16 #include <linux/slab.h>
20 #include <linux/list.h>
25 #include <linux/module.h>
29 #define RESULT_UNSUP_HOST 2
30 #define RESULT_UNSUP_CARD 3
32 #define BUFFER_ORDER 2
33 #define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER)
39 #define TEST_AREA_MAX_SIZE (128 * 1024 * 1024)
145 #ifdef CONFIG_HIGHMEM
190 unsigned dev_addr,
unsigned blocks,
unsigned blksz,
int write)
195 mrq->
cmd->opcode = write ?
198 mrq->
cmd->opcode = write ?
202 mrq->
cmd->arg = dev_addr;
217 mrq->
data->blocks = blocks;
220 mrq->
data->sg_len = sg_len;
244 cmd.
arg = test->
card->rca << 16;
251 if (!busy && mmc_test_busy(&cmd)) {
254 pr_info(
"%s: Warning: Host did not "
255 "wait for busy state to end.\n",
258 }
while (mmc_test_busy(&cmd));
266 static int mmc_test_buffer_transfer(
struct mmc_test_card *test,
284 mmc_test_prepare_mrq(test, &mrq, &sg, 1, addr, 1, blksz, write);
293 ret = mmc_test_wait_busy(test);
306 mem->
arr[mem->
cnt].order);
317 static struct mmc_test_mem *mmc_test_alloc_mem(
unsigned long min_sz,
318 unsigned long max_sz,
319 unsigned int max_segs,
320 unsigned int max_seg_sz)
325 unsigned long page_cnt = 0;
329 if (max_page_cnt > limit)
330 max_page_cnt =
limit;
331 if (min_page_cnt > max_page_cnt)
332 min_page_cnt = max_page_cnt;
334 if (max_seg_page_cnt > max_page_cnt)
335 max_seg_page_cnt = max_page_cnt;
337 if (max_segs > max_page_cnt)
338 max_segs = max_page_cnt;
349 while (max_page_cnt) {
363 if (page_cnt < min_page_cnt)
370 if (max_page_cnt <= (1
UL << order))
374 if (mem->
cnt >= max_segs) {
375 if (page_cnt < min_page_cnt)
384 mmc_test_free_mem(mem);
394 unsigned int max_segs,
unsigned int max_seg_sz,
395 unsigned int *sg_len,
int min_sg_len)
399 unsigned long sz =
size;
402 if (min_sg_len > max_segs)
403 min_sg_len = max_segs;
407 for (i = 0; i < mem->
cnt; i++) {
410 if (min_sg_len && (size / min_sg_len < len))
411 len =
ALIGN(size / min_sg_len, 512);
414 if (len > max_seg_sz)
422 sg_set_page(sg, mem->
arr[i].page, len, 0);
428 }
while (sz && repeat);
443 static int mmc_test_map_sg_max_scatter(
struct mmc_test_mem *mem,
446 unsigned int max_segs,
447 unsigned int max_seg_sz,
448 unsigned int *sg_len)
451 unsigned int i = mem->
cnt,
cnt;
463 if (last_addr && last_addr +
PAGE_SIZE == addr)
467 if (len > max_seg_sz)
520 static void mmc_test_save_transfer_result(
struct mmc_test_card *test,
522 unsigned int rate,
unsigned int iops)
548 unsigned int rate,
iops, sectors = bytes >> 9;
551 ts = timespec_sub(*ts2, *ts1);
553 rate = mmc_test_rate(bytes, &ts);
554 iops = mmc_test_rate(100, &ts);
556 pr_info(
"%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
557 "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
559 (sectors & 1 ?
".5" :
""), (
unsigned long)ts.tv_sec,
560 (
unsigned long)ts.tv_nsec, rate / 1000, rate / 1024,
561 iops / 100, iops % 100);
563 mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops);
570 unsigned int count,
struct timespec *ts1,
573 unsigned int rate, iops, sectors = bytes >> 9;
577 ts = timespec_sub(*ts2, *ts1);
579 rate = mmc_test_rate(tot, &ts);
580 iops = mmc_test_rate(count * 100, &ts);
582 pr_info(
"%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
583 "%lu.%09lu seconds (%u kB/s, %u KiB/s, "
584 "%u.%02u IOPS, sg_len %d)\n",
586 sectors >> 1, (sectors & 1 ?
".5" :
""),
587 (
unsigned long)ts.tv_sec, (
unsigned long)ts.tv_nsec,
588 rate / 1000, rate / 1024, iops / 100, iops % 100,
591 mmc_test_save_transfer_result(test, count, sectors, ts, rate, iops);
597 static unsigned int mmc_test_capacity(
struct mmc_card *
card)
602 return card->
csd.capacity << (card->
csd.read_blkbits - 9);
613 static int __mmc_test_prepare(
struct mmc_test_card *test,
int write)
617 ret = mmc_test_set_blksize(test, 512);
624 for (i = 0;i < 512;i++)
629 ret = mmc_test_buffer_transfer(test, test->
buffer, i, 512, 1);
637 static int mmc_test_prepare_write(
struct mmc_test_card *test)
639 return __mmc_test_prepare(test, 1);
644 return __mmc_test_prepare(test, 0);
651 ret = mmc_test_set_blksize(test, 512);
658 ret = mmc_test_buffer_transfer(test, test->
buffer, i, 512, 1);
673 static void mmc_test_prepare_broken_mrq(
struct mmc_test_card *test,
678 if (mrq->
data->blocks > 1) {
679 mrq->
cmd->opcode = write ?
684 mrq->
cmd->arg = test->
card->rca << 16;
700 if (!ret && mrq->
cmd->error)
701 ret = mrq->
cmd->error;
702 if (!ret && mrq->
data->error)
703 ret = mrq->
data->error;
704 if (!ret && mrq->
stop && mrq->
stop->error)
705 ret = mrq->
stop->error;
706 if (!ret && mrq->
data->bytes_xfered !=
707 mrq->
data->blocks * mrq->
data->blksz)
716 static int mmc_test_check_result_async(
struct mmc_card *card,
722 mmc_test_wait_busy(test_async->
test);
724 return mmc_test_check_result(test_async->
test, areq->
mrq);
730 static int mmc_test_check_broken_result(
struct mmc_test_card *test,
739 if (!ret && mrq->
cmd->error)
740 ret = mrq->
cmd->error;
741 if (!ret && mrq->
data->error == 0)
744 ret = mrq->
data->error;
745 if (!ret && mrq->
stop && mrq->
stop->error)
746 ret = mrq->
stop->error;
747 if (mrq->
data->blocks > 1) {
748 if (!ret && mrq->
data->bytes_xfered > mrq->
data->blksz)
751 if (!ret && mrq->
data->bytes_xfered > 0)
764 static void mmc_test_nonblock_reset(
struct mmc_request *mrq,
778 static int mmc_test_nonblock_transfer(
struct mmc_test_card *test,
780 unsigned dev_addr,
unsigned blocks,
781 unsigned blksz,
int write,
int count)
800 test_areq[0].test =
test;
801 test_areq[1].test =
test;
803 mmc_test_nonblock_reset(&mrq1, &cmd1, &stop1, &
data1);
804 mmc_test_nonblock_reset(&mrq2, &cmd2, &stop2, &
data2);
806 cur_areq->
mrq = &mrq1;
807 cur_areq->
err_check = mmc_test_check_result_async;
808 other_areq->
mrq = &mrq2;
809 other_areq->
err_check = mmc_test_check_result_async;
811 for (i = 0; i <
count; i++) {
812 mmc_test_prepare_mrq(test, cur_areq->
mrq, sg, sg_len, dev_addr,
813 blocks, blksz, write);
816 if (ret || (!done_areq && i > 0))
820 if (done_areq->
mrq == &mrq2)
821 mmc_test_nonblock_reset(&mrq2, &cmd2,
824 mmc_test_nonblock_reset(&mrq1, &cmd1,
827 done_areq = cur_areq;
828 cur_areq = other_areq;
829 other_areq = done_areq;
843 static int mmc_test_simple_transfer(
struct mmc_test_card *test,
844 struct scatterlist *sg,
unsigned sg_len,
unsigned dev_addr,
845 unsigned blocks,
unsigned blksz,
int write)
856 mmc_test_prepare_mrq(test, &mrq, sg, sg_len, dev_addr,
857 blocks, blksz, write);
861 mmc_test_wait_busy(test);
863 return mmc_test_check_result(test, &mrq);
869 static int mmc_test_broken_transfer(
struct mmc_test_card *test,
870 unsigned blocks,
unsigned blksz,
int write)
885 mmc_test_prepare_mrq(test, &mrq, &sg, 1, 0, blocks, blksz, write);
886 mmc_test_prepare_broken_mrq(test, &mrq, write);
890 mmc_test_wait_busy(test);
892 return mmc_test_check_broken_result(test, &mrq);
901 struct scatterlist *sg,
unsigned sg_len,
unsigned dev_addr,
902 unsigned blocks,
unsigned blksz,
int write)
908 for (i = 0;i < blocks *
blksz;i++)
917 ret = mmc_test_set_blksize(test, blksz);
921 ret = mmc_test_simple_transfer(test, sg, sg_len, dev_addr,
922 blocks, blksz, write);
929 ret = mmc_test_set_blksize(test, 512);
933 sectors = (blocks * blksz + 511) / 512;
934 if ((sectors * 512) == (blocks *
blksz))
943 ret = mmc_test_buffer_transfer(test,
945 dev_addr + i, 512, 0);
950 for (i = 0;i < blocks *
blksz;i++) {
955 for (;i < sectors * 512;i++) {
956 if (test->
buffer[i] != 0xDF)
963 for (i = 0;i < blocks *
blksz;i++) {
989 ret = mmc_test_set_blksize(test, 512);
995 ret = mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 1);
1007 ret = mmc_test_set_blksize(test, 512);
1013 ret = mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 0);
1020 static int mmc_test_verify_write(
struct mmc_test_card *test)
1027 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1041 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1054 if (test->
card->host->max_blk_count == 1)
1058 size =
min(size, test->
card->host->max_req_size);
1059 size =
min(size, test->
card->host->max_seg_size);
1060 size =
min(size, test->
card->host->max_blk_count * 512);
1067 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1);
1080 if (test->
card->host->max_blk_count == 1)
1084 size =
min(size, test->
card->host->max_req_size);
1085 size =
min(size, test->
card->host->max_seg_size);
1086 size =
min(size, test->
card->host->max_blk_count * 512);
1093 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0);
1105 if (!test->
card->csd.write_partial)
1108 for (i = 1; i < 512;i <<= 1) {
1110 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
1123 if (!test->
card->csd.read_partial)
1126 for (i = 1; i < 512;i <<= 1) {
1128 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
1141 if (!test->
card->csd.write_partial)
1144 for (i = 3; i < 512;i += 7) {
1146 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
1159 if (!test->
card->csd.read_partial)
1162 for (i = 3; i < 512;i += 7) {
1164 ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
1177 for (i = 1;i < 4;i++) {
1179 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1192 for (i = 1;i < 4;i++) {
1194 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1202 static int mmc_test_align_multi_write(
struct mmc_test_card *test)
1208 if (test->
card->host->max_blk_count == 1)
1212 size =
min(size, test->
card->host->max_req_size);
1213 size =
min(size, test->
card->host->max_seg_size);
1214 size =
min(size, test->
card->host->max_blk_count * 512);
1219 for (i = 1;i < 4;i++) {
1221 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1);
1229 static int mmc_test_align_multi_read(
struct mmc_test_card *test)
1235 if (test->
card->host->max_blk_count == 1)
1239 size =
min(size, test->
card->host->max_req_size);
1240 size =
min(size, test->
card->host->max_seg_size);
1241 size =
min(size, test->
card->host->max_blk_count * 512);
1246 for (i = 1;i < 4;i++) {
1248 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0);
1256 static int mmc_test_xfersize_write(
struct mmc_test_card *test)
1260 ret = mmc_test_set_blksize(test, 512);
1264 ret = mmc_test_broken_transfer(test, 1, 512, 1);
1271 static int mmc_test_xfersize_read(
struct mmc_test_card *test)
1275 ret = mmc_test_set_blksize(test, 512);
1279 ret = mmc_test_broken_transfer(test, 1, 512, 0);
1286 static int mmc_test_multi_xfersize_write(
struct mmc_test_card *test)
1290 if (test->
card->host->max_blk_count == 1)
1293 ret = mmc_test_set_blksize(test, 512);
1297 ret = mmc_test_broken_transfer(test, 2, 512, 1);
1304 static int mmc_test_multi_xfersize_read(
struct mmc_test_card *test)
1308 if (test->
card->host->max_blk_count == 1)
1311 ret = mmc_test_set_blksize(test, 512);
1315 ret = mmc_test_broken_transfer(test, 2, 512, 0);
1322 #ifdef CONFIG_HIGHMEM
1330 sg_set_page(&sg, test->highmem, 512, 0);
1332 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1345 sg_set_page(&sg, test->highmem, 512, 0);
1347 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1354 static int mmc_test_multi_write_high(
struct mmc_test_card *test)
1360 if (test->
card->host->max_blk_count == 1)
1364 size =
min(size, test->
card->host->max_req_size);
1365 size =
min(size, test->
card->host->max_seg_size);
1366 size =
min(size, test->
card->host->max_blk_count * 512);
1372 sg_set_page(&sg, test->highmem, size, 0);
1374 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1);
1381 static int mmc_test_multi_read_high(
struct mmc_test_card *test)
1387 if (test->
card->host->max_blk_count == 1)
1391 size =
min(size, test->
card->host->max_req_size);
1392 size =
min(size, test->
card->host->max_seg_size);
1393 size =
min(size, test->
card->host->max_blk_count * 512);
1399 sg_set_page(&sg, test->highmem, size, 0);
1401 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0);
1412 pr_info(
"%s: Highmem not configured - test skipped\n",
1422 static int mmc_test_area_map(
struct mmc_test_card *test,
unsigned long sz,
1423 int max_scatter,
int min_sg_len)
1431 err = mmc_test_map_sg_max_scatter(t->
mem, sz, t->
sg,
1439 pr_info(
"%s: Failed to map sg list\n",
1447 static int mmc_test_area_transfer(
struct mmc_test_card *test,
1448 unsigned int dev_addr,
int write)
1452 return mmc_test_simple_transfer(test, t->
sg, t->
sg_len, dev_addr,
1459 static int mmc_test_area_io_seq(
struct mmc_test_card *test,
unsigned long sz,
1460 unsigned int dev_addr,
int write,
1461 int max_scatter,
int timed,
int count,
1462 bool nonblock,
int min_sg_len)
1485 ret = mmc_test_area_map(test, sz, max_scatter, min_sg_len);
1492 ret = mmc_test_nonblock_transfer(test, t->
sg, t->
sg_len,
1493 dev_addr, t->
blocks, 512, write, count);
1495 for (i = 0; i < count && ret == 0; i++) {
1496 ret = mmc_test_area_transfer(test, dev_addr, write);
1497 dev_addr += sz >> 9;
1507 mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2);
1512 static int mmc_test_area_io(
struct mmc_test_card *test,
unsigned long sz,
1513 unsigned int dev_addr,
int write,
int max_scatter,
1516 return mmc_test_area_io_seq(test, sz, dev_addr, write, max_scatter,
1517 timed, 1,
false, 0);
1547 static int mmc_test_area_cleanup(
struct mmc_test_card *test)
1552 mmc_test_free_mem(t->
mem);
1567 unsigned long min_sz = 64 * 1024, sz;
1570 ret = mmc_test_set_blksize(test, 512);
1575 sz = (
unsigned long)test->
card->pref_erase << 9;
1577 while (t->
max_sz < 4 * 1024 * 1024)
1587 if (t->
max_tfr >> 9 > test->
card->host->max_blk_count)
1588 t->
max_tfr = test->
card->host->max_blk_count << 9;
1615 ret = mmc_test_area_erase(test);
1621 ret = mmc_test_area_fill(test);
1629 mmc_test_area_cleanup(test);
1636 static int mmc_test_area_prepare(
struct mmc_test_card *test)
1638 return mmc_test_area_init(test, 0, 0);
1644 static int mmc_test_area_prepare_erase(
struct mmc_test_card *test)
1646 return mmc_test_area_init(test, 1, 0);
1652 static int mmc_test_area_prepare_fill(
struct mmc_test_card *test)
1654 return mmc_test_area_init(test, 1, 1);
1665 static int mmc_test_best_performance(
struct mmc_test_card *test,
int write,
1677 static int mmc_test_best_read_performance(
struct mmc_test_card *test)
1679 return mmc_test_best_performance(test, 0, 0);
1685 static int mmc_test_best_write_performance(
struct mmc_test_card *test)
1687 return mmc_test_best_performance(test, 1, 0);
1693 static int mmc_test_best_read_perf_max_scatter(
struct mmc_test_card *test)
1695 return mmc_test_best_performance(test, 0, 1);
1701 static int mmc_test_best_write_perf_max_scatter(
struct mmc_test_card *test)
1703 return mmc_test_best_performance(test, 1, 1);
1709 static int mmc_test_profile_read_perf(
struct mmc_test_card *test)
1716 for (sz = 512; sz < t->
max_tfr; sz <<= 1) {
1717 dev_addr = t->
dev_addr + (sz >> 9);
1718 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1724 return mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1730 static int mmc_test_profile_write_perf(
struct mmc_test_card *test)
1737 ret = mmc_test_area_erase(test);
1740 for (sz = 512; sz < t->
max_tfr; sz <<= 1) {
1741 dev_addr = t->
dev_addr + (sz >> 9);
1742 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1746 ret = mmc_test_area_erase(test);
1751 return mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1757 static int mmc_test_profile_trim_perf(
struct mmc_test_card *test)
1771 for (sz = 512; sz < t->
max_sz; sz <<= 1) {
1772 dev_addr = t->
dev_addr + (sz >> 9);
1778 mmc_test_print_rate(test, sz, &ts1, &ts2);
1786 mmc_test_print_rate(test, sz, &ts1, &ts2);
1790 static int mmc_test_seq_read_perf(
struct mmc_test_card *test,
unsigned long sz)
1800 for (i = 0; i <
cnt; i++) {
1801 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0);
1804 dev_addr += (sz >> 9);
1807 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1814 static int mmc_test_profile_seq_read_perf(
struct mmc_test_card *test)
1820 for (sz = 512; sz < t->
max_tfr; sz <<= 1) {
1821 ret = mmc_test_seq_read_perf(test, sz);
1826 return mmc_test_seq_read_perf(test, sz);
1829 static int mmc_test_seq_write_perf(
struct mmc_test_card *test,
unsigned long sz)
1836 ret = mmc_test_area_erase(test);
1842 for (i = 0; i <
cnt; i++) {
1843 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0);
1846 dev_addr += (sz >> 9);
1849 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1856 static int mmc_test_profile_seq_write_perf(
struct mmc_test_card *test)
1862 for (sz = 512; sz < t->
max_tfr; sz <<= 1) {
1863 ret = mmc_test_seq_write_perf(test, sz);
1868 return mmc_test_seq_write_perf(test, sz);
1874 static int mmc_test_profile_seq_trim_perf(
struct mmc_test_card *test)
1888 for (sz = 512; sz <= t->
max_sz; sz <<= 1) {
1889 ret = mmc_test_area_erase(test);
1892 ret = mmc_test_area_fill(test);
1898 for (i = 0; i <
cnt; i++) {
1903 dev_addr += (sz >> 9);
1906 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1911 static unsigned int rnd_next = 1;
1913 static unsigned int mmc_test_rnd_num(
unsigned int rnd_cnt)
1917 rnd_next = rnd_next * 1103515245 + 12345;
1918 r = (rnd_next >> 16) & 0x7fff;
1919 return (r * rnd_cnt) >> 15;
1922 static int mmc_test_rnd_perf(
struct mmc_test_card *test,
int write,
int print,
1925 unsigned int dev_addr,
cnt, rnd_addr, range1, range2, last_ea = 0,
ea;
1932 rnd_addr = mmc_test_capacity(test->
card) / 4;
1933 range1 = rnd_addr / test->
card->pref_erase;
1934 range2 = range1 / ssz;
1937 for (cnt = 0; cnt <
UINT_MAX; cnt++) {
1939 ts = timespec_sub(ts2, ts1);
1940 if (ts.tv_sec >= 10)
1942 ea = mmc_test_rnd_num(range1);
1946 dev_addr = rnd_addr + test->
card->pref_erase *
ea +
1947 ssz * mmc_test_rnd_num(range2);
1948 ret = mmc_test_area_io(test, sz, dev_addr, write, 0, 0);
1953 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1957 static int mmc_test_random_perf(
struct mmc_test_card *test,
int write)
1964 for (sz = 512; sz < t->
max_tfr; sz <<= 1) {
1972 ret = mmc_test_rnd_perf(test, write, 0, sz);
1977 ret = mmc_test_rnd_perf(test, write, 1, sz);
1984 ret = mmc_test_rnd_perf(test, write, 0, sz);
1989 return mmc_test_rnd_perf(test, write, 1, sz);
1995 static int mmc_test_random_read_perf(
struct mmc_test_card *test)
1997 return mmc_test_random_perf(test, 0);
2003 static int mmc_test_random_write_perf(
struct mmc_test_card *test)
2005 return mmc_test_random_perf(test, 1);
2008 static int mmc_test_seq_perf(
struct mmc_test_card *test,
int write,
2009 unsigned int tot_sz,
int max_scatter)
2023 unsigned long max_tfr;
2034 dev_addr = mmc_test_capacity(test->
card) / 4;
2035 if (tot_sz > dev_addr << 9)
2036 tot_sz = dev_addr << 9;
2038 dev_addr &= 0xffff0000;
2041 for (i = 0; i <
cnt; i++) {
2042 ret = mmc_test_area_io(test, sz, dev_addr, write,
2050 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
2055 static int mmc_test_large_seq_perf(
struct mmc_test_card *test,
int write)
2059 for (i = 0; i < 10; i++) {
2060 ret = mmc_test_seq_perf(test, write, 10 * 1024 * 1024, 1);
2064 for (i = 0; i < 5; i++) {
2065 ret = mmc_test_seq_perf(test, write, 100 * 1024 * 1024, 1);
2069 for (i = 0; i < 3; i++) {
2070 ret = mmc_test_seq_perf(test, write, 1000 * 1024 * 1024, 1);
2081 static int mmc_test_large_seq_read_perf(
struct mmc_test_card *test)
2083 return mmc_test_large_seq_perf(test, 0);
2089 static int mmc_test_large_seq_write_perf(
struct mmc_test_card *test)
2091 return mmc_test_large_seq_perf(test, 1);
2096 unsigned int reqsize,
unsigned int size,
2099 unsigned int dev_addr;
2104 if (size > mmc_test_capacity(test->
card) / 2 * 512)
2105 size = mmc_test_capacity(test->
card) / 2 * 512;
2108 dev_addr = mmc_test_capacity(test->
card) / 4;
2109 if ((dev_addr & 0xffff0000))
2110 dev_addr &= 0xffff0000;
2112 dev_addr &= 0xfffff800;
2132 ret = mmc_test_area_io_seq(test, reqsize, dev_addr,
2133 tdata->
do_write, 0, 1, size / reqsize,
2140 pr_info(
"[%s] error\n", __func__);
2144 static int mmc_test_rw_multiple_size(
struct mmc_test_card *test,
2149 void *pre_req = test->
card->host->ops->pre_req;
2150 void *post_req = test->
card->host->ops->post_req;
2153 ((!pre_req && post_req) || (pre_req && !post_req))) {
2154 pr_info(
"error: only one of pre/post is defined\n");
2158 for (i = 0 ; i < rw->
len && ret == 0; i++) {
2159 ret = mmc_test_rw_multiple(test, rw, rw->
bs[i], rw->
size, 0);
2166 static int mmc_test_rw_multiple_sg_len(
struct mmc_test_card *test,
2172 for (i = 0 ; i < rw->
len && ret == 0; i++) {
2173 ret = mmc_test_rw_multiple(test, rw, 512*1024, rw->
size,
2184 static int mmc_test_profile_mult_write_blocking_perf(
struct mmc_test_card *test)
2186 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2187 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2193 .do_nonblock_req =
false,
2197 return mmc_test_rw_multiple_size(test, &test_data);
2203 static int mmc_test_profile_mult_write_nonblock_perf(
struct mmc_test_card *test)
2205 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2206 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2212 .do_nonblock_req =
true,
2216 return mmc_test_rw_multiple_size(test, &test_data);
2222 static int mmc_test_profile_mult_read_blocking_perf(
struct mmc_test_card *test)
2224 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2225 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2231 .do_nonblock_req =
false,
2235 return mmc_test_rw_multiple_size(test, &test_data);
2241 static int mmc_test_profile_mult_read_nonblock_perf(
struct mmc_test_card *test)
2243 unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
2244 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
2250 .do_nonblock_req =
true,
2254 return mmc_test_rw_multiple_size(test, &test_data);
2260 static int mmc_test_profile_sglen_wr_blocking_perf(
struct mmc_test_card *test)
2262 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2263 1 << 7, 1 << 8, 1 << 9};
2269 .do_nonblock_req =
false,
2273 return mmc_test_rw_multiple_sg_len(test, &test_data);
2279 static int mmc_test_profile_sglen_wr_nonblock_perf(
struct mmc_test_card *test)
2281 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2282 1 << 7, 1 << 8, 1 << 9};
2288 .do_nonblock_req =
true,
2292 return mmc_test_rw_multiple_sg_len(test, &test_data);
2298 static int mmc_test_profile_sglen_r_blocking_perf(
struct mmc_test_card *test)
2300 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2301 1 << 7, 1 << 8, 1 << 9};
2307 .do_nonblock_req =
false,
2311 return mmc_test_rw_multiple_sg_len(test, &test_data);
2317 static int mmc_test_profile_sglen_r_nonblock_perf(
struct mmc_test_card *test)
2319 unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
2320 1 << 7, 1 << 8, 1 << 9};
2326 .do_nonblock_req =
true,
2330 return mmc_test_rw_multiple_sg_len(test, &test_data);
2360 .name =
"Basic write (no data verification)",
2361 .run = mmc_test_basic_write,
2365 .name =
"Basic read (no data verification)",
2366 .run = mmc_test_basic_read,
2370 .name =
"Basic write (with data verification)",
2371 .prepare = mmc_test_prepare_write,
2372 .run = mmc_test_verify_write,
2373 .cleanup = mmc_test_cleanup,
2377 .name =
"Basic read (with data verification)",
2378 .prepare = mmc_test_prepare_read,
2379 .run = mmc_test_verify_read,
2380 .cleanup = mmc_test_cleanup,
2384 .name =
"Multi-block write",
2385 .prepare = mmc_test_prepare_write,
2386 .run = mmc_test_multi_write,
2387 .cleanup = mmc_test_cleanup,
2391 .name =
"Multi-block read",
2392 .prepare = mmc_test_prepare_read,
2393 .run = mmc_test_multi_read,
2394 .cleanup = mmc_test_cleanup,
2398 .name =
"Power of two block writes",
2399 .prepare = mmc_test_prepare_write,
2400 .run = mmc_test_pow2_write,
2401 .cleanup = mmc_test_cleanup,
2405 .name =
"Power of two block reads",
2406 .prepare = mmc_test_prepare_read,
2407 .run = mmc_test_pow2_read,
2408 .cleanup = mmc_test_cleanup,
2412 .name =
"Weird sized block writes",
2413 .prepare = mmc_test_prepare_write,
2414 .run = mmc_test_weird_write,
2415 .cleanup = mmc_test_cleanup,
2419 .name =
"Weird sized block reads",
2420 .prepare = mmc_test_prepare_read,
2421 .run = mmc_test_weird_read,
2422 .cleanup = mmc_test_cleanup,
2426 .name =
"Badly aligned write",
2427 .prepare = mmc_test_prepare_write,
2428 .run = mmc_test_align_write,
2429 .cleanup = mmc_test_cleanup,
2433 .name =
"Badly aligned read",
2434 .prepare = mmc_test_prepare_read,
2435 .run = mmc_test_align_read,
2436 .cleanup = mmc_test_cleanup,
2440 .name =
"Badly aligned multi-block write",
2441 .prepare = mmc_test_prepare_write,
2442 .run = mmc_test_align_multi_write,
2443 .cleanup = mmc_test_cleanup,
2447 .name =
"Badly aligned multi-block read",
2448 .prepare = mmc_test_prepare_read,
2449 .run = mmc_test_align_multi_read,
2450 .cleanup = mmc_test_cleanup,
2454 .name =
"Correct xfer_size at write (start failure)",
2455 .run = mmc_test_xfersize_write,
2459 .name =
"Correct xfer_size at read (start failure)",
2460 .run = mmc_test_xfersize_read,
2464 .name =
"Correct xfer_size at write (midway failure)",
2465 .run = mmc_test_multi_xfersize_write,
2469 .name =
"Correct xfer_size at read (midway failure)",
2470 .run = mmc_test_multi_xfersize_read,
2473 #ifdef CONFIG_HIGHMEM
2476 .name =
"Highmem write",
2477 .prepare = mmc_test_prepare_write,
2478 .run = mmc_test_write_high,
2479 .cleanup = mmc_test_cleanup,
2483 .name =
"Highmem read",
2484 .prepare = mmc_test_prepare_read,
2485 .run = mmc_test_read_high,
2486 .cleanup = mmc_test_cleanup,
2490 .name =
"Multi-block highmem write",
2491 .prepare = mmc_test_prepare_write,
2492 .run = mmc_test_multi_write_high,
2493 .cleanup = mmc_test_cleanup,
2497 .name =
"Multi-block highmem read",
2498 .prepare = mmc_test_prepare_read,
2499 .run = mmc_test_multi_read_high,
2500 .cleanup = mmc_test_cleanup,
2506 .name =
"Highmem write",
2507 .run = mmc_test_no_highmem,
2511 .name =
"Highmem read",
2512 .run = mmc_test_no_highmem,
2516 .name =
"Multi-block highmem write",
2517 .run = mmc_test_no_highmem,
2521 .name =
"Multi-block highmem read",
2522 .run = mmc_test_no_highmem,
2528 .name =
"Best-case read performance",
2529 .prepare = mmc_test_area_prepare_fill,
2530 .run = mmc_test_best_read_performance,
2531 .cleanup = mmc_test_area_cleanup,
2535 .name =
"Best-case write performance",
2536 .prepare = mmc_test_area_prepare_erase,
2537 .run = mmc_test_best_write_performance,
2538 .cleanup = mmc_test_area_cleanup,
2542 .name =
"Best-case read performance into scattered pages",
2543 .prepare = mmc_test_area_prepare_fill,
2544 .run = mmc_test_best_read_perf_max_scatter,
2545 .cleanup = mmc_test_area_cleanup,
2549 .name =
"Best-case write performance from scattered pages",
2550 .prepare = mmc_test_area_prepare_erase,
2551 .run = mmc_test_best_write_perf_max_scatter,
2552 .cleanup = mmc_test_area_cleanup,
2556 .name =
"Single read performance by transfer size",
2557 .prepare = mmc_test_area_prepare_fill,
2558 .run = mmc_test_profile_read_perf,
2559 .cleanup = mmc_test_area_cleanup,
2563 .name =
"Single write performance by transfer size",
2564 .prepare = mmc_test_area_prepare,
2565 .run = mmc_test_profile_write_perf,
2566 .cleanup = mmc_test_area_cleanup,
2570 .name =
"Single trim performance by transfer size",
2571 .prepare = mmc_test_area_prepare_fill,
2572 .run = mmc_test_profile_trim_perf,
2573 .cleanup = mmc_test_area_cleanup,
2577 .name =
"Consecutive read performance by transfer size",
2578 .prepare = mmc_test_area_prepare_fill,
2579 .run = mmc_test_profile_seq_read_perf,
2580 .cleanup = mmc_test_area_cleanup,
2584 .name =
"Consecutive write performance by transfer size",
2585 .prepare = mmc_test_area_prepare,
2586 .run = mmc_test_profile_seq_write_perf,
2587 .cleanup = mmc_test_area_cleanup,
2591 .name =
"Consecutive trim performance by transfer size",
2592 .prepare = mmc_test_area_prepare,
2593 .run = mmc_test_profile_seq_trim_perf,
2594 .cleanup = mmc_test_area_cleanup,
2598 .name =
"Random read performance by transfer size",
2599 .prepare = mmc_test_area_prepare,
2600 .run = mmc_test_random_read_perf,
2601 .cleanup = mmc_test_area_cleanup,
2605 .name =
"Random write performance by transfer size",
2606 .prepare = mmc_test_area_prepare,
2607 .run = mmc_test_random_write_perf,
2608 .cleanup = mmc_test_area_cleanup,
2612 .name =
"Large sequential read into scattered pages",
2613 .prepare = mmc_test_area_prepare,
2614 .run = mmc_test_large_seq_read_perf,
2615 .cleanup = mmc_test_area_cleanup,
2619 .name =
"Large sequential write from scattered pages",
2620 .prepare = mmc_test_area_prepare,
2621 .run = mmc_test_large_seq_write_perf,
2622 .cleanup = mmc_test_area_cleanup,
2626 .name =
"Write performance with blocking req 4k to 4MB",
2627 .prepare = mmc_test_area_prepare,
2628 .run = mmc_test_profile_mult_write_blocking_perf,
2629 .cleanup = mmc_test_area_cleanup,
2633 .name =
"Write performance with non-blocking req 4k to 4MB",
2634 .prepare = mmc_test_area_prepare,
2635 .run = mmc_test_profile_mult_write_nonblock_perf,
2636 .cleanup = mmc_test_area_cleanup,
2640 .name =
"Read performance with blocking req 4k to 4MB",
2641 .prepare = mmc_test_area_prepare,
2642 .run = mmc_test_profile_mult_read_blocking_perf,
2643 .cleanup = mmc_test_area_cleanup,
2647 .name =
"Read performance with non-blocking req 4k to 4MB",
2648 .prepare = mmc_test_area_prepare,
2649 .run = mmc_test_profile_mult_read_nonblock_perf,
2650 .cleanup = mmc_test_area_cleanup,
2654 .name =
"Write performance blocking req 1 to 512 sg elems",
2655 .prepare = mmc_test_area_prepare,
2656 .run = mmc_test_profile_sglen_wr_blocking_perf,
2657 .cleanup = mmc_test_area_cleanup,
2661 .name =
"Write performance non-blocking req 1 to 512 sg elems",
2662 .prepare = mmc_test_area_prepare,
2663 .run = mmc_test_profile_sglen_wr_nonblock_perf,
2664 .cleanup = mmc_test_area_cleanup,
2668 .name =
"Read performance blocking req 1 to 512 sg elems",
2669 .prepare = mmc_test_area_prepare,
2670 .run = mmc_test_profile_sglen_r_blocking_perf,
2671 .cleanup = mmc_test_area_cleanup,
2675 .name =
"Read performance non-blocking req 1 to 512 sg elems",
2676 .prepare = mmc_test_area_prepare,
2677 .run = mmc_test_profile_sglen_r_nonblock_perf,
2678 .cleanup = mmc_test_area_cleanup,
2682 .name =
"eMMC hardware reset",
2683 .run = mmc_test_hw_reset,
2691 static void mmc_test_run(
struct mmc_test_card *test,
int testcase)
2695 pr_info(
"%s: Starting tests of card %s...\n",
2698 mmc_claim_host(test->
card->host);
2700 for (i = 0;i <
ARRAY_SIZE(mmc_test_cases);i++) {
2703 if (testcase && ((i + 1) != testcase))
2706 pr_info(
"%s: Test case %d. %s...\n",
2708 mmc_test_cases[i].
name);
2710 if (mmc_test_cases[i].prepare) {
2711 ret = mmc_test_cases[
i].
prepare(test);
2713 pr_info(
"%s: Result: Prepare "
2714 "stage failed! (%d)\n",
2724 INIT_LIST_HEAD(&gr->
tr_lst);
2740 ret = mmc_test_cases[
i].
run(test);
2747 pr_info(
"%s: Result: FAILED\n",
2751 pr_info(
"%s: Result: UNSUPPORTED "
2756 pr_info(
"%s: Result: UNSUPPORTED "
2761 pr_info(
"%s: Result: ERROR (%d)\n",
2769 if (mmc_test_cases[i].cleanup) {
2770 ret = mmc_test_cases[
i].
cleanup(test);
2772 pr_info(
"%s: Warning: Cleanup "
2773 "stage failed! (%d)\n",
2782 pr_info(
"%s: Tests completed.\n",
2786 static void mmc_test_free_result(
struct mmc_card *card)
2795 if (card && gr->
card != card)
2812 static int mtf_test_show(
struct seq_file *
sf,
void *data)
2822 if (gr->
card != card)
2828 seq_printf(sf,
"%u %d %lu.%09lu %u %u.%02u\n",
2830 (
unsigned long)tr->
ts.tv_sec,
2831 (
unsigned long)tr->
ts.tv_nsec,
2847 size_t count, loff_t *
pos)
2855 if (count >=
sizeof(lbuf))
2873 mmc_test_free_result(card);
2878 #ifdef CONFIG_HIGHMEM
2882 #ifdef CONFIG_HIGHMEM
2883 if (test->
buffer && test->highmem) {
2888 mmc_test_run(test, testcase);
2892 #ifdef CONFIG_HIGHMEM
2902 .open = mtf_test_open,
2904 .write = mtf_test_write,
2909 static int mtf_testlist_show(
struct seq_file *sf,
void *data)
2915 for (i = 0; i <
ARRAY_SIZE(mmc_test_cases); i++)
2923 static int mtf_testlist_open(
struct inode *
inode,
struct file *file)
2929 .open = mtf_testlist_open,
2935 static void mmc_test_free_dbgfs_file(
struct mmc_card *card)
2942 if (card && df->
card != card)
2952 static int __mmc_test_register_dbgfs_file(
struct mmc_card *card,
2962 if (IS_ERR_OR_NULL(file)) {
2964 "Can't create %s. Perhaps debugfs is disabled.\n",
2973 "Can't allocate memory for internal usage.\n");
2980 list_add(&df->
link, &mmc_test_file_test);
2984 static int mmc_test_register_dbgfs_file(
struct mmc_card *card)
2990 ret = __mmc_test_register_dbgfs_file(card,
"test",
S_IWUSR |
S_IRUGO,
2991 &mmc_test_fops_test);
2995 ret = __mmc_test_register_dbgfs_file(card,
"testlist",
S_IRUGO,
2996 &mmc_test_fops_testlist);
3006 static int mmc_test_probe(
struct mmc_card *card)
3013 ret = mmc_test_register_dbgfs_file(card);
3017 dev_info(&card->
dev,
"Card claimed for testing.\n");
3022 static void mmc_test_remove(
struct mmc_card *card)
3024 mmc_test_free_result(card);
3025 mmc_test_free_dbgfs_file(card);
3032 .probe = mmc_test_probe,
3033 .remove = mmc_test_remove,
3036 static int __init mmc_test_init(
void)
3041 static void __exit mmc_test_exit(
void)
3044 mmc_test_free_result(
NULL);
3045 mmc_test_free_dbgfs_file(
NULL);