Skip to contentSkip to conversation

net: stmmac: Simplify ioctl handling

PATCH Applied Maxime Chevallier 5 participants 12 messages Jul 18 – Jul 21

Subsystems (4)
lore
Share & tools
lore

Maxime Chevallier

author maintainer
#0 lore raw

PATCH 1/1 net: stmmac: Simplify ioctl handling

Now that timestamping is controlled through an NDO, we can simply call phylink_mii_ioctl() to handle ioctls.

The only functional difference is that phylink_mii_ioctl() -> phy_mii_ioctl() can handle SIOCSHWTSTAMP, but this no longer happens as this ioctl is not longer dispatched to the ndo_eth_ioctl().

---

Looking at this, I'm wondering if we can't just get rid of SIOCSHWTSTAMP handling in phy_mii_ioctl(). Looks like we can ?

 .../net/ethernet/stmicro/stmmac/stmmac_main.c   | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -14
index 2a0d7eff88d3..562d20830b94 100644
@@ -6371,28 +6371,17 @@ static irqreturn_t stmmac_msi_intr_rx(int irq, void *data)
  *  @rq: An IOCTL specific structure, that can contain a pointer to
  *  a proprietary structure used to pass information to the driver.
  *  @cmd: IOCTL command
- *  Description:
- *  Currently it supports the phy_mii_ioctl(...) and HW time stamping.
+ *  Description: Forward the PHY ioctls to phylink
+ *  Return: Zero on success or negative error code.
  */
 static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
 	struct stmmac_priv *priv = netdev_priv (dev);
-	int ret = -EOPNOTSUPP;
 
 	if (!netif_running(dev))
 		return -EINVAL;
 
-	switch (cmd) {
-	case SIOCGMIIPHY:
-	case SIOCGMIIREG:
-	case SIOCSMIIREG:
-		ret = phylink_mii_ioctl(priv->phylink, rq, cmd);
-		break;
-	default:
-		break;
-	}
-
-	return ret;
+	return phylink_mii_ioctl(priv->phylink, rq, cmd);
 }
 
 static int stmmac_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 42 lines · Maxime Chevallier

Now that timestamping is controlled through an NDO, we can simply call phylink_mii_ioctl() to handle ioctls.

The only functional difference is that phylink_mii_ioctl() -> phy_mii_ioctl() can handle SIOCSHWTSTAMP, but this no longer happens as this ioctl is not longer dispatched to the ndo_eth_ioctl().

---

Looking at this, I'm wondering if we can't just get rid of SIOCSHWTSTAMP handling in phy_mii_ioctl(). Looks like we can ?

  .../net/ethernet/stmicro/stmmac/stmmac_main.c   | 17 +++--------------
  1 file changed, 3 insertions(+), 14 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -8
index 2a0d7eff88d3..562d20830b94 100644
@@ -6371,28 +6371,17 @@ static irqreturn_t stmmac_msi_intr_rx(int irq, void *data)
   *  @rq: An IOCTL specific structure, that can contain a pointer to
   *  a proprietary structure used to pass information to the driver.
   *  @cmd: IOCTL command
- *  Description:
- *  Currently it supports the phy_mii_ioctl(...) and HW time stamping.
+ *  Description: Forward the PHY ioctls to phylink
+ *  Return: Zero on success or negative error code.
   */
  static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  {
  	struct stmmac_priv *priv = netdev_priv (dev);
-	int ret = -EOPNOTSUPP;
 
  	if (!netif_running(dev))
  		return -EINVAL;
 
-	switch (cmd) {
-	case SIOCGMIIPHY:
-	case SIOCGMIIREG:
-	case SIOCSMIIREG:
-		ret = phylink_mii_ioctl(priv->phylink, rq, cmd);

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static irqreturn_t stmmac_msi_intr_rx(int irq, void *data) · line 6387

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -6
-		break;
-	default:
-		break;
-	}
-
-	return ret;
+	return phylink_mii_ioctl(priv->phylink, rq, cmd);
  }
 
  static int stmmac_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
#2 lore raw
In reply to Maxime Chevallier
Quoted 2 lines

Looking at this, I'm wondering if we can't just get rid of SIOCSHWTSTAMP handling in phy_mii_ioctl(). Looks like we can ?

I'm not sure about that. We need Richards input.

The code in phy_mii_ioctl() allows the MAC to be bypassed, it goes straight to a PHY based stamper. It could be the MAC has no idea the PHY has this capability, so it has not implemented the .ndo?

