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