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

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

Version: ~ [ linux-4.20-rc2 ] ~ [ linux-4.19.1 ] ~ [ linux-4.18.18 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.80 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.136 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.163 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.125 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.60 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.31.14 ] ~ [ linux-2.6.30.10 ] ~ [ linux-2.6.29.6 ] ~ [ linux-2.6.28.10 ] ~ [ linux-2.6.27.62 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ 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/list.h>
 14 #include <linux/types.h>        /* for gfp_t */
 15 #include <linux/gfp.h>          /* for GFP_KERNEL */
 16 
 17 /**
 18  * struct rs_codec - rs codec data
 19  *
 20  * @mm:         Bits per symbol
 21  * @nn:         Symbols per block (= (1<<mm)-1)
 22  * @alpha_to:   log lookup table
 23  * @index_of:   Antilog lookup table
 24  * @genpoly:    Generator polynomial
 25  * @nroots:     Number of generator roots = number of parity symbols
 26  * @fcr:        First consecutive root, index form
 27  * @prim:       Primitive element, index form
 28  * @iprim:      prim-th root of 1, index form
 29  * @gfpoly:     The primitive generator polynominal
 30  * @gffunc:     Function to generate the field, if non-canonical representation
 31  * @users:      Users of this structure
 32  * @list:       List entry for the rs codec list
 33 */
 34 struct rs_codec {
 35         int             mm;
 36         int             nn;
 37         uint16_t        *alpha_to;
 38         uint16_t        *index_of;
 39         uint16_t        *genpoly;
 40         int             nroots;
 41         int             fcr;
 42         int             prim;
 43         int             iprim;
 44         int             gfpoly;
 45         int             (*gffunc)(int);
 46         int             users;
 47         struct list_head list;
 48 };
 49 
 50 /**
 51  * struct rs_control - rs control structure per instance
 52  * @codec:      The codec used for this instance
 53  * @buffers:    Internal scratch buffers used in calls to decode_rs()
 54  */
 55 struct rs_control {
 56         struct rs_codec *codec;
 57         uint16_t        buffers[0];
 58 };
 59 
 60 /* General purpose RS codec, 8-bit data width, symbol width 1-15 bit  */
 61 #ifdef CONFIG_REED_SOLOMON_ENC8
 62 int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par,
 63                uint16_t invmsk);
 64 #endif
 65 #ifdef CONFIG_REED_SOLOMON_DEC8
 66 int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len,
 67                 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
 68                uint16_t *corr);
 69 #endif
 70 
 71 /* General purpose RS codec, 16-bit data width, symbol width 1-15 bit  */
 72 #ifdef CONFIG_REED_SOLOMON_ENC16
 73 int encode_rs16(struct rs_control *rs, uint16_t *data, int len, uint16_t *par,
 74                 uint16_t invmsk);
 75 #endif
 76 #ifdef CONFIG_REED_SOLOMON_DEC16
 77 int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len,
 78                 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
 79                 uint16_t *corr);
 80 #endif
 81 
 82 struct rs_control *init_rs_gfp(int symsize, int gfpoly, int fcr, int prim,
 83                                int nroots, gfp_t gfp);
 84 
 85 /**
 86  * init_rs - Create a RS control struct and initialize it
 87  *  @symsize:   the symbol size (number of bits)
 88  *  @gfpoly:    the extended Galois field generator polynomial coefficients,
 89  *              with the 0th coefficient in the low order bit. The polynomial
 90  *              must be primitive;
 91  *  @fcr:       the first consecutive root of the rs code generator polynomial
 92  *              in index form
 93  *  @prim:      primitive element to generate polynomial roots
 94  *  @nroots:    RS code generator polynomial degree (number of roots)
 95  *
 96  * Allocations use GFP_KERNEL.
 97  */
 98 static inline struct rs_control *init_rs(int symsize, int gfpoly, int fcr,
 99                                          int prim, int nroots)
100 {
101         return init_rs_gfp(symsize, gfpoly, fcr, prim, nroots, GFP_KERNEL);
102 }
103 
104 struct rs_control *init_rs_non_canonical(int symsize, int (*func)(int),
105                                          int fcr, int prim, int nroots);
106 
107 /* Release a rs control structure */
108 void free_rs(struct rs_control *rs);
109 
110 /** modulo replacement for galois field arithmetics
111  *
112  *  @rs:        Pointer to the RS codec
113  *  @x:         the value to reduce
114  *
115  *  where
116  *  rs->mm = number of bits per symbol
117  *  rs->nn = (2^rs->mm) - 1
118  *
119  *  Simple arithmetic modulo would return a wrong result for values
120  *  >= 3 * rs->nn
121 */
122 static inline int rs_modnn(struct rs_codec *rs, int x)
123 {
124         while (x >= rs->nn) {
125                 x -= rs->nn;
126                 x = (x >> rs->mm) + (x & rs->nn);
127         }
128         return x;
129 }
130 
131 #endif
132 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp