Skip to content

Commit 3e43b90

Browse files
lunnkuba-moo
authored andcommitted
net: phy: Immediately call adjust_link if only tx_lpi_enabled changes
The MAC driver changes its EEE hardware configuration in its adjust_link callback. This is called when auto-neg completes. Disabling EEE via eee_enabled false will trigger an autoneg, and as a result the adjust_link callback will be called with phydev->enable_tx_lpi set to false. Similarly, eee_enabled set to true and with a change of advertised link modes will result in a new autoneg, and a call the adjust_link call. If set_eee is called with only a change to tx_lpi_enabled which does not trigger an auto-neg, it is necessary to call the adjust_link callback so that the MAC is reconfigured to take this change into account. When setting phydev->enable_tx_lpi, take both eee_enabled and tx_lpi_enabled into account, so the MAC drivers just needs to act on phydev->enable_tx_lpi and not the whole EEE configuration. The same check should be done for tx_lpi_timer too. Signed-off-by: Andrew Lunn <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: Oleksij Rempel <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent fe0d4fd commit 3e43b90

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

drivers/net/phy/phy-c45.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,8 @@ EXPORT_SYMBOL(genphy_c45_ethtool_get_eee);
15501550
* advertised, but the previously advertised link modes are
15511551
* retained. This allows EEE to be enabled/disabled in a
15521552
* non-destructive way.
1553+
* Returns either error code, 0 if there was no change, or positive
1554+
* value if there was a change which triggered auto-neg.
15531555
*/
15541556
int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
15551557
struct ethtool_keee *data)
@@ -1576,8 +1578,16 @@ int genphy_c45_ethtool_set_eee(struct phy_device *phydev,
15761578
phydev->eee_enabled = data->eee_enabled;
15771579

15781580
ret = genphy_c45_an_config_eee_aneg(phydev);
1579-
if (ret > 0)
1580-
return phy_restart_aneg(phydev);
1581+
if (ret > 0) {
1582+
ret = phy_restart_aneg(phydev);
1583+
if (ret < 0)
1584+
return ret;
1585+
1586+
/* explicitly return 1, otherwise (ret > 0) value will be
1587+
* overwritten by phy_restart_aneg().
1588+
*/
1589+
return 1;
1590+
}
15811591

15821592
return ret;
15831593
}

drivers/net/phy/phy.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,8 @@ static int phy_check_link_status(struct phy_device *phydev)
988988
if (err < 0)
989989
phydev->enable_tx_lpi = false;
990990
else
991-
phydev->enable_tx_lpi = !!err;
991+
phydev->enable_tx_lpi = (err & phydev->eee_cfg.tx_lpi_enabled);
992+
992993
phy_link_up(phydev);
993994
} else if (!phydev->link && phydev->state != PHY_NOLINK) {
994995
phydev->state = PHY_NOLINK;
@@ -1659,6 +1660,36 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_keee *data)
16591660
}
16601661
EXPORT_SYMBOL(phy_ethtool_get_eee);
16611662

1663+
/**
1664+
* phy_ethtool_set_eee_noneg - Adjusts MAC LPI configuration without PHY
1665+
* renegotiation
1666+
* @phydev: pointer to the target PHY device structure
1667+
* @data: pointer to the ethtool_keee structure containing the new EEE settings
1668+
*
1669+
* This function updates the Energy Efficient Ethernet (EEE) configuration
1670+
* for cases where only the MAC's Low Power Idle (LPI) configuration changes,
1671+
* without triggering PHY renegotiation. It ensures that the MAC is properly
1672+
* informed of the new LPI settings by cycling the link down and up, which
1673+
* is necessary for the MAC to adopt the new configuration. This adjustment
1674+
* is done only if there is a change in the tx_lpi_enabled or tx_lpi_timer
1675+
* configuration.
1676+
*/
1677+
static void phy_ethtool_set_eee_noneg(struct phy_device *phydev,
1678+
struct ethtool_keee *data)
1679+
{
1680+
if (phydev->eee_cfg.tx_lpi_enabled != data->tx_lpi_enabled ||
1681+
phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) {
1682+
eee_to_eeecfg(&phydev->eee_cfg, data);
1683+
phydev->enable_tx_lpi = eeecfg_mac_can_tx_lpi(&phydev->eee_cfg);
1684+
if (phydev->link) {
1685+
phydev->link = false;
1686+
phy_link_down(phydev);
1687+
phydev->link = true;
1688+
phy_link_up(phydev);
1689+
}
1690+
}
1691+
}
1692+
16621693
/**
16631694
* phy_ethtool_set_eee - set EEE supported and status
16641695
* @phydev: target phy_device struct
@@ -1675,11 +1706,14 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_keee *data)
16751706

16761707
mutex_lock(&phydev->lock);
16771708
ret = genphy_c45_ethtool_set_eee(phydev, data);
1678-
if (!ret)
1709+
if (ret >= 0) {
1710+
if (ret == 0)
1711+
phy_ethtool_set_eee_noneg(phydev, data);
16791712
eee_to_eeecfg(&phydev->eee_cfg, data);
1713+
}
16801714
mutex_unlock(&phydev->lock);
16811715

1682-
return ret;
1716+
return ret < 0 ? ret : 0;
16831717
}
16841718
EXPORT_SYMBOL(phy_ethtool_set_eee);
16851719

0 commit comments

Comments
 (0)