Re: [PATCH net-next v3 5/7] net: usb: lan78xx: port link settings to phylink API

Maxime Chevallier
2025-03-11T17:11:24Z

Hello Oleksij,

On Mon, 10 Mar 2025 12:57:35 +0100
Oleksij Rempel <o.rempel@pengutronix.de> wrote:

> Refactor lan78xx_get_link_ksettings and lan78xx_set_link_ksettings to
> use the phylink API (phylink_ethtool_ksettings_get and
> phylink_ethtool_ksettings_set) instead of directly interfacing with the
> PHY. This change simplifies the code and ensures better integration with
> the phylink framework for link management.
>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> drivers/net/usb/lan78xx.c | 34 ++--------------------------------
> 1 file changed, 2 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
> index 73f62c3e5c58..7107eaa440e5 100644
> --- a/drivers/net/usb/lan78xx.c
> +++ b/drivers/net/usb/lan78xx.c
> @@ -1862,46 +1862,16 @@ static int lan78xx_get_link_ksettings(struct net_device *net,
> struct ethtool_link_ksettings *cmd)
> {
> struct lan78xx_net *dev = netdev_priv(net);
> - struct phy_device *phydev = net->phydev;
> - int ret;
> -
> - ret = usb_autopm_get_interface(dev->intf);
> - if (ret < 0)
> - return ret;
>
> - phy_ethtool_ksettings_get(phydev, cmd);
> -
> - usb_autopm_put_interface(dev->intf);
> -
> - return ret;
> + return phylink_ethtool_ksettings_get(dev->phylink, cmd);
> }
>
> static int lan78xx_set_link_ksettings(struct net_device *net,
> const struct ethtool_link_ksettings *cmd)
> {
> struct lan78xx_net *dev = netdev_priv(net);
> - struct phy_device *phydev = net->phydev;
> - int ret = 0;
> - int temp;
> -
> - ret = usb_autopm_get_interface(dev->intf);
> - if (ret < 0)
> - return ret;

It is unclear to me why these usb_autopm_* calls are here in the first
place. I think we only need to make sure that the mdio accesses are done
under usb_autopm_get_interface(), which is already the case.

> - /* change speed & duplex */
> - ret = phy_ethtool_ksettings_set(phydev, cmd);
>
> - if (!cmd->base.autoneg) {
> - /* force link down */
> - temp = phy_read(phydev, MII_BMCR);
> - phy_write(phydev, MII_BMCR, temp | BMCR_LOOPBACK);
> - mdelay(1);
> - phy_write(phydev, MII_BMCR, temp);
> - }
> -
> - usb_autopm_put_interface(dev->intf);
> -
> - return ret;
> + return phylink_ethtool_ksettings_set(dev->phylink, cmd);
> }
>
> static void lan78xx_get_pause(struct net_device *net,

If you need to respin maybe add something about it in the commit,
but besides that,

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Maxime