// SPDX-License-Identifier: GPL-2.0-or-later /* * This file provides ECC correction for more than 1 bit per block of data, * using binary BCH codes. It relies on the generic BCH library lib/bch.c. * * Copyright © 2011 Ivan Djelic <[email protected]> */ #include <linux/types.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/bitops.h> #include <linux/mtd/nand.h> #include <linux/mtd/nand-ecc-sw-bch.h> /** * nand_ecc_sw_bch_calculate - Calculate the ECC corresponding to a data block * @nand: NAND device * @buf: Input buffer with raw data * @code: Output buffer with ECC */ int nand_ecc_sw_bch_calculate(struct nand_device *nand, const unsigned char *buf, unsigned char *code) { … } EXPORT_SYMBOL(…); /** * nand_ecc_sw_bch_correct - Detect, correct and report bit error(s) * @nand: NAND device * @buf: Raw data read from the chip * @read_ecc: ECC bytes from the chip * @calc_ecc: ECC calculated from the raw data * * Detect and correct bit errors for a data block. */ int nand_ecc_sw_bch_correct(struct nand_device *nand, unsigned char *buf, unsigned char *read_ecc, unsigned char *calc_ecc) { … } EXPORT_SYMBOL(…); /** * nand_ecc_sw_bch_cleanup - Cleanup software BCH ECC resources * @nand: NAND device */ static void nand_ecc_sw_bch_cleanup(struct nand_device *nand) { … } /** * nand_ecc_sw_bch_init - Initialize software BCH ECC engine * @nand: NAND device * * Returns: a pointer to a new NAND BCH control structure, or NULL upon failure * * Initialize NAND BCH error correction. @nand.ecc parameters 'step_size' and * 'bytes' are used to compute the following BCH parameters: * m, the Galois field order * t, the error correction capability * 'bytes' should be equal to the number of bytes required to store m * t * bits, where m is such that 2^m - 1 > step_size * 8. * * Example: to configure 4 bit correction per 512 bytes, you should pass * step_size = 512 (thus, m = 13 is the smallest integer such that 2^m - 1 > 512 * 8) * bytes = 7 (7 bytes are required to store m * t = 13 * 4 = 52 bits) */ static int nand_ecc_sw_bch_init(struct nand_device *nand) { … } int nand_ecc_sw_bch_init_ctx(struct nand_device *nand) { … } EXPORT_SYMBOL(…); void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand) { … } EXPORT_SYMBOL(…); static int nand_ecc_sw_bch_prepare_io_req(struct nand_device *nand, struct nand_page_io_req *req) { … } static int nand_ecc_sw_bch_finish_io_req(struct nand_device *nand, struct nand_page_io_req *req) { … } static struct nand_ecc_engine_ops nand_ecc_sw_bch_engine_ops = …; static struct nand_ecc_engine nand_ecc_sw_bch_engine = …; struct nand_ecc_engine *nand_ecc_sw_bch_get_engine(void) { … } EXPORT_SYMBOL(…); MODULE_LICENSE(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …;