nand-ecc-sw-hamming.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2000-2010 Steven J. Hill <[email protected]>
  4. * David Woodhouse <[email protected]>
  5. * Thomas Gleixner <[email protected]>
  6. *
  7. * This file is the header for the NAND Hamming ECC implementation.
  8. */
  9. #ifndef __MTD_NAND_ECC_SW_HAMMING_H__
  10. #define __MTD_NAND_ECC_SW_HAMMING_H__
  11. #include <linux/mtd/nand.h>
  12. /**
  13. * struct nand_ecc_sw_hamming_conf - private software Hamming ECC engine structure
  14. * @req_ctx: Save request context and tweak the original request to fit the
  15. * engine needs
  16. * @code_size: Number of bytes needed to store a code (one code per step)
  17. * @calc_buf: Buffer to use when calculating ECC bytes
  18. * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
  19. * @sm_order: Smart Media special ordering
  20. */
  21. struct nand_ecc_sw_hamming_conf {
  22. struct nand_ecc_req_tweak_ctx req_ctx;
  23. unsigned int code_size;
  24. u8 *calc_buf;
  25. u8 *code_buf;
  26. unsigned int sm_order;
  27. };
  28. #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING)
  29. int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand);
  30. void nand_ecc_sw_hamming_cleanup_ctx(struct nand_device *nand);
  31. int ecc_sw_hamming_calculate(const unsigned char *buf, unsigned int step_size,
  32. unsigned char *code, bool sm_order);
  33. int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
  34. const unsigned char *buf,
  35. unsigned char *code);
  36. int ecc_sw_hamming_correct(unsigned char *buf, unsigned char *read_ecc,
  37. unsigned char *calc_ecc, unsigned int step_size,
  38. bool sm_order);
  39. int nand_ecc_sw_hamming_correct(struct nand_device *nand, unsigned char *buf,
  40. unsigned char *read_ecc,
  41. unsigned char *calc_ecc);
  42. #else /* !CONFIG_MTD_NAND_ECC_SW_HAMMING */
  43. static inline int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand)
  44. {
  45. return -ENOTSUPP;
  46. }
  47. static inline void nand_ecc_sw_hamming_cleanup_ctx(struct nand_device *nand) {}
  48. static inline int ecc_sw_hamming_calculate(const unsigned char *buf,
  49. unsigned int step_size,
  50. unsigned char *code, bool sm_order)
  51. {
  52. return -ENOTSUPP;
  53. }
  54. static inline int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
  55. const unsigned char *buf,
  56. unsigned char *code)
  57. {
  58. return -ENOTSUPP;
  59. }
  60. static inline int ecc_sw_hamming_correct(unsigned char *buf,
  61. unsigned char *read_ecc,
  62. unsigned char *calc_ecc,
  63. unsigned int step_size, bool sm_order)
  64. {
  65. return -ENOTSUPP;
  66. }
  67. static inline int nand_ecc_sw_hamming_correct(struct nand_device *nand,
  68. unsigned char *buf,
  69. unsigned char *read_ecc,
  70. unsigned char *calc_ecc)
  71. {
  72. return -ENOTSUPP;
  73. }
  74. #endif /* CONFIG_MTD_NAND_ECC_SW_HAMMING */
  75. #endif /* __MTD_NAND_ECC_SW_HAMMING_H__ */