From: Tony Nguyen <anthony.l.nguyen@intel.com>
To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
edumazet@google.com, andrew+netdev@lunn.ch,
netdev@vger.kernel.org
Cc: Alexander Lobakin <aleksander.lobakin@intel.com>,
anthony.l.nguyen@intel.com, maciej.fijalkowski@intel.com,
magnus.karlsson@intel.com, michal.kubiak@intel.com,
przemyslaw.kitszel@intel.com, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
horms@kernel.org, bpf@vger.kernel.org
Subject: [PATCH net-next 02/16] libeth: support native XDP and register memory model
Date: Tue, 20 May 2025 13:59:03 -0700 [thread overview]
Message-ID: <20250520205920.2134829-3-anthony.l.nguyen@intel.com> (raw)
In-Reply-To: <20250520205920.2134829-1-anthony.l.nguyen@intel.com>
From: Alexander Lobakin <aleksander.lobakin@intel.com>
Expand libeth's Page Pool functionality by adding native XDP support.
This means picking the appropriate headroom and DMA direction.
Also, register all the created &page_pools as XDP memory models.
A driver then can call xdp_rxq_info_attach_page_pool() when registering
its RxQ info.
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
drivers/net/ethernet/intel/libeth/rx.c | 20 +++++++++++++++-----
include/net/libeth/rx.h | 6 +++++-
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/intel/libeth/rx.c b/drivers/net/ethernet/intel/libeth/rx.c
index aa5d878181f7..c0be9cb043a1 100644
--- a/drivers/net/ethernet/intel/libeth/rx.c
+++ b/drivers/net/ethernet/intel/libeth/rx.c
@@ -70,7 +70,7 @@ static u32 libeth_rx_hw_len_truesize(const struct page_pool_params *pp,
static bool libeth_rx_page_pool_params(struct libeth_fq *fq,
struct page_pool_params *pp)
{
- pp->offset = LIBETH_SKB_HEADROOM;
+ pp->offset = fq->xdp ? LIBETH_XDP_HEADROOM : LIBETH_SKB_HEADROOM;
/* HW-writeable / syncable length per one page */
pp->max_len = LIBETH_RX_PAGE_LEN(pp->offset);
@@ -157,11 +157,12 @@ int libeth_rx_fq_create(struct libeth_fq *fq, struct napi_struct *napi)
.dev = napi->dev->dev.parent,
.netdev = napi->dev,
.napi = napi,
- .dma_dir = DMA_FROM_DEVICE,
};
struct libeth_fqe *fqes;
struct page_pool *pool;
- bool ret;
+ int ret;
+
+ pp.dma_dir = fq->xdp ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE;
if (!fq->hsplit)
ret = libeth_rx_page_pool_params(fq, &pp);
@@ -175,18 +176,26 @@ int libeth_rx_fq_create(struct libeth_fq *fq, struct napi_struct *napi)
return PTR_ERR(pool);
fqes = kvcalloc_node(fq->count, sizeof(*fqes), GFP_KERNEL, fq->nid);
- if (!fqes)
+ if (!fqes) {
+ ret = -ENOMEM;
goto err_buf;
+ }
+
+ ret = xdp_reg_page_pool(pool);
+ if (ret)
+ goto err_mem;
fq->fqes = fqes;
fq->pp = pool;
return 0;
+err_mem:
+ kvfree(fqes);
err_buf:
page_pool_destroy(pool);
- return -ENOMEM;
+ return ret;
}
EXPORT_SYMBOL_GPL(libeth_rx_fq_create);
@@ -196,6 +205,7 @@ EXPORT_SYMBOL_GPL(libeth_rx_fq_create);
*/
void libeth_rx_fq_destroy(struct libeth_fq *fq)
{
+ xdp_unreg_page_pool(fq->pp);
kvfree(fq->fqes);
page_pool_destroy(fq->pp);
}
diff --git a/include/net/libeth/rx.h b/include/net/libeth/rx.h
index 7d5dc58984b1..5d991404845e 100644
--- a/include/net/libeth/rx.h
+++ b/include/net/libeth/rx.h
@@ -13,8 +13,10 @@
/* Space reserved in front of each frame */
#define LIBETH_SKB_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN)
+#define LIBETH_XDP_HEADROOM (ALIGN(XDP_PACKET_HEADROOM, NET_SKB_PAD) + \
+ NET_IP_ALIGN)
/* Maximum headroom for worst-case calculations */
-#define LIBETH_MAX_HEADROOM LIBETH_SKB_HEADROOM
+#define LIBETH_MAX_HEADROOM LIBETH_XDP_HEADROOM
/* Link layer / L2 overhead: Ethernet, 2 VLAN tags (C + S), FCS */
#define LIBETH_RX_LL_LEN (ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN)
/* Maximum supported L2-L4 header length */
@@ -66,6 +68,7 @@ enum libeth_fqe_type {
* @count: number of descriptors/buffers the queue has
* @type: type of the buffers this queue has
* @hsplit: flag whether header split is enabled
+ * @xdp: flag indicating whether XDP is enabled
* @buf_len: HW-writeable length per each buffer
* @nid: ID of the closest NUMA node with memory
*/
@@ -81,6 +84,7 @@ struct libeth_fq {
/* Cold fields */
enum libeth_fqe_type type:2;
bool hsplit:1;
+ bool xdp:1;
u32 buf_len;
int nid;
--
2.47.1
next prev parent reply other threads:[~2025-05-20 20:59 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 20:59 [PATCH net-next 00/16][pull request] libeth: add libeth_xdp helper lib Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 01/16] libeth: convert to netmem Tony Nguyen
2025-05-28 1:57 ` Jakub Kicinski
2025-05-28 3:49 ` Mina Almasry
2025-05-29 0:23 ` Jakub Kicinski
2025-05-28 14:54 ` Alexander Lobakin
2025-05-29 0:25 ` Jakub Kicinski
2025-05-20 20:59 ` Tony Nguyen [this message]
2025-05-20 20:59 ` [PATCH net-next 03/16] libeth: xdp: add XDP_TX buffers sending Tony Nguyen
2025-05-28 2:03 ` Jakub Kicinski
2025-05-28 14:57 ` Alexander Lobakin
2025-05-29 0:18 ` Jakub Kicinski
2025-05-20 20:59 ` [PATCH net-next 04/16] libeth: xdp: add .ndo_xdp_xmit() helpers Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 05/16] libeth: xdp: add XDPSQE completion helpers Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 06/16] libeth: xdp: add XDPSQ locking helpers Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 07/16] libeth: xdp: add XDPSQ cleanup timers Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 08/16] libeth: xdp: add helpers for preparing/processing &libeth_xdp_buff Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 09/16] libeth: xdp: add XDP prog run and verdict result handling Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 10/16] libeth: xdp: add templates for building driver-side callbacks Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 11/16] libeth: xdp: add RSS hash hint and XDP features setup helpers Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 12/16] libeth: xsk: add XSk XDP_TX sending helpers Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 13/16] libeth: xsk: add XSk xmit functions Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 14/16] libeth: xsk: add XSk Rx processing support Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 15/16] libeth: xsk: add XSkFQ refill and XSk wakeup helpers Tony Nguyen
2025-05-20 20:59 ` [PATCH net-next 16/16] libeth: xdp, xsk: access adjacent u32s as u64 where applicable Tony Nguyen
2025-05-27 13:49 ` [PATCH net-next 00/16][pull request] libeth: add libeth_xdp helper lib Alexander Lobakin
-- strict thread matches above, loose matches on Subject: below --
2025-03-05 16:21 [PATCH net-next 00/16] idpf: add XDP support Alexander Lobakin
2025-03-05 16:21 ` [PATCH net-next 02/16] libeth: support native XDP and register memory model Alexander Lobakin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250520205920.2134829-3-anthony.l.nguyen@intel.com \
--to=anthony.l.nguyen@intel.com \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=michal.kubiak@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).