From patchwork Fri Sep 22 17:13:17 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: 114064 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3534709qgf; Fri, 22 Sep 2017 10:14:17 -0700 (PDT) X-Received: by 10.200.53.67 with SMTP id z3mr9559669qtb.145.1506100457491; Fri, 22 Sep 2017 10:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506100457; cv=none; d=google.com; s=arc-20160816; b=0h6SIhrKDLy97bZiMOHd8gS4XxlOTuy5m+xPNZdQN0dR0eMyZpPIQ8BdorL5Tyh5Ie vG6scELO5ylE+UwAyFXRm8hI78lKZKv6PuNS2tiOjEVbL1o9na/W0LQjAfIew+PvA0GD e3XEhsAr2ltTo9MUUm2zn/YEkz2c35IG4mb6QGw4/u6Cz3iB3L3ptaDmM0Kxb5uMuFMa PbO6oDZsw4q0XiC/9H6ztehqAXdRKhjuLu98Mc8b1v5afffsOU4avVu0FIt3CG1kZa0X 84iTrHaN1B3I84SYh2qGSRKAymKvEvEMCbouma0WTvgQd4rOaN816i8q53jMxGR2awko PTuA== 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=RPD+p856r9FrgIw/HzA1lMN1CFwjzzKKKeXga43uDfc=; b=F3Cok6aFVxjXnaxuQm3DJ3xKl9uggll7HD1kQAhZuaqEGS/2jahrdDpLzhUGg8vbrI Qvb7lzuooJ6mSqqlGd1lENPtRYjNWnlKaJfL0r3GvJGMd7pvU+iHwE6ezRlbTXziQhgo PA5dCtBqDC2ITzfi2TIKpQ2eY8s7uEuo/6WW90g4twEbq5PmatqYTVutCF3tHSFuOZst sWR5jQfZ8LPp3nhkJe4GBG50xtH8dYHtAvM13i35E2YPSqhGOGod+q/zlAOriMauUldB b5JKs2ayVj6ladbs1/FICQ+sPo9dpcJIgv7bQqg08BMBSKcEP6dEdD1tYJS8yVxdKOLf xgFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=bRnO4inG; 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 l6si212958qkf.422.2017.09.22.10.14.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Sep 2017 10:14:17 -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=bRnO4inG; 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]:60283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRWp-0003Wl-4D for patch@linaro.org; Fri, 22 Sep 2017 13:14:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRWM-00039t-RB for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvRWJ-0003OR-Pu for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:46 -0400 Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]:38068) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvRWJ-0003Nd-JZ; Fri, 22 Sep 2017 13:13:43 -0400 Received: by mail-qk0-x244.google.com with SMTP id c69so1021237qke.5; Fri, 22 Sep 2017 10:13:43 -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=RPD+p856r9FrgIw/HzA1lMN1CFwjzzKKKeXga43uDfc=; b=bRnO4inGgMhmZDK69n6m47NfkU8vsHJBMVJf//OxoRKpPe3b0Xk8vq7Wqp9z7tg5JV po9Y/Jcn34yMdJIp4ntzI3qdqrvgfVpHyg3jZNu4cxCk2KVvSyo2Lw6zJKgRC7MmKFmu qjtayG5fZVAT6lL8IG4iGBjzcQSPmayYWZjqL2hIgkPNbChC9fpuof9kODnI6hgaS1Us 7HLhDd1eF3nmJeWoMazdVccUiKwa5TiyTNbQtqwnOMDwo8Krm7OTA1LgZH9NyKHBXeOd wUf5JHRjjgIu/LDV5sRzLDYhjXBm1lCP4yQFGUPVjcPsNbs/mjJSCeigNpAMBzH0lqRG 4IEg== 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=RPD+p856r9FrgIw/HzA1lMN1CFwjzzKKKeXga43uDfc=; b=GA9PfsNbse2sONyANE/0AI3+iWw72h+k31DV8s0VMyJOS/exPOrJn6Nvrjk6uoFy0N So9/o5WzNmk4cCJeBGbum7DK2W4WUgPoAh8LE2DJ442JbalWtM8GroUmQeHuQ6E2spKT TcTx2gGY++XtFDYzGLkgPjtP3dd67ctWJGLK++3tO5tKZwhXKObzIYhIDIuFOWFaOKsR I4U9WQYZOJOelFoups+3WzDIHLZ+ulZwe0CP5QUi+qKQcwKPPHRIc2VX4uvRemkX6ZgB afQhnPnR3Id1CrVJiKEelSoGqt7eH9jCtgm8EU/Fec0ymTrUile5D3XD56N0J1/rcUkR 0/TQ== X-Gm-Message-State: AHPjjUhgRJ9YVfW4hNrIJJqNQZ+2JI7qB5NqZ39Gh3VkBNY6wYwluw/P YAnht7gjxEPYoHonRbelw20= X-Google-Smtp-Source: AOwi7QDt2loxLlKVKmj3KnkrxySrxbdR2VN5MgX3AElj7g4h6BBndf6cs1P4icXv/KluauQZkKZhdw== X-Received: by 10.55.156.147 with SMTP id f141mr9147481qke.72.1506100422656; Fri, 22 Sep 2017 10:13:42 -0700 (PDT) Received: from yoga.lan ([181.93.89.178]) by smtp.gmail.com with ESMTPSA id f69sm238468qke.27.2017.09.22.10.13.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2017 10:13:41 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Peter Maydell , Grant Likely , Jason Wang , "Edgar E. Iglesias" , Alistair Francis , Fam Zheng , =?utf-8?q?Andreas_F=C3=A4rber?= Date: Fri, 22 Sep 2017 14:13:17 -0300 Message-Id: <20170922171323.10348-2-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::244 Subject: [Qemu-devel] [PATCH v5 1/7] hw/mdio: Generalize etraxfs MDIO bitbanging emulation 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-arm@nongnu.org, qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu?= =?utf-8?q?-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Grant Likely The etraxfs and Xilinx axienet Ethernet models implement quite a nice MDIO core that supports both bitbanging and direct register access. This change factors the common code out into a separate file. There are no functional changes here, just movement of code. The etraxfs and axienet are slightly different. The etraxfs version includes the bitbang state processing, but the axienet version has a minor enhancement for read/write of phy registers without using bitbang state variables. This patch generalizes the etraxfs version, with the axienet change backported in. Signed-off-by: Grant Likely Signed-off-by: Philippe Mathieu-Daudé [PMD: rebased with a minor checkpatch fix] --- include/hw/net/mdio.h | 76 +++++++++++++ hw/net/etraxfs_eth.c | 278 +----------------------------------------------- hw/net/mdio.c | 262 +++++++++++++++++++++++++++++++++++++++++++++ hw/net/xilinx_axienet.c | 187 +------------------------------- hw/net/Makefile.objs | 2 + 5 files changed, 344 insertions(+), 461 deletions(-) create mode 100644 include/hw/net/mdio.h create mode 100644 hw/net/mdio.c -- 2.14.1 diff --git a/include/hw/net/mdio.h b/include/hw/net/mdio.h new file mode 100644 index 0000000000..ac36aed3c3 --- /dev/null +++ b/include/hw/net/mdio.h @@ -0,0 +1,76 @@ +#ifndef BITBANG_MDIO_H +#define BITBANG_MDIO_H + +/* + * QEMU Bitbang Ethernet MDIO bus & PHY controllers. + * + * Copyright (c) 2008 Edgar E. Iglesias, Axis Communications AB. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* PHY Advertisement control register */ +#define PHY_ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */ +#define PHY_ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */ +#define PHY_ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */ +#define PHY_ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */ + +struct qemu_phy { + uint32_t regs[32]; + + int link; + + unsigned int (*read)(struct qemu_phy *phy, unsigned int req); + void (*write)(struct qemu_phy *phy, unsigned int req, unsigned int data); +}; + +struct qemu_mdio { + /* bus. */ + int mdc; + int mdio; + + /* decoder. */ + enum { + PREAMBLE, + SOF, + OPC, + ADDR, + REQ, + TURNAROUND, + DATA + } state; + unsigned int drive; + + unsigned int cnt; + unsigned int addr; + unsigned int opc; + unsigned int req; + unsigned int data; + + struct qemu_phy *devs[32]; +}; + +void tdk_init(struct qemu_phy *phy); +void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, + unsigned int addr); +uint16_t mdio_read_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req); +void mdio_write_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req, uint16_t data); +void mdio_cycle(struct qemu_mdio *bus); + +#endif diff --git a/hw/net/etraxfs_eth.c b/hw/net/etraxfs_eth.c index 013c8d0a41..f8d8f8441d 100644 --- a/hw/net/etraxfs_eth.c +++ b/hw/net/etraxfs_eth.c @@ -26,287 +26,11 @@ #include "hw/sysbus.h" #include "net/net.h" #include "hw/cris/etraxfs.h" +#include "hw/net/mdio.h" #include "qemu/error-report.h" #define D(x) -/* Advertisement control register. */ -#define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */ -#define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */ -#define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */ -#define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */ - -/* - * The MDIO extensions in the TDK PHY model were reversed engineered from the - * linux driver (PHYID and Diagnostics reg). - * TODO: Add friendly names for the register nums. - */ -struct qemu_phy -{ - uint32_t regs[32]; - - int link; - - unsigned int (*read)(struct qemu_phy *phy, unsigned int req); - void (*write)(struct qemu_phy *phy, unsigned int req, unsigned int data); -}; - -static unsigned int tdk_read(struct qemu_phy *phy, unsigned int req) -{ - int regnum; - unsigned r = 0; - - regnum = req & 0x1f; - - switch (regnum) { - case 1: - if (!phy->link) { - break; - } - /* MR1. */ - /* Speeds and modes. */ - r |= (1 << 13) | (1 << 14); - r |= (1 << 11) | (1 << 12); - r |= (1 << 5); /* Autoneg complete. */ - r |= (1 << 3); /* Autoneg able. */ - r |= (1 << 2); /* link. */ - break; - case 5: - /* Link partner ability. - We are kind; always agree with whatever best mode - the guest advertises. */ - r = 1 << 14; /* Success. */ - /* Copy advertised modes. */ - r |= phy->regs[4] & (15 << 5); - /* Autoneg support. */ - r |= 1; - break; - case 18: - { - /* Diagnostics reg. */ - int duplex = 0; - int speed_100 = 0; - - if (!phy->link) { - break; - } - - /* Are we advertising 100 half or 100 duplex ? */ - speed_100 = !!(phy->regs[4] & ADVERTISE_100HALF); - speed_100 |= !!(phy->regs[4] & ADVERTISE_100FULL); - - /* Are we advertising 10 duplex or 100 duplex ? */ - duplex = !!(phy->regs[4] & ADVERTISE_100FULL); - duplex |= !!(phy->regs[4] & ADVERTISE_10FULL); - r = (speed_100 << 10) | (duplex << 11); - } - break; - - default: - r = phy->regs[regnum]; - break; - } - D(printf("\n%s %x = reg[%d]\n", __func__, r, regnum)); - return r; -} - -static void -tdk_write(struct qemu_phy *phy, unsigned int req, unsigned int data) -{ - int regnum; - - regnum = req & 0x1f; - D(printf("%s reg[%d] = %x\n", __func__, regnum, data)); - switch (regnum) { - default: - phy->regs[regnum] = data; - break; - } -} - -static void -tdk_init(struct qemu_phy *phy) -{ - phy->regs[0] = 0x3100; - /* PHY Id. */ - phy->regs[2] = 0x0300; - phy->regs[3] = 0xe400; - /* Autonegotiation advertisement reg. */ - phy->regs[4] = 0x01E1; - phy->link = 1; - - phy->read = tdk_read; - phy->write = tdk_write; -} - -struct qemu_mdio -{ - /* bus. */ - int mdc; - int mdio; - - /* decoder. */ - enum { - PREAMBLE, - SOF, - OPC, - ADDR, - REQ, - TURNAROUND, - DATA - } state; - unsigned int drive; - - unsigned int cnt; - unsigned int addr; - unsigned int opc; - unsigned int req; - unsigned int data; - - struct qemu_phy *devs[32]; -}; - -static void -mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr) -{ - bus->devs[addr & 0x1f] = phy; -} - -#ifdef USE_THIS_DEAD_CODE -static void -mdio_detach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr) -{ - bus->devs[addr & 0x1f] = NULL; -} -#endif - -static void mdio_read_req(struct qemu_mdio *bus) -{ - struct qemu_phy *phy; - - phy = bus->devs[bus->addr]; - if (phy && phy->read) { - bus->data = phy->read(phy, bus->req); - } else { - bus->data = 0xffff; - } -} - -static void mdio_write_req(struct qemu_mdio *bus) -{ - struct qemu_phy *phy; - - phy = bus->devs[bus->addr]; - if (phy && phy->write) { - phy->write(phy, bus->req, bus->data); - } -} - -static void mdio_cycle(struct qemu_mdio *bus) -{ - bus->cnt++; - - D(printf("mdc=%d mdio=%d state=%d cnt=%d drv=%d\n", - bus->mdc, bus->mdio, bus->state, bus->cnt, bus->drive)); -#if 0 - if (bus->mdc) { - printf("%d", bus->mdio); - } -#endif - switch (bus->state) { - case PREAMBLE: - if (bus->mdc) { - if (bus->cnt >= (32 * 2) && !bus->mdio) { - bus->cnt = 0; - bus->state = SOF; - bus->data = 0; - } - } - break; - case SOF: - if (bus->mdc) { - if (bus->mdio != 1) { - printf("WARNING: no SOF\n"); - } - if (bus->cnt == 1*2) { - bus->cnt = 0; - bus->opc = 0; - bus->state = OPC; - } - } - break; - case OPC: - if (bus->mdc) { - bus->opc <<= 1; - bus->opc |= bus->mdio & 1; - if (bus->cnt == 2*2) { - bus->cnt = 0; - bus->addr = 0; - bus->state = ADDR; - } - } - break; - case ADDR: - if (bus->mdc) { - bus->addr <<= 1; - bus->addr |= bus->mdio & 1; - - if (bus->cnt == 5*2) { - bus->cnt = 0; - bus->req = 0; - bus->state = REQ; - } - } - break; - case REQ: - if (bus->mdc) { - bus->req <<= 1; - bus->req |= bus->mdio & 1; - if (bus->cnt == 5*2) { - bus->cnt = 0; - bus->state = TURNAROUND; - } - } - break; - case TURNAROUND: - if (bus->mdc && bus->cnt == 2*2) { - bus->mdio = 0; - bus->cnt = 0; - - if (bus->opc == 2) { - bus->drive = 1; - mdio_read_req(bus); - bus->mdio = bus->data & 1; - } - bus->state = DATA; - } - break; - case DATA: - if (!bus->mdc) { - if (bus->drive) { - bus->mdio = !!(bus->data & (1 << 15)); - bus->data <<= 1; - } - } else { - if (!bus->drive) { - bus->data <<= 1; - bus->data |= bus->mdio; - } - if (bus->cnt == 16 * 2) { - bus->cnt = 0; - bus->state = PREAMBLE; - if (!bus->drive) { - mdio_write_req(bus); - } - bus->drive = 0; - } - } - break; - default: - break; - } -} - /* ETRAX-FS Ethernet MAC block starts here. */ #define RW_MA0_LO 0x00 diff --git a/hw/net/mdio.c b/hw/net/mdio.c new file mode 100644 index 0000000000..3763fcc8af --- /dev/null +++ b/hw/net/mdio.c @@ -0,0 +1,262 @@ +/* + * QEMU Ethernet MDIO bus & PHY models + * + * Copyright (c) 2008 Edgar E. Iglesias, Axis Communications AB. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This is a generic MDIO implementation. + * + * TODO: + * - Split PHYs out as separate device models so they can be defined and + * instantiated separately from the MDIO bus. + * - Split out bitbang state machine into a separate model. Mostly this consists + * of the mdio_cycle() routine and the bitbang state data in struct qemu_mdio + * - Use the GPIO interface for driving bitbang + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/log.h" +#include "hw/net/mdio.h" + +#define D(x) + +/* + * The MDIO extensions in the TDK PHY model were reversed engineered from the + * linux driver (PHYID and Diagnostics reg). + * TODO: Add friendly names for the register nums. + */ +static unsigned int tdk_read(struct qemu_phy *phy, unsigned int req) +{ + int regnum; + unsigned r = 0; + + regnum = req & 0x1f; + + switch (regnum) { + case 1: + if (!phy->link) { + break; + } + /* MR1. */ + /* Speeds and modes. */ + r |= (1 << 13) | (1 << 14); + r |= (1 << 11) | (1 << 12); + r |= (1 << 5); /* Autoneg complete. */ + r |= (1 << 3); /* Autoneg able. */ + r |= (1 << 2); /* link. */ + r |= (1 << 1); /* link. */ + break; + case 5: + /* Link partner ability. + We are kind; always agree with whatever best mode + the guest advertises. */ + r = 1 << 14; /* Success. */ + /* Copy advertised modes. */ + r |= phy->regs[4] & (15 << 5); + /* Autoneg support. */ + r |= 1; + break; + case 17: + /* Marvel PHY on many xilinx boards. */ + r = 0x8000; /* 1000Mb */ + break; + case 18: + { + /* Diagnostics reg. */ + int duplex = 0; + int speed_100 = 0; + + if (!phy->link) { + break; + } + + /* Are we advertising 100 half or 100 duplex ? */ + speed_100 = !!(phy->regs[4] & PHY_ADVERTISE_100HALF); + speed_100 |= !!(phy->regs[4] & PHY_ADVERTISE_100FULL); + + /* Are we advertising 10 duplex or 100 duplex ? */ + duplex = !!(phy->regs[4] & PHY_ADVERTISE_100FULL); + duplex |= !!(phy->regs[4] & PHY_ADVERTISE_10FULL); + r = (speed_100 << 10) | (duplex << 11); + } + break; + + default: + r = phy->regs[regnum]; + break; + } + D(printf("\n%s %x = reg[%d]\n", __func__, r, regnum)); + return r; +} + +static void tdk_write(struct qemu_phy *phy, unsigned int req, unsigned int data) +{ + int regnum; + + regnum = req & 0x1f; + D(printf("%s reg[%d] = %x\n", __func__, regnum, data)); + switch (regnum) { + default: + phy->regs[regnum] = data; + break; + } +} + +void tdk_init(struct qemu_phy *phy) +{ + phy->regs[0] = 0x3100; + /* PHY Id. */ + phy->regs[2] = 0x0300; + phy->regs[3] = 0xe400; + /* Autonegotiation advertisement reg. */ + phy->regs[4] = 0x01e1; + phy->link = 1; + + phy->read = tdk_read; + phy->write = tdk_write; +} + +void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr) +{ + bus->devs[addr & 0x1f] = phy; +} + +uint16_t mdio_read_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req) +{ + struct qemu_phy *phy; + + phy = bus->devs[bus->addr]; + if (phy && phy->read) { + return phy->read(phy, req); + } + return 0xffff; +} + +void mdio_write_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req, + uint16_t data) +{ + struct qemu_phy *phy; + + phy = bus->devs[bus->addr]; + if (phy && phy->write) { + phy->write(phy, req, data); + } +} + +void mdio_cycle(struct qemu_mdio *bus) +{ + bus->cnt++; + + D(printf("mdc=%d mdio=%d state=%d cnt=%d drv=%d\n", + bus->mdc, bus->mdio, bus->state, bus->cnt, bus->drive)); + switch (bus->state) { + case PREAMBLE: + if (bus->mdc) { + if (bus->cnt >= (32 * 2) && !bus->mdio) { + bus->cnt = 0; + bus->state = SOF; + bus->data = 0; + } + } + break; + case SOF: + if (bus->mdc) { + if (bus->mdio != 1) { + printf("WARNING: no SOF\n"); + } + if (bus->cnt == 1 * 2) { + bus->cnt = 0; + bus->opc = 0; + bus->state = OPC; + } + } + break; + case OPC: + if (bus->mdc) { + bus->opc <<= 1; + bus->opc |= bus->mdio & 1; + if (bus->cnt == 2 * 2) { + bus->cnt = 0; + bus->addr = 0; + bus->state = ADDR; + } + } + break; + case ADDR: + if (bus->mdc) { + bus->addr <<= 1; + bus->addr |= bus->mdio & 1; + + if (bus->cnt == 5 * 2) { + bus->cnt = 0; + bus->req = 0; + bus->state = REQ; + } + } + break; + case REQ: + if (bus->mdc) { + bus->req <<= 1; + bus->req |= bus->mdio & 1; + if (bus->cnt == 5 * 2) { + bus->cnt = 0; + bus->state = TURNAROUND; + } + } + break; + case TURNAROUND: + if (bus->mdc && bus->cnt == 2 * 2) { + bus->mdio = 0; + bus->cnt = 0; + + if (bus->opc == 2) { + bus->drive = 1; + bus->data = mdio_read_req(bus, bus->addr, bus->req); + bus->mdio = bus->data & 1; + } + bus->state = DATA; + } + break; + case DATA: + if (!bus->mdc) { + if (bus->drive) { + bus->mdio = !!(bus->data & (1 << 15)); + bus->data <<= 1; + } + } else { + if (!bus->drive) { + bus->data <<= 1; + bus->data |= bus->mdio; + } + if (bus->cnt == 16 * 2) { + bus->cnt = 0; + bus->state = PREAMBLE; + if (!bus->drive) { + mdio_write_req(bus, bus->addr, bus->req, bus->data); + } + bus->drive = 0; + } + } + break; + default: + break; + } +} diff --git a/hw/net/xilinx_axienet.c b/hw/net/xilinx_axienet.c index d4c2c89dc1..1e859fdaae 100644 --- a/hw/net/xilinx_axienet.c +++ b/hw/net/xilinx_axienet.c @@ -26,13 +26,12 @@ #include "hw/sysbus.h" #include "qapi/error.h" #include "qemu/log.h" +#include "hw/net/mdio.h" #include "net/net.h" #include "net/checksum.h" #include "hw/stream.h" -#define DPHY(x) - #define TYPE_XILINX_AXI_ENET "xlnx.axi-ethernet" #define TYPE_XILINX_AXI_ENET_DATA_STREAM "xilinx-axienet-data-stream" #define TYPE_XILINX_AXI_ENET_CONTROL_STREAM "xilinx-axienet-control-stream" @@ -48,189 +47,9 @@ OBJECT_CHECK(XilinxAXIEnetStreamSlave, (obj),\ TYPE_XILINX_AXI_ENET_CONTROL_STREAM) -/* Advertisement control register. */ -#define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */ -#define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */ -#define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */ -#define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */ - #define CONTROL_PAYLOAD_WORDS 5 #define CONTROL_PAYLOAD_SIZE (CONTROL_PAYLOAD_WORDS * (sizeof(uint32_t))) -struct PHY { - uint32_t regs[32]; - - int link; - - unsigned int (*read)(struct PHY *phy, unsigned int req); - void (*write)(struct PHY *phy, unsigned int req, - unsigned int data); -}; - -static unsigned int tdk_read(struct PHY *phy, unsigned int req) -{ - int regnum; - unsigned r = 0; - - regnum = req & 0x1f; - - switch (regnum) { - case 1: - if (!phy->link) { - break; - } - /* MR1. */ - /* Speeds and modes. */ - r |= (1 << 13) | (1 << 14); - r |= (1 << 11) | (1 << 12); - r |= (1 << 5); /* Autoneg complete. */ - r |= (1 << 3); /* Autoneg able. */ - r |= (1 << 2); /* link. */ - r |= (1 << 1); /* link. */ - break; - case 5: - /* Link partner ability. - We are kind; always agree with whatever best mode - the guest advertises. */ - r = 1 << 14; /* Success. */ - /* Copy advertised modes. */ - r |= phy->regs[4] & (15 << 5); - /* Autoneg support. */ - r |= 1; - break; - case 17: - /* Marvell PHY on many xilinx boards. */ - r = 0x8000; /* 1000Mb */ - break; - case 18: - { - /* Diagnostics reg. */ - int duplex = 0; - int speed_100 = 0; - - if (!phy->link) { - break; - } - - /* Are we advertising 100 half or 100 duplex ? */ - speed_100 = !!(phy->regs[4] & ADVERTISE_100HALF); - speed_100 |= !!(phy->regs[4] & ADVERTISE_100FULL); - - /* Are we advertising 10 duplex or 100 duplex ? */ - duplex = !!(phy->regs[4] & ADVERTISE_100FULL); - duplex |= !!(phy->regs[4] & ADVERTISE_10FULL); - r = (speed_100 << 10) | (duplex << 11); - } - break; - - default: - r = phy->regs[regnum]; - break; - } - DPHY(qemu_log("\n%s %x = reg[%d]\n", __func__, r, regnum)); - return r; -} - -static void -tdk_write(struct PHY *phy, unsigned int req, unsigned int data) -{ - int regnum; - - regnum = req & 0x1f; - DPHY(qemu_log("%s reg[%d] = %x\n", __func__, regnum, data)); - switch (regnum) { - default: - phy->regs[regnum] = data; - break; - } - - /* Unconditionally clear regs[BMCR][BMCR_RESET] */ - phy->regs[0] &= ~0x8000; -} - -static void -tdk_init(struct PHY *phy) -{ - phy->regs[0] = 0x3100; - /* PHY Id. */ - phy->regs[2] = 0x0300; - phy->regs[3] = 0xe400; - /* Autonegotiation advertisement reg. */ - phy->regs[4] = 0x01E1; - phy->link = 1; - - phy->read = tdk_read; - phy->write = tdk_write; -} - -struct MDIOBus { - /* bus. */ - int mdc; - int mdio; - - /* decoder. */ - enum { - PREAMBLE, - SOF, - OPC, - ADDR, - REQ, - TURNAROUND, - DATA - } state; - unsigned int drive; - - unsigned int cnt; - unsigned int addr; - unsigned int opc; - unsigned int req; - unsigned int data; - - struct PHY *devs[32]; -}; - -static void -mdio_attach(struct MDIOBus *bus, struct PHY *phy, unsigned int addr) -{ - bus->devs[addr & 0x1f] = phy; -} - -#ifdef USE_THIS_DEAD_CODE -static void -mdio_detach(struct MDIOBus *bus, struct PHY *phy, unsigned int addr) -{ - bus->devs[addr & 0x1f] = NULL; -} -#endif - -static uint16_t mdio_read_req(struct MDIOBus *bus, unsigned int addr, - unsigned int reg) -{ - struct PHY *phy; - uint16_t data; - - phy = bus->devs[addr]; - if (phy && phy->read) { - data = phy->read(phy, reg); - } else { - data = 0xffff; - } - DPHY(qemu_log("%s addr=%d reg=%d data=%x\n", __func__, addr, reg, data)); - return data; -} - -static void mdio_write_req(struct MDIOBus *bus, unsigned int addr, - unsigned int reg, uint16_t data) -{ - struct PHY *phy; - - DPHY(qemu_log("%s addr=%d reg=%d data=%x\n", __func__, addr, reg, data)); - phy = bus->devs[addr]; - if (phy && phy->write) { - phy->write(phy, reg, data); - } -} - #define DENET(x) #define R_RAF (0x000 / 4) @@ -322,8 +141,8 @@ enum { /* Indirect registers. */ struct TEMAC { - struct MDIOBus mdio_bus; - struct PHY phy; + struct qemu_mdio mdio_bus; + struct qemu_phy phy; void *parent; }; diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs index 4171af0b5d..a020963d10 100644 --- a/hw/net/Makefile.objs +++ b/hw/net/Makefile.objs @@ -30,6 +30,8 @@ common-obj-$(CONFIG_SUNHME) += sunhme.o common-obj-$(CONFIG_FTGMAC100) += ftgmac100.o common-obj-$(CONFIG_SUNGEM) += sungem.o +common-obj-y += mdio.o + obj-$(CONFIG_ETRAXFS) += etraxfs_eth.o obj-$(CONFIG_COLDFIRE) += mcf_fec.o obj-$(CONFIG_MILKYMIST) += milkymist-minimac2.o From patchwork Fri Sep 22 17:13:18 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: 114067 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3537243qgf; Fri, 22 Sep 2017 10:16:54 -0700 (PDT) X-Received: by 10.200.57.29 with SMTP id s29mr9592070qtb.309.1506100614437; Fri, 22 Sep 2017 10:16:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506100614; cv=none; d=google.com; s=arc-20160816; b=FiUjp4UVXiWj6TbzogN2qEhoMo0kkfnPkGGHZiW0B62pkxzRL2Lz+gv204p8luSfsQ bF9Sh0p6qK9h95f4IvjbfqkCahVP+ni+F3RDQAZr+TN9NhlkhEgECUZWVQU+YwN6FFXM AIRIQzb1wEIMHhQxrtQB81LACs0ciFTjo5skkmWeaUb2BWKjaLRctT0QwyBrzDJ9bYq1 MnHsqOZJnNU20AwTdoFiZw/1tEoe7ewmyqUyexBEeXSThQ7EmXfQP0ldArLQ52/IotDx OEgVLBlPzww/dcN9t6zBT8q44gp5P2/IPtsqei64ycMdo4q+XkgPAuCXFwrhkRagwco4 kzAQ== 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=7KpW00sMxw16wF0mIEkeF89e/zuRxR6YFdtK1trbEKw=; b=ckl5nzZRQOlJZMkUTV/sH5pnM4X7rwkBHCE7eqMPXyVQuFv08gDXFDPo9RKu6QcXSk o6LWfCLosknOXNo6DIcEa5bcxbh4dXnnn49iaP4OypmB/NmAMufBpG4vahNbUjx4nSZm RhWudxTt/PaLe8FfsrunSQJEQLBp0w9KU/c1wX8Oo7XoHDuNknzLbvWO+xUVAXJCV3Dt Yd0Lgpx77UJnFhR5EdUs0w4vafeo+ra1Kc5FdjdQkFJq8R9QcJzuqbMe+/UO6qcMj/vH 9doRJOGjhc8n0AMX0/xAH5M+pyhc3/phzbuegm/wLAxE55mNqiNQhxRclEiIzxO1F0bI cqqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dkwLpiyk; 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 b201si220424qkg.491.2017.09.22.10.16.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Sep 2017 10:16:54 -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=dkwLpiyk; 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]:60296 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRZM-00064W-Cn for patch@linaro.org; Fri, 22 Sep 2017 13:16:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRWM-00039s-QP for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvRWL-0003R5-LA for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:46 -0400 Received: from mail-qt0-x244.google.com ([2607:f8b0:400d:c0d::244]:34548) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvRWL-0003Qf-HY for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:45 -0400 Received: by mail-qt0-x244.google.com with SMTP id q8so1046258qtb.1 for ; Fri, 22 Sep 2017 10:13:45 -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=7KpW00sMxw16wF0mIEkeF89e/zuRxR6YFdtK1trbEKw=; b=dkwLpiykxStyziN1uZTOc3Q0x+iplgNaM4q2eajF6cygNLZv36rS/6ca8ks6y8bmAJ XIRR1TMy7ZM7VPDH3+jYgpBgdJyjI+Z71UjV6rBJosKAy0whq7Dl4NydzekajkTU+O5o pyEhtxJ4J62kmmZWwa6Yj/4dBoGH3KSCnR10bCiQiurF45nRP4LZ7rD0fDA2vTXGVKOO wJULB8boK7/LzIxPutMChP8EYuk2laoedurlXrnNjSJblJNsr2fnR8XR4ChqcAJ5D+kR N01DFss0aQ2WTOK5KVyUeuMQdzq/pWIIJiBpvYzI0E991fL4THeMxtnLupJ3erDiSAeA qMmw== 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=7KpW00sMxw16wF0mIEkeF89e/zuRxR6YFdtK1trbEKw=; b=qgDdbMpTZsCTcLgiFchJVZcn+BaDECLhDR6Le+Un1stS4P40EaAFGgCw5NaAb7DjtQ C3ZwAftX+5xwL5qA1v9MBMrXwQccvLdEYeJ7yd5F50w2DWGtJlraotLrjt0WzlZULQXF zsR1N+NHjdPY1/BdiGnyk93Q3IRefmjVYiJIKh1R6UrvwFxtRX0k+CvS3rT1slk9mR35 timVQpyGRUmvsbsrrPGF9cMUKs9ZG+vsQM9F+9s89wRVTHlzvcc/9vFpAfMu9lA5aFTT PTHRjxbLUe0xP6o+ZTa1h+RbxIkfTI6iKPFDl30803Z8kfb0TdpsArF3pHbgy9lNJXxO 5gSw== X-Gm-Message-State: AHPjjUg+HTHLGp7ieQSaJZ/mPQGaPrBwIe1o7dNx+EfyjysEVNG9P6DO Oe5Tg1SU0P5mXE8cqAZMMC0= X-Google-Smtp-Source: AOwi7QDDU3npOe0uC7MpnaysQKFhER0t1R1l+gFO4/6wkrwIQcuTDw6LG9uUMRijv+r3JuGqEniXmw== X-Received: by 10.200.43.228 with SMTP id n33mr9705232qtn.241.1506100425068; Fri, 22 Sep 2017 10:13:45 -0700 (PDT) Received: from yoga.lan ([181.93.89.178]) by smtp.gmail.com with ESMTPSA id f69sm238468qke.27.2017.09.22.10.13.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2017 10:13:44 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Peter Maydell , Grant Likely , Jason Wang Date: Fri, 22 Sep 2017 14:13:18 -0300 Message-Id: <20170922171323.10348-3-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:c0d::244 Subject: [Qemu-devel] [PATCH v5 2/7] hw/mdio: Add PHY register definition 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 Trivial patch to add #defines for defined PHY register address and bit fields Signed-off-by: Grant Likely Signed-off-by: Philippe Mathieu-Daudé --- include/hw/net/mdio.h | 24 ++++++++++++++++++++++-- hw/net/mdio.c | 8 ++++---- 2 files changed, 26 insertions(+), 6 deletions(-) -- 2.14.1 Reviewed-by: Alistair Francis diff --git a/include/hw/net/mdio.h b/include/hw/net/mdio.h index ac36aed3c3..7ffa4389b9 100644 --- a/include/hw/net/mdio.h +++ b/include/hw/net/mdio.h @@ -25,14 +25,34 @@ * THE SOFTWARE. */ -/* PHY Advertisement control register */ +/* PHY MII Register/Bit Definitions */ +/* PHY Registers defined by IEEE */ +#define PHY_CTRL 0x00 /* Control Register */ +#define PHY_STATUS 0x01 /* Status Regiser */ +#define PHY_ID1 0x02 /* Phy Id Reg (word 1) */ +#define PHY_ID2 0x03 /* Phy Id Reg (word 2) */ +#define PHY_AUTONEG_ADV 0x04 /* Autoneg Advertisement */ +#define PHY_LP_ABILITY 0x05 /* Link Partner Ability (Base Page) */ +#define PHY_AUTONEG_EXP 0x06 /* Autoneg Expansion Reg */ +#define PHY_NEXT_PAGE_TX 0x07 /* Next Page TX */ +#define PHY_LP_NEXT_PAGE 0x08 /* Link Partner Next Page */ +#define PHY_1000T_CTRL 0x09 /* 1000Base-T Control Reg */ +#define PHY_1000T_STATUS 0x0A /* 1000Base-T Status Reg */ +#define PHY_EXT_STATUS 0x0F /* Extended Status Reg */ + +#define NUM_PHY_REGS 0x20 /* 5 bit address bus (0-0x1F) */ + +#define PHY_CTRL_RST 0x8000 /* PHY reset command */ +#define PHY_CTRL_ANEG_RST 0x0200 /* Autonegotiation reset command */ + +/* PHY Advertisement control and remote capability registers (same bitfields) */ #define PHY_ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */ #define PHY_ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */ #define PHY_ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */ #define PHY_ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */ struct qemu_phy { - uint32_t regs[32]; + uint32_t regs[NUM_PHY_REGS]; int link; diff --git a/hw/net/mdio.c b/hw/net/mdio.c index 3763fcc8af..3d70d99077 100644 --- a/hw/net/mdio.c +++ b/hw/net/mdio.c @@ -122,12 +122,12 @@ static void tdk_write(struct qemu_phy *phy, unsigned int req, unsigned int data) void tdk_init(struct qemu_phy *phy) { - phy->regs[0] = 0x3100; + phy->regs[PHY_CTRL] = 0x3100; /* PHY Id. */ - phy->regs[2] = 0x0300; - phy->regs[3] = 0xe400; + phy->regs[PHY_ID1] = 0x0300; + phy->regs[PHY_ID2] = 0xe400; /* Autonegotiation advertisement reg. */ - phy->regs[4] = 0x01e1; + phy->regs[PHY_AUTONEG_ADV] = 0x01e1; phy->link = 1; phy->read = tdk_read; From patchwork Fri Sep 22 17:13:19 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: 114066 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3534868qgf; Fri, 22 Sep 2017 10:14:28 -0700 (PDT) X-Received: by 10.200.8.225 with SMTP id y30mr9409398qth.233.1506100468887; Fri, 22 Sep 2017 10:14:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506100468; cv=none; d=google.com; s=arc-20160816; b=AHMN7HZWkPtuQ7KRPwLAMCJFm13V2AuYOGCaIUXRyiWI890TxLGmI5PJFpSBcwCh3W jxvh+9PBhukxwG8FWVyhkQqQ7rXh2H6RC7b/5QM3IjNISqtFuVscTmR0RC09jPQKkYGa OQDVL5pmjOGiAV7FM31Nhd67xdOH+VdilIdKcmLF1wZ0hE43AVC6m3oU2lZIScHUcmcO TPYPVsIjvU6fYs0VYQhlghUFurWot/4w1lxlif6HC8QEOYhndFzTEmdxaVb5qLFstIz7 d4fnKHDuccBOtXVotWcoTUFg9kpAI3E49gqjmpg6ehkDGDIDy7gIwZDDxs/bmU37/zPp 4gPw== 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=jCs+7aCSuo0aq+jzG5++EzGklGRDA53oMWn9sbBVFsw=; b=o+jhufm89tlghMjW+jKWOnLtRV3/iV1xW6khxuMRL28b42SPRYEGfVqfAZQnK2F3iA QqzXsKFnH3acaqK7P2QkuWkiN7qP8t4ktj5Pf8zxx+9welC0TvbUAnfKbH2VSHiw5l/6 dmtCxkenzAu21lFrvfk6M9ycd/KNvDEh8W8e98tfAqwWO79yVFijDtwZZlBYXWohDQP2 oxKSen9gyBBnkKemoI80TqvqLtK3EQcMI1+jpbYyKKjtrUhwN77ERwH3fQZgzsNxkY8P NJYZ9skZ1nOHiCWCHmHISgi399wMliEGuj83G4xLaCZUrqIT7mitUIZiNcck9+bKr7Go IZ8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YLeeiRAm; 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 s6si213857qkd.525.2017.09.22.10.14.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Sep 2017 10:14:28 -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=YLeeiRAm; 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]:60285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRX0-0003gz-KM for patch@linaro.org; Fri, 22 Sep 2017 13:14:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59391) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRWQ-0003KE-BS for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvRWP-0003TU-3d for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:50 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:37391) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvRWO-0003TF-Ur; Fri, 22 Sep 2017 13:13:49 -0400 Received: by mail-qt0-x243.google.com with SMTP id u48so1045059qtc.4; Fri, 22 Sep 2017 10:13:48 -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=jCs+7aCSuo0aq+jzG5++EzGklGRDA53oMWn9sbBVFsw=; b=YLeeiRAm0VUquG/5X8LwPPrSgjE97CwpNLDMl8nk+O+lJTez84dGyJSbOwKh4bSEYE Zzk5+LcVVrZdQ4qQ0WqUp9qRLmoTLYW4jrTonBl5io/+SHOq1oAzHyA54qKiXmfOEPp1 Chue8LcGCZ6vPe0ZWkf+NaF0IdRMznFOvkn6DAGCR6itNo572eYJRbtOTCJEm2Fcu3dl O8/BpJTE3QAB8XVblnlpaJtNMRrrIYukepkgAeQfL61bBswu4iTXzga0gf/tPdTgLn1/ uYYBuEUVqdrjmgZdg/mHmOY36bRhf7Qx28+GA403uazPHAPctlzx2y2pALDWBCzLEBj/ rUbg== 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=jCs+7aCSuo0aq+jzG5++EzGklGRDA53oMWn9sbBVFsw=; b=PTDz20lJS18CWKqDJxuhXxNUCSs87VoNtDQDwwmaUhZCS7BUpPM8e6zFPpA9ZqO2Bw iq8TNySi3qDTcqZqzTOH9o3Di7W31+dIR8Y82jktIE5noFR9uygTjltEq02NB/kMpBoE Q1wvHHwx80L0Ax3h0JtdoBs96hgkbvSK/RAhfEWAfIrzDWZOJQLDpdyxScc1FajaR/Iw wJpkb4etq0KOYRmfuBbTchZHVnEHqsIuFpsvk1aNmrvDFXTeT+wpFFTqpDjlXLbKWEVF Um2/dZsJi0WGn/aaGHC4jFIF3ZOPQ47eQVb9JhNqdjrg5xTcGznwyZIi2F5g7Kf8V1UG FE1Q== X-Gm-Message-State: AHPjjUjQug8SpCSxt3XSgR/aFPmk7gaOpQBQDh1t3SpaJtnyuPMpaxo0 fxrOPgT5lBHtJ3+4Ub0yP1Y= X-Google-Smtp-Source: AOwi7QDVzy6vUZzcLCl9Od/fHGIiJ78o0vmMgVRtMESEj/wlmblcJcY78cDCs9Pd08/R9vysomowBw== X-Received: by 10.200.33.131 with SMTP id 3mr7516611qty.177.1506100428426; Fri, 22 Sep 2017 10:13:48 -0700 (PDT) Received: from yoga.lan ([181.93.89.178]) by smtp.gmail.com with ESMTPSA id f69sm238468qke.27.2017.09.22.10.13.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2017 10:13:47 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Peter Maydell , Grant Likely , Jason Wang , "Edgar E. Iglesias" , Alistair Francis , Fam Zheng , =?utf-8?q?Andreas_F=C3=A4rber?= Date: Fri, 22 Sep 2017 14:13:19 -0300 Message-Id: <20170922171323.10348-4-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:c0d::243 Subject: [Qemu-devel] [PATCH v5 3/7] hw/mdio: Generalize phy initialization routine 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-arm@nongnu.org, qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu?= =?utf-8?q?-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Grant Likely There really isn't anything tdk-specific about tdk_init() other than the phy id registers. The function should instead be generalized for any phy, at least as far as the ID registers are concerned. For the most part the read/write behaviour should be very similar across PHYs. This patch renames tdk_{read,write,init}() to mdio_phy_*() so it can be used for any PHY. More work definitely needs to be done here to make it easy to override the default behaviour for specific PHYs, but this at least is a reasonable start. Signed-off-by: Grant Likely Signed-off-by: Philippe Mathieu-Daudé [PMD: just rebased] --- include/hw/net/mdio.h | 2 +- hw/net/etraxfs_eth.c | 2 +- hw/net/mdio.c | 14 +++++++------- hw/net/xilinx_axienet.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) -- 2.14.1 diff --git a/include/hw/net/mdio.h b/include/hw/net/mdio.h index 7ffa4389b9..b3b4f497c0 100644 --- a/include/hw/net/mdio.h +++ b/include/hw/net/mdio.h @@ -86,7 +86,7 @@ struct qemu_mdio { struct qemu_phy *devs[32]; }; -void tdk_init(struct qemu_phy *phy); +void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2); void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr); uint16_t mdio_read_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req); diff --git a/hw/net/etraxfs_eth.c b/hw/net/etraxfs_eth.c index f8d8f8441d..4c5415771f 100644 --- a/hw/net/etraxfs_eth.c +++ b/hw/net/etraxfs_eth.c @@ -333,7 +333,7 @@ static int fs_eth_init(SysBusDevice *sbd) qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); - tdk_init(&s->phy); + mdio_phy_init(&s->phy, 0x0300, 0xe400); mdio_attach(&s->mdio_bus, &s->phy, s->phyaddr); return 0; } diff --git a/hw/net/mdio.c b/hw/net/mdio.c index 3d70d99077..33bfbb4623 100644 --- a/hw/net/mdio.c +++ b/hw/net/mdio.c @@ -43,7 +43,7 @@ * linux driver (PHYID and Diagnostics reg). * TODO: Add friendly names for the register nums. */ -static unsigned int tdk_read(struct qemu_phy *phy, unsigned int req) +static unsigned int mdio_phy_read(struct qemu_phy *phy, unsigned int req) { int regnum; unsigned r = 0; @@ -107,7 +107,7 @@ static unsigned int tdk_read(struct qemu_phy *phy, unsigned int req) return r; } -static void tdk_write(struct qemu_phy *phy, unsigned int req, unsigned int data) +static void mdio_phy_write(struct qemu_phy *phy, unsigned int req, unsigned int data) { int regnum; @@ -120,18 +120,18 @@ static void tdk_write(struct qemu_phy *phy, unsigned int req, unsigned int data) } } -void tdk_init(struct qemu_phy *phy) +void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2) { phy->regs[PHY_CTRL] = 0x3100; /* PHY Id. */ - phy->regs[PHY_ID1] = 0x0300; - phy->regs[PHY_ID2] = 0xe400; + phy->regs[PHY_ID1] = id1; + phy->regs[PHY_ID2] = id2; /* Autonegotiation advertisement reg. */ phy->regs[PHY_AUTONEG_ADV] = 0x01e1; phy->link = 1; - phy->read = tdk_read; - phy->write = tdk_write; + phy->read = mdio_phy_read; + phy->write = mdio_phy_write; } void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr) diff --git a/hw/net/xilinx_axienet.c b/hw/net/xilinx_axienet.c index 1e859fdaae..408cd6e675 100644 --- a/hw/net/xilinx_axienet.c +++ b/hw/net/xilinx_axienet.c @@ -791,7 +791,7 @@ static void xilinx_enet_realize(DeviceState *dev, Error **errp) object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); - tdk_init(&s->TEMAC.phy); + mdio_phy_init(&s->TEMAC.phy, 0x0300, 0xe400); mdio_attach(&s->TEMAC.mdio_bus, &s->TEMAC.phy, s->c_phyaddr); s->TEMAC.parent = s; From patchwork Fri Sep 22 17:13:20 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: 114069 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3539092qgf; Fri, 22 Sep 2017 10:18:44 -0700 (PDT) X-Received: by 10.55.98.214 with SMTP id w205mr8263132qkb.355.1506100724289; Fri, 22 Sep 2017 10:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506100724; cv=none; d=google.com; s=arc-20160816; b=g7KdqyH/AStrb4GbIAi8sPNdZHZ1TQU6Y/8GmTb613P6MgFkI6Bx0qDOQ9UB9YGXYd ZhAC2XpdGNlpT278+gkgp5POFO6ggKxNC4LCF9055JPiuvNBD0hkFwL5Muj9CU642Oqx iZbQEIOVwPWaDXMNYIrPxYq+7CMH/7N8j1jTD2+O7NfTcWiM5zXBOyZ/duvwVoyOKizY rQlZLSILYS08dlMQ7wP+jVFIrUQL7VTB5v0g6DT8H8ADu6zqeYvfYXFV9pY8pcL30+0L CW142In1Zw3jH/V8I4yLNZnBc3j8G22ON1RImQxQhYv0H3bL0jIXHeiUsptVdFQDGPTN GzDw== 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=rxMyLB2uMtPH+zMkI5VbbZoqC3EDT+m6CVY44lTEBi4=; b=b00G5t0l3+BsMZp+QvOYKB4WRPI7i2ht7dk8qHJ5pts30oVXNq6SP6MyhVGPyIa9ug j4kDKEMGCxJpZy5d2pcq9TeoS3NWHp8Cy3J8hvQtVAOF5M1ohgzmvzbEUhk7vl2STqhm L3+h8RKOEZfAs1QC6QKeOhqb3uRtWj/FPjILW6fZ4DundgL6RbbjhJahD+d5arBYhVg4 vziU8zNu0/FspSOOAjzyE02A32mNI8oqOCqKnMcG1myoNSFerRRA6C8OJhtB3h1Pw0Dk y6OQkpwQQNSCRyutC8za1ACPl/DBnMFwHQ6VshHLRq0DOBLekjzRsvrQV2i8pJj574ca +Myw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ZcfO/pze; 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 c26si248486qtg.391.2017.09.22.10.18.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Sep 2017 10:18:44 -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=ZcfO/pze; 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]:60303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRb8-000827-96 for patch@linaro.org; Fri, 22 Sep 2017 13:18:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRWT-0003WF-NI for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvRWR-0003Vg-Kl for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:53 -0400 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:38070) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvRWR-0003VW-Gn for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:51 -0400 Received: by mail-qk0-x241.google.com with SMTP id c69so1021460qke.5 for ; Fri, 22 Sep 2017 10:13:51 -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=rxMyLB2uMtPH+zMkI5VbbZoqC3EDT+m6CVY44lTEBi4=; b=ZcfO/pzeZwwQivDlrW2iP1XSRNNOnI2VnAJYWjvF883p0QyuL/9o4RkxguUYK81YIg wHRvTsy2LD0CNakWA5xEPi76v9LEM+R0QXmCZf+5/W3/P4MZ1IcPBKP3kXDUKWJnEaLL MgctFPGV4ZyIW5zwW2NM1tYjsM6BKXvBpPr2kv5k/URPpsJ+bCyJaT0r+EKPSyNjG+79 pJbCLetur5NINhn4YjRO2xN5TdJFY2K6x8Qty92lexhPnvxk7P2P4YWc6yEyGuogSZPm a7yde52mR4QeeB5DvUE39X2uFR1lTKPL90ucBWQTRIgkpcXQG/BEZebs2SUghK04SwQ+ 0dTQ== 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=rxMyLB2uMtPH+zMkI5VbbZoqC3EDT+m6CVY44lTEBi4=; b=gn4rQOE7fULbb33aXM8bOsFW6Go3cCXvNNAwDxBxx30AYbpc4nkbVu0QvYmM+ltMNj V2CsYijAhh9lWCuP5u4c+iIuCBiyjHfcatzW014ibVUkB8l7BtP7Wtn4rbj5WuMU9uBo V+3zfA8qQLI3Kd+9UXx1Ug0wnNAkaVHyYSZNotd6HirmUwoq4ykWS5Dm/67+2LtjMYac ahaklNRlrYOgWDD6S6vBfnKHIzYn+M92jo1Yj7+7Ixz8caCFCFSRfLprPKvI/diSOOAy A4Xj/WoyHBAd1m09oJEglUQ42WsFufwxr+IUaBUapjw2ZzRWj6ByWUw9dQj1Hb9SaDYq 5aRw== X-Gm-Message-State: AHPjjUgzgwhfCFCXBJnc9Nf+jWUC8AIE1wT44DRlCHREJTC2lOWlnkwB p8JxUeYmDAMlsRaq1XZQ5fo= X-Google-Smtp-Source: AOwi7QCvjnvA+3j/ZRTK/+ZALDhOvHyc1f7sbh3T9jWSxIiSfer3ncRVhuWQWl3YPfubtZBhE43JTQ== X-Received: by 10.55.87.135 with SMTP id l129mr9063888qkb.182.1506100431003; Fri, 22 Sep 2017 10:13:51 -0700 (PDT) Received: from yoga.lan ([181.93.89.178]) by smtp.gmail.com with ESMTPSA id f69sm238468qke.27.2017.09.22.10.13.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2017 10:13:50 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Peter Maydell , Grant Likely , Jason Wang Date: Fri, 22 Sep 2017 14:13:20 -0300 Message-Id: <20170922171323.10348-5-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::241 Subject: [Qemu-devel] [PATCH v5 4/7] hw/mdio: Mask out read-only bits. 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 RST and ANEG_RST bits are commands, not settings. An operating system will get confused (or at least u-boot does) if those bits remain set after writing to them. Therefore, mask them out on write. Similarly, no bits in the ID1, ID2, and remote capability registers are writeable; so mask them out also. Signed-off-by: Grant Likely Signed-off-by: Philippe Mathieu-Daudé [PMD: just rebased] --- include/hw/net/mdio.h | 1 + hw/net/mdio.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) -- 2.14.1 diff --git a/include/hw/net/mdio.h b/include/hw/net/mdio.h index b3b4f497c0..ed1879a728 100644 --- a/include/hw/net/mdio.h +++ b/include/hw/net/mdio.h @@ -53,6 +53,7 @@ struct qemu_phy { uint32_t regs[NUM_PHY_REGS]; + const uint16_t *regs_readonly_mask; /* 0=writable, 1=read-only */ int link; diff --git a/hw/net/mdio.c b/hw/net/mdio.c index 33bfbb4623..89a6a3a590 100644 --- a/hw/net/mdio.c +++ b/hw/net/mdio.c @@ -109,17 +109,24 @@ static unsigned int mdio_phy_read(struct qemu_phy *phy, unsigned int req) static void mdio_phy_write(struct qemu_phy *phy, unsigned int req, unsigned int data) { - int regnum; + int regnum = req & 0x1f; + uint16_t mask = phy->regs_readonly_mask[regnum]; - regnum = req & 0x1f; - D(printf("%s reg[%d] = %x\n", __func__, regnum, data)); + D(printf("%s reg[%d] = %x; mask=%x\n", __func__, regnum, data, mask)); switch (regnum) { default: - phy->regs[regnum] = data; + phy->regs[regnum] = (phy->regs[regnum] & mask) | (data & ~mask); break; } } +static const uint16_t default_readonly_mask[32] = { + [PHY_CTRL] = PHY_CTRL_RST | PHY_CTRL_ANEG_RST, + [PHY_ID1] = 0xffff, + [PHY_ID2] = 0xffff, + [PHY_LP_ABILITY] = 0xffff, +}; + void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2) { phy->regs[PHY_CTRL] = 0x3100; @@ -128,6 +135,7 @@ void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2) phy->regs[PHY_ID2] = id2; /* Autonegotiation advertisement reg. */ phy->regs[PHY_AUTONEG_ADV] = 0x01e1; + phy->regs_readonly_mask = default_readonly_mask; phy->link = 1; phy->read = mdio_phy_read; From patchwork Fri Sep 22 17:13:21 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: 114065 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3534820qgf; Fri, 22 Sep 2017 10:14:26 -0700 (PDT) X-Received: by 10.200.56.184 with SMTP id f53mr8740269qtc.139.1506100466146; Fri, 22 Sep 2017 10:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506100466; cv=none; d=google.com; s=arc-20160816; b=x7tWv94hgTy5FV4J8mgWKDREl4z/eQ4vOn0s/+judqGA4aEk3GzOaPcsVByilbATY9 hMeNtOi1xKrgqPdwgAnAF1UYylGijnMqEE4lfcbXSRhatM2eGvNPz8e0yBor1PQmbuYM RFwTQcLa7pqajDHr2z1SV3Jn8OlEM+TXaj46K/6QZNG9Yqee38zeGokqRwYutivtXcmq sVy5IWxNXlRuPFhyR6slZ2PyEl4lW7I2aEBBVKUX5CsERgOruRNdkAQGsXOOSiKBtcL6 OpHb8PVTGHOYQBtMoA9y3kh6I6ZHWqqW7dH02oHLBhl6J6+OLG4l0uAO85yzglsSvtrN MVnQ== 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=RlV+UKksAkV+37i3nDePyzlUjXAz8TI33VoE13qtgXY=; b=pViCmPGI8LW0JseaQSIsnnSGeeHm4c2aQWRKDeZfSU1bo2ZcCbn/2Xgz5spS3jP4JG ohybkjp9jYL107FBGr5TZVE4aJaF2wb0Klni3V1neha7ZZLNDSecTVApKiZZNZ/EpRlK YrNkYG/ZrUgLhKWoPIbi1dvu+YC68Yb07JOXbUzTpAivDURZ9Xd3E+fvPTjeIrqWDLxo a/vaWHRtmHB8pQffcEcVG3yR2GVXQkcUwOdyE568fFPVtpV5+cL7rn34bpckoYAaCKe9 RPnzs/0wcgLGyYHUC4EVnEx/t/Es8yA9dNRGG1YbqEVJP4PSZWO7D8hW/f0u9IpwCHoj MU1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=qFfaHUty; 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 o123si224365qkd.308.2017.09.22.10.14.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Sep 2017 10:14:26 -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=qFfaHUty; 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]:60284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRWx-0003de-ON for patch@linaro.org; Fri, 22 Sep 2017 13:14:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59434) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRWW-0003Zl-I7 for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvRWU-0003Xn-Lr for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:56 -0400 Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]:36708) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvRWU-0003Wu-GZ for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:54 -0400 Received: by mail-qk0-x244.google.com with SMTP id i14so1025392qke.3 for ; Fri, 22 Sep 2017 10:13:54 -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=RlV+UKksAkV+37i3nDePyzlUjXAz8TI33VoE13qtgXY=; b=qFfaHUtym48GrRLTLg887ESkgBlFF3fNHsp2EAY3WKUaPyLLm2Qt4I2ykn2XbqQMGV X7+KiC1suKxc8G2Ob80pZFVSUBwgo+CDHaC9/mEht64ek1UTYpFC1Mv3kWiymBQbxhv7 MXd+ntcz7Zouf0+5lXX/ai7hBPdEhugzueqUYkyjjc9UxzIYSSr+N/RqydEMPNRTUGRN WlkSzGpHJSAbpmqiMepQp9Ysz5RhhAi0td49qdwDiEVv9vE4gBLvfLNA3hnwhzcQJZsk w4XcK/BjtAFKPpZ5NA0u2EA9DfXogBem1X9YYhCWAUqumTj1IK6fYcIz/CoFCSk0pm2L j8pg== 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=RlV+UKksAkV+37i3nDePyzlUjXAz8TI33VoE13qtgXY=; b=ez1Zq79khX2O7AhbgIGDGamjnKsTdd5nbcpXMQE9IvPXTj/3foQX/CIZcoCpg4Dqwx r3Wkf090r31enApB9x5iti17EQsjZOs/V3XDkIvuNejXI+k5oiUnUj4cakAmXKcoT0Mn oV2EP6EVsbnSfc3nv1Yi28DkAatdZi+b2etE6qKX24BKxbFHZqVkiT+9htWfO68Uo3IL rVA6baL5aEu/0d9h0kk3wTdxjoV7pXWzRvxXkHWzB//7U1gJh/wuwBhJbQkA0yuuMtXW gUEyLTtzUp+4YBnv0u9CshTI3yRkZeLZp3rnz2QMViFwbJSz0Y7ZGkwWIs4RA5oV5zJb tkzg== X-Gm-Message-State: AHPjjUgzSn898n6wMmDuCbNIzy/th/DXPfnxV72soWis4pphj7FjHFPp +HurRQAc4tedPF76tq4N3Fw= X-Google-Smtp-Source: AOwi7QCrQadcZ75w8oIvsYc37Ii8SFU0MftGP5ZORh/tkKwjh8gm4/hN4OGMQFamrWxi/1UuOREAuQ== X-Received: by 10.55.141.66 with SMTP id p63mr1625658qkd.314.1506100433928; Fri, 22 Sep 2017 10:13:53 -0700 (PDT) Received: from yoga.lan ([181.93.89.178]) by smtp.gmail.com with ESMTPSA id f69sm238468qke.27.2017.09.22.10.13.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2017 10:13:53 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Peter Maydell , "Edgar E. Iglesias" , Grant Likely , Jason Wang Date: Fri, 22 Sep 2017 14:13:21 -0300 Message-Id: <20170922171323.10348-6-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::244 Subject: [Qemu-devel] [PATCH v5 5/7] hw/mdio: Refactor bitbanging state machine 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 MDIO state machine has a moderate amount of duplicate code in the state processing that can be consolidated. This patch does so and reorganizes it a bit so that far less code is required. Most of the states simply stream a fixed number of bits in as a single integer and can be handled by a common processing function that checks for completion of the state and returns the streamed in value. Changes include: - Move clock state change tracking into core code - Use a common shift register for clocking data in and out - Create separate mdc & mdio accessor functions - will be replaced with GPIO connection in a follow-on patch Signed-off-by: Grant Likely Signed-off-by: Philippe Mathieu-Daudé [PMD: just rebased] --- include/hw/net/mdio.h | 41 ++++++++------- hw/net/etraxfs_eth.c | 11 ++-- hw/net/mdio.c | 140 ++++++++++++++++++++++---------------------------- 3 files changed, 87 insertions(+), 105 deletions(-) -- 2.14.1 Acked-by: Alistair Francis diff --git a/include/hw/net/mdio.h b/include/hw/net/mdio.h index ed1879a728..7fca19784e 100644 --- a/include/hw/net/mdio.h +++ b/include/hw/net/mdio.h @@ -52,37 +52,33 @@ #define PHY_ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */ struct qemu_phy { - uint32_t regs[NUM_PHY_REGS]; + uint16_t regs[NUM_PHY_REGS]; const uint16_t *regs_readonly_mask; /* 0=writable, 1=read-only */ - int link; + bool link; - unsigned int (*read)(struct qemu_phy *phy, unsigned int req); - void (*write)(struct qemu_phy *phy, unsigned int req, unsigned int data); + uint16_t (*read)(struct qemu_phy *phy, unsigned int req); + void (*write)(struct qemu_phy *phy, unsigned int req, uint16_t data); }; struct qemu_mdio { - /* bus. */ - int mdc; - int mdio; - - /* decoder. */ + /* bitbanging state machine */ + bool mdc; + bool mdio; enum { PREAMBLE, - SOF, OPC, ADDR, REQ, TURNAROUND, DATA } state; - unsigned int drive; - unsigned int cnt; - unsigned int addr; - unsigned int opc; - unsigned int req; - unsigned int data; + uint16_t cnt; /* Bit count for current state */ + uint16_t addr; /* PHY Address; retrieved during ADDR state */ + uint16_t opc; /* Operation; 2:read */ + uint16_t req; /* Register address */ + uint32_t shiftreg; /* shift register; bits in to or out from PHY */ struct qemu_phy *devs[32]; }; @@ -91,7 +87,16 @@ void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2); void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr); uint16_t mdio_read_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req); -void mdio_write_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req, uint16_t data); -void mdio_cycle(struct qemu_mdio *bus); +void mdio_write_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req, + uint16_t data); +void mdio_bitbang_set_clk(struct qemu_mdio *bus, bool mdc); +static inline void mdio_bitbang_set_data(struct qemu_mdio *bus, bool mdio) +{ + bus->mdio = mdio; +} +static inline bool mdio_bitbang_get_data(struct qemu_mdio *bus) +{ + return bus->mdio; +} #endif diff --git a/hw/net/etraxfs_eth.c b/hw/net/etraxfs_eth.c index 4c5415771f..1b518ea16e 100644 --- a/hw/net/etraxfs_eth.c +++ b/hw/net/etraxfs_eth.c @@ -119,7 +119,7 @@ eth_read(void *opaque, hwaddr addr, unsigned int size) switch (addr) { case R_STAT: - r = eth->mdio_bus.mdio & 1; + r = mdio_bitbang_get_data(ð->mdio_bus); break; default: r = eth->regs[addr]; @@ -177,13 +177,10 @@ eth_write(void *opaque, hwaddr addr, case RW_MGM_CTRL: /* Attach an MDIO/PHY abstraction. */ if (value & 2) { - eth->mdio_bus.mdio = value & 1; + mdio_bitbang_set_data(ð->mdio_bus, value & 1); } - if (eth->mdio_bus.mdc != (value & 4)) { - mdio_cycle(ð->mdio_bus); - eth_validate_duplex(eth); - } - eth->mdio_bus.mdc = !!(value & 4); + mdio_bitbang_set_clk(ð->mdio_bus, value & 4); + eth_validate_duplex(eth); eth->regs[addr] = value; break; diff --git a/hw/net/mdio.c b/hw/net/mdio.c index 89a6a3a590..96e10fada0 100644 --- a/hw/net/mdio.c +++ b/hw/net/mdio.c @@ -43,7 +43,7 @@ * linux driver (PHYID and Diagnostics reg). * TODO: Add friendly names for the register nums. */ -static unsigned int mdio_phy_read(struct qemu_phy *phy, unsigned int req) +static uint16_t mdio_phy_read(struct qemu_phy *phy, unsigned int req) { int regnum; unsigned r = 0; @@ -107,7 +107,8 @@ static unsigned int mdio_phy_read(struct qemu_phy *phy, unsigned int req) return r; } -static void mdio_phy_write(struct qemu_phy *phy, unsigned int req, unsigned int data) +static void mdio_phy_write(struct qemu_phy *phy, unsigned int req, + uint16_t data) { int regnum = req & 0x1f; uint16_t mask = phy->regs_readonly_mask[regnum]; @@ -136,13 +137,14 @@ void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2) /* Autonegotiation advertisement reg. */ phy->regs[PHY_AUTONEG_ADV] = 0x01e1; phy->regs_readonly_mask = default_readonly_mask; - phy->link = 1; + phy->link = true; phy->read = mdio_phy_read; phy->write = mdio_phy_write; } -void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr) +void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, + unsigned int addr) { bus->devs[addr & 0x1f] = phy; } @@ -169,99 +171,77 @@ void mdio_write_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req, } } -void mdio_cycle(struct qemu_mdio *bus) +/** + * mdio_bitbang_update() - internal function to check how many clocks have + * passed and move to the next state if necessary. Returns TRUE on state change. + */ +static bool mdio_bitbang_update(struct qemu_mdio *bus, int num_bits, int next, + uint16_t *reg) { + if (bus->cnt < num_bits) { + return false; + } + if (reg) { + *reg = bus->shiftreg; + } + bus->state = next; + bus->cnt = 0; + bus->shiftreg = 0; + return true; +} + +/** + * mdio_bitbang_set_clk() - set value of mdc signal and update state + */ +void mdio_bitbang_set_clk(struct qemu_mdio *bus, bool mdc) +{ + uint16_t tmp; + + if (mdc == bus->mdc) { + return; /* Clock state hasn't changed; do nothing */ + } + + bus->mdc = mdc; + if (bus->mdc) { + /* Falling (inactive) clock edge */ + if ((bus->state == DATA) && (bus->opc == 2)) { + bus->mdio = !!(bus->shiftreg & 0x8000); + } + return; + } + + /* Rising clock Edge */ + bus->shiftreg = (bus->shiftreg << 1) | bus->mdio; bus->cnt++; - D(printf("mdc=%d mdio=%d state=%d cnt=%d drv=%d\n", - bus->mdc, bus->mdio, bus->state, bus->cnt, bus->drive)); + bus->mdc, bus->mdio, bus->state, bus->cnt)); switch (bus->state) { case PREAMBLE: - if (bus->mdc) { - if (bus->cnt >= (32 * 2) && !bus->mdio) { - bus->cnt = 0; - bus->state = SOF; - bus->data = 0; - } - } - break; - case SOF: - if (bus->mdc) { - if (bus->mdio != 1) { - printf("WARNING: no SOF\n"); - } - if (bus->cnt == 1 * 2) { - bus->cnt = 0; - bus->opc = 0; - bus->state = OPC; - } + /* MDIO must be 30 clocks high, 1 low, and 1 high to get out of + preamble */ + if (bus->shiftreg == 0xfffffffd) { + mdio_bitbang_update(bus, 0, OPC, NULL); } break; case OPC: - if (bus->mdc) { - bus->opc <<= 1; - bus->opc |= bus->mdio & 1; - if (bus->cnt == 2 * 2) { - bus->cnt = 0; - bus->addr = 0; - bus->state = ADDR; - } - } + mdio_bitbang_update(bus, 2, ADDR, &bus->opc); break; case ADDR: - if (bus->mdc) { - bus->addr <<= 1; - bus->addr |= bus->mdio & 1; - - if (bus->cnt == 5 * 2) { - bus->cnt = 0; - bus->req = 0; - bus->state = REQ; - } - } + mdio_bitbang_update(bus, 5, REQ, &bus->addr); break; case REQ: - if (bus->mdc) { - bus->req <<= 1; - bus->req |= bus->mdio & 1; - if (bus->cnt == 5 * 2) { - bus->cnt = 0; - bus->state = TURNAROUND; - } - } + mdio_bitbang_update(bus, 5, TURNAROUND, &bus->req); break; case TURNAROUND: - if (bus->mdc && bus->cnt == 2 * 2) { - bus->mdio = 0; - bus->cnt = 0; - - if (bus->opc == 2) { - bus->drive = 1; - bus->data = mdio_read_req(bus, bus->addr, bus->req); - bus->mdio = bus->data & 1; - } - bus->state = DATA; + /* If beginning of DATA READ cycle, then read PHY into shift register */ + if (mdio_bitbang_update(bus, 2, DATA, NULL) && (bus->opc == 2)) { + bus->shiftreg = mdio_read_req(bus, bus->addr, bus->req); } break; case DATA: - if (!bus->mdc) { - if (bus->drive) { - bus->mdio = !!(bus->data & (1 << 15)); - bus->data <<= 1; - } - } else { - if (!bus->drive) { - bus->data <<= 1; - bus->data |= bus->mdio; - } - if (bus->cnt == 16 * 2) { - bus->cnt = 0; - bus->state = PREAMBLE; - if (!bus->drive) { - mdio_write_req(bus, bus->addr, bus->req, bus->data); - } - bus->drive = 0; - } + /* If end of DATA WRITE cycle, then write shift register to PHY */ + if (mdio_bitbang_update(bus, 16, PREAMBLE, &tmp) && (bus->opc == 1)) { + mdio_write_req(bus, bus->addr, bus->req, tmp); } break; default: From patchwork Fri Sep 22 17:13:22 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: 114068 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3537706qgf; Fri, 22 Sep 2017 10:17:18 -0700 (PDT) X-Received: by 10.55.127.70 with SMTP id a67mr8459814qkd.90.1506100638367; Fri, 22 Sep 2017 10:17:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506100638; cv=none; d=google.com; s=arc-20160816; b=EDkurZNmq0isqxYl7+M8qBRnh74vqioKvUyAfmS4fd606rjMM9yo4ekQNvppXrMC7k EUd1W3DBpTSRL/qQHqehx/7ONg4zdkTEC8VjlLH7+onhwZsbJWRtdFgEoJXQMufGr1sR 6HZWWvP8Uj1hO3nWGhRhE7O+fMdW6lvMZ/u81wm2w1hDkpygBpgH3j3aL9dp1Z676ZVG +j5feS5rT3xXZqZHtzqVa6jkX9QrTn0KrTTdOvROhnbOKV2PpzJGhwjE3s5ejTkHtIR6 RYlGlW1GBfVUw+S9Yp38OnwSyeqpyDf1DBazhDO/S5SBL6zFIVHcIjudj40Uvpw66IZd lIow== 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=/uYu4uuFxDkoaslS0IXjyrZpP1KOsmMM+Jx/vmcm260=; b=yv49mQ/NFfKPBSmfmVjn+vT5r0imfkgkvFBikQT1pHJ19k4ZViWYObfXm2oyhsKtMl FiFua5V7QqCSRUGKVeEqjge9ucoSz0IdgqEXOJOAomIGmFXd5boquODGl6Jqwjw6J4+U uXPNZoNeOiRfQjDvKlL2wWwAcKb4LQpyv5zFsTLDs02WAV07YF//z5/wiL1WEOHeE4Ng tJ5NE8S26e84Uv4TZBPdR8R7lp7t/vMhO9vSkUC8P8UPol2VkQ4bsL5g6McfM/G2JsRi XKpjJJylZS99on3tW2twTO+fHzHbct2R9bsxquaxZFgoWuELR2D7UZNHTYmOWn3AnBvo RnWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UEgrMXkQ; 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 o29si246997qtc.347.2017.09.22.10.17.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Sep 2017 10:17:18 -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=UEgrMXkQ; 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]:60300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRZk-0006rH-Ar for patch@linaro.org; Fri, 22 Sep 2017 13:17:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRWX-0003bE-Un for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvRWW-0003ZK-QP for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:57 -0400 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:34738) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvRWW-0003Z4-M6 for qemu-devel@nongnu.org; Fri, 22 Sep 2017 13:13:56 -0400 Received: by mail-qk0-x241.google.com with SMTP id d70so1028194qkc.1 for ; Fri, 22 Sep 2017 10:13:56 -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=/uYu4uuFxDkoaslS0IXjyrZpP1KOsmMM+Jx/vmcm260=; b=UEgrMXkQj/aRiYqXl7o6iS8Pda9PmW3IaeZGJhNd4JFmXDi3SCHJh+aQ0eCMmEoaXQ WYII1m4/Ls5ES99MrBKOX4d+HOpCuKiz6I5GEYFTaAgxdaZCw9x8OHIfVqY7bLPmPIup Hk9JVRSiZhMh910etJYpvWHfZIf7eln0Lj/7LB+vo3EZsYNx1bxVbgByYluZ86975p7A UsB9tXj++vvLOOFs4DpXRwfgrnf6WKt+p5BlmvZ2/l6T/S/S9yKbZj3picaNRzmMO3Gh /AMaAbMvKDB3iLITiTrqRb32/T5cCWcyTl+n1k8q63zBL7G2C6zkqNOLWlR+ouYnsiVz akMQ== 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=/uYu4uuFxDkoaslS0IXjyrZpP1KOsmMM+Jx/vmcm260=; b=TMtvem+YWNu4QkNNPpAYOnML6ByLUmmvq2tK5DOX9rMcyQtPHBzbB7ZX4m3WeCakQR JCmCcuiSgZscPCQ6f701GtqD+fEmU65YAeM9O17RHHQXqCp38fhvhpjGu8I4uPoe+Lpx NJeCPBG+EctO8NLS0ZiizBfyjsUeO/gI9K7hXp7yHyAq5W4MryI5gddaWFU4o7ISqI3T pjflW1F0/p39WI4+xBXrS6EL3ZQMLjvtAUb3Q0TWFe7TPLEElnnuLMYjbzMtQO6AokUn h1j60XTrlwNfCKo5WkF7Cym4caLoXmHtHtjMaIXbx1kVMCy9XEa/NFy0vq3ofOIOmXNt NwGA== X-Gm-Message-State: AHPjjUj7YBoKcmz1BliOQqut239wMaSIGXH+LdmhrL8EgK2fbvXL48xP KFjhPfkDXNXuOq6Vv8jwVnA= X-Google-Smtp-Source: AOwi7QC/b5kxFgJ6ELzkvdUw+IBPLCzz7da8xc0OyL11evkV2dj+J0WpCtZG40vCnjMeSMANeuO9lA== X-Received: by 10.55.66.22 with SMTP id p22mr9027891qka.78.1506100436286; Fri, 22 Sep 2017 10:13:56 -0700 (PDT) Received: from yoga.lan ([181.93.89.178]) by smtp.gmail.com with ESMTPSA id f69sm238468qke.27.2017.09.22.10.13.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2017 10:13:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Peter Maydell , Grant Likely , Jason Wang Date: Fri, 22 Sep 2017 14:13:22 -0300 Message-Id: <20170922171323.10348-7-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::241 Subject: [Qemu-devel] [PATCH v5 6/7] hw/mdio: Add VMState support 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 MDIO model needs to have VMState support before it can be used by devices that support VMState. This patch adds VMState macros for both qemu_mdio and qemu_phy. Signed-off-by: Grant Likely Signed-off-by: Philippe Mathieu-Daudé [PMD: just rebased] --- include/hw/net/mdio.h | 22 ++++++++++++++++++++++ hw/net/mdio.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) -- 2.14.1 Reviewed-by: Alistair Francis diff --git a/include/hw/net/mdio.h b/include/hw/net/mdio.h index 7fca19784e..b94e5ec337 100644 --- a/include/hw/net/mdio.h +++ b/include/hw/net/mdio.h @@ -25,6 +25,8 @@ * THE SOFTWARE. */ +#include "migration/vmstate.h" + /* PHY MII Register/Bit Definitions */ /* PHY Registers defined by IEEE */ #define PHY_CTRL 0x00 /* Control Register */ @@ -61,6 +63,16 @@ struct qemu_phy { void (*write)(struct qemu_phy *phy, unsigned int req, uint16_t data); }; +extern const VMStateDescription vmstate_mdio_phy; + +#define VMSTATE_MDIO_PHY(_field, _state) { \ + .name = (stringify(_field)), \ + .size = sizeof(struct qemu_phy), \ + .vmsd = &vmstate_mdio_phy, \ + .flags = VMS_STRUCT, \ + .offset = vmstate_offset_value(_state, _field, struct qemu_phy), \ +} + struct qemu_mdio { /* bitbanging state machine */ bool mdc; @@ -83,6 +95,16 @@ struct qemu_mdio { struct qemu_phy *devs[32]; }; +extern const VMStateDescription vmstate_mdio; + +#define VMSTATE_MDIO(_field, _state) { \ + .name = (stringify(_field)), \ + .size = sizeof(struct qemu_mdio), \ + .vmsd = &vmstate_mdio, \ + .flags = VMS_STRUCT, \ + .offset = vmstate_offset_value(_state, _field, struct qemu_mdio), \ +} + void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2); void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr); diff --git a/hw/net/mdio.c b/hw/net/mdio.c index 96e10fada0..6c13cc7272 100644 --- a/hw/net/mdio.c +++ b/hw/net/mdio.c @@ -248,3 +248,33 @@ void mdio_bitbang_set_clk(struct qemu_mdio *bus, bool mdc) break; } } + +const VMStateDescription vmstate_mdio = { + .name = "mdio", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_BOOL(mdc, struct qemu_mdio), + VMSTATE_BOOL(mdio, struct qemu_mdio), + VMSTATE_UINT32(state, struct qemu_mdio), + VMSTATE_UINT16(cnt, struct qemu_mdio), + VMSTATE_UINT16(addr, struct qemu_mdio), + VMSTATE_UINT16(opc, struct qemu_mdio), + VMSTATE_UINT16(req, struct qemu_mdio), + VMSTATE_UINT32(shiftreg, struct qemu_mdio), + VMSTATE_END_OF_LIST() + } +}; + +const VMStateDescription vmstate_mdio_phy = { + .name = "mdio", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT16_ARRAY(regs, struct qemu_phy, 32), + VMSTATE_BOOL(link, struct qemu_phy), + VMSTATE_END_OF_LIST() + } +}; 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; }