summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/ic/dp8390.c20
-rw-r--r--sys/dev/ic/rtl81x9.c38
-rw-r--r--sys/dev/isa/if_ed.c21
-rw-r--r--sys/dev/pci/if_ste.c37
-rw-r--r--sys/dev/pci/if_stge.c32
-rw-r--r--sys/dev/pci/if_vr.c39
-rw-r--r--sys/dev/pci/if_wb.c40
-rw-r--r--sys/dev/usb/if_axe.c39
-rw-r--r--sys/dev/usb/if_cue.c39
9 files changed, 67 insertions, 238 deletions
diff --git a/sys/dev/ic/dp8390.c b/sys/dev/ic/dp8390.c
index 37a461ef099..8f8ea1572ab 100644
--- a/sys/dev/ic/dp8390.c
+++ b/sys/dev/ic/dp8390.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dp8390.c,v 1.25 2004/05/12 06:35:10 tedu Exp $ */
+/* $OpenBSD: dp8390.c,v 1.26 2004/06/06 17:56:36 mcbride Exp $ */
/* $NetBSD: dp8390.c,v 1.13 1998/07/05 06:49:11 jonathan Exp $ */
/*
@@ -972,9 +972,8 @@ dp8390_getmcaf(ec, af)
{
struct ifnet *ifp = &ec->ac_if;
struct ether_multi *enm;
- u_int8_t *cp, c;
u_int32_t crc;
- int i, len;
+ int i;
struct ether_multistep step;
/*
@@ -1010,21 +1009,8 @@ dp8390_getmcaf(ec, af)
af[i] = 0xff;
return;
}
- cp = enm->enm_addrlo;
- crc = 0xffffffff;
- for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
- c = *cp++;
- for (i = 8; --i >= 0;) {
- if (((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01)) {
- crc <<= 1;
- crc ^= 0x04c11db6 | 1;
- } else
- crc <<= 1;
- c >>= 1;
- }
- }
/* Just want the 6 most significant bits. */
- crc >>= 26;
+ crc = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26;
/* Turn on the corresponding bit in the filter. */
af[crc >> 3] |= 1 << (crc & 0x7);
diff --git a/sys/dev/ic/rtl81x9.c b/sys/dev/ic/rtl81x9.c
index dcd99aeca5c..94705284561 100644
--- a/sys/dev/ic/rtl81x9.c
+++ b/sys/dev/ic/rtl81x9.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtl81x9.c,v 1.25 2004/05/19 11:36:59 brad Exp $ */
+/* $OpenBSD: rtl81x9.c,v 1.26 2004/06/06 17:56:36 mcbride Exp $ */
/*
* Copyright (c) 1997, 1998
@@ -160,7 +160,6 @@ int rl_miibus_readreg(struct device *, int, int);
void rl_miibus_writereg(struct device *, int, int, int);
void rl_miibus_statchg(struct device *);
-u_int8_t rl_calchash(caddr_t);
void rl_setmulti(struct rl_softc *);
void rl_reset(struct rl_softc *);
int rl_list_tx_init(struct rl_softc *);
@@ -461,34 +460,6 @@ int rl_mii_writereg(sc, frame)
}
/*
- * Calculate CRC of a multicast group address, return the upper 6 bits.
- */
-u_int8_t rl_calchash(addr)
- caddr_t addr;
-{
- u_int32_t crc, carry;
- int i, j;
- u_int8_t c;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (i = 0; i < 6; i++) {
- c = *(addr + i);
- for (j = 0; j < 8; j++) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
- crc <<= 1;
- c >>= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /* return the filter bit position */
- return(crc >> 26);
-}
-
-/*
* Program the 64-bit multicast hash filter.
*/
void rl_setmulti(sc)
@@ -507,6 +478,7 @@ void rl_setmulti(sc)
rxfilt = CSR_READ_4(sc, RL_RXCFG);
+allmulti:
if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
rxfilt |= RL_RXCFG_RX_MULTI;
CSR_WRITE_4(sc, RL_RXCFG, rxfilt);
@@ -522,8 +494,12 @@ void rl_setmulti(sc)
/* now program new ones */
ETHER_FIRST_MULTI(step, ac, enm);
while (enm != NULL) {
+ if (bcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
+ ifp->if_flags |= IFF_ALLMULTI;
+ goto allmulti;
+ }
mcnt++;
- h = rl_calchash(enm->enm_addrlo);
+ h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26;
if (h < 32)
hashes[0] |= (1 << h);
else
diff --git a/sys/dev/isa/if_ed.c b/sys/dev/isa/if_ed.c
index 5fbcec670d3..b74cd90ee28 100644
--- a/sys/dev/isa/if_ed.c
+++ b/sys/dev/isa/if_ed.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ed.c,v 1.52 2004/05/12 06:35:10 tedu Exp $ */
+/* $OpenBSD: if_ed.c,v 1.53 2004/06/06 17:56:36 mcbride Exp $ */
/* $NetBSD: if_ed.c,v 1.105 1996/10/21 22:40:45 thorpej Exp $ */
/*
@@ -2860,9 +2860,8 @@ ed_getmcaf(ac, af)
{
struct ifnet *ifp = &ac->ac_if;
struct ether_multi *enm;
- register u_char *cp, c;
register u_int32_t crc;
- register int i, len;
+ register int i;
struct ether_multistep step;
/*
@@ -2897,22 +2896,8 @@ ed_getmcaf(ac, af)
return;
}
- cp = enm->enm_addrlo;
- crc = 0xffffffff;
- for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
- c = *cp++;
- for (i = 8; --i >= 0;) {
- if (((crc & 0x80000000) ? 1 : 0)
- ^ (c & 0x01)) {
- crc <<= 1;
- crc ^= 0x04c11db6 | 1;
- } else
- crc <<= 1;
- c >>= 1;
- }
- }
/* Just want the 6 most significant bits. */
- crc >>= 26;
+ crc = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26;
/* Turn on the corresponding bit in the filter. */
af[crc >> 5] |= 1 << ((crc & 0x1f) ^ 0);
diff --git a/sys/dev/pci/if_ste.c b/sys/dev/pci/if_ste.c
index 4c10b2cdada..4b866fe8b84 100644
--- a/sys/dev/pci/if_ste.c
+++ b/sys/dev/pci/if_ste.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ste.c,v 1.21 2004/04/09 21:52:17 henning Exp $ */
+/* $OpenBSD: if_ste.c,v 1.22 2004/06/06 17:56:36 mcbride Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
@@ -115,7 +115,6 @@ int ste_eeprom_wait(struct ste_softc *);
int ste_read_eeprom(struct ste_softc *, caddr_t, int,
int, int);
void ste_wait(struct ste_softc *);
-u_int8_t ste_calchash(caddr_t);
void ste_setmulti(struct ste_softc *);
int ste_init_rx_list(struct ste_softc *);
void ste_init_tx_list(struct ste_softc *);
@@ -491,32 +490,6 @@ int ste_read_eeprom(sc, dest, off, cnt, swap)
return(err ? 1 : 0);
}
-u_int8_t ste_calchash(addr)
- caddr_t addr;
-{
-
- u_int32_t crc, carry;
- int i, j;
- u_int8_t c;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (i = 0; i < 6; i++) {
- c = *(addr + i);
- for (j = 0; j < 8; j++) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
- crc <<= 1;
- c >>= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /* return the filter bit position */
- return(crc & 0x0000003F);
-}
-
void ste_setmulti(sc)
struct ste_softc *sc;
{
@@ -528,6 +501,7 @@ void ste_setmulti(sc)
u_int32_t hashes[2] = { 0, 0 };
ifp = &sc->arpcom.ac_if;
+allmulti:
if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
STE_SETBIT1(sc, STE_RX_MODE, STE_RXMODE_ALLMULTI);
STE_CLRBIT1(sc, STE_RX_MODE, STE_RXMODE_MULTIHASH);
@@ -541,7 +515,12 @@ void ste_setmulti(sc)
/* now program new ones */
ETHER_FIRST_MULTI(step, ac, enm);
while (enm != NULL) {
- h = ste_calchash(enm->enm_addrlo);
+ if (bcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
+ ifp->if_flags |= IFF_ALLMULTI;
+ goto allmulti;
+ }
+ h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) &
+ 0x0000003F;
if (h < 32)
hashes[0] |= (1 << h);
else
diff --git a/sys/dev/pci/if_stge.c b/sys/dev/pci/if_stge.c
index bc45e7655ce..0313839531a 100644
--- a/sys/dev/pci/if_stge.c
+++ b/sys/dev/pci/if_stge.c
@@ -1860,33 +1860,6 @@ stge_add_rxbuf(struct stge_softc *sc, int idx)
return (0);
}
-u_int8_t stge_calchash(caddr_t);
-
-u_int8_t stge_calchash(addr)
- caddr_t addr;
-{
- u_int32_t crc, carry;
- int i, j;
- u_int8_t c;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (i = 0; i < 6; i++) {
- c = *(addr + i);
- for (j = 0; j < 8; j++) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
- crc <<= 1;
- c >>= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /* return the filter bit position */
- return(crc & 0x0000003F);
-}
-
/*
* stge_set_filter:
*
@@ -1923,7 +1896,10 @@ stge_set_filter(struct stge_softc *sc)
goto done;
while (enm != NULL) {
- h = stge_calchash(enm->enm_addrlo);
+ if (bcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN))
+ goto allmulti;
+ h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) &
+ 0x0000003F;
if (h < 32)
mchash[0] |= (1 << h);
else
diff --git a/sys/dev/pci/if_vr.c b/sys/dev/pci/if_vr.c
index 0148f7ae8f7..1981f62d666 100644
--- a/sys/dev/pci/if_vr.c
+++ b/sys/dev/pci/if_vr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_vr.c,v 1.42 2004/04/14 04:48:56 deraadt Exp $ */
+/* $OpenBSD: if_vr.c,v 1.43 2004/06/06 17:56:36 mcbride Exp $ */
/*
* Copyright (c) 1997, 1998
@@ -136,7 +136,6 @@ void vr_miibus_writereg(struct device *, int, int, int);
void vr_miibus_statchg(struct device *);
void vr_setcfg(struct vr_softc *, int);
-u_int8_t vr_calchash(u_int8_t *);
void vr_setmulti(struct vr_softc *);
void vr_reset(struct vr_softc *);
int vr_list_rx_init(struct vr_softc *);
@@ -491,35 +490,6 @@ vr_miibus_statchg(dev)
}
/*
- * Calculate CRC of a multicast group address, return the lower 6 bits.
- */
-u_int8_t
-vr_calchash(addr)
- u_int8_t *addr;
-{
- u_int32_t crc, carry;
- int i, j;
- u_int8_t c;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (i = 0; i < 6; i++) {
- c = *(addr + i);
- for (j = 0; j < 8; j++) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
- crc <<= 1;
- c >>= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /* return the filter bit position */
- return((crc >> 26) & 0x0000003F);
-}
-
-/*
* Program the 64-bit multicast hash filter.
*/
void
@@ -539,6 +509,7 @@ vr_setmulti(sc)
rxfilt = CSR_READ_1(sc, VR_RXCFG);
+allmulti:
if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
rxfilt |= VR_RXCFG_RX_MULTI;
CSR_WRITE_1(sc, VR_RXCFG, rxfilt);
@@ -554,7 +525,11 @@ vr_setmulti(sc)
/* now program new ones */
ETHER_FIRST_MULTI(step, ac, enm);
while (enm != NULL) {
- h = vr_calchash(enm->enm_addrlo);
+ if (bcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
+ ifp->if_flags |= IFF_ALLMULTI;
+ goto allmulti;
+ }
+ h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26;
if (h < 32)
hashes[0] |= (1 << h);
else
diff --git a/sys/dev/pci/if_wb.c b/sys/dev/pci/if_wb.c
index d74a612662b..de6d6ec090e 100644
--- a/sys/dev/pci/if_wb.c
+++ b/sys/dev/pci/if_wb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_wb.c,v 1.22 2003/08/19 14:01:35 mpech Exp $ */
+/* $OpenBSD: if_wb.c,v 1.23 2004/06/06 17:56:37 mcbride Exp $ */
/*
* Copyright (c) 1997, 1998
@@ -521,37 +521,6 @@ wb_miibus_statchg(dev)
wb_setcfg(sc, sc->sc_mii.mii_media_active);
}
-u_int8_t wb_calchash(addr)
- caddr_t addr;
-{
- u_int32_t crc, carry;
- int i, j;
- u_int8_t c;
-
- /* Compute CRC for the address value. */
- crc = 0xFFFFFFFF; /* initial value */
-
- for (i = 0; i < 6; i++) {
- c = *(addr + i);
- for (j = 0; j < 8; j++) {
- carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
- crc <<= 1;
- c >>= 1;
- if (carry)
- crc = (crc ^ 0x04c11db6) | carry;
- }
- }
-
- /*
- * return the filter bit position
- * Note: I arrived at the following nonsense
- * through experimentation. It's not the usual way to
- * generate the bit position but it's the only thing
- * I could come up with that works.
- */
- return(~(crc >> 26) & 0x0000003F);
-}
-
/*
* Program the 64-bit multicast hash filter.
*/
@@ -571,6 +540,7 @@ void wb_setmulti(sc)
rxfilt = CSR_READ_4(sc, WB_NETCFG);
+allmulti:
if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
rxfilt |= WB_NETCFG_RX_MULTI;
CSR_WRITE_4(sc, WB_NETCFG, rxfilt);
@@ -586,7 +556,11 @@ void wb_setmulti(sc)
/* now program new ones */
ETHER_FIRST_MULTI(step, ac, enm);
while (enm != NULL) {
- h = wb_calchash(enm->enm_addrlo);
+ if (bcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
+ ifp->if_flags |= IFF_ALLMULTI;
+ goto allmulti;
+ }
+ h = ~(ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26);
if (h < 32)
hashes[0] |= (1 << h);
else
diff --git a/sys/dev/usb/if_axe.c b/sys/dev/usb/if_axe.c
index 9249aabaf3a..07e84ba11a4 100644
--- a/sys/dev/usb/if_axe.c
+++ b/sys/dev/usb/if_axe.c
@@ -189,7 +189,6 @@ Static void axe_ifmedia_sts(struct ifnet *, struct ifmediareq *);
Static void axe_reset(struct axe_softc *sc);
Static void axe_setmulti(struct axe_softc *);
-Static u_int32_t axe_mchash(caddr_t);
Static void axe_lock_mii(struct axe_softc *sc);
Static void axe_unlock_mii(struct axe_softc *sc);
@@ -346,29 +345,6 @@ axe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
ifmr->ifm_status = mii->mii_media_status;
}
-Static u_int32_t
-axe_mchash(caddr_t addr)
-{
- u_int32_t crc, carry;
- int idx, bit;
- u_int8_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)
{
@@ -401,7 +377,7 @@ axe_setmulti(struct axe_softc *sc)
ETHER_ADDR_LEN) != 0)
goto allmulti;
- h = axe_mchash(enm->enm_addrlo);
+ h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26;
hashtbl[h / 8] |= 1 << (h % 8);
ETHER_NEXT_MULTI(step, enm);
}
@@ -1256,8 +1232,17 @@ axe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
- axe_setmulti(sc);
- error = 0;
+ error = (cmd == SIOCADDMULTI) ?
+ ether_addmulti(ifr, &sc->arpcom) :
+ ether_delmulti(ifr, &sc->arpcom);
+ if (error == ENETRESET) {
+ /*
+ * Multicast list has changed; set the hardware
+ * filter accordingly.
+ */
+ axe_setmulti(sc);
+ error = 0;
+ }
break;
case SIOCGIFMEDIA:
case SIOCSIFMEDIA:
diff --git a/sys/dev/usb/if_cue.c b/sys/dev/usb/if_cue.c
index bfefa57dbf7..39c39eb4056 100644
--- a/sys/dev/usb/if_cue.c
+++ b/sys/dev/usb/if_cue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_cue.c,v 1.19 2003/12/15 23:36:14 cedric Exp $ */
+/* $OpenBSD: if_cue.c,v 1.20 2004/06/06 17:56:37 mcbride Exp $ */
/* $NetBSD: if_cue.c,v 1.40 2002/07/11 21:14:26 augustss Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
@@ -161,7 +161,6 @@ Static void cue_stop(struct cue_softc *);
Static void cue_watchdog(struct ifnet *);
Static void cue_setmulti(struct cue_softc *);
-Static u_int32_t cue_crc(caddr_t);
Static void cue_reset(struct cue_softc *);
Static int cue_csr_read_1(struct cue_softc *, int);
@@ -359,25 +358,8 @@ cue_getmac(struct cue_softc *sc, void *buf)
return (0);
}
-#define CUE_POLY 0xEDB88320
#define CUE_BITS 9
-Static u_int32_t
-cue_crc(caddr_t addr)
-{
- u_int32_t idx, bit, data, crc;
-
- /* 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);
- }
-
- return (crc & ((1 << CUE_BITS) - 1));
-}
-
Static void
cue_setmulti(struct cue_softc *sc)
{
@@ -416,7 +398,8 @@ allmulti:
enm->enm_addrhi, ETHER_ADDR_LEN) != 0)
goto allmulti;
- h = cue_crc(enm->enm_addrlo);
+ h = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN) &
+ ((1 << CUE_BITS) - 1);
sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
ETHER_NEXT_MULTI(step, enm);
}
@@ -428,7 +411,8 @@ allmulti:
* so we can receive broadcast frames.
*/
if (ifp->if_flags & IFF_BROADCAST) {
- h = cue_crc(etherbroadcastaddr);
+ h = ether_crc32_le(etherbroadcastaddr, ETHER_ADDR_LEN) &
+ ((1 << CUE_BITS) - 1);
sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
}
@@ -1232,8 +1216,17 @@ cue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
- cue_setmulti(sc);
- error = 0;
+ error = (command == SIOCADDMULTI) ?
+ ether_addmulti(ifr, &sc->arpcom) :
+ ether_delmulti(ifr, &sc->arpcom);
+ if (error == ENETRESET) {
+ /*
+ * Multicast list has changed; set the hardware
+ * filter accordingly.
+ */
+ cue_setmulti(sc);
+ error = 0;
+ }
break;
default:
error = EINVAL;