Skip to content

net: bcmgenet: add XDP support

Nicolai Buchwitz bpf lkml netdev 9 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v9 Latest7 patches 5 repliesIn review
  2. v87 patches 9 repliesSuperseded
  3. v77 patches 1 replySuperseded
Earlier versions · 6
VersionPostedPatchesRepliesStatus
v67 patches9 repliesSuperseded
v56 patches4 repliesSuperseded
v46 patches2 repliesSuperseded
v36 patches13 repliesSuperseded
v26 patches4 repliesSuperseded
v16 patches9 repliesSuperseded

Changes in v9 from the cover letter

- Patch 1:
* Add explicit #include <linux/bpf.h> for XDP_PACKET_HEADROOM.
* Remove unused priv->rx_buf_len after page_pool conversion.
* Sync only the RSB and the actual received frame length in page_pool_dma_sync_for_cpu(), instead of the full RX_BUF_LENGTH.
* Add a runt length guard (len < GENET_RSB_PAD) to prevent __skb_put underflow on broken HW.
- Patch 4:
* Guard netdev_tx_reset_queue() in bcmgenet_tx_reclaim()'s all=true path against ring->index == DESC_INDEX, fixing an out-of-bounds dev->_tx[16] access during interface teardown.
* Assign explicit lowest priority to ring 16 so XDP_TX does not preempt normal SKB TX under strict-priority arbitration.
- Patch 5:
* Stop manipulating xdp_features_clear/set_redirect_target() in bcmgenet_xdp_setup(); ndo_xdp_xmit works without a local XDP program, so leave NETDEV_XDP_ACT_NDO_XMIT advertised at all times.
- Patch 6:
* Increment xdp_tx_err on xdp_convert_buff_to_frame() failure.
* Add separate xdp_aborted counter for XDP_ABORTED and invalid- action returns, instead of folding them into xdp_drop.

Patches in v9 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7net: bcmgenet: convert RX path to page_pooldrivers/net/ethernet/broadcom/Kconfig drivers/net/ethernet/broadcom/genet/bcmgenet.c drivers/net/ethernet/broadcom/genet/bcmgenet.h+154 -841 reply
2/7net: bcmgenet: register xdp_rxq_info for each RX ringdrivers/net/ethernet/broadcom/genet/bcmgenet.c drivers/net/ethernet/broadcom/genet/bcmgenet.h+20 -00 replies
3/7net: bcmgenet: add basic XDP support (PASS/DROP)drivers/net/ethernet/broadcom/genet/bcmgenet.c drivers/net/ethernet/broadcom/genet/bcmgenet.h+116 -171 reply
4/7net: bcmgenet: add XDP_TX supportdrivers/net/ethernet/broadcom/genet/bcmgenet.c drivers/net/ethernet/broadcom/genet/bcmgenet.h+211 -231 reply
5/7net: bcmgenet: add XDP_REDIRECT and ndo_xdp_xmit supportdrivers/net/ethernet/broadcom/genet/bcmgenet.c+67 -142 replies
6/7net: bcmgenet: add XDP statistics countersdrivers/net/ethernet/broadcom/genet/bcmgenet.c drivers/net/ethernet/broadcom/genet/bcmgenet.h+24 -00 replies
7/7net: bcmgenet: reject MTU changes incompatible with XDPdrivers/net/ethernet/broadcom/genet/bcmgenet.c+15 -00 replies

Reviews trailers per patch

2 of 7 patches have a Reviewed-by or Acked-by.

PatchFlorian FainelliMohsin Bashir
1/7
2/7R-b
3/7
4/7
5/7
6/7
7/7R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v9 thread

Cover letter [PATCH net-next v9 0/7] net: bcmgenet: add XDP support

Add XDP support to the bcmgenet driver, covering XDP_PASS, XDP_DROP, XDP_TX, XDP_REDIRECT, and ndo_xdp_xmit.

The first patch converts the RX path from the existing kmalloc-based allocation to page_pool, which is a prerequisite for XDP. The remaining patches incrementally add XDP functionality and per-action statistics.

Tested on Raspberry Pi CM4 (BCM2711, bcmgenet, 1Gbps link):
- XDP_PASS: 943 Mbit/s TX, 935 Mbit/s RX (no regression vs baseline)
- XDP_PASS latency: 0.164ms avg, 0% packet loss
- XDP_DROP: all inbound traffic blocked as expected
- XDP_TX: TX counter increments (packet reflection working)
- Link flap with XDP attached: no errors
- Program swap under iperf3 load: no errors
- Upstream XDP selftests (xdp.py): pass_sb, drop_sb, tx_sb passing
- XDP-based EtherCAT master (~37 kHz cycle rate, all packet processing in BPF/XDP), stable over multiple days

Previous versions:
v8: https://lore.kernel.org/netdev/[email protected]/
v7: https://lore.kernel.org/netdev/[email protected]/
v6: https://lore.kernel.org/netdev/[email protected]/
v5: https://lore.kernel.org/netdev/[email protected]/
v4: https://lore.kernel.org/netdev/[email protected]/
v3: https://lore.kernel.org/netdev/[email protected]/
v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/

