1 .. SPDX-License-Identifier: GPL-2.0 2 3 ======================== 4 MMC Test Framework 5 ======================== 6 7 Overview 8 ======== 9 10 The `mmc_test` framework is designed to test the performance and reliability of host controller drivers and all devices handled by the MMC subsystem. This includes not only MMC devices but also SD cards and other devices supported by the subsystem. 11 12 The framework provides a variety of tests to evaluate different aspects of the host controller and device interactions, such as read and write performance, data integrity, and error handling. These tests help ensure that the host controller drivers and devices operate correctly under various conditions. 13 14 The `mmc_test` framework is particularly useful for: 15 16 - Verifying the functionality and performance of MMC and SD host controller drivers. 17 - Ensuring compatibility and reliability of MMC and SD devices. 18 - Identifying and diagnosing issues in the MMC subsystem. 19 20 The results of the tests are logged in the kernel log, providing detailed information about the test outcomes and any encountered issues. 21 22 Note: whatever is on your card will be overwritten by these tests. 23 24 Initialization 25 ============== 26 27 To use the ``mmc_test`` framework, follow these steps: 28 29 1. **Enable the MMC Test Framework**: 30 31 Ensure that the ``CONFIG_MMC_TEST`` kernel configuration option is enabled. This can be done by configuring the kernel: 32 33 .. code-block:: none 34 35 make menuconfig 36 37 Navigate to: 38 39 Device Drivers ---> 40 <*> MMC/SD/SDIO card support ---> 41 [*] MMC host test driver 42 43 Alternatively, you can enable it directly in the kernel configuration file: 44 45 .. code-block:: none 46 47 echo "CONFIG_MMC_TEST=y" >> .config 48 49 Rebuild and install the kernel if necessary. 50 51 2. **Load the MMC Test Module**: 52 53 If the ``mmc_test`` framework is built as a module, you need to load it using ``modprobe``: 54 55 .. code-block:: none 56 57 modprobe mmc_test 58 59 Binding the MMC Card for Testing 60 ================================ 61 62 To enable MMC testing, you need to unbind the MMC card from the ``mmcblk`` driver and bind it to the ``mmc_test`` driver. This allows the ``mmc_test`` framework to take control of the MMC card for testing purposes. 63 64 1. Identify the MMC card: 65 66 .. code-block:: sh 67 68 ls /sys/bus/mmc/devices/ 69 70 This will list the MMC devices, such as ``mmc0:0001``. 71 72 2. Unbind the MMC card from the ``mmcblk`` driver: 73 74 .. code-block:: sh 75 76 echo 'mmc0:0001' > /sys/bus/mmc/drivers/mmcblk/unbind 77 78 3. Bind the MMC card to the ``mmc_test`` driver: 79 80 .. code-block:: sh 81 82 echo 'mmc0:0001' > /sys/bus/mmc/drivers/mmc_test/bind 83 84 After binding, you should see a line in the kernel log indicating that the card has been claimed for testing: 85 86 .. code-block:: none 87 88 mmc_test mmc0:0001: Card claimed for testing. 89 90 91 Usage - Debugfs Entries 92 ======================= 93 94 Once the ``mmc_test`` framework is enabled, you can interact with the following debugfs entries located in ``/sys/kernel/debug/mmc0/mmc0:0001``: 95 96 1. **test**: 97 98 This file is used to run specific tests. Write the test number to this file to execute a test. 99 100 .. code-block:: sh 101 102 echo <test_number> > /sys/kernel/debug/mmc0/mmc0:0001/test 103 104 The test result is indicated in the kernel log info. You can view the kernel log using the `dmesg` command or by checking the log file in `/var/log/`. 105 106 .. code-block:: sh 107 108 dmesg | grep mmc0 109 110 Example: 111 112 To run test number 4 (Basic read with data verification): 113 114 .. code-block:: sh 115 116 echo 4 > /sys/kernel/debug/mmc0/mmc0:0001/test 117 118 Check the kernel log for the result: 119 120 .. code-block:: sh 121 122 dmesg | grep mmc0 123 124 2. **testlist**: 125 126 This file lists all available tests. You can read this file to see the list of tests and their corresponding numbers. 127 128 .. code-block:: sh 129 130 cat /sys/kernel/debug/mmc0/mmc0:0001/testlist 131 132 The available tests are listed in the table below: 133 134 +------+--------------------------------+---------------------------------------------+ 135 | Test | Test Name | Test Description | 136 +======+================================+=============================================+ 137 | 0 | Run all tests | Runs all available tests | 138 +------+--------------------------------+---------------------------------------------+ 139 | 1 | Basic write | Performs a basic write operation of a | 140 | | | single 512-Byte block to the MMC card | 141 | | | without data verification. | 142 +------+--------------------------------+---------------------------------------------+ 143 | 2 | Basic read | Same for read | 144 +------+--------------------------------+---------------------------------------------+ 145 | 3 | Basic write | Performs a basic write operation of a | 146 | | (with data verification) | single 512-Byte block to the MMC card | 147 | | | with data verification by reading back | 148 | | | the written data and comparing it. | 149 +------+--------------------------------+---------------------------------------------+ 150 | 4 | Basic read | Same for read | 151 | | (with data verification) | | 152 +------+--------------------------------+---------------------------------------------+ 153 | 5 | Multi-block write | Performs a multi-block write operation of | 154 | | | 8 blocks (each 512 bytes) to the MMC card. | 155 +------+--------------------------------+---------------------------------------------+ 156 | 6 | Multi-block read | Same for read | 157 +------+--------------------------------+---------------------------------------------+ 158 | 7 | Power of two block writes | Performs write operations with block sizes | 159 | | | that are powers of two, starting from 1 | 160 | | | byte up to 256 bytes, to the MMC card. | 161 +------+--------------------------------+---------------------------------------------+ 162 | 8 | Power of two block reads | Same for read | 163 +------+--------------------------------+---------------------------------------------+ 164 | 9 | Weird sized block writes | Performs write operations with varying | 165 | | | block sizes starting from 3 bytes and | 166 | | | increasing by 7 bytes each iteration, up | 167 | | | to 511 bytes, to the MMC card. | 168 +------+--------------------------------+---------------------------------------------+ 169 | 10 | Weird sized block reads | same for read | 170 +------+--------------------------------+---------------------------------------------+ 171 | 11 | Badly aligned write | Performs write operations with buffers | 172 | | | starting at different alignments (0 to 7 | 173 | | | bytes offset) to test how the MMC card | 174 | | | handles unaligned data transfers. | 175 +------+--------------------------------+---------------------------------------------+ 176 | 12 | Badly aligned read | same for read | 177 +------+--------------------------------+---------------------------------------------+ 178 | 13 | Badly aligned multi-block write| same for multi-write | 179 +------+--------------------------------+---------------------------------------------+ 180 | 14 | Badly aligned multi-block read | same for multi-read | 181 +------+--------------------------------+---------------------------------------------+ 182 | 15 | Proper xfer_size at write | intentionally create a broken transfer by | 183 | | (Start failure) | modifying the MMC request in a way that it | 184 | | | will not perform as expected, e.g. use | 185 | | | MMC_WRITE_BLOCK for a multi-block transfer | 186 +------+--------------------------------+---------------------------------------------+ 187 | 16 | Proper xfer_size at read | same for read | 188 | | (Start failure) | | 189 +------+--------------------------------+---------------------------------------------+ 190 | 17 | Proper xfer_size at write | same for 2 blocks | 191 | | (Midway failure) | | 192 +------+--------------------------------+---------------------------------------------+ 193 | 18 | Proper xfer_size at read | same for read | 194 | | (Midway failure) | | 195 +------+--------------------------------+---------------------------------------------+ 196 | 19 | Highmem write | use a high memory page | 197 +------+--------------------------------+---------------------------------------------+ 198 | 20 | Highmem read | same for read | 199 +------+--------------------------------+---------------------------------------------+ 200 | 21 | Multi-block highmem write | same for multi-write | 201 +------+--------------------------------+---------------------------------------------+ 202 | 22 | Multi-block highmem read | same for mult-read | 203 +------+--------------------------------+---------------------------------------------+ 204 | 23 | Best-case read performance | Performs 512K sequential read (non sg) | 205 +------+--------------------------------+---------------------------------------------+ 206 | 24 | Best-case write performance | same for write | 207 +------+--------------------------------+---------------------------------------------+ 208 | 25 | Best-case read performance | Same using sg | 209 | | (Into scattered pages) | | 210 +------+--------------------------------+---------------------------------------------+ 211 | 26 | Best-case write performance | same for write | 212 | | (From scattered pages) | | 213 +------+--------------------------------+---------------------------------------------+ 214 | 27 | Single read performance | By transfer size | 215 +------+--------------------------------+---------------------------------------------+ 216 | 28 | Single write performance | By transfer size | 217 +------+--------------------------------+---------------------------------------------+ 218 | 29 | Single trim performance | By transfer size | 219 +------+--------------------------------+---------------------------------------------+ 220 | 30 | Consecutive read performance | By transfer size | 221 +------+--------------------------------+---------------------------------------------+ 222 | 31 | Consecutive write performance | By transfer size | 223 +------+--------------------------------+---------------------------------------------+ 224 | 32 | Consecutive trim performance | By transfer size | 225 +------+--------------------------------+---------------------------------------------+ 226 | 33 | Random read performance | By transfer size | 227 +------+--------------------------------+---------------------------------------------+ 228 | 34 | Random write performance | By transfer size | 229 +------+--------------------------------+---------------------------------------------+ 230 | 35 | Large sequential read | Into scattered pages | 231 +------+--------------------------------+---------------------------------------------+ 232 | 36 | Large sequential write | From scattered pages | 233 +------+--------------------------------+---------------------------------------------+ 234 | 37 | Write performance | With blocking req 4k to 4MB | 235 +------+--------------------------------+---------------------------------------------+ 236 | 38 | Write performance | With non-blocking req 4k to 4MB | 237 +------+--------------------------------+---------------------------------------------+ 238 | 39 | Read performance | With blocking req 4k to 4MB | 239 +------+--------------------------------+---------------------------------------------+ 240 | 40 | Read performance | With non-blocking req 4k to 4MB | 241 +------+--------------------------------+---------------------------------------------+ 242 | 41 | Write performance | Blocking req 1 to 512 sg elems | 243 +------+--------------------------------+---------------------------------------------+ 244 | 42 | Write performance | Non-blocking req 1 to 512 sg elems | 245 +------+--------------------------------+---------------------------------------------+ 246 | 43 | Read performance | Blocking req 1 to 512 sg elems | 247 +------+--------------------------------+---------------------------------------------+ 248 | 44 | Read performance | Non-blocking req 1 to 512 sg elems | 249 +------+--------------------------------+---------------------------------------------+ 250 | 45 | Reset test | | 251 +------+--------------------------------+---------------------------------------------+ 252 | 46 | Commands during read | No Set Block Count (CMD23) | 253 +------+--------------------------------+---------------------------------------------+ 254 | 47 | Commands during write | No Set Block Count (CMD23) | 255 +------+--------------------------------+---------------------------------------------+ 256 | 48 | Commands during read | Use Set Block Count (CMD23) | 257 +------+--------------------------------+---------------------------------------------+ 258 | 49 | Commands during write | Use Set Block Count (CMD23) | 259 +------+--------------------------------+---------------------------------------------+ 260 | 50 | Commands during non-blocking | Read - use Set Block Count (CMD23) | 261 +------+--------------------------------+---------------------------------------------+ 262 | 51 | Commands during non-blocking | Write - use Set Block Count (CMD23) | 263 +------+--------------------------------+---------------------------------------------+ 264 265 Test Results 266 ============ 267 268 The results of the tests are logged in the kernel log. Each test logs the start, end, and result of the test. The possible results are: 269 270 - **OK**: The test completed successfully. 271 - **FAILED**: The test failed. 272 - **UNSUPPORTED (by host)**: The test is unsupported by the host. 273 - **UNSUPPORTED (by card)**: The test is unsupported by the card. 274 - **ERROR**: An error occurred during the test. 275 276 Example Kernel Log Output 277 ========================= 278 279 When running a test, you will see log entries similar to the following in the kernel log: 280 281 .. code-block:: none 282 283 [ 1234.567890] mmc0: Starting tests of card mmc0:0001... 284 [ 1234.567891] mmc0: Test case 4. Basic read (with data verification)... 285 [ 1234.567892] mmc0: Result: OK 286 [ 1234.567893] mmc0: Tests completed. 287 288 In this example, test case 4 (Basic read with data verification) was executed, and the result was OK. 289 290 291 Contributing 292 ============ 293 294 Contributions to the `mmc_test` framework are welcome. Please follow the standard Linux kernel contribution guidelines and submit patches to the appropriate maintainers. 295 296 Contact 297 ======= 298 299 For more information or to report issues, please contact the MMC subsystem maintainers.
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.