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 5/8] net: macb: move macb_xdp_submit_frame() body to helper function
Date: Wed, 04 Mar 2026 19:24:28 +0100 [thread overview]
Message-ID: <20260304-macb-xsk-v1-5-ba2ebe2bdaa3@bootlin.com> (raw)
In-Reply-To: <20260304-macb-xsk-v1-0-ba2ebe2bdaa3@bootlin.com>
Part of macb_xdp_submit_frame() is specific to the handling of an XDP
buffer (pick a queue for emission, DMA map or sync, report emitted
bytes), part is chitchat with hardware to update DMA descriptor and
start transmit.
Move the hardware specific code out of macb_xdp_submit_frame() into a
macb_xdp_submit_buff() helper function. The goal is to make code
reusable to support XSK buffers.
The macb_xdp_submit_frame() body is modified slightly: we bring the
dma_map_single() call outside of the queue->tx_ptr_lock critical
section, to minimise its span.
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/net/ethernet/cadence/macb_main.c | 143 +++++++++++++++++--------------
1 file changed, 78 insertions(+), 65 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index ed94f9f0894b..65c2ec2a843c 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -1208,6 +1208,52 @@ static bool ptp_one_step_sync(struct sk_buff *skb)
return false;
}
+static void macb_xdp_submit_buff(struct macb *bp, unsigned int queue_index,
+ struct macb_tx_buff buff)
+{
+ struct macb_queue *queue = &bp->queues[queue_index];
+ struct net_device *netdev = bp->dev;
+ struct macb_tx_buff *tx_buff;
+ struct macb_dma_desc *desc;
+ unsigned int next_head;
+ u32 ctrl;
+
+ next_head = queue->tx_head + 1;
+
+ ctrl = MACB_BIT(TX_USED);
+ desc = macb_tx_desc(queue, next_head);
+ desc->ctrl = ctrl;
+
+ desc = macb_tx_desc(queue, queue->tx_head);
+ tx_buff = macb_tx_buff(queue, queue->tx_head);
+ *tx_buff = buff;
+
+ ctrl = (u32)buff.size;
+ ctrl |= MACB_BIT(TX_LAST);
+
+ if (unlikely(macb_tx_ring_wrap(bp, queue->tx_head) == (bp->tx_ring_size - 1)))
+ ctrl |= MACB_BIT(TX_WRAP);
+
+ /* Set TX buffer descriptor */
+ macb_set_addr(bp, desc, buff.mapping);
+ /* desc->addr must be visible to hardware before clearing
+ * 'TX_USED' bit in desc->ctrl.
+ */
+ wmb();
+ desc->ctrl = ctrl;
+ queue->tx_head = next_head;
+
+ /* Make newly initialized descriptor visible to hardware */
+ wmb();
+
+ spin_lock(&bp->lock);
+ macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART));
+ spin_unlock(&bp->lock);
+
+ if (CIRC_SPACE(queue->tx_head, queue->tx_tail, bp->tx_ring_size) < 1)
+ netif_stop_subqueue(netdev, queue_index);
+}
+
static int macb_tx_complete(struct macb_queue *queue, int budget)
{
struct macb *bp = queue->bp;
@@ -1430,44 +1476,25 @@ static void discard_partial_frame(struct macb_queue *queue, unsigned int begin,
}
static int macb_xdp_submit_frame(struct macb *bp, struct xdp_frame *xdpf,
- struct net_device *dev, bool dma_map,
+ struct net_device *netdev, bool dma_map,
dma_addr_t addr)
{
+ struct device *dev = &bp->pdev->dev;
enum macb_tx_buff_type buff_type;
- struct macb_tx_buff *tx_buff;
int cpu = smp_processor_id();
- struct macb_dma_desc *desc;
struct macb_queue *queue;
- unsigned int next_head;
unsigned long flags;
dma_addr_t mapping;
u16 queue_index;
int err = 0;
- u32 ctrl;
-
- queue_index = cpu % bp->num_queues;
- queue = &bp->queues[queue_index];
- buff_type = dma_map ? MACB_TYPE_XDP_NDO : MACB_TYPE_XDP_TX;
-
- spin_lock_irqsave(&queue->tx_ptr_lock, flags);
-
- /* This is a hard error, log it. */
- if (CIRC_SPACE(queue->tx_head, queue->tx_tail, bp->tx_ring_size) < 1) {
- netif_stop_subqueue(dev, queue_index);
- netdev_dbg(bp->dev, "tx_head = %u, tx_tail = %u\n",
- queue->tx_head, queue->tx_tail);
- err = -ENOMEM;
- goto unlock;
- }
if (dma_map) {
- mapping = dma_map_single(&bp->pdev->dev,
- xdpf->data,
- xdpf->len, DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
- err = -ENOMEM;
- goto unlock;
- }
+ mapping = dma_map_single(dev, xdpf->data, xdpf->len, DMA_TO_DEVICE);
+ err = dma_mapping_error(&bp->pdev->dev, mapping);
+ if (unlikely(err))
+ return err;
+
+ buff_type = MACB_TYPE_XDP_NDO;
} else {
/* progs can adjust the head. Sync and set the adjusted one.
* This also implicitly takes into account ip alignment,
@@ -1476,52 +1503,38 @@ static int macb_xdp_submit_frame(struct macb *bp, struct xdp_frame *xdpf,
mapping = addr + xdpf->headroom + sizeof(*xdpf);
dma_sync_single_for_device(&bp->pdev->dev, mapping,
xdpf->len, DMA_BIDIRECTIONAL);
+
+ buff_type = MACB_TYPE_XDP_TX;
}
- next_head = queue->tx_head + 1;
+ queue_index = cpu % bp->num_queues;
+ queue = &bp->queues[queue_index];
- ctrl = MACB_BIT(TX_USED);
- desc = macb_tx_desc(queue, next_head);
- desc->ctrl = ctrl;
+ spin_lock_irqsave(&queue->tx_ptr_lock, flags);
- desc = macb_tx_desc(queue, queue->tx_head);
- tx_buff = macb_tx_buff(queue, queue->tx_head);
- tx_buff->ptr = xdpf;
- tx_buff->type = buff_type;
- tx_buff->mapping = dma_map ? mapping : 0;
- tx_buff->size = xdpf->len;
- tx_buff->mapped_as_page = false;
+ if (CIRC_SPACE(queue->tx_head, queue->tx_tail, bp->tx_ring_size) < 1) {
+ /* This is a hard error, log it. */
+ netif_stop_subqueue(netdev, queue_index);
+ netdev_dbg(netdev, "tx_head = %u, tx_tail = %u\n",
+ queue->tx_head, queue->tx_tail);
+ err = -ENOMEM;
+ } else {
+ macb_xdp_submit_buff(bp, queue_index, (struct macb_tx_buff){
+ .ptr = xdpf,
+ .mapping = dma_map ? mapping : 0,
+ .size = xdpf->len,
+ .mapped_as_page = false,
+ .type = buff_type,
+ });
- ctrl = (u32)tx_buff->size;
- ctrl |= MACB_BIT(TX_LAST);
+ netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index), xdpf->len);
+ }
- if (unlikely(macb_tx_ring_wrap(bp, queue->tx_head) == (bp->tx_ring_size - 1)))
- ctrl |= MACB_BIT(TX_WRAP);
-
- /* Set TX buffer descriptor */
- macb_set_addr(bp, desc, mapping);
- /* desc->addr must be visible to hardware before clearing
- * 'TX_USED' bit in desc->ctrl.
- */
- wmb();
- desc->ctrl = ctrl;
- queue->tx_head = next_head;
-
- /* Make newly initialized descriptor visible to hardware */
- wmb();
-
- spin_lock(&bp->lock);
- macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART));
- spin_unlock(&bp->lock);
-
- netdev_tx_sent_queue(netdev_get_tx_queue(bp->dev, queue_index), xdpf->len);
-
- if (CIRC_SPACE(queue->tx_head, queue->tx_tail, bp->tx_ring_size) < 1)
- netif_stop_subqueue(dev, queue_index);
-
-unlock:
spin_unlock_irqrestore(&queue->tx_ptr_lock, flags);
+ if (err && dma_map)
+ dma_unmap_single(dev, mapping, xdpf->len, DMA_TO_DEVICE);
+
return err;
}
--
2.53.0
next prev parent reply other threads:[~2026-03-04 18:24 UTC|newest]
Thread overview: 15+ 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 ` Théo Lebrun [this message]
2026-03-04 18:24 ` [PATCH net-next 6/8] net: macb: add infrastructure for XSK buffer pool Théo Lebrun
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
-- strict thread matches above, loose matches on Subject: below --
2026-03-04 18:23 Théo Lebrun
2026-03-04 18:23 ` [PATCH net-next 5/8] net: macb: move macb_xdp_submit_frame() body to helper function Théo Lebrun
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-5-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