Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  Copyright (C) 2000-2010 Steven J. Hill <sjhill@realitydiluted.com>
0004  *              David Woodhouse <dwmw2@infradead.org>
0005  *              Thomas Gleixner <tglx@linutronix.de>
0006  *
0007  * This file is the header for the NAND Hamming ECC implementation.
0008  */
0009 
0010 #ifndef __MTD_NAND_ECC_SW_HAMMING_H__
0011 #define __MTD_NAND_ECC_SW_HAMMING_H__
0012 
0013 #include <linux/mtd/nand.h>
0014 
0015 /**
0016  * struct nand_ecc_sw_hamming_conf - private software Hamming ECC engine structure
0017  * @req_ctx: Save request context and tweak the original request to fit the
0018  *           engine needs
0019  * @code_size: Number of bytes needed to store a code (one code per step)
0020  * @calc_buf: Buffer to use when calculating ECC bytes
0021  * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
0022  * @sm_order: Smart Media special ordering
0023  */
0024 struct nand_ecc_sw_hamming_conf {
0025     struct nand_ecc_req_tweak_ctx req_ctx;
0026     unsigned int code_size;
0027     u8 *calc_buf;
0028     u8 *code_buf;
0029     unsigned int sm_order;
0030 };
0031 
0032 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING)
0033 
0034 int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand);
0035 void nand_ecc_sw_hamming_cleanup_ctx(struct nand_device *nand);
0036 int ecc_sw_hamming_calculate(const unsigned char *buf, unsigned int step_size,
0037                  unsigned char *code, bool sm_order);
0038 int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
0039                   const unsigned char *buf,
0040                   unsigned char *code);
0041 int ecc_sw_hamming_correct(unsigned char *buf, unsigned char *read_ecc,
0042                unsigned char *calc_ecc, unsigned int step_size,
0043                bool sm_order);
0044 int nand_ecc_sw_hamming_correct(struct nand_device *nand, unsigned char *buf,
0045                 unsigned char *read_ecc,
0046                 unsigned char *calc_ecc);
0047 
0048 #else /* !CONFIG_MTD_NAND_ECC_SW_HAMMING */
0049 
0050 static inline int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand)
0051 {
0052     return -ENOTSUPP;
0053 }
0054 
0055 static inline void nand_ecc_sw_hamming_cleanup_ctx(struct nand_device *nand) {}
0056 
0057 static inline int ecc_sw_hamming_calculate(const unsigned char *buf,
0058                        unsigned int step_size,
0059                        unsigned char *code, bool sm_order)
0060 {
0061     return -ENOTSUPP;
0062 }
0063 
0064 static inline int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
0065                         const unsigned char *buf,
0066                         unsigned char *code)
0067 {
0068     return -ENOTSUPP;
0069 }
0070 
0071 static inline int ecc_sw_hamming_correct(unsigned char *buf,
0072                      unsigned char *read_ecc,
0073                      unsigned char *calc_ecc,
0074                      unsigned int step_size, bool sm_order)
0075 {
0076     return -ENOTSUPP;
0077 }
0078 
0079 static inline int nand_ecc_sw_hamming_correct(struct nand_device *nand,
0080                           unsigned char *buf,
0081                           unsigned char *read_ecc,
0082                           unsigned char *calc_ecc)
0083 {
0084     return -ENOTSUPP;
0085 }
0086 
0087 #endif /* CONFIG_MTD_NAND_ECC_SW_HAMMING */
0088 
0089 #endif /* __MTD_NAND_ECC_SW_HAMMING_H__ */