Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Functions
bch.h File Reference
#include <linux/types.h>

Go to the source code of this file.

Data Structures

struct  bch_control
 

Functions

struct bch_controlinit_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)
 

Function Documentation

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.

Definition at line 986 of file bch.c.

void encode_bch ( struct bch_control bch,
const uint8_t data,
unsigned int  len,
uint8_t ecc 
)

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.

Definition at line 184 of file bch.c.

void free_bch ( struct bch_control bch)

free_bch - free the BCH control structure : BCH control structure to release

Definition at line 1343 of file bch.c.

struct bch_control* init_bch ( int  m,
int  t,
unsigned int  prim_poly 
)
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.

Definition at line 1249 of file bch.c.