Message ID | 20241112072447.3238892-2-yong.liang.choong@linux.intel.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Fix ethtool --show-eee for stmmac | expand |
On 12.11.2024 08:24, Choong Yong Liang wrote: > The commit fe0d4fd9285e ("net: phy: Keep track of EEE configuration") > introduced eee_cfg, which is used to check the existing settings against > the requested changes. When the 'ethtool --show-eee' command is issued, > it reads the values from eee_cfg. However, the 'show-eee' command does > not show the correct result after system boot-up, link up, and link down. > In stmmac_ethtool_op_get_eee() you have the following: edata->tx_lpi_timer = priv->tx_lpi_timer; edata->tx_lpi_enabled = priv->tx_lpi_enabled; return phylink_ethtool_get_eee(priv->phylink, edata); You have to call phylink_ethtool_get_eee() first, otherwise the manually set values will be overridden. However setting tx_lpi_enabled shouldn't be needed if you respect phydev->enable_tx_lpi. > For system boot-up, the commit 49168d1980e2 > ("net: phy: Add phy_support_eee() indicating MAC support EEE") introduced > phy_support_eee to set eee_cfg as the default value. However, the values > set were not always correct, as after autonegotiation or speed changes, > the selected speed might not be supported by EEE. > > phy_update_eee() was introduced to update the correct values for eee_cfg > during link up and down, ensuring that 'ethtool --show-eee' shows > the correct status. > > Fixes: fe0d4fd9285e ("net: phy: Keep track of EEE configuration") > Cc: <stable@vger.kernel.org> > Signed-off-by: Choong Yong Liang <yong.liang.choong@linux.intel.com> > --- > drivers/net/phy/phy_device.c | 24 ++++++++++++++++++++++++ > include/linux/phy.h | 2 ++ > 2 files changed, 26 insertions(+) > > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c > index 499797646580..94dadf011ca6 100644 > --- a/drivers/net/phy/phy_device.c > +++ b/drivers/net/phy/phy_device.c > @@ -3016,6 +3016,30 @@ void phy_support_eee(struct phy_device *phydev) > } > EXPORT_SYMBOL(phy_support_eee); > > +/** > + * phy_update_eee - Update the Energy Efficient Ethernet (EEE) settings > + * @phydev: target phy_device struct > + * @tx_lpi_enabled: boolean indicating if Low Power Idle (LPI) for > + * transmission is enabled. > + * @eee_enabled: boolean indicating if Energy Efficient Ethernet (EEE) is > + * enabled. > + * @tx_lpi_timer: the Low Power Idle (LPI) timer value (in microseconds) for > + * transmission. > + * > + * Description: > + * This function updates the Energy Efficient Ethernet (EEE) settings for the > + * specified PHY device. It is typically called during link up and down events > + * to configure the EEE parameters according to the current link state. > + */ > +void phy_update_eee(struct phy_device *phydev, bool tx_lpi_enabled, > + bool eee_enabled, u32 tx_lpi_timer) > +{ > + phydev->eee_cfg.tx_lpi_enabled = tx_lpi_enabled; > + phydev->eee_cfg.eee_enabled = eee_enabled; > + phydev->eee_cfg.tx_lpi_timer = tx_lpi_timer; > +} > +EXPORT_SYMBOL(phy_update_eee); > + > /** > * phy_support_sym_pause - Enable support of symmetrical pause > * @phydev: target phy_device struct > diff --git a/include/linux/phy.h b/include/linux/phy.h > index a98bc91a0cde..6c300ba47a2d 100644 > --- a/include/linux/phy.h > +++ b/include/linux/phy.h > @@ -2004,6 +2004,8 @@ void phy_advertise_eee_all(struct phy_device *phydev); > void phy_support_sym_pause(struct phy_device *phydev); > void phy_support_asym_pause(struct phy_device *phydev); > void phy_support_eee(struct phy_device *phydev); > +void phy_update_eee(struct phy_device *phydev, bool tx_lpi_enabled, > + bool eee_enabled, u32 tx_lpi_timer); > void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx, > bool autoneg); > void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);
On Tue, Nov 12, 2024 at 12:03:15PM +0100, Heiner Kallweit wrote: > On 12.11.2024 08:24, Choong Yong Liang wrote: > > The commit fe0d4fd9285e ("net: phy: Keep track of EEE configuration") > > introduced eee_cfg, which is used to check the existing settings against > > the requested changes. When the 'ethtool --show-eee' command is issued, > > it reads the values from eee_cfg. However, the 'show-eee' command does > > not show the correct result after system boot-up, link up, and link down. > > > > In stmmac_ethtool_op_get_eee() you have the following: > > edata->tx_lpi_timer = priv->tx_lpi_timer; > edata->tx_lpi_enabled = priv->tx_lpi_enabled; > return phylink_ethtool_get_eee(priv->phylink, edata); > > You have to call phylink_ethtool_get_eee() first, otherwise the manually > set values will be overridden. However setting tx_lpi_enabled shouldn't > be needed if you respect phydev->enable_tx_lpi. I agree with Heiner here, this sounds like a bug somewhere, not something which needs new code in phylib. Lets understand why it gives the wrong results. Andrew
On 12/11/2024 9:04 pm, Andrew Lunn wrote: > On Tue, Nov 12, 2024 at 12:03:15PM +0100, Heiner Kallweit wrote: >> In stmmac_ethtool_op_get_eee() you have the following: >> >> edata->tx_lpi_timer = priv->tx_lpi_timer; >> edata->tx_lpi_enabled = priv->tx_lpi_enabled; >> return phylink_ethtool_get_eee(priv->phylink, edata); >> >> You have to call phylink_ethtool_get_eee() first, otherwise the manually >> set values will be overridden. However setting tx_lpi_enabled shouldn't >> be needed if you respect phydev->enable_tx_lpi. > > I agree with Heiner here, this sounds like a bug somewhere, not > something which needs new code in phylib. Lets understand why it gives > the wrong results. > > Andrew Hi Russell, Andrew, and Heiner, thanks a lot for your valuable feedback. The current implementation of the 'ethtool --show-eee' command heavily relies on the phy_ethtool_get_eee() in phy.c. The eeecfg values are set by the 'ethtool --set-eee' command and the phy_support_eee() during the initial state. The phy_ethtool_get_eee() calls eeecfg_to_eee(), which returns the eeecfg containing tx_lpi_timer, tx_lpi_enabled, and eee_enable for the 'ethtool --show-eee' command. The tx_lpi_timer and tx_lpi_enabled values stored in the MAC or PHY driver are not retrieved by the 'ethtool --show-eee' command. Currently, we are facing 3 issues: 1. When we boot up our system and do not issue the 'ethtool --set-eee' command, and then directly issue the 'ethtool --show-eee' command, it always shows that EEE is disabled due to the eeecfg values not being set. However, in the Maxliner GPY PHY, the driver EEE is enabled. If we try to disable EEE, nothing happens because the eeecfg matches the setting required to disable EEE in ethnl_set_eee(). The phy_support_eee() was introduced to set the initial values to enable eee_enabled and tx_lpi_enabled. This would allow 'ethtool --show-eee' to show that EEE is enabled during the initial state. However, the Marvell PHY is designed to have hardware disabled EEE during the initial state. Users are required to use Ethtool to enable the EEE. phy_support_eee() does not show the correct for Marvell PHY. 2. The 'ethtool --show-eee' command does not display the correct status, even if the link is down or the speed changes to one that does not support EEE. 3. The tx_lpi_timer in 'ethtool --show-eee' always shows 0 if we have not used 'ethtool --set-eee' to set the values, even though the driver sets different values. I appreciate Russell's point that eee_enabled is a user configuration bit, not a status bit. However, I am curious if tx_lpi_timer, tx_lpi_enabled, and other fields are also considered configuration bits. According to the ethtool man page: --show-eee Queries the specified network device for its support of Energy-Efficient Ethernet (according to the IEEE 802.3az specifications) It does not specify which fields are configuration bits and which are status bits.
On 13.11.2024 11:10, Choong Yong Liang wrote: > > > On 12/11/2024 9:04 pm, Andrew Lunn wrote: >> On Tue, Nov 12, 2024 at 12:03:15PM +0100, Heiner Kallweit wrote: >>> In stmmac_ethtool_op_get_eee() you have the following: >>> >>> edata->tx_lpi_timer = priv->tx_lpi_timer; >>> edata->tx_lpi_enabled = priv->tx_lpi_enabled; >>> return phylink_ethtool_get_eee(priv->phylink, edata); >>> >>> You have to call phylink_ethtool_get_eee() first, otherwise the manually >>> set values will be overridden. However setting tx_lpi_enabled shouldn't >>> be needed if you respect phydev->enable_tx_lpi. >> >> I agree with Heiner here, this sounds like a bug somewhere, not >> something which needs new code in phylib. Lets understand why it gives >> the wrong results. >> >> Andrew > Hi Russell, Andrew, and Heiner, thanks a lot for your valuable feedback. > > The current implementation of the 'ethtool --show-eee' command heavily relies on the phy_ethtool_get_eee() in phy.c. The eeecfg values are set by the 'ethtool --set-eee' command and the phy_support_eee() during the initial state. The phy_ethtool_get_eee() calls eeecfg_to_eee(), which returns the eeecfg containing tx_lpi_timer, tx_lpi_enabled, and eee_enable for the 'ethtool --show-eee' command. > "relies on" may be the wrong term here. There's an API definition, and phy_ethtool_get_eee() takes care of the PHY-related kernel part, provided that the MAC driver uses phylib. I say "PHY-related part", because tx_lpi_timer is something relevant for the MAC only. Therefore phylib stores the master config timer value only, not the actual value. The MAC driver should populate tx_lpi_timer in the get_eee() callback, in addition to what phy_ethtool_get_eee() populates. This may result in the master config value being overwritten with actual value in cases where the MAC doesn't support the master config value. One (maybe there are more) special case of tx_lpi_timer handling is Realtek chips, as they store the LPI timer in bytes. Means whenever the link speed changes, the actual timer value also changes implicitly. Few values exist twice: As a master config value, and as status. struct phy_device has the status values: @eee_enabled: Flag indicating whether the EEE feature is enabled @enable_tx_lpi: When True, MAC should transmit LPI to PHY And master config values are in struct eee_cfg: struct eee_config { u32 tx_lpi_timer; bool tx_lpi_enabled; bool eee_enabled; }; And yes, it may be a little misleading that eee_enabled exists twice, you have to be careful which one you're referring to. ethtool handles the master config values, only "active" is a status information. So the MAC driver should: - provide a link change handler in e.g. phy_connect_direct() - this handler should: - use phydev->enable_tx_lpi to set whether MAC transmits LPI or not - use phydev->eee_cfg.tx_lpi_timer to set the timer (if the config value is set) Important note: This describes how MAC drivers *should* behave. Some don't get it right. So part of your confusion may be caused by misbehaving MAC drivers. One example of a MAC driver bug is what I wrote earlier about stmmac_ethtool_op_get_eee(). And what I write here refers to plain phylib, I don't cover phylink as additional layer. > The tx_lpi_timer and tx_lpi_enabled values stored in the MAC or PHY driver are not retrieved by the 'ethtool --show-eee' command. > > Currently, we are facing 3 issues: > 1. When we boot up our system and do not issue the 'ethtool --set-eee' command, and then directly issue the 'ethtool --show-eee' command, it always shows that EEE is disabled due to the eeecfg values not being set. However, in the Maxliner GPY PHY, the driver EEE is enabled. If we try to disable EEE, nothing happens because the eeecfg matches the setting required to disable EEE in ethnl_set_eee(). The phy_support_eee() was introduced to set the initial values to enable eee_enabled and tx_lpi_enabled. This would allow 'ethtool --show-eee' to show that EEE is enabled during the initial state. However, the Marvell PHY is designed to have hardware disabled EEE during the initial state. Users are required to use Ethtool to enable the EEE. phy_support_eee() does not show the correct for Marvell PHY. > > 2. The 'ethtool --show-eee' command does not display the correct status, even if the link is down or the speed changes to one that does not support EEE. > > 3. The tx_lpi_timer in 'ethtool --show-eee' always shows 0 if we have not used 'ethtool --set-eee' to set the values, even though the driver sets different values. > > I appreciate Russell's point that eee_enabled is a user configuration bit, not a status bit. However, I am curious if tx_lpi_timer, tx_lpi_enabled, and other fields are also considered configuration bits. > > According to the ethtool man page: > --show-eee > Queries the specified network device for its support of Energy-Efficient Ethernet (according to the IEEE 802.3az specifications) > > It does not specify which fields are configuration bits and which are status bits.
On Wed, Nov 13, 2024 at 06:10:55PM +0800, Choong Yong Liang wrote: > > > On 12/11/2024 9:04 pm, Andrew Lunn wrote: > > On Tue, Nov 12, 2024 at 12:03:15PM +0100, Heiner Kallweit wrote: > > > In stmmac_ethtool_op_get_eee() you have the following: > > > > > > edata->tx_lpi_timer = priv->tx_lpi_timer; > > > edata->tx_lpi_enabled = priv->tx_lpi_enabled; > > > return phylink_ethtool_get_eee(priv->phylink, edata); > > > > > > You have to call phylink_ethtool_get_eee() first, otherwise the manually > > > set values will be overridden. However setting tx_lpi_enabled shouldn't > > > be needed if you respect phydev->enable_tx_lpi. > > > > I agree with Heiner here, this sounds like a bug somewhere, not > > something which needs new code in phylib. Lets understand why it gives > > the wrong results. > > > > Andrew > Hi Russell, Andrew, and Heiner, thanks a lot for your valuable feedback. > > The current implementation of the 'ethtool --show-eee' command heavily > relies on the phy_ethtool_get_eee() in phy.c. The eeecfg values are set by > the 'ethtool --set-eee' command and the phy_support_eee() during the initial > state. The phy_ethtool_get_eee() calls eeecfg_to_eee(), which returns the > eeecfg containing tx_lpi_timer, tx_lpi_enabled, and eee_enable for the > 'ethtool --show-eee' command. > > The tx_lpi_timer and tx_lpi_enabled values stored in the MAC or PHY driver > are not retrieved by the 'ethtool --show-eee' command. tx_lpi_timer is a MAC property, but phylib does track it across --set-eee calls and will fill it in for get-eee. What however is missing it setting its default value. There is currently no API the MAC driver can call to let phylib know what default value it is using. Either such an API could be added, e.g. as part of phy_support_eee(), or we could hard code a value, probably again in phy_support_eee(). tx_lpi_enabled is filled in by phy_ethtool_get_eee(), and its default value is set by phy_support_eee(). So i don't see what is wrong here. > Currently, we are facing 3 issues: > 1. When we boot up our system and do not issue the 'ethtool --set-eee' > command, and then directly issue the 'ethtool --show-eee' command, it always > shows that EEE is disabled due to the eeecfg values not being set. However, > in the Maxliner GPY PHY, the driver EEE is enabled. If we try to disable > EEE, nothing happens because the eeecfg matches the setting required to > disable EEE in ethnl_set_eee(). The phy_support_eee() was introduced to set > the initial values to enable eee_enabled and tx_lpi_enabled. This would > allow 'ethtool --show-eee' to show that EEE is enabled during the initial > state. However, the Marvell PHY is designed to have hardware disabled EEE > during the initial state. Users are required to use Ethtool to enable the > EEE. phy_support_eee() does not show the correct for Marvell PHY. We discussed what to set the initial state to when we reworked the EEE support. It is a hard problem, because changing anything could cause regressions. Some users don't want EEE enabled, because it can add latency and jitter, e.g. to PTP packets. Some users want it enabled for the power savings. We decided to leave the PHY untouched, and will read out its configuration. If this is going wrong, that is a bug which should be found and fixed. We want the core to be fixed, not workaround added to MAC drivers. Please think about this when proposing future patches. Andrew
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 499797646580..94dadf011ca6 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3016,6 +3016,30 @@ void phy_support_eee(struct phy_device *phydev) } EXPORT_SYMBOL(phy_support_eee); +/** + * phy_update_eee - Update the Energy Efficient Ethernet (EEE) settings + * @phydev: target phy_device struct + * @tx_lpi_enabled: boolean indicating if Low Power Idle (LPI) for + * transmission is enabled. + * @eee_enabled: boolean indicating if Energy Efficient Ethernet (EEE) is + * enabled. + * @tx_lpi_timer: the Low Power Idle (LPI) timer value (in microseconds) for + * transmission. + * + * Description: + * This function updates the Energy Efficient Ethernet (EEE) settings for the + * specified PHY device. It is typically called during link up and down events + * to configure the EEE parameters according to the current link state. + */ +void phy_update_eee(struct phy_device *phydev, bool tx_lpi_enabled, + bool eee_enabled, u32 tx_lpi_timer) +{ + phydev->eee_cfg.tx_lpi_enabled = tx_lpi_enabled; + phydev->eee_cfg.eee_enabled = eee_enabled; + phydev->eee_cfg.tx_lpi_timer = tx_lpi_timer; +} +EXPORT_SYMBOL(phy_update_eee); + /** * phy_support_sym_pause - Enable support of symmetrical pause * @phydev: target phy_device struct diff --git a/include/linux/phy.h b/include/linux/phy.h index a98bc91a0cde..6c300ba47a2d 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2004,6 +2004,8 @@ void phy_advertise_eee_all(struct phy_device *phydev); void phy_support_sym_pause(struct phy_device *phydev); void phy_support_asym_pause(struct phy_device *phydev); void phy_support_eee(struct phy_device *phydev); +void phy_update_eee(struct phy_device *phydev, bool tx_lpi_enabled, + bool eee_enabled, u32 tx_lpi_timer); void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx, bool autoneg); void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx);
The commit fe0d4fd9285e ("net: phy: Keep track of EEE configuration") introduced eee_cfg, which is used to check the existing settings against the requested changes. When the 'ethtool --show-eee' command is issued, it reads the values from eee_cfg. However, the 'show-eee' command does not show the correct result after system boot-up, link up, and link down. For system boot-up, the commit 49168d1980e2 ("net: phy: Add phy_support_eee() indicating MAC support EEE") introduced phy_support_eee to set eee_cfg as the default value. However, the values set were not always correct, as after autonegotiation or speed changes, the selected speed might not be supported by EEE. phy_update_eee() was introduced to update the correct values for eee_cfg during link up and down, ensuring that 'ethtool --show-eee' shows the correct status. Fixes: fe0d4fd9285e ("net: phy: Keep track of EEE configuration") Cc: <stable@vger.kernel.org> Signed-off-by: Choong Yong Liang <yong.liang.choong@linux.intel.com> --- drivers/net/phy/phy_device.c | 24 ++++++++++++++++++++++++ include/linux/phy.h | 2 ++ 2 files changed, 26 insertions(+)