[PATCH v2 06/10] scatterlist: support "page-less" (__pfn_t only) entries

2015-05-06 Thread Dan Williams
From: Matthew Wilcox 

Given that an offset will never be more than PAGE_SIZE, steal the unused
bits of the offset to implement a flags field.  Move the existing "this
is a sg_chain() entry" flag to the new flags field, and add a new flag
(SG_FLAGS_PAGE) to indicate that there is a struct page backing for the
entry.

Signed-off-by: Dan Williams 
Signed-off-by: Matthew Wilcox 
---
 block/blk-merge.c |2 -
 drivers/dma/ste_dma40.c   |5 --
 drivers/mmc/card/queue.c  |4 +-
 include/asm-generic/scatterlist.h |9 
 include/crypto/scatterwalk.h  |   10 
 include/linux/scatterlist.h   |   91 +
 6 files changed, 105 insertions(+), 16 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 218ad1e57a49..82a688551b72 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -267,7 +267,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request 
*rq,
if (rq->cmd_flags & REQ_WRITE)
memset(q->dma_drain_buffer, 0, q->dma_drain_size);
 
-   sg->page_link &= ~0x02;
+   sg_unmark_end(sg);
sg = sg_next(sg);
sg_set_page(sg, virt_to_page(q->dma_drain_buffer),
q->dma_drain_size,
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index 3c10f034d4b9..e8c00642cacb 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -2562,10 +2562,7 @@ dma40_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t 
dma_addr,
dma_addr += period_len;
}
 
-   sg[periods].offset = 0;
-   sg_dma_len([periods]) = 0;
-   sg[periods].page_link =
-   ((unsigned long)sg | 0x01) & ~0x02;
+   sg_chain(sg, periods + 1, sg);
 
