2007-08-12 20:23:50 +08:00
|
|
|
/*
|
2008-06-28 23:51:27 +08:00
|
|
|
* Copyright 2007-2008 Pierre Ossman
|
2007-08-12 20:23:50 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/mmc/core.h>
|
|
|
|
#include <linux/mmc/card.h>
|
|
|
|
#include <linux/mmc/host.h>
|
|
|
|
#include <linux/mmc/mmc.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
#include <linux/scatterlist.h>
|
2010-08-12 05:17:51 +08:00
|
|
|
#include <linux/swap.h> /* For nr_free_buffer_pages() */
|
2010-09-01 14:26:47 +08:00
|
|
|
#include <linux/list.h>
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2010-09-10 15:10:50 +08:00
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/seq_file.h>
|
2011-07-04 03:15:51 +08:00
|
|
|
#include <linux/module.h>
|
2010-09-10 15:10:50 +08:00
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
#define RESULT_OK 0
|
|
|
|
#define RESULT_FAIL 1
|
|
|
|
#define RESULT_UNSUP_HOST 2
|
|
|
|
#define RESULT_UNSUP_CARD 3
|
|
|
|
|
2008-07-05 00:17:13 +08:00
|
|
|
#define BUFFER_ORDER 2
|
|
|
|
#define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER)
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2014-11-04 18:42:49 +08:00
|
|
|
#define TEST_ALIGN_END 8
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
/*
|
|
|
|
* Limit the test area size to the maximum MMC HC erase group size. Note that
|
|
|
|
* the maximum SD allocation unit size is just 4MiB.
|
|
|
|
*/
|
|
|
|
#define TEST_AREA_MAX_SIZE (128 * 1024 * 1024)
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
/**
|
|
|
|
* struct mmc_test_pages - pages allocated by 'alloc_pages()'.
|
|
|
|
* @page: first page in the allocation
|
|
|
|
* @order: order of the number of pages allocated
|
|
|
|
*/
|
|
|
|
struct mmc_test_pages {
|
|
|
|
struct page *page;
|
|
|
|
unsigned int order;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mmc_test_mem - allocated memory.
|
|
|
|
* @arr: array of allocations
|
|
|
|
* @cnt: number of allocations
|
|
|
|
*/
|
|
|
|
struct mmc_test_mem {
|
|
|
|
struct mmc_test_pages *arr;
|
|
|
|
unsigned int cnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mmc_test_area - information for performance tests.
|
|
|
|
* @max_sz: test area size (in bytes)
|
2010-08-12 05:17:51 +08:00
|
|
|
* @dev_addr: address on card at which to do performance tests
|
2010-09-10 16:33:45 +08:00
|
|
|
* @max_tfr: maximum transfer size allowed by driver (in bytes)
|
|
|
|
* @max_segs: maximum segments allowed by driver in scatterlist @sg
|
|
|
|
* @max_seg_sz: maximum segment size allowed by driver
|
2010-08-12 05:17:51 +08:00
|
|
|
* @blocks: number of (512 byte) blocks currently mapped by @sg
|
|
|
|
* @sg_len: length of currently mapped scatterlist @sg
|
|
|
|
* @mem: allocated memory
|
|
|
|
* @sg: scatterlist
|
|
|
|
*/
|
|
|
|
struct mmc_test_area {
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long max_sz;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned int dev_addr;
|
2010-09-10 16:33:45 +08:00
|
|
|
unsigned int max_tfr;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned int max_segs;
|
2010-09-10 16:33:45 +08:00
|
|
|
unsigned int max_seg_sz;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned int blocks;
|
|
|
|
unsigned int sg_len;
|
|
|
|
struct mmc_test_mem *mem;
|
|
|
|
struct scatterlist *sg;
|
|
|
|
};
|
|
|
|
|
2010-09-01 14:26:47 +08:00
|
|
|
/**
|
|
|
|
* struct mmc_test_transfer_result - transfer results for performance tests.
|
|
|
|
* @link: double-linked list
|
|
|
|
* @count: amount of group of sectors to check
|
|
|
|
* @sectors: amount of sectors to check in one group
|
|
|
|
* @ts: time values of transfer
|
|
|
|
* @rate: calculated transfer rate
|
2011-02-08 19:41:02 +08:00
|
|
|
* @iops: I/O operations per second (times 100)
|
2010-09-01 14:26:47 +08:00
|
|
|
*/
|
|
|
|
struct mmc_test_transfer_result {
|
|
|
|
struct list_head link;
|
|
|
|
unsigned int count;
|
|
|
|
unsigned int sectors;
|
|
|
|
struct timespec ts;
|
|
|
|
unsigned int rate;
|
2011-02-08 19:41:02 +08:00
|
|
|
unsigned int iops;
|
2010-09-01 14:26:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mmc_test_general_result - results for tests.
|
|
|
|
* @link: double-linked list
|
|
|
|
* @card: card under test
|
|
|
|
* @testcase: number of test case
|
|
|
|
* @result: result of test run
|
|
|
|
* @tr_lst: transfer measurements if any as mmc_test_transfer_result
|
|
|
|
*/
|
|
|
|
struct mmc_test_general_result {
|
|
|
|
struct list_head link;
|
|
|
|
struct mmc_card *card;
|
|
|
|
int testcase;
|
|
|
|
int result;
|
|
|
|
struct list_head tr_lst;
|
|
|
|
};
|
|
|
|
|
2010-09-10 15:10:50 +08:00
|
|
|
/**
|
|
|
|
* struct mmc_test_dbgfs_file - debugfs related file.
|
|
|
|
* @link: double-linked list
|
|
|
|
* @card: card under test
|
|
|
|
* @file: file created under debugfs
|
|
|
|
*/
|
|
|
|
struct mmc_test_dbgfs_file {
|
|
|
|
struct list_head link;
|
|
|
|
struct mmc_card *card;
|
|
|
|
struct dentry *file;
|
|
|
|
};
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
/**
|
|
|
|
* struct mmc_test_card - test information.
|
|
|
|
* @card: card under test
|
|
|
|
* @scratch: transfer buffer
|
|
|
|
* @buffer: transfer buffer
|
|
|
|
* @highmem: buffer for highmem tests
|
|
|
|
* @area: information for performance tests
|
2010-09-01 14:26:47 +08:00
|
|
|
* @gr: pointer to results of current testcase
|
2010-08-12 05:17:51 +08:00
|
|
|
*/
|
2007-08-12 20:23:50 +08:00
|
|
|
struct mmc_test_card {
|
|
|
|
struct mmc_card *card;
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
u8 scratch[BUFFER_SIZE];
|
2007-08-12 20:23:50 +08:00
|
|
|
u8 *buffer;
|
2008-07-05 00:17:13 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
struct page *highmem;
|
|
|
|
#endif
|
2010-09-01 14:26:47 +08:00
|
|
|
struct mmc_test_area area;
|
|
|
|
struct mmc_test_general_result *gr;
|
2007-08-12 20:23:50 +08:00
|
|
|
};
|
|
|
|
|
2011-07-02 00:55:26 +08:00
|
|
|
enum mmc_test_prep_media {
|
|
|
|
MMC_TEST_PREP_NONE = 0,
|
|
|
|
MMC_TEST_PREP_WRITE_FULL = 1 << 0,
|
|
|
|
MMC_TEST_PREP_ERASE = 1 << 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mmc_test_multiple_rw {
|
2011-07-02 00:55:27 +08:00
|
|
|
unsigned int *sg_len;
|
2011-07-02 00:55:26 +08:00
|
|
|
unsigned int *bs;
|
|
|
|
unsigned int len;
|
|
|
|
unsigned int size;
|
|
|
|
bool do_write;
|
|
|
|
bool do_nonblock_req;
|
|
|
|
enum mmc_test_prep_media prepare;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mmc_test_async_req {
|
|
|
|
struct mmc_async_req areq;
|
|
|
|
struct mmc_test_card *test;
|
|
|
|
};
|
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
/*******************************************************************/
|
2008-06-30 15:09:27 +08:00
|
|
|
/* General helper functions */
|
2007-08-12 20:23:50 +08:00
|
|
|
/*******************************************************************/
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
/*
|
|
|
|
* Configure correct block size in card
|
|
|
|
*/
|
2007-08-12 20:23:50 +08:00
|
|
|
static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size)
|
|
|
|
{
|
2010-08-24 18:20:26 +08:00
|
|
|
return mmc_set_blocklen(test->card, size);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 18:44:12 +08:00
|
|
|
static bool mmc_test_card_cmd23(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
return mmc_card_mmc(card) ||
|
|
|
|
(mmc_card_sd(card) && card->scr.cmds & SD_SCR_CMD23_SUPPORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mmc_test_prepare_sbc(struct mmc_test_card *test,
|
|
|
|
struct mmc_request *mrq, unsigned int blocks)
|
|
|
|
{
|
|
|
|
struct mmc_card *card = test->card;
|
|
|
|
|
|
|
|
if (!mrq->sbc || !mmc_host_cmd23(card->host) ||
|
|
|
|
!mmc_test_card_cmd23(card) || !mmc_op_multi(mrq->cmd->opcode) ||
|
|
|
|
(card->quirks & MMC_QUIRK_BLK_NO_CMD23)) {
|
|
|
|
mrq->sbc = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mrq->sbc->opcode = MMC_SET_BLOCK_COUNT;
|
|
|
|
mrq->sbc->arg = blocks;
|
|
|
|
mrq->sbc->flags = MMC_RSP_R1 | MMC_CMD_AC;
|
|
|
|
}
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
/*
|
|
|
|
* Fill in the mmc_request structure given a set of transfer parameters.
|
|
|
|
*/
|
|
|
|
static void mmc_test_prepare_mrq(struct mmc_test_card *test,
|
|
|
|
struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len,
|
|
|
|
unsigned dev_addr, unsigned blocks, unsigned blksz, int write)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
2016-11-02 15:26:57 +08:00
|
|
|
if (WARN_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop))
|
|
|
|
return;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
if (blocks > 1) {
|
|
|
|
mrq->cmd->opcode = write ?
|
|
|
|
MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK;
|
2007-08-12 20:23:50 +08:00
|
|
|
} else {
|
2008-06-30 15:09:27 +08:00
|
|
|
mrq->cmd->opcode = write ?
|
|
|
|
MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
mrq->cmd->arg = dev_addr;
|
2010-02-11 05:56:34 +08:00
|
|
|
if (!mmc_card_blockaddr(test->card))
|
|
|
|
mrq->cmd->arg <<= 9;
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
mrq->cmd->flags = MMC_RSP_R1 | MMC_CMD_ADTC;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
if (blocks == 1)
|
|
|
|
mrq->stop = NULL;
|
|
|
|
else {
|
|
|
|
mrq->stop->opcode = MMC_STOP_TRANSMISSION;
|
|
|
|
mrq->stop->arg = 0;
|
|
|
|
mrq->stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
mrq->data->blksz = blksz;
|
|
|
|
mrq->data->blocks = blocks;
|
|
|
|
mrq->data->flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
|
|
|
|
mrq->data->sg = sg;
|
|
|
|
mrq->data->sg_len = sg_len;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2016-08-16 18:44:12 +08:00
|
|
|
mmc_test_prepare_sbc(test, mrq, blocks);
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
mmc_set_data_timeout(mrq->data, test->card);
|
|
|
|
}
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
static int mmc_test_busy(struct mmc_command *cmd)
|
|
|
|
{
|
|
|
|
return !(cmd->resp[0] & R1_READY_FOR_DATA) ||
|
2011-08-10 17:46:28 +08:00
|
|
|
(R1_CURRENT_STATE(cmd->resp[0]) == R1_STATE_PRG);
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
/*
|
|
|
|
* Wait for the card to finish the busy state
|
|
|
|
*/
|
|
|
|
static int mmc_test_wait_busy(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, busy;
|
2016-12-19 19:51:18 +08:00
|
|
|
struct mmc_command cmd = {};
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
busy = 0;
|
|
|
|
do {
|
|
|
|
memset(&cmd, 0, sizeof(struct mmc_command));
|
|
|
|
|
|
|
|
cmd.opcode = MMC_SEND_STATUS;
|
|
|
|
cmd.arg = test->card->rca << 16;
|
|
|
|
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
ret = mmc_wait_for_cmd(test->card->host, &cmd, 0);
|
|
|
|
if (ret)
|
2007-08-12 20:23:50 +08:00
|
|
|
break;
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
if (!busy && mmc_test_busy(&cmd)) {
|
2007-08-12 20:23:50 +08:00
|
|
|
busy = 1;
|
2011-02-07 04:06:24 +08:00
|
|
|
if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Warning: Host did not "
|
2011-02-07 04:06:24 +08:00
|
|
|
"wait for busy state to end.\n",
|
|
|
|
mmc_hostname(test->card->host));
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
2010-08-12 05:17:51 +08:00
|
|
|
} while (mmc_test_busy(&cmd));
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
/*
|
|
|
|
* Transfer a single sector of kernel addressable data
|
|
|
|
*/
|
|
|
|
static int mmc_test_buffer_transfer(struct mmc_test_card *test,
|
|
|
|
u8 *buffer, unsigned addr, unsigned blksz, int write)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
2016-12-19 19:51:18 +08:00
|
|
|
struct mmc_request mrq = {};
|
|
|
|
struct mmc_command cmd = {};
|
|
|
|
struct mmc_command stop = {};
|
|
|
|
struct mmc_data data = {};
|
2008-06-30 15:09:27 +08:00
|
|
|
|
|
|
|
struct scatterlist sg;
|
|
|
|
|
|
|
|
mrq.cmd = &cmd;
|
|
|
|
mrq.data = &data;
|
|
|
|
mrq.stop = &stop;
|
|
|
|
|
|
|
|
sg_init_one(&sg, buffer, blksz);
|
|
|
|
|
|
|
|
mmc_test_prepare_mrq(test, &mrq, &sg, 1, addr, 1, blksz, write);
|
|
|
|
|
|
|
|
mmc_wait_for_req(test->card->host, &mrq);
|
|
|
|
|
|
|
|
if (cmd.error)
|
|
|
|
return cmd.error;
|
|
|
|
if (data.error)
|
|
|
|
return data.error;
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_wait_busy(test);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
static void mmc_test_free_mem(struct mmc_test_mem *mem)
|
|
|
|
{
|
|
|
|
if (!mem)
|
|
|
|
return;
|
|
|
|
while (mem->cnt--)
|
|
|
|
__free_pages(mem->arr[mem->cnt].page,
|
|
|
|
mem->arr[mem->cnt].order);
|
|
|
|
kfree(mem->arr);
|
|
|
|
kfree(mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-31 09:57:33 +08:00
|
|
|
* Allocate a lot of memory, preferably max_sz but at least min_sz. In case
|
2010-09-10 16:33:45 +08:00
|
|
|
* there isn't much memory do not exceed 1/16th total lowmem pages. Also do
|
|
|
|
* not exceed a maximum number of segments and try not to make segments much
|
|
|
|
* bigger than maximum segment size.
|
2010-08-12 05:17:51 +08:00
|
|
|
*/
|
2010-08-12 05:17:51 +08:00
|
|
|
static struct mmc_test_mem *mmc_test_alloc_mem(unsigned long min_sz,
|
2010-09-10 16:33:45 +08:00
|
|
|
unsigned long max_sz,
|
|
|
|
unsigned int max_segs,
|
|
|
|
unsigned int max_seg_sz)
|
2010-08-12 05:17:51 +08:00
|
|
|
{
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long max_page_cnt = DIV_ROUND_UP(max_sz, PAGE_SIZE);
|
|
|
|
unsigned long min_page_cnt = DIV_ROUND_UP(min_sz, PAGE_SIZE);
|
2010-09-10 16:33:45 +08:00
|
|
|
unsigned long max_seg_page_cnt = DIV_ROUND_UP(max_seg_sz, PAGE_SIZE);
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long page_cnt = 0;
|
|
|
|
unsigned long limit = nr_free_buffer_pages() >> 4;
|
2010-08-12 05:17:51 +08:00
|
|
|
struct mmc_test_mem *mem;
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
if (max_page_cnt > limit)
|
|
|
|
max_page_cnt = limit;
|
2010-09-23 19:51:29 +08:00
|
|
|
if (min_page_cnt > max_page_cnt)
|
|
|
|
min_page_cnt = max_page_cnt;
|
2010-08-12 05:17:51 +08:00
|
|
|
|
2010-09-10 16:33:45 +08:00
|
|
|
if (max_seg_page_cnt > max_page_cnt)
|
|
|
|
max_seg_page_cnt = max_page_cnt;
|
|
|
|
|
|
|
|
if (max_segs > max_page_cnt)
|
|
|
|
max_segs = max_page_cnt;
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
mem = kzalloc(sizeof(struct mmc_test_mem), GFP_KERNEL);
|
|
|
|
if (!mem)
|
|
|
|
return NULL;
|
|
|
|
|
2010-09-10 16:33:45 +08:00
|
|
|
mem->arr = kzalloc(sizeof(struct mmc_test_pages) * max_segs,
|
2010-08-12 05:17:51 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!mem->arr)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
while (max_page_cnt) {
|
|
|
|
struct page *page;
|
|
|
|
unsigned int order;
|
|
|
|
gfp_t flags = GFP_KERNEL | GFP_DMA | __GFP_NOWARN |
|
|
|
|
__GFP_NORETRY;
|
|
|
|
|
2010-09-10 16:33:45 +08:00
|
|
|
order = get_order(max_seg_page_cnt << PAGE_SHIFT);
|
2010-08-12 05:17:51 +08:00
|
|
|
while (1) {
|
|
|
|
page = alloc_pages(flags, order);
|
|
|
|
if (page || !order)
|
|
|
|
break;
|
|
|
|
order -= 1;
|
|
|
|
}
|
|
|
|
if (!page) {
|
|
|
|
if (page_cnt < min_page_cnt)
|
|
|
|
goto out_free;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mem->arr[mem->cnt].page = page;
|
|
|
|
mem->arr[mem->cnt].order = order;
|
|
|
|
mem->cnt += 1;
|
2010-08-12 05:17:51 +08:00
|
|
|
if (max_page_cnt <= (1UL << order))
|
|
|
|
break;
|
2010-09-23 19:51:29 +08:00
|
|
|
max_page_cnt -= 1UL << order;
|
|
|
|
page_cnt += 1UL << order;
|
2010-09-10 16:33:45 +08:00
|
|
|
if (mem->cnt >= max_segs) {
|
|
|
|
if (page_cnt < min_page_cnt)
|
|
|
|
goto out_free;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
mmc_test_free_mem(mem);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map memory into a scatterlist. Optionally allow the same memory to be
|
|
|
|
* mapped more than once.
|
|
|
|
*/
|
2011-07-02 00:55:27 +08:00
|
|
|
static int mmc_test_map_sg(struct mmc_test_mem *mem, unsigned long size,
|
2010-08-12 05:17:51 +08:00
|
|
|
struct scatterlist *sglist, int repeat,
|
2010-09-10 16:33:45 +08:00
|
|
|
unsigned int max_segs, unsigned int max_seg_sz,
|
2011-07-02 00:55:27 +08:00
|
|
|
unsigned int *sg_len, int min_sg_len)
|
2010-08-12 05:17:51 +08:00
|
|
|
{
|
|
|
|
struct scatterlist *sg = NULL;
|
|
|
|
unsigned int i;
|
2011-07-02 00:55:27 +08:00
|
|
|
unsigned long sz = size;
|
2010-08-12 05:17:51 +08:00
|
|
|
|
|
|
|
sg_init_table(sglist, max_segs);
|
2011-07-02 00:55:27 +08:00
|
|
|
if (min_sg_len > max_segs)
|
|
|
|
min_sg_len = max_segs;
|
2010-08-12 05:17:51 +08:00
|
|
|
|
|
|
|
*sg_len = 0;
|
|
|
|
do {
|
|
|
|
for (i = 0; i < mem->cnt; i++) {
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long len = PAGE_SIZE << mem->arr[i].order;
|
2010-08-12 05:17:51 +08:00
|
|
|
|
2011-07-02 00:55:27 +08:00
|
|
|
if (min_sg_len && (size / min_sg_len < len))
|
|
|
|
len = ALIGN(size / min_sg_len, 512);
|
2010-09-10 16:33:45 +08:00
|
|
|
if (len > sz)
|
2010-08-12 05:17:51 +08:00
|
|
|
len = sz;
|
2010-09-10 16:33:45 +08:00
|
|
|
if (len > max_seg_sz)
|
|
|
|
len = max_seg_sz;
|
2010-08-12 05:17:51 +08:00
|
|
|
if (sg)
|
|
|
|
sg = sg_next(sg);
|
|
|
|
else
|
|
|
|
sg = sglist;
|
|
|
|
if (!sg)
|
|
|
|
return -EINVAL;
|
|
|
|
sg_set_page(sg, mem->arr[i].page, len, 0);
|
|
|
|
sz -= len;
|
|
|
|
*sg_len += 1;
|
|
|
|
if (!sz)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (sz && repeat);
|
|
|
|
|
|
|
|
if (sz)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (sg)
|
|
|
|
sg_mark_end(sg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map memory into a scatterlist so that no pages are contiguous. Allow the
|
|
|
|
* same memory to be mapped more than once.
|
|
|
|
*/
|
|
|
|
static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem,
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long sz,
|
2010-08-12 05:17:51 +08:00
|
|
|
struct scatterlist *sglist,
|
|
|
|
unsigned int max_segs,
|
2010-09-10 16:33:45 +08:00
|
|
|
unsigned int max_seg_sz,
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned int *sg_len)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg = NULL;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned int i = mem->cnt, cnt;
|
|
|
|
unsigned long len;
|
2010-08-12 05:17:51 +08:00
|
|
|
void *base, *addr, *last_addr = NULL;
|
|
|
|
|
|
|
|
sg_init_table(sglist, max_segs);
|
|
|
|
|
|
|
|
*sg_len = 0;
|
2010-09-10 16:33:45 +08:00
|
|
|
while (sz) {
|
2010-08-12 05:17:51 +08:00
|
|
|
base = page_address(mem->arr[--i].page);
|
|
|
|
cnt = 1 << mem->arr[i].order;
|
|
|
|
while (sz && cnt) {
|
|
|
|
addr = base + PAGE_SIZE * --cnt;
|
|
|
|
if (last_addr && last_addr + PAGE_SIZE == addr)
|
|
|
|
continue;
|
|
|
|
last_addr = addr;
|
|
|
|
len = PAGE_SIZE;
|
2010-09-10 16:33:45 +08:00
|
|
|
if (len > max_seg_sz)
|
|
|
|
len = max_seg_sz;
|
|
|
|
if (len > sz)
|
2010-08-12 05:17:51 +08:00
|
|
|
len = sz;
|
|
|
|
if (sg)
|
|
|
|
sg = sg_next(sg);
|
|
|
|
else
|
|
|
|
sg = sglist;
|
|
|
|
if (!sg)
|
|
|
|
return -EINVAL;
|
|
|
|
sg_set_page(sg, virt_to_page(addr), len, 0);
|
|
|
|
sz -= len;
|
|
|
|
*sg_len += 1;
|
|
|
|
}
|
2010-09-10 16:33:45 +08:00
|
|
|
if (i == 0)
|
|
|
|
i = mem->cnt;
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sg)
|
|
|
|
sg_mark_end(sg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate transfer rate in bytes per second.
|
|
|
|
*/
|
|
|
|
static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts)
|
|
|
|
{
|
|
|
|
uint64_t ns;
|
|
|
|
|
|
|
|
ns = ts->tv_sec;
|
|
|
|
ns *= 1000000000;
|
|
|
|
ns += ts->tv_nsec;
|
|
|
|
|
|
|
|
bytes *= 1000000000;
|
|
|
|
|
|
|
|
while (ns > UINT_MAX) {
|
|
|
|
bytes >>= 1;
|
|
|
|
ns >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ns)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
do_div(bytes, (uint32_t)ns);
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
2010-09-01 14:26:47 +08:00
|
|
|
/*
|
|
|
|
* Save transfer results for future usage
|
|
|
|
*/
|
|
|
|
static void mmc_test_save_transfer_result(struct mmc_test_card *test,
|
|
|
|
unsigned int count, unsigned int sectors, struct timespec ts,
|
2011-02-08 19:41:02 +08:00
|
|
|
unsigned int rate, unsigned int iops)
|
2010-09-01 14:26:47 +08:00
|
|
|
{
|
|
|
|
struct mmc_test_transfer_result *tr;
|
|
|
|
|
|
|
|
if (!test->gr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tr = kmalloc(sizeof(struct mmc_test_transfer_result), GFP_KERNEL);
|
|
|
|
if (!tr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tr->count = count;
|
|
|
|
tr->sectors = sectors;
|
|
|
|
tr->ts = ts;
|
|
|
|
tr->rate = rate;
|
2011-02-08 19:41:02 +08:00
|
|
|
tr->iops = iops;
|
2010-09-01 14:26:47 +08:00
|
|
|
|
|
|
|
list_add_tail(&tr->link, &test->gr->tr_lst);
|
|
|
|
}
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
/*
|
|
|
|
* Print the transfer rate.
|
|
|
|
*/
|
|
|
|
static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
|
|
|
|
struct timespec *ts1, struct timespec *ts2)
|
|
|
|
{
|
2011-02-08 19:41:02 +08:00
|
|
|
unsigned int rate, iops, sectors = bytes >> 9;
|
2010-08-12 05:17:51 +08:00
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
ts = timespec_sub(*ts2, *ts1);
|
|
|
|
|
|
|
|
rate = mmc_test_rate(bytes, &ts);
|
2011-02-08 19:41:02 +08:00
|
|
|
iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
|
2010-08-12 05:17:51 +08:00
|
|
|
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
|
2011-02-08 19:41:02 +08:00
|
|
|
"seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
|
2010-08-12 05:17:51 +08:00
|
|
|
mmc_hostname(test->card->host), sectors, sectors >> 1,
|
2010-09-23 19:51:36 +08:00
|
|
|
(sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
|
2011-02-08 19:41:02 +08:00
|
|
|
(unsigned long)ts.tv_nsec, rate / 1000, rate / 1024,
|
|
|
|
iops / 100, iops % 100);
|
2010-09-01 14:26:47 +08:00
|
|
|
|
2011-02-08 19:41:02 +08:00
|
|
|
mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops);
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the average transfer rate.
|
|
|
|
*/
|
|
|
|
static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
|
|
|
|
unsigned int count, struct timespec *ts1,
|
|
|
|
struct timespec *ts2)
|
|
|
|
{
|
2011-02-08 19:41:02 +08:00
|
|
|
unsigned int rate, iops, sectors = bytes >> 9;
|
2010-08-12 05:17:51 +08:00
|
|
|
uint64_t tot = bytes * count;
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
ts = timespec_sub(*ts2, *ts1);
|
|
|
|
|
|
|
|
rate = mmc_test_rate(tot, &ts);
|
2011-02-08 19:41:02 +08:00
|
|
|
iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
|
2010-08-12 05:17:51 +08:00
|
|
|
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
|
2011-02-08 19:41:02 +08:00
|
|
|
"%lu.%09lu seconds (%u kB/s, %u KiB/s, "
|
2011-07-02 00:55:27 +08:00
|
|
|
"%u.%02u IOPS, sg_len %d)\n",
|
2010-08-12 05:17:51 +08:00
|
|
|
mmc_hostname(test->card->host), count, sectors, count,
|
2010-09-23 19:51:36 +08:00
|
|
|
sectors >> 1, (sectors & 1 ? ".5" : ""),
|
2010-08-12 05:17:51 +08:00
|
|
|
(unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec,
|
2011-07-02 00:55:27 +08:00
|
|
|
rate / 1000, rate / 1024, iops / 100, iops % 100,
|
|
|
|
test->area.sg_len);
|
2010-09-01 14:26:47 +08:00
|
|
|
|
2011-02-08 19:41:02 +08:00
|
|
|
mmc_test_save_transfer_result(test, count, sectors, ts, rate, iops);
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the card size in sectors.
|
|
|
|
*/
|
|
|
|
static unsigned int mmc_test_capacity(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
if (!mmc_card_sd(card) && mmc_card_blockaddr(card))
|
|
|
|
return card->ext_csd.sectors;
|
|
|
|
else
|
|
|
|
return card->csd.capacity << (card->csd.read_blkbits - 9);
|
|
|
|
}
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
/*******************************************************************/
|
|
|
|
/* Test preparation and cleanup */
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill the first couple of sectors of the card with known data
|
|
|
|
* so that bad reads/writes can be detected
|
|
|
|
*/
|
|
|
|
static int __mmc_test_prepare(struct mmc_test_card *test, int write)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (write)
|
2008-06-30 15:09:27 +08:00
|
|
|
memset(test->buffer, 0xDF, 512);
|
2007-08-12 20:23:50 +08:00
|
|
|
else {
|
2008-06-30 15:09:27 +08:00
|
|
|
for (i = 0;i < 512;i++)
|
2007-08-12 20:23:50 +08:00
|
|
|
test->buffer[i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0;i < BUFFER_SIZE / 512;i++) {
|
2010-02-11 05:56:34 +08:00
|
|
|
ret = mmc_test_buffer_transfer(test, test->buffer, i, 512, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
static int mmc_test_prepare_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return __mmc_test_prepare(test, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_prepare_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return __mmc_test_prepare(test, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_cleanup(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
memset(test->buffer, 0, 512);
|
|
|
|
|
|
|
|
for (i = 0;i < BUFFER_SIZE / 512;i++) {
|
2010-02-11 05:56:34 +08:00
|
|
|
ret = mmc_test_buffer_transfer(test, test->buffer, i, 512, 1);
|
2008-06-30 15:09:27 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
/* Test execution helpers */
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modifies the mmc_request to perform the "short transfer" tests
|
|
|
|
*/
|
|
|
|
static void mmc_test_prepare_broken_mrq(struct mmc_test_card *test,
|
|
|
|
struct mmc_request *mrq, int write)
|
|
|
|
{
|
2016-11-02 15:26:57 +08:00
|
|
|
if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
|
|
|
|
return;
|
2008-06-30 15:09:27 +08:00
|
|
|
|
|
|
|
if (mrq->data->blocks > 1) {
|
|
|
|
mrq->cmd->opcode = write ?
|
|
|
|
MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
|
|
|
|
mrq->stop = NULL;
|
|
|
|
} else {
|
|
|
|
mrq->cmd->opcode = MMC_SEND_STATUS;
|
|
|
|
mrq->cmd->arg = test->card->rca << 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks that a normal transfer didn't have any errors
|
|
|
|
*/
|
|
|
|
static int mmc_test_check_result(struct mmc_test_card *test,
|
2011-07-02 00:55:26 +08:00
|
|
|
struct mmc_request *mrq)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
2008-06-30 15:09:27 +08:00
|
|
|
int ret;
|
|
|
|
|
2016-11-02 15:26:57 +08:00
|
|
|
if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
|
|
|
|
return -EINVAL;
|
2008-06-30 15:09:27 +08:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2016-08-16 18:44:12 +08:00
|
|
|
if (mrq->sbc && mrq->sbc->error)
|
|
|
|
ret = mrq->sbc->error;
|
2008-06-30 15:09:27 +08:00
|
|
|
if (!ret && mrq->cmd->error)
|
|
|
|
ret = mrq->cmd->error;
|
|
|
|
if (!ret && mrq->data->error)
|
|
|
|
ret = mrq->data->error;
|
|
|
|
if (!ret && mrq->stop && mrq->stop->error)
|
|
|
|
ret = mrq->stop->error;
|
|
|
|
if (!ret && mrq->data->bytes_xfered !=
|
|
|
|
mrq->data->blocks * mrq->data->blksz)
|
|
|
|
ret = RESULT_FAIL;
|
|
|
|
|
|
|
|
if (ret == -EINVAL)
|
|
|
|
ret = RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
return ret;
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
2016-11-04 18:05:19 +08:00
|
|
|
static enum mmc_blk_status mmc_test_check_result_async(struct mmc_card *card,
|
2011-07-02 00:55:26 +08:00
|
|
|
struct mmc_async_req *areq)
|
|
|
|
{
|
|
|
|
struct mmc_test_async_req *test_async =
|
|
|
|
container_of(areq, struct mmc_test_async_req, areq);
|
2016-11-04 18:05:19 +08:00
|
|
|
int ret;
|
2011-07-02 00:55:26 +08:00
|
|
|
|
|
|
|
mmc_test_wait_busy(test_async->test);
|
|
|
|
|
2016-11-04 18:05:19 +08:00
|
|
|
/*
|
|
|
|
* FIXME: this would earlier just casts a regular error code,
|
|
|
|
* either of the kernel type -ERRORCODE or the local test framework
|
|
|
|
* RESULT_* errorcode, into an enum mmc_blk_status and return as
|
|
|
|
* result check. Instead, convert it to some reasonable type by just
|
|
|
|
* returning either MMC_BLK_SUCCESS or MMC_BLK_CMD_ERR.
|
|
|
|
* If possible, a reasonable error code should be returned.
|
|
|
|
*/
|
|
|
|
ret = mmc_test_check_result(test_async->test, areq->mrq);
|
|
|
|
if (ret)
|
|
|
|
return MMC_BLK_CMD_ERR;
|
|
|
|
|
|
|
|
return MMC_BLK_SUCCESS;
|
2011-07-02 00:55:26 +08:00
|
|
|
}
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
/*
|
|
|
|
* Checks that a "short transfer" behaved as expected
|
|
|
|
*/
|
|
|
|
static int mmc_test_check_broken_result(struct mmc_test_card *test,
|
|
|
|
struct mmc_request *mrq)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
2008-06-30 15:09:27 +08:00
|
|
|
int ret;
|
|
|
|
|
2016-11-02 15:26:57 +08:00
|
|
|
if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
|
|
|
|
return -EINVAL;
|
2008-06-30 15:09:27 +08:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
if (!ret && mrq->cmd->error)
|
|
|
|
ret = mrq->cmd->error;
|
|
|
|
if (!ret && mrq->data->error == 0)
|
|
|
|
ret = RESULT_FAIL;
|
|
|
|
if (!ret && mrq->data->error != -ETIMEDOUT)
|
|
|
|
ret = mrq->data->error;
|
|
|
|
if (!ret && mrq->stop && mrq->stop->error)
|
|
|
|
ret = mrq->stop->error;
|
|
|
|
if (mrq->data->blocks > 1) {
|
|
|
|
if (!ret && mrq->data->bytes_xfered > mrq->data->blksz)
|
|
|
|
ret = RESULT_FAIL;
|
|
|
|
} else {
|
|
|
|
if (!ret && mrq->data->bytes_xfered > 0)
|
|
|
|
ret = RESULT_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == -EINVAL)
|
|
|
|
ret = RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
return ret;
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
2011-07-02 00:55:26 +08:00
|
|
|
/*
|
|
|
|
* Tests nonblock transfer with certain parameters
|
|
|
|
*/
|
|
|
|
static void mmc_test_nonblock_reset(struct mmc_request *mrq,
|
|
|
|
struct mmc_command *cmd,
|
|
|
|
struct mmc_command *stop,
|
|
|
|
struct mmc_data *data)
|
|
|
|
{
|
|
|
|
memset(mrq, 0, sizeof(struct mmc_request));
|
|
|
|
memset(cmd, 0, sizeof(struct mmc_command));
|
|
|
|
memset(data, 0, sizeof(struct mmc_data));
|
|
|
|
memset(stop, 0, sizeof(struct mmc_command));
|
|
|
|
|
|
|
|
mrq->cmd = cmd;
|
|
|
|
mrq->data = data;
|
|
|
|
mrq->stop = stop;
|
|
|
|
}
|
|
|
|
static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
|
|
|
|
struct scatterlist *sg, unsigned sg_len,
|
|
|
|
unsigned dev_addr, unsigned blocks,
|
|
|
|
unsigned blksz, int write, int count)
|
|
|
|
{
|
|
|
|
struct mmc_request mrq1;
|
|
|
|
struct mmc_command cmd1;
|
|
|
|
struct mmc_command stop1;
|
|
|
|
struct mmc_data data1;
|
|
|
|
|
|
|
|
struct mmc_request mrq2;
|
|
|
|
struct mmc_command cmd2;
|
|
|
|
struct mmc_command stop2;
|
|
|
|
struct mmc_data data2;
|
|
|
|
|
|
|
|
struct mmc_test_async_req test_areq[2];
|
|
|
|
struct mmc_async_req *done_areq;
|
|
|
|
struct mmc_async_req *cur_areq = &test_areq[0].areq;
|
|
|
|
struct mmc_async_req *other_areq = &test_areq[1].areq;
|
2016-11-04 18:05:19 +08:00
|
|
|
enum mmc_blk_status status;
|
2011-07-02 00:55:26 +08:00
|
|
|
int i;
|
2016-11-14 19:31:34 +08:00
|
|
|
int ret = RESULT_OK;
|
2011-07-02 00:55:26 +08:00
|
|
|
|
|
|
|
test_areq[0].test = test;
|
|
|
|
test_areq[1].test = test;
|
|
|
|
|
|
|
|
mmc_test_nonblock_reset(&mrq1, &cmd1, &stop1, &data1);
|
|
|
|
mmc_test_nonblock_reset(&mrq2, &cmd2, &stop2, &data2);
|
|
|
|
|
|
|
|
cur_areq->mrq = &mrq1;
|
|
|
|
cur_areq->err_check = mmc_test_check_result_async;
|
|
|
|
other_areq->mrq = &mrq2;
|
|
|
|
other_areq->err_check = mmc_test_check_result_async;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
mmc_test_prepare_mrq(test, cur_areq->mrq, sg, sg_len, dev_addr,
|
|
|
|
blocks, blksz, write);
|
2016-11-04 18:05:19 +08:00
|
|
|
done_areq = mmc_start_req(test->card->host, cur_areq, &status);
|
2011-07-02 00:55:26 +08:00
|
|
|
|
2016-11-04 18:05:19 +08:00
|
|
|
if (status != MMC_BLK_SUCCESS || (!done_areq && i > 0)) {
|
|
|
|
ret = RESULT_FAIL;
|
2011-07-02 00:55:26 +08:00
|
|
|
goto err;
|
2016-11-04 18:05:19 +08:00
|
|
|
}
|
2011-07-02 00:55:26 +08:00
|
|
|
|
|
|
|
if (done_areq) {
|
|
|
|
if (done_areq->mrq == &mrq2)
|
|
|
|
mmc_test_nonblock_reset(&mrq2, &cmd2,
|
|
|
|
&stop2, &data2);
|
|
|
|
else
|
|
|
|
mmc_test_nonblock_reset(&mrq1, &cmd1,
|
|
|
|
&stop1, &data1);
|
|
|
|
}
|
2015-05-19 01:52:58 +08:00
|
|
|
swap(cur_areq, other_areq);
|
2011-07-02 00:55:26 +08:00
|
|
|
dev_addr += blocks;
|
|
|
|
}
|
|
|
|
|
2016-11-04 18:05:19 +08:00
|
|
|
done_areq = mmc_start_req(test->card->host, NULL, &status);
|
|
|
|
if (status != MMC_BLK_SUCCESS)
|
|
|
|
ret = RESULT_FAIL;
|
2011-07-02 00:55:26 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
/*
|
|
|
|
* Tests a basic transfer with certain parameters
|
|
|
|
*/
|
|
|
|
static int mmc_test_simple_transfer(struct mmc_test_card *test,
|
|
|
|
struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
|
|
|
|
unsigned blocks, unsigned blksz, int write)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
2016-12-19 19:51:18 +08:00
|
|
|
struct mmc_request mrq = {};
|
|
|
|
struct mmc_command cmd = {};
|
|
|
|
struct mmc_command stop = {};
|
|
|
|
struct mmc_data data = {};
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
mrq.cmd = &cmd;
|
|
|
|
mrq.data = &data;
|
|
|
|
mrq.stop = &stop;
|
|
|
|
|
|
|
|
mmc_test_prepare_mrq(test, &mrq, sg, sg_len, dev_addr,
|
|
|
|
blocks, blksz, write);
|
|
|
|
|
|
|
|
mmc_wait_for_req(test->card->host, &mrq);
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
mmc_test_wait_busy(test);
|
|
|
|
|
|
|
|
return mmc_test_check_result(test, &mrq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tests a transfer where the card will fail completely or partly
|
|
|
|
*/
|
|
|
|
static int mmc_test_broken_transfer(struct mmc_test_card *test,
|
|
|
|
unsigned blocks, unsigned blksz, int write)
|
|
|
|
{
|
2016-12-19 19:51:18 +08:00
|
|
|
struct mmc_request mrq = {};
|
|
|
|
struct mmc_command cmd = {};
|
|
|
|
struct mmc_command stop = {};
|
|
|
|
struct mmc_data data = {};
|
2008-06-30 15:09:27 +08:00
|
|
|
|
|
|
|
struct scatterlist sg;
|
|
|
|
|
|
|
|
mrq.cmd = &cmd;
|
|
|
|
mrq.data = &data;
|
|
|
|
mrq.stop = &stop;
|
|
|
|
|
|
|
|
sg_init_one(&sg, test->buffer, blocks * blksz);
|
|
|
|
|
|
|
|
mmc_test_prepare_mrq(test, &mrq, &sg, 1, 0, blocks, blksz, write);
|
|
|
|
mmc_test_prepare_broken_mrq(test, &mrq, write);
|
|
|
|
|
|
|
|
mmc_wait_for_req(test->card->host, &mrq);
|
|
|
|
|
|
|
|
mmc_test_wait_busy(test);
|
|
|
|
|
|
|
|
return mmc_test_check_broken_result(test, &mrq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Does a complete transfer test where data is also validated
|
|
|
|
*
|
|
|
|
* Note: mmc_test_prepare() must have been done before this call
|
|
|
|
*/
|
|
|
|
static int mmc_test_transfer(struct mmc_test_card *test,
|
|
|
|
struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
|
|
|
|
unsigned blocks, unsigned blksz, int write)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
unsigned long flags;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
if (write) {
|
|
|
|
for (i = 0;i < blocks * blksz;i++)
|
2008-06-30 15:09:27 +08:00
|
|
|
test->scratch[i] = i;
|
|
|
|
} else {
|
2008-07-29 07:05:22 +08:00
|
|
|
memset(test->scratch, 0, BUFFER_SIZE);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
2008-06-30 15:09:27 +08:00
|
|
|
local_irq_save(flags);
|
2008-07-29 07:05:22 +08:00
|
|
|
sg_copy_from_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
|
2008-06-30 15:09:27 +08:00
|
|
|
local_irq_restore(flags);
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, blksz);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
ret = mmc_test_simple_transfer(test, sg, sg_len, dev_addr,
|
|
|
|
blocks, blksz, write);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (write) {
|
2008-06-30 15:09:27 +08:00
|
|
|
int sectors;
|
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
sectors = (blocks * blksz + 511) / 512;
|
|
|
|
if ((sectors * 512) == (blocks * blksz))
|
|
|
|
sectors++;
|
|
|
|
|
|
|
|
if ((sectors * 512) > BUFFER_SIZE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
memset(test->buffer, 0, sectors * 512);
|
|
|
|
|
|
|
|
for (i = 0;i < sectors;i++) {
|
2008-06-30 15:09:27 +08:00
|
|
|
ret = mmc_test_buffer_transfer(test,
|
2007-08-12 20:23:50 +08:00
|
|
|
test->buffer + i * 512,
|
2010-02-11 05:56:34 +08:00
|
|
|
dev_addr + i, 512, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0;i < blocks * blksz;i++) {
|
|
|
|
if (test->buffer[i] != (u8)i)
|
|
|
|
return RESULT_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;i < sectors * 512;i++) {
|
|
|
|
if (test->buffer[i] != 0xDF)
|
|
|
|
return RESULT_FAIL;
|
|
|
|
}
|
|
|
|
} else {
|
2008-06-30 15:09:27 +08:00
|
|
|
local_irq_save(flags);
|
2008-07-29 07:05:22 +08:00
|
|
|
sg_copy_to_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
|
2008-06-30 15:09:27 +08:00
|
|
|
local_irq_restore(flags);
|
2007-08-12 20:23:50 +08:00
|
|
|
for (i = 0;i < blocks * blksz;i++) {
|
2008-06-30 15:09:27 +08:00
|
|
|
if (test->scratch[i] != (u8)i)
|
2007-08-12 20:23:50 +08:00
|
|
|
return RESULT_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
/* Tests */
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
|
|
struct mmc_test_case {
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
int (*prepare)(struct mmc_test_card *);
|
|
|
|
int (*run)(struct mmc_test_card *);
|
|
|
|
int (*cleanup)(struct mmc_test_card *);
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mmc_test_basic_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer, 512);
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_basic_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer, 512);
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_verify_write(struct mmc_test_card *test)
|
|
|
|
{
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
|
|
|
|
|
|
|
sg_init_one(&sg, test->buffer, 512);
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_verify_read(struct mmc_test_card *test)
|
|
|
|
{
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
|
|
|
|
|
|
|
sg_init_one(&sg, test->buffer, 512);
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_multi_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int size;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
if (test->card->host->max_blk_count == 1)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
size = PAGE_SIZE * 2;
|
|
|
|
size = min(size, test->card->host->max_req_size);
|
|
|
|
size = min(size, test->card->host->max_seg_size);
|
|
|
|
size = min(size, test->card->host->max_blk_count * 512);
|
|
|
|
|
|
|
|
if (size < 1024)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer, size);
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_multi_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int size;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
if (test->card->host->max_blk_count == 1)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
size = PAGE_SIZE * 2;
|
|
|
|
size = min(size, test->card->host->max_req_size);
|
|
|
|
size = min(size, test->card->host->max_seg_size);
|
|
|
|
size = min(size, test->card->host->max_blk_count * 512);
|
|
|
|
|
|
|
|
if (size < 1024)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer, size);
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_pow2_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, i;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
if (!test->card->csd.write_partial)
|
|
|
|
return RESULT_UNSUP_CARD;
|
|
|
|
|
|
|
|
for (i = 1; i < 512;i <<= 1) {
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer, i);
|
|
|
|
ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_pow2_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, i;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
if (!test->card->csd.read_partial)
|
|
|
|
return RESULT_UNSUP_CARD;
|
|
|
|
|
|
|
|
for (i = 1; i < 512;i <<= 1) {
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer, i);
|
|
|
|
ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_weird_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, i;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
if (!test->card->csd.write_partial)
|
|
|
|
return RESULT_UNSUP_CARD;
|
|
|
|
|
|
|
|
for (i = 3; i < 512;i += 7) {
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer, i);
|
|
|
|
ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_weird_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, i;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
if (!test->card->csd.read_partial)
|
|
|
|
return RESULT_UNSUP_CARD;
|
|
|
|
|
|
|
|
for (i = 3; i < 512;i += 7) {
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer, i);
|
|
|
|
ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_align_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, i;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2014-11-04 18:42:49 +08:00
|
|
|
for (i = 1; i < TEST_ALIGN_END; i++) {
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer + i, 512);
|
|
|
|
ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_align_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, i;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2014-11-04 18:42:49 +08:00
|
|
|
for (i = 1; i < TEST_ALIGN_END; i++) {
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer + i, 512);
|
|
|
|
ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_align_multi_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
unsigned int size;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
if (test->card->host->max_blk_count == 1)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
size = PAGE_SIZE * 2;
|
|
|
|
size = min(size, test->card->host->max_req_size);
|
|
|
|
size = min(size, test->card->host->max_seg_size);
|
|
|
|
size = min(size, test->card->host->max_blk_count * 512);
|
|
|
|
|
|
|
|
if (size < 1024)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
2014-11-04 18:42:49 +08:00
|
|
|
for (i = 1; i < TEST_ALIGN_END; i++) {
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer + i, size);
|
|
|
|
ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_align_multi_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
unsigned int size;
|
2008-06-30 15:09:27 +08:00
|
|
|
struct scatterlist sg;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
|
|
|
if (test->card->host->max_blk_count == 1)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
size = PAGE_SIZE * 2;
|
|
|
|
size = min(size, test->card->host->max_req_size);
|
|
|
|
size = min(size, test->card->host->max_seg_size);
|
|
|
|
size = min(size, test->card->host->max_blk_count * 512);
|
|
|
|
|
|
|
|
if (size < 1024)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
2014-11-04 18:42:49 +08:00
|
|
|
for (i = 1; i < TEST_ALIGN_END; i++) {
|
2008-06-30 15:09:27 +08:00
|
|
|
sg_init_one(&sg, test->buffer + i, size);
|
|
|
|
ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_xfersize_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_broken_transfer(test, 1, 512, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_xfersize_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_broken_transfer(test, 1, 512, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_multi_xfersize_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (test->card->host->max_blk_count == 1)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_broken_transfer(test, 2, 512, 1);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_multi_xfersize_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (test->card->host->max_blk_count == 1)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_broken_transfer(test, 2, 512, 0);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
2008-07-05 00:17:13 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
|
|
|
|
static int mmc_test_write_high(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
struct scatterlist sg;
|
|
|
|
|
|
|
|
sg_init_table(&sg, 1);
|
|
|
|
sg_set_page(&sg, test->highmem, 512, 0);
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
|
2008-07-05 00:17:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_read_high(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
struct scatterlist sg;
|
|
|
|
|
|
|
|
sg_init_table(&sg, 1);
|
|
|
|
sg_set_page(&sg, test->highmem, 512, 0);
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
|
2008-07-05 00:17:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_multi_write_high(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int size;
|
|
|
|
struct scatterlist sg;
|
|
|
|
|
|
|
|
if (test->card->host->max_blk_count == 1)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
size = PAGE_SIZE * 2;
|
|
|
|
size = min(size, test->card->host->max_req_size);
|
|
|
|
size = min(size, test->card->host->max_seg_size);
|
|
|
|
size = min(size, test->card->host->max_blk_count * 512);
|
|
|
|
|
|
|
|
if (size < 1024)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
sg_init_table(&sg, 1);
|
|
|
|
sg_set_page(&sg, test->highmem, size, 0);
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1);
|
2008-07-05 00:17:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_multi_read_high(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int size;
|
|
|
|
struct scatterlist sg;
|
|
|
|
|
|
|
|
if (test->card->host->max_blk_count == 1)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
size = PAGE_SIZE * 2;
|
|
|
|
size = min(size, test->card->host->max_req_size);
|
|
|
|
size = min(size, test->card->host->max_seg_size);
|
|
|
|
size = min(size, test->card->host->max_blk_count * 512);
|
|
|
|
|
|
|
|
if (size < 1024)
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
sg_init_table(&sg, 1);
|
|
|
|
sg_set_page(&sg, test->highmem, size, 0);
|
|
|
|
|
2015-05-10 05:44:49 +08:00
|
|
|
return mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0);
|
2008-07-05 00:17:13 +08:00
|
|
|
}
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
static int mmc_test_no_highmem(struct mmc_test_card *test)
|
|
|
|
{
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Highmem not configured - test skipped\n",
|
2010-08-12 05:17:51 +08:00
|
|
|
mmc_hostname(test->card->host));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-05 00:17:13 +08:00
|
|
|
#endif /* CONFIG_HIGHMEM */
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
/*
|
|
|
|
* Map sz bytes so that it can be transferred.
|
|
|
|
*/
|
2010-08-12 05:17:51 +08:00
|
|
|
static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
|
2011-07-02 00:55:27 +08:00
|
|
|
int max_scatter, int min_sg_len)
|
2010-08-12 05:17:51 +08:00
|
|
|
{
|
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-09-10 16:33:45 +08:00
|
|
|
int err;
|
2010-08-12 05:17:51 +08:00
|
|
|
|
|
|
|
t->blocks = sz >> 9;
|
|
|
|
|
|
|
|
if (max_scatter) {
|
2010-09-10 16:33:45 +08:00
|
|
|
err = mmc_test_map_sg_max_scatter(t->mem, sz, t->sg,
|
|
|
|
t->max_segs, t->max_seg_sz,
|
2010-08-12 05:17:51 +08:00
|
|
|
&t->sg_len);
|
2010-09-10 16:33:45 +08:00
|
|
|
} else {
|
|
|
|
err = mmc_test_map_sg(t->mem, sz, t->sg, 1, t->max_segs,
|
2011-07-02 00:55:27 +08:00
|
|
|
t->max_seg_sz, &t->sg_len, min_sg_len);
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
2010-09-10 16:33:45 +08:00
|
|
|
if (err)
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Failed to map sg list\n",
|
2010-09-10 16:33:45 +08:00
|
|
|
mmc_hostname(test->card->host));
|
|
|
|
return err;
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer bytes mapped by mmc_test_area_map().
|
|
|
|
*/
|
|
|
|
static int mmc_test_area_transfer(struct mmc_test_card *test,
|
|
|
|
unsigned int dev_addr, int write)
|
|
|
|
{
|
|
|
|
struct mmc_test_area *t = &test->area;
|
|
|
|
|
|
|
|
return mmc_test_simple_transfer(test, t->sg, t->sg_len, dev_addr,
|
|
|
|
t->blocks, 512, write);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-07-02 00:55:26 +08:00
|
|
|
* Map and transfer bytes for multiple transfers.
|
2010-08-12 05:17:51 +08:00
|
|
|
*/
|
2011-07-02 00:55:26 +08:00
|
|
|
static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz,
|
|
|
|
unsigned int dev_addr, int write,
|
|
|
|
int max_scatter, int timed, int count,
|
2011-07-02 00:55:27 +08:00
|
|
|
bool nonblock, int min_sg_len)
|
2010-08-12 05:17:51 +08:00
|
|
|
{
|
|
|
|
struct timespec ts1, ts2;
|
2011-07-02 00:55:26 +08:00
|
|
|
int ret = 0;
|
|
|
|
int i;
|
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-08-12 05:17:51 +08:00
|
|
|
|
2010-09-10 16:33:45 +08:00
|
|
|
/*
|
|
|
|
* In the case of a maximally scattered transfer, the maximum transfer
|
|
|
|
* size is further limited by using PAGE_SIZE segments.
|
|
|
|
*/
|
|
|
|
if (max_scatter) {
|
|
|
|
struct mmc_test_area *t = &test->area;
|
|
|
|
unsigned long max_tfr;
|
|
|
|
|
|
|
|
if (t->max_seg_sz >= PAGE_SIZE)
|
|
|
|
max_tfr = t->max_segs * PAGE_SIZE;
|
|
|
|
else
|
|
|
|
max_tfr = t->max_segs * t->max_seg_sz;
|
|
|
|
if (sz > max_tfr)
|
|
|
|
sz = max_tfr;
|
|
|
|
}
|
|
|
|
|
2011-07-02 00:55:27 +08:00
|
|
|
ret = mmc_test_area_map(test, sz, max_scatter, min_sg_len);
|
2010-08-12 05:17:51 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (timed)
|
|
|
|
getnstimeofday(&ts1);
|
2011-07-02 00:55:26 +08:00
|
|
|
if (nonblock)
|
|
|
|
ret = mmc_test_nonblock_transfer(test, t->sg, t->sg_len,
|
|
|
|
dev_addr, t->blocks, 512, write, count);
|
|
|
|
else
|
|
|
|
for (i = 0; i < count && ret == 0; i++) {
|
|
|
|
ret = mmc_test_area_transfer(test, dev_addr, write);
|
|
|
|
dev_addr += sz >> 9;
|
|
|
|
}
|
2010-08-12 05:17:51 +08:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (timed)
|
|
|
|
getnstimeofday(&ts2);
|
|
|
|
|
|
|
|
if (timed)
|
2011-07-02 00:55:26 +08:00
|
|
|
mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2);
|
2010-08-12 05:17:51 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-02 00:55:26 +08:00
|
|
|
static int mmc_test_area_io(struct mmc_test_card *test, unsigned long sz,
|
|
|
|
unsigned int dev_addr, int write, int max_scatter,
|
|
|
|
int timed)
|
|
|
|
{
|
|
|
|
return mmc_test_area_io_seq(test, sz, dev_addr, write, max_scatter,
|
2011-07-02 00:55:27 +08:00
|
|
|
timed, 1, false, 0);
|
2011-07-02 00:55:26 +08:00
|
|
|
}
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
/*
|
|
|
|
* Write the test area entirely.
|
|
|
|
*/
|
|
|
|
static int mmc_test_area_fill(struct mmc_test_card *test)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
|
|
|
|
|
|
|
return mmc_test_area_io(test, t->max_tfr, t->dev_addr, 1, 0, 0);
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Erase the test area entirely.
|
|
|
|
*/
|
|
|
|
static int mmc_test_area_erase(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
struct mmc_test_area *t = &test->area;
|
|
|
|
|
|
|
|
if (!mmc_can_erase(test->card))
|
|
|
|
return 0;
|
|
|
|
|
2011-05-10 20:59:01 +08:00
|
|
|
return mmc_erase(test->card, t->dev_addr, t->max_sz >> 9,
|
2010-08-12 05:17:51 +08:00
|
|
|
MMC_ERASE_ARG);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup struct mmc_test_area.
|
|
|
|
*/
|
|
|
|
static int mmc_test_area_cleanup(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
struct mmc_test_area *t = &test->area;
|
|
|
|
|
|
|
|
kfree(t->sg);
|
|
|
|
mmc_test_free_mem(t->mem);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-02-08 19:41:01 +08:00
|
|
|
* Initialize an area for testing large transfers. The test area is set to the
|
|
|
|
* middle of the card because cards may have different charateristics at the
|
|
|
|
* front (for FAT file system optimization). Optionally, the area is erased
|
|
|
|
* (if the card supports it) which may improve write performance. Optionally,
|
|
|
|
* the area is filled with data for subsequent read tests.
|
2010-08-12 05:17:51 +08:00
|
|
|
*/
|
|
|
|
static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
|
|
|
|
{
|
|
|
|
struct mmc_test_area *t = &test->area;
|
2011-02-08 19:41:01 +08:00
|
|
|
unsigned long min_sz = 64 * 1024, sz;
|
2010-08-12 05:17:51 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mmc_test_set_blksize(test, 512);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-02-08 19:41:01 +08:00
|
|
|
/* Make the test area size about 4MiB */
|
|
|
|
sz = (unsigned long)test->card->pref_erase << 9;
|
|
|
|
t->max_sz = sz;
|
|
|
|
while (t->max_sz < 4 * 1024 * 1024)
|
|
|
|
t->max_sz += sz;
|
|
|
|
while (t->max_sz > TEST_AREA_MAX_SIZE && t->max_sz > sz)
|
|
|
|
t->max_sz -= sz;
|
2010-09-10 16:33:45 +08:00
|
|
|
|
|
|
|
t->max_segs = test->card->host->max_segs;
|
|
|
|
t->max_seg_sz = test->card->host->max_seg_size;
|
2011-11-14 19:04:24 +08:00
|
|
|
t->max_seg_sz -= t->max_seg_sz % 512;
|
2010-09-10 16:33:45 +08:00
|
|
|
|
|
|
|
t->max_tfr = t->max_sz;
|
|
|
|
if (t->max_tfr >> 9 > test->card->host->max_blk_count)
|
|
|
|
t->max_tfr = test->card->host->max_blk_count << 9;
|
|
|
|
if (t->max_tfr > test->card->host->max_req_size)
|
|
|
|
t->max_tfr = test->card->host->max_req_size;
|
|
|
|
if (t->max_tfr / t->max_seg_sz > t->max_segs)
|
|
|
|
t->max_tfr = t->max_segs * t->max_seg_sz;
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
/*
|
2010-09-23 19:51:29 +08:00
|
|
|
* Try to allocate enough memory for a max. sized transfer. Less is OK
|
2010-08-12 05:17:51 +08:00
|
|
|
* because the same memory can be mapped into the scatterlist more than
|
2010-09-10 16:33:45 +08:00
|
|
|
* once. Also, take into account the limits imposed on scatterlist
|
|
|
|
* segments by the host driver.
|
2010-08-12 05:17:51 +08:00
|
|
|
*/
|
2010-09-23 19:51:29 +08:00
|
|
|
t->mem = mmc_test_alloc_mem(min_sz, t->max_tfr, t->max_segs,
|
2010-09-10 16:33:45 +08:00
|
|
|
t->max_seg_sz);
|
2010-08-12 05:17:51 +08:00
|
|
|
if (!t->mem)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-01-09 01:44:26 +08:00
|
|
|
t->sg = kmalloc_array(t->max_segs, sizeof(*t->sg), GFP_KERNEL);
|
2010-08-12 05:17:51 +08:00
|
|
|
if (!t->sg) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
t->dev_addr = mmc_test_capacity(test->card) / 2;
|
|
|
|
t->dev_addr -= t->dev_addr % (t->max_sz >> 9);
|
|
|
|
|
|
|
|
if (erase) {
|
|
|
|
ret = mmc_test_area_erase(test);
|
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fill) {
|
|
|
|
ret = mmc_test_area_fill(test);
|
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
mmc_test_area_cleanup(test);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare for large transfers. Do not erase the test area.
|
|
|
|
*/
|
|
|
|
static int mmc_test_area_prepare(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_area_init(test, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare for large transfers. Do erase the test area.
|
|
|
|
*/
|
|
|
|
static int mmc_test_area_prepare_erase(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_area_init(test, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare for large transfers. Erase and fill the test area.
|
|
|
|
*/
|
|
|
|
static int mmc_test_area_prepare_fill(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_area_init(test, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test best-case performance. Best-case performance is expected from
|
|
|
|
* a single large transfer.
|
|
|
|
*
|
|
|
|
* An additional option (max_scatter) allows the measurement of the same
|
|
|
|
* transfer but with no contiguous pages in the scatter list. This tests
|
|
|
|
* the efficiency of DMA to handle scattered pages.
|
|
|
|
*/
|
|
|
|
static int mmc_test_best_performance(struct mmc_test_card *test, int write,
|
|
|
|
int max_scatter)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
|
|
|
|
|
|
|
return mmc_test_area_io(test, t->max_tfr, t->dev_addr, write,
|
|
|
|
max_scatter, 1);
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Best-case read performance.
|
|
|
|
*/
|
|
|
|
static int mmc_test_best_read_performance(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_best_performance(test, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Best-case write performance.
|
|
|
|
*/
|
|
|
|
static int mmc_test_best_write_performance(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_best_performance(test, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Best-case read performance into scattered pages.
|
|
|
|
*/
|
|
|
|
static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_best_performance(test, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Best-case write performance from scattered pages.
|
|
|
|
*/
|
|
|
|
static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_best_performance(test, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Single read performance by transfer size.
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_read_perf(struct mmc_test_card *test)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long sz;
|
|
|
|
unsigned int dev_addr;
|
2010-08-12 05:17:51 +08:00
|
|
|
int ret;
|
|
|
|
|
2011-05-10 20:59:01 +08:00
|
|
|
for (sz = 512; sz < t->max_tfr; sz <<= 1) {
|
|
|
|
dev_addr = t->dev_addr + (sz >> 9);
|
2010-08-12 05:17:51 +08:00
|
|
|
ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2011-05-10 20:59:01 +08:00
|
|
|
sz = t->max_tfr;
|
|
|
|
dev_addr = t->dev_addr;
|
2010-08-12 05:17:51 +08:00
|
|
|
return mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Single write performance by transfer size.
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_write_perf(struct mmc_test_card *test)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long sz;
|
|
|
|
unsigned int dev_addr;
|
2010-08-12 05:17:51 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mmc_test_area_erase(test);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-05-10 20:59:01 +08:00
|
|
|
for (sz = 512; sz < t->max_tfr; sz <<= 1) {
|
|
|
|
dev_addr = t->dev_addr + (sz >> 9);
|
2010-08-12 05:17:51 +08:00
|
|
|
ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = mmc_test_area_erase(test);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-05-10 20:59:01 +08:00
|
|
|
sz = t->max_tfr;
|
|
|
|
dev_addr = t->dev_addr;
|
2010-08-12 05:17:51 +08:00
|
|
|
return mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Single trim performance by transfer size.
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_trim_perf(struct mmc_test_card *test)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long sz;
|
|
|
|
unsigned int dev_addr;
|
2010-08-12 05:17:51 +08:00
|
|
|
struct timespec ts1, ts2;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!mmc_can_trim(test->card))
|
|
|
|
return RESULT_UNSUP_CARD;
|
|
|
|
|
|
|
|
if (!mmc_can_erase(test->card))
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
2011-05-10 20:59:01 +08:00
|
|
|
for (sz = 512; sz < t->max_sz; sz <<= 1) {
|
|
|
|
dev_addr = t->dev_addr + (sz >> 9);
|
2010-08-12 05:17:51 +08:00
|
|
|
getnstimeofday(&ts1);
|
|
|
|
ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
getnstimeofday(&ts2);
|
|
|
|
mmc_test_print_rate(test, sz, &ts1, &ts2);
|
|
|
|
}
|
2011-05-10 20:59:01 +08:00
|
|
|
dev_addr = t->dev_addr;
|
2010-08-12 05:17:51 +08:00
|
|
|
getnstimeofday(&ts1);
|
|
|
|
ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
getnstimeofday(&ts2);
|
|
|
|
mmc_test_print_rate(test, sz, &ts1, &ts2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-10 16:33:45 +08:00
|
|
|
static int mmc_test_seq_read_perf(struct mmc_test_card *test, unsigned long sz)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-09-10 16:33:45 +08:00
|
|
|
unsigned int dev_addr, i, cnt;
|
|
|
|
struct timespec ts1, ts2;
|
|
|
|
int ret;
|
|
|
|
|
2011-05-10 20:59:01 +08:00
|
|
|
cnt = t->max_sz / sz;
|
|
|
|
dev_addr = t->dev_addr;
|
2010-09-10 16:33:45 +08:00
|
|
|
getnstimeofday(&ts1);
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
dev_addr += (sz >> 9);
|
|
|
|
}
|
|
|
|
getnstimeofday(&ts2);
|
|
|
|
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
/*
|
|
|
|
* Consecutive read performance by transfer size.
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_seq_read_perf(struct mmc_test_card *test)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long sz;
|
2010-09-10 16:33:45 +08:00
|
|
|
int ret;
|
|
|
|
|
2011-05-10 20:59:01 +08:00
|
|
|
for (sz = 512; sz < t->max_tfr; sz <<= 1) {
|
2010-09-10 16:33:45 +08:00
|
|
|
ret = mmc_test_seq_read_perf(test, sz);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2011-05-10 20:59:01 +08:00
|
|
|
sz = t->max_tfr;
|
2010-09-10 16:33:45 +08:00
|
|
|
return mmc_test_seq_read_perf(test, sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned int dev_addr, i, cnt;
|
2010-08-12 05:17:51 +08:00
|
|
|
struct timespec ts1, ts2;
|
|
|
|
int ret;
|
|
|
|
|
2010-09-10 16:33:45 +08:00
|
|
|
ret = mmc_test_area_erase(test);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-05-10 20:59:01 +08:00
|
|
|
cnt = t->max_sz / sz;
|
|
|
|
dev_addr = t->dev_addr;
|
2010-09-10 16:33:45 +08:00
|
|
|
getnstimeofday(&ts1);
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
dev_addr += (sz >> 9);
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
2010-09-10 16:33:45 +08:00
|
|
|
getnstimeofday(&ts2);
|
|
|
|
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
|
2010-08-12 05:17:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Consecutive write performance by transfer size.
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_seq_write_perf(struct mmc_test_card *test)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long sz;
|
2010-08-12 05:17:51 +08:00
|
|
|
int ret;
|
|
|
|
|
2011-05-10 20:59:01 +08:00
|
|
|
for (sz = 512; sz < t->max_tfr; sz <<= 1) {
|
2010-09-10 16:33:45 +08:00
|
|
|
ret = mmc_test_seq_write_perf(test, sz);
|
2010-08-12 05:17:51 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2011-05-10 20:59:01 +08:00
|
|
|
sz = t->max_tfr;
|
2010-09-10 16:33:45 +08:00
|
|
|
return mmc_test_seq_write_perf(test, sz);
|
2010-08-12 05:17:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Consecutive trim performance by transfer size.
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2010-08-12 05:17:51 +08:00
|
|
|
unsigned long sz;
|
|
|
|
unsigned int dev_addr, i, cnt;
|
2010-08-12 05:17:51 +08:00
|
|
|
struct timespec ts1, ts2;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!mmc_can_trim(test->card))
|
|
|
|
return RESULT_UNSUP_CARD;
|
|
|
|
|
|
|
|
if (!mmc_can_erase(test->card))
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
2011-05-10 20:59:01 +08:00
|
|
|
for (sz = 512; sz <= t->max_sz; sz <<= 1) {
|
2010-08-12 05:17:51 +08:00
|
|
|
ret = mmc_test_area_erase(test);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = mmc_test_area_fill(test);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-05-10 20:59:01 +08:00
|
|
|
cnt = t->max_sz / sz;
|
|
|
|
dev_addr = t->dev_addr;
|
2010-08-12 05:17:51 +08:00
|
|
|
getnstimeofday(&ts1);
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
ret = mmc_erase(test->card, dev_addr, sz >> 9,
|
|
|
|
MMC_TRIM_ARG);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
dev_addr += (sz >> 9);
|
|
|
|
}
|
|
|
|
getnstimeofday(&ts2);
|
|
|
|
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:41:02 +08:00
|
|
|
static unsigned int rnd_next = 1;
|
|
|
|
|
|
|
|
static unsigned int mmc_test_rnd_num(unsigned int rnd_cnt)
|
|
|
|
{
|
|
|
|
uint64_t r;
|
|
|
|
|
|
|
|
rnd_next = rnd_next * 1103515245 + 12345;
|
|
|
|
r = (rnd_next >> 16) & 0x7fff;
|
|
|
|
return (r * rnd_cnt) >> 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print,
|
|
|
|
unsigned long sz)
|
|
|
|
{
|
|
|
|
unsigned int dev_addr, cnt, rnd_addr, range1, range2, last_ea = 0, ea;
|
|
|
|
unsigned int ssz;
|
|
|
|
struct timespec ts1, ts2, ts;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ssz = sz >> 9;
|
|
|
|
|
|
|
|
rnd_addr = mmc_test_capacity(test->card) / 4;
|
|
|
|
range1 = rnd_addr / test->card->pref_erase;
|
|
|
|
range2 = range1 / ssz;
|
|
|
|
|
|
|
|
getnstimeofday(&ts1);
|
|
|
|
for (cnt = 0; cnt < UINT_MAX; cnt++) {
|
|
|
|
getnstimeofday(&ts2);
|
|
|
|
ts = timespec_sub(ts2, ts1);
|
|
|
|
if (ts.tv_sec >= 10)
|
|
|
|
break;
|
|
|
|
ea = mmc_test_rnd_num(range1);
|
|
|
|
if (ea == last_ea)
|
|
|
|
ea -= 1;
|
|
|
|
last_ea = ea;
|
|
|
|
dev_addr = rnd_addr + test->card->pref_erase * ea +
|
|
|
|
ssz * mmc_test_rnd_num(range2);
|
|
|
|
ret = mmc_test_area_io(test, sz, dev_addr, write, 0, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (print)
|
|
|
|
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_random_perf(struct mmc_test_card *test, int write)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2011-02-08 19:41:02 +08:00
|
|
|
unsigned int next;
|
|
|
|
unsigned long sz;
|
|
|
|
int ret;
|
|
|
|
|
2011-05-10 20:59:01 +08:00
|
|
|
for (sz = 512; sz < t->max_tfr; sz <<= 1) {
|
2011-02-08 19:41:02 +08:00
|
|
|
/*
|
|
|
|
* When writing, try to get more consistent results by running
|
|
|
|
* the test twice with exactly the same I/O but outputting the
|
|
|
|
* results only for the 2nd run.
|
|
|
|
*/
|
|
|
|
if (write) {
|
|
|
|
next = rnd_next;
|
|
|
|
ret = mmc_test_rnd_perf(test, write, 0, sz);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
rnd_next = next;
|
|
|
|
}
|
|
|
|
ret = mmc_test_rnd_perf(test, write, 1, sz);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2011-05-10 20:59:01 +08:00
|
|
|
sz = t->max_tfr;
|
2011-02-08 19:41:02 +08:00
|
|
|
if (write) {
|
|
|
|
next = rnd_next;
|
|
|
|
ret = mmc_test_rnd_perf(test, write, 0, sz);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
rnd_next = next;
|
|
|
|
}
|
|
|
|
return mmc_test_rnd_perf(test, write, 1, sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Random read performance by transfer size.
|
|
|
|
*/
|
|
|
|
static int mmc_test_random_read_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_random_perf(test, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Random write performance by transfer size.
|
|
|
|
*/
|
|
|
|
static int mmc_test_random_write_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_random_perf(test, 1);
|
|
|
|
}
|
|
|
|
|
2011-02-08 19:41:03 +08:00
|
|
|
static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
|
|
|
|
unsigned int tot_sz, int max_scatter)
|
|
|
|
{
|
2011-05-10 20:59:01 +08:00
|
|
|
struct mmc_test_area *t = &test->area;
|
2011-02-08 19:41:03 +08:00
|
|
|
unsigned int dev_addr, i, cnt, sz, ssz;
|
2011-03-17 05:46:45 +08:00
|
|
|
struct timespec ts1, ts2;
|
2011-02-08 19:41:03 +08:00
|
|
|
int ret;
|
|
|
|
|
2011-05-10 20:59:01 +08:00
|
|
|
sz = t->max_tfr;
|
|
|
|
|
2011-02-08 19:41:03 +08:00
|
|
|
/*
|
|
|
|
* In the case of a maximally scattered transfer, the maximum transfer
|
|
|
|
* size is further limited by using PAGE_SIZE segments.
|
|
|
|
*/
|
|
|
|
if (max_scatter) {
|
|
|
|
unsigned long max_tfr;
|
|
|
|
|
|
|
|
if (t->max_seg_sz >= PAGE_SIZE)
|
|
|
|
max_tfr = t->max_segs * PAGE_SIZE;
|
|
|
|
else
|
|
|
|
max_tfr = t->max_segs * t->max_seg_sz;
|
|
|
|
if (sz > max_tfr)
|
|
|
|
sz = max_tfr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssz = sz >> 9;
|
|
|
|
dev_addr = mmc_test_capacity(test->card) / 4;
|
|
|
|
if (tot_sz > dev_addr << 9)
|
|
|
|
tot_sz = dev_addr << 9;
|
|
|
|
cnt = tot_sz / sz;
|
|
|
|
dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
|
|
|
|
|
|
|
|
getnstimeofday(&ts1);
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
ret = mmc_test_area_io(test, sz, dev_addr, write,
|
|
|
|
max_scatter, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
dev_addr += ssz;
|
|
|
|
}
|
|
|
|
getnstimeofday(&ts2);
|
|
|
|
|
|
|
|
mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_large_seq_perf(struct mmc_test_card *test, int write)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
ret = mmc_test_seq_perf(test, write, 10 * 1024 * 1024, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
ret = mmc_test_seq_perf(test, write, 100 * 1024 * 1024, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
ret = mmc_test_seq_perf(test, write, 1000 * 1024 * 1024, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Large sequential read performance.
|
|
|
|
*/
|
|
|
|
static int mmc_test_large_seq_read_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_large_seq_perf(test, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Large sequential write performance.
|
|
|
|
*/
|
|
|
|
static int mmc_test_large_seq_write_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_large_seq_perf(test, 1);
|
|
|
|
}
|
|
|
|
|
2011-07-02 00:55:26 +08:00
|
|
|
static int mmc_test_rw_multiple(struct mmc_test_card *test,
|
|
|
|
struct mmc_test_multiple_rw *tdata,
|
2011-07-02 00:55:27 +08:00
|
|
|
unsigned int reqsize, unsigned int size,
|
|
|
|
int min_sg_len)
|
2011-07-02 00:55:26 +08:00
|
|
|
{
|
|
|
|
unsigned int dev_addr;
|
|
|
|
struct mmc_test_area *t = &test->area;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* Set up test area */
|
|
|
|
if (size > mmc_test_capacity(test->card) / 2 * 512)
|
|
|
|
size = mmc_test_capacity(test->card) / 2 * 512;
|
|
|
|
if (reqsize > t->max_tfr)
|
|
|
|
reqsize = t->max_tfr;
|
|
|
|
dev_addr = mmc_test_capacity(test->card) / 4;
|
|
|
|
if ((dev_addr & 0xffff0000))
|
|
|
|
dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
|
|
|
|
else
|
|
|
|
dev_addr &= 0xfffff800; /* Round to 1MiB boundary */
|
|
|
|
if (!dev_addr)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (reqsize > size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* prepare test area */
|
|
|
|
if (mmc_can_erase(test->card) &&
|
|
|
|
tdata->prepare & MMC_TEST_PREP_ERASE) {
|
|
|
|
ret = mmc_erase(test->card, dev_addr,
|
|
|
|
size / 512, MMC_SECURE_ERASE_ARG);
|
|
|
|
if (ret)
|
|
|
|
ret = mmc_erase(test->card, dev_addr,
|
|
|
|
size / 512, MMC_ERASE_ARG);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Run test */
|
|
|
|
ret = mmc_test_area_io_seq(test, reqsize, dev_addr,
|
|
|
|
tdata->do_write, 0, 1, size / reqsize,
|
2011-07-02 00:55:27 +08:00
|
|
|
tdata->do_nonblock_req, min_sg_len);
|
2011-07-02 00:55:26 +08:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
err:
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("[%s] error\n", __func__);
|
2011-07-02 00:55:26 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_rw_multiple_size(struct mmc_test_card *test,
|
|
|
|
struct mmc_test_multiple_rw *rw)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int i;
|
|
|
|
void *pre_req = test->card->host->ops->pre_req;
|
|
|
|
void *post_req = test->card->host->ops->post_req;
|
|
|
|
|
|
|
|
if (rw->do_nonblock_req &&
|
|
|
|
((!pre_req && post_req) || (pre_req && !post_req))) {
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("error: only one of pre/post is defined\n");
|
2011-07-02 00:55:26 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < rw->len && ret == 0; i++) {
|
2011-07-02 00:55:27 +08:00
|
|
|
ret = mmc_test_rw_multiple(test, rw, rw->bs[i], rw->size, 0);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_rw_multiple_sg_len(struct mmc_test_card *test,
|
|
|
|
struct mmc_test_multiple_rw *rw)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < rw->len && ret == 0; i++) {
|
|
|
|
ret = mmc_test_rw_multiple(test, rw, 512*1024, rw->size,
|
|
|
|
rw->sg_len[i]);
|
2011-07-02 00:55:26 +08:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Multiple blocking write 4k to 4 MB chunks
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_mult_write_blocking_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
|
|
|
|
1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
|
|
|
|
struct mmc_test_multiple_rw test_data = {
|
|
|
|
.bs = bs,
|
|
|
|
.size = TEST_AREA_MAX_SIZE,
|
|
|
|
.len = ARRAY_SIZE(bs),
|
|
|
|
.do_write = true,
|
|
|
|
.do_nonblock_req = false,
|
|
|
|
.prepare = MMC_TEST_PREP_ERASE,
|
|
|
|
};
|
|
|
|
|
|
|
|
return mmc_test_rw_multiple_size(test, &test_data);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Multiple non-blocking write 4k to 4 MB chunks
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_mult_write_nonblock_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
|
|
|
|
1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
|
|
|
|
struct mmc_test_multiple_rw test_data = {
|
|
|
|
.bs = bs,
|
|
|
|
.size = TEST_AREA_MAX_SIZE,
|
|
|
|
.len = ARRAY_SIZE(bs),
|
|
|
|
.do_write = true,
|
|
|
|
.do_nonblock_req = true,
|
|
|
|
.prepare = MMC_TEST_PREP_ERASE,
|
|
|
|
};
|
|
|
|
|
|
|
|
return mmc_test_rw_multiple_size(test, &test_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Multiple blocking read 4k to 4 MB chunks
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_mult_read_blocking_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
|
|
|
|
1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
|
|
|
|
struct mmc_test_multiple_rw test_data = {
|
|
|
|
.bs = bs,
|
|
|
|
.size = TEST_AREA_MAX_SIZE,
|
|
|
|
.len = ARRAY_SIZE(bs),
|
|
|
|
.do_write = false,
|
|
|
|
.do_nonblock_req = false,
|
|
|
|
.prepare = MMC_TEST_PREP_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
return mmc_test_rw_multiple_size(test, &test_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Multiple non-blocking read 4k to 4 MB chunks
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_mult_read_nonblock_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
|
|
|
|
1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
|
|
|
|
struct mmc_test_multiple_rw test_data = {
|
|
|
|
.bs = bs,
|
|
|
|
.size = TEST_AREA_MAX_SIZE,
|
|
|
|
.len = ARRAY_SIZE(bs),
|
|
|
|
.do_write = false,
|
|
|
|
.do_nonblock_req = true,
|
|
|
|
.prepare = MMC_TEST_PREP_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
return mmc_test_rw_multiple_size(test, &test_data);
|
|
|
|
}
|
|
|
|
|
2011-07-02 00:55:27 +08:00
|
|
|
/*
|
|
|
|
* Multiple blocking write 1 to 512 sg elements
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_sglen_wr_blocking_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
|
|
|
|
1 << 7, 1 << 8, 1 << 9};
|
|
|
|
struct mmc_test_multiple_rw test_data = {
|
|
|
|
.sg_len = sg_len,
|
|
|
|
.size = TEST_AREA_MAX_SIZE,
|
|
|
|
.len = ARRAY_SIZE(sg_len),
|
|
|
|
.do_write = true,
|
|
|
|
.do_nonblock_req = false,
|
|
|
|
.prepare = MMC_TEST_PREP_ERASE,
|
|
|
|
};
|
|
|
|
|
|
|
|
return mmc_test_rw_multiple_sg_len(test, &test_data);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Multiple non-blocking write 1 to 512 sg elements
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_sglen_wr_nonblock_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
|
|
|
|
1 << 7, 1 << 8, 1 << 9};
|
|
|
|
struct mmc_test_multiple_rw test_data = {
|
|
|
|
.sg_len = sg_len,
|
|
|
|
.size = TEST_AREA_MAX_SIZE,
|
|
|
|
.len = ARRAY_SIZE(sg_len),
|
|
|
|
.do_write = true,
|
|
|
|
.do_nonblock_req = true,
|
|
|
|
.prepare = MMC_TEST_PREP_ERASE,
|
|
|
|
};
|
|
|
|
|
|
|
|
return mmc_test_rw_multiple_sg_len(test, &test_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Multiple blocking read 1 to 512 sg elements
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_sglen_r_blocking_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
|
|
|
|
1 << 7, 1 << 8, 1 << 9};
|
|
|
|
struct mmc_test_multiple_rw test_data = {
|
|
|
|
.sg_len = sg_len,
|
|
|
|
.size = TEST_AREA_MAX_SIZE,
|
|
|
|
.len = ARRAY_SIZE(sg_len),
|
|
|
|
.do_write = false,
|
|
|
|
.do_nonblock_req = false,
|
|
|
|
.prepare = MMC_TEST_PREP_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
return mmc_test_rw_multiple_sg_len(test, &test_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Multiple non-blocking read 1 to 512 sg elements
|
|
|
|
*/
|
|
|
|
static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
|
|
|
|
1 << 7, 1 << 8, 1 << 9};
|
|
|
|
struct mmc_test_multiple_rw test_data = {
|
|
|
|
.sg_len = sg_len,
|
|
|
|
.size = TEST_AREA_MAX_SIZE,
|
|
|
|
.len = ARRAY_SIZE(sg_len),
|
|
|
|
.do_write = false,
|
|
|
|
.do_nonblock_req = true,
|
|
|
|
.prepare = MMC_TEST_PREP_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
return mmc_test_rw_multiple_sg_len(test, &test_data);
|
|
|
|
}
|
|
|
|
|
2011-08-29 21:42:14 +08:00
|
|
|
/*
|
|
|
|
* eMMC hardware reset.
|
|
|
|
*/
|
2015-10-12 17:22:23 +08:00
|
|
|
static int mmc_test_reset(struct mmc_test_card *test)
|
2011-08-29 21:42:14 +08:00
|
|
|
{
|
|
|
|
struct mmc_card *card = test->card;
|
|
|
|
struct mmc_host *host = card->host;
|
|
|
|
int err;
|
|
|
|
|
2015-01-12 22:38:04 +08:00
|
|
|
err = mmc_hw_reset(host);
|
2011-08-29 21:42:14 +08:00
|
|
|
if (!err)
|
|
|
|
return RESULT_OK;
|
2015-01-12 22:38:04 +08:00
|
|
|
else if (err == -EOPNOTSUPP)
|
|
|
|
return RESULT_UNSUP_HOST;
|
2011-08-29 21:42:14 +08:00
|
|
|
|
2015-01-12 22:38:04 +08:00
|
|
|
return RESULT_FAIL;
|
2011-08-29 21:42:14 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 18:44:12 +08:00
|
|
|
struct mmc_test_req {
|
|
|
|
struct mmc_request mrq;
|
|
|
|
struct mmc_command sbc;
|
|
|
|
struct mmc_command cmd;
|
|
|
|
struct mmc_command stop;
|
|
|
|
struct mmc_command status;
|
|
|
|
struct mmc_data data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct mmc_test_req *mmc_test_req_alloc(void)
|
|
|
|
{
|
|
|
|
struct mmc_test_req *rq = kzalloc(sizeof(*rq), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (rq) {
|
|
|
|
rq->mrq.cmd = &rq->cmd;
|
|
|
|
rq->mrq.data = &rq->data;
|
|
|
|
rq->mrq.stop = &rq->stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_send_status(struct mmc_test_card *test,
|
|
|
|
struct mmc_command *cmd)
|
|
|
|
{
|
|
|
|
memset(cmd, 0, sizeof(*cmd));
|
|
|
|
|
|
|
|
cmd->opcode = MMC_SEND_STATUS;
|
|
|
|
if (!mmc_host_is_spi(test->card->host))
|
|
|
|
cmd->arg = test->card->rca << 16;
|
|
|
|
cmd->flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
|
|
|
|
|
|
|
|
return mmc_wait_for_cmd(test->card->host, cmd, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
|
|
|
|
unsigned int dev_addr, int use_sbc,
|
|
|
|
int repeat_cmd, int write, int use_areq)
|
|
|
|
{
|
|
|
|
struct mmc_test_req *rq = mmc_test_req_alloc();
|
|
|
|
struct mmc_host *host = test->card->host;
|
|
|
|
struct mmc_test_area *t = &test->area;
|
2016-11-04 19:41:05 +08:00
|
|
|
struct mmc_test_async_req test_areq = { .test = test };
|
2016-08-16 18:44:12 +08:00
|
|
|
struct mmc_request *mrq;
|
|
|
|
unsigned long timeout;
|
|
|
|
bool expired = false;
|
2016-11-04 18:05:19 +08:00
|
|
|
enum mmc_blk_status blkstat = MMC_BLK_SUCCESS;
|
2016-08-16 18:44:12 +08:00
|
|
|
int ret = 0, cmd_ret;
|
|
|
|
u32 status = 0;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (!rq)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
mrq = &rq->mrq;
|
|
|
|
if (use_sbc)
|
|
|
|
mrq->sbc = &rq->sbc;
|
|
|
|
mrq->cap_cmd_during_tfr = true;
|
|
|
|
|
2016-11-04 19:41:05 +08:00
|
|
|
test_areq.areq.mrq = mrq;
|
|
|
|
test_areq.areq.err_check = mmc_test_check_result_async;
|
2016-08-16 18:44:12 +08:00
|
|
|
|
|
|
|
mmc_test_prepare_mrq(test, mrq, t->sg, t->sg_len, dev_addr, t->blocks,
|
|
|
|
512, write);
|
|
|
|
|
|
|
|
if (use_sbc && t->blocks > 1 && !mrq->sbc) {
|
|
|
|
ret = mmc_host_cmd23(host) ?
|
|
|
|
RESULT_UNSUP_CARD :
|
|
|
|
RESULT_UNSUP_HOST;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start ongoing data request */
|
|
|
|
if (use_areq) {
|
2016-11-04 18:05:19 +08:00
|
|
|
mmc_start_req(host, &test_areq.areq, &blkstat);
|
|
|
|
if (blkstat != MMC_BLK_SUCCESS) {
|
|
|
|
ret = RESULT_FAIL;
|
2016-08-16 18:44:12 +08:00
|
|
|
goto out_free;
|
2016-11-04 18:05:19 +08:00
|
|
|
}
|
2016-08-16 18:44:12 +08:00
|
|
|
} else {
|
|
|
|
mmc_wait_for_req(host, mrq);
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout = jiffies + msecs_to_jiffies(3000);
|
|
|
|
do {
|
|
|
|
count += 1;
|
|
|
|
|
|
|
|
/* Send status command while data transfer in progress */
|
|
|
|
cmd_ret = mmc_test_send_status(test, &rq->status);
|
|
|
|
if (cmd_ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
status = rq->status.resp[0];
|
|
|
|
if (status & R1_ERROR) {
|
|
|
|
cmd_ret = -EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mmc_is_req_done(host, mrq))
|
|
|
|
break;
|
|
|
|
|
|
|
|
expired = time_after(jiffies, timeout);
|
|
|
|
if (expired) {
|
|
|
|
pr_info("%s: timeout waiting for Tran state status %#x\n",
|
|
|
|
mmc_hostname(host), status);
|
|
|
|
cmd_ret = -ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (repeat_cmd && R1_CURRENT_STATE(status) != R1_STATE_TRAN);
|
|
|
|
|
|
|
|
/* Wait for data request to complete */
|
2016-11-04 18:05:19 +08:00
|
|
|
if (use_areq) {
|
|
|
|
mmc_start_req(host, NULL, &blkstat);
|
|
|
|
if (blkstat != MMC_BLK_SUCCESS)
|
|
|
|
ret = RESULT_FAIL;
|
|
|
|
} else {
|
2016-08-16 18:44:12 +08:00
|
|
|
mmc_wait_for_req_done(test->card->host, mrq);
|
2016-11-04 18:05:19 +08:00
|
|
|
}
|
2016-08-16 18:44:12 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For cap_cmd_during_tfr request, upper layer must send stop if
|
|
|
|
* required.
|
|
|
|
*/
|
|
|
|
if (mrq->data->stop && (mrq->data->error || !mrq->sbc)) {
|
|
|
|
if (ret)
|
|
|
|
mmc_wait_for_cmd(host, mrq->data->stop, 0);
|
|
|
|
else
|
|
|
|
ret = mmc_wait_for_cmd(host, mrq->data->stop, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (cmd_ret) {
|
|
|
|
pr_info("%s: Send Status failed: status %#x, error %d\n",
|
|
|
|
mmc_hostname(test->card->host), status, cmd_ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = mmc_test_check_result(test, mrq);
|
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
ret = mmc_test_wait_busy(test);
|
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (repeat_cmd && (t->blocks + 1) << 9 > t->max_tfr)
|
|
|
|
pr_info("%s: %d commands completed during transfer of %u blocks\n",
|
|
|
|
mmc_hostname(test->card->host), count, t->blocks);
|
|
|
|
|
|
|
|
if (cmd_ret)
|
|
|
|
ret = cmd_ret;
|
|
|
|
out_free:
|
|
|
|
kfree(rq);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __mmc_test_cmds_during_tfr(struct mmc_test_card *test,
|
|
|
|
unsigned long sz, int use_sbc, int write,
|
|
|
|
int use_areq)
|
|
|
|
{
|
|
|
|
struct mmc_test_area *t = &test->area;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(test->card->host->caps & MMC_CAP_CMD_DURING_TFR))
|
|
|
|
return RESULT_UNSUP_HOST;
|
|
|
|
|
|
|
|
ret = mmc_test_area_map(test, sz, 0, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 0, write,
|
|
|
|
use_areq);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 1, write,
|
|
|
|
use_areq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_cmds_during_tfr(struct mmc_test_card *test, int use_sbc,
|
|
|
|
int write, int use_areq)
|
|
|
|
{
|
|
|
|
struct mmc_test_area *t = &test->area;
|
|
|
|
unsigned long sz;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
for (sz = 512; sz <= t->max_tfr; sz += 512) {
|
|
|
|
ret = __mmc_test_cmds_during_tfr(test, sz, use_sbc, write,
|
|
|
|
use_areq);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commands during read - no Set Block Count (CMD23).
|
|
|
|
*/
|
|
|
|
static int mmc_test_cmds_during_read(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_cmds_during_tfr(test, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commands during write - no Set Block Count (CMD23).
|
|
|
|
*/
|
|
|
|
static int mmc_test_cmds_during_write(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_cmds_during_tfr(test, 0, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commands during read - use Set Block Count (CMD23).
|
|
|
|
*/
|
|
|
|
static int mmc_test_cmds_during_read_cmd23(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_cmds_during_tfr(test, 1, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commands during write - use Set Block Count (CMD23).
|
|
|
|
*/
|
|
|
|
static int mmc_test_cmds_during_write_cmd23(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_cmds_during_tfr(test, 1, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commands during non-blocking read - use Set Block Count (CMD23).
|
|
|
|
*/
|
|
|
|
static int mmc_test_cmds_during_read_cmd23_nonblock(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_cmds_during_tfr(test, 1, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commands during non-blocking write - use Set Block Count (CMD23).
|
|
|
|
*/
|
|
|
|
static int mmc_test_cmds_during_write_cmd23_nonblock(struct mmc_test_card *test)
|
|
|
|
{
|
|
|
|
return mmc_test_cmds_during_tfr(test, 1, 1, 1);
|
|
|
|
}
|
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
static const struct mmc_test_case mmc_test_cases[] = {
|
|
|
|
{
|
|
|
|
.name = "Basic write (no data verification)",
|
|
|
|
.run = mmc_test_basic_write,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Basic read (no data verification)",
|
|
|
|
.run = mmc_test_basic_read,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Basic write (with data verification)",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_write,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_verify_write,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Basic read (with data verification)",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_read,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_verify_read,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Multi-block write",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_write,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_multi_write,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Multi-block read",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_read,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_multi_read,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Power of two block writes",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_write,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_pow2_write,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Power of two block reads",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_read,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_pow2_read,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Weird sized block writes",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_write,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_weird_write,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Weird sized block reads",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_read,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_weird_read,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Badly aligned write",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_write,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_align_write,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Badly aligned read",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_read,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_align_read,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Badly aligned multi-block write",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_write,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_align_multi_write,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Badly aligned multi-block read",
|
2008-06-30 15:09:27 +08:00
|
|
|
.prepare = mmc_test_prepare_read,
|
2007-08-12 20:23:50 +08:00
|
|
|
.run = mmc_test_align_multi_read,
|
2008-06-30 15:09:27 +08:00
|
|
|
.cleanup = mmc_test_cleanup,
|
2007-08-12 20:23:50 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Correct xfer_size at write (start failure)",
|
|
|
|
.run = mmc_test_xfersize_write,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Correct xfer_size at read (start failure)",
|
|
|
|
.run = mmc_test_xfersize_read,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Correct xfer_size at write (midway failure)",
|
|
|
|
.run = mmc_test_multi_xfersize_write,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Correct xfer_size at read (midway failure)",
|
|
|
|
.run = mmc_test_multi_xfersize_read,
|
|
|
|
},
|
2008-07-05 00:17:13 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Highmem write",
|
|
|
|
.prepare = mmc_test_prepare_write,
|
|
|
|
.run = mmc_test_write_high,
|
|
|
|
.cleanup = mmc_test_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Highmem read",
|
|
|
|
.prepare = mmc_test_prepare_read,
|
|
|
|
.run = mmc_test_read_high,
|
|
|
|
.cleanup = mmc_test_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Multi-block highmem write",
|
|
|
|
.prepare = mmc_test_prepare_write,
|
|
|
|
.run = mmc_test_multi_write_high,
|
|
|
|
.cleanup = mmc_test_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Multi-block highmem read",
|
|
|
|
.prepare = mmc_test_prepare_read,
|
|
|
|
.run = mmc_test_multi_read_high,
|
|
|
|
.cleanup = mmc_test_cleanup,
|
|
|
|
},
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Highmem write",
|
|
|
|
.run = mmc_test_no_highmem,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Highmem read",
|
|
|
|
.run = mmc_test_no_highmem,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Multi-block highmem write",
|
|
|
|
.run = mmc_test_no_highmem,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Multi-block highmem read",
|
|
|
|
.run = mmc_test_no_highmem,
|
|
|
|
},
|
|
|
|
|
2008-07-05 00:17:13 +08:00
|
|
|
#endif /* CONFIG_HIGHMEM */
|
|
|
|
|
2010-08-12 05:17:51 +08:00
|
|
|
{
|
|
|
|
.name = "Best-case read performance",
|
|
|
|
.prepare = mmc_test_area_prepare_fill,
|
|
|
|
.run = mmc_test_best_read_performance,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Best-case write performance",
|
|
|
|
.prepare = mmc_test_area_prepare_erase,
|
|
|
|
.run = mmc_test_best_write_performance,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Best-case read performance into scattered pages",
|
|
|
|
.prepare = mmc_test_area_prepare_fill,
|
|
|
|
.run = mmc_test_best_read_perf_max_scatter,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Best-case write performance from scattered pages",
|
|
|
|
.prepare = mmc_test_area_prepare_erase,
|
|
|
|
.run = mmc_test_best_write_perf_max_scatter,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Single read performance by transfer size",
|
|
|
|
.prepare = mmc_test_area_prepare_fill,
|
|
|
|
.run = mmc_test_profile_read_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Single write performance by transfer size",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_write_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Single trim performance by transfer size",
|
|
|
|
.prepare = mmc_test_area_prepare_fill,
|
|
|
|
.run = mmc_test_profile_trim_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Consecutive read performance by transfer size",
|
|
|
|
.prepare = mmc_test_area_prepare_fill,
|
|
|
|
.run = mmc_test_profile_seq_read_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Consecutive write performance by transfer size",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_seq_write_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Consecutive trim performance by transfer size",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_seq_trim_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
2011-02-08 19:41:02 +08:00
|
|
|
{
|
|
|
|
.name = "Random read performance by transfer size",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_random_read_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Random write performance by transfer size",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_random_write_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
2011-02-08 19:41:03 +08:00
|
|
|
{
|
|
|
|
.name = "Large sequential read into scattered pages",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_large_seq_read_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Large sequential write from scattered pages",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_large_seq_write_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
2011-07-02 00:55:26 +08:00
|
|
|
{
|
|
|
|
.name = "Write performance with blocking req 4k to 4MB",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_mult_write_blocking_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Write performance with non-blocking req 4k to 4MB",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_mult_write_nonblock_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Read performance with blocking req 4k to 4MB",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_mult_read_blocking_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Read performance with non-blocking req 4k to 4MB",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_mult_read_nonblock_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
2011-07-02 00:55:27 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Write performance blocking req 1 to 512 sg elems",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_sglen_wr_blocking_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Write performance non-blocking req 1 to 512 sg elems",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_sglen_wr_nonblock_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Read performance blocking req 1 to 512 sg elems",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_sglen_r_blocking_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Read performance non-blocking req 1 to 512 sg elems",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_profile_sglen_r_nonblock_perf,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
2011-08-29 21:42:14 +08:00
|
|
|
|
|
|
|
{
|
2015-10-12 17:22:23 +08:00
|
|
|
.name = "Reset test",
|
|
|
|
.run = mmc_test_reset,
|
2011-08-29 21:42:14 +08:00
|
|
|
},
|
2016-08-16 18:44:12 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Commands during read - no Set Block Count (CMD23)",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_cmds_during_read,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Commands during write - no Set Block Count (CMD23)",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_cmds_during_write,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Commands during read - use Set Block Count (CMD23)",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_cmds_during_read_cmd23,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Commands during write - use Set Block Count (CMD23)",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_cmds_during_write_cmd23,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Commands during non-blocking read - use Set Block Count (CMD23)",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_cmds_during_read_cmd23_nonblock,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.name = "Commands during non-blocking write - use Set Block Count (CMD23)",
|
|
|
|
.prepare = mmc_test_area_prepare,
|
|
|
|
.run = mmc_test_cmds_during_write_cmd23_nonblock,
|
|
|
|
.cleanup = mmc_test_area_cleanup,
|
|
|
|
},
|
2007-08-12 20:23:50 +08:00
|
|
|
};
|
|
|
|
|
2008-09-13 18:03:32 +08:00
|
|
|
static DEFINE_MUTEX(mmc_test_lock);
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2010-09-01 14:26:47 +08:00
|
|
|
static LIST_HEAD(mmc_test_result);
|
|
|
|
|
2008-05-25 04:36:31 +08:00
|
|
|
static void mmc_test_run(struct mmc_test_card *test, int testcase)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Starting tests of card %s...\n",
|
2007-08-12 20:23:50 +08:00
|
|
|
mmc_hostname(test->card->host), mmc_card_id(test->card));
|
|
|
|
|
|
|
|
mmc_claim_host(test->card->host);
|
|
|
|
|
|
|
|
for (i = 0;i < ARRAY_SIZE(mmc_test_cases);i++) {
|
2010-09-01 14:26:47 +08:00
|
|
|
struct mmc_test_general_result *gr;
|
|
|
|
|
2008-05-25 04:36:31 +08:00
|
|
|
if (testcase && ((i + 1) != testcase))
|
|
|
|
continue;
|
|
|
|
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Test case %d. %s...\n",
|
2007-08-12 20:23:50 +08:00
|
|
|
mmc_hostname(test->card->host), i + 1,
|
|
|
|
mmc_test_cases[i].name);
|
|
|
|
|
|
|
|
if (mmc_test_cases[i].prepare) {
|
|
|
|
ret = mmc_test_cases[i].prepare(test);
|
|
|
|
if (ret) {
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Result: Prepare "
|
2007-08-12 20:23:50 +08:00
|
|
|
"stage failed! (%d)\n",
|
|
|
|
mmc_hostname(test->card->host),
|
|
|
|
ret);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-01 14:26:47 +08:00
|
|
|
gr = kzalloc(sizeof(struct mmc_test_general_result),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (gr) {
|
|
|
|
INIT_LIST_HEAD(&gr->tr_lst);
|
|
|
|
|
|
|
|
/* Assign data what we know already */
|
|
|
|
gr->card = test->card;
|
|
|
|
gr->testcase = i;
|
|
|
|
|
|
|
|
/* Append container to global one */
|
|
|
|
list_add_tail(&gr->link, &mmc_test_result);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the pointer to created container in our private
|
|
|
|
* structure.
|
|
|
|
*/
|
|
|
|
test->gr = gr;
|
|
|
|
}
|
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
ret = mmc_test_cases[i].run(test);
|
|
|
|
switch (ret) {
|
|
|
|
case RESULT_OK:
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Result: OK\n",
|
2007-08-12 20:23:50 +08:00
|
|
|
mmc_hostname(test->card->host));
|
|
|
|
break;
|
|
|
|
case RESULT_FAIL:
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Result: FAILED\n",
|
2007-08-12 20:23:50 +08:00
|
|
|
mmc_hostname(test->card->host));
|
|
|
|
break;
|
|
|
|
case RESULT_UNSUP_HOST:
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Result: UNSUPPORTED "
|
2007-08-12 20:23:50 +08:00
|
|
|
"(by host)\n",
|
|
|
|
mmc_hostname(test->card->host));
|
|
|
|
break;
|
|
|
|
case RESULT_UNSUP_CARD:
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Result: UNSUPPORTED "
|
2007-08-12 20:23:50 +08:00
|
|
|
"(by card)\n",
|
|
|
|
mmc_hostname(test->card->host));
|
|
|
|
break;
|
|
|
|
default:
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Result: ERROR (%d)\n",
|
2007-08-12 20:23:50 +08:00
|
|
|
mmc_hostname(test->card->host), ret);
|
|
|
|
}
|
|
|
|
|
2010-09-01 14:26:47 +08:00
|
|
|
/* Save the result */
|
|
|
|
if (gr)
|
|
|
|
gr->result = ret;
|
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
if (mmc_test_cases[i].cleanup) {
|
|
|
|
ret = mmc_test_cases[i].cleanup(test);
|
|
|
|
if (ret) {
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Warning: Cleanup "
|
2007-08-12 20:23:50 +08:00
|
|
|
"stage failed! (%d)\n",
|
|
|
|
mmc_hostname(test->card->host),
|
|
|
|
ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mmc_release_host(test->card->host);
|
|
|
|
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("%s: Tests completed.\n",
|
2007-08-12 20:23:50 +08:00
|
|
|
mmc_hostname(test->card->host));
|
|
|
|
}
|
|
|
|
|
2010-09-01 14:26:47 +08:00
|
|
|
static void mmc_test_free_result(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
struct mmc_test_general_result *gr, *grs;
|
|
|
|
|
|
|
|
mutex_lock(&mmc_test_lock);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(gr, grs, &mmc_test_result, link) {
|
|
|
|
struct mmc_test_transfer_result *tr, *trs;
|
|
|
|
|
|
|
|
if (card && gr->card != card)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(tr, trs, &gr->tr_lst, link) {
|
|
|
|
list_del(&tr->link);
|
|
|
|
kfree(tr);
|
|
|
|
}
|
|
|
|
|
|
|
|
list_del(&gr->link);
|
|
|
|
kfree(gr);
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&mmc_test_lock);
|
|
|
|
}
|
|
|
|
|
2010-09-10 15:10:50 +08:00
|
|
|
static LIST_HEAD(mmc_test_file_test);
|
|
|
|
|
|
|
|
static int mtf_test_show(struct seq_file *sf, void *data)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
2010-09-10 15:10:50 +08:00
|
|
|
struct mmc_card *card = (struct mmc_card *)sf->private;
|
2010-09-01 14:26:47 +08:00
|
|
|
struct mmc_test_general_result *gr;
|
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
mutex_lock(&mmc_test_lock);
|
2010-09-01 14:26:47 +08:00
|
|
|
|
|
|
|
list_for_each_entry(gr, &mmc_test_result, link) {
|
|
|
|
struct mmc_test_transfer_result *tr;
|
|
|
|
|
|
|
|
if (gr->card != card)
|
|
|
|
continue;
|
|
|
|
|
2010-09-10 15:10:50 +08:00
|
|
|
seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
|
2010-09-01 14:26:47 +08:00
|
|
|
|
|
|
|
list_for_each_entry(tr, &gr->tr_lst, link) {
|
2011-02-08 19:41:02 +08:00
|
|
|
seq_printf(sf, "%u %d %lu.%09lu %u %u.%02u\n",
|
2010-09-01 14:26:47 +08:00
|
|
|
tr->count, tr->sectors,
|
|
|
|
(unsigned long)tr->ts.tv_sec,
|
|
|
|
(unsigned long)tr->ts.tv_nsec,
|
2011-02-08 19:41:02 +08:00
|
|
|
tr->rate, tr->iops / 100, tr->iops % 100);
|
2010-09-01 14:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
mutex_unlock(&mmc_test_lock);
|
|
|
|
|
2010-09-10 15:10:50 +08:00
|
|
|
return 0;
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
2010-09-10 15:10:50 +08:00
|
|
|
static int mtf_test_open(struct inode *inode, struct file *file)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
2010-09-10 15:10:50 +08:00
|
|
|
return single_open(file, mtf_test_show, inode->i_private);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mtf_test_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct seq_file *sf = (struct seq_file *)file->private_data;
|
|
|
|
struct mmc_card *card = (struct mmc_card *)sf->private;
|
2007-08-12 20:23:50 +08:00
|
|
|
struct mmc_test_card *test;
|
2010-09-01 14:26:46 +08:00
|
|
|
long testcase;
|
2013-07-19 15:02:43 +08:00
|
|
|
int ret;
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2013-07-19 15:02:43 +08:00
|
|
|
ret = kstrtol_from_user(buf, count, 10, &testcase);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-05-25 04:36:31 +08:00
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL);
|
|
|
|
if (!test)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-09-01 14:26:47 +08:00
|
|
|
/*
|
|
|
|
* Remove all test cases associated with given card. Thus we have only
|
|
|
|
* actual data of the last run.
|
|
|
|
*/
|
|
|
|
mmc_test_free_result(card);
|
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
test->card = card;
|
|
|
|
|
|
|
|
test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL);
|
2008-07-05 00:17:13 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
if (test->buffer && test->highmem) {
|
|
|
|
#else
|
2007-08-12 20:23:50 +08:00
|
|
|
if (test->buffer) {
|
2008-07-05 00:17:13 +08:00
|
|
|
#endif
|
2007-08-12 20:23:50 +08:00
|
|
|
mutex_lock(&mmc_test_lock);
|
2008-05-25 04:36:31 +08:00
|
|
|
mmc_test_run(test, testcase);
|
2007-08-12 20:23:50 +08:00
|
|
|
mutex_unlock(&mmc_test_lock);
|
|
|
|
}
|
|
|
|
|
2008-07-05 00:17:13 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
__free_pages(test->highmem, BUFFER_ORDER);
|
|
|
|
#endif
|
2007-08-12 20:23:50 +08:00
|
|
|
kfree(test->buffer);
|
|
|
|
kfree(test);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2010-09-10 15:10:50 +08:00
|
|
|
static const struct file_operations mmc_test_fops_test = {
|
|
|
|
.open = mtf_test_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.write = mtf_test_write,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
2011-07-02 00:55:25 +08:00
|
|
|
static int mtf_testlist_show(struct seq_file *sf, void *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mutex_lock(&mmc_test_lock);
|
|
|
|
|
2016-01-26 03:20:04 +08:00
|
|
|
seq_printf(sf, "0:\tRun all tests\n");
|
2011-07-02 00:55:25 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++)
|
|
|
|
seq_printf(sf, "%d:\t%s\n", i+1, mmc_test_cases[i].name);
|
|
|
|
|
|
|
|
mutex_unlock(&mmc_test_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtf_testlist_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, mtf_testlist_show, inode->i_private);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations mmc_test_fops_testlist = {
|
|
|
|
.open = mtf_testlist_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
2011-07-22 21:13:36 +08:00
|
|
|
static void mmc_test_free_dbgfs_file(struct mmc_card *card)
|
2010-09-10 15:10:50 +08:00
|
|
|
{
|
|
|
|
struct mmc_test_dbgfs_file *df, *dfs;
|
|
|
|
|
|
|
|
mutex_lock(&mmc_test_lock);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(df, dfs, &mmc_test_file_test, link) {
|
|
|
|
if (card && df->card != card)
|
|
|
|
continue;
|
|
|
|
debugfs_remove(df->file);
|
|
|
|
list_del(&df->link);
|
|
|
|
kfree(df);
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&mmc_test_lock);
|
|
|
|
}
|
|
|
|
|
2011-07-22 21:13:36 +08:00
|
|
|
static int __mmc_test_register_dbgfs_file(struct mmc_card *card,
|
2011-07-24 16:33:43 +08:00
|
|
|
const char *name, umode_t mode, const struct file_operations *fops)
|
2010-09-10 15:10:50 +08:00
|
|
|
{
|
|
|
|
struct dentry *file = NULL;
|
|
|
|
struct mmc_test_dbgfs_file *df;
|
2011-07-02 00:55:25 +08:00
|
|
|
|
|
|
|
if (card->debugfs_root)
|
2011-07-22 21:13:36 +08:00
|
|
|
file = debugfs_create_file(name, mode, card->debugfs_root,
|
|
|
|
card, fops);
|
2011-07-02 00:55:25 +08:00
|
|
|
|
|
|
|
if (IS_ERR_OR_NULL(file)) {
|
|
|
|
dev_err(&card->dev,
|
2011-07-22 21:13:36 +08:00
|
|
|
"Can't create %s. Perhaps debugfs is disabled.\n",
|
|
|
|
name);
|
|
|
|
return -ENODEV;
|
2010-09-10 15:10:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
df = kmalloc(sizeof(struct mmc_test_dbgfs_file), GFP_KERNEL);
|
|
|
|
if (!df) {
|
|
|
|
debugfs_remove(file);
|
|
|
|
dev_err(&card->dev,
|
|
|
|
"Can't allocate memory for internal usage.\n");
|
2011-07-22 21:13:36 +08:00
|
|
|
return -ENOMEM;
|
2010-09-10 15:10:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
df->card = card;
|
|
|
|
df->file = file;
|
|
|
|
|
|
|
|
list_add(&df->link, &mmc_test_file_test);
|
2011-07-22 21:13:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_test_register_dbgfs_file(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&mmc_test_lock);
|
|
|
|
|
|
|
|
ret = __mmc_test_register_dbgfs_file(card, "test", S_IWUSR | S_IRUGO,
|
|
|
|
&mmc_test_fops_test);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = __mmc_test_register_dbgfs_file(card, "testlist", S_IRUGO,
|
|
|
|
&mmc_test_fops_testlist);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2010-09-10 15:10:50 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
mutex_unlock(&mmc_test_lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2007-08-12 20:23:50 +08:00
|
|
|
|
2015-04-14 19:06:12 +08:00
|
|
|
static int mmc_test_probe(struct mmc_card *card)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-09-01 14:26:45 +08:00
|
|
|
if (!mmc_card_mmc(card) && !mmc_card_sd(card))
|
2008-06-28 23:51:27 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2011-07-22 21:13:36 +08:00
|
|
|
ret = mmc_test_register_dbgfs_file(card);
|
2007-08-12 20:23:50 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2008-07-22 20:38:35 +08:00
|
|
|
dev_info(&card->dev, "Card claimed for testing.\n");
|
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-14 19:06:12 +08:00
|
|
|
static void mmc_test_remove(struct mmc_card *card)
|
2007-08-12 20:23:50 +08:00
|
|
|
{
|
2010-09-01 14:26:47 +08:00
|
|
|
mmc_test_free_result(card);
|
2011-07-22 21:13:36 +08:00
|
|
|
mmc_test_free_dbgfs_file(card);
|
2007-08-12 20:23:50 +08:00
|
|
|
}
|
|
|
|
|
2015-04-14 19:06:12 +08:00
|
|
|
static void mmc_test_shutdown(struct mmc_card *card)
|
2013-06-10 23:03:40 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-14 19:06:12 +08:00
|
|
|
static struct mmc_driver mmc_driver = {
|
|
|
|
.drv = {
|
|
|
|
.name = "mmc_test",
|
|
|
|
},
|
2007-08-12 20:23:50 +08:00
|
|
|
.probe = mmc_test_probe,
|
|
|
|
.remove = mmc_test_remove,
|
2013-06-10 23:03:40 +08:00
|
|
|
.shutdown = mmc_test_shutdown,
|
2007-08-12 20:23:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mmc_test_init(void)
|
|
|
|
{
|
|
|
|
return mmc_register_driver(&mmc_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mmc_test_exit(void)
|
|
|
|
{
|
2010-09-01 14:26:47 +08:00
|
|
|
/* Clear stalled data if card is still plugged */
|
|
|
|
mmc_test_free_result(NULL);
|
2011-07-22 21:13:36 +08:00
|
|
|
mmc_test_free_dbgfs_file(NULL);
|
2010-09-01 14:26:47 +08:00
|
|
|
|
2007-08-12 20:23:50 +08:00
|
|
|
mmc_unregister_driver(&mmc_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mmc_test_init);
|
|
|
|
module_exit(mmc_test_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Multimedia Card (MMC) host test driver");
|
|
|
|
MODULE_AUTHOR("Pierre Ossman");
|