blob: aa1712beb0cc355d454948dddb42d615c10b9762 [file] [log] [blame]
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -07001/*
2 * DMA Engine test module
3 *
4 * Copyright (C) 2007 Atmel Corporation
Andy Shevchenko851b7e12013-03-04 11:09:30 +02005 * Copyright (C) 2013 Intel Corporation
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
Dan Williams872f05c2013-11-06 16:29:58 -080011#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070013#include <linux/delay.h>
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000014#include <linux/dma-mapping.h>
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070015#include <linux/dmaengine.h>
Guennadi Liakhovetski981ed702011-08-18 16:50:51 +020016#include <linux/freezer.h>
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070017#include <linux/init.h>
18#include <linux/kthread.h>
Ingo Molnar0881e7b2017-02-05 15:30:50 +010019#include <linux/sched/task.h>
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070020#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/random.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070024#include <linux/wait.h>
25
26static unsigned int test_buf_size = 16384;
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +030027module_param(test_buf_size, uint, S_IRUGO | S_IWUSR);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070028MODULE_PARM_DESC(test_buf_size, "Size of the memcpy test buffer");
29
Kay Sievers06190d82008-11-11 13:12:33 -070030static char test_channel[20];
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +030031module_param_string(channel, test_channel, sizeof(test_channel),
32 S_IRUGO | S_IWUSR);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070033MODULE_PARM_DESC(channel, "Bus ID of the channel to test (default: any)");
34
Guennadi Liakhovetskia85159f2013-12-30 14:58:04 +010035static char test_device[32];
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +030036module_param_string(device, test_device, sizeof(test_device),
37 S_IRUGO | S_IWUSR);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070038MODULE_PARM_DESC(device, "Bus ID of the DMA Engine to test (default: any)");
39
40static unsigned int threads_per_chan = 1;
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +030041module_param(threads_per_chan, uint, S_IRUGO | S_IWUSR);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070042MODULE_PARM_DESC(threads_per_chan,
43 "Number of threads to start per channel (default: 1)");
44
45static unsigned int max_channels;
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +030046module_param(max_channels, uint, S_IRUGO | S_IWUSR);
Dan Williams33df8ca2009-01-06 11:38:15 -070047MODULE_PARM_DESC(max_channels,
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070048 "Maximum number of channels to use (default: all)");
49
Nicolas Ferre0a2ff57d2009-07-03 19:26:51 +020050static unsigned int iterations;
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +030051module_param(iterations, uint, S_IRUGO | S_IWUSR);
Nicolas Ferre0a2ff57d2009-07-03 19:26:51 +020052MODULE_PARM_DESC(iterations,
53 "Iterations before stopping test (default: infinite)");
54
Eugeniy Paltsevd8646722016-09-14 20:40:38 +030055static unsigned int dmatest;
Kedareswara rao Appanaa0d4cb42016-06-09 21:10:14 +053056module_param(dmatest, uint, S_IRUGO | S_IWUSR);
57MODULE_PARM_DESC(dmatest,
Dave Jiangc678fa62017-08-21 10:23:13 -070058 "dmatest 0-memcpy 1-memset (default: 0)");
Kedareswara rao Appanaa0d4cb42016-06-09 21:10:14 +053059
Dan Williamsb54d5cb2009-03-25 09:13:25 -070060static unsigned int xor_sources = 3;
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +030061module_param(xor_sources, uint, S_IRUGO | S_IWUSR);
Dan Williamsb54d5cb2009-03-25 09:13:25 -070062MODULE_PARM_DESC(xor_sources,
63 "Number of xor source buffers (default: 3)");
64
Dan Williams58691d62009-08-29 19:09:27 -070065static unsigned int pq_sources = 3;
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +030066module_param(pq_sources, uint, S_IRUGO | S_IWUSR);
Dan Williams58691d62009-08-29 19:09:27 -070067MODULE_PARM_DESC(pq_sources,
68 "Number of p+q source buffers (default: 3)");
69
Viresh Kumard42efe62011-03-22 17:27:25 +053070static int timeout = 3000;
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +030071module_param(timeout, uint, S_IRUGO | S_IWUSR);
Joe Perches85ee7a12011-04-23 20:38:19 -070072MODULE_PARM_DESC(timeout, "Transfer Timeout in msec (default: 3000), "
73 "Pass -1 for infinite timeout");
Viresh Kumard42efe62011-03-22 17:27:25 +053074
Dan Williamse3b9c342013-11-06 16:30:05 -080075static bool noverify;
76module_param(noverify, bool, S_IRUGO | S_IWUSR);
Yang Shunyong2e67a082018-02-02 17:51:09 +080077MODULE_PARM_DESC(noverify, "Disable data verification (default: verify)");
78
79static bool norandom;
80module_param(norandom, bool, 0644);
81MODULE_PARM_DESC(norandom, "Disable random offset setup (default: random)");
Andy Shevchenko74b5c072013-03-04 11:09:32 +020082
Dan Williams50137a72013-11-08 12:26:26 -080083static bool verbose;
84module_param(verbose, bool, S_IRUGO | S_IWUSR);
85MODULE_PARM_DESC(verbose, "Enable \"success\" result messages (default: off)");
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -070086
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +020087/**
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +020088 * struct dmatest_params - test parameters.
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +020089 * @buf_size: size of the memcpy test buffer
90 * @channel: bus ID of the channel to test
91 * @device: bus ID of the DMA Engine to test
92 * @threads_per_chan: number of threads to start per channel
93 * @max_channels: maximum number of channels to use
94 * @iterations: iterations before stopping test
95 * @xor_sources: number of xor source buffers
96 * @pq_sources: number of p+q source buffers
97 * @timeout: transfer timeout in msec, -1 for infinite timeout
98 */
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +020099struct dmatest_params {
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200100 unsigned int buf_size;
101 char channel[20];
Guennadi Liakhovetskia85159f2013-12-30 14:58:04 +0100102 char device[32];
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200103 unsigned int threads_per_chan;
104 unsigned int max_channels;
105 unsigned int iterations;
106 unsigned int xor_sources;
107 unsigned int pq_sources;
108 int timeout;
Dan Williamse3b9c342013-11-06 16:30:05 -0800109 bool noverify;
Yang Shunyong2e67a082018-02-02 17:51:09 +0800110 bool norandom;
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200111};
112
113/**
114 * struct dmatest_info - test information.
115 * @params: test parameters
Andy Shevchenko851b7e12013-03-04 11:09:30 +0200116 * @lock: access protection to the fields of this structure
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200117 */
Dan Williamsa310d032013-11-06 16:30:01 -0800118static struct dmatest_info {
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200119 /* Test parameters */
120 struct dmatest_params params;
Andy Shevchenko838cc702013-03-04 11:09:28 +0200121
122 /* Internal state */
123 struct list_head channels;
124 unsigned int nr_channels;
Andy Shevchenko851b7e12013-03-04 11:09:30 +0200125 struct mutex lock;
Dan Williamsa310d032013-11-06 16:30:01 -0800126 bool did_init;
127} test_info = {
128 .channels = LIST_HEAD_INIT(test_info.channels),
129 .lock = __MUTEX_INITIALIZER(test_info.lock),
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200130};
131
Dan Williamsa310d032013-11-06 16:30:01 -0800132static int dmatest_run_set(const char *val, const struct kernel_param *kp);
133static int dmatest_run_get(char *val, const struct kernel_param *kp);
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930134static const struct kernel_param_ops run_ops = {
Dan Williamsa310d032013-11-06 16:30:01 -0800135 .set = dmatest_run_set,
136 .get = dmatest_run_get,
137};
138static bool dmatest_run;
139module_param_cb(run, &run_ops, &dmatest_run, S_IRUGO | S_IWUSR);
140MODULE_PARM_DESC(run, "Run the test (default: false)");
141
142/* Maximum amount of mismatched bytes in buffer to print */
143#define MAX_ERROR_COUNT 32
144
145/*
146 * Initialization patterns. All bytes in the source buffer has bit 7
147 * set, all bytes in the destination buffer has bit 7 cleared.
148 *
149 * Bit 6 is set for all bytes which are to be copied by the DMA
150 * engine. Bit 5 is set for all bytes which are to be overwritten by
151 * the DMA engine.
152 *
153 * The remaining bits are the inverse of a counter which increments by
154 * one for each byte address.
155 */
156#define PATTERN_SRC 0x80
157#define PATTERN_DST 0x00
158#define PATTERN_COPY 0x40
159#define PATTERN_OVERWRITE 0x20
160#define PATTERN_COUNT_MASK 0x1f
Sinan Kaya61b5f542017-06-29 22:30:58 -0400161#define PATTERN_MEMSET_IDX 0x01
Dan Williamsa310d032013-11-06 16:30:01 -0800162
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500163/* poor man's completion - we want to use wait_event_freezable() on it */
164struct dmatest_done {
165 bool done;
166 wait_queue_head_t *wait;
167};
168
Dan Williamsa310d032013-11-06 16:30:01 -0800169struct dmatest_thread {
170 struct list_head node;
171 struct dmatest_info *info;
172 struct task_struct *task;
173 struct dma_chan *chan;
174 u8 **srcs;
Dave Jiangd6481602016-11-29 13:22:20 -0700175 u8 **usrcs;
Dan Williamsa310d032013-11-06 16:30:01 -0800176 u8 **dsts;
Dave Jiangd6481602016-11-29 13:22:20 -0700177 u8 **udsts;
Dan Williamsa310d032013-11-06 16:30:01 -0800178 enum dma_transaction_type type;
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500179 wait_queue_head_t done_wait;
180 struct dmatest_done test_done;
Dan Williamsa310d032013-11-06 16:30:01 -0800181 bool done;
182};
183
184struct dmatest_chan {
185 struct list_head node;
186 struct dma_chan *chan;
187 struct list_head threads;
188};
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200189
Dan Williams2d88ce72013-11-06 16:30:09 -0800190static DECLARE_WAIT_QUEUE_HEAD(thread_wait);
191static bool wait;
192
193static bool is_threaded_test_run(struct dmatest_info *info)
194{
195 struct dmatest_chan *dtc;
196
197 list_for_each_entry(dtc, &info->channels, node) {
198 struct dmatest_thread *thread;
199
200 list_for_each_entry(thread, &dtc->threads, node) {
201 if (!thread->done)
202 return true;
203 }
204 }
205
206 return false;
207}
208
209static int dmatest_wait_get(char *val, const struct kernel_param *kp)
210{
211 struct dmatest_info *info = &test_info;
212 struct dmatest_params *params = &info->params;
213
214 if (params->iterations)
215 wait_event(thread_wait, !is_threaded_test_run(info));
216 wait = true;
217 return param_get_bool(val, kp);
218}
219
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930220static const struct kernel_param_ops wait_ops = {
Dan Williams2d88ce72013-11-06 16:30:09 -0800221 .get = dmatest_wait_get,
222 .set = param_set_bool,
223};
224module_param_cb(wait, &wait_ops, &wait, S_IRUGO);
225MODULE_PARM_DESC(wait, "Wait for tests to complete (default: false)");
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700226
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200227static bool dmatest_match_channel(struct dmatest_params *params,
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200228 struct dma_chan *chan)
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700229{
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200230 if (params->channel[0] == '\0')
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700231 return true;
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200232 return strcmp(dma_chan_name(chan), params->channel) == 0;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700233}
234
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200235static bool dmatest_match_device(struct dmatest_params *params,
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200236 struct dma_device *device)
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700237{
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200238 if (params->device[0] == '\0')
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700239 return true;
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200240 return strcmp(dev_name(device->dev), params->device) == 0;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700241}
242
243static unsigned long dmatest_random(void)
244{
245 unsigned long buf;
246
Dan Williamsbe9fa5a2013-11-06 16:30:03 -0800247 prandom_bytes(&buf, sizeof(buf));
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700248 return buf;
249}
250
Sinan Kaya61b5f542017-06-29 22:30:58 -0400251static inline u8 gen_inv_idx(u8 index, bool is_memset)
252{
253 u8 val = is_memset ? PATTERN_MEMSET_IDX : index;
254
255 return ~val & PATTERN_COUNT_MASK;
256}
257
258static inline u8 gen_src_value(u8 index, bool is_memset)
259{
260 return PATTERN_SRC | gen_inv_idx(index, is_memset);
261}
262
263static inline u8 gen_dst_value(u8 index, bool is_memset)
264{
265 return PATTERN_DST | gen_inv_idx(index, is_memset);
266}
267
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200268static void dmatest_init_srcs(u8 **bufs, unsigned int start, unsigned int len,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400269 unsigned int buf_size, bool is_memset)
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700270{
271 unsigned int i;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700272 u8 *buf;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700273
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700274 for (; (buf = *bufs); bufs++) {
275 for (i = 0; i < start; i++)
Sinan Kaya61b5f542017-06-29 22:30:58 -0400276 buf[i] = gen_src_value(i, is_memset);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700277 for ( ; i < start + len; i++)
Sinan Kaya61b5f542017-06-29 22:30:58 -0400278 buf[i] = gen_src_value(i, is_memset) | PATTERN_COPY;
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200279 for ( ; i < buf_size; i++)
Sinan Kaya61b5f542017-06-29 22:30:58 -0400280 buf[i] = gen_src_value(i, is_memset);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700281 buf++;
282 }
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700283}
284
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200285static void dmatest_init_dsts(u8 **bufs, unsigned int start, unsigned int len,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400286 unsigned int buf_size, bool is_memset)
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700287{
288 unsigned int i;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700289 u8 *buf;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700290
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700291 for (; (buf = *bufs); bufs++) {
292 for (i = 0; i < start; i++)
Sinan Kaya61b5f542017-06-29 22:30:58 -0400293 buf[i] = gen_dst_value(i, is_memset);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700294 for ( ; i < start + len; i++)
Sinan Kaya61b5f542017-06-29 22:30:58 -0400295 buf[i] = gen_dst_value(i, is_memset) |
296 PATTERN_OVERWRITE;
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200297 for ( ; i < buf_size; i++)
Sinan Kaya61b5f542017-06-29 22:30:58 -0400298 buf[i] = gen_dst_value(i, is_memset);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700299 }
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700300}
301
Dan Williams7b610172013-11-06 16:29:57 -0800302static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400303 unsigned int counter, bool is_srcbuf, bool is_memset)
Dan Williams7b610172013-11-06 16:29:57 -0800304{
305 u8 diff = actual ^ pattern;
Sinan Kaya61b5f542017-06-29 22:30:58 -0400306 u8 expected = pattern | gen_inv_idx(counter, is_memset);
Dan Williams7b610172013-11-06 16:29:57 -0800307 const char *thread_name = current->comm;
308
309 if (is_srcbuf)
310 pr_warn("%s: srcbuf[0x%x] overwritten! Expected %02x, got %02x\n",
311 thread_name, index, expected, actual);
312 else if ((pattern & PATTERN_COPY)
313 && (diff & (PATTERN_COPY | PATTERN_OVERWRITE)))
314 pr_warn("%s: dstbuf[0x%x] not copied! Expected %02x, got %02x\n",
315 thread_name, index, expected, actual);
316 else if (diff & PATTERN_SRC)
317 pr_warn("%s: dstbuf[0x%x] was copied! Expected %02x, got %02x\n",
318 thread_name, index, expected, actual);
319 else
320 pr_warn("%s: dstbuf[0x%x] mismatch! Expected %02x, got %02x\n",
321 thread_name, index, expected, actual);
322}
323
324static unsigned int dmatest_verify(u8 **bufs, unsigned int start,
325 unsigned int end, unsigned int counter, u8 pattern,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400326 bool is_srcbuf, bool is_memset)
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700327{
328 unsigned int i;
329 unsigned int error_count = 0;
330 u8 actual;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700331 u8 expected;
332 u8 *buf;
333 unsigned int counter_orig = counter;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700334
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700335 for (; (buf = *bufs); bufs++) {
336 counter = counter_orig;
337 for (i = start; i < end; i++) {
338 actual = buf[i];
Sinan Kaya61b5f542017-06-29 22:30:58 -0400339 expected = pattern | gen_inv_idx(counter, is_memset);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700340 if (actual != expected) {
Dan Williams7b610172013-11-06 16:29:57 -0800341 if (error_count < MAX_ERROR_COUNT)
342 dmatest_mismatch(actual, pattern, i,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400343 counter, is_srcbuf,
344 is_memset);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700345 error_count++;
346 }
347 counter++;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700348 }
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700349 }
350
Andy Shevchenko74b5c072013-03-04 11:09:32 +0200351 if (error_count > MAX_ERROR_COUNT)
Dan Williams7b610172013-11-06 16:29:57 -0800352 pr_warn("%s: %u errors suppressed\n",
Andy Shevchenko74b5c072013-03-04 11:09:32 +0200353 current->comm, error_count - MAX_ERROR_COUNT);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700354
355 return error_count;
356}
357
Tejun Heoadfa5432011-11-23 09:28:16 -0800358
359static void dmatest_callback(void *arg)
Dan Williamse44e0aa2009-03-25 09:13:25 -0700360{
Tejun Heoadfa5432011-11-23 09:28:16 -0800361 struct dmatest_done *done = arg;
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500362 struct dmatest_thread *thread =
Yang Shunyong66b3bd22018-01-29 14:40:11 +0800363 container_of(done, struct dmatest_thread, test_done);
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500364 if (!thread->done) {
365 done->done = true;
366 wake_up_all(done->wait);
367 } else {
368 /*
369 * If thread->done, it means that this callback occurred
370 * after the parent thread has cleaned up. This can
371 * happen in the case that driver doesn't implement
372 * the terminate_all() functionality and a dma operation
373 * did not occur within the timeout period
374 */
375 WARN(1, "dmatest: Kernel memory may be corrupted!!\n");
376 }
Dan Williamse44e0aa2009-03-25 09:13:25 -0700377}
378
Akinobu Mita8be9e32b2012-10-28 00:49:32 +0900379static unsigned int min_odd(unsigned int x, unsigned int y)
380{
381 unsigned int val = min(x, y);
382
383 return val % 2 ? val : val - 1;
384}
385
Dan Williams872f05c2013-11-06 16:29:58 -0800386static void result(const char *err, unsigned int n, unsigned int src_off,
387 unsigned int dst_off, unsigned int len, unsigned long data)
Andy Shevchenkod86b2f22013-03-04 11:09:34 +0200388{
Jerome Blin2acec152014-03-04 10:38:55 +0100389 pr_info("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)\n",
Dan Williams872f05c2013-11-06 16:29:58 -0800390 current->comm, n, err, src_off, dst_off, len, data);
Andy Shevchenkod86b2f22013-03-04 11:09:34 +0200391}
392
Dan Williams872f05c2013-11-06 16:29:58 -0800393static void dbg_result(const char *err, unsigned int n, unsigned int src_off,
394 unsigned int dst_off, unsigned int len,
395 unsigned long data)
Andy Shevchenko95019c82013-03-04 11:09:33 +0200396{
Jerome Blin2acec152014-03-04 10:38:55 +0100397 pr_debug("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)\n",
Andy Shevchenkoa835bb82014-10-22 16:16:42 +0300398 current->comm, n, err, src_off, dst_off, len, data);
Andy Shevchenko95019c82013-03-04 11:09:33 +0200399}
400
Andy Shevchenkoa835bb82014-10-22 16:16:42 +0300401#define verbose_result(err, n, src_off, dst_off, len, data) ({ \
402 if (verbose) \
403 result(err, n, src_off, dst_off, len, data); \
404 else \
405 dbg_result(err, n, src_off, dst_off, len, data);\
Dan Williams50137a72013-11-08 12:26:26 -0800406})
407
Dan Williams86727442013-11-06 16:30:07 -0800408static unsigned long long dmatest_persec(s64 runtime, unsigned int val)
Andy Shevchenko95019c82013-03-04 11:09:33 +0200409{
Dan Williams86727442013-11-06 16:30:07 -0800410 unsigned long long per_sec = 1000000;
Andy Shevchenko95019c82013-03-04 11:09:33 +0200411
Dan Williams86727442013-11-06 16:30:07 -0800412 if (runtime <= 0)
413 return 0;
Andy Shevchenko95019c82013-03-04 11:09:33 +0200414
Dan Williams86727442013-11-06 16:30:07 -0800415 /* drop precision until runtime is 32-bits */
416 while (runtime > UINT_MAX) {
417 runtime >>= 1;
418 per_sec <<= 1;
419 }
Andy Shevchenko95019c82013-03-04 11:09:33 +0200420
Dan Williams86727442013-11-06 16:30:07 -0800421 per_sec *= val;
422 do_div(per_sec, runtime);
423 return per_sec;
Andy Shevchenko95019c82013-03-04 11:09:33 +0200424}
425
Dan Williams86727442013-11-06 16:30:07 -0800426static unsigned long long dmatest_KBs(s64 runtime, unsigned long long len)
Andy Shevchenkod86b2f22013-03-04 11:09:34 +0200427{
Dan Williams86727442013-11-06 16:30:07 -0800428 return dmatest_persec(runtime, len >> 10);
Andy Shevchenko95019c82013-03-04 11:09:33 +0200429}
430
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700431/*
432 * This function repeatedly tests DMA transfers of various lengths and
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700433 * offsets for a given operation type until it is told to exit by
434 * kthread_stop(). There may be multiple threads running this function
435 * in parallel for a single channel, and there may be multiple channels
436 * being tested in parallel.
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700437 *
438 * Before each test, the source and destination buffer is initialized
439 * with a known pattern. This pattern is different depending on
440 * whether it's in an area which is supposed to be copied or
441 * overwritten, and different in the source and destination buffers.
442 * So if the DMA engine doesn't copy exactly what we tell it to copy,
443 * we'll notice.
444 */
445static int dmatest_func(void *data)
446{
447 struct dmatest_thread *thread = data;
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500448 struct dmatest_done *done = &thread->test_done;
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200449 struct dmatest_info *info;
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200450 struct dmatest_params *params;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700451 struct dma_chan *chan;
Akinobu Mita8be9e32b2012-10-28 00:49:32 +0900452 struct dma_device *dev;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700453 unsigned int error_count;
454 unsigned int failed_tests = 0;
455 unsigned int total_tests = 0;
456 dma_cookie_t cookie;
457 enum dma_status status;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700458 enum dma_ctrl_flags flags;
Andy Shevchenko945b5af2013-03-04 11:09:26 +0200459 u8 *pq_coefs = NULL;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700460 int ret;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700461 int src_cnt;
462 int dst_cnt;
463 int i;
Sinan Kayae9405ef2016-09-01 10:02:55 -0400464 ktime_t ktime, start, diff;
Thomas Gleixner8b0e1952016-12-25 12:30:41 +0100465 ktime_t filltime = 0;
466 ktime_t comparetime = 0;
Dan Williams86727442013-11-06 16:30:07 -0800467 s64 runtime = 0;
468 unsigned long long total_len = 0;
Dave Jiangd6481602016-11-29 13:22:20 -0700469 u8 align = 0;
Sinan Kaya61b5f542017-06-29 22:30:58 -0400470 bool is_memset = false;
Laura Abbott72ef08b2018-04-10 18:02:16 -0700471 dma_addr_t *srcs;
472 dma_addr_t *dma_pq;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700473
Tejun Heoadfa5432011-11-23 09:28:16 -0800474 set_freezable();
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700475
476 ret = -ENOMEM;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700477
478 smp_rmb();
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200479 info = thread->info;
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200480 params = &info->params;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700481 chan = thread->chan;
Akinobu Mita8be9e32b2012-10-28 00:49:32 +0900482 dev = chan->device;
Dave Jiangd6481602016-11-29 13:22:20 -0700483 if (thread->type == DMA_MEMCPY) {
484 align = dev->copy_align;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700485 src_cnt = dst_cnt = 1;
Sinan Kaya61b5f542017-06-29 22:30:58 -0400486 } else if (thread->type == DMA_MEMSET) {
487 align = dev->fill_align;
488 src_cnt = dst_cnt = 1;
489 is_memset = true;
Dave Jiangd6481602016-11-29 13:22:20 -0700490 } else if (thread->type == DMA_XOR) {
Akinobu Mita8be9e32b2012-10-28 00:49:32 +0900491 /* force odd to ensure dst = src */
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200492 src_cnt = min_odd(params->xor_sources | 1, dev->max_xor);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700493 dst_cnt = 1;
Dave Jiangd6481602016-11-29 13:22:20 -0700494 align = dev->xor_align;
Dan Williams58691d62009-08-29 19:09:27 -0700495 } else if (thread->type == DMA_PQ) {
Akinobu Mita8be9e32b2012-10-28 00:49:32 +0900496 /* force odd to ensure dst = src */
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200497 src_cnt = min_odd(params->pq_sources | 1, dma_maxpq(dev, 0));
Dan Williams58691d62009-08-29 19:09:27 -0700498 dst_cnt = 2;
Dave Jiangd6481602016-11-29 13:22:20 -0700499 align = dev->pq_align;
Andy Shevchenko945b5af2013-03-04 11:09:26 +0200500
Dave Jiang31d18252016-11-29 13:22:01 -0700501 pq_coefs = kmalloc(params->pq_sources + 1, GFP_KERNEL);
Andy Shevchenko945b5af2013-03-04 11:09:26 +0200502 if (!pq_coefs)
503 goto err_thread_type;
504
Anatolij Gustschin94de6482010-02-15 22:35:23 +0100505 for (i = 0; i < src_cnt; i++)
Dan Williams58691d62009-08-29 19:09:27 -0700506 pq_coefs[i] = 1;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700507 } else
Andy Shevchenko945b5af2013-03-04 11:09:26 +0200508 goto err_thread_type;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700509
Dave Jiang31d18252016-11-29 13:22:01 -0700510 thread->srcs = kcalloc(src_cnt + 1, sizeof(u8 *), GFP_KERNEL);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700511 if (!thread->srcs)
512 goto err_srcs;
Dave Jiangd6481602016-11-29 13:22:20 -0700513
514 thread->usrcs = kcalloc(src_cnt + 1, sizeof(u8 *), GFP_KERNEL);
515 if (!thread->usrcs)
516 goto err_usrcs;
517
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700518 for (i = 0; i < src_cnt; i++) {
Dave Jiangd6481602016-11-29 13:22:20 -0700519 thread->usrcs[i] = kmalloc(params->buf_size + align,
520 GFP_KERNEL);
521 if (!thread->usrcs[i])
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700522 goto err_srcbuf;
Dave Jiangd6481602016-11-29 13:22:20 -0700523
524 /* align srcs to alignment restriction */
525 if (align)
526 thread->srcs[i] = PTR_ALIGN(thread->usrcs[i], align);
527 else
528 thread->srcs[i] = thread->usrcs[i];
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700529 }
530 thread->srcs[i] = NULL;
531
Dave Jiang31d18252016-11-29 13:22:01 -0700532 thread->dsts = kcalloc(dst_cnt + 1, sizeof(u8 *), GFP_KERNEL);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700533 if (!thread->dsts)
534 goto err_dsts;
Dave Jiangd6481602016-11-29 13:22:20 -0700535
536 thread->udsts = kcalloc(dst_cnt + 1, sizeof(u8 *), GFP_KERNEL);
537 if (!thread->udsts)
538 goto err_udsts;
539
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700540 for (i = 0; i < dst_cnt; i++) {
Dave Jiangd6481602016-11-29 13:22:20 -0700541 thread->udsts[i] = kmalloc(params->buf_size + align,
542 GFP_KERNEL);
543 if (!thread->udsts[i])
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700544 goto err_dstbuf;
Dave Jiangd6481602016-11-29 13:22:20 -0700545
546 /* align dsts to alignment restriction */
547 if (align)
548 thread->dsts[i] = PTR_ALIGN(thread->udsts[i], align);
549 else
550 thread->dsts[i] = thread->udsts[i];
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700551 }
552 thread->dsts[i] = NULL;
553
Dan Williamse44e0aa2009-03-25 09:13:25 -0700554 set_user_nice(current, 10);
555
Laura Abbott72ef08b2018-04-10 18:02:16 -0700556 srcs = kcalloc(src_cnt, sizeof(dma_addr_t), GFP_KERNEL);
557 if (!srcs)
558 goto err_dstbuf;
559
560 dma_pq = kcalloc(dst_cnt, sizeof(dma_addr_t), GFP_KERNEL);
561 if (!dma_pq)
562 goto err_srcs_array;
563
Ira Snyderb203bd32011-03-03 07:54:53 +0000564 /*
Bartlomiej Zolnierkiewiczd1cab342013-10-18 19:35:21 +0200565 * src and dst buffers are freed by ourselves below
Ira Snyderb203bd32011-03-03 07:54:53 +0000566 */
Bartlomiej Zolnierkiewicz0776ae72013-10-18 19:35:33 +0200567 flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700568
Dan Williams86727442013-11-06 16:30:07 -0800569 ktime = ktime_get();
Nicolas Ferre0a2ff57d2009-07-03 19:26:51 +0200570 while (!kthread_should_stop()
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200571 && !(params->iterations && total_tests >= params->iterations)) {
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700572 struct dma_async_tx_descriptor *tx = NULL;
Dan Williams4076e752013-11-06 16:30:10 -0800573 struct dmaengine_unmap_data *um;
Dan Williams4076e752013-11-06 16:30:10 -0800574 dma_addr_t *dsts;
Andy Shevchenkoede23a52014-10-22 16:16:43 +0300575 unsigned int src_off, dst_off, len;
Atsushi Nemotod86be862009-01-13 09:22:20 -0700576
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700577 total_tests++;
578
Stefan Roesefbfb8e12017-04-27 14:21:41 +0200579 /* Check if buffer count fits into map count variable (u8) */
580 if ((src_cnt + dst_cnt) >= 255) {
581 pr_err("too many buffers (%d of 255 supported)\n",
582 src_cnt + dst_cnt);
583 break;
584 }
585
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200586 if (1 << align > params->buf_size) {
Guennadi Liakhovetskicfe4f272009-12-04 19:44:48 +0100587 pr_err("%u-byte buffer too small for %d-byte alignment\n",
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200588 params->buf_size, 1 << align);
Guennadi Liakhovetskicfe4f272009-12-04 19:44:48 +0100589 break;
590 }
591
Yang Shunyong2e67a082018-02-02 17:51:09 +0800592 if (params->norandom)
Dan Williamse3b9c342013-11-06 16:30:05 -0800593 len = params->buf_size;
Andy Shevchenkoede23a52014-10-22 16:16:43 +0300594 else
595 len = dmatest_random() % params->buf_size + 1;
596
597 len = (len >> align) << align;
598 if (!len)
599 len = 1 << align;
600
601 total_len += len;
602
Yang Shunyong2e67a082018-02-02 17:51:09 +0800603 if (params->norandom) {
Dan Williamse3b9c342013-11-06 16:30:05 -0800604 src_off = 0;
605 dst_off = 0;
606 } else {
Dan Williamse3b9c342013-11-06 16:30:05 -0800607 src_off = dmatest_random() % (params->buf_size - len + 1);
608 dst_off = dmatest_random() % (params->buf_size - len + 1);
609
610 src_off = (src_off >> align) << align;
611 dst_off = (dst_off >> align) << align;
Yang Shunyong2e67a082018-02-02 17:51:09 +0800612 }
Dan Williamse3b9c342013-11-06 16:30:05 -0800613
Yang Shunyong2e67a082018-02-02 17:51:09 +0800614 if (!params->noverify) {
615 start = ktime_get();
Dan Williamse3b9c342013-11-06 16:30:05 -0800616 dmatest_init_srcs(thread->srcs, src_off, len,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400617 params->buf_size, is_memset);
Dan Williamse3b9c342013-11-06 16:30:05 -0800618 dmatest_init_dsts(thread->dsts, dst_off, len,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400619 params->buf_size, is_memset);
Sinan Kayae9405ef2016-09-01 10:02:55 -0400620
621 diff = ktime_sub(ktime_get(), start);
622 filltime = ktime_add(filltime, diff);
Dan Williamse3b9c342013-11-06 16:30:05 -0800623 }
624
Dave Jiang31d18252016-11-29 13:22:01 -0700625 um = dmaengine_get_unmap_data(dev->dev, src_cnt + dst_cnt,
Dan Williams4076e752013-11-06 16:30:10 -0800626 GFP_KERNEL);
627 if (!um) {
628 failed_tests++;
629 result("unmap data NULL", total_tests,
630 src_off, dst_off, len, ret);
631 continue;
632 }
Dan Williams83544ae2009-09-08 17:42:53 -0700633
Dan Williams4076e752013-11-06 16:30:10 -0800634 um->len = params->buf_size;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700635 for (i = 0; i < src_cnt; i++) {
Dan Williams745c00d2013-12-09 11:16:01 -0800636 void *buf = thread->srcs[i];
Dan Williams4076e752013-11-06 16:30:10 -0800637 struct page *pg = virt_to_page(buf);
Geliang Tangf62e5f62017-04-22 09:18:03 +0800638 unsigned long pg_off = offset_in_page(buf);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700639
Dan Williams4076e752013-11-06 16:30:10 -0800640 um->addr[i] = dma_map_page(dev->dev, pg, pg_off,
641 um->len, DMA_TO_DEVICE);
642 srcs[i] = um->addr[i] + src_off;
643 ret = dma_mapping_error(dev->dev, um->addr[i]);
Andy Shevchenkoafde3be2012-12-17 15:59:53 -0800644 if (ret) {
Dan Williams4076e752013-11-06 16:30:10 -0800645 dmaengine_unmap_put(um);
Dan Williams872f05c2013-11-06 16:29:58 -0800646 result("src mapping error", total_tests,
647 src_off, dst_off, len, ret);
Andy Shevchenkoafde3be2012-12-17 15:59:53 -0800648 failed_tests++;
649 continue;
650 }
Dan Williams4076e752013-11-06 16:30:10 -0800651 um->to_cnt++;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700652 }
Atsushi Nemotod86be862009-01-13 09:22:20 -0700653 /* map with DMA_BIDIRECTIONAL to force writeback/invalidate */
Dan Williams4076e752013-11-06 16:30:10 -0800654 dsts = &um->addr[src_cnt];
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700655 for (i = 0; i < dst_cnt; i++) {
Dan Williams745c00d2013-12-09 11:16:01 -0800656 void *buf = thread->dsts[i];
Dan Williams4076e752013-11-06 16:30:10 -0800657 struct page *pg = virt_to_page(buf);
Geliang Tangf62e5f62017-04-22 09:18:03 +0800658 unsigned long pg_off = offset_in_page(buf);
Dan Williams4076e752013-11-06 16:30:10 -0800659
660 dsts[i] = dma_map_page(dev->dev, pg, pg_off, um->len,
661 DMA_BIDIRECTIONAL);
662 ret = dma_mapping_error(dev->dev, dsts[i]);
Andy Shevchenkoafde3be2012-12-17 15:59:53 -0800663 if (ret) {
Dan Williams4076e752013-11-06 16:30:10 -0800664 dmaengine_unmap_put(um);
Dan Williams872f05c2013-11-06 16:29:58 -0800665 result("dst mapping error", total_tests,
666 src_off, dst_off, len, ret);
Andy Shevchenkoafde3be2012-12-17 15:59:53 -0800667 failed_tests++;
668 continue;
669 }
Dan Williams4076e752013-11-06 16:30:10 -0800670 um->bidi_cnt++;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700671 }
Atsushi Nemotod86be862009-01-13 09:22:20 -0700672
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700673 if (thread->type == DMA_MEMCPY)
674 tx = dev->device_prep_dma_memcpy(chan,
Dan Williams4076e752013-11-06 16:30:10 -0800675 dsts[0] + dst_off,
676 srcs[0], len, flags);
Sinan Kaya61b5f542017-06-29 22:30:58 -0400677 else if (thread->type == DMA_MEMSET)
678 tx = dev->device_prep_dma_memset(chan,
679 dsts[0] + dst_off,
680 *(thread->srcs[0] + src_off),
681 len, flags);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700682 else if (thread->type == DMA_XOR)
683 tx = dev->device_prep_dma_xor(chan,
Dan Williams4076e752013-11-06 16:30:10 -0800684 dsts[0] + dst_off,
685 srcs, src_cnt,
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700686 len, flags);
Dan Williams58691d62009-08-29 19:09:27 -0700687 else if (thread->type == DMA_PQ) {
Dan Williams58691d62009-08-29 19:09:27 -0700688 for (i = 0; i < dst_cnt; i++)
Dan Williams4076e752013-11-06 16:30:10 -0800689 dma_pq[i] = dsts[i] + dst_off;
690 tx = dev->device_prep_dma_pq(chan, dma_pq, srcs,
Anatolij Gustschin94de6482010-02-15 22:35:23 +0100691 src_cnt, pq_coefs,
Dan Williams58691d62009-08-29 19:09:27 -0700692 len, flags);
693 }
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700694
Atsushi Nemotod86be862009-01-13 09:22:20 -0700695 if (!tx) {
Dan Williams4076e752013-11-06 16:30:10 -0800696 dmaengine_unmap_put(um);
Dan Williams872f05c2013-11-06 16:29:58 -0800697 result("prep error", total_tests, src_off,
698 dst_off, len, ret);
Atsushi Nemotod86be862009-01-13 09:22:20 -0700699 msleep(100);
700 failed_tests++;
701 continue;
702 }
Dan Williamse44e0aa2009-03-25 09:13:25 -0700703
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500704 done->done = false;
Dan Williamse44e0aa2009-03-25 09:13:25 -0700705 tx->callback = dmatest_callback;
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500706 tx->callback_param = done;
Atsushi Nemotod86be862009-01-13 09:22:20 -0700707 cookie = tx->tx_submit(tx);
708
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700709 if (dma_submit_error(cookie)) {
Dan Williams4076e752013-11-06 16:30:10 -0800710 dmaengine_unmap_put(um);
Dan Williams872f05c2013-11-06 16:29:58 -0800711 result("submit error", total_tests, src_off,
712 dst_off, len, ret);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700713 msleep(100);
714 failed_tests++;
715 continue;
716 }
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700717 dma_async_issue_pending(chan);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700718
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500719 wait_event_freezable_timeout(thread->done_wait, done->done,
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200720 msecs_to_jiffies(params->timeout));
Guennadi Liakhovetski981ed702011-08-18 16:50:51 +0200721
Dan Williamse44e0aa2009-03-25 09:13:25 -0700722 status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700723
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500724 if (!done->done) {
Dan Williams4076e752013-11-06 16:30:10 -0800725 dmaengine_unmap_put(um);
Dan Williams872f05c2013-11-06 16:29:58 -0800726 result("test timed out", total_tests, src_off, dst_off,
727 len, 0);
Dan Williamse44e0aa2009-03-25 09:13:25 -0700728 failed_tests++;
729 continue;
Vinod Koul19e9f992013-10-16 13:37:27 +0530730 } else if (status != DMA_COMPLETE) {
Dan Williams4076e752013-11-06 16:30:10 -0800731 dmaengine_unmap_put(um);
Dan Williams872f05c2013-11-06 16:29:58 -0800732 result(status == DMA_ERROR ?
733 "completion error status" :
734 "completion busy status", total_tests, src_off,
735 dst_off, len, ret);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700736 failed_tests++;
737 continue;
738 }
Dan Williamse44e0aa2009-03-25 09:13:25 -0700739
Dan Williams4076e752013-11-06 16:30:10 -0800740 dmaengine_unmap_put(um);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700741
Dan Williamse3b9c342013-11-06 16:30:05 -0800742 if (params->noverify) {
Dan Williams50137a72013-11-08 12:26:26 -0800743 verbose_result("test passed", total_tests, src_off,
744 dst_off, len, 0);
Dan Williamse3b9c342013-11-06 16:30:05 -0800745 continue;
746 }
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700747
Sinan Kayae9405ef2016-09-01 10:02:55 -0400748 start = ktime_get();
Dan Williams872f05c2013-11-06 16:29:58 -0800749 pr_debug("%s: verifying source buffer...\n", current->comm);
Dan Williamse3b9c342013-11-06 16:30:05 -0800750 error_count = dmatest_verify(thread->srcs, 0, src_off,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400751 0, PATTERN_SRC, true, is_memset);
Dan Williams7b610172013-11-06 16:29:57 -0800752 error_count += dmatest_verify(thread->srcs, src_off,
753 src_off + len, src_off,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400754 PATTERN_SRC | PATTERN_COPY, true, is_memset);
Dan Williams7b610172013-11-06 16:29:57 -0800755 error_count += dmatest_verify(thread->srcs, src_off + len,
756 params->buf_size, src_off + len,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400757 PATTERN_SRC, true, is_memset);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700758
Dan Williams872f05c2013-11-06 16:29:58 -0800759 pr_debug("%s: verifying dest buffer...\n", current->comm);
Dan Williams7b610172013-11-06 16:29:57 -0800760 error_count += dmatest_verify(thread->dsts, 0, dst_off,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400761 0, PATTERN_DST, false, is_memset);
762
Dan Williams7b610172013-11-06 16:29:57 -0800763 error_count += dmatest_verify(thread->dsts, dst_off,
764 dst_off + len, src_off,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400765 PATTERN_SRC | PATTERN_COPY, false, is_memset);
766
Dan Williams7b610172013-11-06 16:29:57 -0800767 error_count += dmatest_verify(thread->dsts, dst_off + len,
768 params->buf_size, dst_off + len,
Sinan Kaya61b5f542017-06-29 22:30:58 -0400769 PATTERN_DST, false, is_memset);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700770
Sinan Kayae9405ef2016-09-01 10:02:55 -0400771 diff = ktime_sub(ktime_get(), start);
772 comparetime = ktime_add(comparetime, diff);
773
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700774 if (error_count) {
Dan Williams872f05c2013-11-06 16:29:58 -0800775 result("data error", total_tests, src_off, dst_off,
776 len, error_count);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700777 failed_tests++;
778 } else {
Dan Williams50137a72013-11-08 12:26:26 -0800779 verbose_result("test passed", total_tests, src_off,
780 dst_off, len, 0);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700781 }
782 }
Sinan Kayae9405ef2016-09-01 10:02:55 -0400783 ktime = ktime_sub(ktime_get(), ktime);
784 ktime = ktime_sub(ktime, comparetime);
785 ktime = ktime_sub(ktime, filltime);
786 runtime = ktime_to_us(ktime);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700787
788 ret = 0;
Laura Abbott72ef08b2018-04-10 18:02:16 -0700789 kfree(dma_pq);
790err_srcs_array:
791 kfree(srcs);
Andy Shevchenko8e1f50d2014-08-22 15:19:44 +0300792err_dstbuf:
Dave Jiangd6481602016-11-29 13:22:20 -0700793 for (i = 0; thread->udsts[i]; i++)
794 kfree(thread->udsts[i]);
795 kfree(thread->udsts);
796err_udsts:
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700797 kfree(thread->dsts);
798err_dsts:
Andy Shevchenko8e1f50d2014-08-22 15:19:44 +0300799err_srcbuf:
Dave Jiangd6481602016-11-29 13:22:20 -0700800 for (i = 0; thread->usrcs[i]; i++)
801 kfree(thread->usrcs[i]);
802 kfree(thread->usrcs);
803err_usrcs:
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700804 kfree(thread->srcs);
805err_srcs:
Andy Shevchenko945b5af2013-03-04 11:09:26 +0200806 kfree(pq_coefs);
807err_thread_type:
Dan Williams86727442013-11-06 16:30:07 -0800808 pr_info("%s: summary %u tests, %u failures %llu iops %llu KB/s (%d)\n",
809 current->comm, total_tests, failed_tests,
810 dmatest_persec(runtime, total_tests),
811 dmatest_KBs(runtime, total_len), ret);
Nicolas Ferre0a2ff57d2009-07-03 19:26:51 +0200812
Viresh Kumar9704efa2011-07-29 16:21:57 +0530813 /* terminate all transfers on specified channels */
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500814 if (ret || failed_tests)
Shiraz Hashim5e034f72012-11-09 15:26:29 +0000815 dmaengine_terminate_all(chan);
816
Andy Shevchenko3e5ccd82013-03-04 11:09:31 +0200817 thread->done = true;
Dan Williams2d88ce72013-11-06 16:30:09 -0800818 wake_up(&thread_wait);
Nicolas Ferre0a2ff57d2009-07-03 19:26:51 +0200819
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700820 return ret;
821}
822
823static void dmatest_cleanup_channel(struct dmatest_chan *dtc)
824{
825 struct dmatest_thread *thread;
826 struct dmatest_thread *_thread;
827 int ret;
828
829 list_for_each_entry_safe(thread, _thread, &dtc->threads, node) {
830 ret = kthread_stop(thread->task);
Dan Williams0adff802013-11-06 16:30:00 -0800831 pr_debug("thread %s exited with status %d\n",
832 thread->task->comm, ret);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700833 list_del(&thread->node);
Dan Williams2d88ce72013-11-06 16:30:09 -0800834 put_task_struct(thread->task);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700835 kfree(thread);
836 }
Viresh Kumar9704efa2011-07-29 16:21:57 +0530837
838 /* terminate all transfers on specified channels */
Jon Mason944ea4d2012-11-11 23:03:20 +0000839 dmaengine_terminate_all(dtc->chan);
Viresh Kumar9704efa2011-07-29 16:21:57 +0530840
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700841 kfree(dtc);
842}
843
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200844static int dmatest_add_threads(struct dmatest_info *info,
845 struct dmatest_chan *dtc, enum dma_transaction_type type)
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700846{
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200847 struct dmatest_params *params = &info->params;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700848 struct dmatest_thread *thread;
849 struct dma_chan *chan = dtc->chan;
850 char *op;
851 unsigned int i;
852
853 if (type == DMA_MEMCPY)
854 op = "copy";
Sinan Kaya61b5f542017-06-29 22:30:58 -0400855 else if (type == DMA_MEMSET)
856 op = "set";
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700857 else if (type == DMA_XOR)
858 op = "xor";
Dan Williams58691d62009-08-29 19:09:27 -0700859 else if (type == DMA_PQ)
860 op = "pq";
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700861 else
862 return -EINVAL;
863
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200864 for (i = 0; i < params->threads_per_chan; i++) {
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700865 thread = kzalloc(sizeof(struct dmatest_thread), GFP_KERNEL);
866 if (!thread) {
Dan Williams0adff802013-11-06 16:30:00 -0800867 pr_warn("No memory for %s-%s%u\n",
868 dma_chan_name(chan), op, i);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700869 break;
870 }
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200871 thread->info = info;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700872 thread->chan = dtc->chan;
873 thread->type = type;
Adam Wallis6f6a23a2017-11-27 10:45:01 -0500874 thread->test_done.wait = &thread->done_wait;
875 init_waitqueue_head(&thread->done_wait);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700876 smp_wmb();
Dan Williams2d88ce72013-11-06 16:30:09 -0800877 thread->task = kthread_create(dmatest_func, thread, "%s-%s%u",
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700878 dma_chan_name(chan), op, i);
879 if (IS_ERR(thread->task)) {
Dan Williams2d88ce72013-11-06 16:30:09 -0800880 pr_warn("Failed to create thread %s-%s%u\n",
Dan Williams0adff802013-11-06 16:30:00 -0800881 dma_chan_name(chan), op, i);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700882 kfree(thread);
883 break;
884 }
885
886 /* srcbuf and dstbuf are allocated by the thread itself */
Dan Williams2d88ce72013-11-06 16:30:09 -0800887 get_task_struct(thread->task);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700888 list_add_tail(&thread->node, &dtc->threads);
Dan Williams2d88ce72013-11-06 16:30:09 -0800889 wake_up_process(thread->task);
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700890 }
891
892 return i;
893}
894
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200895static int dmatest_add_channel(struct dmatest_info *info,
896 struct dma_chan *chan)
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700897{
898 struct dmatest_chan *dtc;
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700899 struct dma_device *dma_dev = chan->device;
900 unsigned int thread_count = 0;
Kulikov Vasiliyb9033e62010-07-17 19:19:48 +0400901 int cnt;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700902
Andrew Morton6fdb8bd2008-09-19 04:16:23 -0700903 dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700904 if (!dtc) {
Dan Williams0adff802013-11-06 16:30:00 -0800905 pr_warn("No memory for %s\n", dma_chan_name(chan));
Dan Williams33df8ca2009-01-06 11:38:15 -0700906 return -ENOMEM;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700907 }
908
909 dtc->chan = chan;
910 INIT_LIST_HEAD(&dtc->threads);
911
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700912 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
Kedareswara rao Appanaa0d4cb42016-06-09 21:10:14 +0530913 if (dmatest == 0) {
914 cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY);
915 thread_count += cnt > 0 ? cnt : 0;
916 }
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700917 }
Kedareswara rao Appanaa0d4cb42016-06-09 21:10:14 +0530918
Sinan Kaya61b5f542017-06-29 22:30:58 -0400919 if (dma_has_cap(DMA_MEMSET, dma_dev->cap_mask)) {
Kedareswara rao Appanaa0d4cb42016-06-09 21:10:14 +0530920 if (dmatest == 1) {
Dave Jiangc678fa62017-08-21 10:23:13 -0700921 cnt = dmatest_add_threads(info, dtc, DMA_MEMSET);
Kedareswara rao Appanaa0d4cb42016-06-09 21:10:14 +0530922 thread_count += cnt > 0 ? cnt : 0;
923 }
924 }
925
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700926 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200927 cnt = dmatest_add_threads(info, dtc, DMA_XOR);
Nicolas Ferref1aef8b2009-07-06 18:19:44 +0200928 thread_count += cnt > 0 ? cnt : 0;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700929 }
Dan Williams58691d62009-08-29 19:09:27 -0700930 if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200931 cnt = dmatest_add_threads(info, dtc, DMA_PQ);
Dr. David Alan Gilbertd07a74a2011-08-25 16:13:55 -0700932 thread_count += cnt > 0 ? cnt : 0;
Dan Williams58691d62009-08-29 19:09:27 -0700933 }
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700934
Dan Williams0adff802013-11-06 16:30:00 -0800935 pr_info("Started %u threads using %s\n",
Dan Williamsb54d5cb2009-03-25 09:13:25 -0700936 thread_count, dma_chan_name(chan));
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700937
Andy Shevchenko838cc702013-03-04 11:09:28 +0200938 list_add_tail(&dtc->node, &info->channels);
939 info->nr_channels++;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700940
Dan Williams33df8ca2009-01-06 11:38:15 -0700941 return 0;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700942}
943
Dan Williams7dd60252009-01-06 11:38:19 -0700944static bool filter(struct dma_chan *chan, void *param)
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700945{
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200946 struct dmatest_params *params = param;
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +0200947
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200948 if (!dmatest_match_channel(params, chan) ||
949 !dmatest_match_device(params, chan->device))
Dan Williams7dd60252009-01-06 11:38:19 -0700950 return false;
Dan Williams33df8ca2009-01-06 11:38:15 -0700951 else
Dan Williams7dd60252009-01-06 11:38:19 -0700952 return true;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700953}
954
Dan Williamsa9e55492013-11-06 16:30:02 -0800955static void request_channels(struct dmatest_info *info,
956 enum dma_transaction_type type)
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700957{
Dan Williams33df8ca2009-01-06 11:38:15 -0700958 dma_cap_mask_t mask;
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700959
Dan Williams33df8ca2009-01-06 11:38:15 -0700960 dma_cap_zero(mask);
Dan Williamsa9e55492013-11-06 16:30:02 -0800961 dma_cap_set(type, mask);
Dan Williams33df8ca2009-01-06 11:38:15 -0700962 for (;;) {
Dan Williamsa9e55492013-11-06 16:30:02 -0800963 struct dmatest_params *params = &info->params;
964 struct dma_chan *chan;
965
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200966 chan = dma_request_channel(mask, filter, params);
Dan Williams33df8ca2009-01-06 11:38:15 -0700967 if (chan) {
Dan Williamsa9e55492013-11-06 16:30:02 -0800968 if (dmatest_add_channel(info, chan)) {
Dan Williams33df8ca2009-01-06 11:38:15 -0700969 dma_release_channel(chan);
970 break; /* add_channel failed, punt */
971 }
972 } else
973 break; /* no more channels available */
Andy Shevchenko15b8a8e2013-03-04 11:09:29 +0200974 if (params->max_channels &&
975 info->nr_channels >= params->max_channels)
Dan Williams33df8ca2009-01-06 11:38:15 -0700976 break; /* we have all we need */
977 }
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700978}
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -0700979
Dan Williamsa9e55492013-11-06 16:30:02 -0800980static void run_threaded_test(struct dmatest_info *info)
Andy Shevchenko851b7e12013-03-04 11:09:30 +0200981{
982 struct dmatest_params *params = &info->params;
Andy Shevchenko851b7e12013-03-04 11:09:30 +0200983
Andy Shevchenko851b7e12013-03-04 11:09:30 +0200984 /* Copy test parameters */
Andy Shevchenkoa6c268d2013-07-23 18:36:46 +0300985 params->buf_size = test_buf_size;
986 strlcpy(params->channel, strim(test_channel), sizeof(params->channel));
987 strlcpy(params->device, strim(test_device), sizeof(params->device));
988 params->threads_per_chan = threads_per_chan;
989 params->max_channels = max_channels;
990 params->iterations = iterations;
991 params->xor_sources = xor_sources;
992 params->pq_sources = pq_sources;
993 params->timeout = timeout;
Dan Williamse3b9c342013-11-06 16:30:05 -0800994 params->noverify = noverify;
Yang Shunyong2e67a082018-02-02 17:51:09 +0800995 params->norandom = norandom;
Dan Williamsa310d032013-11-06 16:30:01 -0800996
Dan Williamsa9e55492013-11-06 16:30:02 -0800997 request_channels(info, DMA_MEMCPY);
Sinan Kaya61b5f542017-06-29 22:30:58 -0400998 request_channels(info, DMA_MEMSET);
Dan Williamsa9e55492013-11-06 16:30:02 -0800999 request_channels(info, DMA_XOR);
1000 request_channels(info, DMA_PQ);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -07001001}
1002
Dan Williamsa310d032013-11-06 16:30:01 -08001003static void stop_threaded_test(struct dmatest_info *info)
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -07001004{
1005 struct dmatest_chan *dtc, *_dtc;
1006 struct dma_chan *chan;
1007
1008 list_for_each_entry_safe(dtc, _dtc, &info->channels, node) {
1009 list_del(&dtc->node);
1010 chan = dtc->chan;
1011 dmatest_cleanup_channel(dtc);
Dan Williams0adff802013-11-06 16:30:00 -08001012 pr_debug("dropped channel %s\n", dma_chan_name(chan));
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +02001013 dma_release_channel(chan);
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -07001014 }
Dan Williams33df8ca2009-01-06 11:38:15 -07001015
Dan Williams7cbd4872009-03-04 16:06:03 -07001016 info->nr_channels = 0;
Dan Williams33df8ca2009-01-06 11:38:15 -07001017}
Andy Shevchenko838cc702013-03-04 11:09:28 +02001018
Dan Williamsa9e55492013-11-06 16:30:02 -08001019static void restart_threaded_test(struct dmatest_info *info, bool run)
Dan Williams7cbd4872009-03-04 16:06:03 -07001020{
Dan Williamsa310d032013-11-06 16:30:01 -08001021 /* we might be called early to set run=, defer running until all
1022 * parameters have been evaluated
1023 */
1024 if (!info->did_init)
Dan Williamsa9e55492013-11-06 16:30:02 -08001025 return;
Andy Shevchenko851b7e12013-03-04 11:09:30 +02001026
Dan Williamsa310d032013-11-06 16:30:01 -08001027 /* Stop any running test first */
1028 stop_threaded_test(info);
Andy Shevchenko851b7e12013-03-04 11:09:30 +02001029
1030 /* Run test with new parameters */
Dan Williamsa9e55492013-11-06 16:30:02 -08001031 run_threaded_test(info);
Andy Shevchenkobcc567e2013-05-23 14:29:53 +03001032}
1033
Dan Williamsa310d032013-11-06 16:30:01 -08001034static int dmatest_run_get(char *val, const struct kernel_param *kp)
Andy Shevchenkobcc567e2013-05-23 14:29:53 +03001035{
Dan Williamsa310d032013-11-06 16:30:01 -08001036 struct dmatest_info *info = &test_info;
Andy Shevchenko851b7e12013-03-04 11:09:30 +02001037
1038 mutex_lock(&info->lock);
Dan Williamsa310d032013-11-06 16:30:01 -08001039 if (is_threaded_test_run(info)) {
1040 dmatest_run = true;
Andy Shevchenko3e5ccd82013-03-04 11:09:31 +02001041 } else {
Dan Williamsa310d032013-11-06 16:30:01 -08001042 stop_threaded_test(info);
1043 dmatest_run = false;
Andy Shevchenko3e5ccd82013-03-04 11:09:31 +02001044 }
Dan Williamsa310d032013-11-06 16:30:01 -08001045 mutex_unlock(&info->lock);
1046
1047 return param_get_bool(val, kp);
1048}
1049
1050static int dmatest_run_set(const char *val, const struct kernel_param *kp)
1051{
1052 struct dmatest_info *info = &test_info;
1053 int ret;
1054
1055 mutex_lock(&info->lock);
1056 ret = param_set_bool(val, kp);
1057 if (ret) {
1058 mutex_unlock(&info->lock);
1059 return ret;
1060 }
1061
1062 if (is_threaded_test_run(info))
1063 ret = -EBUSY;
1064 else if (dmatest_run)
Dan Williamsa9e55492013-11-06 16:30:02 -08001065 restart_threaded_test(info, dmatest_run);
Andy Shevchenko3e5ccd82013-03-04 11:09:31 +02001066
Andy Shevchenko851b7e12013-03-04 11:09:30 +02001067 mutex_unlock(&info->lock);
Andy Shevchenko851b7e12013-03-04 11:09:30 +02001068
Dan Williamsa310d032013-11-06 16:30:01 -08001069 return ret;
Andy Shevchenko851b7e12013-03-04 11:09:30 +02001070}
1071
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +02001072static int __init dmatest_init(void)
1073{
1074 struct dmatest_info *info = &test_info;
Dan Williams2d88ce72013-11-06 16:30:09 -08001075 struct dmatest_params *params = &info->params;
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +02001076
Dan Williamsa310d032013-11-06 16:30:01 -08001077 if (dmatest_run) {
1078 mutex_lock(&info->lock);
Dan Williamsa9e55492013-11-06 16:30:02 -08001079 run_threaded_test(info);
Dan Williamsa310d032013-11-06 16:30:01 -08001080 mutex_unlock(&info->lock);
1081 }
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +02001082
Dan Williams2d88ce72013-11-06 16:30:09 -08001083 if (params->iterations && wait)
1084 wait_event(thread_wait, !is_threaded_test_run(info));
Andy Shevchenko838cc702013-03-04 11:09:28 +02001085
Dan Williamsa310d032013-11-06 16:30:01 -08001086 /* module parameters are stable, inittime tests are started,
1087 * let userspace take over 'run' control
1088 */
1089 info->did_init = true;
Andy Shevchenko95019c82013-03-04 11:09:33 +02001090
Andy Shevchenko851b7e12013-03-04 11:09:30 +02001091 return 0;
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +02001092}
1093/* when compiled-in wait for drivers to load first */
1094late_initcall(dmatest_init);
1095
1096static void __exit dmatest_exit(void)
1097{
1098 struct dmatest_info *info = &test_info;
1099
Dan Williamsa310d032013-11-06 16:30:01 -08001100 mutex_lock(&info->lock);
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +02001101 stop_threaded_test(info);
Dan Williamsa310d032013-11-06 16:30:01 -08001102 mutex_unlock(&info->lock);
Andy Shevchenkoe03e93a2013-03-04 11:09:27 +02001103}
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -07001104module_exit(dmatest_exit);
1105
Jean Delvaree05503e2011-05-18 16:49:24 +02001106MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
Haavard Skinnemoen4a776f02008-07-08 11:58:45 -07001107MODULE_LICENSE("GPL v2");