Skip to content

Commit bbcbc90

Browse files
Wei Fangkuba-moo
authored andcommitted
net: enetc: update UDP checksum when updating originTimestamp field
There is an issue with one-step timestamp based on UDP/IP. The peer will discard the sync packet because of the wrong UDP checksum. For ENETC v1, the software needs to update the UDP checksum when updating the originTimestamp field, so that the hardware can correctly update the UDP checksum when updating the correction field. Otherwise, the UDP checksum in the sync packet will be wrong. Fixes: 7294380 ("enetc: support PTP Sync packet one-step timestamping") Cc: [email protected] Signed-off-by: Wei Fang <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Tested-by: Vladimir Oltean <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a562d0c commit bbcbc90

File tree

1 file changed

+34
-7
lines changed
  • drivers/net/ethernet/freescale/enetc

1 file changed

+34
-7
lines changed

drivers/net/ethernet/freescale/enetc/enetc.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,11 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
297297
}
298298

299299
if (do_onestep_tstamp) {
300-
u32 lo, hi, val;
301-
u64 sec, nsec;
300+
__be32 new_sec_l, new_nsec;
301+
u32 lo, hi, nsec, val;
302+
__be16 new_sec_h;
302303
u8 *data;
304+
u64 sec;
303305

304306
lo = enetc_rd_hot(hw, ENETC_SICTR0);
305307
hi = enetc_rd_hot(hw, ENETC_SICTR1);
@@ -313,13 +315,38 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
313315
/* Update originTimestamp field of Sync packet
314316
* - 48 bits seconds field
315317
* - 32 bits nanseconds field
318+
*
319+
* In addition, the UDP checksum needs to be updated
320+
* by software after updating originTimestamp field,
321+
* otherwise the hardware will calculate the wrong
322+
* checksum when updating the correction field and
323+
* update it to the packet.
316324
*/
317325
data = skb_mac_header(skb);
318-
*(__be16 *)(data + offset2) =
319-
htons((sec >> 32) & 0xffff);
320-
*(__be32 *)(data + offset2 + 2) =
321-
htonl(sec & 0xffffffff);
322-
*(__be32 *)(data + offset2 + 6) = htonl(nsec);
326+
new_sec_h = htons((sec >> 32) & 0xffff);
327+
new_sec_l = htonl(sec & 0xffffffff);
328+
new_nsec = htonl(nsec);
329+
if (udp) {
330+
struct udphdr *uh = udp_hdr(skb);
331+
__be32 old_sec_l, old_nsec;
332+
__be16 old_sec_h;
333+
334+
old_sec_h = *(__be16 *)(data + offset2);
335+
inet_proto_csum_replace2(&uh->check, skb, old_sec_h,
336+
new_sec_h, false);
337+
338+
old_sec_l = *(__be32 *)(data + offset2 + 2);
339+
inet_proto_csum_replace4(&uh->check, skb, old_sec_l,
340+
new_sec_l, false);
341+
342+
old_nsec = *(__be32 *)(data + offset2 + 6);
343+
inet_proto_csum_replace4(&uh->check, skb, old_nsec,
344+
new_nsec, false);
345+
}
346+
347+
*(__be16 *)(data + offset2) = new_sec_h;
348+
*(__be32 *)(data + offset2 + 2) = new_sec_l;
349+
*(__be32 *)(data + offset2 + 6) = new_nsec;
323350

324351
/* Configure single-step register */
325352
val = ENETC_PM0_SINGLE_STEP_EN;

0 commit comments

Comments
 (0)