e1000: link auto-negotiation fixes
v2 cover e1000: link auto-negotiation fixes
New in v2:
- checking for E1000_FLAG_AUTONEG in s->compat_flags when deciding whether to run the auto-negotiation timer vs. simply forcing the link up during e1000_set_link_status()
- grouped E1000_FLAG_AUTONEG check in s->compat_flags tighter with the rest of the auto-negotiation checks in the two other locations they appear in the source code (hopefully improving clarity).
- added patch to move the auto-negotiation timer function past set_ics() to avoid the need for a forward declaration.
This series contains a few fixes and improvements in the emulation of link auto-negotiation:
- use auto-negotiation when the link is bounced externally (e.g. via set_link <foo> down/up on the qemu monitor command line).
- allow mii_tool on linux access to all the phy registers and flags it requires in order to report a successfully auto-negotiated link.
- inject LSC interrupt upon successful link auto-negotiation (required by stock OS X e1000 driver).
Gabriel L. Somlo (4):
e1000: emulate auto-negotiation during external link status change
e1000: improve auto-negotiation reporting via mii-tool
e1000: move e1000_autoneg_timer() to after set_ics()
e1000: signal guest on successful link auto-negotiation
hw/net/e1000.c | 59 ++++++++++++++++++++++++++++++----------------------- hw/net/e1000_regs.h | 3 +++ 2 files changed, 36 insertions(+), 26 deletions(-)
Signature · 1 line
1.9.3
PATCH v2 1/4 e1000: emulate auto-negotiation during external link status change
This patch emulates auto-negotiation when the network link status is modified externally (i.e. via "set_link <id> off/on").
Also, a couple of cleanup items:
- unset PHY status reg. AUTONEG_COMPLETE during link_down()
- set PHY status reg. AUTONEG_COMPLETE during autoneg_timer() only if we actually brought the link up.
- group all checks for "can we, and should we autonegotiate?" together for more clarity.
--- hw/net/e1000.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
hw/net/e1000.c +19 -16
@@ -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,16 @@ e1000_set_link_status(NetClientState *nc)if (nc->link_down) {e1000_link_down (s); }else { -e1000_link_up (s); +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 && + !(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)
@@ -1279,16 +1288,13 @@ static void e1000_pre_save(void *opaque)e1000_mit_timer (s); } -if (!(s->compat_flags &E1000_FLAG_AUTONEG )) { -return ; - } -/* -* If link is down and auto-negotiation is ongoing, complete -* auto-negotiation immediately. This allows is to look at -* MII_SR_AUTONEG_COMPLETE to infer link status on load. +* If link is down and auto-negotiation is supported and ongoing, +* 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 ;
@@ -1313,11 +1319,8 @@ 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 )) { -return 0 ; - } - -if (s->phy_reg[PHY_CTRL ] &MII_CR_AUTO_NEG_EN && +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 && !(s->phy_reg[PHY_STATUS ] &MII_SR_AUTONEG_COMPLETE )) { nc->link_down = false;
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v2 1/4] e1000: emulate auto-negotiation during external link status change
Quoted 10 lines · Gabriel L. Somlo
This patch emulates auto-negotiation when the network link status is modified externally (i.e. via "
set_link<id> off/on").Also, a couple of cleanup items:
- unset PHY status reg.AUTONEG_COMPLETEduringlink_down()
- set PHY status reg.AUTONEG_COMPLETEduringautoneg_timer()only if we actually brought the link up.
- group all checks for "can we, and should we autonegotiate?" together for more clarity.
Quoted 3 lines
Signed-off-by Gabriel Somlo <[email protected]>Reviewed-by Alexander Graf <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>
Now you did this cleanup, let's have a function
to check autonegotiation in a single place.
Can be patch on top.
Quoted 91 lines
--- hw/net/e1000.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)hw/net/e1000.c +19
-16@@ -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,16 @@ e1000_set_link_status(NetClientState *nc)if (nc->link_down) {e1000_link_down (s); }else { -e1000_link_up (s); +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 && + !(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)@@ -1279,16 +1288,13 @@ static void e1000_pre_save(void *opaque)e1000_mit_timer (s); } -if (!(s->compat_flags &E1000_FLAG_AUTONEG )) { -return ; - } -/* -* If link is down and auto-negotiation is ongoing, complete -* auto-negotiation immediately. This allows is to look at -* MII_SR_AUTONEG_COMPLETE to infer link status on load. +* If link is down and auto-negotiation is supported and ongoing, +* 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 ;@@ -1313,11 +1319,8 @@ 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 )) { -return 0 ; - } - -if (s->phy_reg[PHY_CTRL ] &MII_CR_AUTO_NEG_EN && +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 && !(s->phy_reg[PHY_STATUS ] &MII_SR_AUTONEG_COMPLETE )) { nc->link_down = false;Signature · 1 line
1.9.3
PATCH v2 2/4 e1000: improve auto-negotiation reporting via mii-tool
In reply to Gabriel L. SomloUsing mii-tool (on F20-live), the following output is produced:
SIOCGMIIREG on ens3 failed: Input/output error
ens3: no autonegotiation, 1000baseT-FD flow-control, link ok
The first line (SIOCGMIIREG error) is due to mii-tool's inability to read the PHY auto-negotiation expansion register.
On the second line, "no autonegotiation" is wrong, and caused by the absence of a flag in the link partner ability register which would indicate that our link partner has acked us. This flag is listed as "reserved" in the Intel e1000 manual, but mii-tool uses it as LPA_LPACK from /usr/include/linux/mii.h.
This patch adds read access to PHY_AUTONEG_EXP and defines the link partner ack flag, allowing mii-tool to generate output as normally expected:
ens3: negotiated 1000baseT-FD flow-control, link ok
--- hw/net/e1000.c | 5 ++++- hw/net/e1000_regs.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-)
hw/net/e1000.c +4 -1
@@ -176,6 +176,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 ; + s->phy_reg[PHY_LP_ABILITY ] &= ~MII_LPAR_LPACK ; } static void
@@ -209,6 +210,7 @@ e1000_autoneg_timer(void *opaque)E1000State *s = opaque;if (!qemu_get_queue (s->nic)->link_down) {e1000_link_up (s); + s->phy_reg[PHY_LP_ABILITY ] |=MII_LPAR_LPACK ; s->phy_reg[PHY_STATUS ] |=MII_SR_AUTONEG_COMPLETE ;DBGOUT (PHY ,"Auto negotiation is completed\n" ); }
@@ -227,7 +229,8 @@ static const char phy_regcap[0x20] = { [PHY_CTRL] = PHY_RW, [PHY_1000T_CTRL] = PHY_RW, [PHY_LP_ABILITY] = PHY_R, [PHY_1000T_STATUS] = PHY_R, [PHY_AUTONEG_ADV] = PHY_RW, [M88E1000_RX_ERR_CNTR] = PHY_R, - [PHY_ID2] = PHY_R, [M88E1000_PHY_SPEC_STATUS] = PHY_R + [PHY_ID2] = PHY_R, [M88E1000_PHY_SPEC_STATUS] = PHY_R, + [PHY_AUTONEG_EXP] = PHY_R, };/* PHY_ID2 documented in 8254x_GBe_SDM.pdf, pp. 250 */
hw/net/e1000_regs.h +3 -0
@@ -384,6 +384,9 @@#define MII_SR_100X_FD_CAPS 0x4000/* 100X Full Duplex Capable */ #define MII_SR_100T4_CAPS 0x8000/* 100T4 Capable */ +/* PHY Link Partner Ability Register */ +#define MII_LPAR_LPACK 0x4000/* Acked by link partner */ +/* Interrupt Cause Read */ #define E1000_ICR_TXDW 0x00000001/* Transmit desc written back */ #define E1000_ICR_TXQE 0x00000002/* Transmit Queue empty */
Signature · 1 line
1.9.3
PATCH v2 3/4 e1000: move e1000_autoneg_timer() to after set_ics()
In reply to Gabriel L. SomloEnable calling set_ics() from within e1000_autoneg_timer() without the need for a forward declaration.
This patch contains no functional changes.
--- hw/net/e1000.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
hw/net/e1000.c +12 -12
@@ -204,18 +204,6 @@ set_phy_ctrl(E1000State *s, int index, uint16_t val) } } -static void -e1000_autoneg_timer (void *opaque) -{ -E1000State *s = opaque; -if (!qemu_get_queue (s->nic)->link_down) { -e1000_link_up (s); - s->phy_reg[PHY_LP_ABILITY ] |=MII_LPAR_LPACK ; - s->phy_reg[PHY_STATUS ] |=MII_SR_AUTONEG_COMPLETE ; -DBGOUT (PHY ,"Auto negotiation is completed\n" ); - } -} -static void (*phyreg_writeops[])(E1000State *,int ,uint16_t ) = { [PHY_CTRL ] = set_phy_ctrl, };
@@ -347,6 +335,18 @@ set_ics(E1000State *s, int index, uint32_t val)set_interrupt_cause (s,0 , val | s->mac_reg[ICR ]); } +static void +e1000_autoneg_timer (void *opaque) +{ +E1000State *s = opaque; +if (!qemu_get_queue (s->nic)->link_down) { +e1000_link_up (s); + s->phy_reg[PHY_LP_ABILITY ] |=MII_LPAR_LPACK ; + s->phy_reg[PHY_STATUS ] |=MII_SR_AUTONEG_COMPLETE ; +DBGOUT (PHY ,"Auto negotiation is completed\n" ); + } +} +static int rxbufsize (uint32_t v) {
Signature · 1 line
1.9.3
PATCH v2 4/4 e1000: signal guest on successful link auto-negotiation
In reply to Gabriel L. SomloGenerate a link status change interrupt once link auto-netotiation is successfully completed. This does not affect Linux and Windows (XP and 7 tested) in any way, but is needed by the stock OS X driver (AppleIntel8254XEthernet.kext), which would otherwise fail to notice the link status change event.
--- hw/net/e1000.c | 1 + 1 file changed, 1 insertion(+)
hw/net/e1000.c +1 -0
@@ -344,6 +344,7 @@ e1000_autoneg_timer(void *opaque) s->phy_reg[PHY_LP_ABILITY ] |=MII_LPAR_LPACK ; s->phy_reg[PHY_STATUS ] |=MII_SR_AUTONEG_COMPLETE ;DBGOUT (PHY ,"Auto negotiation is completed\n" ); +set_ics (s,0 ,E1000_ICS_LSC );/* signal link status change to guest */ } }
Signature · 1 line
1.9.3
Michael S. Tsirkin
AppliedQuoted 6 lines · Gabriel L. Somlo
New in v2:
- checking for
E1000_FLAG_AUTONEGins->compat_flagswhen deciding whether to run the auto-negotiation timer vs. simply forcing the link up duringe1000_set_link_status()
Quoted 7 lines
- grouped
E1000_FLAG_AUTONEGcheck ins->compat_flagstighter with the rest of the auto-negotiation checks in the two other locations they appear in the source code (hopefully improving clarity).- added patch to move the auto-negotiation timer function past
set_ics()to avoid the need for a forward declaration.
Applied, thanks everyone.
Quoted 24 lines
This series contains a few fixes and improvements in the emulation of link auto-negotiation:
- use auto-negotiation when the link is bounced externally (e.g. via
set_link<foo> down/up on the qemu monitor command line).- allow
mii_toolon linux access to all the phy registers and flags it requires in order to report a successfully auto-negotiated link.- inject LSC interrupt upon successful link auto-negotiation (required by stock OS X e1000 driver).
Gabriel L. Somlo (4):
e1000: emulate auto-negotiation during external link status change
e1000: improve auto-negotiation reporting via mii-tool
e1000: movee1000_autoneg_timer()to afterset_ics()
e1000: signal guest on successful link auto-negotiationhw/net/e1000.c | 59 ++++++++++++++++++++++++++++++----------------------- hw/net/e1000_regs.h | 3 +++ 2 files changed, 36 insertions(+), 26 deletions(-)Signature · 1 line
1.9.3