perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / drivers / mmc / core / mmc_test.c
blobef18daeaa4cc6f0a54f2814762fd7d615fcf4c9f
1 /*
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.
8 */
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>
25 #include "core.h"
26 #include "card.h"
27 #include "host.h"
28 #include "bus.h"
29 #include "mmc_ops.h"
31 #define RESULT_OK 0
32 #define RESULT_FAIL 1
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)
47 /**
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 {
53 struct page *page;
54 unsigned int order;
57 /**
58 * struct mmc_test_mem - allocated memory.
59 * @arr: array of allocations
60 * @cnt: number of allocations
62 struct mmc_test_mem {
63 struct mmc_test_pages *arr;
64 unsigned int cnt;
67 /**
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
77 * @sg: scatterlist
79 struct mmc_test_area {
80 unsigned long max_sz;
81 unsigned int dev_addr;
82 unsigned int max_tfr;
83 unsigned int max_segs;
84 unsigned int max_seg_sz;
85 unsigned int blocks;
86 unsigned int sg_len;
87 struct mmc_test_mem *mem;
88 struct scatterlist *sg;
91 /**
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;
102 unsigned int count;
103 unsigned int sectors;
104 struct timespec64 ts;
105 unsigned int rate;
106 unsigned int iops;
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;
120 int testcase;
121 int result;
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;
134 struct dentry *file;
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];
150 u8 *buffer;
151 #ifdef CONFIG_HIGHMEM
152 struct page *highmem;
153 #endif
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;
166 unsigned int *bs;
167 unsigned int len;
168 unsigned int size;
169 bool do_write;
170 bool do_nonblock_req;
171 enum mmc_test_prep_media prepare;
174 /*******************************************************************/
175 /* General helper functions */
176 /*******************************************************************/
179 * Configure correct block size in card
181 static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size)
183 return mmc_set_blocklen(test->card, size);
186 static bool mmc_test_card_cmd23(struct mmc_card *card)
188 return mmc_card_mmc(card) ||
189 (mmc_card_sd(card) && card->scr.cmds & SD_SCR_CMD23_SUPPORT);
192 static void mmc_test_prepare_sbc(struct mmc_test_card *test,
193 struct mmc_request *mrq, unsigned int blocks)
195 struct mmc_card *card = test->card;
197 if (!mrq->sbc || !mmc_host_cmd23(card->host) ||
198 !mmc_test_card_cmd23(card) || !mmc_op_multi(mrq->cmd->opcode) ||
199 (card->quirks & MMC_QUIRK_BLK_NO_CMD23)) {
200 mrq->sbc = NULL;
201 return;
204 mrq->sbc->opcode = MMC_SET_BLOCK_COUNT;
205 mrq->sbc->arg = blocks;
206 mrq->sbc->flags = MMC_RSP_R1 | MMC_CMD_AC;
210 * Fill in the mmc_request structure given a set of transfer parameters.
212 static void mmc_test_prepare_mrq(struct mmc_test_card *test,
213 struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len,
214 unsigned dev_addr, unsigned blocks, unsigned blksz, int write)
216 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop))
217 return;
219 if (blocks > 1) {
220 mrq->cmd->opcode = write ?
221 MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK;
222 } else {
223 mrq->cmd->opcode = write ?
224 MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
227 mrq->cmd->arg = dev_addr;
228 if (!mmc_card_blockaddr(test->card))
229 mrq->cmd->arg <<= 9;
231 mrq->cmd->flags = MMC_RSP_R1 | MMC_CMD_ADTC;
233 if (blocks == 1)
234 mrq->stop = NULL;
235 else {
236 mrq->stop->opcode = MMC_STOP_TRANSMISSION;
237 mrq->stop->arg = 0;
238 mrq->stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
241 mrq->data->blksz = blksz;
242 mrq->data->blocks = blocks;
243 mrq->data->flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
244 mrq->data->sg = sg;
245 mrq->data->sg_len = sg_len;
247 mmc_test_prepare_sbc(test, mrq, blocks);
249 mmc_set_data_timeout(mrq->data, test->card);
252 static int mmc_test_busy(struct mmc_command *cmd)
254 return !(cmd->resp[0] & R1_READY_FOR_DATA) ||
255 (R1_CURRENT_STATE(cmd->resp[0]) == R1_STATE_PRG);
259 * Wait for the card to finish the busy state
261 static int mmc_test_wait_busy(struct mmc_test_card *test)
263 int ret, busy;
264 struct mmc_command cmd = {};
266 busy = 0;
267 do {
268 memset(&cmd, 0, sizeof(struct mmc_command));
270 cmd.opcode = MMC_SEND_STATUS;
271 cmd.arg = test->card->rca << 16;
272 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
274 ret = mmc_wait_for_cmd(test->card->host, &cmd, 0);
275 if (ret)
276 break;
278 if (!busy && mmc_test_busy(&cmd)) {
279 busy = 1;
280 if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
281 pr_info("%s: Warning: Host did not wait for busy state to end.\n",
282 mmc_hostname(test->card->host));
284 } while (mmc_test_busy(&cmd));
286 return ret;
290 * Transfer a single sector of kernel addressable data
292 static int mmc_test_buffer_transfer(struct mmc_test_card *test,
293 u8 *buffer, unsigned addr, unsigned blksz, int write)
295 struct mmc_request mrq = {};
296 struct mmc_command cmd = {};
297 struct mmc_command stop = {};
298 struct mmc_data data = {};
300 struct scatterlist sg;
302 mrq.cmd = &cmd;
303 mrq.data = &data;
304 mrq.stop = &stop;
306 sg_init_one(&sg, buffer, blksz);
308 mmc_test_prepare_mrq(test, &mrq, &sg, 1, addr, 1, blksz, write);
310 mmc_wait_for_req(test->card->host, &mrq);
312 if (cmd.error)
313 return cmd.error;
314 if (data.error)
315 return data.error;
317 return mmc_test_wait_busy(test);
320 static void mmc_test_free_mem(struct mmc_test_mem *mem)
322 if (!mem)
323 return;
324 while (mem->cnt--)
325 __free_pages(mem->arr[mem->cnt].page,
326 mem->arr[mem->cnt].order);
327 kfree(mem->arr);
328 kfree(mem);
332 * Allocate a lot of memory, preferably max_sz but at least min_sz. In case
333 * there isn't much memory do not exceed 1/16th total lowmem pages. Also do
334 * not exceed a maximum number of segments and try not to make segments much
335 * bigger than maximum segment size.
337 static struct mmc_test_mem *mmc_test_alloc_mem(unsigned long min_sz,
338 unsigned long max_sz,
339 unsigned int max_segs,
340 unsigned int max_seg_sz)
342 unsigned long max_page_cnt = DIV_ROUND_UP(max_sz, PAGE_SIZE);
343 unsigned long min_page_cnt = DIV_ROUND_UP(min_sz, PAGE_SIZE);
344 unsigned long max_seg_page_cnt = DIV_ROUND_UP(max_seg_sz, PAGE_SIZE);
345 unsigned long page_cnt = 0;
346 unsigned long limit = nr_free_buffer_pages() >> 4;
347 struct mmc_test_mem *mem;
349 if (max_page_cnt > limit)
350 max_page_cnt = limit;
351 if (min_page_cnt > max_page_cnt)
352 min_page_cnt = max_page_cnt;
354 if (max_seg_page_cnt > max_page_cnt)
355 max_seg_page_cnt = max_page_cnt;
357 if (max_segs > max_page_cnt)
358 max_segs = max_page_cnt;
360 mem = kzalloc(sizeof(*mem), GFP_KERNEL);
361 if (!mem)
362 return NULL;
364 mem->arr = kcalloc(max_segs, sizeof(*mem->arr), GFP_KERNEL);
365 if (!mem->arr)
366 goto out_free;
368 while (max_page_cnt) {
369 struct page *page;
370 unsigned int order;
371 gfp_t flags = GFP_KERNEL | GFP_DMA | __GFP_NOWARN |
372 __GFP_NORETRY;
374 order = get_order(max_seg_page_cnt << PAGE_SHIFT);
375 while (1) {
376 page = alloc_pages(flags, order);
377 if (page || !order)
378 break;
379 order -= 1;
381 if (!page) {
382 if (page_cnt < min_page_cnt)
383 goto out_free;
384 break;
386 mem->arr[mem->cnt].page = page;
387 mem->arr[mem->cnt].order = order;
388 mem->cnt += 1;
389 if (max_page_cnt <= (1UL << order))
390 break;
391 max_page_cnt -= 1UL << order;
392 page_cnt += 1UL << order;
393 if (mem->cnt >= max_segs) {
394 if (page_cnt < min_page_cnt)
395 goto out_free;
396 break;
400 return mem;
402 out_free:
403 mmc_test_free_mem(mem);
404 return NULL;
408 * Map memory into a scatterlist. Optionally allow the same memory to be
409 * mapped more than once.
411 static int mmc_test_map_sg(struct mmc_test_mem *mem, unsigned long size,
412 struct scatterlist *sglist, int repeat,
413 unsigned int max_segs, unsigned int max_seg_sz,
414 unsigned int *sg_len, int min_sg_len)
416 struct scatterlist *sg = NULL;
417 unsigned int i;
418 unsigned long sz = size;
420 sg_init_table(sglist, max_segs);
421 if (min_sg_len > max_segs)
422 min_sg_len = max_segs;
424 *sg_len = 0;
425 do {
426 for (i = 0; i < mem->cnt; i++) {
427 unsigned long len = PAGE_SIZE << mem->arr[i].order;
429 if (min_sg_len && (size / min_sg_len < len))
430 len = ALIGN(size / min_sg_len, 512);
431 if (len > sz)
432 len = sz;
433 if (len > max_seg_sz)
434 len = max_seg_sz;
435 if (sg)
436 sg = sg_next(sg);
437 else
438 sg = sglist;
439 if (!sg)
440 return -EINVAL;
441 sg_set_page(sg, mem->arr[i].page, len, 0);
442 sz -= len;
443 *sg_len += 1;
444 if (!sz)
445 break;
447 } while (sz && repeat);
449 if (sz)
450 return -EINVAL;
452 if (sg)
453 sg_mark_end(sg);
455 return 0;
459 * Map memory into a scatterlist so that no pages are contiguous. Allow the
460 * same memory to be mapped more than once.
462 static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem,
463 unsigned long sz,
464 struct scatterlist *sglist,
465 unsigned int max_segs,
466 unsigned int max_seg_sz,
467 unsigned int *sg_len)
469 struct scatterlist *sg = NULL;
470 unsigned int i = mem->cnt, cnt;
471 unsigned long len;
472 void *base, *addr, *last_addr = NULL;
474 sg_init_table(sglist, max_segs);
476 *sg_len = 0;
477 while (sz) {
478 base = page_address(mem->arr[--i].page);
479 cnt = 1 << mem->arr[i].order;
480 while (sz && cnt) {
481 addr = base + PAGE_SIZE * --cnt;
482 if (last_addr && last_addr + PAGE_SIZE == addr)
483 continue;
484 last_addr = addr;
485 len = PAGE_SIZE;
486 if (len > max_seg_sz)
487 len = max_seg_sz;
488 if (len > sz)
489 len = sz;
490 if (sg)
491 sg = sg_next(sg);
492 else
493 sg = sglist;
494 if (!sg)
495 return -EINVAL;
496 sg_set_page(sg, virt_to_page(addr), len, 0);
497 sz -= len;
498 *sg_len += 1;
500 if (i == 0)
501 i = mem->cnt;
504 if (sg)
505 sg_mark_end(sg);
507 return 0;
511 * Calculate transfer rate in bytes per second.
513 static unsigned int mmc_test_rate(uint64_t bytes, struct timespec64 *ts)
515 uint64_t ns;
517 ns = timespec64_to_ns(ts);
518 bytes *= 1000000000;
520 while (ns > UINT_MAX) {
521 bytes >>= 1;
522 ns >>= 1;
525 if (!ns)
526 return 0;
528 do_div(bytes, (uint32_t)ns);
530 return bytes;
534 * Save transfer results for future usage
536 static void mmc_test_save_transfer_result(struct mmc_test_card *test,
537 unsigned int count, unsigned int sectors, struct timespec64 ts,
538 unsigned int rate, unsigned int iops)
540 struct mmc_test_transfer_result *tr;
542 if (!test->gr)
543 return;
545 tr = kmalloc(sizeof(*tr), GFP_KERNEL);
546 if (!tr)
547 return;
549 tr->count = count;
550 tr->sectors = sectors;
551 tr->ts = ts;
552 tr->rate = rate;
553 tr->iops = iops;
555 list_add_tail(&tr->link, &test->gr->tr_lst);
559 * Print the transfer rate.
561 static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
562 struct timespec64 *ts1, struct timespec64 *ts2)
564 unsigned int rate, iops, sectors = bytes >> 9;
565 struct timespec64 ts;
567 ts = timespec64_sub(*ts2, *ts1);
569 rate = mmc_test_rate(bytes, &ts);
570 iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
572 pr_info("%s: Transfer of %u sectors (%u%s KiB) took %llu.%09u "
573 "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
574 mmc_hostname(test->card->host), sectors, sectors >> 1,
575 (sectors & 1 ? ".5" : ""), (u64)ts.tv_sec,
576 (u32)ts.tv_nsec, rate / 1000, rate / 1024,
577 iops / 100, iops % 100);
579 mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops);
583 * Print the average transfer rate.
585 static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
586 unsigned int count, struct timespec64 *ts1,
587 struct timespec64 *ts2)
589 unsigned int rate, iops, sectors = bytes >> 9;
590 uint64_t tot = bytes * count;
591 struct timespec64 ts;
593 ts = timespec64_sub(*ts2, *ts1);
595 rate = mmc_test_rate(tot, &ts);
596 iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
598 pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
599 "%llu.%09u seconds (%u kB/s, %u KiB/s, "
600 "%u.%02u IOPS, sg_len %d)\n",
601 mmc_hostname(test->card->host), count, sectors, count,
602 sectors >> 1, (sectors & 1 ? ".5" : ""),
603 (u64)ts.tv_sec, (u32)ts.tv_nsec,
604 rate / 1000, rate / 1024, iops / 100, iops % 100,
605 test->area.sg_len);
607 mmc_test_save_transfer_result(test, count, sectors, ts, rate, iops);
611 * Return the card size in sectors.
613 static unsigned int mmc_test_capacity(struct mmc_card *card)
615 if (!mmc_card_sd(card) && mmc_card_blockaddr(card))
616 return card->ext_csd.sectors;
617 else
618 return card->csd.capacity << (card->csd.read_blkbits - 9);
621 /*******************************************************************/
622 /* Test preparation and cleanup */
623 /*******************************************************************/
626 * Fill the first couple of sectors of the card with known data
627 * so that bad reads/writes can be detected
629 static int __mmc_test_prepare(struct mmc_test_card *test, int write)
631 int ret, i;
633 ret = mmc_test_set_blksize(test, 512);
634 if (ret)
635 return ret;
637 if (write)
638 memset(test->buffer, 0xDF, 512);
639 else {
640 for (i = 0; i < 512; i++)
641 test->buffer[i] = i;
644 for (i = 0; i < BUFFER_SIZE / 512; i++) {
645 ret = mmc_test_buffer_transfer(test, test->buffer, i, 512, 1);
646 if (ret)
647 return ret;
650 return 0;
653 static int mmc_test_prepare_write(struct mmc_test_card *test)
655 return __mmc_test_prepare(test, 1);
658 static int mmc_test_prepare_read(struct mmc_test_card *test)
660 return __mmc_test_prepare(test, 0);
663 static int mmc_test_cleanup(struct mmc_test_card *test)
665 int ret, i;
667 ret = mmc_test_set_blksize(test, 512);
668 if (ret)
669 return ret;
671 memset(test->buffer, 0, 512);
673 for (i = 0; i < BUFFER_SIZE / 512; i++) {
674 ret = mmc_test_buffer_transfer(test, test->buffer, i, 512, 1);
675 if (ret)
676 return ret;
679 return 0;
682 /*******************************************************************/
683 /* Test execution helpers */
684 /*******************************************************************/
687 * Modifies the mmc_request to perform the "short transfer" tests
689 static void mmc_test_prepare_broken_mrq(struct mmc_test_card *test,
690 struct mmc_request *mrq, int write)
692 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
693 return;
695 if (mrq->data->blocks > 1) {
696 mrq->cmd->opcode = write ?
697 MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
698 mrq->stop = NULL;
699 } else {
700 mrq->cmd->opcode = MMC_SEND_STATUS;
701 mrq->cmd->arg = test->card->rca << 16;
706 * Checks that a normal transfer didn't have any errors
708 static int mmc_test_check_result(struct mmc_test_card *test,
709 struct mmc_request *mrq)
711 int ret;
713 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
714 return -EINVAL;
716 ret = 0;
718 if (mrq->sbc && mrq->sbc->error)
719 ret = mrq->sbc->error;
720 if (!ret && mrq->cmd->error)
721 ret = mrq->cmd->error;
722 if (!ret && mrq->data->error)
723 ret = mrq->data->error;
724 if (!ret && mrq->stop && mrq->stop->error)
725 ret = mrq->stop->error;
726 if (!ret && mrq->data->bytes_xfered !=
727 mrq->data->blocks * mrq->data->blksz)
728 ret = RESULT_FAIL;
730 if (ret == -EINVAL)
731 ret = RESULT_UNSUP_HOST;
733 return ret;
737 * Checks that a "short transfer" behaved as expected
739 static int mmc_test_check_broken_result(struct mmc_test_card *test,
740 struct mmc_request *mrq)
742 int ret;
744 if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
745 return -EINVAL;
747 ret = 0;
749 if (!ret && mrq->cmd->error)
750 ret = mrq->cmd->error;
751 if (!ret && mrq->data->error == 0)
752 ret = RESULT_FAIL;
753 if (!ret && mrq->data->error != -ETIMEDOUT)
754 ret = mrq->data->error;
755 if (!ret && mrq->stop && mrq->stop->error)
756 ret = mrq->stop->error;
757 if (mrq->data->blocks > 1) {
758 if (!ret && mrq->data->bytes_xfered > mrq->data->blksz)
759 ret = RESULT_FAIL;
760 } else {
761 if (!ret && mrq->data->bytes_xfered > 0)
762 ret = RESULT_FAIL;
765 if (ret == -EINVAL)
766 ret = RESULT_UNSUP_HOST;
768 return ret;
771 struct mmc_test_req {
772 struct mmc_request mrq;
773 struct mmc_command sbc;
774 struct mmc_command cmd;
775 struct mmc_command stop;
776 struct mmc_command status;
777 struct mmc_data data;
781 * Tests nonblock transfer with certain parameters
783 static void mmc_test_req_reset(struct mmc_test_req *rq)
785 memset(rq, 0, sizeof(struct mmc_test_req));
787 rq->mrq.cmd = &rq->cmd;
788 rq->mrq.data = &rq->data;
789 rq->mrq.stop = &rq->stop;
792 static struct mmc_test_req *mmc_test_req_alloc(void)
794 struct mmc_test_req *rq = kmalloc(sizeof(*rq), GFP_KERNEL);
796 if (rq)
797 mmc_test_req_reset(rq);
799 return rq;
802 static void mmc_test_wait_done(struct mmc_request *mrq)
804 complete(&mrq->completion);
807 static int mmc_test_start_areq(struct mmc_test_card *test,
808 struct mmc_request *mrq,
809 struct mmc_request *prev_mrq)
811 struct mmc_host *host = test->card->host;
812 int err = 0;
814 if (mrq) {
815 init_completion(&mrq->completion);
816 mrq->done = mmc_test_wait_done;
817 mmc_pre_req(host, mrq);
820 if (prev_mrq) {
821 wait_for_completion(&prev_mrq->completion);
822 err = mmc_test_wait_busy(test);
823 if (!err)
824 err = mmc_test_check_result(test, prev_mrq);
827 if (!err && mrq) {
828 err = mmc_start_request(host, mrq);
829 if (err)
830 mmc_retune_release(host);
833 if (prev_mrq)
834 mmc_post_req(host, prev_mrq, 0);
836 if (err && mrq)
837 mmc_post_req(host, mrq, err);
839 return err;
842 static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
843 struct scatterlist *sg, unsigned sg_len,
844 unsigned dev_addr, unsigned blocks,
845 unsigned blksz, int write, int count)
847 struct mmc_test_req *rq1, *rq2;
848 struct mmc_request *mrq, *prev_mrq;
849 int i;
850 int ret = RESULT_OK;
852 rq1 = mmc_test_req_alloc();
853 rq2 = mmc_test_req_alloc();
854 if (!rq1 || !rq2) {
855 ret = RESULT_FAIL;
856 goto err;
859 mrq = &rq1->mrq;
860 prev_mrq = NULL;
862 for (i = 0; i < count; i++) {
863 mmc_test_req_reset(container_of(mrq, struct mmc_test_req, mrq));
864 mmc_test_prepare_mrq(test, mrq, sg, sg_len, dev_addr, blocks,
865 blksz, write);
866 ret = mmc_test_start_areq(test, mrq, prev_mrq);
867 if (ret)
868 goto err;
870 if (!prev_mrq)
871 prev_mrq = &rq2->mrq;
873 swap(mrq, prev_mrq);
874 dev_addr += blocks;
877 ret = mmc_test_start_areq(test, NULL, prev_mrq);
878 err:
879 kfree(rq1);
880 kfree(rq2);
881 return ret;
885 * Tests a basic transfer with certain parameters
887 static int mmc_test_simple_transfer(struct mmc_test_card *test,
888 struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
889 unsigned blocks, unsigned blksz, int write)
891 struct mmc_request mrq = {};
892 struct mmc_command cmd = {};
893 struct mmc_command stop = {};
894 struct mmc_data data = {};
896 mrq.cmd = &cmd;
897 mrq.data = &data;
898 mrq.stop = &stop;
900 mmc_test_prepare_mrq(test, &mrq, sg, sg_len, dev_addr,
901 blocks, blksz, write);
903 mmc_wait_for_req(test->card->host, &mrq);
905 mmc_test_wait_busy(test);
907 return mmc_test_check_result(test, &mrq);
911 * Tests a transfer where the card will fail completely or partly
913 static int mmc_test_broken_transfer(struct mmc_test_card *test,
914 unsigned blocks, unsigned blksz, int write)
916 struct mmc_request mrq = {};
917 struct mmc_command cmd = {};
918 struct mmc_command stop = {};
919 struct mmc_data data = {};
921 struct scatterlist sg;
923 mrq.cmd = &cmd;
924 mrq.data = &data;
925 mrq.stop = &stop;
927 sg_init_one(&sg, test->buffer, blocks * blksz);
929 mmc_test_prepare_mrq(test, &mrq, &sg, 1, 0, blocks, blksz, write);
930 mmc_test_prepare_broken_mrq(test, &mrq, write);
932 mmc_wait_for_req(test->card->host, &mrq);
934 mmc_test_wait_busy(test);
936 return mmc_test_check_broken_result(test, &mrq);
940 * Does a complete transfer test where data is also validated
942 * Note: mmc_test_prepare() must have been done before this call
944 static int mmc_test_transfer(struct mmc_test_card *test,
945 struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
946 unsigned blocks, unsigned blksz, int write)
948 int ret, i;
949 unsigned long flags;
951 if (write) {
952 for (i = 0; i < blocks * blksz; i++)
953 test->scratch[i] = i;
954 } else {
955 memset(test->scratch, 0, BUFFER_SIZE);
957 local_irq_save(flags);
958 sg_copy_from_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
959 local_irq_restore(flags);
961 ret = mmc_test_set_blksize(test, blksz);
962 if (ret)
963 return ret;
965 ret = mmc_test_simple_transfer(test, sg, sg_len, dev_addr,
966 blocks, blksz, write);
967 if (ret)
968 return ret;
970 if (write) {
971 int sectors;
973 ret = mmc_test_set_blksize(test, 512);
974 if (ret)
975 return ret;
977 sectors = (blocks * blksz + 511) / 512;
978 if ((sectors * 512) == (blocks * blksz))
979 sectors++;
981 if ((sectors * 512) > BUFFER_SIZE)
982 return -EINVAL;
984 memset(test->buffer, 0, sectors * 512);
986 for (i = 0; i < sectors; i++) {
987 ret = mmc_test_buffer_transfer(test,
988 test->buffer + i * 512,
989 dev_addr + i, 512, 0);
990 if (ret)
991 return ret;
994 for (i = 0; i < blocks * blksz; i++) {
995 if (test->buffer[i] != (u8)i)
996 return RESULT_FAIL;
999 for (; i < sectors * 512; i++) {
1000 if (test->buffer[i] != 0xDF)
1001 return RESULT_FAIL;
1003 } else {
1004 local_irq_save(flags);
1005 sg_copy_to_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
1006 local_irq_restore(flags);
1007 for (i = 0; i < blocks * blksz; i++) {
1008 if (test->scratch[i] != (u8)i)
1009 return RESULT_FAIL;
1013 return 0;
1016 /*******************************************************************/
1017 /* Tests */
1018 /*******************************************************************/
1020 struct mmc_test_case {
1021 const char *name;
1023 int (*prepare)(struct mmc_test_card *);
1024 int (*run)(struct mmc_test_card *);
1025 int (*cleanup)(struct mmc_test_card *);
1028 static int mmc_test_basic_write(struct mmc_test_card *test)
1030 int ret;
1031 struct scatterlist sg;
1033 ret = mmc_test_set_blksize(test, 512);
1034 if (ret)
1035 return ret;
1037 sg_init_one(&sg, test->buffer, 512);
1039 return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 1);
1042 static int mmc_test_basic_read(struct mmc_test_card *test)
1044 int ret;
1045 struct scatterlist sg;
1047 ret = mmc_test_set_blksize(test, 512);
1048 if (ret)
1049 return ret;
1051 sg_init_one(&sg, test->buffer, 512);
1053 return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 0);
1056 static int mmc_test_verify_write(struct mmc_test_card *test)
1058 struct scatterlist sg;
1060 sg_init_one(&sg, test->buffer, 512);
1062 return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1065 static int mmc_test_verify_read(struct mmc_test_card *test)
1067 struct scatterlist sg;
1069 sg_init_one(&sg, test->buffer, 512);
1071 return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1074 static int mmc_test_multi_write(struct mmc_test_card *test)
1076 unsigned int size;
1077 struct scatterlist sg;
1079 if (test->card->host->max_blk_count == 1)
1080 return RESULT_UNSUP_HOST;
1082 size = PAGE_SIZE * 2;
1083 size = min(size, test->card->host->max_req_size);
1084 size = min(size, test->card->host->max_seg_size);
1085 size = min(size, test->card->host->max_blk_count * 512);
1087 if (size < 1024)
1088 return RESULT_UNSUP_HOST;
1090 sg_init_one(&sg, test->buffer, size);
1092 return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
1095 static int mmc_test_multi_read(struct mmc_test_card *test)
1097 unsigned int size;
1098 struct scatterlist sg;
1100 if (test->card->host->max_blk_count == 1)
1101 return RESULT_UNSUP_HOST;
1103 size = PAGE_SIZE * 2;
1104 size = min(size, test->card->host->max_req_size);
1105 size = min(size, test->card->host->max_seg_size);
1106 size = min(size, test->card->host->max_blk_count * 512);
1108 if (size < 1024)
1109 return RESULT_UNSUP_HOST;
1111 sg_init_one(&sg, test->buffer, size);
1113 return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
1116 static int mmc_test_pow2_write(struct mmc_test_card *test)
1118 int ret, i;
1119 struct scatterlist sg;
1121 if (!test->card->csd.write_partial)
1122 return RESULT_UNSUP_CARD;
1124 for (i = 1; i < 512; i <<= 1) {
1125 sg_init_one(&sg, test->buffer, i);
1126 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
1127 if (ret)
1128 return ret;
1131 return 0;
1134 static int mmc_test_pow2_read(struct mmc_test_card *test)
1136 int ret, i;
1137 struct scatterlist sg;
1139 if (!test->card->csd.read_partial)
1140 return RESULT_UNSUP_CARD;
1142 for (i = 1; i < 512; i <<= 1) {
1143 sg_init_one(&sg, test->buffer, i);
1144 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
1145 if (ret)
1146 return ret;
1149 return 0;
1152 static int mmc_test_weird_write(struct mmc_test_card *test)
1154 int ret, i;
1155 struct scatterlist sg;
1157 if (!test->card->csd.write_partial)
1158 return RESULT_UNSUP_CARD;
1160 for (i = 3; i < 512; i += 7) {
1161 sg_init_one(&sg, test->buffer, i);
1162 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
1163 if (ret)
1164 return ret;
1167 return 0;
1170 static int mmc_test_weird_read(struct mmc_test_card *test)
1172 int ret, i;
1173 struct scatterlist sg;
1175 if (!test->card->csd.read_partial)
1176 return RESULT_UNSUP_CARD;
1178 for (i = 3; i < 512; i += 7) {
1179 sg_init_one(&sg, test->buffer, i);
1180 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
1181 if (ret)
1182 return ret;
1185 return 0;
1188 static int mmc_test_align_write(struct mmc_test_card *test)
1190 int ret, i;
1191 struct scatterlist sg;
1193 for (i = 1; i < TEST_ALIGN_END; i++) {
1194 sg_init_one(&sg, test->buffer + i, 512);
1195 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1196 if (ret)
1197 return ret;
1200 return 0;
1203 static int mmc_test_align_read(struct mmc_test_card *test)
1205 int ret, i;
1206 struct scatterlist sg;
1208 for (i = 1; i < TEST_ALIGN_END; i++) {
1209 sg_init_one(&sg, test->buffer + i, 512);
1210 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1211 if (ret)
1212 return ret;
1215 return 0;
1218 static int mmc_test_align_multi_write(struct mmc_test_card *test)
1220 int ret, i;
1221 unsigned int size;
1222 struct scatterlist sg;
1224 if (test->card->host->max_blk_count == 1)
1225 return RESULT_UNSUP_HOST;
1227 size = PAGE_SIZE * 2;
1228 size = min(size, test->card->host->max_req_size);
1229 size = min(size, test->card->host->max_seg_size);
1230 size = min(size, test->card->host->max_blk_count * 512);
1232 if (size < 1024)
1233 return RESULT_UNSUP_HOST;
1235 for (i = 1; i < TEST_ALIGN_END; i++) {
1236 sg_init_one(&sg, test->buffer + i, size);
1237 ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
1238 if (ret)
1239 return ret;
1242 return 0;
1245 static int mmc_test_align_multi_read(struct mmc_test_card *test)
1247 int ret, i;
1248 unsigned int size;
1249 struct scatterlist sg;
1251 if (test->card->host->max_blk_count == 1)
1252 return RESULT_UNSUP_HOST;
1254 size = PAGE_SIZE * 2;
1255 size = min(size, test->card->host->max_req_size);
1256 size = min(size, test->card->host->max_seg_size);
1257 size = min(size, test->card->host->max_blk_count * 512);
1259 if (size < 1024)
1260 return RESULT_UNSUP_HOST;
1262 for (i = 1; i < TEST_ALIGN_END; i++) {
1263 sg_init_one(&sg, test->buffer + i, size);
1264 ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
1265 if (ret)
1266 return ret;
1269 return 0;
1272 static int mmc_test_xfersize_write(struct mmc_test_card *test)
1274 int ret;
1276 ret = mmc_test_set_blksize(test, 512);
1277 if (ret)
1278 return ret;
1280 return mmc_test_broken_transfer(test, 1, 512, 1);
1283 static int mmc_test_xfersize_read(struct mmc_test_card *test)
1285 int ret;
1287 ret = mmc_test_set_blksize(test, 512);
1288 if (ret)
1289 return ret;
1291 return mmc_test_broken_transfer(test, 1, 512, 0);
1294 static int mmc_test_multi_xfersize_write(struct mmc_test_card *test)
1296 int ret;
1298 if (test->card->host->max_blk_count == 1)
1299 return RESULT_UNSUP_HOST;
1301 ret = mmc_test_set_blksize(test, 512);
1302 if (ret)
1303 return ret;
1305 return mmc_test_broken_transfer(test, 2, 512, 1);
1308 static int mmc_test_multi_xfersize_read(struct mmc_test_card *test)
1310 int ret;
1312 if (test->card->host->max_blk_count == 1)
1313 return RESULT_UNSUP_HOST;
1315 ret = mmc_test_set_blksize(test, 512);
1316 if (ret)
1317 return ret;
1319 return mmc_test_broken_transfer(test, 2, 512, 0);
1322 #ifdef CONFIG_HIGHMEM
1324 static int mmc_test_write_high(struct mmc_test_card *test)
1326 struct scatterlist sg;
1328 sg_init_table(&sg, 1);
1329 sg_set_page(&sg, test->highmem, 512, 0);
1331 return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1334 static int mmc_test_read_high(struct mmc_test_card *test)
1336 struct scatterlist sg;
1338 sg_init_table(&sg, 1);
1339 sg_set_page(&sg, test->highmem, 512, 0);
1341 return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1344 static int mmc_test_multi_write_high(struct mmc_test_card *test)
1346 unsigned int size;
1347 struct scatterlist sg;
1349 if (test->card->host->max_blk_count == 1)
1350 return RESULT_UNSUP_HOST;
1352 size = PAGE_SIZE * 2;
1353 size = min(size, test->card->host->max_req_size);
1354 size = min(size, test->card->host->max_seg_size);
1355 size = min(size, test->card->host->max_blk_count * 512);
1357 if (size < 1024)
1358 return RESULT_UNSUP_HOST;
1360 sg_init_table(&sg, 1);
1361 sg_set_page(&sg, test->highmem, size, 0);
1363 return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
1366 static int mmc_test_multi_read_high(struct mmc_test_card *test)
1368 unsigned int size;
1369 struct scatterlist sg;
1371 if (test->card->host->max_blk_count == 1)
1372 return RESULT_UNSUP_HOST;
1374 size = PAGE_SIZE * 2;
1375 size = min(size, test->card->host->max_req_size);
1376 size = min(size, test->card->host->max_seg_size);
1377 size = min(size, test->card->host->max_blk_count * 512);
1379 if (size < 1024)
1380 return RESULT_UNSUP_HOST;
1382 sg_init_table(&sg, 1);
1383 sg_set_page(&sg, test->highmem, size, 0);
1385 return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
1388 #else
1390 static int mmc_test_no_highmem(struct mmc_test_card *test)
1392 pr_info("%s: Highmem not configured - test skipped\n",
1393 mmc_hostname(test->card->host));
1394 return 0;
1397 #endif /* CONFIG_HIGHMEM */
1400 * Map sz bytes so that it can be transferred.
1402 static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
1403 int max_scatter, int min_sg_len)
1405 struct mmc_test_area *t = &test->area;
1406 int err;
1408 t->blocks = sz >> 9;
1410 if (max_scatter) {
1411 err = mmc_test_map_sg_max_scatter(t->mem, sz, t->sg,
1412 t->max_segs, t->max_seg_sz,
1413 &t->sg_len);
1414 } else {
1415 err = mmc_test_map_sg(t->mem, sz, t->sg, 1, t->max_segs,
1416 t->max_seg_sz, &t->sg_len, min_sg_len);
1418 if (err)
1419 pr_info("%s: Failed to map sg list\n",
1420 mmc_hostname(test->card->host));
1421 return err;
1425 * Transfer bytes mapped by mmc_test_area_map().
1427 static int mmc_test_area_transfer(struct mmc_test_card *test,
1428 unsigned int dev_addr, int write)
1430 struct mmc_test_area *t = &test->area;
1432 return mmc_test_simple_transfer(test, t->sg, t->sg_len, dev_addr,
1433 t->blocks, 512, write);
1437 * Map and transfer bytes for multiple transfers.
1439 static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz,
1440 unsigned int dev_addr, int write,
1441 int max_scatter, int timed, int count,
1442 bool nonblock, int min_sg_len)
1444 struct timespec64 ts1, ts2;
1445 int ret = 0;
1446 int i;
1447 struct mmc_test_area *t = &test->area;
1450 * In the case of a maximally scattered transfer, the maximum transfer
1451 * size is further limited by using PAGE_SIZE segments.
1453 if (max_scatter) {
1454 struct mmc_test_area *t = &test->area;
1455 unsigned long max_tfr;
1457 if (t->max_seg_sz >= PAGE_SIZE)
1458 max_tfr = t->max_segs * PAGE_SIZE;
1459 else
1460 max_tfr = t->max_segs * t->max_seg_sz;
1461 if (sz > max_tfr)
1462 sz = max_tfr;
1465 ret = mmc_test_area_map(test, sz, max_scatter, min_sg_len);
1466 if (ret)
1467 return ret;
1469 if (timed)
1470 ktime_get_ts64(&ts1);
1471 if (nonblock)
1472 ret = mmc_test_nonblock_transfer(test, t->sg, t->sg_len,
1473 dev_addr, t->blocks, 512, write, count);
1474 else
1475 for (i = 0; i < count && ret == 0; i++) {
1476 ret = mmc_test_area_transfer(test, dev_addr, write);
1477 dev_addr += sz >> 9;
1480 if (ret)
1481 return ret;
1483 if (timed)
1484 ktime_get_ts64(&ts2);
1486 if (timed)
1487 mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2);
1489 return 0;
1492 static int mmc_test_area_io(struct mmc_test_card *test, unsigned long sz,
1493 unsigned int dev_addr, int write, int max_scatter,
1494 int timed)
1496 return mmc_test_area_io_seq(test, sz, dev_addr, write, max_scatter,
1497 timed, 1, false, 0);
1501 * Write the test area entirely.
1503 static int mmc_test_area_fill(struct mmc_test_card *test)
1505 struct mmc_test_area *t = &test->area;
1507 return mmc_test_area_io(test, t->max_tfr, t->dev_addr, 1, 0, 0);
1511 * Erase the test area entirely.
1513 static int mmc_test_area_erase(struct mmc_test_card *test)
1515 struct mmc_test_area *t = &test->area;
1517 if (!mmc_can_erase(test->card))
1518 return 0;
1520 return mmc_erase(test->card, t->dev_addr, t->max_sz >> 9,
1521 MMC_ERASE_ARG);
1525 * Cleanup struct mmc_test_area.
1527 static int mmc_test_area_cleanup(struct mmc_test_card *test)
1529 struct mmc_test_area *t = &test->area;
1531 kfree(t->sg);
1532 mmc_test_free_mem(t->mem);
1534 return 0;
1538 * Initialize an area for testing large transfers. The test area is set to the
1539 * middle of the card because cards may have different characteristics at the
1540 * front (for FAT file system optimization). Optionally, the area is erased
1541 * (if the card supports it) which may improve write performance. Optionally,
1542 * the area is filled with data for subsequent read tests.
1544 static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
1546 struct mmc_test_area *t = &test->area;
1547 unsigned long min_sz = 64 * 1024, sz;
1548 int ret;
1550 ret = mmc_test_set_blksize(test, 512);
1551 if (ret)
1552 return ret;
1554 /* Make the test area size about 4MiB */
1555 sz = (unsigned long)test->card->pref_erase << 9;
1556 t->max_sz = sz;
1557 while (t->max_sz < 4 * 1024 * 1024)
1558 t->max_sz += sz;
1559 while (t->max_sz > TEST_AREA_MAX_SIZE && t->max_sz > sz)
1560 t->max_sz -= sz;
1562 t->max_segs = test->card->host->max_segs;
1563 t->max_seg_sz = test->card->host->max_seg_size;
1564 t->max_seg_sz -= t->max_seg_sz % 512;
1566 t->max_tfr = t->max_sz;
1567 if (t->max_tfr >> 9 > test->card->host->max_blk_count)
1568 t->max_tfr = test->card->host->max_blk_count << 9;
1569 if (t->max_tfr > test->card->host->max_req_size)
1570 t->max_tfr = test->card->host->max_req_size;
1571 if (t->max_tfr / t->max_seg_sz > t->max_segs)
1572 t->max_tfr = t->max_segs * t->max_seg_sz;
1575 * Try to allocate enough memory for a max. sized transfer. Less is OK
1576 * because the same memory can be mapped into the scatterlist more than
1577 * once. Also, take into account the limits imposed on scatterlist
1578 * segments by the host driver.
1580 t->mem = mmc_test_alloc_mem(min_sz, t->max_tfr, t->max_segs,
1581 t->max_seg_sz);
1582 if (!t->mem)
1583 return -ENOMEM;
1585 t->sg = kmalloc_array(t->max_segs, sizeof(*t->sg), GFP_KERNEL);
1586 if (!t->sg) {
1587 ret = -ENOMEM;
1588 goto out_free;
1591 t->dev_addr = mmc_test_capacity(test->card) / 2;
1592 t->dev_addr -= t->dev_addr % (t->max_sz >> 9);
1594 if (erase) {
1595 ret = mmc_test_area_erase(test);
1596 if (ret)
1597 goto out_free;
1600 if (fill) {
1601 ret = mmc_test_area_fill(test);
1602 if (ret)
1603 goto out_free;
1606 return 0;
1608 out_free:
1609 mmc_test_area_cleanup(test);
1610 return ret;
1614 * Prepare for large transfers. Do not erase the test area.
1616 static int mmc_test_area_prepare(struct mmc_test_card *test)
1618 return mmc_test_area_init(test, 0, 0);
1622 * Prepare for large transfers. Do erase the test area.
1624 static int mmc_test_area_prepare_erase(struct mmc_test_card *test)
1626 return mmc_test_area_init(test, 1, 0);
1630 * Prepare for large transfers. Erase and fill the test area.
1632 static int mmc_test_area_prepare_fill(struct mmc_test_card *test)
1634 return mmc_test_area_init(test, 1, 1);
1638 * Test best-case performance. Best-case performance is expected from
1639 * a single large transfer.
1641 * An additional option (max_scatter) allows the measurement of the same
1642 * transfer but with no contiguous pages in the scatter list. This tests
1643 * the efficiency of DMA to handle scattered pages.
1645 static int mmc_test_best_performance(struct mmc_test_card *test, int write,
1646 int max_scatter)
1648 struct mmc_test_area *t = &test->area;
1650 return mmc_test_area_io(test, t->max_tfr, t->dev_addr, write,
1651 max_scatter, 1);
1655 * Best-case read performance.
1657 static int mmc_test_best_read_performance(struct mmc_test_card *test)
1659 return mmc_test_best_performance(test, 0, 0);
1663 * Best-case write performance.
1665 static int mmc_test_best_write_performance(struct mmc_test_card *test)
1667 return mmc_test_best_performance(test, 1, 0);
1671 * Best-case read performance into scattered pages.
1673 static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card *test)
1675 return mmc_test_best_performance(test, 0, 1);
1679 * Best-case write performance from scattered pages.
1681 static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card *test)
1683 return mmc_test_best_performance(test, 1, 1);
1687 * Single read performance by transfer size.
1689 static int mmc_test_profile_read_perf(struct mmc_test_card *test)
1691 struct mmc_test_area *t = &test->area;
1692 unsigned long sz;
1693 unsigned int dev_addr;
1694 int ret;
1696 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1697 dev_addr = t->dev_addr + (sz >> 9);
1698 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1699 if (ret)
1700 return ret;
1702 sz = t->max_tfr;
1703 dev_addr = t->dev_addr;
1704 return mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1708 * Single write performance by transfer size.
1710 static int mmc_test_profile_write_perf(struct mmc_test_card *test)
1712 struct mmc_test_area *t = &test->area;
1713 unsigned long sz;
1714 unsigned int dev_addr;
1715 int ret;
1717 ret = mmc_test_area_erase(test);
1718 if (ret)
1719 return ret;
1720 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1721 dev_addr = t->dev_addr + (sz >> 9);
1722 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1723 if (ret)
1724 return ret;
1726 ret = mmc_test_area_erase(test);
1727 if (ret)
1728 return ret;
1729 sz = t->max_tfr;
1730 dev_addr = t->dev_addr;
1731 return mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1735 * Single trim performance by transfer size.
1737 static int mmc_test_profile_trim_perf(struct mmc_test_card *test)
1739 struct mmc_test_area *t = &test->area;
1740 unsigned long sz;
1741 unsigned int dev_addr;
1742 struct timespec64 ts1, ts2;
1743 int ret;
1745 if (!mmc_can_trim(test->card))
1746 return RESULT_UNSUP_CARD;
1748 if (!mmc_can_erase(test->card))
1749 return RESULT_UNSUP_HOST;
1751 for (sz = 512; sz < t->max_sz; sz <<= 1) {
1752 dev_addr = t->dev_addr + (sz >> 9);
1753 ktime_get_ts64(&ts1);
1754 ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
1755 if (ret)
1756 return ret;
1757 ktime_get_ts64(&ts2);
1758 mmc_test_print_rate(test, sz, &ts1, &ts2);
1760 dev_addr = t->dev_addr;
1761 ktime_get_ts64(&ts1);
1762 ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
1763 if (ret)
1764 return ret;
1765 ktime_get_ts64(&ts2);
1766 mmc_test_print_rate(test, sz, &ts1, &ts2);
1767 return 0;
1770 static int mmc_test_seq_read_perf(struct mmc_test_card *test, unsigned long sz)
1772 struct mmc_test_area *t = &test->area;
1773 unsigned int dev_addr, i, cnt;
1774 struct timespec64 ts1, ts2;
1775 int ret;
1777 cnt = t->max_sz / sz;
1778 dev_addr = t->dev_addr;
1779 ktime_get_ts64(&ts1);
1780 for (i = 0; i < cnt; i++) {
1781 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0);
1782 if (ret)
1783 return ret;
1784 dev_addr += (sz >> 9);
1786 ktime_get_ts64(&ts2);
1787 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1788 return 0;
1792 * Consecutive read performance by transfer size.
1794 static int mmc_test_profile_seq_read_perf(struct mmc_test_card *test)
1796 struct mmc_test_area *t = &test->area;
1797 unsigned long sz;
1798 int ret;
1800 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1801 ret = mmc_test_seq_read_perf(test, sz);
1802 if (ret)
1803 return ret;
1805 sz = t->max_tfr;
1806 return mmc_test_seq_read_perf(test, sz);
1809 static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz)
1811 struct mmc_test_area *t = &test->area;
1812 unsigned int dev_addr, i, cnt;
1813 struct timespec64 ts1, ts2;
1814 int ret;
1816 ret = mmc_test_area_erase(test);
1817 if (ret)
1818 return ret;
1819 cnt = t->max_sz / sz;
1820 dev_addr = t->dev_addr;
1821 ktime_get_ts64(&ts1);
1822 for (i = 0; i < cnt; i++) {
1823 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0);
1824 if (ret)
1825 return ret;
1826 dev_addr += (sz >> 9);
1828 ktime_get_ts64(&ts2);
1829 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1830 return 0;
1834 * Consecutive write performance by transfer size.
1836 static int mmc_test_profile_seq_write_perf(struct mmc_test_card *test)
1838 struct mmc_test_area *t = &test->area;
1839 unsigned long sz;
1840 int ret;
1842 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1843 ret = mmc_test_seq_write_perf(test, sz);
1844 if (ret)
1845 return ret;
1847 sz = t->max_tfr;
1848 return mmc_test_seq_write_perf(test, sz);
1852 * Consecutive trim performance by transfer size.
1854 static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
1856 struct mmc_test_area *t = &test->area;
1857 unsigned long sz;
1858 unsigned int dev_addr, i, cnt;
1859 struct timespec64 ts1, ts2;
1860 int ret;
1862 if (!mmc_can_trim(test->card))
1863 return RESULT_UNSUP_CARD;
1865 if (!mmc_can_erase(test->card))
1866 return RESULT_UNSUP_HOST;
1868 for (sz = 512; sz <= t->max_sz; sz <<= 1) {
1869 ret = mmc_test_area_erase(test);
1870 if (ret)
1871 return ret;
1872 ret = mmc_test_area_fill(test);
1873 if (ret)
1874 return ret;
1875 cnt = t->max_sz / sz;
1876 dev_addr = t->dev_addr;
1877 ktime_get_ts64(&ts1);
1878 for (i = 0; i < cnt; i++) {
1879 ret = mmc_erase(test->card, dev_addr, sz >> 9,
1880 MMC_TRIM_ARG);
1881 if (ret)
1882 return ret;
1883 dev_addr += (sz >> 9);
1885 ktime_get_ts64(&ts2);
1886 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1888 return 0;
1891 static unsigned int rnd_next = 1;
1893 static unsigned int mmc_test_rnd_num(unsigned int rnd_cnt)
1895 uint64_t r;
1897 rnd_next = rnd_next * 1103515245 + 12345;
1898 r = (rnd_next >> 16) & 0x7fff;
1899 return (r * rnd_cnt) >> 15;
1902 static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print,
1903 unsigned long sz)
1905 unsigned int dev_addr, cnt, rnd_addr, range1, range2, last_ea = 0, ea;
1906 unsigned int ssz;
1907 struct timespec64 ts1, ts2, ts;
1908 int ret;
1910 ssz = sz >> 9;
1912 rnd_addr = mmc_test_capacity(test->card) / 4;
1913 range1 = rnd_addr / test->card->pref_erase;
1914 range2 = range1 / ssz;
1916 ktime_get_ts64(&ts1);
1917 for (cnt = 0; cnt < UINT_MAX; cnt++) {
1918 ktime_get_ts64(&ts2);
1919 ts = timespec64_sub(ts2, ts1);
1920 if (ts.tv_sec >= 10)
1921 break;
1922 ea = mmc_test_rnd_num(range1);
1923 if (ea == last_ea)
1924 ea -= 1;
1925 last_ea = ea;
1926 dev_addr = rnd_addr + test->card->pref_erase * ea +
1927 ssz * mmc_test_rnd_num(range2);
1928 ret = mmc_test_area_io(test, sz, dev_addr, write, 0, 0);
1929 if (ret)
1930 return ret;
1932 if (print)
1933 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1934 return 0;
1937 static int mmc_test_random_perf(struct mmc_test_card *test, int write)
1939 struct mmc_test_area *t = &test->area;
1940 unsigned int next;
1941 unsigned long sz;
1942 int ret;
1944 for (sz = 512; sz < t->max_tfr; sz <<= 1) {
1946 * When writing, try to get more consistent results by running
1947 * the test twice with exactly the same I/O but outputting the
1948 * results only for the 2nd run.
1950 if (write) {
1951 next = rnd_next;
1952 ret = mmc_test_rnd_perf(test, write, 0, sz);
1953 if (ret)
1954 return ret;
1955 rnd_next = next;
1957 ret = mmc_test_rnd_perf(test, write, 1, sz);
1958 if (ret)
1959 return ret;
1961 sz = t->max_tfr;
1962 if (write) {
1963 next = rnd_next;
1964 ret = mmc_test_rnd_perf(test, write, 0, sz);
1965 if (ret)
1966 return ret;
1967 rnd_next = next;
1969 return mmc_test_rnd_perf(test, write, 1, sz);
1973 * Random read performance by transfer size.
1975 static int mmc_test_random_read_perf(struct mmc_test_card *test)
1977 return mmc_test_random_perf(test, 0);
1981 * Random write performance by transfer size.
1983 static int mmc_test_random_write_perf(struct mmc_test_card *test)
1985 return mmc_test_random_perf(test, 1);
1988 static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
1989 unsigned int tot_sz, int max_scatter)
1991 struct mmc_test_area *t = &test->area;
1992 unsigned int dev_addr, i, cnt, sz, ssz;
1993 struct timespec64 ts1, ts2;
1994 int ret;
1996 sz = t->max_tfr;
1999 * In the case of a maximally scattered transfer, the maximum transfer
2000 * size is further limited by using PAGE_SIZE segments.
2002 if (max_scatter) {
2003 unsigned long max_tfr;
2005 if (t->max_seg_sz >= PAGE_SIZE)
2006 max_tfr = t->max_segs * PAGE_SIZE;
2007 else
2008 max_tfr = t->max_segs * t->max_seg_sz;
2009 if (sz > max_tfr)
2010 sz = max_tfr;
2013 ssz = sz >> 9;
2014 dev_addr = mmc_test_capacity(test->card) / 4;
2015 if (tot_sz > dev_addr << 9)
2016 tot_sz = dev_addr << 9;
2017 cnt = tot_sz / sz;
2018 dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
2020 ktime_get_ts64(&ts1);
2021 for (i = 0; i < cnt; i++) {
2022 ret = mmc_test_area_io(test, sz, dev_addr, write,
2023 max_scatter, 0);
2024 if (ret)
2025 return ret;
2026 dev_addr += ssz;
2028 ktime_get_ts64(&ts2);
2030 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
2032 return 0;
2035 static int mmc_test_large_seq_perf(struct mmc_test_card *test, int write)
2037 int ret, i;
2039 for (i = 0; i < 10; i++) {
2040 ret = mmc_test_seq_perf(test, write, 10 * 1024 * 1024, 1);
2041 if (ret)
2042 return ret;
2044 for (i = 0; i < 5; i++) {
2045 ret = mmc_test_seq_perf(test, write, 100 * 1024 * 1024, 1);
2046 if (ret)
2047 return ret;
2049 for (i = 0; i < 3; i++) {
2050 ret = mmc_test_seq_perf(test, write, 1000 * 1024 * 1024, 1);
2051 if (ret)
2052 return ret;
2055 return ret;
2059 * Large sequential read performance.
2061 static int mmc_test_large_seq_read_perf(struct mmc_test_card *test)
2063 return mmc_test_large_seq_perf(test, 0);
2067 * Large sequential write performance.
2069 static int mmc_test_large_seq_write_perf(struct mmc_test_card *test)
2071 return mmc_test_large_seq_perf(test, 1);
2074 static int mmc_test_rw_multiple(struct mmc_test_card *test,
2075 struct mmc_test_multiple_rw *tdata,
2076 unsigned int reqsize, unsigned int size,
2077 int min_sg_len)
2079 unsigned int dev_addr;
2080 struct mmc_test_area *t = &test->area;
2081 int ret = 0;
2083 /* Set up test area */
2084 if (size > mmc_test_capacity(test->card) / 2 * 512)
2085 size = mmc_test_capacity(test->card) / 2 * 512;
2086 if (reqsize > t->max_tfr)
2087 reqsize = t->max_tfr;
2088 dev_addr = mmc_test_capacity(test->card) / 4;
2089 if ((dev_addr & 0xffff0000))
2090 dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
2091 else
2092 dev_addr &= 0xfffff800; /* Round to 1MiB boundary */
2093 if (!dev_addr)
2094 goto err;
2096 if (reqsize > size)
2097 return 0;
2099 /* prepare test area */
2100 if (mmc_can_erase(test->card) &&
2101 tdata->prepare & MMC_TEST_PREP_ERASE) {
2102 ret = mmc_erase(test->card, dev_addr,
2103 size / 512, MMC_SECURE_ERASE_ARG);
2104 if (ret)
2105 ret = mmc_erase(test->card, dev_addr,
2106 size / 512, MMC_ERASE_ARG);
2107 if (ret)
2108 goto err;
2111 /* Run test */
2112 ret = mmc_test_area_io_seq(test, reqsize, dev_addr,
2113 tdata->do_write, 0, 1, size / reqsize,
2114 tdata->do_nonblock_req, min_sg_len);
2115 if (ret)
2116 goto err;
2118 return ret;
2119 err:
2120 pr_info("[%s] error\n", __func__);
2121 return ret;
2124 static int mmc_test_rw_multiple_size(struct mmc_test_card *test,
2125 struct mmc_test_multiple_rw *rw)
2127 int ret = 0;
2128 int i;
2129 void *pre_req = test->card->host->ops->pre_req;
2130 void *post_req = test->card->host->ops->post_req;
2132 if (rw->do_nonblock_req &&
2133 ((!pre_req && post_req) || (pre_req && !post_req))) {
2134 pr_info("error: only one of pre/post is defined\n");
2135 return -EINVAL;
2138 for (i = 0 ; i < rw->len && ret == 0; i++) {
2139 ret = mmc_test_rw_multiple(test, rw, rw->bs[i], rw->size, 0);
2140 if (ret)
2141 break;
2143 return ret;
2146 static int mmc_test_rw_multiple_sg_len(struct mmc_test_card *test,
2147 struct mmc_test_multiple_rw *rw)
2149 int ret = 0;
2150 int i;
2152 for (i = 0 ; i < rw->len && ret == 0; i++) {
2153 ret = mmc_test_rw_multiple(test, rw, 512 * 1024, rw->size,
2154 rw->sg_len[i]);
2155 if (ret)
2156 break;
2158 return ret;
2162 * Multiple blocking write 4k to 4 MB chunks
2164 static int mmc_test_profile_mult_write_blocking_perf(struct mmc_test_card *test)
2166 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2167 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2168 struct mmc_test_multiple_rw test_data = {
2169 .bs = bs,
2170 .size = TEST_AREA_MAX_SIZE,
2171 .len = ARRAY_SIZE(bs),
2172 .do_write = true,
2173 .do_nonblock_req = false,
2174 .prepare = MMC_TEST_PREP_ERASE,
2177 return mmc_test_rw_multiple_size(test, &test_data);
2181 * Multiple non-blocking write 4k to 4 MB chunks
2183 static int mmc_test_profile_mult_write_nonblock_perf(struct mmc_test_card *test)
2185 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2186 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2187 struct mmc_test_multiple_rw test_data = {
2188 .bs = bs,
2189 .size = TEST_AREA_MAX_SIZE,
2190 .len = ARRAY_SIZE(bs),
2191 .do_write = true,
2192 .do_nonblock_req = true,
2193 .prepare = MMC_TEST_PREP_ERASE,
2196 return mmc_test_rw_multiple_size(test, &test_data);
2200 * Multiple blocking read 4k to 4 MB chunks
2202 static int mmc_test_profile_mult_read_blocking_perf(struct mmc_test_card *test)
2204 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2205 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2206 struct mmc_test_multiple_rw test_data = {
2207 .bs = bs,
2208 .size = TEST_AREA_MAX_SIZE,
2209 .len = ARRAY_SIZE(bs),
2210 .do_write = false,
2211 .do_nonblock_req = false,
2212 .prepare = MMC_TEST_PREP_NONE,
2215 return mmc_test_rw_multiple_size(test, &test_data);
2219 * Multiple non-blocking read 4k to 4 MB chunks
2221 static int mmc_test_profile_mult_read_nonblock_perf(struct mmc_test_card *test)
2223 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2224 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2225 struct mmc_test_multiple_rw test_data = {
2226 .bs = bs,
2227 .size = TEST_AREA_MAX_SIZE,
2228 .len = ARRAY_SIZE(bs),
2229 .do_write = false,
2230 .do_nonblock_req = true,
2231 .prepare = MMC_TEST_PREP_NONE,
2234 return mmc_test_rw_multiple_size(test, &test_data);
2238 * Multiple blocking write 1 to 512 sg elements
2240 static int mmc_test_profile_sglen_wr_blocking_perf(struct mmc_test_card *test)
2242 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2243 1 << 7, 1 << 8, 1 << 9};
2244 struct mmc_test_multiple_rw test_data = {
2245 .sg_len = sg_len,
2246 .size = TEST_AREA_MAX_SIZE,
2247 .len = ARRAY_SIZE(sg_len),
2248 .do_write = true,
2249 .do_nonblock_req = false,
2250 .prepare = MMC_TEST_PREP_ERASE,
2253 return mmc_test_rw_multiple_sg_len(test, &test_data);
2257 * Multiple non-blocking write 1 to 512 sg elements
2259 static int mmc_test_profile_sglen_wr_nonblock_perf(struct mmc_test_card *test)
2261 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2262 1 << 7, 1 << 8, 1 << 9};
2263 struct mmc_test_multiple_rw test_data = {
2264 .sg_len = sg_len,
2265 .size = TEST_AREA_MAX_SIZE,
2266 .len = ARRAY_SIZE(sg_len),
2267 .do_write = true,
2268 .do_nonblock_req = true,
2269 .prepare = MMC_TEST_PREP_ERASE,
2272 return mmc_test_rw_multiple_sg_len(test, &test_data);
2276 * Multiple blocking read 1 to 512 sg elements
2278 static int mmc_test_profile_sglen_r_blocking_perf(struct mmc_test_card *test)
2280 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2281 1 << 7, 1 << 8, 1 << 9};
2282 struct mmc_test_multiple_rw test_data = {
2283 .sg_len = sg_len,
2284 .size = TEST_AREA_MAX_SIZE,
2285 .len = ARRAY_SIZE(sg_len),
2286 .do_write = false,
2287 .do_nonblock_req = false,
2288 .prepare = MMC_TEST_PREP_NONE,
2291 return mmc_test_rw_multiple_sg_len(test, &test_data);
2295 * Multiple non-blocking read 1 to 512 sg elements
2297 static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card *test)
2299 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2300 1 << 7, 1 << 8, 1 << 9};
2301 struct mmc_test_multiple_rw test_data = {
2302 .sg_len = sg_len,
2303 .size = TEST_AREA_MAX_SIZE,
2304 .len = ARRAY_SIZE(sg_len),
2305 .do_write = false,
2306 .do_nonblock_req = true,
2307 .prepare = MMC_TEST_PREP_NONE,
2310 return mmc_test_rw_multiple_sg_len(test, &test_data);
2314 * eMMC hardware reset.
2316 static int mmc_test_reset(struct mmc_test_card *test)
2318 struct mmc_card *card = test->card;
2319 struct mmc_host *host = card->host;
2320 int err;
2322 err = mmc_hw_reset(host);
2323 if (!err) {
2325 * Reset will re-enable the card's command queue, but tests
2326 * expect it to be disabled.
2328 if (card->ext_csd.cmdq_en)
2329 mmc_cmdq_disable(card);
2330 return RESULT_OK;
2331 } else if (err == -EOPNOTSUPP) {
2332 return RESULT_UNSUP_HOST;
2335 return RESULT_FAIL;
2338 static int mmc_test_send_status(struct mmc_test_card *test,
2339 struct mmc_command *cmd)
2341 memset(cmd, 0, sizeof(*cmd));
2343 cmd->opcode = MMC_SEND_STATUS;
2344 if (!mmc_host_is_spi(test->card->host))
2345 cmd->arg = test->card->rca << 16;
2346 cmd->flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
2348 return mmc_wait_for_cmd(test->card->host, cmd, 0);
2351 static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
2352 unsigned int dev_addr, int use_sbc,
2353 int repeat_cmd, int write, int use_areq)
2355 struct mmc_test_req *rq = mmc_test_req_alloc();
2356 struct mmc_host *host = test->card->host;
2357 struct mmc_test_area *t = &test->area;
2358 struct mmc_request *mrq;
2359 unsigned long timeout;
2360 bool expired = false;
2361 int ret = 0, cmd_ret;
2362 u32 status = 0;
2363 int count = 0;
2365 if (!rq)
2366 return -ENOMEM;
2368 mrq = &rq->mrq;
2369 if (use_sbc)
2370 mrq->sbc = &rq->sbc;
2371 mrq->cap_cmd_during_tfr = true;
2373 mmc_test_prepare_mrq(test, mrq, t->sg, t->sg_len, dev_addr, t->blocks,
2374 512, write);
2376 if (use_sbc && t->blocks > 1 && !mrq->sbc) {
2377 ret = mmc_host_cmd23(host) ?
2378 RESULT_UNSUP_CARD :
2379 RESULT_UNSUP_HOST;
2380 goto out_free;
2383 /* Start ongoing data request */
2384 if (use_areq) {
2385 ret = mmc_test_start_areq(test, mrq, NULL);
2386 if (ret)
2387 goto out_free;
2388 } else {
2389 mmc_wait_for_req(host, mrq);
2392 timeout = jiffies + msecs_to_jiffies(3000);
2393 do {
2394 count += 1;
2396 /* Send status command while data transfer in progress */
2397 cmd_ret = mmc_test_send_status(test, &rq->status);
2398 if (cmd_ret)
2399 break;
2401 status = rq->status.resp[0];
2402 if (status & R1_ERROR) {
2403 cmd_ret = -EIO;
2404 break;
2407 if (mmc_is_req_done(host, mrq))
2408 break;
2410 expired = time_after(jiffies, timeout);
2411 if (expired) {
2412 pr_info("%s: timeout waiting for Tran state status %#x\n",
2413 mmc_hostname(host), status);
2414 cmd_ret = -ETIMEDOUT;
2415 break;
2417 } while (repeat_cmd && R1_CURRENT_STATE(status) != R1_STATE_TRAN);
2419 /* Wait for data request to complete */
2420 if (use_areq) {
2421 ret = mmc_test_start_areq(test, NULL, mrq);
2422 } else {
2423 mmc_wait_for_req_done(test->card->host, mrq);
2427 * For cap_cmd_during_tfr request, upper layer must send stop if
2428 * required.
2430 if (mrq->data->stop && (mrq->data->error || !mrq->sbc)) {
2431 if (ret)
2432 mmc_wait_for_cmd(host, mrq->data->stop, 0);
2433 else
2434 ret = mmc_wait_for_cmd(host, mrq->data->stop, 0);
2437 if (ret)
2438 goto out_free;
2440 if (cmd_ret) {
2441 pr_info("%s: Send Status failed: status %#x, error %d\n",
2442 mmc_hostname(test->card->host), status, cmd_ret);
2445 ret = mmc_test_check_result(test, mrq);
2446 if (ret)
2447 goto out_free;
2449 ret = mmc_test_wait_busy(test);
2450 if (ret)
2451 goto out_free;
2453 if (repeat_cmd && (t->blocks + 1) << 9 > t->max_tfr)
2454 pr_info("%s: %d commands completed during transfer of %u blocks\n",
2455 mmc_hostname(test->card->host), count, t->blocks);
2457 if (cmd_ret)
2458 ret = cmd_ret;
2459 out_free:
2460 kfree(rq);
2462 return ret;
2465 static int __mmc_test_cmds_during_tfr(struct mmc_test_card *test,
2466 unsigned long sz, int use_sbc, int write,
2467 int use_areq)
2469 struct mmc_test_area *t = &test->area;
2470 int ret;
2472 if (!(test->card->host->caps & MMC_CAP_CMD_DURING_TFR))
2473 return RESULT_UNSUP_HOST;
2475 ret = mmc_test_area_map(test, sz, 0, 0);
2476 if (ret)
2477 return ret;
2479 ret = mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 0, write,
2480 use_areq);
2481 if (ret)
2482 return ret;
2484 return mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 1, write,
2485 use_areq);
2488 static int mmc_test_cmds_during_tfr(struct mmc_test_card *test, int use_sbc,
2489 int write, int use_areq)
2491 struct mmc_test_area *t = &test->area;
2492 unsigned long sz;
2493 int ret;
2495 for (sz = 512; sz <= t->max_tfr; sz += 512) {
2496 ret = __mmc_test_cmds_during_tfr(test, sz, use_sbc, write,
2497 use_areq);
2498 if (ret)
2499 return ret;
2501 return 0;
2505 * Commands during read - no Set Block Count (CMD23).
2507 static int mmc_test_cmds_during_read(struct mmc_test_card *test)
2509 return mmc_test_cmds_during_tfr(test, 0, 0, 0);
2513 * Commands during write - no Set Block Count (CMD23).
2515 static int mmc_test_cmds_during_write(struct mmc_test_card *test)
2517 return mmc_test_cmds_during_tfr(test, 0, 1, 0);
2521 * Commands during read - use Set Block Count (CMD23).
2523 static int mmc_test_cmds_during_read_cmd23(struct mmc_test_card *test)
2525 return mmc_test_cmds_during_tfr(test, 1, 0, 0);
2529 * Commands during write - use Set Block Count (CMD23).
2531 static int mmc_test_cmds_during_write_cmd23(struct mmc_test_card *test)
2533 return mmc_test_cmds_during_tfr(test, 1, 1, 0);
2537 * Commands during non-blocking read - use Set Block Count (CMD23).
2539 static int mmc_test_cmds_during_read_cmd23_nonblock(struct mmc_test_card *test)
2541 return mmc_test_cmds_during_tfr(test, 1, 0, 1);
2545 * Commands during non-blocking write - use Set Block Count (CMD23).
2547 static int mmc_test_cmds_during_write_cmd23_nonblock(struct mmc_test_card *test)
2549 return mmc_test_cmds_during_tfr(test, 1, 1, 1);
2552 static const struct mmc_test_case mmc_test_cases[] = {
2554 .name = "Basic write (no data verification)",
2555 .run = mmc_test_basic_write,
2559 .name = "Basic read (no data verification)",
2560 .run = mmc_test_basic_read,
2564 .name = "Basic write (with data verification)",
2565 .prepare = mmc_test_prepare_write,
2566 .run = mmc_test_verify_write,
2567 .cleanup = mmc_test_cleanup,
2571 .name = "Basic read (with data verification)",
2572 .prepare = mmc_test_prepare_read,
2573 .run = mmc_test_verify_read,
2574 .cleanup = mmc_test_cleanup,
2578 .name = "Multi-block write",
2579 .prepare = mmc_test_prepare_write,
2580 .run = mmc_test_multi_write,
2581 .cleanup = mmc_test_cleanup,
2585 .name = "Multi-block read",
2586 .prepare = mmc_test_prepare_read,
2587 .run = mmc_test_multi_read,
2588 .cleanup = mmc_test_cleanup,
2592 .name = "Power of two block writes",
2593 .prepare = mmc_test_prepare_write,
2594 .run = mmc_test_pow2_write,
2595 .cleanup = mmc_test_cleanup,
2599 .name = "Power of two block reads",
2600 .prepare = mmc_test_prepare_read,
2601 .run = mmc_test_pow2_read,
2602 .cleanup = mmc_test_cleanup,
2606 .name = "Weird sized block writes",
2607 .prepare = mmc_test_prepare_write,
2608 .run = mmc_test_weird_write,
2609 .cleanup = mmc_test_cleanup,
2613 .name = "Weird sized block reads",
2614 .prepare = mmc_test_prepare_read,
2615 .run = mmc_test_weird_read,
2616 .cleanup = mmc_test_cleanup,
2620 .name = "Badly aligned write",
2621 .prepare = mmc_test_prepare_write,
2622 .run = mmc_test_align_write,
2623 .cleanup = mmc_test_cleanup,
2627 .name = "Badly aligned read",
2628 .prepare = mmc_test_prepare_read,
2629 .run = mmc_test_align_read,
2630 .cleanup = mmc_test_cleanup,
2634 .name = "Badly aligned multi-block write",
2635 .prepare = mmc_test_prepare_write,
2636 .run = mmc_test_align_multi_write,
2637 .cleanup = mmc_test_cleanup,
2641 .name = "Badly aligned multi-block read",
2642 .prepare = mmc_test_prepare_read,
2643 .run = mmc_test_align_multi_read,
2644 .cleanup = mmc_test_cleanup,
2648 .name = "Correct xfer_size at write (start failure)",
2649 .run = mmc_test_xfersize_write,
2653 .name = "Correct xfer_size at read (start failure)",
2654 .run = mmc_test_xfersize_read,
2658 .name = "Correct xfer_size at write (midway failure)",
2659 .run = mmc_test_multi_xfersize_write,
2663 .name = "Correct xfer_size at read (midway failure)",
2664 .run = mmc_test_multi_xfersize_read,
2667 #ifdef CONFIG_HIGHMEM
2670 .name = "Highmem write",
2671 .prepare = mmc_test_prepare_write,
2672 .run = mmc_test_write_high,
2673 .cleanup = mmc_test_cleanup,
2677 .name = "Highmem read",
2678 .prepare = mmc_test_prepare_read,
2679 .run = mmc_test_read_high,
2680 .cleanup = mmc_test_cleanup,
2684 .name = "Multi-block highmem write",
2685 .prepare = mmc_test_prepare_write,
2686 .run = mmc_test_multi_write_high,
2687 .cleanup = mmc_test_cleanup,
2691 .name = "Multi-block highmem read",
2692 .prepare = mmc_test_prepare_read,
2693 .run = mmc_test_multi_read_high,
2694 .cleanup = mmc_test_cleanup,
2697 #else
2700 .name = "Highmem write",
2701 .run = mmc_test_no_highmem,
2705 .name = "Highmem read",
2706 .run = mmc_test_no_highmem,
2710 .name = "Multi-block highmem write",
2711 .run = mmc_test_no_highmem,
2715 .name = "Multi-block highmem read",
2716 .run = mmc_test_no_highmem,
2719 #endif /* CONFIG_HIGHMEM */
2722 .name = "Best-case read performance",
2723 .prepare = mmc_test_area_prepare_fill,
2724 .run = mmc_test_best_read_performance,
2725 .cleanup = mmc_test_area_cleanup,
2729 .name = "Best-case write performance",
2730 .prepare = mmc_test_area_prepare_erase,
2731 .run = mmc_test_best_write_performance,
2732 .cleanup = mmc_test_area_cleanup,
2736 .name = "Best-case read performance into scattered pages",
2737 .prepare = mmc_test_area_prepare_fill,
2738 .run = mmc_test_best_read_perf_max_scatter,
2739 .cleanup = mmc_test_area_cleanup,
2743 .name = "Best-case write performance from scattered pages",
2744 .prepare = mmc_test_area_prepare_erase,
2745 .run = mmc_test_best_write_perf_max_scatter,
2746 .cleanup = mmc_test_area_cleanup,
2750 .name = "Single read performance by transfer size",
2751 .prepare = mmc_test_area_prepare_fill,
2752 .run = mmc_test_profile_read_perf,
2753 .cleanup = mmc_test_area_cleanup,
2757 .name = "Single write performance by transfer size",
2758 .prepare = mmc_test_area_prepare,
2759 .run = mmc_test_profile_write_perf,
2760 .cleanup = mmc_test_area_cleanup,
2764 .name = "Single trim performance by transfer size",
2765 .prepare = mmc_test_area_prepare_fill,
2766 .run = mmc_test_profile_trim_perf,
2767 .cleanup = mmc_test_area_cleanup,
2771 .name = "Consecutive read performance by transfer size",
2772 .prepare = mmc_test_area_prepare_fill,
2773 .run = mmc_test_profile_seq_read_perf,
2774 .cleanup = mmc_test_area_cleanup,
2778 .name = "Consecutive write performance by transfer size",
2779 .prepare = mmc_test_area_prepare,
2780 .run = mmc_test_profile_seq_write_perf,
2781 .cleanup = mmc_test_area_cleanup,
2785 .name = "Consecutive trim performance by transfer size",
2786 .prepare = mmc_test_area_prepare,
2787 .run = mmc_test_profile_seq_trim_perf,
2788 .cleanup = mmc_test_area_cleanup,
2792 .name = "Random read performance by transfer size",
2793 .prepare = mmc_test_area_prepare,
2794 .run = mmc_test_random_read_perf,
2795 .cleanup = mmc_test_area_cleanup,
2799 .name = "Random write performance by transfer size",
2800 .prepare = mmc_test_area_prepare,
2801 .run = mmc_test_random_write_perf,
2802 .cleanup = mmc_test_area_cleanup,
2806 .name = "Large sequential read into scattered pages",
2807 .prepare = mmc_test_area_prepare,
2808 .run = mmc_test_large_seq_read_perf,
2809 .cleanup = mmc_test_area_cleanup,
2813 .name = "Large sequential write from scattered pages",
2814 .prepare = mmc_test_area_prepare,
2815 .run = mmc_test_large_seq_write_perf,
2816 .cleanup = mmc_test_area_cleanup,
2820 .name = "Write performance with blocking req 4k to 4MB",
2821 .prepare = mmc_test_area_prepare,
2822 .run = mmc_test_profile_mult_write_blocking_perf,
2823 .cleanup = mmc_test_area_cleanup,
2827 .name = "Write performance with non-blocking req 4k to 4MB",
2828 .prepare = mmc_test_area_prepare,
2829 .run = mmc_test_profile_mult_write_nonblock_perf,
2830 .cleanup = mmc_test_area_cleanup,
2834 .name = "Read performance with blocking req 4k to 4MB",
2835 .prepare = mmc_test_area_prepare,
2836 .run = mmc_test_profile_mult_read_blocking_perf,
2837 .cleanup = mmc_test_area_cleanup,
2841 .name = "Read performance with non-blocking req 4k to 4MB",
2842 .prepare = mmc_test_area_prepare,
2843 .run = mmc_test_profile_mult_read_nonblock_perf,
2844 .cleanup = mmc_test_area_cleanup,
2848 .name = "Write performance blocking req 1 to 512 sg elems",
2849 .prepare = mmc_test_area_prepare,
2850 .run = mmc_test_profile_sglen_wr_blocking_perf,
2851 .cleanup = mmc_test_area_cleanup,
2855 .name = "Write performance non-blocking req 1 to 512 sg elems",
2856 .prepare = mmc_test_area_prepare,
2857 .run = mmc_test_profile_sglen_wr_nonblock_perf,
2858 .cleanup = mmc_test_area_cleanup,
2862 .name = "Read performance blocking req 1 to 512 sg elems",
2863 .prepare = mmc_test_area_prepare,
2864 .run = mmc_test_profile_sglen_r_blocking_perf,
2865 .cleanup = mmc_test_area_cleanup,
2869 .name = "Read performance non-blocking req 1 to 512 sg elems",
2870 .prepare = mmc_test_area_prepare,
2871 .run = mmc_test_profile_sglen_r_nonblock_perf,
2872 .cleanup = mmc_test_area_cleanup,
2876 .name = "Reset test",
2877 .run = mmc_test_reset,
2881 .name = "Commands during read - no Set Block Count (CMD23)",
2882 .prepare = mmc_test_area_prepare,
2883 .run = mmc_test_cmds_during_read,
2884 .cleanup = mmc_test_area_cleanup,
2888 .name = "Commands during write - no Set Block Count (CMD23)",
2889 .prepare = mmc_test_area_prepare,
2890 .run = mmc_test_cmds_during_write,
2891 .cleanup = mmc_test_area_cleanup,
2895 .name = "Commands during read - use Set Block Count (CMD23)",
2896 .prepare = mmc_test_area_prepare,
2897 .run = mmc_test_cmds_during_read_cmd23,
2898 .cleanup = mmc_test_area_cleanup,
2902 .name = "Commands during write - use Set Block Count (CMD23)",
2903 .prepare = mmc_test_area_prepare,
2904 .run = mmc_test_cmds_during_write_cmd23,
2905 .cleanup = mmc_test_area_cleanup,
2909 .name = "Commands during non-blocking read - use Set Block Count (CMD23)",
2910 .prepare = mmc_test_area_prepare,
2911 .run = mmc_test_cmds_during_read_cmd23_nonblock,
2912 .cleanup = mmc_test_area_cleanup,
2916 .name = "Commands during non-blocking write - use Set Block Count (CMD23)",
2917 .prepare = mmc_test_area_prepare,
2918 .run = mmc_test_cmds_during_write_cmd23_nonblock,
2919 .cleanup = mmc_test_area_cleanup,
2923 static DEFINE_MUTEX(mmc_test_lock);
2925 static LIST_HEAD(mmc_test_result);
2927 static void mmc_test_run(struct mmc_test_card *test, int testcase)
2929 int i, ret;
2931 pr_info("%s: Starting tests of card %s...\n",
2932 mmc_hostname(test->card->host), mmc_card_id(test->card));
2934 mmc_claim_host(test->card->host);
2936 for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++) {
2937 struct mmc_test_general_result *gr;
2939 if (testcase && ((i + 1) != testcase))
2940 continue;
2942 pr_info("%s: Test case %d. %s...\n",
2943 mmc_hostname(test->card->host), i + 1,
2944 mmc_test_cases[i].name);
2946 if (mmc_test_cases[i].prepare) {
2947 ret = mmc_test_cases[i].prepare(test);
2948 if (ret) {
2949 pr_info("%s: Result: Prepare stage failed! (%d)\n",
2950 mmc_hostname(test->card->host),
2951 ret);
2952 continue;
2956 gr = kzalloc(sizeof(*gr), GFP_KERNEL);
2957 if (gr) {
2958 INIT_LIST_HEAD(&gr->tr_lst);
2960 /* Assign data what we know already */
2961 gr->card = test->card;
2962 gr->testcase = i;
2964 /* Append container to global one */
2965 list_add_tail(&gr->link, &mmc_test_result);
2968 * Save the pointer to created container in our private
2969 * structure.
2971 test->gr = gr;
2974 ret = mmc_test_cases[i].run(test);
2975 switch (ret) {
2976 case RESULT_OK:
2977 pr_info("%s: Result: OK\n",
2978 mmc_hostname(test->card->host));
2979 break;
2980 case RESULT_FAIL:
2981 pr_info("%s: Result: FAILED\n",
2982 mmc_hostname(test->card->host));
2983 break;
2984 case RESULT_UNSUP_HOST:
2985 pr_info("%s: Result: UNSUPPORTED (by host)\n",
2986 mmc_hostname(test->card->host));
2987 break;
2988 case RESULT_UNSUP_CARD:
2989 pr_info("%s: Result: UNSUPPORTED (by card)\n",
2990 mmc_hostname(test->card->host));
2991 break;
2992 default:
2993 pr_info("%s: Result: ERROR (%d)\n",
2994 mmc_hostname(test->card->host), ret);
2997 /* Save the result */
2998 if (gr)
2999 gr->result = ret;
3001 if (mmc_test_cases[i].cleanup) {
3002 ret = mmc_test_cases[i].cleanup(test);
3003 if (ret) {
3004 pr_info("%s: Warning: Cleanup stage failed! (%d)\n",
3005 mmc_hostname(test->card->host),
3006 ret);
3011 mmc_release_host(test->card->host);
3013 pr_info("%s: Tests completed.\n",
3014 mmc_hostname(test->card->host));
3017 static void mmc_test_free_result(struct mmc_card *card)
3019 struct mmc_test_general_result *gr, *grs;
3021 mutex_lock(&mmc_test_lock);
3023 list_for_each_entry_safe(gr, grs, &mmc_test_result, link) {
3024 struct mmc_test_transfer_result *tr, *trs;
3026 if (card && gr->card != card)
3027 continue;
3029 list_for_each_entry_safe(tr, trs, &gr->tr_lst, link) {
3030 list_del(&tr->link);
3031 kfree(tr);
3034 list_del(&gr->link);
3035 kfree(gr);
3038 mutex_unlock(&mmc_test_lock);
3041 static LIST_HEAD(mmc_test_file_test);
3043 static int mtf_test_show(struct seq_file *sf, void *data)
3045 struct mmc_card *card = (struct mmc_card *)sf->private;
3046 struct mmc_test_general_result *gr;
3048 mutex_lock(&mmc_test_lock);
3050 list_for_each_entry(gr, &mmc_test_result, link) {
3051 struct mmc_test_transfer_result *tr;
3053 if (gr->card != card)
3054 continue;
3056 seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
3058 list_for_each_entry(tr, &gr->tr_lst, link) {
3059 seq_printf(sf, "%u %d %llu.%09u %u %u.%02u\n",
3060 tr->count, tr->sectors,
3061 (u64)tr->ts.tv_sec, (u32)tr->ts.tv_nsec,
3062 tr->rate, tr->iops / 100, tr->iops % 100);
3066 mutex_unlock(&mmc_test_lock);
3068 return 0;
3071 static int mtf_test_open(struct inode *inode, struct file *file)
3073 return single_open(file, mtf_test_show, inode->i_private);
3076 static ssize_t mtf_test_write(struct file *file, const char __user *buf,
3077 size_t count, loff_t *pos)
3079 struct seq_file *sf = (struct seq_file *)file->private_data;
3080 struct mmc_card *card = (struct mmc_card *)sf->private;
3081 struct mmc_test_card *test;
3082 long testcase;
3083 int ret;
3085 ret = kstrtol_from_user(buf, count, 10, &testcase);
3086 if (ret)
3087 return ret;
3089 test = kzalloc(sizeof(*test), GFP_KERNEL);
3090 if (!test)
3091 return -ENOMEM;
3094 * Remove all test cases associated with given card. Thus we have only
3095 * actual data of the last run.
3097 mmc_test_free_result(card);
3099 test->card = card;
3101 test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL);
3102 #ifdef CONFIG_HIGHMEM
3103 test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER);
3104 #endif
3106 #ifdef CONFIG_HIGHMEM
3107 if (test->buffer && test->highmem) {
3108 #else
3109 if (test->buffer) {
3110 #endif
3111 mutex_lock(&mmc_test_lock);
3112 mmc_test_run(test, testcase);
3113 mutex_unlock(&mmc_test_lock);
3116 #ifdef CONFIG_HIGHMEM
3117 __free_pages(test->highmem, BUFFER_ORDER);
3118 #endif
3119 kfree(test->buffer);
3120 kfree(test);
3122 return count;
3125 static const struct file_operations mmc_test_fops_test = {
3126 .open = mtf_test_open,
3127 .read = seq_read,
3128 .write = mtf_test_write,
3129 .llseek = seq_lseek,
3130 .release = single_release,
3133 static int mtf_testlist_show(struct seq_file *sf, void *data)
3135 int i;
3137 mutex_lock(&mmc_test_lock);
3139 seq_puts(sf, "0:\tRun all tests\n");
3140 for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++)
3141 seq_printf(sf, "%d:\t%s\n", i + 1, mmc_test_cases[i].name);
3143 mutex_unlock(&mmc_test_lock);
3145 return 0;
3148 static int mtf_testlist_open(struct inode *inode, struct file *file)
3150 return single_open(file, mtf_testlist_show, inode->i_private);
3153 static const struct file_operations mmc_test_fops_testlist = {
3154 .open = mtf_testlist_open,
3155 .read = seq_read,
3156 .llseek = seq_lseek,
3157 .release = single_release,
3160 static void mmc_test_free_dbgfs_file(struct mmc_card *card)
3162 struct mmc_test_dbgfs_file *df, *dfs;
3164 mutex_lock(&mmc_test_lock);
3166 list_for_each_entry_safe(df, dfs, &mmc_test_file_test, link) {
3167 if (card && df->card != card)
3168 continue;
3169 debugfs_remove(df->file);
3170 list_del(&df->link);
3171 kfree(df);
3174 mutex_unlock(&mmc_test_lock);
3177 static int __mmc_test_register_dbgfs_file(struct mmc_card *card,
3178 const char *name, umode_t mode, const struct file_operations *fops)
3180 struct dentry *file = NULL;
3181 struct mmc_test_dbgfs_file *df;
3183 if (card->debugfs_root)
3184 file = debugfs_create_file(name, mode, card->debugfs_root,
3185 card, fops);
3187 if (IS_ERR_OR_NULL(file)) {
3188 dev_err(&card->dev,
3189 "Can't create %s. Perhaps debugfs is disabled.\n",
3190 name);
3191 return -ENODEV;
3194 df = kmalloc(sizeof(*df), GFP_KERNEL);
3195 if (!df) {
3196 debugfs_remove(file);
3197 return -ENOMEM;
3200 df->card = card;
3201 df->file = file;
3203 list_add(&df->link, &mmc_test_file_test);
3204 return 0;
3207 static int mmc_test_register_dbgfs_file(struct mmc_card *card)
3209 int ret;
3211 mutex_lock(&mmc_test_lock);
3213 ret = __mmc_test_register_dbgfs_file(card, "test", S_IWUSR | S_IRUGO,
3214 &mmc_test_fops_test);
3215 if (ret)
3216 goto err;
3218 ret = __mmc_test_register_dbgfs_file(card, "testlist", S_IRUGO,
3219 &mmc_test_fops_testlist);
3220 if (ret)
3221 goto err;
3223 err:
3224 mutex_unlock(&mmc_test_lock);
3226 return ret;
3229 static int mmc_test_probe(struct mmc_card *card)
3231 int ret;
3233 if (!mmc_card_mmc(card) && !mmc_card_sd(card))
3234 return -ENODEV;
3236 ret = mmc_test_register_dbgfs_file(card);
3237 if (ret)
3238 return ret;
3240 if (card->ext_csd.cmdq_en) {
3241 mmc_claim_host(card->host);
3242 ret = mmc_cmdq_disable(card);
3243 mmc_release_host(card->host);
3244 if (ret)
3245 return ret;
3248 dev_info(&card->dev, "Card claimed for testing.\n");
3250 return 0;
3253 static void mmc_test_remove(struct mmc_card *card)
3255 if (card->reenable_cmdq) {
3256 mmc_claim_host(card->host);
3257 mmc_cmdq_enable(card);
3258 mmc_release_host(card->host);
3260 mmc_test_free_result(card);
3261 mmc_test_free_dbgfs_file(card);
3264 static void mmc_test_shutdown(struct mmc_card *card)
3268 static struct mmc_driver mmc_driver = {
3269 .drv = {
3270 .name = "mmc_test",
3272 .probe = mmc_test_probe,
3273 .remove = mmc_test_remove,
3274 .shutdown = mmc_test_shutdown,
3277 static int __init mmc_test_init(void)
3279 return mmc_register_driver(&mmc_driver);
3282 static void __exit mmc_test_exit(void)
3284 /* Clear stalled data if card is still plugged */
3285 mmc_test_free_result(NULL);
3286 mmc_test_free_dbgfs_file(NULL);
3288 mmc_unregister_driver(&mmc_driver);
3291 module_init(mmc_test_init);
3292 module_exit(mmc_test_exit);
3294 MODULE_LICENSE("GPL");
3295 MODULE_DESCRIPTION("Multimedia Card (MMC) host test driver");
3296 MODULE_AUTHOR("Pierre Ossman");