Lines Matching +full:k +full:- +full:to +full:- +full:j
1 // SPDX-License-Identifier: GPL-2.0
8 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de)
13 struct rs_codec *rs = rsc->codec;
15 int i, j, r, k, pad; variable
16 int nn = rs->nn;
17 int nroots = rs->nroots;
18 int fcr = rs->fcr;
19 int prim = rs->prim;
20 int iprim = rs->iprim;
21 uint16_t *alpha_to = rs->alpha_to;
22 uint16_t *index_of = rs->index_of;
26 uint16_t msk = (uint16_t) rs->nn;
32 uint16_t *lambda = rsc->buffers + RS_DECODE_LAMBDA * (nroots + 1);
33 uint16_t *syn = rsc->buffers + RS_DECODE_SYN * (nroots + 1);
34 uint16_t *b = rsc->buffers + RS_DECODE_B * (nroots + 1);
35 uint16_t *t = rsc->buffers + RS_DECODE_T * (nroots + 1);
36 uint16_t *omega = rsc->buffers + RS_DECODE_OMEGA * (nroots + 1);
37 uint16_t *root = rsc->buffers + RS_DECODE_ROOT * (nroots + 1);
38 uint16_t *reg = rsc->buffers + RS_DECODE_REG * (nroots + 1);
39 uint16_t *loc = rsc->buffers + RS_DECODE_LOC * (nroots + 1);
42 pad = nn - nroots - len;
43 BUG_ON(pad < 0 || pad >= nn - nroots);
55 /* syndrome is zero, no errors to correct */
64 for (j = 1; j < len; j++) {
67 syn[i] = (((uint16_t) data[j]) ^
70 syn[i] = ((((uint16_t) data[j]) ^
78 for (j = 0; j < nroots; j++) {
81 syn[i] = ((uint16_t) par[j]) & msk;
83 syn[i] = (((uint16_t) par[j]) & msk) ^
91 /* Convert syndromes to index form, checking for nonzero condition */
100 * errors to correct. So return data[] unmodified
110 /* Init lambda to be the erasure locator polynomial */
112 prim * (nn - 1 - (eras_pos[0] + pad)))];
114 u = rs_modnn(rs, prim * (nn - 1 - (eras_pos[i] + pad)));
115 for (j = i + 1; j > 0; j--) {
116 tmp = index_of[lambda[j - 1]];
118 lambda[j] ^=
129 * Begin Berlekamp-Massey algorithm to determine error+erasure
135 /* Compute discrepancy at the r-th step in poly-form */
138 if ((lambda[i] != 0) && (s[r - i - 1] != nn)) {
142 s[r - i - 1])];
147 /* 2 lines below: B(x) <-- x*B(x) */
151 /* 7 lines below: T(x) <-- lambda(x)-discr_r*x*b(x) */
161 if (2 * el <= r + no_eras - 1) {
162 el = r + no_eras - el;
164 * 2 lines below: B(x) <-- inv(discr_r) *
170 - discr_r + nn);
173 /* 2 lines below: B(x) <-- x*B(x) */
181 /* Convert lambda to index form and compute deg(lambda(x)) */
191 * deg(lambda) is zero even though the syndrome is non-zero
194 return -EBADMSG;
200 for (i = 1, k = iprim - 1; i <= nn; i++, k = rs_modnn(rs, k + iprim)) {
202 for (j = deg_lambda; j > 0; j--) {
203 if (reg[j] != nn) {
204 reg[j] = rs_modnn(rs, reg[j] + j);
205 q ^= alpha_to[reg[j]];
211 if (k < pad) {
213 return -EBADMSG;
216 /* store root (index-form) and error location number */
218 loc[count] = k;
220 * abort the search to save time
227 * deg(lambda) unequal to number of roots => uncorrectable
230 return -EBADMSG;
236 deg_omega = deg_lambda - 1;
239 for (j = i; j >= 0; j--) {
240 if ((s[i - j] != nn) && (lambda[j] != nn))
242 alpha_to[rs_modnn(rs, s[i - j] + lambda[j])];
248 * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 =
249 * inv(X(l))**(fcr-1) and den = lambda_pr(inv(X(l))) all in poly-form
250 * Note: we reuse the buffer for b to store the correction pattern
253 for (j = count - 1; j >= 0; j--) {
255 for (i = deg_omega; i >= 0; i--) {
258 i * root[j])];
262 /* Nothing to correct at this position */
263 b[j] = 0;
267 num2 = alpha_to[rs_modnn(rs, root[j] * (fcr - 1) + nn)];
272 for (i = min(deg_lambda, nroots - 1) & ~1; i >= 0; i -= 2) {
275 i * root[j])];
279 b[j] = alpha_to[rs_modnn(rs, index_of[num1] +
281 nn - index_of[den])];
291 for (j = 0; j < count; j++) {
292 if (b[j] == 0)
295 k = (fcr + i) * prim * (nn-loc[j]-1);
296 tmp ^= alpha_to[rs_modnn(rs, index_of[b[j]] + k)];
300 return -EBADMSG;
308 j = 0;
311 corr[j] = b[i];
312 eras_pos[j++] = loc[i] - pad;
316 /* Apply error to data and parity */
318 if (loc[i] < (nn - nroots))
319 data[loc[i] - pad] ^= b[i];
321 par[loc[i] - pad - len] ^= b[i];