Skip to content

Commit d05596f

Browse files
author
Paolo Abeni
committed
Merge branch 'net-pcs-xpcs-yet-more-cleanups'
Russell King says: ==================== net: pcs: xpcs: yet more cleanups I've found yet more potential for cleanups in the XPCS driver. The first patch switches to using generic register definitions. Next, there's an overly complex bit of code in xpcs_link_up_1000basex() which can be simplified down to a simple if() statement. Then, rearrange xpcs_link_up_1000basex() to separate out the warnings from the functional bit. Next, realising that the functional bit is just the helper function we already have and are using in the SGMII version of this function, switch over to that. We can now see that xpcs_link_up_1000basex() and xpcs_link_up_sgmii() are basically functionally identical except for the warnings, so merge the two functions. Next, xpcs_config_usxgmii() seems misnamed, so rename it to follow the established pattern. Lastly, "return foo();" where foo is a void function and the function being returned from is also void is a weird programming pattern. Replace this with something more conventional. With these changes, we see yet another reduction in the amount of code in this driver. Tested-by: Serge Semin <[email protected]> ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents b0b3683 + fd4056d commit d05596f

File tree

2 files changed

+65
-81
lines changed

2 files changed

+65
-81
lines changed

drivers/net/pcs/pcs-xpcs.c

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ static int xpcs_poll_reset(struct dw_xpcs *xpcs, int dev)
223223
int ret, val;
224224

225225
ret = read_poll_timeout(xpcs_read, val,
226-
val < 0 || !(val & MDIO_CTRL1_RESET),
227-
50000, 600000, true, xpcs, dev, MDIO_CTRL1);
226+
val < 0 || !(val & BMCR_RESET),
227+
50000, 600000, true, xpcs, dev, MII_BMCR);
228228
if (val < 0)
229229
ret = val;
230230

@@ -250,7 +250,7 @@ static int xpcs_soft_reset(struct dw_xpcs *xpcs,
250250
return -EINVAL;
251251
}
252252

253-
ret = xpcs_write(xpcs, dev, MDIO_CTRL1, MDIO_CTRL1_RESET);
253+
ret = xpcs_write(xpcs, dev, MII_BMCR, BMCR_RESET);
254254
if (ret < 0)
255255
return ret;
256256

@@ -311,7 +311,7 @@ static int xpcs_read_fault_c73(struct dw_xpcs *xpcs,
311311
return 0;
312312
}
313313

314-
static void xpcs_config_usxgmii(struct dw_xpcs *xpcs, int speed)
314+
static void xpcs_link_up_usxgmii(struct dw_xpcs *xpcs, int speed)
315315
{
316316
int ret, speed_sel;
317317

@@ -343,7 +343,7 @@ static void xpcs_config_usxgmii(struct dw_xpcs *xpcs, int speed)
343343
if (ret < 0)
344344
goto out;
345345

346-
ret = xpcs_modify(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, DW_USXGMII_SS_MASK,
346+
ret = xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR, DW_USXGMII_SS_MASK,
347347
speed_sel | DW_USXGMII_FULL);
348348
if (ret < 0)
349349
goto out;
@@ -646,19 +646,21 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs,
646646
* speed/duplex mode change by HW after SGMII AN complete)
647647
* 5) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 1b (Enable SGMII AN)
648648
*
649+
* Note that VR_MII_MMD_CTRL is MII_BMCR.
650+
*
649651
* Note: Since it is MAC side SGMII, there is no need to set
650652
* SR_MII_AN_ADV. MAC side SGMII receives AN Tx Config from
651653
* PHY about the link state change after C28 AN is completed
652654
* between PHY and Link Partner. There is also no need to
653655
* trigger AN restart for MAC-side SGMII.
654656
*/
655-
mdio_ctrl = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL);
657+
mdio_ctrl = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMCR);
656658
if (mdio_ctrl < 0)
657659
return mdio_ctrl;
658660

659-
if (mdio_ctrl & AN_CL37_EN) {
660-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL,
661-
mdio_ctrl & ~AN_CL37_EN);
661+
if (mdio_ctrl & BMCR_ANENABLE) {
662+
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,
663+
mdio_ctrl & ~BMCR_ANENABLE);
662664
if (ret < 0)
663665
return ret;
664666
}
@@ -696,8 +698,8 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs,
696698
return ret;
697699

698700
if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
699-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL,
700-
mdio_ctrl | AN_CL37_EN);
701+
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,
702+
mdio_ctrl | BMCR_ANENABLE);
701703

