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