Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Driver for USB Mass Storage compliant devices
0004  * SCSI layer glue code
0005  *
0006  * Current development and maintenance by:
0007  *   (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
0008  *
0009  * Developed with the assistance of:
0010  *   (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org)
0011  *   (c) 2000 Stephen J. Gowdy (SGowdy@lbl.gov)
0012  *
0013  * Initial work by:
0014  *   (c) 1999 Michael Gee (michael@linuxspecific.com)
0015  *
0016  * This driver is based on the 'USB Mass Storage Class' document. This
0017  * describes in detail the protocol used to communicate with such
0018  * devices.  Clearly, the designers had SCSI and ATAPI commands in
0019  * mind when they created this document.  The commands are all very
0020  * similar to commands in the SCSI-II and ATAPI specifications.
0021  *
0022  * It is important to note that in a number of cases this class
0023  * exhibits class-specific exemptions from the USB specification.
0024  * Notably the usage of NAK, STALL and ACK differs from the norm, in
0025  * that they are used to communicate wait, failed and OK on commands.
0026  *
0027  * Also, for certain devices, the interrupt endpoint is used to convey
0028  * status of a command.
0029  */
0030 
0031 #include <linux/blkdev.h>
0032 #include <linux/dma-mapping.h>
0033 #include <linux/module.h>
0034 #include <linux/mutex.h>
0035 
0036 #include <scsi/scsi.h>
0037 #include <scsi/scsi_cmnd.h>
0038 #include <scsi/scsi_devinfo.h>
0039 #include <scsi/scsi_device.h>
0040 #include <scsi/scsi_eh.h>
0041 
0042 #include "usb.h"
0043 #include <linux/usb/hcd.h>
0044 #include "scsiglue.h"
0045 #include "debug.h"
0046 #include "transport.h"
0047 #include "protocol.h"
0048 
0049 /*
0050  * Vendor IDs for companies that seem to include the READ CAPACITY bug
0051  * in all their devices
0052  */
0053 #define VENDOR_ID_NOKIA     0x0421
0054 #define VENDOR_ID_NIKON     0x04b0
0055 #define VENDOR_ID_PENTAX    0x0a17
0056 #define VENDOR_ID_MOTOROLA  0x22b8
0057 
0058 /***********************************************************************
0059  * Host functions 
0060  ***********************************************************************/
0061 
0062 static const char* host_info(struct Scsi_Host *host)
0063 {
0064     struct us_data *us = host_to_us(host);
0065     return us->scsi_name;
0066 }
0067 
0068 static int slave_alloc (struct scsi_device *sdev)
0069 {
0070     struct us_data *us = host_to_us(sdev->host);
0071 
0072     /*
0073      * Set the INQUIRY transfer length to 36.  We don't use any of
0074      * the extra data and many devices choke if asked for more or
0075      * less than 36 bytes.
0076      */
0077     sdev->inquiry_len = 36;
0078 
0079     /*
0080      * Some host controllers may have alignment requirements.
0081      * We'll play it safe by requiring 512-byte alignment always.
0082      */
0083     blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
0084 
0085     /* Tell the SCSI layer if we know there is more than one LUN */
0086     if (us->protocol == USB_PR_BULK && us->max_lun > 0)
0087         sdev->sdev_bflags |= BLIST_FORCELUN;
0088 
0089     return 0;
0090 }
0091 
0092 static int slave_configure(struct scsi_device *sdev)
0093 {
0094     struct us_data *us = host_to_us(sdev->host);
0095     struct device *dev = us->pusb_dev->bus->sysdev;
0096 
0097     /*
0098      * Many devices have trouble transferring more than 32KB at a time,
0099      * while others have trouble with more than 64K. At this time we
0100      * are limiting both to 32K (64 sectores).
0101      */
0102     if (us->fflags & (US_FL_MAX_SECTORS_64 | US_FL_MAX_SECTORS_MIN)) {
0103         unsigned int max_sectors = 64;
0104 
0105         if (us->fflags & US_FL_MAX_SECTORS_MIN)
0106             max_sectors = PAGE_SIZE >> 9;
0107         if (queue_max_hw_sectors(sdev->request_queue) > max_sectors)
0108             blk_queue_max_hw_sectors(sdev->request_queue,
0109                           max_sectors);
0110     } else if (sdev->type == TYPE_TAPE) {
0111         /*
0112          * Tapes need much higher max_sector limits, so just
0113          * raise it to the maximum possible (4 GB / 512) and
0114          * let the queue segment size sort out the real limit.
0115          */
0116         blk_queue_max_hw_sectors(sdev->request_queue, 0x7FFFFF);
0117     } else if (us->pusb_dev->speed >= USB_SPEED_SUPER) {
0118         /*
0119          * USB3 devices will be limited to 2048 sectors. This gives us
0120          * better throughput on most devices.
0121          */
0122         blk_queue_max_hw_sectors(sdev->request_queue, 2048);
0123     }
0124 
0125     /*
0126      * The max_hw_sectors should be up to maximum size of a mapping for
0127      * the device. Otherwise, a DMA API might fail on swiotlb environment.
0128      */
0129     blk_queue_max_hw_sectors(sdev->request_queue,
0130         min_t(size_t, queue_max_hw_sectors(sdev->request_queue),
0131               dma_max_mapping_size(dev) >> SECTOR_SHIFT));
0132 
0133     /*
0134      * Some USB host controllers can't do DMA; they have to use PIO.
0135      * For such controllers we need to make sure the block layer sets
0136      * up bounce buffers in addressable memory.
0137      */
0138     if (!hcd_uses_dma(bus_to_hcd(us->pusb_dev->bus)) ||
0139             (bus_to_hcd(us->pusb_dev->bus)->localmem_pool != NULL))
0140         blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_HIGH);
0141 
0142     /*
0143      * We can't put these settings in slave_alloc() because that gets
0144      * called before the device type is known.  Consequently these
0145      * settings can't be overridden via the scsi devinfo mechanism.
0146      */
0147     if (sdev->type == TYPE_DISK) {
0148 
0149         /*
0150          * Some vendors seem to put the READ CAPACITY bug into
0151          * all their devices -- primarily makers of cell phones
0152          * and digital cameras.  Since these devices always use
0153          * flash media and can be expected to have an even number
0154          * of sectors, we will always enable the CAPACITY_HEURISTICS
0155          * flag unless told otherwise.
0156          */
0157         switch (le16_to_cpu(us->pusb_dev->descriptor.idVendor)) {
0158         case VENDOR_ID_NOKIA:
0159         case VENDOR_ID_NIKON:
0160         case VENDOR_ID_PENTAX:
0161         case VENDOR_ID_MOTOROLA:
0162             if (!(us->fflags & (US_FL_FIX_CAPACITY |
0163                     US_FL_CAPACITY_OK)))
0164                 us->fflags |= US_FL_CAPACITY_HEURISTICS;
0165             break;
0166         }
0167 
0168         /*
0169          * Disk-type devices use MODE SENSE(6) if the protocol
0170          * (SubClass) is Transparent SCSI, otherwise they use
0171          * MODE SENSE(10).
0172          */
0173         if (us->subclass != USB_SC_SCSI && us->subclass != USB_SC_CYP_ATACB)
0174             sdev->use_10_for_ms = 1;
0175 
0176         /*
0177          *Many disks only accept MODE SENSE transfer lengths of
0178          * 192 bytes (that's what Windows uses).
0179          */
0180         sdev->use_192_bytes_for_3f = 1;
0181 
0182         /*
0183          * Some devices don't like MODE SENSE with page=0x3f,
0184          * which is the command used for checking if a device
0185          * is write-protected.  Now that we tell the sd driver
0186          * to do a 192-byte transfer with this command the
0187          * majority of devices work fine, but a few still can't
0188          * handle it.  The sd driver will simply assume those
0189          * devices are write-enabled.
0190          */
0191         if (us->fflags & US_FL_NO_WP_DETECT)
0192             sdev->skip_ms_page_3f = 1;
0193 
0194         /*
0195          * A number of devices have problems with MODE SENSE for
0196          * page x08, so we will skip it.
0197          */
0198         sdev->skip_ms_page_8 = 1;
0199 
0200         /*
0201          * Some devices don't handle VPD pages correctly, so skip vpd
0202          * pages if not forced by SCSI layer.
0203          */
0204         sdev->skip_vpd_pages = !sdev->try_vpd_pages;
0205 
0206         /* Do not attempt to use REPORT SUPPORTED OPERATION CODES */
0207         sdev->no_report_opcodes = 1;
0208 
0209         /* Do not attempt to use WRITE SAME */
0210         sdev->no_write_same = 1;
0211 
0212         /*
0213          * Some disks return the total number of blocks in response
0214          * to READ CAPACITY rather than the highest block number.
0215          * If this device makes that mistake, tell the sd driver.
0216          */
0217         if (us->fflags & US_FL_FIX_CAPACITY)
0218             sdev->fix_capacity = 1;
0219 
0220         /*
0221          * A few disks have two indistinguishable version, one of
0222          * which reports the correct capacity and the other does not.
0223          * The sd driver has to guess which is the case.
0224          */
0225         if (us->fflags & US_FL_CAPACITY_HEURISTICS)
0226             sdev->guess_capacity = 1;
0227 
0228         /* Some devices cannot handle READ_CAPACITY_16 */
0229         if (us->fflags & US_FL_NO_READ_CAPACITY_16)
0230             sdev->no_read_capacity_16 = 1;
0231 
0232         /*
0233          * Many devices do not respond properly to READ_CAPACITY_16.
0234          * Tell the SCSI layer to try READ_CAPACITY_10 first.
0235          * However some USB 3.0 drive enclosures return capacity
0236          * modulo 2TB. Those must use READ_CAPACITY_16
0237          */
0238         if (!(us->fflags & US_FL_NEEDS_CAP16))
0239             sdev->try_rc_10_first = 1;
0240 
0241         /*
0242          * assume SPC3 or latter devices support sense size > 18
0243          * unless US_FL_BAD_SENSE quirk is specified.
0244          */
0245         if (sdev->scsi_level > SCSI_SPC_2 &&
0246             !(us->fflags & US_FL_BAD_SENSE))
0247             us->fflags |= US_FL_SANE_SENSE;
0248 
0249         /*
0250          * USB-IDE bridges tend to report SK = 0x04 (Non-recoverable
0251          * Hardware Error) when any low-level error occurs,
0252          * recoverable or not.  Setting this flag tells the SCSI
0253          * midlayer to retry such commands, which frequently will
0254          * succeed and fix the error.  The worst this can lead to
0255          * is an occasional series of retries that will all fail.
0256          */
0257         sdev->retry_hwerror = 1;
0258 
0259         /*
0260          * USB disks should allow restart.  Some drives spin down
0261          * automatically, requiring a START-STOP UNIT command.
0262          */
0263         sdev->allow_restart = 1;
0264 
0265         /*
0266          * Some USB cardreaders have trouble reading an sdcard's last
0267          * sector in a larger then 1 sector read, since the performance
0268          * impact is negligible we set this flag for all USB disks
0269          */
0270         sdev->last_sector_bug = 1;
0271 
0272         /*
0273          * Enable last-sector hacks for single-target devices using
0274          * the Bulk-only transport, unless we already know the
0275          * capacity will be decremented or is correct.
0276          */
0277         if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK |
0278                     US_FL_SCM_MULT_TARG)) &&
0279                 us->protocol == USB_PR_BULK)
0280             us->use_last_sector_hacks = 1;
0281 
0282         /* Check if write cache default on flag is set or not */
0283         if (us->fflags & US_FL_WRITE_CACHE)
0284             sdev->wce_default_on = 1;
0285 
0286         /* A few buggy USB-ATA bridges don't understand FUA */
0287         if (us->fflags & US_FL_BROKEN_FUA)
0288             sdev->broken_fua = 1;
0289 
0290         /* Some even totally fail to indicate a cache */
0291         if (us->fflags & US_FL_ALWAYS_SYNC) {
0292             /* don't read caching information */
0293             sdev->skip_ms_page_8 = 1;
0294             sdev->skip_ms_page_3f = 1;
0295             /* assume sync is needed */
0296             sdev->wce_default_on = 1;
0297         }
0298     } else {
0299 
0300         /*
0301          * Non-disk-type devices don't need to ignore any pages
0302          * or to force 192-byte transfer lengths for MODE SENSE.
0303          * But they do need to use MODE SENSE(10).
0304          */
0305         sdev->use_10_for_ms = 1;
0306 
0307         /* Some (fake) usb cdrom devices don't like READ_DISC_INFO */
0308         if (us->fflags & US_FL_NO_READ_DISC_INFO)
0309             sdev->no_read_disc_info = 1;
0310     }
0311 
0312     /*
0313      * The CB and CBI transports have no way to pass LUN values
0314      * other than the bits in the second byte of a CDB.  But those
0315      * bits don't get set to the LUN value if the device reports
0316      * scsi_level == 0 (UNKNOWN).  Hence such devices must necessarily
0317      * be single-LUN.
0318      */
0319     if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_CBI) &&
0320             sdev->scsi_level == SCSI_UNKNOWN)
0321         us->max_lun = 0;
0322 
0323     /*
0324      * Some devices choke when they receive a PREVENT-ALLOW MEDIUM
0325      * REMOVAL command, so suppress those commands.
0326      */
0327     if (us->fflags & US_FL_NOT_LOCKABLE)
0328         sdev->lockable = 0;
0329 
0330     /*
0331      * this is to satisfy the compiler, tho I don't think the 
0332      * return code is ever checked anywhere.
0333      */
0334     return 0;
0335 }
0336 
0337 static int target_alloc(struct scsi_target *starget)
0338 {
0339     struct us_data *us = host_to_us(dev_to_shost(starget->dev.parent));
0340 
0341     /*
0342      * Some USB drives don't support REPORT LUNS, even though they
0343      * report a SCSI revision level above 2.  Tell the SCSI layer
0344      * not to issue that command; it will perform a normal sequential
0345      * scan instead.
0346      */
0347     starget->no_report_luns = 1;
0348 
0349     /*
0350      * The UFI spec treats the Peripheral Qualifier bits in an
0351      * INQUIRY result as reserved and requires devices to set them
0352      * to 0.  However the SCSI spec requires these bits to be set
0353      * to 3 to indicate when a LUN is not present.
0354      *
0355      * Let the scanning code know if this target merely sets
0356      * Peripheral Device Type to 0x1f to indicate no LUN.
0357      */
0358     if (us->subclass == USB_SC_UFI)
0359         starget->pdt_1f_for_no_lun = 1;
0360 
0361     return 0;
0362 }
0363 
0364 /* queue a command */
0365 /* This is always called with scsi_lock(host) held */
0366 static int queuecommand_lck(struct scsi_cmnd *srb)
0367 {
0368     void (*done)(struct scsi_cmnd *) = scsi_done;
0369     struct us_data *us = host_to_us(srb->device->host);
0370 
0371     /* check for state-transition errors */
0372     if (us->srb != NULL) {
0373         dev_err(&us->pusb_intf->dev,
0374             "Error in %s: us->srb = %p\n", __func__, us->srb);
0375         return SCSI_MLQUEUE_HOST_BUSY;
0376     }
0377 
0378     /* fail the command if we are disconnecting */
0379     if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
0380         usb_stor_dbg(us, "Fail command during disconnect\n");
0381         srb->result = DID_NO_CONNECT << 16;
0382         done(srb);
0383         return 0;
0384     }
0385 
0386     if ((us->fflags & US_FL_NO_ATA_1X) &&
0387             (srb->cmnd[0] == ATA_12 || srb->cmnd[0] == ATA_16)) {
0388         memcpy(srb->sense_buffer, usb_stor_sense_invalidCDB,
0389                sizeof(usb_stor_sense_invalidCDB));
0390         srb->result = SAM_STAT_CHECK_CONDITION;
0391         done(srb);
0392         return 0;
0393     }
0394 
0395     /* enqueue the command and wake up the control thread */
0396     us->srb = srb;
0397     complete(&us->cmnd_ready);
0398 
0399     return 0;
0400 }
0401 
0402 static DEF_SCSI_QCMD(queuecommand)
0403 
0404 /***********************************************************************
0405  * Error handling functions
0406  ***********************************************************************/
0407 
0408 /* Command timeout and abort */
0409 static int command_abort(struct scsi_cmnd *srb)
0410 {
0411     struct us_data *us = host_to_us(srb->device->host);
0412 
0413     usb_stor_dbg(us, "%s called\n", __func__);
0414 
0415     /*
0416      * us->srb together with the TIMED_OUT, RESETTING, and ABORTING
0417      * bits are protected by the host lock.
0418      */
0419     scsi_lock(us_to_host(us));
0420 
0421     /* Is this command still active? */
0422     if (us->srb != srb) {
0423         scsi_unlock(us_to_host(us));
0424         usb_stor_dbg(us, "-- nothing to abort\n");
0425         return FAILED;
0426     }
0427 
0428     /*
0429      * Set the TIMED_OUT bit.  Also set the ABORTING bit, but only if
0430      * a device reset isn't already in progress (to avoid interfering
0431      * with the reset).  Note that we must retain the host lock while
0432      * calling usb_stor_stop_transport(); otherwise it might interfere
0433      * with an auto-reset that begins as soon as we release the lock.
0434      */
0435     set_bit(US_FLIDX_TIMED_OUT, &us->dflags);
0436     if (!test_bit(US_FLIDX_RESETTING, &us->dflags)) {
0437         set_bit(US_FLIDX_ABORTING, &us->dflags);
0438         usb_stor_stop_transport(us);
0439     }
0440     scsi_unlock(us_to_host(us));
0441 
0442     /* Wait for the aborted command to finish */
0443     wait_for_completion(&us->notify);
0444     return SUCCESS;
0445 }
0446 
0447 /*
0448  * This invokes the transport reset mechanism to reset the state of the
0449  * device
0450  */
0451 static int device_reset(struct scsi_cmnd *srb)
0452 {
0453     struct us_data *us = host_to_us(srb->device->host);
0454     int result;
0455 
0456     usb_stor_dbg(us, "%s called\n", __func__);
0457 
0458     /* lock the device pointers and do the reset */
0459     mutex_lock(&(us->dev_mutex));
0460     result = us->transport_reset(us);
0461     mutex_unlock(&us->dev_mutex);
0462 
0463     return result < 0 ? FAILED : SUCCESS;
0464 }
0465 
0466 /* Simulate a SCSI bus reset by resetting the device's USB port. */
0467 static int bus_reset(struct scsi_cmnd *srb)
0468 {
0469     struct us_data *us = host_to_us(srb->device->host);
0470     int result;
0471 
0472     usb_stor_dbg(us, "%s called\n", __func__);
0473 
0474     result = usb_stor_port_reset(us);
0475     return result < 0 ? FAILED : SUCCESS;
0476 }
0477 
0478 /*
0479  * Report a driver-initiated device reset to the SCSI layer.
0480  * Calling this for a SCSI-initiated reset is unnecessary but harmless.
0481  * The caller must own the SCSI host lock.
0482  */
0483 void usb_stor_report_device_reset(struct us_data *us)
0484 {
0485     int i;
0486     struct Scsi_Host *host = us_to_host(us);
0487 
0488     scsi_report_device_reset(host, 0, 0);
0489     if (us->fflags & US_FL_SCM_MULT_TARG) {
0490         for (i = 1; i < host->max_id; ++i)
0491             scsi_report_device_reset(host, 0, i);
0492     }
0493 }
0494 
0495 /*
0496  * Report a driver-initiated bus reset to the SCSI layer.
0497  * Calling this for a SCSI-initiated reset is unnecessary but harmless.
0498  * The caller must not own the SCSI host lock.
0499  */
0500 void usb_stor_report_bus_reset(struct us_data *us)
0501 {
0502     struct Scsi_Host *host = us_to_host(us);
0503 
0504     scsi_lock(host);
0505     scsi_report_bus_reset(host, 0);
0506     scsi_unlock(host);
0507 }
0508 
0509 /***********************************************************************
0510  * /proc/scsi/ functions
0511  ***********************************************************************/
0512 
0513 static int write_info(struct Scsi_Host *host, char *buffer, int length)
0514 {
0515     /* if someone is sending us data, just throw it away */
0516     return length;
0517 }
0518 
0519 static int show_info (struct seq_file *m, struct Scsi_Host *host)
0520 {
0521     struct us_data *us = host_to_us(host);
0522     const char *string;
0523 
0524     /* print the controller name */
0525     seq_printf(m, "   Host scsi%d: usb-storage\n", host->host_no);
0526 
0527     /* print product, vendor, and serial number strings */
0528     if (us->pusb_dev->manufacturer)
0529         string = us->pusb_dev->manufacturer;
0530     else if (us->unusual_dev->vendorName)
0531         string = us->unusual_dev->vendorName;
0532     else
0533         string = "Unknown";
0534     seq_printf(m, "       Vendor: %s\n", string);
0535     if (us->pusb_dev->product)
0536         string = us->pusb_dev->product;
0537     else if (us->unusual_dev->productName)
0538         string = us->unusual_dev->productName;
0539     else
0540         string = "Unknown";
0541     seq_printf(m, "      Product: %s\n", string);
0542     if (us->pusb_dev->serial)
0543         string = us->pusb_dev->serial;
0544     else
0545         string = "None";
0546     seq_printf(m, "Serial Number: %s\n", string);
0547 
0548     /* show the protocol and transport */
0549     seq_printf(m, "     Protocol: %s\n", us->protocol_name);
0550     seq_printf(m, "    Transport: %s\n", us->transport_name);
0551 
0552     /* show the device flags */
0553     seq_printf(m, "       Quirks:");
0554 
0555 #define US_FLAG(name, value) \
0556     if (us->fflags & value) seq_printf(m, " " #name);
0557 US_DO_ALL_FLAGS
0558 #undef US_FLAG
0559     seq_putc(m, '\n');
0560     return 0;
0561 }
0562 
0563 /***********************************************************************
0564  * Sysfs interface
0565  ***********************************************************************/
0566 
0567 /* Output routine for the sysfs max_sectors file */
0568 static ssize_t max_sectors_show(struct device *dev, struct device_attribute *attr, char *buf)
0569 {
0570     struct scsi_device *sdev = to_scsi_device(dev);
0571 
0572     return sprintf(buf, "%u\n", queue_max_hw_sectors(sdev->request_queue));
0573 }
0574 
0575 /* Input routine for the sysfs max_sectors file */
0576 static ssize_t max_sectors_store(struct device *dev, struct device_attribute *attr, const char *buf,
0577         size_t count)
0578 {
0579     struct scsi_device *sdev = to_scsi_device(dev);
0580     unsigned short ms;
0581 
0582     if (sscanf(buf, "%hu", &ms) > 0) {
0583         blk_queue_max_hw_sectors(sdev->request_queue, ms);
0584         return count;
0585     }
0586     return -EINVAL;
0587 }
0588 static DEVICE_ATTR_RW(max_sectors);
0589 
0590 static struct attribute *usb_sdev_attrs[] = {
0591     &dev_attr_max_sectors.attr,
0592     NULL,
0593 };
0594 
0595 ATTRIBUTE_GROUPS(usb_sdev);
0596 
0597 /*
0598  * this defines our host template, with which we'll allocate hosts
0599  */
0600 
0601 static const struct scsi_host_template usb_stor_host_template = {
0602     /* basic userland interface stuff */
0603     .name =             "usb-storage",
0604     .proc_name =            "usb-storage",
0605     .show_info =            show_info,
0606     .write_info =           write_info,
0607     .info =             host_info,
0608 
0609     /* command interface -- queued only */
0610     .queuecommand =         queuecommand,
0611 
0612     /* error and abort handlers */
0613     .eh_abort_handler =     command_abort,
0614     .eh_device_reset_handler =  device_reset,
0615     .eh_bus_reset_handler =     bus_reset,
0616 
0617     /* queue commands only, only one command per LUN */
0618     .can_queue =            1,
0619 
0620     /* unknown initiator id */
0621     .this_id =          -1,
0622 
0623     .slave_alloc =          slave_alloc,
0624     .slave_configure =      slave_configure,
0625     .target_alloc =         target_alloc,
0626 
0627     /* lots of sg segments can be handled */
0628     .sg_tablesize =         SG_MAX_SEGMENTS,
0629 
0630 
0631     /*
0632      * Limit the total size of a transfer to 120 KB.
0633      *
0634      * Some devices are known to choke with anything larger. It seems like
0635      * the problem stems from the fact that original IDE controllers had
0636      * only an 8-bit register to hold the number of sectors in one transfer
0637      * and even those couldn't handle a full 256 sectors.
0638      *
0639      * Because we want to make sure we interoperate with as many devices as
0640      * possible, we will maintain a 240 sector transfer size limit for USB
0641      * Mass Storage devices.
0642      *
0643      * Tests show that other operating have similar limits with Microsoft
0644      * Windows 7 limiting transfers to 128 sectors for both USB2 and USB3
0645      * and Apple Mac OS X 10.11 limiting transfers to 256 sectors for USB2
0646      * and 2048 for USB3 devices.
0647      */
0648     .max_sectors =                  240,
0649 
0650     /* emulated HBA */
0651     .emulated =         1,
0652 
0653     /* we do our own delay after a device or bus reset */
0654     .skip_settle_delay =        1,
0655 
0656     /* sysfs device attributes */
0657     .sdev_groups =          usb_sdev_groups,
0658 
0659     /* module management */
0660     .module =           THIS_MODULE
0661 };
0662 
0663 void usb_stor_host_template_init(struct scsi_host_template *sht,
0664                  const char *name, struct module *owner)
0665 {
0666     *sht = usb_stor_host_template;
0667     sht->name = name;
0668     sht->proc_name = name;
0669     sht->module = owner;
0670 }
0671 EXPORT_SYMBOL_GPL(usb_stor_host_template_init);
0672 
0673 /* To Report "Illegal Request: Invalid Field in CDB */
0674 unsigned char usb_stor_sense_invalidCDB[18] = {
0675     [0] = 0x70,             /* current error */
0676     [2] = ILLEGAL_REQUEST,      /* Illegal Request = 0x05 */
0677     [7] = 0x0a,             /* additional length */
0678     [12]    = 0x24              /* Invalid Field in CDB */
0679 };
0680 EXPORT_SYMBOL_GPL(usb_stor_sense_invalidCDB);