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"
35 #define SENSE_TIMEOUT SCSI_TIMEOUT
37 #define SENSE_TIMEOUT (10*HZ)
40 #define START_UNIT_TIMEOUT (30*HZ)
43 * These should *probably* be handled by the host itself.
44 * Since it is allowed to sleep, it probably should.
46 #define BUS_RESET_SETTLE_TIME 10*HZ
47 #define HOST_RESET_SETTLE_TIME 10*HZ
49 /* called with shost->host_lock held */
50 void scsi_eh_wakeup(struct Scsi_Host *shost)
52 if (shost->host_busy == shost->host_failed) {
54 SCSI_LOG_ERROR_RECOVERY(5,
55 printk("Waking error handler thread\n"));
60 * scsi_eh_scmd_add - add scsi cmd to error handling.
61 * @scmd: scmd to run eh on.
62 * @eh_flag: optional SCSI_EH flag.
67 int scsi_eh_scmd_add(struct scsi_cmnd *scmd, int eh_flag)
69 struct Scsi_Host *shost = scmd->device->host;
72 if (shost->eh_wait == NULL)
75 spin_lock_irqsave(shost->host_lock, flags);
77 scsi_eh_eflags_set(scmd, eh_flag);
79 * FIXME: Can we stop setting owner and state.
81 scmd->owner = SCSI_OWNER_ERROR_HANDLER;
82 scmd->state = SCSI_STATE_FAILED;
84 * Set the serial_number_at_timeout to the current
87 scmd->serial_number_at_timeout = scmd->serial_number;
88 list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
89 set_bit(SHOST_RECOVERY, &shost->shost_state);
91 scsi_eh_wakeup(shost);
92 spin_unlock_irqrestore(shost->host_lock, flags);
97 * scsi_add_timer - Start timeout timer for a single scsi command.
98 * @scmd: scsi command that is about to start running.
99 * @timeout: amount of time to allow this command to run.
100 * @complete: timeout function to call if timer isn't canceled.
103 * This should be turned into an inline function. Each scsi command
104 * has its own timer, and as it is added to the queue, we set up the
105 * timer. When the command completes, we cancel the timer.
107 void scsi_add_timer(struct scsi_cmnd *scmd, int timeout,
108 void (*complete)(struct scsi_cmnd *))
112 * If the clock was already running for this command, then
113 * first delete the timer. The timer handling code gets rather
114 * confused if we don't do this.
116 if (scmd->eh_timeout.function)
117 del_timer(&scmd->eh_timeout);
119 scmd->eh_timeout.data = (unsigned long)scmd;
120 scmd->eh_timeout.expires = jiffies + timeout;
121 scmd->eh_timeout.function = (void (*)(unsigned long)) complete;
123 SCSI_LOG_ERROR_RECOVERY(5, printk("%s: scmd: %p, time:"
124 " %d, (%p)\n", __FUNCTION__,
125 scmd, timeout, complete));
127 add_timer(&scmd->eh_timeout);
131 * scsi_delete_timer - Delete/cancel timer for a given function.
132 * @scmd: Cmd that we are canceling timer for
135 * This should be turned into an inline function.
138 * 1 if we were able to detach the timer. 0 if we blew it, and the
139 * timer function has already started to run.
141 int scsi_delete_timer(struct scsi_cmnd *scmd)
145 rtn = del_timer(&scmd->eh_timeout);
147 SCSI_LOG_ERROR_RECOVERY(5, printk("%s: scmd: %p,"
148 " rtn: %d\n", __FUNCTION__,
151 scmd->eh_timeout.data = (unsigned long)NULL;
152 scmd->eh_timeout.function = NULL;
158 * scsi_times_out - Timeout function for normal scsi commands.
159 * @scmd: Cmd that is timing out.
162 * We do not need to lock this. There is the potential for a race
163 * only in that the normal completion handling might run, but if the
164 * normal completion function determines that the timer has already
165 * fired, then it mustn't do anything.
167 void scsi_times_out(struct scsi_cmnd *scmd)
169 scsi_log_completion(scmd, TIMEOUT_ERROR);
170 if (unlikely(!scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD))) {
171 panic("Error handler thread not present at %p %p %s %d",
172 scmd, scmd->device->host, __FILE__, __LINE__);
177 * scsi_block_when_processing_errors - Prevent cmds from being queued.
178 * @sdev: Device on which we are performing recovery.
181 * We block until the host is out of error recovery, and then check to
182 * see whether the host or the device is offline.
185 * 0 when dev was taken offline by error recovery. 1 OK to proceed.
187 int scsi_block_when_processing_errors(struct scsi_device *sdev)
191 wait_event(sdev->host->host_wait, (!test_bit(SHOST_RECOVERY, &sdev->host->shost_state)));
193 online = scsi_device_online(sdev);
195 SCSI_LOG_ERROR_RECOVERY(5, printk("%s: rtn: %d\n", __FUNCTION__,
201 #ifdef CONFIG_SCSI_LOGGING
203 * scsi_eh_prt_fail_stats - Log info on failures.
204 * @shost: scsi host being recovered.
205 * @work_q: Queue of scsi cmds to process.
207 static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
208 struct list_head *work_q)
210 struct scsi_cmnd *scmd;
211 struct scsi_device *sdev;
212 int total_failures = 0;
215 int devices_failed = 0;
217 shost_for_each_device(sdev, shost) {
218 list_for_each_entry(scmd, work_q, eh_entry) {
219 if (scmd->device == sdev) {
221 if (scsi_eh_eflags_chk(scmd,
229 if (cmd_cancel || cmd_failed) {
230 SCSI_LOG_ERROR_RECOVERY(3,
231 printk("%s: %d:%d:%d:%d cmds failed: %d,"
233 __FUNCTION__, shost->host_no,
234 sdev->channel, sdev->id, sdev->lun,
235 cmd_failed, cmd_cancel));
242 SCSI_LOG_ERROR_RECOVERY(2, printk("Total of %d commands on %d"
243 " devices require eh work\n",
244 total_failures, devices_failed));
249 * scsi_check_sense - Examine scsi cmd sense
250 * @scmd: Cmd to have sense checked.
253 * SUCCESS or FAILED or NEEDS_RETRY
255 static int scsi_check_sense(struct scsi_cmnd *scmd)
257 if (!SCSI_SENSE_VALID(scmd))
260 if (scmd->sense_buffer[2] & 0xe0)
263 switch (scmd->sense_buffer[2] & 0xf) {
266 case RECOVERED_ERROR:
267 return /* soft_error */ SUCCESS;
269 case ABORTED_COMMAND:
274 * if we are expecting a cc/ua because of a bus reset that we
275 * performed, treat this just as a retry. otherwise this is
276 * information that we should pass up to the upper-level driver
277 * so that we can deal with it there.
279 if (scmd->device->expecting_cc_ua) {
280 scmd->device->expecting_cc_ua = 0;
284 * if the device is in the process of becoming ready, we
287 if ((scmd->sense_buffer[12] == 0x04) &&
288 (scmd->sense_buffer[13] == 0x01)) {
292 * if the device is not started, we need to wake
293 * the error handler to start the motor
295 if (scmd->device->allow_restart &&
296 (scmd->sense_buffer[12] == 0x04) &&
297 (scmd->sense_buffer[13] == 0x02)) {
302 /* these three are not supported */
304 case VOLUME_OVERFLOW:
311 case ILLEGAL_REQUEST:
321 * scsi_eh_completed_normally - Disposition a eh cmd on return from LLD.
322 * @scmd: SCSI cmd to examine.
325 * This is *only* called when we are examining the status of commands
326 * queued during error recovery. the main difference here is that we
327 * don't allow for the possibility of retries here, and we are a lot
328 * more restrictive about what we consider acceptable.
330 static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)
333 * first check the host byte, to see if there is anything in there
334 * that would indicate what we need to do.
336 if (host_byte(scmd->result) == DID_RESET) {
338 * rats. we are already in the error handler, so we now
339 * get to try and figure out what to do next. if the sense
340 * is valid, we have a pretty good idea of what to do.
341 * if not, we mark it as FAILED.
343 return scsi_check_sense(scmd);
345 if (host_byte(scmd->result) != DID_OK)
349 * next, check the message byte.
351 if (msg_byte(scmd->result) != COMMAND_COMPLETE)
355 * now, check the status byte to see if this indicates
358 switch (status_byte(scmd->result)) {
360 case COMMAND_TERMINATED:
362 case CHECK_CONDITION:
363 return scsi_check_sense(scmd);
365 case INTERMEDIATE_GOOD:
366 case INTERMEDIATE_C_GOOD:
368 * who knows? FIXME(eric)
373 case RESERVATION_CONFLICT:
381 * scsi_eh_times_out - timeout function for error handling.
382 * @scmd: Cmd that is timing out.
385 * During error handling, the kernel thread will be sleeping waiting
386 * for some action to complete on the device. our only job is to
387 * record that it timed out, and to wake up the thread.
389 static void scsi_eh_times_out(struct scsi_cmnd *scmd)
391 scsi_eh_eflags_set(scmd, SCSI_EH_REC_TIMEOUT);
392 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd:%p\n", __FUNCTION__,
395 if (scmd->device->host->eh_action)
396 up(scmd->device->host->eh_action);
400 * scsi_eh_done - Completion function for error handling.
401 * @scmd: Cmd that is done.
403 static void scsi_eh_done(struct scsi_cmnd *scmd)
406 * if the timeout handler is already running, then just set the
407 * flag which says we finished late, and return. we have no
408 * way of stopping the timeout handler from running, so we must
409 * always defer to it.
411 if (del_timer(&scmd->eh_timeout)) {
412 scmd->request->rq_status = RQ_SCSI_DONE;
413 scmd->owner = SCSI_OWNER_ERROR_HANDLER;
415 SCSI_LOG_ERROR_RECOVERY(3, printk("%s scmd: %p result: %x\n",
416 __FUNCTION__, scmd, scmd->result));
418 if (scmd->device->host->eh_action)
419 up(scmd->device->host->eh_action);
424 * scsi_send_eh_cmnd - send a cmd to a device as part of error recovery.
425 * @scmd: SCSI Cmd to send.
426 * @timeout: Timeout for cmd.
429 * The initialization of the structures is quite a bit different in
430 * this case, and furthermore, there is a different completion handler
431 * vs scsi_dispatch_cmd.
433 * SUCCESS or FAILED or NEEDS_RETRY
435 static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout)
437 struct Scsi_Host *host = scmd->device->host;
438 DECLARE_MUTEX_LOCKED(sem);
443 * we will use a queued command if possible, otherwise we will
444 * emulate the queuing and calling of completion function ourselves.
446 scmd->owner = SCSI_OWNER_LOWLEVEL;
448 if (scmd->device->scsi_level <= SCSI_2)
449 scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) |
450 (scmd->device->lun << 5 & 0xe0);
452 scsi_add_timer(scmd, timeout, scsi_eh_times_out);
455 * set up the semaphore so we wait for the command to complete.
457 scmd->device->host->eh_action = &sem;
458 scmd->request->rq_status = RQ_SCSI_BUSY;
460 spin_lock_irqsave(scmd->device->host->host_lock, flags);
462 host->hostt->queuecommand(scmd, scsi_eh_done);
463 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
466 scsi_log_completion(scmd, SUCCESS);
468 scmd->device->host->eh_action = NULL;
471 * see if timeout. if so, tell the host to forget about it.
472 * in other words, we don't want a callback any more.
474 if (scsi_eh_eflags_chk(scmd, SCSI_EH_REC_TIMEOUT)) {
475 scsi_eh_eflags_clr(scmd, SCSI_EH_REC_TIMEOUT);
476 scmd->owner = SCSI_OWNER_LOWLEVEL;
479 * as far as the low level driver is
480 * concerned, this command is still active, so
481 * we must give the low level driver a chance
484 * FIXME(eric) - we are not tracking whether we could
485 * abort a timed out command or not. not sure how
486 * we should treat them differently anyways.
488 spin_lock_irqsave(scmd->device->host->host_lock, flags);
489 if (scmd->device->host->hostt->eh_abort_handler)
490 scmd->device->host->hostt->eh_abort_handler(scmd);
491 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
493 scmd->request->rq_status = RQ_SCSI_DONE;
494 scmd->owner = SCSI_OWNER_ERROR_HANDLER;
499 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd: %p, rtn:%x\n",
500 __FUNCTION__, scmd, rtn));
503 * now examine the actual status codes to see whether the command
504 * actually did complete normally.
506 if (rtn == SUCCESS) {
507 rtn = scsi_eh_completed_normally(scmd);
508 SCSI_LOG_ERROR_RECOVERY(3,
509 printk("%s: scsi_eh_completed_normally %x\n",
526 * scsi_request_sense - Request sense data from a particular target.
527 * @scmd: SCSI cmd for request sense.
530 * Some hosts automatically obtain this information, others require
531 * that we obtain it on our own. This function will *not* return until
532 * the command either times out, or it completes.
534 static int scsi_request_sense(struct scsi_cmnd *scmd)
536 static unsigned char generic_sense[6] =
537 {REQUEST_SENSE, 0, 0, 0, 252, 0};
538 unsigned char *scsi_result;
542 memcpy(scmd->cmnd, generic_sense, sizeof(generic_sense));
544 scsi_result = kmalloc(252, GFP_ATOMIC | (scmd->device->host->hostt->unchecked_isa_dma) ? __GFP_DMA : 0);
547 if (unlikely(!scsi_result)) {
548 printk(KERN_ERR "%s: cannot allocate scsi_result.\n",
554 * zero the sense buffer. some host adapters automatically always
555 * request sense, so it is not a good idea that
556 * scmd->request_buffer and scmd->sense_buffer point to the same
557 * address (db). 0 is not a valid sense code.
559 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
560 memset(scsi_result, 0, 252);
562 saved_result = scmd->result;
563 scmd->request_buffer = scsi_result;
564 scmd->request_bufflen = 252;
566 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
567 scmd->sc_data_direction = DMA_FROM_DEVICE;
570 rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
572 /* last chance to have valid sense data */
573 if(!SCSI_SENSE_VALID(scmd)) {
574 memcpy(scmd->sense_buffer, scmd->request_buffer,
575 sizeof(scmd->sense_buffer));
581 * when we eventually call scsi_finish, we really wish to complete
582 * the original request, so let's restore the original data. (db)
584 scsi_setup_cmd_retry(scmd);
585 scmd->result = saved_result;
590 * scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
591 * @scmd: Original SCSI cmd that eh has finished.
592 * @done_q: Queue for processed commands.
595 * We don't want to use the normal command completion while we are are
596 * still handling errors - it may cause other commands to be queued,
597 * and that would disturb what we are doing. thus we really want to
598 * keep a list of pending commands for final completion, and once we
599 * are ready to leave error handling we handle completion for real.
601 static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
602 struct list_head *done_q)
604 scmd->device->host->host_failed--;
605 scmd->state = SCSI_STATE_BHQUEUE;
607 scsi_eh_eflags_clr_all(scmd);
610 * set this back so that the upper level can correctly free up
613 scsi_setup_cmd_retry(scmd);
614 list_move_tail(&scmd->eh_entry, done_q);
618 * scsi_eh_get_sense - Get device sense data.
619 * @work_q: Queue of commands to process.
620 * @done_q: Queue of proccessed commands..
623 * See if we need to request sense information. if so, then get it
624 * now, so we have a better idea of what to do.
627 * This has the unfortunate side effect that if a shost adapter does
628 * not automatically request sense information, that we end up shutting
629 * it down before we request it. All shosts should be doing this
630 * anyways, so for now all I have to say is tough noogies if you end up
631 * in here. On second thought, this is probably a good idea. We
632 * *really* want to give authors an incentive to automatically request
635 * In 2.5 this capability will be going away.
639 static int scsi_eh_get_sense(struct list_head *work_q,
640 struct list_head *done_q)
642 struct list_head *lh, *lh_sf;
643 struct scsi_cmnd *scmd;
646 list_for_each_safe(lh, lh_sf, work_q) {
647 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
648 if (scsi_eh_eflags_chk(scmd, SCSI_EH_CANCEL_CMD) ||
649 SCSI_SENSE_VALID(scmd))
652 SCSI_LOG_ERROR_RECOVERY(2, printk("%s: requesting sense"
656 rtn = scsi_request_sense(scmd);
660 SCSI_LOG_ERROR_RECOVERY(3, printk("sense requested for %p"
661 " result %x\n", scmd,
663 SCSI_LOG_ERROR_RECOVERY(3, print_sense("bh", scmd));
665 rtn = scsi_decide_disposition(scmd);
668 * if the result was normal, then just pass it along to the
672 /* we don't want this command reissued, just
673 * finished with the sense data, so set
674 * retries to the max allowed to ensure it
675 * won't get reissued */
676 scmd->retries = scmd->allowed;
677 else if (rtn != NEEDS_RETRY)
680 scsi_eh_finish_cmd(scmd, done_q);
683 return list_empty(work_q);
687 * scsi_try_to_abort_cmd - Ask host to abort a running command.
688 * @scmd: SCSI cmd to abort from Lower Level.
691 * This function will not return until the user's completion function
692 * has been called. there is no timeout on this operation. if the
693 * author of the low-level driver wishes this operation to be timed,
694 * they can provide this facility themselves. helper functions in
695 * scsi_error.c can be supplied to make this easier to do.
697 static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
702 if (!scmd->device->host->hostt->eh_abort_handler)
706 * scsi_done was called just after the command timed out and before
707 * we had a chance to process it. (db)
709 if (scmd->serial_number == 0)
712 scmd->owner = SCSI_OWNER_LOWLEVEL;
714 spin_lock_irqsave(scmd->device->host->host_lock, flags);
715 rtn = scmd->device->host->hostt->eh_abort_handler(scmd);
716 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
722 * scsi_eh_tur - Send TUR to device.
723 * @scmd: Scsi cmd to send TUR
726 * 0 - Device is ready. 1 - Device NOT ready.
728 static int scsi_eh_tur(struct scsi_cmnd *scmd)
730 static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0};
731 int retry_cnt = 1, rtn;
734 memcpy(scmd->cmnd, tur_command, sizeof(tur_command));
737 * zero the sense buffer. the scsi spec mandates that any
738 * untransferred sense data should be interpreted as being zero.
740 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
742 scmd->request_buffer = NULL;
743 scmd->request_bufflen = 0;
745 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
747 scmd->sc_data_direction = DMA_NONE;
749 rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
752 * when we eventually call scsi_finish, we really wish to complete
753 * the original request, so let's restore the original data. (db)
755 scsi_setup_cmd_retry(scmd);
758 * hey, we are done. let's look to see what happened.
760 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
761 __FUNCTION__, scmd, rtn));
764 else if (rtn == NEEDS_RETRY)
771 * scsi_eh_abort_cmds - abort canceled commands.
772 * @shost: scsi host being recovered.
773 * @eh_done_q: list_head for processed commands.
776 * Try and see whether or not it makes sense to try and abort the
777 * running command. this only works out to be the case if we have one
778 * command that has timed out. if the command simply failed, it makes
779 * no sense to try and abort the command, since as far as the shost
780 * adapter is concerned, it isn't running.
782 static int scsi_eh_abort_cmds(struct list_head *work_q,
783 struct list_head *done_q)
785 struct list_head *lh, *lh_sf;
786 struct scsi_cmnd *scmd;
789 list_for_each_safe(lh, lh_sf, work_q) {
790 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
791 if (!scsi_eh_eflags_chk(scmd, SCSI_EH_CANCEL_CMD))
793 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:"
794 "0x%p\n", current->comm,
796 rtn = scsi_try_to_abort_cmd(scmd);
797 if (rtn == SUCCESS) {
798 scsi_eh_eflags_clr(scmd, SCSI_EH_CANCEL_CMD);
799 if (!scsi_device_online(scmd->device) ||
800 !scsi_eh_tur(scmd)) {
801 scsi_eh_finish_cmd(scmd, done_q);
805 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting"
812 return list_empty(work_q);
816 * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
817 * @scmd: SCSI cmd used to send BDR
820 * There is no timeout for this operation. if this operation is
821 * unreliable for a given host, then the host itself needs to put a
822 * timer on it, and set the host back to a consistent state prior to
825 static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
830 if (!scmd->device->host->hostt->eh_device_reset_handler)
833 scmd->owner = SCSI_OWNER_LOWLEVEL;
835 spin_lock_irqsave(scmd->device->host->host_lock, flags);
836 rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd);
837 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
839 if (rtn == SUCCESS) {
840 scmd->device->was_reset = 1;
841 scmd->device->expecting_cc_ua = 1;
848 * scsi_eh_try_stu - Send START_UNIT to device.
849 * @scmd: Scsi cmd to send START_UNIT
852 * 0 - Device is ready. 1 - Device NOT ready.
854 static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
856 static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0};
859 if (!scmd->device->allow_restart)
862 memcpy(scmd->cmnd, stu_command, sizeof(stu_command));
865 * zero the sense buffer. the scsi spec mandates that any
866 * untransferred sense data should be interpreted as being zero.
868 memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
870 scmd->request_buffer = NULL;
871 scmd->request_bufflen = 0;
873 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
875 scmd->sc_data_direction = DMA_NONE;
877 rtn = scsi_send_eh_cmnd(scmd, START_UNIT_TIMEOUT);
880 * when we eventually call scsi_finish, we really wish to complete
881 * the original request, so let's restore the original data. (db)
883 scsi_setup_cmd_retry(scmd);
886 * hey, we are done. let's look to see what happened.
888 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
889 __FUNCTION__, scmd, rtn));
896 * scsi_eh_stu - send START_UNIT if needed
897 * @shost: scsi host being recovered.
898 * @eh_done_q: list_head for processed commands.
901 * If commands are failing due to not ready, initializing command required,
902 * try revalidating the device, which will end up sending a start unit.
904 static int scsi_eh_stu(struct Scsi_Host *shost,
905 struct list_head *work_q,
906 struct list_head *done_q)
908 struct list_head *lh, *lh_sf;
909 struct scsi_cmnd *scmd, *stu_scmd;
910 struct scsi_device *sdev;
912 shost_for_each_device(sdev, shost) {
914 list_for_each_entry(scmd, work_q, eh_entry)
915 if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) &&
916 scsi_check_sense(scmd) == FAILED ) {
924 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending START_UNIT to sdev:"
925 " 0x%p\n", current->comm, sdev));
927 if (!scsi_eh_try_stu(stu_scmd)) {
928 if (!scsi_device_online(sdev) ||
929 !scsi_eh_tur(stu_scmd)) {
930 list_for_each_safe(lh, lh_sf, work_q) {
931 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
932 if (scmd->device == sdev)
933 scsi_eh_finish_cmd(scmd, done_q);
937 SCSI_LOG_ERROR_RECOVERY(3,
938 printk("%s: START_UNIT failed to sdev:"
939 " 0x%p\n", current->comm, sdev));
943 return list_empty(work_q);
948 * scsi_eh_bus_device_reset - send bdr if needed
949 * @shost: scsi host being recovered.
950 * @eh_done_q: list_head for processed commands.
953 * Try a bus device reset. still, look to see whether we have multiple
954 * devices that are jammed or not - if we have multiple devices, it
955 * makes no sense to try bus_device_reset - we really would need to try
956 * a bus_reset instead.
958 static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
959 struct list_head *work_q,
960 struct list_head *done_q)
962 struct list_head *lh, *lh_sf;
963 struct scsi_cmnd *scmd, *bdr_scmd;
964 struct scsi_device *sdev;
967 shost_for_each_device(sdev, shost) {
969 list_for_each_entry(scmd, work_q, eh_entry)
970 if (scmd->device == sdev) {
978 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending BDR sdev:"
979 " 0x%p\n", current->comm,
981 rtn = scsi_try_bus_device_reset(bdr_scmd);
982 if (rtn == SUCCESS) {
983 if (!scsi_device_online(sdev) ||
984 !scsi_eh_tur(bdr_scmd)) {
985 list_for_each_safe(lh, lh_sf,
987 scmd = list_entry(lh, struct
990 if (scmd->device == sdev)
991 scsi_eh_finish_cmd(scmd,
996 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: BDR"
1004 return list_empty(work_q);
1008 * scsi_try_bus_reset - ask host to perform a bus reset
1009 * @scmd: SCSI cmd to send bus reset.
1011 static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
1013 unsigned long flags;
1016 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n",
1018 scmd->owner = SCSI_OWNER_LOWLEVEL;
1019 scmd->serial_number_at_timeout = scmd->serial_number;
1021 if (!scmd->device->host->hostt->eh_bus_reset_handler)
1024 spin_lock_irqsave(scmd->device->host->host_lock, flags);
1025 rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd);
1026 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
1028 if (rtn == SUCCESS) {
1029 scsi_sleep(BUS_RESET_SETTLE_TIME);
1030 spin_lock_irqsave(scmd->device->host->host_lock, flags);
1031 scsi_report_bus_reset(scmd->device->host, scmd->device->channel);
1032 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
1039 * scsi_try_host_reset - ask host adapter to reset itself
1040 * @scmd: SCSI cmd to send hsot reset.
1042 static int scsi_try_host_reset(struct scsi_cmnd *scmd)
1044 unsigned long flags;
1047 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n",
1049 scmd->owner = SCSI_OWNER_LOWLEVEL;
1050 scmd->serial_number_at_timeout = scmd->serial_number;
1052 if (!scmd->device->host->hostt->eh_host_reset_handler)
1055 spin_lock_irqsave(scmd->device->host->host_lock, flags);
1056 rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd);
1057 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
1059 if (rtn == SUCCESS) {
1060 scsi_sleep(HOST_RESET_SETTLE_TIME);
1061 spin_lock_irqsave(scmd->device->host->host_lock, flags);
1062 scsi_report_bus_reset(scmd->device->host, scmd->device->channel);
1063 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
1070 * scsi_eh_bus_reset - send a bus reset
1071 * @shost: scsi host being recovered.
1072 * @eh_done_q: list_head for processed commands.
1074 static int scsi_eh_bus_reset(struct Scsi_Host *shost,
1075 struct list_head *work_q,
1076 struct list_head *done_q)
1078 struct list_head *lh, *lh_sf;
1079 struct scsi_cmnd *scmd;
1080 struct scsi_cmnd *chan_scmd;
1081 unsigned int channel;
1085 * we really want to loop over the various channels, and do this on
1086 * a channel by channel basis. we should also check to see if any
1087 * of the failed commands are on soft_reset devices, and if so, skip
1091 for (channel = 0; channel <= shost->max_channel; channel++) {
1093 list_for_each_entry(scmd, work_q, eh_entry) {
1094 if (channel == scmd->device->channel) {
1098 * FIXME add back in some support for
1099 * soft_reset devices.
1106 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending BRST chan:"
1107 " %d\n", current->comm,
1109 rtn = scsi_try_bus_reset(chan_scmd);
1110 if (rtn == SUCCESS) {
1111 list_for_each_safe(lh, lh_sf, work_q) {
1112 scmd = list_entry(lh, struct scsi_cmnd,
1114 if (channel == scmd->device->channel)
1115 if (!scsi_device_online(scmd->device) ||
1117 scsi_eh_finish_cmd(scmd,
1121 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: BRST"
1122 " failed chan: %d\n",
1127 return list_empty(work_q);
1131 * scsi_eh_host_reset - send a host reset
1132 * @work_q: list_head for processed commands.
1133 * @done_q: list_head for processed commands.
1135 static int scsi_eh_host_reset(struct list_head *work_q,
1136 struct list_head *done_q)
1139 struct list_head *lh, *lh_sf;
1140 struct scsi_cmnd *scmd;
1142 if (!list_empty(work_q)) {
1143 scmd = list_entry(work_q->next,
1144 struct scsi_cmnd, eh_entry);
1146 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending HRST\n"
1149 rtn = scsi_try_host_reset(scmd);
1150 if (rtn == SUCCESS) {
1151 list_for_each_safe(lh, lh_sf, work_q) {
1152 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
1153 if (!scsi_device_online(scmd->device) ||
1154 (!scsi_eh_try_stu(scmd) && !scsi_eh_tur(scmd)) ||
1156 scsi_eh_finish_cmd(scmd, done_q);
1159 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: HRST"
1164 return list_empty(work_q);
1168 * scsi_eh_offline_sdevs - offline scsi devices that fail to recover
1169 * @work_q: list_head for processed commands.
1170 * @done_q: list_head for processed commands.
1173 static void scsi_eh_offline_sdevs(struct list_head *work_q,
1174 struct list_head *done_q)
1176 struct list_head *lh, *lh_sf;
1177 struct scsi_cmnd *scmd;
1179 list_for_each_safe(lh, lh_sf, work_q) {
1180 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
1181 printk(KERN_INFO "scsi: Device offlined - not"
1182 " ready after error recovery: host"
1183 " %d channel %d id %d lun %d\n",
1184 scmd->device->host->host_no,
1185 scmd->device->channel,
1188 scsi_device_set_state(scmd->device, SDEV_OFFLINE);
1189 if (scsi_eh_eflags_chk(scmd, SCSI_EH_CANCEL_CMD)) {
1191 * FIXME: Handle lost cmds.
1194 scsi_eh_finish_cmd(scmd, done_q);
1200 * scsi_sleep_done - timer function for scsi_sleep
1201 * @sem: semphore to signal
1204 static void scsi_sleep_done(unsigned long data)
1206 struct semaphore *sem = (struct semaphore *)data;
1213 * scsi_sleep - sleep for specified timeout
1214 * @timeout: timeout value
1217 void scsi_sleep(int timeout)
1219 DECLARE_MUTEX_LOCKED(sem);
1220 struct timer_list timer;
1223 timer.data = (unsigned long)&sem;
1224 timer.expires = jiffies + timeout;
1225 timer.function = (void (*)(unsigned long))scsi_sleep_done;
1227 SCSI_LOG_ERROR_RECOVERY(5, printk("sleeping for timer tics %d\n",
1237 * scsi_decide_disposition - Disposition a cmd on return from LLD.
1238 * @scmd: SCSI cmd to examine.
1241 * This is *only* called when we are examining the status after sending
1242 * out the actual data command. any commands that are queued for error
1243 * recovery (e.g. test_unit_ready) do *not* come through here.
1245 * When this routine returns failed, it means the error handler thread
1246 * is woken. In cases where the error code indicates an error that
1247 * doesn't require the error handler read (i.e. we don't need to
1248 * abort/reset), this function should return SUCCESS.
1250 int scsi_decide_disposition(struct scsi_cmnd *scmd)
1255 * if the device is offline, then we clearly just pass the result back
1256 * up to the top level.
1258 if (!scsi_device_online(scmd->device)) {
1259 SCSI_LOG_ERROR_RECOVERY(5, printk("%s: device offline - report"
1266 * first check the host byte, to see if there is anything in there
1267 * that would indicate what we need to do.
1269 switch (host_byte(scmd->result)) {
1270 case DID_PASSTHROUGH:
1272 * no matter what, pass this through to the upper layer.
1273 * nuke this special code so that it looks like we are saying
1276 scmd->result &= 0xff00ffff;
1280 * looks good. drop through, and check the next byte.
1283 case DID_NO_CONNECT:
1284 case DID_BAD_TARGET:
1287 * note - this means that we just report the status back
1288 * to the top level driver, not that we actually think
1289 * that it indicates SUCCESS.
1293 * when the low level driver returns did_soft_error,
1294 * it is responsible for keeping an internal retry counter
1295 * in order to avoid endless loops (db)
1297 * actually this is a bug in this function here. we should
1298 * be mindful of the maximum number of retries specified
1299 * and not get stuck in a loop.
1301 case DID_SOFT_ERROR:
1307 if (msg_byte(scmd->result) == COMMAND_COMPLETE &&
1308 status_byte(scmd->result) == RESERVATION_CONFLICT)
1310 * execute reservation conflict processing code
1321 * when we scan the bus, we get timeout messages for
1322 * these commands if there is no device available.
1323 * other hosts report did_no_connect for the same thing.
1325 if ((scmd->cmnd[0] == TEST_UNIT_READY ||
1326 scmd->cmnd[0] == INQUIRY)) {
1338 * next, check the message byte.
1340 if (msg_byte(scmd->result) != COMMAND_COMPLETE)
1344 * check the status byte to see if this indicates anything special.
1346 switch (status_byte(scmd->result)) {
1349 * the case of trying to send too many commands to a
1350 * tagged queueing device.
1354 * device can't talk to us at the moment. Should only
1355 * occur (SAM-3) when the task queue is empty, so will cause
1356 * the empty queue handling to trigger a stall in the
1359 return ADD_TO_MLQUEUE;
1361 case COMMAND_TERMINATED:
1363 case CHECK_CONDITION:
1364 rtn = scsi_check_sense(scmd);
1365 if (rtn == NEEDS_RETRY)
1367 /* if rtn == FAILED, we have no sense information;
1368 * returning FAILED will wake the error handler thread
1369 * to collect the sense and redo the decide
1372 case CONDITION_GOOD:
1373 case INTERMEDIATE_GOOD:
1374 case INTERMEDIATE_C_GOOD:
1376 * who knows? FIXME(eric)
1380 case RESERVATION_CONFLICT:
1381 printk("scsi%d (%d,%d,%d) : reservation conflict\n",
1382 scmd->device->host->host_no, scmd->device->channel,
1383 scmd->device->id, scmd->device->lun);
1384 return SUCCESS; /* causes immediate i/o error */
1392 /* we requeue for retry because the error was retryable, and
1393 * the request was not marked fast fail. Note that above,
1394 * even if the request is marked fast fail, we still requeue
1395 * for queue congestion conditions (QUEUE_FULL or BUSY) */
1396 if ((++scmd->retries) < scmd->allowed
1397 && !blk_noretry_request(scmd->request)) {
1401 * no more retries - report this one back to upper level.
1408 * scsi_eh_lock_done - done function for eh door lock request
1409 * @scmd: SCSI command block for the door lock request
1412 * We completed the asynchronous door lock request, and it has either
1413 * locked the door or failed. We must free the command structures
1414 * associated with this request.
1416 static void scsi_eh_lock_done(struct scsi_cmnd *scmd)
1418 struct scsi_request *sreq = scmd->sc_request;
1420 scsi_release_request(sreq);
1425 * scsi_eh_lock_door - Prevent medium removal for the specified device
1426 * @sdev: SCSI device to prevent medium removal
1429 * We must be called from process context; scsi_allocate_request()
1433 * We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the
1434 * head of the devices request queue, and continue.
1437 * scsi_allocate_request() may sleep waiting for existing requests to
1438 * be processed. However, since we haven't kicked off any request
1439 * processing for this host, this may deadlock.
1441 * If scsi_allocate_request() fails for what ever reason, we
1442 * completely forget to lock the door.
1444 static void scsi_eh_lock_door(struct scsi_device *sdev)
1446 struct scsi_request *sreq = scsi_allocate_request(sdev, GFP_KERNEL);
1448 if (unlikely(!sreq)) {
1449 printk(KERN_ERR "%s: request allocate failed,"
1450 "prevent media removal cmd not sent\n", __FUNCTION__);
1454 sreq->sr_cmnd[0] = ALLOW_MEDIUM_REMOVAL;
1455 sreq->sr_cmnd[1] = 0;
1456 sreq->sr_cmnd[2] = 0;
1457 sreq->sr_cmnd[3] = 0;
1458 sreq->sr_cmnd[4] = SCSI_REMOVAL_PREVENT;
1459 sreq->sr_cmnd[5] = 0;
1460 sreq->sr_data_direction = DMA_NONE;
1461 sreq->sr_bufflen = 0;
1462 sreq->sr_buffer = NULL;
1463 sreq->sr_allowed = 5;
1464 sreq->sr_done = scsi_eh_lock_done;
1465 sreq->sr_timeout_per_command = 10 * HZ;
1466 sreq->sr_cmd_len = COMMAND_SIZE(sreq->sr_cmnd[0]);
1468 scsi_insert_special_req(sreq, 1);
1473 * scsi_restart_operations - restart io operations to the specified host.
1474 * @shost: Host we are restarting.
1477 * When we entered the error handler, we blocked all further i/o to
1478 * this device. we need to 'reverse' this process.
1480 static void scsi_restart_operations(struct Scsi_Host *shost)
1482 struct scsi_device *sdev;
1485 * If the door was locked, we need to insert a door lock request
1486 * onto the head of the SCSI request queue for the device. There
1487 * is no point trying to lock the door of an off-line device.
1489 shost_for_each_device(sdev, shost) {
1490 if (scsi_device_online(sdev) && sdev->locked)
1491 scsi_eh_lock_door(sdev);
1495 * next free up anything directly waiting upon the host. this
1496 * will be requests for character device operations, and also for
1497 * ioctls to queued block devices.
1499 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: waking up host to restart\n",
1502 clear_bit(SHOST_RECOVERY, &shost->shost_state);
1504 wake_up(&shost->host_wait);
1507 * finally we need to re-initiate requests that may be pending. we will
1508 * have had everything blocked while error handling is taking place, and
1509 * now that error recovery is done, we will need to ensure that these
1510 * requests are started.
1512 scsi_run_host_queues(shost);
1516 * scsi_eh_ready_devs - check device ready state and recover if not.
1517 * @shost: host to be recovered.
1518 * @eh_done_q: list_head for processed commands.
1521 static void scsi_eh_ready_devs(struct Scsi_Host *shost,
1522 struct list_head *work_q,
1523 struct list_head *done_q)
1525 if (!scsi_eh_stu(shost, work_q, done_q))
1526 if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
1527 if (!scsi_eh_bus_reset(shost, work_q, done_q))
1528 if (!scsi_eh_host_reset(work_q, done_q))
1529 scsi_eh_offline_sdevs(work_q, done_q);
1533 * scsi_eh_flush_done_q - finish processed commands or retry them.
1534 * @done_q: list_head of processed commands.
1537 static void scsi_eh_flush_done_q(struct list_head *done_q)
1539 struct list_head *lh, *lh_sf;
1540 struct scsi_cmnd *scmd;
1542 list_for_each_safe(lh, lh_sf, done_q) {
1543 scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
1545 if (scsi_device_online(scmd->device) &&
1546 !blk_noretry_request(scmd->request) &&
1547 (++scmd->retries < scmd->allowed)) {
1548 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: flush"
1552 scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
1555 scmd->result |= (DRIVER_TIMEOUT << 24);
1556 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: flush finish"
1558 current->comm, scmd));
1559 scsi_finish_command(scmd);
1565 * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
1566 * @shost: Host to unjam.
1569 * When we come in here, we *know* that all commands on the bus have
1570 * either completed, failed or timed out. we also know that no further
1571 * commands are being sent to the host, so things are relatively quiet
1572 * and we have freedom to fiddle with things as we wish.
1574 * This is only the *default* implementation. it is possible for
1575 * individual drivers to supply their own version of this function, and
1576 * if the maintainer wishes to do this, it is strongly suggested that
1577 * this function be taken as a template and modified. this function
1578 * was designed to correctly handle problems for about 95% of the
1579 * different cases out there, and it should always provide at least a
1580 * reasonable amount of error recovery.
1582 * Any command marked 'failed' or 'timeout' must eventually have
1583 * scsi_finish_cmd() called for it. we do all of the retry stuff
1584 * here, so when we restart the host after we return it should have an
1587 static void scsi_unjam_host(struct Scsi_Host *shost)
1589 unsigned long flags;
1590 LIST_HEAD(eh_work_q);
1591 LIST_HEAD(eh_done_q);
1593 spin_lock_irqsave(shost->host_lock, flags);
1594 list_splice_init(&shost->eh_cmd_q, &eh_work_q);
1595 spin_unlock_irqrestore(shost->host_lock, flags);
1597 SCSI_LOG_ERROR_RECOVERY(1, scsi_eh_prt_fail_stats(shost, &eh_work_q));
1599 if (!scsi_eh_get_sense(&eh_work_q, &eh_done_q))
1600 if (!scsi_eh_abort_cmds(&eh_work_q, &eh_done_q))
1601 scsi_eh_ready_devs(shost, &eh_work_q, &eh_done_q);
1603 scsi_eh_flush_done_q(&eh_done_q);
1607 * scsi_error_handler - Handle errors/timeouts of SCSI cmds.
1608 * @data: Host for which we are running.
1611 * This is always run in the context of a kernel thread. The idea is
1612 * that we start this thing up when the kernel starts up (one per host
1613 * that we detect), and it immediately goes to sleep and waits for some
1614 * event (i.e. failure). When this takes place, we have the job of
1615 * trying to unjam the bus and restarting things.
1617 int scsi_error_handler(void *data)
1619 struct Scsi_Host *shost = (struct Scsi_Host *) data;
1621 DECLARE_MUTEX_LOCKED(sem);
1629 daemonize("scsi_eh_%d", shost->host_no);
1631 current->flags |= PF_NOFREEZE;
1633 shost->eh_wait = &sem;
1634 shost->ehandler = current;
1639 * Wake up the thread that created us.
1641 SCSI_LOG_ERROR_RECOVERY(3, printk("Wake up parent of"
1642 " scsi_eh_%d\n",shost->host_no));
1644 complete(shost->eh_notify);
1648 * If we get a signal, it means we are supposed to go
1649 * away and die. This typically happens if the user is
1650 * trying to unload a module.
1652 SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler"
1654 " sleeping\n",shost->host_no));
1657 * Note - we always use down_interruptible with the semaphore
1658 * even if the module was loaded as part of the kernel. The
1659 * reason is that down() will cause this thread to be counted
1660 * in the load average as a running process, and down
1661 * interruptible doesn't. Given that we need to allow this
1662 * thread to die if the driver was loaded as a module, using
1663 * semaphores isn't unreasonable.
1665 down_interruptible(&sem);
1669 SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler"
1670 " scsi_eh_%d waking"
1671 " up\n",shost->host_no));
1673 shost->eh_active = 1;
1676 * We have a host that is failing for some reason. Figure out
1677 * what we need to do to get it up and online again (if we can).
1678 * If we fail, we end up taking the thing offline.
1680 if (shost->hostt->eh_strategy_handler)
1681 rtn = shost->hostt->eh_strategy_handler(shost);
1683 scsi_unjam_host(shost);
1685 shost->eh_active = 0;
1688 * Note - if the above fails completely, the action is to take
1689 * individual devices offline and flush the queue of any
1690 * outstanding requests that may have been pending. When we
1691 * restart, we restart any I/O to any other devices on the bus
1692 * which are still online.
1694 scsi_restart_operations(shost);
1698 SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler scsi_eh_%d"
1699 " exiting\n",shost->host_no));
1702 * Make sure that nobody tries to wake us up again.
1704 shost->eh_wait = NULL;
1707 * Knock this down too. From this point on, the host is flying
1708 * without a pilot. If this is because the module is being unloaded,
1709 * that's fine. If the user sent a signal to this thing, we are
1710 * potentially in real danger.
1712 shost->eh_active = 0;
1713 shost->ehandler = NULL;
1716 * If anyone is waiting for us to exit (i.e. someone trying to unload
1717 * a driver), then wake up that process to let them know we are on
1718 * the way out the door.
1720 complete_and_exit(shost->eh_notify, 0);
1725 * Function: scsi_report_bus_reset()
1727 * Purpose: Utility function used by low-level drivers to report that
1728 * they have observed a bus reset on the bus being handled.
1730 * Arguments: shost - Host in question
1731 * channel - channel on which reset was observed.
1735 * Lock status: Host lock must be held.
1737 * Notes: This only needs to be called if the reset is one which
1738 * originates from an unknown location. Resets originated
1739 * by the mid-level itself don't need to call this, but there
1740 * should be no harm.
1742 * The main purpose of this is to make sure that a CHECK_CONDITION
1743 * is properly treated.
1745 void scsi_report_bus_reset(struct Scsi_Host *shost, int channel)
1747 struct scsi_device *sdev;
1749 __shost_for_each_device(sdev, shost) {
1750 if (channel == sdev->channel) {
1751 sdev->was_reset = 1;
1752 sdev->expecting_cc_ua = 1;
1758 * Function: scsi_report_device_reset()
1760 * Purpose: Utility function used by low-level drivers to report that
1761 * they have observed a device reset on the device being handled.
1763 * Arguments: shost - Host in question
1764 * channel - channel on which reset was observed
1765 * target - target on which reset was observed
1769 * Lock status: Host lock must be held
1771 * Notes: This only needs to be called if the reset is one which
1772 * originates from an unknown location. Resets originated
1773 * by the mid-level itself don't need to call this, but there
1774 * should be no harm.
1776 * The main purpose of this is to make sure that a CHECK_CONDITION
1777 * is properly treated.
1779 void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
1781 struct scsi_device *sdev;
1783 __shost_for_each_device(sdev, shost) {
1784 if (channel == sdev->channel &&
1785 target == sdev->id) {
1786 sdev->was_reset = 1;
1787 sdev->expecting_cc_ua = 1;
1793 scsi_reset_provider_done_command(struct scsi_cmnd *scmd)
1798 * Function: scsi_reset_provider
1800 * Purpose: Send requested reset to a bus or device at any phase.
1802 * Arguments: device - device to send reset to
1803 * flag - reset type (see scsi.h)
1805 * Returns: SUCCESS/FAILURE.
1807 * Notes: This is used by the SCSI Generic driver to provide
1808 * Bus/Device reset capability.
1811 scsi_reset_provider(struct scsi_device *dev, int flag)
1813 struct scsi_cmnd *scmd = scsi_get_command(dev, GFP_KERNEL);
1817 scmd->request = &req;
1818 memset(&scmd->eh_timeout, 0, sizeof(scmd->eh_timeout));
1819 scmd->request->rq_status = RQ_SCSI_BUSY;
1820 scmd->state = SCSI_STATE_INITIALIZING;
1821 scmd->owner = SCSI_OWNER_MIDLEVEL;
1823 memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd));
1825 scmd->scsi_done = scsi_reset_provider_done_command;
1827 scmd->buffer = NULL;
1829 scmd->request_buffer = NULL;
1830 scmd->request_bufflen = 0;
1831 scmd->internal_timeout = NORMAL_TIMEOUT;
1832 scmd->abort_reason = DID_ABORT;
1836 scmd->sc_data_direction = DMA_BIDIRECTIONAL;
1837 scmd->sc_request = NULL;
1838 scmd->sc_magic = SCSI_CMND_MAGIC;
1840 init_timer(&scmd->eh_timeout);
1843 * Sometimes the command can get back into the timer chain,
1844 * so use the pid as an identifier.
1849 case SCSI_TRY_RESET_DEVICE:
1850 rtn = scsi_try_bus_device_reset(scmd);
1854 case SCSI_TRY_RESET_BUS:
1855 rtn = scsi_try_bus_reset(scmd);
1859 case SCSI_TRY_RESET_HOST:
1860 rtn = scsi_try_host_reset(scmd);
1866 scsi_delete_timer(scmd);
1867 scsi_next_command(scmd);