Commit ceb324a2914487aa517a6c70a06a20b5e3438fda
MLK-12693-1 nand: mxs: fix the bitflips for erased page when uncorrectable error
This patch is porting from linux: http://git.freescale.com/git/cgit.cgi/imx/linux-2.6-imx.git/commit/?h=imx_4.1.15_1.0.0_ga&id=3d42fcece496224fde59f9343763fb2dfc5b0768 " We may meet the bitflips in reading an erased page(contains all 0xFF), this may causes the UBIFS corrupt, please see the log from Elie: ----------------------------------------------------------------- [ 3.831323] UBI warning: ubi_io_read: error -74 (ECC error) while reading 16384 bytes from PEB 443:245760, read only 16384 bytes, retry [ 3.845026] UBI warning: ubi_io_read: error -74 (ECC error) while reading 16384 bytes from PEB 443:245760, read only 16384 bytes, retry [ 3.858710] UBI warning: ubi_io_read: error -74 (ECC error) while reading 16384 bytes from PEB 443:245760, read only 16384 bytes, retry [ 3.872408] UBI error: ubi_io_read: error -74 (ECC error) while reading 16384 bytes from PEB 443:245760, read 16384 bytes ... [ 4.011529] UBIFS error (pid 36): ubifs_recover_leb: corrupt empty space LEB 27:237568, corruption starts at 9815 [ 4.021897] UBIFS error (pid 36): ubifs_scanned_corruption: corruption at LEB 27:247383 [ 4.030000] UBIFS error (pid 36): ubifs_scanned_corruption: first 6569 bytes from LEB 27:247383 ----------------------------------------------------------------- This patch does a check for the uncorrectable failure in the following steps: [0] set the threshold. The threshold is set based on the truth: "A single 0 bit will lead to gf_len(13 or 14) bits 0 after the BCH do the ECC." For the sake of safe, we will set the threshold with half the gf_len, and do not make it bigger the ECC strength. [1] count the bitflips of the current ECC chunk, assume it is N. [2] if the (N <= threshold) is true, we continue to read out the page with ECC disabled. and we count the bitflips again, assume it is N2. (We read out the whole page, not just a chunk, this makes the check more strictly, and make the code more simple.) [3] if the (N2 <= threshold) is true again, we can regard this is a erased page. This is because a real erased page is full of 0xFF(maybe also has several bitflips), while a page contains the 0xFF data will definitely has many bitflips in the ECC parity areas. [4] if the [3] fails, we can regard this is a page filled with the '0xFF' data. " Signed-off-by: Peng Fan <peng.fan@nxp.com>
Showing 1 changed file with 44 additions and 0 deletions Side-by-side Diff
... | ... | @@ -640,6 +640,45 @@ |
640 | 640 | return buf; |
641 | 641 | } |
642 | 642 | |
643 | +static bool mxs_nand_erased_page(struct mtd_info *mtd, struct nand_chip *nand, | |
644 | + uint8_t *buf, int chunk, int page) | |
645 | +{ | |
646 | + int gf_len = galois_field; | |
647 | + unsigned int flip_bits = 0, flip_bits_noecc = 0; | |
648 | + unsigned int threshold; | |
649 | + unsigned int ecc_chunkn_size = MXS_NAND_CHUNK_DATA_CHUNK_SIZE; | |
650 | + unsigned int base = ecc_chunkn_size * chunk; | |
651 | + uint32_t *dma_buf = (uint32_t *)buf; | |
652 | + int i; | |
653 | + | |
654 | + threshold = gf_len / 2; | |
655 | + if (threshold > ecc_strength) | |
656 | + threshold = ecc_strength; | |
657 | + | |
658 | + for (i = 0; i < ecc_chunkn_size; i++) { | |
659 | + flip_bits += hweight8(~buf[base + i]); | |
660 | + if (flip_bits > threshold) | |
661 | + return false; | |
662 | + } | |
663 | + | |
664 | + nand->cmdfunc(mtd, NAND_CMD_READ0, 0, page); | |
665 | + nand->read_buf(mtd, buf, mtd->writesize); | |
666 | + | |
667 | + for (i = 0; i < mtd->writesize / 4; i++) { | |
668 | + flip_bits_noecc += hweight32(~dma_buf[i]); | |
669 | + if (flip_bits_noecc > threshold) | |
670 | + return false; | |
671 | + } | |
672 | + | |
673 | + mtd->ecc_stats.corrected += flip_bits; | |
674 | + | |
675 | + memset(buf, 0xff, mtd->writesize); | |
676 | + | |
677 | + printf("The page(%d) is an erased page(%d,%d,%d,%d).\n", page, chunk, threshold, flip_bits, flip_bits_noecc); | |
678 | + | |
679 | + return true; | |
680 | +} | |
681 | + | |
643 | 682 | /* |
644 | 683 | * Read a page from NAND. |
645 | 684 | */ |
... | ... | @@ -742,6 +781,8 @@ |
742 | 781 | goto rtn; |
743 | 782 | } |
744 | 783 | |
784 | + mxs_nand_return_dma_descs(nand_info); | |
785 | + | |
745 | 786 | /* Invalidate caches */ |
746 | 787 | mxs_nand_inval_data_buf(nand_info); |
747 | 788 | |
... | ... | @@ -758,6 +799,9 @@ |
758 | 799 | continue; |
759 | 800 | |
760 | 801 | if (status[i] == 0xfe) { |
802 | + if (mxs_nand_erased_page(mtd, nand, | |
803 | + nand_info->data_buf, i, page)) | |
804 | + break; | |
761 | 805 | failed++; |
762 | 806 | continue; |
763 | 807 | } |
-
mentioned in commit 026751
-
mentioned in commit 026751
-
mentioned in commit 026751
-
mentioned in commit 026751
-
mentioned in commit 026751
-
mentioned in commit 026751
-
mentioned in commit 93b481
-
mentioned in commit 93b481
-
mentioned in commit 93b481
-
mentioned in commit 93b481
-
mentioned in commit 93b481
-
mentioned in commit eefb30
-
mentioned in commit 93b481
-
mentioned in commit eefb30
-
mentioned in commit 40760d
-
mentioned in commit 40760d
-
mentioned in commit 40760d
-
mentioned in commit 40760d
-
mentioned in commit bc468f
-
mentioned in commit bc468f
-
mentioned in commit 40760d
-
mentioned in commit bc468f
-
mentioned in commit bc468f
-
mentioned in commit bc468f
-
mentioned in commit bc468f