Received: from eggs.gnu.org ([208.118.235.92]:50905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1mhA-0001Ve-DL for qemu-devel@nongnu.org; Sat, 02 Feb 2013 18:40:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1mh7-0000pi-5e for qemu-devel@nongnu.org; Sat, 02 Feb 2013 18:40:28 -0500 Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:56564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1mh6-0000pJ-SE for qemu-devel@nongnu.org; Sat, 02 Feb 2013 18:40:25 -0500 Received: by mail-wi0-f169.google.com with SMTP id l13so1344926wie.4 for ; Sat, 02 Feb 2013 15:40:23 -0800 (PST) Sender: Grant Likely From: Grant Likely Date: Sat, 2 Feb 2013 23:40:09 +0000 Message-Id: <1359848409-1106-9-git-send-email-grant.likely@secretlab.ca> In-Reply-To: <1359848409-1106-1-git-send-email-grant.likely@secretlab.ca> References: <1359848409-1106-1-git-send-email-grant.likely@secretlab.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH V3 8/8] hw/mdio: Use bitbang core for smc91c111 network device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Anthony Liguori , Grant Likely , Paul Brook , "Edgar E. Iglesias" , =?UTF-8?q?Andreas=20F=C3=A4rber?= The smc91c111 device has bitbanged MDIO access, but the model doesn't yet implement it. This patch uses the generalized bitbang MDIO support pulled out of etraxfs Ethernet driver. The MDIO state machine is driven by changes in state to the clock control bit in the management register. The PHY model emulated is currently trivial (being whatever was done for the etraxfs driver), but it is enough to get an OS to recognize a PHY as being present. Tested with the versatilepb model with U-Boot and the Linux Kernel as client software. Cc: Peter Maydell Cc: Paul Brook Cc: Edgar E. Iglesias Cc: Anthony Liguori Cc: Andreas Färber Signed-off-by: Grant Likely --- hw/Makefile.objs | 2 +- hw/smc91c111.c | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/hw/Makefile.objs b/hw/Makefile.objs index af93dfc..4ec6fb8 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -117,7 +117,7 @@ common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o common-obj-$(CONFIG_E1000_PCI) += e1000.o common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o -common-obj-$(CONFIG_SMC91C111) += smc91c111.o +common-obj-$(CONFIG_SMC91C111) += smc91c111.o mdio.o common-obj-$(CONFIG_LAN9118) += lan9118.o common-obj-$(CONFIG_NE2000_ISA) += ne2000-isa.o common-obj-$(CONFIG_OPENCORES_ETH) += opencores_eth.o diff --git a/hw/smc91c111.c b/hw/smc91c111.c index a34698f..506101b 100644 --- a/hw/smc91c111.c +++ b/hw/smc91c111.c @@ -10,6 +10,7 @@ #include "sysbus.h" #include "net/net.h" #include "devices.h" +#include "mdio.h" /* For crc32 */ #include @@ -44,6 +45,10 @@ typedef struct { uint8_t int_level; uint8_t int_mask; MemoryRegion mmio; + + /* MDIO bus and the attached phy */ + struct qemu_mdio mdio_bus; + struct qemu_phy phy; } smc91c111_state; static const VMStateDescription vmstate_smc91c111 = { @@ -71,6 +76,8 @@ static const VMStateDescription vmstate_smc91c111 = { VMSTATE_BUFFER_UNSAFE(data, smc91c111_state, 0, NUM_PACKETS * 2048), VMSTATE_UINT8(int_level, smc91c111_state), VMSTATE_UINT8(int_mask, smc91c111_state), + VMSTATE_MDIO(mdio_bus, smc91c111_state), + VMSTATE_MDIO_PHY(phy, smc91c111_state), VMSTATE_END_OF_LIST() } }; @@ -437,7 +444,15 @@ static void smc91c111_writeb(void *opaque, hwaddr offset, /* Multicast table. */ /* Not implemented. */ return; - case 8: case 9: /* Management Interface. */ + case 8: /* Management Interface. */ + /* Update MDIO data line status; but only if output is enabled */ + if (value & 8) { + mdio_bitbang_set_data(&s->mdio_bus, !!(value & 1)); + } + /* Process the clock */ + mdio_bitbang_set_clk(&s->mdio_bus, value & 4); + return; + case 9: /* Management Interface. */ /* Not implemented. */ return; case 12: /* Early receive. */ @@ -576,8 +591,7 @@ static uint32_t smc91c111_readb(void *opaque, hwaddr offset) /* Not implemented. */ return 0; case 8: /* Management Interface. */ - /* Not implemented. */ - return 0x30; + return 0x30 | (mdio_bitbang_get_data(&s->mdio_bus) ? 2 : 0); case 9: return 0x33; case 10: /* Revision. */ @@ -754,6 +768,9 @@ static int smc91c111_init1(SysBusDevice *dev) s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf, object_get_typename(OBJECT(dev)), dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); + + mdio_phy_init(&s->phy, 0x0016, 0xf84); + mdio_attach(&s->mdio_bus, &s->phy, 0); /* ??? Save/restore. */ return 0; } -- 1.7.10.4