From patchwork Sat Jan 19 22:28:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 213894 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E3A5E2C0084 for ; Sun, 20 Jan 2013 12:02:21 +1100 (EST) Received: from localhost ([::1]:52441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Twie8-0003CJ-4w for incoming@patchwork.ozlabs.org; Sat, 19 Jan 2013 19:20:24 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Twidk-0002yt-9E for qemu-devel@nongnu.org; Sat, 19 Jan 2013 19:20:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Twidh-00028U-V7 for qemu-devel@nongnu.org; Sat, 19 Jan 2013 19:20:00 -0500 Received: from mail-qc0-f175.google.com ([209.85.216.175]:59778) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Twidh-00027w-Qo for qemu-devel@nongnu.org; Sat, 19 Jan 2013 19:19:57 -0500 Received: by mail-qc0-f175.google.com with SMTP id j3so3133016qcs.6 for ; Sat, 19 Jan 2013 16:19:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=vB9RYXuZkGoxRQRQ/ccozARac6Pn6E1j/bSoQCRWLF8=; b=QJpfggUEPY4DHvSM8qmJKKr931li+mL1io9WrpLB/53bXX9Y5u87PKSAHrK2wI+5sx QvyfrSKKLmLrmn8iolBwnHMku5Heh3naN9MR+rlwLdw8Nlu58JYm8MScJ/MiNNS16gp0 Ll+UhSmDdW1GgSL9060Z54f8j5nKf2Y/QI9omr/VbysP5hOtkfH3LOAAYILDHHKui55W bsLwsOEj7N//t7IetmTYparWjHhnYcnwftTxEe1PLm1ZOaAR+MzryOdwYgXIHa7oo45q Yv8l1yPyldeHTfbpWB+mTnet41zm9IBFNyjkYpPjPrwwNpnB1HpwGSpgQ50a+iRbwlwT YGYg== X-Received: by 10.224.183.75 with SMTP id cf11mr14642700qab.82.1358641197309; Sat, 19 Jan 2013 16:19:57 -0800 (PST) Received: from localhost (7-210-static-ppp.3menatwork.com. [64.235.210.7]) by mx.google.com with ESMTPS id eg9sm6131148qab.7.2013.01.19.16.19.55 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 19 Jan 2013 16:19:56 -0800 (PST) Received: by localhost (Postfix, from userid 1000) id 7D2AE3E0B85; Sat, 19 Jan 2013 22:28:16 +0000 (GMT) From: Grant Likely To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2013 18:28:12 -0400 Message-Id: <1358634492-22627-4-git-send-email-grant.likely@secretlab.ca> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358634492-22627-1-git-send-email-grant.likely@secretlab.ca> References: <1358634492-22627-1-git-send-email-grant.likely@secretlab.ca> X-Gm-Message-State: ALoCoQlPV4IlrGTROVhSfKZ0sif/xmieUAJ3Kt6nmHcPmhIW4P+l0uw8ukpJ4ywKr293w5cRGQMS X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.216.175 Cc: Grant Likely , Peter Maydell , Anthony Liguori , Paul Brook , "Edgar E. Iglesias" Subject: [Qemu-devel] [PATCH 3/3] net/bitbang_mdio: Use bitbang core for smc91c111 network device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Grant Likely --- hw/Makefile.objs | 2 +- hw/smc91c111.c | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 74b07a7..0104fd4 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 bitbang_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..715422d 100644 --- a/hw/smc91c111.c +++ b/hw/smc91c111.c @@ -10,6 +10,7 @@ #include "sysbus.h" #include "net/net.h" #include "devices.h" +#include "bitbang_mdio.h" /* For crc32 */ #include @@ -44,6 +45,13 @@ typedef struct { uint8_t int_level; uint8_t int_mask; MemoryRegion mmio; + + /* MDIO bus. */ + struct qemu_mdio mdio_bus; + unsigned int phyaddr; + + /* PHY. */ + struct qemu_phy phy; } smc91c111_state; static const VMStateDescription vmstate_smc91c111 = { @@ -437,8 +445,19 @@ static void smc91c111_writeb(void *opaque, hwaddr offset, /* Multicast table. */ /* Not implemented. */ return; - case 8: case 9: /* Management Interface. */ - /* Not implemented. */ + case 8: /* Management Interface. */ + /* Update MDIO data line status; but only if output is enabled */ + if (value & 8) { + s->mdio_bus.mdio = !!(value & 1); + } + /* Process the clock */ + if (s->mdio_bus.mdc != (value & 4)) { + mdio_cycle(&s->mdio_bus); + s->mdio_bus.mdc = !!(value & 4); + } + return; + case 9: /* Management Interface. */ + /* Not implemented */ return; case 12: /* Early receive. */ s->ercv = value & 0x1f; @@ -576,8 +595,7 @@ static uint32_t smc91c111_readb(void *opaque, hwaddr offset) /* Not implemented. */ return 0; case 8: /* Management Interface. */ - /* Not implemented. */ - return 0x30; + return 0x30 | (s->mdio_bus.mdio ? 2 : 0); case 9: return 0x33; case 10: /* Revision. */ @@ -754,6 +772,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); + + tdk_init(&s->phy); + mdio_attach(&s->mdio_bus, &s->phy, 0); /* ??? Save/restore. */ return 0; }