2 * scsi_error.c Copyright (C) 1997 Eric Youngdale
4 * SCSI error/timeout handling
5 * Initial versions: Eric Youngdale. Based upon conversations with
6 * Leonard Zubkoff and David Miller at Linux Expo,
7 * ideas originating from all over the place.
9 * Restructured scsi_unjam_host and associated functions.
10 * September 04, 2002 Mike Anderson (andmike@us.ibm.com)
12 * Forward port of Russell King's (rmk@arm.linux.org.uk) changes and
14 * September 30, 2002 Mike Anderson (andmike@us.ibm.com)
17 #include <linux/module.h>
18 #include <linux/sched.h>
19 #include <linux/gfp.h>
20 #include <linux/timer.h>
21 #include <linux/string.h>
22 #include <linux/kernel.h>
23 #include <linux/freezer.h>
24 #include <linux/kthread.h>
25 #include <linux/interrupt.h>
26 #include <linux/blkdev.h>
27 #include <linux/delay.h>
28 #include <linux/jiffies.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_cmnd.h>
32 #include <scsi/scsi_dbg.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_driver.h>
35 #include <scsi/scsi_eh.h>
36 #include <scsi/scsi_common.h>
37 #include <scsi/scsi_transport.h>
38 #include <scsi/scsi_host.h>
39 #include <scsi/scsi_ioctl.h>
40 #include <scsi/scsi_dh.h>
43 #include "scsi_priv.h"
44 #include "scsi_logging.h"
45 #include "scsi_transport_api.h"
47 #include <trace/events/scsi.h>
49 #include <asm/unaligned.h>
51 static void scsi_eh_done(struct scsi_cmnd *scmd);
54 * These should *probably* be handled by the host itself.
55 * Since it is allowed to sleep, it probably should.
57 #define BUS_RESET_SETTLE_TIME (10)
58 #define HOST_RESET_SETTLE_TIME (10)
60 static int scsi_eh_try_stu(struct scsi_cmnd *scmd);
61 static int scsi_try_to_abort_cmd(struct scsi_host_template *,
64 /* called with shost->host_lock held */
65 void scsi_eh_wakeup(struct Scsi_Host *shost)
67 if (atomic_read(&shost->host_busy) == shost->host_failed) {
68 trace_scsi_eh_wakeup(shost);
69 wake_up_process(shost->ehandler);
70 SCSI_LOG_ERROR_RECOVERY(5, shost_printk(KERN_INFO, shost,
71 "Waking error handler thread\n"));
76 * scsi_schedule_eh - schedule EH for SCSI host
77 * @shost: SCSI host to invoke error handling on.
79 * Schedule SCSI EH without scmd.
81 void scsi_schedule_eh(struct Scsi_Host *shost)
85 spin_lock_irqsave(shost->host_lock, flags);
87 if (scsi_host_set_state(shost, SHOST_RECOVERY) == 0 ||
88 scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY) == 0) {
89 shost->host_eh_scheduled++;
90 scsi_eh_wakeup(shost);
93 spin_unlock_irqrestore(shost->host_lock, flags);
95 EXPORT_SYMBOL_GPL(scsi_schedule_eh);
97 static int scsi_host_eh_past_deadline(struct Scsi_Host *shost)
99 if (!shost->last_reset || shost->eh_deadline == -1)
103 * 32bit accesses are guaranteed to be atomic
104 * (on all supported architectures), so instead
105 * of using a spinlock we can as well double check
106 * if eh_deadline has been set to 'off' during the
109 if (time_before(jiffies, shost->last_reset + shost->eh_deadline) &&
110 shost->eh_deadline > -1)
117 * scmd_eh_abort_handler - Handle command aborts
118 * @work: command to be aborted.
121 scmd_eh_abort_handler(struct work_struct *work)
123 struct scsi_cmnd *scmd =
124 container_of(work, struct scsi_cmnd, abort_work.work);
125 struct scsi_device *sdev = scmd->device;
128 if (scsi_host_eh_past_deadline(sdev->host)) {
129 SCSI_LOG_ERROR_RECOVERY(3,
130 scmd_printk(KERN_INFO, scmd,
131 "eh timeout, not aborting\n"));
133 SCSI_LOG_ERROR_RECOVERY(3,
134 scmd_printk(KERN_INFO, scmd,
135 "aborting command\n"));
136 rtn = scsi_try_to_abort_cmd(sdev->host->hostt, scmd);
137 if (rtn == SUCCESS) {
138 set_host_byte(scmd, DID_TIME_OUT);
139 if (scsi_host_eh_past_deadline(sdev->host)) {
140 SCSI_LOG_ERROR_RECOVERY(3,
141 scmd_printk(KERN_INFO, scmd,
142 "eh timeout, not retrying "
143 "aborted command\n"));
144 } else if (!scsi_noretry_cmd(scmd) &&
145 (++scmd->retries <= scmd->allowed)) {
146 SCSI_LOG_ERROR_RECOVERY(3,
147 scmd_printk(KERN_WARNING, scmd,
148 "retry aborted command\n"));
149 scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
152 SCSI_LOG_ERROR_RECOVERY(3,
153 scmd_printk(KERN_WARNING, scmd,
154 "finish aborted command\n"));
155 scsi_finish_command(scmd);
159 SCSI_LOG_ERROR_RECOVERY(3,
160 scmd_printk(KERN_INFO, scmd,
162 (rtn == FAST_IO_FAIL) ?
163 "not send" : "failed"));
167 scsi_eh_scmd_add(scmd);
171 * scsi_abort_command - schedule a command abort
172 * @scmd: scmd to abort.
174 * We only need to abort commands after a command timeout
177 scsi_abort_command(struct scsi_cmnd *scmd)
179 struct scsi_device *sdev = scmd->device;
180 struct Scsi_Host *shost = sdev->host;
183 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) {
185 * Retry after abort failed, escalate to next level.
187 SCSI_LOG_ERROR_RECOVERY(3,
188 scmd_printk(KERN_INFO, scmd,
189 "previous abort failed\n"));
190 BUG_ON(delayed_work_pending(&scmd->abort_work));
194 spin_lock_irqsave(shost->host_lock, flags);
195 if (shost->eh_deadline != -1 && !shost->last_reset)
196 shost->last_reset = jiffies;
197 spin_unlock_irqrestore(shost->host_lock, flags);
199 scmd->eh_eflags |= SCSI_EH_ABORT_SCHEDULED;
200 SCSI_LOG_ERROR_RECOVERY(3,
201 scmd_printk(KERN_INFO, scmd, "abort scheduled\n"));
202 queue_delayed_work(shost->tmf_work_q, &scmd->abort_work, HZ / 100);
207 * scsi_eh_reset - call into ->eh_action to reset internal counters
208 * @scmd: scmd to run eh on.
210 * The scsi driver might be carrying internal state about the
211 * devices, so we need to call into the driver to reset the
212 * internal state once the error handler is started.
214 static void scsi_eh_reset(struct scsi_cmnd *scmd)
216 if (!blk_rq_is_passthrough(scmd->request)) {
217 struct scsi_driver *sdrv = scsi_cmd_to_driver(scmd);
219 sdrv->eh_reset(scmd);
223 static void scsi_eh_inc_host_failed(struct rcu_head *head)
225 struct Scsi_Host *shost = container_of(head, typeof(*shost), rcu);
228 spin_lock_irqsave(shost->host_lock, flags);
229 shost->host_failed++;
230 scsi_eh_wakeup(shost);
231 spin_unlock_irqrestore(shost->host_lock, flags);
235 * scsi_eh_scmd_add - add scsi cmd to error handling.
236 * @scmd: scmd to run eh on.
238 void scsi_eh_scmd_add(struct scsi_cmnd *scmd)
240 struct Scsi_Host *shost = scmd->device->host;
244 WARN_ON_ONCE(!shost->ehandler);
246 spin_lock_irqsave(shost->host_lock, flags);
247 if (scsi_host_set_state(shost, SHOST_RECOVERY)) {
248 ret = scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY);
251 if (shost->eh_deadline != -1 && !shost->last_reset)
252 shost->last_reset = jiffies;
255 list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
256 spin_unlock_irqrestore(shost->host_lock, flags);
258 * Ensure that all tasks observe the host state change before the
259 * host_failed change.
261 call_rcu(&shost->rcu, scsi_eh_inc_host_failed);
265 * scsi_times_out - Timeout function for normal scsi commands.
266 * @req: request that is timing out.
269 * We do not need to lock this. There is the potential for a race
270 * only in that the normal completion handling might run, but if the
271 * normal completion function determines that the timer has already
272 * fired, then it mustn't do anything.
274 enum blk_eh_timer_return scsi_times_out(struct request *req)
276 struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
277 enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED;
278 struct Scsi_Host *host = scmd->device->host;
280 trace_scsi_dispatch_cmd_timeout(scmd);
281 scsi_log_completion(scmd, TIMEOUT_ERROR);
283 if (host->eh_deadline != -1 && !host->last_reset)
284 host->last_reset = jiffies;
286 if (host->hostt->eh_timed_out)
287 rtn = host->hostt->eh_timed_out(scmd);
289 if (rtn == BLK_EH_NOT_HANDLED) {
290 if (scsi_abort_command(scmd) != SUCCESS) {
291 set_host_byte(scmd, DID_TIME_OUT);
292 scsi_eh_scmd_add(scmd);
300 * scsi_block_when_processing_errors - Prevent cmds from being queued.
301 * @sdev: Device on which we are performing recovery.
304 * We block until the host is out of error recovery, and then check to
305 * see whether the host or the device is offline.
308 * 0 when dev was taken offline by error recovery. 1 OK to proceed.
310 int scsi_block_when_processing_errors(struct scsi_device *sdev)
314 wait_event(sdev->host->host_wait, !scsi_host_in_recovery(sdev->host));
316 online = scsi_device_online(sdev);
318 SCSI_LOG_ERROR_RECOVERY(5, sdev_printk(KERN_INFO, sdev,
319 "%s: rtn: %d\n", __func__, online));
323 EXPORT_SYMBOL(scsi_block_when_processing_errors);
325 #ifdef CONFIG_SCSI_LOGGING
327 * scsi_eh_prt_fail_stats - Log info on failures.
328 * @shost: scsi host being recovered.
329 * @work_q: Queue of scsi cmds to process.
331 static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
332 struct list_head *work_q)
334 struct scsi_cmnd *scmd;
335 struct scsi_device *sdev;
336 int total_failures = 0;
339 int devices_failed = 0;
341 shost_for_each_device(sdev, shost) {
342 list_for_each_entry(scmd, work_q, eh_entry) {
343 if (scmd->device == sdev) {
345 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED)
352 if (cmd_cancel || cmd_failed) {
353 SCSI_LOG_ERROR_RECOVERY(3,
354 shost_printk(KERN_INFO, shost,
355 "%s: cmds failed: %d, cancel: %d\n",
356 __func__, cmd_failed,
364 SCSI_LOG_ERROR_RECOVERY(2, shost_printk(KERN_INFO, shost,
365 "Total of %d commands on %d"
366 " devices require eh work\n",
367 total_failures, devices_failed));
372 * scsi_report_lun_change - Set flag on all *other* devices on the same target
373 * to indicate that a UNIT ATTENTION is expected.
374 * @sdev: Device reporting the UNIT ATTENTION
376 static void scsi_report_lun_change(struct scsi_device *sdev)
378 sdev->sdev_target->expecting_lun_change = 1;
382 * scsi_report_sense - Examine scsi sense information and log messages for
383 * certain conditions, also issue uevents for some of them.
384 * @sdev: Device reporting the sense code
385 * @sshdr: sshdr to be examined
387 static void scsi_report_sense(struct scsi_device *sdev,
388 struct scsi_sense_hdr *sshdr)
390 enum scsi_device_event evt_type = SDEV_EVT_MAXBITS; /* i.e. none */
392 if (sshdr->sense_key == UNIT_ATTENTION) {
393 if (sshdr->asc == 0x3f && sshdr->ascq == 0x03) {
394 evt_type = SDEV_EVT_INQUIRY_CHANGE_REPORTED;
395 sdev_printk(KERN_WARNING, sdev,
396 "Inquiry data has changed");
397 } else if (sshdr->asc == 0x3f && sshdr->ascq == 0x0e) {
398 evt_type = SDEV_EVT_LUN_CHANGE_REPORTED;
399 scsi_report_lun_change(sdev);
400 sdev_printk(KERN_WARNING, sdev,
401 "Warning! Received an indication that the "
402 "LUN assignments on this target have "
403 "changed. The Linux SCSI layer does not "
404 "automatically remap LUN assignments.\n");
405 } else if (sshdr->asc == 0x3f)
406 sdev_printk(KERN_WARNING, sdev,
407 "Warning! Received an indication that the "
408 "operating parameters on this target have "
409 "changed. The Linux SCSI layer does not "
410 "automatically adjust these parameters.\n");
412 if (sshdr->asc == 0x38 && sshdr->ascq == 0x07) {
413 evt_type = SDEV_EVT_SOFT_THRESHOLD_REACHED_REPORTED;
414 sdev_printk(KERN_WARNING, sdev,
415 "Warning! Received an indication that the "
416 "LUN reached a thin provisioning soft "
420 if (sshdr->asc == 0x2a && sshdr->ascq == 0x01) {
421 evt_type = SDEV_EVT_MODE_PARAMETER_CHANGE_REPORTED;
422 sdev_printk(KERN_WARNING, sdev,
423 "Mode parameters changed");
424 } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x06) {
425 evt_type = SDEV_EVT_ALUA_STATE_CHANGE_REPORTED;
426 sdev_printk(KERN_WARNING, sdev,
427 "Asymmetric access state changed");
428 } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x09) {
429 evt_type = SDEV_EVT_CAPACITY_CHANGE_REPORTED;
430 sdev_printk(KERN_WARNING, sdev,
431 "Capacity data has changed");
432 } else if (sshdr->asc == 0x2a)
433 sdev_printk(KERN_WARNING, sdev,
434 "Parameters changed");
437 if (evt_type != SDEV_EVT_MAXBITS) {
438 set_bit(evt_type, sdev->pending_events);
439 schedule_work(&sdev->event_work);
444 * scsi_check_sense - Examine scsi cmd sense
445 * @scmd: Cmd to have sense checked.
448 * SUCCESS or FAILED or NEEDS_RETRY or ADD_TO_MLQUEUE
451 * When a deferred error is detected the current command has
452 * not been executed and needs retrying.
454 int scsi_check_sense(struct scsi_cmnd *scmd)
456 struct scsi_device *sdev = scmd->device;
457 struct scsi_sense_hdr sshdr;
459 if (! scsi_command_normalize_sense(scmd, &sshdr))
460 return FAILED; /* no valid sense data */
462 scsi_report_sense(sdev, &sshdr);
464 if (scsi_sense_is_deferred(&sshdr))
467 if (sdev->handler && sdev->handler->check_sense) {
470 rc = sdev->handler->check_sense(sdev, &sshdr);
471 if (rc != SCSI_RETURN_NOT_HANDLED)
473 /* handler does not care. Drop down to default handling */
476 if (scmd->cmnd[0] == TEST_UNIT_READY && scmd->scsi_done != scsi_eh_done)
478 * nasty: for mid-layer issued TURs, we need to return the
479 * actual sense data without any recovery attempt. For eh
480 * issued ones, we need to try to recover and interpret
485 * Previous logic looked for FILEMARK, EOM or ILI which are
486 * mainly associated with tapes and returned SUCCESS.
488 if (sshdr.response_code == 0x70) {
490 if (scmd->sense_buffer[2] & 0xe0)
494 * descriptor format: look for "stream commands sense data
495 * descriptor" (see SSC-3). Assume single sense data
496 * descriptor. Ignore ILI from SBC-2 READ LONG and WRITE LONG.
498 if ((sshdr.additional_length > 3) &&
499 (scmd->sense_buffer[8] == 0x4) &&
500 (scmd->sense_buffer[11] & 0xe0))
504 switch (sshdr.sense_key) {
507 case RECOVERED_ERROR:
508 return /* soft_error */ SUCCESS;
510 case ABORTED_COMMAND:
511 if (sshdr.asc == 0x10) /* DIF */
518 * if we are expecting a cc/ua because of a bus reset that we
519 * performed, treat this just as a retry. otherwise this is
520 * information that we should pass up to the upper-level driver
521 * so that we can deal with it there.
523 if (scmd->device->expecting_cc_ua) {
525 * Because some device does not queue unit
526 * attentions correctly, we carefully check
527 * additional sense code and qualifier so as
528 * not to squash media change unit attention.
530 if (sshdr.asc != 0x28 || sshdr.ascq != 0x00) {
531 scmd->device->expecting_cc_ua = 0;
536 * we might also expect a cc/ua if another LUN on the target
537 * reported a UA with an ASC/ASCQ of 3F 0E -
538 * REPORTED LUNS DATA HAS CHANGED.
540 if (scmd->device->sdev_target->expecting_lun_change &&
541 sshdr.asc == 0x3f && sshdr.ascq == 0x0e)
544 * if the device is in the process of becoming ready, we
547 if ((sshdr.asc == 0x04) && (sshdr.ascq == 0x01))
550 * if the device is not started, we need to wake
551 * the error handler to start the motor
553 if (scmd->device->allow_restart &&
554 (sshdr.asc == 0x04) && (sshdr.ascq == 0x02))
557 * Pass the UA upwards for a determination in the completion
562 /* these are not supported */
564 if (sshdr.asc == 0x27 && sshdr.ascq == 0x07) {
565 /* Thin provisioning hard threshold reached */
566 set_host_byte(scmd, DID_ALLOC_FAILURE);
571 case VOLUME_OVERFLOW:
574 set_host_byte(scmd, DID_TARGET_FAILURE);
578 if (sshdr.asc == 0x11 || /* UNRECOVERED READ ERR */
579 sshdr.asc == 0x13 || /* AMNF DATA FIELD */
580 sshdr.asc == 0x14) { /* RECORD NOT FOUND */
581 set_host_byte(scmd, DID_MEDIUM_ERROR);
587 if (scmd->device->retry_hwerror)
588 return ADD_TO_MLQUEUE;
590 set_host_byte(scmd, DID_TARGET_FAILURE);
593 case ILLEGAL_REQUEST:
594 if (sshdr.asc == 0x20 || /* Invalid command operation code */
595 sshdr.asc == 0x21 || /* Logical block address out of range */
596 sshdr.asc == 0x24 || /* Invalid field in cdb */
597 sshdr.asc == 0x26 || /* Parameter value invalid */
598 sshdr.asc == 0x27) { /* Write protected */
599 set_host_byte(scmd, DID_TARGET_FAILURE);
607 EXPORT_SYMBOL_GPL(scsi_check_sense);
609 static void scsi_handle_queue_ramp_up(struct scsi_device *sdev)
611 struct scsi_host_template *sht = sdev->host->hostt;
612 struct scsi_device *tmp_sdev;
614 if (!sht->track_queue_depth ||
615 sdev->queue_depth >= sdev->max_queue_depth)
618 if (time_before(jiffies,
619 sdev->last_queue_ramp_up + sdev->queue_ramp_up_period))
622 if (time_before(jiffies,
623 sdev->last_queue_full_time + sdev->queue_ramp_up_period))
627 * Walk all devices of a target and do
630 shost_for_each_device(tmp_sdev, sdev->host) {
631 if (tmp_sdev->channel != sdev->channel ||
632 tmp_sdev->id != sdev->id ||
633 tmp_sdev->queue_depth == sdev->max_queue_depth)
636 scsi_change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1);
637 sdev->last_queue_ramp_up = jiffies;
641 static void scsi_handle_queue_full(struct scsi_device *sdev)
643 struct scsi_host_template *sht = sdev->host->hostt;
644 struct scsi_device *tmp_sdev;
646 if (!sht->track_queue_depth)
649 shost_for_each_device(tmp_sdev, sdev->host) {
650 if (tmp_sdev->channel != sdev->channel ||
651 tmp_sdev->id != sdev->id)
654 * We do not know the number of commands that were at
655 * the device when we got the queue full so we start
656 * from the highest possible value and work our way down.
658 scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1);
663 * scsi_eh_completed_normally - Disposition a eh cmd on return from LLD.
664 * @scmd: SCSI cmd to examine.
667 * This is *only* called when we are examining the status of commands
668 * queued during error recovery. the main difference here is that we
669 * don't allow for the possibility of retries here, and we are a lot
670 * more restrictive about what we consider acceptable.
672 static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)
675 * first check the host byte, to see if there is anything in there
676 * that would indicate what we need to do.
678 if (host_byte(scmd->result) == DID_RESET) {
680 * rats. we are already in the error handler, so we now
681 * get to try and figure out what to do next. if the sense
682 * is valid, we have a pretty good idea of what to do.
683 * if not, we mark it as FAILED.
685 return scsi_check_sense(scmd);
687 if (host_byte(scmd->result) != DID_OK)
691 * next, check the message byte.
693 if (msg_byte(scmd->result) != COMMAND_COMPLETE)
697 * now, check the status byte to see if this indicates
700 switch (status_byte(scmd->result)) {
702 scsi_handle_queue_ramp_up(scmd->device);
704 case COMMAND_TERMINATED:
706 case CHECK_CONDITION:
707 return scsi_check_sense(scmd);
709 case INTERMEDIATE_GOOD:
710 case INTERMEDIATE_C_GOOD:
712 * who knows? FIXME(eric)
715 case RESERVATION_CONFLICT:
716 if (scmd->cmnd[0] == TEST_UNIT_READY)
717 /* it is a success, we probed the device and
720 /* otherwise, we failed to send the command */
723 scsi_handle_queue_full(scmd->device);
734 * scsi_eh_done - Completion function for error handling.
735 * @scmd: Cmd that is done.
737 static void scsi_eh_done(struct scsi_cmnd *scmd)
739 struct completion *eh_action;
741 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
742 "%s result: %x\n", __func__, scmd->result));
744 eh_action = scmd->device->host->eh_action;
750 * scsi_try_host_reset - ask host adapter to reset itself
751 * @scmd: SCSI cmd to send host reset.
753 static int scsi_try_host_reset(struct scsi_cmnd *scmd)
757 struct Scsi_Host *host = scmd->device->host;
758 struct scsi_host_template *hostt = host->hostt;
760 SCSI_LOG_ERROR_RECOVERY(3,
761 shost_printk(KERN_INFO, host, "Snd Host RST\n"));
763 if (!hostt->eh_host_reset_handler)
766 rtn = hostt->eh_host_reset_handler(scmd);
768 if (rtn == SUCCESS) {
769 if (!hostt->skip_settle_delay)
770 ssleep(HOST_RESET_SETTLE_TIME);
771 spin_lock_irqsave(host->host_lock, flags);
772 scsi_report_bus_reset(host, scmd_channel(scmd));
773 spin_unlock_irqrestore(host->host_lock, flags);
780 * scsi_try_bus_reset - ask host to perform a bus reset
781 * @scmd: SCSI cmd to send bus reset.
783 static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
787 struct Scsi_Host *host = scmd->device->host;
788 struct scsi_host_template *hostt = host->hostt;
790 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
791 "%s: Snd Bus RST\n", __func__));
793 if (!hostt->eh_bus_reset_handler)
796 rtn = hostt->eh_bus_reset_handler(scmd);
798 if (rtn == SUCCESS) {
799 if (!hostt->skip_settle_delay)
800 ssleep(BUS_RESET_SETTLE_TIME);
801 spin_lock_irqsave(host->host_lock, flags);
802 scsi_report_bus_reset(host, scmd_channel(scmd));
803 spin_unlock_irqrestore(host->host_lock, flags);
809 static void __scsi_report_device_reset(struct scsi_device *sdev, void *data)
812 sdev->expecting_cc_ua = 1;
816 * scsi_try_target_reset - Ask host to perform a target reset
817 * @scmd: SCSI cmd used to send a target reset
820 * There is no timeout for this operation. if this operation is
821 * unreliable for a given host, then the host itself needs to put a
822 * timer on it, and set the host back to a consistent state prior to
825 static int scsi_try_target_reset(struct scsi_cmnd *scmd)
829 struct Scsi_Host *host = scmd->device->host;
830 struct scsi_host_template *hostt = host->hostt;
832 if (!hostt->eh_target_reset_handler)
835 rtn = hostt->eh_target_reset_handler(scmd);
836 if (rtn == SUCCESS) {
837 spin_lock_irqsave(host->host_lock, flags);
838 __starget_for_each_device(scsi_target(scmd->device), NULL,
839 __scsi_report_device_reset);
840 spin_unlock_irqrestore(host->host_lock, flags);
847 * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
848 * @scmd: SCSI cmd used to send BDR
851 * There is no timeout for this operation. if this operation is
852 * unreliable for a given host, then the host itself needs to put a
853 * timer on it, and set the host back to a consistent state prior to
856 static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
859 struct scsi_host_template *hostt = scmd->device->host->hostt;
861 if (!hostt->eh_device_reset_handler)
864 rtn = hostt->eh_device_reset_handler(scmd);
866 __scsi_report_device_reset(scmd->device, NULL);
871 * scsi_try_to_abort_cmd - Ask host to abort a SCSI command
872 * @hostt: SCSI driver host template
873 * @scmd: SCSI cmd used to send a target reset
876 * SUCCESS, FAILED, or FAST_IO_FAIL
879 * SUCCESS does not necessarily indicate that the command
880 * has been aborted; it only indicates that the LLDDs
881 * has cleared all references to that command.
882 * LLDDs should return FAILED only if an abort was required
883 * but could not be executed. LLDDs should return FAST_IO_FAIL
884 * if the device is temporarily unavailable (eg due to a
885 * link down on FibreChannel)
887 static int scsi_try_to_abort_cmd(struct scsi_host_template *hostt,
888 struct scsi_cmnd *scmd)
890 if (!hostt->eh_abort_handler)
893 return hostt->eh_abort_handler(scmd);
896 static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
898 if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS)
899 if (scsi_try_bus_device_reset(scmd) != SUCCESS)
900 if (scsi_try_target_reset(scmd) != SUCCESS)
901 if (scsi_try_bus_reset(scmd) != SUCCESS)
902 scsi_try_host_reset(scmd);
906 * scsi_eh_prep_cmnd - Save a scsi command info as part of error recovery
907 * @scmd: SCSI command structure to hijack
908 * @ses: structure to save restore information
909 * @cmnd: CDB to send. Can be NULL if no new cmnd is needed
910 * @cmnd_size: size in bytes of @cmnd (must be <= BLK_MAX_CDB)
911 * @sense_bytes: size of sense data to copy. or 0 (if != 0 @cmnd is ignored)
913 * This function is used to save a scsi command information before re-execution
914 * as part of the error recovery process. If @sense_bytes is 0 the command
915 * sent must be one that does not transfer any data. If @sense_bytes != 0
916 * @cmnd is ignored and this functions sets up a REQUEST_SENSE command
917 * and cmnd buffers to read @sense_bytes into @scmd->sense_buffer.
919 void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses,
920 unsigned char *cmnd, int cmnd_size, unsigned sense_bytes)
922 struct scsi_device *sdev = scmd->device;
925 * We need saved copies of a number of fields - this is because
926 * error handling may need to overwrite these with different values
927 * to run different commands, and once error handling is complete,
928 * we will need to restore these values prior to running the actual
931 ses->cmd_len = scmd->cmd_len;
932 ses->cmnd = scmd->cmnd;
933 ses->data_direction = scmd->sc_data_direction;
934 ses->sdb = scmd->sdb;
935 ses->next_rq = scmd->request->next_rq;
936 ses->result = scmd->result;
937 ses->underflow = scmd->underflow;
938 ses->prot_op = scmd->prot_op;
939 ses->eh_eflags = scmd->eh_eflags;
941 scmd->prot_op = SCSI_PROT_NORMAL;
943 scmd->cmnd = ses->eh_cmnd;
944 memset(scmd->cmnd, 0, BLK_MAX_CDB);
945 memset(&scmd->sdb, 0, sizeof(scmd->sdb));
946 scmd->request->next_rq = NULL;
950 scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE,
952 sg_init_one(&ses->sense_sgl, scmd->sense_buffer,
954 scmd->sdb.table.sgl = &ses->sense_sgl;
955 scmd->sc_data_direction = DMA_FROM_DEVICE;
956 scmd->sdb.table.nents = scmd->sdb.table.orig_nents = 1;
957 scmd->cmnd[0] = REQUEST_SENSE;
958 scmd->cmnd[4] = scmd->sdb.length;
959 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
961 scmd->sc_data_direction = DMA_NONE;
963 BUG_ON(cmnd_size > BLK_MAX_CDB);
964 memcpy(scmd->cmnd, cmnd, cmnd_size);
965 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
971 if (sdev->scsi_level <= SCSI_2 && sdev->scsi_level != SCSI_UNKNOWN)
972 scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) |
973 (sdev->lun << 5 & 0xe0);
976 * Zero the sense buffer. The scsi spec mandates that any
977 * untransferred sense data should be interpreted as being zero.
979 memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
981 EXPORT_SYMBOL(scsi_eh_prep_cmnd);
984 * scsi_eh_restore_cmnd - Restore a scsi command info as part of error recovery
985 * @scmd: SCSI command structure to restore
986 * @ses: saved information from a coresponding call to scsi_eh_prep_cmnd
988 * Undo any damage done by above scsi_eh_prep_cmnd().
990 void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct scsi_eh_save *ses)
993 * Restore original data
995 scmd->cmd_len = ses->cmd_len;
996 scmd->cmnd = ses->cmnd;
997 scmd->sc_data_direction = ses->data_direction;
998 scmd->sdb = ses->sdb;
999 scmd->request->next_rq = ses->next_rq;
1000 scmd->result = ses->result;
1001 scmd->underflow = ses->underflow;
1002 scmd->prot_op = ses->prot_op;
1003 scmd->eh_eflags = ses->eh_eflags;
1005 EXPORT_SYMBOL(scsi_eh_restore_cmnd);
1008 * scsi_send_eh_cmnd - submit a scsi command as part of error recovery
1009 * @scmd: SCSI command structure to hijack
1010 * @cmnd: CDB to send
1011 * @cmnd_size: size in bytes of @cmnd
1012 * @timeout: timeout for this request
1013 * @sense_bytes: size of sense data to copy or 0
1015 * This function is used to send a scsi command down to a target device
1016 * as part of the error recovery process. See also scsi_eh_prep_cmnd() above.
1019 * SUCCESS or FAILED or NEEDS_RETRY
1021 static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, unsigned char *cmnd,
1022 int cmnd_size, int timeout, unsigned sense_bytes)
1024 struct scsi_device *sdev = scmd->device;
1025 struct Scsi_Host *shost = sdev->host;
1026 DECLARE_COMPLETION_ONSTACK(done);
1027 unsigned long timeleft = timeout;
1028 struct scsi_eh_save ses;
1029 const unsigned long stall_for = msecs_to_jiffies(100);
1033 scsi_eh_prep_cmnd(scmd, &ses, cmnd, cmnd_size, sense_bytes);
1034 shost->eh_action = &done;
1036 scsi_log_send(scmd);
1037 scmd->scsi_done = scsi_eh_done;
1038 rtn = shost->hostt->queuecommand(shost, scmd);
1040 if (timeleft > stall_for) {
1041 scsi_eh_restore_cmnd(scmd, &ses);
1042 timeleft -= stall_for;
1043 msleep(jiffies_to_msecs(stall_for));
1046 /* signal not to enter either branch of the if () below */
1050 timeleft = wait_for_completion_timeout(&done, timeout);
1054 shost->eh_action = NULL;
1056 scsi_log_completion(scmd, rtn);
1058 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
1059 "%s timeleft: %ld\n",
1060 __func__, timeleft));
1063 * If there is time left scsi_eh_done got called, and we will examine
1064 * the actual status codes to see whether the command actually did
1065 * complete normally, else if we have a zero return and no time left,
1066 * the command must still be pending, so abort it and return FAILED.
1067 * If we never actually managed to issue the command, because
1068 * ->queuecommand() kept returning non zero, use the rtn = FAILED
1069 * value above (so don't execute either branch of the if)
1072 rtn = scsi_eh_completed_normally(scmd);
1073 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
1074 "%s: scsi_eh_completed_normally %x\n", __func__, rtn));
1081 case ADD_TO_MLQUEUE:
1088 } else if (rtn != FAILED) {
1089 scsi_abort_eh_cmnd(scmd);
1093 scsi_eh_restore_cmnd(scmd, &ses);
1099 * scsi_request_sense - Request sense data from a particular target.
1100 * @scmd: SCSI cmd for request sense.
1103 * Some hosts automatically obtain this information, others require
1104 * that we obtain it on our own. This function will *not* return until
1105 * the command either times out, or it completes.
1107 static int scsi_request_sense(struct scsi_cmnd *scmd)
1109 return scsi_send_eh_cmnd(scmd, NULL, 0, scmd->device->eh_timeout, ~0);
1112 static int scsi_eh_action(struct scsi_cmnd *scmd, int rtn)
1114 if (!blk_rq_is_passthrough(scmd->request)) {
1115 struct scsi_driver *sdrv = scsi_cmd_to_driver(scmd);
1116 if (sdrv->eh_action)
1117 rtn = sdrv->eh_action(scmd, rtn);
1123 * scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
1124 * @scmd: Original SCSI cmd that eh has finished.
1125 * @done_q: Queue for processed commands.
1128 * We don't want to use the normal command completion while we are are
1129 * still handling errors - it may cause other commands to be queued,
1130 * and that would disturb what we are doing. Thus we really want to
1131 * keep a list of pending commands for final completion, and once we
1132 * are ready to leave error handling we handle completion for real.
1134 void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q)
1136 list_move_tail(&scmd->eh_entry, done_q);
1138 EXPORT_SYMBOL(scsi_eh_finish_cmd);
1141 * scsi_eh_get_sense - Get device sense data.
1142 * @work_q: Queue of commands to process.
1143 * @done_q: Queue of processed commands.
1146 * See if we need to request sense information. if so, then get it
1147 * now, so we have a better idea of what to do.
1150 * This has the unfortunate side effect that if a shost adapter does
1151 * not automatically request sense information, we end up shutting
1152 * it down before we request it.
1154 * All drivers should request sense information internally these days,
1155 * so for now all I have to say is tough noogies if you end up in here.
1157 * XXX: Long term this code should go away, but that needs an audit of
1160 int scsi_eh_get_sense(struct list_head *work_q,
1161 struct list_head *done_q)
1163 struct scsi_cmnd *scmd, *next;
1164 struct Scsi_Host *shost;
1168 * If SCSI_EH_ABORT_SCHEDULED has been set, it is timeout IO,
1169 * should not get sense.
1171 list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
1172 if ((scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) ||
1173 SCSI_SENSE_VALID(scmd))
1176 shost = scmd->device->host;
1177 if (scsi_host_eh_past_deadline(shost)) {
1178 SCSI_LOG_ERROR_RECOVERY(3,
1179 scmd_printk(KERN_INFO, scmd,
1180 "%s: skip request sense, past eh deadline\n",
1184 if (status_byte(scmd->result) != CHECK_CONDITION)
1186 * don't request sense if there's no check condition
1187 * status because the error we're processing isn't one
1188 * that has a sense code (and some devices get
1189 * confused by sense requests out of the blue)
1193 SCSI_LOG_ERROR_RECOVERY(2, scmd_printk(KERN_INFO, scmd,
1194 "%s: requesting sense\n",
1196 rtn = scsi_request_sense(scmd);
1200 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
1201 "sense requested, result %x\n", scmd->result));
1202 SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense(scmd));
1204 rtn = scsi_decide_disposition(scmd);
1207 * if the result was normal, then just pass it along to the
1211 /* we don't want this command reissued, just
1212 * finished with the sense data, so set
1213 * retries to the max allowed to ensure it
1214 * won't get reissued */
1215 scmd->retries = scmd->allowed;
1216 else if (rtn != NEEDS_RETRY)
1219 scsi_eh_finish_cmd(scmd, done_q);
1222 return list_empty(work_q);
1224 EXPORT_SYMBOL_GPL(scsi_eh_get_sense);
1227 * scsi_eh_tur - Send TUR to device.
1228 * @scmd: &scsi_cmnd to send TUR
1231 * 0 - Device is ready. 1 - Device NOT ready.
1233 static int scsi_eh_tur(struct scsi_cmnd *scmd)
1235 static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0};
1236 int retry_cnt = 1, rtn;
1239 rtn = scsi_send_eh_cmnd(scmd, tur_command, 6,
1240 scmd->device->eh_timeout, 0);
1242 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
1243 "%s return: %x\n", __func__, rtn));
1258 * scsi_eh_test_devices - check if devices are responding from error recovery.
1259 * @cmd_list: scsi commands in error recovery.
1260 * @work_q: queue for commands which still need more error recovery
1261 * @done_q: queue for commands which are finished
1262 * @try_stu: boolean on if a STU command should be tried in addition to TUR.
1265 * Tests if devices are in a working state. Commands to devices now in
1266 * a working state are sent to the done_q while commands to devices which
1267 * are still failing to respond are returned to the work_q for more
1270 static int scsi_eh_test_devices(struct list_head *cmd_list,
1271 struct list_head *work_q,
1272 struct list_head *done_q, int try_stu)
1274 struct scsi_cmnd *scmd, *next;
1275 struct scsi_device *sdev;
1278 while (!list_empty(cmd_list)) {
1279 scmd = list_entry(cmd_list->next, struct scsi_cmnd, eh_entry);
1280 sdev = scmd->device;
1283 if (scsi_host_eh_past_deadline(sdev->host)) {
1284 /* Push items back onto work_q */
1285 list_splice_init(cmd_list, work_q);
1286 SCSI_LOG_ERROR_RECOVERY(3,
1287 sdev_printk(KERN_INFO, sdev,
1288 "%s: skip test device, past eh deadline",
1294 finish_cmds = !scsi_device_online(scmd->device) ||
1295 (try_stu && !scsi_eh_try_stu(scmd) &&
1296 !scsi_eh_tur(scmd)) ||
1299 list_for_each_entry_safe(scmd, next, cmd_list, eh_entry)
1300 if (scmd->device == sdev) {
1303 scsi_eh_action(scmd, SUCCESS) == SUCCESS))
1304 scsi_eh_finish_cmd(scmd, done_q);
1306 list_move_tail(&scmd->eh_entry, work_q);
1309 return list_empty(work_q);
1313 * scsi_eh_try_stu - Send START_UNIT to device.
1314 * @scmd: &scsi_cmnd to send START_UNIT
1317 * 0 - Device is ready. 1 - Device NOT ready.
1319 static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
1321 static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0};
1323 if (scmd->device->allow_restart) {
1324 int i, rtn = NEEDS_RETRY;
1326 for (i = 0; rtn == NEEDS_RETRY && i < 2; i++)
1327 rtn = scsi_send_eh_cmnd(scmd, stu_command, 6, scmd->device->request_queue->rq_timeout, 0);
1337 * scsi_eh_stu - send START_UNIT if needed
1338 * @shost: &scsi host being recovered.
1339 * @work_q: &list_head for pending commands.
1340 * @done_q: &list_head for processed commands.
1343 * If commands are failing due to not ready, initializing command required,
1344 * try revalidating the device, which will end up sending a start unit.
1346 static int scsi_eh_stu(struct Scsi_Host *shost,
1347 struct list_head *work_q,
1348 struct list_head *done_q)
1350 struct scsi_cmnd *scmd, *stu_scmd, *next;
1351 struct scsi_device *sdev;
1353 shost_for_each_device(sdev, shost) {
1354 if (scsi_host_eh_past_deadline(shost)) {
1355 SCSI_LOG_ERROR_RECOVERY(3,
1356 sdev_printk(KERN_INFO, sdev,
1357 "%s: skip START_UNIT, past eh deadline\n",
1362 list_for_each_entry(scmd, work_q, eh_entry)
1363 if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) &&
1364 scsi_check_sense(scmd) == FAILED ) {
1372 SCSI_LOG_ERROR_RECOVERY(3,
1373 sdev_printk(KERN_INFO, sdev,
1374 "%s: Sending START_UNIT\n",
1377 if (!scsi_eh_try_stu(stu_scmd)) {
1378 if (!scsi_device_online(sdev) ||
1379 !scsi_eh_tur(stu_scmd)) {
1380 list_for_each_entry_safe(scmd, next,
1382 if (scmd->device == sdev &&
1383 scsi_eh_action(scmd, SUCCESS) == SUCCESS)
1384 scsi_eh_finish_cmd(scmd, done_q);
1388 SCSI_LOG_ERROR_RECOVERY(3,
1389 sdev_printk(KERN_INFO, sdev,
1390 "%s: START_UNIT failed\n",
1395 return list_empty(work_q);
1400 * scsi_eh_bus_device_reset - send bdr if needed
1401 * @shost: scsi host being recovered.
1402 * @work_q: &list_head for pending commands.
1403 * @done_q: &list_head for processed commands.
1406 * Try a bus device reset. Still, look to see whether we have multiple
1407 * devices that are jammed or not - if we have multiple devices, it
1408 * makes no sense to try bus_device_reset - we really would need to try
1409 * a bus_reset instead.
1411 static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
1412 struct list_head *work_q,
1413 struct list_head *done_q)
1415 struct scsi_cmnd *scmd, *bdr_scmd, *next;
1416 struct scsi_device *sdev;
1419 shost_for_each_device(sdev, shost) {
1420 if (scsi_host_eh_past_deadline(shost)) {
1421 SCSI_LOG_ERROR_RECOVERY(3,
1422 sdev_printk(KERN_INFO, sdev,
1423 "%s: skip BDR, past eh deadline\n",
1428 list_for_each_entry(scmd, work_q, eh_entry)
1429 if (scmd->device == sdev) {
1437 SCSI_LOG_ERROR_RECOVERY(3,
1438 sdev_printk(KERN_INFO, sdev,
1439 "%s: Sending BDR\n", current->comm));
1440 rtn = scsi_try_bus_device_reset(bdr_scmd);
1441 if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
1442 if (!scsi_device_online(sdev) ||
1443 rtn == FAST_IO_FAIL ||
1444 !scsi_eh_tur(bdr_scmd)) {
1445 list_for_each_entry_safe(scmd, next,
1447 if (scmd->device == sdev &&
1448 scsi_eh_action(scmd, rtn) != FAILED)
1449 scsi_eh_finish_cmd(scmd,
1454 SCSI_LOG_ERROR_RECOVERY(3,
1455 sdev_printk(KERN_INFO, sdev,
1456 "%s: BDR failed\n", current->comm));
1460 return list_empty(work_q);
1464 * scsi_eh_target_reset - send target reset if needed
1465 * @shost: scsi host being recovered.
1466 * @work_q: &list_head for pending commands.
1467 * @done_q: &list_head for processed commands.
1470 * Try a target reset.
1472 static int scsi_eh_target_reset(struct Scsi_Host *shost,
1473 struct list_head *work_q,
1474 struct list_head *done_q)
1476 LIST_HEAD(tmp_list);
1477 LIST_HEAD(check_list);
1479 list_splice_init(work_q, &tmp_list);
1481 while (!list_empty(&tmp_list)) {
1482 struct scsi_cmnd *next, *scmd;
1486 if (scsi_host_eh_past_deadline(shost)) {
1487 /* push back on work queue for further processing */
1488 list_splice_init(&check_list, work_q);
1489 list_splice_init(&tmp_list, work_q);
1490 SCSI_LOG_ERROR_RECOVERY(3,
1491 shost_printk(KERN_INFO, shost,
1492 "%s: Skip target reset, past eh deadline\n",
1494 return list_empty(work_q);
1497 scmd = list_entry(tmp_list.next, struct scsi_cmnd, eh_entry);
1500 SCSI_LOG_ERROR_RECOVERY(3,
1501 shost_printk(KERN_INFO, shost,
1502 "%s: Sending target reset to target %d\n",
1503 current->comm, id));
1504 rtn = scsi_try_target_reset(scmd);
1505 if (rtn != SUCCESS && rtn != FAST_IO_FAIL)
1506 SCSI_LOG_ERROR_RECOVERY(3,
1507 shost_printk(KERN_INFO, shost,
1508 "%s: Target reset failed"
1510 current->comm, id));
1511 list_for_each_entry_safe(scmd, next, &tmp_list, eh_entry) {
1512 if (scmd_id(scmd) != id)
1516 list_move_tail(&scmd->eh_entry, &check_list);
1517 else if (rtn == FAST_IO_FAIL)
1518 scsi_eh_finish_cmd(scmd, done_q);
1520 /* push back on work queue for further processing */
1521 list_move(&scmd->eh_entry, work_q);
1525 return scsi_eh_test_devices(&check_list, work_q, done_q, 0);
1529 * scsi_eh_bus_reset - send a bus reset
1530 * @shost: &scsi host being recovered.
1531 * @work_q: &list_head for pending commands.
1532 * @done_q: &list_head for processed commands.
1534 static int scsi_eh_bus_reset(struct Scsi_Host *shost,
1535 struct list_head *work_q,
1536 struct list_head *done_q)
1538 struct scsi_cmnd *scmd, *chan_scmd, *next;
1539 LIST_HEAD(check_list);
1540 unsigned int channel;
1544 * we really want to loop over the various channels, and do this on
1545 * a channel by channel basis. we should also check to see if any
1546 * of the failed commands are on soft_reset devices, and if so, skip
1550 for (channel = 0; channel <= shost->max_channel; channel++) {
1551 if (scsi_host_eh_past_deadline(shost)) {
1552 list_splice_init(&check_list, work_q);
1553 SCSI_LOG_ERROR_RECOVERY(3,
1554 shost_printk(KERN_INFO, shost,
1555 "%s: skip BRST, past eh deadline\n",
1557 return list_empty(work_q);
1561 list_for_each_entry(scmd, work_q, eh_entry) {
1562 if (channel == scmd_channel(scmd)) {
1566 * FIXME add back in some support for
1567 * soft_reset devices.
1574 SCSI_LOG_ERROR_RECOVERY(3,
1575 shost_printk(KERN_INFO, shost,
1576 "%s: Sending BRST chan: %d\n",
1577 current->comm, channel));
1578 rtn = scsi_try_bus_reset(chan_scmd);
1579 if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
1580 list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
1581 if (channel == scmd_channel(scmd)) {
1582 if (rtn == FAST_IO_FAIL)
1583 scsi_eh_finish_cmd(scmd,
1586 list_move_tail(&scmd->eh_entry,
1591 SCSI_LOG_ERROR_RECOVERY(3,
1592 shost_printk(KERN_INFO, shost,
1593 "%s: BRST failed chan: %d\n",
1594 current->comm, channel));
1597 return scsi_eh_test_devices(&check_list, work_q, done_q, 0);
1601 * scsi_eh_host_reset - send a host reset
1602 * @shost: host to be reset.
1603 * @work_q: &list_head for pending commands.
1604 * @done_q: &list_head for processed commands.
1606 static int scsi_eh_host_reset(struct Scsi_Host *shost,
1607 struct list_head *work_q,
1608 struct list_head *done_q)
1610 struct scsi_cmnd *scmd, *next;
1611 LIST_HEAD(check_list);
1614 if (!list_empty(work_q)) {
1615 scmd = list_entry(work_q->next,
1616 struct scsi_cmnd, eh_entry);
1618 SCSI_LOG_ERROR_RECOVERY(3,
1619 shost_printk(KERN_INFO, shost,
1620 "%s: Sending HRST\n",
1623 rtn = scsi_try_host_reset(scmd);
1624 if (rtn == SUCCESS) {
1625 list_splice_init(work_q, &check_list);
1626 } else if (rtn == FAST_IO_FAIL) {
1627 list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
1628 scsi_eh_finish_cmd(scmd, done_q);
1631 SCSI_LOG_ERROR_RECOVERY(3,
1632 shost_printk(KERN_INFO, shost,
1633 "%s: HRST failed\n",
1637 return scsi_eh_test_devices(&check_list, work_q, done_q, 1);
1641 * scsi_eh_offline_sdevs - offline scsi devices that fail to recover
1642 * @work_q: &list_head for pending commands.
1643 * @done_q: &list_head for processed commands.
1645 static void scsi_eh_offline_sdevs(struct list_head *work_q,
1646 struct list_head *done_q)
1648 struct scsi_cmnd *scmd, *next;
1649 struct scsi_device *sdev;
1651 list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
1652 sdev_printk(KERN_INFO, scmd->device, "Device offlined - "
1653 "not ready after error recovery\n");
1654 sdev = scmd->device;
1656 mutex_lock(&sdev->state_mutex);
1657 scsi_device_set_state(sdev, SDEV_OFFLINE);
1658 mutex_unlock(&sdev->state_mutex);
1660 scsi_eh_finish_cmd(scmd, done_q);
1666 * scsi_noretry_cmd - determine if command should be failed fast
1667 * @scmd: SCSI cmd to examine.
1669 int scsi_noretry_cmd(struct scsi_cmnd *scmd)
1671 switch (host_byte(scmd->result)) {
1677 return (scmd->request->cmd_flags & REQ_FAILFAST_TRANSPORT);
1679 return (scmd->request->cmd_flags & REQ_FAILFAST_DEV);
1681 if (msg_byte(scmd->result) == COMMAND_COMPLETE &&
1682 status_byte(scmd->result) == RESERVATION_CONFLICT)
1685 case DID_SOFT_ERROR:
1686 return (scmd->request->cmd_flags & REQ_FAILFAST_DRIVER);
1689 if (status_byte(scmd->result) != CHECK_CONDITION)
1694 * assume caller has checked sense and determined
1695 * the check condition was retryable.
1697 if (scmd->request->cmd_flags & REQ_FAILFAST_DEV ||
1698 blk_rq_is_passthrough(scmd->request))
1705 * scsi_decide_disposition - Disposition a cmd on return from LLD.
1706 * @scmd: SCSI cmd to examine.
1709 * This is *only* called when we are examining the status after sending
1710 * out the actual data command. any commands that are queued for error
1711 * recovery (e.g. test_unit_ready) do *not* come through here.
1713 * When this routine returns failed, it means the error handler thread
1714 * is woken. In cases where the error code indicates an error that
1715 * doesn't require the error handler read (i.e. we don't need to
1716 * abort/reset), this function should return SUCCESS.
1718 int scsi_decide_disposition(struct scsi_cmnd *scmd)
1723 * if the device is offline, then we clearly just pass the result back
1724 * up to the top level.
1726 if (!scsi_device_online(scmd->device)) {
1727 SCSI_LOG_ERROR_RECOVERY(5, scmd_printk(KERN_INFO, scmd,
1728 "%s: device offline - report as SUCCESS\n", __func__));
1733 * first check the host byte, to see if there is anything in there
1734 * that would indicate what we need to do.
1736 switch (host_byte(scmd->result)) {
1737 case DID_PASSTHROUGH:
1739 * no matter what, pass this through to the upper layer.
1740 * nuke this special code so that it looks like we are saying
1743 scmd->result &= 0xff00ffff;
1747 * looks good. drop through, and check the next byte.
1751 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) {
1752 set_host_byte(scmd, DID_TIME_OUT);
1756 case DID_NO_CONNECT:
1757 case DID_BAD_TARGET:
1759 * note - this means that we just report the status back
1760 * to the top level driver, not that we actually think
1761 * that it indicates SUCCESS.
1765 * when the low level driver returns did_soft_error,
1766 * it is responsible for keeping an internal retry counter
1767 * in order to avoid endless loops (db)
1769 * actually this is a bug in this function here. we should
1770 * be mindful of the maximum number of retries specified
1771 * and not get stuck in a loop.
1773 case DID_SOFT_ERROR:
1779 return ADD_TO_MLQUEUE;
1780 case DID_TRANSPORT_DISRUPTED:
1782 * LLD/transport was disrupted during processing of the IO.
1783 * The transport class is now blocked/blocking,
1784 * and the transport will decide what to do with the IO
1785 * based on its timers and recovery capablilities if
1786 * there are enough retries.
1789 case DID_TRANSPORT_FAILFAST:
1791 * The transport decided to failfast the IO (most likely
1792 * the fast io fail tmo fired), so send IO directly upwards.
1796 if (msg_byte(scmd->result) == COMMAND_COMPLETE &&
1797 status_byte(scmd->result) == RESERVATION_CONFLICT)
1799 * execute reservation conflict processing code
1809 * when we scan the bus, we get timeout messages for
1810 * these commands if there is no device available.
1811 * other hosts report did_no_connect for the same thing.
1813 if ((scmd->cmnd[0] == TEST_UNIT_READY ||
1814 scmd->cmnd[0] == INQUIRY)) {
1826 * next, check the message byte.
1828 if (msg_byte(scmd->result) != COMMAND_COMPLETE)
1832 * check the status byte to see if this indicates anything special.
1834 switch (status_byte(scmd->result)) {
1836 scsi_handle_queue_full(scmd->device);
1838 * the case of trying to send too many commands to a
1839 * tagged queueing device.
1844 * device can't talk to us at the moment. Should only
1845 * occur (SAM-3) when the task queue is empty, so will cause
1846 * the empty queue handling to trigger a stall in the
1849 return ADD_TO_MLQUEUE;
1851 if (scmd->cmnd[0] == REPORT_LUNS)
1852 scmd->device->sdev_target->expecting_lun_change = 0;
1853 scsi_handle_queue_ramp_up(scmd->device);
1855 case COMMAND_TERMINATED:
1859 case CHECK_CONDITION:
1860 rtn = scsi_check_sense(scmd);
1861 if (rtn == NEEDS_RETRY)
1863 /* if rtn == FAILED, we have no sense information;
1864 * returning FAILED will wake the error handler thread
1865 * to collect the sense and redo the decide
1868 case CONDITION_GOOD:
1869 case INTERMEDIATE_GOOD:
1870 case INTERMEDIATE_C_GOOD:
1873 * who knows? FIXME(eric)
1877 case RESERVATION_CONFLICT:
1878 sdev_printk(KERN_INFO, scmd->device,
1879 "reservation conflict\n");
1880 set_host_byte(scmd, DID_NEXUS_FAILURE);
1881 return SUCCESS; /* causes immediate i/o error */
1889 /* we requeue for retry because the error was retryable, and
1890 * the request was not marked fast fail. Note that above,
1891 * even if the request is marked fast fail, we still requeue
1892 * for queue congestion conditions (QUEUE_FULL or BUSY) */
1893 if ((++scmd->retries) <= scmd->allowed
1894 && !scsi_noretry_cmd(scmd)) {
1898 * no more retries - report this one back to upper level.
1904 static void eh_lock_door_done(struct request *req, blk_status_t status)
1906 __blk_put_request(req->q, req);
1910 * scsi_eh_lock_door - Prevent medium removal for the specified device
1911 * @sdev: SCSI device to prevent medium removal
1914 * We must be called from process context.
1917 * We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the
1918 * head of the devices request queue, and continue.
1920 static void scsi_eh_lock_door(struct scsi_device *sdev)
1922 struct request *req;
1923 struct scsi_request *rq;
1926 * blk_get_request with GFP_KERNEL (__GFP_RECLAIM) sleeps until a
1927 * request becomes available
1929 req = blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, GFP_KERNEL);
1934 rq->cmd[0] = ALLOW_MEDIUM_REMOVAL;
1938 rq->cmd[4] = SCSI_REMOVAL_PREVENT;
1940 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
1942 req->rq_flags |= RQF_QUIET;
1943 req->timeout = 10 * HZ;
1946 blk_execute_rq_nowait(req->q, NULL, req, 1, eh_lock_door_done);
1950 * scsi_restart_operations - restart io operations to the specified host.
1951 * @shost: Host we are restarting.
1954 * When we entered the error handler, we blocked all further i/o to
1955 * this device. we need to 'reverse' this process.
1957 static void scsi_restart_operations(struct Scsi_Host *shost)
1959 struct scsi_device *sdev;
1960 unsigned long flags;
1963 * If the door was locked, we need to insert a door lock request
1964 * onto the head of the SCSI request queue for the device. There
1965 * is no point trying to lock the door of an off-line device.
1967 shost_for_each_device(sdev, shost) {
1968 if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) {
1969 scsi_eh_lock_door(sdev);
1970 sdev->was_reset = 0;
1975 * next free up anything directly waiting upon the host. this
1976 * will be requests for character device operations, and also for
1977 * ioctls to queued block devices.
1979 SCSI_LOG_ERROR_RECOVERY(3,
1980 shost_printk(KERN_INFO, shost, "waking up host to restart\n"));
1982 spin_lock_irqsave(shost->host_lock, flags);
1983 if (scsi_host_set_state(shost, SHOST_RUNNING))
1984 if (scsi_host_set_state(shost, SHOST_CANCEL))
1985 BUG_ON(scsi_host_set_state(shost, SHOST_DEL));
1986 spin_unlock_irqrestore(shost->host_lock, flags);
1988 wake_up(&shost->host_wait);
1991 * finally we need to re-initiate requests that may be pending. we will
1992 * have had everything blocked while error handling is taking place, and
1993 * now that error recovery is done, we will need to ensure that these
1994 * requests are started.
1996 scsi_run_host_queues(shost);
1999 * if eh is active and host_eh_scheduled is pending we need to re-run
2000 * recovery. we do this check after scsi_run_host_queues() to allow
2001 * everything pent up since the last eh run a chance to make forward
2002 * progress before we sync again. Either we'll immediately re-run
2003 * recovery or scsi_device_unbusy() will wake us again when these
2004 * pending commands complete.
2006 spin_lock_irqsave(shost->host_lock, flags);
2007 if (shost->host_eh_scheduled)
2008 if (scsi_host_set_state(shost, SHOST_RECOVERY))
2009 WARN_ON(scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY));
2010 spin_unlock_irqrestore(shost->host_lock, flags);
2014 * scsi_eh_ready_devs - check device ready state and recover if not.
2015 * @shost: host to be recovered.
2016 * @work_q: &list_head for pending commands.
2017 * @done_q: &list_head for processed commands.
2019 void scsi_eh_ready_devs(struct Scsi_Host *shost,
2020 struct list_head *work_q,
2021 struct list_head *done_q)
2023 if (!scsi_eh_stu(shost, work_q, done_q))
2024 if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
2025 if (!scsi_eh_target_reset(shost, work_q, done_q))
2026 if (!scsi_eh_bus_reset(shost, work_q, done_q))
2027 if (!scsi_eh_host_reset(shost, work_q, done_q))
2028 scsi_eh_offline_sdevs(work_q,
2031 EXPORT_SYMBOL_GPL(scsi_eh_ready_devs);
2034 * scsi_eh_flush_done_q - finish processed commands or retry them.
2035 * @done_q: list_head of processed commands.
2037 void scsi_eh_flush_done_q(struct list_head *done_q)
2039 struct scsi_cmnd *scmd, *next;
2041 list_for_each_entry_safe(scmd, next, done_q, eh_entry) {
2042 list_del_init(&scmd->eh_entry);
2043 if (scsi_device_online(scmd->device) &&
2044 !scsi_noretry_cmd(scmd) &&
2045 (++scmd->retries <= scmd->allowed)) {
2046 SCSI_LOG_ERROR_RECOVERY(3,
2047 scmd_printk(KERN_INFO, scmd,
2048 "%s: flush retry cmd\n",
2050 scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
2053 * If just we got sense for the device (called
2054 * scsi_eh_get_sense), scmd->result is already
2055 * set, do not set DRIVER_TIMEOUT.
2058 scmd->result |= (DRIVER_TIMEOUT << 24);
2059 SCSI_LOG_ERROR_RECOVERY(3,
2060 scmd_printk(KERN_INFO, scmd,
2061 "%s: flush finish cmd\n",
2063 scsi_finish_command(scmd);
2067 EXPORT_SYMBOL(scsi_eh_flush_done_q);
2070 * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
2071 * @shost: Host to unjam.
2074 * When we come in here, we *know* that all commands on the bus have
2075 * either completed, failed or timed out. we also know that no further
2076 * commands are being sent to the host, so things are relatively quiet
2077 * and we have freedom to fiddle with things as we wish.
2079 * This is only the *default* implementation. it is possible for
2080 * individual drivers to supply their own version of this function, and
2081 * if the maintainer wishes to do this, it is strongly suggested that
2082 * this function be taken as a template and modified. this function
2083 * was designed to correctly handle problems for about 95% of the
2084 * different cases out there, and it should always provide at least a
2085 * reasonable amount of error recovery.
2087 * Any command marked 'failed' or 'timeout' must eventually have
2088 * scsi_finish_cmd() called for it. we do all of the retry stuff
2089 * here, so when we restart the host after we return it should have an
2092 static void scsi_unjam_host(struct Scsi_Host *shost)
2094 unsigned long flags;
2095 LIST_HEAD(eh_work_q);
2096 LIST_HEAD(eh_done_q);
2098 spin_lock_irqsave(shost->host_lock, flags);
2099 list_splice_init(&shost->eh_cmd_q, &eh_work_q);
2100 spin_unlock_irqrestore(shost->host_lock, flags);
2102 SCSI_LOG_ERROR_RECOVERY(1, scsi_eh_prt_fail_stats(shost, &eh_work_q));
2104 if (!scsi_eh_get_sense(&eh_work_q, &eh_done_q))
2105 scsi_eh_ready_devs(shost, &eh_work_q, &eh_done_q);
2107 spin_lock_irqsave(shost->host_lock, flags);
2108 if (shost->eh_deadline != -1)
2109 shost->last_reset = 0;
2110 spin_unlock_irqrestore(shost->host_lock, flags);
2111 scsi_eh_flush_done_q(&eh_done_q);
2115 * scsi_error_handler - SCSI error handler thread
2116 * @data: Host for which we are running.
2119 * This is the main error handling loop. This is run as a kernel thread
2120 * for every SCSI host and handles all error handling activity.
2122 int scsi_error_handler(void *data)
2124 struct Scsi_Host *shost = data;
2127 * We use TASK_INTERRUPTIBLE so that the thread is not
2128 * counted against the load average as a running process.
2129 * We never actually get interrupted because kthread_run
2130 * disables signal delivery for the created thread.
2134 * The sequence in kthread_stop() sets the stop flag first
2135 * then wakes the process. To avoid missed wakeups, the task
2136 * should always be in a non running state before the stop
2139 set_current_state(TASK_INTERRUPTIBLE);
2140 if (kthread_should_stop())
2143 if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) ||
2144 shost->host_failed != atomic_read(&shost->host_busy)) {
2145 SCSI_LOG_ERROR_RECOVERY(1,
2146 shost_printk(KERN_INFO, shost,
2147 "scsi_eh_%d: sleeping\n",
2153 __set_current_state(TASK_RUNNING);
2154 SCSI_LOG_ERROR_RECOVERY(1,
2155 shost_printk(KERN_INFO, shost,
2156 "scsi_eh_%d: waking up %d/%d/%d\n",
2157 shost->host_no, shost->host_eh_scheduled,
2159 atomic_read(&shost->host_busy)));
2162 * We have a host that is failing for some reason. Figure out
2163 * what we need to do to get it up and online again (if we can).
2164 * If we fail, we end up taking the thing offline.
2166 if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) {
2167 SCSI_LOG_ERROR_RECOVERY(1,
2168 shost_printk(KERN_ERR, shost,
2169 "scsi_eh_%d: unable to autoresume\n",
2174 if (shost->transportt->eh_strategy_handler)
2175 shost->transportt->eh_strategy_handler(shost);
2177 scsi_unjam_host(shost);
2179 /* All scmds have been handled */
2180 shost->host_failed = 0;
2183 * Note - if the above fails completely, the action is to take
2184 * individual devices offline and flush the queue of any
2185 * outstanding requests that may have been pending. When we
2186 * restart, we restart any I/O to any other devices on the bus
2187 * which are still online.
2189 scsi_restart_operations(shost);
2190 if (!shost->eh_noresume)
2191 scsi_autopm_put_host(shost);
2193 __set_current_state(TASK_RUNNING);
2195 SCSI_LOG_ERROR_RECOVERY(1,
2196 shost_printk(KERN_INFO, shost,
2197 "Error handler scsi_eh_%d exiting\n",
2199 shost->ehandler = NULL;
2204 * Function: scsi_report_bus_reset()
2206 * Purpose: Utility function used by low-level drivers to report that
2207 * they have observed a bus reset on the bus being handled.
2209 * Arguments: shost - Host in question
2210 * channel - channel on which reset was observed.
2214 * Lock status: Host lock must be held.
2216 * Notes: This only needs to be called if the reset is one which
2217 * originates from an unknown location. Resets originated
2218 * by the mid-level itself don't need to call this, but there
2219 * should be no harm.
2221 * The main purpose of this is to make sure that a CHECK_CONDITION
2222 * is properly treated.
2224 void scsi_report_bus_reset(struct Scsi_Host *shost, int channel)
2226 struct scsi_device *sdev;
2228 __shost_for_each_device(sdev, shost) {
2229 if (channel == sdev_channel(sdev))
2230 __scsi_report_device_reset(sdev, NULL);
2233 EXPORT_SYMBOL(scsi_report_bus_reset);
2236 * Function: scsi_report_device_reset()
2238 * Purpose: Utility function used by low-level drivers to report that
2239 * they have observed a device reset on the device being handled.
2241 * Arguments: shost - Host in question
2242 * channel - channel on which reset was observed
2243 * target - target on which reset was observed
2247 * Lock status: Host lock must be held
2249 * Notes: This only needs to be called if the reset is one which
2250 * originates from an unknown location. Resets originated
2251 * by the mid-level itself don't need to call this, but there
2252 * should be no harm.
2254 * The main purpose of this is to make sure that a CHECK_CONDITION
2255 * is properly treated.
2257 void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
2259 struct scsi_device *sdev;
2261 __shost_for_each_device(sdev, shost) {
2262 if (channel == sdev_channel(sdev) &&
2263 target == sdev_id(sdev))
2264 __scsi_report_device_reset(sdev, NULL);
2267 EXPORT_SYMBOL(scsi_report_device_reset);
2270 scsi_reset_provider_done_command(struct scsi_cmnd *scmd)
2275 * scsi_ioctl_reset: explicitly reset a host/bus/target/device
2276 * @dev: scsi_device to operate on
2277 * @arg: reset type (see sg.h)
2280 scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
2282 struct scsi_cmnd *scmd;
2283 struct Scsi_Host *shost = dev->host;
2285 unsigned long flags;
2286 int error = 0, rtn, val;
2288 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
2291 error = get_user(val, arg);
2295 if (scsi_autopm_get_host(shost) < 0)
2299 rq = kzalloc(sizeof(struct request) + sizeof(struct scsi_cmnd) +
2300 shost->hostt->cmd_size, GFP_KERNEL);
2302 goto out_put_autopm_host;
2303 blk_rq_init(NULL, rq);
2305 scmd = (struct scsi_cmnd *)(rq + 1);
2306 scsi_init_command(dev, scmd);
2308 scmd->cmnd = scsi_req(rq)->cmd;
2310 scmd->scsi_done = scsi_reset_provider_done_command;
2311 memset(&scmd->sdb, 0, sizeof(scmd->sdb));
2315 scmd->sc_data_direction = DMA_BIDIRECTIONAL;
2317 spin_lock_irqsave(shost->host_lock, flags);
2318 shost->tmf_in_progress = 1;
2319 spin_unlock_irqrestore(shost->host_lock, flags);
2321 switch (val & ~SG_SCSI_RESET_NO_ESCALATE) {
2322 case SG_SCSI_RESET_NOTHING:
2325 case SG_SCSI_RESET_DEVICE:
2326 rtn = scsi_try_bus_device_reset(scmd);
2327 if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
2330 case SG_SCSI_RESET_TARGET:
2331 rtn = scsi_try_target_reset(scmd);
2332 if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
2335 case SG_SCSI_RESET_BUS:
2336 rtn = scsi_try_bus_reset(scmd);
2337 if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
2340 case SG_SCSI_RESET_HOST:
2341 rtn = scsi_try_host_reset(scmd);
2350 error = (rtn == SUCCESS) ? 0 : -EIO;
2352 spin_lock_irqsave(shost->host_lock, flags);
2353 shost->tmf_in_progress = 0;
2354 spin_unlock_irqrestore(shost->host_lock, flags);
2357 * be sure to wake up anyone who was sleeping or had their queue
2358 * suspended while we performed the TMF.
2360 SCSI_LOG_ERROR_RECOVERY(3,
2361 shost_printk(KERN_INFO, shost,
2362 "waking up host to restart after TMF\n"));
2364 wake_up(&shost->host_wait);
2365 scsi_run_host_queues(shost);
2367 scsi_put_command(scmd);
2370 out_put_autopm_host:
2371 scsi_autopm_put_host(shost);
2374 EXPORT_SYMBOL(scsi_ioctl_reset);
2376 bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd,
2377 struct scsi_sense_hdr *sshdr)
2379 return scsi_normalize_sense(cmd->sense_buffer,
2380 SCSI_SENSE_BUFFERSIZE, sshdr);
2382 EXPORT_SYMBOL(scsi_command_normalize_sense);
2385 * scsi_get_sense_info_fld - get information field from sense data (either fixed or descriptor format)
2386 * @sense_buffer: byte array of sense data
2387 * @sb_len: number of valid bytes in sense_buffer
2388 * @info_out: pointer to 64 integer where 8 or 4 byte information
2389 * field will be placed if found.
2392 * true if information field found, false if not found.
2394 bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len,
2401 switch (sense_buffer[0] & 0x7f) {
2404 if (sense_buffer[0] & 0x80) {
2405 *info_out = get_unaligned_be32(&sense_buffer[3]);
2411 ucp = scsi_sense_desc_find(sense_buffer, sb_len,
2413 if (ucp && (0xa == ucp[1])) {
2414 *info_out = get_unaligned_be64(&ucp[4]);
2422 EXPORT_SYMBOL(scsi_get_sense_info_fld);