~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise-security

« back to all changes in this revision

Viewing changes to drivers/mmc/card/mmc_test.c

  • Committer: Package Import Robot
  • Author(s): Paolo Pisati, Paolo Pisati
  • Date: 2011-12-06 15:56:07 UTC
  • Revision ID: package-import@ubuntu.com-20111206155607-pcf44kv5fmhk564f
Tags: 3.2.0-1401.1
[ Paolo Pisati ]

* Rebased on top of Ubuntu-3.2.0-3.8
* Tilt-tracking @ ef2487af4bb15bdd0689631774b5a5e3a59f74e2
* Delete debian.ti-omap4/control, it shoudln't be tracked
* Fix architecture spelling (s/armel/armhf/)
* [Config] Update configs following 3.2 import
* [Config] Fix compilation: disable CODA and ARCH_OMAP3
* [Config] Fix compilation: disable Ethernet Faraday
* Update series to precise

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <linux/debugfs.h>
23
23
#include <linux/uaccess.h>
24
24
#include <linux/seq_file.h>
 
25
#include <linux/module.h>
25
26
 
26
27
#define RESULT_OK               0
27
28
#define RESULT_FAIL             1
148
149
        struct mmc_test_general_result  *gr;
149
150
};
150
151
 
 
152
enum mmc_test_prep_media {
 
153
        MMC_TEST_PREP_NONE = 0,
 
154
        MMC_TEST_PREP_WRITE_FULL = 1 << 0,
 
155
        MMC_TEST_PREP_ERASE = 1 << 1,
 
156
};
 
157
 
 
158
struct mmc_test_multiple_rw {
 
159
        unsigned int *sg_len;
 
160
        unsigned int *bs;
 
161
        unsigned int len;
 
162
        unsigned int size;
 
163
        bool do_write;
 
164
        bool do_nonblock_req;
 
165
        enum mmc_test_prep_media prepare;
 
166
};
 
167
 
 
168
struct mmc_test_async_req {
 
169
        struct mmc_async_req areq;
 
170
        struct mmc_test_card *test;
 
171
};
 
172
 
151
173
/*******************************************************************/
152
174
/*  General helper functions                                       */
153
175
/*******************************************************************/
203
225
static int mmc_test_busy(struct mmc_command *cmd)
204
226
{
205
227
        return !(cmd->resp[0] & R1_READY_FOR_DATA) ||
206
 
                (R1_CURRENT_STATE(cmd->resp[0]) == 7);
 
228
                (R1_CURRENT_STATE(cmd->resp[0]) == R1_STATE_PRG);
207
229
}
208
230
 
209
231
/*
229
251
                if (!busy && mmc_test_busy(&cmd)) {
230
252
                        busy = 1;
231
253
                        if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
232
 
                                printk(KERN_INFO "%s: Warning: Host did not "
 
254
                                pr_info("%s: Warning: Host did not "
233
255
                                        "wait for busy state to end.\n",
234
256
                                        mmc_hostname(test->card->host));
235
257
                }
367
389
 * Map memory into a scatterlist.  Optionally allow the same memory to be
368
390
 * mapped more than once.
369
391
 */
370
 
static int mmc_test_map_sg(struct mmc_test_mem *mem, unsigned long sz,
 
392
static int mmc_test_map_sg(struct mmc_test_mem *mem, unsigned long size,
371
393
                           struct scatterlist *sglist, int repeat,
372
394
                           unsigned int max_segs, unsigned int max_seg_sz,
373
 
                           unsigned int *sg_len)
 
395
                           unsigned int *sg_len, int min_sg_len)
