diff options
author | Linus Torvalds | 2016-05-20 21:12:25 -0700 |
---|---|---|
committer | Linus Torvalds | 2016-05-20 21:12:25 -0700 |
commit | 19e36ad292ab24980db64a5ff17973d3118a8fb9 (patch) | |
tree | 175715409a689814e5cd425a98f2d2d47f82addf /drivers/usb/storage/scsiglue.c | |
parent | e10abc629f38efd9b6936cf3612583cc846104d9 (diff) | |
parent | 60d5794fe5a50d02f4a0df84b45910a4dfa8b487 (diff) |
Merge tag 'usb-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB updates from Greg KH:
"Here's the big pull request for USB and PHY drivers for 4.7-rc1
Full details in the shortlog, but it's the normal major gadget driver
updates, phy updates, new usbip code, as well as a bit of lots of
other stuff.
All have been in linux-next with no reported issues"
* tag 'usb-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (164 commits)
USB: serial: ti_usb_3410_5052: add MOXA UPORT 11x0 support
USB: serial: fix minor-number allocation
USB: serial: quatech2: fix use-after-free in probe error path
USB: serial: mxuport: fix use-after-free in probe error path
USB: serial: keyspan: fix debug and error messages
USB: serial: keyspan: fix URB unlink
USB: serial: keyspan: fix use-after-free in probe error path
USB: serial: io_edgeport: fix memory leaks in probe error path
USB: serial: io_edgeport: fix memory leaks in attach error path
usb: Remove unnecessary space before operator ','.
usb: Remove unnecessary space before open square bracket.
USB: FHCI: avoid redundant condition
usb: host: xhci-rcar: Avoid long wait in xhci_reset()
usb/host/fotg210: remove dead code in create_sysfs_files
usb: wusbcore: Do not initialise statics to 0.
usb: wusbcore: Remove space before ',' and '(' .
USB: serial: cp210x: clean up CRTSCTS flag code
USB: serial: cp210x: get rid of magic numbers in CRTSCTS flag code
USB: serial: cp210x: fix hardware flow-control disable
USB: serial: option: add even more ZTE device ids
...
Diffstat (limited to 'drivers/usb/storage/scsiglue.c')
-rw-r--r-- | drivers/usb/storage/scsiglue.c | 169 |
1 files changed, 120 insertions, 49 deletions
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c index ae85861051eb..33eb923df892 100644 --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c @@ -1,4 +1,5 @@ -/* Driver for USB Mass Storage compliant devices +/* + * Driver for USB Mass Storage compliant devices * SCSI layer glue code * * Current development and maintenance by: @@ -58,7 +59,8 @@ #include "transport.h" #include "protocol.h" -/* Vendor IDs for companies that seem to include the READ CAPACITY bug +/* + * Vendor IDs for companies that seem to include the READ CAPACITY bug * in all their devices */ #define VENDOR_ID_NOKIA 0x0421 @@ -87,7 +89,8 @@ static int slave_alloc (struct scsi_device *sdev) */ sdev->inquiry_len = 36; - /* USB has unusual DMA-alignment requirements: Although the + /* + * USB has unusual DMA-alignment requirements: Although the * starting address of each scatter-gather element doesn't matter, * the length of each element except the last must be divisible * by the Bulk maxpacket value. There's currently no way to @@ -115,7 +118,8 @@ static int slave_configure(struct scsi_device *sdev) { struct us_data *us = host_to_us(sdev->host); - /* Many devices have trouble transferring more than 32KB at a time, + /* + * Many devices have trouble transferring more than 32KB at a time, * while others have trouble with more than 64K. At this time we * are limiting both to 32K (64 sectores). */ @@ -128,14 +132,22 @@ static int slave_configure(struct scsi_device *sdev) blk_queue_max_hw_sectors(sdev->request_queue, max_sectors); } else if (sdev->type == TYPE_TAPE) { - /* Tapes need much higher max_sector limits, so just + /* + * Tapes need much higher max_sector limits, so just * raise it to the maximum possible (4 GB / 512) and * let the queue segment size sort out the real limit. */ blk_queue_max_hw_sectors(sdev->request_queue, 0x7FFFFF); + } else if (us->pusb_dev->speed >= USB_SPEED_SUPER) { + /* + * USB3 devices will be limited to 2048 sectors. This gives us + * better throughput on most devices. + */ + blk_queue_max_hw_sectors(sdev->request_queue, 2048); } - /* Some USB host controllers can't do DMA; they have to use PIO. + /* + * Some USB host controllers can't do DMA; they have to use PIO. * They indicate this by setting their dma_mask to NULL. For * such controllers we need to make sure the block layer sets * up bounce buffers in addressable memory. @@ -143,17 +155,21 @@ static int slave_configure(struct scsi_device *sdev) if (!us->pusb_dev->bus->controller->dma_mask) blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_HIGH); - /* We can't put these settings in slave_alloc() because that gets + /* + * We can't put these settings in slave_alloc() because that gets * called before the device type is known. Consequently these - * settings can't be overridden via the scsi devinfo mechanism. */ + * settings can't be overridden via the scsi devinfo mechanism. + */ if (sdev->type == TYPE_DISK) { - /* Some vendors seem to put the READ CAPACITY bug into + /* + * Some vendors seem to put the READ CAPACITY bug into * all their devices -- primarily makers of cell phones * and digital cameras. Since these devices always use * flash media and can be expected to have an even number * of sectors, we will always enable the CAPACITY_HEURISTICS - * flag unless told otherwise. */ + * flag unless told otherwise. + */ switch (le16_to_cpu(us->pusb_dev->descriptor.idVendor)) { case VENDOR_ID_NOKIA: case VENDOR_ID_NIKON: @@ -165,28 +181,36 @@ static int slave_configure(struct scsi_device *sdev) break; } - /* Disk-type devices use MODE SENSE(6) if the protocol + /* + * Disk-type devices use MODE SENSE(6) if the protocol * (SubClass) is Transparent SCSI, otherwise they use - * MODE SENSE(10). */ + * MODE SENSE(10). + */ if (us->subclass != USB_SC_SCSI && us->subclass != USB_SC_CYP_ATACB) sdev->use_10_for_ms = 1; - /* Many disks only accept MODE SENSE transfer lengths of - * 192 bytes (that's what Windows uses). */ + /* + *Many disks only accept MODE SENSE transfer lengths of + * 192 bytes (that's what Windows uses). + */ sdev->use_192_bytes_for_3f = 1; - /* Some devices don't like MODE SENSE with page=0x3f, + /* + * Some devices don't like MODE SENSE with page=0x3f, * which is the command used for checking if a device * is write-protected. Now that we tell the sd driver * to do a 192-byte transfer with this command the * majority of devices work fine, but a few still can't * handle it. The sd driver will simply assume those - * devices are write-enabled. */ + * devices are write-enabled. + */ if (us->fflags & US_FL_NO_WP_DETECT) sdev->skip_ms_page_3f = 1; - /* A number of devices have problems with MODE SENSE for - * page x08, so we will skip it. */ + /* + * A number of devices have problems with MODE SENSE for + * page x08, so we will skip it. + */ sdev->skip_ms_page_8 = 1; /* Some devices don't handle VPD pages correctly */ @@ -198,15 +222,19 @@ static int slave_configure(struct scsi_device *sdev) /* Do not attempt to use WRITE SAME */ sdev->no_write_same = 1; - /* Some disks return the total number of blocks in response + /* + * Some disks return the total number of blocks in response * to READ CAPACITY rather than the highest block number. - * If this device makes that mistake, tell the sd driver. */ + * If this device makes that mistake, tell the sd driver. + */ if (us->fflags & US_FL_FIX_CAPACITY) sdev->fix_capacity = 1; - /* A few disks have two indistinguishable version, one of + /* + * A few disks have two indistinguishable version, one of * which reports the correct capacity and the other does not. - * The sd driver has to guess which is the case. */ + * The sd driver has to guess which is the case. + */ if (us->fflags & US_FL_CAPACITY_HEURISTICS) sdev->guess_capacity = 1; @@ -227,26 +255,34 @@ static int slave_configure(struct scsi_device *sdev) if (sdev->scsi_level > SCSI_SPC_2) us->fflags |= US_FL_SANE_SENSE; - /* USB-IDE bridges tend to report SK = 0x04 (Non-recoverable + /* + * USB-IDE bridges tend to report SK = 0x04 (Non-recoverable * Hardware Error) when any low-level error occurs, * recoverable or not. Setting this flag tells the SCSI * midlayer to retry such commands, which frequently will * succeed and fix the error. The worst this can lead to - * is an occasional series of retries that will all fail. */ + * is an occasional series of retries that will all fail. + */ sdev->retry_hwerror = 1; - /* USB disks should allow restart. Some drives spin down - * automatically, requiring a START-STOP UNIT command. */ + /* + * USB disks should allow restart. Some drives spin down + * automatically, requiring a START-STOP UNIT command. + */ sdev->allow_restart = 1; - /* Some USB cardreaders have trouble reading an sdcard's last + /* + * Some USB cardreaders have trouble reading an sdcard's last * sector in a larger then 1 sector read, since the performance - * impact is negligible we set this flag for all USB disks */ + * impact is negligible we set this flag for all USB disks + */ sdev->last_sector_bug = 1; - /* Enable last-sector hacks for single-target devices using + /* + * Enable last-sector hacks for single-target devices using * the Bulk-only transport, unless we already know the - * capacity will be decremented or is correct. */ + * capacity will be decremented or is correct. + */ if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK | US_FL_SCM_MULT_TARG)) && us->protocol == USB_PR_BULK) @@ -262,9 +298,11 @@ static int slave_configure(struct scsi_device *sdev) } else { - /* Non-disk-type devices don't need to blacklist any pages + /* + * Non-disk-type devices don't need to blacklist any pages * or to force 192-byte transfer lengths for MODE SENSE. - * But they do need to use MODE SENSE(10). */ + * But they do need to use MODE SENSE(10). + */ sdev->use_10_for_ms = 1; /* Some (fake) usb cdrom devices don't like READ_DISC_INFO */ @@ -272,7 +310,8 @@ static int slave_configure(struct scsi_device *sdev) sdev->no_read_disc_info = 1; } - /* The CB and CBI transports have no way to pass LUN values + /* + * The CB and CBI transports have no way to pass LUN values * other than the bits in the second byte of a CDB. But those * bits don't get set to the LUN value if the device reports * scsi_level == 0 (UNKNOWN). Hence such devices must necessarily @@ -282,13 +321,17 @@ static int slave_configure(struct scsi_device *sdev) sdev->scsi_level == SCSI_UNKNOWN) us->max_lun = 0; - /* Some devices choke when they receive a PREVENT-ALLOW MEDIUM - * REMOVAL command, so suppress those commands. */ + /* + * Some devices choke when they receive a PREVENT-ALLOW MEDIUM + * REMOVAL command, so suppress those commands. + */ if (us->fflags & US_FL_NOT_LOCKABLE) sdev->lockable = 0; - /* this is to satisfy the compiler, tho I don't think the - * return code is ever checked anywhere. */ + /* + * this is to satisfy the compiler, tho I don't think the + * return code is ever checked anywhere. + */ return 0; } @@ -362,8 +405,10 @@ static int command_abort(struct scsi_cmnd *srb) usb_stor_dbg(us, "%s called\n", __func__); - /* us->srb together with the TIMED_OUT, RESETTING, and ABORTING - * bits are protected by the host lock. */ + /* + * us->srb together with the TIMED_OUT, RESETTING, and ABORTING + * bits are protected by the host lock. + */ scsi_lock(us_to_host(us)); /* Is this command still active? */ @@ -373,11 +418,13 @@ static int command_abort(struct scsi_cmnd *srb) return FAILED; } - /* Set the TIMED_OUT bit. Also set the ABORTING bit, but only if + /* + * Set the TIMED_OUT bit. Also set the ABORTING bit, but only if * a device reset isn't already in progress (to avoid interfering * with the reset). Note that we must retain the host lock while * calling usb_stor_stop_transport(); otherwise it might interfere - * with an auto-reset that begins as soon as we release the lock. */ + * with an auto-reset that begins as soon as we release the lock. + */ set_bit(US_FLIDX_TIMED_OUT, &us->dflags); if (!test_bit(US_FLIDX_RESETTING, &us->dflags)) { set_bit(US_FLIDX_ABORTING, &us->dflags); @@ -390,8 +437,10 @@ static int command_abort(struct scsi_cmnd *srb) return SUCCESS; } -/* This invokes the transport reset mechanism to reset the state of the - * device */ +/* + * This invokes the transport reset mechanism to reset the state of the + * device + */ static int device_reset(struct scsi_cmnd *srb) { struct us_data *us = host_to_us(srb->device->host); @@ -419,9 +468,11 @@ static int bus_reset(struct scsi_cmnd *srb) return result < 0 ? FAILED : SUCCESS; } -/* Report a driver-initiated device reset to the SCSI layer. +/* + * Report a driver-initiated device reset to the SCSI layer. * Calling this for a SCSI-initiated reset is unnecessary but harmless. - * The caller must own the SCSI host lock. */ + * The caller must own the SCSI host lock. + */ void usb_stor_report_device_reset(struct us_data *us) { int i; @@ -434,9 +485,11 @@ void usb_stor_report_device_reset(struct us_data *us) } } -/* Report a driver-initiated bus reset to the SCSI layer. +/* + * Report a driver-initiated bus reset to the SCSI layer. * Calling this for a SCSI-initiated reset is unnecessary but harmless. - * The caller must not own the SCSI host lock. */ + * The caller must not own the SCSI host lock. + */ void usb_stor_report_bus_reset(struct us_data *us) { struct Scsi_Host *host = us_to_host(us); @@ -565,10 +618,28 @@ static const struct scsi_host_template usb_stor_host_template = { /* lots of sg segments can be handled */ .sg_tablesize = SG_MAX_SEGMENTS, - /* limit the total size of a transfer to 120 KB */ + + /* + * Limit the total size of a transfer to 120 KB. + * + * Some devices are known to choke with anything larger. It seems like + * the problem stems from the fact that original IDE controllers had + * only an 8-bit register to hold the number of sectors in one transfer + * and even those couldn't handle a full 256 sectors. + * + * Because we want to make sure we interoperate with as many devices as + * possible, we will maintain a 240 sector transfer size limit for USB + * Mass Storage devices. + * + * Tests show that other operating have similar limits with Microsoft + * Windows 7 limiting transfers to 128 sectors for both USB2 and USB3 + * and Apple Mac OS X 10.11 limiting transfers to 256 sectors for USB2 + * and 2048 for USB3 devices. + */ .max_sectors = 240, - /* merge commands... this seems to help performance, but + /* + * merge commands... this seems to help performance, but * periodically someone should test to see which setting is more * optimal. */ |