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 | */ |
| 11 | #include <linux/delay.h> |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 12 | #include <linux/dma-mapping.h> |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 13 | #include <linux/dmaengine.h> |
Guennadi Liakhovetski | 981ed70 | 2011-08-18 16:50:51 +0200 | [diff] [blame] | 14 | #include <linux/freezer.h> |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/kthread.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/moduleparam.h> |
| 19 | #include <linux/random.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 21 | #include <linux/wait.h> |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 22 | #include <linux/ctype.h> |
| 23 | #include <linux/debugfs.h> |
| 24 | #include <linux/uaccess.h> |
| 25 | #include <linux/seq_file.h> |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 26 | |
| 27 | static unsigned int test_buf_size = 16384; |
| 28 | module_param(test_buf_size, uint, S_IRUGO); |
| 29 | MODULE_PARM_DESC(test_buf_size, "Size of the memcpy test buffer"); |
| 30 | |
Kay Sievers | 06190d8 | 2008-11-11 13:12:33 -0700 | [diff] [blame] | 31 | static char test_channel[20]; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 32 | module_param_string(channel, test_channel, sizeof(test_channel), S_IRUGO); |
| 33 | MODULE_PARM_DESC(channel, "Bus ID of the channel to test (default: any)"); |
| 34 | |
Kay Sievers | 06190d8 | 2008-11-11 13:12:33 -0700 | [diff] [blame] | 35 | static char test_device[20]; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 36 | module_param_string(device, test_device, sizeof(test_device), S_IRUGO); |
| 37 | MODULE_PARM_DESC(device, "Bus ID of the DMA Engine to test (default: any)"); |
| 38 | |
| 39 | static unsigned int threads_per_chan = 1; |
| 40 | module_param(threads_per_chan, uint, S_IRUGO); |
| 41 | MODULE_PARM_DESC(threads_per_chan, |
| 42 | "Number of threads to start per channel (default: 1)"); |
| 43 | |
| 44 | static unsigned int max_channels; |
| 45 | module_param(max_channels, uint, S_IRUGO); |
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; |
| 50 | module_param(iterations, uint, S_IRUGO); |
| 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; |
| 55 | module_param(xor_sources, uint, S_IRUGO); |
| 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; |
| 60 | module_param(pq_sources, uint, S_IRUGO); |
| 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; |
| 65 | module_param(timeout, uint, S_IRUGO); |
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 | 74b5c07 | 2013-03-04 11:09:32 +0200 | [diff] [blame] | 69 | /* Maximum amount of mismatched bytes in buffer to print */ |
| 70 | #define MAX_ERROR_COUNT 32 |
| 71 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 72 | /* |
| 73 | * Initialization patterns. All bytes in the source buffer has bit 7 |
| 74 | * set, all bytes in the destination buffer has bit 7 cleared. |
| 75 | * |
| 76 | * Bit 6 is set for all bytes which are to be copied by the DMA |
| 77 | * engine. Bit 5 is set for all bytes which are to be overwritten by |
| 78 | * the DMA engine. |
| 79 | * |
| 80 | * The remaining bits are the inverse of a counter which increments by |
| 81 | * one for each byte address. |
| 82 | */ |
| 83 | #define PATTERN_SRC 0x80 |
| 84 | #define PATTERN_DST 0x00 |
| 85 | #define PATTERN_COPY 0x40 |
| 86 | #define PATTERN_OVERWRITE 0x20 |
| 87 | #define PATTERN_COUNT_MASK 0x1f |
| 88 | |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 89 | enum dmatest_error_type { |
| 90 | DMATEST_ET_OK, |
| 91 | DMATEST_ET_MAP_SRC, |
| 92 | DMATEST_ET_MAP_DST, |
| 93 | DMATEST_ET_PREP, |
| 94 | DMATEST_ET_SUBMIT, |
| 95 | DMATEST_ET_TIMEOUT, |
| 96 | DMATEST_ET_DMA_ERROR, |
| 97 | DMATEST_ET_DMA_IN_PROGRESS, |
| 98 | DMATEST_ET_VERIFY, |
| 99 | }; |
| 100 | |
| 101 | struct dmatest_thread_result { |
| 102 | struct list_head node; |
| 103 | unsigned int n; |
| 104 | unsigned int src_off; |
| 105 | unsigned int dst_off; |
| 106 | unsigned int len; |
| 107 | enum dmatest_error_type type; |
| 108 | union { |
| 109 | unsigned long data; |
| 110 | dma_cookie_t cookie; |
| 111 | enum dma_status status; |
| 112 | int error; |
| 113 | }; |
| 114 | }; |
| 115 | |
| 116 | struct dmatest_result { |
| 117 | struct list_head node; |
| 118 | char *name; |
| 119 | struct list_head results; |
| 120 | }; |
| 121 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 122 | struct dmatest_info; |
| 123 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 124 | struct dmatest_thread { |
| 125 | struct list_head node; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 126 | struct dmatest_info *info; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 127 | struct task_struct *task; |
| 128 | struct dma_chan *chan; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 129 | u8 **srcs; |
| 130 | u8 **dsts; |
| 131 | enum dma_transaction_type type; |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 132 | bool done; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | struct dmatest_chan { |
| 136 | struct list_head node; |
| 137 | struct dma_chan *chan; |
| 138 | struct list_head threads; |
| 139 | }; |
| 140 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 141 | /** |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 142 | * struct dmatest_params - test parameters. |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 143 | * @buf_size: size of the memcpy test buffer |
| 144 | * @channel: bus ID of the channel to test |
| 145 | * @device: bus ID of the DMA Engine to test |
| 146 | * @threads_per_chan: number of threads to start per channel |
| 147 | * @max_channels: maximum number of channels to use |
| 148 | * @iterations: iterations before stopping test |
| 149 | * @xor_sources: number of xor source buffers |
| 150 | * @pq_sources: number of p+q source buffers |
| 151 | * @timeout: transfer timeout in msec, -1 for infinite timeout |
| 152 | */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 153 | struct dmatest_params { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 154 | unsigned int buf_size; |
| 155 | char channel[20]; |
| 156 | char device[20]; |
| 157 | unsigned int threads_per_chan; |
| 158 | unsigned int max_channels; |
| 159 | unsigned int iterations; |
| 160 | unsigned int xor_sources; |
| 161 | unsigned int pq_sources; |
| 162 | int timeout; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | /** |
| 166 | * struct dmatest_info - test information. |
| 167 | * @params: test parameters |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 168 | * @lock: access protection to the fields of this structure |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 169 | */ |
| 170 | struct dmatest_info { |
| 171 | /* Test parameters */ |
| 172 | struct dmatest_params params; |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 173 | |
| 174 | /* Internal state */ |
| 175 | struct list_head channels; |
| 176 | unsigned int nr_channels; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 177 | struct mutex lock; |
| 178 | |
| 179 | /* debugfs related stuff */ |
| 180 | struct dentry *root; |
| 181 | struct dmatest_params dbgfs_params; |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 182 | |
| 183 | /* Test results */ |
| 184 | struct list_head results; |
| 185 | struct mutex results_lock; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | static struct dmatest_info test_info; |
| 189 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 190 | static bool dmatest_match_channel(struct dmatest_params *params, |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 191 | struct dma_chan *chan) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 192 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 193 | if (params->channel[0] == '\0') |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 194 | return true; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 195 | return strcmp(dma_chan_name(chan), params->channel) == 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 198 | static bool dmatest_match_device(struct dmatest_params *params, |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 199 | struct dma_device *device) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 200 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 201 | if (params->device[0] == '\0') |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 202 | return true; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 203 | return strcmp(dev_name(device->dev), params->device) == 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static unsigned long dmatest_random(void) |
| 207 | { |
| 208 | unsigned long buf; |
| 209 | |
| 210 | get_random_bytes(&buf, sizeof(buf)); |
| 211 | return buf; |
| 212 | } |
| 213 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 214 | static void dmatest_init_srcs(u8 **bufs, unsigned int start, unsigned int len, |
| 215 | unsigned int buf_size) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 216 | { |
| 217 | unsigned int i; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 218 | u8 *buf; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 219 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 220 | for (; (buf = *bufs); bufs++) { |
| 221 | for (i = 0; i < start; i++) |
| 222 | buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK); |
| 223 | for ( ; i < start + len; i++) |
| 224 | buf[i] = PATTERN_SRC | PATTERN_COPY |
Joe Perches | c019894 | 2009-06-28 09:26:21 -0700 | [diff] [blame] | 225 | | (~i & PATTERN_COUNT_MASK); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 226 | for ( ; i < buf_size; i++) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 227 | buf[i] = PATTERN_SRC | (~i & PATTERN_COUNT_MASK); |
| 228 | buf++; |
| 229 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 232 | static void dmatest_init_dsts(u8 **bufs, unsigned int start, unsigned int len, |
| 233 | unsigned int buf_size) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 234 | { |
| 235 | unsigned int i; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 236 | u8 *buf; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 237 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 238 | for (; (buf = *bufs); bufs++) { |
| 239 | for (i = 0; i < start; i++) |
| 240 | buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK); |
| 241 | for ( ; i < start + len; i++) |
| 242 | buf[i] = PATTERN_DST | PATTERN_OVERWRITE |
| 243 | | (~i & PATTERN_COUNT_MASK); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 244 | for ( ; i < buf_size; i++) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 245 | buf[i] = PATTERN_DST | (~i & PATTERN_COUNT_MASK); |
| 246 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index, |
| 250 | unsigned int counter, bool is_srcbuf) |
| 251 | { |
| 252 | u8 diff = actual ^ pattern; |
| 253 | u8 expected = pattern | (~counter & PATTERN_COUNT_MASK); |
| 254 | const char *thread_name = current->comm; |
| 255 | |
| 256 | if (is_srcbuf) |
| 257 | pr_warning("%s: srcbuf[0x%x] overwritten!" |
| 258 | " Expected %02x, got %02x\n", |
| 259 | thread_name, index, expected, actual); |
| 260 | else if ((pattern & PATTERN_COPY) |
| 261 | && (diff & (PATTERN_COPY | PATTERN_OVERWRITE))) |
| 262 | pr_warning("%s: dstbuf[0x%x] not copied!" |
| 263 | " Expected %02x, got %02x\n", |
| 264 | thread_name, index, expected, actual); |
| 265 | else if (diff & PATTERN_SRC) |
| 266 | pr_warning("%s: dstbuf[0x%x] was copied!" |
| 267 | " Expected %02x, got %02x\n", |
| 268 | thread_name, index, expected, actual); |
| 269 | else |
| 270 | pr_warning("%s: dstbuf[0x%x] mismatch!" |
| 271 | " Expected %02x, got %02x\n", |
| 272 | thread_name, index, expected, actual); |
| 273 | } |
| 274 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 275 | static unsigned int dmatest_verify(u8 **bufs, unsigned int start, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 276 | unsigned int end, unsigned int counter, u8 pattern, |
| 277 | bool is_srcbuf) |
| 278 | { |
| 279 | unsigned int i; |
| 280 | unsigned int error_count = 0; |
| 281 | u8 actual; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 282 | u8 expected; |
| 283 | u8 *buf; |
| 284 | unsigned int counter_orig = counter; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 285 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 286 | for (; (buf = *bufs); bufs++) { |
| 287 | counter = counter_orig; |
| 288 | for (i = start; i < end; i++) { |
| 289 | actual = buf[i]; |
| 290 | expected = pattern | (~counter & PATTERN_COUNT_MASK); |
| 291 | if (actual != expected) { |
Andy Shevchenko | 74b5c07 | 2013-03-04 11:09:32 +0200 | [diff] [blame] | 292 | if (error_count < MAX_ERROR_COUNT) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 293 | dmatest_mismatch(actual, pattern, i, |
| 294 | counter, is_srcbuf); |
| 295 | error_count++; |
| 296 | } |
| 297 | counter++; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 298 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Andy Shevchenko | 74b5c07 | 2013-03-04 11:09:32 +0200 | [diff] [blame] | 301 | if (error_count > MAX_ERROR_COUNT) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 302 | pr_warning("%s: %u errors suppressed\n", |
Andy Shevchenko | 74b5c07 | 2013-03-04 11:09:32 +0200 | [diff] [blame] | 303 | current->comm, error_count - MAX_ERROR_COUNT); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 304 | |
| 305 | return error_count; |
| 306 | } |
| 307 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 308 | /* poor man's completion - we want to use wait_event_freezable() on it */ |
| 309 | struct dmatest_done { |
| 310 | bool done; |
| 311 | wait_queue_head_t *wait; |
| 312 | }; |
| 313 | |
| 314 | static void dmatest_callback(void *arg) |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 315 | { |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 316 | struct dmatest_done *done = arg; |
| 317 | |
| 318 | done->done = true; |
| 319 | wake_up_all(done->wait); |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Andy Shevchenko | 632fd28 | 2012-12-17 15:59:52 -0800 | [diff] [blame] | 322 | static inline void unmap_src(struct device *dev, dma_addr_t *addr, size_t len, |
| 323 | unsigned int count) |
| 324 | { |
| 325 | while (count--) |
| 326 | dma_unmap_single(dev, addr[count], len, DMA_TO_DEVICE); |
| 327 | } |
| 328 | |
| 329 | static inline void unmap_dst(struct device *dev, dma_addr_t *addr, size_t len, |
| 330 | unsigned int count) |
| 331 | { |
| 332 | while (count--) |
| 333 | dma_unmap_single(dev, addr[count], len, DMA_BIDIRECTIONAL); |
| 334 | } |
| 335 | |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 336 | static unsigned int min_odd(unsigned int x, unsigned int y) |
| 337 | { |
| 338 | unsigned int val = min(x, y); |
| 339 | |
| 340 | return val % 2 ? val : val - 1; |
| 341 | } |
| 342 | |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 343 | static char *thread_result_get(const char *name, |
| 344 | struct dmatest_thread_result *tr) |
| 345 | { |
| 346 | static const char * const messages[] = { |
| 347 | [DMATEST_ET_OK] = "No errors", |
| 348 | [DMATEST_ET_MAP_SRC] = "src mapping error", |
| 349 | [DMATEST_ET_MAP_DST] = "dst mapping error", |
| 350 | [DMATEST_ET_PREP] = "prep error", |
| 351 | [DMATEST_ET_SUBMIT] = "submit error", |
| 352 | [DMATEST_ET_TIMEOUT] = "test timed out", |
| 353 | [DMATEST_ET_DMA_ERROR] = |
| 354 | "got completion callback (DMA_ERROR)", |
| 355 | [DMATEST_ET_DMA_IN_PROGRESS] = |
| 356 | "got completion callback (DMA_IN_PROGRESS)", |
| 357 | [DMATEST_ET_VERIFY] = "errors", |
| 358 | }; |
| 359 | static char buf[512]; |
| 360 | |
| 361 | snprintf(buf, sizeof(buf) - 1, |
| 362 | "%s: #%u: %s with src_off=0x%x ""dst_off=0x%x len=0x%x (%lu)", |
| 363 | name, tr->n, messages[tr->type], tr->src_off, tr->dst_off, |
| 364 | tr->len, tr->data); |
| 365 | |
| 366 | return buf; |
| 367 | } |
| 368 | |
| 369 | static int thread_result_add(struct dmatest_info *info, |
| 370 | struct dmatest_result *r, enum dmatest_error_type type, |
| 371 | unsigned int n, unsigned int src_off, unsigned int dst_off, |
| 372 | unsigned int len, unsigned long data) |
| 373 | { |
| 374 | struct dmatest_thread_result *tr; |
| 375 | |
| 376 | tr = kzalloc(sizeof(*tr), GFP_KERNEL); |
| 377 | if (!tr) |
| 378 | return -ENOMEM; |
| 379 | |
| 380 | tr->type = type; |
| 381 | tr->n = n; |
| 382 | tr->src_off = src_off; |
| 383 | tr->dst_off = dst_off; |
| 384 | tr->len = len; |
| 385 | tr->data = data; |
| 386 | |
| 387 | mutex_lock(&info->results_lock); |
| 388 | list_add_tail(&tr->node, &r->results); |
| 389 | mutex_unlock(&info->results_lock); |
| 390 | |
| 391 | pr_warn("%s\n", thread_result_get(r->name, tr)); |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | static void result_free(struct dmatest_info *info, const char *name) |
| 396 | { |
| 397 | struct dmatest_result *r, *_r; |
| 398 | |
| 399 | mutex_lock(&info->results_lock); |
| 400 | list_for_each_entry_safe(r, _r, &info->results, node) { |
| 401 | struct dmatest_thread_result *tr, *_tr; |
| 402 | |
| 403 | if (name && strcmp(r->name, name)) |
| 404 | continue; |
| 405 | |
| 406 | list_for_each_entry_safe(tr, _tr, &r->results, node) { |
| 407 | list_del(&tr->node); |
| 408 | kfree(tr); |
| 409 | } |
| 410 | |
| 411 | kfree(r->name); |
| 412 | list_del(&r->node); |
| 413 | kfree(r); |
| 414 | } |
| 415 | |
| 416 | mutex_unlock(&info->results_lock); |
| 417 | } |
| 418 | |
| 419 | static struct dmatest_result *result_init(struct dmatest_info *info, |
| 420 | const char *name) |
| 421 | { |
| 422 | struct dmatest_result *r; |
| 423 | |
| 424 | r = kzalloc(sizeof(*r), GFP_KERNEL); |
| 425 | if (r) { |
| 426 | r->name = kstrdup(name, GFP_KERNEL); |
| 427 | INIT_LIST_HEAD(&r->results); |
| 428 | mutex_lock(&info->results_lock); |
| 429 | list_add_tail(&r->node, &info->results); |
| 430 | mutex_unlock(&info->results_lock); |
| 431 | } |
| 432 | return r; |
| 433 | } |
| 434 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 435 | /* |
| 436 | * This function repeatedly tests DMA transfers of various lengths and |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 437 | * offsets for a given operation type until it is told to exit by |
| 438 | * kthread_stop(). There may be multiple threads running this function |
| 439 | * in parallel for a single channel, and there may be multiple channels |
| 440 | * being tested in parallel. |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 441 | * |
| 442 | * Before each test, the source and destination buffer is initialized |
| 443 | * with a known pattern. This pattern is different depending on |
| 444 | * whether it's in an area which is supposed to be copied or |
| 445 | * overwritten, and different in the source and destination buffers. |
| 446 | * So if the DMA engine doesn't copy exactly what we tell it to copy, |
| 447 | * we'll notice. |
| 448 | */ |
| 449 | static int dmatest_func(void *data) |
| 450 | { |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 451 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_wait); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 452 | struct dmatest_thread *thread = data; |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 453 | struct dmatest_done done = { .wait = &done_wait }; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 454 | struct dmatest_info *info; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 455 | struct dmatest_params *params; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 456 | struct dma_chan *chan; |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 457 | struct dma_device *dev; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 458 | const char *thread_name; |
| 459 | unsigned int src_off, dst_off, len; |
| 460 | unsigned int error_count; |
| 461 | unsigned int failed_tests = 0; |
| 462 | unsigned int total_tests = 0; |
| 463 | dma_cookie_t cookie; |
| 464 | enum dma_status status; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 465 | enum dma_ctrl_flags flags; |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 466 | u8 *pq_coefs = NULL; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 467 | int ret; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 468 | int src_cnt; |
| 469 | int dst_cnt; |
| 470 | int i; |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 471 | struct dmatest_result *result; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 472 | |
| 473 | thread_name = current->comm; |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 474 | set_freezable(); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 475 | |
| 476 | ret = -ENOMEM; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 477 | |
| 478 | smp_rmb(); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 479 | info = thread->info; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 480 | params = &info->params; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 481 | chan = thread->chan; |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 482 | dev = chan->device; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 483 | if (thread->type == DMA_MEMCPY) |
| 484 | src_cnt = dst_cnt = 1; |
| 485 | else if (thread->type == DMA_XOR) { |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 486 | /* force odd to ensure dst = src */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 487 | src_cnt = min_odd(params->xor_sources | 1, dev->max_xor); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 488 | dst_cnt = 1; |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 489 | } else if (thread->type == DMA_PQ) { |
Akinobu Mita | 8be9e32b | 2012-10-28 00:49:32 +0900 | [diff] [blame] | 490 | /* force odd to ensure dst = src */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 491 | src_cnt = min_odd(params->pq_sources | 1, dma_maxpq(dev, 0)); |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 492 | dst_cnt = 2; |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 493 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 494 | pq_coefs = kmalloc(params->pq_sources+1, GFP_KERNEL); |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 495 | if (!pq_coefs) |
| 496 | goto err_thread_type; |
| 497 | |
Anatolij Gustschin | 94de648 | 2010-02-15 22:35:23 +0100 | [diff] [blame] | 498 | for (i = 0; i < src_cnt; i++) |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 499 | pq_coefs[i] = 1; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 500 | } else |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 501 | goto err_thread_type; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 502 | |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 503 | result = result_init(info, thread_name); |
| 504 | if (!result) |
| 505 | goto err_srcs; |
| 506 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 507 | thread->srcs = kcalloc(src_cnt+1, sizeof(u8 *), GFP_KERNEL); |
| 508 | if (!thread->srcs) |
| 509 | goto err_srcs; |
| 510 | for (i = 0; i < src_cnt; i++) { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 511 | thread->srcs[i] = kmalloc(params->buf_size, GFP_KERNEL); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 512 | if (!thread->srcs[i]) |
| 513 | goto err_srcbuf; |
| 514 | } |
| 515 | thread->srcs[i] = NULL; |
| 516 | |
| 517 | thread->dsts = kcalloc(dst_cnt+1, sizeof(u8 *), GFP_KERNEL); |
| 518 | if (!thread->dsts) |
| 519 | goto err_dsts; |
| 520 | for (i = 0; i < dst_cnt; i++) { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 521 | thread->dsts[i] = kmalloc(params->buf_size, GFP_KERNEL); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 522 | if (!thread->dsts[i]) |
| 523 | goto err_dstbuf; |
| 524 | } |
| 525 | thread->dsts[i] = NULL; |
| 526 | |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 527 | set_user_nice(current, 10); |
| 528 | |
Ira Snyder | b203bd3 | 2011-03-03 07:54:53 +0000 | [diff] [blame] | 529 | /* |
| 530 | * src buffers are freed by the DMAEngine code with dma_unmap_single() |
| 531 | * dst buffers are freed by ourselves below |
| 532 | */ |
| 533 | flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT |
| 534 | | DMA_COMPL_SKIP_DEST_UNMAP | DMA_COMPL_SRC_UNMAP_SINGLE; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 535 | |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 536 | while (!kthread_should_stop() |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 537 | && !(params->iterations && total_tests >= params->iterations)) { |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 538 | struct dma_async_tx_descriptor *tx = NULL; |
| 539 | dma_addr_t dma_srcs[src_cnt]; |
| 540 | dma_addr_t dma_dsts[dst_cnt]; |
Dan Williams | 83544ae | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 541 | u8 align = 0; |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 542 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 543 | total_tests++; |
| 544 | |
Dan Williams | 83544ae | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 545 | /* honor alignment restrictions */ |
| 546 | if (thread->type == DMA_MEMCPY) |
| 547 | align = dev->copy_align; |
| 548 | else if (thread->type == DMA_XOR) |
| 549 | align = dev->xor_align; |
| 550 | else if (thread->type == DMA_PQ) |
| 551 | align = dev->pq_align; |
| 552 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 553 | if (1 << align > params->buf_size) { |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 554 | pr_err("%u-byte buffer too small for %d-byte alignment\n", |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 555 | params->buf_size, 1 << align); |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 556 | break; |
| 557 | } |
| 558 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 559 | len = dmatest_random() % params->buf_size + 1; |
Dan Williams | 83544ae | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 560 | len = (len >> align) << align; |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 561 | if (!len) |
| 562 | len = 1 << align; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 563 | src_off = dmatest_random() % (params->buf_size - len + 1); |
| 564 | dst_off = dmatest_random() % (params->buf_size - len + 1); |
Guennadi Liakhovetski | cfe4f27 | 2009-12-04 19:44:48 +0100 | [diff] [blame] | 565 | |
Dan Williams | 83544ae | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 566 | src_off = (src_off >> align) << align; |
| 567 | dst_off = (dst_off >> align) << align; |
| 568 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 569 | dmatest_init_srcs(thread->srcs, src_off, len, params->buf_size); |
| 570 | dmatest_init_dsts(thread->dsts, dst_off, len, params->buf_size); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 571 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 572 | for (i = 0; i < src_cnt; i++) { |
| 573 | u8 *buf = thread->srcs[i] + src_off; |
| 574 | |
| 575 | dma_srcs[i] = dma_map_single(dev->dev, buf, len, |
| 576 | DMA_TO_DEVICE); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 577 | ret = dma_mapping_error(dev->dev, dma_srcs[i]); |
| 578 | if (ret) { |
| 579 | unmap_src(dev->dev, dma_srcs, len, i); |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 580 | thread_result_add(info, result, |
| 581 | DMATEST_ET_MAP_SRC, |
| 582 | total_tests, src_off, dst_off, |
| 583 | len, ret); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 584 | failed_tests++; |
| 585 | continue; |
| 586 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 587 | } |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 588 | /* map with DMA_BIDIRECTIONAL to force writeback/invalidate */ |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 589 | for (i = 0; i < dst_cnt; i++) { |
| 590 | dma_dsts[i] = dma_map_single(dev->dev, thread->dsts[i], |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 591 | params->buf_size, |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 592 | DMA_BIDIRECTIONAL); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 593 | ret = dma_mapping_error(dev->dev, dma_dsts[i]); |
| 594 | if (ret) { |
| 595 | unmap_src(dev->dev, dma_srcs, len, src_cnt); |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 596 | unmap_dst(dev->dev, dma_dsts, params->buf_size, |
| 597 | i); |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 598 | thread_result_add(info, result, |
| 599 | DMATEST_ET_MAP_DST, |
| 600 | total_tests, src_off, dst_off, |
| 601 | len, ret); |
Andy Shevchenko | afde3be | 2012-12-17 15:59:53 -0800 | [diff] [blame] | 602 | failed_tests++; |
| 603 | continue; |
| 604 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 605 | } |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 606 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 607 | if (thread->type == DMA_MEMCPY) |
| 608 | tx = dev->device_prep_dma_memcpy(chan, |
| 609 | dma_dsts[0] + dst_off, |
| 610 | dma_srcs[0], len, |
| 611 | flags); |
| 612 | else if (thread->type == DMA_XOR) |
| 613 | tx = dev->device_prep_dma_xor(chan, |
| 614 | dma_dsts[0] + dst_off, |
Dan Williams | 67b9124 | 2010-02-28 22:20:18 -0700 | [diff] [blame] | 615 | dma_srcs, src_cnt, |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 616 | len, flags); |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 617 | else if (thread->type == DMA_PQ) { |
| 618 | dma_addr_t dma_pq[dst_cnt]; |
| 619 | |
| 620 | for (i = 0; i < dst_cnt; i++) |
| 621 | dma_pq[i] = dma_dsts[i] + dst_off; |
| 622 | tx = dev->device_prep_dma_pq(chan, dma_pq, dma_srcs, |
Anatolij Gustschin | 94de648 | 2010-02-15 22:35:23 +0100 | [diff] [blame] | 623 | src_cnt, pq_coefs, |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 624 | len, flags); |
| 625 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 626 | |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 627 | if (!tx) { |
Andy Shevchenko | 632fd28 | 2012-12-17 15:59:52 -0800 | [diff] [blame] | 628 | unmap_src(dev->dev, dma_srcs, len, src_cnt); |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 629 | unmap_dst(dev->dev, dma_dsts, params->buf_size, |
| 630 | dst_cnt); |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 631 | thread_result_add(info, result, DMATEST_ET_PREP, |
| 632 | total_tests, src_off, dst_off, |
| 633 | len, 0); |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 634 | msleep(100); |
| 635 | failed_tests++; |
| 636 | continue; |
| 637 | } |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 638 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 639 | done.done = false; |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 640 | tx->callback = dmatest_callback; |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 641 | tx->callback_param = &done; |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 642 | cookie = tx->tx_submit(tx); |
| 643 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 644 | if (dma_submit_error(cookie)) { |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 645 | thread_result_add(info, result, DMATEST_ET_SUBMIT, |
| 646 | total_tests, src_off, dst_off, |
| 647 | len, cookie); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 648 | msleep(100); |
| 649 | failed_tests++; |
| 650 | continue; |
| 651 | } |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 652 | dma_async_issue_pending(chan); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 653 | |
Andy Shevchenko | 77101ce | 2013-03-04 11:09:25 +0200 | [diff] [blame] | 654 | wait_event_freezable_timeout(done_wait, |
| 655 | done.done || kthread_should_stop(), |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 656 | msecs_to_jiffies(params->timeout)); |
Guennadi Liakhovetski | 981ed70 | 2011-08-18 16:50:51 +0200 | [diff] [blame] | 657 | |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 658 | status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 659 | |
Tejun Heo | adfa543 | 2011-11-23 09:28:16 -0800 | [diff] [blame] | 660 | if (!done.done) { |
| 661 | /* |
| 662 | * We're leaving the timed out dma operation with |
| 663 | * dangling pointer to done_wait. To make this |
| 664 | * correct, we'll need to allocate wait_done for |
| 665 | * each test iteration and perform "who's gonna |
| 666 | * free it this time?" dancing. For now, just |
| 667 | * leave it dangling. |
| 668 | */ |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 669 | thread_result_add(info, result, DMATEST_ET_TIMEOUT, |
| 670 | total_tests, src_off, dst_off, |
| 671 | len, 0); |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 672 | failed_tests++; |
| 673 | continue; |
| 674 | } else if (status != DMA_SUCCESS) { |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 675 | enum dmatest_error_type type = (status == DMA_ERROR) ? |
| 676 | DMATEST_ET_DMA_ERROR : DMATEST_ET_DMA_IN_PROGRESS; |
| 677 | thread_result_add(info, result, type, |
| 678 | total_tests, src_off, dst_off, |
| 679 | len, status); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 680 | failed_tests++; |
| 681 | continue; |
| 682 | } |
Dan Williams | e44e0aa | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 683 | |
Atsushi Nemoto | d86be86 | 2009-01-13 09:22:20 -0700 | [diff] [blame] | 684 | /* Unmap by myself (see DMA_COMPL_SKIP_DEST_UNMAP above) */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 685 | unmap_dst(dev->dev, dma_dsts, params->buf_size, dst_cnt); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 686 | |
| 687 | error_count = 0; |
| 688 | |
| 689 | pr_debug("%s: verifying source buffer...\n", thread_name); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 690 | error_count += dmatest_verify(thread->srcs, 0, src_off, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 691 | 0, PATTERN_SRC, true); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 692 | error_count += dmatest_verify(thread->srcs, src_off, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 693 | src_off + len, src_off, |
| 694 | PATTERN_SRC | PATTERN_COPY, true); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 695 | error_count += dmatest_verify(thread->srcs, src_off + len, |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 696 | params->buf_size, src_off + len, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 697 | PATTERN_SRC, true); |
| 698 | |
| 699 | pr_debug("%s: verifying dest buffer...\n", |
| 700 | thread->task->comm); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 701 | error_count += dmatest_verify(thread->dsts, 0, dst_off, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 702 | 0, PATTERN_DST, false); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 703 | error_count += dmatest_verify(thread->dsts, dst_off, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 704 | dst_off + len, src_off, |
| 705 | PATTERN_SRC | PATTERN_COPY, false); |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 706 | error_count += dmatest_verify(thread->dsts, dst_off + len, |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 707 | params->buf_size, dst_off + len, |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 708 | PATTERN_DST, false); |
| 709 | |
| 710 | if (error_count) { |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 711 | thread_result_add(info, result, DMATEST_ET_VERIFY, |
| 712 | total_tests, src_off, dst_off, |
| 713 | len, error_count); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 714 | failed_tests++; |
| 715 | } else { |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 716 | thread_result_add(info, result, DMATEST_ET_OK, |
| 717 | total_tests, src_off, dst_off, |
| 718 | len, 0); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
| 722 | ret = 0; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 723 | for (i = 0; thread->dsts[i]; i++) |
| 724 | kfree(thread->dsts[i]); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 725 | err_dstbuf: |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 726 | kfree(thread->dsts); |
| 727 | err_dsts: |
| 728 | for (i = 0; thread->srcs[i]; i++) |
| 729 | kfree(thread->srcs[i]); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 730 | err_srcbuf: |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 731 | kfree(thread->srcs); |
| 732 | err_srcs: |
Andy Shevchenko | 945b5af | 2013-03-04 11:09:26 +0200 | [diff] [blame] | 733 | kfree(pq_coefs); |
| 734 | err_thread_type: |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 735 | pr_notice("%s: terminating after %u tests, %u failures (status %d)\n", |
| 736 | thread_name, total_tests, failed_tests, ret); |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 737 | |
Viresh Kumar | 9704efa | 2011-07-29 16:21:57 +0530 | [diff] [blame] | 738 | /* terminate all transfers on specified channels */ |
Shiraz Hashim | 5e034f7 | 2012-11-09 15:26:29 +0000 | [diff] [blame] | 739 | if (ret) |
| 740 | dmaengine_terminate_all(chan); |
| 741 | |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 742 | thread->done = true; |
| 743 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 744 | if (params->iterations > 0) |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 745 | while (!kthread_should_stop()) { |
Yong Zhang | b953df7 | 2010-02-05 21:52:37 +0800 | [diff] [blame] | 746 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit); |
Nicolas Ferre | 0a2ff57d | 2009-07-03 19:26:51 +0200 | [diff] [blame] | 747 | interruptible_sleep_on(&wait_dmatest_exit); |
| 748 | } |
| 749 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 750 | return ret; |
| 751 | } |
| 752 | |
| 753 | static void dmatest_cleanup_channel(struct dmatest_chan *dtc) |
| 754 | { |
| 755 | struct dmatest_thread *thread; |
| 756 | struct dmatest_thread *_thread; |
| 757 | int ret; |
| 758 | |
| 759 | list_for_each_entry_safe(thread, _thread, &dtc->threads, node) { |
| 760 | ret = kthread_stop(thread->task); |
| 761 | pr_debug("dmatest: thread %s exited with status %d\n", |
| 762 | thread->task->comm, ret); |
| 763 | list_del(&thread->node); |
| 764 | kfree(thread); |
| 765 | } |
Viresh Kumar | 9704efa | 2011-07-29 16:21:57 +0530 | [diff] [blame] | 766 | |
| 767 | /* terminate all transfers on specified channels */ |
Jon Mason | 944ea4d | 2012-11-11 23:03:20 +0000 | [diff] [blame] | 768 | dmaengine_terminate_all(dtc->chan); |
Viresh Kumar | 9704efa | 2011-07-29 16:21:57 +0530 | [diff] [blame] | 769 | |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 770 | kfree(dtc); |
| 771 | } |
| 772 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 773 | static int dmatest_add_threads(struct dmatest_info *info, |
| 774 | struct dmatest_chan *dtc, enum dma_transaction_type type) |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 775 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 776 | struct dmatest_params *params = &info->params; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 777 | struct dmatest_thread *thread; |
| 778 | struct dma_chan *chan = dtc->chan; |
| 779 | char *op; |
| 780 | unsigned int i; |
| 781 | |
| 782 | if (type == DMA_MEMCPY) |
| 783 | op = "copy"; |
| 784 | else if (type == DMA_XOR) |
| 785 | op = "xor"; |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 786 | else if (type == DMA_PQ) |
| 787 | op = "pq"; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 788 | else |
| 789 | return -EINVAL; |
| 790 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 791 | for (i = 0; i < params->threads_per_chan; i++) { |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 792 | thread = kzalloc(sizeof(struct dmatest_thread), GFP_KERNEL); |
| 793 | if (!thread) { |
| 794 | pr_warning("dmatest: No memory for %s-%s%u\n", |
| 795 | dma_chan_name(chan), op, i); |
| 796 | |
| 797 | break; |
| 798 | } |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 799 | thread->info = info; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 800 | thread->chan = dtc->chan; |
| 801 | thread->type = type; |
| 802 | smp_wmb(); |
| 803 | thread->task = kthread_run(dmatest_func, thread, "%s-%s%u", |
| 804 | dma_chan_name(chan), op, i); |
| 805 | if (IS_ERR(thread->task)) { |
| 806 | pr_warning("dmatest: Failed to run thread %s-%s%u\n", |
| 807 | dma_chan_name(chan), op, i); |
| 808 | kfree(thread); |
| 809 | break; |
| 810 | } |
| 811 | |
| 812 | /* srcbuf and dstbuf are allocated by the thread itself */ |
| 813 | |
| 814 | list_add_tail(&thread->node, &dtc->threads); |
| 815 | } |
| 816 | |
| 817 | return i; |
| 818 | } |
| 819 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 820 | static int dmatest_add_channel(struct dmatest_info *info, |
| 821 | struct dma_chan *chan) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 822 | { |
| 823 | struct dmatest_chan *dtc; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 824 | struct dma_device *dma_dev = chan->device; |
| 825 | unsigned int thread_count = 0; |
Kulikov Vasiliy | b9033e6 | 2010-07-17 19:19:48 +0400 | [diff] [blame] | 826 | int cnt; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 827 | |
Andrew Morton | 6fdb8bd | 2008-09-19 04:16:23 -0700 | [diff] [blame] | 828 | dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 829 | if (!dtc) { |
Dan Williams | 41d5e59 | 2009-01-06 11:38:21 -0700 | [diff] [blame] | 830 | pr_warning("dmatest: No memory for %s\n", dma_chan_name(chan)); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 831 | return -ENOMEM; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | dtc->chan = chan; |
| 835 | INIT_LIST_HEAD(&dtc->threads); |
| 836 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 837 | if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 838 | cnt = dmatest_add_threads(info, dtc, DMA_MEMCPY); |
Nicolas Ferre | f1aef8b | 2009-07-06 18:19:44 +0200 | [diff] [blame] | 839 | thread_count += cnt > 0 ? cnt : 0; |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 840 | } |
| 841 | if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 842 | cnt = dmatest_add_threads(info, dtc, DMA_XOR); |
Nicolas Ferre | f1aef8b | 2009-07-06 18:19:44 +0200 | [diff] [blame] | 843 | thread_count += cnt > 0 ? cnt : 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 844 | } |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 845 | if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 846 | cnt = dmatest_add_threads(info, dtc, DMA_PQ); |
Dr. David Alan Gilbert | d07a74a | 2011-08-25 16:13:55 -0700 | [diff] [blame] | 847 | thread_count += cnt > 0 ? cnt : 0; |
Dan Williams | 58691d6 | 2009-08-29 19:09:27 -0700 | [diff] [blame] | 848 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 849 | |
Dan Williams | b54d5cb | 2009-03-25 09:13:25 -0700 | [diff] [blame] | 850 | pr_info("dmatest: Started %u threads using %s\n", |
| 851 | thread_count, dma_chan_name(chan)); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 852 | |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 853 | list_add_tail(&dtc->node, &info->channels); |
| 854 | info->nr_channels++; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 855 | |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 856 | return 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Dan Williams | 7dd6025 | 2009-01-06 11:38:19 -0700 | [diff] [blame] | 859 | static bool filter(struct dma_chan *chan, void *param) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 860 | { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 861 | struct dmatest_params *params = param; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 862 | |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 863 | if (!dmatest_match_channel(params, chan) || |
| 864 | !dmatest_match_device(params, chan->device)) |
Dan Williams | 7dd6025 | 2009-01-06 11:38:19 -0700 | [diff] [blame] | 865 | return false; |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 866 | else |
Dan Williams | 7dd6025 | 2009-01-06 11:38:19 -0700 | [diff] [blame] | 867 | return true; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 870 | static int __run_threaded_test(struct dmatest_info *info) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 871 | { |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 872 | dma_cap_mask_t mask; |
| 873 | struct dma_chan *chan; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 874 | struct dmatest_params *params = &info->params; |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 875 | int err = 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 876 | |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 877 | dma_cap_zero(mask); |
| 878 | dma_cap_set(DMA_MEMCPY, mask); |
| 879 | for (;;) { |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 880 | chan = dma_request_channel(mask, filter, params); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 881 | if (chan) { |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 882 | err = dmatest_add_channel(info, chan); |
Dan Williams | c56c81a | 2009-04-08 15:08:23 -0700 | [diff] [blame] | 883 | if (err) { |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 884 | dma_release_channel(chan); |
| 885 | break; /* add_channel failed, punt */ |
| 886 | } |
| 887 | } else |
| 888 | break; /* no more channels available */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 889 | if (params->max_channels && |
| 890 | info->nr_channels >= params->max_channels) |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 891 | break; /* we have all we need */ |
| 892 | } |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 893 | return err; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 894 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 895 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 896 | #ifndef MODULE |
| 897 | static int run_threaded_test(struct dmatest_info *info) |
| 898 | { |
| 899 | int ret; |
| 900 | |
| 901 | mutex_lock(&info->lock); |
| 902 | ret = __run_threaded_test(info); |
| 903 | mutex_unlock(&info->lock); |
| 904 | return ret; |
| 905 | } |
| 906 | #endif |
| 907 | |
| 908 | static void __stop_threaded_test(struct dmatest_info *info) |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 909 | { |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 910 | struct dmatest_chan *dtc, *_dtc; |
Dan Williams | 7cbd487 | 2009-03-04 16:06:03 -0700 | [diff] [blame] | 911 | struct dma_chan *chan; |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 912 | |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 913 | list_for_each_entry_safe(dtc, _dtc, &info->channels, node) { |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 914 | list_del(&dtc->node); |
Dan Williams | 7cbd487 | 2009-03-04 16:06:03 -0700 | [diff] [blame] | 915 | chan = dtc->chan; |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 916 | dmatest_cleanup_channel(dtc); |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 917 | pr_debug("dmatest: dropped channel %s\n", dma_chan_name(chan)); |
Dan Williams | 7cbd487 | 2009-03-04 16:06:03 -0700 | [diff] [blame] | 918 | dma_release_channel(chan); |
Dan Williams | 33df8ca | 2009-01-06 11:38:15 -0700 | [diff] [blame] | 919 | } |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 920 | |
| 921 | info->nr_channels = 0; |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 922 | } |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 923 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 924 | static void stop_threaded_test(struct dmatest_info *info) |
| 925 | { |
| 926 | mutex_lock(&info->lock); |
| 927 | __stop_threaded_test(info); |
| 928 | mutex_unlock(&info->lock); |
| 929 | } |
| 930 | |
| 931 | static int __restart_threaded_test(struct dmatest_info *info, bool run) |
| 932 | { |
| 933 | struct dmatest_params *params = &info->params; |
| 934 | int ret; |
| 935 | |
| 936 | /* Stop any running test first */ |
| 937 | __stop_threaded_test(info); |
| 938 | |
| 939 | if (run == false) |
| 940 | return 0; |
| 941 | |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 942 | /* Clear results from previous run */ |
| 943 | result_free(info, NULL); |
| 944 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 945 | /* Copy test parameters */ |
| 946 | memcpy(params, &info->dbgfs_params, sizeof(*params)); |
| 947 | |
| 948 | /* Run test with new parameters */ |
| 949 | ret = __run_threaded_test(info); |
| 950 | if (ret) { |
| 951 | __stop_threaded_test(info); |
| 952 | pr_err("dmatest: Can't run test\n"); |
| 953 | } |
| 954 | |
| 955 | return ret; |
| 956 | } |
| 957 | |
| 958 | static ssize_t dtf_write_string(void *to, size_t available, loff_t *ppos, |
| 959 | const void __user *from, size_t count) |
| 960 | { |
| 961 | char tmp[20]; |
| 962 | ssize_t len; |
| 963 | |
| 964 | len = simple_write_to_buffer(tmp, sizeof(tmp) - 1, ppos, from, count); |
| 965 | if (len >= 0) { |
| 966 | tmp[len] = '\0'; |
| 967 | strlcpy(to, strim(tmp), available); |
| 968 | } |
| 969 | |
| 970 | return len; |
| 971 | } |
| 972 | |
| 973 | static ssize_t dtf_read_channel(struct file *file, char __user *buf, |
| 974 | size_t count, loff_t *ppos) |
| 975 | { |
| 976 | struct dmatest_info *info = file->private_data; |
| 977 | return simple_read_from_buffer(buf, count, ppos, |
| 978 | info->dbgfs_params.channel, |
| 979 | strlen(info->dbgfs_params.channel)); |
| 980 | } |
| 981 | |
| 982 | static ssize_t dtf_write_channel(struct file *file, const char __user *buf, |
| 983 | size_t size, loff_t *ppos) |
| 984 | { |
| 985 | struct dmatest_info *info = file->private_data; |
| 986 | return dtf_write_string(info->dbgfs_params.channel, |
| 987 | sizeof(info->dbgfs_params.channel), |
| 988 | ppos, buf, size); |
| 989 | } |
| 990 | |
| 991 | static const struct file_operations dtf_channel_fops = { |
| 992 | .read = dtf_read_channel, |
| 993 | .write = dtf_write_channel, |
| 994 | .open = simple_open, |
| 995 | .llseek = default_llseek, |
| 996 | }; |
| 997 | |
| 998 | static ssize_t dtf_read_device(struct file *file, char __user *buf, |
| 999 | size_t count, loff_t *ppos) |
| 1000 | { |
| 1001 | struct dmatest_info *info = file->private_data; |
| 1002 | return simple_read_from_buffer(buf, count, ppos, |
| 1003 | info->dbgfs_params.device, |
| 1004 | strlen(info->dbgfs_params.device)); |
| 1005 | } |
| 1006 | |
| 1007 | static ssize_t dtf_write_device(struct file *file, const char __user *buf, |
| 1008 | size_t size, loff_t *ppos) |
| 1009 | { |
| 1010 | struct dmatest_info *info = file->private_data; |
| 1011 | return dtf_write_string(info->dbgfs_params.device, |
| 1012 | sizeof(info->dbgfs_params.device), |
| 1013 | ppos, buf, size); |
| 1014 | } |
| 1015 | |
| 1016 | static const struct file_operations dtf_device_fops = { |
| 1017 | .read = dtf_read_device, |
| 1018 | .write = dtf_write_device, |
| 1019 | .open = simple_open, |
| 1020 | .llseek = default_llseek, |
| 1021 | }; |
| 1022 | |
| 1023 | static ssize_t dtf_read_run(struct file *file, char __user *user_buf, |
| 1024 | size_t count, loff_t *ppos) |
| 1025 | { |
| 1026 | struct dmatest_info *info = file->private_data; |
| 1027 | char buf[3]; |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 1028 | struct dmatest_chan *dtc; |
| 1029 | bool alive = false; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1030 | |
| 1031 | mutex_lock(&info->lock); |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 1032 | list_for_each_entry(dtc, &info->channels, node) { |
| 1033 | struct dmatest_thread *thread; |
| 1034 | |
| 1035 | list_for_each_entry(thread, &dtc->threads, node) { |
| 1036 | if (!thread->done) { |
| 1037 | alive = true; |
| 1038 | break; |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | if (alive) { |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1044 | buf[0] = 'Y'; |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 1045 | } else { |
| 1046 | __stop_threaded_test(info); |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1047 | buf[0] = 'N'; |
Andy Shevchenko | 3e5ccd8 | 2013-03-04 11:09:31 +0200 | [diff] [blame] | 1048 | } |
| 1049 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1050 | mutex_unlock(&info->lock); |
| 1051 | buf[1] = '\n'; |
| 1052 | buf[2] = 0x00; |
| 1053 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); |
| 1054 | } |
| 1055 | |
| 1056 | static ssize_t dtf_write_run(struct file *file, const char __user *user_buf, |
| 1057 | size_t count, loff_t *ppos) |
| 1058 | { |
| 1059 | struct dmatest_info *info = file->private_data; |
| 1060 | char buf[16]; |
| 1061 | bool bv; |
| 1062 | int ret = 0; |
| 1063 | |
| 1064 | if (copy_from_user(buf, user_buf, min(count, (sizeof(buf) - 1)))) |
| 1065 | return -EFAULT; |
| 1066 | |
| 1067 | if (strtobool(buf, &bv) == 0) { |
| 1068 | mutex_lock(&info->lock); |
| 1069 | ret = __restart_threaded_test(info, bv); |
| 1070 | mutex_unlock(&info->lock); |
| 1071 | } |
| 1072 | |
| 1073 | return ret ? ret : count; |
| 1074 | } |
| 1075 | |
| 1076 | static const struct file_operations dtf_run_fops = { |
| 1077 | .read = dtf_read_run, |
| 1078 | .write = dtf_write_run, |
| 1079 | .open = simple_open, |
| 1080 | .llseek = default_llseek, |
| 1081 | }; |
| 1082 | |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 1083 | static int dtf_results_show(struct seq_file *sf, void *data) |
| 1084 | { |
| 1085 | struct dmatest_info *info = sf->private; |
| 1086 | struct dmatest_result *result; |
| 1087 | struct dmatest_thread_result *tr; |
| 1088 | |
| 1089 | mutex_lock(&info->results_lock); |
| 1090 | list_for_each_entry(result, &info->results, node) { |
| 1091 | list_for_each_entry(tr, &result->results, node) |
| 1092 | seq_printf(sf, "%s\n", |
| 1093 | thread_result_get(result->name, tr)); |
| 1094 | } |
| 1095 | |
| 1096 | mutex_unlock(&info->results_lock); |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
| 1100 | static int dtf_results_open(struct inode *inode, struct file *file) |
| 1101 | { |
| 1102 | return single_open(file, dtf_results_show, inode->i_private); |
| 1103 | } |
| 1104 | |
| 1105 | static const struct file_operations dtf_results_fops = { |
| 1106 | .open = dtf_results_open, |
| 1107 | .read = seq_read, |
| 1108 | .llseek = seq_lseek, |
| 1109 | .release = single_release, |
| 1110 | }; |
| 1111 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1112 | static int dmatest_register_dbgfs(struct dmatest_info *info) |
| 1113 | { |
| 1114 | struct dentry *d; |
| 1115 | struct dmatest_params *params = &info->dbgfs_params; |
| 1116 | int ret = -ENOMEM; |
| 1117 | |
| 1118 | d = debugfs_create_dir("dmatest", NULL); |
| 1119 | if (IS_ERR(d)) |
| 1120 | return PTR_ERR(d); |
| 1121 | if (!d) |
| 1122 | goto err_root; |
| 1123 | |
| 1124 | info->root = d; |
| 1125 | |
| 1126 | /* Copy initial values */ |
| 1127 | memcpy(params, &info->params, sizeof(*params)); |
| 1128 | |
| 1129 | /* Test parameters */ |
| 1130 | |
| 1131 | d = debugfs_create_u32("test_buf_size", S_IWUSR | S_IRUGO, info->root, |
| 1132 | (u32 *)¶ms->buf_size); |
| 1133 | if (IS_ERR_OR_NULL(d)) |
| 1134 | goto err_node; |
| 1135 | |
| 1136 | d = debugfs_create_file("channel", S_IRUGO | S_IWUSR, info->root, |
| 1137 | info, &dtf_channel_fops); |
| 1138 | if (IS_ERR_OR_NULL(d)) |
| 1139 | goto err_node; |
| 1140 | |
| 1141 | d = debugfs_create_file("device", S_IRUGO | S_IWUSR, info->root, |
| 1142 | info, &dtf_device_fops); |
| 1143 | if (IS_ERR_OR_NULL(d)) |
| 1144 | goto err_node; |
| 1145 | |
| 1146 | d = debugfs_create_u32("threads_per_chan", S_IWUSR | S_IRUGO, info->root, |
| 1147 | (u32 *)¶ms->threads_per_chan); |
| 1148 | if (IS_ERR_OR_NULL(d)) |
| 1149 | goto err_node; |
| 1150 | |
| 1151 | d = debugfs_create_u32("max_channels", S_IWUSR | S_IRUGO, info->root, |
| 1152 | (u32 *)¶ms->max_channels); |
| 1153 | if (IS_ERR_OR_NULL(d)) |
| 1154 | goto err_node; |
| 1155 | |
| 1156 | d = debugfs_create_u32("iterations", S_IWUSR | S_IRUGO, info->root, |
| 1157 | (u32 *)¶ms->iterations); |
| 1158 | if (IS_ERR_OR_NULL(d)) |
| 1159 | goto err_node; |
| 1160 | |
| 1161 | d = debugfs_create_u32("xor_sources", S_IWUSR | S_IRUGO, info->root, |
| 1162 | (u32 *)¶ms->xor_sources); |
| 1163 | if (IS_ERR_OR_NULL(d)) |
| 1164 | goto err_node; |
| 1165 | |
| 1166 | d = debugfs_create_u32("pq_sources", S_IWUSR | S_IRUGO, info->root, |
| 1167 | (u32 *)¶ms->pq_sources); |
| 1168 | if (IS_ERR_OR_NULL(d)) |
| 1169 | goto err_node; |
| 1170 | |
| 1171 | d = debugfs_create_u32("timeout", S_IWUSR | S_IRUGO, info->root, |
| 1172 | (u32 *)¶ms->timeout); |
| 1173 | if (IS_ERR_OR_NULL(d)) |
| 1174 | goto err_node; |
| 1175 | |
| 1176 | /* Run or stop threaded test */ |
| 1177 | d = debugfs_create_file("run", S_IWUSR | S_IRUGO, info->root, |
| 1178 | info, &dtf_run_fops); |
| 1179 | if (IS_ERR_OR_NULL(d)) |
| 1180 | goto err_node; |
| 1181 | |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 1182 | /* Results of test in progress */ |
| 1183 | d = debugfs_create_file("results", S_IRUGO, info->root, info, |
| 1184 | &dtf_results_fops); |
| 1185 | if (IS_ERR_OR_NULL(d)) |
| 1186 | goto err_node; |
| 1187 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1188 | return 0; |
| 1189 | |
| 1190 | err_node: |
| 1191 | debugfs_remove_recursive(info->root); |
| 1192 | err_root: |
| 1193 | pr_err("dmatest: Failed to initialize debugfs\n"); |
| 1194 | return ret; |
| 1195 | } |
| 1196 | |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1197 | static int __init dmatest_init(void) |
| 1198 | { |
| 1199 | struct dmatest_info *info = &test_info; |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 1200 | struct dmatest_params *params = &info->params; |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1201 | int ret; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1202 | |
| 1203 | memset(info, 0, sizeof(*info)); |
| 1204 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1205 | mutex_init(&info->lock); |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 1206 | INIT_LIST_HEAD(&info->channels); |
| 1207 | |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 1208 | mutex_init(&info->results_lock); |
| 1209 | INIT_LIST_HEAD(&info->results); |
| 1210 | |
Andy Shevchenko | 838cc70 | 2013-03-04 11:09:28 +0200 | [diff] [blame] | 1211 | /* Set default parameters */ |
Andy Shevchenko | 15b8a8e | 2013-03-04 11:09:29 +0200 | [diff] [blame] | 1212 | params->buf_size = test_buf_size; |
| 1213 | strlcpy(params->channel, test_channel, sizeof(params->channel)); |
| 1214 | strlcpy(params->device, test_device, sizeof(params->device)); |
| 1215 | params->threads_per_chan = threads_per_chan; |
| 1216 | params->max_channels = max_channels; |
| 1217 | params->iterations = iterations; |
| 1218 | params->xor_sources = xor_sources; |
| 1219 | params->pq_sources = pq_sources; |
| 1220 | params->timeout = timeout; |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1221 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1222 | ret = dmatest_register_dbgfs(info); |
| 1223 | if (ret) |
| 1224 | return ret; |
| 1225 | |
| 1226 | #ifdef MODULE |
| 1227 | return 0; |
| 1228 | #else |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1229 | return run_threaded_test(info); |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1230 | #endif |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1231 | } |
| 1232 | /* when compiled-in wait for drivers to load first */ |
| 1233 | late_initcall(dmatest_init); |
| 1234 | |
| 1235 | static void __exit dmatest_exit(void) |
| 1236 | { |
| 1237 | struct dmatest_info *info = &test_info; |
| 1238 | |
Andy Shevchenko | 851b7e1 | 2013-03-04 11:09:30 +0200 | [diff] [blame] | 1239 | debugfs_remove_recursive(info->root); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1240 | stop_threaded_test(info); |
Andy Shevchenko | 95019c8 | 2013-03-04 11:09:33 +0200 | [diff] [blame^] | 1241 | result_free(info, NULL); |
Andy Shevchenko | e03e93a | 2013-03-04 11:09:27 +0200 | [diff] [blame] | 1242 | } |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 1243 | module_exit(dmatest_exit); |
| 1244 | |
Jean Delvare | e05503e | 2011-05-18 16:49:24 +0200 | [diff] [blame] | 1245 | MODULE_AUTHOR("Haavard Skinnemoen (Atmel)"); |
Haavard Skinnemoen | 4a776f0 | 2008-07-08 11:58:45 -0700 | [diff] [blame] | 1246 | MODULE_LICENSE("GPL v2"); |