qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Anthony Liguori" <aliguori@us.ibm.com>,
	kvm@suse.de, qemu-stable@nongnu.org, "Bjørn Mork" <bjorn@mork.no>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH stable-0.15 03/36] e1000: use MII status register for link up/down
Date: Wed, 28 Mar 2012 14:52:06 +0200	[thread overview]
Message-ID: <1332939159-16434-4-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1332939159-16434-1-git-send-email-afaerber@suse.de>

From: Bjørn Mork <bjorn@mork.no>

Some guests will use the standard MII status register
to verify link state.  They will not notice link changes
unless this register is updated.

Verified with Linux 3.0 and Windows XP guests.

Without this patch, ethtool will report speed and duplex as
unknown when the link is down, but still report the link as
up.  This is because the Linux e1000 driver checks the
mac_reg[STATUS] register link state before it checks speed
and duplex, but uses the phy_reg[PHY_STATUS] register for
the actual link state check.  Fix by updating both registers
on link state changes.

Linux guest before:

 (qemu) set_link e1000.0 off

 kvm-sid:~# ethtool eth0
 Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: Unknown!
        Duplex: Unknown! (255)
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: umbg
        Wake-on: d
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes

 (qemu) set_link e1000.0 on

Linux guest after:

 (qemu) set_link e1000.0 off
 [   63.384221] e1000: eth0 NIC Link is Down

 kvm-sid:~# ethtool eth0
 Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: Unknown!
        Duplex: Unknown! (255)
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: umbg
        Wake-on: d
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: no

 (qemu) set_link e1000.0 on
 [   84.304582] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX

Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(cherry picked from commit d4044c2a6b9ba4a00dd653f515a4b0ebfcb7e125)

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/e1000.c    |    7 +++++--
 hw/e1000_hw.h |   17 +++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 96d84f9..e4d9ab5 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -624,10 +624,13 @@ e1000_set_link_status(VLANClientState *nc)
     E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
     uint32_t old_status = s->mac_reg[STATUS];
 
-    if (nc->link_down)
+    if (nc->link_down) {
         s->mac_reg[STATUS] &= ~E1000_STATUS_LU;
-    else
+        s->phy_reg[PHY_STATUS] &= ~MII_SR_LINK_STATUS;
+    } else {
         s->mac_reg[STATUS] |= E1000_STATUS_LU;
+        s->phy_reg[PHY_STATUS] |= MII_SR_LINK_STATUS;
+    }
 
     if (s->mac_reg[STATUS] != old_status)
         set_ics(s, 0, E1000_ICR_LSC);
diff --git a/hw/e1000_hw.h b/hw/e1000_hw.h
index 9bd8a4b..2e341ac 100644
--- a/hw/e1000_hw.h
+++ b/hw/e1000_hw.h
@@ -349,6 +349,23 @@
 #define M88E1000_PHY_VCO_REG_BIT8  0x100 /* Bits 8 & 11 are adjusted for */
 #define M88E1000_PHY_VCO_REG_BIT11 0x800    /* improved BER performance */
 
+/* PHY Status Register */
+#define MII_SR_EXTENDED_CAPS     0x0001	/* Extended register capabilities */
+#define MII_SR_JABBER_DETECT     0x0002	/* Jabber Detected */
+#define MII_SR_LINK_STATUS       0x0004	/* Link Status 1 = link */
+#define MII_SR_AUTONEG_CAPS      0x0008	/* Auto Neg Capable */
+#define MII_SR_REMOTE_FAULT      0x0010	/* Remote Fault Detect */
+#define MII_SR_AUTONEG_COMPLETE  0x0020	/* Auto Neg Complete */
+#define MII_SR_PREAMBLE_SUPPRESS 0x0040	/* Preamble may be suppressed */
+#define MII_SR_EXTENDED_STATUS   0x0100	/* Ext. status info in Reg 0x0F */
+#define MII_SR_100T2_HD_CAPS     0x0200	/* 100T2 Half Duplex Capable */
+#define MII_SR_100T2_FD_CAPS     0x0400	/* 100T2 Full Duplex Capable */
+#define MII_SR_10T_HD_CAPS       0x0800	/* 10T   Half Duplex Capable */
+#define MII_SR_10T_FD_CAPS       0x1000	/* 10T   Full Duplex Capable */
+#define MII_SR_100X_HD_CAPS      0x2000	/* 100X  Half Duplex Capable */
+#define MII_SR_100X_FD_CAPS      0x4000	/* 100X  Full Duplex Capable */
+#define MII_SR_100T4_CAPS        0x8000	/* 100T4 Capable */
+
 /* Interrupt Cause Read */
 #define E1000_ICR_TXDW          0x00000001 /* Transmit desc written back */
 #define E1000_ICR_TXQE          0x00000002 /* Transmit Queue empty */
-- 
1.7.7

  parent reply	other threads:[~2012-03-28 12:53 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-28 12:52 [Qemu-devel] [PATCH stable-0.15 00/36] Preparing 0.15.2 Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 01/36] ccid: Fix buffer overrun in handling of VSC_ATR message Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 02/36] qdev: Reset hot-plugged devices Andreas Färber
2012-03-28 12:52 ` Andreas Färber [this message]
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 04/36] e1000: Don't set the Capabilities List bit Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 05/36] e1000: bounds packet size against buffer size Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 06/36] compatfd.c: Don't pass NULL pointer to SYS_signalfd Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 07/36] kvm: avoid reentring kvm_flush_coalesced_mmio_buffer() Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 08/36] vmdk: vmdk_read_cid returns garbage if p_name is NULL Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 09/36] block: Fix bdrv_open use after free Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 10/36] ide: Fix off-by-one error in array index check Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 11/36] acl: Fix use after free in qemu_acl_reset() Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 12/36] migration: flush migration data to disk Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 13/36] Fix X86 CPU topology in KVM mode Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 14/36] hw/lan9118.c: Add missing 'break' to fix buffer overrun Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 15/36] ac97: don't override the pci subsystem id Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 16/36] vvfat: Fix potential buffer overflow Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 17/36] vns/tls: don't use depricated gnutls functions Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 18/36] block/curl: Implement a flush function on the fd handlers Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 19/36] hda: do not mix output and input streams, RHBZ #740493 Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 20/36] hda: do not mix output and input stream states, " Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 21/36] Teach block/vdi about "discarded" (no longer allocated) blocks Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 22/36] vmdk: Improve error handling Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 23/36] block: set bs->read_only before .bdrv_open() Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 24/36] console: Fix rendering of VGA underline Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 25/36] block: Fix vpc initialization of the Dynamic Disk Header Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 26/36] qcow: Fix bdrv_write_compressed error handling Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 27/36] block: reinitialize across bdrv_close()/bdrv_open() Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 28/36] qxl: stride fixup Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 29/36] vmdk: Fix possible segfaults Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 30/36] pc: Fix floppy drives with if=none Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 31/36] cpu-common: Have a ram_addr_t of uint64 with Xen Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 32/36] Error check find_ram_offset Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 33/36] pc: add pc-0.15 Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 34/36] pc: fix event_idx compatibility for virtio devices Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 35/36] Add missing trace call to oslib-posix.c:qemu_vmalloc() Andreas Färber
2012-03-28 12:52 ` [Qemu-devel] [PATCH stable-0.15 36/36] qemu_vmalloc: align properly for transparent hugepages and KVM Andreas Färber
2012-03-28 17:06 ` [Qemu-devel] [PATCH stable-0.15 00/36] Preparing 0.15.2 Stefan Weil
2012-06-10 22:11   ` Andreas Färber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1332939159-16434-4-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=bjorn@mork.no \
    --cc=kvm@suse.de \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).