summaryrefslogtreecommitdiffstats
path: root/sys/dev/usb
diff options
context:
space:
mode:
authornaddy <naddy@FreeBSD.org>2004-06-09 14:34:04 +0000
committernaddy <naddy@FreeBSD.org>2004-06-09 14:34:04 +0000
commit03b06cd9a3bb0e9d75237994d18bd6d3b6469ac1 (patch)
tree63c1a8adb963adf2b159557569195cbc8c219d33 /sys/dev/usb
parentd57aeb149e038b4931b3859597fe80119588eebc (diff)
downloadFreeBSD-src-03b06cd9a3bb0e9d75237994d18bd6d3b6469ac1.zip
FreeBSD-src-03b06cd9a3bb0e9d75237994d18bd6d3b6469ac1.tar.gz
Replace handrolled CRC calculation with ether_crc32_[lb]e().
Diffstat (limited to 'sys/dev/usb')
-rw-r--r--sys/dev/usb/if_aue.c23
-rw-r--r--sys/dev/usb/if_axe.c27
-rw-r--r--sys/dev/usb/if_cue.c10
-rw-r--r--sys/dev/usb/if_rue.c31
4 files changed, 7 insertions, 84 deletions
diff --git a/sys/dev/usb/if_aue.c b/sys/dev/usb/if_aue.c
index 36bf5fa..22f2b7a 100644
--- a/sys/dev/usb/if_aue.c
+++ b/sys/dev/usb/if_aue.c
@@ -208,7 +208,6 @@ Static int aue_miibus_writereg(device_ptr_t, int, int, int);
Static void aue_miibus_statchg(device_ptr_t);
Static void aue_setmulti(struct aue_softc *);
-Static uint32_t aue_mchash(const uint8_t *);
Static void aue_reset(struct aue_softc *);
Static int aue_csr_read_1(struct aue_softc *, int);
@@ -519,27 +518,8 @@ aue_miibus_statchg(device_ptr_t dev)
return;
}
-#define AUE_POLY 0xEDB88320
#define AUE_BITS 6
-Static u_int32_t
-aue_mchash(const uint8_t *addr)
-{
- uint32_t crc;
- int idx, bit;
- uint8_t data;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (idx = 0; idx < 6; idx++) {
- for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
- crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0);
- }
-
- return (crc & ((1 << AUE_BITS) - 1));
-}
-
Static void
aue_setmulti(struct aue_softc *sc)
{
@@ -569,7 +549,8 @@ aue_setmulti(struct aue_softc *sc)
{
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
- h = aue_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
+ h = ether_crc32_le(LLADDR((struct sockaddr_dl *)
+ ifma->ifma_addr), ETHER_ADDR_LEN) & ((1 << AUE_BITS) - 1);
AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0x7));
}
diff --git a/sys/dev/usb/if_axe.c b/sys/dev/usb/if_axe.c
index 51eb4dc..440f468 100644
--- a/sys/dev/usb/if_axe.c
+++ b/sys/dev/usb/if_axe.c
@@ -140,7 +140,6 @@ Static int axe_ifmedia_upd(struct ifnet *);
Static void axe_ifmedia_sts(struct ifnet *, struct ifmediareq *);
Static void axe_setmulti(struct axe_softc *);
-Static uint32_t axe_mchash(const uint8_t *);
Static device_method_t axe_methods[] = {
/* Device interface */
@@ -313,29 +312,6 @@ axe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
return;
}
-Static uint32_t
-axe_mchash(const uint8_t *addr)
-{
- uint32_t crc, carry;
- int idx, bit;
- uint8_t data;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (idx = 0; idx < 6; idx++) {
- for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01);
- crc <<= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /* return the filter bit position */
- return((crc >> 26) & 0x0000003F);
-}
-
Static void
axe_setmulti(struct axe_softc *sc)
{
@@ -361,7 +337,8 @@ axe_setmulti(struct axe_softc *sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
- h = axe_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
+ h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
+ ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
hashtbl[h / 8] |= 1 << (h % 8);
}
diff --git a/sys/dev/usb/if_cue.c b/sys/dev/usb/if_cue.c
index 3ea9596..d7f5f6b 100644
--- a/sys/dev/usb/if_cue.c
+++ b/sys/dev/usb/if_cue.c
@@ -323,23 +323,15 @@ cue_getmac(struct cue_softc *sc, void *buf)
return(0);
}
-#define CUE_POLY 0xEDB88320
#define CUE_BITS 9
Static uint32_t
cue_mchash(const uint8_t *addr)
{
uint32_t crc;
- int idx, bit;
- uint8_t data;
/* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (idx = 0; idx < 6; idx++) {
- for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
- crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CUE_POLY : 0);
- }
+ crc = ether_crc32_le(addr, ETHER_ADDR_LEN);
return (crc & ((1 << CUE_BITS) - 1));
}
diff --git a/sys/dev/usb/if_rue.c b/sys/dev/usb/if_rue.c
index da7cebc..cc1f496 100644
--- a/sys/dev/usb/if_rue.c
+++ b/sys/dev/usb/if_rue.c
@@ -156,7 +156,6 @@ Static int rue_miibus_readreg(device_ptr_t, int, int);
Static int rue_miibus_writereg(device_ptr_t, int, int, int);
Static void rue_miibus_statchg(device_ptr_t);
-Static uint32_t rue_mchash(const uint8_t *);
Static void rue_setmulti(struct rue_softc *);
Static void rue_reset(struct rue_softc *);
@@ -460,33 +459,6 @@ rue_miibus_statchg(device_ptr_t dev)
}
/*
- * Calculate CRC of a multicast group address, return the upper 6 bits.
- */
-
-Static uint32_t
-rue_mchash(const uint8_t *addr)
-{
- uint32_t crc, carry;
- int idx, bit;
- uint8_t data;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (idx = 0; idx < 6; idx++) {
- for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01);
- crc <<= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /* return the filter bit position */
- return (crc >> 26);
-}
-
-/*
* Program the 64-bit multicast hash filter.
*/
@@ -526,7 +498,8 @@ rue_setmulti(struct rue_softc *sc)
{
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
- h = rue_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
+ h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
+ ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
if (h < 32)
hashes[0] |= (1 << h);
else
OpenPOWER on IntegriCloud