Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 May 2020 09:43:32 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r361204 - stable/11/sys/compat/linuxkpi/common/include/linux
Message-ID:  <202005180943.04I9hWNU077204@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Mon May 18 09:43:31 2020
New Revision: 361204
URL: https://svnweb.freebsd.org/changeset/base/361204

Log:
  MFC r360622:
  Implement more scatter and gather functions in the LinuxKPI.
  
  Differential Revision:	https://reviews.freebsd.org/D24611
  Submitted by:	ashafer_badland.io (Austin Shafer)
  Sponsored by:	Mellanox Technologies

Modified:
  stable/11/sys/compat/linuxkpi/common/include/linux/scatterlist.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/compat/linuxkpi/common/include/linux/scatterlist.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/linux/scatterlist.h	Mon May 18 09:37:02 2020	(r361203)
+++ stable/11/sys/compat/linuxkpi/common/include/linux/scatterlist.h	Mon May 18 09:43:31 2020	(r361204)
@@ -64,6 +64,10 @@ struct sg_page_iter {
 	} internal;
 };
 
+struct sg_dma_page_iter {
+	struct sg_page_iter base;
+};
+
 #define	SCATTERLIST_MAX_SEGMENT	(-1U & ~(PAGE_SIZE - 1))
 
 #define	SG_MAX_SINGLE_ALLOC	(PAGE_SIZE / sizeof(struct scatterlist))
@@ -83,6 +87,8 @@ struct sg_page_iter {
 #define	for_each_sg_page(sgl, iter, nents, pgoffset)			\
 	for (_sg_iter_init(sgl, iter, nents, pgoffset);			\
 	     (iter)->sg; _sg_iter_next(iter))
+#define	for_each_sg_dma_page(sgl, iter, nents, pgoffset) 		\
+	for_each_sg_page(sgl, &(iter)->base, nents, pgoffset)
 
 #define	for_each_sg(sglist, sg, sgmax, iter)				\
 	for (iter = 0, sg = (sglist); iter < (sgmax); iter++, sg = sg_next(sg))
@@ -402,6 +408,8 @@ sg_page_count(struct scatterlist *sg)
 {
 	return (PAGE_ALIGN(sg->offset + sg->length) >> PAGE_SHIFT);
 }
+#define	sg_dma_page_count(sg) \
+	sg_page_count(sg)
 
 static inline bool
 __sg_page_iter_next(struct sg_page_iter *piter)
@@ -424,6 +432,8 @@ __sg_page_iter_next(struct sg_page_iter *piter)
 	}
 	return (1);
 }
+#define	__sg_page_iter_dma_next(itr) \
+	__sg_page_iter_next(&(itr)->base)
 
 static inline void
 _sg_iter_init(struct scatterlist *sgl, struct sg_page_iter *iter,
@@ -441,11 +451,20 @@ _sg_iter_init(struct scatterlist *sgl, struct sg_page_
 	}
 }
 
-static inline dma_addr_t
-sg_page_iter_dma_address(struct sg_page_iter *spi)
-{
-	return (spi->sg->address + (spi->sg_pgoffset << PAGE_SHIFT));
-}
+/*
+ * sg_page_iter_dma_address() is implemented as a macro because it
+ * needs to accept two different and identical structure types. This
+ * allows both old and new code to co-exist. The compile time assert
+ * adds some safety, that the structure sizes match.
+ */
+#define	sg_page_iter_dma_address(spi) ({		\
+	struct sg_page_iter *__spi = (void *)(spi);	\
+	dma_addr_t __dma_address;			\
+	CTASSERT(sizeof(*(spi)) == sizeof(*__spi));	\
+	__dma_address = __spi->sg->address +	\
+	    (__spi->sg_pgoffset << PAGE_SHIFT);		\
+	__dma_address;					\
+})
 
 static inline struct page *
 sg_page_iter_page(struct sg_page_iter *piter)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005180943.04I9hWNU077204>