1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
4 *
5 * This file is the header for the NAND BCH ECC implementation.
6 */
7
8#ifndef __MTD_NAND_ECC_SW_BCH_H__
9#define __MTD_NAND_ECC_SW_BCH_H__
10
11#include <linux/mtd/nand.h>
12#include <linux/bch.h>
13
14/**
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
17 * engine needs
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
24 */
25struct nand_ecc_sw_bch_conf {
26 struct nand_ecc_req_tweak_ctx req_ctx;
27 unsigned int code_size;
28 u8 *calc_buf;
29 u8 *code_buf;
30 struct bch_control *bch;
31 unsigned int *errloc;
32 unsigned char *eccmask;
33};
34
35#if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)
36
37int nand_ecc_sw_bch_calculate(struct nand_device *nand,
38 const unsigned char *buf, unsigned char *code);
39int nand_ecc_sw_bch_correct(struct nand_device *nand, unsigned char *buf,
40 unsigned char *read_ecc, unsigned char *calc_ecc);
41int nand_ecc_sw_bch_init_ctx(struct nand_device *nand);
42void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand);
43struct nand_ecc_engine *nand_ecc_sw_bch_get_engine(void);
44
45#else /* !CONFIG_MTD_NAND_ECC_SW_BCH */
46
47static inline int nand_ecc_sw_bch_calculate(struct nand_device *nand,
48 const unsigned char *buf,
49 unsigned char *code)
50{
51 return -ENOTSUPP;
52}
53
54static inline int nand_ecc_sw_bch_correct(struct nand_device *nand,
55 unsigned char *buf,
56 unsigned char *read_ecc,
57 unsigned char *calc_ecc)
58{
59 return -ENOTSUPP;
60}
61
62static inline int nand_ecc_sw_bch_init_ctx(struct nand_device *nand)
63{
64 return -ENOTSUPP;
65}
66
67static inline void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand) {}
68
69#endif /* CONFIG_MTD_NAND_ECC_SW_BCH */
70
71#endif /* __MTD_NAND_ECC_SW_BCH_H__ */
72

source code of linux/include/linux/mtd/nand-ecc-sw-bch.h