bch.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Generic binary BCH encoding/decoding library
  4. *
  5. * Copyright © 2011 Parrot S.A.
  6. *
  7. * Author: Ivan Djelic <ivan.djelic@parrot.com>
  8. *
  9. * Description:
  10. *
  11. * This library provides runtime configurable encoding/decoding of binary
  12. * Bose-Chaudhuri-Hocquenghem (BCH) codes.
  13. */
  14. #ifndef _BCH_H
  15. #define _BCH_H
  16. #include <linux/types.h>
  17. /**
  18. * struct bch_control - BCH control structure
  19. * @m: Galois field order
  20. * @n: maximum codeword size in bits (= 2^m-1)
  21. * @t: error correction capability in bits
  22. * @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree (<=m*t)
  23. * @ecc_bytes: ecc max size (m*t bits) in bytes
  24. * @a_pow_tab: Galois field GF(2^m) exponentiation lookup table
  25. * @a_log_tab: Galois field GF(2^m) log lookup table
  26. * @mod8_tab: remainder generator polynomial lookup tables
  27. * @ecc_buf: ecc parity words buffer
  28. * @ecc_buf2: ecc parity words buffer
  29. * @xi_tab: GF(2^m) base for solving degree 2 polynomial roots
  30. * @syn: syndrome buffer
  31. * @cache: log-based polynomial representation buffer
  32. * @elp: error locator polynomial
  33. * @poly_2t: temporary polynomials of degree 2t
  34. */
  35. struct bch_control {
  36. unsigned int m;
  37. unsigned int n;
  38. unsigned int t;
  39. unsigned int ecc_bits;
  40. unsigned int ecc_bytes;
  41. /* private: */
  42. uint16_t *a_pow_tab;
  43. uint16_t *a_log_tab;
  44. uint32_t *mod8_tab;
  45. uint32_t *ecc_buf;
  46. uint32_t *ecc_buf2;
  47. unsigned int *xi_tab;
  48. unsigned int *syn;
  49. int *cache;
  50. struct gf_poly *elp;
  51. struct gf_poly *poly_2t[4];
  52. };
  53. struct bch_control *init_bch(int m, int t, unsigned int prim_poly);
  54. void free_bch(struct bch_control *bch);
  55. void encode_bch(struct bch_control *bch, const uint8_t *data,
  56. unsigned int len, uint8_t *ecc);
  57. int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
  58. const uint8_t *recv_ecc, const uint8_t *calc_ecc,
  59. const unsigned int *syn, unsigned int *errloc);
  60. #endif /* _BCH_H */