Lines Matching full:ecc
22 * if we have HW ECC support.
262 res = chip->ecc.read_oob(chip, first_page + page_offset); in nand_block_bad()
433 status = chip->ecc.write_oob_raw(chip, page & chip->pagemask); in nand_do_write_oob()
435 status = chip->ecc.write_oob(chip, page & chip->pagemask); in nand_do_write_oob()
2496 * nand_check_erased_ecc_chunk - check if an ECC chunk contains (almost) only
2500 * @ecc: ECC buffer
2501 * @ecclen: ECC length
2506 * Check if a data buffer and its associated ECC and OOB data contains only
2513 * 1/ ECC algorithms are working on pre-defined block sizes which are usually
2514 * different from the NAND page size. When fixing bitflips, ECC engines will
2521 * the payload data but also their associated ECC data, because a user might
2523 * shouldn't consider the chunk as erased, and checking ECC bytes prevent
2526 * data are protected by the ECC engine.
2528 * extra OOB data to an ECC chunk.
2535 void *ecc, int ecclen, in nand_check_erased_ecc_chunk() argument
2548 ecc_bitflips = nand_check_erased_buf(ecc, ecclen, bitflips_threshold); in nand_check_erased_ecc_chunk()
2563 memset(ecc, 0xff, ecclen); in nand_check_erased_ecc_chunk()
2588 * nand_read_page_raw - [INTERN] read raw page data without ecc
2594 * Not for syndrome calculating ECC controllers, which use a special oob layout.
2659 * nand_read_page_raw_syndrome - [INTERN] read raw page data without ecc
2671 int eccsize = chip->ecc.size; in nand_read_page_raw_syndrome()
2672 int eccbytes = chip->ecc.bytes; in nand_read_page_raw_syndrome()
2680 for (steps = chip->ecc.steps; steps > 0; steps--) { in nand_read_page_raw_syndrome()
2687 if (chip->ecc.prepad) { in nand_read_page_raw_syndrome()
2688 ret = nand_read_data_op(chip, oob, chip->ecc.prepad, in nand_read_page_raw_syndrome()
2693 oob += chip->ecc.prepad; in nand_read_page_raw_syndrome()
2702 if (chip->ecc.postpad) { in nand_read_page_raw_syndrome()
2703 ret = nand_read_data_op(chip, oob, chip->ecc.postpad, in nand_read_page_raw_syndrome()
2708 oob += chip->ecc.postpad; in nand_read_page_raw_syndrome()
2723 * nand_read_page_swecc - [REPLACEABLE] software ECC based page read function
2733 int i, eccsize = chip->ecc.size, ret; in nand_read_page_swecc()
2734 int eccbytes = chip->ecc.bytes; in nand_read_page_swecc()
2735 int eccsteps = chip->ecc.steps; in nand_read_page_swecc()
2737 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_read_page_swecc()
2738 uint8_t *ecc_code = chip->ecc.code_buf; in nand_read_page_swecc()
2741 chip->ecc.read_page_raw(chip, buf, 1, page); in nand_read_page_swecc()
2744 chip->ecc.calculate(chip, p, &ecc_calc[i]); in nand_read_page_swecc()
2747 chip->ecc.total); in nand_read_page_swecc()
2751 eccsteps = chip->ecc.steps; in nand_read_page_swecc()
2757 stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_swecc()
2769 * nand_read_subpage - [REPLACEABLE] ECC based sub-page read function
2789 /* Column address within the page aligned to ECC size (256bytes) */ in nand_read_subpage()
2790 start_step = data_offs / chip->ecc.size; in nand_read_subpage()
2791 end_step = (data_offs + readlen - 1) / chip->ecc.size; in nand_read_subpage()
2793 index = start_step * chip->ecc.bytes; in nand_read_subpage()
2795 /* Data size aligned to ECC ecc.size */ in nand_read_subpage()
2796 datafrag_len = num_steps * chip->ecc.size; in nand_read_subpage()
2797 eccfrag_len = num_steps * chip->ecc.bytes; in nand_read_subpage()
2799 data_col_addr = start_step * chip->ecc.size; in nand_read_subpage()
2806 /* Calculate ECC */ in nand_read_subpage()
2807 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) in nand_read_subpage()
2808 chip->ecc.calculate(chip, p, &chip->ecc.calc_buf[i]); in nand_read_subpage()
2812 * ecc.pos. Let's make sure that there are no gaps in ECC positions. in nand_read_subpage()
2829 * Send the command to read the particular ECC bytes take care in nand_read_subpage()
2836 if ((oobregion.offset + (num_steps * chip->ecc.bytes)) & in nand_read_subpage()
2848 ret = mtd_ooblayout_get_eccbytes(mtd, chip->ecc.code_buf, in nand_read_subpage()
2854 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) { in nand_read_subpage()
2857 stat = chip->ecc.correct(chip, p, &chip->ecc.code_buf[i], in nand_read_subpage()
2858 &chip->ecc.calc_buf[i]); in nand_read_subpage()
2860 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_subpage()
2862 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, in nand_read_subpage()
2863 &chip->ecc.code_buf[i], in nand_read_subpage()
2864 chip->ecc.bytes, in nand_read_subpage()
2866 chip->ecc.strength); in nand_read_subpage()
2880 * nand_read_page_hwecc - [REPLACEABLE] hardware ECC based page read function
2886 * Not for syndrome calculating ECC controllers which need a special oob layout.
2892 int i, eccsize = chip->ecc.size, ret; in nand_read_page_hwecc()
2893 int eccbytes = chip->ecc.bytes; in nand_read_page_hwecc()
2894 int eccsteps = chip->ecc.steps; in nand_read_page_hwecc()
2896 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_read_page_hwecc()
2897 uint8_t *ecc_code = chip->ecc.code_buf; in nand_read_page_hwecc()
2905 chip->ecc.hwctl(chip, NAND_ECC_READ); in nand_read_page_hwecc()
2911 chip->ecc.calculate(chip, p, &ecc_calc[i]); in nand_read_page_hwecc()
2920 chip->ecc.total); in nand_read_page_hwecc()
2924 eccsteps = chip->ecc.steps; in nand_read_page_hwecc()
2930 stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_hwecc()
2932 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_hwecc()
2937 chip->ecc.strength); in nand_read_page_hwecc()
2951 * nand_read_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page read
2964 int ret, i, eccsize = chip->ecc.size; in nand_read_page_syndrome()
2965 int eccbytes = chip->ecc.bytes; in nand_read_page_syndrome()
2966 int eccsteps = chip->ecc.steps; in nand_read_page_syndrome()
2967 int eccpadbytes = eccbytes + chip->ecc.prepad + chip->ecc.postpad; in nand_read_page_syndrome()
2979 chip->ecc.hwctl(chip, NAND_ECC_READ); in nand_read_page_syndrome()
2985 if (chip->ecc.prepad) { in nand_read_page_syndrome()
2986 ret = nand_read_data_op(chip, oob, chip->ecc.prepad, in nand_read_page_syndrome()
2991 oob += chip->ecc.prepad; in nand_read_page_syndrome()
2994 chip->ecc.hwctl(chip, NAND_ECC_READSYN); in nand_read_page_syndrome()
3000 stat = chip->ecc.correct(chip, p, oob, NULL); in nand_read_page_syndrome()
3004 if (chip->ecc.postpad) { in nand_read_page_syndrome()
3005 ret = nand_read_data_op(chip, oob, chip->ecc.postpad, in nand_read_page_syndrome()
3010 oob += chip->ecc.postpad; in nand_read_page_syndrome()
3014 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_syndrome()
3016 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, in nand_read_page_syndrome()
3020 chip->ecc.strength); in nand_read_page_syndrome()
3080 * when there are too many bitflips in a page (i.e., ECC error). After setting
3108 * nand_do_read_ops - [INTERN] Read data with ECC
3169 * the read methods return max bitflips per ecc step. in nand_do_read_ops()
3172 ret = chip->ecc.read_page_raw(chip, bufpoi, in nand_do_read_ops()
3177 ret = chip->ecc.read_subpage(chip, col, bytes, in nand_do_read_ops()
3180 ret = chip->ecc.read_page(chip, bufpoi, in nand_do_read_ops()
3299 * nand_read_oob_syndrome - [REPLACEABLE] OOB data read function for HW ECC
3308 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad; in nand_read_oob_syndrome()
3309 int eccsize = chip->ecc.size; in nand_read_oob_syndrome()
3313 ret = nand_read_page_op(chip, page, chip->ecc.size, NULL, 0); in nand_read_oob_syndrome()
3317 for (i = 0; i < chip->ecc.steps; i++) { in nand_read_oob_syndrome()
3367 * nand_write_oob_syndrome - [REPLACEABLE] OOB data write function for HW ECC
3375 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad; in nand_write_oob_syndrome()
3376 int eccsize = chip->ecc.size, length = mtd->oobsize; in nand_write_oob_syndrome()
3377 int ret, i, len, pos, sndcmd = 0, steps = chip->ecc.steps; in nand_write_oob_syndrome()
3381 * data-ecc-data-ecc ... ecc-oob in nand_write_oob_syndrome()
3383 * data-pad-ecc-pad-data-pad .... ecc-pad-oob in nand_write_oob_syndrome()
3385 if (!chip->ecc.prepad && !chip->ecc.postpad) { in nand_write_oob_syndrome()
3475 ret = chip->ecc.read_oob_raw(chip, page); in nand_do_read_oob()
3477 ret = chip->ecc.read_oob(chip, page); in nand_do_read_oob()
3571 * Not for syndrome calculating ECC controllers, which use a special oob layout.
3637 * We need a special oob layout and handling even when ECC isn't checked.
3644 int eccsize = chip->ecc.size; in nand_write_page_raw_syndrome()
3645 int eccbytes = chip->ecc.bytes; in nand_write_page_raw_syndrome()
3653 for (steps = chip->ecc.steps; steps > 0; steps--) { in nand_write_page_raw_syndrome()
3660 if (chip->ecc.prepad) { in nand_write_page_raw_syndrome()
3661 ret = nand_write_data_op(chip, oob, chip->ecc.prepad, in nand_write_page_raw_syndrome()
3666 oob += chip->ecc.prepad; in nand_write_page_raw_syndrome()
3675 if (chip->ecc.postpad) { in nand_write_page_raw_syndrome()
3676 ret = nand_write_data_op(chip, oob, chip->ecc.postpad, in nand_write_page_raw_syndrome()
3681 oob += chip->ecc.postpad; in nand_write_page_raw_syndrome()
3695 * nand_write_page_swecc - [REPLACEABLE] software ECC based page write function
3705 int i, eccsize = chip->ecc.size, ret; in nand_write_page_swecc()
3706 int eccbytes = chip->ecc.bytes; in nand_write_page_swecc()
3707 int eccsteps = chip->ecc.steps; in nand_write_page_swecc()
3708 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_write_page_swecc()
3711 /* Software ECC calculation */ in nand_write_page_swecc()
3713 chip->ecc.calculate(chip, p, &ecc_calc[i]); in nand_write_page_swecc()
3716 chip->ecc.total); in nand_write_page_swecc()
3720 return chip->ecc.write_page_raw(chip, buf, 1, page); in nand_write_page_swecc()
3724 * nand_write_page_hwecc - [REPLACEABLE] hardware ECC based page write function
3734 int i, eccsize = chip->ecc.size, ret; in nand_write_page_hwecc()
3735 int eccbytes = chip->ecc.bytes; in nand_write_page_hwecc()
3736 int eccsteps = chip->ecc.steps; in nand_write_page_hwecc()
3737 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_write_page_hwecc()
3745 chip->ecc.hwctl(chip, NAND_ECC_WRITE); in nand_write_page_hwecc()
3751 chip->ecc.calculate(chip, p, &ecc_calc[i]); in nand_write_page_hwecc()
3755 chip->ecc.total); in nand_write_page_hwecc()
3768 * nand_write_subpage_hwecc - [REPLACEABLE] hardware ECC based subpage write
3782 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_write_subpage_hwecc()
3783 int ecc_size = chip->ecc.size; in nand_write_subpage_hwecc()
3784 int ecc_bytes = chip->ecc.bytes; in nand_write_subpage_hwecc()
3785 int ecc_steps = chip->ecc.steps; in nand_write_subpage_hwecc()
3797 chip->ecc.hwctl(chip, NAND_ECC_WRITE); in nand_write_subpage_hwecc()
3804 /* mask ECC of un-touched subpages by padding 0xFF */ in nand_write_subpage_hwecc()
3808 chip->ecc.calculate(chip, buf, ecc_calc); in nand_write_subpage_hwecc()
3820 /* copy calculated ECC for whole page to chip->buffer->oob */ in nand_write_subpage_hwecc()
3822 ecc_calc = chip->ecc.calc_buf; in nand_write_subpage_hwecc()
3824 chip->ecc.total); in nand_write_subpage_hwecc()
3838 * nand_write_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page write
3851 int i, eccsize = chip->ecc.size; in nand_write_page_syndrome()
3852 int eccbytes = chip->ecc.bytes; in nand_write_page_syndrome()
3853 int eccsteps = chip->ecc.steps; in nand_write_page_syndrome()
3863 chip->ecc.hwctl(chip, NAND_ECC_WRITE); in nand_write_page_syndrome()
3869 if (chip->ecc.prepad) { in nand_write_page_syndrome()
3870 ret = nand_write_data_op(chip, oob, chip->ecc.prepad, in nand_write_page_syndrome()
3875 oob += chip->ecc.prepad; in nand_write_page_syndrome()
3878 chip->ecc.calculate(chip, p, oob); in nand_write_page_syndrome()
3886 if (chip->ecc.postpad) { in nand_write_page_syndrome()
3887 ret = nand_write_data_op(chip, oob, chip->ecc.postpad, in nand_write_page_syndrome()
3892 oob += chip->ecc.postpad; in nand_write_page_syndrome()
3925 chip->ecc.write_subpage) in nand_write_page()
3931 status = chip->ecc.write_page_raw(chip, buf, oob_required, in nand_write_page()
3934 status = chip->ecc.write_subpage(chip, offset, data_len, buf, in nand_write_page()
3937 status = chip->ecc.write_page(chip, buf, oob_required, page); in nand_write_page()
3948 * nand_do_write_ops - [INTERN] NAND write with ECC
3953 * NAND write with ECC.
4077 * panic_nand_write - [MTD Interface] NAND write with ECC
4084 * NAND write with ECC. Used when performing writes in interrupt context, this
4899 err = of_property_read_string(np, "nand-ecc-mode", &pm); in of_get_rawnand_ecc_engine_type_legacy()
4932 err = of_property_read_string(np, "nand-ecc-mode", &pm); in of_get_rawnand_ecc_placement_legacy()
4946 err = of_property_read_string(np, "nand-ecc-mode", &pm); in of_get_rawnand_ecc_algo_legacy()
4960 struct nand_ecc_props *user_conf = &chip->base.ecc.user_conf; in of_get_nand_ecc_legacy_user_config()
5015 * ECC engine type, we will default to NAND_ECC_ENGINE_TYPE_ON_HOST. in rawnand_dt_init()
5017 nand->ecc.defaults.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in rawnand_dt_init()
5024 if (nand->ecc.user_conf.engine_type != NAND_ECC_ENGINE_TYPE_INVALID) in rawnand_dt_init()
5025 chip->ecc.engine_type = nand->ecc.user_conf.engine_type; in rawnand_dt_init()
5026 if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_INVALID) in rawnand_dt_init()
5027 chip->ecc.engine_type = nand->ecc.defaults.engine_type; in rawnand_dt_init()
5029 chip->ecc.placement = nand->ecc.user_conf.placement; in rawnand_dt_init()
5030 chip->ecc.algo = nand->ecc.user_conf.algo; in rawnand_dt_init()
5031 chip->ecc.strength = nand->ecc.user_conf.strength; in rawnand_dt_init()
5032 chip->ecc.size = nand->ecc.user_conf.step_size; in rawnand_dt_init()
5047 * to tweak some ECC-related parameters before nand_scan_tail(). This separation
5140 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_set_ecc_on_host_ops() local
5142 switch (ecc->placement) { in nand_set_ecc_on_host_ops()
5146 if (!ecc->read_page) in nand_set_ecc_on_host_ops()
5147 ecc->read_page = nand_read_page_hwecc; in nand_set_ecc_on_host_ops()
5148 if (!ecc->write_page) in nand_set_ecc_on_host_ops()
5149 ecc->write_page = nand_write_page_hwecc; in nand_set_ecc_on_host_ops()
5150 if (!ecc->read_page_raw) in nand_set_ecc_on_host_ops()
5151 ecc->read_page_raw = nand_read_page_raw; in nand_set_ecc_on_host_ops()
5152 if (!ecc->write_page_raw) in nand_set_ecc_on_host_ops()
5153 ecc->write_page_raw = nand_write_page_raw; in nand_set_ecc_on_host_ops()
5154 if (!ecc->read_oob) in nand_set_ecc_on_host_ops()
5155 ecc->read_oob = nand_read_oob_std; in nand_set_ecc_on_host_ops()
5156 if (!ecc->write_oob) in nand_set_ecc_on_host_ops()
5157 ecc->write_oob = nand_write_oob_std; in nand_set_ecc_on_host_ops()
5158 if (!ecc->read_subpage) in nand_set_ecc_on_host_ops()
5159 ecc->read_subpage = nand_read_subpage; in nand_set_ecc_on_host_ops()
5160 if (!ecc->write_subpage && ecc->hwctl && ecc->calculate) in nand_set_ecc_on_host_ops()
5161 ecc->write_subpage = nand_write_subpage_hwecc; in nand_set_ecc_on_host_ops()
5165 if ((!ecc->calculate || !ecc->correct || !ecc->hwctl) && in nand_set_ecc_on_host_ops()
5166 (!ecc->read_page || in nand_set_ecc_on_host_ops()
5167 ecc->read_page == nand_read_page_hwecc || in nand_set_ecc_on_host_ops()
5168 !ecc->write_page || in nand_set_ecc_on_host_ops()
5169 ecc->write_page == nand_write_page_hwecc)) { in nand_set_ecc_on_host_ops()
5170 WARN(1, "No ECC functions supplied; hardware ECC not possible\n"); in nand_set_ecc_on_host_ops()
5174 if (!ecc->read_page) in nand_set_ecc_on_host_ops()
5175 ecc->read_page = nand_read_page_syndrome; in nand_set_ecc_on_host_ops()
5176 if (!ecc->write_page) in nand_set_ecc_on_host_ops()
5177 ecc->write_page = nand_write_page_syndrome; in nand_set_ecc_on_host_ops()
5178 if (!ecc->read_page_raw) in nand_set_ecc_on_host_ops()
5179 ecc->read_page_raw = nand_read_page_raw_syndrome; in nand_set_ecc_on_host_ops()
5180 if (!ecc->write_page_raw) in nand_set_ecc_on_host_ops()
5181 ecc->write_page_raw = nand_write_page_raw_syndrome; in nand_set_ecc_on_host_ops()
5182 if (!ecc->read_oob) in nand_set_ecc_on_host_ops()
5183 ecc->read_oob = nand_read_oob_syndrome; in nand_set_ecc_on_host_ops()
5184 if (!ecc->write_oob) in nand_set_ecc_on_host_ops()
5185 ecc->write_oob = nand_write_oob_syndrome; in nand_set_ecc_on_host_ops()
5190 ecc->placement); in nand_set_ecc_on_host_ops()
5201 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_set_ecc_soft_ops() local
5203 if (WARN_ON(ecc->engine_type != NAND_ECC_ENGINE_TYPE_SOFT)) in nand_set_ecc_soft_ops()
5206 switch (ecc->algo) { in nand_set_ecc_soft_ops()
5208 ecc->calculate = nand_calculate_ecc; in nand_set_ecc_soft_ops()
5209 ecc->correct = nand_correct_data; in nand_set_ecc_soft_ops()
5210 ecc->read_page = nand_read_page_swecc; in nand_set_ecc_soft_ops()
5211 ecc->read_subpage = nand_read_subpage; in nand_set_ecc_soft_ops()
5212 ecc->write_page = nand_write_page_swecc; in nand_set_ecc_soft_ops()
5213 if (!ecc->read_page_raw) in nand_set_ecc_soft_ops()
5214 ecc->read_page_raw = nand_read_page_raw; in nand_set_ecc_soft_ops()
5215 if (!ecc->write_page_raw) in nand_set_ecc_soft_ops()
5216 ecc->write_page_raw = nand_write_page_raw; in nand_set_ecc_soft_ops()
5217 ecc->read_oob = nand_read_oob_std; in nand_set_ecc_soft_ops()
5218 ecc->write_oob = nand_write_oob_std; in nand_set_ecc_soft_ops()
5219 if (!ecc->size) in nand_set_ecc_soft_ops()
5220 ecc->size = 256; in nand_set_ecc_soft_ops()
5221 ecc->bytes = 3; in nand_set_ecc_soft_ops()
5222 ecc->strength = 1; in nand_set_ecc_soft_ops()
5225 ecc->options |= NAND_ECC_SOFT_HAMMING_SM_ORDER; in nand_set_ecc_soft_ops()
5233 ecc->calculate = nand_bch_calculate_ecc; in nand_set_ecc_soft_ops()
5234 ecc->correct = nand_bch_correct_data; in nand_set_ecc_soft_ops()
5235 ecc->read_page = nand_read_page_swecc; in nand_set_ecc_soft_ops()
5236 ecc->read_subpage = nand_read_subpage; in nand_set_ecc_soft_ops()
5237 ecc->write_page = nand_write_page_swecc; in nand_set_ecc_soft_ops()
5238 if (!ecc->read_page_raw) in nand_set_ecc_soft_ops()
5239 ecc->read_page_raw = nand_read_page_raw; in nand_set_ecc_soft_ops()
5240 if (!ecc->write_page_raw) in nand_set_ecc_soft_ops()
5241 ecc->write_page_raw = nand_write_page_raw; in nand_set_ecc_soft_ops()
5242 ecc->read_oob = nand_read_oob_std; in nand_set_ecc_soft_ops()
5243 ecc->write_oob = nand_write_oob_std; in nand_set_ecc_soft_ops()
5246 * Board driver should supply ecc.size and ecc.strength in nand_set_ecc_soft_ops()
5250 if (!ecc->size && (mtd->oobsize >= 64)) { in nand_set_ecc_soft_ops()
5251 ecc->size = 512; in nand_set_ecc_soft_ops()
5252 ecc->strength = 4; in nand_set_ecc_soft_ops()
5256 * if no ecc placement scheme was provided pickup the default in nand_set_ecc_soft_ops()
5271 * We can only maximize ECC config when the default layout is in nand_set_ecc_soft_ops()
5276 nanddev->ecc.user_conf.flags & NAND_ECC_MAXIMIZE_STRENGTH) { in nand_set_ecc_soft_ops()
5280 ecc->size = 1024; in nand_set_ecc_soft_ops()
5281 steps = mtd->writesize / ecc->size; in nand_set_ecc_soft_ops()
5285 ecc->strength = bytes * 8 / fls(8 * ecc->size); in nand_set_ecc_soft_ops()
5289 ecc->bytes = 0; in nand_set_ecc_soft_ops()
5290 ecc->priv = nand_bch_init(mtd); in nand_set_ecc_soft_ops()
5291 if (!ecc->priv) { in nand_set_ecc_soft_ops()
5292 WARN(1, "BCH ECC initialization failed!\n"); in nand_set_ecc_soft_ops()
5297 WARN(1, "Unsupported ECC algorithm!\n"); in nand_set_ecc_soft_ops()
5303 * nand_check_ecc_caps - check the sanity of preset ECC settings
5305 * @caps: ECC caps info structure
5306 * @oobavail: OOB size that the ECC engine can use
5308 * When ECC step size and strength are already set, check if they are supported
5309 * by the controller and the calculated ECC bytes fit within the chip's OOB.
5310 * On success, the calculated ECC bytes is set.
5318 int preset_step = chip->ecc.size; in nand_check_ecc_caps()
5319 int preset_strength = chip->ecc.strength; in nand_check_ecc_caps()
5339 pr_err("ECC (step, strength) = (%d, %d) does not fit in OOB", in nand_check_ecc_caps()
5344 chip->ecc.bytes = ecc_bytes; in nand_check_ecc_caps()
5350 pr_err("ECC (step, strength) = (%d, %d) not supported on this controller", in nand_check_ecc_caps()
5357 * nand_match_ecc_req - meet the chip's requirement with least ECC bytes
5359 * @caps: ECC engine caps info structure
5360 * @oobavail: OOB size that the ECC engine can use
5362 * If a chip's ECC requirement is provided, try to meet it with the least
5363 * number of ECC bytes (i.e. with the largest number of OOB-free bytes).
5364 * On success, the chosen ECC settings are set.
5419 * with the least number of ECC bytes. in nand_match_ecc_req()
5433 chip->ecc.size = best_step; in nand_match_ecc_req()
5434 chip->ecc.strength = best_strength; in nand_match_ecc_req()
5435 chip->ecc.bytes = best_ecc_bytes; in nand_match_ecc_req()
5441 * nand_maximize_ecc - choose the max ECC strength available
5443 * @caps: ECC engine caps info structure
5444 * @oobavail: OOB size that the ECC engine can use
5446 * Choose the max ECC strength that is supported on the controller, and can fit
5447 * within the chip's OOB. On success, the chosen ECC settings are set.
5465 /* If chip->ecc.size is already set, respect it */ in nand_maximize_ecc()
5466 if (chip->ecc.size && step_size != chip->ecc.size) in nand_maximize_ecc()
5503 chip->ecc.size = best_step; in nand_maximize_ecc()
5504 chip->ecc.strength = best_strength; in nand_maximize_ecc()
5505 chip->ecc.bytes = best_ecc_bytes; in nand_maximize_ecc()
5511 * nand_ecc_choose_conf - Set the ECC strength and ECC step size
5513 * @caps: ECC engine caps info structure
5514 * @oobavail: OOB size that the ECC engine can use
5516 * Choose the ECC configuration according to following logic.
5518 * 1. If both ECC step size and ECC strength are already set (usually by DT)
5520 * 2. If the user provided the nand-ecc-maximize property, then select maximum
5521 * ECC strength.
5522 * 3. Otherwise, try to match the ECC step size and ECC strength closest
5524 * requirement then fallback to the maximum ECC step size and ECC strength.
5526 * On success, the chosen ECC settings are set.
5537 if (chip->ecc.size && chip->ecc.strength) in nand_ecc_choose_conf()
5540 if (nanddev->ecc.user_conf.flags & NAND_ECC_MAXIMIZE_STRENGTH) in nand_ecc_choose_conf()
5605 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_scan_tail() local
5637 !(ecc->engine_type == NAND_ECC_ENGINE_TYPE_SOFT && in nand_scan_tail()
5638 ecc->algo == NAND_ECC_ALGO_BCH)) { in nand_scan_tail()
5654 * page with ECC layout when ->oobsize <= 128 for in nand_scan_tail()
5657 if (ecc->engine_type == NAND_ECC_ENGINE_TYPE_NONE) { in nand_scan_tail()
5671 * Check ECC mode, default to software if 3byte/512byte hardware ECC is in nand_scan_tail()
5672 * selected and we have 256 byte pagesize fallback to software ECC in nand_scan_tail()
5675 switch (ecc->engine_type) { in nand_scan_tail()
5681 if (mtd->writesize >= ecc->size) { in nand_scan_tail()
5682 if (!ecc->strength) { in nand_scan_tail()
5683 WARN(1, "Driver must set ecc.strength when using hardware ECC\n"); in nand_scan_tail()
5689 pr_warn("%d byte HW ECC not possible on %d byte page size, fallback to SW ECC\n", in nand_scan_tail()
5690 ecc->size, mtd->writesize); in nand_scan_tail()
5691 ecc->engine_type = NAND_ECC_ENGINE_TYPE_SOFT; in nand_scan_tail()
5692 ecc->algo = NAND_ECC_ALGO_HAMMING; in nand_scan_tail()
5702 if (!ecc->read_page || !ecc->write_page) { in nand_scan_tail()
5703 WARN(1, "No ECC functions supplied; on-die ECC not possible\n"); in nand_scan_tail()
5707 if (!ecc->read_oob) in nand_scan_tail()
5708 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
5709 if (!ecc->write_oob) in nand_scan_tail()
5710 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
5715 ecc->read_page = nand_read_page_raw; in nand_scan_tail()
5716 ecc->write_page = nand_write_page_raw; in nand_scan_tail()
5717 ecc->read_oob = nand_read_oob_std; in nand_scan_tail()
5718 ecc->read_page_raw = nand_read_page_raw; in nand_scan_tail()
5719 ecc->write_page_raw = nand_write_page_raw; in nand_scan_tail()
5720 ecc->write_oob = nand_write_oob_std; in nand_scan_tail()
5721 ecc->size = mtd->writesize; in nand_scan_tail()
5722 ecc->bytes = 0; in nand_scan_tail()
5723 ecc->strength = 0; in nand_scan_tail()
5727 WARN(1, "Invalid NAND_ECC_MODE %d\n", ecc->engine_type); in nand_scan_tail()
5732 if (ecc->correct || ecc->calculate) { in nand_scan_tail()
5733 ecc->calc_buf = kmalloc(mtd->oobsize, GFP_KERNEL); in nand_scan_tail()
5734 ecc->code_buf = kmalloc(mtd->oobsize, GFP_KERNEL); in nand_scan_tail()
5735 if (!ecc->calc_buf || !ecc->code_buf) { in nand_scan_tail()
5742 if (!ecc->read_oob_raw) in nand_scan_tail()
5743 ecc->read_oob_raw = ecc->read_oob; in nand_scan_tail()
5744 if (!ecc->write_oob_raw) in nand_scan_tail()
5745 ecc->write_oob_raw = ecc->write_oob; in nand_scan_tail()
5747 /* propagate ecc info to mtd_info */ in nand_scan_tail()
5748 mtd->ecc_strength = ecc->strength; in nand_scan_tail()
5749 mtd->ecc_step_size = ecc->size; in nand_scan_tail()
5752 * Set the number of read / write steps for one page depending on ECC in nand_scan_tail()
5755 ecc->steps = mtd->writesize / ecc->size; in nand_scan_tail()
5756 if (ecc->steps * ecc->size != mtd->writesize) { in nand_scan_tail()
5757 WARN(1, "Invalid ECC parameters\n"); in nand_scan_tail()
5762 ecc->total = ecc->steps * ecc->bytes; in nand_scan_tail()
5763 chip->base.ecc.ctx.total = ecc->total; in nand_scan_tail()
5765 if (ecc->total > mtd->oobsize) { in nand_scan_tail()
5766 WARN(1, "Total number of ECC bytes exceeded oobsize\n"); in nand_scan_tail()
5781 /* ECC sanity check: warn if it's too weak */ in nand_scan_tail()
5783 …pr_warn("WARNING: %s: the ECC used on your system (%db/%dB) is too weak compared to the one requir… in nand_scan_tail()
5784 mtd->name, chip->ecc.strength, chip->ecc.size, in nand_scan_tail()
5788 /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */ in nand_scan_tail()
5790 switch (ecc->steps) { in nand_scan_tail()
5807 switch (ecc->engine_type) { in nand_scan_tail()
5885 kfree(ecc->code_buf); in nand_scan_tail()
5886 kfree(ecc->calc_buf); in nand_scan_tail()
5952 if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT && in nand_cleanup()
5953 chip->ecc.algo == NAND_ECC_ALGO_BCH) in nand_cleanup()
5954 nand_bch_free((struct nand_bch_control *)chip->ecc.priv); in nand_cleanup()
5961 kfree(chip->ecc.code_buf); in nand_cleanup()
5962 kfree(chip->ecc.calc_buf); in nand_cleanup()