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

Oleksij Rempel posted 7 patches 11 months ago
There is a newer version of this series
[PATCH net-next v3 5/7] net: usb: lan78xx: port link settings to phylink API
Posted by Oleksij Rempel 11 months ago
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;
-
-	/* 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,
-- 
2.39.5
Re: [PATCH net-next v3 5/7] net: usb: lan78xx: port link settings to phylink API
Posted by kernel test robot 11 months ago
Hi Oleksij,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Oleksij-Rempel/net-usb-lan78xx-Convert-to-PHYlink-for-improved-PHY-and-MAC-management/20250310-200116
base:   net-next/main
patch link:    https://lore.kernel.org/r/20250310115737.784047-6-o.rempel%40pengutronix.de
patch subject: [PATCH net-next v3 5/7] net: usb: lan78xx: port link settings to phylink API
config: i386-randconfig-006-20250315 (https://download.01.org/0day-ci/archive/20250315/202503151447.4eGbKrTa-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250315/202503151447.4eGbKrTa-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202503151447.4eGbKrTa-lkp@intel.com/

All errors (new ones prefixed by >>):

   ld: drivers/net/usb/lan78xx.o: in function `lan78xx_set_link_ksettings':
>> drivers/net/usb/lan78xx.c:1874: undefined reference to `phylink_ethtool_ksettings_set'
   ld: drivers/net/usb/lan78xx.o: in function `lan78xx_get_link_ksettings':
>> drivers/net/usb/lan78xx.c:1866: undefined reference to `phylink_ethtool_ksettings_get'
   ld: drivers/net/usb/lan78xx.o: in function `lan78xx_open':
   drivers/net/usb/lan78xx.c:3252: undefined reference to `phylink_start'
   ld: drivers/net/usb/lan78xx.o: in function `lan78xx_stop':
   drivers/net/usb/lan78xx.c:3322: undefined reference to `phylink_stop'
   ld: drivers/net/usb/lan78xx.o: in function `lan78xx_disconnect':
   drivers/net/usb/lan78xx.c:4347: undefined reference to `phylink_stop'
   ld: drivers/net/usb/lan78xx.c:4348: undefined reference to `phylink_disconnect_phy'
   ld: drivers/net/usb/lan78xx.c:4359: undefined reference to `phylink_destroy'
   ld: drivers/net/usb/lan78xx.o: in function `lan78xx_reset_resume':
   drivers/net/usb/lan78xx.c:5145: undefined reference to `phylink_start'
   ld: drivers/net/usb/lan78xx.o: in function `lan78xx_phy_init':
   drivers/net/usb/lan78xx.c:2650: undefined reference to `phylink_connect_phy'
   ld: drivers/net/usb/lan78xx.c:2618: undefined reference to `phylink_set_fixed_link'
   ld: drivers/net/usb/lan78xx.o: in function `lan78xx_phylink_setup':
   drivers/net/usb/lan78xx.c:2588: undefined reference to `phylink_create'
   ld: drivers/net/usb/lan78xx.o: in function `lan78xx_probe':
   drivers/net/usb/lan78xx.c:4581: undefined reference to `phylink_disconnect_phy'
   ld: drivers/net/usb/lan78xx.c:4583: undefined reference to `phylink_destroy'


vim +1874 drivers/net/usb/lan78xx.c

  1860	
  1861	static int lan78xx_get_link_ksettings(struct net_device *net,
  1862					      struct ethtool_link_ksettings *cmd)
  1863	{
  1864		struct lan78xx_net *dev = netdev_priv(net);
  1865	
> 1866		return phylink_ethtool_ksettings_get(dev->phylink, cmd);
  1867	}
  1868	
  1869	static int lan78xx_set_link_ksettings(struct net_device *net,
  1870					      const struct ethtool_link_ksettings *cmd)
  1871	{
  1872		struct lan78xx_net *dev = netdev_priv(net);
  1873	
> 1874		return phylink_ethtool_ksettings_set(dev->phylink, cmd);
  1875	}
  1876	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH net-next v3 5/7] net: usb: lan78xx: port link settings to phylink API
Posted by Maxime Chevallier 11 months ago
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