Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
0004  *
0005  * This file is the header for the NAND BCH ECC implementation.
0006  */
0007 
0008 #ifndef __MTD_NAND_ECC_SW_BCH_H__
0009 #define __MTD_NAND_ECC_SW_BCH_H__
0010 
0011 #include <linux/mtd/nand.h>
0012 #include <linux/bch.h>
0013 
0014 /**
0015  * struct nand_ecc_sw_bch_conf - private software BCH ECC engine structure
0016  * @req_ctx: Save request context and tweak the original request to fit the
0017  *           engine needs
0018  * @code_size: Number of bytes needed to store a code (one code per step)
0019  * @calc_buf: Buffer to use when calculating ECC bytes
0020  * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
0021  * @bch: BCH control structure
0022  * @errloc: error location array
0023  * @eccmask: XOR ecc mask, allows erased pages to be decoded as valid
0024  */
0025 struct nand_ecc_sw_bch_conf {
0026     struct nand_ecc_req_tweak_ctx req_ctx;
0027     unsigned int code_size;
0028     u8 *calc_buf;
0029     u8 *code_buf;
0030     struct bch_control *bch;
0031     unsigned int *errloc;
0032     unsigned char *eccmask;
0033 };
0034 
0035 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)
0036 
0037 int nand_ecc_sw_bch_calculate(struct nand_device *nand,
0038                   const unsigned char *buf, unsigned char *code);
0039 int nand_ecc_sw_bch_correct(struct nand_device *nand, unsigned char *buf,
0040                 unsigned char *read_ecc, unsigned char *calc_ecc);
0041 int nand_ecc_sw_bch_init_ctx(struct nand_device *nand);
0042 void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand);
0043 struct nand_ecc_engine *nand_ecc_sw_bch_get_engine(void);
0044 
0045 #else /* !CONFIG_MTD_NAND_ECC_SW_BCH */
0046 
0047 static inline int nand_ecc_sw_bch_calculate(struct nand_device *nand,
0048                         const unsigned char *buf,
0049                         unsigned char *code)
0050 {
0051     return -ENOTSUPP;
0052 }
0053 
0054 static inline int nand_ecc_sw_bch_correct(struct nand_device *nand,
0055                       unsigned char *buf,
0056                       unsigned char *read_ecc,
0057                       unsigned char *calc_ecc)
0058 {
0059     return -ENOTSUPP;
0060 }
0061 
0062 static inline int nand_ecc_sw_bch_init_ctx(struct nand_device *nand)
0063 {
0064     return -ENOTSUPP;
0065 }
0066 
0067 static inline void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand) {}
0068 
0069 #endif /* CONFIG_MTD_NAND_ECC_SW_BCH */
0070 
0071 #endif /* __MTD_NAND_ECC_SW_BCH_H__ */