1============== 2DMA Test Guide 3============== 4 5Andy Shevchenko <andriy.shevchenko@linux.intel.com> 6 7This small document introduces how to test DMA drivers using dmatest module. 8 9The dmatest module tests DMA memcpy, memset, XOR and RAID6 P+Q operations using 10various lengths and various offsets into the source and destination buffers. It 11will initialize both buffers with a repeatable pattern and verify that the DMA 12engine copies the requested region and nothing more. It will also verify that 13the bytes aren't swapped around, and that the source buffer isn't modified. 14 15The dmatest module can be configured to test a specific channel. It can also 16test multiple channels at the same time, and it can start multiple threads 17competing for the same channel. 18 19.. note:: 20 The test suite works only on the channels that have at least one 21 capability of the following: DMA_MEMCPY (memory-to-memory), DMA_MEMSET 22 (const-to-memory or memory-to-memory, when emulated), DMA_XOR, DMA_PQ. 23 24.. note:: 25 In case of any related questions use the official mailing list 26 dmaengine@vger.kernel.org. 27 28Part 1 - How to build the test module 29===================================== 30 31The menuconfig contains an option that could be found by following path: 32 33 Device Drivers -> DMA Engine support -> DMA Test client 34 35In the configuration file the option called CONFIG_DMATEST. The dmatest could 36be built as module or inside kernel. Let's consider those cases. 37 38Part 2 - When dmatest is built as a module 39========================================== 40 41Example of usage:: 42 43 % modprobe dmatest timeout=2000 iterations=1 channel=dma0chan0 run=1 44 45...or:: 46 47 % modprobe dmatest 48 % echo 2000 > /sys/module/dmatest/parameters/timeout 49 % echo 1 > /sys/module/dmatest/parameters/iterations 50 % echo dma0chan0 > /sys/module/dmatest/parameters/channel 51 % echo 1 > /sys/module/dmatest/parameters/run 52 53...or on the kernel command line:: 54 55 dmatest.timeout=2000 dmatest.iterations=1 dmatest.channel=dma0chan0 dmatest.run=1 56 57Example of multi-channel test usage (new in the 5.0 kernel):: 58 59 % modprobe dmatest 60 % echo 2000 > /sys/module/dmatest/parameters/timeout 61 % echo 1 > /sys/module/dmatest/parameters/iterations 62 % echo dma0chan0 > /sys/module/dmatest/parameters/channel 63 % echo dma0chan1 > /sys/module/dmatest/parameters/channel 64 % echo dma0chan2 > /sys/module/dmatest/parameters/channel 65 % echo 1 > /sys/module/dmatest/parameters/run 66 67.. note:: 68 For all tests, starting in the 5.0 kernel, either single- or multi-channel, 69 the channel parameter(s) must be set after all other parameters. It is at 70 that time that the existing parameter values are acquired for use by the 71 thread(s). All other parameters are shared. Therefore, if changes are made 72 to any of the other parameters, and an additional channel specified, the 73 (shared) parameters used for all threads will use the new values. 74 After the channels are specified, each thread is set as pending. All threads 75 begin execution when the run parameter is set to 1. 76 77.. hint:: 78 A list of available channels can be found by running the following command:: 79 80 % ls -1 /sys/class/dma/ 81 82Once started a message like " dmatest: Added 1 threads using dma0chan0" is 83emitted. A thread for that specific channel is created and is now pending, the 84pending thread is started once run is to 1. 85 86Note that running a new test will not stop any in progress test. 87 88The following command returns the state of the test. :: 89 90 % cat /sys/module/dmatest/parameters/run 91 92To wait for test completion userpace can poll 'run' until it is false, or use 93the wait parameter. Specifying 'wait=1' when loading the module causes module 94initialization to pause until a test run has completed, while reading 95/sys/module/dmatest/parameters/wait waits for any running test to complete 96before returning. For example, the following scripts wait for 42 tests 97to complete before exiting. Note that if 'iterations' is set to 'infinite' then 98waiting is disabled. 99 100Example:: 101 102 % modprobe dmatest run=1 iterations=42 wait=1 103 % modprobe -r dmatest 104 105...or:: 106 107 % modprobe dmatest run=1 iterations=42 108 % cat /sys/module/dmatest/parameters/wait 109 % modprobe -r dmatest 110 111Part 3 - When built-in in the kernel 112==================================== 113 114The module parameters that is supplied to the kernel command line will be used 115for the first performed test. After user gets a control, the test could be 116re-run with the same or different parameters. For the details see the above 117section `Part 2 - When dmatest is built as a module`_. 118 119In both cases the module parameters are used as the actual values for the test 120case. You always could check them at run-time by running :: 121 122 % grep -H . /sys/module/dmatest/parameters/* 123 124Part 4 - Gathering the test results 125=================================== 126 127Test results are printed to the kernel log buffer with the format:: 128 129 "dmatest: result <channel>: <test id>: '<error msg>' with src_off=<val> dst_off=<val> len=<val> (<err code>)" 130 131Example of output:: 132 133 % dmesg | tail -n 1 134 dmatest: result dma0chan0-copy0: #1: No errors with src_off=0x7bf dst_off=0x8ad len=0x3fea (0) 135 136The message format is unified across the different types of errors. A 137number in the parentheses represents additional information, e.g. error 138code, error counter, or status. A test thread also emits a summary line at 139completion listing the number of tests executed, number that failed, and a 140result code. 141 142Example:: 143 144 % dmesg | tail -n 1 145 dmatest: dma0chan0-copy0: summary 1 test, 0 failures 1000 iops 100000 KB/s (0) 146 147The details of a data miscompare error are also emitted, but do not follow the 148above format. 149 150Part 5 - Handling channel allocation 151==================================== 152 153Allocating Channels 154------------------- 155 156Channels are required to be configured prior to starting the test run. 157Attempting to run the test without configuring the channels will fail. 158 159Example:: 160 161 % echo 1 > /sys/module/dmatest/parameters/run 162 dmatest: Could not start test, no channels configured 163 164Channels are registered using the "channel" parameter. Channels can be requested by their 165name, once requested, the channel is registered and a pending thread is added to the test list. 166 167Example:: 168 169 % echo dma0chan2 > /sys/module/dmatest/parameters/channel 170 dmatest: Added 1 threads using dma0chan2 171 172More channels can be added by repeating the example above. 173Reading back the channel parameter will return the name of last channel that was added successfully. 174 175Example:: 176 177 % echo dma0chan1 > /sys/module/dmatest/parameters/channel 178 dmatest: Added 1 threads using dma0chan1 179 % echo dma0chan2 > /sys/module/dmatest/parameters/channel 180 dmatest: Added 1 threads using dma0chan2 181 % cat /sys/module/dmatest/parameters/channel 182 dma0chan2 183 184Another method of requesting channels is to request a channel with an empty string, Doing so 185will request all channels available to be tested: 186 187Example:: 188 189 % echo "" > /sys/module/dmatest/parameters/channel 190 dmatest: Added 1 threads using dma0chan0 191 dmatest: Added 1 threads using dma0chan3 192 dmatest: Added 1 threads using dma0chan4 193 dmatest: Added 1 threads using dma0chan5 194 dmatest: Added 1 threads using dma0chan6 195 dmatest: Added 1 threads using dma0chan7 196 dmatest: Added 1 threads using dma0chan8 197 198At any point during the test configuration, reading the "test_list" parameter will 199print the list of currently pending tests. 200 201Example:: 202 203 % cat /sys/module/dmatest/parameters/test_list 204 dmatest: 1 threads using dma0chan0 205 dmatest: 1 threads using dma0chan3 206 dmatest: 1 threads using dma0chan4 207 dmatest: 1 threads using dma0chan5 208 dmatest: 1 threads using dma0chan6 209 dmatest: 1 threads using dma0chan7 210 dmatest: 1 threads using dma0chan8 211 212Note: Channels will have to be configured for each test run as channel configurations do not 213carry across to the next test run. 214 215Releasing Channels 216------------------- 217 218Channels can be freed by setting run to 0. 219 220Example:: 221 222 % echo dma0chan1 > /sys/module/dmatest/parameters/channel 223 dmatest: Added 1 threads using dma0chan1 224 % cat /sys/class/dma/dma0chan1/in_use 225 1 226 % echo 0 > /sys/module/dmatest/parameters/run 227 % cat /sys/class/dma/dma0chan1/in_use 228 0 229 230Channels allocated by previous test runs are automatically freed when a new 231channel is requested after completing a successful test run. 232