Changes since v8 (all from Jakub Kicinski's review):
- Patch 1:
* Add explicit #include <linux/bpf.h> for XDP_PACKET_HEADROOM.
* Remove unused priv->rx_buf_len after page_pool conversion.
* Sync only the RSB and the actual received frame length in page_pool_dma_sync_for_cpu(), instead of the full RX_BUF_LENGTH.
* Add a runt length guard (len < GENET_RSB_PAD) to prevent __skb_put underflow on broken HW.
- Patch 4:
* Guard netdev_tx_reset_queue() in bcmgenet_tx_reclaim()'s all=true path against ring->index == DESC_INDEX, fixing an out-of-bounds dev->_tx[16] access during interface teardown.
* Assign explicit lowest priority to ring 16 so XDP_TX does not preempt normal SKB TX under strict-priority arbitration.
- Patch 5:
* Stop manipulating xdp_features_clear/set_redirect_target() in bcmgenet_xdp_setup(); ndo_xdp_xmit works without a local XDP program, so leave NETDEV_XDP_ACT_NDO_XMIT advertised at all times.
- Patch 6:
* Increment xdp_tx_err on xdp_convert_buff_to_frame() failure.
* Add separate xdp_aborted counter for XDP_ABORTED and invalid- action returns, instead of folding them into xdp_drop.

Changes since v7:
- No code changes; resubmitted after net-next reopened.

Changes since v6:
- Removed GENET_XDP_HEADROOM alias, use XDP_PACKET_HEADROOM directly. (Jakub Kicinski)
- Dropped redundant __GFP_NOWARN from page_pool_alloc_pages(), page_pool adds it automatically. (Jakub Kicinski)
- Removed floating code block in desc_rx, moved variables to outer scope. (Jakub Kicinski)
- Make bcmgenet_run_xdp() return XDP_PASS when no program is set, removing the if (xdp_prog) indentation from desc_rx. (Jakub Kicinski)

Changes since v5:
- Refactored desc_rx: always prepare xdp_buff and use bcmgenet_xdp_build_skb for both XDP and non-XDP paths, treating no-prog as XDP_PASS. (Jakub Kicinski)
- Removed synchronize_net() before bpf_prog_put(), RCU handles the grace period. (Jakub Kicinski)
- Save status->rx_csum before running XDP program to prevent bpf_xdp_adjust_head from corrupting the RSB checksum. (Jakub Kicinski)
- Tightened TSB headroom check to include sizeof(struct xdp_frame). (Jakub Kicinski)
- Fixed reclaim gating: check for pending frames on the XDP TX ring instead of priv->xdp_prog, so in-flight frames are still reclaimed after XDP program detach. (Jakub Kicinski)
- Removed dead len -= ETH_FCS_LEN in patch 1. (Mohsin Bashir)
- Added patch 7: minimal ndo_change_mtu that rejects MTU values incompatible with XDP when a program is attached. (Mohsin Bashir, Florian Fainelli)

Changes since v4:
- Fixed unused variable warning: moved tx_ring declaration from patch 4 to patch 5 where it is first used. (Jakub Kicinski)

Changes since v3:
- Fixed xdp_prepare_buff() called with meta_valid=false, causing bcmgenet_xdp_build_skb() to compute metasize=UINT_MAX and corrupt skb meta_len. Now passes true. (Simon Horman)
- Removed bcmgenet_dump_tx_queue() for ring 16 in bcmgenet_timeout(). Ring 16 has no netdev TX queue, so netdev_get_tx_queue(dev, 16) accessed beyond the allocated _tx array. (Simon Horman)
- Fixed checkpatch alignment warnings in patches 4 and 5.

Changes since v2:
- Fixed page leak on partial bcmgenet_alloc_rx_buffers() failure:
free already-allocated rx_cbs before destroying page pool. (Simon Horman)
- Fixed GENET_Q16_TX_BD_CNT defined as 64 instead of 32. (Simon Horman)
- Moved XDP TX ring to a separate struct member (xdp_tx_ring)

    instead of expanding tx_rings[] to DESC_INDEX+1. (Justin Chen)

- Added synchronize_net() before bpf_prog_put() in XDP prog swap.
- Removed goto drop_page inside switch; inlined page_pool_put calls in each failure path. (Justin Chen)
- Removed unnecessary curly braces around case XDP_TX. (Justin Chen)
- Moved int err hoisting from patch 2 to patch 1. (Justin Chen)
- Kept return type on same line as function name, per driver convention. (Justin Chen)
- XDP TX packets/bytes now counted in TX reclaim for standard network statistics.

Changes since v1:
- Fixed tx_rings[DESC_INDEX] out-of-bounds access. Expanded array to DESC_INDEX+1 and initialized ring 16 with dedicated BDs.
- Use ring 16 (hardware default descriptor ring) for XDP TX, isolating from normal SKB TX queues.
- Piggyback ring 16 TX completion on RX NAPI poll (INTRL2_1 bit collision with RX ring 0).
- Fixed ring 16 TX reclaim: skip INTRL2_1 clear, skip BQL completion, use non-destructive reclaim in RX poll path.
- Prepend zeroed TSB before XDP TX frame data (TBUF_64B_EN requires 64-byte struct status_64 prefix on all TX buffers).
- Tested with upstream XDP selftests (xdp.py): pass_sb, drop_sb, tx_sb all passing. The multi-buffer tests (pass_mb, drop_mb, tx_mb) fail because bcmgenet does not support jumbo frames / MTU changes; I plan to add ndo_change_mtu support in a follow-up series.

Nicolai Buchwitz (7):
net: bcmgenet: convert RX path to page_pool
net: bcmgenet: register xdp_rxq_info for each RX ring
net: bcmgenet: add basic XDP support (PASS/DROP)
net: bcmgenet: add XDP_TX support
net: bcmgenet: add XDP_REDIRECT and ndo_xdp_xmit support
net: bcmgenet: add XDP statistics counters
net: bcmgenet: reject MTU changes incompatible with XDP

 drivers/net/ethernet/broadcom/Kconfig         |   1 +
 .../net/ethernet/broadcom/genet/bcmgenet.c    | 655 +++++++++++++++---
 .../net/ethernet/broadcom/genet/bcmgenet.h    |  21 +-
 3 files changed, 573 insertions(+), 104 deletions(-)

--
2.51.0