-/* $OpenBSD: re.c,v 1.87 2008/08/13 03:18:19 brad Exp $ */
+/* $OpenBSD: re.c,v 1.88 2008/08/28 17:51:09 brad Exp $ */
/* $FreeBSD: if_re.c,v 1.31 2004/09/04 07:54:05 ru Exp $ */
/*
* Copyright (c) 1997, 1998-2003
void re_miibus_writereg(struct device *, int, int, int);
void re_miibus_statchg(struct device *);
-void re_setmulti(struct rl_softc *);
-void re_setpromisc(struct rl_softc *);
+void re_iff(struct rl_softc *);
void re_reset(struct rl_softc *);
#ifdef RE_DIAG
{
}
-/*
- * Program the 64-bit multicast hash filter.
- */
void
-re_setmulti(struct rl_softc *sc)
+re_iff(struct rl_softc *sc)
{
- struct ifnet *ifp;
+ struct ifnet *ifp = &sc->sc_arpcom.ac_if;
int h = 0;
u_int32_t hashes[2] = { 0, 0 };
u_int32_t rxfilt;
struct arpcom *ac = &sc->sc_arpcom;
struct ether_multi *enm;
struct ether_multistep step;
-
- ifp = &sc->sc_arpcom.ac_if;
rxfilt = CSR_READ_4(sc, RL_RXCFG);
+ rxfilt &= ~(RL_RXCFG_RX_ALLPHYS | RL_RXCFG_RX_MULTI);
+ ifp->if_flags &= ~IFF_ALLMULTI;
- if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
+ if (ifp->if_flags & IFF_PROMISC ||
+ ac->ac_multirangecnt > 0) {
+ ifp ->if_flags |= IFF_ALLMULTI;
rxfilt |= RL_RXCFG_RX_MULTI;
- CSR_WRITE_4(sc, RL_RXCFG, rxfilt);
- CSR_WRITE_4(sc, RL_MAR0, 0xFFFFFFFF);
- CSR_WRITE_4(sc, RL_MAR4, 0xFFFFFFFF);
- return;
- }
-
- /* first, zot all the existing hash bits */
- CSR_WRITE_4(sc, RL_MAR0, 0);
- CSR_WRITE_4(sc, RL_MAR4, 0);
-
- /* 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;
- mcnt = MAX_NUM_MULTICAST_ADDRESSES;
+ if (ifp->if_flags & IFF_PROMISC)
+ rxfilt |= RL_RXCFG_RX_ALLPHYS;
+ hashes[0] = hashes[1] = 0xFFFFFFFF;
+ } else {
+ /* first, zot all the existing hash bits */
+ CSR_WRITE_4(sc, RL_MAR0, 0);
+ CSR_WRITE_4(sc, RL_MAR4, 0);
+
+ /* now program new ones */
+ ETHER_FIRST_MULTI(step, ac, enm);
+ while (enm != NULL) {
+ h = ether_crc32_be(enm->enm_addrlo,
+ ETHER_ADDR_LEN) >> 26;
+ if (h < 32)
+ hashes[0] |= (1 << h);
+ else
+ hashes[1] |= (1 << (h - 32));
+ mcnt++;
+ ETHER_NEXT_MULTI(step, enm);
}
- if (mcnt == MAX_NUM_MULTICAST_ADDRESSES)
- break;
- h = (ether_crc32_be(enm->enm_addrlo,
- ETHER_ADDR_LEN) >> 26) & 0x0000003F;
- if (h < 32)
- hashes[0] |= (1 << h);
- else
- hashes[1] |= (1 << (h - 32));
- mcnt++;
- ETHER_NEXT_MULTI(step, enm);
+ if (mcnt)
+ rxfilt |= RL_RXCFG_RX_MULTI;
}
- if (mcnt)
- rxfilt |= RL_RXCFG_RX_MULTI;
- else
- rxfilt &= ~RL_RXCFG_RX_MULTI;
-
- CSR_WRITE_4(sc, RL_RXCFG, rxfilt);
-
/*
* For some unfathomable reason, RealTek decided to reverse
* the order of the multicast hash registers in the PCI Express
CSR_WRITE_4(sc, RL_MAR0, hashes[0]);
CSR_WRITE_4(sc, RL_MAR4, hashes[1]);
}
-}
-void
-re_setpromisc(struct rl_softc *sc)
-{
- struct ifnet *ifp;
- u_int32_t rxcfg = 0;
-
- ifp = &sc->sc_arpcom.ac_if;
-
- rxcfg = CSR_READ_4(sc, RL_RXCFG);
- if (ifp->if_flags & IFF_PROMISC)
- rxcfg |= RL_RXCFG_RX_ALLPHYS;
- else
- rxcfg &= ~RL_RXCFG_RX_ALLPHYS;
- CSR_WRITE_4(sc, RL_RXCFG, rxcfg);
+ CSR_WRITE_4(sc, RL_RXCFG, rxfilt);
}
void
CSR_WRITE_4(sc, RL_RXCFG, rxcfg);
- /* Set promiscuous mode. */
- re_setpromisc(sc);
-
- /*
- * Program the multicast filter, if necessary.
- */
- re_setmulti(sc);
+ /* Program promiscuous mode and multicast filters. */
+ re_iff(sc);
/*
* Enable interrupts.
break;
case SIOCSIFFLAGS:
if (ifp->if_flags & IFF_UP) {
- if (ifp->if_flags & IFF_RUNNING &&
- ((ifp->if_flags ^ sc->if_flags) &
- IFF_PROMISC)) {
- re_setpromisc(sc);
- } else {
- if (!(ifp->if_flags & IFF_RUNNING))
- re_init(ifp);
- }
+ if (ifp->if_flags & IFF_RUNNING)
+ re_iff(sc);
+ else
+ re_init(ifp);
} else {
if (ifp->if_flags & IFF_RUNNING)
re_stop(ifp, 1);
* filter accordingly.
*/
if (ifp->if_flags & IFF_RUNNING)
- re_setmulti(sc);
+ re_iff(sc);
error = 0;
}
break;