2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
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
|
|
|
*/
|
2013-11-07 08:29:58 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
#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>
|
2017-02-05 22:30:50 +08:00
|
|
|
#include <linux/sched/task.h>
|
2008-07-09 02:58:45 +08:00
|
|
|
#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>
|
|
|
|
|
|
|
|
static unsigned int test_buf_size = 16384;
|
2013-07-23 23:36:46 +08:00
|
|
|
module_param(test_buf_size, uint, S_IRUGO | S_IWUSR);
|
2008-07-09 02:58:45 +08:00
|
|
|
MODULE_PARM_DESC(test_buf_size, "Size of the memcpy test buffer");
|
|
|
|
|
2013-12-30 21:58:04 +08:00
|
|
|
static char test_device[32];
|
2013-07-23 23:36:46 +08:00
|
|
|
module_param_string(device, test_device, sizeof(test_device),
|
|
|
|
S_IRUGO | S_IWUSR);
|
2008-07-09 02:58:45 +08:00
|
|
|
MODULE_PARM_DESC(device, "Bus ID of the DMA Engine to test (default: any)");
|
|
|
|
|
|
|
|
static unsigned int threads_per_chan = 1;
|
2013-07-23 23:36:46 +08:00
|
|
|
module_param(threads_per_chan, uint, S_IRUGO | S_IWUSR);
|
2008-07-09 02:58:45 +08:00
|
|
|
MODULE_PARM_DESC(threads_per_chan,
|
|
|
|
"Number of threads to start per channel (default: 1)");
|
|
|
|
|
|
|
|
static unsigned int max_channels;
|
2013-07-23 23:36:46 +08:00
|
|
|
module_param(max_channels, uint, S_IRUGO | S_IWUSR);
|
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;
|
2013-07-23 23:36:46 +08:00
|
|
|
module_param(iterations, uint, S_IRUGO | S_IWUSR);
|
2009-07-04 01:26:51 +08:00
|
|
|
MODULE_PARM_DESC(iterations,
|
|
|
|
"Iterations before stopping test (default: infinite)");
|
|
|
|
|
2016-09-15 01:40:38 +08:00
|
|
|
static unsigned int dmatest;
|
2016-06-09 23:40:14 +08:00
|
|
|
module_param(dmatest, uint, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(dmatest,
|
2017-08-22 01:23:13 +08:00
|
|
|
"dmatest 0-memcpy 1-memset (default: 0)");
|
2016-06-09 23:40:14 +08:00
|
|
|
|
2009-03-26 00:13:25 +08:00
|
|
|
static unsigned int xor_sources = 3;
|
2013-07-23 23:36:46 +08:00
|
|
|
module_param(xor_sources, uint, S_IRUGO | S_IWUSR);
|
2009-03-26 00:13:25 +08:00
|
|
|
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;
|
2013-07-23 23:36:46 +08:00
|
|
|
module_param(pq_sources, uint, S_IRUGO | S_IWUSR);
|
2009-08-30 10:09:27 +08:00
|
|
|
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;
|
2020-04-25 00:11:45 +08:00
|
|
|
module_param(timeout, int, S_IRUGO | S_IWUSR);
|
2011-04-24 11:38:19 +08:00
|
|
|
MODULE_PARM_DESC(timeout, "Transfer Timeout in msec (default: 3000), "
|
2020-04-25 00:11:44 +08:00
|
|
|
"Pass -1 for infinite timeout");
|
2011-03-22 19:57:25 +08:00
|
|
|
|
2013-11-07 08:30:05 +08:00
|
|
|
static bool noverify;
|
|
|
|
module_param(noverify, bool, S_IRUGO | S_IWUSR);
|
2018-02-02 17:51:09 +08:00
|
|
|
MODULE_PARM_DESC(noverify, "Disable data verification (default: verify)");
|
|
|
|
|
|
|
|
static bool norandom;
|
|
|
|
module_param(norandom, bool, 0644);
|
|
|
|
MODULE_PARM_DESC(norandom, "Disable random offset setup (default: random)");
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2019-07-31 15:14:38 +08:00
|
|
|
static bool polled;
|
|
|
|
module_param(polled, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(polled, "Use polling for completion instead of interrupts");
|
|
|
|
|
2013-11-09 04:26:26 +08:00
|
|
|
static bool verbose;
|
|
|
|
module_param(verbose, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(verbose, "Enable \"success\" result messages (default: off)");
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2018-12-10 16:52:37 +08:00
|
|
|
static int alignment = -1;
|
|
|
|
module_param(alignment, int, 0644);
|
|
|
|
MODULE_PARM_DESC(alignment, "Custom data address alignment taken as 2^(alignment) (default: not used (-1))");
|
|
|
|
|
2018-12-10 16:52:39 +08:00
|
|
|
static unsigned int transfer_size;
|
|
|
|
module_param(transfer_size, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(transfer_size, "Optional custom transfer size in bytes (default: not used (0))");
|
|
|
|
|
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
|
2020-04-25 00:11:44 +08:00
|
|
|
* @timeout: transfer timeout in msec, -1 for infinite timeout
|
2013-03-04 17:09:27 +08:00
|
|
|
*/
|
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];
|
2013-12-30 21:58:04 +08:00
|
|
|
char device[32];
|
2013-03-04 17:09:27 +08:00
|
|
|
unsigned int threads_per_chan;
|
|
|
|
unsigned int max_channels;
|
|
|
|
unsigned int iterations;
|
|
|
|
unsigned int xor_sources;
|
|
|
|
unsigned int pq_sources;
|
2020-04-25 00:11:44 +08:00
|
|
|
int timeout;
|
2013-11-07 08:30:05 +08:00
|
|
|
bool noverify;
|
2018-02-02 17:51:09 +08:00
|
|
|
bool norandom;
|
2018-12-10 16:52:37 +08:00
|
|
|
int alignment;
|
2018-12-10 16:52:39 +08:00
|
|
|
unsigned int transfer_size;
|
2019-07-31 15:14:38 +08:00
|
|
|
bool polled;
|
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
|
|
|
*/
|
2013-11-07 08:30:01 +08:00
|
|
|
static struct dmatest_info {
|
2013-03-04 17:09:29 +08:00
|
|
|
/* 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;
|
2013-11-07 08:30:01 +08:00
|
|
|
bool did_init;
|
|
|
|
} test_info = {
|
|
|
|
.channels = LIST_HEAD_INIT(test_info.channels),
|
|
|
|
.lock = __MUTEX_INITIALIZER(test_info.lock),
|
|
|
|
};
|
2013-03-04 17:09:30 +08:00
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
static int dmatest_run_set(const char *val, const struct kernel_param *kp);
|
|
|
|
static int dmatest_run_get(char *val, const struct kernel_param *kp);
|
2015-05-27 09:39:38 +08:00
|
|
|
static const struct kernel_param_ops run_ops = {
|
2013-11-07 08:30:01 +08:00
|
|
|
.set = dmatest_run_set,
|
|
|
|
.get = dmatest_run_get,
|
2013-03-04 17:09:27 +08:00
|
|
|
};
|
2013-11-07 08:30:01 +08:00
|
|
|
static bool dmatest_run;
|
|
|
|
module_param_cb(run, &run_ops, &dmatest_run, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(run, "Run the test (default: false)");
|
2013-03-04 17:09:27 +08:00
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
static int dmatest_chan_set(const char *val, const struct kernel_param *kp);
|
|
|
|
static int dmatest_chan_get(char *val, const struct kernel_param *kp);
|
|
|
|
static const struct kernel_param_ops multi_chan_ops = {
|
|
|
|
.set = dmatest_chan_set,
|
|
|
|
.get = dmatest_chan_get,
|
|
|
|
};
|
|
|
|
|
|
|
|
static char test_channel[20];
|
|
|
|
static struct kparam_string newchan_kps = {
|
|
|
|
.string = test_channel,
|
|
|
|
.maxlen = 20,
|
|
|
|
};
|
|
|
|
module_param_cb(channel, &multi_chan_ops, &newchan_kps, 0644);
|
|
|
|
MODULE_PARM_DESC(channel, "Bus ID of the channel to test (default: any)");
|
|
|
|
|
|
|
|
static int dmatest_test_list_get(char *val, const struct kernel_param *kp);
|
|
|
|
static const struct kernel_param_ops test_list_ops = {
|
|
|
|
.get = dmatest_test_list_get,
|
|
|
|
};
|
|
|
|
module_param_cb(test_list, &test_list_ops, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(test_list, "Print current test list");
|
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
/* Maximum amount of mismatched bytes in buffer to print */
|
|
|
|
#define MAX_ERROR_COUNT 32
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2017-06-30 10:30:58 +08:00
|
|
|
#define PATTERN_MEMSET_IDX 0x01
|
2013-03-04 17:09:30 +08:00
|
|
|
|
2018-12-10 16:52:34 +08:00
|
|
|
/* Fixed point arithmetic ops */
|
|
|
|
#define FIXPT_SHIFT 8
|
|
|
|
#define FIXPNT_MASK 0xFF
|
|
|
|
#define FIXPT_TO_INT(a) ((a) >> FIXPT_SHIFT)
|
|
|
|
#define INT_TO_FIXPT(a) ((a) << FIXPT_SHIFT)
|
|
|
|
#define FIXPT_GET_FRAC(a) ((((a) & FIXPNT_MASK) * 100) >> FIXPT_SHIFT)
|
|
|
|
|
2017-11-27 23:45:01 +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;
|
|
|
|
};
|
|
|
|
|
2019-02-12 23:11:37 +08:00
|
|
|
struct dmatest_data {
|
|
|
|
u8 **raw;
|
|
|
|
u8 **aligned;
|
|
|
|
unsigned int cnt;
|
|
|
|
unsigned int off;
|
|
|
|
};
|
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
struct dmatest_thread {
|
|
|
|
struct list_head node;
|
|
|
|
struct dmatest_info *info;
|
|
|
|
struct task_struct *task;
|
|
|
|
struct dma_chan *chan;
|
2019-02-12 23:11:37 +08:00
|
|
|
struct dmatest_data src;
|
|
|
|
struct dmatest_data dst;
|
2013-11-07 08:30:01 +08:00
|
|
|
enum dma_transaction_type type;
|
2017-11-27 23:45:01 +08:00
|
|
|
wait_queue_head_t done_wait;
|
|
|
|
struct dmatest_done test_done;
|
2013-11-07 08:30:01 +08:00
|
|
|
bool done;
|
2018-12-10 16:52:31 +08:00
|
|
|
bool pending;
|
2013-11-07 08:30:01 +08:00
|
|
|
};
|
2013-03-04 17:09:33 +08:00
|
|
|
|
2013-11-07 08:30:01 +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-11-07 08:30:09 +08:00
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(thread_wait);
|
|
|
|
static bool wait;
|
|
|
|
|
|
|
|
static bool is_threaded_test_run(struct dmatest_info *info)
|
|
|
|
{
|
|
|
|
struct dmatest_chan *dtc;
|
|
|
|
|
|
|
|
list_for_each_entry(dtc, &info->channels, node) {
|
|
|
|
struct dmatest_thread *thread;
|
|
|
|
|
|
|
|
list_for_each_entry(thread, &dtc->threads, node) {
|
|
|
|
if (!thread->done)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
static bool is_threaded_test_pending(struct dmatest_info *info)
|
|
|
|
{
|
|
|
|
struct dmatest_chan *dtc;
|
|
|
|
|
|
|
|
list_for_each_entry(dtc, &info->channels, node) {
|
|
|
|
struct dmatest_thread *thread;
|
|
|
|
|
|
|
|
list_for_each_entry(thread, &dtc->threads, node) {
|
|
|
|
if (thread->pending)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-07 08:30:09 +08:00
|
|
|
static int dmatest_wait_get(char *val, const struct kernel_param *kp)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = &test_info;
|
|
|
|
struct dmatest_params *params = &info->params;
|
|
|
|
|
|
|
|
if (params->iterations)
|
|
|
|
wait_event(thread_wait, !is_threaded_test_run(info));
|
|
|
|
wait = true;
|
|
|
|
return param_get_bool(val, kp);
|
|
|
|
}
|
|
|
|
|
2015-05-27 09:39:38 +08:00
|
|
|
static const struct kernel_param_ops wait_ops = {
|
2013-11-07 08:30:09 +08:00
|
|
|
.get = dmatest_wait_get,
|
|
|
|
.set = param_set_bool,
|
|
|
|
};
|
|
|
|
module_param_cb(wait, &wait_ops, &wait, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(wait, "Wait for tests to complete (default: false)");
|
2013-03-04 17:09:27 +08:00
|
|
|
|
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;
|
|
|
|
|
2013-11-07 08:30:03 +08:00
|
|
|
prandom_bytes(&buf, sizeof(buf));
|
2008-07-09 02:58:45 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2017-06-30 10:30:58 +08:00
|
|
|
static inline u8 gen_inv_idx(u8 index, bool is_memset)
|
|
|
|
{
|
|
|
|
u8 val = is_memset ? PATTERN_MEMSET_IDX : index;
|
|
|
|
|
|
|
|
return ~val & PATTERN_COUNT_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u8 gen_src_value(u8 index, bool is_memset)
|
|
|
|
{
|
|
|
|
return PATTERN_SRC | gen_inv_idx(index, is_memset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u8 gen_dst_value(u8 index, bool is_memset)
|
|
|
|
{
|
|
|
|
return PATTERN_DST | gen_inv_idx(index, is_memset);
|
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:27 +08:00
|
|
|
static void dmatest_init_srcs(u8 **bufs, unsigned int start, unsigned int len,
|
2017-06-30 10:30:58 +08:00
|
|
|
unsigned int buf_size, bool is_memset)
|
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++)
|
2017-06-30 10:30:58 +08:00
|
|
|
buf[i] = gen_src_value(i, is_memset);
|
2009-03-26 00:13:25 +08:00
|
|
|
for ( ; i < start + len; i++)
|
2017-06-30 10:30:58 +08:00
|
|
|
buf[i] = gen_src_value(i, is_memset) | PATTERN_COPY;
|
2013-03-04 17:09:27 +08:00
|
|
|
for ( ; i < buf_size; i++)
|
2017-06-30 10:30:58 +08:00
|
|
|
buf[i] = gen_src_value(i, is_memset);
|
2009-03-26 00:13:25 +08:00
|
|
|
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,
|
2017-06-30 10:30:58 +08:00
|
|
|
unsigned int buf_size, bool is_memset)
|
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++)
|
2017-06-30 10:30:58 +08:00
|
|
|
buf[i] = gen_dst_value(i, is_memset);
|
2009-03-26 00:13:25 +08:00
|
|
|
for ( ; i < start + len; i++)
|
2017-06-30 10:30:58 +08:00
|
|
|
buf[i] = gen_dst_value(i, is_memset) |
|
|
|
|
PATTERN_OVERWRITE;
|
2013-03-04 17:09:27 +08:00
|
|
|
for ( ; i < buf_size; i++)
|
2017-06-30 10:30:58 +08:00
|
|
|
buf[i] = gen_dst_value(i, is_memset);
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 08:29:57 +08:00
|
|
|
static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index,
|
2017-06-30 10:30:58 +08:00
|
|
|
unsigned int counter, bool is_srcbuf, bool is_memset)
|
2013-11-07 08:29:57 +08:00
|
|
|
{
|
|
|
|
u8 diff = actual ^ pattern;
|
2017-06-30 10:30:58 +08:00
|
|
|
u8 expected = pattern | gen_inv_idx(counter, is_memset);
|
2013-11-07 08:29:57 +08:00
|
|
|
const char *thread_name = current->comm;
|
|
|
|
|
|
|
|
if (is_srcbuf)
|
|
|
|
pr_warn("%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_warn("%s: dstbuf[0x%x] not copied! Expected %02x, got %02x\n",
|
|
|
|
thread_name, index, expected, actual);
|
|
|
|
else if (diff & PATTERN_SRC)
|
|
|
|
pr_warn("%s: dstbuf[0x%x] was copied! Expected %02x, got %02x\n",
|
|
|
|
thread_name, index, expected, actual);
|
|
|
|
else
|
|
|
|
pr_warn("%s: dstbuf[0x%x] mismatch! Expected %02x, got %02x\n",
|
|
|
|
thread_name, index, expected, actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int dmatest_verify(u8 **bufs, unsigned int start,
|
|
|
|
unsigned int end, unsigned int counter, u8 pattern,
|
2017-06-30 10:30:58 +08:00
|
|
|
bool is_srcbuf, bool is_memset)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
|
|
|
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];
|
2017-06-30 10:30:58 +08:00
|
|
|
expected = pattern | gen_inv_idx(counter, is_memset);
|
2009-03-26 00:13:25 +08:00
|
|
|
if (actual != expected) {
|
2013-11-07 08:29:57 +08:00
|
|
|
if (error_count < MAX_ERROR_COUNT)
|
|
|
|
dmatest_mismatch(actual, pattern, i,
|
2017-06-30 10:30:58 +08:00
|
|
|
counter, is_srcbuf,
|
|
|
|
is_memset);
|
2009-03-26 00:13:25 +08:00
|
|
|
error_count++;
|
|
|
|
}
|
|
|
|
counter++;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:32 +08:00
|
|
|
if (error_count > MAX_ERROR_COUNT)
|
2013-11-07 08:29:57 +08:00
|
|
|
pr_warn("%s: %u errors suppressed\n",
|
2013-03-04 17:09:32 +08:00
|
|
|
current->comm, error_count - MAX_ERROR_COUNT);
|
2008-07-09 02:58:45 +08:00
|
|
|
|
|
|
|
return error_count;
|
|
|
|
}
|
|
|
|
|
2011-11-24 01:28:16 +08:00
|
|
|
|
|
|
|
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;
|
2017-11-27 23:45:01 +08:00
|
|
|
struct dmatest_thread *thread =
|
2018-01-29 14:40:11 +08:00
|
|
|
container_of(done, struct dmatest_thread, test_done);
|
2017-11-27 23:45:01 +08:00
|
|
|
if (!thread->done) {
|
|
|
|
done->done = true;
|
|
|
|
wake_up_all(done->wait);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If thread->done, it means that this callback occurred
|
|
|
|
* after the parent thread has cleaned up. This can
|
|
|
|
* happen in the case that driver doesn't implement
|
|
|
|
* the terminate_all() functionality and a dma operation
|
|
|
|
* did not occur within the timeout period
|
|
|
|
*/
|
|
|
|
WARN(1, "dmatest: Kernel memory may be corrupted!!\n");
|
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-07 08:29:58 +08:00
|
|
|
static void result(const char *err, unsigned int n, unsigned int src_off,
|
|
|
|
unsigned int dst_off, unsigned int len, unsigned long data)
|
2013-03-04 17:09:34 +08:00
|
|
|
{
|
2014-03-04 17:38:55 +08:00
|
|
|
pr_info("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)\n",
|
2013-11-07 08:29:58 +08:00
|
|
|
current->comm, n, err, src_off, dst_off, len, data);
|
2013-03-04 17:09:34 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 08:29:58 +08:00
|
|
|
static void dbg_result(const char *err, unsigned int n, unsigned int src_off,
|
|
|
|
unsigned int dst_off, unsigned int len,
|
|
|
|
unsigned long data)
|
2013-03-04 17:09:33 +08:00
|
|
|
{
|
2014-03-04 17:38:55 +08:00
|
|
|
pr_debug("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)\n",
|
2014-10-22 21:16:42 +08:00
|
|
|
current->comm, n, err, src_off, dst_off, len, data);
|
2013-03-04 17:09:33 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 21:16:42 +08:00
|
|
|
#define verbose_result(err, n, src_off, dst_off, len, data) ({ \
|
|
|
|
if (verbose) \
|
|
|
|
result(err, n, src_off, dst_off, len, data); \
|
|
|
|
else \
|
|
|
|
dbg_result(err, n, src_off, dst_off, len, data);\
|
2013-11-09 04:26:26 +08:00
|
|
|
})
|
2013-03-04 17:09:33 +08:00
|
|
|
|
2013-11-07 08:30:07 +08:00
|
|
|
static unsigned long long dmatest_persec(s64 runtime, unsigned int val)
|
2013-03-04 17:09:34 +08:00
|
|
|
{
|
2013-11-07 08:30:07 +08:00
|
|
|
unsigned long long per_sec = 1000000;
|
2013-03-04 17:09:34 +08:00
|
|
|
|
2013-11-07 08:30:07 +08:00
|
|
|
if (runtime <= 0)
|
|
|
|
return 0;
|
2013-03-04 17:09:33 +08:00
|
|
|
|
2013-11-07 08:30:07 +08:00
|
|
|
/* drop precision until runtime is 32-bits */
|
|
|
|
while (runtime > UINT_MAX) {
|
|
|
|
runtime >>= 1;
|
|
|
|
per_sec <<= 1;
|
2013-03-04 17:09:33 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 08:30:07 +08:00
|
|
|
per_sec *= val;
|
2018-12-10 16:52:34 +08:00
|
|
|
per_sec = INT_TO_FIXPT(per_sec);
|
2013-11-07 08:30:07 +08:00
|
|
|
do_div(per_sec, runtime);
|
2018-12-10 16:52:34 +08:00
|
|
|
|
2013-11-07 08:30:07 +08:00
|
|
|
return per_sec;
|
2013-03-04 17:09:33 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 08:30:07 +08:00
|
|
|
static unsigned long long dmatest_KBs(s64 runtime, unsigned long long len)
|
2013-03-04 17:09:33 +08:00
|
|
|
{
|
2018-12-10 16:52:34 +08:00
|
|
|
return FIXPT_TO_INT(dmatest_persec(runtime, len >> 10));
|
2013-03-04 17:09:33 +08:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:11:39 +08:00
|
|
|
static void __dmatest_free_test_data(struct dmatest_data *d, unsigned int cnt)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < cnt; i++)
|
|
|
|
kfree(d->raw[i]);
|
|
|
|
|
|
|
|
kfree(d->aligned);
|
|
|
|
kfree(d->raw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dmatest_free_test_data(struct dmatest_data *d)
|
|
|
|
{
|
|
|
|
__dmatest_free_test_data(d, d->cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dmatest_alloc_test_data(struct dmatest_data *d,
|
|
|
|
unsigned int buf_size, u8 align)
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
d->raw = kcalloc(d->cnt + 1, sizeof(u8 *), GFP_KERNEL);
|
|
|
|
if (!d->raw)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
d->aligned = kcalloc(d->cnt + 1, sizeof(u8 *), GFP_KERNEL);
|
|
|
|
if (!d->aligned)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
for (i = 0; i < d->cnt; i++) {
|
|
|
|
d->raw[i] = kmalloc(buf_size + align, GFP_KERNEL);
|
|
|
|
if (!d->raw[i])
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* align to alignment restriction */
|
|
|
|
if (align)
|
|
|
|
d->aligned[i] = PTR_ALIGN(d->raw[i], align);
|
|
|
|
else
|
|
|
|
d->aligned[i] = d->raw[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
__dmatest_free_test_data(d, i);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct dmatest_thread *thread = data;
|
2017-11-27 23:45:01 +08:00
|
|
|
struct dmatest_done *done = &thread->test_done;
|
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
|
|
|
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;
|
2019-02-12 23:11:38 +08:00
|
|
|
unsigned int buf_size;
|
2019-02-12 23:11:37 +08:00
|
|
|
struct dmatest_data *src;
|
|
|
|
struct dmatest_data *dst;
|
2009-03-26 00:13:25 +08:00
|
|
|
int i;
|
2016-09-01 22:02:55 +08:00
|
|
|
ktime_t ktime, start, diff;
|
2016-12-25 19:30:41 +08:00
|
|
|
ktime_t filltime = 0;
|
|
|
|
ktime_t comparetime = 0;
|
2013-11-07 08:30:07 +08:00
|
|
|
s64 runtime = 0;
|
|
|
|
unsigned long long total_len = 0;
|
2018-12-10 16:52:34 +08:00
|
|
|
unsigned long long iops = 0;
|
2016-11-30 04:22:20 +08:00
|
|
|
u8 align = 0;
|
2017-06-30 10:30:58 +08:00
|
|
|
bool is_memset = false;
|
2018-04-11 09:02:16 +08:00
|
|
|
dma_addr_t *srcs;
|
|
|
|
dma_addr_t *dma_pq;
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2011-11-24 01:28:16 +08:00
|
|
|
set_freezable();
|
2008-07-09 02:58:45 +08:00
|
|
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
|
|
|
|
smp_rmb();
|
2018-12-10 16:52:31 +08:00
|
|
|
thread->pending = false;
|
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;
|
2019-02-12 23:11:37 +08:00
|
|
|
src = &thread->src;
|
|
|
|
dst = &thread->dst;
|
2016-11-30 04:22:20 +08:00
|
|
|
if (thread->type == DMA_MEMCPY) {
|
2018-12-10 16:52:37 +08:00
|
|
|
align = params->alignment < 0 ? dev->copy_align :
|
|
|
|
params->alignment;
|
2019-02-12 23:11:37 +08:00
|
|
|
src->cnt = dst->cnt = 1;
|
2017-06-30 10:30:58 +08:00
|
|
|
} else if (thread->type == DMA_MEMSET) {
|
2018-12-10 16:52:37 +08:00
|
|
|
align = params->alignment < 0 ? dev->fill_align :
|
|
|
|
params->alignment;
|
2019-02-12 23:11:37 +08:00
|
|
|
src->cnt = dst->cnt = 1;
|
2017-06-30 10:30:58 +08:00
|
|
|
is_memset = true;
|
2016-11-30 04:22:20 +08:00
|
|
|
} else if (thread->type == DMA_XOR) {
|
2012-10-27 23:49:32 +08:00
|
|
|
/* force odd to ensure dst = src */
|
2019-02-12 23:11:37 +08:00
|
|
|
src->cnt = min_odd(params->xor_sources | 1, dev->max_xor);
|
|
|
|
dst->cnt = 1;
|
2018-12-10 16:52:37 +08:00
|
|
|
align = params->alignment < 0 ? dev->xor_align :
|
|
|
|
params->alignment;
|
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 */
|
2019-02-12 23:11:37 +08:00
|
|
|
src->cnt = min_odd(params->pq_sources | 1, dma_maxpq(dev, 0));
|
|
|
|
dst->cnt = 2;
|
2018-12-10 16:52:37 +08:00
|
|
|
align = params->alignment < 0 ? dev->pq_align :
|
|
|
|
params->alignment;
|
2013-03-04 17:09:26 +08:00
|
|
|
|
2016-11-30 04:22:01 +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;
|
|
|
|
|
2019-02-12 23:11:37 +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
|
|
|
|
2018-11-02 00:07:16 +08:00
|
|
|
/* Check if buffer count fits into map count variable (u8) */
|
2019-02-12 23:11:37 +08:00
|
|
|
if ((src->cnt + dst->cnt) >= 255) {
|
2018-11-02 00:07:16 +08:00
|
|
|
pr_err("too many buffers (%d of 255 supported)\n",
|
2019-02-12 23:11:37 +08:00
|
|
|
src->cnt + dst->cnt);
|
2018-12-03 22:49:33 +08:00
|
|
|
goto err_free_coefs;
|
2018-11-02 00:07:16 +08:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:11:38 +08:00
|
|
|
buf_size = params->buf_size;
|
|
|
|
if (1 << align > buf_size) {
|
2018-11-02 00:07:16 +08:00
|
|
|
pr_err("%u-byte buffer too small for %d-byte alignment\n",
|
2019-02-12 23:11:38 +08:00
|
|
|
buf_size, 1 << align);
|
2018-12-03 22:49:33 +08:00
|
|
|
goto err_free_coefs;
|
2018-11-02 00:07:16 +08:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:11:39 +08:00
|
|
|
if (dmatest_alloc_test_data(src, buf_size, align) < 0)
|
2018-12-03 22:49:33 +08:00
|
|
|
goto err_free_coefs;
|
2016-11-30 04:22:20 +08:00
|
|
|
|
2019-02-12 23:11:39 +08:00
|
|
|
if (dmatest_alloc_test_data(dst, buf_size, align) < 0)
|
|
|
|
goto err_src;
|
2009-03-26 00:13:25 +08:00
|
|
|
|
2009-03-26 00:13:25 +08:00
|
|
|
set_user_nice(current, 10);
|
|
|
|
|
2019-02-12 23:11:37 +08:00
|
|
|
srcs = kcalloc(src->cnt, sizeof(dma_addr_t), GFP_KERNEL);
|
2018-04-11 09:02:16 +08:00
|
|
|
if (!srcs)
|
2019-02-12 23:11:39 +08:00
|
|
|
goto err_dst;
|
2018-04-11 09:02:16 +08:00
|
|
|
|
2019-02-12 23:11:37 +08:00
|
|
|
dma_pq = kcalloc(dst->cnt, sizeof(dma_addr_t), GFP_KERNEL);
|
2018-04-11 09:02:16 +08:00
|
|
|
if (!dma_pq)
|
|
|
|
goto err_srcs_array;
|
|
|
|
|
2011-03-03 15:54:53 +08:00
|
|
|
/*
|
2013-10-19 01:35:21 +08:00
|
|
|
* src and dst buffers are freed by ourselves below
|
2011-03-03 15:54:53 +08:00
|
|
|
*/
|
2019-07-31 15:14:38 +08:00
|
|
|
if (params->polled)
|
|
|
|
flags = DMA_CTRL_ACK;
|
|
|
|
else
|
|
|
|
flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2013-11-07 08:30:07 +08:00
|
|
|
ktime = ktime_get();
|
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;
|
2013-11-07 08:30:10 +08:00
|
|
|
struct dmaengine_unmap_data *um;
|
|
|
|
dma_addr_t *dsts;
|
2019-02-12 23:11:37 +08:00
|
|
|
unsigned int len;
|
2009-01-14 00:22:20 +08:00
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
total_tests++;
|
|
|
|
|
2018-12-10 16:52:39 +08:00
|
|
|
if (params->transfer_size) {
|
2019-02-12 23:11:38 +08:00
|
|
|
if (params->transfer_size >= buf_size) {
|
2018-12-10 16:52:39 +08:00
|
|
|
pr_err("%u-byte transfer size must be lower than %u-buffer size\n",
|
2019-02-12 23:11:38 +08:00
|
|
|
params->transfer_size, buf_size);
|
2018-12-10 16:52:39 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
len = params->transfer_size;
|
|
|
|
} else if (params->norandom) {
|
2019-02-12 23:11:38 +08:00
|
|
|
len = buf_size;
|
2018-12-10 16:52:39 +08:00
|
|
|
} else {
|
2019-02-12 23:11:38 +08:00
|
|
|
len = dmatest_random() % buf_size + 1;
|
2018-12-10 16:52:39 +08:00
|
|
|
}
|
2014-10-22 21:16:43 +08:00
|
|
|
|
2018-12-10 16:52:39 +08:00
|
|
|
/* Do not alter transfer size explicitly defined by user */
|
|
|
|
if (!params->transfer_size) {
|
|
|
|
len = (len >> align) << align;
|
|
|
|
if (!len)
|
|
|
|
len = 1 << align;
|
|
|
|
}
|
2014-10-22 21:16:43 +08:00
|
|
|
total_len += len;
|
|
|
|
|
2018-02-02 17:51:09 +08:00
|
|
|
if (params->norandom) {
|
2019-02-12 23:11:37 +08:00
|
|
|
src->off = 0;
|
|
|
|
dst->off = 0;
|
2013-11-07 08:30:05 +08:00
|
|
|
} else {
|
2019-02-12 23:11:38 +08:00
|
|
|
src->off = dmatest_random() % (buf_size - len + 1);
|
|
|
|
dst->off = dmatest_random() % (buf_size - len + 1);
|
2013-11-07 08:30:05 +08:00
|
|
|
|
2019-02-12 23:11:37 +08:00
|
|
|
src->off = (src->off >> align) << align;
|
|
|
|
dst->off = (dst->off >> align) << align;
|
2018-02-02 17:51:09 +08:00
|
|
|
}
|
2013-11-07 08:30:05 +08:00
|
|
|
|
2018-02-02 17:51:09 +08:00
|
|
|
if (!params->noverify) {
|
|
|
|
start = ktime_get();
|
2019-02-12 23:11:37 +08:00
|
|
|
dmatest_init_srcs(src->aligned, src->off, len,
|
2019-02-12 23:11:38 +08:00
|
|
|
buf_size, is_memset);
|
2019-02-12 23:11:37 +08:00
|
|
|
dmatest_init_dsts(dst->aligned, dst->off, len,
|
2019-02-12 23:11:38 +08:00
|
|
|
buf_size, is_memset);
|
2016-09-01 22:02:55 +08:00
|
|
|
|
|
|
|
diff = ktime_sub(ktime_get(), start);
|
|
|
|
filltime = ktime_add(filltime, diff);
|
2013-11-07 08:30:05 +08:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:11:37 +08:00
|
|
|
um = dmaengine_get_unmap_data(dev->dev, src->cnt + dst->cnt,
|
2013-11-07 08:30:10 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!um) {
|
|
|
|
failed_tests++;
|
|
|
|
result("unmap data NULL", total_tests,
|
2019-02-12 23:11:37 +08:00
|
|
|
src->off, dst->off, len, ret);
|
2013-11-07 08:30:10 +08:00
|
|
|
continue;
|
|
|
|
}
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2019-02-12 23:11:38 +08:00
|
|
|
um->len = buf_size;
|
2019-02-12 23:11:37 +08:00
|
|
|
for (i = 0; i < src->cnt; i++) {
|
|
|
|
void *buf = src->aligned[i];
|
2013-11-07 08:30:10 +08:00
|
|
|
struct page *pg = virt_to_page(buf);
|
2017-04-22 09:18:03 +08:00
|
|
|
unsigned long pg_off = offset_in_page(buf);
|
2013-11-07 08:30:10 +08:00
|
|
|
|
|
|
|
um->addr[i] = dma_map_page(dev->dev, pg, pg_off,
|
|
|
|
um->len, DMA_TO_DEVICE);
|
2019-02-12 23:11:37 +08:00
|
|
|
srcs[i] = um->addr[i] + src->off;
|
2013-11-07 08:30:10 +08:00
|
|
|
ret = dma_mapping_error(dev->dev, um->addr[i]);
|
2012-12-18 07:59:53 +08:00
|
|
|
if (ret) {
|
2013-11-07 08:29:58 +08:00
|
|
|
result("src mapping error", total_tests,
|
2019-02-12 23:11:37 +08:00
|
|
|
src->off, dst->off, len, ret);
|
2019-01-31 03:48:44 +08:00
|
|
|
goto error_unmap_continue;
|
2012-12-18 07:59:53 +08:00
|
|
|
}
|
2013-11-07 08:30:10 +08:00
|
|
|
um->to_cnt++;
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
2009-01-14 00:22:20 +08:00
|
|
|
/* map with DMA_BIDIRECTIONAL to force writeback/invalidate */
|
2019-02-12 23:11:37 +08:00
|
|
|
dsts = &um->addr[src->cnt];
|
|
|
|
for (i = 0; i < dst->cnt; i++) {
|
|
|
|
void *buf = dst->aligned[i];
|
2013-11-07 08:30:10 +08:00
|
|
|
struct page *pg = virt_to_page(buf);
|
2017-04-22 09:18:03 +08:00
|
|
|
unsigned long pg_off = offset_in_page(buf);
|
2013-11-07 08:30:10 +08:00
|
|
|
|
|
|
|
dsts[i] = dma_map_page(dev->dev, pg, pg_off, um->len,
|
|
|
|
DMA_BIDIRECTIONAL);
|
|
|
|
ret = dma_mapping_error(dev->dev, dsts[i]);
|
2012-12-18 07:59:53 +08:00
|
|
|
if (ret) {
|
2013-11-07 08:29:58 +08:00
|
|
|
result("dst mapping error", total_tests,
|
2019-02-12 23:11:37 +08:00
|
|
|
src->off, dst->off, len, ret);
|
2019-01-31 03:48:44 +08:00
|
|
|
goto error_unmap_continue;
|
2012-12-18 07:59:53 +08:00
|
|
|
}
|
2013-11-07 08:30:10 +08:00
|
|
|
um->bidi_cnt++;
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (thread->type == DMA_MEMCPY)
|
|
|
|
tx = dev->device_prep_dma_memcpy(chan,
|
2019-02-12 23:11:37 +08:00
|
|
|
dsts[0] + dst->off,
|
2013-11-07 08:30:10 +08:00
|
|
|
srcs[0], len, flags);
|
2017-06-30 10:30:58 +08:00
|
|
|
else if (thread->type == DMA_MEMSET)
|
|
|
|
tx = dev->device_prep_dma_memset(chan,
|
2019-02-12 23:11:37 +08:00
|
|
|
dsts[0] + dst->off,
|
|
|
|
*(src->aligned[0] + src->off),
|
2017-06-30 10:30:58 +08:00
|
|
|
len, flags);
|
2009-03-26 00:13:25 +08:00
|
|
|
else if (thread->type == DMA_XOR)
|
|
|
|
tx = dev->device_prep_dma_xor(chan,
|
2019-02-12 23:11:37 +08:00
|
|
|
dsts[0] + dst->off,
|
|
|
|
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) {
|
2019-02-12 23:11:37 +08:00
|
|
|
for (i = 0; i < dst->cnt; i++)
|
|
|
|
dma_pq[i] = dsts[i] + dst->off;
|
2013-11-07 08:30:10 +08:00
|
|
|
tx = dev->device_prep_dma_pq(chan, dma_pq, srcs,
|
2019-02-12 23:11:37 +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) {
|
2019-02-12 23:11:37 +08:00
|
|
|
result("prep error", total_tests, src->off,
|
|
|
|
dst->off, len, ret);
|
2009-01-14 00:22:20 +08:00
|
|
|
msleep(100);
|
2019-01-31 03:48:44 +08:00
|
|
|
goto error_unmap_continue;
|
2009-01-14 00:22:20 +08:00
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
|
2017-11-27 23:45:01 +08:00
|
|
|
done->done = false;
|
2019-07-31 15:14:38 +08:00
|
|
|
if (!params->polled) {
|
|
|
|
tx->callback = dmatest_callback;
|
|
|
|
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)) {
|
2019-02-12 23:11:37 +08:00
|
|
|
result("submit error", total_tests, src->off,
|
|
|
|
dst->off, len, ret);
|
2008-07-09 02:58:45 +08:00
|
|
|
msleep(100);
|
2019-01-31 03:48:44 +08:00
|
|
|
goto error_unmap_continue;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
2019-07-31 15:14:38 +08:00
|
|
|
if (params->polled) {
|
|
|
|
status = dma_sync_wait(chan, cookie);
|
|
|
|
dmaengine_terminate_sync(chan);
|
|
|
|
if (status == DMA_COMPLETE)
|
|
|
|
done->done = true;
|
|
|
|
} else {
|
|
|
|
dma_async_issue_pending(chan);
|
|
|
|
|
|
|
|
wait_event_freezable_timeout(thread->done_wait,
|
|
|
|
done->done,
|
|
|
|
msecs_to_jiffies(params->timeout));
|
2011-08-18 22:50:51 +08:00
|
|
|
|
2019-07-31 15:14:38 +08:00
|
|
|
status = dma_async_is_tx_complete(chan, cookie, NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2017-11-27 23:45:01 +08:00
|
|
|
if (!done->done) {
|
2019-02-12 23:11:37 +08:00
|
|
|
result("test timed out", total_tests, src->off, dst->off,
|
2013-11-07 08:29:58 +08:00
|
|
|
len, 0);
|
2019-01-31 03:48:44 +08:00
|
|
|
goto error_unmap_continue;
|
2013-10-16 16:07:27 +08:00
|
|
|
} else if (status != DMA_COMPLETE) {
|
2013-11-07 08:29:58 +08:00
|
|
|
result(status == DMA_ERROR ?
|
|
|
|
"completion error status" :
|
2019-02-12 23:11:37 +08:00
|
|
|
"completion busy status", total_tests, src->off,
|
|
|
|
dst->off, len, ret);
|
2019-01-31 03:48:44 +08:00
|
|
|
goto error_unmap_continue;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
|
2019-01-31 03:48:44 +08:00
|
|
|
dmaengine_unmap_put(um);
|
|
|
|
|
2013-11-07 08:30:05 +08:00
|
|
|
if (params->noverify) {
|
2019-02-12 23:11:37 +08:00
|
|
|
verbose_result("test passed", total_tests, src->off,
|
|
|
|
dst->off, len, 0);
|
2013-11-07 08:30:05 +08:00
|
|
|
continue;
|
|
|
|
}
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2016-09-01 22:02:55 +08:00
|
|
|
start = ktime_get();
|
2013-11-07 08:29:58 +08:00
|
|
|
pr_debug("%s: verifying source buffer...\n", current->comm);
|
2019-02-12 23:11:37 +08:00
|
|
|
error_count = dmatest_verify(src->aligned, 0, src->off,
|
2017-06-30 10:30:58 +08:00
|
|
|
0, PATTERN_SRC, true, is_memset);
|
2019-02-12 23:11:37 +08:00
|
|
|
error_count += dmatest_verify(src->aligned, src->off,
|
|
|
|
src->off + len, src->off,
|
2017-06-30 10:30:58 +08:00
|
|
|
PATTERN_SRC | PATTERN_COPY, true, is_memset);
|
2019-02-12 23:11:37 +08:00
|
|
|
error_count += dmatest_verify(src->aligned, src->off + len,
|
2019-02-12 23:11:38 +08:00
|
|
|
buf_size, src->off + len,
|
2017-06-30 10:30:58 +08:00
|
|
|
PATTERN_SRC, true, is_memset);
|
2013-11-07 08:29:57 +08:00
|
|
|
|
2013-11-07 08:29:58 +08:00
|
|
|
pr_debug("%s: verifying dest buffer...\n", current->comm);
|
2019-02-12 23:11:37 +08:00
|
|
|
error_count += dmatest_verify(dst->aligned, 0, dst->off,
|
2017-06-30 10:30:58 +08:00
|
|
|
0, PATTERN_DST, false, is_memset);
|
|
|
|
|
2019-02-12 23:11:37 +08:00
|
|
|
error_count += dmatest_verify(dst->aligned, dst->off,
|
|
|
|
dst->off + len, src->off,
|
2017-06-30 10:30:58 +08:00
|
|
|
PATTERN_SRC | PATTERN_COPY, false, is_memset);
|
|
|
|
|
2019-02-12 23:11:37 +08:00
|
|
|
error_count += dmatest_verify(dst->aligned, dst->off + len,
|
2019-02-12 23:11:38 +08:00
|
|
|
buf_size, dst->off + len,
|
2017-06-30 10:30:58 +08:00
|
|
|
PATTERN_DST, false, is_memset);
|
2008-07-09 02:58:45 +08:00
|
|
|
|
2016-09-01 22:02:55 +08:00
|
|
|
diff = ktime_sub(ktime_get(), start);
|
|
|
|
comparetime = ktime_add(comparetime, diff);
|
|
|
|
|
2008-07-09 02:58:45 +08:00
|
|
|
if (error_count) {
|
2019-02-12 23:11:37 +08:00
|
|
|
result("data error", total_tests, src->off, dst->off,
|
2013-11-07 08:29:58 +08:00
|
|
|
len, error_count);
|
2008-07-09 02:58:45 +08:00
|
|
|
failed_tests++;
|
|
|
|
} else {
|
2019-02-12 23:11:37 +08:00
|
|
|
verbose_result("test passed", total_tests, src->off,
|
|
|
|
dst->off, len, 0);
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
2019-01-31 03:48:44 +08:00
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
error_unmap_continue:
|
|
|
|
dmaengine_unmap_put(um);
|
|
|
|
failed_tests++;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
2016-09-01 22:02:55 +08:00
|
|
|
ktime = ktime_sub(ktime_get(), ktime);
|
|
|
|
ktime = ktime_sub(ktime, comparetime);
|
|
|
|
ktime = ktime_sub(ktime, filltime);
|
|
|
|
runtime = ktime_to_us(ktime);
|
2008-07-09 02:58:45 +08:00
|
|
|
|
|
|
|
ret = 0;
|
2018-04-11 09:02:16 +08:00
|
|
|
kfree(dma_pq);
|
|
|
|
err_srcs_array:
|
|
|
|
kfree(srcs);
|
2019-02-12 23:11:39 +08:00
|
|
|
err_dst:
|
|
|
|
dmatest_free_test_data(dst);
|
|
|
|
err_src:
|
|
|
|
dmatest_free_test_data(src);
|
2018-12-03 22:49:33 +08:00
|
|
|
err_free_coefs:
|
2013-03-04 17:09:26 +08:00
|
|
|
kfree(pq_coefs);
|
|
|
|
err_thread_type:
|
2018-12-10 16:52:34 +08:00
|
|
|
iops = dmatest_persec(runtime, total_tests);
|
|
|
|
pr_info("%s: summary %u tests, %u failures %llu.%02llu iops %llu KB/s (%d)\n",
|
2013-11-07 08:30:07 +08:00
|
|
|
current->comm, total_tests, failed_tests,
|
2018-12-10 16:52:34 +08:00
|
|
|
FIXPT_TO_INT(iops), FIXPT_GET_FRAC(iops),
|
2013-11-07 08:30:07 +08:00
|
|
|
dmatest_KBs(runtime, total_len), ret);
|
2009-07-04 01:26:51 +08:00
|
|
|
|
2011-07-29 18:51:57 +08:00
|
|
|
/* terminate all transfers on specified channels */
|
2017-11-27 23:45:01 +08:00
|
|
|
if (ret || failed_tests)
|
2018-10-29 17:23:36 +08:00
|
|
|
dmaengine_terminate_sync(chan);
|
2012-11-09 23:26:29 +08:00
|
|
|
|
2013-03-04 17:09:31 +08:00
|
|
|
thread->done = true;
|
2013-11-07 08:30:09 +08:00
|
|
|
wake_up(&thread_wait);
|
2009-07-04 01:26:51 +08:00
|
|
|
|
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);
|
2013-11-07 08:30:00 +08:00
|
|
|
pr_debug("thread %s exited with status %d\n",
|
|
|
|
thread->task->comm, ret);
|
2008-07-09 02:58:45 +08:00
|
|
|
list_del(&thread->node);
|
2013-11-07 08:30:09 +08:00
|
|
|
put_task_struct(thread->task);
|
2008-07-09 02:58:45 +08:00
|
|
|
kfree(thread);
|
|
|
|
}
|
2011-07-29 18:51:57 +08:00
|
|
|
|
|
|
|
/* terminate all transfers on specified channels */
|
2018-10-29 17:23:36 +08:00
|
|
|
dmaengine_terminate_sync(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";
|
2017-06-30 10:30:58 +08:00
|
|
|
else if (type == DMA_MEMSET)
|
|
|
|
op = "set";
|
2009-03-26 00:13:25 +08:00
|
|
|
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) {
|
2013-11-07 08:30:00 +08:00
|
|
|
pr_warn("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;
|
2017-11-27 23:45:01 +08:00
|
|
|
thread->test_done.wait = &thread->done_wait;
|
|
|
|
init_waitqueue_head(&thread->done_wait);
|
2008-07-09 02:58:45 +08:00
|
|
|
smp_wmb();
|
2013-11-07 08:30:09 +08:00
|
|
|
thread->task = kthread_create(dmatest_func, thread, "%s-%s%u",
|
2009-03-26 00:13:25 +08:00
|
|
|
dma_chan_name(chan), op, i);
|
2008-07-09 02:58:45 +08:00
|
|
|
if (IS_ERR(thread->task)) {
|
2013-11-07 08:30:09 +08:00
|
|
|
pr_warn("Failed to create thread %s-%s%u\n",
|
2013-11-07 08:30:00 +08:00
|
|
|
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 */
|
2013-11-07 08:30:09 +08:00
|
|
|
get_task_struct(thread->task);
|
2008-07-09 02:58:45 +08:00
|
|
|
list_add_tail(&thread->node, &dtc->threads);
|
2018-12-10 16:52:31 +08:00
|
|
|
thread->pending = true;
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-11-07 08:30:00 +08:00
|
|
|
pr_warn("No memory for %s\n", dma_chan_name(chan));
|
2009-03-26 00:13:25 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
dtc->chan = chan;
|
|
|
|
INIT_LIST_HEAD(&dtc->threads);
|
|
|
|
|
|
|
|
if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
|
2016-06-09 23:40:14 +08:00
|
|
|
if (dmatest == 0) {
|
|
|
|
cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
|
|
|
|
thread_count += cnt > 0 ? cnt : 0;
|
|
|
|
}
|
2009-03-26 00:13:25 +08:00
|
|
|
}
|
2016-06-09 23:40:14 +08:00
|
|
|
|
2017-06-30 10:30:58 +08:00
|
|
|
if (dma_has_cap(DMA_MEMSET, dma_dev->cap_mask)) {
|
2016-06-09 23:40:14 +08:00
|
|
|
if (dmatest == 1) {
|
2017-08-22 01:23:13 +08:00
|
|
|
cnt = dmatest_add_threads(info, dtc, DMA_MEMSET);
|
2016-06-09 23:40:14 +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
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
pr_info("Added %u threads using %s\n",
|
2009-03-26 00:13:25 +08:00
|
|
|
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-11-07 08:30:02 +08:00
|
|
|
static void request_channels(struct dmatest_info *info,
|
|
|
|
enum dma_transaction_type type)
|
2008-07-09 02:58:45 +08:00
|
|
|
{
|
2009-01-07 02:38:15 +08:00
|
|
|
dma_cap_mask_t mask;
|
|
|
|
|
|
|
|
dma_cap_zero(mask);
|
2013-11-07 08:30:02 +08:00
|
|
|
dma_cap_set(type, mask);
|
2009-01-07 02:38:15 +08:00
|
|
|
for (;;) {
|
2013-11-07 08:30:02 +08:00
|
|
|
struct dmatest_params *params = &info->params;
|
|
|
|
struct dma_chan *chan;
|
|
|
|
|
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-11-07 08:30:02 +08:00
|
|
|
if (dmatest_add_channel(info, chan)) {
|
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 */
|
|
|
|
}
|
2008-07-09 02:58:45 +08:00
|
|
|
}
|
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
static void add_threaded_test(struct dmatest_info *info)
|
2013-03-04 17:09:30 +08:00
|
|
|
{
|
2013-11-07 08:30:02 +08:00
|
|
|
struct dmatest_params *params = &info->params;
|
2013-03-04 17:09:30 +08:00
|
|
|
|
2013-11-07 08:30:02 +08:00
|
|
|
/* Copy test parameters */
|
|
|
|
params->buf_size = test_buf_size;
|
|
|
|
strlcpy(params->channel, strim(test_channel), sizeof(params->channel));
|
|
|
|
strlcpy(params->device, strim(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-11-07 08:30:05 +08:00
|
|
|
params->noverify = noverify;
|
2018-02-02 17:51:09 +08:00
|
|
|
params->norandom = norandom;
|
2018-12-10 16:52:37 +08:00
|
|
|
params->alignment = alignment;
|
2018-12-10 16:52:39 +08:00
|
|
|
params->transfer_size = transfer_size;
|
2019-07-31 15:14:38 +08:00
|
|
|
params->polled = polled;
|
2013-11-07 08:30:02 +08:00
|
|
|
|
|
|
|
request_channels(info, DMA_MEMCPY);
|
2017-06-30 10:30:58 +08:00
|
|
|
request_channels(info, DMA_MEMSET);
|
2013-11-07 08:30:02 +08:00
|
|
|
request_channels(info, DMA_XOR);
|
|
|
|
request_channels(info, DMA_PQ);
|
2013-03-04 17:09:30 +08:00
|
|
|
}
|
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
static void run_pending_tests(struct dmatest_info *info)
|
|
|
|
{
|
|
|
|
struct dmatest_chan *dtc;
|
|
|
|
unsigned int thread_count = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(dtc, &info->channels, node) {
|
|
|
|
struct dmatest_thread *thread;
|
|
|
|
|
|
|
|
thread_count = 0;
|
|
|
|
list_for_each_entry(thread, &dtc->threads, node) {
|
|
|
|
wake_up_process(thread->task);
|
|
|
|
thread_count++;
|
|
|
|
}
|
|
|
|
pr_info("Started %u threads using %s\n",
|
|
|
|
thread_count, dma_chan_name(dtc->chan));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
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-11-07 08:30:00 +08:00
|
|
|
pr_debug("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
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
static void start_threaded_tests(struct dmatest_info *info)
|
2013-03-04 17:09:30 +08:00
|
|
|
{
|
2013-11-07 08:30:01 +08:00
|
|
|
/* we might be called early to set run=, defer running until all
|
|
|
|
* parameters have been evaluated
|
|
|
|
*/
|
|
|
|
if (!info->did_init)
|
2013-11-07 08:30:02 +08:00
|
|
|
return;
|
2013-03-04 17:09:30 +08:00
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
run_pending_tests(info);
|
2013-03-04 17:09:30 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
static int dmatest_run_get(char *val, const struct kernel_param *kp)
|
2013-03-04 17:09:30 +08:00
|
|
|
{
|
2013-11-07 08:30:01 +08:00
|
|
|
struct dmatest_info *info = &test_info;
|
2013-03-04 17:09:30 +08:00
|
|
|
|
|
|
|
mutex_lock(&info->lock);
|
2013-11-07 08:30:01 +08:00
|
|
|
if (is_threaded_test_run(info)) {
|
|
|
|
dmatest_run = true;
|
2013-03-04 17:09:31 +08:00
|
|
|
} else {
|
2018-12-10 16:52:31 +08:00
|
|
|
if (!is_threaded_test_pending(info))
|
|
|
|
stop_threaded_test(info);
|
2013-11-07 08:30:01 +08:00
|
|
|
dmatest_run = false;
|
2013-03-04 17:09:31 +08:00
|
|
|
}
|
2013-03-04 17:09:30 +08:00
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
return param_get_bool(val, kp);
|
2013-03-04 17:09:30 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
static int dmatest_run_set(const char *val, const struct kernel_param *kp)
|
2013-03-04 17:09:33 +08:00
|
|
|
{
|
2013-11-07 08:30:01 +08:00
|
|
|
struct dmatest_info *info = &test_info;
|
|
|
|
int ret;
|
2013-03-04 17:09:33 +08:00
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
mutex_lock(&info->lock);
|
|
|
|
ret = param_set_bool(val, kp);
|
|
|
|
if (ret) {
|
2013-03-04 17:09:30 +08:00
|
|
|
mutex_unlock(&info->lock);
|
2013-11-07 08:30:01 +08:00
|
|
|
return ret;
|
2018-12-10 16:52:31 +08:00
|
|
|
} else if (dmatest_run) {
|
|
|
|
if (is_threaded_test_pending(info))
|
|
|
|
start_threaded_tests(info);
|
|
|
|
else
|
|
|
|
pr_info("Could not start test, no channels configured\n");
|
|
|
|
} else {
|
|
|
|
stop_threaded_test(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dmatest_chan_set(const char *val, const struct kernel_param *kp)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = &test_info;
|
|
|
|
struct dmatest_chan *dtc;
|
|
|
|
char chan_reset_val[20];
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
ret = param_set_copystring(val, kp);
|
|
|
|
if (ret) {
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/*Clear any previously run threads */
|
|
|
|
if (!is_threaded_test_run(info) && !is_threaded_test_pending(info))
|
|
|
|
stop_threaded_test(info);
|
|
|
|
/* Reject channels that are already registered */
|
|
|
|
if (is_threaded_test_pending(info)) {
|
|
|
|
list_for_each_entry(dtc, &info->channels, node) {
|
|
|
|
if (strcmp(dma_chan_name(dtc->chan),
|
|
|
|
strim(test_channel)) == 0) {
|
|
|
|
dtc = list_last_entry(&info->channels,
|
|
|
|
struct dmatest_chan,
|
|
|
|
node);
|
|
|
|
strlcpy(chan_reset_val,
|
|
|
|
dma_chan_name(dtc->chan),
|
|
|
|
sizeof(chan_reset_val));
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto add_chan_err;
|
|
|
|
}
|
|
|
|
}
|
2013-03-04 17:09:33 +08:00
|
|
|
}
|
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
add_threaded_test(info);
|
|
|
|
|
|
|
|
/* Check if channel was added successfully */
|
|
|
|
dtc = list_last_entry(&info->channels, struct dmatest_chan, node);
|
|
|
|
|
|
|
|
if (dtc->chan) {
|
|
|
|
/*
|
|
|
|
* if new channel was not successfully added, revert the
|
|
|
|
* "test_channel" string to the name of the last successfully
|
|
|
|
* added channel. exception for when users issues empty string
|
|
|
|
* to channel parameter.
|
|
|
|
*/
|
|
|
|
if ((strcmp(dma_chan_name(dtc->chan), strim(test_channel)) != 0)
|
|
|
|
&& (strcmp("", strim(test_channel)) != 0)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
strlcpy(chan_reset_val, dma_chan_name(dtc->chan),
|
|
|
|
sizeof(chan_reset_val));
|
|
|
|
goto add_chan_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Clear test_channel if no channels were added successfully */
|
|
|
|
strlcpy(chan_reset_val, "", sizeof(chan_reset_val));
|
2013-11-07 08:30:01 +08:00
|
|
|
ret = -EBUSY;
|
2018-12-10 16:52:31 +08:00
|
|
|
goto add_chan_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
|
|
|
|
return ret;
|
2013-03-04 17:09:30 +08:00
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
add_chan_err:
|
|
|
|
param_set_copystring(chan_reset_val, kp);
|
2013-11-07 08:30:01 +08:00
|
|
|
mutex_unlock(&info->lock);
|
2013-03-04 17:09:30 +08:00
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
return ret;
|
2013-03-04 17:09:30 +08:00
|
|
|
}
|
|
|
|
|
2018-12-10 16:52:31 +08:00
|
|
|
static int dmatest_chan_get(char *val, const struct kernel_param *kp)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = &test_info;
|
|
|
|
|
|
|
|
mutex_lock(&info->lock);
|
|
|
|
if (!is_threaded_test_run(info) && !is_threaded_test_pending(info)) {
|
|
|
|
stop_threaded_test(info);
|
|
|
|
strlcpy(test_channel, "", sizeof(test_channel));
|
|
|
|
}
|
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
|
|
|
|
return param_get_string(val, kp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dmatest_test_list_get(char *val, const struct kernel_param *kp)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = &test_info;
|
|
|
|
struct dmatest_chan *dtc;
|
|
|
|
unsigned int thread_count = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(dtc, &info->channels, node) {
|
|
|
|
struct dmatest_thread *thread;
|
|
|
|
|
|
|
|
thread_count = 0;
|
|
|
|
list_for_each_entry(thread, &dtc->threads, node) {
|
|
|
|
thread_count++;
|
|
|
|
}
|
|
|
|
pr_info("%u threads using %s\n",
|
|
|
|
thread_count, dma_chan_name(dtc->chan));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-04 17:09:27 +08:00
|
|
|
static int __init dmatest_init(void)
|
|
|
|
{
|
|
|
|
struct dmatest_info *info = &test_info;
|
2013-11-07 08:30:09 +08:00
|
|
|
struct dmatest_params *params = &info->params;
|
2013-03-04 17:09:27 +08:00
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
if (dmatest_run) {
|
|
|
|
mutex_lock(&info->lock);
|
2018-12-10 16:52:31 +08:00
|
|
|
add_threaded_test(info);
|
|
|
|
run_pending_tests(info);
|
2013-11-07 08:30:01 +08:00
|
|
|
mutex_unlock(&info->lock);
|
|
|
|
}
|
2013-03-04 17:09:28 +08:00
|
|
|
|
2013-11-07 08:30:09 +08:00
|
|
|
if (params->iterations && wait)
|
|
|
|
wait_event(thread_wait, !is_threaded_test_run(info));
|
2013-03-04 17:09:33 +08:00
|
|
|
|
2013-11-07 08:30:01 +08:00
|
|
|
/* module parameters are stable, inittime tests are started,
|
|
|
|
* let userspace take over 'run' control
|
|
|
|
*/
|
|
|
|
info->did_init = true;
|
2013-03-04 17:09:30 +08:00
|
|
|
|
|
|
|
return 0;
|
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-11-07 08:30:01 +08:00
|
|
|
mutex_lock(&info->lock);
|
2013-03-04 17:09:27 +08:00
|
|
|
stop_threaded_test(info);
|
2013-11-07 08:30:01 +08:00
|
|
|
mutex_unlock(&info->lock);
|
2013-03-04 17:09:27 +08:00
|
|
|
}
|
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");
|