Lines Matching +full:ssc +full:- +full:block +full:- +full:bus

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
141 * Because the block layer marks a request as complete before it calls
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.
378 * We block until the host is out of error recovery, and then check to
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
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
542 struct scsi_device *sdev = scmd->device; in scsi_check_sense()
553 if (sdev->handler && sdev->handler->check_sense) { in scsi_check_sense()
556 rc = sdev->handler->check_sense(sdev, &sshdr); in scsi_check_sense()
562 if (scmd->cmnd[0] == TEST_UNIT_READY && in scsi_check_sense()
563 scmd->submitter != SUBMITTED_BY_SCSI_ERROR_HANDLER) in scsi_check_sense()
565 * nasty: for mid-layer issued TURs, we need to return the in scsi_check_sense()
577 if (scmd->sense_buffer[2] & 0xe0) in scsi_check_sense()
582 * descriptor" (see SSC-3). Assume single sense data in scsi_check_sense()
583 * descriptor. Ignore ILI from SBC-2 READ LONG and WRITE LONG. in scsi_check_sense()
586 (scmd->sense_buffer[8] == 0x4) && in scsi_check_sense()
587 (scmd->sense_buffer[11] & 0xe0)) in scsi_check_sense()
612 req->cmd_flags |= REQ_FAILFAST_DEV; in scsi_check_sense()
613 req->rq_flags |= RQF_QUIET; in scsi_check_sense()
617 if (sshdr.asc == 0x44 && sdev->sdev_bflags & BLIST_RETRY_ITF) in scsi_check_sense()
620 sdev->sdev_bflags & BLIST_RETRY_ASC_C1) in scsi_check_sense()
627 * if we are expecting a cc/ua because of a bus reset that we in scsi_check_sense()
629 * information that we should pass up to the upper-level driver in scsi_check_sense()
632 if (scmd->device->expecting_cc_ua) { in scsi_check_sense()
640 scmd->device->expecting_cc_ua = 0; in scsi_check_sense()
646 * reported a UA with an ASC/ASCQ of 3F 0E - in scsi_check_sense()
649 if (scmd->device->sdev_target->expecting_lun_change && in scsi_check_sense()
662 if (scmd->device->allow_restart && in scsi_check_sense()
696 if (scmd->device->retry_hwerror) in scsi_check_sense()
704 sshdr.asc == 0x21 || /* Logical block address out of range */ in scsi_check_sense()
716 req->cmd_flags |= REQ_FAILFAST_DEV; in scsi_check_sense()
717 req->rq_flags |= RQF_QUIET; in scsi_check_sense()
729 const struct scsi_host_template *sht = sdev->host->hostt; in scsi_handle_queue_ramp_up()
732 if (!sht->track_queue_depth || in scsi_handle_queue_ramp_up()
733 sdev->queue_depth >= sdev->max_queue_depth) in scsi_handle_queue_ramp_up()
737 sdev->last_queue_ramp_up + sdev->queue_ramp_up_period)) in scsi_handle_queue_ramp_up()
741 sdev->last_queue_full_time + sdev->queue_ramp_up_period)) in scsi_handle_queue_ramp_up()
748 shost_for_each_device(tmp_sdev, sdev->host) { in scsi_handle_queue_ramp_up()
749 if (tmp_sdev->channel != sdev->channel || in scsi_handle_queue_ramp_up()
750 tmp_sdev->id != sdev->id || in scsi_handle_queue_ramp_up()
751 tmp_sdev->queue_depth == sdev->max_queue_depth) in scsi_handle_queue_ramp_up()
754 scsi_change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1); in scsi_handle_queue_ramp_up()
755 sdev->last_queue_ramp_up = jiffies; in scsi_handle_queue_ramp_up()
761 const struct scsi_host_template *sht = sdev->host->hostt; in scsi_handle_queue_full()
764 if (!sht->track_queue_depth) in scsi_handle_queue_full()
767 shost_for_each_device(tmp_sdev, sdev->host) { in scsi_handle_queue_full()
768 if (tmp_sdev->channel != sdev->channel || in scsi_handle_queue_full()
769 tmp_sdev->id != sdev->id) in scsi_handle_queue_full()
776 scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1); in scsi_handle_queue_full()
781 * scsi_eh_completed_normally - Disposition a eh cmd on return from LLD.
796 if (host_byte(scmd->result) == DID_RESET) { in scsi_eh_completed_normally()
805 if (host_byte(scmd->result) != DID_OK) in scsi_eh_completed_normally()
814 scsi_handle_queue_ramp_up(scmd->device); in scsi_eh_completed_normally()
815 if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd)) in scsi_eh_completed_normally()
836 if (scmd->cmnd[0] == TEST_UNIT_READY) in scsi_eh_completed_normally()
843 scsi_handle_queue_full(scmd->device); in scsi_eh_completed_normally()
854 * scsi_eh_done - Completion function for error handling.
862 "%s result: %x\n", __func__, scmd->result)); in scsi_eh_done()
864 eh_action = scmd->device->host->eh_action; in scsi_eh_done()
870 * scsi_try_host_reset - ask host adapter to reset itself
877 struct Scsi_Host *host = scmd->device->host; in scsi_try_host_reset()
878 const struct scsi_host_template *hostt = host->hostt; in scsi_try_host_reset()
883 if (!hostt->eh_host_reset_handler) in scsi_try_host_reset()
886 rtn = hostt->eh_host_reset_handler(scmd); in scsi_try_host_reset()
889 if (!hostt->skip_settle_delay) in scsi_try_host_reset()
891 spin_lock_irqsave(host->host_lock, flags); in scsi_try_host_reset()
893 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_host_reset()
900 * scsi_try_bus_reset - ask host to perform a bus reset
901 * @scmd: SCSI cmd to send bus reset.
907 struct Scsi_Host *host = scmd->device->host; in scsi_try_bus_reset()
908 const struct scsi_host_template *hostt = host->hostt; in scsi_try_bus_reset()
911 "%s: Snd Bus RST\n", __func__)); in scsi_try_bus_reset()
913 if (!hostt->eh_bus_reset_handler) in scsi_try_bus_reset()
916 rtn = hostt->eh_bus_reset_handler(scmd); in scsi_try_bus_reset()
919 if (!hostt->skip_settle_delay) in scsi_try_bus_reset()
921 spin_lock_irqsave(host->host_lock, flags); in scsi_try_bus_reset()
923 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_bus_reset()
931 sdev->was_reset = 1; in __scsi_report_device_reset()
932 sdev->expecting_cc_ua = 1; in __scsi_report_device_reset()
936 * scsi_try_target_reset - Ask host to perform a target reset
949 struct Scsi_Host *host = scmd->device->host; in scsi_try_target_reset()
950 const struct scsi_host_template *hostt = host->hostt; in scsi_try_target_reset()
952 if (!hostt->eh_target_reset_handler) in scsi_try_target_reset()
955 rtn = hostt->eh_target_reset_handler(scmd); in scsi_try_target_reset()
957 spin_lock_irqsave(host->host_lock, flags); in scsi_try_target_reset()
958 __starget_for_each_device(scsi_target(scmd->device), NULL, in scsi_try_target_reset()
960 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_target_reset()
967 * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
979 const struct scsi_host_template *hostt = scmd->device->host->hostt; in scsi_try_bus_device_reset()
981 if (!hostt->eh_device_reset_handler) in scsi_try_bus_device_reset()
984 rtn = hostt->eh_device_reset_handler(scmd); in scsi_try_bus_device_reset()
986 __scsi_report_device_reset(scmd->device, NULL); in scsi_try_bus_device_reset()
991 * scsi_try_to_abort_cmd - Ask host to abort a SCSI command
1010 if (!hostt->eh_abort_handler) in scsi_try_to_abort_cmd()
1013 return hostt->eh_abort_handler(scmd); in scsi_try_to_abort_cmd()
1018 if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS) in scsi_abort_eh_cmnd()
1026 * scsi_eh_prep_cmnd - Save a scsi command info as part of error recovery
1033 * This function is used to save a scsi command information before re-execution
1037 * and cmnd buffers to read @sense_bytes into @scmd->sense_buffer.
1042 struct scsi_device *sdev = scmd->device; in scsi_eh_prep_cmnd()
1045 * We need saved copies of a number of fields - this is because in scsi_eh_prep_cmnd()
1051 ses->cmd_len = scmd->cmd_len; in scsi_eh_prep_cmnd()
1052 ses->data_direction = scmd->sc_data_direction; in scsi_eh_prep_cmnd()
1053 ses->sdb = scmd->sdb; in scsi_eh_prep_cmnd()
1054 ses->result = scmd->result; in scsi_eh_prep_cmnd()
1055 ses->resid_len = scmd->resid_len; in scsi_eh_prep_cmnd()
1056 ses->underflow = scmd->underflow; in scsi_eh_prep_cmnd()
1057 ses->prot_op = scmd->prot_op; in scsi_eh_prep_cmnd()
1058 ses->eh_eflags = scmd->eh_eflags; in scsi_eh_prep_cmnd()
1060 scmd->prot_op = SCSI_PROT_NORMAL; in scsi_eh_prep_cmnd()
1061 scmd->eh_eflags = 0; in scsi_eh_prep_cmnd()
1062 memcpy(ses->cmnd, scmd->cmnd, sizeof(ses->cmnd)); in scsi_eh_prep_cmnd()
1063 memset(scmd->cmnd, 0, sizeof(scmd->cmnd)); in scsi_eh_prep_cmnd()
1064 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); in scsi_eh_prep_cmnd()
1065 scmd->result = 0; in scsi_eh_prep_cmnd()
1066 scmd->resid_len = 0; in scsi_eh_prep_cmnd()
1069 scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE, in scsi_eh_prep_cmnd()
1071 sg_init_one(&ses->sense_sgl, scmd->sense_buffer, in scsi_eh_prep_cmnd()
1072 scmd->sdb.length); in scsi_eh_prep_cmnd()
1073 scmd->sdb.table.sgl = &ses->sense_sgl; in scsi_eh_prep_cmnd()
1074 scmd->sc_data_direction = DMA_FROM_DEVICE; in scsi_eh_prep_cmnd()
1075 scmd->sdb.table.nents = scmd->sdb.table.orig_nents = 1; in scsi_eh_prep_cmnd()
1076 scmd->cmnd[0] = REQUEST_SENSE; in scsi_eh_prep_cmnd()
1077 scmd->cmnd[4] = scmd->sdb.length; in scsi_eh_prep_cmnd()
1078 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_prep_cmnd()
1080 scmd->sc_data_direction = DMA_NONE; in scsi_eh_prep_cmnd()
1082 BUG_ON(cmnd_size > sizeof(scmd->cmnd)); in scsi_eh_prep_cmnd()
1083 memcpy(scmd->cmnd, cmnd, cmnd_size); in scsi_eh_prep_cmnd()
1084 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_prep_cmnd()
1088 scmd->underflow = 0; in scsi_eh_prep_cmnd()
1090 if (sdev->scsi_level <= SCSI_2 && sdev->scsi_level != SCSI_UNKNOWN) in scsi_eh_prep_cmnd()
1091 scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) | in scsi_eh_prep_cmnd()
1092 (sdev->lun << 5 & 0xe0); in scsi_eh_prep_cmnd()
1098 memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in scsi_eh_prep_cmnd()
1103 * scsi_eh_restore_cmnd - Restore a scsi command info as part of error recovery
1114 scmd->cmd_len = ses->cmd_len; in scsi_eh_restore_cmnd()
1115 memcpy(scmd->cmnd, ses->cmnd, sizeof(ses->cmnd)); in scsi_eh_restore_cmnd()
1116 scmd->sc_data_direction = ses->data_direction; in scsi_eh_restore_cmnd()
1117 scmd->sdb = ses->sdb; in scsi_eh_restore_cmnd()
1118 scmd->result = ses->result; in scsi_eh_restore_cmnd()
1119 scmd->resid_len = ses->resid_len; in scsi_eh_restore_cmnd()
1120 scmd->underflow = ses->underflow; in scsi_eh_restore_cmnd()
1121 scmd->prot_op = ses->prot_op; in scsi_eh_restore_cmnd()
1122 scmd->eh_eflags = ses->eh_eflags; in scsi_eh_restore_cmnd()
1127 * scsi_send_eh_cmnd - submit a scsi command as part of error recovery
1143 struct scsi_device *sdev = scmd->device; in scsi_send_eh_cmnd()
1144 struct Scsi_Host *shost = sdev->host; in scsi_send_eh_cmnd()
1153 shost->eh_action = &done; in scsi_send_eh_cmnd()
1156 scmd->submitter = SUBMITTED_BY_SCSI_ERROR_HANDLER; in scsi_send_eh_cmnd()
1157 scmd->flags |= SCMD_LAST; in scsi_send_eh_cmnd()
1160 * Lock sdev->state_mutex to avoid that scsi_device_quiesce() can in scsi_send_eh_cmnd()
1164 mutex_lock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1165 while (sdev->sdev_state == SDEV_BLOCK && timeleft > 0) { in scsi_send_eh_cmnd()
1166 mutex_unlock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1168 "%s: state %d <> %d\n", __func__, sdev->sdev_state, in scsi_send_eh_cmnd()
1171 timeleft -= delay; in scsi_send_eh_cmnd()
1173 mutex_lock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1175 if (sdev->sdev_state != SDEV_BLOCK) in scsi_send_eh_cmnd()
1176 rtn = shost->hostt->queuecommand(shost, scmd); in scsi_send_eh_cmnd()
1179 mutex_unlock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1185 timeleft -= stall_for; in scsi_send_eh_cmnd()
1197 shost->eh_action = NULL; in scsi_send_eh_cmnd()
1211 * ->queuecommand() kept returning non zero, use the rtn = FAILED in scsi_send_eh_cmnd()
1242 * scsi_request_sense - Request sense data from a particular target.
1252 return scsi_send_eh_cmnd(scmd, NULL, 0, scmd->device->eh_timeout, ~0); in scsi_request_sense()
1260 if (sdrv->eh_action) in scsi_eh_action()
1261 rtn = sdrv->eh_action(scmd, rtn); in scsi_eh_action()
1267 * scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
1273 * still handling errors - it may cause other commands to be queued,
1280 list_move_tail(&scmd->eh_entry, done_q); in scsi_eh_finish_cmd()
1285 * scsi_eh_get_sense - Get device sense data.
1316 if ((scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) || in scsi_eh_get_sense()
1320 shost = scmd->device->host; in scsi_eh_get_sense()
1325 current->comm)); in scsi_eh_get_sense()
1328 if (!scsi_status_is_check_condition(scmd->result)) in scsi_eh_get_sense()
1339 current->comm)); in scsi_eh_get_sense()
1345 "sense requested, result %x\n", scmd->result)); in scsi_eh_get_sense()
1363 if (scmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT) in scsi_eh_get_sense()
1364 scmd->retries = scmd->allowed = 1; in scsi_eh_get_sense()
1366 scmd->retries = scmd->allowed; in scsi_eh_get_sense()
1378 * scsi_eh_tur - Send TUR to device.
1382 * 0 - Device is ready. 1 - Device NOT ready.
1392 scmd->device->eh_timeout, 0); in scsi_eh_tur()
1399 if (retry_cnt--) in scsi_eh_tur()
1410 * scsi_eh_test_devices - check if devices are responding from error recovery.
1431 scmd = list_entry(cmd_list->next, struct scsi_cmnd, eh_entry); in scsi_eh_test_devices()
1432 sdev = scmd->device; in scsi_eh_test_devices()
1435 if (scsi_host_eh_past_deadline(sdev->host)) { in scsi_eh_test_devices()
1441 current->comm)); in scsi_eh_test_devices()
1446 finish_cmds = !scsi_device_online(scmd->device) || in scsi_eh_test_devices()
1452 if (scmd->device == sdev) { in scsi_eh_test_devices()
1458 list_move_tail(&scmd->eh_entry, work_q); in scsi_eh_test_devices()
1465 * scsi_eh_try_stu - Send START_UNIT to device.
1469 * 0 - Device is ready. 1 - Device NOT ready.
1475 if (scmd->device->allow_restart) { in scsi_eh_try_stu()
1481 scmd->device->eh_timeout, 0); in scsi_eh_try_stu()
1491 * scsi_eh_stu - send START_UNIT if needed
1512 current->comm)); in scsi_eh_stu()
1518 if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) && in scsi_eh_stu()
1530 current->comm)); in scsi_eh_stu()
1537 if (scmd->device == sdev && in scsi_eh_stu()
1546 current->comm)); in scsi_eh_stu()
1555 * scsi_eh_bus_device_reset - send bdr if needed
1561 * Try a bus device reset. Still, look to see whether we have multiple
1562 * devices that are jammed or not - if we have multiple devices, it
1563 * makes no sense to try bus_device_reset - we really would need to try
1579 current->comm)); in scsi_eh_bus_device_reset()
1585 if (scmd->device == sdev) { in scsi_eh_bus_device_reset()
1595 "%s: Sending BDR\n", current->comm)); in scsi_eh_bus_device_reset()
1603 if (scmd->device == sdev && in scsi_eh_bus_device_reset()
1612 "%s: BDR failed\n", current->comm)); in scsi_eh_bus_device_reset()
1620 * scsi_eh_target_reset - send target reset if needed
1649 current->comm)); in scsi_eh_target_reset()
1659 current->comm, id)); in scsi_eh_target_reset()
1666 current->comm, id)); in scsi_eh_target_reset()
1672 list_move_tail(&scmd->eh_entry, &check_list); in scsi_eh_target_reset()
1677 list_move(&scmd->eh_entry, work_q); in scsi_eh_target_reset()
1685 * scsi_eh_bus_reset - send a bus reset
1706 for (channel = 0; channel <= shost->max_channel; channel++) { in scsi_eh_bus_reset()
1712 current->comm)); in scsi_eh_bus_reset()
1733 current->comm, channel)); in scsi_eh_bus_reset()
1742 list_move_tail(&scmd->eh_entry, in scsi_eh_bus_reset()
1750 current->comm, channel)); in scsi_eh_bus_reset()
1757 * scsi_eh_host_reset - send a host reset
1771 scmd = list_entry(work_q->next, in scsi_eh_host_reset()
1777 current->comm)); in scsi_eh_host_reset()
1790 current->comm)); in scsi_eh_host_reset()
1797 * scsi_eh_offline_sdevs - offline scsi devices that fail to recover
1808 sdev_printk(KERN_INFO, scmd->device, "Device offlined - " in scsi_eh_offline_sdevs()
1810 sdev = scmd->device; in scsi_eh_offline_sdevs()
1812 mutex_lock(&sdev->state_mutex); in scsi_eh_offline_sdevs()
1814 mutex_unlock(&sdev->state_mutex); in scsi_eh_offline_sdevs()
1822 * scsi_noretry_cmd - determine if command should be failed fast
1829 switch (host_byte(scmd->result)) { in scsi_noretry_cmd()
1835 return !!(req->cmd_flags & REQ_FAILFAST_TRANSPORT); in scsi_noretry_cmd()
1837 return !!(req->cmd_flags & REQ_FAILFAST_DEV); in scsi_noretry_cmd()
1843 return !!(req->cmd_flags & REQ_FAILFAST_DRIVER); in scsi_noretry_cmd()
1847 if (scsi_ml_byte(scmd->result) == SCSIML_STAT_DL_TIMEOUT) in scsi_noretry_cmd()
1850 if (!scsi_status_is_check_condition(scmd->result)) in scsi_noretry_cmd()
1858 if (req->cmd_flags & REQ_FAILFAST_DEV || blk_rq_is_passthrough(req)) in scsi_noretry_cmd()
1865 * scsi_decide_disposition - Disposition a cmd on return from LLD.
1886 if (!scsi_device_online(scmd->device)) { in scsi_decide_disposition()
1888 "%s: device offline - report as SUCCESS\n", __func__)); in scsi_decide_disposition()
1896 switch (host_byte(scmd->result)) { in scsi_decide_disposition()
1903 scmd->result &= 0xff00ffff; in scsi_decide_disposition()
1911 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) { in scsi_decide_disposition()
1919 * note - this means that we just report the status back in scsi_decide_disposition()
1970 * when we scan the bus, we get timeout messages for in scsi_decide_disposition()
1974 if ((scmd->cmnd[0] == TEST_UNIT_READY || in scsi_decide_disposition()
1975 scmd->cmnd[0] == INQUIRY)) { in scsi_decide_disposition()
1991 scsi_handle_queue_full(scmd->device); in scsi_decide_disposition()
2000 * occur (SAM-3) when the task queue is empty, so will cause in scsi_decide_disposition()
2006 if (scmd->cmnd[0] == REPORT_LUNS) in scsi_decide_disposition()
2007 scmd->device->sdev_target->expecting_lun_change = 0; in scsi_decide_disposition()
2008 scsi_handle_queue_ramp_up(scmd->device); in scsi_decide_disposition()
2009 if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd)) in scsi_decide_disposition()
2041 sdev_printk(KERN_INFO, scmd->device, in scsi_decide_disposition()
2058 * no more retries - report this one back to upper level. in scsi_decide_disposition()
2072 * scsi_eh_lock_door - Prevent medium removal for the specified device
2087 req = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN, 0); in scsi_eh_lock_door()
2092 scmd->cmnd[0] = ALLOW_MEDIUM_REMOVAL; in scsi_eh_lock_door()
2093 scmd->cmnd[1] = 0; in scsi_eh_lock_door()
2094 scmd->cmnd[2] = 0; in scsi_eh_lock_door()
2095 scmd->cmnd[3] = 0; in scsi_eh_lock_door()
2096 scmd->cmnd[4] = SCSI_REMOVAL_PREVENT; in scsi_eh_lock_door()
2097 scmd->cmnd[5] = 0; in scsi_eh_lock_door()
2098 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_lock_door()
2099 scmd->allowed = 5; in scsi_eh_lock_door()
2101 req->rq_flags |= RQF_QUIET; in scsi_eh_lock_door()
2102 req->timeout = 10 * HZ; in scsi_eh_lock_door()
2103 req->end_io = eh_lock_door_done; in scsi_eh_lock_door()
2109 * scsi_restart_operations - restart io operations to the specified host.
2124 * is no point trying to lock the door of an off-line device. in scsi_restart_operations()
2127 if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) { in scsi_restart_operations()
2129 sdev->was_reset = 0; in scsi_restart_operations()
2136 * ioctls to queued block devices. in scsi_restart_operations()
2141 spin_lock_irqsave(shost->host_lock, flags); in scsi_restart_operations()
2145 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_restart_operations()
2147 wake_up(&shost->host_wait); in scsi_restart_operations()
2150 * finally we need to re-initiate requests that may be pending. we will in scsi_restart_operations()
2158 * if eh is active and host_eh_scheduled is pending we need to re-run in scsi_restart_operations()
2161 * progress before we sync again. Either we'll immediately re-run in scsi_restart_operations()
2165 spin_lock_irqsave(shost->host_lock, flags); in scsi_restart_operations()
2166 if (shost->host_eh_scheduled) in scsi_restart_operations()
2169 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_restart_operations()
2173 * scsi_eh_ready_devs - check device ready state and recover if not.
2193 * scsi_eh_flush_done_q - finish processed commands or retry them.
2201 struct scsi_device *sdev = scmd->device; in scsi_eh_flush_done_q()
2203 list_del_init(&scmd->eh_entry); in scsi_eh_flush_done_q()
2210 current->comm)); in scsi_eh_flush_done_q()
2212 blk_mq_kick_requeue_list(sdev->request_queue); in scsi_eh_flush_done_q()
2216 * scsi_eh_get_sense), scmd->result is already in scsi_eh_flush_done_q()
2219 if (!scmd->result && in scsi_eh_flush_done_q()
2220 !(scmd->flags & SCMD_FORCE_EH_SUCCESS)) in scsi_eh_flush_done_q()
2221 scmd->result |= (DID_TIME_OUT << 16); in scsi_eh_flush_done_q()
2225 current->comm)); in scsi_eh_flush_done_q()
2233 * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
2237 * When we come in here, we *know* that all commands on the bus have
2261 spin_lock_irqsave(shost->host_lock, flags); in scsi_unjam_host()
2262 list_splice_init(&shost->eh_cmd_q, &eh_work_q); in scsi_unjam_host()
2263 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_unjam_host()
2270 spin_lock_irqsave(shost->host_lock, flags); in scsi_unjam_host()
2271 if (shost->eh_deadline != -1) in scsi_unjam_host()
2272 shost->last_reset = 0; in scsi_unjam_host()
2273 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_unjam_host()
2278 * scsi_error_handler - SCSI error handler thread
2306 if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) || in scsi_error_handler()
2307 shost->host_failed != scsi_host_busy(shost)) { in scsi_error_handler()
2311 shost->host_no)); in scsi_error_handler()
2320 shost->host_no, shost->host_eh_scheduled, in scsi_error_handler()
2321 shost->host_failed, in scsi_error_handler()
2329 if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) { in scsi_error_handler()
2333 shost->host_no)); in scsi_error_handler()
2337 if (shost->transportt->eh_strategy_handler) in scsi_error_handler()
2338 shost->transportt->eh_strategy_handler(shost); in scsi_error_handler()
2343 shost->host_failed = 0; in scsi_error_handler()
2346 * Note - if the above fails completely, the action is to take in scsi_error_handler()
2349 * restart, we restart any I/O to any other devices on the bus in scsi_error_handler()
2353 if (!shost->eh_noresume) in scsi_error_handler()
2361 shost->host_no)); in scsi_error_handler()
2362 shost->ehandler = NULL; in scsi_error_handler()
2369 * Purpose: Utility function used by low-level drivers to report that
2370 * they have observed a bus reset on the bus being handled.
2372 * Arguments: shost - Host in question
2373 * channel - channel on which reset was observed.
2381 * by the mid-level itself don't need to call this, but there
2401 * Purpose: Utility function used by low-level drivers to report that
2404 * Arguments: shost - Host in question
2405 * channel - channel on which reset was observed
2406 * target - target on which reset was observed
2414 * by the mid-level itself don't need to call this, but there
2433 * scsi_ioctl_reset: explicitly reset a host/bus/target/device
2441 struct Scsi_Host *shost = dev->host; in scsi_ioctl_reset()
2448 return -EACCES; in scsi_ioctl_reset()
2455 return -EIO; in scsi_ioctl_reset()
2457 error = -EIO; in scsi_ioctl_reset()
2459 shost->hostt->cmd_size, GFP_KERNEL); in scsi_ioctl_reset()
2467 scmd->submitter = SUBMITTED_BY_SCSI_RESET_IOCTL; in scsi_ioctl_reset()
2468 scmd->flags |= SCMD_LAST; in scsi_ioctl_reset()
2469 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); in scsi_ioctl_reset()
2471 scmd->cmd_len = 0; in scsi_ioctl_reset()
2473 scmd->sc_data_direction = DMA_BIDIRECTIONAL; in scsi_ioctl_reset()
2475 spin_lock_irqsave(shost->host_lock, flags); in scsi_ioctl_reset()
2476 shost->tmf_in_progress = 1; in scsi_ioctl_reset()
2477 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_ioctl_reset()
2508 error = (rtn == SUCCESS) ? 0 : -EIO; in scsi_ioctl_reset()
2510 spin_lock_irqsave(shost->host_lock, flags); in scsi_ioctl_reset()
2511 shost->tmf_in_progress = 0; in scsi_ioctl_reset()
2512 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_ioctl_reset()
2522 wake_up(&shost->host_wait); in scsi_ioctl_reset()
2535 return scsi_normalize_sense(cmd->sense_buffer, in scsi_command_normalize_sense()
2541 …* scsi_get_sense_info_fld - get information field from sense data (either fixed or descriptor form…