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