diff options
-rw-r--r-- | drivers/md/dm-verity-fec.c | 2 | ||||
-rw-r--r-- | drivers/mtd/nand/raw/cafe_nand.c | 7 | ||||
-rw-r--r-- | drivers/mtd/nand/raw/diskonchip.c | 67 | ||||
-rw-r--r-- | include/linux/rslib.h | 74 | ||||
-rw-r--r-- | lib/reed_solomon/decode_rs.c | 34 | ||||
-rw-r--r-- | lib/reed_solomon/encode_rs.c | 15 | ||||
-rw-r--r-- | lib/reed_solomon/reed_solomon.c | 240 |
7 files changed, 243 insertions, 196 deletions
diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c index 86405869f1af..684af08d0747 100644 --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c | |||
@@ -570,7 +570,7 @@ static void *fec_rs_alloc(gfp_t gfp_mask, void *pool_data) | |||
570 | { | 570 | { |
571 | struct dm_verity *v = (struct dm_verity *)pool_data; | 571 | struct dm_verity *v = (struct dm_verity *)pool_data; |
572 | 572 | ||
573 | return init_rs(8, 0x11d, 0, 1, v->fec->roots); | 573 | return init_rs_gfp(8, 0x11d, 0, 1, v->fec->roots, gfp_mask); |
574 | } | 574 | } |
575 | 575 | ||
576 | static void fec_rs_free(void *element, void *pool_data) | 576 | static void fec_rs_free(void *element, void *pool_data) |
diff --git a/drivers/mtd/nand/raw/cafe_nand.c b/drivers/mtd/nand/raw/cafe_nand.c index d8c8c9d1e640..d721f489b38b 100644 --- a/drivers/mtd/nand/raw/cafe_nand.c +++ b/drivers/mtd/nand/raw/cafe_nand.c | |||
@@ -394,12 +394,13 @@ static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip, | |||
394 | 394 | ||
395 | for (i=0; i<8; i+=2) { | 395 | for (i=0; i<8; i+=2) { |
396 | uint32_t tmp = cafe_readl(cafe, NAND_ECC_SYN01 + (i*2)); | 396 | uint32_t tmp = cafe_readl(cafe, NAND_ECC_SYN01 + (i*2)); |
397 | syn[i] = cafe->rs->index_of[tmp & 0xfff]; | 397 | |
398 | syn[i+1] = cafe->rs->index_of[(tmp >> 16) & 0xfff]; | 398 | syn[i] = cafe->rs->codec->index_of[tmp & 0xfff]; |
399 | syn[i+1] = cafe->rs->codec->index_of[(tmp >> 16) & 0xfff]; | ||
399 | } | 400 | } |
400 | 401 | ||
401 | n = decode_rs16(cafe->rs, NULL, NULL, 1367, syn, 0, pos, 0, | 402 | n = decode_rs16(cafe->rs, NULL, NULL, 1367, syn, 0, pos, 0, |
402 | pat); | 403 | pat); |
403 | 404 | ||
404 | for (i = 0; i < n; i++) { | 405 | for (i = 0; i < n; i++) { |
405 | int p = pos[i]; | 406 | int p = pos[i]; |
diff --git a/drivers/mtd/nand/raw/diskonchip.c b/drivers/mtd/nand/raw/diskonchip.c index 86a258de0b75..2b7b2b982b77 100644 --- a/drivers/mtd/nand/raw/diskonchip.c +++ b/drivers/mtd/nand/raw/diskonchip.c | |||
@@ -66,6 +66,7 @@ struct doc_priv { | |||
66 | int curchip; | 66 | int curchip; |
67 | int mh0_page; | 67 | int mh0_page; |
68 | int mh1_page; | 68 | int mh1_page; |
69 | struct rs_control *rs_decoder; | ||
69 | struct mtd_info *nextdoc; | 70 | struct mtd_info *nextdoc; |
70 | 71 | ||
71 | /* Handle the last stage of initialization (BBT scan, partitioning) */ | 72 | /* Handle the last stage of initialization (BBT scan, partitioning) */ |
@@ -123,9 +124,6 @@ MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe | |||
123 | /* Number of symbols */ | 124 | /* Number of symbols */ |
124 | #define NN 1023 | 125 | #define NN 1023 |
125 | 126 | ||
126 | /* the Reed Solomon control structure */ | ||
127 | static struct rs_control *rs_decoder; | ||
128 | |||
129 | /* | 127 | /* |
130 | * The HW decoder in the DoC ASIC's provides us a error syndrome, | 128 | * The HW decoder in the DoC ASIC's provides us a error syndrome, |
131 | * which we must convert to a standard syndrome usable by the generic | 129 | * which we must convert to a standard syndrome usable by the generic |
@@ -140,6 +138,7 @@ static int doc_ecc_decode(struct rs_control *rs, uint8_t *data, uint8_t *ecc) | |||
140 | int i, j, nerr, errpos[8]; | 138 | int i, j, nerr, errpos[8]; |
141 | uint8_t parity; | 139 | uint8_t parity; |
142 | uint16_t ds[4], s[5], tmp, errval[8], syn[4]; | 140 | uint16_t ds[4], s[5], tmp, errval[8], syn[4]; |
141 | struct rs_codec *cd = rs->codec; | ||
143 | 142 | ||
144 | memset(syn, 0, sizeof(syn)); | 143 | memset(syn, 0, sizeof(syn)); |
145 | /* Convert the ecc bytes into words */ | 144 | /* Convert the ecc bytes into words */ |
@@ -160,15 +159,15 @@ static int doc_ecc_decode(struct rs_control *rs, uint8_t *data, uint8_t *ecc) | |||
160 | for (j = 1; j < NROOTS; j++) { | 159 | for (j = 1; j < NROOTS; j++) { |
161 | if (ds[j] == 0) | 160 | if (ds[j] == 0) |
162 | continue; | 161 | continue; |
163 | tmp = rs->index_of[ds[j]]; | 162 | tmp = cd->index_of[ds[j]]; |
164 | for (i = 0; i < NROOTS; i++) | 163 | for (i = 0; i < NROOTS; i++) |
165 | s[i] ^= rs->alpha_to[rs_modnn(rs, tmp + (FCR + i) * j)]; | 164 | s[i] ^= cd->alpha_to[rs_modnn(cd, tmp + (FCR + i) * j)]; |
166 | } | 165 | } |
167 | 166 | ||
168 | /* Calc syn[i] = s[i] / alpha^(v + i) */ | 167 | /* Calc syn[i] = s[i] / alpha^(v + i) */ |
169 | for (i = 0; i < NROOTS; i++) { | 168 | for (i = 0; i < NROOTS; i++) { |
170 | if (s[i]) | 169 | if (s[i]) |
171 | syn[i] = rs_modnn(rs, rs->index_of[s[i]] + (NN - FCR - i)); | 170 | syn[i] = rs_modnn(cd, cd->index_of[s[i]] + (NN - FCR - i)); |
172 | } | 171 | } |
173 | /* Call the decoder library */ | 172 | /* Call the decoder library */ |
174 | nerr = decode_rs16(rs, NULL, NULL, 1019, syn, 0, errpos, 0, errval); | 173 | nerr = decode_rs16(rs, NULL, NULL, 1019, syn, 0, errpos, 0, errval); |
@@ -930,7 +929,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, | |||
930 | calc_ecc[i] = ReadDOC_(docptr, DoC_ECCSyndrome0 + i); | 929 | calc_ecc[i] = ReadDOC_(docptr, DoC_ECCSyndrome0 + i); |
931 | } | 930 | } |
932 | 931 | ||
933 | ret = doc_ecc_decode(rs_decoder, dat, calc_ecc); | 932 | ret = doc_ecc_decode(doc->rs_decoder, dat, calc_ecc); |
934 | if (ret > 0) | 933 | if (ret > 0) |
935 | pr_err("doc200x_correct_data corrected %d errors\n", | 934 | pr_err("doc200x_correct_data corrected %d errors\n", |
936 | ret); | 935 | ret); |
@@ -1421,10 +1420,10 @@ static inline int __init doc2001plus_init(struct mtd_info *mtd) | |||
1421 | 1420 | ||
1422 | static int __init doc_probe(unsigned long physadr) | 1421 | static int __init doc_probe(unsigned long physadr) |
1423 | { | 1422 | { |
1423 | struct nand_chip *nand = NULL; | ||
1424 | struct doc_priv *doc = NULL; | ||
1424 | unsigned char ChipID; | 1425 | unsigned char ChipID; |
1425 | struct mtd_info *mtd; | 1426 | struct mtd_info *mtd; |
1426 | struct nand_chip *nand; | ||
1427 | struct doc_priv *doc; | ||
1428 | void __iomem *virtadr; | 1427 | void __iomem *virtadr; |
1429 | unsigned char save_control; | 1428 | unsigned char save_control; |
1430 | unsigned char tmp, tmpb, tmpc; | 1429 | unsigned char tmp, tmpb, tmpc; |
@@ -1561,8 +1560,25 @@ static int __init doc_probe(unsigned long physadr) | |||
1561 | goto fail; | 1560 | goto fail; |
1562 | } | 1561 | } |
1563 | 1562 | ||
1563 | |||
1564 | /* | ||
1565 | * Allocate a RS codec instance | ||
1566 | * | ||
1567 | * Symbolsize is 10 (bits) | ||
1568 | * Primitve polynomial is x^10+x^3+1 | ||
1569 | * First consecutive root is 510 | ||
1570 | * Primitve element to generate roots = 1 | ||
1571 | * Generator polinomial degree = 4 | ||
1572 | */ | ||
1573 | doc = (struct doc_priv *) (nand + 1); | ||
1574 | doc->rs_decoder = init_rs(10, 0x409, FCR, 1, NROOTS); | ||
1575 | if (!doc->rs_decoder) { | ||
1576 | pr_err("DiskOnChip: Could not create a RS codec\n"); | ||
1577 | ret = -ENOMEM; | ||
1578 | goto fail; | ||
1579 | } | ||
1580 | |||
1564 | mtd = nand_to_mtd(nand); | 1581 | mtd = nand_to_mtd(nand); |
1565 | doc = (struct doc_priv *) (nand + 1); | ||
1566 | nand->bbt_td = (struct nand_bbt_descr *) (doc + 1); | 1582 | nand->bbt_td = (struct nand_bbt_descr *) (doc + 1); |
1567 | nand->bbt_md = nand->bbt_td + 1; | 1583 | nand->bbt_md = nand->bbt_td + 1; |
1568 | 1584 | ||
@@ -1612,7 +1628,6 @@ static int __init doc_probe(unsigned long physadr) | |||
1612 | haven't yet added it. This is handled without incident by | 1628 | haven't yet added it. This is handled without incident by |
1613 | mtd_device_unregister, as far as I can tell. */ | 1629 | mtd_device_unregister, as far as I can tell. */ |
1614 | nand_release(mtd); | 1630 | nand_release(mtd); |
1615 | kfree(nand); | ||
1616 | goto fail; | 1631 | goto fail; |
1617 | } | 1632 | } |
1618 | 1633 | ||
@@ -1625,6 +1640,9 @@ static int __init doc_probe(unsigned long physadr) | |||
1625 | actually a DiskOnChip. */ | 1640 | actually a DiskOnChip. */ |
1626 | WriteDOC(save_control, virtadr, DOCControl); | 1641 | WriteDOC(save_control, virtadr, DOCControl); |
1627 | fail: | 1642 | fail: |
1643 | if (doc) | ||
1644 | free_rs(doc->rs_decoder); | ||
1645 | kfree(nand); | ||
1628 | iounmap(virtadr); | 1646 | iounmap(virtadr); |
1629 | 1647 | ||
1630 | error_ioremap: | 1648 | error_ioremap: |
@@ -1647,6 +1665,7 @@ static void release_nanddoc(void) | |||
1647 | nand_release(mtd); | 1665 | nand_release(mtd); |
1648 | iounmap(doc->virtadr); | 1666 | iounmap(doc->virtadr); |
1649 | release_mem_region(doc->physadr, DOC_IOREMAP_LEN); | 1667 | release_mem_region(doc->physadr, DOC_IOREMAP_LEN); |
1668 | free_rs(doc->rs_decoder); | ||
1650 | kfree(nand); | 1669 | kfree(nand); |
1651 | } | 1670 | } |
1652 | } | 1671 | } |
@@ -1655,27 +1674,12 @@ static int __init init_nanddoc(void) | |||
1655 | { | 1674 | { |
1656 | int i, ret = 0; | 1675 | int i, ret = 0; |
1657 | 1676 | ||
1658 | /* We could create the decoder on demand, if memory is a concern. | ||
1659 | * This way we have it handy, if an error happens | ||
1660 | * | ||
1661 | * Symbolsize is 10 (bits) | ||
1662 | * Primitve polynomial is x^10+x^3+1 | ||
1663 | * first consecutive root is 510 | ||
1664 | * primitve element to generate roots = 1 | ||
1665 | * generator polinomial degree = 4 | ||
1666 | */ | ||
1667 | rs_decoder = init_rs(10, 0x409, FCR, 1, NROOTS); | ||
1668 | if (!rs_decoder) { | ||
1669 | pr_err("DiskOnChip: Could not create a RS decoder\n"); | ||
1670 | return -ENOMEM; | ||
1671 | } | ||
1672 | |||
1673 | if (doc_config_location) { | 1677 | if (doc_config_location) { |
1674 | pr_info("Using configured DiskOnChip probe address 0x%lx\n", | 1678 | pr_info("Using configured DiskOnChip probe address 0x%lx\n", |
1675 | doc_config_location); | 1679 | doc_config_location); |
1676 | ret = doc_probe(doc_config_location); | 1680 | ret = doc_probe(doc_config_location); |
1677 | if (ret < 0) | 1681 | if (ret < 0) |
1678 | goto outerr; | 1682 | return ret; |
1679 | } else { | 1683 | } else { |
1680 | for (i = 0; (doc_locations[i] != 0xffffffff); i++) { | 1684 | for (i = 0; (doc_locations[i] != 0xffffffff); i++) { |
1681 | doc_probe(doc_locations[i]); | 1685 | doc_probe(doc_locations[i]); |
@@ -1686,11 +1690,7 @@ static int __init init_nanddoc(void) | |||
1686 | if (!doclist) { | 1690 | if (!doclist) { |
1687 | pr_info("No valid DiskOnChip devices found\n"); | 1691 | pr_info("No valid DiskOnChip devices found\n"); |
1688 | ret = -ENODEV; | 1692 | ret = -ENODEV; |
1689 | goto outerr; | ||
1690 | } | 1693 | } |
1691 | return 0; | ||
1692 | outerr: | ||
1693 | free_rs(rs_decoder); | ||
1694 | return ret; | 1694 | return ret; |
1695 | } | 1695 | } |
1696 | 1696 | ||
@@ -1698,11 +1698,6 @@ static void __exit cleanup_nanddoc(void) | |||
1698 | { | 1698 | { |
1699 | /* Cleanup the nand/DoC resources */ | 1699 | /* Cleanup the nand/DoC resources */ |
1700 | release_nanddoc(); | 1700 | release_nanddoc(); |
1701 | |||
1702 | /* Free the reed solomon resources */ | ||
1703 | if (rs_decoder) { | ||
1704 | free_rs(rs_decoder); | ||
1705 | } | ||
1706 | } | 1701 | } |
1707 | 1702 | ||
1708 | module_init(init_nanddoc); | 1703 | module_init(init_nanddoc); |
diff --git a/include/linux/rslib.h b/include/linux/rslib.h index 746580c1939c..5974cedd008c 100644 --- a/include/linux/rslib.h +++ b/include/linux/rslib.h | |||
@@ -1,28 +1,21 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
1 | /* | 2 | /* |
2 | * include/linux/rslib.h | 3 | * Generic Reed Solomon encoder / decoder library |
3 | * | ||
4 | * Overview: | ||
5 | * Generic Reed Solomon encoder / decoder library | ||
6 | * | 4 | * |
7 | * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) | 5 | * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) |
8 | * | 6 | * |
9 | * RS code lifted from reed solomon library written by Phil Karn | 7 | * RS code lifted from reed solomon library written by Phil Karn |
10 | * Copyright 2002 Phil Karn, KA9Q | 8 | * Copyright 2002 Phil Karn, KA9Q |
11 | * | ||
12 | * $Id: rslib.h,v 1.4 2005/11/07 11:14:52 gleixner Exp $ | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License version 2 as | ||
16 | * published by the Free Software Foundation. | ||
17 | */ | 9 | */ |
18 | |||
19 | #ifndef _RSLIB_H_ | 10 | #ifndef _RSLIB_H_ |
20 | #define _RSLIB_H_ | 11 | #define _RSLIB_H_ |
21 | 12 | ||
22 | #include <linux/list.h> | 13 | #include <linux/list.h> |
14 | #include <linux/types.h> /* for gfp_t */ | ||
15 | #include <linux/gfp.h> /* for GFP_KERNEL */ | ||
23 | 16 | ||
24 | /** | 17 | /** |
25 | * struct rs_control - rs control structure | 18 | * struct rs_codec - rs codec data |
26 | * | 19 | * |
27 | * @mm: Bits per symbol | 20 | * @mm: Bits per symbol |
28 | * @nn: Symbols per block (= (1<<mm)-1) | 21 | * @nn: Symbols per block (= (1<<mm)-1) |
@@ -36,24 +29,34 @@ | |||
36 | * @gfpoly: The primitive generator polynominal | 29 | * @gfpoly: The primitive generator polynominal |
37 | * @gffunc: Function to generate the field, if non-canonical representation | 30 | * @gffunc: Function to generate the field, if non-canonical representation |
38 | * @users: Users of this structure | 31 | * @users: Users of this structure |
39 | * @list: List entry for the rs control list | 32 | * @list: List entry for the rs codec list |
40 | */ | 33 | */ |
41 | struct rs_control { | 34 | struct rs_codec { |
42 | int mm; | 35 | int mm; |
43 | int nn; | 36 | int nn; |
44 | uint16_t *alpha_to; | 37 | uint16_t *alpha_to; |
45 | uint16_t *index_of; | 38 | uint16_t *index_of; |
46 | uint16_t *genpoly; | 39 | uint16_t *genpoly; |
47 | int nroots; | 40 | int nroots; |
48 | int fcr; | 41 | int fcr; |
49 | int prim; | 42 | int prim; |
50 | int iprim; | 43 | int iprim; |
51 | int gfpoly; | 44 | int gfpoly; |
52 | int (*gffunc)(int); | 45 | int (*gffunc)(int); |
53 | int users; | 46 | int users; |
54 | struct list_head list; | 47 | struct list_head list; |
55 | }; | 48 | }; |
56 | 49 | ||
50 | /** | ||
51 | * struct rs_control - rs control structure per instance | ||
52 | * @codec: The codec used for this instance | ||
53 | * @buffers: Internal scratch buffers used in calls to decode_rs() | ||
54 | */ | ||
55 | struct rs_control { | ||
56 | struct rs_codec *codec; | ||
57 | uint16_t buffers[0]; | ||
58 | }; | ||
59 | |||
57 | /* General purpose RS codec, 8-bit data width, symbol width 1-15 bit */ | 60 | /* General purpose RS codec, 8-bit data width, symbol width 1-15 bit */ |
58 | #ifdef CONFIG_REED_SOLOMON_ENC8 | 61 | #ifdef CONFIG_REED_SOLOMON_ENC8 |
59 | int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par, | 62 | int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par, |
@@ -76,18 +79,37 @@ int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len, | |||
76 | uint16_t *corr); | 79 | uint16_t *corr); |
77 | #endif | 80 | #endif |
78 | 81 | ||
79 | /* Create or get a matching rs control structure */ | 82 | struct rs_control *init_rs_gfp(int symsize, int gfpoly, int fcr, int prim, |
80 | struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim, | 83 | int nroots, gfp_t gfp); |
81 | int nroots); | 84 | |
85 | /** | ||
86 | * init_rs - Create a RS control struct and initialize it | ||
87 | * @symsize: the symbol size (number of bits) | ||
88 | * @gfpoly: the extended Galois field generator polynomial coefficients, | ||
89 | * with the 0th coefficient in the low order bit. The polynomial | ||
90 | * must be primitive; | ||
91 | * @fcr: the first consecutive root of the rs code generator polynomial | ||
92 | * in index form | ||
93 | * @prim: primitive element to generate polynomial roots | ||
94 | * @nroots: RS code generator polynomial degree (number of roots) | ||
95 | * | ||
96 | * Allocations use GFP_KERNEL. | ||
97 | */ | ||
98 | static inline struct rs_control *init_rs(int symsize, int gfpoly, int fcr, | ||
99 | int prim, int nroots) | ||
100 | { | ||
101 | return init_rs_gfp(symsize, gfpoly, fcr, prim, nroots, GFP_KERNEL); | ||
102 | } | ||
103 | |||
82 | struct rs_control *init_rs_non_canonical(int symsize, int (*func)(int), | 104 | struct rs_control *init_rs_non_canonical(int symsize, int (*func)(int), |
83 | int fcr, int prim, int nroots); | 105 | int fcr, int prim, int nroots); |
84 | 106 | ||
85 | /* Release a rs control structure */ | 107 | /* Release a rs control structure */ |
86 | void free_rs(struct rs_control *rs); | 108 | void free_rs(struct rs_control *rs); |
87 | 109 | ||
88 | /** modulo replacement for galois field arithmetics | 110 | /** modulo replacement for galois field arithmetics |
89 | * | 111 | * |
90 | * @rs: the rs control structure | 112 | * @rs: Pointer to the RS codec |
91 | * @x: the value to reduce | 113 | * @x: the value to reduce |
92 | * | 114 | * |
93 | * where | 115 | * where |
@@ -97,7 +119,7 @@ void free_rs(struct rs_control *rs); | |||
97 | * Simple arithmetic modulo would return a wrong result for values | 119 | * Simple arithmetic modulo would return a wrong result for values |
98 | * >= 3 * rs->nn | 120 | * >= 3 * rs->nn |
99 | */ | 121 | */ |
100 | static inline int rs_modnn(struct rs_control *rs, int x) | 122 | static inline int rs_modnn(struct rs_codec *rs, int x) |
101 | { | 123 | { |
102 | while (x >= rs->nn) { | 124 | while (x >= rs->nn) { |
103 | x -= rs->nn; | 125 | x -= rs->nn; |
diff --git a/lib/reed_solomon/decode_rs.c b/lib/reed_solomon/decode_rs.c index 0ec3f257ffdf..1db74eb098d0 100644 --- a/lib/reed_solomon/decode_rs.c +++ b/lib/reed_solomon/decode_rs.c | |||
@@ -1,22 +1,16 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
1 | /* | 2 | /* |
2 | * lib/reed_solomon/decode_rs.c | 3 | * Generic Reed Solomon encoder / decoder library |
3 | * | ||
4 | * Overview: | ||
5 | * Generic Reed Solomon encoder / decoder library | ||
6 | * | 4 | * |
7 | * Copyright 2002, Phil Karn, KA9Q | 5 | * Copyright 2002, Phil Karn, KA9Q |
8 | * May be used under the terms of the GNU General Public License (GPL) | 6 | * May be used under the terms of the GNU General Public License (GPL) |
9 | * | 7 | * |
10 | * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de) | 8 | * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de) |
11 | * | 9 | * |
12 | * $Id: decode_rs.c,v 1.7 2005/11/07 11:14:59 gleixner Exp $ | 10 | * Generic data width independent code which is included by the wrappers. |
13 | * | ||
14 | */ | ||
15 | |||
16 | /* Generic data width independent code which is included by the | ||
17 | * wrappers. | ||
18 | */ | 11 | */ |
19 | { | 12 | { |
13 | struct rs_codec *rs = rsc->codec; | ||
20 | int deg_lambda, el, deg_omega; | 14 | int deg_lambda, el, deg_omega; |
21 | int i, j, r, k, pad; | 15 | int i, j, r, k, pad; |
22 | int nn = rs->nn; | 16 | int nn = rs->nn; |
@@ -27,16 +21,22 @@ | |||
27 | uint16_t *alpha_to = rs->alpha_to; | 21 | uint16_t *alpha_to = rs->alpha_to; |
28 | uint16_t *index_of = rs->index_of; | 22 | uint16_t *index_of = rs->index_of; |
29 | uint16_t u, q, tmp, num1, num2, den, discr_r, syn_error; | 23 | uint16_t u, q, tmp, num1, num2, den, discr_r, syn_error; |
30 | /* Err+Eras Locator poly and syndrome poly The maximum value | ||
31 | * of nroots is 8. So the necessary stack size will be about | ||
32 | * 220 bytes max. | ||
33 | */ | ||
34 | uint16_t lambda[nroots + 1], syn[nroots]; | ||
35 | uint16_t b[nroots + 1], t[nroots + 1], omega[nroots + 1]; | ||
36 | uint16_t root[nroots], reg[nroots + 1], loc[nroots]; | ||
37 | int count = 0; | 24 | int count = 0; |
38 | uint16_t msk = (uint16_t) rs->nn; | 25 | uint16_t msk = (uint16_t) rs->nn; |
39 | 26 | ||
27 | /* | ||
28 | * The decoder buffers are in the rs control struct. They are | ||
29 | * arrays sized [nroots + 1] | ||
30 | */ | ||
31 | uint16_t *lambda = rsc->buffers + RS_DECODE_LAMBDA * (nroots + 1); | ||
32 | uint16_t *syn = rsc->buffers + RS_DECODE_SYN * (nroots + 1); | ||
33 | uint16_t *b = rsc->buffers + RS_DECODE_B * (nroots + 1); | ||
34 | uint16_t *t = rsc->buffers + RS_DECODE_T * (nroots + 1); | ||
35 | uint16_t *omega = rsc->buffers + RS_DECODE_OMEGA * (nroots + 1); | ||
36 | uint16_t *root = rsc->buffers + RS_DECODE_ROOT * (nroots + 1); | ||
37 | uint16_t *reg = rsc->buffers + RS_DECODE_REG * (nroots + 1); | ||
38 | uint16_t *loc = rsc->buffers + RS_DECODE_LOC * (nroots + 1); | ||
39 | |||
40 | /* Check length parameter for validity */ | 40 | /* Check length parameter for validity */ |
41 | pad = nn - nroots - len; | 41 | pad = nn - nroots - len; |
42 | BUG_ON(pad < 0 || pad >= nn); | 42 | BUG_ON(pad < 0 || pad >= nn); |
diff --git a/lib/reed_solomon/encode_rs.c b/lib/reed_solomon/encode_rs.c index 0b5b1a6728ec..9112d46e869e 100644 --- a/lib/reed_solomon/encode_rs.c +++ b/lib/reed_solomon/encode_rs.c | |||
@@ -1,23 +1,16 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
1 | /* | 2 | /* |
2 | * lib/reed_solomon/encode_rs.c | 3 | * Generic Reed Solomon encoder / decoder library |
3 | * | ||
4 | * Overview: | ||
5 | * Generic Reed Solomon encoder / decoder library | ||
6 | * | 4 | * |
7 | * Copyright 2002, Phil Karn, KA9Q | 5 | * Copyright 2002, Phil Karn, KA9Q |
8 | * May be used under the terms of the GNU General Public License (GPL) | 6 | * May be used under the terms of the GNU General Public License (GPL) |
9 | * | 7 | * |
10 | * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de) | 8 | * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de) |
11 | * | 9 | * |
12 | * $Id: encode_rs.c,v 1.5 2005/11/07 11:14:59 gleixner Exp $ | 10 | * Generic data width independent code which is included by the wrappers. |
13 | * | ||
14 | */ | ||
15 | |||
16 | /* Generic data width independent code which is included by the | ||
17 | * wrappers. | ||
18 | * int encode_rsX (struct rs_control *rs, uintX_t *data, int len, uintY_t *par) | ||
19 | */ | 11 | */ |
20 | { | 12 | { |
13 | struct rs_codec *rs = rsc->codec; | ||
21 | int i, j, pad; | 14 | int i, j, pad; |
22 | int nn = rs->nn; | 15 | int nn = rs->nn; |
23 | int nroots = rs->nroots; | 16 | int nroots = rs->nroots; |
diff --git a/lib/reed_solomon/reed_solomon.c b/lib/reed_solomon/reed_solomon.c index 06d04cfa9339..dfcf54242fb9 100644 --- a/lib/reed_solomon/reed_solomon.c +++ b/lib/reed_solomon/reed_solomon.c | |||
@@ -1,43 +1,34 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
1 | /* | 2 | /* |
2 | * lib/reed_solomon/reed_solomon.c | 3 | * Generic Reed Solomon encoder / decoder library |
3 | * | ||
4 | * Overview: | ||
5 | * Generic Reed Solomon encoder / decoder library | ||
6 | * | 4 | * |
7 | * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) | 5 | * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) |
8 | * | 6 | * |
9 | * Reed Solomon code lifted from reed solomon library written by Phil Karn | 7 | * Reed Solomon code lifted from reed solomon library written by Phil Karn |
10 | * Copyright 2002 Phil Karn, KA9Q | 8 | * Copyright 2002 Phil Karn, KA9Q |
11 | * | 9 | * |
12 | * $Id: rslib.c,v 1.7 2005/11/07 11:14:59 gleixner Exp $ | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License version 2 as | ||
16 | * published by the Free Software Foundation. | ||
17 | * | ||
18 | * Description: | 10 | * Description: |
19 | * | 11 | * |
20 | * The generic Reed Solomon library provides runtime configurable | 12 | * The generic Reed Solomon library provides runtime configurable |
21 | * encoding / decoding of RS codes. | 13 | * encoding / decoding of RS codes. |
22 | * Each user must call init_rs to get a pointer to a rs_control | ||
23 | * structure for the given rs parameters. This structure is either | ||
24 | * generated or a already available matching control structure is used. | ||
25 | * If a structure is generated then the polynomial arrays for | ||
26 | * fast encoding / decoding are built. This can take some time so | ||
27 | * make sure not to call this function from a time critical path. | ||
28 | * Usually a module / driver should initialize the necessary | ||
29 | * rs_control structure on module / driver init and release it | ||
30 | * on exit. | ||
31 | * The encoding puts the calculated syndrome into a given syndrome | ||
32 | * buffer. | ||
33 | * The decoding is a two step process. The first step calculates | ||
34 | * the syndrome over the received (data + syndrome) and calls the | ||
35 | * second stage, which does the decoding / error correction itself. | ||
36 | * Many hw encoders provide a syndrome calculation over the received | ||
37 | * data + syndrome and can call the second stage directly. | ||
38 | * | 14 | * |
15 | * Each user must call init_rs to get a pointer to a rs_control structure | ||
16 | * for the given rs parameters. The control struct is unique per instance. | ||
17 | * It points to a codec which can be shared by multiple control structures. | ||
18 | * If a codec is newly allocated then the polynomial arrays for fast | ||
19 | * encoding / decoding are built. This can take some time so make sure not | ||
20 | * to call this function from a time critical path. Usually a module / | ||
21 | * driver should initialize the necessary rs_control structure on module / | ||
22 | * driver init and release it on exit. | ||
23 | * | ||
24 | * The encoding puts the calculated syndrome into a given syndrome buffer. | ||
25 | * | ||
26 | * The decoding is a two step process. The first step calculates the | ||
27 | * syndrome over the received (data + syndrome) and calls the second stage, | ||
28 | * which does the decoding / error correction itself. Many hw encoders | ||
29 | * provide a syndrome calculation over the received data + syndrome and can | ||
30 | * call the second stage directly. | ||
39 | */ | 31 | */ |
40 | |||
41 | #include <linux/errno.h> | 32 | #include <linux/errno.h> |
42 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
43 | #include <linux/init.h> | 34 | #include <linux/init.h> |
@@ -46,32 +37,44 @@ | |||
46 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
47 | #include <linux/mutex.h> | 38 | #include <linux/mutex.h> |
48 | 39 | ||
49 | /* This list holds all currently allocated rs control structures */ | 40 | enum { |
50 | static LIST_HEAD (rslist); | 41 | RS_DECODE_LAMBDA, |
42 | RS_DECODE_SYN, | ||
43 | RS_DECODE_B, | ||
44 | RS_DECODE_T, | ||
45 | RS_DECODE_OMEGA, | ||
46 | RS_DECODE_ROOT, | ||
47 | RS_DECODE_REG, | ||
48 | RS_DECODE_LOC, | ||
49 | RS_DECODE_NUM_BUFFERS | ||
50 | }; | ||
51 | |||
52 | /* This list holds all currently allocated rs codec structures */ | ||
53 | static LIST_HEAD(codec_list); | ||
51 | /* Protection for the list */ | 54 | /* Protection for the list */ |
52 | static DEFINE_MUTEX(rslistlock); | 55 | static DEFINE_MUTEX(rslistlock); |
53 | 56 | ||
54 | /** | 57 | /** |
55 | * rs_init - Initialize a Reed-Solomon codec | 58 | * codec_init - Initialize a Reed-Solomon codec |
56 | * @symsize: symbol size, bits (1-8) | 59 | * @symsize: symbol size, bits (1-8) |
57 | * @gfpoly: Field generator polynomial coefficients | 60 | * @gfpoly: Field generator polynomial coefficients |
58 | * @gffunc: Field generator function | 61 | * @gffunc: Field generator function |
59 | * @fcr: first root of RS code generator polynomial, index form | 62 | * @fcr: first root of RS code generator polynomial, index form |
60 | * @prim: primitive element to generate polynomial roots | 63 | * @prim: primitive element to generate polynomial roots |
61 | * @nroots: RS code generator polynomial degree (number of roots) | 64 | * @nroots: RS code generator polynomial degree (number of roots) |
65 | * @gfp: GFP_ flags for allocations | ||
62 | * | 66 | * |
63 | * Allocate a control structure and the polynom arrays for faster | 67 | * Allocate a codec structure and the polynom arrays for faster |
64 | * en/decoding. Fill the arrays according to the given parameters. | 68 | * en/decoding. Fill the arrays according to the given parameters. |
65 | */ | 69 | */ |
66 | static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int), | 70 | static struct rs_codec *codec_init(int symsize, int gfpoly, int (*gffunc)(int), |
67 | int fcr, int prim, int nroots) | 71 | int fcr, int prim, int nroots, gfp_t gfp) |
68 | { | 72 | { |
69 | struct rs_control *rs; | ||
70 | int i, j, sr, root, iprim; | 73 | int i, j, sr, root, iprim; |
74 | struct rs_codec *rs; | ||
71 | 75 | ||
72 | /* Allocate the control structure */ | 76 | rs = kzalloc(sizeof(*rs), gfp); |
73 | rs = kmalloc(sizeof (struct rs_control), GFP_KERNEL); | 77 | if (!rs) |
74 | if (rs == NULL) | ||
75 | return NULL; | 78 | return NULL; |
76 | 79 | ||
77 | INIT_LIST_HEAD(&rs->list); | 80 | INIT_LIST_HEAD(&rs->list); |
@@ -85,17 +88,17 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int), | |||
85 | rs->gffunc = gffunc; | 88 | rs->gffunc = gffunc; |
86 | 89 | ||
87 | /* Allocate the arrays */ | 90 | /* Allocate the arrays */ |
88 | rs->alpha_to = kmalloc(sizeof(uint16_t) * (rs->nn + 1), GFP_KERNEL); | 91 | rs->alpha_to = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp); |
89 | if (rs->alpha_to == NULL) | 92 | if (rs->alpha_to == NULL) |
90 | goto errrs; | 93 | goto err; |
91 | 94 | ||
92 | rs->index_of = kmalloc(sizeof(uint16_t) * (rs->nn + 1), GFP_KERNEL); | 95 | rs->index_of = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp); |
93 | if (rs->index_of == NULL) | 96 | if (rs->index_of == NULL) |
94 | goto erralp; | 97 | goto err; |
95 | 98 | ||
96 | rs->genpoly = kmalloc(sizeof(uint16_t) * (rs->nroots + 1), GFP_KERNEL); | 99 | rs->genpoly = kmalloc(sizeof(uint16_t) * (rs->nroots + 1), gfp); |
97 | if(rs->genpoly == NULL) | 100 | if(rs->genpoly == NULL) |
98 | goto erridx; | 101 | goto err; |
99 | 102 | ||
100 | /* Generate Galois field lookup tables */ | 103 | /* Generate Galois field lookup tables */ |
101 | rs->index_of[0] = rs->nn; /* log(zero) = -inf */ | 104 | rs->index_of[0] = rs->nn; /* log(zero) = -inf */ |
@@ -120,7 +123,7 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int), | |||
120 | } | 123 | } |
121 | /* If it's not primitive, exit */ | 124 | /* If it's not primitive, exit */ |
122 | if(sr != rs->alpha_to[0]) | 125 | if(sr != rs->alpha_to[0]) |
123 | goto errpol; | 126 | goto err; |
124 | 127 | ||
125 | /* Find prim-th root of 1, used in decoding */ | 128 | /* Find prim-th root of 1, used in decoding */ |
126 | for(iprim = 1; (iprim % prim) != 0; iprim += rs->nn); | 129 | for(iprim = 1; (iprim % prim) != 0; iprim += rs->nn); |
@@ -148,42 +151,52 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int), | |||
148 | /* convert rs->genpoly[] to index form for quicker encoding */ | 151 | /* convert rs->genpoly[] to index form for quicker encoding */ |
149 | for (i = 0; i <= nroots; i++) | 152 | for (i = 0; i <= nroots; i++) |
150 | rs->genpoly[i] = rs->index_of[rs->genpoly[i]]; | 153 | rs->genpoly[i] = rs->index_of[rs->genpoly[i]]; |
154 | |||
155 | rs->users = 1; | ||
156 | list_add(&rs->list, &codec_list); | ||
151 | return rs; | 157 | return rs; |
152 | 158 | ||
153 | /* Error exit */ | 159 | err: |
154 | errpol: | ||
155 | kfree(rs->genpoly); | 160 | kfree(rs->genpoly); |
156 | erridx: | ||
157 | kfree(rs->index_of); | 161 | kfree(rs->index_of); |
158 | erralp: | ||
159 | kfree(rs->alpha_to); | 162 | kfree(rs->alpha_to); |
160 | errrs: | ||
161 | kfree(rs); | 163 | kfree(rs); |
162 | return NULL; | 164 | return NULL; |
163 | } | 165 | } |
164 | 166 | ||
165 | 167 | ||
166 | /** | 168 | /** |
167 | * free_rs - Free the rs control structure, if it is no longer used | 169 | * free_rs - Free the rs control structure |
168 | * @rs: the control structure which is not longer used by the | 170 | * @rs: The control structure which is not longer used by the |
169 | * caller | 171 | * caller |
172 | * | ||
173 | * Free the control structure. If @rs is the last user of the associated | ||
174 | * codec, free the codec as well. | ||
170 | */ | 175 | */ |
171 | void free_rs(struct rs_control *rs) | 176 | void free_rs(struct rs_control *rs) |
172 | { | 177 | { |
178 | struct rs_codec *cd; | ||
179 | |||
180 | if (!rs) | ||
181 | return; | ||
182 | |||
183 | cd = rs->codec; | ||
173 | mutex_lock(&rslistlock); | 184 | mutex_lock(&rslistlock); |
174 | rs->users--; | 185 | cd->users--; |
175 | if(!rs->users) { | 186 | if(!cd->users) { |
176 | list_del(&rs->list); | 187 | list_del(&cd->list); |
177 | kfree(rs->alpha_to); | 188 | kfree(cd->alpha_to); |
178 | kfree(rs->index_of); | 189 | kfree(cd->index_of); |
179 | kfree(rs->genpoly); | 190 | kfree(cd->genpoly); |
180 | kfree(rs); | 191 | kfree(cd); |
181 | } | 192 | } |
182 | mutex_unlock(&rslistlock); | 193 | mutex_unlock(&rslistlock); |
194 | kfree(rs); | ||
183 | } | 195 | } |
196 | EXPORT_SYMBOL_GPL(free_rs); | ||
184 | 197 | ||
185 | /** | 198 | /** |
186 | * init_rs_internal - Find a matching or allocate a new rs control structure | 199 | * init_rs_internal - Allocate rs control, find a matching codec or allocate a new one |
187 | * @symsize: the symbol size (number of bits) | 200 | * @symsize: the symbol size (number of bits) |
188 | * @gfpoly: the extended Galois field generator polynomial coefficients, | 201 | * @gfpoly: the extended Galois field generator polynomial coefficients, |
189 | * with the 0th coefficient in the low order bit. The polynomial | 202 | * with the 0th coefficient in the low order bit. The polynomial |
@@ -191,55 +204,69 @@ void free_rs(struct rs_control *rs) | |||
191 | * @gffunc: pointer to function to generate the next field element, | 204 | * @gffunc: pointer to function to generate the next field element, |
192 | * or the multiplicative identity element if given 0. Used | 205 | * or the multiplicative identity element if given 0. Used |
193 | * instead of gfpoly if gfpoly is 0 | 206 | * instead of gfpoly if gfpoly is 0 |
194 | * @fcr: the first consecutive root of the rs code generator polynomial | 207 | * @fcr: the first consecutive root of the rs code generator polynomial |
195 | * in index form | 208 | * in index form |
196 | * @prim: primitive element to generate polynomial roots | 209 | * @prim: primitive element to generate polynomial roots |
197 | * @nroots: RS code generator polynomial degree (number of roots) | 210 | * @nroots: RS code generator polynomial degree (number of roots) |
211 | * @gfp: GFP_ flags for allocations | ||
198 | */ | 212 | */ |
199 | static struct rs_control *init_rs_internal(int symsize, int gfpoly, | 213 | static struct rs_control *init_rs_internal(int symsize, int gfpoly, |
200 | int (*gffunc)(int), int fcr, | 214 | int (*gffunc)(int), int fcr, |
201 | int prim, int nroots) | 215 | int prim, int nroots, gfp_t gfp) |
202 | { | 216 | { |
203 | struct list_head *tmp; | 217 | struct list_head *tmp; |
204 | struct rs_control *rs; | 218 | struct rs_control *rs; |
219 | unsigned int bsize; | ||
205 | 220 | ||
206 | /* Sanity checks */ | 221 | /* Sanity checks */ |
207 | if (symsize < 1) | 222 | if (symsize < 1) |
208 | return NULL; | 223 | return NULL; |
209 | if (fcr < 0 || fcr >= (1<<symsize)) | 224 | if (fcr < 0 || fcr >= (1<<symsize)) |
210 | return NULL; | 225 | return NULL; |
211 | if (prim <= 0 || prim >= (1<<symsize)) | 226 | if (prim <= 0 || prim >= (1<<symsize)) |
212 | return NULL; | 227 | return NULL; |
213 | if (nroots < 0 || nroots >= (1<<symsize)) | 228 | if (nroots < 0 || nroots >= (1<<symsize)) |
214 | return NULL; | 229 | return NULL; |
215 | 230 | ||
231 | /* | ||
232 | * The decoder needs buffers in each control struct instance to | ||
233 | * avoid variable size or large fixed size allocations on | ||
234 | * stack. Size the buffers to arrays of [nroots + 1]. | ||
235 | */ | ||
236 | bsize = sizeof(uint16_t) * RS_DECODE_NUM_BUFFERS * (nroots + 1); | ||
237 | rs = kzalloc(sizeof(*rs) + bsize, gfp); | ||
238 | if (!rs) | ||
239 | return NULL; | ||
240 | |||
216 | mutex_lock(&rslistlock); | 241 | mutex_lock(&rslistlock); |
217 | 242 | ||
218 | /* Walk through the list and look for a matching entry */ | 243 | /* Walk through the list and look for a matching entry */ |
219 | list_for_each(tmp, &rslist) { | 244 | list_for_each(tmp, &codec_list) { |
220 | rs = list_entry(tmp, struct rs_control, list); | 245 | struct rs_codec *cd = list_entry(tmp, struct rs_codec, list); |
221 | if (symsize != rs->mm) | 246 | |
247 | if (symsize != cd->mm) | ||
222 | continue; | 248 | continue; |
223 | if (gfpoly != rs->gfpoly) | 249 | if (gfpoly != cd->gfpoly) |
224 | continue; | 250 | continue; |
225 | if (gffunc != rs->gffunc) | 251 | if (gffunc != cd->gffunc) |
226 | continue; | 252 | continue; |
227 | if (fcr != rs->fcr) | 253 | if (fcr != cd->fcr) |
228 | continue; | 254 | continue; |
229 | if (prim != rs->prim) | 255 | if (prim != cd->prim) |
230 | continue; | 256 | continue; |
231 | if (nroots != rs->nroots) | 257 | if (nroots != cd->nroots) |
232 | continue; | 258 | continue; |
233 | /* We have a matching one already */ | 259 | /* We have a matching one already */ |
234 | rs->users++; | 260 | cd->users++; |
261 | rs->codec = cd; | ||
235 | goto out; | 262 | goto out; |
236 | } | 263 | } |
237 | 264 | ||
238 | /* Create a new one */ | 265 | /* Create a new one */ |
239 | rs = rs_init(symsize, gfpoly, gffunc, fcr, prim, nroots); | 266 | rs->codec = codec_init(symsize, gfpoly, gffunc, fcr, prim, nroots, gfp); |
240 | if (rs) { | 267 | if (!rs->codec) { |
241 | rs->users = 1; | 268 | kfree(rs); |
242 | list_add(&rs->list, &rslist); | 269 | rs = NULL; |
243 | } | 270 | } |
244 | out: | 271 | out: |
245 | mutex_unlock(&rslistlock); | 272 | mutex_unlock(&rslistlock); |
@@ -247,45 +274,48 @@ out: | |||
247 | } | 274 | } |
248 | 275 | ||
249 | /** | 276 | /** |
250 | * init_rs - Find a matching or allocate a new rs control structure | 277 | * init_rs_gfp - Create a RS control struct and initialize it |
251 | * @symsize: the symbol size (number of bits) | 278 | * @symsize: the symbol size (number of bits) |
252 | * @gfpoly: the extended Galois field generator polynomial coefficients, | 279 | * @gfpoly: the extended Galois field generator polynomial coefficients, |
253 | * with the 0th coefficient in the low order bit. The polynomial | 280 | * with the 0th coefficient in the low order bit. The polynomial |
254 | * must be primitive; | 281 | * must be primitive; |
255 | * @fcr: the first consecutive root of the rs code generator polynomial | 282 | * @fcr: the first consecutive root of the rs code generator polynomial |
256 | * in index form | 283 | * in index form |
257 | * @prim: primitive element to generate polynomial roots | 284 | * @prim: primitive element to generate polynomial roots |
258 | * @nroots: RS code generator polynomial degree (number of roots) | 285 | * @nroots: RS code generator polynomial degree (number of roots) |
286 | * @gfp: GFP_ flags for allocations | ||
259 | */ | 287 | */ |
260 | struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim, | 288 | struct rs_control *init_rs_gfp(int symsize, int gfpoly, int fcr, int prim, |
261 | int nroots) | 289 | int nroots, gfp_t gfp) |
262 | { | 290 | { |
263 | return init_rs_internal(symsize, gfpoly, NULL, fcr, prim, nroots); | 291 | return init_rs_internal(symsize, gfpoly, NULL, fcr, prim, nroots, gfp); |
264 | } | 292 | } |
293 | EXPORT_SYMBOL_GPL(init_rs_gfp); | ||
265 | 294 | ||
266 | /** | 295 | /** |
267 | * init_rs_non_canonical - Find a matching or allocate a new rs control | 296 | * init_rs_non_canonical - Allocate rs control struct for fields with |
268 | * structure, for fields with non-canonical | 297 | * non-canonical representation |
269 | * representation | ||
270 | * @symsize: the symbol size (number of bits) | 298 | * @symsize: the symbol size (number of bits) |
271 | * @gffunc: pointer to function to generate the next field element, | 299 | * @gffunc: pointer to function to generate the next field element, |
272 | * or the multiplicative identity element if given 0. Used | 300 | * or the multiplicative identity element if given 0. Used |
273 | * instead of gfpoly if gfpoly is 0 | 301 | * instead of gfpoly if gfpoly is 0 |
274 | * @fcr: the first consecutive root of the rs code generator polynomial | 302 | * @fcr: the first consecutive root of the rs code generator polynomial |
275 | * in index form | 303 | * in index form |
276 | * @prim: primitive element to generate polynomial roots | 304 | * @prim: primitive element to generate polynomial roots |
277 | * @nroots: RS code generator polynomial degree (number of roots) | 305 | * @nroots: RS code generator polynomial degree (number of roots) |
278 | */ | 306 | */ |
279 | struct rs_control *init_rs_non_canonical(int symsize, int (*gffunc)(int), | 307 | struct rs_control *init_rs_non_canonical(int symsize, int (*gffunc)(int), |
280 | int fcr, int prim, int nroots) | 308 | int fcr, int prim, int nroots) |
281 | { | 309 | { |
282 | return init_rs_internal(symsize, 0, gffunc, fcr, prim, nroots); | 310 | return init_rs_internal(symsize, 0, gffunc, fcr, prim, nroots, |
311 | GFP_KERNEL); | ||
283 | } | 312 | } |
313 | EXPORT_SYMBOL_GPL(init_rs_non_canonical); | ||
284 | 314 | ||
285 | #ifdef CONFIG_REED_SOLOMON_ENC8 | 315 | #ifdef CONFIG_REED_SOLOMON_ENC8 |
286 | /** | 316 | /** |
287 | * encode_rs8 - Calculate the parity for data values (8bit data width) | 317 | * encode_rs8 - Calculate the parity for data values (8bit data width) |
288 | * @rs: the rs control structure | 318 | * @rsc: the rs control structure |
289 | * @data: data field of a given type | 319 | * @data: data field of a given type |
290 | * @len: data length | 320 | * @len: data length |
291 | * @par: parity data, must be initialized by caller (usually all 0) | 321 | * @par: parity data, must be initialized by caller (usually all 0) |
@@ -295,7 +325,7 @@ struct rs_control *init_rs_non_canonical(int symsize, int (*gffunc)(int), | |||
295 | * symbol size > 8. The calling code must take care of encoding of the | 325 | * symbol size > 8. The calling code must take care of encoding of the |
296 | * syndrome result for storage itself. | 326 | * syndrome result for storage itself. |
297 | */ | 327 | */ |
298 | int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par, | 328 | int encode_rs8(struct rs_control *rsc, uint8_t *data, int len, uint16_t *par, |
299 | uint16_t invmsk) | 329 | uint16_t invmsk) |
300 | { | 330 | { |
301 | #include "encode_rs.c" | 331 | #include "encode_rs.c" |
@@ -306,7 +336,7 @@ EXPORT_SYMBOL_GPL(encode_rs8); | |||
306 | #ifdef CONFIG_REED_SOLOMON_DEC8 | 336 | #ifdef CONFIG_REED_SOLOMON_DEC8 |
307 | /** | 337 | /** |
308 | * decode_rs8 - Decode codeword (8bit data width) | 338 | * decode_rs8 - Decode codeword (8bit data width) |
309 | * @rs: the rs control structure | 339 | * @rsc: the rs control structure |
310 | * @data: data field of a given type | 340 | * @data: data field of a given type |
311 | * @par: received parity data field | 341 | * @par: received parity data field |
312 | * @len: data length | 342 | * @len: data length |
@@ -319,9 +349,14 @@ EXPORT_SYMBOL_GPL(encode_rs8); | |||
319 | * The syndrome and parity uses a uint16_t data type to enable | 349 | * The syndrome and parity uses a uint16_t data type to enable |
320 | * symbol size > 8. The calling code must take care of decoding of the | 350 | * symbol size > 8. The calling code must take care of decoding of the |
321 | * syndrome result and the received parity before calling this code. | 351 | * syndrome result and the received parity before calling this code. |
352 | * | ||
353 | * Note: The rs_control struct @rsc contains buffers which are used for | ||
354 | * decoding, so the caller has to ensure that decoder invocations are | ||
355 | * serialized. | ||
356 | * | ||
322 | * Returns the number of corrected bits or -EBADMSG for uncorrectable errors. | 357 | * Returns the number of corrected bits or -EBADMSG for uncorrectable errors. |
323 | */ | 358 | */ |
324 | int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len, | 359 | int decode_rs8(struct rs_control *rsc, uint8_t *data, uint16_t *par, int len, |
325 | uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, | 360 | uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, |
326 | uint16_t *corr) | 361 | uint16_t *corr) |
327 | { | 362 | { |
@@ -333,7 +368,7 @@ EXPORT_SYMBOL_GPL(decode_rs8); | |||
333 | #ifdef CONFIG_REED_SOLOMON_ENC16 | 368 | #ifdef CONFIG_REED_SOLOMON_ENC16 |
334 | /** | 369 | /** |
335 | * encode_rs16 - Calculate the parity for data values (16bit data width) | 370 | * encode_rs16 - Calculate the parity for data values (16bit data width) |
336 | * @rs: the rs control structure | 371 | * @rsc: the rs control structure |
337 | * @data: data field of a given type | 372 | * @data: data field of a given type |
338 | * @len: data length | 373 | * @len: data length |
339 | * @par: parity data, must be initialized by caller (usually all 0) | 374 | * @par: parity data, must be initialized by caller (usually all 0) |
@@ -341,7 +376,7 @@ EXPORT_SYMBOL_GPL(decode_rs8); | |||
341 | * | 376 | * |
342 | * Each field in the data array contains up to symbol size bits of valid data. | 377 | * Each field in the data array contains up to symbol size bits of valid data. |
343 | */ | 378 | */ |
344 | int encode_rs16(struct rs_control *rs, uint16_t *data, int len, uint16_t *par, | 379 | int encode_rs16(struct rs_control *rsc, uint16_t *data, int len, uint16_t *par, |
345 | uint16_t invmsk) | 380 | uint16_t invmsk) |
346 | { | 381 | { |
347 | #include "encode_rs.c" | 382 | #include "encode_rs.c" |
@@ -352,7 +387,7 @@ EXPORT_SYMBOL_GPL(encode_rs16); | |||
352 | #ifdef CONFIG_REED_SOLOMON_DEC16 | 387 | #ifdef CONFIG_REED_SOLOMON_DEC16 |
353 | /** | 388 | /** |
354 | * decode_rs16 - Decode codeword (16bit data width) | 389 | * decode_rs16 - Decode codeword (16bit data width) |
355 | * @rs: the rs control structure | 390 | * @rsc: the rs control structure |
356 | * @data: data field of a given type | 391 | * @data: data field of a given type |
357 | * @par: received parity data field | 392 | * @par: received parity data field |
358 | * @len: data length | 393 | * @len: data length |
@@ -363,9 +398,14 @@ EXPORT_SYMBOL_GPL(encode_rs16); | |||
363 | * @corr: buffer to store correction bitmask on eras_pos | 398 | * @corr: buffer to store correction bitmask on eras_pos |
364 | * | 399 | * |
365 | * Each field in the data array contains up to symbol size bits of valid data. | 400 | * Each field in the data array contains up to symbol size bits of valid data. |
401 | * | ||
402 | * Note: The rc_control struct @rsc contains buffers which are used for | ||
403 | * decoding, so the caller has to ensure that decoder invocations are | ||
404 | * serialized. | ||
405 | * | ||
366 | * Returns the number of corrected bits or -EBADMSG for uncorrectable errors. | 406 | * Returns the number of corrected bits or -EBADMSG for uncorrectable errors. |
367 | */ | 407 | */ |
368 | int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len, | 408 | int decode_rs16(struct rs_control *rsc, uint16_t *data, uint16_t *par, int len, |
369 | uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, | 409 | uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, |
370 | uint16_t *corr) | 410 | uint16_t *corr) |
371 | { | 411 | { |
@@ -374,10 +414,6 @@ int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len, | |||
374 | EXPORT_SYMBOL_GPL(decode_rs16); | 414 | EXPORT_SYMBOL_GPL(decode_rs16); |
375 | #endif | 415 | #endif |
376 | 416 | ||
377 | EXPORT_SYMBOL_GPL(init_rs); | ||
378 | EXPORT_SYMBOL_GPL(init_rs_non_canonical); | ||
379 | EXPORT_SYMBOL_GPL(free_rs); | ||
380 | |||
381 | MODULE_LICENSE("GPL"); | 417 | MODULE_LICENSE("GPL"); |
382 | MODULE_DESCRIPTION("Reed Solomon encoder/decoder"); | 418 | MODULE_DESCRIPTION("Reed Solomon encoder/decoder"); |
383 | MODULE_AUTHOR("Phil Karn, Thomas Gleixner"); | 419 | MODULE_AUTHOR("Phil Karn, Thomas Gleixner"); |