Lines Matching refs:ecc

38 #include <linux/mtd/nand-ecc-sw-hamming.h>
39 #include <linux/mtd/nand-ecc-sw-bch.h>
262 res = chip->ecc.read_oob(chip, first_page + page_offset);
479 status = chip->ecc.write_oob_raw(chip, page & chip->pagemask);
481 status = chip->ecc.write_oob(chip, page & chip->pagemask);
2838 * @ecc: ECC buffer
2873 void *ecc, int ecclen,
2886 ecc_bitflips = nand_check_erased_buf(ecc, ecclen, bitflips_threshold);
2901 memset(ecc, 0xff, ecclen);
2926 * nand_read_page_raw - [INTERN] read raw page data without ecc
2997 * nand_read_page_raw_syndrome - [INTERN] read raw page data without ecc
3009 int eccsize = chip->ecc.size;
3010 int eccbytes = chip->ecc.bytes;
3018 for (steps = chip->ecc.steps; steps > 0; steps--) {
3025 if (chip->ecc.prepad) {
3026 ret = nand_read_data_op(chip, oob, chip->ecc.prepad,
3031 oob += chip->ecc.prepad;
3040 if (chip->ecc.postpad) {
3041 ret = nand_read_data_op(chip, oob, chip->ecc.postpad,
3046 oob += chip->ecc.postpad;
3071 int i, eccsize = chip->ecc.size, ret;
3072 int eccbytes = chip->ecc.bytes;
3073 int eccsteps = chip->ecc.steps;
3075 uint8_t *ecc_calc = chip->ecc.calc_buf;
3076 uint8_t *ecc_code = chip->ecc.code_buf;
3079 chip->ecc.read_page_raw(chip, buf, 1, page);
3082 chip->ecc.calculate(chip, p, &ecc_calc[i]);
3085 chip->ecc.total);
3089 eccsteps = chip->ecc.steps;
3095 stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]);
3128 start_step = data_offs / chip->ecc.size;
3129 end_step = (data_offs + readlen - 1) / chip->ecc.size;
3131 index = start_step * chip->ecc.bytes;
3133 /* Data size aligned to ECC ecc.size */
3134 datafrag_len = num_steps * chip->ecc.size;
3135 eccfrag_len = num_steps * chip->ecc.bytes;
3137 data_col_addr = start_step * chip->ecc.size;
3145 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size)
3146 chip->ecc.calculate(chip, p, &chip->ecc.calc_buf[i]);
3150 * ecc.pos. Let's make sure that there are no gaps in ECC positions.
3174 if ((oobregion.offset + (num_steps * chip->ecc.bytes)) &
3186 ret = mtd_ooblayout_get_eccbytes(mtd, chip->ecc.code_buf,
3192 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) {
3195 stat = chip->ecc.correct(chip, p, &chip->ecc.code_buf[i],
3196 &chip->ecc.calc_buf[i]);
3198 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) {
3200 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size,
3201 &chip->ecc.code_buf[i],
3202 chip->ecc.bytes,
3204 chip->ecc.strength);
3230 int i, eccsize = chip->ecc.size, ret;
3231 int eccbytes = chip->ecc.bytes;
3232 int eccsteps = chip->ecc.steps;
3234 uint8_t *ecc_calc = chip->ecc.calc_buf;
3235 uint8_t *ecc_code = chip->ecc.code_buf;
3243 chip->ecc.hwctl(chip, NAND_ECC_READ);
3249 chip->ecc.calculate(chip, p, &ecc_calc[i]);
3258 chip->ecc.total);
3262 eccsteps = chip->ecc.steps;
3268 stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]);
3270 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) {
3275 chip->ecc.strength);
3303 int i, eccsize = chip->ecc.size, ret;
3304 int eccbytes = chip->ecc.bytes;
3305 int eccsteps = chip->ecc.steps;
3307 uint8_t *ecc_code = chip->ecc.code_buf;
3321 chip->ecc.total);
3328 chip->ecc.hwctl(chip, NAND_ECC_READ);
3334 stat = chip->ecc.correct(chip, p, &ecc_code[i], NULL);
3336 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) {
3341 chip->ecc.strength);
3369 int ret, i, eccsize = chip->ecc.size;
3370 int eccbytes = chip->ecc.bytes;
3371 int eccsteps = chip->ecc.steps;
3372 int eccpadbytes = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
3384 chip->ecc.hwctl(chip, NAND_ECC_READ);
3390 if (chip->ecc.prepad) {
3391 ret = nand_read_data_op(chip, oob, chip->ecc.prepad,
3396 oob += chip->ecc.prepad;
3399 chip->ecc.hwctl(chip, NAND_ECC_READSYN);
3405 stat = chip->ecc.correct(chip, p, oob, NULL);
3409 if (chip->ecc.postpad) {
3410 ret = nand_read_data_op(chip, oob, chip->ecc.postpad,
3415 oob += chip->ecc.postpad;
3419 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) {
3421 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size,
3425 chip->ecc.strength);
3626 * the read methods return max bitflips per ecc step.
3629 ret = chip->ecc.read_page_raw(chip, bufpoi,
3634 ret = chip->ecc.read_subpage(chip, col, bytes,
3637 ret = chip->ecc.read_page(chip, bufpoi,
3770 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
3771 int eccsize = chip->ecc.size;
3775 ret = nand_read_page_op(chip, page, chip->ecc.size, NULL, 0);
3779 for (i = 0; i < chip->ecc.steps; i++) {
3837 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
3838 int eccsize = chip->ecc.size, length = mtd->oobsize;
3839 int ret, i, len, pos, sndcmd = 0, steps = chip->ecc.steps;
3843 * data-ecc-data-ecc ... ecc-oob
3845 * data-pad-ecc-pad-data-pad .... ecc-pad-oob
3847 if (!chip->ecc.prepad && !chip->ecc.postpad) {
3941 ret = chip->ecc.read_oob_raw(chip, page);
3943 ret = chip->ecc.read_oob(chip, page);
4120 int eccsize = chip->ecc.size;
4121 int eccbytes = chip->ecc.bytes;
4129 for (steps = chip->ecc.steps; steps > 0; steps--) {
4136 if (chip->ecc.prepad) {
4137 ret = nand_write_data_op(chip, oob, chip->ecc.prepad,
4142 oob += chip->ecc.prepad;
4151 if (chip->ecc.postpad) {
4152 ret = nand_write_data_op(chip, oob, chip->ecc.postpad,
4157 oob += chip->ecc.postpad;
4181 int i, eccsize = chip->ecc.size, ret;
4182 int eccbytes = chip->ecc.bytes;
4183 int eccsteps = chip->ecc.steps;
4184 uint8_t *ecc_calc = chip->ecc.calc_buf;
4189 chip->ecc.calculate(chip, p, &ecc_calc[i]);
4192 chip->ecc.total);
4196 return chip->ecc.write_page_raw(chip, buf, 1, page);
4210 int i, eccsize = chip->ecc.size, ret;
4211 int eccbytes = chip->ecc.bytes;
4212 int eccsteps = chip->ecc.steps;
4213 uint8_t *ecc_calc = chip->ecc.calc_buf;
4221 chip->ecc.hwctl(chip, NAND_ECC_WRITE);
4227 chip->ecc.calculate(chip, p, &ecc_calc[i]);
4231 chip->ecc.total);
4258 uint8_t *ecc_calc = chip->ecc.calc_buf;
4259 int ecc_size = chip->ecc.size;
4260 int ecc_bytes = chip->ecc.bytes;
4261 int ecc_steps = chip->ecc.steps;
4273 chip->ecc.hwctl(chip, NAND_ECC_WRITE);
4284 chip->ecc.calculate(chip, buf, ecc_calc);
4298 ecc_calc = chip->ecc.calc_buf;
4300 chip->ecc.total);
4327 int i, eccsize = chip->ecc.size;
4328 int eccbytes = chip->ecc.bytes;
4329 int eccsteps = chip->ecc.steps;
4339 chip->ecc.hwctl(chip, NAND_ECC_WRITE);
4345 if (chip->ecc.prepad) {
4346 ret = nand_write_data_op(chip, oob, chip->ecc.prepad,
4351 oob += chip->ecc.prepad;
4354 chip->ecc.calculate(chip, p, oob);
4362 if (chip->ecc.postpad) {
4363 ret = nand_write_data_op(chip, oob, chip->ecc.postpad,
4368 oob += chip->ecc.postpad;
4401 chip->ecc.write_subpage)
4407 status = chip->ecc.write_page_raw(chip, buf, oob_required,
4410 status = chip->ecc.write_subpage(chip, offset, data_len, buf,
4413 status = chip->ecc.write_page(chip, buf, oob_required, page);
5213 if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_DIE)
5223 if (!(chip->ecc.read_page == nand_read_page_hwecc ||
5224 chip->ecc.read_page == nand_read_page_syndrome ||
5225 chip->ecc.read_page == nand_read_page_swecc))
5447 err = of_property_read_string(np, "nand-ecc-mode", &pm);
5480 err = of_property_read_string(np, "nand-ecc-mode", &pm);
5494 err = of_property_read_string(np, "nand-ecc-mode", &pm);
5508 struct nand_ecc_props *user_conf = &chip->base.ecc.user_conf;
5634 nand->ecc.defaults.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
5641 if (nand->ecc.user_conf.engine_type != NAND_ECC_ENGINE_TYPE_INVALID)
5642 chip->ecc.engine_type = nand->ecc.user_conf.engine_type;
5643 if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_INVALID)
5644 chip->ecc.engine_type = nand->ecc.defaults.engine_type;
5646 chip->ecc.placement = nand->ecc.user_conf.placement;
5647 chip->ecc.algo = nand->ecc.user_conf.algo;
5648 chip->ecc.strength = nand->ecc.user_conf.strength;
5649 chip->ecc.size = nand->ecc.user_conf.step_size;
5761 base->ecc.user_conf.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
5762 base->ecc.user_conf.algo = NAND_ECC_ALGO_HAMMING;
5763 base->ecc.user_conf.strength = chip->ecc.strength;
5764 base->ecc.user_conf.step_size = chip->ecc.size;
5770 engine_conf = base->ecc.ctx.priv;
5772 if (chip->ecc.options & NAND_ECC_SOFT_HAMMING_SM_ORDER)
5775 chip->ecc.size = base->ecc.ctx.conf.step_size;
5776 chip->ecc.strength = base->ecc.ctx.conf.strength;
5777 chip->ecc.total = base->ecc.ctx.total;
5778 chip->ecc.steps = nanddev_get_ecc_nsteps(base);
5779 chip->ecc.bytes = base->ecc.ctx.total / nanddev_get_ecc_nsteps(base);
5820 base->ecc.user_conf.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
5821 base->ecc.user_conf.algo = NAND_ECC_ALGO_BCH;
5822 base->ecc.user_conf.step_size = chip->ecc.size;
5823 base->ecc.user_conf.strength = chip->ecc.strength;
5829 chip->ecc.size = ecc_conf->step_size;
5830 chip->ecc.strength = ecc_conf->strength;
5831 chip->ecc.total = base->ecc.ctx.total;
5832 chip->ecc.steps = nanddev_get_ecc_nsteps(base);
5833 chip->ecc.bytes = base->ecc.ctx.total / nanddev_get_ecc_nsteps(base);
5867 struct nand_ecc_ctrl *ecc = &chip->ecc;
5869 switch (ecc->placement) {
5873 if (!ecc->read_page)
5874 ecc->read_page = nand_read_page_hwecc;
5875 if (!ecc->write_page)
5876 ecc->write_page = nand_write_page_hwecc;
5877 if (!ecc->read_page_raw)
5878 ecc->read_page_raw = nand_read_page_raw;
5879 if (!ecc->write_page_raw)
5880 ecc->write_page_raw = nand_write_page_raw;
5881 if (!ecc->read_oob)
5882 ecc->read_oob = nand_read_oob_std;
5883 if (!ecc->write_oob)
5884 ecc->write_oob = nand_write_oob_std;
5885 if (!ecc->read_subpage)
5886 ecc->read_subpage = nand_read_subpage;
5887 if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
5888 ecc->write_subpage = nand_write_subpage_hwecc;
5892 if ((!ecc->calculate || !ecc->correct || !ecc->hwctl) &&
5893 (!ecc->read_page ||
5894 ecc->read_page == nand_read_page_hwecc ||
5895 !ecc->write_page ||
5896 ecc->write_page == nand_write_page_hwecc)) {
5901 if (!ecc->read_page)
5902 ecc->read_page = nand_read_page_syndrome;
5903 if (!ecc->write_page)
5904 ecc->write_page = nand_write_page_syndrome;
5905 if (!ecc->read_page_raw)
5906 ecc->read_page_raw = nand_read_page_raw_syndrome;
5907 if (!ecc->write_page_raw)
5908 ecc->write_page_raw = nand_write_page_raw_syndrome;
5909 if (!ecc->read_oob)
5910 ecc->read_oob = nand_read_oob_syndrome;
5911 if (!ecc->write_oob)
5912 ecc->write_oob = nand_write_oob_syndrome;
5917 ecc->placement);
5928 struct nand_ecc_ctrl *ecc = &chip->ecc;
5931 if (WARN_ON(ecc->engine_type != NAND_ECC_ENGINE_TYPE_SOFT))
5934 switch (ecc->algo) {
5936 ecc->calculate = rawnand_sw_hamming_calculate;
5937 ecc->correct = rawnand_sw_hamming_correct;
5938 ecc->read_page = nand_read_page_swecc;
5939 ecc->read_subpage = nand_read_subpage;
5940 ecc->write_page = nand_write_page_swecc;
5941 if (!ecc->read_page_raw)
5942 ecc->read_page_raw = nand_read_page_raw;
5943 if (!ecc->write_page_raw)
5944 ecc->write_page_raw = nand_write_page_raw;
5945 ecc->read_oob = nand_read_oob_std;
5946 ecc->write_oob = nand_write_oob_std;
5947 if (!ecc->size)
5948 ecc->size = 256;
5949 ecc->bytes = 3;
5950 ecc->strength = 1;
5953 ecc->options |= NAND_ECC_SOFT_HAMMING_SM_ORDER;
5967 ecc->calculate = rawnand_sw_bch_calculate;
5968 ecc->correct = rawnand_sw_bch_correct;
5969 ecc->read_page = nand_read_page_swecc;
5970 ecc->read_subpage = nand_read_subpage;
5971 ecc->write_page = nand_write_page_swecc;
5972 if (!ecc->read_page_raw)
5973 ecc->read_page_raw = nand_read_page_raw;
5974 if (!ecc->write_page_raw)
5975 ecc->write_page_raw = nand_write_page_raw;
5976 ecc->read_oob = nand_read_oob_std;
5977 ecc->write_oob = nand_write_oob_std;
5984 if (nanddev->ecc.user_conf.flags & NAND_ECC_MAXIMIZE_STRENGTH &&
5986 nanddev->ecc.user_conf.flags &= ~NAND_ECC_MAXIMIZE_STRENGTH;
6017 int preset_step = chip->ecc.size;
6018 int preset_strength = chip->ecc.strength;
6043 chip->ecc.bytes = ecc_bytes;
6132 chip->ecc.size = best_step;
6133 chip->ecc.strength = best_strength;
6134 chip->ecc.bytes = best_ecc_bytes;
6164 /* If chip->ecc.size is already set, respect it */
6165 if (chip->ecc.size && step_size != chip->ecc.size)
6202 chip->ecc.size = best_step;
6203 chip->ecc.strength = best_strength;
6204 chip->ecc.bytes = best_ecc_bytes;
6219 * 2. If the user provided the nand-ecc-maximize property, then select maximum
6236 if (chip->ecc.size && chip->ecc.strength)
6239 if (nanddev->ecc.user_conf.flags & NAND_ECC_MAXIMIZE_STRENGTH)
6304 struct nand_ecc_ctrl *ecc = &chip->ecc;
6336 !(ecc->engine_type == NAND_ECC_ENGINE_TYPE_SOFT &&
6337 ecc->algo == NAND_ECC_ALGO_BCH) &&
6338 !(ecc->engine_type == NAND_ECC_ENGINE_TYPE_SOFT &&
6339 ecc->algo == NAND_ECC_ALGO_HAMMING)) {
6358 if (ecc->engine_type == NAND_ECC_ENGINE_TYPE_NONE) {
6376 switch (ecc->engine_type) {
6382 if (mtd->writesize >= ecc->size) {
6383 if (!ecc->strength) {
6384 WARN(1, "Driver must set ecc.strength when using hardware ECC\n");
6391 ecc->size, mtd->writesize);
6392 ecc->engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
6393 ecc->algo = NAND_ECC_ALGO_HAMMING;
6403 if (!ecc->read_page || !ecc->write_page) {
6408 if (!ecc->read_oob)
6409 ecc->read_oob = nand_read_oob_std;
6410 if (!ecc->write_oob)
6411 ecc->write_oob = nand_write_oob_std;
6416 ecc->read_page = nand_read_page_raw;
6417 ecc->write_page = nand_write_page_raw;
6418 ecc->read_oob = nand_read_oob_std;
6419 ecc->read_page_raw = nand_read_page_raw;
6420 ecc->write_page_raw = nand_write_page_raw;
6421 ecc->write_oob = nand_write_oob_std;
6422 ecc->size = mtd->writesize;
6423 ecc->bytes = 0;
6424 ecc->strength = 0;
6428 WARN(1, "Invalid NAND_ECC_MODE %d\n", ecc->engine_type);
6433 if (ecc->correct || ecc->calculate) {
6434 ecc->calc_buf = kmalloc(mtd->oobsize, GFP_KERNEL);
6435 ecc->code_buf = kmalloc(mtd->oobsize, GFP_KERNEL);
6436 if (!ecc->calc_buf || !ecc->code_buf) {
6443 if (!ecc->read_oob_raw)
6444 ecc->read_oob_raw = ecc->read_oob;
6445 if (!ecc->write_oob_raw)
6446 ecc->write_oob_raw = ecc->write_oob;
6448 /* propagate ecc info to mtd_info */
6449 mtd->ecc_strength = ecc->strength;
6450 mtd->ecc_step_size = ecc->size;
6456 if (!ecc->steps)
6457 ecc->steps = mtd->writesize / ecc->size;
6458 if (ecc->steps * ecc->size != mtd->writesize) {
6464 if (!ecc->total) {
6465 ecc->total = ecc->steps * ecc->bytes;
6466 chip->base.ecc.ctx.total = ecc->total;
6469 if (ecc->total > mtd->oobsize) {
6488 mtd->name, chip->ecc.strength, chip->ecc.size,
6492 /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
6494 switch (ecc->steps) {
6511 switch (ecc->engine_type) {
6604 kfree(ecc->code_buf);
6605 kfree(ecc->calc_buf);
6671 if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT) {
6672 if (chip->ecc.algo == NAND_ECC_ALGO_HAMMING)
6674 else if (chip->ecc.algo == NAND_ECC_ALGO_BCH)
6686 kfree(chip->ecc.code_buf);
6687 kfree(chip->ecc.calc_buf);