For L4 checksum offload, enetc_map_tx_buffs() programs the following TX BD fields: ENETC_TX_BD_L3_START <- skb_network_offset(skb) and ENETC_TX_BD_L3_HDR_LEN <- skb_network_header_len(skb) / 4. These fields are passed this way so that the hardware simultaneously knows the L3 header start (for computing the pseudo-header) and the L4 header start (by summing up L3_START + 4 x L3_HDR_SIZE) which is the csum_start. Section 106.3.5.1.2.1.3.5 Transmit Checksum Offload of the i.MX95 RM has this statement: BD[L3_START] + (BD[L3_HDR_SIZE] x 4) is set to the offset within the packet to begin checksumming. (BD[L3_START] + (BD[L3_HDR_SIZE] x 4) + any hardware inserted tags) must be smaller than 127 bytes. We have no test for this condition, and with IPv6 extension headers it is possible for that sum to actually exceed 127 bytes. For example, when using the Segment Routing Header, 4 Segment Identifiers (SIDs) will produce an L4 header offset of 126 bytes (OK), while 5 SIDs will produce an L4 offset of 142 bytes (not OK). The hardware picks up these packets from the TX ring, identifies the incorrect header length, refuses to send them, updates the TX BD writeback with the STATUS field set to 1, meaning: Programming error An error exists in either the Tx BD, the Tx ring registers, or some combination of these which meant that this frame could not be transmitted. releases the buffer and updates tx_ring->stats.packets and tx_ring->stats.bytes as if the packets were sent (but no MAC counter updates). This error can only be seen through manual code instrumentation, since the driver only checks the writeback when it sets tx_swbd->check_wb, and it does that for taprio offload and for 2-step TX timestamping. Issue found while investigating Sashiko's question "Can a 256-byte header still break the hardware LSO path because lso->hdr_len is a u8?": https://lore.kernel.org/imx/sashiko-outbox-211955@kernel.org/ and was reproduced using: https://gist.github.com/vladimiroltean/7cecf636b788b29f361a2fbdae646010 Turns out, LSO breaks sooner than the assumed 256 byte limit, because of the checksum offload feature it depends on. LS1028A also declares the NETIF_F_HW_CSUM feature in order for GSO to be passed to the driver for software segmentation, but performs the checksum in software - either through csum_partial()/csum_block_add() for GSO, or through skb_checksum_help() for non-GSO. Point being, it does not use the HW offload engine, does not have the limitation, and is the reason why we need to discern using the ENETC_F_TXCSUM bit from priv->active_offloads instead. Signed-off-by: Vladimir Oltean --- v1->v2: patch is new --- drivers/net/ethernet/freescale/enetc/enetc.c | 16 ++++++++++++++++ drivers/net/ethernet/freescale/enetc/enetc.h | 1 + 2 files changed, 17 insertions(+) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 7f089a84d9a6..6cc519eea5bd 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1114,6 +1114,16 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev) } EXPORT_SYMBOL_GPL(enetc_xmit); +static bool enetc_skb_l4_too_deep(const struct sk_buff *skb) +{ + unsigned int l4_offset = skb_checksum_start_offset(skb); + + if (skb_vlan_tag_present(skb)) + l4_offset += VLAN_HLEN; + + return l4_offset >= ENETC_TX_CSUM_MAX_L4_OFFSET; +} + netdev_features_t enetc_features_check(struct sk_buff *skb, struct net_device *ndev, netdev_features_t features) @@ -1122,6 +1132,12 @@ netdev_features_t enetc_features_check(struct sk_buff *skb, features = vlan_features_check(skb, features); + if (priv->active_offloads & ENETC_F_TXCSUM && + skb->ip_summed == CHECKSUM_PARTIAL && enetc_skb_l4_too_deep(skb)) { + features &= ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); + return features; + } + if (!skb_is_gso(skb) || enetc_skb_uses_lso(priv, skb)) return features; diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index 1e3290d1a388..5b8cffd589c7 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -75,6 +75,7 @@ struct enetc_lso_t { int total_len; /* total data length, not include LSO header */ }; +#define ENETC_TX_CSUM_MAX_L4_OFFSET 127 #define ENETC_LSO_MAX_DATA_LEN SZ_256K #define ENETC_RX_MAXFRM_SIZE ENETC_MAC_MAXFRM_SIZE -- 2.53.0