Lines Matching +full:256 +full:- +full:byte
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * errors in a 256 byte block of data.
14 * can be found in Documentation/driver-api/mtd/nand_ecc.rst
21 #include <linux/mtd/nand-ecc-sw-hamming.h>
26 * invparity is a 256 byte table that contains the odd parity
27 * for each byte. So if the number of bits in a byte is even,
31 static const char invparity[256] = {
51 * bitsperbyte contains the number of bits per byte
55 static const char bitsperbyte[256] = {
75 * addressbits is a lookup table to filter out the bits from the xor-ed
80 static const char addressbits[256] = {
119 const u32 eccsize_mult = (step_size == 256) ? 1 : 2; in ecc_sw_hamming_calculate()
122 /* rp0..rp17 are the various accumulated parities (per byte) */ in ecc_sw_hamming_calculate()
220 * we'll bring rp4..rp14..rp16 back to single byte entities by in ecc_sw_hamming_calculate()
357 * nand_ecc_sw_hamming_calculate - Calculate 3-byte ECC for 256/512-byte block
365 struct nand_ecc_sw_hamming_conf *engine_conf = nand->ecc.ctx.priv; in nand_ecc_sw_hamming_calculate()
366 unsigned int step_size = nand->ecc.ctx.conf.step_size; in nand_ecc_sw_hamming_calculate()
367 bool sm_order = engine_conf ? engine_conf->sm_order : false; in nand_ecc_sw_hamming_calculate()
410 * rp17/rp15/13/11/9/7/5/3/1 indicate which byte is the faulty in ecc_sw_hamming_correct()
411 * byte, cp 5/3/1 indicate the faulty bit. in ecc_sw_hamming_correct()
413 * the bits from the byte they are in. in ecc_sw_hamming_correct()
441 return -EBADMSG; in ecc_sw_hamming_correct()
446 * nand_ecc_sw_hamming_correct - Detect and correct bit error(s)
452 * Detect and correct up to 1 bit error per 256/512-byte block.
458 struct nand_ecc_sw_hamming_conf *engine_conf = nand->ecc.ctx.priv; in nand_ecc_sw_hamming_correct()
459 unsigned int step_size = nand->ecc.ctx.conf.step_size; in nand_ecc_sw_hamming_correct()
460 bool sm_order = engine_conf ? engine_conf->sm_order : false; in nand_ecc_sw_hamming_correct()
469 struct nand_ecc_props *conf = &nand->ecc.ctx.conf; in nand_ecc_sw_hamming_init_ctx()
474 if (!mtd->ooblayout) { in nand_ecc_sw_hamming_init_ctx()
475 switch (mtd->oobsize) { in nand_ecc_sw_hamming_init_ctx()
486 return -ENOTSUPP; in nand_ecc_sw_hamming_init_ctx()
490 conf->engine_type = NAND_ECC_ENGINE_TYPE_SOFT; in nand_ecc_sw_hamming_init_ctx()
491 conf->algo = NAND_ECC_ALGO_HAMMING; in nand_ecc_sw_hamming_init_ctx()
492 conf->step_size = nand->ecc.user_conf.step_size; in nand_ecc_sw_hamming_init_ctx()
493 conf->strength = 1; in nand_ecc_sw_hamming_init_ctx()
496 if (conf->step_size != 256 && conf->step_size != 512) in nand_ecc_sw_hamming_init_ctx()
497 conf->step_size = 256; in nand_ecc_sw_hamming_init_ctx()
501 return -ENOMEM; in nand_ecc_sw_hamming_init_ctx()
503 ret = nand_ecc_init_req_tweaking(&engine_conf->req_ctx, nand); in nand_ecc_sw_hamming_init_ctx()
507 engine_conf->code_size = 3; in nand_ecc_sw_hamming_init_ctx()
508 engine_conf->calc_buf = kzalloc(mtd->oobsize, GFP_KERNEL); in nand_ecc_sw_hamming_init_ctx()
509 engine_conf->code_buf = kzalloc(mtd->oobsize, GFP_KERNEL); in nand_ecc_sw_hamming_init_ctx()
510 if (!engine_conf->calc_buf || !engine_conf->code_buf) { in nand_ecc_sw_hamming_init_ctx()
511 ret = -ENOMEM; in nand_ecc_sw_hamming_init_ctx()
515 nand->ecc.ctx.priv = engine_conf; in nand_ecc_sw_hamming_init_ctx()
516 nand->ecc.ctx.nsteps = mtd->writesize / conf->step_size; in nand_ecc_sw_hamming_init_ctx()
517 nand->ecc.ctx.total = nand->ecc.ctx.nsteps * engine_conf->code_size; in nand_ecc_sw_hamming_init_ctx()
522 nand_ecc_cleanup_req_tweaking(&engine_conf->req_ctx); in nand_ecc_sw_hamming_init_ctx()
523 kfree(engine_conf->calc_buf); in nand_ecc_sw_hamming_init_ctx()
524 kfree(engine_conf->code_buf); in nand_ecc_sw_hamming_init_ctx()
534 struct nand_ecc_sw_hamming_conf *engine_conf = nand->ecc.ctx.priv; in nand_ecc_sw_hamming_cleanup_ctx()
537 nand_ecc_cleanup_req_tweaking(&engine_conf->req_ctx); in nand_ecc_sw_hamming_cleanup_ctx()
538 kfree(engine_conf->calc_buf); in nand_ecc_sw_hamming_cleanup_ctx()
539 kfree(engine_conf->code_buf); in nand_ecc_sw_hamming_cleanup_ctx()
548 struct nand_ecc_sw_hamming_conf *engine_conf = nand->ecc.ctx.priv; in nand_ecc_sw_hamming_prepare_io_req()
550 int eccsize = nand->ecc.ctx.conf.step_size; in nand_ecc_sw_hamming_prepare_io_req()
551 int eccbytes = engine_conf->code_size; in nand_ecc_sw_hamming_prepare_io_req()
552 int eccsteps = nand->ecc.ctx.nsteps; in nand_ecc_sw_hamming_prepare_io_req()
553 int total = nand->ecc.ctx.total; in nand_ecc_sw_hamming_prepare_io_req()
554 u8 *ecccalc = engine_conf->calc_buf; in nand_ecc_sw_hamming_prepare_io_req()
559 if (req->mode == MTD_OPS_RAW) in nand_ecc_sw_hamming_prepare_io_req()
563 if (!req->datalen) in nand_ecc_sw_hamming_prepare_io_req()
566 nand_ecc_tweak_req(&engine_conf->req_ctx, req); in nand_ecc_sw_hamming_prepare_io_req()
569 if (req->type == NAND_PAGE_READ) in nand_ecc_sw_hamming_prepare_io_req()
573 for (i = 0, data = req->databuf.out; in nand_ecc_sw_hamming_prepare_io_req()
575 eccsteps--, i += eccbytes, data += eccsize) in nand_ecc_sw_hamming_prepare_io_req()
578 return mtd_ooblayout_set_eccbytes(mtd, ecccalc, (void *)req->oobbuf.out, in nand_ecc_sw_hamming_prepare_io_req()
585 struct nand_ecc_sw_hamming_conf *engine_conf = nand->ecc.ctx.priv; in nand_ecc_sw_hamming_finish_io_req()
587 int eccsize = nand->ecc.ctx.conf.step_size; in nand_ecc_sw_hamming_finish_io_req()
588 int total = nand->ecc.ctx.total; in nand_ecc_sw_hamming_finish_io_req()
589 int eccbytes = engine_conf->code_size; in nand_ecc_sw_hamming_finish_io_req()
590 int eccsteps = nand->ecc.ctx.nsteps; in nand_ecc_sw_hamming_finish_io_req()
591 u8 *ecccalc = engine_conf->calc_buf; in nand_ecc_sw_hamming_finish_io_req()
592 u8 *ecccode = engine_conf->code_buf; in nand_ecc_sw_hamming_finish_io_req()
594 u8 *data = req->databuf.in; in nand_ecc_sw_hamming_finish_io_req()
598 if (req->mode == MTD_OPS_RAW) in nand_ecc_sw_hamming_finish_io_req()
602 if (!req->datalen) in nand_ecc_sw_hamming_finish_io_req()
606 if (req->type == NAND_PAGE_WRITE) { in nand_ecc_sw_hamming_finish_io_req()
607 nand_ecc_restore_req(&engine_conf->req_ctx, req); in nand_ecc_sw_hamming_finish_io_req()
612 ret = mtd_ooblayout_get_eccbytes(mtd, ecccode, req->oobbuf.in, 0, in nand_ecc_sw_hamming_finish_io_req()
618 for (i = 0; eccsteps; eccsteps--, i += eccbytes, data += eccsize) in nand_ecc_sw_hamming_finish_io_req()
622 for (eccsteps = nand->ecc.ctx.nsteps, i = 0, data = req->databuf.in; in nand_ecc_sw_hamming_finish_io_req()
624 eccsteps--, i += eccbytes, data += eccsize) { in nand_ecc_sw_hamming_finish_io_req()
629 mtd->ecc_stats.failed++; in nand_ecc_sw_hamming_finish_io_req()
631 mtd->ecc_stats.corrected += stat; in nand_ecc_sw_hamming_finish_io_req()
636 nand_ecc_restore_req(&engine_conf->req_ctx, req); in nand_ecc_sw_hamming_finish_io_req()