[RFC: DMA_PMD 20/22] net/idpf: Use DMA_PMD memory for tx header bounce buffers

From: Luigi Rizzo

Date: Sat Oct 03 2026 - 17:26:02 EST


When dev->dma_pmd_tx_hdrs is enabled, allocate a MAX_TCP_HEADER
bounce buffer per TX buffer slot out of the DMA_PMD arena. When the
linear portion of a transmitted packet is at most MAX_TCP_HEADER bytes,
copy it into the pre-mapped bounce buffer and set the SQE unmap length
to 0 instead of calling dma_map_single()/dma_unmap_page() on every
packet.

Signed-off-by: Luigi Rizzo <lrizzo@xxxxxxxxxx>
---
.../ethernet/intel/idpf/idpf_singleq_txrx.c | 6 ++---
drivers/net/ethernet/intel/idpf/idpf_txrx.c | 21 ++++++++++++---
drivers/net/ethernet/intel/idpf/idpf_txrx.h | 27 ++++++++++++++++++-
include/net/libeth/tx.h | 5 ++--
4 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c
index e3ddf18dcbf51..24a2dfec6212d 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c
@@ -261,7 +261,7 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q,

tx_desc = &tx_q->base_tx[i];

- dma = dma_map_single(tx_q->dev, skb->data, size, DMA_TO_DEVICE);
+ dma = idpf_tx_map_hdr(tx_q, skb, first, size);

/* write each descriptor with CRC bit */
if (idpf_queue_has(CRC_EN, tx_q))
@@ -274,8 +274,7 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q,
return idpf_tx_singleq_dma_map_error(tx_q, skb,
first, i);

- /* record length, and DMA address */
- dma_unmap_len_set(tx_buf, len, size);
+ /* record DMA address */
dma_unmap_addr_set(tx_buf, dma, dma);
tx_buf->type = LIBETH_SQE_FRAG;

@@ -326,6 +325,7 @@ static void idpf_tx_singleq_map(struct idpf_tx_queue *tx_q,

size = skb_frag_size(frag);
data_len -= size;
+ dma_unmap_len_set(tx_buf, len, size);

dma = skb_frag_dma_map(tx_q->dev, frag, 0, size,
DMA_TO_DEVICE);
diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
index 4311ffa30bb18..4bdec468ea2ce 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
@@ -90,6 +90,14 @@ static void idpf_tx_buf_rel_all(struct idpf_tx_queue *txq)
else
idpf_tx_buf_clean(txq);

+ if (txq->hdr_buf_va) {
+ dma_free_coherent(txq->dev,
+ txq->buf_pool_size * MAX_TCP_HEADER,
+ txq->hdr_buf_va, txq->hdr_buf_dma);
+ txq->hdr_buf_va = NULL;
+ txq->hdr_buf_dma = 0;
+ }
+
kfree(txq->tx_buf);
txq->tx_buf = NULL;
}
@@ -187,6 +195,13 @@ static int idpf_tx_buf_alloc_all(struct idpf_tx_queue *tx_q)
if (!tx_q->tx_buf)
return -ENOMEM;

+ if (tx_q->dev->dma_pmd_tx_hdrs)
+ tx_q->hdr_buf_va =
+ dma_alloc_coherent(tx_q->dev,
+ tx_q->buf_pool_size * MAX_TCP_HEADER,
+ &tx_q->hdr_buf_dma,
+ GFP_KERNEL | __GFP_NOWARN);
+
return 0;
}

@@ -2663,7 +2678,7 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q,

tx_desc = &tx_q->flex_tx[i];

- dma = dma_map_single(tx_q->dev, skb->data, size, DMA_TO_DEVICE);
+ dma = idpf_tx_map_hdr(tx_q, skb, first, size);

tx_buf = first;
first->nr_frags = 0;
@@ -2680,8 +2695,7 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q,
first->nr_frags++;
tx_buf->type = LIBETH_SQE_FRAG;

- /* record length, and DMA address */
- dma_unmap_len_set(tx_buf, len, size);
+ /* record DMA address */
dma_unmap_addr_set(tx_buf, dma, dma);

