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