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