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

can: etas_es58x: advertise timestamping capabilities and add ioctl support

Currently, userland has no method to query which timestamping features
are supported by the etas_es58x driver (aside maybe of getting RX
messages and observe whether or not hardware timestamps stay at zero).

The canonical way for a network driver to advertise what kind of
timestamping is supports is to implement
ethtool_ops::get_ts_info(). Here, we use the CAN specific
can_ethtool_op_get_ts_info_hwts() function to achieve this.

In addition, the driver currently does not support the hardware
timestamps ioctls. According to [1], SIOCSHWTSTAMP is "must" and
SIOCGHWTSTAMP is "should". This patch fills up that gap by
implementing net_device_ops::ndo_eth_ioctl() using the CAN specific
function can_eth_ioctl_hwts().

[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-11-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
1d46efa0 b1f6b93e

+8 -1
+8 -1
drivers/net/can/usb/etas_es58x/es58x_core.c
··· 10 10 * Copyright (c) 2020, 2021 Vincent Mailhol <mailhol.vincent@wanadoo.fr> 11 11 */ 12 12 13 + #include <linux/ethtool.h> 13 14 #include <linux/kernel.h> 14 15 #include <linux/module.h> 15 16 #include <linux/usb.h> ··· 1979 1978 static const struct net_device_ops es58x_netdev_ops = { 1980 1979 .ndo_open = es58x_open, 1981 1980 .ndo_stop = es58x_stop, 1982 - .ndo_start_xmit = es58x_start_xmit 1981 + .ndo_start_xmit = es58x_start_xmit, 1982 + .ndo_eth_ioctl = can_eth_ioctl_hwts, 1983 + }; 1984 + 1985 + static const struct ethtool_ops es58x_ethtool_ops = { 1986 + .get_ts_info = can_ethtool_op_get_ts_info_hwts, 1983 1987 }; 1984 1988 1985 1989 /** ··· 2091 2085 es58x_init_priv(es58x_dev, es58x_priv(netdev), channel_idx); 2092 2086 2093 2087 netdev->netdev_ops = &es58x_netdev_ops; 2088 + netdev->ethtool_ops = &es58x_ethtool_ops; 2094 2089 netdev->flags |= IFF_ECHO; /* We support local echo */ 2095 2090 netdev->dev_port = channel_idx; 2096 2091