From nobody Tue Apr 7 06:32:11 2026 Received: from mail.tipi-net.de (mail.tipi-net.de [194.13.80.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CB0137AA6F; Sun, 15 Mar 2026 21:50:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.13.80.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611409; cv=none; b=Eqy+0U/ORJGh4BTgDMFiMbvQRdrQ6/7TAhxZZCj4g0MVNet3DSGxNLuUv49adP7J/5PD6AhTeqbQVd0NV8kUh5baVfMMntTCEk2xMNWmDdLPtbzk8ThTuxEoVNLzmR8beBwp9L4/2abjKgqxNqU/o/djHB1ka2zWYPr7K0Weqt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611409; c=relaxed/simple; bh=1SaRQsAs6AsmEauiwUfVsXSX4Z++Q74EMJhzZndsZnc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pQMNJ3CjHiAkS62XyeOiujNJFFyBE4HBqbVBupv+GQh2WRjw0dpmCfz2/4Lqk/CQ51DVNZV9ZQQu3wiJW5tzSdVfzNf6zlDPaJA1FTo63Sgoza+7YVInjfZQcDFqgmuRgYIc3t1QJe1M4En+50aSrf4wFGu/rHyiH2tJOVdHer4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de; spf=pass smtp.mailfrom=tipi-net.de; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b=fWmBMz+I; arc=none smtp.client-ip=194.13.80.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b="fWmBMz+I" Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id F21ADA56FC; Sun, 15 Mar 2026 22:49:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tipi-net.de; s=dkim; t=1773611398; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=yKakVXrvFu5zd8knKYT6mpq6EoG49IT8UCNhqgyfI2Y=; b=fWmBMz+IMt+0AlWYXPBFfHTimgFy4/31h6a8CV0gVTchnidpipX87sndhslNJLpGztq1z0 hToSTF38SkxJNM6b1tfTQW+NHWVlu0uf0i0I5/OOk5DzTNgvZ6pN59WLSnYDksY9S+jXh3 lkUfNSsQycHwGbI83o1ZutZ9rkjRzN8os+RM1kBv6pqWebq6azwcfWy7kDCRCg4ccecZdN vP6iprkJ2sF/O8EdcUS0lw7lgcvUcfdACzB5FWO+cPmHb7sR3ld+bRl1/kd5898vRSI66C qDWoj7/zA4Kc4qBnUpxR5fhF3GrNGSpyA5p9IZk3LnjanEgoIIsdCSWHEHGS6Q== From: Nicolai Buchwitz To: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Doug Berger , Florian Fainelli Cc: Broadcom internal kernel review list , Vikas Gupta , Bhargava Marreddy , Rajashekar Hudumula , Eric Biggers , Heiner Kallweit , =?UTF-8?q?Markus=20Bl=C3=B6chl?= , Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Buchwitz Subject: [PATCH net-next v2 1/6] net: bcmgenet: convert RX path to page_pool Date: Sun, 15 Mar 2026 22:49:09 +0100 Message-ID: <20260315214914.1555777-2-nb@tipi-net.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260315214914.1555777-1-nb@tipi-net.de> References: <20260315214914.1555777-1-nb@tipi-net.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Replace the per-packet __netdev_alloc_skb() + dma_map_single() in the RX path with page_pool, which provides efficient page recycling and DMA mapping management. This is a prerequisite for XDP support (which requires stable page-backed buffers rather than SKB linear data). Key changes: - Create a page_pool per RX ring (PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV) - bcmgenet_rx_refill() allocates pages via page_pool_alloc_pages() - bcmgenet_desc_rx() builds SKBs from pages via napi_build_skb() with skb_mark_for_recycle() for automatic page_pool return - Buffer layout reserves XDP_PACKET_HEADROOM (256 bytes) before the HW RSB (64 bytes) + alignment pad (2 bytes) for future XDP headroom Signed-off-by: Nicolai Buchwitz --- drivers/net/ethernet/broadcom/Kconfig | 1 + .../net/ethernet/broadcom/genet/bcmgenet.c | 213 +++++++++++------- .../net/ethernet/broadcom/genet/bcmgenet.h | 4 + 3 files changed, 141 insertions(+), 77 deletions(-) diff --git a/drivers/net/ethernet/broadcom/Kconfig b/drivers/net/ethernet/b= roadcom/Kconfig index cd7dddeb91dd..e3b9a5272406 100644 --- a/drivers/net/ethernet/broadcom/Kconfig +++ b/drivers/net/ethernet/broadcom/Kconfig @@ -78,6 +78,7 @@ config BCMGENET select BCM7XXX_PHY select MDIO_BCM_UNIMAC select DIMLIB + select PAGE_POOL select BROADCOM_PHY if ARCH_BCM2835 help This driver supports the built-in Ethernet MACs found in the diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/e= thernet/broadcom/genet/bcmgenet.c index 482a31e7b72b..7410034d9bdc 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -52,6 +52,14 @@ #define RX_BUF_LENGTH 2048 #define SKB_ALIGNMENT 32 =20 +/* Page pool RX buffer layout: + * XDP_PACKET_HEADROOM | RSB(64) + pad(2) | frame data | skb_shared_info + * The HW writes the 64B RSB + 2B alignment padding before the frame. + */ +#define GENET_XDP_HEADROOM XDP_PACKET_HEADROOM +#define GENET_RSB_PAD (sizeof(struct status_64) + 2) +#define GENET_RX_HEADROOM (GENET_XDP_HEADROOM + GENET_RSB_PAD) + /* Tx/Rx DMA register offset, skip 256 descriptors */ #define WORDS_PER_BD(p) (p->hw_params->words_per_bd) #define DMA_DESC_SIZE (WORDS_PER_BD(priv) * sizeof(u32)) @@ -1895,21 +1903,13 @@ static struct sk_buff *bcmgenet_free_tx_cb(struct d= evice *dev, } =20 /* Simple helper to free a receive control block's resources */ -static struct sk_buff *bcmgenet_free_rx_cb(struct device *dev, - struct enet_cb *cb) +static void bcmgenet_free_rx_cb(struct enet_cb *cb, + struct page_pool *pool) { - struct sk_buff *skb; - - skb =3D cb->skb; - cb->skb =3D NULL; - - if (dma_unmap_addr(cb, dma_addr)) { - dma_unmap_single(dev, dma_unmap_addr(cb, dma_addr), - dma_unmap_len(cb, dma_len), DMA_FROM_DEVICE); - dma_unmap_addr_set(cb, dma_addr, 0); + if (cb->rx_page) { + page_pool_put_full_page(pool, cb->rx_page, false); + cb->rx_page =3D NULL; } - - return skb; } =20 /* Unlocked version of the reclaim routine */ @@ -2248,46 +2248,30 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *sk= b, struct net_device *dev) goto out; } =20 -static struct sk_buff *bcmgenet_rx_refill(struct bcmgenet_priv *priv, - struct enet_cb *cb) +static int bcmgenet_rx_refill(struct bcmgenet_rx_ring *ring, + struct enet_cb *cb) { - struct device *kdev =3D &priv->pdev->dev; - struct sk_buff *skb; - struct sk_buff *rx_skb; + struct bcmgenet_priv *priv =3D ring->priv; dma_addr_t mapping; + struct page *page; =20 - /* Allocate a new Rx skb */ - skb =3D __netdev_alloc_skb(priv->dev, priv->rx_buf_len + SKB_ALIGNMENT, - GFP_ATOMIC | __GFP_NOWARN); - if (!skb) { + page =3D page_pool_alloc_pages(ring->page_pool, + GFP_ATOMIC | __GFP_NOWARN); + if (!page) { priv->mib.alloc_rx_buff_failed++; netif_err(priv, rx_err, priv->dev, - "%s: Rx skb allocation failed\n", __func__); - return NULL; - } - - /* DMA-map the new Rx skb */ - mapping =3D dma_map_single(kdev, skb->data, priv->rx_buf_len, - DMA_FROM_DEVICE); - if (dma_mapping_error(kdev, mapping)) { - priv->mib.rx_dma_failed++; - dev_kfree_skb_any(skb); - netif_err(priv, rx_err, priv->dev, - "%s: Rx skb DMA mapping failed\n", __func__); - return NULL; + "%s: Rx page allocation failed\n", __func__); + return -ENOMEM; } =20 - /* Grab the current Rx skb from the ring and DMA-unmap it */ - rx_skb =3D bcmgenet_free_rx_cb(kdev, cb); + /* page_pool handles DMA mapping via PP_FLAG_DMA_MAP */ + mapping =3D page_pool_get_dma_addr(page) + GENET_XDP_HEADROOM; =20 - /* Put the new Rx skb on the ring */ - cb->skb =3D skb; - dma_unmap_addr_set(cb, dma_addr, mapping); - dma_unmap_len_set(cb, dma_len, priv->rx_buf_len); + cb->rx_page =3D page; + cb->rx_page_offset =3D GENET_XDP_HEADROOM; dmadesc_set_addr(priv, cb->bd_addr, mapping); =20 - /* Return the current Rx skb to caller */ - return rx_skb; + return 0; } =20 /* bcmgenet_desc_rx - descriptor based rx process. @@ -2339,25 +2323,28 @@ static unsigned int bcmgenet_desc_rx(struct bcmgene= t_rx_ring *ring, while ((rxpktprocessed < rxpkttoprocess) && (rxpktprocessed < budget)) { struct status_64 *status; + struct page *rx_page; + unsigned int rx_off; __be16 rx_csum; + void *hard_start; =20 cb =3D &priv->rx_cbs[ring->read_ptr]; - skb =3D bcmgenet_rx_refill(priv, cb); =20 - if (unlikely(!skb)) { + /* Save the received page before refilling */ + rx_page =3D cb->rx_page; + rx_off =3D cb->rx_page_offset; + + if (bcmgenet_rx_refill(ring, cb)) { BCMGENET_STATS64_INC(stats, dropped); goto next; } =20 - status =3D (struct status_64 *)skb->data; + page_pool_dma_sync_for_cpu(ring->page_pool, rx_page, 0, + RX_BUF_LENGTH); + + hard_start =3D page_address(rx_page) + rx_off; + status =3D (struct status_64 *)hard_start; dma_length_status =3D status->length_status; - if (dev->features & NETIF_F_RXCSUM) { - rx_csum =3D (__force __be16)(status->rx_csum & 0xffff); - if (rx_csum) { - skb->csum =3D (__force __wsum)ntohs(rx_csum); - skb->ip_summed =3D CHECKSUM_COMPLETE; - } - } =20 /* DMA flags and length are still valid no matter how * we got the Receive Status Vector (64B RSB or register) @@ -2373,7 +2360,8 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_= rx_ring *ring, if (unlikely(len > RX_BUF_LENGTH)) { netif_err(priv, rx_status, dev, "oversized packet\n"); BCMGENET_STATS64_INC(stats, length_errors); - dev_kfree_skb_any(skb); + page_pool_put_full_page(ring->page_pool, rx_page, + true); goto next; } =20 @@ -2381,7 +2369,8 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_= rx_ring *ring, netif_err(priv, rx_status, dev, "dropping fragmented packet!\n"); BCMGENET_STATS64_INC(stats, fragmented_errors); - dev_kfree_skb_any(skb); + page_pool_put_full_page(ring->page_pool, rx_page, + true); goto next; } =20 @@ -2409,24 +2398,48 @@ static unsigned int bcmgenet_desc_rx(struct bcmgene= t_rx_ring *ring, DMA_RX_RXER)) =3D=3D DMA_RX_RXER) u64_stats_inc(&stats->errors); u64_stats_update_end(&stats->syncp); - dev_kfree_skb_any(skb); + page_pool_put_full_page(ring->page_pool, rx_page, + true); goto next; } /* error packet */ =20 - skb_put(skb, len); + /* Build SKB from the page - data starts at hard_start, + * frame begins after RSB(64) + pad(2) =3D 66 bytes. + */ + skb =3D napi_build_skb(hard_start, PAGE_SIZE - GENET_XDP_HEADROOM); + if (unlikely(!skb)) { + BCMGENET_STATS64_INC(stats, dropped); + page_pool_put_full_page(ring->page_pool, rx_page, + true); + goto next; + } + + skb_mark_for_recycle(skb); =20 - /* remove RSB and hardware 2bytes added for IP alignment */ - skb_pull(skb, 66); - len -=3D 66; + /* Reserve the RSB + pad, then set the data length */ + skb_reserve(skb, GENET_RSB_PAD); + __skb_put(skb, len - GENET_RSB_PAD); =20 if (priv->crc_fwd_en) { - skb_trim(skb, len - ETH_FCS_LEN); + skb_trim(skb, skb->len - ETH_FCS_LEN); len -=3D ETH_FCS_LEN; } =20 + /* Set up checksum offload */ + if (dev->features & NETIF_F_RXCSUM) { + rx_csum =3D (__force __be16)(status->rx_csum & 0xffff); + if (rx_csum) { + skb->csum =3D (__force __wsum)ntohs(rx_csum); + skb->ip_summed =3D CHECKSUM_COMPLETE; + } + } + + len =3D skb->len; bytes_processed +=3D len; =20 - /*Finish setting up the received SKB and send it to the kernel*/ + /* Finish setting up the received SKB and send it to the + * kernel. + */ skb->protocol =3D eth_type_trans(skb, priv->dev); =20 u64_stats_update_begin(&stats->syncp); @@ -2495,12 +2508,11 @@ static void bcmgenet_dim_work(struct work_struct *w= ork) dim->state =3D DIM_START_MEASURE; } =20 -/* Assign skb to RX DMA descriptor. */ +/* Assign page_pool pages to RX DMA descriptors. */ static int bcmgenet_alloc_rx_buffers(struct bcmgenet_priv *priv, struct bcmgenet_rx_ring *ring) { struct enet_cb *cb; - struct sk_buff *skb; int i; =20 netif_dbg(priv, hw, priv->dev, "%s\n", __func__); @@ -2508,10 +2520,7 @@ static int bcmgenet_alloc_rx_buffers(struct bcmgenet= _priv *priv, /* loop here for each buffer needing assign */ for (i =3D 0; i < ring->size; i++) { cb =3D ring->cbs + i; - skb =3D bcmgenet_rx_refill(priv, cb); - if (skb) - dev_consume_skb_any(skb); - if (!cb->skb) + if (bcmgenet_rx_refill(ring, cb)) return -ENOMEM; } =20 @@ -2520,16 +2529,18 @@ static int bcmgenet_alloc_rx_buffers(struct bcmgene= t_priv *priv, =20 static void bcmgenet_free_rx_buffers(struct bcmgenet_priv *priv) { - struct sk_buff *skb; + struct bcmgenet_rx_ring *ring; struct enet_cb *cb; - int i; + int q, i; =20 - for (i =3D 0; i < priv->num_rx_bds; i++) { - cb =3D &priv->rx_cbs[i]; - - skb =3D bcmgenet_free_rx_cb(&priv->pdev->dev, cb); - if (skb) - dev_consume_skb_any(skb); + for (q =3D 0; q <=3D priv->hw_params->rx_queues; q++) { + ring =3D &priv->rx_rings[q]; + if (!ring->page_pool) + continue; + for (i =3D 0; i < ring->size; i++) { + cb =3D ring->cbs + i; + bcmgenet_free_rx_cb(cb, ring->page_pool); + } } } =20 @@ -2747,6 +2758,31 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_pr= iv *priv, netif_napi_add_tx(priv->dev, &ring->napi, bcmgenet_tx_poll); } =20 +static int bcmgenet_rx_ring_create_pool(struct bcmgenet_priv *priv, + struct bcmgenet_rx_ring *ring) +{ + struct page_pool_params pp_params =3D { + .order =3D 0, + .flags =3D PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .pool_size =3D ring->size, + .nid =3D NUMA_NO_NODE, + .dev =3D &priv->pdev->dev, + .dma_dir =3D DMA_FROM_DEVICE, + .offset =3D GENET_XDP_HEADROOM, + .max_len =3D RX_BUF_LENGTH, + }; + + ring->page_pool =3D page_pool_create(&pp_params); + if (IS_ERR(ring->page_pool)) { + int err =3D PTR_ERR(ring->page_pool); + + ring->page_pool =3D NULL; + return err; + } + + return 0; +} + /* Initialize a RDMA ring */ static int bcmgenet_init_rx_ring(struct bcmgenet_priv *priv, unsigned int index, unsigned int size, @@ -2765,10 +2801,17 @@ static int bcmgenet_init_rx_ring(struct bcmgenet_pr= iv *priv, ring->cb_ptr =3D start_ptr; ring->end_ptr =3D end_ptr - 1; =20 - ret =3D bcmgenet_alloc_rx_buffers(priv, ring); + ret =3D bcmgenet_rx_ring_create_pool(priv, ring); if (ret) return ret; =20 + ret =3D bcmgenet_alloc_rx_buffers(priv, ring); + if (ret) { + page_pool_destroy(ring->page_pool); + ring->page_pool =3D NULL; + return ret; + } + bcmgenet_init_dim(ring, bcmgenet_dim_work); bcmgenet_init_rx_coalesce(ring); =20 @@ -2961,6 +3004,20 @@ static void bcmgenet_fini_rx_napi(struct bcmgenet_pr= iv *priv) } } =20 +static void bcmgenet_destroy_rx_page_pools(struct bcmgenet_priv *priv) +{ + struct bcmgenet_rx_ring *ring; + unsigned int i; + + for (i =3D 0; i <=3D priv->hw_params->rx_queues; ++i) { + ring =3D &priv->rx_rings[i]; + if (ring->page_pool) { + page_pool_destroy(ring->page_pool); + ring->page_pool =3D NULL; + } + } +} + /* Initialize Rx queues * * Queues 0-15 are priority queues. Hardware Filtering Block (HFB) can be @@ -3032,6 +3089,7 @@ static void bcmgenet_fini_dma(struct bcmgenet_priv *p= riv) } =20 bcmgenet_free_rx_buffers(priv); + bcmgenet_destroy_rx_page_pools(priv); kfree(priv->rx_cbs); kfree(priv->tx_cbs); } @@ -3108,6 +3166,7 @@ static int bcmgenet_init_dma(struct bcmgenet_priv *pr= iv, bool flush_rx) if (ret) { netdev_err(priv->dev, "failed to initialize Rx queues\n"); bcmgenet_free_rx_buffers(priv); + bcmgenet_destroy_rx_page_pools(priv); kfree(priv->rx_cbs); kfree(priv->tx_cbs); return ret; diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/e= thernet/broadcom/genet/bcmgenet.h index 9e4110c7fdf6..11a0ec563a89 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h @@ -15,6 +15,7 @@ #include #include #include +#include =20 #include "../unimac.h" =20 @@ -469,6 +470,8 @@ struct bcmgenet_rx_stats64 { =20 struct enet_cb { struct sk_buff *skb; + struct page *rx_page; + unsigned int rx_page_offset; void __iomem *bd_addr; DEFINE_DMA_UNMAP_ADDR(dma_addr); DEFINE_DMA_UNMAP_LEN(dma_len); @@ -575,6 +578,7 @@ struct bcmgenet_rx_ring { struct bcmgenet_net_dim dim; u32 rx_max_coalesced_frames; u32 rx_coalesce_usecs; + struct page_pool *page_pool; struct bcmgenet_priv *priv; }; =20 --=20 2.51.0 From nobody Tue Apr 7 06:32:11 2026 Received: from mail.tipi-net.de (mail.tipi-net.de [194.13.80.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C3D437B3F2; Sun, 15 Mar 2026 21:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.13.80.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611409; cv=none; b=IyeJGLm9DXibkNHtE2N8LY1AkiGYSQTF77QtJDdHfHFOyf9affGk21I7ez3czdPs/CoyQPu7I+nRv8MmJGCY4tzYisPbg3uO8ci7w6A4PUFgDW7VFUVks4yX/MB49RXGB8jD2sqZqVPtA0ZD3YSM3nDHlZFiKsCsFYofgQjObpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611409; c=relaxed/simple; bh=fllZxkDRUNeCABiWG3jVqUjJSnmkYnXd6EO39R29dWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=itnza11CJO7ZHUlF+ytnBUF5i6K0/PUBmq+9P+UhxIbizVpOtNIrugW5wV/Im7Mm77xjdNIK8CreUxDcp7vJGvsjaPpZSyV2nZkye7EznVpFV9qZH46Aag5Q40rcXUAO7qJC1rVxj2CQH5V9tgI1Tfhu4zsepLUo4K+XkEBvNMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de; spf=pass smtp.mailfrom=tipi-net.de; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b=wsS+e1vp; arc=none smtp.client-ip=194.13.80.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b="wsS+e1vp" Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 803DCA5756; Sun, 15 Mar 2026 22:49:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tipi-net.de; s=dkim; t=1773611400; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=LrqSBjFg0lxjthVlm691SVDRHN7NxeZf6tRtCC91mf4=; b=wsS+e1vpTBJdOficIvno/j9VLLzvkVJxBM87kV0sQW/gAn3ks25kq4OU7LwWKxncfpdYpW Rb/z9l79eTJaV+7m3NtHvD+ztWkwkrgIx0C1upf0u88ADOTLfRMsHlZFaE+T7pVPqXZQeE 6OpilOZvCriOJE+lghICEf7ePMwNwrJMkNnSEnDaBIgKnKarXpm6Bcz6xFL8F1zxB4GxAi Il5U7aI9HoBwhlkxFvrvM8TFhTGo14mjpnWMHNJ2LvL7MSJ9DALtqTbHTMqhXboKHMsY5D Qu10VhhzJT/sqMuQjaiL4TeScKEyzhbGKanxT4vuqKPVDM11NV5q/OL1Dp3WNA== From: Nicolai Buchwitz To: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Doug Berger , Florian Fainelli Cc: Broadcom internal kernel review list , Vikas Gupta , Bhargava Marreddy , Rajashekar Hudumula , Eric Biggers , Heiner Kallweit , =?UTF-8?q?Markus=20Bl=C3=B6chl?= , Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Buchwitz Subject: [PATCH net-next v2 2/6] net: bcmgenet: register xdp_rxq_info for each RX ring Date: Sun, 15 Mar 2026 22:49:10 +0100 Message-ID: <20260315214914.1555777-3-nb@tipi-net.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260315214914.1555777-1-nb@tipi-net.de> References: <20260315214914.1555777-1-nb@tipi-net.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Register an xdp_rxq_info per RX ring and associate it with the ring's page_pool via MEM_TYPE_PAGE_POOL. This is required infrastructure for XDP program execution: the XDP framework needs to know the memory model backing each RX queue for correct page lifecycle management. No functional change - XDP programs are not yet attached or executed. Signed-off-by: Nicolai Buchwitz --- .../net/ethernet/broadcom/genet/bcmgenet.c | 22 +++++++++++++++++-- .../net/ethernet/broadcom/genet/bcmgenet.h | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/e= thernet/broadcom/genet/bcmgenet.c index 7410034d9bdc..6e610e73e12f 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -2771,16 +2771,32 @@ static int bcmgenet_rx_ring_create_pool(struct bcmg= enet_priv *priv, .offset =3D GENET_XDP_HEADROOM, .max_len =3D RX_BUF_LENGTH, }; + int err; =20 ring->page_pool =3D page_pool_create(&pp_params); if (IS_ERR(ring->page_pool)) { - int err =3D PTR_ERR(ring->page_pool); - + err =3D PTR_ERR(ring->page_pool); ring->page_pool =3D NULL; return err; } =20 + err =3D xdp_rxq_info_reg(&ring->xdp_rxq, priv->dev, ring->index, 0); + if (err) + goto err_free_pp; + + err =3D xdp_rxq_info_reg_mem_model(&ring->xdp_rxq, MEM_TYPE_PAGE_POOL, + ring->page_pool); + if (err) + goto err_unreg_rxq; + return 0; + +err_unreg_rxq: + xdp_rxq_info_unreg(&ring->xdp_rxq); +err_free_pp: + page_pool_destroy(ring->page_pool); + ring->page_pool =3D NULL; + return err; } =20 /* Initialize a RDMA ring */ @@ -2807,6 +2823,7 @@ static int bcmgenet_init_rx_ring(struct bcmgenet_priv= *priv, =20 ret =3D bcmgenet_alloc_rx_buffers(priv, ring); if (ret) { + xdp_rxq_info_unreg(&ring->xdp_rxq); page_pool_destroy(ring->page_pool); ring->page_pool =3D NULL; return ret; @@ -3012,6 +3029,7 @@ static void bcmgenet_destroy_rx_page_pools(struct bcm= genet_priv *priv) for (i =3D 0; i <=3D priv->hw_params->rx_queues; ++i) { ring =3D &priv->rx_rings[i]; if (ring->page_pool) { + xdp_rxq_info_unreg(&ring->xdp_rxq); page_pool_destroy(ring->page_pool); ring->page_pool =3D NULL; } diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/e= thernet/broadcom/genet/bcmgenet.h index 11a0ec563a89..82a6d29f481d 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h @@ -16,6 +16,7 @@ #include #include #include +#include =20 #include "../unimac.h" =20 @@ -579,6 +580,7 @@ struct bcmgenet_rx_ring { u32 rx_max_coalesced_frames; u32 rx_coalesce_usecs; struct page_pool *page_pool; + struct xdp_rxq_info xdp_rxq; struct bcmgenet_priv *priv; }; =20 --=20 2.51.0 From nobody Tue Apr 7 06:32:11 2026 Received: from mail.tipi-net.de (mail.tipi-net.de [194.13.80.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86E6F361DA6; Sun, 15 Mar 2026 21:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.13.80.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611410; cv=none; b=tkf2pNQEm30iwkuAhZB+WjcwCpjZuCwMcevISqKsZjng6VQS9oxpeV4ZmE3m7We++q3Bbtvo92bWCMbNPyH4b4qAsEsESjSX8MeoVUKMPU+M7uyU/xY6hdkd3IPqaJO69HMbuj6PXWw//L+w8NlQHOpy9xIn/NBl2GKp4SfU0Co= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611410; c=relaxed/simple; bh=dLyQvrmelxX5rPYf+Z7dIvU7jjdKNoJGtsp7q3G4HVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ER8ThJ7hP0HypW/0rWuhTdw7TqYgpmBpk8qmPypKbBGAnMIajf2VTtHDVRHON36FrJl1zI3wqOixigquhceJwDPxnCaqScLXzb6xWGHssKCQuYqxi9xneRivpwr3zRTKv973Cal7m4nR3tu37TDQTw9pt8WWchf8hyC7M7IkR68= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de; spf=pass smtp.mailfrom=tipi-net.de; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b=qnPD9eSg; arc=none smtp.client-ip=194.13.80.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b="qnPD9eSg" Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 876A9A5757; Sun, 15 Mar 2026 22:50:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tipi-net.de; s=dkim; t=1773611401; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=GSjVQ99FjW9fBgU4jn6obEg8PFuexxeGyDGCgqUWONU=; b=qnPD9eSgCrhB4/WhUUhLVqSLbnI1w3xa+6aTB+2empP0b+Brp91+6db+s8xwgUBlk364N/ ff3ui1CEuxwXuKhBxCEE7OtTNzz3rADzd5fVqviJKInjnLg36DTLV32nGASUGN5dah8aZu xl9oW1BJ1tTf6mKlsDfdbVa9W8zdm0T9aCZRkzlgdpsX/O/xEXy7+f1tYDNUCGaBzfrGw0 T2mrugPJ3G1OLdB3V8eMfwCOZDT/GIH6Gv4ITPmHaZY/tStiTgcrMGOBVL4woWZEjkUNQa RVPsRIBMBTn1lxdsSjkzFB1CThUgJwFcYBOClG0+SVYxDfk9D6NycT0pWJqjag== From: Nicolai Buchwitz To: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Doug Berger , Florian Fainelli Cc: Broadcom internal kernel review list , Vikas Gupta , Bhargava Marreddy , Rajashekar Hudumula , Eric Biggers , Heiner Kallweit , =?UTF-8?q?Markus=20Bl=C3=B6chl?= , Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Buchwitz Subject: [PATCH net-next v2 3/6] net: bcmgenet: add basic XDP support (PASS/DROP) Date: Sun, 15 Mar 2026 22:49:11 +0100 Message-ID: <20260315214914.1555777-4-nb@tipi-net.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260315214914.1555777-1-nb@tipi-net.de> References: <20260315214914.1555777-1-nb@tipi-net.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Add XDP program attachment via ndo_bpf and execute XDP programs in the RX path. XDP_PASS builds an SKB from the xdp_buff (handling xdp_adjust_head/tail), XDP_DROP returns the page to page_pool without SKB allocation. XDP_TX and XDP_REDIRECT are not yet supported and return XDP_ABORTED. Advertise NETDEV_XDP_ACT_BASIC in xdp_features. Signed-off-by: Nicolai Buchwitz --- .../net/ethernet/broadcom/genet/bcmgenet.c | 147 +++++++++++++++--- .../net/ethernet/broadcom/genet/bcmgenet.h | 4 + 2 files changed, 133 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/e= thernet/broadcom/genet/bcmgenet.c index 6e610e73e12f..f6a2567af7cb 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include =20 #include =20 @@ -2274,6 +2276,53 @@ static int bcmgenet_rx_refill(struct bcmgenet_rx_rin= g *ring, return 0; } =20 +static struct sk_buff *bcmgenet_xdp_build_skb(struct bcmgenet_rx_ring *rin= g, + struct xdp_buff *xdp, + struct page *rx_page) +{ + unsigned int metasize; + struct sk_buff *skb; + + skb =3D napi_build_skb(xdp->data_hard_start, PAGE_SIZE); + if (unlikely(!skb)) + return NULL; + + skb_mark_for_recycle(skb); + + metasize =3D xdp->data - xdp->data_meta; + skb_reserve(skb, xdp->data - xdp->data_hard_start); + __skb_put(skb, xdp->data_end - xdp->data); + + if (metasize) + skb_metadata_set(skb, metasize); + + return skb; +} + +static unsigned int +bcmgenet_run_xdp(struct bcmgenet_rx_ring *ring, struct bpf_prog *prog, + struct xdp_buff *xdp, struct page *rx_page) +{ + unsigned int act; + + act =3D bpf_prog_run_xdp(prog, xdp); + + switch (act) { + case XDP_PASS: + return XDP_PASS; + case XDP_DROP: + page_pool_put_full_page(ring->page_pool, rx_page, true); + return XDP_DROP; + default: + bpf_warn_invalid_xdp_action(ring->priv->dev, prog, act); + fallthrough; + case XDP_ABORTED: + trace_xdp_exception(ring->priv->dev, prog, act); + page_pool_put_full_page(ring->page_pool, rx_page, true); + return XDP_ABORTED; + } +} + /* bcmgenet_desc_rx - descriptor based rx process. * this could be called from bottom half, or from NAPI polling method. */ @@ -2283,6 +2332,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_= rx_ring *ring, struct bcmgenet_rx_stats64 *stats =3D &ring->stats64; struct bcmgenet_priv *priv =3D ring->priv; struct net_device *dev =3D priv->dev; + struct bpf_prog *xdp_prog; struct enet_cb *cb; struct sk_buff *skb; u32 dma_length_status; @@ -2293,6 +2343,8 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_= rx_ring *ring, unsigned int p_index, mask; unsigned int discards; =20 + xdp_prog =3D READ_ONCE(priv->xdp_prog); + /* Clear status before servicing to reduce spurious interrupts */ mask =3D 1 << (UMAC_IRQ1_RX_INTR_SHIFT + ring->index); bcmgenet_intrl2_1_writel(priv, mask, INTRL2_CPU_CLEAR); @@ -2403,26 +2455,52 @@ static unsigned int bcmgenet_desc_rx(struct bcmgene= t_rx_ring *ring, goto next; } /* error packet */ =20 - /* Build SKB from the page - data starts at hard_start, - * frame begins after RSB(64) + pad(2) =3D 66 bytes. - */ - skb =3D napi_build_skb(hard_start, PAGE_SIZE - GENET_XDP_HEADROOM); - if (unlikely(!skb)) { - BCMGENET_STATS64_INC(stats, dropped); - page_pool_put_full_page(ring->page_pool, rx_page, - true); - goto next; - } - - skb_mark_for_recycle(skb); + /* XDP: frame data starts after RSB + pad */ + if (xdp_prog) { + struct xdp_buff xdp; + unsigned int xdp_act; + int pkt_len; + + pkt_len =3D len - GENET_RSB_PAD; + if (priv->crc_fwd_en) + pkt_len -=3D ETH_FCS_LEN; + + xdp_init_buff(&xdp, PAGE_SIZE, &ring->xdp_rxq); + xdp_prepare_buff(&xdp, page_address(rx_page), + GENET_RX_HEADROOM, pkt_len, false); + + xdp_act =3D bcmgenet_run_xdp(ring, xdp_prog, &xdp, + rx_page); + if (xdp_act !=3D XDP_PASS) + goto next; + + /* XDP_PASS: build SKB from (possibly modified) xdp */ + skb =3D bcmgenet_xdp_build_skb(ring, &xdp, rx_page); + if (unlikely(!skb)) { + BCMGENET_STATS64_INC(stats, dropped); + page_pool_put_full_page(ring->page_pool, + rx_page, true); + goto next; + } + } else { + /* Build SKB from the page - data starts at + * hard_start, frame begins after RSB(64) + pad(2). + */ + skb =3D napi_build_skb(hard_start, + PAGE_SIZE - GENET_XDP_HEADROOM); + if (unlikely(!skb)) { + BCMGENET_STATS64_INC(stats, dropped); + page_pool_put_full_page(ring->page_pool, + rx_page, true); + goto next; + } =20 - /* Reserve the RSB + pad, then set the data length */ - skb_reserve(skb, GENET_RSB_PAD); - __skb_put(skb, len - GENET_RSB_PAD); + skb_mark_for_recycle(skb); + skb_reserve(skb, GENET_RSB_PAD); + __skb_put(skb, len - GENET_RSB_PAD); =20 - if (priv->crc_fwd_en) { - skb_trim(skb, skb->len - ETH_FCS_LEN); - len -=3D ETH_FCS_LEN; + if (priv->crc_fwd_en) + skb_trim(skb, skb->len - ETH_FCS_LEN); } =20 /* Set up checksum offload */ @@ -3743,6 +3821,37 @@ static int bcmgenet_change_carrier(struct net_device= *dev, bool new_carrier) return 0; } =20 +static int bcmgenet_xdp_setup(struct net_device *dev, + struct netdev_bpf *xdp) +{ + struct bcmgenet_priv *priv =3D netdev_priv(dev); + struct bpf_prog *old_prog; + struct bpf_prog *prog =3D xdp->prog; + + if (prog && dev->mtu > PAGE_SIZE - GENET_RX_HEADROOM - + SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) { + NL_SET_ERR_MSG_MOD(xdp->extack, + "MTU too large for single-page XDP buffer"); + return -EOPNOTSUPP; + } + + old_prog =3D xchg(&priv->xdp_prog, prog); + if (old_prog) + bpf_prog_put(old_prog); + + return 0; +} + +static int bcmgenet_xdp(struct net_device *dev, struct netdev_bpf *xdp) +{ + switch (xdp->command) { + case XDP_SETUP_PROG: + return bcmgenet_xdp_setup(dev, xdp); + default: + return -EOPNOTSUPP; + } +} + static const struct net_device_ops bcmgenet_netdev_ops =3D { .ndo_open =3D bcmgenet_open, .ndo_stop =3D bcmgenet_close, @@ -3754,6 +3863,7 @@ static const struct net_device_ops bcmgenet_netdev_op= s =3D { .ndo_set_features =3D bcmgenet_set_features, .ndo_get_stats64 =3D bcmgenet_get_stats64, .ndo_change_carrier =3D bcmgenet_change_carrier, + .ndo_bpf =3D bcmgenet_xdp, }; =20 /* GENET hardware parameters/characteristics */ @@ -4056,6 +4166,7 @@ static int bcmgenet_probe(struct platform_device *pde= v) NETIF_F_RXCSUM; dev->hw_features |=3D dev->features; dev->vlan_features |=3D dev->features; + dev->xdp_features =3D NETDEV_XDP_ACT_BASIC; =20 netdev_sw_irq_coalesce_default_on(dev); =20 diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/e= thernet/broadcom/genet/bcmgenet.h index 82a6d29f481d..1459473ac1b0 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h @@ -16,6 +16,7 @@ #include #include #include +#include #include =20 #include "../unimac.h" @@ -671,6 +672,9 @@ struct bcmgenet_priv { u8 sopass[SOPASS_MAX]; =20 struct bcmgenet_mib_counters mib; + + /* XDP */ + struct bpf_prog *xdp_prog; }; =20 static inline bool bcmgenet_has_40bits(struct bcmgenet_priv *priv) --=20 2.51.0 From nobody Tue Apr 7 06:32:11 2026 Received: from mail.tipi-net.de (mail.tipi-net.de [194.13.80.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F4DB37D105; Sun, 15 Mar 2026 21:50:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.13.80.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611411; cv=none; b=WsqDBORIrwRQlM48S3rfUxHB4jAcKRjWGELvWIqZ3hH+q11j2ANWbgVRtRglzQhiGlMrSxsVBbjvu4zXr95NMpcHL30PE60rraDgEzTJYq6pQ+IQQ/+Y4hKXeLujnjM05u2uSzeh6Xwtbvng8+Zbx45ZaS3H4aS4i1KAd9f8iTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611411; c=relaxed/simple; bh=aJOGlYQe7B/Q73hn3s1IESLOLRjf3cZ3ejeZyozSD6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XL7dELu6ezagQ0PC0AWVoS8OpwGTyAZ02WOV1xM0JASEDh4pFMHo7kUju/aMNbLGc02YoR4cur3gGb06M9NTgNIgIJ0njDX3Hof4xoDpM1muOgJiHkbHB7XJztS0dCamM1iJH5754UIkKfrOwVQRFbvK/TavdRZiAcgcfzav5lY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de; spf=pass smtp.mailfrom=tipi-net.de; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b=eawePA74; arc=none smtp.client-ip=194.13.80.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b="eawePA74" Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 73E40A575A; Sun, 15 Mar 2026 22:50:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tipi-net.de; s=dkim; t=1773611402; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=frIijmZ7c1jazOGnzirhHcM5mgbZTKjNXVAkfOsesIM=; b=eawePA74IwUHFisdGgiDI2dSuntI4KdPfNrV++LDRdUW8EeuyvnaD7brw4bROp9l9Z2HSf ZKW1GWFzTOEJ9vo7wQp7wN9led/vqya5uWU8jQEZSd9ySF2a7z0nRb4yX7L0/YoO84YbEH bTXZ/WWJ7AhEGNa4Zkakz/fjRS8iVlwMLmXCN1a6H0E5xWzUIiiDybZcT/BTylipzQVfyC 4dWBP1oZkCVD/LwbSh4NiL9HE2w8O0QG4+odD1MTDN9K3ONLkf9nPXnqS2mJt/R6s7Q+M7 OSBI9aYKt6azSCLy+zNlwPcGbGgvk6x8f0pStXN+fqRsQ5DZgMBHJJ2+myJ7tQ== From: Nicolai Buchwitz To: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Doug Berger , Florian Fainelli Cc: Broadcom internal kernel review list , Vikas Gupta , Bhargava Marreddy , Rajashekar Hudumula , Eric Biggers , Heiner Kallweit , =?UTF-8?q?Markus=20Bl=C3=B6chl?= , Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Buchwitz Subject: [PATCH net-next v2 4/6] net: bcmgenet: add XDP_TX support Date: Sun, 15 Mar 2026 22:49:12 +0100 Message-ID: <20260315214914.1555777-5-nb@tipi-net.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260315214914.1555777-1-nb@tipi-net.de> References: <20260315214914.1555777-1-nb@tipi-net.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Implement XDP_TX using ring 16 (DESC_INDEX), the hardware default descriptor ring, dedicated to XDP TX for isolation from SKB TX queues. Ring 16 gets 32 BDs carved from ring 0's allocation. TX completion is piggybacked on RX NAPI poll since ring 16's INTRL2_1 bit collides with RX ring 0, similar to how bnxt, ice, and other XDP drivers handle TX completion within the RX poll path. The GENET MAC has TBUF_64B_EN set globally, requiring every TX buffer to start with a 64-byte struct status_64 (TSB). For local XDP_TX, the TSB is prepended by backing xdp->data into the RSB area (unused after BPF execution) and zeroing it. For foreign frames (ndo_xdp_xmit), the TSB is written into the xdp_frame headroom. The page_pool DMA direction is changed from DMA_FROM_DEVICE to DMA_BIDIRECTIONAL to allow TX reuse of the existing DMA mapping. Signed-off-by: Nicolai Buchwitz --- .../net/ethernet/broadcom/genet/bcmgenet.c | 196 ++++++++++++++++-- .../net/ethernet/broadcom/genet/bcmgenet.h | 4 +- 2 files changed, 182 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/e= thernet/broadcom/genet/bcmgenet.c index f6a2567af7cb..922895bc7461 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -48,8 +48,10 @@ =20 #define GENET_Q0_RX_BD_CNT \ (TOTAL_DESC - priv->hw_params->rx_queues * priv->hw_params->rx_bds_per_q) +#define GENET_Q16_TX_BD_CNT 32 #define GENET_Q0_TX_BD_CNT \ - (TOTAL_DESC - priv->hw_params->tx_queues * priv->hw_params->tx_bds_per_q) + (TOTAL_DESC - priv->hw_params->tx_queues * priv->hw_params->tx_bds_per_q \ + - GENET_Q16_TX_BD_CNT) =20 #define RX_BUF_LENGTH 2048 #define SKB_ALIGNMENT 32 @@ -1893,6 +1895,14 @@ static struct sk_buff *bcmgenet_free_tx_cb(struct de= vice *dev, if (cb =3D=3D GENET_CB(skb)->last_cb) return skb; =20 + } else if (cb->xdpf) { + if (cb->xdp_dma_map) + dma_unmap_single(dev, dma_unmap_addr(cb, dma_addr), + dma_unmap_len(cb, dma_len), + DMA_TO_DEVICE); + dma_unmap_addr_set(cb, dma_addr, 0); + xdp_return_frame(cb->xdpf); + cb->xdpf =3D NULL; } else if (dma_unmap_addr(cb, dma_addr)) { dma_unmap_page(dev, dma_unmap_addr(cb, dma_addr), @@ -1927,8 +1937,13 @@ static unsigned int __bcmgenet_tx_reclaim(struct net= _device *dev, unsigned int c_index; struct sk_buff *skb; =20 - /* Clear status before servicing to reduce spurious interrupts */ - bcmgenet_intrl2_1_writel(priv, (1 << ring->index), INTRL2_CPU_CLEAR); + /* Clear status before servicing to reduce spurious interrupts. + * Ring DESC_INDEX (XDP TX) has no interrupt; skip the clear to + * avoid clobbering RX ring 0's bit at the same position. + */ + if (ring->index !=3D DESC_INDEX) + bcmgenet_intrl2_1_writel(priv, (1 << ring->index), + INTRL2_CPU_CLEAR); =20 /* Compute how many buffers are transmitted since last xmit call */ c_index =3D bcmgenet_tdma_ring_readl(priv, ring->index, TDMA_CONS_INDEX) @@ -1964,8 +1979,11 @@ static unsigned int __bcmgenet_tx_reclaim(struct net= _device *dev, u64_stats_add(&stats->bytes, bytes_compl); u64_stats_update_end(&stats->syncp); =20 - netdev_tx_completed_queue(netdev_get_tx_queue(dev, ring->index), - pkts_compl, bytes_compl); + /* Ring DESC_INDEX (XDP TX) has no netdev TX queue; skip BQL */ + if (ring->index !=3D DESC_INDEX) + netdev_tx_completed_queue( + netdev_get_tx_queue(dev, ring->index), + pkts_compl, bytes_compl); =20 return txbds_processed; } @@ -2042,6 +2060,9 @@ static void bcmgenet_tx_reclaim_all(struct net_device= *dev) do { bcmgenet_tx_reclaim(dev, &priv->tx_rings[i++], true); } while (i <=3D priv->hw_params->tx_queues && netif_is_multiqueue(dev)); + + /* Also reclaim XDP TX ring */ + bcmgenet_tx_reclaim(dev, &priv->tx_rings[DESC_INDEX], true); } =20 /* Reallocate the SKB to put enough headroom in front of it and insert @@ -2299,10 +2320,96 @@ static struct sk_buff *bcmgenet_xdp_build_skb(struc= t bcmgenet_rx_ring *ring, return skb; } =20 +static bool bcmgenet_xdp_xmit_frame(struct bcmgenet_priv *priv, + struct xdp_frame *xdpf, + bool dma_map) +{ + struct bcmgenet_tx_ring *ring =3D &priv->tx_rings[DESC_INDEX]; + struct device *kdev =3D &priv->pdev->dev; + struct enet_cb *tx_cb_ptr; + dma_addr_t mapping; + unsigned int dma_len; + u32 len_stat; + + spin_lock(&ring->lock); + + if (ring->free_bds < 1) { + spin_unlock(&ring->lock); + return false; + } + + tx_cb_ptr =3D bcmgenet_get_txcb(priv, ring); + + if (dma_map) { + void *tsb_start; + + /* The GENET MAC has TBUF_64B_EN set globally, so hardware + * expects a 64-byte TSB prefix on every TX buffer. For + * redirected frames (ndo_xdp_xmit) we prepend a zeroed TSB + * using the frame's headroom. + */ + if (unlikely(xdpf->headroom < sizeof(struct status_64))) { + bcmgenet_put_txcb(priv, ring); + spin_unlock(&ring->lock); + return false; + } + + tsb_start =3D xdpf->data - sizeof(struct status_64); + memset(tsb_start, 0, sizeof(struct status_64)); + + dma_len =3D xdpf->len + sizeof(struct status_64); + mapping =3D dma_map_single(kdev, tsb_start, dma_len, + DMA_TO_DEVICE); + if (dma_mapping_error(kdev, mapping)) { + tx_cb_ptr->skb =3D NULL; + tx_cb_ptr->xdpf =3D NULL; + bcmgenet_put_txcb(priv, ring); + spin_unlock(&ring->lock); + return false; + } + } else { + struct page *page =3D virt_to_page(xdpf->data); + + /* For local XDP_TX the caller already prepended the TSB + * into xdpf->data/len, so dma_len =3D=3D xdpf->len. + */ + dma_len =3D xdpf->len; + mapping =3D page_pool_get_dma_addr(page) + + sizeof(*xdpf) + xdpf->headroom; + dma_sync_single_for_device(kdev, mapping, dma_len, + DMA_BIDIRECTIONAL); + } + + dma_unmap_addr_set(tx_cb_ptr, dma_addr, mapping); + dma_unmap_len_set(tx_cb_ptr, dma_len, dma_len); + tx_cb_ptr->skb =3D NULL; + tx_cb_ptr->xdpf =3D xdpf; + tx_cb_ptr->xdp_dma_map =3D dma_map; + + len_stat =3D (dma_len << DMA_BUFLENGTH_SHIFT) | + (priv->hw_params->qtag_mask << DMA_TX_QTAG_SHIFT) | + DMA_TX_APPEND_CRC | DMA_SOP | DMA_EOP; + + dmadesc_set(priv, tx_cb_ptr->bd_addr, mapping, len_stat); + + ring->free_bds--; + ring->prod_index++; + ring->prod_index &=3D DMA_P_INDEX_MASK; + + bcmgenet_tdma_ring_writel(priv, ring->index, ring->prod_index, + TDMA_PROD_INDEX); + + spin_unlock(&ring->lock); + + return true; +} + static unsigned int bcmgenet_run_xdp(struct bcmgenet_rx_ring *ring, struct bpf_prog *prog, struct xdp_buff *xdp, struct page *rx_page) { + struct bcmgenet_priv *priv =3D ring->priv; + struct xdp_frame *xdpf; unsigned int act; =20 act =3D bpf_prog_run_xdp(prog, xdp); @@ -2310,14 +2417,33 @@ bcmgenet_run_xdp(struct bcmgenet_rx_ring *ring, str= uct bpf_prog *prog, switch (act) { case XDP_PASS: return XDP_PASS; + case XDP_TX: + /* Prepend a zeroed TSB (Transmit Status Block). The GENET + * MAC has TBUF_64B_EN set globally, so hardware expects every + * TX buffer to begin with a 64-byte struct status_64. Back + * up xdp->data into the RSB area (which is no longer needed + * after the BPF program ran) and zero it. + */ + xdp->data -=3D sizeof(struct status_64); + xdp->data_meta -=3D sizeof(struct status_64); + memset(xdp->data, 0, sizeof(struct status_64)); + + xdpf =3D xdp_convert_buff_to_frame(xdp); + if (unlikely(!xdpf) || + unlikely(!bcmgenet_xdp_xmit_frame(priv, xdpf, false))) { + page_pool_put_full_page(ring->page_pool, rx_page, + true); + return XDP_DROP; + } + return XDP_TX; case XDP_DROP: page_pool_put_full_page(ring->page_pool, rx_page, true); return XDP_DROP; default: - bpf_warn_invalid_xdp_action(ring->priv->dev, prog, act); + bpf_warn_invalid_xdp_action(priv->dev, prog, act); fallthrough; case XDP_ABORTED: - trace_xdp_exception(ring->priv->dev, prog, act); + trace_xdp_exception(priv->dev, prog, act); page_pool_put_full_page(ring->page_pool, rx_page, true); return XDP_ABORTED; } @@ -2555,9 +2681,15 @@ static int bcmgenet_rx_poll(struct napi_struct *napi= , int budget) { struct bcmgenet_rx_ring *ring =3D container_of(napi, struct bcmgenet_rx_ring, napi); + struct bcmgenet_priv *priv =3D ring->priv; struct dim_sample dim_sample =3D {}; unsigned int work_done; =20 + /* Reclaim completed XDP TX frames (ring 16 has no interrupt) */ + if (priv->xdp_prog) + bcmgenet_tx_reclaim(priv->dev, + &priv->tx_rings[DESC_INDEX], false); + work_done =3D bcmgenet_desc_rx(ring, budget); =20 if (work_done < budget && napi_complete_done(napi, work_done)) @@ -2832,8 +2964,11 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_pr= iv *priv, bcmgenet_tdma_ring_writel(priv, index, end_ptr * words_per_bd - 1, DMA_END_ADDR); =20 - /* Initialize Tx NAPI */ - netif_napi_add_tx(priv->dev, &ring->napi, bcmgenet_tx_poll); + /* Initialize Tx NAPI for priority queues only; ring DESC_INDEX + * (XDP TX) has its completions handled inline in RX NAPI. + */ + if (index !=3D DESC_INDEX) + netif_napi_add_tx(priv->dev, &ring->napi, bcmgenet_tx_poll); } =20 static int bcmgenet_rx_ring_create_pool(struct bcmgenet_priv *priv, @@ -2845,7 +2980,7 @@ static int bcmgenet_rx_ring_create_pool(struct bcmgen= et_priv *priv, .pool_size =3D ring->size, .nid =3D NUMA_NO_NODE, .dev =3D &priv->pdev->dev, - .dma_dir =3D DMA_FROM_DEVICE, + .dma_dir =3D DMA_BIDIRECTIONAL, .offset =3D GENET_XDP_HEADROOM, .max_len =3D RX_BUF_LENGTH, }; @@ -2977,6 +3112,7 @@ static int bcmgenet_tdma_disable(struct bcmgenet_priv= *priv) =20 reg =3D bcmgenet_tdma_readl(priv, DMA_CTRL); mask =3D (1 << (priv->hw_params->tx_queues + 1)) - 1; + mask |=3D BIT(DESC_INDEX); mask =3D (mask << DMA_RING_BUF_EN_SHIFT) | DMA_EN; reg &=3D ~mask; bcmgenet_tdma_writel(priv, reg, DMA_CTRL); @@ -3022,14 +3158,18 @@ static int bcmgenet_rdma_disable(struct bcmgenet_pr= iv *priv) * with queue 1 being the highest priority queue. * * Queue 0 is the default Tx queue with - * GENET_Q0_TX_BD_CNT =3D 256 - 4 * 32 =3D 128 descriptors. + * GENET_Q0_TX_BD_CNT =3D 256 - 4 * 32 - 32 =3D 96 descriptors. + * + * Ring 16 (DESC_INDEX) is used for XDP TX with + * GENET_Q16_TX_BD_CNT =3D 32 descriptors. * * The transmit control block pool is then partitioned as follows: - * - Tx queue 0 uses tx_cbs[0..127] - * - Tx queue 1 uses tx_cbs[128..159] - * - Tx queue 2 uses tx_cbs[160..191] - * - Tx queue 3 uses tx_cbs[192..223] - * - Tx queue 4 uses tx_cbs[224..255] + * - Tx queue 0 uses tx_cbs[0..95] + * - Tx queue 1 uses tx_cbs[96..127] + * - Tx queue 2 uses tx_cbs[128..159] + * - Tx queue 3 uses tx_cbs[160..191] + * - Tx queue 4 uses tx_cbs[192..223] + * - Tx ring 16 uses tx_cbs[224..255] */ static void bcmgenet_init_tx_queues(struct net_device *dev) { @@ -3050,13 +3190,18 @@ static void bcmgenet_init_tx_queues(struct net_devi= ce *dev) << DMA_PRIO_REG_SHIFT(i); } =20 + /* Initialize ring 16 (descriptor ring) for XDP TX */ + bcmgenet_init_tx_ring(priv, DESC_INDEX, GENET_Q16_TX_BD_CNT, + TOTAL_DESC - GENET_Q16_TX_BD_CNT, TOTAL_DESC); + /* Set Tx queue priorities */ bcmgenet_tdma_writel(priv, dma_priority[0], DMA_PRIORITY_0); bcmgenet_tdma_writel(priv, dma_priority[1], DMA_PRIORITY_1); bcmgenet_tdma_writel(priv, dma_priority[2], DMA_PRIORITY_2); =20 - /* Configure Tx queues as descriptor rings */ + /* Configure Tx queues as descriptor rings, including ring 16 */ ring_mask =3D (1 << (priv->hw_params->tx_queues + 1)) - 1; + ring_mask |=3D BIT(DESC_INDEX); bcmgenet_tdma_writel(priv, ring_mask, DMA_RING_CFG); =20 /* Enable Tx rings */ @@ -3637,6 +3782,7 @@ static void bcmgenet_timeout(struct net_device *dev, = unsigned int txqueue) =20 for (q =3D 0; q <=3D priv->hw_params->tx_queues; q++) bcmgenet_dump_tx_queue(&priv->tx_rings[q]); + bcmgenet_dump_tx_queue(&priv->tx_rings[DESC_INDEX]); =20 bcmgenet_tx_reclaim_all(dev); =20 @@ -3770,6 +3916,21 @@ static void bcmgenet_get_stats64(struct net_device *= dev, stats->tx_dropped +=3D tx_dropped; } =20 + /* Include XDP TX ring (DESC_INDEX) stats */ + tx_stats =3D &priv->tx_rings[DESC_INDEX].stats64; + do { + start =3D u64_stats_fetch_begin(&tx_stats->syncp); + tx_bytes =3D u64_stats_read(&tx_stats->bytes); + tx_packets =3D u64_stats_read(&tx_stats->packets); + tx_errors =3D u64_stats_read(&tx_stats->errors); + tx_dropped =3D u64_stats_read(&tx_stats->dropped); + } while (u64_stats_fetch_retry(&tx_stats->syncp, start)); + + stats->tx_bytes +=3D tx_bytes; + stats->tx_packets +=3D tx_packets; + stats->tx_errors +=3D tx_errors; + stats->tx_dropped +=3D tx_dropped; + for (q =3D 0; q <=3D priv->hw_params->rx_queues; q++) { rx_stats =3D &priv->rx_rings[q].stats64; do { @@ -4273,6 +4434,7 @@ static int bcmgenet_probe(struct platform_device *pde= v) u64_stats_init(&priv->rx_rings[i].stats64.syncp); for (i =3D 0; i <=3D priv->hw_params->tx_queues; i++) u64_stats_init(&priv->tx_rings[i].stats64.syncp); + u64_stats_init(&priv->tx_rings[DESC_INDEX].stats64.syncp); =20 /* libphy will determine the link state */ netif_carrier_off(dev); diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/e= thernet/broadcom/genet/bcmgenet.h index 1459473ac1b0..fce598c29a96 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h @@ -472,6 +472,8 @@ struct bcmgenet_rx_stats64 { =20 struct enet_cb { struct sk_buff *skb; + struct xdp_frame *xdpf; + bool xdp_dma_map; struct page *rx_page; unsigned int rx_page_offset; void __iomem *bd_addr; @@ -610,7 +612,7 @@ struct bcmgenet_priv { struct enet_cb *tx_cbs; unsigned int num_tx_bds; =20 - struct bcmgenet_tx_ring tx_rings[GENET_MAX_MQ_CNT + 1]; + struct bcmgenet_tx_ring tx_rings[DESC_INDEX + 1]; =20 /* receive variables */ void __iomem *rx_bds; --=20 2.51.0 From nobody Tue Apr 7 06:32:11 2026 Received: from mail.tipi-net.de (mail.tipi-net.de [194.13.80.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D762C37D128; Sun, 15 Mar 2026 21:50:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.13.80.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611411; cv=none; b=pofBe+egDUNiehwD0WFelUkl2W5uBp61T6DF6M15ugU/Cufx+o/xMuRyd0pZHxkzbiMXE/aE/21xNnqO3HDRzyLJJ9Y4T5qQpdl149dJ5e+52Tp4lEUpJYoMzy82IsCedkg/jZ6FpkeazXJ4b9b3DwkWp0jnIn99YeMUmWZVhjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611411; c=relaxed/simple; bh=vVlU/tLju4Y1C+amxm9HQKjeleu1zqO9lZT3LOSTwaY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uDffZ2uf7Y5RvOMbhQboy+RFy1ik8P1pfLBDGzPswyQxLF/4gm1ZfIrQfW/tL4D/OZqstaL7tzy+f2kKjNxQ+Ens2HhPZHEviBzaGosLAd3r5wN9fAHLg8WTQHV8TiX8qLYtMJfigdPhEUVSP85kE+bNzywz87JDWZH9diVuFjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de; spf=pass smtp.mailfrom=tipi-net.de; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b=swzCEM2G; arc=none smtp.client-ip=194.13.80.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b="swzCEM2G" Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 57229A575C; Sun, 15 Mar 2026 22:50:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tipi-net.de; s=dkim; t=1773611403; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Cll75lNtnT5wlTHQImlKL6wvWpXQYzV8bB5+50bW3fM=; b=swzCEM2GU5G0GfDBKUZfUoZK6QelRFsAW57uUnb/9DgvWoaZgRavj4BhT1X4M2603sVbb7 DhpRjdBNOB57gsn0nCI3kaT1uqKDk7vENNpKgJUnmWF2v8mNvc/Wkjnd8sCPkEjHapcbqN d97DII8sG242lxGN5HOqZD5hFsnRZf6fL5lW88tVFLtrsN9o9TpUl78LFAzzmYOpe01GpS 4mtIDz8xyu4yqxfJmirpXdO0Hjv8caNeKgUAUcn6/g27pa3M36kVUzFvj/hjd0BMPGDQNU tSJuINrAQGwBMezgtJRSTfxYVyGn/BpdjpfcgrsMnAvIVa9PPm1vEWP5ZIlFvg== From: Nicolai Buchwitz To: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Doug Berger , Florian Fainelli Cc: Broadcom internal kernel review list , Vikas Gupta , Bhargava Marreddy , Rajashekar Hudumula , Eric Biggers , Heiner Kallweit , =?UTF-8?q?Markus=20Bl=C3=B6chl?= , Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Buchwitz Subject: [PATCH net-next v2 5/6] net: bcmgenet: add XDP_REDIRECT and ndo_xdp_xmit support Date: Sun, 15 Mar 2026 22:49:13 +0100 Message-ID: <20260315214914.1555777-6-nb@tipi-net.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260315214914.1555777-1-nb@tipi-net.de> References: <20260315214914.1555777-1-nb@tipi-net.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Add XDP_REDIRECT support and implement ndo_xdp_xmit for receiving redirected frames from other devices. XDP_REDIRECT calls xdp_do_redirect() in the RX path with xdp_do_flush() once per NAPI poll cycle. ndo_xdp_xmit batches frames into ring 16 under a single spinlock acquisition. Advertise NETDEV_XDP_ACT_REDIRECT and NETDEV_XDP_ACT_NDO_XMIT in xdp_features. Signed-off-by: Nicolai Buchwitz --- .../net/ethernet/broadcom/genet/bcmgenet.c | 96 +++++++++++++++---- 1 file changed, 78 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/e= thernet/broadcom/genet/bcmgenet.c index 922895bc7461..5dfe6b764930 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -2320,23 +2320,23 @@ static struct sk_buff *bcmgenet_xdp_build_skb(struc= t bcmgenet_rx_ring *ring, return skb; } =20 +/* Submit a single XDP frame to the TX ring. Caller must hold ring->lock. + * Returns true on success. Does not ring the doorbell - caller must + * write TDMA_PROD_INDEX after batching. + */ static bool bcmgenet_xdp_xmit_frame(struct bcmgenet_priv *priv, + struct bcmgenet_tx_ring *ring, struct xdp_frame *xdpf, bool dma_map) { - struct bcmgenet_tx_ring *ring =3D &priv->tx_rings[DESC_INDEX]; struct device *kdev =3D &priv->pdev->dev; struct enet_cb *tx_cb_ptr; dma_addr_t mapping; unsigned int dma_len; u32 len_stat; =20 - spin_lock(&ring->lock); - - if (ring->free_bds < 1) { - spin_unlock(&ring->lock); + if (ring->free_bds < 1) return false; - } =20 tx_cb_ptr =3D bcmgenet_get_txcb(priv, ring); =20 @@ -2350,7 +2350,6 @@ static bool bcmgenet_xdp_xmit_frame(struct bcmgenet_p= riv *priv, */ if (unlikely(xdpf->headroom < sizeof(struct status_64))) { bcmgenet_put_txcb(priv, ring); - spin_unlock(&ring->lock); return false; } =20 @@ -2364,7 +2363,6 @@ static bool bcmgenet_xdp_xmit_frame(struct bcmgenet_p= riv *priv, tx_cb_ptr->skb =3D NULL; tx_cb_ptr->xdpf =3D NULL; bcmgenet_put_txcb(priv, ring); - spin_unlock(&ring->lock); return false; } } else { @@ -2396,12 +2394,14 @@ static bool bcmgenet_xdp_xmit_frame(struct bcmgenet= _priv *priv, ring->prod_index++; ring->prod_index &=3D DMA_P_INDEX_MASK; =20 + return true; +} + +static void bcmgenet_xdp_ring_doorbell(struct bcmgenet_priv *priv, + struct bcmgenet_tx_ring *ring) +{ bcmgenet_tdma_ring_writel(priv, ring->index, ring->prod_index, TDMA_PROD_INDEX); - - spin_unlock(&ring->lock); - - return true; } =20 static unsigned int @@ -2417,7 +2417,11 @@ bcmgenet_run_xdp(struct bcmgenet_rx_ring *ring, stru= ct bpf_prog *prog, switch (act) { case XDP_PASS: return XDP_PASS; - case XDP_TX: + case XDP_TX: { + struct bcmgenet_tx_ring *tx_ring; + + tx_ring =3D &priv->tx_rings[DESC_INDEX]; + /* Prepend a zeroed TSB (Transmit Status Block). The GENET * MAC has TBUF_64B_EN set globally, so hardware expects every * TX buffer to begin with a 64-byte struct status_64. Back @@ -2429,14 +2433,26 @@ bcmgenet_run_xdp(struct bcmgenet_rx_ring *ring, str= uct bpf_prog *prog, memset(xdp->data, 0, sizeof(struct status_64)); =20 xdpf =3D xdp_convert_buff_to_frame(xdp); - if (unlikely(!xdpf) || - unlikely(!bcmgenet_xdp_xmit_frame(priv, xdpf, false))) { - page_pool_put_full_page(ring->page_pool, rx_page, - true); + if (unlikely(!xdpf)) + goto drop_page; + + spin_lock(&tx_ring->lock); + if (unlikely(!bcmgenet_xdp_xmit_frame(priv, tx_ring, xdpf, + false))) { + spin_unlock(&tx_ring->lock); + xdp_return_frame_rx_napi(xdpf); return XDP_DROP; } + bcmgenet_xdp_ring_doorbell(priv, tx_ring); + spin_unlock(&tx_ring->lock); return XDP_TX; + } + case XDP_REDIRECT: + if (unlikely(xdp_do_redirect(priv->dev, xdp, prog))) + goto drop_page; + return XDP_REDIRECT; case XDP_DROP: +drop_page: page_pool_put_full_page(ring->page_pool, rx_page, true); return XDP_DROP; default: @@ -2459,6 +2475,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_= rx_ring *ring, struct bcmgenet_priv *priv =3D ring->priv; struct net_device *dev =3D priv->dev; struct bpf_prog *xdp_prog; + bool xdp_flush =3D false; struct enet_cb *cb; struct sk_buff *skb; u32 dma_length_status; @@ -2597,6 +2614,8 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_= rx_ring *ring, =20 xdp_act =3D bcmgenet_run_xdp(ring, xdp_prog, &xdp, rx_page); + if (xdp_act =3D=3D XDP_REDIRECT) + xdp_flush =3D true; if (xdp_act !=3D XDP_PASS) goto next; =20 @@ -2670,6 +2689,9 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_= rx_ring *ring, bcmgenet_rdma_ring_writel(priv, ring->index, ring->c_index, RDMA_CONS_IN= DEX); } =20 + if (xdp_flush) + xdp_do_flush(); + ring->dim.bytes =3D bytes_processed; ring->dim.packets =3D rxpktprocessed; =20 @@ -3996,10 +4018,16 @@ static int bcmgenet_xdp_setup(struct net_device *de= v, return -EOPNOTSUPP; } =20 + if (!prog) + xdp_features_clear_redirect_target(dev); + old_prog =3D xchg(&priv->xdp_prog, prog); if (old_prog) bpf_prog_put(old_prog); =20 + if (prog) + xdp_features_set_redirect_target(dev, false); + return 0; } =20 @@ -4013,6 +4041,36 @@ static int bcmgenet_xdp(struct net_device *dev, stru= ct netdev_bpf *xdp) } } =20 +static int bcmgenet_xdp_xmit(struct net_device *dev, int num_frames, + struct xdp_frame **frames, u32 flags) +{ + struct bcmgenet_priv *priv =3D netdev_priv(dev); + struct bcmgenet_tx_ring *ring =3D &priv->tx_rings[DESC_INDEX]; + int sent =3D 0; + int i; + + if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) + return -EINVAL; + + if (unlikely(!netif_running(dev))) + return -ENETDOWN; + + spin_lock(&ring->lock); + + for (i =3D 0; i < num_frames; i++) { + if (!bcmgenet_xdp_xmit_frame(priv, ring, frames[i], true)) + break; + sent++; + } + + if (sent) + bcmgenet_xdp_ring_doorbell(priv, ring); + + spin_unlock(&ring->lock); + + return sent; +} + static const struct net_device_ops bcmgenet_netdev_ops =3D { .ndo_open =3D bcmgenet_open, .ndo_stop =3D bcmgenet_close, @@ -4025,6 +4083,7 @@ static const struct net_device_ops bcmgenet_netdev_op= s =3D { .ndo_get_stats64 =3D bcmgenet_get_stats64, .ndo_change_carrier =3D bcmgenet_change_carrier, .ndo_bpf =3D bcmgenet_xdp, + .ndo_xdp_xmit =3D bcmgenet_xdp_xmit, }; =20 /* GENET hardware parameters/characteristics */ @@ -4327,7 +4386,8 @@ static int bcmgenet_probe(struct platform_device *pde= v) NETIF_F_RXCSUM; dev->hw_features |=3D dev->features; dev->vlan_features |=3D dev->features; - dev->xdp_features =3D NETDEV_XDP_ACT_BASIC; + dev->xdp_features =3D NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | + NETDEV_XDP_ACT_NDO_XMIT; =20 netdev_sw_irq_coalesce_default_on(dev); =20 --=20 2.51.0 From nobody Tue Apr 7 06:32:11 2026 Received: from mail.tipi-net.de (mail.tipi-net.de [194.13.80.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5CFA37D127; Sun, 15 Mar 2026 21:50:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.13.80.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611411; cv=none; b=aPUCMvV5BLyehTlcL4nOvd3pKpESoD1pddxByL2pdT2qIgVqWqYTqIZVOSB8WXuhG/+Lov83Yf0gIh3+7biGSvhgH7m9D+cKVZZrGLmZ+HjRufBMQJ2VTu0dM12/DVKL3yqWMtHLdQuY+gduFtxPozudb214hwT9WUovuobdTgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773611411; c=relaxed/simple; bh=A6CsQvnP1SsdZU5VeN0fA0xmkj/hOiFDXCLLQs5lQ04=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rk0goE4OyuJkJm5hEpNZ/HH5DDFVjF0NqkMQh4F9Or3d0SQi96zJNBOfkmN+4YPugmnZSjVngLBLOVrSJDCKMoyMHY2ZBCIbAbmVB/zBCQoLz3alx2jYqmbEAh6SeEmtaftvzbrWmuXptaowmT+KexeuT2nbOyOmPYTkRgIOd/w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de; spf=pass smtp.mailfrom=tipi-net.de; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b=4Y3UvcGB; arc=none smtp.client-ip=194.13.80.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tipi-net.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tipi-net.de header.i=@tipi-net.de header.b="4Y3UvcGB" Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 97C35A575F; Sun, 15 Mar 2026 22:50:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tipi-net.de; s=dkim; t=1773611404; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=RkpES3soYkluKN2F4ytaxiBMAbsU2NEhuXh3rlqE2zw=; b=4Y3UvcGB1t6FMIIwhMeJvIyfOy73cQjC+lXB19Rb+OJ/QG1l9hF9LCxdME8S6TII/E3yD2 9x0xYpEN0QU+g9IjtP1aiogIUV0hAPn366ls7iNmbRuyk+dHY1i5i2OBEgqnUjhcMAlod3 AZEsT14bPvx93knsLVl52iWyIRV+GjWPRjGKskkwwNRAjvh8CepjiCLN1dC3nPz8FU18PO 3PXnKdEreEEisep4uVjywzF5i0jxzuLRShfWWxCZmJzplvDfu+PBSwT+O4rvb1TGbJn9VU gLBD3kK/fvn3T851dmUd4AzyIbcZh13UtgWn2GjZupxRj4dOAjdQCN2YVTrekw== From: Nicolai Buchwitz To: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Doug Berger , Florian Fainelli Cc: Broadcom internal kernel review list , Vikas Gupta , Bhargava Marreddy , Rajashekar Hudumula , Eric Biggers , Heiner Kallweit , =?UTF-8?q?Markus=20Bl=C3=B6chl?= , Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Buchwitz Subject: [PATCH net-next v2 6/6] net: bcmgenet: add XDP statistics counters Date: Sun, 15 Mar 2026 22:49:14 +0100 Message-ID: <20260315214914.1555777-7-nb@tipi-net.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260315214914.1555777-1-nb@tipi-net.de> References: <20260315214914.1555777-1-nb@tipi-net.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Expose per-action XDP counters via ethtool -S: xdp_pass, xdp_drop, xdp_tx, xdp_tx_err, xdp_redirect, and xdp_redirect_err. These use the existing soft MIB infrastructure and are incremented in bcmgenet_run_xdp() alongside the existing driver statistics. Signed-off-by: Nicolai Buchwitz --- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 17 ++++++++++++++++- drivers/net/ethernet/broadcom/genet/bcmgenet.h | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/e= thernet/broadcom/genet/bcmgenet.c index 5dfe6b764930..ca79340b8bf9 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -1170,6 +1170,13 @@ static const struct bcmgenet_stats bcmgenet_gstrings= _stats[] =3D { STAT_GENET_SOFT_MIB("tx_realloc_tsb", mib.tx_realloc_tsb), STAT_GENET_SOFT_MIB("tx_realloc_tsb_failed", mib.tx_realloc_tsb_failed), + /* XDP counters */ + STAT_GENET_SOFT_MIB("xdp_pass", mib.xdp_pass), + STAT_GENET_SOFT_MIB("xdp_drop", mib.xdp_drop), + STAT_GENET_SOFT_MIB("xdp_tx", mib.xdp_tx), + STAT_GENET_SOFT_MIB("xdp_tx_err", mib.xdp_tx_err), + STAT_GENET_SOFT_MIB("xdp_redirect", mib.xdp_redirect), + STAT_GENET_SOFT_MIB("xdp_redirect_err", mib.xdp_redirect_err), /* Per TX queues */ STAT_GENET_Q(0), STAT_GENET_Q(1), @@ -2416,6 +2423,7 @@ bcmgenet_run_xdp(struct bcmgenet_rx_ring *ring, struc= t bpf_prog *prog, =20 switch (act) { case XDP_PASS: + priv->mib.xdp_pass++; return XDP_PASS; case XDP_TX: { struct bcmgenet_tx_ring *tx_ring; @@ -2441,18 +2449,24 @@ bcmgenet_run_xdp(struct bcmgenet_rx_ring *ring, str= uct bpf_prog *prog, false))) { spin_unlock(&tx_ring->lock); xdp_return_frame_rx_napi(xdpf); + priv->mib.xdp_tx_err++; return XDP_DROP; } bcmgenet_xdp_ring_doorbell(priv, tx_ring); spin_unlock(&tx_ring->lock); + priv->mib.xdp_tx++; return XDP_TX; } case XDP_REDIRECT: - if (unlikely(xdp_do_redirect(priv->dev, xdp, prog))) + if (unlikely(xdp_do_redirect(priv->dev, xdp, prog))) { + priv->mib.xdp_redirect_err++; goto drop_page; + } + priv->mib.xdp_redirect++; return XDP_REDIRECT; case XDP_DROP: drop_page: + priv->mib.xdp_drop++; page_pool_put_full_page(ring->page_pool, rx_page, true); return XDP_DROP; default: @@ -2460,6 +2474,7 @@ bcmgenet_run_xdp(struct bcmgenet_rx_ring *ring, struc= t bpf_prog *prog, fallthrough; case XDP_ABORTED: trace_xdp_exception(priv->dev, prog, act); + priv->mib.xdp_drop++; page_pool_put_full_page(ring->page_pool, rx_page, true); return XDP_ABORTED; } diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/e= thernet/broadcom/genet/bcmgenet.h index fce598c29a96..9e4f5bac38e7 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h @@ -156,6 +156,12 @@ struct bcmgenet_mib_counters { u32 tx_dma_failed; u32 tx_realloc_tsb; u32 tx_realloc_tsb_failed; + u32 xdp_pass; + u32 xdp_drop; + u32 xdp_tx; + u32 xdp_tx_err; + u32 xdp_redirect; + u32 xdp_redirect_err; }; =20 struct bcmgenet_tx_stats64 { --=20 2.51.0