···11-<?xml version="1.0" encoding="UTF-8"?>22-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"33- "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>44-55-<book id="Reed-Solomon-Library-Guide">66- <bookinfo>77- <title>Reed-Solomon Library Programming Interface</title>88-99- <authorgroup>1010- <author>1111- <firstname>Thomas</firstname>1212- <surname>Gleixner</surname>1313- <affiliation>1414- <address>1515- <email>tglx@linutronix.de</email>1616- </address>1717- </affiliation>1818- </author>1919- </authorgroup>2020-2121- <copyright>2222- <year>2004</year>2323- <holder>Thomas Gleixner</holder>2424- </copyright>2525-2626- <legalnotice>2727- <para>2828- This documentation is free software; you can redistribute2929- it and/or modify it under the terms of the GNU General Public3030- License version 2 as published by the Free Software Foundation.3131- </para>3232-3333- <para>3434- This program is distributed in the hope that it will be3535- useful, but WITHOUT ANY WARRANTY; without even the implied3636- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.3737- See the GNU General Public License for more details.3838- </para>3939-4040- <para>4141- You should have received a copy of the GNU General Public4242- License along with this program; if not, write to the Free4343- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,4444- MA 02111-1307 USA4545- </para>4646-4747- <para>4848- For more details see the file COPYING in the source4949- distribution of Linux.5050- </para>5151- </legalnotice>5252- </bookinfo>5353-5454-<toc></toc>5555-5656- <chapter id="intro">5757- <title>Introduction</title>5858- <para>5959- The generic Reed-Solomon Library provides encoding, decoding6060- and error correction functions.6161- </para>6262- <para>6363- Reed-Solomon codes are used in communication and storage6464- applications to ensure data integrity. 6565- </para>6666- <para>6767- This documentation is provided for developers who want to utilize6868- the functions provided by the library.6969- </para>7070- </chapter>7171-7272- <chapter id="bugs">7373- <title>Known Bugs And Assumptions</title>7474- <para>7575- None. 7676- </para>7777- </chapter>7878-7979- <chapter id="usage">8080- <title>Usage</title>8181- <para>8282- This chapter provides examples of how to use the library.8383- </para>8484- <sect1>8585- <title>Initializing</title>8686- <para>8787- The init function init_rs returns a pointer to an8888- rs decoder structure, which holds the necessary8989- information for encoding, decoding and error correction9090- with the given polynomial. It either uses an existing9191- matching decoder or creates a new one. On creation all9292- the lookup tables for fast en/decoding are created.9393- The function may take a while, so make sure not to 9494- call it in critical code paths.9595- </para>9696- <programlisting>9797-/* the Reed Solomon control structure */9898-static struct rs_control *rs_decoder;9999-100100-/* Symbolsize is 10 (bits)101101- * Primitive polynomial is x^10+x^3+1102102- * first consecutive root is 0103103- * primitive element to generate roots = 1104104- * generator polynomial degree (number of roots) = 6105105- */106106-rs_decoder = init_rs (10, 0x409, 0, 1, 6);107107- </programlisting>108108- </sect1>109109- <sect1>110110- <title>Encoding</title>111111- <para>112112- The encoder calculates the Reed-Solomon code over113113- the given data length and stores the result in 114114- the parity buffer. Note that the parity buffer must115115- be initialized before calling the encoder.116116- </para>117117- <para>118118- The expanded data can be inverted on the fly by119119- providing a non-zero inversion mask. The expanded data is120120- XOR'ed with the mask. This is used e.g. for FLASH121121- ECC, where the all 0xFF is inverted to an all 0x00.122122- The Reed-Solomon code for all 0x00 is all 0x00. The123123- code is inverted before storing to FLASH so it is 0xFF124124- too. This prevents that reading from an erased FLASH125125- results in ECC errors.126126- </para>127127- <para>128128- The databytes are expanded to the given symbol size129129- on the fly. There is no support for encoding continuous130130- bitstreams with a symbol size != 8 at the moment. If131131- it is necessary it should be not a big deal to implement132132- such functionality.133133- </para>134134- <programlisting>135135-/* Parity buffer. Size = number of roots */136136-uint16_t par[6];137137-/* Initialize the parity buffer */138138-memset(par, 0, sizeof(par));139139-/* Encode 512 byte in data8. Store parity in buffer par */140140-encode_rs8 (rs_decoder, data8, 512, par, 0);141141- </programlisting>142142- </sect1>143143- <sect1>144144- <title>Decoding</title>145145- <para>146146- The decoder calculates the syndrome over147147- the given data length and the received parity symbols148148- and corrects errors in the data.149149- </para>150150- <para>151151- If a syndrome is available from a hardware decoder152152- then the syndrome calculation is skipped.153153- </para>154154- <para>155155- The correction of the data buffer can be suppressed156156- by providing a correction pattern buffer and an error157157- location buffer to the decoder. The decoder stores the158158- calculated error location and the correction bitmask159159- in the given buffers. This is useful for hardware160160- decoders which use a weird bit ordering scheme.161161- </para>162162- <para>163163- The databytes are expanded to the given symbol size164164- on the fly. There is no support for decoding continuous165165- bitstreams with a symbolsize != 8 at the moment. If166166- it is necessary it should be not a big deal to implement167167- such functionality.168168- </para>169169-170170- <sect2>171171- <title>172172- Decoding with syndrome calculation, direct data correction173173- </title>174174- <programlisting>175175-/* Parity buffer. Size = number of roots */176176-uint16_t par[6];177177-uint8_t data[512];178178-int numerr;179179-/* Receive data */180180-.....181181-/* Receive parity */182182-.....183183-/* Decode 512 byte in data8.*/184184-numerr = decode_rs8 (rs_decoder, data8, par, 512, NULL, 0, NULL, 0, NULL);185185- </programlisting>186186- </sect2>187187-188188- <sect2>189189- <title>190190- Decoding with syndrome given by hardware decoder, direct data correction191191- </title>192192- <programlisting>193193-/* Parity buffer. Size = number of roots */194194-uint16_t par[6], syn[6];195195-uint8_t data[512];196196-int numerr;197197-/* Receive data */198198-.....199199-/* Receive parity */200200-.....201201-/* Get syndrome from hardware decoder */202202-.....203203-/* Decode 512 byte in data8.*/204204-numerr = decode_rs8 (rs_decoder, data8, par, 512, syn, 0, NULL, 0, NULL);205205- </programlisting>206206- </sect2>207207-208208- <sect2>209209- <title>210210- Decoding with syndrome given by hardware decoder, no direct data correction.211211- </title>212212- <para>213213- Note: It's not necessary to give data and received parity to the decoder.214214- </para>215215- <programlisting>216216-/* Parity buffer. Size = number of roots */217217-uint16_t par[6], syn[6], corr[8];218218-uint8_t data[512];219219-int numerr, errpos[8];220220-/* Receive data */221221-.....222222-/* Receive parity */223223-.....224224-/* Get syndrome from hardware decoder */225225-.....226226-/* Decode 512 byte in data8.*/227227-numerr = decode_rs8 (rs_decoder, NULL, NULL, 512, syn, 0, errpos, 0, corr);228228-for (i = 0; i < numerr; i++) {229229- do_error_correction_in_your_buffer(errpos[i], corr[i]);230230-}231231- </programlisting>232232- </sect2>233233- </sect1>234234- <sect1>235235- <title>Cleanup</title>236236- <para>237237- The function free_rs frees the allocated resources,238238- if the caller is the last user of the decoder.239239- </para>240240- <programlisting>241241-/* Release resources */242242-free_rs(rs_decoder);243243- </programlisting>244244- </sect1>245245-246246- </chapter>247247-248248- <chapter id="structs">249249- <title>Structures</title>250250- <para>251251- This chapter contains the autogenerated documentation of the structures which are252252- used in the Reed-Solomon Library and are relevant for a developer.253253- </para>254254-!Iinclude/linux/rslib.h255255- </chapter>256256-257257- <chapter id="pubfunctions">258258- <title>Public Functions Provided</title>259259- <para>260260- This chapter contains the autogenerated documentation of the Reed-Solomon functions261261- which are exported.262262- </para>263263-!Elib/reed_solomon/reed_solomon.c264264- </chapter>265265-266266- <chapter id="credits">267267- <title>Credits</title>268268- <para>269269- The library code for encoding and decoding was written by Phil Karn.270270- </para>271271- <programlisting>272272- Copyright 2002, Phil Karn, KA9Q273273- May be used under the terms of the GNU General Public License (GPL)274274- </programlisting>275275- <para>276276- The wrapper functions and interfaces are written by Thomas Gleixner.277277- </para>278278- <para>279279- Many users have provided bugfixes, improvements and helping hands for testing.280280- Thanks a lot.281281- </para>282282- <para>283283- The following people have contributed to this document:284284- </para>285285- <para>286286- Thomas Gleixner<email>tglx@linutronix.de</email>287287- </para>288288- </chapter>289289-</book>
+1
Documentation/core-api/index.rst
···1919 workqueue2020 genericirq2121 flexible-arrays2222+ librs22232324Interfaces for kernel debugging2425===============================
+212
Documentation/core-api/librs.rst
···11+==========================================22+Reed-Solomon Library Programming Interface33+==========================================44+55+:Author: Thomas Gleixner66+77+Introduction88+============99+1010+The generic Reed-Solomon Library provides encoding, decoding and error1111+correction functions.1212+1313+Reed-Solomon codes are used in communication and storage applications to1414+ensure data integrity.1515+1616+This documentation is provided for developers who want to utilize the1717+functions provided by the library.1818+1919+Known Bugs And Assumptions2020+==========================2121+2222+None.2323+2424+Usage2525+=====2626+2727+This chapter provides examples of how to use the library.2828+2929+Initializing3030+------------3131+3232+The init function init_rs returns a pointer to an rs decoder structure,3333+which holds the necessary information for encoding, decoding and error3434+correction with the given polynomial. It either uses an existing3535+matching decoder or creates a new one. On creation all the lookup tables3636+for fast en/decoding are created. The function may take a while, so make3737+sure not to call it in critical code paths.3838+3939+::4040+4141+ /* the Reed Solomon control structure */4242+ static struct rs_control *rs_decoder;4343+4444+ /* Symbolsize is 10 (bits)4545+ * Primitive polynomial is x^10+x^3+14646+ * first consecutive root is 04747+ * primitive element to generate roots = 14848+ * generator polynomial degree (number of roots) = 64949+ */5050+ rs_decoder = init_rs (10, 0x409, 0, 1, 6);5151+5252+5353+Encoding5454+--------5555+5656+The encoder calculates the Reed-Solomon code over the given data length5757+and stores the result in the parity buffer. Note that the parity buffer5858+must be initialized before calling the encoder.5959+6060+The expanded data can be inverted on the fly by providing a non-zero6161+inversion mask. The expanded data is XOR'ed with the mask. This is used6262+e.g. for FLASH ECC, where the all 0xFF is inverted to an all 0x00. The6363+Reed-Solomon code for all 0x00 is all 0x00. The code is inverted before6464+storing to FLASH so it is 0xFF too. This prevents that reading from an6565+erased FLASH results in ECC errors.6666+6767+The databytes are expanded to the given symbol size on the fly. There is6868+no support for encoding continuous bitstreams with a symbol size != 8 at6969+the moment. If it is necessary it should be not a big deal to implement7070+such functionality.7171+7272+::7373+7474+ /* Parity buffer. Size = number of roots */7575+ uint16_t par[6];7676+ /* Initialize the parity buffer */7777+ memset(par, 0, sizeof(par));7878+ /* Encode 512 byte in data8. Store parity in buffer par */7979+ encode_rs8 (rs_decoder, data8, 512, par, 0);8080+8181+8282+Decoding8383+--------8484+8585+The decoder calculates the syndrome over the given data length and the8686+received parity symbols and corrects errors in the data.8787+8888+If a syndrome is available from a hardware decoder then the syndrome8989+calculation is skipped.9090+9191+The correction of the data buffer can be suppressed by providing a9292+correction pattern buffer and an error location buffer to the decoder.9393+The decoder stores the calculated error location and the correction9494+bitmask in the given buffers. This is useful for hardware decoders which9595+use a weird bit ordering scheme.9696+9797+The databytes are expanded to the given symbol size on the fly. There is9898+no support for decoding continuous bitstreams with a symbolsize != 8 at9999+the moment. If it is necessary it should be not a big deal to implement100100+such functionality.101101+102102+Decoding with syndrome calculation, direct data correction103103+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~104104+105105+::106106+107107+ /* Parity buffer. Size = number of roots */108108+ uint16_t par[6];109109+ uint8_t data[512];110110+ int numerr;111111+ /* Receive data */112112+ .....113113+ /* Receive parity */114114+ .....115115+ /* Decode 512 byte in data8.*/116116+ numerr = decode_rs8 (rs_decoder, data8, par, 512, NULL, 0, NULL, 0, NULL);117117+118118+119119+Decoding with syndrome given by hardware decoder, direct data correction120120+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~121121+122122+::123123+124124+ /* Parity buffer. Size = number of roots */125125+ uint16_t par[6], syn[6];126126+ uint8_t data[512];127127+ int numerr;128128+ /* Receive data */129129+ .....130130+ /* Receive parity */131131+ .....132132+ /* Get syndrome from hardware decoder */133133+ .....134134+ /* Decode 512 byte in data8.*/135135+ numerr = decode_rs8 (rs_decoder, data8, par, 512, syn, 0, NULL, 0, NULL);136136+137137+138138+Decoding with syndrome given by hardware decoder, no direct data correction.139139+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~140140+141141+Note: It's not necessary to give data and received parity to the142142+decoder.143143+144144+::145145+146146+ /* Parity buffer. Size = number of roots */147147+ uint16_t par[6], syn[6], corr[8];148148+ uint8_t data[512];149149+ int numerr, errpos[8];150150+ /* Receive data */151151+ .....152152+ /* Receive parity */153153+ .....154154+ /* Get syndrome from hardware decoder */155155+ .....156156+ /* Decode 512 byte in data8.*/157157+ numerr = decode_rs8 (rs_decoder, NULL, NULL, 512, syn, 0, errpos, 0, corr);158158+ for (i = 0; i < numerr; i++) {159159+ do_error_correction_in_your_buffer(errpos[i], corr[i]);160160+ }161161+162162+163163+Cleanup164164+-------165165+166166+The function free_rs frees the allocated resources, if the caller is167167+the last user of the decoder.168168+169169+::170170+171171+ /* Release resources */172172+ free_rs(rs_decoder);173173+174174+175175+Structures176176+==========177177+178178+This chapter contains the autogenerated documentation of the structures179179+which are used in the Reed-Solomon Library and are relevant for a180180+developer.181181+182182+.. kernel-doc:: include/linux/rslib.h183183+ :internal:184184+185185+Public Functions Provided186186+=========================187187+188188+This chapter contains the autogenerated documentation of the189189+Reed-Solomon functions which are exported.190190+191191+.. kernel-doc:: lib/reed_solomon/reed_solomon.c192192+ :export:193193+194194+Credits195195+=======196196+197197+The library code for encoding and decoding was written by Phil Karn.198198+199199+::200200+201201+ Copyright 2002, Phil Karn, KA9Q202202+ May be used under the terms of the GNU General Public License (GPL)203203+204204+205205+The wrapper functions and interfaces are written by Thomas Gleixner.206206+207207+Many users have provided bugfixes, improvements and helping hands for208208+testing. Thanks a lot.209209+210210+The following people have contributed to this document:211211+212212+Thomas Gleixner\ tglx@linutronix.de