Lines Matching defs:us

160 	struct us_data *us = usb_get_intfdata(iface);
163 mutex_lock(&us->dev_mutex);
165 if (us->suspend_resume_hook)
166 (us->suspend_resume_hook)(us, US_SUSPEND);
173 mutex_unlock(&us->dev_mutex);
180 struct us_data *us = usb_get_intfdata(iface);
182 mutex_lock(&us->dev_mutex);
184 if (us->suspend_resume_hook)
185 (us->suspend_resume_hook)(us, US_RESUME);
187 mutex_unlock(&us->dev_mutex);
194 struct us_data *us = usb_get_intfdata(iface);
197 usb_stor_report_bus_reset(us);
216 struct us_data *us = usb_get_intfdata(iface);
219 mutex_lock(&us->dev_mutex);
226 struct us_data *us = usb_get_intfdata(iface);
229 usb_stor_report_bus_reset(us);
236 mutex_unlock(&us->dev_mutex);
250 void fill_inquiry_response(struct us_data *us, unsigned char *data,
269 u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice);
272 n = strlen(us->unusual_dev->vendorName);
273 memcpy(data+8, us->unusual_dev->vendorName, min(8, n));
274 n = strlen(us->unusual_dev->productName);
275 memcpy(data+16, us->unusual_dev->productName, min(16, n));
283 usb_stor_set_xfer_buf(data, data_len, us->srb);
289 struct us_data *us = (struct us_data *)__us;
290 struct Scsi_Host *host = us_to_host(us);
294 usb_stor_dbg(us, "*** thread sleeping\n");
295 if (wait_for_completion_interruptible(&us->cmnd_ready))
298 usb_stor_dbg(us, "*** thread awakened\n");
301 mutex_lock(&(us->dev_mutex));
307 srb = us->srb;
310 mutex_unlock(&us->dev_mutex);
311 usb_stor_dbg(us, "-- exiting\n");
316 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
328 usb_stor_dbg(us, "UNKNOWN data direction\n");
337 !(us->fflags & US_FL_SCM_MULT_TARG)) {
338 usb_stor_dbg(us, "Bad target number (%d:%llu)\n",
344 else if (srb->device->lun > us->max_lun) {
345 usb_stor_dbg(us, "Bad LUN (%d:%llu)\n",
352 * Handle those devices which need us to fake
356 (us->fflags & US_FL_FIX_INQUIRY)) {
361 usb_stor_dbg(us, "Faking INQUIRY command\n");
362 fill_inquiry_response(us, data_ptr, 36);
368 US_DEBUG(usb_stor_show_command(us, srb));
369 us->proto_handler(srb, us);
370 usb_mark_last_busy(us->pusb_dev);
379 usb_stor_dbg(us, "scsi command aborted\n");
390 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
391 complete(&(us->notify));
394 clear_bit(US_FLIDX_ABORTING, &us->dflags);
395 clear_bit(US_FLIDX_TIMED_OUT, &us->dflags);
399 us->srb = NULL;
403 mutex_unlock(&us->dev_mutex);
407 usb_stor_dbg(us, "scsi cmd done, result=0x%x\n",
429 static int associate_dev(struct us_data *us, struct usb_interface *intf)
432 us->pusb_dev = interface_to_usbdev(intf);
433 us->pusb_intf = intf;
434 us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
435 usb_stor_dbg(us, "Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n",
436 le16_to_cpu(us->pusb_dev->descriptor.idVendor),
437 le16_to_cpu(us->pusb_dev->descriptor.idProduct),
438 le16_to_cpu(us->pusb_dev->descriptor.bcdDevice));
439 usb_stor_dbg(us, "Interface Subclass: 0x%02x, Protocol: 0x%02x\n",
444 usb_set_intfdata(intf, us);
447 us->cr = kmalloc(sizeof(*us->cr), GFP_KERNEL);
448 if (!us->cr)
451 us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE,
452 GFP_KERNEL, &us->iobuf_dma);
453 if (!us->iobuf) {
454 usb_stor_dbg(us, "I/O buffer allocation failed\n");
577 static int get_device_info(struct us_data *us, const struct usb_device_id *id,
580 struct usb_device *dev = us->pusb_dev;
582 &us->pusb_intf->cur_altsetting->desc;
583 struct device *pdev = &us->pusb_intf->dev;
586 us->unusual_dev = unusual_dev;
587 us->subclass = (unusual_dev->useProtocol == USB_SC_DEVICE) ?
590 us->protocol = (unusual_dev->useTransport == USB_PR_DEVICE) ?
593 us->fflags = id->driver_info;
594 usb_stor_adjust_quirks(us->pusb_dev, &us->fflags);
596 if (us->fflags & US_FL_IGNORE_DEVICE) {
606 us->fflags &= ~US_FL_GO_SLOW;
608 if (us->fflags)
612 us->fflags);
617 * reports from users that will help us remove unneeded entries
629 us->subclass == idesc->bInterfaceSubClass)
632 us->protocol == idesc->bInterfaceProtocol)
634 if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE))
655 static void get_transport(struct us_data *us)
657 switch (us->protocol) {
659 us->transport_name = "Control/Bulk";
660 us->transport = usb_stor_CB_transport;
661 us->transport_reset = usb_stor_CB_reset;
662 us->max_lun = 7;
666 us->transport_name = "Control/Bulk/Interrupt";
667 us->transport = usb_stor_CB_transport;
668 us->transport_reset = usb_stor_CB_reset;
669 us->max_lun = 7;
673 us->transport_name = "Bulk";
674 us->transport = usb_stor_Bulk_transport;
675 us->transport_reset = usb_stor_Bulk_reset;
681 static void get_protocol(struct us_data *us)
683 switch (us->subclass) {
685 us->protocol_name = "Reduced Block Commands (RBC)";
686 us->proto_handler = usb_stor_transparent_scsi_command;
690 us->protocol_name = "8020i";
691 us->proto_handler = usb_stor_pad12_command;
692 us->max_lun = 0;
696 us->protocol_name = "QIC-157";
697 us->proto_handler = usb_stor_pad12_command;
698 us->max_lun = 0;
702 us->protocol_name = "8070i";
703 us->proto_handler = usb_stor_pad12_command;
704 us->max_lun = 0;
708 us->protocol_name = "Transparent SCSI";
709 us->proto_handler = usb_stor_transparent_scsi_command;
713 us->protocol_name = "Uniform Floppy Interface (UFI)";
714 us->proto_handler = usb_stor_ufi_command;
720 static int get_pipes(struct us_data *us)
722 struct usb_host_interface *alt = us->pusb_intf->cur_altsetting;
736 usb_stor_dbg(us, "bulk endpoints not found\n");
741 if (res && us->protocol == USB_PR_CBI) {
742 usb_stor_dbg(us, "interrupt endpoint not found\n");
747 us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0);
748 us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0);
749 us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev,
751 us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev,
754 us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev,
756 us->ep_bInterval = ep_int->bInterval;
762 static int usb_stor_acquire_resources(struct us_data *us)
767 us->current_urb = usb_alloc_urb(0, GFP_KERNEL);
768 if (!us->current_urb)
775 if (us->unusual_dev->initFunction) {
776 p = us->unusual_dev->initFunction(us);
782 th = kthread_run(usb_stor_control_thread, us, "usb-storage");
784 dev_warn(&us->pusb_intf->dev,
788 us->ctl_thread = th;
794 static void usb_stor_release_resources(struct us_data *us)
801 usb_stor_dbg(us, "-- sending exit command to thread\n");
802 complete(&us->cmnd_ready);
803 if (us->ctl_thread)
804 kthread_stop(us->ctl_thread);
807 if (us->extra_destructor) {
808 usb_stor_dbg(us, "-- calling extra_destructor()\n");
809 us->extra_destructor(us->extra);
813 kfree(us->extra);
814 usb_free_urb(us->current_urb);
818 static void dissociate_dev(struct us_data *us)
821 kfree(us->cr);
822 usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma);
825 usb_set_intfdata(us->pusb_intf, NULL);
832 static void quiesce_and_remove_host(struct us_data *us)
834 struct Scsi_Host *host = us_to_host(us);
837 if (us->pusb_dev->state == USB_STATE_NOTATTACHED) {
838 set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
839 wake_up(&us->delay_wait);
846 cancel_delayed_work_sync(&us->scan_dwork);
849 if (test_bit(US_FLIDX_SCAN_PENDING, &us->dflags))
850 usb_autopm_put_interface_no_suspend(us->pusb_intf);
863 set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
865 wake_up(&us->delay_wait);
869 static void release_everything(struct us_data *us)
871 usb_stor_release_resources(us);
872 dissociate_dev(us);
876 * (and "us" along with it) when the refcount becomes 0.
878 scsi_host_put(us_to_host(us));
884 struct us_data *us = container_of(work, struct us_data,
886 struct device *dev = &us->pusb_intf->dev;
891 if (us->protocol == USB_PR_BULK &&
892 !(us->fflags & US_FL_SINGLE_LUN) &&
893 !(us->fflags & US_FL_SCM_MULT_TARG)) {
894 mutex_lock(&us->dev_mutex);
895 us->max_lun = usb_stor_Bulk_max_lun(us);
901 if (us->max_lun >= 8)
902 us_to_host(us)->max_lun = us->max_lun+1;
903 mutex_unlock(&us->dev_mutex);
905 scsi_scan_host(us_to_host(us));
910 usb_autopm_put_interface(us->pusb_intf);
911 clear_bit(US_FLIDX_SCAN_PENDING, &us->dflags);
932 struct us_data *us;
941 host = scsi_host_alloc(sht, sizeof(*us));
952 *pus = us = host_to_us(host);
953 mutex_init(&(us->dev_mutex));
954 us_set_lock_class(&us->dev_mutex, intf);
955 init_completion(&us->cmnd_ready);
956 init_completion(&(us->notify));
957 init_waitqueue_head(&us->delay_wait);
958 INIT_DELAYED_WORK(&us->scan_dwork, usb_stor_scan_dwork);
961 result = associate_dev(us, intf);
970 if (!hcd_uses_dma(bus_to_hcd(us->pusb_dev->bus)) ||
971 bus_to_hcd(us->pusb_dev->bus)->localmem_pool)
975 result = get_device_info(us, id, unusual_dev);
980 get_transport(us);
981 get_protocol(us);
990 usb_stor_dbg(us, "storage_probe() failed\n");
991 release_everything(us);
997 int usb_stor_probe2(struct us_data *us)
1000 struct device *dev = &us->pusb_intf->dev;
1003 if (!us->transport || !us->proto_handler) {
1007 usb_stor_dbg(us, "Transport: %s\n", us->transport_name);
1008 usb_stor_dbg(us, "Protocol: %s\n", us->protocol_name);
1010 if (us->fflags & US_FL_SCM_MULT_TARG) {
1015 us->max_lun = 7;
1017 us_to_host(us)->this_id = 7;
1021 us_to_host(us)->max_id = 1;
1027 if (us->transport == usb_stor_Bulk_transport)
1028 us_to_host(us)->no_scsi2_lun_in_cdb = 1;
1032 if (us->fflags & US_FL_SINGLE_LUN)
1033 us->max_lun = 0;
1036 result = get_pipes(us);
1044 if (us->fflags & US_FL_INITIAL_READ10)
1045 set_bit(US_FLIDX_REDO_READ10, &us->dflags);
1048 result = usb_stor_acquire_resources(us);
1051 usb_autopm_get_interface_no_resume(us->pusb_intf);
1052 snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s",
1053 dev_name(&us->pusb_intf->dev));
1054 result = scsi_add_host(us_to_host(us), dev);
1062 set_bit(US_FLIDX_SCAN_PENDING, &us->dflags);
1066 queue_delayed_work(system_freezable_wq, &us->scan_dwork,
1072 usb_autopm_put_interface_no_suspend(us->pusb_intf);
1074 usb_stor_dbg(us, "storage_probe() failed\n");
1075 release_everything(us);
1083 struct us_data *us = usb_get_intfdata(intf);
1085 quiesce_and_remove_host(us);
1086 release_everything(us);
1097 struct us_data *us;
1132 result = usb_stor_probe1(&us, intf, id, unusual_dev,
1139 result = usb_stor_probe2(us);