From: Paolo Valerio <pvalerio@redhat.com>
To: netdev@vger.kernel.org
Cc: "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>,
"Lorenzo Bianconi" <lorenzo@kernel.org>,
"Théo Lebrun" <theo.lebrun@bootlin.com>,
"Nicolai Buchwitz" <nb@tipi-net.de>
Subject: [PATCH net-next v5 6/8] net: macb: generalize tx buffer handling
Date: Fri, 13 Mar 2026 21:14:31 +0100 [thread overview]
Message-ID: <20260313201433.2346119-7-pvalerio@redhat.com> (raw)
In-Reply-To: <20260313201433.2346119-1-pvalerio@redhat.com>
Rename struct macb_tx_buff member skb to ptr and introduce
macb_tx_buff_type to identify the buffer type macb_tx_buff
represents.
Currently the buffer can only be MACB_TYPE_SKB, so the sk_buff
case is handled unconditionally in the tx path.
The remaining type handling will be handled by subsequent patches.
This is the last preparatory step for XDP xmit support.
Signed-off-by: Paolo Valerio <pvalerio@redhat.com>
---
drivers/net/ethernet/cadence/macb.h | 25 ++++++++-----
drivers/net/ethernet/cadence/macb_main.c | 45 ++++++++++++++----------
2 files changed, 43 insertions(+), 27 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index 1cc626088174..d8c581394b98 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -965,19 +965,28 @@ struct macb_dma_desc_ptp {
/* Scaled PPM fraction */
#define PPM_FRACTION 16
-/* struct macb_tx_buff - data about an skb which is being transmitted
- * @skb: skb currently being transmitted, only set for the last buffer
- * of the frame
- * @mapping: DMA address of the skb's fragment buffer
+enum macb_tx_buff_type {
+ MACB_TYPE_SKB,
+ MACB_TYPE_XDP_TX,
+ MACB_TYPE_XDP_NDO,
+};
+
+/* struct macb_tx_buff - data about an skb or xdp frame which is being
+ * transmitted.
+ * @ptr: pointer to skb or xdp frame being transmitted, only set
+ * for the last buffer for sk_buff
+ * @mapping: DMA address of the skb's fragment or xdp buffer
* @size: size of the DMA mapped buffer
* @mapped_as_page: true when buffer was mapped with skb_frag_dma_map(),
* false when buffer was mapped with dma_map_single()
+ * @type: type of buffer (MACB_TYPE_SKB, MACB_TYPE_XDP_TX, MACB_TYPE_XDP_NDO)
*/
struct macb_tx_buff {
- struct sk_buff *skb;
- dma_addr_t mapping;
- size_t size;
- bool mapped_as_page;
+ void *ptr;
+ dma_addr_t mapping;
+ size_t size;
+ bool mapped_as_page;
+ enum macb_tx_buff_type type;
};
/* Hardware-collected statistics. Used when updating the network
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 1dff136cc63a..0cc63c2f498f 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -1190,7 +1190,8 @@ static int macb_halt_tx(struct macb *bp)
bp, TSR);
}
-static void macb_tx_unmap(struct macb *bp, struct macb_tx_buff *tx_buff, int budget)
+static void macb_tx_unmap(struct macb *bp, struct macb_tx_buff *tx_buff,
+ int budget)
{
if (tx_buff->mapping) {
if (tx_buff->mapped_as_page)
@@ -1202,9 +1203,9 @@ static void macb_tx_unmap(struct macb *bp, struct macb_tx_buff *tx_buff, int bud
tx_buff->mapping = 0;
}
- if (tx_buff->skb) {
- napi_consume_skb(tx_buff->skb, budget);
- tx_buff->skb = NULL;
+ if (tx_buff->ptr) {
+ napi_consume_skb(tx_buff->ptr, budget);
+ tx_buff->ptr = NULL;
}
}
@@ -1291,7 +1292,7 @@ static void macb_tx_error_task(struct work_struct *work)
desc = macb_tx_desc(queue, tail);
ctrl = desc->ctrl;
tx_buff = macb_tx_buff(queue, tail);
- skb = tx_buff->skb;
+ skb = tx_buff->ptr;
if (ctrl & MACB_BIT(TX_USED)) {
/* skb is set for the last buffer of the frame */
@@ -1299,7 +1300,7 @@ static void macb_tx_error_task(struct work_struct *work)
macb_tx_unmap(bp, tx_buff, 0);
tail++;
tx_buff = macb_tx_buff(queue, tail);
- skb = tx_buff->skb;
+ skb = tx_buff->ptr;
}
/* ctrl still refers to the first buffer descriptor
@@ -1396,20 +1397,22 @@ static bool ptp_one_step_sync(struct sk_buff *skb)
static int macb_tx_complete(struct macb_queue *queue, int budget)
{
struct macb *bp = queue->bp;
- u16 queue_index = queue - bp->queues;
unsigned long flags;
unsigned int tail;
unsigned int head;
+ u16 queue_index;
int packets = 0;
u32 bytes = 0;
+ queue_index = queue - bp->queues;
+
spin_lock_irqsave(&queue->tx_ptr_lock, flags);
head = queue->tx_head;
for (tail = queue->tx_tail; tail != head && packets < budget; tail++) {
- struct macb_tx_buff *tx_buff;
- struct sk_buff *skb;
- struct macb_dma_desc *desc;
- u32 ctrl;
+ struct macb_tx_buff *tx_buff;
+ struct macb_dma_desc *desc;
+ struct sk_buff *skb;
+ u32 ctrl;
desc = macb_tx_desc(queue, tail);
@@ -1427,7 +1430,7 @@ static int macb_tx_complete(struct macb_queue *queue, int budget)
/* Process all buffers of the current transmitted frame */
for (;; tail++) {
tx_buff = macb_tx_buff(queue, tail);
- skb = tx_buff->skb;
+ skb = tx_buff->ptr;
/* First, update TX stats if needed */
if (skb) {
@@ -2358,7 +2361,8 @@ static unsigned int macb_tx_map(struct macb *bp,
goto dma_error;
/* Save info to properly release resources */
- tx_buff->skb = NULL;
+ tx_buff->ptr = NULL;
+ tx_buff->type = MACB_TYPE_SKB;
tx_buff->mapping = mapping;
tx_buff->size = size;
tx_buff->mapped_as_page = false;
@@ -2386,7 +2390,8 @@ static unsigned int macb_tx_map(struct macb *bp,
goto dma_error;
/* Save info to properly release resources */
- tx_buff->skb = NULL;
+ tx_buff->ptr = NULL;
+ tx_buff->type = MACB_TYPE_SKB;
tx_buff->mapping = mapping;
tx_buff->size = size;
tx_buff->mapped_as_page = true;
@@ -2404,7 +2409,8 @@ static unsigned int macb_tx_map(struct macb *bp,
}
/* This is the last buffer of the frame: save socket buffer */
- tx_buff->skb = skb;
+ tx_buff->ptr = skb;
+ tx_buff->type = MACB_TYPE_SKB;
/* Update TX ring: update buffer descriptors in reverse order
* to avoid race condition
@@ -5268,8 +5274,9 @@ static netdev_tx_t at91ether_start_xmit(struct sk_buff *skb,
netif_stop_queue(dev);
/* Store packet information (to free when Tx completed) */
- lp->rm9200_txq[desc].skb = skb;
+ lp->rm9200_txq[desc].ptr = skb;
lp->rm9200_txq[desc].size = skb->len;
+ lp->rm9200_txq[desc].type = MACB_TYPE_SKB;
lp->rm9200_txq[desc].mapping = dma_map_single(&lp->pdev->dev, skb->data,
skb->len, DMA_TO_DEVICE);
if (dma_mapping_error(&lp->pdev->dev, lp->rm9200_txq[desc].mapping)) {
@@ -5361,9 +5368,9 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
dev->stats.tx_errors++;
desc = 0;
- if (lp->rm9200_txq[desc].skb) {
- dev_consume_skb_irq(lp->rm9200_txq[desc].skb);
- lp->rm9200_txq[desc].skb = NULL;
+ if (lp->rm9200_txq[desc].ptr) {
+ dev_consume_skb_irq(lp->rm9200_txq[desc].ptr);
+ lp->rm9200_txq[desc].ptr = NULL;
dma_unmap_single(&lp->pdev->dev, lp->rm9200_txq[desc].mapping,
lp->rm9200_txq[desc].size, DMA_TO_DEVICE);
dev->stats.tx_packets++;
--
2.53.0
next prev parent reply other threads:[~2026-03-13 20:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 20:14 [PATCH net-next v5 0/8] net: macb: Add XDP support and page pool integration Paolo Valerio
2026-03-13 20:14 ` [PATCH net-next v5 1/8] net: macb: move Rx buffers alloc from link up to open Paolo Valerio
2026-03-16 12:19 ` Nicolai Buchwitz
2026-03-13 20:14 ` [PATCH net-next v5 2/8] net: macb: rename rx_skbuff into rx_buff Paolo Valerio
2026-03-16 12:20 ` Nicolai Buchwitz
2026-03-13 20:14 ` [PATCH net-next v5 3/8] net: macb: Add page pool support handle multi-descriptor frame rx Paolo Valerio
2026-03-13 20:14 ` [PATCH net-next v5 4/8] net: macb: use the current queue number for stats Paolo Valerio
2026-03-16 16:30 ` Nicolai Buchwitz
2026-03-18 21:27 ` Paolo Valerio
2026-03-13 20:14 ` [PATCH net-next v5 5/8] net: macb: make macb_tx_skb generic Paolo Valerio
2026-03-16 12:21 ` Nicolai Buchwitz
2026-03-13 20:14 ` Paolo Valerio [this message]
2026-03-16 12:18 ` [PATCH net-next v5 6/8] net: macb: generalize tx buffer handling Nicolai Buchwitz
2026-03-13 20:14 ` [PATCH net-next v5 7/8] net: macb: add XDP support for gem Paolo Valerio
2026-03-13 20:14 ` [PATCH net-next v5 8/8] net: macb: introduce ndo_xdp_xmit support Paolo Valerio
2026-03-16 12:12 ` [PATCH net-next v5 0/8] net: macb: Add XDP support and page pool integration Nicolai Buchwitz
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=20260313201433.2346119-7-pvalerio@redhat.com \
--to=pvalerio@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=claudiu.beznea@tuxon.dev \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=lorenzo@kernel.org \
--cc=nb@tipi-net.de \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=pabeni@redhat.com \
--cc=theo.lebrun@bootlin.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