From: Jimmy Assarsson <extja@kvaser.com>
To: linux-can@vger.kernel.org
Cc: Jimmy Assarsson <jimmyassarsson@gmail.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
Jimmy Assarsson <extja@kvaser.com>
Subject: [PATCH can-next v2 09/15] can: kvaser_usb: leaf: Add hardware timestamp support to leaf based devices
Date: Mon, 1 Jul 2024 17:49:30 +0200 [thread overview]
Message-ID: <20240701154936.92633-10-extja@kvaser.com> (raw)
In-Reply-To: <20240701154936.92633-1-extja@kvaser.com>
Add hardware timestamp support to leaf based devices (M32C and leafimx).
Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
---
Changes in v2:
- Utilize new helper functions, from
can: kvaser_usb: Add helper functions to convert device timestamp into ktime
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 11 +++++++----
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 15 +++++++++++++++
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
index daa34b532aa8..b5d762d38d5d 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
@@ -106,14 +106,16 @@ static const struct kvaser_usb_driver_info kvaser_usb_driver_info_usbcan = {
};
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf = {
- .quirks = KVASER_USB_QUIRK_IGNORE_CLK_FREQ,
+ .quirks = KVASER_USB_QUIRK_IGNORE_CLK_FREQ |
+ KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP,
.family = KVASER_LEAF,
.ops = &kvaser_usb_leaf_dev_ops,
};
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err = {
.quirks = KVASER_USB_QUIRK_HAS_TXRX_ERRORS |
- KVASER_USB_QUIRK_IGNORE_CLK_FREQ,
+ KVASER_USB_QUIRK_IGNORE_CLK_FREQ |
+ KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP,
.family = KVASER_LEAF,
.ops = &kvaser_usb_leaf_dev_ops,
};
@@ -121,13 +123,14 @@ static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err = {
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err_listen = {
.quirks = KVASER_USB_QUIRK_HAS_TXRX_ERRORS |
KVASER_USB_QUIRK_HAS_SILENT_MODE |
- KVASER_USB_QUIRK_IGNORE_CLK_FREQ,
+ KVASER_USB_QUIRK_IGNORE_CLK_FREQ |
+ KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP,
.family = KVASER_LEAF,
.ops = &kvaser_usb_leaf_dev_ops,
};
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leafimx = {
- .quirks = 0,
+ .quirks = KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP,
.family = KVASER_LEAF,
.ops = &kvaser_usb_leaf_dev_ops,
};
diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
index caef1f26a95c..5839333eb5ae 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
@@ -915,6 +915,8 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev,
struct kvaser_usb_net_priv *priv;
unsigned long flags;
u8 channel, tid;
+ struct sk_buff *skb;
+ ktime_t hwtstamp = 0;
channel = cmd->u.tx_acknowledge_header.channel;
tid = cmd->u.tx_acknowledge_header.tid;
@@ -954,9 +956,19 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev,
priv->can.state = CAN_STATE_ERROR_ACTIVE;
}
+ switch (dev->driver_info->family) {
+ case KVASER_LEAF:
+ hwtstamp = kvaser_usb_timestamp48_to_ktime(dev->cfg, cmd->u.leaf.tx_ack.time);
+ break;
+ case KVASER_USBCAN:
+ break;
+ }
spin_lock_irqsave(&priv->tx_contexts_lock, flags);
+ skb = priv->can.echo_skb[context->echo_index];
+ if (skb)
+ skb_hwtstamps(skb)->hwtstamp = hwtstamp;
stats->tx_packets++;
stats->tx_bytes += can_get_echo_skb(priv->netdev,
context->echo_index, NULL);
@@ -1334,6 +1346,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,
struct net_device_stats *stats;
u8 channel = cmd->u.rx_can_header.channel;
const u8 *rx_data = NULL; /* GCC */
+ ktime_t hwtstamp = 0;
if (channel >= dev->nchannels) {
dev_err(&dev->intf->dev,
@@ -1364,6 +1377,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,
switch (dev->driver_info->family) {
case KVASER_LEAF:
rx_data = cmd->u.leaf.rx_can.data;
+ hwtstamp = kvaser_usb_timestamp48_to_ktime(dev->cfg, cmd->u.leaf.rx_can.time);
break;
case KVASER_USBCAN:
rx_data = cmd->u.usbcan.rx_can.data;
@@ -1410,6 +1424,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,
memcpy(cf->data, &rx_data[6], cf->len);
}
+ skb_hwtstamps(skb)->hwtstamp = hwtstamp;
stats->rx_packets++;
if (!(cf->can_id & CAN_RTR_FLAG))
stats->rx_bytes += cf->len;
--
2.45.2
next prev parent reply other threads:[~2024-07-01 15:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-01 15:49 [PATCH can-next v2 00/15] can: kvaser_usb: Add hardware timestamp support to all devices Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 01/15] can: kvaser_usb: Add helper functions to convert device timestamp into ktime Jimmy Assarsson
2024-07-02 4:47 ` Vincent MAILHOL
2024-07-02 19:37 ` Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 02/15] can: kvaser_usb: hydra: kvaser_usb_hydra_ktime_from_rx_cmd: Drop {rx_} in function name Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 03/15] can: kvaser_usb: hydra: Add struct for Tx ACK commands Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 04/15] can: kvaser_usb: hydra: Set hardware timestamp on transmitted packets Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 05/15] can: kvaser_usb: leaf: Add struct for Tx ACK commands Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 06/15] can: kvaser_usb: leaf: Assign correct timestamp_freq for kvaser_usb_leaf_imx_dev_cfg_{16,24,32}mhz Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 07/15] can: kvaser_usb: leaf: Replace kvaser_usb_leaf_m32c_dev_cfg with kvaser_usb_leaf_m32c_dev_cfg_{16,24,32}mhz Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 08/15] can: kvaser_usb: leaf: kvaser_usb_leaf_tx_acknowledge: Rename local variable Jimmy Assarsson
2024-07-01 15:49 ` Jimmy Assarsson [this message]
2024-07-01 15:49 ` [PATCH can-next v2 10/15] can: kvaser_usb: leaf: Add structs for Tx ACK and clock overflow commands Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 11/15] can: kvaser_usb: leaf: Store MSB of timestamp Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 12/15] can: kvaser_usb: leaf: Add hardware timestamp support to usbcan devices Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 13/15] can: kvaser_usb: Remove KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 14/15] can: kvaser_usb: Remove struct variables kvaser_usb_{ethtool,netdev}_ops Jimmy Assarsson
2024-07-01 15:49 ` [PATCH can-next v2 15/15] can: kvaser_usb: Rename kvaser_usb_{ethtool,netdev}_ops_hwts to kvaser_usb_{ethtool,netdev}_ops Jimmy Assarsson
2024-07-02 4:52 ` [PATCH can-next v2 00/15] can: kvaser_usb: Add hardware timestamp support to all devices Vincent MAILHOL
2024-07-02 19:37 ` Jimmy Assarsson
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=20240701154936.92633-10-extja@kvaser.com \
--to=extja@kvaser.com \
--cc=jimmyassarsson@gmail.com \
--cc=linux-can@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox