Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Driver for USB Mass Storage compliant devices |
| 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Current development and maintenance by: |
| 4 | * (c) 1999-2003 Matthew Dharm (mdharm-usb@one-eyed-alien.net) |
| 5 | * |
| 6 | * Developed with the assistance of: |
| 7 | * (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org) |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 8 | * (c) 2003-2009 Alan Stern (stern@rowland.harvard.edu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * Initial work by: |
| 11 | * (c) 1999 Michael Gee (michael@linuxspecific.com) |
| 12 | * |
| 13 | * usb_device_id support by Adam J. Richter (adam@yggdrasil.com): |
| 14 | * (c) 2000 Yggdrasil Computing, Inc. |
| 15 | * |
| 16 | * This driver is based on the 'USB Mass Storage Class' document. This |
| 17 | * describes in detail the protocol used to communicate with such |
| 18 | * devices. Clearly, the designers had SCSI and ATAPI commands in |
| 19 | * mind when they created this document. The commands are all very |
| 20 | * similar to commands in the SCSI-II and ATAPI specifications. |
| 21 | * |
| 22 | * It is important to note that in a number of cases this class |
| 23 | * exhibits class-specific exemptions from the USB specification. |
| 24 | * Notably the usage of NAK, STALL and ACK differs from the norm, in |
| 25 | * that they are used to communicate wait, failed and OK on commands. |
| 26 | * |
| 27 | * Also, for certain devices, the interrupt endpoint is used to convey |
| 28 | * status of a command. |
| 29 | * |
| 30 | * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more |
| 31 | * information about this driver. |
| 32 | * |
| 33 | * This program is free software; you can redistribute it and/or modify it |
| 34 | * under the terms of the GNU General Public License as published by the |
| 35 | * Free Software Foundation; either version 2, or (at your option) any |
| 36 | * later version. |
| 37 | * |
| 38 | * This program is distributed in the hope that it will be useful, but |
| 39 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 41 | * General Public License for more details. |
| 42 | * |
| 43 | * You should have received a copy of the GNU General Public License along |
| 44 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 45 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 46 | */ |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/sched.h> |
| 49 | #include <linux/errno.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 50 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/module.h> |
| 52 | #include <linux/init.h> |
| 53 | #include <linux/slab.h> |
Alan Stern | 3f13e66 | 2005-10-23 19:43:36 -0700 | [diff] [blame] | 54 | #include <linux/kthread.h> |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 55 | #include <linux/mutex.h> |
Sam Ravnborg | 00f8b0c | 2007-03-05 00:30:55 -0800 | [diff] [blame] | 56 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | #include <scsi/scsi.h> |
| 59 | #include <scsi/scsi_cmnd.h> |
| 60 | #include <scsi/scsi_device.h> |
| 61 | |
| 62 | #include "usb.h" |
| 63 | #include "scsiglue.h" |
| 64 | #include "transport.h" |
| 65 | #include "protocol.h" |
| 66 | #include "debug.h" |
| 67 | #include "initializers.h" |
| 68 | |
Kevin Lloyd | 32fe5e3 | 2008-07-10 14:14:57 -0700 | [diff] [blame] | 69 | #include "sierra_ms.h" |
Dan Williams | 281b064 | 2008-12-14 12:39:22 -0500 | [diff] [blame] | 70 | #include "option_ms.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | /* Some informational data */ |
| 73 | MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>"); |
| 74 | MODULE_DESCRIPTION("USB Mass Storage driver for Linux"); |
| 75 | MODULE_LICENSE("GPL"); |
| 76 | |
| 77 | static unsigned int delay_use = 5; |
| 78 | module_param(delay_use, uint, S_IRUGO | S_IWUSR); |
| 79 | MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device"); |
| 80 | |
Alan Stern | c838ea4 | 2008-12-15 10:40:06 -0500 | [diff] [blame] | 81 | static char quirks[128]; |
| 82 | module_param_string(quirks, quirks, sizeof(quirks), S_IRUGO | S_IWUSR); |
Alan Stern | d4f373e | 2008-11-10 14:07:45 -0500 | [diff] [blame] | 83 | MODULE_PARM_DESC(quirks, "supplemental list of device IDs and their quirks"); |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Pete Zaitcev | a00828e | 2005-10-22 20:15:09 -0700 | [diff] [blame] | 86 | /* |
| 87 | * The entries in this table correspond, line for line, |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 88 | * with the entries in usb_storage_usb_ids[], defined in usual-tables.c. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | /* The vendor name should be kept at eight characters or less, and |
| 92 | * the product name should be kept at 16 characters or less. If a device |
| 93 | * has the US_FL_FIX_INQUIRY flag, then the vendor and product names |
| 94 | * normally generated by a device thorugh the INQUIRY response will be |
| 95 | * taken from this list, and this is the reason for the above size |
| 96 | * restriction. However, if the flag is not present, then you |
| 97 | * are free to use as many characters as you like. |
| 98 | */ |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \ |
| 101 | vendor_name, product_name, use_protocol, use_transport, \ |
| 102 | init_function, Flags) \ |
| 103 | { \ |
| 104 | .vendorName = vendor_name, \ |
| 105 | .productName = product_name, \ |
| 106 | .useProtocol = use_protocol, \ |
| 107 | .useTransport = use_transport, \ |
| 108 | .initFunction = init_function, \ |
Pete Zaitcev | a00828e | 2005-10-22 20:15:09 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Alan Stern | 25ff1c3 | 2008-12-15 12:43:41 -0500 | [diff] [blame] | 111 | #define COMPLIANT_DEV UNUSUAL_DEV |
| 112 | |
Pete Zaitcev | a00828e | 2005-10-22 20:15:09 -0700 | [diff] [blame] | 113 | #define USUAL_DEV(use_protocol, use_transport, use_type) \ |
| 114 | { \ |
| 115 | .useProtocol = use_protocol, \ |
| 116 | .useTransport = use_transport, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static struct us_unusual_dev us_unusual_dev_list[] = { |
| 120 | # include "unusual_devs.h" |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 121 | { } /* Terminating entry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 124 | #undef UNUSUAL_DEV |
| 125 | #undef COMPLIANT_DEV |
| 126 | #undef USUAL_DEV |
| 127 | |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 128 | |
| 129 | #ifdef CONFIG_PM /* Minimal support for suspend and resume */ |
| 130 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 131 | int usb_stor_suspend(struct usb_interface *iface, pm_message_t message) |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 132 | { |
| 133 | struct us_data *us = usb_get_intfdata(iface); |
| 134 | |
| 135 | /* Wait until no command is running */ |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 136 | mutex_lock(&us->dev_mutex); |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 137 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 138 | US_DEBUGP("%s\n", __func__); |
Matthew Dharm | 7931e1c | 2005-12-04 21:56:51 -0800 | [diff] [blame] | 139 | if (us->suspend_resume_hook) |
| 140 | (us->suspend_resume_hook)(us, US_SUSPEND); |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 141 | |
Greg Kroah-Hartman | d526875 | 2007-09-13 06:01:24 -0700 | [diff] [blame] | 142 | /* When runtime PM is working, we'll set a flag to indicate |
| 143 | * whether we should autoresume when a SCSI request arrives. */ |
| 144 | |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 145 | mutex_unlock(&us->dev_mutex); |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 146 | return 0; |
| 147 | } |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 148 | EXPORT_SYMBOL_GPL(usb_stor_suspend); |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 149 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 150 | int usb_stor_resume(struct usb_interface *iface) |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 151 | { |
| 152 | struct us_data *us = usb_get_intfdata(iface); |
| 153 | |
Greg Kroah-Hartman | d526875 | 2007-09-13 06:01:24 -0700 | [diff] [blame] | 154 | mutex_lock(&us->dev_mutex); |
Alan Stern | 8dfe4b1 | 2007-07-06 14:24:27 -0400 | [diff] [blame] | 155 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 156 | US_DEBUGP("%s\n", __func__); |
Matthew Dharm | 7931e1c | 2005-12-04 21:56:51 -0800 | [diff] [blame] | 157 | if (us->suspend_resume_hook) |
| 158 | (us->suspend_resume_hook)(us, US_RESUME); |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 159 | |
Greg Kroah-Hartman | d526875 | 2007-09-13 06:01:24 -0700 | [diff] [blame] | 160 | mutex_unlock(&us->dev_mutex); |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 161 | return 0; |
| 162 | } |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 163 | EXPORT_SYMBOL_GPL(usb_stor_resume); |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 164 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 165 | int usb_stor_reset_resume(struct usb_interface *iface) |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 166 | { |
| 167 | struct us_data *us = usb_get_intfdata(iface); |
| 168 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 169 | US_DEBUGP("%s\n", __func__); |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 170 | |
| 171 | /* Report the reset to the SCSI core */ |
| 172 | usb_stor_report_bus_reset(us); |
| 173 | |
| 174 | /* FIXME: Notify the subdrivers that they need to reinitialize |
| 175 | * the device */ |
| 176 | return 0; |
| 177 | } |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 178 | EXPORT_SYMBOL_GPL(usb_stor_reset_resume); |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 179 | |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 180 | #endif /* CONFIG_PM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | /* |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 183 | * The next two routines get called just before and just after |
| 184 | * a USB port reset, whether from this driver or a different one. |
| 185 | */ |
| 186 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 187 | int usb_stor_pre_reset(struct usb_interface *iface) |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 188 | { |
| 189 | struct us_data *us = usb_get_intfdata(iface); |
| 190 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 191 | US_DEBUGP("%s\n", __func__); |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 192 | |
| 193 | /* Make sure no command runs during the reset */ |
| 194 | mutex_lock(&us->dev_mutex); |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 195 | return 0; |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 196 | } |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 197 | EXPORT_SYMBOL_GPL(usb_stor_pre_reset); |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 198 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 199 | int usb_stor_post_reset(struct usb_interface *iface) |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 200 | { |
| 201 | struct us_data *us = usb_get_intfdata(iface); |
| 202 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 203 | US_DEBUGP("%s\n", __func__); |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 204 | |
| 205 | /* Report the reset to the SCSI core */ |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 206 | usb_stor_report_bus_reset(us); |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 207 | |
| 208 | /* FIXME: Notify the subdrivers that they need to reinitialize |
| 209 | * the device */ |
Alan Stern | 0458d5b | 2007-05-04 11:52:20 -0400 | [diff] [blame] | 210 | |
Alan Stern | f07600c | 2007-05-30 15:38:16 -0400 | [diff] [blame] | 211 | mutex_unlock(&us->dev_mutex); |
| 212 | return 0; |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 213 | } |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 214 | EXPORT_SYMBOL_GPL(usb_stor_post_reset); |
Alan Stern | 47104b0 | 2006-06-01 13:52:56 -0400 | [diff] [blame] | 215 | |
| 216 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | * fill_inquiry_response takes an unsigned char array (which must |
| 218 | * be at least 36 characters) and populates the vendor name, |
| 219 | * product name, and revision fields. Then the array is copied |
| 220 | * into the SCSI command's response buffer (oddly enough |
| 221 | * called request_buffer). data_len contains the length of the |
| 222 | * data array, which again must be at least 36. |
| 223 | */ |
| 224 | |
| 225 | void fill_inquiry_response(struct us_data *us, unsigned char *data, |
| 226 | unsigned int data_len) |
| 227 | { |
| 228 | if (data_len<36) // You lose. |
| 229 | return; |
| 230 | |
| 231 | if(data[0]&0x20) { /* USB device currently not connected. Return |
| 232 | peripheral qualifier 001b ("...however, the |
| 233 | physical device is not currently connected |
| 234 | to this logical unit") and leave vendor and |
| 235 | product identification empty. ("If the target |
| 236 | does store some of the INQUIRY data on the |
| 237 | device, it may return zeros or ASCII spaces |
| 238 | (20h) in those fields until the data is |
| 239 | available from the device."). */ |
| 240 | memset(data+8,0,28); |
| 241 | } else { |
| 242 | u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice); |
| 243 | memcpy(data+8, us->unusual_dev->vendorName, |
| 244 | strlen(us->unusual_dev->vendorName) > 8 ? 8 : |
| 245 | strlen(us->unusual_dev->vendorName)); |
| 246 | memcpy(data+16, us->unusual_dev->productName, |
| 247 | strlen(us->unusual_dev->productName) > 16 ? 16 : |
| 248 | strlen(us->unusual_dev->productName)); |
| 249 | data[32] = 0x30 + ((bcdDevice>>12) & 0x0F); |
| 250 | data[33] = 0x30 + ((bcdDevice>>8) & 0x0F); |
| 251 | data[34] = 0x30 + ((bcdDevice>>4) & 0x0F); |
| 252 | data[35] = 0x30 + ((bcdDevice) & 0x0F); |
| 253 | } |
| 254 | |
| 255 | usb_stor_set_xfer_buf(data, data_len, us->srb); |
| 256 | } |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 257 | EXPORT_SYMBOL_GPL(fill_inquiry_response); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | static int usb_stor_control_thread(void * __us) |
| 260 | { |
| 261 | struct us_data *us = (struct us_data *)__us; |
| 262 | struct Scsi_Host *host = us_to_host(us); |
| 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | for(;;) { |
| 265 | US_DEBUGP("*** thread sleeping.\n"); |
Alan Stern | 7119e3c | 2008-05-01 15:36:13 -0400 | [diff] [blame] | 266 | if (wait_for_completion_interruptible(&us->cmnd_ready)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | break; |
Alan Stern | 7119e3c | 2008-05-01 15:36:13 -0400 | [diff] [blame] | 268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | US_DEBUGP("*** thread awakened.\n"); |
| 270 | |
| 271 | /* lock the device pointers */ |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 272 | mutex_lock(&(us->dev_mutex)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | /* lock access to the state */ |
| 275 | scsi_lock(host); |
| 276 | |
Alan Stern | 543f781 | 2008-05-08 11:55:59 -0400 | [diff] [blame] | 277 | /* When we are called with no command pending, we're done */ |
| 278 | if (us->srb == NULL) { |
| 279 | scsi_unlock(host); |
| 280 | mutex_unlock(&us->dev_mutex); |
| 281 | US_DEBUGP("-- exiting\n"); |
| 282 | break; |
| 283 | } |
| 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | /* has the command timed out *already* ? */ |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 286 | if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | us->srb->result = DID_ABORT << 16; |
| 288 | goto SkipForAbort; |
| 289 | } |
| 290 | |
| 291 | scsi_unlock(host); |
| 292 | |
| 293 | /* reject the command if the direction indicator |
| 294 | * is UNKNOWN |
| 295 | */ |
| 296 | if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) { |
| 297 | US_DEBUGP("UNKNOWN data direction\n"); |
| 298 | us->srb->result = DID_ERROR << 16; |
| 299 | } |
| 300 | |
| 301 | /* reject if target != 0 or if LUN is higher than |
| 302 | * the maximum known LUN |
| 303 | */ |
| 304 | else if (us->srb->device->id && |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 305 | !(us->fflags & US_FL_SCM_MULT_TARG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | US_DEBUGP("Bad target number (%d:%d)\n", |
| 307 | us->srb->device->id, us->srb->device->lun); |
| 308 | us->srb->result = DID_BAD_TARGET << 16; |
| 309 | } |
| 310 | |
| 311 | else if (us->srb->device->lun > us->max_lun) { |
| 312 | US_DEBUGP("Bad LUN (%d:%d)\n", |
| 313 | us->srb->device->id, us->srb->device->lun); |
| 314 | us->srb->result = DID_BAD_TARGET << 16; |
| 315 | } |
| 316 | |
| 317 | /* Handle those devices which need us to fake |
| 318 | * their inquiry data */ |
| 319 | else if ((us->srb->cmnd[0] == INQUIRY) && |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 320 | (us->fflags & US_FL_FIX_INQUIRY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | unsigned char data_ptr[36] = { |
| 322 | 0x00, 0x80, 0x02, 0x02, |
| 323 | 0x1F, 0x00, 0x00, 0x00}; |
| 324 | |
| 325 | US_DEBUGP("Faking INQUIRY command\n"); |
| 326 | fill_inquiry_response(us, data_ptr, 36); |
| 327 | us->srb->result = SAM_STAT_GOOD; |
| 328 | } |
| 329 | |
| 330 | /* we've got a command, let's do it! */ |
| 331 | else { |
| 332 | US_DEBUG(usb_stor_show_command(us->srb)); |
| 333 | us->proto_handler(us->srb, us); |
| 334 | } |
| 335 | |
| 336 | /* lock access to the state */ |
| 337 | scsi_lock(host); |
| 338 | |
| 339 | /* indicate that the command is done */ |
Alan Stern | 543f781 | 2008-05-08 11:55:59 -0400 | [diff] [blame] | 340 | if (us->srb->result != DID_ABORT << 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | US_DEBUGP("scsi cmd done, result=0x%x\n", |
| 342 | us->srb->result); |
| 343 | us->srb->scsi_done(us->srb); |
| 344 | } else { |
| 345 | SkipForAbort: |
| 346 | US_DEBUGP("scsi command aborted\n"); |
| 347 | } |
| 348 | |
| 349 | /* If an abort request was received we need to signal that |
| 350 | * the abort has finished. The proper test for this is |
| 351 | * the TIMED_OUT flag, not srb->result == DID_ABORT, because |
Matthew Dharm | 226173e | 2005-08-25 20:03:50 -0700 | [diff] [blame] | 352 | * the timeout might have occurred after the command had |
| 353 | * already completed with a different result code. */ |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 354 | if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | complete(&(us->notify)); |
| 356 | |
Matthew Dharm | 226173e | 2005-08-25 20:03:50 -0700 | [diff] [blame] | 357 | /* Allow USB transfers to resume */ |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 358 | clear_bit(US_FLIDX_ABORTING, &us->dflags); |
| 359 | clear_bit(US_FLIDX_TIMED_OUT, &us->dflags); |
Matthew Dharm | 226173e | 2005-08-25 20:03:50 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | /* finished working on this command */ |
| 363 | us->srb = NULL; |
| 364 | scsi_unlock(host); |
| 365 | |
| 366 | /* unlock the device pointers */ |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 367 | mutex_unlock(&us->dev_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } /* for (;;) */ |
| 369 | |
Alan Stern | ed76cac | 2007-06-07 17:12:25 -0400 | [diff] [blame] | 370 | /* Wait until we are told to stop */ |
| 371 | for (;;) { |
| 372 | set_current_state(TASK_INTERRUPTIBLE); |
| 373 | if (kthread_should_stop()) |
| 374 | break; |
| 375 | schedule(); |
| 376 | } |
| 377 | __set_current_state(TASK_RUNNING); |
| 378 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /*********************************************************************** |
| 382 | * Device probing and disconnecting |
| 383 | ***********************************************************************/ |
| 384 | |
| 385 | /* Associate our private data with the USB device */ |
| 386 | static int associate_dev(struct us_data *us, struct usb_interface *intf) |
| 387 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 388 | US_DEBUGP("-- %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | /* Fill in the device-related fields */ |
| 391 | us->pusb_dev = interface_to_usbdev(intf); |
| 392 | us->pusb_intf = intf; |
| 393 | us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber; |
| 394 | US_DEBUGP("Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n", |
| 395 | le16_to_cpu(us->pusb_dev->descriptor.idVendor), |
| 396 | le16_to_cpu(us->pusb_dev->descriptor.idProduct), |
| 397 | le16_to_cpu(us->pusb_dev->descriptor.bcdDevice)); |
| 398 | US_DEBUGP("Interface Subclass: 0x%02x, Protocol: 0x%02x\n", |
| 399 | intf->cur_altsetting->desc.bInterfaceSubClass, |
| 400 | intf->cur_altsetting->desc.bInterfaceProtocol); |
| 401 | |
| 402 | /* Store our private data in the interface */ |
| 403 | usb_set_intfdata(intf, us); |
| 404 | |
| 405 | /* Allocate the device-related DMA-mapped buffers */ |
| 406 | us->cr = usb_buffer_alloc(us->pusb_dev, sizeof(*us->cr), |
| 407 | GFP_KERNEL, &us->cr_dma); |
| 408 | if (!us->cr) { |
| 409 | US_DEBUGP("usb_ctrlrequest allocation failed\n"); |
| 410 | return -ENOMEM; |
| 411 | } |
| 412 | |
| 413 | us->iobuf = usb_buffer_alloc(us->pusb_dev, US_IOBUF_SIZE, |
| 414 | GFP_KERNEL, &us->iobuf_dma); |
| 415 | if (!us->iobuf) { |
| 416 | US_DEBUGP("I/O buffer allocation failed\n"); |
| 417 | return -ENOMEM; |
| 418 | } |
| 419 | return 0; |
| 420 | } |
| 421 | |
Alan Stern | c838ea4 | 2008-12-15 10:40:06 -0500 | [diff] [blame] | 422 | /* Works only for digits and letters, but small and fast */ |
| 423 | #define TOLOWER(x) ((x) | 0x20) |
| 424 | |
Alan Stern | d4f373e | 2008-11-10 14:07:45 -0500 | [diff] [blame] | 425 | /* Adjust device flags based on the "quirks=" module parameter */ |
| 426 | static void adjust_quirks(struct us_data *us) |
| 427 | { |
Alan Stern | c838ea4 | 2008-12-15 10:40:06 -0500 | [diff] [blame] | 428 | char *p; |
| 429 | u16 vid = le16_to_cpu(us->pusb_dev->descriptor.idVendor); |
| 430 | u16 pid = le16_to_cpu(us->pusb_dev->descriptor.idProduct); |
| 431 | unsigned f = 0; |
| 432 | unsigned int mask = (US_FL_SANE_SENSE | US_FL_FIX_CAPACITY | |
| 433 | US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE | |
Alan Stern | d4f373e | 2008-11-10 14:07:45 -0500 | [diff] [blame] | 434 | US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 | |
Alan Stern | c838ea4 | 2008-12-15 10:40:06 -0500 | [diff] [blame] | 435 | US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE | |
| 436 | US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT); |
Alan Stern | d4f373e | 2008-11-10 14:07:45 -0500 | [diff] [blame] | 437 | |
Alan Stern | c838ea4 | 2008-12-15 10:40:06 -0500 | [diff] [blame] | 438 | p = quirks; |
| 439 | while (*p) { |
| 440 | /* Each entry consists of VID:PID:flags */ |
| 441 | if (vid == simple_strtoul(p, &p, 16) && |
| 442 | *p == ':' && |
| 443 | pid == simple_strtoul(p+1, &p, 16) && |
| 444 | *p == ':') |
Alan Stern | d4f373e | 2008-11-10 14:07:45 -0500 | [diff] [blame] | 445 | break; |
Alan Stern | c838ea4 | 2008-12-15 10:40:06 -0500 | [diff] [blame] | 446 | |
| 447 | /* Move forward to the next entry */ |
| 448 | while (*p) { |
| 449 | if (*p++ == ',') |
| 450 | break; |
Alan Stern | d4f373e | 2008-11-10 14:07:45 -0500 | [diff] [blame] | 451 | } |
| 452 | } |
Alan Stern | c838ea4 | 2008-12-15 10:40:06 -0500 | [diff] [blame] | 453 | if (!*p) /* No match */ |
| 454 | return; |
| 455 | |
| 456 | /* Collect the flags */ |
| 457 | while (*++p && *p != ',') { |
| 458 | switch (TOLOWER(*p)) { |
| 459 | case 'a': |
| 460 | f |= US_FL_SANE_SENSE; |
| 461 | break; |
| 462 | case 'c': |
| 463 | f |= US_FL_FIX_CAPACITY; |
| 464 | break; |
| 465 | case 'h': |
| 466 | f |= US_FL_CAPACITY_HEURISTICS; |
| 467 | break; |
| 468 | case 'i': |
| 469 | f |= US_FL_IGNORE_DEVICE; |
| 470 | break; |
| 471 | case 'l': |
| 472 | f |= US_FL_NOT_LOCKABLE; |
| 473 | break; |
| 474 | case 'm': |
| 475 | f |= US_FL_MAX_SECTORS_64; |
| 476 | break; |
| 477 | case 'o': |
| 478 | f |= US_FL_CAPACITY_OK; |
| 479 | break; |
| 480 | case 'r': |
| 481 | f |= US_FL_IGNORE_RESIDUE; |
| 482 | break; |
| 483 | case 's': |
| 484 | f |= US_FL_SINGLE_LUN; |
| 485 | break; |
| 486 | case 'w': |
| 487 | f |= US_FL_NO_WP_DETECT; |
| 488 | break; |
| 489 | /* Ignore unrecognized flag characters */ |
| 490 | } |
| 491 | } |
| 492 | us->fflags = (us->fflags & ~mask) | f; |
| 493 | dev_info(&us->pusb_intf->dev, "Quirks match for " |
| 494 | "vid %04x pid %04x: %x\n", |
| 495 | vid, pid, f); |
Alan Stern | d4f373e | 2008-11-10 14:07:45 -0500 | [diff] [blame] | 496 | } |
| 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | /* Get the unusual_devs entries and the string descriptors */ |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 499 | static int get_device_info(struct us_data *us, const struct usb_device_id *id, |
| 500 | struct us_unusual_dev *unusual_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | { |
| 502 | struct usb_device *dev = us->pusb_dev; |
| 503 | struct usb_interface_descriptor *idesc = |
| 504 | &us->pusb_intf->cur_altsetting->desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
| 506 | /* Store the entries */ |
| 507 | us->unusual_dev = unusual_dev; |
| 508 | us->subclass = (unusual_dev->useProtocol == US_SC_DEVICE) ? |
| 509 | idesc->bInterfaceSubClass : |
| 510 | unusual_dev->useProtocol; |
| 511 | us->protocol = (unusual_dev->useTransport == US_PR_DEVICE) ? |
| 512 | idesc->bInterfaceProtocol : |
| 513 | unusual_dev->useTransport; |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 514 | us->fflags = USB_US_ORIG_FLAGS(id->driver_info); |
Alan Stern | d4f373e | 2008-11-10 14:07:45 -0500 | [diff] [blame] | 515 | adjust_quirks(us); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 517 | if (us->fflags & US_FL_IGNORE_DEVICE) { |
Daniel Drake | 3c33242 | 2006-07-26 13:59:23 +0100 | [diff] [blame] | 518 | printk(KERN_INFO USB_STORAGE "device ignored\n"); |
| 519 | return -ENODEV; |
| 520 | } |
| 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | /* |
| 523 | * This flag is only needed when we're in high-speed, so let's |
| 524 | * disable it if we're in full-speed |
| 525 | */ |
| 526 | if (dev->speed != USB_SPEED_HIGH) |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 527 | us->fflags &= ~US_FL_GO_SLOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | /* Log a message if a non-generic unusual_dev entry contains an |
| 530 | * unnecessary subclass or protocol override. This may stimulate |
| 531 | * reports from users that will help us remove unneeded entries |
| 532 | * from the unusual_devs.h table. |
| 533 | */ |
| 534 | if (id->idVendor || id->idProduct) { |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 535 | static const char *msgs[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | "an unneeded SubClass entry", |
| 537 | "an unneeded Protocol entry", |
| 538 | "unneeded SubClass and Protocol entries"}; |
| 539 | struct usb_device_descriptor *ddesc = &dev->descriptor; |
| 540 | int msg = -1; |
| 541 | |
| 542 | if (unusual_dev->useProtocol != US_SC_DEVICE && |
| 543 | us->subclass == idesc->bInterfaceSubClass) |
| 544 | msg += 1; |
| 545 | if (unusual_dev->useTransport != US_PR_DEVICE && |
| 546 | us->protocol == idesc->bInterfaceProtocol) |
| 547 | msg += 2; |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 548 | if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | printk(KERN_NOTICE USB_STORAGE "This device " |
| 550 | "(%04x,%04x,%04x S %02x P %02x)" |
Phil Dibowitz | 5650b4d | 2006-06-24 17:27:54 -0700 | [diff] [blame] | 551 | " has %s in unusual_devs.h (kernel" |
| 552 | " %s)\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | " Please send a copy of this message to " |
Andrew Lunn | cef03f8 | 2008-04-23 22:04:30 +0200 | [diff] [blame] | 554 | "<linux-usb@vger.kernel.org> and " |
| 555 | "<usb-storage@lists.one-eyed-alien.net>\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | le16_to_cpu(ddesc->idVendor), |
| 557 | le16_to_cpu(ddesc->idProduct), |
| 558 | le16_to_cpu(ddesc->bcdDevice), |
| 559 | idesc->bInterfaceSubClass, |
| 560 | idesc->bInterfaceProtocol, |
Phil Dibowitz | 5650b4d | 2006-06-24 17:27:54 -0700 | [diff] [blame] | 561 | msgs[msg], |
Sam Ravnborg | 00f8b0c | 2007-03-05 00:30:55 -0800 | [diff] [blame] | 562 | utsname()->release); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
Daniel Drake | 3c33242 | 2006-07-26 13:59:23 +0100 | [diff] [blame] | 564 | |
| 565 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* Get the transport settings */ |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 569 | static void get_transport(struct us_data *us) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
| 571 | switch (us->protocol) { |
| 572 | case US_PR_CB: |
| 573 | us->transport_name = "Control/Bulk"; |
| 574 | us->transport = usb_stor_CB_transport; |
| 575 | us->transport_reset = usb_stor_CB_reset; |
| 576 | us->max_lun = 7; |
| 577 | break; |
| 578 | |
| 579 | case US_PR_CBI: |
| 580 | us->transport_name = "Control/Bulk/Interrupt"; |
Alan Stern | 64648a9 | 2008-11-20 14:20:03 -0500 | [diff] [blame] | 581 | us->transport = usb_stor_CB_transport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | us->transport_reset = usb_stor_CB_reset; |
| 583 | us->max_lun = 7; |
| 584 | break; |
| 585 | |
| 586 | case US_PR_BULK: |
| 587 | us->transport_name = "Bulk"; |
| 588 | us->transport = usb_stor_Bulk_transport; |
| 589 | us->transport_reset = usb_stor_Bulk_reset; |
| 590 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /* Get the protocol settings */ |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 595 | static void get_protocol(struct us_data *us) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | { |
| 597 | switch (us->subclass) { |
| 598 | case US_SC_RBC: |
| 599 | us->protocol_name = "Reduced Block Commands (RBC)"; |
| 600 | us->proto_handler = usb_stor_transparent_scsi_command; |
| 601 | break; |
| 602 | |
| 603 | case US_SC_8020: |
| 604 | us->protocol_name = "8020i"; |
Alan Stern | 3dae534 | 2008-11-20 14:22:18 -0500 | [diff] [blame] | 605 | us->proto_handler = usb_stor_pad12_command; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | us->max_lun = 0; |
| 607 | break; |
| 608 | |
| 609 | case US_SC_QIC: |
| 610 | us->protocol_name = "QIC-157"; |
Alan Stern | 3dae534 | 2008-11-20 14:22:18 -0500 | [diff] [blame] | 611 | us->proto_handler = usb_stor_pad12_command; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | us->max_lun = 0; |
| 613 | break; |
| 614 | |
| 615 | case US_SC_8070: |
| 616 | us->protocol_name = "8070i"; |
Alan Stern | 3dae534 | 2008-11-20 14:22:18 -0500 | [diff] [blame] | 617 | us->proto_handler = usb_stor_pad12_command; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | us->max_lun = 0; |
| 619 | break; |
| 620 | |
| 621 | case US_SC_SCSI: |
| 622 | us->protocol_name = "Transparent SCSI"; |
| 623 | us->proto_handler = usb_stor_transparent_scsi_command; |
| 624 | break; |
| 625 | |
| 626 | case US_SC_UFI: |
| 627 | us->protocol_name = "Uniform Floppy Interface (UFI)"; |
| 628 | us->proto_handler = usb_stor_ufi_command; |
| 629 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /* Get the pipe settings */ |
| 634 | static int get_pipes(struct us_data *us) |
| 635 | { |
| 636 | struct usb_host_interface *altsetting = |
| 637 | us->pusb_intf->cur_altsetting; |
| 638 | int i; |
| 639 | struct usb_endpoint_descriptor *ep; |
| 640 | struct usb_endpoint_descriptor *ep_in = NULL; |
| 641 | struct usb_endpoint_descriptor *ep_out = NULL; |
| 642 | struct usb_endpoint_descriptor *ep_int = NULL; |
| 643 | |
| 644 | /* |
Alan Stern | 1096f78 | 2007-01-22 11:58:34 -0500 | [diff] [blame] | 645 | * Find the first endpoint of each type we need. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | * We are expecting a minimum of 2 endpoints - in and out (bulk). |
Alan Stern | 1096f78 | 2007-01-22 11:58:34 -0500 | [diff] [blame] | 647 | * An optional interrupt-in is OK (necessary for CBI protocol). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | * We will ignore any others. |
| 649 | */ |
| 650 | for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { |
| 651 | ep = &altsetting->endpoint[i].desc; |
| 652 | |
Luiz Fernando N. Capitulino | 0472074 | 2006-10-26 13:03:03 -0300 | [diff] [blame] | 653 | if (usb_endpoint_xfer_bulk(ep)) { |
Alan Stern | 1096f78 | 2007-01-22 11:58:34 -0500 | [diff] [blame] | 654 | if (usb_endpoint_dir_in(ep)) { |
| 655 | if (!ep_in) |
| 656 | ep_in = ep; |
| 657 | } else { |
| 658 | if (!ep_out) |
| 659 | ep_out = ep; |
| 660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Alan Stern | 1096f78 | 2007-01-22 11:58:34 -0500 | [diff] [blame] | 663 | else if (usb_endpoint_is_int_in(ep)) { |
| 664 | if (!ep_int) |
| 665 | ep_int = ep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
| 669 | if (!ep_in || !ep_out || (us->protocol == US_PR_CBI && !ep_int)) { |
| 670 | US_DEBUGP("Endpoint sanity check failed! Rejecting dev.\n"); |
| 671 | return -EIO; |
| 672 | } |
| 673 | |
| 674 | /* Calculate and store the pipe values */ |
| 675 | us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0); |
| 676 | us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0); |
| 677 | us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev, |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 678 | usb_endpoint_num(ep_out)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev, |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 680 | usb_endpoint_num(ep_in)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | if (ep_int) { |
| 682 | us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev, |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 683 | usb_endpoint_num(ep_int)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | us->ep_bInterval = ep_int->bInterval; |
| 685 | } |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | /* Initialize all the dynamic resources we need */ |
| 690 | static int usb_stor_acquire_resources(struct us_data *us) |
| 691 | { |
| 692 | int p; |
Alan Stern | 3f13e66 | 2005-10-23 19:43:36 -0700 | [diff] [blame] | 693 | struct task_struct *th; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | us->current_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 696 | if (!us->current_urb) { |
| 697 | US_DEBUGP("URB allocation failed\n"); |
| 698 | return -ENOMEM; |
| 699 | } |
| 700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | /* Just before we start our control thread, initialize |
| 702 | * the device if it needs initialization */ |
Alan Stern | b876aef | 2005-10-23 19:38:56 -0700 | [diff] [blame] | 703 | if (us->unusual_dev->initFunction) { |
| 704 | p = us->unusual_dev->initFunction(us); |
| 705 | if (p) |
| 706 | return p; |
| 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
| 709 | /* Start up our control thread */ |
Alan Stern | ed76cac | 2007-06-07 17:12:25 -0400 | [diff] [blame] | 710 | th = kthread_run(usb_stor_control_thread, us, "usb-storage"); |
Alan Stern | 3f13e66 | 2005-10-23 19:43:36 -0700 | [diff] [blame] | 711 | if (IS_ERR(th)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | printk(KERN_WARNING USB_STORAGE |
| 713 | "Unable to start control thread\n"); |
Alan Stern | 3f13e66 | 2005-10-23 19:43:36 -0700 | [diff] [blame] | 714 | return PTR_ERR(th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
Alan Stern | ed76cac | 2007-06-07 17:12:25 -0400 | [diff] [blame] | 716 | us->ctl_thread = th; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
| 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | /* Release all our dynamic resources */ |
| 722 | static void usb_stor_release_resources(struct us_data *us) |
| 723 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 724 | US_DEBUGP("-- %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
| 726 | /* Tell the control thread to exit. The SCSI host must |
Alan Stern | 543f781 | 2008-05-08 11:55:59 -0400 | [diff] [blame] | 727 | * already have been removed and the DISCONNECTING flag set |
| 728 | * so that we won't accept any more commands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | */ |
| 730 | US_DEBUGP("-- sending exit command to thread\n"); |
Alan Stern | 7119e3c | 2008-05-01 15:36:13 -0400 | [diff] [blame] | 731 | complete(&us->cmnd_ready); |
Alan Stern | ed76cac | 2007-06-07 17:12:25 -0400 | [diff] [blame] | 732 | if (us->ctl_thread) |
| 733 | kthread_stop(us->ctl_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
| 735 | /* Call the destructor routine, if it exists */ |
| 736 | if (us->extra_destructor) { |
| 737 | US_DEBUGP("-- calling extra_destructor()\n"); |
| 738 | us->extra_destructor(us->extra); |
| 739 | } |
| 740 | |
| 741 | /* Free the extra data and the URB */ |
| 742 | kfree(us->extra); |
| 743 | usb_free_urb(us->current_urb); |
| 744 | } |
| 745 | |
| 746 | /* Dissociate from the USB device */ |
| 747 | static void dissociate_dev(struct us_data *us) |
| 748 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 749 | US_DEBUGP("-- %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
| 751 | /* Free the device-related DMA-mapped buffers */ |
| 752 | if (us->cr) |
| 753 | usb_buffer_free(us->pusb_dev, sizeof(*us->cr), us->cr, |
| 754 | us->cr_dma); |
| 755 | if (us->iobuf) |
| 756 | usb_buffer_free(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, |
| 757 | us->iobuf_dma); |
| 758 | |
| 759 | /* Remove our private data from the interface */ |
| 760 | usb_set_intfdata(us->pusb_intf, NULL); |
| 761 | } |
| 762 | |
Alan Stern | 543f781 | 2008-05-08 11:55:59 -0400 | [diff] [blame] | 763 | /* First stage of disconnect processing: stop SCSI scanning, |
| 764 | * remove the host, and stop accepting new commands |
| 765 | */ |
Matthew Dharm | 77f4632 | 2005-07-28 14:44:29 -0700 | [diff] [blame] | 766 | static void quiesce_and_remove_host(struct us_data *us) |
| 767 | { |
Alan Stern | eecd11e | 2006-06-19 14:50:15 -0400 | [diff] [blame] | 768 | struct Scsi_Host *host = us_to_host(us); |
| 769 | |
Alan Stern | 543f781 | 2008-05-08 11:55:59 -0400 | [diff] [blame] | 770 | /* If the device is really gone, cut short reset delays */ |
| 771 | if (us->pusb_dev->state == USB_STATE_NOTATTACHED) |
| 772 | set_bit(US_FLIDX_DISCONNECTING, &us->dflags); |
| 773 | |
| 774 | /* Prevent SCSI-scanning (if it hasn't started yet) |
| 775 | * and wait for the SCSI-scanning thread to stop. |
| 776 | */ |
| 777 | set_bit(US_FLIDX_DONT_SCAN, &us->dflags); |
| 778 | wake_up(&us->delay_wait); |
| 779 | wait_for_completion(&us->scanning_done); |
| 780 | |
| 781 | /* Removing the host will perform an orderly shutdown: caches |
| 782 | * synchronized, disks spun down, etc. |
| 783 | */ |
| 784 | scsi_remove_host(host); |
| 785 | |
| 786 | /* Prevent any new commands from being accepted and cut short |
| 787 | * reset delays. |
| 788 | */ |
Alan Stern | eecd11e | 2006-06-19 14:50:15 -0400 | [diff] [blame] | 789 | scsi_lock(host); |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 790 | set_bit(US_FLIDX_DISCONNECTING, &us->dflags); |
Alan Stern | eecd11e | 2006-06-19 14:50:15 -0400 | [diff] [blame] | 791 | scsi_unlock(host); |
Matthew Dharm | 77f4632 | 2005-07-28 14:44:29 -0700 | [diff] [blame] | 792 | wake_up(&us->delay_wait); |
Matthew Dharm | 77f4632 | 2005-07-28 14:44:29 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | /* Second stage of disconnect processing: deallocate all resources */ |
| 796 | static void release_everything(struct us_data *us) |
| 797 | { |
| 798 | usb_stor_release_resources(us); |
| 799 | dissociate_dev(us); |
| 800 | |
| 801 | /* Drop our reference to the host; the SCSI core will free it |
| 802 | * (and "us" along with it) when the refcount becomes 0. */ |
| 803 | scsi_host_put(us_to_host(us)); |
| 804 | } |
| 805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | /* Thread to carry out delayed SCSI-device scanning */ |
| 807 | static int usb_stor_scan_thread(void * __us) |
| 808 | { |
| 809 | struct us_data *us = (struct us_data *)__us; |
| 810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | printk(KERN_DEBUG |
| 812 | "usb-storage: device found at %d\n", us->pusb_dev->devnum); |
| 813 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 814 | set_freezable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | /* Wait for the timeout to expire or for a disconnect */ |
| 816 | if (delay_use > 0) { |
| 817 | printk(KERN_DEBUG "usb-storage: waiting for device " |
| 818 | "to settle before scanning\n"); |
Rafael J. Wysocki | e42837b | 2007-10-18 03:04:45 -0700 | [diff] [blame] | 819 | wait_event_freezable_timeout(us->delay_wait, |
Alan Stern | 543f781 | 2008-05-08 11:55:59 -0400 | [diff] [blame] | 820 | test_bit(US_FLIDX_DONT_SCAN, &us->dflags), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | delay_use * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /* If the device is still connected, perform the scanning */ |
Alan Stern | 543f781 | 2008-05-08 11:55:59 -0400 | [diff] [blame] | 825 | if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) { |
Alan Stern | b876aef | 2005-10-23 19:38:56 -0700 | [diff] [blame] | 826 | |
| 827 | /* For bulk-only devices, determine the max LUN value */ |
| 828 | if (us->protocol == US_PR_BULK && |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 829 | !(us->fflags & US_FL_SINGLE_LUN)) { |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 830 | mutex_lock(&us->dev_mutex); |
Alan Stern | b876aef | 2005-10-23 19:38:56 -0700 | [diff] [blame] | 831 | us->max_lun = usb_stor_Bulk_max_lun(us); |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 832 | mutex_unlock(&us->dev_mutex); |
Alan Stern | b876aef | 2005-10-23 19:38:56 -0700 | [diff] [blame] | 833 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | scsi_scan_host(us_to_host(us)); |
| 835 | printk(KERN_DEBUG "usb-storage: device scan complete\n"); |
| 836 | |
| 837 | /* Should we unbind if no devices were detected? */ |
| 838 | } |
| 839 | |
Alan Stern | 2f67cd5 | 2007-08-16 16:16:00 -0400 | [diff] [blame] | 840 | complete_and_exit(&us->scanning_done, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 844 | /* First part of general USB mass-storage probing */ |
| 845 | int usb_stor_probe1(struct us_data **pus, |
| 846 | struct usb_interface *intf, |
| 847 | const struct usb_device_id *id, |
| 848 | struct us_unusual_dev *unusual_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | { |
| 850 | struct Scsi_Host *host; |
| 851 | struct us_data *us; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | int result; |
Pete Zaitcev | a00828e | 2005-10-22 20:15:09 -0700 | [diff] [blame] | 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | US_DEBUGP("USB Mass Storage device detected\n"); |
| 855 | |
| 856 | /* |
| 857 | * Ask the SCSI layer to allocate a host structure, with extra |
| 858 | * space at the end for our private us_data structure. |
| 859 | */ |
| 860 | host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us)); |
| 861 | if (!host) { |
| 862 | printk(KERN_WARNING USB_STORAGE |
| 863 | "Unable to allocate the scsi host\n"); |
| 864 | return -ENOMEM; |
| 865 | } |
| 866 | |
Richard Sharpe | 17f0602 | 2007-10-10 10:56:28 -0700 | [diff] [blame] | 867 | /* |
| 868 | * Allow 16-byte CDBs and thus > 2TB |
| 869 | */ |
| 870 | host->max_cmd_len = 16; |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 871 | *pus = us = host_to_us(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | memset(us, 0, sizeof(struct us_data)); |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 873 | mutex_init(&(us->dev_mutex)); |
Alan Stern | 7119e3c | 2008-05-01 15:36:13 -0400 | [diff] [blame] | 874 | init_completion(&us->cmnd_ready); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | init_completion(&(us->notify)); |
| 876 | init_waitqueue_head(&us->delay_wait); |
Alan Stern | 2f67cd5 | 2007-08-16 16:16:00 -0400 | [diff] [blame] | 877 | init_completion(&us->scanning_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
| 879 | /* Associate the us_data structure with the USB device */ |
| 880 | result = associate_dev(us, intf); |
| 881 | if (result) |
| 882 | goto BadDevice; |
| 883 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 884 | /* Get the unusual_devs entries and the descriptors */ |
| 885 | result = get_device_info(us, id, unusual_dev); |
Daniel Drake | 3c33242 | 2006-07-26 13:59:23 +0100 | [diff] [blame] | 886 | if (result) |
| 887 | goto BadDevice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 889 | /* Get standard transport and protocol settings */ |
| 890 | get_transport(us); |
| 891 | get_protocol(us); |
| 892 | |
| 893 | /* Give the caller a chance to fill in specialized transport |
| 894 | * or protocol settings. |
| 895 | */ |
| 896 | return 0; |
| 897 | |
| 898 | BadDevice: |
| 899 | US_DEBUGP("storage_probe() failed\n"); |
| 900 | release_everything(us); |
| 901 | return result; |
| 902 | } |
| 903 | EXPORT_SYMBOL_GPL(usb_stor_probe1); |
| 904 | |
| 905 | /* Second part of general USB mass-storage probing */ |
| 906 | int usb_stor_probe2(struct us_data *us) |
| 907 | { |
| 908 | struct task_struct *th; |
| 909 | int result; |
| 910 | |
| 911 | /* Make sure the transport and protocol have both been set */ |
| 912 | if (!us->transport || !us->proto_handler) { |
| 913 | result = -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | goto BadDevice; |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 915 | } |
| 916 | US_DEBUGP("Transport: %s\n", us->transport_name); |
| 917 | US_DEBUGP("Protocol: %s\n", us->protocol_name); |
| 918 | |
| 919 | /* fix for single-lun devices */ |
| 920 | if (us->fflags & US_FL_SINGLE_LUN) |
| 921 | us->max_lun = 0; |
| 922 | |
| 923 | /* Find the endpoints and calculate pipe values */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | result = get_pipes(us); |
| 925 | if (result) |
| 926 | goto BadDevice; |
| 927 | |
| 928 | /* Acquire all the other resources and add the host */ |
| 929 | result = usb_stor_acquire_resources(us); |
| 930 | if (result) |
| 931 | goto BadDevice; |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 932 | result = scsi_add_host(us_to_host(us), &us->pusb_intf->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | if (result) { |
| 934 | printk(KERN_WARNING USB_STORAGE |
| 935 | "Unable to add the scsi host\n"); |
| 936 | goto BadDevice; |
| 937 | } |
| 938 | |
| 939 | /* Start up the thread for delayed SCSI-device scanning */ |
Alan Stern | 3f13e66 | 2005-10-23 19:43:36 -0700 | [diff] [blame] | 940 | th = kthread_create(usb_stor_scan_thread, us, "usb-stor-scan"); |
| 941 | if (IS_ERR(th)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | printk(KERN_WARNING USB_STORAGE |
| 943 | "Unable to start the device-scanning thread\n"); |
Alan Stern | 543f781 | 2008-05-08 11:55:59 -0400 | [diff] [blame] | 944 | complete(&us->scanning_done); |
Matthew Dharm | 77f4632 | 2005-07-28 14:44:29 -0700 | [diff] [blame] | 945 | quiesce_and_remove_host(us); |
Alan Stern | 3f13e66 | 2005-10-23 19:43:36 -0700 | [diff] [blame] | 946 | result = PTR_ERR(th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | goto BadDevice; |
| 948 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | |
Alan Stern | 3f13e66 | 2005-10-23 19:43:36 -0700 | [diff] [blame] | 950 | wake_up_process(th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
| 952 | return 0; |
| 953 | |
| 954 | /* We come here if there are any problems */ |
| 955 | BadDevice: |
| 956 | US_DEBUGP("storage_probe() failed\n"); |
Matthew Dharm | 77f4632 | 2005-07-28 14:44:29 -0700 | [diff] [blame] | 957 | release_everything(us); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | return result; |
| 959 | } |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 960 | EXPORT_SYMBOL_GPL(usb_stor_probe2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 962 | /* Handle a USB mass-storage disconnect */ |
| 963 | void usb_stor_disconnect(struct usb_interface *intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | { |
| 965 | struct us_data *us = usb_get_intfdata(intf); |
| 966 | |
| 967 | US_DEBUGP("storage_disconnect() called\n"); |
Matthew Dharm | 77f4632 | 2005-07-28 14:44:29 -0700 | [diff] [blame] | 968 | quiesce_and_remove_host(us); |
| 969 | release_everything(us); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | } |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 971 | EXPORT_SYMBOL_GPL(usb_stor_disconnect); |
| 972 | |
| 973 | /* The main probe routine for standard devices */ |
| 974 | static int storage_probe(struct usb_interface *intf, |
| 975 | const struct usb_device_id *id) |
| 976 | { |
| 977 | struct us_data *us; |
| 978 | int result; |
| 979 | |
| 980 | /* |
| 981 | * If libusual is configured, let it decide whether a standard |
| 982 | * device should be handled by usb-storage or by ub. |
| 983 | * If the device isn't standard (is handled by a subdriver |
| 984 | * module) then don't accept it. |
| 985 | */ |
| 986 | if (usb_usual_check_type(id, USB_US_TYPE_STOR) || |
| 987 | usb_usual_ignore_device(intf)) |
| 988 | return -ENXIO; |
| 989 | |
| 990 | /* |
| 991 | * Call the general probe procedures. |
| 992 | * |
| 993 | * The unusual_dev_list array is parallel to the usb_storage_usb_ids |
| 994 | * table, so we use the index of the id entry to find the |
| 995 | * corresponding unusual_devs entry. |
| 996 | */ |
| 997 | result = usb_stor_probe1(&us, intf, id, |
| 998 | (id - usb_storage_usb_ids) + us_unusual_dev_list); |
| 999 | if (result) |
| 1000 | return result; |
| 1001 | |
| 1002 | /* No special transport or protocol settings in the main module */ |
| 1003 | |
| 1004 | result = usb_stor_probe2(us); |
| 1005 | return result; |
| 1006 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | |
| 1008 | /*********************************************************************** |
| 1009 | * Initialization and registration |
| 1010 | ***********************************************************************/ |
| 1011 | |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 1012 | static struct usb_driver usb_storage_driver = { |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 1013 | .name = "usb-storage", |
| 1014 | .probe = storage_probe, |
Alan Stern | e6e244b | 2009-02-12 14:47:44 -0500 | [diff] [blame] | 1015 | .disconnect = usb_stor_disconnect, |
| 1016 | .suspend = usb_stor_suspend, |
| 1017 | .resume = usb_stor_resume, |
| 1018 | .reset_resume = usb_stor_reset_resume, |
| 1019 | .pre_reset = usb_stor_pre_reset, |
| 1020 | .post_reset = usb_stor_post_reset, |
| 1021 | .id_table = usb_storage_usb_ids, |
Alan Stern | 543f781 | 2008-05-08 11:55:59 -0400 | [diff] [blame] | 1022 | .soft_unbind = 1, |
Alan Stern | ce2596d | 2005-10-23 19:41:39 -0700 | [diff] [blame] | 1023 | }; |
| 1024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | static int __init usb_stor_init(void) |
| 1026 | { |
| 1027 | int retval; |
Alan Stern | d4f373e | 2008-11-10 14:07:45 -0500 | [diff] [blame] | 1028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | printk(KERN_INFO "Initializing USB Mass Storage driver...\n"); |
| 1030 | |
| 1031 | /* register the driver, return usb_register return code if error */ |
| 1032 | retval = usb_register(&usb_storage_driver); |
Pete Zaitcev | a00828e | 2005-10-22 20:15:09 -0700 | [diff] [blame] | 1033 | if (retval == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | printk(KERN_INFO "USB Mass Storage support registered.\n"); |
Pete Zaitcev | a00828e | 2005-10-22 20:15:09 -0700 | [diff] [blame] | 1035 | usb_usual_set_present(USB_US_TYPE_STOR); |
| 1036 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | return retval; |
| 1038 | } |
| 1039 | |
| 1040 | static void __exit usb_stor_exit(void) |
| 1041 | { |
| 1042 | US_DEBUGP("usb_stor_exit() called\n"); |
| 1043 | |
| 1044 | /* Deregister the driver |
| 1045 | * This will cause disconnect() to be called for each |
| 1046 | * attached unit |
| 1047 | */ |
| 1048 | US_DEBUGP("-- calling usb_deregister()\n"); |
| 1049 | usb_deregister(&usb_storage_driver) ; |
| 1050 | |
Pete Zaitcev | a00828e | 2005-10-22 20:15:09 -0700 | [diff] [blame] | 1051 | usb_usual_clear_present(USB_US_TYPE_STOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | module_init(usb_stor_init); |
| 1055 | module_exit(usb_stor_exit); |