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