2008-07-09 02:58:45 +08:00
|
|
|
/*
|
|
|
|
* DMA Engine test module
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Atmel Corporation
|
2013-03-04 17:09:30 +08:00
|
|
|
* Copyright (C) 2013 Intel Corporation
|
2008-07-09 02:58:45 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
2011-06-16 19:01:34 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2008-07-09 02:58:45 +08:00
|
|
|
#include <linux/dmaengine.h>
|
2011-08-18 22:50:51 +08:00
|
|
|
#include <linux/freezer.h>
|
2008-07-09 02:58:45 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/random.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-07-09 02:58:45 +08:00
|
|
|
#include <linux/wait.h>
|
2013-03-04 17:09:30 +08:00
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/seq_file.h>
|
2008-07-09 02:58:45 +08:00
|
|
|
|
|
|
|
static unsigned int test_buf_size = 16384;
|
|
|
|
module_param(test_buf_size, uint, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(test_buf_size, "Size of the memcpy test buffer");
|
|
|
|
|
2008-11-12 04:12:33 +08:00
|
|
|
static char test_channel[20];
|
2008-07-09 02:58:45 +08:00
|
|
|
module_param_string(channel, test_channel, sizeof(test_channel), S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(channel, "Bus ID of the channel to test (default: any)");
|
|
|
|
|
2008-11-12 04:12:33 +08:00
|
|
|
static char test_device[20];
|
2008-07-09 02:58:45 +08:00
|
|
|
module_param_string(device, test_device, sizeof(test_device), S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(device, "Bus ID of the DMA Engine to test (default: any)");
|
|
|
|
|
|
|
|
static unsigned int threads_per_chan = 1;
|
|
|
|
module_param(threads_per_chan, uint, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(threads_per_chan,
|
|
|
|
"Number of threads to start per channel (default: 1)");
|
|
|
|
|
|
|
|
static unsigned int max_channels;
|
|
|
|
module_param(max_channels, uint, S_IRUGO);
|
2009-01-07 02:38:15 +08:00
|
|
|
MODULE_PARM_DESC(max_channels,
|
2008-07-09 02:58:45 +08:00
|
|
|
"Maximum number of channels to use (default: all)");
|
|
|
|
|
2009-07-04 01:26:51 +08:00
|
|
|
static unsigned int iterations;
|
|
|
|
module_param(iterations, uint, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(iterations,
|
|
|
|
"Iterations before stopping test (default: infinite)");
|
|
|
|
|
2009-03-26 00:13:25 +08:00
|
|
|
static unsigned int xor_sources = 3;
|
|
|
|
module_param(xor_sources, uint, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(xor_sources,
|
|
|
|
"Number of xor source buffers (default: 3)");
|
|
|
|
|
2009-08-30 10:09:27 +08:00
|
|
|
static unsigned int pq_sources = 3;
|
|
|
|
module_param(pq_sources, uint, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(pq_sources,
|
|
|
|
"Number of p+q source buffers (default: 3)");
|
|
|
|
|
2011-03-22 19:57:25 +08:00
|
|
|
static int timeout = 3000;
|
|
|
|
module_param(timeout, uint, S_IRUGO);
|
2011-04-24 11:38:19 +08:00
|
|
|
MODULE_PARM_DESC(timeout, "Transfer Timeout in msec (default: 3000), "
|
|
|
|
"Pass -1 for infinite timeout");
|
2011-03-22 19:57:25 +08:00
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
/*
|
|
|
|
* Initialization patterns. All bytes in the source buffer has bit 7
|
|
|
|
* set, all bytes in the destination buffer has bit 7 cleared.
|
|
|
|
*
|
|
|
|
* Bit 6 is set for all bytes which are to be copied by the DMA
|
|
|
|
* engine. Bit 5 is set for all bytes which are to be overwritten by
|
|
|
|
* the DMA engine.
|
|
|
|
*
|
|
|
|
* The remaining bits are the inverse of a counter which increments by
|
|
|
|
* one for each byte address.
|
|
|
|
*/
|
|
|
|
#define PATTERN_SRC 0x80
|
|
|
|
#define PATTERN_DST 0x00
|
|
|
|
#define PATTERN_COPY 0x40
|
|
|
|
#define PATTERN_OVERWRITE 0x20
|
|
|
|
#define PATTERN_COUNT_MASK 0x1f
|
|
|
|
|
2013-03-04 17:09:27 +08:00
|
|
|
struct dmatest_info;
|
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
struct dmatest_thread {
|
|
|
|
struct list_head node;
|
2013-03-04 17:09:27 +08:00
|
|
|
struct dmatest_info *info;
|
2008-07-09 02:58:45 +08:00
|
|
|
struct task_struct *task;
|
|
|
|
struct dma_chan *chan;
|
2009-03-26 00:13:25 +08:00
|
|
|
u8 **srcs;
|
|
|
|
u8 **dsts;
|
|
|
|
enum dma_transaction_type type;
|
2008-07-09 02:58:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dmatest_chan {
|
|
|
|
struct list_head node;
|
|
|
|
struct dma_chan *chan;
|
|
|
|
struct list_head threads;
|
|
|
|
};
|
|
|
|
|
2013-03-04 17:09:27 +08:00
|
|
|
/**
|
2013-03-04 17:09:29 +08:00
|
|
|
* struct dmatest_params - test parameters.
|
2013-03-04 17:09:27 +08:00
|
|
|
* @buf_size: size of the memcpy test buffer
|
|
|
|
* @channel: bus ID of the channel to test
|
|
|
|
* @device: bus ID of the DMA Engine to test
|
|
|
|
* @threads_per_chan: number of threads to start per channel
|
|
|
|
* @max_channels: maximum number of channels to use
|
|
|
|
* @iterations: iterations before stopping test
|
|
|
|
* @xor_sources: number of xor source buffers
|
|
|
|
* @pq_sources: number of p+q source buffers
|
|
|
|
* @timeout: transfer timeout in msec, -1 for infinite timeout
|
|
|
|
*/
|
2013-03-04 17:09:29 +08:00
|
|
|
struct dmatest_params {
|
2013-03-04 17:09:27 +08:00
|
|
|
unsigned int buf_size;
|
|
|
|
char channel[20];
|
|
|
|
char device[20];
|
|
|
|
unsigned int threads_per_chan;
|
|
|
|
unsigned int max_channels;
|
|
|
|
unsigned int iterations;
|
|
|
|
unsigned int xor_sources;
|
|
|
|
unsigned int pq_sources;
|
|
|
|
int timeout;
|
2013-03-04 17:09:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct dmatest_info - test information.
|
|
|
|
* @params: test parameters
|
2013-03-04 17:09:30 +08:00
|
|
|
* @lock: access protection to the fields of this structure
|
2013-03-04 17:09:29 +08:00
|
|
|
*/
|
|
|
|
struct dmatest_info {
|
|
|
|
/* Test parameters */
|
|
|
|
struct dmatest_params params;
|
2013-03-04 17:09:28 +08:00
|
|
|
|
|
|
|
/* Internal state */
|
|
|
|
struct list_head channels;
|
|
|
|
unsigned int nr_channels;
|
2013-03-04 17:09:30 +08:00
|
|
|
struct mutex lock;
|
|
|
|
|
|
|
|
/* debugfs related stuff */
|
|
|
|
struct dentry *root;
|
|
|
|
struct dmatest_params dbgfs_params;
|
2013-03-04 17:09:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct dmatest_info test_info;
|
|
|
|
|
2013-03-04 17:09:29 +08:00
|
|
|
static bool dmatest_match_channel(struct dmatest_params *params,
|
2013-03-04 17:09:27 +08:00
|
|
|
struct dma_chan *chan)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
2013-03-04 17:09:29 +08:00
|
|
|
if (params->channel[0] == '\0')
|
2008-07-09 02:58:45 +08:00
|
|
|
return true;
|
2013-03-04 17:09:29 +08:00
|
|
|
return strcmp(dma_chan_name(chan), params->channel) == 0;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:29 +08:00
|
|
|
static bool dmatest_match_device(struct dmatest_params *params,
|
2013-03-04 17:09:27 +08:00
|
|
|
struct dma_device *device)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
2013-03-04 17:09:29 +08:00
|
|
|
if (params->device[0] == '\0')
|
2008-07-09 02:58:45 +08:00
|
|
|
return true;
|
2013-03-04 17:09:29 +08:00
|
|
|
return strcmp(dev_name(device->dev), params->device) == 0;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long dmatest_random(void)
|
|
|
|
{
|
|
|
|
unsigned long buf;
|
|
|
|
|
|
|
|
get_random_bytes(&buf, sizeof(buf));
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:27 +08:00
|
|
|
static void dmatest_init_srcs(u8 **bufs, unsigned int start, unsigned int len,
|
|
|
|
unsigned int buf_size)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2009-03-26 00:13:25 +08:00
|
|
|
u8 *buf;
|
|
|
|
|
|
|
|
for (; (buf = *bufs); bufs++) {
|
|
|
|
for (i = 0; i < start; i++)
|
|
|
|
buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK);
|
|
|
|
for ( ; i < start + len; i++)
|
|
|
|
buf[i] = PATTERN_SRC | PATTERN_COPY
|
2009-06-29 00:26:21 +08:00
|
|
|
| (~i & PATTERN_COUNT_MASK);
|
2013-03-04 17:09:27 +08:00
|
|
|
for ( ; i < buf_size; i++)
|
2009-03-26 00:13:25 +08:00
|
|
|
buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK);
|
|
|
|
buf++;
|
|
|
|
}
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:27 +08:00
|
|
|
static void dmatest_init_dsts(u8 **bufs, unsigned int start, unsigned int len,
|
|
|
|
unsigned int buf_size)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2009-03-26 00:13:25 +08:00
|
|
|
u8 *buf;
|
|
|
|
|
|
|
|
for (; (buf = *bufs); bufs++) {
|
|
|
|
for (i = 0; i < start; i++)
|
|
|
|
buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK);
|
|
|
|
for ( ; i < start + len; i++)
|
|
|
|
buf[i] = PATTERN_DST | PATTERN_OVERWRITE
|
|
|
|
| (~i & PATTERN_COUNT_MASK);
|
2013-03-04 17:09:27 +08:00
|
|
|
for ( ; i < buf_size; i++)
|
2009-03-26 00:13:25 +08:00
|
|
|
buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK);
|
|
|
|
}
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index,
|
|
|
|
unsigned int counter, bool is_srcbuf)
|
|
|
|
{
|
|
|
|
u8 diff = actual ^ pattern;
|
|
|
|
u8 expected = pattern | (~counter & PATTERN_COUNT_MASK);
|
|
|
|
const char *thread_name = current->comm;
|
|
|
|
|
|
|
|
if (is_srcbuf)
|
|
|
|
pr_warning("%s: srcbuf[0x%x] overwritten!"
|
|
|
|
" Expected %02x, got %02x\n",
|
|
|
|
thread_name, index, expected, actual);
|
|
|
|
else if ((pattern & PATTERN_COPY)
|
|
|
|
&& (diff & (PATTERN_COPY | PATTERN_OVERWRITE)))
|
|
|
|
pr_warning("%s: dstbuf[0x%x] not copied!"
|
|
|
|
" Expected %02x, got %02x\n",
|
|
|
|
thread_name, index, expected, actual);
|
|
|
|
else if (diff & PATTERN_SRC)
|
|
|
|
pr_warning("%s: dstbuf[0x%x] was copied!"
|
|
|
|
" Expected %02x, got %02x\n",
|
|
|
|
thread_name, index, expected, actual);
|
|
|
|
else
|
|
|
|
pr_warning("%s: dstbuf[0x%x] mismatch!"
|
|
|
|
" Expected %02x, got %02x\n",
|
|
|
|
thread_name, index, expected, actual);
|
|
|
|
}
|
|
|
|
|
2009-03-26 00:13:25 +08:00
|
|
|
static unsigned int dmatest_verify(u8 **bufs, unsigned int start,
|
2008-07-09 02:58:45 +08:00
|
|
|
unsigned int end, unsigned int counter, u8 pattern,
|
|
|
|
bool is_srcbuf)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int error_count = 0;
|
|
|
|
u8 actual;
|
2009-03-26 00:13:25 +08:00
|
|
|
u8 expected;
|
|
|
|
u8 *buf;
|
|
|
|
unsigned int counter_orig = counter;
|
|
|
|
|
|
|
|
for (; (buf = *bufs); bufs++) {
|
|
|
|
counter = counter_orig;
|
|
|
|
for (i = start; i < end; i++) {
|
|
|
|
actual = buf[i];
|
|
|
|
expected = pattern | (~counter & PATTERN_COUNT_MASK);
|
|
|
|
if (actual != expected) {
|
|
|
|
if (error_count < 32)
|
|
|
|
dmatest_mismatch(actual, pattern, i,
|
|
|
|
counter, is_srcbuf);
|
|
|
|
error_count++;
|
|
|
|
}
|
|
|
|
counter++;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error_count > 32)
|
|
|
|
pr_warning("%s: %u errors suppressed\n",
|
|
|
|
current->comm, error_count - 32);
|
|
|
|
|
|
|
|
return error_count;
|
|
|
|
}
|
|
|
|
|
2011-11-24 01:28:16 +08:00
|
|
|
/* poor man's completion - we want to use wait_event_freezable() on it */
|
|
|
|
struct dmatest_done {
|
|
|
|
bool done;
|
|
|
|
wait_queue_head_t *wait;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void dmatest_callback(void *arg)
|
2009-03-26 00:13:25 +08:00
|
|
|
{
|
2011-11-24 01:28:16 +08:00
|
|
|
struct dmatest_done *done = arg;
|
|
|
|
|
|
|
|
done->done = true;
|
|
|
|
wake_up_all(done->wait);
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 07:59:52 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-10-27 23:49:32 +08:00
|
|
|
static unsigned int min_odd(unsigned int x, unsigned int y)
|
|
|
|
{
|
|
|
|
unsigned int val = min(x, y);
|
|
|
|
|
|
|
|
return val % 2 ? val : val - 1;
|
|
|
|
}
|
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
/*
|
|
|
|
* This function repeatedly tests DMA transfers of various lengths and
|
2009-03-26 00:13:25 +08:00
|
|
|
* offsets for a given operation type until it is told to exit by
|
|
|
|
* kthread_stop(). There may be multiple threads running this function
|
|
|
|
* in parallel for a single channel, and there may be multiple channels
|
|
|
|
* being tested in parallel.
|
2008-07-09 02:58:45 +08:00
|
|
|
*
|
|
|
|
* Before each test, the source and destination buffer is initialized
|
|
|
|
* with a known pattern. This pattern is different depending on
|
|
|
|
* whether it's in an area which is supposed to be copied or
|
|
|
|
* overwritten, and different in the source and destination buffers.
|
|
|
|
* So if the DMA engine doesn't copy exactly what we tell it to copy,
|
|
|
|
* we'll notice.
|
|
|
|
*/
|
|
|
|
static int dmatest_func(void *data)
|
|
|
|
{
|
2011-11-24 01:28:16 +08:00
|
|
|
DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_wait);
|
2008-07-09 02:58:45 +08:00
|
|
|
struct dmatest_thread *thread = data;
|
2011-11-24 01:28:16 +08:00
|
|
|
struct dmatest_done done = { .wait = &done_wait };
|
2013-03-04 17:09:27 +08:00
|
|
|
struct dmatest_info *info;
|
2013-03-04 17:09:29 +08:00
|
|
|
struct dmatest_params *params;
|
2008-07-09 02:58:45 +08:00
|
|
|
struct dma_chan *chan;
|
2012-10-27 23:49:32 +08:00
|
|
|
struct dma_device *dev;
|
2008-07-09 02:58:45 +08:00
|
|
|
const char *thread_name;
|
|
|
|
unsigned int src_off, dst_off, len;
|
|
|
|
unsigned int error_count;
|
|
|
|
unsigned int failed_tests = 0;
|
|
|
|
unsigned int total_tests = 0;
|
|
|
|
dma_cookie_t cookie;
|
|
|
|
enum dma_status status;
|
2009-03-26 00:13:25 +08:00
|
|
|
enum dma_ctrl_flags flags;
|
2013-03-04 17:09:26 +08:00
|
|
|
u8 *pq_coefs = NULL;
|
2008-07-09 02:58:45 +08:00
|
|
|
int ret;
|
2009-03-26 00:13:25 +08:00
|
|
|
int src_cnt;
|
|
|
|
int dst_cnt;
|
|
|
|
int i;
|
2008-07-09 02:58:45 +08:00
|
|
|
|
|
|
|
thread_name = current->comm;
|
2011-11-24 01:28:16 +08:00
|
|
|
set_freezable();
|
2008-07-09 02:58:45 +08:00
|
|
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
|
|
|
|
smp_rmb();
|
2013-03-04 17:09:27 +08:00
|
|
|
info = thread->info;
|
2013-03-04 17:09:29 +08:00
|
|
|
params = &info->params;
|
2008-07-09 02:58:45 +08:00
|
|
|
chan = thread->chan;
|
2012-10-27 23:49:32 +08:00
|
|
|
dev = chan->device;
|
2009-03-26 00:13:25 +08:00
|
|
|
if (thread->type == DMA_MEMCPY)
|
|
|
|
src_cnt = dst_cnt = 1;
|
|
|
|
else if (thread->type == DMA_XOR) {
|
2012-10-27 23:49:32 +08:00
|
|
|
/* force odd to ensure dst = src */
|
2013-03-04 17:09:29 +08:00
|
|
|
src_cnt = min_odd(params->xor_sources | 1, dev->max_xor);
|
2009-03-26 00:13:25 +08:00
|
|
|
dst_cnt = 1;
|
2009-08-30 10:09:27 +08:00
|
|
|
} else if (thread->type == DMA_PQ) {
|
2012-10-27 23:49:32 +08:00
|
|
|
/* force odd to ensure dst = src */
|
2013-03-04 17:09:29 +08:00
|
|
|
src_cnt = min_odd(params->pq_sources | 1, dma_maxpq(dev, 0));
|
2009-08-30 10:09:27 +08:00
|
|
|
dst_cnt = 2;
|
2013-03-04 17:09:26 +08:00
|
|
|
|
2013-03-04 17:09:29 +08:00
|
|
|
pq_coefs = kmalloc(params->pq_sources+1, GFP_KERNEL);
|
2013-03-04 17:09:26 +08:00
|
|
|
if (!pq_coefs)
|
|
|
|
goto err_thread_type;
|
|
|
|
|
2010-02-16 05:35:23 +08:00
|
|
|
for (i = 0; i < src_cnt; i++)
|
2009-08-30 10:09:27 +08:00
|
|
|
pq_coefs[i] = 1;
|
2009-03-26 00:13:25 +08:00
|
|
|
} else
|
2013-03-04 17:09:26 +08:00
|
|
|
goto err_thread_type;
|
2009-03-26 00:13:25 +08:00
|
|
|
|
|
|
|
thread->srcs = kcalloc(src_cnt+1, sizeof(u8 *), GFP_KERNEL);
|
|
|
|
if (!thread->srcs)
|
|
|
|
goto err_srcs;
|
|
|
|
for (i = 0; i < src_cnt; i++) {
|
2013-03-04 17:09:29 +08:00
|
|
|
thread->srcs[i] = kmalloc(params->buf_size, GFP_KERNEL);
|
2009-03-26 00:13:25 +08:00
|
|
|
if (!thread->srcs[i])
|
|
|
|
goto err_srcbuf;
|
|
|
|
}
|
|
|
|
thread->srcs[i] = NULL;
|
|
|
|
|
|
|
|
thread->dsts = kcalloc(dst_cnt+1, sizeof(u8 *), GFP_KERNEL);
|
|
|
|
if (!thread->dsts)
|
|
|
|
goto err_dsts;
|
|
|
|
for (i = 0; i < dst_cnt; i++) {
|
2013-03-04 17:09:29 +08:00
|
|
|
thread->dsts[i] = kmalloc(params->buf_size, GFP_KERNEL);
|
2009-03-26 00:13:25 +08:00
|
|
|
if (!thread->dsts[i])
|
|
|
|
goto err_dstbuf;
|
|
|
|
}
|
|
|
|
thread->dsts[i] = NULL;
|
|
|
|
|
2009-03-26 00:13:25 +08:00
|
|
|
set_user_nice(current, 10);
|
|
|
|
|
2011-03-03 15:54:53 +08:00
|
|
|
/*
|
|
|
|
* src buffers are freed by the DMAEngine code with dma_unmap_single()
|
|
|
|
* dst buffers are freed by ourselves below
|
|
|
|
*/
|
|
|
|
flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT
|
|
|
|
| DMA_COMPL_SKIP_DEST_UNMAP | DMA_COMPL_SRC_UNMAP_SINGLE;
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2009-07-04 01:26:51 +08:00
|
|
|
while (!kthread_should_stop()
|
2013-03-04 17:09:29 +08:00
|
|
|
&& !(params->iterations && total_tests >= params->iterations)) {
|
2009-03-26 00:13:25 +08:00
|
|
|
struct dma_async_tx_descriptor *tx = NULL;
|
|
|
|
dma_addr_t dma_srcs[src_cnt];
|
|
|
|
dma_addr_t dma_dsts[dst_cnt];
|
2009-09-09 08:42:53 +08:00
|
|
|
u8 align = 0;
|
2009-01-14 00:22:20 +08:00
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
total_tests++;
|
|
|
|
|
2009-09-09 08:42:53 +08:00
|
|
|
/* honor alignment restrictions */
|
|
|
|
if (thread->type == DMA_MEMCPY)
|
|
|
|
align = dev->copy_align;
|
|
|
|
else if (thread->type == DMA_XOR)
|
|
|
|
align = dev->xor_align;
|
|
|
|
else if (thread->type == DMA_PQ)
|
|
|
|
align = dev->pq_align;
|
|
|
|
|
2013-03-04 17:09:29 +08:00
|
|
|
if (1 << align > params->buf_size) {
|
2009-12-05 02:44:48 +08:00
|
|
|
pr_err("%u-byte buffer too small for %d-byte alignment\n",
|
2013-03-04 17:09:29 +08:00
|
|
|
params->buf_size, 1 << align);
|
2009-12-05 02:44:48 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:29 +08:00
|
|
|
len = dmatest_random() % params->buf_size + 1;
|
2009-09-09 08:42:53 +08:00
|
|
|
len = (len >> align) << align;
|
2009-12-05 02:44:48 +08:00
|
|
|
if (!len)
|
|
|
|
len = 1 << align;
|
2013-03-04 17:09:29 +08:00
|
|
|
src_off = dmatest_random() % (params->buf_size - len + 1);
|
|
|
|
dst_off = dmatest_random() % (params->buf_size - len + 1);
|
2009-12-05 02:44:48 +08:00
|
|
|
|
2009-09-09 08:42:53 +08:00
|
|
|
src_off = (src_off >> align) << align;
|
|
|
|
dst_off = (dst_off >> align) << align;
|
|
|
|
|
2013-03-04 17:09:29 +08:00
|
|
|
dmatest_init_srcs(thread->srcs, src_off, len, params->buf_size);
|
|
|
|
dmatest_init_dsts(thread->dsts, dst_off, len, params->buf_size);
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2009-03-26 00:13:25 +08:00
|
|
|
for (i = 0; i < src_cnt; i++) {
|
|
|
|
u8 *buf = thread->srcs[i] + src_off;
|
|
|
|
|
|
|
|
dma_srcs[i] = dma_map_single(dev->dev, buf, len,
|
|
|
|
DMA_TO_DEVICE);
|
2012-12-18 07:59:53 +08:00
|
|
|
ret = dma_mapping_error(dev->dev, dma_srcs[i]);
|
|
|
|
if (ret) {
|
|
|
|
unmap_src(dev->dev, dma_srcs, len, i);
|
|
|
|
pr_warn("%s: #%u: mapping error %d with "
|
|
|
|
"src_off=0x%x len=0x%x\n",
|
|
|
|
thread_name, total_tests - 1, ret,
|
|
|
|
src_off, len);
|
|
|
|
failed_tests++;
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
2009-01-14 00:22:20 +08:00
|
|
|
/* map with DMA_BIDIRECTIONAL to force writeback/invalidate */
|
2009-03-26 00:13:25 +08:00
|
|
|
for (i = 0; i < dst_cnt; i++) {
|
|
|
|
dma_dsts[i] = dma_map_single(dev->dev, thread->dsts[i],
|
2013-03-04 17:09:29 +08:00
|
|
|
params->buf_size,
|
2009-03-26 00:13:25 +08:00
|
|
|
DMA_BIDIRECTIONAL);
|
2012-12-18 07:59:53 +08:00
|
|
|
ret = dma_mapping_error(dev->dev, dma_dsts[i]);
|
|
|
|
if (ret) {
|
|
|
|
unmap_src(dev->dev, dma_srcs, len, src_cnt);
|
2013-03-04 17:09:29 +08:00
|
|
|
unmap_dst(dev->dev, dma_dsts, params->buf_size,
|
|
|
|
i);
|
2012-12-18 07:59:53 +08:00
|
|
|
pr_warn("%s: #%u: mapping error %d with "
|
|
|
|
"dst_off=0x%x len=0x%x\n",
|
|
|
|
thread_name, total_tests - 1, ret,
|
2013-03-04 17:09:29 +08:00
|
|
|
dst_off, params->buf_size);
|
2012-12-18 07:59:53 +08:00
|
|
|
failed_tests++;
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (thread->type == DMA_MEMCPY)
|
|
|
|
tx = dev->device_prep_dma_memcpy(chan,
|
|
|
|
dma_dsts[0] + dst_off,
|
|
|
|
dma_srcs[0], len,
|
|
|
|
flags);
|
|
|
|
else if (thread->type == DMA_XOR)
|
|
|
|
tx = dev->device_prep_dma_xor(chan,
|
|
|
|
dma_dsts[0] + dst_off,
|
2010-03-01 13:20:18 +08:00
|
|
|
dma_srcs, src_cnt,
|
2009-03-26 00:13:25 +08:00
|
|
|
len, flags);
|
2009-08-30 10:09:27 +08:00
|
|
|
else if (thread->type == DMA_PQ) {
|
|
|
|
dma_addr_t dma_pq[dst_cnt];
|
|
|
|
|
|
|
|
for (i = 0; i < dst_cnt; i++)
|
|
|
|
dma_pq[i] = dma_dsts[i] + dst_off;
|
|
|
|
tx = dev->device_prep_dma_pq(chan, dma_pq, dma_srcs,
|
2010-02-16 05:35:23 +08:00
|
|
|
src_cnt, pq_coefs,
|
2009-08-30 10:09:27 +08:00
|
|
|
len, flags);
|
|
|
|
}
|
2009-01-14 00:22:20 +08:00
|
|
|
|
|
|
|
if (!tx) {
|
2012-12-18 07:59:52 +08:00
|
|
|
unmap_src(dev->dev, dma_srcs, len, src_cnt);
|
2013-03-04 17:09:29 +08:00
|
|
|
unmap_dst(dev->dev, dma_dsts, params->buf_size,
|
|
|
|
dst_cnt);
|
2009-01-14 00:22:20 +08:00
|
|
|
pr_warning("%s: #%u: prep error with src_off=0x%x "
|
|
|
|
"dst_off=0x%x len=0x%x\n",
|
|
|
|
thread_name, total_tests - 1,
|
|
|
|
src_off, dst_off, len);
|
|
|
|
msleep(100);
|
|
|
|
failed_tests++;
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
|
2011-11-24 01:28:16 +08:00
|
|
|
done.done = false;
|
2009-03-26 00:13:25 +08:00
|
|
|
tx->callback = dmatest_callback;
|
2011-11-24 01:28:16 +08:00
|
|
|
tx->callback_param = &done;
|
2009-01-14 00:22:20 +08:00
|
|
|
cookie = tx->tx_submit(tx);
|
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
if (dma_submit_error(cookie)) {
|
|
|
|
pr_warning("%s: #%u: submit error %d with src_off=0x%x "
|
|
|
|
"dst_off=0x%x len=0x%x\n",
|
|
|
|
thread_name, total_tests - 1, cookie,
|
|
|
|
src_off, dst_off, len);
|
|
|
|
msleep(100);
|
|
|
|
failed_tests++;
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
dma_async_issue_pending(chan);
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2013-03-04 17:09:25 +08:00
|
|
|
wait_event_freezable_timeout(done_wait,
|
|
|
|
done.done || kthread_should_stop(),
|
2013-03-04 17:09:29 +08:00
|
|
|
msecs_to_jiffies(params->timeout));
|
2011-08-18 22:50:51 +08:00
|
|
|
|
2009-03-26 00:13:25 +08:00
|
|
|
status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2011-11-24 01:28:16 +08:00
|
|
|
if (!done.done) {
|
|
|
|
/*
|
|
|
|
* We're leaving the timed out dma operation with
|
|
|
|
* dangling pointer to done_wait. To make this
|
|
|
|
* correct, we'll need to allocate wait_done for
|
|
|
|
* each test iteration and perform "who's gonna
|
|
|
|
* free it this time?" dancing. For now, just
|
|
|
|
* leave it dangling.
|
|
|
|
*/
|
2009-03-26 00:13:25 +08:00
|
|
|
pr_warning("%s: #%u: test timed out\n",
|
|
|
|
thread_name, total_tests - 1);
|
|
|
|
failed_tests++;
|
|
|
|
continue;
|
|
|
|
} else if (status != DMA_SUCCESS) {
|
|
|
|
pr_warning("%s: #%u: got completion callback,"
|
|
|
|
" but status is \'%s\'\n",
|
|
|
|
thread_name, total_tests - 1,
|
|
|
|
status == DMA_ERROR ? "error" : "in progress");
|
2008-07-09 02:58:45 +08:00
|
|
|
failed_tests++;
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
|
2009-01-14 00:22:20 +08:00
|
|
|
/* Unmap by myself (see DMA_COMPL_SKIP_DEST_UNMAP above) */
|
2013-03-04 17:09:29 +08:00
|
|
|
unmap_dst(dev->dev, dma_dsts, params->buf_size, dst_cnt);
|
2008-07-09 02:58:45 +08:00
|
|
|
|
|
|
|
error_count = 0;
|
|
|
|
|
|
|
|
pr_debug("%s: verifying source buffer...\n", thread_name);
|
2009-03-26 00:13:25 +08:00
|
|
|
error_count += dmatest_verify(thread->srcs, 0, src_off,
|
2008-07-09 02:58:45 +08:00
|
|
|
0, PATTERN_SRC, true);
|
2009-03-26 00:13:25 +08:00
|
|
|
error_count += dmatest_verify(thread->srcs, src_off,
|
2008-07-09 02:58:45 +08:00
|
|
|
src_off + len, src_off,
|
|
|
|
PATTERN_SRC | PATTERN_COPY, true);
|
2009-03-26 00:13:25 +08:00
|
|
|
error_count += dmatest_verify(thread->srcs, src_off + len,
|
2013-03-04 17:09:29 +08:00
|
|
|
params->buf_size, src_off + len,
|
2008-07-09 02:58:45 +08:00
|
|
|
PATTERN_SRC, true);
|
|
|
|
|
|
|
|
pr_debug("%s: verifying dest buffer...\n",
|
|
|
|
thread->task->comm);
|
2009-03-26 00:13:25 +08:00
|
|
|
error_count += dmatest_verify(thread->dsts, 0, dst_off,
|
2008-07-09 02:58:45 +08:00
|
|
|
0, PATTERN_DST, false);
|
2009-03-26 00:13:25 +08:00
|
|
|
error_count += dmatest_verify(thread->dsts, dst_off,
|
2008-07-09 02:58:45 +08:00
|
|
|
dst_off + len, src_off,
|
|
|
|
PATTERN_SRC | PATTERN_COPY, false);
|
2009-03-26 00:13:25 +08:00
|
|
|
error_count += dmatest_verify(thread->dsts, dst_off + len,
|
2013-03-04 17:09:29 +08:00
|
|
|
params->buf_size, dst_off + len,
|
2008-07-09 02:58:45 +08:00
|
|
|
PATTERN_DST, false);
|
|
|
|
|
|
|
|
if (error_count) {
|
|
|
|
pr_warning("%s: #%u: %u errors with "
|
|
|
|
"src_off=0x%x dst_off=0x%x len=0x%x\n",
|
|
|
|
thread_name, total_tests - 1, error_count,
|
|
|
|
src_off, dst_off, len);
|
|
|
|
failed_tests++;
|
|
|
|
} else {
|
|
|
|
pr_debug("%s: #%u: No errors with "
|
|
|
|
"src_off=0x%x dst_off=0x%x len=0x%x\n",
|
|
|
|
thread_name, total_tests - 1,
|
|
|
|
src_off, dst_off, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2009-03-26 00:13:25 +08:00
|
|
|
for (i = 0; thread->dsts[i]; i++)
|
|
|
|
kfree(thread->dsts[i]);
|
2008-07-09 02:58:45 +08:00
|
|
|
err_dstbuf:
|
2009-03-26 00:13:25 +08:00
|
|
|
kfree(thread->dsts);
|
|
|
|
err_dsts:
|
|
|
|
for (i = 0; thread->srcs[i]; i++)
|
|
|
|
kfree(thread->srcs[i]);
|
2008-07-09 02:58:45 +08:00
|
|
|
err_srcbuf:
|
2009-03-26 00:13:25 +08:00
|
|
|
kfree(thread->srcs);
|
|
|
|
err_srcs:
|
2013-03-04 17:09:26 +08:00
|
|
|
kfree(pq_coefs);
|
|
|
|
err_thread_type:
|
2008-07-09 02:58:45 +08:00
|
|
|
pr_notice("%s: terminating after %u tests, %u failures (status %d)\n",
|
|
|
|
thread_name, total_tests, failed_tests, ret);
|
2009-07-04 01:26:51 +08:00
|
|
|
|
2011-07-29 18:51:57 +08:00
|
|
|
/* terminate all transfers on specified channels */
|
2012-11-09 23:26:29 +08:00
|
|
|
if (ret)
|
|
|
|
dmaengine_terminate_all(chan);
|
|
|
|
|
2013-03-04 17:09:29 +08:00
|
|
|
if (params->iterations > 0)
|
2009-07-04 01:26:51 +08:00
|
|
|
while (!kthread_should_stop()) {
|
2010-02-05 21:52:37 +08:00
|
|
|
DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit);
|
2009-07-04 01:26:51 +08:00
|
|
|
interruptible_sleep_on(&wait_dmatest_exit);
|
|
|
|
}
|
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dmatest_cleanup_channel(struct dmatest_chan *dtc)
|
|
|
|
{
|
|
|
|
struct dmatest_thread *thread;
|
|
|
|
struct dmatest_thread *_thread;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(thread, _thread, &dtc->threads, node) {
|
|
|
|
ret = kthread_stop(thread->task);
|
|
|
|
pr_debug("dmatest: thread %s exited with status %d\n",
|
|
|
|
thread->task->comm, ret);
|
|
|
|
list_del(&thread->node);
|
|
|
|
kfree(thread);
|
|
|
|
}
|
2011-07-29 18:51:57 +08:00
|
|
|
|
|
|
|
/* terminate all transfers on specified channels */
|
2012-11-12 07:03:20 +08:00
|
|
|
dmaengine_terminate_all(dtc->chan);
|
2011-07-29 18:51:57 +08:00
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
kfree(dtc);
|
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:27 +08:00
|
|
|
static int dmatest_add_threads(struct dmatest_info *info,
|
|
|
|
struct dmatest_chan *dtc, enum dma_transaction_type type)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
2013-03-04 17:09:29 +08:00
|
|
|
struct dmatest_params *params = &info->params;
|
2009-03-26 00:13:25 +08:00
|
|
|
struct dmatest_thread *thread;
|
|
|
|
struct dma_chan *chan = dtc->chan;
|
|
|
|
char *op;
|
|
|
|
unsigned int i;
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2009-03-26 00:13:25 +08:00
|
|
|
if (type == DMA_MEMCPY)
|
|
|
|
op = "copy";
|
|
|
|
else if (type == DMA_XOR)
|
|
|
|
op = "xor";
|
2009-08-30 10:09:27 +08:00
|
|
|
else if (type == DMA_PQ)
|
|
|
|
op = "pq";
|
2009-03-26 00:13:25 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2013-03-04 17:09:29 +08:00
|
|
|
for (i = 0; i < params->threads_per_chan; i++) {
|
2008-07-09 02:58:45 +08:00
|
|
|
thread = kzalloc(sizeof(struct dmatest_thread), GFP_KERNEL);
|
|
|
|
if (!thread) {
|
2009-03-26 00:13:25 +08:00
|
|
|
pr_warning("dmatest: No memory for %s-%s%u\n",
|
|
|
|
dma_chan_name(chan), op, i);
|
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-03-04 17:09:27 +08:00
|
|
|
thread->info = info;
|
2008-07-09 02:58:45 +08:00
|
|
|
thread->chan = dtc->chan;
|
2009-03-26 00:13:25 +08:00
|
|
|
thread->type = type;
|
2008-07-09 02:58:45 +08:00
|
|
|
smp_wmb();
|
2009-03-26 00:13:25 +08:00
|
|
|
thread->task = kthread_run(dmatest_func, thread, "%s-%s%u",
|
|
|
|
dma_chan_name(chan), op, i);
|
2008-07-09 02:58:45 +08:00
|
|
|
if (IS_ERR(thread->task)) {
|
2009-03-26 00:13:25 +08:00
|
|
|
pr_warning("dmatest: Failed to run thread %s-%s%u\n",
|
|
|
|
dma_chan_name(chan), op, i);
|
2008-07-09 02:58:45 +08:00
|
|
|
kfree(thread);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* srcbuf and dstbuf are allocated by the thread itself */
|
|
|
|
|
|
|
|
list_add_tail(&thread->node, &dtc->threads);
|
|
|
|
}
|
|
|
|
|
2009-03-26 00:13:25 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:27 +08:00
|
|
|
static int dmatest_add_channel(struct dmatest_info *info,
|
|
|
|
struct dma_chan *chan)
|
2009-03-26 00:13:25 +08:00
|
|
|
{
|
|
|
|
struct dmatest_chan *dtc;
|
|
|
|
struct dma_device *dma_dev = chan->device;
|
|
|
|
unsigned int thread_count = 0;
|
2010-07-17 23:19:48 +08:00
|
|
|
int cnt;
|
2009-03-26 00:13:25 +08:00
|
|
|
|
|
|
|
dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL);
|
|
|
|
if (!dtc) {
|
|
|
|
pr_warning("dmatest: No memory for %s\n", dma_chan_name(chan));
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
dtc->chan = chan;
|
|
|
|
INIT_LIST_HEAD(&dtc->threads);
|
|
|
|
|
|
|
|
if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
|
2013-03-04 17:09:27 +08:00
|
|
|
cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
|
2009-07-07 00:19:44 +08:00
|
|
|
thread_count += cnt > 0 ? cnt : 0;
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
|
|
|
if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
|
2013-03-04 17:09:27 +08:00
|
|
|
cnt = dmatest_add_threads(info, dtc, DMA_XOR);
|
2009-07-07 00:19:44 +08:00
|
|
|
thread_count += cnt > 0 ? cnt : 0;
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
2009-08-30 10:09:27 +08:00
|
|
|
if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
|
2013-03-04 17:09:27 +08:00
|
|
|
cnt = dmatest_add_threads(info, dtc, DMA_PQ);
|
2011-08-26 07:13:55 +08:00
|
|
|
thread_count += cnt > 0 ? cnt : 0;
|
2009-08-30 10:09:27 +08:00
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
|
|
|
|
pr_info("dmatest: Started %u threads using %s\n",
|
|
|
|
thread_count, dma_chan_name(chan));
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2013-03-04 17:09:28 +08:00
|
|
|
list_add_tail(&dtc->node, &info->channels);
|
|
|
|
info->nr_channels++;
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2009-01-07 02:38:15 +08:00
|
|
|
return 0;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
2009-01-07 02:38:19 +08:00
|
|
|
static bool filter(struct dma_chan *chan, void *param)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
2013-03-04 17:09:29 +08:00
|
|
|
struct dmatest_params *params = param;
|
2013-03-04 17:09:27 +08:00
|
|
|
|
2013-03-04 17:09:29 +08:00
|
|
|
if (!dmatest_match_channel(params, chan) ||
|
|
|
|
!dmatest_match_device(params, chan->device))
|
2009-01-07 02:38:19 +08:00
|
|
|
return false;
|
2009-01-07 02:38:15 +08:00
|
|
|
else
|
2009-01-07 02:38:19 +08:00
|
|
|
return true;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:30 +08:00
|
|
|
static int __run_threaded_test(struct dmatest_info *info)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
2009-01-07 02:38:15 +08:00
|
|
|
dma_cap_mask_t mask;
|
|
|
|
struct dma_chan *chan;
|
2013-03-04 17:09:29 +08:00
|
|
|
struct dmatest_params *params = &info->params;
|
2009-01-07 02:38:15 +08:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
dma_cap_zero(mask);
|
|
|
|
dma_cap_set(DMA_MEMCPY, mask);
|
|
|
|
for (;;) {
|
2013-03-04 17:09:29 +08:00
|
|
|
chan = dma_request_channel(mask, filter, params);
|
2009-01-07 02:38:15 +08:00
|
|
|
if (chan) {
|
2013-03-04 17:09:27 +08:00
|
|
|
err = dmatest_add_channel(info, chan);
|
2009-04-09 06:08:23 +08:00
|
|
|
if (err) {
|
2009-01-07 02:38:15 +08:00
|
|
|
dma_release_channel(chan);
|
|
|
|
break; /* add_channel failed, punt */
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
break; /* no more channels available */
|
2013-03-04 17:09:29 +08:00
|
|
|
if (params->max_channels &&
|
|
|
|
info->nr_channels >= params->max_channels)
|
2009-01-07 02:38:15 +08:00
|
|
|
break; /* we have all we need */
|
|
|
|
}
|
|
|
|
return err;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:30 +08:00
|
|
|
#ifndef MODULE
|
|
|
|
static int run_threaded_test(struct dmatest_info *info)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
ret = __run_threaded_test(info);
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void __stop_threaded_test(struct dmatest_info *info)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
2009-01-07 02:38:15 +08:00
|
|
|
struct dmatest_chan *dtc, *_dtc;
|
2009-03-05 07:06:03 +08:00
|
|
|
struct dma_chan *chan;
|
2009-01-07 02:38:15 +08:00
|
|
|
|
2013-03-04 17:09:28 +08:00
|
|
|
list_for_each_entry_safe(dtc, _dtc, &info->channels, node) {
|
2009-01-07 02:38:15 +08:00
|
|
|
list_del(&dtc->node);
|
2009-03-05 07:06:03 +08:00
|
|
|
chan = dtc->chan;
|
2009-01-07 02:38:15 +08:00
|
|
|
dmatest_cleanup_channel(dtc);
|
2013-03-04 17:09:28 +08:00
|
|
|
pr_debug("dmatest: dropped channel %s\n", dma_chan_name(chan));
|
2009-03-05 07:06:03 +08:00
|
|
|
dma_release_channel(chan);
|
2009-01-07 02:38:15 +08:00
|
|
|
}
|
2013-03-04 17:09:28 +08:00
|
|
|
|
|
|
|
info->nr_channels = 0;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
2013-03-04 17:09:27 +08:00
|
|
|
|
2013-03-04 17:09:30 +08:00
|
|
|
static void stop_threaded_test(struct dmatest_info *info)
|
|
|
|
{
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
__stop_threaded_test(info);
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __restart_threaded_test(struct dmatest_info *info, bool run)
|
|
|
|
{
|
|
|
|
struct dmatest_params *params = &info->params;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Stop any running test first */
|
|
|
|
__stop_threaded_test(info);
|
|
|
|
|
|
|
|
if (run == false)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Copy test parameters */
|
|
|
|
memcpy(params, &info->dbgfs_params, sizeof(*params));
|
|
|
|
|
|
|
|
/* Run test with new parameters */
|
|
|
|
ret = __run_threaded_test(info);
|
|
|
|
if (ret) {
|
|
|
|
__stop_threaded_test(info);
|
|
|
|
pr_err("dmatest: Can't run test\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dtf_write_string(void *to, size_t available, loff_t *ppos,
|
|
|
|
const void __user *from, size_t count)
|
|
|
|
{
|
|
|
|
char tmp[20];
|
|
|
|
ssize_t len;
|
|
|
|
|
|
|
|
len = simple_write_to_buffer(tmp, sizeof(tmp) - 1, ppos, from, count);
|
|
|
|
if (len >= 0) {
|
|
|
|
tmp[len] = '\0';
|
|
|
|
strlcpy(to, strim(tmp), available);
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dtf_read_channel(struct file *file, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = file->private_data;
|
|
|
|
return simple_read_from_buffer(buf, count, ppos,
|
|
|
|
info->dbgfs_params.channel,
|
|
|
|
strlen(info->dbgfs_params.channel));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dtf_write_channel(struct file *file, const char __user *buf,
|
|
|
|
size_t size, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = file->private_data;
|
|
|
|
return dtf_write_string(info->dbgfs_params.channel,
|
|
|
|
sizeof(info->dbgfs_params.channel),
|
|
|
|
ppos, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations dtf_channel_fops = {
|
|
|
|
.read = dtf_read_channel,
|
|
|
|
.write = dtf_write_channel,
|
|
|
|
.open = simple_open,
|
|
|
|
.llseek = default_llseek,
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t dtf_read_device(struct file *file, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = file->private_data;
|
|
|
|
return simple_read_from_buffer(buf, count, ppos,
|
|
|
|
info->dbgfs_params.device,
|
|
|
|
strlen(info->dbgfs_params.device));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dtf_write_device(struct file *file, const char __user *buf,
|
|
|
|
size_t size, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = file->private_data;
|
|
|
|
return dtf_write_string(info->dbgfs_params.device,
|
|
|
|
sizeof(info->dbgfs_params.device),
|
|
|
|
ppos, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations dtf_device_fops = {
|
|
|
|
.read = dtf_read_device,
|
|
|
|
.write = dtf_write_device,
|
|
|
|
.open = simple_open,
|
|
|
|
.llseek = default_llseek,
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t dtf_read_run(struct file *file, char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = file->private_data;
|
|
|
|
char buf[3];
|
|
|
|
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
if (info->nr_channels)
|
|
|
|
buf[0] = 'Y';
|
|
|
|
else
|
|
|
|
buf[0] = 'N';
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
buf[1] = '\n';
|
|
|
|
buf[2] = 0x00;
|
|
|
|
return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dtf_write_run(struct file *file, const char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = file->private_data;
|
|
|
|
char buf[16];
|
|
|
|
bool bv;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (copy_from_user(buf, user_buf, min(count, (sizeof(buf) - 1))))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (strtobool(buf, &bv) == 0) {
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
ret = __restart_threaded_test(info, bv);
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret ? ret : count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations dtf_run_fops = {
|
|
|
|
.read = dtf_read_run,
|
|
|
|
.write = dtf_write_run,
|
|
|
|
.open = simple_open,
|
|
|
|
.llseek = default_llseek,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int dmatest_register_dbgfs(struct dmatest_info *info)
|
|
|
|
{
|
|
|
|
struct dentry *d;
|
|
|
|
struct dmatest_params *params = &info->dbgfs_params;
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
|
|
|
|
d = debugfs_create_dir("dmatest", NULL);
|
|
|
|
if (IS_ERR(d))
|
|
|
|
return PTR_ERR(d);
|
|
|
|
if (!d)
|
|
|
|
goto err_root;
|
|
|
|
|
|
|
|
info->root = d;
|
|
|
|
|
|
|
|
/* Copy initial values */
|
|
|
|
memcpy(params, &info->params, sizeof(*params));
|
|
|
|
|
|
|
|
/* Test parameters */
|
|
|
|
|
|
|
|
d = debugfs_create_u32("test_buf_size", S_IWUSR | S_IRUGO, info->root,
|
|
|
|
(u32 *)¶ms->buf_size);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
d = debugfs_create_file("channel", S_IRUGO | S_IWUSR, info->root,
|
|
|
|
info, &dtf_channel_fops);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
d = debugfs_create_file("device", S_IRUGO | S_IWUSR, info->root,
|
|
|
|
info, &dtf_device_fops);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
d = debugfs_create_u32("threads_per_chan", S_IWUSR | S_IRUGO, info->root,
|
|
|
|
(u32 *)¶ms->threads_per_chan);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
d = debugfs_create_u32("max_channels", S_IWUSR | S_IRUGO, info->root,
|
|
|
|
(u32 *)¶ms->max_channels);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
d = debugfs_create_u32("iterations", S_IWUSR | S_IRUGO, info->root,
|
|
|
|
(u32 *)¶ms->iterations);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
d = debugfs_create_u32("xor_sources", S_IWUSR | S_IRUGO, info->root,
|
|
|
|
(u32 *)¶ms->xor_sources);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
d = debugfs_create_u32("pq_sources", S_IWUSR | S_IRUGO, info->root,
|
|
|
|
(u32 *)¶ms->pq_sources);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
d = debugfs_create_u32("timeout", S_IWUSR | S_IRUGO, info->root,
|
|
|
|
(u32 *)¶ms->timeout);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
/* Run or stop threaded test */
|
|
|
|
d = debugfs_create_file("run", S_IWUSR | S_IRUGO, info->root,
|
|
|
|
info, &dtf_run_fops);
|
|
|
|
if (IS_ERR_OR_NULL(d))
|
|
|
|
goto err_node;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_node:
|
|
|
|
debugfs_remove_recursive(info->root);
|
|
|
|
err_root:
|
|
|
|
pr_err("dmatest: Failed to initialize debugfs\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:27 +08:00
|
|
|
static int __init dmatest_init(void)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = &test_info;
|
2013-03-04 17:09:29 +08:00
|
|
|
struct dmatest_params *params = &info->params;
|
2013-03-04 17:09:30 +08:00
|
|
|
int ret;
|
2013-03-04 17:09:27 +08:00
|
|
|
|
|
|
|
memset(info, 0, sizeof(*info));
|
|
|
|
|
2013-03-04 17:09:30 +08:00
|
|
|
mutex_init(&info->lock);
|
2013-03-04 17:09:28 +08:00
|
|
|
INIT_LIST_HEAD(&info->channels);
|
|
|
|
|
|
|
|
/* Set default parameters */
|
2013-03-04 17:09:29 +08:00
|
|
|
params->buf_size = test_buf_size;
|
|
|
|
strlcpy(params->channel, test_channel, sizeof(params->channel));
|
|
|
|
strlcpy(params->device, test_device, sizeof(params->device));
|
|
|
|
params->threads_per_chan = threads_per_chan;
|
|
|
|
params->max_channels = max_channels;
|
|
|
|
params->iterations = iterations;
|
|
|
|
params->xor_sources = xor_sources;
|
|
|
|
params->pq_sources = pq_sources;
|
|
|
|
params->timeout = timeout;
|
2013-03-04 17:09:27 +08:00
|
|
|
|
2013-03-04 17:09:30 +08:00
|
|
|
ret = dmatest_register_dbgfs(info);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
#ifdef MODULE
|
|
|
|
return 0;
|
|
|
|
#else
|
2013-03-04 17:09:27 +08:00
|
|
|
return run_threaded_test(info);
|
2013-03-04 17:09:30 +08:00
|
|
|
#endif
|
2013-03-04 17:09:27 +08:00
|
|
|
}
|
|
|
|
/* when compiled-in wait for drivers to load first */
|
|
|
|
late_initcall(dmatest_init);
|
|
|
|
|
|
|
|
static void __exit dmatest_exit(void)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = &test_info;
|
|
|
|
|
2013-03-04 17:09:30 +08:00
|
|
|
debugfs_remove_recursive(info->root);
|
2013-03-04 17:09:27 +08:00
|
|
|
stop_threaded_test(info);
|
|
|
|
}
|
2008-07-09 02:58:45 +08:00
|
|
|
module_exit(dmatest_exit);
|
|
|
|
|
2011-05-18 22:49:24 +08:00
|
|
|
MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
|
2008-07-09 02:58:45 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|