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