scsiglue.c 20 KB

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