Skip to content

Commit 1d2709d

Browse files
Russell King (Oracle)Paolo Abeni
authored andcommitted
net: pcs: xpcs: use generic register definitions
As a general policy, we refer our generic register definitions over vendor specific definitions. In XPCS, it appears that the register layout follows a BMCR, BMSR and ADVERTISE register definition. We already refer to this BMCR register using several different macros which is confusing. Convert the following register definitions to generic versions: DW_VR_MII_MMD_CTRL => MII_BMCR MDIO_CTRL1 => MII_BMCR AN_CL37_EN => BMCR_ANENABLE SGMII_SPEED_SS6 => BMCR_SPEED1000 SGMII_SPEED_SS13 => BMCR_SPEED100 MDIO_CTRL1_RESET => BMCR_RESET DW_VR_MII_MMD_STS => MII_BMSR DW_VR_MII_MMD_STS_LINK_STS => BMSR_LSTATUS DW_FULL_DUPLEX => ADVERTISE_1000XFULL iDW_HALF_DUPLEX => ADVERTISE_1000XHALF Signed-off-by: Russell King (Oracle) <[email protected]> Tested-by: Serge Semin <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent b0b3683 commit 1d2709d

File tree

2 files changed

+34
-42
lines changed

2 files changed

+34
-42
lines changed

drivers/net/pcs/pcs-xpcs.c

Lines changed: 34 additions & 30 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

@@ -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

@@ -1109,7 +1113,7 @@ static void xpcs_link_up_sgmii(struct dw_xpcs *xpcs, unsigned int neg_mode,
11091113
return;
11101114

11111115
val = mii_bmcr_encode_fixed(speed, duplex);
1112-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, val);
1116+
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR, val);
11131117
if (ret)
11141118
dev_err(&xpcs->mdiodev->dev, "%s: xpcs_write returned %pe\n",
11151119
__func__, ERR_PTR(ret));
@@ -1141,7 +1145,7 @@ static void xpcs_link_up_1000basex(struct dw_xpcs *xpcs, unsigned int neg_mode,
11411145
dev_err(&xpcs->mdiodev->dev, "%s: half duplex not supported\n",
11421146
__func__);
11431147

1144-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, val);
1148+
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR, val);
11451149
if (ret)
11461150
dev_err(&xpcs->mdiodev->dev, "%s: xpcs_write returned %pe\n",
11471151
__func__, ERR_PTR(ret));
@@ -1164,7 +1168,7 @@ static void xpcs_an_restart(struct phylink_pcs *pcs)
11641168
{
11651169
struct dw_xpcs *xpcs = phylink_pcs_to_xpcs(pcs);
11661170

1167-
xpcs_modify(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, BMCR_ANRESTART,
1171+
xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR, BMCR_ANRESTART,
11681172
BMCR_ANRESTART);
11691173
}
11701174

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)