[PATCH net-next v2 1/1] net: sxgbe: rework EEE handling based on PHY negotiation
From: Oleksij Rempel <o.rempel@pengutronix.de>
Date: 2025-02-07 10:56:25
From: Andrew Lunn <andrew@lunn.ch> Rework EEE handling to depend on PHY negotiation results. Enable EEE only after a valid link is established and allow proper LPI mode activation. Previously, sxgbe_eee_init() was called in sxgbe_open() to invoke phy_init_eee() most probably before the PHY could complete auto-negotiation. Non-automotive PHYs typically take ~1 sec to establish a link, so EEE was rarely enabled. Now, EEE activation is deferred until after PHY negotiation. The driver delegates EEE control to phylib via ethtool set/get calls. Timer values are taken from phydev->eee_cfg.tx_lpi_timer, and sxgbe_eee_adjust() configures EEE based on phydev->enable_tx_lpi and the PHY link status. This activation of LPI may reveal issues that were hidden when LPI was rarely active. WARNING: This patch is only compile tested. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> --- changes v2: - major rework with many changes - use phydev->eee_cfg.tx_lpi_timer where possible - drop sxgbe_eee_init() and rework sxgbe_eee_adjust() --- .../net/ethernet/samsung/sxgbe/sxgbe_common.h | 2 - .../ethernet/samsung/sxgbe/sxgbe_ethtool.c | 22 +----- .../net/ethernet/samsung/sxgbe/sxgbe_main.c | 69 +++++++------------ 3 files changed, 26 insertions(+), 67 deletions(-)
diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h b/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h
index 1458939c3bf5..a8eed188d110 100644
--- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h
+++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h@@ -526,6 +526,4 @@ int sxgbe_restore(struct net_device *ndev); const struct sxgbe_mtl_ops *sxgbe_get_mtl_ops(void); -void sxgbe_disable_eee_mode(struct sxgbe_priv_data * const priv); -bool sxgbe_eee_init(struct sxgbe_priv_data * const priv); #endif /* __SXGBE_COMMON_H__ */
diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c
index 4a439b34114d..a13360962e47 100644
--- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c
+++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c@@ -140,8 +140,6 @@ static int sxgbe_get_eee(struct net_device *dev, if (!priv->hw_cap.eee) return -EOPNOTSUPP; - edata->tx_lpi_timer = priv->tx_lpi_timer; - return phy_ethtool_get_eee(dev->phydev, edata); }
@@ -150,22 +148,8 @@ static int sxgbe_set_eee(struct net_device *dev, { struct sxgbe_priv_data *priv = netdev_priv(dev); - priv->eee_enabled = edata->eee_enabled; - - if (!priv->eee_enabled) { - sxgbe_disable_eee_mode(priv); - } else { - /* We are asking for enabling the EEE but it is safe - * to verify all by invoking the eee_init function. - * In case of failure it will return an error. - */ - priv->eee_enabled = sxgbe_eee_init(priv); - if (!priv->eee_enabled) - return -EOPNOTSUPP; - - /* Do not change tx_lpi_timer in case of failure */ - priv->tx_lpi_timer = edata->tx_lpi_timer; - } + if (!priv->hw_cap.eee) + return -EOPNOTSUPP; return phy_ethtool_set_eee(dev->phydev, edata); }
@@ -228,7 +212,7 @@ static void sxgbe_get_ethtool_stats(struct net_device *dev, int i; char *p; - if (priv->eee_enabled) { + if (dev->phydev->eee_active) { int val = phy_get_eee_err(dev->phydev); if (val)
diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
index 12c8396b6942..8a385c92a6d1 100644
--- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
+++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c@@ -87,7 +87,7 @@ static void sxgbe_enable_eee_mode(const struct sxgbe_priv_data *priv) priv->hw->mac->set_eee_mode(priv->ioaddr); } -void sxgbe_disable_eee_mode(struct sxgbe_priv_data * const priv) +static void sxgbe_disable_eee_mode(struct sxgbe_priv_data * const priv) { /* Exit and disable EEE in case of we are in LPI state. */ priv->hw->mac->reset_eee_mode(priv->ioaddr);
@@ -110,52 +110,25 @@ static void sxgbe_eee_ctrl_timer(struct timer_list *t) mod_timer(&priv->eee_ctrl_timer, SXGBE_LPI_TIMER(eee_timer)); } -/** - * sxgbe_eee_init - * @priv: private device pointer - * Description: - * If the EEE support has been enabled while configuring the driver, - * if the GMAC actually supports the EEE (from the HW cap reg) and the - * phy can also manage EEE, so enable the LPI state and start the timer - * to verify if the tx path can enter in LPI state. - */ -bool sxgbe_eee_init(struct sxgbe_priv_data * const priv) +static void sxgbe_eee_adjust(struct sxgbe_priv_data *priv) { - struct net_device *ndev = priv->dev; - bool ret = false; + struct phy_device *phydev = priv->dev->phydev; - /* MAC core supports the EEE feature. */ - if (priv->hw_cap.eee) { - /* Check if the PHY supports EEE */ - if (phy_init_eee(ndev->phydev, true)) - return false; + if (!priv->hw_cap.eee) + return; - timer_setup(&priv->eee_ctrl_timer, sxgbe_eee_ctrl_timer, 0); - priv->eee_ctrl_timer.expires = SXGBE_LPI_TIMER(eee_timer); + if (phydev->enable_tx_lpi) { add_timer(&priv->eee_ctrl_timer); - priv->hw->mac->set_eee_timer(priv->ioaddr, SXGBE_DEFAULT_LPI_TIMER, - priv->tx_lpi_timer); - - pr_info("Energy-Efficient Ethernet initialized\n"); - - ret = true; + phydev->eee_cfg.tx_lpi_timer); + priv->eee_enabled = true; + } else { + sxgbe_disable_eee_mode(priv); + priv->eee_enabled = false; } - return ret; -} - -static void sxgbe_eee_adjust(const struct sxgbe_priv_data *priv) -{ - struct net_device *ndev = priv->dev; - - /* When the EEE has been already initialised we have to - * modify the PLS bit in the LPI ctrl & status reg according - * to the PHY link status. For this reason. - */ - if (priv->eee_enabled) - priv->hw->mac->set_eee_pls(priv->ioaddr, ndev->phydev->link); + priv->hw->mac->set_eee_pls(priv->ioaddr, phydev->link); } /**
@@ -301,6 +274,16 @@ static int sxgbe_init_phy(struct net_device *ndev) return -ENODEV; } + if (priv->hw_cap.eee) { + phy_support_eee(phydev); + phy_eee_rx_clock_stop(priv->dev->phydev, true); + phydev->eee_cfg.tx_lpi_timer = SXGBE_DEFAULT_LPI_TIMER; + + /* configure timer which will be used for LPI handling */ + timer_setup(&priv->eee_ctrl_timer, sxgbe_eee_ctrl_timer, 0); + priv->eee_ctrl_timer.expires = SXGBE_LPI_TIMER(eee_timer); + } + netdev_dbg(ndev, "%s: attached to PHY (UID 0x%x) Link = %d\n", __func__, phydev->phy_id, phydev->link);
@@ -802,7 +785,7 @@ static void sxgbe_tx_all_clean(struct sxgbe_priv_data * const priv) sxgbe_tx_queue_clean(tqueue); } - if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) { + if (priv->eee_enabled && !priv->tx_path_in_lpi_mode) { sxgbe_enable_eee_mode(priv); mod_timer(&priv->eee_ctrl_timer, SXGBE_LPI_TIMER(eee_timer)); }
@@ -1179,9 +1162,6 @@ static int sxgbe_open(struct net_device *dev) priv->hw->dma->rx_watchdog(priv->ioaddr, SXGBE_MAX_DMA_RIWT); } - priv->tx_lpi_timer = SXGBE_DEFAULT_LPI_TIMER; - priv->eee_enabled = sxgbe_eee_init(priv); - napi_enable(&priv->napi); netif_start_queue(dev);
@@ -1207,9 +1187,6 @@ static int sxgbe_release(struct net_device *dev) { struct sxgbe_priv_data *priv = netdev_priv(dev); - if (priv->eee_enabled) - del_timer_sync(&priv->eee_ctrl_timer); - /* Stop and disconnect the PHY */ if (dev->phydev) { phy_stop(dev->phydev);
--
2.39.5