scsiglue.c 21 KB

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