Skip to content

Commit d853d14

Browse files
jbrun3tdavem330
authored andcommitted
net: phy: add an option to disable EEE advertisement
This patch adds an option to disable EEE advertisement in the generic PHY by providing a mask of prohibited modes corresponding to the value found in the MDIO_AN_EEE_ADV register. On some platforms, PHY Low power idle seems to be causing issues, even breaking the link some cases. The patch provides a convenient way for these platforms to disable EEE advertisement and work around the issue. Signed-off-by: Jerome Brunet <jbrunet@baylibre.com> Tested-by: Yegor Yefremov <yegorslists@googlemail.com> Tested-by: Andreas Färber <afaerber@suse.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 436feaf commit d853d14

3 files changed

Lines changed: 77 additions & 9 deletions

File tree

‎drivers/net/phy/phy.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,9 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data)
13961396
{
13971397
int val = ethtool_adv_to_mmd_eee_adv_t(data->advertised);
13981398

1399+
/* Mask prohibited EEE modes */
1400+
val &= ~phydev->eee_broken_modes;
1401+
13991402
phy_write_mmd_indirect(phydev, MDIO_AN_EEE_ADV, MDIO_MMD_AN, val);
14001403

14011404
return 0;

‎drivers/net/phy/phy_device.c‎

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,43 @@ static int genphy_config_advert(struct phy_device *phydev)
11201120
return changed;
11211121
}
11221122

1123+
/**
1124+
* genphy_config_eee_advert - disable unwanted eee mode advertisement
1125+
* @phydev: target phy_device struct
1126+
*
1127+
* Description: Writes MDIO_AN_EEE_ADV after disabling unsupported energy
1128+
* efficent ethernet modes. Returns 0 if the PHY's advertisement hasn't
1129+
* changed, and 1 if it has changed.
1130+
*/
1131+
static int genphy_config_eee_advert(struct phy_device *phydev)
1132+
{
1133+
u32 broken = phydev->eee_broken_modes;
1134+
u32 old_adv, adv;
1135+
1136+
/* Nothing to disable */
1137+
if (!broken)
1138+
return 0;
1139+
1140+
/* If the following call fails, we assume that EEE is not
1141+
* supported by the phy. If we read 0, EEE is not advertised
1142+
* In both case, we don't need to continue
1143+
*/
1144+
adv = phy_read_mmd_indirect(phydev, MDIO_AN_EEE_ADV, MDIO_MMD_AN);
1145+
if (adv <= 0)
1146+
return 0;
1147+
1148+
old_adv = adv;
1149+
adv &= ~broken;
1150+
1151+
/* Advertising remains unchanged with the broken mask */
1152+
if (old_adv == adv)
1153+
return 0;
1154+
1155+
phy_write_mmd_indirect(phydev, MDIO_AN_EEE_ADV, MDIO_MMD_AN, adv);
1156+
1157+
return 1;
1158+
}
1159+
11231160
/**
11241161
* genphy_setup_forced - configures/forces speed/duplex from @phydev
11251162
* @phydev: target phy_device struct
@@ -1178,15 +1215,20 @@ EXPORT_SYMBOL(genphy_restart_aneg);
11781215
*/
11791216
int genphy_config_aneg(struct phy_device *phydev)
11801217
{
1181-
int result;
1218+
int err, changed;
1219+
1220+
changed = genphy_config_eee_advert(phydev);
11821221

11831222
if (AUTONEG_ENABLE != phydev->autoneg)
11841223
return genphy_setup_forced(phydev);
11851224

1186-
result = genphy_config_advert(phydev);
1187-
if (result < 0) /* error */
1188-
return result;
1189-
if (result == 0) {
1225+
err = genphy_config_advert(phydev);
1226+
if (err < 0) /* error */
1227+
return err;
1228+
1229+
changed |= err;
1230+
1231+
if (changed == 0) {
11901232
/* Advertisement hasn't changed, but maybe aneg was never on to
11911233
* begin with? Or maybe phy was isolated?
11921234
*/
@@ -1196,16 +1238,16 @@ int genphy_config_aneg(struct phy_device *phydev)
11961238
return ctl;
11971239

11981240
if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
1199-
result = 1; /* do restart aneg */
1241+
changed = 1; /* do restart aneg */
12001242
}
12011243

12021244
/* Only restart aneg if we are advertising something different
12031245
* than we were before.
12041246
*/
1205-
if (result > 0)
1206-
result = genphy_restart_aneg(phydev);
1247+
if (changed > 0)
1248+
return genphy_restart_aneg(phydev);
12071249

1208-
return result;
1250+
return 0;
12091251
}
12101252
EXPORT_SYMBOL(genphy_config_aneg);
12111253

@@ -1563,6 +1605,21 @@ static void of_set_phy_supported(struct phy_device *phydev)
15631605
__set_phy_supported(phydev, max_speed);
15641606
}
15651607

1608+
static void of_set_phy_eee_broken(struct phy_device *phydev)
1609+
{
1610+
struct device_node *node = phydev->mdio.dev.of_node;
1611+
u32 broken;
1612+
1613+
if (!IS_ENABLED(CONFIG_OF_MDIO))
1614+
return;
1615+
1616+
if (!node)
1617+
return;
1618+
1619+
if (!of_property_read_u32(node, "eee-broken-modes", &broken))
1620+
phydev->eee_broken_modes = broken;
1621+
}
1622+
15661623
/**
15671624
* phy_probe - probe and init a PHY device
15681625
* @dev: device to probe and init
@@ -1600,6 +1657,11 @@ static int phy_probe(struct device *dev)
16001657
of_set_phy_supported(phydev);
16011658
phydev->advertising = phydev->supported;
16021659

1660+
/* Get the EEE modes we want to prohibit. We will ask
1661+
* the PHY stop advertising these mode later on
1662+
*/
1663+
of_set_phy_eee_broken(phydev);
1664+
16031665
/* Set the state to READY by default */
16041666
phydev->state = PHY_READY;
16051667

‎include/linux/phy.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ struct phy_device {
417417
u32 advertising;
418418
u32 lp_advertising;
419419

420+
/* Energy efficient ethernet modes which should be prohibited */
421+
u32 eee_broken_modes;
422+
420423
int autoneg;
421424

422425
int link_timeout;

0 commit comments

Comments
 (0)