~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/rslib.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Generic Reed Solomon encoder / decoder library
  4  *
  5  * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
  6  *
  7  * RS code lifted from reed solomon library written by Phil Karn
  8  * Copyright 2002 Phil Karn, KA9Q
  9  */
 10 #ifndef _RSLIB_H_
 11 #define _RSLIB_H_
 12 
 13 #include <linux/types.h>        /* for gfp_t */
 14 #include <linux/gfp.h>          /* for GFP_KERNEL */
 15 
 16 /**
 17  * struct rs_codec - rs codec data
 18  *
 19  * @mm:         Bits per symbol
 20  * @nn:         Symbols per block (= (1<<mm)-1)
 21  * @alpha_to:   log lookup table
 22  * @index_of:   Antilog lookup table
 23  * @genpoly:    Generator polynomial
 24  * @nroots:     Number of generator roots = number of parity symbols
 25  * @fcr:        First consecutive root, index form
 26  * @prim:       Primitive element, index form
 27  * @iprim:      prim-th root of 1, index form
 28  * @gfpoly:     The primitive generator polynominal
 29  * @gffunc:     Function to generate the field, if non-canonical representation
 30  * @users:      Users of this structure
 31  * @list:       List entry for the rs codec list
 32 */
 33 struct rs_codec {
 34         int             mm;
 35         int             nn;
 36         uint16_t        *alpha_to;
 37         uint16_t        *index_of;
 38         uint16_t        *genpoly;
 39         int             nroots;
 40         int             fcr;
 41         int             prim;
 42         int             iprim;
 43         int             gfpoly;
 44         int             (*gffunc)(int);
 45         int             users;
 46         struct list_head list;
 47 };
 48 
 49 /**
 50  * struct rs_control - rs control structure per instance
 51  * @codec:      The codec used for this instance
 52  * @buffers:    Internal scratch buffers used in calls to decode_rs()
 53  */
 54 struct rs_control {
 55         struct rs_codec *codec;
 56         uint16_t        buffers[];
 57 };
 58 
 59 /* General purpose RS codec, 8-bit data width, symbol width 1-15 bit  */
 60 #ifdef CONFIG_REED_SOLOMON_ENC8
 61 int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par,
 62                uint16_t invmsk);
 63 #endif
 64 #ifdef CONFIG_REED_SOLOMON_DEC8
 65 int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len,
 66                 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
 67                uint16_t *corr);
 68 #endif
 69 
 70 /* General purpose RS codec, 16-bit data width, symbol width 1-15 bit  */
 71 #ifdef CONFIG_REED_SOLOMON_ENC16
 72 int encode_rs16(struct rs_control *rs, uint16_t *data, int len, uint16_t *par,
 73                 uint16_t invmsk);
 74 #endif
 75 #ifdef CONFIG_REED_SOLOMON_DEC16
 76 int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len,
 77                 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
 78                 uint16_t *corr);
 79 #endif
 80 
 81 struct rs_control *init_rs_gfp(int symsize, int gfpoly, int fcr, int prim,
 82                                int nroots, gfp_t gfp);
 83 
 84 /**
 85  * init_rs - Create a RS control struct and initialize it
 86  *  @symsize:   the symbol size (number of bits)
 87  *  @gfpoly:    the extended Galois field generator polynomial coefficients,
 88  *              with the 0th coefficient in the low order bit. The polynomial
 89  *              must be primitive;
 90  *  @fcr:       the first consecutive root of the rs code generator polynomial
 91  *              in index form
 92  *  @prim:      primitive element to generate polynomial roots
 93  *  @nroots:    RS code generator polynomial degree (number of roots)
 94  *
 95  * Allocations use GFP_KERNEL.
 96  */
 97 static inline struct rs_control *init_rs(int symsize, int gfpoly, int fcr,
 98                                          int prim, int nroots)
 99 {
100         return init_rs_gfp(symsize, gfpoly, fcr, prim, nroots, GFP_KERNEL);
101 }
102 
103 struct rs_control *init_rs_non_canonical(int symsize, int (*func)(int),
104                                          int fcr, int prim, int nroots);
105 
106 /* Release a rs control structure */
107 void free_rs(struct rs_control *rs);
108 
109 /** modulo replacement for galois field arithmetics
110  *
111  *  @rs:        Pointer to the RS codec
112  *  @x:         the value to reduce
113  *
114  *  where
115  *  rs->mm = number of bits per symbol
116  *  rs->nn = (2^rs->mm) - 1
117  *
118  *  Simple arithmetic modulo would return a wrong result for values
119  *  >= 3 * rs->nn
120 */
121 static inline int rs_modnn(struct rs_codec *rs, int x)
122 {
123         while (x >= rs->nn) {
124                 x -= rs->nn;
125                 x = (x >> rs->mm) + (x & rs->nn);
126         }
127         return x;
128 }
129 
130 #endif
131 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php