From patchwork Wed Jan 23 16:15:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 215056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3F0EF2C008D for ; Thu, 24 Jan 2013 09:21:33 +1100 (EST) Received: from localhost ([::1]:38729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ty8hH-0003wD-9i for incoming@patchwork.ozlabs.org; Wed, 23 Jan 2013 17:21:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ty8h1-0003w3-46 for qemu-devel@nongnu.org; Wed, 23 Jan 2013 17:21:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ty8gy-0007rI-8S for qemu-devel@nongnu.org; Wed, 23 Jan 2013 17:21:15 -0500 Received: from mail-wg0-f44.google.com ([74.125.82.44]:38310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ty8gx-0007qt-Vb for qemu-devel@nongnu.org; Wed, 23 Jan 2013 17:21:12 -0500 Received: by mail-wg0-f44.google.com with SMTP id dr12so5417081wgb.11 for ; Wed, 23 Jan 2013 14:21:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=2zxG1ABYY4nXmYSMXL44OLtB18Y+LtxDmzDGNfwqHb8=; b=nbzGc7cvCJ3q7PxTsJkkLiL9HxYxK3VO+BRmOH8Yu1lcmp1vilyxQDgQYrDFXfkR33 w7t3fFo6wWdKsooMDd+UciN1/0MnlAsxtx0yQW4uS4eDXNpOA4y4zskaUIK/svrdeInj RHUZYJOtuTx0JmavOH3lt1OkdquHa3sZXRgZx4SPKX/USjIrSQfq2pgw5neacJxdZT2v oZB7Kwj8ia1Imxneq9kpF6Md91yMya/eSQ0J+g+CQMyqUljNWsbiB94hGZYXBxxaTKMY Ci5+JLhauX9DfWl8ZJHoSGF9S8DUszKYPPRAUjbBqVXNzhBUXcBcZgcJe46cLatB8uMb ZrrQ== X-Received: by 10.180.108.137 with SMTP id hk9mr181017wib.28.1358979670920; Wed, 23 Jan 2013 14:21:10 -0800 (PST) Received: from localhost (host31-53-18-123.range31-53.btcentralplus.com. [31.53.18.123]) by mx.google.com with ESMTPS id s16sm33417857wii.0.2013.01.23.14.21.07 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 23 Jan 2013 14:21:09 -0800 (PST) Received: by localhost (Postfix, from userid 1000) id F06B33E09D1; Wed, 23 Jan 2013 11:15:35 -0500 (EST) From: Grant Likely To: qemu-devel@nongnu.org Date: Wed, 23 Jan 2013 16:15:28 +0000 Message-Id: <1358957730-17897-5-git-send-email-grant.likely@secretlab.ca> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358957730-17897-1-git-send-email-grant.likely@secretlab.ca> References: <1358957730-17897-1-git-send-email-grant.likely@secretlab.ca> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmAnZrsMr1SV2kPFYFPp3jYcnsbqt+MJJRvviwZ2hEHclkyGjAGlpGY8jUmSayrIE6g8vwH X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 74.125.82.44 Cc: Peter Maydell , Anthony Liguori , Grant Likely , Paul Brook , "Edgar E. Iglesias" , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH V2 4/6] hw/mdio: Add VMState support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The 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. Cc: Peter Maydell Cc: Paul Brook Cc: Edgar E. Iglesias Cc: Anthony Liguori Cc: Andreas Färber Signed-off-by: Grant Likely --- hw/mdio.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- hw/mdio.h | 50 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 74 insertions(+), 25 deletions(-) diff --git a/hw/mdio.c b/hw/mdio.c index b138efa..ca55e21 100644 --- a/hw/mdio.c +++ b/hw/mdio.c @@ -44,7 +44,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 uint16_t tdk_read(struct qemu_phy *phy, unsigned int req) { int regnum; unsigned r = 0; @@ -108,7 +108,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 tdk_write(struct qemu_phy *phy, unsigned int req, uint16_t data) { int regnum; @@ -133,7 +133,7 @@ void tdk_init(struct qemu_phy *phy) phy->regs[3] = 0xe400; /* Autonegotiation advertisement reg. */ phy->regs[4] = 0x01e1; - phy->link = 1; + phy->link = true; phy->read = tdk_read; phy->write = tdk_write; @@ -178,7 +178,7 @@ 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)); + bus->mdc, bus->mdio, bus->state, bus->cnt, bus->output_enable)); switch (bus->state) { case PREAMBLE: if (bus->mdc) { @@ -240,7 +240,7 @@ void mdio_cycle(struct qemu_mdio *bus) bus->cnt = 0; if (bus->opc == 2) { - bus->drive = 1; + bus->output_enable = true; bus->data = mdio_read_req(bus, bus->addr, bus->req); bus->mdio = bus->data & 1; } @@ -249,22 +249,22 @@ void mdio_cycle(struct qemu_mdio *bus) break; case DATA: if (!bus->mdc) { - if (bus->drive) { + if (bus->output_enable) { bus->mdio = !!(bus->data & (1 << 15)); bus->data <<= 1; } } else { - if (!bus->drive) { + if (!bus->output_enable) { bus->data <<= 1; bus->data |= bus->mdio; } if (bus->cnt == 16 * 2) { bus->cnt = 0; bus->state = PREAMBLE; - if (!bus->drive) { + if (!bus->output_enable) { mdio_write_req(bus, bus->addr, bus->req, bus->data); } - bus->drive = 0; + bus->output_enable = false; } } break; @@ -272,3 +272,34 @@ void mdio_cycle(struct qemu_mdio *bus) 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_BOOL(output_enable, struct qemu_mdio), + VMSTATE_UINT32(state, struct qemu_mdio), + VMSTATE_UINT8(cnt, struct qemu_mdio), + VMSTATE_UINT8(addr, struct qemu_mdio), + VMSTATE_UINT8(opc, struct qemu_mdio), + VMSTATE_UINT8(req, struct qemu_mdio), + VMSTATE_UINT32(data, 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() + } +}; diff --git a/hw/mdio.h b/hw/mdio.h index c0c2533..1cbb422 100644 --- a/hw/mdio.h +++ b/hw/mdio.h @@ -26,22 +26,31 @@ */ #include +#include "migration/vmstate.h" struct qemu_phy { - uint32_t regs[32]; + uint16_t regs[32]; + bool link; - int 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; +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), \ +} - /* decoder. */ +struct qemu_mdio { + /* bitbanging state machine */ + bool mdc; + bool mdio; + bool output_enable; enum { PREAMBLE, SOF, @@ -51,17 +60,26 @@ struct qemu_mdio { TURNAROUND, DATA } state; - unsigned int drive; - unsigned int cnt; - unsigned int addr; - unsigned int opc; - unsigned int req; - unsigned int data; + uint8_t cnt; /* Bit count for current state */ + uint8_t addr; /* PHY Address; retrieved during ADDR state */ + uint8_t opc; /* Operation; 2:read */ + uint8_t req; /* Register address */ + uint32_t data; /* Data to write, or data read from PHY */ 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 tdk_init(struct qemu_phy *phy); void mdio_attach(struct qemu_mdio *bus, struct qemu_phy *phy, unsigned int addr);