added a lot of printk output to ease writing of emulator
[linux-2.4.21-pre4.git] / include / linux / crc32.h
1 /*
2  * crc32.h for early Linux 2.4.19pre kernel inclusion
3  * This defines ether_crc_le() and ether_crc() as inline functions
4  * This is slated to change to using the library crc32 functions
5  * as kernel 2.5.2 included at some future date.
6  */
7 #ifndef _LINUX_CRC32_H
8 #define _LINUX_CRC32_H
9
10 #include <linux/types.h>
11
12 /* The little-endian AUTODIN II ethernet CRC calculation.
13    N.B. Do not use for bulk data, use a table-based routine instead.
14    This is common code and should be moved to net/core/crc.c */
15 static unsigned const ethernet_polynomial_le = 0xedb88320U;
16 static inline unsigned ether_crc_le(int length, unsigned char *data)
17 {
18         unsigned int crc = 0xffffffff;  /* Initial value. */
19         while(--length >= 0) {
20                 unsigned char current_octet = *data++;
21                 int bit;
22                 for (bit = 8; --bit >= 0; current_octet >>= 1) {
23                         if ((crc ^ current_octet) & 1) {
24                                 crc >>= 1;
25                                 crc ^= ethernet_polynomial_le;
26                         } else
27                                 crc >>= 1;
28                 }
29         }
30         return crc;
31 }
32
33 static unsigned const ethernet_polynomial = 0x04c11db7U;
34 static inline u32 ether_crc(int length, unsigned char *data)
35 {
36         int crc = -1;
37         while (--length >= 0) {
38                 unsigned char current_octet = *data++;
39                 int bit;
40                 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
41                         crc = (crc << 1) ^
42                                 ((crc < 0) ^ (current_octet & 1) ?
43                                  ethernet_polynomial : 0);
44                 }
45         }
46         return crc;
47 }
48
49 #endif /* _LINUX_CRC32_H */