1302 * cleanup whatever attach has setup
1303 */
1304 static int
1305 scsa2usb_cleanup(dev_info_t *dip, scsa2usb_state_t *scsa2usbp)
1306 {
1307 int rval, i;
1308 scsa2usb_power_t *pm;
1309 uint_t lun;
1310
1311 USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
1312 "scsa2usb_cleanup:");
1313
1314 /* wait till the work thread is done */
1315 mutex_enter(&scsa2usbp->scsa2usb_mutex);
1316 for (i = 0; i < SCSA2USB_DRAIN_TIMEOUT; i++) {
1317 if (scsa2usbp->scsa2usb_work_thread_id == NULL) {
1318
1319 break;
1320 }
1321 mutex_exit(&scsa2usbp->scsa2usb_mutex);
1322 delay(drv_usectohz(1000000));
1323 mutex_enter(&scsa2usbp->scsa2usb_mutex);
1324 }
1325 mutex_exit(&scsa2usbp->scsa2usb_mutex);
1326
1327 if (i >= SCSA2USB_DRAIN_TIMEOUT) {
1328
1329 return (USB_FAILURE);
1330 }
1331
1332 /*
1333 * Disable the event callbacks first, after this point, event
1334 * callbacks will never get called. Note we shouldn't hold
1335 * mutex while unregistering events because there may be a
1336 * competing event callback thread. Event callbacks are done
1337 * with ndi mutex held and this can cause a potential deadlock.
1338 */
1339 usb_unregister_event_cbs(scsa2usbp->scsa2usb_dip, &scsa2usb_events);
1340
1341 if (scsa2usbp->scsa2usb_flags & SCSA2USB_FLAGS_LOCKS_INIT) {
1342 /*
5436
5437 USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
5438 "scsa2usb_disconnect_event_cb: dip = 0x%p", (void *)dip);
5439
5440 mutex_enter(&scsa2usbp->scsa2usb_mutex);
5441 scsa2usbp->scsa2usb_dev_state = USB_DEV_DISCONNECTED;
5442
5443 /*
5444 * wait till the work thread is done, carry on regardless
5445 * if not.
5446 */
5447 for (i = 0; i < SCSA2USB_DRAIN_TIMEOUT; i++) {
5448 if ((scsa2usbp->scsa2usb_work_thread_id == NULL) &&
5449 (scsa2usbp->scsa2usb_cur_pkt == NULL) &&
5450 (scsa2usb_all_waitQs_empty(scsa2usbp) ==
5451 USB_SUCCESS)) {
5452
5453 break;
5454 }
5455 mutex_exit(&scsa2usbp->scsa2usb_mutex);
5456 delay(drv_usectohz(1000000));
5457 mutex_enter(&scsa2usbp->scsa2usb_mutex);
5458 }
5459 mutex_exit(&scsa2usbp->scsa2usb_mutex);
5460
5461 ndi_devi_enter(dip, &circ);
5462 for (cdip = ddi_get_child(dip); cdip; ) {
5463 dev_info_t *next = ddi_get_next_sibling(cdip);
5464
5465 mutex_enter(&DEVI(cdip)->devi_lock);
5466 DEVI_SET_DEVICE_REMOVED(cdip);
5467 mutex_exit(&DEVI(cdip)->devi_lock);
5468
5469 cdip = next;
5470 }
5471 ndi_devi_exit(dip, circ);
5472
5473 if (scsa2usbp->scsa2usb_ugen_hdl) {
5474 rval = usb_ugen_disconnect_ev_cb(
5475 scsa2usbp->scsa2usb_ugen_hdl);
5476 }
|
1302 * cleanup whatever attach has setup
1303 */
1304 static int
1305 scsa2usb_cleanup(dev_info_t *dip, scsa2usb_state_t *scsa2usbp)
1306 {
1307 int rval, i;
1308 scsa2usb_power_t *pm;
1309 uint_t lun;
1310
1311 USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
1312 "scsa2usb_cleanup:");
1313
1314 /* wait till the work thread is done */
1315 mutex_enter(&scsa2usbp->scsa2usb_mutex);
1316 for (i = 0; i < SCSA2USB_DRAIN_TIMEOUT; i++) {
1317 if (scsa2usbp->scsa2usb_work_thread_id == NULL) {
1318
1319 break;
1320 }
1321 mutex_exit(&scsa2usbp->scsa2usb_mutex);
1322 delay(drv_sectohz(1));
1323 mutex_enter(&scsa2usbp->scsa2usb_mutex);
1324 }
1325 mutex_exit(&scsa2usbp->scsa2usb_mutex);
1326
1327 if (i >= SCSA2USB_DRAIN_TIMEOUT) {
1328
1329 return (USB_FAILURE);
1330 }
1331
1332 /*
1333 * Disable the event callbacks first, after this point, event
1334 * callbacks will never get called. Note we shouldn't hold
1335 * mutex while unregistering events because there may be a
1336 * competing event callback thread. Event callbacks are done
1337 * with ndi mutex held and this can cause a potential deadlock.
1338 */
1339 usb_unregister_event_cbs(scsa2usbp->scsa2usb_dip, &scsa2usb_events);
1340
1341 if (scsa2usbp->scsa2usb_flags & SCSA2USB_FLAGS_LOCKS_INIT) {
1342 /*
5436
5437 USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
5438 "scsa2usb_disconnect_event_cb: dip = 0x%p", (void *)dip);
5439
5440 mutex_enter(&scsa2usbp->scsa2usb_mutex);
5441 scsa2usbp->scsa2usb_dev_state = USB_DEV_DISCONNECTED;
5442
5443 /*
5444 * wait till the work thread is done, carry on regardless
5445 * if not.
5446 */
5447 for (i = 0; i < SCSA2USB_DRAIN_TIMEOUT; i++) {
5448 if ((scsa2usbp->scsa2usb_work_thread_id == NULL) &&
5449 (scsa2usbp->scsa2usb_cur_pkt == NULL) &&
5450 (scsa2usb_all_waitQs_empty(scsa2usbp) ==
5451 USB_SUCCESS)) {
5452
5453 break;
5454 }
5455 mutex_exit(&scsa2usbp->scsa2usb_mutex);
5456 delay(drv_sectohz(1));
5457 mutex_enter(&scsa2usbp->scsa2usb_mutex);
5458 }
5459 mutex_exit(&scsa2usbp->scsa2usb_mutex);
5460
5461 ndi_devi_enter(dip, &circ);
5462 for (cdip = ddi_get_child(dip); cdip; ) {
5463 dev_info_t *next = ddi_get_next_sibling(cdip);
5464
5465 mutex_enter(&DEVI(cdip)->devi_lock);
5466 DEVI_SET_DEVICE_REMOVED(cdip);
5467 mutex_exit(&DEVI(cdip)->devi_lock);
5468
5469 cdip = next;
5470 }
5471 ndi_devi_exit(dip, circ);
5472
5473 if (scsa2usbp->scsa2usb_ugen_hdl) {
5474 rval = usb_ugen_disconnect_ev_cb(
5475 scsa2usbp->scsa2usb_ugen_hdl);
5476 }
|