Linux Kernel
3.7.1
|
#include <linux/types.h>
Go to the source code of this file.
Data Structures | |
struct | bch_control |
Functions | |
struct bch_control * | init_bch (int m, int t, unsigned int prim_poly) |
void | free_bch (struct bch_control *bch) |
void | encode_bch (struct bch_control *bch, const uint8_t *data, unsigned int len, uint8_t *ecc) |
int | decode_bch (struct bch_control *bch, const uint8_t *data, unsigned int len, const uint8_t *recv_ecc, const uint8_t *calc_ecc, const unsigned int *syn, unsigned int *errloc) |
int decode_bch | ( | struct bch_control * | bch, |
const uint8_t * | data, | ||
unsigned int | len, | ||
const uint8_t * | recv_ecc, | ||
const uint8_t * | calc_ecc, | ||
const unsigned int * | syn, | ||
unsigned int * | errloc | ||
) |
decode_bch - decode received codeword and find bit error locations : BCH control structure : received data, ignored if is provided : data length in bytes, must always be provided : received ecc, if NULL then assume it was XORed in : calculated ecc, if NULL then calc_ecc is computed from : hw computed syndrome data (if NULL, syndrome is calculated) : output array of error locations
Returns: The number of errors found, or -EBADMSG if decoding failed, or -EINVAL if invalid parameters were provided
Depending on the available hw BCH support and the need to compute separately (using encode_bch()), this function should be called with one of the following parameter configurations -
by providing and only: decode_bch(, , , , NULL, NULL, )
by providing and : decode_bch(, NULL, , , , NULL, )
by providing ecc = recv_ecc XOR calc_ecc: decode_bch(, NULL, , NULL, ecc, NULL, )
by providing syndrome results : decode_bch(, NULL, , NULL, NULL, , )
Once decode_bch() has successfully returned with a positive value, error locations returned in array should be interpreted as follows -
if (errloc[n] >= 8*len), then n-th error is located in ecc (no need for data correction)
if (errloc[n] < 8*len), then n-th error is located in data and can be corrected with statement data[errloc[n]/8] ^= 1 << (errloc[n] % 8);
Note that this function does not perform any data correction by itself, it merely indicates error locations.
encode_bch - calculate BCH ecc parity of data : BCH control structure : data to encode : data length in bytes : ecc parity data, must be initialized by caller
The parity array is used both as input and output parameter, in order to allow incremental computations. It should be of the size indicated by member of , and should be initialized to 0 before the first call.
The exact number of computed ecc parity bits is given by member of ; it may be less than m*t for large values of t.
void free_bch | ( | struct bch_control * | bch | ) |
|
read |
init_bch - initialize a BCH encoder/decoder : Galois field order, should be in the range 5-15 : maximum error correction capability, in bits : user-provided primitive polynomial (or 0 to use default)
Returns: a newly allocated BCH control structure if successful, NULL otherwise
This initialization can take some time, as lookup tables are built for fast encoding/decoding; make sure not to call this function from a time critical path. Usually, init_bch() should be called on module/driver init and free_bch() should be called to release memory on exit.
You may provide your own primitive polynomial of degree in argument , or let init_bch() use its default polynomial.
Once init_bch() has successfully returned a pointer to a newly allocated BCH control structure, ecc length in bytes is given by member of the structure.