scsiglue.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Driver for USB Mass Storage compliant devices
  4. * SCSI layer glue code
  5. *
  6. * Current development and maintenance by:
  7. * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
  8. *
  9. * Developed with the assistance of:
  10. * (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org)
  11. * (c) 2000 Stephen J. Gowdy (SGowdy@lbl.gov)
  12. *
  13. * Initial work by:
  14. * (c) 1999 Michael Gee (michael@linuxspecific.com)
  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. #include <linux/module.h>
  34. #include <linux/mutex.h>
  35. #include <scsi/scsi.h>
  36. #include <scsi/scsi_cmnd.h>
  37. #include <scsi/scsi_devinfo.h>
  38. #include <scsi/scsi_device.h>
  39. #include <scsi/scsi_eh.h>
  40. #include "usb.h"
  41. #include "scsiglue.h"
  42. #include "debug.h"
  43. #include "transport.h"
  44. #include "protocol.h"
  45. /*
  46. * Vendor IDs for companies that seem to include the READ CAPACITY bug
  47. * in all their devices
  48. */
  49. #define VENDOR_ID_NOKIA 0x0421
  50. #define VENDOR_ID_NIKON 0x04b0
  51. #define VENDOR_ID_PENTAX 0x0a17
  52. #define VENDOR_ID_MOTOROLA 0x22b8
  53. /***********************************************************************
  54. * Host functions
  55. ***********************************************************************/
  56. static const char* host_info(struct Scsi_Host *host)
  57. {
  58. struct us_data *us = host_to_us(host);
  59. return us->scsi_name;
  60. }
  61. static int slave_alloc (struct scsi_device *sdev)
  62. {
  63. struct us_data *us = host_to_us(sdev->host);
  64. /*
  65. * Set the INQUIRY transfer length to 36. We don't use any of
  66. * the extra data and many devices choke if asked for more or
  67. * less than 36 bytes.
  68. */
  69. sdev->inquiry_len = 36;
  70. /*
  71. * USB has unusual DMA-alignment requirements: Although the
  72. * starting address of each scatter-gather element doesn't matter,
  73. * the length of each element except the last must be divisible
  74. * by the Bulk maxpacket value. There's currently no way to
  75. * express this by block-layer constraints, so we'll cop out
  76. * and simply require addresses to be aligned at 512-byte
  77. * boundaries. This is okay since most block I/O involves
  78. * hardware sectors that are multiples of 512 bytes in length,
  79. * and since host controllers up through USB 2.0 have maxpacket
  80. * values no larger than 512.
  81. *
  82. * But it doesn't suffice for Wireless USB, where Bulk maxpacket
  83. * values can be as large as 2048. To make that work properly
  84. * will require changes to the block layer.
  85. */
  86. blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
  87. /* Tell the SCSI layer if we know there is more than one LUN */
  88. if (us->protocol == USB_PR_BULK && us->max_lun > 0)
  89. sdev->sdev_bflags |= BLIST_FORCELUN;
  90. return 0;
  91. }
  92. static int slave_configure(struct scsi_device *sdev)
  93. {
  94. struct us_data *us = host_to_us(sdev->host);
  95. /*
  96. * Many devices have trouble transferring more than 32KB at a time,
  97. * while others have trouble with more than 64K. At this time we
  98. * are limiting both to 32K (64 sectores).
  99. */
  100. if (us->fflags & (US_FL_MAX_SECTORS_64 | US_FL_MAX_SECTORS_MIN)) {
  101. unsigned int max_sectors = 64;
  102. if (us->fflags & US_FL_MAX_SECTORS_MIN)
  103. max_sectors = PAGE_SIZE >> 9;
  104. if (queue_max_hw_sectors(sdev->request_queue) > max_sectors)
  105. blk_queue_max_hw_sectors(sdev->request_queue,
  106. max_sectors);
  107. } else if (sdev->type == TYPE_TAPE) {
  108. /*
  109. * Tapes need much higher max_sector limits, so just
  110. * raise it to the maximum possible (4 GB / 512) and
  111. * let the queue segment size sort out the real limit.
  112. */
  113. blk_queue_max_hw_sectors(sdev->request_queue, 0x7FFFFF);
  114. } else if (us->pusb_dev->speed >= USB_SPEED_SUPER) {
  115. /*
  116. * USB3 devices will be limited to 2048 sectors. This gives us
  117. * better throughput on most devices.
  118. */
  119. blk_queue_max_hw_sectors(sdev->request_queue, 2048);
  120. }
  121. /*
  122. * Some USB host controllers can't do DMA; they have to use PIO.
  123. * They indicate this by setting their dma_mask to NULL. For
  124. * such controllers we need to make sure the block layer sets
  125. * up bounce buffers in addressable memory.
  126. */
  127. if (!us->pusb_dev->bus->controller->dma_mask)
  128. blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_HIGH);
  129. /*
  130. * We can't put these settings in slave_alloc() because that gets
  131. * called before the device type is known. Consequently these
  132. * settings can't be overridden via the scsi devinfo mechanism.
  133. */
  134. if (sdev->type == TYPE_DISK) {
  135. /*
  136. * Some vendors seem to put the READ CAPACITY bug into
  137. * all their devices -- primarily makers of cell phones
  138. * and digital cameras. Since these devices always use
  139. * flash media and can be expected to have an even number
  140. * of sectors, we will always enable the CAPACITY_HEURISTICS
  141. * flag unless told otherwise.
  142. */
  143. switch (le16_to_cpu(us->pusb_dev->descriptor.idVendor)) {
  144. case VENDOR_ID_NOKIA:
  145. case VENDOR_ID_NIKON:
  146. case VENDOR_ID_PENTAX:
  147. case VENDOR_ID_MOTOROLA:
  148. if (!(us->fflags & (US_FL_FIX_CAPACITY |
  149. US_FL_CAPACITY_OK)))
  150. us->fflags |= US_FL_CAPACITY_HEURISTICS;
  151. break;
  152. }
  153. /*
  154. * Disk-type devices use MODE SENSE(6) if the protocol
  155. * (SubClass) is Transparent SCSI, otherwise they use
  156. * MODE SENSE(10).
  157. */
  158. if (us->subclass != USB_SC_SCSI && us->subclass != USB_SC_CYP_ATACB)
  159. sdev->use_10_for_ms = 1;
  160. /*
  161. *Many disks only accept MODE SENSE transfer lengths of
  162. * 192 bytes (that's what Windows uses).
  163. */
  164. sdev->use_192_bytes_for_3f = 1;
  165. /*
  166. * Some devices don't like MODE SENSE with page=0x3f,
  167. * which is the command used for checking if a device
  168. * is write-protected. Now that we tell the sd driver
  169. * to do a 192-byte transfer with this command the
  170. * majority of devices work fine, but a few still can't
  171. * handle it. The sd driver will simply assume those
  172. * devices are write-enabled.
  173. */
  174. if (us->fflags & US_FL_NO_WP_DETECT)
  175. sdev->skip_ms_page_3f = 1;
  176. /*
  177. * A number of devices have problems with MODE SENSE for
  178. * page x08, so we will skip it.
  179. */
  180. sdev->skip_ms_page_8 = 1;
  181. /* Some devices don't handle VPD pages correctly */
  182. sdev->skip_vpd_pages = 1;
  183. /* Do not attempt to use REPORT SUPPORTED OPERATION CODES */
  184. sdev->no_report_opcodes = 1;
  185. /* Do not attempt to use WRITE SAME */
  186. sdev->no_write_same = 1;
  187. /*
  188. * Some disks return the total number of blocks in response
  189. * to READ CAPACITY rather than the highest block number.
  190. * If this device makes that mistake, tell the sd driver.
  191. */
  192. if (us->fflags & US_FL_FIX_CAPACITY)
  193. sdev->fix_capacity = 1;
  194. /*
  195. * A few disks have two indistinguishable version, one of
  196. * which reports the correct capacity and the other does not.
  197. * The sd driver has to guess which is the case.
  198. */
  199. if (us->fflags & US_FL_CAPACITY_HEURISTICS)
  200. sdev->guess_capacity = 1;
  201. /* Some devices cannot handle READ_CAPACITY_16 */
  202. if (us->fflags & US_FL_NO_READ_CAPACITY_16)
  203. sdev->no_read_capacity_16 = 1;
  204. /*
  205. * Many devices do not respond properly to READ_CAPACITY_16.
  206. * Tell the SCSI layer to try READ_CAPACITY_10 first.
  207. * However some USB 3.0 drive enclosures return capacity
  208. * modulo 2TB. Those must use READ_CAPACITY_16
  209. */
  210. if (!(us->fflags & US_FL_NEEDS_CAP16))
  211. sdev->try_rc_10_first = 1;
  212. /* assume SPC3 or latter devices support sense size > 18 */
  213. if (sdev->scsi_level > SCSI_SPC_2)
  214. us->fflags |= US_FL_SANE_SENSE;
  215. /*
  216. * USB-IDE bridges tend to report SK = 0x04 (Non-recoverable
  217. * Hardware Error) when any low-level error occurs,
  218. * recoverable or not. Setting this flag tells the SCSI
  219. * midlayer to retry such commands, which frequently will
  220. * succeed and fix the error. The worst this can lead to
  221. * is an occasional series of retries that will all fail.
  222. */
  223. sdev->retry_hwerror = 1;
  224. /*
  225. * USB disks should allow restart. Some drives spin down
  226. * automatically, requiring a START-STOP UNIT command.
  227. */
  228. sdev->allow_restart = 1;
  229. /*
  230. * Some USB cardreaders have trouble reading an sdcard's last
  231. * sector in a larger then 1 sector read, since the performance
  232. * impact is negligible we set this flag for all USB disks
  233. */
  234. sdev->last_sector_bug = 1;
  235. /*
  236. * Enable last-sector hacks for single-target devices using
  237. * the Bulk-only transport, unless we already know the
  238. * capacity will be decremented or is correct.
  239. */
  240. if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK |
  241. US_FL_SCM_MULT_TARG)) &&
  242. us->protocol == USB_PR_BULK)
  243. us->use_last_sector_hacks = 1;
  244. /* Check if write cache default on flag is set or not */
  245. if (us->fflags & US_FL_WRITE_CACHE)
  246. sdev->wce_default_on = 1;
  247. /* A few buggy USB-ATA bridges don't understand FUA */
  248. if (us->fflags & US_FL_BROKEN_FUA)
  249. sdev->broken_fua = 1;
  250. /* Some even totally fail to indicate a cache */
  251. if (us->fflags & US_FL_ALWAYS_SYNC) {
  252. /* don't read caching information */
  253. sdev->skip_ms_page_8 = 1;
  254. sdev->skip_ms_page_3f = 1;
  255. /* assume sync is needed */
  256. sdev->wce_default_on = 1;
  257. }
  258. } else {
  259. /*
  260. * Non-disk-type devices don't need to blacklist any pages
  261. * or to force 192-byte transfer lengths for MODE SENSE.
  262. * But they do need to use MODE SENSE(10).
  263. */
  264. sdev->use_10_for_ms = 1;
  265. /* Some (fake) usb cdrom devices don't like READ_DISC_INFO */
  266. if (us->fflags & US_FL_NO_READ_DISC_INFO)
  267. sdev->no_read_disc_info = 1;
  268. }
  269. /*
  270. * The CB and CBI transports have no way to pass LUN values
  271. * other than the bits in the second byte of a CDB. But those
  272. * bits don't get set to the LUN value if the device reports
  273. * scsi_level == 0 (UNKNOWN). Hence such devices must necessarily
  274. * be single-LUN.
  275. */
  276. if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_CBI) &&
  277. sdev->scsi_level == SCSI_UNKNOWN)
  278. us->max_lun = 0;
  279. /*
  280. * Some devices choke when they receive a PREVENT-ALLOW MEDIUM
  281. * REMOVAL command, so suppress those commands.
  282. */
  283. if (us->fflags & US_FL_NOT_LOCKABLE)
  284. sdev->lockable = 0;
  285. /*
  286. * this is to satisfy the compiler, tho I don't think the
  287. * return code is ever checked anywhere.
  288. */
  289. return 0;
  290. }
  291. static int target_alloc(struct scsi_target *starget)
  292. {
  293. struct us_data *us = host_to_us(dev_to_shost(starget->dev.parent));
  294. /*
  295. * Some USB drives don't support REPORT LUNS, even though they
  296. * report a SCSI revision level above 2. Tell the SCSI layer
  297. * not to issue that command; it will perform a normal sequential
  298. * scan instead.
  299. */
  300. starget->no_report_luns = 1;
  301. /*
  302. * The UFI spec treats the Peripheral Qualifier bits in an
  303. * INQUIRY result as reserved and requires devices to set them
  304. * to 0. However the SCSI spec requires these bits to be set
  305. * to 3 to indicate when a LUN is not present.
  306. *
  307. * Let the scanning code know if this target merely sets
  308. * Peripheral Device Type to 0x1f to indicate no LUN.
  309. */
  310. if (us->subclass == USB_SC_UFI)
  311. starget->pdt_1f_for_no_lun = 1;
  312. return 0;
  313. }
  314. /* queue a command */
  315. /* This is always called with scsi_lock(host) held */
  316. static int queuecommand_lck(struct scsi_cmnd *srb,
  317. void (*done)(struct scsi_cmnd *))
  318. {
  319. struct us_data *us = host_to_us(srb->device->host);
  320. /* check for state-transition errors */
  321. if (us->srb != NULL) {
  322. printk(KERN_ERR USB_STORAGE "Error in %s: us->srb = %p\n",
  323. __func__, us->srb);
  324. return SCSI_MLQUEUE_HOST_BUSY;
  325. }
  326. /* fail the command if we are disconnecting */
  327. if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
  328. usb_stor_dbg(us, "Fail command during disconnect\n");
  329. srb->result = DID_NO_CONNECT << 16;
  330. done(srb);
  331. return 0;
  332. }
  333. /* enqueue the command and wake up the control thread */
  334. srb->scsi_done = done;
  335. us->srb = srb;
  336. complete(&us->cmnd_ready);
  337. return 0;
  338. }
  339. static DEF_SCSI_QCMD(queuecommand)
  340. /***********************************************************************
  341. * Error handling functions
  342. ***********************************************************************/
  343. /* Command timeout and abort */
  344. static int command_abort(struct scsi_cmnd *srb)
  345. {
  346. struct us_data *us = host_to_us(srb->device->host);
  347. usb_stor_dbg(us, "%s called\n", __func__);
  348. /*
  349. * us->srb together with the TIMED_OUT, RESETTING, and ABORTING
  350. * bits are protected by the host lock.
  351. */
  352. scsi_lock(us_to_host(us));
  353. /* Is this command still active? */
  354. if (us->srb != srb) {
  355. scsi_unlock(us_to_host(us));
  356. usb_stor_dbg(us, "-- nothing to abort\n");
  357. return FAILED;
  358. }
  359. /*
  360. * Set the TIMED_OUT bit. Also set the ABORTING bit, but only if
  361. * a device reset isn't already in progress (to avoid interfering
  362. * with the reset). Note that we must retain the host lock while
  363. * calling usb_stor_stop_transport(); otherwise it might interfere
  364. * with an auto-reset that begins as soon as we release the lock.
  365. */
  366. set_bit(US_FLIDX_TIMED_OUT, &us->dflags);
  367. if (!test_bit(US_FLIDX_RESETTING, &us->dflags)) {
  368. set_bit(US_FLIDX_ABORTING, &us->dflags);
  369. usb_stor_stop_transport(us);
  370. }
  371. scsi_unlock(us_to_host(us));
  372. /* Wait for the aborted command to finish */
  373. wait_for_completion(&us->notify);
  374. return SUCCESS;
  375. }
  376. /*
  377. * This invokes the transport reset mechanism to reset the state of the
  378. * device
  379. */
  380. static int device_reset(struct scsi_cmnd *srb)
  381. {
  382. struct us_data *us = host_to_us(srb->device->host);
  383. int result;
  384. usb_stor_dbg(us, "%s called\n", __func__);
  385. /* lock the device pointers and do the reset */
  386. mutex_lock(&(us->dev_mutex));
  387. result = us->transport_reset(us);
  388. mutex_unlock(&us->dev_mutex);
  389. return result < 0 ? FAILED : SUCCESS;
  390. }
  391. /* Simulate a SCSI bus reset by resetting the device's USB port. */
  392. static int bus_reset(struct scsi_cmnd *srb)
  393. {
  394. struct us_data *us = host_to_us(srb->device->host);
  395. int result;
  396. usb_stor_dbg(us, "%s called\n", __func__);
  397. result = usb_stor_port_reset(us);
  398. return result < 0 ? FAILED : SUCCESS;
  399. }
  400. /*
  401. * Report a driver-initiated device reset to the SCSI layer.
  402. * Calling this for a SCSI-initiated reset is unnecessary but harmless.
  403. * The caller must own the SCSI host lock.
  404. */
  405. void usb_stor_report_device_reset(struct us_data *us)
  406. {
  407. int i;
  408. struct Scsi_Host *host = us_to_host(us);
  409. scsi_report_device_reset(host, 0, 0);
  410. if (us->fflags & US_FL_SCM_MULT_TARG) {
  411. for (i = 1; i < host->max_id; ++i)
  412. scsi_report_device_reset(host, 0, i);
  413. }
  414. }
  415. /*
  416. * Report a driver-initiated bus reset to the SCSI layer.
  417. * Calling this for a SCSI-initiated reset is unnecessary but harmless.
  418. * The caller must not own the SCSI host lock.
  419. */
  420. void usb_stor_report_bus_reset(struct us_data *us)
  421. {
  422. struct Scsi_Host *host = us_to_host(us);
  423. scsi_lock(host);
  424. scsi_report_bus_reset(host, 0);
  425. scsi_unlock(host);
  426. }
  427. /***********************************************************************
  428. * /proc/scsi/ functions
  429. ***********************************************************************/
  430. static int write_info(struct Scsi_Host *host, char *buffer, int length)
  431. {
  432. /* if someone is sending us data, just throw it away */
  433. return length;
  434. }
  435. static int show_info (struct seq_file *m, struct Scsi_Host *host)
  436. {
  437. struct us_data *us = host_to_us(host);
  438. const char *string;
  439. /* print the controller name */
  440. seq_printf(m, " Host scsi%d: usb-storage\n", host->host_no);
  441. /* print product, vendor, and serial number strings */
  442. if (us->pusb_dev->manufacturer)
  443. string = us->pusb_dev->manufacturer;
  444. else if (us->unusual_dev->vendorName)
  445. string = us->unusual_dev->vendorName;
  446. else
  447. string = "Unknown";
  448. seq_printf(m, " Vendor: %s\n", string);
  449. if (us->pusb_dev->product)
  450. string = us->pusb_dev->product;
  451. else if (us->unusual_dev->productName)
  452. string = us->unusual_dev->productName;
  453. else
  454. string = "Unknown";
  455. seq_printf(m, " Product: %s\n", string);
  456. if (us->pusb_dev->serial)
  457. string = us->pusb_dev->serial;
  458. else
  459. string = "None";
  460. seq_printf(m, "Serial Number: %s\n", string);
  461. /* show the protocol and transport */
  462. seq_printf(m, " Protocol: %s\n", us->protocol_name);
  463. seq_printf(m, " Transport: %s\n", us->transport_name);
  464. /* show the device flags */
  465. seq_printf(m, " Quirks:");
  466. #define US_FLAG(name, value) \
  467. if (us->fflags & value) seq_printf(m, " " #name);
  468. US_DO_ALL_FLAGS
  469. #undef US_FLAG
  470. seq_putc(m, '\n');
  471. return 0;
  472. }
  473. /***********************************************************************
  474. * Sysfs interface
  475. ***********************************************************************/
  476. /* Output routine for the sysfs max_sectors file */
  477. static ssize_t max_sectors_show(struct device *dev, struct device_attribute *attr, char *buf)
  478. {
  479. struct scsi_device *sdev = to_scsi_device(dev);
  480. return sprintf(buf, "%u\n", queue_max_hw_sectors(sdev->request_queue));
  481. }
  482. /* Input routine for the sysfs max_sectors file */
  483. static ssize_t max_sectors_store(struct device *dev, struct device_attribute *attr, const char *buf,
  484. size_t count)
  485. {
  486. struct scsi_device *sdev = to_scsi_device(dev);
  487. unsigned short ms;
  488. if (sscanf(buf, "%hu", &ms) > 0) {
  489. blk_queue_max_hw_sectors(sdev->request_queue, ms);
  490. return count;
  491. }
  492. return -EINVAL;
  493. }
  494. static DEVICE_ATTR_RW(max_sectors);
  495. static struct device_attribute *sysfs_device_attr_list[] = {
  496. &dev_attr_max_sectors,
  497. NULL,
  498. };
  499. /*
  500. * this defines our host template, with which we'll allocate hosts
  501. */
  502. static const struct scsi_host_template usb_stor_host_template = {
  503. /* basic userland interface stuff */
  504. .name = "usb-storage",
  505. .proc_name = "usb-storage",
  506. .show_info = show_info,
  507. .write_info = write_info,
  508. .info = host_info,
  509. /* command interface -- queued only */
  510. .queuecommand = queuecommand,
  511. /* error and abort handlers */
  512. .eh_abort_handler = command_abort,
  513. .eh_device_reset_handler = device_reset,
  514. .eh_bus_reset_handler = bus_reset,
  515. /* queue commands only, only one command per LUN */
  516. .can_queue = 1,
  517. /* unknown initiator id */
  518. .this_id = -1,
  519. .slave_alloc = slave_alloc,
  520. .slave_configure = slave_configure,
  521. .target_alloc = target_alloc,
  522. /* lots of sg segments can be handled */
  523. .sg_tablesize = SG_MAX_SEGMENTS,
  524. /*
  525. * Limit the total size of a transfer to 120 KB.
  526. *
  527. * Some devices are known to choke with anything larger. It seems like
  528. * the problem stems from the fact that original IDE controllers had
  529. * only an 8-bit register to hold the number of sectors in one transfer
  530. * and even those couldn't handle a full 256 sectors.
  531. *
  532. * Because we want to make sure we interoperate with as many devices as
  533. * possible, we will maintain a 240 sector transfer size limit for USB
  534. * Mass Storage devices.
  535. *
  536. * Tests show that other operating have similar limits with Microsoft
  537. * Windows 7 limiting transfers to 128 sectors for both USB2 and USB3
  538. * and Apple Mac OS X 10.11 limiting transfers to 256 sectors for USB2
  539. * and 2048 for USB3 devices.
  540. */
  541. .max_sectors = 240,
  542. /*
  543. * merge commands... this seems to help performance, but
  544. * periodically someone should test to see which setting is more
  545. * optimal.
  546. */
  547. .use_clustering = 1,
  548. /* emulated HBA */
  549. .emulated = 1,
  550. /* we do our own delay after a device or bus reset */
  551. .skip_settle_delay = 1,
  552. /* sysfs device attributes */
  553. .sdev_attrs = sysfs_device_attr_list,
  554. /* module management */
  555. .module = THIS_MODULE
  556. };
  557. void usb_stor_host_template_init(struct scsi_host_template *sht,
  558. const char *name, struct module *owner)
  559. {
  560. *sht = usb_stor_host_template;
  561. sht->name = name;
  562. sht->proc_name = name;
  563. sht->module = owner;
  564. }
  565. EXPORT_SYMBOL_GPL(usb_stor_host_template_init);
  566. /* To Report "Illegal Request: Invalid Field in CDB */
  567. unsigned char usb_stor_sense_invalidCDB[18] = {
  568. [0] = 0x70, /* current error */
  569. [2] = ILLEGAL_REQUEST, /* Illegal Request = 0x05 */
  570. [7] = 0x0a, /* additional length */
  571. [12] = 0x24 /* Invalid Field in CDB */
  572. };
  573. EXPORT_SYMBOL_GPL(usb_stor_sense_invalidCDB);