]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
can: convert generic HW timestamp ioctl to ndo_hwtstamp callbacks
authorVadim Fedorenko <vadim.fedorenko@linux.dev>
Wed, 29 Oct 2025 23:16:18 +0000 (23:16 +0000)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Fri, 31 Oct 2025 12:12:18 +0000 (13:12 +0100)
Can has generic implementation of ndo_eth_ioctl which implements only HW
timestamping commands. Implement generic ndo_hwtstamp callbacks and use
it in drivers instead of generic ioctl interface.

Signed-off-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Reviewed-by: Kory Maincent <kory.maincent@bootlin.com>
Reviewed-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20251029231620.1135640-2-vadim.fedorenko@linux.dev
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/dev/dev.c
drivers/net/can/esd/esd_402_pci-core.c
drivers/net/can/kvaser_pciefd/kvaser_pciefd_core.c
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
drivers/net/can/usb/etas_es58x/es58x_core.c
drivers/net/can/usb/gs_usb.c
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
include/linux/can/dev.h

index 0cc3d008adb350cdaf25ca947f85a05fa82f67ae..80e1ab18de876120ab4ca30c00e2fbe86b1b88a4 100644 (file)
@@ -379,34 +379,33 @@ int can_set_static_ctrlmode(struct net_device *dev, u32 static_mode)
 }
 EXPORT_SYMBOL_GPL(can_set_static_ctrlmode);
 
-/* generic implementation of netdev_ops::ndo_eth_ioctl for CAN devices
+/* generic implementation of netdev_ops::ndo_hwtstamp_get for CAN devices
  * supporting hardware timestamps
  */
-int can_eth_ioctl_hwts(struct net_device *netdev, struct ifreq *ifr, int cmd)
+int can_hwtstamp_get(struct net_device *netdev,
+                    struct kernel_hwtstamp_config *cfg)
 {
-       struct hwtstamp_config hwts_cfg = { 0 };
-
-       switch (cmd) {
-       case SIOCSHWTSTAMP: /* set */
-               if (copy_from_user(&hwts_cfg, ifr->ifr_data, sizeof(hwts_cfg)))
-                       return -EFAULT;
-               if (hwts_cfg.tx_type == HWTSTAMP_TX_ON &&
-                   hwts_cfg.rx_filter == HWTSTAMP_FILTER_ALL)
-                       return 0;
-               return -ERANGE;
-
-       case SIOCGHWTSTAMP: /* get */
-               hwts_cfg.tx_type = HWTSTAMP_TX_ON;
-               hwts_cfg.rx_filter = HWTSTAMP_FILTER_ALL;
-               if (copy_to_user(ifr->ifr_data, &hwts_cfg, sizeof(hwts_cfg)))
-                       return -EFAULT;
-               return 0;
+       cfg->tx_type = HWTSTAMP_TX_ON;
+       cfg->rx_filter = HWTSTAMP_FILTER_ALL;
 
-       default:
-               return -EOPNOTSUPP;
-       }
+       return 0;
+}
+EXPORT_SYMBOL(can_hwtstamp_get);
+
+/* generic implementation of netdev_ops::ndo_hwtstamp_set for CAN devices
+ * supporting hardware timestamps
+ */
+int can_hwtstamp_set(struct net_device *netdev,
+                    struct kernel_hwtstamp_config *cfg,
+                    struct netlink_ext_ack *extack)
+{
+       if (cfg->tx_type == HWTSTAMP_TX_ON &&
+           cfg->rx_filter == HWTSTAMP_FILTER_ALL)
+               return 0;
+       NL_SET_ERR_MSG_MOD(extack, "Only TX on and RX all packets filter supported");
+       return -ERANGE;
 }
