/* * rtk_detach: * Detach a rtk interface. */ int rtk_detach(struct rtk_softc *sc) { struct ifnet *ifp = &sc->ethercom.ec_if; struct rtk_tx_desc *txd; int i; /* * Succeed now if there isn't any work to do. */ if ((sc->sc_flags & RTK_ATTACHED) == 0) return 0; /* Unhook our tick handler. */ callout_stop(&sc->rtk_tick_ch); /* Detach all PHYs. */ mii_detach(&sc->mii, MII_PHY_ANY, MII_OFFSET_ANY); /* Delete all remaining media. */ ifmedia_delete_instance(&sc->mii.mii_media, IFM_INST_ANY); rnd_detach_source(&sc->rnd_source); ether_ifdetach(ifp); if_detach(ifp); for (i = 0; i < RTK_TX_LIST_CNT; i++) { txd = &sc->rtk_tx_descs[i]; if (txd->txd_dmamap != NULL) bus_dmamap_destroy(sc->sc_dmat, txd->txd_dmamap); } bus_dmamap_destroy(sc->sc_dmat, sc->recv_dmamap); bus_dmamem_unmap(sc->sc_dmat, sc->rtk_rx_buf, RTK_RXBUFLEN + 16); bus_dmamem_free(sc->sc_dmat, &sc->sc_dmaseg, sc->sc_dmanseg); /* we don't want to run again */ sc->sc_flags &= ~RTK_ATTACHED; return 0; }
int pair_clone_destroy(struct ifnet *ifp) { struct pair_softc *sc = ifp->if_softc; struct ifnet *pairedifp; struct pair_softc *dstsc = ifp->if_softc; if ((pairedifp = if_get(sc->sc_pairedif)) != NULL) { dstsc = pairedifp->if_softc; dstsc->sc_pairedif = 0; pair_link_state(pairedifp); if_put(pairedifp); } ifmedia_delete_instance(&sc->sc_media, IFM_INST_ANY); ether_ifdetach(ifp); if_detach(ifp); free(sc, M_DEVBUF, sizeof(*sc)); return (0); }
void ieee80211_ifdetach(struct ieee80211com *ic) { struct ifnet *ifp = ic->ic_ifp; ieee80211_remove_vap(ic); ieee80211_sysctl_detach(ic); ieee80211_proto_detach(ic); ieee80211_crypto_detach(ic); ieee80211_node_detach(ic); LIST_REMOVE(ic, ic_list); ifmedia_delete_instance(&ic->ic_media, IFM_INST_ANY); IEEE80211_BEACON_LOCK_DESTROY(ic); #if NBPFILTER > 0 bpfdetach(ifp); #endif ether_ifdetach(ifp); }
/* * When detaching, we do the inverse of what is done in the attach * routine, in reversed order. */ static int tap_detach(device_t self, int flags) { struct tap_softc *sc = device_private(self); struct ifnet *ifp = &sc->sc_ec.ec_if; int error; int s; sc->sc_flags |= TAP_GOING; s = splnet(); tap_stop(ifp, 1); if_down(ifp); splx(s); if (sc->sc_sih != NULL) { softint_disestablish(sc->sc_sih); sc->sc_sih = NULL; } /* * Destroying a single leaf is a very straightforward operation using * sysctl_destroyv. One should be sure to always end the path with * CTL_EOL. */ if ((error = sysctl_destroyv(NULL, CTL_NET, AF_LINK, tap_node, device_unit(sc->sc_dev), CTL_EOL)) != 0) aprint_error_dev(self, "sysctl_destroyv returned %d, ignoring\n", error); ether_ifdetach(ifp); if_detach(ifp); ifmedia_delete_instance(&sc->sc_im, IFM_INST_ANY); seldestroy(&sc->sc_rsel); mutex_destroy(&sc->sc_rdlock); mutex_destroy(&sc->sc_kqlock); pmf_device_deregister(self); return (0); }
/* * ae_detach: * * Detach a device interface. */ int ae_detach(device_t self, int flags) { struct ae_softc *sc = device_private(self); struct ifnet *ifp = &sc->sc_ethercom.ec_if; struct ae_rxsoft *rxs; struct ae_txsoft *txs; int i; /* * Succeed now if there isn't any work to do. */ if ((sc->sc_flags & AE_ATTACHED) == 0) return (0); /* Unhook our tick handler. */ if (sc->sc_tick) callout_stop(&sc->sc_tick_callout); /* Detach all PHYs */ mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY); /* Delete all remaining media. */ ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY); rnd_detach_source(&sc->sc_rnd_source); ether_ifdetach(ifp); if_detach(ifp); for (i = 0; i < AE_NRXDESC; i++) { rxs = &sc->sc_rxsoft[i]; if (rxs->rxs_mbuf != NULL) { bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmamap); m_freem(rxs->rxs_mbuf); rxs->rxs_mbuf = NULL; } bus_dmamap_destroy(sc->sc_dmat, rxs->rxs_dmamap); } for (i = 0; i < AE_TXQUEUELEN; i++) { txs = &sc->sc_txsoft[i]; if (txs->txs_mbuf != NULL) { bus_dmamap_unload(sc->sc_dmat, txs->txs_dmamap); m_freem(txs->txs_mbuf); txs->txs_mbuf = NULL; } bus_dmamap_destroy(sc->sc_dmat, txs->txs_dmamap); } bus_dmamap_unload(sc->sc_dmat, sc->sc_cddmamap); bus_dmamap_destroy(sc->sc_dmat, sc->sc_cddmamap); bus_dmamem_unmap(sc->sc_dmat, (void *)sc->sc_control_data, sizeof(struct ae_control_data)); bus_dmamem_free(sc->sc_dmat, &sc->sc_cdseg, sc->sc_cdnseg); shutdownhook_disestablish(sc->sc_sdhook); powerhook_disestablish(sc->sc_powerhook); bus_space_unmap(sc->sc_st, sc->sc_sh, sc->sc_size); return (0); }