Commit 4076e755 authored by Dan Williams's avatar Dan Williams

dmatest: convert to dmaengine_unmap_data

Remove the open coded unmap and add coverage for this core functionality
to dmatest.

Also fixes up a couple places where we leaked dma mappings.
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 2d88ce76
...@@ -326,20 +326,6 @@ static void dmatest_callback(void *arg) ...@@ -326,20 +326,6 @@ static void dmatest_callback(void *arg)
wake_up_all(done->wait); wake_up_all(done->wait);
} }
static inline void unmap_src(struct device *dev, dma_addr_t *addr, size_t len,
unsigned int count)
{
while (count--)
dma_unmap_single(dev, addr[count], len, DMA_TO_DEVICE);
}
static inline void unmap_dst(struct device *dev, dma_addr_t *addr, size_t len,
unsigned int count)
{
while (count--)
dma_unmap_single(dev, addr[count], len, DMA_BIDIRECTIONAL);
}
static unsigned int min_odd(unsigned int x, unsigned int y) static unsigned int min_odd(unsigned int x, unsigned int y)
{ {
unsigned int val = min(x, y); unsigned int val = min(x, y);
...@@ -484,8 +470,9 @@ static int dmatest_func(void *data) ...@@ -484,8 +470,9 @@ static int dmatest_func(void *data)
while (!kthread_should_stop() while (!kthread_should_stop()
&& !(params->iterations && total_tests >= params->iterations)) { && !(params->iterations && total_tests >= params->iterations)) {
struct dma_async_tx_descriptor *tx = NULL; struct dma_async_tx_descriptor *tx = NULL;
dma_addr_t dma_srcs[src_cnt]; struct dmaengine_unmap_data *um;
dma_addr_t dma_dsts[dst_cnt]; dma_addr_t srcs[src_cnt];
dma_addr_t *dsts;
u8 align = 0; u8 align = 0;
total_tests++; total_tests++;
...@@ -530,61 +517,75 @@ static int dmatest_func(void *data) ...@@ -530,61 +517,75 @@ static int dmatest_func(void *data)
len = 1 << align; len = 1 << align;
total_len += len; total_len += len;
for (i = 0; i < src_cnt; i++) { um = dmaengine_get_unmap_data(dev->dev, src_cnt+dst_cnt,
u8 *buf = thread->srcs[i] + src_off; GFP_KERNEL);
if (!um) {
failed_tests++;
result("unmap data NULL", total_tests,
src_off, dst_off, len, ret);
continue;
}
dma_srcs[i] = dma_map_single(dev->dev, buf, len, um->len = params->buf_size;
DMA_TO_DEVICE); for (i = 0; i < src_cnt; i++) {
ret = dma_mapping_error(dev->dev, dma_srcs[i]); unsigned long buf = (unsigned long) thread->srcs[i];
struct page *pg = virt_to_page(buf);
unsigned pg_off = buf & ~PAGE_MASK;
um->addr[i] = dma_map_page(dev->dev, pg, pg_off,
um->len, DMA_TO_DEVICE);
srcs[i] = um->addr[i] + src_off;
ret = dma_mapping_error(dev->dev, um->addr[i]);
if (ret) { if (ret) {
unmap_src(dev->dev, dma_srcs, len, i); dmaengine_unmap_put(um);
result("src mapping error", total_tests, result("src mapping error", total_tests,
src_off, dst_off, len, ret); src_off, dst_off, len, ret);
failed_tests++; failed_tests++;
continue; continue;
} }
um->to_cnt++;
} }
/* map with DMA_BIDIRECTIONAL to force writeback/invalidate */ /* map with DMA_BIDIRECTIONAL to force writeback/invalidate */
dsts = &um->addr[src_cnt];
for (i = 0; i < dst_cnt; i++) { for (i = 0; i < dst_cnt; i++) {
dma_dsts[i] = dma_map_single(dev->dev, thread->dsts[i], unsigned long buf = (unsigned long) thread->dsts[i];
params->buf_size, struct page *pg = virt_to_page(buf);
DMA_BIDIRECTIONAL); unsigned pg_off = buf & ~PAGE_MASK;
ret = dma_mapping_error(dev->dev, dma_dsts[i]);
dsts[i] = dma_map_page(dev->dev, pg, pg_off, um->len,
DMA_BIDIRECTIONAL);
ret = dma_mapping_error(dev->dev, dsts[i]);
if (ret) { if (ret) {
unmap_src(dev->dev, dma_srcs, len, src_cnt); dmaengine_unmap_put(um);
unmap_dst(dev->dev, dma_dsts, params->buf_size,
i);
result("dst mapping error", total_tests, result("dst mapping error", total_tests,
src_off, dst_off, len, ret); src_off, dst_off, len, ret);
failed_tests++; failed_tests++;
continue; continue;
} }
um->bidi_cnt++;
} }
if (thread->type == DMA_MEMCPY) if (thread->type == DMA_MEMCPY)
tx = dev->device_prep_dma_memcpy(chan, tx = dev->device_prep_dma_memcpy(chan,
dma_dsts[0] + dst_off, dsts[0] + dst_off,
dma_srcs[0], len, srcs[0], len, flags);
flags);
else if (thread->type == DMA_XOR) else if (thread->type == DMA_XOR)
tx = dev->device_prep_dma_xor(chan, tx = dev->device_prep_dma_xor(chan,
dma_dsts[0] + dst_off, dsts[0] + dst_off,
dma_srcs, src_cnt, srcs, src_cnt,
len, flags); len, flags);
else if (thread->type == DMA_PQ) { else if (thread->type == DMA_PQ) {
dma_addr_t dma_pq[dst_cnt]; dma_addr_t dma_pq[dst_cnt];
for (i = 0; i < dst_cnt; i++) for (i = 0; i < dst_cnt; i++)
dma_pq[i] = dma_dsts[i] + dst_off; dma_pq[i] = dsts[i] + dst_off;
tx = dev->device_prep_dma_pq(chan, dma_pq, dma_srcs, tx = dev->device_prep_dma_pq(chan, dma_pq, srcs,
src_cnt, pq_coefs, src_cnt, pq_coefs,
len, flags); len, flags);
} }
if (!tx) { if (!tx) {
unmap_src(dev->dev, dma_srcs, len, src_cnt); dmaengine_unmap_put(um);
unmap_dst(dev->dev, dma_dsts, params->buf_size,
dst_cnt);
result("prep error", total_tests, src_off, result("prep error", total_tests, src_off,
dst_off, len, ret); dst_off, len, ret);
msleep(100); msleep(100);
...@@ -598,6 +599,7 @@ static int dmatest_func(void *data) ...@@ -598,6 +599,7 @@ static int dmatest_func(void *data)
cookie = tx->tx_submit(tx); cookie = tx->tx_submit(tx);
if (dma_submit_error(cookie)) { if (dma_submit_error(cookie)) {
dmaengine_unmap_put(um);
result("submit error", total_tests, src_off, result("submit error", total_tests, src_off,
dst_off, len, ret); dst_off, len, ret);
msleep(100); msleep(100);
...@@ -620,11 +622,13 @@ static int dmatest_func(void *data) ...@@ -620,11 +622,13 @@ static int dmatest_func(void *data)
* free it this time?" dancing. For now, just * free it this time?" dancing. For now, just
* leave it dangling. * leave it dangling.
*/ */
dmaengine_unmap_put(um);
result("test timed out", total_tests, src_off, dst_off, result("test timed out", total_tests, src_off, dst_off,
len, 0); len, 0);
failed_tests++; failed_tests++;
continue; continue;
} else if (status != DMA_SUCCESS) { } else if (status != DMA_SUCCESS) {
dmaengine_unmap_put(um);
result(status == DMA_ERROR ? result(status == DMA_ERROR ?
"completion error status" : "completion error status" :
"completion busy status", total_tests, src_off, "completion busy status", total_tests, src_off,
...@@ -633,9 +637,7 @@ static int dmatest_func(void *data) ...@@ -633,9 +637,7 @@ static int dmatest_func(void *data)
continue; continue;
} }
/* Unmap by myself */ dmaengine_unmap_put(um);
unmap_src(dev->dev, dma_srcs, len, src_cnt);
unmap_dst(dev->dev, dma_dsts, params->buf_size, dst_cnt);
if (params->noverify) { if (params->noverify) {
dbg_result("test passed", total_tests, src_off, dst_off, dbg_result("test passed", total_tests, src_off, dst_off,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment