From b66d62c67d0c6e9c9e272002eb94f76bae347204 Mon Sep 17 00:00:00 2001 From: Ryan Thomas McBride Date: Sun, 6 Jun 2004 17:56:38 +0000 Subject: Multicast cleanups - make multicast ranges work - replace handrolled crc code with ether_crc32_{be,le}() - add missing calls to ether_{add,del}multi() ok deraadt@ --- sys/dev/usb/if_axe.c | 39 ++++++++++++--------------------------- sys/dev/usb/if_cue.c | 39 ++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 50 deletions(-) (limited to 'sys/dev/usb') 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; -- cgit v1.2.3