From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz6Yn-0004NR-5z for qemu-devel@nongnu.org; Mon, 23 Jun 2014 11:53:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz6Yg-0001nI-KO for qemu-devel@nongnu.org; Mon, 23 Jun 2014 11:53:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz6Yg-0001n3-Ct for qemu-devel@nongnu.org; Mon, 23 Jun 2014 11:53:26 -0400 Date: Mon, 23 Jun 2014 18:53:43 +0300 From: "Michael S. Tsirkin" Message-ID: <1403538745-18622-12-git-send-email-mst@redhat.com> References: <1403538745-18622-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1403538745-18622-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 11/23] e1000: factor out checking for auto-negotiation availability List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Peter Crosthwaite , Anthony Liguori , Gabriel Somlo , "Gabriel L. Somlo" , Stefan Hajnoczi From: "Gabriel L. Somlo" Also fix minor indentation issues in the surrounding code. Suggested-by: Michael S. Tsirkin Signed-off-by: Gabriel Somlo Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/net/e1000.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 8ee5225..0fc29a0 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -848,6 +848,14 @@ 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) { @@ -857,9 +865,7 @@ e1000_set_link_status(NetClientState *nc) if (nc->link_down) { e1000_link_down(s); } else { - if (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 && + if (have_autoneg(s) && !(s->phy_reg[PHY_STATUS] & MII_SR_AUTONEG_COMPLETE)) { /* emulate auto-negotiation if supported */ timer_mod(s->autoneg_timer, @@ -1297,11 +1303,8 @@ static void e1000_pre_save(void *opaque) * complete auto-negotiation immediately. This allows us to look * at MII_SR_AUTONEG_COMPLETE to infer link status on load. */ - if (nc->link_down && - 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) { - s->phy_reg[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE; + if (nc->link_down && have_autoneg(s)) { + s->phy_reg[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE; } } @@ -1323,12 +1326,11 @@ static int e1000_post_load(void *opaque, int version_id) * Alternatively, restart link negotiation if it was in progress. */ nc->link_down = (s->mac_reg[STATUS] & E1000_STATUS_LU) == 0; - if (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 && + if (have_autoneg(s) && !(s->phy_reg[PHY_STATUS] & MII_SR_AUTONEG_COMPLETE)) { nc->link_down = false; - 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); } return 0; -- MST