[PATCH v3 net-next 14/15] net: enetc: don't update sync packet checksum if checksum offload is used

Wei Fang
2025-08-12T10:08:37Z

For ENETC v4, the hardware has the capability to support Tx checksum
offload. so the enetc driver does not need to update the UDP checksum
of PTP sync packets if Tx checksum offload is enabled.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>

---
v3: no changes, just collect Reviewed-by tag
---
drivers/net/ethernet/freescale/enetc/enetc.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 6dbc9cc811a0..aae462a0cf5a 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -247,7 +247,7 @@ static void enetc4_set_one_step_ts(struct enetc_si *si, bool udp, int offset)
}

static u32 enetc_update_ptp_sync_msg(struct enetc_ndev_priv *priv,
- struct sk_buff *skb)
+ struct sk_buff *skb, bool csum_offload)
{
struct enetc_skb_cb *enetc_cb = ENETC_SKB_CB(skb);
u16 tstamp_off = enetc_cb->origin_tstamp_off;
@@ -269,18 +269,17 @@ static u32 enetc_update_ptp_sync_msg(struct enetc_ndev_priv *priv,
* - 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.
+ * In addition, if csum_offload is false, 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);
new_sec_h = htons((sec >> 32) & 0xffff);
new_sec_l = htonl(sec & 0xffffffff);
new_nsec = htonl(nsec);
- if (enetc_cb->udp) {
+ if (enetc_cb->udp && !csum_offload) {
struct udphdr *uh = udp_hdr(skb);
__be32 old_sec_l, old_nsec;
__be16 old_sec_h;
@@ -319,6 +318,7 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
struct enetc_tx_swbd *tx_swbd;
int len = skb_headlen(skb);
union enetc_tx_bd temp_bd;
+ bool csum_offload = false;
union enetc_tx_bd *txbd;
int i, count = 0;
skb_frag_t *frag;
@@ -345,6 +345,7 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
temp_bd.l4_aux = FIELD_PREP(ENETC_TX_BD_L4T,
ENETC_TXBD_L4T_UDP);
flags |= ENETC_TXBD_FLAGS_CSUM_LSO | ENETC_TXBD_FLAGS_L4CS;
+ csum_offload = true;
} else if (skb_checksum_help(skb)) {
return 0;
}
@@ -352,7 +353,7 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)

if (enetc_cb->flag & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) {
do_onestep_tstamp = true;
- tstamp = enetc_update_ptp_sync_msg(priv, skb);
+ tstamp = enetc_update_ptp_sync_msg(priv, skb, csum_offload);
} else if (enetc_cb->flag & ENETC_F_TX_TSTAMP) {
do_twostep_tstamp = true;
}
--
2.34.1