Lines Matching refs:us

186 	struct us_data *us = usb_get_intfdata(iface);  in usb_stor_suspend()  local
189 mutex_lock(&us->dev_mutex); in usb_stor_suspend()
191 if (us->suspend_resume_hook) in usb_stor_suspend()
192 (us->suspend_resume_hook)(us, US_SUSPEND); in usb_stor_suspend()
197 mutex_unlock(&us->dev_mutex); in usb_stor_suspend()
204 struct us_data *us = usb_get_intfdata(iface); in usb_stor_resume() local
206 mutex_lock(&us->dev_mutex); in usb_stor_resume()
208 if (us->suspend_resume_hook) in usb_stor_resume()
209 (us->suspend_resume_hook)(us, US_RESUME); in usb_stor_resume()
211 mutex_unlock(&us->dev_mutex); in usb_stor_resume()
218 struct us_data *us = usb_get_intfdata(iface); in usb_stor_reset_resume() local
221 usb_stor_report_bus_reset(us); in usb_stor_reset_resume()
238 struct us_data *us = usb_get_intfdata(iface); in usb_stor_pre_reset() local
241 mutex_lock(&us->dev_mutex); in usb_stor_pre_reset()
248 struct us_data *us = usb_get_intfdata(iface); in usb_stor_post_reset() local
251 usb_stor_report_bus_reset(us); in usb_stor_post_reset()
256 mutex_unlock(&us->dev_mutex); in usb_stor_post_reset()
270 void fill_inquiry_response(struct us_data *us, unsigned char *data, in fill_inquiry_response() argument
287 u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice); in fill_inquiry_response()
290 n = strlen(us->unusual_dev->vendorName); in fill_inquiry_response()
291 memcpy(data+8, us->unusual_dev->vendorName, min(8, n)); in fill_inquiry_response()
292 n = strlen(us->unusual_dev->productName); in fill_inquiry_response()
293 memcpy(data+16, us->unusual_dev->productName, min(16, n)); in fill_inquiry_response()
301 usb_stor_set_xfer_buf(data, data_len, us->srb); in fill_inquiry_response()
307 struct us_data *us = (struct us_data *)__us; in usb_stor_control_thread() local
308 struct Scsi_Host *host = us_to_host(us); in usb_stor_control_thread()
311 usb_stor_dbg(us, "*** thread sleeping\n"); in usb_stor_control_thread()
312 if (wait_for_completion_interruptible(&us->cmnd_ready)) in usb_stor_control_thread()
315 usb_stor_dbg(us, "*** thread awakened\n"); in usb_stor_control_thread()
318 mutex_lock(&(us->dev_mutex)); in usb_stor_control_thread()
324 if (us->srb == NULL) { in usb_stor_control_thread()
326 mutex_unlock(&us->dev_mutex); in usb_stor_control_thread()
327 usb_stor_dbg(us, "-- exiting\n"); in usb_stor_control_thread()
332 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { in usb_stor_control_thread()
333 us->srb->result = DID_ABORT << 16; in usb_stor_control_thread()
342 if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) { in usb_stor_control_thread()
343 usb_stor_dbg(us, "UNKNOWN data direction\n"); in usb_stor_control_thread()
344 us->srb->result = DID_ERROR << 16; in usb_stor_control_thread()
350 else if (us->srb->device->id && in usb_stor_control_thread()
351 !(us->fflags & US_FL_SCM_MULT_TARG)) { in usb_stor_control_thread()
352 usb_stor_dbg(us, "Bad target number (%d:%llu)\n", in usb_stor_control_thread()
353 us->srb->device->id, in usb_stor_control_thread()
354 us->srb->device->lun); in usb_stor_control_thread()
355 us->srb->result = DID_BAD_TARGET << 16; in usb_stor_control_thread()
358 else if (us->srb->device->lun > us->max_lun) { in usb_stor_control_thread()
359 usb_stor_dbg(us, "Bad LUN (%d:%llu)\n", in usb_stor_control_thread()
360 us->srb->device->id, in usb_stor_control_thread()
361 us->srb->device->lun); in usb_stor_control_thread()
362 us->srb->result = DID_BAD_TARGET << 16; in usb_stor_control_thread()
367 else if ((us->srb->cmnd[0] == INQUIRY) && in usb_stor_control_thread()
368 (us->fflags & US_FL_FIX_INQUIRY)) { in usb_stor_control_thread()
373 usb_stor_dbg(us, "Faking INQUIRY command\n"); in usb_stor_control_thread()
374 fill_inquiry_response(us, data_ptr, 36); in usb_stor_control_thread()
375 us->srb->result = SAM_STAT_GOOD; in usb_stor_control_thread()
380 US_DEBUG(usb_stor_show_command(us, us->srb)); in usb_stor_control_thread()
381 us->proto_handler(us->srb, us); in usb_stor_control_thread()
382 usb_mark_last_busy(us->pusb_dev); in usb_stor_control_thread()
389 if (us->srb->result != DID_ABORT << 16) { in usb_stor_control_thread()
390 usb_stor_dbg(us, "scsi cmd done, result=0x%x\n", in usb_stor_control_thread()
391 us->srb->result); in usb_stor_control_thread()
392 us->srb->scsi_done(us->srb); in usb_stor_control_thread()
395 usb_stor_dbg(us, "scsi command aborted\n"); in usb_stor_control_thread()
403 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { in usb_stor_control_thread()
404 complete(&(us->notify)); in usb_stor_control_thread()
407 clear_bit(US_FLIDX_ABORTING, &us->dflags); in usb_stor_control_thread()
408 clear_bit(US_FLIDX_TIMED_OUT, &us->dflags); in usb_stor_control_thread()
412 us->srb = NULL; in usb_stor_control_thread()
416 mutex_unlock(&us->dev_mutex); in usb_stor_control_thread()
435 static int associate_dev(struct us_data *us, struct usb_interface *intf) in associate_dev() argument
438 us->pusb_dev = interface_to_usbdev(intf); in associate_dev()
439 us->pusb_intf = intf; in associate_dev()
440 us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber; in associate_dev()
441 usb_stor_dbg(us, "Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n", in associate_dev()
442 le16_to_cpu(us->pusb_dev->descriptor.idVendor), in associate_dev()
443 le16_to_cpu(us->pusb_dev->descriptor.idProduct), in associate_dev()
444 le16_to_cpu(us->pusb_dev->descriptor.bcdDevice)); in associate_dev()
445 usb_stor_dbg(us, "Interface Subclass: 0x%02x, Protocol: 0x%02x\n", in associate_dev()
450 usb_set_intfdata(intf, us); in associate_dev()
453 us->cr = kmalloc(sizeof(*us->cr), GFP_KERNEL); in associate_dev()
454 if (!us->cr) in associate_dev()
457 us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE, in associate_dev()
458 GFP_KERNEL, &us->iobuf_dma); in associate_dev()
459 if (!us->iobuf) { in associate_dev()
460 usb_stor_dbg(us, "I/O buffer allocation failed\n"); in associate_dev()
576 static int get_device_info(struct us_data *us, const struct usb_device_id *id, in get_device_info() argument
579 struct usb_device *dev = us->pusb_dev; in get_device_info()
581 &us->pusb_intf->cur_altsetting->desc; in get_device_info()
582 struct device *pdev = &us->pusb_intf->dev; in get_device_info()
585 us->unusual_dev = unusual_dev; in get_device_info()
586 us->subclass = (unusual_dev->useProtocol == USB_SC_DEVICE) ? in get_device_info()
589 us->protocol = (unusual_dev->useTransport == USB_PR_DEVICE) ? in get_device_info()
592 us->fflags = id->driver_info; in get_device_info()
593 usb_stor_adjust_quirks(us->pusb_dev, &us->fflags); in get_device_info()
595 if (us->fflags & US_FL_IGNORE_DEVICE) { in get_device_info()
605 us->fflags &= ~US_FL_GO_SLOW; in get_device_info()
607 if (us->fflags) in get_device_info()
611 us->fflags); in get_device_info()
627 us->subclass == idesc->bInterfaceSubClass) in get_device_info()
630 us->protocol == idesc->bInterfaceProtocol) in get_device_info()
632 if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE)) in get_device_info()
653 static void get_transport(struct us_data *us) in get_transport() argument
655 switch (us->protocol) { in get_transport()
657 us->transport_name = "Control/Bulk"; in get_transport()
658 us->transport = usb_stor_CB_transport; in get_transport()
659 us->transport_reset = usb_stor_CB_reset; in get_transport()
660 us->max_lun = 7; in get_transport()
664 us->transport_name = "Control/Bulk/Interrupt"; in get_transport()
665 us->transport = usb_stor_CB_transport; in get_transport()
666 us->transport_reset = usb_stor_CB_reset; in get_transport()
667 us->max_lun = 7; in get_transport()
671 us->transport_name = "Bulk"; in get_transport()
672 us->transport = usb_stor_Bulk_transport; in get_transport()
673 us->transport_reset = usb_stor_Bulk_reset; in get_transport()
679 static void get_protocol(struct us_data *us) in get_protocol() argument
681 switch (us->subclass) { in get_protocol()
683 us->protocol_name = "Reduced Block Commands (RBC)"; in get_protocol()
684 us->proto_handler = usb_stor_transparent_scsi_command; in get_protocol()
688 us->protocol_name = "8020i"; in get_protocol()
689 us->proto_handler = usb_stor_pad12_command; in get_protocol()
690 us->max_lun = 0; in get_protocol()
694 us->protocol_name = "QIC-157"; in get_protocol()
695 us->proto_handler = usb_stor_pad12_command; in get_protocol()
696 us->max_lun = 0; in get_protocol()
700 us->protocol_name = "8070i"; in get_protocol()
701 us->proto_handler = usb_stor_pad12_command; in get_protocol()
702 us->max_lun = 0; in get_protocol()
706 us->protocol_name = "Transparent SCSI"; in get_protocol()
707 us->proto_handler = usb_stor_transparent_scsi_command; in get_protocol()
711 us->protocol_name = "Uniform Floppy Interface (UFI)"; in get_protocol()
712 us->proto_handler = usb_stor_ufi_command; in get_protocol()
718 static int get_pipes(struct us_data *us) in get_pipes() argument
721 us->pusb_intf->cur_altsetting; in get_pipes()
753 if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) { in get_pipes()
754 usb_stor_dbg(us, "Endpoint sanity check failed! Rejecting dev.\n"); in get_pipes()
759 us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0); in get_pipes()
760 us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0); in get_pipes()
761 us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev, in get_pipes()
763 us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev, in get_pipes()
766 us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev, in get_pipes()
768 us->ep_bInterval = ep_int->bInterval; in get_pipes()
774 static int usb_stor_acquire_resources(struct us_data *us) in usb_stor_acquire_resources() argument
779 us->current_urb = usb_alloc_urb(0, GFP_KERNEL); in usb_stor_acquire_resources()
780 if (!us->current_urb) { in usb_stor_acquire_resources()
781 usb_stor_dbg(us, "URB allocation failed\n"); in usb_stor_acquire_resources()
787 if (us->unusual_dev->initFunction) { in usb_stor_acquire_resources()
788 p = us->unusual_dev->initFunction(us); in usb_stor_acquire_resources()
794 th = kthread_run(usb_stor_control_thread, us, "usb-storage"); in usb_stor_acquire_resources()
796 dev_warn(&us->pusb_intf->dev, in usb_stor_acquire_resources()
800 us->ctl_thread = th; in usb_stor_acquire_resources()
806 static void usb_stor_release_resources(struct us_data *us) in usb_stor_release_resources() argument
812 usb_stor_dbg(us, "-- sending exit command to thread\n"); in usb_stor_release_resources()
813 complete(&us->cmnd_ready); in usb_stor_release_resources()
814 if (us->ctl_thread) in usb_stor_release_resources()
815 kthread_stop(us->ctl_thread); in usb_stor_release_resources()
818 if (us->extra_destructor) { in usb_stor_release_resources()
819 usb_stor_dbg(us, "-- calling extra_destructor()\n"); in usb_stor_release_resources()
820 us->extra_destructor(us->extra); in usb_stor_release_resources()
824 kfree(us->extra); in usb_stor_release_resources()
825 usb_free_urb(us->current_urb); in usb_stor_release_resources()
829 static void dissociate_dev(struct us_data *us) in dissociate_dev() argument
832 kfree(us->cr); in dissociate_dev()
833 usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma); in dissociate_dev()
836 usb_set_intfdata(us->pusb_intf, NULL); in dissociate_dev()
842 static void quiesce_and_remove_host(struct us_data *us) in quiesce_and_remove_host() argument
844 struct Scsi_Host *host = us_to_host(us); in quiesce_and_remove_host()
847 if (us->pusb_dev->state == USB_STATE_NOTATTACHED) { in quiesce_and_remove_host()
848 set_bit(US_FLIDX_DISCONNECTING, &us->dflags); in quiesce_and_remove_host()
849 wake_up(&us->delay_wait); in quiesce_and_remove_host()
855 cancel_delayed_work_sync(&us->scan_dwork); in quiesce_and_remove_host()
858 if (test_bit(US_FLIDX_SCAN_PENDING, &us->dflags)) in quiesce_and_remove_host()
859 usb_autopm_put_interface_no_suspend(us->pusb_intf); in quiesce_and_remove_host()
870 set_bit(US_FLIDX_DISCONNECTING, &us->dflags); in quiesce_and_remove_host()
872 wake_up(&us->delay_wait); in quiesce_and_remove_host()
876 static void release_everything(struct us_data *us) in release_everything() argument
878 usb_stor_release_resources(us); in release_everything()
879 dissociate_dev(us); in release_everything()
883 scsi_host_put(us_to_host(us)); in release_everything()
889 struct us_data *us = container_of(work, struct us_data, in usb_stor_scan_dwork() local
891 struct device *dev = &us->pusb_intf->dev; in usb_stor_scan_dwork()
896 if (us->protocol == USB_PR_BULK && in usb_stor_scan_dwork()
897 !(us->fflags & US_FL_SINGLE_LUN) && in usb_stor_scan_dwork()
898 !(us->fflags & US_FL_SCM_MULT_TARG)) { in usb_stor_scan_dwork()
899 mutex_lock(&us->dev_mutex); in usb_stor_scan_dwork()
900 us->max_lun = usb_stor_Bulk_max_lun(us); in usb_stor_scan_dwork()
905 if (us->max_lun >= 8) in usb_stor_scan_dwork()
906 us_to_host(us)->max_lun = us->max_lun+1; in usb_stor_scan_dwork()
907 mutex_unlock(&us->dev_mutex); in usb_stor_scan_dwork()
909 scsi_scan_host(us_to_host(us)); in usb_stor_scan_dwork()
914 usb_autopm_put_interface(us->pusb_intf); in usb_stor_scan_dwork()
915 clear_bit(US_FLIDX_SCAN_PENDING, &us->dflags); in usb_stor_scan_dwork()
936 struct us_data *us; in usb_stor_probe1() local
945 host = scsi_host_alloc(sht, sizeof(*us)); in usb_stor_probe1()
956 *pus = us = host_to_us(host); in usb_stor_probe1()
957 mutex_init(&(us->dev_mutex)); in usb_stor_probe1()
958 us_set_lock_class(&us->dev_mutex, intf); in usb_stor_probe1()
959 init_completion(&us->cmnd_ready); in usb_stor_probe1()
960 init_completion(&(us->notify)); in usb_stor_probe1()
961 init_waitqueue_head(&us->delay_wait); in usb_stor_probe1()
962 INIT_DELAYED_WORK(&us->scan_dwork, usb_stor_scan_dwork); in usb_stor_probe1()
965 result = associate_dev(us, intf); in usb_stor_probe1()
970 result = get_device_info(us, id, unusual_dev); in usb_stor_probe1()
975 get_transport(us); in usb_stor_probe1()
976 get_protocol(us); in usb_stor_probe1()
984 usb_stor_dbg(us, "storage_probe() failed\n"); in usb_stor_probe1()
985 release_everything(us); in usb_stor_probe1()
991 int usb_stor_probe2(struct us_data *us) in usb_stor_probe2() argument
994 struct device *dev = &us->pusb_intf->dev; in usb_stor_probe2()
997 if (!us->transport || !us->proto_handler) { in usb_stor_probe2()
1001 usb_stor_dbg(us, "Transport: %s\n", us->transport_name); in usb_stor_probe2()
1002 usb_stor_dbg(us, "Protocol: %s\n", us->protocol_name); in usb_stor_probe2()
1004 if (us->fflags & US_FL_SCM_MULT_TARG) { in usb_stor_probe2()
1009 us->max_lun = 7; in usb_stor_probe2()
1011 us_to_host(us)->this_id = 7; in usb_stor_probe2()
1015 us_to_host(us)->max_id = 1; in usb_stor_probe2()
1021 if (us->transport == usb_stor_Bulk_transport) in usb_stor_probe2()
1022 us_to_host(us)->no_scsi2_lun_in_cdb = 1; in usb_stor_probe2()
1026 if (us->fflags & US_FL_SINGLE_LUN) in usb_stor_probe2()
1027 us->max_lun = 0; in usb_stor_probe2()
1030 result = get_pipes(us); in usb_stor_probe2()
1038 if (us->fflags & US_FL_INITIAL_READ10) in usb_stor_probe2()
1039 set_bit(US_FLIDX_REDO_READ10, &us->dflags); in usb_stor_probe2()
1042 result = usb_stor_acquire_resources(us); in usb_stor_probe2()
1045 snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s", in usb_stor_probe2()
1046 dev_name(&us->pusb_intf->dev)); in usb_stor_probe2()
1047 result = scsi_add_host(us_to_host(us), dev); in usb_stor_probe2()
1055 usb_autopm_get_interface_no_resume(us->pusb_intf); in usb_stor_probe2()
1056 set_bit(US_FLIDX_SCAN_PENDING, &us->dflags); in usb_stor_probe2()
1060 queue_delayed_work(system_freezable_wq, &us->scan_dwork, in usb_stor_probe2()
1066 usb_stor_dbg(us, "storage_probe() failed\n"); in usb_stor_probe2()
1067 release_everything(us); in usb_stor_probe2()
1075 struct us_data *us = usb_get_intfdata(intf); in usb_stor_disconnect() local
1077 quiesce_and_remove_host(us); in usb_stor_disconnect()
1078 release_everything(us); in usb_stor_disconnect()
1089 struct us_data *us; in storage_probe() local
1124 result = usb_stor_probe1(&us, intf, id, unusual_dev, in storage_probe()
1131 result = usb_stor_probe2(us); in storage_probe()