net: pcs: xpcs: fix SGMII state reading
Subsystems (5)
PATCH 1/1 net: pcs: xpcs: fix SGMII state reading
Commit 2a22b7ae2fa3 ("net: pcs: xpcs: adapt Wangxun NICs for SGMII mode") added a path in xpcs_get_state_c37_sgmii() that reads speed/duplex from BMCR after AN completes. However, BMCR does not reflect the negotiated result on the hardware where this has been tested:
- On RK3568 (MAC side SGMII), BMCR returns a fixed hardware reset value
- Wangxun engineer Jiawen Wu confirmed that on their side, "BMCR looks like it only wants to be return as 0" [0]
The correct information is available in CL37_ANSGM_STS, which contains the actual link status and negotiated speed/duplex.
This bug was previously masked by phylink core, which overrides the PCS link state with the PHY state when a PHY is present:
/* If we have a phy, the "up" state is the union of both the
* PHY and the MAC
*/
if (phy)
link_state.link &= pl->phy_state.link;Thus, when the link is down, the PHY's link_down state is applied on top of whatever the PCS reports, hiding the broken PCS state reading path.
Modify xpcs_get_state_c37_sgmii() to:
1. Read link state from CL37_ANSGM_STS
2. If link is up, report speed/duplex from CL37_ANSGM_STS
3. Remove the broken BMCR reading path entirely
Also properly set state->an_complete to reflect the AN completion status, and clear CL37_ANCMPLT_INTR when link is down to avoid stale state.
[0] https://lore.kernel.org/all/[email protected]/
--- drivers/net/pcs/pcs-xpcs.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-)
drivers/net/pcs/pcs-xpcs.c +7 -25
@@ -1058,6 +1058,7 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,/* Reset link_state */ state->link = false; + state->an_complete = false; state->speed =SPEED_UNKNOWN ; state->duplex =DUPLEX_UNKNOWN ; state->pause =0 ;
@@ -1069,6 +1070,8 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,if (ret <0 )return ret; + state->an_complete = ret &DW_VR_MII_AN_STS_C37_ANCMPLT_INTR ; +if (ret &DW_VR_MII_C37_ANSGM_SP_LNKSTS ) {int speed_value;
@@ -1086,34 +1089,13 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs, state->duplex =DUPLEX_FULL ; else state->duplex = DUPLEX_HALF; - }else if (ret ==DW_VR_MII_AN_STS_C37_ANCMPLT_INTR ) { -int speed, duplex; - - state->link = true; - - speed =xpcs_read (xpcs,MDIO_MMD_VEND2 ,MII_BMCR ); -if (speed <0 ) -return speed; - - speed &=BMCR_SPEED100 |BMCR_SPEED1000 ; -if (speed ==BMCR_SPEED1000 ) - state->speed =SPEED_1000 ; -else if (speed ==BMCR_SPEED100 ) - state->speed =SPEED_100 ; -else if (speed ==0 ) - state->speed =SPEED_10 ; - - duplex =xpcs_read (xpcs,MDIO_MMD_VEND2 ,MII_ADVERTISE ); -if (duplex <0 ) -return duplex; -if (duplex &ADVERTISE_1000XFULL ) - state->duplex =DUPLEX_FULL ; -else if (duplex &ADVERTISE_1000XHALF ) - state->duplex =DUPLEX_HALF ; +return 0 ; + } +/* Clear AN complete status or interrupt */ +if (state->an_complete)xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_AN_INTR_STS ,0 ); - }return 0 ; }
Signature · 1 line
2.47.3
Hi,
Quoted 32 lines · Coia Prant
Commit
2a22b7ae2fa3("net: pcs: xpcs: adapt Wangxun NICs for SGMII mode") added a path inxpcs_get_state_c37_sgmii()that reads speed/duplex from BMCR after AN completes. However, BMCR does not reflect the negotiated result on the hardware where this has been tested:- On RK3568 (MAC side SGMII), BMCR returns a fixed hardware reset value
- Wangxun engineer Jiawen Wu confirmed that on their side, "BMCR looks like it only wants to be return as 0" [0]The correct information is available in
CL37_ANSGM_STS, which contains the actual link status and negotiated speed/duplex.This bug was previously masked by phylink core, which overrides the PCS link state with the PHY state when a PHY is present:
/* If we have a phy, the "up" state is the union of both the * PHY and the MAC */ if (phy) link_state.link &= pl->phy_state.link;Thus, when the link is down, the PHY's
link_downstate is applied on top of whatever the PCS reports, hiding the broken PCS state reading path.Modify
xpcs_get_state_c37_sgmii()to:
1. Read link state fromCL37_ANSGM_STS
2. If link is up, report speed/duplex fromCL37_ANSGM_STS
3. Remove the broken BMCR reading path entirelyAlso properly set
state->an_completeto reflect the AN completion status, and clearCL37_ANCMPLT_INTRwhen link is down to avoid stale state.
Quoted 6 lines
[0] https://lore.kernel.org/all/[email protected]/
Fixes 2a22b7ae2fa3 ("net: pcs: xpcs: adapt Wangxun NICs for SGMII mode")Tested-by Jiawen Wu <[email protected]>Signed-off-by Coia Prant <[email protected]>
Give that a test on ksz9477 that has an older XPCS for SGMII, this makes some sense to me and no regressions were found.
Maxime
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 17 Jul 2026 15:43:25 +0800 you wrote:
Commit
2a22b7ae2fa3("net: pcs: xpcs: adapt Wangxun NICs for SGMII mode") added a path inxpcs_get_state_c37_sgmii()that reads speed/duplex from BMCR after AN completes. However, BMCR does not reflect the negotiated result on the hardware where this has been tested:- On RK3568 (MAC side SGMII), BMCR returns a fixed hardware reset value
- Wangxun engineer Jiawen Wu confirmed that on their side, "BMCR looks like it only wants to be return as 0" [0][...]
Here is the summary with links:
- [net] net: pcs: xpcs: fix SGMII state reading
https://git.kernel.org/netdev/net/c/def9a4745e10
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html