2 * scsi_error.c Copyright (C) 1997 Eric Youngdale
4 * SCSI error/timeout handling
5 * Initial versions: Eric Youngdale. Based upon conversations with
6 * Leonard Zubkoff and David Miller at Linux Expo,
7 * ideas originating from all over the place.
9 * Restructured scsi_unjam_host and associated functions.
10 * September 04, 2002 Mike Anderson (andmike@us.ibm.com)
12 * Forward port of Russell King's (rmk@arm.linux.org.uk) changes and
14 * September 30, 2002 Mike Anderson (andmike@us.ibm.com)
17 #include <linux/module.h>
18 #include <linux/sched.h>
19 #include <linux/timer.h>
20 #include <linux/string.h>
21 #include <linux/slab.h>
22 #include <linux/kernel.h>
23 #include <linux/interrupt.h>
24 #include <linux/blkdev.h>
25 #include <linux/smp_lock.h>
26 #include <scsi/scsi_ioctl.h>
29 #include <scsi/scsi_host.h>
31 #include "scsi_priv.h"
32 #include "scsi_logging.h"
34 #define SENSE_TIMEOUT (10*HZ)
35 #define START_UNIT_TIMEOUT (30*HZ)
38 * These should *probably* be handled by the host itself.
39 * Since it is allowed to sleep, it probably should.
41 #define BUS_RESET_SETTLE_TIME (10*HZ)
42 #define HOST_RESET_SETTLE_TIME (10*HZ)
44 /* called with shost->host_lock held */
45 void scsi_eh_wakeup(struct Scsi_Host *shost)
47 if (shost->host_busy == shost->host_failed) {
49 SCSI_LOG_ERROR_RECOVERY(5,
50 printk("Waking error handler thread\n"));
55 * scsi_eh_scmd_add - add scsi cmd to error handling.
56 * @scmd: scmd to run eh on.
57 * @eh_flag: optional SCSI_EH flag.
62 int scsi_eh_scmd_add(struct scsi_cmnd *scmd, int eh_flag)
64 struct Scsi_Host *shost = scmd->device->host;
67 if (shost->eh_wait == NULL)
70 spin_lock_irqsave(shost->host_lock, flags);
72 scsi_eh_eflags_set(scmd, eh_flag);
74 * FIXME: Can we stop setting owner and state.
76 scmd->owner = SCSI_OWNER_ERROR_HANDLER;
77 scmd->state = SCSI_STATE_FAILED;
79 * Set the serial_number_at_timeout to the current
82 scmd->serial_number_at_timeout = scmd->serial_number;
83 list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
84 set_bit(SHOST_RECOVERY, &shost->shost_state);
86 scsi_eh_wakeup(shost);
87 spin_unlock_irqrestore(shost->host_lock, flags);
92 * scsi_add_timer - Start timeout timer for a single scsi command.
93 * @scmd: scsi command that is about to start running.
94 * @timeout: amount of time to allow this command to run.
95 * @complete: timeout function to call if timer isn't canceled.
98 * This should be turned into an inline function. Each scsi command
99 * has its own timer, and as it is added to the queue, we set up the
100 * timer. When the command completes, we cancel the timer.
102 void scsi_add_timer(struct scsi_cmnd *scmd, int timeout,
103 void (*complete)(struct scsi_cmnd *))
107 * If the clock was already running for this command, then
108 * first delete the timer. The timer handling code gets rather
109 * confused if we don't do this.
111 if (scmd->eh_timeout.function)
112 del_timer(&scmd->eh_timeout);
114 scmd->eh_timeout.data = (unsigned long)scmd;
115 scmd->eh_timeout.expires = jiffies + timeout;
116 scmd->eh_timeout.function = (void (*)(unsigned long)) complete;
118 SCSI_LOG_ERROR_RECOVERY(5, printk("%s: scmd: %p, time:"
119 " %d, (%p)\n", __FUNCTION__,
120 scmd, timeout, complete));
122 add_timer(&scmd->eh_timeout);
126 * scsi_delete_timer - Delete/cancel timer for a given function.
127 * @scmd: Cmd that we are canceling timer for
130 * This should be turned into an inline function.
133 * 1 if we were able to detach the timer. 0 if we blew it, and the
134 * timer function has already started to run.
136 int scsi_delete_timer(struct scsi_cmnd *scmd)
140 rtn = del_timer(&scmd->eh_timeout);
142 SCSI_LOG_ERROR_RECOVERY(5, printk("%s: scmd: %p,"
143 " rtn: %d\n", __FUNCTION__,
146 scmd->eh_timeout.data = (unsigned long)NULL;
147 scmd->eh_timeout.function = NULL;
153 * scsi_times_out - Timeout function for normal scsi commands.
154 * @scmd: Cmd that is timing out.
157 * We do not need to lock this. There is the potential for a race
158 * only in that the normal completion handling might run, but if the
159 * normal completion function determines that the timer has already
160 * fired, then it mustn't do anything.
162 void scsi_times_out(struct scsi_cmnd *scmd)
164 scsi_log_completion(scmd, TIMEOUT_ERROR);
165 if (unlikely(!scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD))) {
166 panic("Error handler thread not present at %p %p %s %d",
167 scmd, scmd->device->host, __FILE__, __LINE__);
172 * scsi_block_when_processing_errors - Prevent cmds from being queued.
173 * @sdev: Device on which we are performing recovery.
176 * We block until the host is out of error recovery, and then check to
177 * see whether the host or the device is offline.
180 * 0 when dev was taken offline by error recovery. 1 OK to proceed.
182 int scsi_block_when_processing_errors(struct scsi_device *sdev)
186 wait_event(sdev->host->host_wait, (!test_bit(SHOST_RECOVERY, &sdev->host->shost_state)));
188 online = scsi_device_online(sdev);
190 SCSI_LOG_ERROR_RECOVERY(5, printk("%s: rtn: %d\n", __FUNCTION__,
196 #ifdef CONFIG_SCSI_LOGGING
198 * scsi_eh_prt_fail_stats - Log info on failures.
199 * @shost: scsi host being recovered.
200 * @work_q: Queue of scsi cmds to process.
202 static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
203 struct list_head *work_q)
205 struct scsi_cmnd *scmd;
206 struct scsi_device *sdev;
207 int total_failures = 0;
210 int devices_failed = 0;
212 shost_for_each_device(sdev, shost) {
213 list_for_each_entry(scmd, work_q, eh_entry) {
214 if (scmd->device == sdev) {
216 if (scsi_eh_eflags_chk(scmd,
224 if (cmd_cancel || cmd_failed) {
225 SCSI_LOG_ERROR_RECOVERY(3,
226 printk("%s: %d:%d:%d:%d cmds failed: %d,"
228 __FUNCTION__, shost->host_no,
229 sdev->channel, sdev->id, sdev->lun,
230 cmd_failed, cmd_cancel));
237 SCSI_LOG_ERROR_RECOVERY(2, printk("Total of %d commands on %d"
238 " devices require eh work\n",
239 total_failures, devices_failed));
244 * scsi_check_sense - Examine scsi cmd sense
245 * @scmd: Cmd to have sense checked.
248 * SUCCESS or FAILED or NEEDS_RETRY
250 static int scsi_check_sense(struct scsi_cmnd *scmd)
252 if (!SCSI_SENSE_VALID(scmd))
255 if (scmd->sense_buffer[2] & 0xe0)
258 switch (scmd->sense_buffer[2] & 0xf) {
261 case RECOVERED_ERROR:
262 return /* soft_error */ SUCCESS;
264 case ABORTED_COMMAND:
269 * if we are expecting a cc/ua because of a bus reset that we
270 * performed, treat this just as a retry. otherwise this is
271 * information that we should pass up to the upper-level driver
272 * so that we can deal with it there.
274 if (scmd->device->expecting_cc_ua) {
275 scmd->device->expecting_cc_ua = 0;
279 * if the device is in the process of becoming ready, we
282 if ((scmd->sense_buffer[12] == 0x04) &&
283 (scmd->sense_buffer[13] == 0x01)) {
287 * if the device is not started, we need to wake
288 * the error handler to start the motor
290 if (scmd->device->allow_restart &&
291 (scmd->sense_buffer[12] == 0x04) &&
292 (scmd->sense_buffer[13] == 0x02)) {
297 /* these three are not supported */
299 case VOLUME_OVERFLOW:
306 case ILLEGAL_REQUEST:
316 * scsi_eh_completed_normally - Disposition a eh cmd on return from LLD.
317 * @scmd: SCSI cmd to examine.
320 * This is *only* called when we are examining the status of commands
321 * queued during error recovery. the main difference here is that we
322 * don't allow for the possibility of retries here, and we are a lot
323 * more restrictive about what we consider acceptable.
325 static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)
328 * first check the host byte, to see if there is anything in there
329 * that would indicate what we need to do.
331 if (host_byte(scmd->result) == DID_RESET) {
333 * rats. we are already in the error handler, so we now
334 * get to try and figure out what to do next. if the sense
335 * is valid, we have a pretty good idea of what to do.
336 * if not, we mark it as FAILED.
338 return scsi_check_sense(scmd);
340 if (host_byte(scmd->result) != DID_OK)
344 * next, check the message byte.
346 if (msg_byte(scmd->result) != COMMAND_COMPLETE)
350 * now, check the status byte to see if this indicates
353 switch (status_byte(scmd->result)) {
355 case COMMAND_TERMINATED:
357 case CHECK_CONDITION:
358 return scsi_check_sense(scmd);
360 case INTERMEDIATE_GOOD:
361 case INTERMEDIATE_C_GOOD:
363 * who knows? FIXME(eric)
368 case RESERVATION_CONFLICT:
376 * scsi_eh_times_out - timeout function for error handling.
377 * @scmd: Cmd that is timing out.
380 * During error handling, the kernel thread will be sleeping waiting
381 * for some action to complete on the device. our only job is to
382 * record that it timed out, and to wake up the thread.
384 static void scsi_eh_times_out(struct scsi_cmnd *scmd)
386 scsi_eh_eflags_set(scmd, SCSI_EH_REC_TIMEOUT);
387 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd:%p\n", __FUNCTION__,
390 if (scmd->device->host->eh_action)
391 up(scmd->device->host->eh_action);
395 * scsi_eh_done - Completion function for error handling.
396 * @scmd: Cmd that is done.
398 static void scsi_eh_done(struct scsi_cmnd *scmd)
401 * if the timeout handler is already running, then just set the
402 * flag which says we finished late, and return. we have no
403 * way of stopping the timeout handler from running, so we must
404 * always defer to it.
406 if (del_timer(&scmd->eh_timeout)) {
407 scmd->request->rq_status = RQ_SCSI_DONE;
408 scmd->owner = SCSI_OWNER_ERROR_HANDLER;
410 SCSI_LOG_ERROR_RECOVERY(3, printk("%s scmd: %p result: %x\n",
411 __FUNCTION__, scmd, scmd->result));
413 if (scmd->device->host->eh_action)
414 up(scmd->device->host->eh_action);
419 * scsi_send_eh_cmnd - send a cmd to a device as part of error recovery.
420 * @scmd: SCSI Cmd to send.
421 * @timeout: Timeout for cmd.
424 * The initialization of the structures is quite a bit different in
425 * this case, and furthermore, there is a different completion handler
426 * vs scsi_dispatch_cmd.
428 * SUCCESS or FAILED or NEEDS_RETRY
430 static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout)
432 struct Scsi_Host *host = scmd->device->host;
433 DECLARE_MUTEX_LOCKED(sem);
438 * we will use a queued command if possible, otherwise we will
439 * emulate the queuing and calling of completion function ourselves.
441 scmd->owner = SCSI_OWNER_LOWLEVEL;
443 if (scmd->device->scsi_level <= SCSI_2)
444 scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) |
445 (scmd->device->lun << 5 & 0xe0);
447 scsi_add_timer(scmd, timeout, scsi_eh_times_out);
450 * set up the semaphore so we wait for the command to complete.
452 scmd->device->host->eh_action = &sem;
453 scmd->request->rq_status = RQ_SCSI_BUSY;
455 spin_lock_irqsave(scmd->device->host->host_lock, flags);
457 host->hostt->queuecommand(scmd, scsi_eh_done);
458 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
461 scsi_log_completion(scmd, SUCCESS);
463 scmd->device->host->eh_action = NULL;
466 * see if timeout. if so, tell the host to forget about it.
467 * in other words, we don't want a callback any more.
469 if (scsi_eh_eflags_chk(scmd, SCSI_EH_REC_TIMEOUT)) {
470 scsi_eh_eflags_clr(scmd, SCSI_EH_REC_TIMEOUT);
471 scmd->owner = SCSI_OWNER_LOWLEVEL;
474 * as far as the low level driver is
475 * concerned, this command is still active, so
476 * we must give the low level driver a chance
479 * FIXME(eric) - we are not tracking whether we could
480 * abort a timed out command or not. not sure how
481 * we should treat them differently anyways.
483 spin_lock_irqsave(scmd->device->host->host_lock, flags);
484 if (scmd->device->host->hostt->eh_abort_handler)
485 scmd->device->host->hostt->eh_abort_handler(scmd);
486 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
488 scmd->request->rq_status = RQ_SCSI_DONE;
489 scmd->owner = SCSI_OWNER_ERROR_HANDLER;
494 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd: %p, rtn:%x\n",
495 __FUNCTION__, scmd, rtn));
498 * now examine the actual status codes to see whether the command
499 * actually did complete normally.
501 if (rtn == SUCCESS) {
502 rtn = scsi_eh_completed_normally(scmd);
503 SCSI_LOG_ERROR_RECOVERY(3,
504 printk("%s: scsi_eh_completed_normally %x\n",
521 * scsi_request_sense - Request sense data from a particular target.
522 * @scmd: SCSI cmd for request sense.
525 * Some hosts automatically obtain this information, others require
526 * that we obtain it on our own. This function will *not* return until
527 * the command either times out, or it completes.
529 static int scsi_request_sense(struct scsi_cmnd *scmd)
531 static unsigned char generic_sense[6] =
532 {REQUEST_SENSE, 0, 0, 0, 252, 0};
533 unsigned char *scsi_result;
537 memcpy(scmd->cmnd, generic_sense, sizeof(generic_sense));
539 scsi_result = kmalloc(252, GFP_ATOMIC | (scmd->device->host->hostt->unchecked_isa_dma) ? __GFP_DMA : 0);
542 if (unlikely(!scsi_result)) {
543 printk(KERN_ERR "%s: cannot allocate scsi_result.\n",
549 * zero the sense buffer. some host adapters automatically always
550 * request sense, so it is not a good idea that
551 * scmd->request_buffer and scmd->sense_buffer point to the same
552 * address (db). 0 is not a valid sense code.
554 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
555 memset(scsi_result, 0, 252);
557 saved_result = scmd->result;
558 scmd->request_buffer = scsi_result;
559 scmd->request_bufflen = 252;
561 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
562 scmd->sc_data_direction = DMA_FROM_DEVICE;
565 rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
567 /* last chance to have valid sense data */
568 if(!SCSI_SENSE_VALID(scmd)) {
569 memcpy(scmd->sense_buffer, scmd->request_buffer,
570 sizeof(scmd->sense_buffer));
576 * when we eventually call scsi_finish, we really wish to complete
577 * the original request, so let's restore the original data. (db)
579 scsi_setup_cmd_retry(scmd);
580 scmd->result = saved_result;
585 * scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
586 * @scmd: Original SCSI cmd that eh has finished.
587 * @done_q: Queue for processed commands.
590 * We don't want to use the normal command completion while we are are
591 * still handling errors - it may cause other commands to be queued,
592 * and that would disturb what we are doing. thus we really want to
593 * keep a list of pending commands for final completion, and once we
594 * are ready to leave error handling we handle completion for real.
596 static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
597 struct list_head *done_q)
599 scmd->device->host->host_failed--;
600 scmd->state = SCSI_STATE_BHQUEUE;
602 scsi_eh_eflags_clr_all(scmd);
605 * set this back so that the upper level can correctly free up
608 scsi_setup_cmd_retry(scmd);
609 list_move_tail(&scmd->eh_entry, done_q);
613 * scsi_eh_get_sense - Get device sense data.
614 * @work_q: Queue of commands to process.
615 * @done_q: Queue of proccessed commands..
618 * See if we need to request sense information. if so, then get it
619 * now, so we have a better idea of what to do.
622 * This has the unfortunate side effect that if a shost adapter does
623 * not automatically request sense information, that we end up shutting
624 * it down before we request it. All shosts should be doing this
625 * anyways, so for now all I have to say is tough noogies if you end up
626 * in here. On second thought, this is probably a good idea. We
627 * *really* want to give authors an incentive to automatically request
630 * In 2.5 this capability will be going away.
634 static int scsi_eh_get_sense(struct list_head *work_q,
635 struct list_head *done_q)
637 struct list_head *lh, *lh_sf;
638 struct scsi_cmnd *scmd;
641 list_for_each_safe(lh, lh_sf, work_q) {
642 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
643 if (scsi_eh_eflags_chk(scmd, SCSI_EH_CANCEL_CMD) ||
644 SCSI_SENSE_VALID(scmd))
647 SCSI_LOG_ERROR_RECOVERY(2, printk("%s: requesting sense"
651 rtn = scsi_request_sense(scmd);
655 SCSI_LOG_ERROR_RECOVERY(3, printk("sense requested for %p"
656 " result %x\n", scmd,
658 SCSI_LOG_ERROR_RECOVERY(3, print_sense("bh", scmd));
660 rtn = scsi_decide_disposition(scmd);
663 * if the result was normal, then just pass it along to the
667 /* we don't want this command reissued, just
668 * finished with the sense data, so set
669 * retries to the max allowed to ensure it
670 * won't get reissued */
671 scmd->retries = scmd->allowed;
672 else if (rtn != NEEDS_RETRY)
675 scsi_eh_finish_cmd(scmd, done_q);
678 return list_empty(work_q);
682 * scsi_try_to_abort_cmd - Ask host to abort a running command.
683 * @scmd: SCSI cmd to abort from Lower Level.
686 * This function will not return until the user's completion function
687 * has been called. there is no timeout on this operation. if the
688 * author of the low-level driver wishes this operation to be timed,
689 * they can provide this facility themselves. helper functions in
690 * scsi_error.c can be supplied to make this easier to do.
692 static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
697 if (!scmd->device->host->hostt->eh_abort_handler)
701 * scsi_done was called just after the command timed out and before
702 * we had a chance to process it. (db)
704 if (scmd->serial_number == 0)
707 scmd->owner = SCSI_OWNER_LOWLEVEL;
709 spin_lock_irqsave(scmd->device->host->host_lock, flags);
710 rtn = scmd->device->host->hostt->eh_abort_handler(scmd);
711 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
717 * scsi_eh_tur - Send TUR to device.
718 * @scmd: Scsi cmd to send TUR
721 * 0 - Device is ready. 1 - Device NOT ready.
723 static int scsi_eh_tur(struct scsi_cmnd *scmd)
725 static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0};
726 int retry_cnt = 1, rtn;
729 memcpy(scmd->cmnd, tur_command, sizeof(tur_command));
732 * zero the sense buffer. the scsi spec mandates that any
733 * untransferred sense data should be interpreted as being zero.
735 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
737 scmd->request_buffer = NULL;
738 scmd->request_bufflen = 0;
740 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
742 scmd->sc_data_direction = DMA_NONE;
744 rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
747 * when we eventually call scsi_finish, we really wish to complete
748 * the original request, so let's restore the original data. (db)
750 scsi_setup_cmd_retry(scmd);
753 * hey, we are done. let's look to see what happened.
755 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
756 __FUNCTION__, scmd, rtn));
759 else if (rtn == NEEDS_RETRY)
766 * scsi_eh_abort_cmds - abort canceled commands.
767 * @shost: scsi host being recovered.
768 * @eh_done_q: list_head for processed commands.
771 * Try and see whether or not it makes sense to try and abort the
772 * running command. this only works out to be the case if we have one
773 * command that has timed out. if the command simply failed, it makes
774 * no sense to try and abort the command, since as far as the shost
775 * adapter is concerned, it isn't running.
777 static int scsi_eh_abort_cmds(struct list_head *work_q,
778 struct list_head *done_q)
780 struct list_head *lh, *lh_sf;
781 struct scsi_cmnd *scmd;
784 list_for_each_safe(lh, lh_sf, work_q) {
785 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
786 if (!scsi_eh_eflags_chk(scmd, SCSI_EH_CANCEL_CMD))
788 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:"
789 "0x%p\n", current->comm,
791 rtn = scsi_try_to_abort_cmd(scmd);
792 if (rtn == SUCCESS) {
793 scsi_eh_eflags_clr(scmd, SCSI_EH_CANCEL_CMD);
794 if (!scsi_device_online(scmd->device) ||
795 !scsi_eh_tur(scmd)) {
796 scsi_eh_finish_cmd(scmd, done_q);
800 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting"
807 return list_empty(work_q);
811 * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
812 * @scmd: SCSI cmd used to send BDR
815 * There is no timeout for this operation. if this operation is
816 * unreliable for a given host, then the host itself needs to put a
817 * timer on it, and set the host back to a consistent state prior to
820 static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
825 if (!scmd->device->host->hostt->eh_device_reset_handler)
828 scmd->owner = SCSI_OWNER_LOWLEVEL;
830 spin_lock_irqsave(scmd->device->host->host_lock, flags);
831 rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd);
832 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
834 if (rtn == SUCCESS) {
835 scmd->device->was_reset = 1;
836 scmd->device->expecting_cc_ua = 1;
843 * scsi_eh_try_stu - Send START_UNIT to device.
844 * @scmd: Scsi cmd to send START_UNIT
847 * 0 - Device is ready. 1 - Device NOT ready.
849 static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
851 static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0};
854 if (!scmd->device->allow_restart)
857 memcpy(scmd->cmnd, stu_command, sizeof(stu_command));
860 * zero the sense buffer. the scsi spec mandates that any
861 * untransferred sense data should be interpreted as being zero.
863 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
865 scmd->request_buffer = NULL;
866 scmd->request_bufflen = 0;
868 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
870 scmd->sc_data_direction = DMA_NONE;
872 rtn = scsi_send_eh_cmnd(scmd, START_UNIT_TIMEOUT);
875 * when we eventually call scsi_finish, we really wish to complete
876 * the original request, so let's restore the original data. (db)
878 scsi_setup_cmd_retry(scmd);
881 * hey, we are done. let's look to see what happened.
883 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
884 __FUNCTION__, scmd, rtn));
891 * scsi_eh_stu - send START_UNIT if needed
892 * @shost: scsi host being recovered.
893 * @eh_done_q: list_head for processed commands.
896 * If commands are failing due to not ready, initializing command required,
897 * try revalidating the device, which will end up sending a start unit.
899 static int scsi_eh_stu(struct Scsi_Host *shost,
900 struct list_head *work_q,
901 struct list_head *done_q)
903 struct list_head *lh, *lh_sf;
904 struct scsi_cmnd *scmd, *stu_scmd;
905 struct scsi_device *sdev;
907 shost_for_each_device(sdev, shost) {
909 list_for_each_entry(scmd, work_q, eh_entry)
910 if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) &&
911 scsi_check_sense(scmd) == FAILED ) {
919 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending START_UNIT to sdev:"
920 " 0x%p\n", current->comm, sdev));
922 if (!scsi_eh_try_stu(stu_scmd)) {
923 if (!scsi_device_online(sdev) ||
924 !scsi_eh_tur(stu_scmd)) {
925 list_for_each_safe(lh, lh_sf, work_q) {
926 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
927 if (scmd->device == sdev)
928 scsi_eh_finish_cmd(scmd, done_q);
932 SCSI_LOG_ERROR_RECOVERY(3,
933 printk("%s: START_UNIT failed to sdev:"
934 " 0x%p\n", current->comm, sdev));
938 return list_empty(work_q);
943 * scsi_eh_bus_device_reset - send bdr if needed
944 * @shost: scsi host being recovered.
945 * @eh_done_q: list_head for processed commands.
948 * Try a bus device reset. still, look to see whether we have multiple
949 * devices that are jammed or not - if we have multiple devices, it
950 * makes no sense to try bus_device_reset - we really would need to try
951 * a bus_reset instead.
953 static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
954 struct list_head *work_q,
955 struct list_head *done_q)
957 struct list_head *lh, *lh_sf;
958 struct scsi_cmnd *scmd, *bdr_scmd;
959 struct scsi_device *sdev;
962 shost_for_each_device(sdev, shost) {
964 list_for_each_entry(scmd, work_q, eh_entry)
965 if (scmd->device == sdev) {
973 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending BDR sdev:"
974 " 0x%p\n", current->comm,
976 rtn = scsi_try_bus_device_reset(bdr_scmd);
977 if (rtn == SUCCESS) {
978 if (!scsi_device_online(sdev) ||
979 !scsi_eh_tur(bdr_scmd)) {
980 list_for_each_safe(lh, lh_sf,
982 scmd = list_entry(lh, struct
985 if (scmd->device == sdev)
986 scsi_eh_finish_cmd(scmd,
991 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: BDR"
999 return list_empty(work_q);
1003 * scsi_try_bus_reset - ask host to perform a bus reset
1004 * @scmd: SCSI cmd to send bus reset.
1006 static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
1008 unsigned long flags;
1011 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n",
1013 scmd->owner = SCSI_OWNER_LOWLEVEL;
1014 scmd->serial_number_at_timeout = scmd->serial_number;
1016 if (!scmd->device->host->hostt->eh_bus_reset_handler)
1019 spin_lock_irqsave(scmd->device->host->host_lock, flags);
1020 rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd);
1021 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
1023 if (rtn == SUCCESS) {
1024 if (!scmd->device->host->hostt->skip_settle_delay)
1025 scsi_sleep(BUS_RESET_SETTLE_TIME);
1026 spin_lock_irqsave(scmd->device->host->host_lock, flags);
1027 scsi_report_bus_reset(scmd->device->host, scmd->device->channel);
1028 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
1035 * scsi_try_host_reset - ask host adapter to reset itself
1036 * @scmd: SCSI cmd to send hsot reset.
1038 static int scsi_try_host_reset(struct scsi_cmnd *scmd)
1040 unsigned long flags;
1043 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n",
1045 scmd->owner = SCSI_OWNER_LOWLEVEL;
1046 scmd->serial_number_at_timeout = scmd->serial_number;
1048 if (!scmd->device->host->hostt->eh_host_reset_handler)
1051 spin_lock_irqsave(scmd->device->host->host_lock, flags);
1052 rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd);
1053 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
1055 if (rtn == SUCCESS) {
1056 if (!scmd->device->host->hostt->skip_settle_delay)
1057 scsi_sleep(HOST_RESET_SETTLE_TIME);
1058 spin_lock_irqsave(scmd->device->host->host_lock, flags);
1059 scsi_report_bus_reset(scmd->device->host, scmd->device->channel);
1060 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
1067 * scsi_eh_bus_reset - send a bus reset
1068 * @shost: scsi host being recovered.
1069 * @eh_done_q: list_head for processed commands.
1071 static int scsi_eh_bus_reset(struct Scsi_Host *shost,
1072 struct list_head *work_q,
1073 struct list_head *done_q)
1075 struct list_head *lh, *lh_sf;
1076 struct scsi_cmnd *scmd;
1077 struct scsi_cmnd *chan_scmd;
1078 unsigned int channel;
1082 * we really want to loop over the various channels, and do this on
1083 * a channel by channel basis. we should also check to see if any
1084 * of the failed commands are on soft_reset devices, and if so, skip
1088 for (channel = 0; channel <= shost->max_channel; channel++) {
1090 list_for_each_entry(scmd, work_q, eh_entry) {
1091 if (channel == scmd->device->channel) {
1095 * FIXME add back in some support for
1096 * soft_reset devices.
1103 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending BRST chan:"
1104 " %d\n", current->comm,
1106 rtn = scsi_try_bus_reset(chan_scmd);
1107 if (rtn == SUCCESS) {
1108 list_for_each_safe(lh, lh_sf, work_q) {
1109 scmd = list_entry(lh, struct scsi_cmnd,
1111 if (channel == scmd->device->channel)
1112 if (!scsi_device_online(scmd->device) ||
1114 scsi_eh_finish_cmd(scmd,
1118 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: BRST"
1119 " failed chan: %d\n",
1124 return list_empty(work_q);
1128 * scsi_eh_host_reset - send a host reset
1129 * @work_q: list_head for processed commands.
1130 * @done_q: list_head for processed commands.
1132 static int scsi_eh_host_reset(struct list_head *work_q,
1133 struct list_head *done_q)
1136 struct list_head *lh, *lh_sf;
1137 struct scsi_cmnd *scmd;
1139 if (!list_empty(work_q)) {
1140 scmd = list_entry(work_q->next,
1141 struct scsi_cmnd, eh_entry);
1143 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending HRST\n"
1146 rtn = scsi_try_host_reset(scmd);
1147 if (rtn == SUCCESS) {
1148 list_for_each_safe(lh, lh_sf, work_q) {
1149 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
1150 if (!scsi_device_online(scmd->device) ||
1151 (!scsi_eh_try_stu(scmd) && !scsi_eh_tur(scmd)) ||
1153 scsi_eh_finish_cmd(scmd, done_q);
1156 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: HRST"
1161 return list_empty(work_q);
1165 * scsi_eh_offline_sdevs - offline scsi devices that fail to recover
1166 * @work_q: list_head for processed commands.
1167 * @done_q: list_head for processed commands.
1170 static void scsi_eh_offline_sdevs(struct list_head *work_q,
1171 struct list_head *done_q)
1173 struct list_head *lh, *lh_sf;
1174 struct scsi_cmnd *scmd;
1176 list_for_each_safe(lh, lh_sf, work_q) {
1177 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
1178 printk(KERN_INFO "scsi: Device offlined - not"
1179 " ready after error recovery: host"
1180 " %d channel %d id %d lun %d\n",
1181 scmd->device->host->host_no,
1182 scmd->device->channel,
1185 scsi_device_set_state(scmd->device, SDEV_OFFLINE);
1186 if (scsi_eh_eflags_chk(scmd, SCSI_EH_CANCEL_CMD)) {
1188 * FIXME: Handle lost cmds.
1191 scsi_eh_finish_cmd(scmd, done_q);
1197 * scsi_sleep_done - timer function for scsi_sleep
1198 * @sem: semphore to signal
1201 static void scsi_sleep_done(unsigned long data)
1203 struct semaphore *sem = (struct semaphore *)data;
1210 * scsi_sleep - sleep for specified timeout
1211 * @timeout: timeout value
1214 void scsi_sleep(int timeout)
1216 DECLARE_MUTEX_LOCKED(sem);
1217 struct timer_list timer;
1220 timer.data = (unsigned long)&sem;
1221 timer.expires = jiffies + timeout;
1222 timer.function = (void (*)(unsigned long))scsi_sleep_done;
1224 SCSI_LOG_ERROR_RECOVERY(5, printk("sleeping for timer tics %d\n",
1234 * scsi_decide_disposition - Disposition a cmd on return from LLD.
1235 * @scmd: SCSI cmd to examine.
1238 * This is *only* called when we are examining the status after sending
1239 * out the actual data command. any commands that are queued for error
1240 * recovery (e.g. test_unit_ready) do *not* come through here.
1242 * When this routine returns failed, it means the error handler thread
1243 * is woken. In cases where the error code indicates an error that
1244 * doesn't require the error handler read (i.e. we don't need to
1245 * abort/reset), this function should return SUCCESS.
1247 int scsi_decide_disposition(struct scsi_cmnd *scmd)
1252 * if the device is offline, then we clearly just pass the result back
1253 * up to the top level.
1255 if (!scsi_device_online(scmd->device)) {
1256 SCSI_LOG_ERROR_RECOVERY(5, printk("%s: device offline - report"
1263 * first check the host byte, to see if there is anything in there
1264 * that would indicate what we need to do.
1266 switch (host_byte(scmd->result)) {
1267 case DID_PASSTHROUGH:
1269 * no matter what, pass this through to the upper layer.
1270 * nuke this special code so that it looks like we are saying
1273 scmd->result &= 0xff00ffff;
1277 * looks good. drop through, and check the next byte.
1280 case DID_NO_CONNECT:
1281 case DID_BAD_TARGET:
1284 * note - this means that we just report the status back
1285 * to the top level driver, not that we actually think
1286 * that it indicates SUCCESS.
1290 * when the low level driver returns did_soft_error,
1291 * it is responsible for keeping an internal retry counter
1292 * in order to avoid endless loops (db)
1294 * actually this is a bug in this function here. we should
1295 * be mindful of the maximum number of retries specified
1296 * and not get stuck in a loop.
1298 case DID_SOFT_ERROR:
1304 if (msg_byte(scmd->result) == COMMAND_COMPLETE &&
1305 status_byte(scmd->result) == RESERVATION_CONFLICT)
1307 * execute reservation conflict processing code
1318 * when we scan the bus, we get timeout messages for
1319 * these commands if there is no device available.
1320 * other hosts report did_no_connect for the same thing.
1322 if ((scmd->cmnd[0] == TEST_UNIT_READY ||
1323 scmd->cmnd[0] == INQUIRY)) {
1335 * next, check the message byte.
1337 if (msg_byte(scmd->result) != COMMAND_COMPLETE)
1341 * check the status byte to see if this indicates anything special.
1343 switch (status_byte(scmd->result)) {
1346 * the case of trying to send too many commands to a
1347 * tagged queueing device.
1351 * device can't talk to us at the moment. Should only
1352 * occur (SAM-3) when the task queue is empty, so will cause
1353 * the empty queue handling to trigger a stall in the
1356 return ADD_TO_MLQUEUE;
1358 case COMMAND_TERMINATED:
1360 case CHECK_CONDITION:
1361 rtn = scsi_check_sense(scmd);
1362 if (rtn == NEEDS_RETRY)
1364 /* if rtn == FAILED, we have no sense information;
1365 * returning FAILED will wake the error handler thread
1366 * to collect the sense and redo the decide
1369 case CONDITION_GOOD:
1370 case INTERMEDIATE_GOOD:
1371 case INTERMEDIATE_C_GOOD:
1373 * who knows? FIXME(eric)
1377 case RESERVATION_CONFLICT:
1378 printk("scsi%d (%d,%d,%d) : reservation conflict\n",
1379 scmd->device->host->host_no, scmd->device->channel,
1380 scmd->device->id, scmd->device->lun);
1381 return SUCCESS; /* causes immediate i/o error */
1389 /* we requeue for retry because the error was retryable, and
1390 * the request was not marked fast fail. Note that above,
1391 * even if the request is marked fast fail, we still requeue
1392 * for queue congestion conditions (QUEUE_FULL or BUSY) */
1393 if ((++scmd->retries) < scmd->allowed
1394 && !blk_noretry_request(scmd->request)) {
1398 * no more retries - report this one back to upper level.
1405 * scsi_eh_lock_done - done function for eh door lock request
1406 * @scmd: SCSI command block for the door lock request
1409 * We completed the asynchronous door lock request, and it has either
1410 * locked the door or failed. We must free the command structures
1411 * associated with this request.
1413 static void scsi_eh_lock_done(struct scsi_cmnd *scmd)
1415 struct scsi_request *sreq = scmd->sc_request;
1417 scsi_release_request(sreq);
1422 * scsi_eh_lock_door - Prevent medium removal for the specified device
1423 * @sdev: SCSI device to prevent medium removal
1426 * We must be called from process context; scsi_allocate_request()
1430 * We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the
1431 * head of the devices request queue, and continue.
1434 * scsi_allocate_request() may sleep waiting for existing requests to
1435 * be processed. However, since we haven't kicked off any request
1436 * processing for this host, this may deadlock.
1438 * If scsi_allocate_request() fails for what ever reason, we
1439 * completely forget to lock the door.
1441 static void scsi_eh_lock_door(struct scsi_device *sdev)
1443 struct scsi_request *sreq = scsi_allocate_request(sdev, GFP_KERNEL);
1445 if (unlikely(!sreq)) {
1446 printk(KERN_ERR "%s: request allocate failed,"
1447 "prevent media removal cmd not sent\n", __FUNCTION__);
1451 sreq->sr_cmnd[0] = ALLOW_MEDIUM_REMOVAL;
1452 sreq->sr_cmnd[1] = 0;
1453 sreq->sr_cmnd[2] = 0;
1454 sreq->sr_cmnd[3] = 0;
1455 sreq->sr_cmnd[4] = SCSI_REMOVAL_PREVENT;
1456 sreq->sr_cmnd[5] = 0;
1457 sreq->sr_data_direction = DMA_NONE;
1458 sreq->sr_bufflen = 0;
1459 sreq->sr_buffer = NULL;
1460 sreq->sr_allowed = 5;
1461 sreq->sr_done = scsi_eh_lock_done;
1462 sreq->sr_timeout_per_command = 10 * HZ;
1463 sreq->sr_cmd_len = COMMAND_SIZE(sreq->sr_cmnd[0]);
1465 scsi_insert_special_req(sreq, 1);
1470 * scsi_restart_operations - restart io operations to the specified host.
1471 * @shost: Host we are restarting.
1474 * When we entered the error handler, we blocked all further i/o to
1475 * this device. we need to 'reverse' this process.
1477 static void scsi_restart_operations(struct Scsi_Host *shost)
1479 struct scsi_device *sdev;
1482 * If the door was locked, we need to insert a door lock request
1483 * onto the head of the SCSI request queue for the device. There
1484 * is no point trying to lock the door of an off-line device.
1486 shost_for_each_device(sdev, shost) {
1487 if (scsi_device_online(sdev) && sdev->locked)
1488 scsi_eh_lock_door(sdev);
1492 * next free up anything directly waiting upon the host. this
1493 * will be requests for character device operations, and also for
1494 * ioctls to queued block devices.
1496 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: waking up host to restart\n",
1499 clear_bit(SHOST_RECOVERY, &shost->shost_state);
1501 wake_up(&shost->host_wait);
1504 * finally we need to re-initiate requests that may be pending. we will
1505 * have had everything blocked while error handling is taking place, and
1506 * now that error recovery is done, we will need to ensure that these
1507 * requests are started.
1509 scsi_run_host_queues(shost);
1513 * scsi_eh_ready_devs - check device ready state and recover if not.
1514 * @shost: host to be recovered.
1515 * @eh_done_q: list_head for processed commands.
1518 static void scsi_eh_ready_devs(struct Scsi_Host *shost,
1519 struct list_head *work_q,
1520 struct list_head *done_q)
1522 if (!scsi_eh_stu(shost, work_q, done_q))
1523 if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
1524 if (!scsi_eh_bus_reset(shost, work_q, done_q))
1525 if (!scsi_eh_host_reset(work_q, done_q))
1526 scsi_eh_offline_sdevs(work_q, done_q);
1530 * scsi_eh_flush_done_q - finish processed commands or retry them.
1531 * @done_q: list_head of processed commands.
1534 static void scsi_eh_flush_done_q(struct list_head *done_q)
1536 struct list_head *lh, *lh_sf;
1537 struct scsi_cmnd *scmd;
1539 list_for_each_safe(lh, lh_sf, done_q) {
1540 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
1542 if (scsi_device_online(scmd->device) &&
1543 !blk_noretry_request(scmd->request) &&
1544 (++scmd->retries < scmd->allowed)) {
1545 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: flush"
1549 scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
1552 scmd->result |= (DRIVER_TIMEOUT << 24);
1553 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: flush finish"
1555 current->comm, scmd));
1556 scsi_finish_command(scmd);
1562 * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
1563 * @shost: Host to unjam.
1566 * When we come in here, we *know* that all commands on the bus have
1567 * either completed, failed or timed out. we also know that no further
1568 * commands are being sent to the host, so things are relatively quiet
1569 * and we have freedom to fiddle with things as we wish.
1571 * This is only the *default* implementation. it is possible for
1572 * individual drivers to supply their own version of this function, and
1573 * if the maintainer wishes to do this, it is strongly suggested that
1574 * this function be taken as a template and modified. this function
1575 * was designed to correctly handle problems for about 95% of the
1576 * different cases out there, and it should always provide at least a
1577 * reasonable amount of error recovery.
1579 * Any command marked 'failed' or 'timeout' must eventually have
1580 * scsi_finish_cmd() called for it. we do all of the retry stuff
1581 * here, so when we restart the host after we return it should have an
1584 static void scsi_unjam_host(struct Scsi_Host *shost)
1586 unsigned long flags;
1587 LIST_HEAD(eh_work_q);
1588 LIST_HEAD(eh_done_q);
1590 spin_lock_irqsave(shost->host_lock, flags);
1591 list_splice_init(&shost->eh_cmd_q, &eh_work_q);
1592 spin_unlock_irqrestore(shost->host_lock, flags);
1594 SCSI_LOG_ERROR_RECOVERY(1, scsi_eh_prt_fail_stats(shost, &eh_work_q));
1596 if (!scsi_eh_get_sense(&eh_work_q, &eh_done_q))
1597 if (!scsi_eh_abort_cmds(&eh_work_q, &eh_done_q))
1598 scsi_eh_ready_devs(shost, &eh_work_q, &eh_done_q);
1600 scsi_eh_flush_done_q(&eh_done_q);
1604 * scsi_error_handler - Handle errors/timeouts of SCSI cmds.
1605 * @data: Host for which we are running.
1608 * This is always run in the context of a kernel thread. The idea is
1609 * that we start this thing up when the kernel starts up (one per host
1610 * that we detect), and it immediately goes to sleep and waits for some
1611 * event (i.e. failure). When this takes place, we have the job of
1612 * trying to unjam the bus and restarting things.
1614 int scsi_error_handler(void *data)
1616 struct Scsi_Host *shost = (struct Scsi_Host *) data;
1618 DECLARE_MUTEX_LOCKED(sem);
1626 daemonize("scsi_eh_%d", shost->host_no);
1628 current->flags |= PF_NOFREEZE;
1630 shost->eh_wait = &sem;
1631 shost->ehandler = current;
1636 * Wake up the thread that created us.
1638 SCSI_LOG_ERROR_RECOVERY(3, printk("Wake up parent of"
1639 " scsi_eh_%d\n",shost->host_no));
1641 complete(shost->eh_notify);
1645 * If we get a signal, it means we are supposed to go
1646 * away and die. This typically happens if the user is
1647 * trying to unload a module.
1649 SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler"
1651 " sleeping\n",shost->host_no));
1654 * Note - we always use down_interruptible with the semaphore
1655 * even if the module was loaded as part of the kernel. The
1656 * reason is that down() will cause this thread to be counted
1657 * in the load average as a running process, and down
1658 * interruptible doesn't. Given that we need to allow this
1659 * thread to die if the driver was loaded as a module, using
1660 * semaphores isn't unreasonable.
1662 down_interruptible(&sem);
1666 SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler"
1667 " scsi_eh_%d waking"
1668 " up\n",shost->host_no));
1670 shost->eh_active = 1;
1673 * We have a host that is failing for some reason. Figure out
1674 * what we need to do to get it up and online again (if we can).
1675 * If we fail, we end up taking the thing offline.
1677 if (shost->hostt->eh_strategy_handler)
1678 rtn = shost->hostt->eh_strategy_handler(shost);
1680 scsi_unjam_host(shost);
1682 shost->eh_active = 0;
1685 * Note - if the above fails completely, the action is to take
1686 * individual devices offline and flush the queue of any
1687 * outstanding requests that may have been pending. When we
1688 * restart, we restart any I/O to any other devices on the bus
1689 * which are still online.
1691 scsi_restart_operations(shost);
1695 SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler scsi_eh_%d"
1696 " exiting\n",shost->host_no));
1699 * Make sure that nobody tries to wake us up again.
1701 shost->eh_wait = NULL;
1704 * Knock this down too. From this point on, the host is flying
1705 * without a pilot. If this is because the module is being unloaded,
1706 * that's fine. If the user sent a signal to this thing, we are
1707 * potentially in real danger.
1709 shost->eh_active = 0;
1710 shost->ehandler = NULL;
1713 * If anyone is waiting for us to exit (i.e. someone trying to unload
1714 * a driver), then wake up that process to let them know we are on
1715 * the way out the door.
1717 complete_and_exit(shost->eh_notify, 0);
1722 * Function: scsi_report_bus_reset()
1724 * Purpose: Utility function used by low-level drivers to report that
1725 * they have observed a bus reset on the bus being handled.
1727 * Arguments: shost - Host in question
1728 * channel - channel on which reset was observed.
1732 * Lock status: Host lock must be held.
1734 * Notes: This only needs to be called if the reset is one which
1735 * originates from an unknown location. Resets originated
1736 * by the mid-level itself don't need to call this, but there
1737 * should be no harm.
1739 * The main purpose of this is to make sure that a CHECK_CONDITION
1740 * is properly treated.
1742 void scsi_report_bus_reset(struct Scsi_Host *shost, int channel)
1744 struct scsi_device *sdev;
1746 __shost_for_each_device(sdev, shost) {
1747 if (channel == sdev->channel) {
1748 sdev->was_reset = 1;
1749 sdev->expecting_cc_ua = 1;
1755 * Function: scsi_report_device_reset()
1757 * Purpose: Utility function used by low-level drivers to report that
1758 * they have observed a device reset on the device being handled.
1760 * Arguments: shost - Host in question
1761 * channel - channel on which reset was observed
1762 * target - target on which reset was observed
1766 * Lock status: Host lock must be held
1768 * Notes: This only needs to be called if the reset is one which
1769 * originates from an unknown location. Resets originated
1770 * by the mid-level itself don't need to call this, but there
1771 * should be no harm.
1773 * The main purpose of this is to make sure that a CHECK_CONDITION
1774 * is properly treated.
1776 void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
1778 struct scsi_device *sdev;
1780 __shost_for_each_device(sdev, shost) {
1781 if (channel == sdev->channel &&
1782 target == sdev->id) {
1783 sdev->was_reset = 1;
1784 sdev->expecting_cc_ua = 1;
1790 scsi_reset_provider_done_command(struct scsi_cmnd *scmd)
1795 * Function: scsi_reset_provider
1797 * Purpose: Send requested reset to a bus or device at any phase.
1799 * Arguments: device - device to send reset to
1800 * flag - reset type (see scsi.h)
1802 * Returns: SUCCESS/FAILURE.
1804 * Notes: This is used by the SCSI Generic driver to provide
1805 * Bus/Device reset capability.
1808 scsi_reset_provider(struct scsi_device *dev, int flag)
1810 struct scsi_cmnd *scmd = scsi_get_command(dev, GFP_KERNEL);
1814 scmd->request = &req;
1815 memset(&scmd->eh_timeout, 0, sizeof(scmd->eh_timeout));
1816 scmd->request->rq_status = RQ_SCSI_BUSY;
1817 scmd->state = SCSI_STATE_INITIALIZING;
1818 scmd->owner = SCSI_OWNER_MIDLEVEL;
1820 memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd));
1822 scmd->scsi_done = scsi_reset_provider_done_command;
1824 scmd->buffer = NULL;
1826 scmd->request_buffer = NULL;
1827 scmd->request_bufflen = 0;
1828 scmd->internal_timeout = NORMAL_TIMEOUT;
1829 scmd->abort_reason = DID_ABORT;
1833 scmd->sc_data_direction = DMA_BIDIRECTIONAL;
1834 scmd->sc_request = NULL;
1835 scmd->sc_magic = SCSI_CMND_MAGIC;
1837 init_timer(&scmd->eh_timeout);
1840 * Sometimes the command can get back into the timer chain,
1841 * so use the pid as an identifier.
1846 case SCSI_TRY_RESET_DEVICE:
1847 rtn = scsi_try_bus_device_reset(scmd);
1851 case SCSI_TRY_RESET_BUS:
1852 rtn = scsi_try_bus_reset(scmd);
1856 case SCSI_TRY_RESET_HOST:
1857 rtn = scsi_try_host_reset(scmd);
1863 scsi_delete_timer(scmd);
1864 scsi_next_command(scmd);