Try to create some sort of consistency in how the routings to find the

multicast hash are written.  There are still two distinct algorithms used,
and there actually isn't any reason each driver should have its own copy
of this function as they could all share one copy of it (if it grew an
additional argument).
This commit is contained in:
obrien 2003-11-13 20:55:53 +00:00
parent 0a565c9c57
commit 73c5beec0f
31 changed files with 346 additions and 367 deletions

View File

@ -209,7 +209,7 @@ static void bge_ifmedia_sts (struct ifnet *, struct ifmediareq *);
static u_int8_t bge_eeprom_getbyte (struct bge_softc *, int, u_int8_t *);
static int bge_read_eeprom (struct bge_softc *, caddr_t, int, int);
static u_int32_t bge_crc (caddr_t);
static u_int32_t bge_mchash (caddr_t);
static void bge_setmulti (struct bge_softc *);
static void bge_handle_events (struct bge_softc *);
@ -1134,10 +1134,12 @@ bge_init_tx_ring(sc)
#define BGE_POLY 0xEDB88320
static u_int32_t
bge_crc(addr)
bge_mchash(addr)
caddr_t addr;
{
u_int32_t idx, bit, data, crc;
u_int32_t crc;
int idx, bit;
u_int8_t data;
/* Compute CRC for the address value. */
crc = 0xFFFFFFFF; /* initial value */
@ -1177,7 +1179,7 @@ bge_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = bge_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = bge_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
hashes[(h & 0x60) >> 5] |= 1 << (h & 0x1F);
}

View File

