1179a214eSVinod Koul============== 2179a214eSVinod KoulDMA Test Guide 3179a214eSVinod Koul============== 4179a214eSVinod Koul 5179a214eSVinod KoulAndy Shevchenko <andriy.shevchenko@linux.intel.com> 6179a214eSVinod Koul 7179a214eSVinod KoulThis small document introduces how to test DMA drivers using dmatest module. 8179a214eSVinod Koul 937829227SDaniel ThompsonThe dmatest module tests DMA memcpy, memset, XOR and RAID6 P+Q operations using 1037829227SDaniel Thompsonvarious lengths and various offsets into the source and destination buffers. It 1137829227SDaniel Thompsonwill initialize both buffers with a repeatable pattern and verify that the DMA 1237829227SDaniel Thompsonengine copies the requested region and nothing more. It will also verify that 1337829227SDaniel Thompsonthe bytes aren't swapped around, and that the source buffer isn't modified. 1437829227SDaniel Thompson 1537829227SDaniel ThompsonThe dmatest module can be configured to test a specific channel. It can also 1637829227SDaniel Thompsontest multiple channels at the same time, and it can start multiple threads 1737829227SDaniel Thompsoncompeting for the same channel. 1837829227SDaniel Thompson 19a6cd7714SAndy Shevchenko.. note:: 20a6cd7714SAndy Shevchenko The test suite works only on the channels that have at least one 21a6cd7714SAndy Shevchenko capability of the following: DMA_MEMCPY (memory-to-memory), DMA_MEMSET 22a6cd7714SAndy Shevchenko (const-to-memory or memory-to-memory, when emulated), DMA_XOR, DMA_PQ. 23a6cd7714SAndy Shevchenko 2448c465d2SAndy Shevchenko.. note:: 2548c465d2SAndy Shevchenko In case of any related questions use the official mailing list 2648c465d2SAndy Shevchenko dmaengine@vger.kernel.org. 2748c465d2SAndy Shevchenko 28179a214eSVinod KoulPart 1 - How to build the test module 29179a214eSVinod Koul===================================== 30179a214eSVinod Koul 31179a214eSVinod KoulThe menuconfig contains an option that could be found by following path: 32bc1287b9SAndy Shevchenko 33179a214eSVinod Koul Device Drivers -> DMA Engine support -> DMA Test client 34179a214eSVinod Koul 35179a214eSVinod KoulIn the configuration file the option called CONFIG_DMATEST. The dmatest could 36179a214eSVinod Koulbe built as module or inside kernel. Let's consider those cases. 37179a214eSVinod Koul 38179a214eSVinod KoulPart 2 - When dmatest is built as a module 39179a214eSVinod Koul========================================== 40179a214eSVinod Koul 41bc1287b9SAndy ShevchenkoExample of usage:: 42179a214eSVinod Koul 43f80f9988SSeraj Alijan % modprobe dmatest timeout=2000 iterations=1 channel=dma0chan0 run=1 44179a214eSVinod Koul 45bc1287b9SAndy Shevchenko...or:: 46179a214eSVinod Koul 47179a214eSVinod Koul % modprobe dmatest 48179a214eSVinod Koul % echo 2000 > /sys/module/dmatest/parameters/timeout 49179a214eSVinod Koul % echo 1 > /sys/module/dmatest/parameters/iterations 50f80f9988SSeraj Alijan % echo dma0chan0 > /sys/module/dmatest/parameters/channel 51179a214eSVinod Koul % echo 1 > /sys/module/dmatest/parameters/run 52179a214eSVinod Koul 53bc1287b9SAndy Shevchenko...or on the kernel command line:: 54179a214eSVinod Koul 55f80f9988SSeraj Alijan dmatest.timeout=2000 dmatest.iterations=1 dmatest.channel=dma0chan0 dmatest.run=1 56179a214eSVinod Koul 579dcb98a2SHook, GaryExample of multi-channel test usage (new in the 5.0 kernel):: 589dcb98a2SHook, Gary 59f80f9988SSeraj Alijan % modprobe dmatest 60f80f9988SSeraj Alijan % echo 2000 > /sys/module/dmatest/parameters/timeout 61f80f9988SSeraj Alijan % echo 1 > /sys/module/dmatest/parameters/iterations 62f80f9988SSeraj Alijan % echo dma0chan0 > /sys/module/dmatest/parameters/channel 63f80f9988SSeraj Alijan % echo dma0chan1 > /sys/module/dmatest/parameters/channel 64f80f9988SSeraj Alijan % echo dma0chan2 > /sys/module/dmatest/parameters/channel 65f80f9988SSeraj Alijan % echo 1 > /sys/module/dmatest/parameters/run 66f80f9988SSeraj Alijan 679dcb98a2SHook, Gary.. note:: 689dcb98a2SHook, Gary For all tests, starting in the 5.0 kernel, either single- or multi-channel, 699dcb98a2SHook, Gary the channel parameter(s) must be set after all other parameters. It is at 709dcb98a2SHook, Gary that time that the existing parameter values are acquired for use by the 719dcb98a2SHook, Gary thread(s). All other parameters are shared. Therefore, if changes are made 729dcb98a2SHook, Gary to any of the other parameters, and an additional channel specified, the 739dcb98a2SHook, Gary (shared) parameters used for all threads will use the new values. 749dcb98a2SHook, Gary After the channels are specified, each thread is set as pending. All threads 759dcb98a2SHook, Gary begin execution when the run parameter is set to 1. 76b2971596SRandy Dunlap 77bc1287b9SAndy Shevchenko.. hint:: 789dcb98a2SHook, Gary A list of available channels can be found by running the following command:: 79179a214eSVinod Koul 80179a214eSVinod Koul % ls -1 /sys/class/dma/ 81179a214eSVinod Koul 82f80f9988SSeraj AlijanOnce started a message like " dmatest: Added 1 threads using dma0chan0" is 83f80f9988SSeraj Alijanemitted. A thread for that specific channel is created and is now pending, the 84f80f9988SSeraj Alijanpending thread is started once run is to 1. 85179a214eSVinod Koul 86179a214eSVinod KoulNote that running a new test will not stop any in progress test. 87179a214eSVinod Koul 88179a214eSVinod KoulThe following command returns the state of the test. :: 89179a214eSVinod Koul 90179a214eSVinod Koul % cat /sys/module/dmatest/parameters/run 91179a214eSVinod Koul 92*7852fe3aSRandy DunlapTo wait for test completion userspace can poll 'run' until it is false, or use 93179a214eSVinod Koulthe wait parameter. Specifying 'wait=1' when loading the module causes module 94179a214eSVinod Koulinitialization to pause until a test run has completed, while reading 95179a214eSVinod Koul/sys/module/dmatest/parameters/wait waits for any running test to complete 96179a214eSVinod Koulbefore returning. For example, the following scripts wait for 42 tests 97179a214eSVinod Koulto complete before exiting. Note that if 'iterations' is set to 'infinite' then 98179a214eSVinod Koulwaiting is disabled. 99179a214eSVinod Koul 100bc1287b9SAndy ShevchenkoExample:: 101179a214eSVinod Koul 102179a214eSVinod Koul % modprobe dmatest run=1 iterations=42 wait=1 103179a214eSVinod Koul % modprobe -r dmatest 104179a214eSVinod Koul 105bc1287b9SAndy Shevchenko...or:: 106179a214eSVinod Koul 107179a214eSVinod Koul % modprobe dmatest run=1 iterations=42 108179a214eSVinod Koul % cat /sys/module/dmatest/parameters/wait 109179a214eSVinod Koul % modprobe -r dmatest 110179a214eSVinod Koul 111179a214eSVinod KoulPart 3 - When built-in in the kernel 112179a214eSVinod Koul==================================== 113179a214eSVinod Koul 114179a214eSVinod KoulThe module parameters that is supplied to the kernel command line will be used 115179a214eSVinod Koulfor the first performed test. After user gets a control, the test could be 116179a214eSVinod Koulre-run with the same or different parameters. For the details see the above 117bc1287b9SAndy Shevchenkosection `Part 2 - When dmatest is built as a module`_. 118179a214eSVinod Koul 119179a214eSVinod KoulIn both cases the module parameters are used as the actual values for the test 120179a214eSVinod Koulcase. You always could check them at run-time by running :: 121179a214eSVinod Koul 122179a214eSVinod Koul % grep -H . /sys/module/dmatest/parameters/* 123179a214eSVinod Koul 124179a214eSVinod KoulPart 4 - Gathering the test results 125179a214eSVinod Koul=================================== 126179a214eSVinod Koul 127bc1287b9SAndy ShevchenkoTest results are printed to the kernel log buffer with the format:: 128179a214eSVinod Koul 129179a214eSVinod Koul "dmatest: result <channel>: <test id>: '<error msg>' with src_off=<val> dst_off=<val> len=<val> (<err code>)" 130179a214eSVinod Koul 131bc1287b9SAndy ShevchenkoExample of output:: 132179a214eSVinod Koul 133179a214eSVinod Koul % dmesg | tail -n 1 134179a214eSVinod Koul dmatest: result dma0chan0-copy0: #1: No errors with src_off=0x7bf dst_off=0x8ad len=0x3fea (0) 135179a214eSVinod Koul 1367af8c46dSAndy ShevchenkoThe message format is unified across the different types of errors. A 1377af8c46dSAndy Shevchenkonumber in the parentheses represents additional information, e.g. error 1387af8c46dSAndy Shevchenkocode, error counter, or status. A test thread also emits a summary line at 1397af8c46dSAndy Shevchenkocompletion listing the number of tests executed, number that failed, and a 1407af8c46dSAndy Shevchenkoresult code. 141179a214eSVinod Koul 142bc1287b9SAndy ShevchenkoExample:: 143179a214eSVinod Koul 144179a214eSVinod Koul % dmesg | tail -n 1 145179a214eSVinod Koul dmatest: dma0chan0-copy0: summary 1 test, 0 failures 1000 iops 100000 KB/s (0) 146179a214eSVinod Koul 147179a214eSVinod KoulThe details of a data miscompare error are also emitted, but do not follow the 148179a214eSVinod Koulabove format. 149f80f9988SSeraj Alijan 150f80f9988SSeraj AlijanPart 5 - Handling channel allocation 151f80f9988SSeraj Alijan==================================== 152f80f9988SSeraj Alijan 153f80f9988SSeraj AlijanAllocating Channels 154f80f9988SSeraj Alijan------------------- 155f80f9988SSeraj Alijan 156c61d7b2eSDaniel ThompsonChannels do not need to be configured prior to starting a test run. Attempting 157c61d7b2eSDaniel Thompsonto run the test without configuring the channels will result in testing any 158c61d7b2eSDaniel Thompsonchannels that are available. 159f80f9988SSeraj Alijan 160f80f9988SSeraj AlijanExample:: 161f80f9988SSeraj Alijan 162f80f9988SSeraj Alijan % echo 1 > /sys/module/dmatest/parameters/run 163c61d7b2eSDaniel Thompson dmatest: No channels configured, continue with any 164f80f9988SSeraj Alijan 165f80f9988SSeraj AlijanChannels are registered using the "channel" parameter. Channels can be requested by their 166f80f9988SSeraj Alijanname, once requested, the channel is registered and a pending thread is added to the test list. 167f80f9988SSeraj Alijan 168f80f9988SSeraj AlijanExample:: 169f80f9988SSeraj Alijan 170f80f9988SSeraj Alijan % echo dma0chan2 > /sys/module/dmatest/parameters/channel 171f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan2 172f80f9988SSeraj Alijan 173f80f9988SSeraj AlijanMore channels can be added by repeating the example above. 174f80f9988SSeraj AlijanReading back the channel parameter will return the name of last channel that was added successfully. 175f80f9988SSeraj Alijan 176f80f9988SSeraj AlijanExample:: 177f80f9988SSeraj Alijan 178f80f9988SSeraj Alijan % echo dma0chan1 > /sys/module/dmatest/parameters/channel 179f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan1 180f80f9988SSeraj Alijan % echo dma0chan2 > /sys/module/dmatest/parameters/channel 181f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan2 182f80f9988SSeraj Alijan % cat /sys/module/dmatest/parameters/channel 183f80f9988SSeraj Alijan dma0chan2 184f80f9988SSeraj Alijan 185f80f9988SSeraj AlijanAnother method of requesting channels is to request a channel with an empty string, Doing so 186f80f9988SSeraj Alijanwill request all channels available to be tested: 187f80f9988SSeraj Alijan 188f80f9988SSeraj AlijanExample:: 189f80f9988SSeraj Alijan 190f80f9988SSeraj Alijan % echo "" > /sys/module/dmatest/parameters/channel 191f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan0 192f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan3 193f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan4 194f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan5 195f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan6 196f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan7 197f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan8 198f80f9988SSeraj Alijan 199f80f9988SSeraj AlijanAt any point during the test configuration, reading the "test_list" parameter will 200f80f9988SSeraj Alijanprint the list of currently pending tests. 201f80f9988SSeraj Alijan 202f80f9988SSeraj AlijanExample:: 203f80f9988SSeraj Alijan 204f80f9988SSeraj Alijan % cat /sys/module/dmatest/parameters/test_list 205f80f9988SSeraj Alijan dmatest: 1 threads using dma0chan0 206f80f9988SSeraj Alijan dmatest: 1 threads using dma0chan3 207f80f9988SSeraj Alijan dmatest: 1 threads using dma0chan4 208f80f9988SSeraj Alijan dmatest: 1 threads using dma0chan5 209f80f9988SSeraj Alijan dmatest: 1 threads using dma0chan6 210f80f9988SSeraj Alijan dmatest: 1 threads using dma0chan7 211f80f9988SSeraj Alijan dmatest: 1 threads using dma0chan8 212f80f9988SSeraj Alijan 213f80f9988SSeraj AlijanNote: Channels will have to be configured for each test run as channel configurations do not 214f80f9988SSeraj Alijancarry across to the next test run. 215f80f9988SSeraj Alijan 216f80f9988SSeraj AlijanReleasing Channels 217f80f9988SSeraj Alijan------------------- 218f80f9988SSeraj Alijan 219f80f9988SSeraj AlijanChannels can be freed by setting run to 0. 220f80f9988SSeraj Alijan 221f80f9988SSeraj AlijanExample:: 2229dcb98a2SHook, Gary 223f80f9988SSeraj Alijan % echo dma0chan1 > /sys/module/dmatest/parameters/channel 224f80f9988SSeraj Alijan dmatest: Added 1 threads using dma0chan1 225f80f9988SSeraj Alijan % cat /sys/class/dma/dma0chan1/in_use 226f80f9988SSeraj Alijan 1 227f80f9988SSeraj Alijan % echo 0 > /sys/module/dmatest/parameters/run 228f80f9988SSeraj Alijan % cat /sys/class/dma/dma0chan1/in_use 229f80f9988SSeraj Alijan 0 230f80f9988SSeraj Alijan 231f80f9988SSeraj AlijanChannels allocated by previous test runs are automatically freed when a new 232f80f9988SSeraj Alijanchannel is requested after completing a successful test run. 233