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()
557 scmd->device->ua_new_media_ctr++; in scsi_check_sense()
559 scmd->device->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()
589 if (scmd->sense_buffer[2] & 0xe0) 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()
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()
639 * if we are expecting a cc/ua because of a bus reset that we 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()
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()
674 if (scmd->device->allow_restart && in scsi_check_sense()
708 if (scmd->device->retry_hwerror) in scsi_check_sense()
716 sshdr.asc == 0x21 || /* Logical block address out of range */ in scsi_check_sense()
735 req->cmd_flags |= REQ_FAILFAST_DEV; in scsi_check_sense()
736 req->rq_flags |= RQF_QUIET; in scsi_check_sense()
748 const struct scsi_host_template *sht = sdev->host->hostt; in scsi_handle_queue_ramp_up()
751 if (!sht->track_queue_depth || in scsi_handle_queue_ramp_up()
752 sdev->queue_depth >= sdev->max_queue_depth) in scsi_handle_queue_ramp_up()
756 sdev->last_queue_ramp_up + sdev->queue_ramp_up_period)) in scsi_handle_queue_ramp_up()
760 sdev->last_queue_full_time + sdev->queue_ramp_up_period)) in scsi_handle_queue_ramp_up()
767 shost_for_each_device(tmp_sdev, sdev->host) { in scsi_handle_queue_ramp_up()
768 if (tmp_sdev->channel != sdev->channel || in scsi_handle_queue_ramp_up()
769 tmp_sdev->id != sdev->id || in scsi_handle_queue_ramp_up()
770 tmp_sdev->queue_depth == sdev->max_queue_depth) in scsi_handle_queue_ramp_up()
773 scsi_change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1); in scsi_handle_queue_ramp_up()
774 sdev->last_queue_ramp_up = jiffies; in scsi_handle_queue_ramp_up()
780 const struct scsi_host_template *sht = sdev->host->hostt; in scsi_handle_queue_full()
783 if (!sht->track_queue_depth) in scsi_handle_queue_full()
786 shost_for_each_device(tmp_sdev, sdev->host) { in scsi_handle_queue_full()
787 if (tmp_sdev->channel != sdev->channel || in scsi_handle_queue_full()
788 tmp_sdev->id != sdev->id) in scsi_handle_queue_full()
795 scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1); in scsi_handle_queue_full()
800 * scsi_eh_completed_normally - Disposition a eh cmd on return from LLD.
815 if (host_byte(scmd->result) == DID_RESET) { in scsi_eh_completed_normally()
824 if (host_byte(scmd->result) != DID_OK) in scsi_eh_completed_normally()
833 scsi_handle_queue_ramp_up(scmd->device); in scsi_eh_completed_normally()
834 if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd)) in scsi_eh_completed_normally()
855 if (scmd->cmnd[0] == TEST_UNIT_READY) in scsi_eh_completed_normally()
862 scsi_handle_queue_full(scmd->device); in scsi_eh_completed_normally()
873 * scsi_eh_done - Completion function for error handling.
881 "%s result: %x\n", __func__, scmd->result)); in scsi_eh_done()
883 eh_action = scmd->device->host->eh_action; in scsi_eh_done()
889 * scsi_try_host_reset - ask host adapter to reset itself
896 struct Scsi_Host *host = scmd->device->host; in scsi_try_host_reset()
897 const struct scsi_host_template *hostt = host->hostt; in scsi_try_host_reset()
902 if (!hostt->eh_host_reset_handler) in scsi_try_host_reset()
905 rtn = hostt->eh_host_reset_handler(scmd); in scsi_try_host_reset()
908 if (!hostt->skip_settle_delay) in scsi_try_host_reset()
910 spin_lock_irqsave(host->host_lock, flags); in scsi_try_host_reset()
912 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_host_reset()
919 * scsi_try_bus_reset - ask host to perform a bus reset
920 * @scmd: SCSI cmd to send bus reset.
926 struct Scsi_Host *host = scmd->device->host; in scsi_try_bus_reset()
927 const struct scsi_host_template *hostt = host->hostt; in scsi_try_bus_reset()
930 "%s: Snd Bus RST\n", __func__)); in scsi_try_bus_reset()
932 if (!hostt->eh_bus_reset_handler) in scsi_try_bus_reset()
935 rtn = hostt->eh_bus_reset_handler(scmd); in scsi_try_bus_reset()
938 if (!hostt->skip_settle_delay) in scsi_try_bus_reset()
940 spin_lock_irqsave(host->host_lock, flags); in scsi_try_bus_reset()
942 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_bus_reset()
950 sdev->was_reset = 1; in __scsi_report_device_reset()
951 sdev->expecting_cc_ua = 1; in __scsi_report_device_reset()
955 * scsi_try_target_reset - Ask host to perform a target reset
968 struct Scsi_Host *host = scmd->device->host; in scsi_try_target_reset()
969 const struct scsi_host_template *hostt = host->hostt; in scsi_try_target_reset()
971 if (!hostt->eh_target_reset_handler) in scsi_try_target_reset()
974 rtn = hostt->eh_target_reset_handler(scmd); in scsi_try_target_reset()
976 spin_lock_irqsave(host->host_lock, flags); in scsi_try_target_reset()
977 __starget_for_each_device(scsi_target(scmd->device), NULL, in scsi_try_target_reset()
979 spin_unlock_irqrestore(host->host_lock, flags); in scsi_try_target_reset()
986 * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
998 const struct scsi_host_template *hostt = scmd->device->host->hostt; in scsi_try_bus_device_reset()
1000 if (!hostt->eh_device_reset_handler) in scsi_try_bus_device_reset()
1003 rtn = hostt->eh_device_reset_handler(scmd); in scsi_try_bus_device_reset()
1005 __scsi_report_device_reset(scmd->device, NULL); in scsi_try_bus_device_reset()
1010 * scsi_try_to_abort_cmd - Ask host to abort a SCSI command
1029 if (!hostt->eh_abort_handler) in scsi_try_to_abort_cmd()
1032 return hostt->eh_abort_handler(scmd); in scsi_try_to_abort_cmd()
1037 if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS) in scsi_abort_eh_cmnd()
1045 * scsi_eh_prep_cmnd - Save a scsi command info as part of error recovery
1052 * This function is used to save a scsi command information before re-execution
1056 * and cmnd buffers to read @sense_bytes into @scmd->sense_buffer.
1061 struct scsi_device *sdev = scmd->device; in scsi_eh_prep_cmnd()
1064 * We need saved copies of a number of fields - this is because in scsi_eh_prep_cmnd()
1070 ses->cmd_len = scmd->cmd_len; in scsi_eh_prep_cmnd()
1071 ses->data_direction = scmd->sc_data_direction; in scsi_eh_prep_cmnd()
1072 ses->sdb = scmd->sdb; in scsi_eh_prep_cmnd()
1073 ses->result = scmd->result; in scsi_eh_prep_cmnd()
1074 ses->resid_len = scmd->resid_len; in scsi_eh_prep_cmnd()
1075 ses->underflow = scmd->underflow; in scsi_eh_prep_cmnd()
1076 ses->prot_op = scmd->prot_op; in scsi_eh_prep_cmnd()
1077 ses->eh_eflags = scmd->eh_eflags; in scsi_eh_prep_cmnd()
1079 scmd->prot_op = SCSI_PROT_NORMAL; in scsi_eh_prep_cmnd()
1080 scmd->eh_eflags = 0; in scsi_eh_prep_cmnd()
1081 memcpy(ses->cmnd, scmd->cmnd, sizeof(ses->cmnd)); in scsi_eh_prep_cmnd()
1082 memset(scmd->cmnd, 0, sizeof(scmd->cmnd)); in scsi_eh_prep_cmnd()
1083 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); in scsi_eh_prep_cmnd()
1084 scmd->result = 0; in scsi_eh_prep_cmnd()
1085 scmd->resid_len = 0; in scsi_eh_prep_cmnd()
1088 scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE, in scsi_eh_prep_cmnd()
1090 sg_init_one(&ses->sense_sgl, scmd->sense_buffer, in scsi_eh_prep_cmnd()
1091 scmd->sdb.length); in scsi_eh_prep_cmnd()
1092 scmd->sdb.table.sgl = &ses->sense_sgl; in scsi_eh_prep_cmnd()
1093 scmd->sc_data_direction = DMA_FROM_DEVICE; in scsi_eh_prep_cmnd()
1094 scmd->sdb.table.nents = scmd->sdb.table.orig_nents = 1; in scsi_eh_prep_cmnd()
1095 scmd->cmnd[0] = REQUEST_SENSE; in scsi_eh_prep_cmnd()
1096 scmd->cmnd[4] = scmd->sdb.length; in scsi_eh_prep_cmnd()
1097 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_prep_cmnd()
1099 scmd->sc_data_direction = DMA_NONE; in scsi_eh_prep_cmnd()
1101 BUG_ON(cmnd_size > sizeof(scmd->cmnd)); in scsi_eh_prep_cmnd()
1102 memcpy(scmd->cmnd, cmnd, cmnd_size); in scsi_eh_prep_cmnd()
1103 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_prep_cmnd()
1107 scmd->underflow = 0; in scsi_eh_prep_cmnd()
1109 if (sdev->scsi_level <= SCSI_2 && sdev->scsi_level != SCSI_UNKNOWN) in scsi_eh_prep_cmnd()
1110 scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) | in scsi_eh_prep_cmnd()
1111 (sdev->lun << 5 & 0xe0); in scsi_eh_prep_cmnd()
1117 memset(scmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in scsi_eh_prep_cmnd()
1122 * scsi_eh_restore_cmnd - Restore a scsi command info as part of error recovery
1133 scmd->cmd_len = ses->cmd_len; in scsi_eh_restore_cmnd()
1134 memcpy(scmd->cmnd, ses->cmnd, sizeof(ses->cmnd)); in scsi_eh_restore_cmnd()
1135 scmd->sc_data_direction = ses->data_direction; in scsi_eh_restore_cmnd()
1136 scmd->sdb = ses->sdb; in scsi_eh_restore_cmnd()
1137 scmd->result = ses->result; in scsi_eh_restore_cmnd()
1138 scmd->resid_len = ses->resid_len; in scsi_eh_restore_cmnd()
1139 scmd->underflow = ses->underflow; in scsi_eh_restore_cmnd()
1140 scmd->prot_op = ses->prot_op; in scsi_eh_restore_cmnd()
1141 scmd->eh_eflags = ses->eh_eflags; in scsi_eh_restore_cmnd()
1146 * scsi_send_eh_cmnd - submit a scsi command as part of error recovery
1162 struct scsi_device *sdev = scmd->device; in scsi_send_eh_cmnd()
1163 struct Scsi_Host *shost = sdev->host; in scsi_send_eh_cmnd()
1172 shost->eh_action = &done; in scsi_send_eh_cmnd()
1175 scmd->submitter = SUBMITTED_BY_SCSI_ERROR_HANDLER; in scsi_send_eh_cmnd()
1176 scmd->flags |= SCMD_LAST; in scsi_send_eh_cmnd()
1179 * Lock sdev->state_mutex to avoid that scsi_device_quiesce() can in scsi_send_eh_cmnd()
1183 mutex_lock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1184 while (sdev->sdev_state == SDEV_BLOCK && timeleft > 0) { in scsi_send_eh_cmnd()
1185 mutex_unlock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1187 "%s: state %d <> %d\n", __func__, sdev->sdev_state, in scsi_send_eh_cmnd()
1190 timeleft -= delay; in scsi_send_eh_cmnd()
1192 mutex_lock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1194 if (sdev->sdev_state != SDEV_BLOCK) in scsi_send_eh_cmnd()
1195 rtn = shost->hostt->queuecommand(shost, scmd); in scsi_send_eh_cmnd()
1198 mutex_unlock(&sdev->state_mutex); in scsi_send_eh_cmnd()
1204 timeleft -= stall_for; in scsi_send_eh_cmnd()
1216 shost->eh_action = NULL; in scsi_send_eh_cmnd()
1230 * ->queuecommand() kept returning non zero, use the rtn = FAILED in scsi_send_eh_cmnd()
1261 * scsi_request_sense - Request sense data from a particular target.
1271 return scsi_send_eh_cmnd(scmd, NULL, 0, scmd->device->eh_timeout, ~0); in scsi_request_sense()
1279 if (sdrv->eh_action) in scsi_eh_action()
1280 rtn = sdrv->eh_action(scmd, rtn); in scsi_eh_action()
1286 * scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
1292 * still handling errors - it may cause other commands to be queued,
1299 list_move_tail(&scmd->eh_entry, done_q); in scsi_eh_finish_cmd()
1304 * scsi_eh_get_sense - Get device sense data.
1335 if ((scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) || in scsi_eh_get_sense()
1339 shost = scmd->device->host; in scsi_eh_get_sense()
1344 current->comm)); in scsi_eh_get_sense()
1347 if (!scsi_status_is_check_condition(scmd->result)) in scsi_eh_get_sense()
1358 current->comm)); in scsi_eh_get_sense()
1364 "sense requested, result %x\n", scmd->result)); in scsi_eh_get_sense()
1382 if (scmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT) in scsi_eh_get_sense()
1383 scmd->retries = scmd->allowed = 1; in scsi_eh_get_sense()
1385 scmd->retries = scmd->allowed; in scsi_eh_get_sense()
1397 * scsi_eh_tur - Send TUR to device.
1401 * 0 - Device is ready. 1 - Device NOT ready.
1411 scmd->device->eh_timeout, 0); in scsi_eh_tur()
1418 if (retry_cnt--) in scsi_eh_tur()
1429 * scsi_eh_test_devices - check if devices are responding from error recovery.
1450 scmd = list_entry(cmd_list->next, struct scsi_cmnd, eh_entry); in scsi_eh_test_devices()
1451 sdev = scmd->device; in scsi_eh_test_devices()
1454 if (scsi_host_eh_past_deadline(sdev->host)) { in scsi_eh_test_devices()
1460 current->comm)); in scsi_eh_test_devices()
1465 finish_cmds = !scsi_device_online(scmd->device) || in scsi_eh_test_devices()
1471 if (scmd->device == sdev) { in scsi_eh_test_devices()
1477 list_move_tail(&scmd->eh_entry, work_q); in scsi_eh_test_devices()
1484 * scsi_eh_try_stu - Send START_UNIT to device.
1488 * 0 - Device is ready. 1 - Device NOT ready.
1494 if (scmd->device->allow_restart) { in scsi_eh_try_stu()
1500 scmd->device->eh_timeout, 0); in scsi_eh_try_stu()
1510 * scsi_eh_stu - send START_UNIT if needed
1531 current->comm)); in scsi_eh_stu()
1537 if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) && in scsi_eh_stu()
1549 current->comm)); in scsi_eh_stu()
1556 if (scmd->device == sdev && in scsi_eh_stu()
1565 current->comm)); in scsi_eh_stu()
1574 * scsi_eh_bus_device_reset - send bdr if needed
1580 * Try a bus device reset. Still, look to see whether we have multiple
1581 * devices that are jammed or not - if we have multiple devices, it
1582 * makes no sense to try bus_device_reset - we really would need to try
1598 current->comm)); in scsi_eh_bus_device_reset()
1604 if (scmd->device == sdev) { in scsi_eh_bus_device_reset()
1614 "%s: Sending BDR\n", current->comm)); in scsi_eh_bus_device_reset()
1622 if (scmd->device == sdev && in scsi_eh_bus_device_reset()
1631 "%s: BDR failed\n", current->comm)); in scsi_eh_bus_device_reset()
1639 * scsi_eh_target_reset - send target reset if needed
1668 current->comm)); in scsi_eh_target_reset()
1678 current->comm, id)); in scsi_eh_target_reset()
1685 current->comm, id)); in scsi_eh_target_reset()
1691 list_move_tail(&scmd->eh_entry, &check_list); in scsi_eh_target_reset()
1696 list_move(&scmd->eh_entry, work_q); in scsi_eh_target_reset()
1704 * scsi_eh_bus_reset - send a bus reset
1725 for (channel = 0; channel <= shost->max_channel; channel++) { in scsi_eh_bus_reset()
1731 current->comm)); in scsi_eh_bus_reset()
1752 current->comm, channel)); in scsi_eh_bus_reset()
1761 list_move_tail(&scmd->eh_entry, in scsi_eh_bus_reset()
1769 current->comm, channel)); in scsi_eh_bus_reset()
1776 * scsi_eh_host_reset - send a host reset
1790 scmd = list_entry(work_q->next, in scsi_eh_host_reset()
1796 current->comm)); in scsi_eh_host_reset()
1809 current->comm)); in scsi_eh_host_reset()
1816 * scsi_eh_offline_sdevs - offline scsi devices that fail to recover
1827 sdev_printk(KERN_INFO, scmd->device, "Device offlined - " in scsi_eh_offline_sdevs()
1829 sdev = scmd->device; in scsi_eh_offline_sdevs()
1831 mutex_lock(&sdev->state_mutex); in scsi_eh_offline_sdevs()
1833 mutex_unlock(&sdev->state_mutex); in scsi_eh_offline_sdevs()
1841 * scsi_noretry_cmd - determine if command should be failed fast
1848 switch (host_byte(scmd->result)) { in scsi_noretry_cmd()
1854 return !!(req->cmd_flags & REQ_FAILFAST_TRANSPORT); in scsi_noretry_cmd()
1856 return !!(req->cmd_flags & REQ_FAILFAST_DEV); in scsi_noretry_cmd()
1862 return !!(req->cmd_flags & REQ_FAILFAST_DRIVER); in scsi_noretry_cmd()
1866 if (scsi_ml_byte(scmd->result) == SCSIML_STAT_DL_TIMEOUT) in scsi_noretry_cmd()
1869 if (!scsi_status_is_check_condition(scmd->result)) in scsi_noretry_cmd()
1877 if (req->cmd_flags & REQ_FAILFAST_DEV || blk_rq_is_passthrough(req)) in scsi_noretry_cmd()
1884 * scsi_decide_disposition - Disposition a cmd on return from LLD.
1905 if (!scsi_device_online(scmd->device)) { in scsi_decide_disposition()
1907 "%s: device offline - report as SUCCESS\n", __func__)); in scsi_decide_disposition()
1915 switch (host_byte(scmd->result)) { in scsi_decide_disposition()
1922 scmd->result &= 0xff00ffff; in scsi_decide_disposition()
1930 if (scmd->eh_eflags & SCSI_EH_ABORT_SCHEDULED) { in scsi_decide_disposition()
1938 * note - this means that we just report the status back in scsi_decide_disposition()
1989 * when we scan the bus, we get timeout messages for in scsi_decide_disposition()
1993 if ((scmd->cmnd[0] == TEST_UNIT_READY || in scsi_decide_disposition()
1994 scmd->cmnd[0] == INQUIRY)) { in scsi_decide_disposition()
2010 scsi_handle_queue_full(scmd->device); in scsi_decide_disposition()
2019 * occur (SAM-3) when the task queue is empty, so will cause in scsi_decide_disposition()
2025 if (scmd->cmnd[0] == REPORT_LUNS) in scsi_decide_disposition()
2026 scmd->device->sdev_target->expecting_lun_change = 0; in scsi_decide_disposition()
2027 scsi_handle_queue_ramp_up(scmd->device); in scsi_decide_disposition()
2028 if (scmd->sense_buffer && SCSI_SENSE_VALID(scmd)) in scsi_decide_disposition()
2060 sdev_printk(KERN_INFO, scmd->device, in scsi_decide_disposition()
2077 * no more retries - report this one back to upper level. in scsi_decide_disposition()
2091 * scsi_eh_lock_door - Prevent medium removal for the specified device
2106 req = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN, 0); in scsi_eh_lock_door()
2111 scmd->cmnd[0] = ALLOW_MEDIUM_REMOVAL; in scsi_eh_lock_door()
2112 scmd->cmnd[1] = 0; in scsi_eh_lock_door()
2113 scmd->cmnd[2] = 0; in scsi_eh_lock_door()
2114 scmd->cmnd[3] = 0; in scsi_eh_lock_door()
2115 scmd->cmnd[4] = SCSI_REMOVAL_PREVENT; in scsi_eh_lock_door()
2116 scmd->cmnd[5] = 0; in scsi_eh_lock_door()
2117 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); in scsi_eh_lock_door()
2118 scmd->allowed = 5; in scsi_eh_lock_door()
2120 req->rq_flags |= RQF_QUIET; in scsi_eh_lock_door()
2121 req->timeout = 10 * HZ; in scsi_eh_lock_door()
2122 req->end_io = eh_lock_door_done; in scsi_eh_lock_door()
2128 * scsi_restart_operations - restart io operations to the specified host.
2143 * is no point trying to lock the door of an off-line device. in scsi_restart_operations()
2146 if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) { in scsi_restart_operations()
2148 sdev->was_reset = 0; in scsi_restart_operations()
2155 * ioctls to queued block devices. in scsi_restart_operations()
2160 spin_lock_irqsave(shost->host_lock, flags); in scsi_restart_operations()
2164 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_restart_operations()
2166 wake_up(&shost->host_wait); in scsi_restart_operations()
2169 * finally we need to re-initiate requests that may be pending. we will in scsi_restart_operations()
2177 * if eh is active and host_eh_scheduled is pending we need to re-run in scsi_restart_operations()
2180 * progress before we sync again. Either we'll immediately re-run in scsi_restart_operations()
2184 spin_lock_irqsave(shost->host_lock, flags); in scsi_restart_operations()
2185 if (shost->host_eh_scheduled) in scsi_restart_operations()
2188 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_restart_operations()
2192 * scsi_eh_ready_devs - check device ready state and recover if not.
2212 * scsi_eh_flush_done_q - finish processed commands or retry them.
2220 struct scsi_device *sdev = scmd->device; in scsi_eh_flush_done_q()
2222 list_del_init(&scmd->eh_entry); in scsi_eh_flush_done_q()
2229 current->comm)); in scsi_eh_flush_done_q()
2231 blk_mq_kick_requeue_list(sdev->request_queue); in scsi_eh_flush_done_q()
2235 * scsi_eh_get_sense), scmd->result is already in scsi_eh_flush_done_q()
2238 if (!scmd->result && in scsi_eh_flush_done_q()
2239 !(scmd->flags & SCMD_FORCE_EH_SUCCESS)) in scsi_eh_flush_done_q()
2240 scmd->result |= (DID_TIME_OUT << 16); in scsi_eh_flush_done_q()
2244 current->comm)); in scsi_eh_flush_done_q()
2252 * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
2256 * When we come in here, we *know* that all commands on the bus have
2280 spin_lock_irqsave(shost->host_lock, flags); in scsi_unjam_host()
2281 list_splice_init(&shost->eh_cmd_q, &eh_work_q); in scsi_unjam_host()
2282 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_unjam_host()
2289 spin_lock_irqsave(shost->host_lock, flags); in scsi_unjam_host()
2290 if (shost->eh_deadline != -1) in scsi_unjam_host()
2291 shost->last_reset = 0; in scsi_unjam_host()
2292 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_unjam_host()
2297 * scsi_error_handler - SCSI error handler thread
2325 if ((shost->host_failed == 0 && shost->host_eh_scheduled == 0) || in scsi_error_handler()
2326 shost->host_failed != scsi_host_busy(shost)) { in scsi_error_handler()
2330 shost->host_no)); in scsi_error_handler()
2339 shost->host_no, shost->host_eh_scheduled, in scsi_error_handler()
2340 shost->host_failed, in scsi_error_handler()
2348 if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) { in scsi_error_handler()
2352 shost->host_no)); in scsi_error_handler()
2356 if (shost->transportt->eh_strategy_handler) in scsi_error_handler()
2357 shost->transportt->eh_strategy_handler(shost); in scsi_error_handler()
2362 shost->host_failed = 0; in scsi_error_handler()
2365 * Note - if the above fails completely, the action is to take in scsi_error_handler()
2368 * restart, we restart any I/O to any other devices on the bus in scsi_error_handler()
2372 if (!shost->eh_noresume) in scsi_error_handler()
2380 shost->host_no)); in scsi_error_handler()
2381 shost->ehandler = NULL; in scsi_error_handler()
2386 * scsi_report_bus_reset() - report bus reset observed
2388 * Utility function used by low-level drivers to report that
2389 * they have observed a bus reset on the bus being handled.
2400 * by the mid-level itself don't need to call this, but there
2418 * scsi_report_device_reset() - report device reset observed
2420 * Utility function used by low-level drivers to report that
2433 * by the mid-level itself don't need to call this, but there
2452 * scsi_ioctl_reset: explicitly reset a host/bus/target/device
2460 struct Scsi_Host *shost = dev->host; in scsi_ioctl_reset()
2467 return -EACCES; in scsi_ioctl_reset()
2474 return -EIO; in scsi_ioctl_reset()
2476 error = -EIO; in scsi_ioctl_reset()
2478 shost->hostt->cmd_size, GFP_KERNEL); in scsi_ioctl_reset()
2486 scmd->submitter = SUBMITTED_BY_SCSI_RESET_IOCTL; in scsi_ioctl_reset()
2487 scmd->flags |= SCMD_LAST; in scsi_ioctl_reset()
2488 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); in scsi_ioctl_reset()
2490 scmd->cmd_len = 0; in scsi_ioctl_reset()
2492 scmd->sc_data_direction = DMA_BIDIRECTIONAL; in scsi_ioctl_reset()
2494 spin_lock_irqsave(shost->host_lock, flags); in scsi_ioctl_reset()
2495 shost->tmf_in_progress = 1; in scsi_ioctl_reset()
2496 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_ioctl_reset()
2527 error = (rtn == SUCCESS) ? 0 : -EIO; in scsi_ioctl_reset()
2529 spin_lock_irqsave(shost->host_lock, flags); in scsi_ioctl_reset()
2530 shost->tmf_in_progress = 0; in scsi_ioctl_reset()
2531 spin_unlock_irqrestore(shost->host_lock, flags); in scsi_ioctl_reset()
2541 wake_up(&shost->host_wait); in scsi_ioctl_reset()
2554 return scsi_normalize_sense(cmd->sense_buffer, in scsi_command_normalize_sense()
2560 …* scsi_get_sense_info_fld - get information field from sense data (either fixed or descriptor form…