scsiglue.c 20 KB

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