forked from luck/tmp_suning_uos_patched
lib/bch: Rework a little bit the exported function names
There are four exported functions, all suffixed by _bch, which is clearly not the norm. Let's rename them by prefixing them with bch_ instead. This is a mechanical change: init_bch -> bch_init free_bch -> bch_free encode_bch -> bch_encode decode_bch -> bch_decode Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Link: https://lore.kernel.org/linux-mtd/20200519074549.23673-2-miquel.raynal@bootlin.com
This commit is contained in:
parent
f068980285
commit
c8ae3f744d
|
@ -647,7 +647,7 @@ static int doc_ecc_bch_fix_data(struct docg3 *docg3, void *buf, u8 *hwecc)
|
|||
|
||||
for (i = 0; i < DOC_ECC_BCH_SIZE; i++)
|
||||
ecc[i] = bitrev8(hwecc[i]);
|
||||
numerrs = decode_bch(docg3->cascade->bch, NULL,
|
||||
numerrs = bch_decode(docg3->cascade->bch, NULL,
|
||||
DOC_ECC_BCH_COVERED_BYTES,
|
||||
NULL, ecc, NULL, errorpos);
|
||||
BUG_ON(numerrs == -EINVAL);
|
||||
|
@ -1984,8 +1984,8 @@ static int __init docg3_probe(struct platform_device *pdev)
|
|||
return ret;
|
||||
cascade->base = base;
|
||||
mutex_init(&cascade->lock);
|
||||
cascade->bch = init_bch(DOC_ECC_BCH_M, DOC_ECC_BCH_T,
|
||||
DOC_ECC_BCH_PRIMPOLY);
|
||||
cascade->bch = bch_init(DOC_ECC_BCH_M, DOC_ECC_BCH_T,
|
||||
DOC_ECC_BCH_PRIMPOLY);
|
||||
if (!cascade->bch)
|
||||
return ret;
|
||||
|
||||
|
@ -2021,7 +2021,7 @@ static int __init docg3_probe(struct platform_device *pdev)
|
|||
ret = -ENODEV;
|
||||
dev_info(dev, "No supported DiskOnChip found\n");
|
||||
err_probe:
|
||||
free_bch(cascade->bch);
|
||||
bch_free(cascade->bch);
|
||||
for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++)
|
||||
if (cascade->floors[floor])
|
||||
doc_release_device(cascade->floors[floor]);
|
||||
|
@ -2045,7 +2045,7 @@ static int docg3_release(struct platform_device *pdev)
|
|||
if (cascade->floors[floor])
|
||||
doc_release_device(cascade->floors[floor]);
|
||||
|
||||
free_bch(docg3->cascade->bch);
|
||||
bch_free(docg3->cascade->bch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ int nand_bch_calculate_ecc(struct nand_chip *chip, const unsigned char *buf,
|
|||
unsigned int i;
|
||||
|
||||
memset(code, 0, chip->ecc.bytes);
|
||||
encode_bch(nbc->bch, buf, chip->ecc.size, code);
|
||||
bch_encode(nbc->bch, buf, chip->ecc.size, code);
|
||||
|
||||
/* apply mask so that an erased page is a valid codeword */
|
||||
for (i = 0; i < chip->ecc.bytes; i++)
|
||||
|
@ -67,7 +67,7 @@ int nand_bch_correct_data(struct nand_chip *chip, unsigned char *buf,
|
|||
unsigned int *errloc = nbc->errloc;
|
||||
int i, count;
|
||||
|
||||
count = decode_bch(nbc->bch, NULL, chip->ecc.size, read_ecc, calc_ecc,
|
||||
count = bch_decode(nbc->bch, NULL, chip->ecc.size, read_ecc, calc_ecc,
|
||||
NULL, errloc);
|
||||
if (count > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
|
@ -130,7 +130,7 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
|
|||
if (!nbc)
|
||||
goto fail;
|
||||
|
||||
nbc->bch = init_bch(m, t, 0);
|
||||
nbc->bch = bch_init(m, t, 0);
|
||||
if (!nbc->bch)
|
||||
goto fail;
|
||||
|
||||
|
@ -182,7 +182,7 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
|
|||
goto fail;
|
||||
|
||||
memset(erased_page, 0xff, eccsize);
|
||||
encode_bch(nbc->bch, erased_page, eccsize, nbc->eccmask);
|
||||
bch_encode(nbc->bch, erased_page, eccsize, nbc->eccmask);
|
||||
kfree(erased_page);
|
||||
|
||||
for (i = 0; i < eccbytes; i++)
|
||||
|
@ -205,7 +205,7 @@ EXPORT_SYMBOL(nand_bch_init);
|
|||
void nand_bch_free(struct nand_bch_control *nbc)
|
||||
{
|
||||
if (nbc) {
|
||||
free_bch(nbc->bch);
|
||||
bch_free(nbc->bch);
|
||||
kfree(nbc->errloc);
|
||||
kfree(nbc->eccmask);
|
||||
kfree(nbc);
|
||||
|
|
|
@ -53,14 +53,14 @@ struct bch_control {
|
|||
struct gf_poly *poly_2t[4];
|
||||
};
|
||||
|
||||
struct bch_control *init_bch(int m, int t, unsigned int prim_poly);
|
||||
struct bch_control *bch_init(int m, int t, unsigned int prim_poly);
|
||||
|
||||
void free_bch(struct bch_control *bch);
|
||||
void bch_free(struct bch_control *bch);
|
||||
|
||||
void encode_bch(struct bch_control *bch, const uint8_t *data,
|
||||
void bch_encode(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,
|
||||
int bch_decode(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);
|
||||
|
||||
|
|
64
lib/bch.c
64
lib/bch.c
|
@ -23,15 +23,15 @@
|
|||
* This library provides runtime configurable encoding/decoding of binary
|
||||
* Bose-Chaudhuri-Hocquenghem (BCH) codes.
|
||||
*
|
||||
* Call init_bch to get a pointer to a newly allocated bch_control structure for
|
||||
* Call bch_init to get a pointer to a newly allocated bch_control structure for
|
||||
* the given m (Galois field order), t (error correction capability) and
|
||||
* (optional) primitive polynomial parameters.
|
||||
*
|
||||
* Call encode_bch to compute and store ecc parity bytes to a given buffer.
|
||||
* Call decode_bch to detect and locate errors in received data.
|
||||
* Call bch_encode to compute and store ecc parity bytes to a given buffer.
|
||||
* Call bch_decode to detect and locate errors in received data.
|
||||
*
|
||||
* On systems supporting hw BCH features, intermediate results may be provided
|
||||
* to decode_bch in order to skip certain steps. See decode_bch() documentation
|
||||
* to bch_decode in order to skip certain steps. See bch_decode() documentation
|
||||
* for details.
|
||||
*
|
||||
* Option CONFIG_BCH_CONST_PARAMS can be used to force fixed values of
|
||||
|
@ -115,9 +115,9 @@ struct gf_poly_deg1 {
|
|||
};
|
||||
|
||||
/*
|
||||
* same as encode_bch(), but process input data one byte at a time
|
||||
* same as bch_encode(), but process input data one byte at a time
|
||||
*/
|
||||
static void encode_bch_unaligned(struct bch_control *bch,
|
||||
static void bch_encode_unaligned(struct bch_control *bch,
|
||||
const unsigned char *data, unsigned int len,
|
||||
uint32_t *ecc)
|
||||
{
|
||||
|
@ -174,7 +174,7 @@ static void store_ecc8(struct bch_control *bch, uint8_t *dst,
|
|||
}
|
||||
|
||||
/**
|
||||
* encode_bch - calculate BCH ecc parity of data
|
||||
* bch_encode - calculate BCH ecc parity of data
|
||||
* @bch: BCH control structure
|
||||
* @data: data to encode
|
||||
* @len: data length in bytes
|
||||
|
@ -187,7 +187,7 @@ static void store_ecc8(struct bch_control *bch, uint8_t *dst,
|
|||
* The exact number of computed ecc parity bits is given by member @ecc_bits of
|
||||
* @bch; it may be less than m*t for large values of t.
|
||||
*/
|
||||
void encode_bch(struct bch_control *bch, const uint8_t *data,
|
||||
void bch_encode(struct bch_control *bch, const uint8_t *data,
|
||||
unsigned int len, uint8_t *ecc)
|
||||
{
|
||||
const unsigned int l = BCH_ECC_WORDS(bch)-1;
|
||||
|
@ -215,7 +215,7 @@ void encode_bch(struct bch_control *bch, const uint8_t *data,
|
|||
m = ((unsigned long)data) & 3;
|
||||
if (m) {
|
||||
mlen = (len < (4-m)) ? len : 4-m;
|
||||
encode_bch_unaligned(bch, data, mlen, bch->ecc_buf);
|
||||
bch_encode_unaligned(bch, data, mlen, bch->ecc_buf);
|
||||
data += mlen;
|
||||
len -= mlen;
|
||||
}
|
||||
|
@ -255,13 +255,13 @@ void encode_bch(struct bch_control *bch, const uint8_t *data,
|
|||
|
||||
/* process last unaligned bytes */
|
||||
if (len)
|
||||
encode_bch_unaligned(bch, data, len, bch->ecc_buf);
|
||||
bch_encode_unaligned(bch, data, len, bch->ecc_buf);
|
||||
|
||||
/* store ecc parity bytes into original parity buffer */
|
||||
if (ecc)
|
||||
store_ecc8(bch, ecc, bch->ecc_buf);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(encode_bch);
|
||||
EXPORT_SYMBOL_GPL(bch_encode);
|
||||
|
||||
static inline int modulo(struct bch_control *bch, unsigned int v)
|
||||
{
|
||||
|
@ -952,7 +952,7 @@ static int chien_search(struct bch_control *bch, unsigned int len,
|
|||
#endif /* USE_CHIEN_SEARCH */
|
||||
|
||||
/**
|
||||
* decode_bch - decode received codeword and find bit error locations
|
||||
* bch_decode - decode received codeword and find bit error locations
|
||||
* @bch: BCH control structure
|
||||
* @data: received data, ignored if @calc_ecc is provided
|
||||
* @len: data length in bytes, must always be provided
|
||||
|
@ -966,22 +966,22 @@ static int chien_search(struct bch_control *bch, unsigned int len,
|
|||
* invalid parameters were provided
|
||||
*
|
||||
* Depending on the available hw BCH support and the need to compute @calc_ecc
|
||||
* separately (using encode_bch()), this function should be called with one of
|
||||
* separately (using bch_encode()), this function should be called with one of
|
||||
* the following parameter configurations -
|
||||
*
|
||||
* by providing @data and @recv_ecc only:
|
||||
* decode_bch(@bch, @data, @len, @recv_ecc, NULL, NULL, @errloc)
|
||||
* bch_decode(@bch, @data, @len, @recv_ecc, NULL, NULL, @errloc)
|
||||
*
|
||||
* by providing @recv_ecc and @calc_ecc:
|
||||
* decode_bch(@bch, NULL, @len, @recv_ecc, @calc_ecc, NULL, @errloc)
|
||||
* bch_decode(@bch, NULL, @len, @recv_ecc, @calc_ecc, NULL, @errloc)
|
||||
*
|
||||
* by providing ecc = recv_ecc XOR calc_ecc:
|
||||
* decode_bch(@bch, NULL, @len, NULL, ecc, NULL, @errloc)
|
||||
* bch_decode(@bch, NULL, @len, NULL, ecc, NULL, @errloc)
|
||||
*
|
||||
* by providing syndrome results @syn:
|
||||
* decode_bch(@bch, NULL, @len, NULL, NULL, @syn, @errloc)
|
||||
* bch_decode(@bch, NULL, @len, NULL, NULL, @syn, @errloc)
|
||||
*
|
||||
* Once decode_bch() has successfully returned with a positive value, error
|
||||
* Once bch_decode() has successfully returned with a positive value, error
|
||||
* locations returned in array @errloc should be interpreted as follows -
|
||||
*
|
||||
* if (errloc[n] >= 8*len), then n-th error is located in ecc (no need for
|
||||
|
@ -993,7 +993,7 @@ static int chien_search(struct bch_control *bch, unsigned int len,
|
|||
* Note that this function does not perform any data correction by itself, it
|
||||
* merely indicates error locations.
|
||||
*/
|
||||
int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
|
||||
int bch_decode(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)
|
||||
{
|
||||
|
@ -1012,7 +1012,7 @@ int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
|
|||
/* compute received data ecc into an internal buffer */
|
||||
if (!data || !recv_ecc)
|
||||
return -EINVAL;
|
||||
encode_bch(bch, data, len, NULL);
|
||||
bch_encode(bch, data, len, NULL);
|
||||
} else {
|
||||
/* load provided calculated ecc */
|
||||
load_ecc8(bch, bch->ecc_buf, calc_ecc);
|
||||
|
@ -1053,7 +1053,7 @@ int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
|
|||
}
|
||||
return (err >= 0) ? err : -EBADMSG;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(decode_bch);
|
||||
EXPORT_SYMBOL_GPL(bch_decode);
|
||||
|
||||
/*
|
||||
* generate Galois field lookup tables
|
||||
|
@ -1236,7 +1236,7 @@ static uint32_t *compute_generator_polynomial(struct bch_control *bch)
|
|||
}
|
||||
|
||||
/**
|
||||
* init_bch - initialize a BCH encoder/decoder
|
||||
* bch_init - initialize a BCH encoder/decoder
|
||||
* @m: Galois field order, should be in the range 5-15
|
||||
* @t: maximum error correction capability, in bits
|
||||
* @prim_poly: user-provided primitive polynomial (or 0 to use default)
|
||||
|
@ -1246,17 +1246,17 @@ static uint32_t *compute_generator_polynomial(struct bch_control *bch)
|
|||
*
|
||||
* 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.
|
||||
* path. Usually, bch_init() should be called on module/driver init and
|
||||
* bch_free() should be called to release memory on exit.
|
||||
*
|
||||
* You may provide your own primitive polynomial of degree @m in argument
|
||||
* @prim_poly, or let init_bch() use its default polynomial.
|
||||
* @prim_poly, or let bch_init() use its default polynomial.
|
||||
*
|
||||
* Once init_bch() has successfully returned a pointer to a newly allocated
|
||||
* Once bch_init() has successfully returned a pointer to a newly allocated
|
||||
* BCH control structure, ecc length in bytes is given by member @ecc_bytes of
|
||||
* the structure.
|
||||
*/
|
||||
struct bch_control *init_bch(int m, int t, unsigned int prim_poly)
|
||||
struct bch_control *bch_init(int m, int t, unsigned int prim_poly)
|
||||
{
|
||||
int err = 0;
|
||||
unsigned int i, words;
|
||||
|
@ -1347,16 +1347,16 @@ struct bch_control *init_bch(int m, int t, unsigned int prim_poly)
|
|||
return bch;
|
||||
|
||||
fail:
|
||||
free_bch(bch);
|
||||
bch_free(bch);
|
||||
return NULL;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(init_bch);
|
||||
EXPORT_SYMBOL_GPL(bch_init);
|
||||
|
||||
/**
|
||||
* free_bch - free the BCH control structure
|
||||
* bch_free - free the BCH control structure
|
||||
* @bch: BCH control structure to release
|
||||
*/
|
||||
void free_bch(struct bch_control *bch)
|
||||
void bch_free(struct bch_control *bch)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
|
@ -1377,7 +1377,7 @@ void free_bch(struct bch_control *bch)
|
|||
kfree(bch);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(free_bch);
|
||||
EXPORT_SYMBOL_GPL(bch_free);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Ivan Djelic <ivan.djelic@parrot.com>");
|
||||
|
|
Loading…
Reference in New Issue
Block a user