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