xref: /linux/include/linux/mtd/nand-ecc-sw-bch.h (revision 3e66843c)
1cdbe8df5SMiquel Raynal /* SPDX-License-Identifier: GPL-2.0-only */
2cdbe8df5SMiquel Raynal /*
3cdbe8df5SMiquel Raynal  * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
4cdbe8df5SMiquel Raynal  *
5cdbe8df5SMiquel Raynal  * This file is the header for the NAND BCH ECC implementation.
6cdbe8df5SMiquel Raynal  */
7cdbe8df5SMiquel Raynal 
8cdbe8df5SMiquel Raynal #ifndef __MTD_NAND_ECC_SW_BCH_H__
9cdbe8df5SMiquel Raynal #define __MTD_NAND_ECC_SW_BCH_H__
10cdbe8df5SMiquel Raynal 
11ea146d7fSMiquel Raynal #include <linux/mtd/nand.h>
1280fe6031SMiquel Raynal #include <linux/bch.h>
1380fe6031SMiquel Raynal 
1480fe6031SMiquel Raynal /**
1580fe6031SMiquel Raynal  * struct nand_ecc_sw_bch_conf - private software BCH ECC engine structure
16*9994bb3fSMiquel Raynal  * @req_ctx: Save request context and tweak the original request to fit the
17*9994bb3fSMiquel Raynal  *           engine needs
1880fe6031SMiquel Raynal  * @code_size: Number of bytes needed to store a code (one code per step)
1980fe6031SMiquel Raynal  * @calc_buf: Buffer to use when calculating ECC bytes
2080fe6031SMiquel Raynal  * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
2180fe6031SMiquel Raynal  * @bch: BCH control structure
2280fe6031SMiquel Raynal  * @errloc: error location array
2380fe6031SMiquel Raynal  * @eccmask: XOR ecc mask, allows erased pages to be decoded as valid
2480fe6031SMiquel Raynal  */
2580fe6031SMiquel Raynal struct nand_ecc_sw_bch_conf {
26*9994bb3fSMiquel Raynal 	struct nand_ecc_req_tweak_ctx req_ctx;
2780fe6031SMiquel Raynal 	unsigned int code_size;
2880fe6031SMiquel Raynal 	u8 *calc_buf;
2980fe6031SMiquel Raynal 	u8 *code_buf;
3080fe6031SMiquel Raynal 	struct bch_control *bch;
3180fe6031SMiquel Raynal 	unsigned int *errloc;
3280fe6031SMiquel Raynal 	unsigned char *eccmask;
3380fe6031SMiquel Raynal };
34cdbe8df5SMiquel Raynal 
35cdbe8df5SMiquel Raynal #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)
36cdbe8df5SMiquel Raynal 
37ea146d7fSMiquel Raynal int nand_ecc_sw_bch_calculate(struct nand_device *nand,
38ea146d7fSMiquel Raynal 			      const unsigned char *buf, unsigned char *code);
39ea146d7fSMiquel Raynal int nand_ecc_sw_bch_correct(struct nand_device *nand, unsigned char *buf,
40ea146d7fSMiquel Raynal 			    unsigned char *read_ecc, unsigned char *calc_ecc);
41*9994bb3fSMiquel Raynal int nand_ecc_sw_bch_init_ctx(struct nand_device *nand);
42*9994bb3fSMiquel Raynal void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand);
43*9994bb3fSMiquel Raynal struct nand_ecc_engine *nand_ecc_sw_bch_get_engine(void);
44cdbe8df5SMiquel Raynal 
45cdbe8df5SMiquel Raynal #else /* !CONFIG_MTD_NAND_ECC_SW_BCH */
46cdbe8df5SMiquel Raynal 
nand_ecc_sw_bch_calculate(struct nand_device * nand,const unsigned char * buf,unsigned char * code)47ea146d7fSMiquel Raynal static inline int nand_ecc_sw_bch_calculate(struct nand_device *nand,
48ea146d7fSMiquel Raynal 					    const unsigned char *buf,
49ea146d7fSMiquel Raynal 					    unsigned char *code)
50cdbe8df5SMiquel Raynal {
51e3010bd3SMiquel Raynal 	return -ENOTSUPP;
52cdbe8df5SMiquel Raynal }
53cdbe8df5SMiquel Raynal 
nand_ecc_sw_bch_correct(struct nand_device * nand,unsigned char * buf,unsigned char * read_ecc,unsigned char * calc_ecc)54ea146d7fSMiquel Raynal static inline int nand_ecc_sw_bch_correct(struct nand_device *nand,
55ea146d7fSMiquel Raynal 					  unsigned char *buf,
56ea146d7fSMiquel Raynal 					  unsigned char *read_ecc,
57ea146d7fSMiquel Raynal 					  unsigned char *calc_ecc)
58cdbe8df5SMiquel Raynal {
59cdbe8df5SMiquel Raynal 	return -ENOTSUPP;
60cdbe8df5SMiquel Raynal }
61cdbe8df5SMiquel Raynal 
nand_ecc_sw_bch_init_ctx(struct nand_device * nand)62*9994bb3fSMiquel Raynal static inline int nand_ecc_sw_bch_init_ctx(struct nand_device *nand)
63cdbe8df5SMiquel Raynal {
643c0fe36aSMiquel Raynal 	return -ENOTSUPP;
65cdbe8df5SMiquel Raynal }
66cdbe8df5SMiquel Raynal 
nand_ecc_sw_bch_cleanup_ctx(struct nand_device * nand)67*9994bb3fSMiquel Raynal static inline void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand) {}
68cdbe8df5SMiquel Raynal 
69cdbe8df5SMiquel Raynal #endif /* CONFIG_MTD_NAND_ECC_SW_BCH */
70cdbe8df5SMiquel Raynal 
71cdbe8df5SMiquel Raynal #endif /* __MTD_NAND_ECC_SW_BCH_H__ */
72