It might be we need to hoist the code from phy_mii_ioctl() into dev_{sg}et_hwtstamp()?

Andrew

#3 lore raw
Quoted 11 lines · Andrew Lunn
Quoted 2 lines

Looking at this, I'm wondering if we can't just get rid of SIOCSHWTSTAMP handling in phy_mii_ioctl(). Looks like we can ?

I'm not sure about that. We need Richards input.

The code in phy_mii_ioctl() allows the MAC to be bypassed, it goes straight to a PHY based stamper. It could be the MAC has no idea the PHY has this capability, so it has not implemented the .ndo?

It might be we need to hoist the code from phy_mii_ioctl() into dev_{sg}et_hwtstamp()?

Hi Andrew!

I think I've converted all phy drivers while removing support for SIOCSHWTSTAMP/SIOCGHWTSTAMP from netdev ioctl. I believe it's impossible right now to reach SIOCSHWTSTAMP path of phy_mii_ioctl via ioctl on net device.

Is it possible to have ioctl on phy device directly without involving netdev?

author maintainer
#4 lore raw
Quoted 9 lines · Vadim Fedorenko
Quoted 8 lines · Andrew Lunn
Quoted 2 lines

Looking at this, I'm wondering if we can't just get rid of SIOCSHWTSTAMP handling in phy_mii_ioctl(). Looks like we can ?

I'm not sure about that. We need Richards input.

The code in phy_mii_ioctl() allows the MAC to be bypassed, it goes straight to a PHY based stamper. It could be the MAC has no idea the PHY has this capability, so it has not implemented the .ndo?

Indeed, but even then the SIOCxHWTSTAMP aren't reaching the ndo_ioctl.

Maybe the thing to change (unrelated to the icotl though) is in dev_set_hwtstamp :

	if (!ops->ndo_hwtstamp_set)
		return -EOPNOTSUPP;

	if (!netif_device_present(dev))
		return -ENODEV;

	netdev_lock_ops(dev);
	err = dev_set_hwtstamp_phylib(dev, &kernel_cfg, &extack);
	netdev_unlock_ops(dev);

We don't try to configure the PHY timestamping if the MAC doesn't support the .ndo, maybe we should allow that ?

Quoted 9 lines
Quoted 3 lines

It might be we need to hoist the code from phy_mii_ioctl() into dev_{sg}et_hwtstamp()?

Hi Andrew!

I think I've converted all phy drivers while removing support for SIOCSHWTSTAMP/SIOCGHWTSTAMP from netdev ioctl. I believe it's impossible right now to reach SIOCSHWTSTAMP path of phy_mii_ioctl via ioctl on net device.

That was also my understanding indeed.

Quoted 1 line

Is it possible to have ioctl on phy device directly without involving netdev?

Unless there's an obscure mechanism I don't know about, there shouldn't be a way.

SIOCSHWTSTAMP/SIOCGHWTSTAMP don't seem to reach netdev anymore with the (great !) work you've done, so they won't reach the PHY either indeed.

The SIOC ioctls can't reach PHYs without a netdev, neither can the ethnl ones. Even when we have multiple PHYs and we use netlink, we can only reach the ones behind a netdevice.

There is still sysfs entries for standalone PHYs, but I don't think we can use any of that for ioctl.

Maxime

#5 lore raw
In reply to Vadim Fedorenko
Quoted 10 lines · Vadim Fedorenko
Quoted 9 lines · Andrew Lunn
Quoted 2 lines

Looking at this, I'm wondering if we can't just get rid of SIOCSHWTSTAMP handling in phy_mii_ioctl(). Looks like we can ?

I'm not sure about that. We need Richards input.

The code in phy_mii_ioctl() allows the MAC to be bypassed, it goes straight to a PHY based stamper. It could be the MAC has no idea the PHY has this capability, so it has not implemented the .ndo?

Quoted 8 lines
Quoted 2 lines

It might be we need to hoist the code from phy_mii_ioctl() into dev_{sg}et_hwtstamp()?

Hi Andrew!

I think I've converted all phy drivers while removing support for SIOCSHWTSTAMP/SIOCGHWTSTAMP from netdev ioctl. I believe it's impossible right now to reach SIOCSHWTSTAMP path of phy_mii_ioctl via ioctl on net device.

Lets look at this, using a random example:

drivers/net/ethernet/marvell/mv643xx_eth.c

mv643xx_eth_netdev_ops has nothing about time stamping. However it does have a mv643xx_eth_ioctl. Which calls phy_mii_ioctl().

