Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: convert generic HW timestamp ioctl to ndo_hwtstamp callbacks

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>

authored by

Vadim Fedorenko and committed by
Marc Kleine-Budde
4f6b0435 ea7d0d60

+54 -32
+22 -23
drivers/net/can/dev/dev.c
··· 379 379 } 380 380 EXPORT_SYMBOL_GPL(can_set_static_ctrlmode); 381 381 382 - /* generic implementation of netdev_ops::ndo_eth_ioctl for CAN devices 382 + /* generic implementation of netdev_ops::ndo_hwtstamp_get for CAN devices 383 383 * supporting hardware timestamps 384 384 */ 385 - int can_eth_ioctl_hwts(struct net_device *netdev, struct ifreq *ifr, int cmd) 385 + int can_hwtstamp_get(struct net_device *netdev, 386 + struct kernel_hwtstamp_config *cfg) 386 387 { 387 - struct hwtstamp_config hwts_cfg = { 0 }; 388 + cfg->tx_type = HWTSTAMP_TX_ON; 389 + cfg->rx_filter = HWTSTAMP_FILTER_ALL; 388 390 389 - switch (cmd) { 390 - case SIOCSHWTSTAMP: /* set */ 391 - if (copy_from_user(&hwts_cfg, ifr->ifr_data, sizeof(hwts_cfg))) 392 - return -EFAULT; 393 - if (hwts_cfg.tx_type == HWTSTAMP_TX_ON && 394 - hwts_cfg.rx_filter == HWTSTAMP_FILTER_ALL) 395 - return 0; 396 - return -ERANGE; 397 - 398 - case SIOCGHWTSTAMP: /* get */ 399 - hwts_cfg.tx_type = HWTSTAMP_TX_ON; 400 - hwts_cfg.rx_filter = HWTSTAMP_FILTER_ALL; 401 - if (copy_to_user(ifr->ifr_data, &hwts_cfg, sizeof(hwts_cfg))) 402 - return -EFAULT; 403 - return 0; 404 - 405 - default: 406 - return -EOPNOTSUPP; 407 - } 391 + return 0; 408 392 } 409 - EXPORT_SYMBOL(can_eth_ioctl_hwts); 393 + EXPORT_SYMBOL(can_hwtstamp_get); 394 + 395 + /* generic implementation of netdev_ops::ndo_hwtstamp_set for CAN devices 396 + * supporting hardware timestamps 397 + */ 398 + int can_hwtstamp_set(struct net_device *netdev, 399 + struct kernel_hwtstamp_config *cfg, 400 + struct netlink_ext_ack *extack) 401 + { 402 + if (cfg->tx_type == HWTSTAMP_TX_ON && 403 + cfg->rx_filter == HWTSTAMP_FILTER_ALL) 404 + return 0; 405 + NL_SET_ERR_MSG_MOD(extack, "Only TX on and RX all packets filter supported"); 406 + return -ERANGE; 407 + } 408 + EXPORT_SYMBOL(can_hwtstamp_set); 410 409 411 410 /* generic implementation of ethtool_ops::get_ts_info for CAN devices 412 411 * supporting hardware timestamps
+2 -1
drivers/net/can/esd/esd_402_pci-core.c
··· 86 86 .ndo_open = acc_open, 87 87 .ndo_stop = acc_close, 88 88 .ndo_start_xmit = acc_start_xmit, 89 - .ndo_eth_ioctl = can_eth_ioctl_hwts, 89 + .ndo_hwtstamp_get = can_hwtstamp_get, 90 + .ndo_hwtstamp_set = can_hwtstamp_set, 90 91 }; 91 92 92 93 static const struct ethtool_ops pci402_acc_ethtool_ops = {
+2 -1
drivers/net/can/kvaser_pciefd/kvaser_pciefd_core.c
··· 902 902 static const struct net_device_ops kvaser_pciefd_netdev_ops = { 903 903 .ndo_open = kvaser_pciefd_open, 904 904 .ndo_stop = kvaser_pciefd_stop, 905 - .ndo_eth_ioctl = can_eth_ioctl_hwts, 906 905 .ndo_start_xmit = kvaser_pciefd_start_xmit, 906 + .ndo_hwtstamp_get = can_hwtstamp_get, 907 + .ndo_hwtstamp_set = can_hwtstamp_set, 907 908 }; 908 909 909 910 static int kvaser_pciefd_set_phys_id(struct net_device *netdev,
+2 -1
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
··· 1714 1714 .ndo_open = mcp251xfd_open, 1715 1715 .ndo_stop = mcp251xfd_stop, 1716 1716 .ndo_start_xmit = mcp251xfd_start_xmit, 1717 - .ndo_eth_ioctl = can_eth_ioctl_hwts, 1717 + .ndo_hwtstamp_get = can_hwtstamp_get, 1718 + .ndo_hwtstamp_set = can_hwtstamp_set, 1718 1719 }; 1719 1720 1720 1721 static void
+2 -1
drivers/net/can/usb/etas_es58x/es58x_core.c
··· 1976 1976 .ndo_open = es58x_open, 1977 1977 .ndo_stop = es58x_stop, 1978 1978 .ndo_start_xmit = es58x_start_xmit, 1979 - .ndo_eth_ioctl = can_eth_ioctl_hwts, 1979 + .ndo_hwtstamp_get = can_hwtstamp_get, 1980 + .ndo_hwtstamp_set = can_hwtstamp_set, 1980 1981 }; 1981 1982 1982 1983 static const struct ethtool_ops es58x_ethtool_ops = {
+17 -3
drivers/net/can/usb/gs_usb.c
··· 1087 1087 return 0; 1088 1088 } 1089 1089 1090 - static int gs_can_eth_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) 1090 + static int gs_can_hwtstamp_get(struct net_device *netdev, 1091 + struct kernel_hwtstamp_config *cfg) 1091 1092 { 1092 1093 const struct gs_can *dev = netdev_priv(netdev); 1093 1094 1094 1095 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1095 - return can_eth_ioctl_hwts(netdev, ifr, cmd); 1096 + return can_hwtstamp_get(netdev, cfg); 1097 + 1098 + return -EOPNOTSUPP; 1099 + } 1100 + 1101 + static int gs_can_hwtstamp_set(struct net_device *netdev, 1102 + struct kernel_hwtstamp_config *cfg, 1103 + struct netlink_ext_ack *extack) 1104 + { 1105 + const struct gs_can *dev = netdev_priv(netdev); 1106 + 1107 + if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) 1108 + return can_hwtstamp_set(netdev, cfg, extack); 1096 1109 1097 1110 return -EOPNOTSUPP; 1098 1111 } ··· 1114 1101 .ndo_open = gs_can_open, 1115 1102 .ndo_stop = gs_can_close, 1116 1103 .ndo_start_xmit = gs_can_start_xmit, 1117 - .ndo_eth_ioctl = gs_can_eth_ioctl, 1104 + .ndo_hwtstamp_get = gs_can_hwtstamp_get, 1105 + .ndo_hwtstamp_set = gs_can_hwtstamp_set, 1118 1106 }; 1119 1107 1120 1108 static int gs_usb_set_identify(struct net_device *netdev, bool do_identify)
+2 -1
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
··· 784 784 static const struct net_device_ops kvaser_usb_netdev_ops = { 785 785 .ndo_open = kvaser_usb_open, 786 786 .ndo_stop = kvaser_usb_close, 787 - .ndo_eth_ioctl = can_eth_ioctl_hwts, 788 787 .ndo_start_xmit = kvaser_usb_start_xmit, 788 + .ndo_hwtstamp_get = can_hwtstamp_get, 789 + .ndo_hwtstamp_set = can_hwtstamp_set, 789 790 }; 790 791 791 792 static const struct ethtool_ops kvaser_usb_ethtool_ops = {
+5 -1
include/linux/can/dev.h
··· 129 129 void can_set_default_mtu(struct net_device *dev); 130 130 int __must_check can_set_static_ctrlmode(struct net_device *dev, 131 131 u32 static_mode); 132 - int can_eth_ioctl_hwts(struct net_device *netdev, struct ifreq *ifr, int cmd); 132 + int can_hwtstamp_get(struct net_device *netdev, 133 + struct kernel_hwtstamp_config *cfg); 134 + int can_hwtstamp_set(struct net_device *netdev, 135 + struct kernel_hwtstamp_config *cfg, 136 + struct netlink_ext_ack *extack); 133 137 int can_ethtool_op_get_ts_info_hwts(struct net_device *dev, 134 138 struct kernel_ethtool_ts_info *info); 135 139