blob: bdda8d552f01d030caa20436239d81d59c08b619 [file] [log] [blame]
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14/* MMC block test */
15
16#include <linux/module.h>
17#include <linux/blkdev.h>
18#include <linux/debugfs.h>
19#include <linux/mmc/card.h>
20#include <linux/mmc/host.h>
21#include <linux/delay.h>
22#include <linux/test-iosched.h>
23#include "queue.h"
24
25#define MODULE_NAME "mmc_block_test"
26#define TEST_MAX_SECTOR_RANGE (600*1024*1024) /* 600 MB */
27#define TEST_MAX_BIOS_PER_REQ 120
28#define CMD23_PACKED_BIT (1 << 30)
29#define LARGE_PRIME_1 1103515367
30#define LARGE_PRIME_2 35757
31#define PACKED_HDR_VER_MASK 0x000000FF
32#define PACKED_HDR_RW_MASK 0x0000FF00
33#define PACKED_HDR_NUM_REQS_MASK 0x00FF0000
34#define PACKED_HDR_BITS_16_TO_29_SET 0x3FFF0000
35
36#define test_pr_debug(fmt, args...) pr_debug("%s: "fmt"\n", MODULE_NAME, args)
37#define test_pr_info(fmt, args...) pr_info("%s: "fmt"\n", MODULE_NAME, args)
38#define test_pr_err(fmt, args...) pr_err("%s: "fmt"\n", MODULE_NAME, args)
39
40enum is_random {
41 NON_RANDOM_TEST,
42 RANDOM_TEST,
43};
44
45enum mmc_block_test_testcases {
46 /* Start of send write packing test group */
47 SEND_WRITE_PACKING_MIN_TESTCASE,
48 TEST_STOP_DUE_TO_READ = SEND_WRITE_PACKING_MIN_TESTCASE,
49 TEST_STOP_DUE_TO_READ_AFTER_MAX_REQS,
50 TEST_STOP_DUE_TO_FLUSH,
51 TEST_STOP_DUE_TO_FLUSH_AFTER_MAX_REQS,
52 TEST_STOP_DUE_TO_EMPTY_QUEUE,
53 TEST_STOP_DUE_TO_MAX_REQ_NUM,
54 TEST_STOP_DUE_TO_THRESHOLD,
55 SEND_WRITE_PACKING_MAX_TESTCASE = TEST_STOP_DUE_TO_THRESHOLD,
56
57 /* Start of err check test group */
58 ERR_CHECK_MIN_TESTCASE,
59 TEST_RET_ABORT = ERR_CHECK_MIN_TESTCASE,
60 TEST_RET_PARTIAL_FOLLOWED_BY_SUCCESS,
61 TEST_RET_PARTIAL_FOLLOWED_BY_ABORT,
62 TEST_RET_PARTIAL_MULTIPLE_UNTIL_SUCCESS,
63 TEST_RET_PARTIAL_MAX_FAIL_IDX,
64 TEST_RET_RETRY,
65 TEST_RET_CMD_ERR,
66 TEST_RET_DATA_ERR,
67 ERR_CHECK_MAX_TESTCASE = TEST_RET_DATA_ERR,
68
69 /* Start of send invalid test group */
70 INVALID_CMD_MIN_TESTCASE,
71 TEST_HDR_INVALID_VERSION = INVALID_CMD_MIN_TESTCASE,
72 TEST_HDR_WRONG_WRITE_CODE,
73 TEST_HDR_INVALID_RW_CODE,
74 TEST_HDR_DIFFERENT_ADDRESSES,
75 TEST_HDR_REQ_NUM_SMALLER_THAN_ACTUAL,
76 TEST_HDR_REQ_NUM_LARGER_THAN_ACTUAL,
77 TEST_HDR_CMD23_PACKED_BIT_SET,
78 TEST_CMD23_MAX_PACKED_WRITES,
79 TEST_CMD23_ZERO_PACKED_WRITES,
80 TEST_CMD23_PACKED_BIT_UNSET,
81 TEST_CMD23_REL_WR_BIT_SET,
82 TEST_CMD23_BITS_16TO29_SET,
83 TEST_CMD23_HDR_BLK_NOT_IN_COUNT,
84 INVALID_CMD_MAX_TESTCASE = TEST_CMD23_HDR_BLK_NOT_IN_COUNT,
Tatyana Brokhman91e1e322012-10-09 13:53:43 +020085
86 /*
87 * Start of packing control test group.
88 * in these next testcases the abbreviation FB = followed by
89 */
90 PACKING_CONTROL_MIN_TESTCASE,
91 TEST_PACKING_EXP_ONE_OVER_TRIGGER_FB_READ =
92 PACKING_CONTROL_MIN_TESTCASE,
93 TEST_PACKING_EXP_N_OVER_TRIGGER,
94 TEST_PACKING_EXP_N_OVER_TRIGGER_FB_READ,
95 TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N,
96 TEST_PACKING_EXP_THRESHOLD_OVER_TRIGGER,
97 TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS,
98 TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS,
99 TEST_PACKING_NOT_EXP_TRIGGER_READ_TRIGGER,
100 TEST_PACKING_NOT_EXP_TRIGGER_FLUSH_TRIGGER,
101 TEST_PACK_MIX_PACKED_NO_PACKED_PACKED,
102 TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED,
103 PACKING_CONTROL_MAX_TESTCASE = TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED,
Tatyana Brokhman09b010d2012-10-09 13:50:56 +0200104};
105
106enum mmc_block_test_group {
107 TEST_NO_GROUP,
108 TEST_GENERAL_GROUP,
109 TEST_SEND_WRITE_PACKING_GROUP,
110 TEST_ERR_CHECK_GROUP,
111 TEST_SEND_INVALID_GROUP,
Tatyana Brokhman91e1e322012-10-09 13:53:43 +0200112 TEST_PACKING_CONTROL_GROUP,
Tatyana Brokhman09b010d2012-10-09 13:50:56 +0200113};
114
115struct mmc_block_test_debug {
116 struct dentry *send_write_packing_test;
117 struct dentry *err_check_test;
118 struct dentry *send_invalid_packed_test;
119 struct dentry *random_test_seed;
Tatyana Brokhman91e1e322012-10-09 13:53:43 +0200120 struct dentry *packing_control_test;
Tatyana Brokhman09b010d2012-10-09 13:50:56 +0200121};
122
123struct mmc_block_test_data {
124 /* The number of write requests that the test will issue */
125 int num_requests;
126 /* The expected write packing statistics for the current test */
127 struct mmc_wr_pack_stats exp_packed_stats;
128 /*
129 * A user-defined seed for random choices of number of bios written in
130 * a request, and of number of requests issued in a test
131 * This field is randomly updated after each use
132 */
133 unsigned int random_test_seed;
134 /* A retry counter used in err_check tests */
135 int err_check_counter;
136 /* Can be one of the values of enum test_group */
137 enum mmc_block_test_group test_group;
138 /*
139 * Indicates if the current testcase is running with random values of
140 * num_requests and num_bios (in each request)
141 */
142 int is_random;
143 /* Data structure for debugfs dentrys */
144 struct mmc_block_test_debug debug;
145 /*
146 * Data structure containing individual test information, including
147 * self-defined specific data
148 */
149 struct test_info test_info;
150 /* mmc block device test */
151 struct blk_dev_test_type bdt;
152};
153
154static struct mmc_block_test_data *mbtd;
155
156/*
157 * A callback assigned to the packed_test_fn field.
158 * Called from block layer in mmc_blk_packed_hdr_wrq_prep.
159 * Here we alter the packed header or CMD23 in order to send an invalid
160 * packed command to the card.
161 */
162static void test_invalid_packed_cmd(struct request_queue *q,
163 struct mmc_queue_req *mqrq)
164{
165 struct mmc_queue *mq = q->queuedata;
166 u32 *packed_cmd_hdr = mqrq->packed_cmd_hdr;
167 struct request *req = mqrq->req;
168 struct request *second_rq;
169 struct test_request *test_rq;
170 struct mmc_blk_request *brq = &mqrq->brq;
171 int num_requests;
172 int max_packed_reqs;
173
174 if (!mq) {
175 test_pr_err("%s: NULL mq", __func__);
176 return;
177 }
178
179 test_rq = (struct test_request *)req->elv.priv[0];
180 if (!test_rq) {
181 test_pr_err("%s: NULL test_rq", __func__);
182 return;
183 }
184 max_packed_reqs = mq->card->ext_csd.max_packed_writes;
185
186 switch (mbtd->test_info.testcase) {
187 case TEST_HDR_INVALID_VERSION:
188 test_pr_info("%s: set invalid header version", __func__);
189 /* Put 0 in header version field (1 byte, offset 0 in header) */
190 packed_cmd_hdr[0] = packed_cmd_hdr[0] & ~PACKED_HDR_VER_MASK;
191 break;
192 case TEST_HDR_WRONG_WRITE_CODE:
193 test_pr_info("%s: wrong write code", __func__);
194 /* Set R/W field with R value (1 byte, offset 1 in header) */
195 packed_cmd_hdr[0] = packed_cmd_hdr[0] & ~PACKED_HDR_RW_MASK;
196 packed_cmd_hdr[0] = packed_cmd_hdr[0] | 0x00000100;
197 break;
198 case TEST_HDR_INVALID_RW_CODE:
199 test_pr_info("%s: invalid r/w code", __func__);
200 /* Set R/W field with invalid value */
201 packed_cmd_hdr[0] = packed_cmd_hdr[0] & ~PACKED_HDR_RW_MASK;
202 packed_cmd_hdr[0] = packed_cmd_hdr[0] | 0x00000400;
203 break;
204 case TEST_HDR_DIFFERENT_ADDRESSES:
205 test_pr_info("%s: different addresses", __func__);
206 second_rq = list_entry(req->queuelist.next, struct request,
207 queuelist);
208 test_pr_info("%s: test_rq->sector=%ld, second_rq->sector=%ld",
209 __func__, (long)req->__sector,
210 (long)second_rq->__sector);
211 /*
212 * Put start sector of second write request in the first write
213 * request's cmd25 argument in the packed header
214 */
215 packed_cmd_hdr[3] = second_rq->__sector;
216 break;
217 case TEST_HDR_REQ_NUM_SMALLER_THAN_ACTUAL:
218 test_pr_info("%s: request num smaller than actual" , __func__);
219 num_requests = (packed_cmd_hdr[0] & PACKED_HDR_NUM_REQS_MASK)
220 >> 16;
221 /* num of entries is decremented by 1 */
222 num_requests = (num_requests - 1) << 16;
223 /*
224 * Set number of requests field in packed write header to be
225 * smaller than the actual number (1 byte, offset 2 in header)
226 */
227 packed_cmd_hdr[0] = (packed_cmd_hdr[0] &
228 ~PACKED_HDR_NUM_REQS_MASK) + num_requests;
229 break;
230 case TEST_HDR_REQ_NUM_LARGER_THAN_ACTUAL:
231 test_pr_info("%s: request num larger than actual" , __func__);
232 num_requests = (packed_cmd_hdr[0] & PACKED_HDR_NUM_REQS_MASK)
233 >> 16;
234 /* num of entries is incremented by 1 */
235 num_requests = (num_requests + 1) << 16;
236 /*
237 * Set number of requests field in packed write header to be
238 * larger than the actual number (1 byte, offset 2 in header).
239 */
240 packed_cmd_hdr[0] = (packed_cmd_hdr[0] &
241 ~PACKED_HDR_NUM_REQS_MASK) + num_requests;
242 break;
243 case TEST_HDR_CMD23_PACKED_BIT_SET:
244 test_pr_info("%s: header CMD23 packed bit set" , __func__);
245 /*
246 * Set packed bit (bit 30) in cmd23 argument of first and second
247 * write requests in packed write header.
248 * These are located at bytes 2 and 4 in packed write header
249 */
250 packed_cmd_hdr[2] = packed_cmd_hdr[2] | CMD23_PACKED_BIT;
251 packed_cmd_hdr[4] = packed_cmd_hdr[4] | CMD23_PACKED_BIT;
252 break;
253 case TEST_CMD23_MAX_PACKED_WRITES:
254 test_pr_info("%s: CMD23 request num > max_packed_reqs",
255 __func__);
256 /*
257 * Set the individual packed cmd23 request num to
258 * max_packed_reqs + 1
259 */
260 brq->sbc.arg = MMC_CMD23_ARG_PACKED | (max_packed_reqs + 1);
261 break;
262 case TEST_CMD23_ZERO_PACKED_WRITES:
263 test_pr_info("%s: CMD23 request num = 0", __func__);
264 /* Set the individual packed cmd23 request num to zero */
265 brq->sbc.arg = MMC_CMD23_ARG_PACKED;
266 break;
267 case TEST_CMD23_PACKED_BIT_UNSET:
268 test_pr_info("%s: CMD23 packed bit unset", __func__);
269 /*
270 * Set the individual packed cmd23 packed bit to 0,
271 * although there is a packed write request
272 */
273 brq->sbc.arg &= ~CMD23_PACKED_BIT;
274 break;
275 case TEST_CMD23_REL_WR_BIT_SET:
276 test_pr_info("%s: CMD23 REL WR bit set", __func__);
277 /* Set the individual packed cmd23 reliable write bit */
278 brq->sbc.arg = MMC_CMD23_ARG_PACKED | MMC_CMD23_ARG_REL_WR;
279 break;
280 case TEST_CMD23_BITS_16TO29_SET:
281 test_pr_info("%s: CMD23 bits [16-29] set", __func__);
282 brq->sbc.arg = MMC_CMD23_ARG_PACKED |
283 PACKED_HDR_BITS_16_TO_29_SET;
284 break;
285 case TEST_CMD23_HDR_BLK_NOT_IN_COUNT:
286 test_pr_info("%s: CMD23 hdr not in block count", __func__);
287 brq->sbc.arg = MMC_CMD23_ARG_PACKED |
288 ((rq_data_dir(req) == READ) ? 0 : mqrq->packed_blocks);
289 break;
290 default:
291 test_pr_err("%s: unexpected testcase %d",
292 __func__, mbtd->test_info.testcase);
293 break;
294 }
295}
296
297/*
298 * A callback assigned to the err_check_fn field of the mmc_request by the
299 * MMC/card/block layer.
300 * Called upon request completion by the MMC/core layer.
301 * Here we emulate an error return value from the card.
302 */
303static int test_err_check(struct mmc_card *card, struct mmc_async_req *areq)
304{
305 struct mmc_queue_req *mq_rq = container_of(areq, struct mmc_queue_req,
306 mmc_active);
307 struct request_queue *req_q = test_iosched_get_req_queue();
308 struct mmc_queue *mq;
309 int max_packed_reqs;
310 int ret = 0;
311
312 if (req_q)
313 mq = req_q->queuedata;
314 else {
315 test_pr_err("%s: NULL request_queue", __func__);
316 return 0;
317 }
318
319 if (!mq) {
320 test_pr_err("%s: %s: NULL mq", __func__,
321 mmc_hostname(card->host));
322 return 0;
323 }
324
325 max_packed_reqs = mq->card->ext_csd.max_packed_writes;
326
327 if (!mq_rq) {
328 test_pr_err("%s: %s: NULL mq_rq", __func__,
329 mmc_hostname(card->host));
330 return 0;
331 }
332
333 switch (mbtd->test_info.testcase) {
334 case TEST_RET_ABORT:
335 test_pr_info("%s: return abort", __func__);
336 ret = MMC_BLK_ABORT;
337 break;
338 case TEST_RET_PARTIAL_FOLLOWED_BY_SUCCESS:
339 test_pr_info("%s: return partial followed by success",
340 __func__);
341 /*
342 * Since in this testcase num_requests is always >= 2,
343 * we can be sure that packed_fail_idx is always >= 1
344 */
345 mq_rq->packed_fail_idx = (mbtd->num_requests / 2);
346 test_pr_info("%s: packed_fail_idx = %d"
347 , __func__, mq_rq->packed_fail_idx);
348 mq->err_check_fn = NULL;
349 ret = MMC_BLK_PARTIAL;
350 break;
351 case TEST_RET_PARTIAL_FOLLOWED_BY_ABORT:
352 if (!mbtd->err_check_counter) {
353 test_pr_info("%s: return partial followed by abort",
354 __func__);
355 mbtd->err_check_counter++;
356 /*
357 * Since in this testcase num_requests is always >= 3,
358 * we have that packed_fail_idx is always >= 1
359 */
360 mq_rq->packed_fail_idx = (mbtd->num_requests / 2);
361 test_pr_info("%s: packed_fail_idx = %d"
362 , __func__, mq_rq->packed_fail_idx);
363 ret = MMC_BLK_PARTIAL;
364 break;
365 }
366 mbtd->err_check_counter = 0;
367 mq->err_check_fn = NULL;
368 ret = MMC_BLK_ABORT;
369 break;
370 case TEST_RET_PARTIAL_MULTIPLE_UNTIL_SUCCESS:
371 test_pr_info("%s: return partial multiple until success",
372 __func__);
373 if (++mbtd->err_check_counter >= (mbtd->num_requests)) {
374 mq->err_check_fn = NULL;
375 mbtd->err_check_counter = 0;
376 ret = MMC_BLK_PARTIAL;
377 break;
378 }
379 mq_rq->packed_fail_idx = 1;
380 ret = MMC_BLK_PARTIAL;
381 break;
382 case TEST_RET_PARTIAL_MAX_FAIL_IDX:
383 test_pr_info("%s: return partial max fail_idx", __func__);
384 mq_rq->packed_fail_idx = max_packed_reqs - 1;
385 mq->err_check_fn = NULL;
386 ret = MMC_BLK_PARTIAL;
387 break;
388 case TEST_RET_RETRY:
389 test_pr_info("%s: return retry", __func__);
390 ret = MMC_BLK_RETRY;
391 break;
392 case TEST_RET_CMD_ERR:
393 test_pr_info("%s: return cmd err", __func__);
394 ret = MMC_BLK_CMD_ERR;
395 break;
396 case TEST_RET_DATA_ERR:
397 test_pr_info("%s: return data err", __func__);
398 ret = MMC_BLK_DATA_ERR;
399 break;
400 default:
401 test_pr_err("%s: unexpected testcase %d",
402 __func__, mbtd->test_info.testcase);
403 }
404
405 return ret;
406}
407
408/*
409 * This is a specific implementation for the get_test_case_str_fn function
410 * pointer in the test_info data structure. Given a valid test_data instance,
411 * the function returns a string resembling the test name, based on the testcase
412 */
413static char *get_test_case_str(struct test_data *td)
414{
415 if (!td) {
416 test_pr_err("%s: NULL td", __func__);
417 return NULL;
418 }
419
420 switch (td->test_info.testcase) {
421 case TEST_STOP_DUE_TO_FLUSH:
422 return "Test stop due to flush";
423 case TEST_STOP_DUE_TO_FLUSH_AFTER_MAX_REQS:
424 return "Test stop due to flush after max-1 reqs";
425 case TEST_STOP_DUE_TO_READ:
426 return "Test stop due to read";
427 case TEST_STOP_DUE_TO_READ_AFTER_MAX_REQS:
428 return "Test stop due to read after max-1 reqs";
429 case TEST_STOP_DUE_TO_EMPTY_QUEUE:
430 return "Test stop due to empty queue";
431 case TEST_STOP_DUE_TO_MAX_REQ_NUM:
432 return "Test stop due to max req num";
433 case TEST_STOP_DUE_TO_THRESHOLD:
434 return "Test stop due to exceeding threshold";
435 case TEST_RET_ABORT:
436 return "Test err_check return abort";
437 case TEST_RET_PARTIAL_FOLLOWED_BY_SUCCESS:
438 return "Test err_check return partial followed by success";
439 case TEST_RET_PARTIAL_FOLLOWED_BY_ABORT:
440 return "Test err_check return partial followed by abort";
441 case TEST_RET_PARTIAL_MULTIPLE_UNTIL_SUCCESS:
442 return "Test err_check return partial multiple until success";
443 case TEST_RET_PARTIAL_MAX_FAIL_IDX:
444 return "Test err_check return partial max fail index";
445 case TEST_RET_RETRY:
446 return "Test err_check return retry";
447 case TEST_RET_CMD_ERR:
448 return "Test err_check return cmd error";
449 case TEST_RET_DATA_ERR:
450 return "Test err_check return data error";
451 case TEST_HDR_INVALID_VERSION:
452 return "Test invalid - wrong header version";
453 case TEST_HDR_WRONG_WRITE_CODE:
454 return "Test invalid - wrong write code";
455 case TEST_HDR_INVALID_RW_CODE:
456 return "Test invalid - wrong R/W code";
457 case TEST_HDR_DIFFERENT_ADDRESSES:
458 return "Test invalid - header different addresses";
459 case TEST_HDR_REQ_NUM_SMALLER_THAN_ACTUAL:
460 return "Test invalid - header req num smaller than actual";
461 case TEST_HDR_REQ_NUM_LARGER_THAN_ACTUAL:
462 return "Test invalid - header req num larger than actual";
463 case TEST_HDR_CMD23_PACKED_BIT_SET:
464 return "Test invalid - header cmd23 packed bit set";
465 case TEST_CMD23_MAX_PACKED_WRITES:
466 return "Test invalid - cmd23 max packed writes";
467 case TEST_CMD23_ZERO_PACKED_WRITES:
468 return "Test invalid - cmd23 zero packed writes";
469 case TEST_CMD23_PACKED_BIT_UNSET:
470 return "Test invalid - cmd23 packed bit unset";
471 case TEST_CMD23_REL_WR_BIT_SET:
472 return "Test invalid - cmd23 rel wr bit set";
473 case TEST_CMD23_BITS_16TO29_SET:
474 return "Test invalid - cmd23 bits [16-29] set";
475 case TEST_CMD23_HDR_BLK_NOT_IN_COUNT:
476 return "Test invalid - cmd23 header block not in count";
Tatyana Brokhman91e1e322012-10-09 13:53:43 +0200477 case TEST_PACKING_EXP_N_OVER_TRIGGER:
478 return "\nTest packing control - pack n";
479 case TEST_PACKING_EXP_N_OVER_TRIGGER_FB_READ:
480 return "\nTest packing control - pack n followed by read";
481 case TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N:
482 return "\nTest packing control - pack n followed by flush";
483 case TEST_PACKING_EXP_ONE_OVER_TRIGGER_FB_READ:
484 return "\nTest packing control - pack one followed by read";
485 case TEST_PACKING_EXP_THRESHOLD_OVER_TRIGGER:
486 return "\nTest packing control - pack threshold";
487 case TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS:
488 return "\nTest packing control - no packing";
489 case TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS:
490 return "\nTest packing control - no packing, trigger requests";
491 case TEST_PACKING_NOT_EXP_TRIGGER_READ_TRIGGER:
492 return "\nTest packing control - no pack, trigger-read-trigger";
493 case TEST_PACKING_NOT_EXP_TRIGGER_FLUSH_TRIGGER:
494 return "\nTest packing control- no pack, trigger-flush-trigger";
495 case TEST_PACK_MIX_PACKED_NO_PACKED_PACKED:
496 return "\nTest packing control - mix: pack -> no pack -> pack";
497 case TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED:
498 return "\nTest packing control - mix: no pack->pack->no pack";
Tatyana Brokhman09b010d2012-10-09 13:50:56 +0200499 default:
500 return "Unknown testcase";
501 }
502
503 return NULL;
504}
505
506/*
507 * Compare individual testcase's statistics to the expected statistics:
508 * Compare stop reason and number of packing events
509 */
510static int check_wr_packing_statistics(struct test_data *td)
511{
512 struct mmc_wr_pack_stats *mmc_packed_stats;
513 struct mmc_queue *mq = td->req_q->queuedata;
514 int max_packed_reqs = mq->card->ext_csd.max_packed_writes;
515 int i;
516 struct mmc_card *card = mq->card;
517 struct mmc_wr_pack_stats expected_stats;
518 int *stop_reason;
519 int ret = 0;
520
521 if (!mq) {
522 test_pr_err("%s: NULL mq", __func__);
523 return -EINVAL;
524 }
525
526 expected_stats = mbtd->exp_packed_stats;
527
528 mmc_packed_stats = mmc_blk_get_packed_statistics(card);
529 if (!mmc_packed_stats) {
530 test_pr_err("%s: NULL mmc_packed_stats", __func__);
531 return -EINVAL;
532 }
533
534 if (!mmc_packed_stats->packing_events) {
535 test_pr_err("%s: NULL packing_events", __func__);
536 return -EINVAL;
537 }
538
539 spin_lock(&mmc_packed_stats->lock);
540
541 if (!mmc_packed_stats->enabled) {
542 test_pr_err("%s write packing statistics are not enabled",
543 __func__);
544 ret = -EINVAL;
545 goto exit_err;
546 }
547
548 stop_reason = mmc_packed_stats->pack_stop_reason;
549
Tatyana Brokhman91e1e322012-10-09 13:53:43 +0200550 for (i = 1; i <= max_packed_reqs; ++i) {
Tatyana Brokhman09b010d2012-10-09 13:50:56 +0200551 if (mmc_packed_stats->packing_events[i] !=
552 expected_stats.packing_events[i]) {
553 test_pr_err(
554 "%s: Wrong pack stats in index %d, got %d, expected %d",
555 __func__, i, mmc_packed_stats->packing_events[i],
556 expected_stats.packing_events[i]);
557 if (td->fs_wr_reqs_during_test)
558 goto cancel_round;
559 ret = -EINVAL;
560 goto exit_err;
561 }
562 }
563
564 if (mmc_packed_stats->pack_stop_reason[EXCEEDS_SEGMENTS] !=
565 expected_stats.pack_stop_reason[EXCEEDS_SEGMENTS]) {
566 test_pr_err(
567 "%s: Wrong pack stop reason EXCEEDS_SEGMENTS %d, expected %d",
568 __func__, stop_reason[EXCEEDS_SEGMENTS],
569 expected_stats.pack_stop_reason[EXCEEDS_SEGMENTS]);
570 if (td->fs_wr_reqs_during_test)
571 goto cancel_round;
572 ret = -EINVAL;
573 goto exit_err;
574 }
575
576 if (mmc_packed_stats->pack_stop_reason[EXCEEDS_SECTORS] !=
577 expected_stats.pack_stop_reason[EXCEEDS_SECTORS]) {
578 test_pr_err(
579 "%s: Wrong pack stop reason EXCEEDS_SECTORS %d, expected %d",
580 __func__, stop_reason[EXCEEDS_SECTORS],
581 expected_stats.pack_stop_reason[EXCEEDS_SECTORS]);
582 if (td->fs_wr_reqs_during_test)
583 goto cancel_round;
584 ret = -EINVAL;
585 goto exit_err;
586 }
587
588 if (mmc_packed_stats->pack_stop_reason[WRONG_DATA_DIR] !=
589 expected_stats.pack_stop_reason[WRONG_DATA_DIR]) {
590 test_pr_err(
591 "%s: Wrong pack stop reason WRONG_DATA_DIR %d, expected %d",
592 __func__, stop_reason[WRONG_DATA_DIR],
593 expected_stats.pack_stop_reason[WRONG_DATA_DIR]);
594 if (td->fs_wr_reqs_during_test)
595 goto cancel_round;
596 ret = -EINVAL;
597 goto exit_err;
598 }
599
600 if (mmc_packed_stats->pack_stop_reason[FLUSH_OR_DISCARD] !=
601 expected_stats.pack_stop_reason[FLUSH_OR_DISCARD]) {
602 test_pr_err(
603 "%s: Wrong pack stop reason FLUSH_OR_DISCARD %d, expected %d",
604 __func__, stop_reason[FLUSH_OR_DISCARD],
605 expected_stats.pack_stop_reason[FLUSH_OR_DISCARD]);
606 if (td->fs_wr_reqs_during_test)
607 goto cancel_round;
608 ret = -EINVAL;
609 goto exit_err;
610 }
611
612 if (mmc_packed_stats->pack_stop_reason[EMPTY_QUEUE] !=
613 expected_stats.pack_stop_reason[EMPTY_QUEUE]) {
614 test_pr_err(
615 "%s: Wrong pack stop reason EMPTY_QUEUE %d, expected %d",
616 __func__, stop_reason[EMPTY_QUEUE],
617 expected_stats.pack_stop_reason[EMPTY_QUEUE]);
618 if (td->fs_wr_reqs_during_test)
619 goto cancel_round;
620 ret = -EINVAL;
621 goto exit_err;
622 }
623
624 if (mmc_packed_stats->pack_stop_reason[REL_WRITE] !=
625 expected_stats.pack_stop_reason[REL_WRITE]) {
626 test_pr_err(
627 "%s: Wrong pack stop reason REL_WRITE %d, expected %d",
628 __func__, stop_reason[REL_WRITE],
629 expected_stats.pack_stop_reason[REL_WRITE]);
630 if (td->fs_wr_reqs_during_test)
631 goto cancel_round;
632 ret = -EINVAL;
633 goto exit_err;
634 }
635
636exit_err:
637 spin_unlock(&mmc_packed_stats->lock);
638 if (ret && mmc_packed_stats->enabled)
639 print_mmc_packing_stats(card);
640 return ret;
641cancel_round:
642 spin_unlock(&mmc_packed_stats->lock);
643 test_iosched_set_ignore_round(true);
644 return 0;
645}
646
647/*
648 * Pseudo-randomly choose a seed based on the last seed, and update it in
649 * seed_number. then return seed_number (mod max_val), or min_val.
650 */
651static unsigned int pseudo_random_seed(unsigned int *seed_number,
652 unsigned int min_val,
653 unsigned int max_val)
654{
655 int ret = 0;
656
657 if (!seed_number)
658 return 0;
659
660 *seed_number = ((unsigned int)(((unsigned long)*seed_number *
661 (unsigned long)LARGE_PRIME_1) + LARGE_PRIME_2));
662 ret = (unsigned int)((*seed_number) % max_val);
663
664 return (ret > min_val ? ret : min_val);
665}
666
667/*
668 * Given a pseudo-random seed, find a pseudo-random num_of_bios.
669 * Make sure that num_of_bios is not larger than TEST_MAX_SECTOR_RANGE
670 */
671static void pseudo_rnd_num_of_bios(unsigned int *num_bios_seed,
672 unsigned int *num_of_bios)
673{
674 do {
675 *num_of_bios = pseudo_random_seed(num_bios_seed, 1,
676 TEST_MAX_BIOS_PER_REQ);
677 if (!(*num_of_bios))
678 *num_of_bios = 1;
679 } while ((*num_of_bios) * BIO_U32_SIZE * 4 > TEST_MAX_SECTOR_RANGE);
680}
681
682/* Add a single read request to the given td's request queue */
683static int prepare_request_add_read(struct test_data *td)
684{
685 int ret;
686 int start_sec;
687
688 if (td)
689 start_sec = td->start_sector;
690 else {
691 test_pr_err("%s: NULL td", __func__);
692 return 0;
693 }
694
695 test_pr_info("%s: Adding a read request, first req_id=%d", __func__,
696 td->wr_rd_next_req_id);
697
698 ret = test_iosched_add_wr_rd_test_req(0, READ, start_sec, 2,
699 TEST_PATTERN_5A, NULL);
700 if (ret) {
701 test_pr_err("%s: failed to add a read request", __func__);
702 return ret;
703 }
704
705 return 0;
706}
707
708/* Add a single flush request to the given td's request queue */
709static int prepare_request_add_flush(struct test_data *td)
710{
711 int ret;
712
713 if (!td) {
714 test_pr_err("%s: NULL td", __func__);
715 return 0;
716 }
717
718 test_pr_info("%s: Adding a flush request, first req_id=%d", __func__,
719 td->unique_next_req_id);
720 ret = test_iosched_add_unique_test_req(0, REQ_UNIQUE_FLUSH,
721 0, 0, NULL);
722 if (ret) {
723 test_pr_err("%s: failed to add a flush request", __func__);
724 return ret;
725 }
726
727 return ret;
728}
729
730/*
731 * Add num_requets amount of write requests to the given td's request queue.
732 * If random test mode is chosen we pseudo-randomly choose the number of bios
733 * for each write request, otherwise add between 1 to 5 bio per request.
734 */
735static int prepare_request_add_write_reqs(struct test_data *td,
736 int num_requests, int is_err_expected,
737 int is_random)
738{
739 int i;
740 unsigned int start_sec;
741 int num_bios;
742 int ret = 0;
743 unsigned int *bio_seed = &mbtd->random_test_seed;
744
745 if (td)
746 start_sec = td->start_sector;
747 else {
748 test_pr_err("%s: NULL td", __func__);
749 return ret;
750 }
751
752 test_pr_info("%s: Adding %d write requests, first req_id=%d", __func__,
753 num_requests, td->wr_rd_next_req_id);
754
Tatyana Brokhman91e1e322012-10-09 13:53:43 +0200755 for (i = 1; i <= num_requests; i++) {
Tatyana Brokhman09b010d2012-10-09 13:50:56 +0200756 start_sec = td->start_sector + 4096 * td->num_of_write_bios;
757 if (is_random)
758 pseudo_rnd_num_of_bios(bio_seed, &num_bios);
759 else
760 /*
761 * For the non-random case, give num_bios a value
762 * between 1 and 5, to keep a small number of BIOs
763 */
764 num_bios = (i%5)+1;
765
766 ret = test_iosched_add_wr_rd_test_req(is_err_expected, WRITE,
767 start_sec, num_bios, TEST_PATTERN_5A, NULL);
768
769 if (ret) {
770 test_pr_err("%s: failed to add a write request",
771 __func__);
772 return ret;
773 }
774 }
775 return 0;
776}
777
778/*
779 * Prepare the write, read and flush requests for a generic packed commands
780 * testcase
781 */
782static int prepare_packed_requests(struct test_data *td, int is_err_expected,
783 int num_requests, int is_random)
784{
785 int ret = 0;
786 struct mmc_queue *mq;
787 int max_packed_reqs;
788 struct request_queue *req_q;
789
790 if (!td) {
791 pr_err("%s: NULL td", __func__);
792 return -EINVAL;
793 }
794
795 req_q = td->req_q;
796
797 if (!req_q) {
798 pr_err("%s: NULL request queue", __func__);
799 return -EINVAL;
800 }
801
802 mq = req_q->queuedata;
803 if (!mq) {
804 test_pr_err("%s: NULL mq", __func__);
805 return -EINVAL;
806 }
807
808 max_packed_reqs = mq->card->ext_csd.max_packed_writes;
809
810 if (mbtd->random_test_seed <= 0) {
811 mbtd->random_test_seed =
812 (unsigned int)(get_jiffies_64() & 0xFFFF);
813 test_pr_info("%s: got seed from jiffies %d",
814 __func__, mbtd->random_test_seed);
815 }
816
817 mmc_blk_init_packed_statistics(mq->card);
818
819 ret = prepare_request_add_write_reqs(td, num_requests, is_err_expected,
820 is_random);
821 if (ret)
822 return ret;
823
824 /* Avoid memory corruption in upcoming stats set */
825 if (td->test_info.testcase == TEST_STOP_DUE_TO_THRESHOLD)
826 num_requests--;
827
828 memset((void *)mbtd->exp_packed_stats.pack_stop_reason, 0,
829 sizeof(mbtd->exp_packed_stats.pack_stop_reason));
830 memset(mbtd->exp_packed_stats.packing_events, 0,
831 (max_packed_reqs + 1) * sizeof(u32));
832 if (num_requests <= max_packed_reqs)
833 mbtd->exp_packed_stats.packing_events[num_requests] = 1;
834
835 switch (td->test_info.testcase) {
836 case TEST_STOP_DUE_TO_FLUSH:
837 case TEST_STOP_DUE_TO_FLUSH_AFTER_MAX_REQS:
838 ret = prepare_request_add_flush(td);
839 if (ret)
840 return ret;
841
842 mbtd->exp_packed_stats.pack_stop_reason[FLUSH_OR_DISCARD] = 1;
843 break;
844 case TEST_STOP_DUE_TO_READ:
845 case TEST_STOP_DUE_TO_READ_AFTER_MAX_REQS:
846 ret = prepare_request_add_read(td);
847 if (ret)
848 return ret;
849
850 mbtd->exp_packed_stats.pack_stop_reason[WRONG_DATA_DIR] = 1;
851 break;
852 case TEST_STOP_DUE_TO_THRESHOLD:
853 mbtd->exp_packed_stats.packing_events[num_requests] = 1;
854 mbtd->exp_packed_stats.packing_events[1] = 1;
855 mbtd->exp_packed_stats.pack_stop_reason[THRESHOLD] = 1;
856 mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
857 break;
858 case TEST_STOP_DUE_TO_MAX_REQ_NUM:
859 case TEST_RET_PARTIAL_MAX_FAIL_IDX:
860 mbtd->exp_packed_stats.pack_stop_reason[THRESHOLD] = 1;
861 break;
862 default:
863 mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
864 }
865 mbtd->num_requests = num_requests;
866
867 return 0;
868}
869
870/*
Tatyana Brokhman91e1e322012-10-09 13:53:43 +0200871 * Prepare the write, read and flush requests for the packing control
872 * testcases
873 */
874static int prepare_packed_control_tests_requests(struct test_data *td,
875 int is_err_expected, int num_requests, int is_random)
876{
877 int ret = 0;
878 struct mmc_queue *mq;
879 int max_packed_reqs;
880 int temp_num_req = num_requests;
881 struct request_queue *req_q;
882 int test_packed_trigger;
883 int num_packed_reqs;
884
885 if (!td) {
886 test_pr_err("%s: NULL td\n", __func__);
887 return -EINVAL;
888 }
889
890 req_q = td->req_q;
891
892 if (!req_q) {
893 test_pr_err("%s: NULL request queue\n", __func__);
894 return -EINVAL;
895 }
896
897 mq = req_q->queuedata;
898 if (!mq) {
899 test_pr_err("%s: NULL mq", __func__);
900 return -EINVAL;
901 }
902
903 max_packed_reqs = mq->card->ext_csd.max_packed_writes;
904 test_packed_trigger = mq->num_wr_reqs_to_start_packing;
905 num_packed_reqs = num_requests - test_packed_trigger;
906
907 if (mbtd->random_test_seed == 0) {
908 mbtd->random_test_seed =
909 (unsigned int)(get_jiffies_64() & 0xFFFF);
910 test_pr_info("%s: got seed from jiffies %d",
911 __func__, mbtd->random_test_seed);
912 }
913
914 mmc_blk_init_packed_statistics(mq->card);
915
916 if (td->test_info.testcase ==
917 TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED) {
918 temp_num_req = num_requests;
919 num_requests = test_packed_trigger - 1;
920 }
921
922 /* Verify that the packing is disabled before starting the test */
923 mq->wr_packing_enabled = false;
924 mq->num_of_potential_packed_wr_reqs = 0;
925
926 if (td->test_info.testcase == TEST_PACK_MIX_PACKED_NO_PACKED_PACKED) {
927 mq->num_of_potential_packed_wr_reqs = test_packed_trigger + 1;
928 mq->wr_packing_enabled = true;
929 num_requests = test_packed_trigger + 2;
930 }
931
932 ret = prepare_request_add_write_reqs(td, num_requests, is_err_expected,
933 is_random);
934 if (ret)
935 goto exit;
936
937 if (td->test_info.testcase == TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED)
938 num_requests = temp_num_req;
939
940 memset((void *)mbtd->exp_packed_stats.pack_stop_reason, 0,
941 sizeof(mbtd->exp_packed_stats.pack_stop_reason));
942 memset(mbtd->exp_packed_stats.packing_events, 0,
943 (max_packed_reqs + 1) * sizeof(u32));
944
945 switch (td->test_info.testcase) {
946 case TEST_PACKING_EXP_N_OVER_TRIGGER_FB_READ:
947 case TEST_PACKING_EXP_ONE_OVER_TRIGGER_FB_READ:
948 ret = prepare_request_add_read(td);
949 if (ret)
950 goto exit;
951
952 mbtd->exp_packed_stats.pack_stop_reason[WRONG_DATA_DIR] = 1;
953 mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
954 break;
955 case TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N:
956 ret = prepare_request_add_flush(td);
957 if (ret)
958 goto exit;
959
960 ret = prepare_request_add_write_reqs(td, num_packed_reqs,
961 is_err_expected, is_random);
962 if (ret)
963 goto exit;
964
965 mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
966 mbtd->exp_packed_stats.pack_stop_reason[FLUSH_OR_DISCARD] = 1;
967 mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 2;
968 break;
969 case TEST_PACKING_NOT_EXP_TRIGGER_READ_TRIGGER:
970 ret = prepare_request_add_read(td);
971 if (ret)
972 goto exit;
973
974 ret = prepare_request_add_write_reqs(td, test_packed_trigger,
975 is_err_expected, is_random);
976 if (ret)
977 goto exit;
978
979 mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
980 break;
981 case TEST_PACKING_NOT_EXP_TRIGGER_FLUSH_TRIGGER:
982 ret = prepare_request_add_flush(td);
983 if (ret)
984 goto exit;
985
986 ret = prepare_request_add_write_reqs(td, test_packed_trigger,
987 is_err_expected, is_random);
988 if (ret)
989 goto exit;
990
991 mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
992 break;
993 case TEST_PACK_MIX_PACKED_NO_PACKED_PACKED:
994 ret = prepare_request_add_read(td);
995 if (ret)
996 goto exit;
997
998 ret = prepare_request_add_write_reqs(td, test_packed_trigger-1,
999 is_err_expected, is_random);
1000 if (ret)
1001 goto exit;
1002
1003 ret = prepare_request_add_write_reqs(td, num_requests,
1004 is_err_expected, is_random);
1005 if (ret)
1006 goto exit;
1007
1008 mbtd->exp_packed_stats.packing_events[num_requests] = 1;
1009 mbtd->exp_packed_stats.packing_events[num_requests-1] = 1;
1010 mbtd->exp_packed_stats.pack_stop_reason[WRONG_DATA_DIR] = 1;
1011 mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
1012 break;
1013 case TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED:
1014 ret = prepare_request_add_read(td);
1015 if (ret)
1016 goto exit;
1017
1018 ret = prepare_request_add_write_reqs(td, num_requests,
1019 is_err_expected, is_random);
1020 if (ret)
1021 goto exit;
1022
1023 ret = prepare_request_add_read(td);
1024 if (ret)
1025 goto exit;
1026
1027 ret = prepare_request_add_write_reqs(td, test_packed_trigger-1,
1028 is_err_expected, is_random);
1029 if (ret)
1030 goto exit;
1031
1032 mbtd->exp_packed_stats.pack_stop_reason[WRONG_DATA_DIR] = 1;
1033 mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
1034 break;
1035 case TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS:
1036 case TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS:
1037 mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
1038 break;
1039 default:
1040 mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
1041 mbtd->exp_packed_stats.packing_events[num_packed_reqs] = 1;
1042 }
1043 mbtd->num_requests = num_requests;
1044
1045exit:
1046 return ret;
1047}
1048
1049/*
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001050 * Prepare requests for the TEST_RET_PARTIAL_FOLLOWED_BY_ABORT testcase.
1051 * In this testcase we have mixed error expectations from different
1052 * write requests, hence the special prepare function.
1053 */
1054static int prepare_partial_followed_by_abort(struct test_data *td,
1055 int num_requests)
1056{
1057 int i, start_address;
1058 int is_err_expected = 0;
1059 int ret = 0;
1060 struct mmc_queue *mq = test_iosched_get_req_queue()->queuedata;
1061 int max_packed_reqs;
1062
1063 if (!mq) {
1064 test_pr_err("%s: NULL mq", __func__);
1065 return -EINVAL;
1066 }
1067
1068 max_packed_reqs = mq->card->ext_csd.max_packed_writes;
1069
1070 mmc_blk_init_packed_statistics(mq->card);
1071
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001072 for (i = 1; i <= num_requests; i++) {
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001073 if (i > (num_requests / 2))
1074 is_err_expected = 1;
1075
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001076 start_address = td->start_sector + 4096 * td->num_of_write_bios;
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001077 ret = test_iosched_add_wr_rd_test_req(is_err_expected, WRITE,
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001078 start_address, (i % 5) + 1, TEST_PATTERN_5A,
1079 NULL);
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001080 if (ret) {
1081 test_pr_err("%s: failed to add a write request",
1082 __func__);
1083 return ret;
1084 }
1085 }
1086
1087 memset((void *)&mbtd->exp_packed_stats.pack_stop_reason, 0,
1088 sizeof(mbtd->exp_packed_stats.pack_stop_reason));
1089 memset(mbtd->exp_packed_stats.packing_events, 0,
1090 (max_packed_reqs + 1) * sizeof(u32));
1091 mbtd->exp_packed_stats.packing_events[num_requests] = 1;
1092 mbtd->exp_packed_stats.pack_stop_reason[EMPTY_QUEUE] = 1;
1093
1094 mbtd->num_requests = num_requests;
1095
1096 return ret;
1097}
1098
1099/*
1100 * Get number of write requests for current testcase. If random test mode was
1101 * chosen, pseudo-randomly choose the number of requests, otherwise set to
1102 * two less than the packing threshold.
1103 */
1104static int get_num_requests(struct test_data *td)
1105{
1106 int *seed = &mbtd->random_test_seed;
1107 struct request_queue *req_q;
1108 struct mmc_queue *mq;
1109 int max_num_requests;
1110 int num_requests;
1111 int min_num_requests = 2;
1112 int is_random = mbtd->is_random;
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001113 int max_for_double;
1114 int test_packed_trigger;
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001115
1116 req_q = test_iosched_get_req_queue();
1117 if (req_q)
1118 mq = req_q->queuedata;
1119 else {
1120 test_pr_err("%s: NULL request queue", __func__);
1121 return 0;
1122 }
1123
1124 if (!mq) {
1125 test_pr_err("%s: NULL mq", __func__);
1126 return -EINVAL;
1127 }
1128
1129 max_num_requests = mq->card->ext_csd.max_packed_writes;
1130 num_requests = max_num_requests - 2;
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001131 test_packed_trigger = mq->num_wr_reqs_to_start_packing;
1132
1133 /*
1134 * Here max_for_double is intended for packed control testcases
1135 * in which we issue many write requests. It's purpose is to prevent
1136 * exceeding max number of req_queue requests.
1137 */
1138 max_for_double = max_num_requests - 10;
1139
1140 if (td->test_info.testcase ==
1141 TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS)
1142 /* Don't expect packing, so issue up to trigger-1 reqs */
1143 num_requests = test_packed_trigger - 1;
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001144
1145 if (is_random) {
1146 if (td->test_info.testcase ==
1147 TEST_RET_PARTIAL_FOLLOWED_BY_ABORT)
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001148 /*
1149 * Here we don't want num_requests to be less than 1
1150 * as a consequence of division by 2.
1151 */
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001152 min_num_requests = 3;
1153
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001154 if (td->test_info.testcase ==
1155 TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS)
1156 /* Don't expect packing, so issue up to trigger reqs */
1157 max_num_requests = test_packed_trigger;
1158
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001159 num_requests = pseudo_random_seed(seed, min_num_requests,
1160 max_num_requests - 1);
1161 }
1162
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001163 if (td->test_info.testcase ==
1164 TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS)
1165 num_requests -= test_packed_trigger;
1166
1167 if (td->test_info.testcase == TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N)
1168 num_requests =
1169 num_requests > max_for_double ? max_for_double : num_requests;
1170
1171 if (mbtd->test_group == TEST_PACKING_CONTROL_GROUP)
1172 num_requests += test_packed_trigger;
1173
1174 if (td->test_info.testcase == TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS)
1175 num_requests = test_packed_trigger;
1176
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001177 return num_requests;
1178}
1179
1180/*
1181 * An implementation for the prepare_test_fn pointer in the test_info
1182 * data structure. According to the testcase we add the right number of requests
1183 * and decide if an error is expected or not.
1184 */
1185static int prepare_test(struct test_data *td)
1186{
1187 struct mmc_queue *mq = test_iosched_get_req_queue()->queuedata;
1188 int max_num_requests;
1189 int num_requests = 0;
1190 int ret = 0;
1191 int is_random = mbtd->is_random;
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001192 int test_packed_trigger = mq->num_wr_reqs_to_start_packing;
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001193
1194 if (!mq) {
1195 test_pr_err("%s: NULL mq", __func__);
1196 return -EINVAL;
1197 }
1198
1199 max_num_requests = mq->card->ext_csd.max_packed_writes;
1200
1201 if (is_random && mbtd->random_test_seed == 0) {
1202 mbtd->random_test_seed =
1203 (unsigned int)(get_jiffies_64() & 0xFFFF);
1204 test_pr_info("%s: got seed from jiffies %d",
1205 __func__, mbtd->random_test_seed);
1206 }
1207
1208 num_requests = get_num_requests(td);
1209
1210 if (mbtd->test_group == TEST_SEND_INVALID_GROUP)
1211 mq->packed_test_fn =
1212 test_invalid_packed_cmd;
1213
1214 if (mbtd->test_group == TEST_ERR_CHECK_GROUP)
1215 mq->err_check_fn = test_err_check;
1216
1217 switch (td->test_info.testcase) {
1218 case TEST_STOP_DUE_TO_FLUSH:
1219 case TEST_STOP_DUE_TO_READ:
1220 case TEST_RET_PARTIAL_FOLLOWED_BY_SUCCESS:
1221 case TEST_RET_PARTIAL_MULTIPLE_UNTIL_SUCCESS:
1222 case TEST_STOP_DUE_TO_EMPTY_QUEUE:
1223 case TEST_CMD23_PACKED_BIT_UNSET:
1224 ret = prepare_packed_requests(td, 0, num_requests, is_random);
1225 break;
1226 case TEST_STOP_DUE_TO_FLUSH_AFTER_MAX_REQS:
1227 case TEST_STOP_DUE_TO_READ_AFTER_MAX_REQS:
1228 ret = prepare_packed_requests(td, 0, max_num_requests - 1,
1229 is_random);
1230 break;
1231 case TEST_RET_PARTIAL_FOLLOWED_BY_ABORT:
1232 ret = prepare_partial_followed_by_abort(td, num_requests);
1233 break;
1234 case TEST_STOP_DUE_TO_MAX_REQ_NUM:
1235 case TEST_RET_PARTIAL_MAX_FAIL_IDX:
1236 ret = prepare_packed_requests(td, 0, max_num_requests,
1237 is_random);
1238 break;
1239 case TEST_STOP_DUE_TO_THRESHOLD:
1240 ret = prepare_packed_requests(td, 0, max_num_requests + 1,
1241 is_random);
1242 break;
1243 case TEST_RET_ABORT:
1244 case TEST_RET_RETRY:
1245 case TEST_RET_CMD_ERR:
1246 case TEST_RET_DATA_ERR:
1247 case TEST_HDR_INVALID_VERSION:
1248 case TEST_HDR_WRONG_WRITE_CODE:
1249 case TEST_HDR_INVALID_RW_CODE:
1250 case TEST_HDR_DIFFERENT_ADDRESSES:
1251 case TEST_HDR_REQ_NUM_SMALLER_THAN_ACTUAL:
1252 case TEST_HDR_REQ_NUM_LARGER_THAN_ACTUAL:
1253 case TEST_CMD23_MAX_PACKED_WRITES:
1254 case TEST_CMD23_ZERO_PACKED_WRITES:
1255 case TEST_CMD23_REL_WR_BIT_SET:
1256 case TEST_CMD23_BITS_16TO29_SET:
1257 case TEST_CMD23_HDR_BLK_NOT_IN_COUNT:
1258 case TEST_HDR_CMD23_PACKED_BIT_SET:
1259 ret = prepare_packed_requests(td, 1, num_requests, is_random);
1260 break;
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001261 case TEST_PACKING_EXP_N_OVER_TRIGGER:
1262 case TEST_PACKING_EXP_N_OVER_TRIGGER_FB_READ:
1263 case TEST_PACKING_NOT_EXP_TRIGGER_REQUESTS:
1264 case TEST_PACKING_NOT_EXP_LESS_THAN_TRIGGER_REQUESTS:
1265 case TEST_PACK_MIX_PACKED_NO_PACKED_PACKED:
1266 case TEST_PACK_MIX_NO_PACKED_PACKED_NO_PACKED:
1267 ret = prepare_packed_control_tests_requests(td, 0, num_requests,
1268 is_random);
1269 break;
1270 case TEST_PACKING_EXP_THRESHOLD_OVER_TRIGGER:
1271 ret = prepare_packed_control_tests_requests(td, 0,
1272 max_num_requests, is_random);
1273 break;
1274 case TEST_PACKING_EXP_ONE_OVER_TRIGGER_FB_READ:
1275 ret = prepare_packed_control_tests_requests(td, 0,
1276 test_packed_trigger + 1,
1277 is_random);
1278 break;
1279 case TEST_PACKING_EXP_N_OVER_TRIGGER_FLUSH_N:
1280 ret = prepare_packed_control_tests_requests(td, 0, num_requests,
1281 is_random);
1282 break;
1283 case TEST_PACKING_NOT_EXP_TRIGGER_READ_TRIGGER:
1284 case TEST_PACKING_NOT_EXP_TRIGGER_FLUSH_TRIGGER:
1285 ret = prepare_packed_control_tests_requests(td, 0,
1286 test_packed_trigger, is_random);
1287 break;
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001288 default:
1289 test_pr_info("%s: Invalid test case...", __func__);
1290 return -EINVAL;
1291 }
1292
1293 return ret;
1294}
1295
1296/*
1297 * An implementation for the post_test_fn in the test_info data structure.
1298 * In our case we just reset the function pointers in the mmc_queue in order for
1299 * the FS to be able to dispatch it's requests correctly after the test is
1300 * finished.
1301 */
1302static int post_test(struct test_data *td)
1303{
1304 struct mmc_queue *mq;
1305
1306 if (!td)
1307 return -EINVAL;
1308
1309 mq = td->req_q->queuedata;
1310
1311 if (!mq) {
1312 test_pr_err("%s: NULL mq", __func__);
1313 return -EINVAL;
1314 }
1315
1316 mq->packed_test_fn = NULL;
1317 mq->err_check_fn = NULL;
1318
1319 return 0;
1320}
1321
1322/*
1323 * This function checks, based on the current test's test_group, that the
1324 * packed commands capability and control are set right. In addition, we check
1325 * if the card supports the packed command feature.
1326 */
1327static int validate_packed_commands_settings(void)
1328{
1329 struct request_queue *req_q;
1330 struct mmc_queue *mq;
1331 int max_num_requests;
1332 struct mmc_host *host;
1333
1334 req_q = test_iosched_get_req_queue();
1335 if (!req_q) {
1336 test_pr_err("%s: test_iosched_get_req_queue failed", __func__);
1337 test_iosched_set_test_result(TEST_FAILED);
1338 return -EINVAL;
1339 }
1340
1341 mq = req_q->queuedata;
1342 if (!mq) {
1343 test_pr_err("%s: NULL mq", __func__);
1344 return -EINVAL;
1345 }
1346
1347 max_num_requests = mq->card->ext_csd.max_packed_writes;
1348 host = mq->card->host;
1349
1350 if (!(host->caps2 && MMC_CAP2_PACKED_WR)) {
1351 test_pr_err("%s: Packed Write capability disabled, exit test",
1352 __func__);
1353 test_iosched_set_test_result(TEST_NOT_SUPPORTED);
1354 return -EINVAL;
1355 }
1356
1357 if (max_num_requests == 0) {
1358 test_pr_err(
1359 "%s: no write packing support, ext_csd.max_packed_writes=%d",
1360 __func__, mq->card->ext_csd.max_packed_writes);
1361 test_iosched_set_test_result(TEST_NOT_SUPPORTED);
1362 return -EINVAL;
1363 }
1364
1365 test_pr_info("%s: max number of packed requests supported is %d ",
1366 __func__, max_num_requests);
1367
1368 switch (mbtd->test_group) {
1369 case TEST_SEND_WRITE_PACKING_GROUP:
1370 case TEST_ERR_CHECK_GROUP:
1371 case TEST_SEND_INVALID_GROUP:
1372 /* disable the packing control */
1373 host->caps2 &= ~MMC_CAP2_PACKED_WR_CONTROL;
1374 break;
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001375 case TEST_PACKING_CONTROL_GROUP:
1376 host->caps2 |= MMC_CAP2_PACKED_WR_CONTROL;
1377 break;
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001378 default:
1379 break;
1380 }
1381
1382 return 0;
1383}
1384
1385static bool message_repeat;
1386static int test_open(struct inode *inode, struct file *file)
1387{
1388 file->private_data = inode->i_private;
1389 message_repeat = 1;
1390 return 0;
1391}
1392
1393/* send_packing TEST */
1394static ssize_t send_write_packing_test_write(struct file *file,
1395 const char __user *buf,
1396 size_t count,
1397 loff_t *ppos)
1398{
1399 int ret = 0;
1400 int i = 0;
1401 int number = -1;
1402 int j = 0;
1403
1404 test_pr_info("%s: -- send_write_packing TEST --", __func__);
1405
1406 sscanf(buf, "%d", &number);
1407
1408 if (number <= 0)
1409 number = 1;
1410
1411
1412 mbtd->test_group = TEST_SEND_WRITE_PACKING_GROUP;
1413
1414 if (validate_packed_commands_settings())
1415 return count;
1416
1417 if (mbtd->random_test_seed > 0)
1418 test_pr_info("%s: Test seed: %d", __func__,
1419 mbtd->random_test_seed);
1420
1421 memset(&mbtd->test_info, 0, sizeof(struct test_info));
1422
1423 mbtd->test_info.data = mbtd;
1424 mbtd->test_info.prepare_test_fn = prepare_test;
1425 mbtd->test_info.check_test_result_fn = check_wr_packing_statistics;
1426 mbtd->test_info.get_test_case_str_fn = get_test_case_str;
1427 mbtd->test_info.post_test_fn = post_test;
1428
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001429 for (i = 0; i < number; ++i) {
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001430 test_pr_info("%s: Cycle # %d / %d", __func__, i+1, number);
1431 test_pr_info("%s: ====================", __func__);
1432
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001433 for (j = SEND_WRITE_PACKING_MIN_TESTCASE;
1434 j <= SEND_WRITE_PACKING_MAX_TESTCASE; j++) {
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001435
1436 mbtd->test_info.testcase = j;
1437 mbtd->is_random = RANDOM_TEST;
1438 ret = test_iosched_start_test(&mbtd->test_info);
1439 if (ret)
1440 break;
1441 /* Allow FS requests to be dispatched */
1442 msleep(1000);
1443 mbtd->test_info.testcase = j;
1444 mbtd->is_random = NON_RANDOM_TEST;
1445 ret = test_iosched_start_test(&mbtd->test_info);
1446 if (ret)
1447 break;
1448 /* Allow FS requests to be dispatched */
1449 msleep(1000);
1450 }
1451 }
1452
1453 test_pr_info("%s: Completed all the test cases.", __func__);
1454
1455 return count;
1456}
1457
1458static ssize_t send_write_packing_test_read(struct file *file,
1459 char __user *buffer,
1460 size_t count,
1461 loff_t *offset)
1462{
1463 memset((void *)buffer, 0, count);
1464
1465 snprintf(buffer, count,
1466 "\nsend_write_packing_test\n"
1467 "=========\n"
1468 "Description:\n"
1469 "This test checks the following scenarios\n"
1470 "- Pack due to FLUSH message\n"
1471 "- Pack due to FLUSH after threshold writes\n"
1472 "- Pack due to READ message\n"
1473 "- Pack due to READ after threshold writes\n"
1474 "- Pack due to empty queue\n"
1475 "- Pack due to threshold writes\n"
1476 "- Pack due to one over threshold writes\n");
1477
1478 if (message_repeat == 1) {
1479 message_repeat = 0;
1480 return strnlen(buffer, count);
1481 } else {
1482 return 0;
1483 }
1484}
1485
1486const struct file_operations send_write_packing_test_ops = {
1487 .open = test_open,
1488 .write = send_write_packing_test_write,
1489 .read = send_write_packing_test_read,
1490};
1491
1492/* err_check TEST */
1493static ssize_t err_check_test_write(struct file *file,
1494 const char __user *buf,
1495 size_t count,
1496 loff_t *ppos)
1497{
1498 int ret = 0;
1499 int i = 0;
1500 int number = -1;
1501 int j = 0;
1502
1503 test_pr_info("%s: -- err_check TEST --", __func__);
1504
1505 sscanf(buf, "%d", &number);
1506
1507 if (number <= 0)
1508 number = 1;
1509
1510 mbtd->test_group = TEST_ERR_CHECK_GROUP;
1511
1512 if (validate_packed_commands_settings())
1513 return count;
1514
1515 if (mbtd->random_test_seed > 0)
1516 test_pr_info("%s: Test seed: %d", __func__,
1517 mbtd->random_test_seed);
1518
1519 memset(&mbtd->test_info, 0, sizeof(struct test_info));
1520
1521 mbtd->test_info.data = mbtd;
1522 mbtd->test_info.prepare_test_fn = prepare_test;
1523 mbtd->test_info.check_test_result_fn = check_wr_packing_statistics;
1524 mbtd->test_info.get_test_case_str_fn = get_test_case_str;
1525 mbtd->test_info.post_test_fn = post_test;
1526
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001527 for (i = 0; i < number; ++i) {
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001528 test_pr_info("%s: Cycle # %d / %d", __func__, i+1, number);
1529 test_pr_info("%s: ====================", __func__);
1530
1531 for (j = ERR_CHECK_MIN_TESTCASE;
1532 j <= ERR_CHECK_MAX_TESTCASE ; j++) {
1533 mbtd->test_info.testcase = j;
1534 mbtd->is_random = RANDOM_TEST;
1535 ret = test_iosched_start_test(&mbtd->test_info);
1536 if (ret)
1537 break;
1538 /* Allow FS requests to be dispatched */
1539 msleep(1000);
1540 mbtd->test_info.testcase = j;
1541 mbtd->is_random = NON_RANDOM_TEST;
1542 ret = test_iosched_start_test(&mbtd->test_info);
1543 if (ret)
1544 break;
1545 /* Allow FS requests to be dispatched */
1546 msleep(1000);
1547 }
1548 }
1549
1550 test_pr_info("%s: Completed all the test cases.", __func__);
1551
1552 return count;
1553}
1554
1555static ssize_t err_check_test_read(struct file *file,
1556 char __user *buffer,
1557 size_t count,
1558 loff_t *offset)
1559{
1560 memset((void *)buffer, 0, count);
1561
1562 snprintf(buffer, count,
1563 "\nerr_check_TEST\n"
1564 "=========\n"
1565 "Description:\n"
1566 "This test checks the following scenarios\n"
1567 "- Return ABORT\n"
1568 "- Return PARTIAL followed by success\n"
1569 "- Return PARTIAL followed by abort\n"
1570 "- Return PARTIAL multiple times until success\n"
1571 "- Return PARTIAL with fail index = threshold\n"
1572 "- Return RETRY\n"
1573 "- Return CMD_ERR\n"
1574 "- Return DATA_ERR\n");
1575
1576 if (message_repeat == 1) {
1577 message_repeat = 0;
1578 return strnlen(buffer, count);
1579 } else {
1580 return 0;
1581 }
1582}
1583
1584const struct file_operations err_check_test_ops = {
1585 .open = test_open,
1586 .write = err_check_test_write,
1587 .read = err_check_test_read,
1588};
1589
1590/* send_invalid_packed TEST */
1591static ssize_t send_invalid_packed_test_write(struct file *file,
1592 const char __user *buf,
1593 size_t count,
1594 loff_t *ppos)
1595{
1596 int ret = 0;
1597 int i = 0;
1598 int number = -1;
1599 int j = 0;
1600 int num_of_failures = 0;
1601
1602 test_pr_info("%s: -- send_invalid_packed TEST --", __func__);
1603
1604 sscanf(buf, "%d", &number);
1605
1606 if (number <= 0)
1607 number = 1;
1608
1609 mbtd->test_group = TEST_SEND_INVALID_GROUP;
1610
1611 if (validate_packed_commands_settings())
1612 return count;
1613
1614 if (mbtd->random_test_seed > 0)
1615 test_pr_info("%s: Test seed: %d", __func__,
1616 mbtd->random_test_seed);
1617
1618 memset(&mbtd->test_info, 0, sizeof(struct test_info));
1619
1620 mbtd->test_info.data = mbtd;
1621 mbtd->test_info.prepare_test_fn = prepare_test;
1622 mbtd->test_info.check_test_result_fn = check_wr_packing_statistics;
1623 mbtd->test_info.get_test_case_str_fn = get_test_case_str;
1624 mbtd->test_info.post_test_fn = post_test;
1625
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001626 for (i = 0; i < number; ++i) {
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001627 test_pr_info("%s: Cycle # %d / %d", __func__, i+1, number);
1628 test_pr_info("%s: ====================", __func__);
1629
1630 for (j = INVALID_CMD_MIN_TESTCASE;
1631 j <= INVALID_CMD_MAX_TESTCASE ; j++) {
1632
1633 mbtd->test_info.testcase = j;
1634 mbtd->is_random = RANDOM_TEST;
1635 ret = test_iosched_start_test(&mbtd->test_info);
1636 if (ret)
1637 num_of_failures++;
1638 /* Allow FS requests to be dispatched */
1639 msleep(1000);
1640
1641 mbtd->test_info.testcase = j;
1642 mbtd->is_random = NON_RANDOM_TEST;
1643 ret = test_iosched_start_test(&mbtd->test_info);
1644 if (ret)
1645 num_of_failures++;
1646 /* Allow FS requests to be dispatched */
1647 msleep(1000);
1648 }
1649 }
1650
1651 test_pr_info("%s: Completed all the test cases.", __func__);
1652
1653 if (num_of_failures > 0) {
1654 test_iosched_set_test_result(TEST_FAILED);
1655 test_pr_err(
1656 "There were %d failures during the test, TEST FAILED",
1657 num_of_failures);
1658 }
1659 return count;
1660}
1661
1662static ssize_t send_invalid_packed_test_read(struct file *file,
1663 char __user *buffer,
1664 size_t count,
1665 loff_t *offset)
1666{
1667 memset((void *)buffer, 0, count);
1668
1669 snprintf(buffer, count,
1670 "\nsend_invalid_packed_TEST\n"
1671 "=========\n"
1672 "Description:\n"
1673 "This test checks the following scenarios\n"
1674 "- Send an invalid header version\n"
1675 "- Send the wrong write code\n"
1676 "- Send an invalid R/W code\n"
1677 "- Send wrong start address in header\n"
1678 "- Send header with block_count smaller than actual\n"
1679 "- Send header with block_count larger than actual\n"
1680 "- Send header CMD23 packed bit set\n"
1681 "- Send CMD23 with block count over threshold\n"
1682 "- Send CMD23 with block_count equals zero\n"
1683 "- Send CMD23 packed bit unset\n"
1684 "- Send CMD23 reliable write bit set\n"
1685 "- Send CMD23 bits [16-29] set\n"
1686 "- Send CMD23 header block not in block_count\n");
1687
1688 if (message_repeat == 1) {
1689 message_repeat = 0;
1690 return strnlen(buffer, count);
1691 } else {
1692 return 0;
1693 }
1694}
1695
1696const struct file_operations send_invalid_packed_test_ops = {
1697 .open = test_open,
1698 .write = send_invalid_packed_test_write,
1699 .read = send_invalid_packed_test_read,
1700};
1701
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001702/* packing_control TEST */
1703static ssize_t write_packing_control_test_write(struct file *file,
1704 const char __user *buf,
1705 size_t count,
1706 loff_t *ppos)
1707{
1708 int ret = 0;
1709 int i = 0;
1710 int number = -1;
1711 int j = 0;
1712 struct mmc_queue *mq = test_iosched_get_req_queue()->queuedata;
1713 int max_num_requests = mq->card->ext_csd.max_packed_writes;
1714 int test_successful = 1;
1715
1716 test_pr_info("%s: -- write_packing_control TEST --", __func__);
1717
1718 sscanf(buf, "%d", &number);
1719
1720 if (number <= 0)
1721 number = 1;
1722
1723 test_pr_info("%s: max_num_requests = %d ", __func__,
1724 max_num_requests);
1725
1726 memset(&mbtd->test_info, 0, sizeof(struct test_info));
1727 mbtd->test_group = TEST_PACKING_CONTROL_GROUP;
1728
1729 if (validate_packed_commands_settings())
1730 return count;
1731
1732 mbtd->test_info.data = mbtd;
1733 mbtd->test_info.prepare_test_fn = prepare_test;
1734 mbtd->test_info.check_test_result_fn = check_wr_packing_statistics;
1735 mbtd->test_info.get_test_case_str_fn = get_test_case_str;
1736
1737 for (i = 0; i < number; ++i) {
1738 test_pr_info("%s: Cycle # %d / %d", __func__, i+1, number);
1739 test_pr_info("%s: ====================", __func__);
1740
1741 for (j = PACKING_CONTROL_MIN_TESTCASE;
1742 j <= PACKING_CONTROL_MAX_TESTCASE; j++) {
1743
1744 test_successful = 1;
1745 mbtd->test_info.testcase = j;
1746 mbtd->is_random = RANDOM_TEST;
1747 ret = test_iosched_start_test(&mbtd->test_info);
1748 if (ret) {
1749 test_successful = 0;
1750 break;
1751 }
1752 /* Allow FS requests to be dispatched */
1753 msleep(1000);
1754
1755 mbtd->test_info.testcase = j;
1756 mbtd->is_random = NON_RANDOM_TEST;
1757 ret = test_iosched_start_test(&mbtd->test_info);
1758 if (ret) {
1759 test_successful = 0;
1760 break;
1761 }
1762 /* Allow FS requests to be dispatched */
1763 msleep(1000);
1764 }
1765
1766 if (!test_successful)
1767 break;
1768 }
1769
1770 test_pr_info("%s: Completed all the test cases.", __func__);
1771
1772 return count;
1773}
1774
1775static ssize_t write_packing_control_test_read(struct file *file,
1776 char __user *buffer,
1777 size_t count,
1778 loff_t *offset)
1779{
1780 memset((void *)buffer, 0, count);
1781
1782 snprintf(buffer, count,
1783 "\nwrite_packing_control_test\n"
1784 "=========\n"
1785 "Description:\n"
1786 "This test checks the following scenarios\n"
1787 "- Packing expected - one over trigger\n"
1788 "- Packing expected - N over trigger\n"
1789 "- Packing expected - N over trigger followed by read\n"
1790 "- Packing expected - N over trigger followed by flush\n"
1791 "- Packing expected - threshold over trigger FB by flush\n"
1792 "- Packing not expected - less than trigger\n"
1793 "- Packing not expected - trigger requests\n"
1794 "- Packing not expected - trigger, read, trigger\n"
1795 "- Mixed state - packing -> no packing -> packing\n"
1796 "- Mixed state - no packing -> packing -> no packing\n");
1797
1798 if (message_repeat == 1) {
1799 message_repeat = 0;
1800 return strnlen(buffer, count);
1801 } else {
1802 return 0;
1803 }
1804}
1805
1806const struct file_operations write_packing_control_test_ops = {
1807 .open = test_open,
1808 .write = write_packing_control_test_write,
1809 .read = write_packing_control_test_read,
1810};
1811
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001812static void mmc_block_test_debugfs_cleanup(void)
1813{
1814 debugfs_remove(mbtd->debug.random_test_seed);
1815 debugfs_remove(mbtd->debug.send_write_packing_test);
1816 debugfs_remove(mbtd->debug.err_check_test);
1817 debugfs_remove(mbtd->debug.send_invalid_packed_test);
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001818 debugfs_remove(mbtd->debug.packing_control_test);
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001819}
1820
1821static int mmc_block_test_debugfs_init(void)
1822{
1823 struct dentry *utils_root, *tests_root;
1824
1825 utils_root = test_iosched_get_debugfs_utils_root();
1826 tests_root = test_iosched_get_debugfs_tests_root();
1827
1828 if (!utils_root || !tests_root)
1829 return -EINVAL;
1830
1831 mbtd->debug.random_test_seed = debugfs_create_u32(
1832 "random_test_seed",
1833 S_IRUGO | S_IWUGO,
1834 utils_root,
1835 &mbtd->random_test_seed);
1836
1837 if (!mbtd->debug.random_test_seed)
1838 goto err_nomem;
1839
1840 mbtd->debug.send_write_packing_test =
1841 debugfs_create_file("send_write_packing_test",
1842 S_IRUGO | S_IWUGO,
1843 tests_root,
1844 NULL,
1845 &send_write_packing_test_ops);
1846
1847 if (!mbtd->debug.send_write_packing_test)
1848 goto err_nomem;
1849
1850 mbtd->debug.err_check_test =
1851 debugfs_create_file("err_check_test",
1852 S_IRUGO | S_IWUGO,
1853 tests_root,
1854 NULL,
1855 &err_check_test_ops);
1856
1857 if (!mbtd->debug.err_check_test)
1858 goto err_nomem;
1859
1860 mbtd->debug.send_invalid_packed_test =
1861 debugfs_create_file("send_invalid_packed_test",
1862 S_IRUGO | S_IWUGO,
1863 tests_root,
1864 NULL,
1865 &send_invalid_packed_test_ops);
1866
1867 if (!mbtd->debug.send_invalid_packed_test)
1868 goto err_nomem;
1869
Tatyana Brokhman91e1e322012-10-09 13:53:43 +02001870 mbtd->debug.packing_control_test = debugfs_create_file(
1871 "packing_control_test",
1872 S_IRUGO | S_IWUGO,
1873 tests_root,
1874 NULL,
1875 &write_packing_control_test_ops);
1876
1877 if (!mbtd->debug.packing_control_test)
1878 goto err_nomem;
1879
Tatyana Brokhman09b010d2012-10-09 13:50:56 +02001880 return 0;
1881
1882err_nomem:
1883 mmc_block_test_debugfs_cleanup();
1884 return -ENOMEM;
1885}
1886
1887static void mmc_block_test_probe(void)
1888{
1889 struct request_queue *q = test_iosched_get_req_queue();
1890 struct mmc_queue *mq;
1891 int max_packed_reqs;
1892
1893 if (!q) {
1894 test_pr_err("%s: NULL request queue", __func__);
1895 return;
1896 }
1897
1898 mq = q->queuedata;
1899 if (!mq) {
1900 test_pr_err("%s: NULL mq", __func__);
1901 return;
1902 }
1903
1904 max_packed_reqs = mq->card->ext_csd.max_packed_writes;
1905 mbtd->exp_packed_stats.packing_events =
1906 kzalloc((max_packed_reqs + 1) *
1907 sizeof(*mbtd->exp_packed_stats.packing_events),
1908 GFP_KERNEL);
1909
1910 mmc_block_test_debugfs_init();
1911}
1912
1913static void mmc_block_test_remove(void)
1914{
1915 mmc_block_test_debugfs_cleanup();
1916}
1917
1918static int __init mmc_block_test_init(void)
1919{
1920 mbtd = kzalloc(sizeof(struct mmc_block_test_data), GFP_KERNEL);
1921 if (!mbtd) {
1922 test_pr_err("%s: failed to allocate mmc_block_test_data",
1923 __func__);
1924 return -ENODEV;
1925 }
1926
1927 mbtd->bdt.init_fn = mmc_block_test_probe;
1928 mbtd->bdt.exit_fn = mmc_block_test_remove;
1929 INIT_LIST_HEAD(&mbtd->bdt.list);
1930 test_iosched_register(&mbtd->bdt);
1931
1932 return 0;
1933}
1934
1935static void __exit mmc_block_test_exit(void)
1936{
1937 test_iosched_unregister(&mbtd->bdt);
1938 kfree(mbtd);
1939}
1940
1941module_init(mmc_block_test_init);
1942module_exit(mmc_block_test_exit);
1943
1944MODULE_LICENSE("GPL v2");
1945MODULE_DESCRIPTION("MMC block test");