From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wwaih-00065q-O4 for qemu-devel@nongnu.org; Mon, 16 Jun 2014 13:29:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wwaic-0000FZ-11 for qemu-devel@nongnu.org; Mon, 16 Jun 2014 13:29:23 -0400 Received: from mail-qc0-x22f.google.com ([2607:f8b0:400d:c01::22f]:46166) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wwaib-0000FN-SW for qemu-devel@nongnu.org; Mon, 16 Jun 2014 13:29:17 -0400 Received: by mail-qc0-f175.google.com with SMTP id i8so8384716qcq.34 for ; Mon, 16 Jun 2014 10:29:17 -0700 (PDT) From: "Gabriel L. Somlo" Date: Mon, 16 Jun 2014 13:29:09 -0400 Message-Id: <1402939751-8371-2-git-send-email-somlo@cmu.edu> In-Reply-To: <1402939751-8371-1-git-send-email-somlo@cmu.edu> References: <1402939751-8371-1-git-send-email-somlo@cmu.edu> Subject: [Qemu-devel] [PATCH v1 1/3] e1000: emulate auto-negotiation during external link status change List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: romain@dolbeau.org, mst@redhat.com, agraf@suse.de, stefanha@redhat.com, pbonzini@redhat.com, afaerber@suse.de This patch emulates auto-negotiation when the network link status is modified externally (i.e. via "set_link off/on"). Also, a couple of cleanup items regarding the PHY status register: - unset AUTONEG_COMPLETE during link_down() - set AUTONEG_COMPLETE during autoneg_timer() only if we actually brought the link up. Signed-off-by: Gabriel Somlo --- hw/net/e1000.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 57bdffd..f0070ca 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -175,6 +175,7 @@ e1000_link_down(E1000State *s) { s->mac_reg[STATUS] &= ~E1000_STATUS_LU; s->phy_reg[PHY_STATUS] &= ~MII_SR_LINK_STATUS; + s->phy_reg[PHY_STATUS] &= ~MII_SR_AUTONEG_COMPLETE; } static void @@ -197,7 +198,6 @@ set_phy_ctrl(E1000State *s, int index, uint16_t val) } if ((val & MII_CR_AUTO_NEG_EN) && (val & MII_CR_RESTART_AUTO_NEG)) { e1000_link_down(s); - s->phy_reg[PHY_STATUS] &= ~MII_SR_AUTONEG_COMPLETE; DBGOUT(PHY, "Start link auto negotiation\n"); timer_mod(s->autoneg_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500); } @@ -209,9 +209,9 @@ e1000_autoneg_timer(void *opaque) E1000State *s = opaque; if (!qemu_get_queue(s->nic)->link_down) { e1000_link_up(s); + s->phy_reg[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE; + DBGOUT(PHY, "Auto negotiation is completed\n"); } - s->phy_reg[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE; - DBGOUT(PHY, "Auto negotiation is completed\n"); } static void (*phyreg_writeops[])(E1000State *, int, uint16_t) = { @@ -853,7 +853,15 @@ e1000_set_link_status(NetClientState *nc) if (nc->link_down) { e1000_link_down(s); } else { - e1000_link_up(s); + if (s->phy_reg[PHY_CTRL] & MII_CR_AUTO_NEG_EN && + s->phy_reg[PHY_CTRL] & MII_CR_RESTART_AUTO_NEG && + !(s->phy_reg[PHY_STATUS] & MII_SR_AUTONEG_COMPLETE)) { + /* emulate auto-negotiation if supported */ + timer_mod(s->autoneg_timer, + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500); + } else { + e1000_link_up(s); + } } if (s->mac_reg[STATUS] != old_status) -- 1.9.3