···11-/* 11+/*22 * include/linux/rslib.h33 *44 * Overview:55 * Generic Reed Solomon encoder / decoder library66- * 66+ *77 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)88 *99 * RS code lifted from reed solomon library written by Phil Karn1010 * Copyright 2002 Phil Karn, KA9Q1111 *1212- * $Id: rslib.h,v 1.3 2004/10/05 22:08:22 gleixner Exp $1212+ * $Id: rslib.h,v 1.4 2005/11/07 11:14:52 gleixner Exp $1313 *1414 * This program is free software; you can redistribute it and/or modify1515 * it under the terms of the GNU General Public License version 2 as···21212222#include <linux/list.h>23232424-/** 2424+/**2525 * struct rs_control - rs control structure2626- * 2626+ *2727 * @mm: Bits per symbol2828 * @nn: Symbols per block (= (1<<mm)-1)2929 * @alpha_to: log lookup table3030 * @index_of: Antilog lookup table3131- * @genpoly: Generator polynomial 3131+ * @genpoly: Generator polynomial3232 * @nroots: Number of generator roots = number of parity symbols3333 * @fcr: First consecutive root, index form3434- * @prim: Primitive element, index form 3535- * @iprim: prim-th root of 1, index form 3636- * @gfpoly: The primitive generator polynominal 3737- * @users: Users of this structure 3434+ * @prim: Primitive element, index form3535+ * @iprim: prim-th root of 1, index form3636+ * @gfpoly: The primitive generator polynominal3737+ * @users: Users of this structure3838 * @list: List entry for the rs control list3939*/4040struct rs_control {···5858 uint16_t invmsk);5959#endif6060#ifdef CONFIG_REED_SOLOMON_DEC86161-int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len, 6161+int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len,6262 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,6363 uint16_t *corr);6464#endif···7575#endif76767777/* Create or get a matching rs control structure */7878-struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim, 7878+struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim,7979 int nroots);80808181/* Release a rs control structure */···8787 * @x: the value to reduce8888 *8989 * where9090- * rs->mm = number of bits per symbol 9090+ * rs->mm = number of bits per symbol9191 * rs->nn = (2^rs->mm) - 19292- * 9292+ *9393 * Simple arithmetic modulo would return a wrong result for values9494 * >= 3 * rs->nn9595*/
+1-1
lib/reed_solomon/Makefile
···11#22-# This is a modified version of reed solomon lib, 22+# This is a modified version of reed solomon lib,33#4455obj-$(CONFIG_REED_SOLOMON) += reed_solomon.o
+18-18
lib/reed_solomon/decode_rs.c
···11-/* 11+/*22 * lib/reed_solomon/decode_rs.c33 *44 * Overview:55 * Generic Reed Solomon encoder / decoder library66- * 66+ *77 * Copyright 2002, Phil Karn, KA9Q88 * May be used under the terms of the GNU General Public License (GPL)99 *1010 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de)1111 *1212- * $Id: decode_rs.c,v 1.6 2004/10/22 15:41:47 gleixner Exp $1212+ * $Id: decode_rs.c,v 1.7 2005/11/07 11:14:59 gleixner Exp $1313 *1414 */15151616-/* Generic data width independent code which is included by the 1616+/* Generic data width independent code which is included by the1717 * wrappers.1818 */1919-{ 1919+{2020 int deg_lambda, el, deg_omega;2121 int i, j, r, k, pad;2222 int nn = rs->nn;···4141 pad = nn - nroots - len;4242 if (pad < 0 || pad >= nn)4343 return -ERANGE;4444-4444+4545 /* Does the caller provide the syndrome ? */4646- if (s != NULL) 4646+ if (s != NULL)4747 goto decode;48484949 /* form the syndromes; i.e., evaluate data(x) at roots of···5454 for (j = 1; j < len; j++) {5555 for (i = 0; i < nroots; i++) {5656 if (syn[i] == 0) {5757- syn[i] = (((uint16_t) data[j]) ^ 5757+ syn[i] = (((uint16_t) data[j]) ^5858 invmsk) & msk;5959 } else {6060 syn[i] = ((((uint16_t) data[j]) ^6161- invmsk) & msk) ^ 6161+ invmsk) & msk) ^6262 alpha_to[rs_modnn(rs, index_of[syn[i]] +6363 (fcr + i) * prim)];6464 }···7070 if (syn[i] == 0) {7171 syn[i] = ((uint16_t) par[j]) & msk;7272 } else {7373- syn[i] = (((uint16_t) par[j]) & msk) ^ 7373+ syn[i] = (((uint16_t) par[j]) & msk) ^7474 alpha_to[rs_modnn(rs, index_of[syn[i]] +7575 (fcr+i)*prim)];7676 }···9999100100 if (no_eras > 0) {101101 /* Init lambda to be the erasure locator polynomial */102102- lambda[1] = alpha_to[rs_modnn(rs, 102102+ lambda[1] = alpha_to[rs_modnn(rs,103103 prim * (nn - 1 - eras_pos[0]))];104104 for (i = 1; i < no_eras; i++) {105105 u = rs_modnn(rs, prim * (nn - 1 - eras_pos[i]));106106 for (j = i + 1; j > 0; j--) {107107 tmp = index_of[lambda[j - 1]];108108 if (tmp != nn) {109109- lambda[j] ^= 109109+ lambda[j] ^=110110 alpha_to[rs_modnn(rs, u + tmp)];111111 }112112 }···127127 discr_r = 0;128128 for (i = 0; i < r; i++) {129129 if ((lambda[i] != 0) && (s[r - i - 1] != nn)) {130130- discr_r ^= 131131- alpha_to[rs_modnn(rs, 130130+ discr_r ^=131131+ alpha_to[rs_modnn(rs,132132 index_of[lambda[i]] +133133 s[r - i - 1])];134134 }···143143 t[0] = lambda[0];144144 for (i = 0; i < nroots; i++) {145145 if (b[i] != nn) {146146- t[i + 1] = lambda[i + 1] ^ 146146+ t[i + 1] = lambda[i + 1] ^147147 alpha_to[rs_modnn(rs, discr_r +148148 b[i])];149149 } else···229229 num1 = 0;230230 for (i = deg_omega; i >= 0; i--) {231231 if (omega[i] != nn)232232- num1 ^= alpha_to[rs_modnn(rs, omega[i] + 232232+ num1 ^= alpha_to[rs_modnn(rs, omega[i] +233233 i * root[j])];234234 }235235 num2 = alpha_to[rs_modnn(rs, root[j] * (fcr - 1) + nn)];···239239 * lambda_pr of lambda[i] */240240 for (i = min(deg_lambda, nroots - 1) & ~1; i >= 0; i -= 2) {241241 if (lambda[i + 1] != nn) {242242- den ^= alpha_to[rs_modnn(rs, lambda[i + 1] + 242242+ den ^= alpha_to[rs_modnn(rs, lambda[i + 1] +243243 i * root[j])];244244 }245245 }246246 /* Apply error to data */247247 if (num1 != 0 && loc[j] >= pad) {248248- uint16_t cor = alpha_to[rs_modnn(rs,index_of[num1] + 248248+ uint16_t cor = alpha_to[rs_modnn(rs,index_of[num1] +249249 index_of[num2] +250250 nn - index_of[den])];251251 /* Store the error correction pattern, if a
+7-7
lib/reed_solomon/encode_rs.c
···11-/* 11+/*22 * lib/reed_solomon/encode_rs.c33 *44 * Overview:55 * Generic Reed Solomon encoder / decoder library66- * 66+ *77 * Copyright 2002, Phil Karn, KA9Q88 * May be used under the terms of the GNU General Public License (GPL)99 *1010 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de)1111 *1212- * $Id: encode_rs.c,v 1.4 2004/10/22 15:41:47 gleixner Exp $1212+ * $Id: encode_rs.c,v 1.5 2005/11/07 11:14:59 gleixner Exp $1313 *1414 */15151616-/* Generic data width independent code which is included by the 1616+/* Generic data width independent code which is included by the1717 * wrappers.1818 * int encode_rsX (struct rs_control *rs, uintX_t *data, int len, uintY_t *par)1919 */···3535 for (i = 0; i < len; i++) {3636 fb = index_of[((((uint16_t) data[i])^invmsk) & msk) ^ par[0]];3737 /* feedback term is non-zero */3838- if (fb != nn) { 3838+ if (fb != nn) {3939 for (j = 1; j < nroots; j++) {4040- par[j] ^= alpha_to[rs_modnn(rs, fb + 4040+ par[j] ^= alpha_to[rs_modnn(rs, fb +4141 genpoly[nroots - j])];4242 }4343 }4444 /* Shift */4545 memmove(&par[0], &par[1], sizeof(uint16_t) * (nroots - 1));4646 if (fb != nn) {4747- par[nroots - 1] = alpha_to[rs_modnn(rs, 4747+ par[nroots - 1] = alpha_to[rs_modnn(rs,4848 fb + genpoly[0])];4949 } else {5050 par[nroots - 1] = 0;
+32-32
lib/reed_solomon/reed_solomon.c
···11-/* 11+/*22 * lib/reed_solomon/rslib.c33 *44 * Overview:55 * Generic Reed Solomon encoder / decoder library66- * 66+ *77 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)88 *99 * Reed Solomon code lifted from reed solomon library written by Phil Karn1010 * Copyright 2002 Phil Karn, KA9Q1111 *1212- * $Id: rslib.c,v 1.5 2004/10/22 15:41:47 gleixner Exp $1212+ * $Id: rslib.c,v 1.7 2005/11/07 11:14:59 gleixner Exp $1313 *1414 * This program is free software; you can redistribute it and/or modify1515 * it under the terms of the GNU General Public License version 2 as1616 * published by the Free Software Foundation.1717 *1818 * Description:1919- * 1919+ *2020 * The generic Reed Solomon library provides runtime configurable2121 * encoding / decoding of RS codes.2222 * Each user must call init_rs to get a pointer to a rs_control···2525 * If a structure is generated then the polynomial arrays for2626 * fast encoding / decoding are built. This can take some time so2727 * make sure not to call this function from a time critical path.2828- * Usually a module / driver should initialize the necessary 2828+ * Usually a module / driver should initialize the necessary2929 * rs_control structure on module / driver init and release it3030 * on exit.3131- * The encoding puts the calculated syndrome into a given syndrome 3232- * buffer. 3131+ * The encoding puts the calculated syndrome into a given syndrome3232+ * buffer.3333 * The decoding is a two step process. The first step calculates3434 * the syndrome over the received (data + syndrome) and calls the3535 * second stage, which does the decoding / error correction itself.···5151/* Protection for the list */5252static DECLARE_MUTEX(rslistlock);53535454-/** 5454+/**5555 * rs_init - Initialize a Reed-Solomon codec5656 *5757 * @symsize: symbol size, bits (1-8)···6363 * Allocate a control structure and the polynom arrays for faster6464 * en/decoding. Fill the arrays according to the given parameters6565 */6666-static struct rs_control *rs_init(int symsize, int gfpoly, int fcr, 6666+static struct rs_control *rs_init(int symsize, int gfpoly, int fcr,6767 int prim, int nroots)6868{6969 struct rs_control *rs;···124124 /* Multiply rs->genpoly[] by @**(root + x) */125125 for (j = i; j > 0; j--) {126126 if (rs->genpoly[j] != 0) {127127- rs->genpoly[j] = rs->genpoly[j -1] ^ 128128- rs->alpha_to[rs_modnn(rs, 127127+ rs->genpoly[j] = rs->genpoly[j -1] ^128128+ rs->alpha_to[rs_modnn(rs,129129 rs->index_of[rs->genpoly[j]] + root)];130130 } else131131 rs->genpoly[j] = rs->genpoly[j - 1];132132 }133133 /* rs->genpoly[0] can never be zero */134134- rs->genpoly[0] = 135135- rs->alpha_to[rs_modnn(rs, 134134+ rs->genpoly[0] =135135+ rs->alpha_to[rs_modnn(rs,136136 rs->index_of[rs->genpoly[0]] + root)];137137 }138138 /* convert rs->genpoly[] to index form for quicker encoding */···153153}154154155155156156-/** 156156+/**157157 * free_rs - Free the rs control structure, if its not longer used158158 *159159 * @rs: the control structure which is not longer used by the···173173 up(&rslistlock);174174}175175176176-/** 176176+/**177177 * init_rs - Find a matching or allocate a new rs control structure178178 *179179 * @symsize: the symbol size (number of bits)180180 * @gfpoly: the extended Galois field generator polynomial coefficients,181181 * with the 0th coefficient in the low order bit. The polynomial182182 * must be primitive;183183- * @fcr: the first consecutive root of the rs code generator polynomial 183183+ * @fcr: the first consecutive root of the rs code generator polynomial184184 * in index form185185 * @prim: primitive element to generate polynomial roots186186 * @nroots: RS code generator polynomial degree (number of roots)187187 */188188-struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim, 188188+struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim,189189 int nroots)190190{191191 struct list_head *tmp;···198198 return NULL;199199 if (prim <= 0 || prim >= (1<<symsize))200200 return NULL;201201- if (nroots < 0 || nroots >= (1<<symsize) || nroots > 8)201201+ if (nroots < 0 || nroots >= (1<<symsize))202202 return NULL;203203-203203+204204 down(&rslistlock);205205206206 /* Walk through the list and look for a matching entry */···211211 if (gfpoly != rs->gfpoly)212212 continue;213213 if (fcr != rs->fcr)214214- continue; 214214+ continue;215215 if (prim != rs->prim)216216- continue; 216216+ continue;217217 if (nroots != rs->nroots)218218 continue;219219 /* We have a matching one already */···227227 rs->users = 1;228228 list_add(&rs->list, &rslist);229229 }230230-out: 230230+out:231231 up(&rslistlock);232232 return rs;233233}234234235235#ifdef CONFIG_REED_SOLOMON_ENC8236236-/** 236236+/**237237 * encode_rs8 - Calculate the parity for data values (8bit data width)238238 *239239 * @rs: the rs control structure240240 * @data: data field of a given type241241- * @len: data length 241241+ * @len: data length242242 * @par: parity data, must be initialized by caller (usually all 0)243243 * @invmsk: invert data mask (will be xored on data)244244 *···246246 * symbol size > 8. The calling code must take care of encoding of the247247 * syndrome result for storage itself.248248 */249249-int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par, 249249+int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par,250250 uint16_t invmsk)251251{252252#include "encode_rs.c"···255255#endif256256257257#ifdef CONFIG_REED_SOLOMON_DEC8258258-/** 258258+/**259259 * decode_rs8 - Decode codeword (8bit data width)260260 *261261 * @rs: the rs control structure···273273 * syndrome result and the received parity before calling this code.274274 */275275int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len,276276- uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, 276276+ uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,277277 uint16_t *corr)278278{279279#include "decode_rs.c"···287287 *288288 * @rs: the rs control structure289289 * @data: data field of a given type290290- * @len: data length 290290+ * @len: data length291291 * @par: parity data, must be initialized by caller (usually all 0)292292 * @invmsk: invert data mask (will be xored on data, not on parity!)293293 *294294 * Each field in the data array contains up to symbol size bits of valid data.295295 */296296-int encode_rs16(struct rs_control *rs, uint16_t *data, int len, uint16_t *par, 296296+int encode_rs16(struct rs_control *rs, uint16_t *data, int len, uint16_t *par,297297 uint16_t invmsk)298298{299299#include "encode_rs.c"···302302#endif303303304304#ifdef CONFIG_REED_SOLOMON_DEC16305305-/** 305305+/**306306 * decode_rs16 - Decode codeword (16bit data width)307307 *308308 * @rs: the rs control structure···312312 * @s: syndrome data field (if NULL, syndrome is calculated)313313 * @no_eras: number of erasures314314 * @eras_pos: position of erasures, can be NULL315315- * @invmsk: invert data mask (will be xored on data, not on parity!) 315315+ * @invmsk: invert data mask (will be xored on data, not on parity!)316316 * @corr: buffer to store correction bitmask on eras_pos317317 *318318 * Each field in the data array contains up to symbol size bits of valid data.319319 */320320int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len,321321- uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, 321321+ uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,322322 uint16_t *corr)323323{324324#include "decode_rs.c"