Currently, userland has no method to query which timestamping features are supported by the peak_usb driver (aside maybe of getting RX messages and obseverse whever or not hardware timestamps stay at zero). The canonical way for a network driver to advertise what kind of timestamping it 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 CC: Stephane Grosjean <s.grosjean@xxxxxxxxxxxxxxx> Signed-off-by: Vincent Mailhol <mailhol.vincent@xxxxxxxxxx> --- Hi Stéphane, as far as I understand, the pcan_usb and the pacn_usb_pro support hardware timestamps but the pcan_usb_fd doesn't. If not the case, let me know. This is not tested. If you find any issue or if you want to modify, feel free to pick up that patch and resend it. --- drivers/net/can/usb/peak_usb/pcan_usb.c | 2 ++ drivers/net/can/usb/peak_usb/pcan_usb_core.c | 12 ++++++++++-- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 4 ++++ drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 2 ++ drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 2 ++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c index d07b7ee79e3e..23966d5d7825 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c @@ -965,6 +965,7 @@ static int pcan_usb_set_phys_id(struct net_device *netdev, static const struct ethtool_ops pcan_usb_ethtool_ops = { .set_phys_id = pcan_usb_set_phys_id, + .get_ts_info = can_ethtool_op_get_ts_info_hwts, }; /* @@ -996,6 +997,7 @@ const struct peak_usb_adapter pcan_usb = { /* size of device private data */ .sizeof_dev_private = sizeof(struct pcan_usb), + .netdev_ops = &pcan_usb_netdev_ops, .ethtool_ops = &pcan_usb_ethtool_ops, /* timestamps usage */ diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c index 27b0a72fd885..88d0505d3f8d 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c @@ -775,13 +775,21 @@ static int peak_usb_set_data_bittiming(struct net_device *netdev) return 0; } -static const struct net_device_ops peak_usb_netdev_ops = { +const struct net_device_ops pcan_usb_netdev_ops = { .ndo_open = peak_usb_ndo_open, .ndo_stop = peak_usb_ndo_stop, .ndo_start_xmit = peak_usb_ndo_start_xmit, .ndo_change_mtu = can_change_mtu, }; +const struct net_device_ops pcan_usb_netdev_ops_hwts = { + .ndo_open = peak_usb_ndo_open, + .ndo_stop = peak_usb_ndo_stop, + .ndo_eth_ioctl = can_eth_ioctl_hwts, + .ndo_start_xmit = peak_usb_ndo_start_xmit, + .ndo_change_mtu = can_change_mtu, +}; + /* * create one device which is attached to CAN controller #ctrl_idx of the * usb adapter. @@ -833,7 +841,7 @@ static int peak_usb_create_dev(const struct peak_usb_adapter *peak_usb_adapter, dev->can.do_get_berr_counter = peak_usb_adapter->do_get_berr_counter; dev->can.ctrlmode_supported = peak_usb_adapter->ctrlmode_supported; - netdev->netdev_ops = &peak_usb_netdev_ops; + netdev->netdev_ops = peak_usb_adapter->netdev_ops; netdev->flags |= IFF_ECHO; /* we support local echo */ diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h index 9c90487b9c92..a7412235d36f 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h @@ -46,6 +46,7 @@ struct peak_usb_adapter { const struct can_bittiming_const * const data_bittiming_const; unsigned int ctrl_count; + const struct net_device_ops *netdev_ops; const struct ethtool_ops *ethtool_ops; int (*intf_probe)(struct usb_interface *intf); @@ -88,6 +89,9 @@ extern const struct peak_usb_adapter pcan_usb_chip; extern const struct peak_usb_adapter pcan_usb_pro_fd; extern const struct peak_usb_adapter pcan_usb_x6; +extern const struct net_device_ops pcan_usb_netdev_ops; +extern const struct net_device_ops pcan_usb_netdev_ops_hwts; + struct peak_time_ref { ktime_t tv_host_0, tv_host; u32 ts_dev_1, ts_dev_2; diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index 3d7e0e370505..8560f82b0ab2 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c @@ -1080,6 +1080,7 @@ static int pcan_usb_fd_set_phys_id(struct net_device *netdev, static const struct ethtool_ops pcan_usb_fd_ethtool_ops = { .set_phys_id = pcan_usb_fd_set_phys_id, + .get_ts_info = ethtool_op_get_ts_info, }; /* describes the PCAN-USB FD adapter */ @@ -1123,6 +1124,7 @@ const struct peak_usb_adapter pcan_usb_fd = { /* size of device private data */ .sizeof_dev_private = sizeof(struct pcan_usb_fd_device), + .netdev_ops = &pcan_usb_netdev_ops_hwts, .ethtool_ops = &pcan_usb_fd_ethtool_ops, /* timestamps usage */ diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c index 457887113e75..13b2d82047c7 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c @@ -1022,6 +1022,7 @@ static int pcan_usb_pro_set_phys_id(struct net_device *netdev, static const struct ethtool_ops pcan_usb_pro_ethtool_ops = { .set_phys_id = pcan_usb_pro_set_phys_id, + .get_ts_info = can_ethtool_op_get_ts_info_hwts, }; /* @@ -1053,6 +1054,7 @@ const struct peak_usb_adapter pcan_usb_pro = { /* size of device private data */ .sizeof_dev_private = sizeof(struct pcan_usb_pro_device), + .netdev_ops = &pcan_usb_netdev_ops_hwts, .ethtool_ops = &pcan_usb_pro_ethtool_ops, /* timestamps usage */ -- 2.35.1