Received: from eggs.gnu.org ([2001:4830:134:3::10]:50642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1i83-0000Yh-BL for qemu-devel@nongnu.org; Mon, 30 Jun 2014 16:24:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1i7u-0001Tu-Pm for qemu-devel@nongnu.org; Mon, 30 Jun 2014 16:24:43 -0400 Received: from mail-qc0-x232.google.com ([2607:f8b0:400d:c01::232]:41277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1i7u-0001Td-L1 for qemu-devel@nongnu.org; Mon, 30 Jun 2014 16:24:34 -0400 Received: by mail-qc0-f178.google.com with SMTP id c9so7679955qcz.9 for ; Mon, 30 Jun 2014 13:24:34 -0700 (PDT) Date: Mon, 30 Jun 2014 16:24:32 -0400 From: "Gabriel L. Somlo" Message-ID: <20140630202431.GQ1688@ERROL.INI.CMU.EDU> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH v2] e1000: clean up phyreg_writeops/set_phy_ctrl List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: pbonzini@redhat.com, Jason Wang , qemu-devel@nongnu.org, stefanha@redhat.com, agraf@suse.de Make phyreg_writeops responsible for actually writing their respective phy registers. The only current instance of phyreg_writeops is the set_phy_ctrl() function, which we modify to actually write the register, while also correctly handling reserved and self-clearing bits. have_autoneg() does not need to check for MII_CR_RESTART_AUTO_NEG, since the only time the flag comes into play is during set_phy_ctrl(), and never actually gets written to the phy control register. We also move it in front of set_phy_ctrl(), to avoid a forward declaration. Signed-off-by: Gabriel Somlo --- No longer an RFC, since I now think I understand what I'm doing, and believe it's "The Right Thing (TM)" :) Uncoupling it from the timer delay value patch, since they're orthogonal, and we should talk about that independently... Thanks much, Gabriel hw/net/e1000.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 0fc29a0..4002430 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -186,6 +186,13 @@ e1000_link_up(E1000State *s) s->phy_reg[PHY_STATUS] |= MII_SR_LINK_STATUS; } +static bool +have_autoneg(E1000State *s) +{ + return (s->compat_flags & E1000_FLAG_AUTONEG) && + (s->phy_reg[PHY_CTRL] & MII_CR_AUTO_NEG_EN); +} + static void set_phy_ctrl(E1000State *s, int index, uint16_t val) { @@ -194,13 +201,16 @@ set_phy_ctrl(E1000State *s, int index, uint16_t val) * migrate during auto negotiation, after migration the link will be * down. */ - if (!(s->compat_flags & E1000_FLAG_AUTONEG)) { - return; - } - if ((val & MII_CR_AUTO_NEG_EN) && (val & MII_CR_RESTART_AUTO_NEG)) { + + /* bits 0-5 reserved; MII_CR_[RESTART_AUTO_NEG,RESET] are self clearing */ + s->phy_reg[PHY_CTRL] = val & + ~(0x3f | MII_CR_RESTART_AUTO_NEG | MII_CR_RESET); + + if (have_autoneg(s) && (val & MII_CR_RESTART_AUTO_NEG)) { e1000_link_down(s); DBGOUT(PHY, "Start link auto negotiation\n"); - timer_mod(s->autoneg_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500); + timer_mod(s->autoneg_timer, + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500); } } @@ -446,8 +456,9 @@ set_mdic(E1000State *s, int index, uint32_t val) } else { if (addr < NPHYWRITEOPS && phyreg_writeops[addr]) { phyreg_writeops[addr](s, index, data); + } else { + s->phy_reg[addr] = data; } - s->phy_reg[addr] = data; } } s->mac_reg[MDIC] = val | E1000_MDIC_READY; @@ -848,14 +859,6 @@ receive_filter(E1000State *s, const uint8_t *buf, int size) return 0; } -static bool -have_autoneg(E1000State *s) -{ - return (s->compat_flags & E1000_FLAG_AUTONEG) && - (s->phy_reg[PHY_CTRL] & MII_CR_AUTO_NEG_EN) && - (s->phy_reg[PHY_CTRL] & MII_CR_RESTART_AUTO_NEG); -} - static void e1000_set_link_status(NetClientState *nc) { -- 1.9.3