702704
return ret;
703705
}
@@ -715,14 +717,16 @@ static int xpcs_config_aneg_c37_1000basex(struct dw_xpcs *xpcs,
715717
* be disabled first:-
716718
* 1) VR_MII_MMD_CTRL Bit(12)[AN_ENABLE] = 0b
717719
* 2) VR_MII_AN_CTRL Bit(2:1)[PCS_MODE] = 00b (1000BASE-X C37)
720+
*
721+
* Note that VR_MII_MMD_CTRL is MII_BMCR.
718722
*/
719-
mdio_ctrl = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL);
723+
mdio_ctrl = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMCR);
720724
if (mdio_ctrl < 0)
721725
return mdio_ctrl;
722726

723-
if (mdio_ctrl & AN_CL37_EN) {
724-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL,
725-
mdio_ctrl & ~AN_CL37_EN);
727+
if (mdio_ctrl & BMCR_ANENABLE) {
728+
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,
729+
mdio_ctrl & ~BMCR_ANENABLE);
726730
if (ret < 0)
727731
return ret;
728732
}
@@ -760,8 +764,8 @@ static int xpcs_config_aneg_c37_1000basex(struct dw_xpcs *xpcs,
760764
return ret;
761765

762766
if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
763-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL,
764-
mdio_ctrl | AN_CL37_EN);
767+
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,
768+
mdio_ctrl | BMCR_ANENABLE);
765769
if (ret < 0)
766770
return ret;
767771
}
@@ -780,9 +784,9 @@ static int xpcs_config_2500basex(struct dw_xpcs *xpcs)
780784
if (ret < 0)
781785
return ret;
782786

783-
return xpcs_modify(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_CTRL,
784-
AN_CL37_EN | SGMII_SPEED_SS6 | SGMII_SPEED_SS13,
785-
SGMII_SPEED_SS6);
787+
return xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR,
788+
BMCR_ANENABLE | BMCR_SPEED1000 | BMCR_SPEED100,
789+
BMCR_SPEED1000);
786790
}
787791

788792
static int xpcs_do_config(struct dw_xpcs *xpcs, phy_interface_t interface,
@@ -972,14 +976,14 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,
972976

973977
state->link = true;
974978

975-
speed = xpcs_read(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1);
979+
speed = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMCR);
976980
if (speed < 0)
977981
return speed;
978982

979-
speed &= SGMII_SPEED_SS13 | SGMII_SPEED_SS6;
980-
if (speed == SGMII_SPEED_SS6)
983+
speed &= BMCR_SPEED100 | BMCR_SPEED1000;
984+
if (speed == BMCR_SPEED1000)
981985
state->speed = SPEED_1000;
982-
else if (speed == SGMII_SPEED_SS13)
986+
else if (speed == BMCR_SPEED100)
983987
state->speed = SPEED_100;
984988
else if (speed == 0)
985989
state->speed = SPEED_10;
@@ -988,9 +992,9 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,
988992
if (duplex < 0)
989993
return duplex;
990994

991-
if (duplex & DW_FULL_DUPLEX)
995+
if (duplex & ADVERTISE_1000XFULL)
992996
state->duplex = DUPLEX_FULL;
993-
else if (duplex & DW_HALF_DUPLEX)
997+
else if (duplex & ADVERTISE_1000XHALF)
994998
state->duplex = DUPLEX_HALF;
995999

9961000
xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS, 0);
@@ -1039,13 +1043,13 @@ static int xpcs_get_state_2500basex(struct dw_xpcs *xpcs,
10391043
{
10401044
int ret;
10411045

1042-
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_MMD_STS);
1046+
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMSR);
10431047
if (ret < 0) {
10441048
state->link = 0;
10451049
return ret;
10461050
}
10471051

1048-
state->link = !!(ret & DW_VR_MII_MMD_STS_LINK_STS);
1052+
state->link = !!(ret & BMSR_LSTATUS);
10491053
if (!state->link)
10501054
return 0;
10511055

@@ -1100,48 +1104,32 @@ static void xpcs_get_state(struct phylink_pcs *pcs,
11001104
}
11011105
}
11021106

