summaryrefslogtreecommitdiffstats
path: root/sys/pci/if_sis.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2005-10-01 18:56:19 +0000
committerglebius <glebius@FreeBSD.org>2005-10-01 18:56:19 +0000
commitf41a83bf429b15386f43f43f3f5326d4ece7bfce (patch)
treeb78f9e953b7b58b2789d042cf37cc725045fdcf1 /sys/pci/if_sis.c
parent6c6c328bd0bbb1d9f6b3230a33d194bf961b0eae (diff)
downloadFreeBSD-src-f41a83bf429b15386f43f43f3f5326d4ece7bfce.zip
FreeBSD-src-f41a83bf429b15386f43f43f3f5326d4ece7bfce.tar.gz
Big polling(4) cleanup.
o Axe poll in trap. o Axe IFF_POLLING flag from if_flags. o Rework revision 1.21 (Giant removal), in such a way that poll_mtx is not dropped during call to polling handler. This fixes problem with idle polling. o Make registration and deregistration from polling in a functional way, insted of next tick/interrupt. o Obsolete kern.polling.enable. Polling is turned on/off with ifconfig. Detailed kern_poll.c changes: - Remove polling handler flags, introduced in 1.21. The are not needed now. - Forget and do not check if_flags, if_capenable and if_drv_flags. - Call all registered polling handlers unconditionally. - Do not drop poll_mtx, when entering polling handlers. - In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx. - In netisr_poll() axe the block, where polling code asks drivers to unregister. - In netisr_poll() and ether_poll() do polling always, if any handlers are present. - In ether_poll_[de]register() remove a lot of error hiding code. Assert that arguments are correct, instead. - In ether_poll_[de]register() use standard return values in case of error or success. - Introduce poll_switch() that is a sysctl handler for kern.polling.enable. poll_switch() goes through interface list and enabled/disables polling. A message that kern.polling.enable is deprecated is printed. Detailed driver changes: - On attach driver announces IFCAP_POLLING in if_capabilities, but not in if_capenable. - On detach driver calls ether_poll_deregister() if polling is enabled. - In polling handler driver obtains its lock and checks IFF_DRV_RUNNING flag. If there is no, then unlocks and returns. - In ioctl handler driver checks for IFCAP_POLLING flag requested to be set or cleared. Driver first calls ether_poll_[de]register(), then obtains driver lock and [dis/en]ables interrupts. - In interrupt handler driver checks IFCAP_POLLING flag in if_capenable. If present, then returns.This is important to protect from spurious interrupts. Reviewed by: ru, sam, jhb
Diffstat (limited to 'sys/pci/if_sis.c')
-rw-r--r--sys/pci/if_sis.c75
1 files changed, 44 insertions, 31 deletions
diff --git a/sys/pci/if_sis.c b/sys/pci/if_sis.c
index 117a46a..c0417be 100644
--- a/sys/pci/if_sis.c
+++ b/sys/pci/if_sis.c
@@ -1217,11 +1217,10 @@ sis_attach(device_t dev)
*/
ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
ifp->if_capabilities |= IFCAP_VLAN_MTU;
-
+ ifp->if_capenable = ifp->if_capabilities;
#ifdef DEVICE_POLLING
ifp->if_capabilities |= IFCAP_POLLING;
#endif
- ifp->if_capenable = ifp->if_capabilities;
/* Hook interrupt last to avoid having to lock softc */
error = bus_setup_intr(dev, sc->sis_res[1], INTR_TYPE_NET | INTR_MPSAFE,
@@ -1257,6 +1256,11 @@ sis_detach(device_t dev)
KASSERT(mtx_initialized(&sc->sis_mtx), ("sis mutex not initialized"));
ifp = sc->sis_ifp;
+#ifdef DEVICE_POLLING
+ if (ifp->if_capenable & IFCAP_POLLING)
+ ether_poll_deregister(ifp);
+#endif
+
/* These should only be active if attach succeeded. */
if (device_is_attached(dev)) {
SIS_LOCK(sc);
@@ -1404,12 +1408,12 @@ sis_rxeof(struct sis_softc *sc)
cur_rx = cur_rx->sis_nextdesc) {
#ifdef DEVICE_POLLING
- if (ifp->if_flags & IFF_POLLING) {
+ if (ifp->if_capenable & IFCAP_POLLING) {
if (sc->rxcycles <= 0)
break;
sc->rxcycles--;
}
-#endif /* DEVICE_POLLING */
+#endif
rxstat = cur_rx->sis_rxstat;
bus_dmamap_sync(sc->sis_tag,
cur_rx->sis_map, BUS_DMASYNC_POSTWRITE);
@@ -1574,13 +1578,9 @@ sis_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
struct sis_softc *sc = ifp->if_softc;
SIS_LOCK(sc);
- if (!(ifp->if_capenable & IFCAP_POLLING)) {
- ether_poll_deregister(ifp);
- cmd = POLL_DEREGISTER;
- }
- if (cmd == POLL_DEREGISTER) { /* final call, enable interrupts */
- CSR_WRITE_4(sc, SIS_IER, 1);
- goto done;
+ if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
+ SIS_UNLOCK(sc);
+ return;
}
/*
@@ -1613,7 +1613,7 @@ sis_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
sis_initl(sc);
}
}
-done:
+
SIS_UNLOCK(sc);
}
#endif /* DEVICE_POLLING */
@@ -1633,14 +1633,11 @@ sis_intr(void *arg)
SIS_LOCK(sc);
#ifdef DEVICE_POLLING
- if (ifp->if_flags & IFF_POLLING)
- goto done;
- if ((ifp->if_capenable & IFCAP_POLLING) &&
- ether_poll_register(sis_poll, ifp)) { /* ok, disable interrupts */
- CSR_WRITE_4(sc, SIS_IER, 0);
- goto done;
+ if (ifp->if_capenable & IFCAP_POLLING) {
+ SIS_UNLOCK(sc);
+ return;
}
-#endif /* DEVICE_POLLING */
+#endif
/* Disable interrupts. */
CSR_WRITE_4(sc, SIS_IER, 0);
@@ -1679,9 +1676,6 @@ sis_intr(void *arg)
if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
sis_startl(ifp);
-#ifdef DEVICE_POLLING
-done:
-#endif /* DEVICE_POLLING */
SIS_UNLOCK(sc);
}
@@ -2033,10 +2027,10 @@ sis_initl(struct sis_softc *sc)
* ... only enable interrupts if we are not polling, make sure
* they are off otherwise.
*/
- if (ifp->if_flags & IFF_POLLING)
+ if (ifp->if_capenable & IFCAP_POLLING)
CSR_WRITE_4(sc, SIS_IER, 0);
else
-#endif /* DEVICE_POLLING */
+#endif
CSR_WRITE_4(sc, SIS_IER, 1);
/* Enable receiver and transmitter. */
@@ -2133,10 +2127,32 @@ sis_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
break;
case SIOCSIFCAP:
- SIS_LOCK(sc);
- ifp->if_capenable &= ~IFCAP_POLLING;
- ifp->if_capenable |= ifr->ifr_reqcap & IFCAP_POLLING;
- SIS_UNLOCK(sc);
+ /* ok, disable interrupts */
+#ifdef DEVICE_POLLING
+ if (ifr->ifr_reqcap & IFCAP_POLLING &&
+ !(ifp->if_capenable & IFCAP_POLLING)) {
+ error = ether_poll_register(sis_poll, ifp);
+ if (error)
+ return(error);
+ SIS_LOCK(sc);
+ /* Disable interrupts */
+ CSR_WRITE_4(sc, SIS_IER, 0);
+ ifp->if_capenable |= IFCAP_POLLING;
+ SIS_UNLOCK(sc);
+ return (error);
+
+ }
+ if (!(ifr->ifr_reqcap & IFCAP_POLLING) &&
+ ifp->if_capenable & IFCAP_POLLING) {
+ error = ether_poll_deregister(ifp);
+ /* Enable interrupts. */
+ SIS_LOCK(sc);
+ CSR_WRITE_4(sc, SIS_IER, 1);
+ ifp->if_capenable &= ~IFCAP_POLLING;
+ SIS_UNLOCK(sc);
+ return (error);
+ }
+#endif /* DEVICE_POLLING */
break;
default:
error = ether_ioctl(ifp, command, data);
@@ -2192,9 +2208,6 @@ sis_stop(struct sis_softc *sc)
callout_stop(&sc->sis_stat_ch);
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
-#ifdef DEVICE_POLLING
- ether_poll_deregister(ifp);
-#endif
CSR_WRITE_4(sc, SIS_IER, 0);
CSR_WRITE_4(sc, SIS_IMR, 0);
CSR_READ_4(sc, SIS_ISR); /* clear any interrupts already pending */
OpenPOWER on IntegriCloud