2019-05-19 20:08:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* scsi_error.c Copyright (C) 1997 Eric Youngdale
|
|
|
|
*
|
|
|
|
* SCSI error/timeout handling
|
|
|
|
* Initial versions: Eric Youngdale. Based upon conversations with
|
2011-03-22 03:47:31 +08:00
|
|
|
* Leonard Zubkoff and David Miller at Linux Expo,
|
2005-04-17 06:20:36 +08: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 03:47:31 +08:00
|
|
|
* minor cleanups.
|
2005-04-17 06:20:36 +08: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 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/kernel.h>
|
2007-07-17 19:03:35 +08:00
|
|
|
#include <linux/freezer.h>
|
2005-09-06 20:04:26 +08:00
|
|
|
#include <linux/kthread.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/delay.h>
|
2013-04-25 14:10:00 +08:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <scsi/scsi.h>
|
2006-06-11 00:01:03 +08:00
|
|
|
#include <scsi/scsi_cmnd.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <scsi/scsi_dbg.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
2012-02-10 02:48:53 +08:00
|
|
|
#include <scsi/scsi_driver.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <scsi/scsi_eh.h>
|
2015-07-08 22:58:52 +08:00
|
|
|
#include <scsi/scsi_common.h>
|
2006-03-13 21:28:57 +08:00
|
|
|
#include <scsi/scsi_transport.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <scsi/scsi_ioctl.h>
|
2015-08-27 20:16:59 +08:00
|
|
|
#include <scsi/scsi_dh.h>
|
2018-04-18 07:35:10 +08:00
|
|
|
#include <scsi/scsi_devinfo.h>
|
2014-10-11 18:06:47 +08:00
|
|
|
#include <scsi/sg.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "scsi_priv.h"
|
|
|
|
#include "scsi_logging.h"
|
2007-08-11 05:50:42 +08:00
|
|
|
#include "scsi_transport_api.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-04-01 19:41:40 +08:00
|
|
|
#include <trace/events/scsi.h>
|
|
|
|
|
2024-10-02 03:35:57 +08:00
|
|
|
#include <linux/unaligned.h>
|
2017-04-24 15:51:12 +08:00
|
|
|
|
2005-04-17 06:20:36 +08: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 02:41:12 +08:00
|
|
|
static int scsi_eh_try_stu(struct scsi_cmnd *scmd);
|
2023-03-23 03:53:57 +08:00
|
|
|
static enum scsi_disposition scsi_try_to_abort_cmd(const struct scsi_host_template *,
|
2021-04-16 06:08:11 +08:00
|
|
|
struct scsi_cmnd *);
|
2011-05-20 02:41:12 +08:00
|
|
|
|
2024-01-12 15:00:00 +08:00
|
|
|
void scsi_eh_wakeup(struct Scsi_Host *shost, unsigned int busy)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-12-05 02:06:24 +08:00
|
|
|
lockdep_assert_held(shost->host_lock);
|
|
|
|
|
2024-01-12 15:00:00 +08:00
|
|
|
if (busy == shost->host_failed) {
|
2010-04-01 19:41:40 +08:00
|
|
|
trace_scsi_eh_wakeup(shost);
|
2005-09-19 22:50:04 +08:00
|
|
|
wake_up_process(shost->ehandler);
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(5, shost_printk(KERN_INFO, shost,
|
|
|
|
"Waking error handler thread\n"));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2006-05-19 20:07:05 +08: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 07:42:30 +08:00
|
|
|
*/
|
2006-05-19 20:07:05 +08: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++;
|
2024-01-12 15:00:00 +08:00
|
|
|
scsi_eh_wakeup(shost, scsi_host_busy(shost));
|
2006-05-19 20:07:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(scsi_schedule_eh);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-23 16:51:21 +08:00
|
|
|
static int scsi_host_eh_past_deadline(struct Scsi_Host *shost)
|
|
|
|
{
|
2013-11-11 20:44:56 +08:00
|
|
|
if (!shost->last_reset || shost->eh_deadline == -1)
|
2013-10-23 16:51:21 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-11-11 20:44:55 +08: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 20:44:56 +08:00
|
|
|
* if eh_deadline has been set to 'off' during the
|
2013-11-11 20:44:55 +08:00
|
|
|
* time_before call.
|
|
|
|
*/
|
|
|
|
if (time_before(jiffies, shost->last_reset + shost->eh_deadline) &&
|
2013-11-11 20:44:56 +08:00
|
|
|
shost->eh_deadline > -1)
|
2013-10-23 16:51:21 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-10-01 23:35:53 +08:00
|
|
|
static bool scsi_cmd_retry_allowed(struct scsi_cmnd *cmd)
|
|
|
|
{
|
|
|
|
if (cmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return ++cmd->retries <= cmd->allowed;
|
|
|
|
}
|
|
|
|
|
2021-01-07 05:49:05 +08:00
|
|
|
static bool scsi_eh_should_retry_cmd(struct scsi_cmnd *cmd)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev = cmd->device;
|
|
|
|
struct Scsi_Host *host = sdev->host;
|
|
|
|
|
|
|
|
if (host->hostt->eh_should_retry_cmd)
|
|
|
|
return host->hostt->eh_should_retry_cmd(cmd);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-11 20:44:54 +08:00
|
|
|
/**
|
|
|
|
* scmd_eh_abort_handler - Handle command aborts
|
|
|
|
* @work: command to be aborted.
|
2018-02-13 02:38:05 +08: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
|
2022-07-06 20:03:49 +08:00
|
|
|
* scsi_timeout(), a .scsi_done() call from the LLD for a command that has
|
2018-02-13 02:38:05 +08:00
|
|
|
* timed out do not have any effect. Hence it is safe to call
|
|
|
|
* scsi_finish_command() from this function.
|
2013-11-11 20:44:54 +08: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;
|
2021-10-30 03:43:11 +08:00
|
|
|
struct Scsi_Host *shost = sdev->host;
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2021-10-30 03:43:10 +08:00
|
|
|
unsigned long flags;
|
2013-11-11 20:44:54 +08:00
|
|
|
|
2021-10-30 03:43:11 +08:00
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
2013-11-11 20:44:54 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 14:43:50 +08:00
|
|
|
"eh timeout, not aborting\n"));
|
2021-10-30 03:43:11 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2013-11-11 20:44:54 +08:00
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 14:43:50 +08:00
|
|
|
"aborting command\n"));
|
2021-10-30 03:43:11 +08:00
|
|
|
rtn = scsi_try_to_abort_cmd(shost->hostt, scmd);
|
|
|
|
if (rtn != SUCCESS) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
|
|
|
"cmd abort %s\n",
|
|
|
|
(rtn == FAST_IO_FAIL) ?
|
|
|
|
"not send" : "failed"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
set_host_byte(scmd, DID_TIME_OUT);
|
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
|
|
|
"eh timeout, not retrying "
|
|
|
|
"aborted command\n"));
|
|
|
|
goto out;
|
2013-11-11 20:44:54 +08:00
|
|
|
}
|
|
|
|
|
2021-10-30 03:43:11 +08:00
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
2021-10-30 03:43:10 +08:00
|
|
|
list_del_init(&scmd->eh_entry);
|
2021-10-30 03:43:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the abort succeeds, and there is no further
|
|
|
|
* EH action, clear the ->last_reset time.
|
|
|
|
*/
|
|
|
|
if (list_empty(&shost->eh_abort_list) &&
|
|
|
|
list_empty(&shost->eh_cmd_q))
|
|
|
|
if (shost->eh_deadline != -1)
|
|
|
|
shost->last_reset = 0;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
|
|
|
|
if (!scsi_noretry_cmd(scmd) &&
|
|
|
|
scsi_cmd_retry_allowed(scmd) &&
|
|
|
|
scsi_eh_should_retry_cmd(scmd)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_WARNING, scmd,
|
|
|
|
"retry aborted command\n"));
|
|
|
|
scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
|
|
|
|
} else {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_WARNING, scmd,
|
|
|
|
"finish aborted command\n"));
|
|
|
|
scsi_finish_command(scmd);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
out:
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
list_del_init(&scmd->eh_entry);
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
|
2017-04-06 21:36:35 +08:00
|
|
|
scsi_eh_scmd_add(scmd);
|
2013-11-11 20:44:54 +08: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;
|
|
|
|
|
2022-12-06 21:13:45 +08:00
|
|
|
if (!shost->hostt->eh_abort_handler) {
|
|
|
|
/* No abort handler, fail command directly */
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2013-11-11 20:44:54 +08:00
|
|
|
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 14:43:50 +08:00
|
|
|
"previous abort failed\n"));
|
2014-06-02 17:50:52 +08:00
|
|
|
BUG_ON(delayed_work_pending(&scmd->abort_work));
|
2013-11-11 20:44:54 +08:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
2013-11-11 20:44:56 +08:00
|
|
|
if (shost->eh_deadline != -1 && !shost->last_reset)
|
2013-11-11 20:44:54 +08:00
|
|
|
shost->last_reset = jiffies;
|
2021-10-30 03:43:10 +08:00
|
|
|
BUG_ON(!list_empty(&scmd->eh_entry));
|
|
|
|
list_add_tail(&scmd->eh_entry, &shost->eh_abort_list);
|
2013-11-11 20:44:54 +08:00
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
|
|
|
|
scmd->eh_eflags |= SCSI_EH_ABORT_SCHEDULED;
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2015-01-08 14:43:50 +08:00
|
|
|
scmd_printk(KERN_INFO, scmd, "abort scheduled\n"));
|
2013-11-11 20:44:54 +08:00
|
|
|
queue_delayed_work(shost->tmf_work_q, &scmd->abort_work, HZ / 100);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
2017-04-06 21:36:29 +08:00
|
|
|
* scsi_eh_reset - call into ->eh_action to reset internal counters
|
2005-04-17 06:20:36 +08:00
|
|
|
* @scmd: scmd to run eh on.
|
|
|
|
*
|
2017-04-06 21:36:29 +08: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 07:42:30 +08:00
|
|
|
*/
|
2017-04-06 21:36:29 +08:00
|
|
|
static void scsi_eh_reset(struct scsi_cmnd *scmd)
|
|
|
|
{
|
2021-08-10 07:03:05 +08:00
|
|
|
if (!blk_rq_is_passthrough(scsi_cmd_to_rq(scmd))) {
|
2017-04-06 21:36:29 +08:00
|
|
|
struct scsi_driver *sdrv = scsi_cmd_to_driver(scmd);
|
|
|
|
if (sdrv->eh_reset)
|
|
|
|
sdrv->eh_reset(scmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 02:06:23 +08:00
|
|
|
static void scsi_eh_inc_host_failed(struct rcu_head *head)
|
|
|
|
{
|
2018-02-23 03:30:20 +08:00
|
|
|
struct scsi_cmnd *scmd = container_of(head, typeof(*scmd), rcu);
|
|
|
|
struct Scsi_Host *shost = scmd->device->host;
|
2024-02-03 10:45:21 +08:00
|
|
|
unsigned int busy = scsi_host_busy(shost);
|
2017-12-05 02:06:23 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
shost->host_failed++;
|
2024-02-03 10:45:21 +08:00
|
|
|
scsi_eh_wakeup(shost, busy);
|
2017-12-05 02:06:23 +08:00
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* scsi_eh_scmd_add - add scsi cmd to error handling.
|
|
|
|
* @scmd: scmd to run eh on.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2017-04-06 21:36:35 +08:00
|
|
|
void scsi_eh_scmd_add(struct scsi_cmnd *scmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct Scsi_Host *shost = scmd->device->host;
|
|
|
|
unsigned long flags;
|
2017-04-06 21:36:34 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-04-06 21:36:34 +08:00
|
|
|
WARN_ON_ONCE(!shost->ehandler);
|
2023-11-16 03:33:43 +08:00
|
|
|
WARN_ON_ONCE(!test_bit(SCMD_STATE_INFLIGHT, &scmd->state));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
2017-04-06 21:36:34 +08: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 20:44:56 +08:00
|
|
|
if (shost->eh_deadline != -1 && !shost->last_reset)
|
2013-10-23 16:51:21 +08:00
|
|
|
shost->last_reset = jiffies;
|
|
|
|
|
2017-04-06 21:36:29 +08:00
|
|
|
scsi_eh_reset(scmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
2017-12-05 02:06:23 +08:00
|
|
|
/*
|
|
|
|
* Ensure that all tasks observe the host state change before the
|
|
|
|
* host_failed change.
|
|
|
|
*/
|
scsi/scsi_error: Use call_rcu_hurry() instead of call_rcu()
Earlier commits in this series allow battery-powered systems to build
their kernels with the default-disabled CONFIG_RCU_LAZY=y Kconfig option.
This Kconfig option causes call_rcu() to delay its callbacks in order
to batch them. This means that a given RCU grace period covers more
callbacks, thus reducing the number of grace periods, in turn reducing
the amount of energy consumed, which increases battery lifetime which
can be a very good thing. This is not a subtle effect: In some important
use cases, the battery lifetime is increased by more than 10%.
This CONFIG_RCU_LAZY=y option is available only for CPUs that offload
callbacks, for example, CPUs mentioned in the rcu_nocbs kernel boot
parameter passed to kernels built with CONFIG_RCU_NOCB_CPU=y.
Delaying callbacks is normally not a problem because most callbacks do
nothing but free memory. If the system is short on memory, a shrinker
will kick all currently queued lazy callbacks out of their laziness,
thus freeing their memory in short order. Similarly, the rcu_barrier()
function, which blocks until all currently queued callbacks are invoked,
will also kick lazy callbacks, thus enabling rcu_barrier() to complete
in a timely manner.
However, there are some cases where laziness is not a good option.
For example, synchronize_rcu() invokes call_rcu(), and blocks until
the newly queued callback is invoked. It would not be a good for
synchronize_rcu() to block for ten seconds, even on an idle system.
Therefore, synchronize_rcu() invokes call_rcu_hurry() instead of
call_rcu(). The arrival of a non-lazy call_rcu_hurry() callback on a
given CPU kicks any lazy callbacks that might be already queued on that
CPU. After all, if there is going to be a grace period, all callbacks
might as well get full benefit from it.
Yes, this could be done the other way around by creating a
call_rcu_lazy(), but earlier experience with this approach and
feedback at the 2022 Linux Plumbers Conference shifted the approach
to call_rcu() being lazy with call_rcu_hurry() for the few places
where laziness is inappropriate.
And another call_rcu() instance that cannot be lazy is the one in the
scsi_eh_scmd_add() function. Leaving this instance lazy results in
unacceptably slow boot times.
Therefore, make scsi_eh_scmd_add() use call_rcu_hurry() in order to
revert to the old behavior.
[ paulmck: Apply s/call_rcu_flush/call_rcu_hurry/ feedback from Tejun Heo. ]
Tested-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Uladzislau Rezki <urezki@gmail.com>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: <linux-scsi@vger.kernel.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Acked-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
2022-10-17 00:23:02 +08:00
|
|
|
call_rcu_hurry(&scmd->rcu, scsi_eh_inc_host_failed);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-06 20:03:49 +08:00
|
|
|
* scsi_timeout - Timeout function for normal scsi commands.
|
2008-09-14 20:55:09 +08:00
|
|
|
* @req: request that is timing out.
|
2005-04-17 06:20:36 +08: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 07:42:30 +08:00
|
|
|
*/
|
2022-07-06 20:03:51 +08:00
|
|
|
enum blk_eh_timer_return scsi_timeout(struct request *req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-08-26 04:46:32 +08:00
|
|
|
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
|
2011-03-22 03:47:31 +08:00
|
|
|
struct Scsi_Host *host = scmd->device->host;
|
2007-03-17 06:44:41 +08:00
|
|
|
|
2010-04-01 19:41:40 +08:00
|
|
|
trace_scsi_dispatch_cmd_timeout(scmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_log_completion(scmd, TIMEOUT_ERROR);
|
|
|
|
|
2022-09-20 17:32:19 +08:00
|
|
|
atomic_inc(&scmd->device->iotmo_cnt);
|
2013-11-11 20:44:56 +08:00
|
|
|
if (host->eh_deadline != -1 && !host->last_reset)
|
2013-10-23 16:51:21 +08:00
|
|
|
host->last_reset = jiffies;
|
|
|
|
|
2022-10-19 04:29:50 +08:00
|
|
|
if (host->hostt->eh_timed_out) {
|
|
|
|
switch (host->hostt->eh_timed_out(scmd)) {
|
|
|
|
case SCSI_EH_DONE:
|
2022-10-19 04:29:49 +08:00
|
|
|
return BLK_EH_DONE;
|
2022-10-19 04:29:50 +08:00
|
|
|
case SCSI_EH_RESET_TIMER:
|
2018-11-27 00:54:29 +08:00
|
|
|
return BLK_EH_RESET_TIMER;
|
2022-10-19 04:29:50 +08:00
|
|
|
case SCSI_EH_NOT_HANDLED:
|
|
|
|
break;
|
2017-04-06 21:36:34 +08:00
|
|
|
}
|
2014-06-13 20:01:45 +08:00
|
|
|
}
|
2008-09-14 20:55:09 +08:00
|
|
|
|
2022-10-19 04:29:50 +08:00
|
|
|
/*
|
|
|
|
* If scsi_done() has already set SCMD_STATE_COMPLETE, do not modify
|
|
|
|
* *scmd.
|
|
|
|
*/
|
|
|
|
if (test_and_set_bit(SCMD_STATE_COMPLETE, &scmd->state))
|
|
|
|
return BLK_EH_DONE;
|
2022-11-23 20:21:36 +08:00
|
|
|
atomic_inc(&scmd->device->iodone_cnt);
|
2022-10-19 04:29:50 +08:00
|
|
|
if (scsi_abort_command(scmd) != SUCCESS) {
|
|
|
|
set_host_byte(scmd, DID_TIME_OUT);
|
|
|
|
scsi_eh_scmd_add(scmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return BLK_EH_DONE;
|
2005-04-17 06:20:36 +08: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 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int scsi_block_when_processing_errors(struct scsi_device *sdev)
|
|
|
|
{
|
|
|
|
int online;
|
|
|
|
|
2005-09-19 04:05:20 +08:00
|
|
|
wait_event(sdev->host->host_wait, !scsi_host_in_recovery(sdev->host));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
online = scsi_device_online(sdev);
|
|
|
|
|
|
|
|
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 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08: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 21:36:35 +08:00
|
|
|
if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED)
|
2005-04-17 06:20:36 +08:00
|
|
|
++cmd_cancel;
|
2011-03-22 03:47:31 +08:00
|
|
|
else
|
2005-04-17 06:20:36 +08:00
|
|
|
++cmd_failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd_cancel || cmd_failed) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 20:27:03 +08:00
|
|
|
shost_printk(KERN_INFO, shost,
|
2005-10-03 00:45:08 +08:00
|
|
|
"%s: cmds failed: %d, cancel: %d\n",
|
2008-07-04 14:47:27 +08:00
|
|
|
__func__, cmd_failed,
|
2005-10-03 00:45:08 +08:00
|
|
|
cmd_cancel));
|
2005-04-17 06:20:36 +08:00
|
|
|
cmd_cancel = 0;
|
|
|
|
cmd_failed = 0;
|
|
|
|
++devices_failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-25 22:39:59 +08: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 03:47:31 +08:00
|
|
|
total_failures, devices_failed));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-09 03:07:48 +08: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,
|
|
|
|
"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,
|
2022-06-30 10:38:11 +08:00
|
|
|
"Operating parameters on this target have "
|
2013-08-09 03:07:48 +08:00
|
|
|
"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 15:11:24 +08:00
|
|
|
if (sshdr->asc == 0x29) {
|
|
|
|
evt_type = SDEV_EVT_POWER_ON_RESET_OCCURRED;
|
2022-02-28 19:36:51 +08:00
|
|
|
/*
|
|
|
|
* Do not print message if it is an expected side-effect
|
|
|
|
* of runtime PM.
|
|
|
|
*/
|
|
|
|
if (!sdev->silence_suspend)
|
|
|
|
sdev_printk(KERN_WARNING, sdev,
|
|
|
|
"Power-on or device reset occurred\n");
|
2017-10-17 15:11:24 +08:00
|
|
|
}
|
|
|
|
|
2013-08-09 03:07:48 +08: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 19:41:53 +08: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 03:07:48 +08: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-12 09:00:25 +08:00
|
|
|
static inline void set_scsi_ml_byte(struct scsi_cmnd *cmd, u8 status)
|
|
|
|
{
|
|
|
|
cmd->result = (cmd->result & 0xffff00ff) | (status << 8);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* scsi_check_sense - Examine scsi cmd sense
|
|
|
|
* @scmd: Cmd to have sense checked.
|
|
|
|
*
|
|
|
|
* Return value:
|
2013-07-01 21:16:24 +08:00
|
|
|
* SUCCESS or FAILED or NEEDS_RETRY or ADD_TO_MLQUEUE
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* When a deferred error is detected the current command has
|
|
|
|
* not been executed and needs retrying.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition scsi_check_sense(struct scsi_cmnd *scmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
scsi: sd: Handle read/write CDL timeout failures
Commands using a duration limit descriptor that has limit policies set to a
value other than 0x0 may be failed by the device if one of the limits are
exceeded. For such commands, since the failure is the result of the user
duration limit configuration and workload, the commands should not be
retried and terminated immediately. Furthermore, to allow the user to
differentiate these "soft" failures from hard errors due to hardware
problem, a different error code than EIO should be returned.
There are 2 cases to consider:
(1) The failure is due to a limit policy failing the command with a check
condition sense key, that is, any limit policy other than 0xD. For this
case, scsi_check_sense() is modified to detect failures with the ABORTED
COMMAND sense key and the COMMAND TIMEOUT BEFORE PROCESSING or COMMAND
TIMEOUT DURING PROCESSING or COMMAND TIMEOUT DURING PROCESSING DUE TO ERROR
RECOVERY additional sense code. For these failures, a SUCCESS disposition
is returned so that scsi_finish_command() is called to terminate the
command.
(2) The failure is due to a limit policy set to 0xD, which result in the
command being terminated with a GOOD status, COMPLETED sense key, and DATA
CURRENTLY UNAVAILABLE additional sense code. To handle this case, the
scsi_check_sense() is modified to return a SUCCESS disposition so that
scsi_finish_command() is called to terminate the command. In addition,
scsi_decide_disposition() has to be modified to see if a command being
terminated with GOOD status has sense data. This is as defined in SCSI
Primary Commands - 6 (SPC-6), so all according to spec, even if GOOD status
commands were not checked before.
If scsi_check_sense() detects sense data representing a duration limit,
scsi_check_sense() will set the newly introduced SCSI ML byte
SCSIML_STAT_DL_TIMEOUT. This SCSI ML byte is checked in scsi_noretry_cmd(),
so that a command that failed because of a CDL timeout cannot be
retried. The SCSI ML byte is also checked in scsi_result_to_blk_status() to
complete the command request with the BLK_STS_DURATION_LIMIT status, which
result in the user seeing ETIME errors for the failed commands.
Co-developed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20230511011356.227789-12-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2023-05-11 09:13:44 +08:00
|
|
|
struct request *req = scsi_cmd_to_rq(scmd);
|
2008-05-02 05:49:46 +08:00
|
|
|
struct scsi_device *sdev = scmd->device;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
|
|
|
|
if (! scsi_command_normalize_sense(scmd, &sshdr))
|
|
|
|
return FAILED; /* no valid sense data */
|
|
|
|
|
2013-08-09 03:07:48 +08:00
|
|
|
scsi_report_sense(sdev, &sshdr);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (scsi_sense_is_deferred(&sshdr))
|
|
|
|
return NEEDS_RETRY;
|
|
|
|
|
2015-08-27 20:16:59 +08:00
|
|
|
if (sdev->handler && sdev->handler->check_sense) {
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rc;
|
2008-05-02 05:49:46 +08:00
|
|
|
|
2015-08-27 20:16:59 +08:00
|
|
|
rc = sdev->handler->check_sense(sdev, &sshdr);
|
2008-05-02 05:49:46 +08:00
|
|
|
if (rc != SCSI_RETURN_NOT_HANDLED)
|
|
|
|
return rc;
|
|
|
|
/* handler does not care. Drop down to default handling */
|
|
|
|
}
|
|
|
|
|
2021-10-08 04:27:56 +08:00
|
|
|
if (scmd->cmnd[0] == TEST_UNIT_READY &&
|
|
|
|
scmd->submitter != SUBMITTED_BY_SCSI_ERROR_HANDLER)
|
2014-11-07 05:11:22 +08:00
|
|
|
/*
|
|
|
|
* 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 06:20:36 +08: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 16:28:33 +08:00
|
|
|
if (sshdr.asc == 0x10) /* DIF */
|
|
|
|
return SUCCESS;
|
|
|
|
|
scsi: sd: Handle read/write CDL timeout failures
Commands using a duration limit descriptor that has limit policies set to a
value other than 0x0 may be failed by the device if one of the limits are
exceeded. For such commands, since the failure is the result of the user
duration limit configuration and workload, the commands should not be
retried and terminated immediately. Furthermore, to allow the user to
differentiate these "soft" failures from hard errors due to hardware
problem, a different error code than EIO should be returned.
There are 2 cases to consider:
(1) The failure is due to a limit policy failing the command with a check
condition sense key, that is, any limit policy other than 0xD. For this
case, scsi_check_sense() is modified to detect failures with the ABORTED
COMMAND sense key and the COMMAND TIMEOUT BEFORE PROCESSING or COMMAND
TIMEOUT DURING PROCESSING or COMMAND TIMEOUT DURING PROCESSING DUE TO ERROR
RECOVERY additional sense code. For these failures, a SUCCESS disposition
is returned so that scsi_finish_command() is called to terminate the
command.
(2) The failure is due to a limit policy set to 0xD, which result in the
command being terminated with a GOOD status, COMPLETED sense key, and DATA
CURRENTLY UNAVAILABLE additional sense code. To handle this case, the
scsi_check_sense() is modified to return a SUCCESS disposition so that
scsi_finish_command() is called to terminate the command. In addition,
scsi_decide_disposition() has to be modified to see if a command being
terminated with GOOD status has sense data. This is as defined in SCSI
Primary Commands - 6 (SPC-6), so all according to spec, even if GOOD status
commands were not checked before.
If scsi_check_sense() detects sense data representing a duration limit,
scsi_check_sense() will set the newly introduced SCSI ML byte
SCSIML_STAT_DL_TIMEOUT. This SCSI ML byte is checked in scsi_noretry_cmd(),
so that a command that failed because of a CDL timeout cannot be
retried. The SCSI ML byte is also checked in scsi_result_to_blk_status() to
complete the command request with the BLK_STS_DURATION_LIMIT status, which
result in the user seeing ETIME errors for the failed commands.
Co-developed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20230511011356.227789-12-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2023-05-11 09:13:44 +08:00
|
|
|
/*
|
|
|
|
* Check aborts due to command duration limit policy:
|
|
|
|
* ABORTED COMMAND additional sense code with the
|
|
|
|
* COMMAND TIMEOUT BEFORE PROCESSING or
|
|
|
|
* COMMAND TIMEOUT DURING PROCESSING or
|
|
|
|
* COMMAND TIMEOUT DURING PROCESSING DUE TO ERROR RECOVERY
|
|
|
|
* additional sense code qualifiers.
|
|
|
|
*/
|
|
|
|
if (sshdr.asc == 0x2e &&
|
|
|
|
sshdr.ascq >= 0x01 && sshdr.ascq <= 0x03) {
|
|
|
|
set_scsi_ml_byte(scmd, SCSIML_STAT_DL_TIMEOUT);
|
|
|
|
req->cmd_flags |= REQ_FAILFAST_DEV;
|
|
|
|
req->rq_flags |= RQF_QUIET;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-04-18 07:35:10 +08:00
|
|
|
if (sshdr.asc == 0x44 && sdev->sdev_bflags & BLIST_RETRY_ITF)
|
|
|
|
return ADD_TO_MLQUEUE;
|
2018-04-18 07:35:11 +08:00
|
|
|
if (sshdr.asc == 0xc1 && sshdr.ascq == 0x01 &&
|
|
|
|
sdev->sdev_bflags & BLIST_RETRY_ASC_C1)
|
|
|
|
return ADD_TO_MLQUEUE;
|
2018-04-18 07:35:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08: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 19:25:20 +08: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 06:20:36 +08:00
|
|
|
}
|
2013-08-09 03:07:48 +08: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 06:20:36 +08:00
|
|
|
/*
|
2011-03-22 03:47:31 +08:00
|
|
|
* if the device is in the process of becoming ready, we
|
2005-04-17 06:20:36 +08: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 21:54:09 +08:00
|
|
|
/*
|
|
|
|
* Pass the UA upwards for a determination in the completion
|
|
|
|
* functions.
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-01-18 17:13:11 +08:00
|
|
|
/* these are not supported */
|
2013-07-01 21:16:25 +08:00
|
|
|
case DATA_PROTECT:
|
|
|
|
if (sshdr.asc == 0x27 && sshdr.ascq == 0x07) {
|
|
|
|
/* Thin provisioning hard threshold reached */
|
2022-08-12 09:00:26 +08:00
|
|
|
set_scsi_ml_byte(scmd, SCSIML_STAT_NOSPC);
|
2013-07-01 21:16:25 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2005-04-17 06:20:36 +08:00
|
|
|
case COPY_ABORTED:
|
|
|
|
case VOLUME_OVERFLOW:
|
|
|
|
case MISCOMPARE:
|
2011-01-18 17:13:11 +08:00
|
|
|
case BLANK_CHECK:
|
2022-08-12 09:00:26 +08:00
|
|
|
set_scsi_ml_byte(scmd, SCSIML_STAT_TGT_FAILURE);
|
2013-07-01 21:16:24 +08:00
|
|
|
return SUCCESS;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
case MEDIUM_ERROR:
|
2006-11-30 11:45:23 +08:00
|
|
|
if (sshdr.asc == 0x11 || /* UNRECOVERED READ ERR */
|
|
|
|
sshdr.asc == 0x13 || /* AMNF DATA FIELD */
|
|
|
|
sshdr.asc == 0x14) { /* RECORD NOT FOUND */
|
2022-08-12 09:00:26 +08:00
|
|
|
set_scsi_ml_byte(scmd, SCSIML_STAT_MED_ERROR);
|
2013-07-01 21:16:24 +08:00
|
|
|
return SUCCESS;
|
2006-11-30 11:45:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return NEEDS_RETRY;
|
|
|
|
|
|
|
|
case HARDWARE_ERROR:
|
|
|
|
if (scmd->device->retry_hwerror)
|
2008-08-13 03:11:58 +08:00
|
|
|
return ADD_TO_MLQUEUE;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2022-08-12 09:00:26 +08:00
|
|
|
set_scsi_ml_byte(scmd, SCSIML_STAT_TGT_FAILURE);
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
case ILLEGAL_REQUEST:
|
2012-02-14 07:35:11 +08:00
|
|
|
if (sshdr.asc == 0x20 || /* Invalid command operation code */
|
|
|
|
sshdr.asc == 0x21 || /* Logical block address out of range */
|
2017-10-17 15:10:56 +08:00
|
|
|
sshdr.asc == 0x22 || /* Invalid function */
|
2012-02-14 07:35:11 +08:00
|
|
|
sshdr.asc == 0x24 || /* Invalid field in cdb */
|
2017-09-27 20:44:19 +08:00
|
|
|
sshdr.asc == 0x26 || /* Parameter value invalid */
|
|
|
|
sshdr.asc == 0x27) { /* Write protected */
|
2022-08-12 09:00:26 +08:00
|
|
|
set_scsi_ml_byte(scmd, SCSIML_STAT_TGT_FAILURE);
|
2012-02-14 07:35:11 +08:00
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
|
scsi: sd: Handle read/write CDL timeout failures
Commands using a duration limit descriptor that has limit policies set to a
value other than 0x0 may be failed by the device if one of the limits are
exceeded. For such commands, since the failure is the result of the user
duration limit configuration and workload, the commands should not be
retried and terminated immediately. Furthermore, to allow the user to
differentiate these "soft" failures from hard errors due to hardware
problem, a different error code than EIO should be returned.
There are 2 cases to consider:
(1) The failure is due to a limit policy failing the command with a check
condition sense key, that is, any limit policy other than 0xD. For this
case, scsi_check_sense() is modified to detect failures with the ABORTED
COMMAND sense key and the COMMAND TIMEOUT BEFORE PROCESSING or COMMAND
TIMEOUT DURING PROCESSING or COMMAND TIMEOUT DURING PROCESSING DUE TO ERROR
RECOVERY additional sense code. For these failures, a SUCCESS disposition
is returned so that scsi_finish_command() is called to terminate the
command.
(2) The failure is due to a limit policy set to 0xD, which result in the
command being terminated with a GOOD status, COMPLETED sense key, and DATA
CURRENTLY UNAVAILABLE additional sense code. To handle this case, the
scsi_check_sense() is modified to return a SUCCESS disposition so that
scsi_finish_command() is called to terminate the command. In addition,
scsi_decide_disposition() has to be modified to see if a command being
terminated with GOOD status has sense data. This is as defined in SCSI
Primary Commands - 6 (SPC-6), so all according to spec, even if GOOD status
commands were not checked before.
If scsi_check_sense() detects sense data representing a duration limit,
scsi_check_sense() will set the newly introduced SCSI ML byte
SCSIML_STAT_DL_TIMEOUT. This SCSI ML byte is checked in scsi_noretry_cmd(),
so that a command that failed because of a CDL timeout cannot be
retried. The SCSI ML byte is also checked in scsi_result_to_blk_status() to
complete the command request with the BLK_STS_DURATION_LIMIT status, which
result in the user seeing ETIME errors for the failed commands.
Co-developed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20230511011356.227789-12-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2023-05-11 09:13:44 +08:00
|
|
|
case COMPLETED:
|
|
|
|
if (sshdr.asc == 0x55 && sshdr.ascq == 0x0a) {
|
|
|
|
set_scsi_ml_byte(scmd, SCSIML_STAT_DL_TIMEOUT);
|
|
|
|
req->cmd_flags |= REQ_FAILFAST_DEV;
|
|
|
|
req->rq_flags |= RQF_QUIET;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2016-04-04 17:44:01 +08:00
|
|
|
EXPORT_SYMBOL_GPL(scsi_check_sense);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-10-23 06:46:33 +08:00
|
|
|
static void scsi_handle_queue_ramp_up(struct scsi_device *sdev)
|
|
|
|
{
|
2023-03-23 03:53:57 +08:00
|
|
|
const struct scsi_host_template *sht = sdev->host->hostt;
|
2009-10-23 06:46:33 +08:00
|
|
|
struct scsi_device *tmp_sdev;
|
|
|
|
|
2014-11-13 21:25:11 +08:00
|
|
|
if (!sht->track_queue_depth ||
|
2009-10-23 06:46:33 +08: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 21:25:11 +08:00
|
|
|
|
2014-11-13 22:08:42 +08:00
|
|
|
scsi_change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1);
|
2009-10-23 06:46:33 +08:00
|
|
|
sdev->last_queue_ramp_up = jiffies;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-16 08:46:44 +08:00
|
|
|
static void scsi_handle_queue_full(struct scsi_device *sdev)
|
|
|
|
{
|
2023-03-23 03:53:57 +08:00
|
|
|
const struct scsi_host_template *sht = sdev->host->hostt;
|
2009-10-16 08:46:44 +08:00
|
|
|
struct scsi_device *tmp_sdev;
|
|
|
|
|
2014-11-13 21:25:11 +08:00
|
|
|
if (!sht->track_queue_depth)
|
2009-10-16 08:46:44 +08: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 21:25:11 +08:00
|
|
|
scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1);
|
2009-10-16 08:46:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08: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 07:42:30 +08:00
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
static enum scsi_disposition scsi_eh_completed_normally(struct scsi_cmnd *scmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now, check the status byte to see if this indicates
|
|
|
|
* anything special.
|
|
|
|
*/
|
2021-04-27 16:30:46 +08:00
|
|
|
switch (get_status_byte(scmd)) {
|
|
|
|
case SAM_STAT_GOOD:
|
2009-10-23 06:46:33 +08:00
|
|
|
scsi_handle_queue_ramp_up(scmd->device);
|
scsi: sd: Handle read/write CDL timeout failures
Commands using a duration limit descriptor that has limit policies set to a
value other than 0x0 may be failed by the device if one of the limits are
exceeded. For such commands, since the failure is the result of the user
duration limit configuration and workload, the commands should not be
retried and terminated immediately. Furthermore, to allow the user to
differentiate these "soft" failures from hard errors due to hardware
problem, a different error code than EIO should be returned.
There are 2 cases to consider:
(1) The failure is due to a limit policy failing the command with a check
condition sense key, that is, any limit policy other than 0xD. For this
case, scsi_check_sense() is modified to detect failures with the ABORTED
COMMAND sense key and the COMMAND TIMEOUT BEFORE PROCESSING or COMMAND
TIMEOUT DURING PROCESSING or COMMAND TIMEOUT DURING PROCESSING DUE TO ERROR
RECOVERY additional sense code. For these failures, a SUCCESS disposition
is returned so that scsi_finish_command() is called to terminate the
command.
(2) The failure is due to a limit policy set to 0xD, which result in the
command being terminated with a GOOD status, COMPLETED sense key, and DATA
CURRENTLY UNAVAILABLE additional sense code. To handle this case, the
scsi_check_sense() is modified to return a SUCCESS disposition so that
scsi_finish_command() is called to terminate the command. In addition,
scsi_decide_disposition() has to be modified to see if a command being
terminated with GOOD status has sense data. This is as defined in SCSI
Primary Commands - 6 (SPC-6), so all according to spec, even if GOOD status
commands were not checked before.
If scsi_check_sense() detects sense data representing a duration limit,
scsi_check_sense() will set the newly introduced SCSI ML byte
SCSIML_STAT_DL_TIMEOUT. This SCSI ML byte is checked in scsi_noretry_cmd(),
so that a command that failed because of a CDL timeout cannot be
retried. The SCSI ML byte is also checked in scsi_result_to_blk_status() to
complete the command request with the BLK_STS_DURATION_LIMIT status, which
result in the user seeing ETIME errors for the failed commands.
Co-developed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20230511011356.227789-12-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2023-05-11 09:13:44 +08:00
|
|
|
if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd))
|
|
|
|
/*
|
|
|
|
* If we have sense data, call scsi_check_sense() in
|
|
|
|
* order to set the correct SCSI ML byte (if any).
|
|
|
|
* No point in checking the return value, since the
|
|
|
|
* command has already completed successfully.
|
|
|
|
*/
|
|
|
|
scsi_check_sense(scmd);
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_COMMAND_TERMINATED:
|
2005-04-17 06:20:36 +08:00
|
|
|
return SUCCESS;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_CHECK_CONDITION:
|
2005-04-17 06:20:36 +08:00
|
|
|
return scsi_check_sense(scmd);
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_CONDITION_MET:
|
|
|
|
case SAM_STAT_INTERMEDIATE:
|
|
|
|
case SAM_STAT_INTERMEDIATE_CONDITION_MET:
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* who knows? FIXME(eric)
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_RESERVATION_CONFLICT:
|
2010-08-07 04:17:24 +08: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;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_TASK_SET_FULL:
|
2009-10-16 08:46:44 +08:00
|
|
|
scsi_handle_queue_full(scmd->device);
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_BUSY:
|
2010-07-29 16:10:16 +08:00
|
|
|
return NEEDS_RETRY;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_done - Completion function for error handling.
|
|
|
|
* @scmd: Cmd that is done.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2021-10-08 04:27:56 +08:00
|
|
|
void scsi_eh_done(struct scsi_cmnd *scmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-03-22 03:47:31 +08:00
|
|
|
struct completion *eh_action;
|
2005-12-08 11:46:27 +08:00
|
|
|
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
2015-01-08 14:43:50 +08:00
|
|
|
"%s result: %x\n", __func__, scmd->result));
|
2005-12-08 11:46:27 +08:00
|
|
|
|
|
|
|
eh_action = scmd->device->host->eh_action;
|
|
|
|
if (eh_action)
|
|
|
|
complete(eh_action);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-01-31 07:51:17 +08:00
|
|
|
/**
|
|
|
|
* scsi_try_host_reset - ask host adapter to reset itself
|
2013-05-17 19:22:29 +08:00
|
|
|
* @scmd: SCSI cmd to send host reset.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
static enum scsi_disposition scsi_try_host_reset(struct scsi_cmnd *scmd)
|
2007-01-31 07:51:17 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2011-03-22 03:47:31 +08:00
|
|
|
struct Scsi_Host *host = scmd->device->host;
|
2023-03-23 03:53:57 +08:00
|
|
|
const struct scsi_host_template *hostt = host->hostt;
|
2007-01-31 07:51:17 +08:00
|
|
|
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, host, "Snd Host RST\n"));
|
2007-01-31 07:51:17 +08:00
|
|
|
|
2011-03-22 03:47:31 +08:00
|
|
|
if (!hostt->eh_host_reset_handler)
|
2007-01-31 07:51:17 +08:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 03:47:31 +08:00
|
|
|
rtn = hostt->eh_host_reset_handler(scmd);
|
2007-01-31 07:51:17 +08:00
|
|
|
|
|
|
|
if (rtn == SUCCESS) {
|
2011-03-22 03:47:31 +08:00
|
|
|
if (!hostt->skip_settle_delay)
|
2007-01-31 07:51:17 +08:00
|
|
|
ssleep(HOST_RESET_SETTLE_TIME);
|
2011-03-22 03:47:31 +08: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 07:51:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_try_bus_reset - ask host to perform a bus reset
|
|
|
|
* @scmd: SCSI cmd to send bus reset.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
static enum scsi_disposition scsi_try_bus_reset(struct scsi_cmnd *scmd)
|
2007-01-31 07:51:17 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2011-03-22 03:47:31 +08:00
|
|
|
struct Scsi_Host *host = scmd->device->host;
|
2023-03-23 03:53:57 +08:00
|
|
|
const struct scsi_host_template *hostt = host->hostt;
|
2007-01-31 07:51:17 +08:00
|
|
|
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: Snd Bus RST\n", __func__));
|
2007-01-31 07:51:17 +08:00
|
|
|
|
2011-03-22 03:47:31 +08:00
|
|
|
if (!hostt->eh_bus_reset_handler)
|
2007-01-31 07:51:17 +08:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 03:47:31 +08:00
|
|
|
rtn = hostt->eh_bus_reset_handler(scmd);
|
2007-01-31 07:51:17 +08:00
|
|
|
|
|
|
|
if (rtn == SUCCESS) {
|
2011-03-22 03:47:31 +08:00
|
|
|
if (!hostt->skip_settle_delay)
|
2007-01-31 07:51:17 +08:00
|
|
|
ssleep(BUS_RESET_SETTLE_TIME);
|
2011-03-22 03:47:31 +08: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 07:51:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2008-03-01 08:25:19 +08: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.
|
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd)
|
2008-03-01 08:25:19 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2011-03-22 03:47:31 +08:00
|
|
|
struct Scsi_Host *host = scmd->device->host;
|
2023-03-23 03:53:57 +08:00
|
|
|
const struct scsi_host_template *hostt = host->hostt;
|
2008-03-01 08:25:19 +08:00
|
|
|
|
2011-03-22 03:47:31 +08:00
|
|
|
if (!hostt->eh_target_reset_handler)
|
2008-03-01 08:25:19 +08:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 03:47:31 +08:00
|
|
|
rtn = hostt->eh_target_reset_handler(scmd);
|
2008-03-01 08:25:19 +08:00
|
|
|
if (rtn == SUCCESS) {
|
2011-03-22 03:47:31 +08:00
|
|
|
spin_lock_irqsave(host->host_lock, flags);
|
2008-03-01 08:25:19 +08:00
|
|
|
__starget_for_each_device(scsi_target(scmd->device), NULL,
|
|
|
|
__scsi_report_device_reset);
|
2011-03-22 03:47:31 +08:00
|
|
|
spin_unlock_irqrestore(host->host_lock, flags);
|
2008-03-01 08:25:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2007-01-31 07:51:17 +08: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 07:42:30 +08:00
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
static enum scsi_disposition scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
|
2007-01-31 07:51:17 +08:00
|
|
|
{
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2023-03-23 03:53:57 +08:00
|
|
|
const struct scsi_host_template *hostt = scmd->device->host->hostt;
|
2007-01-31 07:51:17 +08:00
|
|
|
|
2011-03-22 03:47:31 +08:00
|
|
|
if (!hostt->eh_device_reset_handler)
|
2007-01-31 07:51:17 +08:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 03:47:31 +08:00
|
|
|
rtn = hostt->eh_device_reset_handler(scmd);
|
2008-03-01 08:25:19 +08:00
|
|
|
if (rtn == SUCCESS)
|
|
|
|
__scsi_report_device_reset(scmd->device, NULL);
|
2007-01-31 07:51:17 +08:00
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2014-10-24 20:27:04 +08:00
|
|
|
/**
|
|
|
|
* scsi_try_to_abort_cmd - Ask host to abort a SCSI command
|
2014-12-30 01:40:56 +08:00
|
|
|
* @hostt: SCSI driver host template
|
2014-10-24 20:27:04 +08: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)
|
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
static enum scsi_disposition
|
2023-03-23 03:53:57 +08:00
|
|
|
scsi_try_to_abort_cmd(const struct scsi_host_template *hostt, struct scsi_cmnd *scmd)
|
2007-01-31 07:51:17 +08:00
|
|
|
{
|
2011-03-22 03:47:31 +08:00
|
|
|
if (!hostt->eh_abort_handler)
|
2007-01-31 07:51:17 +08:00
|
|
|
return FAILED;
|
|
|
|
|
2011-03-22 03:47:31 +08:00
|
|
|
return hostt->eh_abort_handler(scmd);
|
2007-01-31 07:51:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
|
|
|
|
{
|
2011-03-22 03:47:31 +08:00
|
|
|
if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS)
|
2007-01-31 07:51:17 +08:00
|
|
|
if (scsi_try_bus_device_reset(scmd) != SUCCESS)
|
2008-03-01 08:25:19 +08:00
|
|
|
if (scsi_try_target_reset(scmd) != SUCCESS)
|
|
|
|
if (scsi_try_bus_reset(scmd) != SUCCESS)
|
|
|
|
scsi_try_host_reset(scmd);
|
2007-01-31 07:51:17 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
2012-04-08 21:17:09 +08:00
|
|
|
* scsi_eh_prep_cmnd - Save a scsi command info as part of error recovery
|
2006-11-05 03:04:21 +08:00
|
|
|
* @scmd: SCSI command structure to hijack
|
2007-10-08 22:36:45 +08:00
|
|
|
* @ses: structure to save restore information
|
2007-10-08 22:35:19 +08:00
|
|
|
* @cmnd: CDB to send. Can be NULL if no new cmnd is needed
|
2022-02-25 01:55:47 +08:00
|
|
|
* @cmnd_size: size in bytes of @cmnd (must be <= MAX_COMMAND_SIZE)
|
2007-10-08 22:35:19 +08:00
|
|
|
* @sense_bytes: size of sense data to copy. or 0 (if != 0 @cmnd is ignored)
|
2006-11-05 03:04:21 +08:00
|
|
|
*
|
2007-10-08 22:36:45 +08:00
|
|
|
* This function is used to save a scsi command information before re-execution
|
2007-10-08 22:35:19 +08: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 07:42:30 +08:00
|
|
|
*/
|
2007-10-08 22:36:45 +08: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 06:20:36 +08:00
|
|
|
{
|
2005-04-18 04:00:23 +08:00
|
|
|
struct scsi_device *sdev = scmd->device;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-09 02:42:15 +08: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 22:36:45 +08:00
|
|
|
ses->cmd_len = scmd->cmd_len;
|
|
|
|
ses->data_direction = scmd->sc_data_direction;
|
2007-12-13 19:47:40 +08:00
|
|
|
ses->sdb = scmd->sdb;
|
2007-10-08 22:36:45 +08:00
|
|
|
ses->result = scmd->result;
|
2022-02-25 01:55:49 +08:00
|
|
|
ses->resid_len = scmd->resid_len;
|
2008-07-21 22:25:52 +08:00
|
|
|
ses->underflow = scmd->underflow;
|
2008-07-17 16:28:31 +08:00
|
|
|
ses->prot_op = scmd->prot_op;
|
2017-04-06 21:36:33 +08:00
|
|
|
ses->eh_eflags = scmd->eh_eflags;
|
2006-07-09 02:42:15 +08:00
|
|
|
|
2008-07-17 16:28:31 +08:00
|
|
|
scmd->prot_op = SCSI_PROT_NORMAL;
|
2014-04-11 04:36:11 +08:00
|
|
|
scmd->eh_eflags = 0;
|
2022-02-25 01:55:47 +08:00
|
|
|
memcpy(ses->cmnd, scmd->cmnd, sizeof(ses->cmnd));
|
|
|
|
memset(scmd->cmnd, 0, sizeof(scmd->cmnd));
|
2007-12-13 19:47:40 +08:00
|
|
|
memset(&scmd->sdb, 0, sizeof(scmd->sdb));
|
2014-03-29 01:51:15 +08:00
|
|
|
scmd->result = 0;
|
2022-02-25 01:55:49 +08:00
|
|
|
scmd->resid_len = 0;
|
2007-12-13 19:47:40 +08:00
|
|
|
|
2007-10-08 22:35:19 +08:00
|
|
|
if (sense_bytes) {
|
2007-12-13 19:47:40 +08:00
|
|
|
scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE,
|
|
|
|
sense_bytes);
|
2007-10-08 22:36:45 +08:00
|
|
|
sg_init_one(&ses->sense_sgl, scmd->sense_buffer,
|
2007-12-13 19:47:40 +08:00
|
|
|
scmd->sdb.length);
|
|
|
|
scmd->sdb.table.sgl = &ses->sense_sgl;
|
2007-10-08 22:35:19 +08:00
|
|
|
scmd->sc_data_direction = DMA_FROM_DEVICE;
|
2015-07-16 23:40:41 +08:00
|
|
|
scmd->sdb.table.nents = scmd->sdb.table.orig_nents = 1;
|
2007-10-08 22:35:19 +08:00
|
|
|
scmd->cmnd[0] = REQUEST_SENSE;
|
2007-12-13 19:47:40 +08:00
|
|
|
scmd->cmnd[4] = scmd->sdb.length;
|
2007-10-08 22:35:19 +08:00
|
|
|
scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
|
2006-07-09 02:42:15 +08:00
|
|
|
} else {
|
|
|
|
scmd->sc_data_direction = DMA_NONE;
|
2007-10-08 22:35:19 +08:00
|
|
|
if (cmnd) {
|
2022-02-25 01:55:47 +08:00
|
|
|
BUG_ON(cmnd_size > sizeof(scmd->cmnd));
|
2007-10-08 22:35:19 +08:00
|
|
|
memcpy(scmd->cmnd, cmnd, cmnd_size);
|
|
|
|
scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
|
|
|
|
}
|
2006-07-09 02:42:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
scmd->underflow = 0;
|
|
|
|
|
2007-10-08 22:35:19 +08:00
|
|
|
if (sdev->scsi_level <= SCSI_2 && sdev->scsi_level != SCSI_UNKNOWN)
|
2005-04-17 06:20:36 +08:00
|
|
|
scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) |
|
2005-04-18 04:00:23 +08:00
|
|
|
(sdev->lun << 5 & 0xe0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-09 02:42:15 +08:00
|
|
|
/*
|
|
|
|
* Zero the sense buffer. The scsi spec mandates that any
|
|
|
|
* untransferred sense data should be interpreted as being zero.
|
|
|
|
*/
|
2008-01-13 14:46:13 +08:00
|
|
|
memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
|
2007-10-08 22:36:45 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_eh_prep_cmnd);
|
|
|
|
|
|
|
|
/**
|
2012-04-08 21:17:09 +08:00
|
|
|
* scsi_eh_restore_cmnd - Restore a scsi command info as part of error recovery
|
2007-10-08 22:36:45 +08:00
|
|
|
* @scmd: SCSI command structure to restore
|
2009-04-28 02:54:22 +08:00
|
|
|
* @ses: saved information from a coresponding call to scsi_eh_prep_cmnd
|
2007-10-08 22:36:45 +08:00
|
|
|
*
|
2009-04-28 02:54:22 +08:00
|
|
|
* Undo any damage done by above scsi_eh_prep_cmnd().
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2007-10-08 22:36:45 +08:00
|
|
|
void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct scsi_eh_save *ses)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Restore original data
|
|
|
|
*/
|
|
|
|
scmd->cmd_len = ses->cmd_len;
|
2022-02-25 01:55:47 +08:00
|
|
|
memcpy(scmd->cmnd, ses->cmnd, sizeof(ses->cmnd));
|
2007-10-08 22:36:45 +08:00
|
|
|
scmd->sc_data_direction = ses->data_direction;
|
2007-12-13 19:47:40 +08:00
|
|
|
scmd->sdb = ses->sdb;
|
2007-10-08 22:36:45 +08:00
|
|
|
scmd->result = ses->result;
|
2022-02-25 01:55:49 +08:00
|
|
|
scmd->resid_len = ses->resid_len;
|
2008-07-21 22:25:52 +08:00
|
|
|
scmd->underflow = ses->underflow;
|
2008-07-17 16:28:31 +08:00
|
|
|
scmd->prot_op = ses->prot_op;
|
2017-04-06 21:36:33 +08:00
|
|
|
scmd->eh_eflags = ses->eh_eflags;
|
2007-10-08 22:36:45 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_eh_restore_cmnd);
|
2006-07-09 02:42:15 +08:00
|
|
|
|
2007-10-08 22:36:45 +08:00
|
|
|
/**
|
2012-04-08 21:17:09 +08:00
|
|
|
* scsi_send_eh_cmnd - submit a scsi command as part of error recovery
|
2007-10-08 22:36:45 +08: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 07:42:30 +08:00
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
static enum scsi_disposition scsi_send_eh_cmnd(struct scsi_cmnd *scmd,
|
|
|
|
unsigned char *cmnd, int cmnd_size, int timeout, unsigned sense_bytes)
|
2007-10-08 22:36:45 +08:00
|
|
|
{
|
|
|
|
struct scsi_device *sdev = scmd->device;
|
|
|
|
struct Scsi_Host *shost = sdev->host;
|
|
|
|
DECLARE_COMPLETION_ONSTACK(done);
|
2019-06-17 23:18:19 +08:00
|
|
|
unsigned long timeleft = timeout, delay;
|
2007-10-08 22:36:45 +08:00
|
|
|
struct scsi_eh_save ses;
|
2013-04-25 14:10:00 +08:00
|
|
|
const unsigned long stall_for = msecs_to_jiffies(100);
|
2007-10-08 22:36:45 +08:00
|
|
|
int rtn;
|
|
|
|
|
2013-04-25 14:10:00 +08:00
|
|
|
retry:
|
2007-10-08 22:36:45 +08:00
|
|
|
scsi_eh_prep_cmnd(scmd, &ses, cmnd, cmnd_size, sense_bytes);
|
2005-11-01 01:49:52 +08:00
|
|
|
shost->eh_action = &done;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
scsi_log_send(scmd);
|
2021-10-08 04:27:56 +08:00
|
|
|
scmd->submitter = SUBMITTED_BY_SCSI_ERROR_HANDLER;
|
2023-12-15 20:10:08 +08:00
|
|
|
scmd->flags |= SCMD_LAST;
|
2019-06-17 23:18:19 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock sdev->state_mutex to avoid that scsi_device_quiesce() can
|
|
|
|
* change the SCSI device state after we have examined it and before
|
|
|
|
* .queuecommand() is called.
|
|
|
|
*/
|
|
|
|
mutex_lock(&sdev->state_mutex);
|
|
|
|
while (sdev->sdev_state == SDEV_BLOCK && timeleft > 0) {
|
|
|
|
mutex_unlock(&sdev->state_mutex);
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(5, sdev_printk(KERN_DEBUG, sdev,
|
|
|
|
"%s: state %d <> %d\n", __func__, sdev->sdev_state,
|
|
|
|
SDEV_BLOCK));
|
|
|
|
delay = min(timeleft, stall_for);
|
|
|
|
timeleft -= delay;
|
|
|
|
msleep(jiffies_to_msecs(delay));
|
|
|
|
mutex_lock(&sdev->state_mutex);
|
|
|
|
}
|
|
|
|
if (sdev->sdev_state != SDEV_BLOCK)
|
|
|
|
rtn = shost->hostt->queuecommand(shost, scmd);
|
|
|
|
else
|
2021-04-16 06:08:10 +08:00
|
|
|
rtn = FAILED;
|
2019-06-17 23:18:19 +08:00
|
|
|
mutex_unlock(&sdev->state_mutex);
|
|
|
|
|
2013-04-25 14:10:00 +08:00
|
|
|
if (rtn) {
|
|
|
|
if (timeleft > stall_for) {
|
|
|
|
scsi_eh_restore_cmnd(scmd, &ses);
|
2021-10-08 04:27:56 +08:00
|
|
|
|
2013-04-25 14:10:00 +08:00
|
|
|
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 23:44:49 +08:00
|
|
|
rtn = FAILED;
|
2013-04-25 14:10:00 +08:00
|
|
|
} else {
|
|
|
|
timeleft = wait_for_completion_timeout(&done, timeout);
|
2014-05-08 14:09:56 +08:00
|
|
|
rtn = SUCCESS;
|
2013-04-25 14:10:00 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-04-18 04:00:23 +08:00
|
|
|
shost->eh_action = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-25 14:10:00 +08:00
|
|
|
scsi_log_completion(scmd, rtn);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
2015-01-08 14:43:50 +08:00
|
|
|
"%s timeleft: %ld\n",
|
|
|
|
__func__, timeleft));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2013-04-25 14:10:00 +08: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 06:20:36 +08:00
|
|
|
*/
|
2005-11-01 01:49:52 +08:00
|
|
|
if (timeleft) {
|
2005-04-17 06:20:36 +08:00
|
|
|
rtn = scsi_eh_completed_normally(scmd);
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: scsi_eh_completed_normally %x\n", __func__, rtn));
|
2005-11-01 01:49:52 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (rtn) {
|
|
|
|
case SUCCESS:
|
|
|
|
case NEEDS_RETRY:
|
|
|
|
case FAILED:
|
|
|
|
break;
|
2009-09-17 23:00:26 +08:00
|
|
|
case ADD_TO_MLQUEUE:
|
|
|
|
rtn = NEEDS_RETRY;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
|
|
|
rtn = FAILED;
|
|
|
|
break;
|
|
|
|
}
|
2014-11-21 23:44:49 +08:00
|
|
|
} else if (rtn != FAILED) {
|
2007-01-31 07:51:17 +08:00
|
|
|
scsi_abort_eh_cmnd(scmd);
|
2005-11-01 01:49:52 +08:00
|
|
|
rtn = FAILED;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-10-08 22:36:45 +08:00
|
|
|
scsi_eh_restore_cmnd(scmd, &ses);
|
2012-02-10 02:48:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08: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 07:42:30 +08:00
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
static enum scsi_disposition scsi_request_sense(struct scsi_cmnd *scmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-05-10 22:36:04 +08:00
|
|
|
return scsi_send_eh_cmnd(scmd, NULL, 0, scmd->device->eh_timeout, ~0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2021-04-16 06:08:11 +08:00
|
|
|
static enum scsi_disposition
|
|
|
|
scsi_eh_action(struct scsi_cmnd *scmd, enum scsi_disposition rtn)
|
2013-11-11 20:44:53 +08:00
|
|
|
{
|
2021-08-10 07:03:05 +08:00
|
|
|
if (!blk_rq_is_passthrough(scsi_cmd_to_rq(scmd))) {
|
2013-11-11 20:44:53 +08: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 06:20:36 +08: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 02:30:39 +08:00
|
|
|
* and that would disturb what we are doing. Thus we really want to
|
2005-04-17 06:20:36 +08: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 07:42:30 +08:00
|
|
|
*/
|
2006-01-23 12:09:36 +08:00
|
|
|
void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
list_move_tail(&scmd->eh_entry, done_q);
|
|
|
|
}
|
2006-01-23 12:09:36 +08:00
|
|
|
EXPORT_SYMBOL(scsi_eh_finish_cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_get_sense - Get device sense data.
|
|
|
|
* @work_q: Queue of commands to process.
|
2007-11-04 02:30:39 +08:00
|
|
|
* @done_q: Queue of processed commands.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* See if we need to request sense information. if so, then get it
|
2011-03-22 03:47:31 +08:00
|
|
|
* now, so we have a better idea of what to do.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* This has the unfortunate side effect that if a shost adapter does
|
2007-11-04 02:30:39 +08:00
|
|
|
* not automatically request sense information, we end up shutting
|
2005-04-17 06:20:36 +08: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 07:42:30 +08:00
|
|
|
*/
|
2007-01-27 06:08:49 +08:00
|
|
|
int scsi_eh_get_sense(struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-19 19:43:56 +08:00
|
|
|
struct scsi_cmnd *scmd, *next;
|
2013-10-23 16:51:21 +08:00
|
|
|
struct Scsi_Host *shost;
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-07-31 17:52:10 +08:00
|
|
|
/*
|
|
|
|
* If SCSI_EH_ABORT_SCHEDULED has been set, it is timeout IO,
|
|
|
|
* should not get sense.
|
|
|
|
*/
|
2005-06-19 19:43:56 +08:00
|
|
|
list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
|
2017-04-06 21:36:35 +08:00
|
|
|
if ((scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) ||
|
2005-04-17 06:20:36 +08:00
|
|
|
SCSI_SENSE_VALID(scmd))
|
|
|
|
continue;
|
|
|
|
|
2013-10-23 16:51:21 +08:00
|
|
|
shost = scmd->device->host;
|
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 20:27:02 +08:00
|
|
|
scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: skip request sense, past eh deadline\n",
|
|
|
|
current->comm));
|
2013-10-23 16:51:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-04-27 16:30:14 +08:00
|
|
|
if (!scsi_status_is_check_condition(scmd->result))
|
2014-03-29 01:50:17 +08:00
|
|
|
/*
|
|
|
|
* 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 06:04:06 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(2, scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: requesting sense\n",
|
|
|
|
current->comm));
|
2005-04-17 06:20:36 +08:00
|
|
|
rtn = scsi_request_sense(scmd);
|
|
|
|
if (rtn != SUCCESS)
|
|
|
|
continue;
|
|
|
|
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
2015-01-08 14:43:50 +08:00
|
|
|
"sense requested, result %x\n", scmd->result));
|
2014-10-24 20:26:45 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense(scmd));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rtn = scsi_decide_disposition(scmd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the result was normal, then just pass it along to the
|
|
|
|
* upper level.
|
|
|
|
*/
|
|
|
|
if (rtn == SUCCESS)
|
2020-10-01 23:35:53 +08:00
|
|
|
/*
|
|
|
|
* 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. If the user
|
|
|
|
* has requested infinite retries, we also want to
|
|
|
|
* finish this command, so force completion by setting
|
|
|
|
* retries and allowed to the same value.
|
|
|
|
*/
|
|
|
|
if (scmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT)
|
|
|
|
scmd->retries = scmd->allowed = 1;
|
|
|
|
else
|
|
|
|
scmd->retries = scmd->allowed;
|
2005-04-17 06:20:36 +08:00
|
|
|
else if (rtn != NEEDS_RETRY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
2007-01-27 06:08:49 +08:00
|
|
|
EXPORT_SYMBOL_GPL(scsi_eh_get_sense);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_tur - Send TUR to device.
|
2007-11-04 02:30:39 +08:00
|
|
|
* @scmd: &scsi_cmnd to send TUR
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 - Device is ready. 1 - Device NOT ready.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int scsi_eh_tur(struct scsi_cmnd *scmd)
|
|
|
|
{
|
|
|
|
static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0};
|
2021-04-16 06:08:11 +08:00
|
|
|
int retry_cnt = 1;
|
|
|
|
enum scsi_disposition rtn;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
retry_tur:
|
2013-05-10 22:36:04 +08:00
|
|
|
rtn = scsi_send_eh_cmnd(scmd, tur_command, 6,
|
|
|
|
scmd->device->eh_timeout, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
|
2015-01-08 14:43:50 +08:00
|
|
|
"%s return: %x\n", __func__, rtn));
|
2006-07-09 02:42:15 +08:00
|
|
|
|
|
|
|
switch (rtn) {
|
|
|
|
case NEEDS_RETRY:
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retry_cnt--)
|
|
|
|
goto retry_tur;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2006-07-09 02:42:15 +08:00
|
|
|
case SUCCESS:
|
2005-03-31 04:05:45 +08:00
|
|
|
return 0;
|
2006-07-09 02:42:15 +08:00
|
|
|
default:
|
|
|
|
return 1;
|
2005-03-31 04:05:45 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-05-20 02:41:12 +08:00
|
|
|
/**
|
|
|
|
* scsi_eh_test_devices - check if devices are responding from error recovery.
|
|
|
|
* @cmd_list: scsi commands in error recovery.
|
2014-08-17 05:15:11 +08: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 02:41:12 +08: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 16:51:21 +08: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 20:27:02 +08:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: skip test device, past eh deadline",
|
|
|
|
current->comm));
|
2013-10-23 16:51:21 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-20 02:41:12 +08: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 20:44:53 +08:00
|
|
|
if (finish_cmds &&
|
|
|
|
(try_stu ||
|
|
|
|
scsi_eh_action(scmd, SUCCESS) == SUCCESS))
|
2011-05-20 02:41:12 +08: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 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* scsi_eh_try_stu - Send START_UNIT to device.
|
2007-11-04 02:30:39 +08:00
|
|
|
* @scmd: &scsi_cmnd to send START_UNIT
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 - Device is ready. 1 - Device NOT ready.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08: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 02:42:15 +08:00
|
|
|
if (scmd->device->allow_restart) {
|
2021-04-16 06:08:11 +08:00
|
|
|
int i;
|
|
|
|
enum scsi_disposition rtn = NEEDS_RETRY;
|
2007-03-30 04:25:52 +08:00
|
|
|
|
|
|
|
for (i = 0; rtn == NEEDS_RETRY && i < 2; i++)
|
2021-11-10 09:23:32 +08:00
|
|
|
rtn = scsi_send_eh_cmnd(scmd, stu_command, 6,
|
|
|
|
scmd->device->eh_timeout, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-09 02:42:15 +08:00
|
|
|
if (rtn == SUCCESS)
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_stu - send START_UNIT if needed
|
2007-11-04 02:30:39 +08:00
|
|
|
* @shost: &scsi host being recovered.
|
2014-08-17 05:15:11 +08:00
|
|
|
* @work_q: &list_head for pending commands.
|
2007-11-04 02:30:39 +08:00
|
|
|
* @done_q: &list_head for processed commands.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* If commands are failing due to not ready, initializing command required,
|
2011-03-22 03:47:31 +08:00
|
|
|
* try revalidating the device, which will end up sending a start unit.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int scsi_eh_stu(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2005-06-19 19:43:56 +08:00
|
|
|
struct scsi_cmnd *scmd, *stu_scmd, *next;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct scsi_device *sdev;
|
|
|
|
|
|
|
|
shost_for_each_device(sdev, shost) {
|
2013-10-23 16:51:21 +08:00
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 20:27:02 +08:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: skip START_UNIT, past eh deadline\n",
|
|
|
|
current->comm));
|
2020-05-18 15:44:20 +08:00
|
|
|
scsi_device_put(sdev);
|
2013-10-23 16:51:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2005-04-17 06:20:36 +08: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 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 20:27:02 +08:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: Sending START_UNIT\n",
|
|
|
|
current->comm));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!scsi_eh_try_stu(stu_scmd)) {
|
|
|
|
if (!scsi_device_online(sdev) ||
|
|
|
|
!scsi_eh_tur(stu_scmd)) {
|
2005-06-19 19:43:56 +08:00
|
|
|
list_for_each_entry_safe(scmd, next,
|
|
|
|
work_q, eh_entry) {
|
2013-11-11 20:44:53 +08:00
|
|
|
if (scmd->device == sdev &&
|
|
|
|
scsi_eh_action(scmd, SUCCESS) == SUCCESS)
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 20:27:02 +08:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: START_UNIT failed\n",
|
|
|
|
current->comm));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_bus_device_reset - send bdr if needed
|
|
|
|
* @shost: scsi host being recovered.
|
2014-08-17 05:15:11 +08:00
|
|
|
* @work_q: &list_head for pending commands.
|
2007-11-04 02:30:39 +08:00
|
|
|
* @done_q: &list_head for processed commands.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Notes:
|
2007-11-04 02:30:39 +08:00
|
|
|
* Try a bus device reset. Still, look to see whether we have multiple
|
2005-04-17 06:20:36 +08: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 03:47:31 +08:00
|
|
|
* a bus_reset instead.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08: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 19:43:56 +08:00
|
|
|
struct scsi_cmnd *scmd, *bdr_scmd, *next;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct scsi_device *sdev;
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
shost_for_each_device(sdev, shost) {
|
2013-10-23 16:51:21 +08:00
|
|
|
if (scsi_host_eh_past_deadline(shost)) {
|
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 20:27:02 +08:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: skip BDR, past eh deadline\n",
|
|
|
|
current->comm));
|
2020-05-18 15:44:20 +08:00
|
|
|
scsi_device_put(sdev);
|
2013-10-23 16:51:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2005-04-17 06:20:36 +08: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 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 20:27:02 +08:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: Sending BDR\n", current->comm));
|
2005-04-17 06:20:36 +08:00
|
|
|
rtn = scsi_try_bus_device_reset(bdr_scmd);
|
2010-03-24 23:50:30 +08:00
|
|
|
if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!scsi_device_online(sdev) ||
|
2010-03-24 23:50:30 +08:00
|
|
|
rtn == FAST_IO_FAIL ||
|
2005-04-17 06:20:36 +08:00
|
|
|
!scsi_eh_tur(bdr_scmd)) {
|
2005-06-19 19:43:56 +08:00
|
|
|
list_for_each_entry_safe(scmd, next,
|
|
|
|
work_q, eh_entry) {
|
2013-11-11 20:44:53 +08:00
|
|
|
if (scmd->device == sdev &&
|
|
|
|
scsi_eh_action(scmd, rtn) != FAILED)
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_eh_finish_cmd(scmd,
|
|
|
|
done_q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-10-24 20:27:02 +08:00
|
|
|
sdev_printk(KERN_INFO, sdev,
|
|
|
|
"%s: BDR failed\n", current->comm));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
|
|
|
|
2008-03-01 08:25:19 +08:00
|
|
|
/**
|
|
|
|
* scsi_eh_target_reset - send target reset if needed
|
|
|
|
* @shost: scsi host being recovered.
|
2014-08-17 05:15:11 +08:00
|
|
|
* @work_q: &list_head for pending commands.
|
2008-03-01 08:25:19 +08: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 04:53:41 +08:00
|
|
|
LIST_HEAD(tmp_list);
|
2011-05-20 02:41:12 +08:00
|
|
|
LIST_HEAD(check_list);
|
2008-03-01 08:25:19 +08:00
|
|
|
|
2010-10-26 04:53:41 +08:00
|
|
|
list_splice_init(work_q, &tmp_list);
|
|
|
|
|
|
|
|
while (!list_empty(&tmp_list)) {
|
|
|
|
struct scsi_cmnd *next, *scmd;
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2010-10-26 04:53:41 +08:00
|
|
|
unsigned int id;
|
2013-10-23 16:51:21 +08: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 20:27:02 +08:00
|
|
|
"%s: Skip target reset, past eh deadline\n",
|
|
|
|
current->comm));
|
2013-10-23 16:51:21 +08:00
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
2010-10-26 04:53:41 +08:00
|
|
|
|
|
|
|
scmd = list_entry(tmp_list.next, struct scsi_cmnd, eh_entry);
|
|
|
|
id = scmd_id(scmd);
|
2008-03-01 08:25:19 +08:00
|
|
|
|
2014-06-25 22:39:59 +08: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 04:53:41 +08:00
|
|
|
rtn = scsi_try_target_reset(scmd);
|
|
|
|
if (rtn != SUCCESS && rtn != FAST_IO_FAIL)
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: Target reset failed"
|
|
|
|
" target: %d\n",
|
|
|
|
current->comm, id));
|
2010-10-26 04:53:41 +08:00
|
|
|
list_for_each_entry_safe(scmd, next, &tmp_list, eh_entry) {
|
|
|
|
if (scmd_id(scmd) != id)
|
|
|
|
continue;
|
|
|
|
|
2011-05-20 02:41:12 +08:00
|
|
|
if (rtn == SUCCESS)
|
|
|
|
list_move_tail(&scmd->eh_entry, &check_list);
|
|
|
|
else if (rtn == FAST_IO_FAIL)
|
2010-10-26 04:53:41 +08: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 08:25:19 +08:00
|
|
|
|
2011-05-20 02:41:12 +08:00
|
|
|
return scsi_eh_test_devices(&check_list, work_q, done_q, 0);
|
2008-03-01 08:25:19 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
2011-03-22 03:47:31 +08:00
|
|
|
* scsi_eh_bus_reset - send a bus reset
|
2007-11-04 02:30:39 +08:00
|
|
|
* @shost: &scsi host being recovered.
|
2014-08-17 05:15:11 +08:00
|
|
|
* @work_q: &list_head for pending commands.
|
2007-11-04 02:30:39 +08:00
|
|
|
* @done_q: &list_head for processed commands.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int scsi_eh_bus_reset(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2005-06-19 19:43:56 +08:00
|
|
|
struct scsi_cmnd *scmd, *chan_scmd, *next;
|
2011-05-20 02:41:12 +08:00
|
|
|
LIST_HEAD(check_list);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int channel;
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 03:47:31 +08:00
|
|
|
* the reset.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
for (channel = 0; channel <= shost->max_channel; channel++) {
|
2013-10-23 16:51:21 +08: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 20:27:02 +08:00
|
|
|
"%s: skip BRST, past eh deadline\n",
|
|
|
|
current->comm));
|
2013-10-23 16:51:21 +08:00
|
|
|
return list_empty(work_q);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
chan_scmd = NULL;
|
|
|
|
list_for_each_entry(scmd, work_q, eh_entry) {
|
2005-10-25 06:05:09 +08:00
|
|
|
if (channel == scmd_channel(scmd)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
chan_scmd = scmd;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* FIXME add back in some support for
|
|
|
|
* soft_reset devices.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!chan_scmd)
|
|
|
|
continue;
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: Sending BRST chan: %d\n",
|
|
|
|
current->comm, channel));
|
2005-04-17 06:20:36 +08:00
|
|
|
rtn = scsi_try_bus_reset(chan_scmd);
|
2010-03-24 23:50:30 +08:00
|
|
|
if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
|
2005-06-19 19:43:56 +08:00
|
|
|
list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
|
2011-05-20 02:41:12 +08:00
|
|
|
if (channel == scmd_channel(scmd)) {
|
|
|
|
if (rtn == FAST_IO_FAIL)
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_eh_finish_cmd(scmd,
|
|
|
|
done_q);
|
2011-05-20 02:41:12 +08:00
|
|
|
else
|
|
|
|
list_move_tail(&scmd->eh_entry,
|
|
|
|
&check_list);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else {
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: BRST failed chan: %d\n",
|
|
|
|
current->comm, channel));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2011-05-20 02:41:12 +08:00
|
|
|
return scsi_eh_test_devices(&check_list, work_q, done_q, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-03-22 03:47:31 +08:00
|
|
|
* scsi_eh_host_reset - send a host reset
|
2014-08-17 05:15:11 +08:00
|
|
|
* @shost: host to be reset.
|
|
|
|
* @work_q: &list_head for pending commands.
|
|
|
|
* @done_q: &list_head for processed commands.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2014-06-25 22:39:59 +08:00
|
|
|
static int scsi_eh_host_reset(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2005-06-19 19:43:56 +08:00
|
|
|
struct scsi_cmnd *scmd, *next;
|
2011-05-20 02:41:12 +08:00
|
|
|
LIST_HEAD(check_list);
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!list_empty(work_q)) {
|
|
|
|
scmd = list_entry(work_q->next,
|
|
|
|
struct scsi_cmnd, eh_entry);
|
|
|
|
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: Sending HRST\n",
|
|
|
|
current->comm));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rtn = scsi_try_host_reset(scmd);
|
2011-05-20 02:41:12 +08:00
|
|
|
if (rtn == SUCCESS) {
|
|
|
|
list_splice_init(work_q, &check_list);
|
|
|
|
} else if (rtn == FAST_IO_FAIL) {
|
2005-06-19 19:43:56 +08:00
|
|
|
list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
}
|
|
|
|
} else {
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"%s: HRST failed\n",
|
|
|
|
current->comm));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2011-05-20 02:41:12 +08:00
|
|
|
return scsi_eh_test_devices(&check_list, work_q, done_q, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_offline_sdevs - offline scsi devices that fail to recover
|
2014-08-17 05:15:11 +08:00
|
|
|
* @work_q: &list_head for pending commands.
|
|
|
|
* @done_q: &list_head for processed commands.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static void scsi_eh_offline_sdevs(struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
|
|
|
{
|
2005-06-19 19:43:56 +08:00
|
|
|
struct scsi_cmnd *scmd, *next;
|
2017-06-03 05:21:55 +08:00
|
|
|
struct scsi_device *sdev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-19 19:43:56 +08:00
|
|
|
list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
|
2007-08-18 01:02:10 +08:00
|
|
|
sdev_printk(KERN_INFO, scmd->device, "Device offlined - "
|
|
|
|
"not ready after error recovery\n");
|
2017-06-03 05:21:55 +08:00
|
|
|
sdev = scmd->device;
|
|
|
|
|
|
|
|
mutex_lock(&sdev->state_mutex);
|
|
|
|
scsi_device_set_state(sdev, SDEV_OFFLINE);
|
|
|
|
mutex_unlock(&sdev->state_mutex);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_eh_finish_cmd(scmd, done_q);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-08-20 07:45:31 +08:00
|
|
|
/**
|
2013-11-11 20:44:54 +08:00
|
|
|
* scsi_noretry_cmd - determine if command should be failed fast
|
2008-08-20 07:45:31 +08:00
|
|
|
* @scmd: SCSI cmd to examine.
|
|
|
|
*/
|
2022-07-15 02:07:06 +08:00
|
|
|
bool scsi_noretry_cmd(struct scsi_cmnd *scmd)
|
2008-08-20 07:45:31 +08:00
|
|
|
{
|
2021-08-10 07:03:05 +08:00
|
|
|
struct request *req = scsi_cmd_to_rq(scmd);
|
|
|
|
|
2008-08-20 07:45:31 +08:00
|
|
|
switch (host_byte(scmd->result)) {
|
|
|
|
case DID_OK:
|
|
|
|
break;
|
2013-11-11 20:44:54 +08:00
|
|
|
case DID_TIME_OUT:
|
|
|
|
goto check_type;
|
2008-08-20 07:45:31 +08:00
|
|
|
case DID_BUS_BUSY:
|
2022-07-15 02:07:06 +08:00
|
|
|
return !!(req->cmd_flags & REQ_FAILFAST_TRANSPORT);
|
2008-08-20 07:45:31 +08:00
|
|
|
case DID_PARITY:
|
2022-07-15 02:07:06 +08:00
|
|
|
return !!(req->cmd_flags & REQ_FAILFAST_DEV);
|
2008-08-20 07:45:31 +08:00
|
|
|
case DID_ERROR:
|
2021-04-27 16:30:46 +08:00
|
|
|
if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT)
|
2022-07-15 02:07:06 +08:00
|
|
|
return false;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2008-08-20 07:45:31 +08:00
|
|
|
case DID_SOFT_ERROR:
|
2022-07-15 02:07:06 +08:00
|
|
|
return !!(req->cmd_flags & REQ_FAILFAST_DRIVER);
|
2008-08-20 07:45:31 +08:00
|
|
|
}
|
|
|
|
|
scsi: sd: Handle read/write CDL timeout failures
Commands using a duration limit descriptor that has limit policies set to a
value other than 0x0 may be failed by the device if one of the limits are
exceeded. For such commands, since the failure is the result of the user
duration limit configuration and workload, the commands should not be
retried and terminated immediately. Furthermore, to allow the user to
differentiate these "soft" failures from hard errors due to hardware
problem, a different error code than EIO should be returned.
There are 2 cases to consider:
(1) The failure is due to a limit policy failing the command with a check
condition sense key, that is, any limit policy other than 0xD. For this
case, scsi_check_sense() is modified to detect failures with the ABORTED
COMMAND sense key and the COMMAND TIMEOUT BEFORE PROCESSING or COMMAND
TIMEOUT DURING PROCESSING or COMMAND TIMEOUT DURING PROCESSING DUE TO ERROR
RECOVERY additional sense code. For these failures, a SUCCESS disposition
is returned so that scsi_finish_command() is called to terminate the
command.
(2) The failure is due to a limit policy set to 0xD, which result in the
command being terminated with a GOOD status, COMPLETED sense key, and DATA
CURRENTLY UNAVAILABLE additional sense code. To handle this case, the
scsi_check_sense() is modified to return a SUCCESS disposition so that
scsi_finish_command() is called to terminate the command. In addition,
scsi_decide_disposition() has to be modified to see if a command being
terminated with GOOD status has sense data. This is as defined in SCSI
Primary Commands - 6 (SPC-6), so all according to spec, even if GOOD status
commands were not checked before.
If scsi_check_sense() detects sense data representing a duration limit,
scsi_check_sense() will set the newly introduced SCSI ML byte
SCSIML_STAT_DL_TIMEOUT. This SCSI ML byte is checked in scsi_noretry_cmd(),
so that a command that failed because of a CDL timeout cannot be
retried. The SCSI ML byte is also checked in scsi_result_to_blk_status() to
complete the command request with the BLK_STS_DURATION_LIMIT status, which
result in the user seeing ETIME errors for the failed commands.
Co-developed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20230511011356.227789-12-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2023-05-11 09:13:44 +08:00
|
|
|
/* Never retry commands aborted due to a duration limit timeout */
|
|
|
|
if (scsi_ml_byte(scmd->result) == SCSIML_STAT_DL_TIMEOUT)
|
|
|
|
return true;
|
|
|
|
|
2021-04-27 16:30:14 +08:00
|
|
|
if (!scsi_status_is_check_condition(scmd->result))
|
2022-07-15 02:07:06 +08:00
|
|
|
return false;
|
2008-08-20 07:45:31 +08:00
|
|
|
|
2013-11-11 20:44:54 +08:00
|
|
|
check_type:
|
|
|
|
/*
|
|
|
|
* assume caller has checked sense and determined
|
|
|
|
* the check condition was retryable.
|
|
|
|
*/
|
2021-08-10 07:03:05 +08:00
|
|
|
if (req->cmd_flags & REQ_FAILFAST_DEV || blk_rq_is_passthrough(req))
|
2022-07-15 02:07:06 +08:00
|
|
|
return true;
|
2020-09-10 15:48:41 +08:00
|
|
|
|
2022-07-15 02:07:06 +08:00
|
|
|
return false;
|
2008-08-20 07:45:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08: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 07:42:30 +08:00
|
|
|
*/
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *scmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2021-04-16 06:08:11 +08:00
|
|
|
enum scsi_disposition rtn;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(5, scmd_printk(KERN_INFO, scmd,
|
|
|
|
"%s: device offline - report as SUCCESS\n", __func__));
|
2005-04-17 06:20:36 +08: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 20:44:54 +08:00
|
|
|
case DID_ABORT:
|
|
|
|
if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) {
|
2014-06-04 19:34:57 +08:00
|
|
|
set_host_byte(scmd, DID_TIME_OUT);
|
2013-11-11 20:44:54 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2005-04-17 06:20:36 +08: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 05:38:10 +08:00
|
|
|
case DID_SOFT_ERROR:
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* when the low level driver returns did_soft_error,
|
2011-03-22 03:47:31 +08:00
|
|
|
* it is responsible for keeping an internal retry counter
|
2005-04-17 06:20:36 +08:00
|
|
|
* in order to avoid endless loops (db)
|
|
|
|
*/
|
|
|
|
goto maybe_retry;
|
|
|
|
case DID_IMM_RETRY:
|
|
|
|
return NEEDS_RETRY;
|
|
|
|
|
2005-04-13 06:49:09 +08: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 07:45:25 +08: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 09:47:19 +08: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 07:45:25 +08:00
|
|
|
*/
|
2008-11-05 09:47:19 +08: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 07:45:25 +08: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;
|
2021-01-07 05:49:04 +08:00
|
|
|
case DID_TRANSPORT_MARGINAL:
|
|
|
|
/*
|
|
|
|
* caller has decided not to do retries on
|
|
|
|
* abort success, so send IO directly upwards
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
2005-04-17 06:20:36 +08:00
|
|
|
case DID_ERROR:
|
2021-04-27 16:30:46 +08:00
|
|
|
if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT)
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* execute reservation conflict processing code
|
|
|
|
* lower down
|
|
|
|
*/
|
|
|
|
break;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2005-04-17 06:20:36 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check the status byte to see if this indicates anything special.
|
|
|
|
*/
|
2021-04-27 16:30:46 +08:00
|
|
|
switch (get_status_byte(scmd)) {
|
|
|
|
case SAM_STAT_TASK_SET_FULL:
|
2009-10-16 08:46:44 +08:00
|
|
|
scsi_handle_queue_full(scmd->device);
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* the case of trying to send too many commands to a
|
|
|
|
* tagged queueing device.
|
|
|
|
*/
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_BUSY:
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* 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;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_GOOD:
|
2013-08-09 03:07:48 +08:00
|
|
|
if (scmd->cmnd[0] == REPORT_LUNS)
|
|
|
|
scmd->device->sdev_target->expecting_lun_change = 0;
|
2009-10-23 06:46:33 +08:00
|
|
|
scsi_handle_queue_ramp_up(scmd->device);
|
scsi: sd: Handle read/write CDL timeout failures
Commands using a duration limit descriptor that has limit policies set to a
value other than 0x0 may be failed by the device if one of the limits are
exceeded. For such commands, since the failure is the result of the user
duration limit configuration and workload, the commands should not be
retried and terminated immediately. Furthermore, to allow the user to
differentiate these "soft" failures from hard errors due to hardware
problem, a different error code than EIO should be returned.
There are 2 cases to consider:
(1) The failure is due to a limit policy failing the command with a check
condition sense key, that is, any limit policy other than 0xD. For this
case, scsi_check_sense() is modified to detect failures with the ABORTED
COMMAND sense key and the COMMAND TIMEOUT BEFORE PROCESSING or COMMAND
TIMEOUT DURING PROCESSING or COMMAND TIMEOUT DURING PROCESSING DUE TO ERROR
RECOVERY additional sense code. For these failures, a SUCCESS disposition
is returned so that scsi_finish_command() is called to terminate the
command.
(2) The failure is due to a limit policy set to 0xD, which result in the
command being terminated with a GOOD status, COMPLETED sense key, and DATA
CURRENTLY UNAVAILABLE additional sense code. To handle this case, the
scsi_check_sense() is modified to return a SUCCESS disposition so that
scsi_finish_command() is called to terminate the command. In addition,
scsi_decide_disposition() has to be modified to see if a command being
terminated with GOOD status has sense data. This is as defined in SCSI
Primary Commands - 6 (SPC-6), so all according to spec, even if GOOD status
commands were not checked before.
If scsi_check_sense() detects sense data representing a duration limit,
scsi_check_sense() will set the newly introduced SCSI ML byte
SCSIML_STAT_DL_TIMEOUT. This SCSI ML byte is checked in scsi_noretry_cmd(),
so that a command that failed because of a CDL timeout cannot be
retried. The SCSI ML byte is also checked in scsi_result_to_blk_status() to
complete the command request with the BLK_STS_DURATION_LIMIT status, which
result in the user seeing ETIME errors for the failed commands.
Co-developed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20230511011356.227789-12-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2023-05-11 09:13:44 +08:00
|
|
|
if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd))
|
|
|
|
/*
|
|
|
|
* If we have sense data, call scsi_check_sense() in
|
|
|
|
* order to set the correct SCSI ML byte (if any).
|
|
|
|
* No point in checking the return value, since the
|
|
|
|
* command has already completed successfully.
|
|
|
|
*/
|
|
|
|
scsi_check_sense(scmd);
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_COMMAND_TERMINATED:
|
2005-04-17 06:20:36 +08:00
|
|
|
return SUCCESS;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_TASK_ABORTED:
|
2008-11-06 18:57:52 +08:00
|
|
|
goto maybe_retry;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_CHECK_CONDITION:
|
2005-04-17 06:20:36 +08:00
|
|
|
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;
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_CONDITION_MET:
|
|
|
|
case SAM_STAT_INTERMEDIATE:
|
|
|
|
case SAM_STAT_INTERMEDIATE_CONDITION_MET:
|
|
|
|
case SAM_STAT_ACA_ACTIVE:
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* who knows? FIXME(eric)
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
|
|
|
|
2021-04-27 16:30:46 +08:00
|
|
|
case SAM_STAT_RESERVATION_CONFLICT:
|
2005-10-03 00:45:08 +08:00
|
|
|
sdev_printk(KERN_INFO, scmd->device,
|
|
|
|
"reservation conflict\n");
|
2022-08-12 09:00:26 +08:00
|
|
|
set_scsi_ml_byte(scmd, SCSIML_STAT_RESV_CONFLICT);
|
2005-04-17 06:20:36 +08:00
|
|
|
return SUCCESS; /* causes immediate i/o error */
|
|
|
|
}
|
|
|
|
return FAILED;
|
|
|
|
|
2018-02-26 15:59:16 +08:00
|
|
|
maybe_retry:
|
2005-04-17 06:20:36 +08: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) */
|
2020-10-01 23:35:53 +08:00
|
|
|
if (scsi_cmd_retry_allowed(scmd) && !scsi_noretry_cmd(scmd)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
return NEEDS_RETRY;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* no more retries - report this one back to upper level.
|
|
|
|
*/
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 05:19:54 +08:00
|
|
|
static enum rq_end_io_ret eh_lock_door_done(struct request *req,
|
|
|
|
blk_status_t status)
|
2008-12-14 00:23:45 +08:00
|
|
|
{
|
2021-10-25 15:05:07 +08:00
|
|
|
blk_mq_free_request(req);
|
2022-09-22 05:19:54 +08:00
|
|
|
return RQ_END_IO_NONE;
|
2008-12-14 00:23:45 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* scsi_eh_lock_door - Prevent medium removal for the specified device
|
|
|
|
* @sdev: SCSI device to prevent medium removal
|
|
|
|
*
|
|
|
|
* Locking:
|
2009-05-17 22:30:48 +08:00
|
|
|
* We must be called from process context.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the
|
|
|
|
* head of the devices request queue, and continue.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static void scsi_eh_lock_door(struct scsi_device *sdev)
|
|
|
|
{
|
2022-02-25 01:55:47 +08:00
|
|
|
struct scsi_cmnd *scmd;
|
2008-12-14 00:23:45 +08:00
|
|
|
struct request *req;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-10-21 14:06:05 +08:00
|
|
|
req = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN, 0);
|
2014-08-28 22:15:21 +08:00
|
|
|
if (IS_ERR(req))
|
2014-07-03 03:35:16 +08:00
|
|
|
return;
|
2022-02-25 01:55:47 +08:00
|
|
|
scmd = blk_mq_rq_to_pdu(req);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2022-02-25 01:55:47 +08:00
|
|
|
scmd->cmnd[0] = ALLOW_MEDIUM_REMOVAL;
|
|
|
|
scmd->cmnd[1] = 0;
|
|
|
|
scmd->cmnd[2] = 0;
|
|
|
|
scmd->cmnd[3] = 0;
|
|
|
|
scmd->cmnd[4] = SCSI_REMOVAL_PREVENT;
|
|
|
|
scmd->cmnd[5] = 0;
|
|
|
|
scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
|
2022-05-24 20:15:30 +08:00
|
|
|
scmd->allowed = 5;
|
2008-12-14 00:23:45 +08:00
|
|
|
|
2016-10-20 21:12:13 +08:00
|
|
|
req->rq_flags |= RQF_QUIET;
|
2008-12-14 00:23:45 +08:00
|
|
|
req->timeout = 10 * HZ;
|
2022-05-24 20:15:30 +08:00
|
|
|
req->end_io = eh_lock_door_done;
|
2008-12-14 00:23:45 +08:00
|
|
|
|
2022-05-24 20:15:30 +08:00
|
|
|
blk_execute_rq_nowait(req, true);
|
2008-12-14 00:23:45 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08: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 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static void scsi_restart_operations(struct Scsi_Host *shost)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev;
|
2005-09-19 04:05:20 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08: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 02:36:40 +08:00
|
|
|
if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) {
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_eh_lock_door(sdev);
|
2014-11-04 02:36:40 +08:00
|
|
|
sdev->was_reset = 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08: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 16:51:21 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
2014-06-25 22:39:59 +08:00
|
|
|
shost_printk(KERN_INFO, shost, "waking up host to restart\n"));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-19 04:05:20 +08: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 06:20:36 +08: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 14:25:32 +08: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 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_ready_devs - check device ready state and recover if not.
|
2014-08-17 05:15:11 +08:00
|
|
|
* @shost: host to be recovered.
|
|
|
|
* @work_q: &list_head for pending commands.
|
2007-11-04 02:30:39 +08:00
|
|
|
* @done_q: &list_head for processed commands.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2007-01-27 06:08:49 +08:00
|
|
|
void scsi_eh_ready_devs(struct Scsi_Host *shost,
|
|
|
|
struct list_head *work_q,
|
|
|
|
struct list_head *done_q)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (!scsi_eh_stu(shost, work_q, done_q))
|
|
|
|
if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
|
2008-03-01 08:25:19 +08:00
|
|
|
if (!scsi_eh_target_reset(shost, work_q, done_q))
|
|
|
|
if (!scsi_eh_bus_reset(shost, work_q, done_q))
|
2014-06-25 22:39:59 +08:00
|
|
|
if (!scsi_eh_host_reset(shost, work_q, done_q))
|
2008-03-01 08:25:19 +08:00
|
|
|
scsi_eh_offline_sdevs(work_q,
|
|
|
|
done_q);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-01-27 06:08:49 +08:00
|
|
|
EXPORT_SYMBOL_GPL(scsi_eh_ready_devs);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scsi_eh_flush_done_q - finish processed commands or retry them.
|
|
|
|
* @done_q: list_head of processed commands.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2006-01-23 12:09:36 +08:00
|
|
|
void scsi_eh_flush_done_q(struct list_head *done_q)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-19 19:43:56 +08:00
|
|
|
struct scsi_cmnd *scmd, *next;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-19 19:43:56 +08:00
|
|
|
list_for_each_entry_safe(scmd, next, done_q, eh_entry) {
|
scsi: core: Kick the requeue list after inserting when flushing
When libata calls ata_link_abort() to abort all ata queued commands, it
calls blk_abort_request() on the SCSI command representing each QC.
This causes scsi_timeout() to be called, which calls scsi_eh_scmd_add() for
each SCSI command.
scsi_eh_scmd_add() sets the SCSI host to state recovery, and then adds the
command to shost->eh_cmd_q.
This will wake up the SCSI EH, and eventually the libata EH strategy
handler will be called, which calls scsi_eh_flush_done_q() to either flush
retry or flush finish each failed command.
The commands that are flush retried by scsi_eh_flush_done_q() are done so
using scsi_queue_insert().
Before commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if
necessary"), __scsi_queue_insert() called blk_mq_requeue_request() with the
second argument set to true, indicating that it should always kick/run the
requeue list after inserting.
After commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if
necessary"), __scsi_queue_insert() does not kick/run the requeue list after
inserting, if the current SCSI host state is recovery (which is the case in
the libata example above).
This optimization is probably fine in most cases, as I can only assume that
most often someone will eventually kick/run the queues.
However, that is not the case for scsi_eh_flush_done_q(), where we can see
that the request gets inserted to the requeue list, but the queue is never
started after the request has been inserted, leading to the block layer
waiting for the completion of command that never gets to run.
Since scsi_eh_flush_done_q() is called by SCSI EH context, the SCSI host
state is most likely always in recovery when this function is called.
Thus, let scsi_eh_flush_done_q() explicitly kick the requeue list after
inserting a flush retry command, so that scsi_eh_flush_done_q() keeps the
same behavior as before commit 8b566edbdbfb ("scsi: core: Only kick the
requeue list if necessary").
Simple reproducer for the libata example above:
$ hdparm -Y /dev/sda
$ echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/delete
Fixes: 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary")
Reported-by: Kevin Locke <kevin@kevinlocke.name>
Closes: https://lore.kernel.org/linux-scsi/ZZw3Th70wUUvCiCY@kevinlocke.name/
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Link: https://lore.kernel.org/r/20240111120533.3612509-1-cassel@kernel.org
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2024-01-11 20:05:32 +08:00
|
|
|
struct scsi_device *sdev = scmd->device;
|
|
|
|
|
2005-06-19 19:43:56 +08:00
|
|
|
list_del_init(&scmd->eh_entry);
|
scsi: core: Kick the requeue list after inserting when flushing
When libata calls ata_link_abort() to abort all ata queued commands, it
calls blk_abort_request() on the SCSI command representing each QC.
This causes scsi_timeout() to be called, which calls scsi_eh_scmd_add() for
each SCSI command.
scsi_eh_scmd_add() sets the SCSI host to state recovery, and then adds the
command to shost->eh_cmd_q.
This will wake up the SCSI EH, and eventually the libata EH strategy
handler will be called, which calls scsi_eh_flush_done_q() to either flush
retry or flush finish each failed command.
The commands that are flush retried by scsi_eh_flush_done_q() are done so
using scsi_queue_insert().
Before commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if
necessary"), __scsi_queue_insert() called blk_mq_requeue_request() with the
second argument set to true, indicating that it should always kick/run the
requeue list after inserting.
After commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if
necessary"), __scsi_queue_insert() does not kick/run the requeue list after
inserting, if the current SCSI host state is recovery (which is the case in
the libata example above).
This optimization is probably fine in most cases, as I can only assume that
most often someone will eventually kick/run the queues.
However, that is not the case for scsi_eh_flush_done_q(), where we can see
that the request gets inserted to the requeue list, but the queue is never
started after the request has been inserted, leading to the block layer
waiting for the completion of command that never gets to run.
Since scsi_eh_flush_done_q() is called by SCSI EH context, the SCSI host
state is most likely always in recovery when this function is called.
Thus, let scsi_eh_flush_done_q() explicitly kick the requeue list after
inserting a flush retry command, so that scsi_eh_flush_done_q() keeps the
same behavior as before commit 8b566edbdbfb ("scsi: core: Only kick the
requeue list if necessary").
Simple reproducer for the libata example above:
$ hdparm -Y /dev/sda
$ echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/delete
Fixes: 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary")
Reported-by: Kevin Locke <kevin@kevinlocke.name>
Closes: https://lore.kernel.org/linux-scsi/ZZw3Th70wUUvCiCY@kevinlocke.name/
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Link: https://lore.kernel.org/r/20240111120533.3612509-1-cassel@kernel.org
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2024-01-11 20:05:32 +08:00
|
|
|
if (scsi_device_online(sdev) && !scsi_noretry_cmd(scmd) &&
|
|
|
|
scsi_cmd_retry_allowed(scmd) &&
|
|
|
|
scsi_eh_should_retry_cmd(scmd)) {
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 14:43:50 +08:00
|
|
|
"%s: flush retry cmd\n",
|
|
|
|
current->comm));
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
|
scsi: core: Kick the requeue list after inserting when flushing
When libata calls ata_link_abort() to abort all ata queued commands, it
calls blk_abort_request() on the SCSI command representing each QC.
This causes scsi_timeout() to be called, which calls scsi_eh_scmd_add() for
each SCSI command.
scsi_eh_scmd_add() sets the SCSI host to state recovery, and then adds the
command to shost->eh_cmd_q.
This will wake up the SCSI EH, and eventually the libata EH strategy
handler will be called, which calls scsi_eh_flush_done_q() to either flush
retry or flush finish each failed command.
The commands that are flush retried by scsi_eh_flush_done_q() are done so
using scsi_queue_insert().
Before commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if
necessary"), __scsi_queue_insert() called blk_mq_requeue_request() with the
second argument set to true, indicating that it should always kick/run the
requeue list after inserting.
After commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if
necessary"), __scsi_queue_insert() does not kick/run the requeue list after
inserting, if the current SCSI host state is recovery (which is the case in
the libata example above).
This optimization is probably fine in most cases, as I can only assume that
most often someone will eventually kick/run the queues.
However, that is not the case for scsi_eh_flush_done_q(), where we can see
that the request gets inserted to the requeue list, but the queue is never
started after the request has been inserted, leading to the block layer
waiting for the completion of command that never gets to run.
Since scsi_eh_flush_done_q() is called by SCSI EH context, the SCSI host
state is most likely always in recovery when this function is called.
Thus, let scsi_eh_flush_done_q() explicitly kick the requeue list after
inserting a flush retry command, so that scsi_eh_flush_done_q() keeps the
same behavior as before commit 8b566edbdbfb ("scsi: core: Only kick the
requeue list if necessary").
Simple reproducer for the libata example above:
$ hdparm -Y /dev/sda
$ echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/delete
Fixes: 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary")
Reported-by: Kevin Locke <kevin@kevinlocke.name>
Closes: https://lore.kernel.org/linux-scsi/ZZw3Th70wUUvCiCY@kevinlocke.name/
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Link: https://lore.kernel.org/r/20240111120533.3612509-1-cassel@kernel.org
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2024-01-11 20:05:32 +08:00
|
|
|
blk_mq_kick_requeue_list(sdev->request_queue);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2005-05-17 08:42:15 +08:00
|
|
|
/*
|
|
|
|
* If just we got sense for the device (called
|
|
|
|
* scsi_eh_get_sense), scmd->result is already
|
2021-04-27 16:30:17 +08:00
|
|
|
* set, do not set DID_TIME_OUT.
|
2005-05-17 08:42:15 +08:00
|
|
|
*/
|
scsi: core: Allow libata to complete successful commands via EH
In SCSI, we get the sense data as part of the completion, for ATA however,
we need to fetch the sense data as an extra step. For an aborted ATA
command the sense data is fetched via libata's ->eh_strategy_handler().
For Command Duration Limits policy 0xD:
The device shall complete the command without error with the additional
sense code set to DATA CURRENTLY UNAVAILABLE.
In order to handle this policy in libata, we intend to send a successful
command via SCSI EH, and let libata's ->eh_strategy_handler() fetch the
sense data for the good command. This is similar to how we handle an
aborted ATA command, just that we need to read the Successful NCQ Commands
log instead of the NCQ Command Error log.
When we get a SATA completion with successful commands, ATA_SENSE will be
set, indicating that some commands in the completion have sense data.
The sense_valid bitmask in the Sense Data for Successful NCQ Commands log
will inform exactly which commands that had sense data, which might be a
subset of all the commands that was completed in the same completion. (Yet
all will have ATA_SENSE set, since the status is per completion.)
The successful commands that have e.g. a "DATA CURRENTLY UNAVAILABLE" sense
data will have a SCSI ML byte set, so scsi_eh_flush_done_q() will not set
the scmd->result to DID_TIME_OUT for these commands. However, the
successful commands that did not have sense data, must not get their result
marked as DID_TIME_OUT by SCSI EH.
Add a new flag SCMD_FORCE_EH_SUCCESS, which tells SCSI EH to not mark a
command as DID_TIME_OUT, even if it has scmd->result == SAM_STAT_GOOD.
This will be used by libata in a subsequent commit.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Link: https://lore.kernel.org/r/20230511011356.227789-5-nks@flawful.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2023-05-11 09:13:37 +08:00
|
|
|
if (!scmd->result &&
|
|
|
|
!(scmd->flags & SCMD_FORCE_EH_SUCCESS))
|
2021-04-27 16:30:17 +08:00
|
|
|
scmd->result |= (DID_TIME_OUT << 16);
|
2014-06-25 22:39:59 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(3,
|
|
|
|
scmd_printk(KERN_INFO, scmd,
|
2015-01-08 14:43:50 +08:00
|
|
|
"%s: flush finish cmd\n",
|
|
|
|
current->comm));
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_finish_command(scmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-23 12:09:36 +08:00
|
|
|
EXPORT_SYMBOL(scsi_eh_flush_done_q);
|
2005-04-17 06:20:36 +08: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 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08: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 21:36:35 +08:00
|
|
|
scsi_eh_ready_devs(shost, &eh_work_q, &eh_done_q);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-23 16:51:21 +08:00
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
2013-11-11 20:44:56 +08:00
|
|
|
if (shost->eh_deadline != -1)
|
2013-10-23 16:51:21 +08:00
|
|
|
shost->last_reset = 0;
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_eh_flush_done_q(&eh_done_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-10-29 07:01:55 +08:00
|
|
|
* scsi_error_handler - SCSI error handler thread
|
2005-04-17 06:20:36 +08:00
|
|
|
* @data: Host for which we are running.
|
|
|
|
*
|
|
|
|
* Notes:
|
2005-10-29 07:01:55 +08: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 07:42:30 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int scsi_error_handler(void *data)
|
|
|
|
{
|
2005-10-29 07:01:55 +08:00
|
|
|
struct Scsi_Host *shost = data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2005-10-29 07:01:55 +08: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 07:54:00 +08:00
|
|
|
* disables signal delivery for the created thread.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2015-08-28 02:16:37 +08: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 14:25:42 +08:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2015-08-28 02:16:37 +08:00
|
|
|
if (kthread_should_stop())
|
|
|
|
break;
|
|
|
|
|
2006-05-15 19:57:20 +08:00
|
|
|
if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) ||
|
2018-06-24 22:03:26 +08:00
|
|
|
shost->host_failed != scsi_host_busy(shost)) {
|
2005-10-29 07:01:55 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(1,
|
2014-06-25 22:39:59 +08:00
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"scsi_eh_%d: sleeping\n",
|
|
|
|
shost->host_no));
|
2005-09-19 22:50:04 +08:00
|
|
|
schedule();
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-19 22:50:04 +08:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2005-10-29 07:01:55 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(1,
|
2014-06-25 22:39:59 +08: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 22:29:29 +08:00
|
|
|
shost->host_failed,
|
2018-06-24 22:03:26 +08:00
|
|
|
scsi_host_busy(shost)));
|
2005-04-17 06:20:36 +08: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 09:20:24 +08: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 22:41:42 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(1,
|
2014-10-24 20:27:02 +08: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 22:41:42 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-04-02 01:21:04 +08:00
|
|
|
if (shost->transportt->eh_strategy_handler)
|
|
|
|
shost->transportt->eh_strategy_handler(shost);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
scsi_unjam_host(shost);
|
|
|
|
|
2016-06-07 14:53:56 +08:00
|
|
|
/* All scmds have been handled */
|
|
|
|
shost->host_failed = 0;
|
|
|
|
|
2005-04-17 06:20:36 +08: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 09:20:24 +08:00
|
|
|
if (!shost->eh_noresume)
|
|
|
|
scsi_autopm_put_host(shost);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-10-19 20:22:13 +08:00
|
|
|
__set_current_state(TASK_RUNNING);
|
|
|
|
|
2005-10-29 07:01:55 +08:00
|
|
|
SCSI_LOG_ERROR_RECOVERY(1,
|
2014-06-25 22:39:59 +08:00
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"Error handler scsi_eh_%d exiting\n",
|
|
|
|
shost->host_no));
|
2005-09-19 22:50:04 +08:00
|
|
|
shost->ehandler = NULL;
|
2005-04-17 06:20:36 +08: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 08:25:19 +08:00
|
|
|
if (channel == sdev_channel(sdev))
|
|
|
|
__scsi_report_device_reset(sdev, NULL);
|
2005-04-17 06:20:36 +08: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 06:05:09 +08:00
|
|
|
if (channel == sdev_channel(sdev) &&
|
2008-03-01 08:25:19 +08:00
|
|
|
target == sdev_id(sdev))
|
|
|
|
__scsi_report_device_reset(sdev, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_report_device_reset);
|
|
|
|
|
2014-10-11 18:06:47 +08: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 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int
|
2014-10-11 18:06:47 +08:00
|
|
|
scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
|
2005-04-17 06:20:36 +08: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 22:41:42 +08:00
|
|
|
struct scsi_cmnd *scmd;
|
2006-03-09 03:50:12 +08:00
|
|
|
struct Scsi_Host *shost = dev->host;
|
2017-01-03 02:55:26 +08:00
|
|
|
struct request *rq;
|
2006-03-09 03:50:12 +08:00
|
|
|
unsigned long flags;
|
2021-04-16 06:08:11 +08:00
|
|
|
int error = 0, val;
|
|
|
|
enum scsi_disposition rtn;
|
2014-10-11 18:06:47 +08:00
|
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
|
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
error = get_user(val, arg);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2005-04-17 06:20:36 +08: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 22:41:42 +08:00
|
|
|
if (scsi_autopm_get_host(shost) < 0)
|
2014-10-11 18:06:47 +08: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 22:41:42 +08:00
|
|
|
|
2014-10-11 18:06:47 +08:00
|
|
|
error = -EIO;
|
2017-01-03 02:55:26 +08:00
|
|
|
rq = kzalloc(sizeof(struct request) + sizeof(struct scsi_cmnd) +
|
|
|
|
shost->hostt->cmd_size, GFP_KERNEL);
|
|
|
|
if (!rq)
|
2014-05-01 22:51:05 +08:00
|
|
|
goto out_put_autopm_host;
|
2017-01-03 02:55:26 +08:00
|
|
|
blk_rq_init(NULL, rq);
|
2014-05-01 22:51:05 +08:00
|
|
|
|
2017-01-03 02:55:26 +08:00
|
|
|
scmd = (struct scsi_cmnd *)(rq + 1);
|
|
|
|
scsi_init_command(dev, scmd);
|
2008-04-30 16:19:47 +08:00
|
|
|
|
2021-10-08 04:27:56 +08:00
|
|
|
scmd->submitter = SUBMITTED_BY_SCSI_RESET_IOCTL;
|
2023-12-15 20:10:08 +08:00
|
|
|
scmd->flags |= SCMD_LAST;
|
2007-12-13 19:47:40 +08:00
|
|
|
memset(&scmd->sdb, 0, sizeof(scmd->sdb));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
scmd->cmd_len = 0;
|
|
|
|
|
|
|
|
scmd->sc_data_direction = DMA_BIDIRECTIONAL;
|
|
|
|
|
2006-03-09 03:50:12 +08:00
|
|
|
spin_lock_irqsave(shost->host_lock, flags);
|
|
|
|
shost->tmf_in_progress = 1;
|
|
|
|
spin_unlock_irqrestore(shost->host_lock, flags);
|
|
|
|
|
2014-10-11 18:06:47 +08:00
|
|
|
switch (val & ~SG_SCSI_RESET_NO_ESCALATE) {
|
|
|
|
case SG_SCSI_RESET_NOTHING:
|
|
|
|
rtn = SUCCESS;
|
|
|
|
break;
|
|
|
|
case SG_SCSI_RESET_DEVICE:
|
2005-04-17 06:20:36 +08:00
|
|
|
rtn = scsi_try_bus_device_reset(scmd);
|
2014-10-11 18:06:47 +08:00
|
|
|
if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2014-10-11 18:06:47 +08:00
|
|
|
case SG_SCSI_RESET_TARGET:
|
2008-03-01 08:25:19 +08:00
|
|
|
rtn = scsi_try_target_reset(scmd);
|
2014-10-11 18:06:47 +08:00
|
|
|
if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
|
2008-03-01 08:25:19 +08:00
|
|
|
break;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2014-10-11 18:06:47 +08:00
|
|
|
case SG_SCSI_RESET_BUS:
|
2005-04-17 06:20:36 +08:00
|
|
|
rtn = scsi_try_bus_reset(scmd);
|
2014-10-11 18:06:47 +08:00
|
|
|
if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2014-10-11 18:06:47 +08:00
|
|
|
case SG_SCSI_RESET_HOST:
|
2005-04-17 06:20:36 +08:00
|
|
|
rtn = scsi_try_host_reset(scmd);
|
2014-10-11 18:06:47 +08:00
|
|
|
if (rtn == SUCCESS)
|
|
|
|
break;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2017-08-26 04:46:29 +08:00
|
|
|
default:
|
2005-04-17 06:20:36 +08:00
|
|
|
rtn = FAILED;
|
2014-10-11 18:06:47 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-10-11 18:06:47 +08:00
|
|
|
error = (rtn == SUCCESS) ? 0 : -EIO;
|
|
|
|
|
2006-03-09 03:50:12 +08: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 22:39:59 +08:00
|
|
|
shost_printk(KERN_INFO, shost,
|
|
|
|
"waking up host to restart after TMF\n"));
|
2006-03-09 03:50:12 +08:00
|
|
|
|
|
|
|
wake_up(&shost->host_wait);
|
|
|
|
scsi_run_host_queues(shost);
|
|
|
|
|
2017-01-03 02:55:26 +08:00
|
|
|
kfree(rq);
|
2014-09-06 09:00:05 +08:00
|
|
|
|
2014-02-21 06:20:55 +08: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 22:41:42 +08:00
|
|
|
scsi_autopm_put_host(shost);
|
2014-10-11 18:06:47 +08:00
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-10-24 20:26:52 +08:00
|
|
|
bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd,
|
|
|
|
struct scsi_sense_hdr *sshdr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
return scsi_normalize_sense(cmd->sense_buffer,
|
2008-01-13 14:46:13 +08:00
|
|
|
SCSI_SENSE_BUFFERSIZE, sshdr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_command_normalize_sense);
|
|
|
|
|
|
|
|
/**
|
2007-11-04 02:30:39 +08:00
|
|
|
* scsi_get_sense_info_fld - get information field from sense data (either fixed or descriptor format)
|
2005-04-17 06:20:36 +08: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 15:51:12 +08:00
|
|
|
* true if information field found, false if not found.
|
2007-11-16 07:42:30 +08:00
|
|
|
*/
|
2017-04-24 15:51:12 +08:00
|
|
|
bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len,
|
|
|
|
u64 *info_out)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
const u8 * ucp;
|
|
|
|
|
|
|
|
if (sb_len < 7)
|
2017-04-24 15:51:12 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (sense_buffer[0] & 0x7f) {
|
|
|
|
case 0x70:
|
|
|
|
case 0x71:
|
|
|
|
if (sense_buffer[0] & 0x80) {
|
2017-04-24 15:51:12 +08:00
|
|
|
*info_out = get_unaligned_be32(&sense_buffer[3]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2005-04-17 06:20:36 +08: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 15:51:12 +08:00
|
|
|
*info_out = get_unaligned_be64(&ucp[4]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
2017-04-24 15:51:12 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scsi_get_sense_info_fld);
|