OSDN Git Service

net: pcs: xpcs: clean up reading clause 73 link partner advertisement
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Tue, 23 May 2023 10:16:03 +0000 (11:16 +0100)
committerJakub Kicinski <kuba@kernel.org>
Wed, 24 May 2023 16:13:22 +0000 (09:13 -0700)
Read the clause 73 link partner advertisement in a loop and then
translate to the ethtool modes.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/pcs/pcs-xpcs.c
drivers/net/pcs/pcs-xpcs.h

index 72f25e7..5723abf 100644 (file)
@@ -487,7 +487,7 @@ static int xpcs_aneg_done_c73(struct dw_xpcs *xpcs,
                return ret;
 
        if (ret & MDIO_AN_STAT1_COMPLETE) {
-               ret = xpcs_read(xpcs, MDIO_MMD_AN, DW_SR_AN_LP_ABL1);
+               ret = xpcs_read(xpcs, MDIO_MMD_AN, MDIO_AN_LPA);
                if (ret < 0)
                        return ret;
 
@@ -506,7 +506,8 @@ static int xpcs_aneg_done_c73(struct dw_xpcs *xpcs,
 static int xpcs_read_lpa_c73(struct dw_xpcs *xpcs,
                             struct phylink_link_state *state)
 {
-       int ret;
+       u16 lpa[3];
+       int i, ret;
 
        ret = xpcs_read(xpcs, MDIO_MMD_AN, MDIO_STAT1);
        if (ret < 0)
@@ -519,32 +520,26 @@ static int xpcs_read_lpa_c73(struct dw_xpcs *xpcs,
 
        phylink_set(state->lp_advertising, Autoneg);
 
-       /* Clause 73 outcome */
-       ret = xpcs_read(xpcs, MDIO_MMD_AN, DW_SR_AN_LP_ABL3);
-       if (ret < 0)
-               return ret;
-
-       if (ret & DW_C73_2500KX)
-               phylink_set(state->lp_advertising, 2500baseX_Full);
+       /* Read Clause 73 link partner advertisement */
+       for (i = ARRAY_SIZE(lpa); --i >= 0; ) {
+               ret = xpcs_read(xpcs, MDIO_MMD_AN, MDIO_AN_LPA + i);
+               if (ret < 0)
+                       return ret;
 
-       ret = xpcs_read(xpcs, MDIO_MMD_AN, DW_SR_AN_LP_ABL2);
-       if (ret < 0)
-               return ret;
+               lpa[i] = ret;
+       }
 
-       if (ret & DW_C73_1000KX)
+       if (lpa[2] & DW_C73_2500KX)
+               phylink_set(state->lp_advertising, 2500baseX_Full);
+       if (lpa[1] & DW_C73_1000KX)
                phylink_set(state->lp_advertising, 1000baseKX_Full);
-       if (ret & DW_C73_10000KX4)
+       if (lpa[1] & DW_C73_10000KX4)
                phylink_set(state->lp_advertising, 10000baseKX4_Full);
-       if (ret & DW_C73_10000KR)
+       if (lpa[1] & DW_C73_10000KR)
                phylink_set(state->lp_advertising, 10000baseKR_Full);
-
-       ret = xpcs_read(xpcs, MDIO_MMD_AN, DW_SR_AN_LP_ABL1);
-       if (ret < 0)
-               return ret;
-
-       if (ret & DW_C73_PAUSE)
+       if (lpa[0] & DW_C73_PAUSE)
                phylink_set(state->lp_advertising, Pause);
-       if (ret & DW_C73_ASYM_PAUSE)
+       if (lpa[0] & DW_C73_ASYM_PAUSE)
                phylink_set(state->lp_advertising, Asym_Pause);
 
        linkmode_and(state->lp_advertising, state->lp_advertising,
index 770df50..68c6b5a 100644 (file)
@@ -32,9 +32,6 @@
 #define DW_SR_AN_ADV1                  0x10
 #define DW_SR_AN_ADV2                  0x11
 #define DW_SR_AN_ADV3                  0x12
-#define DW_SR_AN_LP_ABL1               0x13
-#define DW_SR_AN_LP_ABL2               0x14
-#define DW_SR_AN_LP_ABL3               0x15
 
 /* Clause 73 Defines */
 /* AN_LP_ABL1 */