Skip to contentSkip to conversation

tsnep: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()

PATCH In review Gerhard Engleder 2 participants 4 messages Oct 17, 2025 – Oct 21, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tsnep: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()

From: Vladimir Oltean <[email protected]>

I took over this patch from Vladimir Oltean. The only change from my side is the adaption of the commit message. I hope I mentioned his work correctly in the tags.

New timestamping API was introduced in commit 66f7223039c0 ("net: add NDOs for configuring hardware timestamping") from kernel v6.6.

It is time to convert the tsnep driver to the new API, so that timestamping configuration can be removed from the ndo_eth_ioctl() path completely.

The driver does not need the interface to be down in order for timestamping to be changed. Thus, the netif_running() restriction in tsnep_netdev_ioctl() is not migrated to the new API. There is no interaction with hardware registers for either operation, just a concurrency with the data path which is fine.

After removing the PHY timestamping logic from tsnep_netdev_ioctl(), the rest is almost equivalent to phy_do_ioctl_running(), except for the return code on the !netif_running() condition: -EINVAL vs -ENODEV. Let's make the conversion to phy_do_ioctl_running() anyway, on the premise that a return code standardized tree-wide is less complex.

---
 drivers/net/ethernet/engleder/tsnep.h      |  8 +-
 drivers/net/ethernet/engleder/tsnep_main.c | 14 +---
 drivers/net/ethernet/engleder/tsnep_ptp.c  | 90 +++++++++++-----------
 3 files changed, 53 insertions(+), 59 deletions(-)