/* buf_addr is in same location for both desc types */
@@ -2784,6 +2798,7 @@ static void idpf_tx_splitq_map(struct idpf_tx_queue *tx_q,

size = skb_frag_size(frag);
data_len -= size;
+ dma_unmap_len_set(tx_buf, len, size);

dma = skb_frag_dma_map(tx_q->dev, frag, 0, size,
DMA_TO_DEVICE);
diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.h b/drivers/net/ethernet/intel/idpf/idpf_txrx.h
index 93547597efd2a..39458a8e5baa0 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.h
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.h
@@ -8,6 +8,7 @@
#include <linux/net/intel/virtchnl2_lan_desc.h>

#include <net/libeth/cache.h>
+#include <net/libeth/tx.h>
#include <net/libeth/types.h>
#include <net/netdev_queues.h>
#include <net/tcp.h>
@@ -639,6 +640,8 @@ libeth_cacheline_set_assert(struct idpf_rx_queue,
* @q_vector: Backreference to associated vector
* @buf_pool_size: Total number of idpf_tx_buf
* @rel_q_id: relative virtchnl queue index
+ * @hdr_buf_va: Base of the TX header bounce buffer array, or NULL
+ * @hdr_buf_dma: DMA address matching @hdr_buf_va
*/
struct idpf_tx_queue {
__cacheline_group_begin_aligned(read_mostly);
@@ -715,6 +718,8 @@ struct idpf_tx_queue {

u32 buf_pool_size;
u32 rel_q_id;
+ void *hdr_buf_va;
+ dma_addr_t hdr_buf_dma;
__cacheline_group_end_aligned(cold);
};
libeth_cacheline_set_assert(struct idpf_tx_queue, 64,
@@ -723,7 +728,7 @@ libeth_cacheline_set_assert(struct idpf_tx_queue, 64,
offsetofend(struct idpf_tx_queue, timer) +
offsetof(struct idpf_tx_queue, q_stats) -
offsetofend(struct idpf_tx_queue, tstamp_task),
- 32);
+ 48);

/**
* struct idpf_buf_queue - software structure representing a buffer queue
@@ -1131,4 +1136,24 @@ int idpf_tso(struct sk_buff *skb, struct idpf_tx_offload_params *off);

void idpf_wait_for_sw_marker_completion(const struct idpf_tx_queue *txq);

+static inline dma_addr_t idpf_tx_map_hdr(struct idpf_tx_queue *tx_q,
+ const struct sk_buff *skb,
+ struct libeth_sqe *first,
+ unsigned int size)
+{
+ u32 buf_idx = first - tx_q->tx_buf;
+
+ if (tx_q->hdr_buf_va && buf_idx < tx_q->buf_pool_size &&
+ size <= MAX_TCP_HEADER) {
+ u32 offset = buf_idx * MAX_TCP_HEADER;
+
+ memcpy(tx_q->hdr_buf_va + offset, skb->data, size);
+ dma_unmap_len_set(first, len, 0);
+ return tx_q->hdr_buf_dma + offset;
+ }
+
+ dma_unmap_len_set(first, len, size);
+ return dma_map_single(tx_q->dev, skb->data, size, DMA_TO_DEVICE);
+}
+
#endif /* !_IDPF_TXRX_H_ */
diff --git a/include/net/libeth/tx.h b/include/net/libeth/tx.h
index c3db5c6f16410..2720ab9393e90 100644
--- a/include/net/libeth/tx.h
+++ b/include/net/libeth/tx.h
@@ -130,8 +130,9 @@ static inline void libeth_tx_complete(struct libeth_sqe *sqe,
case LIBETH_SQE_SKB:
case LIBETH_SQE_FRAG:
case LIBETH_SQE_SLAB:
- dma_unmap_page(cp->dev, dma_unmap_addr(sqe, dma),
- dma_unmap_len(sqe, len), DMA_TO_DEVICE);
+ if (dma_unmap_len(sqe, len))
+ dma_unmap_page(cp->dev, dma_unmap_addr(sqe, dma),
+ dma_unmap_len(sqe, len), DMA_TO_DEVICE);
break;
default:
break;
--
2.56.0.rc1.315.gc6ed9934b7-goog