blob: cb21e8b5a4e0e0a57475bdf003ccecba85917f85 [file] [log] [blame]
Thomas Gleixnerdc8f9232018-04-22 18:23:50 +02001// SPDX-License-Identifier: GPL-2.0
Thomas Gleixner03ead842005-11-07 11:15:37 +00002/*
Thomas Gleixner3413e182018-04-22 18:23:49 +02003 * Generic Reed Solomon encoder / decoder library
Thomas Gleixner03ead842005-11-07 11:15:37 +00004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
6 *
7 * Reed Solomon code lifted from reed solomon library written by Phil Karn
8 * Copyright 2002 Phil Karn, KA9Q
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * Description:
Thomas Gleixner03ead842005-11-07 11:15:37 +000011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * The generic Reed Solomon library provides runtime configurable
13 * encoding / decoding of RS codes.
Thomas Gleixner21633982018-04-22 18:23:53 +020014 *
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/errno.h>
33#include <linux/kernel.h>
34#include <linux/init.h>
35#include <linux/module.h>
36#include <linux/rslib.h>
37#include <linux/slab.h>
Arjan van de Ven97d1f152006-03-23 03:00:24 -080038#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Thomas Gleixner21633982018-04-22 18:23:53 +020040/* This list holds all currently allocated rs codec structures */
41static LIST_HEAD(codec_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/* Protection for the list */
Arjan van de Ven97d1f152006-03-23 03:00:24 -080043static DEFINE_MUTEX(rslistlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Thomas Gleixner03ead842005-11-07 11:15:37 +000045/**
Thomas Gleixner21633982018-04-22 18:23:53 +020046 * codec_init - Initialize a Reed-Solomon codec
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 * @symsize: symbol size, bits (1-8)
48 * @gfpoly: Field generator polynomial coefficients
Segher Boessenkoold7e5a542007-05-02 12:18:41 +020049 * @gffunc: Field generator function
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * @fcr: first root of RS code generator polynomial, index form
51 * @prim: primitive element to generate polynomial roots
52 * @nroots: RS code generator polynomial degree (number of roots)
Thomas Gleixner83a530e2018-04-22 18:23:46 +020053 * @gfp: GFP_ flags for allocations
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 *
Thomas Gleixner21633982018-04-22 18:23:53 +020055 * Allocate a codec structure and the polynom arrays for faster
Randy Dunlap9dc65572006-06-25 05:49:14 -070056 * en/decoding. Fill the arrays according to the given parameters.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 */
Thomas Gleixner21633982018-04-22 18:23:53 +020058static struct rs_codec *codec_init(int symsize, int gfpoly, int (*gffunc)(int),
59 int fcr, int prim, int nroots, gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 int i, j, sr, root, iprim;
Thomas Gleixner21633982018-04-22 18:23:53 +020062 struct rs_codec *rs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Thomas Gleixnera85e1262018-04-22 18:23:52 +020064 rs = kzalloc(sizeof(*rs), gfp);
Thomas Gleixner83a530e2018-04-22 18:23:46 +020065 if (!rs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 return NULL;
67
68 INIT_LIST_HEAD(&rs->list);
69
70 rs->mm = symsize;
71 rs->nn = (1 << symsize) - 1;
72 rs->fcr = fcr;
73 rs->prim = prim;
74 rs->nroots = nroots;
75 rs->gfpoly = gfpoly;
Segher Boessenkoold7e5a542007-05-02 12:18:41 +020076 rs->gffunc = gffunc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 /* Allocate the arrays */
Thomas Gleixner83a530e2018-04-22 18:23:46 +020079 rs->alpha_to = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 if (rs->alpha_to == NULL)
Thomas Gleixnera85e1262018-04-22 18:23:52 +020081 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Thomas Gleixner83a530e2018-04-22 18:23:46 +020083 rs->index_of = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (rs->index_of == NULL)
Thomas Gleixnera85e1262018-04-22 18:23:52 +020085 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Thomas Gleixner83a530e2018-04-22 18:23:46 +020087 rs->genpoly = kmalloc(sizeof(uint16_t) * (rs->nroots + 1), gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 if(rs->genpoly == NULL)
Thomas Gleixnera85e1262018-04-22 18:23:52 +020089 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 /* Generate Galois field lookup tables */
92 rs->index_of[0] = rs->nn; /* log(zero) = -inf */
93 rs->alpha_to[rs->nn] = 0; /* alpha**-inf = 0 */
Segher Boessenkoold7e5a542007-05-02 12:18:41 +020094 if (gfpoly) {
95 sr = 1;
96 for (i = 0; i < rs->nn; i++) {
97 rs->index_of[sr] = i;
98 rs->alpha_to[i] = sr;
99 sr <<= 1;
100 if (sr & (1 << symsize))
101 sr ^= gfpoly;
102 sr &= rs->nn;
103 }
104 } else {
105 sr = gffunc(0);
106 for (i = 0; i < rs->nn; i++) {
107 rs->index_of[sr] = i;
108 rs->alpha_to[i] = sr;
109 sr = gffunc(sr);
110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
112 /* If it's not primitive, exit */
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200113 if(sr != rs->alpha_to[0])
Thomas Gleixnera85e1262018-04-22 18:23:52 +0200114 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 /* Find prim-th root of 1, used in decoding */
117 for(iprim = 1; (iprim % prim) != 0; iprim += rs->nn);
118 /* prim-th root of 1, index form */
119 rs->iprim = iprim / prim;
120
121 /* Form RS code generator polynomial from its roots */
122 rs->genpoly[0] = 1;
123 for (i = 0, root = fcr * prim; i < nroots; i++, root += prim) {
124 rs->genpoly[i + 1] = 1;
125 /* Multiply rs->genpoly[] by @**(root + x) */
126 for (j = i; j > 0; j--) {
127 if (rs->genpoly[j] != 0) {
Thomas Gleixner03ead842005-11-07 11:15:37 +0000128 rs->genpoly[j] = rs->genpoly[j -1] ^
129 rs->alpha_to[rs_modnn(rs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 rs->index_of[rs->genpoly[j]] + root)];
131 } else
132 rs->genpoly[j] = rs->genpoly[j - 1];
133 }
134 /* rs->genpoly[0] can never be zero */
Thomas Gleixner03ead842005-11-07 11:15:37 +0000135 rs->genpoly[0] =
136 rs->alpha_to[rs_modnn(rs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 rs->index_of[rs->genpoly[0]] + root)];
138 }
139 /* convert rs->genpoly[] to index form for quicker encoding */
140 for (i = 0; i <= nroots; i++)
141 rs->genpoly[i] = rs->index_of[rs->genpoly[i]];
Thomas Gleixner21633982018-04-22 18:23:53 +0200142
143 rs->users = 1;
144 list_add(&rs->list, &codec_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return rs;
146
Thomas Gleixnera85e1262018-04-22 18:23:52 +0200147err:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 kfree(rs->genpoly);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 kfree(rs->index_of);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 kfree(rs->alpha_to);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 kfree(rs);
152 return NULL;
153}
154
155
Thomas Gleixner03ead842005-11-07 11:15:37 +0000156/**
Thomas Gleixner21633982018-04-22 18:23:53 +0200157 * free_rs - Free the rs control structure
158 * @rs: The control structure which is not longer used by the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 * caller
Thomas Gleixner21633982018-04-22 18:23:53 +0200160 *
161 * Free the control structure. If @rs is the last user of the associated
162 * codec, free the codec as well.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 */
164void free_rs(struct rs_control *rs)
165{
Thomas Gleixner21633982018-04-22 18:23:53 +0200166 struct rs_codec *cd;
167
168 if (!rs)
169 return;
170
171 cd = rs->codec;
Arjan van de Ven97d1f152006-03-23 03:00:24 -0800172 mutex_lock(&rslistlock);
Thomas Gleixner21633982018-04-22 18:23:53 +0200173 cd->users--;
174 if(!cd->users) {
175 list_del(&cd->list);
176 kfree(cd->alpha_to);
177 kfree(cd->index_of);
178 kfree(cd->genpoly);
179 kfree(cd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
Arjan van de Ven97d1f152006-03-23 03:00:24 -0800181 mutex_unlock(&rslistlock);
Thomas Gleixner21633982018-04-22 18:23:53 +0200182 kfree(rs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200184EXPORT_SYMBOL_GPL(free_rs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Thomas Gleixner03ead842005-11-07 11:15:37 +0000186/**
Thomas Gleixner21633982018-04-22 18:23:53 +0200187 * init_rs_internal - Allocate rs control, find a matching codec or allocate a new one
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 * @symsize: the symbol size (number of bits)
189 * @gfpoly: the extended Galois field generator polynomial coefficients,
190 * with the 0th coefficient in the low order bit. The polynomial
191 * must be primitive;
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200192 * @gffunc: pointer to function to generate the next field element,
193 * or the multiplicative identity element if given 0. Used
194 * instead of gfpoly if gfpoly is 0
Thomas Gleixnercc4b86e42018-04-22 18:23:48 +0200195 * @fcr: the first consecutive root of the rs code generator polynomial
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 * in index form
197 * @prim: primitive element to generate polynomial roots
198 * @nroots: RS code generator polynomial degree (number of roots)
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200199 * @gfp: GFP_ flags for allocations
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 */
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200201static struct rs_control *init_rs_internal(int symsize, int gfpoly,
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200202 int (*gffunc)(int), int fcr,
203 int prim, int nroots, gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200205 struct list_head *tmp;
206 struct rs_control *rs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 /* Sanity checks */
209 if (symsize < 1)
210 return NULL;
211 if (fcr < 0 || fcr >= (1<<symsize))
Thomas Gleixnercc4b86e42018-04-22 18:23:48 +0200212 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 if (prim <= 0 || prim >= (1<<symsize))
Thomas Gleixnercc4b86e42018-04-22 18:23:48 +0200214 return NULL;
Thomas Gleixner03ead842005-11-07 11:15:37 +0000215 if (nroots < 0 || nroots >= (1<<symsize))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 return NULL;
Thomas Gleixner03ead842005-11-07 11:15:37 +0000217
Thomas Gleixner21633982018-04-22 18:23:53 +0200218 rs = kzalloc(sizeof(*rs), GFP_KERNEL);
219 if (!rs)
220 return NULL;
221
Arjan van de Ven97d1f152006-03-23 03:00:24 -0800222 mutex_lock(&rslistlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 /* Walk through the list and look for a matching entry */
Thomas Gleixner21633982018-04-22 18:23:53 +0200225 list_for_each(tmp, &codec_list) {
226 struct rs_codec *cd = list_entry(tmp, struct rs_codec, list);
227
228 if (symsize != cd->mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 continue;
Thomas Gleixner21633982018-04-22 18:23:53 +0200230 if (gfpoly != cd->gfpoly)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 continue;
Thomas Gleixner21633982018-04-22 18:23:53 +0200232 if (gffunc != cd->gffunc)
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200233 continue;
Thomas Gleixner21633982018-04-22 18:23:53 +0200234 if (fcr != cd->fcr)
Thomas Gleixner03ead842005-11-07 11:15:37 +0000235 continue;
Thomas Gleixner21633982018-04-22 18:23:53 +0200236 if (prim != cd->prim)
Thomas Gleixner03ead842005-11-07 11:15:37 +0000237 continue;
Thomas Gleixner21633982018-04-22 18:23:53 +0200238 if (nroots != cd->nroots)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 continue;
240 /* We have a matching one already */
Thomas Gleixner21633982018-04-22 18:23:53 +0200241 cd->users++;
242 rs->codec = cd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 goto out;
244 }
245
246 /* Create a new one */
Thomas Gleixner21633982018-04-22 18:23:53 +0200247 rs->codec = codec_init(symsize, gfpoly, gffunc, fcr, prim, nroots, gfp);
248 if (!rs->codec) {
249 kfree(rs);
250 rs = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
Thomas Gleixner03ead842005-11-07 11:15:37 +0000252out:
Arjan van de Ven97d1f152006-03-23 03:00:24 -0800253 mutex_unlock(&rslistlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return rs;
255}
256
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200257/**
Thomas Gleixner21633982018-04-22 18:23:53 +0200258 * init_rs_gfp - Create a RS control struct and initialize it
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200259 * @symsize: the symbol size (number of bits)
260 * @gfpoly: the extended Galois field generator polynomial coefficients,
261 * with the 0th coefficient in the low order bit. The polynomial
262 * must be primitive;
Thomas Gleixnercc4b86e42018-04-22 18:23:48 +0200263 * @fcr: the first consecutive root of the rs code generator polynomial
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200264 * in index form
265 * @prim: primitive element to generate polynomial roots
266 * @nroots: RS code generator polynomial degree (number of roots)
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200267 * @gfp: GFP_ flags for allocations
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200268 */
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200269struct rs_control *init_rs_gfp(int symsize, int gfpoly, int fcr, int prim,
270 int nroots, gfp_t gfp)
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200271{
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200272 return init_rs_internal(symsize, gfpoly, NULL, fcr, prim, nroots, gfp);
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200273}
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200274EXPORT_SYMBOL_GPL(init_rs_gfp);
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200275
276/**
Thomas Gleixner21633982018-04-22 18:23:53 +0200277 * init_rs_non_canonical - Allocate rs control struct for fields with
278 * non-canonical representation
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200279 * @symsize: the symbol size (number of bits)
280 * @gffunc: pointer to function to generate the next field element,
281 * or the multiplicative identity element if given 0. Used
282 * instead of gfpoly if gfpoly is 0
Thomas Gleixnercc4b86e42018-04-22 18:23:48 +0200283 * @fcr: the first consecutive root of the rs code generator polynomial
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200284 * in index form
285 * @prim: primitive element to generate polynomial roots
286 * @nroots: RS code generator polynomial degree (number of roots)
287 */
288struct rs_control *init_rs_non_canonical(int symsize, int (*gffunc)(int),
Thomas Gleixnercc4b86e42018-04-22 18:23:48 +0200289 int fcr, int prim, int nroots)
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200290{
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200291 return init_rs_internal(symsize, 0, gffunc, fcr, prim, nroots,
292 GFP_KERNEL);
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200293}
Thomas Gleixner83a530e2018-04-22 18:23:46 +0200294EXPORT_SYMBOL_GPL(init_rs_non_canonical);
Segher Boessenkoold7e5a542007-05-02 12:18:41 +0200295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#ifdef CONFIG_REED_SOLOMON_ENC8
Thomas Gleixner03ead842005-11-07 11:15:37 +0000297/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 * encode_rs8 - Calculate the parity for data values (8bit data width)
Thomas Gleixner21633982018-04-22 18:23:53 +0200299 * @rsc: the rs control structure
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 * @data: data field of a given type
Thomas Gleixner03ead842005-11-07 11:15:37 +0000301 * @len: data length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 * @par: parity data, must be initialized by caller (usually all 0)
303 * @invmsk: invert data mask (will be xored on data)
304 *
305 * The parity uses a uint16_t data type to enable
306 * symbol size > 8. The calling code must take care of encoding of the
307 * syndrome result for storage itself.
308 */
Thomas Gleixner21633982018-04-22 18:23:53 +0200309int encode_rs8(struct rs_control *rsc, uint8_t *data, int len, uint16_t *par,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 uint16_t invmsk)
311{
312#include "encode_rs.c"
313}
314EXPORT_SYMBOL_GPL(encode_rs8);
315#endif
316
317#ifdef CONFIG_REED_SOLOMON_DEC8
Thomas Gleixner03ead842005-11-07 11:15:37 +0000318/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 * decode_rs8 - Decode codeword (8bit data width)
Thomas Gleixner21633982018-04-22 18:23:53 +0200320 * @rsc: the rs control structure
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 * @data: data field of a given type
322 * @par: received parity data field
323 * @len: data length
324 * @s: syndrome data field (if NULL, syndrome is calculated)
325 * @no_eras: number of erasures
326 * @eras_pos: position of erasures, can be NULL
327 * @invmsk: invert data mask (will be xored on data, not on parity!)
328 * @corr: buffer to store correction bitmask on eras_pos
329 *
330 * The syndrome and parity uses a uint16_t data type to enable
331 * symbol size > 8. The calling code must take care of decoding of the
332 * syndrome result and the received parity before calling this code.
Jörn Engeleb684502007-10-20 23:16:32 +0200333 * Returns the number of corrected bits or -EBADMSG for uncorrectable errors.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 */
Thomas Gleixner21633982018-04-22 18:23:53 +0200335int decode_rs8(struct rs_control *rsc, uint8_t *data, uint16_t *par, int len,
Thomas Gleixner03ead842005-11-07 11:15:37 +0000336 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 uint16_t *corr)
338{
339#include "decode_rs.c"
340}
341EXPORT_SYMBOL_GPL(decode_rs8);
342#endif
343
344#ifdef CONFIG_REED_SOLOMON_ENC16
345/**
346 * encode_rs16 - Calculate the parity for data values (16bit data width)
Thomas Gleixner21633982018-04-22 18:23:53 +0200347 * @rsc: the rs control structure
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 * @data: data field of a given type
Thomas Gleixner03ead842005-11-07 11:15:37 +0000349 * @len: data length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 * @par: parity data, must be initialized by caller (usually all 0)
351 * @invmsk: invert data mask (will be xored on data, not on parity!)
352 *
353 * Each field in the data array contains up to symbol size bits of valid data.
354 */
Thomas Gleixner21633982018-04-22 18:23:53 +0200355int encode_rs16(struct rs_control *rsc, uint16_t *data, int len, uint16_t *par,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 uint16_t invmsk)
357{
358#include "encode_rs.c"
359}
360EXPORT_SYMBOL_GPL(encode_rs16);
361#endif
362
363#ifdef CONFIG_REED_SOLOMON_DEC16
Thomas Gleixner03ead842005-11-07 11:15:37 +0000364/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 * decode_rs16 - Decode codeword (16bit data width)
Thomas Gleixner21633982018-04-22 18:23:53 +0200366 * @rsc: the rs control structure
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 * @data: data field of a given type
368 * @par: received parity data field
369 * @len: data length
370 * @s: syndrome data field (if NULL, syndrome is calculated)
371 * @no_eras: number of erasures
372 * @eras_pos: position of erasures, can be NULL
Thomas Gleixner03ead842005-11-07 11:15:37 +0000373 * @invmsk: invert data mask (will be xored on data, not on parity!)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 * @corr: buffer to store correction bitmask on eras_pos
375 *
376 * Each field in the data array contains up to symbol size bits of valid data.
Jörn Engeleb684502007-10-20 23:16:32 +0200377 * Returns the number of corrected bits or -EBADMSG for uncorrectable errors.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 */
Thomas Gleixner21633982018-04-22 18:23:53 +0200379int decode_rs16(struct rs_control *rsc, uint16_t *data, uint16_t *par, int len,
Thomas Gleixner03ead842005-11-07 11:15:37 +0000380 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 uint16_t *corr)
382{
383#include "decode_rs.c"
384}
385EXPORT_SYMBOL_GPL(decode_rs16);
386#endif
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388MODULE_LICENSE("GPL");
389MODULE_DESCRIPTION("Reed Solomon encoder/decoder");
390MODULE_AUTHOR("Phil Karn, Thomas Gleixner");
391