Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Generic Reed Solomon encoder / decoder library
0004  *
0005  * Copyright 2002, Phil Karn, KA9Q
0006  * May be used under the terms of the GNU General Public License (GPL)
0007  *
0008  * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de)
0009  *
0010  * Generic data width independent code which is included by the wrappers.
0011  */
0012 {
0013     struct rs_codec *rs = rsc->codec;
0014     int i, j, pad;
0015     int nn = rs->nn;
0016     int nroots = rs->nroots;
0017     uint16_t *alpha_to = rs->alpha_to;
0018     uint16_t *index_of = rs->index_of;
0019     uint16_t *genpoly = rs->genpoly;
0020     uint16_t fb;
0021     uint16_t msk = (uint16_t) rs->nn;
0022 
0023     /* Check length parameter for validity */
0024     pad = nn - nroots - len;
0025     if (pad < 0 || pad >= nn)
0026         return -ERANGE;
0027 
0028     for (i = 0; i < len; i++) {
0029         fb = index_of[((((uint16_t) data[i])^invmsk) & msk) ^ par[0]];
0030         /* feedback term is non-zero */
0031         if (fb != nn) {
0032             for (j = 1; j < nroots; j++) {
0033                 par[j] ^= alpha_to[rs_modnn(rs, fb +
0034                              genpoly[nroots - j])];
0035             }
0036         }
0037         /* Shift */
0038         memmove(&par[0], &par[1], sizeof(uint16_t) * (nroots - 1));
0039         if (fb != nn) {
0040             par[nroots - 1] = alpha_to[rs_modnn(rs,
0041                                 fb + genpoly[0])];
0042         } else {
0043             par[nroots - 1] = 0;
0044         }
0045     }
0046     return 0;
0047 }