^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Generic Reed Solomon encoder / decoder library
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2002, Phil Karn, KA9Q
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * May be used under the terms of the GNU General Public License (GPL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Generic data width independent code which is included by the wrappers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct rs_codec *rs = rsc->codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) int i, j, pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) int nn = rs->nn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) int nroots = rs->nroots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) uint16_t *alpha_to = rs->alpha_to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) uint16_t *index_of = rs->index_of;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) uint16_t *genpoly = rs->genpoly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) uint16_t fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) uint16_t msk = (uint16_t) rs->nn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /* Check length parameter for validity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) pad = nn - nroots - len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) if (pad < 0 || pad >= nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) for (i = 0; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) fb = index_of[((((uint16_t) data[i])^invmsk) & msk) ^ par[0]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* feedback term is non-zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (fb != nn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) for (j = 1; j < nroots; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) par[j] ^= alpha_to[rs_modnn(rs, fb +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) genpoly[nroots - j])];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Shift */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) memmove(&par[0], &par[1], sizeof(uint16_t) * (nroots - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (fb != nn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) par[nroots - 1] = alpha_to[rs_modnn(rs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) fb + genpoly[0])];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) par[nroots - 1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }