scsiglue.c 20 KB

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