Skip to contentSkip to conversation

ether_crc wrong in 2.5.50

PATCH Manfred Spraul 1 participant 1 message Dec 10, 2002

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

The ether_crc were converted to use the crc32 library in 2.5. The conversion is incorrect:

crc32_le and _be are about the bit order in which the bits are processed:
_le means least significant bit first, _be msb first.

ethernet is always lsb first.
ether_crc means the output should be in the cpu bit order [msb in bit 31], ether_crc_le means the output should be with msb in bit 0: that what crc32_le usually generates.

The attached patch is tested with winbond-840, natsemi and 8139too, i.e. ether_crc works. ether_crc_le generates the same output as the inline functions from 2.4.18, but it's untested due to lack of nics.

Could someone test it on a nic that uses ether_crc_le?

Signature · 1 line
  Manfred

// $Header$
// Kernel Version:

//  VERSION = 2
//  PATCHLEVEL = 5
//  SUBLEVEL = 50
//  EXTRAVERSION =
include/linux/crc32.h +11 -1
@@ -9,9 +9,19 @@
 
 extern u32  crc32_le(u32 crc, unsigned char const *p, size_t len);
 extern u32  crc32_be(u32 crc, unsigned char const *p, size_t len);
+extern u32  bitreverse(u32 in);
 
 #define crc32(seed, data, length)  crc32_le(seed, (unsigned char const *)data, length)
+
+/*
+ * Helpers for hash table generation of ethernet nics:
+ *
+ * Ethernet sends the least significant bit of a byte first, thus crc32_le
+ * is used. The output of crc32_le is bit reversed [most significant bit
+ * is in bit nr 0], thus it must be reversed before use. Except for
+ * nics that bit swap the result internally...
+ */
+#define ether_crc(length, data)    bitreverse(crc32_le(~0, data, length))
 #define ether_crc_le(length, data) crc32_le(~0, data, length)
-#define ether_crc(length, data)    crc32_be(~0, data, length)
 
 #endif /* _LINUX_CRC32_H */
lib/crc32.c +10 -10
@@ -255,6 +255,16 @@
 }
 #endif
 
+u32 bitreverse(u32 x)
+{
+	x = (x >> 16) | (x << 16);
+	x = (x >> 8 & 0x00ff00ff) | (x << 8 & 0xff00ff00);
+	x = (x >> 4 & 0x0f0f0f0f) | (x << 4 & 0xf0f0f0f0);
+	x = (x >> 2 & 0x33333333) | (x << 2 & 0xcccccccc);
+	x = (x >> 1 & 0x55555555) | (x << 1 & 0xaaaaaaaa);
+	return x;
+}
+
 /*
  * A brief CRC tutorial.
  *
@@ -399,16 +409,6 @@
 }
 #endif
 
-static u32 attribute((const)) bitreverse(u32 x)
-{
-	x = (x >> 16) | (x << 16);
-	x = (x >> 8 & 0x00ff00ff) | (x << 8 & 0xff00ff00);
-	x = (x >> 4 & 0x0f0f0f0f) | (x << 4 & 0xf0f0f0f0);
-	x = (x >> 2 & 0x33333333) | (x << 2 & 0xcccccccc);
-	x = (x >> 1 & 0x55555555) | (x << 1 & 0xaaaaaaaa);
-	return x;
-}
-
 static void bytereverse(unsigned char *buf, size_t len)
 {
 	while (len--) {
drivers/net/natsemi.c +3 -41

62 lines not on this page · raw message