Lines Matching full:ecc
21 * if we have HW ECC support.
1134 * nand_check_erased_ecc_chunk - check if an ECC chunk contains (almost) only
1138 * @ecc: ECC buffer
1139 * @ecclen: ECC length
1144 * Check if a data buffer and its associated ECC and OOB data contains only
1151 * 1/ ECC algorithms are working on pre-defined block sizes which are usually
1152 * different from the NAND page size. When fixing bitflips, ECC engines will
1159 * the payload data but also their associated ECC data, because a user might
1161 * shouldn't consider the chunk as erased, and checking ECC bytes prevent
1164 * data are protected by the ECC engine.
1166 * extra OOB data to an ECC chunk.
1173 void *ecc, int ecclen, in nand_check_erased_ecc_chunk() argument
1186 ecc_bitflips = nand_check_erased_buf(ecc, ecclen, bitflips_threshold); in nand_check_erased_ecc_chunk()
1201 memset(ecc, 0xff, ecclen); in nand_check_erased_ecc_chunk()
1211 * nand_read_page_raw - [INTERN] read raw page data without ecc
1218 * Not for syndrome calculating ECC controllers, which use a special oob layout.
1230 * nand_read_page_raw_syndrome - [INTERN] read raw page data without ecc
1243 int eccsize = chip->ecc.size; in nand_read_page_raw_syndrome()
1244 int eccbytes = chip->ecc.bytes; in nand_read_page_raw_syndrome()
1248 for (steps = chip->ecc.steps; steps > 0; steps--) { in nand_read_page_raw_syndrome()
1252 if (chip->ecc.prepad) { in nand_read_page_raw_syndrome()
1253 chip->read_buf(mtd, oob, chip->ecc.prepad); in nand_read_page_raw_syndrome()
1254 oob += chip->ecc.prepad; in nand_read_page_raw_syndrome()
1260 if (chip->ecc.postpad) { in nand_read_page_raw_syndrome()
1261 chip->read_buf(mtd, oob, chip->ecc.postpad); in nand_read_page_raw_syndrome()
1262 oob += chip->ecc.postpad; in nand_read_page_raw_syndrome()
1274 * nand_read_page_swecc - [REPLACEABLE] software ECC based page read function
1284 int i, eccsize = chip->ecc.size; in nand_read_page_swecc()
1285 int eccbytes = chip->ecc.bytes; in nand_read_page_swecc()
1286 int eccsteps = chip->ecc.steps; in nand_read_page_swecc()
1290 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_read_page_swecc()
1293 chip->ecc.read_page_raw(mtd, chip, buf, 1, page); in nand_read_page_swecc()
1296 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_swecc()
1298 for (i = 0; i < chip->ecc.total; i++) in nand_read_page_swecc()
1301 eccsteps = chip->ecc.steps; in nand_read_page_swecc()
1307 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_swecc()
1319 * nand_read_subpage - [REPLACEABLE] ECC based sub-page read function
1332 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_read_subpage()
1340 /* Column address within the page aligned to ECC size (256bytes) */ in nand_read_subpage()
1341 start_step = data_offs / chip->ecc.size; in nand_read_subpage()
1342 end_step = (data_offs + readlen - 1) / chip->ecc.size; in nand_read_subpage()
1344 index = start_step * chip->ecc.bytes; in nand_read_subpage()
1346 /* Data size aligned to ECC ecc.size */ in nand_read_subpage()
1347 datafrag_len = num_steps * chip->ecc.size; in nand_read_subpage()
1348 eccfrag_len = num_steps * chip->ecc.bytes; in nand_read_subpage()
1350 data_col_addr = start_step * chip->ecc.size; in nand_read_subpage()
1358 /* Calculate ECC */ in nand_read_subpage()
1359 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) in nand_read_subpage()
1360 chip->ecc.calculate(mtd, p, &chip->buffers->ecccalc[i]); in nand_read_subpage()
1364 * ecc.pos. Let's make sure that there are no gaps in ECC positions. in nand_read_subpage()
1377 * Send the command to read the particular ECC bytes take care in nand_read_subpage()
1384 if (eccpos[index + (num_steps * chip->ecc.bytes)] & (busw - 1)) in nand_read_subpage()
1396 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) { in nand_read_subpage()
1399 stat = chip->ecc.correct(mtd, p, in nand_read_subpage()
1402 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_subpage()
1404 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, in nand_read_subpage()
1406 chip->ecc.bytes, in nand_read_subpage()
1408 chip->ecc.strength); in nand_read_subpage()
1422 * nand_read_page_hwecc - [REPLACEABLE] hardware ECC based page read function
1429 * Not for syndrome calculating ECC controllers which need a special oob layout.
1434 int i, eccsize = chip->ecc.size; in nand_read_page_hwecc()
1435 int eccbytes = chip->ecc.bytes; in nand_read_page_hwecc()
1436 int eccsteps = chip->ecc.steps; in nand_read_page_hwecc()
1440 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_read_page_hwecc()
1444 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_hwecc()
1446 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_hwecc()
1450 for (i = 0; i < chip->ecc.total; i++) in nand_read_page_hwecc()
1453 eccsteps = chip->ecc.steps; in nand_read_page_hwecc()
1459 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_hwecc()
1461 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_hwecc()
1466 chip->ecc.strength); in nand_read_page_hwecc()
1480 * nand_read_page_hwecc_oob_first - [REPLACEABLE] hw ecc, read oob first
1487 * Hardware ECC for large page chips, require OOB to be read first. For this
1488 * ECC mode, the write_page method is re-used from ECC_HW. These methods
1489 * read/write ECC from the OOB area, unlike the ECC_HW_SYNDROME support with
1490 * multiple ECC steps, follows the "infix ECC" scheme and reads/writes ECC from
1496 int i, eccsize = chip->ecc.size; in nand_read_page_hwecc_oob_first()
1497 int eccbytes = chip->ecc.bytes; in nand_read_page_hwecc_oob_first()
1498 int eccsteps = chip->ecc.steps; in nand_read_page_hwecc_oob_first()
1501 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_read_page_hwecc_oob_first()
1510 for (i = 0; i < chip->ecc.total; i++) in nand_read_page_hwecc_oob_first()
1516 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_hwecc_oob_first()
1518 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_hwecc_oob_first()
1520 stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL); in nand_read_page_hwecc_oob_first()
1522 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_hwecc_oob_first()
1527 chip->ecc.strength); in nand_read_page_hwecc_oob_first()
1541 * nand_read_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page read
1554 int i, eccsize = chip->ecc.size; in nand_read_page_syndrome()
1555 int eccbytes = chip->ecc.bytes; in nand_read_page_syndrome()
1556 int eccsteps = chip->ecc.steps; in nand_read_page_syndrome()
1557 int eccpadbytes = eccbytes + chip->ecc.prepad + chip->ecc.postpad; in nand_read_page_syndrome()
1565 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_syndrome()
1568 if (chip->ecc.prepad) { in nand_read_page_syndrome()
1569 chip->read_buf(mtd, oob, chip->ecc.prepad); in nand_read_page_syndrome()
1570 oob += chip->ecc.prepad; in nand_read_page_syndrome()
1573 chip->ecc.hwctl(mtd, NAND_ECC_READSYN); in nand_read_page_syndrome()
1575 stat = chip->ecc.correct(mtd, p, oob, NULL); in nand_read_page_syndrome()
1579 if (chip->ecc.postpad) { in nand_read_page_syndrome()
1580 chip->read_buf(mtd, oob, chip->ecc.postpad); in nand_read_page_syndrome()
1581 oob += chip->ecc.postpad; in nand_read_page_syndrome()
1585 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_syndrome()
1587 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, in nand_read_page_syndrome()
1591 chip->ecc.strength); in nand_read_page_syndrome()
1628 struct nand_oobfree *free = chip->ecc.layout->oobfree; in nand_transfer_oob()
1664 * when there are too many bitflips in a page (i.e., ECC error). After setting
1683 * nand_do_read_ops - [INTERN] Read data with ECC
1742 if (nand_standard_page_accessors(&chip->ecc)) in nand_do_read_ops()
1747 * the read methods return max bitflips per ecc step. in nand_do_read_ops()
1750 ret = chip->ecc.read_page_raw(mtd, chip, bufpoi, in nand_do_read_ops()
1755 ret = chip->ecc.read_subpage(mtd, chip, in nand_do_read_ops()
1759 ret = chip->ecc.read_page(mtd, chip, bufpoi, in nand_do_read_ops()
1883 * nand_read_oob_syndrome - [REPLACEABLE] OOB data read function for HW ECC
1893 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad; in nand_read_oob_syndrome()
1894 int eccsize = chip->ecc.size; in nand_read_oob_syndrome()
1898 chip->cmdfunc(mtd, NAND_CMD_READ0, chip->ecc.size, page); in nand_read_oob_syndrome()
1899 for (i = 0; i < chip->ecc.steps; i++) { in nand_read_oob_syndrome()
1943 * nand_write_oob_syndrome - [REPLACEABLE] OOB data write function for HW ECC
1952 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad; in nand_write_oob_syndrome()
1953 int eccsize = chip->ecc.size, length = mtd->oobsize; in nand_write_oob_syndrome()
1954 int i, len, pos, status = 0, sndcmd = 0, steps = chip->ecc.steps; in nand_write_oob_syndrome()
1958 * data-ecc-data-ecc ... ecc-oob in nand_write_oob_syndrome()
1960 * data-pad-ecc-pad-data-pad .... ecc-pad-oob in nand_write_oob_syndrome()
1962 if (!chip->ecc.prepad && !chip->ecc.postpad) { in nand_write_oob_syndrome()
2053 ret = chip->ecc.read_oob_raw(mtd, chip, page); in nand_do_read_oob()
2055 ret = chip->ecc.read_oob(mtd, chip, page); in nand_do_read_oob()
2152 * Not for syndrome calculating ECC controllers, which use a special oob layout.
2172 * We need a special oob layout and handling even when ECC isn't checked.
2179 int eccsize = chip->ecc.size; in nand_write_page_raw_syndrome()
2180 int eccbytes = chip->ecc.bytes; in nand_write_page_raw_syndrome()
2184 for (steps = chip->ecc.steps; steps > 0; steps--) { in nand_write_page_raw_syndrome()
2188 if (chip->ecc.prepad) { in nand_write_page_raw_syndrome()
2189 chip->write_buf(mtd, oob, chip->ecc.prepad); in nand_write_page_raw_syndrome()
2190 oob += chip->ecc.prepad; in nand_write_page_raw_syndrome()
2196 if (chip->ecc.postpad) { in nand_write_page_raw_syndrome()
2197 chip->write_buf(mtd, oob, chip->ecc.postpad); in nand_write_page_raw_syndrome()
2198 oob += chip->ecc.postpad; in nand_write_page_raw_syndrome()
2209 * nand_write_page_swecc - [REPLACEABLE] software ECC based page write function
2220 int i, eccsize = chip->ecc.size; in nand_write_page_swecc()
2221 int eccbytes = chip->ecc.bytes; in nand_write_page_swecc()
2222 int eccsteps = chip->ecc.steps; in nand_write_page_swecc()
2225 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_write_page_swecc()
2227 /* Software ECC calculation */ in nand_write_page_swecc()
2229 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_write_page_swecc()
2231 for (i = 0; i < chip->ecc.total; i++) in nand_write_page_swecc()
2234 return chip->ecc.write_page_raw(mtd, chip, buf, 1, page); in nand_write_page_swecc()
2238 * nand_write_page_hwecc - [REPLACEABLE] hardware ECC based page write function
2249 int i, eccsize = chip->ecc.size; in nand_write_page_hwecc()
2250 int eccbytes = chip->ecc.bytes; in nand_write_page_hwecc()
2251 int eccsteps = chip->ecc.steps; in nand_write_page_hwecc()
2254 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_write_page_hwecc()
2257 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_page_hwecc()
2259 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_write_page_hwecc()
2262 for (i = 0; i < chip->ecc.total; i++) in nand_write_page_hwecc()
2272 * nand_write_subpage_hwecc - [REPLACEABLE] hardware ECC based subpage write
2288 int ecc_size = chip->ecc.size; in nand_write_subpage_hwecc()
2289 int ecc_bytes = chip->ecc.bytes; in nand_write_subpage_hwecc()
2290 int ecc_steps = chip->ecc.steps; in nand_write_subpage_hwecc()
2291 uint32_t *eccpos = chip->ecc.layout->eccpos; in nand_write_subpage_hwecc()
2299 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_subpage_hwecc()
2304 /* mask ECC of un-touched subpages by padding 0xFF */ in nand_write_subpage_hwecc()
2308 chip->ecc.calculate(mtd, buf, ecc_calc); in nand_write_subpage_hwecc()
2320 /* copy calculated ECC for whole page to chip->buffer->oob */ in nand_write_subpage_hwecc()
2323 for (i = 0; i < chip->ecc.total; i++) in nand_write_subpage_hwecc()
2334 * nand_write_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page write
2349 int i, eccsize = chip->ecc.size; in nand_write_page_syndrome()
2350 int eccbytes = chip->ecc.bytes; in nand_write_page_syndrome()
2351 int eccsteps = chip->ecc.steps; in nand_write_page_syndrome()
2357 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_page_syndrome()
2360 if (chip->ecc.prepad) { in nand_write_page_syndrome()
2361 chip->write_buf(mtd, oob, chip->ecc.prepad); in nand_write_page_syndrome()
2362 oob += chip->ecc.prepad; in nand_write_page_syndrome()
2365 chip->ecc.calculate(mtd, p, oob); in nand_write_page_syndrome()
2369 if (chip->ecc.postpad) { in nand_write_page_syndrome()
2370 chip->write_buf(mtd, oob, chip->ecc.postpad); in nand_write_page_syndrome()
2371 oob += chip->ecc.postpad; in nand_write_page_syndrome()
2401 chip->ecc.write_subpage) in nand_write_page()
2406 if (nand_standard_page_accessors(&chip->ecc)) in nand_write_page()
2410 status = chip->ecc.write_page_raw(mtd, chip, buf, in nand_write_page()
2413 status = chip->ecc.write_subpage(mtd, chip, offset, data_len, in nand_write_page()
2416 status = chip->ecc.write_page(mtd, chip, buf, oob_required, in nand_write_page()
2422 if (nand_standard_page_accessors(&chip->ecc)) { in nand_write_page()
2459 struct nand_oobfree *free = chip->ecc.layout->oobfree; in nand_fill_oob()
2492 * nand_do_write_ops - [INTERN] NAND write with ECC
2497 * NAND write with ECC.
2618 * panic_nand_write - [MTD Interface] NAND write with ECC
2625 * NAND write with ECC. Used when performing writes in interrupt context, this
2722 status = chip->ecc.write_oob_raw(mtd, chip, page & chip->pagemask); in nand_do_write_oob()
2724 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); in nand_do_write_oob()
3119 struct onfi_ext_ecc_info *ecc; in nand_flash_detect_ext_param_page() local
3154 /* find the ECC section. */ in nand_flash_detect_ext_param_page()
3163 pr_debug("We can not find the ECC section.\n"); in nand_flash_detect_ext_param_page()
3168 ecc = (struct onfi_ext_ecc_info *)cursor; in nand_flash_detect_ext_param_page()
3170 if (!ecc->codeword_size) { in nand_flash_detect_ext_param_page()
3175 chip->ecc_strength_ds = ecc->ecc_bits; in nand_flash_detect_ext_param_page()
3176 chip->ecc_step_ds = 1 << ecc->codeword_size; in nand_flash_detect_ext_param_page()
3303 pr_warn("Could not retrieve ONFI ECC requirements\n"); in nand_flash_detect_onfi()
3326 struct jedec_ecc_info *ecc; in nand_flash_detect_jedec() local
3387 /* ECC info */ in nand_flash_detect_jedec()
3388 ecc = &p->ecc_info[0]; in nand_flash_detect_jedec()
3390 if (ecc->codeword_size >= 9) { in nand_flash_detect_jedec()
3391 chip->ecc_strength_ds = ecc->ecc_bits; in nand_flash_detect_jedec()
3392 chip->ecc_step_ds = 1 << ecc->codeword_size; in nand_flash_detect_jedec()
3896 str = fdt_getprop(blob, node, "nand-ecc-mode", NULL); in nand_dt_init()
3913 ecc_strength = fdtdec_get_int(blob, node, "nand-ecc-strength", -1); in nand_dt_init()
3914 ecc_step = fdtdec_get_int(blob, node, "nand-ecc-step-size", -1); in nand_dt_init()
3923 chip->ecc.mode = ecc_mode; in nand_dt_init()
3926 chip->ecc.strength = ecc_strength; in nand_dt_init()
3929 chip->ecc.size = ecc_step; in nand_dt_init()
3931 if (fdt_getprop(blob, node, "nand-ecc-maximize", NULL)) in nand_dt_init()
3932 chip->ecc.options |= NAND_ECC_MAXIMIZE; in nand_dt_init()
4031 * nand_check_ecc_caps - check the sanity of preset ECC settings
4033 * @caps: ECC caps info structure
4034 * @oobavail: OOB size that the ECC engine can use
4036 * When ECC step size and strength are already set, check if they are supported
4037 * by the controller and the calculated ECC bytes fit within the chip's OOB.
4038 * On success, the calculated ECC bytes is set.
4045 int preset_step = chip->ecc.size; in nand_check_ecc_caps()
4046 int preset_strength = chip->ecc.strength; in nand_check_ecc_caps()
4074 pr_err("ECC (step, strength) = (%d, %d) does not fit in OOB", in nand_check_ecc_caps()
4079 chip->ecc.bytes = ecc_bytes; in nand_check_ecc_caps()
4085 pr_err("ECC (step, strength) = (%d, %d) not supported on this controller", in nand_check_ecc_caps()
4093 * nand_match_ecc_req - meet the chip's requirement with least ECC bytes
4095 * @caps: ECC engine caps info structure
4096 * @oobavail: OOB size that the ECC engine can use
4098 * If a chip's ECC requirement is provided, try to meet it with the least
4099 * number of ECC bytes (i.e. with the largest number of OOB-free bytes).
4100 * On success, the chosen ECC settings are set.
4155 * with the least number of ECC bytes. in nand_match_ecc_req()
4169 chip->ecc.size = best_step; in nand_match_ecc_req()
4170 chip->ecc.strength = best_strength; in nand_match_ecc_req()
4171 chip->ecc.bytes = best_ecc_bytes; in nand_match_ecc_req()
4178 * nand_maximize_ecc - choose the max ECC strength available
4180 * @caps: ECC engine caps info structure
4181 * @oobavail: OOB size that the ECC engine can use
4183 * Choose the max ECC strength that is supported on the controller, and can fit
4184 * within the chip's OOB. On success, the chosen ECC settings are set.
4204 /* If chip->ecc.size is already set, respect it */ in nand_maximize_ecc()
4205 if (chip->ecc.size && step_size != chip->ecc.size) in nand_maximize_ecc()
4242 chip->ecc.size = best_step; in nand_maximize_ecc()
4243 chip->ecc.strength = best_strength; in nand_maximize_ecc()
4244 chip->ecc.bytes = best_ecc_bytes; in nand_maximize_ecc()
4267 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_ecc_strength_good() local
4270 if (ecc->size == 0 || chip->ecc_step_ds == 0) in nand_ecc_strength_good()
4278 corr = (mtd->writesize * ecc->strength) / ecc->size; in nand_ecc_strength_good()
4281 return corr >= ds_corr && ecc->strength >= chip->ecc_strength_ds; in nand_ecc_strength_good()
4286 struct nand_ecc_ctrl *ecc = &chip->ecc; in invalid_ecc_page_accessors() local
4288 if (nand_standard_page_accessors(ecc)) in invalid_ecc_page_accessors()
4297 return (!ecc->read_page || !ecc->write_page || in invalid_ecc_page_accessors()
4298 !ecc->read_page_raw || !ecc->write_page_raw || in invalid_ecc_page_accessors()
4299 (NAND_HAS_SUBPAGE_READ(chip) && !ecc->read_subpage) || in invalid_ecc_page_accessors()
4300 (NAND_HAS_SUBPAGE_WRITE(chip) && !ecc->write_subpage && in invalid_ecc_page_accessors()
4301 ecc->hwctl && ecc->calculate)); in invalid_ecc_page_accessors()
4316 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_scan_tail() local
4324 pr_err("Invalid ECC page accessors setup\n"); in nand_scan_tail()
4342 if (!ecc->layout && (ecc->mode != NAND_ECC_SOFT_BCH)) { in nand_scan_tail()
4346 ecc->layout = &nand_oob_8; in nand_scan_tail()
4349 ecc->layout = &nand_oob_16; in nand_scan_tail()
4352 ecc->layout = &nand_oob_64; in nand_scan_tail()
4355 ecc->layout = &nand_oob_128; in nand_scan_tail()
4369 * Check ECC mode, default to software if 3byte/512byte hardware ECC is in nand_scan_tail()
4370 * selected and we have 256 byte pagesize fallback to software ECC in nand_scan_tail()
4373 switch (ecc->mode) { in nand_scan_tail()
4376 if (!ecc->calculate || !ecc->correct || !ecc->hwctl) { in nand_scan_tail()
4377 pr_warn("No ECC functions supplied; hardware ECC not possible\n"); in nand_scan_tail()
4380 if (!ecc->read_page) in nand_scan_tail()
4381 ecc->read_page = nand_read_page_hwecc_oob_first; in nand_scan_tail()
4385 if (!ecc->read_page) in nand_scan_tail()
4386 ecc->read_page = nand_read_page_hwecc; in nand_scan_tail()
4387 if (!ecc->write_page) in nand_scan_tail()
4388 ecc->write_page = nand_write_page_hwecc; in nand_scan_tail()
4389 if (!ecc->read_page_raw) in nand_scan_tail()
4390 ecc->read_page_raw = nand_read_page_raw; in nand_scan_tail()
4391 if (!ecc->write_page_raw) in nand_scan_tail()
4392 ecc->write_page_raw = nand_write_page_raw; in nand_scan_tail()
4393 if (!ecc->read_oob) in nand_scan_tail()
4394 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
4395 if (!ecc->write_oob) in nand_scan_tail()
4396 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
4397 if (!ecc->read_subpage) in nand_scan_tail()
4398 ecc->read_subpage = nand_read_subpage; in nand_scan_tail()
4399 if (!ecc->write_subpage && ecc->hwctl && ecc->calculate) in nand_scan_tail()
4400 ecc->write_subpage = nand_write_subpage_hwecc; in nand_scan_tail()
4403 if ((!ecc->calculate || !ecc->correct || !ecc->hwctl) && in nand_scan_tail()
4404 (!ecc->read_page || in nand_scan_tail()
4405 ecc->read_page == nand_read_page_hwecc || in nand_scan_tail()
4406 !ecc->write_page || in nand_scan_tail()
4407 ecc->write_page == nand_write_page_hwecc)) { in nand_scan_tail()
4408 pr_warn("No ECC functions supplied; hardware ECC not possible\n"); in nand_scan_tail()
4412 if (!ecc->read_page) in nand_scan_tail()
4413 ecc->read_page = nand_read_page_syndrome; in nand_scan_tail()
4414 if (!ecc->write_page) in nand_scan_tail()
4415 ecc->write_page = nand_write_page_syndrome; in nand_scan_tail()
4416 if (!ecc->read_page_raw) in nand_scan_tail()
4417 ecc->read_page_raw = nand_read_page_raw_syndrome; in nand_scan_tail()
4418 if (!ecc->write_page_raw) in nand_scan_tail()
4419 ecc->write_page_raw = nand_write_page_raw_syndrome; in nand_scan_tail()
4420 if (!ecc->read_oob) in nand_scan_tail()
4421 ecc->read_oob = nand_read_oob_syndrome; in nand_scan_tail()
4422 if (!ecc->write_oob) in nand_scan_tail()
4423 ecc->write_oob = nand_write_oob_syndrome; in nand_scan_tail()
4425 if (mtd->writesize >= ecc->size) { in nand_scan_tail()
4426 if (!ecc->strength) { in nand_scan_tail()
4427 pr_warn("Driver must set ecc.strength when using hardware ECC\n"); in nand_scan_tail()
4432 pr_warn("%d byte HW ECC not possible on %d byte page size, fallback to SW ECC\n", in nand_scan_tail()
4433 ecc->size, mtd->writesize); in nand_scan_tail()
4434 ecc->mode = NAND_ECC_SOFT; in nand_scan_tail()
4437 ecc->calculate = nand_calculate_ecc; in nand_scan_tail()
4438 ecc->correct = nand_correct_data; in nand_scan_tail()
4439 ecc->read_page = nand_read_page_swecc; in nand_scan_tail()
4440 ecc->read_subpage = nand_read_subpage; in nand_scan_tail()
4441 ecc->write_page = nand_write_page_swecc; in nand_scan_tail()
4442 ecc->read_page_raw = nand_read_page_raw; in nand_scan_tail()
4443 ecc->write_page_raw = nand_write_page_raw; in nand_scan_tail()
4444 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
4445 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
4446 if (!ecc->size) in nand_scan_tail()
4447 ecc->size = 256; in nand_scan_tail()
4448 ecc->bytes = 3; in nand_scan_tail()
4449 ecc->strength = 1; in nand_scan_tail()
4457 ecc->calculate = nand_bch_calculate_ecc; in nand_scan_tail()
4458 ecc->correct = nand_bch_correct_data; in nand_scan_tail()
4459 ecc->read_page = nand_read_page_swecc; in nand_scan_tail()
4460 ecc->read_subpage = nand_read_subpage; in nand_scan_tail()
4461 ecc->write_page = nand_write_page_swecc; in nand_scan_tail()
4462 ecc->read_page_raw = nand_read_page_raw; in nand_scan_tail()
4463 ecc->write_page_raw = nand_write_page_raw; in nand_scan_tail()
4464 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
4465 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
4467 * Board driver should supply ecc.size and ecc.strength values in nand_scan_tail()
4471 if (!ecc->size && (mtd->oobsize >= 64)) { in nand_scan_tail()
4472 ecc->size = 512; in nand_scan_tail()
4473 ecc->strength = 4; in nand_scan_tail()
4477 ecc->bytes = 0; in nand_scan_tail()
4478 ecc->priv = nand_bch_init(mtd); in nand_scan_tail()
4479 if (!ecc->priv) { in nand_scan_tail()
4480 pr_warn("BCH ECC initialization failed!\n"); in nand_scan_tail()
4487 ecc->read_page = nand_read_page_raw; in nand_scan_tail()
4488 ecc->write_page = nand_write_page_raw; in nand_scan_tail()
4489 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
4490 ecc->read_page_raw = nand_read_page_raw; in nand_scan_tail()
4491 ecc->write_page_raw = nand_write_page_raw; in nand_scan_tail()
4492 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
4493 ecc->size = mtd->writesize; in nand_scan_tail()
4494 ecc->bytes = 0; in nand_scan_tail()
4495 ecc->strength = 0; in nand_scan_tail()
4499 pr_warn("Invalid NAND_ECC_MODE %d\n", ecc->mode); in nand_scan_tail()
4504 if (!ecc->read_oob_raw) in nand_scan_tail()
4505 ecc->read_oob_raw = ecc->read_oob; in nand_scan_tail()
4506 if (!ecc->write_oob_raw) in nand_scan_tail()
4507 ecc->write_oob_raw = ecc->write_oob; in nand_scan_tail()
4514 if (ecc->layout) { in nand_scan_tail()
4515 for (i = 0; ecc->layout->oobfree[i].length; i++) in nand_scan_tail()
4516 mtd->oobavail += ecc->layout->oobfree[i].length; in nand_scan_tail()
4519 /* ECC sanity check: warn if it's too weak */ in nand_scan_tail()
4521 …pr_warn("WARNING: %s: the ECC used on your system is too weak compared to the one required by the … in nand_scan_tail()
4525 * Set the number of read / write steps for one page depending on ECC in nand_scan_tail()
4528 ecc->steps = mtd->writesize / ecc->size; in nand_scan_tail()
4529 if (ecc->steps * ecc->size != mtd->writesize) { in nand_scan_tail()
4530 pr_warn("Invalid ECC parameters\n"); in nand_scan_tail()
4533 ecc->total = ecc->steps * ecc->bytes; in nand_scan_tail()
4535 /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */ in nand_scan_tail()
4537 switch (ecc->steps) { in nand_scan_tail()
4557 switch (ecc->mode) { in nand_scan_tail()
4584 /* propagate ecc info to mtd_info */ in nand_scan_tail()
4585 mtd->ecclayout = ecc->layout; in nand_scan_tail()
4586 mtd->ecc_strength = ecc->strength; in nand_scan_tail()
4587 mtd->ecc_step_size = ecc->size; in nand_scan_tail()