RE: [PATCH net-next v5 7/8] net: fec: Move fec_enet_eee_mode_set() and helper earlier

From: Wei Fang
Date: Fri Feb 23 2024 - 01:03:51 EST


> -----Original Message-----
> From: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
> Sent: 2024年2月21日 14:21
> To: Wei Fang <wei.fang@xxxxxxx>; David S. Miller <davem@xxxxxxxxxxxxx>;
> Eric Dumazet <edumazet@xxxxxxxxxx>; Jakub Kicinski <kuba@xxxxxxxxxx>;
> Paolo Abeni <pabeni@xxxxxxxxxx>; Andrew Lunn <andrew@xxxxxxx>;
> Heiner Kallweit <hkallweit1@xxxxxxxxx>; Russell King
> <linux@xxxxxxxxxxxxxxx>
> Cc: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>; kernel@xxxxxxxxxxxxxx;
> linux-kernel@xxxxxxxxxxxxxxx; netdev@xxxxxxxxxxxxxxx; Shenwei Wang
> <shenwei.wang@xxxxxxx>; Clark Wang <xiaoning.wang@xxxxxxx>;
> dl-linux-imx <linux-imx@xxxxxxx>
> Subject: [PATCH net-next v5 7/8] net: fec: Move fec_enet_eee_mode_set()
> and helper earlier
>
> From: Andrew Lunn <andrew@xxxxxxx>
>
> FEC is about to get its EEE code re-written. To allow this, move
> fec_enet_eee_mode_set() before fec_enet_adjust_link() which will need to
> call it.
>
> Signed-off-by: Andrew Lunn <andrew@xxxxxxx>
> Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
> ---
> drivers/net/ethernet/freescale/fec_main.c | 75 ++++++++++++-----------
> 1 file changed, 38 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> index 207f1f66c117..a2c786550342 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -2017,6 +2017,44 @@ static int fec_get_mac(struct net_device *ndev)
> /*
> * Phy section
> */
> +
> +/* LPI Sleep Ts count base on tx clk (clk_ref).
> + * The lpi sleep cnt value = X us / (cycle_ns).
> + */
> +static int fec_enet_us_to_tx_cycle(struct net_device *ndev, int us) {
> + struct fec_enet_private *fep = netdev_priv(ndev);
> +
> + return us * (fep->clk_ref_rate / 1000) / 1000; }
> +
> +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 {
> + sleep_cycle = 0;
> + wake_cycle = 0;
> + }
> +
> + p->tx_lpi_enabled = enable;
> +
> + writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP);
> + writel(wake_cycle, fep->hwp + FEC_LPI_WAKE);
> +
> + return 0;
> +}
> +
> static void fec_enet_adjust_link(struct net_device *ndev) {
> struct fec_enet_private *fep = netdev_priv(ndev); @@ -3121,43 +3159,6
> @@ static int fec_enet_set_coalesce(struct net_device *ndev,
> return 0;
> }
>
> -/* LPI Sleep Ts count base on tx clk (clk_ref).
> - * The lpi sleep cnt value = X us / (cycle_ns).
> - */
> -static int fec_enet_us_to_tx_cycle(struct net_device *ndev, int us) -{
> - struct fec_enet_private *fep = netdev_priv(ndev);
> -
> - return us * (fep->clk_ref_rate / 1000) / 1000;
> -}
> -
> -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 {
> - sleep_cycle = 0;
> - wake_cycle = 0;
> - }
> -
> - p->tx_lpi_enabled = enable;
> -
> - writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP);
> - writel(wake_cycle, fep->hwp + FEC_LPI_WAKE);
> -
> - return 0;
> -}
> -
> static int
> fec_enet_get_eee(struct net_device *ndev, struct ethtool_keee *edata) {
> --
> 2.39.2

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