bch.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Generic binary BCH encoding/decoding library
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published by
  6. * the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc., 51
  15. * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * Copyright © 2011 Parrot S.A.
  18. *
  19. * Author: Ivan Djelic <ivan.djelic@parrot.com>
  20. *
  21. * Description:
  22. *
  23. * This library provides runtime configurable encoding/decoding of binary
  24. * Bose-Chaudhuri-Hocquenghem (BCH) codes.
  25. */
  26. #ifndef _BCH_H
  27. #define _BCH_H
  28. #include <linux/types.h>
  29. /**
  30. * struct bch_control - BCH control structure
  31. * @m: Galois field order
  32. * @n: maximum codeword size in bits (= 2^m-1)
  33. * @t: error correction capability in bits
  34. * @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree (<=m*t)
  35. * @ecc_bytes: ecc max size (m*t bits) in bytes
  36. * @a_pow_tab: Galois field GF(2^m) exponentiation lookup table
  37. * @a_log_tab: Galois field GF(2^m) log lookup table
  38. * @mod8_tab: remainder generator polynomial lookup tables
  39. * @ecc_buf: ecc parity words buffer
  40. * @ecc_buf2: ecc parity words buffer
  41. * @xi_tab: GF(2^m) base for solving degree 2 polynomial roots
  42. * @syn: syndrome buffer
  43. * @cache: log-based polynomial representation buffer
  44. * @elp: error locator polynomial
  45. * @poly_2t: temporary polynomials of degree 2t
  46. */
  47. struct bch_control {
  48. unsigned int m;
  49. unsigned int n;
  50. unsigned int t;
  51. unsigned int ecc_bits;
  52. unsigned int ecc_bytes;
  53. /* private: */
  54. uint16_t *a_pow_tab;
  55. uint16_t *a_log_tab;
  56. uint32_t *mod8_tab;
  57. uint32_t *ecc_buf;
  58. uint32_t *ecc_buf2;
  59. unsigned int *xi_tab;
  60. unsigned int *syn;
  61. int *cache;
  62. struct gf_poly *elp;
  63. struct gf_poly *poly_2t[4];
  64. };
  65. struct bch_control *init_bch(int m, int t, unsigned int prim_poly);
  66. void free_bch(struct bch_control *bch);
  67. void encode_bch(struct bch_control *bch, const uint8_t *data,
  68. unsigned int len, uint8_t *ecc);
  69. int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
  70. const uint8_t *recv_ecc, const uint8_t *calc_ecc,
  71. const unsigned int *syn, unsigned int *errloc);
  72. #endif /* _BCH_H */