* [PATCH] can: peak_usb: CANFD: store 64-bits hw timestamps
@ 2021-09-30 9:46 Stephane Grosjean
2021-10-18 12:34 ` Marc Kleine-Budde
0 siblings, 1 reply; 2+ messages in thread
From: Stephane Grosjean @ 2021-09-30 9:46 UTC (permalink / raw)
To: linux-can Mailing List; +Cc: Stephane Grosjean
This patch allows to use the whole 64-bit timestamps received from the
CAN-FD device (expressed in µs) rather than only its low part, in the
hwtstamp structure of the skb transferred to the network layer, when a
CAN/CANFD frame has been received.
Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
---
drivers/net/can/usb/peak_usb/pcan_usb_core.c | 11 +++++++++++
drivers/net/can/usb/peak_usb/pcan_usb_core.h | 1 +
drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 9 ++++++---
3 files changed, 18 insertions(+), 3 deletions(-)
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 e8f43ed90b72..4bb6b9d53df4 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -205,6 +205,17 @@ int peak_usb_netif_rx(struct sk_buff *skb,
return netif_rx(skb);
}
+/* post received skb with native 64-bit hw timestamp */
+int peak_usb_netif_rx_64(struct sk_buff *skb, u32 ts_low, u32 ts_high)
+{
+ struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
+ u64 ns_ts = (((u64)ts_high << 32) + ts_low) * NSEC_PER_USEC;
+
+ hwts->hwtstamp = ns_to_ktime(ns_ts);
+
+ return netif_rx(skb);
+}
+
/*
* callback for bulk Rx urb
*/
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 b00a4811bf61..daa19f57e742 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
@@ -143,6 +143,7 @@ void peak_usb_set_ts_now(struct peak_time_ref *time_ref, u32 ts_now);
void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *tv);
int peak_usb_netif_rx(struct sk_buff *skb,
struct peak_time_ref *time_ref, u32 ts_low);
+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);
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 09029a3bad1a..6bd12549f101 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
@@ -515,7 +515,8 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if,
netdev->stats.rx_packets++;
netdev->stats.rx_bytes += cfd->len;
- peak_usb_netif_rx(skb, &usb_if->time_ref, le32_to_cpu(rm->ts_low));
+ peak_usb_netif_rx_64(skb, le32_to_cpu(rm->ts_low),
+ le32_to_cpu(rm->ts_high));
return 0;
}
@@ -579,7 +580,8 @@ static int pcan_usb_fd_decode_status(struct pcan_usb_fd_if *usb_if,
netdev->stats.rx_packets++;
netdev->stats.rx_bytes += cf->len;
- peak_usb_netif_rx(skb, &usb_if->time_ref, le32_to_cpu(sm->ts_low));
+ peak_usb_netif_rx_64(skb, le32_to_cpu(sm->ts_low),
+ le32_to_cpu(sm->ts_high));
return 0;
}
@@ -629,7 +631,8 @@ static int pcan_usb_fd_decode_overrun(struct pcan_usb_fd_if *usb_if,
cf->can_id |= CAN_ERR_CRTL;
cf->data[1] |= CAN_ERR_CRTL_RX_OVERFLOW;
- peak_usb_netif_rx(skb, &usb_if->time_ref, le32_to_cpu(ov->ts_low));
+ peak_usb_netif_rx_64(skb, le32_to_cpu(ov->ts_low),
+ le32_to_cpu(ov->ts_high));
netdev->stats.rx_over_errors++;
netdev->stats.rx_errors++;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] can: peak_usb: CANFD: store 64-bits hw timestamps
2021-09-30 9:46 [PATCH] can: peak_usb: CANFD: store 64-bits hw timestamps Stephane Grosjean
@ 2021-10-18 12:34 ` Marc Kleine-Budde
0 siblings, 0 replies; 2+ messages in thread
From: Marc Kleine-Budde @ 2021-10-18 12:34 UTC (permalink / raw)
To: Stephane Grosjean; +Cc: linux-can Mailing List
[-- Attachment #1: Type: text/plain, Size: 2104 bytes --]
On 30.09.2021 11:46:03, Stephane Grosjean wrote:
> This patch allows to use the whole 64-bit timestamps received from the
> CAN-FD device (expressed in µs) rather than only its low part, in the
> hwtstamp structure of the skb transferred to the network layer, when a
> CAN/CANFD frame has been received.
>
> Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
> ---
> drivers/net/can/usb/peak_usb/pcan_usb_core.c | 11 +++++++++++
> drivers/net/can/usb/peak_usb/pcan_usb_core.h | 1 +
> drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 9 ++++++---
> 3 files changed, 18 insertions(+), 3 deletions(-)
>
> 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 e8f43ed90b72..4bb6b9d53df4 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> @@ -205,6 +205,17 @@ int peak_usb_netif_rx(struct sk_buff *skb,
> return netif_rx(skb);
> }
>
> +/* post received skb with native 64-bit hw timestamp */
> +int peak_usb_netif_rx_64(struct sk_buff *skb, u32 ts_low, u32 ts_high)
> +{
> + struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
> + u64 ns_ts = (((u64)ts_high << 32) + ts_low) * NSEC_PER_USEC;
> +
> + hwts->hwtstamp = ns_to_ktime(ns_ts);
> +
> + return netif_rx(skb);
> +}
> +
Applied to linux-can-next/testing, and I've reformatted the code a bit:
+/* post received skb with native 64-bit hw timestamp */
+int peak_usb_netif_rx_64(struct sk_buff *skb, u32 ts_low, u32 ts_high)
+{
+ struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
+ u64 ns_ts;
+
+ ns_ts = (u64)ts_high << 32 | ts_low;
+ ns_ts *= NSEC_PER_USEC;
+ hwts->hwtstamp = ns_to_ktime(ns_ts);
+
+ return netif_rx(skb);
+}
regards,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-18 12:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30 9:46 [PATCH] can: peak_usb: CANFD: store 64-bits hw timestamps Stephane Grosjean
2021-10-18 12:34 ` Marc Kleine-Budde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).