net: bcmgenet: fix broken EEE by converting to phylib-managed state
Subsystems (3)
Nicolai Buchwitz
maintainerPATCH v2 1/1 net: bcmgenet: fix broken EEE by converting to phylib-managed state
The bcmgenet EEE implementation is broken in several ways. phy_support_eee() is never called, so the PHY never advertises EEE and phylib never sets phydev->enable_tx_lpi. bcmgenet_mac_config() checks priv->eee.eee_enabled to decide whether to enable the MAC LPI logic, but that field is never initialised to true, so the MAC never enters Low Power Idle even when EEE is negotiated - wasting the power savings EEE is designed to provide. The only way to get EEE working at all is a manual 'ethtool --set-eee eth0 eee on' after every link-up, and even then bcmgenet_get_eee() immediately clobbers the reported state because phy_ethtool_get_eee() overwrites eee_enabled and tx_lpi_enabled with the uninitialised PHY eee_cfg values. Finally, bcmgenet_mac_config() is only called on link-up, so EEE is never disabled in hardware on link-down.
Fix all of this by removing the MAC-side EEE state tracking (priv->eee) and aligning with the pattern used by other non-phylink MAC drivers such as FEC.
Call phy_support_eee() in bcmgenet_mii_probe() so the PHY advertises EEE link modes and phylib tracks negotiation state. Move the EEE hardware control to bcmgenet_mii_setup(), which is called on every link event, and drive it directly from phydev->enable_tx_lpi - the flag phylib sets when EEE is negotiated and the user has not disabled it. This enables EEE automatically once the link partner agrees and disables it cleanly on link-down.
Make bcmgenet_get_eee() and bcmgenet_set_eee() pure passthroughs to phy_ethtool_get_eee() and phy_ethtool_set_eee(), with the MAC hardware register read/written for tx_lpi_timer. Drop struct ethtool_keee eee from struct bcmgenet_priv.
---
This patch supersedes two earlier submissions:
- [1] https://lore.kernel.org/netdev/[email protected]/
- [2] https://lore.kernel.org/netdev/[email protected]/
.../net/ethernet/broadcom/genet/bcmgenet.c | 31 +++++++------------ .../net/ethernet/broadcom/genet/bcmgenet.h | 5 +-- drivers/net/ethernet/broadcom/genet/bcmmii.c | 10 +++--- 3 files changed, 18 insertions(+), 28 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +12 -19
@@ -1342,8 +1342,7 @@ static void bcmgenet_get_ethtool_stats(struct net_device *dev, } } -void bcmgenet_eee_enable_set (struct net_device *dev,bool enable, -bool tx_lpi_enabled) +void bcmgenet_eee_enable_set (struct net_device *dev,bool enable) {struct bcmgenet_priv *priv =netdev_priv (dev);u32 off = priv->hw_params->tbuf_offset +TBUF_ENERGY_CTRL ;
@@ -1363,7 +1362,7 @@ void bcmgenet_eee_enable_set(struct net_device *dev, bool enable,/* Enable EEE and switch to a 27Mhz clock automatically */ reg =bcmgenet_readl (priv->base + off); -if (tx_lpi_enabled) +if (enable) reg |=TBUF_EEE_EN |TBUF_PM_EN ;else reg &= ~(TBUF_EEE_EN |TBUF_PM_EN );
@@ -1382,14 +1381,12 @@ void bcmgenet_eee_enable_set(struct net_device *dev, bool enable, priv->clk_eee_enabled = false; } - priv->eee.eee_enabled = enable; - priv->eee.tx_lpi_enabled = tx_lpi_enabled; }static int bcmgenet_get_eee (struct net_device *dev,struct ethtool_keee *e) {struct bcmgenet_priv *priv =netdev_priv (dev); -struct ethtool_keee *p = &priv->eee; +int ret;if (GENET_IS_V1 (priv))return -EOPNOTSUPP ;
@@ -1397,17 +1394,21 @@ static int bcmgenet_get_eee(struct net_device *dev, struct ethtool_keee *e)if (!dev->phydev)return -ENODEV ; - e->tx_lpi_enabled = p->tx_lpi_enabled; + ret =phy_ethtool_get_eee (dev->phydev, e); +if (ret) +return ret; + +/* tx_lpi_timer is maintained by the MAC hardware register; the +* PHY-level eee_cfg timer is not set for GENET. +*/ e->tx_lpi_timer =bcmgenet_umac_readl (priv,UMAC_EEE_LPI_TIMER ); -return phy_ethtool_get_eee (dev->phydev, e); +return 0 ; }static int bcmgenet_set_eee (struct net_device *dev,struct ethtool_keee *e) {struct bcmgenet_priv *priv =netdev_priv (dev); -struct ethtool_keee *p = &priv->eee; -bool active;if (GENET_IS_V1 (priv))return -EOPNOTSUPP ;
@@ -1415,15 +1416,7 @@ static int bcmgenet_set_eee(struct net_device *dev, struct ethtool_keee *e)if (!dev->phydev)return -ENODEV ; - p->eee_enabled = e->eee_enabled; - -if (!p->eee_enabled) { -bcmgenet_eee_enable_set (dev, false, false); - }else { - active =phy_init_eee (dev->phydev, false) >=0 ; -bcmgenet_umac_writel (priv, e->tx_lpi_timer,UMAC_EEE_LPI_TIMER ); -bcmgenet_eee_enable_set (dev, active, e->tx_lpi_enabled); - } +bcmgenet_umac_writel (priv, e->tx_lpi_timer,UMAC_EEE_LPI_TIMER );return phy_ethtool_set_eee (dev->phydev, e); }
drivers/net/ethernet/broadcom/genet/bcmgenet.h +1 -4
@@ -665,8 +665,6 @@ struct bcmgenet_priv {u8 sopass[SOPASS_MAX ];struct bcmgenet_mib_counters mib; - -struct ethtool_keee eee; };static inline bool bcmgenet_has_40bits (struct bcmgenet_priv *priv)
@@ -749,7 +747,6 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,int bcmgenet_wol_power_up_cfg (struct bcmgenet_priv *priv,enum bcmgenet_power_mode mode); -void bcmgenet_eee_enable_set (struct net_device *dev,bool enable, -bool tx_lpi_enabled); +void bcmgenet_eee_enable_set (struct net_device *dev,bool enable);#endif /* __BCMGENET_H__ */
drivers/net/ethernet/broadcom/genet/bcmmii.c +5 -5
@@ -29,7 +29,6 @@ static void bcmgenet_mac_config(struct net_device *dev)struct bcmgenet_priv *priv =netdev_priv (dev);struct phy_device *phydev = dev->phydev;u32 reg, cmd_bits =0 ; -bool active;/* speed */ if (phydev->speed ==SPEED_1000 )
@@ -90,10 +89,6 @@ static void bcmgenet_mac_config(struct net_device *dev)bcmgenet_umac_writel (priv, reg,UMAC_CMD );spin_unlock_bh (&priv->reg_lock); - active =phy_init_eee (phydev,0 ) >=0 ; -bcmgenet_eee_enable_set (dev, - priv->eee.eee_enabled && active, - priv->eee.tx_lpi_enabled); }/* setup netdev link state when PHY link status change and
@@ -113,6 +108,8 @@ void bcmgenet_mii_setup(struct net_device *dev)bcmgenet_ext_writel (priv, reg,EXT_RGMII_OOB_CTRL ); } +bcmgenet_eee_enable_set (dev, phydev->enable_tx_lpi); +phy_print_status (phydev); }
@@ -412,6 +409,9 @@ int bcmgenet_mii_probe(struct net_device *dev)/* Indicate that the MAC is responsible for PHY PM */ dev->phydev->mac_managed_pm = true; +if (!GENET_IS_V1 (priv)) +phy_support_eee (dev->phydev); +return 0 ; }
Signature · 1 line
2.51.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 14 lines · On Tue, 10 Mar 2026 06:49:35 +0100 you wrote:
The bcmgenet EEE implementation is broken in several ways.
phy_support_eee()is never called, so the PHY never advertises EEE and phylib never setsphydev->enable_tx_lpi.bcmgenet_mac_config()checkspriv->eee.eee_enabledto decide whether to enable the MAC LPI logic, but that field is never initialised to true, so the MAC never enters Low Power Idle even when EEE is negotiated - wasting the power savings EEE is designed to provide. The only way to get EEE working at all is a manual 'ethtool --set-eee eth0 eee on' after every link-up, and even thenbcmgenet_get_eee()immediately clobbers the reported state becausephy_ethtool_get_eee()overwriteseee_enabledandtx_lpi_enabledwith the uninitialised PHYeee_cfgvalues. Finally,bcmgenet_mac_config()is only called on link-up, so EEE is never disabled in hardware on link-down.
Quoted 1 line
[...]
Here is the summary with links:
- [net,v2] net: bcmgenet: fix broken EEE by converting to phylib-managed state
https://git.kernel.org/netdev/net/c/908c344d5cfa
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html