usb.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Driver for USB Mass Storage compliant devices
  4. *
  5. * Current development and maintenance by:
  6. * (c) 1999-2003 Matthew Dharm ([email protected])
  7. *
  8. * Developed with the assistance of:
  9. * (c) 2000 David L. Brown, Jr. ([email protected])
  10. * (c) 2003-2009 Alan Stern ([email protected])
  11. *
  12. * Initial work by:
  13. * (c) 1999 Michael Gee ([email protected])
  14. *
  15. * usb_device_id support by Adam J. Richter ([email protected]):
  16. * (c) 2000 Yggdrasil Computing, Inc.
  17. *
  18. * This driver is based on the 'USB Mass Storage Class' document. This
  19. * describes in detail the protocol used to communicate with such
  20. * devices. Clearly, the designers had SCSI and ATAPI commands in
  21. * mind when they created this document. The commands are all very
  22. * similar to commands in the SCSI-II and ATAPI specifications.
  23. *
  24. * It is important to note that in a number of cases this class
  25. * exhibits class-specific exemptions from the USB specification.
  26. * Notably the usage of NAK, STALL and ACK differs from the norm, in
  27. * that they are used to communicate wait, failed and OK on commands.
  28. *
  29. * Also, for certain devices, the interrupt endpoint is used to convey
  30. * status of a command.
  31. */
  32. #ifdef CONFIG_USB_STORAGE_DEBUG
  33. #define DEBUG
  34. #endif
  35. #include <linux/sched.h>
  36. #include <linux/errno.h>
  37. #include <linux/module.h>
  38. #include <linux/slab.h>
  39. #include <linux/kthread.h>
  40. #include <linux/mutex.h>
  41. #include <linux/utsname.h>
  42. #include <scsi/scsi.h>
  43. #include <scsi/scsi_cmnd.h>
  44. #include <scsi/scsi_device.h>
  45. #include "usb.h"
  46. #include "scsiglue.h"
  47. #include "transport.h"
  48. #include "protocol.h"
  49. #include "debug.h"
  50. #include "initializers.h"
  51. #include "sierra_ms.h"
  52. #include "option_ms.h"
  53. #if IS_ENABLED(CONFIG_USB_UAS)
  54. #include "uas-detect.h"
  55. #endif
  56. #define DRV_NAME "usb-storage"
  57. /* Some informational data */
  58. MODULE_AUTHOR("Matthew Dharm <[email protected]>");
  59. MODULE_DESCRIPTION("USB Mass Storage driver for Linux");
  60. MODULE_LICENSE("GPL");
  61. static unsigned int delay_use = 1;
  62. module_param(delay_use, uint, S_IRUGO | S_IWUSR);
  63. MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device");
  64. static char quirks[128];
  65. module_param_string(quirks, quirks, sizeof(quirks), S_IRUGO | S_IWUSR);
  66. MODULE_PARM_DESC(quirks, "supplemental list of device IDs and their quirks");
  67. /*
  68. * The entries in this table correspond, line for line,
  69. * with the entries in usb_storage_usb_ids[], defined in usual-tables.c.
  70. */
  71. /*
  72. *The vendor name should be kept at eight characters or less, and
  73. * the product name should be kept at 16 characters or less. If a device
  74. * has the US_FL_FIX_INQUIRY flag, then the vendor and product names
  75. * normally generated by a device through the INQUIRY response will be
  76. * taken from this list, and this is the reason for the above size
  77. * restriction. However, if the flag is not present, then you
  78. * are free to use as many characters as you like.
  79. */
  80. #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
  81. vendor_name, product_name, use_protocol, use_transport, \
  82. init_function, Flags) \
  83. { \
  84. .vendorName = vendor_name, \
  85. .productName = product_name, \
  86. .useProtocol = use_protocol, \
  87. .useTransport = use_transport, \
  88. .initFunction = init_function, \
  89. }
  90. #define COMPLIANT_DEV UNUSUAL_DEV
  91. #define USUAL_DEV(use_protocol, use_transport) \
  92. { \
  93. .useProtocol = use_protocol, \
  94. .useTransport = use_transport, \
  95. }
  96. #define UNUSUAL_VENDOR_INTF(idVendor, cl, sc, pr, \
  97. vendor_name, product_name, use_protocol, use_transport, \
  98. init_function, Flags) \
  99. { \
  100. .vendorName = vendor_name, \
  101. .productName = product_name, \
  102. .useProtocol = use_protocol, \
  103. .useTransport = use_transport, \
  104. .initFunction = init_function, \
  105. }
  106. static const struct us_unusual_dev us_unusual_dev_list[] = {
  107. # include "unusual_devs.h"
  108. { } /* Terminating entry */
  109. };
  110. static const struct us_unusual_dev for_dynamic_ids =
  111. USUAL_DEV(USB_SC_SCSI, USB_PR_BULK);
  112. #undef UNUSUAL_DEV
  113. #undef COMPLIANT_DEV
  114. #undef USUAL_DEV
  115. #undef UNUSUAL_VENDOR_INTF
  116. #ifdef CONFIG_LOCKDEP
  117. static struct lock_class_key us_interface_key[USB_MAXINTERFACES];
  118. static void us_set_lock_class(struct mutex *mutex,
  119. struct usb_interface *intf)
  120. {
  121. struct usb_device *udev = interface_to_usbdev(intf);
  122. struct usb_host_config *config = udev->actconfig;
  123. int i;
  124. for (i = 0; i < config->desc.bNumInterfaces; i++) {
  125. if (config->interface[i] == intf)
  126. break;
  127. }
  128. BUG_ON(i == config->desc.bNumInterfaces);
  129. lockdep_set_class(mutex, &us_interface_key[i]);
  130. }
  131. #else
  132. static void us_set_lock_class(struct mutex *mutex,
  133. struct usb_interface *intf)
  134. {
  135. }
  136. #endif
  137. #ifdef CONFIG_PM /* Minimal support for suspend and resume */
  138. int usb_stor_suspend(struct usb_interface *iface, pm_message_t message)
  139. {
  140. struct us_data *us = usb_get_intfdata(iface);
  141. /* Wait until no command is running */
  142. mutex_lock(&us->dev_mutex);
  143. if (us->suspend_resume_hook)
  144. (us->suspend_resume_hook)(us, US_SUSPEND);
  145. /*
  146. * When runtime PM is working, we'll set a flag to indicate
  147. * whether we should autoresume when a SCSI request arrives.
  148. */
  149. mutex_unlock(&us->dev_mutex);
  150. return 0;
  151. }
  152. EXPORT_SYMBOL_GPL(usb_stor_suspend);
  153. int usb_stor_resume(struct usb_interface *iface)
  154. {
  155. struct us_data *us = usb_get_intfdata(iface);
  156. mutex_lock(&us->dev_mutex);
  157. if (us->suspend_resume_hook)
  158. (us->suspend_resume_hook)(us, US_RESUME);
  159. mutex_unlock(&us->dev_mutex);
  160. return 0;
  161. }
  162. EXPORT_SYMBOL_GPL(usb_stor_resume);
  163. int usb_stor_reset_resume(struct usb_interface *iface)
  164. {
  165. struct us_data *us = usb_get_intfdata(iface);
  166. /* Report the reset to the SCSI core */
  167. usb_stor_report_bus_reset(us);
  168. /*
  169. * If any of the subdrivers implemented a reinitialization scheme,
  170. * this is where the callback would be invoked.
  171. */
  172. return 0;
  173. }
  174. EXPORT_SYMBOL_GPL(usb_stor_reset_resume);
  175. #endif /* CONFIG_PM */
  176. /*
  177. * The next two routines get called just before and just after
  178. * a USB port reset, whether from this driver or a different one.
  179. */
  180. int usb_stor_pre_reset(struct usb_interface *iface)
  181. {
  182. #if defined(CONFIG_USB_HOST_SAMSUNG_FEATURE)
  183. struct us_data *us;
  184. unsigned long jiffies_expire = jiffies + HZ;
  185. int mu_lock = 1;
  186. pr_info("%s +\n", __func__);
  187. us = usb_get_intfdata(iface);
  188. /* Make sure no command runs during the reset */
  189. while (!mutex_trylock(&us->dev_mutex)) {
  190. /* If we can't acquire the lock after waiting one second,
  191. * we're probably deadlocked */
  192. if (time_after(jiffies, jiffies_expire))
  193. goto busy;
  194. msleep(15);
  195. if (us->pusb_dev->state == USB_STATE_NOTATTACHED) {
  196. mu_lock = 0;
  197. goto skip;
  198. }
  199. if (us->pusb_dev->state == USB_STATE_SUSPENDED) {
  200. mu_lock = 0;
  201. goto skip;
  202. }
  203. if (iface->condition == USB_INTERFACE_UNBINDING ||
  204. iface->condition == USB_INTERFACE_UNBOUND) {
  205. mu_lock = 0;
  206. goto skip;
  207. }
  208. }
  209. goto skip;
  210. busy:
  211. pr_info("%s busy\n", __func__);
  212. set_bit(US_FLIDX_ABORTING, &us->dflags);
  213. usb_stor_stop_transport(us);
  214. /* wait 6 seconds. usb unlink may be spend 5 sec. */
  215. jiffies_expire = jiffies + 6*HZ;
  216. pr_info("%s try lock again\n", __func__);
  217. while (!mutex_trylock(&us->dev_mutex)) {
  218. /* If we can't acquire the lock after waiting one second,
  219. * we're probably deadlocked */
  220. if (time_after(jiffies, jiffies_expire)) {
  221. mu_lock = 0;
  222. goto skip;
  223. }
  224. msleep(15);
  225. if (us->pusb_dev->state == USB_STATE_NOTATTACHED) {
  226. mu_lock = 0;
  227. goto skip;
  228. }
  229. if (us->pusb_dev->state == USB_STATE_SUSPENDED) {
  230. mu_lock = 0;
  231. goto skip;
  232. }
  233. if (iface->condition == USB_INTERFACE_UNBINDING ||
  234. iface->condition == USB_INTERFACE_UNBOUND) {
  235. mu_lock = 0;
  236. goto skip;
  237. }
  238. }
  239. skip:
  240. set_bit(US_FLIDX_RESETTING, &us->dflags);
  241. if (mu_lock)
  242. set_bit(US_FLIDX_MUTEX_LOCK, &us->dflags);
  243. pr_info("%s -\n", __func__);
  244. return 0;
  245. #else
  246. struct us_data *us = usb_get_intfdata(iface);
  247. /* Make sure no command runs during the reset */
  248. mutex_lock(&us->dev_mutex);
  249. return 0;
  250. #endif
  251. }
  252. EXPORT_SYMBOL_GPL(usb_stor_pre_reset);
  253. int usb_stor_post_reset(struct usb_interface *iface)
  254. {
  255. #if defined(CONFIG_USB_HOST_SAMSUNG_FEATURE)
  256. struct us_data *us = usb_get_intfdata(iface);
  257. pr_info("%s +\n", __func__);
  258. /* Report the reset to the SCSI core */
  259. usb_stor_report_bus_reset(us);
  260. /*
  261. * If any of the subdrivers implemented a reinitialization scheme,
  262. * this is where the callback would be invoked.
  263. */
  264. clear_bit(US_FLIDX_RESETTING, &us->dflags);
  265. clear_bit(US_FLIDX_ABORTING, &us->dflags);
  266. if (test_bit(US_FLIDX_MUTEX_LOCK, &us->dflags)) {
  267. mutex_unlock(&us->dev_mutex);
  268. clear_bit(US_FLIDX_MUTEX_LOCK, &us->dflags);
  269. pr_info("%s mutex_unlock\n", __func__);
  270. }
  271. pr_info("%s -\n", __func__);
  272. return 0;
  273. #else
  274. struct us_data *us = usb_get_intfdata(iface);
  275. /* Report the reset to the SCSI core */
  276. usb_stor_report_bus_reset(us);
  277. /*
  278. * If any of the subdrivers implemented a reinitialization scheme,
  279. * this is where the callback would be invoked.
  280. */
  281. mutex_unlock(&us->dev_mutex);
  282. return 0;
  283. #endif
  284. }
  285. EXPORT_SYMBOL_GPL(usb_stor_post_reset);
  286. /*
  287. * fill_inquiry_response takes an unsigned char array (which must
  288. * be at least 36 characters) and populates the vendor name,
  289. * product name, and revision fields. Then the array is copied
  290. * into the SCSI command's response buffer (oddly enough
  291. * called request_buffer). data_len contains the length of the
  292. * data array, which again must be at least 36.
  293. */
  294. void fill_inquiry_response(struct us_data *us, unsigned char *data,
  295. unsigned int data_len)
  296. {
  297. if (data_len < 36) /* You lose. */
  298. return;
  299. memset(data+8, ' ', 28);
  300. if (data[0]&0x20) { /*
  301. * USB device currently not connected. Return
  302. * peripheral qualifier 001b ("...however, the
  303. * physical device is not currently connected
  304. * to this logical unit") and leave vendor and
  305. * product identification empty. ("If the target
  306. * does store some of the INQUIRY data on the
  307. * device, it may return zeros or ASCII spaces
  308. * (20h) in those fields until the data is
  309. * available from the device.").
  310. */
  311. } else {
  312. u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice);
  313. int n;
  314. n = strlen(us->unusual_dev->vendorName);
  315. memcpy(data+8, us->unusual_dev->vendorName, min(8, n));
  316. n = strlen(us->unusual_dev->productName);
  317. memcpy(data+16, us->unusual_dev->productName, min(16, n));
  318. data[32] = 0x30 + ((bcdDevice>>12) & 0x0F);
  319. data[33] = 0x30 + ((bcdDevice>>8) & 0x0F);
  320. data[34] = 0x30 + ((bcdDevice>>4) & 0x0F);
  321. data[35] = 0x30 + ((bcdDevice) & 0x0F);
  322. }
  323. usb_stor_set_xfer_buf(data, data_len, us->srb);
  324. }
  325. EXPORT_SYMBOL_GPL(fill_inquiry_response);
  326. static int usb_stor_control_thread(void * __us)
  327. {
  328. struct us_data *us = (struct us_data *)__us;
  329. struct Scsi_Host *host = us_to_host(us);
  330. struct scsi_cmnd *srb;
  331. for (;;) {
  332. usb_stor_dbg(us, "*** thread sleeping\n");
  333. if (wait_for_completion_interruptible(&us->cmnd_ready))
  334. break;
  335. usb_stor_dbg(us, "*** thread awakened\n");
  336. /* lock the device pointers */
  337. mutex_lock(&(us->dev_mutex));
  338. /* lock access to the state */
  339. scsi_lock(host);
  340. /* When we are called with no command pending, we're done */
  341. srb = us->srb;
  342. if (srb == NULL) {
  343. scsi_unlock(host);
  344. mutex_unlock(&us->dev_mutex);
  345. usb_stor_dbg(us, "-- exiting\n");
  346. break;
  347. }
  348. /* has the command timed out *already* ? */
  349. if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
  350. srb->result = DID_ABORT << 16;
  351. goto SkipForAbort;
  352. }
  353. scsi_unlock(host);
  354. /*
  355. * reject the command if the direction indicator
  356. * is UNKNOWN
  357. */
  358. if (srb->sc_data_direction == DMA_BIDIRECTIONAL) {
  359. usb_stor_dbg(us, "UNKNOWN data direction\n");
  360. srb->result = DID_ERROR << 16;
  361. }
  362. /*
  363. * reject if target != 0 or if LUN is higher than
  364. * the maximum known LUN
  365. */
  366. else if (srb->device->id &&
  367. !(us->fflags & US_FL_SCM_MULT_TARG)) {
  368. usb_stor_dbg(us, "Bad target number (%d:%llu)\n",
  369. srb->device->id,
  370. srb->device->lun);
  371. srb->result = DID_BAD_TARGET << 16;
  372. }
  373. else if (srb->device->lun > us->max_lun) {
  374. usb_stor_dbg(us, "Bad LUN (%d:%llu)\n",
  375. srb->device->id,
  376. srb->device->lun);
  377. srb->result = DID_BAD_TARGET << 16;
  378. }
  379. /*
  380. * Handle those devices which need us to fake
  381. * their inquiry data
  382. */
  383. else if ((srb->cmnd[0] == INQUIRY) &&
  384. (us->fflags & US_FL_FIX_INQUIRY)) {
  385. unsigned char data_ptr[36] = {
  386. 0x00, 0x80, 0x02, 0x02,
  387. 0x1F, 0x00, 0x00, 0x00};
  388. usb_stor_dbg(us, "Faking INQUIRY command\n");
  389. fill_inquiry_response(us, data_ptr, 36);
  390. srb->result = SAM_STAT_GOOD;
  391. }
  392. /* we've got a command, let's do it! */
  393. else {
  394. US_DEBUG(usb_stor_show_command(us, srb));
  395. us->proto_handler(srb, us);
  396. usb_mark_last_busy(us->pusb_dev);
  397. }
  398. /* lock access to the state */
  399. scsi_lock(host);
  400. /* was the command aborted? */
  401. if (srb->result == DID_ABORT << 16) {
  402. SkipForAbort:
  403. usb_stor_dbg(us, "scsi command aborted\n");
  404. srb = NULL; /* Don't call scsi_done() */
  405. }
  406. /*
  407. * If an abort request was received we need to signal that
  408. * the abort has finished. The proper test for this is
  409. * the TIMED_OUT flag, not srb->result == DID_ABORT, because
  410. * the timeout might have occurred after the command had
  411. * already completed with a different result code.
  412. */
  413. if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
  414. complete(&(us->notify));
  415. /* Allow USB transfers to resume */
  416. clear_bit(US_FLIDX_ABORTING, &us->dflags);
  417. clear_bit(US_FLIDX_TIMED_OUT, &us->dflags);
  418. #ifdef CONFIG_USB_DEBUG_DETAILED_LOG
  419. pr_err("usb_storage: %s clear TIMED_OUT\n", __func__);
  420. #endif
  421. }
  422. /* finished working on this command */
  423. us->srb = NULL;
  424. scsi_unlock(host);
  425. /* unlock the device pointers */
  426. mutex_unlock(&us->dev_mutex);
  427. /* now that the locks are released, notify the SCSI core */
  428. if (srb) {
  429. usb_stor_dbg(us, "scsi cmd done, result=0x%x\n",
  430. srb->result);
  431. scsi_done_direct(srb);
  432. }
  433. } /* for (;;) */
  434. /* Wait until we are told to stop */
  435. for (;;) {
  436. set_current_state(TASK_INTERRUPTIBLE);
  437. if (kthread_should_stop())
  438. break;
  439. schedule();
  440. }
  441. __set_current_state(TASK_RUNNING);
  442. return 0;
  443. }
  444. /***********************************************************************
  445. * Device probing and disconnecting
  446. ***********************************************************************/
  447. /* Associate our private data with the USB device */
  448. static int associate_dev(struct us_data *us, struct usb_interface *intf)
  449. {
  450. /* Fill in the device-related fields */
  451. us->pusb_dev = interface_to_usbdev(intf);
  452. us->pusb_intf = intf;
  453. us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
  454. usb_stor_dbg(us, "Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n",
  455. le16_to_cpu(us->pusb_dev->descriptor.idVendor),
  456. le16_to_cpu(us->pusb_dev->descriptor.idProduct),
  457. le16_to_cpu(us->pusb_dev->descriptor.bcdDevice));
  458. usb_stor_dbg(us, "Interface Subclass: 0x%02x, Protocol: 0x%02x\n",
  459. intf->cur_altsetting->desc.bInterfaceSubClass,
  460. intf->cur_altsetting->desc.bInterfaceProtocol);
  461. /* Store our private data in the interface */
  462. usb_set_intfdata(intf, us);
  463. /* Allocate the control/setup and DMA-mapped buffers */
  464. us->cr = kmalloc(sizeof(*us->cr), GFP_KERNEL);
  465. if (!us->cr)
  466. return -ENOMEM;
  467. us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE,
  468. GFP_KERNEL, &us->iobuf_dma);
  469. if (!us->iobuf) {
  470. usb_stor_dbg(us, "I/O buffer allocation failed\n");
  471. return -ENOMEM;
  472. }
  473. return 0;
  474. }
  475. /* Works only for digits and letters, but small and fast */
  476. #define TOLOWER(x) ((x) | 0x20)
  477. /* Adjust device flags based on the "quirks=" module parameter */
  478. void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags)
  479. {
  480. char *p;
  481. u16 vid = le16_to_cpu(udev->descriptor.idVendor);
  482. u16 pid = le16_to_cpu(udev->descriptor.idProduct);
  483. unsigned f = 0;
  484. unsigned int mask = (US_FL_SANE_SENSE | US_FL_BAD_SENSE |
  485. US_FL_FIX_CAPACITY | US_FL_IGNORE_UAS |
  486. US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE |
  487. US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 |
  488. US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE |
  489. US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT |
  490. US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 |
  491. US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE |
  492. US_FL_NO_ATA_1X | US_FL_NO_REPORT_OPCODES |
  493. US_FL_MAX_SECTORS_240 | US_FL_NO_REPORT_LUNS |
  494. US_FL_ALWAYS_SYNC);
  495. p = quirks;
  496. while (*p) {
  497. /* Each entry consists of VID:PID:flags */
  498. if (vid == simple_strtoul(p, &p, 16) &&
  499. *p == ':' &&
  500. pid == simple_strtoul(p+1, &p, 16) &&
  501. *p == ':')
  502. break;
  503. /* Move forward to the next entry */
  504. while (*p) {
  505. if (*p++ == ',')
  506. break;
  507. }
  508. }
  509. if (!*p) /* No match */
  510. return;
  511. /* Collect the flags */
  512. while (*++p && *p != ',') {
  513. switch (TOLOWER(*p)) {
  514. case 'a':
  515. f |= US_FL_SANE_SENSE;
  516. break;
  517. case 'b':
  518. f |= US_FL_BAD_SENSE;
  519. break;
  520. case 'c':
  521. f |= US_FL_FIX_CAPACITY;
  522. break;
  523. case 'd':
  524. f |= US_FL_NO_READ_DISC_INFO;
  525. break;
  526. case 'e':
  527. f |= US_FL_NO_READ_CAPACITY_16;
  528. break;
  529. case 'f':
  530. f |= US_FL_NO_REPORT_OPCODES;
  531. break;
  532. case 'g':
  533. f |= US_FL_MAX_SECTORS_240;
  534. break;
  535. case 'h':
  536. f |= US_FL_CAPACITY_HEURISTICS;
  537. break;
  538. case 'i':
  539. f |= US_FL_IGNORE_DEVICE;
  540. break;
  541. case 'j':
  542. f |= US_FL_NO_REPORT_LUNS;
  543. break;
  544. case 'k':
  545. f |= US_FL_NO_SAME;
  546. break;
  547. case 'l':
  548. f |= US_FL_NOT_LOCKABLE;
  549. break;
  550. case 'm':
  551. f |= US_FL_MAX_SECTORS_64;
  552. break;
  553. case 'n':
  554. f |= US_FL_INITIAL_READ10;
  555. break;
  556. case 'o':
  557. f |= US_FL_CAPACITY_OK;
  558. break;
  559. case 'p':
  560. f |= US_FL_WRITE_CACHE;
  561. break;
  562. case 'r':
  563. f |= US_FL_IGNORE_RESIDUE;
  564. break;
  565. case 's':
  566. f |= US_FL_SINGLE_LUN;
  567. break;
  568. case 't':
  569. f |= US_FL_NO_ATA_1X;
  570. break;
  571. case 'u':
  572. f |= US_FL_IGNORE_UAS;
  573. break;
  574. case 'w':
  575. f |= US_FL_NO_WP_DETECT;
  576. break;
  577. case 'y':
  578. f |= US_FL_ALWAYS_SYNC;
  579. break;
  580. /* Ignore unrecognized flag characters */
  581. }
  582. }
  583. *fflags = (*fflags & ~mask) | f;
  584. }
  585. EXPORT_SYMBOL_GPL(usb_stor_adjust_quirks);
  586. /* Get the unusual_devs entries and the string descriptors */
  587. static int get_device_info(struct us_data *us, const struct usb_device_id *id,
  588. const struct us_unusual_dev *unusual_dev)
  589. {
  590. struct usb_device *dev = us->pusb_dev;
  591. struct usb_interface_descriptor *idesc =
  592. &us->pusb_intf->cur_altsetting->desc;
  593. struct device *pdev = &us->pusb_intf->dev;
  594. /* Store the entries */
  595. us->unusual_dev = unusual_dev;
  596. us->subclass = (unusual_dev->useProtocol == USB_SC_DEVICE) ?
  597. idesc->bInterfaceSubClass :
  598. unusual_dev->useProtocol;
  599. us->protocol = (unusual_dev->useTransport == USB_PR_DEVICE) ?
  600. idesc->bInterfaceProtocol :
  601. unusual_dev->useTransport;
  602. us->fflags = id->driver_info;
  603. usb_stor_adjust_quirks(us->pusb_dev, &us->fflags);
  604. if (us->fflags & US_FL_IGNORE_DEVICE) {
  605. dev_info(pdev, "device ignored\n");
  606. return -ENODEV;
  607. }
  608. /*
  609. * This flag is only needed when we're in high-speed, so let's
  610. * disable it if we're in full-speed
  611. */
  612. if (dev->speed != USB_SPEED_HIGH)
  613. us->fflags &= ~US_FL_GO_SLOW;
  614. if (us->fflags)
  615. dev_info(pdev, "Quirks match for vid %04x pid %04x: %lx\n",
  616. le16_to_cpu(dev->descriptor.idVendor),
  617. le16_to_cpu(dev->descriptor.idProduct),
  618. us->fflags);
  619. /*
  620. * Log a message if a non-generic unusual_dev entry contains an
  621. * unnecessary subclass or protocol override. This may stimulate
  622. * reports from users that will help us remove unneeded entries
  623. * from the unusual_devs.h table.
  624. */
  625. if (id->idVendor || id->idProduct) {
  626. static const char *msgs[3] = {
  627. "an unneeded SubClass entry",
  628. "an unneeded Protocol entry",
  629. "unneeded SubClass and Protocol entries"};
  630. struct usb_device_descriptor *ddesc = &dev->descriptor;
  631. int msg = -1;
  632. if (unusual_dev->useProtocol != USB_SC_DEVICE &&
  633. us->subclass == idesc->bInterfaceSubClass)
  634. msg += 1;
  635. if (unusual_dev->useTransport != USB_PR_DEVICE &&
  636. us->protocol == idesc->bInterfaceProtocol)
  637. msg += 2;
  638. if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE))
  639. dev_notice(pdev, "This device "
  640. "(%04x,%04x,%04x S %02x P %02x)"
  641. " has %s in unusual_devs.h (kernel"
  642. " %s)\n"
  643. " Please send a copy of this message to "
  644. "<[email protected]> and "
  645. "<[email protected]>\n",
  646. le16_to_cpu(ddesc->idVendor),
  647. le16_to_cpu(ddesc->idProduct),
  648. le16_to_cpu(ddesc->bcdDevice),
  649. idesc->bInterfaceSubClass,
  650. idesc->bInterfaceProtocol,
  651. msgs[msg],
  652. utsname()->release);
  653. }
  654. return 0;
  655. }
  656. /* Get the transport settings */
  657. static void get_transport(struct us_data *us)
  658. {
  659. switch (us->protocol) {
  660. case USB_PR_CB:
  661. us->transport_name = "Control/Bulk";
  662. us->transport = usb_stor_CB_transport;
  663. us->transport_reset = usb_stor_CB_reset;
  664. us->max_lun = 7;
  665. break;
  666. case USB_PR_CBI:
  667. us->transport_name = "Control/Bulk/Interrupt";
  668. us->transport = usb_stor_CB_transport;
  669. us->transport_reset = usb_stor_CB_reset;
  670. us->max_lun = 7;
  671. break;
  672. case USB_PR_BULK:
  673. us->transport_name = "Bulk";
  674. us->transport = usb_stor_Bulk_transport;
  675. us->transport_reset = usb_stor_Bulk_reset;
  676. break;
  677. }
  678. }
  679. /* Get the protocol settings */
  680. static void get_protocol(struct us_data *us)
  681. {
  682. switch (us->subclass) {
  683. case USB_SC_RBC:
  684. us->protocol_name = "Reduced Block Commands (RBC)";
  685. us->proto_handler = usb_stor_transparent_scsi_command;
  686. break;
  687. case USB_SC_8020:
  688. us->protocol_name = "8020i";
  689. us->proto_handler = usb_stor_pad12_command;
  690. us->max_lun = 0;
  691. break;
  692. case USB_SC_QIC:
  693. us->protocol_name = "QIC-157";
  694. us->proto_handler = usb_stor_pad12_command;
  695. us->max_lun = 0;
  696. break;
  697. case USB_SC_8070:
  698. us->protocol_name = "8070i";
  699. us->proto_handler = usb_stor_pad12_command;
  700. us->max_lun = 0;
  701. break;
  702. case USB_SC_SCSI:
  703. us->protocol_name = "Transparent SCSI";
  704. us->proto_handler = usb_stor_transparent_scsi_command;
  705. break;
  706. case USB_SC_UFI:
  707. us->protocol_name = "Uniform Floppy Interface (UFI)";
  708. us->proto_handler = usb_stor_ufi_command;
  709. break;
  710. }
  711. }
  712. /* Get the pipe settings */
  713. static int get_pipes(struct us_data *us)
  714. {
  715. struct usb_host_interface *alt = us->pusb_intf->cur_altsetting;
  716. struct usb_endpoint_descriptor *ep_in;
  717. struct usb_endpoint_descriptor *ep_out;
  718. struct usb_endpoint_descriptor *ep_int;
  719. int res;
  720. /*
  721. * Find the first endpoint of each type we need.
  722. * We are expecting a minimum of 2 endpoints - in and out (bulk).
  723. * An optional interrupt-in is OK (necessary for CBI protocol).
  724. * We will ignore any others.
  725. */
  726. res = usb_find_common_endpoints(alt, &ep_in, &ep_out, NULL, NULL);
  727. if (res) {
  728. usb_stor_dbg(us, "bulk endpoints not found\n");
  729. return res;
  730. }
  731. res = usb_find_int_in_endpoint(alt, &ep_int);
  732. if (res && us->protocol == USB_PR_CBI) {
  733. usb_stor_dbg(us, "interrupt endpoint not found\n");
  734. return res;
  735. }
  736. /* Calculate and store the pipe values */
  737. us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0);
  738. us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0);
  739. us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev,
  740. usb_endpoint_num(ep_out));
  741. us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev,
  742. usb_endpoint_num(ep_in));
  743. if (ep_int) {
  744. us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev,
  745. usb_endpoint_num(ep_int));
  746. us->ep_bInterval = ep_int->bInterval;
  747. }
  748. return 0;
  749. }
  750. /* Initialize all the dynamic resources we need */
  751. static int usb_stor_acquire_resources(struct us_data *us)
  752. {
  753. int p;
  754. struct task_struct *th;
  755. us->current_urb = usb_alloc_urb(0, GFP_KERNEL);
  756. if (!us->current_urb)
  757. return -ENOMEM;
  758. /*
  759. * Just before we start our control thread, initialize
  760. * the device if it needs initialization
  761. */
  762. if (us->unusual_dev->initFunction) {
  763. p = us->unusual_dev->initFunction(us);
  764. if (p)
  765. return p;
  766. }
  767. /* Start up our control thread */
  768. th = kthread_run(usb_stor_control_thread, us, "usb-storage");
  769. if (IS_ERR(th)) {
  770. dev_warn(&us->pusb_intf->dev,
  771. "Unable to start control thread\n");
  772. return PTR_ERR(th);
  773. }
  774. us->ctl_thread = th;
  775. return 0;
  776. }
  777. /* Release all our dynamic resources */
  778. static void usb_stor_release_resources(struct us_data *us)
  779. {
  780. /*
  781. * Tell the control thread to exit. The SCSI host must
  782. * already have been removed and the DISCONNECTING flag set
  783. * so that we won't accept any more commands.
  784. */
  785. usb_stor_dbg(us, "-- sending exit command to thread\n");
  786. complete(&us->cmnd_ready);
  787. if (us->ctl_thread)
  788. kthread_stop(us->ctl_thread);
  789. /* Call the destructor routine, if it exists */
  790. if (us->extra_destructor) {
  791. usb_stor_dbg(us, "-- calling extra_destructor()\n");
  792. us->extra_destructor(us->extra);
  793. }
  794. /* Free the extra data and the URB */
  795. kfree(us->extra);
  796. usb_free_urb(us->current_urb);
  797. }
  798. /* Dissociate from the USB device */
  799. static void dissociate_dev(struct us_data *us)
  800. {
  801. /* Free the buffers */
  802. kfree(us->cr);
  803. usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma);
  804. /* Remove our private data from the interface */
  805. usb_set_intfdata(us->pusb_intf, NULL);
  806. }
  807. /*
  808. * First stage of disconnect processing: stop SCSI scanning,
  809. * remove the host, and stop accepting new commands
  810. */
  811. static void quiesce_and_remove_host(struct us_data *us)
  812. {
  813. struct Scsi_Host *host = us_to_host(us);
  814. /* If the device is really gone, cut short reset delays */
  815. if (us->pusb_dev->state == USB_STATE_NOTATTACHED) {
  816. set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
  817. wake_up(&us->delay_wait);
  818. }
  819. /*
  820. * Prevent SCSI scanning (if it hasn't started yet)
  821. * or wait for the SCSI-scanning routine to stop.
  822. */
  823. cancel_delayed_work_sync(&us->scan_dwork);
  824. /* Balance autopm calls if scanning was cancelled */
  825. if (test_bit(US_FLIDX_SCAN_PENDING, &us->dflags))
  826. usb_autopm_put_interface_no_suspend(us->pusb_intf);
  827. /*
  828. * Removing the host will perform an orderly shutdown: caches
  829. * synchronized, disks spun down, etc.
  830. */
  831. scsi_remove_host(host);
  832. /*
  833. * Prevent any new commands from being accepted and cut short
  834. * reset delays.
  835. */
  836. scsi_lock(host);
  837. set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
  838. scsi_unlock(host);
  839. wake_up(&us->delay_wait);
  840. }
  841. /* Second stage of disconnect processing: deallocate all resources */
  842. static void release_everything(struct us_data *us)
  843. {
  844. usb_stor_release_resources(us);
  845. dissociate_dev(us);
  846. /*
  847. * Drop our reference to the host; the SCSI core will free it
  848. * (and "us" along with it) when the refcount becomes 0.
  849. */
  850. scsi_host_put(us_to_host(us));
  851. }
  852. /* Delayed-work routine to carry out SCSI-device scanning */
  853. static void usb_stor_scan_dwork(struct work_struct *work)
  854. {
  855. struct us_data *us = container_of(work, struct us_data,
  856. scan_dwork.work);
  857. struct device *dev = &us->pusb_intf->dev;
  858. dev_dbg(dev, "starting scan\n");
  859. /* For bulk-only devices, determine the max LUN value */
  860. if (us->protocol == USB_PR_BULK &&
  861. !(us->fflags & US_FL_SINGLE_LUN) &&
  862. !(us->fflags & US_FL_SCM_MULT_TARG)) {
  863. mutex_lock(&us->dev_mutex);
  864. us->max_lun = usb_stor_Bulk_max_lun(us);
  865. /*
  866. * Allow proper scanning of devices that present more than 8 LUNs
  867. * While not affecting other devices that may need the previous
  868. * behavior
  869. */
  870. if (us->max_lun >= 8)
  871. us_to_host(us)->max_lun = us->max_lun+1;
  872. mutex_unlock(&us->dev_mutex);
  873. }
  874. scsi_scan_host(us_to_host(us));
  875. dev_dbg(dev, "scan complete\n");
  876. /* Should we unbind if no devices were detected? */
  877. usb_autopm_put_interface(us->pusb_intf);
  878. clear_bit(US_FLIDX_SCAN_PENDING, &us->dflags);
  879. }
  880. static unsigned int usb_stor_sg_tablesize(struct usb_interface *intf)
  881. {
  882. struct usb_device *usb_dev = interface_to_usbdev(intf);
  883. if (usb_dev->bus->sg_tablesize) {
  884. return usb_dev->bus->sg_tablesize;
  885. }
  886. return SG_ALL;
  887. }
  888. /* First part of general USB mass-storage probing */
  889. int usb_stor_probe1(struct us_data **pus,
  890. struct usb_interface *intf,
  891. const struct usb_device_id *id,
  892. const struct us_unusual_dev *unusual_dev,
  893. struct scsi_host_template *sht)
  894. {
  895. struct Scsi_Host *host;
  896. struct us_data *us;
  897. int result;
  898. dev_info(&intf->dev, "USB Mass Storage device detected\n");
  899. /*
  900. * Ask the SCSI layer to allocate a host structure, with extra
  901. * space at the end for our private us_data structure.
  902. */
  903. host = scsi_host_alloc(sht, sizeof(*us));
  904. if (!host) {
  905. dev_warn(&intf->dev, "Unable to allocate the scsi host\n");
  906. return -ENOMEM;
  907. }
  908. /*
  909. * Allow 16-byte CDBs and thus > 2TB
  910. */
  911. host->max_cmd_len = 16;
  912. host->sg_tablesize = usb_stor_sg_tablesize(intf);
  913. *pus = us = host_to_us(host);
  914. mutex_init(&(us->dev_mutex));
  915. us_set_lock_class(&us->dev_mutex, intf);
  916. init_completion(&us->cmnd_ready);
  917. init_completion(&(us->notify));
  918. init_waitqueue_head(&us->delay_wait);
  919. INIT_DELAYED_WORK(&us->scan_dwork, usb_stor_scan_dwork);
  920. /* Associate the us_data structure with the USB device */
  921. result = associate_dev(us, intf);
  922. if (result)
  923. goto BadDevice;
  924. /* Get the unusual_devs entries and the descriptors */
  925. result = get_device_info(us, id, unusual_dev);
  926. if (result)
  927. goto BadDevice;
  928. /* Get standard transport and protocol settings */
  929. get_transport(us);
  930. get_protocol(us);
  931. /*
  932. * Give the caller a chance to fill in specialized transport
  933. * or protocol settings.
  934. */
  935. return 0;
  936. BadDevice:
  937. usb_stor_dbg(us, "storage_probe() failed\n");
  938. release_everything(us);
  939. return result;
  940. }
  941. EXPORT_SYMBOL_GPL(usb_stor_probe1);
  942. /* Second part of general USB mass-storage probing */
  943. int usb_stor_probe2(struct us_data *us)
  944. {
  945. int result;
  946. struct device *dev = &us->pusb_intf->dev;
  947. /* Make sure the transport and protocol have both been set */
  948. if (!us->transport || !us->proto_handler) {
  949. result = -ENXIO;
  950. goto BadDevice;
  951. }
  952. usb_stor_dbg(us, "Transport: %s\n", us->transport_name);
  953. usb_stor_dbg(us, "Protocol: %s\n", us->protocol_name);
  954. if (us->fflags & US_FL_SCM_MULT_TARG) {
  955. /*
  956. * SCM eUSCSI bridge devices can have different numbers
  957. * of LUNs on different targets; allow all to be probed.
  958. */
  959. us->max_lun = 7;
  960. /* The eUSCSI itself has ID 7, so avoid scanning that */
  961. us_to_host(us)->this_id = 7;
  962. /* max_id is 8 initially, so no need to set it here */
  963. } else {
  964. /* In the normal case there is only a single target */
  965. us_to_host(us)->max_id = 1;
  966. /*
  967. * Like Windows, we won't store the LUN bits in CDB[1] for
  968. * SCSI-2 devices using the Bulk-Only transport (even though
  969. * this violates the SCSI spec).
  970. */
  971. if (us->transport == usb_stor_Bulk_transport)
  972. us_to_host(us)->no_scsi2_lun_in_cdb = 1;
  973. }
  974. /* fix for single-lun devices */
  975. if (us->fflags & US_FL_SINGLE_LUN)
  976. us->max_lun = 0;
  977. /* Find the endpoints and calculate pipe values */
  978. result = get_pipes(us);
  979. if (result)
  980. goto BadDevice;
  981. /*
  982. * If the device returns invalid data for the first READ(10)
  983. * command, indicate the command should be retried.
  984. */
  985. if (us->fflags & US_FL_INITIAL_READ10)
  986. set_bit(US_FLIDX_REDO_READ10, &us->dflags);
  987. /* Acquire all the other resources and add the host */
  988. result = usb_stor_acquire_resources(us);
  989. if (result)
  990. goto BadDevice;
  991. usb_autopm_get_interface_no_resume(us->pusb_intf);
  992. snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s",
  993. dev_name(&us->pusb_intf->dev));
  994. result = scsi_add_host(us_to_host(us), dev);
  995. if (result) {
  996. dev_warn(dev,
  997. "Unable to add the scsi host\n");
  998. goto HostAddErr;
  999. }
  1000. /* Submit the delayed_work for SCSI-device scanning */
  1001. set_bit(US_FLIDX_SCAN_PENDING, &us->dflags);
  1002. if (delay_use > 0)
  1003. dev_dbg(dev, "waiting for device to settle before scanning\n");
  1004. queue_delayed_work(system_freezable_wq, &us->scan_dwork,
  1005. delay_use * HZ);
  1006. return 0;
  1007. /* We come here if there are any problems */
  1008. HostAddErr:
  1009. usb_autopm_put_interface_no_suspend(us->pusb_intf);
  1010. BadDevice:
  1011. usb_stor_dbg(us, "storage_probe() failed\n");
  1012. release_everything(us);
  1013. return result;
  1014. }
  1015. EXPORT_SYMBOL_GPL(usb_stor_probe2);
  1016. /* Handle a USB mass-storage disconnect */
  1017. void usb_stor_disconnect(struct usb_interface *intf)
  1018. {
  1019. struct us_data *us = usb_get_intfdata(intf);
  1020. #ifdef CONFIG_USB_DEBUG_DETAILED_LOG
  1021. pr_info("%s enter\n", __func__);
  1022. #endif
  1023. quiesce_and_remove_host(us);
  1024. #ifdef CONFIG_USB_DEBUG_DETAILED_LOG
  1025. pr_info("%s doing\n", __func__);
  1026. #endif
  1027. release_everything(us);
  1028. #ifdef CONFIG_USB_DEBUG_DETAILED_LOG
  1029. pr_info("%s exit\n", __func__);
  1030. #endif
  1031. }
  1032. EXPORT_SYMBOL_GPL(usb_stor_disconnect);
  1033. static struct scsi_host_template usb_stor_host_template;
  1034. /* The main probe routine for standard devices */
  1035. static int storage_probe(struct usb_interface *intf,
  1036. const struct usb_device_id *id)
  1037. {
  1038. const struct us_unusual_dev *unusual_dev;
  1039. struct us_data *us;
  1040. int result;
  1041. int size;
  1042. /* If uas is enabled and this device can do uas then ignore it. */
  1043. #if IS_ENABLED(CONFIG_USB_UAS)
  1044. if (uas_use_uas_driver(intf, id, NULL))
  1045. return -ENXIO;
  1046. #endif
  1047. /*
  1048. * If the device isn't standard (is handled by a subdriver
  1049. * module) then don't accept it.
  1050. */
  1051. if (usb_usual_ignore_device(intf))
  1052. return -ENXIO;
  1053. /*
  1054. * Call the general probe procedures.
  1055. *
  1056. * The unusual_dev_list array is parallel to the usb_storage_usb_ids
  1057. * table, so we use the index of the id entry to find the
  1058. * corresponding unusual_devs entry.
  1059. */
  1060. size = ARRAY_SIZE(us_unusual_dev_list);
  1061. if (id >= usb_storage_usb_ids && id < usb_storage_usb_ids + size) {
  1062. unusual_dev = (id - usb_storage_usb_ids) + us_unusual_dev_list;
  1063. } else {
  1064. unusual_dev = &for_dynamic_ids;
  1065. dev_dbg(&intf->dev, "Use Bulk-Only transport with the Transparent SCSI protocol for dynamic id: 0x%04x 0x%04x\n",
  1066. id->idVendor, id->idProduct);
  1067. }
  1068. result = usb_stor_probe1(&us, intf, id, unusual_dev,
  1069. &usb_stor_host_template);
  1070. if (result)
  1071. return result;
  1072. /* No special transport or protocol settings in the main module */
  1073. result = usb_stor_probe2(us);
  1074. return result;
  1075. }
  1076. static struct usb_driver usb_storage_driver = {
  1077. .name = DRV_NAME,
  1078. .probe = storage_probe,
  1079. .disconnect = usb_stor_disconnect,
  1080. .suspend = usb_stor_suspend,
  1081. .resume = usb_stor_resume,
  1082. .reset_resume = usb_stor_reset_resume,
  1083. .pre_reset = usb_stor_pre_reset,
  1084. .post_reset = usb_stor_post_reset,
  1085. .id_table = usb_storage_usb_ids,
  1086. .supports_autosuspend = 1,
  1087. .soft_unbind = 1,
  1088. };
  1089. module_usb_stor_driver(usb_storage_driver, usb_stor_host_template, DRV_NAME);