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