net: pcs: xpcs: fix incorrect CL37 AN sequence
PATCH v2 1/1 net: pcs: xpcs: fix incorrect CL37 AN sequence
According to Synopsys DesignWare Cores Ethernet PCS databook, it is required to disable Clause 37 auto-negotiation by programming bit-12 (AN_ENABLE) to 0 if it is already enabled, before programming various fields of VR_MII_AN_CTRL registers.
After all these programming are done, it is then required to enable Clause 37 auto-negotiation by programming bit-12 (AN_ENABLE) to 1.
---
v1 -> v2:
- Removed use of xpcs_modify() helper function.
- Add conditional check on inband auto-negotiation.
drivers/net/pcs/pcs-xpcs.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)
drivers/net/pcs/pcs-xpcs.c +26 -4
@@ -700,11 +700,14 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode)int ret;/* For AN for C37 SGMII mode, the settings are :- -* 1) VR_MII_AN_CTRL Bit(2:1)[PCS_MODE] = 10b (SGMII AN) -* 2) VR_MII_AN_CTRL Bit(3) [TX_CONFIG] = 0b (MAC side SGMII) +* 1) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 0b (Disable SGMII AN in case +it is already enabled) +* 2) VR_MII_AN_CTRL Bit(2:1)[PCS_MODE] = 10b (SGMII AN) +* 3) VR_MII_AN_CTRL Bit(3) [TX_CONFIG] = 0b (MAC side SGMII) * DW xPCS used with DW EQoS MAC is always MAC side SGMII. -* 3) VR_MII_DIG_CTRL1 Bit(9) [MAC_AUTO_SW] = 1b (Automatic +* 4) VR_MII_DIG_CTRL1 Bit(9) [MAC_AUTO_SW] = 1b (Automatic * speed/duplex mode change by HW after SGMII AN complete) +* 5) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 1b (Enable SGMII AN) * * Note: Since it is MAC side SGMII, there is no need to set * SR_MII_AN_ADV. MAC side SGMII receives AN Tx Config from
@@ -712,6 +715,12 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode)* between PHY and Link Partner. There is also no need to * trigger AN restart for MAC-side SGMII. */ + ret =xpcs_read (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_MMD_CTRL ); +if (ret <0 ) +return ret; + ret &= ~AN_CL37_EN ; +xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_MMD_CTRL , ret); + ret =xpcs_read (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_AN_CTRL );if (ret <0 )return ret;
@@ -736,7 +745,20 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode)else ret &= ~DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW ; -return xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_DIG_CTRL1 , ret); + ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_DIG_CTRL1 , ret); +if (ret <0 ) +return ret; + + ret =xpcs_read (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_MMD_CTRL ); +if (ret <0 ) +return ret; + +if (phylink_autoneg_inband (mode)) + ret |=AN_CL37_EN ; +else + ret &= ~AN_CL37_EN ; + +return xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_MMD_CTRL , ret); }static int xpcs_config_2500basex (struct dw_xpcs *xpcs)
Signature · 1 line
2.25.1
Quoted 11 lines · Wong Vee Khee
According to Synopsys DesignWare Cores Ethernet PCS databook, it is required to disable Clause 37 auto-negotiation by programming bit-12 (
AN_ENABLE) to 0 if it is already enabled, before programming various fields ofVR_MII_AN_CTRLregisters.After all these programming are done, it is then required to enable Clause 37 auto-negotiation by programming bit-12 (
AN_ENABLE) to 1.Cc Vladimir Oltean <[email protected]>Signed-off-by Wong Vee Khee <[email protected]>---
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 30 lines
v1 -> v2:
- Removed use ofxpcs_modify()helper function.
- Add conditional check on inband auto-negotiation.drivers/net/pcs/pcs-xpcs.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)drivers/net/pcs/pcs-xpcs.c +6
-3@@ -700,11 +700,14 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode)int ret;/* For AN for C37 SGMII mode, the settings are :- -* 1) VR_MII_AN_CTRL Bit(2:1)[PCS_MODE] = 10b (SGMII AN) -* 2) VR_MII_AN_CTRL Bit(3) [TX_CONFIG] = 0b (MAC side SGMII) +* 1) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 0b (Disable SGMII AN in case +it is already enabled) +* 2) VR_MII_AN_CTRL Bit(2:1)[PCS_MODE] = 10b (SGMII AN) +* 3) VR_MII_AN_CTRL Bit(3) [TX_CONFIG] = 0b (MAC side SGMII) * DW xPCS used with DW EQoS MAC is always MAC side SGMII. -* 3) VR_MII_DIG_CTRL1 Bit(9) [MAC_AUTO_SW] = 1b (Automatic +* 4) VR_MII_DIG_CTRL1 Bit(9) [MAC_AUTO_SW] = 1b (Automatic * speed/duplex mode change by HW after SGMII AN complete) +* 5) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 1b (Enable SGMII AN) * * Note: Since it is MAC side SGMII, there is no need to set * SR_MII_AN_ADV. MAC side SGMII receives AN Tx Config from
drivers/net/pcs/pcs-xpcs.c static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode) · line 722
Quoted 8 lines
drivers/net/pcs/pcs-xpcs.c +5
-0@@ -712,6 +715,12 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode)* between PHY and Link Partner. There is also no need to * trigger AN restart for MAC-side SGMII. */ + ret =xpcs_read (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_MMD_CTRL ); +if (ret <0 ) +return ret; + ret &= ~AN_CL37_EN ; +xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_MMD_CTRL , ret);
For consistency can you please check the return code from this xpcs_write too?
Quoted 13 lines
drivers/net/pcs/pcs-xpcs.c +5
-1+ ret =xpcs_read (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_AN_CTRL );if (ret <0 )return ret;@@ -736,7 +745,20 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode)else ret &= ~DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW ; -return xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_DIG_CTRL1 , ret); + ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_DIG_CTRL1 , ret); +if (ret <0 ) +return ret; +
drivers/net/pcs/pcs-xpcs.c static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, unsigned int mode) · line 761
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +10
-0+ ret =xpcs_read (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_MMD_CTRL ); +if (ret <0 ) +return ret; + +if (phylink_autoneg_inband (mode)) + ret |=AN_CL37_EN ; +else + ret &= ~AN_CL37_EN ; + +return xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_MMD_CTRL , ret);
Not sure whether this is too much for "net" or not, but I suppose it is pretty much relevant.
Clearing AN_CL37_EN during the first step is only necessary if it was set in the first place. Otherwise, you could do only the xpcs_read but not the xpcs_write.
At the end, you don't really need to read DW_VR_MII_MMD_CTRL again, you just read it above, didn't you, can't you save it in a local variable?
And you only need to perform the write if the state of the AN_CL37_EN bit changed, i.e. it was 0 before, and is now 1.
What I'm trying to say is that for the sja1105 driver, the XPCS is accessed over SPI commands, and I would like for the number of those to be minimized if possible. Thanks.
I've tested the change and it still works, by the way. I will add the appropriate tags when you resend the v3.
Quoted 6 lines
drivers/net/pcs/pcs-xpcs.c +0
-0}static int xpcs_config_2500basex (struct dw_xpcs *xpcs)Signature · 1 line
2.25.1