From nobody Fri May 3 09:38:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506100556414954.3599424058074; Fri, 22 Sep 2017 10:15:56 -0700 (PDT) Received: from localhost ([::1]:60293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRYN-0004rw-FR for importer@patchew.org; Fri, 22 Sep 2017 13:15:51 -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) 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) 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , Grant Likely , Jason Wang , "Edgar E. Iglesias" , Alistair Francis , Fam Zheng , =?UTF-8?q?Andreas=20F=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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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=C3=A9 [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 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"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * 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 dat= a); +}; + +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, uint= 16_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" =20 #define D(x) =20 -/* 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 dat= a); -}; - -static unsigned int tdk_read(struct qemu_phy *phy, unsigned int req) -{ - int regnum; - unsigned r =3D 0; - - regnum =3D req & 0x1f; - - switch (regnum) { - case 1: - if (!phy->link) { - break; - } - /* MR1. */ - /* Speeds and modes. */ - r |=3D (1 << 13) | (1 << 14); - r |=3D (1 << 11) | (1 << 12); - r |=3D (1 << 5); /* Autoneg complete. */ - r |=3D (1 << 3); /* Autoneg able. */ - r |=3D (1 << 2); /* link. */ - break; - case 5: - /* Link partner ability. - We are kind; always agree with whatever best mode - the guest advertises. */ - r =3D 1 << 14; /* Success. */ - /* Copy advertised modes. */ - r |=3D phy->regs[4] & (15 << 5); - /* Autoneg support. */ - r |=3D 1; - break; - case 18: - { - /* Diagnostics reg. */ - int duplex =3D 0; - int speed_100 =3D 0; - - if (!phy->link) { - break; - } - - /* Are we advertising 100 half or 100 duplex ? */ - speed_100 =3D !!(phy->regs[4] & ADVERTISE_100HALF); - speed_100 |=3D !!(phy->regs[4] & ADVERTISE_100FULL); - - /* Are we advertising 10 duplex or 100 duplex ? */ - duplex =3D !!(phy->regs[4] & ADVERTISE_100FULL); - duplex |=3D !!(phy->regs[4] & ADVERTISE_10FULL); - r =3D (speed_100 << 10) | (duplex << 11); - } - break; - - default: - r =3D phy->regs[regnum]; - break; - } - D(printf("\n%s %x =3D 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 =3D req & 0x1f; - D(printf("%s reg[%d] =3D %x\n", __func__, regnum, data)); - switch (regnum) { - default: - phy->regs[regnum] =3D data; - break; - } -} - -static void -tdk_init(struct qemu_phy *phy) -{ - phy->regs[0] =3D 0x3100; - /* PHY Id. */ - phy->regs[2] =3D 0x0300; - phy->regs[3] =3D 0xe400; - /* Autonegotiation advertisement reg. */ - phy->regs[4] =3D 0x01E1; - phy->link =3D 1; - - phy->read =3D tdk_read; - phy->write =3D 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] =3D 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] =3D NULL; -} -#endif - -static void mdio_read_req(struct qemu_mdio *bus) -{ - struct qemu_phy *phy; - - phy =3D bus->devs[bus->addr]; - if (phy && phy->read) { - bus->data =3D phy->read(phy, bus->req); - } else { - bus->data =3D 0xffff; - } -} - -static void mdio_write_req(struct qemu_mdio *bus) -{ - struct qemu_phy *phy; - - phy =3D 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=3D%d mdio=3D%d state=3D%d cnt=3D%d drv=3D%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 >=3D (32 * 2) && !bus->mdio) { - bus->cnt =3D 0; - bus->state =3D SOF; - bus->data =3D 0; - } - } - break; - case SOF: - if (bus->mdc) { - if (bus->mdio !=3D 1) { - printf("WARNING: no SOF\n"); - } - if (bus->cnt =3D=3D 1*2) { - bus->cnt =3D 0; - bus->opc =3D 0; - bus->state =3D OPC; - } - } - break; - case OPC: - if (bus->mdc) { - bus->opc <<=3D 1; - bus->opc |=3D bus->mdio & 1; - if (bus->cnt =3D=3D 2*2) { - bus->cnt =3D 0; - bus->addr =3D 0; - bus->state =3D ADDR; - } - } - break; - case ADDR: - if (bus->mdc) { - bus->addr <<=3D 1; - bus->addr |=3D bus->mdio & 1; - - if (bus->cnt =3D=3D 5*2) { - bus->cnt =3D 0; - bus->req =3D 0; - bus->state =3D REQ; - } - } - break; - case REQ: - if (bus->mdc) { - bus->req <<=3D 1; - bus->req |=3D bus->mdio & 1; - if (bus->cnt =3D=3D 5*2) { - bus->cnt =3D 0; - bus->state =3D TURNAROUND; - } - } - break; - case TURNAROUND: - if (bus->mdc && bus->cnt =3D=3D 2*2) { - bus->mdio =3D 0; - bus->cnt =3D 0; - - if (bus->opc =3D=3D 2) { - bus->drive =3D 1; - mdio_read_req(bus); - bus->mdio =3D bus->data & 1; - } - bus->state =3D DATA; - } - break; - case DATA: - if (!bus->mdc) { - if (bus->drive) { - bus->mdio =3D !!(bus->data & (1 << 15)); - bus->data <<=3D 1; - } - } else { - if (!bus->drive) { - bus->data <<=3D 1; - bus->data |=3D bus->mdio; - } - if (bus->cnt =3D=3D 16 * 2) { - bus->cnt =3D 0; - bus->state =3D PREAMBLE; - if (!bus->drive) { - mdio_write_req(bus); - } - bus->drive =3D 0; - } - } - break; - default: - break; - } -} - /* ETRAX-FS Ethernet MAC block starts here. */ =20 #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"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * 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 co= nsists + * 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 =3D 0; + + regnum =3D req & 0x1f; + + switch (regnum) { + case 1: + if (!phy->link) { + break; + } + /* MR1. */ + /* Speeds and modes. */ + r |=3D (1 << 13) | (1 << 14); + r |=3D (1 << 11) | (1 << 12); + r |=3D (1 << 5); /* Autoneg complete. */ + r |=3D (1 << 3); /* Autoneg able. */ + r |=3D (1 << 2); /* link. */ + r |=3D (1 << 1); /* link. */ + break; + case 5: + /* Link partner ability. + We are kind; always agree with whatever best mode + the guest advertises. */ + r =3D 1 << 14; /* Success. */ + /* Copy advertised modes. */ + r |=3D phy->regs[4] & (15 << 5); + /* Autoneg support. */ + r |=3D 1; + break; + case 17: + /* Marvel PHY on many xilinx boards. */ + r =3D 0x8000; /* 1000Mb */ + break; + case 18: + { + /* Diagnostics reg. */ + int duplex =3D 0; + int speed_100 =3D 0; + + if (!phy->link) { + break; + } + + /* Are we advertising 100 half or 100 duplex ? */ + speed_100 =3D !!(phy->regs[4] & PHY_ADVERTISE_100HALF); + speed_100 |=3D !!(phy->regs[4] & PHY_ADVERTISE_100FULL); + + /* Are we advertising 10 duplex or 100 duplex ? */ + duplex =3D !!(phy->regs[4] & PHY_ADVERTISE_100FULL); + duplex |=3D !!(phy->regs[4] & PHY_ADVERTISE_10FULL); + r =3D (speed_100 << 10) | (duplex << 11); + } + break; + + default: + r =3D phy->regs[regnum]; + break; + } + D(printf("\n%s %x =3D 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 =3D req & 0x1f; + D(printf("%s reg[%d] =3D %x\n", __func__, regnum, data)); + switch (regnum) { + default: + phy->regs[regnum] =3D data; + break; + } +} + +void tdk_init(struct qemu_phy *phy) +{ + phy->regs[0] =3D 0x3100; + /* PHY Id. */ + phy->regs[2] =3D 0x0300; + phy->regs[3] =3D 0xe400; + /* Autonegotiation advertisement reg. */ + phy->regs[4] =3D 0x01e1; + phy->link =3D 1; + + phy->read =3D tdk_read; + phy->write =3D tdk_write; +} + +void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int= addr) +{ + bus->devs[addr & 0x1f] =3D phy; +} + +uint16_t mdio_read_req(struct qemu_mdio *bus, uint8_t addr, uint8_t req) +{ + struct qemu_phy *phy; + + phy =3D 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 =3D 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=3D%d mdio=3D%d state=3D%d cnt=3D%d drv=3D%d\n", + bus->mdc, bus->mdio, bus->state, bus->cnt, bus->drive)); + switch (bus->state) { + case PREAMBLE: + if (bus->mdc) { + if (bus->cnt >=3D (32 * 2) && !bus->mdio) { + bus->cnt =3D 0; + bus->state =3D SOF; + bus->data =3D 0; + } + } + break; + case SOF: + if (bus->mdc) { + if (bus->mdio !=3D 1) { + printf("WARNING: no SOF\n"); + } + if (bus->cnt =3D=3D 1 * 2) { + bus->cnt =3D 0; + bus->opc =3D 0; + bus->state =3D OPC; + } + } + break; + case OPC: + if (bus->mdc) { + bus->opc <<=3D 1; + bus->opc |=3D bus->mdio & 1; + if (bus->cnt =3D=3D 2 * 2) { + bus->cnt =3D 0; + bus->addr =3D 0; + bus->state =3D ADDR; + } + } + break; + case ADDR: + if (bus->mdc) { + bus->addr <<=3D 1; + bus->addr |=3D bus->mdio & 1; + + if (bus->cnt =3D=3D 5 * 2) { + bus->cnt =3D 0; + bus->req =3D 0; + bus->state =3D REQ; + } + } + break; + case REQ: + if (bus->mdc) { + bus->req <<=3D 1; + bus->req |=3D bus->mdio & 1; + if (bus->cnt =3D=3D 5 * 2) { + bus->cnt =3D 0; + bus->state =3D TURNAROUND; + } + } + break; + case TURNAROUND: + if (bus->mdc && bus->cnt =3D=3D 2 * 2) { + bus->mdio =3D 0; + bus->cnt =3D 0; + + if (bus->opc =3D=3D 2) { + bus->drive =3D 1; + bus->data =3D mdio_read_req(bus, bus->addr, bus->req); + bus->mdio =3D bus->data & 1; + } + bus->state =3D DATA; + } + break; + case DATA: + if (!bus->mdc) { + if (bus->drive) { + bus->mdio =3D !!(bus->data & (1 << 15)); + bus->data <<=3D 1; + } + } else { + if (!bus->drive) { + bus->data <<=3D 1; + bus->data |=3D bus->mdio; + } + if (bus->cnt =3D=3D 16 * 2) { + bus->cnt =3D 0; + bus->state =3D PREAMBLE; + if (!bus->drive) { + mdio_write_req(bus, bus->addr, bus->req, bus->data); + } + bus->drive =3D 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" =20 #include "hw/stream.h" =20 -#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) =20 -/* 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))) =20 -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 =3D 0; - - regnum =3D req & 0x1f; - - switch (regnum) { - case 1: - if (!phy->link) { - break; - } - /* MR1. */ - /* Speeds and modes. */ - r |=3D (1 << 13) | (1 << 14); - r |=3D (1 << 11) | (1 << 12); - r |=3D (1 << 5); /* Autoneg complete. */ - r |=3D (1 << 3); /* Autoneg able. */ - r |=3D (1 << 2); /* link. */ - r |=3D (1 << 1); /* link. */ - break; - case 5: - /* Link partner ability. - We are kind; always agree with whatever best mode - the guest advertises. */ - r =3D 1 << 14; /* Success. */ - /* Copy advertised modes. */ - r |=3D phy->regs[4] & (15 << 5); - /* Autoneg support. */ - r |=3D 1; - break; - case 17: - /* Marvell PHY on many xilinx boards. */ - r =3D 0x8000; /* 1000Mb */ - break; - case 18: - { - /* Diagnostics reg. */ - int duplex =3D 0; - int speed_100 =3D 0; - - if (!phy->link) { - break; - } - - /* Are we advertising 100 half or 100 duplex ? */ - speed_100 =3D !!(phy->regs[4] & ADVERTISE_100HALF); - speed_100 |=3D !!(phy->regs[4] & ADVERTISE_100FULL); - - /* Are we advertising 10 duplex or 100 duplex ? */ - duplex =3D !!(phy->regs[4] & ADVERTISE_100FULL); - duplex |=3D !!(phy->regs[4] & ADVERTISE_10FULL); - r =3D (speed_100 << 10) | (duplex << 11); - } - break; - - default: - r =3D phy->regs[regnum]; - break; - } - DPHY(qemu_log("\n%s %x =3D reg[%d]\n", __func__, r, regnum)); - return r; -} - -static void -tdk_write(struct PHY *phy, unsigned int req, unsigned int data) -{ - int regnum; - - regnum =3D req & 0x1f; - DPHY(qemu_log("%s reg[%d] =3D %x\n", __func__, regnum, data)); - switch (regnum) { - default: - phy->regs[regnum] =3D data; - break; - } - - /* Unconditionally clear regs[BMCR][BMCR_RESET] */ - phy->regs[0] &=3D ~0x8000; -} - -static void -tdk_init(struct PHY *phy) -{ - phy->regs[0] =3D 0x3100; - /* PHY Id. */ - phy->regs[2] =3D 0x0300; - phy->regs[3] =3D 0xe400; - /* Autonegotiation advertisement reg. */ - phy->regs[4] =3D 0x01E1; - phy->link =3D 1; - - phy->read =3D tdk_read; - phy->write =3D 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] =3D phy; -} - -#ifdef USE_THIS_DEAD_CODE -static void -mdio_detach(struct MDIOBus *bus, struct PHY *phy, unsigned int addr) -{ - bus->devs[addr & 0x1f] =3D NULL; -} -#endif - -static uint16_t mdio_read_req(struct MDIOBus *bus, unsigned int addr, - unsigned int reg) -{ - struct PHY *phy; - uint16_t data; - - phy =3D bus->devs[addr]; - if (phy && phy->read) { - data =3D phy->read(phy, reg); - } else { - data =3D 0xffff; - } - DPHY(qemu_log("%s addr=3D%d reg=3D%d data=3D%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=3D%d reg=3D%d data=3D%x\n", __func__, addr, reg= , data)); - phy =3D bus->devs[addr]; - if (phy && phy->write) { - phy->write(phy, reg, data); - } -} - #define DENET(x) =20 #define R_RAF (0x000 / 4) @@ -322,8 +141,8 @@ enum { =20 /* Indirect registers. */ struct TEMAC { - struct MDIOBus mdio_bus; - struct PHY phy; + struct qemu_mdio mdio_bus; + struct qemu_phy phy; =20 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) +=3D sunhme.o common-obj-$(CONFIG_FTGMAC100) +=3D ftgmac100.o common-obj-$(CONFIG_SUNGEM) +=3D sungem.o =20 +common-obj-y +=3D mdio.o + obj-$(CONFIG_ETRAXFS) +=3D etraxfs_eth.o obj-$(CONFIG_COLDFIRE) +=3D mcf_fec.o obj-$(CONFIG_MILKYMIST) +=3D milkymist-minimac2.o --=20 2.14.1 From nobody Fri May 3 09:38:57 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506100688958411.61113995700384; Fri, 22 Sep 2017 10:18:08 -0700 (PDT) Received: from localhost ([::1]:60301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRaJ-0007K8-GV for importer@patchew.org; Fri, 22 Sep 2017 13:17:51 -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) 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) 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) From: =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 Z_629925259 SPT_0 From: Grant Likely Trivial patch to add #defines for defined PHY register address and bit fiel= ds Signed-off-by: Grant Likely Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- include/hw/net/mdio.h | 24 ++++++++++++++++++++++-- hw/net/mdio.c | 8 ++++---- 2 files changed, 26 insertions(+), 6 deletions(-) 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. */ =20 -/* 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 bitfiel= ds) */ #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 */ =20 struct qemu_phy { - uint32_t regs[32]; + uint32_t regs[NUM_PHY_REGS]; =20 int link; =20 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) =20 void tdk_init(struct qemu_phy *phy) { - phy->regs[0] =3D 0x3100; + phy->regs[PHY_CTRL] =3D 0x3100; /* PHY Id. */ - phy->regs[2] =3D 0x0300; - phy->regs[3] =3D 0xe400; + phy->regs[PHY_ID1] =3D 0x0300; + phy->regs[PHY_ID2] =3D 0xe400; /* Autonegotiation advertisement reg. */ - phy->regs[4] =3D 0x01e1; + phy->regs[PHY_AUTONEG_ADV] =3D 0x01e1; phy->link =3D 1; =20 phy->read =3D tdk_read; --=20 2.14.1 From nobody Fri May 3 09:38:57 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506100570282525.085413950487; Fri, 22 Sep 2017 10:16:10 -0700 (PDT) Received: from localhost ([::1]:60295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRYT-00059E-5K for importer@patchew.org; Fri, 22 Sep 2017 13:15:57 -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) 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) 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , Grant Likely , Jason Wang , "Edgar E. Iglesias" , Alistair Francis , Fam Zheng , =?UTF-8?q?Andreas=20F=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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 Z_629925259 SPT_0 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=C3=A9 [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(-) 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]; }; =20 -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); =20 =20 - 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 =3D 0; @@ -107,7 +107,7 @@ static unsigned int tdk_read(struct qemu_phy *phy, unsi= gned int req) return r; } =20 -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, unsigne= d int data) { int regnum; =20 @@ -120,18 +120,18 @@ static void tdk_write(struct qemu_phy *phy, unsigned = int req, unsigned int data) } } =20 -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] =3D 0x3100; /* PHY Id. */ - phy->regs[PHY_ID1] =3D 0x0300; - phy->regs[PHY_ID2] =3D 0xe400; + phy->regs[PHY_ID1] =3D id1; + phy->regs[PHY_ID2] =3D id2; /* Autonegotiation advertisement reg. */ phy->regs[PHY_AUTONEG_ADV] =3D 0x01e1; phy->link =3D 1; =20 - phy->read =3D tdk_read; - phy->write =3D tdk_write; + phy->read =3D mdio_phy_read; + phy->write =3D mdio_phy_write; } =20 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); =20 - 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); =20 s->TEMAC.parent =3D s; --=20 2.14.1 From nobody Fri May 3 09:38:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506100803921955.8834109746398; Fri, 22 Sep 2017 10:20:03 -0700 (PDT) Received: from localhost ([::1]:60306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRcK-0000Tm-V0 for importer@patchew.org; Fri, 22 Sep 2017 13:19:56 -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) 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) 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) From: =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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=C3=A9 [PMD: just rebased] --- include/hw/net/mdio.h | 1 + hw/net/mdio.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) 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 @@ =20 struct qemu_phy { uint32_t regs[NUM_PHY_REGS]; + const uint16_t *regs_readonly_mask; /* 0=3Dwritable, 1=3Dread-only */ =20 int link; =20 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 *ph= y, unsigned int req) =20 static void mdio_phy_write(struct qemu_phy *phy, unsigned int req, unsigne= d int data) { - int regnum; + int regnum =3D req & 0x1f; + uint16_t mask =3D phy->regs_readonly_mask[regnum]; =20 - regnum =3D req & 0x1f; - D(printf("%s reg[%d] =3D %x\n", __func__, regnum, data)); + D(printf("%s reg[%d] =3D %x; mask=3D%x\n", __func__, regnum, data, mas= k)); switch (regnum) { default: - phy->regs[regnum] =3D data; + phy->regs[regnum] =3D (phy->regs[regnum] & mask) | (data & ~mask); break; } } =20 +static const uint16_t default_readonly_mask[32] =3D { + [PHY_CTRL] =3D PHY_CTRL_RST | PHY_CTRL_ANEG_RST, + [PHY_ID1] =3D 0xffff, + [PHY_ID2] =3D 0xffff, + [PHY_LP_ABILITY] =3D 0xffff, +}; + void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, uint16_t id2) { phy->regs[PHY_CTRL] =3D 0x3100; @@ -128,6 +135,7 @@ void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, = uint16_t id2) phy->regs[PHY_ID2] =3D id2; /* Autonegotiation advertisement reg. */ phy->regs[PHY_AUTONEG_ADV] =3D 0x01e1; + phy->regs_readonly_mask =3D default_readonly_mask; phy->link =3D 1; =20 phy->read =3D mdio_phy_read; --=20 2.14.1 From nobody Fri May 3 09:38:57 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506100565348187.12835560153724; Fri, 22 Sep 2017 10:16:05 -0700 (PDT) Received: from localhost ([::1]:60294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRYS-00056U-7x for importer@patchew.org; Fri, 22 Sep 2017 13:15:56 -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) 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) 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) From: =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 Z_629925259 SPT_0 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=C3=A9 [PMD: just rebased] Acked-by: Alistair Francis --- include/hw/net/mdio.h | 41 ++++++++------- hw/net/etraxfs_eth.c | 11 ++-- hw/net/mdio.c | 140 ++++++++++++++++++++++------------------------= ---- 3 files changed, 87 insertions(+), 105 deletions(-) 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 */ =20 struct qemu_phy { - uint32_t regs[NUM_PHY_REGS]; + uint16_t regs[NUM_PHY_REGS]; const uint16_t *regs_readonly_mask; /* 0=3Dwritable, 1=3Dread-only */ =20 - int link; + bool link; =20 - unsigned int (*read)(struct qemu_phy *phy, unsigned int req); - void (*write)(struct qemu_phy *phy, unsigned int req, unsigned int dat= a); + uint16_t (*read)(struct qemu_phy *phy, unsigned int req); + void (*write)(struct qemu_phy *phy, unsigned int req, uint16_t data); }; =20 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; =20 - 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 */ =20 struct qemu_phy *devs[32]; }; @@ -91,7 +87,16 @@ void mdio_phy_init(struct qemu_phy *phy, uint16_t id1, u= int16_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, uint= 16_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 =3D mdio; +} +static inline bool mdio_bitbang_get_data(struct qemu_mdio *bus) +{ + return bus->mdio; +} =20 #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) =20 switch (addr) { case R_STAT: - r =3D eth->mdio_bus.mdio & 1; + r =3D mdio_bitbang_get_data(ð->mdio_bus); break; default: r =3D 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 =3D value & 1; + mdio_bitbang_set_data(ð->mdio_bus, value & 1); } - if (eth->mdio_bus.mdc !=3D (value & 4)) { - mdio_cycle(ð->mdio_bus); - eth_validate_duplex(eth); - } - eth->mdio_bus.mdc =3D !!(value & 4); + mdio_bitbang_set_clk(ð->mdio_bus, value & 4); + eth_validate_duplex(eth); eth->regs[addr] =3D value; break; =20 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 =3D 0; @@ -107,7 +107,8 @@ static unsigned int mdio_phy_read(struct qemu_phy *phy,= unsigned int req) return r; } =20 -static void mdio_phy_write(struct qemu_phy *phy, unsigned int req, unsigne= d int data) +static void mdio_phy_write(struct qemu_phy *phy, unsigned int req, + uint16_t data) { int regnum =3D req & 0x1f; uint16_t mask =3D 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] =3D 0x01e1; phy->regs_readonly_mask =3D default_readonly_mask; - phy->link =3D 1; + phy->link =3D true; =20 phy->read =3D mdio_phy_read; phy->write =3D mdio_phy_write; } =20 -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] =3D phy; } @@ -169,99 +171,77 @@ void mdio_write_req(struct qemu_mdio *bus, uint8_t ad= dr, uint8_t req, } } =20 -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 c= hange. + */ +static bool mdio_bitbang_update(struct qemu_mdio *bus, int num_bits, int n= ext, + uint16_t *reg) { + if (bus->cnt < num_bits) { + return false; + } + if (reg) { + *reg =3D bus->shiftreg; + } + bus->state =3D next; + bus->cnt =3D 0; + bus->shiftreg =3D 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 =3D=3D bus->mdc) { + return; /* Clock state hasn't changed; do nothing */ + } + + bus->mdc =3D mdc; + if (bus->mdc) { + /* Falling (inactive) clock edge */ + if ((bus->state =3D=3D DATA) && (bus->opc =3D=3D 2)) { + bus->mdio =3D !!(bus->shiftreg & 0x8000); + } + return; + } + + /* Rising clock Edge */ + bus->shiftreg =3D (bus->shiftreg << 1) | bus->mdio; bus->cnt++; - D(printf("mdc=3D%d mdio=3D%d state=3D%d cnt=3D%d drv=3D%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 >=3D (32 * 2) && !bus->mdio) { - bus->cnt =3D 0; - bus->state =3D SOF; - bus->data =3D 0; - } - } - break; - case SOF: - if (bus->mdc) { - if (bus->mdio !=3D 1) { - printf("WARNING: no SOF\n"); - } - if (bus->cnt =3D=3D 1 * 2) { - bus->cnt =3D 0; - bus->opc =3D 0; - bus->state =3D OPC; - } + /* MDIO must be 30 clocks high, 1 low, and 1 high to get out of + preamble */ + if (bus->shiftreg =3D=3D 0xfffffffd) { + mdio_bitbang_update(bus, 0, OPC, NULL); } break; case OPC: - if (bus->mdc) { - bus->opc <<=3D 1; - bus->opc |=3D bus->mdio & 1; - if (bus->cnt =3D=3D 2 * 2) { - bus->cnt =3D 0; - bus->addr =3D 0; - bus->state =3D ADDR; - } - } + mdio_bitbang_update(bus, 2, ADDR, &bus->opc); break; case ADDR: - if (bus->mdc) { - bus->addr <<=3D 1; - bus->addr |=3D bus->mdio & 1; - - if (bus->cnt =3D=3D 5 * 2) { - bus->cnt =3D 0; - bus->req =3D 0; - bus->state =3D REQ; - } - } + mdio_bitbang_update(bus, 5, REQ, &bus->addr); break; case REQ: - if (bus->mdc) { - bus->req <<=3D 1; - bus->req |=3D bus->mdio & 1; - if (bus->cnt =3D=3D 5 * 2) { - bus->cnt =3D 0; - bus->state =3D TURNAROUND; - } - } + mdio_bitbang_update(bus, 5, TURNAROUND, &bus->req); break; case TURNAROUND: - if (bus->mdc && bus->cnt =3D=3D 2 * 2) { - bus->mdio =3D 0; - bus->cnt =3D 0; - - if (bus->opc =3D=3D 2) { - bus->drive =3D 1; - bus->data =3D mdio_read_req(bus, bus->addr, bus->req); - bus->mdio =3D bus->data & 1; - } - bus->state =3D DATA; + /* If beginning of DATA READ cycle, then read PHY into shift regis= ter */ + if (mdio_bitbang_update(bus, 2, DATA, NULL) && (bus->opc =3D=3D 2)= ) { + bus->shiftreg =3D mdio_read_req(bus, bus->addr, bus->req); } break; case DATA: - if (!bus->mdc) { - if (bus->drive) { - bus->mdio =3D !!(bus->data & (1 << 15)); - bus->data <<=3D 1; - } - } else { - if (!bus->drive) { - bus->data <<=3D 1; - bus->data |=3D bus->mdio; - } - if (bus->cnt =3D=3D 16 * 2) { - bus->cnt =3D 0; - bus->state =3D PREAMBLE; - if (!bus->drive) { - mdio_write_req(bus, bus->addr, bus->req, bus->data); - } - bus->drive =3D 0; - } + /* If end of DATA WRITE cycle, then write shift register to PHY */ + if (mdio_bitbang_update(bus, 16, PREAMBLE, &tmp) && (bus->opc =3D= =3D 1)) { + mdio_write_req(bus, bus->addr, bus->req, tmp); } break; default: --=20 2.14.1 From nobody Fri May 3 09:38:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506100708562841.2577447427582; Fri, 22 Sep 2017 10:18:28 -0700 (PDT) Received: from localhost ([::1]:60302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRaj-0007gM-H7 for importer@patchew.org; Fri, 22 Sep 2017 13:18:17 -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) 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) 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) From: =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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=C3=A9 [PMD: just rebased] Reviewed-by: Alistair Francis --- include/hw/net/mdio.h | 22 ++++++++++++++++++++++ hw/net/mdio.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) 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. */ =20 +#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); }; =20 +extern const VMStateDescription vmstate_mdio_phy; + +#define VMSTATE_MDIO_PHY(_field, _state) { \ + .name =3D (stringify(_field)), \ + .size =3D sizeof(struct qemu_phy), \ + .vmsd =3D &vmstate_mdio_phy, \ + .flags =3D VMS_STRUCT, \ + .offset =3D 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]; }; =20 +extern const VMStateDescription vmstate_mdio; + +#define VMSTATE_MDIO(_field, _state) { \ + .name =3D (stringify(_field)), \ + .size =3D sizeof(struct qemu_mdio), \ + .vmsd =3D &vmstate_mdio, \ + .flags =3D VMS_STRUCT, \ + .offset =3D 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 =3D { + .name =3D "mdio", + .version_id =3D 1, + .minimum_version_id =3D 1, + .minimum_version_id_old =3D 1, + .fields =3D (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 =3D { + .name =3D "mdio", + .version_id =3D 1, + .minimum_version_id =3D 1, + .minimum_version_id_old =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT16_ARRAY(regs, struct qemu_phy, 32), + VMSTATE_BOOL(link, struct qemu_phy), + VMSTATE_END_OF_LIST() + } +}; --=20 2.14.1 From nobody Fri May 3 09:38:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506100837605641.5104142880904; Fri, 22 Sep 2017 10:20:37 -0700 (PDT) Received: from localhost ([::1]:60310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvRcw-0000wN-HB for importer@patchew.org; Fri, 22 Sep 2017 13:20:34 -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) 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) 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) From: =?UTF-8?q?Philippe=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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=C3=A9 [PMD: just rebased] --- hw/net/smc91c111.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) 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 =20 @@ -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; =20 static const VMStateDescription vmstate_smc91c111 =3D { .name =3D "smc91c111", - .version_id =3D 1, - .minimum_version_id =3D 1, + .version_id =3D 2, + .minimum_version_id =3D 2, .fields =3D (VMStateField[]) { VMSTATE_UINT16(tcr, smc91c111_state), VMSTATE_UINT16(rcr, smc91c111_state), @@ -76,6 +81,8 @@ static const VMStateDescription vmstate_smc91c111 =3D { 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 offs= et, /* 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 of= fset) /* 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 =3D 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; } --=20 2.14.1