2 * linux/drivers/mmc/card/mmc_test.c
4 * Copyright 2007-2008 Pierre Ossman
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
12 #include <linux/mmc/core.h>
13 #include <linux/mmc/card.h>
14 #include <linux/mmc/host.h>
15 #include <linux/mmc/mmc.h>
16 #include <linux/slab.h>
17 #include <linux/device.h>
19 #include <linux/scatterlist.h>
20 #include <linux/swap.h> /* For nr_free_buffer_pages() */
21 #include <linux/list.h>
23 #include <linux/debugfs.h>
24 #include <linux/uaccess.h>
25 #include <linux/seq_file.h>
26 #include <linux/module.h>
30 #define RESULT_UNSUP_HOST 2
31 #define RESULT_UNSUP_CARD 3
33 #define BUFFER_ORDER 2
34 #define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER)
36 #define TEST_ALIGN_END 8
39 * Limit the test area size to the maximum MMC HC erase group size. Note that
40 * the maximum SD allocation unit size is just 4MiB.
42 #define TEST_AREA_MAX_SIZE (128 * 1024 * 1024)
45 * struct mmc_test_pages - pages allocated by 'alloc_pages()'.
46 * @page: first page in the allocation
47 * @order: order of the number of pages allocated
49 struct mmc_test_pages
{
55 * struct mmc_test_mem - allocated memory.
56 * @arr: array of allocations
57 * @cnt: number of allocations
60 struct mmc_test_pages
*arr
;
65 * struct mmc_test_area - information for performance tests.
66 * @max_sz: test area size (in bytes)
67 * @dev_addr: address on card at which to do performance tests
68 * @max_tfr: maximum transfer size allowed by driver (in bytes)
69 * @max_segs: maximum segments allowed by driver in scatterlist @sg
70 * @max_seg_sz: maximum segment size allowed by driver
71 * @blocks: number of (512 byte) blocks currently mapped by @sg
72 * @sg_len: length of currently mapped scatterlist @sg
73 * @mem: allocated memory
76 struct mmc_test_area
{
78 unsigned int dev_addr
;
80 unsigned int max_segs
;
81 unsigned int max_seg_sz
;
84 struct mmc_test_mem
*mem
;
85 struct scatterlist
*sg
;
89 * struct mmc_test_transfer_result - transfer results for performance tests.
90 * @link: double-linked list
91 * @count: amount of group of sectors to check
92 * @sectors: amount of sectors to check in one group
93 * @ts: time values of transfer
94 * @rate: calculated transfer rate
95 * @iops: I/O operations per second (times 100)
97 struct mmc_test_transfer_result
{
98 struct list_head link
;
100 unsigned int sectors
;
107 * struct mmc_test_general_result - results for tests.
108 * @link: double-linked list
109 * @card: card under test
110 * @testcase: number of test case
111 * @result: result of test run
112 * @tr_lst: transfer measurements if any as mmc_test_transfer_result
114 struct mmc_test_general_result
{
115 struct list_head link
;
116 struct mmc_card
*card
;
119 struct list_head tr_lst
;
123 * struct mmc_test_dbgfs_file - debugfs related file.
124 * @link: double-linked list
125 * @card: card under test
126 * @file: file created under debugfs
128 struct mmc_test_dbgfs_file
{
129 struct list_head link
;
130 struct mmc_card
*card
;
135 * struct mmc_test_card - test information.
136 * @card: card under test
137 * @scratch: transfer buffer
138 * @buffer: transfer buffer
139 * @highmem: buffer for highmem tests
140 * @area: information for performance tests
141 * @gr: pointer to results of current testcase
143 struct mmc_test_card
{
144 struct mmc_card
*card
;
146 u8 scratch
[BUFFER_SIZE
];
148 #ifdef CONFIG_HIGHMEM
149 struct page
*highmem
;
151 struct mmc_test_area area
;
152 struct mmc_test_general_result
*gr
;
155 enum mmc_test_prep_media
{
156 MMC_TEST_PREP_NONE
= 0,
157 MMC_TEST_PREP_WRITE_FULL
= 1 << 0,
158 MMC_TEST_PREP_ERASE
= 1 << 1,
161 struct mmc_test_multiple_rw
{
162 unsigned int *sg_len
;
167 bool do_nonblock_req
;
168 enum mmc_test_prep_media prepare
;
171 struct mmc_test_async_req
{
172 struct mmc_async_req areq
;
173 struct mmc_test_card
*test
;
176 /*******************************************************************/
177 /* General helper functions */
178 /*******************************************************************/
181 * Configure correct block size in card
183 static int mmc_test_set_blksize(struct mmc_test_card
*test
, unsigned size
)
185 return mmc_set_blocklen(test
->card
, size
);
189 * Fill in the mmc_request structure given a set of transfer parameters.
191 static void mmc_test_prepare_mrq(struct mmc_test_card
*test
,
192 struct mmc_request
*mrq
, struct scatterlist
*sg
, unsigned sg_len
,
193 unsigned dev_addr
, unsigned blocks
, unsigned blksz
, int write
)
195 BUG_ON(!mrq
|| !mrq
->cmd
|| !mrq
->data
|| !mrq
->stop
);
198 mrq
->cmd
->opcode
= write
?
199 MMC_WRITE_MULTIPLE_BLOCK
: MMC_READ_MULTIPLE_BLOCK
;
201 mrq
->cmd
->opcode
= write
?
202 MMC_WRITE_BLOCK
: MMC_READ_SINGLE_BLOCK
;
205 mrq
->cmd
->arg
= dev_addr
;
206 if (!mmc_card_blockaddr(test
->card
))
209 mrq
->cmd
->flags
= MMC_RSP_R1
| MMC_CMD_ADTC
;
214 mrq
->stop
->opcode
= MMC_STOP_TRANSMISSION
;
216 mrq
->stop
->flags
= MMC_RSP_R1B
| MMC_CMD_AC
;
219 mrq
->data
->blksz
= blksz
;
220 mrq
->data
->blocks
= blocks
;
221 mrq
->data
->flags
= write
? MMC_DATA_WRITE
: MMC_DATA_READ
;
223 mrq
->data
->sg_len
= sg_len
;
225 mmc_set_data_timeout(mrq
->data
, test
->card
);
228 static int mmc_test_busy(struct mmc_command
*cmd
)
230 return !(cmd
->resp
[0] & R1_READY_FOR_DATA
) ||
231 (R1_CURRENT_STATE(cmd
->resp
[0]) == R1_STATE_PRG
);
235 * Wait for the card to finish the busy state
237 static int mmc_test_wait_busy(struct mmc_test_card
*test
)
240 struct mmc_command cmd
= {0};
244 memset(&cmd
, 0, sizeof(struct mmc_command
));
246 cmd
.opcode
= MMC_SEND_STATUS
;
247 cmd
.arg
= test
->card
->rca
<< 16;
248 cmd
.flags
= MMC_RSP_R1
| MMC_CMD_AC
;
250 ret
= mmc_wait_for_cmd(test
->card
->host
, &cmd
, 0);
254 if (!busy
&& mmc_test_busy(&cmd
)) {
256 if (test
->card
->host
->caps
& MMC_CAP_WAIT_WHILE_BUSY
)
257 pr_info("%s: Warning: Host did not "
258 "wait for busy state to end.\n",
259 mmc_hostname(test
->card
->host
));
261 } while (mmc_test_busy(&cmd
));
267 * Transfer a single sector of kernel addressable data
269 static int mmc_test_buffer_transfer(struct mmc_test_card
*test
,
270 u8
*buffer
, unsigned addr
, unsigned blksz
, int write
)
274 struct mmc_request mrq
= {0};
275 struct mmc_command cmd
= {0};
276 struct mmc_command stop
= {0};
277 struct mmc_data data
= {0};
279 struct scatterlist sg
;
285 sg_init_one(&sg
, buffer
, blksz
);
287 mmc_test_prepare_mrq(test
, &mrq
, &sg
, 1, addr
, 1, blksz
, write
);
289 mmc_wait_for_req(test
->card
->host
, &mrq
);
296 ret
= mmc_test_wait_busy(test
);
303 static void mmc_test_free_mem(struct mmc_test_mem
*mem
)
308 __free_pages(mem
->arr
[mem
->cnt
].page
,
309 mem
->arr
[mem
->cnt
].order
);
315 * Allocate a lot of memory, preferably max_sz but at least min_sz. In case
316 * there isn't much memory do not exceed 1/16th total lowmem pages. Also do
317 * not exceed a maximum number of segments and try not to make segments much
318 * bigger than maximum segment size.
320 static struct mmc_test_mem
*mmc_test_alloc_mem(unsigned long min_sz
,
321 unsigned long max_sz
,
322 unsigned int max_segs
,
323 unsigned int max_seg_sz
)
325 unsigned long max_page_cnt
= DIV_ROUND_UP(max_sz
, PAGE_SIZE
);
326 unsigned long min_page_cnt
= DIV_ROUND_UP(min_sz
, PAGE_SIZE
);
327 unsigned long max_seg_page_cnt
= DIV_ROUND_UP(max_seg_sz
, PAGE_SIZE
);
328 unsigned long page_cnt
= 0;
329 unsigned long limit
= nr_free_buffer_pages() >> 4;
330 struct mmc_test_mem
*mem
;
332 if (max_page_cnt
> limit
)
333 max_page_cnt
= limit
;
334 if (min_page_cnt
> max_page_cnt
)
335 min_page_cnt
= max_page_cnt
;
337 if (max_seg_page_cnt
> max_page_cnt
)
338 max_seg_page_cnt
= max_page_cnt
;
340 if (max_segs
> max_page_cnt
)
341 max_segs
= max_page_cnt
;
343 mem
= kzalloc(sizeof(struct mmc_test_mem
), GFP_KERNEL
);
347 mem
->arr
= kzalloc(sizeof(struct mmc_test_pages
) * max_segs
,
352 while (max_page_cnt
) {
355 gfp_t flags
= GFP_KERNEL
| GFP_DMA
| __GFP_NOWARN
|
358 order
= get_order(max_seg_page_cnt
<< PAGE_SHIFT
);
360 page
= alloc_pages(flags
, order
);
366 if (page_cnt
< min_page_cnt
)
370 mem
->arr
[mem
->cnt
].page
= page
;
371 mem
->arr
[mem
->cnt
].order
= order
;
373 if (max_page_cnt
<= (1UL << order
))
375 max_page_cnt
-= 1UL << order
;
376 page_cnt
+= 1UL << order
;
377 if (mem
->cnt
>= max_segs
) {
378 if (page_cnt
< min_page_cnt
)
387 mmc_test_free_mem(mem
);
392 * Map memory into a scatterlist. Optionally allow the same memory to be
393 * mapped more than once.
395 static int mmc_test_map_sg(struct mmc_test_mem
*mem
, unsigned long size
,
396 struct scatterlist
*sglist
, int repeat
,
397 unsigned int max_segs
, unsigned int max_seg_sz
,
398 unsigned int *sg_len
, int min_sg_len
)
400 struct scatterlist
*sg
= NULL
;
402 unsigned long sz
= size
;
404 sg_init_table(sglist
, max_segs
);
405 if (min_sg_len
> max_segs
)
406 min_sg_len
= max_segs
;
410 for (i
= 0; i
< mem
->cnt
; i
++) {
411 unsigned long len
= PAGE_SIZE
<< mem
->arr
[i
].order
;
413 if (min_sg_len
&& (size
/ min_sg_len
< len
))
414 len
= ALIGN(size
/ min_sg_len
, 512);
417 if (len
> max_seg_sz
)
425 sg_set_page(sg
, mem
->arr
[i
].page
, len
, 0);
431 } while (sz
&& repeat
);
443 * Map memory into a scatterlist so that no pages are contiguous. Allow the
444 * same memory to be mapped more than once.
446 static int mmc_test_map_sg_max_scatter(struct mmc_test_mem
*mem
,
448 struct scatterlist
*sglist
,
449 unsigned int max_segs
,
450 unsigned int max_seg_sz
,
451 unsigned int *sg_len
)
453 struct scatterlist
*sg
= NULL
;
454 unsigned int i
= mem
->cnt
, cnt
;
456 void *base
, *addr
, *last_addr
= NULL
;
458 sg_init_table(sglist
, max_segs
);
462 base
= page_address(mem
->arr
[--i
].page
);
463 cnt
= 1 << mem
->arr
[i
].order
;
465 addr
= base
+ PAGE_SIZE
* --cnt
;
466 if (last_addr
&& last_addr
+ PAGE_SIZE
== addr
)
470 if (len
> max_seg_sz
)
480 sg_set_page(sg
, virt_to_page(addr
), len
, 0);
495 * Calculate transfer rate in bytes per second.
497 static unsigned int mmc_test_rate(uint64_t bytes
, struct timespec
*ts
)
507 while (ns
> UINT_MAX
) {
515 do_div(bytes
, (uint32_t)ns
);
521 * Save transfer results for future usage
523 static void mmc_test_save_transfer_result(struct mmc_test_card
*test
,
524 unsigned int count
, unsigned int sectors
, struct timespec ts
,
525 unsigned int rate
, unsigned int iops
)
527 struct mmc_test_transfer_result
*tr
;
532 tr
= kmalloc(sizeof(struct mmc_test_transfer_result
), GFP_KERNEL
);
537 tr
->sectors
= sectors
;
542 list_add_tail(&tr
->link
, &test
->gr
->tr_lst
);
546 * Print the transfer rate.
548 static void mmc_test_print_rate(struct mmc_test_card
*test
, uint64_t bytes
,
549 struct timespec
*ts1
, struct timespec
*ts2
)
551 unsigned int rate
, iops
, sectors
= bytes
>> 9;
554 ts
= timespec_sub(*ts2
, *ts1
);
556 rate
= mmc_test_rate(bytes
, &ts
);
557 iops
= mmc_test_rate(100, &ts
); /* I/O ops per sec x 100 */
559 pr_info("%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
560 "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
561 mmc_hostname(test
->card
->host
), sectors
, sectors
>> 1,
562 (sectors
& 1 ? ".5" : ""), (unsigned long)ts
.tv_sec
,
563 (unsigned long)ts
.tv_nsec
, rate
/ 1000, rate
/ 1024,
564 iops
/ 100, iops
% 100);
566 mmc_test_save_transfer_result(test
, 1, sectors
, ts
, rate
, iops
);
570 * Print the average transfer rate.
572 static void mmc_test_print_avg_rate(struct mmc_test_card
*test
, uint64_t bytes
,
573 unsigned int count
, struct timespec
*ts1
,
574 struct timespec
*ts2
)
576 unsigned int rate
, iops
, sectors
= bytes
>> 9;
577 uint64_t tot
= bytes
* count
;
580 ts
= timespec_sub(*ts2
, *ts1
);
582 rate
= mmc_test_rate(tot
, &ts
);
583 iops
= mmc_test_rate(count
* 100, &ts
); /* I/O ops per sec x 100 */
585 pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
586 "%lu.%09lu seconds (%u kB/s, %u KiB/s, "
587 "%u.%02u IOPS, sg_len %d)\n",
588 mmc_hostname(test
->card
->host
), count
, sectors
, count
,
589 sectors
>> 1, (sectors
& 1 ? ".5" : ""),
590 (unsigned long)ts
.tv_sec
, (unsigned long)ts
.tv_nsec
,
591 rate
/ 1000, rate
/ 1024, iops
/ 100, iops
% 100,
594 mmc_test_save_transfer_result(test
, count
, sectors
, ts
, rate
, iops
);
598 * Return the card size in sectors.
600 static unsigned int mmc_test_capacity(struct mmc_card
*card
)
602 if (!mmc_card_sd(card
) && mmc_card_blockaddr(card
))
603 return card
->ext_csd
.sectors
;
605 return card
->csd
.capacity
<< (card
->csd
.read_blkbits
- 9);
608 /*******************************************************************/
609 /* Test preparation and cleanup */
610 /*******************************************************************/
613 * Fill the first couple of sectors of the card with known data
614 * so that bad reads/writes can be detected
616 static int __mmc_test_prepare(struct mmc_test_card
*test
, int write
)
620 ret
= mmc_test_set_blksize(test
, 512);
625 memset(test
->buffer
, 0xDF, 512);
627 for (i
= 0;i
< 512;i
++)
631 for (i
= 0;i
< BUFFER_SIZE
/ 512;i
++) {
632 ret
= mmc_test_buffer_transfer(test
, test
->buffer
, i
, 512, 1);
640 static int mmc_test_prepare_write(struct mmc_test_card
*test
)
642 return __mmc_test_prepare(test
, 1);
645 static int mmc_test_prepare_read(struct mmc_test_card
*test
)
647 return __mmc_test_prepare(test
, 0);
650 static int mmc_test_cleanup(struct mmc_test_card
*test
)
654 ret
= mmc_test_set_blksize(test
, 512);
658 memset(test
->buffer
, 0, 512);
660 for (i
= 0;i
< BUFFER_SIZE
/ 512;i
++) {
661 ret
= mmc_test_buffer_transfer(test
, test
->buffer
, i
, 512, 1);
669 /*******************************************************************/
670 /* Test execution helpers */
671 /*******************************************************************/
674 * Modifies the mmc_request to perform the "short transfer" tests
676 static void mmc_test_prepare_broken_mrq(struct mmc_test_card
*test
,
677 struct mmc_request
*mrq
, int write
)
679 BUG_ON(!mrq
|| !mrq
->cmd
|| !mrq
->data
);
681 if (mrq
->data
->blocks
> 1) {
682 mrq
->cmd
->opcode
= write
?
683 MMC_WRITE_BLOCK
: MMC_READ_SINGLE_BLOCK
;
686 mrq
->cmd
->opcode
= MMC_SEND_STATUS
;
687 mrq
->cmd
->arg
= test
->card
->rca
<< 16;
692 * Checks that a normal transfer didn't have any errors
694 static int mmc_test_check_result(struct mmc_test_card
*test
,
695 struct mmc_request
*mrq
)
699 BUG_ON(!mrq
|| !mrq
->cmd
|| !mrq
->data
);
703 if (!ret
&& mrq
->cmd
->error
)
704 ret
= mrq
->cmd
->error
;
705 if (!ret
&& mrq
->data
->error
)
706 ret
= mrq
->data
->error
;
707 if (!ret
&& mrq
->stop
&& mrq
->stop
->error
)
708 ret
= mrq
->stop
->error
;
709 if (!ret
&& mrq
->data
->bytes_xfered
!=
710 mrq
->data
->blocks
* mrq
->data
->blksz
)
714 ret
= RESULT_UNSUP_HOST
;
719 static int mmc_test_check_result_async(struct mmc_card
*card
,
720 struct mmc_async_req
*areq
)
722 struct mmc_test_async_req
*test_async
=
723 container_of(areq
, struct mmc_test_async_req
, areq
);
725 mmc_test_wait_busy(test_async
->test
);
727 return mmc_test_check_result(test_async
->test
, areq
->mrq
);
731 * Checks that a "short transfer" behaved as expected
733 static int mmc_test_check_broken_result(struct mmc_test_card
*test
,
734 struct mmc_request
*mrq
)
738 BUG_ON(!mrq
|| !mrq
->cmd
|| !mrq
->data
);
742 if (!ret
&& mrq
->cmd
->error
)
743 ret
= mrq
->cmd
->error
;
744 if (!ret
&& mrq
->data
->error
== 0)
746 if (!ret
&& mrq
->data
->error
!= -ETIMEDOUT
)
747 ret
= mrq
->data
->error
;
748 if (!ret
&& mrq
->stop
&& mrq
->stop
->error
)
749 ret
= mrq
->stop
->error
;
750 if (mrq
->data
->blocks
> 1) {
751 if (!ret
&& mrq
->data
->bytes_xfered
> mrq
->data
->blksz
)
754 if (!ret
&& mrq
->data
->bytes_xfered
> 0)
759 ret
= RESULT_UNSUP_HOST
;
765 * Tests nonblock transfer with certain parameters
767 static void mmc_test_nonblock_reset(struct mmc_request
*mrq
,
768 struct mmc_command
*cmd
,
769 struct mmc_command
*stop
,
770 struct mmc_data
*data
)
772 memset(mrq
, 0, sizeof(struct mmc_request
));
773 memset(cmd
, 0, sizeof(struct mmc_command
));
774 memset(data
, 0, sizeof(struct mmc_data
));
775 memset(stop
, 0, sizeof(struct mmc_command
));
781 static int mmc_test_nonblock_transfer(struct mmc_test_card
*test
,
782 struct scatterlist
*sg
, unsigned sg_len
,
783 unsigned dev_addr
, unsigned blocks
,
784 unsigned blksz
, int write
, int count
)
786 struct mmc_request mrq1
;
787 struct mmc_command cmd1
;
788 struct mmc_command stop1
;
789 struct mmc_data data1
;
791 struct mmc_request mrq2
;
792 struct mmc_command cmd2
;
793 struct mmc_command stop2
;
794 struct mmc_data data2
;
796 struct mmc_test_async_req test_areq
[2];
797 struct mmc_async_req
*done_areq
;
798 struct mmc_async_req
*cur_areq
= &test_areq
[0].areq
;
799 struct mmc_async_req
*other_areq
= &test_areq
[1].areq
;
803 test_areq
[0].test
= test
;
804 test_areq
[1].test
= test
;
806 mmc_test_nonblock_reset(&mrq1
, &cmd1
, &stop1
, &data1
);
807 mmc_test_nonblock_reset(&mrq2
, &cmd2
, &stop2
, &data2
);
809 cur_areq
->mrq
= &mrq1
;
810 cur_areq
->err_check
= mmc_test_check_result_async
;
811 other_areq
->mrq
= &mrq2
;
812 other_areq
->err_check
= mmc_test_check_result_async
;
814 for (i
= 0; i
< count
; i
++) {
815 mmc_test_prepare_mrq(test
, cur_areq
->mrq
, sg
, sg_len
, dev_addr
,
816 blocks
, blksz
, write
);
817 done_areq
= mmc_start_req(test
->card
->host
, cur_areq
, &ret
);
819 if (ret
|| (!done_areq
&& i
> 0))
823 if (done_areq
->mrq
== &mrq2
)
824 mmc_test_nonblock_reset(&mrq2
, &cmd2
,
827 mmc_test_nonblock_reset(&mrq1
, &cmd1
,
830 done_areq
= cur_areq
;
831 cur_areq
= other_areq
;
832 other_areq
= done_areq
;
836 done_areq
= mmc_start_req(test
->card
->host
, NULL
, &ret
);
844 * Tests a basic transfer with certain parameters
846 static int mmc_test_simple_transfer(struct mmc_test_card
*test
,
847 struct scatterlist
*sg
, unsigned sg_len
, unsigned dev_addr
,
848 unsigned blocks
, unsigned blksz
, int write
)
850 struct mmc_request mrq
= {0};
851 struct mmc_command cmd
= {0};
852 struct mmc_command stop
= {0};
853 struct mmc_data data
= {0};
859 mmc_test_prepare_mrq(test
, &mrq
, sg
, sg_len
, dev_addr
,
860 blocks
, blksz
, write
);
862 mmc_wait_for_req(test
->card
->host
, &mrq
);
864 mmc_test_wait_busy(test
);
866 return mmc_test_check_result(test
, &mrq
);
870 * Tests a transfer where the card will fail completely or partly
872 static int mmc_test_broken_transfer(struct mmc_test_card
*test
,
873 unsigned blocks
, unsigned blksz
, int write
)
875 struct mmc_request mrq
= {0};
876 struct mmc_command cmd
= {0};
877 struct mmc_command stop
= {0};
878 struct mmc_data data
= {0};
880 struct scatterlist sg
;
886 sg_init_one(&sg
, test
->buffer
, blocks
* blksz
);
888 mmc_test_prepare_mrq(test
, &mrq
, &sg
, 1, 0, blocks
, blksz
, write
);
889 mmc_test_prepare_broken_mrq(test
, &mrq
, write
);
891 mmc_wait_for_req(test
->card
->host
, &mrq
);
893 mmc_test_wait_busy(test
);
895 return mmc_test_check_broken_result(test
, &mrq
);
899 * Does a complete transfer test where data is also validated
901 * Note: mmc_test_prepare() must have been done before this call
903 static int mmc_test_transfer(struct mmc_test_card
*test
,
904 struct scatterlist
*sg
, unsigned sg_len
, unsigned dev_addr
,
905 unsigned blocks
, unsigned blksz
, int write
)
911 for (i
= 0;i
< blocks
* blksz
;i
++)
912 test
->scratch
[i
] = i
;
914 memset(test
->scratch
, 0, BUFFER_SIZE
);
916 local_irq_save(flags
);
917 sg_copy_from_buffer(sg
, sg_len
, test
->scratch
, BUFFER_SIZE
);
918 local_irq_restore(flags
);
920 ret
= mmc_test_set_blksize(test
, blksz
);
924 ret
= mmc_test_simple_transfer(test
, sg
, sg_len
, dev_addr
,
925 blocks
, blksz
, write
);
932 ret
= mmc_test_set_blksize(test
, 512);
936 sectors
= (blocks
* blksz
+ 511) / 512;
937 if ((sectors
* 512) == (blocks
* blksz
))
940 if ((sectors
* 512) > BUFFER_SIZE
)
943 memset(test
->buffer
, 0, sectors
* 512);
945 for (i
= 0;i
< sectors
;i
++) {
946 ret
= mmc_test_buffer_transfer(test
,
947 test
->buffer
+ i
* 512,
948 dev_addr
+ i
, 512, 0);
953 for (i
= 0;i
< blocks
* blksz
;i
++) {
954 if (test
->buffer
[i
] != (u8
)i
)
958 for (;i
< sectors
* 512;i
++) {
959 if (test
->buffer
[i
] != 0xDF)
963 local_irq_save(flags
);
964 sg_copy_to_buffer(sg
, sg_len
, test
->scratch
, BUFFER_SIZE
);
965 local_irq_restore(flags
);
966 for (i
= 0;i
< blocks
* blksz
;i
++) {
967 if (test
->scratch
[i
] != (u8
)i
)
975 /*******************************************************************/
977 /*******************************************************************/
979 struct mmc_test_case
{
982 int (*prepare
)(struct mmc_test_card
*);
983 int (*run
)(struct mmc_test_card
*);
984 int (*cleanup
)(struct mmc_test_card
*);
987 static int mmc_test_basic_write(struct mmc_test_card
*test
)
990 struct scatterlist sg
;
992 ret
= mmc_test_set_blksize(test
, 512);
996 sg_init_one(&sg
, test
->buffer
, 512);
998 ret
= mmc_test_simple_transfer(test
, &sg
, 1, 0, 1, 512, 1);
1005 static int mmc_test_basic_read(struct mmc_test_card
*test
)
1008 struct scatterlist sg
;
1010 ret
= mmc_test_set_blksize(test
, 512);
1014 sg_init_one(&sg
, test
->buffer
, 512);
1016 ret
= mmc_test_simple_transfer(test
, &sg
, 1, 0, 1, 512, 0);
1023 static int mmc_test_verify_write(struct mmc_test_card
*test
)
1026 struct scatterlist sg
;
1028 sg_init_one(&sg
, test
->buffer
, 512);
1030 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 1);
1037 static int mmc_test_verify_read(struct mmc_test_card
*test
)
1040 struct scatterlist sg
;
1042 sg_init_one(&sg
, test
->buffer
, 512);
1044 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 0);
1051 static int mmc_test_multi_write(struct mmc_test_card
*test
)
1055 struct scatterlist sg
;
1057 if (test
->card
->host
->max_blk_count
== 1)
1058 return RESULT_UNSUP_HOST
;
1060 size
= PAGE_SIZE
* 2;
1061 size
= min(size
, test
->card
->host
->max_req_size
);
1062 size
= min(size
, test
->card
->host
->max_seg_size
);
1063 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1066 return RESULT_UNSUP_HOST
;
1068 sg_init_one(&sg
, test
->buffer
, size
);
1070 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 1);
1077 static int mmc_test_multi_read(struct mmc_test_card
*test
)
1081 struct scatterlist sg
;
1083 if (test
->card
->host
->max_blk_count
== 1)
1084 return RESULT_UNSUP_HOST
;
1086 size
= PAGE_SIZE
* 2;
1087 size
= min(size
, test
->card
->host
->max_req_size
);
1088 size
= min(size
, test
->card
->host
->max_seg_size
);
1089 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1092 return RESULT_UNSUP_HOST
;
1094 sg_init_one(&sg
, test
->buffer
, size
);
1096 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 0);
1103 static int mmc_test_pow2_write(struct mmc_test_card
*test
)
1106 struct scatterlist sg
;
1108 if (!test
->card
->csd
.write_partial
)
1109 return RESULT_UNSUP_CARD
;
1111 for (i
= 1; i
< 512;i
<<= 1) {
1112 sg_init_one(&sg
, test
->buffer
, i
);
1113 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, i
, 1);
1121 static int mmc_test_pow2_read(struct mmc_test_card
*test
)
1124 struct scatterlist sg
;
1126 if (!test
->card
->csd
.read_partial
)
1127 return RESULT_UNSUP_CARD
;
1129 for (i
= 1; i
< 512;i
<<= 1) {
1130 sg_init_one(&sg
, test
->buffer
, i
);
1131 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, i
, 0);
1139 static int mmc_test_weird_write(struct mmc_test_card
*test
)
1142 struct scatterlist sg
;
1144 if (!test
->card
->csd
.write_partial
)
1145 return RESULT_UNSUP_CARD
;
1147 for (i
= 3; i
< 512;i
+= 7) {
1148 sg_init_one(&sg
, test
->buffer
, i
);
1149 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, i
, 1);
1157 static int mmc_test_weird_read(struct mmc_test_card
*test
)
1160 struct scatterlist sg
;
1162 if (!test
->card
->csd
.read_partial
)
1163 return RESULT_UNSUP_CARD
;
1165 for (i
= 3; i
< 512;i
+= 7) {
1166 sg_init_one(&sg
, test
->buffer
, i
);
1167 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, i
, 0);
1175 static int mmc_test_align_write(struct mmc_test_card
*test
)
1178 struct scatterlist sg
;
1180 for (i
= 1; i
< TEST_ALIGN_END
; i
++) {
1181 sg_init_one(&sg
, test
->buffer
+ i
, 512);
1182 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 1);
1190 static int mmc_test_align_read(struct mmc_test_card
*test
)
1193 struct scatterlist sg
;
1195 for (i
= 1; i
< TEST_ALIGN_END
; i
++) {
1196 sg_init_one(&sg
, test
->buffer
+ i
, 512);
1197 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 0);
1205 static int mmc_test_align_multi_write(struct mmc_test_card
*test
)
1209 struct scatterlist sg
;
1211 if (test
->card
->host
->max_blk_count
== 1)
1212 return RESULT_UNSUP_HOST
;
1214 size
= PAGE_SIZE
* 2;
1215 size
= min(size
, test
->card
->host
->max_req_size
);
1216 size
= min(size
, test
->card
->host
->max_seg_size
);
1217 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1220 return RESULT_UNSUP_HOST
;
1222 for (i
= 1; i
< TEST_ALIGN_END
; i
++) {
1223 sg_init_one(&sg
, test
->buffer
+ i
, size
);
1224 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 1);
1232 static int mmc_test_align_multi_read(struct mmc_test_card
*test
)
1236 struct scatterlist sg
;
1238 if (test
->card
->host
->max_blk_count
== 1)
1239 return RESULT_UNSUP_HOST
;
1241 size
= PAGE_SIZE
* 2;
1242 size
= min(size
, test
->card
->host
->max_req_size
);
1243 size
= min(size
, test
->card
->host
->max_seg_size
);
1244 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1247 return RESULT_UNSUP_HOST
;
1249 for (i
= 1; i
< TEST_ALIGN_END
; i
++) {
1250 sg_init_one(&sg
, test
->buffer
+ i
, size
);
1251 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 0);
1259 static int mmc_test_xfersize_write(struct mmc_test_card
*test
)
1263 ret
= mmc_test_set_blksize(test
, 512);
1267 ret
= mmc_test_broken_transfer(test
, 1, 512, 1);
1274 static int mmc_test_xfersize_read(struct mmc_test_card
*test
)
1278 ret
= mmc_test_set_blksize(test
, 512);
1282 ret
= mmc_test_broken_transfer(test
, 1, 512, 0);
1289 static int mmc_test_multi_xfersize_write(struct mmc_test_card
*test
)
1293 if (test
->card
->host
->max_blk_count
== 1)
1294 return RESULT_UNSUP_HOST
;
1296 ret
= mmc_test_set_blksize(test
, 512);
1300 ret
= mmc_test_broken_transfer(test
, 2, 512, 1);
1307 static int mmc_test_multi_xfersize_read(struct mmc_test_card
*test
)
1311 if (test
->card
->host
->max_blk_count
== 1)
1312 return RESULT_UNSUP_HOST
;
1314 ret
= mmc_test_set_blksize(test
, 512);
1318 ret
= mmc_test_broken_transfer(test
, 2, 512, 0);
1325 #ifdef CONFIG_HIGHMEM
1327 static int mmc_test_write_high(struct mmc_test_card
*test
)
1330 struct scatterlist sg
;
1332 sg_init_table(&sg
, 1);
1333 sg_set_page(&sg
, test
->highmem
, 512, 0);
1335 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 1);
1342 static int mmc_test_read_high(struct mmc_test_card
*test
)
1345 struct scatterlist sg
;
1347 sg_init_table(&sg
, 1);
1348 sg_set_page(&sg
, test
->highmem
, 512, 0);
1350 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 0);
1357 static int mmc_test_multi_write_high(struct mmc_test_card
*test
)
1361 struct scatterlist sg
;
1363 if (test
->card
->host
->max_blk_count
== 1)
1364 return RESULT_UNSUP_HOST
;
1366 size
= PAGE_SIZE
* 2;
1367 size
= min(size
, test
->card
->host
->max_req_size
);
1368 size
= min(size
, test
->card
->host
->max_seg_size
);
1369 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1372 return RESULT_UNSUP_HOST
;
1374 sg_init_table(&sg
, 1);
1375 sg_set_page(&sg
, test
->highmem
, size
, 0);
1377 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 1);
1384 static int mmc_test_multi_read_high(struct mmc_test_card
*test
)
1388 struct scatterlist sg
;
1390 if (test
->card
->host
->max_blk_count
== 1)
1391 return RESULT_UNSUP_HOST
;
1393 size
= PAGE_SIZE
* 2;
1394 size
= min(size
, test
->card
->host
->max_req_size
);
1395 size
= min(size
, test
->card
->host
->max_seg_size
);
1396 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1399 return RESULT_UNSUP_HOST
;
1401 sg_init_table(&sg
, 1);
1402 sg_set_page(&sg
, test
->highmem
, size
, 0);
1404 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 0);
1413 static int mmc_test_no_highmem(struct mmc_test_card
*test
)
1415 pr_info("%s: Highmem not configured - test skipped\n",
1416 mmc_hostname(test
->card
->host
));
1420 #endif /* CONFIG_HIGHMEM */
1423 * Map sz bytes so that it can be transferred.
1425 static int mmc_test_area_map(struct mmc_test_card
*test
, unsigned long sz
,
1426 int max_scatter
, int min_sg_len
)
1428 struct mmc_test_area
*t
= &test
->area
;
1431 t
->blocks
= sz
>> 9;
1434 err
= mmc_test_map_sg_max_scatter(t
->mem
, sz
, t
->sg
,
1435 t
->max_segs
, t
->max_seg_sz
,
1438 err
= mmc_test_map_sg(t
->mem
, sz
, t
->sg
, 1, t
->max_segs
,
1439 t
->max_seg_sz
, &t
->sg_len
, min_sg_len
);
1442 pr_info("%s: Failed to map sg list\n",
1443 mmc_hostname(test
->card
->host
));
1448 * Transfer bytes mapped by mmc_test_area_map().
1450 static int mmc_test_area_transfer(struct mmc_test_card
*test
,
1451 unsigned int dev_addr
, int write
)
1453 struct mmc_test_area
*t
= &test
->area
;
1455 return mmc_test_simple_transfer(test
, t
->sg
, t
->sg_len
, dev_addr
,
1456 t
->blocks
, 512, write
);
1460 * Map and transfer bytes for multiple transfers.
1462 static int mmc_test_area_io_seq(struct mmc_test_card
*test
, unsigned long sz
,
1463 unsigned int dev_addr
, int write
,
1464 int max_scatter
, int timed
, int count
,
1465 bool nonblock
, int min_sg_len
)
1467 struct timespec ts1
, ts2
;
1470 struct mmc_test_area
*t
= &test
->area
;
1473 * In the case of a maximally scattered transfer, the maximum transfer
1474 * size is further limited by using PAGE_SIZE segments.
1477 struct mmc_test_area
*t
= &test
->area
;
1478 unsigned long max_tfr
;
1480 if (t
->max_seg_sz
>= PAGE_SIZE
)
1481 max_tfr
= t
->max_segs
* PAGE_SIZE
;
1483 max_tfr
= t
->max_segs
* t
->max_seg_sz
;
1488 ret
= mmc_test_area_map(test
, sz
, max_scatter
, min_sg_len
);
1493 getnstimeofday(&ts1
);
1495 ret
= mmc_test_nonblock_transfer(test
, t
->sg
, t
->sg_len
,
1496 dev_addr
, t
->blocks
, 512, write
, count
);
1498 for (i
= 0; i
< count
&& ret
== 0; i
++) {
1499 ret
= mmc_test_area_transfer(test
, dev_addr
, write
);
1500 dev_addr
+= sz
>> 9;
1507 getnstimeofday(&ts2
);
1510 mmc_test_print_avg_rate(test
, sz
, count
, &ts1
, &ts2
);
1515 static int mmc_test_area_io(struct mmc_test_card
*test
, unsigned long sz
,
1516 unsigned int dev_addr
, int write
, int max_scatter
,
1519 return mmc_test_area_io_seq(test
, sz
, dev_addr
, write
, max_scatter
,
1520 timed
, 1, false, 0);
1524 * Write the test area entirely.
1526 static int mmc_test_area_fill(struct mmc_test_card
*test
)
1528 struct mmc_test_area
*t
= &test
->area
;
1530 return mmc_test_area_io(test
, t
->max_tfr
, t
->dev_addr
, 1, 0, 0);
1534 * Erase the test area entirely.
1536 static int mmc_test_area_erase(struct mmc_test_card
*test
)
1538 struct mmc_test_area
*t
= &test
->area
;
1540 if (!mmc_can_erase(test
->card
))
1543 return mmc_erase(test
->card
, t
->dev_addr
, t
->max_sz
>> 9,
1548 * Cleanup struct mmc_test_area.
1550 static int mmc_test_area_cleanup(struct mmc_test_card
*test
)
1552 struct mmc_test_area
*t
= &test
->area
;
1555 mmc_test_free_mem(t
->mem
);
1561 * Initialize an area for testing large transfers. The test area is set to the
1562 * middle of the card because cards may have different charateristics at the
1563 * front (for FAT file system optimization). Optionally, the area is erased
1564 * (if the card supports it) which may improve write performance. Optionally,
1565 * the area is filled with data for subsequent read tests.
1567 static int mmc_test_area_init(struct mmc_test_card
*test
, int erase
, int fill
)
1569 struct mmc_test_area
*t
= &test
->area
;
1570 unsigned long min_sz
= 64 * 1024, sz
;
1573 ret
= mmc_test_set_blksize(test
, 512);
1577 /* Make the test area size about 4MiB */
1578 sz
= (unsigned long)test
->card
->pref_erase
<< 9;
1580 while (t
->max_sz
< 4 * 1024 * 1024)
1582 while (t
->max_sz
> TEST_AREA_MAX_SIZE
&& t
->max_sz
> sz
)
1585 t
->max_segs
= test
->card
->host
->max_segs
;
1586 t
->max_seg_sz
= test
->card
->host
->max_seg_size
;
1587 t
->max_seg_sz
-= t
->max_seg_sz
% 512;
1589 t
->max_tfr
= t
->max_sz
;
1590 if (t
->max_tfr
>> 9 > test
->card
->host
->max_blk_count
)
1591 t
->max_tfr
= test
->card
->host
->max_blk_count
<< 9;
1592 if (t
->max_tfr
> test
->card
->host
->max_req_size
)
1593 t
->max_tfr
= test
->card
->host
->max_req_size
;
1594 if (t
->max_tfr
/ t
->max_seg_sz
> t
->max_segs
)
1595 t
->max_tfr
= t
->max_segs
* t
->max_seg_sz
;
1598 * Try to allocate enough memory for a max. sized transfer. Less is OK
1599 * because the same memory can be mapped into the scatterlist more than
1600 * once. Also, take into account the limits imposed on scatterlist
1601 * segments by the host driver.
1603 t
->mem
= mmc_test_alloc_mem(min_sz
, t
->max_tfr
, t
->max_segs
,
1608 t
->sg
= kmalloc(sizeof(struct scatterlist
) * t
->max_segs
, GFP_KERNEL
);
1614 t
->dev_addr
= mmc_test_capacity(test
->card
) / 2;
1615 t
->dev_addr
-= t
->dev_addr
% (t
->max_sz
>> 9);
1618 ret
= mmc_test_area_erase(test
);
1624 ret
= mmc_test_area_fill(test
);
1632 mmc_test_area_cleanup(test
);
1637 * Prepare for large transfers. Do not erase the test area.
1639 static int mmc_test_area_prepare(struct mmc_test_card
*test
)
1641 return mmc_test_area_init(test
, 0, 0);
1645 * Prepare for large transfers. Do erase the test area.
1647 static int mmc_test_area_prepare_erase(struct mmc_test_card
*test
)
1649 return mmc_test_area_init(test
, 1, 0);
1653 * Prepare for large transfers. Erase and fill the test area.
1655 static int mmc_test_area_prepare_fill(struct mmc_test_card
*test
)
1657 return mmc_test_area_init(test
, 1, 1);
1661 * Test best-case performance. Best-case performance is expected from
1662 * a single large transfer.
1664 * An additional option (max_scatter) allows the measurement of the same
1665 * transfer but with no contiguous pages in the scatter list. This tests
1666 * the efficiency of DMA to handle scattered pages.
1668 static int mmc_test_best_performance(struct mmc_test_card
*test
, int write
,
1671 struct mmc_test_area
*t
= &test
->area
;
1673 return mmc_test_area_io(test
, t
->max_tfr
, t
->dev_addr
, write
,
1678 * Best-case read performance.
1680 static int mmc_test_best_read_performance(struct mmc_test_card
*test
)
1682 return mmc_test_best_performance(test
, 0, 0);
1686 * Best-case write performance.
1688 static int mmc_test_best_write_performance(struct mmc_test_card
*test
)
1690 return mmc_test_best_performance(test
, 1, 0);
1694 * Best-case read performance into scattered pages.
1696 static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card
*test
)
1698 return mmc_test_best_performance(test
, 0, 1);
1702 * Best-case write performance from scattered pages.
1704 static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card
*test
)
1706 return mmc_test_best_performance(test
, 1, 1);
1710 * Single read performance by transfer size.
1712 static int mmc_test_profile_read_perf(struct mmc_test_card
*test
)
1714 struct mmc_test_area
*t
= &test
->area
;
1716 unsigned int dev_addr
;
1719 for (sz
= 512; sz
< t
->max_tfr
; sz
<<= 1) {
1720 dev_addr
= t
->dev_addr
+ (sz
>> 9);
1721 ret
= mmc_test_area_io(test
, sz
, dev_addr
, 0, 0, 1);
1726 dev_addr
= t
->dev_addr
;
1727 return mmc_test_area_io(test
, sz
, dev_addr
, 0, 0, 1);
1731 * Single write performance by transfer size.
1733 static int mmc_test_profile_write_perf(struct mmc_test_card
*test
)
1735 struct mmc_test_area
*t
= &test
->area
;
1737 unsigned int dev_addr
;
1740 ret
= mmc_test_area_erase(test
);
1743 for (sz
= 512; sz
< t
->max_tfr
; sz
<<= 1) {
1744 dev_addr
= t
->dev_addr
+ (sz
>> 9);
1745 ret
= mmc_test_area_io(test
, sz
, dev_addr
, 1, 0, 1);
1749 ret
= mmc_test_area_erase(test
);
1753 dev_addr
= t
->dev_addr
;
1754 return mmc_test_area_io(test
, sz
, dev_addr
, 1, 0, 1);
1758 * Single trim performance by transfer size.
1760 static int mmc_test_profile_trim_perf(struct mmc_test_card
*test
)
1762 struct mmc_test_area
*t
= &test
->area
;
1764 unsigned int dev_addr
;
1765 struct timespec ts1
, ts2
;
1768 if (!mmc_can_trim(test
->card
))
1769 return RESULT_UNSUP_CARD
;
1771 if (!mmc_can_erase(test
->card
))
1772 return RESULT_UNSUP_HOST
;
1774 for (sz
= 512; sz
< t
->max_sz
; sz
<<= 1) {
1775 dev_addr
= t
->dev_addr
+ (sz
>> 9);
1776 getnstimeofday(&ts1
);
1777 ret
= mmc_erase(test
->card
, dev_addr
, sz
>> 9, MMC_TRIM_ARG
);
1780 getnstimeofday(&ts2
);
1781 mmc_test_print_rate(test
, sz
, &ts1
, &ts2
);
1783 dev_addr
= t
->dev_addr
;
1784 getnstimeofday(&ts1
);
1785 ret
= mmc_erase(test
->card
, dev_addr
, sz
>> 9, MMC_TRIM_ARG
);
1788 getnstimeofday(&ts2
);
1789 mmc_test_print_rate(test
, sz
, &ts1
, &ts2
);
1793 static int mmc_test_seq_read_perf(struct mmc_test_card
*test
, unsigned long sz
)
1795 struct mmc_test_area
*t
= &test
->area
;
1796 unsigned int dev_addr
, i
, cnt
;
1797 struct timespec ts1
, ts2
;
1800 cnt
= t
->max_sz
/ sz
;
1801 dev_addr
= t
->dev_addr
;
1802 getnstimeofday(&ts1
);
1803 for (i
= 0; i
< cnt
; i
++) {
1804 ret
= mmc_test_area_io(test
, sz
, dev_addr
, 0, 0, 0);
1807 dev_addr
+= (sz
>> 9);
1809 getnstimeofday(&ts2
);
1810 mmc_test_print_avg_rate(test
, sz
, cnt
, &ts1
, &ts2
);
1815 * Consecutive read performance by transfer size.
1817 static int mmc_test_profile_seq_read_perf(struct mmc_test_card
*test
)
1819 struct mmc_test_area
*t
= &test
->area
;
1823 for (sz
= 512; sz
< t
->max_tfr
; sz
<<= 1) {
1824 ret
= mmc_test_seq_read_perf(test
, sz
);
1829 return mmc_test_seq_read_perf(test
, sz
);
1832 static int mmc_test_seq_write_perf(struct mmc_test_card
*test
, unsigned long sz
)
1834 struct mmc_test_area
*t
= &test
->area
;
1835 unsigned int dev_addr
, i
, cnt
;
1836 struct timespec ts1
, ts2
;
1839 ret
= mmc_test_area_erase(test
);
1842 cnt
= t
->max_sz
/ sz
;
1843 dev_addr
= t
->dev_addr
;
1844 getnstimeofday(&ts1
);
1845 for (i
= 0; i
< cnt
; i
++) {
1846 ret
= mmc_test_area_io(test
, sz
, dev_addr
, 1, 0, 0);
1849 dev_addr
+= (sz
>> 9);
1851 getnstimeofday(&ts2
);
1852 mmc_test_print_avg_rate(test
, sz
, cnt
, &ts1
, &ts2
);
1857 * Consecutive write performance by transfer size.
1859 static int mmc_test_profile_seq_write_perf(struct mmc_test_card
*test
)
1861 struct mmc_test_area
*t
= &test
->area
;
1865 for (sz
= 512; sz
< t
->max_tfr
; sz
<<= 1) {
1866 ret
= mmc_test_seq_write_perf(test
, sz
);
1871 return mmc_test_seq_write_perf(test
, sz
);
1875 * Consecutive trim performance by transfer size.
1877 static int mmc_test_profile_seq_trim_perf(struct mmc_test_card
*test
)
1879 struct mmc_test_area
*t
= &test
->area
;
1881 unsigned int dev_addr
, i
, cnt
;
1882 struct timespec ts1
, ts2
;
1885 if (!mmc_can_trim(test
->card
))
1886 return RESULT_UNSUP_CARD
;
1888 if (!mmc_can_erase(test
->card
))
1889 return RESULT_UNSUP_HOST
;
1891 for (sz
= 512; sz
<= t
->max_sz
; sz
<<= 1) {
1892 ret
= mmc_test_area_erase(test
);
1895 ret
= mmc_test_area_fill(test
);
1898 cnt
= t
->max_sz
/ sz
;
1899 dev_addr
= t
->dev_addr
;
1900 getnstimeofday(&ts1
);
1901 for (i
= 0; i
< cnt
; i
++) {
1902 ret
= mmc_erase(test
->card
, dev_addr
, sz
>> 9,
1906 dev_addr
+= (sz
>> 9);
1908 getnstimeofday(&ts2
);
1909 mmc_test_print_avg_rate(test
, sz
, cnt
, &ts1
, &ts2
);
1914 static unsigned int rnd_next
= 1;
1916 static unsigned int mmc_test_rnd_num(unsigned int rnd_cnt
)
1920 rnd_next
= rnd_next
* 1103515245 + 12345;
1921 r
= (rnd_next
>> 16) & 0x7fff;
1922 return (r
* rnd_cnt
) >> 15;
1925 static int mmc_test_rnd_perf(struct mmc_test_card
*test
, int write
, int print
,
1928 unsigned int dev_addr
, cnt
, rnd_addr
, range1
, range2
, last_ea
= 0, ea
;
1930 struct timespec ts1
, ts2
, ts
;
1935 rnd_addr
= mmc_test_capacity(test
->card
) / 4;
1936 range1
= rnd_addr
/ test
->card
->pref_erase
;
1937 range2
= range1
/ ssz
;
1939 getnstimeofday(&ts1
);
1940 for (cnt
= 0; cnt
< UINT_MAX
; cnt
++) {
1941 getnstimeofday(&ts2
);
1942 ts
= timespec_sub(ts2
, ts1
);
1943 if (ts
.tv_sec
>= 10)
1945 ea
= mmc_test_rnd_num(range1
);
1949 dev_addr
= rnd_addr
+ test
->card
->pref_erase
* ea
+
1950 ssz
* mmc_test_rnd_num(range2
);
1951 ret
= mmc_test_area_io(test
, sz
, dev_addr
, write
, 0, 0);
1956 mmc_test_print_avg_rate(test
, sz
, cnt
, &ts1
, &ts2
);
1960 static int mmc_test_random_perf(struct mmc_test_card
*test
, int write
)
1962 struct mmc_test_area
*t
= &test
->area
;
1967 for (sz
= 512; sz
< t
->max_tfr
; sz
<<= 1) {
1969 * When writing, try to get more consistent results by running
1970 * the test twice with exactly the same I/O but outputting the
1971 * results only for the 2nd run.
1975 ret
= mmc_test_rnd_perf(test
, write
, 0, sz
);
1980 ret
= mmc_test_rnd_perf(test
, write
, 1, sz
);
1987 ret
= mmc_test_rnd_perf(test
, write
, 0, sz
);
1992 return mmc_test_rnd_perf(test
, write
, 1, sz
);
1996 * Random read performance by transfer size.
1998 static int mmc_test_random_read_perf(struct mmc_test_card
*test
)
2000 return mmc_test_random_perf(test
, 0);
2004 * Random write performance by transfer size.
2006 static int mmc_test_random_write_perf(struct mmc_test_card
*test
)
2008 return mmc_test_random_perf(test
, 1);
2011 static int mmc_test_seq_perf(struct mmc_test_card
*test
, int write
,
2012 unsigned int tot_sz
, int max_scatter
)
2014 struct mmc_test_area
*t
= &test
->area
;
2015 unsigned int dev_addr
, i
, cnt
, sz
, ssz
;
2016 struct timespec ts1
, ts2
;
2022 * In the case of a maximally scattered transfer, the maximum transfer
2023 * size is further limited by using PAGE_SIZE segments.
2026 unsigned long max_tfr
;
2028 if (t
->max_seg_sz
>= PAGE_SIZE
)
2029 max_tfr
= t
->max_segs
* PAGE_SIZE
;
2031 max_tfr
= t
->max_segs
* t
->max_seg_sz
;
2037 dev_addr
= mmc_test_capacity(test
->card
) / 4;
2038 if (tot_sz
> dev_addr
<< 9)
2039 tot_sz
= dev_addr
<< 9;
2041 dev_addr
&= 0xffff0000; /* Round to 64MiB boundary */
2043 getnstimeofday(&ts1
);
2044 for (i
= 0; i
< cnt
; i
++) {
2045 ret
= mmc_test_area_io(test
, sz
, dev_addr
, write
,
2051 getnstimeofday(&ts2
);
2053 mmc_test_print_avg_rate(test
, sz
, cnt
, &ts1
, &ts2
);
2058 static int mmc_test_large_seq_perf(struct mmc_test_card
*test
, int write
)
2062 for (i
= 0; i
< 10; i
++) {
2063 ret
= mmc_test_seq_perf(test
, write
, 10 * 1024 * 1024, 1);
2067 for (i
= 0; i
< 5; i
++) {
2068 ret
= mmc_test_seq_perf(test
, write
, 100 * 1024 * 1024, 1);
2072 for (i
= 0; i
< 3; i
++) {
2073 ret
= mmc_test_seq_perf(test
, write
, 1000 * 1024 * 1024, 1);
2082 * Large sequential read performance.
2084 static int mmc_test_large_seq_read_perf(struct mmc_test_card
*test
)
2086 return mmc_test_large_seq_perf(test
, 0);
2090 * Large sequential write performance.
2092 static int mmc_test_large_seq_write_perf(struct mmc_test_card
*test
)
2094 return mmc_test_large_seq_perf(test
, 1);
2097 static int mmc_test_rw_multiple(struct mmc_test_card
*test
,
2098 struct mmc_test_multiple_rw
*tdata
,
2099 unsigned int reqsize
, unsigned int size
,
2102 unsigned int dev_addr
;
2103 struct mmc_test_area
*t
= &test
->area
;
2106 /* Set up test area */
2107 if (size
> mmc_test_capacity(test
->card
) / 2 * 512)
2108 size
= mmc_test_capacity(test
->card
) / 2 * 512;
2109 if (reqsize
> t
->max_tfr
)
2110 reqsize
= t
->max_tfr
;
2111 dev_addr
= mmc_test_capacity(test
->card
) / 4;
2112 if ((dev_addr
& 0xffff0000))
2113 dev_addr
&= 0xffff0000; /* Round to 64MiB boundary */
2115 dev_addr
&= 0xfffff800; /* Round to 1MiB boundary */
2122 /* prepare test area */
2123 if (mmc_can_erase(test
->card
) &&
2124 tdata
->prepare
& MMC_TEST_PREP_ERASE
) {
2125 ret
= mmc_erase(test
->card
, dev_addr
,
2126 size
/ 512, MMC_SECURE_ERASE_ARG
);
2128 ret
= mmc_erase(test
->card
, dev_addr
,
2129 size
/ 512, MMC_ERASE_ARG
);
2135 ret
= mmc_test_area_io_seq(test
, reqsize
, dev_addr
,
2136 tdata
->do_write
, 0, 1, size
/ reqsize
,
2137 tdata
->do_nonblock_req
, min_sg_len
);
2143 pr_info("[%s] error\n", __func__
);
2147 static int mmc_test_rw_multiple_size(struct mmc_test_card
*test
,
2148 struct mmc_test_multiple_rw
*rw
)
2152 void *pre_req
= test
->card
->host
->ops
->pre_req
;
2153 void *post_req
= test
->card
->host
->ops
->post_req
;
2155 if (rw
->do_nonblock_req
&&
2156 ((!pre_req
&& post_req
) || (pre_req
&& !post_req
))) {
2157 pr_info("error: only one of pre/post is defined\n");
2161 for (i
= 0 ; i
< rw
->len
&& ret
== 0; i
++) {
2162 ret
= mmc_test_rw_multiple(test
, rw
, rw
->bs
[i
], rw
->size
, 0);
2169 static int mmc_test_rw_multiple_sg_len(struct mmc_test_card
*test
,
2170 struct mmc_test_multiple_rw
*rw
)
2175 for (i
= 0 ; i
< rw
->len
&& ret
== 0; i
++) {
2176 ret
= mmc_test_rw_multiple(test
, rw
, 512*1024, rw
->size
,
2185 * Multiple blocking write 4k to 4 MB chunks
2187 static int mmc_test_profile_mult_write_blocking_perf(struct mmc_test_card
*test
)
2189 unsigned int bs
[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2190 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2191 struct mmc_test_multiple_rw test_data
= {
2193 .size
= TEST_AREA_MAX_SIZE
,
2194 .len
= ARRAY_SIZE(bs
),
2196 .do_nonblock_req
= false,
2197 .prepare
= MMC_TEST_PREP_ERASE
,
2200 return mmc_test_rw_multiple_size(test
, &test_data
);
2204 * Multiple non-blocking write 4k to 4 MB chunks
2206 static int mmc_test_profile_mult_write_nonblock_perf(struct mmc_test_card
*test
)
2208 unsigned int bs
[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2209 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2210 struct mmc_test_multiple_rw test_data
= {
2212 .size
= TEST_AREA_MAX_SIZE
,
2213 .len
= ARRAY_SIZE(bs
),
2215 .do_nonblock_req
= true,
2216 .prepare
= MMC_TEST_PREP_ERASE
,
2219 return mmc_test_rw_multiple_size(test
, &test_data
);
2223 * Multiple blocking read 4k to 4 MB chunks
2225 static int mmc_test_profile_mult_read_blocking_perf(struct mmc_test_card
*test
)
2227 unsigned int bs
[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2228 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2229 struct mmc_test_multiple_rw test_data
= {
2231 .size
= TEST_AREA_MAX_SIZE
,
2232 .len
= ARRAY_SIZE(bs
),
2234 .do_nonblock_req
= false,
2235 .prepare
= MMC_TEST_PREP_NONE
,
2238 return mmc_test_rw_multiple_size(test
, &test_data
);
2242 * Multiple non-blocking read 4k to 4 MB chunks
2244 static int mmc_test_profile_mult_read_nonblock_perf(struct mmc_test_card
*test
)
2246 unsigned int bs
[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2247 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2248 struct mmc_test_multiple_rw test_data
= {
2250 .size
= TEST_AREA_MAX_SIZE
,
2251 .len
= ARRAY_SIZE(bs
),
2253 .do_nonblock_req
= true,
2254 .prepare
= MMC_TEST_PREP_NONE
,
2257 return mmc_test_rw_multiple_size(test
, &test_data
);
2261 * Multiple blocking write 1 to 512 sg elements
2263 static int mmc_test_profile_sglen_wr_blocking_perf(struct mmc_test_card
*test
)
2265 unsigned int sg_len
[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2266 1 << 7, 1 << 8, 1 << 9};
2267 struct mmc_test_multiple_rw test_data
= {
2269 .size
= TEST_AREA_MAX_SIZE
,
2270 .len
= ARRAY_SIZE(sg_len
),
2272 .do_nonblock_req
= false,
2273 .prepare
= MMC_TEST_PREP_ERASE
,
2276 return mmc_test_rw_multiple_sg_len(test
, &test_data
);
2280 * Multiple non-blocking write 1 to 512 sg elements
2282 static int mmc_test_profile_sglen_wr_nonblock_perf(struct mmc_test_card
*test
)
2284 unsigned int sg_len
[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2285 1 << 7, 1 << 8, 1 << 9};
2286 struct mmc_test_multiple_rw test_data
= {
2288 .size
= TEST_AREA_MAX_SIZE
,
2289 .len
= ARRAY_SIZE(sg_len
),
2291 .do_nonblock_req
= true,
2292 .prepare
= MMC_TEST_PREP_ERASE
,
2295 return mmc_test_rw_multiple_sg_len(test
, &test_data
);
2299 * Multiple blocking read 1 to 512 sg elements
2301 static int mmc_test_profile_sglen_r_blocking_perf(struct mmc_test_card
*test
)
2303 unsigned int sg_len
[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2304 1 << 7, 1 << 8, 1 << 9};
2305 struct mmc_test_multiple_rw test_data
= {
2307 .size
= TEST_AREA_MAX_SIZE
,
2308 .len
= ARRAY_SIZE(sg_len
),
2310 .do_nonblock_req
= false,
2311 .prepare
= MMC_TEST_PREP_NONE
,
2314 return mmc_test_rw_multiple_sg_len(test
, &test_data
);
2318 * Multiple non-blocking read 1 to 512 sg elements
2320 static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card
*test
)
2322 unsigned int sg_len
[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2323 1 << 7, 1 << 8, 1 << 9};
2324 struct mmc_test_multiple_rw test_data
= {
2326 .size
= TEST_AREA_MAX_SIZE
,
2327 .len
= ARRAY_SIZE(sg_len
),
2329 .do_nonblock_req
= true,
2330 .prepare
= MMC_TEST_PREP_NONE
,
2333 return mmc_test_rw_multiple_sg_len(test
, &test_data
);
2337 * eMMC hardware reset.
2339 static int mmc_test_hw_reset(struct mmc_test_card
*test
)
2341 struct mmc_card
*card
= test
->card
;
2342 struct mmc_host
*host
= card
->host
;
2345 if (!mmc_card_mmc(card
) || !mmc_can_reset(card
))
2346 return RESULT_UNSUP_CARD
;
2348 err
= mmc_hw_reset(host
);
2351 else if (err
== -EOPNOTSUPP
)
2352 return RESULT_UNSUP_HOST
;
2357 static const struct mmc_test_case mmc_test_cases
[] = {
2359 .name
= "Basic write (no data verification)",
2360 .run
= mmc_test_basic_write
,
2364 .name
= "Basic read (no data verification)",
2365 .run
= mmc_test_basic_read
,
2369 .name
= "Basic write (with data verification)",
2370 .prepare
= mmc_test_prepare_write
,
2371 .run
= mmc_test_verify_write
,
2372 .cleanup
= mmc_test_cleanup
,
2376 .name
= "Basic read (with data verification)",
2377 .prepare
= mmc_test_prepare_read
,
2378 .run
= mmc_test_verify_read
,
2379 .cleanup
= mmc_test_cleanup
,
2383 .name
= "Multi-block write",
2384 .prepare
= mmc_test_prepare_write
,
2385 .run
= mmc_test_multi_write
,
2386 .cleanup
= mmc_test_cleanup
,
2390 .name
= "Multi-block read",
2391 .prepare
= mmc_test_prepare_read
,
2392 .run
= mmc_test_multi_read
,
2393 .cleanup
= mmc_test_cleanup
,
2397 .name
= "Power of two block writes",
2398 .prepare
= mmc_test_prepare_write
,
2399 .run
= mmc_test_pow2_write
,
2400 .cleanup
= mmc_test_cleanup
,
2404 .name
= "Power of two block reads",
2405 .prepare
= mmc_test_prepare_read
,
2406 .run
= mmc_test_pow2_read
,
2407 .cleanup
= mmc_test_cleanup
,
2411 .name
= "Weird sized block writes",
2412 .prepare
= mmc_test_prepare_write
,
2413 .run
= mmc_test_weird_write
,
2414 .cleanup
= mmc_test_cleanup
,
2418 .name
= "Weird sized block reads",
2419 .prepare
= mmc_test_prepare_read
,
2420 .run
= mmc_test_weird_read
,
2421 .cleanup
= mmc_test_cleanup
,
2425 .name
= "Badly aligned write",
2426 .prepare
= mmc_test_prepare_write
,
2427 .run
= mmc_test_align_write
,
2428 .cleanup
= mmc_test_cleanup
,
2432 .name
= "Badly aligned read",
2433 .prepare
= mmc_test_prepare_read
,
2434 .run
= mmc_test_align_read
,
2435 .cleanup
= mmc_test_cleanup
,
2439 .name
= "Badly aligned multi-block write",
2440 .prepare
= mmc_test_prepare_write
,
2441 .run
= mmc_test_align_multi_write
,
2442 .cleanup
= mmc_test_cleanup
,
2446 .name
= "Badly aligned multi-block read",
2447 .prepare
= mmc_test_prepare_read
,
2448 .run
= mmc_test_align_multi_read
,
2449 .cleanup
= mmc_test_cleanup
,
2453 .name
= "Correct xfer_size at write (start failure)",
2454 .run
= mmc_test_xfersize_write
,
2458 .name
= "Correct xfer_size at read (start failure)",
2459 .run
= mmc_test_xfersize_read
,
2463 .name
= "Correct xfer_size at write (midway failure)",
2464 .run
= mmc_test_multi_xfersize_write
,
2468 .name
= "Correct xfer_size at read (midway failure)",
2469 .run
= mmc_test_multi_xfersize_read
,
2472 #ifdef CONFIG_HIGHMEM
2475 .name
= "Highmem write",
2476 .prepare
= mmc_test_prepare_write
,
2477 .run
= mmc_test_write_high
,
2478 .cleanup
= mmc_test_cleanup
,
2482 .name
= "Highmem read",
2483 .prepare
= mmc_test_prepare_read
,
2484 .run
= mmc_test_read_high
,
2485 .cleanup
= mmc_test_cleanup
,
2489 .name
= "Multi-block highmem write",
2490 .prepare
= mmc_test_prepare_write
,
2491 .run
= mmc_test_multi_write_high
,
2492 .cleanup
= mmc_test_cleanup
,
2496 .name
= "Multi-block highmem read",
2497 .prepare
= mmc_test_prepare_read
,
2498 .run
= mmc_test_multi_read_high
,
2499 .cleanup
= mmc_test_cleanup
,
2505 .name
= "Highmem write",
2506 .run
= mmc_test_no_highmem
,
2510 .name
= "Highmem read",
2511 .run
= mmc_test_no_highmem
,
2515 .name
= "Multi-block highmem write",
2516 .run
= mmc_test_no_highmem
,
2520 .name
= "Multi-block highmem read",
2521 .run
= mmc_test_no_highmem
,
2524 #endif /* CONFIG_HIGHMEM */
2527 .name
= "Best-case read performance",
2528 .prepare
= mmc_test_area_prepare_fill
,
2529 .run
= mmc_test_best_read_performance
,
2530 .cleanup
= mmc_test_area_cleanup
,
2534 .name
= "Best-case write performance",
2535 .prepare
= mmc_test_area_prepare_erase
,
2536 .run
= mmc_test_best_write_performance
,
2537 .cleanup
= mmc_test_area_cleanup
,
2541 .name
= "Best-case read performance into scattered pages",
2542 .prepare
= mmc_test_area_prepare_fill
,
2543 .run
= mmc_test_best_read_perf_max_scatter
,
2544 .cleanup
= mmc_test_area_cleanup
,
2548 .name
= "Best-case write performance from scattered pages",
2549 .prepare
= mmc_test_area_prepare_erase
,
2550 .run
= mmc_test_best_write_perf_max_scatter
,
2551 .cleanup
= mmc_test_area_cleanup
,
2555 .name
= "Single read performance by transfer size",
2556 .prepare
= mmc_test_area_prepare_fill
,
2557 .run
= mmc_test_profile_read_perf
,
2558 .cleanup
= mmc_test_area_cleanup
,
2562 .name
= "Single write performance by transfer size",
2563 .prepare
= mmc_test_area_prepare
,
2564 .run
= mmc_test_profile_write_perf
,
2565 .cleanup
= mmc_test_area_cleanup
,
2569 .name
= "Single trim performance by transfer size",
2570 .prepare
= mmc_test_area_prepare_fill
,
2571 .run
= mmc_test_profile_trim_perf
,
2572 .cleanup
= mmc_test_area_cleanup
,
2576 .name
= "Consecutive read performance by transfer size",
2577 .prepare
= mmc_test_area_prepare_fill
,
2578 .run
= mmc_test_profile_seq_read_perf
,
2579 .cleanup
= mmc_test_area_cleanup
,
2583 .name
= "Consecutive write performance by transfer size",
2584 .prepare
= mmc_test_area_prepare
,
2585 .run
= mmc_test_profile_seq_write_perf
,
2586 .cleanup
= mmc_test_area_cleanup
,
2590 .name
= "Consecutive trim performance by transfer size",
2591 .prepare
= mmc_test_area_prepare
,
2592 .run
= mmc_test_profile_seq_trim_perf
,
2593 .cleanup
= mmc_test_area_cleanup
,
2597 .name
= "Random read performance by transfer size",
2598 .prepare
= mmc_test_area_prepare
,
2599 .run
= mmc_test_random_read_perf
,
2600 .cleanup
= mmc_test_area_cleanup
,
2604 .name
= "Random write performance by transfer size",
2605 .prepare
= mmc_test_area_prepare
,
2606 .run
= mmc_test_random_write_perf
,
2607 .cleanup
= mmc_test_area_cleanup
,
2611 .name
= "Large sequential read into scattered pages",
2612 .prepare
= mmc_test_area_prepare
,
2613 .run
= mmc_test_large_seq_read_perf
,
2614 .cleanup
= mmc_test_area_cleanup
,
2618 .name
= "Large sequential write from scattered pages",
2619 .prepare
= mmc_test_area_prepare
,
2620 .run
= mmc_test_large_seq_write_perf
,
2621 .cleanup
= mmc_test_area_cleanup
,
2625 .name
= "Write performance with blocking req 4k to 4MB",
2626 .prepare
= mmc_test_area_prepare
,
2627 .run
= mmc_test_profile_mult_write_blocking_perf
,
2628 .cleanup
= mmc_test_area_cleanup
,
2632 .name
= "Write performance with non-blocking req 4k to 4MB",
2633 .prepare
= mmc_test_area_prepare
,
2634 .run
= mmc_test_profile_mult_write_nonblock_perf
,
2635 .cleanup
= mmc_test_area_cleanup
,
2639 .name
= "Read performance with blocking req 4k to 4MB",
2640 .prepare
= mmc_test_area_prepare
,
2641 .run
= mmc_test_profile_mult_read_blocking_perf
,
2642 .cleanup
= mmc_test_area_cleanup
,
2646 .name
= "Read performance with non-blocking req 4k to 4MB",
2647 .prepare
= mmc_test_area_prepare
,
2648 .run
= mmc_test_profile_mult_read_nonblock_perf
,
2649 .cleanup
= mmc_test_area_cleanup
,
2653 .name
= "Write performance blocking req 1 to 512 sg elems",
2654 .prepare
= mmc_test_area_prepare
,
2655 .run
= mmc_test_profile_sglen_wr_blocking_perf
,
2656 .cleanup
= mmc_test_area_cleanup
,
2660 .name
= "Write performance non-blocking req 1 to 512 sg elems",
2661 .prepare
= mmc_test_area_prepare
,
2662 .run
= mmc_test_profile_sglen_wr_nonblock_perf
,
2663 .cleanup
= mmc_test_area_cleanup
,
2667 .name
= "Read performance blocking req 1 to 512 sg elems",
2668 .prepare
= mmc_test_area_prepare
,
2669 .run
= mmc_test_profile_sglen_r_blocking_perf
,
2670 .cleanup
= mmc_test_area_cleanup
,
2674 .name
= "Read performance non-blocking req 1 to 512 sg elems",
2675 .prepare
= mmc_test_area_prepare
,
2676 .run
= mmc_test_profile_sglen_r_nonblock_perf
,
2677 .cleanup
= mmc_test_area_cleanup
,
2681 .name
= "eMMC hardware reset",
2682 .run
= mmc_test_hw_reset
,
2686 static DEFINE_MUTEX(mmc_test_lock
);
2688 static LIST_HEAD(mmc_test_result
);
2690 static void mmc_test_run(struct mmc_test_card
*test
, int testcase
)
2694 pr_info("%s: Starting tests of card %s...\n",
2695 mmc_hostname(test
->card
->host
), mmc_card_id(test
->card
));
2697 mmc_claim_host(test
->card
->host
);
2699 for (i
= 0;i
< ARRAY_SIZE(mmc_test_cases
);i
++) {
2700 struct mmc_test_general_result
*gr
;
2702 if (testcase
&& ((i
+ 1) != testcase
))
2705 pr_info("%s: Test case %d. %s...\n",
2706 mmc_hostname(test
->card
->host
), i
+ 1,
2707 mmc_test_cases
[i
].name
);
2709 if (mmc_test_cases
[i
].prepare
) {
2710 ret
= mmc_test_cases
[i
].prepare(test
);
2712 pr_info("%s: Result: Prepare "
2713 "stage failed! (%d)\n",
2714 mmc_hostname(test
->card
->host
),
2720 gr
= kzalloc(sizeof(struct mmc_test_general_result
),
2723 INIT_LIST_HEAD(&gr
->tr_lst
);
2725 /* Assign data what we know already */
2726 gr
->card
= test
->card
;
2729 /* Append container to global one */
2730 list_add_tail(&gr
->link
, &mmc_test_result
);
2733 * Save the pointer to created container in our private
2739 ret
= mmc_test_cases
[i
].run(test
);
2742 pr_info("%s: Result: OK\n",
2743 mmc_hostname(test
->card
->host
));
2746 pr_info("%s: Result: FAILED\n",
2747 mmc_hostname(test
->card
->host
));
2749 case RESULT_UNSUP_HOST
:
2750 pr_info("%s: Result: UNSUPPORTED "
2752 mmc_hostname(test
->card
->host
));
2754 case RESULT_UNSUP_CARD
:
2755 pr_info("%s: Result: UNSUPPORTED "
2757 mmc_hostname(test
->card
->host
));
2760 pr_info("%s: Result: ERROR (%d)\n",
2761 mmc_hostname(test
->card
->host
), ret
);
2764 /* Save the result */
2768 if (mmc_test_cases
[i
].cleanup
) {
2769 ret
= mmc_test_cases
[i
].cleanup(test
);
2771 pr_info("%s: Warning: Cleanup "
2772 "stage failed! (%d)\n",
2773 mmc_hostname(test
->card
->host
),
2779 mmc_release_host(test
->card
->host
);
2781 pr_info("%s: Tests completed.\n",
2782 mmc_hostname(test
->card
->host
));
2785 static void mmc_test_free_result(struct mmc_card
*card
)
2787 struct mmc_test_general_result
*gr
, *grs
;
2789 mutex_lock(&mmc_test_lock
);
2791 list_for_each_entry_safe(gr
, grs
, &mmc_test_result
, link
) {
2792 struct mmc_test_transfer_result
*tr
, *trs
;
2794 if (card
&& gr
->card
!= card
)
2797 list_for_each_entry_safe(tr
, trs
, &gr
->tr_lst
, link
) {
2798 list_del(&tr
->link
);
2802 list_del(&gr
->link
);
2806 mutex_unlock(&mmc_test_lock
);
2809 static LIST_HEAD(mmc_test_file_test
);
2811 static int mtf_test_show(struct seq_file
*sf
, void *data
)
2813 struct mmc_card
*card
= (struct mmc_card
*)sf
->private;
2814 struct mmc_test_general_result
*gr
;
2816 mutex_lock(&mmc_test_lock
);
2818 list_for_each_entry(gr
, &mmc_test_result
, link
) {
2819 struct mmc_test_transfer_result
*tr
;
2821 if (gr
->card
!= card
)
2824 seq_printf(sf
, "Test %d: %d\n", gr
->testcase
+ 1, gr
->result
);
2826 list_for_each_entry(tr
, &gr
->tr_lst
, link
) {
2827 seq_printf(sf
, "%u %d %lu.%09lu %u %u.%02u\n",
2828 tr
->count
, tr
->sectors
,
2829 (unsigned long)tr
->ts
.tv_sec
,
2830 (unsigned long)tr
->ts
.tv_nsec
,
2831 tr
->rate
, tr
->iops
/ 100, tr
->iops
% 100);
2835 mutex_unlock(&mmc_test_lock
);
2840 static int mtf_test_open(struct inode
*inode
, struct file
*file
)
2842 return single_open(file
, mtf_test_show
, inode
->i_private
);
2845 static ssize_t
mtf_test_write(struct file
*file
, const char __user
*buf
,
2846 size_t count
, loff_t
*pos
)
2848 struct seq_file
*sf
= (struct seq_file
*)file
->private_data
;
2849 struct mmc_card
*card
= (struct mmc_card
*)sf
->private;
2850 struct mmc_test_card
*test
;
2854 ret
= kstrtol_from_user(buf
, count
, 10, &testcase
);
2858 test
= kzalloc(sizeof(struct mmc_test_card
), GFP_KERNEL
);
2863 * Remove all test cases associated with given card. Thus we have only
2864 * actual data of the last run.
2866 mmc_test_free_result(card
);
2870 test
->buffer
= kzalloc(BUFFER_SIZE
, GFP_KERNEL
);
2871 #ifdef CONFIG_HIGHMEM
2872 test
->highmem
= alloc_pages(GFP_KERNEL
| __GFP_HIGHMEM
, BUFFER_ORDER
);
2875 #ifdef CONFIG_HIGHMEM
2876 if (test
->buffer
&& test
->highmem
) {
2880 mutex_lock(&mmc_test_lock
);
2881 mmc_test_run(test
, testcase
);
2882 mutex_unlock(&mmc_test_lock
);
2885 #ifdef CONFIG_HIGHMEM
2886 __free_pages(test
->highmem
, BUFFER_ORDER
);
2888 kfree(test
->buffer
);
2894 static const struct file_operations mmc_test_fops_test
= {
2895 .open
= mtf_test_open
,
2897 .write
= mtf_test_write
,
2898 .llseek
= seq_lseek
,
2899 .release
= single_release
,
2902 static int mtf_testlist_show(struct seq_file
*sf
, void *data
)
2906 mutex_lock(&mmc_test_lock
);
2908 for (i
= 0; i
< ARRAY_SIZE(mmc_test_cases
); i
++)
2909 seq_printf(sf
, "%d:\t%s\n", i
+1, mmc_test_cases
[i
].name
);
2911 mutex_unlock(&mmc_test_lock
);
2916 static int mtf_testlist_open(struct inode
*inode
, struct file
*file
)
2918 return single_open(file
, mtf_testlist_show
, inode
->i_private
);
2921 static const struct file_operations mmc_test_fops_testlist
= {
2922 .open
= mtf_testlist_open
,
2924 .llseek
= seq_lseek
,
2925 .release
= single_release
,
2928 static void mmc_test_free_dbgfs_file(struct mmc_card
*card
)
2930 struct mmc_test_dbgfs_file
*df
, *dfs
;
2932 mutex_lock(&mmc_test_lock
);
2934 list_for_each_entry_safe(df
, dfs
, &mmc_test_file_test
, link
) {
2935 if (card
&& df
->card
!= card
)
2937 debugfs_remove(df
->file
);
2938 list_del(&df
->link
);
2942 mutex_unlock(&mmc_test_lock
);
2945 static int __mmc_test_register_dbgfs_file(struct mmc_card
*card
,
2946 const char *name
, umode_t mode
, const struct file_operations
*fops
)
2948 struct dentry
*file
= NULL
;
2949 struct mmc_test_dbgfs_file
*df
;
2951 if (card
->debugfs_root
)
2952 file
= debugfs_create_file(name
, mode
, card
->debugfs_root
,
2955 if (IS_ERR_OR_NULL(file
)) {
2957 "Can't create %s. Perhaps debugfs is disabled.\n",
2962 df
= kmalloc(sizeof(struct mmc_test_dbgfs_file
), GFP_KERNEL
);
2964 debugfs_remove(file
);
2966 "Can't allocate memory for internal usage.\n");
2973 list_add(&df
->link
, &mmc_test_file_test
);
2977 static int mmc_test_register_dbgfs_file(struct mmc_card
*card
)
2981 mutex_lock(&mmc_test_lock
);
2983 ret
= __mmc_test_register_dbgfs_file(card
, "test", S_IWUSR
| S_IRUGO
,
2984 &mmc_test_fops_test
);
2988 ret
= __mmc_test_register_dbgfs_file(card
, "testlist", S_IRUGO
,
2989 &mmc_test_fops_testlist
);
2994 mutex_unlock(&mmc_test_lock
);
2999 static int mmc_test_probe(struct device
*dev
)
3001 struct mmc_card
*card
= mmc_dev_to_card(dev
);
3004 if (!mmc_card_mmc(card
) && !mmc_card_sd(card
))
3007 ret
= mmc_test_register_dbgfs_file(card
);
3011 dev_info(&card
->dev
, "Card claimed for testing.\n");
3016 static int mmc_test_remove(struct device
*dev
)
3018 struct mmc_card
*card
= mmc_dev_to_card(dev
);
3020 mmc_test_free_result(card
);
3021 mmc_test_free_dbgfs_file(card
);
3026 static void mmc_test_shutdown(struct device
*dev
)
3030 static struct device_driver mmc_driver
= {
3032 .probe
= mmc_test_probe
,
3033 .remove
= mmc_test_remove
,
3034 .shutdown
= mmc_test_shutdown
,
3037 static int __init
mmc_test_init(void)
3039 return mmc_register_driver(&mmc_driver
);
3042 static void __exit
mmc_test_exit(void)
3044 /* Clear stalled data if card is still plugged */
3045 mmc_test_free_result(NULL
);
3046 mmc_test_free_dbgfs_file(NULL
);
3048 mmc_unregister_driver(&mmc_driver
);
3051 module_init(mmc_test_init
);
3052 module_exit(mmc_test_exit
);
3054 MODULE_LICENSE("GPL");
3055 MODULE_DESCRIPTION("Multimedia Card (MMC) host test driver");
3056 MODULE_AUTHOR("Pierre Ossman");