2 * Generic binary BCH encoding/decoding library
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.
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
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.
17 * Copyright © 2011 Parrot S.A.
19 * Author: Ivan Djelic <ivan.djelic@parrot.com>
23 * This library provides runtime configurable encoding/decoding of binary
24 * Bose-Chaudhuri-Hocquenghem (BCH) codes.
29 #include <linux/types.h>
32 * struct bch_control - BCH control structure
33 * @m: Galois field order
34 * @n: maximum codeword size in bits (= 2^m-1)
35 * @t: error correction capability in bits
36 * @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree (<=m*t)
37 * @ecc_bytes: ecc max size (m*t bits) in bytes
38 * @a_pow_tab: Galois field GF(2^m) exponentiation lookup table
39 * @a_log_tab: Galois field GF(2^m) log lookup table
40 * @mod8_tab: remainder generator polynomial lookup tables
41 * @ecc_buf: ecc parity words buffer
42 * @ecc_buf2: ecc parity words buffer
43 * @xi_tab: GF(2^m) base for solving degree 2 polynomial roots
44 * @syn: syndrome buffer
45 * @cache: log-based polynomial representation buffer
46 * @elp: error locator polynomial
47 * @poly_2t: temporary polynomials of degree 2t
53 unsigned int ecc_bits;
54 unsigned int ecc_bytes;
65 struct gf_poly *poly_2t[4];
68 struct bch_control *init_bch(int m, int t, unsigned int prim_poly);
70 void free_bch(struct bch_control *bch);
72 void encode_bch(struct bch_control *bch, const uint8_t *data,
73 unsigned int len, uint8_t *ecc);
75 int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
76 const uint8_t *recv_ecc, const uint8_t *calc_ecc,
77 const unsigned int *syn, unsigned int *errloc);