Lines Matching +full:host +full:- +full:command

1 // SPDX-License-Identifier: GPL-2.0-only
56 * These should *probably* be handled by the host itself.
68 lockdep_assert_held(shost->host_lock); in scsi_eh_wakeup()
70 if (scsi_host_busy(shost) == shost->host_failed) { in scsi_eh_wakeup()
72 wake_up_process(shost->ehandler); in scsi_eh_wakeup()
79 * scsi_schedule_eh - schedule EH for SCSI host
80 * @shost: SCSI host to invoke error handling on.
88 spin_lock_irqsave(shost->host_lock, flags); in scsi_schedule_eh()
92 shost->host_eh_scheduled++; in scsi_schedule_eh()
96 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_schedule_eh()
102 if (!shost->last_reset || shost->eh_deadline == -1) in scsi_host_eh_past_deadline()
112 if (time_before(jiffies, shost->last_reset + shost->eh_deadline) && in scsi_host_eh_past_deadline()
113 shost->eh_deadline > -1) in scsi_host_eh_past_deadline()
121 if (cmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT) in scsi_cmd_retry_allowed()
124 return ++cmd->retries <= cmd->allowed; in scsi_cmd_retry_allowed()
129 struct scsi_device *sdev = cmd->device; in scsi_eh_should_retry_cmd()
130 struct Scsi_Host *host = sdev->host; in scsi_eh_should_retry_cmd() local
132 if (host->hostt->eh_should_retry_cmd) in scsi_eh_should_retry_cmd()
133 return host->hostt->eh_should_retry_cmd(cmd); in scsi_eh_should_retry_cmd()
139 * scmd_eh_abort_handler - Handle command aborts
140 * @work: command to be aborted.
142 * Note: this function must be called only for a command that has timed out.
144 * scsi_times_out(), a .scsi_done() call from the LLD for a command that has
153 struct scsi_device *sdev = scmd->device; in scmd_eh_abort_handler()
156 if (scsi_host_eh_past_deadline(sdev->host)) { in scmd_eh_abort_handler()
163 "aborting command\n")); in scmd_eh_abort_handler()
164 rtn = scsi_try_to_abort_cmd(sdev->host->hostt, scmd); in scmd_eh_abort_handler()
167 if (scsi_host_eh_past_deadline(sdev->host)) { in scmd_eh_abort_handler()
171 "aborted command\n")); in scmd_eh_abort_handler()
177 "retry aborted command\n")); in scmd_eh_abort_handler()
183 "finish aborted command\n")); in scmd_eh_abort_handler()
200 * scsi_abort_command - schedule a command abort
203 * We only need to abort commands after a command timeout
208 struct scsi_device *sdev = scmd->device; in scsi_abort_command()
209 struct Scsi_Host *shost = sdev->host; in scsi_abort_command()
212 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) { in scsi_abort_command()
219 BUG_ON(delayed_work_pending(&scmd->abort_work)); in scsi_abort_command()
223 spin_lock_irqsave(shost->host_lock, flags); in scsi_abort_command()
224 if (shost->eh_deadline != -1 && !shost->last_reset) in scsi_abort_command()
225 shost->last_reset = jiffies; in scsi_abort_command()
226 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_abort_command()
228 scmd->eh_eflags |= SCSI_EH_ABORT_SCHEDULED; in scsi_abort_command()
231 queue_delayed_work(shost->tmf_work_q, &scmd->abort_work, HZ / 100); in scsi_abort_command()
236 * scsi_eh_reset - call into ->eh_action to reset internal counters
247 if (sdrv->eh_reset) in scsi_eh_reset()
248 sdrv->eh_reset(scmd); in scsi_eh_reset()
255 struct Scsi_Host *shost = scmd->device->host; in scsi_eh_inc_host_failed()
258 spin_lock_irqsave(shost->host_lock, flags); in scsi_eh_inc_host_failed()
259 shost->host_failed++; in scsi_eh_inc_host_failed()
261 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_eh_inc_host_failed()
265 * scsi_eh_scmd_add - add scsi cmd to error handling.
270 struct Scsi_Host *shost = scmd->device->host; in scsi_eh_scmd_add()
274 WARN_ON_ONCE(!shost->ehandler); in scsi_eh_scmd_add()
276 spin_lock_irqsave(shost->host_lock, flags); in scsi_eh_scmd_add()
281 if (shost->eh_deadline != -1 && !shost->last_reset) in scsi_eh_scmd_add()
282 shost->last_reset = jiffies; in scsi_eh_scmd_add()
285 list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q); in scsi_eh_scmd_add()
286 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_eh_scmd_add()
288 * Ensure that all tasks observe the host state change before the in scsi_eh_scmd_add()
291 call_rcu(&scmd->rcu, scsi_eh_inc_host_failed); in scsi_eh_scmd_add()
295 * scsi_times_out - Timeout function for normal scsi commands.
308 struct Scsi_Host *host = scmd->device->host; in scsi_times_out() local
313 if (host->eh_deadline != -1 && !host->last_reset) in scsi_times_out()
314 host->last_reset = jiffies; in scsi_times_out()
316 if (host->hostt->eh_timed_out) in scsi_times_out()
317 rtn = host->hostt->eh_timed_out(scmd); in scsi_times_out()
321 * Set the command to complete first in order to prevent a real in scsi_times_out()
322 * completion from releasing the command while error handling in scsi_times_out()
323 * is using it. If the command was already completed, then the in scsi_times_out()
330 * at this command. in scsi_times_out()
332 if (test_and_set_bit(SCMD_STATE_COMPLETE, &scmd->state)) in scsi_times_out()
344 * scsi_block_when_processing_errors - Prevent cmds from being queued.
348 * We block until the host is out of error recovery, and then check to
349 * see whether the host or the device is offline.
358 wait_event(sdev->host->host_wait, !scsi_host_in_recovery(sdev->host)); in scsi_block_when_processing_errors()
368 * scsi_eh_prt_fail_stats - Log info on failures.
369 * @shost: scsi host being recovered.
384 if (scmd->device == sdev) { in scsi_eh_prt_fail_stats()
386 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) in scsi_eh_prt_fail_stats()
413 * scsi_report_lun_change - Set flag on all *other* devices on the same target
419 sdev->sdev_target->expecting_lun_change = 1; in scsi_report_lun_change()
423 * scsi_report_sense - Examine scsi sense information and log messages for
433 if (sshdr->sense_key == UNIT_ATTENTION) { in scsi_report_sense()
434 if (sshdr->asc == 0x3f && sshdr->ascq == 0x03) { in scsi_report_sense()
438 } else if (sshdr->asc == 0x3f && sshdr->ascq == 0x0e) { in scsi_report_sense()
446 } else if (sshdr->asc == 0x3f) in scsi_report_sense()
453 if (sshdr->asc == 0x38 && sshdr->ascq == 0x07) { in scsi_report_sense()
461 if (sshdr->asc == 0x29) { in scsi_report_sense()
464 "Power-on or device reset occurred\n"); in scsi_report_sense()
467 if (sshdr->asc == 0x2a && sshdr->ascq == 0x01) { in scsi_report_sense()
471 } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x06) { in scsi_report_sense()
475 } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x09) { in scsi_report_sense()
479 } else if (sshdr->asc == 0x2a) in scsi_report_sense()
485 set_bit(evt_type, sdev->pending_events); in scsi_report_sense()
486 schedule_work(&sdev->event_work); in scsi_report_sense()
491 * scsi_check_sense - Examine scsi cmd sense
498 * When a deferred error is detected the current command has
503 struct scsi_device *sdev = scmd->device; in scsi_check_sense()
514 if (sdev->handler && sdev->handler->check_sense) { in scsi_check_sense()
517 rc = sdev->handler->check_sense(sdev, &sshdr); in scsi_check_sense()
523 if (scmd->cmnd[0] == TEST_UNIT_READY && scmd->scsi_done != scsi_eh_done) in scsi_check_sense()
525 * nasty: for mid-layer issued TURs, we need to return the in scsi_check_sense()
537 if (scmd->sense_buffer[2] & 0xe0) in scsi_check_sense()
542 * descriptor" (see SSC-3). Assume single sense data in scsi_check_sense()
543 * descriptor. Ignore ILI from SBC-2 READ LONG and WRITE LONG. in scsi_check_sense()
546 (scmd->sense_buffer[8] == 0x4) && in scsi_check_sense()
547 (scmd->sense_buffer[11] & 0xe0)) in scsi_check_sense()
561 if (sshdr.asc == 0x44 && sdev->sdev_bflags & BLIST_RETRY_ITF) in scsi_check_sense()
564 sdev->sdev_bflags & BLIST_RETRY_ASC_C1) in scsi_check_sense()
573 * information that we should pass up to the upper-level driver in scsi_check_sense()
576 if (scmd->device->expecting_cc_ua) { in scsi_check_sense()
584 scmd->device->expecting_cc_ua = 0; in scsi_check_sense()
590 * reported a UA with an ASC/ASCQ of 3F 0E - in scsi_check_sense()
593 if (scmd->device->sdev_target->expecting_lun_change && in scsi_check_sense()
606 if (scmd->device->allow_restart && in scsi_check_sense()
640 if (scmd->device->retry_hwerror) in scsi_check_sense()
647 if (sshdr.asc == 0x20 || /* Invalid command operation code */ in scsi_check_sense()
665 struct scsi_host_template *sht = sdev->host->hostt; in scsi_handle_queue_ramp_up()
668 if (!sht->track_queue_depth || in scsi_handle_queue_ramp_up()
669 sdev->queue_depth >= sdev->max_queue_depth) in scsi_handle_queue_ramp_up()
673 sdev->last_queue_ramp_up + sdev->queue_ramp_up_period)) in scsi_handle_queue_ramp_up()
677 sdev->last_queue_full_time + sdev->queue_ramp_up_period)) in scsi_handle_queue_ramp_up()
684 shost_for_each_device(tmp_sdev, sdev->host) { in scsi_handle_queue_ramp_up()
685 if (tmp_sdev->channel != sdev->channel || in scsi_handle_queue_ramp_up()
686 tmp_sdev->id != sdev->id || in scsi_handle_queue_ramp_up()
687 tmp_sdev->queue_depth == sdev->max_queue_depth) in scsi_handle_queue_ramp_up()
690 scsi_change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1); in scsi_handle_queue_ramp_up()
691 sdev->last_queue_ramp_up = jiffies; in scsi_handle_queue_ramp_up()
697 struct scsi_host_template *sht = sdev->host->hostt; in scsi_handle_queue_full()
700 if (!sht->track_queue_depth) in scsi_handle_queue_full()
703 shost_for_each_device(tmp_sdev, sdev->host) { in scsi_handle_queue_full()
704 if (tmp_sdev->channel != sdev->channel || in scsi_handle_queue_full()
705 tmp_sdev->id != sdev->id) in scsi_handle_queue_full()
712 scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1); in scsi_handle_queue_full()
717 * scsi_eh_completed_normally - Disposition a eh cmd on return from LLD.
729 * first check the host byte, to see if there is anything in there in scsi_eh_completed_normally()
732 if (host_byte(scmd->result) == DID_RESET) { in scsi_eh_completed_normally()
741 if (host_byte(scmd->result) != DID_OK) in scsi_eh_completed_normally()
750 scsi_handle_queue_ramp_up(scmd->device); in scsi_eh_completed_normally()
764 if (scmd->cmnd[0] == TEST_UNIT_READY) in scsi_eh_completed_normally()
768 /* otherwise, we failed to send the command */ in scsi_eh_completed_normally()
771 scsi_handle_queue_full(scmd->device); in scsi_eh_completed_normally()
782 * scsi_eh_done - Completion function for error handling.
790 "%s result: %x\n", __func__, scmd->result)); in scsi_eh_done()
792 eh_action = scmd->device->host->eh_action; in scsi_eh_done()
798 * scsi_try_host_reset - ask host adapter to reset itself
799 * @scmd: SCSI cmd to send host reset.
805 struct Scsi_Host *host = scmd->device->host; in scsi_try_host_reset() local
806 struct scsi_host_template *hostt = host->hostt; in scsi_try_host_reset()
809 shost_printk(KERN_INFO, host, "Snd Host RST\n")); in scsi_try_host_reset()
811 if (!hostt->eh_host_reset_handler) in scsi_try_host_reset()
814 rtn = hostt->eh_host_reset_handler(scmd); in scsi_try_host_reset()
817 if (!hostt->skip_settle_delay) in scsi_try_host_reset()
819 spin_lock_irqsave(host->host_lock, flags); in scsi_try_host_reset()
820 scsi_report_bus_reset(host, scmd_channel(scmd)); in scsi_try_host_reset()
821 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_host_reset()
828 * scsi_try_bus_reset - ask host to perform a bus reset
835 struct Scsi_Host *host = scmd->device->host; in scsi_try_bus_reset() local
836 struct scsi_host_template *hostt = host->hostt; in scsi_try_bus_reset()
841 if (!hostt->eh_bus_reset_handler) in scsi_try_bus_reset()
844 rtn = hostt->eh_bus_reset_handler(scmd); in scsi_try_bus_reset()
847 if (!hostt->skip_settle_delay) in scsi_try_bus_reset()
849 spin_lock_irqsave(host->host_lock, flags); in scsi_try_bus_reset()
850 scsi_report_bus_reset(host, scmd_channel(scmd)); in scsi_try_bus_reset()
851 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_bus_reset()
859 sdev->was_reset = 1; in __scsi_report_device_reset()
860 sdev->expecting_cc_ua = 1; in __scsi_report_device_reset()
864 * scsi_try_target_reset - Ask host to perform a target reset
869 * unreliable for a given host, then the host itself needs to put a
870 * timer on it, and set the host back to a consistent state prior to
877 struct Scsi_Host *host = scmd->device->host; in scsi_try_target_reset() local
878 struct scsi_host_template *hostt = host->hostt; in scsi_try_target_reset()
880 if (!hostt->eh_target_reset_handler) in scsi_try_target_reset()
883 rtn = hostt->eh_target_reset_handler(scmd); in scsi_try_target_reset()
885 spin_lock_irqsave(host->host_lock, flags); in scsi_try_target_reset()
886 __starget_for_each_device(scsi_target(scmd->device), NULL, in scsi_try_target_reset()
888 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_target_reset()
895 * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
900 * unreliable for a given host, then the host itself needs to put a
901 * timer on it, and set the host back to a consistent state prior to
907 struct scsi_host_template *hostt = scmd->device->host->hostt; in scsi_try_bus_device_reset()
909 if (!hostt->eh_device_reset_handler) in scsi_try_bus_device_reset()
912 rtn = hostt->eh_device_reset_handler(scmd); in scsi_try_bus_device_reset()
914 __scsi_report_device_reset(scmd->device, NULL); in scsi_try_bus_device_reset()
919 * scsi_try_to_abort_cmd - Ask host to abort a SCSI command
920 * @hostt: SCSI driver host template
927 * SUCCESS does not necessarily indicate that the command
929 * has cleared all references to that command.
938 if (!hostt->eh_abort_handler) in scsi_try_to_abort_cmd()
941 return hostt->eh_abort_handler(scmd); in scsi_try_to_abort_cmd()
946 if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS) in scsi_abort_eh_cmnd()
954 * scsi_eh_prep_cmnd - Save a scsi command info as part of error recovery
955 * @scmd: SCSI command structure to hijack
961 * This function is used to save a scsi command information before re-execution
962 * as part of the error recovery process. If @sense_bytes is 0 the command
964 * @cmnd is ignored and this functions sets up a REQUEST_SENSE command
965 * and cmnd buffers to read @sense_bytes into @scmd->sense_buffer.
970 struct scsi_device *sdev = scmd->device; in scsi_eh_prep_cmnd()
973 * We need saved copies of a number of fields - this is because in scsi_eh_prep_cmnd()
977 * command. in scsi_eh_prep_cmnd()
979 ses->cmd_len = scmd->cmd_len; in scsi_eh_prep_cmnd()
980 ses->cmnd = scmd->cmnd; in scsi_eh_prep_cmnd()
981 ses->data_direction = scmd->sc_data_direction; in scsi_eh_prep_cmnd()
982 ses->sdb = scmd->sdb; in scsi_eh_prep_cmnd()
983 ses->result = scmd->result; in scsi_eh_prep_cmnd()
984 ses->resid_len = scmd->req.resid_len; in scsi_eh_prep_cmnd()
985 ses->underflow = scmd->underflow; in scsi_eh_prep_cmnd()
986 ses->prot_op = scmd->prot_op; in scsi_eh_prep_cmnd()
987 ses->eh_eflags = scmd->eh_eflags; in scsi_eh_prep_cmnd()
989 scmd->prot_op = SCSI_PROT_NORMAL; in scsi_eh_prep_cmnd()
990 scmd->eh_eflags = 0; in scsi_eh_prep_cmnd()
991 scmd->cmnd = ses->eh_cmnd; in scsi_eh_prep_cmnd()
992 memset(scmd->cmnd, 0, BLK_MAX_CDB); in scsi_eh_prep_cmnd()
993 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); in scsi_eh_prep_cmnd()
994 scmd->result = 0; in scsi_eh_prep_cmnd()
995 scmd->req.resid_len = 0; in scsi_eh_prep_cmnd()
998 scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE, in scsi_eh_prep_cmnd()
1000 sg_init_one(&ses->sense_sgl, scmd->sense_buffer, in scsi_eh_prep_cmnd()
1001 scmd->sdb.length); in scsi_eh_prep_cmnd()
1002 scmd->sdb.table.sgl = &ses->sense_sgl; in scsi_eh_prep_cmnd()
1003 scmd->sc_data_direction = DMA_FROM_DEVICE; in scsi_eh_prep_cmnd()
1004 scmd->sdb.table.nents = scmd->sdb.table.orig_nents = 1; in scsi_eh_prep_cmnd()
1005 scmd->cmnd[0] = REQUEST_SENSE; in scsi_eh_prep_cmnd()
1006 scmd->cmnd[4] = scmd->sdb.length; in scsi_eh_prep_cmnd()
1007 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_prep_cmnd()
1009 scmd->sc_data_direction = DMA_NONE; in scsi_eh_prep_cmnd()
1012 memcpy(scmd->cmnd, cmnd, cmnd_size); in scsi_eh_prep_cmnd()
1013 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_prep_cmnd()
1017 scmd->underflow = 0; in scsi_eh_prep_cmnd()
1019 if (sdev->scsi_level <= SCSI_2 && sdev->scsi_level != SCSI_UNKNOWN) in scsi_eh_prep_cmnd()
1020 scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) | in scsi_eh_prep_cmnd()
1021 (sdev->lun << 5 & 0xe0); in scsi_eh_prep_cmnd()
1027 memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in scsi_eh_prep_cmnd()
1032 * scsi_eh_restore_cmnd - Restore a scsi command info as part of error recovery
1033 * @scmd: SCSI command structure to restore
1043 scmd->cmd_len = ses->cmd_len; in scsi_eh_restore_cmnd()
1044 scmd->cmnd = ses->cmnd; in scsi_eh_restore_cmnd()
1045 scmd->sc_data_direction = ses->data_direction; in scsi_eh_restore_cmnd()
1046 scmd->sdb = ses->sdb; in scsi_eh_restore_cmnd()
1047 scmd->result = ses->result; in scsi_eh_restore_cmnd()
1048 scmd->req.resid_len = ses->resid_len; in scsi_eh_restore_cmnd()
1049 scmd->underflow = ses->underflow; in scsi_eh_restore_cmnd()
1050 scmd->prot_op = ses->prot_op; in scsi_eh_restore_cmnd()
1051 scmd->eh_eflags = ses->eh_eflags; in scsi_eh_restore_cmnd()
1056 * scsi_send_eh_cmnd - submit a scsi command as part of error recovery
1057 * @scmd: SCSI command structure to hijack
1063 * This function is used to send a scsi command down to a target device
1072 struct scsi_device *sdev = scmd->device; in scsi_send_eh_cmnd()
1073 struct Scsi_Host *shost = sdev->host; in scsi_send_eh_cmnd()
1082 shost->eh_action = &done; in scsi_send_eh_cmnd()
1085 scmd->scsi_done = scsi_eh_done; in scsi_send_eh_cmnd()
1088 * Lock sdev->state_mutex to avoid that scsi_device_quiesce() can in scsi_send_eh_cmnd()
1092 mutex_lock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1093 while (sdev->sdev_state == SDEV_BLOCK && timeleft > 0) { in scsi_send_eh_cmnd()
1094 mutex_unlock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1096 "%s: state %d <> %d\n", __func__, sdev->sdev_state, in scsi_send_eh_cmnd()
1099 timeleft -= delay; in scsi_send_eh_cmnd()
1101 mutex_lock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1103 if (sdev->sdev_state != SDEV_BLOCK) in scsi_send_eh_cmnd()
1104 rtn = shost->hostt->queuecommand(shost, scmd); in scsi_send_eh_cmnd()
1107 mutex_unlock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1112 timeleft -= stall_for; in scsi_send_eh_cmnd()
1124 shost->eh_action = NULL; in scsi_send_eh_cmnd()
1134 * the actual status codes to see whether the command actually did in scsi_send_eh_cmnd()
1136 * the command must still be pending, so abort it and return FAILED. in scsi_send_eh_cmnd()
1137 * If we never actually managed to issue the command, because in scsi_send_eh_cmnd()
1138 * ->queuecommand() kept returning non zero, use the rtn = FAILED in scsi_send_eh_cmnd()
1169 * scsi_request_sense - Request sense data from a particular target.
1175 * the command either times out, or it completes.
1179 return scsi_send_eh_cmnd(scmd, NULL, 0, scmd->device->eh_timeout, ~0); in scsi_request_sense()
1187 if (sdrv->eh_action) in scsi_eh_action()
1188 rtn = sdrv->eh_action(scmd, rtn); in scsi_eh_action()
1194 * scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
1199 * We don't want to use the normal command completion while we are are
1200 * still handling errors - it may cause other commands to be queued,
1207 list_move_tail(&scmd->eh_entry, done_q); in scsi_eh_finish_cmd()
1212 * scsi_eh_get_sense - Get device sense data.
1243 if ((scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) || in scsi_eh_get_sense()
1247 shost = scmd->device->host; in scsi_eh_get_sense()
1252 current->comm)); in scsi_eh_get_sense()
1255 if (!scsi_status_is_check_condition(scmd->result)) in scsi_eh_get_sense()
1266 current->comm)); in scsi_eh_get_sense()
1272 "sense requested, result %x\n", scmd->result)); in scsi_eh_get_sense()
1283 * We don't want this command reissued, just finished in scsi_eh_get_sense()
1287 * finish this command, so force completion by setting in scsi_eh_get_sense()
1290 if (scmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT) in scsi_eh_get_sense()
1291 scmd->retries = scmd->allowed = 1; in scsi_eh_get_sense()
1293 scmd->retries = scmd->allowed; in scsi_eh_get_sense()
1305 * scsi_eh_tur - Send TUR to device.
1309 * 0 - Device is ready. 1 - Device NOT ready.
1319 scmd->device->eh_timeout, 0); in scsi_eh_tur()
1326 if (retry_cnt--) in scsi_eh_tur()
1337 * scsi_eh_test_devices - check if devices are responding from error recovery.
1341 * @try_stu: boolean on if a STU command should be tried in addition to TUR.
1358 scmd = list_entry(cmd_list->next, struct scsi_cmnd, eh_entry); in scsi_eh_test_devices()
1359 sdev = scmd->device; in scsi_eh_test_devices()
1362 if (scsi_host_eh_past_deadline(sdev->host)) { in scsi_eh_test_devices()
1368 current->comm)); in scsi_eh_test_devices()
1373 finish_cmds = !scsi_device_online(scmd->device) || in scsi_eh_test_devices()
1379 if (scmd->device == sdev) { in scsi_eh_test_devices()
1385 list_move_tail(&scmd->eh_entry, work_q); in scsi_eh_test_devices()
1392 * scsi_eh_try_stu - Send START_UNIT to device.
1396 * 0 - Device is ready. 1 - Device NOT ready.
1402 if (scmd->device->allow_restart) { in scsi_eh_try_stu()
1407 rtn = scsi_send_eh_cmnd(scmd, stu_command, 6, scmd->device->request_queue->rq_timeout, 0); in scsi_eh_try_stu()
1417 * scsi_eh_stu - send START_UNIT if needed
1418 * @shost: &scsi host being recovered.
1423 * If commands are failing due to not ready, initializing command required,
1438 current->comm)); in scsi_eh_stu()
1444 if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) && in scsi_eh_stu()
1456 current->comm)); in scsi_eh_stu()
1463 if (scmd->device == sdev && in scsi_eh_stu()
1472 current->comm)); in scsi_eh_stu()
1481 * scsi_eh_bus_device_reset - send bdr if needed
1482 * @shost: scsi host being recovered.
1488 * devices that are jammed or not - if we have multiple devices, it
1489 * makes no sense to try bus_device_reset - we really would need to try
1505 current->comm)); in scsi_eh_bus_device_reset()
1511 if (scmd->device == sdev) { in scsi_eh_bus_device_reset()
1521 "%s: Sending BDR\n", current->comm)); in scsi_eh_bus_device_reset()
1529 if (scmd->device == sdev && in scsi_eh_bus_device_reset()
1538 "%s: BDR failed\n", current->comm)); in scsi_eh_bus_device_reset()
1546 * scsi_eh_target_reset - send target reset if needed
1547 * @shost: scsi host being recovered.
1575 current->comm)); in scsi_eh_target_reset()
1585 current->comm, id)); in scsi_eh_target_reset()
1592 current->comm, id)); in scsi_eh_target_reset()
1598 list_move_tail(&scmd->eh_entry, &check_list); in scsi_eh_target_reset()
1603 list_move(&scmd->eh_entry, work_q); in scsi_eh_target_reset()
1611 * scsi_eh_bus_reset - send a bus reset
1612 * @shost: &scsi host being recovered.
1632 for (channel = 0; channel <= shost->max_channel; channel++) { in scsi_eh_bus_reset()
1638 current->comm)); in scsi_eh_bus_reset()
1659 current->comm, channel)); in scsi_eh_bus_reset()
1668 list_move_tail(&scmd->eh_entry, in scsi_eh_bus_reset()
1676 current->comm, channel)); in scsi_eh_bus_reset()
1683 * scsi_eh_host_reset - send a host reset
1684 * @shost: host to be reset.
1697 scmd = list_entry(work_q->next, in scsi_eh_host_reset()
1703 current->comm)); in scsi_eh_host_reset()
1716 current->comm)); in scsi_eh_host_reset()
1723 * scsi_eh_offline_sdevs - offline scsi devices that fail to recover
1734 sdev_printk(KERN_INFO, scmd->device, "Device offlined - " in scsi_eh_offline_sdevs()
1736 sdev = scmd->device; in scsi_eh_offline_sdevs()
1738 mutex_lock(&sdev->state_mutex); in scsi_eh_offline_sdevs()
1740 mutex_unlock(&sdev->state_mutex); in scsi_eh_offline_sdevs()
1748 * scsi_noretry_cmd - determine if command should be failed fast
1755 switch (host_byte(scmd->result)) { in scsi_noretry_cmd()
1761 return req->cmd_flags & REQ_FAILFAST_TRANSPORT; in scsi_noretry_cmd()
1763 return req->cmd_flags & REQ_FAILFAST_DEV; in scsi_noretry_cmd()
1769 return req->cmd_flags & REQ_FAILFAST_DRIVER; in scsi_noretry_cmd()
1772 if (!scsi_status_is_check_condition(scmd->result)) in scsi_noretry_cmd()
1780 if (req->cmd_flags & REQ_FAILFAST_DEV || blk_rq_is_passthrough(req)) in scsi_noretry_cmd()
1787 * scsi_decide_disposition - Disposition a cmd on return from LLD.
1792 * out the actual data command. any commands that are queued for error
1808 if (!scsi_device_online(scmd->device)) { in scsi_decide_disposition()
1810 "%s: device offline - report as SUCCESS\n", __func__)); in scsi_decide_disposition()
1815 * first check the host byte, to see if there is anything in there in scsi_decide_disposition()
1818 switch (host_byte(scmd->result)) { in scsi_decide_disposition()
1825 scmd->result &= 0xff00ffff; in scsi_decide_disposition()
1833 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) { in scsi_decide_disposition()
1841 * note - this means that we just report the status back in scsi_decide_disposition()
1896 if ((scmd->cmnd[0] == TEST_UNIT_READY || in scsi_decide_disposition()
1897 scmd->cmnd[0] == INQUIRY)) { in scsi_decide_disposition()
1913 scsi_handle_queue_full(scmd->device); in scsi_decide_disposition()
1922 * occur (SAM-3) when the task queue is empty, so will cause in scsi_decide_disposition()
1928 if (scmd->cmnd[0] == REPORT_LUNS) in scsi_decide_disposition()
1929 scmd->device->sdev_target->expecting_lun_change = 0; in scsi_decide_disposition()
1930 scsi_handle_queue_ramp_up(scmd->device); in scsi_decide_disposition()
1955 sdev_printk(KERN_INFO, scmd->device, in scsi_decide_disposition()
1974 * no more retries - report this one back to upper level. in scsi_decide_disposition()
1986 * scsi_eh_lock_door - Prevent medium removal for the specified device
2001 req = blk_get_request(sdev->request_queue, REQ_OP_DRV_IN, 0); in scsi_eh_lock_door()
2006 rq->cmd[0] = ALLOW_MEDIUM_REMOVAL; in scsi_eh_lock_door()
2007 rq->cmd[1] = 0; in scsi_eh_lock_door()
2008 rq->cmd[2] = 0; in scsi_eh_lock_door()
2009 rq->cmd[3] = 0; in scsi_eh_lock_door()
2010 rq->cmd[4] = SCSI_REMOVAL_PREVENT; in scsi_eh_lock_door()
2011 rq->cmd[5] = 0; in scsi_eh_lock_door()
2012 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]); in scsi_eh_lock_door()
2014 req->rq_flags |= RQF_QUIET; in scsi_eh_lock_door()
2015 req->timeout = 10 * HZ; in scsi_eh_lock_door()
2016 rq->retries = 5; in scsi_eh_lock_door()
2022 * scsi_restart_operations - restart io operations to the specified host.
2023 * @shost: Host we are restarting.
2037 * is no point trying to lock the door of an off-line device. in scsi_restart_operations()
2040 if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) { in scsi_restart_operations()
2042 sdev->was_reset = 0; in scsi_restart_operations()
2047 * next free up anything directly waiting upon the host. this in scsi_restart_operations()
2052 shost_printk(KERN_INFO, shost, "waking up host to restart\n")); in scsi_restart_operations()
2054 spin_lock_irqsave(shost->host_lock, flags); in scsi_restart_operations()
2058 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_restart_operations()
2060 wake_up(&shost->host_wait); in scsi_restart_operations()
2063 * finally we need to re-initiate requests that may be pending. we will in scsi_restart_operations()
2071 * if eh is active and host_eh_scheduled is pending we need to re-run in scsi_restart_operations()
2074 * progress before we sync again. Either we'll immediately re-run in scsi_restart_operations()
2078 spin_lock_irqsave(shost->host_lock, flags); in scsi_restart_operations()
2079 if (shost->host_eh_scheduled) in scsi_restart_operations()
2082 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_restart_operations()
2086 * scsi_eh_ready_devs - check device ready state and recover if not.
2087 * @shost: host to be recovered.
2106 * scsi_eh_flush_done_q - finish processed commands or retry them.
2114 list_del_init(&scmd->eh_entry); in scsi_eh_flush_done_q()
2115 if (scsi_device_online(scmd->device) && in scsi_eh_flush_done_q()
2121 current->comm)); in scsi_eh_flush_done_q()
2126 * scsi_eh_get_sense), scmd->result is already in scsi_eh_flush_done_q()
2129 if (!scmd->result) in scsi_eh_flush_done_q()
2130 scmd->result |= (DID_TIME_OUT << 16); in scsi_eh_flush_done_q()
2134 current->comm)); in scsi_eh_flush_done_q()
2142 * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
2143 * @shost: Host to unjam.
2148 * commands are being sent to the host, so things are relatively quiet
2159 * Any command marked 'failed' or 'timeout' must eventually have
2161 * here, so when we restart the host after we return it should have an
2170 spin_lock_irqsave(shost->host_lock, flags); in scsi_unjam_host()
2171 list_splice_init(&shost->eh_cmd_q, &eh_work_q); in scsi_unjam_host()
2172 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_unjam_host()
2179 spin_lock_irqsave(shost->host_lock, flags); in scsi_unjam_host()
2180 if (shost->eh_deadline != -1) in scsi_unjam_host()
2181 shost->last_reset = 0; in scsi_unjam_host()
2182 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_unjam_host()
2187 * scsi_error_handler - SCSI error handler thread
2188 * @data: Host for which we are running.
2192 * for every SCSI host and handles all error handling activity.
2215 if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) || in scsi_error_handler()
2216 shost->host_failed != scsi_host_busy(shost)) { in scsi_error_handler()
2220 shost->host_no)); in scsi_error_handler()
2229 shost->host_no, shost->host_eh_scheduled, in scsi_error_handler()
2230 shost->host_failed, in scsi_error_handler()
2234 * We have a host that is failing for some reason. Figure out in scsi_error_handler()
2238 if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) { in scsi_error_handler()
2242 shost->host_no)); in scsi_error_handler()
2246 if (shost->transportt->eh_strategy_handler) in scsi_error_handler()
2247 shost->transportt->eh_strategy_handler(shost); in scsi_error_handler()
2252 shost->host_failed = 0; in scsi_error_handler()
2255 * Note - if the above fails completely, the action is to take in scsi_error_handler()
2262 if (!shost->eh_noresume) in scsi_error_handler()
2270 shost->host_no)); in scsi_error_handler()
2271 shost->ehandler = NULL; in scsi_error_handler()
2278 * Purpose: Utility function used by low-level drivers to report that
2281 * Arguments: shost - Host in question
2282 * channel - channel on which reset was observed.
2286 * Lock status: Host lock must be held.
2290 * by the mid-level itself don't need to call this, but there
2310 * Purpose: Utility function used by low-level drivers to report that
2313 * Arguments: shost - Host in question
2314 * channel - channel on which reset was observed
2315 * target - target on which reset was observed
2319 * Lock status: Host lock must be held
2323 * by the mid-level itself don't need to call this, but there
2347 * scsi_ioctl_reset: explicitly reset a host/bus/target/device
2355 struct Scsi_Host *shost = dev->host; in scsi_ioctl_reset()
2362 return -EACCES; in scsi_ioctl_reset()
2369 return -EIO; in scsi_ioctl_reset()
2371 error = -EIO; in scsi_ioctl_reset()
2373 shost->hostt->cmd_size, GFP_KERNEL); in scsi_ioctl_reset()
2380 scmd->cmnd = scsi_req(rq)->cmd; in scsi_ioctl_reset()
2382 scmd->scsi_done = scsi_reset_provider_done_command; in scsi_ioctl_reset()
2383 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); in scsi_ioctl_reset()
2385 scmd->cmd_len = 0; in scsi_ioctl_reset()
2387 scmd->sc_data_direction = DMA_BIDIRECTIONAL; in scsi_ioctl_reset()
2389 spin_lock_irqsave(shost->host_lock, flags); in scsi_ioctl_reset()
2390 shost->tmf_in_progress = 1; in scsi_ioctl_reset()
2391 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_ioctl_reset()
2422 error = (rtn == SUCCESS) ? 0 : -EIO; in scsi_ioctl_reset()
2424 spin_lock_irqsave(shost->host_lock, flags); in scsi_ioctl_reset()
2425 shost->tmf_in_progress = 0; in scsi_ioctl_reset()
2426 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_ioctl_reset()
2434 "waking up host to restart after TMF\n")); in scsi_ioctl_reset()
2436 wake_up(&shost->host_wait); in scsi_ioctl_reset()
2449 return scsi_normalize_sense(cmd->sense_buffer, in scsi_command_normalize_sense()
2455 …* scsi_get_sense_info_fld - get information field from sense data (either fixed or descriptor form…