]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.4.20-crc32.patch
- ported from linux-2.4.25-atmdd.patch
[packages/kernel.git] / linux-2.4.20-crc32.patch
1 diff -Nru a/drivers/net/Makefile.lib b/drivers/net/Makefile.lib
2 --- /dev/null   Wed Dec 31 16:00:00 1969
3 +++ b/drivers/net/Makefile.lib  Sat May 17 18:11:24 2003
4 @@ -0,0 +1,74 @@
5 +# These drivers all require crc32.o
6 +obj-$(CONFIG_8139CP)           += crc32.o
7 +obj-$(CONFIG_8139TOO)          += crc32.o
8 +obj-$(CONFIG_A2065)            += crc32.o
9 +obj-$(CONFIG_ADAPTEC_STARFIRE) += crc32.o
10 +obj-$(CONFIG_AMD8111_ETH)      += crc32.o
11 +obj-$(CONFIG_ARM_AM79C961A)    += crc32.o
12 +obj-$(CONFIG_AT1700)           += crc32.o
13 +obj-$(CONFIG_ATP)              += crc32.o
14 +obj-$(CONFIG_BMAC)             += crc32.o
15 +obj-$(CONFIG_DE4X5)            += crc32.o
16 +obj-$(CONFIG_DECLANCE)         += crc32.o
17 +obj-$(CONFIG_DEPCA)            += crc32.o
18 +obj-$(CONFIG_DL2K)             += crc32.o
19 +obj-$(CONFIG_DM9102)           += crc32.o
20 +obj-$(CONFIG_EPIC100)          += crc32.o
21 +obj-$(CONFIG_EWRK3)            += crc32.o
22 +obj-$(CONFIG_FEALNX)           += crc32.o
23 +obj-$(CONFIG_GMAC)             += crc32.o
24 +obj-$(CONFIG_HAPPYMEAL)                += crc32.o
25 +obj-$(CONFIG_MACE)             += crc32.o
26 +obj-$(CONFIG_MACMACE)          += crc32.o
27 +obj-$(CONFIG_PCNET32)          += crc32.o
28 +obj-$(CONFIG_R8169)            += crc32.o
29 +obj-$(CONFIG_SGI_IOC3_ETH)     += crc32.o
30 +obj-$(CONFIG_SIS900)           += crc32.o
31 +obj-$(CONFIG_SMC9194)          += crc32.o
32 +obj-$(CONFIG_SUNBMAC)          += crc32.o
33 +obj-$(CONFIG_SUNDANCE)         += crc32.o
34 +obj-$(CONFIG_SUNGEM)           += crc32.o
35 +obj-$(CONFIG_SUNLANCE)         += crc32.o
36 +obj-$(CONFIG_SUNQE)            += crc32.o
37 +obj-$(CONFIG_TYPHOON)          += crc32.o
38 +obj-$(CONFIG_VIA_RHINE)                += crc32.o
39 +obj-$(CONFIG_WINBOND_840)      += crc32.o
40 +obj-$(CONFIG_YELLOWFIN)                += crc32.o
41 +
42 +# These rely on drivers/net/7990.o which requires crc32.o
43 +obj-$(CONFIG_HPLANCE)          += crc32.o      
44 +obj-$(CONFIG_MVME147_NET)      += crc32.o      
45 +
46 +# These rely on drivers/net/8390.o which requires crc32.o
47 +obj-$(CONFIG_OAKNET)           += crc32.o
48 +obj-$(CONFIG_NE2K_PCI)         += crc32.o
49 +obj-$(CONFIG_STNIC)            += crc32.o
50 +obj-$(CONFIG_MAC8390)          += crc32.o
51 +obj-$(CONFIG_APNE)             += crc32.o
52 +obj-$(CONFIG_PCMCIA_PCNET)     += crc32.o
53 +obj-$(CONFIG_ARM_ETHERH)       += crc32.o
54 +obj-$(CONFIG_WD80x3)           += crc32.o
55 +obj-$(CONFIG_EL2)              += crc32.o
56 +obj-$(CONFIG_NE2000)           += crc32.o
57 +obj-$(CONFIG_NE2_MCA)          += crc32.o
58 +obj-$(CONFIG_HPLAN)            += crc32.o
59 +obj-$(CONFIG_HPLAN_PLUS)       += crc32.o
60 +obj-$(CONFIG_ULTRA)            += crc32.o
61 +obj-$(CONFIG_ULTRAMCA)         += crc32.o
62 +obj-$(CONFIG_ULTRA32)          += crc32.o
63 +obj-$(CONFIG_E2100)            += crc32.o
64 +obj-$(CONFIG_ES3210)           += crc32.o
65 +obj-$(CONFIG_LNE390)           += crc32.o
66 +obj-$(CONFIG_NE3210)           += crc32.o
67 +obj-$(CONFIG_AC3200)           += crc32.o
68 +obj-$(CONFIG_ARIADNE2)         += crc32.o
69 +obj-$(CONFIG_HYDRA)            += crc32.o
70 +
71 +# drivers/net/pcmcia
72 +obj-$(CONFIG_PCMCIA_FMVJ18X)   += crc32.o
73 +obj-$(CONFIG_PCMCIA_SMC91C92)  += crc32.o
74 +obj-$(CONFIG_PCMCIA_XIRTULIP)  += crc32.o
75 +
76 +# drivers/net/tulip
77 +obj-$(CONFIG_TULIP)            += crc32.o
78 +
79 diff -Nru a/drivers/usb/Makefile.lib b/drivers/usb/Makefile.lib
80 --- /dev/null   Wed Dec 31 16:00:00 1969
81 +++ b/drivers/usb/Makefile.lib  Sat May 17 18:11:24 2003
82 @@ -0,0 +1,3 @@
83 +obj-$(CONFIG_USB_USBNET)               += crc32.o
84 +obj-$(CONFIG_USB_CATC)                 += crc32.o
85 +
86 diff -Nru a/drivers/usb/catc.c b/drivers/usb/catc.c
87 --- a/drivers/usb/catc.c        Sat May 17 18:11:24 2003
88 +++ b/drivers/usb/catc.c        Sat May 17 18:11:24 2003
89 @@ -42,6 +42,7 @@
90  #include <linux/skbuff.h>
91  #include <linux/spinlock.h>
92  #include <linux/ethtool.h>
93 +#include <linux/crc32.h>
94  #include <asm/bitops.h>
95  #include <asm/uaccess.h>
96  
97 @@ -596,20 +597,9 @@
98   * Receive modes. Broadcast, Multicast, Promisc.
99   */
100  
101 -static inline u32 ether_crc_le(int cnt, unsigned char *addr)
102 -{
103 -       unsigned int crc = 0xffffffff;
104 -       u8 byte, idx, bit;
105 -       
106 -        for (idx = 0; idx < cnt; idx++)
107 -                for (byte = *addr++, bit = 0; bit < 8; bit++, byte >>= 1)
108 -                        crc = (crc >> 1) ^ (((crc ^ byte) & 1) ? 0xedb88320U : 0);
109 -       return crc;
110 -}
111 -
112  static void catc_multicast(unsigned char *addr, u8 *multicast)
113  {
114 -       unsigned int crc = ether_crc_le(6, addr);
115 +       u32 crc = ether_crc_le(6, addr);
116         multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
117  }
118  
119 diff -Nru a/drivers/usb/usbnet.c b/drivers/usb/usbnet.c
120 --- a/drivers/usb/usbnet.c      Sat May 17 18:11:24 2003
121 +++ b/drivers/usb/usbnet.c      Sat May 17 18:11:24 2003
122 @@ -1306,6 +1306,8 @@
123  \f
124  #ifdef CONFIG_USB_ZAURUS
125  
126 +#include <linux/crc32.h>
127 +
128  /*-------------------------------------------------------------------------
129   *
130   * Zaurus is also a SA-1110 based PDA, but one using a different driver
131 @@ -1318,56 +1320,6 @@
132   *
133   *-------------------------------------------------------------------------*/
134  
135 -// FIXME try <linux/crc32.h> instead
136 -
137 -static const u32 crc32_table [256] = {
138 -    0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
139 -    0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
140 -    0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
141 -    0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
142 -    0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
143 -    0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
144 -    0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
145 -    0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
146 -    0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
147 -    0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
148 -    0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
149 -    0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
150 -    0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
151 -    0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
152 -    0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
153 -    0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
154 -    0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
155 -    0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
156 -    0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
157 -    0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
158 -    0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
159 -    0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
160 -    0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
161 -    0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
162 -    0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
163 -    0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
164 -    0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
165 -    0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
166 -    0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
167 -    0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
168 -    0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
169 -    0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
170 -};
171 -
172 -#define CRC32_INITFCS     0xffffffff  // Initial FCS value 
173 -#define CRC32_FCS(fcs, c) (((fcs) >> 8) ^ crc32_table[((fcs) ^ (c)) & 0xff])
174 -
175 -/* fcs_compute32 - memcpy and calculate fcs
176 - * Perform a memcpy and calculate fcs using ppp 32bit CRC algorithm.
177 - */
178 -static inline u32 fcs_compute32 (unsigned char *sp, int len, u32 fcs)
179 -{
180 -       for (;len-- > 0; fcs = CRC32_FCS (fcs, *sp++))
181 -               continue;
182 -       return fcs;
183 -}
184 -
185  static struct sk_buff *
186  zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
187  {
188 @@ -1387,7 +1338,7 @@
189         if (skb) {
190                 u32             fcs;
191  done:
192 -               fcs = fcs_compute32 (skb->data, skb->len, CRC32_INITFCS);
193 +               fcs = crc32_le (~0, skb->data, skb->len);
194                 fcs = ~fcs;
195  
196                 *skb_put (skb, 1) = fcs       & 0xff;
197 diff -Nru a/fs/Makefile.lib b/fs/Makefile.lib
198 --- /dev/null   Wed Dec 31 16:00:00 1969
199 +++ b/fs/Makefile.lib   Sat May 17 18:11:24 2003
200 @@ -0,0 +1,2 @@
201 +obj-$(CONFIG_JFFS2_FS)         += crc32.o
202 +obj-$(CONFIG_EFI_PARTITION)    += crc32.o
203 diff -Nru a/fs/jffs2/Makefile b/fs/jffs2/Makefile
204 --- a/fs/jffs2/Makefile Sat May 17 18:11:24 2003
205 +++ b/fs/jffs2/Makefile Sat May 17 18:11:24 2003
206 @@ -12,7 +12,7 @@
207  
208  COMPR_OBJS     := compr.o compr_rubin.o compr_rtime.o pushpull.o \
209                         compr_zlib.o
210 -JFFS2_OBJS     := crc32.o dir.o file.o ioctl.o nodelist.o malloc.o \
211 +JFFS2_OBJS     := dir.o file.o ioctl.o nodelist.o malloc.o \
212         read.o nodemgmt.o readinode.o super.o write.o scan.o gc.o \
213         symlink.o build.o erase.o background.o
214  
215 diff -Nru a/fs/jffs2/crc32.c b/fs/jffs2/crc32.c
216 --- a/fs/jffs2/crc32.c  Sat May 17 18:11:24 2003
217 +++ /dev/null   Wed Dec 31 16:00:00 1969
218 @@ -1,97 +0,0 @@
219 -/*
220 - *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
221 - *  code or tables extracted from it, as desired without restriction.
222 - *
223 - *  First, the polynomial itself and its table of feedback terms.  The
224 - *  polynomial is
225 - *  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
226 - *
227 - *  Note that we take it "backwards" and put the highest-order term in
228 - *  the lowest-order bit.  The X^32 term is "implied"; the LSB is the
229 - *  X^31 term, etc.  The X^0 term (usually shown as "+1") results in
230 - *  the MSB being 1
231 - *
232 - *  Note that the usual hardware shift register implementation, which
233 - *  is what we're using (we're merely optimizing it by doing eight-bit
234 - *  chunks at a time) shifts bits into the lowest-order term.  In our
235 - *  implementation, that means shifting towards the right.  Why do we
236 - *  do it this way?  Because the calculated CRC must be transmitted in
237 - *  order from highest-order term to lowest-order term.  UARTs transmit
238 - *  characters in order from LSB to MSB.  By storing the CRC this way
239 - *  we hand it to the UART in the order low-byte to high-byte; the UART
240 - *  sends each low-bit to hight-bit; and the result is transmission bit
241 - *  by bit from highest- to lowest-order term without requiring any bit
242 - *  shuffling on our part.  Reception works similarly
243 - *
244 - *  The feedback terms table consists of 256, 32-bit entries.  Notes
245 - *
246 - *      The table can be generated at runtime if desired; code to do so
247 - *      is shown later.  It might not be obvious, but the feedback
248 - *      terms simply represent the results of eight shift/xor opera
249 - *      tions for all combinations of data and CRC register values
250 - *
251 - *      The values must be right-shifted by eight bits by the "updcrc
252 - *      logic; the shift must be unsigned (bring in zeroes).  On some
253 - *      hardware you could probably optimize the shift in assembler by
254 - *      using byte-swap instructions
255 - *      polynomial $edb88320
256 - */
257 -
258 -/* $Id$ */
259 -
260 -#include "crc32.h"
261 -
262 -const __u32 crc32_table[256] = {
263 -       0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
264 -       0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
265 -       0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
266 -       0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
267 -       0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
268 -       0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
269 -       0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
270 -       0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
271 -       0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
272 -       0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
273 -       0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
274 -       0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
275 -       0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
276 -       0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
277 -       0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
278 -       0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
279 -       0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
280 -       0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
281 -       0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
282 -       0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
283 -       0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
284 -       0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
285 -       0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
286 -       0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
287 -       0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
288 -       0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
289 -       0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
290 -       0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
291 -       0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
292 -       0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
293 -       0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
294 -       0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
295 -       0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
296 -       0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
297 -       0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
298 -       0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
299 -       0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
300 -       0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
301 -       0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
302 -       0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
303 -       0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
304 -       0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
305 -       0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
306 -       0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
307 -       0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
308 -       0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
309 -       0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
310 -       0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
311 -       0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
312 -       0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
313 -       0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
314 -       0x2d02ef8dL
315 -};
316 diff -Nru a/fs/jffs2/crc32.h b/fs/jffs2/crc32.h
317 --- a/fs/jffs2/crc32.h  Sat May 17 18:11:24 2003
318 +++ /dev/null   Wed Dec 31 16:00:00 1969
319 @@ -1,21 +0,0 @@
320 -#ifndef CRC32_H
321 -#define CRC32_H
322 -
323 -/* $Id$ */
324 -
325 -#include <linux/types.h>
326 -
327 -extern const __u32 crc32_table[256];
328 -
329 -/* Return a 32-bit CRC of the contents of the buffer. */
330 -
331 -static inline __u32 
332 -crc32(__u32 val, const void *ss, int len)
333 -{
334 -       const unsigned char *s = ss;
335 -        while (--len >= 0)
336 -                val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
337 -        return val;
338 -}
339 -
340 -#endif
341 diff -Nru a/fs/jffs2/dir.c b/fs/jffs2/dir.c
342 --- a/fs/jffs2/dir.c    Sat May 17 18:11:24 2003
343 +++ b/fs/jffs2/dir.c    Sat May 17 18:11:24 2003
344 @@ -43,7 +43,7 @@
345  #include <linux/jffs2_fs_i.h>
346  #include <linux/jffs2_fs_sb.h>
347  #include "nodelist.h"
348 -#include "crc32.h"
349 +#include <linux/crc32.h>
350  
351  static int jffs2_readdir (struct file *, void *, filldir_t);
352  
353 diff -Nru a/fs/jffs2/erase.c b/fs/jffs2/erase.c
354 --- a/fs/jffs2/erase.c  Sat May 17 18:11:24 2003
355 +++ b/fs/jffs2/erase.c  Sat May 17 18:11:24 2003
356 @@ -40,7 +40,7 @@
357  #include <linux/jffs2.h>
358  #include <linux/interrupt.h>
359  #include "nodelist.h"
360 -#include "crc32.h"
361 +#include <linux/crc32.h>
362  
363  struct erase_priv_struct {
364         struct jffs2_eraseblock *jeb;
365 diff -Nru a/fs/jffs2/file.c b/fs/jffs2/file.c
366 --- a/fs/jffs2/file.c   Sat May 17 18:11:24 2003
367 +++ b/fs/jffs2/file.c   Sat May 17 18:11:24 2003
368 @@ -42,7 +42,7 @@
369  #include <linux/pagemap.h>
370  #include <linux/jffs2.h>
371  #include "nodelist.h"
372 -#include "crc32.h"
373 +#include <linux/crc32.h>
374  
375  extern int generic_file_open(struct inode *, struct file *) __attribute__((weak));
376  extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin) __attribute__((weak));
377 diff -Nru a/fs/jffs2/gc.c b/fs/jffs2/gc.c
378 --- a/fs/jffs2/gc.c     Sat May 17 18:11:24 2003
379 +++ b/fs/jffs2/gc.c     Sat May 17 18:11:24 2003
380 @@ -43,7 +43,7 @@
381  #include <linux/interrupt.h>
382  #include <linux/pagemap.h>
383  #include "nodelist.h"
384 -#include "crc32.h"
385 +#include <linux/crc32.h>
386  
387  static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 
388                                         struct inode *inode, struct jffs2_full_dnode *fd);
389 diff -Nru a/fs/jffs2/read.c b/fs/jffs2/read.c
390 --- a/fs/jffs2/read.c   Sat May 17 18:11:24 2003
391 +++ b/fs/jffs2/read.c   Sat May 17 18:11:24 2003
392 @@ -40,7 +40,7 @@
393  #include <linux/jffs2.h>
394  #include <linux/mtd/mtd.h>
395  #include "nodelist.h"
396 -#include "crc32.h"
397 +#include <linux/crc32.h>
398  
399  int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_full_dnode *fd, unsigned char *buf, int ofs, int len)
400  {
401 diff -Nru a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
402 --- a/fs/jffs2/readinode.c      Sat May 17 18:11:24 2003
403 +++ b/fs/jffs2/readinode.c      Sat May 17 18:11:24 2003
404 @@ -44,7 +44,7 @@
405  #include <linux/mtd/mtd.h>
406  #include <linux/jffs2.h>
407  #include "nodelist.h"
408 -#include "crc32.h"
409 +#include <linux/crc32.h>
410  
411  
412  D1(void jffs2_print_frag_list(struct jffs2_inode_info *f)
413 diff -Nru a/fs/jffs2/scan.c b/fs/jffs2/scan.c
414 --- a/fs/jffs2/scan.c   Sat May 17 18:11:24 2003
415 +++ b/fs/jffs2/scan.c   Sat May 17 18:11:24 2003
416 @@ -40,7 +40,7 @@
417  #include <linux/mtd/mtd.h>
418  #include <linux/pagemap.h>
419  #include "nodelist.h"
420 -#include "crc32.h"
421 +#include <linux/crc32.h>
422  
423  
424  #define DIRTY_SPACE(x) do { typeof(x) _x = (x); \
425 diff -Nru a/fs/jffs2/write.c b/fs/jffs2/write.c
426 --- a/fs/jffs2/write.c  Sat May 17 18:11:24 2003
427 +++ b/fs/jffs2/write.c  Sat May 17 18:11:24 2003
428 @@ -40,7 +40,7 @@
429  #include <linux/jffs2.h>
430  #include <linux/mtd/mtd.h>
431  #include "nodelist.h"
432 -#include "crc32.h"
433 +#include <linux/crc32.h>
434  
435  /* jffs2_new_inode: allocate a new inode and inocache, add it to the hash,
436     fill in the raw_inode while you're at it. */
437 diff -Nru a/fs/partitions/efi.c b/fs/partitions/efi.c
438 --- a/fs/partitions/efi.c       Sat May 17 18:11:24 2003
439 +++ b/fs/partitions/efi.c       Sat May 17 18:11:24 2003
440 @@ -99,6 +99,7 @@
441  #include <linux/slab.h>
442  #include <linux/smp_lock.h>
443  #include <linux/init.h>
444 +#include <linux/crc32.h>
445  #include <asm/system.h>
446  #include <asm/byteorder.h>
447  #include "check.h"
448 @@ -138,73 +139,6 @@
449  }
450  __setup("gpt", force_gpt_fn);
451  
452 -
453 -/*
454 - * There are multiple 16-bit CRC polynomials in common use, but this is
455 - * *the* standard CRC-32 polynomial, first popularized by Ethernet.
456 - * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0
457 - */
458 -#define CRCPOLY_LE 0xedb88320
459 -/* How many bits at a time to use.  Requires a table of 4<<CRC_xx_BITS bytes. */
460 -/* For less performance-sensitive, use 4 */
461 -#define CRC_LE_BITS 8
462 -static u32 *crc32table_le;
463 -
464 -/**
465 - * crc32init_le() - allocate and initialize LE table data
466 - *
467 - * crc is the crc of the byte i; other entries are filled in based on the
468 - * fact that crctable[i^j] = crctable[i] ^ crctable[j].
469 - *
470 - */
471 -static int __init crc32init_le(void)
472 -{
473 -       unsigned i, j;
474 -       u32 crc = 1;
475 -
476 -       crc32table_le =
477 -           kmalloc((1 << CRC_LE_BITS) * sizeof(u32), GFP_KERNEL);
478 -       if (!crc32table_le)
479 -               return 1;
480 -       crc32table_le[0] = 0;
481 -
482 -       for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) {
483 -               crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
484 -               for (j = 0; j < 1 << CRC_LE_BITS; j += 2 * i)
485 -                       crc32table_le[i + j] = crc ^ crc32table_le[j];
486 -       }
487 -       return 0;
488 -}
489 -
490 -/**
491 - * crc32cleanup_le(): free LE table data
492 - */
493 -static void __exit crc32cleanup_le(void)
494 -{
495 -       if (crc32table_le) kfree(crc32table_le);
496 -       crc32table_le = NULL;
497 -}
498 -
499 -__initcall(crc32init_le);
500 -__exitcall(crc32cleanup_le);
501 -
502 -/**
503 - * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
504 - * @crc - seed value for computation.  ~0 for Ethernet, sometimes 0 for
505 - *        other uses, or the previous crc32 value if computing incrementally.
506 - * @p   - pointer to buffer over which CRC is run
507 - * @len - length of buffer @p
508 - * 
509 - */
510 -static u32 crc32_le(u32 crc, unsigned char const *p, size_t len)
511 -{
512 -       while (len--) {
513 -               crc = (crc >> 8) ^ crc32table_le[(crc ^ *p++) & 255];
514 -       }
515 -       return crc;
516 -}
517 -
518 -
519  /**
520   * efi_crc32() - EFI version of crc32 function
521   * @buf: buffer to calculate crc32 of
522 @@ -220,7 +154,7 @@
523  static inline u32
524  efi_crc32(const void *buf, unsigned long len)
525  {
526 -       return (crc32_le(~0L, buf, len) ^ ~0L);
527 +       return (crc32(~0L, buf, len) ^ ~0L);
528  }
529  
530  /**
531 diff -Nru a/include/linux/crc32.h b/include/linux/crc32.h
532 --- a/include/linux/crc32.h     Sat May 17 18:11:24 2003
533 +++ b/include/linux/crc32.h     Sat May 17 18:11:24 2003
534 @@ -1,49 +1,27 @@
535  /*
536 - * crc32.h for early Linux 2.4.19pre kernel inclusion
537 - * This defines ether_crc_le() and ether_crc() as inline functions
538 - * This is slated to change to using the library crc32 functions
539 - * as kernel 2.5.2 included at some future date.
540 + * crc32.h
541 + * See linux/lib/crc32.c for license and changes
542   */
543  #ifndef _LINUX_CRC32_H
544  #define _LINUX_CRC32_H
545  
546  #include <linux/types.h>
547  
548 -/* The little-endian AUTODIN II ethernet CRC calculation.
549 -   N.B. Do not use for bulk data, use a table-based routine instead.
550 -   This is common code and should be moved to net/core/crc.c */
551 -static unsigned const ethernet_polynomial_le = 0xedb88320U;
552 -static inline unsigned ether_crc_le(int length, unsigned char *data)
553 -{
554 -       unsigned int crc = 0xffffffff;  /* Initial value. */
555 -       while(--length >= 0) {
556 -               unsigned char current_octet = *data++;
557 -               int bit;
558 -               for (bit = 8; --bit >= 0; current_octet >>= 1) {
559 -                       if ((crc ^ current_octet) & 1) {
560 -                               crc >>= 1;
561 -                               crc ^= ethernet_polynomial_le;
562 -                       } else
563 -                               crc >>= 1;
564 -               }
565 -       }
566 -       return crc;
567 -}
568 +extern u32  crc32_le(u32 crc, unsigned char const *p, size_t len);
569 +extern u32  crc32_be(u32 crc, unsigned char const *p, size_t len);
570 +extern u32  bitreverse(u32 in);
571  
572 -static unsigned const ethernet_polynomial = 0x04c11db7U;
573 -static inline u32 ether_crc(int length, unsigned char *data)
574 -{
575 -       int crc = -1;
576 -       while (--length >= 0) {
577 -               unsigned char current_octet = *data++;
578 -               int bit;
579 -               for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
580 -                       crc = (crc << 1) ^
581 -                               ((crc < 0) ^ (current_octet & 1) ?
582 -                                ethernet_polynomial : 0);
583 -               }
584 -       }
585 -       return crc;
586 -}
587 +#define crc32(seed, data, length)  crc32_le(seed, (unsigned char const *)data, length)
588 +
589 +/*
590 + * Helpers for hash table generation of ethernet nics:
591 + *
592 + * Ethernet sends the least significant bit of a byte first, thus crc32_le
593 + * is used. The output of crc32_le is bit reversed [most significant bit
594 + * is in bit nr 0], thus it must be reversed before use. Except for
595 + * nics that bit swap the result internally...
596 + */
597 +#define ether_crc(length, data)    bitreverse(crc32_le(~0, data, length))
598 +#define ether_crc_le(length, data) crc32_le(~0, data, length)
599  
600  #endif /* _LINUX_CRC32_H */
601 diff -Nru a/lib/Config.in b/lib/Config.in
602 --- a/lib/Config.in     Sat May 17 18:11:24 2003
603 +++ b/lib/Config.in     Sat May 17 18:11:24 2003
604 @@ -4,6 +4,8 @@
605  mainmenu_option next_comment
606  comment 'Library routines'
607  
608 +tristate 'CRC32 functions' CONFIG_CRC32
609 +
610  #
611  # Do we need the compression support?
612  #
613 diff -Nru a/lib/Makefile b/lib/Makefile
614 --- a/lib/Makefile      Sat May 17 18:11:24 2003
615 +++ b/lib/Makefile      Sat May 17 18:11:24 2003
616 @@ -1,4 +1,4 @@
617 -#
618 + #
619  # Makefile for some libs needed in the kernel.
620  #
621  # Note! Dependencies are done automagically by 'make dep', which also
622 @@ -8,7 +8,7 @@
623  L_TARGET := lib.a
624  
625  export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o rbtree.o \
626 -              qsort.o
627 +              qsort.o crc32.o
628  
629  obj-y := errno.o ctype.o string.o vsprintf.o brlock.o cmdline.o \
630          bust_spinlocks.o rbtree.o dump_stack.o
631 @@ -20,12 +20,27 @@
632    obj-y += dec_and_lock.o
633  endif
634  
635 +obj-$(CONFIG_CRC32)     += crc32.o
636 +
637  subdir-$(CONFIG_ZLIB_INFLATE) += zlib_inflate
638  subdir-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate
639  
640 +include $(TOPDIR)/drivers/net/Makefile.lib
641 +include $(TOPDIR)/drivers/usb/Makefile.lib
642 +include $(TOPDIR)/fs/Makefile.lib
643 +include $(TOPDIR)/net/bluetooth/bnep/Makefile.lib
644 +
645  obj-$(CONFIG_QSORT) += qsort.o
646  
647  # Include the subdirs, if necessary.
648  obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o))
649  
650  include $(TOPDIR)/Rules.make
651 +
652 +crc32.o: crc32table.h
653 +
654 +gen_crc32table: gen_crc32table.c
655 +       $(HOSTCC) $(HOSTCCFLAGS) -o $@ $<
656 +
657 +crc32table.h: gen_crc32table
658 +       ./$< > $@
659 diff -Nru a/lib/crc32.c b/lib/crc32.c
660 --- /dev/null   Wed Dec 31 16:00:00 1969
661 +++ b/lib/crc32.c       Sat May 17 18:11:24 2003
662 @@ -0,0 +1,536 @@
663 +/* 
664 + * Oct 15, 2000 Matt Domsch <Matt_Domsch@dell.com>
665 + * Nicer crc32 functions/docs submitted by linux@horizon.com.  Thanks!
666 + *
667 + * Oct 12, 2000 Matt Domsch <Matt_Domsch@dell.com>
668 + * Same crc32 function was used in 5 other places in the kernel.
669 + * I made one version, and deleted the others.
670 + * There are various incantations of crc32().  Some use a seed of 0 or ~0.
671 + * Some xor at the end with ~0.  The generic crc32() function takes
672 + * seed as an argument, and doesn't xor at the end.  Then individual
673 + * users can do whatever they need.
674 + *   drivers/net/smc9194.c uses seed ~0, doesn't xor with ~0.
675 + *   fs/jffs2 uses seed 0, doesn't xor with ~0.
676 + *   fs/partitions/efi.c uses seed ~0, xor's with ~0.
677 + * 
678 + */
679 +
680 +#include <linux/crc32.h>
681 +#include <linux/kernel.h>
682 +#include <linux/module.h>
683 +#include <linux/types.h>
684 +#include <linux/slab.h>
685 +#include <linux/init.h>
686 +#include <asm/atomic.h>
687 +#include "crc32defs.h"
688 +#if CRC_LE_BITS == 8
689 +#define tole(x) __constant_cpu_to_le32(x)
690 +#define tobe(x) __constant_cpu_to_be32(x)
691 +#else
692 +#define tole(x) (x)
693 +#define tobe(x) (x)
694 +#endif
695 +#include "crc32table.h"
696 +
697 +#if __GNUC__ >= 3      /* 2.x has "attribute", but only 3.0 has "pure */
698 +#define attribute(x) __attribute__(x)
699 +#else
700 +#define attribute(x)
701 +#endif
702 +
703 +/*
704 + * This code is in the public domain; copyright abandoned.
705 + * Liability for non-performance of this code is limited to the amount
706 + * you paid for it.  Since it is distributed for free, your refund will
707 + * be very very small.  If it breaks, you get to keep both pieces.
708 + */
709 +
710 +MODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>");
711 +MODULE_DESCRIPTION("Ethernet CRC32 calculations");
712 +MODULE_LICENSE("GPL and additional rights");
713 +
714 +#if CRC_LE_BITS == 1
715 +/*
716 + * In fact, the table-based code will work in this case, but it can be
717 + * simplified by inlining the table in ?: form.
718 + */
719 +
720 +/**
721 + * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
722 + * @crc - seed value for computation.  ~0 for Ethernet, sometimes 0 for
723 + *        other uses, or the previous crc32 value if computing incrementally.
724 + * @p   - pointer to buffer over which CRC is run
725 + * @len - length of buffer @p
726 + * 
727 + */
728 +u32 attribute((pure)) crc32_le(u32 crc, unsigned char const *p, size_t len)
729 +{
730 +       int i;
731 +       while (len--) {
732 +               crc ^= *p++;
733 +               for (i = 0; i < 8; i++)
734 +                       crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
735 +       }
736 +       return crc;
737 +}
738 +#else                          /* Table-based approach */
739 +
740 +/**
741 + * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
742 + * @crc - seed value for computation.  ~0 for Ethernet, sometimes 0 for
743 + *        other uses, or the previous crc32 value if computing incrementally.
744 + * @p   - pointer to buffer over which CRC is run
745 + * @len - length of buffer @p
746 + * 
747 + */
748 +u32 attribute((pure)) crc32_le(u32 crc, unsigned char const *p, size_t len)
749 +{
750 +# if CRC_LE_BITS == 8
751 +       const u32      *b =(u32 *)p;
752 +       const u32      *tab = crc32table_le;
753 +
754 +# ifdef __LITTLE_ENDIAN
755 +#  define DO_CRC crc = (crc>>8) ^ tab[ crc & 255 ]
756 +#  define ENDIAN_SHIFT 0
757 +# else
758 +#  define DO_CRC crc = (crc<<8) ^ tab[ crc >> 24 ]
759 +#  define ENDIAN_SHIFT 24
760 +# endif
761 +
762 +       crc = __cpu_to_le32(crc);
763 +       /* Align it */
764 +       if( ((u32)b)&3 && len){
765 +               do {
766 +                       crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
767 +                       DO_CRC;
768 +               } while ((--len) && ((u32)b)&3 );
769 +       }
770 +       if(len >= 4){
771 +               /* load data 32 bits wide, xor data 32 bits wide. */
772 +               size_t save_len = len & 3;
773 +               len = len >> 2;
774 +               --b; /* use pre increment below(*++b) for speed */
775 +               do {
776 +                       crc ^= *++b;
777 +                       DO_CRC;
778 +                       DO_CRC;
779 +                       DO_CRC;
780 +                       DO_CRC;
781 +               } while (--len);
782 +               b++; /* point to next byte(s) */
783 +               len = save_len;
784 +       }
785 +       /* And the last few bytes */
786 +       if(len){
787 +               do {
788 +                       crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
789 +                       DO_CRC;
790 +               } while (--len);
791 +       }
792 +
793 +       return __le32_to_cpu(crc);
794 +#undef ENDIAN_SHIFT
795 +#undef DO_CRC
796 +
797 +# elif CRC_LE_BITS == 4
798 +       while (len--) {
799 +               crc ^= *p++;
800 +               crc = (crc >> 4) ^ crc32table_le[crc & 15];
801 +               crc = (crc >> 4) ^ crc32table_le[crc & 15];
802 +       }
803 +       return crc;
804 +# elif CRC_LE_BITS == 2
805 +       while (len--) {
806 +               crc ^= *p++;
807 +               crc = (crc >> 2) ^ crc32table_le[crc & 3];
808 +               crc = (crc >> 2) ^ crc32table_le[crc & 3];
809 +               crc = (crc >> 2) ^ crc32table_le[crc & 3];
810 +               crc = (crc >> 2) ^ crc32table_le[crc & 3];
811 +       }
812 +       return crc;
813 +# endif
814 +}
815 +#endif
816 +
817 +#if CRC_BE_BITS == 1
818 +/*
819 + * In fact, the table-based code will work in this case, but it can be
820 + * simplified by inlining the table in ?: form.
821 + */
822 +
823 +/**
824 + * crc32_be() - Calculate bitwise big-endian Ethernet AUTODIN II CRC32
825 + * @crc - seed value for computation.  ~0 for Ethernet, sometimes 0 for
826 + *        other uses, or the previous crc32 value if computing incrementally.
827 + * @p   - pointer to buffer over which CRC is run
828 + * @len - length of buffer @p
829 + * 
830 + */
831 +u32 attribute((pure)) crc32_be(u32 crc, unsigned char const *p, size_t len)
832 +{
833 +       int i;
834 +       while (len--) {
835 +               crc ^= *p++ << 24;
836 +               for (i = 0; i < 8; i++)
837 +                       crc =
838 +                           (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE :
839 +                                         0);
840 +       }
841 +       return crc;
842 +}
843 +
844 +#else                          /* Table-based approach */
845 +/**
846 + * crc32_be() - Calculate bitwise big-endian Ethernet AUTODIN II CRC32
847 + * @crc - seed value for computation.  ~0 for Ethernet, sometimes 0 for
848 + *        other uses, or the previous crc32 value if computing incrementally.
849 + * @p   - pointer to buffer over which CRC is run
850 + * @len - length of buffer @p
851 + * 
852 + */
853 +u32 attribute((pure)) crc32_be(u32 crc, unsigned char const *p, size_t len)
854 +{
855 +# if CRC_BE_BITS == 8
856 +       const u32      *b =(u32 *)p;
857 +       const u32      *tab = crc32table_be;
858 +
859 +# ifdef __LITTLE_ENDIAN
860 +#  define DO_CRC crc = (crc>>8) ^ tab[ crc & 255 ]
861 +#  define ENDIAN_SHIFT 24
862 +# else
863 +#  define DO_CRC crc = (crc<<8) ^ tab[ crc >> 24 ]
864 +#  define ENDIAN_SHIFT 0
865 +# endif
866 +
867 +       crc = __cpu_to_be32(crc);
868 +       /* Align it */
869 +       if( ((u32)b)&3 && len){
870 +               do {
871 +                       crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
872 +                       DO_CRC;
873 +               } while ((--len) && ((u32)b)&3 );
874 +       }
875 +       if(len >= 4){
876 +               /* load data 32 bits wide, xor data 32 bits wide. */
877 +               size_t save_len = len & 3;
878 +               len = len >> 2;
879 +               --b; /* use pre increment below(*++b) for speed */
880 +               do {
881 +                       crc ^= *++b;
882 +                       DO_CRC;
883 +                       DO_CRC;
884 +                       DO_CRC;
885 +                       DO_CRC;
886 +               } while (--len);
887 +               b++; /* point to next byte(s) */
888 +               len = save_len;
889 +       }
890 +       /* And the last few bytes */
891 +       if(len){
892 +               do {
893 +                       crc ^= *((u8 *)b)++ << ENDIAN_SHIFT;
894 +                       DO_CRC;
895 +               } while (--len);
896 +       }
897 +       return __be32_to_cpu(crc);
898 +#undef ENDIAN_SHIFT
899 +#undef DO_CRC
900 +
901 +# elif CRC_BE_BITS == 4
902 +       while (len--) {
903 +               crc ^= *p++ << 24;
904 +               crc = (crc << 4) ^ crc32table_be[crc >> 28];
905 +               crc = (crc << 4) ^ crc32table_be[crc >> 28];
906 +       }
907 +       return crc;
908 +# elif CRC_BE_BITS == 2
909 +       while (len--) {
910 +               crc ^= *p++ << 24;
911 +               crc = (crc << 2) ^ crc32table_be[crc >> 30];
912 +               crc = (crc << 2) ^ crc32table_be[crc >> 30];
913 +               crc = (crc << 2) ^ crc32table_be[crc >> 30];
914 +               crc = (crc << 2) ^ crc32table_be[crc >> 30];
915 +       }
916 +       return crc;
917 +# endif
918 +}
919 +#endif
920 +
921 +u32 bitreverse(u32 x)
922 +{
923 +       x = (x >> 16) | (x << 16);
924 +       x = (x >> 8 & 0x00ff00ff) | (x << 8 & 0xff00ff00);
925 +       x = (x >> 4 & 0x0f0f0f0f) | (x << 4 & 0xf0f0f0f0);
926 +       x = (x >> 2 & 0x33333333) | (x << 2 & 0xcccccccc);
927 +       x = (x >> 1 & 0x55555555) | (x << 1 & 0xaaaaaaaa);
928 +       return x;
929 +}
930 +
931 +EXPORT_SYMBOL(crc32_le);
932 +EXPORT_SYMBOL(crc32_be);
933 +EXPORT_SYMBOL(bitreverse);
934 +
935 +/*
936 + * A brief CRC tutorial.
937 + *
938 + * A CRC is a long-division remainder.  You add the CRC to the message,
939 + * and the whole thing (message+CRC) is a multiple of the given
940 + * CRC polynomial.  To check the CRC, you can either check that the
941 + * CRC matches the recomputed value, *or* you can check that the
942 + * remainder computed on the message+CRC is 0.  This latter approach
943 + * is used by a lot of hardware implementations, and is why so many
944 + * protocols put the end-of-frame flag after the CRC.
945 + *
946 + * It's actually the same long division you learned in school, except that
947 + * - We're working in binary, so the digits are only 0 and 1, and
948 + * - When dividing polynomials, there are no carries.  Rather than add and
949 + *   subtract, we just xor.  Thus, we tend to get a bit sloppy about
950 + *   the difference between adding and subtracting.
951 + *
952 + * A 32-bit CRC polynomial is actually 33 bits long.  But since it's
953 + * 33 bits long, bit 32 is always going to be set, so usually the CRC
954 + * is written in hex with the most significant bit omitted.  (If you're
955 + * familiar with the IEEE 754 floating-point format, it's the same idea.)
956 + *
957 + * Note that a CRC is computed over a string of *bits*, so you have
958 + * to decide on the endianness of the bits within each byte.  To get
959 + * the best error-detecting properties, this should correspond to the
960 + * order they're actually sent.  For example, standard RS-232 serial is
961 + * little-endian; the most significant bit (sometimes used for parity)
962 + * is sent last.  And when appending a CRC word to a message, you should
963 + * do it in the right order, matching the endianness.
964 + *
965 + * Just like with ordinary division, the remainder is always smaller than
966 + * the divisor (the CRC polynomial) you're dividing by.  Each step of the
967 + * division, you take one more digit (bit) of the dividend and append it
968 + * to the current remainder.  Then you figure out the appropriate multiple
969 + * of the divisor to subtract to being the remainder back into range.
970 + * In binary, it's easy - it has to be either 0 or 1, and to make the
971 + * XOR cancel, it's just a copy of bit 32 of the remainder.
972 + *
973 + * When computing a CRC, we don't care about the quotient, so we can
974 + * throw the quotient bit away, but subtract the appropriate multiple of
975 + * the polynomial from the remainder and we're back to where we started,
976 + * ready to process the next bit.
977 + *
978 + * A big-endian CRC written this way would be coded like:
979 + * for (i = 0; i < input_bits; i++) {
980 + *     multiple = remainder & 0x80000000 ? CRCPOLY : 0;
981 + *     remainder = (remainder << 1 | next_input_bit()) ^ multiple;
982 + * }
983 + * Notice how, to get at bit 32 of the shifted remainder, we look
984 + * at bit 31 of the remainder *before* shifting it.
985 + *
986 + * But also notice how the next_input_bit() bits we're shifting into
987 + * the remainder don't actually affect any decision-making until
988 + * 32 bits later.  Thus, the first 32 cycles of this are pretty boring.
989 + * Also, to add the CRC to a message, we need a 32-bit-long hole for it at
990 + * the end, so we have to add 32 extra cycles shifting in zeros at the
991 + * end of every message,
992 + *
993 + * So the standard trick is to rearrage merging in the next_input_bit()
994 + * until the moment it's needed.  Then the first 32 cycles can be precomputed,
995 + * and merging in the final 32 zero bits to make room for the CRC can be
996 + * skipped entirely.
997 + * This changes the code to:
998 + * for (i = 0; i < input_bits; i++) {
999 + *      remainder ^= next_input_bit() << 31;
1000 + *     multiple = (remainder & 0x80000000) ? CRCPOLY : 0;
1001 + *     remainder = (remainder << 1) ^ multiple;
1002 + * }
1003 + * With this optimization, the little-endian code is simpler:
1004 + * for (i = 0; i < input_bits; i++) {
1005 + *      remainder ^= next_input_bit();
1006 + *     multiple = (remainder & 1) ? CRCPOLY : 0;
1007 + *     remainder = (remainder >> 1) ^ multiple;
1008 + * }
1009 + *
1010 + * Note that the other details of endianness have been hidden in CRCPOLY
1011 + * (which must be bit-reversed) and next_input_bit().
1012 + *
1013 + * However, as long as next_input_bit is returning the bits in a sensible
1014 + * order, we can actually do the merging 8 or more bits at a time rather
1015 + * than one bit at a time:
1016 + * for (i = 0; i < input_bytes; i++) {
1017 + *     remainder ^= next_input_byte() << 24;
1018 + *     for (j = 0; j < 8; j++) {
1019 + *             multiple = (remainder & 0x80000000) ? CRCPOLY : 0;
1020 + *             remainder = (remainder << 1) ^ multiple;
1021 + *     }
1022 + * }
1023 + * Or in little-endian:
1024 + * for (i = 0; i < input_bytes; i++) {
1025 + *     remainder ^= next_input_byte();
1026 + *     for (j = 0; j < 8; j++) {
1027 + *             multiple = (remainder & 1) ? CRCPOLY : 0;
1028 + *             remainder = (remainder << 1) ^ multiple;
1029 + *     }
1030 + * }
1031 + * If the input is a multiple of 32 bits, you can even XOR in a 32-bit
1032 + * word at a time and increase the inner loop count to 32.
1033 + *
1034 + * You can also mix and match the two loop styles, for example doing the
1035 + * bulk of a message byte-at-a-time and adding bit-at-a-time processing
1036 + * for any fractional bytes at the end.
1037 + *
1038 + * The only remaining optimization is to the byte-at-a-time table method.
1039 + * Here, rather than just shifting one bit of the remainder to decide
1040 + * in the correct multiple to subtract, we can shift a byte at a time.
1041 + * This produces a 40-bit (rather than a 33-bit) intermediate remainder,
1042 + * but again the multiple of the polynomial to subtract depends only on
1043 + * the high bits, the high 8 bits in this case.  
1044 + *
1045 + * The multile we need in that case is the low 32 bits of a 40-bit
1046 + * value whose high 8 bits are given, and which is a multiple of the
1047 + * generator polynomial.  This is simply the CRC-32 of the given
1048 + * one-byte message.
1049 + *
1050 + * Two more details: normally, appending zero bits to a message which
1051 + * is already a multiple of a polynomial produces a larger multiple of that
1052 + * polynomial.  To enable a CRC to detect this condition, it's common to
1053 + * invert the CRC before appending it.  This makes the remainder of the
1054 + * message+crc come out not as zero, but some fixed non-zero value.
1055 + *
1056 + * The same problem applies to zero bits prepended to the message, and
1057 + * a similar solution is used.  Instead of starting with a remainder of
1058 + * 0, an initial remainder of all ones is used.  As long as you start
1059 + * the same way on decoding, it doesn't make a difference.
1060 + */
1061 +
1062 +#if UNITTEST
1063 +
1064 +#include <stdlib.h>
1065 +#include <stdio.h>
1066 +
1067 +#if 0                          /*Not used at present */
1068 +static void
1069 +buf_dump(char const *prefix, unsigned char const *buf, size_t len)
1070 +{
1071 +       fputs(prefix, stdout);
1072 +       while (len--)
1073 +               printf(" %02x", *buf++);
1074 +       putchar('\n');
1075 +
1076 +}
1077 +#endif
1078 +
1079 +static void bytereverse(unsigned char *buf, size_t len)
1080 +{
1081 +       while (len--) {
1082 +               unsigned char x = *buf;
1083 +               x = (x >> 4) | (x << 4);
1084 +               x = (x >> 2 & 0x33) | (x << 2 & 0xcc);
1085 +               x = (x >> 1 & 0x55) | (x << 1 & 0xaa);
1086 +               *buf++ = x;
1087 +       }
1088 +}
1089 +
1090 +static void random_garbage(unsigned char *buf, size_t len)
1091 +{
1092 +       while (len--)
1093 +               *buf++ = (unsigned char) random();
1094 +}
1095 +
1096 +#if 0                          /* Not used at present */
1097 +static void store_le(u32 x, unsigned char *buf)
1098 +{
1099 +       buf[0] = (unsigned char) x;
1100 +       buf[1] = (unsigned char) (x >> 8);
1101 +       buf[2] = (unsigned char) (x >> 16);
1102 +       buf[3] = (unsigned char) (x >> 24);
1103 +}
1104 +#endif
1105 +
1106 +static void store_be(u32 x, unsigned char *buf)
1107 +{
1108 +       buf[0] = (unsigned char) (x >> 24);
1109 +       buf[1] = (unsigned char) (x >> 16);
1110 +       buf[2] = (unsigned char) (x >> 8);
1111 +       buf[3] = (unsigned char) x;
1112 +}
1113 +
1114 +/*
1115 + * This checks that CRC(buf + CRC(buf)) = 0, and that
1116 + * CRC commutes with bit-reversal.  This has the side effect
1117 + * of bytewise bit-reversing the input buffer, and returns
1118 + * the CRC of the reversed buffer.
1119 + */
1120 +static u32 test_step(u32 init, unsigned char *buf, size_t len)
1121 +{
1122 +       u32 crc1, crc2;
1123 +       size_t i;
1124 +
1125 +       crc1 = crc32_be(init, buf, len);
1126 +       store_be(crc1, buf + len);
1127 +       crc2 = crc32_be(init, buf, len + 4);
1128 +       if (crc2)
1129 +               printf("\nCRC cancellation fail: 0x%08x should be 0\n",
1130 +                      crc2);
1131 +
1132 +       for (i = 0; i <= len + 4; i++) {
1133 +               crc2 = crc32_be(init, buf, i);
1134 +               crc2 = crc32_be(crc2, buf + i, len + 4 - i);
1135 +               if (crc2)
1136 +                       printf("\nCRC split fail: 0x%08x\n", crc2);
1137 +       }
1138 +
1139 +       /* Now swap it around for the other test */
1140 +
1141 +       bytereverse(buf, len + 4);
1142 +       init = bitreverse(init);
1143 +       crc2 = bitreverse(crc1);
1144 +       if (crc1 != bitreverse(crc2))
1145 +               printf("\nBit reversal fail: 0x%08x -> %0x08x -> 0x%08x\n",
1146 +                      crc1, crc2, bitreverse(crc2));
1147 +       crc1 = crc32_le(init, buf, len);
1148 +       if (crc1 != crc2)
1149 +               printf("\nCRC endianness fail: 0x%08x != 0x%08x\n", crc1,
1150 +                      crc2);
1151 +       crc2 = crc32_le(init, buf, len + 4);
1152 +       if (crc2)
1153 +               printf("\nCRC cancellation fail: 0x%08x should be 0\n",
1154 +                      crc2);
1155 +
1156 +       for (i = 0; i <= len + 4; i++) {
1157 +               crc2 = crc32_le(init, buf, i);
1158 +               crc2 = crc32_le(crc2, buf + i, len + 4 - i);
1159 +               if (crc2)
1160 +                       printf("\nCRC split fail: 0x%08x\n", crc2);
1161 +       }
1162 +
1163 +       return crc1;
1164 +}
1165 +
1166 +#define SIZE 64
1167 +#define INIT1 0
1168 +#define INIT2 0
1169 +
1170 +int main(void)
1171 +{
1172 +       unsigned char buf1[SIZE + 4];
1173 +       unsigned char buf2[SIZE + 4];
1174 +       unsigned char buf3[SIZE + 4];
1175 +       int i, j;
1176 +       u32 crc1, crc2, crc3;
1177 +
1178 +       for (i = 0; i <= SIZE; i++) {
1179 +               printf("\rTesting length %d...", i);
1180 +               fflush(stdout);
1181 +               random_garbage(buf1, i);
1182 +               random_garbage(buf2, i);
1183 +               for (j = 0; j < i; j++)
1184 +                       buf3[j] = buf1[j] ^ buf2[j];
1185 +
1186 +               crc1 = test_step(INIT1, buf1, i);
1187 +               crc2 = test_step(INIT2, buf2, i);
1188 +               /* Now check that CRC(buf1 ^ buf2) = CRC(buf1) ^ CRC(buf2) */
1189 +               crc3 = test_step(INIT1 ^ INIT2, buf3, i);
1190 +               if (crc3 != (crc1 ^ crc2))
1191 +                       printf("CRC XOR fail: 0x%08x != 0x%08x ^ 0x%08x\n",
1192 +                              crc3, crc1, crc2);
1193 +       }
1194 +       printf("\nAll test complete.  No failures expected.\n");
1195 +       return 0;
1196 +}
1197 +
1198 +#endif                         /* UNITTEST */
1199 diff -Nru a/lib/crc32defs.h b/lib/crc32defs.h
1200 --- /dev/null   Wed Dec 31 16:00:00 1969
1201 +++ b/lib/crc32defs.h   Sat May 17 18:11:24 2003
1202 @@ -0,0 +1,28 @@
1203 +/*
1204 + * There are multiple 16-bit CRC polynomials in common use, but this is
1205 + * *the* standard CRC-32 polynomial, first popularized by Ethernet.
1206 + * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0
1207 + */
1208 +#define CRCPOLY_LE 0xedb88320
1209 +#define CRCPOLY_BE 0x04c11db7
1210 +
1211 +/* How many bits at a time to use.  Requires a table of 4<<CRC_xx_BITS bytes. */
1212 +/* For less performance-sensitive, use 4 */
1213 +#define CRC_LE_BITS 8
1214 +#define CRC_BE_BITS 8
1215 +
1216 +/*
1217 + * Little-endian CRC computation.  Used with serial bit streams sent
1218 + * lsbit-first.  Be sure to use cpu_to_le32() to append the computed CRC.
1219 + */
1220 +#if CRC_LE_BITS > 8 || CRC_LE_BITS < 1 || CRC_LE_BITS & CRC_LE_BITS-1
1221 +# error CRC_LE_BITS must be a power of 2 between 1 and 8
1222 +#endif
1223 +
1224 +/*
1225 + * Big-endian CRC computation.  Used with serial bit streams sent
1226 + * msbit-first.  Be sure to use cpu_to_be32() to append the computed CRC.
1227 + */
1228 +#if CRC_BE_BITS > 8 || CRC_BE_BITS < 1 || CRC_BE_BITS & CRC_BE_BITS-1
1229 +# error CRC_BE_BITS must be a power of 2 between 1 and 8
1230 +#endif
1231 diff -Nru a/lib/crc32table.h b/lib/crc32table.h
1232 --- /dev/null   Wed Dec 31 16:00:00 1969
1233 +++ b/lib/crc32table.h  Sat May 17 18:11:24 2003
1234 @@ -0,0 +1,134 @@
1235 +/* this file is generated - do not edit */
1236 +
1237 +static const u32 crc32table_le[] = {
1238 +tole(0x00000000L), tole(0x77073096L), tole(0xee0e612cL), tole(0x990951baL), 
1239 +tole(0x076dc419L), tole(0x706af48fL), tole(0xe963a535L), tole(0x9e6495a3L), 
1240 +tole(0x0edb8832L), tole(0x79dcb8a4L), tole(0xe0d5e91eL), tole(0x97d2d988L), 
1241 +tole(0x09b64c2bL), tole(0x7eb17cbdL), tole(0xe7b82d07L), tole(0x90bf1d91L), 
1242 +tole(0x1db71064L), tole(0x6ab020f2L), tole(0xf3b97148L), tole(0x84be41deL), 
1243 +tole(0x1adad47dL), tole(0x6ddde4ebL), tole(0xf4d4b551L), tole(0x83d385c7L), 
1244 +tole(0x136c9856L), tole(0x646ba8c0L), tole(0xfd62f97aL), tole(0x8a65c9ecL), 
1245 +tole(0x14015c4fL), tole(0x63066cd9L), tole(0xfa0f3d63L), tole(0x8d080df5L), 
1246 +tole(0x3b6e20c8L), tole(0x4c69105eL), tole(0xd56041e4L), tole(0xa2677172L), 
1247 +tole(0x3c03e4d1L), tole(0x4b04d447L), tole(0xd20d85fdL), tole(0xa50ab56bL), 
1248 +tole(0x35b5a8faL), tole(0x42b2986cL), tole(0xdbbbc9d6L), tole(0xacbcf940L), 
1249 +tole(0x32d86ce3L), tole(0x45df5c75L), tole(0xdcd60dcfL), tole(0xabd13d59L), 
1250 +tole(0x26d930acL), tole(0x51de003aL), tole(0xc8d75180L), tole(0xbfd06116L), 
1251 +tole(0x21b4f4b5L), tole(0x56b3c423L), tole(0xcfba9599L), tole(0xb8bda50fL), 
1252 +tole(0x2802b89eL), tole(0x5f058808L), tole(0xc60cd9b2L), tole(0xb10be924L), 
1253 +tole(0x2f6f7c87L), tole(0x58684c11L), tole(0xc1611dabL), tole(0xb6662d3dL), 
1254 +tole(0x76dc4190L), tole(0x01db7106L), tole(0x98d220bcL), tole(0xefd5102aL), 
1255 +tole(0x71b18589L), tole(0x06b6b51fL), tole(0x9fbfe4a5L), tole(0xe8b8d433L), 
1256 +tole(0x7807c9a2L), tole(0x0f00f934L), tole(0x9609a88eL), tole(0xe10e9818L), 
1257 +tole(0x7f6a0dbbL), tole(0x086d3d2dL), tole(0x91646c97L), tole(0xe6635c01L), 
1258 +tole(0x6b6b51f4L), tole(0x1c6c6162L), tole(0x856530d8L), tole(0xf262004eL), 
1259 +tole(0x6c0695edL), tole(0x1b01a57bL), tole(0x8208f4c1L), tole(0xf50fc457L), 
1260 +tole(0x65b0d9c6L), tole(0x12b7e950L), tole(0x8bbeb8eaL), tole(0xfcb9887cL), 
1261 +tole(0x62dd1ddfL), tole(0x15da2d49L), tole(0x8cd37cf3L), tole(0xfbd44c65L), 
1262 +tole(0x4db26158L), tole(0x3ab551ceL), tole(0xa3bc0074L), tole(0xd4bb30e2L), 
1263 +tole(0x4adfa541L), tole(0x3dd895d7L), tole(0xa4d1c46dL), tole(0xd3d6f4fbL), 
1264 +tole(0x4369e96aL), tole(0x346ed9fcL), tole(0xad678846L), tole(0xda60b8d0L), 
1265 +tole(0x44042d73L), tole(0x33031de5L), tole(0xaa0a4c5fL), tole(0xdd0d7cc9L), 
1266 +tole(0x5005713cL), tole(0x270241aaL), tole(0xbe0b1010L), tole(0xc90c2086L), 
1267 +tole(0x5768b525L), tole(0x206f85b3L), tole(0xb966d409L), tole(0xce61e49fL), 
1268 +tole(0x5edef90eL), tole(0x29d9c998L), tole(0xb0d09822L), tole(0xc7d7a8b4L), 
1269 +tole(0x59b33d17L), tole(0x2eb40d81L), tole(0xb7bd5c3bL), tole(0xc0ba6cadL), 
1270 +tole(0xedb88320L), tole(0x9abfb3b6L), tole(0x03b6e20cL), tole(0x74b1d29aL), 
1271 +tole(0xead54739L), tole(0x9dd277afL), tole(0x04db2615L), tole(0x73dc1683L), 
1272 +tole(0xe3630b12L), tole(0x94643b84L), tole(0x0d6d6a3eL), tole(0x7a6a5aa8L), 
1273 +tole(0xe40ecf0bL), tole(0x9309ff9dL), tole(0x0a00ae27L), tole(0x7d079eb1L), 
1274 +tole(0xf00f9344L), tole(0x8708a3d2L), tole(0x1e01f268L), tole(0x6906c2feL), 
1275 +tole(0xf762575dL), tole(0x806567cbL), tole(0x196c3671L), tole(0x6e6b06e7L), 
1276 +tole(0xfed41b76L), tole(0x89d32be0L), tole(0x10da7a5aL), tole(0x67dd4accL), 
1277 +tole(0xf9b9df6fL), tole(0x8ebeeff9L), tole(0x17b7be43L), tole(0x60b08ed5L), 
1278 +tole(0xd6d6a3e8L), tole(0xa1d1937eL), tole(0x38d8c2c4L), tole(0x4fdff252L), 
1279 +tole(0xd1bb67f1L), tole(0xa6bc5767L), tole(0x3fb506ddL), tole(0x48b2364bL), 
1280 +tole(0xd80d2bdaL), tole(0xaf0a1b4cL), tole(0x36034af6L), tole(0x41047a60L), 
1281 +tole(0xdf60efc3L), tole(0xa867df55L), tole(0x316e8eefL), tole(0x4669be79L), 
1282 +tole(0xcb61b38cL), tole(0xbc66831aL), tole(0x256fd2a0L), tole(0x5268e236L), 
1283 +tole(0xcc0c7795L), tole(0xbb0b4703L), tole(0x220216b9L), tole(0x5505262fL), 
1284 +tole(0xc5ba3bbeL), tole(0xb2bd0b28L), tole(0x2bb45a92L), tole(0x5cb36a04L), 
1285 +tole(0xc2d7ffa7L), tole(0xb5d0cf31L), tole(0x2cd99e8bL), tole(0x5bdeae1dL), 
1286 +tole(0x9b64c2b0L), tole(0xec63f226L), tole(0x756aa39cL), tole(0x026d930aL), 
1287 +tole(0x9c0906a9L), tole(0xeb0e363fL), tole(0x72076785L), tole(0x05005713L), 
1288 +tole(0x95bf4a82L), tole(0xe2b87a14L), tole(0x7bb12baeL), tole(0x0cb61b38L), 
1289 +tole(0x92d28e9bL), tole(0xe5d5be0dL), tole(0x7cdcefb7L), tole(0x0bdbdf21L), 
1290 +tole(0x86d3d2d4L), tole(0xf1d4e242L), tole(0x68ddb3f8L), tole(0x1fda836eL), 
1291 +tole(0x81be16cdL), tole(0xf6b9265bL), tole(0x6fb077e1L), tole(0x18b74777L), 
1292 +tole(0x88085ae6L), tole(0xff0f6a70L), tole(0x66063bcaL), tole(0x11010b5cL), 
1293 +tole(0x8f659effL), tole(0xf862ae69L), tole(0x616bffd3L), tole(0x166ccf45L), 
1294 +tole(0xa00ae278L), tole(0xd70dd2eeL), tole(0x4e048354L), tole(0x3903b3c2L), 
1295 +tole(0xa7672661L), tole(0xd06016f7L), tole(0x4969474dL), tole(0x3e6e77dbL), 
1296 +tole(0xaed16a4aL), tole(0xd9d65adcL), tole(0x40df0b66L), tole(0x37d83bf0L), 
1297 +tole(0xa9bcae53L), tole(0xdebb9ec5L), tole(0x47b2cf7fL), tole(0x30b5ffe9L), 
1298 +tole(0xbdbdf21cL), tole(0xcabac28aL), tole(0x53b39330L), tole(0x24b4a3a6L), 
1299 +tole(0xbad03605L), tole(0xcdd70693L), tole(0x54de5729L), tole(0x23d967bfL), 
1300 +tole(0xb3667a2eL), tole(0xc4614ab8L), tole(0x5d681b02L), tole(0x2a6f2b94L), 
1301 +tole(0xb40bbe37L), tole(0xc30c8ea1L), tole(0x5a05df1bL), tole(0x2d02ef8dL)
1302 +};
1303 +static const u32 crc32table_be[] = {
1304 +tobe(0x00000000L), tobe(0x04c11db7L), tobe(0x09823b6eL), tobe(0x0d4326d9L), 
1305 +tobe(0x130476dcL), tobe(0x17c56b6bL), tobe(0x1a864db2L), tobe(0x1e475005L), 
1306 +tobe(0x2608edb8L), tobe(0x22c9f00fL), tobe(0x2f8ad6d6L), tobe(0x2b4bcb61L), 
1307 +tobe(0x350c9b64L), tobe(0x31cd86d3L), tobe(0x3c8ea00aL), tobe(0x384fbdbdL), 
1308 +tobe(0x4c11db70L), tobe(0x48d0c6c7L), tobe(0x4593e01eL), tobe(0x4152fda9L), 
1309 +tobe(0x5f15adacL), tobe(0x5bd4b01bL), tobe(0x569796c2L), tobe(0x52568b75L), 
1310 +tobe(0x6a1936c8L), tobe(0x6ed82b7fL), tobe(0x639b0da6L), tobe(0x675a1011L), 
1311 +tobe(0x791d4014L), tobe(0x7ddc5da3L), tobe(0x709f7b7aL), tobe(0x745e66cdL), 
1312 +tobe(0x9823b6e0L), tobe(0x9ce2ab57L), tobe(0x91a18d8eL), tobe(0x95609039L), 
1313 +tobe(0x8b27c03cL), tobe(0x8fe6dd8bL), tobe(0x82a5fb52L), tobe(0x8664e6e5L), 
1314 +tobe(0xbe2b5b58L), tobe(0xbaea46efL), tobe(0xb7a96036L), tobe(0xb3687d81L), 
1315 +tobe(0xad2f2d84L), tobe(0xa9ee3033L), tobe(0xa4ad16eaL), tobe(0xa06c0b5dL), 
1316 +tobe(0xd4326d90L), tobe(0xd0f37027L), tobe(0xddb056feL), tobe(0xd9714b49L), 
1317 +tobe(0xc7361b4cL), tobe(0xc3f706fbL), tobe(0xceb42022L), tobe(0xca753d95L), 
1318 +tobe(0xf23a8028L), tobe(0xf6fb9d9fL), tobe(0xfbb8bb46L), tobe(0xff79a6f1L), 
1319 +tobe(0xe13ef6f4L), tobe(0xe5ffeb43L), tobe(0xe8bccd9aL), tobe(0xec7dd02dL), 
1320 +tobe(0x34867077L), tobe(0x30476dc0L), tobe(0x3d044b19L), tobe(0x39c556aeL), 
1321 +tobe(0x278206abL), tobe(0x23431b1cL), tobe(0x2e003dc5L), tobe(0x2ac12072L), 
1322 +tobe(0x128e9dcfL), tobe(0x164f8078L), tobe(0x1b0ca6a1L), tobe(0x1fcdbb16L), 
1323 +tobe(0x018aeb13L), tobe(0x054bf6a4L), tobe(0x0808d07dL), tobe(0x0cc9cdcaL), 
1324 +tobe(0x7897ab07L), tobe(0x7c56b6b0L), tobe(0x71159069L), tobe(0x75d48ddeL), 
1325 +tobe(0x6b93dddbL), tobe(0x6f52c06cL), tobe(0x6211e6b5L), tobe(0x66d0fb02L), 
1326 +tobe(0x5e9f46bfL), tobe(0x5a5e5b08L), tobe(0x571d7dd1L), tobe(0x53dc6066L), 
1327 +tobe(0x4d9b3063L), tobe(0x495a2dd4L), tobe(0x44190b0dL), tobe(0x40d816baL), 
1328 +tobe(0xaca5c697L), tobe(0xa864db20L), tobe(0xa527fdf9L), tobe(0xa1e6e04eL), 
1329 +tobe(0xbfa1b04bL), tobe(0xbb60adfcL), tobe(0xb6238b25L), tobe(0xb2e29692L), 
1330 +tobe(0x8aad2b2fL), tobe(0x8e6c3698L), tobe(0x832f1041L), tobe(0x87ee0df6L), 
1331 +tobe(0x99a95df3L), tobe(0x9d684044L), tobe(0x902b669dL), tobe(0x94ea7b2aL), 
1332 +tobe(0xe0b41de7L), tobe(0xe4750050L), tobe(0xe9362689L), tobe(0xedf73b3eL), 
1333 +tobe(0xf3b06b3bL), tobe(0xf771768cL), tobe(0xfa325055L), tobe(0xfef34de2L), 
1334 +tobe(0xc6bcf05fL), tobe(0xc27dede8L), tobe(0xcf3ecb31L), tobe(0xcbffd686L), 
1335 +tobe(0xd5b88683L), tobe(0xd1799b34L), tobe(0xdc3abdedL), tobe(0xd8fba05aL), 
1336 +tobe(0x690ce0eeL), tobe(0x6dcdfd59L), tobe(0x608edb80L), tobe(0x644fc637L), 
1337 +tobe(0x7a089632L), tobe(0x7ec98b85L), tobe(0x738aad5cL), tobe(0x774bb0ebL), 
1338 +tobe(0x4f040d56L), tobe(0x4bc510e1L), tobe(0x46863638L), tobe(0x42472b8fL), 
1339 +tobe(0x5c007b8aL), tobe(0x58c1663dL), tobe(0x558240e4L), tobe(0x51435d53L), 
1340 +tobe(0x251d3b9eL), tobe(0x21dc2629L), tobe(0x2c9f00f0L), tobe(0x285e1d47L), 
1341 +tobe(0x36194d42L), tobe(0x32d850f5L), tobe(0x3f9b762cL), tobe(0x3b5a6b9bL), 
1342 +tobe(0x0315d626L), tobe(0x07d4cb91L), tobe(0x0a97ed48L), tobe(0x0e56f0ffL), 
1343 +tobe(0x1011a0faL), tobe(0x14d0bd4dL), tobe(0x19939b94L), tobe(0x1d528623L), 
1344 +tobe(0xf12f560eL), tobe(0xf5ee4bb9L), tobe(0xf8ad6d60L), tobe(0xfc6c70d7L), 
1345 +tobe(0xe22b20d2L), tobe(0xe6ea3d65L), tobe(0xeba91bbcL), tobe(0xef68060bL), 
1346 +tobe(0xd727bbb6L), tobe(0xd3e6a601L), tobe(0xdea580d8L), tobe(0xda649d6fL), 
1347 +tobe(0xc423cd6aL), tobe(0xc0e2d0ddL), tobe(0xcda1f604L), tobe(0xc960ebb3L), 
1348 +tobe(0xbd3e8d7eL), tobe(0xb9ff90c9L), tobe(0xb4bcb610L), tobe(0xb07daba7L), 
1349 +tobe(0xae3afba2L), tobe(0xaafbe615L), tobe(0xa7b8c0ccL), tobe(0xa379dd7bL), 
1350 +tobe(0x9b3660c6L), tobe(0x9ff77d71L), tobe(0x92b45ba8L), tobe(0x9675461fL), 
1351 +tobe(0x8832161aL), tobe(0x8cf30badL), tobe(0x81b02d74L), tobe(0x857130c3L), 
1352 +tobe(0x5d8a9099L), tobe(0x594b8d2eL), tobe(0x5408abf7L), tobe(0x50c9b640L), 
1353 +tobe(0x4e8ee645L), tobe(0x4a4ffbf2L), tobe(0x470cdd2bL), tobe(0x43cdc09cL), 
1354 +tobe(0x7b827d21L), tobe(0x7f436096L), tobe(0x7200464fL), tobe(0x76c15bf8L), 
1355 +tobe(0x68860bfdL), tobe(0x6c47164aL), tobe(0x61043093L), tobe(0x65c52d24L), 
1356 +tobe(0x119b4be9L), tobe(0x155a565eL), tobe(0x18197087L), tobe(0x1cd86d30L), 
1357 +tobe(0x029f3d35L), tobe(0x065e2082L), tobe(0x0b1d065bL), tobe(0x0fdc1becL), 
1358 +tobe(0x3793a651L), tobe(0x3352bbe6L), tobe(0x3e119d3fL), tobe(0x3ad08088L), 
1359 +tobe(0x2497d08dL), tobe(0x2056cd3aL), tobe(0x2d15ebe3L), tobe(0x29d4f654L), 
1360 +tobe(0xc5a92679L), tobe(0xc1683bceL), tobe(0xcc2b1d17L), tobe(0xc8ea00a0L), 
1361 +tobe(0xd6ad50a5L), tobe(0xd26c4d12L), tobe(0xdf2f6bcbL), tobe(0xdbee767cL), 
1362 +tobe(0xe3a1cbc1L), tobe(0xe760d676L), tobe(0xea23f0afL), tobe(0xeee2ed18L), 
1363 +tobe(0xf0a5bd1dL), tobe(0xf464a0aaL), tobe(0xf9278673L), tobe(0xfde69bc4L), 
1364 +tobe(0x89b8fd09L), tobe(0x8d79e0beL), tobe(0x803ac667L), tobe(0x84fbdbd0L), 
1365 +tobe(0x9abc8bd5L), tobe(0x9e7d9662L), tobe(0x933eb0bbL), tobe(0x97ffad0cL), 
1366 +tobe(0xafb010b1L), tobe(0xab710d06L), tobe(0xa6322bdfL), tobe(0xa2f33668L), 
1367 +tobe(0xbcb4666dL), tobe(0xb8757bdaL), tobe(0xb5365d03L), tobe(0xb1f740b4L)
1368 +};
1369 diff -Nru a/lib/gen_crc32table.c b/lib/gen_crc32table.c
1370 --- /dev/null   Wed Dec 31 16:00:00 1969
1371 +++ b/lib/gen_crc32table.c      Sat May 17 18:11:24 2003
1372 @@ -0,0 +1,82 @@
1373 +#include <stdio.h>
1374 +#include "crc32defs.h"
1375 +#include <sys/types.h>
1376 +
1377 +#define ENTRIES_PER_LINE 4
1378 +
1379 +#define LE_TABLE_SIZE (1 << CRC_LE_BITS)
1380 +#define BE_TABLE_SIZE (1 << CRC_BE_BITS)
1381 +
1382 +static u_int32_t crc32table_le[LE_TABLE_SIZE];
1383 +static u_int32_t crc32table_be[BE_TABLE_SIZE];
1384 +
1385 +/**
1386 + * crc32init_le() - allocate and initialize LE table data
1387 + *
1388 + * crc is the crc of the byte i; other entries are filled in based on the
1389 + * fact that crctable[i^j] = crctable[i] ^ crctable[j].
1390 + *
1391 + */
1392 +static void crc32init_le(void)
1393 +{
1394 +       unsigned i, j;
1395 +       u_int32_t crc = 1;
1396 +
1397 +       crc32table_le[0] = 0;
1398 +
1399 +       for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) {
1400 +               crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
1401 +               for (j = 0; j < LE_TABLE_SIZE; j += 2 * i)
1402 +                       crc32table_le[i + j] = crc ^ crc32table_le[j];
1403 +       }
1404 +}
1405 +
1406 +/**
1407 + * crc32init_be() - allocate and initialize BE table data
1408 + */
1409 +static void crc32init_be(void)
1410 +{
1411 +       unsigned i, j;
1412 +       u_int32_t crc = 0x80000000;
1413 +
1414 +       crc32table_be[0] = 0;
1415 +
1416 +       for (i = 1; i < BE_TABLE_SIZE; i <<= 1) {
1417 +               crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0);
1418 +               for (j = 0; j < i; j++)
1419 +                       crc32table_be[i + j] = crc ^ crc32table_be[j];
1420 +       }
1421 +}
1422 +
1423 +static void output_table(u_int32_t table[], int len, char *trans)
1424 +{
1425 +       int i;
1426 +
1427 +       for (i = 0; i < len - 1; i++) {
1428 +               if (i % ENTRIES_PER_LINE == 0)
1429 +                       printf("\n");
1430 +               printf("%s(0x%8.8xL), ", trans, table[i]);
1431 +       }
1432 +       printf("%s(0x%8.8xL)\n", trans, table[len - 1]);
1433 +}
1434 +
1435 +int main(int argc, char** argv)
1436 +{
1437 +       printf("/* this file is generated - do not edit */\n\n");
1438 +
1439 +       if (CRC_LE_BITS > 1) {
1440 +               crc32init_le();
1441 +               printf("static const u32 crc32table_le[] = {");
1442 +               output_table(crc32table_le, LE_TABLE_SIZE, "tole");
1443 +               printf("};\n");
1444 +       }
1445 +
1446 +       if (CRC_BE_BITS > 1) {
1447 +               crc32init_be();
1448 +               printf("static const u32 crc32table_be[] = {");
1449 +               output_table(crc32table_be, BE_TABLE_SIZE, "tobe");
1450 +               printf("};\n");
1451 +       }
1452 +
1453 +       return 0;
1454 +}
1455 diff -Nru a/net/bluetooth/bnep/Makefile b/net/bluetooth/bnep/Makefile
1456 --- a/net/bluetooth/bnep/Makefile       Sat May 17 18:11:24 2003
1457 +++ b/net/bluetooth/bnep/Makefile       Sat May 17 18:11:24 2003
1458 @@ -4,7 +4,7 @@
1459  
1460  O_TARGET := bnep.o
1461  
1462 -obj-y   := core.o sock.o netdev.o crc32.o
1463 +obj-y   := core.o sock.o netdev.o
1464  obj-m    += $(O_TARGET)
1465  
1466  include $(TOPDIR)/Rules.make
1467 diff -Nru a/net/bluetooth/bnep/Makefile.lib b/net/bluetooth/bnep/Makefile.lib
1468 --- /dev/null   Wed Dec 31 16:00:00 1969
1469 +++ b/net/bluetooth/bnep/Makefile.lib   Sat May 17 18:11:24 2003
1470 @@ -0,0 +1 @@
1471 +obj-$(CONFIG_BLUEZ_BNEP) += crc32.o
1472 diff -Nru a/net/bluetooth/bnep/bnep.h b/net/bluetooth/bnep/bnep.h
1473 --- a/net/bluetooth/bnep/bnep.h Sat May 17 18:11:24 2003
1474 +++ b/net/bluetooth/bnep/bnep.h Sat May 17 18:11:24 2003
1475 @@ -26,7 +26,7 @@
1476  #include <linux/types.h>
1477  #include <net/bluetooth/bluetooth.h>
1478  
1479 -#include "crc32.h"
1480 +#include <linux/crc32.h>
1481  
1482  // Limits
1483  #define BNEP_MAX_PROTO_FILTERS     5
1484 @@ -179,7 +179,7 @@
1485  
1486  static inline int bnep_mc_hash(__u8 *addr)
1487  {
1488 -        return (bnep_crc32(~0, addr, ETH_ALEN) >> 26);
1489 +        return (crc32_be(~0, addr, ETH_ALEN) >> 26);
1490  }
1491  
1492  #endif
1493 diff -Nru a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
1494 --- a/net/bluetooth/bnep/core.c Sat May 17 18:11:24 2003
1495 +++ b/net/bluetooth/bnep/core.c Sat May 17 18:11:24 2003
1496 @@ -680,7 +680,6 @@
1497  
1498  static int __init bnep_init_module(void)
1499  {
1500 -       bnep_crc32_init();
1501         bnep_sock_init();
1502  
1503         BT_INFO("BlueZ BNEP ver %s", VERSION);
1504 @@ -695,7 +694,6 @@
1505  static void __exit bnep_cleanup_module(void)
1506  {
1507         bnep_sock_cleanup();
1508 -       bnep_crc32_cleanup();
1509  }
1510  
1511  module_init(bnep_init_module);
1512 diff -Nru a/net/bluetooth/bnep/crc32.c b/net/bluetooth/bnep/crc32.c
1513 --- a/net/bluetooth/bnep/crc32.c        Sat May 17 18:11:24 2003
1514 +++ /dev/null   Wed Dec 31 16:00:00 1969
1515 @@ -1,59 +0,0 @@
1516 -/* 
1517 - * Based on linux-2.5/lib/crc32 by Matt Domsch <Matt_Domsch@dell.com>
1518 - *
1519 - * FIXME: Remove in 2.5  
1520 - */
1521 -
1522 -#include <linux/kernel.h>
1523 -#include <linux/module.h>
1524 -#include <linux/types.h>
1525 -#include <linux/slab.h>
1526 -#include <linux/init.h>
1527 -#include <asm/atomic.h>
1528 -
1529 -#include "crc32.h"
1530 -
1531 -#define CRCPOLY_BE 0x04c11db7
1532 -#define CRC_BE_BITS 8
1533 -
1534 -static u32 *bnep_crc32_table;
1535 -
1536 -/*
1537 - * This code is in the public domain; copyright abandoned.
1538 - * Liability for non-performance of this code is limited to the amount
1539 - * you paid for it.  Since it is distributed for free, your refund will
1540 - * be very very small.  If it breaks, you get to keep both pieces.
1541 - */
1542 -u32 bnep_crc32(u32 crc, unsigned char const *p, size_t len)
1543 -{
1544 -       while (len--)
1545 -               crc = (crc << 8) ^ bnep_crc32_table[(crc >> 24) ^ *p++];
1546 -       
1547 -       return crc;
1548 -}
1549 -
1550 -int __init bnep_crc32_init(void)
1551 -{
1552 -       unsigned i, j;
1553 -       u32 crc = 0x80000000;
1554 -
1555 -       bnep_crc32_table = kmalloc((1 << CRC_BE_BITS) * sizeof(u32), GFP_KERNEL);
1556 -       if (!bnep_crc32_table)
1557 -               return -ENOMEM;
1558 -
1559 -       bnep_crc32_table[0] = 0;
1560 -
1561 -       for (i = 1; i < 1 << CRC_BE_BITS; i <<= 1) {
1562 -               crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0);
1563 -               for (j = 0; j < i; j++)
1564 -                       bnep_crc32_table[i + j] = crc ^ bnep_crc32_table[j];
1565 -       }
1566 -       return 0;
1567 -}
1568 -
1569 -void __exit bnep_crc32_cleanup(void)
1570 -{
1571 -       if (bnep_crc32_table)
1572 -               kfree(bnep_crc32_table);
1573 -       bnep_crc32_table = NULL;
1574 -}
1575 diff -Nru a/net/bluetooth/bnep/crc32.h b/net/bluetooth/bnep/crc32.h
1576 --- a/net/bluetooth/bnep/crc32.h        Sat May 17 18:11:24 2003
1577 +++ /dev/null   Wed Dec 31 16:00:00 1969
1578 @@ -1,10 +0,0 @@
1579 -/*
1580 - * crc32.h
1581 - * See crc32.c for license and changes
1582 - *
1583 - * FIXME: Remove in 2.5
1584 - */
1585 -
1586 -int  bnep_crc32_init(void);
1587 -void bnep_crc32_cleanup(void);
1588 -u32  bnep_crc32(u32 crc, unsigned char const *p, size_t len);
This page took 0.128311 seconds and 3 git commands to generate.