From patchwork Fri Sep 22 17:13:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 114070 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3539603qgf; Fri, 22 Sep 2017 10:19:16 -0700 (PDT) X-Received: by 10.55.217.18 with SMTP id u18mr8306908qki.53.1506100756086; Fri, 22 Sep 2017 10:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506100756; cv=none; d=google.com; s=arc-20160816; b=omS3cybUYpeH40OOhDtydab4PZqn9s3iMmsdsiJJ4paGa2xRmtTisgNwbcWsLlhD5W uyEw6llRhTU1eYqsgAWWqKbpiWH7A+tljRllW6/Z1C3Q5/pG4BrSrObkiYFmt/0nEdi3 Bv4439a3x3pioUB1tgGAu/WpAiUGulsiULzy3u27CnLT9VN8P8gRpeBVe4hc2Ermqcql vjzsfOf/GE5rerNSThUpKtvVMxrJJeouEn1nlzniLUxTvdjuhB3DuDxvfR5W+/Hkz2BK f07vFP7rZsvLMFIZ+V8cuPwU1NABUA5xOqZrXRJRGBaO7yln7oVyGkHHiDJiuAPbXKhA YafA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=8WUBkW9wpJPB/VCLjIGjQWKuBifSyiF53SoglAoDu9w=; b=THd1Sz6NJ9dVdaB6exmvzEqDevNTOOQjnFzqSsfBxOR1VZ5Fshhgvyy1jkh0imisr2 xMtCxLdfwi+zSRY1tkl1OZJzfM8JCU6REkPvq43vqRf1hgHfKVU1tQaidet4znZ6zNFC SlLo/XmzGHsSdED1MDSEc55DITQEsCenkSdEKL7k+YSX5UIV2uU+YYzmH2tXLkuW8oXM 1T7zMVe7A77kBI7O8cqoYDV4z7Rrr9i5/J+tGGzokG+foV/dnOIh+206Dki8jdcluZ35 tLSINYIFCgrSNgX7lEsGPpw3LpfNLSdbWpHE40g6yu01dBWbdJIPr+qDAD+gm1T6Je4D 5GVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=k1CpRbaU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h198si243199qke.124.2017.09.22.10.19.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Sep 2017 10:19:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=k1CpRbaU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:60305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRbd-0008JK-Tn for patch@linaro.org; Fri, 22 Sep 2017 13:19:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRWf-0003jB-Tm for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:14:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvRWc-0003cI-Ix for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:14:05 -0400 Received: from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]:34739) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvRWc-0003c4-Dp for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:14:02 -0400 Received: by mail-qk0-x243.google.com with SMTP id d70so1028312qkc.1 for ; Fri, 22 Sep 2017 10:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8WUBkW9wpJPB/VCLjIGjQWKuBifSyiF53SoglAoDu9w=; b=k1CpRbaU5zC39rgVotHezDiC01wrIWlc9sboIyUtVRd8hi1Wg7cdaeJwqnNDo4vN4V SOkGNZHgwHEzdUDqz96wmA6vQb8vJucZV7Tfrjd3sfM82XPKhViNFTXsSXmF50fYJxY5 BNYwc0xHRJTPlK27Ymvlq8oJCIym5ykRwonsIHs6Fr1br1rNP+6oxv9t/APUOnOi5wLP rBw+ESFb0YYVFcWRdmVFqxzGGCHZScDOjqYP9VEt3odZubV5KuhJCJWaTCYDQLT06Su+ xCDF2k8mYx16SRfDy4nqzxA8illy/yj4oWxgbFbNNQnvbX0yVmqi0g3/uI2k2H+Qmecd folA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=8WUBkW9wpJPB/VCLjIGjQWKuBifSyiF53SoglAoDu9w=; b=k+pULdPzfUsVy9w/P1ECuaql5gQAKgD5pb9Dztqn3tVeqJhgdQY6HSf/vXyWVmrZ+j 72igm+DZaE6wNoNAGHwa63KtJWRvDG7KBhLdCUC/ClD8ntJbXYlzXyGIjTOKCHrT7YWI p8pqFChAOCXiP4X22NCOMXC3xtCt/Xtn5ctkwtZA4aFZhpVyWj251ViWb5ThmAw9oK7W kcxF0nPiCU8PDCjp7KT26qHMULb2g3g13KmTUxSmRhP4+WZe/g5VyCbOtXnqFH1zq7UE NgailtfK1lsXr8v23K1lQ3yCNZN+HTX07y8VwN6tfMK9ZqNMs1TlBFDUn/1kFBAw6MFT oIYw== X-Gm-Message-State: AHPjjUhGf5uVQxE1t+rs29JkM/eDtMnkNL/PAzQy7Eaij6mcfEz6I/Z4 FSiazcUZxks+MbUmahm3yRc= X-Google-Smtp-Source: AOwi7QABBPM04NKbGcUavZLFRmQtDREhlQtkwG92AAetSNIVKiV7cix+Ofm989NPSYOG799ARsRxhQ== X-Received: by 10.55.33.87 with SMTP id h84mr8422313qkh.138.1506100438901; Fri, 22 Sep 2017 10:13:58 -0700 (PDT) Received: from yoga.lan ([181.93.89.178]) by smtp.gmail.com with ESMTPSA id f69sm238468qke.27.2017.09.22.10.13.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2017 10:13:58 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Peter Maydell , Grant Likely , Jason Wang , Peter Crosthwaite Date: Fri, 22 Sep 2017 14:13:23 -0300 Message-Id: <20170922171323.10348-8-f4bug@amsat.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170922171323.10348-1-f4bug@amsat.org> References: <20170922171323.10348-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::243 Subject: [Qemu-devel] [PATCH v5 7/7] hw/mdio: Use bitbang core for smc91c111 network device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Grant Likely 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. Updated .version_id and .minimum_version_id fields because this patch add fields to the state structure. Signed-off-by: Grant Likely Signed-off-by: Philippe Mathieu-Daudé [PMD: just rebased] --- hw/net/smc91c111.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) -- 2.14.1 diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c index 3b16dcf5a1..b5cc493f9f 100644 --- a/hw/net/smc91c111.c +++ b/hw/net/smc91c111.c @@ -11,6 +11,7 @@ #include "hw/sysbus.h" #include "net/net.h" #include "hw/devices.h" +#include "hw/net/mdio.h" /* For crc32 */ #include @@ -49,12 +50,16 @@ 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 = { .name = "smc91c111", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .fields = (VMStateField[]) { VMSTATE_UINT16(tcr, smc91c111_state), VMSTATE_UINT16(rcr, smc91c111_state), @@ -76,6 +81,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() } }; @@ -466,7 +473,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. */ @@ -606,8 +621,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. */ @@ -774,6 +788,9 @@ static int smc91c111_init1(SysBusDevice *sbd) s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); + + mdio_phy_init(&s->phy, 0x0016, 0xf84); + mdio_attach(&s->mdio_bus, &s->phy, 0); /* ??? Save/restore. */ return 0; }