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>
18 #include <linux/scatterlist.h>
19 #include <linux/swap.h> /* For nr_free_buffer_pages() */
23 #define RESULT_UNSUP_HOST 2
24 #define RESULT_UNSUP_CARD 3
26 #define BUFFER_ORDER 2
27 #define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER)
30 * Limit the test area size to the maximum MMC HC erase group size. Note that
31 * the maximum SD allocation unit size is just 4MiB.
33 #define TEST_AREA_MAX_SIZE (128 * 1024 * 1024)
36 * struct mmc_test_pages - pages allocated by 'alloc_pages()'.
37 * @page: first page in the allocation
38 * @order: order of the number of pages allocated
40 struct mmc_test_pages
{
46 * struct mmc_test_mem - allocated memory.
47 * @arr: array of allocations
48 * @cnt: number of allocations
51 struct mmc_test_pages
*arr
;
56 * struct mmc_test_area - information for performance tests.
57 * @max_sz: test area size (in bytes)
58 * @dev_addr: address on card at which to do performance tests
59 * @max_tfr: maximum transfer size allowed by driver (in bytes)
60 * @max_segs: maximum segments allowed by driver in scatterlist @sg
61 * @max_seg_sz: maximum segment size allowed by driver
62 * @blocks: number of (512 byte) blocks currently mapped by @sg
63 * @sg_len: length of currently mapped scatterlist @sg
64 * @mem: allocated memory
67 struct mmc_test_area
{
69 unsigned int dev_addr
;
71 unsigned int max_segs
;
72 unsigned int max_seg_sz
;
75 struct mmc_test_mem
*mem
;
76 struct scatterlist
*sg
;
80 * struct mmc_test_card - test information.
81 * @card: card under test
82 * @scratch: transfer buffer
83 * @buffer: transfer buffer
84 * @highmem: buffer for highmem tests
85 * @area: information for performance tests
87 struct mmc_test_card
{
88 struct mmc_card
*card
;
90 u8 scratch
[BUFFER_SIZE
];
95 struct mmc_test_area area
;
98 /*******************************************************************/
99 /* General helper functions */
100 /*******************************************************************/
103 * Configure correct block size in card
105 static int mmc_test_set_blksize(struct mmc_test_card
*test
, unsigned size
)
107 struct mmc_command cmd
;
110 cmd
.opcode
= MMC_SET_BLOCKLEN
;
112 cmd
.flags
= MMC_RSP_R1
| MMC_CMD_AC
;
113 ret
= mmc_wait_for_cmd(test
->card
->host
, &cmd
, 0);
121 * Fill in the mmc_request structure given a set of transfer parameters.
123 static void mmc_test_prepare_mrq(struct mmc_test_card
*test
,
124 struct mmc_request
*mrq
, struct scatterlist
*sg
, unsigned sg_len
,
125 unsigned dev_addr
, unsigned blocks
, unsigned blksz
, int write
)
127 BUG_ON(!mrq
|| !mrq
->cmd
|| !mrq
->data
|| !mrq
->stop
);
130 mrq
->cmd
->opcode
= write
?
131 MMC_WRITE_MULTIPLE_BLOCK
: MMC_READ_MULTIPLE_BLOCK
;
133 mrq
->cmd
->opcode
= write
?
134 MMC_WRITE_BLOCK
: MMC_READ_SINGLE_BLOCK
;
137 mrq
->cmd
->arg
= dev_addr
;
138 if (!mmc_card_blockaddr(test
->card
))
141 mrq
->cmd
->flags
= MMC_RSP_R1
| MMC_CMD_ADTC
;
146 mrq
->stop
->opcode
= MMC_STOP_TRANSMISSION
;
148 mrq
->stop
->flags
= MMC_RSP_R1B
| MMC_CMD_AC
;
151 mrq
->data
->blksz
= blksz
;
152 mrq
->data
->blocks
= blocks
;
153 mrq
->data
->flags
= write
? MMC_DATA_WRITE
: MMC_DATA_READ
;
155 mrq
->data
->sg_len
= sg_len
;
157 mmc_set_data_timeout(mrq
->data
, test
->card
);
160 static int mmc_test_busy(struct mmc_command
*cmd
)
162 return !(cmd
->resp
[0] & R1_READY_FOR_DATA
) ||
163 (R1_CURRENT_STATE(cmd
->resp
[0]) == 7);
167 * Wait for the card to finish the busy state
169 static int mmc_test_wait_busy(struct mmc_test_card
*test
)
172 struct mmc_command cmd
;
176 memset(&cmd
, 0, sizeof(struct mmc_command
));
178 cmd
.opcode
= MMC_SEND_STATUS
;
179 cmd
.arg
= test
->card
->rca
<< 16;
180 cmd
.flags
= MMC_RSP_R1
| MMC_CMD_AC
;
182 ret
= mmc_wait_for_cmd(test
->card
->host
, &cmd
, 0);
186 if (!busy
&& mmc_test_busy(&cmd
)) {
188 printk(KERN_INFO
"%s: Warning: Host did not "
189 "wait for busy state to end.\n",
190 mmc_hostname(test
->card
->host
));
192 } while (mmc_test_busy(&cmd
));
198 * Transfer a single sector of kernel addressable data
200 static int mmc_test_buffer_transfer(struct mmc_test_card
*test
,
201 u8
*buffer
, unsigned addr
, unsigned blksz
, int write
)
205 struct mmc_request mrq
;
206 struct mmc_command cmd
;
207 struct mmc_command stop
;
208 struct mmc_data data
;
210 struct scatterlist sg
;
212 memset(&mrq
, 0, sizeof(struct mmc_request
));
213 memset(&cmd
, 0, sizeof(struct mmc_command
));
214 memset(&data
, 0, sizeof(struct mmc_data
));
215 memset(&stop
, 0, sizeof(struct mmc_command
));
221 sg_init_one(&sg
, buffer
, blksz
);
223 mmc_test_prepare_mrq(test
, &mrq
, &sg
, 1, addr
, 1, blksz
, write
);
225 mmc_wait_for_req(test
->card
->host
, &mrq
);
232 ret
= mmc_test_wait_busy(test
);
239 static void mmc_test_free_mem(struct mmc_test_mem
*mem
)
244 __free_pages(mem
->arr
[mem
->cnt
].page
,
245 mem
->arr
[mem
->cnt
].order
);
251 * Allocate a lot of memory, preferrably max_sz but at least min_sz. In case
252 * there isn't much memory do not exceed 1/16th total lowmem pages. Also do
253 * not exceed a maximum number of segments and try not to make segments much
254 * bigger than maximum segment size.
256 static struct mmc_test_mem
*mmc_test_alloc_mem(unsigned long min_sz
,
257 unsigned long max_sz
,
258 unsigned int max_segs
,
259 unsigned int max_seg_sz
)
261 unsigned long max_page_cnt
= DIV_ROUND_UP(max_sz
, PAGE_SIZE
);
262 unsigned long min_page_cnt
= DIV_ROUND_UP(min_sz
, PAGE_SIZE
);
263 unsigned long max_seg_page_cnt
= DIV_ROUND_UP(max_seg_sz
, PAGE_SIZE
);
264 unsigned long page_cnt
= 0;
265 unsigned long limit
= nr_free_buffer_pages() >> 4;
266 struct mmc_test_mem
*mem
;
268 if (max_page_cnt
> limit
)
269 max_page_cnt
= limit
;
270 if (max_page_cnt
< min_page_cnt
)
271 max_page_cnt
= min_page_cnt
;
273 if (max_seg_page_cnt
> max_page_cnt
)
274 max_seg_page_cnt
= max_page_cnt
;
276 if (max_segs
> max_page_cnt
)
277 max_segs
= max_page_cnt
;
279 mem
= kzalloc(sizeof(struct mmc_test_mem
), GFP_KERNEL
);
283 mem
->arr
= kzalloc(sizeof(struct mmc_test_pages
) * max_segs
,
288 while (max_page_cnt
) {
291 gfp_t flags
= GFP_KERNEL
| GFP_DMA
| __GFP_NOWARN
|
294 order
= get_order(max_seg_page_cnt
<< PAGE_SHIFT
);
296 page
= alloc_pages(flags
, order
);
302 if (page_cnt
< min_page_cnt
)
306 mem
->arr
[mem
->cnt
].page
= page
;
307 mem
->arr
[mem
->cnt
].order
= order
;
309 if (max_page_cnt
<= (1UL << order
))
311 if (mem
->cnt
>= max_segs
) {
312 if (page_cnt
< min_page_cnt
)
316 max_page_cnt
-= 1UL << order
;
317 page_cnt
+= 1UL << order
;
323 mmc_test_free_mem(mem
);
328 * Map memory into a scatterlist. Optionally allow the same memory to be
329 * mapped more than once.
331 static int mmc_test_map_sg(struct mmc_test_mem
*mem
, unsigned long sz
,
332 struct scatterlist
*sglist
, int repeat
,
333 unsigned int max_segs
, unsigned int max_seg_sz
,
334 unsigned int *sg_len
)
336 struct scatterlist
*sg
= NULL
;
339 sg_init_table(sglist
, max_segs
);
343 for (i
= 0; i
< mem
->cnt
; i
++) {
344 unsigned long len
= PAGE_SIZE
<< mem
->arr
[i
].order
;
348 if (len
> max_seg_sz
)
356 sg_set_page(sg
, mem
->arr
[i
].page
, len
, 0);
362 } while (sz
&& repeat
);
374 * Map memory into a scatterlist so that no pages are contiguous. Allow the
375 * same memory to be mapped more than once.
377 static int mmc_test_map_sg_max_scatter(struct mmc_test_mem
*mem
,
379 struct scatterlist
*sglist
,
380 unsigned int max_segs
,
381 unsigned int max_seg_sz
,
382 unsigned int *sg_len
)
384 struct scatterlist
*sg
= NULL
;
385 unsigned int i
= mem
->cnt
, cnt
;
387 void *base
, *addr
, *last_addr
= NULL
;
389 sg_init_table(sglist
, max_segs
);
393 base
= page_address(mem
->arr
[--i
].page
);
394 cnt
= 1 << mem
->arr
[i
].order
;
396 addr
= base
+ PAGE_SIZE
* --cnt
;
397 if (last_addr
&& last_addr
+ PAGE_SIZE
== addr
)
401 if (len
> max_seg_sz
)
411 sg_set_page(sg
, virt_to_page(addr
), len
, 0);
426 * Calculate transfer rate in bytes per second.
428 static unsigned int mmc_test_rate(uint64_t bytes
, struct timespec
*ts
)
438 while (ns
> UINT_MAX
) {
446 do_div(bytes
, (uint32_t)ns
);
452 * Print the transfer rate.
454 static void mmc_test_print_rate(struct mmc_test_card
*test
, uint64_t bytes
,
455 struct timespec
*ts1
, struct timespec
*ts2
)
457 unsigned int rate
, sectors
= bytes
>> 9;
460 ts
= timespec_sub(*ts2
, *ts1
);
462 rate
= mmc_test_rate(bytes
, &ts
);
464 printk(KERN_INFO
"%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
465 "seconds (%u kB/s, %u KiB/s)\n",
466 mmc_hostname(test
->card
->host
), sectors
, sectors
>> 1,
467 (sectors
== 1 ? ".5" : ""), (unsigned long)ts
.tv_sec
,
468 (unsigned long)ts
.tv_nsec
, rate
/ 1000, rate
/ 1024);
472 * Print the average transfer rate.
474 static void mmc_test_print_avg_rate(struct mmc_test_card
*test
, uint64_t bytes
,
475 unsigned int count
, struct timespec
*ts1
,
476 struct timespec
*ts2
)
478 unsigned int rate
, sectors
= bytes
>> 9;
479 uint64_t tot
= bytes
* count
;
482 ts
= timespec_sub(*ts2
, *ts1
);
484 rate
= mmc_test_rate(tot
, &ts
);
486 printk(KERN_INFO
"%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
487 "%lu.%09lu seconds (%u kB/s, %u KiB/s)\n",
488 mmc_hostname(test
->card
->host
), count
, sectors
, count
,
489 sectors
>> 1, (sectors
== 1 ? ".5" : ""),
490 (unsigned long)ts
.tv_sec
, (unsigned long)ts
.tv_nsec
,
491 rate
/ 1000, rate
/ 1024);
495 * Return the card size in sectors.
497 static unsigned int mmc_test_capacity(struct mmc_card
*card
)
499 if (!mmc_card_sd(card
) && mmc_card_blockaddr(card
))
500 return card
->ext_csd
.sectors
;
502 return card
->csd
.capacity
<< (card
->csd
.read_blkbits
- 9);
505 /*******************************************************************/
506 /* Test preparation and cleanup */
507 /*******************************************************************/
510 * Fill the first couple of sectors of the card with known data
511 * so that bad reads/writes can be detected
513 static int __mmc_test_prepare(struct mmc_test_card
*test
, int write
)
517 ret
= mmc_test_set_blksize(test
, 512);
522 memset(test
->buffer
, 0xDF, 512);
524 for (i
= 0;i
< 512;i
++)
528 for (i
= 0;i
< BUFFER_SIZE
/ 512;i
++) {
529 ret
= mmc_test_buffer_transfer(test
, test
->buffer
, i
, 512, 1);
537 static int mmc_test_prepare_write(struct mmc_test_card
*test
)
539 return __mmc_test_prepare(test
, 1);
542 static int mmc_test_prepare_read(struct mmc_test_card
*test
)
544 return __mmc_test_prepare(test
, 0);
547 static int mmc_test_cleanup(struct mmc_test_card
*test
)
551 ret
= mmc_test_set_blksize(test
, 512);
555 memset(test
->buffer
, 0, 512);
557 for (i
= 0;i
< BUFFER_SIZE
/ 512;i
++) {
558 ret
= mmc_test_buffer_transfer(test
, test
->buffer
, i
, 512, 1);
566 /*******************************************************************/
567 /* Test execution helpers */
568 /*******************************************************************/
571 * Modifies the mmc_request to perform the "short transfer" tests
573 static void mmc_test_prepare_broken_mrq(struct mmc_test_card
*test
,
574 struct mmc_request
*mrq
, int write
)
576 BUG_ON(!mrq
|| !mrq
->cmd
|| !mrq
->data
);
578 if (mrq
->data
->blocks
> 1) {
579 mrq
->cmd
->opcode
= write
?
580 MMC_WRITE_BLOCK
: MMC_READ_SINGLE_BLOCK
;
583 mrq
->cmd
->opcode
= MMC_SEND_STATUS
;
584 mrq
->cmd
->arg
= test
->card
->rca
<< 16;
589 * Checks that a normal transfer didn't have any errors
591 static int mmc_test_check_result(struct mmc_test_card
*test
,
592 struct mmc_request
*mrq
)
596 BUG_ON(!mrq
|| !mrq
->cmd
|| !mrq
->data
);
600 if (!ret
&& mrq
->cmd
->error
)
601 ret
= mrq
->cmd
->error
;
602 if (!ret
&& mrq
->data
->error
)
603 ret
= mrq
->data
->error
;
604 if (!ret
&& mrq
->stop
&& mrq
->stop
->error
)
605 ret
= mrq
->stop
->error
;
606 if (!ret
&& mrq
->data
->bytes_xfered
!=
607 mrq
->data
->blocks
* mrq
->data
->blksz
)
611 ret
= RESULT_UNSUP_HOST
;
617 * Checks that a "short transfer" behaved as expected
619 static int mmc_test_check_broken_result(struct mmc_test_card
*test
,
620 struct mmc_request
*mrq
)
624 BUG_ON(!mrq
|| !mrq
->cmd
|| !mrq
->data
);
628 if (!ret
&& mrq
->cmd
->error
)
629 ret
= mrq
->cmd
->error
;
630 if (!ret
&& mrq
->data
->error
== 0)
632 if (!ret
&& mrq
->data
->error
!= -ETIMEDOUT
)
633 ret
= mrq
->data
->error
;
634 if (!ret
&& mrq
->stop
&& mrq
->stop
->error
)
635 ret
= mrq
->stop
->error
;
636 if (mrq
->data
->blocks
> 1) {
637 if (!ret
&& mrq
->data
->bytes_xfered
> mrq
->data
->blksz
)
640 if (!ret
&& mrq
->data
->bytes_xfered
> 0)
645 ret
= RESULT_UNSUP_HOST
;
651 * Tests a basic transfer with certain parameters
653 static int mmc_test_simple_transfer(struct mmc_test_card
*test
,
654 struct scatterlist
*sg
, unsigned sg_len
, unsigned dev_addr
,
655 unsigned blocks
, unsigned blksz
, int write
)
657 struct mmc_request mrq
;
658 struct mmc_command cmd
;
659 struct mmc_command stop
;
660 struct mmc_data data
;
662 memset(&mrq
, 0, sizeof(struct mmc_request
));
663 memset(&cmd
, 0, sizeof(struct mmc_command
));
664 memset(&data
, 0, sizeof(struct mmc_data
));
665 memset(&stop
, 0, sizeof(struct mmc_command
));
671 mmc_test_prepare_mrq(test
, &mrq
, sg
, sg_len
, dev_addr
,
672 blocks
, blksz
, write
);
674 mmc_wait_for_req(test
->card
->host
, &mrq
);
676 mmc_test_wait_busy(test
);
678 return mmc_test_check_result(test
, &mrq
);
682 * Tests a transfer where the card will fail completely or partly
684 static int mmc_test_broken_transfer(struct mmc_test_card
*test
,
685 unsigned blocks
, unsigned blksz
, int write
)
687 struct mmc_request mrq
;
688 struct mmc_command cmd
;
689 struct mmc_command stop
;
690 struct mmc_data data
;
692 struct scatterlist sg
;
694 memset(&mrq
, 0, sizeof(struct mmc_request
));
695 memset(&cmd
, 0, sizeof(struct mmc_command
));
696 memset(&data
, 0, sizeof(struct mmc_data
));
697 memset(&stop
, 0, sizeof(struct mmc_command
));
703 sg_init_one(&sg
, test
->buffer
, blocks
* blksz
);
705 mmc_test_prepare_mrq(test
, &mrq
, &sg
, 1, 0, blocks
, blksz
, write
);
706 mmc_test_prepare_broken_mrq(test
, &mrq
, write
);
708 mmc_wait_for_req(test
->card
->host
, &mrq
);
710 mmc_test_wait_busy(test
);
712 return mmc_test_check_broken_result(test
, &mrq
);
716 * Does a complete transfer test where data is also validated
718 * Note: mmc_test_prepare() must have been done before this call
720 static int mmc_test_transfer(struct mmc_test_card
*test
,
721 struct scatterlist
*sg
, unsigned sg_len
, unsigned dev_addr
,
722 unsigned blocks
, unsigned blksz
, int write
)
728 for (i
= 0;i
< blocks
* blksz
;i
++)
729 test
->scratch
[i
] = i
;
731 memset(test
->scratch
, 0, BUFFER_SIZE
);
733 local_irq_save(flags
);
734 sg_copy_from_buffer(sg
, sg_len
, test
->scratch
, BUFFER_SIZE
);
735 local_irq_restore(flags
);
737 ret
= mmc_test_set_blksize(test
, blksz
);
741 ret
= mmc_test_simple_transfer(test
, sg
, sg_len
, dev_addr
,
742 blocks
, blksz
, write
);
749 ret
= mmc_test_set_blksize(test
, 512);
753 sectors
= (blocks
* blksz
+ 511) / 512;
754 if ((sectors
* 512) == (blocks
* blksz
))
757 if ((sectors
* 512) > BUFFER_SIZE
)
760 memset(test
->buffer
, 0, sectors
* 512);
762 for (i
= 0;i
< sectors
;i
++) {
763 ret
= mmc_test_buffer_transfer(test
,
764 test
->buffer
+ i
* 512,
765 dev_addr
+ i
, 512, 0);
770 for (i
= 0;i
< blocks
* blksz
;i
++) {
771 if (test
->buffer
[i
] != (u8
)i
)
775 for (;i
< sectors
* 512;i
++) {
776 if (test
->buffer
[i
] != 0xDF)
780 local_irq_save(flags
);
781 sg_copy_to_buffer(sg
, sg_len
, test
->scratch
, BUFFER_SIZE
);
782 local_irq_restore(flags
);
783 for (i
= 0;i
< blocks
* blksz
;i
++) {
784 if (test
->scratch
[i
] != (u8
)i
)
792 /*******************************************************************/
794 /*******************************************************************/
796 struct mmc_test_case
{
799 int (*prepare
)(struct mmc_test_card
*);
800 int (*run
)(struct mmc_test_card
*);
801 int (*cleanup
)(struct mmc_test_card
*);
804 static int mmc_test_basic_write(struct mmc_test_card
*test
)
807 struct scatterlist sg
;
809 ret
= mmc_test_set_blksize(test
, 512);
813 sg_init_one(&sg
, test
->buffer
, 512);
815 ret
= mmc_test_simple_transfer(test
, &sg
, 1, 0, 1, 512, 1);
822 static int mmc_test_basic_read(struct mmc_test_card
*test
)
825 struct scatterlist sg
;
827 ret
= mmc_test_set_blksize(test
, 512);
831 sg_init_one(&sg
, test
->buffer
, 512);
833 ret
= mmc_test_simple_transfer(test
, &sg
, 1, 0, 1, 512, 0);
840 static int mmc_test_verify_write(struct mmc_test_card
*test
)
843 struct scatterlist sg
;
845 sg_init_one(&sg
, test
->buffer
, 512);
847 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 1);
854 static int mmc_test_verify_read(struct mmc_test_card
*test
)
857 struct scatterlist sg
;
859 sg_init_one(&sg
, test
->buffer
, 512);
861 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 0);
868 static int mmc_test_multi_write(struct mmc_test_card
*test
)
872 struct scatterlist sg
;
874 if (test
->card
->host
->max_blk_count
== 1)
875 return RESULT_UNSUP_HOST
;
877 size
= PAGE_SIZE
* 2;
878 size
= min(size
, test
->card
->host
->max_req_size
);
879 size
= min(size
, test
->card
->host
->max_seg_size
);
880 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
883 return RESULT_UNSUP_HOST
;
885 sg_init_one(&sg
, test
->buffer
, size
);
887 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 1);
894 static int mmc_test_multi_read(struct mmc_test_card
*test
)
898 struct scatterlist sg
;
900 if (test
->card
->host
->max_blk_count
== 1)
901 return RESULT_UNSUP_HOST
;
903 size
= PAGE_SIZE
* 2;
904 size
= min(size
, test
->card
->host
->max_req_size
);
905 size
= min(size
, test
->card
->host
->max_seg_size
);
906 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
909 return RESULT_UNSUP_HOST
;
911 sg_init_one(&sg
, test
->buffer
, size
);
913 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 0);
920 static int mmc_test_pow2_write(struct mmc_test_card
*test
)
923 struct scatterlist sg
;
925 if (!test
->card
->csd
.write_partial
)
926 return RESULT_UNSUP_CARD
;
928 for (i
= 1; i
< 512;i
<<= 1) {
929 sg_init_one(&sg
, test
->buffer
, i
);
930 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, i
, 1);
938 static int mmc_test_pow2_read(struct mmc_test_card
*test
)
941 struct scatterlist sg
;
943 if (!test
->card
->csd
.read_partial
)
944 return RESULT_UNSUP_CARD
;
946 for (i
= 1; i
< 512;i
<<= 1) {
947 sg_init_one(&sg
, test
->buffer
, i
);
948 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, i
, 0);
956 static int mmc_test_weird_write(struct mmc_test_card
*test
)
959 struct scatterlist sg
;
961 if (!test
->card
->csd
.write_partial
)
962 return RESULT_UNSUP_CARD
;
964 for (i
= 3; i
< 512;i
+= 7) {
965 sg_init_one(&sg
, test
->buffer
, i
);
966 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, i
, 1);
974 static int mmc_test_weird_read(struct mmc_test_card
*test
)
977 struct scatterlist sg
;
979 if (!test
->card
->csd
.read_partial
)
980 return RESULT_UNSUP_CARD
;
982 for (i
= 3; i
< 512;i
+= 7) {
983 sg_init_one(&sg
, test
->buffer
, i
);
984 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, i
, 0);
992 static int mmc_test_align_write(struct mmc_test_card
*test
)
995 struct scatterlist sg
;
997 for (i
= 1;i
< 4;i
++) {
998 sg_init_one(&sg
, test
->buffer
+ i
, 512);
999 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 1);
1007 static int mmc_test_align_read(struct mmc_test_card
*test
)
1010 struct scatterlist sg
;
1012 for (i
= 1;i
< 4;i
++) {
1013 sg_init_one(&sg
, test
->buffer
+ i
, 512);
1014 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 0);
1022 static int mmc_test_align_multi_write(struct mmc_test_card
*test
)
1026 struct scatterlist sg
;
1028 if (test
->card
->host
->max_blk_count
== 1)
1029 return RESULT_UNSUP_HOST
;
1031 size
= PAGE_SIZE
* 2;
1032 size
= min(size
, test
->card
->host
->max_req_size
);
1033 size
= min(size
, test
->card
->host
->max_seg_size
);
1034 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1037 return RESULT_UNSUP_HOST
;
1039 for (i
= 1;i
< 4;i
++) {
1040 sg_init_one(&sg
, test
->buffer
+ i
, size
);
1041 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 1);
1049 static int mmc_test_align_multi_read(struct mmc_test_card
*test
)
1053 struct scatterlist sg
;
1055 if (test
->card
->host
->max_blk_count
== 1)
1056 return RESULT_UNSUP_HOST
;
1058 size
= PAGE_SIZE
* 2;
1059 size
= min(size
, test
->card
->host
->max_req_size
);
1060 size
= min(size
, test
->card
->host
->max_seg_size
);
1061 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1064 return RESULT_UNSUP_HOST
;
1066 for (i
= 1;i
< 4;i
++) {
1067 sg_init_one(&sg
, test
->buffer
+ i
, size
);
1068 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 0);
1076 static int mmc_test_xfersize_write(struct mmc_test_card
*test
)
1080 ret
= mmc_test_set_blksize(test
, 512);
1084 ret
= mmc_test_broken_transfer(test
, 1, 512, 1);
1091 static int mmc_test_xfersize_read(struct mmc_test_card
*test
)
1095 ret
= mmc_test_set_blksize(test
, 512);
1099 ret
= mmc_test_broken_transfer(test
, 1, 512, 0);
1106 static int mmc_test_multi_xfersize_write(struct mmc_test_card
*test
)
1110 if (test
->card
->host
->max_blk_count
== 1)
1111 return RESULT_UNSUP_HOST
;
1113 ret
= mmc_test_set_blksize(test
, 512);
1117 ret
= mmc_test_broken_transfer(test
, 2, 512, 1);
1124 static int mmc_test_multi_xfersize_read(struct mmc_test_card
*test
)
1128 if (test
->card
->host
->max_blk_count
== 1)
1129 return RESULT_UNSUP_HOST
;
1131 ret
= mmc_test_set_blksize(test
, 512);
1135 ret
= mmc_test_broken_transfer(test
, 2, 512, 0);
1142 #ifdef CONFIG_HIGHMEM
1144 static int mmc_test_write_high(struct mmc_test_card
*test
)
1147 struct scatterlist sg
;
1149 sg_init_table(&sg
, 1);
1150 sg_set_page(&sg
, test
->highmem
, 512, 0);
1152 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 1);
1159 static int mmc_test_read_high(struct mmc_test_card
*test
)
1162 struct scatterlist sg
;
1164 sg_init_table(&sg
, 1);
1165 sg_set_page(&sg
, test
->highmem
, 512, 0);
1167 ret
= mmc_test_transfer(test
, &sg
, 1, 0, 1, 512, 0);
1174 static int mmc_test_multi_write_high(struct mmc_test_card
*test
)
1178 struct scatterlist sg
;
1180 if (test
->card
->host
->max_blk_count
== 1)
1181 return RESULT_UNSUP_HOST
;
1183 size
= PAGE_SIZE
* 2;
1184 size
= min(size
, test
->card
->host
->max_req_size
);
1185 size
= min(size
, test
->card
->host
->max_seg_size
);
1186 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1189 return RESULT_UNSUP_HOST
;
1191 sg_init_table(&sg
, 1);
1192 sg_set_page(&sg
, test
->highmem
, size
, 0);
1194 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 1);
1201 static int mmc_test_multi_read_high(struct mmc_test_card
*test
)
1205 struct scatterlist sg
;
1207 if (test
->card
->host
->max_blk_count
== 1)
1208 return RESULT_UNSUP_HOST
;
1210 size
= PAGE_SIZE
* 2;
1211 size
= min(size
, test
->card
->host
->max_req_size
);
1212 size
= min(size
, test
->card
->host
->max_seg_size
);
1213 size
= min(size
, test
->card
->host
->max_blk_count
* 512);
1216 return RESULT_UNSUP_HOST
;
1218 sg_init_table(&sg
, 1);
1219 sg_set_page(&sg
, test
->highmem
, size
, 0);
1221 ret
= mmc_test_transfer(test
, &sg
, 1, 0, size
/512, 512, 0);
1230 static int mmc_test_no_highmem(struct mmc_test_card
*test
)
1232 printk(KERN_INFO
"%s: Highmem not configured - test skipped\n",
1233 mmc_hostname(test
->card
->host
));
1237 #endif /* CONFIG_HIGHMEM */
1240 * Map sz bytes so that it can be transferred.
1242 static int mmc_test_area_map(struct mmc_test_card
*test
, unsigned long sz
,
1245 struct mmc_test_area
*t
= &test
->area
;
1248 t
->blocks
= sz
>> 9;
1251 err
= mmc_test_map_sg_max_scatter(t
->mem
, sz
, t
->sg
,
1252 t
->max_segs
, t
->max_seg_sz
,
1255 err
= mmc_test_map_sg(t
->mem
, sz
, t
->sg
, 1, t
->max_segs
,
1256 t
->max_seg_sz
, &t
->sg_len
);
1259 printk(KERN_INFO
"%s: Failed to map sg list\n",
1260 mmc_hostname(test
->card
->host
));
1265 * Transfer bytes mapped by mmc_test_area_map().
1267 static int mmc_test_area_transfer(struct mmc_test_card
*test
,
1268 unsigned int dev_addr
, int write
)
1270 struct mmc_test_area
*t
= &test
->area
;
1272 return mmc_test_simple_transfer(test
, t
->sg
, t
->sg_len
, dev_addr
,
1273 t
->blocks
, 512, write
);
1277 * Map and transfer bytes.
1279 static int mmc_test_area_io(struct mmc_test_card
*test
, unsigned long sz
,
1280 unsigned int dev_addr
, int write
, int max_scatter
,
1283 struct timespec ts1
, ts2
;
1287 * In the case of a maximally scattered transfer, the maximum transfer
1288 * size is further limited by using PAGE_SIZE segments.
1291 struct mmc_test_area
*t
= &test
->area
;
1292 unsigned long max_tfr
;
1294 if (t
->max_seg_sz
>= PAGE_SIZE
)
1295 max_tfr
= t
->max_segs
* PAGE_SIZE
;
1297 max_tfr
= t
->max_segs
* t
->max_seg_sz
;
1302 ret
= mmc_test_area_map(test
, sz
, max_scatter
);
1307 getnstimeofday(&ts1
);
1309 ret
= mmc_test_area_transfer(test
, dev_addr
, write
);
1314 getnstimeofday(&ts2
);
1317 mmc_test_print_rate(test
, sz
, &ts1
, &ts2
);
1323 * Write the test area entirely.
1325 static int mmc_test_area_fill(struct mmc_test_card
*test
)
1327 return mmc_test_area_io(test
, test
->area
.max_tfr
, test
->area
.dev_addr
,
1332 * Erase the test area entirely.
1334 static int mmc_test_area_erase(struct mmc_test_card
*test
)
1336 struct mmc_test_area
*t
= &test
->area
;
1338 if (!mmc_can_erase(test
->card
))
1341 return mmc_erase(test
->card
, t
->dev_addr
, test
->area
.max_sz
>> 9,
1346 * Cleanup struct mmc_test_area.
1348 static int mmc_test_area_cleanup(struct mmc_test_card
*test
)
1350 struct mmc_test_area
*t
= &test
->area
;
1353 mmc_test_free_mem(t
->mem
);
1359 * Initialize an area for testing large transfers. The size of the area is the
1360 * preferred erase size which is a good size for optimal transfer speed. Note
1361 * that is typically 4MiB for modern cards. The test area is set to the middle
1362 * of the card because cards may have different charateristics at the front
1363 * (for FAT file system optimization). Optionally, the area is erased (if the
1364 * card supports it) which may improve write performance. Optionally, the area
1365 * is filled with data for subsequent read tests.
1367 static int mmc_test_area_init(struct mmc_test_card
*test
, int erase
, int fill
)
1369 struct mmc_test_area
*t
= &test
->area
;
1370 unsigned long min_sz
= 64 * 1024;
1373 ret
= mmc_test_set_blksize(test
, 512);
1377 if (test
->card
->pref_erase
> TEST_AREA_MAX_SIZE
>> 9)
1378 t
->max_sz
= TEST_AREA_MAX_SIZE
;
1380 t
->max_sz
= (unsigned long)test
->card
->pref_erase
<< 9;
1382 t
->max_segs
= test
->card
->host
->max_segs
;
1383 t
->max_seg_sz
= test
->card
->host
->max_seg_size
;
1385 t
->max_tfr
= t
->max_sz
;
1386 if (t
->max_tfr
>> 9 > test
->card
->host
->max_blk_count
)
1387 t
->max_tfr
= test
->card
->host
->max_blk_count
<< 9;
1388 if (t
->max_tfr
> test
->card
->host
->max_req_size
)
1389 t
->max_tfr
= test
->card
->host
->max_req_size
;
1390 if (t
->max_tfr
/ t
->max_seg_sz
> t
->max_segs
)
1391 t
->max_tfr
= t
->max_segs
* t
->max_seg_sz
;
1394 * Try to allocate enough memory for the whole area. Less is OK
1395 * because the same memory can be mapped into the scatterlist more than
1396 * once. Also, take into account the limits imposed on scatterlist
1397 * segments by the host driver.
1399 t
->mem
= mmc_test_alloc_mem(min_sz
, t
->max_sz
, t
->max_segs
,
1404 t
->sg
= kmalloc(sizeof(struct scatterlist
) * t
->max_segs
, GFP_KERNEL
);
1410 t
->dev_addr
= mmc_test_capacity(test
->card
) / 2;
1411 t
->dev_addr
-= t
->dev_addr
% (t
->max_sz
>> 9);
1414 ret
= mmc_test_area_erase(test
);
1420 ret
= mmc_test_area_fill(test
);
1428 mmc_test_area_cleanup(test
);
1433 * Prepare for large transfers. Do not erase the test area.
1435 static int mmc_test_area_prepare(struct mmc_test_card
*test
)
1437 return mmc_test_area_init(test
, 0, 0);
1441 * Prepare for large transfers. Do erase the test area.
1443 static int mmc_test_area_prepare_erase(struct mmc_test_card
*test
)
1445 return mmc_test_area_init(test
, 1, 0);
1449 * Prepare for large transfers. Erase and fill the test area.
1451 static int mmc_test_area_prepare_fill(struct mmc_test_card
*test
)
1453 return mmc_test_area_init(test
, 1, 1);
1457 * Test best-case performance. Best-case performance is expected from
1458 * a single large transfer.
1460 * An additional option (max_scatter) allows the measurement of the same
1461 * transfer but with no contiguous pages in the scatter list. This tests
1462 * the efficiency of DMA to handle scattered pages.
1464 static int mmc_test_best_performance(struct mmc_test_card
*test
, int write
,
1467 return mmc_test_area_io(test
, test
->area
.max_tfr
, test
->area
.dev_addr
,
1468 write
, max_scatter
, 1);
1472 * Best-case read performance.
1474 static int mmc_test_best_read_performance(struct mmc_test_card
*test
)
1476 return mmc_test_best_performance(test
, 0, 0);
1480 * Best-case write performance.
1482 static int mmc_test_best_write_performance(struct mmc_test_card
*test
)
1484 return mmc_test_best_performance(test
, 1, 0);
1488 * Best-case read performance into scattered pages.
1490 static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card
*test
)
1492 return mmc_test_best_performance(test
, 0, 1);
1496 * Best-case write performance from scattered pages.
1498 static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card
*test
)
1500 return mmc_test_best_performance(test
, 1, 1);
1504 * Single read performance by transfer size.
1506 static int mmc_test_profile_read_perf(struct mmc_test_card
*test
)
1509 unsigned int dev_addr
;
1512 for (sz
= 512; sz
< test
->area
.max_tfr
; sz
<<= 1) {
1513 dev_addr
= test
->area
.dev_addr
+ (sz
>> 9);
1514 ret
= mmc_test_area_io(test
, sz
, dev_addr
, 0, 0, 1);
1518 sz
= test
->area
.max_tfr
;
1519 dev_addr
= test
->area
.dev_addr
;
1520 return mmc_test_area_io(test
, sz
, dev_addr
, 0, 0, 1);
1524 * Single write performance by transfer size.
1526 static int mmc_test_profile_write_perf(struct mmc_test_card
*test
)
1529 unsigned int dev_addr
;
1532 ret
= mmc_test_area_erase(test
);
1535 for (sz
= 512; sz
< test
->area
.max_tfr
; sz
<<= 1) {
1536 dev_addr
= test
->area
.dev_addr
+ (sz
>> 9);
1537 ret
= mmc_test_area_io(test
, sz
, dev_addr
, 1, 0, 1);
1541 ret
= mmc_test_area_erase(test
);
1544 sz
= test
->area
.max_tfr
;
1545 dev_addr
= test
->area
.dev_addr
;
1546 return mmc_test_area_io(test
, sz
, dev_addr
, 1, 0, 1);
1550 * Single trim performance by transfer size.
1552 static int mmc_test_profile_trim_perf(struct mmc_test_card
*test
)
1555 unsigned int dev_addr
;
1556 struct timespec ts1
, ts2
;
1559 if (!mmc_can_trim(test
->card
))
1560 return RESULT_UNSUP_CARD
;
1562 if (!mmc_can_erase(test
->card
))
1563 return RESULT_UNSUP_HOST
;
1565 for (sz
= 512; sz
< test
->area
.max_sz
; sz
<<= 1) {
1566 dev_addr
= test
->area
.dev_addr
+ (sz
>> 9);
1567 getnstimeofday(&ts1
);
1568 ret
= mmc_erase(test
->card
, dev_addr
, sz
>> 9, MMC_TRIM_ARG
);
1571 getnstimeofday(&ts2
);
1572 mmc_test_print_rate(test
, sz
, &ts1
, &ts2
);
1574 dev_addr
= test
->area
.dev_addr
;
1575 getnstimeofday(&ts1
);
1576 ret
= mmc_erase(test
->card
, dev_addr
, sz
>> 9, MMC_TRIM_ARG
);
1579 getnstimeofday(&ts2
);
1580 mmc_test_print_rate(test
, sz
, &ts1
, &ts2
);
1584 static int mmc_test_seq_read_perf(struct mmc_test_card
*test
, unsigned long sz
)
1586 unsigned int dev_addr
, i
, cnt
;
1587 struct timespec ts1
, ts2
;
1590 cnt
= test
->area
.max_sz
/ sz
;
1591 dev_addr
= test
->area
.dev_addr
;
1592 getnstimeofday(&ts1
);
1593 for (i
= 0; i
< cnt
; i
++) {
1594 ret
= mmc_test_area_io(test
, sz
, dev_addr
, 0, 0, 0);
1597 dev_addr
+= (sz
>> 9);
1599 getnstimeofday(&ts2
);
1600 mmc_test_print_avg_rate(test
, sz
, cnt
, &ts1
, &ts2
);
1605 * Consecutive read performance by transfer size.
1607 static int mmc_test_profile_seq_read_perf(struct mmc_test_card
*test
)
1612 for (sz
= 512; sz
< test
->area
.max_tfr
; sz
<<= 1) {
1613 ret
= mmc_test_seq_read_perf(test
, sz
);
1617 sz
= test
->area
.max_tfr
;
1618 return mmc_test_seq_read_perf(test
, sz
);
1621 static int mmc_test_seq_write_perf(struct mmc_test_card
*test
, unsigned long sz
)
1623 unsigned int dev_addr
, i
, cnt
;
1624 struct timespec ts1
, ts2
;
1627 ret
= mmc_test_area_erase(test
);
1630 cnt
= test
->area
.max_sz
/ sz
;
1631 dev_addr
= test
->area
.dev_addr
;
1632 getnstimeofday(&ts1
);
1633 for (i
= 0; i
< cnt
; i
++) {
1634 ret
= mmc_test_area_io(test
, sz
, dev_addr
, 1, 0, 0);
1637 dev_addr
+= (sz
>> 9);
1639 getnstimeofday(&ts2
);
1640 mmc_test_print_avg_rate(test
, sz
, cnt
, &ts1
, &ts2
);
1645 * Consecutive write performance by transfer size.
1647 static int mmc_test_profile_seq_write_perf(struct mmc_test_card
*test
)
1652 for (sz
= 512; sz
< test
->area
.max_tfr
; sz
<<= 1) {
1653 ret
= mmc_test_seq_write_perf(test
, sz
);
1657 sz
= test
->area
.max_tfr
;
1658 return mmc_test_seq_write_perf(test
, sz
);
1662 * Consecutive trim performance by transfer size.
1664 static int mmc_test_profile_seq_trim_perf(struct mmc_test_card
*test
)
1667 unsigned int dev_addr
, i
, cnt
;
1668 struct timespec ts1
, ts2
;
1671 if (!mmc_can_trim(test
->card
))
1672 return RESULT_UNSUP_CARD
;
1674 if (!mmc_can_erase(test
->card
))
1675 return RESULT_UNSUP_HOST
;
1677 for (sz
= 512; sz
<= test
->area
.max_sz
; sz
<<= 1) {
1678 ret
= mmc_test_area_erase(test
);
1681 ret
= mmc_test_area_fill(test
);
1684 cnt
= test
->area
.max_sz
/ sz
;
1685 dev_addr
= test
->area
.dev_addr
;
1686 getnstimeofday(&ts1
);
1687 for (i
= 0; i
< cnt
; i
++) {
1688 ret
= mmc_erase(test
->card
, dev_addr
, sz
>> 9,
1692 dev_addr
+= (sz
>> 9);
1694 getnstimeofday(&ts2
);
1695 mmc_test_print_avg_rate(test
, sz
, cnt
, &ts1
, &ts2
);
1700 static const struct mmc_test_case mmc_test_cases
[] = {
1702 .name
= "Basic write (no data verification)",
1703 .run
= mmc_test_basic_write
,
1707 .name
= "Basic read (no data verification)",
1708 .run
= mmc_test_basic_read
,
1712 .name
= "Basic write (with data verification)",
1713 .prepare
= mmc_test_prepare_write
,
1714 .run
= mmc_test_verify_write
,
1715 .cleanup
= mmc_test_cleanup
,
1719 .name
= "Basic read (with data verification)",
1720 .prepare
= mmc_test_prepare_read
,
1721 .run
= mmc_test_verify_read
,
1722 .cleanup
= mmc_test_cleanup
,
1726 .name
= "Multi-block write",
1727 .prepare
= mmc_test_prepare_write
,
1728 .run
= mmc_test_multi_write
,
1729 .cleanup
= mmc_test_cleanup
,
1733 .name
= "Multi-block read",
1734 .prepare
= mmc_test_prepare_read
,
1735 .run
= mmc_test_multi_read
,
1736 .cleanup
= mmc_test_cleanup
,
1740 .name
= "Power of two block writes",
1741 .prepare
= mmc_test_prepare_write
,
1742 .run
= mmc_test_pow2_write
,
1743 .cleanup
= mmc_test_cleanup
,
1747 .name
= "Power of two block reads",
1748 .prepare
= mmc_test_prepare_read
,
1749 .run
= mmc_test_pow2_read
,
1750 .cleanup
= mmc_test_cleanup
,
1754 .name
= "Weird sized block writes",
1755 .prepare
= mmc_test_prepare_write
,
1756 .run
= mmc_test_weird_write
,
1757 .cleanup
= mmc_test_cleanup
,
1761 .name
= "Weird sized block reads",
1762 .prepare
= mmc_test_prepare_read
,
1763 .run
= mmc_test_weird_read
,
1764 .cleanup
= mmc_test_cleanup
,
1768 .name
= "Badly aligned write",
1769 .prepare
= mmc_test_prepare_write
,
1770 .run
= mmc_test_align_write
,
1771 .cleanup
= mmc_test_cleanup
,
1775 .name
= "Badly aligned read",
1776 .prepare
= mmc_test_prepare_read
,
1777 .run
= mmc_test_align_read
,
1778 .cleanup
= mmc_test_cleanup
,
1782 .name
= "Badly aligned multi-block write",
1783 .prepare
= mmc_test_prepare_write
,
1784 .run
= mmc_test_align_multi_write
,
1785 .cleanup
= mmc_test_cleanup
,
1789 .name
= "Badly aligned multi-block read",
1790 .prepare
= mmc_test_prepare_read
,
1791 .run
= mmc_test_align_multi_read
,
1792 .cleanup
= mmc_test_cleanup
,
1796 .name
= "Correct xfer_size at write (start failure)",
1797 .run
= mmc_test_xfersize_write
,
1801 .name
= "Correct xfer_size at read (start failure)",
1802 .run
= mmc_test_xfersize_read
,
1806 .name
= "Correct xfer_size at write (midway failure)",
1807 .run
= mmc_test_multi_xfersize_write
,
1811 .name
= "Correct xfer_size at read (midway failure)",
1812 .run
= mmc_test_multi_xfersize_read
,
1815 #ifdef CONFIG_HIGHMEM
1818 .name
= "Highmem write",
1819 .prepare
= mmc_test_prepare_write
,
1820 .run
= mmc_test_write_high
,
1821 .cleanup
= mmc_test_cleanup
,
1825 .name
= "Highmem read",
1826 .prepare
= mmc_test_prepare_read
,
1827 .run
= mmc_test_read_high
,
1828 .cleanup
= mmc_test_cleanup
,
1832 .name
= "Multi-block highmem write",
1833 .prepare
= mmc_test_prepare_write
,
1834 .run
= mmc_test_multi_write_high
,
1835 .cleanup
= mmc_test_cleanup
,
1839 .name
= "Multi-block highmem read",
1840 .prepare
= mmc_test_prepare_read
,
1841 .run
= mmc_test_multi_read_high
,
1842 .cleanup
= mmc_test_cleanup
,
1848 .name
= "Highmem write",
1849 .run
= mmc_test_no_highmem
,
1853 .name
= "Highmem read",
1854 .run
= mmc_test_no_highmem
,
1858 .name
= "Multi-block highmem write",
1859 .run
= mmc_test_no_highmem
,
1863 .name
= "Multi-block highmem read",
1864 .run
= mmc_test_no_highmem
,
1867 #endif /* CONFIG_HIGHMEM */
1870 .name
= "Best-case read performance",
1871 .prepare
= mmc_test_area_prepare_fill
,
1872 .run
= mmc_test_best_read_performance
,
1873 .cleanup
= mmc_test_area_cleanup
,
1877 .name
= "Best-case write performance",
1878 .prepare
= mmc_test_area_prepare_erase
,
1879 .run
= mmc_test_best_write_performance
,
1880 .cleanup
= mmc_test_area_cleanup
,
1884 .name
= "Best-case read performance into scattered pages",
1885 .prepare
= mmc_test_area_prepare_fill
,
1886 .run
= mmc_test_best_read_perf_max_scatter
,
1887 .cleanup
= mmc_test_area_cleanup
,
1891 .name
= "Best-case write performance from scattered pages",
1892 .prepare
= mmc_test_area_prepare_erase
,
1893 .run
= mmc_test_best_write_perf_max_scatter
,
1894 .cleanup
= mmc_test_area_cleanup
,
1898 .name
= "Single read performance by transfer size",
1899 .prepare
= mmc_test_area_prepare_fill
,
1900 .run
= mmc_test_profile_read_perf
,
1901 .cleanup
= mmc_test_area_cleanup
,
1905 .name
= "Single write performance by transfer size",
1906 .prepare
= mmc_test_area_prepare
,
1907 .run
= mmc_test_profile_write_perf
,
1908 .cleanup
= mmc_test_area_cleanup
,
1912 .name
= "Single trim performance by transfer size",
1913 .prepare
= mmc_test_area_prepare_fill
,
1914 .run
= mmc_test_profile_trim_perf
,
1915 .cleanup
= mmc_test_area_cleanup
,
1919 .name
= "Consecutive read performance by transfer size",
1920 .prepare
= mmc_test_area_prepare_fill
,
1921 .run
= mmc_test_profile_seq_read_perf
,
1922 .cleanup
= mmc_test_area_cleanup
,
1926 .name
= "Consecutive write performance by transfer size",
1927 .prepare
= mmc_test_area_prepare
,
1928 .run
= mmc_test_profile_seq_write_perf
,
1929 .cleanup
= mmc_test_area_cleanup
,
1933 .name
= "Consecutive trim performance by transfer size",
1934 .prepare
= mmc_test_area_prepare
,
1935 .run
= mmc_test_profile_seq_trim_perf
,
1936 .cleanup
= mmc_test_area_cleanup
,
1941 static DEFINE_MUTEX(mmc_test_lock
);
1943 static void mmc_test_run(struct mmc_test_card
*test
, int testcase
)
1947 printk(KERN_INFO
"%s: Starting tests of card %s...\n",
1948 mmc_hostname(test
->card
->host
), mmc_card_id(test
->card
));
1950 mmc_claim_host(test
->card
->host
);
1952 for (i
= 0;i
< ARRAY_SIZE(mmc_test_cases
);i
++) {
1953 if (testcase
&& ((i
+ 1) != testcase
))
1956 printk(KERN_INFO
"%s: Test case %d. %s...\n",
1957 mmc_hostname(test
->card
->host
), i
+ 1,
1958 mmc_test_cases
[i
].name
);
1960 if (mmc_test_cases
[i
].prepare
) {
1961 ret
= mmc_test_cases
[i
].prepare(test
);
1963 printk(KERN_INFO
"%s: Result: Prepare "
1964 "stage failed! (%d)\n",
1965 mmc_hostname(test
->card
->host
),
1971 ret
= mmc_test_cases
[i
].run(test
);
1974 printk(KERN_INFO
"%s: Result: OK\n",
1975 mmc_hostname(test
->card
->host
));
1978 printk(KERN_INFO
"%s: Result: FAILED\n",
1979 mmc_hostname(test
->card
->host
));
1981 case RESULT_UNSUP_HOST
:
1982 printk(KERN_INFO
"%s: Result: UNSUPPORTED "
1984 mmc_hostname(test
->card
->host
));
1986 case RESULT_UNSUP_CARD
:
1987 printk(KERN_INFO
"%s: Result: UNSUPPORTED "
1989 mmc_hostname(test
->card
->host
));
1992 printk(KERN_INFO
"%s: Result: ERROR (%d)\n",
1993 mmc_hostname(test
->card
->host
), ret
);
1996 if (mmc_test_cases
[i
].cleanup
) {
1997 ret
= mmc_test_cases
[i
].cleanup(test
);
1999 printk(KERN_INFO
"%s: Warning: Cleanup "
2000 "stage failed! (%d)\n",
2001 mmc_hostname(test
->card
->host
),
2007 mmc_release_host(test
->card
->host
);
2009 printk(KERN_INFO
"%s: Tests completed.\n",
2010 mmc_hostname(test
->card
->host
));
2013 static ssize_t
mmc_test_show(struct device
*dev
,
2014 struct device_attribute
*attr
, char *buf
)
2016 mutex_lock(&mmc_test_lock
);
2017 mutex_unlock(&mmc_test_lock
);
2022 static ssize_t
mmc_test_store(struct device
*dev
,
2023 struct device_attribute
*attr
, const char *buf
, size_t count
)
2025 struct mmc_card
*card
= mmc_dev_to_card(dev
);
2026 struct mmc_test_card
*test
;
2029 testcase
= simple_strtol(buf
, NULL
, 10);
2031 test
= kzalloc(sizeof(struct mmc_test_card
), GFP_KERNEL
);
2037 test
->buffer
= kzalloc(BUFFER_SIZE
, GFP_KERNEL
);
2038 #ifdef CONFIG_HIGHMEM
2039 test
->highmem
= alloc_pages(GFP_KERNEL
| __GFP_HIGHMEM
, BUFFER_ORDER
);
2042 #ifdef CONFIG_HIGHMEM
2043 if (test
->buffer
&& test
->highmem
) {
2047 mutex_lock(&mmc_test_lock
);
2048 mmc_test_run(test
, testcase
);
2049 mutex_unlock(&mmc_test_lock
);
2052 #ifdef CONFIG_HIGHMEM
2053 __free_pages(test
->highmem
, BUFFER_ORDER
);
2055 kfree(test
->buffer
);
2061 static DEVICE_ATTR(test
, S_IWUSR
| S_IRUGO
, mmc_test_show
, mmc_test_store
);
2063 static int mmc_test_probe(struct mmc_card
*card
)
2067 if ((card
->type
!= MMC_TYPE_MMC
) && (card
->type
!= MMC_TYPE_SD
))
2070 ret
= device_create_file(&card
->dev
, &dev_attr_test
);
2074 dev_info(&card
->dev
, "Card claimed for testing.\n");
2079 static void mmc_test_remove(struct mmc_card
*card
)
2081 device_remove_file(&card
->dev
, &dev_attr_test
);
2084 static struct mmc_driver mmc_driver
= {
2088 .probe
= mmc_test_probe
,
2089 .remove
= mmc_test_remove
,
2092 static int __init
mmc_test_init(void)
2094 return mmc_register_driver(&mmc_driver
);
2097 static void __exit
mmc_test_exit(void)
2099 mmc_unregister_driver(&mmc_driver
);
2102 module_init(mmc_test_init
);
2103 module_exit(mmc_test_exit
);
2105 MODULE_LICENSE("GPL");
2106 MODULE_DESCRIPTION("Multimedia Card (MMC) host test driver");
2107 MODULE_AUTHOR("Pierre Ossman");