Skip to content

Commit 0a6e1bd

Browse files
vincent-mailholgregkh
authored andcommitted
can: dev: add generic function can_eth_ioctl_hwts()
[ Upstream commit 90f942c ] Tools based on libpcap (such as tcpdump) expect the SIOCSHWTSTAMP ioctl call to be supported. This is also specified in the kernel doc [1]. The purpose of this ioctl is to toggle the hardware timestamps. Currently, CAN devices which support hardware timestamping have those always activated. can_eth_ioctl_hwts() is a dumb function that will always succeed when requested to set tx_type to HWTSTAMP_TX_ON or rx_filter to HWTSTAMP_FILTER_ALL. [1] Kernel doc: Timestamping, section 3.1 "Hardware Timestamping Implementation: Device Drivers" Link: https://docs.kernel.org/networking/timestamping.html#hardware-timestamping-implementation-device-drivers Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Link: https://lore.kernel.org/all/20220727101641.198847-9-mailhol.vincent@wanadoo.fr Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Stable-dep-of: 38c0aba ("can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b9a0e6f commit 0a6e1bd

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

drivers/net/can/dev/dev.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,35 @@ int can_change_mtu(struct net_device *dev, int new_mtu)
331331
}
332332
EXPORT_SYMBOL_GPL(can_change_mtu);
333333

334+
/* generic implementation of netdev_ops::ndo_eth_ioctl for CAN devices
335+
* supporting hardware timestamps
336+
*/
337+
int can_eth_ioctl_hwts(struct net_device *netdev, struct ifreq *ifr, int cmd)
338+
{
339+
struct hwtstamp_config hwts_cfg = { 0 };
340+
341+
switch (cmd) {
342+
case SIOCSHWTSTAMP: /* set */
343+
if (copy_from_user(&hwts_cfg, ifr->ifr_data, sizeof(hwts_cfg)))
344+
return -EFAULT;
345+
if (hwts_cfg.tx_type == HWTSTAMP_TX_ON &&
346+
hwts_cfg.rx_filter == HWTSTAMP_FILTER_ALL)
347+
return 0;
348+
return -ERANGE;
349+
350+
case SIOCGHWTSTAMP: /* get */
351+
hwts_cfg.tx_type = HWTSTAMP_TX_ON;
352+
hwts_cfg.rx_filter = HWTSTAMP_FILTER_ALL;
353+
if (copy_to_user(ifr->ifr_data, &hwts_cfg, sizeof(hwts_cfg)))
354+
return -EFAULT;
355+
return 0;
356+
357+
default:
358+
return -EOPNOTSUPP;
359+
}
360+
}
361+
EXPORT_SYMBOL(can_eth_ioctl_hwts);
362+
334363
/* generic implementation of ethtool_ops::get_ts_info for CAN devices
335364
* supporting hardware timestamps
336365
*/

include/linux/can/dev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ struct can_priv *safe_candev_priv(struct net_device *dev);
133133
int open_candev(struct net_device *dev);
134134
void close_candev(struct net_device *dev);
135135
int can_change_mtu(struct net_device *dev, int new_mtu);
136+
int can_eth_ioctl_hwts(struct net_device *netdev, struct ifreq *ifr, int cmd);
136137
int can_ethtool_op_get_ts_info_hwts(struct net_device *dev,
137138
struct ethtool_ts_info *info);
138139

0 commit comments

Comments
 (0)