Lines Matching +full:current +full:- +full:sense
1 // SPDX-License-Identifier: GPL-2.0-only
66 lockdep_assert_held(shost->host_lock); in scsi_eh_wakeup()
68 if (busy == shost->host_failed) { in scsi_eh_wakeup()
70 wake_up_process(shost->ehandler); in scsi_eh_wakeup()
77 * scsi_schedule_eh - schedule EH for SCSI host
86 spin_lock_irqsave(shost->host_lock, flags); in scsi_schedule_eh()
90 shost->host_eh_scheduled++; in scsi_schedule_eh()
94 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_schedule_eh()
100 if (!shost->last_reset || shost->eh_deadline == -1) in scsi_host_eh_past_deadline()
110 if (time_before(jiffies, shost->last_reset + shost->eh_deadline) && in scsi_host_eh_past_deadline()
111 shost->eh_deadline > -1) in scsi_host_eh_past_deadline()
119 if (cmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT) in scsi_cmd_retry_allowed()
122 return ++cmd->retries <= cmd->allowed; in scsi_cmd_retry_allowed()
127 struct scsi_device *sdev = cmd->device; in scsi_eh_should_retry_cmd()
128 struct Scsi_Host *host = sdev->host; in scsi_eh_should_retry_cmd()
130 if (host->hostt->eh_should_retry_cmd) in scsi_eh_should_retry_cmd()
131 return host->hostt->eh_should_retry_cmd(cmd); in scsi_eh_should_retry_cmd()
137 * scmd_eh_abort_handler - Handle command aborts
151 struct scsi_device *sdev = scmd->device; in scmd_eh_abort_handler()
152 struct Scsi_Host *shost = sdev->host; in scmd_eh_abort_handler()
166 rtn = scsi_try_to_abort_cmd(shost->hostt, scmd); in scmd_eh_abort_handler()
184 spin_lock_irqsave(shost->host_lock, flags); in scmd_eh_abort_handler()
185 list_del_init(&scmd->eh_entry); in scmd_eh_abort_handler()
189 * EH action, clear the ->last_reset time. in scmd_eh_abort_handler()
191 if (list_empty(&shost->eh_abort_list) && in scmd_eh_abort_handler()
192 list_empty(&shost->eh_cmd_q)) in scmd_eh_abort_handler()
193 if (shost->eh_deadline != -1) in scmd_eh_abort_handler()
194 shost->last_reset = 0; in scmd_eh_abort_handler()
196 spin_unlock_irqrestore(shost->host_lock, flags); in scmd_eh_abort_handler()
214 spin_lock_irqsave(shost->host_lock, flags); in scmd_eh_abort_handler()
215 list_del_init(&scmd->eh_entry); in scmd_eh_abort_handler()
216 spin_unlock_irqrestore(shost->host_lock, flags); in scmd_eh_abort_handler()
222 * scsi_abort_command - schedule a command abort
230 struct scsi_device *sdev = scmd->device; in scsi_abort_command()
231 struct Scsi_Host *shost = sdev->host; in scsi_abort_command()
234 if (!shost->hostt->eh_abort_handler) { in scsi_abort_command()
239 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) { in scsi_abort_command()
246 BUG_ON(delayed_work_pending(&scmd->abort_work)); in scsi_abort_command()
250 spin_lock_irqsave(shost->host_lock, flags); in scsi_abort_command()
251 if (shost->eh_deadline != -1 && !shost->last_reset) in scsi_abort_command()
252 shost->last_reset = jiffies; in scsi_abort_command()
253 BUG_ON(!list_empty(&scmd->eh_entry)); in scsi_abort_command()
254 list_add_tail(&scmd->eh_entry, &shost->eh_abort_list); in scsi_abort_command()
255 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_abort_command()
257 scmd->eh_eflags |= SCSI_EH_ABORT_SCHEDULED; in scsi_abort_command()
260 queue_delayed_work(shost->tmf_work_q, &scmd->abort_work, HZ / 100); in scsi_abort_command()
265 * scsi_eh_reset - call into ->eh_action to reset internal counters
276 if (sdrv->eh_reset) in scsi_eh_reset()
277 sdrv->eh_reset(scmd); in scsi_eh_reset()
284 struct Scsi_Host *shost = scmd->device->host; in scsi_eh_inc_host_failed()
288 spin_lock_irqsave(shost->host_lock, flags); in scsi_eh_inc_host_failed()
289 shost->host_failed++; in scsi_eh_inc_host_failed()
291 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_eh_inc_host_failed()
295 * scsi_eh_scmd_add - add scsi cmd to error handling.
300 struct Scsi_Host *shost = scmd->device->host; in scsi_eh_scmd_add()
304 WARN_ON_ONCE(!shost->ehandler); in scsi_eh_scmd_add()
305 WARN_ON_ONCE(!test_bit(SCMD_STATE_INFLIGHT, &scmd->state)); in scsi_eh_scmd_add()
307 spin_lock_irqsave(shost->host_lock, flags); in scsi_eh_scmd_add()
312 if (shost->eh_deadline != -1 && !shost->last_reset) in scsi_eh_scmd_add()
313 shost->last_reset = jiffies; in scsi_eh_scmd_add()
316 list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q); in scsi_eh_scmd_add()
317 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_eh_scmd_add()
322 call_rcu_hurry(&scmd->rcu, scsi_eh_inc_host_failed); in scsi_eh_scmd_add()
326 * scsi_timeout - Timeout function for normal scsi commands.
338 struct Scsi_Host *host = scmd->device->host; in scsi_timeout()
343 atomic_inc(&scmd->device->iotmo_cnt); in scsi_timeout()
344 if (host->eh_deadline != -1 && !host->last_reset) in scsi_timeout()
345 host->last_reset = jiffies; in scsi_timeout()
347 if (host->hostt->eh_timed_out) { in scsi_timeout()
348 switch (host->hostt->eh_timed_out(scmd)) { in scsi_timeout()
362 if (test_and_set_bit(SCMD_STATE_COMPLETE, &scmd->state)) in scsi_timeout()
364 atomic_inc(&scmd->device->iodone_cnt); in scsi_timeout()
374 * scsi_block_when_processing_errors - Prevent cmds from being queued.
388 wait_event(sdev->host->host_wait, !scsi_host_in_recovery(sdev->host)); in scsi_block_when_processing_errors()
398 * scsi_eh_prt_fail_stats - Log info on failures.
414 if (scmd->device == sdev) { in scsi_eh_prt_fail_stats()
416 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) in scsi_eh_prt_fail_stats()
443 * scsi_report_lun_change - Set flag on all *other* devices on the same target
449 sdev->sdev_target->expecting_lun_change = 1; in scsi_report_lun_change()
453 * scsi_report_sense - Examine scsi sense information and log messages for
455 * @sdev: Device reporting the sense code
463 if (sshdr->sense_key == UNIT_ATTENTION) { in scsi_report_sense()
464 if (sshdr->asc == 0x3f && sshdr->ascq == 0x03) { in scsi_report_sense()
468 } else if (sshdr->asc == 0x3f && sshdr->ascq == 0x0e) { in scsi_report_sense()
475 } else if (sshdr->asc == 0x3f) in scsi_report_sense()
481 if (sshdr->asc == 0x38 && sshdr->ascq == 0x07) { in scsi_report_sense()
489 if (sshdr->asc == 0x29) { in scsi_report_sense()
492 * Do not print message if it is an expected side-effect in scsi_report_sense()
495 if (!sdev->silence_suspend) in scsi_report_sense()
497 "Power-on or device reset occurred\n"); in scsi_report_sense()
500 if (sshdr->asc == 0x2a && sshdr->ascq == 0x01) { in scsi_report_sense()
504 } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x06) { in scsi_report_sense()
508 } else if (sshdr->asc == 0x2a && sshdr->ascq == 0x09) { in scsi_report_sense()
512 } else if (sshdr->asc == 0x2a) in scsi_report_sense()
518 set_bit(evt_type, sdev->pending_events); in scsi_report_sense()
519 schedule_work(&sdev->event_work); in scsi_report_sense()
525 cmd->result = (cmd->result & 0xffff00ff) | (status << 8); in set_scsi_ml_byte()
529 * scsi_check_sense - Examine scsi cmd sense
530 * @scmd: Cmd to have sense checked.
536 * When a deferred error is detected the current command has
542 struct scsi_device *sdev = scmd->device; in scsi_check_sense()
546 return FAILED; /* no valid sense data */ in scsi_check_sense()
554 * happened, even if someone else gets the sense data. in scsi_check_sense()
557 atomic_inc(&sdev->ua_new_media_ctr); in scsi_check_sense()
559 atomic_inc(&sdev->ua_por_ctr); in scsi_check_sense()
565 if (sdev->handler && sdev->handler->check_sense) { in scsi_check_sense()
568 rc = sdev->handler->check_sense(sdev, &sshdr); in scsi_check_sense()
574 if (scmd->cmnd[0] == TEST_UNIT_READY && in scsi_check_sense()
575 scmd->submitter != SUBMITTED_BY_SCSI_ERROR_HANDLER) in scsi_check_sense()
577 * nasty: for mid-layer issued TURs, we need to return the in scsi_check_sense()
578 * actual sense data without any recovery attempt. For eh in scsi_check_sense()
589 if (scmd->sense_buffer[2] & 0xe0) in scsi_check_sense()
593 * descriptor format: look for "stream commands sense data in scsi_check_sense()
594 * descriptor" (see SSC-3). Assume single sense data in scsi_check_sense()
595 * descriptor. Ignore ILI from SBC-2 READ LONG and WRITE LONG. in scsi_check_sense()
598 (scmd->sense_buffer[8] == 0x4) && in scsi_check_sense()
599 (scmd->sense_buffer[11] & 0xe0)) in scsi_check_sense()
615 * ABORTED COMMAND additional sense code with the in scsi_check_sense()
619 * additional sense code qualifiers. in scsi_check_sense()
624 req->cmd_flags |= REQ_FAILFAST_DEV; in scsi_check_sense()
625 req->rq_flags |= RQF_QUIET; in scsi_check_sense()
629 if (sshdr.asc == 0x44 && sdev->sdev_bflags & BLIST_RETRY_ITF) in scsi_check_sense()
632 sdev->sdev_bflags & BLIST_RETRY_ASC_C1) in scsi_check_sense()
641 * information that we should pass up to the upper-level driver in scsi_check_sense()
644 if (scmd->device->expecting_cc_ua) { in scsi_check_sense()
648 * additional sense code and qualifier so as in scsi_check_sense()
652 scmd->device->expecting_cc_ua = 0; in scsi_check_sense()
658 * reported a UA with an ASC/ASCQ of 3F 0E - in scsi_check_sense()
661 if (scmd->device->sdev_target->expecting_lun_change && in scsi_check_sense()
675 if (scmd->device->allow_restart && in scsi_check_sense()
709 if (scmd->device->retry_hwerror) in scsi_check_sense()
730 * and the sense data DATA CURRENTLY UNAVAILABLE, indicating in scsi_check_sense()
736 req->cmd_flags |= REQ_FAILFAST_DEV; in scsi_check_sense()
737 req->rq_flags |= RQF_QUIET; in scsi_check_sense()
749 const struct scsi_host_template *sht = sdev->host->hostt; in scsi_handle_queue_ramp_up()
752 if (!sht->track_queue_depth || in scsi_handle_queue_ramp_up()
753 sdev->queue_depth >= sdev->max_queue_depth) in scsi_handle_queue_ramp_up()
757 sdev->last_queue_ramp_up + sdev->queue_ramp_up_period)) in scsi_handle_queue_ramp_up()
761 sdev->last_queue_full_time + sdev->queue_ramp_up_period)) in scsi_handle_queue_ramp_up()
768 shost_for_each_device(tmp_sdev, sdev->host) { in scsi_handle_queue_ramp_up()
769 if (tmp_sdev->channel != sdev->channel || in scsi_handle_queue_ramp_up()
770 tmp_sdev->id != sdev->id || in scsi_handle_queue_ramp_up()
771 tmp_sdev->queue_depth == sdev->max_queue_depth) in scsi_handle_queue_ramp_up()
774 scsi_change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1); in scsi_handle_queue_ramp_up()
775 sdev->last_queue_ramp_up = jiffies; in scsi_handle_queue_ramp_up()
781 const struct scsi_host_template *sht = sdev->host->hostt; in scsi_handle_queue_full()
784 if (!sht->track_queue_depth) in scsi_handle_queue_full()
787 shost_for_each_device(tmp_sdev, sdev->host) { in scsi_handle_queue_full()
788 if (tmp_sdev->channel != sdev->channel || in scsi_handle_queue_full()
789 tmp_sdev->id != sdev->id) in scsi_handle_queue_full()
796 scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1); in scsi_handle_queue_full()
801 * scsi_eh_completed_normally - Disposition a eh cmd on return from LLD.
816 if (host_byte(scmd->result) == DID_RESET) { in scsi_eh_completed_normally()
819 * get to try and figure out what to do next. if the sense in scsi_eh_completed_normally()
825 if (host_byte(scmd->result) != DID_OK) in scsi_eh_completed_normally()
834 scsi_handle_queue_ramp_up(scmd->device); in scsi_eh_completed_normally()
835 if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd)) in scsi_eh_completed_normally()
837 * If we have sense data, call scsi_check_sense() in in scsi_eh_completed_normally()
856 if (scmd->cmnd[0] == TEST_UNIT_READY) in scsi_eh_completed_normally()
863 scsi_handle_queue_full(scmd->device); in scsi_eh_completed_normally()
874 * scsi_eh_done - Completion function for error handling.
882 "%s result: %x\n", __func__, scmd->result)); in scsi_eh_done()
884 eh_action = scmd->device->host->eh_action; in scsi_eh_done()
890 * scsi_try_host_reset - ask host adapter to reset itself
897 struct Scsi_Host *host = scmd->device->host; in scsi_try_host_reset()
898 const struct scsi_host_template *hostt = host->hostt; in scsi_try_host_reset()
903 if (!hostt->eh_host_reset_handler) in scsi_try_host_reset()
906 rtn = hostt->eh_host_reset_handler(scmd); in scsi_try_host_reset()
909 if (!hostt->skip_settle_delay) in scsi_try_host_reset()
911 spin_lock_irqsave(host->host_lock, flags); in scsi_try_host_reset()
913 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_host_reset()
920 * scsi_try_bus_reset - ask host to perform a bus reset
927 struct Scsi_Host *host = scmd->device->host; in scsi_try_bus_reset()
928 const struct scsi_host_template *hostt = host->hostt; in scsi_try_bus_reset()
933 if (!hostt->eh_bus_reset_handler) in scsi_try_bus_reset()
936 rtn = hostt->eh_bus_reset_handler(scmd); in scsi_try_bus_reset()
939 if (!hostt->skip_settle_delay) in scsi_try_bus_reset()
941 spin_lock_irqsave(host->host_lock, flags); in scsi_try_bus_reset()
943 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_bus_reset()
951 sdev->was_reset = 1; in __scsi_report_device_reset()
952 sdev->expecting_cc_ua = 1; in __scsi_report_device_reset()
956 * scsi_try_target_reset - Ask host to perform a target reset
969 struct Scsi_Host *host = scmd->device->host; in scsi_try_target_reset()
970 const struct scsi_host_template *hostt = host->hostt; in scsi_try_target_reset()
972 if (!hostt->eh_target_reset_handler) in scsi_try_target_reset()
975 rtn = hostt->eh_target_reset_handler(scmd); in scsi_try_target_reset()
977 spin_lock_irqsave(host->host_lock, flags); in scsi_try_target_reset()
978 __starget_for_each_device(scsi_target(scmd->device), NULL, in scsi_try_target_reset()
980 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_target_reset()
987 * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
999 const struct scsi_host_template *hostt = scmd->device->host->hostt; in scsi_try_bus_device_reset()
1001 if (!hostt->eh_device_reset_handler) in scsi_try_bus_device_reset()
1004 rtn = hostt->eh_device_reset_handler(scmd); in scsi_try_bus_device_reset()
1006 __scsi_report_device_reset(scmd->device, NULL); in scsi_try_bus_device_reset()
1011 * scsi_try_to_abort_cmd - Ask host to abort a SCSI command
1030 if (!hostt->eh_abort_handler) in scsi_try_to_abort_cmd()
1033 return hostt->eh_abort_handler(scmd); in scsi_try_to_abort_cmd()
1038 if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS) in scsi_abort_eh_cmnd()
1046 * scsi_eh_prep_cmnd - Save a scsi command info as part of error recovery
1051 * @sense_bytes: size of sense data to copy. or 0 (if != 0 @cmnd is ignored)
1053 * This function is used to save a scsi command information before re-execution
1057 * and cmnd buffers to read @sense_bytes into @scmd->sense_buffer.
1062 struct scsi_device *sdev = scmd->device; in scsi_eh_prep_cmnd()
1065 * We need saved copies of a number of fields - this is because in scsi_eh_prep_cmnd()
1071 ses->cmd_len = scmd->cmd_len; in scsi_eh_prep_cmnd()
1072 ses->data_direction = scmd->sc_data_direction; in scsi_eh_prep_cmnd()
1073 ses->sdb = scmd->sdb; in scsi_eh_prep_cmnd()
1074 ses->result = scmd->result; in scsi_eh_prep_cmnd()
1075 ses->resid_len = scmd->resid_len; in scsi_eh_prep_cmnd()
1076 ses->underflow = scmd->underflow; in scsi_eh_prep_cmnd()
1077 ses->prot_op = scmd->prot_op; in scsi_eh_prep_cmnd()
1078 ses->eh_eflags = scmd->eh_eflags; in scsi_eh_prep_cmnd()
1080 scmd->prot_op = SCSI_PROT_NORMAL; in scsi_eh_prep_cmnd()
1081 scmd->eh_eflags = 0; in scsi_eh_prep_cmnd()
1082 memcpy(ses->cmnd, scmd->cmnd, sizeof(ses->cmnd)); in scsi_eh_prep_cmnd()
1083 memset(scmd->cmnd, 0, sizeof(scmd->cmnd)); in scsi_eh_prep_cmnd()
1084 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); in scsi_eh_prep_cmnd()
1085 scmd->result = 0; in scsi_eh_prep_cmnd()
1086 scmd->resid_len = 0; in scsi_eh_prep_cmnd()
1089 scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE, in scsi_eh_prep_cmnd()
1091 sg_init_one(&ses->sense_sgl, scmd->sense_buffer, in scsi_eh_prep_cmnd()
1092 scmd->sdb.length); in scsi_eh_prep_cmnd()
1093 scmd->sdb.table.sgl = &ses->sense_sgl; in scsi_eh_prep_cmnd()
1094 scmd->sc_data_direction = DMA_FROM_DEVICE; in scsi_eh_prep_cmnd()
1095 scmd->sdb.table.nents = scmd->sdb.table.orig_nents = 1; in scsi_eh_prep_cmnd()
1096 scmd->cmnd[0] = REQUEST_SENSE; in scsi_eh_prep_cmnd()
1097 scmd->cmnd[4] = scmd->sdb.length; in scsi_eh_prep_cmnd()
1098 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_prep_cmnd()
1100 scmd->sc_data_direction = DMA_NONE; in scsi_eh_prep_cmnd()
1102 BUG_ON(cmnd_size > sizeof(scmd->cmnd)); in scsi_eh_prep_cmnd()
1103 memcpy(scmd->cmnd, cmnd, cmnd_size); in scsi_eh_prep_cmnd()
1104 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_prep_cmnd()
1108 scmd->underflow = 0; in scsi_eh_prep_cmnd()
1110 if (sdev->scsi_level <= SCSI_2 && sdev->scsi_level != SCSI_UNKNOWN) in scsi_eh_prep_cmnd()
1111 scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) | in scsi_eh_prep_cmnd()
1112 (sdev->lun << 5 & 0xe0); in scsi_eh_prep_cmnd()
1115 * Zero the sense buffer. The scsi spec mandates that any in scsi_eh_prep_cmnd()
1116 * untransferred sense data should be interpreted as being zero. in scsi_eh_prep_cmnd()
1118 memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in scsi_eh_prep_cmnd()
1123 * scsi_eh_restore_cmnd - Restore a scsi command info as part of error recovery
1134 scmd->cmd_len = ses->cmd_len; in scsi_eh_restore_cmnd()
1135 memcpy(scmd->cmnd, ses->cmnd, sizeof(ses->cmnd)); in scsi_eh_restore_cmnd()
1136 scmd->sc_data_direction = ses->data_direction; in scsi_eh_restore_cmnd()
1137 scmd->sdb = ses->sdb; in scsi_eh_restore_cmnd()
1138 scmd->result = ses->result; in scsi_eh_restore_cmnd()
1139 scmd->resid_len = ses->resid_len; in scsi_eh_restore_cmnd()
1140 scmd->underflow = ses->underflow; in scsi_eh_restore_cmnd()
1141 scmd->prot_op = ses->prot_op; in scsi_eh_restore_cmnd()
1142 scmd->eh_eflags = ses->eh_eflags; in scsi_eh_restore_cmnd()
1147 * scsi_send_eh_cmnd - submit a scsi command as part of error recovery
1152 * @sense_bytes: size of sense data to copy or 0
1163 struct scsi_device *sdev = scmd->device; in scsi_send_eh_cmnd()
1164 struct Scsi_Host *shost = sdev->host; in scsi_send_eh_cmnd()
1173 shost->eh_action = &done; in scsi_send_eh_cmnd()
1176 scmd->submitter = SUBMITTED_BY_SCSI_ERROR_HANDLER; in scsi_send_eh_cmnd()
1177 scmd->flags |= SCMD_LAST; in scsi_send_eh_cmnd()
1180 * Lock sdev->state_mutex to avoid that scsi_device_quiesce() can in scsi_send_eh_cmnd()
1184 mutex_lock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1185 while (sdev->sdev_state == SDEV_BLOCK && timeleft > 0) { in scsi_send_eh_cmnd()
1186 mutex_unlock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1188 "%s: state %d <> %d\n", __func__, sdev->sdev_state, in scsi_send_eh_cmnd()
1191 timeleft -= delay; in scsi_send_eh_cmnd()
1193 mutex_lock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1195 if (sdev->sdev_state != SDEV_BLOCK) in scsi_send_eh_cmnd()
1196 rtn = shost->hostt->queuecommand(shost, scmd); in scsi_send_eh_cmnd()
1199 mutex_unlock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1205 timeleft -= stall_for; in scsi_send_eh_cmnd()
1217 shost->eh_action = NULL; in scsi_send_eh_cmnd()
1231 * ->queuecommand() kept returning non zero, use the rtn = FAILED in scsi_send_eh_cmnd()
1262 * scsi_request_sense - Request sense data from a particular target.
1263 * @scmd: SCSI cmd for request sense.
1272 return scsi_send_eh_cmnd(scmd, NULL, 0, scmd->device->eh_timeout, ~0); in scsi_request_sense()
1280 if (sdrv->eh_action) in scsi_eh_action()
1281 rtn = sdrv->eh_action(scmd, rtn); in scsi_eh_action()
1287 * scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
1293 * still handling errors - it may cause other commands to be queued,
1300 list_move_tail(&scmd->eh_entry, done_q); in scsi_eh_finish_cmd()
1305 * scsi_eh_get_sense - Get device sense data.
1310 * See if we need to request sense information. if so, then get it
1315 * not automatically request sense information, we end up shutting
1318 * All drivers should request sense information internally these days,
1333 * should not get sense. in scsi_eh_get_sense()
1336 if ((scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) || in scsi_eh_get_sense()
1340 shost = scmd->device->host; in scsi_eh_get_sense()
1344 "%s: skip request sense, past eh deadline\n", in scsi_eh_get_sense()
1345 current->comm)); in scsi_eh_get_sense()
1348 if (!scsi_status_is_check_condition(scmd->result)) in scsi_eh_get_sense()
1350 * don't request sense if there's no check condition in scsi_eh_get_sense()
1352 * that has a sense code (and some devices get in scsi_eh_get_sense()
1353 * confused by sense requests out of the blue) in scsi_eh_get_sense()
1358 "%s: requesting sense\n", in scsi_eh_get_sense()
1359 current->comm)); in scsi_eh_get_sense()
1365 "sense requested, result %x\n", scmd->result)); in scsi_eh_get_sense()
1377 * with the sense data, so set retries to the max in scsi_eh_get_sense()
1383 if (scmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT) in scsi_eh_get_sense()
1384 scmd->retries = scmd->allowed = 1; in scsi_eh_get_sense()
1386 scmd->retries = scmd->allowed; in scsi_eh_get_sense()
1398 * scsi_eh_tur - Send TUR to device.
1402 * 0 - Device is ready. 1 - Device NOT ready.
1412 scmd->device->eh_timeout, 0); in scsi_eh_tur()
1419 if (retry_cnt--) in scsi_eh_tur()
1430 * scsi_eh_test_devices - check if devices are responding from error recovery.
1451 scmd = list_entry(cmd_list->next, struct scsi_cmnd, eh_entry); in scsi_eh_test_devices()
1452 sdev = scmd->device; in scsi_eh_test_devices()
1455 if (scsi_host_eh_past_deadline(sdev->host)) { in scsi_eh_test_devices()
1461 current->comm)); in scsi_eh_test_devices()
1466 finish_cmds = !scsi_device_online(scmd->device) || in scsi_eh_test_devices()
1472 if (scmd->device == sdev) { in scsi_eh_test_devices()
1478 list_move_tail(&scmd->eh_entry, work_q); in scsi_eh_test_devices()
1485 * scsi_eh_try_stu - Send START_UNIT to device.
1489 * 0 - Device is ready. 1 - Device NOT ready.
1495 if (scmd->device->allow_restart) { in scsi_eh_try_stu()
1501 scmd->device->eh_timeout, 0); in scsi_eh_try_stu()
1511 * scsi_eh_stu - send START_UNIT if needed
1532 current->comm)); in scsi_eh_stu()
1538 if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) && in scsi_eh_stu()
1550 current->comm)); in scsi_eh_stu()
1557 if (scmd->device == sdev && in scsi_eh_stu()
1566 current->comm)); in scsi_eh_stu()
1575 * scsi_eh_bus_device_reset - send bdr if needed
1582 * devices that are jammed or not - if we have multiple devices, it
1583 * makes no sense to try bus_device_reset - we really would need to try
1599 current->comm)); in scsi_eh_bus_device_reset()
1605 if (scmd->device == sdev) { in scsi_eh_bus_device_reset()
1615 "%s: Sending BDR\n", current->comm)); in scsi_eh_bus_device_reset()
1623 if (scmd->device == sdev && in scsi_eh_bus_device_reset()
1632 "%s: BDR failed\n", current->comm)); in scsi_eh_bus_device_reset()
1640 * scsi_eh_target_reset - send target reset if needed
1669 current->comm)); in scsi_eh_target_reset()
1679 current->comm, id)); in scsi_eh_target_reset()
1686 current->comm, id)); in scsi_eh_target_reset()
1692 list_move_tail(&scmd->eh_entry, &check_list); in scsi_eh_target_reset()
1697 list_move(&scmd->eh_entry, work_q); in scsi_eh_target_reset()
1705 * scsi_eh_bus_reset - send a bus reset
1726 for (channel = 0; channel <= shost->max_channel; channel++) { in scsi_eh_bus_reset()
1732 current->comm)); in scsi_eh_bus_reset()
1753 current->comm, channel)); in scsi_eh_bus_reset()
1762 list_move_tail(&scmd->eh_entry, in scsi_eh_bus_reset()
1770 current->comm, channel)); in scsi_eh_bus_reset()
1777 * scsi_eh_host_reset - send a host reset
1791 scmd = list_entry(work_q->next, in scsi_eh_host_reset()
1797 current->comm)); in scsi_eh_host_reset()
1810 current->comm)); in scsi_eh_host_reset()
1817 * scsi_eh_offline_sdevs - offline scsi devices that fail to recover
1828 sdev_printk(KERN_INFO, scmd->device, "Device offlined - " in scsi_eh_offline_sdevs()
1830 sdev = scmd->device; in scsi_eh_offline_sdevs()
1832 mutex_lock(&sdev->state_mutex); in scsi_eh_offline_sdevs()
1834 mutex_unlock(&sdev->state_mutex); in scsi_eh_offline_sdevs()
1842 * scsi_noretry_cmd - determine if command should be failed fast
1849 switch (host_byte(scmd->result)) { in scsi_noretry_cmd()
1855 return !!(req->cmd_flags & REQ_FAILFAST_TRANSPORT); in scsi_noretry_cmd()
1857 return !!(req->cmd_flags & REQ_FAILFAST_DEV); in scsi_noretry_cmd()
1863 return !!(req->cmd_flags & REQ_FAILFAST_DRIVER); in scsi_noretry_cmd()
1867 if (scsi_ml_byte(scmd->result) == SCSIML_STAT_DL_TIMEOUT) in scsi_noretry_cmd()
1870 if (!scsi_status_is_check_condition(scmd->result)) in scsi_noretry_cmd()
1875 * assume caller has checked sense and determined in scsi_noretry_cmd()
1878 if (req->cmd_flags & REQ_FAILFAST_DEV || blk_rq_is_passthrough(req)) in scsi_noretry_cmd()
1885 * scsi_decide_disposition - Disposition a cmd on return from LLD.
1906 if (!scsi_device_online(scmd->device)) { in scsi_decide_disposition()
1908 "%s: device offline - report as SUCCESS\n", __func__)); in scsi_decide_disposition()
1916 switch (host_byte(scmd->result)) { in scsi_decide_disposition()
1923 scmd->result &= 0xff00ffff; in scsi_decide_disposition()
1931 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) { in scsi_decide_disposition()
1939 * note - this means that we just report the status back in scsi_decide_disposition()
1994 if ((scmd->cmnd[0] == TEST_UNIT_READY || in scsi_decide_disposition()
1995 scmd->cmnd[0] == INQUIRY)) { in scsi_decide_disposition()
2011 scsi_handle_queue_full(scmd->device); in scsi_decide_disposition()
2020 * occur (SAM-3) when the task queue is empty, so will cause in scsi_decide_disposition()
2026 if (scmd->cmnd[0] == REPORT_LUNS) in scsi_decide_disposition()
2027 scmd->device->sdev_target->expecting_lun_change = 0; in scsi_decide_disposition()
2028 scsi_handle_queue_ramp_up(scmd->device); in scsi_decide_disposition()
2029 if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd)) in scsi_decide_disposition()
2031 * If we have sense data, call scsi_check_sense() in in scsi_decide_disposition()
2046 /* if rtn == FAILED, we have no sense information; in scsi_decide_disposition()
2048 * to collect the sense and redo the decide in scsi_decide_disposition()
2061 sdev_printk(KERN_INFO, scmd->device, in scsi_decide_disposition()
2078 * no more retries - report this one back to upper level. in scsi_decide_disposition()
2092 * scsi_eh_lock_door - Prevent medium removal for the specified device
2107 req = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN, 0); in scsi_eh_lock_door()
2112 scmd->cmnd[0] = ALLOW_MEDIUM_REMOVAL; in scsi_eh_lock_door()
2113 scmd->cmnd[1] = 0; in scsi_eh_lock_door()
2114 scmd->cmnd[2] = 0; in scsi_eh_lock_door()
2115 scmd->cmnd[3] = 0; in scsi_eh_lock_door()
2116 scmd->cmnd[4] = SCSI_REMOVAL_PREVENT; in scsi_eh_lock_door()
2117 scmd->cmnd[5] = 0; in scsi_eh_lock_door()
2118 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_lock_door()
2119 scmd->allowed = 5; in scsi_eh_lock_door()
2121 req->rq_flags |= RQF_QUIET; in scsi_eh_lock_door()
2122 req->timeout = 10 * HZ; in scsi_eh_lock_door()
2123 req->end_io = eh_lock_door_done; in scsi_eh_lock_door()
2129 * scsi_restart_operations - restart io operations to the specified host.
2144 * is no point trying to lock the door of an off-line device. in scsi_restart_operations()
2147 if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) { in scsi_restart_operations()
2149 sdev->was_reset = 0; in scsi_restart_operations()
2161 spin_lock_irqsave(shost->host_lock, flags); in scsi_restart_operations()
2165 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_restart_operations()
2167 wake_up(&shost->host_wait); in scsi_restart_operations()
2170 * finally we need to re-initiate requests that may be pending. we will in scsi_restart_operations()
2178 * if eh is active and host_eh_scheduled is pending we need to re-run in scsi_restart_operations()
2181 * progress before we sync again. Either we'll immediately re-run in scsi_restart_operations()
2185 spin_lock_irqsave(shost->host_lock, flags); in scsi_restart_operations()
2186 if (shost->host_eh_scheduled) in scsi_restart_operations()
2189 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_restart_operations()
2193 * scsi_eh_ready_devs - check device ready state and recover if not.
2213 * scsi_eh_flush_done_q - finish processed commands or retry them.
2221 struct scsi_device *sdev = scmd->device; in scsi_eh_flush_done_q()
2223 list_del_init(&scmd->eh_entry); in scsi_eh_flush_done_q()
2230 current->comm)); in scsi_eh_flush_done_q()
2232 blk_mq_kick_requeue_list(sdev->request_queue); in scsi_eh_flush_done_q()
2235 * If just we got sense for the device (called in scsi_eh_flush_done_q()
2236 * scsi_eh_get_sense), scmd->result is already in scsi_eh_flush_done_q()
2239 if (!scmd->result && in scsi_eh_flush_done_q()
2240 !(scmd->flags & SCMD_FORCE_EH_SUCCESS)) in scsi_eh_flush_done_q()
2241 scmd->result |= (DID_TIME_OUT << 16); in scsi_eh_flush_done_q()
2245 current->comm)); in scsi_eh_flush_done_q()
2253 * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
2281 spin_lock_irqsave(shost->host_lock, flags); in scsi_unjam_host()
2282 list_splice_init(&shost->eh_cmd_q, &eh_work_q); in scsi_unjam_host()
2283 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_unjam_host()
2290 spin_lock_irqsave(shost->host_lock, flags); in scsi_unjam_host()
2291 if (shost->eh_deadline != -1) in scsi_unjam_host()
2292 shost->last_reset = 0; in scsi_unjam_host()
2293 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_unjam_host()
2298 * scsi_error_handler - SCSI error handler thread
2326 if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) || in scsi_error_handler()
2327 shost->host_failed != scsi_host_busy(shost)) { in scsi_error_handler()
2331 shost->host_no)); in scsi_error_handler()
2340 shost->host_no, shost->host_eh_scheduled, in scsi_error_handler()
2341 shost->host_failed, in scsi_error_handler()
2349 if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) { in scsi_error_handler()
2353 shost->host_no)); in scsi_error_handler()
2357 if (shost->transportt->eh_strategy_handler) in scsi_error_handler()
2358 shost->transportt->eh_strategy_handler(shost); in scsi_error_handler()
2363 shost->host_failed = 0; in scsi_error_handler()
2366 * Note - if the above fails completely, the action is to take in scsi_error_handler()
2373 if (!shost->eh_noresume) in scsi_error_handler()
2381 shost->host_no)); in scsi_error_handler()
2382 shost->ehandler = NULL; in scsi_error_handler()
2387 * scsi_report_bus_reset() - report bus reset observed
2389 * Utility function used by low-level drivers to report that
2401 * by the mid-level itself don't need to call this, but there
2419 * scsi_report_device_reset() - report device reset observed
2421 * Utility function used by low-level drivers to report that
2434 * by the mid-level itself don't need to call this, but there
2461 struct Scsi_Host *shost = dev->host; in scsi_ioctl_reset()
2468 return -EACCES; in scsi_ioctl_reset()
2475 return -EIO; in scsi_ioctl_reset()
2477 error = -EIO; in scsi_ioctl_reset()
2479 shost->hostt->cmd_size, GFP_KERNEL); in scsi_ioctl_reset()
2487 scmd->submitter = SUBMITTED_BY_SCSI_RESET_IOCTL; in scsi_ioctl_reset()
2488 scmd->flags |= SCMD_LAST; in scsi_ioctl_reset()
2489 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); in scsi_ioctl_reset()
2491 scmd->cmd_len = 0; in scsi_ioctl_reset()
2493 scmd->sc_data_direction = DMA_BIDIRECTIONAL; in scsi_ioctl_reset()
2495 spin_lock_irqsave(shost->host_lock, flags); in scsi_ioctl_reset()
2496 shost->tmf_in_progress = 1; in scsi_ioctl_reset()
2497 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_ioctl_reset()
2528 error = (rtn == SUCCESS) ? 0 : -EIO; in scsi_ioctl_reset()
2530 spin_lock_irqsave(shost->host_lock, flags); in scsi_ioctl_reset()
2531 shost->tmf_in_progress = 0; in scsi_ioctl_reset()
2532 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_ioctl_reset()
2542 wake_up(&shost->host_wait); in scsi_ioctl_reset()
2555 return scsi_normalize_sense(cmd->sense_buffer, in scsi_command_normalize_sense()
2561 …* scsi_get_sense_info_fld - get information field from sense data (either fixed or descriptor form…
2562 * @sense_buffer: byte array of sense data