1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-20 11:11:24 +00:00

Rework RX filter programming by providing separate handler for

DP8381[56] and SiS 900/7016 controllers.  After r212119, sis(4) no
longer reinitializes controller if ALLMULTI/PROMISC was changed.
However, RX filter handling code assumed some bits of the RX filter
is programmed by driver initialization. This caused ALLMULTI/PROMISC
configuration is ignored under certain conditions.
Fix that issue by reprogramming all bits of RX filter register.
While I'm here follow recommended RX filter programming steps
recommended by National DP8381[56] data sheet(RX filter should be
is disabled before programming).

Reported by:	Paul Schenkeveld < freebsd () psconsult dot nl >
Tested by:	Paul Schenkeveld < freebsd () psconsult dot nl >
MFC after:	3 days
This commit is contained in:
Pyun YongHyeon 2011-01-18 17:50:14 +00:00
parent 6bd823f334
commit ed15702f7e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=217548

View File

@ -149,6 +149,9 @@ static int sis_ioctl(struct ifnet *, u_long, caddr_t);
static int sis_newbuf(struct sis_softc *, struct sis_rxdesc *); static int sis_newbuf(struct sis_softc *, struct sis_rxdesc *);
static int sis_resume(device_t); static int sis_resume(device_t);
static int sis_rxeof(struct sis_softc *); static int sis_rxeof(struct sis_softc *);
static void sis_rxfilter(struct sis_softc *);
static void sis_rxfilter_ns(struct sis_softc *);
static void sis_rxfilter_sis(struct sis_softc *);
static void sis_start(struct ifnet *); static void sis_start(struct ifnet *);
static void sis_startl(struct ifnet *); static void sis_startl(struct ifnet *);
static void sis_stop(struct sis_softc *); static void sis_stop(struct sis_softc *);
@ -806,80 +809,117 @@ sis_mchash(struct sis_softc *sc, const uint8_t *addr)
} }
static void static void
sis_setmulti_ns(struct sis_softc *sc) sis_rxfilter(struct sis_softc *sc)
{ {
struct ifnet *ifp;
struct ifmultiaddr *ifma;
uint32_t h = 0, i, filtsave;
int bit, index;
ifp = sc->sis_ifp; SIS_LOCK_ASSERT(sc);
if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { if (sc->sis_type == SIS_TYPE_83815)
SIS_CLRBIT(sc, SIS_RXFILT_CTL, NS_RXFILTCTL_MCHASH); sis_rxfilter_ns(sc);
SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ALLMULTI); else
return; sis_rxfilter_sis(sc);
}
/*
* We have to explicitly enable the multicast hash table
* on the NatSemi chip if we want to use it, which we do.
*/
SIS_SETBIT(sc, SIS_RXFILT_CTL, NS_RXFILTCTL_MCHASH);
SIS_CLRBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ALLMULTI);
filtsave = CSR_READ_4(sc, SIS_RXFILT_CTL);
/* first, zot all the existing hash bits */
for (i = 0; i < 32; i++) {
CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_FMEM_LO + (i*2));
CSR_WRITE_4(sc, SIS_RXFILT_DATA, 0);
}
if_maddr_rlock(ifp);
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
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);
if (bit > 0xF)
bit -= 0x10;
SIS_SETBIT(sc, SIS_RXFILT_DATA, (1 << bit));
}
if_maddr_runlock(ifp);
CSR_WRITE_4(sc, SIS_RXFILT_CTL, filtsave);
} }
static void static void
sis_setmulti_sis(struct sis_softc *sc) sis_rxfilter_ns(struct sis_softc *sc)
{ {
struct ifnet *ifp; struct ifnet *ifp;
struct ifmultiaddr *ifma; struct ifmultiaddr *ifma;
uint32_t h, i, n, ctl; uint32_t h, i, filter;
int bit, index;
ifp = sc->sis_ifp;
filter = CSR_READ_4(sc, SIS_RXFILT_CTL);
if (filter & SIS_RXFILTCTL_ENABLE) {
/*
* Filter should be disabled to program other bits.
*/
CSR_WRITE_4(sc, SIS_RXFILT_CTL, filter & ~SIS_RXFILTCTL_ENABLE);
CSR_READ_4(sc, SIS_RXFILT_CTL);
}
filter &= ~(NS_RXFILTCTL_ARP | NS_RXFILTCTL_PERFECT |
NS_RXFILTCTL_MCHASH | SIS_RXFILTCTL_ALLPHYS | SIS_RXFILTCTL_BROAD |
SIS_RXFILTCTL_ALLMULTI);
if (ifp->if_flags & IFF_BROADCAST)
filter |= SIS_RXFILTCTL_BROAD;
/*
* For the NatSemi chip, we have to explicitly enable the
* reception of ARP frames, as well as turn on the 'perfect
* match' filter where we store the station address, otherwise
* we won't receive unicasts meant for this host.
*/
filter |= NS_RXFILTCTL_ARP | NS_RXFILTCTL_PERFECT;
if (ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC)) {
filter |= SIS_RXFILTCTL_ALLMULTI;
if (ifp->if_flags & IFF_PROMISC)
filter |= SIS_RXFILTCTL_ALLPHYS;
} else {
/*
* We have to explicitly enable the multicast hash table
* on the NatSemi chip if we want to use it, which we do.
*/
filter |= NS_RXFILTCTL_MCHASH;
/* first, zot all the existing hash bits */
for (i = 0; i < 32; i++) {
CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_FMEM_LO +
(i * 2));
CSR_WRITE_4(sc, SIS_RXFILT_DATA, 0);
}
if_maddr_rlock(ifp);
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
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);
if (bit > 0xF)
bit -= 0x10;
SIS_SETBIT(sc, SIS_RXFILT_DATA, (1 << bit));
}
if_maddr_runlock(ifp);
}
CSR_WRITE_4(sc, SIS_RXFILT_CTL, filter);
CSR_READ_4(sc, SIS_RXFILT_CTL);
}
static void
sis_rxfilter_sis(struct sis_softc *sc)
{
struct ifnet *ifp;
struct ifmultiaddr *ifma;
uint32_t filter, h, i, n;
uint16_t hashes[16]; uint16_t hashes[16];
ifp = sc->sis_ifp; ifp = sc->sis_ifp;
/* hash table size */ /* hash table size */
if (sc->sis_rev >= SIS_REV_635 || if (sc->sis_rev >= SIS_REV_635 || sc->sis_rev == SIS_REV_900B)
sc->sis_rev == SIS_REV_900B)
n = 16; n = 16;
else else
n = 8; n = 8;
ctl = CSR_READ_4(sc, SIS_RXFILT_CTL) & SIS_RXFILTCTL_ENABLE; filter = CSR_READ_4(sc, SIS_RXFILT_CTL);
if (filter & SIS_RXFILTCTL_ENABLE) {
CSR_WRITE_4(sc, SIS_RXFILT_CTL, filter & ~SIS_RXFILT_CTL);
CSR_READ_4(sc, SIS_RXFILT_CTL);
}
filter &= ~(SIS_RXFILTCTL_ALLPHYS | SIS_RXFILTCTL_BROAD |
SIS_RXFILTCTL_ALLMULTI);
if (ifp->if_flags & IFF_BROADCAST) if (ifp->if_flags & IFF_BROADCAST)
ctl |= SIS_RXFILTCTL_BROAD; filter |= SIS_RXFILTCTL_BROAD;
if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { if (ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC)) {
ctl |= SIS_RXFILTCTL_ALLMULTI; filter |= SIS_RXFILTCTL_ALLMULTI;
if (ifp->if_flags & IFF_PROMISC) if (ifp->if_flags & IFF_PROMISC)
ctl |= SIS_RXFILTCTL_BROAD|SIS_RXFILTCTL_ALLPHYS; filter |= SIS_RXFILTCTL_ALLPHYS;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
hashes[i] = ~0; hashes[i] = ~0;
} else { } else {
@ -897,7 +937,7 @@ sis_setmulti_sis(struct sis_softc *sc)
} }
if_maddr_runlock(ifp); if_maddr_runlock(ifp);
if (i > n) { if (i > n) {
ctl |= SIS_RXFILTCTL_ALLMULTI; filter |= SIS_RXFILTCTL_ALLMULTI;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
hashes[i] = ~0; hashes[i] = ~0;
} }
@ -908,7 +948,8 @@ sis_setmulti_sis(struct sis_softc *sc)
CSR_WRITE_4(sc, SIS_RXFILT_DATA, hashes[i]); CSR_WRITE_4(sc, SIS_RXFILT_DATA, hashes[i]);
} }
CSR_WRITE_4(sc, SIS_RXFILT_CTL, ctl); CSR_WRITE_4(sc, SIS_RXFILT_CTL, filter);
CSR_READ_4(sc, SIS_RXFILT_CTL);
} }
static void static void
@ -2104,41 +2145,7 @@ sis_initl(struct sis_softc *sc)
CSR_WRITE_4(sc, NS_PHY_PAGE, 0); CSR_WRITE_4(sc, NS_PHY_PAGE, 0);
} }
/* sis_rxfilter(sc);
* For the NatSemi chip, we have to explicitly enable the
* reception of ARP frames, as well as turn on the 'perfect
* match' filter where we store the station address, otherwise
* we won't receive unicasts meant for this host.
*/
if (sc->sis_type == SIS_TYPE_83815) {
SIS_SETBIT(sc, SIS_RXFILT_CTL, NS_RXFILTCTL_ARP);
SIS_SETBIT(sc, SIS_RXFILT_CTL, NS_RXFILTCTL_PERFECT);
}
/* If we want promiscuous mode, set the allframes bit. */
if (ifp->if_flags & IFF_PROMISC) {
SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ALLPHYS);
} else {
SIS_CLRBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ALLPHYS);
}
/*
* Set the capture broadcast bit to capture broadcast frames.
*/
if (ifp->if_flags & IFF_BROADCAST) {
SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_BROAD);
} else {
SIS_CLRBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_BROAD);
}
/*
* Load the multicast filter.
*/
if (sc->sis_type == SIS_TYPE_83815)
sis_setmulti_ns(sc);
else
sis_setmulti_sis(sc);
/* Turn the receive filter on */ /* Turn the receive filter on */
SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ENABLE); SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ENABLE);
@ -2252,27 +2259,19 @@ sis_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
if (ifp->if_flags & IFF_UP) { if (ifp->if_flags & IFF_UP) {
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0 && if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0 &&
((ifp->if_flags ^ sc->sis_if_flags) & ((ifp->if_flags ^ sc->sis_if_flags) &
(IFF_PROMISC | IFF_ALLMULTI)) != 0) { (IFF_PROMISC | IFF_ALLMULTI)) != 0)
if (sc->sis_type == SIS_TYPE_83815) sis_rxfilter(sc);
sis_setmulti_ns(sc); else
else
sis_setmulti_sis(sc);
} else
sis_initl(sc); sis_initl(sc);
} else if (ifp->if_drv_flags & IFF_DRV_RUNNING) { } else if (ifp->if_drv_flags & IFF_DRV_RUNNING)
sis_stop(sc); sis_stop(sc);
}
sc->sis_if_flags = ifp->if_flags; sc->sis_if_flags = ifp->if_flags;
SIS_UNLOCK(sc); SIS_UNLOCK(sc);
error = 0;
break; break;
case SIOCADDMULTI: case SIOCADDMULTI:
case SIOCDELMULTI: case SIOCDELMULTI:
SIS_LOCK(sc); SIS_LOCK(sc);
if (sc->sis_type == SIS_TYPE_83815) sis_rxfilter(sc);
sis_setmulti_ns(sc);
else
sis_setmulti_sis(sc);
SIS_UNLOCK(sc); SIS_UNLOCK(sc);
break; break;
case SIOCGIFMEDIA: case SIOCGIFMEDIA: