Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc_block: ensure all sectors that do not have errors are read

If a card encounters an ECC error while reading a sector it will
timeout. Instead of reporting the entire I/O request as having
an error, redo the I/O one sector at a time so that all readable
sectors are provided to the upper layers.

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>

authored by

Adrian Hunter and committed by
Pierre Ossman
6a79e391 a0d045ca

+59 -17
+59 -17
drivers/mmc/card/block.c
··· 229 229 struct mmc_blk_data *md = mq->data; 230 230 struct mmc_card *card = md->queue.card; 231 231 struct mmc_blk_request brq; 232 - int ret = 1; 232 + int ret = 1, disable_multi = 0; 233 233 234 234 mmc_claim_host(card->host); 235 235 ··· 250 250 brq.stop.arg = 0; 251 251 brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; 252 252 brq.data.blocks = req->nr_sectors; 253 + 254 + /* 255 + * After a read error, we redo the request one sector at a time 256 + * in order to accurately determine which sectors can be read 257 + * successfully. 258 + */ 259 + if (disable_multi && brq.data.blocks > 1) 260 + brq.data.blocks = 1; 253 261 254 262 if (brq.data.blocks > 1) { 255 263 /* SPI multiblock writes terminate using a special ··· 287 279 brq.data.sg = mq->sg; 288 280 brq.data.sg_len = mmc_queue_map_sg(mq); 289 281 282 + /* 283 + * Adjust the sg list so it is the same size as the 284 + * request. 285 + */ 286 + if (brq.data.blocks != req->nr_sectors) { 287 + int i, data_size = brq.data.blocks << 9; 288 + struct scatterlist *sg; 289 + 290 + for_each_sg(brq.data.sg, sg, brq.data.sg_len, i) { 291 + data_size -= sg->length; 292 + if (data_size <= 0) { 293 + sg->length += data_size; 294 + i++; 295 + break; 296 + } 297 + } 298 + brq.data.sg_len = i; 299 + } 300 + 290 301 mmc_queue_bounce_pre(mq); 291 302 292 303 mmc_wait_for_req(card->host, &brq.mrq); ··· 317 290 * until later as we need to wait for the card to leave 318 291 * programming mode even when things go wrong. 319 292 */ 320 - if (brq.cmd.error || brq.data.error || brq.stop.error) 293 + if (brq.cmd.error || brq.data.error || brq.stop.error) { 294 + if (brq.data.blocks > 1 && rq_data_dir(req) == READ) { 295 + /* Redo read one sector at a time */ 296 + printk(KERN_WARNING "%s: retrying using single " 297 + "block read\n", req->rq_disk->disk_name); 298 + disable_multi = 1; 299 + continue; 300 + } 321 301 status = get_card_status(card, req); 302 + } 322 303 323 304 if (brq.cmd.error) { 324 305 printk(KERN_ERR "%s: error %d sending read/write " ··· 383 348 #endif 384 349 } 385 350 386 - if (brq.cmd.error || brq.data.error || brq.stop.error) 351 + if (brq.cmd.error || brq.stop.error || brq.data.error) { 352 + if (rq_data_dir(req) == READ) { 353 + /* 354 + * After an error, we redo I/O one sector at a 355 + * time, so we only reach here after trying to 356 + * read a single sector. 357 + */ 358 + spin_lock_irq(&md->lock); 359 + ret = __blk_end_request(req, -EIO, brq.data.blksz); 360 + spin_unlock_irq(&md->lock); 361 + continue; 362 + } 387 363 goto cmd_err; 364 + } 388 365 389 366 /* 390 367 * A block was successfully transferred. ··· 418 371 * If the card is not SD, we can still ok written sectors 419 372 * as reported by the controller (which might be less than 420 373 * the real number of written sectors, but never more). 421 - * 422 - * For reads we just fail the entire chunk as that should 423 - * be safe in all cases. 424 374 */ 425 - if (rq_data_dir(req) != READ) { 426 - if (mmc_card_sd(card)) { 427 - u32 blocks; 375 + if (mmc_card_sd(card)) { 376 + u32 blocks; 428 377 429 - blocks = mmc_sd_num_wr_blocks(card); 430 - if (blocks != (u32)-1) { 431 - spin_lock_irq(&md->lock); 432 - ret = __blk_end_request(req, 0, blocks << 9); 433 - spin_unlock_irq(&md->lock); 434 - } 435 - } else { 378 + blocks = mmc_sd_num_wr_blocks(card); 379 + if (blocks != (u32)-1) { 436 380 spin_lock_irq(&md->lock); 437 - ret = __blk_end_request(req, 0, brq.data.bytes_xfered); 381 + ret = __blk_end_request(req, 0, blocks << 9); 438 382 spin_unlock_irq(&md->lock); 439 383 } 384 + } else { 385 + spin_lock_irq(&md->lock); 386 + ret = __blk_end_request(req, 0, brq.data.bytes_xfered); 387 + spin_unlock_irq(&md->lock); 440 388 } 441 389 442 390 mmc_release_host(card->host);