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