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