@ -264,8 +264,8 @@ static void dc_miibus_statchg (device_t);
static void dc_miibus_mediainit (device_t);
static void dc_setcfg (struct dc_softc *, int);
static u_int32_t dc_crc_le (struct dc_softc *, const uint8_t *);
static u_int32_t dc_crc_be (const uint8_t *);
static u_int32_t dc_mchash_le (struct dc_softc *, caddr_t);
static u_int32_t dc_mchash_be (caddr_t);
static void dc_setfilt_21143 (struct dc_softc *);
static void dc_setfilt_asix (struct dc_softc *);
static void dc_setfilt_admtek (struct dc_softc *);
@ -1021,9 +1021,11 @@ dc_miibus_mediainit(device_t dev)
#define DC_BITS_64 6
static u_int32_t
dc_crc_le(struct dc_softc *sc, const uint8_t *addr)
dc_mchash_le(struct dc_softc *sc, caddr_t addr)
{
uint32_t idx, bit, data, crc;
u_int32_t crc;
int idx, bit;
u_int8_t data;
/* Compute CRC for the address value. */
crc = 0xFFFFFFFF; /* initial value */
@ -1061,21 +1063,20 @@ dc_crc_le(struct dc_softc *sc, const uint8_t *addr)
* Calculate CRC of a multicast group address, return the lower 6 bits.
*/
static u_int32_t
dc_crc_be(const uint8_t *addr)
dc_mchash_be(caddr_t addr)
{
uint32_t crc, carry;
int i, j;
uint8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
for (idx = 0; idx < 6; idx++) {
for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) {
carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01);
data >>= 1;
crc <<= 1;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -1133,13 +1134,13 @@ dc_setfilt_21143(struct dc_softc *sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = dc_crc_le(sc,
h = dc_mchash_le(sc,
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
sp[h >> 4] |= htole32(1 << (h & 0xF));
}
if (ifp->if_flags & IFF_BROADCAST) {
h = dc_crc_le(sc, ifp->if_broadcastaddr);
h = dc_mchash_le(sc, ifp->if_broadcastaddr);
sp[h >> 4] |= htole32(1 << (h & 0xF));
}
@ -1203,9 +1204,11 @@ dc_setfilt_admtek(struct dc_softc *sc)
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
if (DC_IS_CENTAUR(sc))
h = dc_crc_le(sc, LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = dc_mchash_le(sc,
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
else
h = dc_crc_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = dc_mchash_be(
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else
@ -1271,7 +1274,7 @@ dc_setfilt_asix(struct dc_softc *sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = dc_crc_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = dc_mchash_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else
@ -1323,13 +1326,13 @@ dc_setfilt_xircom(struct dc_softc *sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = dc_crc_le(sc,
h = dc_mchash_le(sc,
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
sp[h >> 4] |= htole32(1 << (h & 0xF));
}
if (ifp->if_flags & IFF_BROADCAST) {
h = dc_crc_le(sc, ifp->if_broadcastaddr);
h = dc_mchash_le(sc, ifp->if_broadcastaddr);
sp[h >> 4] |= htole32(1 << (h & 0xF));
}

View File

@ -103,7 +103,7 @@ static u_short ed_pio_write_mbufs(struct ed_softc *, struct mbuf *, int);
static void ed_setrcr (struct ed_softc *);
static u_int32_t ds_crc (u_char *ep);
static u_int32_t ds_mchash (caddr_t addr);
/*
* Interrupt conversion table for WD/SMC ASIC/83C584
@ -3531,22 +3531,20 @@ ed_setrcr(sc)
* Compute crc for ethernet address
*/
static u_int32_t
ds_crc(ep)
u_char *ep;
ds_mchash(addr)
caddr_t addr;
{
#define POLYNOMIAL 0x04c11db6
#define ED_POLYNOMIAL 0x04c11db6
register u_int32_t crc = 0xffffffff;
register int carry, i, j;
register u_char b;
register int carry, idx, bit;
register u_char data;
for (i = 6; --i >= 0;) {
b = *ep++;
for (j = 8; --j >= 0;) {
carry = ((crc & 0x80000000) ? 1 : 0) ^ (b & 0x01);
for (idx = 6; --idx >= 0;) {
for (data = *addr++, bit = 8; --bit >= 0; data >>=1 ) {
carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01);
crc <<= 1;
b >>= 1;
if (carry)
crc = (crc ^ POLYNOMIAL) | carry;
crc = (crc ^ ED_POLYNOMIAL) | carry;
}
}
return crc;
@ -3572,7 +3570,7 @@ ds_getmcaf(sc, mcaf)
TAILQ_FOREACH(ifma, &sc->arpcom.ac_if.if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
index = ds_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr))
index = ds_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr))
>> 26;
af[index >> 3] |= 1 << (index & 7);
}

View File

@ -2046,26 +2046,24 @@ fe_write_mbufs (struct fe_softc *sc, struct mbuf *m)
/*
* Compute hash value for an Ethernet address
*/
static int
fe_hash ( u_char * ep )
static u_int32_t
fe_mchash (caddr_t addr)
{
#define FE_HASH_MAGIC_NUMBER 0xEDB88320L
#define FE_POLY 0xEDB88320L
u_long hash = 0xFFFFFFFFL;
int i, j;
u_char b;
u_long m;
u_long carry, crc = 0xFFFFFFFFL;
int idx, bit;
u_int8_t data;
for ( i = ETHER_ADDR_LEN; --i >= 0; ) {
b = *ep++;
for ( j = 8; --j >= 0; ) {
m = hash;
hash >>= 1;
if ( ( m ^ b ) & 1 ) hash ^= FE_HASH_MAGIC_NUMBER;
b >>= 1;
for ( idx = ETHER_ADDR_LEN; --idx >= 0; ) {
for (data = *addr++, bit = 8; --bit >= 0; data >>= 1) {
carry = crc;
crc >>= 1;
if ((carry ^ data) & 1)
crc ^= FE_POLY;
}
}
return ( ( int )( hash >> 26 ) );
return (crc >> 26);
}
/*
@ -2083,7 +2081,7 @@ fe_mcaf ( struct fe_softc *sc )
TAILQ_FOREACH(ifma, &sc->arpcom.ac_if.if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
index = fe_hash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
index = fe_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
#ifdef FE_DEBUG
printf("%s: hash(%6D) == %d\n",
sc->sc_xname, enm->enm_addrlo , ":", index);

View File

@ -152,7 +152,7 @@ static int lge_miibus_writereg(device_t, int, int, int);
static void lge_miibus_statchg(device_t);
static void lge_setmulti(struct lge_softc *);
static u_int32_t lge_crc(struct lge_softc *, caddr_t);
static u_int32_t lge_mchash(caddr_t);
static void lge_reset(struct lge_softc *);
static int lge_list_rx_init(struct lge_softc *);
static int lge_list_tx_init(struct lge_softc *);
@ -371,23 +371,20 @@ lge_miibus_statchg(dev)
}
static u_int32_t
lge_crc(sc, addr)
struct lge_softc *sc;
caddr_t addr;
lge_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -426,7 +423,7 @@ lge_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = lge_crc(sc, LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = lge_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else

View File

@ -190,22 +190,22 @@ lance_probe(struct lnc_softc *sc)
return (UNKNOWN);
}
static __inline u_long
ether_crc(const u_char *ether_addr)
static __inline u_int32_t
lnc_mchash(caddr_t ether_addr)
{
#define POLYNOMIAL 0xEDB88320UL
u_char i, j, addr;
u_int crc = 0xFFFFFFFFUL;
#define LNC_POLYNOMIAL 0xEDB88320UL
u_int32_t crc = 0xFFFFFFFFUL;
int idx, bit;
u_int8_t data;
for (i = 0; i < ETHER_ADDR_LEN; i++) {
addr = *ether_addr++;
for (j = 0; j < MULTICAST_FILTER_LEN; j++) {
crc = (crc >> 1) ^ (((crc ^ addr) & 1) ? POLYNOMIAL : 0);
addr >>= 1;
for (idx = 0; idx < ETHER_ADDR_LEN; idx++) {
for (data = *ether_addr++, bit = 0; bit < MULTICAST_FILTER_LEN; bit++) {
crc = (crc >> 1) ^ (((crc ^ data) & 1) ? LNC_POLYNOMIAL : 0);
data >>= 1;
}
}
return crc;
#undef POLYNOMIAL
#undef LNC_POLYNOMIAL
}
void
@ -262,8 +262,8 @@ lnc_setladrf(struct lnc_softc *sc)
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
index = ether_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr))
>> 26;
index = lnc_mchash(
LLADDR((struct sockaddr_dl *)ifma->ifma_addr)) >> 26;
sc->init_block->ladrf[index >> 3] |= 1 << (index & 7);
}
}

View File

@ -142,7 +142,7 @@ static void my_autoneg_mii(struct my_softc *, int, int);
static void my_setmode_mii(struct my_softc *, int);
static void my_getmode_mii(struct my_softc *);
static void my_setcfg(struct my_softc *, int);
static u_int8_t my_calchash(caddr_t);
static u_int32_t my_mchash(caddr_t);
static void my_setmulti(struct my_softc *);
static void my_reset(struct my_softc *);
static int my_list_rx_init(struct my_softc *);
@ -313,22 +313,20 @@ my_phy_writereg(struct my_softc * sc, int reg, int data)
return;
}
static u_int8_t
my_calchash(caddr_t addr)
static u_int32_t
my_mchash(caddr_t addr)
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -381,7 +379,7 @@ my_setmulti(struct my_softc * sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = my_calchash(LLADDR((struct sockaddr_dl *) ifma->ifma_addr));
h = my_mchash(LLADDR((struct sockaddr_dl *) ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else

View File

@ -187,7 +187,7 @@ static int nge_miibus_writereg(device_t, int, int, int);
static void nge_miibus_statchg(device_t);
static void nge_setmulti(struct nge_softc *);
static u_int32_t nge_crc(struct nge_softc *, caddr_t);
static u_int32_t nge_mchash(caddr_t);
static void nge_reset(struct nge_softc *);
static int nge_list_rx_init(struct nge_softc *);
static int nge_list_tx_init(struct nge_softc *);
@ -675,23 +675,20 @@ nge_miibus_statchg(dev)
}
static u_int32_t
nge_crc(sc, addr)
struct nge_softc *sc;
caddr_t addr;
nge_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -749,7 +746,7 @@ nge_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = nge_crc(sc, LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = nge_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
index = (h >> 4) & 0x7F;
bit = h & 0xF;
CSR_WRITE_4(sc, NGE_RXFILT_CTL,

View File

@ -225,7 +225,7 @@ static int re_miibus_readreg (device_t, int, int);
static int re_miibus_writereg (device_t, int, int, int);
static void re_miibus_statchg (device_t);
static u_int8_t re_calchash (caddr_t);
static u_int32_t re_mchash (caddr_t);
static void re_setmulti (struct rl_softc *);
static void re_reset (struct rl_softc *);
@ -574,23 +574,21 @@ re_miibus_statchg(dev)
/*
* Calculate CRC of a multicast group address, return the upper 6 bits.
*/
static u_int8_t
re_calchash(addr)
caddr_t addr;
static u_int32_t
re_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -634,7 +632,7 @@ re_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = re_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = re_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else

View File

@ -160,7 +160,7 @@ static int sf_setvlan (struct sf_softc *, int, u_int32_t);
#endif
static u_int8_t sf_read_eeprom (struct sf_softc *, int);
static u_int32_t sf_calchash (caddr_t);
static u_int32_t sf_mchash (caddr_t);
static int sf_miibus_readreg (device_t, int, int);
static int sf_miibus_writereg (device_t, int, int, int);
@ -260,22 +260,20 @@ csr_write_4(sc, reg, val)
}
static u_int32_t
sf_calchash(addr)
caddr_t addr;
sf_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -332,7 +330,7 @@ sf_sethash(sc, mac, prio)
if (mac == NULL)
return(EINVAL);
h = sf_calchash(mac);
h = sf_mchash(mac);
if (prio) {
SF_SETBIT(sc, SF_RXFILT_HASH_BASE + SF_RXFILT_HASH_PRIOOFF +

View File

@ -1,4 +1,4 @@
/* $OpenBSD: if_sk.c,v 1.33 2003/08/12 05:23:06 nate Exp $ */
/* $OpenBSD: if_sk.c,v 2.33 2003/08/12 05:23:06 nate Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
@ -226,7 +226,7 @@ static int sk_marv_miibus_writereg (struct sk_if_softc *, int, int,
int);
static void sk_marv_miibus_statchg (struct sk_if_softc *);
static u_int32_t sk_calchash (caddr_t);
static u_int32_t sk_mchash (caddr_t);
static void sk_setfilt (struct sk_if_softc *, caddr_t, int);
static void sk_setmulti (struct sk_if_softc *);
@ -715,10 +715,12 @@ sk_marv_miibus_statchg(sc_if)
#define SK_BITS 6
static u_int32_t
sk_calchash(addr)
caddr_t addr;
sk_mchash(addr)
caddr_t addr;
{
u_int32_t idx, bit, data, crc;
u_int32_t crc;
int idx, bit;
u_int8_t data;
/* Compute CRC for the address value. */
crc = 0xFFFFFFFF; /* initial value */
@ -798,7 +800,7 @@ sk_setmulti(sc_if)
continue;
}
h = sk_calchash(
h = sk_mchash(
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);

View File

@ -134,7 +134,7 @@ static void snwatchdog(struct ifnet *);
static void sn_setmcast(struct sn_softc *);
static int sn_getmcf(struct arpcom *ac, u_char *mcf);
static u_int sn_crc(u_char *);
static u_int32_t sn_mchash(caddr_t);
/* I (GB) have been unlucky getting the hardware padding
* to work properly.
@ -1440,7 +1440,8 @@ sn_getmcf(struct arpcom *ac, uint8_t *mcf)
TAILQ_FOREACH(ifma, &ac->ac_if.if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
return 0;
index = sn_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr)) & 0x3f;
index = sn_mchash(
LLADDR((struct sockaddr_dl *)ifma->ifma_addr)) & 0x3f;
index2 = 0;
for (i = 0; i < 6; i++) {
index2 <<= 1;
@ -1452,21 +1453,21 @@ sn_getmcf(struct arpcom *ac, uint8_t *mcf)
return 1; /* use multicast filter */
}
static u_int
sn_crc(u_char *s)
static u_int32_t
sn_mchash(caddr_t addr)
{
int perByte;
int perBit;
const uint32_t poly = 0xedb88320;
uint32_t v = 0xffffffff;
uint8_t c;
for (perByte = 0; perByte < ETHER_ADDR_LEN; perByte++) {
c = s[perByte];
for (perBit = 0; perBit < 8; perBit++) {
v = (v >> 1)^(((v ^ c) & 0x01) ? poly : 0);
c >>= 1;
u_int32_t crc;
int idx, bit;
u_int8_t data;
/* Compute CRC for the address value. */
crc = 0xFFFFFFFF; /* initial value */
for (idx = 0; idx < ETHER_ADDR_LEN; idx++) {
for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) {
crc = (crc >> 1)^(((crc ^ data) & 0x01) ? poly : 0);
}
}
return v;
return crc;
}

View File

@ -105,7 +105,7 @@ static void epic_start_activity(epic_softc_t *);
static void epic_set_rx_mode(epic_softc_t *);
static void epic_set_tx_mode(epic_softc_t *);
static void epic_set_mc_table(epic_softc_t *);
static u_int8_t epic_calchash(caddr_t);
static u_int32_t tx_mchash(caddr_t);
static int epic_read_eeprom(epic_softc_t *,u_int16_t);
static void epic_output_eepromw(epic_softc_t *, u_int16_t);
static u_int16_t epic_input_eepromw(epic_softc_t *);
@ -1416,8 +1416,7 @@ epic_set_mc_table(sc)
#endif
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = epic_calchash(
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = tx_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
filter[h >> 4] |= 1 << (h & 0xF);
}
@ -1430,23 +1429,21 @@ epic_set_mc_table(sc)
/*
* Synopsis: calculate EPIC's hash of multicast address.
*/
static u_int8_t
epic_calchash(addr)
static u_int32_t
tx_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}

View File

@ -1,4 +1,4 @@
/*
/*-
* Copyright (c) 1997, 1998, 1999, 2000
* Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
*
@ -210,7 +210,7 @@ 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 u_int32_t aue_crc(caddr_t);
Static u_int32_t aue_mchash(caddr_t);
Static void aue_reset(struct aue_softc *);
Static int aue_csr_read_1(struct aue_softc *, int);
@ -525,9 +525,11 @@ aue_miibus_statchg(device_ptr_t dev)
#define AUE_BITS 6
Static u_int32_t
aue_crc(caddr_t addr)
aue_mchash(caddr_t addr)
{
u_int32_t idx, bit, data, crc;
u_int32_t crc;
int idx, bit;
u_int8_t data;
/* Compute CRC for the address value. */
crc = 0xFFFFFFFF; /* initial value */
@ -569,7 +571,7 @@ aue_setmulti(struct aue_softc *sc)
{
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = aue_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = aue_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0x7));
}

View File

@ -28,7 +28,6 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <sys/cdefs.h>
@ -102,11 +101,6 @@ __FBSDID("$FreeBSD$");
#include <dev/usb/if_axereg.h>
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#endif
/*
* Various supported device vendors/products.
*/
@ -146,7 +140,7 @@ Static int axe_ifmedia_upd(struct ifnet *);
Static void axe_ifmedia_sts(struct ifnet *, struct ifmediareq *);
Static void axe_setmulti(struct axe_softc *);
Static u_int32_t axe_crc(caddr_t);
Static u_int32_t axe_mchash(caddr_t);
Static device_method_t axe_methods[] = {
/* Device interface */
@ -320,21 +314,19 @@ axe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
}
Static u_int32_t
axe_crc(caddr_t addr)
axe_mchash(caddr_t addr)
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -369,7 +361,7 @@ 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_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = axe_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
hashtbl[h / 8] |= 1 << (h % 8);
}

View File

@ -116,7 +116,7 @@ Static void cue_watchdog(struct ifnet *);
Static void cue_shutdown(device_ptr_t);
Static void cue_setmulti(struct cue_softc *);
Static u_int32_t cue_crc(const uint8_t *);
Static u_int32_t cue_mchash(caddr_t);
Static void cue_reset(struct cue_softc *);
Static int cue_csr_read_1(struct cue_softc *, int);
@ -331,9 +331,11 @@ cue_getmac(struct cue_softc *sc, void *buf)
#define CUE_BITS 9
Static u_int32_t
cue_crc(const uint8_t *addr)
cue_mchash(caddr_t addr)
{
uint32_t idx, bit, data, crc;
u_int32_t crc;
int idx, bit;
u_int8_t data;
/* Compute CRC for the address value. */
crc = 0xFFFFFFFF; /* initial value */
@ -376,7 +378,7 @@ cue_setmulti(struct cue_softc *sc)
{
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = cue_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = cue_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
}
@ -386,9 +388,9 @@ cue_setmulti(struct cue_softc *sc)
*/
if (ifp->if_flags & IFF_BROADCAST) {
#if __FreeBSD_version >= 500000
h = cue_crc(ifp->if_broadcastaddr);
h = cue_mchash(ifp->if_broadcastaddr);
#else
h = cue_crc(etherbroadcastaddr);
h = cue_mchash(etherbroadcastaddr);
#endif
sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
}

View File

@ -103,7 +103,7 @@ __FBSDID("$FreeBSD$");
#include "miibus_if.h"
#ifdef USB_DEBUG
static int ruedebug = 0;
Static int ruedebug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, rue, CTLFLAG_RW, 0, "USB rue");
SYSCTL_INT(_hw_usb_rue, OID_AUTO, debug, CTLFLAG_RW,
&ruedebug, 0, "rue debug level");
@ -157,7 +157,7 @@ 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 u_int8_t rue_calchash(caddr_t);
Static u_int32_t rue_mchash(caddr_t);
Static void rue_setmulti(struct rue_softc *);
Static void rue_reset(struct rue_softc *);
@ -464,22 +464,20 @@ rue_miibus_statchg(device_ptr_t dev)
* Calculate CRC of a multicast group address, return the upper 6 bits.
*/
static u_int8_t
rue_calchash(caddr_t addr)
Static u_int32_t
rue_mchash(caddr_t addr)
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -529,7 +527,7 @@ rue_setmulti(struct rue_softc *sc)
{
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = rue_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = rue_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else

View File

@ -161,7 +161,7 @@ static int vr_miibus_writereg (device_t, int, int, int);
static void vr_miibus_statchg (device_t);
static void vr_setcfg (struct vr_softc *, int);
static u_int8_t vr_calchash (u_int8_t *);
static u_int32_t vr_mchash (caddr_t);
static void vr_setmulti (struct vr_softc *);
static void vr_reset (struct vr_softc *);
static int vr_list_rx_init (struct vr_softc *);
@ -565,22 +565,21 @@ vr_miibus_statchg(dev)
/*
* Calculate CRC of a multicast group address, return the lower 6 bits.
*/
static u_int8_t vr_calchash(addr)
u_int8_t *addr;
static u_int32_t
vr_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -624,7 +623,7 @@ vr_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = vr_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = vr_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else

View File

@ -1,7 +1,4 @@
/*
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@ -131,7 +128,6 @@ __FBSDID("$FreeBSD$");
* All rights reserved.
*
*/
/*
Copyright 1988, 1989 by Olivetti Advanced Technology Center, Inc.,
Cupertino, California.
@ -154,7 +150,6 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
@ -177,6 +172,10 @@ NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* NOTE:
* by rvb:

View File

@ -22,13 +22,7 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: if_xe.c,v 1.20 1999/06/13 19:17:40 scott Exp $
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* Portions of this software were derived from Werner Koch's xirc2ps driver
* for Linux under the terms of the following license (from v1.30 of the
@ -62,6 +56,9 @@ __FBSDID("$FreeBSD$");
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* FreeBSD device driver for Xircom CreditCard PCMCIA Ethernet adapters. The
* following cards are currently known to work with the driver:
@ -166,7 +163,7 @@ static void xe_enable_intr (struct xe_softc *scp);
static void xe_disable_intr (struct xe_softc *scp);
static void xe_set_multicast (struct xe_softc *scp);
static void xe_set_addr (struct xe_softc *scp, u_int8_t* addr, unsigned idx);
static void xe_set_hash (struct xe_softc *scp, u_int8_t* addr);
static void xe_mchash (struct xe_softc *scp, caddr_t addr);
static int xe_pio_write_packet (struct xe_softc *scp, struct mbuf *mbp);
/*
@ -1302,7 +1299,7 @@ xe_set_multicast(struct xe_softc *scp) {
else
if (scp->mohawk)
/* Use hash filter on Mohawk and Dingo */
xe_set_hash(scp, LLADDR((struct sockaddr_dl *)maddr->ifma_addr));
xe_mchash(scp, LLADDR((struct sockaddr_dl *)maddr->ifma_addr));
else
/* Nowhere else to put them on CE2 */
break;
@ -1415,46 +1412,50 @@ xe_set_addr(struct xe_softc *scp, u_int8_t* addr, unsigned idx) {
* address.
*/
static void
xe_set_hash(struct xe_softc* scp, u_int8_t* addr) {
xe_mchash(struct xe_softc* scp, caddr_t addr) {
u_int32_t crc = 0xffffffff;
u_int8_t bit, byte, crc31, idx;
unsigned i, j;
int idx, bit;
u_int8_t carry, byte, data, crc31, hash;
/* Compute CRC of the address -- standard Ethernet CRC function */
for (i = 0; i < 6; i++) {
byte = addr[i];
for (j = 1; j <= 8; j++) {
for (data = *addr++, idx = 0; idx < 6; idx++, data >>= 1) {
for (bit = 1; bit <= 8; bit++) {
if (crc & 0x80000000)
crc31 = 0x01;
else
crc31 = 0;
bit = crc31 ^ (byte & 0x01);
carry = crc31 ^ (data & 0x01);
crc <<= 1;
byte >>= 1;
if (bit)
crc = (crc ^ XE_CRC_POLY)|1;
data >>= 1;
crc = (crc ^ XE_CRC_POLY) | (carry|0x1);
}
}
DEVPRINTF(3, (scp->dev, "set_hash: CRC = 0x%08x\n", crc));
/* Hash table index = 6 msbs of CRC, reversed */
for (i = 0, idx = 0; i < 6; i++) {
idx >>= 1;
/*
* Convert a CRC into an index into the multicast hash table. What we do is
* take the most-significant 6 bits of the CRC, reverse them, and use that as
* the bit number in the hash table. Bits 5:3 of the result give the byte
* within the table (0-7); bits 2:0 give the bit number within that byte (also
* 0-7), ie. the number of shifts needed to get it into the lsb position.
*/
for (idx = 0, hash = 0; idx < 6; idx++) {
hash >>= 1;
if (crc & 0x80000000) {
idx |= 0x20;
hash |= 0x20;
}
crc <<= 1;
}
/* Top 3 bits of idx give register - 8, bottom 3 give bit within register */
byte = idx >> 3 | 0x08;
bit = 0x01 << (idx & 0x07);
/* Top 3 bits of hash give register - 8, bottom 3 give bit within register */
byte = hash >> 3 | 0x08;
carry = 0x01 << (hash & 0x07);
DEVPRINTF(3, (scp->dev, "set_hash: idx = 0x%02x, byte = 0x%02x, bit = 0x%02x\n", idx, byte, bit));
DEVPRINTF(3, (scp->dev, "set_hash: hash = 0x%02x, byte = 0x%02x, carry = 0x%02x\n", hash, byte, carry));
XE_SELECT_PAGE(0x58);
XE_OUTB(byte, XE_INB(byte) | bit);
XE_OUTB(byte, XE_INB(byte) | carry);
}

View File

@ -264,8 +264,8 @@ static void dc_miibus_statchg (device_t);
static void dc_miibus_mediainit (device_t);
static void dc_setcfg (struct dc_softc *, int);
static u_int32_t dc_crc_le (struct dc_softc *, const uint8_t *);
static u_int32_t dc_crc_be (const uint8_t *);
static u_int32_t dc_mchash_le (struct dc_softc *, caddr_t);
static u_int32_t dc_mchash_be (caddr_t);
static void dc_setfilt_21143 (struct dc_softc *);
static void dc_setfilt_asix (struct dc_softc *);
static void dc_setfilt_admtek (struct dc_softc *);
@ -1021,9 +1021,11 @@ dc_miibus_mediainit(device_t dev)
#define DC_BITS_64 6
static u_int32_t
dc_crc_le(struct dc_softc *sc, const uint8_t *addr)
dc_mchash_le(struct dc_softc *sc, caddr_t addr)
{
uint32_t idx, bit, data, crc;
u_int32_t crc;
int idx, bit;
u_int8_t data;
/* Compute CRC for the address value. */
crc = 0xFFFFFFFF; /* initial value */
@ -1061,21 +1063,20 @@ dc_crc_le(struct dc_softc *sc, const uint8_t *addr)
* Calculate CRC of a multicast group address, return the lower 6 bits.
*/
static u_int32_t
dc_crc_be(const uint8_t *addr)
dc_mchash_be(caddr_t addr)
{
uint32_t crc, carry;
int i, j;
uint8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
for (idx = 0; idx < 6; idx++) {
for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) {
carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01);
data >>= 1;
crc <<= 1;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -1133,13 +1134,13 @@ dc_setfilt_21143(struct dc_softc *sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = dc_crc_le(sc,
h = dc_mchash_le(sc,
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
sp[h >> 4] |= htole32(1 << (h & 0xF));
}
if (ifp->if_flags & IFF_BROADCAST) {
h = dc_crc_le(sc, ifp->if_broadcastaddr);
h = dc_mchash_le(sc, ifp->if_broadcastaddr);
sp[h >> 4] |= htole32(1 << (h & 0xF));
}
@ -1203,9 +1204,11 @@ dc_setfilt_admtek(struct dc_softc *sc)
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
if (DC_IS_CENTAUR(sc))
h = dc_crc_le(sc, LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = dc_mchash_le(sc,
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
else
h = dc_crc_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = dc_mchash_be(
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else
@ -1271,7 +1274,7 @@ dc_setfilt_asix(struct dc_softc *sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = dc_crc_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = dc_mchash_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else
@ -1323,13 +1326,13 @@ dc_setfilt_xircom(struct dc_softc *sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = dc_crc_le(sc,
h = dc_mchash_le(sc,
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
sp[h >> 4] |= htole32(1 << (h & 0xF));
}
if (ifp->if_flags & IFF_BROADCAST) {
h = dc_crc_le(sc, ifp->if_broadcastaddr);
h = dc_mchash_le(sc, ifp->if_broadcastaddr);
sp[h >> 4] |= htole32(1 << (h & 0xF));
}

View File

@ -136,7 +136,7 @@ static void pcn_miibus_statchg (device_t);
static void pcn_setfilt (struct ifnet *);
static void pcn_setmulti (struct pcn_softc *);
static u_int32_t pcn_crc (caddr_t);
static u_int32_t pcn_mchash (caddr_t);
static void pcn_reset (struct pcn_softc *);
static int pcn_list_rx_init (struct pcn_softc *);
static int pcn_list_tx_init (struct pcn_softc *);
@ -309,10 +309,12 @@ pcn_miibus_statchg(dev)
#define DC_POLY 0xEDB88320
static u_int32_t
pcn_crc(addr)
caddr_t addr;
pcn_mchash(addr)
caddr_t addr;
{
u_int32_t idx, bit, data, crc;
u_int32_t crc;
int idx, bit;
u_int8_t data;
/* Compute CRC for the address value. */
crc = 0xFFFFFFFF; /* initial value */
@ -353,7 +355,7 @@ pcn_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = pcn_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = pcn_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
hashes[h >> 4] |= 1 << (h & 0xF);
}

View File

@ -207,7 +207,7 @@ static int rl_miibus_readreg (device_t, int, int);
static int rl_miibus_writereg (device_t, int, int, int);
static void rl_miibus_statchg (device_t);
static u_int8_t rl_calchash (caddr_t);
static u_int32_t rl_mchash (caddr_t);
static void rl_setmulti (struct rl_softc *);
static void rl_reset (struct rl_softc *);
static int rl_list_tx_init (struct rl_softc *);
@ -735,23 +735,21 @@ rl_miibus_statchg(dev)
/*
* Calculate CRC of a multicast group address, return the upper 6 bits.
*/
static u_int8_t
rl_calchash(addr)
caddr_t addr;
static u_int32_t
rl_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -795,7 +793,7 @@ rl_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = rl_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = rl_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else

View File

@ -160,7 +160,7 @@ static int sf_setvlan (struct sf_softc *, int, u_int32_t);
#endif
static u_int8_t sf_read_eeprom (struct sf_softc *, int);
static u_int32_t sf_calchash (caddr_t);
static u_int32_t sf_mchash (caddr_t);
static int sf_miibus_readreg (device_t, int, int);
static int sf_miibus_writereg (device_t, int, int, int);
@ -260,22 +260,20 @@ csr_write_4(sc, reg, val)
}
static u_int32_t
sf_calchash(addr)
caddr_t addr;
sf_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -332,7 +330,7 @@ sf_sethash(sc, mac, prio)
if (mac == NULL)
return(EINVAL);
h = sf_calchash(mac);
h = sf_mchash(mac);
if (prio) {
SF_SETBIT(sc, SF_RXFILT_HASH_BASE + SF_RXFILT_HASH_PRIOOFF +

View File

@ -156,7 +156,7 @@ static void sis_miibus_statchg (device_t);
static void sis_setmulti_sis (struct sis_softc *);
static void sis_setmulti_ns (struct sis_softc *);
static u_int32_t sis_crc (struct sis_softc *, caddr_t);
static u_int32_t sis_mchash (struct sis_softc *, caddr_t);
static void sis_reset (struct sis_softc *);
static int sis_list_rx_init (struct sis_softc *);
static int sis_list_tx_init (struct sis_softc *);
@ -838,23 +838,21 @@ sis_miibus_statchg(dev)
}
static u_int32_t
sis_crc(sc, addr)
sis_mchash(sc, addr)
struct sis_softc *sc;
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -910,7 +908,8 @@ sis_setmulti_ns(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = sis_crc(sc, LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = sis_mchash(sc,
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
index = h >> 3;
bit = h & 0x1F;
CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_FMEM_LO + index);
@ -960,7 +959,7 @@ sis_setmulti_sis(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = sis_crc(sc,
h = sis_mchash(sc,
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
hashes[h >> 4] |= 1 << (h & 0xf);
i++;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: if_sk.c,v 1.33 2003/08/12 05:23:06 nate Exp $ */
/* $OpenBSD: if_sk.c,v 2.33 2003/08/12 05:23:06 nate Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
@ -226,7 +226,7 @@ static int sk_marv_miibus_writereg (struct sk_if_softc *, int, int,
int);
static void sk_marv_miibus_statchg (struct sk_if_softc *);
static u_int32_t sk_calchash (caddr_t);
static u_int32_t sk_mchash (caddr_t);
static void sk_setfilt (struct sk_if_softc *, caddr_t, int);
static void sk_setmulti (struct sk_if_softc *);
@ -715,10 +715,12 @@ sk_marv_miibus_statchg(sc_if)
#define SK_BITS 6
static u_int32_t
sk_calchash(addr)
caddr_t addr;
sk_mchash(addr)
caddr_t addr;
{
u_int32_t idx, bit, data, crc;
u_int32_t crc;
int idx, bit;
u_int8_t data;
/* Compute CRC for the address value. */
crc = 0xFFFFFFFF; /* initial value */
@ -798,7 +800,7 @@ sk_setmulti(sc_if)
continue;
}
h = sk_calchash(
h = sk_mchash(
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);

View File

@ -119,7 +119,7 @@ static void ste_miibus_statchg (device_t);
static int ste_eeprom_wait (struct ste_softc *);
static int ste_read_eeprom (struct ste_softc *, caddr_t, int, int, int);
static void ste_wait (struct ste_softc *);
static u_int8_t ste_calchash (caddr_t);
static u_int32_t ste_mchash (caddr_t);
static void ste_setmulti (struct ste_softc *);
static int ste_init_rx_list (struct ste_softc *);
static void ste_init_tx_list (struct ste_softc *);
@ -552,24 +552,22 @@ ste_read_eeprom(sc, dest, off, cnt, swap)
return(err ? 1 : 0);
}
static u_int8_t
ste_calchash(addr)
caddr_t addr;
static u_int32_t
ste_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -605,7 +603,7 @@ ste_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = ste_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = ste_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else

View File

@ -300,7 +300,7 @@ static int tl_miibus_writereg (device_t, int, int, int);
static void tl_miibus_statchg (device_t);
static void tl_setmode (struct tl_softc *, int);
static int tl_calchash (caddr_t);
static u_int32_t tl_mchash (caddr_t);
static void tl_setmulti (struct tl_softc *);
static void tl_setfilt (struct tl_softc *, caddr_t, int);
static void tl_softreset (struct tl_softc *, int);
@ -889,11 +889,11 @@ tl_setmode(sc, media)
* Bytes 0-2 and 3-5 are symmetrical, so are folded together. Then
* the folded 24-bit value is split into 6-bit portions and XOR'd.
*/
static int
tl_calchash(addr)
caddr_t addr;
static u_int32_t
tl_mchash(addr)
caddr_t addr;
{
int t;
int t;
t = (addr[0] ^ addr[3]) << 16 | (addr[1] ^ addr[4]) << 8 |
(addr[2] ^ addr[5]);
@ -978,7 +978,7 @@ tl_setmulti(sc)
continue;
}
h = tl_calchash(
h = tl_mchash(
LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);

View File

@ -161,7 +161,7 @@ static int vr_miibus_writereg (device_t, int, int, int);
static void vr_miibus_statchg (device_t);
static void vr_setcfg (struct vr_softc *, int);
static u_int8_t vr_calchash (u_int8_t *);
static u_int32_t vr_mchash (caddr_t);
static void vr_setmulti (struct vr_softc *);
static void vr_reset (struct vr_softc *);
static int vr_list_rx_init (struct vr_softc *);
@ -565,22 +565,21 @@ vr_miibus_statchg(dev)
/*
* Calculate CRC of a multicast group address, return the lower 6 bits.
*/
static u_int8_t vr_calchash(addr)
u_int8_t *addr;
static u_int32_t
vr_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -624,7 +623,7 @@ vr_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = vr_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = vr_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else

View File

@ -175,7 +175,7 @@ static int wb_mii_readreg (struct wb_softc *, struct wb_mii_frame *);
static int wb_mii_writereg (struct wb_softc *, struct wb_mii_frame *);
static void wb_setcfg (struct wb_softc *, u_int32_t);
static u_int8_t wb_calchash (caddr_t);
static u_int32_t wb_mchash (caddr_t);
static void wb_setmulti (struct wb_softc *);
static void wb_reset (struct wb_softc *);
static void wb_fixmedia (struct wb_softc *);
@ -587,22 +587,21 @@ wb_miibus_statchg(dev)
return;
}
static u_int8_t wb_calchash(addr)
caddr_t addr;
static u_int32_t
wb_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -652,7 +651,7 @@ wb_setmulti(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = wb_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = wb_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
if (h < 32)
hashes[0] |= (1 << h);
else

View File

@ -239,7 +239,7 @@ static int xl_mii_writereg (struct xl_softc *, struct xl_mii_frame *);
static void xl_setcfg (struct xl_softc *);
static void xl_setmode (struct xl_softc *, int);
static u_int8_t xl_calchash (caddr_t);
static u_int32_t xl_mchash (caddr_t);
static void xl_setmulti (struct xl_softc *);
static void xl_setmulti_hash (struct xl_softc *);
static void xl_reset (struct xl_softc *);
@ -810,22 +810,21 @@ xl_read_eeprom(sc, dest, off, cnt, swap)
* 256 bit hash table. This means we have to use all 8 bits regardless.
* On older cards, the upper 2 bits will be ignored. Grrrr....
*/
static u_int8_t xl_calchash(addr)
caddr_t addr;
static u_int32_t
xl_mchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
int i, j;
u_int8_t c;
u_int32_t crc, carry;
int idx, bit;
u_int8_t data;
/* 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);
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;
c >>= 1;
if (carry)
crc = (crc ^ 0x04c11db6) | carry;
}
@ -906,7 +905,7 @@ xl_setmulti_hash(sc)
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
h = xl_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
h = xl_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_HASH|XL_HASH_SET|h);
mcnt++;
}