1 /* SPDX-License-Identifier: GPL-2.0-only */ << 2 /* 1 /* 3 * Generic binary BCH encoding/decoding librar 2 * Generic binary BCH encoding/decoding library 4 * 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 * 5 * Copyright © 2011 Parrot S.A. 17 * Copyright © 2011 Parrot S.A. 6 * 18 * 7 * Author: Ivan Djelic <ivan.djelic@parrot.com 19 * Author: Ivan Djelic <ivan.djelic@parrot.com> 8 * 20 * 9 * Description: 21 * Description: 10 * 22 * 11 * This library provides runtime configurable 23 * This library provides runtime configurable encoding/decoding of binary 12 * Bose-Chaudhuri-Hocquenghem (BCH) codes. 24 * Bose-Chaudhuri-Hocquenghem (BCH) codes. 13 */ 25 */ 14 #ifndef _BCH_H 26 #ifndef _BCH_H 15 #define _BCH_H 27 #define _BCH_H 16 28 17 #include <linux/types.h> 29 #include <linux/types.h> 18 30 19 /** 31 /** 20 * struct bch_control - BCH control structure 32 * struct bch_control - BCH control structure 21 * @m: Galois field order 33 * @m: Galois field order 22 * @n: maximum codeword size in bits 34 * @n: maximum codeword size in bits (= 2^m-1) 23 * @t: error correction capability in 35 * @t: error correction capability in bits 24 * @ecc_bits: ecc exact size in bits, i.e. g 36 * @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree (<=m*t) 25 * @ecc_bytes: ecc max size (m*t bits) in byt 37 * @ecc_bytes: ecc max size (m*t bits) in bytes 26 * @a_pow_tab: Galois field GF(2^m) exponenti 38 * @a_pow_tab: Galois field GF(2^m) exponentiation lookup table 27 * @a_log_tab: Galois field GF(2^m) log looku 39 * @a_log_tab: Galois field GF(2^m) log lookup table 28 * @mod8_tab: remainder generator polynomial 40 * @mod8_tab: remainder generator polynomial lookup tables 29 * @ecc_buf: ecc parity words buffer 41 * @ecc_buf: ecc parity words buffer 30 * @ecc_buf2: ecc parity words buffer 42 * @ecc_buf2: ecc parity words buffer 31 * @xi_tab: GF(2^m) base for solving degre 43 * @xi_tab: GF(2^m) base for solving degree 2 polynomial roots 32 * @syn: syndrome buffer 44 * @syn: syndrome buffer 33 * @cache: log-based polynomial represent 45 * @cache: log-based polynomial representation buffer 34 * @elp: error locator polynomial 46 * @elp: error locator polynomial 35 * @poly_2t: temporary polynomials of degre 47 * @poly_2t: temporary polynomials of degree 2t 36 * @swap_bits: swap bits within data and synd << 37 */ 48 */ 38 struct bch_control { 49 struct bch_control { 39 unsigned int m; 50 unsigned int m; 40 unsigned int n; 51 unsigned int n; 41 unsigned int t; 52 unsigned int t; 42 unsigned int ecc_bits; 53 unsigned int ecc_bits; 43 unsigned int ecc_bytes; 54 unsigned int ecc_bytes; 44 /* private: */ 55 /* private: */ 45 uint16_t *a_pow_tab; 56 uint16_t *a_pow_tab; 46 uint16_t *a_log_tab; 57 uint16_t *a_log_tab; 47 uint32_t *mod8_tab; 58 uint32_t *mod8_tab; 48 uint32_t *ecc_buf; 59 uint32_t *ecc_buf; 49 uint32_t *ecc_buf2; 60 uint32_t *ecc_buf2; 50 unsigned int *xi_tab; 61 unsigned int *xi_tab; 51 unsigned int *syn; 62 unsigned int *syn; 52 int *cache; 63 int *cache; 53 struct gf_poly *elp; 64 struct gf_poly *elp; 54 struct gf_poly *poly_2t[4]; 65 struct gf_poly *poly_2t[4]; 55 bool swap_bits; << 56 }; 66 }; 57 67 58 struct bch_control *bch_init(int m, int t, uns !! 68 struct bch_control *init_bch(int m, int t, unsigned int prim_poly); 59 bool swap_bits); << 60 69 61 void bch_free(struct bch_control *bch); !! 70 void free_bch(struct bch_control *bch); 62 71 63 void bch_encode(struct bch_control *bch, const !! 72 void encode_bch(struct bch_control *bch, const uint8_t *data, 64 unsigned int len, uint8_t *ecc 73 unsigned int len, uint8_t *ecc); 65 74 66 int bch_decode(struct bch_control *bch, const !! 75 int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len, 67 const uint8_t *recv_ecc, const 76 const uint8_t *recv_ecc, const uint8_t *calc_ecc, 68 const unsigned int *syn, unsign 77 const unsigned int *syn, unsigned int *errloc); 69 78 70 #endif /* _BCH_H */ 79 #endif /* _BCH_H */ 71 80
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.