RE: [PATCH net-next v5 8/8] net: fec: Fixup EEE

Wei Fang
2024-02-23T06:03:53Z

> -----Original Message-----
> From: Oleksij Rempel <o.rempel@pengutronix.de>
> Sent: 2024年2月21日 14:21
> To: Wei Fang <wei.fang@nxp.com>; David S. Miller <davem@davemloft.net>;
> Eric Dumazet <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>;
> Paolo Abeni <pabeni@redhat.com>; Andrew Lunn <andrew@lunn.ch>;
> Heiner Kallweit <hkallweit1@gmail.com>; Russell King
> <linux@armlinux.org.uk>
> Cc: Oleksij Rempel <o.rempel@pengutronix.de>; kernel@pengutronix.de;
> linux-kernel@vger.kernel.org; netdev@vger.kernel.org; Shenwei Wang
> <shenwei.wang@nxp.com>; Clark Wang <xiaoning.wang@nxp.com>;
> dl-linux-imx <linux-imx@nxp.com>
> Subject: [PATCH net-next v5 8/8] net: fec: Fixup EEE
>
> From: Andrew Lunn <andrew@lunn.ch>
>
> The enabling/disabling of EEE in the MAC should happen as a result of auto
> negotiation. So move the enable/disable into
> fec_enet_adjust_link() which gets called by phylib when there is a change in
> link status.
>
> fec_enet_set_eee() now just stores away the LPI timer value.
> Everything else is passed to phylib, so it can correctly setup the PHY.
>
> fec_enet_get_eee() relies on phylib doing most of the work, the MAC driver
> just adds the LPI timer value.
>
> Call phy_support_eee() if the quirk is present to indicate the MAC actually
> supports EEE.
>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> (On iMX8MP debix)
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> v2: Only call fec_enet_eee_mode_set for those that support EEE
> v7: update against kernel v6.8-rc4
> ---
> drivers/net/ethernet/freescale/fec_main.c | 23 +++++------------------
> 1 file changed, 5 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> index a2c786550342..d7693fdf640d 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -2033,13 +2033,8 @@ static int fec_enet_eee_mode_set(struct
> net_device *ndev, bool enable)
> struct fec_enet_private *fep = netdev_priv(ndev);
> struct ethtool_keee *p = &fep->eee;
> unsigned int sleep_cycle, wake_cycle;
> - int ret = 0;
>
> if (enable) {
> - ret = phy_init_eee(ndev->phydev, false);
> - if (ret)
> - return ret;
> -
> sleep_cycle = fec_enet_us_to_tx_cycle(ndev, p->tx_lpi_timer);
> wake_cycle = sleep_cycle;
> } else {
> @@ -2047,8 +2042,6 @@ static int fec_enet_eee_mode_set(struct
> net_device *ndev, bool enable)
> wake_cycle = 0;
> }
>
> - p->tx_lpi_enabled = enable;
> -
> writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP);
> writel(wake_cycle, fep->hwp + FEC_LPI_WAKE);
>
> @@ -2094,6 +2087,8 @@ static void fec_enet_adjust_link(struct net_device
> *ndev)
> netif_tx_unlock_bh(ndev);
> napi_enable(&fep->napi);
> }
> + if (fep->quirks & FEC_QUIRK_HAS_EEE)
> + fec_enet_eee_mode_set(ndev, phy_dev->enable_tx_lpi);
> } else {
> if (fep->link) {
> netif_stop_queue(ndev);
> @@ -2453,6 +2448,9 @@ static int fec_enet_mii_probe(struct net_device
> *ndev)
> else
> phy_set_max_speed(phy_dev, 100);
>
> + if (fep->quirks & FEC_QUIRK_HAS_EEE)
> + phy_support_eee(phy_dev);
> +
> fep->link = 0;
> fep->full_duplex = 0;
>
> @@ -3172,7 +3170,6 @@ fec_enet_get_eee(struct net_device *ndev, struct
> ethtool_keee *edata)
> return -ENETDOWN;
>
> edata->tx_lpi_timer = p->tx_lpi_timer;
> - edata->tx_lpi_enabled = p->tx_lpi_enabled;
>
> return phy_ethtool_get_eee(ndev->phydev, edata); } @@ -3182,7
> +3179,6 @@ fec_enet_set_eee(struct net_device *ndev, struct ethtool_keee
> *edata) {
> struct fec_enet_private *fep = netdev_priv(ndev);
> struct ethtool_keee *p = &fep->eee;
> - int ret = 0;
>
> if (!(fep->quirks & FEC_QUIRK_HAS_EEE))
> return -EOPNOTSUPP;
> @@ -3192,15 +3188,6 @@ fec_enet_set_eee(struct net_device *ndev, struct
> ethtool_keee *edata)
>
> p->tx_lpi_timer = edata->tx_lpi_timer;
>
> - if (!edata->eee_enabled || !edata->tx_lpi_enabled ||
> - !edata->tx_lpi_timer)
> - ret = fec_enet_eee_mode_set(ndev, false);
> - else
> - ret = fec_enet_eee_mode_set(ndev, true);
> -
> - if (ret)
> - return ret;
> -
> return phy_ethtool_set_eee(ndev->phydev, edata); }
>
> --
> 2.39.2

Reviewed-by: Wei Fang <wei.fang@nxp.com>