From: Wei Fang <wei.fang@nxp.com>
To: claudiu.manoil@nxp.com, vladimir.oltean@nxp.com,
xiaoning.wang@nxp.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: ioana.ciornei@nxp.com, yangbo.lu@nxp.com,
michal.swiatkowski@linux.intel.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, imx@lists.linux.dev,
stable@vger.kernel.org
Subject: [PATCH v2 net 5/9] net: enetc: update UDP checksum when updating originTimestamp field
Date: Wed, 19 Feb 2025 13:42:43 +0800 [thread overview]
Message-ID: <20250219054247.733243-6-wei.fang@nxp.com> (raw)
In-Reply-To: <20250219054247.733243-1-wei.fang@nxp.com>
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: 7294380c5211 ("enetc: support PTP Sync packet one-step timestamping")
Cc: stable@vger.kernel.org
Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
drivers/net/ethernet/freescale/enetc/enetc.c | 41 ++++++++++++++++----
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 77f8ef5358b6..9a24d1176479 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -279,9 +279,11 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
}
if (do_onestep_tstamp) {
- u32 lo, hi, val;
- u64 sec, nsec;
+ __be32 new_sec_l, new_nsec;
+ u32 lo, hi, nsec, val;
+ __be16 new_sec_h;
u8 *data;
+ u64 sec;
lo = enetc_rd_hot(hw, ENETC_SICTR0);
hi = enetc_rd_hot(hw, ENETC_SICTR1);
@@ -295,13 +297,38 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
/* Update originTimestamp field of Sync packet
* - 48 bits seconds field
* - 32 bits nanseconds field
+ *
+ * In addition, the UDP checksum needs to be updated
+ * by software after updating originTimestamp field,
+ * otherwise the hardware will calculate the wrong
+ * checksum when updating the correction field and
+ * update it to the packet.
*/
data = skb_mac_header(skb);
- *(__be16 *)(data + offset2) =
- htons((sec >> 32) & 0xffff);
- *(__be32 *)(data + offset2 + 2) =
- htonl(sec & 0xffffffff);
- *(__be32 *)(data + offset2 + 6) = htonl(nsec);
+ new_sec_h = htons((sec >> 32) & 0xffff);
+ new_sec_l = htonl(sec & 0xffffffff);
+ new_nsec = htonl(nsec);
+ if (udp) {
+ struct udphdr *uh = udp_hdr(skb);
+ __be32 old_sec_l, old_nsec;
+ __be16 old_sec_h;
+
+ old_sec_h = *(__be16 *)(data + offset2);
+ inet_proto_csum_replace2(&uh->check, skb, old_sec_h,
+ new_sec_h, false);
+
+ old_sec_l = *(__be32 *)(data + offset2 + 2);
+ inet_proto_csum_replace4(&uh->check, skb, old_sec_l,
+ new_sec_l, false);
+
+ old_nsec = *(__be32 *)(data + offset2 + 6);
+ inet_proto_csum_replace4(&uh->check, skb, old_nsec,
+ new_nsec, false);
+ }
+
+ *(__be16 *)(data + offset2) = new_sec_h;
+ *(__be32 *)(data + offset2 + 2) = new_sec_l;
+ *(__be32 *)(data + offset2 + 6) = new_nsec;
/* Configure single-step register */
val = ENETC_PM0_SINGLE_STEP_EN;
--
2.34.1
next prev parent reply other threads:[~2025-02-19 6:00 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 5:42 [PATCH v2 net 0/9] net: enetc: fix some known issues Wei Fang
2025-02-19 5:42 ` [PATCH v2 net 1/9] net: enetc: fix the off-by-one issue in enetc_map_tx_buffs() Wei Fang
2025-02-19 10:48 ` Claudiu Manoil
2025-02-20 13:01 ` Vladimir Oltean
2025-02-21 1:26 ` Wei Fang
2025-02-19 5:42 ` [PATCH v2 net 2/9] net: enetc: correct the tx_swbd statistics Wei Fang
2025-02-20 8:31 ` Ioana Ciornei
2025-02-20 16:01 ` Vladimir Oltean
2025-02-21 1:42 ` Wei Fang
2025-02-21 8:03 ` Claudiu Manoil
2025-02-21 8:34 ` Wei Fang
2025-02-21 9:22 ` Claudiu Manoil
2025-02-21 9:18 ` Vladimir Oltean
2025-02-24 3:27 ` Wei Fang
2025-02-19 5:42 ` [PATCH v2 net 3/9] net: enetc: correct the xdp_tx statistics Wei Fang
2025-02-20 8:37 ` Ioana Ciornei
2025-02-20 16:58 ` Vladimir Oltean
2025-02-19 5:42 ` [PATCH v2 net 4/9] net: enetc: VFs do not support HWTSTAMP_TX_ONESTEP_SYNC Wei Fang
2025-02-20 16:52 ` Vladimir Oltean
2025-02-19 5:42 ` Wei Fang [this message]
2025-02-20 15:50 ` [PATCH v2 net 5/9] net: enetc: update UDP checksum when updating originTimestamp field Vladimir Oltean
2025-02-19 5:42 ` [PATCH v2 net 6/9] net: enetc: add missing enetc4_link_deinit() Wei Fang
2025-02-20 16:50 ` Vladimir Oltean
2025-02-19 5:42 ` [PATCH v2 net 7/9] net: enetc: remove the mm_lock from the ENETC v4 driver Wei Fang
2025-02-20 16:03 ` Vladimir Oltean
2025-02-19 5:42 ` [PATCH v2 net 8/9] net: enetc: correct the EMDIO base offset for ENETC v4 Wei Fang
2025-02-19 20:42 ` Andrew Lunn
2025-02-20 8:05 ` Wei Fang
2025-02-20 15:58 ` Vladimir Oltean
2025-02-19 5:42 ` [PATCH v2 net 9/9] net: enetc: fix the off-by-one issue in enetc_map_tx_tso_buffs() Wei Fang
2025-02-19 11:04 ` Michal Swiatkowski
2025-02-19 17:46 ` Claudiu Manoil
2025-02-20 5:06 ` Wei Fang
2025-02-20 8:39 ` Claudiu Manoil
2025-02-20 16:32 ` Vladimir Oltean
2025-02-20 16:46 ` Vladimir Oltean
2025-02-21 2:56 ` Wei Fang
2025-02-21 9:30 ` Vladimir Oltean
2025-02-24 4:42 ` Wei Fang
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=20250219054247.733243-6-wei.fang@nxp.com \
--to=wei.fang@nxp.com \
--cc=andrew+netdev@lunn.ch \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=imx@lists.linux.dev \
--cc=ioana.ciornei@nxp.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.swiatkowski@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=vladimir.oltean@nxp.com \
--cc=xiaoning.wang@nxp.com \
--cc=yangbo.lu@nxp.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