2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* scsi_error.c Copyright (C) 1997 Eric Youngdale
|
|
|
|
*
|
|
|
|
* SCSI error/timeout handling
|
|
|
|
* Initial versions: Eric Youngdale. Based upon conversations with
|
2011-03-22 02:47:31 +07:00
|
|
|
* Leonard Zubkoff and David Miller at Linux Expo,
|
2005-04-17 05:20:36 +07:00
|
|
|
* ideas originating from all over the place.
|
|
|
|
*
|
|
|
|
* Restructured scsi_unjam_host and associated functions.
|
|
|
|
* September 04, 2002 Mike Anderson (andmike@us.ibm.com)
|
|
|
|
*
|
|
|
|
* Forward port of Russell King's (rmk@arm.linux.org.uk) changes and
|
2011-03-22 02:47:31 +07:00
|
|
|
* minor cleanups.
|
2005-04-17 05:20:36 +07:00
|
|
|
* September 30, 2002 Mike Anderson (andmike@us.ibm.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#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 15:04:11 +07:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/kernel.h>
|
2007-07-17 18:03:35 +07:00
|
|
|
#include <linux/freezer.h>
|
2005-09-06 19:04:26 +07:00
|
|
|
#include <linux/kthread.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/delay.h>
|
2013-04-25 13:10:00 +07:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include <scsi/scsi.h>
|
2006-06-10 23:01:03 +07:00
|
|
|
#include <scsi/scsi_cmnd.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <scsi/scsi_dbg.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
2012-02-10 01:48:53 +07:00
|
|
|
#include <scsi/scsi_driver.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <scsi/scsi_eh.h>
|
2015-07-08 21:58:52 +07:00
|
|
|
#include <scsi/scsi_common.h>
|
2006-03-13 20:28:57 +07:00
|
|
|
#include <scsi/scsi_transport.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <scsi/scsi_ioctl.h>
|
2015-08-27 19:16:59 +07:00
|
|
|
#include <scsi/scsi_dh.h>
|
2018-04-18 06:35:10 +07:00
|
|
|
#include <scsi/scsi_devinfo.h>
|
2014-10-11 17:06:47 +07:00
|
|
|
#include <scsi/sg.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include "scsi_priv.h"
|
|
|
|
#include "scsi_logging.h"
|
2007-08-11 04:50:42 +07:00
|
|
|
#include "scsi_transport_api.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-04-01 18:41:40 +07:00
|
|
|
#include <trace/events/scsi.h>
|
|
|
|
|
2017-04-24 14:51:12 +07:00
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
2012-07-26 02:55:55 +07:00
|
|
|
static void scsi_eh_done(struct scsi_cmnd *scmd);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* These should *probably* be handled by the host itself.
|
|
|
|
* Since it is allowed to sleep, it probably should.
|
|
|
|
*/
|
|
|
|
#define BUS_RESET_SETTLE_TIME (10)
|
|
|
|
#define HOST_RESET_SETTLE_TIME (10)
|
|
|
|
|
2011-05-20 01:41:12 +07:00
|
|
|
static int scsi_eh_try_stu(struct scsi_cmnd *scmd);
|
2013-11-11 19:44:54 +07:00
|
|
|
static int scsi_try_to_abort_cmd(struct scsi_host_template *,
|
|
|
|
struct scsi_cmnd *);
|
2011-05-20 01:41:12 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
void scsi_eh_wakeup(struct Scsi_Host *shost)
|
|
|
|
{
|
2017-12-05 01:06:24 +07:00
|
|
|
lockdep_assert_held(shost->host_lock);
|
|
|
|
|
2018-06-24 21:03:26 +07:00
|
|
|
if (scsi_host_busy(shost) == shost->host_failed) {
|
2010-04-01 18:41:40 +07:00
|
|
|
trace_scsi_eh_wakeup(shost);
|
2005-09-19 21:50:04 +07:00
|
|
|
wake_up_process(shost->ehandler);
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(5, shost_printk(KERN_INFO, shost,
|
|
|
|
"Waking error handler thread\n"));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
2006-05-19 19:07:05 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_schedule_eh - schedule EH for SCSI host
|
|
|
|
* @shost: SCSI host to invoke error handling on.
|
|
|
|
*
|
|
|
|
* Schedule SCSI EH without scmd.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2006-05-19 19:07:05 +07:00
|
|
|
void scsi_schedule_eh(struct Scsi_Host *shost)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
|
|
|
|
if (scsi_host_set_state(shost, SHOST_RECOVERY) == 0 ||
|
|
|
|
scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY) == 0) {
|
|
|
|
shost->host_eh_scheduled++;
|
|
|
|
scsi_eh_wakeup(shost);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(scsi_schedule_eh);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-10-23 15:51:21 +07:00
|
|
|
static int scsi_host_eh_past_deadline(struct Scsi_Host *shost)
|
|
|
|
{
|
2013-11-11 19:44:56 +07:00
|
|
|
if (!shost->last_reset || shost->eh_deadline == -1)
|
2013-10-23 15:51:21 +07:00
|
|
|
return 0;
|
|
|
|
|
2013-11-11 19:44:55 +07:00
|
|
|
/*
|
|
|
|
* 32bit accesses are guaranteed to be atomic
|
|
|
|
* (on all supported architectures), so instead
|
|
|
|
* of using a spinlock we can as well double check
|
2013-11-11 19:44:56 +07:00
|
|
|
* if eh_deadline has been set to 'off' during the
|
2013-11-11 19:44:55 +07:00
|
|
|
* time_before call.
|
|
|
|
*/
|
|
|
|
if (time_before(jiffies, shost->last_reset + shost->eh_deadline) &&
|
2013-11-11 19:44:56 +07:00
|
|
|
shost->eh_deadline > -1)
|
2013-10-23 15:51:21 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-11-11 19:44:54 +07:00
|
|
|
/**
|
|
|
|
* scmd_eh_abort_handler - Handle command aborts
|
|
|
|
* @work: command to be aborted.
|
2018-02-13 01:38:05 +07:00
|
|
|
*
|
|
|
|
* Note: this function must be called only for a command that has timed out.
|
|
|
|
* Because the block layer marks a request as complete before it calls
|
|
|
|
* scsi_times_out(), a .scsi_done() call from the LLD for a command that has
|
|
|
|
* timed out do not have any effect. Hence it is safe to call
|
|
|
|
* scsi_finish_command() from this function.
|
2013-11-11 19:44:54 +07:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
scmd_eh_abort_handler(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct scsi_cmnd *scmd =
|
|
|
|
container_of(work, struct scsi_cmnd, abort_work.work);
|
|
|
|
struct scsi_device *sdev = scmd->device;
|
|
|
|
int rtn;
|
|
|
|
|
|
|
|
if (scsi_host_eh_past_deadline(sdev->host)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"eh timeout, not aborting\n"));
|
2013-11-11 19:44:54 +07:00
|
|
|
} else {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"aborting command\n"));
|
2013-11-11 19:44:54 +07:00
|
|
|
rtn = scsi_try_to_abort_cmd(sdev->host->hostt, scmd);
|
|
|
|
if (rtn == SUCCESS) {
|
2014-06-04 18:34:57 +07:00
|
|
|
set_host_byte(scmd, DID_TIME_OUT);
|
2013-11-11 19:44:56 +07:00
|
|
|
if (scsi_host_eh_past_deadline(sdev->host)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"eh timeout, not retrying "
|
|
|
|
"aborted command\n"));
|
2013-11-11 19:44:56 +07:00
|
|
|
} else if (!scsi_noretry_cmd(scmd) &&
|
2013-11-11 19:44:54 +07:00
|
|
|
(++scmd->retries <= scmd->allowed)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_WARNING, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"retry aborted command\n"));
|
2013-11-11 19:44:54 +07:00
|
|
|
scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
|
2013-11-11 19:44:56 +07:00
|
|
|
return;
|
2013-11-11 19:44:54 +07:00
|
|
|
} else {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_WARNING, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"finish aborted command\n"));
|
2013-11-11 19:44:54 +07:00
|
|
|
scsi_finish_command(scmd);
|
2013-11-11 19:44:56 +07:00
|
|
|
return;
|
2013-11-11 19:44:54 +07:00
|
|
|
}
|
2013-11-11 19:44:56 +07:00
|
|
|
} else {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"cmd abort %s\n",
|
2014-10-24 19:27:04 +07:00
|
|
|
(rtn == FAST_IO_FAIL) ?
|
|
|
|
"not send" : "failed"));
|
2013-11-11 19:44:54 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-06 20:36:35 +07:00
|
|
|
scsi_eh_scmd_add(scmd);
|
2013-11-11 19:44:54 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_abort_command - schedule a command abort
|
|
|
|
* @scmd: scmd to abort.
|
|
|
|
*
|
|
|
|
* We only need to abort commands after a command timeout
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
scsi_abort_command(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev = scmd->device;
|
|
|
|
struct Scsi_Host *shost = sdev->host;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) {
|
|
|
|
/*
|
|
|
|
* Retry after abort failed, escalate to next level.
|
|
|
|
*/
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"previous abort failed\n"));
|
2014-06-02 16:50:52 +07:00
|
|
|
BUG_ON(delayed_work_pending(&scmd->abort_work));
|
2013-11-11 19:44:54 +07:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
2013-11-11 19:44:56 +07:00
|
|
|
if (shost->eh_deadline != -1 && !shost->last_reset)
|
2013-11-11 19:44:54 +07:00
|
|
|
shost->last_reset = jiffies;
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
|
|
|
|
scmd->eh_eflags |= SCSI_EH_ABORT_SCHEDULED;
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2015-01-08 13:43:50 +07:00
|
|
|
scmd_printk(KERN_INFO, scmd, "abort scheduled\n"));
|
2013-11-11 19:44:54 +07:00
|
|
|
queue_delayed_work(shost->tmf_work_q, &scmd->abort_work, HZ / 100);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
2017-04-06 20:36:29 +07:00
|
|
|
* scsi_eh_reset - call into ->eh_action to reset internal counters
|
2005-04-17 05:20:36 +07:00
|
|
|
* @scmd: scmd to run eh on.
|
|
|
|
*
|
2017-04-06 20:36:29 +07:00
|
|
|
* The scsi driver might be carrying internal state about the
|
|
|
|
* devices, so we need to call into the driver to reset the
|
|
|
|
* internal state once the error handler is started.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2017-04-06 20:36:29 +07:00
|
|
|
static void scsi_eh_reset(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
if (!blk_rq_is_passthrough(scmd->request)) {
|
|
|
|
struct scsi_driver *sdrv = scsi_cmd_to_driver(scmd);
|
|
|
|
if (sdrv->eh_reset)
|
|
|
|
sdrv->eh_reset(scmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 01:06:23 +07:00
|
|
|
static void scsi_eh_inc_host_failed(struct rcu_head *head)
|
|
|
|
{
|
2018-02-23 02:30:20 +07:00
|
|
|
struct scsi_cmnd *scmd = container_of(head, typeof(*scmd), rcu);
|
|
|
|
struct Scsi_Host *shost = scmd->device->host;
|
2017-12-05 01:06:23 +07:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
shost->host_failed++;
|
|
|
|
scsi_eh_wakeup(shost);
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* scsi_eh_scmd_add - add scsi cmd to error handling.
|
|
|
|
* @scmd: scmd to run eh on.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2017-04-06 20:36:35 +07:00
|
|
|
void scsi_eh_scmd_add(struct scsi_cmnd *scmd)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct Scsi_Host *shost = scmd->device->host;
|
|
|
|
unsigned long flags;
|
2017-04-06 20:36:34 +07:00
|
|
|
int ret;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2017-04-06 20:36:34 +07:00
|
|
|
WARN_ON_ONCE(!shost->ehandler);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
2017-04-06 20:36:34 +07:00
|
|
|
if (scsi_host_set_state(shost, SHOST_RECOVERY)) {
|
|
|
|
ret = scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY);
|
|
|
|
WARN_ON_ONCE(ret);
|
|
|
|
}
|
2013-11-11 19:44:56 +07:00
|
|
|
if (shost->eh_deadline != -1 && !shost->last_reset)
|
2013-10-23 15:51:21 +07:00
|
|
|
shost->last_reset = jiffies;
|
|
|
|
|
2017-04-06 20:36:29 +07:00
|
|
|
scsi_eh_reset(scmd);
|
2005-04-17 05:20:36 +07:00
|
|
|
list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
2017-12-05 01:06:23 +07:00
|
|
|
/*
|
|
|
|
* Ensure that all tasks observe the host state change before the
|
|
|
|
* host_failed change.
|
|
|
|
*/
|
2018-02-23 02:30:20 +07:00
|
|
|
call_rcu(&scmd->rcu, scsi_eh_inc_host_failed);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_times_out - Timeout function for normal scsi commands.
|
2008-09-14 19:55:09 +07:00
|
|
|
* @req: request that is timing out.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* We do not need to lock this. There is the potential for a race
|
|
|
|
* only in that the normal completion handling might run, but if the
|
|
|
|
* normal completion function determines that the timer has already
|
|
|
|
* fired, then it mustn't do anything.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2008-09-14 19:55:09 +07:00
|
|
|
enum blk_eh_timer_return scsi_times_out(struct request *req)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2017-08-26 03:46:32 +07:00
|
|
|
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
|
2018-05-29 20:52:29 +07:00
|
|
|
enum blk_eh_timer_return rtn = BLK_EH_DONE;
|
2011-03-22 02:47:31 +07:00
|
|
|
struct Scsi_Host *host = scmd->device->host;
|
2007-03-17 05:44:41 +07:00
|
|
|
|
2010-04-01 18:41:40 +07:00
|
|
|
trace_scsi_dispatch_cmd_timeout(scmd);
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_log_completion(scmd, TIMEOUT_ERROR);
|
|
|
|
|
2013-11-11 19:44:56 +07:00
|
|
|
if (host->eh_deadline != -1 && !host->last_reset)
|
2013-10-23 15:51:21 +07:00
|
|
|
host->last_reset = jiffies;
|
|
|
|
|
2017-01-30 19:18:58 +07:00
|
|
|
if (host->hostt->eh_timed_out)
|
2011-03-22 02:47:31 +07:00
|
|
|
rtn = host->hostt->eh_timed_out(scmd);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-05-29 20:52:29 +07:00
|
|
|
if (rtn == BLK_EH_DONE) {
|
2018-07-23 21:37:51 +07:00
|
|
|
/*
|
|
|
|
* For blk-mq, we must set the request state to complete now
|
|
|
|
* before sending the request to the scsi error handler. This
|
|
|
|
* will prevent a use-after-free in the event the LLD manages
|
|
|
|
* to complete the request before the error handler finishes
|
|
|
|
* processing this timed out request.
|
|
|
|
*
|
|
|
|
* If the request was already completed, then the LLD beat the
|
|
|
|
* time out handler from transferring the request to the scsi
|
|
|
|
* error handler. In that case we can return immediately as no
|
|
|
|
* further action is required.
|
|
|
|
*/
|
|
|
|
if (req->q->mq_ops && !blk_mq_mark_complete(req))
|
|
|
|
return rtn;
|
2017-04-06 20:36:35 +07:00
|
|
|
if (scsi_abort_command(scmd) != SUCCESS) {
|
2017-04-06 20:36:34 +07:00
|
|
|
set_host_byte(scmd, DID_TIME_OUT);
|
2017-04-06 20:36:35 +07:00
|
|
|
scsi_eh_scmd_add(scmd);
|
2017-04-06 20:36:34 +07:00
|
|
|
}
|
2014-06-13 19:01:45 +07:00
|
|
|
}
|
2008-09-14 19:55:09 +07:00
|
|
|
|
2008-11-05 21:03:15 +07:00
|
|
|
return rtn;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_block_when_processing_errors - Prevent cmds from being queued.
|
|
|
|
* @sdev: Device on which we are performing recovery.
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* We block until the host is out of error recovery, and then check to
|
|
|
|
* see whether the host or the device is offline.
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 when dev was taken offline by error recovery. 1 OK to proceed.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
int scsi_block_when_processing_errors(struct scsi_device *sdev)
|
|
|
|
{
|
|
|
|
int online;
|
|
|
|
|
2005-09-19 03:05:20 +07:00
|
|
|
wait_event(sdev->host->host_wait, !scsi_host_in_recovery(sdev->host));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
online = scsi_device_online(sdev);
|
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(5, sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: rtn: %d\n", __func__, online));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return online;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_block_when_processing_errors);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCSI_LOGGING
|
|
|
|
/**
|
|
|
|
* scsi_eh_prt_fail_stats - Log info on failures.
|
|
|
|
* @shost: scsi host being recovered.
|
|
|
|
* @work_q: Queue of scsi cmds to process.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q)
|
|
|
|
{
|
|
|
|
struct scsi_cmnd *scmd;
|
|
|
|
struct scsi_device *sdev;
|
|
|
|
int total_failures = 0;
|
|
|
|
int cmd_failed = 0;
|
|
|
|
int cmd_cancel = 0;
|
|
|
|
int devices_failed = 0;
|
|
|
|
|
|
|
|
shost_for_each_device(sdev, shost) {
|
|
|
|
list_for_each_entry(scmd, work_q, eh_entry) {
|
|
|
|
if (scmd->device == sdev) {
|
|
|
|
++total_failures;
|
2017-04-06 20:36:35 +07:00
|
|
|
if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED)
|
2005-04-17 05:20:36 +07:00
|
|
|
++cmd_cancel;
|
2011-03-22 02:47:31 +07:00
|
|
|
else
|
2005-04-17 05:20:36 +07:00
|
|
|
++cmd_failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd_cancel || cmd_failed) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 19:27:03 +07:00
|
|
|
shost_printk(KERN_INFO, shost,
|
2005-10-02 23:45:08 +07:00
|
|
|
"%s: cmds failed: %d, cancel: %d\n",
|
2008-07-04 13:47:27 +07:00
|
|
|
__func__, cmd_failed,
|
2005-10-02 23:45:08 +07:00
|
|
|
cmd_cancel));
|
2005-04-17 05:20:36 +07:00
|
|
|
cmd_cancel = 0;
|
|
|
|
cmd_failed = 0;
|
|
|
|
++devices_failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(2, shost_printk(KERN_INFO, shost,
|
|
|
|
"Total of %d commands on %d"
|
|
|
|
" devices require eh work\n",
|
2011-03-22 02:47:31 +07:00
|
|
|
total_failures, devices_failed));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-09 02:07:48 +07:00
|
|
|
/**
|
|
|
|
* scsi_report_lun_change - Set flag on all *other* devices on the same target
|
|
|
|
* to indicate that a UNIT ATTENTION is expected.
|
|
|
|
* @sdev: Device reporting the UNIT ATTENTION
|
|
|
|
*/
|
|
|
|
static void scsi_report_lun_change(struct scsi_device *sdev)
|
|
|
|
{
|
|
|
|
sdev->sdev_target->expecting_lun_change = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_report_sense - Examine scsi sense information and log messages for
|
|
|
|
* certain conditions, also issue uevents for some of them.
|
|
|
|
* @sdev: Device reporting the sense code
|
|
|
|
* @sshdr: sshdr to be examined
|
|
|
|
*/
|
|
|
|
static void scsi_report_sense(struct scsi_device *sdev,
|
|
|
|
struct scsi_sense_hdr *sshdr)
|
|
|
|
{
|
|
|
|
enum scsi_device_event evt_type = SDEV_EVT_MAXBITS; /* i.e. none */
|
|
|
|
|
|
|
|
if (sshdr->sense_key == UNIT_ATTENTION) {
|
|
|
|
if (sshdr->asc == 0x3f && sshdr->ascq == 0x03) {
|
|
|
|
evt_type = SDEV_EVT_INQUIRY_CHANGE_REPORTED;
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Inquiry data has changed");
|
|
|
|
} else if (sshdr->asc == 0x3f && sshdr->ascq == 0x0e) {
|
|
|
|
evt_type = SDEV_EVT_LUN_CHANGE_REPORTED;
|
|
|
|
scsi_report_lun_change(sdev);
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Warning! Received an indication that the "
|
|
|
|
"LUN assignments on this target have "
|
|
|
|
"changed. The Linux SCSI layer does not "
|
|
|
|
"automatically remap LUN assignments.\n");
|
|
|
|
} else if (sshdr->asc == 0x3f)
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Warning! Received an indication that the "
|
|
|
|
"operating parameters on this target have "
|
|
|
|
"changed. The Linux SCSI layer does not "
|
|
|
|
"automatically adjust these parameters.\n");
|
|
|
|
|
|
|
|
if (sshdr->asc == 0x38 && sshdr->ascq == 0x07) {
|
|
|
|
evt_type = SDEV_EVT_SOFT_THRESHOLD_REACHED_REPORTED;
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Warning! Received an indication that the "
|
|
|
|
"LUN reached a thin provisioning soft "
|
|
|
|
"threshold.\n");
|
|
|
|
}
|
|
|
|
|
2017-10-17 14:11:24 +07:00
|
|
|
if (sshdr->asc == 0x29) {
|
|
|
|
evt_type = SDEV_EVT_POWER_ON_RESET_OCCURRED;
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Power-on or device reset occurred\n");
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:07:48 +07:00
|
|
|
if (sshdr->asc == 0x2a && sshdr->ascq == 0x01) {
|
|
|
|
evt_type = SDEV_EVT_MODE_PARAMETER_CHANGE_REPORTED;
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Mode parameters changed");
|
2015-07-06 18:41:53 +07:00
|
|
|
} else if (sshdr->asc == 0x2a && sshdr->ascq == 0x06) {
|
|
|
|
evt_type = SDEV_EVT_ALUA_STATE_CHANGE_REPORTED;
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Asymmetric access state changed");
|
2013-08-09 02:07:48 +07:00
|
|
|
} else if (sshdr->asc == 0x2a && sshdr->ascq == 0x09) {
|
|
|
|
evt_type = SDEV_EVT_CAPACITY_CHANGE_REPORTED;
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Capacity data has changed");
|
|
|
|
} else if (sshdr->asc == 0x2a)
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Parameters changed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (evt_type != SDEV_EVT_MAXBITS) {
|
|
|
|
set_bit(evt_type, sdev->pending_events);
|
|
|
|
schedule_work(&sdev->event_work);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* scsi_check_sense - Examine scsi cmd sense
|
|
|
|
* @scmd: Cmd to have sense checked.
|
|
|
|
*
|
|
|
|
* Return value:
|
2013-07-01 20:16:24 +07:00
|
|
|
* SUCCESS or FAILED or NEEDS_RETRY or ADD_TO_MLQUEUE
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* When a deferred error is detected the current command has
|
|
|
|
* not been executed and needs retrying.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2016-04-04 16:44:01 +07:00
|
|
|
int scsi_check_sense(struct scsi_cmnd *scmd)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-05-02 04:49:46 +07:00
|
|
|
struct scsi_device *sdev = scmd->device;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
|
|
|
|
if (! scsi_command_normalize_sense(scmd, &sshdr))
|
|
|
|
return FAILED; /* no valid sense data */
|
|
|
|
|
2013-08-09 02:07:48 +07:00
|
|
|
scsi_report_sense(sdev, &sshdr);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (scsi_sense_is_deferred(&sshdr))
|
|
|
|
return NEEDS_RETRY;
|
|
|
|
|
2015-08-27 19:16:59 +07:00
|
|
|
if (sdev->handler && sdev->handler->check_sense) {
|
2008-05-02 04:49:46 +07:00
|
|
|
int rc;
|
|
|
|
|
2015-08-27 19:16:59 +07:00
|
|
|
rc = sdev->handler->check_sense(sdev, &sshdr);
|
2008-05-02 04:49:46 +07:00
|
|
|
if (rc != SCSI_RETURN_NOT_HANDLED)
|
|
|
|
return rc;
|
|
|
|
/* handler does not care. Drop down to default handling */
|
|
|
|
}
|
|
|
|
|
2014-11-07 04:11:22 +07:00
|
|
|
if (scmd->cmnd[0] == TEST_UNIT_READY && scmd->scsi_done != scsi_eh_done)
|
|
|
|
/*
|
|
|
|
* nasty: for mid-layer issued TURs, we need to return the
|
|
|
|
* actual sense data without any recovery attempt. For eh
|
|
|
|
* issued ones, we need to try to recover and interpret
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Previous logic looked for FILEMARK, EOM or ILI which are
|
|
|
|
* mainly associated with tapes and returned SUCCESS.
|
|
|
|
*/
|
|
|
|
if (sshdr.response_code == 0x70) {
|
|
|
|
/* fixed format */
|
|
|
|
if (scmd->sense_buffer[2] & 0xe0)
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* descriptor format: look for "stream commands sense data
|
|
|
|
* descriptor" (see SSC-3). Assume single sense data
|
|
|
|
* descriptor. Ignore ILI from SBC-2 READ LONG and WRITE LONG.
|
|
|
|
*/
|
|
|
|
if ((sshdr.additional_length > 3) &&
|
|
|
|
(scmd->sense_buffer[8] == 0x4) &&
|
|
|
|
(scmd->sense_buffer[11] & 0xe0))
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sshdr.sense_key) {
|
|
|
|
case NO_SENSE:
|
|
|
|
return SUCCESS;
|
|
|
|
case RECOVERED_ERROR:
|
|
|
|
return /* soft_error */ SUCCESS;
|
|
|
|
|
|
|
|
case ABORTED_COMMAND:
|
2008-07-17 15:28:33 +07:00
|
|
|
if (sshdr.asc == 0x10) /* DIF */
|
|
|
|
return SUCCESS;
|
|
|
|
|
2018-04-18 06:35:10 +07:00
|
|
|
if (sshdr.asc == 0x44 && sdev->sdev_bflags & BLIST_RETRY_ITF)
|
|
|
|
return ADD_TO_MLQUEUE;
|
2018-04-18 06:35:11 +07:00
|
|
|
if (sshdr.asc == 0xc1 && sshdr.ascq == 0x01 &&
|
|
|
|
sdev->sdev_bflags & BLIST_RETRY_ASC_C1)
|
|
|
|
return ADD_TO_MLQUEUE;
|
2018-04-18 06:35:10 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return NEEDS_RETRY;
|
|
|
|
case NOT_READY:
|
|
|
|
case UNIT_ATTENTION:
|
|
|
|
/*
|
|
|
|
* if we are expecting a cc/ua because of a bus reset that we
|
|
|
|
* performed, treat this just as a retry. otherwise this is
|
|
|
|
* information that we should pass up to the upper-level driver
|
|
|
|
* so that we can deal with it there.
|
|
|
|
*/
|
|
|
|
if (scmd->device->expecting_cc_ua) {
|
2011-08-11 18:25:20 +07:00
|
|
|
/*
|
|
|
|
* Because some device does not queue unit
|
|
|
|
* attentions correctly, we carefully check
|
|
|
|
* additional sense code and qualifier so as
|
|
|
|
* not to squash media change unit attention.
|
|
|
|
*/
|
|
|
|
if (sshdr.asc != 0x28 || sshdr.ascq != 0x00) {
|
|
|
|
scmd->device->expecting_cc_ua = 0;
|
|
|
|
return NEEDS_RETRY;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2013-08-09 02:07:48 +07:00
|
|
|
/*
|
|
|
|
* we might also expect a cc/ua if another LUN on the target
|
|
|
|
* reported a UA with an ASC/ASCQ of 3F 0E -
|
|
|
|
* REPORTED LUNS DATA HAS CHANGED.
|
|
|
|
*/
|
|
|
|
if (scmd->device->sdev_target->expecting_lun_change &&
|
|
|
|
sshdr.asc == 0x3f && sshdr.ascq == 0x0e)
|
|
|
|
return NEEDS_RETRY;
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2011-03-22 02:47:31 +07:00
|
|
|
* if the device is in the process of becoming ready, we
|
2005-04-17 05:20:36 +07:00
|
|
|
* should retry.
|
|
|
|
*/
|
|
|
|
if ((sshdr.asc == 0x04) && (sshdr.ascq == 0x01))
|
|
|
|
return NEEDS_RETRY;
|
|
|
|
/*
|
|
|
|
* if the device is not started, we need to wake
|
|
|
|
* the error handler to start the motor
|
|
|
|
*/
|
|
|
|
if (scmd->device->allow_restart &&
|
|
|
|
(sshdr.asc == 0x04) && (sshdr.ascq == 0x02))
|
|
|
|
return FAILED;
|
2010-11-10 20:54:09 +07:00
|
|
|
/*
|
|
|
|
* Pass the UA upwards for a determination in the completion
|
|
|
|
* functions.
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-01-18 16:13:11 +07:00
|
|
|
/* these are not supported */
|
2013-07-01 20:16:25 +07:00
|
|
|
case DATA_PROTECT:
|
|
|
|
if (sshdr.asc == 0x27 && sshdr.ascq == 0x07) {
|
|
|
|
/* Thin provisioning hard threshold reached */
|
|
|
|
set_host_byte(scmd, DID_ALLOC_FAILURE);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2017-08-26 03:46:29 +07:00
|
|
|
/* FALLTHROUGH */
|
2005-04-17 05:20:36 +07:00
|
|
|
case COPY_ABORTED:
|
|
|
|
case VOLUME_OVERFLOW:
|
|
|
|
case MISCOMPARE:
|
2011-01-18 16:13:11 +07:00
|
|
|
case BLANK_CHECK:
|
2013-07-01 20:16:24 +07:00
|
|
|
set_host_byte(scmd, DID_TARGET_FAILURE);
|
|
|
|
return SUCCESS;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
case MEDIUM_ERROR:
|
2006-11-30 10:45:23 +07:00
|
|
|
if (sshdr.asc == 0x11 || /* UNRECOVERED READ ERR */
|
|
|
|
sshdr.asc == 0x13 || /* AMNF DATA FIELD */
|
|
|
|
sshdr.asc == 0x14) { /* RECORD NOT FOUND */
|
2013-07-01 20:16:26 +07:00
|
|
|
set_host_byte(scmd, DID_MEDIUM_ERROR);
|
2013-07-01 20:16:24 +07:00
|
|
|
return SUCCESS;
|
2006-11-30 10:45:23 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
return NEEDS_RETRY;
|
|
|
|
|
|
|
|
case HARDWARE_ERROR:
|
|
|
|
if (scmd->device->retry_hwerror)
|
2008-08-13 02:11:58 +07:00
|
|
|
return ADD_TO_MLQUEUE;
|
2005-04-17 05:20:36 +07:00
|
|
|
else
|
2013-07-01 20:16:24 +07:00
|
|
|
set_host_byte(scmd, DID_TARGET_FAILURE);
|
2017-08-26 03:46:29 +07:00
|
|
|
/* FALLTHROUGH */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
case ILLEGAL_REQUEST:
|
2012-02-14 06:35:11 +07:00
|
|
|
if (sshdr.asc == 0x20 || /* Invalid command operation code */
|
|
|
|
sshdr.asc == 0x21 || /* Logical block address out of range */
|
2017-10-17 14:10:56 +07:00
|
|
|
sshdr.asc == 0x22 || /* Invalid function */
|
2012-02-14 06:35:11 +07:00
|
|
|
sshdr.asc == 0x24 || /* Invalid field in cdb */
|
2017-09-27 19:44:19 +07:00
|
|
|
sshdr.asc == 0x26 || /* Parameter value invalid */
|
|
|
|
sshdr.asc == 0x27) { /* Write protected */
|
2013-07-01 20:16:24 +07:00
|
|
|
set_host_byte(scmd, DID_TARGET_FAILURE);
|
2012-02-14 06:35:11 +07:00
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
default:
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2016-04-04 16:44:01 +07:00
|
|
|
EXPORT_SYMBOL_GPL(scsi_check_sense);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-10-23 05:46:33 +07:00
|
|
|
static void scsi_handle_queue_ramp_up(struct scsi_device *sdev)
|
|
|
|
{
|
|
|
|
struct scsi_host_template *sht = sdev->host->hostt;
|
|
|
|
struct scsi_device *tmp_sdev;
|
|
|
|
|
2014-11-13 20:25:11 +07:00
|
|
|
if (!sht->track_queue_depth ||
|
2009-10-23 05:46:33 +07:00
|
|
|
sdev->queue_depth >= sdev->max_queue_depth)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (time_before(jiffies,
|
|
|
|
sdev->last_queue_ramp_up + sdev->queue_ramp_up_period))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (time_before(jiffies,
|
|
|
|
sdev->last_queue_full_time + sdev->queue_ramp_up_period))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk all devices of a target and do
|
|
|
|
* ramp up on them.
|
|
|
|
*/
|
|
|
|
shost_for_each_device(tmp_sdev, sdev->host) {
|
|
|
|
if (tmp_sdev->channel != sdev->channel ||
|
|
|
|
tmp_sdev->id != sdev->id ||
|
|
|
|
tmp_sdev->queue_depth == sdev->max_queue_depth)
|
|
|
|
continue;
|
2014-11-13 20:25:11 +07:00
|
|
|
|
2014-11-13 21:08:42 +07:00
|
|
|
scsi_change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1);
|
2009-10-23 05:46:33 +07:00
|
|
|
sdev->last_queue_ramp_up = jiffies;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-16 07:46:44 +07:00
|
|
|
static void scsi_handle_queue_full(struct scsi_device *sdev)
|
|
|
|
{
|
|
|
|
struct scsi_host_template *sht = sdev->host->hostt;
|
|
|
|
struct scsi_device *tmp_sdev;
|
|
|
|
|
2014-11-13 20:25:11 +07:00
|
|
|
if (!sht->track_queue_depth)
|
2009-10-16 07:46:44 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
shost_for_each_device(tmp_sdev, sdev->host) {
|
|
|
|
if (tmp_sdev->channel != sdev->channel ||
|
|
|
|
tmp_sdev->id != sdev->id)
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* We do not know the number of commands that were at
|
|
|
|
* the device when we got the queue full so we start
|
|
|
|
* from the highest possible value and work our way down.
|
|
|
|
*/
|
2014-11-13 20:25:11 +07:00
|
|
|
scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1);
|
2009-10-16 07:46:44 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* scsi_eh_completed_normally - Disposition a eh cmd on return from LLD.
|
|
|
|
* @scmd: SCSI cmd to examine.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* This is *only* called when we are examining the status of commands
|
|
|
|
* queued during error recovery. the main difference here is that we
|
|
|
|
* don't allow for the possibility of retries here, and we are a lot
|
|
|
|
* more restrictive about what we consider acceptable.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* first check the host byte, to see if there is anything in there
|
|
|
|
* that would indicate what we need to do.
|
|
|
|
*/
|
|
|
|
if (host_byte(scmd->result) == DID_RESET) {
|
|
|
|
/*
|
|
|
|
* rats. we are already in the error handler, so we now
|
|
|
|
* get to try and figure out what to do next. if the sense
|
|
|
|
* is valid, we have a pretty good idea of what to do.
|
|
|
|
* if not, we mark it as FAILED.
|
|
|
|
*/
|
|
|
|
return scsi_check_sense(scmd);
|
|
|
|
}
|
|
|
|
if (host_byte(scmd->result) != DID_OK)
|
|
|
|
return FAILED;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* next, check the message byte.
|
|
|
|
*/
|
|
|
|
if (msg_byte(scmd->result) != COMMAND_COMPLETE)
|
|
|
|
return FAILED;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now, check the status byte to see if this indicates
|
|
|
|
* anything special.
|
|
|
|
*/
|
|
|
|
switch (status_byte(scmd->result)) {
|
|
|
|
case GOOD:
|
2009-10-23 05:46:33 +07:00
|
|
|
scsi_handle_queue_ramp_up(scmd->device);
|
2017-08-26 03:46:29 +07:00
|
|
|
/* FALLTHROUGH */
|
2005-04-17 05:20:36 +07:00
|
|
|
case COMMAND_TERMINATED:
|
|
|
|
return SUCCESS;
|
|
|
|
case CHECK_CONDITION:
|
|
|
|
return scsi_check_sense(scmd);
|
|
|
|
case CONDITION_GOOD:
|
|
|
|
case INTERMEDIATE_GOOD:
|
|
|
|
case INTERMEDIATE_C_GOOD:
|
|
|
|
/*
|
|
|
|
* who knows? FIXME(eric)
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
2009-08-10 23:59:28 +07:00
|
|
|
case RESERVATION_CONFLICT:
|
2010-08-07 03:17:24 +07:00
|
|
|
if (scmd->cmnd[0] == TEST_UNIT_READY)
|
|
|
|
/* it is a success, we probed the device and
|
|
|
|
* found it */
|
|
|
|
return SUCCESS;
|
|
|
|
/* otherwise, we failed to send the command */
|
|
|
|
return FAILED;
|
2005-04-17 05:20:36 +07:00
|
|
|
case QUEUE_FULL:
|
2009-10-16 07:46:44 +07:00
|
|
|
scsi_handle_queue_full(scmd->device);
|
|
|
|
/* fall through */
|
|
|
|
case BUSY:
|
2010-07-29 15:10:16 +07:00
|
|
|
return NEEDS_RETRY;
|
2005-04-17 05:20:36 +07:00
|
|
|
default:
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_done - Completion function for error handling.
|
|
|
|
* @scmd: Cmd that is done.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static void scsi_eh_done(struct scsi_cmnd *scmd)
|
|
|
|
{
|
2011-03-22 02:47:31 +07:00
|
|
|
struct completion *eh_action;
|
2005-12-08 10:46:27 +07:00
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"%s result: %x\n", __func__, scmd->result));
|
2005-12-08 10:46:27 +07:00
|
|
|
|
|
|
|
eh_action = scmd->device->host->eh_action;
|
|
|
|
if (eh_action)
|
|
|
|
complete(eh_action);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-01-31 06:51:17 +07:00
|
|
|
/**
|
|
|
|
* scsi_try_host_reset - ask host adapter to reset itself
|
2013-05-17 18:22:29 +07:00
|
|
|
* @scmd: SCSI cmd to send host reset.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2007-01-31 06:51:17 +07:00
|
|
|
static int scsi_try_host_reset(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int rtn;
|
2011-03-22 02:47:31 +07:00
|
|
|
struct Scsi_Host *host = scmd->device->host;
|
|
|
|
struct scsi_host_template *hostt = host->hostt;
|
2007-01-31 06:51:17 +07:00
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, host, "Snd Host RST\n"));
|
2007-01-31 06:51:17 +07:00
|
|
|
|
2011-03-22 02:47:31 +07:00
|
|
|
if (!hostt->eh_host_reset_handler)
|
2007-01-31 06:51:17 +07:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 02:47:31 +07:00
|
|
|
rtn = hostt->eh_host_reset_handler(scmd);
|
2007-01-31 06:51:17 +07:00
|
|
|
|
|
|
|
if (rtn == SUCCESS) {
|
2011-03-22 02:47:31 +07:00
|
|
|
if (!hostt->skip_settle_delay)
|
2007-01-31 06:51:17 +07:00
|
|
|
ssleep(HOST_RESET_SETTLE_TIME);
|
2011-03-22 02:47:31 +07:00
|
|
|
spin_lock_irqsave(host->host_lock, flags);
|
|
|
|
scsi_report_bus_reset(host, scmd_channel(scmd));
|
|
|
|
spin_unlock_irqrestore(host->host_lock, flags);
|
2007-01-31 06:51:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_try_bus_reset - ask host to perform a bus reset
|
|
|
|
* @scmd: SCSI cmd to send bus reset.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2007-01-31 06:51:17 +07:00
|
|
|
static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int rtn;
|
2011-03-22 02:47:31 +07:00
|
|
|
struct Scsi_Host *host = scmd->device->host;
|
|
|
|
struct scsi_host_template *hostt = host->hostt;
|
2007-01-31 06:51:17 +07:00
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: Snd Bus RST\n", __func__));
|
2007-01-31 06:51:17 +07:00
|
|
|
|
2011-03-22 02:47:31 +07:00
|
|
|
if (!hostt->eh_bus_reset_handler)
|
2007-01-31 06:51:17 +07:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 02:47:31 +07:00
|
|
|
rtn = hostt->eh_bus_reset_handler(scmd);
|
2007-01-31 06:51:17 +07:00
|
|
|
|
|
|
|
if (rtn == SUCCESS) {
|
2011-03-22 02:47:31 +07:00
|
|
|
if (!hostt->skip_settle_delay)
|
2007-01-31 06:51:17 +07:00
|
|
|
ssleep(BUS_RESET_SETTLE_TIME);
|
2011-03-22 02:47:31 +07:00
|
|
|
spin_lock_irqsave(host->host_lock, flags);
|
|
|
|
scsi_report_bus_reset(host, scmd_channel(scmd));
|
|
|
|
spin_unlock_irqrestore(host->host_lock, flags);
|
2007-01-31 06:51:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2008-03-01 07:25:19 +07:00
|
|
|
static void __scsi_report_device_reset(struct scsi_device *sdev, void *data)
|
|
|
|
{
|
|
|
|
sdev->was_reset = 1;
|
|
|
|
sdev->expecting_cc_ua = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_try_target_reset - Ask host to perform a target reset
|
|
|
|
* @scmd: SCSI cmd used to send a target reset
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* There is no timeout for this operation. if this operation is
|
|
|
|
* unreliable for a given host, then the host itself needs to put a
|
|
|
|
* timer on it, and set the host back to a consistent state prior to
|
|
|
|
* returning.
|
|
|
|
*/
|
|
|
|
static int scsi_try_target_reset(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int rtn;
|
2011-03-22 02:47:31 +07:00
|
|
|
struct Scsi_Host *host = scmd->device->host;
|
|
|
|
struct scsi_host_template *hostt = host->hostt;
|
2008-03-01 07:25:19 +07:00
|
|
|
|
2011-03-22 02:47:31 +07:00
|
|
|
if (!hostt->eh_target_reset_handler)
|
2008-03-01 07:25:19 +07:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 02:47:31 +07:00
|
|
|
rtn = hostt->eh_target_reset_handler(scmd);
|
2008-03-01 07:25:19 +07:00
|
|
|
if (rtn == SUCCESS) {
|
2011-03-22 02:47:31 +07:00
|
|
|
spin_lock_irqsave(host->host_lock, flags);
|
2008-03-01 07:25:19 +07:00
|
|
|
__starget_for_each_device(scsi_target(scmd->device), NULL,
|
|
|
|
__scsi_report_device_reset);
|
2011-03-22 02:47:31 +07:00
|
|
|
spin_unlock_irqrestore(host->host_lock, flags);
|
2008-03-01 07:25:19 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2007-01-31 06:51:17 +07:00
|
|
|
/**
|
|
|
|
* scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
|
|
|
|
* @scmd: SCSI cmd used to send BDR
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* There is no timeout for this operation. if this operation is
|
|
|
|
* unreliable for a given host, then the host itself needs to put a
|
|
|
|
* timer on it, and set the host back to a consistent state prior to
|
|
|
|
* returning.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2007-01-31 06:51:17 +07:00
|
|
|
static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
int rtn;
|
2011-03-22 02:47:31 +07:00
|
|
|
struct scsi_host_template *hostt = scmd->device->host->hostt;
|
2007-01-31 06:51:17 +07:00
|
|
|
|
2011-03-22 02:47:31 +07:00
|
|
|
if (!hostt->eh_device_reset_handler)
|
2007-01-31 06:51:17 +07:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 02:47:31 +07:00
|
|
|
rtn = hostt->eh_device_reset_handler(scmd);
|
2008-03-01 07:25:19 +07:00
|
|
|
if (rtn == SUCCESS)
|
|
|
|
__scsi_report_device_reset(scmd->device, NULL);
|
2007-01-31 06:51:17 +07:00
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2014-10-24 19:27:04 +07:00
|
|
|
/**
|
|
|
|
* scsi_try_to_abort_cmd - Ask host to abort a SCSI command
|
2014-12-30 00:40:56 +07:00
|
|
|
* @hostt: SCSI driver host template
|
2014-10-24 19:27:04 +07:00
|
|
|
* @scmd: SCSI cmd used to send a target reset
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* SUCCESS, FAILED, or FAST_IO_FAIL
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* SUCCESS does not necessarily indicate that the command
|
|
|
|
* has been aborted; it only indicates that the LLDDs
|
|
|
|
* has cleared all references to that command.
|
|
|
|
* LLDDs should return FAILED only if an abort was required
|
|
|
|
* but could not be executed. LLDDs should return FAST_IO_FAIL
|
|
|
|
* if the device is temporarily unavailable (eg due to a
|
|
|
|
* link down on FibreChannel)
|
|
|
|
*/
|
|
|
|
static int scsi_try_to_abort_cmd(struct scsi_host_template *hostt,
|
|
|
|
struct scsi_cmnd *scmd)
|
2007-01-31 06:51:17 +07:00
|
|
|
{
|
2011-03-22 02:47:31 +07:00
|
|
|
if (!hostt->eh_abort_handler)
|
2007-01-31 06:51:17 +07:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 02:47:31 +07:00
|
|
|
return hostt->eh_abort_handler(scmd);
|
2007-01-31 06:51:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
|
|
|
|
{
|
2011-03-22 02:47:31 +07:00
|
|
|
if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS)
|
2007-01-31 06:51:17 +07:00
|
|
|
if (scsi_try_bus_device_reset(scmd) != SUCCESS)
|
2008-03-01 07:25:19 +07:00
|
|
|
if (scsi_try_target_reset(scmd) != SUCCESS)
|
|
|
|
if (scsi_try_bus_reset(scmd) != SUCCESS)
|
|
|
|
scsi_try_host_reset(scmd);
|
2007-01-31 06:51:17 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
2012-04-08 20:17:09 +07:00
|
|
|
* scsi_eh_prep_cmnd - Save a scsi command info as part of error recovery
|
2006-11-05 02:04:21 +07:00
|
|
|
* @scmd: SCSI command structure to hijack
|
2007-10-08 21:36:45 +07:00
|
|
|
* @ses: structure to save restore information
|
2007-10-08 21:35:19 +07:00
|
|
|
* @cmnd: CDB to send. Can be NULL if no new cmnd is needed
|
2008-04-30 15:19:47 +07:00
|
|
|
* @cmnd_size: size in bytes of @cmnd (must be <= BLK_MAX_CDB)
|
2007-10-08 21:35:19 +07:00
|
|
|
* @sense_bytes: size of sense data to copy. or 0 (if != 0 @cmnd is ignored)
|
2006-11-05 02:04:21 +07:00
|
|
|
*
|
2007-10-08 21:36:45 +07:00
|
|
|
* This function is used to save a scsi command information before re-execution
|
2007-10-08 21:35:19 +07:00
|
|
|
* as part of the error recovery process. If @sense_bytes is 0 the command
|
|
|
|
* sent must be one that does not transfer any data. If @sense_bytes != 0
|
|
|
|
* @cmnd is ignored and this functions sets up a REQUEST_SENSE command
|
|
|
|
* and cmnd buffers to read @sense_bytes into @scmd->sense_buffer.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2007-10-08 21:36:45 +07:00
|
|
|
void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses,
|
|
|
|
unsigned char *cmnd, int cmnd_size, unsigned sense_bytes)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-04-18 03:00:23 +07:00
|
|
|
struct scsi_device *sdev = scmd->device;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-07-09 01:42:15 +07:00
|
|
|
/*
|
|
|
|
* We need saved copies of a number of fields - this is because
|
|
|
|
* error handling may need to overwrite these with different values
|
|
|
|
* to run different commands, and once error handling is complete,
|
|
|
|
* we will need to restore these values prior to running the actual
|
|
|
|
* command.
|
|
|
|
*/
|
2007-10-08 21:36:45 +07:00
|
|
|
ses->cmd_len = scmd->cmd_len;
|
2008-04-30 15:19:47 +07:00
|
|
|
ses->cmnd = scmd->cmnd;
|
2007-10-08 21:36:45 +07:00
|
|
|
ses->data_direction = scmd->sc_data_direction;
|
2007-12-13 18:47:40 +07:00
|
|
|
ses->sdb = scmd->sdb;
|
2007-12-13 18:50:53 +07:00
|
|
|
ses->next_rq = scmd->request->next_rq;
|
2007-10-08 21:36:45 +07:00
|
|
|
ses->result = scmd->result;
|
2008-07-21 21:25:52 +07:00
|
|
|
ses->underflow = scmd->underflow;
|
2008-07-17 15:28:31 +07:00
|
|
|
ses->prot_op = scmd->prot_op;
|
2017-04-06 20:36:33 +07:00
|
|
|
ses->eh_eflags = scmd->eh_eflags;
|
2006-07-09 01:42:15 +07:00
|
|
|
|
2008-07-17 15:28:31 +07:00
|
|
|
scmd->prot_op = SCSI_PROT_NORMAL;
|
2014-04-11 03:36:11 +07:00
|
|
|
scmd->eh_eflags = 0;
|
2008-04-30 15:19:47 +07:00
|
|
|
scmd->cmnd = ses->eh_cmnd;
|
|
|
|
memset(scmd->cmnd, 0, BLK_MAX_CDB);
|
2007-12-13 18:47:40 +07:00
|
|
|
memset(&scmd->sdb, 0, sizeof(scmd->sdb));
|
2007-12-13 18:50:53 +07:00
|
|
|
scmd->request->next_rq = NULL;
|
2014-03-29 00:51:15 +07:00
|
|
|
scmd->result = 0;
|
2007-12-13 18:47:40 +07:00
|
|
|
|
2007-10-08 21:35:19 +07:00
|
|
|
if (sense_bytes) {
|
2007-12-13 18:47:40 +07:00
|
|
|
scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE,
|
|
|
|
sense_bytes);
|
2007-10-08 21:36:45 +07:00
|
|
|
sg_init_one(&ses->sense_sgl, scmd->sense_buffer,
|
2007-12-13 18:47:40 +07:00
|
|
|
scmd->sdb.length);
|
|
|
|
scmd->sdb.table.sgl = &ses->sense_sgl;
|
2007-10-08 21:35:19 +07:00
|
|
|
scmd->sc_data_direction = DMA_FROM_DEVICE;
|
2015-07-16 22:40:41 +07:00
|
|
|
scmd->sdb.table.nents = scmd->sdb.table.orig_nents = 1;
|
2007-10-08 21:35:19 +07:00
|
|
|
scmd->cmnd[0] = REQUEST_SENSE;
|
2007-12-13 18:47:40 +07:00
|
|
|
scmd->cmnd[4] = scmd->sdb.length;
|
2007-10-08 21:35:19 +07:00
|
|
|
scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
|
2006-07-09 01:42:15 +07:00
|
|
|
} else {
|
|
|
|
scmd->sc_data_direction = DMA_NONE;
|
2007-10-08 21:35:19 +07:00
|
|
|
if (cmnd) {
|
2008-04-30 15:19:47 +07:00
|
|
|
BUG_ON(cmnd_size > BLK_MAX_CDB);
|
2007-10-08 21:35:19 +07:00
|
|
|
memcpy(scmd->cmnd, cmnd, cmnd_size);
|
|
|
|
scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
|
|
|
|
}
|
2006-07-09 01:42:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
scmd->underflow = 0;
|
|
|
|
|
2007-10-08 21:35:19 +07:00
|
|
|
if (sdev->scsi_level <= SCSI_2 && sdev->scsi_level != SCSI_UNKNOWN)
|
2005-04-17 05:20:36 +07:00
|
|
|
scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) |
|
2005-04-18 03:00:23 +07:00
|
|
|
(sdev->lun << 5 & 0xe0);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-07-09 01:42:15 +07:00
|
|
|
/*
|
|
|
|
* Zero the sense buffer. The scsi spec mandates that any
|
|
|
|
* untransferred sense data should be interpreted as being zero.
|
|
|
|
*/
|
2008-01-13 13:46:13 +07:00
|
|
|
memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
|
2007-10-08 21:36:45 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_eh_prep_cmnd);
|
|
|
|
|
|
|
|
/**
|
2012-04-08 20:17:09 +07:00
|
|
|
* scsi_eh_restore_cmnd - Restore a scsi command info as part of error recovery
|
2007-10-08 21:36:45 +07:00
|
|
|
* @scmd: SCSI command structure to restore
|
2009-04-28 01:54:22 +07:00
|
|
|
* @ses: saved information from a coresponding call to scsi_eh_prep_cmnd
|
2007-10-08 21:36:45 +07:00
|
|
|
*
|
2009-04-28 01:54:22 +07:00
|
|
|
* Undo any damage done by above scsi_eh_prep_cmnd().
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2007-10-08 21:36:45 +07:00
|
|
|
void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct scsi_eh_save *ses)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Restore original data
|
|
|
|
*/
|
|
|
|
scmd->cmd_len = ses->cmd_len;
|
2008-04-30 15:19:47 +07:00
|
|
|
scmd->cmnd = ses->cmnd;
|
2007-10-08 21:36:45 +07:00
|
|
|
scmd->sc_data_direction = ses->data_direction;
|
2007-12-13 18:47:40 +07:00
|
|
|
scmd->sdb = ses->sdb;
|
2007-12-13 18:50:53 +07:00
|
|
|
scmd->request->next_rq = ses->next_rq;
|
2007-10-08 21:36:45 +07:00
|
|
|
scmd->result = ses->result;
|
2008-07-21 21:25:52 +07:00
|
|
|
scmd->underflow = ses->underflow;
|
2008-07-17 15:28:31 +07:00
|
|
|
scmd->prot_op = ses->prot_op;
|
2017-04-06 20:36:33 +07:00
|
|
|
scmd->eh_eflags = ses->eh_eflags;
|
2007-10-08 21:36:45 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_eh_restore_cmnd);
|
2006-07-09 01:42:15 +07:00
|
|
|
|
2007-10-08 21:36:45 +07:00
|
|
|
/**
|
2012-04-08 20:17:09 +07:00
|
|
|
* scsi_send_eh_cmnd - submit a scsi command as part of error recovery
|
2007-10-08 21:36:45 +07:00
|
|
|
* @scmd: SCSI command structure to hijack
|
|
|
|
* @cmnd: CDB to send
|
|
|
|
* @cmnd_size: size in bytes of @cmnd
|
|
|
|
* @timeout: timeout for this request
|
|
|
|
* @sense_bytes: size of sense data to copy or 0
|
|
|
|
*
|
|
|
|
* This function is used to send a scsi command down to a target device
|
|
|
|
* as part of the error recovery process. See also scsi_eh_prep_cmnd() above.
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* SUCCESS or FAILED or NEEDS_RETRY
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2007-10-08 21:36:45 +07:00
|
|
|
static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, unsigned char *cmnd,
|
|
|
|
int cmnd_size, int timeout, unsigned sense_bytes)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev = scmd->device;
|
|
|
|
struct Scsi_Host *shost = sdev->host;
|
|
|
|
DECLARE_COMPLETION_ONSTACK(done);
|
2013-04-25 13:10:00 +07:00
|
|
|
unsigned long timeleft = timeout;
|
2007-10-08 21:36:45 +07:00
|
|
|
struct scsi_eh_save ses;
|
2013-04-25 13:10:00 +07:00
|
|
|
const unsigned long stall_for = msecs_to_jiffies(100);
|
2007-10-08 21:36:45 +07:00
|
|
|
int rtn;
|
|
|
|
|
2013-04-25 13:10:00 +07:00
|
|
|
retry:
|
2007-10-08 21:36:45 +07:00
|
|
|
scsi_eh_prep_cmnd(scmd, &ses, cmnd, cmnd_size, sense_bytes);
|
2005-11-01 00:49:52 +07:00
|
|
|
shost->eh_action = &done;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
scsi_log_send(scmd);
|
2010-11-16 14:10:29 +07:00
|
|
|
scmd->scsi_done = scsi_eh_done;
|
2013-04-25 13:10:00 +07:00
|
|
|
rtn = shost->hostt->queuecommand(shost, scmd);
|
|
|
|
if (rtn) {
|
|
|
|
if (timeleft > stall_for) {
|
|
|
|
scsi_eh_restore_cmnd(scmd, &ses);
|
|
|
|
timeleft -= stall_for;
|
|
|
|
msleep(jiffies_to_msecs(stall_for));
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
/* signal not to enter either branch of the if () below */
|
|
|
|
timeleft = 0;
|
2014-11-21 22:44:49 +07:00
|
|
|
rtn = FAILED;
|
2013-04-25 13:10:00 +07:00
|
|
|
} else {
|
|
|
|
timeleft = wait_for_completion_timeout(&done, timeout);
|
2014-05-08 13:09:56 +07:00
|
|
|
rtn = SUCCESS;
|
2013-04-25 13:10:00 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-04-18 03:00:23 +07:00
|
|
|
shost->eh_action = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-04-25 13:10:00 +07:00
|
|
|
scsi_log_completion(scmd, rtn);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"%s timeleft: %ld\n",
|
|
|
|
__func__, timeleft));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
2013-04-25 13:10:00 +07:00
|
|
|
* If there is time left scsi_eh_done got called, and we will examine
|
|
|
|
* the actual status codes to see whether the command actually did
|
|
|
|
* complete normally, else if we have a zero return and no time left,
|
|
|
|
* the command must still be pending, so abort it and return FAILED.
|
|
|
|
* If we never actually managed to issue the command, because
|
|
|
|
* ->queuecommand() kept returning non zero, use the rtn = FAILED
|
|
|
|
* value above (so don't execute either branch of the if)
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2005-11-01 00:49:52 +07:00
|
|
|
if (timeleft) {
|
2005-04-17 05:20:36 +07:00
|
|
|
rtn = scsi_eh_completed_normally(scmd);
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: scsi_eh_completed_normally %x\n", __func__, rtn));
|
2005-11-01 00:49:52 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
switch (rtn) {
|
|
|
|
case SUCCESS:
|
|
|
|
case NEEDS_RETRY:
|
|
|
|
case FAILED:
|
|
|
|
break;
|
2009-09-17 22:00:26 +07:00
|
|
|
case ADD_TO_MLQUEUE:
|
|
|
|
rtn = NEEDS_RETRY;
|
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
default:
|
|
|
|
rtn = FAILED;
|
|
|
|
break;
|
|
|
|
}
|
2014-11-21 22:44:49 +07:00
|
|
|
} else if (rtn != FAILED) {
|
2007-01-31 06:51:17 +07:00
|
|
|
scsi_abort_eh_cmnd(scmd);
|
2005-11-01 00:49:52 +07:00
|
|
|
rtn = FAILED;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-10-08 21:36:45 +07:00
|
|
|
scsi_eh_restore_cmnd(scmd, &ses);
|
2012-02-10 01:48:53 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_request_sense - Request sense data from a particular target.
|
|
|
|
* @scmd: SCSI cmd for request sense.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* Some hosts automatically obtain this information, others require
|
|
|
|
* that we obtain it on our own. This function will *not* return until
|
|
|
|
* the command either times out, or it completes.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static int scsi_request_sense(struct scsi_cmnd *scmd)
|
|
|
|
{
|
2013-05-10 21:36:04 +07:00
|
|
|
return scsi_send_eh_cmnd(scmd, NULL, 0, scmd->device->eh_timeout, ~0);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2013-11-11 19:44:53 +07:00
|
|
|
static int scsi_eh_action(struct scsi_cmnd *scmd, int rtn)
|
|
|
|
{
|
2017-01-31 22:57:29 +07:00
|
|
|
if (!blk_rq_is_passthrough(scmd->request)) {
|
2013-11-11 19:44:53 +07:00
|
|
|
struct scsi_driver *sdrv = scsi_cmd_to_driver(scmd);
|
|
|
|
if (sdrv->eh_action)
|
|
|
|
rtn = sdrv->eh_action(scmd, rtn);
|
|
|
|
}
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
|
|
|
|
* @scmd: Original SCSI cmd that eh has finished.
|
|
|
|
* @done_q: Queue for processed commands.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* We don't want to use the normal command completion while we are are
|
|
|
|
* still handling errors - it may cause other commands to be queued,
|
2007-11-04 01:30:39 +07:00
|
|
|
* and that would disturb what we are doing. Thus we really want to
|
2005-04-17 05:20:36 +07:00
|
|
|
* keep a list of pending commands for final completion, and once we
|
|
|
|
* are ready to leave error handling we handle completion for real.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2006-01-23 11:09:36 +07:00
|
|
|
void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
list_move_tail(&scmd->eh_entry, done_q);
|
|
|
|
}
|
2006-01-23 11:09:36 +07:00
|
|
|
EXPORT_SYMBOL(scsi_eh_finish_cmd);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_get_sense - Get device sense data.
|
|
|
|
* @work_q: Queue of commands to process.
|
2007-11-04 01:30:39 +07:00
|
|
|
* @done_q: Queue of processed commands.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* See if we need to request sense information. if so, then get it
|
2011-03-22 02:47:31 +07:00
|
|
|
* now, so we have a better idea of what to do.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* This has the unfortunate side effect that if a shost adapter does
|
2007-11-04 01:30:39 +07:00
|
|
|
* not automatically request sense information, we end up shutting
|
2005-04-17 05:20:36 +07:00
|
|
|
* it down before we request it.
|
|
|
|
*
|
|
|
|
* All drivers should request sense information internally these days,
|
|
|
|
* so for now all I have to say is tough noogies if you end up in here.
|
|
|
|
*
|
|
|
|
* XXX: Long term this code should go away, but that needs an audit of
|
|
|
|
* all LLDDs first.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2007-01-27 05:08:49 +07:00
|
|
|
int scsi_eh_get_sense(struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-06-19 18:43:56 +07:00
|
|
|
struct scsi_cmnd *scmd, *next;
|
2013-10-23 15:51:21 +07:00
|
|
|
struct Scsi_Host *shost;
|
2005-04-17 05:20:36 +07:00
|
|
|
int rtn;
|
|
|
|
|
2015-07-31 16:52:10 +07:00
|
|
|
/*
|
|
|
|
* If SCSI_EH_ABORT_SCHEDULED has been set, it is timeout IO,
|
|
|
|
* should not get sense.
|
|
|
|
*/
|
2005-06-19 18:43:56 +07:00
|
|
|
list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
|
2017-04-06 20:36:35 +07:00
|
|
|
if ((scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) ||
|
2005-04-17 05:20:36 +07:00
|
|
|
SCSI_SENSE_VALID(scmd))
|
|
|
|
continue;
|
|
|
|
|
2013-10-23 15:51:21 +07:00
|
|
|
shost = scmd->device->host;
|
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 19:27:02 +07:00
|
|
|
scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: skip request sense, past eh deadline\n",
|
|
|
|
current->comm));
|
2013-10-23 15:51:21 +07:00
|
|
|
break;
|
|
|
|
}
|
2014-03-29 00:50:17 +07:00
|
|
|
if (status_byte(scmd->result) != CHECK_CONDITION)
|
|
|
|
/*
|
|
|
|
* don't request sense if there's no check condition
|
|
|
|
* status because the error we're processing isn't one
|
|
|
|
* that has a sense code (and some devices get
|
|
|
|
* confused by sense requests out of the blue)
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
|
2005-10-25 05:04:06 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(2, scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: requesting sense\n",
|
|
|
|
current->comm));
|
2005-04-17 05:20:36 +07:00
|
|
|
rtn = scsi_request_sense(scmd);
|
|
|
|
if (rtn != SUCCESS)
|
|
|
|
continue;
|
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"sense requested, result %x\n", scmd->result));
|
2014-10-24 19:26:45 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense(scmd));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
rtn = scsi_decide_disposition(scmd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the result was normal, then just pass it along to the
|
|
|
|
* upper level.
|
|
|
|
*/
|
|
|
|
if (rtn == SUCCESS)
|
|
|
|
/* we don't want this command reissued, just
|
|
|
|
* finished with the sense data, so set
|
|
|
|
* retries to the max allowed to ensure it
|
|
|
|
* won't get reissued */
|
|
|
|
scmd->retries = scmd->allowed;
|
|
|
|
else if (rtn != NEEDS_RETRY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
2007-01-27 05:08:49 +07:00
|
|
|
EXPORT_SYMBOL_GPL(scsi_eh_get_sense);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_tur - Send TUR to device.
|
2007-11-04 01:30:39 +07:00
|
|
|
* @scmd: &scsi_cmnd to send TUR
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 - Device is ready. 1 - Device NOT ready.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static int scsi_eh_tur(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0};
|
|
|
|
int retry_cnt = 1, rtn;
|
|
|
|
|
|
|
|
retry_tur:
|
2013-05-10 21:36:04 +07:00
|
|
|
rtn = scsi_send_eh_cmnd(scmd, tur_command, 6,
|
|
|
|
scmd->device->eh_timeout, 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"%s return: %x\n", __func__, rtn));
|
2006-07-09 01:42:15 +07:00
|
|
|
|
|
|
|
switch (rtn) {
|
|
|
|
case NEEDS_RETRY:
|
2005-04-17 05:20:36 +07:00
|
|
|
if (retry_cnt--)
|
|
|
|
goto retry_tur;
|
2006-07-09 01:42:15 +07:00
|
|
|
/*FALLTHRU*/
|
|
|
|
case SUCCESS:
|
2005-03-31 03:05:45 +07:00
|
|
|
return 0;
|
2006-07-09 01:42:15 +07:00
|
|
|
default:
|
|
|
|
return 1;
|
2005-03-31 03:05:45 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2011-05-20 01:41:12 +07:00
|
|
|
/**
|
|
|
|
* scsi_eh_test_devices - check if devices are responding from error recovery.
|
|
|
|
* @cmd_list: scsi commands in error recovery.
|
2014-08-17 04:15:11 +07:00
|
|
|
* @work_q: queue for commands which still need more error recovery
|
|
|
|
* @done_q: queue for commands which are finished
|
|
|
|
* @try_stu: boolean on if a STU command should be tried in addition to TUR.
|
2011-05-20 01:41:12 +07:00
|
|
|
*
|
|
|
|
* Decription:
|
|
|
|
* Tests if devices are in a working state. Commands to devices now in
|
|
|
|
* a working state are sent to the done_q while commands to devices which
|
|
|
|
* are still failing to respond are returned to the work_q for more
|
|
|
|
* processing.
|
|
|
|
**/
|
|
|
|
static int scsi_eh_test_devices(struct list_head *cmd_list,
|
|
|
|
struct list_head *work_q,
|
|
|
|
struct list_head *done_q, int try_stu)
|
|
|
|
{
|
|
|
|
struct scsi_cmnd *scmd, *next;
|
|
|
|
struct scsi_device *sdev;
|
|
|
|
int finish_cmds;
|
|
|
|
|
|
|
|
while (!list_empty(cmd_list)) {
|
|
|
|
scmd = list_entry(cmd_list->next, struct scsi_cmnd, eh_entry);
|
|
|
|
sdev = scmd->device;
|
|
|
|
|
2013-10-23 15:51:21 +07:00
|
|
|
if (!try_stu) {
|
|
|
|
if (scsi_host_eh_past_deadline(sdev->host)) {
|
|
|
|
/* Push items back onto work_q */
|
|
|
|
list_splice_init(cmd_list, work_q);
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 19:27:02 +07:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: skip test device, past eh deadline",
|
|
|
|
current->comm));
|
2013-10-23 15:51:21 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-20 01:41:12 +07:00
|
|
|
finish_cmds = !scsi_device_online(scmd->device) ||
|
|
|
|
(try_stu && !scsi_eh_try_stu(scmd) &&
|
|
|
|
!scsi_eh_tur(scmd)) ||
|
|
|
|
!scsi_eh_tur(scmd);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(scmd, next, cmd_list, eh_entry)
|
|
|
|
if (scmd->device == sdev) {
|
2013-11-11 19:44:53 +07:00
|
|
|
if (finish_cmds &&
|
|
|
|
(try_stu ||
|
|
|
|
scsi_eh_action(scmd, SUCCESS) == SUCCESS))
|
2011-05-20 01:41:12 +07:00
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
else
|
|
|
|
list_move_tail(&scmd->eh_entry, work_q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* scsi_eh_try_stu - Send START_UNIT to device.
|
2007-11-04 01:30:39 +07:00
|
|
|
* @scmd: &scsi_cmnd to send START_UNIT
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 - Device is ready. 1 - Device NOT ready.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0};
|
|
|
|
|
2006-07-09 01:42:15 +07:00
|
|
|
if (scmd->device->allow_restart) {
|
2007-03-30 03:25:52 +07:00
|
|
|
int i, rtn = NEEDS_RETRY;
|
|
|
|
|
|
|
|
for (i = 0; rtn == NEEDS_RETRY && i < 2; i++)
|
2008-11-30 23:32:26 +07:00
|
|
|
rtn = scsi_send_eh_cmnd(scmd, stu_command, 6, scmd->device->request_queue->rq_timeout, 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-07-09 01:42:15 +07:00
|
|
|
if (rtn == SUCCESS)
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_stu - send START_UNIT if needed
|
2007-11-04 01:30:39 +07:00
|
|
|
* @shost: &scsi host being recovered.
|
2014-08-17 04:15:11 +07:00
|
|
|
* @work_q: &list_head for pending commands.
|
2007-11-04 01:30:39 +07:00
|
|
|
* @done_q: &list_head for processed commands.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* If commands are failing due to not ready, initializing command required,
|
2011-03-22 02:47:31 +07:00
|
|
|
* try revalidating the device, which will end up sending a start unit.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static int scsi_eh_stu(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2005-06-19 18:43:56 +07:00
|
|
|
struct scsi_cmnd *scmd, *stu_scmd, *next;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct scsi_device *sdev;
|
|
|
|
|
|
|
|
shost_for_each_device(sdev, shost) {
|
2013-10-23 15:51:21 +07:00
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 19:27:02 +07:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: skip START_UNIT, past eh deadline\n",
|
|
|
|
current->comm));
|
2013-10-23 15:51:21 +07:00
|
|
|
break;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
stu_scmd = NULL;
|
|
|
|
list_for_each_entry(scmd, work_q, eh_entry)
|
|
|
|
if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) &&
|
|
|
|
scsi_check_sense(scmd) == FAILED ) {
|
|
|
|
stu_scmd = scmd;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stu_scmd)
|
|
|
|
continue;
|
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 19:27:02 +07:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: Sending START_UNIT\n",
|
|
|
|
current->comm));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (!scsi_eh_try_stu(stu_scmd)) {
|
|
|
|
if (!scsi_device_online(sdev) ||
|
|
|
|
!scsi_eh_tur(stu_scmd)) {
|
2005-06-19 18:43:56 +07:00
|
|
|
list_for_each_entry_safe(scmd, next,
|
|
|
|
work_q, eh_entry) {
|
2013-11-11 19:44:53 +07:00
|
|
|
if (scmd->device == sdev &&
|
|
|
|
scsi_eh_action(scmd, SUCCESS) == SUCCESS)
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 19:27:02 +07:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: START_UNIT failed\n",
|
|
|
|
current->comm));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_bus_device_reset - send bdr if needed
|
|
|
|
* @shost: scsi host being recovered.
|
2014-08-17 04:15:11 +07:00
|
|
|
* @work_q: &list_head for pending commands.
|
2007-11-04 01:30:39 +07:00
|
|
|
* @done_q: &list_head for processed commands.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Notes:
|
2007-11-04 01:30:39 +07:00
|
|
|
* Try a bus device reset. Still, look to see whether we have multiple
|
2005-04-17 05:20:36 +07:00
|
|
|
* devices that are jammed or not - if we have multiple devices, it
|
|
|
|
* makes no sense to try bus_device_reset - we really would need to try
|
2011-03-22 02:47:31 +07:00
|
|
|
* a bus_reset instead.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2005-06-19 18:43:56 +07:00
|
|
|
struct scsi_cmnd *scmd, *bdr_scmd, *next;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct scsi_device *sdev;
|
|
|
|
int rtn;
|
|
|
|
|
|
|
|
shost_for_each_device(sdev, shost) {
|
2013-10-23 15:51:21 +07:00
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 19:27:02 +07:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: skip BDR, past eh deadline\n",
|
|
|
|
current->comm));
|
2013-10-23 15:51:21 +07:00
|
|
|
break;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
bdr_scmd = NULL;
|
|
|
|
list_for_each_entry(scmd, work_q, eh_entry)
|
|
|
|
if (scmd->device == sdev) {
|
|
|
|
bdr_scmd = scmd;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bdr_scmd)
|
|
|
|
continue;
|
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 19:27:02 +07:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: Sending BDR\n", current->comm));
|
2005-04-17 05:20:36 +07:00
|
|
|
rtn = scsi_try_bus_device_reset(bdr_scmd);
|
2010-03-24 22:50:30 +07:00
|
|
|
if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!scsi_device_online(sdev) ||
|
2010-03-24 22:50:30 +07:00
|
|
|
rtn == FAST_IO_FAIL ||
|
2005-04-17 05:20:36 +07:00
|
|
|
!scsi_eh_tur(bdr_scmd)) {
|
2005-06-19 18:43:56 +07:00
|
|
|
list_for_each_entry_safe(scmd, next,
|
|
|
|
work_q, eh_entry) {
|
2013-11-11 19:44:53 +07:00
|
|
|
if (scmd->device == sdev &&
|
|
|
|
scsi_eh_action(scmd, rtn) != FAILED)
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_eh_finish_cmd(scmd,
|
|
|
|
done_q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 19:27:02 +07:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: BDR failed\n", current->comm));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
|
|
|
|
2008-03-01 07:25:19 +07:00
|
|
|
/**
|
|
|
|
* scsi_eh_target_reset - send target reset if needed
|
|
|
|
* @shost: scsi host being recovered.
|
2014-08-17 04:15:11 +07:00
|
|
|
* @work_q: &list_head for pending commands.
|
2008-03-01 07:25:19 +07:00
|
|
|
* @done_q: &list_head for processed commands.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* Try a target reset.
|
|
|
|
*/
|
|
|
|
static int scsi_eh_target_reset(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2010-10-26 03:53:41 +07:00
|
|
|
LIST_HEAD(tmp_list);
|
2011-05-20 01:41:12 +07:00
|
|
|
LIST_HEAD(check_list);
|
2008-03-01 07:25:19 +07:00
|
|
|
|
2010-10-26 03:53:41 +07:00
|
|
|
list_splice_init(work_q, &tmp_list);
|
|
|
|
|
|
|
|
while (!list_empty(&tmp_list)) {
|
|
|
|
struct scsi_cmnd *next, *scmd;
|
|
|
|
int rtn;
|
|
|
|
unsigned int id;
|
2013-10-23 15:51:21 +07:00
|
|
|
|
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
|
|
|
/* push back on work queue for further processing */
|
|
|
|
list_splice_init(&check_list, work_q);
|
|
|
|
list_splice_init(&tmp_list, work_q);
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
2014-10-24 19:27:02 +07:00
|
|
|
"%s: Skip target reset, past eh deadline\n",
|
|
|
|
current->comm));
|
2013-10-23 15:51:21 +07:00
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
2010-10-26 03:53:41 +07:00
|
|
|
|
|
|
|
scmd = list_entry(tmp_list.next, struct scsi_cmnd, eh_entry);
|
|
|
|
id = scmd_id(scmd);
|
2008-03-01 07:25:19 +07:00
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: Sending target reset to target %d\n",
|
|
|
|
current->comm, id));
|
2010-10-26 03:53:41 +07:00
|
|
|
rtn = scsi_try_target_reset(scmd);
|
|
|
|
if (rtn != SUCCESS && rtn != FAST_IO_FAIL)
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: Target reset failed"
|
|
|
|
" target: %d\n",
|
|
|
|
current->comm, id));
|
2010-10-26 03:53:41 +07:00
|
|
|
list_for_each_entry_safe(scmd, next, &tmp_list, eh_entry) {
|
|
|
|
if (scmd_id(scmd) != id)
|
|
|
|
continue;
|
|
|
|
|
2011-05-20 01:41:12 +07:00
|
|
|
if (rtn == SUCCESS)
|
|
|
|
list_move_tail(&scmd->eh_entry, &check_list);
|
|
|
|
else if (rtn == FAST_IO_FAIL)
|
2010-10-26 03:53:41 +07:00
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
else
|
|
|
|
/* push back on work queue for further processing */
|
|
|
|
list_move(&scmd->eh_entry, work_q);
|
|
|
|
}
|
|
|
|
}
|
2008-03-01 07:25:19 +07:00
|
|
|
|
2011-05-20 01:41:12 +07:00
|
|
|
return scsi_eh_test_devices(&check_list, work_q, done_q, 0);
|
2008-03-01 07:25:19 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
2011-03-22 02:47:31 +07:00
|
|
|
* scsi_eh_bus_reset - send a bus reset
|
2007-11-04 01:30:39 +07:00
|
|
|
* @shost: &scsi host being recovered.
|
2014-08-17 04:15:11 +07:00
|
|
|
* @work_q: &list_head for pending commands.
|
2007-11-04 01:30:39 +07:00
|
|
|
* @done_q: &list_head for processed commands.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static int scsi_eh_bus_reset(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2005-06-19 18:43:56 +07:00
|
|
|
struct scsi_cmnd *scmd, *chan_scmd, *next;
|
2011-05-20 01:41:12 +07:00
|
|
|
LIST_HEAD(check_list);
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned int channel;
|
|
|
|
int rtn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we really want to loop over the various channels, and do this on
|
|
|
|
* a channel by channel basis. we should also check to see if any
|
|
|
|
* of the failed commands are on soft_reset devices, and if so, skip
|
2011-03-22 02:47:31 +07:00
|
|
|
* the reset.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
for (channel = 0; channel <= shost->max_channel; channel++) {
|
2013-10-23 15:51:21 +07:00
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
|
|
|
list_splice_init(&check_list, work_q);
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
2014-10-24 19:27:02 +07:00
|
|
|
"%s: skip BRST, past eh deadline\n",
|
|
|
|
current->comm));
|
2013-10-23 15:51:21 +07:00
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
chan_scmd = NULL;
|
|
|
|
list_for_each_entry(scmd, work_q, eh_entry) {
|
2005-10-25 05:05:09 +07:00
|
|
|
if (channel == scmd_channel(scmd)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
chan_scmd = scmd;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* FIXME add back in some support for
|
|
|
|
* soft_reset devices.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!chan_scmd)
|
|
|
|
continue;
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: Sending BRST chan: %d\n",
|
|
|
|
current->comm, channel));
|
2005-04-17 05:20:36 +07:00
|
|
|
rtn = scsi_try_bus_reset(chan_scmd);
|
2010-03-24 22:50:30 +07:00
|
|
|
if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
|
2005-06-19 18:43:56 +07:00
|
|
|
list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
|
2011-05-20 01:41:12 +07:00
|
|
|
if (channel == scmd_channel(scmd)) {
|
|
|
|
if (rtn == FAST_IO_FAIL)
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_eh_finish_cmd(scmd,
|
|
|
|
done_q);
|
2011-05-20 01:41:12 +07:00
|
|
|
else
|
|
|
|
list_move_tail(&scmd->eh_entry,
|
|
|
|
&check_list);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
} else {
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: BRST failed chan: %d\n",
|
|
|
|
current->comm, channel));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
2011-05-20 01:41:12 +07:00
|
|
|
return scsi_eh_test_devices(&check_list, work_q, done_q, 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-03-22 02:47:31 +07:00
|
|
|
* scsi_eh_host_reset - send a host reset
|
2014-08-17 04:15:11 +07:00
|
|
|
* @shost: host to be reset.
|
|
|
|
* @work_q: &list_head for pending commands.
|
|
|
|
* @done_q: &list_head for processed commands.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2014-06-25 21:39:59 +07:00
|
|
|
static int scsi_eh_host_reset(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
2005-04-17 05:20:36 +07:00
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2005-06-19 18:43:56 +07:00
|
|
|
struct scsi_cmnd *scmd, *next;
|
2011-05-20 01:41:12 +07:00
|
|
|
LIST_HEAD(check_list);
|
2005-04-17 05:20:36 +07:00
|
|
|
int rtn;
|
|
|
|
|
|
|
|
if (!list_empty(work_q)) {
|
|
|
|
scmd = list_entry(work_q->next,
|
|
|
|
struct scsi_cmnd, eh_entry);
|
|
|
|
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: Sending HRST\n",
|
|
|
|
current->comm));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
rtn = scsi_try_host_reset(scmd);
|
2011-05-20 01:41:12 +07:00
|
|
|
if (rtn == SUCCESS) {
|
|
|
|
list_splice_init(work_q, &check_list);
|
|
|
|
} else if (rtn == FAST_IO_FAIL) {
|
2005-06-19 18:43:56 +07:00
|
|
|
list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
}
|
|
|
|
} else {
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: HRST failed\n",
|
|
|
|
current->comm));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
2011-05-20 01:41:12 +07:00
|
|
|
return scsi_eh_test_devices(&check_list, work_q, done_q, 1);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_offline_sdevs - offline scsi devices that fail to recover
|
2014-08-17 04:15:11 +07:00
|
|
|
* @work_q: &list_head for pending commands.
|
|
|
|
* @done_q: &list_head for processed commands.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static void scsi_eh_offline_sdevs(struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2005-06-19 18:43:56 +07:00
|
|
|
struct scsi_cmnd *scmd, *next;
|
2017-06-03 04:21:55 +07:00
|
|
|
struct scsi_device *sdev;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-06-19 18:43:56 +07:00
|
|
|
list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
|
2007-08-18 00:02:10 +07:00
|
|
|
sdev_printk(KERN_INFO, scmd->device, "Device offlined - "
|
|
|
|
"not ready after error recovery\n");
|
2017-06-03 04:21:55 +07:00
|
|
|
sdev = scmd->device;
|
|
|
|
|
|
|
|
mutex_lock(&sdev->state_mutex);
|
|
|
|
scsi_device_set_state(sdev, SDEV_OFFLINE);
|
|
|
|
mutex_unlock(&sdev->state_mutex);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-08-20 06:45:31 +07:00
|
|
|
/**
|
2013-11-11 19:44:54 +07:00
|
|
|
* scsi_noretry_cmd - determine if command should be failed fast
|
2008-08-20 06:45:31 +07:00
|
|
|
* @scmd: SCSI cmd to examine.
|
|
|
|
*/
|
|
|
|
int scsi_noretry_cmd(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
switch (host_byte(scmd->result)) {
|
|
|
|
case DID_OK:
|
|
|
|
break;
|
2013-11-11 19:44:54 +07:00
|
|
|
case DID_TIME_OUT:
|
|
|
|
goto check_type;
|
2008-08-20 06:45:31 +07:00
|
|
|
case DID_BUS_BUSY:
|
2010-08-07 23:17:56 +07:00
|
|
|
return (scmd->request->cmd_flags & REQ_FAILFAST_TRANSPORT);
|
2008-08-20 06:45:31 +07:00
|
|
|
case DID_PARITY:
|
2010-08-07 23:17:56 +07:00
|
|
|
return (scmd->request->cmd_flags & REQ_FAILFAST_DEV);
|
2008-08-20 06:45:31 +07:00
|
|
|
case DID_ERROR:
|
|
|
|
if (msg_byte(scmd->result) == COMMAND_COMPLETE &&
|
|
|
|
status_byte(scmd->result) == RESERVATION_CONFLICT)
|
|
|
|
return 0;
|
|
|
|
/* fall through */
|
|
|
|
case DID_SOFT_ERROR:
|
2010-08-07 23:17:56 +07:00
|
|
|
return (scmd->request->cmd_flags & REQ_FAILFAST_DRIVER);
|
2008-08-20 06:45:31 +07:00
|
|
|
}
|
|
|
|
|
2013-11-11 19:44:54 +07:00
|
|
|
if (status_byte(scmd->result) != CHECK_CONDITION)
|
|
|
|
return 0;
|
2008-08-20 06:45:31 +07:00
|
|
|
|
2013-11-11 19:44:54 +07:00
|
|
|
check_type:
|
|
|
|
/*
|
|
|
|
* assume caller has checked sense and determined
|
|
|
|
* the check condition was retryable.
|
|
|
|
*/
|
|
|
|
if (scmd->request->cmd_flags & REQ_FAILFAST_DEV ||
|
2017-01-31 22:57:29 +07:00
|
|
|
blk_rq_is_passthrough(scmd->request))
|
2013-11-11 19:44:54 +07:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
2008-08-20 06:45:31 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* scsi_decide_disposition - Disposition a cmd on return from LLD.
|
|
|
|
* @scmd: SCSI cmd to examine.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* This is *only* called when we are examining the status after sending
|
|
|
|
* out the actual data command. any commands that are queued for error
|
|
|
|
* recovery (e.g. test_unit_ready) do *not* come through here.
|
|
|
|
*
|
|
|
|
* When this routine returns failed, it means the error handler thread
|
|
|
|
* is woken. In cases where the error code indicates an error that
|
|
|
|
* doesn't require the error handler read (i.e. we don't need to
|
|
|
|
* abort/reset), this function should return SUCCESS.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
int scsi_decide_disposition(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
int rtn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the device is offline, then we clearly just pass the result back
|
|
|
|
* up to the top level.
|
|
|
|
*/
|
|
|
|
if (!scsi_device_online(scmd->device)) {
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(5, scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: device offline - report as SUCCESS\n", __func__));
|
2005-04-17 05:20:36 +07:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* first check the host byte, to see if there is anything in there
|
|
|
|
* that would indicate what we need to do.
|
|
|
|
*/
|
|
|
|
switch (host_byte(scmd->result)) {
|
|
|
|
case DID_PASSTHROUGH:
|
|
|
|
/*
|
|
|
|
* no matter what, pass this through to the upper layer.
|
|
|
|
* nuke this special code so that it looks like we are saying
|
|
|
|
* did_ok.
|
|
|
|
*/
|
|
|
|
scmd->result &= 0xff00ffff;
|
|
|
|
return SUCCESS;
|
|
|
|
case DID_OK:
|
|
|
|
/*
|
|
|
|
* looks good. drop through, and check the next byte.
|
|
|
|
*/
|
|
|
|
break;
|
2013-11-11 19:44:54 +07:00
|
|
|
case DID_ABORT:
|
|
|
|
if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) {
|
2014-06-04 18:34:57 +07:00
|
|
|
set_host_byte(scmd, DID_TIME_OUT);
|
2013-11-11 19:44:54 +07:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2017-08-26 03:46:29 +07:00
|
|
|
/* FALLTHROUGH */
|
2005-04-17 05:20:36 +07:00
|
|
|
case DID_NO_CONNECT:
|
|
|
|
case DID_BAD_TARGET:
|
|
|
|
/*
|
|
|
|
* note - this means that we just report the status back
|
|
|
|
* to the top level driver, not that we actually think
|
|
|
|
* that it indicates SUCCESS.
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
2017-10-31 04:38:10 +07:00
|
|
|
case DID_SOFT_ERROR:
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* when the low level driver returns did_soft_error,
|
2011-03-22 02:47:31 +07:00
|
|
|
* it is responsible for keeping an internal retry counter
|
2005-04-17 05:20:36 +07:00
|
|
|
* in order to avoid endless loops (db)
|
|
|
|
*/
|
|
|
|
goto maybe_retry;
|
|
|
|
case DID_IMM_RETRY:
|
|
|
|
return NEEDS_RETRY;
|
|
|
|
|
2005-04-13 05:49:09 +07:00
|
|
|
case DID_REQUEUE:
|
|
|
|
return ADD_TO_MLQUEUE;
|
[SCSI] scsi: add transport host byte errors (v3)
Currently, if there is a transport problem the iscsi drivers will return
outstanding commands (commands being exeucted by the driver/fw/hw) with
DID_BUS_BUSY and block the session so no new commands can be queued.
Commands that are caught between the failure handling and blocking are
failed with DID_IMM_RETRY or one of the scsi ml queuecommand return values.
When the recovery_timeout fires, the iscsi drivers then fail IO with
DID_NO_CONNECT.
For fcp, some drivers will fail some outstanding IO (disk but possibly not
tape) with DID_BUS_BUSY or DID_ERROR or some other value that causes a retry
and hits the scsi_error.c failfast check, block the rport, and commands
caught in the race are failed with DID_IMM_RETRY. Other drivers, may
hold onto all IO and wait for the terminate_rport_io or dev_loss_tmo_callbk
to be called.
The following patches attempt to unify what upper layers will see drivers
like multipath can make a good guess. This relies on drivers being
hooked into their transport class.
This first patch just defines two new host byte errors so drivers can
return the same value for when a rport/session is blocked and for
when the fast_io_fail_tmo fires.
The idea is that if the LLD/class detects a problem and is going to block
a rport/session, then if the LLD wants or must return the command to scsi-ml,
then it can return it with DID_TRANSPORT_DISRUPTED. This will requeue
the IO into the same scsi queue it came from, until the fast io fail timer
fires and the class decides what to do.
When using multipath and the fast_io_fail_tmo fires then the class
can fail commands with DID_TRANSPORT_FAILFAST or drivers can use
DID_TRANSPORT_FAILFAST in their terminate_rport_io callbacks or
the equivlent in iscsi if we ever implement more advanced recovery methods.
A LLD, like lpfc, could continue to return DID_ERROR and then it will hit
the normal failfast path, so drivers do not have fully be ported to
work better. The point of the patches is that upper layers will
not see a failure that could be recovered from while the rport/session is
blocked until fast_io_fail_tmo/recovery_timeout fires.
V3
Remove some comments.
V2
Fixed patch/diff errors and renamed DID_TRANSPORT_BLOCKED to
DID_TRANSPORT_DISRUPTED.
V1
initial patch.
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2008-08-20 06:45:25 +07:00
|
|
|
case DID_TRANSPORT_DISRUPTED:
|
|
|
|
/*
|
|
|
|
* LLD/transport was disrupted during processing of the IO.
|
|
|
|
* The transport class is now blocked/blocking,
|
|
|
|
* and the transport will decide what to do with the IO
|
2008-11-05 08:47:19 +07:00
|
|
|
* based on its timers and recovery capablilities if
|
|
|
|
* there are enough retries.
|
[SCSI] scsi: add transport host byte errors (v3)
Currently, if there is a transport problem the iscsi drivers will return
outstanding commands (commands being exeucted by the driver/fw/hw) with
DID_BUS_BUSY and block the session so no new commands can be queued.
Commands that are caught between the failure handling and blocking are
failed with DID_IMM_RETRY or one of the scsi ml queuecommand return values.
When the recovery_timeout fires, the iscsi drivers then fail IO with
DID_NO_CONNECT.
For fcp, some drivers will fail some outstanding IO (disk but possibly not
tape) with DID_BUS_BUSY or DID_ERROR or some other value that causes a retry
and hits the scsi_error.c failfast check, block the rport, and commands
caught in the race are failed with DID_IMM_RETRY. Other drivers, may
hold onto all IO and wait for the terminate_rport_io or dev_loss_tmo_callbk
to be called.
The following patches attempt to unify what upper layers will see drivers
like multipath can make a good guess. This relies on drivers being
hooked into their transport class.
This first patch just defines two new host byte errors so drivers can
return the same value for when a rport/session is blocked and for
when the fast_io_fail_tmo fires.
The idea is that if the LLD/class detects a problem and is going to block
a rport/session, then if the LLD wants or must return the command to scsi-ml,
then it can return it with DID_TRANSPORT_DISRUPTED. This will requeue
the IO into the same scsi queue it came from, until the fast io fail timer
fires and the class decides what to do.
When using multipath and the fast_io_fail_tmo fires then the class
can fail commands with DID_TRANSPORT_FAILFAST or drivers can use
DID_TRANSPORT_FAILFAST in their terminate_rport_io callbacks or
the equivlent in iscsi if we ever implement more advanced recovery methods.
A LLD, like lpfc, could continue to return DID_ERROR and then it will hit
the normal failfast path, so drivers do not have fully be ported to
work better. The point of the patches is that upper layers will
not see a failure that could be recovered from while the rport/session is
blocked until fast_io_fail_tmo/recovery_timeout fires.
V3
Remove some comments.
V2
Fixed patch/diff errors and renamed DID_TRANSPORT_BLOCKED to
DID_TRANSPORT_DISRUPTED.
V1
initial patch.
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2008-08-20 06:45:25 +07:00
|
|
|
*/
|
2008-11-05 08:47:19 +07:00
|
|
|
goto maybe_retry;
|
[SCSI] scsi: add transport host byte errors (v3)
Currently, if there is a transport problem the iscsi drivers will return
outstanding commands (commands being exeucted by the driver/fw/hw) with
DID_BUS_BUSY and block the session so no new commands can be queued.
Commands that are caught between the failure handling and blocking are
failed with DID_IMM_RETRY or one of the scsi ml queuecommand return values.
When the recovery_timeout fires, the iscsi drivers then fail IO with
DID_NO_CONNECT.
For fcp, some drivers will fail some outstanding IO (disk but possibly not
tape) with DID_BUS_BUSY or DID_ERROR or some other value that causes a retry
and hits the scsi_error.c failfast check, block the rport, and commands
caught in the race are failed with DID_IMM_RETRY. Other drivers, may
hold onto all IO and wait for the terminate_rport_io or dev_loss_tmo_callbk
to be called.
The following patches attempt to unify what upper layers will see drivers
like multipath can make a good guess. This relies on drivers being
hooked into their transport class.
This first patch just defines two new host byte errors so drivers can
return the same value for when a rport/session is blocked and for
when the fast_io_fail_tmo fires.
The idea is that if the LLD/class detects a problem and is going to block
a rport/session, then if the LLD wants or must return the command to scsi-ml,
then it can return it with DID_TRANSPORT_DISRUPTED. This will requeue
the IO into the same scsi queue it came from, until the fast io fail timer
fires and the class decides what to do.
When using multipath and the fast_io_fail_tmo fires then the class
can fail commands with DID_TRANSPORT_FAILFAST or drivers can use
DID_TRANSPORT_FAILFAST in their terminate_rport_io callbacks or
the equivlent in iscsi if we ever implement more advanced recovery methods.
A LLD, like lpfc, could continue to return DID_ERROR and then it will hit
the normal failfast path, so drivers do not have fully be ported to
work better. The point of the patches is that upper layers will
not see a failure that could be recovered from while the rport/session is
blocked until fast_io_fail_tmo/recovery_timeout fires.
V3
Remove some comments.
V2
Fixed patch/diff errors and renamed DID_TRANSPORT_BLOCKED to
DID_TRANSPORT_DISRUPTED.
V1
initial patch.
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
2008-08-20 06:45:25 +07:00
|
|
|
case DID_TRANSPORT_FAILFAST:
|
|
|
|
/*
|
|
|
|
* The transport decided to failfast the IO (most likely
|
|
|
|
* the fast io fail tmo fired), so send IO directly upwards.
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
2005-04-17 05:20:36 +07:00
|
|
|
case DID_ERROR:
|
|
|
|
if (msg_byte(scmd->result) == COMMAND_COMPLETE &&
|
|
|
|
status_byte(scmd->result) == RESERVATION_CONFLICT)
|
|
|
|
/*
|
|
|
|
* execute reservation conflict processing code
|
|
|
|
* lower down
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
/* fallthrough */
|
|
|
|
case DID_BUS_BUSY:
|
|
|
|
case DID_PARITY:
|
|
|
|
goto maybe_retry;
|
|
|
|
case DID_TIME_OUT:
|
|
|
|
/*
|
|
|
|
* when we scan the bus, we get timeout messages for
|
|
|
|
* these commands if there is no device available.
|
|
|
|
* other hosts report did_no_connect for the same thing.
|
|
|
|
*/
|
|
|
|
if ((scmd->cmnd[0] == TEST_UNIT_READY ||
|
|
|
|
scmd->cmnd[0] == INQUIRY)) {
|
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
case DID_RESET:
|
|
|
|
return SUCCESS;
|
|
|
|
default:
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* next, check the message byte.
|
|
|
|
*/
|
|
|
|
if (msg_byte(scmd->result) != COMMAND_COMPLETE)
|
|
|
|
return FAILED;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check the status byte to see if this indicates anything special.
|
|
|
|
*/
|
|
|
|
switch (status_byte(scmd->result)) {
|
|
|
|
case QUEUE_FULL:
|
2009-10-16 07:46:44 +07:00
|
|
|
scsi_handle_queue_full(scmd->device);
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* the case of trying to send too many commands to a
|
|
|
|
* tagged queueing device.
|
|
|
|
*/
|
2017-08-26 03:46:29 +07:00
|
|
|
/* FALLTHROUGH */
|
2005-04-17 05:20:36 +07:00
|
|
|
case BUSY:
|
|
|
|
/*
|
|
|
|
* device can't talk to us at the moment. Should only
|
|
|
|
* occur (SAM-3) when the task queue is empty, so will cause
|
|
|
|
* the empty queue handling to trigger a stall in the
|
|
|
|
* device.
|
|
|
|
*/
|
|
|
|
return ADD_TO_MLQUEUE;
|
|
|
|
case GOOD:
|
2013-08-09 02:07:48 +07:00
|
|
|
if (scmd->cmnd[0] == REPORT_LUNS)
|
|
|
|
scmd->device->sdev_target->expecting_lun_change = 0;
|
2009-10-23 05:46:33 +07:00
|
|
|
scsi_handle_queue_ramp_up(scmd->device);
|
2017-08-26 03:46:29 +07:00
|
|
|
/* FALLTHROUGH */
|
2005-04-17 05:20:36 +07:00
|
|
|
case COMMAND_TERMINATED:
|
|
|
|
return SUCCESS;
|
2008-11-06 17:57:52 +07:00
|
|
|
case TASK_ABORTED:
|
|
|
|
goto maybe_retry;
|
2005-04-17 05:20:36 +07:00
|
|
|
case CHECK_CONDITION:
|
|
|
|
rtn = scsi_check_sense(scmd);
|
|
|
|
if (rtn == NEEDS_RETRY)
|
|
|
|
goto maybe_retry;
|
|
|
|
/* if rtn == FAILED, we have no sense information;
|
|
|
|
* returning FAILED will wake the error handler thread
|
|
|
|
* to collect the sense and redo the decide
|
|
|
|
* disposition */
|
|
|
|
return rtn;
|
|
|
|
case CONDITION_GOOD:
|
|
|
|
case INTERMEDIATE_GOOD:
|
|
|
|
case INTERMEDIATE_C_GOOD:
|
|
|
|
case ACA_ACTIVE:
|
|
|
|
/*
|
|
|
|
* who knows? FIXME(eric)
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
case RESERVATION_CONFLICT:
|
2005-10-02 23:45:08 +07:00
|
|
|
sdev_printk(KERN_INFO, scmd->device,
|
|
|
|
"reservation conflict\n");
|
2012-01-25 03:38:46 +07:00
|
|
|
set_host_byte(scmd, DID_NEXUS_FAILURE);
|
2005-04-17 05:20:36 +07:00
|
|
|
return SUCCESS; /* causes immediate i/o error */
|
|
|
|
default:
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
return FAILED;
|
|
|
|
|
2018-02-26 14:59:16 +07:00
|
|
|
maybe_retry:
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* we requeue for retry because the error was retryable, and
|
|
|
|
* the request was not marked fast fail. Note that above,
|
|
|
|
* even if the request is marked fast fail, we still requeue
|
|
|
|
* for queue congestion conditions (QUEUE_FULL or BUSY) */
|
2006-02-25 06:10:04 +07:00
|
|
|
if ((++scmd->retries) <= scmd->allowed
|
2008-08-20 06:45:31 +07:00
|
|
|
&& !scsi_noretry_cmd(scmd)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
return NEEDS_RETRY;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* no more retries - report this one back to upper level.
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-03 14:38:04 +07:00
|
|
|
static void eh_lock_door_done(struct request *req, blk_status_t status)
|
2008-12-13 23:23:45 +07:00
|
|
|
{
|
|
|
|
__blk_put_request(req->q, req);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* scsi_eh_lock_door - Prevent medium removal for the specified device
|
|
|
|
* @sdev: SCSI device to prevent medium removal
|
|
|
|
*
|
|
|
|
* Locking:
|
2009-05-17 21:30:48 +07:00
|
|
|
* We must be called from process context.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the
|
|
|
|
* head of the devices request queue, and continue.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static void scsi_eh_lock_door(struct scsi_device *sdev)
|
|
|
|
{
|
2008-12-13 23:23:45 +07:00
|
|
|
struct request *req;
|
2017-01-27 15:46:29 +07:00
|
|
|
struct scsi_request *rq;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-05-09 14:54:05 +07:00
|
|
|
req = blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, 0);
|
2014-08-28 21:15:21 +07:00
|
|
|
if (IS_ERR(req))
|
2014-07-03 02:35:16 +07:00
|
|
|
return;
|
2017-01-27 15:46:29 +07:00
|
|
|
rq = scsi_req(req);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2017-01-27 15:46:29 +07:00
|
|
|
rq->cmd[0] = ALLOW_MEDIUM_REMOVAL;
|
|
|
|
rq->cmd[1] = 0;
|
|
|
|
rq->cmd[2] = 0;
|
|
|
|
rq->cmd[3] = 0;
|
|
|
|
rq->cmd[4] = SCSI_REMOVAL_PREVENT;
|
|
|
|
rq->cmd[5] = 0;
|
|
|
|
rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
|
2008-12-13 23:23:45 +07:00
|
|
|
|
2016-10-20 20:12:13 +07:00
|
|
|
req->rq_flags |= RQF_QUIET;
|
2008-12-13 23:23:45 +07:00
|
|
|
req->timeout = 10 * HZ;
|
2017-04-06 00:18:12 +07:00
|
|
|
rq->retries = 5;
|
2008-12-13 23:23:45 +07:00
|
|
|
|
|
|
|
blk_execute_rq_nowait(req->q, NULL, req, 1, eh_lock_door_done);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_restart_operations - restart io operations to the specified host.
|
|
|
|
* @shost: Host we are restarting.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* When we entered the error handler, we blocked all further i/o to
|
|
|
|
* this device. we need to 'reverse' this process.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static void scsi_restart_operations(struct Scsi_Host *shost)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev;
|
2005-09-19 03:05:20 +07:00
|
|
|
unsigned long flags;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the door was locked, we need to insert a door lock request
|
|
|
|
* onto the head of the SCSI request queue for the device. There
|
|
|
|
* is no point trying to lock the door of an off-line device.
|
|
|
|
*/
|
|
|
|
shost_for_each_device(sdev, shost) {
|
2014-11-04 01:36:40 +07:00
|
|
|
if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) {
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_eh_lock_door(sdev);
|
2014-11-04 01:36:40 +07:00
|
|
|
sdev->was_reset = 0;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* next free up anything directly waiting upon the host. this
|
|
|
|
* will be requests for character device operations, and also for
|
|
|
|
* ioctls to queued block devices.
|
|
|
|
*/
|
2013-10-23 15:51:21 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-06-25 21:39:59 +07:00
|
|
|
shost_printk(KERN_INFO, shost, "waking up host to restart\n"));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-09-19 03:05:20 +07:00
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
if (scsi_host_set_state(shost, SHOST_RUNNING))
|
|
|
|
if (scsi_host_set_state(shost, SHOST_CANCEL))
|
|
|
|
BUG_ON(scsi_host_set_state(shost, SHOST_DEL));
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
wake_up(&shost->host_wait);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* finally we need to re-initiate requests that may be pending. we will
|
|
|
|
* have had everything blocked while error handling is taking place, and
|
|
|
|
* now that error recovery is done, we will need to ensure that these
|
|
|
|
* requests are started.
|
|
|
|
*/
|
|
|
|
scsi_run_host_queues(shost);
|
2012-06-22 13:25:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if eh is active and host_eh_scheduled is pending we need to re-run
|
|
|
|
* recovery. we do this check after scsi_run_host_queues() to allow
|
|
|
|
* everything pent up since the last eh run a chance to make forward
|
|
|
|
* progress before we sync again. Either we'll immediately re-run
|
|
|
|
* recovery or scsi_device_unbusy() will wake us again when these
|
|
|
|
* pending commands complete.
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
if (shost->host_eh_scheduled)
|
|
|
|
if (scsi_host_set_state(shost, SHOST_RECOVERY))
|
|
|
|
WARN_ON(scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY));
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_ready_devs - check device ready state and recover if not.
|
2014-08-17 04:15:11 +07:00
|
|
|
* @shost: host to be recovered.
|
|
|
|
* @work_q: &list_head for pending commands.
|
2007-11-04 01:30:39 +07:00
|
|
|
* @done_q: &list_head for processed commands.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2007-01-27 05:08:49 +07:00
|
|
|
void scsi_eh_ready_devs(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
if (!scsi_eh_stu(shost, work_q, done_q))
|
|
|
|
if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
|
2008-03-01 07:25:19 +07:00
|
|
|
if (!scsi_eh_target_reset(shost, work_q, done_q))
|
|
|
|
if (!scsi_eh_bus_reset(shost, work_q, done_q))
|
2014-06-25 21:39:59 +07:00
|
|
|
if (!scsi_eh_host_reset(shost, work_q, done_q))
|
2008-03-01 07:25:19 +07:00
|
|
|
scsi_eh_offline_sdevs(work_q,
|
|
|
|
done_q);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2007-01-27 05:08:49 +07:00
|
|
|
EXPORT_SYMBOL_GPL(scsi_eh_ready_devs);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_flush_done_q - finish processed commands or retry them.
|
|
|
|
* @done_q: list_head of processed commands.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2006-01-23 11:09:36 +07:00
|
|
|
void scsi_eh_flush_done_q(struct list_head *done_q)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-06-19 18:43:56 +07:00
|
|
|
struct scsi_cmnd *scmd, *next;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-06-19 18:43:56 +07:00
|
|
|
list_for_each_entry_safe(scmd, next, done_q, eh_entry) {
|
|
|
|
list_del_init(&scmd->eh_entry);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (scsi_device_online(scmd->device) &&
|
2008-08-20 06:45:31 +07:00
|
|
|
!scsi_noretry_cmd(scmd) &&
|
2006-02-25 06:10:04 +07:00
|
|
|
(++scmd->retries <= scmd->allowed)) {
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"%s: flush retry cmd\n",
|
|
|
|
current->comm));
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
|
|
|
|
} else {
|
2005-05-17 07:42:15 +07:00
|
|
|
/*
|
|
|
|
* If just we got sense for the device (called
|
|
|
|
* scsi_eh_get_sense), scmd->result is already
|
|
|
|
* set, do not set DRIVER_TIMEOUT.
|
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!scmd->result)
|
|
|
|
scmd->result |= (DRIVER_TIMEOUT << 24);
|
2014-06-25 21:39:59 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 13:43:50 +07:00
|
|
|
"%s: flush finish cmd\n",
|
|
|
|
current->comm));
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_finish_command(scmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-23 11:09:36 +07:00
|
|
|
EXPORT_SYMBOL(scsi_eh_flush_done_q);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
|
|
|
|
* @shost: Host to unjam.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* When we come in here, we *know* that all commands on the bus have
|
|
|
|
* either completed, failed or timed out. we also know that no further
|
|
|
|
* commands are being sent to the host, so things are relatively quiet
|
|
|
|
* and we have freedom to fiddle with things as we wish.
|
|
|
|
*
|
|
|
|
* This is only the *default* implementation. it is possible for
|
|
|
|
* individual drivers to supply their own version of this function, and
|
|
|
|
* if the maintainer wishes to do this, it is strongly suggested that
|
|
|
|
* this function be taken as a template and modified. this function
|
|
|
|
* was designed to correctly handle problems for about 95% of the
|
|
|
|
* different cases out there, and it should always provide at least a
|
|
|
|
* reasonable amount of error recovery.
|
|
|
|
*
|
|
|
|
* Any command marked 'failed' or 'timeout' must eventually have
|
|
|
|
* scsi_finish_cmd() called for it. we do all of the retry stuff
|
|
|
|
* here, so when we restart the host after we return it should have an
|
|
|
|
* empty queue.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
static void scsi_unjam_host(struct Scsi_Host *shost)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
LIST_HEAD(eh_work_q);
|
|
|
|
LIST_HEAD(eh_done_q);
|
|
|
|
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
list_splice_init(&shost->eh_cmd_q, &eh_work_q);
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(1, scsi_eh_prt_fail_stats(shost, &eh_work_q));
|
|
|
|
|
|
|
|
if (!scsi_eh_get_sense(&eh_work_q, &eh_done_q))
|
2017-04-06 20:36:35 +07:00
|
|
|
scsi_eh_ready_devs(shost, &eh_work_q, &eh_done_q);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-10-23 15:51:21 +07:00
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
2013-11-11 19:44:56 +07:00
|
|
|
if (shost->eh_deadline != -1)
|
2013-10-23 15:51:21 +07:00
|
|
|
shost->last_reset = 0;
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
scsi_eh_flush_done_q(&eh_done_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-10-29 06:01:55 +07:00
|
|
|
* scsi_error_handler - SCSI error handler thread
|
2005-04-17 05:20:36 +07:00
|
|
|
* @data: Host for which we are running.
|
|
|
|
*
|
|
|
|
* Notes:
|
2005-10-29 06:01:55 +07:00
|
|
|
* This is the main error handling loop. This is run as a kernel thread
|
|
|
|
* for every SCSI host and handles all error handling activity.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
int scsi_error_handler(void *data)
|
|
|
|
{
|
2005-10-29 06:01:55 +07:00
|
|
|
struct Scsi_Host *shost = data;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
2005-10-29 06:01:55 +07:00
|
|
|
* We use TASK_INTERRUPTIBLE so that the thread is not
|
|
|
|
* counted against the load average as a running process.
|
|
|
|
* We never actually get interrupted because kthread_run
|
2008-12-23 06:54:00 +07:00
|
|
|
* disables signal delivery for the created thread.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2015-08-28 01:16:37 +07:00
|
|
|
while (true) {
|
|
|
|
/*
|
|
|
|
* The sequence in kthread_stop() sets the stop flag first
|
|
|
|
* then wakes the process. To avoid missed wakeups, the task
|
|
|
|
* should always be in a non running state before the stop
|
|
|
|
* flag is checked
|
|
|
|
*/
|
2012-06-22 13:25:42 +07:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2015-08-28 01:16:37 +07:00
|
|
|
if (kthread_should_stop())
|
|
|
|
break;
|
|
|
|
|
2006-05-15 18:57:20 +07:00
|
|
|
if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) ||
|
2018-06-24 21:03:26 +07:00
|
|
|
shost->host_failed != scsi_host_busy(shost)) {
|
2005-10-29 06:01:55 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(1,
|
2014-06-25 21:39:59 +07:00
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"scsi_eh_%d: sleeping\n",
|
|
|
|
shost->host_no));
|
2005-09-19 21:50:04 +07:00
|
|
|
schedule();
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-09-19 21:50:04 +07:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2005-10-29 06:01:55 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(1,
|
2014-06-25 21:39:59 +07:00
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"scsi_eh_%d: waking up %d/%d/%d\n",
|
|
|
|
shost->host_no, shost->host_eh_scheduled,
|
2014-01-22 21:29:29 +07:00
|
|
|
shost->host_failed,
|
2018-06-24 21:03:26 +07:00
|
|
|
scsi_host_busy(shost)));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have a host that is failing for some reason. Figure out
|
|
|
|
* what we need to do to get it up and online again (if we can).
|
|
|
|
* If we fail, we end up taking the thing offline.
|
|
|
|
*/
|
2011-12-05 08:20:24 +07:00
|
|
|
if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) {
|
[SCSI] implement runtime Power Management
This patch (as1398b) adds runtime PM support to the SCSI layer. Only
the machanism is provided; use of it is up to the various high-level
drivers, and the patch doesn't change any of them. Except for sg --
the patch expicitly prevents a device from being runtime-suspended
while its sg device file is open.
The implementation is simplistic. In general, hosts and targets are
automatically suspended when all their children are asleep, but for
them the runtime-suspend code doesn't actually do anything. (A host's
runtime PM status is propagated up the device tree, though, so a
runtime-PM-aware lower-level driver could power down the host adapter
hardware at the appropriate times.) There are comments indicating
where a transport class might be notified or some other hooks added.
LUNs are runtime-suspended by calling the drivers' existing suspend
handlers (and likewise for runtime-resume). Somewhat arbitrarily, the
implementation delays for 100 ms before suspending an eligible LUN.
This is because there typically are occasions during bootup when the
same device file is opened and closed several times in quick
succession.
The way this all works is that the SCSI core increments a device's
PM-usage count when it is registered. If a high-level driver does
nothing then the device will not be eligible for runtime-suspend
because of the elevated usage count. If a high-level driver wants to
use runtime PM then it can call scsi_autopm_put_device() in its probe
routine to decrement the usage count and scsi_autopm_get_device() in
its remove routine to restore the original count.
Hosts, targets, and LUNs are not suspended while they are being probed
or removed, or while the error handler is running. In fact, a fairly
large part of the patch consists of code to make sure that things
aren't suspended at such times.
[jejb: fix up compile issues in PM config variations]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-17 21:41:42 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(1,
|
2014-10-24 19:27:02 +07:00
|
|
|
shost_printk(KERN_ERR, shost,
|
|
|
|
"scsi_eh_%d: unable to autoresume\n",
|
|
|
|
shost->host_no));
|
[SCSI] implement runtime Power Management
This patch (as1398b) adds runtime PM support to the SCSI layer. Only
the machanism is provided; use of it is up to the various high-level
drivers, and the patch doesn't change any of them. Except for sg --
the patch expicitly prevents a device from being runtime-suspended
while its sg device file is open.
The implementation is simplistic. In general, hosts and targets are
automatically suspended when all their children are asleep, but for
them the runtime-suspend code doesn't actually do anything. (A host's
runtime PM status is propagated up the device tree, though, so a
runtime-PM-aware lower-level driver could power down the host adapter
hardware at the appropriate times.) There are comments indicating
where a transport class might be notified or some other hooks added.
LUNs are runtime-suspended by calling the drivers' existing suspend
handlers (and likewise for runtime-resume). Somewhat arbitrarily, the
implementation delays for 100 ms before suspending an eligible LUN.
This is because there typically are occasions during bootup when the
same device file is opened and closed several times in quick
succession.
The way this all works is that the SCSI core increments a device's
PM-usage count when it is registered. If a high-level driver does
nothing then the device will not be eligible for runtime-suspend
because of the elevated usage count. If a high-level driver wants to
use runtime PM then it can call scsi_autopm_put_device() in its probe
routine to decrement the usage count and scsi_autopm_get_device() in
its remove routine to restore the original count.
Hosts, targets, and LUNs are not suspended while they are being probed
or removed, or while the error handler is running. In fact, a fairly
large part of the patch consists of code to make sure that things
aren't suspended at such times.
[jejb: fix up compile issues in PM config variations]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-17 21:41:42 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-04-02 00:21:04 +07:00
|
|
|
if (shost->transportt->eh_strategy_handler)
|
|
|
|
shost->transportt->eh_strategy_handler(shost);
|
2005-04-17 05:20:36 +07:00
|
|
|
else
|
|
|
|
scsi_unjam_host(shost);
|
|
|
|
|
2016-06-07 13:53:56 +07:00
|
|
|
/* All scmds have been handled */
|
|
|
|
shost->host_failed = 0;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Note - if the above fails completely, the action is to take
|
|
|
|
* individual devices offline and flush the queue of any
|
|
|
|
* outstanding requests that may have been pending. When we
|
|
|
|
* restart, we restart any I/O to any other devices on the bus
|
|
|
|
* which are still online.
|
|
|
|
*/
|
|
|
|
scsi_restart_operations(shost);
|
2011-12-05 08:20:24 +07:00
|
|
|
if (!shost->eh_noresume)
|
|
|
|
scsi_autopm_put_host(shost);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2005-10-19 19:22:13 +07:00
|
|
|
__set_current_state(TASK_RUNNING);
|
|
|
|
|
2005-10-29 06:01:55 +07:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(1,
|
2014-06-25 21:39:59 +07:00
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"Error handler scsi_eh_%d exiting\n",
|
|
|
|
shost->host_no));
|
2005-09-19 21:50:04 +07:00
|
|
|
shost->ehandler = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function: scsi_report_bus_reset()
|
|
|
|
*
|
|
|
|
* Purpose: Utility function used by low-level drivers to report that
|
|
|
|
* they have observed a bus reset on the bus being handled.
|
|
|
|
*
|
|
|
|
* Arguments: shost - Host in question
|
|
|
|
* channel - channel on which reset was observed.
|
|
|
|
*
|
|
|
|
* Returns: Nothing
|
|
|
|
*
|
|
|
|
* Lock status: Host lock must be held.
|
|
|
|
*
|
|
|
|
* Notes: This only needs to be called if the reset is one which
|
|
|
|
* originates from an unknown location. Resets originated
|
|
|
|
* by the mid-level itself don't need to call this, but there
|
|
|
|
* should be no harm.
|
|
|
|
*
|
|
|
|
* The main purpose of this is to make sure that a CHECK_CONDITION
|
|
|
|
* is properly treated.
|
|
|
|
*/
|
|
|
|
void scsi_report_bus_reset(struct Scsi_Host *shost, int channel)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev;
|
|
|
|
|
|
|
|
__shost_for_each_device(sdev, shost) {
|
2008-03-01 07:25:19 +07:00
|
|
|
if (channel == sdev_channel(sdev))
|
|
|
|
__scsi_report_device_reset(sdev, NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_report_bus_reset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function: scsi_report_device_reset()
|
|
|
|
*
|
|
|
|
* Purpose: Utility function used by low-level drivers to report that
|
|
|
|
* they have observed a device reset on the device being handled.
|
|
|
|
*
|
|
|
|
* Arguments: shost - Host in question
|
|
|
|
* channel - channel on which reset was observed
|
|
|
|
* target - target on which reset was observed
|
|
|
|
*
|
|
|
|
* Returns: Nothing
|
|
|
|
*
|
|
|
|
* Lock status: Host lock must be held
|
|
|
|
*
|
|
|
|
* Notes: This only needs to be called if the reset is one which
|
|
|
|
* originates from an unknown location. Resets originated
|
|
|
|
* by the mid-level itself don't need to call this, but there
|
|
|
|
* should be no harm.
|
|
|
|
*
|
|
|
|
* The main purpose of this is to make sure that a CHECK_CONDITION
|
|
|
|
* is properly treated.
|
|
|
|
*/
|
|
|
|
void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev;
|
|
|
|
|
|
|
|
__shost_for_each_device(sdev, shost) {
|
2005-10-25 05:05:09 +07:00
|
|
|
if (channel == sdev_channel(sdev) &&
|
2008-03-01 07:25:19 +07:00
|
|
|
target == sdev_id(sdev))
|
|
|
|
__scsi_report_device_reset(sdev, NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_report_device_reset);
|
|
|
|
|
|
|
|
static void
|
|
|
|
scsi_reset_provider_done_command(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-11 17:06:47 +07:00
|
|
|
/**
|
|
|
|
* scsi_ioctl_reset: explicitly reset a host/bus/target/device
|
|
|
|
* @dev: scsi_device to operate on
|
|
|
|
* @arg: reset type (see sg.h)
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
int
|
2014-10-11 17:06:47 +07:00
|
|
|
scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
[SCSI] implement runtime Power Management
This patch (as1398b) adds runtime PM support to the SCSI layer. Only
the machanism is provided; use of it is up to the various high-level
drivers, and the patch doesn't change any of them. Except for sg --
the patch expicitly prevents a device from being runtime-suspended
while its sg device file is open.
The implementation is simplistic. In general, hosts and targets are
automatically suspended when all their children are asleep, but for
them the runtime-suspend code doesn't actually do anything. (A host's
runtime PM status is propagated up the device tree, though, so a
runtime-PM-aware lower-level driver could power down the host adapter
hardware at the appropriate times.) There are comments indicating
where a transport class might be notified or some other hooks added.
LUNs are runtime-suspended by calling the drivers' existing suspend
handlers (and likewise for runtime-resume). Somewhat arbitrarily, the
implementation delays for 100 ms before suspending an eligible LUN.
This is because there typically are occasions during bootup when the
same device file is opened and closed several times in quick
succession.
The way this all works is that the SCSI core increments a device's
PM-usage count when it is registered. If a high-level driver does
nothing then the device will not be eligible for runtime-suspend
because of the elevated usage count. If a high-level driver wants to
use runtime PM then it can call scsi_autopm_put_device() in its probe
routine to decrement the usage count and scsi_autopm_get_device() in
its remove routine to restore the original count.
Hosts, targets, and LUNs are not suspended while they are being probed
or removed, or while the error handler is running. In fact, a fairly
large part of the patch consists of code to make sure that things
aren't suspended at such times.
[jejb: fix up compile issues in PM config variations]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-17 21:41:42 +07:00
|
|
|
struct scsi_cmnd *scmd;
|
2006-03-09 02:50:12 +07:00
|
|
|
struct Scsi_Host *shost = dev->host;
|
2017-01-03 01:55:26 +07:00
|
|
|
struct request *rq;
|
2006-03-09 02:50:12 +07:00
|
|
|
unsigned long flags;
|
2014-10-11 17:06:47 +07:00
|
|
|
int error = 0, rtn, val;
|
|
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
|
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
error = get_user(val, arg);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
[SCSI] implement runtime Power Management
This patch (as1398b) adds runtime PM support to the SCSI layer. Only
the machanism is provided; use of it is up to the various high-level
drivers, and the patch doesn't change any of them. Except for sg --
the patch expicitly prevents a device from being runtime-suspended
while its sg device file is open.
The implementation is simplistic. In general, hosts and targets are
automatically suspended when all their children are asleep, but for
them the runtime-suspend code doesn't actually do anything. (A host's
runtime PM status is propagated up the device tree, though, so a
runtime-PM-aware lower-level driver could power down the host adapter
hardware at the appropriate times.) There are comments indicating
where a transport class might be notified or some other hooks added.
LUNs are runtime-suspended by calling the drivers' existing suspend
handlers (and likewise for runtime-resume). Somewhat arbitrarily, the
implementation delays for 100 ms before suspending an eligible LUN.
This is because there typically are occasions during bootup when the
same device file is opened and closed several times in quick
succession.
The way this all works is that the SCSI core increments a device's
PM-usage count when it is registered. If a high-level driver does
nothing then the device will not be eligible for runtime-suspend
because of the elevated usage count. If a high-level driver wants to
use runtime PM then it can call scsi_autopm_put_device() in its probe
routine to decrement the usage count and scsi_autopm_get_device() in
its remove routine to restore the original count.
Hosts, targets, and LUNs are not suspended while they are being probed
or removed, or while the error handler is running. In fact, a fairly
large part of the patch consists of code to make sure that things
aren't suspended at such times.
[jejb: fix up compile issues in PM config variations]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-17 21:41:42 +07:00
|
|
|
if (scsi_autopm_get_host(shost) < 0)
|
2014-10-11 17:06:47 +07:00
|
|
|
return -EIO;
|
[SCSI] implement runtime Power Management
This patch (as1398b) adds runtime PM support to the SCSI layer. Only
the machanism is provided; use of it is up to the various high-level
drivers, and the patch doesn't change any of them. Except for sg --
the patch expicitly prevents a device from being runtime-suspended
while its sg device file is open.
The implementation is simplistic. In general, hosts and targets are
automatically suspended when all their children are asleep, but for
them the runtime-suspend code doesn't actually do anything. (A host's
runtime PM status is propagated up the device tree, though, so a
runtime-PM-aware lower-level driver could power down the host adapter
hardware at the appropriate times.) There are comments indicating
where a transport class might be notified or some other hooks added.
LUNs are runtime-suspended by calling the drivers' existing suspend
handlers (and likewise for runtime-resume). Somewhat arbitrarily, the
implementation delays for 100 ms before suspending an eligible LUN.
This is because there typically are occasions during bootup when the
same device file is opened and closed several times in quick
succession.
The way this all works is that the SCSI core increments a device's
PM-usage count when it is registered. If a high-level driver does
nothing then the device will not be eligible for runtime-suspend
because of the elevated usage count. If a high-level driver wants to
use runtime PM then it can call scsi_autopm_put_device() in its probe
routine to decrement the usage count and scsi_autopm_get_device() in
its remove routine to restore the original count.
Hosts, targets, and LUNs are not suspended while they are being probed
or removed, or while the error handler is running. In fact, a fairly
large part of the patch consists of code to make sure that things
aren't suspended at such times.
[jejb: fix up compile issues in PM config variations]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-17 21:41:42 +07:00
|
|
|
|
2014-10-11 17:06:47 +07:00
|
|
|
error = -EIO;
|
2017-01-03 01:55:26 +07:00
|
|
|
rq = kzalloc(sizeof(struct request) + sizeof(struct scsi_cmnd) +
|
|
|
|
shost->hostt->cmd_size, GFP_KERNEL);
|
|
|
|
if (!rq)
|
2014-05-01 21:51:05 +07:00
|
|
|
goto out_put_autopm_host;
|
2017-01-03 01:55:26 +07:00
|
|
|
blk_rq_init(NULL, rq);
|
2014-05-01 21:51:05 +07:00
|
|
|
|
2017-01-03 01:55:26 +07:00
|
|
|
scmd = (struct scsi_cmnd *)(rq + 1);
|
|
|
|
scsi_init_command(dev, scmd);
|
|
|
|
scmd->request = rq;
|
2017-01-27 15:46:29 +07:00
|
|
|
scmd->cmnd = scsi_req(rq)->cmd;
|
2008-04-30 15:19:47 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
scmd->scsi_done = scsi_reset_provider_done_command;
|
2007-12-13 18:47:40 +07:00
|
|
|
memset(&scmd->sdb, 0, sizeof(scmd->sdb));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
scmd->cmd_len = 0;
|
|
|
|
|
|
|
|
scmd->sc_data_direction = DMA_BIDIRECTIONAL;
|
|
|
|
|
2006-03-09 02:50:12 +07:00
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
shost->tmf_in_progress = 1;
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
|
2014-10-11 17:06:47 +07:00
|
|
|
switch (val & ~SG_SCSI_RESET_NO_ESCALATE) {
|
|
|
|
case SG_SCSI_RESET_NOTHING:
|
|
|
|
rtn = SUCCESS;
|
|
|
|
break;
|
|
|
|
case SG_SCSI_RESET_DEVICE:
|
2005-04-17 05:20:36 +07:00
|
|
|
rtn = scsi_try_bus_device_reset(scmd);
|
2014-10-11 17:06:47 +07:00
|
|
|
if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
/* FALLTHROUGH */
|
2014-10-11 17:06:47 +07:00
|
|
|
case SG_SCSI_RESET_TARGET:
|
2008-03-01 07:25:19 +07:00
|
|
|
rtn = scsi_try_target_reset(scmd);
|
2014-10-11 17:06:47 +07:00
|
|
|
if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
|
2008-03-01 07:25:19 +07:00
|
|
|
break;
|
|
|
|
/* FALLTHROUGH */
|
2014-10-11 17:06:47 +07:00
|
|
|
case SG_SCSI_RESET_BUS:
|
2005-04-17 05:20:36 +07:00
|
|
|
rtn = scsi_try_bus_reset(scmd);
|
2014-10-11 17:06:47 +07:00
|
|
|
if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
/* FALLTHROUGH */
|
2014-10-11 17:06:47 +07:00
|
|
|
case SG_SCSI_RESET_HOST:
|
2005-04-17 05:20:36 +07:00
|
|
|
rtn = scsi_try_host_reset(scmd);
|
2014-10-11 17:06:47 +07:00
|
|
|
if (rtn == SUCCESS)
|
|
|
|
break;
|
|
|
|
/* FALLTHROUGH */
|
2017-08-26 03:46:29 +07:00
|
|
|
default:
|
2005-04-17 05:20:36 +07:00
|
|
|
rtn = FAILED;
|
2014-10-11 17:06:47 +07:00
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2014-10-11 17:06:47 +07:00
|
|
|
error = (rtn == SUCCESS) ? 0 : -EIO;
|
|
|
|
|
2006-03-09 02:50:12 +07:00
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
shost->tmf_in_progress = 0;
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* be sure to wake up anyone who was sleeping or had their queue
|
|
|
|
* suspended while we performed the TMF.
|
|
|
|
*/
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-06-25 21:39:59 +07:00
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"waking up host to restart after TMF\n"));
|
2006-03-09 02:50:12 +07:00
|
|
|
|
|
|
|
wake_up(&shost->host_wait);
|
|
|
|
scsi_run_host_queues(shost);
|
|
|
|
|
2014-09-06 08:00:05 +07:00
|
|
|
scsi_put_command(scmd);
|
2017-01-03 01:55:26 +07:00
|
|
|
kfree(rq);
|
2014-09-06 08:00:05 +07:00
|
|
|
|
2014-02-21 05:20:55 +07:00
|
|
|
out_put_autopm_host:
|
[SCSI] implement runtime Power Management
This patch (as1398b) adds runtime PM support to the SCSI layer. Only
the machanism is provided; use of it is up to the various high-level
drivers, and the patch doesn't change any of them. Except for sg --
the patch expicitly prevents a device from being runtime-suspended
while its sg device file is open.
The implementation is simplistic. In general, hosts and targets are
automatically suspended when all their children are asleep, but for
them the runtime-suspend code doesn't actually do anything. (A host's
runtime PM status is propagated up the device tree, though, so a
runtime-PM-aware lower-level driver could power down the host adapter
hardware at the appropriate times.) There are comments indicating
where a transport class might be notified or some other hooks added.
LUNs are runtime-suspended by calling the drivers' existing suspend
handlers (and likewise for runtime-resume). Somewhat arbitrarily, the
implementation delays for 100 ms before suspending an eligible LUN.
This is because there typically are occasions during bootup when the
same device file is opened and closed several times in quick
succession.
The way this all works is that the SCSI core increments a device's
PM-usage count when it is registered. If a high-level driver does
nothing then the device will not be eligible for runtime-suspend
because of the elevated usage count. If a high-level driver wants to
use runtime PM then it can call scsi_autopm_put_device() in its probe
routine to decrement the usage count and scsi_autopm_get_device() in
its remove routine to restore the original count.
Hosts, targets, and LUNs are not suspended while they are being probed
or removed, or while the error handler is running. In fact, a fairly
large part of the patch consists of code to make sure that things
aren't suspended at such times.
[jejb: fix up compile issues in PM config variations]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
2010-06-17 21:41:42 +07:00
|
|
|
scsi_autopm_put_host(shost);
|
2014-10-11 17:06:47 +07:00
|
|
|
return error;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2014-10-11 17:06:47 +07:00
|
|
|
EXPORT_SYMBOL(scsi_ioctl_reset);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-10-24 19:26:52 +07:00
|
|
|
bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd,
|
|
|
|
struct scsi_sense_hdr *sshdr)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
return scsi_normalize_sense(cmd->sense_buffer,
|
2008-01-13 13:46:13 +07:00
|
|
|
SCSI_SENSE_BUFFERSIZE, sshdr);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_command_normalize_sense);
|
|
|
|
|
|
|
|
/**
|
2007-11-04 01:30:39 +07:00
|
|
|
* scsi_get_sense_info_fld - get information field from sense data (either fixed or descriptor format)
|
2005-04-17 05:20:36 +07:00
|
|
|
* @sense_buffer: byte array of sense data
|
|
|
|
* @sb_len: number of valid bytes in sense_buffer
|
|
|
|
* @info_out: pointer to 64 integer where 8 or 4 byte information
|
|
|
|
* field will be placed if found.
|
|
|
|
*
|
|
|
|
* Return value:
|
2017-04-24 14:51:12 +07:00
|
|
|
* true if information field found, false if not found.
|
2007-11-16 06:42:30 +07:00
|
|
|
*/
|
2017-04-24 14:51:12 +07:00
|
|
|
bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len,
|
|
|
|
u64 *info_out)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
const u8 * ucp;
|
|
|
|
|
|
|
|
if (sb_len < 7)
|
2017-04-24 14:51:12 +07:00
|
|
|
return false;
|
2005-04-17 05:20:36 +07:00
|
|
|
switch (sense_buffer[0] & 0x7f) {
|
|
|
|
case 0x70:
|
|
|
|
case 0x71:
|
|
|
|
if (sense_buffer[0] & 0x80) {
|
2017-04-24 14:51:12 +07:00
|
|
|
*info_out = get_unaligned_be32(&sense_buffer[3]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2005-04-17 05:20:36 +07:00
|
|
|
case 0x72:
|
|
|
|
case 0x73:
|
|
|
|
ucp = scsi_sense_desc_find(sense_buffer, sb_len,
|
|
|
|
0 /* info desc */);
|
|
|
|
if (ucp && (0xa == ucp[1])) {
|
2017-04-24 14:51:12 +07:00
|
|
|
*info_out = get_unaligned_be64(&ucp[4]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2005-04-17 05:20:36 +07:00
|
|
|
default:
|
2017-04-24 14:51:12 +07:00
|
|
|
return false;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_get_sense_info_fld);
|