2 * Copyright 2007-2008 Pierre Ossman
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
10 #include <linux/mmc/core.h>
11 #include <linux/mmc/card.h>
12 #include <linux/mmc/host.h>
13 #include <linux/mmc/mmc.h>
14 #include <linux/slab.h>
16 #include <linux/scatterlist.h>
17 #include <linux/swap.h> /* For nr_free_buffer_pages() */
18 #include <linux/list.h>
20 #include <linux/debugfs.h>
21 #include <linux/uaccess.h>
22 #include <linux/seq_file.h>
23 #include <linux/module.h>
33 #define RESULT_UNSUP_HOST 2
34 #define RESULT_UNSUP_CARD 3
36 #define BUFFER_ORDER 2
37 #define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER)
39 #define TEST_ALIGN_END 8
42 * Limit the test area size to the maximum MMC HC erase group size. Note that
43 * the maximum SD allocation unit size is just 4MiB.
45 #define TEST_AREA_MAX_SIZE (128 * 1024 * 1024)
48 * struct mmc_test_pages - pages allocated by 'alloc_pages()'.
49 * @page: first page in the allocation
50 * @order: order of the number of pages allocated
52 struct mmc_test_pages {
58 * struct mmc_test_mem - allocated memory.
59 * @arr: array of allocations
60 * @cnt: number of allocations
63 struct mmc_test_pages *arr;
68 * struct mmc_test_area - information for performance tests.
69 * @max_sz: test area size (in bytes)
70 * @dev_addr: address on card at which to do performance tests
71 * @max_tfr: maximum transfer size allowed by driver (in bytes)
72 * @max_segs: maximum segments allowed by driver in scatterlist @sg
73 * @max_seg_sz: maximum segment size allowed by driver
74 * @blocks: number of (512 byte) blocks currently mapped by @sg
75 * @sg_len: length of currently mapped scatterlist @sg
76 * @mem: allocated memory
79 struct mmc_test_area {
81 unsigned int dev_addr;
83 unsigned int max_segs;
84 unsigned int max_seg_sz;
87 struct mmc_test_mem *mem;
88 struct scatterlist *sg;
92 * struct mmc_test_transfer_result - transfer results for performance tests.
93 * @link: double-linked list
94 * @count: amount of group of sectors to check
95 * @sectors: amount of sectors to check in one group
96 * @ts: time values of transfer
97 * @rate: calculated transfer rate
98 * @iops: I/O operations per second (times 100)
100 struct mmc_test_transfer_result {
101 struct list_head link;
103 unsigned int sectors;
110 * struct mmc_test_general_result - results for tests.
111 * @link: double-linked list
112 * @card: card under test
113 * @testcase: number of test case
114 * @result: result of test run
115 * @tr_lst: transfer measurements if any as mmc_test_transfer_result
117 struct mmc_test_general_result {
118 struct list_head link;
119 struct mmc_card *card;
122 struct list_head tr_lst;
126 * struct mmc_test_dbgfs_file - debugfs related file.
127 * @link: double-linked list
128 * @card: card under test
129 * @file: file created under debugfs
131 struct mmc_test_dbgfs_file {
132 struct list_head link;
133 struct mmc_card *card;
138 * struct mmc_test_card - test information.
139 * @card: card under test
140 * @scratch: transfer buffer
141 * @buffer: transfer buffer
142 * @highmem: buffer for highmem tests
143 * @area: information for performance tests
144 * @gr: pointer to results of current testcase
146 struct mmc_test_card {
147 struct mmc_card *card;
149 u8 scratch[BUFFER_SIZE];
151 #ifdef CONFIG_HIGHMEM
152 struct page *highmem;
154 struct mmc_test_area area;
155 struct mmc_test_general_result *gr;
158 enum mmc_test_prep_media {
159 MMC_TEST_PREP_NONE = 0,
160 MMC_TEST_PREP_WRITE_FULL = 1 << 0,
161 MMC_TEST_PREP_ERASE = 1 << 1,
164 struct mmc_test_multiple_rw {
165 unsigned int *sg_len;
170 bool do_nonblock_req;
171 enum mmc_test_prep_media prepare;
174 struct mmc_test_async_req {
175 struct mmc_async_req areq;
176 struct mmc_test_card *test;
179 /*******************************************************************/
180 /* General helper functions */
181 /*******************************************************************/
184 * Configure correct block size in card
186 static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size)
188 return mmc_set_blocklen(test->card, size);
191 static bool mmc_test_card_cmd23(struct mmc_card *card)
193 return mmc_card_mmc(card) ||
194 (mmc_card_sd(card) && card->scr.cmds & SD_SCR_CMD23_SUPPORT);
197 static void mmc_test_prepare_sbc(struct mmc_test_card *test,
198 struct mmc_request *mrq, unsigned int blocks)
200 struct mmc_card *card = test->card;
202 if (!mrq->sbc || !mmc_host_cmd23(card->host) ||
203 !mmc_test_card_cmd23(card) || !mmc_op_multi(mrq->cmd->opcode) ||
204 (card->quirks & MMC_QUIRK_BLK_NO_CMD23)) {
209 mrq->sbc->opcode = MMC_SET_BLOCK_COUNT;
210 mrq->sbc->arg = blocks;
211 mrq->sbc->flags = MMC_RSP_R1 | MMC_CMD_AC;
215 * Fill in the mmc_request structure given a set of transfer parameters.
217 static void mmc_test_prepare_mrq(struct mmc_test_card *test,
218 struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len,
219 unsigned dev_addr, unsigned blocks, unsigned blksz, int write)
221 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop))
225 mrq->cmd->opcode = write ?
226 MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK;
228 mrq->cmd->opcode = write ?
229 MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
232 mrq->cmd->arg = dev_addr;
233 if (!mmc_card_blockaddr(test->card))
236 mrq->cmd->flags = MMC_RSP_R1 | MMC_CMD_ADTC;
241 mrq->stop->opcode = MMC_STOP_TRANSMISSION;
243 mrq->stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
246 mrq->data->blksz = blksz;
247 mrq->data->blocks = blocks;
248 mrq->data->flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
250 mrq->data->sg_len = sg_len;
252 mmc_test_prepare_sbc(test, mrq, blocks);
254 mmc_set_data_timeout(mrq->data, test->card);
257 static int mmc_test_busy(struct mmc_command *cmd)
259 return !(cmd->resp[0] & R1_READY_FOR_DATA) ||
260 (R1_CURRENT_STATE(cmd->resp[0]) == R1_STATE_PRG);
264 * Wait for the card to finish the busy state
266 static int mmc_test_wait_busy(struct mmc_test_card *test)
269 struct mmc_command cmd = {};
273 memset(&cmd, 0, sizeof(struct mmc_command));
275 cmd.opcode = MMC_SEND_STATUS;
276 cmd.arg = test->card->rca << 16;
277 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
279 ret = mmc_wait_for_cmd(test->card->host, &cmd, 0);
283 if (!busy && mmc_test_busy(&cmd)) {
285 if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
286 pr_info("%s: Warning: Host did not wait for busy state to end.\n",
287 mmc_hostname(test->card->host));
289 } while (mmc_test_busy(&cmd));
295 * Transfer a single sector of kernel addressable data
297 static int mmc_test_buffer_transfer(struct mmc_test_card *test,
298 u8 *buffer, unsigned addr, unsigned blksz, int write)
300 struct mmc_request mrq = {};
301 struct mmc_command cmd = {};
302 struct mmc_command stop = {};
303 struct mmc_data data = {};
305 struct scatterlist sg;
311 sg_init_one(&sg, buffer, blksz);
313 mmc_test_prepare_mrq(test, &mrq, &sg, 1, addr, 1, blksz, write);
315 mmc_wait_for_req(test->card->host, &mrq);
322 return mmc_test_wait_busy(test);
325 static void mmc_test_free_mem(struct mmc_test_mem *mem)
330 __free_pages(mem->arr[mem->cnt].page,
331 mem->arr[mem->cnt].order);
337 * Allocate a lot of memory, preferably max_sz but at least min_sz. In case
338 * there isn't much memory do not exceed 1/16th total lowmem pages. Also do
339 * not exceed a maximum number of segments and try not to make segments much
340 * bigger than maximum segment size.
342 static struct mmc_test_mem *mmc_test_alloc_mem(unsigned long min_sz,
343 unsigned long max_sz,
344 unsigned int max_segs,
345 unsigned int max_seg_sz)
347 unsigned long max_page_cnt = DIV_ROUND_UP(max_sz, PAGE_SIZE);
348 unsigned long min_page_cnt = DIV_ROUND_UP(min_sz, PAGE_SIZE);
349 unsigned long max_seg_page_cnt = DIV_ROUND_UP(max_seg_sz, PAGE_SIZE);
350 unsigned long page_cnt = 0;
351 unsigned long limit = nr_free_buffer_pages() >> 4;
352 struct mmc_test_mem *mem;
354 if (max_page_cnt > limit)
355 max_page_cnt = limit;
356 if (min_page_cnt > max_page_cnt)
357 min_page_cnt = max_page_cnt;
359 if (max_seg_page_cnt > max_page_cnt)
360 max_seg_page_cnt = max_page_cnt;
362 if (max_segs > max_page_cnt)
363 max_segs = max_page_cnt;
365 mem = kzalloc(sizeof(*mem), GFP_KERNEL);
369 mem->arr = kcalloc(max_segs, sizeof(*mem->arr), GFP_KERNEL);
373 while (max_page_cnt) {
376 gfp_t flags = GFP_KERNEL | GFP_DMA | __GFP_NOWARN |
379 order = get_order(max_seg_page_cnt << PAGE_SHIFT);
381 page = alloc_pages(flags, order);
387 if (page_cnt < min_page_cnt)
391 mem->arr[mem->cnt].page = page;
392 mem->arr[mem->cnt].order = order;
394 if (max_page_cnt <= (1UL << order))
396 max_page_cnt -= 1UL << order;
397 page_cnt += 1UL << order;
398 if (mem->cnt >= max_segs) {
399 if (page_cnt < min_page_cnt)
408 mmc_test_free_mem(mem);
413 * Map memory into a scatterlist. Optionally allow the same memory to be
414 * mapped more than once.
416 static int mmc_test_map_sg(struct mmc_test_mem *mem, unsigned long size,
417 struct scatterlist *sglist, int repeat,
418 unsigned int max_segs, unsigned int max_seg_sz,
419 unsigned int *sg_len, int min_sg_len)
421 struct scatterlist *sg = NULL;
423 unsigned long sz = size;
425 sg_init_table(sglist, max_segs);
426 if (min_sg_len > max_segs)
427 min_sg_len = max_segs;
431 for (i = 0; i < mem->cnt; i++) {
432 unsigned long len = PAGE_SIZE << mem->arr[i].order;
434 if (min_sg_len && (size / min_sg_len < len))
435 len = ALIGN(size / min_sg_len, 512);
438 if (len > max_seg_sz)
446 sg_set_page(sg, mem->arr[i].page, len, 0);
452 } while (sz && repeat);
464 * Map memory into a scatterlist so that no pages are contiguous. Allow the
465 * same memory to be mapped more than once.
467 static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem,
469 struct scatterlist *sglist,
470 unsigned int max_segs,
471 unsigned int max_seg_sz,
472 unsigned int *sg_len)
474 struct scatterlist *sg = NULL;
475 unsigned int i = mem->cnt, cnt;
477 void *base, *addr, *last_addr = NULL;
479 sg_init_table(sglist, max_segs);
483 base = page_address(mem->arr[--i].page);
484 cnt = 1 << mem->arr[i].order;
486 addr = base + PAGE_SIZE * --cnt;
487 if (last_addr && last_addr + PAGE_SIZE == addr)
491 if (len > max_seg_sz)
501 sg_set_page(sg, virt_to_page(addr), len, 0);
516 * Calculate transfer rate in bytes per second.
518 static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts)
528 while (ns > UINT_MAX) {
536 do_div(bytes, (uint32_t)ns);
542 * Save transfer results for future usage
544 static void mmc_test_save_transfer_result(struct mmc_test_card *test,
545 unsigned int count, unsigned int sectors, struct timespec ts,
546 unsigned int rate, unsigned int iops)
548 struct mmc_test_transfer_result *tr;
553 tr = kmalloc(sizeof(*tr), GFP_KERNEL);
558 tr->sectors = sectors;
563 list_add_tail(&tr->link, &test->gr->tr_lst);
567 * Print the transfer rate.
569 static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
570 struct timespec *ts1, struct timespec *ts2)
572 unsigned int rate, iops, sectors = bytes >> 9;
575 ts = timespec_sub(*ts2, *ts1);
577 rate = mmc_test_rate(bytes, &ts);
578 iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
580 pr_info("%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
581 "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
582 mmc_hostname(test->card->host), sectors, sectors >> 1,
583 (sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
584 (unsigned long)ts.tv_nsec, rate / 1000, rate / 1024,
585 iops / 100, iops % 100);
587 mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops);
591 * Print the average transfer rate.
593 static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
594 unsigned int count, struct timespec *ts1,
595 struct timespec *ts2)
597 unsigned int rate, iops, sectors = bytes >> 9;
598 uint64_t tot = bytes * count;
601 ts = timespec_sub(*ts2, *ts1);
603 rate = mmc_test_rate(tot, &ts);
604 iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
606 pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
607 "%lu.%09lu seconds (%u kB/s, %u KiB/s, "
608 "%u.%02u IOPS, sg_len %d)\n",
609 mmc_hostname(test->card->host), count, sectors, count,
610 sectors >> 1, (sectors & 1 ? ".5" : ""),
611 (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec,
612 rate / 1000, rate / 1024, iops / 100, iops % 100,
615 mmc_test_save_transfer_result(test, count, sectors, ts, rate, iops);
619 * Return the card size in sectors.
621 static unsigned int mmc_test_capacity(struct mmc_card *card)
623 if (!mmc_card_sd(card) && mmc_card_blockaddr(card))
624 return card->ext_csd.sectors;
626 return card->csd.capacity << (card->csd.read_blkbits - 9);
629 /*******************************************************************/
630 /* Test preparation and cleanup */
631 /*******************************************************************/
634 * Fill the first couple of sectors of the card with known data
635 * so that bad reads/writes can be detected
637 static int __mmc_test_prepare(struct mmc_test_card *test, int write)
641 ret = mmc_test_set_blksize(test, 512);
646 memset(test->buffer, 0xDF, 512);
648 for (i = 0; i < 512; i++)
652 for (i = 0; i < BUFFER_SIZE / 512; i++) {
653 ret = mmc_test_buffer_transfer(test, test->buffer, i, 512, 1);
661 static int mmc_test_prepare_write(struct mmc_test_card *test)
663 return __mmc_test_prepare(test, 1);
666 static int mmc_test_prepare_read(struct mmc_test_card *test)
668 return __mmc_test_prepare(test, 0);
671 static int mmc_test_cleanup(struct mmc_test_card *test)
675 ret = mmc_test_set_blksize(test, 512);
679 memset(test->buffer, 0, 512);
681 for (i = 0; i < BUFFER_SIZE / 512; i++) {
682 ret = mmc_test_buffer_transfer(test, test->buffer, i, 512, 1);
690 /*******************************************************************/
691 /* Test execution helpers */
692 /*******************************************************************/
695 * Modifies the mmc_request to perform the "short transfer" tests
697 static void mmc_test_prepare_broken_mrq(struct mmc_test_card *test,
698 struct mmc_request *mrq, int write)
700 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
703 if (mrq->data->blocks > 1) {
704 mrq->cmd->opcode = write ?
705 MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
708 mrq->cmd->opcode = MMC_SEND_STATUS;
709 mrq->cmd->arg = test->card->rca << 16;
714 * Checks that a normal transfer didn't have any errors
716 static int mmc_test_check_result(struct mmc_test_card *test,
717 struct mmc_request *mrq)
721 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
726 if (mrq->sbc && mrq->sbc->error)
727 ret = mrq->sbc->error;
728 if (!ret && mrq->cmd->error)
729 ret = mrq->cmd->error;
730 if (!ret && mrq->data->error)
731 ret = mrq->data->error;
732 if (!ret && mrq->stop && mrq->stop->error)
733 ret = mrq->stop->error;
734 if (!ret && mrq->data->bytes_xfered !=
735 mrq->data->blocks * mrq->data->blksz)
739 ret = RESULT_UNSUP_HOST;
744 static enum mmc_blk_status mmc_test_check_result_async(struct mmc_card *card,
745 struct mmc_async_req *areq)
747 struct mmc_test_async_req *test_async =
748 container_of(areq, struct mmc_test_async_req, areq);
751 mmc_test_wait_busy(test_async->test);
754 * FIXME: this would earlier just casts a regular error code,
755 * either of the kernel type -ERRORCODE or the local test framework
756 * RESULT_* errorcode, into an enum mmc_blk_status and return as
757 * result check. Instead, convert it to some reasonable type by just
758 * returning either MMC_BLK_SUCCESS or MMC_BLK_CMD_ERR.
759 * If possible, a reasonable error code should be returned.
761 ret = mmc_test_check_result(test_async->test, areq->mrq);
763 return MMC_BLK_CMD_ERR;
765 return MMC_BLK_SUCCESS;
769 * Checks that a "short transfer" behaved as expected
771 static int mmc_test_check_broken_result(struct mmc_test_card *test,
772 struct mmc_request *mrq)
776 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
781 if (!ret && mrq->cmd->error)
782 ret = mrq->cmd->error;
783 if (!ret && mrq->data->error == 0)
785 if (!ret && mrq->data->error != -ETIMEDOUT)
786 ret = mrq->data->error;
787 if (!ret && mrq->stop && mrq->stop->error)
788 ret = mrq->stop->error;
789 if (mrq->data->blocks > 1) {
790 if (!ret && mrq->data->bytes_xfered > mrq->data->blksz)
793 if (!ret && mrq->data->bytes_xfered > 0)
798 ret = RESULT_UNSUP_HOST;
803 struct mmc_test_req {
804 struct mmc_request mrq;
805 struct mmc_command sbc;
806 struct mmc_command cmd;
807 struct mmc_command stop;
808 struct mmc_command status;
809 struct mmc_data data;
813 * Tests nonblock transfer with certain parameters
815 static void mmc_test_req_reset(struct mmc_test_req *rq)
817 memset(rq, 0, sizeof(struct mmc_test_req));
819 rq->mrq.cmd = &rq->cmd;
820 rq->mrq.data = &rq->data;
821 rq->mrq.stop = &rq->stop;
824 static struct mmc_test_req *mmc_test_req_alloc(void)
826 struct mmc_test_req *rq = kmalloc(sizeof(*rq), GFP_KERNEL);
829 mmc_test_req_reset(rq);
835 static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
836 struct scatterlist *sg, unsigned sg_len,
837 unsigned dev_addr, unsigned blocks,
838 unsigned blksz, int write, int count)
840 struct mmc_test_req *rq1, *rq2;
841 struct mmc_test_async_req test_areq[2];
842 struct mmc_async_req *done_areq;
843 struct mmc_async_req *cur_areq = &test_areq[0].areq;
844 struct mmc_async_req *other_areq = &test_areq[1].areq;
845 enum mmc_blk_status status;
849 test_areq[0].test = test;
850 test_areq[1].test = test;
852 rq1 = mmc_test_req_alloc();
853 rq2 = mmc_test_req_alloc();
859 cur_areq->mrq = &rq1->mrq;
860 cur_areq->err_check = mmc_test_check_result_async;
861 other_areq->mrq = &rq2->mrq;
862 other_areq->err_check = mmc_test_check_result_async;
864 for (i = 0; i < count; i++) {
865 mmc_test_prepare_mrq(test, cur_areq->mrq, sg, sg_len, dev_addr,
866 blocks, blksz, write);
867 done_areq = mmc_start_areq(test->card->host, cur_areq, &status);
869 if (status != MMC_BLK_SUCCESS || (!done_areq && i > 0)) {
875 mmc_test_req_reset(container_of(done_areq->mrq,
876 struct mmc_test_req, mrq));
878 swap(cur_areq, other_areq);
882 done_areq = mmc_start_areq(test->card->host, NULL, &status);
883 if (status != MMC_BLK_SUCCESS)
893 * Tests a basic transfer with certain parameters
895 static int mmc_test_simple_transfer(struct mmc_test_card *test,
896 struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
897 unsigned blocks, unsigned blksz, int write)
899 struct mmc_request mrq = {};
900 struct mmc_command cmd = {};
901 struct mmc_command stop = {};
902 struct mmc_data data = {};
908 mmc_test_prepare_mrq(test, &mrq, sg, sg_len, dev_addr,
909 blocks, blksz, write);
911 mmc_wait_for_req(test->card->host, &mrq);
913 mmc_test_wait_busy(test);
915 return mmc_test_check_result(test, &mrq);
919 * Tests a transfer where the card will fail completely or partly
921 static int mmc_test_broken_transfer(struct mmc_test_card *test,
922 unsigned blocks, unsigned blksz, int write)
924 struct mmc_request mrq = {};
925 struct mmc_command cmd = {};
926 struct mmc_command stop = {};
927 struct mmc_data data = {};
929 struct scatterlist sg;
935 sg_init_one(&sg, test->buffer, blocks * blksz);
937 mmc_test_prepare_mrq(test, &mrq, &sg, 1, 0, blocks, blksz, write);
938 mmc_test_prepare_broken_mrq(test, &mrq, write);
940 mmc_wait_for_req(test->card->host, &mrq);
942 mmc_test_wait_busy(test);
944 return mmc_test_check_broken_result(test, &mrq);
948 * Does a complete transfer test where data is also validated
950 * Note: mmc_test_prepare() must have been done before this call
952 static int mmc_test_transfer(struct mmc_test_card *test,
953 struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
954 unsigned blocks, unsigned blksz, int write)
960 for (i = 0; i < blocks * blksz; i++)
961 test->scratch[i] = i;
963 memset(test->scratch, 0, BUFFER_SIZE);
965 local_irq_save(flags);
966 sg_copy_from_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
967 local_irq_restore(flags);
969 ret = mmc_test_set_blksize(test, blksz);
973 ret = mmc_test_simple_transfer(test, sg, sg_len, dev_addr,
974 blocks, blksz, write);
981 ret = mmc_test_set_blksize(test, 512);
985 sectors = (blocks * blksz + 511) / 512;
986 if ((sectors * 512) == (blocks * blksz))
989 if ((sectors * 512) > BUFFER_SIZE)
992 memset(test->buffer, 0, sectors * 512);
994 for (i = 0; i < sectors; i++) {
995 ret = mmc_test_buffer_transfer(test,
996 test->buffer + i * 512,
997 dev_addr + i, 512, 0);
1002 for (i = 0; i < blocks * blksz; i++) {
1003 if (test->buffer[i] != (u8)i)
1007 for (; i < sectors * 512; i++) {
1008 if (test->buffer[i] != 0xDF)
1012 local_irq_save(flags);
1013 sg_copy_to_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
1014 local_irq_restore(flags);
1015 for (i = 0; i < blocks * blksz; i++) {
1016 if (test->scratch[i] != (u8)i)
1024 /*******************************************************************/
1026 /*******************************************************************/
1028 struct mmc_test_case {
1031 int (*prepare)(struct mmc_test_card *);
1032 int (*run)(struct mmc_test_card *);
1033 int (*cleanup)(struct mmc_test_card *);
1036 static int mmc_test_basic_write(struct mmc_test_card *test)
1039 struct scatterlist sg;
1041 ret = mmc_test_set_blksize(test, 512);
1045 sg_init_one(&sg, test->buffer, 512);
1047 return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 1);
1050 static int mmc_test_basic_read(struct mmc_test_card *test)
1053 struct scatterlist sg;
1055 ret = mmc_test_set_blksize(test, 512);
1059 sg_init_one(&sg, test->buffer, 512);
1061 return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 0);
1064 static int mmc_test_verify_write(struct mmc_test_card *test)
1066 struct scatterlist sg;
1068 sg_init_one(&sg, test->buffer, 512);
1070 return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1073 static int mmc_test_verify_read(struct mmc_test_card *test)
1075 struct scatterlist sg;
1077 sg_init_one(&sg, test->buffer, 512);
1079 return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1082 static int mmc_test_multi_write(struct mmc_test_card *test)
1085 struct scatterlist sg;
1087 if (test->card->host->max_blk_count == 1)
1088 return RESULT_UNSUP_HOST;
1090 size = PAGE_SIZE * 2;
1091 size = min(size, test->card->host->max_req_size);
1092 size = min(size, test->card->host->max_seg_size);
1093 size = min(size, test->card->host->max_blk_count * 512);
1096 return RESULT_UNSUP_HOST;
1098 sg_init_one(&sg, test->buffer, size);
1100 return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
1103 static int mmc_test_multi_read(struct mmc_test_card *test)
1106 struct scatterlist sg;
1108 if (test->card->host->max_blk_count == 1)
1109 return RESULT_UNSUP_HOST;
1111 size = PAGE_SIZE * 2;
1112 size = min(size, test->card->host->max_req_size);
1113 size = min(size, test->card->host->max_seg_size);
1114 size = min(size, test->card->host->max_blk_count * 512);
1117 return RESULT_UNSUP_HOST;
1119 sg_init_one(&sg, test->buffer, size);
1121 return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
1124 static int mmc_test_pow2_write(struct mmc_test_card *test)
1127 struct scatterlist sg;
1129 if (!test->card->csd.write_partial)
1130 return RESULT_UNSUP_CARD;
1132 for (i = 1; i < 512; i <<= 1) {
1133 sg_init_one(&sg, test->buffer, i);
1134 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
1142 static int mmc_test_pow2_read(struct mmc_test_card *test)
1145 struct scatterlist sg;
1147 if (!test->card->csd.read_partial)
1148 return RESULT_UNSUP_CARD;
1150 for (i = 1; i < 512; i <<= 1) {
1151 sg_init_one(&sg, test->buffer, i);
1152 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
1160 static int mmc_test_weird_write(struct mmc_test_card *test)
1163 struct scatterlist sg;
1165 if (!test->card->csd.write_partial)
1166 return RESULT_UNSUP_CARD;
1168 for (i = 3; i < 512; i += 7) {
1169 sg_init_one(&sg, test->buffer, i);
1170 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
1178 static int mmc_test_weird_read(struct mmc_test_card *test)
1181 struct scatterlist sg;
1183 if (!test->card->csd.read_partial)
1184 return RESULT_UNSUP_CARD;
1186 for (i = 3; i < 512; i += 7) {
1187 sg_init_one(&sg, test->buffer, i);
1188 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
1196 static int mmc_test_align_write(struct mmc_test_card *test)
1199 struct scatterlist sg;
1201 for (i = 1; i < TEST_ALIGN_END; i++) {
1202 sg_init_one(&sg, test->buffer + i, 512);
1203 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1211 static int mmc_test_align_read(struct mmc_test_card *test)
1214 struct scatterlist sg;
1216 for (i = 1; i < TEST_ALIGN_END; i++) {
1217 sg_init_one(&sg, test->buffer + i, 512);
1218 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1226 static int mmc_test_align_multi_write(struct mmc_test_card *test)
1230 struct scatterlist sg;
1232 if (test->card->host->max_blk_count == 1)
1233 return RESULT_UNSUP_HOST;
1235 size = PAGE_SIZE * 2;
1236 size = min(size, test->card->host->max_req_size);
1237 size = min(size, test->card->host->max_seg_size);
1238 size = min(size, test->card->host->max_blk_count * 512);
1241 return RESULT_UNSUP_HOST;
1243 for (i = 1; i < TEST_ALIGN_END; i++) {
1244 sg_init_one(&sg, test->buffer + i, size);
1245 ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
1253 static int mmc_test_align_multi_read(struct mmc_test_card *test)
1257 struct scatterlist sg;
1259 if (test->card->host->max_blk_count == 1)
1260 return RESULT_UNSUP_HOST;
1262 size = PAGE_SIZE * 2;
1263 size = min(size, test->card->host->max_req_size);
1264 size = min(size, test->card->host->max_seg_size);
1265 size = min(size, test->card->host->max_blk_count * 512);
1268 return RESULT_UNSUP_HOST;
1270 for (i = 1; i < TEST_ALIGN_END; i++) {
1271 sg_init_one(&sg, test->buffer + i, size);
1272 ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
1280 static int mmc_test_xfersize_write(struct mmc_test_card *test)
1284 ret = mmc_test_set_blksize(test, 512);
1288 return mmc_test_broken_transfer(test, 1, 512, 1);
1291 static int mmc_test_xfersize_read(struct mmc_test_card *test)
1295 ret = mmc_test_set_blksize(test, 512);
1299 return mmc_test_broken_transfer(test, 1, 512, 0);
1302 static int mmc_test_multi_xfersize_write(struct mmc_test_card *test)
1306 if (test->card->host->max_blk_count == 1)
1307 return RESULT_UNSUP_HOST;
1309 ret = mmc_test_set_blksize(test, 512);
1313 return mmc_test_broken_transfer(test, 2, 512, 1);
1316 static int mmc_test_multi_xfersize_read(struct mmc_test_card *test)
1320 if (test->card->host->max_blk_count == 1)
1321 return RESULT_UNSUP_HOST;
1323 ret = mmc_test_set_blksize(test, 512);
1327 return mmc_test_broken_transfer(test, 2, 512, 0);
1330 #ifdef CONFIG_HIGHMEM
1332 static int mmc_test_write_high(struct mmc_test_card *test)
1334 struct scatterlist sg;
1336 sg_init_table(&sg, 1);
1337 sg_set_page(&sg, test->highmem, 512, 0);
1339 return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1342 static int mmc_test_read_high(struct mmc_test_card *test)
1344 struct scatterlist sg;
1346 sg_init_table(&sg, 1);
1347 sg_set_page(&sg, test->highmem, 512, 0);
1349 return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1352 static int mmc_test_multi_write_high(struct mmc_test_card *test)
1355 struct scatterlist sg;
1357 if (test->card->host->max_blk_count == 1)
1358 return RESULT_UNSUP_HOST;
1360 size = PAGE_SIZE * 2;
1361 size = min(size, test->card->host->max_req_size);
1362 size = min(size, test->card->host->max_seg_size);
1363 size = min(size, test->card->host->max_blk_count * 512);
1366 return RESULT_UNSUP_HOST;
1368 sg_init_table(&sg, 1);
1369 sg_set_page(&sg, test->highmem, size, 0);
1371 return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
1374 static int mmc_test_multi_read_high(struct mmc_test_card *test)
1377 struct scatterlist sg;
1379 if (test->card->host->max_blk_count == 1)
1380 return RESULT_UNSUP_HOST;
1382 size = PAGE_SIZE * 2;
1383 size = min(size, test->card->host->max_req_size);
1384 size = min(size, test->card->host->max_seg_size);
1385 size = min(size, test->card->host->max_blk_count * 512);
1388 return RESULT_UNSUP_HOST;
1390 sg_init_table(&sg, 1);
1391 sg_set_page(&sg, test->highmem, size, 0);
1393 return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
1398 static int mmc_test_no_highmem(struct mmc_test_card *test)
1400 pr_info("%s: Highmem not configured - test skipped\n",
1401 mmc_hostname(test->card->host));
1405 #endif /* CONFIG_HIGHMEM */
1408 * Map sz bytes so that it can be transferred.
1410 static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
1411 int max_scatter, int min_sg_len)
1413 struct mmc_test_area *t = &test->area;
1416 t->blocks = sz >> 9;
1419 err = mmc_test_map_sg_max_scatter(t->mem, sz, t->sg,
1420 t->max_segs, t->max_seg_sz,
1423 err = mmc_test_map_sg(t->mem, sz, t->sg, 1, t->max_segs,
1424 t->max_seg_sz, &t->sg_len, min_sg_len);
1427 pr_info("%s: Failed to map sg list\n",
1428 mmc_hostname(test->card->host));
1433 * Transfer bytes mapped by mmc_test_area_map().
1435 static int mmc_test_area_transfer(struct mmc_test_card *test,
1436 unsigned int dev_addr, int write)
1438 struct mmc_test_area *t = &test->area;
1440 return mmc_test_simple_transfer(test, t->sg, t->sg_len, dev_addr,
1441 t->blocks, 512, write);
1445 * Map and transfer bytes for multiple transfers.
1447 static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz,
1448 unsigned int dev_addr, int write,
1449 int max_scatter, int timed, int count,
1450 bool nonblock, int min_sg_len)
1452 struct timespec ts1, ts2;
1455 struct mmc_test_area *t = &test->area;
1458 * In the case of a maximally scattered transfer, the maximum transfer
1459 * size is further limited by using PAGE_SIZE segments.
1462 struct mmc_test_area *t = &test->area;
1463 unsigned long max_tfr;
1465 if (t->max_seg_sz >= PAGE_SIZE)
1466 max_tfr = t->max_segs * PAGE_SIZE;
1468 max_tfr = t->max_segs * t->max_seg_sz;
1473 ret = mmc_test_area_map(test, sz, max_scatter, min_sg_len);
1478 getnstimeofday(&ts1);
1480 ret = mmc_test_nonblock_transfer(test, t->sg, t->sg_len,
1481 dev_addr, t->blocks, 512, write, count);
1483 for (i = 0; i < count && ret == 0; i++) {
1484 ret = mmc_test_area_transfer(test, dev_addr, write);
1485 dev_addr += sz >> 9;
1492 getnstimeofday(&ts2);
1495 mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2);
1500 static int mmc_test_area_io(struct mmc_test_card *test, unsigned long sz,
1501 unsigned int dev_addr, int write, int max_scatter,
1504 return mmc_test_area_io_seq(test, sz, dev_addr, write, max_scatter,
1505 timed, 1, false, 0);
1509 * Write the test area entirely.
1511 static int mmc_test_area_fill(struct mmc_test_card *test)
1513 struct mmc_test_area *t = &test->area;
1515 return mmc_test_area_io(test, t->max_tfr, t->dev_addr, 1, 0, 0);
1519 * Erase the test area entirely.
1521 static int mmc_test_area_erase(struct mmc_test_card *test)
1523 struct mmc_test_area *t = &test->area;
1525 if (!mmc_can_erase(test->card))
1528 return mmc_erase(test->card, t->dev_addr, t->max_sz >> 9,
1533 * Cleanup struct mmc_test_area.
1535 static int mmc_test_area_cleanup(struct mmc_test_card *test)
1537 struct mmc_test_area *t = &test->area;
1540 mmc_test_free_mem(t->mem);
1546 * Initialize an area for testing large transfers. The test area is set to the
1547 * middle of the card because cards may have different characteristics at the
1548 * front (for FAT file system optimization). Optionally, the area is erased
1549 * (if the card supports it) which may improve write performance. Optionally,
1550 * the area is filled with data for subsequent read tests.
1552 static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
1554 struct mmc_test_area *t = &test->area;
1555 unsigned long min_sz = 64 * 1024, sz;
1558 ret = mmc_test_set_blksize(test, 512);
1562 /* Make the test area size about 4MiB */
1563 sz = (unsigned long)test->card->pref_erase << 9;
1565 while (t->max_sz < 4 * 1024 * 1024)
1567 while (t->max_sz > TEST_AREA_MAX_SIZE && t->max_sz > sz)
1570 t->max_segs = test->card->host->max_segs;
1571 t->max_seg_sz = test->card->host->max_seg_size;
1572 t->max_seg_sz -= t->max_seg_sz % 512;
1574 t->max_tfr = t->max_sz;
1575 if (t->max_tfr >> 9 > test->card->host->max_blk_count)
1576 t->max_tfr = test->card->host->max_blk_count << 9;
1577 if (t->max_tfr > test->card->host->max_req_size)
1578 t->max_tfr = test->card->host->max_req_size;
1579 if (t->max_tfr / t->max_seg_sz > t->max_segs)
1580 t->max_tfr = t->max_segs * t->max_seg_sz;
1583 * Try to allocate enough memory for a max. sized transfer. Less is OK
1584 * because the same memory can be mapped into the scatterlist more than
1585 * once. Also, take into account the limits imposed on scatterlist
1586 * segments by the host driver.
1588 t->mem = mmc_test_alloc_mem(min_sz, t->max_tfr, t->max_segs,
1593 t->sg = kmalloc_array(t->max_segs, sizeof(*t->sg), GFP_KERNEL);
1599 t->dev_addr = mmc_test_capacity(test->card) / 2;
1600 t->dev_addr -= t->dev_addr % (t->max_sz >> 9);
1603 ret = mmc_test_area_erase(test);
1609 ret = mmc_test_area_fill(test);
1617 mmc_test_area_cleanup(test);
1622 * Prepare for large transfers. Do not erase the test area.
1624 static int mmc_test_area_prepare(struct mmc_test_card *test)
1626 return mmc_test_area_init(test, 0, 0);
1630 * Prepare for large transfers. Do erase the test area.
1632 static int mmc_test_area_prepare_erase(struct mmc_test_card *test)
1634 return mmc_test_area_init(test, 1, 0);
1638 * Prepare for large transfers. Erase and fill the test area.
1640 static int mmc_test_area_prepare_fill(struct mmc_test_card *test)
1642 return mmc_test_area_init(test, 1, 1);
1646 * Test best-case performance. Best-case performance is expected from
1647 * a single large transfer.
1649 * An additional option (max_scatter) allows the measurement of the same
1650 * transfer but with no contiguous pages in the scatter list. This tests
1651 * the efficiency of DMA to handle scattered pages.
1653 static int mmc_test_best_performance(struct mmc_test_card *test, int write,
1656 struct mmc_test_area *t = &test->area;
1658 return mmc_test_area_io(test, t->max_tfr, t->dev_addr, write,
1663 * Best-case read performance.
1665 static int mmc_test_best_read_performance(struct mmc_test_card *test)
1667 return mmc_test_best_performance(test, 0, 0);
1671 * Best-case write performance.
1673 static int mmc_test_best_write_performance(struct mmc_test_card *test)
1675 return mmc_test_best_performance(test, 1, 0);
1679 * Best-case read performance into scattered pages.
1681 static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card *test)
1683 return mmc_test_best_performance(test, 0, 1);
1687 * Best-case write performance from scattered pages.
1689 static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card *test)
1691 return mmc_test_best_performance(test, 1, 1);
1695 * Single read performance by transfer size.
1697 static int mmc_test_profile_read_perf(struct mmc_test_card *test)
1699 struct mmc_test_area *t = &test->area;
1701 unsigned int dev_addr;
1704 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1705 dev_addr = t->dev_addr + (sz >> 9);
1706 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1711 dev_addr = t->dev_addr;
1712 return mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1716 * Single write performance by transfer size.
1718 static int mmc_test_profile_write_perf(struct mmc_test_card *test)
1720 struct mmc_test_area *t = &test->area;
1722 unsigned int dev_addr;
1725 ret = mmc_test_area_erase(test);
1728 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1729 dev_addr = t->dev_addr + (sz >> 9);
1730 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1734 ret = mmc_test_area_erase(test);
1738 dev_addr = t->dev_addr;
1739 return mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1743 * Single trim performance by transfer size.
1745 static int mmc_test_profile_trim_perf(struct mmc_test_card *test)
1747 struct mmc_test_area *t = &test->area;
1749 unsigned int dev_addr;
1750 struct timespec ts1, ts2;
1753 if (!mmc_can_trim(test->card))
1754 return RESULT_UNSUP_CARD;
1756 if (!mmc_can_erase(test->card))
1757 return RESULT_UNSUP_HOST;
1759 for (sz = 512; sz < t->max_sz; sz <<= 1) {
1760 dev_addr = t->dev_addr + (sz >> 9);
1761 getnstimeofday(&ts1);
1762 ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
1765 getnstimeofday(&ts2);
1766 mmc_test_print_rate(test, sz, &ts1, &ts2);
1768 dev_addr = t->dev_addr;
1769 getnstimeofday(&ts1);
1770 ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
1773 getnstimeofday(&ts2);
1774 mmc_test_print_rate(test, sz, &ts1, &ts2);
1778 static int mmc_test_seq_read_perf(struct mmc_test_card *test, unsigned long sz)
1780 struct mmc_test_area *t = &test->area;
1781 unsigned int dev_addr, i, cnt;
1782 struct timespec ts1, ts2;
1785 cnt = t->max_sz / sz;
1786 dev_addr = t->dev_addr;
1787 getnstimeofday(&ts1);
1788 for (i = 0; i < cnt; i++) {
1789 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0);
1792 dev_addr += (sz >> 9);
1794 getnstimeofday(&ts2);
1795 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1800 * Consecutive read performance by transfer size.
1802 static int mmc_test_profile_seq_read_perf(struct mmc_test_card *test)
1804 struct mmc_test_area *t = &test->area;
1808 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1809 ret = mmc_test_seq_read_perf(test, sz);
1814 return mmc_test_seq_read_perf(test, sz);
1817 static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz)
1819 struct mmc_test_area *t = &test->area;
1820 unsigned int dev_addr, i, cnt;
1821 struct timespec ts1, ts2;
1824 ret = mmc_test_area_erase(test);
1827 cnt = t->max_sz / sz;
1828 dev_addr = t->dev_addr;
1829 getnstimeofday(&ts1);
1830 for (i = 0; i < cnt; i++) {
1831 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0);
1834 dev_addr += (sz >> 9);
1836 getnstimeofday(&ts2);
1837 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1842 * Consecutive write performance by transfer size.
1844 static int mmc_test_profile_seq_write_perf(struct mmc_test_card *test)
1846 struct mmc_test_area *t = &test->area;
1850 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1851 ret = mmc_test_seq_write_perf(test, sz);
1856 return mmc_test_seq_write_perf(test, sz);
1860 * Consecutive trim performance by transfer size.
1862 static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
1864 struct mmc_test_area *t = &test->area;
1866 unsigned int dev_addr, i, cnt;
1867 struct timespec ts1, ts2;
1870 if (!mmc_can_trim(test->card))
1871 return RESULT_UNSUP_CARD;
1873 if (!mmc_can_erase(test->card))
1874 return RESULT_UNSUP_HOST;
1876 for (sz = 512; sz <= t->max_sz; sz <<= 1) {
1877 ret = mmc_test_area_erase(test);
1880 ret = mmc_test_area_fill(test);
1883 cnt = t->max_sz / sz;
1884 dev_addr = t->dev_addr;
1885 getnstimeofday(&ts1);
1886 for (i = 0; i < cnt; i++) {
1887 ret = mmc_erase(test->card, dev_addr, sz >> 9,
1891 dev_addr += (sz >> 9);
1893 getnstimeofday(&ts2);
1894 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1899 static unsigned int rnd_next = 1;
1901 static unsigned int mmc_test_rnd_num(unsigned int rnd_cnt)
1905 rnd_next = rnd_next * 1103515245 + 12345;
1906 r = (rnd_next >> 16) & 0x7fff;
1907 return (r * rnd_cnt) >> 15;
1910 static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print,
1913 unsigned int dev_addr, cnt, rnd_addr, range1, range2, last_ea = 0, ea;
1915 struct timespec ts1, ts2, ts;
1920 rnd_addr = mmc_test_capacity(test->card) / 4;
1921 range1 = rnd_addr / test->card->pref_erase;
1922 range2 = range1 / ssz;
1924 getnstimeofday(&ts1);
1925 for (cnt = 0; cnt < UINT_MAX; cnt++) {
1926 getnstimeofday(&ts2);
1927 ts = timespec_sub(ts2, ts1);
1928 if (ts.tv_sec >= 10)
1930 ea = mmc_test_rnd_num(range1);
1934 dev_addr = rnd_addr + test->card->pref_erase * ea +
1935 ssz * mmc_test_rnd_num(range2);
1936 ret = mmc_test_area_io(test, sz, dev_addr, write, 0, 0);
1941 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1945 static int mmc_test_random_perf(struct mmc_test_card *test, int write)
1947 struct mmc_test_area *t = &test->area;
1952 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1954 * When writing, try to get more consistent results by running
1955 * the test twice with exactly the same I/O but outputting the
1956 * results only for the 2nd run.
1960 ret = mmc_test_rnd_perf(test, write, 0, sz);
1965 ret = mmc_test_rnd_perf(test, write, 1, sz);
1972 ret = mmc_test_rnd_perf(test, write, 0, sz);
1977 return mmc_test_rnd_perf(test, write, 1, sz);
1981 * Random read performance by transfer size.
1983 static int mmc_test_random_read_perf(struct mmc_test_card *test)
1985 return mmc_test_random_perf(test, 0);
1989 * Random write performance by transfer size.
1991 static int mmc_test_random_write_perf(struct mmc_test_card *test)
1993 return mmc_test_random_perf(test, 1);
1996 static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
1997 unsigned int tot_sz, int max_scatter)
1999 struct mmc_test_area *t = &test->area;
2000 unsigned int dev_addr, i, cnt, sz, ssz;
2001 struct timespec ts1, ts2;
2007 * In the case of a maximally scattered transfer, the maximum transfer
2008 * size is further limited by using PAGE_SIZE segments.
2011 unsigned long max_tfr;
2013 if (t->max_seg_sz >= PAGE_SIZE)
2014 max_tfr = t->max_segs * PAGE_SIZE;
2016 max_tfr = t->max_segs * t->max_seg_sz;
2022 dev_addr = mmc_test_capacity(test->card) / 4;
2023 if (tot_sz > dev_addr << 9)
2024 tot_sz = dev_addr << 9;
2026 dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
2028 getnstimeofday(&ts1);
2029 for (i = 0; i < cnt; i++) {
2030 ret = mmc_test_area_io(test, sz, dev_addr, write,
2036 getnstimeofday(&ts2);
2038 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
2043 static int mmc_test_large_seq_perf(struct mmc_test_card *test, int write)
2047 for (i = 0; i < 10; i++) {
2048 ret = mmc_test_seq_perf(test, write, 10 * 1024 * 1024, 1);
2052 for (i = 0; i < 5; i++) {
2053 ret = mmc_test_seq_perf(test, write, 100 * 1024 * 1024, 1);
2057 for (i = 0; i < 3; i++) {
2058 ret = mmc_test_seq_perf(test, write, 1000 * 1024 * 1024, 1);
2067 * Large sequential read performance.
2069 static int mmc_test_large_seq_read_perf(struct mmc_test_card *test)
2071 return mmc_test_large_seq_perf(test, 0);
2075 * Large sequential write performance.
2077 static int mmc_test_large_seq_write_perf(struct mmc_test_card *test)
2079 return mmc_test_large_seq_perf(test, 1);
2082 static int mmc_test_rw_multiple(struct mmc_test_card *test,
2083 struct mmc_test_multiple_rw *tdata,
2084 unsigned int reqsize, unsigned int size,
2087 unsigned int dev_addr;
2088 struct mmc_test_area *t = &test->area;
2091 /* Set up test area */
2092 if (size > mmc_test_capacity(test->card) / 2 * 512)
2093 size = mmc_test_capacity(test->card) / 2 * 512;
2094 if (reqsize > t->max_tfr)
2095 reqsize = t->max_tfr;
2096 dev_addr = mmc_test_capacity(test->card) / 4;
2097 if ((dev_addr & 0xffff0000))
2098 dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
2100 dev_addr &= 0xfffff800; /* Round to 1MiB boundary */
2107 /* prepare test area */
2108 if (mmc_can_erase(test->card) &&
2109 tdata->prepare & MMC_TEST_PREP_ERASE) {
2110 ret = mmc_erase(test->card, dev_addr,
2111 size / 512, MMC_SECURE_ERASE_ARG);
2113 ret = mmc_erase(test->card, dev_addr,
2114 size / 512, MMC_ERASE_ARG);
2120 ret = mmc_test_area_io_seq(test, reqsize, dev_addr,
2121 tdata->do_write, 0, 1, size / reqsize,
2122 tdata->do_nonblock_req, min_sg_len);
2128 pr_info("[%s] error\n", __func__);
2132 static int mmc_test_rw_multiple_size(struct mmc_test_card *test,
2133 struct mmc_test_multiple_rw *rw)
2137 void *pre_req = test->card->host->ops->pre_req;
2138 void *post_req = test->card->host->ops->post_req;
2140 if (rw->do_nonblock_req &&
2141 ((!pre_req && post_req) || (pre_req && !post_req))) {
2142 pr_info("error: only one of pre/post is defined\n");
2146 for (i = 0 ; i < rw->len && ret == 0; i++) {
2147 ret = mmc_test_rw_multiple(test, rw, rw->bs[i], rw->size, 0);
2154 static int mmc_test_rw_multiple_sg_len(struct mmc_test_card *test,
2155 struct mmc_test_multiple_rw *rw)
2160 for (i = 0 ; i < rw->len && ret == 0; i++) {
2161 ret = mmc_test_rw_multiple(test, rw, 512 * 1024, rw->size,
2170 * Multiple blocking write 4k to 4 MB chunks
2172 static int mmc_test_profile_mult_write_blocking_perf(struct mmc_test_card *test)
2174 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2175 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2176 struct mmc_test_multiple_rw test_data = {
2178 .size = TEST_AREA_MAX_SIZE,
2179 .len = ARRAY_SIZE(bs),
2181 .do_nonblock_req = false,
2182 .prepare = MMC_TEST_PREP_ERASE,
2185 return mmc_test_rw_multiple_size(test, &test_data);
2189 * Multiple non-blocking write 4k to 4 MB chunks
2191 static int mmc_test_profile_mult_write_nonblock_perf(struct mmc_test_card *test)
2193 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2194 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2195 struct mmc_test_multiple_rw test_data = {
2197 .size = TEST_AREA_MAX_SIZE,
2198 .len = ARRAY_SIZE(bs),
2200 .do_nonblock_req = true,
2201 .prepare = MMC_TEST_PREP_ERASE,
2204 return mmc_test_rw_multiple_size(test, &test_data);
2208 * Multiple blocking read 4k to 4 MB chunks
2210 static int mmc_test_profile_mult_read_blocking_perf(struct mmc_test_card *test)
2212 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2213 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2214 struct mmc_test_multiple_rw test_data = {
2216 .size = TEST_AREA_MAX_SIZE,
2217 .len = ARRAY_SIZE(bs),
2219 .do_nonblock_req = false,
2220 .prepare = MMC_TEST_PREP_NONE,
2223 return mmc_test_rw_multiple_size(test, &test_data);
2227 * Multiple non-blocking read 4k to 4 MB chunks
2229 static int mmc_test_profile_mult_read_nonblock_perf(struct mmc_test_card *test)
2231 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2232 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2233 struct mmc_test_multiple_rw test_data = {
2235 .size = TEST_AREA_MAX_SIZE,
2236 .len = ARRAY_SIZE(bs),
2238 .do_nonblock_req = true,
2239 .prepare = MMC_TEST_PREP_NONE,
2242 return mmc_test_rw_multiple_size(test, &test_data);
2246 * Multiple blocking write 1 to 512 sg elements
2248 static int mmc_test_profile_sglen_wr_blocking_perf(struct mmc_test_card *test)
2250 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2251 1 << 7, 1 << 8, 1 << 9};
2252 struct mmc_test_multiple_rw test_data = {
2254 .size = TEST_AREA_MAX_SIZE,
2255 .len = ARRAY_SIZE(sg_len),
2257 .do_nonblock_req = false,
2258 .prepare = MMC_TEST_PREP_ERASE,
2261 return mmc_test_rw_multiple_sg_len(test, &test_data);
2265 * Multiple non-blocking write 1 to 512 sg elements
2267 static int mmc_test_profile_sglen_wr_nonblock_perf(struct mmc_test_card *test)
2269 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2270 1 << 7, 1 << 8, 1 << 9};
2271 struct mmc_test_multiple_rw test_data = {
2273 .size = TEST_AREA_MAX_SIZE,
2274 .len = ARRAY_SIZE(sg_len),
2276 .do_nonblock_req = true,
2277 .prepare = MMC_TEST_PREP_ERASE,
2280 return mmc_test_rw_multiple_sg_len(test, &test_data);
2284 * Multiple blocking read 1 to 512 sg elements
2286 static int mmc_test_profile_sglen_r_blocking_perf(struct mmc_test_card *test)
2288 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2289 1 << 7, 1 << 8, 1 << 9};
2290 struct mmc_test_multiple_rw test_data = {
2292 .size = TEST_AREA_MAX_SIZE,
2293 .len = ARRAY_SIZE(sg_len),
2295 .do_nonblock_req = false,
2296 .prepare = MMC_TEST_PREP_NONE,
2299 return mmc_test_rw_multiple_sg_len(test, &test_data);
2303 * Multiple non-blocking read 1 to 512 sg elements
2305 static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card *test)
2307 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2308 1 << 7, 1 << 8, 1 << 9};
2309 struct mmc_test_multiple_rw test_data = {
2311 .size = TEST_AREA_MAX_SIZE,
2312 .len = ARRAY_SIZE(sg_len),
2314 .do_nonblock_req = true,
2315 .prepare = MMC_TEST_PREP_NONE,
2318 return mmc_test_rw_multiple_sg_len(test, &test_data);
2322 * eMMC hardware reset.
2324 static int mmc_test_reset(struct mmc_test_card *test)
2326 struct mmc_card *card = test->card;
2327 struct mmc_host *host = card->host;
2330 err = mmc_hw_reset(host);
2333 * Reset will re-enable the card's command queue, but tests
2334 * expect it to be disabled.
2336 if (card->ext_csd.cmdq_en)
2337 mmc_cmdq_disable(card);
2339 } else if (err == -EOPNOTSUPP) {
2340 return RESULT_UNSUP_HOST;
2346 static int mmc_test_send_status(struct mmc_test_card *test,
2347 struct mmc_command *cmd)
2349 memset(cmd, 0, sizeof(*cmd));
2351 cmd->opcode = MMC_SEND_STATUS;
2352 if (!mmc_host_is_spi(test->card->host))
2353 cmd->arg = test->card->rca << 16;
2354 cmd->flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
2356 return mmc_wait_for_cmd(test->card->host, cmd, 0);
2359 static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
2360 unsigned int dev_addr, int use_sbc,
2361 int repeat_cmd, int write, int use_areq)
2363 struct mmc_test_req *rq = mmc_test_req_alloc();
2364 struct mmc_host *host = test->card->host;
2365 struct mmc_test_area *t = &test->area;
2366 struct mmc_test_async_req test_areq = { .test = test };
2367 struct mmc_request *mrq;
2368 unsigned long timeout;
2369 bool expired = false;
2370 enum mmc_blk_status blkstat = MMC_BLK_SUCCESS;
2371 int ret = 0, cmd_ret;
2380 mrq->sbc = &rq->sbc;
2381 mrq->cap_cmd_during_tfr = true;
2383 test_areq.areq.mrq = mrq;
2384 test_areq.areq.err_check = mmc_test_check_result_async;
2386 mmc_test_prepare_mrq(test, mrq, t->sg, t->sg_len, dev_addr, t->blocks,
2389 if (use_sbc && t->blocks > 1 && !mrq->sbc) {
2390 ret = mmc_host_cmd23(host) ?
2396 /* Start ongoing data request */
2398 mmc_start_areq(host, &test_areq.areq, &blkstat);
2399 if (blkstat != MMC_BLK_SUCCESS) {
2404 mmc_wait_for_req(host, mrq);
2407 timeout = jiffies + msecs_to_jiffies(3000);
2411 /* Send status command while data transfer in progress */
2412 cmd_ret = mmc_test_send_status(test, &rq->status);
2416 status = rq->status.resp[0];
2417 if (status & R1_ERROR) {
2422 if (mmc_is_req_done(host, mrq))
2425 expired = time_after(jiffies, timeout);
2427 pr_info("%s: timeout waiting for Tran state status %#x\n",
2428 mmc_hostname(host), status);
2429 cmd_ret = -ETIMEDOUT;
2432 } while (repeat_cmd && R1_CURRENT_STATE(status) != R1_STATE_TRAN);
2434 /* Wait for data request to complete */
2436 mmc_start_areq(host, NULL, &blkstat);
2437 if (blkstat != MMC_BLK_SUCCESS)
2440 mmc_wait_for_req_done(test->card->host, mrq);
2444 * For cap_cmd_during_tfr request, upper layer must send stop if
2447 if (mrq->data->stop && (mrq->data->error || !mrq->sbc)) {
2449 mmc_wait_for_cmd(host, mrq->data->stop, 0);
2451 ret = mmc_wait_for_cmd(host, mrq->data->stop, 0);
2458 pr_info("%s: Send Status failed: status %#x, error %d\n",
2459 mmc_hostname(test->card->host), status, cmd_ret);
2462 ret = mmc_test_check_result(test, mrq);
2466 ret = mmc_test_wait_busy(test);
2470 if (repeat_cmd && (t->blocks + 1) << 9 > t->max_tfr)
2471 pr_info("%s: %d commands completed during transfer of %u blocks\n",
2472 mmc_hostname(test->card->host), count, t->blocks);
2482 static int __mmc_test_cmds_during_tfr(struct mmc_test_card *test,
2483 unsigned long sz, int use_sbc, int write,
2486 struct mmc_test_area *t = &test->area;
2489 if (!(test->card->host->caps & MMC_CAP_CMD_DURING_TFR))
2490 return RESULT_UNSUP_HOST;
2492 ret = mmc_test_area_map(test, sz, 0, 0);
2496 ret = mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 0, write,
2501 return mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 1, write,
2505 static int mmc_test_cmds_during_tfr(struct mmc_test_card *test, int use_sbc,
2506 int write, int use_areq)
2508 struct mmc_test_area *t = &test->area;
2512 for (sz = 512; sz <= t->max_tfr; sz += 512) {
2513 ret = __mmc_test_cmds_during_tfr(test, sz, use_sbc, write,
2522 * Commands during read - no Set Block Count (CMD23).
2524 static int mmc_test_cmds_during_read(struct mmc_test_card *test)
2526 return mmc_test_cmds_during_tfr(test, 0, 0, 0);
2530 * Commands during write - no Set Block Count (CMD23).
2532 static int mmc_test_cmds_during_write(struct mmc_test_card *test)
2534 return mmc_test_cmds_during_tfr(test, 0, 1, 0);
2538 * Commands during read - use Set Block Count (CMD23).
2540 static int mmc_test_cmds_during_read_cmd23(struct mmc_test_card *test)
2542 return mmc_test_cmds_during_tfr(test, 1, 0, 0);
2546 * Commands during write - use Set Block Count (CMD23).
2548 static int mmc_test_cmds_during_write_cmd23(struct mmc_test_card *test)
2550 return mmc_test_cmds_during_tfr(test, 1, 1, 0);
2554 * Commands during non-blocking read - use Set Block Count (CMD23).
2556 static int mmc_test_cmds_during_read_cmd23_nonblock(struct mmc_test_card *test)
2558 return mmc_test_cmds_during_tfr(test, 1, 0, 1);
2562 * Commands during non-blocking write - use Set Block Count (CMD23).
2564 static int mmc_test_cmds_during_write_cmd23_nonblock(struct mmc_test_card *test)
2566 return mmc_test_cmds_during_tfr(test, 1, 1, 1);
2569 static const struct mmc_test_case mmc_test_cases[] = {
2571 .name = "Basic write (no data verification)",
2572 .run = mmc_test_basic_write,
2576 .name = "Basic read (no data verification)",
2577 .run = mmc_test_basic_read,
2581 .name = "Basic write (with data verification)",
2582 .prepare = mmc_test_prepare_write,
2583 .run = mmc_test_verify_write,
2584 .cleanup = mmc_test_cleanup,
2588 .name = "Basic read (with data verification)",
2589 .prepare = mmc_test_prepare_read,
2590 .run = mmc_test_verify_read,
2591 .cleanup = mmc_test_cleanup,
2595 .name = "Multi-block write",
2596 .prepare = mmc_test_prepare_write,
2597 .run = mmc_test_multi_write,
2598 .cleanup = mmc_test_cleanup,
2602 .name = "Multi-block read",
2603 .prepare = mmc_test_prepare_read,
2604 .run = mmc_test_multi_read,
2605 .cleanup = mmc_test_cleanup,
2609 .name = "Power of two block writes",
2610 .prepare = mmc_test_prepare_write,
2611 .run = mmc_test_pow2_write,
2612 .cleanup = mmc_test_cleanup,
2616 .name = "Power of two block reads",
2617 .prepare = mmc_test_prepare_read,
2618 .run = mmc_test_pow2_read,
2619 .cleanup = mmc_test_cleanup,
2623 .name = "Weird sized block writes",
2624 .prepare = mmc_test_prepare_write,
2625 .run = mmc_test_weird_write,
2626 .cleanup = mmc_test_cleanup,
2630 .name = "Weird sized block reads",
2631 .prepare = mmc_test_prepare_read,
2632 .run = mmc_test_weird_read,
2633 .cleanup = mmc_test_cleanup,
2637 .name = "Badly aligned write",
2638 .prepare = mmc_test_prepare_write,
2639 .run = mmc_test_align_write,
2640 .cleanup = mmc_test_cleanup,
2644 .name = "Badly aligned read",
2645 .prepare = mmc_test_prepare_read,
2646 .run = mmc_test_align_read,
2647 .cleanup = mmc_test_cleanup,
2651 .name = "Badly aligned multi-block write",
2652 .prepare = mmc_test_prepare_write,
2653 .run = mmc_test_align_multi_write,
2654 .cleanup = mmc_test_cleanup,
2658 .name = "Badly aligned multi-block read",
2659 .prepare = mmc_test_prepare_read,
2660 .run = mmc_test_align_multi_read,
2661 .cleanup = mmc_test_cleanup,
2665 .name = "Correct xfer_size at write (start failure)",
2666 .run = mmc_test_xfersize_write,
2670 .name = "Correct xfer_size at read (start failure)",
2671 .run = mmc_test_xfersize_read,
2675 .name = "Correct xfer_size at write (midway failure)",
2676 .run = mmc_test_multi_xfersize_write,
2680 .name = "Correct xfer_size at read (midway failure)",
2681 .run = mmc_test_multi_xfersize_read,
2684 #ifdef CONFIG_HIGHMEM
2687 .name = "Highmem write",
2688 .prepare = mmc_test_prepare_write,
2689 .run = mmc_test_write_high,
2690 .cleanup = mmc_test_cleanup,
2694 .name = "Highmem read",
2695 .prepare = mmc_test_prepare_read,
2696 .run = mmc_test_read_high,
2697 .cleanup = mmc_test_cleanup,
2701 .name = "Multi-block highmem write",
2702 .prepare = mmc_test_prepare_write,
2703 .run = mmc_test_multi_write_high,
2704 .cleanup = mmc_test_cleanup,
2708 .name = "Multi-block highmem read",
2709 .prepare = mmc_test_prepare_read,
2710 .run = mmc_test_multi_read_high,
2711 .cleanup = mmc_test_cleanup,
2717 .name = "Highmem write",
2718 .run = mmc_test_no_highmem,
2722 .name = "Highmem read",
2723 .run = mmc_test_no_highmem,
2727 .name = "Multi-block highmem write",
2728 .run = mmc_test_no_highmem,
2732 .name = "Multi-block highmem read",
2733 .run = mmc_test_no_highmem,
2736 #endif /* CONFIG_HIGHMEM */
2739 .name = "Best-case read performance",
2740 .prepare = mmc_test_area_prepare_fill,
2741 .run = mmc_test_best_read_performance,
2742 .cleanup = mmc_test_area_cleanup,
2746 .name = "Best-case write performance",
2747 .prepare = mmc_test_area_prepare_erase,
2748 .run = mmc_test_best_write_performance,
2749 .cleanup = mmc_test_area_cleanup,
2753 .name = "Best-case read performance into scattered pages",
2754 .prepare = mmc_test_area_prepare_fill,
2755 .run = mmc_test_best_read_perf_max_scatter,
2756 .cleanup = mmc_test_area_cleanup,
2760 .name = "Best-case write performance from scattered pages",
2761 .prepare = mmc_test_area_prepare_erase,
2762 .run = mmc_test_best_write_perf_max_scatter,
2763 .cleanup = mmc_test_area_cleanup,
2767 .name = "Single read performance by transfer size",
2768 .prepare = mmc_test_area_prepare_fill,
2769 .run = mmc_test_profile_read_perf,
2770 .cleanup = mmc_test_area_cleanup,
2774 .name = "Single write performance by transfer size",
2775 .prepare = mmc_test_area_prepare,
2776 .run = mmc_test_profile_write_perf,
2777 .cleanup = mmc_test_area_cleanup,
2781 .name = "Single trim performance by transfer size",
2782 .prepare = mmc_test_area_prepare_fill,
2783 .run = mmc_test_profile_trim_perf,
2784 .cleanup = mmc_test_area_cleanup,
2788 .name = "Consecutive read performance by transfer size",
2789 .prepare = mmc_test_area_prepare_fill,
2790 .run = mmc_test_profile_seq_read_perf,
2791 .cleanup = mmc_test_area_cleanup,
2795 .name = "Consecutive write performance by transfer size",
2796 .prepare = mmc_test_area_prepare,
2797 .run = mmc_test_profile_seq_write_perf,
2798 .cleanup = mmc_test_area_cleanup,
2802 .name = "Consecutive trim performance by transfer size",
2803 .prepare = mmc_test_area_prepare,
2804 .run = mmc_test_profile_seq_trim_perf,
2805 .cleanup = mmc_test_area_cleanup,
2809 .name = "Random read performance by transfer size",
2810 .prepare = mmc_test_area_prepare,
2811 .run = mmc_test_random_read_perf,
2812 .cleanup = mmc_test_area_cleanup,
2816 .name = "Random write performance by transfer size",
2817 .prepare = mmc_test_area_prepare,
2818 .run = mmc_test_random_write_perf,
2819 .cleanup = mmc_test_area_cleanup,
2823 .name = "Large sequential read into scattered pages",
2824 .prepare = mmc_test_area_prepare,
2825 .run = mmc_test_large_seq_read_perf,
2826 .cleanup = mmc_test_area_cleanup,
2830 .name = "Large sequential write from scattered pages",
2831 .prepare = mmc_test_area_prepare,
2832 .run = mmc_test_large_seq_write_perf,
2833 .cleanup = mmc_test_area_cleanup,
2837 .name = "Write performance with blocking req 4k to 4MB",
2838 .prepare = mmc_test_area_prepare,
2839 .run = mmc_test_profile_mult_write_blocking_perf,
2840 .cleanup = mmc_test_area_cleanup,
2844 .name = "Write performance with non-blocking req 4k to 4MB",
2845 .prepare = mmc_test_area_prepare,
2846 .run = mmc_test_profile_mult_write_nonblock_perf,
2847 .cleanup = mmc_test_area_cleanup,
2851 .name = "Read performance with blocking req 4k to 4MB",
2852 .prepare = mmc_test_area_prepare,
2853 .run = mmc_test_profile_mult_read_blocking_perf,
2854 .cleanup = mmc_test_area_cleanup,
2858 .name = "Read performance with non-blocking req 4k to 4MB",
2859 .prepare = mmc_test_area_prepare,
2860 .run = mmc_test_profile_mult_read_nonblock_perf,
2861 .cleanup = mmc_test_area_cleanup,
2865 .name = "Write performance blocking req 1 to 512 sg elems",
2866 .prepare = mmc_test_area_prepare,
2867 .run = mmc_test_profile_sglen_wr_blocking_perf,
2868 .cleanup = mmc_test_area_cleanup,
2872 .name = "Write performance non-blocking req 1 to 512 sg elems",
2873 .prepare = mmc_test_area_prepare,
2874 .run = mmc_test_profile_sglen_wr_nonblock_perf,
2875 .cleanup = mmc_test_area_cleanup,
2879 .name = "Read performance blocking req 1 to 512 sg elems",
2880 .prepare = mmc_test_area_prepare,
2881 .run = mmc_test_profile_sglen_r_blocking_perf,
2882 .cleanup = mmc_test_area_cleanup,
2886 .name = "Read performance non-blocking req 1 to 512 sg elems",
2887 .prepare = mmc_test_area_prepare,
2888 .run = mmc_test_profile_sglen_r_nonblock_perf,
2889 .cleanup = mmc_test_area_cleanup,
2893 .name = "Reset test",
2894 .run = mmc_test_reset,
2898 .name = "Commands during read - no Set Block Count (CMD23)",
2899 .prepare = mmc_test_area_prepare,
2900 .run = mmc_test_cmds_during_read,
2901 .cleanup = mmc_test_area_cleanup,
2905 .name = "Commands during write - no Set Block Count (CMD23)",
2906 .prepare = mmc_test_area_prepare,
2907 .run = mmc_test_cmds_during_write,
2908 .cleanup = mmc_test_area_cleanup,
2912 .name = "Commands during read - use Set Block Count (CMD23)",
2913 .prepare = mmc_test_area_prepare,
2914 .run = mmc_test_cmds_during_read_cmd23,
2915 .cleanup = mmc_test_area_cleanup,
2919 .name = "Commands during write - use Set Block Count (CMD23)",
2920 .prepare = mmc_test_area_prepare,
2921 .run = mmc_test_cmds_during_write_cmd23,
2922 .cleanup = mmc_test_area_cleanup,
2926 .name = "Commands during non-blocking read - use Set Block Count (CMD23)",
2927 .prepare = mmc_test_area_prepare,
2928 .run = mmc_test_cmds_during_read_cmd23_nonblock,
2929 .cleanup = mmc_test_area_cleanup,
2933 .name = "Commands during non-blocking write - use Set Block Count (CMD23)",
2934 .prepare = mmc_test_area_prepare,
2935 .run = mmc_test_cmds_during_write_cmd23_nonblock,
2936 .cleanup = mmc_test_area_cleanup,
2940 static DEFINE_MUTEX(mmc_test_lock);
2942 static LIST_HEAD(mmc_test_result);
2944 static void mmc_test_run(struct mmc_test_card *test, int testcase)
2948 pr_info("%s: Starting tests of card %s...\n",
2949 mmc_hostname(test->card->host), mmc_card_id(test->card));
2951 mmc_claim_host(test->card->host);
2953 for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++) {
2954 struct mmc_test_general_result *gr;
2956 if (testcase && ((i + 1) != testcase))
2959 pr_info("%s: Test case %d. %s...\n",
2960 mmc_hostname(test->card->host), i + 1,
2961 mmc_test_cases[i].name);
2963 if (mmc_test_cases[i].prepare) {
2964 ret = mmc_test_cases[i].prepare(test);
2966 pr_info("%s: Result: Prepare stage failed! (%d)\n",
2967 mmc_hostname(test->card->host),
2973 gr = kzalloc(sizeof(*gr), GFP_KERNEL);
2975 INIT_LIST_HEAD(&gr->tr_lst);
2977 /* Assign data what we know already */
2978 gr->card = test->card;
2981 /* Append container to global one */
2982 list_add_tail(&gr->link, &mmc_test_result);
2985 * Save the pointer to created container in our private
2991 ret = mmc_test_cases[i].run(test);
2994 pr_info("%s: Result: OK\n",
2995 mmc_hostname(test->card->host));
2998 pr_info("%s: Result: FAILED\n",
2999 mmc_hostname(test->card->host));
3001 case RESULT_UNSUP_HOST:
3002 pr_info("%s: Result: UNSUPPORTED (by host)\n",
3003 mmc_hostname(test->card->host));
3005 case RESULT_UNSUP_CARD:
3006 pr_info("%s: Result: UNSUPPORTED (by card)\n",
3007 mmc_hostname(test->card->host));
3010 pr_info("%s: Result: ERROR (%d)\n",
3011 mmc_hostname(test->card->host), ret);
3014 /* Save the result */
3018 if (mmc_test_cases[i].cleanup) {
3019 ret = mmc_test_cases[i].cleanup(test);
3021 pr_info("%s: Warning: Cleanup stage failed! (%d)\n",
3022 mmc_hostname(test->card->host),
3028 mmc_release_host(test->card->host);
3030 pr_info("%s: Tests completed.\n",
3031 mmc_hostname(test->card->host));
3034 static void mmc_test_free_result(struct mmc_card *card)
3036 struct mmc_test_general_result *gr, *grs;
3038 mutex_lock(&mmc_test_lock);
3040 list_for_each_entry_safe(gr, grs, &mmc_test_result, link) {
3041 struct mmc_test_transfer_result *tr, *trs;
3043 if (card && gr->card != card)
3046 list_for_each_entry_safe(tr, trs, &gr->tr_lst, link) {
3047 list_del(&tr->link);
3051 list_del(&gr->link);
3055 mutex_unlock(&mmc_test_lock);
3058 static LIST_HEAD(mmc_test_file_test);
3060 static int mtf_test_show(struct seq_file *sf, void *data)
3062 struct mmc_card *card = (struct mmc_card *)sf->private;
3063 struct mmc_test_general_result *gr;
3065 mutex_lock(&mmc_test_lock);
3067 list_for_each_entry(gr, &mmc_test_result, link) {
3068 struct mmc_test_transfer_result *tr;
3070 if (gr->card != card)
3073 seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
3075 list_for_each_entry(tr, &gr->tr_lst, link) {
3076 seq_printf(sf, "%u %d %lu.%09lu %u %u.%02u\n",
3077 tr->count, tr->sectors,
3078 (unsigned long)tr->ts.tv_sec,
3079 (unsigned long)tr->ts.tv_nsec,
3080 tr->rate, tr->iops / 100, tr->iops % 100);
3084 mutex_unlock(&mmc_test_lock);
3089 static int mtf_test_open(struct inode *inode, struct file *file)
3091 return single_open(file, mtf_test_show, inode->i_private);
3094 static ssize_t mtf_test_write(struct file *file, const char __user *buf,
3095 size_t count, loff_t *pos)
3097 struct seq_file *sf = (struct seq_file *)file->private_data;
3098 struct mmc_card *card = (struct mmc_card *)sf->private;
3099 struct mmc_test_card *test;
3103 ret = kstrtol_from_user(buf, count, 10, &testcase);
3107 test = kzalloc(sizeof(*test), GFP_KERNEL);
3112 * Remove all test cases associated with given card. Thus we have only
3113 * actual data of the last run.
3115 mmc_test_free_result(card);
3119 test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL);
3120 #ifdef CONFIG_HIGHMEM
3121 test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER);
3124 #ifdef CONFIG_HIGHMEM
3125 if (test->buffer && test->highmem) {
3129 mutex_lock(&mmc_test_lock);
3130 mmc_test_run(test, testcase);
3131 mutex_unlock(&mmc_test_lock);
3134 #ifdef CONFIG_HIGHMEM
3135 __free_pages(test->highmem, BUFFER_ORDER);
3137 kfree(test->buffer);
3143 static const struct file_operations mmc_test_fops_test = {
3144 .open = mtf_test_open,
3146 .write = mtf_test_write,
3147 .llseek = seq_lseek,
3148 .release = single_release,
3151 static int mtf_testlist_show(struct seq_file *sf, void *data)
3155 mutex_lock(&mmc_test_lock);
3157 seq_puts(sf, "0:\tRun all tests\n");
3158 for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++)
3159 seq_printf(sf, "%d:\t%s\n", i + 1, mmc_test_cases[i].name);
3161 mutex_unlock(&mmc_test_lock);
3166 static int mtf_testlist_open(struct inode *inode, struct file *file)
3168 return single_open(file, mtf_testlist_show, inode->i_private);
3171 static const struct file_operations mmc_test_fops_testlist = {
3172 .open = mtf_testlist_open,
3174 .llseek = seq_lseek,
3175 .release = single_release,
3178 static void mmc_test_free_dbgfs_file(struct mmc_card *card)
3180 struct mmc_test_dbgfs_file *df, *dfs;
3182 mutex_lock(&mmc_test_lock);
3184 list_for_each_entry_safe(df, dfs, &mmc_test_file_test, link) {
3185 if (card && df->card != card)
3187 debugfs_remove(df->file);
3188 list_del(&df->link);
3192 mutex_unlock(&mmc_test_lock);
3195 static int __mmc_test_register_dbgfs_file(struct mmc_card *card,
3196 const char *name, umode_t mode, const struct file_operations *fops)
3198 struct dentry *file = NULL;
3199 struct mmc_test_dbgfs_file *df;
3201 if (card->debugfs_root)
3202 file = debugfs_create_file(name, mode, card->debugfs_root,
3205 if (IS_ERR_OR_NULL(file)) {
3207 "Can't create %s. Perhaps debugfs is disabled.\n",
3212 df = kmalloc(sizeof(*df), GFP_KERNEL);
3214 debugfs_remove(file);
3221 list_add(&df->link, &mmc_test_file_test);
3225 static int mmc_test_register_dbgfs_file(struct mmc_card *card)
3229 mutex_lock(&mmc_test_lock);
3231 ret = __mmc_test_register_dbgfs_file(card, "test", S_IWUSR | S_IRUGO,
3232 &mmc_test_fops_test);
3236 ret = __mmc_test_register_dbgfs_file(card, "testlist", S_IRUGO,
3237 &mmc_test_fops_testlist);
3242 mutex_unlock(&mmc_test_lock);
3247 static int mmc_test_probe(struct mmc_card *card)
3251 if (!mmc_card_mmc(card) && !mmc_card_sd(card))
3254 ret = mmc_test_register_dbgfs_file(card);
3258 if (card->ext_csd.cmdq_en) {
3259 mmc_claim_host(card->host);
3260 ret = mmc_cmdq_disable(card);
3261 mmc_release_host(card->host);
3266 dev_info(&card->dev, "Card claimed for testing.\n");
3271 static void mmc_test_remove(struct mmc_card *card)
3273 if (card->reenable_cmdq) {
3274 mmc_claim_host(card->host);
3275 mmc_cmdq_enable(card);
3276 mmc_release_host(card->host);
3278 mmc_test_free_result(card);
3279 mmc_test_free_dbgfs_file(card);
3282 static void mmc_test_shutdown(struct mmc_card *card)
3286 static struct mmc_driver mmc_driver = {
3290 .probe = mmc_test_probe,
3291 .remove = mmc_test_remove,
3292 .shutdown = mmc_test_shutdown,
3295 static int __init mmc_test_init(void)
3297 return mmc_register_driver(&mmc_driver);
3300 static void __exit mmc_test_exit(void)
3302 /* Clear stalled data if card is still plugged */
3303 mmc_test_free_result(NULL);
3304 mmc_test_free_dbgfs_file(NULL);
3306 mmc_unregister_driver(&mmc_driver);
3309 module_init(mmc_test_init);
3310 module_exit(mmc_test_exit);
3312 MODULE_LICENSE("GPL");
3313 MODULE_DESCRIPTION("Multimedia Card (MMC) host test driver");
3314 MODULE_AUTHOR("Pierre Ossman");