1103-
static void xpcs_link_up_sgmii(struct dw_xpcs *xpcs, unsigned int neg_mode,
1104-
int speed, int duplex)
1107+
static void xpcs_link_up_sgmii_1000basex(struct dw_xpcs *xpcs,
1108+
unsigned int neg_mode,
1109+
phy_interface_t interface,
1110+
int speed, int duplex)
11051111
{
1106-
int val, ret;
1112+
int ret;
11071113

11081114
if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
11091115
return;
11101116

1111-
val = mii_bmcr_encode_fixed(speed, duplex);
1112-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, val);
1113-
if (ret)
1114-
dev_err(&xpcs->mdiodev->dev, "%s: xpcs_write returned %pe\n",
1115-
__func__, ERR_PTR(ret));
1116-
}
1117-
1118-
static void xpcs_link_up_1000basex(struct dw_xpcs *xpcs, unsigned int neg_mode,
1119-
int speed, int duplex)
1120-
{
1121-
int val, ret;
1122-
1123-
if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
1124-
return;
1117+
if (interface == PHY_INTERFACE_MODE_1000BASEX) {
1118+
if (speed != SPEED_1000) {
1119+
dev_err(&xpcs->mdiodev->dev,
1120+
"%s: speed %dMbps not supported\n",
1121+
__func__, speed);
1122+
return;
1123+
}
11251124

1126-
switch (speed) {
1127-
case SPEED_1000:
1128-
val = BMCR_SPEED1000;
1129-
break;
1130-
case SPEED_100:
1131-
case SPEED_10:
1132-
default:
1133-
dev_err(&xpcs->mdiodev->dev, "%s: speed = %d\n",
1134-
__func__, speed);
1135-
return;
1125+
if (duplex != DUPLEX_FULL)
1126+
dev_err(&xpcs->mdiodev->dev,
1127+
"%s: half duplex not supported\n",
1128+
__func__);
11361129
}
11371130

1138-
if (duplex == DUPLEX_FULL)
1139-
val |= BMCR_FULLDPLX;
1140-
else
1141-
dev_err(&xpcs->mdiodev->dev, "%s: half duplex not supported\n",
1142-
__func__);
1143-
1144-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, val);
1131+
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,
1132+
mii_bmcr_encode_fixed(speed, duplex));
11451133
if (ret)
11461134
dev_err(&xpcs->mdiodev->dev, "%s: xpcs_write returned %pe\n",
11471135
__func__, ERR_PTR(ret));
@@ -1152,19 +1140,27 @@ static void xpcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
11521140
{
11531141
struct dw_xpcs *xpcs = phylink_pcs_to_xpcs(pcs);
11541142

1155-
if (interface == PHY_INTERFACE_MODE_USXGMII)
1156-
return xpcs_config_usxgmii(xpcs, speed);
1157-
if (interface == PHY_INTERFACE_MODE_SGMII)
1158-
return xpcs_link_up_sgmii(xpcs, neg_mode, speed, duplex);
1159-
if (interface == PHY_INTERFACE_MODE_1000BASEX)
1160-
return xpcs_link_up_1000basex(xpcs, neg_mode, speed, duplex);
1143+
switch (interface) {
1144+
case PHY_INTERFACE_MODE_USXGMII:
1145+
xpcs_link_up_usxgmii(xpcs, speed);
1146+
break;
1147+
1148+
case PHY_INTERFACE_MODE_SGMII:
1149+
case PHY_INTERFACE_MODE_1000BASEX:
1150+
xpcs_link_up_sgmii_1000basex(xpcs, neg_mode, interface, speed,
1151+
duplex);
1152+
break;
1153+
1154+
default:
1155+
break;
1156+
}
11611157
}
11621158

11631159
static void xpcs_an_restart(struct phylink_pcs *pcs)
11641160
{
11651161
struct dw_xpcs *xpcs = phylink_pcs_to_xpcs(pcs);
11661162

1167-
xpcs_modify(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, BMCR_ANRESTART,
1163+
xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR, BMCR_ANRESTART,
11681164
BMCR_ANRESTART);
11691165
}
11701166

drivers/net/pcs/pcs-xpcs.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454

5555
/* Clause 37 Defines */
5656
/* VR MII MMD registers offsets */
57-
#define DW_VR_MII_MMD_CTRL 0x0000
58-
#define DW_VR_MII_MMD_STS 0x0001
59-
#define DW_VR_MII_MMD_STS_LINK_STS BIT(2)
6057
#define DW_VR_MII_DIG_CTRL1 0x8000
6158
#define DW_VR_MII_AN_CTRL 0x8001
6259
#define DW_VR_MII_AN_INTR_STS 0x8002
@@ -93,15 +90,6 @@
9390
#define DW_VR_MII_C37_ANSGM_SP_1000 0x2
9491
#define DW_VR_MII_C37_ANSGM_SP_LNKSTS BIT(4)
9592

96-
/* SR MII MMD Control defines */
97-
#define AN_CL37_EN BIT(12) /* Enable Clause 37 auto-nego */
98-
#define SGMII_SPEED_SS13 BIT(13) /* SGMII speed along with SS6 */
99-
#define SGMII_SPEED_SS6 BIT(6) /* SGMII speed along with SS13 */
100-
101-
/* SR MII MMD AN Advertisement defines */
102-
#define DW_HALF_DUPLEX BIT(6)
103-
#define DW_FULL_DUPLEX BIT(5)
104-
10593
/* VR MII EEE Control 0 defines */
10694
#define DW_VR_MII_EEE_LTX_EN BIT(0) /* LPI Tx Enable */
10795
#define DW_VR_MII_EEE_LRX_EN BIT(1) /* LPI Rx Enable */

0 commit comments

Comments
 (0)