nand-ecc-sw-bch.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright © 2011 Ivan Djelic <[email protected]>
  4. *
  5. * This file is the header for the NAND BCH ECC implementation.
  6. */
  7. #ifndef __MTD_NAND_ECC_SW_BCH_H__
  8. #define __MTD_NAND_ECC_SW_BCH_H__
  9. #include <linux/mtd/nand.h>
  10. #include <linux/bch.h>
  11. /**
  12. * struct nand_ecc_sw_bch_conf - private software BCH ECC engine structure
  13. * @req_ctx: Save request context and tweak the original request to fit the
  14. * engine needs
  15. * @code_size: Number of bytes needed to store a code (one code per step)
  16. * @calc_buf: Buffer to use when calculating ECC bytes
  17. * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
  18. * @bch: BCH control structure
  19. * @errloc: error location array
  20. * @eccmask: XOR ecc mask, allows erased pages to be decoded as valid
  21. */
  22. struct nand_ecc_sw_bch_conf {
  23. struct nand_ecc_req_tweak_ctx req_ctx;
  24. unsigned int code_size;
  25. u8 *calc_buf;
  26. u8 *code_buf;
  27. struct bch_control *bch;
  28. unsigned int *errloc;
  29. unsigned char *eccmask;
  30. };
  31. #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)
  32. int nand_ecc_sw_bch_calculate(struct nand_device *nand,
  33. const unsigned char *buf, unsigned char *code);
  34. int nand_ecc_sw_bch_correct(struct nand_device *nand, unsigned char *buf,
  35. unsigned char *read_ecc, unsigned char *calc_ecc);
  36. int nand_ecc_sw_bch_init_ctx(struct nand_device *nand);
  37. void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand);
  38. struct nand_ecc_engine *nand_ecc_sw_bch_get_engine(void);
  39. #else /* !CONFIG_MTD_NAND_ECC_SW_BCH */
  40. static inline int nand_ecc_sw_bch_calculate(struct nand_device *nand,
  41. const unsigned char *buf,
  42. unsigned char *code)
  43. {
  44. return -ENOTSUPP;
  45. }
  46. static inline int nand_ecc_sw_bch_correct(struct nand_device *nand,
  47. unsigned char *buf,
  48. unsigned char *read_ecc,
  49. unsigned char *calc_ecc)
  50. {
  51. return -ENOTSUPP;
  52. }
  53. static inline int nand_ecc_sw_bch_init_ctx(struct nand_device *nand)
  54. {
  55. return -ENOTSUPP;
  56. }
  57. static inline void nand_ecc_sw_bch_cleanup_ctx(struct nand_device *nand) {}
  58. #endif /* CONFIG_MTD_NAND_ECC_SW_BCH */
  59. #endif /* __MTD_NAND_ECC_SW_BCH_H__ */