Commit 7150962d637cf38617924f7f72ea00612283eb89
Committed by
John W. Linville
1 parent
dabd3001f9
Exists in
master
and in
20 other branches
lib: crc8: add new library module providing crc8 algorithm
The brcm80211 driver in staging tree uses a crc8 function. Based on feedback from John Linville to move this to lib directory, the linux source has been searched. Although there is currently only one other kernel driver using this algorithm (ie. drivers/ssb) we are providing this as a library function for others to use. Cc: linux-kernel@vger.kernel.org Cc: linux-wireless@vger.kernel.org Cc: Dan Carpenter <error27@gmail.com> Cc: George Spelvin <linux@horizon.com> Cc: Randy Dunlap <rdunlap@xenotime.net> Reviewed-by: Henry Ptasinski <henryp@broadcom.com> Reviewed-by: Roland Vossen <rvossen@broadcom.com> Reviewed-by: "Franky (Zhenhui) Lin" <frankyl@broadcom.com> Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Showing 4 changed files with 195 additions and 0 deletions Inline Diff
include/linux/crc8.h
File was created | 1 | /* | |
2 | * Copyright (c) 2011 Broadcom Corporation | ||
3 | * | ||
4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | #ifndef __CRC8_H_ | ||
17 | #define __CRC8_H_ | ||
18 | |||
19 | #include <linux/types.h> | ||
20 | |||
21 | /* see usage of this value in crc8() description */ | ||
22 | #define CRC8_INIT_VALUE 0xFF | ||
23 | |||
24 | /* | ||
25 | * Return value of crc8() indicating valid message+crc. This is true | ||
26 | * if a CRC is inverted before transmission. The CRC computed over the | ||
27 | * whole received bitstream is _table[x], where x is the bit pattern | ||
28 | * of the modification (almost always 0xff). | ||
29 | */ | ||
30 | #define CRC8_GOOD_VALUE(_table) (_table[0xFF]) | ||
31 | |||
32 | /* required table size for crc8 algorithm */ | ||
33 | #define CRC8_TABLE_SIZE 256 | ||
34 | |||
35 | /* helper macro assuring right table size is used */ | ||
36 | #define DECLARE_CRC8_TABLE(_table) \ | ||
37 | static u8 _table[CRC8_TABLE_SIZE] | ||
38 | |||
39 | /** | ||
40 | * crc8_populate_lsb - fill crc table for given polynomial in regular bit order. | ||
41 | * | ||
42 | * @table: table to be filled. | ||
43 | * @polynomial: polynomial for which table is to be filled. | ||
44 | * | ||
45 | * This function fills the provided table according the polynomial provided for | ||
46 | * regular bit order (lsb first). Polynomials in CRC algorithms are typically | ||
47 | * represented as shown below. | ||
48 | * | ||
49 | * poly = x^8 + x^7 + x^6 + x^4 + x^2 + 1 | ||
50 | * | ||
51 | * For lsb first direction x^7 maps to the lsb. So the polynomial is as below. | ||
52 | * | ||
53 | * - lsb first: poly = 10101011(1) = 0xAB | ||
54 | */ | ||
55 | void crc8_populate_lsb(u8 table[CRC8_TABLE_SIZE], u8 polynomial); | ||
56 | |||
57 | /** | ||
58 | * crc8_populate_msb - fill crc table for given polynomial in reverse bit order. | ||
59 | * | ||
60 | * @table: table to be filled. | ||
61 | * @polynomial: polynomial for which table is to be filled. | ||
62 | * | ||
63 | * This function fills the provided table according the polynomial provided for | ||
64 | * reverse bit order (msb first). Polynomials in CRC algorithms are typically | ||
65 | * represented as shown below. | ||
66 | * | ||
67 | * poly = x^8 + x^7 + x^6 + x^4 + x^2 + 1 | ||
68 | * | ||
69 | * For msb first direction x^7 maps to the msb. So the polynomial is as below. | ||
70 | * | ||
71 | * - msb first: poly = (1)11010101 = 0xD5 | ||
72 | */ | ||
73 | void crc8_populate_msb(u8 table[CRC8_TABLE_SIZE], u8 polynomial); | ||
74 | |||
75 | /** | ||
76 | * crc8() - calculate a crc8 over the given input data. | ||
77 | * | ||
78 | * @table: crc table used for calculation. | ||
79 | * @pdata: pointer to data buffer. | ||
80 | * @nbytes: number of bytes in data buffer. | ||
81 | * @crc: previous returned crc8 value. | ||
82 | * | ||
83 | * The CRC8 is calculated using the polynomial given in crc8_populate_msb() | ||
84 | * or crc8_populate_lsb(). | ||
85 | * | ||
86 | * The caller provides the initial value (either %CRC8_INIT_VALUE | ||
87 | * or the previous returned value) to allow for processing of | ||
88 | * discontiguous blocks of data. When generating the CRC the | ||
89 | * caller is responsible for complementing the final return value | ||
90 | * and inserting it into the byte stream. When validating a byte | ||
91 | * stream (including CRC8), a final return value of %CRC8_GOOD_VALUE | ||
92 | * indicates the byte stream data can be considered valid. | ||
93 | * | ||
94 | * Reference: | ||
95 | * "A Painless Guide to CRC Error Detection Algorithms", ver 3, Aug 1993 | ||
96 | * Williams, Ross N., ross<at>ross.net | ||
97 | * (see URL http://www.ross.net/crc/download/crc_v3.txt). | ||
98 | */ | ||
99 | u8 crc8(const u8 table[CRC8_TABLE_SIZE], u8 *pdata, size_t nbytes, u8 crc); | ||
100 | |||
101 | #endif /* __CRC8_H_ */ | ||
102 |
lib/Kconfig
1 | # | 1 | # |
2 | # Library configuration | 2 | # Library configuration |
3 | # | 3 | # |
4 | 4 | ||
5 | config BINARY_PRINTF | 5 | config BINARY_PRINTF |
6 | def_bool n | 6 | def_bool n |
7 | 7 | ||
8 | menu "Library routines" | 8 | menu "Library routines" |
9 | 9 | ||
10 | config RAID6_PQ | 10 | config RAID6_PQ |
11 | tristate | 11 | tristate |
12 | 12 | ||
13 | config BITREVERSE | 13 | config BITREVERSE |
14 | tristate | 14 | tristate |
15 | 15 | ||
16 | config RATIONAL | 16 | config RATIONAL |
17 | boolean | 17 | boolean |
18 | 18 | ||
19 | config GENERIC_FIND_FIRST_BIT | 19 | config GENERIC_FIND_FIRST_BIT |
20 | bool | 20 | bool |
21 | 21 | ||
22 | config GENERIC_FIND_NEXT_BIT | 22 | config GENERIC_FIND_NEXT_BIT |
23 | bool | 23 | bool |
24 | 24 | ||
25 | config GENERIC_FIND_BIT_LE | 25 | config GENERIC_FIND_BIT_LE |
26 | bool | 26 | bool |
27 | 27 | ||
28 | config GENERIC_FIND_LAST_BIT | 28 | config GENERIC_FIND_LAST_BIT |
29 | bool | 29 | bool |
30 | default y | 30 | default y |
31 | 31 | ||
32 | config CRC_CCITT | 32 | config CRC_CCITT |
33 | tristate "CRC-CCITT functions" | 33 | tristate "CRC-CCITT functions" |
34 | help | 34 | help |
35 | This option is provided for the case where no in-kernel-tree | 35 | This option is provided for the case where no in-kernel-tree |
36 | modules require CRC-CCITT functions, but a module built outside | 36 | modules require CRC-CCITT functions, but a module built outside |
37 | the kernel tree does. Such modules that use library CRC-CCITT | 37 | the kernel tree does. Such modules that use library CRC-CCITT |
38 | functions require M here. | 38 | functions require M here. |
39 | 39 | ||
40 | config CRC16 | 40 | config CRC16 |
41 | tristate "CRC16 functions" | 41 | tristate "CRC16 functions" |
42 | help | 42 | help |
43 | This option is provided for the case where no in-kernel-tree | 43 | This option is provided for the case where no in-kernel-tree |
44 | modules require CRC16 functions, but a module built outside | 44 | modules require CRC16 functions, but a module built outside |
45 | the kernel tree does. Such modules that use library CRC16 | 45 | the kernel tree does. Such modules that use library CRC16 |
46 | functions require M here. | 46 | functions require M here. |
47 | 47 | ||
48 | config CRC_T10DIF | 48 | config CRC_T10DIF |
49 | tristate "CRC calculation for the T10 Data Integrity Field" | 49 | tristate "CRC calculation for the T10 Data Integrity Field" |
50 | help | 50 | help |
51 | This option is only needed if a module that's not in the | 51 | This option is only needed if a module that's not in the |
52 | kernel tree needs to calculate CRC checks for use with the | 52 | kernel tree needs to calculate CRC checks for use with the |
53 | SCSI data integrity subsystem. | 53 | SCSI data integrity subsystem. |
54 | 54 | ||
55 | config CRC_ITU_T | 55 | config CRC_ITU_T |
56 | tristate "CRC ITU-T V.41 functions" | 56 | tristate "CRC ITU-T V.41 functions" |
57 | help | 57 | help |
58 | This option is provided for the case where no in-kernel-tree | 58 | This option is provided for the case where no in-kernel-tree |
59 | modules require CRC ITU-T V.41 functions, but a module built outside | 59 | modules require CRC ITU-T V.41 functions, but a module built outside |
60 | the kernel tree does. Such modules that use library CRC ITU-T V.41 | 60 | the kernel tree does. Such modules that use library CRC ITU-T V.41 |
61 | functions require M here. | 61 | functions require M here. |
62 | 62 | ||
63 | config CRC32 | 63 | config CRC32 |
64 | tristate "CRC32 functions" | 64 | tristate "CRC32 functions" |
65 | default y | 65 | default y |
66 | select BITREVERSE | 66 | select BITREVERSE |
67 | help | 67 | help |
68 | This option is provided for the case where no in-kernel-tree | 68 | This option is provided for the case where no in-kernel-tree |
69 | modules require CRC32 functions, but a module built outside the | 69 | modules require CRC32 functions, but a module built outside the |
70 | kernel tree does. Such modules that use library CRC32 functions | 70 | kernel tree does. Such modules that use library CRC32 functions |
71 | require M here. | 71 | require M here. |
72 | 72 | ||
73 | config CRC7 | 73 | config CRC7 |
74 | tristate "CRC7 functions" | 74 | tristate "CRC7 functions" |
75 | help | 75 | help |
76 | This option is provided for the case where no in-kernel-tree | 76 | This option is provided for the case where no in-kernel-tree |
77 | modules require CRC7 functions, but a module built outside | 77 | modules require CRC7 functions, but a module built outside |
78 | the kernel tree does. Such modules that use library CRC7 | 78 | the kernel tree does. Such modules that use library CRC7 |
79 | functions require M here. | 79 | functions require M here. |
80 | 80 | ||
81 | config LIBCRC32C | 81 | config LIBCRC32C |
82 | tristate "CRC32c (Castagnoli, et al) Cyclic Redundancy-Check" | 82 | tristate "CRC32c (Castagnoli, et al) Cyclic Redundancy-Check" |
83 | select CRYPTO | 83 | select CRYPTO |
84 | select CRYPTO_CRC32C | 84 | select CRYPTO_CRC32C |
85 | help | 85 | help |
86 | This option is provided for the case where no in-kernel-tree | 86 | This option is provided for the case where no in-kernel-tree |
87 | modules require CRC32c functions, but a module built outside the | 87 | modules require CRC32c functions, but a module built outside the |
88 | kernel tree does. Such modules that use library CRC32c functions | 88 | kernel tree does. Such modules that use library CRC32c functions |
89 | require M here. See Castagnoli93. | 89 | require M here. See Castagnoli93. |
90 | Module will be libcrc32c. | 90 | Module will be libcrc32c. |
91 | 91 | ||
92 | config CRC8 | ||
93 | tristate "CRC8 function" | ||
94 | help | ||
95 | This option provides CRC8 function. Drivers may select this | ||
96 | when they need to do cyclic redundancy check according CRC8 | ||
97 | algorithm. Module will be called crc8. | ||
98 | |||
92 | config AUDIT_GENERIC | 99 | config AUDIT_GENERIC |
93 | bool | 100 | bool |
94 | depends on AUDIT && !AUDIT_ARCH | 101 | depends on AUDIT && !AUDIT_ARCH |
95 | default y | 102 | default y |
96 | 103 | ||
97 | # | 104 | # |
98 | # compression support is select'ed if needed | 105 | # compression support is select'ed if needed |
99 | # | 106 | # |
100 | config ZLIB_INFLATE | 107 | config ZLIB_INFLATE |
101 | tristate | 108 | tristate |
102 | 109 | ||
103 | config ZLIB_DEFLATE | 110 | config ZLIB_DEFLATE |
104 | tristate | 111 | tristate |
105 | 112 | ||
106 | config LZO_COMPRESS | 113 | config LZO_COMPRESS |
107 | tristate | 114 | tristate |
108 | 115 | ||
109 | config LZO_DECOMPRESS | 116 | config LZO_DECOMPRESS |
110 | tristate | 117 | tristate |
111 | 118 | ||
112 | source "lib/xz/Kconfig" | 119 | source "lib/xz/Kconfig" |
113 | 120 | ||
114 | # | 121 | # |
115 | # These all provide a common interface (hence the apparent duplication with | 122 | # These all provide a common interface (hence the apparent duplication with |
116 | # ZLIB_INFLATE; DECOMPRESS_GZIP is just a wrapper.) | 123 | # ZLIB_INFLATE; DECOMPRESS_GZIP is just a wrapper.) |
117 | # | 124 | # |
118 | config DECOMPRESS_GZIP | 125 | config DECOMPRESS_GZIP |
119 | select ZLIB_INFLATE | 126 | select ZLIB_INFLATE |
120 | tristate | 127 | tristate |
121 | 128 | ||
122 | config DECOMPRESS_BZIP2 | 129 | config DECOMPRESS_BZIP2 |
123 | tristate | 130 | tristate |
124 | 131 | ||
125 | config DECOMPRESS_LZMA | 132 | config DECOMPRESS_LZMA |
126 | tristate | 133 | tristate |
127 | 134 | ||
128 | config DECOMPRESS_XZ | 135 | config DECOMPRESS_XZ |
129 | select XZ_DEC | 136 | select XZ_DEC |
130 | tristate | 137 | tristate |
131 | 138 | ||
132 | config DECOMPRESS_LZO | 139 | config DECOMPRESS_LZO |
133 | select LZO_DECOMPRESS | 140 | select LZO_DECOMPRESS |
134 | tristate | 141 | tristate |
135 | 142 | ||
136 | # | 143 | # |
137 | # Generic allocator support is selected if needed | 144 | # Generic allocator support is selected if needed |
138 | # | 145 | # |
139 | config GENERIC_ALLOCATOR | 146 | config GENERIC_ALLOCATOR |
140 | boolean | 147 | boolean |
141 | 148 | ||
142 | # | 149 | # |
143 | # reed solomon support is select'ed if needed | 150 | # reed solomon support is select'ed if needed |
144 | # | 151 | # |
145 | config REED_SOLOMON | 152 | config REED_SOLOMON |
146 | tristate | 153 | tristate |
147 | 154 | ||
148 | config REED_SOLOMON_ENC8 | 155 | config REED_SOLOMON_ENC8 |
149 | boolean | 156 | boolean |
150 | 157 | ||
151 | config REED_SOLOMON_DEC8 | 158 | config REED_SOLOMON_DEC8 |
152 | boolean | 159 | boolean |
153 | 160 | ||
154 | config REED_SOLOMON_ENC16 | 161 | config REED_SOLOMON_ENC16 |
155 | boolean | 162 | boolean |
156 | 163 | ||
157 | config REED_SOLOMON_DEC16 | 164 | config REED_SOLOMON_DEC16 |
158 | boolean | 165 | boolean |
159 | 166 | ||
160 | # | 167 | # |
161 | # BCH support is selected if needed | 168 | # BCH support is selected if needed |
162 | # | 169 | # |
163 | config BCH | 170 | config BCH |
164 | tristate | 171 | tristate |
165 | 172 | ||
166 | config BCH_CONST_PARAMS | 173 | config BCH_CONST_PARAMS |
167 | boolean | 174 | boolean |
168 | help | 175 | help |
169 | Drivers may select this option to force specific constant | 176 | Drivers may select this option to force specific constant |
170 | values for parameters 'm' (Galois field order) and 't' | 177 | values for parameters 'm' (Galois field order) and 't' |
171 | (error correction capability). Those specific values must | 178 | (error correction capability). Those specific values must |
172 | be set by declaring default values for symbols BCH_CONST_M | 179 | be set by declaring default values for symbols BCH_CONST_M |
173 | and BCH_CONST_T. | 180 | and BCH_CONST_T. |
174 | Doing so will enable extra compiler optimizations, | 181 | Doing so will enable extra compiler optimizations, |
175 | improving encoding and decoding performance up to 2x for | 182 | improving encoding and decoding performance up to 2x for |
176 | usual (m,t) values (typically such that m*t < 200). | 183 | usual (m,t) values (typically such that m*t < 200). |
177 | When this option is selected, the BCH library supports | 184 | When this option is selected, the BCH library supports |
178 | only a single (m,t) configuration. This is mainly useful | 185 | only a single (m,t) configuration. This is mainly useful |
179 | for NAND flash board drivers requiring known, fixed BCH | 186 | for NAND flash board drivers requiring known, fixed BCH |
180 | parameters. | 187 | parameters. |
181 | 188 | ||
182 | config BCH_CONST_M | 189 | config BCH_CONST_M |
183 | int | 190 | int |
184 | range 5 15 | 191 | range 5 15 |
185 | help | 192 | help |
186 | Constant value for Galois field order 'm'. If 'k' is the | 193 | Constant value for Galois field order 'm'. If 'k' is the |
187 | number of data bits to protect, 'm' should be chosen such | 194 | number of data bits to protect, 'm' should be chosen such |
188 | that (k + m*t) <= 2**m - 1. | 195 | that (k + m*t) <= 2**m - 1. |
189 | Drivers should declare a default value for this symbol if | 196 | Drivers should declare a default value for this symbol if |
190 | they select option BCH_CONST_PARAMS. | 197 | they select option BCH_CONST_PARAMS. |
191 | 198 | ||
192 | config BCH_CONST_T | 199 | config BCH_CONST_T |
193 | int | 200 | int |
194 | help | 201 | help |
195 | Constant value for error correction capability in bits 't'. | 202 | Constant value for error correction capability in bits 't'. |
196 | Drivers should declare a default value for this symbol if | 203 | Drivers should declare a default value for this symbol if |
197 | they select option BCH_CONST_PARAMS. | 204 | they select option BCH_CONST_PARAMS. |
198 | 205 | ||
199 | # | 206 | # |
200 | # Textsearch support is select'ed if needed | 207 | # Textsearch support is select'ed if needed |
201 | # | 208 | # |
202 | config TEXTSEARCH | 209 | config TEXTSEARCH |
203 | boolean | 210 | boolean |
204 | 211 | ||
205 | config TEXTSEARCH_KMP | 212 | config TEXTSEARCH_KMP |
206 | tristate | 213 | tristate |
207 | 214 | ||
208 | config TEXTSEARCH_BM | 215 | config TEXTSEARCH_BM |
209 | tristate | 216 | tristate |
210 | 217 | ||
211 | config TEXTSEARCH_FSM | 218 | config TEXTSEARCH_FSM |
212 | tristate | 219 | tristate |
213 | 220 | ||
214 | config BTREE | 221 | config BTREE |
215 | boolean | 222 | boolean |
216 | 223 | ||
217 | config HAS_IOMEM | 224 | config HAS_IOMEM |
218 | boolean | 225 | boolean |
219 | depends on !NO_IOMEM | 226 | depends on !NO_IOMEM |
220 | default y | 227 | default y |
221 | 228 | ||
222 | config HAS_IOPORT | 229 | config HAS_IOPORT |
223 | boolean | 230 | boolean |
224 | depends on HAS_IOMEM && !NO_IOPORT | 231 | depends on HAS_IOMEM && !NO_IOPORT |
225 | default y | 232 | default y |
226 | 233 | ||
227 | config HAS_DMA | 234 | config HAS_DMA |
228 | boolean | 235 | boolean |
229 | depends on !NO_DMA | 236 | depends on !NO_DMA |
230 | default y | 237 | default y |
231 | 238 | ||
232 | config CHECK_SIGNATURE | 239 | config CHECK_SIGNATURE |
233 | bool | 240 | bool |
234 | 241 | ||
235 | config CPUMASK_OFFSTACK | 242 | config CPUMASK_OFFSTACK |
236 | bool "Force CPU masks off stack" if DEBUG_PER_CPU_MAPS | 243 | bool "Force CPU masks off stack" if DEBUG_PER_CPU_MAPS |
237 | help | 244 | help |
238 | Use dynamic allocation for cpumask_var_t, instead of putting | 245 | Use dynamic allocation for cpumask_var_t, instead of putting |
239 | them on the stack. This is a bit more expensive, but avoids | 246 | them on the stack. This is a bit more expensive, but avoids |
240 | stack overflow. | 247 | stack overflow. |
241 | 248 | ||
242 | config DISABLE_OBSOLETE_CPUMASK_FUNCTIONS | 249 | config DISABLE_OBSOLETE_CPUMASK_FUNCTIONS |
243 | bool "Disable obsolete cpumask functions" if DEBUG_PER_CPU_MAPS | 250 | bool "Disable obsolete cpumask functions" if DEBUG_PER_CPU_MAPS |
244 | depends on EXPERIMENTAL && BROKEN | 251 | depends on EXPERIMENTAL && BROKEN |
245 | 252 | ||
246 | config CPU_RMAP | 253 | config CPU_RMAP |
247 | bool | 254 | bool |
248 | depends on SMP | 255 | depends on SMP |
249 | 256 | ||
250 | # | 257 | # |
251 | # Netlink attribute parsing support is select'ed if needed | 258 | # Netlink attribute parsing support is select'ed if needed |
252 | # | 259 | # |
253 | config NLATTR | 260 | config NLATTR |
254 | bool | 261 | bool |
255 | 262 | ||
256 | # | 263 | # |
257 | # Generic 64-bit atomic support is selected if needed | 264 | # Generic 64-bit atomic support is selected if needed |
258 | # | 265 | # |
259 | config GENERIC_ATOMIC64 | 266 | config GENERIC_ATOMIC64 |
260 | bool | 267 | bool |
261 | 268 | ||
262 | config LRU_CACHE | 269 | config LRU_CACHE |
263 | tristate | 270 | tristate |
264 | 271 | ||
265 | config AVERAGE | 272 | config AVERAGE |
266 | bool "Averaging functions" | 273 | bool "Averaging functions" |
267 | help | 274 | help |
268 | This option is provided for the case where no in-kernel-tree | 275 | This option is provided for the case where no in-kernel-tree |
269 | modules require averaging functions, but a module built outside | 276 | modules require averaging functions, but a module built outside |
270 | the kernel tree does. Such modules that use library averaging | 277 | the kernel tree does. Such modules that use library averaging |
271 | functions require Y here. | 278 | functions require Y here. |
272 | 279 | ||
273 | If unsure, say N. | 280 | If unsure, say N. |
274 | 281 | ||
275 | endmenu | 282 | endmenu |
276 | 283 |
lib/Makefile
1 | # | 1 | # |
2 | # Makefile for some libs needed in the kernel. | 2 | # Makefile for some libs needed in the kernel. |
3 | # | 3 | # |
4 | 4 | ||
5 | ifdef CONFIG_FUNCTION_TRACER | 5 | ifdef CONFIG_FUNCTION_TRACER |
6 | ORIG_CFLAGS := $(KBUILD_CFLAGS) | 6 | ORIG_CFLAGS := $(KBUILD_CFLAGS) |
7 | KBUILD_CFLAGS = $(subst -pg,,$(ORIG_CFLAGS)) | 7 | KBUILD_CFLAGS = $(subst -pg,,$(ORIG_CFLAGS)) |
8 | endif | 8 | endif |
9 | 9 | ||
10 | lib-y := ctype.o string.o vsprintf.o cmdline.o \ | 10 | lib-y := ctype.o string.o vsprintf.o cmdline.o \ |
11 | rbtree.o radix-tree.o dump_stack.o timerqueue.o\ | 11 | rbtree.o radix-tree.o dump_stack.o timerqueue.o\ |
12 | idr.o int_sqrt.o extable.o prio_tree.o \ | 12 | idr.o int_sqrt.o extable.o prio_tree.o \ |
13 | sha1.o irq_regs.o reciprocal_div.o argv_split.o \ | 13 | sha1.o irq_regs.o reciprocal_div.o argv_split.o \ |
14 | proportions.o prio_heap.o ratelimit.o show_mem.o \ | 14 | proportions.o prio_heap.o ratelimit.o show_mem.o \ |
15 | is_single_threaded.o plist.o decompress.o | 15 | is_single_threaded.o plist.o decompress.o |
16 | 16 | ||
17 | lib-$(CONFIG_MMU) += ioremap.o | 17 | lib-$(CONFIG_MMU) += ioremap.o |
18 | lib-$(CONFIG_SMP) += cpumask.o | 18 | lib-$(CONFIG_SMP) += cpumask.o |
19 | 19 | ||
20 | lib-y += kobject.o kref.o klist.o | 20 | lib-y += kobject.o kref.o klist.o |
21 | 21 | ||
22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 22 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 23 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ | 24 | string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ |
25 | bsearch.o | 25 | bsearch.o |
26 | obj-y += kstrtox.o | 26 | obj-y += kstrtox.o |
27 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | 27 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o |
28 | 28 | ||
29 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 29 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
30 | CFLAGS_kobject.o += -DDEBUG | 30 | CFLAGS_kobject.o += -DDEBUG |
31 | CFLAGS_kobject_uevent.o += -DDEBUG | 31 | CFLAGS_kobject_uevent.o += -DDEBUG |
32 | endif | 32 | endif |
33 | 33 | ||
34 | lib-$(CONFIG_HOTPLUG) += kobject_uevent.o | 34 | lib-$(CONFIG_HOTPLUG) += kobject_uevent.o |
35 | obj-$(CONFIG_GENERIC_IOMAP) += iomap.o | 35 | obj-$(CONFIG_GENERIC_IOMAP) += iomap.o |
36 | obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o | 36 | obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o |
37 | obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o | 37 | obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o |
38 | obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o | 38 | obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o |
39 | obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o | 39 | obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o |
40 | lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o | 40 | lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o |
41 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o | 41 | lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o |
42 | lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o | 42 | lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o |
43 | lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o | 43 | lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o |
44 | lib-$(CONFIG_GENERIC_FIND_BIT_LE) += find_next_bit.o | 44 | lib-$(CONFIG_GENERIC_FIND_BIT_LE) += find_next_bit.o |
45 | obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o | 45 | obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o |
46 | 46 | ||
47 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) | 47 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) |
48 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o | 48 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o |
49 | 49 | ||
50 | obj-$(CONFIG_BTREE) += btree.o | 50 | obj-$(CONFIG_BTREE) += btree.o |
51 | obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o | 51 | obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o |
52 | obj-$(CONFIG_DEBUG_LIST) += list_debug.o | 52 | obj-$(CONFIG_DEBUG_LIST) += list_debug.o |
53 | obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o | 53 | obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o |
54 | 54 | ||
55 | ifneq ($(CONFIG_HAVE_DEC_LOCK),y) | 55 | ifneq ($(CONFIG_HAVE_DEC_LOCK),y) |
56 | lib-y += dec_and_lock.o | 56 | lib-y += dec_and_lock.o |
57 | endif | 57 | endif |
58 | 58 | ||
59 | obj-$(CONFIG_BITREVERSE) += bitrev.o | 59 | obj-$(CONFIG_BITREVERSE) += bitrev.o |
60 | obj-$(CONFIG_RATIONAL) += rational.o | 60 | obj-$(CONFIG_RATIONAL) += rational.o |
61 | obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o | 61 | obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o |
62 | obj-$(CONFIG_CRC16) += crc16.o | 62 | obj-$(CONFIG_CRC16) += crc16.o |
63 | obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o | 63 | obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o |
64 | obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o | 64 | obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o |
65 | obj-$(CONFIG_CRC32) += crc32.o | 65 | obj-$(CONFIG_CRC32) += crc32.o |
66 | obj-$(CONFIG_CRC7) += crc7.o | 66 | obj-$(CONFIG_CRC7) += crc7.o |
67 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o | 67 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o |
68 | obj-$(CONFIG_CRC8) += crc8.o | ||
68 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o | 69 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o |
69 | 70 | ||
70 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ | 71 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ |
71 | obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/ | 72 | obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/ |
72 | obj-$(CONFIG_REED_SOLOMON) += reed_solomon/ | 73 | obj-$(CONFIG_REED_SOLOMON) += reed_solomon/ |
73 | obj-$(CONFIG_BCH) += bch.o | 74 | obj-$(CONFIG_BCH) += bch.o |
74 | obj-$(CONFIG_LZO_COMPRESS) += lzo/ | 75 | obj-$(CONFIG_LZO_COMPRESS) += lzo/ |
75 | obj-$(CONFIG_LZO_DECOMPRESS) += lzo/ | 76 | obj-$(CONFIG_LZO_DECOMPRESS) += lzo/ |
76 | obj-$(CONFIG_XZ_DEC) += xz/ | 77 | obj-$(CONFIG_XZ_DEC) += xz/ |
77 | obj-$(CONFIG_RAID6_PQ) += raid6/ | 78 | obj-$(CONFIG_RAID6_PQ) += raid6/ |
78 | 79 | ||
79 | lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o | 80 | lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o |
80 | lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o | 81 | lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o |
81 | lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o | 82 | lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o |
82 | lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o | 83 | lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o |
83 | lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o | 84 | lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o |
84 | 85 | ||
85 | obj-$(CONFIG_TEXTSEARCH) += textsearch.o | 86 | obj-$(CONFIG_TEXTSEARCH) += textsearch.o |
86 | obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o | 87 | obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o |
87 | obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o | 88 | obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o |
88 | obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o | 89 | obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o |
89 | obj-$(CONFIG_SMP) += percpu_counter.o | 90 | obj-$(CONFIG_SMP) += percpu_counter.o |
90 | obj-$(CONFIG_AUDIT_GENERIC) += audit.o | 91 | obj-$(CONFIG_AUDIT_GENERIC) += audit.o |
91 | 92 | ||
92 | obj-$(CONFIG_SWIOTLB) += swiotlb.o | 93 | obj-$(CONFIG_SWIOTLB) += swiotlb.o |
93 | obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o | 94 | obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o |
94 | obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o | 95 | obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o |
95 | obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o | 96 | obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o |
96 | 97 | ||
97 | lib-$(CONFIG_GENERIC_BUG) += bug.o | 98 | lib-$(CONFIG_GENERIC_BUG) += bug.o |
98 | 99 | ||
99 | obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o | 100 | obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o |
100 | 101 | ||
101 | obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o | 102 | obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o |
102 | 103 | ||
103 | obj-$(CONFIG_NLATTR) += nlattr.o | 104 | obj-$(CONFIG_NLATTR) += nlattr.o |
104 | 105 | ||
105 | obj-$(CONFIG_LRU_CACHE) += lru_cache.o | 106 | obj-$(CONFIG_LRU_CACHE) += lru_cache.o |
106 | 107 | ||
107 | obj-$(CONFIG_DMA_API_DEBUG) += dma-debug.o | 108 | obj-$(CONFIG_DMA_API_DEBUG) += dma-debug.o |
108 | 109 | ||
109 | obj-$(CONFIG_GENERIC_CSUM) += checksum.o | 110 | obj-$(CONFIG_GENERIC_CSUM) += checksum.o |
110 | 111 | ||
111 | obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o | 112 | obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o |
112 | 113 | ||
113 | obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o | 114 | obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o |
114 | 115 | ||
115 | obj-$(CONFIG_AVERAGE) += average.o | 116 | obj-$(CONFIG_AVERAGE) += average.o |
116 | 117 | ||
117 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o | 118 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o |
118 | 119 | ||
119 | hostprogs-y := gen_crc32table | 120 | hostprogs-y := gen_crc32table |
120 | clean-files := crc32table.h | 121 | clean-files := crc32table.h |
121 | 122 | ||
122 | $(obj)/crc32.o: $(obj)/crc32table.h | 123 | $(obj)/crc32.o: $(obj)/crc32table.h |
123 | 124 | ||
124 | quiet_cmd_crc32 = GEN $@ | 125 | quiet_cmd_crc32 = GEN $@ |
125 | cmd_crc32 = $< > $@ | 126 | cmd_crc32 = $< > $@ |
126 | 127 | ||
127 | $(obj)/crc32table.h: $(obj)/gen_crc32table | 128 | $(obj)/crc32table.h: $(obj)/gen_crc32table |
128 | $(call cmd,crc32) | 129 | $(call cmd,crc32) |
129 | 130 |
lib/crc8.c
File was created | 1 | /* | |
2 | * Copyright (c) 2011 Broadcom Corporation | ||
3 | * | ||
4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/crc8.h> | ||
21 | #include <linux/printk.h> | ||
22 | |||
23 | /* | ||
24 | * crc8_populate_msb - fill crc table for given polynomial in reverse bit order. | ||
25 | * | ||
26 | * table: table to be filled. | ||
27 | * polynomial: polynomial for which table is to be filled. | ||
28 | */ | ||
29 | void crc8_populate_msb(u8 table[CRC8_TABLE_SIZE], u8 polynomial) | ||
30 | { | ||
31 | int i, j; | ||
32 | const u8 msbit = 0x80; | ||
33 | u8 t = msbit; | ||
34 | |||
35 | table[0] = 0; | ||
36 | |||
37 | for (i = 1; i < CRC8_TABLE_SIZE; i *= 2) { | ||
38 | t = (t << 1) ^ (t & msbit ? polynomial : 0); | ||
39 | for (j = 0; j < i; j++) | ||
40 | table[i+j] = table[j] ^ t; | ||
41 | } | ||
42 | } | ||
43 | EXPORT_SYMBOL(crc8_populate_msb); | ||
44 | |||
45 | /* | ||
46 | * crc8_populate_lsb - fill crc table for given polynomial in regular bit order. | ||
47 | * | ||
48 | * table: table to be filled. | ||
49 | * polynomial: polynomial for which table is to be filled. | ||
50 | */ | ||
51 | void crc8_populate_lsb(u8 table[CRC8_TABLE_SIZE], u8 polynomial) | ||
52 | { | ||
53 | int i, j; | ||
54 | u8 t = 1; | ||
55 | |||
56 | table[0] = 0; | ||
57 | |||
58 | for (i = (CRC8_TABLE_SIZE >> 1); i; i >>= 1) { | ||
59 | t = (t >> 1) ^ (t & 1 ? polynomial : 0); | ||
60 | for (j = 0; j < CRC8_TABLE_SIZE; j += 2*i) | ||
61 | table[i+j] = table[j] ^ t; | ||
62 | } | ||
63 | } | ||
64 | EXPORT_SYMBOL(crc8_populate_lsb); | ||
65 | |||
66 | /* | ||
67 | * crc8 - calculate a crc8 over the given input data. | ||
68 | * | ||
69 | * table: crc table used for calculation. | ||
70 | * pdata: pointer to data buffer. | ||
71 | * nbytes: number of bytes in data buffer. | ||
72 | * crc: previous returned crc8 value. | ||
73 | */ | ||
74 | u8 crc8(const u8 table[CRC8_TABLE_SIZE], u8 *pdata, size_t nbytes, u8 crc) | ||
75 | { | ||
76 | /* loop over the buffer data */ | ||
77 | while (nbytes-- > 0) | ||
78 | crc = table[(crc ^ *pdata++) & 0xff]; | ||
79 | |||
80 | return crc; | ||
81 | } | ||
82 | EXPORT_SYMBOL(crc8); | ||
83 | |||
84 | MODULE_DESCRIPTION("CRC8 (by Williams, Ross N.) function"); | ||
85 | MODULE_AUTHOR("Broadcom Corporation"); | ||
86 | MODULE_LICENSE("Dual BSD/GPL"); | ||
87 |