bch.h 2.0 KB

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