From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
kernel@pengutronix.de,
Stephane Grosjean <s.grosjean@peak-system.com>,
Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net-next 13/15] can: peak_usb: CANFD: store 64-bits hw timestamps
Date: Sun, 24 Oct 2021 22:43:23 +0200 [thread overview]
Message-ID: <20211024204325.3293425-14-mkl@pengutronix.de> (raw)
In-Reply-To: <20211024204325.3293425-1-mkl@pengutronix.de>
From: Stephane Grosjean <s.grosjean@peak-system.com>
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.
Link: https://lore.kernel.org/all/20210930094603.23134-1-s.grosjean@peak-system.com
Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/peak_usb/pcan_usb_core.c | 13 +++++++++++++
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, 20 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..6107fef9f4a0 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,19 @@ 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;
+
+ ns_ts = (u64)ts_high << 32 | ts_low;
+ ns_ts *= 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.33.0
next prev parent reply other threads:[~2021-10-24 20:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-24 20:43 pull-request: can-next 2021-10-24 Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 01/15] can: bcm: Use hrtimer_forward_now() Marc Kleine-Budde
2021-10-25 12:10 ` patchwork-bot+netdevbpf
2021-10-24 20:43 ` [PATCH net-next 02/15] can: bittiming: can_fixup_bittiming(): change type of tseg1 and alltseg to unsigned int Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 03/15] can: bittiming: allow TDC{V,O} to be zero and add can_tdc_const::tdc{v,o,f}_min Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 04/15] can: bittiming: change unit of TDC parameters to clock periods Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 05/15] can: bittiming: change can_calc_tdco()'s prototype to not directly modify priv Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 06/15] can: netlink: add interface for CAN-FD Transmitter Delay Compensation (TDC) Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 07/15] can: netlink: add can_priv::do_get_auto_tdcv() to retrieve tdcv from device Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 08/15] can: dev: add can_tdc_get_relative_tdco() helper function Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 09/15] can: at91/janz-ican3: replace snprintf() in show functions with sysfs_emit() Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 10/15] can: rcar: drop unneeded ARM dependency Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 11/15] can: mscan: mpc5xxx_can: Make use of the helper function dev_err_probe() Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 12/15] can: gs_usb: use %u to print unsigned values Marc Kleine-Budde
2021-10-24 20:43 ` Marc Kleine-Budde [this message]
2021-10-24 20:43 ` [PATCH net-next 14/15] can: xilinx_can: remove repeated word from the kernel-doc Marc Kleine-Budde
2021-10-24 20:43 ` [PATCH net-next 15/15] can: xilinx_can: xcan_remove(): remove redundant netif_napi_del() Marc Kleine-Budde
2021-10-25 12:10 ` pull-request: can-next 2021-10-24 patchwork-bot+netdevbpf
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=20211024204325.3293425-14-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=s.grosjean@peak-system.com \
/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;
as well as URLs for NNTP newsgroup(s).