static int keyspan_pre_detach(dev_info_t *dip, ddi_detach_cmd_t cmd, void *statep) { int instance = ddi_get_instance(dip); keyspan_pre_state_t *kbp; kbp = ddi_get_soft_state(statep, instance); switch (cmd) { case DDI_DETACH: break; case DDI_SUSPEND: return (DDI_SUCCESS); default: return (DDI_FAILURE); } usb_free_log_hdl(kbp->kb_lh); usb_client_detach(dip, kbp->kb_dev_data); ddi_soft_state_free(statep, instance); return (DDI_SUCCESS); }
/* * configuration clean up */ static void uftdi_cleanup(uftdi_state_t *uf, int level) { ASSERT(level > 0 && level <= UFTDI_CLEANUP_LEVEL_MAX); switch (level) { default: case 6: uftdi_close_pipes(uf); /*FALLTHROUGH*/ case 5: usb_unregister_event_cbs(uf->uf_dip, uf->uf_usb_events); /*FALLTHROUGH*/ case 4: uftdi_destroy_pm_components(uf); /*FALLTHROUGH*/ case 3: mutex_destroy(&uf->uf_lock); cv_destroy(&uf->uf_tx_cv); usb_free_log_hdl(uf->uf_lh); uf->uf_lh = NULL; usb_free_descr_tree(uf->uf_dip, uf->uf_dev_data); uf->uf_def_ph = NULL; /*FALLTHROUGH*/ case 2: usb_client_detach(uf->uf_dip, uf->uf_dev_data); /*FALLTHROUGH*/ case 1: kmem_free(uf, sizeof (*uf)); break; } }
/* * wusb_df_cleanup: * clean up the driver state for detach */ static int wusb_df_cleanup(dev_info_t *dip, wusb_df_state_t *wusb_dfp) { USB_DPRINTF_L3(PRINT_MASK_ATTA, wusb_dfp->wusb_df_log_hdl, "Cleanup: enter"); if (wusb_dfp->wusb_df_locks_initialized) { /* This must be done 1st to prevent more events from coming. */ usb_unregister_hotplug_cbs(dip); /* * At this point, no new activity can be initiated. The driver * has disabled hotplug callbacks. The Solaris framework has * disabled new opens on a device being detached, and does not * allow detaching an open device. * * The following ensures that all driver activity has drained. */ mutex_enter(&wusb_dfp->wusb_df_mutex); (void) wusb_df_serialize_access(wusb_dfp, WUSB_DF_SER_NOSIG); wusb_df_release_access(wusb_dfp); mutex_exit(&wusb_dfp->wusb_df_mutex); /* All device activity has died down. */ wusb_df_destroy_power_mgmt(wusb_dfp); /* start dismantling */ ddi_remove_minor_node(dip, NULL); cv_destroy(&wusb_dfp->wusb_df_serial_cv); mutex_destroy(&wusb_dfp->wusb_df_mutex); } usb_client_detach(dip, wusb_dfp->wusb_df_reg); usb_free_log_hdl(wusb_dfp->wusb_df_log_hdl); if (wusb_dfp->wusb_df_devinst != NULL) { kmem_free(wusb_dfp->wusb_df_devinst, strlen(wusb_dfp->wusb_df_devinst) + 1); } ddi_soft_state_free(wusb_df_statep, ddi_get_instance(dip)); ddi_prop_remove_all(dip); return (USB_SUCCESS); }
/* USBA framework destroys */ void usba_usbai_destroy() { USB_DPRINTF_L4(DPRINT_MASK_USBAI, usbai_log_handle, "usba_usbai_destroy"); mutex_destroy(&usba_print_mutex); mutex_destroy(&usbai_mutex); if (usba_debug_buf) { kmem_free(usba_debug_buf, usba_debug_buf_size + USBA_DEBUG_SIZE_EXTRA_ALLOC); } usb_free_log_hdl(usbai_log_handle); }
/*ARGSUSED*/ static int keyspan_pre_attach(dev_info_t *dip, ddi_attach_cmd_t cmd, void *statep) { int instance = ddi_get_instance(dip); keyspan_pre_state_t *kbp = NULL; usb_client_dev_data_t *dev_data = NULL; int rval = DDI_FAILURE; switch (cmd) { case DDI_ATTACH: break; case DDI_RESUME: return (DDI_SUCCESS); default: return (DDI_FAILURE); } /* attach driver to USBA */ if (usb_client_attach(dip, USBDRV_VERSION, 0) == USB_SUCCESS) { (void) usb_get_dev_data(dip, &dev_data, USB_PARSE_LVL_IF, 0); } if (dev_data == NULL) { goto fail; } /* * If 19HS, needn't download firmware, but need check the current cfg. * If 49WLC, need check the current cfg before download fw. And after * download, the product id will change to KEYSPAN_USA49WLC_PID. */ if (dev_data->dev_descr->idProduct == KEYSPAN_USA19HS_PID || dev_data->dev_descr->idProduct == KEYSPAN_USA49WLC_PID) { if (keyspan_set_cfg(dip) == USB_SUCCESS) { /* Go to keyspan_attach() by return DDI_ECONTEXT. */ rval = DDI_ECONTEXT; } goto fail; } /* * By checking KEYSPAN_FW_FLAG, we can check whether the firmware * has been downloaded. * If firmware is already there, then do normal attach. */ if (!keyspan_need_fw(dev_data)) { /* Go to keyspan_attach() by return DDI_ECONTEXT. */ rval = DDI_ECONTEXT; goto fail; } /* Go on to download firmware. */ if (ddi_soft_state_zalloc(statep, instance) == DDI_SUCCESS) { kbp = ddi_get_soft_state(statep, instance); } if (kbp) { kbp->kb_dip = dip; kbp->kb_instance = instance; kbp->kb_dev_data = dev_data; kbp->kb_def_pipe.pipe_handle = kbp->kb_dev_data->dev_default_ph; kbp->kb_lh = usb_alloc_log_hdl(kbp->kb_dip, "keyspan[*].", &keyspan_pre_errlevel, &keyspan_pre_errmask, &keyspan_pre_instance_debug, 0); kbp->kb_def_pipe.pipe_lh = kbp->kb_lh; if (keyspan_download_firmware(kbp) == USB_SUCCESS) { USB_DPRINTF_L4(DPRINT_ATTACH, kbp->kb_lh, "keyspan_pre_attach: completed."); /* keyspan download firmware done. */ return (DDI_SUCCESS); } } fail: if (kbp) { usb_free_log_hdl(kbp->kb_lh); ddi_soft_state_free(statep, instance); } usb_client_detach(dip, dev_data); return (rval); }