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
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
* (c) 2002 Alan Stern <stern@rowland.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
|
|
|
|
* information about this driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/errno.h>
|
2011-05-27 21:56:31 +08:00
|
|
|
#include <linux/export.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-12-18 19:14:21 +08:00
|
|
|
#include <linux/usb/quirks.h>
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <scsi/scsi.h>
|
2007-09-11 03:36:31 +08:00
|
|
|
#include <scsi/scsi_eh.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <scsi/scsi_device.h>
|
|
|
|
|
|
|
|
#include "usb.h"
|
|
|
|
#include "transport.h"
|
|
|
|
#include "protocol.h"
|
|
|
|
#include "scsiglue.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
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
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include "../../scsi/sd.h"
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Data transfer routines
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is subtle, so pay attention:
|
|
|
|
* ---------------------------------
|
|
|
|
* We're very concerned about races with a command abort. Hanging this code
|
|
|
|
* is a sure fire way to hang the kernel. (Note that this discussion applies
|
|
|
|
* only to transactions resulting from a scsi queued-command, since only
|
|
|
|
* these transactions are subject to a scsi abort. Other transactions, such
|
|
|
|
* as those occurring during device-specific initialization, must be handled
|
|
|
|
* by a separate code path.)
|
|
|
|
*
|
|
|
|
* The abort function (usb_storage_command_abort() in scsiglue.c) first
|
2008-05-02 03:35:18 +08:00
|
|
|
* sets the machine state and the ABORTING bit in us->dflags to prevent
|
2005-04-17 06:20:36 +08:00
|
|
|
* new URBs from being submitted. It then calls usb_stor_stop_transport()
|
2008-05-02 03:35:18 +08:00
|
|
|
* below, which atomically tests-and-clears the URB_ACTIVE bit in us->dflags
|
2005-04-17 06:20:36 +08:00
|
|
|
* to see if the current_urb needs to be stopped. Likewise, the SG_ACTIVE
|
|
|
|
* bit is tested to see if the current_sg scatter-gather request needs to be
|
|
|
|
* stopped. The timeout callback routine does much the same thing.
|
|
|
|
*
|
2008-05-02 03:35:18 +08:00
|
|
|
* When a disconnect occurs, the DISCONNECTING bit in us->dflags is set to
|
2005-04-17 06:20:36 +08:00
|
|
|
* prevent new URBs from being submitted, and usb_stor_stop_transport() is
|
|
|
|
* called to stop any ongoing requests.
|
|
|
|
*
|
|
|
|
* The submit function first verifies that the submitting is allowed
|
|
|
|
* (neither ABORTING nor DISCONNECTING bits are set) and that the submit
|
|
|
|
* completes without errors, and only then sets the URB_ACTIVE bit. This
|
|
|
|
* prevents the stop_transport() function from trying to cancel the URB
|
|
|
|
* while the submit call is underway. Next, the submit function must test
|
|
|
|
* the flags to see if an abort or disconnect occurred during the submission
|
|
|
|
* or before the URB_ACTIVE bit was set. If so, it's essential to cancel
|
|
|
|
* the URB if it hasn't been cancelled already (i.e., if the URB_ACTIVE bit
|
|
|
|
* is still set). Either way, the function must then wait for the URB to
|
[PATCH] USB: URB_ASYNC_UNLINK flag removed from the kernel
29 July 2005, Cambridge, MA:
This afternoon Alan Stern submitted a patch to remove the URB_ASYNC_UNLINK
flag from the Linux kernel. Mr. Stern explained, "This flag is a relic
from an earlier, less-well-designed system. For over a year it hasn't
been used for anything other than printing warning messages."
An anonymous spokesman for the Linux kernel development community
commented, "This is exactly the sort of thing we see happening all the
time. As the kernel evolves, support for old techniques and old code can
be jettisoned and replaced by newer, better approaches. Proprietary
operating systems do not have the freedom or flexibility to change so
quickly."
Mr. Stern, a staff member at Harvard University's Rowland Institute who
works on Linux only as a hobby, noted that the patch (labelled as548) did
not update two files, keyspan.c and option.c, in the USB drivers' "serial"
subdirectory. "Those files need more extensive changes," he remarked.
"They examine the status field of several URBs at times when they're not
supposed to. That will need to be fixed before the URB_ASYNC_UNLINK flag
is removed."
Greg Kroah-Hartman, the kernel maintainer responsible for overseeing all
of Linux's USB drivers, did not respond to our inquiries or return our
calls. His only comment was "Applied, thanks."
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-07-30 04:11:07 +08:00
|
|
|
* finish. Note that the URB can still be in progress even after a call to
|
|
|
|
* usb_unlink_urb() returns.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* The idea is that (1) once the ABORTING or DISCONNECTING bit is set,
|
|
|
|
* either the stop_transport() function or the submitting function
|
|
|
|
* is guaranteed to call usb_unlink_urb() for an active URB,
|
|
|
|
* and (2) test_and_clear_bit() prevents usb_unlink_urb() from being
|
|
|
|
* called more than once or from being called during usb_submit_urb().
|
|
|
|
*/
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* This is the completion handler which will wake us up when an URB
|
2005-04-17 06:20:36 +08:00
|
|
|
* completes.
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static void usb_stor_blocking_completion(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-24 18:41:47 +08:00
|
|
|
struct completion *urb_done_ptr = urb->context;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
complete(urb_done_ptr);
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* This is the common part of the URB message submission code
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* All URBs from the usb-storage driver involved in handling a queued scsi
|
|
|
|
* command _must_ pass through this function (or something like it) for the
|
|
|
|
* abort mechanisms to work properly.
|
|
|
|
*/
|
|
|
|
static int usb_stor_msg_common(struct us_data *us, int timeout)
|
|
|
|
{
|
|
|
|
struct completion urb_done;
|
2006-05-24 22:57:28 +08:00
|
|
|
long timeleft;
|
2005-04-17 06:20:36 +08:00
|
|
|
int status;
|
|
|
|
|
2008-05-08 23:55:59 +08:00
|
|
|
/* don't submit URBs during abort processing */
|
|
|
|
if (test_bit(US_FLIDX_ABORTING, &us->dflags))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* set up data structures for the wakeup system */
|
|
|
|
init_completion(&urb_done);
|
|
|
|
|
|
|
|
/* fill the common fields in the URB */
|
|
|
|
us->current_urb->context = &urb_done;
|
2010-07-12 23:18:18 +08:00
|
|
|
us->current_urb->transfer_flags = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* we assume that if transfer_buffer isn't us->iobuf then it
|
2005-04-17 06:20:36 +08:00
|
|
|
* hasn't been mapped for DMA. Yes, this is clunky, but it's
|
|
|
|
* easier than always having the caller tell us whether the
|
2016-04-18 18:09:11 +08:00
|
|
|
* transfer buffer has already been mapped.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (us->current_urb->transfer_buffer == us->iobuf)
|
|
|
|
us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
|
|
|
us->current_urb->transfer_dma = us->iobuf_dma;
|
|
|
|
|
|
|
|
/* submit the URB */
|
|
|
|
status = usb_submit_urb(us->current_urb, GFP_NOIO);
|
|
|
|
if (status) {
|
|
|
|
/* something went wrong */
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* since the URB has been submitted successfully, it's now okay
|
|
|
|
* to cancel it
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
set_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-05-08 23:55:59 +08:00
|
|
|
/* did an abort occur during the submission? */
|
|
|
|
if (test_bit(US_FLIDX_ABORTING, &us->dflags)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* cancel the URB, if it hasn't been cancelled already */
|
2008-05-02 03:35:18 +08:00
|
|
|
if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- cancelling URB\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_unlink_urb(us->current_urb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for the completion of the URB */
|
2006-05-24 22:57:28 +08:00
|
|
|
timeleft = wait_for_completion_interruptible_timeout(
|
|
|
|
&urb_done, timeout ? : MAX_SCHEDULE_TIMEOUT);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-05-02 03:35:18 +08:00
|
|
|
clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
|
2006-05-24 22:57:28 +08:00
|
|
|
|
|
|
|
if (timeleft <= 0) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "%s -- cancelling URB\n",
|
|
|
|
timeleft == 0 ? "Timeout" : "Signal");
|
2006-07-10 19:44:47 +08:00
|
|
|
usb_kill_urb(us->current_urb);
|
2006-05-24 22:57:28 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* return the URB status */
|
|
|
|
return us->current_urb->status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer one control message, with timeouts, and allowing early
|
|
|
|
* termination. Return codes are usual -Exxx, *not* USB_STOR_XFER_xxx.
|
|
|
|
*/
|
|
|
|
int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
|
|
|
|
u8 request, u8 requesttype, u16 value, u16 index,
|
|
|
|
void *data, u16 size, int timeout)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n",
|
|
|
|
request, requesttype, value, index, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* fill in the devrequest structure */
|
|
|
|
us->cr->bRequestType = requesttype;
|
|
|
|
us->cr->bRequest = request;
|
|
|
|
us->cr->wValue = cpu_to_le16(value);
|
|
|
|
us->cr->wIndex = cpu_to_le16(index);
|
|
|
|
us->cr->wLength = cpu_to_le16(size);
|
|
|
|
|
|
|
|
/* fill and submit the URB */
|
|
|
|
usb_fill_control_urb(us->current_urb, us->pusb_dev, pipe,
|
|
|
|
(unsigned char*) us->cr, data, size,
|
|
|
|
usb_stor_blocking_completion, NULL);
|
|
|
|
status = usb_stor_msg_common(us, timeout);
|
|
|
|
|
|
|
|
/* return the actual length of the data transferred if no error */
|
|
|
|
if (status == 0)
|
|
|
|
status = us->current_urb->actual_length;
|
|
|
|
return status;
|
|
|
|
}
|
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_control_msg);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* This is a version of usb_clear_halt() that allows early termination and
|
2005-04-17 06:20:36 +08:00
|
|
|
* doesn't read the status from the device -- this is because some devices
|
|
|
|
* crash their internal firmware when the status is requested after a halt.
|
|
|
|
*
|
|
|
|
* A definitive list of these 'bad' devices is too difficult to maintain or
|
|
|
|
* make complete enough to be useful. This problem was first observed on the
|
|
|
|
* Hagiwara FlashGate DUAL unit. However, bus traces reveal that neither
|
|
|
|
* MacOS nor Windows checks the status after clearing a halt.
|
|
|
|
*
|
|
|
|
* Since many vendors in this space limit their testing to interoperability
|
|
|
|
* with these two OSes, specification violations like this one are common.
|
|
|
|
*/
|
|
|
|
int usb_stor_clear_halt(struct us_data *us, unsigned int pipe)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
int endp = usb_pipeendpoint(pipe);
|
|
|
|
|
|
|
|
if (usb_pipein (pipe))
|
|
|
|
endp |= USB_DIR_IN;
|
|
|
|
|
|
|
|
result = usb_stor_control_msg(us, us->send_ctrl_pipe,
|
|
|
|
USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT,
|
|
|
|
USB_ENDPOINT_HALT, endp,
|
|
|
|
NULL, 0, 3*HZ);
|
|
|
|
|
2005-06-07 08:19:29 +08:00
|
|
|
if (result >= 0)
|
2009-04-09 01:36:28 +08:00
|
|
|
usb_reset_endpoint(us->pusb_dev, endp);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "result = %d\n", result);
|
2005-04-17 06:20:36 +08:00
|
|
|
return result;
|
|
|
|
}
|
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_clear_halt);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interpret the results of a URB transfer
|
|
|
|
*
|
|
|
|
* This function prints appropriate debugging messages, clears halts on
|
|
|
|
* non-control endpoints, and translates the status to the corresponding
|
|
|
|
* USB_STOR_XFER_xxx return code.
|
|
|
|
*/
|
|
|
|
static int interpret_urb_result(struct us_data *us, unsigned int pipe,
|
|
|
|
unsigned int length, int result, unsigned int partial)
|
|
|
|
{
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Status code %d; transferred %u/%u\n",
|
|
|
|
result, partial, length);
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (result) {
|
|
|
|
|
|
|
|
/* no error code; did we send all the data? */
|
|
|
|
case 0:
|
|
|
|
if (partial != length) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- short transfer\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_SHORT;
|
|
|
|
}
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- transfer complete\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_GOOD;
|
|
|
|
|
|
|
|
/* stalled */
|
|
|
|
case -EPIPE:
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* for control endpoints, (used by CB[I]) a stall indicates
|
|
|
|
* a failed command
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (usb_pipecontrol(pipe)) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- stall on control pipe\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_STALLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for other sorts of endpoint, clear the stall */
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "clearing endpoint halt for pipe 0x%x\n",
|
|
|
|
pipe);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (usb_stor_clear_halt(us, pipe) < 0)
|
|
|
|
return USB_STOR_XFER_ERROR;
|
|
|
|
return USB_STOR_XFER_STALLED;
|
|
|
|
|
|
|
|
/* babble - the device tried to send more than we wanted to read */
|
|
|
|
case -EOVERFLOW:
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- babble\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_LONG;
|
|
|
|
|
|
|
|
/* the transfer was cancelled by abort, disconnect, or timeout */
|
|
|
|
case -ECONNRESET:
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- transfer cancelled\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_ERROR;
|
|
|
|
|
|
|
|
/* short scatter-gather read transfer */
|
|
|
|
case -EREMOTEIO:
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- short read transfer\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_SHORT;
|
|
|
|
|
|
|
|
/* abort or disconnect in progress */
|
|
|
|
case -EIO:
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- abort or disconnect in progress\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_ERROR;
|
|
|
|
|
|
|
|
/* the catch-all error case */
|
|
|
|
default:
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- unknown error\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer one control message, without timeouts, but allowing early
|
|
|
|
* termination. Return codes are USB_STOR_XFER_xxx.
|
|
|
|
*/
|
|
|
|
int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
|
|
|
|
u8 request, u8 requesttype, u16 value, u16 index,
|
|
|
|
void *data, u16 size)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n",
|
|
|
|
request, requesttype, value, index, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* fill in the devrequest structure */
|
|
|
|
us->cr->bRequestType = requesttype;
|
|
|
|
us->cr->bRequest = request;
|
|
|
|
us->cr->wValue = cpu_to_le16(value);
|
|
|
|
us->cr->wIndex = cpu_to_le16(index);
|
|
|
|
us->cr->wLength = cpu_to_le16(size);
|
|
|
|
|
|
|
|
/* fill and submit the URB */
|
|
|
|
usb_fill_control_urb(us->current_urb, us->pusb_dev, pipe,
|
|
|
|
(unsigned char*) us->cr, data, size,
|
|
|
|
usb_stor_blocking_completion, NULL);
|
|
|
|
result = usb_stor_msg_common(us, 0);
|
|
|
|
|
|
|
|
return interpret_urb_result(us, pipe, size, result,
|
|
|
|
us->current_urb->actual_length);
|
|
|
|
}
|
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_ctrl_transfer);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive one interrupt buffer, without timeouts, but allowing early
|
|
|
|
* termination. Return codes are USB_STOR_XFER_xxx.
|
|
|
|
*
|
|
|
|
* This routine always uses us->recv_intr_pipe as the pipe and
|
|
|
|
* us->ep_bInterval as the interrupt interval.
|
|
|
|
*/
|
|
|
|
static int usb_stor_intr_transfer(struct us_data *us, void *buf,
|
|
|
|
unsigned int length)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
unsigned int pipe = us->recv_intr_pipe;
|
|
|
|
unsigned int maxp;
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "xfer %u bytes\n", length);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* calculate the max packet size */
|
|
|
|
maxp = usb_maxpacket(us->pusb_dev, pipe, usb_pipeout(pipe));
|
|
|
|
if (maxp > length)
|
|
|
|
maxp = length;
|
|
|
|
|
|
|
|
/* fill and submit the URB */
|
|
|
|
usb_fill_int_urb(us->current_urb, us->pusb_dev, pipe, buf,
|
|
|
|
maxp, usb_stor_blocking_completion, NULL,
|
|
|
|
us->ep_bInterval);
|
|
|
|
result = usb_stor_msg_common(us, 0);
|
|
|
|
|
|
|
|
return interpret_urb_result(us, pipe, length, result,
|
|
|
|
us->current_urb->actual_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer one buffer via bulk pipe, without timeouts, but allowing early
|
|
|
|
* termination. Return codes are USB_STOR_XFER_xxx. If the bulk pipe
|
|
|
|
* stalls during the transfer, the halt is automatically cleared.
|
|
|
|
*/
|
|
|
|
int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
|
|
|
|
void *buf, unsigned int length, unsigned int *act_len)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "xfer %u bytes\n", length);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* fill and submit the URB */
|
|
|
|
usb_fill_bulk_urb(us->current_urb, us->pusb_dev, pipe, buf, length,
|
|
|
|
usb_stor_blocking_completion, NULL);
|
|
|
|
result = usb_stor_msg_common(us, 0);
|
|
|
|
|
|
|
|
/* store the actual length of the data transferred */
|
|
|
|
if (act_len)
|
|
|
|
*act_len = us->current_urb->actual_length;
|
|
|
|
return interpret_urb_result(us, pipe, length, result,
|
|
|
|
us->current_urb->actual_length);
|
|
|
|
}
|
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_bulk_transfer_buf);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer a scatter-gather list via bulk transfer
|
|
|
|
*
|
|
|
|
* This function does basically the same thing as usb_stor_bulk_transfer_buf()
|
|
|
|
* above, but it uses the usbcore scatter-gather library.
|
|
|
|
*/
|
|
|
|
static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
|
|
|
|
struct scatterlist *sg, int num_sg, unsigned int length,
|
|
|
|
unsigned int *act_len)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
2008-05-08 23:55:59 +08:00
|
|
|
/* don't submit s-g requests during abort processing */
|
|
|
|
if (test_bit(US_FLIDX_ABORTING, &us->dflags))
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_ERROR;
|
|
|
|
|
|
|
|
/* initialize the scatter-gather request block */
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "xfer %u bytes, %d entries\n", length, num_sg);
|
2005-04-17 06:20:36 +08:00
|
|
|
result = usb_sg_init(&us->current_sg, us->pusb_dev, pipe, 0,
|
2006-12-07 12:33:13 +08:00
|
|
|
sg, num_sg, length, GFP_NOIO);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (result) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "usb_sg_init returned %d\n", result);
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_XFER_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* since the block has been initialized successfully, it's now
|
|
|
|
* okay to cancel it
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
set_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-05-08 23:55:59 +08:00
|
|
|
/* did an abort occur during the submission? */
|
|
|
|
if (test_bit(US_FLIDX_ABORTING, &us->dflags)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* cancel the request, if it hasn't been cancelled already */
|
2008-05-02 03:35:18 +08:00
|
|
|
if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- cancelling sg request\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_sg_cancel(&us->current_sg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for the completion of the transfer */
|
|
|
|
usb_sg_wait(&us->current_sg);
|
2008-05-02 03:35:18 +08:00
|
|
|
clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
result = us->current_sg.status;
|
|
|
|
if (act_len)
|
|
|
|
*act_len = us->current_sg.bytes;
|
|
|
|
return interpret_urb_result(us, pipe, length, result,
|
|
|
|
us->current_sg.bytes);
|
|
|
|
}
|
|
|
|
|
2007-09-10 23:01:08 +08:00
|
|
|
/*
|
|
|
|
* Common used function. Transfer a complete command
|
|
|
|
* via usb_stor_bulk_transfer_sglist() above. Set cmnd resid
|
|
|
|
*/
|
|
|
|
int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
|
|
|
|
struct scsi_cmnd* srb)
|
|
|
|
{
|
|
|
|
unsigned int partial;
|
|
|
|
int result = usb_stor_bulk_transfer_sglist(us, pipe, scsi_sglist(srb),
|
|
|
|
scsi_sg_count(srb), scsi_bufflen(srb),
|
|
|
|
&partial);
|
|
|
|
|
|
|
|
scsi_set_resid(srb, scsi_bufflen(srb) - partial);
|
|
|
|
return result;
|
|
|
|
}
|
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_bulk_srb);
|
2007-09-10 23:01:08 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Transfer an entire SCSI command's worth of data payload over the bulk
|
|
|
|
* pipe.
|
|
|
|
*
|
|
|
|
* Note that this uses usb_stor_bulk_transfer_buf() and
|
|
|
|
* usb_stor_bulk_transfer_sglist() to achieve its goals --
|
|
|
|
* this function simply determines whether we're going to use
|
|
|
|
* scatter-gather or not, and acts appropriately.
|
|
|
|
*/
|
|
|
|
int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe,
|
|
|
|
void *buf, unsigned int length_left, int use_sg, int *residual)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
unsigned int partial;
|
|
|
|
|
|
|
|
/* are we scatter-gathering? */
|
|
|
|
if (use_sg) {
|
|
|
|
/* use the usb core scatter-gather primitives */
|
|
|
|
result = usb_stor_bulk_transfer_sglist(us, pipe,
|
|
|
|
(struct scatterlist *) buf, use_sg,
|
|
|
|
length_left, &partial);
|
|
|
|
length_left -= partial;
|
|
|
|
} else {
|
|
|
|
/* no scatter-gather, just make the request */
|
|
|
|
result = usb_stor_bulk_transfer_buf(us, pipe, buf,
|
|
|
|
length_left, &partial);
|
|
|
|
length_left -= partial;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store the residual and return the error code */
|
|
|
|
if (residual)
|
|
|
|
*residual = length_left;
|
|
|
|
return result;
|
|
|
|
}
|
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_bulk_transfer_sg);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Transport routines
|
|
|
|
***********************************************************************/
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* There are so many devices that report the capacity incorrectly,
|
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
|
|
|
* this routine was written to counteract some of the resulting
|
|
|
|
* problems.
|
|
|
|
*/
|
|
|
|
static void last_sector_hacks(struct us_data *us, struct scsi_cmnd *srb)
|
|
|
|
{
|
|
|
|
struct gendisk *disk;
|
|
|
|
struct scsi_disk *sdkp;
|
|
|
|
u32 sector;
|
|
|
|
|
|
|
|
/* To Report "Medium Error: Record Not Found */
|
|
|
|
static unsigned char record_not_found[18] = {
|
|
|
|
[0] = 0x70, /* current error */
|
|
|
|
[2] = MEDIUM_ERROR, /* = 0x03 */
|
|
|
|
[7] = 0x0a, /* additional length */
|
|
|
|
[12] = 0x14 /* Record Not Found */
|
|
|
|
};
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* If last-sector problems can't occur, whether because the
|
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
|
|
|
* capacity was already decremented or because the device is
|
|
|
|
* known to report the correct capacity, then we don't need
|
|
|
|
* to do anything.
|
|
|
|
*/
|
|
|
|
if (!us->use_last_sector_hacks)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Was this command a READ(10) or a WRITE(10)? */
|
|
|
|
if (srb->cmnd[0] != READ_10 && srb->cmnd[0] != WRITE_10)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Did this command access the last sector? */
|
|
|
|
sector = (srb->cmnd[2] << 24) | (srb->cmnd[3] << 16) |
|
|
|
|
(srb->cmnd[4] << 8) | (srb->cmnd[5]);
|
|
|
|
disk = srb->request->rq_disk;
|
|
|
|
if (!disk)
|
|
|
|
goto done;
|
|
|
|
sdkp = scsi_disk(disk);
|
|
|
|
if (!sdkp)
|
|
|
|
goto done;
|
|
|
|
if (sector + 1 != sdkp->capacity)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (srb->result == SAM_STAT_GOOD && scsi_get_resid(srb) == 0) {
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* The command succeeded. We know this device doesn't
|
2009-02-02 22:51:01 +08:00
|
|
|
* have the last-sector bug, so stop checking it.
|
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
|
|
|
*/
|
2009-02-02 22:51:01 +08:00
|
|
|
us->use_last_sector_hacks = 0;
|
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
|
|
|
|
|
|
|
} else {
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* The command failed. Allow up to 3 retries in case this
|
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
|
|
|
* is some normal sort of failure. After that, assume the
|
|
|
|
* capacity is wrong and we're trying to access the sector
|
|
|
|
* beyond the end. Replace the result code and sense data
|
|
|
|
* with values that will cause the SCSI core to fail the
|
|
|
|
* command immediately, instead of going into an infinite
|
|
|
|
* (or even just a very long) retry loop.
|
|
|
|
*/
|
|
|
|
if (++us->last_sector_retries < 3)
|
|
|
|
return;
|
|
|
|
srb->result = SAM_STAT_CHECK_CONDITION;
|
|
|
|
memcpy(srb->sense_buffer, record_not_found,
|
|
|
|
sizeof(record_not_found));
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Don't reset the retry counter for TEST UNIT READY commands,
|
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
|
|
|
* because they get issued after device resets which might be
|
|
|
|
* caused by a failed last-sector access.
|
|
|
|
*/
|
|
|
|
if (srb->cmnd[0] != TEST_UNIT_READY)
|
|
|
|
us->last_sector_retries = 0;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Invoke the transport and basic error-handling/recovery methods
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This is used by the protocol layers to actually send the message to
|
|
|
|
* the device and receive the response.
|
|
|
|
*/
|
|
|
|
void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
|
|
|
|
{
|
|
|
|
int need_auto_sense;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
/* send the command to the transport layer */
|
2007-09-10 23:01:08 +08:00
|
|
|
scsi_set_resid(srb, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
result = us->transport(srb, us);
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* if the command gets aborted by the higher layers, we need to
|
2005-04-17 06:20:36 +08:00
|
|
|
* short-circuit all other processing
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- command was aborted\n");
|
2005-06-07 08:21:41 +08:00
|
|
|
srb->result = DID_ABORT << 16;
|
|
|
|
goto Handle_Errors;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if there is a transport error, reset and don't auto-sense */
|
|
|
|
if (result == USB_STOR_TRANSPORT_ERROR) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- transport indicates error, resetting\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
srb->result = DID_ERROR << 16;
|
2005-06-07 08:21:41 +08:00
|
|
|
goto Handle_Errors;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if the transport provided its own sense data, don't auto-sense */
|
|
|
|
if (result == USB_STOR_TRANSPORT_NO_SENSE) {
|
|
|
|
srb->result = SAM_STAT_CHECK_CONDITION;
|
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
|
|
|
last_sector_hacks(us, srb);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
srb->result = SAM_STAT_GOOD;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Determine if we need to auto-sense
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* I normally don't use a flag like this, but it's almost impossible
|
|
|
|
* to understand what's going on here if I don't.
|
|
|
|
*/
|
|
|
|
need_auto_sense = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're running the CB transport, which is incapable
|
|
|
|
* of determining status on its own, we will auto-sense
|
|
|
|
* unless the operation involved a data-in transfer. Devices
|
|
|
|
* can signal most data-in errors by stalling the bulk-in pipe.
|
|
|
|
*/
|
2010-10-07 19:05:21 +08:00
|
|
|
if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_DPCM_USB) &&
|
2005-04-17 06:20:36 +08:00
|
|
|
srb->sc_data_direction != DMA_FROM_DEVICE) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- CB transport device requiring auto-sense\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
need_auto_sense = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a failure, we're going to do a REQUEST_SENSE
|
|
|
|
* automatically. Note that we differentiate between a command
|
|
|
|
* "failure" and an "error" in the transport mechanism.
|
|
|
|
*/
|
|
|
|
if (result == USB_STOR_TRANSPORT_FAILED) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- transport indicates command failure\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
need_auto_sense = 1;
|
|
|
|
}
|
|
|
|
|
2008-11-19 05:31:13 +08:00
|
|
|
/*
|
|
|
|
* Determine if this device is SAT by seeing if the
|
|
|
|
* command executed successfully. Otherwise we'll have
|
|
|
|
* to wait for at least one CHECK_CONDITION to determine
|
|
|
|
* SANE_SENSE support
|
|
|
|
*/
|
2009-12-08 05:39:16 +08:00
|
|
|
if (unlikely((srb->cmnd[0] == ATA_16 || srb->cmnd[0] == ATA_12) &&
|
2008-11-19 05:31:13 +08:00
|
|
|
result == USB_STOR_TRANSPORT_GOOD &&
|
|
|
|
!(us->fflags & US_FL_SANE_SENSE) &&
|
2009-12-08 05:39:16 +08:00
|
|
|
!(us->fflags & US_FL_BAD_SENSE) &&
|
|
|
|
!(srb->cmnd[2] & 0x20))) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- SAT supported, increasing auto-sense\n");
|
2008-11-19 05:31:13 +08:00
|
|
|
us->fflags |= US_FL_SANE_SENSE;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* A short transfer on a command where we don't expect it
|
|
|
|
* is unusual, but it doesn't mean we need to auto-sense.
|
|
|
|
*/
|
2007-09-10 23:01:08 +08:00
|
|
|
if ((scsi_get_resid(srb) > 0) &&
|
2005-04-17 06:20:36 +08:00
|
|
|
!((srb->cmnd[0] == REQUEST_SENSE) ||
|
|
|
|
(srb->cmnd[0] == INQUIRY) ||
|
|
|
|
(srb->cmnd[0] == MODE_SENSE) ||
|
|
|
|
(srb->cmnd[0] == LOG_SENSE) ||
|
|
|
|
(srb->cmnd[0] == MODE_SENSE_10))) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- unexpectedly short transfer\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, if we need to do the auto-sense, let's do it */
|
|
|
|
if (need_auto_sense) {
|
|
|
|
int temp_result;
|
2007-09-11 03:36:31 +08:00
|
|
|
struct scsi_eh_save ses;
|
2008-11-19 05:31:13 +08:00
|
|
|
int sense_size = US_SENSE_SIZE;
|
2010-11-12 07:43:11 +08:00
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
const u8 *scdd;
|
|
|
|
u8 fm_ili;
|
2008-11-19 05:31:13 +08:00
|
|
|
|
|
|
|
/* device supports and needs bigger sense buffer */
|
|
|
|
if (us->fflags & US_FL_SANE_SENSE)
|
|
|
|
sense_size = ~0;
|
2009-10-13 12:53:47 +08:00
|
|
|
Retry_Sense:
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Issuing auto-REQUEST_SENSE\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-11-19 05:31:13 +08:00
|
|
|
scsi_eh_prep_cmnd(srb, &ses, NULL, 0, sense_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* FIXME: we must do the protocol translation here */
|
2010-10-07 19:05:21 +08:00
|
|
|
if (us->subclass == USB_SC_RBC || us->subclass == USB_SC_SCSI ||
|
|
|
|
us->subclass == USB_SC_CYP_ATACB)
|
2005-04-17 06:20:36 +08:00
|
|
|
srb->cmd_len = 6;
|
|
|
|
else
|
|
|
|
srb->cmd_len = 12;
|
|
|
|
|
|
|
|
/* issue the auto-sense command */
|
2007-09-10 23:01:08 +08:00
|
|
|
scsi_set_resid(srb, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
temp_result = us->transport(us->srb, us);
|
|
|
|
|
|
|
|
/* let's clean up right away */
|
2007-09-11 03:36:31 +08:00
|
|
|
scsi_eh_restore_cmnd(srb, &ses);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-05-02 03:35:18 +08:00
|
|
|
if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- auto-sense aborted\n");
|
2005-06-07 08:21:41 +08:00
|
|
|
srb->result = DID_ABORT << 16;
|
2009-12-08 05:39:16 +08:00
|
|
|
|
|
|
|
/* If SANE_SENSE caused this problem, disable it */
|
|
|
|
if (sense_size != US_SENSE_SIZE) {
|
|
|
|
us->fflags &= ~US_FL_SANE_SENSE;
|
|
|
|
us->fflags |= US_FL_BAD_SENSE;
|
|
|
|
}
|
2005-06-07 08:21:41 +08:00
|
|
|
goto Handle_Errors;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-10-13 12:53:47 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some devices claim to support larger sense but fail when
|
2009-10-13 12:53:47 +08:00
|
|
|
* trying to request it. When a transport failure happens
|
|
|
|
* using US_FS_SANE_SENSE, we always retry with a standard
|
|
|
|
* (small) sense request. This fixes some USB GSM modems
|
|
|
|
*/
|
|
|
|
if (temp_result == USB_STOR_TRANSPORT_FAILED &&
|
2009-12-08 05:39:16 +08:00
|
|
|
sense_size != US_SENSE_SIZE) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- auto-sense failure, retry small sense\n");
|
2009-10-13 12:53:47 +08:00
|
|
|
sense_size = US_SENSE_SIZE;
|
2009-12-08 05:39:16 +08:00
|
|
|
us->fflags &= ~US_FL_SANE_SENSE;
|
|
|
|
us->fflags |= US_FL_BAD_SENSE;
|
2009-10-13 12:53:47 +08:00
|
|
|
goto Retry_Sense;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Other failures */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (temp_result != USB_STOR_TRANSPORT_GOOD) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- auto-sense failure\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* we skip the reset if this happens to be a
|
2005-04-17 06:20:36 +08:00
|
|
|
* multi-target device, since failure of an
|
|
|
|
* auto-sense is perfectly valid
|
|
|
|
*/
|
|
|
|
srb->result = DID_ERROR << 16;
|
2008-05-02 03:35:18 +08:00
|
|
|
if (!(us->fflags & US_FL_SCM_MULT_TARG))
|
2005-06-07 08:21:41 +08:00
|
|
|
goto Handle_Errors;
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* If the sense data returned is larger than 18-bytes then we
|
2008-11-19 05:31:13 +08:00
|
|
|
* assume this device supports requesting more in the future.
|
|
|
|
* The response code must be 70h through 73h inclusive.
|
|
|
|
*/
|
|
|
|
if (srb->sense_buffer[7] > (US_SENSE_SIZE - 8) &&
|
|
|
|
!(us->fflags & US_FL_SANE_SENSE) &&
|
2009-12-08 05:39:16 +08:00
|
|
|
!(us->fflags & US_FL_BAD_SENSE) &&
|
2008-11-19 05:31:13 +08:00
|
|
|
(srb->sense_buffer[0] & 0x7C) == 0x70) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- SANE_SENSE support enabled\n");
|
2008-11-19 05:31:13 +08:00
|
|
|
us->fflags |= US_FL_SANE_SENSE;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Indicate to the user that we truncated their sense
|
2008-11-19 05:31:13 +08:00
|
|
|
* because we didn't know it supported larger sense.
|
|
|
|
*/
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- Sense data truncated to %i from %i\n",
|
|
|
|
US_SENSE_SIZE,
|
|
|
|
srb->sense_buffer[7] + 8);
|
2008-11-19 05:31:13 +08:00
|
|
|
srb->sense_buffer[7] = (US_SENSE_SIZE - 8);
|
|
|
|
}
|
|
|
|
|
2010-11-12 07:43:11 +08:00
|
|
|
scsi_normalize_sense(srb->sense_buffer, SCSI_SENSE_BUFFERSIZE,
|
|
|
|
&sshdr);
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- Result from auto-sense is %d\n",
|
|
|
|
temp_result);
|
|
|
|
usb_stor_dbg(us, "-- code: 0x%x, key: 0x%x, ASC: 0x%x, ASCQ: 0x%x\n",
|
|
|
|
sshdr.response_code, sshdr.sense_key,
|
|
|
|
sshdr.asc, sshdr.ascq);
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_USB_STORAGE_DEBUG
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_show_sense(us, sshdr.sense_key, sshdr.asc, sshdr.ascq);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* set the result so the higher layers expect this data */
|
|
|
|
srb->result = SAM_STAT_CHECK_CONDITION;
|
|
|
|
|
2010-11-12 07:43:11 +08:00
|
|
|
scdd = scsi_sense_desc_find(srb->sense_buffer,
|
|
|
|
SCSI_SENSE_BUFFERSIZE, 4);
|
|
|
|
fm_ili = (scdd ? scdd[3] : srb->sense_buffer[2]) & 0xA0;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* We often get empty sense data. This could indicate that
|
2009-10-07 02:07:57 +08:00
|
|
|
* everything worked or that there was an unspecified
|
|
|
|
* problem. We have to decide which.
|
|
|
|
*/
|
2010-11-12 07:43:11 +08:00
|
|
|
if (sshdr.sense_key == 0 && sshdr.asc == 0 && sshdr.ascq == 0 &&
|
|
|
|
fm_ili == 0) {
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* If things are really okay, then let's show that.
|
2009-10-07 02:07:57 +08:00
|
|
|
* Zero out the sense buffer so the higher layers
|
|
|
|
* won't realize we did an unsolicited auto-sense.
|
|
|
|
*/
|
|
|
|
if (result == USB_STOR_TRANSPORT_GOOD) {
|
|
|
|
srb->result = SAM_STAT_GOOD;
|
|
|
|
srb->sense_buffer[0] = 0x0;
|
usb-storage: fix bogus hardware error messages for ATA pass-thru devices
Ever since commit a621bac3044e ("scsi_lib: correctly retry failed zero
length REQ_TYPE_FS commands"), people have been getting bogus error
messages for USB disk drives using ATA pass-thru. For example:
[ 1344.880193] sd 6:0:0:0: [sdb] Attached SCSI disk
[ 1345.069152] sd 6:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_ERROR driverbyte=DRIVER_SENSE
[ 1345.069159] sd 6:0:0:0: [sdb] tag#0 Sense Key : Hardware Error [current] [descriptor]
[ 1345.069162] sd 6:0:0:0: [sdb] tag#0 Add. Sense: No additional sense information
[ 1345.069168] sd 6:0:0:0: [sdb] tag#0 CDB: ATA command pass through(16) 85 06 20 00 00 00 00 00 00 00 00 00 00 00 e5 00
[ 1345.172252] sd 6:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_ERROR driverbyte=DRIVER_SENSE
[ 1345.172258] sd 6:0:0:0: [sdb] tag#0 Sense Key : Hardware Error [current] [descriptor]
[ 1345.172261] sd 6:0:0:0: [sdb] tag#0 Add. Sense: No additional sense information
[ 1345.172266] sd 6:0:0:0: [sdb] tag#0 CDB: ATA command pass through(12)/Blank a1 06 20 da 00 00 4f c2 00 b0 00 00
These messages can be quite annoying, because programs like udisks2
provoke them every 10 minutes or so. Other programs can also have
this effect, such as those in smartmontools.
I don't fully understand how that commit induced the SCSI core to log
these error messages, but the underlying cause for them is code added
to usb-storage by commit f1a0743bc0e7 ("USB: storage: When a device
returns no sense data, call it a Hardware Error"). At the time it was
necessary to do this, in order to prevent an infinite retry loop with
some not-so-great mass storage devices.
However, the ATA pass-thru protocol uses SCSI sense data to return
command status values, and some devices always report Check Condition
status for ATA pass-thru commands to ensure that the host retrieves
the sense data, even if the command succeeded. This violates the USB
mass-storage protocol (Check Condition status is supposed to mean the
command failed), but we can't help that.
This patch attempts to mitigate the problem of these bogus error
reports by changing usb-storage. The HARDWARE ERROR sense key will be
inserted only for commands that aren't ATA pass-thru.
Thanks to Ewan Milne for pointing out that this mechanism was present
in usb-storage. 8 years after writing it, I had completely forgotten
its existence.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Tested-by: Kris Lindgren <kris.lindgren@gmail.com>
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1351305
CC: Ewan D. Milne <emilne@redhat.com>
CC: <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-22 04:02:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ATA-passthru commands use sense data to report
|
|
|
|
* the command completion status, and often devices
|
|
|
|
* return Check Condition status when nothing is
|
|
|
|
* wrong.
|
|
|
|
*/
|
|
|
|
else if (srb->cmnd[0] == ATA_16 ||
|
|
|
|
srb->cmnd[0] == ATA_12) {
|
|
|
|
/* leave the data alone */
|
|
|
|
}
|
2009-10-07 02:07:57 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* If there was a problem, report an unspecified
|
2009-10-07 02:07:57 +08:00
|
|
|
* hardware error to prevent the higher layers from
|
|
|
|
* entering an infinite retry loop.
|
|
|
|
*/
|
usb-storage: fix bogus hardware error messages for ATA pass-thru devices
Ever since commit a621bac3044e ("scsi_lib: correctly retry failed zero
length REQ_TYPE_FS commands"), people have been getting bogus error
messages for USB disk drives using ATA pass-thru. For example:
[ 1344.880193] sd 6:0:0:0: [sdb] Attached SCSI disk
[ 1345.069152] sd 6:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_ERROR driverbyte=DRIVER_SENSE
[ 1345.069159] sd 6:0:0:0: [sdb] tag#0 Sense Key : Hardware Error [current] [descriptor]
[ 1345.069162] sd 6:0:0:0: [sdb] tag#0 Add. Sense: No additional sense information
[ 1345.069168] sd 6:0:0:0: [sdb] tag#0 CDB: ATA command pass through(16) 85 06 20 00 00 00 00 00 00 00 00 00 00 00 e5 00
[ 1345.172252] sd 6:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_ERROR driverbyte=DRIVER_SENSE
[ 1345.172258] sd 6:0:0:0: [sdb] tag#0 Sense Key : Hardware Error [current] [descriptor]
[ 1345.172261] sd 6:0:0:0: [sdb] tag#0 Add. Sense: No additional sense information
[ 1345.172266] sd 6:0:0:0: [sdb] tag#0 CDB: ATA command pass through(12)/Blank a1 06 20 da 00 00 4f c2 00 b0 00 00
These messages can be quite annoying, because programs like udisks2
provoke them every 10 minutes or so. Other programs can also have
this effect, such as those in smartmontools.
I don't fully understand how that commit induced the SCSI core to log
these error messages, but the underlying cause for them is code added
to usb-storage by commit f1a0743bc0e7 ("USB: storage: When a device
returns no sense data, call it a Hardware Error"). At the time it was
necessary to do this, in order to prevent an infinite retry loop with
some not-so-great mass storage devices.
However, the ATA pass-thru protocol uses SCSI sense data to return
command status values, and some devices always report Check Condition
status for ATA pass-thru commands to ensure that the host retrieves
the sense data, even if the command succeeded. This violates the USB
mass-storage protocol (Check Condition status is supposed to mean the
command failed), but we can't help that.
This patch attempts to mitigate the problem of these bogus error
reports by changing usb-storage. The HARDWARE ERROR sense key will be
inserted only for commands that aren't ATA pass-thru.
Thanks to Ewan Milne for pointing out that this mechanism was present
in usb-storage. 8 years after writing it, I had completely forgotten
its existence.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Tested-by: Kris Lindgren <kris.lindgren@gmail.com>
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1351305
CC: Ewan D. Milne <emilne@redhat.com>
CC: <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-22 04:02:05 +08:00
|
|
|
else {
|
2009-10-07 02:07:57 +08:00
|
|
|
srb->result = DID_ERROR << 16;
|
2010-11-12 07:43:11 +08:00
|
|
|
if ((sshdr.response_code & 0x72) == 0x72)
|
|
|
|
srb->sense_buffer[1] = HARDWARE_ERROR;
|
|
|
|
else
|
|
|
|
srb->sense_buffer[2] = HARDWARE_ERROR;
|
2009-10-07 02:07:57 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-07 23:35:52 +08:00
|
|
|
/*
|
|
|
|
* Some devices don't work or return incorrect data the first
|
|
|
|
* time they get a READ(10) command, or for the first READ(10)
|
|
|
|
* after a media change. If the INITIAL_READ10 flag is set,
|
|
|
|
* keep track of whether READ(10) commands succeed. If the
|
|
|
|
* previous one succeeded and this one failed, set the REDO_READ10
|
|
|
|
* flag to force a retry.
|
|
|
|
*/
|
|
|
|
if (unlikely((us->fflags & US_FL_INITIAL_READ10) &&
|
|
|
|
srb->cmnd[0] == READ_10)) {
|
|
|
|
if (srb->result == SAM_STAT_GOOD) {
|
|
|
|
set_bit(US_FLIDX_READ10_WORKED, &us->dflags);
|
|
|
|
} else if (test_bit(US_FLIDX_READ10_WORKED, &us->dflags)) {
|
|
|
|
clear_bit(US_FLIDX_READ10_WORKED, &us->dflags);
|
|
|
|
set_bit(US_FLIDX_REDO_READ10, &us->dflags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Next, if the REDO_READ10 flag is set, return a result
|
|
|
|
* code that will cause the SCSI core to retry the READ(10)
|
|
|
|
* command immediately.
|
|
|
|
*/
|
|
|
|
if (test_bit(US_FLIDX_REDO_READ10, &us->dflags)) {
|
|
|
|
clear_bit(US_FLIDX_REDO_READ10, &us->dflags);
|
|
|
|
srb->result = DID_IMM_RETRY << 16;
|
|
|
|
srb->sense_buffer[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Did we transfer less than the minimum amount required? */
|
2008-09-02 22:12:11 +08:00
|
|
|
if ((srb->result == SAM_STAT_GOOD || srb->sense_buffer[2] == 0) &&
|
2007-09-10 23:01:08 +08:00
|
|
|
scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow)
|
2009-01-04 16:14:11 +08:00
|
|
|
srb->result = DID_ERROR << 16;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
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
|
|
|
last_sector_hacks(us, srb);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Error and abort processing: try to resynchronize with the device
|
2005-06-07 08:21:41 +08:00
|
|
|
* by issuing a port reset. If that fails, try a class-specific
|
2016-04-18 18:09:11 +08:00
|
|
|
* device reset.
|
|
|
|
*/
|
2005-06-07 08:21:41 +08:00
|
|
|
Handle_Errors:
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Set the RESETTING bit, and clear the ABORTING bit so that
|
|
|
|
* the reset may proceed.
|
|
|
|
*/
|
2005-06-07 08:21:41 +08:00
|
|
|
scsi_lock(us_to_host(us));
|
2008-05-02 03:35:18 +08:00
|
|
|
set_bit(US_FLIDX_RESETTING, &us->dflags);
|
|
|
|
clear_bit(US_FLIDX_ABORTING, &us->dflags);
|
2005-06-07 08:21:41 +08:00
|
|
|
scsi_unlock(us_to_host(us));
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* We must release the device lock because the pre_reset routine
|
|
|
|
* will want to acquire it.
|
|
|
|
*/
|
2006-06-02 01:52:56 +08:00
|
|
|
mutex_unlock(&us->dev_mutex);
|
2005-06-07 08:21:41 +08:00
|
|
|
result = usb_stor_port_reset(us);
|
2006-06-02 01:52:56 +08:00
|
|
|
mutex_lock(&us->dev_mutex);
|
|
|
|
|
2005-06-07 08:21:41 +08:00
|
|
|
if (result < 0) {
|
|
|
|
scsi_lock(us_to_host(us));
|
|
|
|
usb_stor_report_device_reset(us);
|
|
|
|
scsi_unlock(us_to_host(us));
|
2005-04-17 06:20:36 +08:00
|
|
|
us->transport_reset(us);
|
2005-06-07 08:21:41 +08:00
|
|
|
}
|
2008-05-02 03:35:18 +08:00
|
|
|
clear_bit(US_FLIDX_RESETTING, &us->dflags);
|
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
|
|
|
last_sector_hacks(us, srb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop the current URB transfer */
|
|
|
|
void usb_stor_stop_transport(struct us_data *us)
|
|
|
|
{
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* If the state machine is blocked waiting for an URB,
|
2005-04-17 06:20:36 +08:00
|
|
|
* let's wake it up. The test_and_clear_bit() call
|
|
|
|
* guarantees that if a URB has just been submitted,
|
2016-04-18 18:09:11 +08:00
|
|
|
* it won't be cancelled more than once.
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- cancelling URB\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_unlink_urb(us->current_urb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we are waiting for a scatter-gather operation, cancel it. */
|
2008-05-02 03:35:18 +08:00
|
|
|
if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "-- cancelling sg request\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_sg_cancel(&us->current_sg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-11-21 03:20:03 +08:00
|
|
|
* Control/Bulk and Control/Bulk/Interrupt transport
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2008-11-21 03:20:03 +08:00
|
|
|
int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-09-10 23:01:08 +08:00
|
|
|
unsigned int transfer_length = scsi_bufflen(srb);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int pipe = 0;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
/* COMMAND STAGE */
|
|
|
|
/* let's send the command via the control pipe */
|
2016-11-11 05:57:14 +08:00
|
|
|
/*
|
|
|
|
* Command is sometime (f.e. after scsi_eh_prep_cmnd) on the stack.
|
|
|
|
* Stack may be vmallocated. So no DMA for us. Make a copy.
|
|
|
|
*/
|
|
|
|
memcpy(us->iobuf, srb->cmnd, srb->cmd_len);
|
2005-04-17 06:20:36 +08:00
|
|
|
result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
|
|
|
|
US_CBI_ADSC,
|
|
|
|
USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0,
|
2016-11-11 05:57:14 +08:00
|
|
|
us->ifnum, us->iobuf, srb->cmd_len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* check the return code for the command */
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Call to usb_stor_ctrl_transfer() returned %d\n",
|
|
|
|
result);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* if we stalled the command, it means command failed */
|
|
|
|
if (result == USB_STOR_XFER_STALLED) {
|
|
|
|
return USB_STOR_TRANSPORT_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Uh oh... serious problem here */
|
|
|
|
if (result != USB_STOR_XFER_GOOD) {
|
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DATA STAGE */
|
|
|
|
/* transfer the data payload for this command, if one exists*/
|
|
|
|
if (transfer_length) {
|
|
|
|
pipe = srb->sc_data_direction == DMA_FROM_DEVICE ?
|
|
|
|
us->recv_bulk_pipe : us->send_bulk_pipe;
|
2007-09-10 23:01:08 +08:00
|
|
|
result = usb_stor_bulk_srb(us, pipe, srb);
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "CBI data stage result is 0x%x\n", result);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* if we stalled the data transfer it means command failed */
|
|
|
|
if (result == USB_STOR_XFER_STALLED)
|
|
|
|
return USB_STOR_TRANSPORT_FAILED;
|
|
|
|
if (result > USB_STOR_XFER_STALLED)
|
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* STATUS STAGE */
|
2008-11-21 03:20:03 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* NOTE: CB does not have a status stage. Silly, I know. So
|
2008-11-21 03:20:03 +08:00
|
|
|
* we have to catch this at a higher level.
|
|
|
|
*/
|
2010-10-07 19:05:21 +08:00
|
|
|
if (us->protocol != USB_PR_CBI)
|
2008-11-21 03:20:03 +08:00
|
|
|
return USB_STOR_TRANSPORT_GOOD;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
result = usb_stor_intr_transfer(us, us->iobuf, 2);
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Got interrupt data (0x%x, 0x%x)\n",
|
|
|
|
us->iobuf[0], us->iobuf[1]);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (result != USB_STOR_XFER_GOOD)
|
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* UFI gives us ASC and ASCQ, like a request sense
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* REQUEST_SENSE and INQUIRY don't affect the sense data on UFI
|
|
|
|
* devices, so we ignore the information for those commands. Note
|
|
|
|
* that this means we could be ignoring a real error on these
|
|
|
|
* commands, but that can't be helped.
|
|
|
|
*/
|
2010-10-07 19:05:21 +08:00
|
|
|
if (us->subclass == USB_SC_UFI) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (srb->cmnd[0] == REQUEST_SENSE ||
|
|
|
|
srb->cmnd[0] == INQUIRY)
|
|
|
|
return USB_STOR_TRANSPORT_GOOD;
|
|
|
|
if (us->iobuf[0])
|
|
|
|
goto Failed;
|
|
|
|
return USB_STOR_TRANSPORT_GOOD;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* If not UFI, we interpret the data as a result code
|
2005-04-17 06:20:36 +08:00
|
|
|
* The first byte should always be a 0x0.
|
|
|
|
*
|
|
|
|
* Some bogus devices don't follow that rule. They stuff the ASC
|
|
|
|
* into the first byte -- so if it's non-zero, call it a failure.
|
|
|
|
*/
|
|
|
|
if (us->iobuf[0]) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "CBI IRQ data showed reserved bType 0x%x\n",
|
|
|
|
us->iobuf[0]);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto Failed;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The second byte & 0x0F should be 0x0 for good, otherwise error */
|
|
|
|
switch (us->iobuf[1] & 0x0F) {
|
|
|
|
case 0x00:
|
|
|
|
return USB_STOR_TRANSPORT_GOOD;
|
|
|
|
case 0x01:
|
|
|
|
goto Failed;
|
|
|
|
}
|
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* the CBI spec requires that the bulk pipe must be cleared
|
2005-04-17 06:20:36 +08:00
|
|
|
* following any data-in/out command failure (section 2.4.3.1.3)
|
|
|
|
*/
|
|
|
|
Failed:
|
|
|
|
if (pipe)
|
|
|
|
usb_stor_clear_halt(us, pipe);
|
|
|
|
return USB_STOR_TRANSPORT_FAILED;
|
|
|
|
}
|
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_CB_transport);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bulk only transport
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Determine what the maximum LUN supported is */
|
|
|
|
int usb_stor_Bulk_max_lun(struct us_data *us)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
/* issue the command */
|
2005-10-24 10:38:56 +08:00
|
|
|
us->iobuf[0] = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
|
|
|
|
US_BULK_GET_MAX_LUN,
|
|
|
|
USB_DIR_IN | USB_TYPE_CLASS |
|
|
|
|
USB_RECIP_INTERFACE,
|
2009-07-14 05:23:33 +08:00
|
|
|
0, us->ifnum, us->iobuf, 1, 10*HZ);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "GetMaxLUN command result is %d, data is %d\n",
|
|
|
|
result, us->iobuf[0]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-11-04 21:00:22 +08:00
|
|
|
/*
|
|
|
|
* If we have a successful request, return the result if valid. The
|
|
|
|
* CBW LUN field is 4 bits wide, so the value reported by the device
|
|
|
|
* should fit into that.
|
|
|
|
*/
|
|
|
|
if (result > 0) {
|
|
|
|
if (us->iobuf[0] < 16) {
|
|
|
|
return us->iobuf[0];
|
|
|
|
} else {
|
|
|
|
dev_info(&us->pusb_intf->dev,
|
|
|
|
"Max LUN %d is not valid, using 0 instead",
|
|
|
|
us->iobuf[0]);
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some devices don't like GetMaxLUN. They may STALL the control
|
|
|
|
* pipe, they may return a zero-length result, they may do nothing at
|
|
|
|
* all and timeout, or they may fail in even more bizarrely creative
|
|
|
|
* ways. In these cases the best approach is to use the default
|
|
|
|
* value: only one LUN.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
|
|
|
|
{
|
|
|
|
struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
|
|
|
|
struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
|
2007-09-10 23:01:08 +08:00
|
|
|
unsigned int transfer_length = scsi_bufflen(srb);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int residue;
|
|
|
|
int result;
|
|
|
|
int fake_sense = 0;
|
|
|
|
unsigned int cswlen;
|
|
|
|
unsigned int cbwlen = US_BULK_CB_WRAP_LEN;
|
|
|
|
|
|
|
|
/* Take care of BULK32 devices; set extra byte to 0 */
|
2008-05-02 03:35:18 +08:00
|
|
|
if (unlikely(us->fflags & US_FL_BULK32)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
cbwlen = 32;
|
|
|
|
us->iobuf[31] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set up the command wrapper */
|
|
|
|
bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
|
|
|
|
bcb->DataTransferLength = cpu_to_le32(transfer_length);
|
2012-02-26 01:28:10 +08:00
|
|
|
bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ?
|
|
|
|
US_BULK_FLAG_IN : 0;
|
2005-07-29 05:43:08 +08:00
|
|
|
bcb->Tag = ++us->tag;
|
2005-04-17 06:20:36 +08:00
|
|
|
bcb->Lun = srb->device->lun;
|
2008-05-02 03:35:18 +08:00
|
|
|
if (us->fflags & US_FL_SCM_MULT_TARG)
|
2005-04-17 06:20:36 +08:00
|
|
|
bcb->Lun |= srb->device->id << 4;
|
|
|
|
bcb->Length = srb->cmd_len;
|
|
|
|
|
|
|
|
/* copy the command payload */
|
|
|
|
memset(bcb->CDB, 0, sizeof(bcb->CDB));
|
|
|
|
memcpy(bcb->CDB, srb->cmnd, bcb->Length);
|
|
|
|
|
|
|
|
/* send it to out endpoint */
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n",
|
|
|
|
le32_to_cpu(bcb->Signature), bcb->Tag,
|
|
|
|
le32_to_cpu(bcb->DataTransferLength), bcb->Flags,
|
|
|
|
(bcb->Lun >> 4), (bcb->Lun & 0x0F),
|
|
|
|
bcb->Length);
|
2005-04-17 06:20:36 +08:00
|
|
|
result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
|
|
|
|
bcb, cbwlen, NULL);
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Bulk command transfer result=%d\n", result);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (result != USB_STOR_XFER_GOOD)
|
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
|
|
|
|
/* DATA STAGE */
|
|
|
|
/* send/receive data payload, if there is any */
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some USB-IDE converter chips need a 100us delay between the
|
2005-04-17 06:20:36 +08:00
|
|
|
* command phase and the data phase. Some devices need a little
|
2016-04-18 18:09:11 +08:00
|
|
|
* more than that, probably because of clock rate inaccuracies.
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
if (unlikely(us->fflags & US_FL_GO_SLOW))
|
2015-07-07 14:57:03 +08:00
|
|
|
usleep_range(125, 150);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (transfer_length) {
|
|
|
|
unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ?
|
|
|
|
us->recv_bulk_pipe : us->send_bulk_pipe;
|
2007-09-10 23:01:08 +08:00
|
|
|
result = usb_stor_bulk_srb(us, pipe, srb);
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Bulk data transfer result 0x%x\n", result);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (result == USB_STOR_XFER_ERROR)
|
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* If the device tried to send back more data than the
|
2005-04-17 06:20:36 +08:00
|
|
|
* amount requested, the spec requires us to transfer
|
|
|
|
* the CSW anyway. Since there's no point retrying the
|
|
|
|
* the command, we'll return fake sense data indicating
|
|
|
|
* Illegal Request, Invalid Field in CDB.
|
|
|
|
*/
|
|
|
|
if (result == USB_STOR_XFER_LONG)
|
|
|
|
fake_sense = 1;
|
2014-11-01 02:49:47 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sometimes a device will mistakenly skip the data phase
|
|
|
|
* and go directly to the status phase without sending a
|
|
|
|
* zero-length packet. If we get a 13-byte response here,
|
|
|
|
* check whether it really is a CSW.
|
|
|
|
*/
|
|
|
|
if (result == USB_STOR_XFER_SHORT &&
|
|
|
|
srb->sc_data_direction == DMA_FROM_DEVICE &&
|
|
|
|
transfer_length - scsi_get_resid(srb) ==
|
|
|
|
US_BULK_CS_WRAP_LEN) {
|
|
|
|
struct scatterlist *sg = NULL;
|
|
|
|
unsigned int offset = 0;
|
|
|
|
|
|
|
|
if (usb_stor_access_xfer_buf((unsigned char *) bcs,
|
|
|
|
US_BULK_CS_WRAP_LEN, srb, &sg,
|
|
|
|
&offset, FROM_XFER_BUF) ==
|
|
|
|
US_BULK_CS_WRAP_LEN &&
|
|
|
|
bcs->Signature ==
|
|
|
|
cpu_to_le32(US_BULK_CS_SIGN)) {
|
|
|
|
usb_stor_dbg(us, "Device skipped data phase\n");
|
|
|
|
scsi_set_resid(srb, transfer_length);
|
|
|
|
goto skipped_data_phase;
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* See flow chart on pg 15 of the Bulk Only Transport spec for
|
2005-04-17 06:20:36 +08:00
|
|
|
* an explanation of how this code works.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get CSW for device status */
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Attempting to get CSW...\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
|
|
|
|
bcs, US_BULK_CS_WRAP_LEN, &cswlen);
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some broken devices add unnecessary zero-length packets to the
|
2005-04-17 06:20:36 +08:00
|
|
|
* end of their data transfers. Such packets show up as 0-length
|
|
|
|
* CSWs. If we encounter such a thing, try to read the CSW again.
|
|
|
|
*/
|
|
|
|
if (result == USB_STOR_XFER_SHORT && cswlen == 0) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Received 0-length CSW; retrying...\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
|
|
|
|
bcs, US_BULK_CS_WRAP_LEN, &cswlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* did the attempt to read the CSW fail? */
|
|
|
|
if (result == USB_STOR_XFER_STALLED) {
|
|
|
|
|
|
|
|
/* get the status again */
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Attempting to get CSW (2nd try)...\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
|
|
|
|
bcs, US_BULK_CS_WRAP_LEN, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we still have a failure at this point, we're in trouble */
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Bulk status result = %d\n", result);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (result != USB_STOR_XFER_GOOD)
|
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
|
2014-11-01 02:49:47 +08:00
|
|
|
skipped_data_phase:
|
2005-04-17 06:20:36 +08:00
|
|
|
/* check bulk status */
|
|
|
|
residue = le32_to_cpu(bcs->Residue);
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
|
|
|
|
le32_to_cpu(bcs->Signature), bcs->Tag,
|
|
|
|
residue, bcs->Status);
|
2008-05-02 03:35:18 +08:00
|
|
|
if (!(bcs->Tag == us->tag || (us->fflags & US_FL_BULK_IGNORE_TAG)) ||
|
2008-03-17 04:04:23 +08:00
|
|
|
bcs->Status > US_BULK_STAT_PHASE) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Bulk logical error\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Some broken devices report odd signatures, so we do not check them
|
2005-04-17 06:20:36 +08:00
|
|
|
* for validity against the spec. We store the first one we see,
|
|
|
|
* and check subsequent transfers for validity against this signature.
|
|
|
|
*/
|
|
|
|
if (!us->bcs_signature) {
|
|
|
|
us->bcs_signature = bcs->Signature;
|
|
|
|
if (us->bcs_signature != cpu_to_le32(US_BULK_CS_SIGN))
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Learnt BCS signature 0x%08X\n",
|
|
|
|
le32_to_cpu(us->bcs_signature));
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (bcs->Signature != us->bcs_signature) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Signature mismatch: got %08X, expecting %08X\n",
|
|
|
|
le32_to_cpu(bcs->Signature),
|
|
|
|
le32_to_cpu(us->bcs_signature));
|
2005-04-17 06:20:36 +08:00
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* try to compute the actual residue, based on how much data
|
|
|
|
* was really transferred and what the device tells us
|
|
|
|
*/
|
2008-07-29 23:58:06 +08:00
|
|
|
if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) {
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Heuristically detect devices that generate bogus residues
|
2008-07-29 23:58:06 +08:00
|
|
|
* by seeing what happens with INQUIRY and READ CAPACITY
|
|
|
|
* commands.
|
|
|
|
*/
|
|
|
|
if (bcs->Status == US_BULK_STAT_OK &&
|
|
|
|
scsi_get_resid(srb) == 0 &&
|
|
|
|
((srb->cmnd[0] == INQUIRY &&
|
|
|
|
transfer_length == 36) ||
|
|
|
|
(srb->cmnd[0] == READ_CAPACITY &&
|
|
|
|
transfer_length == 8))) {
|
|
|
|
us->fflags |= US_FL_IGNORE_RESIDUE;
|
|
|
|
|
|
|
|
} else {
|
2005-04-17 06:20:36 +08:00
|
|
|
residue = min(residue, transfer_length);
|
2007-09-10 23:01:08 +08:00
|
|
|
scsi_set_resid(srb, max(scsi_get_resid(srb),
|
|
|
|
(int) residue));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* based on the status code, we report good or bad */
|
|
|
|
switch (bcs->Status) {
|
|
|
|
case US_BULK_STAT_OK:
|
|
|
|
/* device babbled -- return fake sense data */
|
|
|
|
if (fake_sense) {
|
|
|
|
memcpy(srb->sense_buffer,
|
|
|
|
usb_stor_sense_invalidCDB,
|
|
|
|
sizeof(usb_stor_sense_invalidCDB));
|
|
|
|
return USB_STOR_TRANSPORT_NO_SENSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* command good -- note that data could be short */
|
|
|
|
return USB_STOR_TRANSPORT_GOOD;
|
|
|
|
|
|
|
|
case US_BULK_STAT_FAIL:
|
|
|
|
/* command failed */
|
|
|
|
return USB_STOR_TRANSPORT_FAILED;
|
|
|
|
|
|
|
|
case US_BULK_STAT_PHASE:
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* phase error -- note that a transport reset will be
|
2005-04-17 06:20:36 +08:00
|
|
|
* invoked by the invoke_transport() function
|
|
|
|
*/
|
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we should never get here, but if we do, we're in trouble */
|
|
|
|
return USB_STOR_TRANSPORT_ERROR;
|
|
|
|
}
|
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_Bulk_transport);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Reset routines
|
|
|
|
***********************************************************************/
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* This is the common part of the device reset code.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* It's handy that every transport mechanism uses the control endpoint for
|
|
|
|
* resets.
|
|
|
|
*
|
2005-06-07 08:19:29 +08:00
|
|
|
* Basically, we send a reset with a 5-second timeout, so we don't get
|
2005-04-17 06:20:36 +08:00
|
|
|
* jammed attempting to do the reset.
|
|
|
|
*/
|
|
|
|
static int usb_stor_reset_common(struct us_data *us,
|
|
|
|
u8 request, u8 requesttype,
|
|
|
|
u16 value, u16 index, void *data, u16 size)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
int result2;
|
|
|
|
|
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, "No reset during disconnect\n");
|
2005-06-07 08:21:41 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
result = usb_stor_control_msg(us, us->send_ctrl_pipe,
|
|
|
|
request, requesttype, value, index, data, size,
|
2005-06-07 08:19:29 +08:00
|
|
|
5*HZ);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (result < 0) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Soft reset failed: %d\n", result);
|
2005-06-07 08:21:41 +08:00
|
|
|
return result;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Give the device some time to recover from the reset,
|
|
|
|
* but don't delay disconnect processing.
|
|
|
|
*/
|
2008-05-02 03:35:18 +08:00
|
|
|
wait_event_interruptible_timeout(us->delay_wait,
|
|
|
|
test_bit(US_FLIDX_DISCONNECTING, &us->dflags),
|
|
|
|
HZ*6);
|
|
|
|
if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Reset interrupted by disconnect\n");
|
2005-06-07 08:21:41 +08:00
|
|
|
return -EIO;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Soft reset: clearing bulk-in endpoint halt\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
result = usb_stor_clear_halt(us, us->recv_bulk_pipe);
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Soft reset: clearing bulk-out endpoint halt\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
result2 = usb_stor_clear_halt(us, us->send_bulk_pipe);
|
|
|
|
|
2005-06-07 08:19:29 +08:00
|
|
|
/* return a result code based on the result of the clear-halts */
|
|
|
|
if (result >= 0)
|
|
|
|
result = result2;
|
2005-06-07 08:21:41 +08:00
|
|
|
if (result < 0)
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Soft reset failed\n");
|
2005-06-07 08:21:41 +08:00
|
|
|
else
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "Soft reset done\n");
|
2005-06-07 08:21:41 +08:00
|
|
|
return result;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/* This issues a CB[I] Reset to the device in question */
|
2005-04-17 06:20:36 +08:00
|
|
|
#define CB_RESET_CMD_SIZE 12
|
|
|
|
|
|
|
|
int usb_stor_CB_reset(struct us_data *us)
|
|
|
|
{
|
|
|
|
memset(us->iobuf, 0xFF, CB_RESET_CMD_SIZE);
|
|
|
|
us->iobuf[0] = SEND_DIAGNOSTIC;
|
|
|
|
us->iobuf[1] = 4;
|
|
|
|
return usb_stor_reset_common(us, US_CBI_ADSC,
|
|
|
|
USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
|
|
|
0, us->ifnum, us->iobuf, CB_RESET_CMD_SIZE);
|
|
|
|
}
|
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_CB_reset);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* This issues a Bulk-only Reset to the device in question, including
|
2005-04-17 06:20:36 +08:00
|
|
|
* clearing the subsequent endpoint halts that may occur.
|
|
|
|
*/
|
|
|
|
int usb_stor_Bulk_reset(struct us_data *us)
|
|
|
|
{
|
|
|
|
return usb_stor_reset_common(us, US_BULK_RESET_REQUEST,
|
|
|
|
USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
|
|
|
0, us->ifnum, NULL, 0);
|
|
|
|
}
|
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_Bulk_reset);
|
2005-06-07 08:21:41 +08:00
|
|
|
|
2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Issue a USB port reset to the device. The caller must not hold
|
2006-06-02 01:52:56 +08:00
|
|
|
* us->dev_mutex.
|
|
|
|
*/
|
2005-06-07 08:21:41 +08:00
|
|
|
int usb_stor_port_reset(struct us_data *us)
|
|
|
|
{
|
2008-11-05 00:29:27 +08:00
|
|
|
int result;
|
2005-06-07 08:21:41 +08:00
|
|
|
|
2009-12-18 19:14:21 +08:00
|
|
|
/*for these devices we must use the class specific method */
|
2012-08-17 16:44:56 +08:00
|
|
|
if (us->pusb_dev->quirks & USB_QUIRK_RESET)
|
2009-12-18 19:14:21 +08:00
|
|
|
return -EPERM;
|
|
|
|
|
2008-11-05 00:29:27 +08:00
|
|
|
result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
|
2006-06-02 01:52:56 +08:00
|
|
|
if (result < 0)
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "unable to lock device for reset: %d\n",
|
|
|
|
result);
|
2006-06-02 01:52:56 +08:00
|
|
|
else {
|
|
|
|
/* Were we disconnected while waiting for the lock? */
|
2008-05-02 03:35:18 +08:00
|
|
|
if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
|
2006-06-02 01:52:56 +08:00
|
|
|
result = -EIO;
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "No reset during disconnect\n");
|
2005-06-07 08:21:41 +08:00
|
|
|
} else {
|
2008-06-18 22:00:29 +08:00
|
|
|
result = usb_reset_device(us->pusb_dev);
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "usb_reset_device returns %d\n",
|
|
|
|
result);
|
2005-06-07 08:21:41 +08:00
|
|
|
}
|
2008-11-05 00:29:27 +08:00
|
|
|
usb_unlock_device(us->pusb_dev);
|
2005-06-07 08:21:41 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|