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

net: dsa: microchip: ptp: move pdelay_rsp correction field to tail tag

For PDelay_Resp messages we will likely have a negative value in the
correction field. The switch hardware cannot correctly update such
values (produces an off by one error in the UDP checksum), so it must be
moved to the time stamp field in the tail tag. Format of the correction
field is 48 bit ns + 16 bit fractional ns. After updating the
correction field, clone is no longer required hence it is freed.

Signed-off-by: Christian Eggers <ceggers@arri.de>
Co-developed-by: Arun Ramadoss <arun.ramadoss@microchip.com>
Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Christian Eggers and committed by
David S. Miller
a32190b1 ab32f56a

+34 -1
+4
drivers/net/dsa/microchip/ksz_ptp.c
··· 267 267 switch (ptp_msg_type) { 268 268 case PTP_MSGTYPE_PDELAY_REQ: 269 269 break; 270 + case PTP_MSGTYPE_PDELAY_RESP: 271 + KSZ_SKB_CB(skb)->ptp_type = type; 272 + KSZ_SKB_CB(skb)->update_correction = true; 273 + return; 270 274 271 275 default: 272 276 return;
+2
include/linux/dsa/ksz_common.h
··· 36 36 37 37 struct ksz_skb_cb { 38 38 struct sk_buff *clone; 39 + unsigned int ptp_type; 40 + bool update_correction; 39 41 u32 tstamp; 40 42 }; 41 43
+28 -1
net/dsa/tag_ksz.c
··· 7 7 #include <linux/dsa/ksz_common.h> 8 8 #include <linux/etherdevice.h> 9 9 #include <linux/list.h> 10 + #include <linux/ptp_classify.h> 10 11 #include <net/dsa.h> 11 12 12 13 #include "tag.h" ··· 196 195 static void ksz_xmit_timestamp(struct dsa_port *dp, struct sk_buff *skb) 197 196 { 198 197 struct ksz_tagger_private *priv; 198 + struct ptp_header *ptp_hdr; 199 + unsigned int ptp_type; 200 + u32 tstamp_raw = 0; 201 + s64 correction; 199 202 200 203 priv = ksz_tagger_private(dp->ds); 201 204 202 205 if (!test_bit(KSZ_HWTS_EN, &priv->state)) 203 206 return; 204 207 205 - put_unaligned_be32(0, skb_put(skb, KSZ_PTP_TAG_LEN)); 208 + if (!KSZ_SKB_CB(skb)->update_correction) 209 + goto output_tag; 210 + 211 + ptp_type = KSZ_SKB_CB(skb)->ptp_type; 212 + 213 + ptp_hdr = ptp_parse_header(skb, ptp_type); 214 + if (!ptp_hdr) 215 + goto output_tag; 216 + 217 + correction = (s64)get_unaligned_be64(&ptp_hdr->correction); 218 + 219 + if (correction < 0) { 220 + struct timespec64 ts; 221 + 222 + ts = ns_to_timespec64(-correction >> 16); 223 + tstamp_raw = ((ts.tv_sec & 3) << 30) | ts.tv_nsec; 224 + 225 + /* Set correction field to 0 and update UDP checksum */ 226 + ptp_header_update_correction(skb, ptp_type, ptp_hdr, 0); 227 + } 228 + 229 + output_tag: 230 + put_unaligned_be32(tstamp_raw, skb_put(skb, KSZ_PTP_TAG_LEN)); 206 231 } 207 232 208 233 /* Defer transmit if waiting for egress time stamp is required. */