374
396
{
375
397
        struct scatterlist *sg = NULL;
376
398
        unsigned int i;
 
399
        unsigned long sz = size;
377
400
 
378
401
        sg_init_table(sglist, max_segs);
 
402
        if (min_sg_len > max_segs)
 
403
                min_sg_len = max_segs;
379
404
 
380
405
        *sg_len = 0;
381
406
        do {
382
407
                for (i = 0; i < mem->cnt; i++) {
383
408
                        unsigned long len = PAGE_SIZE << mem->arr[i].order;
384
409
 
 
410
                        if (min_sg_len && (size / min_sg_len < len))
 
411
                                len = ALIGN(size / min_sg_len, 512);
385
412
                        if (len > sz)
386
413
                                len = sz;
387
414
                        if (len > max_seg_sz)
526
553
        rate = mmc_test_rate(bytes, &ts);
527
554
        iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
528
555
 
529
 
        printk(KERN_INFO "%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
 
556
        pr_info("%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
530
557
                         "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
531
558
                         mmc_hostname(test->card->host), sectors, sectors >> 1,
532
559
                         (sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
552
579
        rate = mmc_test_rate(tot, &ts);
553
580
        iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
554
581
 
555
 
        printk(KERN_INFO "%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
 
582
        pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
556
583
                         "%lu.%09lu seconds (%u kB/s, %u KiB/s, "
557
 
                         "%u.%02u IOPS)\n",
 
584
                         "%u.%02u IOPS, sg_len %d)\n",
558
585
                         mmc_hostname(test->card->host), count, sectors, count,
559
586
                         sectors >> 1, (sectors & 1 ? ".5" : ""),
560
587
                         (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec,
561
 
                         rate / 1000, rate / 1024, iops / 100, iops % 100);
 
588
                         rate / 1000, rate / 1024, iops / 100, iops % 100,
 
589
                         test->area.sg_len);
562
590
 
563
591
        mmc_test_save_transfer_result(test, count, sectors, ts, rate, iops);
564
592
}
661
689
 * Checks that a normal transfer didn't have any errors
662
690
 */
663
691
static int mmc_test_check_result(struct mmc_test_card *test,
664
 
        struct mmc_request *mrq)
 
692
                                 struct mmc_request *mrq)
665
693
{
666
694
        int ret;
667
695
 
685
713
        return ret;
686
714
}
687
715
 
 
716
static int mmc_test_check_result_async(struct mmc_card *card,
 
717
                                       struct mmc_async_req *areq)
 
718
{
 
719
        struct mmc_test_async_req *test_async =
 
720
                container_of(areq, struct mmc_test_async_req, areq);
 
721
 
 
722
        mmc_test_wait_busy(test_async->test);
 
723
 
 
724
        return mmc_test_check_result(test_async->test, areq->mrq);
 
725
}
 
726
 
688
727
/*
689
728
 * Checks that a "short transfer" behaved as expected
690
729
 */
720
759
}
721
760
 
722
761
/*
 
762
 * Tests nonblock transfer with certain parameters
 
763
 */
 
764
static void mmc_test_nonblock_reset(struct mmc_request *mrq,
 
765
                                    struct mmc_command *cmd,
 
766
                                    struct mmc_command *stop,
 
767
                                    struct mmc_data *data)
 
768
{
 
769
        memset(mrq, 0, sizeof(struct mmc_request));
 
770
        memset(cmd, 0, sizeof(struct mmc_command));
 
771
        memset(data, 0, sizeof(struct mmc_data));
 
772
        memset(stop, 0, sizeof(struct mmc_command));
 
773
 
 
774
        mrq->cmd = cmd;
 
775
        mrq->data = data;
 
776
        mrq->stop = stop;
 
777
}
 
778
static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
 
779
                                      struct scatterlist *sg, unsigned sg_len,
 
780
                                      unsigned dev_addr, unsigned blocks,
 
781
                                      unsigned blksz, int write, int count)
 
782
{
 
783
        struct mmc_request mrq1;
 
784
        struct mmc_command cmd1;
 
785
        struct mmc_command stop1;
 
786
        struct mmc_data data1;
 
787
 
 
788
        struct mmc_request mrq2;
 
789
        struct mmc_command cmd2;
 
790
        struct mmc_command stop2;
 
791
        struct mmc_data data2;
 
792
 
 
793
        struct mmc_test_async_req test_areq[2];
 
794
        struct mmc_async_req *done_areq;
 
795
        struct mmc_async_req *cur_areq = &test_areq[0].areq;
 
796
        struct mmc_async_req *other_areq = &test_areq[1].areq;
 
797
        int i;
 
798
        int ret;
 
799
 
 
800
        test_areq[0].test = test;
 
801
        test_areq[1].test = test;
 
802
 
 
803
        mmc_test_nonblock_reset(&mrq1, &cmd1, &stop1, &data1);
 
804
        mmc_test_nonblock_reset(&mrq2, &cmd2, &stop2, &data2);
 
805
 
 
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;
 
810
 
 
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);
 
814
                done_areq = mmc_start_req(test->card->host, cur_areq, &ret);
 
815
 
 
816
                if (ret || (!done_areq && i > 0))
 
817
                        goto err;
 
818
 
 
819
                if (done_areq) {
 
820
                        if (done_areq->mrq == &mrq2)
 
821
                                mmc_test_nonblock_reset(&mrq2, &cmd2,
 
822
                                                        &stop2, &data2);
 
823
                        else
 
824
                                mmc_test_nonblock_reset(&mrq1, &cmd1,
 
825
                                                        &stop1, &data1);
 
826
                }
 
827
                done_areq = cur_areq;
 
828
                cur_areq = other_areq;
 
829
                other_areq = done_areq;
 
830
                dev_addr += blocks;
 
831
        }
 
832
 
 
833
        done_areq = mmc_start_req(test->card->host, NULL, &ret);
 
834
 
 
835
        return ret;
 
836
err:
 
837
        return ret;
 
838
}
 