Lets say this Marvell MAC driver was paired with a nxp-c45-tja11xx. nxp_c45_probe() does:

                priv->mii_ts.rxtstamp = nxp_c45_rxtstamp;
                priv->mii_ts.txtstamp = nxp_c45_txtstamp;
                priv->mii_ts.hwtstamp_set = nxp_c45_hwtstamp_set;
                priv->mii_ts.hwtstamp_get = nxp_c45_hwtstamp_get;
                priv->mii_ts.ts_info = nxp_c45_ts_info;
                phydev->mii_ts = &priv->mii_ts;

So it looks like in phy_mii_ioctl(), the conditions:

       case SIOCSHWTSTAMP:
                if (phydev->mii_ts && phydev->mii_ts->hwtstamp_set) {

are fulfilled, and

                        ret = phydev->mii_ts->hwtstamp_set(phydev->mii_ts,
                                                           &kernel_cfg,
                                                           &extack);

will happen.

Now, this combination of MAC and PHY is very unlikely but it proves the point. As far as i remember, Richard added this code for the dp83640 PHY device, but i don't remember what MAC driver it was paired with. He wanted to make PHY support just work without the MAC driver even caring.

Andrew

#6 lore raw
Quoted 48 lines · Andrew Lunn
Quoted 10 lines · Vadim Fedorenko
Quoted 9 lines · Andrew Lunn
Quoted 2 lines

Looking at this, I'm wondering if we can't just get rid of SIOCSHWTSTAMP handling in phy_mii_ioctl(). Looks like we can ?

I'm not sure about that. We need Richards input.

The code in phy_mii_ioctl() allows the MAC to be bypassed, it goes straight to a PHY based stamper. It could be the MAC has no idea the PHY has this capability, so it has not implemented the .ndo?

Quoted 8 lines
Quoted 2 lines

It might be we need to hoist the code from phy_mii_ioctl() into dev_{sg}et_hwtstamp()?

Hi Andrew!

I think I've converted all phy drivers while removing support for SIOCSHWTSTAMP/SIOCGHWTSTAMP from netdev ioctl. I believe it's impossible right now to reach SIOCSHWTSTAMP path of phy_mii_ioctl via ioctl on net device.

Lets look at this, using a random example:

drivers/net/ethernet/marvell/mv643xx_eth.c

mv643xx_eth_netdev_ops has nothing about time stamping. However it does have a mv643xx_eth_ioctl. Which calls phy_mii_ioctl().

Lets say this Marvell MAC driver was paired with a nxp-c45-tja11xx. nxp_c45_probe() does:

                 priv->mii_ts.rxtstamp = nxp_c45_rxtstamp;
                 priv->mii_ts.txtstamp = nxp_c45_txtstamp;
                 priv->mii_ts.hwtstamp_set = nxp_c45_hwtstamp_set;
                 priv->mii_ts.hwtstamp_get = nxp_c45_hwtstamp_get;
                 priv->mii_ts.ts_info = nxp_c45_ts_info;
                 phydev->mii_ts = &priv->mii_ts;

So it looks like in phy_mii_ioctl(), the conditions:

        case SIOCSHWTSTAMP:
                 if (phydev->mii_ts && phydev->mii_ts->hwtstamp_set) {

are fulfilled, and

                         ret = phydev->mii_ts->hwtstamp_set(phydev->mii_ts,
                                                            &kernel_cfg,
                                                            &extack);
Quoted 7 lines

will happen.

Now, this combination of MAC and PHY is very unlikely but it proves the point. As far as i remember, Richard added this code for the dp83640 PHY device, but i don't remember what MAC driver it was paired with. He wanted to make PHY support just work without the MAC driver even caring.

looks like it won't work now. we have to create helpers in phy to fix it.
I can work on it, but I don't have such HW combination to test. Do you have some HW to test this combination?

Quoted 2 lines

Andrew

#7 lore raw
Quoted 3 lines

looks like it won't work now. we have to create helpers in phy to fix it. I can work on it, but I don't have such HW combination to test. Do you have some HW to test this combination?

I don't. You should ask Richard Cochran. He added this code.

Andrew

#8 lore raw
In reply to Andrew Lunn
Quoted 48 lines · Andrew Lunn
Quoted 10 lines · Vadim Fedorenko
Quoted 9 lines · Andrew Lunn
Quoted 2 lines

Looking at this, I'm wondering if we can't just get rid of SIOCSHWTSTAMP handling in phy_mii_ioctl(). Looks like we can ?

I'm not sure about that. We need Richards input.

The code in phy_mii_ioctl() allows the MAC to be bypassed, it goes straight to a PHY based stamper. It could be the MAC has no idea the PHY has this capability, so it has not implemented the .ndo?

Quoted 8 lines
Quoted 2 lines

It might be we need to hoist the code from phy_mii_ioctl() into dev_{sg}et_hwtstamp()?

Hi Andrew!

I think I've converted all phy drivers while removing support for SIOCSHWTSTAMP/SIOCGHWTSTAMP from netdev ioctl. I believe it's impossible right now to reach SIOCSHWTSTAMP path of phy_mii_ioctl via ioctl on net device.

Lets look at this, using a random example:

drivers/net/ethernet/marvell/mv643xx_eth.c

mv643xx_eth_netdev_ops has nothing about time stamping. However it does have a mv643xx_eth_ioctl. Which calls phy_mii_ioctl().

Lets say this Marvell MAC driver was paired with a nxp-c45-tja11xx. nxp_c45_probe() does:

                 priv->mii_ts.rxtstamp = nxp_c45_rxtstamp;
                 priv->mii_ts.txtstamp = nxp_c45_txtstamp;
                 priv->mii_ts.hwtstamp_set = nxp_c45_hwtstamp_set;
                 priv->mii_ts.hwtstamp_get = nxp_c45_hwtstamp_get;
                 priv->mii_ts.ts_info = nxp_c45_ts_info;
                 phydev->mii_ts = &priv->mii_ts;

So it looks like in phy_mii_ioctl(), the conditions:

        case SIOCSHWTSTAMP:
                 if (phydev->mii_ts && phydev->mii_ts->hwtstamp_set) {

are fulfilled, and

                         ret = phydev->mii_ts->hwtstamp_set(phydev->mii_ts,
                                                            &kernel_cfg,
                                                            &extack);
Quoted 7 lines

will happen.

Now, this combination of MAC and PHY is very unlikely but it proves the point. As far as i remember, Richard added this code for the dp83640 PHY device, but i don't remember what MAC driver it was paired with. He wanted to make PHY support just work without the MAC driver even caring.

Richard,

is it still a case? do you have a HW to test patches that I'm going to write to restore the functionality?

maintainer
#9 lore raw
In reply to Maxime Chevallier
Quoted 6 lines · On Sat, 18 Jul 2026 16:38:47 +0200 Maxime Chevallier wrote:

Now that timestamping is controlled through an NDO, we can simply call phylink_mii_ioctl() to handle ioctls.

The only functional difference is that phylink_mii_ioctl() -> phy_mii_ioctl() can handle SIOCSHWTSTAMP, but this no longer happens as this ioctl is not longer dispatched to the ndo_eth_ioctl().

To double check - the discussion is orthogonal and this patch can be applied as is?

author maintainer
#10 lore raw

Hi Jakub,

Quoted 10 lines · Jakub Kicinski
Quoted 6 lines · On Sat, 18 Jul 2026 16:38:47 +0200 Maxime Chevallier wrote:

Now that timestamping is controlled through an NDO, we can simply call phylink_mii_ioctl() to handle ioctls.

The only functional difference is that phylink_mii_ioctl() -> phy_mii_ioctl() can handle SIOCSHWTSTAMP, but this no longer happens as this ioctl is not longer dispatched to the ndo_eth_ioctl().

To double check - the discussion is orthogonal and this patch can be applied as is?

Indeed yes, the patch itself doesn't introduce any behaviour change.

That's actually when I noticed that it doesn't introduce behaviour changes (as the SIOCSHWTSTAMP ioctl is masked and doesn't reach the .ndo_ioctl() in the first place) that I added the small comment that started this discussion :)

Maxime

#11 lore raw
In reply to Maxime Chevallier
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Sat, 18 Jul 2026 16:38:47 +0200 you wrote:

Now that timestamping is controlled through an NDO, we can simply call phylink_mii_ioctl() to handle ioctls.

The only functional difference is that phylink_mii_ioctl() -> phy_mii_ioctl() can handle SIOCSHWTSTAMP, but this no longer happens as this ioctl is not longer dispatched to the ndo_eth_ioctl().

[...]

Here is the summary with links:
- [net-next] net: stmmac: Simplify ioctl handling

    https://git.kernel.org/netdev/net-next/c/357997831d0b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html