Lines Matching refs:us

184 	struct us_data *us = usb_get_intfdata(iface);  in usb_stor_suspend()  local
187 mutex_lock(&us->dev_mutex); in usb_stor_suspend()
189 if (us->suspend_resume_hook) in usb_stor_suspend()
190 (us->suspend_resume_hook)(us, US_SUSPEND); in usb_stor_suspend()
195 mutex_unlock(&us->dev_mutex); in usb_stor_suspend()
202 struct us_data *us = usb_get_intfdata(iface); in usb_stor_resume() local
204 mutex_lock(&us->dev_mutex); in usb_stor_resume()
206 if (us->suspend_resume_hook) in usb_stor_resume()
207 (us->suspend_resume_hook)(us, US_RESUME); in usb_stor_resume()
209 mutex_unlock(&us->dev_mutex); in usb_stor_resume()
216 struct us_data *us = usb_get_intfdata(iface); in usb_stor_reset_resume() local
219 usb_stor_report_bus_reset(us); in usb_stor_reset_resume()
236 struct us_data *us = usb_get_intfdata(iface); in usb_stor_pre_reset() local
239 mutex_lock(&us->dev_mutex); in usb_stor_pre_reset()
246 struct us_data *us = usb_get_intfdata(iface); in usb_stor_post_reset() local
249 usb_stor_report_bus_reset(us); in usb_stor_post_reset()
254 mutex_unlock(&us->dev_mutex); in usb_stor_post_reset()
268 void fill_inquiry_response(struct us_data *us, unsigned char *data, in fill_inquiry_response() argument
285 u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice); in fill_inquiry_response()
288 n = strlen(us->unusual_dev->vendorName); in fill_inquiry_response()
289 memcpy(data+8, us->unusual_dev->vendorName, min(8, n)); in fill_inquiry_response()
290 n = strlen(us->unusual_dev->productName); in fill_inquiry_response()
291 memcpy(data+16, us->unusual_dev->productName, min(16, n)); in fill_inquiry_response()
299 usb_stor_set_xfer_buf(data, data_len, us->srb); in fill_inquiry_response()
305 struct us_data *us = (struct us_data *)__us; in usb_stor_control_thread() local
306 struct Scsi_Host *host = us_to_host(us); in usb_stor_control_thread()
309 usb_stor_dbg(us, "*** thread sleeping\n"); in usb_stor_control_thread()
310 if (wait_for_completion_interruptible(&us->cmnd_ready)) in usb_stor_control_thread()
313 usb_stor_dbg(us, "*** thread awakened\n"); in usb_stor_control_thread()
316 mutex_lock(&(us->dev_mutex)); in usb_stor_control_thread()
322 if (us->srb == NULL) { in usb_stor_control_thread()
324 mutex_unlock(&us->dev_mutex); in usb_stor_control_thread()
325 usb_stor_dbg(us, "-- exiting\n"); in usb_stor_control_thread()
330 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { in usb_stor_control_thread()
331 us->srb->result = DID_ABORT << 16; in usb_stor_control_thread()
340 if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) { in usb_stor_control_thread()
341 usb_stor_dbg(us, "UNKNOWN data direction\n"); in usb_stor_control_thread()
342 us->srb->result = DID_ERROR << 16; in usb_stor_control_thread()
348 else if (us->srb->device->id && in usb_stor_control_thread()
349 !(us->fflags & US_FL_SCM_MULT_TARG)) { in usb_stor_control_thread()
350 usb_stor_dbg(us, "Bad target number (%d:%llu)\n", in usb_stor_control_thread()
351 us->srb->device->id, in usb_stor_control_thread()
352 us->srb->device->lun); in usb_stor_control_thread()
353 us->srb->result = DID_BAD_TARGET << 16; in usb_stor_control_thread()
356 else if (us->srb->device->lun > us->max_lun) { in usb_stor_control_thread()
357 usb_stor_dbg(us, "Bad LUN (%d:%llu)\n", in usb_stor_control_thread()
358 us->srb->device->id, in usb_stor_control_thread()
359 us->srb->device->lun); in usb_stor_control_thread()
360 us->srb->result = DID_BAD_TARGET << 16; in usb_stor_control_thread()
365 else if ((us->srb->cmnd[0] == INQUIRY) && in usb_stor_control_thread()
366 (us->fflags & US_FL_FIX_INQUIRY)) { in usb_stor_control_thread()
371 usb_stor_dbg(us, "Faking INQUIRY command\n"); in usb_stor_control_thread()
372 fill_inquiry_response(us, data_ptr, 36); in usb_stor_control_thread()
373 us->srb->result = SAM_STAT_GOOD; in usb_stor_control_thread()
378 US_DEBUG(usb_stor_show_command(us, us->srb)); in usb_stor_control_thread()
379 us->proto_handler(us->srb, us); in usb_stor_control_thread()
380 usb_mark_last_busy(us->pusb_dev); in usb_stor_control_thread()
387 if (us->srb->result != DID_ABORT << 16) { in usb_stor_control_thread()
388 usb_stor_dbg(us, "scsi cmd done, result=0x%x\n", in usb_stor_control_thread()
389 us->srb->result); in usb_stor_control_thread()
390 us->srb->scsi_done(us->srb); in usb_stor_control_thread()
393 usb_stor_dbg(us, "scsi command aborted\n"); in usb_stor_control_thread()
401 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { in usb_stor_control_thread()
402 complete(&(us->notify)); in usb_stor_control_thread()
405 clear_bit(US_FLIDX_ABORTING, &us->dflags); in usb_stor_control_thread()
406 clear_bit(US_FLIDX_TIMED_OUT, &us->dflags); in usb_stor_control_thread()
410 us->srb = NULL; in usb_stor_control_thread()
414 mutex_unlock(&us->dev_mutex); in usb_stor_control_thread()
433 static int associate_dev(struct us_data *us, struct usb_interface *intf) in associate_dev() argument
436 us->pusb_dev = interface_to_usbdev(intf); in associate_dev()
437 us->pusb_intf = intf; in associate_dev()
438 us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber; in associate_dev()
439 usb_stor_dbg(us, "Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n", in associate_dev()
440 le16_to_cpu(us->pusb_dev->descriptor.idVendor), in associate_dev()
441 le16_to_cpu(us->pusb_dev->descriptor.idProduct), in associate_dev()
442 le16_to_cpu(us->pusb_dev->descriptor.bcdDevice)); in associate_dev()
443 usb_stor_dbg(us, "Interface Subclass: 0x%02x, Protocol: 0x%02x\n", in associate_dev()
448 usb_set_intfdata(intf, us); in associate_dev()
451 us->cr = kmalloc(sizeof(*us->cr), GFP_KERNEL); in associate_dev()
452 if (!us->cr) in associate_dev()
455 us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE, in associate_dev()
456 GFP_KERNEL, &us->iobuf_dma); in associate_dev()
457 if (!us->iobuf) { in associate_dev()
458 usb_stor_dbg(us, "I/O buffer allocation failed\n"); in associate_dev()
574 static int get_device_info(struct us_data *us, const struct usb_device_id *id, in get_device_info() argument
577 struct usb_device *dev = us->pusb_dev; in get_device_info()
579 &us->pusb_intf->cur_altsetting->desc; in get_device_info()
580 struct device *pdev = &us->pusb_intf->dev; in get_device_info()
583 us->unusual_dev = unusual_dev; in get_device_info()
584 us->subclass = (unusual_dev->useProtocol == USB_SC_DEVICE) ? in get_device_info()
587 us->protocol = (unusual_dev->useTransport == USB_PR_DEVICE) ? in get_device_info()
590 us->fflags = id->driver_info; in get_device_info()
591 usb_stor_adjust_quirks(us->pusb_dev, &us->fflags); in get_device_info()
593 if (us->fflags & US_FL_IGNORE_DEVICE) { in get_device_info()
603 us->fflags &= ~US_FL_GO_SLOW; in get_device_info()
605 if (us->fflags) in get_device_info()
609 us->fflags); in get_device_info()
625 us->subclass == idesc->bInterfaceSubClass) in get_device_info()
628 us->protocol == idesc->bInterfaceProtocol) in get_device_info()
630 if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE)) in get_device_info()
651 static void get_transport(struct us_data *us) in get_transport() argument
653 switch (us->protocol) { in get_transport()
655 us->transport_name = "Control/Bulk"; in get_transport()
656 us->transport = usb_stor_CB_transport; in get_transport()
657 us->transport_reset = usb_stor_CB_reset; in get_transport()
658 us->max_lun = 7; in get_transport()
662 us->transport_name = "Control/Bulk/Interrupt"; in get_transport()
663 us->transport = usb_stor_CB_transport; in get_transport()
664 us->transport_reset = usb_stor_CB_reset; in get_transport()
665 us->max_lun = 7; in get_transport()
669 us->transport_name = "Bulk"; in get_transport()
670 us->transport = usb_stor_Bulk_transport; in get_transport()
671 us->transport_reset = usb_stor_Bulk_reset; in get_transport()
677 static void get_protocol(struct us_data *us) in get_protocol() argument
679 switch (us->subclass) { in get_protocol()
681 us->protocol_name = "Reduced Block Commands (RBC)"; in get_protocol()
682 us->proto_handler = usb_stor_transparent_scsi_command; in get_protocol()
686 us->protocol_name = "8020i"; in get_protocol()
687 us->proto_handler = usb_stor_pad12_command; in get_protocol()
688 us->max_lun = 0; in get_protocol()
692 us->protocol_name = "QIC-157"; in get_protocol()
693 us->proto_handler = usb_stor_pad12_command; in get_protocol()
694 us->max_lun = 0; in get_protocol()
698 us->protocol_name = "8070i"; in get_protocol()
699 us->proto_handler = usb_stor_pad12_command; in get_protocol()
700 us->max_lun = 0; in get_protocol()
704 us->protocol_name = "Transparent SCSI"; in get_protocol()
705 us->proto_handler = usb_stor_transparent_scsi_command; in get_protocol()
709 us->protocol_name = "Uniform Floppy Interface (UFI)"; in get_protocol()
710 us->proto_handler = usb_stor_ufi_command; in get_protocol()
716 static int get_pipes(struct us_data *us) in get_pipes() argument
719 us->pusb_intf->cur_altsetting; in get_pipes()
751 if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) { in get_pipes()
752 usb_stor_dbg(us, "Endpoint sanity check failed! Rejecting dev.\n"); in get_pipes()
757 us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0); in get_pipes()
758 us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0); in get_pipes()
759 us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev, in get_pipes()
761 us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev, in get_pipes()
764 us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev, in get_pipes()
766 us->ep_bInterval = ep_int->bInterval; in get_pipes()
772 static int usb_stor_acquire_resources(struct us_data *us) in usb_stor_acquire_resources() argument
777 us->current_urb = usb_alloc_urb(0, GFP_KERNEL); in usb_stor_acquire_resources()
778 if (!us->current_urb) { in usb_stor_acquire_resources()
779 usb_stor_dbg(us, "URB allocation failed\n"); in usb_stor_acquire_resources()
785 if (us->unusual_dev->initFunction) { in usb_stor_acquire_resources()
786 p = us->unusual_dev->initFunction(us); in usb_stor_acquire_resources()
792 th = kthread_run(usb_stor_control_thread, us, "usb-storage"); in usb_stor_acquire_resources()
794 dev_warn(&us->pusb_intf->dev, in usb_stor_acquire_resources()
798 us->ctl_thread = th; in usb_stor_acquire_resources()
804 static void usb_stor_release_resources(struct us_data *us) in usb_stor_release_resources() argument
810 usb_stor_dbg(us, "-- sending exit command to thread\n"); in usb_stor_release_resources()
811 complete(&us->cmnd_ready); in usb_stor_release_resources()
812 if (us->ctl_thread) in usb_stor_release_resources()
813 kthread_stop(us->ctl_thread); in usb_stor_release_resources()
816 if (us->extra_destructor) { in usb_stor_release_resources()
817 usb_stor_dbg(us, "-- calling extra_destructor()\n"); in usb_stor_release_resources()
818 us->extra_destructor(us->extra); in usb_stor_release_resources()
822 kfree(us->extra); in usb_stor_release_resources()
823 usb_free_urb(us->current_urb); in usb_stor_release_resources()
827 static void dissociate_dev(struct us_data *us) in dissociate_dev() argument
830 kfree(us->cr); in dissociate_dev()
831 usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma); in dissociate_dev()
834 usb_set_intfdata(us->pusb_intf, NULL); in dissociate_dev()
840 static void quiesce_and_remove_host(struct us_data *us) in quiesce_and_remove_host() argument
842 struct Scsi_Host *host = us_to_host(us); in quiesce_and_remove_host()
845 if (us->pusb_dev->state == USB_STATE_NOTATTACHED) { in quiesce_and_remove_host()
846 set_bit(US_FLIDX_DISCONNECTING, &us->dflags); in quiesce_and_remove_host()
847 wake_up(&us->delay_wait); in quiesce_and_remove_host()
853 cancel_delayed_work_sync(&us->scan_dwork); in quiesce_and_remove_host()
856 if (test_bit(US_FLIDX_SCAN_PENDING, &us->dflags)) in quiesce_and_remove_host()
857 usb_autopm_put_interface_no_suspend(us->pusb_intf); in quiesce_and_remove_host()
868 set_bit(US_FLIDX_DISCONNECTING, &us->dflags); in quiesce_and_remove_host()
870 wake_up(&us->delay_wait); in quiesce_and_remove_host()
874 static void release_everything(struct us_data *us) in release_everything() argument
876 usb_stor_release_resources(us); in release_everything()
877 dissociate_dev(us); in release_everything()
881 scsi_host_put(us_to_host(us)); in release_everything()
887 struct us_data *us = container_of(work, struct us_data, in usb_stor_scan_dwork() local
889 struct device *dev = &us->pusb_intf->dev; in usb_stor_scan_dwork()
894 if (us->protocol == USB_PR_BULK && in usb_stor_scan_dwork()
895 !(us->fflags & US_FL_SINGLE_LUN) && in usb_stor_scan_dwork()
896 !(us->fflags & US_FL_SCM_MULT_TARG)) { in usb_stor_scan_dwork()
897 mutex_lock(&us->dev_mutex); in usb_stor_scan_dwork()
898 us->max_lun = usb_stor_Bulk_max_lun(us); in usb_stor_scan_dwork()
903 if (us->max_lun >= 8) in usb_stor_scan_dwork()
904 us_to_host(us)->max_lun = us->max_lun+1; in usb_stor_scan_dwork()
905 mutex_unlock(&us->dev_mutex); in usb_stor_scan_dwork()
907 scsi_scan_host(us_to_host(us)); in usb_stor_scan_dwork()
912 usb_autopm_put_interface(us->pusb_intf); in usb_stor_scan_dwork()
913 clear_bit(US_FLIDX_SCAN_PENDING, &us->dflags); in usb_stor_scan_dwork()
933 struct us_data *us; in usb_stor_probe1() local
942 host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us)); in usb_stor_probe1()
953 *pus = us = host_to_us(host); in usb_stor_probe1()
954 mutex_init(&(us->dev_mutex)); in usb_stor_probe1()
955 us_set_lock_class(&us->dev_mutex, intf); in usb_stor_probe1()
956 init_completion(&us->cmnd_ready); in usb_stor_probe1()
957 init_completion(&(us->notify)); in usb_stor_probe1()
958 init_waitqueue_head(&us->delay_wait); in usb_stor_probe1()
959 INIT_DELAYED_WORK(&us->scan_dwork, usb_stor_scan_dwork); in usb_stor_probe1()
962 result = associate_dev(us, intf); in usb_stor_probe1()
967 result = get_device_info(us, id, unusual_dev); in usb_stor_probe1()
972 get_transport(us); in usb_stor_probe1()
973 get_protocol(us); in usb_stor_probe1()
981 usb_stor_dbg(us, "storage_probe() failed\n"); in usb_stor_probe1()
982 release_everything(us); in usb_stor_probe1()
988 int usb_stor_probe2(struct us_data *us) in usb_stor_probe2() argument
991 struct device *dev = &us->pusb_intf->dev; in usb_stor_probe2()
994 if (!us->transport || !us->proto_handler) { in usb_stor_probe2()
998 usb_stor_dbg(us, "Transport: %s\n", us->transport_name); in usb_stor_probe2()
999 usb_stor_dbg(us, "Protocol: %s\n", us->protocol_name); in usb_stor_probe2()
1001 if (us->fflags & US_FL_SCM_MULT_TARG) { in usb_stor_probe2()
1006 us->max_lun = 7; in usb_stor_probe2()
1008 us_to_host(us)->this_id = 7; in usb_stor_probe2()
1012 us_to_host(us)->max_id = 1; in usb_stor_probe2()
1018 if (us->transport == usb_stor_Bulk_transport) in usb_stor_probe2()
1019 us_to_host(us)->no_scsi2_lun_in_cdb = 1; in usb_stor_probe2()
1023 if (us->fflags & US_FL_SINGLE_LUN) in usb_stor_probe2()
1024 us->max_lun = 0; in usb_stor_probe2()
1027 result = get_pipes(us); in usb_stor_probe2()
1035 if (us->fflags & US_FL_INITIAL_READ10) in usb_stor_probe2()
1036 set_bit(US_FLIDX_REDO_READ10, &us->dflags); in usb_stor_probe2()
1039 result = usb_stor_acquire_resources(us); in usb_stor_probe2()
1042 snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s", in usb_stor_probe2()
1043 dev_name(&us->pusb_intf->dev)); in usb_stor_probe2()
1044 result = scsi_add_host(us_to_host(us), dev); in usb_stor_probe2()
1052 usb_autopm_get_interface_no_resume(us->pusb_intf); in usb_stor_probe2()
1053 set_bit(US_FLIDX_SCAN_PENDING, &us->dflags); in usb_stor_probe2()
1057 queue_delayed_work(system_freezable_wq, &us->scan_dwork, in usb_stor_probe2()
1063 usb_stor_dbg(us, "storage_probe() failed\n"); in usb_stor_probe2()
1064 release_everything(us); in usb_stor_probe2()
1072 struct us_data *us = usb_get_intfdata(intf); in usb_stor_disconnect() local
1074 quiesce_and_remove_host(us); in usb_stor_disconnect()
1075 release_everything(us); in usb_stor_disconnect()
1084 struct us_data *us; in storage_probe() local
1119 result = usb_stor_probe1(&us, intf, id, unusual_dev); in storage_probe()
1125 result = usb_stor_probe2(us); in storage_probe()