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