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