All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
To: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Stephane Grosjean <s.grosjean@peak-system.com>,
	Jimmy Assarsson <extja@kvaser.com>,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	Dario Binacchi <dario.binacchi@amarulasolutions.com>,
	Max Staudt <max@enpas.org>,
	Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Subject: [PATCH v4 14/14] can: peak_usb: advertise timestamping capabilities and add ioctl support
Date: Wed, 27 Jul 2022 19:16:41 +0900	[thread overview]
Message-ID: <20220727101641.198847-15-mailhol.vincent@wanadoo.fr> (raw)
In-Reply-To: <20220727101641.198847-1-mailhol.vincent@wanadoo.fr>

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

The canonical way to add hardware timestamp support is to implement
ethtool_ops::get_ts_info() in order to advertise the timestamping
capabilities and to implement net_device_ops::ndo_eth_ioctl() as
requested in [1]. Currently, the driver only supports hardware RX
timestamps [2] but not hardware TX. For this reason, the generic
function can_ethtool_op_get_ts_info_hwts() and can_eth_ioctl_hwts()
can not be reused and instead this patch adds pcan_get_ts_info() and
peak_eth_ioctl().

[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

[2] https://lore.kernel.org/linux-can/20220727080634.l6uttnbrmwbabh3o@pengutronix.de/

CC: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c      |  1 +
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 41 ++++++++++++++++++++
 drivers/net/can/usb/peak_usb/pcan_usb_core.h |  1 +
 drivers/net/can/usb/peak_usb/pcan_usb_fd.c   |  1 +
 drivers/net/can/usb/peak_usb/pcan_usb_pro.c  |  1 +
 5 files changed, 45 insertions(+)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index d07b7ee79e3e..687dd542f7f6 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 = pcan_get_ts_info,
 };
 
 /*
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..8c9d53f6e24c 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,54 @@ static int peak_usb_set_data_bittiming(struct net_device *netdev)
 	return 0;
 }
 
+static int peak_eth_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
+{
+	struct hwtstamp_config hwts_cfg = { 0 };
+
+	switch (cmd) {
+	case SIOCSHWTSTAMP: /* set */
+		if (copy_from_user(&hwts_cfg, ifr->ifr_data, sizeof(hwts_cfg)))
+			return -EFAULT;
+		if (hwts_cfg.tx_type == HWTSTAMP_TX_OFF &&
+		    hwts_cfg.rx_filter == HWTSTAMP_FILTER_ALL)
+			return 0;
+		return -ERANGE;
+
+	case SIOCGHWTSTAMP: /* get */
+		hwts_cfg.tx_type = HWTSTAMP_TX_OFF;
+		hwts_cfg.rx_filter = HWTSTAMP_FILTER_ALL;
+		if (copy_to_user(ifr->ifr_data, &hwts_cfg, sizeof(hwts_cfg)))
+			return -EFAULT;
+		return 0;
+
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
 static const struct net_device_ops peak_usb_netdev_ops = {
 	.ndo_open = peak_usb_ndo_open,
 	.ndo_stop = peak_usb_ndo_stop,
+	.ndo_eth_ioctl = peak_eth_ioctl,
 	.ndo_start_xmit = peak_usb_ndo_start_xmit,
 	.ndo_change_mtu = can_change_mtu,
 };
 
