OSDN Git Service

can: gs_usb: add RX and TX hardware timestamp support
authorJohn Whittington <git@jbrengineering.co.uk>
Mon, 22 Aug 2022 10:01:10 +0000 (12:01 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Tue, 6 Sep 2022 06:21:47 +0000 (08:21 +0200)
commit45dfa45f52e66f8eee30a64b16550a9c47915044
tree64534cc5b2a1b9f863492bd8f3de065400327ad8
parent49c007b9ecead37a7c703aac7d161c9c5bc25527
can: gs_usb: add RX and TX hardware timestamp support

Add support for hardware timestamps, if the firmware includes it as a
feature via the GS_CAN_FEATURE_HW_TIMESTAMP flag. Check for this
feature during probe, extend the RX expected length if it is and
enable it during open.

The struct classic_can_ts and struct canfd_ts are extended to include
the µs timestamp following data as defined in the firmware. The
timestamp is then captured and set using skb_hwtstamps() on each RX
and TX.

The frame µs timestamp is provided from a 32 bit 1 MHz timer which
rolls over every 4294 seconds, so a cyclecounter, timecounter, and
delayed worker are used to convert the timer into a proper ns
timestamp - same implementation as commit efd8d98dfb900 ("can:
mcp251xfd: add HW timestamp infrastructure").

Hardware timestamps are added to capabilities as commit
b1f6b93e678f ("can: mcp251xfd: advertise timestamping capabilities and
add ioctl support").

Signed-off-by: John Whittington <git@jbrengineering.co.uk>
Link: https://github.com/candle-usb/candleLight_fw/issues/100
Link: https://lore.kernel.org/all/20220827221548.3291393-3-mkl@pengutronix.de
Co-developed-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/usb/gs_usb.c