Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: dev: add hardware TX timestamp

Because of the loopback feature of socket CAN, hardware TX timestamps
are nothing else than the hardware RX timespamp of the corresponding
loopback packet. This patch simply reuses the hardware RX timestamp.

The rationale to clone this timestamp value is that existing tools
which rely of libpcap (such as tcpdump) expect support for both TX and
RX hardware timestamps in order to activate the feature (i.e. no
granular control to activate either of TX or RX hardware timestamps).

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/all/20220727101641.198847-7-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
8bdd1112 409c188c

+6
+6
drivers/net/can/dev/skb.c
··· 72 72 /* save frame_len to reuse it when transmission is completed */ 73 73 can_skb_prv(skb)->frame_len = frame_len; 74 74 75 + if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) 76 + skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; 77 + 75 78 skb_tx_timestamp(skb); 76 79 77 80 /* save this skb for tx interrupt echo handling */ ··· 109 106 struct sk_buff *skb = priv->echo_skb[idx]; 110 107 struct can_skb_priv *can_skb_priv = can_skb_prv(skb); 111 108 struct canfd_frame *cf = (struct canfd_frame *)skb->data; 109 + 110 + if (skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) 111 + skb_tstamp_tx(skb, skb_hwtstamps(skb)); 112 112 113 113 /* get the real payload length for netdev statistics */ 114 114 if (cf->can_id & CAN_RTR_FLAG)