[PATCH net v3 RESEND 5/6] net: bcmasp: account for offload header in TX short packet padding
From: Florian Fainelli
Date: Tue Oct 13 2026 - 17:59:36 EST
When hardware checksum offload is enabled for an skb,
bcmasp_csum_offload() prepends a struct bcmasp_pkt_offload header
(20 bytes) to the skb via skb_push(). This increases skb->len and
skb_headlen(skb) by sizeof(struct bcmasp_pkt_offload).
Because the hardware descriptor processor strips this offload header
before transmitting the packet on the wire, the wire packet length is
smaller by sizeof(struct bcmasp_pkt_offload). The padding calculation
must account for this extra header; otherwise, short frames are sent on
the wire smaller than the minimum Ethernet frame size (ETH_ZLEN +
ETH_FCS_LEN).
Furthermore, small frames with payload in page fragments (such as small
TCP segments with CHECKSUM_PARTIAL) have nr_frags > 0 and were skipping
padding entirely because the padding check was restricted to
nr_frags == 0.
Perform the padding check on skb->len before the descriptor loop using
skb_put_padto(), adding sizeof(struct bcmasp_pkt_offload) to min_size
when checksum offload is enabled, and re-read nr_frags after padding in
case the skb was linearized.
Fixes: 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
Assisted-by: LLM
Reviewed-by: Justin Chen <justin.chen@xxxxxxxxxxxx>
Signed-off-by: Florian Fainelli <florian.fainelli@xxxxxxxxxxxx>
---
.../net/ethernet/broadcom/asp2/bcmasp_intf.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
index 693e8cdfe960..a855e637b6f0 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
@@ -236,7 +236,7 @@ static struct sk_buff *bcmasp_csum_offload(struct net_device *dev,
static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct bcmasp_intf *intf = netdev_priv(dev);
- unsigned int total_bytes, size;
+ unsigned int total_bytes, size, min_size;
int spb_index, nr_frags, i, j;
struct bcmasp_tx_cb *txcb;
dma_addr_t mapping, valid;
@@ -262,16 +262,21 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev)
if (!skb)
return NETDEV_TX_OK;
+ min_size = ETH_ZLEN + ETH_FCS_LEN;
+ if (csum_hw)
+ min_size += sizeof(struct bcmasp_pkt_offload);
+
+ if (skb->len < min_size) {
+ if (skb_put_padto(skb, min_size))
+ return NETDEV_TX_OK;
+ nr_frags = skb_shinfo(skb)->nr_frags;
+ }
+
spb_index = intf->tx_spb_index;
valid = intf->tx_spb_dma_valid;
for (i = 0; i <= nr_frags; i++) {
if (!i) {
size = skb_headlen(skb);
- if (!nr_frags && size < (ETH_ZLEN + ETH_FCS_LEN)) {
- if (skb_put_padto(skb, ETH_ZLEN + ETH_FCS_LEN))
- return NETDEV_TX_OK;
- size = skb->len;
- }
mapping = dma_map_single(kdev, skb->data, size,
DMA_TO_DEVICE);
} else {
--
2.34.1