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