839
 
 
840
/*
723
841
 * Tests a basic transfer with certain parameters
724
842
 */
725
843
static int mmc_test_simple_transfer(struct mmc_test_card *test,
1291
1409
 
1292
1410
static int mmc_test_no_highmem(struct mmc_test_card *test)
1293
1411
{
1294
 
        printk(KERN_INFO "%s: Highmem not configured - test skipped\n",
 
1412
        pr_info("%s: Highmem not configured - test skipped\n",
1295
1413
               mmc_hostname(test->card->host));
1296
1414
        return 0;
1297
1415
}
1302
1420
 * Map sz bytes so that it can be transferred.
1303
1421
 */
1304
1422
static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
1305
 
                             int max_scatter)
 
1423
                             int max_scatter, int min_sg_len)
1306
1424
{
1307
1425
        struct mmc_test_area *t = &test->area;
1308
1426
        int err;
1315
1433
                                       &t->sg_len);
1316
1434
        } else {
1317
1435
                err = mmc_test_map_sg(t->mem, sz, t->sg, 1, t->max_segs,
1318
 
                                      t->max_seg_sz, &t->sg_len);
 
1436
                                      t->max_seg_sz, &t->sg_len, min_sg_len);
1319
1437
        }
1320
1438
        if (err)
1321
 
                printk(KERN_INFO "%s: Failed to map sg list\n",
 
1439
                pr_info("%s: Failed to map sg list\n",
1322
1440
                       mmc_hostname(test->card->host));
1323
1441
        return err;
1324
1442
}
1336
1454
}
1337
1455
 
1338
1456
/*
1339
 
 * Map and transfer bytes.
 
1457
 * Map and transfer bytes for multiple transfers.
1340
1458
 */
 
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)
 
1463
{
 
1464
        struct timespec ts1, ts2;
 
1465
        int ret = 0;
 
1466
        int i;
 
1467
        struct mmc_test_area *t = &test->area;
 
1468
 
 
1469
        /*
 
1470
         * In the case of a maximally scattered transfer, the maximum transfer
 
1471
         * size is further limited by using PAGE_SIZE segments.
 
1472
         */
 
1473
        if (max_scatter) {
 
1474
                struct mmc_test_area *t = &test->area;
 
1475
                unsigned long max_tfr;
 
1476
 
 
1477
                if (t->max_seg_sz >= PAGE_SIZE)
 
1478
                        max_tfr = t->max_segs * PAGE_SIZE;
 
1479
                else
 
1480
                        max_tfr = t->max_segs * t->max_seg_sz;
 
1481
                if (sz > max_tfr)
 
1482
                        sz = max_tfr;
 
1483
        }
 
1484
 
 
1485
        ret = mmc_test_area_map(test, sz, max_scatter, min_sg_len);
 
1486
        if (ret)
 
1487
                return ret;
 
1488
 
 
1489
        if (timed)
 
1490
                getnstimeofday(&ts1);
 
1491
        if (nonblock)
 
1492
                ret = mmc_test_nonblock_transfer(test, t->sg, t->sg_len,
 
1493
                                 dev_addr, t->blocks, 512, write, count);
 
1494
        else
 
1495
                for (i = 0; i < count && ret == 0; i++) {
 
1496
                        ret = mmc_test_area_transfer(test, dev_addr, write);
 
1497
                        dev_addr += sz >> 9;
 
1498
                }
 
1499
 
 
1500
        if (ret)
 
1501
                return ret;
 
1502
 
 
1503
        if (timed)
 
1504
                getnstimeofday(&ts2);
 
1505
 
 
1506
        if (timed)
 
1507
                mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2);
 
1508
 
 
1509
        return 0;
 
1510
}
 
1511
 
1341
1512
static int mmc_test_area_io(struct mmc_test_card *test, unsigned long sz,
1342
1513
                            unsigned int dev_addr, int write, int max_scatter,
1343
1514
                            int timed)
