Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2000-2010 Steven J. Hill <sjhill@realitydiluted.com>
4 * David Woodhouse <dwmw2@infradead.org>
5 * Thomas Gleixner <tglx@linutronix.de>
6 *
7 * This file is the header for the NAND Hamming ECC implementation.
8 */
9
10#ifndef __MTD_NAND_ECC_SW_HAMMING_H__
11#define __MTD_NAND_ECC_SW_HAMMING_H__
12
13#include <linux/mtd/nand.h>
14
15/**
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
18 * engine needs
19 * @code_size: Number of bytes needed to store a code (one code per step)
20 * @nsteps: Number of steps
21 * @calc_buf: Buffer to use when calculating ECC bytes
22 * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
23 * @sm_order: Smart Media special ordering
24 */
25struct nand_ecc_sw_hamming_conf {
26 struct nand_ecc_req_tweak_ctx req_ctx;
27 unsigned int code_size;
28 unsigned int nsteps;
29 u8 *calc_buf;
30 u8 *code_buf;
31 unsigned int sm_order;
32};
33
34#if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING)
35
36int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand);
37void nand_ecc_sw_hamming_cleanup_ctx(struct nand_device *nand);
38int ecc_sw_hamming_calculate(const unsigned char *buf, unsigned int step_size,
39 unsigned char *code, bool sm_order);
40int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
41 const unsigned char *buf,
42 unsigned char *code);
43int ecc_sw_hamming_correct(unsigned char *buf, unsigned char *read_ecc,
44 unsigned char *calc_ecc, unsigned int step_size,
45 bool sm_order);
46int nand_ecc_sw_hamming_correct(struct nand_device *nand, unsigned char *buf,
47 unsigned char *read_ecc,
48 unsigned char *calc_ecc);
49
50#else /* !CONFIG_MTD_NAND_ECC_SW_HAMMING */
51
52static inline int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand)
53{
54 return -ENOTSUPP;
55}
56
57static inline void nand_ecc_sw_hamming_cleanup_ctx(struct nand_device *nand) {}
58
59static inline int ecc_sw_hamming_calculate(const unsigned char *buf,
60 unsigned int step_size,
61 unsigned char *code, bool sm_order)
62{
63 return -ENOTSUPP;
64}
65
66static inline int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
67 const unsigned char *buf,
68 unsigned char *code)
69{
70 return -ENOTSUPP;
71}
72
73static inline int ecc_sw_hamming_correct(unsigned char *buf,
74 unsigned char *read_ecc,
75 unsigned char *calc_ecc,
76 unsigned int step_size, bool sm_order)
77{
78 return -ENOTSUPP;
79}
80
81static inline int nand_ecc_sw_hamming_correct(struct nand_device *nand,
82 unsigned char *buf,
83 unsigned char *read_ecc,
84 unsigned char *calc_ecc)
85{
86 return -ENOTSUPP;
87}
88
89#endif /* CONFIG_MTD_NAND_ECC_SW_HAMMING */
90
91#endif /* __MTD_NAND_ECC_SW_HAMMING_H__ */