Christian Hitz | 4c6de85 | 2011-10-12 09:31:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Generic binary BCH encoding/decoding library |
| 3 | * |
Tom Rini | 5b8031c | 2016-01-14 22:05:13 -0500 | [diff] [blame^] | 4 | * SPDX-License-Identifier: GPL-2.0 |
Christian Hitz | 4c6de85 | 2011-10-12 09:31:59 +0200 | [diff] [blame] | 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 | |
| 18 | #include <linux/types.h> |
| 19 | |
| 20 | /** |
| 21 | * struct bch_control - BCH control structure |
| 22 | * @m: Galois field order |
| 23 | * @n: maximum codeword size in bits (= 2^m-1) |
| 24 | * @t: error correction capability in bits |
| 25 | * @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree (<=m*t) |
| 26 | * @ecc_bytes: ecc max size (m*t bits) in bytes |
| 27 | * @a_pow_tab: Galois field GF(2^m) exponentiation lookup table |
| 28 | * @a_log_tab: Galois field GF(2^m) log lookup table |
| 29 | * @mod8_tab: remainder generator polynomial lookup tables |
| 30 | * @ecc_buf: ecc parity words buffer |
| 31 | * @ecc_buf2: ecc parity words buffer |
| 32 | * @xi_tab: GF(2^m) base for solving degree 2 polynomial roots |
| 33 | * @syn: syndrome buffer |
| 34 | * @cache: log-based polynomial representation buffer |
| 35 | * @elp: error locator polynomial |
| 36 | * @poly_2t: temporary polynomials of degree 2t |
| 37 | */ |
| 38 | struct bch_control { |
| 39 | unsigned int m; |
| 40 | unsigned int n; |
| 41 | unsigned int t; |
| 42 | unsigned int ecc_bits; |
| 43 | unsigned int ecc_bytes; |
| 44 | /* private: */ |
| 45 | uint16_t *a_pow_tab; |
| 46 | uint16_t *a_log_tab; |
| 47 | uint32_t *mod8_tab; |
| 48 | uint32_t *ecc_buf; |
| 49 | uint32_t *ecc_buf2; |
| 50 | unsigned int *xi_tab; |
| 51 | unsigned int *syn; |
| 52 | int *cache; |
| 53 | struct gf_poly *elp; |
| 54 | struct gf_poly *poly_2t[4]; |
| 55 | }; |
| 56 | |
| 57 | struct bch_control *init_bch(int m, int t, unsigned int prim_poly); |
| 58 | |
| 59 | void free_bch(struct bch_control *bch); |
| 60 | |
| 61 | void encode_bch(struct bch_control *bch, const uint8_t *data, |
| 62 | unsigned int len, uint8_t *ecc); |
| 63 | |
| 64 | int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len, |
| 65 | const uint8_t *recv_ecc, const uint8_t *calc_ecc, |
| 66 | const unsigned int *syn, unsigned int *errloc); |
| 67 | |
| 68 | #endif /* _BCH_H */ |