Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bch.h
Go to the documentation of this file.
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 <[email protected]>
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 
29 #include <linux/types.h>
30 
49 struct bch_control {
50  unsigned int m;
51  unsigned int n;
52  unsigned int t;
53  unsigned int ecc_bits;
54  unsigned int ecc_bytes;
55 /* private: */
61  unsigned int *xi_tab;
62  unsigned int *syn;
63  int *cache;
64  struct gf_poly *elp;
65  struct gf_poly *poly_2t[4];
66 };
67 
68 struct bch_control *init_bch(int m, int t, unsigned int prim_poly);
69 
70 void free_bch(struct bch_control *bch);
71 
72 void encode_bch(struct bch_control *bch, const uint8_t *data,
73  unsigned int len, uint8_t *ecc);
74 
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);
78 
79 #endif /* _BCH_H */