1344
1515
{
1345
 
        struct timespec ts1, ts2;
1346
 
        int ret;
1347
 
 
1348
 
        /*
1349
 
         * In the case of a maximally scattered transfer, the maximum transfer
1350
 
         * size is further limited by using PAGE_SIZE segments.
1351
 
         */
1352
 
        if (max_scatter) {
1353
 
                struct mmc_test_area *t = &test->area;
1354
 
                unsigned long max_tfr;
1355
 
 
1356
 
                if (t->max_seg_sz >= PAGE_SIZE)
1357
 
                        max_tfr = t->max_segs * PAGE_SIZE;
1358
 
                else
1359
 
                        max_tfr = t->max_segs * t->max_seg_sz;
1360
 
                if (sz > max_tfr)
1361
 
                        sz = max_tfr;
1362
 
        }
1363
 
 
1364
 
        ret = mmc_test_area_map(test, sz, max_scatter);
1365
 
        if (ret)
1366
 
                return ret;
1367
 
 
1368
 
        if (timed)
1369
 
                getnstimeofday(&ts1);
1370
 
 
1371
 
        ret = mmc_test_area_transfer(test, dev_addr, write);
1372
 
        if (ret)
1373
 
                return ret;
1374
 
 
1375
 
        if (timed)
1376
 
                getnstimeofday(&ts2);
1377
 
 
1378
 
        if (timed)
1379
 
                mmc_test_print_rate(test, sz, &ts1, &ts2);
1380
 
 
1381
 
        return 0;
 
1516
        return mmc_test_area_io_seq(test, sz, dev_addr, write, max_scatter,
 
1517
                                    timed, 1, false, 0);
1382
1518
}
1383
1519
 
1384
1520
/*
1954
2090
        return mmc_test_large_seq_perf(test, 1);
1955
2091
}
1956
2092
 
 
2093
static int mmc_test_rw_multiple(struct mmc_test_card *test,
 
2094
                                struct mmc_test_multiple_rw *tdata,
 
2095
                                unsigned int reqsize, unsigned int size,
 
2096
                                int min_sg_len)
 
2097
{
 
2098
        unsigned int dev_addr;
 
2099
        struct mmc_test_area *t = &test->area;
 
2100
        int ret = 0;
 
2101
 
 
2102
        /* Set up test area */
 
2103
        if (size > mmc_test_capacity(test->card) / 2 * 512)
 
2104
                size = mmc_test_capacity(test->card) / 2 * 512;
 
2105
        if (reqsize > t->max_tfr)
 
2106
                reqsize = t->max_tfr;
 
2107
        dev_addr = mmc_test_capacity(test->card) / 4;
 
2108
        if ((dev_addr & 0xffff0000))
 
2109
                dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
 
2110
        else
 
2111
                dev_addr &= 0xfffff800; /* Round to 1MiB boundary */
 
2112
        if (!dev_addr)
 
2113
                goto err;
 
2114
 
 
2115
        if (reqsize > size)
 
2116
                return 0;
 
2117
 
 
2118
        /* prepare test area */
 
2119
        if (mmc_can_erase(test->card) &&
 
2120
            tdata->prepare & MMC_TEST_PREP_ERASE) {
 
2121
                ret = mmc_erase(test->card, dev_addr,
 
2122
                                size / 512, MMC_SECURE_ERASE_ARG);
 
2123
                if (ret)
 
2124
                        ret = mmc_erase(test->card, dev_addr,
 
2125
                                        size / 512, MMC_ERASE_ARG);
 
2126
                if (ret)
 
2127
                        goto err;
 
2128
        }
 
2129
 
 
2130
        /* Run test */
 
2131
        ret = mmc_test_area_io_seq(test, reqsize, dev_addr,
 
2132
                                   tdata->do_write, 0, 1, size / reqsize,
 
2133
                                   tdata->do_nonblock_req, min_sg_len);
 
2134
        if (ret)
 
2135
                goto err;
 
2136
 
 
2137
        return ret;
 
2138
 err:
 
2139
        pr_info("[%s] error\n", __func__);
 
2140
        return ret;
 
2141
}
 
2142
 
 
2143
static int mmc_test_rw_multiple_size(struct mmc_test_card *test,
 
2144
                                     struct mmc_test_multiple_rw *rw)
 
2145
{
 
2146
        int ret = 0;
 
2147
        int i;
 
2148
        void *pre_req = test->card->host->ops->pre_req;
 
2149
        void *post_req = test->card->host->ops->post_req;
 
2150
 
 
2151
        if (rw->do_nonblock_req &&
 
2152
            ((!pre_req && post_req) || (pre_req && !post_req))) {
 
2153
                pr_info("error: only one of pre/post is defined\n");
 
2154
                return -EINVAL;
 
2155
        }
 
2156
 
 
2157
        for (i = 0 ; i < rw->len && ret == 0; i++) {
 
2158
                ret = mmc_test_rw_multiple(test, rw, rw->bs[i], rw->size, 0);
 
2159
                if (ret)
 
2160
                        break;
 
2161
        }
 
2162
        return ret;
 
2163
}
 