drivers/net/ethernet/engleder/tsnep.h +6 -2
index f188fba021a6..452ab982afbe 100644
@@ -176,7 +176,7 @@ struct tsnep_adapter {
 	struct tsnep_gcl gcl[2];
 	int next_gcl;
 
-	struct hwtstamp_config hwtstamp_config;
+	struct kernel_hwtstamp_config hwtstamp_config;
 	struct ptp_clock *ptp_clock;
 	struct ptp_clock_info ptp_clock_info;
 	/* ptp clock lock */
@@ -203,7 +203,11 @@ extern const struct ethtool_ops tsnep_ethtool_ops;
 
 int tsnep_ptp_init(struct tsnep_adapter *adapter);
 void tsnep_ptp_cleanup(struct tsnep_adapter *adapter);
-int tsnep_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
+int tsnep_hwtstamp_get(struct net_device *netdev,
+		       struct kernel_hwtstamp_config *config);
+int tsnep_hwtstamp_set(struct net_device *netdev,
+		       struct kernel_hwtstamp_config *config,
+		       struct netlink_ext_ack *extack);
 
 int tsnep_tc_init(struct tsnep_adapter *adapter);
 void tsnep_tc_cleanup(struct tsnep_adapter *adapter);
drivers/net/ethernet/engleder/tsnep_main.c +3 -11
index eba73246f986..c12ad990a2b6 100644
@@ -2168,16 +2168,6 @@ static netdev_tx_t tsnep_netdev_xmit_frame(struct sk_buff *skb,
 	return tsnep_xmit_frame_ring(skb, &adapter->tx[queue_mapping]);
 }
 
-static int tsnep_netdev_ioctl(struct net_device *netdev, struct ifreq *ifr,
-			      int cmd)
-{
-	if (!netif_running(netdev))
-		return -EINVAL;
-	if (cmd == SIOCSHWTSTAMP || cmd == SIOCGHWTSTAMP)
-		return tsnep_ptp_ioctl(netdev, ifr, cmd);
-	return phy_mii_ioctl(netdev->phydev, ifr, cmd);
-}
-
 static void tsnep_netdev_set_multicast(struct net_device *netdev)
 {
 	struct tsnep_adapter *adapter = netdev_priv(netdev);
@@ -2384,7 +2374,7 @@ static const struct net_device_ops tsnep_netdev_ops = {
 	.ndo_open = tsnep_netdev_open,
 	.ndo_stop = tsnep_netdev_close,
 	.ndo_start_xmit = tsnep_netdev_xmit_frame,
-	.ndo_eth_ioctl = tsnep_netdev_ioctl,
+	.ndo_eth_ioctl = phy_do_ioctl_running,
 	.ndo_set_rx_mode = tsnep_netdev_set_multicast,
 	.ndo_get_stats64 = tsnep_netdev_get_stats64,
 	.ndo_set_mac_address = tsnep_netdev_set_mac_address,
@@ -2394,6 +2384,8 @@ static const struct net_device_ops tsnep_netdev_ops = {
 	.ndo_bpf = tsnep_netdev_bpf,
 	.ndo_xdp_xmit = tsnep_netdev_xdp_xmit,
 	.ndo_xsk_wakeup = tsnep_netdev_xsk_wakeup,
+	.ndo_hwtstamp_get = tsnep_hwtstamp_get,
+	.ndo_hwtstamp_set = tsnep_hwtstamp_set,
 };
 
 static int tsnep_mac_init(struct tsnep_adapter *adapter)
drivers/net/ethernet/engleder/tsnep_ptp.c +44 -46

100 lines not on this page · raw message

Signature · 1 line
2.39.5
reviewer
#1 lore raw

+ Vadim

Quoted 25 lines · Gerhard Engleder

From: Vladimir Oltean <[email protected]>

I took over this patch from Vladimir Oltean. The only change from my side is the adaption of the commit message. I hope I mentioned his work correctly in the tags.

New timestamping API was introduced in commit 66f7223039c0 ("net: add NDOs for configuring hardware timestamping") from kernel v6.6.

It is time to convert the tsnep driver to the new API, so that timestamping configuration can be removed from the ndo_eth_ioctl() path completely.

The driver does not need the interface to be down in order for timestamping to be changed. Thus, the netif_running() restriction in tsnep_netdev_ioctl() is not migrated to the new API. There is no interaction with hardware registers for either operation, just a concurrency with the data path which is fine.

After removing the PHY timestamping logic from tsnep_netdev_ioctl(), the rest is almost equivalent to phy_do_ioctl_running(), except for the return code on the !netif_running() condition: -EINVAL vs -ENODEV. Let's make the conversion to phy_do_ioctl_running() anyway, on the premise that a return code standardized tree-wide is less complex.

Quoted 3 lines

Hi Gerhard, Vladimir, Vadim, all,

Recently Vadim has been working on converting a number of drivers to use ndo_hwtstamp_get() and ndo_hwtstamp_set(). And this includes a patch, rather similar to this one, for the tsnep [1].

I think it would be good to agree on the way forward here.

[1] https://lore.kernel.org/all/[email protected]/

...

#2 lore raw
Quoted 34 lines · Simon Horman

+ Vadim

Quoted 25 lines · Gerhard Engleder

From: Vladimir Oltean <[email protected]>

I took over this patch from Vladimir Oltean. The only change from my side is the adaption of the commit message. I hope I mentioned his work correctly in the tags.

New timestamping API was introduced in commit 66f7223039c0 ("net: add NDOs for configuring hardware timestamping") from kernel v6.6.

It is time to convert the tsnep driver to the new API, so that timestamping configuration can be removed from the ndo_eth_ioctl() path completely.

The driver does not need the interface to be down in order for timestamping to be changed. Thus, the netif_running() restriction in tsnep_netdev_ioctl() is not migrated to the new API. There is no interaction with hardware registers for either operation, just a concurrency with the data path which is fine.

After removing the PHY timestamping logic from tsnep_netdev_ioctl(), the rest is almost equivalent to phy_do_ioctl_running(), except for the return code on the !netif_running() condition: -EINVAL vs -ENODEV. Let's make the conversion to phy_do_ioctl_running() anyway, on the premise that a return code standardized tree-wide is less complex.

Quoted 3 lines

Hi Gerhard, Vladimir, Vadim, all,

Quoted 7 lines

Recently Vadim has been working on converting a number of drivers to use ndo_hwtstamp_get() and ndo_hwtstamp_set(). And this includes a patch, rather similar to this one, for the tsnep [1].

I think it would be good to agree on the way forward here.

[1] https://lore.kernel.org/all/[email protected]/

I already replied to Vadim, but on the first patch version, not on V3.

@Vadim: I reviewed your V3. Thanks for your work!

So this patch can be stopped.

Gerhard

reviewer
#3 lore raw
Quoted 41 lines · Gerhard Engleder
Quoted 40 lines · Simon Horman

+ Vadim

Quoted 25 lines · Gerhard Engleder

From: Vladimir Oltean <[email protected]>

I took over this patch from Vladimir Oltean. The only change from my side is the adaption of the commit message. I hope I mentioned his work correctly in the tags.

New timestamping API was introduced in commit 66f7223039c0 ("net: add NDOs for configuring hardware timestamping") from kernel v6.6.

It is time to convert the tsnep driver to the new API, so that timestamping configuration can be removed from the ndo_eth_ioctl() path completely.

The driver does not need the interface to be down in order for timestamping to be changed. Thus, the netif_running() restriction in tsnep_netdev_ioctl() is not migrated to the new API. There is no interaction with hardware registers for either operation, just a concurrency with the data path which is fine.

After removing the PHY timestamping logic from tsnep_netdev_ioctl(), the rest is almost equivalent to phy_do_ioctl_running(), except for the return code on the !netif_running() condition: -EINVAL vs -ENODEV. Let's make the conversion to phy_do_ioctl_running() anyway, on the premise that a return code standardized tree-wide is less complex.

Quoted 3 lines

Hi Gerhard, Vladimir, Vadim, all,

Recently Vadim has been working on converting a number of drivers to use ndo_hwtstamp_get() and ndo_hwtstamp_set(). And this includes a patch, rather similar to this one, for the tsnep [1].

I think it would be good to agree on the way forward here.

Quoted 7 lines
Quoted 1 line

[1] https://lore.kernel.org/all/[email protected]/

I already replied to Vadim, but on the first patch version, not on V3.

@Vadim: I reviewed your V3. Thanks for your work!

So this patch can be stopped.

Thanks for the clarification, much appreciated.