/* detach */ int url_detach(device_t self, int flags) { struct url_softc *sc = device_private(self); struct ifnet *ifp = GET_IFP(sc); int s; DPRINTF(("%s: %s: enter\n", device_xname(sc->sc_dev), __func__)); /* Detached before attached finished */ if (!sc->sc_attached) return (0); callout_stop(&sc->sc_stat_ch); /* Remove any pending tasks */ usb_rem_task(sc->sc_udev, &sc->sc_tick_task); usb_rem_task(sc->sc_udev, &sc->sc_stop_task); s = splusb(); if (--sc->sc_refcnt >= 0) { /* Wait for processes to go away */ usb_detach_waitold(sc->sc_dev); } if (ifp->if_flags & IFF_RUNNING) url_stop(GET_IFP(sc), 1); rnd_detach_source(&sc->rnd_source); mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY); ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY); ether_ifdetach(ifp); if_detach(ifp); #ifdef DIAGNOSTIC if (sc->sc_pipe_tx != NULL) aprint_debug_dev(self, "detach has active tx endpoint.\n"); if (sc->sc_pipe_rx != NULL) aprint_debug_dev(self, "detach has active rx endpoint.\n"); if (sc->sc_pipe_intr != NULL) aprint_debug_dev(self, "detach has active intr endpoint.\n"); #endif sc->sc_attached = 0; splx(s); rw_destroy(&sc->sc_mii_rwlock); usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev); return (0); }
static int udsir_detach(device_t self, int flags) { struct udsir_softc *sc = device_private(self); int s; int rv = 0; DPRINTFN(0, ("udsir_detach: sc=%p flags=%d\n", sc, flags)); sc->sc_closing = sc->sc_dying = 1; wakeup(&sc->sc_thread); while (sc->sc_thread != NULL) tsleep(&sc->sc_closing, PWAIT, "usircl", 0); /* Abort all pipes. Causes processes waiting for transfer to wake. */ if (sc->sc_rd_pipe != NULL) { usbd_abort_pipe(sc->sc_rd_pipe); usbd_close_pipe(sc->sc_rd_pipe); sc->sc_rd_pipe = NULL; } if (sc->sc_wr_pipe != NULL) { usbd_abort_pipe(sc->sc_wr_pipe); usbd_close_pipe(sc->sc_wr_pipe); sc->sc_wr_pipe = NULL; } wakeup(&sc->sc_ur_framelen); wakeup(&sc->sc_wr_buf); s = splusb(); if (--sc->sc_refcnt >= 0) { /* Wait for processes to go away. */ usb_detach_waitold(sc->sc_dev); } splx(s); if (sc->sc_child != NULL) rv = config_detach(sc->sc_child, flags); usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev); seldestroy(&sc->sc_rd_sel); seldestroy(&sc->sc_wr_sel); return rv; }
int urio_detach(device_t self, int flags) { struct urio_softc *sc = device_private(self); int s; int maj, mn; DPRINTF(("urio_detach: sc=%p flags=%d\n", sc, flags)); sc->sc_dying = 1; /* Abort all pipes. Causes processes waiting for transfer to wake. */ if (sc->sc_in_pipe != NULL) { usbd_abort_pipe(sc->sc_in_pipe); usbd_close_pipe(sc->sc_in_pipe); sc->sc_in_pipe = NULL; } if (sc->sc_out_pipe != NULL) { usbd_abort_pipe(sc->sc_out_pipe); usbd_close_pipe(sc->sc_out_pipe); sc->sc_out_pipe = NULL; } s = splusb(); if (--sc->sc_refcnt >= 0) { /* Wait for processes to go away. */ usb_detach_waitold(sc->sc_dev); } splx(s); /* locate the major number */ maj = cdevsw_lookup_major(&urio_cdevsw); /* Nuke the vnodes for any open instances (calls close). */ mn = device_unit(self); vdevgone(maj, mn, mn, VCHR); usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev); return (0); }
int uscanner_detach(device_t self, int flags) { struct uscanner_softc *sc = device_private(self); int s; int maj, mn; DPRINTF(("uscanner_detach: sc=%p flags=%d\n", sc, flags)); sc->sc_dying = 1; sc->sc_dev_flags = 0; /* make close really close device */ /* Abort all pipes. Causes processes waiting for transfer to wake. */ if (sc->sc_bulkin_pipe != NULL) usbd_abort_pipe(sc->sc_bulkin_pipe); if (sc->sc_bulkout_pipe != NULL) usbd_abort_pipe(sc->sc_bulkout_pipe); s = splusb(); if (--sc->sc_refcnt >= 0) { /* Wait for processes to go away. */ usb_detach_waitold(sc->sc_dev); } splx(s); /* locate the major number */ maj = cdevsw_lookup_major(&uscanner_cdevsw); /* Nuke the vnodes for any open instances (calls close). */ mn = device_unit(self) * USB_MAX_ENDPOINTS; vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR); usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev); seldestroy(&sc->sc_selq); return (0); }
int ucom_detach(device_t self, int flags) { struct ucom_softc *sc = device_private(self); struct tty *tp = sc->sc_tty; int maj, mn; int s, i; DPRINTF(("ucom_detach: sc=%p flags=%d tp=%p, pipe=%d,%d\n", sc, flags, tp, sc->sc_bulkin_no, sc->sc_bulkout_no)); sc->sc_dying = 1; pmf_device_deregister(self); if (sc->sc_bulkin_pipe != NULL) usbd_abort_pipe(sc->sc_bulkin_pipe); if (sc->sc_bulkout_pipe != NULL) usbd_abort_pipe(sc->sc_bulkout_pipe); s = splusb(); if (--sc->sc_refcnt >= 0) { /* Wake up anyone waiting */ if (tp != NULL) { mutex_spin_enter(&tty_lock); CLR(tp->t_state, TS_CARR_ON); CLR(tp->t_cflag, CLOCAL | MDMBUF); ttyflush(tp, FREAD|FWRITE); mutex_spin_exit(&tty_lock); } /* Wait for processes to go away. */ usb_detach_waitold(sc->sc_dev); } softint_disestablish(sc->sc_si); splx(s); /* locate the major number */ maj = cdevsw_lookup_major(&ucom_cdevsw); /* Nuke the vnodes for any open instances. */ mn = device_unit(self); DPRINTF(("ucom_detach: maj=%d mn=%d\n", maj, mn)); vdevgone(maj, mn, mn, VCHR); vdevgone(maj, mn | UCOMDIALOUT_MASK, mn | UCOMDIALOUT_MASK, VCHR); vdevgone(maj, mn | UCOMCALLUNIT_MASK, mn | UCOMCALLUNIT_MASK, VCHR); /* Detach and free the tty. */ if (tp != NULL) { tty_detach(tp); tty_free(tp); sc->sc_tty = NULL; } for (i = 0; i < UCOM_IN_BUFFS; i++) { if (sc->sc_ibuff[i].ub_xfer != NULL) usbd_free_xfer(sc->sc_ibuff[i].ub_xfer); } for (i = 0; i < UCOM_OUT_BUFFS; i++) { if (sc->sc_obuff[i].ub_xfer != NULL) usbd_free_xfer(sc->sc_obuff[i].ub_xfer); } /* Detach the random source */ rnd_detach_source(&sc->sc_rndsource); return (0); }