2164
 
 
2165
static int mmc_test_rw_multiple_sg_len(struct mmc_test_card *test,
 
2166
                                       struct mmc_test_multiple_rw *rw)
 
2167
{
 
2168
        int ret = 0;
 
2169
        int i;
 
2170
 
 
2171
        for (i = 0 ; i < rw->len && ret == 0; i++) {
 
2172
                ret = mmc_test_rw_multiple(test, rw, 512*1024, rw->size,
 
2173
                                           rw->sg_len[i]);
 
2174
                if (ret)
 
2175
                        break;
 
2176
        }
 
2177
        return ret;
 
2178
}
 
2179
 
 
2180
/*
 
2181
 * Multiple blocking write 4k to 4 MB chunks
 
2182
 */
 
2183
static int mmc_test_profile_mult_write_blocking_perf(struct mmc_test_card *test)
 
2184
{
 
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 = false,
 
2193
                .prepare = MMC_TEST_PREP_ERASE,
 
2194
        };
 
2195
 
 
2196
        return mmc_test_rw_multiple_size(test, &test_data);
 
2197
};
 
2198
 
 
2199
/*
 
2200
 * Multiple non-blocking write 4k to 4 MB chunks
 
2201
 */
 
2202
static int mmc_test_profile_mult_write_nonblock_perf(struct mmc_test_card *test)
 
2203
{
 
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 = true,
 
2211
                .do_nonblock_req = true,
 
2212
                .prepare = MMC_TEST_PREP_ERASE,
 
2213
        };
 
2214
 
 
2215
        return mmc_test_rw_multiple_size(test, &test_data);
 
2216
}
 
2217
 
 
2218
/*
 
2219
 * Multiple blocking read 4k to 4 MB chunks
 
2220
 */
 
2221
static int mmc_test_profile_mult_read_blocking_perf(struct mmc_test_card *test)
 
2222
{
 
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 = false,
 
2231
                .prepare = MMC_TEST_PREP_NONE,
 
2232
        };
 
2233
 
 
2234
        return mmc_test_rw_multiple_size(test, &test_data);
 
2235
}
 
2236
 
 
2237
/*
 
2238
 * Multiple non-blocking read 4k to 4 MB chunks
 
2239
 */
 
2240
static int mmc_test_profile_mult_read_nonblock_perf(struct mmc_test_card *test)
 
2241
{
 
2242
        unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
 
2243
                             1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
 
2244
        struct mmc_test_multiple_rw test_data = {
 
2245
                .bs = bs,
 
2246
                .size = TEST_AREA_MAX_SIZE,
 
2247
                .len = ARRAY_SIZE(bs),
 
2248
                .do_write = false,
 
2249
                .do_nonblock_req = true,
 
2250
                .prepare = MMC_TEST_PREP_NONE,
 
2251
        };
 
2252
 
 
2253
        return mmc_test_rw_multiple_size(test, &test_data);
 
2254
}
 
2255
 
 
2256
/*
 
2257
 * Multiple blocking write 1 to 512 sg elements
 
2258
 */
 
2259
static int mmc_test_profile_sglen_wr_blocking_perf(struct mmc_test_card *test)
 
2260
{
 
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 = false,
 
2269
                .prepare = MMC_TEST_PREP_ERASE,
 
2270
        };
 
2271
 
 
2272
        return mmc_test_rw_multiple_sg_len(test, &test_data);
 
2273
};
 
2274
 
 
2275
/*
 
2276
 * Multiple non-blocking write 1 to 512 sg elements
 
2277
 */
 
2278
static int mmc_test_profile_sglen_wr_nonblock_perf(struct mmc_test_card *test)
 
2279
{
 
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 = true,
 
2287
                .do_nonblock_req = true,
 
2288
                .prepare = MMC_TEST_PREP_ERASE,
 
2289
        };
 
2290
 
 
2291
        return mmc_test_rw_multiple_sg_len(test, &test_data);
 
2292
}
 
2293
 
 
2294
/*
 
2295
 * Multiple blocking read 1 to 512 sg elements
 
2296
 */
 
2297
static int mmc_test_profile_sglen_r_blocking_perf(struct mmc_test_card *test)
 
2298
{
 
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 = false,
 
2307
                .prepare = MMC_TEST_PREP_NONE,
 
2308
        };
 
2309
 
 
2310
        return mmc_test_rw_multiple_sg_len(test, &test_data);
 
2311
}
 
2312
 
 
2313
/*
 
2314
 * Multiple non-blocking read 1 to 512 sg elements
 
2315
 */
 
2316
static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card *test)
 
