1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2000-2010 Steven J. Hill <sjhill@realitydiluted.com>
4 * David Woodhouse <dwmw2@infradead.org>
5 * Thomas Gleixner <tglx@linutronix.de>
7 * This file is the header for the NAND Hamming ECC implementation.
10 #ifndef __MTD_NAND_ECC_SW_HAMMING_H__
11 #define __MTD_NAND_ECC_SW_HAMMING_H__
13 #include <linux/mtd/nand.h>
16 * struct nand_ecc_sw_hamming_conf - private software Hamming ECC engine structure
17 * @req_ctx: Save request context and tweak the original request to fit the
19 * @code_size: Number of bytes needed to store a code (one code per step)
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 * @sm_order: Smart Media special ordering
24 struct nand_ecc_sw_hamming_conf {
25 struct nand_ecc_req_tweak_ctx req_ctx;
26 unsigned int code_size;
29 unsigned int sm_order;
32 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING)
34 int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand);
35 void nand_ecc_sw_hamming_cleanup_ctx(struct nand_device *nand);
36 int ecc_sw_hamming_calculate(const unsigned char *buf, unsigned int step_size,
37 unsigned char *code, bool sm_order);
38 int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
39 const unsigned char *buf,
41 int ecc_sw_hamming_correct(unsigned char *buf, unsigned char *read_ecc,
42 unsigned char *calc_ecc, unsigned int step_size,
44 int nand_ecc_sw_hamming_correct(struct nand_device *nand, unsigned char *buf,
45 unsigned char *read_ecc,
46 unsigned char *calc_ecc);
48 #else /* !CONFIG_MTD_NAND_ECC_SW_HAMMING */
50 static inline int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand)
55 static inline void nand_ecc_sw_hamming_cleanup_ctx(struct nand_device *nand) {}
57 static inline int ecc_sw_hamming_calculate(const unsigned char *buf,
58 unsigned int step_size,
59 unsigned char *code, bool sm_order)
64 static inline int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
65 const unsigned char *buf,
71 static inline int ecc_sw_hamming_correct(unsigned char *buf,
72 unsigned char *read_ecc,
73 unsigned char *calc_ecc,
74 unsigned int step_size, bool sm_order)
79 static inline int nand_ecc_sw_hamming_correct(struct nand_device *nand,
81 unsigned char *read_ecc,
82 unsigned char *calc_ecc)
87 #endif /* CONFIG_MTD_NAND_ECC_SW_HAMMING */
89 #endif /* __MTD_NAND_ECC_SW_HAMMING_H__ */