[net-next v6 01/12] net: tso: Introduce tso_dma_map

Joe Damato posted 12 patches 6 days, 18 hours ago
There is a newer version of this series
[net-next v6 01/12] net: tso: Introduce tso_dma_map
Posted by Joe Damato 6 days, 18 hours ago
Add struct tso_dma_map to tso.h for tracking DMA addresses of mapped
GSO payload data.

The struct combines DMA mapping storage with iterator state, allowing
drivers to walk pre-mapped DMA regions linearly. Includes fields for
the DMA IOVA path (iova_state, iova_offset, total_len) and a fallback
per-region path (linear_dma, frags[], frag_idx, offset).

Helpers to initialize and operate on this struct will be added in the
next commit.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Joe Damato <joe@dama.to>
---
 v3:
   - struct tso_dma_map extended to track IOVA state and
     a fallback per-region path.

 include/net/tso.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/include/net/tso.h b/include/net/tso.h
index e7e157ae0526..8f8d9d74e873 100644
--- a/include/net/tso.h
+++ b/include/net/tso.h
@@ -3,6 +3,7 @@
 #define _TSO_H
 
 #include <linux/skbuff.h>
+#include <linux/dma-mapping.h>
 #include <net/ip.h>
 
 #define TSO_HEADER_SIZE		256
@@ -28,4 +29,43 @@ void tso_build_hdr(const struct sk_buff *skb, char *hdr, struct tso_t *tso,
 void tso_build_data(const struct sk_buff *skb, struct tso_t *tso, int size);
 int tso_start(struct sk_buff *skb, struct tso_t *tso);
 
+/**
+ * struct tso_dma_map - DMA mapping state for GSO payload
+ * @dev: device used for DMA mapping
+ * @skb: the GSO skb being mapped
+ * @hdr_len: per-segment header length
+ * @iova_state: DMA IOVA state (when IOMMU available)
+ * @iova_offset: global byte offset into IOVA range (IOVA path only)
+ * @total_len: total payload length
+ * @frag_idx: current region (-1 = linear, 0..nr_frags-1 = frag)
+ * @offset: byte offset within current region
+ * @linear_dma: DMA address of the linear payload
+ * @linear_len: length of the linear payload
+ * @nr_frags: number of frags successfully DMA-mapped
+ * @frags: per-frag DMA address and length
+ *
+ * DMA-maps the payload regions of a GSO skb (linear data + frags).
+ * Prefers the DMA IOVA API for a single contiguous mapping with one
+ * IOTLB sync; falls back to per-region dma_map_phys() otherwise.
+ */
+struct tso_dma_map {
+	struct device		*dev;
+	const struct sk_buff	*skb;
+	unsigned int		hdr_len;
+	/* IOVA path */
+	struct dma_iova_state	iova_state;
+	size_t			iova_offset;
+	size_t			total_len;
+	/* Fallback path if IOVA path fails */
+	int			frag_idx;
+	unsigned int		offset;
+	dma_addr_t		linear_dma;
+	unsigned int		linear_len;
+	unsigned int		nr_frags;
+	struct {
+		dma_addr_t	dma;
+		unsigned int	len;
+	} frags[MAX_SKB_FRAGS];
+};
+
 #endif	/* _TSO_H */
-- 
2.52.0
Re: [net-next v6 01/12] net: tso: Introduce tso_dma_map
Posted by Jakub Kicinski 3 days, 20 hours ago
On Thu, 26 Mar 2026 16:52:20 -0700 Joe Damato wrote:
> Add struct tso_dma_map to tso.h for tracking DMA addresses of mapped
> GSO payload data.
> 
> The struct combines DMA mapping storage with iterator state, allowing
> drivers to walk pre-mapped DMA regions linearly. Includes fields for
> the DMA IOVA path (iova_state, iova_offset, total_len) and a fallback
> per-region path (linear_dma, frags[], frag_idx, offset).
> 
> Helpers to initialize and operate on this struct will be added in the
> next commit.

Let's squash this with patch 2? Quite useful to see the struct when
reviewing the code..
Re: [net-next v6 01/12] net: tso: Introduce tso_dma_map
Posted by Joe Damato 3 days, 2 hours ago
On Sun, Mar 29, 2026 at 03:11:47PM -0700, Jakub Kicinski wrote:
> On Thu, 26 Mar 2026 16:52:20 -0700 Joe Damato wrote:
> > Add struct tso_dma_map to tso.h for tracking DMA addresses of mapped
> > GSO payload data.
> > 
> > The struct combines DMA mapping storage with iterator state, allowing
> > drivers to walk pre-mapped DMA regions linearly. Includes fields for
> > the DMA IOVA path (iova_state, iova_offset, total_len) and a fallback
> > per-region path (linear_dma, frags[], frag_idx, offset).
> > 
> > Helpers to initialize and operate on this struct will be added in the
> > next commit.
> 
> Let's squash this with patch 2? Quite useful to see the struct when
> reviewing the code..

Sure, will do for the v7.