2317
{
 
2318
        unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
 
2319
                                 1 << 7, 1 << 8, 1 << 9};
 
2320
        struct mmc_test_multiple_rw test_data = {
 
2321
                .sg_len = sg_len,
 
2322
                .size = TEST_AREA_MAX_SIZE,
 
2323
                .len = ARRAY_SIZE(sg_len),
 
2324
                .do_write = false,
 
2325
                .do_nonblock_req = true,
 
2326
                .prepare = MMC_TEST_PREP_NONE,
 
2327
        };
 
2328
 
 
2329
        return mmc_test_rw_multiple_sg_len(test, &test_data);
 
2330
}
 
2331
 
 
2332
/*
 
2333
 * eMMC hardware reset.
 
2334
 */
 
2335
static int mmc_test_hw_reset(struct mmc_test_card *test)
 
2336
{
 
2337
        struct mmc_card *card = test->card;
 
2338
        struct mmc_host *host = card->host;
 
2339
        int err;
 
2340
 
 
2341
        err = mmc_hw_reset_check(host);
 
2342
        if (!err)
 
2343
                return RESULT_OK;
 
2344
 
 
2345
        if (err == -ENOSYS)
 
2346
                return RESULT_FAIL;
 
2347
 
 
2348
        if (err != -EOPNOTSUPP)
 
2349
                return err;
 
2350
 
 
2351
        if (!mmc_can_reset(card))
 
2352
                return RESULT_UNSUP_CARD;
 
2353
 
 
2354
        return RESULT_UNSUP_HOST;
 
2355
}
 
2356
 
1957
2357
static const struct mmc_test_case mmc_test_cases[] = {
1958
2358
        {
1959
2359
                .name = "Basic write (no data verification)",
2221
2621
                .cleanup = mmc_test_area_cleanup,
2222
2622
        },
2223
2623
 
 
2624
        {
 
2625
                .name = "Write performance with blocking req 4k to 4MB",
 
2626
                .prepare = mmc_test_area_prepare,
 
2627
                .run = mmc_test_profile_mult_write_blocking_perf,
 
2628
                .cleanup = mmc_test_area_cleanup,
 
2629
        },
 
2630
 
 
2631
        {
 
2632
                .name = "Write performance with non-blocking req 4k to 4MB",
 
2633
                .prepare = mmc_test_area_prepare,
 
2634
                .run = mmc_test_profile_mult_write_nonblock_perf,
 
2635
                .cleanup = mmc_test_area_cleanup,
 
2636
        },
 
2637
 
 
2638
        {
 
2639
                .name = "Read performance with blocking req 4k to 4MB",
 
2640
                .prepare = mmc_test_area_prepare,
 
2641
                .run = mmc_test_profile_mult_read_blocking_perf,
 
2642
                .cleanup = mmc_test_area_cleanup,
 
2643
        },
 
2644
 
 
2645
        {
 
2646
                .name = "Read performance with non-blocking req 4k to 4MB",
 
2647
                .prepare = mmc_test_area_prepare,
 
2648
                .run = mmc_test_profile_mult_read_nonblock_perf,
 
2649
                .cleanup = mmc_test_area_cleanup,
 
2650
        },
 
2651
 
 
2652
        {
 
2653
                .name = "Write performance blocking req 1 to 512 sg elems",
 
2654
                .prepare = mmc_test_area_prepare,
 
2655
                .run = mmc_test_profile_sglen_wr_blocking_perf,
 
2656
                .cleanup = mmc_test_area_cleanup,
 
2657
        },
 
2658
 
 
2659
        {
 
2660
                .name = "Write performance non-blocking req 1 to 512 sg elems",
 
2661
                .prepare = mmc_test_area_prepare,
 
2662
                .run = mmc_test_profile_sglen_wr_nonblock_perf,
 
2663
                .cleanup = mmc_test_area_cleanup,
 
2664
        },
 
2665
 
 
2666
        {
 
2667
                .name = "Read performance blocking req 1 to 512 sg elems",
 
2668
                .prepare = mmc_test_area_prepare,
 
2669
                .run = mmc_test_profile_sglen_r_blocking_perf,
 
2670
                .cleanup = mmc_test_area_cleanup,
 
2671
        },
 
2672
 
 
2673
        {
 
2674
                .name = "Read performance non-blocking req 1 to 512 sg elems",
 
2675
                .prepare = mmc_test_area_prepare,
 
2676
                .run = mmc_test_profile_sglen_r_nonblock_perf,
 
2677
                .cleanup = mmc_test_area_cleanup,
 
2678
        },
 
2679
 
 
2680
        {
 
2681
                .name = "eMMC hardware reset",
 
2682
                .run = mmc_test_hw_reset,
 
2683
        },
2224
2684
};
2225
2685
 
