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