diff options
author | benno <benno@FreeBSD.org> | 2008-06-13 00:48:09 +0000 |
---|---|---|
committer | benno <benno@FreeBSD.org> | 2008-06-13 00:48:09 +0000 |
commit | c4a36debd172a0d4a285bf72152c6fa7f1eb39f1 (patch) | |
tree | db46529e87d2efa3a6fab26d173ae6c041cc1e91 /sys/dev | |
parent | 94a61263f938428d2e1f7a0763797c136a20bfdf (diff) | |
download | FreeBSD-src-c4a36debd172a0d4a285bf72152c6fa7f1eb39f1.zip FreeBSD-src-c4a36debd172a0d4a285bf72152c6fa7f1eb39f1.tar.gz |
Use callout_init_mtx to simplify locking somewhat. While we're here, rearrange
some operations in smc_detach to remove the need for the smc_shutdown variable.
Suggested by: jhb
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/smc/if_smc.c | 52 | ||||
-rw-r--r-- | sys/dev/smc/if_smcvar.h | 1 |
2 files changed, 18 insertions, 35 deletions
diff --git a/sys/dev/smc/if_smc.c b/sys/dev/smc/if_smc.c index 81e468e..9293b3e 100644 --- a/sys/dev/smc/if_smc.c +++ b/sys/dev/smc/if_smc.c @@ -279,10 +279,6 @@ smc_attach(device_t dev) error = 0; sc->smc_dev = dev; - sc->smc_shutdown = 0; - - /* Set up watchdog callout. */ - callout_init(&sc->smc_watchdog, 1); ifp = sc->smc_ifp = if_alloc(IFT_ETHER); if (ifp == NULL) { @@ -292,6 +288,9 @@ smc_attach(device_t dev) mtx_init(&sc->smc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); + /* Set up watchdog callout. */ + callout_init_mtx(&sc->smc_watchdog, &sc->smc_mtx, 0); + type = SYS_RES_IOPORT; if (sc->smc_usemem) type = SYS_RES_MEMORY; @@ -322,7 +321,8 @@ smc_attach(device_t dev) if (bootverbose) device_printf(dev, "revision %x\n", sc->smc_rev); - callout_init(&sc->smc_mii_tick_ch, 1); + callout_init_mtx(&sc->smc_mii_tick_ch, &sc->smc_mtx, + CALLOUT_RETURNUNLOCKED); if (sc->smc_chip >= REV_CHIP_91110FD) { mii_phy_probe(dev, &sc->smc_miibus, smc_mii_ifmedia_upd, smc_mii_ifmedia_sts); @@ -391,10 +391,17 @@ smc_detach(device_t dev) sc = device_get_softc(dev); SMC_LOCK(sc); - sc->smc_shutdown = 1; smc_stop(sc); SMC_UNLOCK(sc); - + +#ifdef DEVICE_POLLING + if (sc->smc_ifp->if_capenable & IFCAP_POLLING) + ether_poll_deregister(sc->smc_ifp); +#endif + + if (sc->smc_ih != NULL) + bus_teardown_intr(sc->smc_dev, sc->smc_irq, sc->smc_ih); + if (sc->smc_tq != NULL) { taskqueue_drain(sc->smc_tq, &sc->smc_intr); taskqueue_drain(sc->smc_tq, &sc->smc_rx); @@ -403,13 +410,6 @@ smc_detach(device_t dev) sc->smc_tq = NULL; } -#ifdef DEVICE_POLLING - if (sc->smc_ifp->if_capenable & IFCAP_POLLING) - ether_poll_deregister(sc->smc_ifp); -#endif - - if (sc->smc_ih != NULL) - bus_teardown_intr(sc->smc_dev, sc->smc_irq, sc->smc_ih); if (sc->smc_ifp != NULL) { ether_ifdetach(sc->smc_ifp); @@ -417,7 +417,6 @@ smc_detach(device_t dev) } if (sc->smc_miibus != NULL) { - callout_stop(&sc->smc_mii_tick_ch); device_delete_child(sc->smc_dev, sc->smc_miibus); bus_generic_detach(sc->smc_dev); } @@ -540,10 +539,6 @@ smc_task_tx(void *context, int pending) sc = ifp->if_softc; SMC_LOCK(sc); - if (sc->smc_shutdown == 1) { - SMC_UNLOCK(sc); - return; - } if (sc->smc_pending == NULL) { SMC_UNLOCK(sc); @@ -647,10 +642,6 @@ smc_task_rx(void *context, int pending) mhead = mtail = NULL; SMC_LOCK(sc); - if (sc->smc_shutdown == 1) { - SMC_UNLOCK(sc); - return; - } packet = smc_read_1(sc, FIFO_RX); while ((packet & FIFO_EMPTY) == 0) { @@ -792,10 +783,6 @@ smc_task_intr(void *context, int pending) sc = ifp->if_softc; SMC_LOCK(sc); - if (sc->smc_shutdown == 1) { - SMC_UNLOCK(sc); - return; - } smc_select_bank(sc, 2); @@ -1104,6 +1091,8 @@ smc_mii_tick(void *context) if (sc->smc_miibus == NULL) return; + SMC_UNLOCK(sc); + mii_tick(device_get_softc(sc->smc_miibus)); callout_reset(&sc->smc_mii_tick_ch, hz, smc_mii_tick, sc); } @@ -1216,9 +1205,10 @@ smc_stop(struct smc_softc *sc) SMC_ASSERT_LOCKED(sc); /* - * Turn off watchdog. + * Turn off callouts. */ callout_stop(&sc->smc_watchdog); + callout_stop(&sc->smc_mii_tick_ch); /* * Mask all interrupts. @@ -1247,12 +1237,6 @@ smc_watchdog(void *arg) struct smc_softc *sc; sc = (struct smc_softc *)arg; - SMC_LOCK(sc); - if (sc->smc_shutdown == 1) { - SMC_UNLOCK(sc); - return; - } - SMC_UNLOCK(sc); device_printf(sc->smc_dev, "watchdog timeout\n"); taskqueue_enqueue_fast(sc->smc_tq, &sc->smc_intr); } diff --git a/sys/dev/smc/if_smcvar.h b/sys/dev/smc/if_smcvar.h index 7463d0a..9bff17d 100644 --- a/sys/dev/smc/if_smcvar.h +++ b/sys/dev/smc/if_smcvar.h @@ -35,7 +35,6 @@ struct smc_softc { u_int smc_chip; u_int smc_rev; u_int smc_mask; - u_int smc_shutdown; /* Resources */ int smc_usemem; |