Skip to content

Commit 4145921

Browse files
Russell King (Oracle)Paolo Abeni
authored andcommitted
net: pcs: xpcs: combine xpcs_link_up_{1000basex,sgmii}()
xpcs_link_up_sgmii() and xpcs_link_up_1000basex() are almost identical with the exception of checking the speed and duplex for 1000BASE-X. Combine the two functions. Signed-off-by: Russell King (Oracle) <[email protected]> Tested-by: Serge Semin <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 1c17f9d commit 4145921

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

drivers/net/pcs/pcs-xpcs.c

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,41 +1104,32 @@ static void xpcs_get_state(struct phylink_pcs *pcs,
11041104
}
11051105
}
11061106

1107-
static void xpcs_link_up_sgmii(struct dw_xpcs *xpcs, unsigned int neg_mode,
1108-
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)
11091111
{
1110-
int val, ret;
1112+
int ret;
11111113

11121114
if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
11131115
return;
11141116

1115-
val = mii_bmcr_encode_fixed(speed, duplex);
1116-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR, val);
1117-
if (ret)
1118-
dev_err(&xpcs->mdiodev->dev, "%s: xpcs_write returned %pe\n",
1119-
__func__, ERR_PTR(ret));
1120-
}
1121-
1122-
static void xpcs_link_up_1000basex(struct dw_xpcs *xpcs, unsigned int neg_mode,
1123-
int speed, int duplex)
1124-
{
1125-
int val, ret;
1126-
1127-
if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
1128-
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+
}
11291124

1130-
if (speed != SPEED_1000) {
1131-
dev_err(&xpcs->mdiodev->dev, "%s: speed %dMbps not supported\n",
1132-
__func__, speed);
1133-
return;
1125+
if (duplex != DUPLEX_FULL)
1126+
dev_err(&xpcs->mdiodev->dev,
1127+
"%s: half duplex not supported\n",
1128+
__func__);
11341129
}
11351130

1136-
if (duplex != DUPLEX_FULL)
1137-
dev_err(&xpcs->mdiodev->dev, "%s: half duplex not supported\n",
1138-
__func__);
1139-
1140-
val = mii_bmcr_encode_fixed(speed, duplex);
1141-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR, val);
1131+
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,
1132+
mii_bmcr_encode_fixed(speed, duplex));
11421133
if (ret)
11431134
dev_err(&xpcs->mdiodev->dev, "%s: xpcs_write returned %pe\n",
11441135
__func__, ERR_PTR(ret));
@@ -1151,10 +1142,11 @@ static void xpcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode,
11511142

11521143
if (interface == PHY_INTERFACE_MODE_USXGMII)
11531144
return xpcs_config_usxgmii(xpcs, speed);
1154-
if (interface == PHY_INTERFACE_MODE_SGMII)
1155-
return xpcs_link_up_sgmii(xpcs, neg_mode, speed, duplex);
1156-
if (interface == PHY_INTERFACE_MODE_1000BASEX)
1157-
return xpcs_link_up_1000basex(xpcs, neg_mode, speed, duplex);
1145+
1146+
if (interface == PHY_INTERFACE_MODE_SGMII ||
1147+
interface == PHY_INTERFACE_MODE_1000BASEX)
1148+
return xpcs_link_up_sgmii_1000basex(xpcs, neg_mode, interface,
1149+
speed, duplex);
11581150
}
11591151

11601152
static void xpcs_an_restart(struct phylink_pcs *pcs)

0 commit comments

Comments
 (0)