2226
2686
static DEFINE_MUTEX(mmc_test_lock);
2231
2691
{
2232
2692
        int i, ret;
2233
2693
 
2234
 
        printk(KERN_INFO "%s: Starting tests of card %s...\n",
 
2694
        pr_info("%s: Starting tests of card %s...\n",
2235
2695
                mmc_hostname(test->card->host), mmc_card_id(test->card));
2236
2696
 
2237
2697
        mmc_claim_host(test->card->host);
2242
2702
                if (testcase && ((i + 1) != testcase))
2243
2703
                        continue;
2244
2704
 
2245
 
                printk(KERN_INFO "%s: Test case %d. %s...\n",
 
2705
                pr_info("%s: Test case %d. %s...\n",
2246
2706
                        mmc_hostname(test->card->host), i + 1,
2247
2707
                        mmc_test_cases[i].name);
2248
2708
 
2249
2709
                if (mmc_test_cases[i].prepare) {
2250
2710
                        ret = mmc_test_cases[i].prepare(test);
2251
2711
                        if (ret) {
2252
 
                                printk(KERN_INFO "%s: Result: Prepare "
 
2712
                                pr_info("%s: Result: Prepare "
2253
2713
                                        "stage failed! (%d)\n",
2254
2714
                                        mmc_hostname(test->card->host),
2255
2715
                                        ret);
2279
2739
                ret = mmc_test_cases[i].run(test);
2280
2740
                switch (ret) {
2281
2741
                case RESULT_OK:
2282
 
                        printk(KERN_INFO "%s: Result: OK\n",
 
2742
                        pr_info("%s: Result: OK\n",
2283
2743
                                mmc_hostname(test->card->host));
2284
2744
                        break;
2285
2745
                case RESULT_FAIL:
2286
 
                        printk(KERN_INFO "%s: Result: FAILED\n",
 
2746
                        pr_info("%s: Result: FAILED\n",
2287
2747
                                mmc_hostname(test->card->host));
2288
2748
                        break;
2289
2749
                case RESULT_UNSUP_HOST:
2290
 
                        printk(KERN_INFO "%s: Result: UNSUPPORTED "
 
2750
                        pr_info("%s: Result: UNSUPPORTED "
2291
2751
                                "(by host)\n",
2292
2752
                                mmc_hostname(test->card->host));
2293
2753
                        break;
2294
2754
                case RESULT_UNSUP_CARD:
2295
 
                        printk(KERN_INFO "%s: Result: UNSUPPORTED "
 
2755
                        pr_info("%s: Result: UNSUPPORTED "
2296
2756
                                "(by card)\n",
2297
2757
                                mmc_hostname(test->card->host));
2298
2758
                        break;
2299
2759
                default:
2300
 
                        printk(KERN_INFO "%s: Result: ERROR (%d)\n",
 
2760
                        pr_info("%s: Result: ERROR (%d)\n",
2301
2761
                                mmc_hostname(test->card->host), ret);
2302
2762
                }
2303
2763
 
2308
2768
                if (mmc_test_cases[i].cleanup) {
2309
2769
                        ret = mmc_test_cases[i].cleanup(test);
2310
2770
                        if (ret) {
2311
 
                                printk(KERN_INFO "%s: Warning: Cleanup "
 
2771
                                pr_info("%s: Warning: Cleanup "
2312
2772
                                        "stage failed! (%d)\n",
2313
2773
                                        mmc_hostname(test->card->host),
2314
2774
                                        ret);
2318
2778
 
2319
2779
        mmc_release_host(test->card->host);
2320
2780
 
2321
 
        printk(KERN_INFO "%s: Tests completed.\n",
 
2781
        pr_info("%s: Tests completed.\n",
2322
2782
                mmc_hostname(test->card->host));
2323
2783
}
2324
2784
 
2445
2905
        .release        = single_release,
2446
2906
};
2447
2907
 
2448
 
static void mmc_test_free_file_test(struct mmc_card *card)
 
2908
static int mtf_testlist_show(struct seq_file *sf, void *data)
 
2909
{
 
2910
        int i;
 
2911
 
 
2912
        mutex_lock(&mmc_test_lock);
 
2913
 
 
2914
        for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++)
 
2915
                seq_printf(sf, "%d:\t%s\n", i+1, mmc_test_cases[i].name);
 
2916
 
 
2917
        mutex_unlock(&mmc_test_lock);
 
2918
 
 
2919
        return 0;
 
2920
}
 
2921
 
 
2922
static int mtf_testlist_open(struct inode *inode, struct file *file)
 
2923
{
 
2924
        return single_open(file, mtf_testlist_show, inode->i_private);
 
2925
}
 
2926
 
 
2927
static const struct file_operations mmc_test_fops_testlist = {
 
2928
        .open           = mtf_testlist_open,
 
2929
        .read           = seq_read,
 
2930
        .llseek         = seq_lseek,
 
2931
        .release        = single_release,
 
2932
};
 
2933
 
 
2934
static void mmc_test_free_dbgfs_file(struct mmc_card *card)
2449
2935
{
2450
2936
        struct mmc_test_dbgfs_file *df, *dfs;
2451
2937
 
2462
2948
        mutex_unlock(&mmc_test_lock);
2463
2949
}
2464
2950
 
2465
 
static int mmc_test_register_file_test(struct mmc_card *card)
 
2951
static int __mmc_test_register_dbgfs_file(struct mmc_card *card,
 
2952
        const char *name, mode_t mode, const struct file_operations *fops)
2466
2953
{
2467
2954
        struct dentry *file = NULL;
2468
2955
        struct mmc_test_dbgfs_file *df;
2469
 
        int ret = 0;
2470
 
 
2471
 
        mutex_lock(&mmc_test_lock);
2472
2956
 
2473
2957
        if (card->debugfs_root)
2474
 
                file = debugfs_create_file("test", S_IWUSR | S_IRUGO,
2475
 
                        card->debugfs_root, card, &mmc_test_fops_test);
 
2958
                file = debugfs_create_file(name, mode, card->debugfs_root,
 
2959
                        card, fops);
2476
2960
 
2477
2961
        if (IS_ERR_OR_NULL(file)) {
2478
2962
                dev_err(&card->dev,
2479
 
                        "Can't create file. Perhaps debugfs is disabled.\n");
2480
 
                ret = -ENODEV;
2481
 
                goto err;
 
2963
                        "Can't create %s. Perhaps debugfs is disabled.\n",
 
2964
                        name);
 
2965
                return -ENODEV;
2482
2966
        }
2483
2967
 
2484
2968
        df = kmalloc(sizeof(struct mmc_test_dbgfs_file), GFP_KERNEL);
2486
2970
                debugfs_remove(file);
2487
2971
                dev_err(&card->dev,
2488
2972
                        "Can't allocate memory for internal usage.\n");
2489
 
                ret = -ENOMEM;
2490
 
                goto err;
 
2973
                return -ENOMEM;
2491
2974
        }
2492
2975
 
2493
2976
        df->card = card;
2494
2977
        df->file = file;
2495
2978
 
2496
2979
        list_add(&df->link, &mmc_test_file_test);
 
2980
        return 0;
 
2981
}
 
2982
 
 
2983
static int mmc_test_register_dbgfs_file(struct mmc_card *card)
 
2984
{
 
2985
        int ret;
 
2986
 
 
2987
        mutex_lock(&mmc_test_lock);
 
2988
 
 
2989
        ret = __mmc_test_register_dbgfs_file(card, "test", S_IWUSR | S_IRUGO,
 
2990
                &mmc_test_fops_test);
 
2991
        if (ret)
 
2992
                goto err;
 
2993
 
 
2994
        ret = __mmc_test_register_dbgfs_file(card, "testlist", S_IRUGO,
 
2995
                &mmc_test_fops_testlist);
 
2996
        if (ret)
 
2997
                goto err;
2497
2998
 
2498
2999
err:
2499
3000
        mutex_unlock(&mmc_test_lock);
2508
3009
        if (!mmc_card_mmc(card) && !mmc_card_sd(card))
2509
3010
                return -ENODEV;
2510
3011
 
2511
 
        ret = mmc_test_register_file_test(card);
 
3012
        ret = mmc_test_register_dbgfs_file(card);
2512
3013
        if (ret)
2513
3014
                return ret;
2514
3015
 
2520
3021
static void mmc_test_remove(struct mmc_card *card)
2521
3022
{
2522
3023
        mmc_test_free_result(card);
2523
 
        mmc_test_free_file_test(card);
 
3024
        mmc_test_free_dbgfs_file(card);
2524
3025
}
2525
3026
 
2526
3027
static struct mmc_driver mmc_driver = {
2540
3041
{
2541
3042
        /* Clear stalled data if card is still plugged */
2542
3043
        mmc_test_free_result(NULL);
2543
 
        mmc_test_free_file_test(NULL);
 
3044
        mmc_test_free_dbgfs_file(NULL);
2544
3045
 
2545
3046
        mmc_unregister_driver(&mmc_driver);
2546
3047
}