/* * 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)
/** * 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; unsignedint order;
};
/** * struct mmc_test_mem - allocated memory. * @arr: array of allocations * @cnt: number of allocations
*/ struct mmc_test_mem { struct mmc_test_pages *arr; unsignedint cnt;
};
/** * struct mmc_test_area - information for performance tests. * @max_sz: test area size (in bytes) * @dev_addr: address on card at which to do performance tests * @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 * @blocks: number of (512 byte) blocks currently mapped by @sg * @sg_len: length of currently mapped scatterlist @sg * @mem: allocated memory * @sg: scatterlist * @sg_areq: scatterlist for non-blocking request
*/ struct mmc_test_area { unsignedlong max_sz; unsignedint dev_addr; unsignedint max_tfr; unsignedint max_segs; unsignedint max_seg_sz; unsignedint blocks; unsignedint sg_len; struct mmc_test_mem *mem; struct scatterlist *sg; struct scatterlist *sg_areq;
};
/** * 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 * @iops: I/O operations per second (times 100)
*/ struct mmc_test_transfer_result { struct list_head link; unsignedint count; unsignedint sectors; struct timespec64 ts; unsignedint rate; unsignedint iops;
};
/** * 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;
};
/** * 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;
};
/** * 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 * @gr: pointer to results of current testcase
*/ struct mmc_test_card { struct mmc_card *card;
/* * Fill in the mmc_request structure given a set of transfer parameters.
*/ staticvoid 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)
{ if (WARN_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop)) return;
/* * Wait for the card to finish the busy state
*/ staticint mmc_test_wait_busy(struct mmc_test_card *test)
{ int ret, busy; struct mmc_command cmd = {};
busy = 0; do {
memset(&cmd, 0, sizeof(struct mmc_command));
ret = mmc_wait_for_cmd(test->card->host, &cmd, 0); if (ret) break;
if (!busy && mmc_test_busy(&cmd)) {
busy = 1; if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
pr_info("%s: Warning: Host did not wait for busy state to end.\n",
mmc_hostname(test->card->host));
}
} while (mmc_test_busy(&cmd));
return ret;
}
/* * Transfer a single sector of kernel addressable data
*/ staticint mmc_test_buffer_transfer(struct mmc_test_card *test,
u8 *buffer, unsigned addr, unsigned blksz, int write)
{ struct mmc_request mrq = {}; struct mmc_command cmd = {}; struct mmc_command stop = {}; struct mmc_data data = {};
if (cmd.error) return cmd.error; if (data.error) return data.error;
return mmc_test_wait_busy(test);
}
staticvoid 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);
}
/* * Allocate a lot of memory, preferably max_sz but at least min_sz. In case * 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.
*/ staticstruct mmc_test_mem *mmc_test_alloc_mem(unsignedlong min_sz, unsignedlong max_sz, unsignedint max_segs, unsignedint max_seg_sz)
{ unsignedlong max_page_cnt = DIV_ROUND_UP(max_sz, PAGE_SIZE); unsignedlong min_page_cnt = DIV_ROUND_UP(min_sz, PAGE_SIZE); unsignedlong max_seg_page_cnt = DIV_ROUND_UP(max_seg_sz, PAGE_SIZE); unsignedlong page_cnt = 0; unsignedlong limit = nr_free_buffer_pages() >> 4; struct mmc_test_mem *mem;
if (max_page_cnt > limit)
max_page_cnt = limit; if (min_page_cnt > max_page_cnt)
min_page_cnt = max_page_cnt;
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;
mem = kzalloc(sizeof(*mem), GFP_KERNEL); if (!mem) return NULL;
mem->arr = kcalloc(max_segs, sizeof(*mem->arr), GFP_KERNEL); if (!mem->arr) goto out_free;
order = get_order(max_seg_page_cnt << PAGE_SHIFT); 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; if (max_page_cnt <= (1UL << order)) break;
max_page_cnt -= 1UL << order;
page_cnt += 1UL << order; if (mem->cnt >= max_segs) { if (page_cnt < min_page_cnt) goto out_free; break;
}
}
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.
*/ staticint mmc_test_map_sg(struct mmc_test_mem *mem, unsignedlong size, struct scatterlist *sglist, int repeat, unsignedint max_segs, unsignedint max_seg_sz, unsignedint *sg_len, int min_sg_len)
{ struct scatterlist *sg = NULL; unsignedint i; unsignedlong sz = size;
sg_init_table(sglist, max_segs); if (min_sg_len > max_segs)
min_sg_len = max_segs;
*sg_len = 0; do { for (i = 0; i < mem->cnt; i++) { unsignedlong len = PAGE_SIZE << mem->arr[i].order;
if (min_sg_len && (size / min_sg_len < len))
len = ALIGN(size / min_sg_len, 512); if (len > sz)
len = sz; if (len > max_seg_sz)
len = max_seg_sz; 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.
*/ staticint mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem, unsignedlong sz, struct scatterlist *sglist, unsignedint max_segs, unsignedint max_seg_sz, unsignedint *sg_len)
{ struct scatterlist *sg = NULL; unsignedint i = mem->cnt, cnt; unsignedlong len; void *base, *addr, *last_addr = NULL;
sg_init_table(sglist, max_segs);
*sg_len = 0; while (sz) {
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; if (len > max_seg_sz)
len = max_seg_sz; if (len > sz)
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;
} if (i == 0)
i = mem->cnt;
}
if (sg)
sg_mark_end(sg);
return 0;
}
/* * Calculate transfer rate in bytes per second.
*/ staticunsignedint mmc_test_rate(uint64_t bytes, struct timespec64 *ts)
{
uint64_t ns;
ns = timespec64_to_ns(ts);
bytes *= 1000000000;
while (ns > UINT_MAX) {
bytes >>= 1;
ns >>= 1;
}
if (!ns) return 0;
do_div(bytes, (uint32_t)ns);
return bytes;
}
/* * Save transfer results for future usage
*/ staticvoid mmc_test_save_transfer_result(struct mmc_test_card *test, unsignedint count, unsignedint sectors, struct timespec64 ts, unsignedint rate, unsignedint iops)
{ struct mmc_test_transfer_result *tr;
if (!test->gr) return;
tr = kmalloc(sizeof(*tr), GFP_KERNEL); if (!tr) return;
/* * Return the card size in sectors.
*/ staticunsignedint 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);
}
/*******************************************************************/ /* Test preparation and cleanup */ /*******************************************************************/
/* * Fill the first couple of sectors of the card with known data * so that bad reads/writes can be detected
*/ staticint __mmc_test_prepare(struct mmc_test_card *test, int write, int val)
{ int ret, i;
ret = mmc_test_set_blksize(test, 512); if (ret) return ret;
if (write)
memset(test->buffer, val, 512); else { for (i = 0; i < 512; i++)
test->buffer[i] = i;
}
for (i = 0; i < BUFFER_SIZE / 512; i++) {
ret = mmc_test_buffer_transfer(test, test->buffer, i, 512, 1); if (ret) return ret;
}
/* * Checks that a normal transfer didn't have any errors
*/ staticint mmc_test_check_result(struct mmc_test_card *test, struct mmc_request *mrq)
{ int ret;
if (WARN_ON(!mrq || !mrq->cmd || !mrq->data)) return -EINVAL;
ret = 0;
if (mrq->sbc && mrq->sbc->error)
ret = mrq->sbc->error; 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;
}
/* * Checks that a "short transfer" behaved as expected
*/ staticint mmc_test_check_broken_result(struct mmc_test_card *test, struct mmc_request *mrq)
{ int ret;
if (WARN_ON(!mrq || !mrq->cmd || !mrq->data)) return -EINVAL;
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;
}
/* * Does a complete transfer test where data is also validated * * Note: mmc_test_prepare() must have been done before this call
*/ staticint 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;
if (write) { for (i = 0; i < blocks * blksz; i++)
test->scratch[i] = i;
} else {
memset(test->scratch, 0, BUFFER_SIZE);
}
sg_copy_from_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
ret = mmc_test_set_blksize(test, blksz); if (ret) return ret;
ret = mmc_test_simple_transfer(test, sg, sg_len, dev_addr,
blocks, blksz, write); if (ret) return ret;
if (write) { int sectors;
ret = mmc_test_set_blksize(test, 512); if (ret) return ret;
for (i = 1; i < TEST_ALIGN_END; i++) {
sg_init_one(&sg, test->buffer + i, 512);
ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1); if (ret) return ret;
}
for (i = 1; i < TEST_ALIGN_END; i++) {
sg_init_one(&sg, test->buffer + i, 512);
ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0); if (ret) return ret;
}
for (i = 1; i < TEST_ALIGN_END; i++) {
sg_init_one(&sg, test->buffer + i, size);
ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1); if (ret) return ret;
}
for (i = 1; i < TEST_ALIGN_END; i++) {
sg_init_one(&sg, test->buffer + i, size);
ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0); if (ret) return ret;
}
return 0;
}
staticint mmc_test_xfersize_write(struct mmc_test_card *test)
{ int ret;
ret = mmc_test_set_blksize(test, 512); if (ret) return ret;
staticint mmc_test_no_highmem(struct mmc_test_card *test)
{
pr_info("%s: Highmem not configured - test skipped\n",
mmc_hostname(test->card->host)); return 0;
}
#endif/* CONFIG_HIGHMEM */
/* * Map sz bytes so that it can be transferred.
*/ staticint mmc_test_area_map(struct mmc_test_card *test, unsignedlong sz, int max_scatter, int min_sg_len, bool nonblock)
{ struct mmc_test_area *t = &test->area; int err; unsignedint sg_len = 0;
/* * Map and transfer bytes for multiple transfers.
*/ staticint mmc_test_area_io_seq(struct mmc_test_card *test, unsignedlong sz, unsignedint dev_addr, int write, int max_scatter, int timed, int count, bool nonblock, int min_sg_len)
{ struct timespec64 ts1, ts2; int ret = 0; int i;
/* * 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; unsignedlong max_tfr;
ret = mmc_test_area_map(test, sz, max_scatter, min_sg_len, nonblock); if (ret) return ret;
if (timed)
ktime_get_ts64(&ts1); if (nonblock)
ret = mmc_test_nonblock_transfer(test, dev_addr, write, count); else for (i = 0; i < count && ret == 0; i++) {
ret = mmc_test_area_transfer(test, dev_addr, write);
dev_addr += sz >> 9;
}
if (ret) return ret;
if (timed)
ktime_get_ts64(&ts2);
if (timed)
mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2);
return 0;
}
staticint mmc_test_area_io(struct mmc_test_card *test, unsignedlong sz, unsignedint dev_addr, int write, int max_scatter, int timed)
{ return mmc_test_area_io_seq(test, sz, dev_addr, write, max_scatter,
timed, 1, false, 0);
}
/* * Write the test area entirely.
*/ staticint mmc_test_area_fill(struct mmc_test_card *test)
{ struct mmc_test_area *t = &test->area;
/* * Initialize an area for testing large transfers. The test area is set to the * middle of the card because cards may have different characteristics 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.
*/ staticint mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
{ struct mmc_test_area *t = &test->area; unsignedlong min_sz = 64 * 1024, sz; int ret;
ret = mmc_test_set_blksize(test, 512); if (ret) return ret;
/* Make the test area size about 4MiB */
sz = (unsignedlong)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;
/* * Try to allocate enough memory for a max. sized transfer. Less is OK * because the same memory can be mapped into the scatterlist more than * once. Also, take into account the limits imposed on scatterlist * segments by the host driver.
*/
t->mem = mmc_test_alloc_mem(min_sz, t->max_tfr, t->max_segs,
t->max_seg_sz); if (!t->mem) return -ENOMEM;
t->sg = kmalloc_array(t->max_segs, sizeof(*t->sg), GFP_KERNEL); if (!t->sg) {
ret = -ENOMEM; goto out_free;
}
t->sg_areq = kmalloc_array(t->max_segs, sizeof(*t->sg_areq),
GFP_KERNEL); if (!t->sg_areq) {
ret = -ENOMEM; goto out_free;
}
/* * Prepare for large transfers. Do not erase the test area.
*/ staticint 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.
*/ staticint 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.
*/ staticint 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.
*/ staticint mmc_test_best_performance(struct mmc_test_card *test, int write, int max_scatter)
{ struct mmc_test_area *t = &test->area;
ktime_get_ts64(&ts1); for (cnt = 0; cnt < UINT_MAX; cnt++) {
ktime_get_ts64(&ts2);
ts = timespec64_sub(ts2, ts1); if (ts.tv_sec >= secs) 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); if (force_retuning)
mmc_retune_needed(test->card->host);
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;
}
staticint mmc_test_random_perf(struct mmc_test_card *test, int write)
{ struct mmc_test_area *t = &test->area; unsignedint next; unsignedlong sz; int ret;
for (sz = 512; sz < t->max_tfr; sz <<= 1) { /* * 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, 10, 0); if (ret) return ret;
rnd_next = next;
}
ret = mmc_test_rnd_perf(test, write, 1, sz, 10, 0); if (ret) return ret;
}
sz = t->max_tfr; if (write) {
next = rnd_next;
ret = mmc_test_rnd_perf(test, write, 0, sz, 10, 0); if (ret) return ret;
rnd_next = next;
} return mmc_test_rnd_perf(test, write, 1, sz, 10, 0);
}
staticint mmc_test_retuning(struct mmc_test_card *test)
{ if (!mmc_can_retune(test->card->host)) {
pr_info("%s: No retuning - test skipped\n",
mmc_hostname(test->card->host)); return RESULT_UNSUP_HOST;
}
/* * Random read performance by transfer size.
*/ staticint mmc_test_random_read_perf(struct mmc_test_card *test)
{ return mmc_test_random_perf(test, 0);
}
/* * Random write performance by transfer size.
*/ staticint mmc_test_random_write_perf(struct mmc_test_card *test)
{ return mmc_test_random_perf(test, 1);
}
staticint mmc_test_seq_perf(struct mmc_test_card *test, int write, unsignedint tot_sz, int max_scatter)
{ struct mmc_test_area *t = &test->area; unsignedint dev_addr, i, cnt, sz, ssz; struct timespec64 ts1, ts2; int ret;
sz = t->max_tfr;
/* * In the case of a maximally scattered transfer, the maximum transfer * size is further limited by using PAGE_SIZE segments.
*/ if (max_scatter) { unsignedlong max_tfr;
staticint 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;
}
staticint mmc_test_rw_multiple(struct mmc_test_card *test, struct mmc_test_multiple_rw *tdata, unsignedint reqsize, unsignedint size, int min_sg_len)
{ unsignedint 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_card_can_erase(test->card) &&
tdata->prepare & MMC_TEST_PREP_ERASE) {
ret = mmc_erase(test->card, dev_addr,
size / 512, test->card->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,
tdata->do_nonblock_req, min_sg_len); if (ret) goto err;
staticint 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))) {
pr_info("error: only one of pre/post is defined\n"); return -EINVAL;
}
for (i = 0 ; i < rw->len && ret == 0; i++) {
ret = mmc_test_rw_multiple(test, rw, rw->bs[i], rw->size, 0); if (ret) break;
} return ret;
}
staticint 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]); if (ret) break;
} return ret;
}
err = mmc_hw_reset(card); if (!err) { /* * Reset will re-enable the card's command queue, but tests * expect it to be disabled.
*/ if (card->ext_csd.cmdq_en)
mmc_cmdq_disable(card); return RESULT_OK;
} elseif (err == -EOPNOTSUPP) { return RESULT_UNSUP_HOST;
}
if (use_sbc && t->blocks > 1 && !mrq->sbc) {
ret = mmc_host_can_cmd23(host) ?
RESULT_UNSUP_CARD :
RESULT_UNSUP_HOST; goto out_free;
}
/* Start ongoing data request */ if (use_areq) {
ret = mmc_test_start_areq(test, mrq, NULL); if (ret) goto out_free;
} 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 */ if (use_areq) {
ret = mmc_test_start_areq(test, NULL, mrq);
} else {
mmc_wait_for_req_done(test->card->host, mrq);
}
/* * 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;
}
staticint __mmc_test_cmds_during_tfr(struct mmc_test_card *test, unsignedlong 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, use_areq); if (ret) return ret;
ret = mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 0, write,
use_areq); if (ret) return ret;
staticint 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; unsignedlong 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).
*/ staticint 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).
*/ staticint 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).
*/ staticint 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).
*/ staticint 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).
*/ staticint 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).
*/ staticint mmc_test_cmds_during_write_cmd23_nonblock(struct mmc_test_card *test)
{ return mmc_test_cmds_during_tfr(test, 1, 1, 1);
}
staticconststruct 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,
},
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.