FreeBSD/sys/dev/ste/if_ste.c
/*
 * Shutdown hardware and free up resources. This can be called any
 * time after the mutex has been initialized. It is called in both
 * the error case in attach and the normal detach case so it needs
 * to be careful about only freeing resources that have actually been
 * allocated.
 */
Shutdown hardware and free up resources. This can be called any
time after the mutex has been initialized. It is called in both
the error case in attach and the normal detach case so it needs
to be careful about only freeing resources that have actually been
allocated.
Shutdown hardware and free up resources . This can be called any time after the mutex has been initialized . It is called in both the error case in attach and the normal detach case so it needs to be careful about only freeing resources that have actually been allocated .
static int
ste_detach(device_t dev)
{
	struct ste_softc *sc;
	struct ifnet *ifp;
	sc = device_get_softc(dev);
	KASSERT(mtx_initialized(&sc->ste_mtx), ("ste mutex not initialized"));
	ifp = sc->ste_ifp;
#ifdef DEVICE_POLLING
	if (ifp->if_capenable & IFCAP_POLLING)
		ether_poll_deregister(ifp);
#endif
	if (device_is_attached(dev)) {
		ether_ifdetach(ifp);
		STE_LOCK(sc);
		ste_stop(sc);
		STE_UNLOCK(sc);
		callout_drain(&sc->ste_callout);
	}
	if (sc->ste_miibus)
		device_delete_child(dev, sc->ste_miibus);
	bus_generic_detach(dev);
	if (sc->ste_intrhand)
		bus_teardown_intr(dev, sc->ste_irq, sc->ste_intrhand);
	if (sc->ste_irq)
		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ste_irq);
	if (sc->ste_res)
		bus_release_resource(dev, sc->ste_res_type, sc->ste_res_id,
		    sc->ste_res);
	if (ifp)
		if_free(ifp);
	ste_dma_free(sc);
	mtx_destroy(&sc->ste_mtx);
	return (0);
}
static int ste_detach ( device_t dev ) { struct ste_softc * sc ; struct ifnet * ifp ; sc = device_get_softc ( dev ) ; KASSERT ( mtx_initialized ( & sc -> ste_mtx ) , ( " " ) ) ; ifp = sc -> ste_ifp ; #ifdef DEVICE_POLLING if ( ifp -> if_capenable & IFCAP_POLLING ) ether_poll_deregister ( ifp ) ; #endif if ( device_is_attached ( dev ) ) { ether_ifdetach ( ifp ) ; STE_LOCK ( sc ) ; ste_stop ( sc ) ; STE_UNLOCK ( sc ) ; callout_drain ( & sc -> ste_callout ) ; } if ( sc -> ste_miibus ) device_delete_child ( dev , sc -> ste_miibus ) ; bus_generic_detach ( dev ) ; if ( sc -> ste_intrhand ) bus_teardown_intr ( dev , sc -> ste_irq , sc -> ste_intrhand ) ; if ( sc -> ste_irq ) bus_release_resource ( dev , SYS_RES_IRQ , 0 , sc -> ste_irq ) ; if ( sc -> ste_res ) bus_release_resource ( dev , sc -> ste_res_type , sc -> ste_res_id , sc -> ste_res ) ; if ( ifp ) if_free ( ifp ) ; ste_dma_free ( sc ) ; mtx_destroy ( & sc -> ste_mtx ) ; return ( 0 ) ; }
Shutdown hardware and free up resources.
Shutdown hardware and free up resources .
/* These should only be active if attach succeeded */