+int pcan_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
+{
+	info->so_timestamping =
+		SOF_TIMESTAMPING_TX_SOFTWARE |
+		SOF_TIMESTAMPING_RX_SOFTWARE |
+		SOF_TIMESTAMPING_SOFTWARE |
+		SOF_TIMESTAMPING_RX_HARDWARE |
+		SOF_TIMESTAMPING_RAW_HARDWARE;
+	info->phc_index = -1;
+	info->tx_types = BIT(HWTSTAMP_TX_OFF);
+	info->rx_filters = BIT(HWTSTAMP_FILTER_ALL);
+
+	return 0;
+}
+
 /*
  * create one device which is attached to CAN controller #ctrl_idx of the
  * usb adapter.
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..f6bdd8b3f290 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
@@ -145,5 +145,6 @@ int peak_usb_netif_rx(struct sk_buff *skb,
 int peak_usb_netif_rx_64(struct sk_buff *skb, u32 ts_low, u32 ts_high);
 void peak_usb_async_complete(struct urb *urb);
 void peak_usb_restart_complete(struct peak_usb_device *dev);
+int pcan_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info);
 
 #endif
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..2ea1500df393 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 = pcan_get_ts_info,
 };
 
 /* describes the PCAN-USB FD adapter */
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..5d8f6a40bb2c 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 = pcan_get_ts_info,
 };
 
 /*
-- 
2.35.1


  parent reply	other threads:[~2022-07-27 10:17 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-25 13:31 [PATCH v1 00/24] can: add ethtool support and reporting of timestamping capabilities Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 01/24] can: can327: use KBUILD_MODNAME instead of hard coded name Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 02/24] can: ems_ubs: " Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 03/24] can: slcan: add DRV_NAME and define pr_fmt to replace hardcoded names Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 04/24] can: softing: add DRV_NAME " Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 05/24] can: esd_usb: use KBUILD_MODNAME instead of hard coded name Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 06/24] can: gs_ubs: " Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 07/24] can: softing: add DRV_NAME to replace hardcoded names Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 08/24] can: ubs_8dev: use KBUILD_MODNAME instead of hard coded name Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 09/24] can: etas_es58x: remove DRV_VERSION Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 10/24] can: tree-wide: implement ethtool_ops::get_drvinfo() Vincent Mailhol
2022-07-25 14:09   ` Marc Kleine-Budde
2022-07-25 14:29     ` Vincent MAILHOL
2022-07-26  7:29   ` Dario Binacchi
2022-07-26  8:42     ` Vincent MAILHOL
2022-07-26  9:21       ` Dario Binacchi
2022-07-26  9:59         ` Vincent MAILHOL
2022-07-27  8:19           ` Marc Kleine-Budde
2022-07-27  9:05             ` Vincent MAILHOL
2022-07-27 11:19               ` Marc Kleine-Budde
2022-07-25 13:31 ` [PATCH v1 11/24] can: can327: add software tx timestamps Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 12/24] can: janz-ican3: add software tx timestamp Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 13/24] can: slcan: add software tx timestamps Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 14/24] can: v(x)can: " Vincent Mailhol
2022-07-25 13:31 ` [PATCH v1 15/24] can: tree-wide: advertise software timestamping capabilities Vincent Mailhol
2022-07-25 13:32 ` [PATCH v1 16/24] can: dev: add hardware TX timestamp Vincent Mailhol
2022-07-25 13:32 ` [PATCH v1 17/24] can: dev: add generic function can_ethtool_op_get_ts_info_hwts() Vincent Mailhol
2022-07-25 13:32 ` [PATCH v1 18/24] can: dev: add generic function can_eth_ioctl_hwts() Vincent Mailhol
2022-07-25 14:22   ` Marc Kleine-Budde
2022-07-25 14:41     ` Vincent MAILHOL
2022-07-25 16:19       ` Marc Kleine-Budde
2022-07-25 13:32 ` [PATCH v1 19/24] can: mcp251xfd: advertise timestamping capabilities and add ioctl support Vincent Mailhol
2022-07-25 13:32 ` [PATCH v1 20/24] can: etas_es58x: " Vincent Mailhol
2022-07-25 13:32 ` [PATCH v1 21/24] can: kvaser_pciefd: " Vincent Mailhol
2022-07-25 13:32 ` [PATCH v1 22/24] can: kvaser_usb: " Vincent Mailhol
2022-07-25 13:32 ` [PATCH v1 23/24] can: peak_canfd: " Vincent Mailhol
2022-07-25 13:32 ` [PATCH v1 24/24] can: peak_usb: " Vincent Mailhol
2022-07-25 13:53 ` [PATCH v1 00/24] can: add ethtool support and reporting of timestamping capabilities Vincent MAILHOL
2022-07-25 15:53 ` [PATCH v2 00/14] " Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 01/14] can: can327: add software tx timestamps Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 02/14] can: janz-ican3: add software tx timestamp Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 03/14] can: slcan: add software tx timestamps Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 04/14] can: v(x)can: " Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 05/14] can: tree-wide: advertise software timestamping capabilities Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 06/14] can: dev: add hardware TX timestamp Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 07/14] can: dev: add generic function can_ethtool_op_get_ts_info_hwts() Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 08/14] can: dev: add generic function can_eth_ioctl_hwts() Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 09/14] can: mcp251xfd: advertise timestamping capabilities and add ioctl support Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 10/14] can: etas_es58x: " Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 11/14] can: kvaser_pciefd: " Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 12/14] can: kvaser_usb: " Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 13/14] can: peak_canfd: " Vincent Mailhol
2022-07-25 15:53   ` [PATCH v2 14/14] can: peak_usb: " Vincent Mailhol
2022-07-26 10:24 ` [PATCH v3 00/14] Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 01/14] can: can327: add software tx timestamps Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 02/14] can: janz-ican3: add software tx timestamp Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 03/14] can: slcan: add software tx timestamps Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 04/14] can: v(x)can: " Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 05/14] can: tree-wide: advertise software timestamping capabilities Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 06/14] can: dev: add hardware TX timestamp Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 07/14] can: dev: add generic function can_ethtool_op_get_ts_info_hwts() Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 08/14] can: dev: add generic function can_eth_ioctl_hwts() Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 09/14] can: mcp251xfd: advertise timestamping capabilities and add ioctl support Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 10/14] can: etas_es58x: " Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 11/14] can: kvaser_pciefd: " Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 12/14] can: kvaser_usb: " Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 13/14] can: peak_canfd: " Vincent Mailhol
2022-07-26 10:24   ` [PATCH v3 14/14] can: peak_usb: " Vincent Mailhol
2022-07-27  8:06     ` Marc Kleine-Budde
2022-07-27  8:29       ` Vincent MAILHOL
2022-07-27  8:42         ` Marc Kleine-Budde
2022-07-27  9:17           ` Vincent MAILHOL
2022-07-27 10:16 ` [PATCH v4 00/14] can: add ethtool support and reporting of timestamping capabilities Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 01/14] can: can327: add software tx timestamps Vincent Mailhol
2022-07-27 20:24     ` Max Staudt
2022-07-27 10:16   ` [PATCH v4 02/14] can: janz-ican3: add software tx timestamp Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 03/14] can: slcan: add software tx timestamps Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 04/14] can: v(x)can: " Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 05/14] can: tree-wide: advertise software timestamping capabilities Vincent Mailhol
2022-07-28  9:38     ` Marc Kleine-Budde
2022-07-28 13:28       ` Vincent MAILHOL
2022-07-28 13:35         ` Marc Kleine-Budde
2022-07-27 10:16   ` [PATCH v4 06/14] can: dev: add hardware TX timestamp Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 07/14] can: dev: add generic function can_ethtool_op_get_ts_info_hwts() Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 08/14] can: dev: add generic function can_eth_ioctl_hwts() Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 09/14] can: mcp251xfd: advertise timestamping capabilities and add ioctl support Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 10/14] can: etas_es58x: " Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 11/14] can: kvaser_pciefd: " Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 12/14] can: kvaser_usb: " Vincent Mailhol
2022-07-27 10:16   ` [PATCH v4 13/14] can: peak_canfd: " Vincent Mailhol
2022-07-27 10:16   ` Vincent Mailhol [this message]
2022-07-28 10:09   ` [PATCH v4 00/14] can: add ethtool support and reporting of timestamping capabilities Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220727101641.198847-15-mailhol.vincent@wanadoo.fr \
    --to=mailhol.vincent@wanadoo.fr \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=extja@kvaser.com \
    --cc=linux-can@vger.kernel.org \
    --cc=max@enpas.org \
    --cc=mkl@pengutronix.de \
    --cc=s.grosjean@peak-system.com \
    --cc=socketcan@hartkopp.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.