From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: Nicolas Ferre <nicolas.ferre@microchip.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Richard Cochran <richardcochran@gmail.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Benoît Monin" <benoit.monin@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
"Théo Lebrun" <theo.lebrun@bootlin.com>
Subject: [PATCH net-next 6/8] net: macb: add infrastructure for XSK buffer pool
Date: Wed, 04 Mar 2026 19:24:29 +0100 [thread overview]
Message-ID: <20260304-macb-xsk-v1-6-ba2ebe2bdaa3@bootlin.com> (raw)
In-Reply-To: <20260304-macb-xsk-v1-0-ba2ebe2bdaa3@bootlin.com>
Store a XSK buffer pool per queue, assigned through .ndo_bpf() with
command == XDP_SETUP_XSK_POOL.
We have no sequence upstream to disable a single queue, free its
buffers, refill it and re-enable the queue (without affecting other
queues). Therefore we protect our operation with interface-wide close
and open.
Also, prepare the terrain with a .ndo_xsk_wakeup() operation that does
the pre-flight-checks but is a no-op.
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/net/ethernet/cadence/macb.h | 1 +
drivers/net/ethernet/cadence/macb_main.c | 66 +++++++++++++++++++++++++++++++-
2 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index 009a44e94726..a9e6f0289ecb 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -1278,6 +1278,7 @@ struct macb_queue {
struct napi_struct napi_rx;
struct queue_stats stats;
struct page_pool *page_pool;
+ struct xsk_buff_pool *xsk_pool;
struct sk_buff *skb;
struct xdp_rxq_info xdp_rxq;
};
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 65c2ec2a843c..a72d59ffd1cf 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -38,6 +38,7 @@
#include <linux/types.h>
#include <linux/udp.h>
#include <net/pkt_sched.h>
+#include <net/xdp_sock_drv.h>
#include "macb.h"
/* This structure is only used for MACB on SiFive FU540 devices */
@@ -1564,6 +1565,24 @@ static int gem_xdp_xmit(struct net_device *dev, int num_frame,
return xmitted;
}
+static int gem_xsk_wakeup(struct net_device *dev, u32 qid, u32 flags)
+{
+ struct macb *bp = netdev_priv(dev);
+ struct macb_queue *queue = &bp->queues[qid];
+
+ if (unlikely(!netif_carrier_ok(dev)))
+ return -ENETDOWN;
+
+ if (unlikely(qid >= bp->num_queues ||
+ !rcu_access_pointer(bp->prog) ||
+ !queue->xsk_pool))
+ return -ENXIO;
+
+ /* no-op, until rx/tx implement XSK support */
+
+ return 0;
+}
+
static u32 gem_xdp_run(struct macb_queue *queue, void *buff_head,
unsigned int *len, unsigned int *headroom,
dma_addr_t addr)
@@ -3580,6 +3599,46 @@ static int gem_xdp_setup(struct net_device *dev, struct bpf_prog *prog,
return err;
}
+static int gem_xdp_setup_xsk_pool(struct net_device *netdev,
+ struct xsk_buff_pool *pool, u16 qid)
+{
+ struct macb *bp = netdev_priv(netdev);
+ unsigned long attrs = DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING;
+ struct macb_queue *queue = &bp->queues[qid];
+ bool running = netif_running(netdev);
+ struct device *dev = &bp->pdev->dev;
+ int err = 0;
+
+ if (qid >= bp->num_queues)
+ return -EINVAL;
+
+ if (pool && queue->xsk_pool)
+ return -EBUSY;
+
+ if (running)
+ macb_close(netdev);
+
+ if (pool) {
+ err = xsk_pool_dma_map(pool, dev, attrs);
+ if (err)
+ netdev_err(netdev, "xdp: failed to DMA map XSK pool\n");
+ else
+ queue->xsk_pool = pool;
+ } else {
+ if (queue->xsk_pool)
+ xsk_pool_dma_unmap(queue->xsk_pool, attrs);
+ queue->xsk_pool = NULL;
+ }
+
+ if (running) {
+ int err_open = macb_open(netdev);
+
+ err = err ?: err_open;
+ }
+
+ return err;
+}
+
static int gem_xdp(struct net_device *dev, struct netdev_bpf *xdp)
{
struct macb *bp = netdev_priv(dev);
@@ -3590,6 +3649,9 @@ static int gem_xdp(struct net_device *dev, struct netdev_bpf *xdp)
switch (xdp->command) {
case XDP_SETUP_PROG:
return gem_xdp_setup(dev, xdp->prog, xdp->extack);
+ case XDP_SETUP_XSK_POOL:
+ return gem_xdp_setup_xsk_pool(dev, xdp->xsk.pool,
+ xdp->xsk.queue_id);
default:
return -EOPNOTSUPP;
}
@@ -4852,6 +4914,7 @@ static const struct net_device_ops macb_netdev_ops = {
.ndo_setup_tc = macb_setup_tc,
.ndo_bpf = gem_xdp,
.ndo_xdp_xmit = gem_xdp_xmit,
+ .ndo_xsk_wakeup = gem_xsk_wakeup,
};
/* Configure peripheral capabilities according to device tree
@@ -6156,7 +6219,8 @@ static int macb_probe(struct platform_device *pdev)
dev->xdp_features = NETDEV_XDP_ACT_BASIC |
NETDEV_XDP_ACT_REDIRECT |
- NETDEV_XDP_ACT_NDO_XMIT;
+ NETDEV_XDP_ACT_NDO_XMIT |
+ NETDEV_XDP_ACT_XSK_ZEROCOPY;
}
netif_carrier_off(dev);
--
2.53.0
next prev parent reply other threads:[~2026-03-04 18:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 18:24 [PATCH net-next 0/8] net: macb: add XSK support Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 1/8] net: macb: make rx error messages rate-limited Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 2/8] net: macb: account for stats in Rx XDP codepaths Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 3/8] net: macb: account for stats in Tx " Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 4/8] net: macb: drop handling of recycled buffers in gem_rx_refill() Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 5/8] net: macb: move macb_xdp_submit_frame() body to helper function Théo Lebrun
2026-03-04 18:24 ` Théo Lebrun [this message]
2026-03-04 18:24 ` [PATCH net-next 7/8] net: macb: add Rx zero-copy AF_XDP support Théo Lebrun
2026-03-04 18:24 ` [PATCH net-next 8/8] net: macb: add Tx " Théo Lebrun
2026-03-06 12:48 ` Maxime Chevallier
2026-03-06 17:18 ` Théo Lebrun
2026-03-06 17:53 ` Maxime Chevallier
2026-03-09 10:56 ` Théo Lebrun
2026-03-06 3:11 ` [PATCH net-next 0/8] net: macb: add XSK support Jakub Kicinski
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=20260304-macb-xsk-v1-6-ba2ebe2bdaa3@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=ast@kernel.org \
--cc=benoit.monin@bootlin.com \
--cc=bpf@vger.kernel.org \
--cc=claudiu.beznea@tuxon.dev \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregory.clement@bootlin.com \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=sdf@fomichev.me \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.kondratiev@mobileye.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