Re: [PATCH net-next v1 10/11] eth: fbnic: Support RX buffers it cannot split
From: Dimitri Daskalakis
Date: Wed Nov 11 2026 - 16:46:15 EST
On 11/10/26 2:20 AM, Björn Töpel wrote:
> fbnic packs several headers, and several payloads, into one page. A
> provider without MP_CAP_FRAG needs one descriptor per buffer. Give
> such a buffer a single reference, program the queue so each header and
> payload takes a buffer of its own, and drop packets that break this.
>
> Header split is now set per queue, so link up changes only the drop
> mode.
>
> Signed-off-by: Björn Töpel <bjorn@xxxxxxxxxx>
> ---
> drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 119 ++++++++++++++++---
> drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 2 +
> 2 files changed, 102 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
> index bfaa284e497e..d96c957d6fba 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
> @@ -761,8 +761,14 @@ static void fbnic_page_pool_init(struct fbnic_ring *ring, unsigned int idx,
> {
> struct fbnic_rx_buf *rx_buf = &ring->rx_buf[idx];
>
> - page_pool_fragment_netmem(netmem, FBNIC_PAGECNT_BIAS_MAX);
> - rx_buf->pagecnt_bias = FBNIC_PAGECNT_BIAS_MAX;
> + /* A whole buffer has one reference. The packet takes it, so the buffer
> + * may be reused before its BDQ entry is cleaned.
> + */
> + rx_buf->pagecnt_bias = 1;
> + if (page_pool_supports_frag(ring->page_pool)) {
> + page_pool_fragment_netmem(netmem, FBNIC_PAGECNT_BIAS_MAX);
> + rx_buf->pagecnt_bias = FBNIC_PAGECNT_BIAS_MAX;
> + }
> rx_buf->netmem = netmem;
> }
>
> @@ -792,7 +798,8 @@ static void fbnic_page_pool_drain(struct fbnic_ring *ring, unsigned int idx,
> struct fbnic_rx_buf *rx_buf = &ring->rx_buf[idx];
> netmem_ref netmem = rx_buf->netmem;
>
> - if (!page_pool_unref_netmem(netmem, rx_buf->pagecnt_bias))
> + if (rx_buf->pagecnt_bias &&
> + !page_pool_unref_netmem(netmem, rx_buf->pagecnt_bias))
> page_pool_put_unrefed_netmem(ring->page_pool, netmem, -1,
> !!budget);
>
> @@ -993,6 +1000,19 @@ static unsigned int fbnic_hdr_pg_end(unsigned int pg_off, unsigned int len)
> return ALIGN(pg_off, 128) - FBNIC_RX_HROOM;
> }
>
> +/* A buffer that cannot be split has one reference and takes one descriptor */
> +static bool fbnic_bd_one_desc(struct fbnic_napi_vector *nv,
> + const struct fbnic_ring *bdq, unsigned int idx,
> + bool ok)
> +{
> + if (likely(page_pool_supports_frag(bdq->page_pool) ||
> + (bdq->rx_buf[idx].pagecnt_bias == 1 && ok)))
> + return true;
> +
> + netdev_err_once(nv->napi.dev, "Bad descriptor for a whole RX buffer\n");
> + return false;
> +}
> +
> static void fbnic_pkt_prepare(struct fbnic_napi_vector *nv, u64 rcd,
> struct fbnic_pkt_buff *pkt,
> struct fbnic_q_triad *qt)
> @@ -1007,6 +1027,17 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector *nv, u64 rcd,
> /* data_hard_start should always be NULL when this is called */
> WARN_ON_ONCE(pkt->buff.data_hard_start);
>
> + /* MAX_HDR leaves no room for a second header in a whole buffer, so
> + * the device closes it, with PAGE_FIN, after the first.
> + */
> + pkt->add_frag_failed = false;
> + if (unlikely(!fbnic_bd_one_desc(nv, &qt->sub0, hdr_pg_idx,
> + FIELD_GET(FBNIC_RCD_AL_PAGE_FIN,
> + rcd)))) {
> + pkt->add_frag_failed = true;
> + return;
> + }
> +
> netmem = fbnic_page_pool_get_head(qt, hdr_pg_idx);
> pkt->head = netmem;
>
> @@ -1032,7 +1063,6 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector *nv, u64 rcd,
> len - FBNIC_RX_PAD, true);
>
> pkt->hwtstamp = 0;
> - pkt->add_frag_failed = false;
> }
>
> static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd,
> @@ -1046,8 +1076,20 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd,
> netmem_ref netmem;
> bool added;
>
> + if (unlikely(!fbnic_bd_one_desc(nv, &qt->sub1, pg_idx, !pg_off))) {
> + pkt->add_frag_failed = true;
> + return;
> + }
> +
> netmem = fbnic_page_pool_get_data(qt, pg_idx);
>
> + /* Without a header buffer, the packet is dropped. */
> + if (unlikely(!pkt->buff.data_hard_start)) {
> + page_pool_put_full_netmem(qt->sub1.page_pool, netmem, true);
> + pkt->add_frag_failed = true;
> + return;
> + }
> +
How would we get in this state? Does the device need to misbehave and skip
the header descriptor?