can: etas_es58x: advertise timestamping capabilities and add ioctl support
authorVincent Mailhol <mailhol.vincent@wanadoo.fr>
Wed, 27 Jul 2022 10:16:37 +0000 (19:16 +0900)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 28 Jul 2022 09:44:30 +0000 (11:44 +0200)
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>
drivers/net/can/usb/etas_es58x/es58x_core.c

index c22e989d42ff14fdc88806aced09855b110d8576..3b949e9795834457d5db7e00bb8b1e2a7cc95c71 100644 (file)
@@ -10,6 +10,7 @@
  * Copyright (c) 2020, 2021 Vincent Mailhol <mailhol.vincent@wanadoo.fr>
  */
 
+#include <linux/ethtool.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/usb.h>
@@ -1978,7 +1979,12 @@ static netdev_tx_t es58x_start_xmit(struct sk_buff *skb,
 static const struct net_device_ops es58x_netdev_ops = {
        .ndo_open = es58x_open,
        .ndo_stop = es58x_stop,
-       .ndo_start_xmit = es58x_start_xmit
+       .ndo_start_xmit = es58x_start_xmit,
+       .ndo_eth_ioctl = can_eth_ioctl_hwts,
+};
+
+static const struct ethtool_ops es58x_ethtool_ops = {
+       .get_ts_info = can_ethtool_op_get_ts_info_hwts,
 };
 
 /**
@@ -2085,6 +2091,7 @@ static int es58x_init_netdev(struct es58x_device *es58x_dev, int channel_idx)
        es58x_init_priv(es58x_dev, es58x_priv(netdev), channel_idx);
 
        netdev->netdev_ops = &es58x_netdev_ops;
+       netdev->ethtool_ops = &es58x_ethtool_ops;
        netdev->flags |= IFF_ECHO;      /* We support local echo */
        netdev->dev_port = channel_idx;