Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * DMA Engine test module |
| 3 | * |
| 4 | * Copyright (C) 2007 Atmel Corporation |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 5 | * Copyright (C) 2013 Intel Corporation |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 6 | * |
| 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 Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 12 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 13 | #include <linux/delay.h> |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 14 | #include <linux/dma-mapping.h> |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 15 | #include <linux/dmaengine.h> |
Guennadi Liakhovetski | 981ed70 | 2011-08-18 16:50:51 +0200 | [diff] [blame] | 16 | #include <linux/freezer.h> |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 17 | #include <linux/init.h> |
| 18 | #include <linux/kthread.h> |
Ingo Molnar | 0881e7b | 2017-02-05 15:30:50 +0100 | [diff] [blame] | 19 | #include <linux/sched/task.h> |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 20 | #include <linux/module.h> |
| 21 | #include <linux/moduleparam.h> |
| 22 | #include <linux/random.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 24 | #include <linux/wait.h> |
| 25 | |
| 26 | static unsigned int test_buf_size = 16384; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 27 | module_param(test_buf_size, uint, S_IRUGO | S_IWUSR); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 28 | MODULE_PARM_DESC(test_buf_size, "Size of the memcpy test buffer"); |
| 29 | |
Kay Sievers | 06190d8 | 2008-11-11 13:12:33 -0700 | [diff] [blame] | 30 | static char test_channel[20]; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 31 | module_param_string(channel, test_channel, sizeof(test_channel), |
| 32 | S_IRUGO | S_IWUSR); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 33 | MODULE_PARM_DESC(channel, "Bus ID of the channel to test (default: any)"); |
| 34 | |
Guennadi Liakhovetski | a85159f | 2013-12-30 14:58:04 +0100 | [diff] [blame] | 35 | static char test_device[32]; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 36 | module_param_string(device, test_device, sizeof(test_device), |
| 37 | S_IRUGO | S_IWUSR); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 38 | MODULE_PARM_DESC(device, "Bus ID of the DMA Engine to test (default: any)"); |
| 39 | |
| 40 | static unsigned int threads_per_chan = 1; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 41 | module_param(threads_per_chan, uint, S_IRUGO | S_IWUSR); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 42 | MODULE_PARM_DESC(threads_per_chan, |
| 43 | "Number of threads to start per channel (default: 1)"); |
| 44 | |
| 45 | static unsigned int max_channels; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 46 | module_param(max_channels, uint, S_IRUGO | S_IWUSR); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 47 | MODULE_PARM_DESC(max_channels, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 48 | "Maximum number of channels to use (default: all)"); |
| 49 | |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 50 | static unsigned int iterations; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 51 | module_param(iterations, uint, S_IRUGO | S_IWUSR); |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 52 | MODULE_PARM_DESC(iterations, |
| 53 | "Iterations before stopping test (default: infinite)"); |
| 54 | |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 55 | static unsigned int sg_buffers = 1; |
| 56 | module_param(sg_buffers, uint, S_IRUGO | S_IWUSR); |
| 57 | MODULE_PARM_DESC(sg_buffers, |
| 58 | "Number of scatter gather buffers (default: 1)"); |
| 59 | |
Eugeniy Paltsev | d864672 | 2016-09-14 20:40:38 +0300 | [diff] [blame] | 60 | static unsigned int dmatest; |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 61 | module_param(dmatest, uint, S_IRUGO | S_IWUSR); |
| 62 | MODULE_PARM_DESC(dmatest, |
Eugeniy Paltsev | d864672 | 2016-09-14 20:40:38 +0300 | [diff] [blame] | 63 | "dmatest 0-memcpy 1-slave_sg (default: 0)"); |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 64 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 65 | static unsigned int xor_sources = 3; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 66 | module_param(xor_sources, uint, S_IRUGO | S_IWUSR); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 67 | MODULE_PARM_DESC(xor_sources, |
| 68 | "Number of xor source buffers (default: 3)"); |
| 69 | |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 70 | static unsigned int pq_sources = 3; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 71 | module_param(pq_sources, uint, S_IRUGO | S_IWUSR); |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 72 | MODULE_PARM_DESC(pq_sources, |
| 73 | "Number of p+q source buffers (default: 3)"); |
| 74 | |
Viresh Kumar | d42efe6 | 2011-03-22 17:27:25 +0530 | [diff] [blame] | 75 | static int timeout = 3000; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 76 | module_param(timeout, uint, S_IRUGO | S_IWUSR); |
Joe Perches | 85ee7a1 | 2011-04-23 20:38:19 -0700 | [diff] [blame] | 77 | MODULE_PARM_DESC(timeout, "Transfer Timeout in msec (default: 3000), " |
| 78 | "Pass -1 for infinite timeout"); |
Viresh Kumar | d42efe6 | 2011-03-22 17:27:25 +0530 | [diff] [blame] | 79 | |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 80 | static bool noverify; |
| 81 | module_param(noverify, bool, S_IRUGO | S_IWUSR); |
| 82 | MODULE_PARM_DESC(noverify, "Disable random data setup and verification"); |
Andy Shevchenko | 74b5c07 | 2013-03-04 11:09:32 +0200 | [diff] [blame] | 83 | |
Dan Williams | 50137a7 | 2013-11-08 12:26:26 -0800 | [diff] [blame] | 84 | static bool verbose; |
| 85 | module_param(verbose, bool, S_IRUGO | S_IWUSR); |
| 86 | MODULE_PARM_DESC(verbose, "Enable \"success\" result messages (default: off)"); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 87 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 88 | /** |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 89 | * struct dmatest_params - test parameters. |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 90 | * @buf_size: size of the memcpy test buffer |
| 91 | * @channel: bus ID of the channel to test |
| 92 | * @device: bus ID of the DMA Engine to test |
| 93 | * @threads_per_chan: number of threads to start per channel |
| 94 | * @max_channels: maximum number of channels to use |
| 95 | * @iterations: iterations before stopping test |
| 96 | * @xor_sources: number of xor source buffers |
| 97 | * @pq_sources: number of p+q source buffers |
| 98 | * @timeout: transfer timeout in msec, -1 for infinite timeout |
| 99 | */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 100 | struct dmatest_params { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 101 | unsigned int buf_size; |
| 102 | char channel[20]; |
Guennadi Liakhovetski | a85159f | 2013-12-30 14:58:04 +0100 | [diff] [blame] | 103 | char device[32]; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 104 | unsigned int threads_per_chan; |
| 105 | unsigned int max_channels; |
| 106 | unsigned int iterations; |
| 107 | unsigned int xor_sources; |
| 108 | unsigned int pq_sources; |
| 109 | int timeout; |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 110 | bool noverify; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | /** |
| 114 | * struct dmatest_info - test information. |
| 115 | * @params: test parameters |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 116 | * @lock: access protection to the fields of this structure |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 117 | */ |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 118 | static struct dmatest_info { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 119 | /* Test parameters */ |
| 120 | struct dmatest_params params; |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 121 | |
| 122 | /* Internal state */ |
| 123 | struct list_head channels; |
| 124 | unsigned int nr_channels; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 125 | struct mutex lock; |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 126 | bool did_init; |
| 127 | } test_info = { |
| 128 | .channels = LIST_HEAD_INIT(test_info.channels), |
| 129 | .lock = __MUTEX_INITIALIZER(test_info.lock), |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 130 | }; |
| 131 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 132 | static int dmatest_run_set(const char *val, const struct kernel_param *kp); |
| 133 | static int dmatest_run_get(char *val, const struct kernel_param *kp); |
Luis R. Rodriguez | 9c27847 | 2015-05-27 11:09:38 +0930 | [diff] [blame] | 134 | static const struct kernel_param_ops run_ops = { |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 135 | .set = dmatest_run_set, |
| 136 | .get = dmatest_run_get, |
| 137 | }; |
| 138 | static bool dmatest_run; |
| 139 | module_param_cb(run, &run_ops, &dmatest_run, S_IRUGO | S_IWUSR); |
| 140 | MODULE_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 |
| 161 | |
| 162 | struct dmatest_thread { |
| 163 | struct list_head node; |
| 164 | struct dmatest_info *info; |
| 165 | struct task_struct *task; |
| 166 | struct dma_chan *chan; |
| 167 | u8 **srcs; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 168 | u8 **usrcs; |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 169 | u8 **dsts; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 170 | u8 **udsts; |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 171 | enum dma_transaction_type type; |
| 172 | bool done; |
| 173 | }; |
| 174 | |
| 175 | struct dmatest_chan { |
| 176 | struct list_head node; |
| 177 | struct dma_chan *chan; |
| 178 | struct list_head threads; |
| 179 | }; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 180 | |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 181 | static DECLARE_WAIT_QUEUE_HEAD(thread_wait); |
| 182 | static bool wait; |
| 183 | |
| 184 | static bool is_threaded_test_run(struct dmatest_info *info) |
| 185 | { |
| 186 | struct dmatest_chan *dtc; |
| 187 | |
| 188 | list_for_each_entry(dtc, &info->channels, node) { |
| 189 | struct dmatest_thread *thread; |
| 190 | |
| 191 | list_for_each_entry(thread, &dtc->threads, node) { |
| 192 | if (!thread->done) |
| 193 | return true; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | static int dmatest_wait_get(char *val, const struct kernel_param *kp) |
| 201 | { |
| 202 | struct dmatest_info *info = &test_info; |
| 203 | struct dmatest_params *params = &info->params; |
| 204 | |
| 205 | if (params->iterations) |
| 206 | wait_event(thread_wait, !is_threaded_test_run(info)); |
| 207 | wait = true; |
| 208 | return param_get_bool(val, kp); |
| 209 | } |
| 210 | |
Luis R. Rodriguez | 9c27847 | 2015-05-27 11:09:38 +0930 | [diff] [blame] | 211 | static const struct kernel_param_ops wait_ops = { |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 212 | .get = dmatest_wait_get, |
| 213 | .set = param_set_bool, |
| 214 | }; |
| 215 | module_param_cb(wait, &wait_ops, &wait, S_IRUGO); |
| 216 | MODULE_PARM_DESC(wait, "Wait for tests to complete (default: false)"); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 217 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 218 | static bool dmatest_match_channel(struct dmatest_params *params, |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 219 | struct dma_chan *chan) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 220 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 221 | if (params->channel[0] == '\0') |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 222 | return true; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 223 | return strcmp(dma_chan_name(chan), params->channel) == 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 226 | static bool dmatest_match_device(struct dmatest_params *params, |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 227 | struct dma_device *device) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 228 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 229 | if (params->device[0] == '\0') |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 230 | return true; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 231 | return strcmp(dev_name(device->dev), params->device) == 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static unsigned long dmatest_random(void) |
| 235 | { |
| 236 | unsigned long buf; |
| 237 | |
Dan Williams | be9fa5a | 2013-11-06 16:30:03 -0800 | [diff] [blame] | 238 | prandom_bytes(&buf, sizeof(buf)); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 239 | return buf; |
| 240 | } |
| 241 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 242 | static void dmatest_init_srcs(u8 **bufs, unsigned int start, unsigned int len, |
| 243 | unsigned int buf_size) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 244 | { |
| 245 | unsigned int i; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 246 | u8 *buf; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 247 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 248 | for (; (buf = *bufs); bufs++) { |
| 249 | for (i = 0; i < start; i++) |
| 250 | buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK); |
| 251 | for ( ; i < start + len; i++) |
| 252 | buf[i] = PATTERN_SRC | PATTERN_COPY |
Joe Perches | c019894 | 2009-06-28 09:26:21 -0700 | [diff] [blame] | 253 | | (~i & PATTERN_COUNT_MASK); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 254 | for ( ; i < buf_size; i++) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 255 | buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK); |
| 256 | buf++; |
| 257 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 260 | static void dmatest_init_dsts(u8 **bufs, unsigned int start, unsigned int len, |
| 261 | unsigned int buf_size) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 262 | { |
| 263 | unsigned int i; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 264 | u8 *buf; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 265 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 266 | for (; (buf = *bufs); bufs++) { |
| 267 | for (i = 0; i < start; i++) |
| 268 | buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK); |
| 269 | for ( ; i < start + len; i++) |
| 270 | buf[i] = PATTERN_DST | PATTERN_OVERWRITE |
| 271 | | (~i & PATTERN_COUNT_MASK); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 272 | for ( ; i < buf_size; i++) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 273 | buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK); |
| 274 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 277 | static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index, |
| 278 | unsigned int counter, bool is_srcbuf) |
| 279 | { |
| 280 | u8 diff = actual ^ pattern; |
| 281 | u8 expected = pattern | (~counter & PATTERN_COUNT_MASK); |
| 282 | const char *thread_name = current->comm; |
| 283 | |
| 284 | if (is_srcbuf) |
| 285 | pr_warn("%s: srcbuf[0x%x] overwritten! Expected %02x, got %02x\n", |
| 286 | thread_name, index, expected, actual); |
| 287 | else if ((pattern & PATTERN_COPY) |
| 288 | && (diff & (PATTERN_COPY | PATTERN_OVERWRITE))) |
| 289 | pr_warn("%s: dstbuf[0x%x] not copied! Expected %02x, got %02x\n", |
| 290 | thread_name, index, expected, actual); |
| 291 | else if (diff & PATTERN_SRC) |
| 292 | pr_warn("%s: dstbuf[0x%x] was copied! Expected %02x, got %02x\n", |
| 293 | thread_name, index, expected, actual); |
| 294 | else |
| 295 | pr_warn("%s: dstbuf[0x%x] mismatch! Expected %02x, got %02x\n", |
| 296 | thread_name, index, expected, actual); |
| 297 | } |
| 298 | |
| 299 | static unsigned int dmatest_verify(u8 **bufs, unsigned int start, |
| 300 | unsigned int end, unsigned int counter, u8 pattern, |
| 301 | bool is_srcbuf) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 302 | { |
| 303 | unsigned int i; |
| 304 | unsigned int error_count = 0; |
| 305 | u8 actual; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 306 | u8 expected; |
| 307 | u8 *buf; |
| 308 | unsigned int counter_orig = counter; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 309 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 310 | for (; (buf = *bufs); bufs++) { |
| 311 | counter = counter_orig; |
| 312 | for (i = start; i < end; i++) { |
| 313 | actual = buf[i]; |
| 314 | expected = pattern | (~counter & PATTERN_COUNT_MASK); |
| 315 | if (actual != expected) { |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 316 | if (error_count < MAX_ERROR_COUNT) |
| 317 | dmatest_mismatch(actual, pattern, i, |
| 318 | counter, is_srcbuf); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 319 | error_count++; |
| 320 | } |
| 321 | counter++; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 322 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Andy Shevchenko | 74b5c07 | 2013-03-04 11:09:32 +0200 | [diff] [blame] | 325 | if (error_count > MAX_ERROR_COUNT) |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 326 | pr_warn("%s: %u errors suppressed\n", |
Andy Shevchenko | 74b5c07 | 2013-03-04 11:09:32 +0200 | [diff] [blame] | 327 | current->comm, error_count - MAX_ERROR_COUNT); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 328 | |
| 329 | return error_count; |
| 330 | } |
| 331 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 332 | /* poor man's completion - we want to use wait_event_freezable() on it */ |
| 333 | struct dmatest_done { |
| 334 | bool done; |
| 335 | wait_queue_head_t *wait; |
| 336 | }; |
| 337 | |
| 338 | static void dmatest_callback(void *arg) |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 339 | { |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 340 | struct dmatest_done *done = arg; |
| 341 | |
| 342 | done->done = true; |
| 343 | wake_up_all(done->wait); |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 346 | static unsigned int min_odd(unsigned int x, unsigned int y) |
| 347 | { |
| 348 | unsigned int val = min(x, y); |
| 349 | |
| 350 | return val % 2 ? val : val - 1; |
| 351 | } |
| 352 | |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 353 | static void result(const char *err, unsigned int n, unsigned int src_off, |
| 354 | unsigned int dst_off, unsigned int len, unsigned long data) |
Andy Shevchenko | d86b2f2 | 2013-03-04 11:09:34 +0200 | [diff] [blame] | 355 | { |
Jerome Blin | 2acec15 | 2014-03-04 10:38:55 +0100 | [diff] [blame] | 356 | pr_info("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)\n", |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 357 | current->comm, n, err, src_off, dst_off, len, data); |
Andy Shevchenko | d86b2f2 | 2013-03-04 11:09:34 +0200 | [diff] [blame] | 358 | } |
| 359 | |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 360 | static void dbg_result(const char *err, unsigned int n, unsigned int src_off, |
| 361 | unsigned int dst_off, unsigned int len, |
| 362 | unsigned long data) |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 363 | { |
Jerome Blin | 2acec15 | 2014-03-04 10:38:55 +0100 | [diff] [blame] | 364 | pr_debug("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)\n", |
Andy Shevchenko | a835bb8 | 2014-10-22 16:16:42 +0300 | [diff] [blame] | 365 | current->comm, n, err, src_off, dst_off, len, data); |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 366 | } |
| 367 | |
Andy Shevchenko | a835bb8 | 2014-10-22 16:16:42 +0300 | [diff] [blame] | 368 | #define verbose_result(err, n, src_off, dst_off, len, data) ({ \ |
| 369 | if (verbose) \ |
| 370 | result(err, n, src_off, dst_off, len, data); \ |
| 371 | else \ |
| 372 | dbg_result(err, n, src_off, dst_off, len, data);\ |
Dan Williams | 50137a7 | 2013-11-08 12:26:26 -0800 | [diff] [blame] | 373 | }) |
| 374 | |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 375 | static unsigned long long dmatest_persec(s64 runtime, unsigned int val) |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 376 | { |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 377 | unsigned long long per_sec = 1000000; |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 378 | |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 379 | if (runtime <= 0) |
| 380 | return 0; |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 381 | |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 382 | /* drop precision until runtime is 32-bits */ |
| 383 | while (runtime > UINT_MAX) { |
| 384 | runtime >>= 1; |
| 385 | per_sec <<= 1; |
| 386 | } |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 387 | |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 388 | per_sec *= val; |
| 389 | do_div(per_sec, runtime); |
| 390 | return per_sec; |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 391 | } |
| 392 | |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 393 | static unsigned long long dmatest_KBs(s64 runtime, unsigned long long len) |
Andy Shevchenko | d86b2f2 | 2013-03-04 11:09:34 +0200 | [diff] [blame] | 394 | { |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 395 | return dmatest_persec(runtime, len >> 10); |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 396 | } |
| 397 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 398 | /* |
| 399 | * This function repeatedly tests DMA transfers of various lengths and |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 400 | * offsets for a given operation type until it is told to exit by |
| 401 | * kthread_stop(). There may be multiple threads running this function |
| 402 | * in parallel for a single channel, and there may be multiple channels |
| 403 | * being tested in parallel. |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 404 | * |
| 405 | * Before each test, the source and destination buffer is initialized |
| 406 | * with a known pattern. This pattern is different depending on |
| 407 | * whether it's in an area which is supposed to be copied or |
| 408 | * overwritten, and different in the source and destination buffers. |
| 409 | * So if the DMA engine doesn't copy exactly what we tell it to copy, |
| 410 | * we'll notice. |
| 411 | */ |
| 412 | static int dmatest_func(void *data) |
| 413 | { |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 414 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_wait); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 415 | struct dmatest_thread *thread = data; |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 416 | struct dmatest_done done = { .wait = &done_wait }; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 417 | struct dmatest_info *info; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 418 | struct dmatest_params *params; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 419 | struct dma_chan *chan; |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 420 | struct dma_device *dev; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 421 | unsigned int error_count; |
| 422 | unsigned int failed_tests = 0; |
| 423 | unsigned int total_tests = 0; |
| 424 | dma_cookie_t cookie; |
| 425 | enum dma_status status; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 426 | enum dma_ctrl_flags flags; |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 427 | u8 *pq_coefs = NULL; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 428 | int ret; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 429 | int src_cnt; |
| 430 | int dst_cnt; |
| 431 | int i; |
Sinan Kaya | e9405ef | 2016-09-01 10:02:55 -0400 | [diff] [blame] | 432 | ktime_t ktime, start, diff; |
Thomas Gleixner | 8b0e195 | 2016-12-25 12:30:41 +0100 | [diff] [blame] | 433 | ktime_t filltime = 0; |
| 434 | ktime_t comparetime = 0; |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 435 | s64 runtime = 0; |
| 436 | unsigned long long total_len = 0; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 437 | u8 align = 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 438 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 439 | set_freezable(); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 440 | |
| 441 | ret = -ENOMEM; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 442 | |
| 443 | smp_rmb(); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 444 | info = thread->info; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 445 | params = &info->params; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 446 | chan = thread->chan; |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 447 | dev = chan->device; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 448 | if (thread->type == DMA_MEMCPY) { |
| 449 | align = dev->copy_align; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 450 | src_cnt = dst_cnt = 1; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 451 | } else if (thread->type == DMA_SG) { |
| 452 | align = dev->copy_align; |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 453 | src_cnt = dst_cnt = sg_buffers; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 454 | } else if (thread->type == DMA_XOR) { |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 455 | /* force odd to ensure dst = src */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 456 | src_cnt = min_odd(params->xor_sources | 1, dev->max_xor); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 457 | dst_cnt = 1; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 458 | align = dev->xor_align; |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 459 | } else if (thread->type == DMA_PQ) { |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 460 | /* force odd to ensure dst = src */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 461 | src_cnt = min_odd(params->pq_sources | 1, dma_maxpq(dev, 0)); |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 462 | dst_cnt = 2; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 463 | align = dev->pq_align; |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 464 | |
Dave Jiang | 31d1825 | 2016-11-29 13:22:01 -0700 | [diff] [blame] | 465 | pq_coefs = kmalloc(params->pq_sources + 1, GFP_KERNEL); |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 466 | if (!pq_coefs) |
| 467 | goto err_thread_type; |
| 468 | |
Anatolij Gustschin | 94de648 | 2010-02-15 22:35:23 +0100 | [diff] [blame] | 469 | for (i = 0; i < src_cnt; i++) |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 470 | pq_coefs[i] = 1; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 471 | } else |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 472 | goto err_thread_type; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 473 | |
Dave Jiang | 31d1825 | 2016-11-29 13:22:01 -0700 | [diff] [blame] | 474 | thread->srcs = kcalloc(src_cnt + 1, sizeof(u8 *), GFP_KERNEL); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 475 | if (!thread->srcs) |
| 476 | goto err_srcs; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 477 | |
| 478 | thread->usrcs = kcalloc(src_cnt + 1, sizeof(u8 *), GFP_KERNEL); |
| 479 | if (!thread->usrcs) |
| 480 | goto err_usrcs; |
| 481 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 482 | for (i = 0; i < src_cnt; i++) { |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 483 | thread->usrcs[i] = kmalloc(params->buf_size + align, |
| 484 | GFP_KERNEL); |
| 485 | if (!thread->usrcs[i]) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 486 | goto err_srcbuf; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 487 | |
| 488 | /* align srcs to alignment restriction */ |
| 489 | if (align) |
| 490 | thread->srcs[i] = PTR_ALIGN(thread->usrcs[i], align); |
| 491 | else |
| 492 | thread->srcs[i] = thread->usrcs[i]; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 493 | } |
| 494 | thread->srcs[i] = NULL; |
| 495 | |
Dave Jiang | 31d1825 | 2016-11-29 13:22:01 -0700 | [diff] [blame] | 496 | thread->dsts = kcalloc(dst_cnt + 1, sizeof(u8 *), GFP_KERNEL); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 497 | if (!thread->dsts) |
| 498 | goto err_dsts; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 499 | |
| 500 | thread->udsts = kcalloc(dst_cnt + 1, sizeof(u8 *), GFP_KERNEL); |
| 501 | if (!thread->udsts) |
| 502 | goto err_udsts; |
| 503 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 504 | for (i = 0; i < dst_cnt; i++) { |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 505 | thread->udsts[i] = kmalloc(params->buf_size + align, |
| 506 | GFP_KERNEL); |
| 507 | if (!thread->udsts[i]) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 508 | goto err_dstbuf; |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 509 | |
| 510 | /* align dsts to alignment restriction */ |
| 511 | if (align) |
| 512 | thread->dsts[i] = PTR_ALIGN(thread->udsts[i], align); |
| 513 | else |
| 514 | thread->dsts[i] = thread->udsts[i]; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 515 | } |
| 516 | thread->dsts[i] = NULL; |
| 517 | |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 518 | set_user_nice(current, 10); |
| 519 | |
Ira Snyder | b203bd3 | 2011-03-03 07:54:53 +0000 | [diff] [blame] | 520 | /* |
Bartlomiej Zolnierkiewicz | d1cab34 | 2013-10-18 19:35:21 +0200 | [diff] [blame] | 521 | * src and dst buffers are freed by ourselves below |
Ira Snyder | b203bd3 | 2011-03-03 07:54:53 +0000 | [diff] [blame] | 522 | */ |
Bartlomiej Zolnierkiewicz | 0776ae7 | 2013-10-18 19:35:33 +0200 | [diff] [blame] | 523 | flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 524 | |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 525 | ktime = ktime_get(); |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 526 | while (!kthread_should_stop() |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 527 | && !(params->iterations && total_tests >= params->iterations)) { |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 528 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 529 | struct dmaengine_unmap_data *um; |
| 530 | dma_addr_t srcs[src_cnt]; |
| 531 | dma_addr_t *dsts; |
Andy Shevchenko | ede23a5 | 2014-10-22 16:16:43 +0300 | [diff] [blame] | 532 | unsigned int src_off, dst_off, len; |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 533 | struct scatterlist tx_sg[src_cnt]; |
| 534 | struct scatterlist rx_sg[src_cnt]; |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 535 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 536 | total_tests++; |
| 537 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 538 | if (1 << align > params->buf_size) { |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 539 | pr_err("%u-byte buffer too small for %d-byte alignment\n", |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 540 | params->buf_size, 1 << align); |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 541 | break; |
| 542 | } |
| 543 | |
Andy Shevchenko | ede23a5 | 2014-10-22 16:16:43 +0300 | [diff] [blame] | 544 | if (params->noverify) |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 545 | len = params->buf_size; |
Andy Shevchenko | ede23a5 | 2014-10-22 16:16:43 +0300 | [diff] [blame] | 546 | else |
| 547 | len = dmatest_random() % params->buf_size + 1; |
| 548 | |
| 549 | len = (len >> align) << align; |
| 550 | if (!len) |
| 551 | len = 1 << align; |
| 552 | |
| 553 | total_len += len; |
| 554 | |
| 555 | if (params->noverify) { |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 556 | src_off = 0; |
| 557 | dst_off = 0; |
| 558 | } else { |
Sinan Kaya | e9405ef | 2016-09-01 10:02:55 -0400 | [diff] [blame] | 559 | start = ktime_get(); |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 560 | src_off = dmatest_random() % (params->buf_size - len + 1); |
| 561 | dst_off = dmatest_random() % (params->buf_size - len + 1); |
| 562 | |
| 563 | src_off = (src_off >> align) << align; |
| 564 | dst_off = (dst_off >> align) << align; |
| 565 | |
| 566 | dmatest_init_srcs(thread->srcs, src_off, len, |
| 567 | params->buf_size); |
| 568 | dmatest_init_dsts(thread->dsts, dst_off, len, |
| 569 | params->buf_size); |
Sinan Kaya | e9405ef | 2016-09-01 10:02:55 -0400 | [diff] [blame] | 570 | |
| 571 | diff = ktime_sub(ktime_get(), start); |
| 572 | filltime = ktime_add(filltime, diff); |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Dave Jiang | 31d1825 | 2016-11-29 13:22:01 -0700 | [diff] [blame] | 575 | um = dmaengine_get_unmap_data(dev->dev, src_cnt + dst_cnt, |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 576 | GFP_KERNEL); |
| 577 | if (!um) { |
| 578 | failed_tests++; |
| 579 | result("unmap data NULL", total_tests, |
| 580 | src_off, dst_off, len, ret); |
| 581 | continue; |
| 582 | } |
Dan Williams | 83544ae | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 583 | |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 584 | um->len = params->buf_size; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 585 | for (i = 0; i < src_cnt; i++) { |
Dan Williams | 745c00d | 2013-12-09 11:16:01 -0800 | [diff] [blame] | 586 | void *buf = thread->srcs[i]; |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 587 | struct page *pg = virt_to_page(buf); |
Dan Williams | 745c00d | 2013-12-09 11:16:01 -0800 | [diff] [blame] | 588 | unsigned pg_off = (unsigned long) buf & ~PAGE_MASK; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 589 | |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 590 | um->addr[i] = dma_map_page(dev->dev, pg, pg_off, |
| 591 | um->len, DMA_TO_DEVICE); |
| 592 | srcs[i] = um->addr[i] + src_off; |
| 593 | ret = dma_mapping_error(dev->dev, um->addr[i]); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 594 | if (ret) { |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 595 | dmaengine_unmap_put(um); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 596 | result("src mapping error", total_tests, |
| 597 | src_off, dst_off, len, ret); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 598 | failed_tests++; |
| 599 | continue; |
| 600 | } |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 601 | um->to_cnt++; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 602 | } |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 603 | /* map with DMA_BIDIRECTIONAL to force writeback/invalidate */ |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 604 | dsts = &um->addr[src_cnt]; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 605 | for (i = 0; i < dst_cnt; i++) { |
Dan Williams | 745c00d | 2013-12-09 11:16:01 -0800 | [diff] [blame] | 606 | void *buf = thread->dsts[i]; |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 607 | struct page *pg = virt_to_page(buf); |
Dan Williams | 745c00d | 2013-12-09 11:16:01 -0800 | [diff] [blame] | 608 | unsigned pg_off = (unsigned long) buf & ~PAGE_MASK; |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 609 | |
| 610 | dsts[i] = dma_map_page(dev->dev, pg, pg_off, um->len, |
| 611 | DMA_BIDIRECTIONAL); |
| 612 | ret = dma_mapping_error(dev->dev, dsts[i]); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 613 | if (ret) { |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 614 | dmaengine_unmap_put(um); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 615 | result("dst mapping error", total_tests, |
| 616 | src_off, dst_off, len, ret); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 617 | failed_tests++; |
| 618 | continue; |
| 619 | } |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 620 | um->bidi_cnt++; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 621 | } |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 622 | |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 623 | sg_init_table(tx_sg, src_cnt); |
| 624 | sg_init_table(rx_sg, src_cnt); |
| 625 | for (i = 0; i < src_cnt; i++) { |
| 626 | sg_dma_address(&rx_sg[i]) = srcs[i]; |
| 627 | sg_dma_address(&tx_sg[i]) = dsts[i] + dst_off; |
| 628 | sg_dma_len(&tx_sg[i]) = len; |
| 629 | sg_dma_len(&rx_sg[i]) = len; |
| 630 | } |
| 631 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 632 | if (thread->type == DMA_MEMCPY) |
| 633 | tx = dev->device_prep_dma_memcpy(chan, |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 634 | dsts[0] + dst_off, |
| 635 | srcs[0], len, flags); |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 636 | else if (thread->type == DMA_SG) |
| 637 | tx = dev->device_prep_dma_sg(chan, tx_sg, src_cnt, |
| 638 | rx_sg, src_cnt, flags); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 639 | else if (thread->type == DMA_XOR) |
| 640 | tx = dev->device_prep_dma_xor(chan, |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 641 | dsts[0] + dst_off, |
| 642 | srcs, src_cnt, |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 643 | len, flags); |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 644 | else if (thread->type == DMA_PQ) { |
| 645 | dma_addr_t dma_pq[dst_cnt]; |
| 646 | |
| 647 | for (i = 0; i < dst_cnt; i++) |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 648 | dma_pq[i] = dsts[i] + dst_off; |
| 649 | tx = dev->device_prep_dma_pq(chan, dma_pq, srcs, |
Anatolij Gustschin | 94de648 | 2010-02-15 22:35:23 +0100 | [diff] [blame] | 650 | src_cnt, pq_coefs, |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 651 | len, flags); |
| 652 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 653 | |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 654 | if (!tx) { |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 655 | dmaengine_unmap_put(um); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 656 | result("prep error", total_tests, src_off, |
| 657 | dst_off, len, ret); |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 658 | msleep(100); |
| 659 | failed_tests++; |
| 660 | continue; |
| 661 | } |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 662 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 663 | done.done = false; |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 664 | tx->callback = dmatest_callback; |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 665 | tx->callback_param = &done; |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 666 | cookie = tx->tx_submit(tx); |
| 667 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 668 | if (dma_submit_error(cookie)) { |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 669 | dmaengine_unmap_put(um); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 670 | result("submit error", total_tests, src_off, |
| 671 | dst_off, len, ret); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 672 | msleep(100); |
| 673 | failed_tests++; |
| 674 | continue; |
| 675 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 676 | dma_async_issue_pending(chan); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 677 | |
Andy Shevchenko | bcc567e | 2013-05-23 14:29:53 +0300 | [diff] [blame] | 678 | wait_event_freezable_timeout(done_wait, done.done, |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 679 | msecs_to_jiffies(params->timeout)); |
Guennadi Liakhovetski | 981ed70 | 2011-08-18 16:50:51 +0200 | [diff] [blame] | 680 | |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 681 | status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 682 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 683 | if (!done.done) { |
| 684 | /* |
| 685 | * We're leaving the timed out dma operation with |
| 686 | * dangling pointer to done_wait. To make this |
| 687 | * correct, we'll need to allocate wait_done for |
| 688 | * each test iteration and perform "who's gonna |
| 689 | * free it this time?" dancing. For now, just |
| 690 | * leave it dangling. |
| 691 | */ |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 692 | dmaengine_unmap_put(um); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 693 | result("test timed out", total_tests, src_off, dst_off, |
| 694 | len, 0); |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 695 | failed_tests++; |
| 696 | continue; |
Vinod Koul | 19e9f99 | 2013-10-16 13:37:27 +0530 | [diff] [blame] | 697 | } else if (status != DMA_COMPLETE) { |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 698 | dmaengine_unmap_put(um); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 699 | result(status == DMA_ERROR ? |
| 700 | "completion error status" : |
| 701 | "completion busy status", total_tests, src_off, |
| 702 | dst_off, len, ret); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 703 | failed_tests++; |
| 704 | continue; |
| 705 | } |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 706 | |
Dan Williams | 4076e75 | 2013-11-06 16:30:10 -0800 | [diff] [blame] | 707 | dmaengine_unmap_put(um); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 708 | |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 709 | if (params->noverify) { |
Dan Williams | 50137a7 | 2013-11-08 12:26:26 -0800 | [diff] [blame] | 710 | verbose_result("test passed", total_tests, src_off, |
| 711 | dst_off, len, 0); |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 712 | continue; |
| 713 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 714 | |
Sinan Kaya | e9405ef | 2016-09-01 10:02:55 -0400 | [diff] [blame] | 715 | start = ktime_get(); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 716 | pr_debug("%s: verifying source buffer...\n", current->comm); |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 717 | error_count = dmatest_verify(thread->srcs, 0, src_off, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 718 | 0, PATTERN_SRC, true); |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 719 | error_count += dmatest_verify(thread->srcs, src_off, |
| 720 | src_off + len, src_off, |
| 721 | PATTERN_SRC | PATTERN_COPY, true); |
| 722 | error_count += dmatest_verify(thread->srcs, src_off + len, |
| 723 | params->buf_size, src_off + len, |
| 724 | PATTERN_SRC, true); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 725 | |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 726 | pr_debug("%s: verifying dest buffer...\n", current->comm); |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 727 | error_count += dmatest_verify(thread->dsts, 0, dst_off, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 728 | 0, PATTERN_DST, false); |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 729 | error_count += dmatest_verify(thread->dsts, dst_off, |
| 730 | dst_off + len, src_off, |
| 731 | PATTERN_SRC | PATTERN_COPY, false); |
| 732 | error_count += dmatest_verify(thread->dsts, dst_off + len, |
| 733 | params->buf_size, dst_off + len, |
| 734 | PATTERN_DST, false); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 735 | |
Sinan Kaya | e9405ef | 2016-09-01 10:02:55 -0400 | [diff] [blame] | 736 | diff = ktime_sub(ktime_get(), start); |
| 737 | comparetime = ktime_add(comparetime, diff); |
| 738 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 739 | if (error_count) { |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 740 | result("data error", total_tests, src_off, dst_off, |
| 741 | len, error_count); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 742 | failed_tests++; |
| 743 | } else { |
Dan Williams | 50137a7 | 2013-11-08 12:26:26 -0800 | [diff] [blame] | 744 | verbose_result("test passed", total_tests, src_off, |
| 745 | dst_off, len, 0); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
Sinan Kaya | e9405ef | 2016-09-01 10:02:55 -0400 | [diff] [blame] | 748 | ktime = ktime_sub(ktime_get(), ktime); |
| 749 | ktime = ktime_sub(ktime, comparetime); |
| 750 | ktime = ktime_sub(ktime, filltime); |
| 751 | runtime = ktime_to_us(ktime); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 752 | |
| 753 | ret = 0; |
Andy Shevchenko | 8e1f50d | 2014-08-22 15:19:44 +0300 | [diff] [blame] | 754 | err_dstbuf: |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 755 | for (i = 0; thread->udsts[i]; i++) |
| 756 | kfree(thread->udsts[i]); |
| 757 | kfree(thread->udsts); |
| 758 | err_udsts: |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 759 | kfree(thread->dsts); |
| 760 | err_dsts: |
Andy Shevchenko | 8e1f50d | 2014-08-22 15:19:44 +0300 | [diff] [blame] | 761 | err_srcbuf: |
Dave Jiang | d648160 | 2016-11-29 13:22:20 -0700 | [diff] [blame] | 762 | for (i = 0; thread->usrcs[i]; i++) |
| 763 | kfree(thread->usrcs[i]); |
| 764 | kfree(thread->usrcs); |
| 765 | err_usrcs: |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 766 | kfree(thread->srcs); |
| 767 | err_srcs: |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 768 | kfree(pq_coefs); |
| 769 | err_thread_type: |
Dan Williams | 8672744 | 2013-11-06 16:30:07 -0800 | [diff] [blame] | 770 | pr_info("%s: summary %u tests, %u failures %llu iops %llu KB/s (%d)\n", |
| 771 | current->comm, total_tests, failed_tests, |
| 772 | dmatest_persec(runtime, total_tests), |
| 773 | dmatest_KBs(runtime, total_len), ret); |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 774 | |
Viresh Kumar | 9704efa | 2011-07-29 16:21:57 +0530 | [diff] [blame] | 775 | /* terminate all transfers on specified channels */ |
Shiraz Hashim | 5e034f7 | 2012-11-09 15:26:29 +0000 | [diff] [blame] | 776 | if (ret) |
| 777 | dmaengine_terminate_all(chan); |
| 778 | |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 779 | thread->done = true; |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 780 | wake_up(&thread_wait); |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 781 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 782 | return ret; |
| 783 | } |
| 784 | |
| 785 | static void dmatest_cleanup_channel(struct dmatest_chan *dtc) |
| 786 | { |
| 787 | struct dmatest_thread *thread; |
| 788 | struct dmatest_thread *_thread; |
| 789 | int ret; |
| 790 | |
| 791 | list_for_each_entry_safe(thread, _thread, &dtc->threads, node) { |
| 792 | ret = kthread_stop(thread->task); |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 793 | pr_debug("thread %s exited with status %d\n", |
| 794 | thread->task->comm, ret); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 795 | list_del(&thread->node); |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 796 | put_task_struct(thread->task); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 797 | kfree(thread); |
| 798 | } |
Viresh Kumar | 9704efa | 2011-07-29 16:21:57 +0530 | [diff] [blame] | 799 | |
| 800 | /* terminate all transfers on specified channels */ |
Jon Mason | 944ea4d | 2012-11-11 23:03:20 +0000 | [diff] [blame] | 801 | dmaengine_terminate_all(dtc->chan); |
Viresh Kumar | 9704efa | 2011-07-29 16:21:57 +0530 | [diff] [blame] | 802 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 803 | kfree(dtc); |
| 804 | } |
| 805 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 806 | static int dmatest_add_threads(struct dmatest_info *info, |
| 807 | struct dmatest_chan *dtc, enum dma_transaction_type type) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 808 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 809 | struct dmatest_params *params = &info->params; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 810 | struct dmatest_thread *thread; |
| 811 | struct dma_chan *chan = dtc->chan; |
| 812 | char *op; |
| 813 | unsigned int i; |
| 814 | |
| 815 | if (type == DMA_MEMCPY) |
| 816 | op = "copy"; |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 817 | else if (type == DMA_SG) |
| 818 | op = "sg"; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 819 | else if (type == DMA_XOR) |
| 820 | op = "xor"; |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 821 | else if (type == DMA_PQ) |
| 822 | op = "pq"; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 823 | else |
| 824 | return -EINVAL; |
| 825 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 826 | for (i = 0; i < params->threads_per_chan; i++) { |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 827 | thread = kzalloc(sizeof(struct dmatest_thread), GFP_KERNEL); |
| 828 | if (!thread) { |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 829 | pr_warn("No memory for %s-%s%u\n", |
| 830 | dma_chan_name(chan), op, i); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 831 | break; |
| 832 | } |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 833 | thread->info = info; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 834 | thread->chan = dtc->chan; |
| 835 | thread->type = type; |
| 836 | smp_wmb(); |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 837 | thread->task = kthread_create(dmatest_func, thread, "%s-%s%u", |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 838 | dma_chan_name(chan), op, i); |
| 839 | if (IS_ERR(thread->task)) { |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 840 | pr_warn("Failed to create thread %s-%s%u\n", |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 841 | dma_chan_name(chan), op, i); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 842 | kfree(thread); |
| 843 | break; |
| 844 | } |
| 845 | |
| 846 | /* srcbuf and dstbuf are allocated by the thread itself */ |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 847 | get_task_struct(thread->task); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 848 | list_add_tail(&thread->node, &dtc->threads); |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 849 | wake_up_process(thread->task); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | return i; |
| 853 | } |
| 854 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 855 | static int dmatest_add_channel(struct dmatest_info *info, |
| 856 | struct dma_chan *chan) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 857 | { |
| 858 | struct dmatest_chan *dtc; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 859 | struct dma_device *dma_dev = chan->device; |
| 860 | unsigned int thread_count = 0; |
Kulikov Vasiliy | b9033e6 | 2010-07-17 19:19:48 +0400 | [diff] [blame] | 861 | int cnt; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 862 | |
Andrew Morton | 6fdb8bd | 2008-09-19 04:16:23 -0700 | [diff] [blame] | 863 | dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 864 | if (!dtc) { |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 865 | pr_warn("No memory for %s\n", dma_chan_name(chan)); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 866 | return -ENOMEM; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | dtc->chan = chan; |
| 870 | INIT_LIST_HEAD(&dtc->threads); |
| 871 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 872 | if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) { |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 873 | if (dmatest == 0) { |
| 874 | cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY); |
| 875 | thread_count += cnt > 0 ? cnt : 0; |
| 876 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 877 | } |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 878 | |
| 879 | if (dma_has_cap(DMA_SG, dma_dev->cap_mask)) { |
| 880 | if (dmatest == 1) { |
| 881 | cnt = dmatest_add_threads(info, dtc, DMA_SG); |
| 882 | thread_count += cnt > 0 ? cnt : 0; |
| 883 | } |
| 884 | } |
| 885 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 886 | if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 887 | cnt = dmatest_add_threads(info, dtc, DMA_XOR); |
Nicolas Ferre | f1aef8b | 2009-07-06 18:19:44 +0200 | [diff] [blame] | 888 | thread_count += cnt > 0 ? cnt : 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 889 | } |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 890 | if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 891 | cnt = dmatest_add_threads(info, dtc, DMA_PQ); |
Dr. David Alan Gilbert | d07a74a | 2011-08-25 16:13:55 -0700 | [diff] [blame] | 892 | thread_count += cnt > 0 ? cnt : 0; |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 893 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 894 | |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 895 | pr_info("Started %u threads using %s\n", |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 896 | thread_count, dma_chan_name(chan)); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 897 | |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 898 | list_add_tail(&dtc->node, &info->channels); |
| 899 | info->nr_channels++; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 900 | |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 901 | return 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Dan Williams | 7dd6025 | 2009-01-06 11:38:19 -0700 | [diff] [blame] | 904 | static bool filter(struct dma_chan *chan, void *param) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 905 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 906 | struct dmatest_params *params = param; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 907 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 908 | if (!dmatest_match_channel(params, chan) || |
| 909 | !dmatest_match_device(params, chan->device)) |
Dan Williams | 7dd6025 | 2009-01-06 11:38:19 -0700 | [diff] [blame] | 910 | return false; |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 911 | else |
Dan Williams | 7dd6025 | 2009-01-06 11:38:19 -0700 | [diff] [blame] | 912 | return true; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 915 | static void request_channels(struct dmatest_info *info, |
| 916 | enum dma_transaction_type type) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 917 | { |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 918 | dma_cap_mask_t mask; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 919 | |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 920 | dma_cap_zero(mask); |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 921 | dma_cap_set(type, mask); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 922 | for (;;) { |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 923 | struct dmatest_params *params = &info->params; |
| 924 | struct dma_chan *chan; |
| 925 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 926 | chan = dma_request_channel(mask, filter, params); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 927 | if (chan) { |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 928 | if (dmatest_add_channel(info, chan)) { |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 929 | dma_release_channel(chan); |
| 930 | break; /* add_channel failed, punt */ |
| 931 | } |
| 932 | } else |
| 933 | break; /* no more channels available */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 934 | if (params->max_channels && |
| 935 | info->nr_channels >= params->max_channels) |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 936 | break; /* we have all we need */ |
| 937 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 938 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 939 | |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 940 | static void run_threaded_test(struct dmatest_info *info) |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 941 | { |
| 942 | struct dmatest_params *params = &info->params; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 943 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 944 | /* Copy test parameters */ |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 945 | params->buf_size = test_buf_size; |
| 946 | strlcpy(params->channel, strim(test_channel), sizeof(params->channel)); |
| 947 | strlcpy(params->device, strim(test_device), sizeof(params->device)); |
| 948 | params->threads_per_chan = threads_per_chan; |
| 949 | params->max_channels = max_channels; |
| 950 | params->iterations = iterations; |
| 951 | params->xor_sources = xor_sources; |
| 952 | params->pq_sources = pq_sources; |
| 953 | params->timeout = timeout; |
Dan Williams | e3b9c34 | 2013-11-06 16:30:05 -0800 | [diff] [blame] | 954 | params->noverify = noverify; |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 955 | |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 956 | request_channels(info, DMA_MEMCPY); |
| 957 | request_channels(info, DMA_XOR); |
Kedareswara rao Appana | a0d4cb4 | 2016-06-09 21:10:14 +0530 | [diff] [blame] | 958 | request_channels(info, DMA_SG); |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 959 | request_channels(info, DMA_PQ); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 962 | static void stop_threaded_test(struct dmatest_info *info) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 963 | { |
| 964 | struct dmatest_chan *dtc, *_dtc; |
| 965 | struct dma_chan *chan; |
| 966 | |
| 967 | list_for_each_entry_safe(dtc, _dtc, &info->channels, node) { |
| 968 | list_del(&dtc->node); |
| 969 | chan = dtc->chan; |
| 970 | dmatest_cleanup_channel(dtc); |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 971 | pr_debug("dropped channel %s\n", dma_chan_name(chan)); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 972 | dma_release_channel(chan); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 973 | } |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 974 | |
Dan Williams | 7cbd487 | 2009-03-04 16:06:03 -0700 | [diff] [blame] | 975 | info->nr_channels = 0; |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 976 | } |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 977 | |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 978 | static void restart_threaded_test(struct dmatest_info *info, bool run) |
Dan Williams | 7cbd487 | 2009-03-04 16:06:03 -0700 | [diff] [blame] | 979 | { |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 980 | /* we might be called early to set run=, defer running until all |
| 981 | * parameters have been evaluated |
| 982 | */ |
| 983 | if (!info->did_init) |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 984 | return; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 985 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 986 | /* Stop any running test first */ |
| 987 | stop_threaded_test(info); |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 988 | |
| 989 | /* Run test with new parameters */ |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 990 | run_threaded_test(info); |
Andy Shevchenko | bcc567e | 2013-05-23 14:29:53 +0300 | [diff] [blame] | 991 | } |
| 992 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 993 | static int dmatest_run_get(char *val, const struct kernel_param *kp) |
Andy Shevchenko | bcc567e | 2013-05-23 14:29:53 +0300 | [diff] [blame] | 994 | { |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 995 | struct dmatest_info *info = &test_info; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 996 | |
| 997 | mutex_lock(&info->lock); |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 998 | if (is_threaded_test_run(info)) { |
| 999 | dmatest_run = true; |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 1000 | } else { |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 1001 | stop_threaded_test(info); |
| 1002 | dmatest_run = false; |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 1003 | } |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 1004 | mutex_unlock(&info->lock); |
| 1005 | |
| 1006 | return param_get_bool(val, kp); |
| 1007 | } |
| 1008 | |
| 1009 | static int dmatest_run_set(const char *val, const struct kernel_param *kp) |
| 1010 | { |
| 1011 | struct dmatest_info *info = &test_info; |
| 1012 | int ret; |
| 1013 | |
| 1014 | mutex_lock(&info->lock); |
| 1015 | ret = param_set_bool(val, kp); |
| 1016 | if (ret) { |
| 1017 | mutex_unlock(&info->lock); |
| 1018 | return ret; |
| 1019 | } |
| 1020 | |
| 1021 | if (is_threaded_test_run(info)) |
| 1022 | ret = -EBUSY; |
| 1023 | else if (dmatest_run) |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 1024 | restart_threaded_test(info, dmatest_run); |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 1025 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1026 | mutex_unlock(&info->lock); |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1027 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 1028 | return ret; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1029 | } |
| 1030 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1031 | static int __init dmatest_init(void) |
| 1032 | { |
| 1033 | struct dmatest_info *info = &test_info; |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 1034 | struct dmatest_params *params = &info->params; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1035 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 1036 | if (dmatest_run) { |
| 1037 | mutex_lock(&info->lock); |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame] | 1038 | run_threaded_test(info); |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 1039 | mutex_unlock(&info->lock); |
| 1040 | } |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1041 | |
Dan Williams | 2d88ce7 | 2013-11-06 16:30:09 -0800 | [diff] [blame] | 1042 | if (params->iterations && wait) |
| 1043 | wait_event(thread_wait, !is_threaded_test_run(info)); |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 1044 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 1045 | /* module parameters are stable, inittime tests are started, |
| 1046 | * let userspace take over 'run' control |
| 1047 | */ |
| 1048 | info->did_init = true; |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 1049 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1050 | return 0; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1051 | } |
| 1052 | /* when compiled-in wait for drivers to load first */ |
| 1053 | late_initcall(dmatest_init); |
| 1054 | |
| 1055 | static void __exit dmatest_exit(void) |
| 1056 | { |
| 1057 | struct dmatest_info *info = &test_info; |
| 1058 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 1059 | mutex_lock(&info->lock); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1060 | stop_threaded_test(info); |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 1061 | mutex_unlock(&info->lock); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1062 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 1063 | module_exit(dmatest_exit); |
| 1064 | |
Jean Delvare | e05503e | 2011-05-18 16:49:24 +0200 | [diff] [blame] | 1065 | MODULE_AUTHOR("Haavard Skinnemoen (Atmel)"); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 1066 | MODULE_LICENSE("GPL v2"); |