Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * scsi_error.c Copyright (C) 1997 Eric Youngdale |
| 4 | * |
| 5 | * SCSI error/timeout handling |
| 6 | * Initial versions: Eric Youngdale. Based upon conversations with |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 7 | * Leonard Zubkoff and David Miller at Linux Expo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * ideas originating from all over the place. |
| 9 | * |
| 10 | * Restructured scsi_unjam_host and associated functions. |
| 11 | * September 04, 2002 Mike Anderson (andmike@us.ibm.com) |
| 12 | * |
| 13 | * Forward port of Russell King's (rmk@arm.linux.org.uk) changes and |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 14 | * minor cleanups. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * September 30, 2002 Mike Anderson (andmike@us.ibm.com) |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/timer.h> |
| 22 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 24 | #include <linux/freezer.h> |
Christoph Hellwig | c5478de | 2005-09-06 14:04:26 +0200 | [diff] [blame] | 25 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/blkdev.h> |
| 28 | #include <linux/delay.h> |
Hannes Reinecke | fc73648 | 2013-04-25 08:10:00 +0200 | [diff] [blame] | 29 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include <scsi/scsi.h> |
Christoph Hellwig | beb4048 | 2006-06-10 18:01:03 +0200 | [diff] [blame] | 32 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <scsi/scsi_dbg.h> |
| 34 | #include <scsi/scsi_device.h> |
Martin K. Petersen | 18a4d0a | 2012-02-09 13:48:53 -0500 | [diff] [blame] | 35 | #include <scsi/scsi_driver.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <scsi/scsi_eh.h> |
Sagi Grimberg | 7708c16 | 2015-07-08 17:58:52 +0300 | [diff] [blame] | 37 | #include <scsi/scsi_common.h> |
James Smart | c829c39 | 2006-03-13 08:28:57 -0500 | [diff] [blame] | 38 | #include <scsi/scsi_transport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <scsi/scsi_host.h> |
| 40 | #include <scsi/scsi_ioctl.h> |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 41 | #include <scsi/scsi_dh.h> |
Martin Wilck | 29cfc2a | 2018-04-18 01:35:10 +0200 | [diff] [blame] | 42 | #include <scsi/scsi_devinfo.h> |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 43 | #include <scsi/sg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | #include "scsi_priv.h" |
| 46 | #include "scsi_logging.h" |
Adrian Bunk | 79ee830 | 2007-08-10 14:50:42 -0700 | [diff] [blame] | 47 | #include "scsi_transport_api.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Kei Tokunaga | bf81623 | 2010-04-01 20:41:40 +0900 | [diff] [blame] | 49 | #include <trace/events/scsi.h> |
| 50 | |
Damien Le Moal | 2908769 | 2017-04-24 16:51:12 +0900 | [diff] [blame] | 51 | #include <asm/unaligned.h> |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* |
| 54 | * These should *probably* be handled by the host itself. |
| 55 | * Since it is allowed to sleep, it probably should. |
| 56 | */ |
| 57 | #define BUS_RESET_SETTLE_TIME (10) |
| 58 | #define HOST_RESET_SETTLE_TIME (10) |
| 59 | |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 60 | static int scsi_eh_try_stu(struct scsi_cmnd *scmd); |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 61 | static enum scsi_disposition scsi_try_to_abort_cmd(struct scsi_host_template *, |
| 62 | struct scsi_cmnd *); |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | void scsi_eh_wakeup(struct Scsi_Host *shost) |
| 65 | { |
Bart Van Assche | f0317e8 | 2017-12-04 10:06:24 -0800 | [diff] [blame] | 66 | lockdep_assert_held(shost->host_lock); |
| 67 | |
Ming Lei | c84b023 | 2018-06-24 22:03:26 +0800 | [diff] [blame] | 68 | if (scsi_host_busy(shost) == shost->host_failed) { |
Kei Tokunaga | bf81623 | 2010-04-01 20:41:40 +0900 | [diff] [blame] | 69 | trace_scsi_eh_wakeup(shost); |
James Bottomley | 3ed7a47 | 2005-09-19 09:50:04 -0500 | [diff] [blame] | 70 | wake_up_process(shost->ehandler); |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 71 | SCSI_LOG_ERROR_RECOVERY(5, shost_printk(KERN_INFO, shost, |
| 72 | "Waking error handler thread\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
Tejun Heo | f8bbfc2 | 2006-05-19 21:07:05 +0900 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * scsi_schedule_eh - schedule EH for SCSI host |
| 78 | * @shost: SCSI host to invoke error handling on. |
| 79 | * |
| 80 | * Schedule SCSI EH without scmd. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 81 | */ |
Tejun Heo | f8bbfc2 | 2006-05-19 21:07:05 +0900 | [diff] [blame] | 82 | void scsi_schedule_eh(struct Scsi_Host *shost) |
| 83 | { |
| 84 | unsigned long flags; |
| 85 | |
| 86 | spin_lock_irqsave(shost->host_lock, flags); |
| 87 | |
| 88 | if (scsi_host_set_state(shost, SHOST_RECOVERY) == 0 || |
| 89 | scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY) == 0) { |
| 90 | shost->host_eh_scheduled++; |
| 91 | scsi_eh_wakeup(shost); |
| 92 | } |
| 93 | |
| 94 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 95 | } |
| 96 | EXPORT_SYMBOL_GPL(scsi_schedule_eh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 98 | static int scsi_host_eh_past_deadline(struct Scsi_Host *shost) |
| 99 | { |
Ren Mingxin | bb3b621 | 2013-11-11 13:44:56 +0100 | [diff] [blame] | 100 | if (!shost->last_reset || shost->eh_deadline == -1) |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 101 | return 0; |
| 102 | |
Hannes Reinecke | 76ad3e5 | 2013-11-11 13:44:55 +0100 | [diff] [blame] | 103 | /* |
| 104 | * 32bit accesses are guaranteed to be atomic |
| 105 | * (on all supported architectures), so instead |
| 106 | * of using a spinlock we can as well double check |
Ren Mingxin | bb3b621 | 2013-11-11 13:44:56 +0100 | [diff] [blame] | 107 | * if eh_deadline has been set to 'off' during the |
Hannes Reinecke | 76ad3e5 | 2013-11-11 13:44:55 +0100 | [diff] [blame] | 108 | * time_before call. |
| 109 | */ |
| 110 | if (time_before(jiffies, shost->last_reset + shost->eh_deadline) && |
Ren Mingxin | bb3b621 | 2013-11-11 13:44:56 +0100 | [diff] [blame] | 111 | shost->eh_deadline > -1) |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 112 | return 0; |
| 113 | |
| 114 | return 1; |
| 115 | } |
| 116 | |
Mike Christie | 2a242d5 | 2020-10-01 10:35:53 -0500 | [diff] [blame] | 117 | static bool scsi_cmd_retry_allowed(struct scsi_cmnd *cmd) |
| 118 | { |
| 119 | if (cmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT) |
| 120 | return true; |
| 121 | |
| 122 | return ++cmd->retries <= cmd->allowed; |
| 123 | } |
| 124 | |
Muneendra Kumar | 60bee27 | 2021-01-07 03:19:05 +0530 | [diff] [blame] | 125 | static bool scsi_eh_should_retry_cmd(struct scsi_cmnd *cmd) |
| 126 | { |
| 127 | struct scsi_device *sdev = cmd->device; |
| 128 | struct Scsi_Host *host = sdev->host; |
| 129 | |
| 130 | if (host->hostt->eh_should_retry_cmd) |
| 131 | return host->hostt->eh_should_retry_cmd(cmd); |
| 132 | |
| 133 | return true; |
| 134 | } |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /** |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 137 | * scmd_eh_abort_handler - Handle command aborts |
| 138 | * @work: command to be aborted. |
Bart Van Assche | 923f46f | 2018-02-12 10:38:05 -0800 | [diff] [blame] | 139 | * |
| 140 | * Note: this function must be called only for a command that has timed out. |
| 141 | * Because the block layer marks a request as complete before it calls |
| 142 | * scsi_times_out(), a .scsi_done() call from the LLD for a command that has |
| 143 | * timed out do not have any effect. Hence it is safe to call |
| 144 | * scsi_finish_command() from this function. |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 145 | */ |
| 146 | void |
| 147 | scmd_eh_abort_handler(struct work_struct *work) |
| 148 | { |
| 149 | struct scsi_cmnd *scmd = |
| 150 | container_of(work, struct scsi_cmnd, abort_work.work); |
| 151 | struct scsi_device *sdev = scmd->device; |
Ewan D. Milne | 54d816d | 2021-10-29 15:43:11 -0400 | [diff] [blame] | 152 | struct Scsi_Host *shost = sdev->host; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 153 | enum scsi_disposition rtn; |
Ewan D. Milne | 5ae1750 | 2021-10-29 15:43:10 -0400 | [diff] [blame] | 154 | unsigned long flags; |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 155 | |
Ewan D. Milne | 54d816d | 2021-10-29 15:43:11 -0400 | [diff] [blame] | 156 | if (scsi_host_eh_past_deadline(shost)) { |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 157 | SCSI_LOG_ERROR_RECOVERY(3, |
| 158 | scmd_printk(KERN_INFO, scmd, |
Hannes Reinecke | 470613b | 2015-01-08 07:43:50 +0100 | [diff] [blame] | 159 | "eh timeout, not aborting\n")); |
Ewan D. Milne | 54d816d | 2021-10-29 15:43:11 -0400 | [diff] [blame] | 160 | goto out; |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Ewan D. Milne | 54d816d | 2021-10-29 15:43:11 -0400 | [diff] [blame] | 163 | SCSI_LOG_ERROR_RECOVERY(3, |
| 164 | scmd_printk(KERN_INFO, scmd, |
| 165 | "aborting command\n")); |
| 166 | rtn = scsi_try_to_abort_cmd(shost->hostt, scmd); |
| 167 | if (rtn != SUCCESS) { |
| 168 | SCSI_LOG_ERROR_RECOVERY(3, |
| 169 | scmd_printk(KERN_INFO, scmd, |
| 170 | "cmd abort %s\n", |
| 171 | (rtn == FAST_IO_FAIL) ? |
| 172 | "not send" : "failed")); |
| 173 | goto out; |
| 174 | } |
| 175 | set_host_byte(scmd, DID_TIME_OUT); |
| 176 | if (scsi_host_eh_past_deadline(shost)) { |
| 177 | SCSI_LOG_ERROR_RECOVERY(3, |
| 178 | scmd_printk(KERN_INFO, scmd, |
| 179 | "eh timeout, not retrying " |
| 180 | "aborted command\n")); |
| 181 | goto out; |
| 182 | } |
| 183 | |
| 184 | spin_lock_irqsave(shost->host_lock, flags); |
Ewan D. Milne | 5ae1750 | 2021-10-29 15:43:10 -0400 | [diff] [blame] | 185 | list_del_init(&scmd->eh_entry); |
Ewan D. Milne | 54d816d | 2021-10-29 15:43:11 -0400 | [diff] [blame] | 186 | |
| 187 | /* |
| 188 | * If the abort succeeds, and there is no further |
| 189 | * EH action, clear the ->last_reset time. |
| 190 | */ |
| 191 | if (list_empty(&shost->eh_abort_list) && |
| 192 | list_empty(&shost->eh_cmd_q)) |
| 193 | if (shost->eh_deadline != -1) |
| 194 | shost->last_reset = 0; |
| 195 | |
| 196 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 197 | |
| 198 | if (!scsi_noretry_cmd(scmd) && |
| 199 | scsi_cmd_retry_allowed(scmd) && |
| 200 | scsi_eh_should_retry_cmd(scmd)) { |
| 201 | SCSI_LOG_ERROR_RECOVERY(3, |
| 202 | scmd_printk(KERN_WARNING, scmd, |
| 203 | "retry aborted command\n")); |
| 204 | scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY); |
| 205 | } else { |
| 206 | SCSI_LOG_ERROR_RECOVERY(3, |
| 207 | scmd_printk(KERN_WARNING, scmd, |
| 208 | "finish aborted command\n")); |
| 209 | scsi_finish_command(scmd); |
| 210 | } |
| 211 | return; |
| 212 | |
| 213 | out: |
| 214 | spin_lock_irqsave(shost->host_lock, flags); |
| 215 | list_del_init(&scmd->eh_entry); |
| 216 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 217 | |
Hannes Reinecke | a065863 | 2017-04-06 15:36:35 +0200 | [diff] [blame] | 218 | scsi_eh_scmd_add(scmd); |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** |
| 222 | * scsi_abort_command - schedule a command abort |
| 223 | * @scmd: scmd to abort. |
| 224 | * |
| 225 | * We only need to abort commands after a command timeout |
| 226 | */ |
| 227 | static int |
| 228 | scsi_abort_command(struct scsi_cmnd *scmd) |
| 229 | { |
| 230 | struct scsi_device *sdev = scmd->device; |
| 231 | struct Scsi_Host *shost = sdev->host; |
| 232 | unsigned long flags; |
| 233 | |
| 234 | if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) { |
| 235 | /* |
| 236 | * Retry after abort failed, escalate to next level. |
| 237 | */ |
| 238 | SCSI_LOG_ERROR_RECOVERY(3, |
| 239 | scmd_printk(KERN_INFO, scmd, |
Hannes Reinecke | 470613b | 2015-01-08 07:43:50 +0100 | [diff] [blame] | 240 | "previous abort failed\n")); |
Bart Van Assche | fcc95a7 | 2014-06-02 11:50:52 +0200 | [diff] [blame] | 241 | BUG_ON(delayed_work_pending(&scmd->abort_work)); |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 242 | return FAILED; |
| 243 | } |
| 244 | |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 245 | spin_lock_irqsave(shost->host_lock, flags); |
Ren Mingxin | bb3b621 | 2013-11-11 13:44:56 +0100 | [diff] [blame] | 246 | if (shost->eh_deadline != -1 && !shost->last_reset) |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 247 | shost->last_reset = jiffies; |
Ewan D. Milne | 5ae1750 | 2021-10-29 15:43:10 -0400 | [diff] [blame] | 248 | BUG_ON(!list_empty(&scmd->eh_entry)); |
| 249 | list_add_tail(&scmd->eh_entry, &shost->eh_abort_list); |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 250 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 251 | |
| 252 | scmd->eh_eflags |= SCSI_EH_ABORT_SCHEDULED; |
| 253 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | 470613b | 2015-01-08 07:43:50 +0100 | [diff] [blame] | 254 | scmd_printk(KERN_INFO, scmd, "abort scheduled\n")); |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 255 | queue_delayed_work(shost->tmf_work_q, &scmd->abort_work, HZ / 100); |
| 256 | return SUCCESS; |
| 257 | } |
| 258 | |
| 259 | /** |
Hannes Reinecke | 7a38dc0 | 2017-04-06 15:36:29 +0200 | [diff] [blame] | 260 | * scsi_eh_reset - call into ->eh_action to reset internal counters |
| 261 | * @scmd: scmd to run eh on. |
| 262 | * |
| 263 | * The scsi driver might be carrying internal state about the |
| 264 | * devices, so we need to call into the driver to reset the |
| 265 | * internal state once the error handler is started. |
| 266 | */ |
| 267 | static void scsi_eh_reset(struct scsi_cmnd *scmd) |
| 268 | { |
Bart Van Assche | aa8e25e | 2021-08-09 16:03:05 -0700 | [diff] [blame] | 269 | if (!blk_rq_is_passthrough(scsi_cmd_to_rq(scmd))) { |
Hannes Reinecke | 7a38dc0 | 2017-04-06 15:36:29 +0200 | [diff] [blame] | 270 | struct scsi_driver *sdrv = scsi_cmd_to_driver(scmd); |
| 271 | if (sdrv->eh_reset) |
| 272 | sdrv->eh_reset(scmd); |
| 273 | } |
| 274 | } |
| 275 | |
Bart Van Assche | 3bd6f43 | 2017-12-04 10:06:23 -0800 | [diff] [blame] | 276 | static void scsi_eh_inc_host_failed(struct rcu_head *head) |
| 277 | { |
Bart Van Assche | 3be8828 | 2018-02-22 11:30:20 -0800 | [diff] [blame] | 278 | struct scsi_cmnd *scmd = container_of(head, typeof(*scmd), rcu); |
| 279 | struct Scsi_Host *shost = scmd->device->host; |
Bart Van Assche | 3bd6f43 | 2017-12-04 10:06:23 -0800 | [diff] [blame] | 280 | unsigned long flags; |
| 281 | |
| 282 | spin_lock_irqsave(shost->host_lock, flags); |
| 283 | shost->host_failed++; |
| 284 | scsi_eh_wakeup(shost); |
| 285 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 286 | } |
| 287 | |
Hannes Reinecke | 7a38dc0 | 2017-04-06 15:36:29 +0200 | [diff] [blame] | 288 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | * scsi_eh_scmd_add - add scsi cmd to error handling. |
| 290 | * @scmd: scmd to run eh on. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 291 | */ |
Hannes Reinecke | a065863 | 2017-04-06 15:36:35 +0200 | [diff] [blame] | 292 | void scsi_eh_scmd_add(struct scsi_cmnd *scmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
| 294 | struct Scsi_Host *shost = scmd->device->host; |
| 295 | unsigned long flags; |
Hannes Reinecke | 2171b6d | 2017-04-06 15:36:34 +0200 | [diff] [blame] | 296 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Hannes Reinecke | 2171b6d | 2017-04-06 15:36:34 +0200 | [diff] [blame] | 298 | WARN_ON_ONCE(!shost->ehandler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | spin_lock_irqsave(shost->host_lock, flags); |
Hannes Reinecke | 2171b6d | 2017-04-06 15:36:34 +0200 | [diff] [blame] | 301 | if (scsi_host_set_state(shost, SHOST_RECOVERY)) { |
| 302 | ret = scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY); |
| 303 | WARN_ON_ONCE(ret); |
| 304 | } |
Ren Mingxin | bb3b621 | 2013-11-11 13:44:56 +0100 | [diff] [blame] | 305 | if (shost->eh_deadline != -1 && !shost->last_reset) |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 306 | shost->last_reset = jiffies; |
| 307 | |
Hannes Reinecke | 7a38dc0 | 2017-04-06 15:36:29 +0200 | [diff] [blame] | 308 | scsi_eh_reset(scmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | spin_unlock_irqrestore(shost->host_lock, flags); |
Bart Van Assche | 3bd6f43 | 2017-12-04 10:06:23 -0800 | [diff] [blame] | 311 | /* |
| 312 | * Ensure that all tasks observe the host state change before the |
| 313 | * host_failed change. |
| 314 | */ |
Bart Van Assche | 3be8828 | 2018-02-22 11:30:20 -0800 | [diff] [blame] | 315 | call_rcu(&scmd->rcu, scsi_eh_inc_host_failed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | * scsi_times_out - Timeout function for normal scsi commands. |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 320 | * @req: request that is timing out. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | * |
| 322 | * Notes: |
| 323 | * We do not need to lock this. There is the potential for a race |
| 324 | * only in that the normal completion handling might run, but if the |
| 325 | * normal completion function determines that the timer has already |
| 326 | * fired, then it mustn't do anything. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 327 | */ |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 328 | enum blk_eh_timer_return scsi_times_out(struct request *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Bart Van Assche | bed2213 | 2017-08-25 13:46:32 -0700 | [diff] [blame] | 330 | struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req); |
Christoph Hellwig | 6600593 | 2018-05-29 15:52:29 +0200 | [diff] [blame] | 331 | enum blk_eh_timer_return rtn = BLK_EH_DONE; |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 332 | struct Scsi_Host *host = scmd->device->host; |
James Bottomley | 6c5f8ce | 2007-03-16 17:44:41 -0500 | [diff] [blame] | 333 | |
Kei Tokunaga | bf81623 | 2010-04-01 20:41:40 +0900 | [diff] [blame] | 334 | trace_scsi_dispatch_cmd_timeout(scmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | scsi_log_completion(scmd, TIMEOUT_ERROR); |
| 336 | |
Ren Mingxin | bb3b621 | 2013-11-11 13:44:56 +0100 | [diff] [blame] | 337 | if (host->eh_deadline != -1 && !host->last_reset) |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 338 | host->last_reset = jiffies; |
| 339 | |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 340 | if (host->hostt->eh_timed_out) |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 341 | rtn = host->hostt->eh_timed_out(scmd); |
James Bottomley | 6c5f8ce | 2007-03-16 17:44:41 -0500 | [diff] [blame] | 342 | |
Christoph Hellwig | 6600593 | 2018-05-29 15:52:29 +0200 | [diff] [blame] | 343 | if (rtn == BLK_EH_DONE) { |
Keith Busch | 065990b | 2018-07-23 08:37:51 -0600 | [diff] [blame] | 344 | /* |
Keith Busch | f134270 | 2018-11-26 09:54:29 -0700 | [diff] [blame] | 345 | * Set the command to complete first in order to prevent a real |
| 346 | * completion from releasing the command while error handling |
| 347 | * is using it. If the command was already completed, then the |
| 348 | * lower level driver beat the timeout handler, and it is safe |
| 349 | * to return without escalating error recovery. |
Keith Busch | 065990b | 2018-07-23 08:37:51 -0600 | [diff] [blame] | 350 | * |
Keith Busch | f134270 | 2018-11-26 09:54:29 -0700 | [diff] [blame] | 351 | * If timeout handling lost the race to a real completion, the |
| 352 | * block layer may ignore that due to a fake timeout injection, |
| 353 | * so return RESET_TIMER to allow error handling another shot |
| 354 | * at this command. |
Keith Busch | 065990b | 2018-07-23 08:37:51 -0600 | [diff] [blame] | 355 | */ |
Keith Busch | f134270 | 2018-11-26 09:54:29 -0700 | [diff] [blame] | 356 | if (test_and_set_bit(SCMD_STATE_COMPLETE, &scmd->state)) |
| 357 | return BLK_EH_RESET_TIMER; |
Hannes Reinecke | a065863 | 2017-04-06 15:36:35 +0200 | [diff] [blame] | 358 | if (scsi_abort_command(scmd) != SUCCESS) { |
Hannes Reinecke | 2171b6d | 2017-04-06 15:36:34 +0200 | [diff] [blame] | 359 | set_host_byte(scmd, DID_TIME_OUT); |
Hannes Reinecke | a065863 | 2017-04-06 15:36:35 +0200 | [diff] [blame] | 360 | scsi_eh_scmd_add(scmd); |
Hannes Reinecke | 2171b6d | 2017-04-06 15:36:34 +0200 | [diff] [blame] | 361 | } |
Hannes Reinecke | a33c070 | 2014-06-13 14:01:45 +0200 | [diff] [blame] | 362 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 363 | |
Christoph Hellwig | fa99078 | 2008-11-05 15:03:15 +0100 | [diff] [blame] | 364 | return rtn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /** |
| 368 | * scsi_block_when_processing_errors - Prevent cmds from being queued. |
| 369 | * @sdev: Device on which we are performing recovery. |
| 370 | * |
| 371 | * Description: |
| 372 | * We block until the host is out of error recovery, and then check to |
| 373 | * see whether the host or the device is offline. |
| 374 | * |
| 375 | * Return value: |
| 376 | * 0 when dev was taken offline by error recovery. 1 OK to proceed. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 377 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | int scsi_block_when_processing_errors(struct scsi_device *sdev) |
| 379 | { |
| 380 | int online; |
| 381 | |
James Bottomley | 939647e | 2005-09-18 15:05:20 -0500 | [diff] [blame] | 382 | wait_event(sdev->host->host_wait, !scsi_host_in_recovery(sdev->host)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | online = scsi_device_online(sdev); |
| 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | return online; |
| 387 | } |
| 388 | EXPORT_SYMBOL(scsi_block_when_processing_errors); |
| 389 | |
| 390 | #ifdef CONFIG_SCSI_LOGGING |
| 391 | /** |
| 392 | * scsi_eh_prt_fail_stats - Log info on failures. |
| 393 | * @shost: scsi host being recovered. |
| 394 | * @work_q: Queue of scsi cmds to process. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 395 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost, |
| 397 | struct list_head *work_q) |
| 398 | { |
| 399 | struct scsi_cmnd *scmd; |
| 400 | struct scsi_device *sdev; |
| 401 | int total_failures = 0; |
| 402 | int cmd_failed = 0; |
| 403 | int cmd_cancel = 0; |
| 404 | int devices_failed = 0; |
| 405 | |
| 406 | shost_for_each_device(sdev, shost) { |
| 407 | list_for_each_entry(scmd, work_q, eh_entry) { |
| 408 | if (scmd->device == sdev) { |
| 409 | ++total_failures; |
Hannes Reinecke | a065863 | 2017-04-06 15:36:35 +0200 | [diff] [blame] | 410 | if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | ++cmd_cancel; |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 412 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | ++cmd_failed; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | if (cmd_cancel || cmd_failed) { |
| 418 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | a3a790d | 2014-10-24 14:27:03 +0200 | [diff] [blame] | 419 | shost_printk(KERN_INFO, shost, |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 420 | "%s: cmds failed: %d, cancel: %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 421 | __func__, cmd_failed, |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 422 | cmd_cancel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | cmd_cancel = 0; |
| 424 | cmd_failed = 0; |
| 425 | ++devices_failed; |
| 426 | } |
| 427 | } |
| 428 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 429 | SCSI_LOG_ERROR_RECOVERY(2, shost_printk(KERN_INFO, shost, |
| 430 | "Total of %d commands on %d" |
| 431 | " devices require eh work\n", |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 432 | total_failures, devices_failed)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | #endif |
| 435 | |
Ewan D. Milne | 279afdf | 2013-08-08 15:07:48 -0400 | [diff] [blame] | 436 | /** |
| 437 | * scsi_report_lun_change - Set flag on all *other* devices on the same target |
| 438 | * to indicate that a UNIT ATTENTION is expected. |
| 439 | * @sdev: Device reporting the UNIT ATTENTION |
| 440 | */ |
| 441 | static void scsi_report_lun_change(struct scsi_device *sdev) |
| 442 | { |
| 443 | sdev->sdev_target->expecting_lun_change = 1; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * scsi_report_sense - Examine scsi sense information and log messages for |
| 448 | * certain conditions, also issue uevents for some of them. |
| 449 | * @sdev: Device reporting the sense code |
| 450 | * @sshdr: sshdr to be examined |
| 451 | */ |
| 452 | static void scsi_report_sense(struct scsi_device *sdev, |
| 453 | struct scsi_sense_hdr *sshdr) |
| 454 | { |
| 455 | enum scsi_device_event evt_type = SDEV_EVT_MAXBITS; /* i.e. none */ |
| 456 | |
| 457 | if (sshdr->sense_key == UNIT_ATTENTION) { |
| 458 | if (sshdr->asc == 0x3f && sshdr->ascq == 0x03) { |
| 459 | evt_type = SDEV_EVT_INQUIRY_CHANGE_REPORTED; |
| 460 | sdev_printk(KERN_WARNING, sdev, |
| 461 | "Inquiry data has changed"); |
| 462 | } else if (sshdr->asc == 0x3f && sshdr->ascq == 0x0e) { |
| 463 | evt_type = SDEV_EVT_LUN_CHANGE_REPORTED; |
| 464 | scsi_report_lun_change(sdev); |
| 465 | sdev_printk(KERN_WARNING, sdev, |
| 466 | "Warning! Received an indication that the " |
| 467 | "LUN assignments on this target have " |
| 468 | "changed. The Linux SCSI layer does not " |
| 469 | "automatically remap LUN assignments.\n"); |
| 470 | } else if (sshdr->asc == 0x3f) |
| 471 | sdev_printk(KERN_WARNING, sdev, |
| 472 | "Warning! Received an indication that the " |
| 473 | "operating parameters on this target have " |
| 474 | "changed. The Linux SCSI layer does not " |
| 475 | "automatically adjust these parameters.\n"); |
| 476 | |
| 477 | if (sshdr->asc == 0x38 && sshdr->ascq == 0x07) { |
| 478 | evt_type = SDEV_EVT_SOFT_THRESHOLD_REACHED_REPORTED; |
| 479 | sdev_printk(KERN_WARNING, sdev, |
| 480 | "Warning! Received an indication that the " |
| 481 | "LUN reached a thin provisioning soft " |
| 482 | "threshold.\n"); |
| 483 | } |
| 484 | |
Hannes Reinecke | cf3431b | 2017-10-17 09:11:24 +0200 | [diff] [blame] | 485 | if (sshdr->asc == 0x29) { |
| 486 | evt_type = SDEV_EVT_POWER_ON_RESET_OCCURRED; |
| 487 | sdev_printk(KERN_WARNING, sdev, |
| 488 | "Power-on or device reset occurred\n"); |
| 489 | } |
| 490 | |
Ewan D. Milne | 279afdf | 2013-08-08 15:07:48 -0400 | [diff] [blame] | 491 | if (sshdr->asc == 0x2a && sshdr->ascq == 0x01) { |
| 492 | evt_type = SDEV_EVT_MODE_PARAMETER_CHANGE_REPORTED; |
| 493 | sdev_printk(KERN_WARNING, sdev, |
| 494 | "Mode parameters changed"); |
Hannes Reinecke | 14c3e67 | 2015-07-06 13:41:53 +0200 | [diff] [blame] | 495 | } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x06) { |
| 496 | evt_type = SDEV_EVT_ALUA_STATE_CHANGE_REPORTED; |
| 497 | sdev_printk(KERN_WARNING, sdev, |
| 498 | "Asymmetric access state changed"); |
Ewan D. Milne | 279afdf | 2013-08-08 15:07:48 -0400 | [diff] [blame] | 499 | } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x09) { |
| 500 | evt_type = SDEV_EVT_CAPACITY_CHANGE_REPORTED; |
| 501 | sdev_printk(KERN_WARNING, sdev, |
| 502 | "Capacity data has changed"); |
| 503 | } else if (sshdr->asc == 0x2a) |
| 504 | sdev_printk(KERN_WARNING, sdev, |
| 505 | "Parameters changed"); |
| 506 | } |
| 507 | |
| 508 | if (evt_type != SDEV_EVT_MAXBITS) { |
| 509 | set_bit(evt_type, sdev->pending_events); |
| 510 | schedule_work(&sdev->event_work); |
| 511 | } |
| 512 | } |
| 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | /** |
| 515 | * scsi_check_sense - Examine scsi cmd sense |
| 516 | * @scmd: Cmd to have sense checked. |
| 517 | * |
| 518 | * Return value: |
Hannes Reinecke | 87f14e6 | 2013-07-01 15:16:24 +0200 | [diff] [blame] | 519 | * SUCCESS or FAILED or NEEDS_RETRY or ADD_TO_MLQUEUE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | * |
| 521 | * Notes: |
| 522 | * When a deferred error is detected the current command has |
| 523 | * not been executed and needs retrying. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 524 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 525 | enum scsi_disposition scsi_check_sense(struct scsi_cmnd *scmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | { |
Chandra Seetharaman | a6a8d9f | 2008-05-01 14:49:46 -0700 | [diff] [blame] | 527 | struct scsi_device *sdev = scmd->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | struct scsi_sense_hdr sshdr; |
| 529 | |
| 530 | if (! scsi_command_normalize_sense(scmd, &sshdr)) |
| 531 | return FAILED; /* no valid sense data */ |
| 532 | |
Ewan D. Milne | 279afdf | 2013-08-08 15:07:48 -0400 | [diff] [blame] | 533 | scsi_report_sense(sdev, &sshdr); |
| 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | if (scsi_sense_is_deferred(&sshdr)) |
| 536 | return NEEDS_RETRY; |
| 537 | |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 538 | if (sdev->handler && sdev->handler->check_sense) { |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 539 | enum scsi_disposition rc; |
Chandra Seetharaman | a6a8d9f | 2008-05-01 14:49:46 -0700 | [diff] [blame] | 540 | |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 541 | rc = sdev->handler->check_sense(sdev, &sshdr); |
Chandra Seetharaman | a6a8d9f | 2008-05-01 14:49:46 -0700 | [diff] [blame] | 542 | if (rc != SCSI_RETURN_NOT_HANDLED) |
| 543 | return rc; |
| 544 | /* handler does not care. Drop down to default handling */ |
| 545 | } |
| 546 | |
Bart Van Assche | bf23e61 | 2021-10-07 13:27:56 -0700 | [diff] [blame] | 547 | if (scmd->cmnd[0] == TEST_UNIT_READY && |
| 548 | scmd->submitter != SUBMITTED_BY_SCSI_ERROR_HANDLER) |
Christoph Hellwig | e925cc4 | 2014-11-06 15:11:22 -0600 | [diff] [blame] | 549 | /* |
| 550 | * nasty: for mid-layer issued TURs, we need to return the |
| 551 | * actual sense data without any recovery attempt. For eh |
| 552 | * issued ones, we need to try to recover and interpret |
| 553 | */ |
| 554 | return SUCCESS; |
| 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | /* |
| 557 | * Previous logic looked for FILEMARK, EOM or ILI which are |
| 558 | * mainly associated with tapes and returned SUCCESS. |
| 559 | */ |
| 560 | if (sshdr.response_code == 0x70) { |
| 561 | /* fixed format */ |
| 562 | if (scmd->sense_buffer[2] & 0xe0) |
| 563 | return SUCCESS; |
| 564 | } else { |
| 565 | /* |
| 566 | * descriptor format: look for "stream commands sense data |
| 567 | * descriptor" (see SSC-3). Assume single sense data |
| 568 | * descriptor. Ignore ILI from SBC-2 READ LONG and WRITE LONG. |
| 569 | */ |
| 570 | if ((sshdr.additional_length > 3) && |
| 571 | (scmd->sense_buffer[8] == 0x4) && |
| 572 | (scmd->sense_buffer[11] & 0xe0)) |
| 573 | return SUCCESS; |
| 574 | } |
| 575 | |
| 576 | switch (sshdr.sense_key) { |
| 577 | case NO_SENSE: |
| 578 | return SUCCESS; |
| 579 | case RECOVERED_ERROR: |
| 580 | return /* soft_error */ SUCCESS; |
| 581 | |
| 582 | case ABORTED_COMMAND: |
Martin K. Petersen | 511e44f | 2008-07-17 04:28:33 -0400 | [diff] [blame] | 583 | if (sshdr.asc == 0x10) /* DIF */ |
| 584 | return SUCCESS; |
| 585 | |
Martin Wilck | 29cfc2a | 2018-04-18 01:35:10 +0200 | [diff] [blame] | 586 | if (sshdr.asc == 0x44 && sdev->sdev_bflags & BLIST_RETRY_ITF) |
| 587 | return ADD_TO_MLQUEUE; |
Martin Wilck | c360652 | 2018-04-18 01:35:11 +0200 | [diff] [blame] | 588 | if (sshdr.asc == 0xc1 && sshdr.ascq == 0x01 && |
| 589 | sdev->sdev_bflags & BLIST_RETRY_ASC_C1) |
| 590 | return ADD_TO_MLQUEUE; |
Martin Wilck | 29cfc2a | 2018-04-18 01:35:10 +0200 | [diff] [blame] | 591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | return NEEDS_RETRY; |
| 593 | case NOT_READY: |
| 594 | case UNIT_ATTENTION: |
| 595 | /* |
| 596 | * if we are expecting a cc/ua because of a bus reset that we |
| 597 | * performed, treat this just as a retry. otherwise this is |
| 598 | * information that we should pass up to the upper-level driver |
| 599 | * so that we can deal with it there. |
| 600 | */ |
| 601 | if (scmd->device->expecting_cc_ua) { |
TARUISI Hiroaki | dfcf777 | 2011-08-11 20:25:20 +0900 | [diff] [blame] | 602 | /* |
| 603 | * Because some device does not queue unit |
| 604 | * attentions correctly, we carefully check |
| 605 | * additional sense code and qualifier so as |
| 606 | * not to squash media change unit attention. |
| 607 | */ |
| 608 | if (sshdr.asc != 0x28 || sshdr.ascq != 0x00) { |
| 609 | scmd->device->expecting_cc_ua = 0; |
| 610 | return NEEDS_RETRY; |
| 611 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | /* |
Ewan D. Milne | 279afdf | 2013-08-08 15:07:48 -0400 | [diff] [blame] | 614 | * we might also expect a cc/ua if another LUN on the target |
| 615 | * reported a UA with an ASC/ASCQ of 3F 0E - |
| 616 | * REPORTED LUNS DATA HAS CHANGED. |
| 617 | */ |
| 618 | if (scmd->device->sdev_target->expecting_lun_change && |
| 619 | sshdr.asc == 0x3f && sshdr.ascq == 0x0e) |
| 620 | return NEEDS_RETRY; |
| 621 | /* |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 622 | * if the device is in the process of becoming ready, we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | * should retry. |
| 624 | */ |
| 625 | if ((sshdr.asc == 0x04) && (sshdr.ascq == 0x01)) |
| 626 | return NEEDS_RETRY; |
| 627 | /* |
| 628 | * if the device is not started, we need to wake |
| 629 | * the error handler to start the motor |
| 630 | */ |
| 631 | if (scmd->device->allow_restart && |
| 632 | (sshdr.asc == 0x04) && (sshdr.ascq == 0x02)) |
| 633 | return FAILED; |
Christoph Hellwig | 02e031c | 2010-11-10 14:54:09 +0100 | [diff] [blame] | 634 | /* |
| 635 | * Pass the UA upwards for a determination in the completion |
| 636 | * functions. |
| 637 | */ |
| 638 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Hannes Reinecke | 63583cc | 2011-01-18 10:13:11 +0100 | [diff] [blame] | 640 | /* these are not supported */ |
Hannes Reinecke | a9d6ceb8 | 2013-07-01 15:16:25 +0200 | [diff] [blame] | 641 | case DATA_PROTECT: |
| 642 | if (sshdr.asc == 0x27 && sshdr.ascq == 0x07) { |
| 643 | /* Thin provisioning hard threshold reached */ |
| 644 | set_host_byte(scmd, DID_ALLOC_FAILURE); |
| 645 | return SUCCESS; |
| 646 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 647 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | case COPY_ABORTED: |
| 649 | case VOLUME_OVERFLOW: |
| 650 | case MISCOMPARE: |
Hannes Reinecke | 63583cc | 2011-01-18 10:13:11 +0100 | [diff] [blame] | 651 | case BLANK_CHECK: |
Hannes Reinecke | 87f14e6 | 2013-07-01 15:16:24 +0200 | [diff] [blame] | 652 | set_host_byte(scmd, DID_TARGET_FAILURE); |
| 653 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
| 655 | case MEDIUM_ERROR: |
Luben Tuikov | fd1b494 | 2006-11-29 19:45:23 -0800 | [diff] [blame] | 656 | if (sshdr.asc == 0x11 || /* UNRECOVERED READ ERR */ |
| 657 | sshdr.asc == 0x13 || /* AMNF DATA FIELD */ |
| 658 | sshdr.asc == 0x14) { /* RECORD NOT FOUND */ |
Hannes Reinecke | 7e782af | 2013-07-01 15:16:26 +0200 | [diff] [blame] | 659 | set_host_byte(scmd, DID_MEDIUM_ERROR); |
Hannes Reinecke | 87f14e6 | 2013-07-01 15:16:24 +0200 | [diff] [blame] | 660 | return SUCCESS; |
Luben Tuikov | fd1b494 | 2006-11-29 19:45:23 -0800 | [diff] [blame] | 661 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | return NEEDS_RETRY; |
| 663 | |
| 664 | case HARDWARE_ERROR: |
| 665 | if (scmd->device->retry_hwerror) |
Mike Anderson | bb0003c | 2008-08-12 12:11:58 -0700 | [diff] [blame] | 666 | return ADD_TO_MLQUEUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | else |
Hannes Reinecke | 87f14e6 | 2013-07-01 15:16:24 +0200 | [diff] [blame] | 668 | set_host_byte(scmd, DID_TARGET_FAILURE); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 669 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
| 671 | case ILLEGAL_REQUEST: |
Mike Snitzer | 47ac56d | 2012-02-13 18:35:11 -0500 | [diff] [blame] | 672 | if (sshdr.asc == 0x20 || /* Invalid command operation code */ |
| 673 | sshdr.asc == 0x21 || /* Logical block address out of range */ |
Hannes Reinecke | a8bbb2a | 2017-10-17 09:10:56 +0200 | [diff] [blame] | 674 | sshdr.asc == 0x22 || /* Invalid function */ |
Mike Snitzer | 47ac56d | 2012-02-13 18:35:11 -0500 | [diff] [blame] | 675 | sshdr.asc == 0x24 || /* Invalid field in cdb */ |
Martin Wilck | d0b7a90 | 2017-09-27 14:44:19 +0200 | [diff] [blame] | 676 | sshdr.asc == 0x26 || /* Parameter value invalid */ |
| 677 | sshdr.asc == 0x27) { /* Write protected */ |
Hannes Reinecke | 87f14e6 | 2013-07-01 15:16:24 +0200 | [diff] [blame] | 678 | set_host_byte(scmd, DID_TARGET_FAILURE); |
Mike Snitzer | 47ac56d | 2012-02-13 18:35:11 -0500 | [diff] [blame] | 679 | } |
| 680 | return SUCCESS; |
| 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | default: |
| 683 | return SUCCESS; |
| 684 | } |
| 685 | } |
Hannes Reinecke | 3852e37 | 2016-04-04 11:44:01 +0200 | [diff] [blame] | 686 | EXPORT_SYMBOL_GPL(scsi_check_sense); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Vasu Dev | 4a84067 | 2009-10-22 15:46:33 -0700 | [diff] [blame] | 688 | static void scsi_handle_queue_ramp_up(struct scsi_device *sdev) |
| 689 | { |
| 690 | struct scsi_host_template *sht = sdev->host->hostt; |
| 691 | struct scsi_device *tmp_sdev; |
| 692 | |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 693 | if (!sht->track_queue_depth || |
Vasu Dev | 4a84067 | 2009-10-22 15:46:33 -0700 | [diff] [blame] | 694 | sdev->queue_depth >= sdev->max_queue_depth) |
| 695 | return; |
| 696 | |
| 697 | if (time_before(jiffies, |
| 698 | sdev->last_queue_ramp_up + sdev->queue_ramp_up_period)) |
| 699 | return; |
| 700 | |
| 701 | if (time_before(jiffies, |
| 702 | sdev->last_queue_full_time + sdev->queue_ramp_up_period)) |
| 703 | return; |
| 704 | |
| 705 | /* |
| 706 | * Walk all devices of a target and do |
| 707 | * ramp up on them. |
| 708 | */ |
| 709 | shost_for_each_device(tmp_sdev, sdev->host) { |
| 710 | if (tmp_sdev->channel != sdev->channel || |
| 711 | tmp_sdev->id != sdev->id || |
| 712 | tmp_sdev->queue_depth == sdev->max_queue_depth) |
| 713 | continue; |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 714 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 715 | scsi_change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1); |
Vasu Dev | 4a84067 | 2009-10-22 15:46:33 -0700 | [diff] [blame] | 716 | sdev->last_queue_ramp_up = jiffies; |
| 717 | } |
| 718 | } |
| 719 | |
Mike Christie | 42a6a91 | 2009-10-15 17:46:44 -0700 | [diff] [blame] | 720 | static void scsi_handle_queue_full(struct scsi_device *sdev) |
| 721 | { |
| 722 | struct scsi_host_template *sht = sdev->host->hostt; |
| 723 | struct scsi_device *tmp_sdev; |
| 724 | |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 725 | if (!sht->track_queue_depth) |
Mike Christie | 42a6a91 | 2009-10-15 17:46:44 -0700 | [diff] [blame] | 726 | return; |
| 727 | |
| 728 | shost_for_each_device(tmp_sdev, sdev->host) { |
| 729 | if (tmp_sdev->channel != sdev->channel || |
| 730 | tmp_sdev->id != sdev->id) |
| 731 | continue; |
| 732 | /* |
| 733 | * We do not know the number of commands that were at |
| 734 | * the device when we got the queue full so we start |
| 735 | * from the highest possible value and work our way down. |
| 736 | */ |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 737 | scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1); |
Mike Christie | 42a6a91 | 2009-10-15 17:46:44 -0700 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | /** |
| 742 | * scsi_eh_completed_normally - Disposition a eh cmd on return from LLD. |
| 743 | * @scmd: SCSI cmd to examine. |
| 744 | * |
| 745 | * Notes: |
| 746 | * This is *only* called when we are examining the status of commands |
| 747 | * queued during error recovery. the main difference here is that we |
| 748 | * don't allow for the possibility of retries here, and we are a lot |
| 749 | * more restrictive about what we consider acceptable. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 750 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 751 | static enum scsi_disposition scsi_eh_completed_normally(struct scsi_cmnd *scmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | { |
| 753 | /* |
| 754 | * first check the host byte, to see if there is anything in there |
| 755 | * that would indicate what we need to do. |
| 756 | */ |
| 757 | if (host_byte(scmd->result) == DID_RESET) { |
| 758 | /* |
| 759 | * rats. we are already in the error handler, so we now |
| 760 | * get to try and figure out what to do next. if the sense |
| 761 | * is valid, we have a pretty good idea of what to do. |
| 762 | * if not, we mark it as FAILED. |
| 763 | */ |
| 764 | return scsi_check_sense(scmd); |
| 765 | } |
| 766 | if (host_byte(scmd->result) != DID_OK) |
| 767 | return FAILED; |
| 768 | |
| 769 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | * now, check the status byte to see if this indicates |
| 771 | * anything special. |
| 772 | */ |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 773 | switch (get_status_byte(scmd)) { |
| 774 | case SAM_STAT_GOOD: |
Vasu Dev | 4a84067 | 2009-10-22 15:46:33 -0700 | [diff] [blame] | 775 | scsi_handle_queue_ramp_up(scmd->device); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 776 | fallthrough; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 777 | case SAM_STAT_COMMAND_TERMINATED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | return SUCCESS; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 779 | case SAM_STAT_CHECK_CONDITION: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | return scsi_check_sense(scmd); |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 781 | case SAM_STAT_CONDITION_MET: |
| 782 | case SAM_STAT_INTERMEDIATE: |
| 783 | case SAM_STAT_INTERMEDIATE_CONDITION_MET: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | /* |
| 785 | * who knows? FIXME(eric) |
| 786 | */ |
| 787 | return SUCCESS; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 788 | case SAM_STAT_RESERVATION_CONFLICT: |
James Bottomley | 67110df | 2010-08-06 15:17:24 -0500 | [diff] [blame] | 789 | if (scmd->cmnd[0] == TEST_UNIT_READY) |
| 790 | /* it is a success, we probed the device and |
| 791 | * found it */ |
| 792 | return SUCCESS; |
| 793 | /* otherwise, we failed to send the command */ |
| 794 | return FAILED; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 795 | case SAM_STAT_TASK_SET_FULL: |
Mike Christie | 42a6a91 | 2009-10-15 17:46:44 -0700 | [diff] [blame] | 796 | scsi_handle_queue_full(scmd->device); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 797 | fallthrough; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 798 | case SAM_STAT_BUSY: |
Hannes Reinecke | 3eb3a92 | 2010-07-29 10:10:16 +0200 | [diff] [blame] | 799 | return NEEDS_RETRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | default: |
| 801 | return FAILED; |
| 802 | } |
| 803 | return FAILED; |
| 804 | } |
| 805 | |
| 806 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | * scsi_eh_done - Completion function for error handling. |
| 808 | * @scmd: Cmd that is done. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 809 | */ |
Bart Van Assche | bf23e61 | 2021-10-07 13:27:56 -0700 | [diff] [blame] | 810 | void scsi_eh_done(struct scsi_cmnd *scmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | { |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 812 | struct completion *eh_action; |
Michael Reed | 8563167 | 2005-12-07 21:46:27 -0600 | [diff] [blame] | 813 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 814 | SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, |
Hannes Reinecke | 470613b | 2015-01-08 07:43:50 +0100 | [diff] [blame] | 815 | "%s result: %x\n", __func__, scmd->result)); |
Michael Reed | 8563167 | 2005-12-07 21:46:27 -0600 | [diff] [blame] | 816 | |
| 817 | eh_action = scmd->device->host->eh_action; |
| 818 | if (eh_action) |
| 819 | complete(eh_action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | /** |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 823 | * scsi_try_host_reset - ask host adapter to reset itself |
Geert Uytterhoeven | c2b3ebd | 2013-05-17 13:22:29 +0200 | [diff] [blame] | 824 | * @scmd: SCSI cmd to send host reset. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 825 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 826 | static enum scsi_disposition scsi_try_host_reset(struct scsi_cmnd *scmd) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 827 | { |
| 828 | unsigned long flags; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 829 | enum scsi_disposition rtn; |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 830 | struct Scsi_Host *host = scmd->device->host; |
| 831 | struct scsi_host_template *hostt = host->hostt; |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 832 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 833 | SCSI_LOG_ERROR_RECOVERY(3, |
| 834 | shost_printk(KERN_INFO, host, "Snd Host RST\n")); |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 835 | |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 836 | if (!hostt->eh_host_reset_handler) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 837 | return FAILED; |
| 838 | |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 839 | rtn = hostt->eh_host_reset_handler(scmd); |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 840 | |
| 841 | if (rtn == SUCCESS) { |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 842 | if (!hostt->skip_settle_delay) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 843 | ssleep(HOST_RESET_SETTLE_TIME); |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 844 | spin_lock_irqsave(host->host_lock, flags); |
| 845 | scsi_report_bus_reset(host, scmd_channel(scmd)); |
| 846 | spin_unlock_irqrestore(host->host_lock, flags); |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | return rtn; |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * scsi_try_bus_reset - ask host to perform a bus reset |
| 854 | * @scmd: SCSI cmd to send bus reset. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 855 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 856 | static enum scsi_disposition scsi_try_bus_reset(struct scsi_cmnd *scmd) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 857 | { |
| 858 | unsigned long flags; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 859 | enum scsi_disposition rtn; |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 860 | struct Scsi_Host *host = scmd->device->host; |
| 861 | struct scsi_host_template *hostt = host->hostt; |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 862 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 863 | SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, |
| 864 | "%s: Snd Bus RST\n", __func__)); |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 865 | |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 866 | if (!hostt->eh_bus_reset_handler) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 867 | return FAILED; |
| 868 | |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 869 | rtn = hostt->eh_bus_reset_handler(scmd); |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 870 | |
| 871 | if (rtn == SUCCESS) { |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 872 | if (!hostt->skip_settle_delay) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 873 | ssleep(BUS_RESET_SETTLE_TIME); |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 874 | spin_lock_irqsave(host->host_lock, flags); |
| 875 | scsi_report_bus_reset(host, scmd_channel(scmd)); |
| 876 | spin_unlock_irqrestore(host->host_lock, flags); |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | return rtn; |
| 880 | } |
| 881 | |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 882 | static void __scsi_report_device_reset(struct scsi_device *sdev, void *data) |
| 883 | { |
| 884 | sdev->was_reset = 1; |
| 885 | sdev->expecting_cc_ua = 1; |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * scsi_try_target_reset - Ask host to perform a target reset |
| 890 | * @scmd: SCSI cmd used to send a target reset |
| 891 | * |
| 892 | * Notes: |
| 893 | * There is no timeout for this operation. if this operation is |
| 894 | * unreliable for a given host, then the host itself needs to put a |
| 895 | * timer on it, and set the host back to a consistent state prior to |
| 896 | * returning. |
| 897 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 898 | static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd) |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 899 | { |
| 900 | unsigned long flags; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 901 | enum scsi_disposition rtn; |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 902 | struct Scsi_Host *host = scmd->device->host; |
| 903 | struct scsi_host_template *hostt = host->hostt; |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 904 | |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 905 | if (!hostt->eh_target_reset_handler) |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 906 | return FAILED; |
| 907 | |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 908 | rtn = hostt->eh_target_reset_handler(scmd); |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 909 | if (rtn == SUCCESS) { |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 910 | spin_lock_irqsave(host->host_lock, flags); |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 911 | __starget_for_each_device(scsi_target(scmd->device), NULL, |
| 912 | __scsi_report_device_reset); |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 913 | spin_unlock_irqrestore(host->host_lock, flags); |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | return rtn; |
| 917 | } |
| 918 | |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 919 | /** |
| 920 | * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev |
| 921 | * @scmd: SCSI cmd used to send BDR |
| 922 | * |
| 923 | * Notes: |
| 924 | * There is no timeout for this operation. if this operation is |
| 925 | * unreliable for a given host, then the host itself needs to put a |
| 926 | * timer on it, and set the host back to a consistent state prior to |
| 927 | * returning. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 928 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 929 | static enum scsi_disposition scsi_try_bus_device_reset(struct scsi_cmnd *scmd) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 930 | { |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 931 | enum scsi_disposition rtn; |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 932 | struct scsi_host_template *hostt = scmd->device->host->hostt; |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 933 | |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 934 | if (!hostt->eh_device_reset_handler) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 935 | return FAILED; |
| 936 | |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 937 | rtn = hostt->eh_device_reset_handler(scmd); |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 938 | if (rtn == SUCCESS) |
| 939 | __scsi_report_device_reset(scmd->device, NULL); |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 940 | return rtn; |
| 941 | } |
| 942 | |
Hannes Reinecke | 883a030 | 2014-10-24 14:27:04 +0200 | [diff] [blame] | 943 | /** |
| 944 | * scsi_try_to_abort_cmd - Ask host to abort a SCSI command |
Randy Dunlap | 6583f6f | 2014-12-29 09:40:56 -0800 | [diff] [blame] | 945 | * @hostt: SCSI driver host template |
Hannes Reinecke | 883a030 | 2014-10-24 14:27:04 +0200 | [diff] [blame] | 946 | * @scmd: SCSI cmd used to send a target reset |
| 947 | * |
| 948 | * Return value: |
| 949 | * SUCCESS, FAILED, or FAST_IO_FAIL |
| 950 | * |
| 951 | * Notes: |
| 952 | * SUCCESS does not necessarily indicate that the command |
| 953 | * has been aborted; it only indicates that the LLDDs |
| 954 | * has cleared all references to that command. |
| 955 | * LLDDs should return FAILED only if an abort was required |
| 956 | * but could not be executed. LLDDs should return FAST_IO_FAIL |
| 957 | * if the device is temporarily unavailable (eg due to a |
| 958 | * link down on FibreChannel) |
| 959 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 960 | static enum scsi_disposition |
| 961 | scsi_try_to_abort_cmd(struct scsi_host_template *hostt, struct scsi_cmnd *scmd) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 962 | { |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 963 | if (!hostt->eh_abort_handler) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 964 | return FAILED; |
| 965 | |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 966 | return hostt->eh_abort_handler(scmd); |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 967 | } |
| 968 | |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 969 | static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd) |
| 970 | { |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 971 | if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS) |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 972 | if (scsi_try_bus_device_reset(scmd) != SUCCESS) |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 973 | if (scsi_try_target_reset(scmd) != SUCCESS) |
| 974 | if (scsi_try_bus_reset(scmd) != SUCCESS) |
| 975 | scsi_try_host_reset(scmd); |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | /** |
Santosh Y | 3b729f7 | 2012-04-08 18:47:09 +0530 | [diff] [blame] | 979 | * scsi_eh_prep_cmnd - Save a scsi command info as part of error recovery |
Christoph Hellwig | 2dc611d | 2006-11-04 20:04:21 +0100 | [diff] [blame] | 980 | * @scmd: SCSI command structure to hijack |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 981 | * @ses: structure to save restore information |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 982 | * @cmnd: CDB to send. Can be NULL if no new cmnd is needed |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 983 | * @cmnd_size: size in bytes of @cmnd (must be <= BLK_MAX_CDB) |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 984 | * @sense_bytes: size of sense data to copy. or 0 (if != 0 @cmnd is ignored) |
Christoph Hellwig | 2dc611d | 2006-11-04 20:04:21 +0100 | [diff] [blame] | 985 | * |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 986 | * This function is used to save a scsi command information before re-execution |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 987 | * as part of the error recovery process. If @sense_bytes is 0 the command |
| 988 | * sent must be one that does not transfer any data. If @sense_bytes != 0 |
| 989 | * @cmnd is ignored and this functions sets up a REQUEST_SENSE command |
| 990 | * and cmnd buffers to read @sense_bytes into @scmd->sense_buffer. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 991 | */ |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 992 | void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses, |
| 993 | unsigned char *cmnd, int cmnd_size, unsigned sense_bytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | { |
| f59114b | 2005-04-17 15:00:23 -0500 | [diff] [blame] | 995 | struct scsi_device *sdev = scmd->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 997 | /* |
| 998 | * We need saved copies of a number of fields - this is because |
| 999 | * error handling may need to overwrite these with different values |
| 1000 | * to run different commands, and once error handling is complete, |
| 1001 | * we will need to restore these values prior to running the actual |
| 1002 | * command. |
| 1003 | */ |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1004 | ses->cmd_len = scmd->cmd_len; |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 1005 | ses->cmnd = scmd->cmnd; |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1006 | ses->data_direction = scmd->sc_data_direction; |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 1007 | ses->sdb = scmd->sdb; |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1008 | ses->result = scmd->result; |
Damien Le Moal | 8f8fed0 | 2019-10-01 16:48:39 +0900 | [diff] [blame] | 1009 | ses->resid_len = scmd->req.resid_len; |
Alan Stern | 1226570 | 2008-07-21 10:25:52 -0400 | [diff] [blame] | 1010 | ses->underflow = scmd->underflow; |
Martin K. Petersen | db007fc | 2008-07-17 04:28:31 -0400 | [diff] [blame] | 1011 | ses->prot_op = scmd->prot_op; |
Hannes Reinecke | 8e8c9d0 | 2017-04-06 15:36:33 +0200 | [diff] [blame] | 1012 | ses->eh_eflags = scmd->eh_eflags; |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1013 | |
Martin K. Petersen | db007fc | 2008-07-17 04:28:31 -0400 | [diff] [blame] | 1014 | scmd->prot_op = SCSI_PROT_NORMAL; |
James Bottomley | c69e6f8 | 2014-04-10 13:36:11 -0700 | [diff] [blame] | 1015 | scmd->eh_eflags = 0; |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 1016 | scmd->cmnd = ses->eh_cmnd; |
| 1017 | memset(scmd->cmnd, 0, BLK_MAX_CDB); |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 1018 | memset(&scmd->sdb, 0, sizeof(scmd->sdb)); |
Alan Stern | 644373a | 2014-03-28 10:51:15 -0700 | [diff] [blame] | 1019 | scmd->result = 0; |
Damien Le Moal | 8f8fed0 | 2019-10-01 16:48:39 +0900 | [diff] [blame] | 1020 | scmd->req.resid_len = 0; |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 1021 | |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 1022 | if (sense_bytes) { |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 1023 | scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE, |
| 1024 | sense_bytes); |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1025 | sg_init_one(&ses->sense_sgl, scmd->sense_buffer, |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 1026 | scmd->sdb.length); |
| 1027 | scmd->sdb.table.sgl = &ses->sense_sgl; |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 1028 | scmd->sc_data_direction = DMA_FROM_DEVICE; |
Tony Battersby | 0c958ec | 2015-07-16 11:40:41 -0400 | [diff] [blame] | 1029 | scmd->sdb.table.nents = scmd->sdb.table.orig_nents = 1; |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 1030 | scmd->cmnd[0] = REQUEST_SENSE; |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 1031 | scmd->cmnd[4] = scmd->sdb.length; |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 1032 | scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1033 | } else { |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1034 | scmd->sc_data_direction = DMA_NONE; |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 1035 | if (cmnd) { |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 1036 | BUG_ON(cmnd_size > BLK_MAX_CDB); |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 1037 | memcpy(scmd->cmnd, cmnd, cmnd_size); |
| 1038 | scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); |
| 1039 | } |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | scmd->underflow = 0; |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1043 | |
Boaz Harrosh | 55db6c1 | 2007-10-08 16:35:19 +0200 | [diff] [blame] | 1044 | if (sdev->scsi_level <= SCSI_2 && sdev->scsi_level != SCSI_UNKNOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) | |
| f59114b | 2005-04-17 15:00:23 -0500 | [diff] [blame] | 1046 | (sdev->lun << 5 & 0xe0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1048 | /* |
| 1049 | * Zero the sense buffer. The scsi spec mandates that any |
| 1050 | * untransferred sense data should be interpreted as being zero. |
| 1051 | */ |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 1052 | memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1053 | } |
| 1054 | EXPORT_SYMBOL(scsi_eh_prep_cmnd); |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1055 | |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1056 | /** |
Santosh Y | 3b729f7 | 2012-04-08 18:47:09 +0530 | [diff] [blame] | 1057 | * scsi_eh_restore_cmnd - Restore a scsi command info as part of error recovery |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1058 | * @scmd: SCSI command structure to restore |
Bartlomiej Zolnierkiewicz | 477e608 | 2009-04-27 20:54:22 +0200 | [diff] [blame] | 1059 | * @ses: saved information from a coresponding call to scsi_eh_prep_cmnd |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1060 | * |
Bartlomiej Zolnierkiewicz | 477e608 | 2009-04-27 20:54:22 +0200 | [diff] [blame] | 1061 | * Undo any damage done by above scsi_eh_prep_cmnd(). |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1062 | */ |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1063 | void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct scsi_eh_save *ses) |
| 1064 | { |
| 1065 | /* |
| 1066 | * Restore original data |
| 1067 | */ |
| 1068 | scmd->cmd_len = ses->cmd_len; |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 1069 | scmd->cmnd = ses->cmnd; |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1070 | scmd->sc_data_direction = ses->data_direction; |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 1071 | scmd->sdb = ses->sdb; |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1072 | scmd->result = ses->result; |
Damien Le Moal | 8f8fed0 | 2019-10-01 16:48:39 +0900 | [diff] [blame] | 1073 | scmd->req.resid_len = ses->resid_len; |
Alan Stern | 1226570 | 2008-07-21 10:25:52 -0400 | [diff] [blame] | 1074 | scmd->underflow = ses->underflow; |
Martin K. Petersen | db007fc | 2008-07-17 04:28:31 -0400 | [diff] [blame] | 1075 | scmd->prot_op = ses->prot_op; |
Hannes Reinecke | 8e8c9d0 | 2017-04-06 15:36:33 +0200 | [diff] [blame] | 1076 | scmd->eh_eflags = ses->eh_eflags; |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1077 | } |
| 1078 | EXPORT_SYMBOL(scsi_eh_restore_cmnd); |
| 1079 | |
| 1080 | /** |
Santosh Y | 3b729f7 | 2012-04-08 18:47:09 +0530 | [diff] [blame] | 1081 | * scsi_send_eh_cmnd - submit a scsi command as part of error recovery |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1082 | * @scmd: SCSI command structure to hijack |
| 1083 | * @cmnd: CDB to send |
| 1084 | * @cmnd_size: size in bytes of @cmnd |
| 1085 | * @timeout: timeout for this request |
| 1086 | * @sense_bytes: size of sense data to copy or 0 |
| 1087 | * |
| 1088 | * This function is used to send a scsi command down to a target device |
| 1089 | * as part of the error recovery process. See also scsi_eh_prep_cmnd() above. |
| 1090 | * |
| 1091 | * Return value: |
| 1092 | * SUCCESS or FAILED or NEEDS_RETRY |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1093 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1094 | static enum scsi_disposition scsi_send_eh_cmnd(struct scsi_cmnd *scmd, |
| 1095 | unsigned char *cmnd, int cmnd_size, int timeout, unsigned sense_bytes) |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1096 | { |
| 1097 | struct scsi_device *sdev = scmd->device; |
| 1098 | struct Scsi_Host *shost = sdev->host; |
| 1099 | DECLARE_COMPLETION_ONSTACK(done); |
Bart Van Assche | bbe9fb0 | 2019-06-17 08:18:19 -0700 | [diff] [blame] | 1100 | unsigned long timeleft = timeout, delay; |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1101 | struct scsi_eh_save ses; |
Hannes Reinecke | fc73648 | 2013-04-25 08:10:00 +0200 | [diff] [blame] | 1102 | const unsigned long stall_for = msecs_to_jiffies(100); |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1103 | int rtn; |
| 1104 | |
Hannes Reinecke | fc73648 | 2013-04-25 08:10:00 +0200 | [diff] [blame] | 1105 | retry: |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1106 | scsi_eh_prep_cmnd(scmd, &ses, cmnd, cmnd_size, sense_bytes); |
Christoph Hellwig | 7dfdc9a | 2005-10-31 18:49:52 +0100 | [diff] [blame] | 1107 | shost->eh_action = &done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | scsi_log_send(scmd); |
Bart Van Assche | bf23e61 | 2021-10-07 13:27:56 -0700 | [diff] [blame] | 1110 | scmd->submitter = SUBMITTED_BY_SCSI_ERROR_HANDLER; |
Bart Van Assche | bbe9fb0 | 2019-06-17 08:18:19 -0700 | [diff] [blame] | 1111 | |
| 1112 | /* |
| 1113 | * Lock sdev->state_mutex to avoid that scsi_device_quiesce() can |
| 1114 | * change the SCSI device state after we have examined it and before |
| 1115 | * .queuecommand() is called. |
| 1116 | */ |
| 1117 | mutex_lock(&sdev->state_mutex); |
| 1118 | while (sdev->sdev_state == SDEV_BLOCK && timeleft > 0) { |
| 1119 | mutex_unlock(&sdev->state_mutex); |
| 1120 | SCSI_LOG_ERROR_RECOVERY(5, sdev_printk(KERN_DEBUG, sdev, |
| 1121 | "%s: state %d <> %d\n", __func__, sdev->sdev_state, |
| 1122 | SDEV_BLOCK)); |
| 1123 | delay = min(timeleft, stall_for); |
| 1124 | timeleft -= delay; |
| 1125 | msleep(jiffies_to_msecs(delay)); |
| 1126 | mutex_lock(&sdev->state_mutex); |
| 1127 | } |
| 1128 | if (sdev->sdev_state != SDEV_BLOCK) |
| 1129 | rtn = shost->hostt->queuecommand(shost, scmd); |
| 1130 | else |
Bart Van Assche | 280e91b | 2021-04-15 15:08:10 -0700 | [diff] [blame] | 1131 | rtn = FAILED; |
Bart Van Assche | bbe9fb0 | 2019-06-17 08:18:19 -0700 | [diff] [blame] | 1132 | mutex_unlock(&sdev->state_mutex); |
| 1133 | |
Hannes Reinecke | fc73648 | 2013-04-25 08:10:00 +0200 | [diff] [blame] | 1134 | if (rtn) { |
| 1135 | if (timeleft > stall_for) { |
| 1136 | scsi_eh_restore_cmnd(scmd, &ses); |
Bart Van Assche | bf23e61 | 2021-10-07 13:27:56 -0700 | [diff] [blame] | 1137 | |
Hannes Reinecke | fc73648 | 2013-04-25 08:10:00 +0200 | [diff] [blame] | 1138 | timeleft -= stall_for; |
| 1139 | msleep(jiffies_to_msecs(stall_for)); |
| 1140 | goto retry; |
| 1141 | } |
| 1142 | /* signal not to enter either branch of the if () below */ |
| 1143 | timeleft = 0; |
Alan Stern | 511833a | 2014-11-21 10:44:49 -0500 | [diff] [blame] | 1144 | rtn = FAILED; |
Hannes Reinecke | fc73648 | 2013-04-25 08:10:00 +0200 | [diff] [blame] | 1145 | } else { |
| 1146 | timeleft = wait_for_completion_timeout(&done, timeout); |
Hannes Reinecke | ac61d19 | 2014-05-08 08:09:56 +0200 | [diff] [blame] | 1147 | rtn = SUCCESS; |
Hannes Reinecke | fc73648 | 2013-04-25 08:10:00 +0200 | [diff] [blame] | 1148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
| f59114b | 2005-04-17 15:00:23 -0500 | [diff] [blame] | 1150 | shost->eh_action = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
Hannes Reinecke | fc73648 | 2013-04-25 08:10:00 +0200 | [diff] [blame] | 1152 | scsi_log_completion(scmd, rtn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1154 | SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, |
Hannes Reinecke | 470613b | 2015-01-08 07:43:50 +0100 | [diff] [blame] | 1155 | "%s timeleft: %ld\n", |
| 1156 | __func__, timeleft)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
| 1158 | /* |
Hannes Reinecke | fc73648 | 2013-04-25 08:10:00 +0200 | [diff] [blame] | 1159 | * If there is time left scsi_eh_done got called, and we will examine |
| 1160 | * the actual status codes to see whether the command actually did |
| 1161 | * complete normally, else if we have a zero return and no time left, |
| 1162 | * the command must still be pending, so abort it and return FAILED. |
| 1163 | * If we never actually managed to issue the command, because |
| 1164 | * ->queuecommand() kept returning non zero, use the rtn = FAILED |
| 1165 | * value above (so don't execute either branch of the if) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | */ |
Christoph Hellwig | 7dfdc9a | 2005-10-31 18:49:52 +0100 | [diff] [blame] | 1167 | if (timeleft) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | rtn = scsi_eh_completed_normally(scmd); |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1169 | SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, |
| 1170 | "%s: scsi_eh_completed_normally %x\n", __func__, rtn)); |
Christoph Hellwig | 7dfdc9a | 2005-10-31 18:49:52 +0100 | [diff] [blame] | 1171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | switch (rtn) { |
| 1173 | case SUCCESS: |
| 1174 | case NEEDS_RETRY: |
| 1175 | case FAILED: |
| 1176 | break; |
Hannes Reinecke | 6e883b0 | 2009-09-17 17:00:26 +0200 | [diff] [blame] | 1177 | case ADD_TO_MLQUEUE: |
| 1178 | rtn = NEEDS_RETRY; |
| 1179 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | default: |
| 1181 | rtn = FAILED; |
| 1182 | break; |
| 1183 | } |
Alan Stern | 511833a | 2014-11-21 10:44:49 -0500 | [diff] [blame] | 1184 | } else if (rtn != FAILED) { |
Brian King | 292148f | 2007-01-30 17:51:17 -0600 | [diff] [blame] | 1185 | scsi_abort_eh_cmnd(scmd); |
Christoph Hellwig | 7dfdc9a | 2005-10-31 18:49:52 +0100 | [diff] [blame] | 1186 | rtn = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Boaz Harrosh | e1c2346 | 2007-10-08 16:36:45 +0200 | [diff] [blame] | 1189 | scsi_eh_restore_cmnd(scmd, &ses); |
Martin K. Petersen | 18a4d0a | 2012-02-09 13:48:53 -0500 | [diff] [blame] | 1190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | return rtn; |
| 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * scsi_request_sense - Request sense data from a particular target. |
| 1196 | * @scmd: SCSI cmd for request sense. |
| 1197 | * |
| 1198 | * Notes: |
| 1199 | * Some hosts automatically obtain this information, others require |
| 1200 | * that we obtain it on our own. This function will *not* return until |
| 1201 | * the command either times out, or it completes. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1202 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1203 | static enum scsi_disposition scsi_request_sense(struct scsi_cmnd *scmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | { |
Martin K. Petersen | 0816c92 | 2013-05-10 10:36:04 -0400 | [diff] [blame] | 1205 | return scsi_send_eh_cmnd(scmd, NULL, 0, scmd->device->eh_timeout, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1208 | static enum scsi_disposition |
| 1209 | scsi_eh_action(struct scsi_cmnd *scmd, enum scsi_disposition rtn) |
James Bottomley | 2451079 | 2013-11-11 13:44:53 +0100 | [diff] [blame] | 1210 | { |
Bart Van Assche | aa8e25e | 2021-08-09 16:03:05 -0700 | [diff] [blame] | 1211 | if (!blk_rq_is_passthrough(scsi_cmd_to_rq(scmd))) { |
James Bottomley | 2451079 | 2013-11-11 13:44:53 +0100 | [diff] [blame] | 1212 | struct scsi_driver *sdrv = scsi_cmd_to_driver(scmd); |
| 1213 | if (sdrv->eh_action) |
| 1214 | rtn = sdrv->eh_action(scmd, rtn); |
| 1215 | } |
| 1216 | return rtn; |
| 1217 | } |
| 1218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | /** |
| 1220 | * scsi_eh_finish_cmd - Handle a cmd that eh is finished with. |
| 1221 | * @scmd: Original SCSI cmd that eh has finished. |
| 1222 | * @done_q: Queue for processed commands. |
| 1223 | * |
| 1224 | * Notes: |
| 1225 | * We don't want to use the normal command completion while we are are |
| 1226 | * still handling errors - it may cause other commands to be queued, |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1227 | * and that would disturb what we are doing. Thus we really want to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | * keep a list of pending commands for final completion, and once we |
| 1229 | * are ready to leave error handling we handle completion for real. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1230 | */ |
Tejun Heo | 041c5fc | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1231 | void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | list_move_tail(&scmd->eh_entry, done_q); |
| 1234 | } |
Tejun Heo | 041c5fc | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1235 | EXPORT_SYMBOL(scsi_eh_finish_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
| 1237 | /** |
| 1238 | * scsi_eh_get_sense - Get device sense data. |
| 1239 | * @work_q: Queue of commands to process. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1240 | * @done_q: Queue of processed commands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | * |
| 1242 | * Description: |
| 1243 | * See if we need to request sense information. if so, then get it |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 1244 | * now, so we have a better idea of what to do. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | * |
| 1246 | * Notes: |
| 1247 | * This has the unfortunate side effect that if a shost adapter does |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1248 | * not automatically request sense information, we end up shutting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | * it down before we request it. |
| 1250 | * |
| 1251 | * All drivers should request sense information internally these days, |
| 1252 | * so for now all I have to say is tough noogies if you end up in here. |
| 1253 | * |
| 1254 | * XXX: Long term this code should go away, but that needs an audit of |
| 1255 | * all LLDDs first. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1256 | */ |
Darrick J. Wong | dca84e4 | 2007-01-26 14:08:49 -0800 | [diff] [blame] | 1257 | int scsi_eh_get_sense(struct list_head *work_q, |
| 1258 | struct list_head *done_q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1260 | struct scsi_cmnd *scmd, *next; |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1261 | struct Scsi_Host *shost; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1262 | enum scsi_disposition rtn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
jiang.biao2@zte.com.cn | 709c75b | 2015-07-31 17:52:10 +0800 | [diff] [blame] | 1264 | /* |
| 1265 | * If SCSI_EH_ABORT_SCHEDULED has been set, it is timeout IO, |
| 1266 | * should not get sense. |
| 1267 | */ |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1268 | list_for_each_entry_safe(scmd, next, work_q, eh_entry) { |
Hannes Reinecke | a065863 | 2017-04-06 15:36:35 +0200 | [diff] [blame] | 1269 | if ((scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | SCSI_SENSE_VALID(scmd)) |
| 1271 | continue; |
| 1272 | |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1273 | shost = scmd->device->host; |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1274 | if (scsi_host_eh_past_deadline(shost)) { |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1275 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1276 | scmd_printk(KERN_INFO, scmd, |
| 1277 | "%s: skip request sense, past eh deadline\n", |
| 1278 | current->comm)); |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1279 | break; |
| 1280 | } |
Hannes Reinecke | d0672a0 | 2021-04-27 10:30:14 +0200 | [diff] [blame] | 1281 | if (!scsi_status_is_check_condition(scmd->result)) |
James Bottomley | d555a2a | 2014-03-28 10:50:17 -0700 | [diff] [blame] | 1282 | /* |
| 1283 | * don't request sense if there's no check condition |
| 1284 | * status because the error we're processing isn't one |
| 1285 | * that has a sense code (and some devices get |
| 1286 | * confused by sense requests out of the blue) |
| 1287 | */ |
| 1288 | continue; |
| 1289 | |
Jeff Garzik | 3bf743e | 2005-10-24 18:04:06 -0400 | [diff] [blame] | 1290 | SCSI_LOG_ERROR_RECOVERY(2, scmd_printk(KERN_INFO, scmd, |
| 1291 | "%s: requesting sense\n", |
| 1292 | current->comm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | rtn = scsi_request_sense(scmd); |
| 1294 | if (rtn != SUCCESS) |
| 1295 | continue; |
| 1296 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1297 | SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, |
Hannes Reinecke | 470613b | 2015-01-08 07:43:50 +0100 | [diff] [blame] | 1298 | "sense requested, result %x\n", scmd->result)); |
Hannes Reinecke | d811b84 | 2014-10-24 14:26:45 +0200 | [diff] [blame] | 1299 | SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense(scmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
| 1301 | rtn = scsi_decide_disposition(scmd); |
| 1302 | |
| 1303 | /* |
| 1304 | * if the result was normal, then just pass it along to the |
| 1305 | * upper level. |
| 1306 | */ |
| 1307 | if (rtn == SUCCESS) |
Mike Christie | 2a242d5 | 2020-10-01 10:35:53 -0500 | [diff] [blame] | 1308 | /* |
| 1309 | * We don't want this command reissued, just finished |
| 1310 | * with the sense data, so set retries to the max |
| 1311 | * allowed to ensure it won't get reissued. If the user |
| 1312 | * has requested infinite retries, we also want to |
| 1313 | * finish this command, so force completion by setting |
| 1314 | * retries and allowed to the same value. |
| 1315 | */ |
| 1316 | if (scmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT) |
| 1317 | scmd->retries = scmd->allowed = 1; |
| 1318 | else |
| 1319 | scmd->retries = scmd->allowed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | else if (rtn != NEEDS_RETRY) |
| 1321 | continue; |
| 1322 | |
| 1323 | scsi_eh_finish_cmd(scmd, done_q); |
| 1324 | } |
| 1325 | |
| 1326 | return list_empty(work_q); |
| 1327 | } |
Darrick J. Wong | dca84e4 | 2007-01-26 14:08:49 -0800 | [diff] [blame] | 1328 | EXPORT_SYMBOL_GPL(scsi_eh_get_sense); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | |
| 1330 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | * scsi_eh_tur - Send TUR to device. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1332 | * @scmd: &scsi_cmnd to send TUR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | * |
| 1334 | * Return value: |
| 1335 | * 0 - Device is ready. 1 - Device NOT ready. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1336 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | static int scsi_eh_tur(struct scsi_cmnd *scmd) |
| 1338 | { |
| 1339 | static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0}; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1340 | int retry_cnt = 1; |
| 1341 | enum scsi_disposition rtn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
| 1343 | retry_tur: |
Martin K. Petersen | 0816c92 | 2013-05-10 10:36:04 -0400 | [diff] [blame] | 1344 | rtn = scsi_send_eh_cmnd(scmd, tur_command, 6, |
| 1345 | scmd->device->eh_timeout, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1347 | SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, |
Hannes Reinecke | 470613b | 2015-01-08 07:43:50 +0100 | [diff] [blame] | 1348 | "%s return: %x\n", __func__, rtn)); |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1349 | |
| 1350 | switch (rtn) { |
| 1351 | case NEEDS_RETRY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | if (retry_cnt--) |
| 1353 | goto retry_tur; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1354 | fallthrough; |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1355 | case SUCCESS: |
Alan Stern | e47373e | 2005-03-30 15:05:45 -0500 | [diff] [blame] | 1356 | return 0; |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1357 | default: |
| 1358 | return 1; |
Alan Stern | e47373e | 2005-03-30 15:05:45 -0500 | [diff] [blame] | 1359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | /** |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1363 | * scsi_eh_test_devices - check if devices are responding from error recovery. |
| 1364 | * @cmd_list: scsi commands in error recovery. |
Randy Dunlap | 74cf298 | 2014-08-16 14:15:11 -0700 | [diff] [blame] | 1365 | * @work_q: queue for commands which still need more error recovery |
| 1366 | * @done_q: queue for commands which are finished |
| 1367 | * @try_stu: boolean on if a STU command should be tried in addition to TUR. |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1368 | * |
| 1369 | * Decription: |
| 1370 | * Tests if devices are in a working state. Commands to devices now in |
| 1371 | * a working state are sent to the done_q while commands to devices which |
| 1372 | * are still failing to respond are returned to the work_q for more |
| 1373 | * processing. |
| 1374 | **/ |
| 1375 | static int scsi_eh_test_devices(struct list_head *cmd_list, |
| 1376 | struct list_head *work_q, |
| 1377 | struct list_head *done_q, int try_stu) |
| 1378 | { |
| 1379 | struct scsi_cmnd *scmd, *next; |
| 1380 | struct scsi_device *sdev; |
| 1381 | int finish_cmds; |
| 1382 | |
| 1383 | while (!list_empty(cmd_list)) { |
| 1384 | scmd = list_entry(cmd_list->next, struct scsi_cmnd, eh_entry); |
| 1385 | sdev = scmd->device; |
| 1386 | |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1387 | if (!try_stu) { |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1388 | if (scsi_host_eh_past_deadline(sdev->host)) { |
| 1389 | /* Push items back onto work_q */ |
| 1390 | list_splice_init(cmd_list, work_q); |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1391 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1392 | sdev_printk(KERN_INFO, sdev, |
| 1393 | "%s: skip test device, past eh deadline", |
| 1394 | current->comm)); |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1395 | break; |
| 1396 | } |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1397 | } |
| 1398 | |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1399 | finish_cmds = !scsi_device_online(scmd->device) || |
| 1400 | (try_stu && !scsi_eh_try_stu(scmd) && |
| 1401 | !scsi_eh_tur(scmd)) || |
| 1402 | !scsi_eh_tur(scmd); |
| 1403 | |
| 1404 | list_for_each_entry_safe(scmd, next, cmd_list, eh_entry) |
| 1405 | if (scmd->device == sdev) { |
James Bottomley | 2451079 | 2013-11-11 13:44:53 +0100 | [diff] [blame] | 1406 | if (finish_cmds && |
| 1407 | (try_stu || |
| 1408 | scsi_eh_action(scmd, SUCCESS) == SUCCESS)) |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1409 | scsi_eh_finish_cmd(scmd, done_q); |
| 1410 | else |
| 1411 | list_move_tail(&scmd->eh_entry, work_q); |
| 1412 | } |
| 1413 | } |
| 1414 | return list_empty(work_q); |
| 1415 | } |
| 1416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | * scsi_eh_try_stu - Send START_UNIT to device. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1419 | * @scmd: &scsi_cmnd to send START_UNIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | * |
| 1421 | * Return value: |
| 1422 | * 0 - Device is ready. 1 - Device NOT ready. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1423 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | static int scsi_eh_try_stu(struct scsi_cmnd *scmd) |
| 1425 | { |
| 1426 | static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1428 | if (scmd->device->allow_restart) { |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1429 | int i; |
| 1430 | enum scsi_disposition rtn = NEEDS_RETRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
Brian King | ed773e6 | 2007-03-29 15:25:52 -0500 | [diff] [blame] | 1432 | for (i = 0; rtn == NEEDS_RETRY && i < 2; i++) |
Chunguang Xu | adcc796 | 2021-11-10 09:23:32 +0800 | [diff] [blame] | 1433 | rtn = scsi_send_eh_cmnd(scmd, stu_command, 6, |
| 1434 | scmd->device->eh_timeout, 0); |
Brian King | ed773e6 | 2007-03-29 15:25:52 -0500 | [diff] [blame] | 1435 | |
Christoph Hellwig | 631c228 | 2006-07-08 20:42:15 +0200 | [diff] [blame] | 1436 | if (rtn == SUCCESS) |
| 1437 | return 0; |
| 1438 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | return 1; |
| 1441 | } |
| 1442 | |
| 1443 | /** |
| 1444 | * scsi_eh_stu - send START_UNIT if needed |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1445 | * @shost: &scsi host being recovered. |
Randy Dunlap | 74cf298 | 2014-08-16 14:15:11 -0700 | [diff] [blame] | 1446 | * @work_q: &list_head for pending commands. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1447 | * @done_q: &list_head for processed commands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | * |
| 1449 | * Notes: |
| 1450 | * If commands are failing due to not ready, initializing command required, |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 1451 | * try revalidating the device, which will end up sending a start unit. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1452 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | static int scsi_eh_stu(struct Scsi_Host *shost, |
| 1454 | struct list_head *work_q, |
| 1455 | struct list_head *done_q) |
| 1456 | { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1457 | struct scsi_cmnd *scmd, *stu_scmd, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | struct scsi_device *sdev; |
| 1459 | |
| 1460 | shost_for_each_device(sdev, shost) { |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1461 | if (scsi_host_eh_past_deadline(shost)) { |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1462 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1463 | sdev_printk(KERN_INFO, sdev, |
| 1464 | "%s: skip START_UNIT, past eh deadline\n", |
| 1465 | current->comm)); |
Ye Bin | 4dea170 | 2020-05-18 15:44:20 +0800 | [diff] [blame] | 1466 | scsi_device_put(sdev); |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1467 | break; |
| 1468 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | stu_scmd = NULL; |
| 1470 | list_for_each_entry(scmd, work_q, eh_entry) |
| 1471 | if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) && |
| 1472 | scsi_check_sense(scmd) == FAILED ) { |
| 1473 | stu_scmd = scmd; |
| 1474 | break; |
| 1475 | } |
| 1476 | |
| 1477 | if (!stu_scmd) |
| 1478 | continue; |
| 1479 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1480 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1481 | sdev_printk(KERN_INFO, sdev, |
| 1482 | "%s: Sending START_UNIT\n", |
| 1483 | current->comm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | |
| 1485 | if (!scsi_eh_try_stu(stu_scmd)) { |
| 1486 | if (!scsi_device_online(sdev) || |
| 1487 | !scsi_eh_tur(stu_scmd)) { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1488 | list_for_each_entry_safe(scmd, next, |
| 1489 | work_q, eh_entry) { |
James Bottomley | 2451079 | 2013-11-11 13:44:53 +0100 | [diff] [blame] | 1490 | if (scmd->device == sdev && |
| 1491 | scsi_eh_action(scmd, SUCCESS) == SUCCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | scsi_eh_finish_cmd(scmd, done_q); |
| 1493 | } |
| 1494 | } |
| 1495 | } else { |
| 1496 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1497 | sdev_printk(KERN_INFO, sdev, |
| 1498 | "%s: START_UNIT failed\n", |
| 1499 | current->comm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | return list_empty(work_q); |
| 1504 | } |
| 1505 | |
| 1506 | |
| 1507 | /** |
| 1508 | * scsi_eh_bus_device_reset - send bdr if needed |
| 1509 | * @shost: scsi host being recovered. |
Randy Dunlap | 74cf298 | 2014-08-16 14:15:11 -0700 | [diff] [blame] | 1510 | * @work_q: &list_head for pending commands. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1511 | * @done_q: &list_head for processed commands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | * |
| 1513 | * Notes: |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1514 | * Try a bus device reset. Still, look to see whether we have multiple |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | * devices that are jammed or not - if we have multiple devices, it |
| 1516 | * makes no sense to try bus_device_reset - we really would need to try |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 1517 | * a bus_reset instead. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1518 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, |
| 1520 | struct list_head *work_q, |
| 1521 | struct list_head *done_q) |
| 1522 | { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1523 | struct scsi_cmnd *scmd, *bdr_scmd, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | struct scsi_device *sdev; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1525 | enum scsi_disposition rtn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | |
| 1527 | shost_for_each_device(sdev, shost) { |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1528 | if (scsi_host_eh_past_deadline(shost)) { |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1529 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1530 | sdev_printk(KERN_INFO, sdev, |
| 1531 | "%s: skip BDR, past eh deadline\n", |
| 1532 | current->comm)); |
Ye Bin | 4dea170 | 2020-05-18 15:44:20 +0800 | [diff] [blame] | 1533 | scsi_device_put(sdev); |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1534 | break; |
| 1535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | bdr_scmd = NULL; |
| 1537 | list_for_each_entry(scmd, work_q, eh_entry) |
| 1538 | if (scmd->device == sdev) { |
| 1539 | bdr_scmd = scmd; |
| 1540 | break; |
| 1541 | } |
| 1542 | |
| 1543 | if (!bdr_scmd) |
| 1544 | continue; |
| 1545 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1546 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1547 | sdev_printk(KERN_INFO, sdev, |
| 1548 | "%s: Sending BDR\n", current->comm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | rtn = scsi_try_bus_device_reset(bdr_scmd); |
Christof Schmitt | 2f2eb58 | 2010-03-24 16:50:30 +0100 | [diff] [blame] | 1550 | if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | if (!scsi_device_online(sdev) || |
Christof Schmitt | 2f2eb58 | 2010-03-24 16:50:30 +0100 | [diff] [blame] | 1552 | rtn == FAST_IO_FAIL || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | !scsi_eh_tur(bdr_scmd)) { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1554 | list_for_each_entry_safe(scmd, next, |
| 1555 | work_q, eh_entry) { |
James Bottomley | 2451079 | 2013-11-11 13:44:53 +0100 | [diff] [blame] | 1556 | if (scmd->device == sdev && |
| 1557 | scsi_eh_action(scmd, rtn) != FAILED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | scsi_eh_finish_cmd(scmd, |
| 1559 | done_q); |
| 1560 | } |
| 1561 | } |
| 1562 | } else { |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1563 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1564 | sdev_printk(KERN_INFO, sdev, |
| 1565 | "%s: BDR failed\n", current->comm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | return list_empty(work_q); |
| 1570 | } |
| 1571 | |
| 1572 | /** |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 1573 | * scsi_eh_target_reset - send target reset if needed |
| 1574 | * @shost: scsi host being recovered. |
Randy Dunlap | 74cf298 | 2014-08-16 14:15:11 -0700 | [diff] [blame] | 1575 | * @work_q: &list_head for pending commands. |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 1576 | * @done_q: &list_head for processed commands. |
| 1577 | * |
| 1578 | * Notes: |
| 1579 | * Try a target reset. |
| 1580 | */ |
| 1581 | static int scsi_eh_target_reset(struct Scsi_Host *shost, |
| 1582 | struct list_head *work_q, |
| 1583 | struct list_head *done_q) |
| 1584 | { |
James Bottomley | 98db519 | 2010-10-25 15:53:41 -0500 | [diff] [blame] | 1585 | LIST_HEAD(tmp_list); |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1586 | LIST_HEAD(check_list); |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 1587 | |
James Bottomley | 98db519 | 2010-10-25 15:53:41 -0500 | [diff] [blame] | 1588 | list_splice_init(work_q, &tmp_list); |
| 1589 | |
| 1590 | while (!list_empty(&tmp_list)) { |
| 1591 | struct scsi_cmnd *next, *scmd; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1592 | enum scsi_disposition rtn; |
James Bottomley | 98db519 | 2010-10-25 15:53:41 -0500 | [diff] [blame] | 1593 | unsigned int id; |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1594 | |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1595 | if (scsi_host_eh_past_deadline(shost)) { |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1596 | /* push back on work queue for further processing */ |
| 1597 | list_splice_init(&check_list, work_q); |
| 1598 | list_splice_init(&tmp_list, work_q); |
| 1599 | SCSI_LOG_ERROR_RECOVERY(3, |
| 1600 | shost_printk(KERN_INFO, shost, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1601 | "%s: Skip target reset, past eh deadline\n", |
| 1602 | current->comm)); |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1603 | return list_empty(work_q); |
| 1604 | } |
James Bottomley | 98db519 | 2010-10-25 15:53:41 -0500 | [diff] [blame] | 1605 | |
| 1606 | scmd = list_entry(tmp_list.next, struct scsi_cmnd, eh_entry); |
| 1607 | id = scmd_id(scmd); |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 1608 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1609 | SCSI_LOG_ERROR_RECOVERY(3, |
| 1610 | shost_printk(KERN_INFO, shost, |
| 1611 | "%s: Sending target reset to target %d\n", |
| 1612 | current->comm, id)); |
James Bottomley | 98db519 | 2010-10-25 15:53:41 -0500 | [diff] [blame] | 1613 | rtn = scsi_try_target_reset(scmd); |
| 1614 | if (rtn != SUCCESS && rtn != FAST_IO_FAIL) |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1615 | SCSI_LOG_ERROR_RECOVERY(3, |
| 1616 | shost_printk(KERN_INFO, shost, |
| 1617 | "%s: Target reset failed" |
| 1618 | " target: %d\n", |
| 1619 | current->comm, id)); |
James Bottomley | 98db519 | 2010-10-25 15:53:41 -0500 | [diff] [blame] | 1620 | list_for_each_entry_safe(scmd, next, &tmp_list, eh_entry) { |
| 1621 | if (scmd_id(scmd) != id) |
| 1622 | continue; |
| 1623 | |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1624 | if (rtn == SUCCESS) |
| 1625 | list_move_tail(&scmd->eh_entry, &check_list); |
| 1626 | else if (rtn == FAST_IO_FAIL) |
James Bottomley | 98db519 | 2010-10-25 15:53:41 -0500 | [diff] [blame] | 1627 | scsi_eh_finish_cmd(scmd, done_q); |
| 1628 | else |
| 1629 | /* push back on work queue for further processing */ |
| 1630 | list_move(&scmd->eh_entry, work_q); |
| 1631 | } |
| 1632 | } |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 1633 | |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1634 | return scsi_eh_test_devices(&check_list, work_q, done_q, 0); |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | /** |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 1638 | * scsi_eh_bus_reset - send a bus reset |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1639 | * @shost: &scsi host being recovered. |
Randy Dunlap | 74cf298 | 2014-08-16 14:15:11 -0700 | [diff] [blame] | 1640 | * @work_q: &list_head for pending commands. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1641 | * @done_q: &list_head for processed commands. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1642 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | static int scsi_eh_bus_reset(struct Scsi_Host *shost, |
| 1644 | struct list_head *work_q, |
| 1645 | struct list_head *done_q) |
| 1646 | { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1647 | struct scsi_cmnd *scmd, *chan_scmd, *next; |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1648 | LIST_HEAD(check_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | unsigned int channel; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1650 | enum scsi_disposition rtn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
| 1652 | /* |
| 1653 | * we really want to loop over the various channels, and do this on |
| 1654 | * a channel by channel basis. we should also check to see if any |
| 1655 | * of the failed commands are on soft_reset devices, and if so, skip |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 1656 | * the reset. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | */ |
| 1658 | |
| 1659 | for (channel = 0; channel <= shost->max_channel; channel++) { |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1660 | if (scsi_host_eh_past_deadline(shost)) { |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1661 | list_splice_init(&check_list, work_q); |
| 1662 | SCSI_LOG_ERROR_RECOVERY(3, |
| 1663 | shost_printk(KERN_INFO, shost, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 1664 | "%s: skip BRST, past eh deadline\n", |
| 1665 | current->comm)); |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1666 | return list_empty(work_q); |
| 1667 | } |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 1668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | chan_scmd = NULL; |
| 1670 | list_for_each_entry(scmd, work_q, eh_entry) { |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 1671 | if (channel == scmd_channel(scmd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | chan_scmd = scmd; |
| 1673 | break; |
| 1674 | /* |
| 1675 | * FIXME add back in some support for |
| 1676 | * soft_reset devices. |
| 1677 | */ |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | if (!chan_scmd) |
| 1682 | continue; |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1683 | SCSI_LOG_ERROR_RECOVERY(3, |
| 1684 | shost_printk(KERN_INFO, shost, |
| 1685 | "%s: Sending BRST chan: %d\n", |
| 1686 | current->comm, channel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | rtn = scsi_try_bus_reset(chan_scmd); |
Christof Schmitt | 2f2eb58 | 2010-03-24 16:50:30 +0100 | [diff] [blame] | 1688 | if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1689 | list_for_each_entry_safe(scmd, next, work_q, eh_entry) { |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1690 | if (channel == scmd_channel(scmd)) { |
| 1691 | if (rtn == FAST_IO_FAIL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | scsi_eh_finish_cmd(scmd, |
| 1693 | done_q); |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1694 | else |
| 1695 | list_move_tail(&scmd->eh_entry, |
| 1696 | &check_list); |
| 1697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | } |
| 1699 | } else { |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1700 | SCSI_LOG_ERROR_RECOVERY(3, |
| 1701 | shost_printk(KERN_INFO, shost, |
| 1702 | "%s: BRST failed chan: %d\n", |
| 1703 | current->comm, channel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | } |
| 1705 | } |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1706 | return scsi_eh_test_devices(&check_list, work_q, done_q, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | /** |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 1710 | * scsi_eh_host_reset - send a host reset |
Randy Dunlap | 74cf298 | 2014-08-16 14:15:11 -0700 | [diff] [blame] | 1711 | * @shost: host to be reset. |
| 1712 | * @work_q: &list_head for pending commands. |
| 1713 | * @done_q: &list_head for processed commands. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1714 | */ |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1715 | static int scsi_eh_host_reset(struct Scsi_Host *shost, |
| 1716 | struct list_head *work_q, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | struct list_head *done_q) |
| 1718 | { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1719 | struct scsi_cmnd *scmd, *next; |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1720 | LIST_HEAD(check_list); |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1721 | enum scsi_disposition rtn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | |
| 1723 | if (!list_empty(work_q)) { |
| 1724 | scmd = list_entry(work_q->next, |
| 1725 | struct scsi_cmnd, eh_entry); |
| 1726 | |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1727 | SCSI_LOG_ERROR_RECOVERY(3, |
| 1728 | shost_printk(KERN_INFO, shost, |
| 1729 | "%s: Sending HRST\n", |
| 1730 | current->comm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | |
| 1732 | rtn = scsi_try_host_reset(scmd); |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1733 | if (rtn == SUCCESS) { |
| 1734 | list_splice_init(work_q, &check_list); |
| 1735 | } else if (rtn == FAST_IO_FAIL) { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1736 | list_for_each_entry_safe(scmd, next, work_q, eh_entry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | scsi_eh_finish_cmd(scmd, done_q); |
| 1738 | } |
| 1739 | } else { |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1740 | SCSI_LOG_ERROR_RECOVERY(3, |
| 1741 | shost_printk(KERN_INFO, shost, |
| 1742 | "%s: HRST failed\n", |
| 1743 | current->comm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | } |
| 1745 | } |
David Jeffery | 3eef625 | 2011-05-19 14:41:12 -0400 | [diff] [blame] | 1746 | return scsi_eh_test_devices(&check_list, work_q, done_q, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | /** |
| 1750 | * scsi_eh_offline_sdevs - offline scsi devices that fail to recover |
Randy Dunlap | 74cf298 | 2014-08-16 14:15:11 -0700 | [diff] [blame] | 1751 | * @work_q: &list_head for pending commands. |
| 1752 | * @done_q: &list_head for processed commands. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1753 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | static void scsi_eh_offline_sdevs(struct list_head *work_q, |
| 1755 | struct list_head *done_q) |
| 1756 | { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1757 | struct scsi_cmnd *scmd, *next; |
Bart Van Assche | 0db6ca8 | 2017-06-02 14:21:55 -0700 | [diff] [blame] | 1758 | struct scsi_device *sdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 1760 | list_for_each_entry_safe(scmd, next, work_q, eh_entry) { |
Matthew Wilcox | 31765d7 | 2007-08-17 11:02:10 -0600 | [diff] [blame] | 1761 | sdev_printk(KERN_INFO, scmd->device, "Device offlined - " |
| 1762 | "not ready after error recovery\n"); |
Bart Van Assche | 0db6ca8 | 2017-06-02 14:21:55 -0700 | [diff] [blame] | 1763 | sdev = scmd->device; |
| 1764 | |
| 1765 | mutex_lock(&sdev->state_mutex); |
| 1766 | scsi_device_set_state(sdev, SDEV_OFFLINE); |
| 1767 | mutex_unlock(&sdev->state_mutex); |
| 1768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | scsi_eh_finish_cmd(scmd, done_q); |
| 1770 | } |
| 1771 | return; |
| 1772 | } |
| 1773 | |
| 1774 | /** |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 1775 | * scsi_noretry_cmd - determine if command should be failed fast |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1776 | * @scmd: SCSI cmd to examine. |
| 1777 | */ |
| 1778 | int scsi_noretry_cmd(struct scsi_cmnd *scmd) |
| 1779 | { |
Bart Van Assche | aa8e25e | 2021-08-09 16:03:05 -0700 | [diff] [blame] | 1780 | struct request *req = scsi_cmd_to_rq(scmd); |
| 1781 | |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1782 | switch (host_byte(scmd->result)) { |
| 1783 | case DID_OK: |
| 1784 | break; |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 1785 | case DID_TIME_OUT: |
| 1786 | goto check_type; |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1787 | case DID_BUS_BUSY: |
Bart Van Assche | aa8e25e | 2021-08-09 16:03:05 -0700 | [diff] [blame] | 1788 | return req->cmd_flags & REQ_FAILFAST_TRANSPORT; |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1789 | case DID_PARITY: |
Bart Van Assche | aa8e25e | 2021-08-09 16:03:05 -0700 | [diff] [blame] | 1790 | return req->cmd_flags & REQ_FAILFAST_DEV; |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1791 | case DID_ERROR: |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1792 | if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT) |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1793 | return 0; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1794 | fallthrough; |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1795 | case DID_SOFT_ERROR: |
Bart Van Assche | aa8e25e | 2021-08-09 16:03:05 -0700 | [diff] [blame] | 1796 | return req->cmd_flags & REQ_FAILFAST_DRIVER; |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1797 | } |
| 1798 | |
Hannes Reinecke | d0672a0 | 2021-04-27 10:30:14 +0200 | [diff] [blame] | 1799 | if (!scsi_status_is_check_condition(scmd->result)) |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 1800 | return 0; |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1801 | |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 1802 | check_type: |
| 1803 | /* |
| 1804 | * assume caller has checked sense and determined |
| 1805 | * the check condition was retryable. |
| 1806 | */ |
Bart Van Assche | aa8e25e | 2021-08-09 16:03:05 -0700 | [diff] [blame] | 1807 | if (req->cmd_flags & REQ_FAILFAST_DEV || blk_rq_is_passthrough(req)) |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 1808 | return 1; |
Damien Le Moal | 342c81e | 2020-09-10 16:48:41 +0900 | [diff] [blame] | 1809 | |
| 1810 | return 0; |
Mike Christie | 4a27446 | 2008-08-19 18:45:31 -0500 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | * scsi_decide_disposition - Disposition a cmd on return from LLD. |
| 1815 | * @scmd: SCSI cmd to examine. |
| 1816 | * |
| 1817 | * Notes: |
| 1818 | * This is *only* called when we are examining the status after sending |
| 1819 | * out the actual data command. any commands that are queued for error |
| 1820 | * recovery (e.g. test_unit_ready) do *not* come through here. |
| 1821 | * |
| 1822 | * When this routine returns failed, it means the error handler thread |
| 1823 | * is woken. In cases where the error code indicates an error that |
| 1824 | * doesn't require the error handler read (i.e. we don't need to |
| 1825 | * abort/reset), this function should return SUCCESS. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 1826 | */ |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1827 | enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *scmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | { |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 1829 | enum scsi_disposition rtn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
| 1831 | /* |
| 1832 | * if the device is offline, then we clearly just pass the result back |
| 1833 | * up to the top level. |
| 1834 | */ |
| 1835 | if (!scsi_device_online(scmd->device)) { |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 1836 | SCSI_LOG_ERROR_RECOVERY(5, scmd_printk(KERN_INFO, scmd, |
| 1837 | "%s: device offline - report as SUCCESS\n", __func__)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | return SUCCESS; |
| 1839 | } |
| 1840 | |
| 1841 | /* |
| 1842 | * first check the host byte, to see if there is anything in there |
| 1843 | * that would indicate what we need to do. |
| 1844 | */ |
| 1845 | switch (host_byte(scmd->result)) { |
| 1846 | case DID_PASSTHROUGH: |
| 1847 | /* |
| 1848 | * no matter what, pass this through to the upper layer. |
| 1849 | * nuke this special code so that it looks like we are saying |
| 1850 | * did_ok. |
| 1851 | */ |
| 1852 | scmd->result &= 0xff00ffff; |
| 1853 | return SUCCESS; |
| 1854 | case DID_OK: |
| 1855 | /* |
| 1856 | * looks good. drop through, and check the next byte. |
| 1857 | */ |
| 1858 | break; |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 1859 | case DID_ABORT: |
| 1860 | if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) { |
Ulrich Obergfell | 8922a90 | 2014-06-04 13:34:57 +0200 | [diff] [blame] | 1861 | set_host_byte(scmd, DID_TIME_OUT); |
Hannes Reinecke | e494f6a | 2013-11-11 13:44:54 +0100 | [diff] [blame] | 1862 | return SUCCESS; |
| 1863 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1864 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | case DID_NO_CONNECT: |
| 1866 | case DID_BAD_TARGET: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | /* |
| 1868 | * note - this means that we just report the status back |
| 1869 | * to the top level driver, not that we actually think |
| 1870 | * that it indicates SUCCESS. |
| 1871 | */ |
| 1872 | return SUCCESS; |
Petros Koutoupis | ad95028 | 2017-10-30 16:38:10 -0500 | [diff] [blame] | 1873 | case DID_SOFT_ERROR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | /* |
| 1875 | * when the low level driver returns did_soft_error, |
Jesper Juhl | 0bf8c86 | 2011-03-21 20:47:31 +0100 | [diff] [blame] | 1876 | * it is responsible for keeping an internal retry counter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | * in order to avoid endless loops (db) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | goto maybe_retry; |
| 1880 | case DID_IMM_RETRY: |
| 1881 | return NEEDS_RETRY; |
| 1882 | |
| bf34191 | 2005-04-12 17:49:09 -0500 | [diff] [blame] | 1883 | case DID_REQUEUE: |
| 1884 | return ADD_TO_MLQUEUE; |
Mike Christie | a4dfaa6 | 2008-08-19 18:45:25 -0500 | [diff] [blame] | 1885 | case DID_TRANSPORT_DISRUPTED: |
| 1886 | /* |
| 1887 | * LLD/transport was disrupted during processing of the IO. |
| 1888 | * The transport class is now blocked/blocking, |
| 1889 | * and the transport will decide what to do with the IO |
Mike Christie | 939c2288 | 2008-11-04 19:47:19 -0600 | [diff] [blame] | 1890 | * based on its timers and recovery capablilities if |
| 1891 | * there are enough retries. |
Mike Christie | a4dfaa6 | 2008-08-19 18:45:25 -0500 | [diff] [blame] | 1892 | */ |
Mike Christie | 939c2288 | 2008-11-04 19:47:19 -0600 | [diff] [blame] | 1893 | goto maybe_retry; |
Mike Christie | a4dfaa6 | 2008-08-19 18:45:25 -0500 | [diff] [blame] | 1894 | case DID_TRANSPORT_FAILFAST: |
| 1895 | /* |
| 1896 | * The transport decided to failfast the IO (most likely |
| 1897 | * the fast io fail tmo fired), so send IO directly upwards. |
| 1898 | */ |
| 1899 | return SUCCESS; |
Muneendra Kumar | 962c8dc | 2021-01-07 03:19:04 +0530 | [diff] [blame] | 1900 | case DID_TRANSPORT_MARGINAL: |
| 1901 | /* |
| 1902 | * caller has decided not to do retries on |
| 1903 | * abort success, so send IO directly upwards |
| 1904 | */ |
| 1905 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | case DID_ERROR: |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1907 | if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | /* |
| 1909 | * execute reservation conflict processing code |
| 1910 | * lower down |
| 1911 | */ |
| 1912 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1913 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | case DID_BUS_BUSY: |
| 1915 | case DID_PARITY: |
| 1916 | goto maybe_retry; |
| 1917 | case DID_TIME_OUT: |
| 1918 | /* |
| 1919 | * when we scan the bus, we get timeout messages for |
| 1920 | * these commands if there is no device available. |
| 1921 | * other hosts report did_no_connect for the same thing. |
| 1922 | */ |
| 1923 | if ((scmd->cmnd[0] == TEST_UNIT_READY || |
| 1924 | scmd->cmnd[0] == INQUIRY)) { |
| 1925 | return SUCCESS; |
| 1926 | } else { |
| 1927 | return FAILED; |
| 1928 | } |
| 1929 | case DID_RESET: |
| 1930 | return SUCCESS; |
| 1931 | default: |
| 1932 | return FAILED; |
| 1933 | } |
| 1934 | |
| 1935 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | * check the status byte to see if this indicates anything special. |
| 1937 | */ |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1938 | switch (get_status_byte(scmd)) { |
| 1939 | case SAM_STAT_TASK_SET_FULL: |
Mike Christie | 42a6a91 | 2009-10-15 17:46:44 -0700 | [diff] [blame] | 1940 | scsi_handle_queue_full(scmd->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | /* |
| 1942 | * the case of trying to send too many commands to a |
| 1943 | * tagged queueing device. |
| 1944 | */ |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1945 | fallthrough; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1946 | case SAM_STAT_BUSY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | /* |
| 1948 | * device can't talk to us at the moment. Should only |
| 1949 | * occur (SAM-3) when the task queue is empty, so will cause |
| 1950 | * the empty queue handling to trigger a stall in the |
| 1951 | * device. |
| 1952 | */ |
| 1953 | return ADD_TO_MLQUEUE; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1954 | case SAM_STAT_GOOD: |
Ewan D. Milne | 279afdf | 2013-08-08 15:07:48 -0400 | [diff] [blame] | 1955 | if (scmd->cmnd[0] == REPORT_LUNS) |
| 1956 | scmd->device->sdev_target->expecting_lun_change = 0; |
Vasu Dev | 4a84067 | 2009-10-22 15:46:33 -0700 | [diff] [blame] | 1957 | scsi_handle_queue_ramp_up(scmd->device); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1958 | fallthrough; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1959 | case SAM_STAT_COMMAND_TERMINATED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | return SUCCESS; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1961 | case SAM_STAT_TASK_ABORTED: |
Vladislav Bolkhovitin | a9b589d | 2008-11-06 13:57:52 +0300 | [diff] [blame] | 1962 | goto maybe_retry; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1963 | case SAM_STAT_CHECK_CONDITION: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | rtn = scsi_check_sense(scmd); |
| 1965 | if (rtn == NEEDS_RETRY) |
| 1966 | goto maybe_retry; |
| 1967 | /* if rtn == FAILED, we have no sense information; |
| 1968 | * returning FAILED will wake the error handler thread |
| 1969 | * to collect the sense and redo the decide |
| 1970 | * disposition */ |
| 1971 | return rtn; |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1972 | case SAM_STAT_CONDITION_MET: |
| 1973 | case SAM_STAT_INTERMEDIATE: |
| 1974 | case SAM_STAT_INTERMEDIATE_CONDITION_MET: |
| 1975 | case SAM_STAT_ACA_ACTIVE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | /* |
| 1977 | * who knows? FIXME(eric) |
| 1978 | */ |
| 1979 | return SUCCESS; |
| 1980 | |
Hannes Reinecke | 3d45cefc | 2021-04-27 10:30:46 +0200 | [diff] [blame] | 1981 | case SAM_STAT_RESERVATION_CONFLICT: |
James Bottomley | 9ccfc75 | 2005-10-02 11:45:08 -0500 | [diff] [blame] | 1982 | sdev_printk(KERN_INFO, scmd->device, |
| 1983 | "reservation conflict\n"); |
Moger, Babu | 2082ebc | 2012-01-24 20:38:46 +0000 | [diff] [blame] | 1984 | set_host_byte(scmd, DID_NEXUS_FAILURE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | return SUCCESS; /* causes immediate i/o error */ |
| 1986 | default: |
| 1987 | return FAILED; |
| 1988 | } |
| 1989 | return FAILED; |
| 1990 | |
Jianchao Wang | 8ef7fe4 | 2018-02-26 15:59:16 +0800 | [diff] [blame] | 1991 | maybe_retry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | |
| 1993 | /* we requeue for retry because the error was retryable, and |
| 1994 | * the request was not marked fast fail. Note that above, |
| 1995 | * even if the request is marked fast fail, we still requeue |
| 1996 | * for queue congestion conditions (QUEUE_FULL or BUSY) */ |
Mike Christie | 2a242d5 | 2020-10-01 10:35:53 -0500 | [diff] [blame] | 1997 | if (scsi_cmd_retry_allowed(scmd) && !scsi_noretry_cmd(scmd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | return NEEDS_RETRY; |
| 1999 | } else { |
| 2000 | /* |
| 2001 | * no more retries - report this one back to upper level. |
| 2002 | */ |
| 2003 | return SUCCESS; |
| 2004 | } |
| 2005 | } |
| 2006 | |
Christoph Hellwig | 2a842ac | 2017-06-03 09:38:04 +0200 | [diff] [blame] | 2007 | static void eh_lock_door_done(struct request *req, blk_status_t status) |
FUJITA Tomonori | f078727 | 2008-12-14 01:23:45 +0900 | [diff] [blame] | 2008 | { |
Christoph Hellwig | 0bf6d96 | 2021-10-25 09:05:07 +0200 | [diff] [blame] | 2009 | blk_mq_free_request(req); |
FUJITA Tomonori | f078727 | 2008-12-14 01:23:45 +0900 | [diff] [blame] | 2010 | } |
| 2011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | * scsi_eh_lock_door - Prevent medium removal for the specified device |
| 2014 | * @sdev: SCSI device to prevent medium removal |
| 2015 | * |
| 2016 | * Locking: |
James Bottomley | 91bc31f | 2009-05-17 09:30:48 -0500 | [diff] [blame] | 2017 | * We must be called from process context. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | * |
| 2019 | * Notes: |
| 2020 | * We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the |
| 2021 | * head of the devices request queue, and continue. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 2022 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | static void scsi_eh_lock_door(struct scsi_device *sdev) |
| 2024 | { |
FUJITA Tomonori | f078727 | 2008-12-14 01:23:45 +0900 | [diff] [blame] | 2025 | struct request *req; |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 2026 | struct scsi_request *rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | |
Christoph Hellwig | 68ec3b8 | 2021-10-21 08:06:05 +0200 | [diff] [blame] | 2028 | req = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN, 0); |
Joe Lawrence | a492f07 | 2014-08-28 08:15:21 -0600 | [diff] [blame] | 2029 | if (IS_ERR(req)) |
Joe Lawrence | eb571ee | 2014-07-02 15:35:16 -0400 | [diff] [blame] | 2030 | return; |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 2031 | rq = scsi_req(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 2033 | rq->cmd[0] = ALLOW_MEDIUM_REMOVAL; |
| 2034 | rq->cmd[1] = 0; |
| 2035 | rq->cmd[2] = 0; |
| 2036 | rq->cmd[3] = 0; |
| 2037 | rq->cmd[4] = SCSI_REMOVAL_PREVENT; |
| 2038 | rq->cmd[5] = 0; |
| 2039 | rq->cmd_len = COMMAND_SIZE(rq->cmd[0]); |
FUJITA Tomonori | f078727 | 2008-12-14 01:23:45 +0900 | [diff] [blame] | 2040 | |
Christoph Hellwig | e806402 | 2016-10-20 15:12:13 +0200 | [diff] [blame] | 2041 | req->rq_flags |= RQF_QUIET; |
FUJITA Tomonori | f078727 | 2008-12-14 01:23:45 +0900 | [diff] [blame] | 2042 | req->timeout = 10 * HZ; |
Christoph Hellwig | 64c7f1d | 2017-04-05 19:18:12 +0200 | [diff] [blame] | 2043 | rq->retries = 5; |
FUJITA Tomonori | f078727 | 2008-12-14 01:23:45 +0900 | [diff] [blame] | 2044 | |
Christoph Hellwig | b84ba30 | 2021-11-26 13:18:01 +0100 | [diff] [blame] | 2045 | blk_execute_rq_nowait(req, true, eh_lock_door_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | /** |
| 2049 | * scsi_restart_operations - restart io operations to the specified host. |
| 2050 | * @shost: Host we are restarting. |
| 2051 | * |
| 2052 | * Notes: |
| 2053 | * When we entered the error handler, we blocked all further i/o to |
| 2054 | * this device. we need to 'reverse' this process. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 2055 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | static void scsi_restart_operations(struct Scsi_Host *shost) |
| 2057 | { |
| 2058 | struct scsi_device *sdev; |
James Bottomley | 939647e | 2005-09-18 15:05:20 -0500 | [diff] [blame] | 2059 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
| 2061 | /* |
| 2062 | * If the door was locked, we need to insert a door lock request |
| 2063 | * onto the head of the SCSI request queue for the device. There |
| 2064 | * is no point trying to lock the door of an off-line device. |
| 2065 | */ |
| 2066 | shost_for_each_device(sdev, shost) { |
Christoph Hellwig | 4837927 | 2014-11-03 19:36:40 +0100 | [diff] [blame] | 2067 | if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | scsi_eh_lock_door(sdev); |
Christoph Hellwig | 4837927 | 2014-11-03 19:36:40 +0100 | [diff] [blame] | 2069 | sdev->was_reset = 0; |
| 2070 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | /* |
| 2074 | * next free up anything directly waiting upon the host. this |
| 2075 | * will be requests for character device operations, and also for |
| 2076 | * ioctls to queued block devices. |
| 2077 | */ |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 2078 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 2079 | shost_printk(KERN_INFO, shost, "waking up host to restart\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | |
James Bottomley | 939647e | 2005-09-18 15:05:20 -0500 | [diff] [blame] | 2081 | spin_lock_irqsave(shost->host_lock, flags); |
| 2082 | if (scsi_host_set_state(shost, SHOST_RUNNING)) |
| 2083 | if (scsi_host_set_state(shost, SHOST_CANCEL)) |
| 2084 | BUG_ON(scsi_host_set_state(shost, SHOST_DEL)); |
| 2085 | spin_unlock_irqrestore(shost->host_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | |
| 2087 | wake_up(&shost->host_wait); |
| 2088 | |
| 2089 | /* |
| 2090 | * finally we need to re-initiate requests that may be pending. we will |
| 2091 | * have had everything blocked while error handling is taking place, and |
| 2092 | * now that error recovery is done, we will need to ensure that these |
| 2093 | * requests are started. |
| 2094 | */ |
| 2095 | scsi_run_host_queues(shost); |
Dan Williams | 57fc2e3 | 2012-06-21 23:25:32 -0700 | [diff] [blame] | 2096 | |
| 2097 | /* |
| 2098 | * if eh is active and host_eh_scheduled is pending we need to re-run |
| 2099 | * recovery. we do this check after scsi_run_host_queues() to allow |
| 2100 | * everything pent up since the last eh run a chance to make forward |
| 2101 | * progress before we sync again. Either we'll immediately re-run |
| 2102 | * recovery or scsi_device_unbusy() will wake us again when these |
| 2103 | * pending commands complete. |
| 2104 | */ |
| 2105 | spin_lock_irqsave(shost->host_lock, flags); |
| 2106 | if (shost->host_eh_scheduled) |
| 2107 | if (scsi_host_set_state(shost, SHOST_RECOVERY)) |
| 2108 | WARN_ON(scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY)); |
| 2109 | spin_unlock_irqrestore(shost->host_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | /** |
| 2113 | * scsi_eh_ready_devs - check device ready state and recover if not. |
Randy Dunlap | 74cf298 | 2014-08-16 14:15:11 -0700 | [diff] [blame] | 2114 | * @shost: host to be recovered. |
| 2115 | * @work_q: &list_head for pending commands. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2116 | * @done_q: &list_head for processed commands. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 2117 | */ |
Darrick J. Wong | dca84e4 | 2007-01-26 14:08:49 -0800 | [diff] [blame] | 2118 | void scsi_eh_ready_devs(struct Scsi_Host *shost, |
| 2119 | struct list_head *work_q, |
| 2120 | struct list_head *done_q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | { |
| 2122 | if (!scsi_eh_stu(shost, work_q, done_q)) |
| 2123 | if (!scsi_eh_bus_device_reset(shost, work_q, done_q)) |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 2124 | if (!scsi_eh_target_reset(shost, work_q, done_q)) |
| 2125 | if (!scsi_eh_bus_reset(shost, work_q, done_q)) |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 2126 | if (!scsi_eh_host_reset(shost, work_q, done_q)) |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 2127 | scsi_eh_offline_sdevs(work_q, |
| 2128 | done_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | } |
Darrick J. Wong | dca84e4 | 2007-01-26 14:08:49 -0800 | [diff] [blame] | 2130 | EXPORT_SYMBOL_GPL(scsi_eh_ready_devs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
| 2132 | /** |
| 2133 | * scsi_eh_flush_done_q - finish processed commands or retry them. |
| 2134 | * @done_q: list_head of processed commands. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 2135 | */ |
Tejun Heo | 041c5fc | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 2136 | void scsi_eh_flush_done_q(struct list_head *done_q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | { |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 2138 | struct scsi_cmnd *scmd, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | |
Christoph Hellwig | 937abeaa | 2005-06-19 13:43:56 +0200 | [diff] [blame] | 2140 | list_for_each_entry_safe(scmd, next, done_q, eh_entry) { |
| 2141 | list_del_init(&scmd->eh_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | if (scsi_device_online(scmd->device) && |
Muneendra Kumar | 60bee27 | 2021-01-07 03:19:05 +0530 | [diff] [blame] | 2143 | !scsi_noretry_cmd(scmd) && scsi_cmd_retry_allowed(scmd) && |
| 2144 | scsi_eh_should_retry_cmd(scmd)) { |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 2145 | SCSI_LOG_ERROR_RECOVERY(3, |
| 2146 | scmd_printk(KERN_INFO, scmd, |
Hannes Reinecke | 470613b | 2015-01-08 07:43:50 +0100 | [diff] [blame] | 2147 | "%s: flush retry cmd\n", |
| 2148 | current->comm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY); |
| 2150 | } else { |
Patrick Mansfield | 793698c | 2005-05-16 17:42:15 -0700 | [diff] [blame] | 2151 | /* |
| 2152 | * If just we got sense for the device (called |
| 2153 | * scsi_eh_get_sense), scmd->result is already |
Hannes Reinecke | 4bd51e5 | 2021-04-27 10:30:17 +0200 | [diff] [blame] | 2154 | * set, do not set DID_TIME_OUT. |
Patrick Mansfield | 793698c | 2005-05-16 17:42:15 -0700 | [diff] [blame] | 2155 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | if (!scmd->result) |
Hannes Reinecke | 4bd51e5 | 2021-04-27 10:30:17 +0200 | [diff] [blame] | 2157 | scmd->result |= (DID_TIME_OUT << 16); |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 2158 | SCSI_LOG_ERROR_RECOVERY(3, |
| 2159 | scmd_printk(KERN_INFO, scmd, |
Hannes Reinecke | 470613b | 2015-01-08 07:43:50 +0100 | [diff] [blame] | 2160 | "%s: flush finish cmd\n", |
| 2161 | current->comm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | scsi_finish_command(scmd); |
| 2163 | } |
| 2164 | } |
| 2165 | } |
Tejun Heo | 041c5fc | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 2166 | EXPORT_SYMBOL(scsi_eh_flush_done_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | |
| 2168 | /** |
| 2169 | * scsi_unjam_host - Attempt to fix a host which has a cmd that failed. |
| 2170 | * @shost: Host to unjam. |
| 2171 | * |
| 2172 | * Notes: |
| 2173 | * When we come in here, we *know* that all commands on the bus have |
| 2174 | * either completed, failed or timed out. we also know that no further |
| 2175 | * commands are being sent to the host, so things are relatively quiet |
| 2176 | * and we have freedom to fiddle with things as we wish. |
| 2177 | * |
| 2178 | * This is only the *default* implementation. it is possible for |
| 2179 | * individual drivers to supply their own version of this function, and |
| 2180 | * if the maintainer wishes to do this, it is strongly suggested that |
| 2181 | * this function be taken as a template and modified. this function |
| 2182 | * was designed to correctly handle problems for about 95% of the |
| 2183 | * different cases out there, and it should always provide at least a |
| 2184 | * reasonable amount of error recovery. |
| 2185 | * |
| 2186 | * Any command marked 'failed' or 'timeout' must eventually have |
| 2187 | * scsi_finish_cmd() called for it. we do all of the retry stuff |
| 2188 | * here, so when we restart the host after we return it should have an |
| 2189 | * empty queue. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 2190 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | static void scsi_unjam_host(struct Scsi_Host *shost) |
| 2192 | { |
| 2193 | unsigned long flags; |
| 2194 | LIST_HEAD(eh_work_q); |
| 2195 | LIST_HEAD(eh_done_q); |
| 2196 | |
| 2197 | spin_lock_irqsave(shost->host_lock, flags); |
| 2198 | list_splice_init(&shost->eh_cmd_q, &eh_work_q); |
| 2199 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2200 | |
| 2201 | SCSI_LOG_ERROR_RECOVERY(1, scsi_eh_prt_fail_stats(shost, &eh_work_q)); |
| 2202 | |
| 2203 | if (!scsi_eh_get_sense(&eh_work_q, &eh_done_q)) |
Hannes Reinecke | a065863 | 2017-04-06 15:36:35 +0200 | [diff] [blame] | 2204 | scsi_eh_ready_devs(shost, &eh_work_q, &eh_done_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 2206 | spin_lock_irqsave(shost->host_lock, flags); |
Ren Mingxin | bb3b621 | 2013-11-11 13:44:56 +0100 | [diff] [blame] | 2207 | if (shost->eh_deadline != -1) |
Hannes Reinecke | b456202 | 2013-10-23 10:51:21 +0200 | [diff] [blame] | 2208 | shost->last_reset = 0; |
| 2209 | spin_unlock_irqrestore(shost->host_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | scsi_eh_flush_done_q(&eh_done_q); |
| 2211 | } |
| 2212 | |
| 2213 | /** |
Christoph Hellwig | ad42eb1 | 2005-10-29 01:01:55 +0200 | [diff] [blame] | 2214 | * scsi_error_handler - SCSI error handler thread |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | * @data: Host for which we are running. |
| 2216 | * |
| 2217 | * Notes: |
Christoph Hellwig | ad42eb1 | 2005-10-29 01:01:55 +0200 | [diff] [blame] | 2218 | * This is the main error handling loop. This is run as a kernel thread |
| 2219 | * for every SCSI host and handles all error handling activity. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 2220 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | int scsi_error_handler(void *data) |
| 2222 | { |
Christoph Hellwig | ad42eb1 | 2005-10-29 01:01:55 +0200 | [diff] [blame] | 2223 | struct Scsi_Host *shost = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | /* |
Christoph Hellwig | ad42eb1 | 2005-10-29 01:01:55 +0200 | [diff] [blame] | 2226 | * We use TASK_INTERRUPTIBLE so that the thread is not |
| 2227 | * counted against the load average as a running process. |
| 2228 | * We never actually get interrupted because kthread_run |
Frederik Schwarzer | c03264a | 2008-12-23 00:54:00 +0100 | [diff] [blame] | 2229 | * disables signal delivery for the created thread. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | */ |
Michal Hocko | 537b604 | 2015-08-27 20:16:37 +0200 | [diff] [blame] | 2231 | while (true) { |
| 2232 | /* |
| 2233 | * The sequence in kthread_stop() sets the stop flag first |
| 2234 | * then wakes the process. To avoid missed wakeups, the task |
| 2235 | * should always be in a non running state before the stop |
| 2236 | * flag is checked |
| 2237 | */ |
Dan Williams | b9d5c6b | 2012-06-21 23:25:42 -0700 | [diff] [blame] | 2238 | set_current_state(TASK_INTERRUPTIBLE); |
Michal Hocko | 537b604 | 2015-08-27 20:16:37 +0200 | [diff] [blame] | 2239 | if (kthread_should_stop()) |
| 2240 | break; |
| 2241 | |
Tejun Heo | ee7863b | 2006-05-15 20:57:20 +0900 | [diff] [blame] | 2242 | if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) || |
Ming Lei | c84b023 | 2018-06-24 22:03:26 +0800 | [diff] [blame] | 2243 | shost->host_failed != scsi_host_busy(shost)) { |
Christoph Hellwig | ad42eb1 | 2005-10-29 01:01:55 +0200 | [diff] [blame] | 2244 | SCSI_LOG_ERROR_RECOVERY(1, |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 2245 | shost_printk(KERN_INFO, shost, |
| 2246 | "scsi_eh_%d: sleeping\n", |
| 2247 | shost->host_no)); |
James Bottomley | 3ed7a47 | 2005-09-19 09:50:04 -0500 | [diff] [blame] | 2248 | schedule(); |
James Bottomley | 3ed7a47 | 2005-09-19 09:50:04 -0500 | [diff] [blame] | 2249 | continue; |
| 2250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | |
James Bottomley | 3ed7a47 | 2005-09-19 09:50:04 -0500 | [diff] [blame] | 2252 | __set_current_state(TASK_RUNNING); |
Christoph Hellwig | ad42eb1 | 2005-10-29 01:01:55 +0200 | [diff] [blame] | 2253 | SCSI_LOG_ERROR_RECOVERY(1, |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 2254 | shost_printk(KERN_INFO, shost, |
| 2255 | "scsi_eh_%d: waking up %d/%d/%d\n", |
| 2256 | shost->host_no, shost->host_eh_scheduled, |
Christoph Hellwig | 7466501 | 2014-01-22 15:29:29 +0100 | [diff] [blame] | 2257 | shost->host_failed, |
Ming Lei | c84b023 | 2018-06-24 22:03:26 +0800 | [diff] [blame] | 2258 | scsi_host_busy(shost))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | /* |
| 2261 | * We have a host that is failing for some reason. Figure out |
| 2262 | * what we need to do to get it up and online again (if we can). |
| 2263 | * If we fail, we end up taking the thing offline. |
| 2264 | */ |
Lin Ming | ae0751f | 2011-12-05 09:20:24 +0800 | [diff] [blame] | 2265 | if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) { |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 2266 | SCSI_LOG_ERROR_RECOVERY(1, |
Hannes Reinecke | a222b1e | 2014-10-24 14:27:02 +0200 | [diff] [blame] | 2267 | shost_printk(KERN_ERR, shost, |
| 2268 | "scsi_eh_%d: unable to autoresume\n", |
| 2269 | shost->host_no)); |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 2270 | continue; |
| 2271 | } |
| 2272 | |
Christoph Hellwig | 9227c33 | 2006-04-01 19:21:04 +0200 | [diff] [blame] | 2273 | if (shost->transportt->eh_strategy_handler) |
| 2274 | shost->transportt->eh_strategy_handler(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | else |
| 2276 | scsi_unjam_host(shost); |
| 2277 | |
Wei Fang | 72d8c36 | 2016-06-07 14:53:56 +0800 | [diff] [blame] | 2278 | /* All scmds have been handled */ |
| 2279 | shost->host_failed = 0; |
| 2280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | /* |
| 2282 | * Note - if the above fails completely, the action is to take |
| 2283 | * individual devices offline and flush the queue of any |
| 2284 | * outstanding requests that may have been pending. When we |
| 2285 | * restart, we restart any I/O to any other devices on the bus |
| 2286 | * which are still online. |
| 2287 | */ |
| 2288 | scsi_restart_operations(shost); |
Lin Ming | ae0751f | 2011-12-05 09:20:24 +0800 | [diff] [blame] | 2289 | if (!shost->eh_noresume) |
| 2290 | scsi_autopm_put_host(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | } |
Steven Rostedt | 461a0ff | 2005-10-19 08:22:13 -0400 | [diff] [blame] | 2292 | __set_current_state(TASK_RUNNING); |
| 2293 | |
Christoph Hellwig | ad42eb1 | 2005-10-29 01:01:55 +0200 | [diff] [blame] | 2294 | SCSI_LOG_ERROR_RECOVERY(1, |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 2295 | shost_printk(KERN_INFO, shost, |
| 2296 | "Error handler scsi_eh_%d exiting\n", |
| 2297 | shost->host_no)); |
James Bottomley | 3ed7a47 | 2005-09-19 09:50:04 -0500 | [diff] [blame] | 2298 | shost->ehandler = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | return 0; |
| 2300 | } |
| 2301 | |
| 2302 | /* |
| 2303 | * Function: scsi_report_bus_reset() |
| 2304 | * |
| 2305 | * Purpose: Utility function used by low-level drivers to report that |
| 2306 | * they have observed a bus reset on the bus being handled. |
| 2307 | * |
| 2308 | * Arguments: shost - Host in question |
| 2309 | * channel - channel on which reset was observed. |
| 2310 | * |
| 2311 | * Returns: Nothing |
| 2312 | * |
| 2313 | * Lock status: Host lock must be held. |
| 2314 | * |
| 2315 | * Notes: This only needs to be called if the reset is one which |
| 2316 | * originates from an unknown location. Resets originated |
| 2317 | * by the mid-level itself don't need to call this, but there |
| 2318 | * should be no harm. |
| 2319 | * |
| 2320 | * The main purpose of this is to make sure that a CHECK_CONDITION |
| 2321 | * is properly treated. |
| 2322 | */ |
| 2323 | void scsi_report_bus_reset(struct Scsi_Host *shost, int channel) |
| 2324 | { |
| 2325 | struct scsi_device *sdev; |
| 2326 | |
| 2327 | __shost_for_each_device(sdev, shost) { |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 2328 | if (channel == sdev_channel(sdev)) |
| 2329 | __scsi_report_device_reset(sdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | } |
| 2331 | } |
| 2332 | EXPORT_SYMBOL(scsi_report_bus_reset); |
| 2333 | |
| 2334 | /* |
| 2335 | * Function: scsi_report_device_reset() |
| 2336 | * |
| 2337 | * Purpose: Utility function used by low-level drivers to report that |
| 2338 | * they have observed a device reset on the device being handled. |
| 2339 | * |
| 2340 | * Arguments: shost - Host in question |
| 2341 | * channel - channel on which reset was observed |
| 2342 | * target - target on which reset was observed |
| 2343 | * |
| 2344 | * Returns: Nothing |
| 2345 | * |
| 2346 | * Lock status: Host lock must be held |
| 2347 | * |
| 2348 | * Notes: This only needs to be called if the reset is one which |
| 2349 | * originates from an unknown location. Resets originated |
| 2350 | * by the mid-level itself don't need to call this, but there |
| 2351 | * should be no harm. |
| 2352 | * |
| 2353 | * The main purpose of this is to make sure that a CHECK_CONDITION |
| 2354 | * is properly treated. |
| 2355 | */ |
| 2356 | void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target) |
| 2357 | { |
| 2358 | struct scsi_device *sdev; |
| 2359 | |
| 2360 | __shost_for_each_device(sdev, shost) { |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 2361 | if (channel == sdev_channel(sdev) && |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 2362 | target == sdev_id(sdev)) |
| 2363 | __scsi_report_device_reset(sdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
| 2365 | } |
| 2366 | EXPORT_SYMBOL(scsi_report_device_reset); |
| 2367 | |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2368 | /** |
| 2369 | * scsi_ioctl_reset: explicitly reset a host/bus/target/device |
| 2370 | * @dev: scsi_device to operate on |
| 2371 | * @arg: reset type (see sg.h) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | */ |
| 2373 | int |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2374 | scsi_ioctl_reset(struct scsi_device *dev, int __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | { |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 2376 | struct scsi_cmnd *scmd; |
James Smart | d7a1bb0 | 2006-03-08 14:50:12 -0500 | [diff] [blame] | 2377 | struct Scsi_Host *shost = dev->host; |
Christoph Hellwig | e9c787e | 2017-01-02 21:55:26 +0300 | [diff] [blame] | 2378 | struct request *rq; |
James Smart | d7a1bb0 | 2006-03-08 14:50:12 -0500 | [diff] [blame] | 2379 | unsigned long flags; |
Bart Van Assche | b8e162f | 2021-04-15 15:08:11 -0700 | [diff] [blame] | 2380 | int error = 0, val; |
| 2381 | enum scsi_disposition rtn; |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2382 | |
| 2383 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 2384 | return -EACCES; |
| 2385 | |
| 2386 | error = get_user(val, arg); |
| 2387 | if (error) |
| 2388 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 2390 | if (scsi_autopm_get_host(shost) < 0) |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2391 | return -EIO; |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 2392 | |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2393 | error = -EIO; |
Christoph Hellwig | e9c787e | 2017-01-02 21:55:26 +0300 | [diff] [blame] | 2394 | rq = kzalloc(sizeof(struct request) + sizeof(struct scsi_cmnd) + |
| 2395 | shost->hostt->cmd_size, GFP_KERNEL); |
| 2396 | if (!rq) |
Christoph Hellwig | 95eeb5f | 2014-05-01 16:51:05 +0200 | [diff] [blame] | 2397 | goto out_put_autopm_host; |
Christoph Hellwig | e9c787e | 2017-01-02 21:55:26 +0300 | [diff] [blame] | 2398 | blk_rq_init(NULL, rq); |
Christoph Hellwig | 95eeb5f | 2014-05-01 16:51:05 +0200 | [diff] [blame] | 2399 | |
Christoph Hellwig | e9c787e | 2017-01-02 21:55:26 +0300 | [diff] [blame] | 2400 | scmd = (struct scsi_cmnd *)(rq + 1); |
| 2401 | scsi_init_command(dev, scmd); |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 2402 | scmd->cmnd = scsi_req(rq)->cmd; |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 2403 | |
Bart Van Assche | bf23e61 | 2021-10-07 13:27:56 -0700 | [diff] [blame] | 2404 | scmd->submitter = SUBMITTED_BY_SCSI_RESET_IOCTL; |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 2405 | memset(&scmd->sdb, 0, sizeof(scmd->sdb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | |
| 2407 | scmd->cmd_len = 0; |
| 2408 | |
| 2409 | scmd->sc_data_direction = DMA_BIDIRECTIONAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | |
James Smart | d7a1bb0 | 2006-03-08 14:50:12 -0500 | [diff] [blame] | 2411 | spin_lock_irqsave(shost->host_lock, flags); |
| 2412 | shost->tmf_in_progress = 1; |
| 2413 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2414 | |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2415 | switch (val & ~SG_SCSI_RESET_NO_ESCALATE) { |
| 2416 | case SG_SCSI_RESET_NOTHING: |
| 2417 | rtn = SUCCESS; |
| 2418 | break; |
| 2419 | case SG_SCSI_RESET_DEVICE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | rtn = scsi_try_bus_device_reset(scmd); |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2421 | if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2423 | fallthrough; |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2424 | case SG_SCSI_RESET_TARGET: |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 2425 | rtn = scsi_try_target_reset(scmd); |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2426 | if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE)) |
Mike Christie | 30bd7df | 2008-02-29 18:25:19 -0600 | [diff] [blame] | 2427 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2428 | fallthrough; |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2429 | case SG_SCSI_RESET_BUS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | rtn = scsi_try_bus_reset(scmd); |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2431 | if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2433 | fallthrough; |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2434 | case SG_SCSI_RESET_HOST: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | rtn = scsi_try_host_reset(scmd); |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2436 | if (rtn == SUCCESS) |
| 2437 | break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2438 | fallthrough; |
Bart Van Assche | 3bf2ff6 | 2017-08-25 13:46:29 -0700 | [diff] [blame] | 2439 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | rtn = FAILED; |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2441 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2444 | error = (rtn == SUCCESS) ? 0 : -EIO; |
| 2445 | |
James Smart | d7a1bb0 | 2006-03-08 14:50:12 -0500 | [diff] [blame] | 2446 | spin_lock_irqsave(shost->host_lock, flags); |
| 2447 | shost->tmf_in_progress = 0; |
| 2448 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 2449 | |
| 2450 | /* |
| 2451 | * be sure to wake up anyone who was sleeping or had their queue |
| 2452 | * suspended while we performed the TMF. |
| 2453 | */ |
| 2454 | SCSI_LOG_ERROR_RECOVERY(3, |
Hannes Reinecke | 91921e0 | 2014-06-25 16:39:59 +0200 | [diff] [blame] | 2455 | shost_printk(KERN_INFO, shost, |
| 2456 | "waking up host to restart after TMF\n")); |
James Smart | d7a1bb0 | 2006-03-08 14:50:12 -0500 | [diff] [blame] | 2457 | |
| 2458 | wake_up(&shost->host_wait); |
James Smart | d7a1bb0 | 2006-03-08 14:50:12 -0500 | [diff] [blame] | 2459 | scsi_run_host_queues(shost); |
| 2460 | |
Christoph Hellwig | e9c787e | 2017-01-02 21:55:26 +0300 | [diff] [blame] | 2461 | kfree(rq); |
Christoph Hellwig | 0f121dd | 2014-09-05 18:00:05 -0700 | [diff] [blame] | 2462 | |
Christoph Hellwig | 0479633 | 2014-02-20 14:20:55 -0800 | [diff] [blame] | 2463 | out_put_autopm_host: |
Alan Stern | bc4f240 | 2010-06-17 10:41:42 -0400 | [diff] [blame] | 2464 | scsi_autopm_put_host(shost); |
Christoph Hellwig | 176aa9d | 2014-10-11 12:06:47 +0200 | [diff] [blame] | 2465 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | |
Hannes Reinecke | 4753cbc | 2014-10-24 14:26:52 +0200 | [diff] [blame] | 2468 | bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd, |
| 2469 | struct scsi_sense_hdr *sshdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | { |
| 2471 | return scsi_normalize_sense(cmd->sense_buffer, |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 2472 | SCSI_SENSE_BUFFERSIZE, sshdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | } |
| 2474 | EXPORT_SYMBOL(scsi_command_normalize_sense); |
| 2475 | |
| 2476 | /** |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 2477 | * scsi_get_sense_info_fld - get information field from sense data (either fixed or descriptor format) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | * @sense_buffer: byte array of sense data |
| 2479 | * @sb_len: number of valid bytes in sense_buffer |
| 2480 | * @info_out: pointer to 64 integer where 8 or 4 byte information |
| 2481 | * field will be placed if found. |
| 2482 | * |
| 2483 | * Return value: |
Damien Le Moal | 2908769 | 2017-04-24 16:51:12 +0900 | [diff] [blame] | 2484 | * true if information field found, false if not found. |
Randy Dunlap | dc8875e | 2007-11-15 15:42:30 -0800 | [diff] [blame] | 2485 | */ |
Damien Le Moal | 2908769 | 2017-04-24 16:51:12 +0900 | [diff] [blame] | 2486 | bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len, |
| 2487 | u64 *info_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | const u8 * ucp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | |
| 2491 | if (sb_len < 7) |
Damien Le Moal | 2908769 | 2017-04-24 16:51:12 +0900 | [diff] [blame] | 2492 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | switch (sense_buffer[0] & 0x7f) { |
| 2494 | case 0x70: |
| 2495 | case 0x71: |
| 2496 | if (sense_buffer[0] & 0x80) { |
Damien Le Moal | 2908769 | 2017-04-24 16:51:12 +0900 | [diff] [blame] | 2497 | *info_out = get_unaligned_be32(&sense_buffer[3]); |
| 2498 | return true; |
| 2499 | } |
| 2500 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | case 0x72: |
| 2502 | case 0x73: |
| 2503 | ucp = scsi_sense_desc_find(sense_buffer, sb_len, |
| 2504 | 0 /* info desc */); |
| 2505 | if (ucp && (0xa == ucp[1])) { |
Damien Le Moal | 2908769 | 2017-04-24 16:51:12 +0900 | [diff] [blame] | 2506 | *info_out = get_unaligned_be64(&ucp[4]); |
| 2507 | return true; |
| 2508 | } |
| 2509 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | default: |
Damien Le Moal | 2908769 | 2017-04-24 16:51:12 +0900 | [diff] [blame] | 2511 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | } |
| 2513 | } |
| 2514 | EXPORT_SYMBOL(scsi_get_sense_info_fld); |