Re: [PATCH net-next v1 11/11] eth: fbnic: Support AF_XDP page pool zero copy

From: Dimitri Daskalakis

Date: Mon Nov 16 2026 - 13:49:07 EST


On 11/10/26 2:20 AM, Björn Töpel wrote:
> Header and payload rings share one provider page pool, so refills even
> them out, and a short pool does not starve one of them. Payload
> buffers start at chunk offset 0, and the UMEM headroom rules require
> headroom only in the first buffer. A chunk is one 4 KiB device page,
> also with larger kernel pages, so rings fed by the provider post one
> descriptor per chunk.
>
[...]
> qt->sub0.page_pool = pp;
> + fbnic_bdq_set_page_size(&qt->sub0, xsk ? rx_page_size : PAGE_SIZE);
> qt->hdr_max = 0;
> if (!page_pool_supports_frag(pp))
> - qt->hdr_max = fbnic_whole_hdr_max(FBNIC_RX_HROOM);
> + qt->hdr_max = fbnic_whole_hdr_max(qt->rx_hroom);
> if (netif_rxq_has_unreadable_mp(fbn->netdev, rxq_idx)) {
> pp_params.order = get_order(rx_page_size);
> pp_params.max_len = rx_page_size;
> pp_params.flags |= PP_FLAG_ALLOW_UNREADABLE_NETMEM;
> pp_params.dma_dir = DMA_FROM_DEVICE;
>
> + pp = page_pool_create(&pp_params);
> + if (IS_ERR(pp))
> + goto err_destroy_sub0;
> + } else if (xsk && !xsk_pool_uses_sg(xsk)) {
> + pp_params.flags &= ~PP_FLAG_MEM_PROVIDER;
> + pp_params.rx_roles = 0;
> + pp_params.max_len = PAGE_SIZE;
> + rx_page_size = PAGE_SIZE;
> +
> pp = page_pool_create(&pp_params);
> if (IS_ERR(pp))
> goto err_destroy_sub0;

Maybe I'm misunderstanding, but why is it necessary to create a new page pool for
sub1 if !sg? All frames should be sent to sub0, and the buffers in sub1 should sit idle.

> @@ -1709,6 +1967,7 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_q_triad *qt,
> page_pool_get(pp);
> }
> qt->sub1.page_pool = pp;
> + fbnic_bdq_set_page_size(&qt->sub1, rx_page_size);
>
> return 0;
>
> @@ -1717,16 +1976,6 @@ fbnic_alloc_qt_page_pools(struct fbnic_net *fbn, struct fbnic_q_triad *qt,
> return PTR_ERR(pp);
> }
>
> -static u8 fbnic_bdq_page_shift(u32 page_size)
> -{
> - return ilog2(page_size / FBNIC_BD_PAGE_SIZE);
> -}
> -
> -static void fbnic_bdq_set_page_size(struct fbnic_ring *bdq, u32 page_size)
> -{
> - bdq->bd_page_shift = fbnic_bdq_page_shift(page_size);
> -}
> -
> static void fbnic_ring_init(struct fbnic_ring *ring, u32 __iomem *doorbell,
> int q_idx, u8 flags)
> {
> @@ -1830,7 +2079,8 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,
> if (xdp_count > 0) {
> unsigned int xdp_idx = FBNIC_MAX_TXQS + rxq_idx;
>
> - fbnic_ring_init(&qt->sub1, db, xdp_idx, flags);
> + fbnic_ring_init(&qt->sub1, db, xdp_idx,
> + flags | FBNIC_RING_F_XDP);
> fbn->tx[xdp_idx] = &qt->sub1;
> xdp_count--;
> } else {
> @@ -1977,6 +2227,9 @@ static int fbnic_alloc_tx_ring_buffer(struct fbnic_ring *txr)
> {
> size_t size = array_size(sizeof(*txr->tx_buf), txr->size_mask + 1);
>
> + if (txr->flags & FBNIC_RING_F_XDP)
> + size = array_size(sizeof(*txr->xdp_buf), txr->size_mask + 1);
> +
> txr->tx_buf = kvzalloc(size, GFP_KERNEL | __GFP_NOWARN);
>
> return txr->tx_buf ? 0 : -ENOMEM;
> @@ -2126,20 +2379,19 @@ static int fbnic_alloc_tx_qt_resources(struct fbnic_net *fbn,
> return err;
> }
>
> -static int fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn,
> - struct fbnic_napi_vector *nv,
> - struct fbnic_q_triad *qt,
> - u32 rx_page_size)
> +static int
> +fbnic_alloc_rx_qt_resources(struct fbnic_net *fbn,
> + struct fbnic_napi_vector *nv,
> + struct fbnic_q_triad *qt,
> + const struct netdev_queue_config *qcfg)
> {
> struct device *dev = fbn->netdev->dev.parent;
> int err;
>
> - err = fbnic_alloc_qt_page_pools(fbn, qt, qt->cmpl.q_idx, rx_page_size);
> + err = fbnic_alloc_qt_page_pools(fbn, qt, qt->cmpl.q_idx, qcfg);
> if (err)
> return err;
>
> - fbnic_bdq_set_page_size(&qt->sub1, rx_page_size);
> -
> err = xdp_rxq_info_reg(&qt->xdp_rxq, fbn->netdev, qt->cmpl.q_idx,
> nv->napi.napi_id);
> if (err)
> @@ -2203,8 +2455,7 @@ static int fbnic_alloc_nv_resources(struct fbnic_net *fbn,
> struct netdev_queue_config qcfg;
>
> netdev_queue_config(fbn->netdev, nv->qt[i].cmpl.q_idx, &qcfg);
> - err = fbnic_alloc_rx_qt_resources(fbn, nv, &nv->qt[i],
> - qcfg.rx_page_size);
> + err = fbnic_alloc_rx_qt_resources(fbn, nv, &nv->qt[i], &qcfg);
> if (err)
> goto free_qt_resources;
> }
> @@ -2598,9 +2849,8 @@ static void fbnic_nv_fill(struct fbnic_napi_vector *nv)
> for (j = 0, t = nv->txt_count; j < nv->rxt_count; j++, t++) {
> struct fbnic_q_triad *qt = &nv->qt[t];
>
> - /* Populate the header and payload BDQs */
> - fbnic_fill_bdq(&qt->sub0);
> - fbnic_fill_bdq(&qt->sub1);
> + /* Populate the header and payload BDQs; NAPI retries */
> + fbnic_fill_bdqs(qt);
> }
> }
>
> @@ -2736,14 +2986,20 @@ static void fbnic_config_drop_mode_rcq(struct fbnic_napi_vector *nv,
> struct fbnic_ring *rcq, bool tx_pause,
> bool hdr_split)
> {
> + struct fbnic_q_triad *qt = container_of_const(rcq, struct fbnic_q_triad,
> + cmpl);
> struct fbnic_net *fbn = netdev_priv(nv->napi.dev);
> - u32 drop_mode, rcq_ctl;
> + u32 drop_mode, hroom, rcq_ctl;
> +
> + /* The device aligns the maximum value up to FBNIC_RX_HROOM_MAX. */
> + hroom = min_t(u32, qt->rx_hroom,
> + FIELD_MAX(FBNIC_QUEUE_RDE_CTL0_MIN_HROOM_MASK));
>
> drop_mode = fbnic_drop_mode(fbn, tx_pause);
>
> /* Specify packet layout */
> rcq_ctl = FIELD_PREP(FBNIC_QUEUE_RDE_CTL0_DROP_MODE_MASK, drop_mode) |
> - FIELD_PREP(FBNIC_QUEUE_RDE_CTL0_MIN_HROOM_MASK, FBNIC_RX_HROOM) |
> + FIELD_PREP(FBNIC_QUEUE_RDE_CTL0_MIN_HROOM_MASK, hroom) |
> FIELD_PREP(FBNIC_QUEUE_RDE_CTL0_MIN_TROOM_MASK, FBNIC_RX_TROOM) |
> FIELD_PREP(FBNIC_QUEUE_RDE_CTL0_EN_HDR_SPLIT, hdr_split);
>
> @@ -3028,8 +3284,7 @@ static int fbnic_queue_mem_alloc(struct net_device *dev,
> struct fbnic_napi_vector *nv;
>
> if (!netif_running(dev))
> - return fbnic_alloc_qt_page_pools(fbn, qt, idx,
> - qcfg->rx_page_size);
> + return fbnic_alloc_qt_page_pools(fbn, qt, idx, qcfg);
>
> /* A failed PCIe recovery or resume can leave the datapath torn down
> * while netif_running() is still true. This ndo runs before
> @@ -3049,7 +3304,7 @@ static int fbnic_queue_mem_alloc(struct net_device *dev,
> fbnic_ring_init(&qt->cmpl, real->cmpl.doorbell, real->cmpl.q_idx,
> real->cmpl.flags);
>
> - return fbnic_alloc_rx_qt_resources(fbn, nv, qt, qcfg->rx_page_size);
> + return fbnic_alloc_rx_qt_resources(fbn, nv, qt, qcfg);
> }
>
> static void fbnic_default_qcfg(struct net_device *dev,
> @@ -3086,6 +3341,14 @@ static int fbnic_validate_qcfg(struct net_device *dev,
> return -EINVAL;
> }
>
> + if (qcfg->rx_headroom &&
> + (qcfg->rx_headroom < XDP_PACKET_HEADROOM ||
> + qcfg->rx_headroom > FBNIC_RX_HROOM_MAX ||
> + !IS_ALIGNED(qcfg->rx_headroom, FBNIC_RX_HDR_ALIGN))) {
> + NL_SET_ERR_MSG_MOD(extack, "rx_headroom is not supported");
> + return -EINVAL;
> + }
> +
> /* Payload fragments occupy multiples of FBNIC_RX_PAYLD_ALIGN bytes.
> * Keep at least one reference in the bias until fbnic_clean_bdq()
> * observes a completion from a subsequent allocation.
> @@ -3216,5 +3479,6 @@ const struct netdev_queue_mgmt_ops fbnic_queue_mgmt_ops = {
> .ndo_queue_stop = fbnic_queue_stop,
> .ndo_default_qcfg = fbnic_default_qcfg,
> .ndo_validate_qcfg = fbnic_validate_qcfg,
> - .supported_params = QCFG_RX_PAGE_SIZE,
> + .supported_params = QCFG_RX_PAGE_SIZE | QCFG_RX_HEADROOM,
> + .xsk_page_pool = true,
> };
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h
> index 3077d9bbd587..b4baaa914585 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h
> @@ -14,7 +14,11 @@
>
> #include "fbnic_csr.h"
>
> +struct bpf_prog;
> struct fbnic_net;
> +struct netlink_ext_ack;
> +struct xsk_buff_pool;
> +struct xsk_rx_check;
>
> /* Guarantee we have space needed for storing the buffer
> * To store the buffer we need:
> @@ -36,6 +40,8 @@ struct fbnic_net;
> */
> #define FBNIC_MAX_RX_PKT_DESC 7
> #define FBNIC_RX_DESC_MIN roundup_pow_of_two(FBNIC_MAX_RX_PKT_DESC * 2)
> +/* All descriptors of a packet but the two metadata ones */
> +#define FBNIC_MAX_RX_BUFS (FBNIC_MAX_RX_PKT_DESC - 2)
>
> #define FBNIC_MAX_TXQS 128u
> #define FBNIC_MAX_RXQS 128u
> @@ -66,6 +72,9 @@ struct fbnic_net;
> (ALIGN(FBNIC_RX_TROOM + FBNIC_RX_HROOM_PAD, 128) - FBNIC_RX_TROOM)
> #define FBNIC_RX_PAD 0
> #define FBNIC_RX_HDR_ALIGN 128
> +#define FBNIC_RX_HROOM_MAX \
> + ALIGN(FIELD_MAX(FBNIC_QUEUE_RDE_CTL0_MIN_HROOM_MASK), \
> + FBNIC_RX_HDR_ALIGN)
> #define FBNIC_RX_PAYLD_ALIGN 128
> #define FBNIC_RX_PAYLD_OFFSET 0
> #define FBNIC_RX_PAYLD_PG_CL 0
> @@ -73,6 +82,7 @@ struct fbnic_net;
> #define FBNIC_RING_F_DISABLED BIT(0)
> #define FBNIC_RING_F_CTX BIT(1)
> #define FBNIC_RING_F_STATS BIT(2) /* Ring's stats may be used */
> +#define FBNIC_RING_F_XDP BIT(3) /* XDP TX ring */
>
> #define FBNIC_HDS_THRESH_MAX \
> (4096 - FBNIC_RX_HROOM - FBNIC_RX_TROOM - FBNIC_RX_PAD)
> @@ -121,12 +131,18 @@ struct fbnic_rx_buf {
> long pagecnt_bias;
> };
>
> +/* XDP TX ring entry: an XDP_TX buffer, or an AF_XDP TX descriptor */
> +struct fbnic_xdp_tx_buf {
> + netmem_ref netmem;
> + struct xsk_buff_pool *xsk;
> +};
> +
> struct fbnic_ring {
> /* Pointer to buffer specific info */
> union {
> struct fbnic_pkt_buff *pkt; /* RCQ */
> struct fbnic_rx_buf *rx_buf; /* BDQ */
> - netmem_ref *tx_netmem; /* TWQ1 */
> + struct fbnic_xdp_tx_buf *xdp_buf; /* TWQ1 */
> void **tx_buf; /* TWQ */
> void *buffer; /* Generic pointer */
> };
> @@ -167,6 +183,10 @@ struct fbnic_q_triad {
> struct fbnic_ring sub0, sub1, cmpl;
> struct xdp_rxq_info xdp_rxq;
> u16 hdr_max; /* Header bytes for whole header buffers, or 0 */
> + u16 rx_hroom; /* Headroom before a header */
> + u16 rx_hdr_first; /* Offset of the first header in a buffer */
> + u16 rx_frame_off; /* Offset of the frame in a header buffer */
> + struct xsk_buff_pool *xsk_pool; /* AF_XDP pool of an RX queue */
> };
>
> struct fbnic_napi_vector {
> @@ -178,6 +198,7 @@ struct fbnic_napi_vector {
> u16 v_idx;
> u8 txt_count;
> u8 rxt_count;
> + u8 xsk_tx_next; /* RX queue that sends socket TX first */
>
> struct fbnic_q_triad qt[];
> };
> @@ -203,6 +224,8 @@ void fbnic_aggregate_ring_tx_counters(struct fbnic_net *fbn,
> void fbnic_aggregate_ring_xdp_counters(struct fbnic_net *fbn,
> struct fbnic_ring *xdpr);
>
> +int fbnic_xsk_validate(const struct xsk_rx_check *check,
> + struct bpf_prog *prog, struct netlink_ext_ack *extack);
> int fbnic_alloc_napi_vectors(struct fbnic_net *fbn);
> void fbnic_free_napi_vectors(struct fbnic_net *fbn);
> int fbnic_alloc_resources(struct fbnic_net *fbn);