1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
5 * This file is the header for the NAND BCH ECC implementation.
8 #ifndef __MTD_NAND_ECC_SW_BCH_H__
9 #define __MTD_NAND_ECC_SW_BCH_H__
11 #include <linux/mtd/nand.h>
12 #include <linux/bch.h>
15 * struct nand_ecc_sw_bch_conf - private software BCH ECC engine structure
16 * @req_ctx: Save request context and tweak the original request to fit the
18 * @code_size: Number of bytes needed to store a code (one code per step)
19 * @nsteps: Number of steps
20 * @calc_buf: Buffer to use when calculating ECC bytes
21 * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
22 * @bch: BCH control structure
23 * @errloc: error location array
24 * @eccmask: XOR ecc mask, allows erased pages to be decoded as valid
26 struct nand_ecc_sw_bch_conf {
27 struct nand_ecc_req_tweak_ctx req_ctx;
28 unsigned int code_size;
32 struct bch_control *bch;
34 unsigned char *eccmask;
37 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)
39 int nand_ecc_sw_bch_calculate(struct nand_device *nand,
40 const unsigned char *buf, unsigned char *code);
41 int nand_ecc_sw_bch_correct(struct nand_device *nand, unsigned char *buf,
42 unsigned char *read_ecc, unsigned char *calc_ecc);
43 int nand_ecc_sw_bch_init_ctx(struct nand_device *nand);
44 void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand);
45 struct nand_ecc_engine *nand_ecc_sw_bch_get_engine(void);
47 #else /* !CONFIG_MTD_NAND_ECC_SW_BCH */
49 static inline int nand_ecc_sw_bch_calculate(struct nand_device *nand,
50 const unsigned char *buf,
56 static inline int nand_ecc_sw_bch_correct(struct nand_device *nand,
58 unsigned char *read_ecc,
59 unsigned char *calc_ecc)
64 static inline int nand_ecc_sw_bch_init_ctx(struct nand_device *nand)
69 static inline void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand) {}
71 #endif /* CONFIG_MTD_NAND_ECC_SW_BCH */
73 #endif /* __MTD_NAND_ECC_SW_BCH_H__ */