Lines Matching full:ecc
21 * if we have HW ECC support.
1677 * nand_check_erased_ecc_chunk - check if an ECC chunk contains (almost) only
1681 * @ecc: ECC buffer
1682 * @ecclen: ECC length
1687 * Check if a data buffer and its associated ECC and OOB data contains only
1694 * 1/ ECC algorithms are working on pre-defined block sizes which are usually
1695 * different from the NAND page size. When fixing bitflips, ECC engines will
1702 * the payload data but also their associated ECC data, because a user might
1704 * shouldn't consider the chunk as erased, and checking ECC bytes prevent
1707 * data are protected by the ECC engine.
1709 * extra OOB data to an ECC chunk.
1716 void *ecc, int ecclen, in nand_check_erased_ecc_chunk() argument
1729 ecc_bitflips = nand_check_erased_buf(ecc, ecclen, bitflips_threshold); in nand_check_erased_ecc_chunk()
1744 memset(ecc, 0xff, ecclen); in nand_check_erased_ecc_chunk()
1754 * nand_read_page_raw - [INTERN] read raw page data without ecc
1761 * Not for syndrome calculating ECC controllers, which use a special oob layout.
1783 * nand_read_page_raw_syndrome - [INTERN] read raw page data without ecc
1796 int eccsize = chip->ecc.size; in nand_read_page_raw_syndrome()
1797 int eccbytes = chip->ecc.bytes; in nand_read_page_raw_syndrome()
1801 for (steps = chip->ecc.steps; steps > 0; steps--) { in nand_read_page_raw_syndrome()
1808 if (chip->ecc.prepad) { in nand_read_page_raw_syndrome()
1809 ret = nand_read_data_op(chip, oob, chip->ecc.prepad, in nand_read_page_raw_syndrome()
1814 oob += chip->ecc.prepad; in nand_read_page_raw_syndrome()
1823 if (chip->ecc.postpad) { in nand_read_page_raw_syndrome()
1824 ret = nand_read_data_op(chip, oob, chip->ecc.postpad, in nand_read_page_raw_syndrome()
1829 oob += chip->ecc.postpad; in nand_read_page_raw_syndrome()
1844 * nand_read_page_swecc - [REPLACEABLE] software ECC based page read function
1854 int i, eccsize = chip->ecc.size; in nand_read_page_swecc()
1855 int eccbytes = chip->ecc.bytes; in nand_read_page_swecc()
1856 int eccsteps = chip->ecc.steps; in nand_read_page_swecc()
1860 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_read_page_swecc()
1863 chip->ecc.read_page_raw(mtd, chip, buf, 1, page); in nand_read_page_swecc()
1866 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_swecc()
1868 for (i = 0; i < chip->ecc.total; i++) in nand_read_page_swecc()
1871 eccsteps = chip->ecc.steps; in nand_read_page_swecc()
1877 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_swecc()
1889 * nand_read_subpage - [REPLACEABLE] ECC based sub-page read function
1902 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_read_subpage()
1911 /* Column address within the page aligned to ECC size (256bytes) */ in nand_read_subpage()
1912 start_step = data_offs / chip->ecc.size; in nand_read_subpage()
1913 end_step = (data_offs + readlen - 1) / chip->ecc.size; in nand_read_subpage()
1915 index = start_step * chip->ecc.bytes; in nand_read_subpage()
1917 /* Data size aligned to ECC ecc.size */ in nand_read_subpage()
1918 datafrag_len = num_steps * chip->ecc.size; in nand_read_subpage()
1919 eccfrag_len = num_steps * chip->ecc.bytes; in nand_read_subpage()
1921 data_col_addr = start_step * chip->ecc.size; in nand_read_subpage()
1931 /* Calculate ECC */ in nand_read_subpage()
1932 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) in nand_read_subpage()
1933 chip->ecc.calculate(mtd, p, &chip->buffers->ecccalc[i]); in nand_read_subpage()
1937 * ecc.pos. Let's make sure that there are no gaps in ECC positions. in nand_read_subpage()
1953 * Send the command to read the particular ECC bytes take care in nand_read_subpage()
1960 if (eccpos[index + (num_steps * chip->ecc.bytes)] & (busw - 1)) in nand_read_subpage()
1975 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) { in nand_read_subpage()
1978 stat = chip->ecc.correct(mtd, p, in nand_read_subpage()
1981 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_subpage()
1983 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, in nand_read_subpage()
1985 chip->ecc.bytes, in nand_read_subpage()
1987 chip->ecc.strength); in nand_read_subpage()
2001 * nand_read_page_hwecc - [REPLACEABLE] hardware ECC based page read function
2008 * Not for syndrome calculating ECC controllers which need a special oob layout.
2013 int i, eccsize = chip->ecc.size; in nand_read_page_hwecc()
2014 int eccbytes = chip->ecc.bytes; in nand_read_page_hwecc()
2015 int eccsteps = chip->ecc.steps; in nand_read_page_hwecc()
2019 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_read_page_hwecc()
2024 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_hwecc()
2030 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_hwecc()
2037 for (i = 0; i < chip->ecc.total; i++) in nand_read_page_hwecc()
2040 eccsteps = chip->ecc.steps; in nand_read_page_hwecc()
2046 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_hwecc()
2048 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_hwecc()
2053 chip->ecc.strength); in nand_read_page_hwecc()
2067 * nand_read_page_hwecc_oob_first - [REPLACEABLE] hw ecc, read oob first
2074 * Hardware ECC for large page chips, require OOB to be read first. For this
2075 * ECC mode, the write_page method is re-used from ECC_HW. These methods
2076 * read/write ECC from the OOB area, unlike the ECC_HW_SYNDROME support with
2077 * multiple ECC steps, follows the "infix ECC" scheme and reads/writes ECC from
2083 int i, eccsize = chip->ecc.size; in nand_read_page_hwecc_oob_first()
2084 int eccbytes = chip->ecc.bytes; in nand_read_page_hwecc_oob_first()
2085 int eccsteps = chip->ecc.steps; in nand_read_page_hwecc_oob_first()
2088 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_read_page_hwecc_oob_first()
2102 for (i = 0; i < chip->ecc.total; i++) in nand_read_page_hwecc_oob_first()
2108 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_hwecc_oob_first()
2114 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_hwecc_oob_first()
2116 stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL); in nand_read_page_hwecc_oob_first()
2118 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_hwecc_oob_first()
2123 chip->ecc.strength); in nand_read_page_hwecc_oob_first()
2137 * nand_read_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page read
2150 int ret, i, eccsize = chip->ecc.size; in nand_read_page_syndrome()
2151 int eccbytes = chip->ecc.bytes; in nand_read_page_syndrome()
2152 int eccsteps = chip->ecc.steps; in nand_read_page_syndrome()
2153 int eccpadbytes = eccbytes + chip->ecc.prepad + chip->ecc.postpad; in nand_read_page_syndrome()
2161 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_syndrome()
2167 if (chip->ecc.prepad) { in nand_read_page_syndrome()
2168 ret = nand_read_data_op(chip, oob, chip->ecc.prepad, in nand_read_page_syndrome()
2173 oob += chip->ecc.prepad; in nand_read_page_syndrome()
2176 chip->ecc.hwctl(mtd, NAND_ECC_READSYN); in nand_read_page_syndrome()
2182 stat = chip->ecc.correct(mtd, p, oob, NULL); in nand_read_page_syndrome()
2186 if (chip->ecc.postpad) { in nand_read_page_syndrome()
2187 ret = nand_read_data_op(chip, oob, chip->ecc.postpad, in nand_read_page_syndrome()
2192 oob += chip->ecc.postpad; in nand_read_page_syndrome()
2196 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_syndrome()
2198 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, in nand_read_page_syndrome()
2202 chip->ecc.strength); in nand_read_page_syndrome()
2242 struct nand_oobfree *free = chip->ecc.layout->oobfree; in nand_transfer_oob()
2278 * when there are too many bitflips in a page (i.e., ECC error). After setting
2297 * nand_do_read_ops - [INTERN] Read data with ECC
2356 if (nand_standard_page_accessors(&chip->ecc)) { in nand_do_read_ops()
2364 * the read methods return max bitflips per ecc step. in nand_do_read_ops()
2367 ret = chip->ecc.read_page_raw(mtd, chip, bufpoi, in nand_do_read_ops()
2372 ret = chip->ecc.read_subpage(mtd, chip, in nand_do_read_ops()
2376 ret = chip->ecc.read_page(mtd, chip, bufpoi, in nand_do_read_ops()
2498 * nand_read_oob_syndrome - [REPLACEABLE] OOB data read function for HW ECC
2508 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad; in nand_read_oob_syndrome()
2509 int eccsize = chip->ecc.size; in nand_read_oob_syndrome()
2513 ret = nand_read_page_op(chip, page, chip->ecc.size, NULL, 0); in nand_read_oob_syndrome()
2517 for (i = 0; i < chip->ecc.steps; i++) { in nand_read_oob_syndrome()
2566 * nand_write_oob_syndrome - [REPLACEABLE] OOB data write function for HW ECC
2575 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad; in nand_write_oob_syndrome()
2576 int eccsize = chip->ecc.size, length = mtd->oobsize; in nand_write_oob_syndrome()
2577 int ret, i, len, pos, sndcmd = 0, steps = chip->ecc.steps; in nand_write_oob_syndrome()
2581 * data-ecc-data-ecc ... ecc-oob in nand_write_oob_syndrome()
2583 * data-pad-ecc-pad-data-pad .... ecc-pad-oob in nand_write_oob_syndrome()
2585 if (!chip->ecc.prepad && !chip->ecc.postpad) { in nand_write_oob_syndrome()
2691 ret = chip->ecc.read_oob_raw(mtd, chip, page); in nand_do_read_oob()
2693 ret = chip->ecc.read_oob(mtd, chip, page); in nand_do_read_oob()
2790 * Not for syndrome calculating ECC controllers, which use a special oob layout.
2819 * We need a special oob layout and handling even when ECC isn't checked.
2826 int eccsize = chip->ecc.size; in nand_write_page_raw_syndrome()
2827 int eccbytes = chip->ecc.bytes; in nand_write_page_raw_syndrome()
2831 for (steps = chip->ecc.steps; steps > 0; steps--) { in nand_write_page_raw_syndrome()
2838 if (chip->ecc.prepad) { in nand_write_page_raw_syndrome()
2839 ret = nand_write_data_op(chip, oob, chip->ecc.prepad, in nand_write_page_raw_syndrome()
2844 oob += chip->ecc.prepad; in nand_write_page_raw_syndrome()
2853 if (chip->ecc.postpad) { in nand_write_page_raw_syndrome()
2854 ret = nand_write_data_op(chip, oob, chip->ecc.postpad, in nand_write_page_raw_syndrome()
2859 oob += chip->ecc.postpad; in nand_write_page_raw_syndrome()
2873 * nand_write_page_swecc - [REPLACEABLE] software ECC based page write function
2884 int i, eccsize = chip->ecc.size; in nand_write_page_swecc()
2885 int eccbytes = chip->ecc.bytes; in nand_write_page_swecc()
2886 int eccsteps = chip->ecc.steps; in nand_write_page_swecc()
2889 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_write_page_swecc()
2891 /* Software ECC calculation */ in nand_write_page_swecc()
2893 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_write_page_swecc()
2895 for (i = 0; i < chip->ecc.total; i++) in nand_write_page_swecc()
2898 return chip->ecc.write_page_raw(mtd, chip, buf, 1, page); in nand_write_page_swecc()
2902 * nand_write_page_hwecc - [REPLACEABLE] hardware ECC based page write function
2913 int i, eccsize = chip->ecc.size; in nand_write_page_hwecc()
2914 int eccbytes = chip->ecc.bytes; in nand_write_page_hwecc()
2915 int eccsteps = chip->ecc.steps; in nand_write_page_hwecc()
2918 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_write_page_hwecc()
2922 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_page_hwecc()
2928 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_write_page_hwecc()
2931 for (i = 0; i < chip->ecc.total; i++) in nand_write_page_hwecc()
2943 * nand_write_subpage_hwecc - [REPLACEABLE] hardware ECC based subpage write
2959 int ecc_size = chip->ecc.size; in nand_write_subpage_hwecc()
2960 int ecc_bytes = chip->ecc.bytes; in nand_write_subpage_hwecc()
2961 int ecc_steps = chip->ecc.steps; in nand_write_subpage_hwecc()
2962 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_write_subpage_hwecc()
2971 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_subpage_hwecc()
2978 /* mask ECC of un-touched subpages by padding 0xFF */ in nand_write_subpage_hwecc()
2982 chip->ecc.calculate(mtd, buf, ecc_calc); in nand_write_subpage_hwecc()
2994 /* copy calculated ECC for whole page to chip->buffer->oob */ in nand_write_subpage_hwecc()
2997 for (i = 0; i < chip->ecc.total; i++) in nand_write_subpage_hwecc()
3010 * nand_write_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page write
3025 int i, eccsize = chip->ecc.size; in nand_write_page_syndrome()
3026 int eccbytes = chip->ecc.bytes; in nand_write_page_syndrome()
3027 int eccsteps = chip->ecc.steps; in nand_write_page_syndrome()
3033 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_page_syndrome()
3039 if (chip->ecc.prepad) { in nand_write_page_syndrome()
3040 ret = nand_write_data_op(chip, oob, chip->ecc.prepad, in nand_write_page_syndrome()
3045 oob += chip->ecc.prepad; in nand_write_page_syndrome()
3048 chip->ecc.calculate(mtd, p, oob); in nand_write_page_syndrome()
3056 if (chip->ecc.postpad) { in nand_write_page_syndrome()
3057 ret = nand_write_data_op(chip, oob, chip->ecc.postpad, in nand_write_page_syndrome()
3062 oob += chip->ecc.postpad; in nand_write_page_syndrome()
3095 chip->ecc.write_subpage) in nand_write_page()
3100 if (nand_standard_page_accessors(&chip->ecc)) { in nand_write_page()
3107 status = chip->ecc.write_page_raw(mtd, chip, buf, in nand_write_page()
3110 status = chip->ecc.write_subpage(mtd, chip, offset, data_len, in nand_write_page()
3113 status = chip->ecc.write_page(mtd, chip, buf, oob_required, in nand_write_page()
3119 if (nand_standard_page_accessors(&chip->ecc)) in nand_write_page()
3151 struct nand_oobfree *free = chip->ecc.layout->oobfree; in nand_fill_oob()
3184 * nand_do_write_ops - [INTERN] NAND write with ECC
3189 * NAND write with ECC.
3310 * panic_nand_write - [MTD Interface] NAND write with ECC
3317 * NAND write with ECC. Used when performing writes in interrupt context, this
3414 status = chip->ecc.write_oob_raw(mtd, chip, page & chip->pagemask); in nand_do_write_oob()
3416 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); in nand_do_write_oob()
3797 struct onfi_ext_ecc_info *ecc; in nand_flash_detect_ext_param_page() local
3836 /* find the ECC section. */ in nand_flash_detect_ext_param_page()
3845 pr_debug("We can not find the ECC section.\n"); in nand_flash_detect_ext_param_page()
3850 ecc = (struct onfi_ext_ecc_info *)cursor; in nand_flash_detect_ext_param_page()
3852 if (!ecc->codeword_size) { in nand_flash_detect_ext_param_page()
3857 chip->ecc_strength_ds = ecc->ecc_bits; in nand_flash_detect_ext_param_page()
3858 chip->ecc_step_ds = 1 << ecc->codeword_size; in nand_flash_detect_ext_param_page()
3989 pr_warn("Could not retrieve ONFI ECC requirements\n"); in nand_flash_detect_onfi()
4012 struct jedec_ecc_info *ecc; in nand_flash_detect_jedec() local
4075 /* ECC info */ in nand_flash_detect_jedec()
4076 ecc = &p->ecc_info[0]; in nand_flash_detect_jedec()
4078 if (ecc->codeword_size >= 9) { in nand_flash_detect_jedec()
4079 chip->ecc_strength_ds = ecc->ecc_bits; in nand_flash_detect_jedec()
4080 chip->ecc_step_ds = 1 << ecc->codeword_size; in nand_flash_detect_jedec()
4587 str = fdt_getprop(blob, node, "nand-ecc-mode", NULL); in nand_dt_init()
4604 ecc_strength = fdtdec_get_int(blob, node, "nand-ecc-strength", -1); in nand_dt_init()
4605 ecc_step = fdtdec_get_int(blob, node, "nand-ecc-step-size", -1); in nand_dt_init()
4614 chip->ecc.mode = ecc_mode; in nand_dt_init()
4617 chip->ecc.strength = ecc_strength; in nand_dt_init()
4620 chip->ecc.size = ecc_step; in nand_dt_init()
4622 if (fdt_getprop(blob, node, "nand-ecc-maximize", NULL)) in nand_dt_init()
4623 chip->ecc.options |= NAND_ECC_MAXIMIZE; in nand_dt_init()
4724 * nand_check_ecc_caps - check the sanity of preset ECC settings
4726 * @caps: ECC caps info structure
4727 * @oobavail: OOB size that the ECC engine can use
4729 * When ECC step size and strength are already set, check if they are supported
4730 * by the controller and the calculated ECC bytes fit within the chip's OOB.
4731 * On success, the calculated ECC bytes is set.
4738 int preset_step = chip->ecc.size; in nand_check_ecc_caps()
4739 int preset_strength = chip->ecc.strength; in nand_check_ecc_caps()
4767 pr_err("ECC (step, strength) = (%d, %d) does not fit in OOB", in nand_check_ecc_caps()
4772 chip->ecc.bytes = ecc_bytes; in nand_check_ecc_caps()
4778 pr_err("ECC (step, strength) = (%d, %d) not supported on this controller", in nand_check_ecc_caps()
4786 * nand_match_ecc_req - meet the chip's requirement with least ECC bytes
4788 * @caps: ECC engine caps info structure
4789 * @oobavail: OOB size that the ECC engine can use
4791 * If a chip's ECC requirement is provided, try to meet it with the least
4792 * number of ECC bytes (i.e. with the largest number of OOB-free bytes).
4793 * On success, the chosen ECC settings are set.
4848 * with the least number of ECC bytes. in nand_match_ecc_req()
4862 chip->ecc.size = best_step; in nand_match_ecc_req()
4863 chip->ecc.strength = best_strength; in nand_match_ecc_req()
4864 chip->ecc.bytes = best_ecc_bytes; in nand_match_ecc_req()
4871 * nand_maximize_ecc - choose the max ECC strength available
4873 * @caps: ECC engine caps info structure
4874 * @oobavail: OOB size that the ECC engine can use
4876 * Choose the max ECC strength that is supported on the controller, and can fit
4877 * within the chip's OOB. On success, the chosen ECC settings are set.
4897 /* If chip->ecc.size is already set, respect it */ in nand_maximize_ecc()
4898 if (chip->ecc.size && step_size != chip->ecc.size) in nand_maximize_ecc()
4935 chip->ecc.size = best_step; in nand_maximize_ecc()
4936 chip->ecc.strength = best_strength; in nand_maximize_ecc()
4937 chip->ecc.bytes = best_ecc_bytes; in nand_maximize_ecc()
4960 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_ecc_strength_good() local
4963 if (ecc->size == 0 || chip->ecc_step_ds == 0) in nand_ecc_strength_good()
4971 corr = (mtd->writesize * ecc->strength) / ecc->size; in nand_ecc_strength_good()
4974 return corr >= ds_corr && ecc->strength >= chip->ecc_strength_ds; in nand_ecc_strength_good()
4979 struct nand_ecc_ctrl *ecc = &chip->ecc; in invalid_ecc_page_accessors() local
4981 if (nand_standard_page_accessors(ecc)) in invalid_ecc_page_accessors()
4990 return (!ecc->read_page || !ecc->write_page || in invalid_ecc_page_accessors()
4991 !ecc->read_page_raw || !ecc->write_page_raw || in invalid_ecc_page_accessors()
4992 (NAND_HAS_SUBPAGE_READ(chip) && !ecc->read_subpage) || in invalid_ecc_page_accessors()
4993 (NAND_HAS_SUBPAGE_WRITE(chip) && !ecc->write_subpage && in invalid_ecc_page_accessors()
4994 ecc->hwctl && ecc->calculate)); in invalid_ecc_page_accessors()
5009 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_scan_tail() local
5017 pr_err("Invalid ECC page accessors setup\n"); in nand_scan_tail()
5035 if (!ecc->layout && (ecc->mode != NAND_ECC_SOFT_BCH)) { in nand_scan_tail()
5039 ecc->layout = &nand_oob_8; in nand_scan_tail()
5042 ecc->layout = &nand_oob_16; in nand_scan_tail()
5045 ecc->layout = &nand_oob_64; in nand_scan_tail()
5048 ecc->layout = &nand_oob_128; in nand_scan_tail()
5062 * Check ECC mode, default to software if 3byte/512byte hardware ECC is in nand_scan_tail()
5063 * selected and we have 256 byte pagesize fallback to software ECC in nand_scan_tail()
5066 switch (ecc->mode) { in nand_scan_tail()
5069 if (!ecc->calculate || !ecc->correct || !ecc->hwctl) { in nand_scan_tail()
5070 pr_warn("No ECC functions supplied; hardware ECC not possible\n"); in nand_scan_tail()
5073 if (!ecc->read_page) in nand_scan_tail()
5074 ecc->read_page = nand_read_page_hwecc_oob_first; in nand_scan_tail()
5078 if (!ecc->read_page) in nand_scan_tail()
5079 ecc->read_page = nand_read_page_hwecc; in nand_scan_tail()
5080 if (!ecc->write_page) in nand_scan_tail()
5081 ecc->write_page = nand_write_page_hwecc; in nand_scan_tail()
5082 if (!ecc->read_page_raw) in nand_scan_tail()
5083 ecc->read_page_raw = nand_read_page_raw; in nand_scan_tail()
5084 if (!ecc->write_page_raw) in nand_scan_tail()
5085 ecc->write_page_raw = nand_write_page_raw; in nand_scan_tail()
5086 if (!ecc->read_oob) in nand_scan_tail()
5087 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
5088 if (!ecc->write_oob) in nand_scan_tail()
5089 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
5090 if (!ecc->read_subpage) in nand_scan_tail()
5091 ecc->read_subpage = nand_read_subpage; in nand_scan_tail()
5092 if (!ecc->write_subpage && ecc->hwctl && ecc->calculate) in nand_scan_tail()
5093 ecc->write_subpage = nand_write_subpage_hwecc; in nand_scan_tail()
5096 if ((!ecc->calculate || !ecc->correct || !ecc->hwctl) && in nand_scan_tail()
5097 (!ecc->read_page || in nand_scan_tail()
5098 ecc->read_page == nand_read_page_hwecc || in nand_scan_tail()
5099 !ecc->write_page || in nand_scan_tail()
5100 ecc->write_page == nand_write_page_hwecc)) { in nand_scan_tail()
5101 pr_warn("No ECC functions supplied; hardware ECC not possible\n"); in nand_scan_tail()
5105 if (!ecc->read_page) in nand_scan_tail()
5106 ecc->read_page = nand_read_page_syndrome; in nand_scan_tail()
5107 if (!ecc->write_page) in nand_scan_tail()
5108 ecc->write_page = nand_write_page_syndrome; in nand_scan_tail()
5109 if (!ecc->read_page_raw) in nand_scan_tail()
5110 ecc->read_page_raw = nand_read_page_raw_syndrome; in nand_scan_tail()
5111 if (!ecc->write_page_raw) in nand_scan_tail()
5112 ecc->write_page_raw = nand_write_page_raw_syndrome; in nand_scan_tail()
5113 if (!ecc->read_oob) in nand_scan_tail()
5114 ecc->read_oob = nand_read_oob_syndrome; in nand_scan_tail()
5115 if (!ecc->write_oob) in nand_scan_tail()
5116 ecc->write_oob = nand_write_oob_syndrome; in nand_scan_tail()
5118 if (mtd->writesize >= ecc->size) { in nand_scan_tail()
5119 if (!ecc->strength) { in nand_scan_tail()
5120 pr_warn("Driver must set ecc.strength when using hardware ECC\n"); in nand_scan_tail()
5125 pr_warn("%d byte HW ECC not possible on %d byte page size, fallback to SW ECC\n", in nand_scan_tail()
5126 ecc->size, mtd->writesize); in nand_scan_tail()
5127 ecc->mode = NAND_ECC_SOFT; in nand_scan_tail()
5130 ecc->calculate = nand_calculate_ecc; in nand_scan_tail()
5131 ecc->correct = nand_correct_data; in nand_scan_tail()
5132 ecc->read_page = nand_read_page_swecc; in nand_scan_tail()
5133 ecc->read_subpage = nand_read_subpage; in nand_scan_tail()
5134 ecc->write_page = nand_write_page_swecc; in nand_scan_tail()
5135 ecc->read_page_raw = nand_read_page_raw; in nand_scan_tail()
5136 ecc->write_page_raw = nand_write_page_raw; in nand_scan_tail()
5137 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
5138 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
5139 if (!ecc->size) in nand_scan_tail()
5140 ecc->size = 256; in nand_scan_tail()
5141 ecc->bytes = 3; in nand_scan_tail()
5142 ecc->strength = 1; in nand_scan_tail()
5150 ecc->calculate = nand_bch_calculate_ecc; in nand_scan_tail()
5151 ecc->correct = nand_bch_correct_data; in nand_scan_tail()
5152 ecc->read_page = nand_read_page_swecc; in nand_scan_tail()
5153 ecc->read_subpage = nand_read_subpage; in nand_scan_tail()
5154 ecc->write_page = nand_write_page_swecc; in nand_scan_tail()
5155 ecc->read_page_raw = nand_read_page_raw; in nand_scan_tail()
5156 ecc->write_page_raw = nand_write_page_raw; in nand_scan_tail()
5157 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
5158 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
5160 * Board driver should supply ecc.size and ecc.strength values in nand_scan_tail()
5164 if (!ecc->size && (mtd->oobsize >= 64)) { in nand_scan_tail()
5165 ecc->size = 512; in nand_scan_tail()
5166 ecc->strength = 4; in nand_scan_tail()
5170 ecc->bytes = 0; in nand_scan_tail()
5171 ecc->priv = nand_bch_init(mtd); in nand_scan_tail()
5172 if (!ecc->priv) { in nand_scan_tail()
5173 pr_warn("BCH ECC initialization failed!\n"); in nand_scan_tail()
5180 ecc->read_page = nand_read_page_raw; in nand_scan_tail()
5181 ecc->write_page = nand_write_page_raw; in nand_scan_tail()
5182 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
5183 ecc->read_page_raw = nand_read_page_raw; in nand_scan_tail()
5184 ecc->write_page_raw = nand_write_page_raw; in nand_scan_tail()
5185 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
5186 ecc->size = mtd->writesize; in nand_scan_tail()
5187 ecc->bytes = 0; in nand_scan_tail()
5188 ecc->strength = 0; in nand_scan_tail()
5192 pr_warn("Invalid NAND_ECC_MODE %d\n", ecc->mode); in nand_scan_tail()
5197 if (!ecc->read_oob_raw) in nand_scan_tail()
5198 ecc->read_oob_raw = ecc->read_oob; in nand_scan_tail()
5199 if (!ecc->write_oob_raw) in nand_scan_tail()
5200 ecc->write_oob_raw = ecc->write_oob; in nand_scan_tail()
5207 if (ecc->layout) { in nand_scan_tail()
5208 for (i = 0; ecc->layout->oobfree[i].length; i++) in nand_scan_tail()
5209 mtd->oobavail += ecc->layout->oobfree[i].length; in nand_scan_tail()
5212 /* ECC sanity check: warn if it's too weak */ in nand_scan_tail()
5214 …pr_warn("WARNING: %s: the ECC used on your system is too weak compared to the one required by the … in nand_scan_tail()
5218 * Set the number of read / write steps for one page depending on ECC in nand_scan_tail()
5221 ecc->steps = mtd->writesize / ecc->size; in nand_scan_tail()
5222 if (ecc->steps * ecc->size != mtd->writesize) { in nand_scan_tail()
5223 pr_warn("Invalid ECC parameters\n"); in nand_scan_tail()
5226 ecc->total = ecc->steps * ecc->bytes; in nand_scan_tail()
5228 /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */ in nand_scan_tail()
5230 switch (ecc->steps) { in nand_scan_tail()
5250 switch (ecc->mode) { in nand_scan_tail()
5277 /* propagate ecc info to mtd_info */ in nand_scan_tail()
5278 mtd->ecclayout = ecc->layout; in nand_scan_tail()
5279 mtd->ecc_strength = ecc->strength; in nand_scan_tail()
5280 mtd->ecc_step_size = ecc->size; in nand_scan_tail()