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 * @calc_buf: Buffer to use when calculating ECC bytes
20 * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
21 * @bch: BCH control structure
22 * @errloc: error location array
23 * @eccmask: XOR ecc mask, allows erased pages to be decoded as valid
25 struct nand_ecc_sw_bch_conf
{
26 struct nand_ecc_req_tweak_ctx req_ctx
;
27 unsigned int code_size
;
30 struct bch_control
*bch
;
32 unsigned char *eccmask
;
35 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)
37 int nand_ecc_sw_bch_calculate(struct nand_device
*nand
,
38 const unsigned char *buf
, unsigned char *code
);
39 int nand_ecc_sw_bch_correct(struct nand_device
*nand
, unsigned char *buf
,
40 unsigned char *read_ecc
, unsigned char *calc_ecc
);
41 int nand_ecc_sw_bch_init_ctx(struct nand_device
*nand
);
42 void nand_ecc_sw_bch_cleanup_ctx(struct nand_device
*nand
);
43 struct nand_ecc_engine
*nand_ecc_sw_bch_get_engine(void);
45 #else /* !CONFIG_MTD_NAND_ECC_SW_BCH */
47 static inline int nand_ecc_sw_bch_calculate(struct nand_device
*nand
,
48 const unsigned char *buf
,
54 static inline int nand_ecc_sw_bch_correct(struct nand_device
*nand
,
56 unsigned char *read_ecc
,
57 unsigned char *calc_ecc
)
62 static inline int nand_ecc_sw_bch_init_ctx(struct nand_device
*nand
)
67 static inline void nand_ecc_sw_bch_cleanup_ctx(struct nand_device
*nand
) {}
69 #endif /* CONFIG_MTD_NAND_ECC_SW_BCH */
71 #endif /* __MTD_NAND_ECC_SW_BCH_H__ */