-EXPORT_SYMBOL(can_eth_ioctl_hwts);
+EXPORT_SYMBOL(can_hwtstamp_set);
 
 /* generic implementation of ethtool_ops::get_ts_info for CAN devices
  * supporting hardware timestamps
index 05adecae63757b80b2b419e5831d0d7a671ae545..c826f00c551b4cef49da85774c634bcd0fdbdddf 100644 (file)
@@ -86,7 +86,8 @@ static const struct net_device_ops pci402_acc_netdev_ops = {
        .ndo_open = acc_open,
        .ndo_stop = acc_close,
        .ndo_start_xmit = acc_start_xmit,
-       .ndo_eth_ioctl = can_eth_ioctl_hwts,
+       .ndo_hwtstamp_get = can_hwtstamp_get,
+       .ndo_hwtstamp_set = can_hwtstamp_set,
 };
 
 static const struct ethtool_ops pci402_acc_ethtool_ops = {
index 705f9bb74cd23c9c6a5f34fd7c0f7a529d0535d0..d8c9bfb202304ed0e211589f6f60213bcc8b6d01 100644 (file)
@@ -902,8 +902,9 @@ static void kvaser_pciefd_bec_poll_timer(struct timer_list *data)
 static const struct net_device_ops kvaser_pciefd_netdev_ops = {
        .ndo_open = kvaser_pciefd_open,
        .ndo_stop = kvaser_pciefd_stop,
-       .ndo_eth_ioctl = can_eth_ioctl_hwts,
        .ndo_start_xmit = kvaser_pciefd_start_xmit,
+       .ndo_hwtstamp_get = can_hwtstamp_get,
+       .ndo_hwtstamp_set = can_hwtstamp_set,
 };
 
 static int kvaser_pciefd_set_phys_id(struct net_device *netdev,
index 9402530ba3d48beaa59ccefb929a4fd35290bd01..c0f9d9fed02e3b90404d52b22f3aafae3802c817 100644 (file)
@@ -1714,7 +1714,8 @@ static const struct net_device_ops mcp251xfd_netdev_ops = {
        .ndo_open = mcp251xfd_open,
        .ndo_stop = mcp251xfd_stop,
        .ndo_start_xmit = mcp251xfd_start_xmit,
-       .ndo_eth_ioctl = can_eth_ioctl_hwts,
+       .ndo_hwtstamp_get = can_hwtstamp_get,
+       .ndo_hwtstamp_set = can_hwtstamp_set,
 };
 
 static void
index 47d9e03f304495db90e7d69bd135aaaa4a8d01ed..f799233c2b72c4fca300e5edfd5082aeafda74b0 100644 (file)
@@ -1976,7 +1976,8 @@ static const struct net_device_ops es58x_netdev_ops = {
        .ndo_open = es58x_open,
        .ndo_stop = es58x_stop,
        .ndo_start_xmit = es58x_start_xmit,
-       .ndo_eth_ioctl = can_eth_ioctl_hwts,
+       .ndo_hwtstamp_get = can_hwtstamp_get,
+       .ndo_hwtstamp_set = can_hwtstamp_set,
 };
 
 static const struct ethtool_ops es58x_ethtool_ops = {
index 30608901a974801b65f4e2be164b4e3d91f1a751..1321eb5e89ae5de1635635dfa9c4f1c9b959c118 100644 (file)
@@ -1087,12 +1087,25 @@ static int gs_can_close(struct net_device *netdev)
        return 0;
 }
 
-static int gs_can_eth_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
+static int gs_can_hwtstamp_get(struct net_device *netdev,
+                              struct kernel_hwtstamp_config *cfg)
 {
        const struct gs_can *dev = netdev_priv(netdev);
 
        if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
-               return can_eth_ioctl_hwts(netdev, ifr, cmd);
+               return can_hwtstamp_get(netdev, cfg);
+
+       return -EOPNOTSUPP;
+}
+
+static int gs_can_hwtstamp_set(struct net_device *netdev,
+                              struct kernel_hwtstamp_config *cfg,
+                              struct netlink_ext_ack *extack)
+{
+       const struct gs_can *dev = netdev_priv(netdev);
+
+       if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
+               return can_hwtstamp_set(netdev, cfg, extack);
 
        return -EOPNOTSUPP;
 }
@@ -1101,7 +1114,8 @@ static const struct net_device_ops gs_usb_netdev_ops = {
        .ndo_open = gs_can_open,
        .ndo_stop = gs_can_close,
        .ndo_start_xmit = gs_can_start_xmit,
-       .ndo_eth_ioctl = gs_can_eth_ioctl,
+       .ndo_hwtstamp_get = gs_can_hwtstamp_get,
+       .ndo_hwtstamp_set = gs_can_hwtstamp_set,
 };
 
 static int gs_usb_set_identify(struct net_device *netdev, bool do_identify)
index 89e22b66f91929ac1785b18289cb7669cfa2aaef..62701ec34272ddca32711e8046117f3241c0cc87 100644 (file)
@@ -784,8 +784,9 @@ static int kvaser_usb_set_phys_id(struct net_device *netdev,
 static const struct net_device_ops kvaser_usb_netdev_ops = {
        .ndo_open = kvaser_usb_open,
        .ndo_stop = kvaser_usb_close,
-       .ndo_eth_ioctl = can_eth_ioctl_hwts,
        .ndo_start_xmit = kvaser_usb_start_xmit,
+       .ndo_hwtstamp_get = can_hwtstamp_get,
+       .ndo_hwtstamp_set = can_hwtstamp_set,
 };
 
 static const struct ethtool_ops kvaser_usb_ethtool_ops = {
index 0fe8f80f223e2f0320cb8bc947e463f7884a9ff5..bd7410b5d8a6738adfc6c8d1bf6544d87999fe59 100644 (file)
@@ -129,7 +129,11 @@ void close_candev(struct net_device *dev);
 void can_set_default_mtu(struct net_device *dev);
 int __must_check can_set_static_ctrlmode(struct net_device *dev,
                                         u32 static_mode);
-int can_eth_ioctl_hwts(struct net_device *netdev, struct ifreq *ifr, int cmd);
+int can_hwtstamp_get(struct net_device *netdev,
+                    struct kernel_hwtstamp_config *cfg);
+int can_hwtstamp_set(struct net_device *netdev,
+                    struct kernel_hwtstamp_config *cfg,
+                    struct netlink_ext_ack *extack);
 int can_ethtool_op_get_ts_info_hwts(struct net_device *dev,
                                    struct kernel_ethtool_ts_info *info);