brintos

brintos / linux-shallow public Read only

0
0
Text · 2.1 KiB · 85fdce8 Raw
71 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/*3 * Generic binary BCH encoding/decoding library4 *5 * Copyright © 2011 Parrot S.A.6 *7 * Author: Ivan Djelic <ivan.djelic@parrot.com>8 *9 * Description:10 *11 * This library provides runtime configurable encoding/decoding of binary12 * Bose-Chaudhuri-Hocquenghem (BCH) codes.13*/14#ifndef _BCH_H15#define _BCH_H16 17#include <linux/types.h>18 19/**20 * struct bch_control - BCH control structure21 * @m:          Galois field order22 * @n:          maximum codeword size in bits (= 2^m-1)23 * @t:          error correction capability in bits24 * @ecc_bits:   ecc exact size in bits, i.e. generator polynomial degree (<=m*t)25 * @ecc_bytes:  ecc max size (m*t bits) in bytes26 * @a_pow_tab:  Galois field GF(2^m) exponentiation lookup table27 * @a_log_tab:  Galois field GF(2^m) log lookup table28 * @mod8_tab:   remainder generator polynomial lookup tables29 * @ecc_buf:    ecc parity words buffer30 * @ecc_buf2:   ecc parity words buffer31 * @xi_tab:     GF(2^m) base for solving degree 2 polynomial roots32 * @syn:        syndrome buffer33 * @cache:      log-based polynomial representation buffer34 * @elp:        error locator polynomial35 * @poly_2t:    temporary polynomials of degree 2t36 * @swap_bits:  swap bits within data and syndrome bytes37 */38struct 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	bool		swap_bits;56};57 58struct bch_control *bch_init(int m, int t, unsigned int prim_poly,59			     bool swap_bits);60 61void bch_free(struct bch_control *bch);62 63void bch_encode(struct bch_control *bch, const uint8_t *data,64		unsigned int len, uint8_t *ecc);65 66int bch_decode(struct bch_control *bch, const uint8_t *data, unsigned int len,67	       const uint8_t *recv_ecc, const uint8_t *calc_ecc,68	       const unsigned int *syn, unsigned int *errloc);69 70#endif /* _BCH_H */71