48 #ifdef CONFIG_USB_STORAGE_DEBUG
52 #include <linux/sched.h>
53 #include <linux/errno.h>
55 #include <linux/module.h>
57 #include <linux/slab.h>
60 #include <linux/utsname.h>
62 #include <scsi/scsi.h>
81 static unsigned int delay_use = 1;
85 static char quirks[128];
87 MODULE_PARM_DESC(quirks,
"supplemental list of device IDs and their quirks");
104 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
105 vendor_name, product_name, use_protocol, use_transport, \
106 init_function, Flags) \
108 .vendorName = vendor_name, \
109 .productName = product_name, \
110 .useProtocol = use_protocol, \
111 .useTransport = use_transport, \
112 .initFunction = init_function, \
115 #define COMPLIANT_DEV UNUSUAL_DEV
117 #define USUAL_DEV(use_protocol, use_transport) \
119 .useProtocol = use_protocol, \
120 .useTransport = use_transport, \
135 #ifdef CONFIG_LOCKDEP
139 static void us_set_lock_class(
struct mutex *
mutex,
142 struct usb_device *
udev = interface_to_usbdev(intf);
143 struct usb_host_config *
config = udev->actconfig;
146 for (i = 0; i < config->desc.bNumInterfaces; i++) {
147 if (config->interface[i] == intf)
151 BUG_ON(i == config->desc.bNumInterfaces);
158 static void us_set_lock_class(
struct mutex *mutex,
169 struct us_data *us = usb_get_intfdata(iface);
175 if (us->suspend_resume_hook)
188 struct us_data *us = usb_get_intfdata(iface);
193 if (us->suspend_resume_hook)
194 (us->suspend_resume_hook)(us,
US_RESUME);
203 struct us_data *us = usb_get_intfdata(iface);
225 struct us_data *us = usb_get_intfdata(iface);
237 struct us_data *us = usb_get_intfdata(iface);
286 data[32] = 0x30 + ((bcdDevice>>12) & 0x0F);
287 data[33] = 0x30 + ((bcdDevice>>8) & 0x0F);
288 data[34] = 0x30 + ((bcdDevice>>4) & 0x0F);
289 data[35] = 0x30 + ((bcdDevice) & 0x0F);
296 static int usb_stor_control_thread(
void * __us)
341 else if (us->
srb->device->id &&
342 !(us->
fflags & US_FL_SCM_MULT_TARG)) {
344 us->
srb->device->id, us->
srb->device->lun);
348 else if (us->
srb->device->lun > us->
max_lun) {
350 us->
srb->device->id, us->
srb->device->lun);
357 (us->
fflags & US_FL_FIX_INQUIRY)) {
358 unsigned char data_ptr[36] = {
359 0x00, 0x80, 0x02, 0x02,
360 0x1F, 0x00, 0x00, 0x00};
379 US_DEBUGP(
"scsi cmd done, result=0x%x\n",
381 us->
srb->scsi_done(us->
srb);
429 us->
pusb_dev = interface_to_usbdev(intf);
431 us->
ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
432 US_DEBUGP(
"Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n",
436 US_DEBUGP(
"Interface Subclass: 0x%02x, Protocol: 0x%02x\n",
437 intf->cur_altsetting->desc.bInterfaceSubClass,
438 intf->cur_altsetting->desc.bInterfaceProtocol);
441 usb_set_intfdata(intf, us);
446 US_DEBUGP(
"usb_ctrlrequest allocation failed\n");
453 US_DEBUGP(
"I/O buffer allocation failed\n");
460 #define TOLOWER(x) ((x) | 0x20)
463 static void adjust_quirks(
struct us_data *us)
469 unsigned int mask = (US_FL_SANE_SENSE | US_FL_BAD_SENSE |
471 US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE |
472 US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 |
473 US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE |
474 US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT |
475 US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 |
476 US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE);
497 while (*++p && *p !=
',') {
500 f |= US_FL_SANE_SENSE;
503 f |= US_FL_BAD_SENSE;
506 f |= US_FL_FIX_CAPACITY;
509 f |= US_FL_NO_READ_DISC_INFO;
512 f |= US_FL_NO_READ_CAPACITY_16;
515 f |= US_FL_CAPACITY_HEURISTICS;
518 f |= US_FL_IGNORE_DEVICE;
521 f |= US_FL_NOT_LOCKABLE;
524 f |= US_FL_MAX_SECTORS_64;
527 f |= US_FL_INITIAL_READ10;
530 f |= US_FL_CAPACITY_OK;
533 f |= US_FL_WRITE_CACHE;
536 f |= US_FL_IGNORE_RESIDUE;
539 f |= US_FL_SINGLE_LUN;
542 f |= US_FL_NO_WP_DETECT;
567 us->
fflags =
id->driver_info;
570 if (us->
fflags & US_FL_IGNORE_DEVICE) {
580 us->
fflags &= ~US_FL_GO_SLOW;
583 dev_info(pdev,
"Quirks match for vid %04x pid %04x: %lx\n",
594 static const char *msgs[3] = {
595 "an unneeded SubClass entry",
596 "an unneeded Protocol entry",
597 "unneeded SubClass and Protocol entries"};
607 if (msg >= 0 && !(us->
fflags & US_FL_NEED_OVERRIDE))
608 dev_notice(pdev,
"This device "
609 "(%04x,%04x,%04x S %02x P %02x)"
610 " has %s in unusual_devs.h (kernel"
612 " Please send a copy of this message to "
628 static void get_transport(
struct us_data *us)
654 static void get_protocol(
struct us_data *us)
693 static int get_pipes(
struct us_data *us)
695 struct usb_host_interface *altsetting =
709 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) {
710 ep = &altsetting->endpoint[
i].desc;
712 if (usb_endpoint_xfer_bulk(ep)) {
713 if (usb_endpoint_dir_in(ep)) {
722 else if (usb_endpoint_is_int_in(ep)) {
729 US_DEBUGP(
"Endpoint sanity check failed! Rejecting dev.\n");
737 usb_endpoint_num(ep_out));
739 usb_endpoint_num(ep_in));
742 usb_endpoint_num(ep_int));
749 static int usb_stor_acquire_resources(
struct us_data *us)
769 th =
kthread_run(usb_stor_control_thread, us,
"usb-storage");
772 "Unable to start control thread\n");
781 static void usb_stor_release_resources(
struct us_data *us)
789 US_DEBUGP(
"-- sending exit command to thread\n");
796 US_DEBUGP(
"-- calling extra_destructor()\n");
806 static void dissociate_dev(
struct us_data *us)
821 static void quiesce_and_remove_host(
struct us_data *us)
838 usb_autopm_put_interface_no_suspend(us->
pusb_intf);
855 static void release_everything(
struct us_data *us)
857 usb_stor_release_resources(us);
872 dev_dbg(dev,
"starting scan\n");
881 dev_dbg(dev,
"scan complete\n");
889 static unsigned int usb_stor_sg_tablesize(
struct usb_interface *intf)
891 struct usb_device *usb_dev = interface_to_usbdev(intf);
893 if (usb_dev->bus->sg_tablesize) {
894 return usb_dev->bus->sg_tablesize;
909 US_DEBUGP(
"USB Mass Storage device detected\n");
918 "Unable to allocate the scsi host\n");
927 *pus = us = host_to_us(host);
932 init_completion(&(us->
notify));
937 result = associate_dev(us, intf);
942 result = get_device_info(us,
id, unusual_dev);
957 release_everything(us);
977 if (us->
fflags & US_FL_SINGLE_LUN)
981 result = get_pipes(us);
989 if (us->
fflags & US_FL_INITIAL_READ10)
993 result = usb_stor_acquire_resources(us);
998 result = scsi_add_host(us_to_host(us), dev);
1001 "Unable to add the scsi host\n");
1006 usb_autopm_get_interface_no_resume(us->
pusb_intf);
1010 dev_dbg(dev,
"waiting for device to settle before scanning\n");
1018 release_everything(us);
1026 struct us_data *us = usb_get_intfdata(intf);
1028 US_DEBUGP(
"storage_disconnect() called\n");
1029 quiesce_and_remove_host(us);
1030 release_everything(us);
1062 unusual_dev = &for_dynamic_ids;
1064 US_DEBUGP(
"%s %s 0x%04x 0x%04x\n",
"Use Bulk-Only transport",
1065 "with the Transparent SCSI protocol for dynamic id:",
1083 static struct usb_driver usb_storage_driver = {
1084 .name =
"usb-storage",
1085 .probe = storage_probe,
1093 .supports_autosuspend = 1,
1097 static int __init usb_stor_init(
void)
1101 pr_info(
"Initializing USB Mass Storage driver...\n");
1104 retval = usb_register(&usb_storage_driver);
1106 pr_info(
"USB Mass Storage support registered.\n");
1110 static void __exit usb_stor_exit(
void)
1118 US_DEBUGP(
"-- calling usb_deregister()\n");