[PATCH net-next] microchip: lan865x: add ndo_eth_ioctl handler to enable PHY ioctl support

Parthiban Veerasooran posted 1 patch 1 month, 1 week ago
There is a newer version of this series
drivers/net/ethernet/microchip/lan865x/lan865x.c | 10 ++++++++++
1 file changed, 10 insertions(+)
[PATCH net-next] microchip: lan865x: add ndo_eth_ioctl handler to enable PHY ioctl support
Posted by Parthiban Veerasooran 1 month, 1 week ago
Introduce support for standard MII ioctl operations in the LAN865x
Ethernet driver by implementing the .ndo_eth_ioctl callback. This allows
userspace tools such as ethtool and mii-tool to perform PHY register
access using commands like SIOCGMIIREG and SIOCSMIIREG.

The new lan865x_eth_ioctl() function forwards these ioctl calls to the
PHY layer through phy_mii_ioctl() when the network interface is up.

This feature enables improved diagnostics and PHY configuration
capabilities from userspace.

Signed-off-by: Parthiban Veerasooran <parthiban.veerasooran@microchip.com>
---
 drivers/net/ethernet/microchip/lan865x/lan865x.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/ethernet/microchip/lan865x/lan865x.c b/drivers/net/ethernet/microchip/lan865x/lan865x.c
index 84c41f193561..7f586f9558ff 100644
--- a/drivers/net/ethernet/microchip/lan865x/lan865x.c
+++ b/drivers/net/ethernet/microchip/lan865x/lan865x.c
@@ -320,12 +320,22 @@ static int lan865x_net_open(struct net_device *netdev)
 	return 0;
 }
 
+static int lan865x_eth_ioctl(struct net_device *netdev, struct ifreq *rq,
+			     int cmd)
+{
+	if (!netif_running(netdev))
+		return -EINVAL;
+
+	return phy_mii_ioctl(netdev->phydev, rq, cmd);
+}
+
 static const struct net_device_ops lan865x_netdev_ops = {
 	.ndo_open		= lan865x_net_open,
 	.ndo_stop		= lan865x_net_close,
 	.ndo_start_xmit		= lan865x_send_packet,
 	.ndo_set_rx_mode	= lan865x_set_multicast_list,
 	.ndo_set_mac_address	= lan865x_set_mac_address,
+	.ndo_eth_ioctl          = lan865x_eth_ioctl,
 };
 
 static int lan865x_probe(struct spi_device *spi)

base-commit: a7bd72158063740212344fad5d99dcef45bc70d6
-- 
2.34.1
Re: [PATCH net-next] microchip: lan865x: add ndo_eth_ioctl handler to enable PHY ioctl support
Posted by Paolo Abeni 1 month ago
On 8/22/25 10:50 AM, Parthiban Veerasooran wrote:
> diff --git a/drivers/net/ethernet/microchip/lan865x/lan865x.c b/drivers/net/ethernet/microchip/lan865x/lan865x.c
> index 84c41f193561..7f586f9558ff 100644
> --- a/drivers/net/ethernet/microchip/lan865x/lan865x.c
> +++ b/drivers/net/ethernet/microchip/lan865x/lan865x.c
> @@ -320,12 +320,22 @@ static int lan865x_net_open(struct net_device *netdev)
>  	return 0;
>  }
>  
> +static int lan865x_eth_ioctl(struct net_device *netdev, struct ifreq *rq,
> +			     int cmd)
> +{
> +	if (!netif_running(netdev))
> +		return -EINVAL;
> +
> +	return phy_mii_ioctl(netdev->phydev, rq, cmd);
> +}
> +
>  static const struct net_device_ops lan865x_netdev_ops = {
>  	.ndo_open		= lan865x_net_open,
>  	.ndo_stop		= lan865x_net_close,
>  	.ndo_start_xmit		= lan865x_send_packet,
>  	.ndo_set_rx_mode	= lan865x_set_multicast_list,
>  	.ndo_set_mac_address	= lan865x_set_mac_address,
> +	.ndo_eth_ioctl          = lan865x_eth_ioctl,

It looks like you could use directly phy_do_ioctl_running() and avoid
some code duplication.

/P
Re: [PATCH net-next] microchip: lan865x: add ndo_eth_ioctl handler to enable PHY ioctl support
Posted by Parthiban.Veerasooran@microchip.com 1 month ago
Hi Paolo Abeni,

On 28/08/25 12:54 pm, Paolo Abeni wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 8/22/25 10:50 AM, Parthiban Veerasooran wrote:
>> diff --git a/drivers/net/ethernet/microchip/lan865x/lan865x.c b/drivers/net/ethernet/microchip/lan865x/lan865x.c
>> index 84c41f193561..7f586f9558ff 100644
>> --- a/drivers/net/ethernet/microchip/lan865x/lan865x.c
>> +++ b/drivers/net/ethernet/microchip/lan865x/lan865x.c
>> @@ -320,12 +320,22 @@ static int lan865x_net_open(struct net_device *netdev)
>>        return 0;
>>   }
>>
>> +static int lan865x_eth_ioctl(struct net_device *netdev, struct ifreq *rq,
>> +                          int cmd)
>> +{
>> +     if (!netif_running(netdev))
>> +             return -EINVAL;
>> +
>> +     return phy_mii_ioctl(netdev->phydev, rq, cmd);
>> +}
>> +
>>   static const struct net_device_ops lan865x_netdev_ops = {
>>        .ndo_open               = lan865x_net_open,
>>        .ndo_stop               = lan865x_net_close,
>>        .ndo_start_xmit         = lan865x_send_packet,
>>        .ndo_set_rx_mode        = lan865x_set_multicast_list,
>>        .ndo_set_mac_address    = lan865x_set_mac_address,
>> +     .ndo_eth_ioctl          = lan865x_eth_ioctl,
> 
> It looks like you could use directly phy_do_ioctl_running() and avoid
> some code duplication.
Yes, thank you for pointing that out. I will update it in the next version.

Best regards,
Parthiban V
> 
> /P
>