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> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/moduleparam.h> |
| 21 | #include <linux/random.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 23 | #include <linux/wait.h> |
| 24 | |
| 25 | static unsigned int test_buf_size = 16384; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 26 | module_param(test_buf_size, uint, S_IRUGO | S_IWUSR); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 27 | MODULE_PARM_DESC(test_buf_size, "Size of the memcpy test buffer"); |
| 28 | |
Kay Sievers | 06190d8 | 2008-11-11 13:12:33 -0700 | [diff] [blame] | 29 | static char test_channel[20]; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 30 | module_param_string(channel, test_channel, sizeof(test_channel), |
| 31 | S_IRUGO | S_IWUSR); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 32 | MODULE_PARM_DESC(channel, "Bus ID of the channel to test (default: any)"); |
| 33 | |
Kay Sievers | 06190d8 | 2008-11-11 13:12:33 -0700 | [diff] [blame] | 34 | static char test_device[20]; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 35 | module_param_string(device, test_device, sizeof(test_device), |
| 36 | S_IRUGO | S_IWUSR); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 37 | MODULE_PARM_DESC(device, "Bus ID of the DMA Engine to test (default: any)"); |
| 38 | |
| 39 | static unsigned int threads_per_chan = 1; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 40 | module_param(threads_per_chan, uint, S_IRUGO | S_IWUSR); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 41 | MODULE_PARM_DESC(threads_per_chan, |
| 42 | "Number of threads to start per channel (default: 1)"); |
| 43 | |
| 44 | static unsigned int max_channels; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 45 | module_param(max_channels, uint, S_IRUGO | S_IWUSR); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 46 | MODULE_PARM_DESC(max_channels, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 47 | "Maximum number of channels to use (default: all)"); |
| 48 | |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 49 | static unsigned int iterations; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 50 | module_param(iterations, uint, S_IRUGO | S_IWUSR); |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 51 | MODULE_PARM_DESC(iterations, |
| 52 | "Iterations before stopping test (default: infinite)"); |
| 53 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 54 | static unsigned int xor_sources = 3; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 55 | module_param(xor_sources, uint, S_IRUGO | S_IWUSR); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 56 | MODULE_PARM_DESC(xor_sources, |
| 57 | "Number of xor source buffers (default: 3)"); |
| 58 | |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 59 | static unsigned int pq_sources = 3; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 60 | module_param(pq_sources, uint, S_IRUGO | S_IWUSR); |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 61 | MODULE_PARM_DESC(pq_sources, |
| 62 | "Number of p+q source buffers (default: 3)"); |
| 63 | |
Viresh Kumar | d42efe6 | 2011-03-22 17:27:25 +0530 | [diff] [blame] | 64 | static int timeout = 3000; |
Andy Shevchenko | a6c268d | 2013-07-23 18:36:46 +0300 | [diff] [blame] | 65 | module_param(timeout, uint, S_IRUGO | S_IWUSR); |
Joe Perches | 85ee7a1 | 2011-04-23 20:38:19 -0700 | [diff] [blame] | 66 | MODULE_PARM_DESC(timeout, "Transfer Timeout in msec (default: 3000), " |
| 67 | "Pass -1 for infinite timeout"); |
Viresh Kumar | d42efe6 | 2011-03-22 17:27:25 +0530 | [diff] [blame] | 68 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 69 | /** |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 70 | * struct dmatest_params - test parameters. |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 71 | * @buf_size: size of the memcpy test buffer |
| 72 | * @channel: bus ID of the channel to test |
| 73 | * @device: bus ID of the DMA Engine to test |
| 74 | * @threads_per_chan: number of threads to start per channel |
| 75 | * @max_channels: maximum number of channels to use |
| 76 | * @iterations: iterations before stopping test |
| 77 | * @xor_sources: number of xor source buffers |
| 78 | * @pq_sources: number of p+q source buffers |
| 79 | * @timeout: transfer timeout in msec, -1 for infinite timeout |
| 80 | */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 81 | struct dmatest_params { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 82 | unsigned int buf_size; |
| 83 | char channel[20]; |
| 84 | char device[20]; |
| 85 | unsigned int threads_per_chan; |
| 86 | unsigned int max_channels; |
| 87 | unsigned int iterations; |
| 88 | unsigned int xor_sources; |
| 89 | unsigned int pq_sources; |
| 90 | int timeout; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * struct dmatest_info - test information. |
| 95 | * @params: test parameters |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 96 | * @lock: access protection to the fields of this structure |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 97 | */ |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 98 | static struct dmatest_info { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 99 | /* Test parameters */ |
| 100 | struct dmatest_params params; |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 101 | |
| 102 | /* Internal state */ |
| 103 | struct list_head channels; |
| 104 | unsigned int nr_channels; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 105 | struct mutex lock; |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 106 | bool did_init; |
| 107 | } test_info = { |
| 108 | .channels = LIST_HEAD_INIT(test_info.channels), |
| 109 | .lock = __MUTEX_INITIALIZER(test_info.lock), |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 110 | }; |
| 111 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 112 | static int dmatest_run_set(const char *val, const struct kernel_param *kp); |
| 113 | static int dmatest_run_get(char *val, const struct kernel_param *kp); |
| 114 | static struct kernel_param_ops run_ops = { |
| 115 | .set = dmatest_run_set, |
| 116 | .get = dmatest_run_get, |
| 117 | }; |
| 118 | static bool dmatest_run; |
| 119 | module_param_cb(run, &run_ops, &dmatest_run, S_IRUGO | S_IWUSR); |
| 120 | MODULE_PARM_DESC(run, "Run the test (default: false)"); |
| 121 | |
| 122 | /* Maximum amount of mismatched bytes in buffer to print */ |
| 123 | #define MAX_ERROR_COUNT 32 |
| 124 | |
| 125 | /* |
| 126 | * Initialization patterns. All bytes in the source buffer has bit 7 |
| 127 | * set, all bytes in the destination buffer has bit 7 cleared. |
| 128 | * |
| 129 | * Bit 6 is set for all bytes which are to be copied by the DMA |
| 130 | * engine. Bit 5 is set for all bytes which are to be overwritten by |
| 131 | * the DMA engine. |
| 132 | * |
| 133 | * The remaining bits are the inverse of a counter which increments by |
| 134 | * one for each byte address. |
| 135 | */ |
| 136 | #define PATTERN_SRC 0x80 |
| 137 | #define PATTERN_DST 0x00 |
| 138 | #define PATTERN_COPY 0x40 |
| 139 | #define PATTERN_OVERWRITE 0x20 |
| 140 | #define PATTERN_COUNT_MASK 0x1f |
| 141 | |
| 142 | struct dmatest_thread { |
| 143 | struct list_head node; |
| 144 | struct dmatest_info *info; |
| 145 | struct task_struct *task; |
| 146 | struct dma_chan *chan; |
| 147 | u8 **srcs; |
| 148 | u8 **dsts; |
| 149 | enum dma_transaction_type type; |
| 150 | bool done; |
| 151 | }; |
| 152 | |
| 153 | struct dmatest_chan { |
| 154 | struct list_head node; |
| 155 | struct dma_chan *chan; |
| 156 | struct list_head threads; |
| 157 | }; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 158 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 159 | static bool dmatest_match_channel(struct dmatest_params *params, |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 160 | struct dma_chan *chan) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 161 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 162 | if (params->channel[0] == '\0') |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 163 | return true; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 164 | return strcmp(dma_chan_name(chan), params->channel) == 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 167 | static bool dmatest_match_device(struct dmatest_params *params, |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 168 | struct dma_device *device) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 169 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 170 | if (params->device[0] == '\0') |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 171 | return true; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 172 | return strcmp(dev_name(device->dev), params->device) == 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static unsigned long dmatest_random(void) |
| 176 | { |
| 177 | unsigned long buf; |
| 178 | |
| 179 | get_random_bytes(&buf, sizeof(buf)); |
| 180 | return buf; |
| 181 | } |
| 182 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 183 | static void dmatest_init_srcs(u8 **bufs, unsigned int start, unsigned int len, |
| 184 | unsigned int buf_size) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 185 | { |
| 186 | unsigned int i; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 187 | u8 *buf; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 188 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 189 | for (; (buf = *bufs); bufs++) { |
| 190 | for (i = 0; i < start; i++) |
| 191 | buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK); |
| 192 | for ( ; i < start + len; i++) |
| 193 | buf[i] = PATTERN_SRC | PATTERN_COPY |
Joe Perches | c019894 | 2009-06-28 09:26:21 -0700 | [diff] [blame] | 194 | | (~i & PATTERN_COUNT_MASK); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 195 | for ( ; i < buf_size; i++) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 196 | buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK); |
| 197 | buf++; |
| 198 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 201 | static void dmatest_init_dsts(u8 **bufs, unsigned int start, unsigned int len, |
| 202 | unsigned int buf_size) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 203 | { |
| 204 | unsigned int i; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 205 | u8 *buf; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 206 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 207 | for (; (buf = *bufs); bufs++) { |
| 208 | for (i = 0; i < start; i++) |
| 209 | buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK); |
| 210 | for ( ; i < start + len; i++) |
| 211 | buf[i] = PATTERN_DST | PATTERN_OVERWRITE |
| 212 | | (~i & PATTERN_COUNT_MASK); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 213 | for ( ; i < buf_size; i++) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 214 | buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK); |
| 215 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 218 | static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index, |
| 219 | unsigned int counter, bool is_srcbuf) |
| 220 | { |
| 221 | u8 diff = actual ^ pattern; |
| 222 | u8 expected = pattern | (~counter & PATTERN_COUNT_MASK); |
| 223 | const char *thread_name = current->comm; |
| 224 | |
| 225 | if (is_srcbuf) |
| 226 | pr_warn("%s: srcbuf[0x%x] overwritten! Expected %02x, got %02x\n", |
| 227 | thread_name, index, expected, actual); |
| 228 | else if ((pattern & PATTERN_COPY) |
| 229 | && (diff & (PATTERN_COPY | PATTERN_OVERWRITE))) |
| 230 | pr_warn("%s: dstbuf[0x%x] not copied! Expected %02x, got %02x\n", |
| 231 | thread_name, index, expected, actual); |
| 232 | else if (diff & PATTERN_SRC) |
| 233 | pr_warn("%s: dstbuf[0x%x] was copied! Expected %02x, got %02x\n", |
| 234 | thread_name, index, expected, actual); |
| 235 | else |
| 236 | pr_warn("%s: dstbuf[0x%x] mismatch! Expected %02x, got %02x\n", |
| 237 | thread_name, index, expected, actual); |
| 238 | } |
| 239 | |
| 240 | static unsigned int dmatest_verify(u8 **bufs, unsigned int start, |
| 241 | unsigned int end, unsigned int counter, u8 pattern, |
| 242 | bool is_srcbuf) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 243 | { |
| 244 | unsigned int i; |
| 245 | unsigned int error_count = 0; |
| 246 | u8 actual; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 247 | u8 expected; |
| 248 | u8 *buf; |
| 249 | unsigned int counter_orig = counter; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 250 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 251 | for (; (buf = *bufs); bufs++) { |
| 252 | counter = counter_orig; |
| 253 | for (i = start; i < end; i++) { |
| 254 | actual = buf[i]; |
| 255 | expected = pattern | (~counter & PATTERN_COUNT_MASK); |
| 256 | if (actual != expected) { |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 257 | if (error_count < MAX_ERROR_COUNT) |
| 258 | dmatest_mismatch(actual, pattern, i, |
| 259 | counter, is_srcbuf); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 260 | error_count++; |
| 261 | } |
| 262 | counter++; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 263 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Andy Shevchenko | 74b5c07 | 2013-03-04 11:09:32 +0200 | [diff] [blame] | 266 | if (error_count > MAX_ERROR_COUNT) |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 267 | pr_warn("%s: %u errors suppressed\n", |
Andy Shevchenko | 74b5c07 | 2013-03-04 11:09:32 +0200 | [diff] [blame] | 268 | current->comm, error_count - MAX_ERROR_COUNT); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 269 | |
| 270 | return error_count; |
| 271 | } |
| 272 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 273 | /* poor man's completion - we want to use wait_event_freezable() on it */ |
| 274 | struct dmatest_done { |
| 275 | bool done; |
| 276 | wait_queue_head_t *wait; |
| 277 | }; |
| 278 | |
| 279 | static void dmatest_callback(void *arg) |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 280 | { |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 281 | struct dmatest_done *done = arg; |
| 282 | |
| 283 | done->done = true; |
| 284 | wake_up_all(done->wait); |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Andy Shevchenko | 632fd28 | 2012-12-17 15:59:52 -0800 | [diff] [blame] | 287 | static inline void unmap_src(struct device *dev, dma_addr_t *addr, size_t len, |
| 288 | unsigned int count) |
| 289 | { |
| 290 | while (count--) |
| 291 | dma_unmap_single(dev, addr[count], len, DMA_TO_DEVICE); |
| 292 | } |
| 293 | |
| 294 | static inline void unmap_dst(struct device *dev, dma_addr_t *addr, size_t len, |
| 295 | unsigned int count) |
| 296 | { |
| 297 | while (count--) |
| 298 | dma_unmap_single(dev, addr[count], len, DMA_BIDIRECTIONAL); |
| 299 | } |
| 300 | |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 301 | static unsigned int min_odd(unsigned int x, unsigned int y) |
| 302 | { |
| 303 | unsigned int val = min(x, y); |
| 304 | |
| 305 | return val % 2 ? val : val - 1; |
| 306 | } |
| 307 | |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 308 | static void result(const char *err, unsigned int n, unsigned int src_off, |
| 309 | unsigned int dst_off, unsigned int len, unsigned long data) |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 310 | { |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 311 | pr_info("%s: result #%u: '%s' with src_off=0x%x ""dst_off=0x%x len=0x%x (%lu)", |
| 312 | current->comm, n, err, src_off, dst_off, len, data); |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 315 | static void dbg_result(const char *err, unsigned int n, unsigned int src_off, |
| 316 | unsigned int dst_off, unsigned int len, |
| 317 | unsigned long data) |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 318 | { |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 319 | pr_debug("%s: result #%u: '%s' with src_off=0x%x ""dst_off=0x%x len=0x%x (%lu)", |
| 320 | current->comm, n, err, src_off, dst_off, len, data); |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 323 | /* |
| 324 | * This function repeatedly tests DMA transfers of various lengths and |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 325 | * offsets for a given operation type until it is told to exit by |
| 326 | * kthread_stop(). There may be multiple threads running this function |
| 327 | * in parallel for a single channel, and there may be multiple channels |
| 328 | * being tested in parallel. |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 329 | * |
| 330 | * Before each test, the source and destination buffer is initialized |
| 331 | * with a known pattern. This pattern is different depending on |
| 332 | * whether it's in an area which is supposed to be copied or |
| 333 | * overwritten, and different in the source and destination buffers. |
| 334 | * So if the DMA engine doesn't copy exactly what we tell it to copy, |
| 335 | * we'll notice. |
| 336 | */ |
| 337 | static int dmatest_func(void *data) |
| 338 | { |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 339 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_wait); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 340 | struct dmatest_thread *thread = data; |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 341 | struct dmatest_done done = { .wait = &done_wait }; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 342 | struct dmatest_info *info; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 343 | struct dmatest_params *params; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 344 | struct dma_chan *chan; |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 345 | struct dma_device *dev; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 346 | unsigned int src_off, dst_off, len; |
| 347 | unsigned int error_count; |
| 348 | unsigned int failed_tests = 0; |
| 349 | unsigned int total_tests = 0; |
| 350 | dma_cookie_t cookie; |
| 351 | enum dma_status status; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 352 | enum dma_ctrl_flags flags; |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 353 | u8 *pq_coefs = NULL; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 354 | int ret; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 355 | int src_cnt; |
| 356 | int dst_cnt; |
| 357 | int i; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 358 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 359 | set_freezable(); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 360 | |
| 361 | ret = -ENOMEM; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 362 | |
| 363 | smp_rmb(); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 364 | info = thread->info; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 365 | params = &info->params; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 366 | chan = thread->chan; |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 367 | dev = chan->device; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 368 | if (thread->type == DMA_MEMCPY) |
| 369 | src_cnt = dst_cnt = 1; |
| 370 | else if (thread->type == DMA_XOR) { |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 371 | /* force odd to ensure dst = src */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 372 | src_cnt = min_odd(params->xor_sources | 1, dev->max_xor); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 373 | dst_cnt = 1; |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 374 | } else if (thread->type == DMA_PQ) { |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 375 | /* force odd to ensure dst = src */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 376 | src_cnt = min_odd(params->pq_sources | 1, dma_maxpq(dev, 0)); |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 377 | dst_cnt = 2; |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 378 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 379 | pq_coefs = kmalloc(params->pq_sources+1, GFP_KERNEL); |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 380 | if (!pq_coefs) |
| 381 | goto err_thread_type; |
| 382 | |
Anatolij Gustschin | 94de648 | 2010-02-15 22:35:23 +0100 | [diff] [blame] | 383 | for (i = 0; i < src_cnt; i++) |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 384 | pq_coefs[i] = 1; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 385 | } else |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 386 | goto err_thread_type; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 387 | |
| 388 | thread->srcs = kcalloc(src_cnt+1, sizeof(u8 *), GFP_KERNEL); |
| 389 | if (!thread->srcs) |
| 390 | goto err_srcs; |
| 391 | for (i = 0; i < src_cnt; i++) { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 392 | thread->srcs[i] = kmalloc(params->buf_size, GFP_KERNEL); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 393 | if (!thread->srcs[i]) |
| 394 | goto err_srcbuf; |
| 395 | } |
| 396 | thread->srcs[i] = NULL; |
| 397 | |
| 398 | thread->dsts = kcalloc(dst_cnt+1, sizeof(u8 *), GFP_KERNEL); |
| 399 | if (!thread->dsts) |
| 400 | goto err_dsts; |
| 401 | for (i = 0; i < dst_cnt; i++) { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 402 | thread->dsts[i] = kmalloc(params->buf_size, GFP_KERNEL); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 403 | if (!thread->dsts[i]) |
| 404 | goto err_dstbuf; |
| 405 | } |
| 406 | thread->dsts[i] = NULL; |
| 407 | |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 408 | set_user_nice(current, 10); |
| 409 | |
Ira Snyder | b203bd3 | 2011-03-03 07:54:53 +0000 | [diff] [blame] | 410 | /* |
Bartlomiej Zolnierkiewicz | d1cab34 | 2013-10-18 19:35:21 +0200 | [diff] [blame] | 411 | * src and dst buffers are freed by ourselves below |
Ira Snyder | b203bd3 | 2011-03-03 07:54:53 +0000 | [diff] [blame] | 412 | */ |
Bartlomiej Zolnierkiewicz | 0776ae7 | 2013-10-18 19:35:33 +0200 | [diff] [blame] | 413 | flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 414 | |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 415 | while (!kthread_should_stop() |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 416 | && !(params->iterations && total_tests >= params->iterations)) { |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 417 | struct dma_async_tx_descriptor *tx = NULL; |
| 418 | dma_addr_t dma_srcs[src_cnt]; |
| 419 | dma_addr_t dma_dsts[dst_cnt]; |
Dan Williams | 83544ae | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 420 | u8 align = 0; |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 421 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 422 | total_tests++; |
| 423 | |
Dan Williams | 83544ae | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 424 | /* honor alignment restrictions */ |
| 425 | if (thread->type == DMA_MEMCPY) |
| 426 | align = dev->copy_align; |
| 427 | else if (thread->type == DMA_XOR) |
| 428 | align = dev->xor_align; |
| 429 | else if (thread->type == DMA_PQ) |
| 430 | align = dev->pq_align; |
| 431 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 432 | if (1 << align > params->buf_size) { |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 433 | pr_err("%u-byte buffer too small for %d-byte alignment\n", |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 434 | params->buf_size, 1 << align); |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 435 | break; |
| 436 | } |
| 437 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 438 | len = dmatest_random() % params->buf_size + 1; |
Dan Williams | 83544ae | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 439 | len = (len >> align) << align; |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 440 | if (!len) |
| 441 | len = 1 << align; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 442 | src_off = dmatest_random() % (params->buf_size - len + 1); |
| 443 | dst_off = dmatest_random() % (params->buf_size - len + 1); |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 444 | |
Dan Williams | 83544ae | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 445 | src_off = (src_off >> align) << align; |
| 446 | dst_off = (dst_off >> align) << align; |
| 447 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 448 | dmatest_init_srcs(thread->srcs, src_off, len, params->buf_size); |
| 449 | dmatest_init_dsts(thread->dsts, dst_off, len, params->buf_size); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 450 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 451 | for (i = 0; i < src_cnt; i++) { |
| 452 | u8 *buf = thread->srcs[i] + src_off; |
| 453 | |
| 454 | dma_srcs[i] = dma_map_single(dev->dev, buf, len, |
| 455 | DMA_TO_DEVICE); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 456 | ret = dma_mapping_error(dev->dev, dma_srcs[i]); |
| 457 | if (ret) { |
| 458 | unmap_src(dev->dev, dma_srcs, len, i); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 459 | result("src mapping error", total_tests, |
| 460 | src_off, dst_off, len, ret); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 461 | failed_tests++; |
| 462 | continue; |
| 463 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 464 | } |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 465 | /* map with DMA_BIDIRECTIONAL to force writeback/invalidate */ |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 466 | for (i = 0; i < dst_cnt; i++) { |
| 467 | dma_dsts[i] = dma_map_single(dev->dev, thread->dsts[i], |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 468 | params->buf_size, |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 469 | DMA_BIDIRECTIONAL); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 470 | ret = dma_mapping_error(dev->dev, dma_dsts[i]); |
| 471 | if (ret) { |
| 472 | unmap_src(dev->dev, dma_srcs, len, src_cnt); |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 473 | unmap_dst(dev->dev, dma_dsts, params->buf_size, |
| 474 | i); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 475 | result("dst mapping error", total_tests, |
| 476 | src_off, dst_off, len, ret); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 477 | failed_tests++; |
| 478 | continue; |
| 479 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 480 | } |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 481 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 482 | if (thread->type == DMA_MEMCPY) |
| 483 | tx = dev->device_prep_dma_memcpy(chan, |
| 484 | dma_dsts[0] + dst_off, |
| 485 | dma_srcs[0], len, |
| 486 | flags); |
| 487 | else if (thread->type == DMA_XOR) |
| 488 | tx = dev->device_prep_dma_xor(chan, |
| 489 | dma_dsts[0] + dst_off, |
Dan Williams | 67b9124 | 2010-02-28 22:20:18 -0700 | [diff] [blame] | 490 | dma_srcs, src_cnt, |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 491 | len, flags); |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 492 | else if (thread->type == DMA_PQ) { |
| 493 | dma_addr_t dma_pq[dst_cnt]; |
| 494 | |
| 495 | for (i = 0; i < dst_cnt; i++) |
| 496 | dma_pq[i] = dma_dsts[i] + dst_off; |
| 497 | tx = dev->device_prep_dma_pq(chan, dma_pq, dma_srcs, |
Anatolij Gustschin | 94de648 | 2010-02-15 22:35:23 +0100 | [diff] [blame] | 498 | src_cnt, pq_coefs, |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 499 | len, flags); |
| 500 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 501 | |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 502 | if (!tx) { |
Andy Shevchenko | 632fd28 | 2012-12-17 15:59:52 -0800 | [diff] [blame] | 503 | unmap_src(dev->dev, dma_srcs, len, src_cnt); |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 504 | unmap_dst(dev->dev, dma_dsts, params->buf_size, |
| 505 | dst_cnt); |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 506 | result("prep error", total_tests, src_off, |
| 507 | dst_off, len, ret); |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 508 | msleep(100); |
| 509 | failed_tests++; |
| 510 | continue; |
| 511 | } |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 512 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 513 | done.done = false; |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 514 | tx->callback = dmatest_callback; |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 515 | tx->callback_param = &done; |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 516 | cookie = tx->tx_submit(tx); |
| 517 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 518 | if (dma_submit_error(cookie)) { |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 519 | result("submit error", total_tests, src_off, |
| 520 | dst_off, len, ret); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 521 | msleep(100); |
| 522 | failed_tests++; |
| 523 | continue; |
| 524 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 525 | dma_async_issue_pending(chan); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 526 | |
Andy Shevchenko | bcc567e | 2013-05-23 14:29:53 +0300 | [diff] [blame] | 527 | wait_event_freezable_timeout(done_wait, done.done, |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 528 | msecs_to_jiffies(params->timeout)); |
Guennadi Liakhovetski | 981ed70 | 2011-08-18 16:50:51 +0200 | [diff] [blame] | 529 | |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 530 | status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 531 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 532 | if (!done.done) { |
| 533 | /* |
| 534 | * We're leaving the timed out dma operation with |
| 535 | * dangling pointer to done_wait. To make this |
| 536 | * correct, we'll need to allocate wait_done for |
| 537 | * each test iteration and perform "who's gonna |
| 538 | * free it this time?" dancing. For now, just |
| 539 | * leave it dangling. |
| 540 | */ |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 541 | result("test timed out", total_tests, src_off, dst_off, |
| 542 | len, 0); |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 543 | failed_tests++; |
| 544 | continue; |
| 545 | } else if (status != DMA_SUCCESS) { |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 546 | result(status == DMA_ERROR ? |
| 547 | "completion error status" : |
| 548 | "completion busy status", total_tests, src_off, |
| 549 | dst_off, len, ret); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 550 | failed_tests++; |
| 551 | continue; |
| 552 | } |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 553 | |
Bartlomiej Zolnierkiewicz | d1cab34 | 2013-10-18 19:35:21 +0200 | [diff] [blame] | 554 | /* Unmap by myself */ |
| 555 | unmap_src(dev->dev, dma_srcs, len, src_cnt); |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 556 | unmap_dst(dev->dev, dma_dsts, params->buf_size, dst_cnt); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 557 | |
| 558 | error_count = 0; |
| 559 | |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 560 | pr_debug("%s: verifying source buffer...\n", current->comm); |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 561 | error_count += dmatest_verify(thread->srcs, 0, src_off, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 562 | 0, PATTERN_SRC, true); |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 563 | error_count += dmatest_verify(thread->srcs, src_off, |
| 564 | src_off + len, src_off, |
| 565 | PATTERN_SRC | PATTERN_COPY, true); |
| 566 | error_count += dmatest_verify(thread->srcs, src_off + len, |
| 567 | params->buf_size, src_off + len, |
| 568 | PATTERN_SRC, true); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 569 | |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 570 | pr_debug("%s: verifying dest buffer...\n", current->comm); |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 571 | error_count += dmatest_verify(thread->dsts, 0, dst_off, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 572 | 0, PATTERN_DST, false); |
Dan Williams | 7b61017 | 2013-11-06 16:29:57 -0800 | [diff] [blame] | 573 | error_count += dmatest_verify(thread->dsts, dst_off, |
| 574 | dst_off + len, src_off, |
| 575 | PATTERN_SRC | PATTERN_COPY, false); |
| 576 | error_count += dmatest_verify(thread->dsts, dst_off + len, |
| 577 | params->buf_size, dst_off + len, |
| 578 | PATTERN_DST, false); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 579 | |
| 580 | if (error_count) { |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 581 | result("data error", total_tests, src_off, dst_off, |
| 582 | len, error_count); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 583 | failed_tests++; |
| 584 | } else { |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 585 | dbg_result("test passed", total_tests, src_off, dst_off, |
| 586 | len, 0); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
| 590 | ret = 0; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 591 | for (i = 0; thread->dsts[i]; i++) |
| 592 | kfree(thread->dsts[i]); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 593 | err_dstbuf: |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 594 | kfree(thread->dsts); |
| 595 | err_dsts: |
| 596 | for (i = 0; thread->srcs[i]; i++) |
| 597 | kfree(thread->srcs[i]); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 598 | err_srcbuf: |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 599 | kfree(thread->srcs); |
| 600 | err_srcs: |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 601 | kfree(pq_coefs); |
| 602 | err_thread_type: |
Dan Williams | 872f05c | 2013-11-06 16:29:58 -0800 | [diff] [blame] | 603 | pr_info("%s: terminating after %u tests, %u failures (status %d)\n", |
| 604 | current->comm, total_tests, failed_tests, ret); |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 605 | |
Viresh Kumar | 9704efa | 2011-07-29 16:21:57 +0530 | [diff] [blame] | 606 | /* terminate all transfers on specified channels */ |
Shiraz Hashim | 5e034f7 | 2012-11-09 15:26:29 +0000 | [diff] [blame] | 607 | if (ret) |
| 608 | dmaengine_terminate_all(chan); |
| 609 | |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 610 | thread->done = true; |
| 611 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 612 | if (params->iterations > 0) |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 613 | while (!kthread_should_stop()) { |
Yong Zhang | b953df7 | 2010-02-05 21:52:37 +0800 | [diff] [blame] | 614 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit); |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 615 | interruptible_sleep_on(&wait_dmatest_exit); |
| 616 | } |
| 617 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 618 | return ret; |
| 619 | } |
| 620 | |
| 621 | static void dmatest_cleanup_channel(struct dmatest_chan *dtc) |
| 622 | { |
| 623 | struct dmatest_thread *thread; |
| 624 | struct dmatest_thread *_thread; |
| 625 | int ret; |
| 626 | |
| 627 | list_for_each_entry_safe(thread, _thread, &dtc->threads, node) { |
| 628 | ret = kthread_stop(thread->task); |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 629 | pr_debug("thread %s exited with status %d\n", |
| 630 | thread->task->comm, ret); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 631 | list_del(&thread->node); |
| 632 | kfree(thread); |
| 633 | } |
Viresh Kumar | 9704efa | 2011-07-29 16:21:57 +0530 | [diff] [blame] | 634 | |
| 635 | /* terminate all transfers on specified channels */ |
Jon Mason | 944ea4d | 2012-11-11 23:03:20 +0000 | [diff] [blame] | 636 | dmaengine_terminate_all(dtc->chan); |
Viresh Kumar | 9704efa | 2011-07-29 16:21:57 +0530 | [diff] [blame] | 637 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 638 | kfree(dtc); |
| 639 | } |
| 640 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 641 | static int dmatest_add_threads(struct dmatest_info *info, |
| 642 | struct dmatest_chan *dtc, enum dma_transaction_type type) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 643 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 644 | struct dmatest_params *params = &info->params; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 645 | struct dmatest_thread *thread; |
| 646 | struct dma_chan *chan = dtc->chan; |
| 647 | char *op; |
| 648 | unsigned int i; |
| 649 | |
| 650 | if (type == DMA_MEMCPY) |
| 651 | op = "copy"; |
| 652 | else if (type == DMA_XOR) |
| 653 | op = "xor"; |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 654 | else if (type == DMA_PQ) |
| 655 | op = "pq"; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 656 | else |
| 657 | return -EINVAL; |
| 658 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 659 | for (i = 0; i < params->threads_per_chan; i++) { |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 660 | thread = kzalloc(sizeof(struct dmatest_thread), GFP_KERNEL); |
| 661 | if (!thread) { |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 662 | pr_warn("No memory for %s-%s%u\n", |
| 663 | dma_chan_name(chan), op, i); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 664 | break; |
| 665 | } |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 666 | thread->info = info; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 667 | thread->chan = dtc->chan; |
| 668 | thread->type = type; |
| 669 | smp_wmb(); |
| 670 | thread->task = kthread_run(dmatest_func, thread, "%s-%s%u", |
| 671 | dma_chan_name(chan), op, i); |
| 672 | if (IS_ERR(thread->task)) { |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 673 | pr_warn("Failed to run thread %s-%s%u\n", |
| 674 | dma_chan_name(chan), op, i); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 675 | kfree(thread); |
| 676 | break; |
| 677 | } |
| 678 | |
| 679 | /* srcbuf and dstbuf are allocated by the thread itself */ |
| 680 | |
| 681 | list_add_tail(&thread->node, &dtc->threads); |
| 682 | } |
| 683 | |
| 684 | return i; |
| 685 | } |
| 686 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 687 | static int dmatest_add_channel(struct dmatest_info *info, |
| 688 | struct dma_chan *chan) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 689 | { |
| 690 | struct dmatest_chan *dtc; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 691 | struct dma_device *dma_dev = chan->device; |
| 692 | unsigned int thread_count = 0; |
Kulikov Vasiliy | b9033e6 | 2010-07-17 19:19:48 +0400 | [diff] [blame] | 693 | int cnt; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 694 | |
Andrew Morton | 6fdb8bd | 2008-09-19 04:16:23 -0700 | [diff] [blame] | 695 | dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 696 | if (!dtc) { |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 697 | pr_warn("No memory for %s\n", dma_chan_name(chan)); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 698 | return -ENOMEM; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | dtc->chan = chan; |
| 702 | INIT_LIST_HEAD(&dtc->threads); |
| 703 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 704 | if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 705 | cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY); |
Nicolas Ferre | f1aef8b | 2009-07-06 18:19:44 +0200 | [diff] [blame] | 706 | thread_count += cnt > 0 ? cnt : 0; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 707 | } |
| 708 | if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 709 | cnt = dmatest_add_threads(info, dtc, DMA_XOR); |
Nicolas Ferre | f1aef8b | 2009-07-06 18:19:44 +0200 | [diff] [blame] | 710 | thread_count += cnt > 0 ? cnt : 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 711 | } |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 712 | if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 713 | cnt = dmatest_add_threads(info, dtc, DMA_PQ); |
Dr. David Alan Gilbert | d07a74a | 2011-08-25 16:13:55 -0700 | [diff] [blame] | 714 | thread_count += cnt > 0 ? cnt : 0; |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 715 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 716 | |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 717 | pr_info("Started %u threads using %s\n", |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 718 | thread_count, dma_chan_name(chan)); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 719 | |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 720 | list_add_tail(&dtc->node, &info->channels); |
| 721 | info->nr_channels++; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 722 | |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 723 | return 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Dan Williams | 7dd6025 | 2009-01-06 11:38:19 -0700 | [diff] [blame] | 726 | static bool filter(struct dma_chan *chan, void *param) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 727 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 728 | struct dmatest_params *params = param; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 729 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 730 | if (!dmatest_match_channel(params, chan) || |
| 731 | !dmatest_match_device(params, chan->device)) |
Dan Williams | 7dd6025 | 2009-01-06 11:38:19 -0700 | [diff] [blame] | 732 | return false; |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 733 | else |
Dan Williams | 7dd6025 | 2009-01-06 11:38:19 -0700 | [diff] [blame] | 734 | return true; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame^] | 737 | static void request_channels(struct dmatest_info *info, |
| 738 | enum dma_transaction_type type) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 739 | { |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 740 | dma_cap_mask_t mask; |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame^] | 741 | |
| 742 | dma_cap_zero(mask); |
| 743 | dma_cap_set(type, mask); |
| 744 | for (;;) { |
| 745 | struct dmatest_params *params = &info->params; |
| 746 | struct dma_chan *chan; |
| 747 | |
| 748 | chan = dma_request_channel(mask, filter, params); |
| 749 | if (chan) { |
| 750 | if (dmatest_add_channel(info, chan)) { |
| 751 | dma_release_channel(chan); |
| 752 | break; /* add_channel failed, punt */ |
| 753 | } |
| 754 | } else |
| 755 | break; /* no more channels available */ |
| 756 | if (params->max_channels && |
| 757 | info->nr_channels >= params->max_channels) |
| 758 | break; /* we have all we need */ |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | static void run_threaded_test(struct dmatest_info *info) |
| 763 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 764 | struct dmatest_params *params = &info->params; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 765 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 766 | /* Copy test parameters */ |
| 767 | params->buf_size = test_buf_size; |
| 768 | strlcpy(params->channel, strim(test_channel), sizeof(params->channel)); |
| 769 | strlcpy(params->device, strim(test_device), sizeof(params->device)); |
| 770 | params->threads_per_chan = threads_per_chan; |
| 771 | params->max_channels = max_channels; |
| 772 | params->iterations = iterations; |
| 773 | params->xor_sources = xor_sources; |
| 774 | params->pq_sources = pq_sources; |
| 775 | params->timeout = timeout; |
| 776 | |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame^] | 777 | request_channels(info, DMA_MEMCPY); |
| 778 | request_channels(info, DMA_XOR); |
| 779 | request_channels(info, DMA_PQ); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 780 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 781 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 782 | static void stop_threaded_test(struct dmatest_info *info) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 783 | { |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 784 | struct dmatest_chan *dtc, *_dtc; |
Dan Williams | 7cbd487 | 2009-03-04 16:06:03 -0700 | [diff] [blame] | 785 | struct dma_chan *chan; |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 786 | |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 787 | list_for_each_entry_safe(dtc, _dtc, &info->channels, node) { |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 788 | list_del(&dtc->node); |
Dan Williams | 7cbd487 | 2009-03-04 16:06:03 -0700 | [diff] [blame] | 789 | chan = dtc->chan; |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 790 | dmatest_cleanup_channel(dtc); |
Dan Williams | 0adff80 | 2013-11-06 16:30:00 -0800 | [diff] [blame] | 791 | pr_debug("dropped channel %s\n", dma_chan_name(chan)); |
Dan Williams | 7cbd487 | 2009-03-04 16:06:03 -0700 | [diff] [blame] | 792 | dma_release_channel(chan); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 793 | } |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 794 | |
| 795 | info->nr_channels = 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 796 | } |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 797 | |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame^] | 798 | static void restart_threaded_test(struct dmatest_info *info, bool run) |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 799 | { |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 800 | /* we might be called early to set run=, defer running until all |
| 801 | * parameters have been evaluated |
| 802 | */ |
| 803 | if (!info->did_init) |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame^] | 804 | return; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 805 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 806 | /* Stop any running test first */ |
| 807 | stop_threaded_test(info); |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 808 | |
| 809 | /* Run test with new parameters */ |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame^] | 810 | run_threaded_test(info); |
Andy Shevchenko | bcc567e | 2013-05-23 14:29:53 +0300 | [diff] [blame] | 811 | } |
| 812 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 813 | static bool is_threaded_test_run(struct dmatest_info *info) |
Andy Shevchenko | bcc567e | 2013-05-23 14:29:53 +0300 | [diff] [blame] | 814 | { |
| 815 | struct dmatest_chan *dtc; |
| 816 | |
| 817 | list_for_each_entry(dtc, &info->channels, node) { |
| 818 | struct dmatest_thread *thread; |
| 819 | |
| 820 | list_for_each_entry(thread, &dtc->threads, node) { |
| 821 | if (!thread->done) |
| 822 | return true; |
| 823 | } |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 824 | } |
| 825 | |
Andy Shevchenko | bcc567e | 2013-05-23 14:29:53 +0300 | [diff] [blame] | 826 | return false; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 827 | } |
| 828 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 829 | static int dmatest_run_get(char *val, const struct kernel_param *kp) |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 830 | { |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 831 | struct dmatest_info *info = &test_info; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 832 | |
| 833 | mutex_lock(&info->lock); |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 834 | if (is_threaded_test_run(info)) { |
| 835 | dmatest_run = true; |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 836 | } else { |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 837 | stop_threaded_test(info); |
| 838 | dmatest_run = false; |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 839 | } |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 840 | mutex_unlock(&info->lock); |
| 841 | |
| 842 | return param_get_bool(val, kp); |
| 843 | } |
| 844 | |
| 845 | static int dmatest_run_set(const char *val, const struct kernel_param *kp) |
| 846 | { |
| 847 | struct dmatest_info *info = &test_info; |
| 848 | int ret; |
| 849 | |
| 850 | mutex_lock(&info->lock); |
| 851 | ret = param_set_bool(val, kp); |
| 852 | if (ret) { |
| 853 | mutex_unlock(&info->lock); |
| 854 | return ret; |
| 855 | } |
| 856 | |
| 857 | if (is_threaded_test_run(info)) |
| 858 | ret = -EBUSY; |
| 859 | else if (dmatest_run) |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame^] | 860 | restart_threaded_test(info, dmatest_run); |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 861 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 862 | mutex_unlock(&info->lock); |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 863 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 864 | return ret; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 865 | } |
| 866 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 867 | static int __init dmatest_init(void) |
| 868 | { |
| 869 | struct dmatest_info *info = &test_info; |
| 870 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 871 | if (dmatest_run) { |
| 872 | mutex_lock(&info->lock); |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame^] | 873 | run_threaded_test(info); |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 874 | mutex_unlock(&info->lock); |
| 875 | } |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 876 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 877 | /* module parameters are stable, inittime tests are started, |
| 878 | * let userspace take over 'run' control |
| 879 | */ |
| 880 | info->did_init = true; |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 881 | |
Dan Williams | a9e5549 | 2013-11-06 16:30:02 -0800 | [diff] [blame^] | 882 | return 0; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 883 | } |
| 884 | /* when compiled-in wait for drivers to load first */ |
| 885 | late_initcall(dmatest_init); |
| 886 | |
| 887 | static void __exit dmatest_exit(void) |
| 888 | { |
| 889 | struct dmatest_info *info = &test_info; |
| 890 | |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 891 | mutex_lock(&info->lock); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 892 | stop_threaded_test(info); |
Dan Williams | a310d03 | 2013-11-06 16:30:01 -0800 | [diff] [blame] | 893 | mutex_unlock(&info->lock); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 894 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 895 | module_exit(dmatest_exit); |
| 896 | |
Jean Delvare | e05503e | 2011-05-18 16:49:24 +0200 | [diff] [blame] | 897 | MODULE_AUTHOR("Haavard Skinnemoen (Atmel)"); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 898 | MODULE_LICENSE("GPL v2"); |