2017-11-03 18:28:30 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Driver for USB Mass Storage compliant devices
|
2005-04-17 06:20:36 +08:00
|
|
|
* SCSI layer glue code
|
|
|
|
*
|
|
|
|
* Current development and maintenance by:
|
|
|
|
* (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
|
|
|
|
*
|
|
|
|
* Developed with the assistance of:
|
|
|
|
* (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org)
|
|
|
|
* (c) 2000 Stephen J. Gowdy (SGowdy@lbl.gov)
|
|
|
|
*
|
|
|
|
* Initial work by:
|
|
|
|
* (c) 1999 Michael Gee (michael@linuxspecific.com)
|
|
|
|
*
|
|
|
|
* This driver is based on the 'USB Mass Storage Class' document. This
|
|
|
|
* describes in detail the protocol used to communicate with such
|
|
|
|
* devices. Clearly, the designers had SCSI and ATAPI commands in
|
|
|
|
* mind when they created this document. The commands are all very
|
|
|
|
* similar to commands in the SCSI-II and ATAPI specifications.
|
|
|
|
*
|
|
|
|
* It is important to note that in a number of cases this class
|
|
|
|
* exhibits class-specific exemptions from the USB specification.
|
|
|
|
* Notably the usage of NAK, STALL and ACK differs from the norm, in
|
|
|
|
* that they are used to communicate wait, failed and OK on commands.
|
|
|
|
*
|
|
|
|
* Also, for certain devices, the interrupt endpoint is used to convey
|
|
|
|
* status of a command.
|
|
|
|
*/
|
|
|
|
|
usb-storage: Add a limitation for blk_queue_max_hw_sectors()
This patch fixes an issue that the following error happens on
swiotlb environment:
xhci-hcd ee000000.usb: swiotlb buffer is full (sz: 524288 bytes), total 32768 (slots), used 1338 (slots)
On the kernel v5.1, block settings of a usb-storage with SuperSpeed
were the following so that the block layer will allocate buffers
up to 64 KiB, and then the issue didn't happen.
max_segment_size = 65536
max_hw_sectors_kb = 1024
After the commit 09324d32d2a0 ("block: force an unlimited segment
size on queues with a virt boundary") is applied, the block settings
are the following. So, the block layer will allocate buffers up to
1024 KiB, and then the issue happens:
max_segment_size = 4294967295
max_hw_sectors_kb = 1024
To fix the issue, the usb-storage driver checks the maximum size of
a mapping for the device and then adjusts the max_hw_sectors_kb
if required. After this patch is applied, the block settings will
be the following, and then the issue doesn't happen.
max_segment_size = 4294967295
max_hw_sectors_kb = 256
Fixes: 09324d32d2a0 ("block: force an unlimited segment size on queues with a virt boundary")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/1563793105-20597-1-git-send-email-yoshihiro.shimoda.uh@renesas.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-07-22 18:58:25 +08:00
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
2006-01-11 22:55:29 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_cmnd.h>
|
|
|
|
#include <scsi/scsi_devinfo.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
|
|
|
#include <scsi/scsi_eh.h>
|
|
|
|
|
|
|
|
#include "usb.h"
|
2019-09-03 16:46:12 +08:00
|
|
|
#include <linux/usb/hcd.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "scsiglue.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "transport.h"
|
|
|
|
#include "protocol.h"
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Vendor IDs for companies that seem to include the READ CAPACITY bug
|
2008-12-19 05:41:49 +08:00
|
|
|
* in all their devices
|
|
|
|
*/
|
|
|
|
#define VENDOR_ID_NOKIA 0x0421
|
|
|
|
#define VENDOR_ID_NIKON 0x04b0
|
2009-02-05 04:48:03 +08:00
|
|
|
#define VENDOR_ID_PENTAX 0x0a17
|
2008-12-19 05:41:49 +08:00
|
|
|
#define VENDOR_ID_MOTOROLA 0x22b8
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/***********************************************************************
|
|
|
|
* Host functions
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
static const char* host_info(struct Scsi_Host *host)
|
|
|
|
{
|
2009-09-25 06:19:11 +08:00
|
|
|
struct us_data *us = host_to_us(host);
|
|
|
|
return us->scsi_name;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int slave_alloc (struct scsi_device *sdev)
|
|
|
|
{
|
2014-01-30 23:43:22 +08:00
|
|
|
struct us_data *us = host_to_us(sdev->host);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Set the INQUIRY transfer length to 36. We don't use any of
|
|
|
|
* the extra data and many devices choke if asked for more or
|
|
|
|
* less than 36 bytes.
|
|
|
|
*/
|
|
|
|
sdev->inquiry_len = 36;
|
2006-08-22 00:00:53 +08:00
|
|
|
|
2019-04-16 01:19:25 +08:00
|
|
|
/*
|
|
|
|
* Some host controllers may have alignment requirements.
|
|
|
|
* We'll play it safe by requiring 512-byte alignment always.
|
2008-03-28 02:52:57 +08:00
|
|
|
*/
|
2008-07-01 01:39:59 +08:00
|
|
|
blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
|
2008-01-02 00:00:10 +08:00
|
|
|
|
2014-01-30 23:43:22 +08:00
|
|
|
/* Tell the SCSI layer if we know there is more than one LUN */
|
|
|
|
if (us->protocol == USB_PR_BULK && us->max_lun > 0)
|
|
|
|
sdev->sdev_bflags |= BLIST_FORCELUN;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int slave_configure(struct scsi_device *sdev)
|
|
|
|
{
|
|
|
|
struct us_data *us = host_to_us(sdev->host);
|
usb-storage: Add a limitation for blk_queue_max_hw_sectors()
This patch fixes an issue that the following error happens on
swiotlb environment:
xhci-hcd ee000000.usb: swiotlb buffer is full (sz: 524288 bytes), total 32768 (slots), used 1338 (slots)
On the kernel v5.1, block settings of a usb-storage with SuperSpeed
were the following so that the block layer will allocate buffers
up to 64 KiB, and then the issue didn't happen.
max_segment_size = 65536
max_hw_sectors_kb = 1024
After the commit 09324d32d2a0 ("block: force an unlimited segment
size on queues with a virt boundary") is applied, the block settings
are the following. So, the block layer will allocate buffers up to
1024 KiB, and then the issue happens:
max_segment_size = 4294967295
max_hw_sectors_kb = 1024
To fix the issue, the usb-storage driver checks the maximum size of
a mapping for the device and then adjusts the max_hw_sectors_kb
if required. After this patch is applied, the block settings will
be the following, and then the issue doesn't happen.
max_segment_size = 4294967295
max_hw_sectors_kb = 256
Fixes: 09324d32d2a0 ("block: force an unlimited segment size on queues with a virt boundary")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/1563793105-20597-1-git-send-email-yoshihiro.shimoda.uh@renesas.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-07-22 18:58:25 +08:00
|
|
|
struct device *dev = us->pusb_dev->bus->sysdev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Many devices have trouble transferring more than 32KB at a time,
|
2006-06-25 08:27:10 +08:00
|
|
|
* while others have trouble with more than 64K. At this time we
|
|
|
|
* are limiting both to 32K (64 sectores).
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
if (us->fflags & (US_FL_MAX_SECTORS_64 | US_FL_MAX_SECTORS_MIN)) {
|
2007-12-06 13:36:45 +08:00
|
|
|
unsigned int max_sectors = 64;
|
|
|
|
|
2008-05-02 03:35:18 +08:00
|
|
|
if (us->fflags & US_FL_MAX_SECTORS_MIN)
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
max_sectors = PAGE_SIZE >> 9;
|
2010-02-27 00:49:39 +08:00
|
|
|
if (queue_max_hw_sectors(sdev->request_queue) > max_sectors)
|
2010-02-26 13:20:38 +08:00
|
|
|
blk_queue_max_hw_sectors(sdev->request_queue,
|
2007-12-06 13:36:45 +08:00
|
|
|
max_sectors);
|
2009-03-23 21:51:02 +08:00
|
|
|
} else if (sdev->type == TYPE_TAPE) {
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Tapes need much higher max_sector limits, so just
|
2009-03-23 21:51:02 +08:00
|
|
|
* raise it to the maximum possible (4 GB / 512) and
|
|
|
|
* let the queue segment size sort out the real limit.
|
|
|
|
*/
|
2010-02-26 13:20:38 +08:00
|
|
|
blk_queue_max_hw_sectors(sdev->request_queue, 0x7FFFFF);
|
2016-04-18 18:09:10 +08:00
|
|
|
} else if (us->pusb_dev->speed >= USB_SPEED_SUPER) {
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* USB3 devices will be limited to 2048 sectors. This gives us
|
2016-04-18 18:09:10 +08:00
|
|
|
* better throughput on most devices.
|
|
|
|
*/
|
|
|
|
blk_queue_max_hw_sectors(sdev->request_queue, 2048);
|
2007-12-06 13:36:45 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
usb-storage: Add a limitation for blk_queue_max_hw_sectors()
This patch fixes an issue that the following error happens on
swiotlb environment:
xhci-hcd ee000000.usb: swiotlb buffer is full (sz: 524288 bytes), total 32768 (slots), used 1338 (slots)
On the kernel v5.1, block settings of a usb-storage with SuperSpeed
were the following so that the block layer will allocate buffers
up to 64 KiB, and then the issue didn't happen.
max_segment_size = 65536
max_hw_sectors_kb = 1024
After the commit 09324d32d2a0 ("block: force an unlimited segment
size on queues with a virt boundary") is applied, the block settings
are the following. So, the block layer will allocate buffers up to
1024 KiB, and then the issue happens:
max_segment_size = 4294967295
max_hw_sectors_kb = 1024
To fix the issue, the usb-storage driver checks the maximum size of
a mapping for the device and then adjusts the max_hw_sectors_kb
if required. After this patch is applied, the block settings will
be the following, and then the issue doesn't happen.
max_segment_size = 4294967295
max_hw_sectors_kb = 256
Fixes: 09324d32d2a0 ("block: force an unlimited segment size on queues with a virt boundary")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/1563793105-20597-1-git-send-email-yoshihiro.shimoda.uh@renesas.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-07-22 18:58:25 +08:00
|
|
|
/*
|
|
|
|
* The max_hw_sectors should be up to maximum size of a mapping for
|
|
|
|
* the device. Otherwise, a DMA API might fail on swiotlb environment.
|
|
|
|
*/
|
|
|
|
blk_queue_max_hw_sectors(sdev->request_queue,
|
|
|
|
min_t(size_t, queue_max_hw_sectors(sdev->request_queue),
|
|
|
|
dma_max_mapping_size(dev) >> SECTOR_SHIFT));
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some USB host controllers can't do DMA; they have to use PIO.
|
2019-09-03 16:46:12 +08:00
|
|
|
* For such controllers we need to make sure the block layer sets
|
2008-11-22 00:46:17 +08:00
|
|
|
* up bounce buffers in addressable memory.
|
|
|
|
*/
|
2019-09-03 16:46:12 +08:00
|
|
|
if (!hcd_uses_dma(bus_to_hcd(us->pusb_dev->bus)))
|
2008-11-22 00:46:17 +08:00
|
|
|
blk_queue_bounce_limit(sdev->request_queue, BLK_BOUNCE_HIGH);
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* We can't put these settings in slave_alloc() because that gets
|
2005-04-17 06:20:36 +08:00
|
|
|
* called before the device type is known. Consequently these
|
2016-04-18 18:09:11 +08:00
|
|
|
* settings can't be overridden via the scsi devinfo mechanism.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (sdev->type == TYPE_DISK) {
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some vendors seem to put the READ CAPACITY bug into
|
2008-12-19 05:41:49 +08:00
|
|
|
* 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
|
2016-04-18 18:09:11 +08:00
|
|
|
* flag unless told otherwise.
|
|
|
|
*/
|
2008-12-19 05:41:49 +08:00
|
|
|
switch (le16_to_cpu(us->pusb_dev->descriptor.idVendor)) {
|
|
|
|
case VENDOR_ID_NOKIA:
|
|
|
|
case VENDOR_ID_NIKON:
|
2009-02-05 04:48:03 +08:00
|
|
|
case VENDOR_ID_PENTAX:
|
2008-12-19 05:41:49 +08:00
|
|
|
case VENDOR_ID_MOTOROLA:
|
|
|
|
if (!(us->fflags & (US_FL_FIX_CAPACITY |
|
|
|
|
US_FL_CAPACITY_OK)))
|
|
|
|
us->fflags |= US_FL_CAPACITY_HEURISTICS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Disk-type devices use MODE SENSE(6) if the protocol
|
2005-04-17 06:20:36 +08:00
|
|
|
* (SubClass) is Transparent SCSI, otherwise they use
|
2016-04-18 18:09:11 +08:00
|
|
|
* MODE SENSE(10).
|
|
|
|
*/
|
2010-10-07 19:05:21 +08:00
|
|
|
if (us->subclass != USB_SC_SCSI && us->subclass != USB_SC_CYP_ATACB)
|
2005-04-17 06:20:36 +08:00
|
|
|
sdev->use_10_for_ms = 1;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
*Many disks only accept MODE SENSE transfer lengths of
|
|
|
|
* 192 bytes (that's what Windows uses).
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
sdev->use_192_bytes_for_3f = 1;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some devices don't like MODE SENSE with page=0x3f,
|
2005-04-17 06:20:36 +08:00
|
|
|
* 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
|
2016-04-18 18:09:11 +08:00
|
|
|
* devices are write-enabled.
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
if (us->fflags & US_FL_NO_WP_DETECT)
|
2005-04-17 06:20:36 +08:00
|
|
|
sdev->skip_ms_page_3f = 1;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* A number of devices have problems with MODE SENSE for
|
|
|
|
* page x08, so we will skip it.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
sdev->skip_ms_page_8 = 1;
|
|
|
|
|
2019-06-19 06:44:54 +08:00
|
|
|
/*
|
|
|
|
* Some devices don't handle VPD pages correctly, so skip vpd
|
|
|
|
* pages if not forced by SCSI layer.
|
|
|
|
*/
|
|
|
|
sdev->skip_vpd_pages = !sdev->try_vpd_pages;
|
2012-01-11 02:43:30 +08:00
|
|
|
|
2012-09-19 00:19:30 +08:00
|
|
|
/* Do not attempt to use REPORT SUPPORTED OPERATION CODES */
|
|
|
|
sdev->no_report_opcodes = 1;
|
|
|
|
|
2012-09-19 00:19:32 +08:00
|
|
|
/* Do not attempt to use WRITE SAME */
|
|
|
|
sdev->no_write_same = 1;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some disks return the total number of blocks in response
|
2005-04-17 06:20:36 +08:00
|
|
|
* to READ CAPACITY rather than the highest block number.
|
2016-04-18 18:09:11 +08:00
|
|
|
* If this device makes that mistake, tell the sd driver.
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
if (us->fflags & US_FL_FIX_CAPACITY)
|
2005-04-17 06:20:36 +08:00
|
|
|
sdev->fix_capacity = 1;
|
2005-06-07 08:22:42 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* A few disks have two indistinguishable version, one of
|
2007-02-08 16:04:48 +08:00
|
|
|
* which reports the correct capacity and the other does not.
|
2016-04-18 18:09:11 +08:00
|
|
|
* The sd driver has to guess which is the case.
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
if (us->fflags & US_FL_CAPACITY_HEURISTICS)
|
2007-02-08 16:04:48 +08:00
|
|
|
sdev->guess_capacity = 1;
|
|
|
|
|
2010-10-02 05:20:11 +08:00
|
|
|
/* Some devices cannot handle READ_CAPACITY_16 */
|
|
|
|
if (us->fflags & US_FL_NO_READ_CAPACITY_16)
|
|
|
|
sdev->no_read_capacity_16 = 1;
|
|
|
|
|
2012-06-21 04:04:19 +08:00
|
|
|
/*
|
|
|
|
* Many devices do not respond properly to READ_CAPACITY_16.
|
|
|
|
* Tell the SCSI layer to try READ_CAPACITY_10 first.
|
2013-10-14 21:24:55 +08:00
|
|
|
* However some USB 3.0 drive enclosures return capacity
|
|
|
|
* modulo 2TB. Those must use READ_CAPACITY_16
|
2012-06-21 04:04:19 +08:00
|
|
|
*/
|
2013-10-14 21:24:55 +08:00
|
|
|
if (!(us->fflags & US_FL_NEEDS_CAP16))
|
|
|
|
sdev->try_rc_10_first = 1;
|
2012-06-21 04:04:19 +08:00
|
|
|
|
2019-01-03 11:26:17 +08:00
|
|
|
/*
|
|
|
|
* assume SPC3 or latter devices support sense size > 18
|
|
|
|
* unless US_FL_BAD_SENSE quirk is specified.
|
|
|
|
*/
|
|
|
|
if (sdev->scsi_level > SCSI_SPC_2 &&
|
|
|
|
!(us->fflags & US_FL_BAD_SENSE))
|
2008-11-19 05:31:13 +08:00
|
|
|
us->fflags |= US_FL_SANE_SENSE;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* USB-IDE bridges tend to report SK = 0x04 (Non-recoverable
|
2005-06-07 08:22:42 +08:00
|
|
|
* 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
|
2016-04-18 18:09:11 +08:00
|
|
|
* is an occasional series of retries that will all fail.
|
|
|
|
*/
|
2005-06-07 08:22:42 +08:00
|
|
|
sdev->retry_hwerror = 1;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* USB disks should allow restart. Some drives spin down
|
|
|
|
* automatically, requiring a START-STOP UNIT command.
|
|
|
|
*/
|
2007-10-11 04:29:02 +08:00
|
|
|
sdev->allow_restart = 1;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some USB cardreaders have trouble reading an sdcard's last
|
2008-01-20 18:27:29 +08:00
|
|
|
* sector in a larger then 1 sector read, since the performance
|
2016-04-18 18:09:11 +08:00
|
|
|
* impact is negligible we set this flag for all USB disks
|
|
|
|
*/
|
2008-01-20 18:27:29 +08:00
|
|
|
sdev->last_sector_bug = 1;
|
USB: storage: add last-sector hacks
This patch (as1189b) adds some hacks to usb-storage for dealing with
the growing problems involving bad capacity values and last-sector
accesses:
A new flag, US_FL_CAPACITY_OK, is created to indicate that
the device is known to report its capacity correctly. An
unusual_devs entry for Linux's own File-backed Storage Gadget
is added with this flag set, since g_file_storage always
reports the correct capacity and since the capacity need
not be even (it is determined by the size of the backing
file).
An entry in unusual_devs.h which has only the CAPACITY_OK
flag set shouldn't prejudice libusual, since the device will
work perfectly well with either usb-storage or ub. So a
new macro, COMPLIANT_DEV, is added to let libusual know
about these entries.
When a last-sector access succeeds and the total number of
sectors is odd (the unexpected case, in which guessing that
the number is even might cause trouble), a WARN is triggered.
The kerneloops.org project will collect these warnings,
allowing us to add CAPACITY_OK flags for the devices in
question before implementing the default-to-even heuristic.
If users want to prevent the stack dump produced by the WARN,
they can disable the hack by adding an unusual_devs entry
for their device with the CAPACITY_OK flag.
When a last-sector access fails three times in a row and
neither the FIX_CAPACITY nor the CAPACITY_OK flag is set,
we assume the last-sector bug is present. We replace the
existing status and sense data with values that will cause
the SCSI core to fail the access immediately rather than
retry indefinitely. This should fix the difficulties
people have been having with Nokia phones.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-16 01:43:41 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Enable last-sector hacks for single-target devices using
|
USB: storage: add last-sector hacks
This patch (as1189b) adds some hacks to usb-storage for dealing with
the growing problems involving bad capacity values and last-sector
accesses:
A new flag, US_FL_CAPACITY_OK, is created to indicate that
the device is known to report its capacity correctly. An
unusual_devs entry for Linux's own File-backed Storage Gadget
is added with this flag set, since g_file_storage always
reports the correct capacity and since the capacity need
not be even (it is determined by the size of the backing
file).
An entry in unusual_devs.h which has only the CAPACITY_OK
flag set shouldn't prejudice libusual, since the device will
work perfectly well with either usb-storage or ub. So a
new macro, COMPLIANT_DEV, is added to let libusual know
about these entries.
When a last-sector access succeeds and the total number of
sectors is odd (the unexpected case, in which guessing that
the number is even might cause trouble), a WARN is triggered.
The kerneloops.org project will collect these warnings,
allowing us to add CAPACITY_OK flags for the devices in
question before implementing the default-to-even heuristic.
If users want to prevent the stack dump produced by the WARN,
they can disable the hack by adding an unusual_devs entry
for their device with the CAPACITY_OK flag.
When a last-sector access fails three times in a row and
neither the FIX_CAPACITY nor the CAPACITY_OK flag is set,
we assume the last-sector bug is present. We replace the
existing status and sense data with values that will cause
the SCSI core to fail the access immediately rather than
retry indefinitely. This should fix the difficulties
people have been having with Nokia phones.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-16 01:43:41 +08:00
|
|
|
* the Bulk-only transport, unless we already know the
|
2016-04-18 18:09:11 +08:00
|
|
|
* capacity will be decremented or is correct.
|
|
|
|
*/
|
USB: storage: add last-sector hacks
This patch (as1189b) adds some hacks to usb-storage for dealing with
the growing problems involving bad capacity values and last-sector
accesses:
A new flag, US_FL_CAPACITY_OK, is created to indicate that
the device is known to report its capacity correctly. An
unusual_devs entry for Linux's own File-backed Storage Gadget
is added with this flag set, since g_file_storage always
reports the correct capacity and since the capacity need
not be even (it is determined by the size of the backing
file).
An entry in unusual_devs.h which has only the CAPACITY_OK
flag set shouldn't prejudice libusual, since the device will
work perfectly well with either usb-storage or ub. So a
new macro, COMPLIANT_DEV, is added to let libusual know
about these entries.
When a last-sector access succeeds and the total number of
sectors is odd (the unexpected case, in which guessing that
the number is even might cause trouble), a WARN is triggered.
The kerneloops.org project will collect these warnings,
allowing us to add CAPACITY_OK flags for the devices in
question before implementing the default-to-even heuristic.
If users want to prevent the stack dump produced by the WARN,
they can disable the hack by adding an unusual_devs entry
for their device with the CAPACITY_OK flag.
When a last-sector access fails three times in a row and
neither the FIX_CAPACITY nor the CAPACITY_OK flag is set,
we assume the last-sector bug is present. We replace the
existing status and sense data with values that will cause
the SCSI core to fail the access immediately rather than
retry indefinitely. This should fix the difficulties
people have been having with Nokia phones.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-16 01:43:41 +08:00
|
|
|
if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK |
|
|
|
|
US_FL_SCM_MULT_TARG)) &&
|
2010-10-07 19:05:21 +08:00
|
|
|
us->protocol == USB_PR_BULK)
|
USB: storage: add last-sector hacks
This patch (as1189b) adds some hacks to usb-storage for dealing with
the growing problems involving bad capacity values and last-sector
accesses:
A new flag, US_FL_CAPACITY_OK, is created to indicate that
the device is known to report its capacity correctly. An
unusual_devs entry for Linux's own File-backed Storage Gadget
is added with this flag set, since g_file_storage always
reports the correct capacity and since the capacity need
not be even (it is determined by the size of the backing
file).
An entry in unusual_devs.h which has only the CAPACITY_OK
flag set shouldn't prejudice libusual, since the device will
work perfectly well with either usb-storage or ub. So a
new macro, COMPLIANT_DEV, is added to let libusual know
about these entries.
When a last-sector access succeeds and the total number of
sectors is odd (the unexpected case, in which guessing that
the number is even might cause trouble), a WARN is triggered.
The kerneloops.org project will collect these warnings,
allowing us to add CAPACITY_OK flags for the devices in
question before implementing the default-to-even heuristic.
If users want to prevent the stack dump produced by the WARN,
they can disable the hack by adding an unusual_devs entry
for their device with the CAPACITY_OK flag.
When a last-sector access fails three times in a row and
neither the FIX_CAPACITY nor the CAPACITY_OK flag is set,
we assume the last-sector bug is present. We replace the
existing status and sense data with values that will cause
the SCSI core to fail the access immediately rather than
retry indefinitely. This should fix the difficulties
people have been having with Nokia phones.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-16 01:43:41 +08:00
|
|
|
us->use_last_sector_hacks = 1;
|
2012-07-08 11:05:28 +08:00
|
|
|
|
|
|
|
/* Check if write cache default on flag is set or not */
|
|
|
|
if (us->fflags & US_FL_WRITE_CACHE)
|
|
|
|
sdev->wce_default_on = 1;
|
|
|
|
|
2014-06-30 23:04:21 +08:00
|
|
|
/* A few buggy USB-ATA bridges don't understand FUA */
|
|
|
|
if (us->fflags & US_FL_BROKEN_FUA)
|
|
|
|
sdev->broken_fua = 1;
|
|
|
|
|
2016-09-12 21:19:41 +08:00
|
|
|
/* Some even totally fail to indicate a cache */
|
|
|
|
if (us->fflags & US_FL_ALWAYS_SYNC) {
|
|
|
|
/* don't read caching information */
|
|
|
|
sdev->skip_ms_page_8 = 1;
|
|
|
|
sdev->skip_ms_page_3f = 1;
|
|
|
|
/* assume sync is needed */
|
|
|
|
sdev->wce_default_on = 1;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Non-disk-type devices don't need to blacklist any pages
|
2005-04-17 06:20:36 +08:00
|
|
|
* or to force 192-byte transfer lengths for MODE SENSE.
|
2016-04-18 18:09:11 +08:00
|
|
|
* But they do need to use MODE SENSE(10).
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
sdev->use_10_for_ms = 1;
|
2010-10-02 05:20:10 +08:00
|
|
|
|
|
|
|
/* Some (fake) usb cdrom devices don't like READ_DISC_INFO */
|
|
|
|
if (us->fflags & US_FL_NO_READ_DISC_INFO)
|
|
|
|
sdev->no_read_disc_info = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* The CB and CBI transports have no way to pass LUN values
|
2007-01-09 05:18:05 +08:00
|
|
|
* 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
|
|
|
|
* be single-LUN.
|
|
|
|
*/
|
2010-10-07 19:05:21 +08:00
|
|
|
if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_CBI) &&
|
2007-01-09 05:18:05 +08:00
|
|
|
sdev->scsi_level == SCSI_UNKNOWN)
|
|
|
|
us->max_lun = 0;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some devices choke when they receive a PREVENT-ALLOW MEDIUM
|
|
|
|
* REMOVAL command, so suppress those commands.
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
if (us->fflags & US_FL_NOT_LOCKABLE)
|
2005-04-17 06:20:36 +08:00
|
|
|
sdev->lockable = 0;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* this is to satisfy the compiler, tho I don't think the
|
|
|
|
* return code is ever checked anywhere.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-11 02:43:30 +08:00
|
|
|
static int target_alloc(struct scsi_target *starget)
|
|
|
|
{
|
2012-01-11 02:43:40 +08:00
|
|
|
struct us_data *us = host_to_us(dev_to_shost(starget->dev.parent));
|
|
|
|
|
2012-01-11 02:43:30 +08:00
|
|
|
/*
|
|
|
|
* Some USB drives don't support REPORT LUNS, even though they
|
|
|
|
* report a SCSI revision level above 2. Tell the SCSI layer
|
|
|
|
* not to issue that command; it will perform a normal sequential
|
|
|
|
* scan instead.
|
|
|
|
*/
|
|
|
|
starget->no_report_luns = 1;
|
2012-01-11 02:43:40 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The UFI spec treats the Peripheral Qualifier bits in an
|
|
|
|
* INQUIRY result as reserved and requires devices to set them
|
|
|
|
* to 0. However the SCSI spec requires these bits to be set
|
|
|
|
* to 3 to indicate when a LUN is not present.
|
|
|
|
*
|
|
|
|
* Let the scanning code know if this target merely sets
|
|
|
|
* Peripheral Device Type to 0x1f to indicate no LUN.
|
|
|
|
*/
|
|
|
|
if (us->subclass == USB_SC_UFI)
|
|
|
|
starget->pdt_1f_for_no_lun = 1;
|
|
|
|
|
2012-01-11 02:43:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* queue a command */
|
|
|
|
/* This is always called with scsi_lock(host) held */
|
2010-11-16 15:10:29 +08:00
|
|
|
static int queuecommand_lck(struct scsi_cmnd *srb,
|
2005-04-17 06:20:36 +08:00
|
|
|
void (*done)(struct scsi_cmnd *))
|
|
|
|
{
|
|
|
|
struct us_data *us = host_to_us(srb->device->host);
|
|
|
|
|
|
|
|
/* check for state-transition errors */
|
|
|
|
if (us->srb != NULL) {
|
2019-10-02 19:03:12 +08:00
|
|
|
dev_err(&us->pusb_intf->dev,
|
|
|
|
"Error in %s: us->srb = %p\n", __func__, us->srb);
|
2005-04-17 06:20:36 +08:00
|
|
|
return SCSI_MLQUEUE_HOST_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fail the command if we are disconnecting */
|
2008-05-02 03:35:18 +08:00
|
|
|
if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Fail command during disconnect\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
srb->result = DID_NO_CONNECT << 16;
|
|
|
|
done(srb);
|
|
|
|
return 0;
|
2018-08-10 05:55:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((us->fflags & US_FL_NO_ATA_1X) &&
|
|
|
|
(srb->cmnd[0] == ATA_12 || srb->cmnd[0] == ATA_16)) {
|
|
|
|
memcpy(srb->sense_buffer, usb_stor_sense_invalidCDB,
|
|
|
|
sizeof(usb_stor_sense_invalidCDB));
|
|
|
|
srb->result = SAM_STAT_CHECK_CONDITION;
|
|
|
|
done(srb);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* enqueue the command and wake up the control thread */
|
|
|
|
srb->scsi_done = done;
|
|
|
|
us->srb = srb;
|
2008-05-02 03:36:13 +08:00
|
|
|
complete(&us->cmnd_ready);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-16 15:10:29 +08:00
|
|
|
static DEF_SCSI_QCMD(queuecommand)
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/***********************************************************************
|
|
|
|
* Error handling functions
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
/* Command timeout and abort */
|
|
|
|
static int command_abort(struct scsi_cmnd *srb)
|
|
|
|
{
|
|
|
|
struct us_data *us = host_to_us(srb->device->host);
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "%s called\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* us->srb together with the TIMED_OUT, RESETTING, and ABORTING
|
|
|
|
* bits are protected by the host lock.
|
|
|
|
*/
|
2005-08-26 11:03:50 +08:00
|
|
|
scsi_lock(us_to_host(us));
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Is this command still active? */
|
|
|
|
if (us->srb != srb) {
|
2005-08-26 11:03:50 +08:00
|
|
|
scsi_unlock(us_to_host(us));
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- nothing to abort\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Set the TIMED_OUT bit. Also set the ABORTING bit, but only if
|
2005-04-17 06:20:36 +08:00
|
|
|
* a device reset isn't already in progress (to avoid interfering
|
2005-08-26 11:03:50 +08:00
|
|
|
* with the reset). Note that we must retain the host lock while
|
|
|
|
* calling usb_stor_stop_transport(); otherwise it might interfere
|
2016-04-18 18:09:11 +08:00
|
|
|
* with an auto-reset that begins as soon as we release the lock.
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
set_bit(US_FLIDX_TIMED_OUT, &us->dflags);
|
|
|
|
if (!test_bit(US_FLIDX_RESETTING, &us->dflags)) {
|
|
|
|
set_bit(US_FLIDX_ABORTING, &us->dflags);
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_stor_stop_transport(us);
|
|
|
|
}
|
2005-08-26 11:03:50 +08:00
|
|
|
scsi_unlock(us_to_host(us));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Wait for the aborted command to finish */
|
|
|
|
wait_for_completion(&us->notify);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* This invokes the transport reset mechanism to reset the state of the
|
|
|
|
* device
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int device_reset(struct scsi_cmnd *srb)
|
|
|
|
{
|
|
|
|
struct us_data *us = host_to_us(srb->device->host);
|
|
|
|
int result;
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "%s called\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-09-13 21:01:24 +08:00
|
|
|
/* lock the device pointers and do the reset */
|
|
|
|
mutex_lock(&(us->dev_mutex));
|
|
|
|
result = us->transport_reset(us);
|
|
|
|
mutex_unlock(&us->dev_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-07 08:21:41 +08:00
|
|
|
return result < 0 ? FAILED : SUCCESS;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-06-07 08:21:41 +08:00
|
|
|
/* Simulate a SCSI bus reset by resetting the device's USB port. */
|
2005-04-17 06:20:36 +08:00
|
|
|
static int bus_reset(struct scsi_cmnd *srb)
|
|
|
|
{
|
|
|
|
struct us_data *us = host_to_us(srb->device->host);
|
2005-06-07 08:21:41 +08:00
|
|
|
int result;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "%s called\n", __func__);
|
|
|
|
|
2005-06-07 08:21:41 +08:00
|
|
|
result = usb_stor_port_reset(us);
|
2005-04-17 06:20:36 +08:00
|
|
|
return result < 0 ? FAILED : SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Report a driver-initiated device reset to the SCSI layer.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Calling this for a SCSI-initiated reset is unnecessary but harmless.
|
2016-04-18 18:09:11 +08:00
|
|
|
* The caller must own the SCSI host lock.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
void usb_stor_report_device_reset(struct us_data *us)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct Scsi_Host *host = us_to_host(us);
|
|
|
|
|
|
|
|
scsi_report_device_reset(host, 0, 0);
|
2008-05-02 03:35:18 +08:00
|
|
|
if (us->fflags & US_FL_SCM_MULT_TARG) {
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 1; i < host->max_id; ++i)
|
|
|
|
scsi_report_device_reset(host, 0, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Report a driver-initiated bus reset to the SCSI layer.
|
2005-06-07 08:21:41 +08:00
|
|
|
* Calling this for a SCSI-initiated reset is unnecessary but harmless.
|
2016-04-18 18:09:11 +08:00
|
|
|
* The caller must not own the SCSI host lock.
|
|
|
|
*/
|
2005-06-07 08:21:41 +08:00
|
|
|
void usb_stor_report_bus_reset(struct us_data *us)
|
|
|
|
{
|
2007-05-31 03:38:16 +08:00
|
|
|
struct Scsi_Host *host = us_to_host(us);
|
|
|
|
|
|
|
|
scsi_lock(host);
|
|
|
|
scsi_report_bus_reset(host, 0);
|
|
|
|
scsi_unlock(host);
|
2005-06-07 08:21:41 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/***********************************************************************
|
|
|
|
* /proc/scsi/ functions
|
|
|
|
***********************************************************************/
|
|
|
|
|
2013-03-31 13:37:13 +08:00
|
|
|
static int write_info(struct Scsi_Host *host, char *buffer, int length)
|
|
|
|
{
|
|
|
|
/* if someone is sending us data, just throw it away */
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int show_info (struct seq_file *m, struct Scsi_Host *host)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct us_data *us = host_to_us(host);
|
|
|
|
const char *string;
|
|
|
|
|
|
|
|
/* print the controller name */
|
2015-04-19 10:59:48 +08:00
|
|
|
seq_printf(m, " Host scsi%d: usb-storage\n", host->host_no);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* print product, vendor, and serial number strings */
|
|
|
|
if (us->pusb_dev->manufacturer)
|
|
|
|
string = us->pusb_dev->manufacturer;
|
|
|
|
else if (us->unusual_dev->vendorName)
|
|
|
|
string = us->unusual_dev->vendorName;
|
|
|
|
else
|
|
|
|
string = "Unknown";
|
2015-04-19 10:59:48 +08:00
|
|
|
seq_printf(m, " Vendor: %s\n", string);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (us->pusb_dev->product)
|
|
|
|
string = us->pusb_dev->product;
|
|
|
|
else if (us->unusual_dev->productName)
|
|
|
|
string = us->unusual_dev->productName;
|
|
|
|
else
|
|
|
|
string = "Unknown";
|
2015-04-19 10:59:48 +08:00
|
|
|
seq_printf(m, " Product: %s\n", string);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (us->pusb_dev->serial)
|
|
|
|
string = us->pusb_dev->serial;
|
|
|
|
else
|
|
|
|
string = "None";
|
2015-04-19 10:59:48 +08:00
|
|
|
seq_printf(m, "Serial Number: %s\n", string);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* show the protocol and transport */
|
2015-04-19 10:59:48 +08:00
|
|
|
seq_printf(m, " Protocol: %s\n", us->protocol_name);
|
|
|
|
seq_printf(m, " Transport: %s\n", us->transport_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* show the device flags */
|
2015-04-19 10:59:48 +08:00
|
|
|
seq_printf(m, " Quirks:");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define US_FLAG(name, value) \
|
2013-03-31 13:37:13 +08:00
|
|
|
if (us->fflags & value) seq_printf(m, " " #name);
|
2005-04-17 06:20:36 +08:00
|
|
|
US_DO_ALL_FLAGS
|
|
|
|
#undef US_FLAG
|
2013-03-31 13:37:13 +08:00
|
|
|
seq_putc(m, '\n');
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Sysfs interface
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
/* Output routine for the sysfs max_sectors file */
|
2013-08-28 04:13:07 +08:00
|
|
|
static ssize_t max_sectors_show(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct scsi_device *sdev = to_scsi_device(dev);
|
|
|
|
|
2010-02-27 00:49:39 +08:00
|
|
|
return sprintf(buf, "%u\n", queue_max_hw_sectors(sdev->request_queue));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Input routine for the sysfs max_sectors file */
|
2013-08-28 04:13:07 +08:00
|
|
|
static ssize_t max_sectors_store(struct device *dev, struct device_attribute *attr, const char *buf,
|
2005-04-17 06:20:36 +08:00
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev = to_scsi_device(dev);
|
|
|
|
unsigned short ms;
|
|
|
|
|
2010-02-27 00:49:39 +08:00
|
|
|
if (sscanf(buf, "%hu", &ms) > 0) {
|
2010-02-26 13:20:38 +08:00
|
|
|
blk_queue_max_hw_sectors(sdev->request_queue, ms);
|
2010-02-27 00:49:39 +08:00
|
|
|
return count;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2013-08-28 04:13:07 +08:00
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2013-08-28 04:13:07 +08:00
|
|
|
static DEVICE_ATTR_RW(max_sectors);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct device_attribute *sysfs_device_attr_list[] = {
|
2013-08-28 04:13:07 +08:00
|
|
|
&dev_attr_max_sectors,
|
|
|
|
NULL,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* this defines our host template, with which we'll allocate hosts
|
|
|
|
*/
|
|
|
|
|
2015-05-06 17:24:21 +08:00
|
|
|
static const struct scsi_host_template usb_stor_host_template = {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* basic userland interface stuff */
|
|
|
|
.name = "usb-storage",
|
|
|
|
.proc_name = "usb-storage",
|
2013-03-31 13:37:13 +08:00
|
|
|
.show_info = show_info,
|
|
|
|
.write_info = write_info,
|
2005-04-17 06:20:36 +08:00
|
|
|
.info = host_info,
|
|
|
|
|
|
|
|
/* command interface -- queued only */
|
|
|
|
.queuecommand = queuecommand,
|
|
|
|
|
|
|
|
/* error and abort handlers */
|
|
|
|
.eh_abort_handler = command_abort,
|
|
|
|
.eh_device_reset_handler = device_reset,
|
|
|
|
.eh_bus_reset_handler = bus_reset,
|
|
|
|
|
|
|
|
/* queue commands only, only one command per LUN */
|
|
|
|
.can_queue = 1,
|
|
|
|
|
|
|
|
/* unknown initiator id */
|
|
|
|
.this_id = -1,
|
|
|
|
|
|
|
|
.slave_alloc = slave_alloc,
|
|
|
|
.slave_configure = slave_configure,
|
2012-01-11 02:43:30 +08:00
|
|
|
.target_alloc = target_alloc,
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* lots of sg segments can be handled */
|
2016-04-05 05:48:10 +08:00
|
|
|
.sg_tablesize = SG_MAX_SEGMENTS,
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-04-18 18:09:09 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
.max_sectors = 240,
|
|
|
|
|
|
|
|
/* emulated HBA */
|
|
|
|
.emulated = 1,
|
|
|
|
|
|
|
|
/* we do our own delay after a device or bus reset */
|
|
|
|
.skip_settle_delay = 1,
|
|
|
|
|
|
|
|
/* sysfs device attributes */
|
|
|
|
.sdev_attrs = sysfs_device_attr_list,
|
|
|
|
|
|
|
|
/* module management */
|
|
|
|
.module = THIS_MODULE
|
|
|
|
};
|
|
|
|
|
2015-05-06 17:24:21 +08:00
|
|
|
void usb_stor_host_template_init(struct scsi_host_template *sht,
|
|
|
|
const char *name, struct module *owner)
|
|
|
|
{
|
|
|
|
*sht = usb_stor_host_template;
|
|
|
|
sht->name = name;
|
|
|
|
sht->proc_name = name;
|
|
|
|
sht->module = owner;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usb_stor_host_template_init);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* To Report "Illegal Request: Invalid Field in CDB */
|
|
|
|
unsigned char usb_stor_sense_invalidCDB[18] = {
|
|
|
|
[0] = 0x70, /* current error */
|
|
|
|
[2] = ILLEGAL_REQUEST, /* Illegal Request = 0x05 */
|
|
|
|
[7] = 0x0a, /* additional length */
|
|
|
|
[12] = 0x24 /* Invalid Field in CDB */
|
|
|
|
};
|
usb-storage: prepare for subdriver separation
This patch (as1206) is the first step in converting usb-storage's
subdrivers into separate modules. It makes the following large-scale
changes:
Remove a bunch of unnecessary #ifdef's from usb_usual.h.
Not truly necessary, but it does clean things up.
Move the USB device-ID table (which is duplicated between
libusual and usb-storage) into its own source file,
usual-tables.c, and arrange for this to be linked with
either libusual or usb-storage according to whether
USB_LIBUSUAL is configured.
Add to usual-tables.c a new usb_usual_ignore_device()
function to detect whether a particular device needs to be
managed by a subdriver and not by the standard handlers
in usb-storage.
Export a whole bunch of functions in usb-storage, renaming
some of them because their names don't already begin with
"usb_stor_". These functions will be needed by the new
subdriver modules.
Split usb-storage's probe routine into two functions.
The subdrivers will call the probe1 routine, then fill in
their transport and protocol settings, and then call the
probe2 routine.
Take the default cases and error checking out of
get_transport() and get_protocol(), which run during
probe1, and instead put a check for invalid transport
or protocol values into the probe2 function.
Add a new probe routine to be used for standard devices,
i.e., those that don't need a subdriver. This new routine
checks whether the device should be ignored (because it
should be handled by ub or by a subdriver), and if not,
calls the probe1 and probe2 functions.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-02-13 03:47:44 +08:00
|
|
|
EXPORT_SYMBOL_GPL(usb_stor_sense_invalidCDB);
|