Skip to content

Commit 3eeca4e

Browse files
oleremPaolo Abeni
authored andcommitted
net: phy: do not force EEE support
With following patches: commit 9b01c88 ("net: phy: c22: migrate to genphy_c45_write_eee_adv()") commit 5827b16 ("net: phy: c45: migrate to genphy_c45_write_eee_adv()") we set the advertisement to potentially supported values. This behavior may introduce new regressions on systems where EEE was disabled by default (BIOS or boot loader configuration or by other ways.) At same time, with this patches, we would overwrite EEE advertisement configuration made over ethtool. To avoid this issues, we need to cache initial and ethtool advertisement configuration and store it for later use. Fixes: 9b01c88 ("net: phy: c22: migrate to genphy_c45_write_eee_adv()") Fixes: 5827b16 ("net: phy: c45: migrate to genphy_c45_write_eee_adv()") Fixes: 022c3f8 ("net: phy: add genphy_c45_ethtool_get/set_eee() support") Signed-off-by: Oleksij Rempel <[email protected]> Reviewed-by: Russell King (Oracle) <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent b6478b8 commit 3eeca4e

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

drivers/net/phy/phy-c45.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,7 @@ int genphy_c45_write_eee_adv(struct phy_device *phydev, unsigned long *adv)
721721
* @phydev: target phy_device struct
722722
* @adv: the linkmode advertisement status
723723
*/
724-
static int genphy_c45_read_eee_adv(struct phy_device *phydev,
725-
unsigned long *adv)
724+
int genphy_c45_read_eee_adv(struct phy_device *phydev, unsigned long *adv)
726725
{
727726
int val;
728727

@@ -864,7 +863,13 @@ EXPORT_SYMBOL_GPL(genphy_c45_read_eee_abilities);
864863
*/
865864
int genphy_c45_an_config_eee_aneg(struct phy_device *phydev)
866865
{
867-
return genphy_c45_write_eee_adv(phydev, phydev->supported_eee);
866+
if (!phydev->eee_enabled) {
867+
__ETHTOOL_DECLARE_LINK_MODE_MASK(adv) = {};
868+
869+
return genphy_c45_write_eee_adv(phydev, adv);
870+
}
871+
872+
return genphy_c45_write_eee_adv(phydev, phydev->advertising_eee);
868873
}
869874

870875
/**
@@ -1430,17 +1435,22 @@ EXPORT_SYMBOL(genphy_c45_ethtool_get_eee);
14301435
int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
14311436
struct ethtool_eee *data)
14321437
{
1433-
__ETHTOOL_DECLARE_LINK_MODE_MASK(adv) = {};
14341438
int ret;
14351439

14361440
if (data->eee_enabled) {
14371441
if (data->advertised)
1438-
adv[0] = data->advertised;
1442+
ethtool_convert_legacy_u32_to_link_mode(phydev->advertising_eee,
1443+
data->advertised);
14391444
else
1440-
linkmode_copy(adv, phydev->supported_eee);
1445+
linkmode_copy(phydev->advertising_eee,
1446+
phydev->supported_eee);
1447+
1448+
phydev->eee_enabled = true;
1449+
} else {
1450+
phydev->eee_enabled = false;
14411451
}
14421452

1443-
ret = genphy_c45_write_eee_adv(phydev, adv);
1453+
ret = genphy_c45_an_config_eee_aneg(phydev);
14441454
if (ret < 0)
14451455
return ret;
14461456
if (ret > 0)

drivers/net/phy/phy_device.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,6 +3141,25 @@ static int phy_probe(struct device *dev)
31413141
of_set_phy_supported(phydev);
31423142
phy_advertise_supported(phydev);
31433143

3144+
/* Get PHY default EEE advertising modes and handle them as potentially
3145+
* safe initial configuration.
3146+
*/
3147+
err = genphy_c45_read_eee_adv(phydev, phydev->advertising_eee);
3148+
if (err)
3149+
return err;
3150+
3151+
/* There is no "enabled" flag. If PHY is advertising, assume it is
3152+
* kind of enabled.
3153+
*/
3154+
phydev->eee_enabled = !linkmode_empty(phydev->advertising_eee);
3155+
3156+
/* Some PHYs may advertise, by default, not support EEE modes. So,
3157+
* we need to clean them.
3158+
*/
3159+
if (phydev->eee_enabled)
3160+
linkmode_and(phydev->advertising_eee, phydev->supported_eee,
3161+
phydev->advertising_eee);
3162+
31443163
/* Get the EEE modes we want to prohibit. We will ask
31453164
* the PHY stop advertising these mode later on
31463165
*/

include/linux/phy.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ struct macsec_ops;
575575
* @advertising: Currently advertised linkmodes
576576
* @adv_old: Saved advertised while power saving for WoL
577577
* @supported_eee: supported PHY EEE linkmodes
578+
* @advertising_eee: Currently advertised EEE linkmodes
579+
* @eee_enabled: Flag indicating whether the EEE feature is enabled
578580
* @lp_advertising: Current link partner advertised linkmodes
579581
* @host_interfaces: PHY interface modes supported by host
580582
* @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
@@ -681,6 +683,8 @@ struct phy_device {
681683
__ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old);
682684
/* used for eee validation */
683685
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported_eee);
686+
__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising_eee);
687+
bool eee_enabled;
684688

685689
/* Host supported PHY interface types. Should be ignored if empty. */
686690
DECLARE_PHY_INTERFACE_MASK(host_interfaces);
@@ -1766,6 +1770,7 @@ int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
17661770
struct ethtool_eee *data);
17671771
int genphy_c45_write_eee_adv(struct phy_device *phydev, unsigned long *adv);
17681772
int genphy_c45_an_config_eee_aneg(struct phy_device *phydev);
1773+
int genphy_c45_read_eee_adv(struct phy_device *phydev, unsigned long *adv);
17691774

17701775
/* Generic C45 PHY driver */
17711776
extern struct phy_driver genphy_c45_driver;

0 commit comments

Comments
 (0)