Convert core async_tx code (async_memset()) to do DMA unmapping
itself using the ->callback functionality.

Cc: Dan Williams <d...@fb.com>
Cc: Tomasz Figa <t.f...@samsung.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnier...@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.p...@samsung.com>
---
 crypto/async_tx/async_memset.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/crypto/async_tx/async_memset.c b/crypto/async_tx/async_memset.c
index a6a667b..cf30bf1 100644
--- a/crypto/async_tx/async_memset.c
+++ b/crypto/async_tx/async_memset.c
@@ -30,6 +30,17 @@
 #include <linux/dma-mapping.h>
 #include <linux/async_tx.h>
 
+static void async_memset_cb(void *dma_async_param)
+{
+       struct dma_async_tx_descriptor *tx = dma_async_param;
+       struct dma_device *dev = tx->chan->device;
+
+       dma_unmap_page(dev->dev, tx->dma_dst, tx->dma_len, DMA_FROM_DEVICE);
+
+       if (tx->orig_callback)
+               tx->orig_callback(tx->orig_callback_param);
+}
+
 /**
  * async_memset - attempt to fill memory with a dma engine.
  * @dest: destination page
@@ -47,10 +58,11 @@ async_memset(struct page *dest, int val, unsigned int 
offset, size_t len,
                                                      &dest, 1, NULL, 0, len);
        struct dma_device *device = chan ? chan->device : NULL;
        struct dma_async_tx_descriptor *tx = NULL;
+       dma_addr_t dma_dest;
 
        if (device && is_dma_fill_aligned(device, offset, 0, len)) {
-               dma_addr_t dma_dest;
-               unsigned long dma_prep_flags = 0;
+               unsigned long dma_prep_flags = DMA_COMPL_SKIP_SRC_UNMAP |
+                                              DMA_COMPL_SKIP_DEST_UNMAP;
 
                if (submit->cb_fn)
                        dma_prep_flags |= DMA_PREP_INTERRUPT;
@@ -68,7 +80,11 @@ async_memset(struct page *dest, int val, unsigned int 
offset, size_t len,
 
        if (tx) {
                pr_debug("%s: (async) len: %zu\n", __func__, len);
-               async_tx_submit(chan, tx, submit);
+
+               tx->dma_dst = dma_dest;
+               tx->dma_len = len;
+
+               __async_tx_submit(chan, tx, async_memset_cb, tx, submit);
        } else { /* run the memset synchronously */
                void *dest_buf;
                pr_debug("%s: (sync) len: %zu\n", __func__, len);
-- 
1.8.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to