2 * include/linux/rslib.h
5 * Generic Reed Solomon encoder / decoder library
7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
9 * RS code lifted from reed solomon library written by Phil Karn
10 * Copyright 2002 Phil Karn, KA9Q
12 * $Id: rslib.h,v 1.3 2004/10/05 22:08:22 gleixner Exp $
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
22 #include <linux/list.h>
25 * struct rs_control - rs control structure
27 * @mm: Bits per symbol
28 * @nn: Symbols per block (= (1<<mm)-1)
29 * @alpha_to: log lookup table
30 * @index_of: Antilog lookup table
31 * @genpoly: Generator polynomial
32 * @nroots: Number of generator roots = number of parity symbols
33 * @fcr: First consecutive root, index form
34 * @prim: Primitive element, index form
35 * @iprim: prim-th root of 1, index form
36 * @gfpoly: The primitive generator polynominal
37 * @users: Users of this structure
38 * @list: List entry for the rs control list
52 struct list_head list
;
55 /* General purpose RS codec, 8-bit data width, symbol width 1-15 bit */
56 #ifdef CONFIG_REED_SOLOMON_ENC8
57 int encode_rs8(struct rs_control
*rs
, uint8_t *data
, int len
, uint16_t *par
,
60 #ifdef CONFIG_REED_SOLOMON_DEC8
61 int decode_rs8(struct rs_control
*rs
, uint8_t *data
, uint16_t *par
, int len
,
62 uint16_t *s
, int no_eras
, int *eras_pos
, uint16_t invmsk
,
66 /* General purpose RS codec, 16-bit data width, symbol width 1-15 bit */
67 #ifdef CONFIG_REED_SOLOMON_ENC16
68 int encode_rs16(struct rs_control
*rs
, uint16_t *data
, int len
, uint16_t *par
,
71 #ifdef CONFIG_REED_SOLOMON_DEC16
72 int decode_rs16(struct rs_control
*rs
, uint16_t *data
, uint16_t *par
, int len
,
73 uint16_t *s
, int no_eras
, int *eras_pos
, uint16_t invmsk
,
77 /* Create or get a matching rs control structure */
78 struct rs_control
*init_rs(int symsize
, int gfpoly
, int fcr
, int prim
,
81 /* Release a rs control structure */
82 void free_rs(struct rs_control
*rs
);
84 /** modulo replacement for galois field arithmetics
86 * @rs: the rs control structure
87 * @x: the value to reduce
90 * rs->mm = number of bits per symbol
91 * rs->nn = (2^rs->mm) - 1
93 * Simple arithmetic modulo would return a wrong result for values
96 static inline int rs_modnn(struct rs_control
*rs
, int x
)
100 x
= (x
>> rs
->mm
) + (x
& rs
->nn
);