txd = d40_prep_sg(chan, sg, sg, periods, direction,
  DMA_PREP_INTERRUPT);
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 236d194c2883..127f76294e71 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -469,7 +469,7 @@ static unsigned int mmc_queue_packed_map_sg(struct 
mmc_queue *mq,
sg_set_buf(__sg, buf + offset, len);
offset += len;
remain -= len;
-   (__sg++)->page_link &= ~0x02;
+   sg_unmark_end(__sg++);
sg_len++;
} while (remain);
}
@@ -477,7 +477,7 @@ static unsigned int mmc_queue_packed_map_sg(struct 
mmc_queue *mq,
list_for_each_entry(req, >list, queuelist) {
sg_len += blk_rq_map_sg(mq->queue, req, __sg);
__sg = sg + (sg_len - 1);
-   (__sg++)->page_link &= ~0x02;
+   sg_unmark_end(__sg++);
}
sg_mark_end(sg + (sg_len - 1));
return sg_len;
diff --git a/include/asm-generic/scatterlist.h 
b/include/asm-generic/scatterlist.h
index 5de07355fad4..959f51572a8e 100644
--- a/include/asm-generic/scatterlist.h
+++ b/include/asm-generic/scatterlist.h
@@ -7,8 +7,17 @@ struct scatterlist {
 #ifdef CONFIG_DEBUG_SG
unsigned long   sg_magic;
 #endif
+#ifdef CONFIG_HAVE_DMA_PFN
+   union {
+   __pfn_t pfn;
+   struct scatterlist *next;
+   };
+   unsigned short  offset;
+   unsigned short  sg_flags;
+#else
unsigned long   page_link;
unsigned intoffset;
+#endif
unsigned intlength;
dma_addr_t  dma_address;
 #ifdef CONFIG_NEED_SG_DMA_LENGTH
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h
index 20e4226a2e14..7296d89a50b2 100644
--- a/include/crypto/scatterwalk.h
+++ b/include/crypto/scatterwalk.h
@@ -25,6 +25,15 @@
 #include 
 #include 
 
+#ifdef CONFIG_HAVE_DMA_PFN
+/*
+ * If we're using PFNs, the architecture must also have been converted to
+ * support SG_CHAIN.  So we can use the generic code instead of custom
+ * code.
+ */
+#define scatterwalk_sg_chain(prv, num, sgl)sg_chain(prv, num, sgl)
+#define scatterwalk_sg_next(sgl)   sg_next(sgl)
+#else
 static inline void scatterwalk_sg_chain(struct scatterlist *sg1, int num,
struct scatterlist *sg2)
 {
@@ -32,6 +41,7 @@ static inline void scatterwalk_sg_chain(struct scatterlist 
*sg1, int num,
sg1[num - 1].page_link &= ~0x02;
sg1[num - 1].page_link |= 0x01;
 }
+#endif
 
 static inline void scatterwalk_crypto_chain(struct scatterlist *head,
struct scatterlist *sg,
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index ed8f9e70df9b..9d423e559bdb 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -5,6 +5,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -18,8 +19,14 @@ struct sg_table {
 /*
  * Notes on SG table design.
  *
- * Architectures must provide an unsigned long 

[PATCH v2 06/10] scatterlist: support page-less (__pfn_t only) entries

2015-05-06 Thread Dan Williams
From: Matthew Wilcox wi...@linux.intel.com

Given that an offset will never be more than PAGE_SIZE, steal the unused
bits of the offset to implement a flags field.  Move the existing this
is a sg_chain() entry flag to the new flags field, and add a new flag
(SG_FLAGS_PAGE) to indicate that there is a struct page backing for the
entry.

Signed-off-by: Dan Williams dan.j.willi...@intel.com
Signed-off-by: Matthew Wilcox wi...@linux.intel.com
---
 block/blk-merge.c |2 -
 drivers/dma/ste_dma40.c   |5 --
 drivers/mmc/card/queue.c  |4 +-
 include/asm-generic/scatterlist.h |9 
 include/crypto/scatterwalk.h  |   10 
 include/linux/scatterlist.h   |   91 +
 6 files changed, 105 insertions(+), 16 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 218ad1e57a49..82a688551b72 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -267,7 +267,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request 
*rq,
if (rq-cmd_flags  REQ_WRITE)
memset(q-dma_drain_buffer, 0, q-dma_drain_size);
 
-   sg-page_link = ~0x02;
+   sg_unmark_end(sg);
sg = sg_next(sg);
sg_set_page(sg, virt_to_page(q-dma_drain_buffer),
q-dma_drain_size,
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index 3c10f034d4b9..e8c00642cacb 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -2562,10 +2562,7 @@ dma40_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t 
dma_addr,
dma_addr += period_len;
}
 
-   sg[periods].offset = 0;
-   sg_dma_len(sg[periods]) = 0;
-   sg[periods].page_link =
-   ((unsigned long)sg | 0x01)  ~0x02;
+   sg_chain(sg, periods + 1, sg);
 
txd = d40_prep_sg(chan, sg, sg, periods, direction,
  DMA_PREP_INTERRUPT);
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 236d194c2883..127f76294e71 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -469,7 +469,7 @@ static unsigned int mmc_queue_packed_map_sg(struct 
mmc_queue *mq,
sg_set_buf(__sg, buf + offset, len);
offset += len;
remain -= len;
-   (__sg++)-page_link = ~0x02;
+   sg_unmark_end(__sg++);
sg_len++;
} while (remain);
}
@@ -477,7 +477,7 @@ static unsigned int mmc_queue_packed_map_sg(struct 
mmc_queue *mq,
list_for_each_entry(req, packed-list, queuelist) {
sg_len += blk_rq_map_sg(mq-queue, req, __sg);
__sg = sg + (sg_len - 1);
-   (__sg++)-page_link = ~0x02;
+   sg_unmark_end(__sg++);
}
sg_mark_end(sg + (sg_len - 1));
return sg_len;
diff --git a/include/asm-generic/scatterlist.h 
b/include/asm-generic/scatterlist.h
index 5de07355fad4..959f51572a8e 100644
--- a/include/asm-generic/scatterlist.h
+++ b/include/asm-generic/scatterlist.h
@@ -7,8 +7,17 @@ struct scatterlist {
 #ifdef CONFIG_DEBUG_SG
unsigned long   sg_magic;
 #endif
+#ifdef CONFIG_HAVE_DMA_PFN
+   union {
+   __pfn_t pfn;
+   struct scatterlist *next;
+   };
+   unsigned short  offset;
+   unsigned short  sg_flags;
+#else
unsigned long   page_link;
unsigned intoffset;
+#endif
unsigned intlength;
dma_addr_t  dma_address;
 #ifdef CONFIG_NEED_SG_DMA_LENGTH
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h
index 20e4226a2e14..7296d89a50b2 100644
--- a/include/crypto/scatterwalk.h
+++ b/include/crypto/scatterwalk.h
@@ -25,6 +25,15 @@
 #include linux/scatterlist.h
 #include linux/sched.h
 
+#ifdef CONFIG_HAVE_DMA_PFN
+/*
+ * If we're using PFNs, the architecture must also have been converted to
+ * support SG_CHAIN.  So we can use the generic code instead of custom
+ * code.
+ */
+#define scatterwalk_sg_chain(prv, num, sgl)sg_chain(prv, num, sgl)
+#define scatterwalk_sg_next(sgl)   sg_next(sgl)
+#else
 static inline void scatterwalk_sg_chain(struct scatterlist *sg1, int num,
struct scatterlist *sg2)
 {
@@ -32,6 +41,7 @@ static inline void scatterwalk_sg_chain(struct scatterlist 
*sg1, int num,
sg1[num - 1].page_link = ~0x02;
sg1[num - 1].page_link |= 0x01;
 }
+#endif
 
 static inline void scatterwalk_crypto_chain(struct scatterlist *head,
struct scatterlist *sg,
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index ed8f9e70df9b..9d423e559bdb 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -5,6 +5,7 @@
 #include linux/bug.h
 #include linux/mm.h
 
+#include asm/page.h
 #include asm/types.h
 #include