2 * scsi.c Copyright (C) 1992 Drew Eckhardt
3 * Copyright (C) 1993, 1994, 1995 Eric Youngdale
5 * generic mid-level SCSI driver
6 * Initial versions: Drew Eckhardt
7 * Subsequent revisions: Eric Youngdale
11 * Bug correction thanks go to :
12 * Rik Faith <faith@cs.unc.edu>
13 * Tommy Thorn <tthorn>
14 * Thomas Wuensche <tw@fgb1.fgb.mw.tu-muenchen.de>
16 * Modified by Eric Youngdale eric@aib.com to
17 * add scatter-gather, multiple outstanding request, and other
20 * Native multichannel, wide scsi, /proc/scsi and hot plugging
21 * support added by Michael Neuffer <mike@i-connect.net>
23 * Major improvements to the timeout, abort, and reset processing,
24 * as well as performance modifications for large queue depths by
25 * Leonard N. Zubkoff <lnz@dandelion.com>
27 * Improved compatibility with 2.0 behaviour by Manfred Spraul
28 * <masp0008@stud.uni-sb.de>
32 *#########################################################################
33 *#########################################################################
34 *#########################################################################
35 *#########################################################################
36 * NOTE - NOTE - NOTE - NOTE - NOTE - NOTE - NOTE
38 *#########################################################################
39 *#########################################################################
40 *#########################################################################
41 *#########################################################################
43 * This file contains the 'old' scsi error handling. It is only present
44 * while the new error handling code is being debugged, and while the low
45 * level drivers are being converted to use the new code. Once the last
46 * driver uses the new code this *ENTIRE* file will be nuked.
49 #define __NO_VERSION__
50 #include <linux/module.h>
52 #include <linux/sched.h>
53 #include <linux/timer.h>
54 #include <linux/string.h>
55 #include <linux/malloc.h>
56 #include <linux/ioport.h>
57 #include <linux/kernel.h>
58 #include <linux/stat.h>
59 #include <linux/blk.h>
60 #include <linux/interrupt.h>
61 #include <linux/delay.h>
63 #include <asm/system.h>
69 #include "constants.h"
71 #undef USE_STATIC_SCSI_MEMORY
74 static const char RCSid[] = "$Header: /mnt/ide/home/eric/CVSROOT/linux/drivers/scsi/scsi_obsolete.c,v 1.1 1997/05/18 23:27:21 eric Exp $";
78 #define INTERNAL_ERROR (panic ("Internal error in file %s, line %d.\n", __FILE__, __LINE__))
81 static int scsi_abort(Scsi_Cmnd
*, int code
);
82 static int scsi_reset(Scsi_Cmnd
*, unsigned int);
84 extern void scsi_old_done(Scsi_Cmnd
* SCpnt
);
85 int update_timeout(Scsi_Cmnd
*, int);
86 extern void scsi_old_times_out(Scsi_Cmnd
* SCpnt
);
87 extern void internal_cmnd(Scsi_Cmnd
* SCpnt
);
89 extern volatile struct Scsi_Host
*host_active
;
90 #define SCSI_BLOCK(HOST) ((HOST->block && host_active && HOST != host_active) \
91 || (HOST->can_queue && HOST->host_busy >= HOST->can_queue))
93 static unsigned char generic_sense
[6] = {REQUEST_SENSE
, 0, 0, 0, 255, 0};
96 * This is the number of clock ticks we should wait before we time out
97 * and abort the command. This is for where the scsi.c module generates
98 * the command, not where it originates from a higher level, in which
99 * case the timeout is specified there.
101 * ABORT_TIMEOUT and RESET_TIMEOUT are the timeouts for RESET and ABORT
106 static void scsi_dump_status(void);
111 #define SCSI_TIMEOUT (5*HZ)
113 #define SCSI_TIMEOUT (2*HZ)
117 #define SENSE_TIMEOUT SCSI_TIMEOUT
118 #define ABORT_TIMEOUT SCSI_TIMEOUT
119 #define RESET_TIMEOUT SCSI_TIMEOUT
121 #define SENSE_TIMEOUT (5*HZ/10)
122 #define RESET_TIMEOUT (5*HZ/10)
123 #define ABORT_TIMEOUT (5*HZ/10)
127 /* Do not call reset on error if we just did a reset within 15 sec. */
128 #define MIN_RESET_PERIOD (15*HZ)
133 * Flag bits for the internal_timeout array
135 #define NORMAL_TIMEOUT 0
142 * This is our time out function, called when the timer expires for a
143 * given host adapter. It will attempt to abort the currently executing
144 * command, that failing perform a kernel panic.
147 void scsi_old_times_out(Scsi_Cmnd
* SCpnt
)
151 spin_lock_irqsave(&io_request_lock
, flags
);
153 /* Set the serial_number_at_timeout to the current serial_number */
154 SCpnt
->serial_number_at_timeout
= SCpnt
->serial_number
;
156 switch (SCpnt
->internal_timeout
& (IN_ABORT
| IN_RESET
| IN_RESET2
| IN_RESET3
)) {
164 if (!scsi_abort(SCpnt
, DID_TIME_OUT
))
167 printk("SCSI host %d abort (pid %ld) timed out - resetting\n",
168 SCpnt
->host
->host_no
, SCpnt
->pid
);
169 if (!scsi_reset(SCpnt
, SCSI_RESET_ASYNCHRONOUS
))
172 case (IN_ABORT
| IN_RESET
):
173 /* This might be controversial, but if there is a bus hang,
174 * you might conceivably want the machine up and running
175 * esp if you have an ide disk.
177 printk("SCSI host %d channel %d reset (pid %ld) timed out - "
179 SCpnt
->host
->host_no
, SCpnt
->channel
, SCpnt
->pid
);
180 SCpnt
->internal_timeout
&= ~IN_RESET
;
181 SCpnt
->internal_timeout
|= IN_RESET2
;
183 SCSI_RESET_ASYNCHRONOUS
| SCSI_RESET_SUGGEST_BUS_RESET
);
186 case (IN_ABORT
| IN_RESET2
):
187 /* Obviously the bus reset didn't work.
188 * Let's try even harder and call for an HBA reset.
189 * Maybe the HBA itself crashed and this will shake it loose.
191 printk("SCSI host %d reset (pid %ld) timed out - trying to shake it loose\n",
192 SCpnt
->host
->host_no
, SCpnt
->pid
);
193 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
);
194 SCpnt
->internal_timeout
|= IN_RESET3
;
196 SCSI_RESET_ASYNCHRONOUS
| SCSI_RESET_SUGGEST_HOST_RESET
);
200 printk("SCSI host %d reset (pid %ld) timed out again -\n",
201 SCpnt
->host
->host_no
, SCpnt
->pid
);
202 printk("probably an unrecoverable SCSI bus or device hang.\n");
206 spin_unlock_irqrestore(&io_request_lock
, flags
);
211 * From what I can find in scsi_obsolete.c, this function is only called
212 * by scsi_old_done and scsi_reset. Both of these functions run with the
213 * io_request_lock already held, so we need do nothing here about grabbing
216 static void scsi_request_sense(Scsi_Cmnd
* SCpnt
)
218 SCpnt
->flags
|= WAS_SENSE
| ASKED_FOR_SENSE
;
219 update_timeout(SCpnt
, SENSE_TIMEOUT
);
222 memcpy((void *) SCpnt
->cmnd
, (void *) generic_sense
,
223 sizeof(generic_sense
));
224 memset((void *) SCpnt
->sense_buffer
, 0,
225 sizeof(SCpnt
->sense_buffer
));
227 SCpnt
->cmnd
[1] = SCpnt
->lun
<< 5;
228 SCpnt
->cmnd
[4] = sizeof(SCpnt
->sense_buffer
);
230 SCpnt
->request_buffer
= &SCpnt
->sense_buffer
;
231 SCpnt
->request_bufflen
= sizeof(SCpnt
->sense_buffer
);
233 SCpnt
->cmd_len
= COMMAND_SIZE(SCpnt
->cmnd
[0]);
235 internal_cmnd(SCpnt
);
241 static int check_sense(Scsi_Cmnd
* SCpnt
)
243 /* If there is no sense information, request it. If we have already
244 * requested it, there is no point in asking again - the firmware must
247 if (((SCpnt
->sense_buffer
[0] & 0x70) >> 4) != 7) {
248 if (!(SCpnt
->flags
& ASKED_FOR_SENSE
))
249 return SUGGEST_SENSE
;
251 return SUGGEST_RETRY
;
253 SCpnt
->flags
&= ~ASKED_FOR_SENSE
;
256 printk("scsi%d, channel%d : ", SCpnt
->host
->host_no
, SCpnt
->channel
);
257 print_sense("", SCpnt
);
260 if (SCpnt
->sense_buffer
[2] & 0xe0)
261 return SUGGEST_ABORT
;
263 switch (SCpnt
->sense_buffer
[2] & 0xf) {
266 case RECOVERED_ERROR
:
267 return SUGGEST_IS_OK
;
269 case ABORTED_COMMAND
:
270 return SUGGEST_RETRY
;
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 (SCpnt
->device
->expecting_cc_ua
) {
280 SCpnt
->device
->expecting_cc_ua
= 0;
281 return SUGGEST_RETRY
;
283 return SUGGEST_ABORT
;
285 /* these three are not supported */
287 case VOLUME_OVERFLOW
:
291 return SUGGEST_REMAP
;
295 case ILLEGAL_REQUEST
:
297 return SUGGEST_ABORT
;
301 /* This function is the mid-level interrupt routine, which decides how
302 * to handle error conditions. Each invocation of this function must
303 * do one and *only* one of the following:
305 * (1) Call last_cmnd[host].done. This is done for fatal errors and
306 * normal completion, and indicates that the handling for this
307 * request is complete.
308 * (2) Call internal_cmnd to requeue the command. This will result in
309 * scsi_done being called again when the retry is complete.
310 * (3) Call scsi_request_sense. This asks the host adapter/drive for
311 * more information about the error condition. When the information
312 * is available, scsi_done will be called again.
313 * (4) Call reset(). This is sort of a last resort, and the idea is that
314 * this may kick things loose and get the drive working again. reset()
315 * automatically calls scsi_request_sense, and thus scsi_done will be
316 * called again once the reset is complete.
318 * If none of the above actions are taken, the drive in question
319 * will hang. If more than one of the above actions are taken by
320 * scsi_done, then unpredictable behavior will result.
322 void scsi_old_done(Scsi_Cmnd
* SCpnt
)
328 struct Scsi_Host
*host
= SCpnt
->host
;
329 int result
= SCpnt
->result
;
330 SCpnt
->serial_number
= 0;
331 SCpnt
->serial_number_at_timeout
= 0;
332 oldto
= update_timeout(SCpnt
, 0);
336 printk("Non-zero result in scsi_done %x %d:%d\n",
337 result
, SCpnt
->target
, SCpnt
->lun
);
340 /* If we requested an abort, (and we got it) then fix up the return
343 if (host_byte(result
) == DID_ABORT
&& SCpnt
->abort_reason
)
344 SCpnt
->result
= result
= (result
& 0xff00ffff) |
345 (SCpnt
->abort_reason
<< 16);
348 #define CMD_FINISHED 0
354 printk("In scsi_done(host = %d, result = %06x)\n", host
->host_no
, result
);
357 if (SCpnt
->flags
& SYNC_RESET
) {
359 * The behaviou of scsi_reset(SYNC) was changed in 2.1.? .
360 * The scsi mid-layer does a REDO after every sync reset, the driver
361 * must not do that any more. In order to prevent old drivers from
362 * crashing, all scsi_done() calls during sync resets are ignored.
364 printk("scsi%d: device driver called scsi_done() "
365 "for a syncronous reset.\n", SCpnt
->host
->host_no
);
368 if (SCpnt
->flags
& WAS_SENSE
) {
369 SCpnt
->use_sg
= SCpnt
->old_use_sg
;
370 SCpnt
->cmd_len
= SCpnt
->old_cmd_len
;
372 switch (host_byte(result
)) {
374 if (status_byte(result
) && (SCpnt
->flags
& WAS_SENSE
))
375 /* Failed to obtain sense information */
377 SCpnt
->flags
&= ~WAS_SENSE
;
378 #if 0 /* This cannot possibly be correct. */
379 SCpnt
->internal_timeout
&= ~SENSE_TIMEOUT
;
382 if (!(SCpnt
->flags
& WAS_RESET
)) {
383 printk("scsi%d : channel %d target %d lun %d request sense"
384 " failed, performing reset.\n",
385 SCpnt
->host
->host_no
, SCpnt
->channel
, SCpnt
->target
,
387 scsi_reset(SCpnt
, SCSI_RESET_SYNCHRONOUS
);
391 exit
= (DRIVER_HARD
| SUGGEST_ABORT
);
392 status
= CMD_FINISHED
;
395 switch (msg_byte(result
)) {
396 case COMMAND_COMPLETE
:
397 switch (status_byte(result
)) {
399 if (SCpnt
->flags
& WAS_SENSE
) {
401 printk("In scsi_done, GOOD status, COMMAND COMPLETE, "
402 "parsing sense information.\n");
404 SCpnt
->flags
&= ~WAS_SENSE
;
405 #if 0 /* This cannot possibly be correct. */
406 SCpnt
->internal_timeout
&= ~SENSE_TIMEOUT
;
409 switch (checked
= check_sense(SCpnt
)) {
413 printk("NO SENSE. status = REDO\n");
415 update_timeout(SCpnt
, oldto
);
422 printk("SENSE SUGGEST REMAP - status = CMD_FINISHED\n");
424 status
= CMD_FINISHED
;
425 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
429 printk("SENSE SUGGEST RETRY - status = MAYREDO\n");
432 exit
= DRIVER_SENSE
| SUGGEST_RETRY
;
436 printk("SENSE SUGGEST ABORT - status = CMD_FINISHED");
438 status
= CMD_FINISHED
;
439 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
442 printk("Internal error %s %d \n", __FILE__
,
449 printk("COMMAND COMPLETE message returned, "
450 "status = CMD_FINISHED. \n");
453 status
= CMD_FINISHED
;
457 case CHECK_CONDITION
:
458 case COMMAND_TERMINATED
:
459 switch (check_sense(SCpnt
)) {
461 update_timeout(SCpnt
, oldto
);
465 status
= CMD_FINISHED
;
466 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
470 exit
= DRIVER_SENSE
| SUGGEST_RETRY
;
473 status
= CMD_FINISHED
;
474 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
477 scsi_request_sense(SCpnt
);
484 case INTERMEDIATE_GOOD
:
485 case INTERMEDIATE_C_GOOD
:
490 update_timeout(SCpnt
, oldto
);
494 case RESERVATION_CONFLICT
:
495 printk("scsi%d, channel %d : RESERVATION CONFLICT performing"
496 " reset.\n", SCpnt
->host
->host_no
, SCpnt
->channel
);
497 scsi_reset(SCpnt
, SCSI_RESET_SYNCHRONOUS
);
501 printk("Internal error %s %d \n"
502 "status byte = %d \n", __FILE__
,
503 __LINE__
, status_byte(result
));
508 panic("scsi: unsupported message byte %d received\n",
514 printk("Host returned DID_TIME_OUT - ");
517 if (SCpnt
->flags
& WAS_TIMEDOUT
) {
519 printk("Aborting\n");
522 Allow TEST_UNIT_READY and INQUIRY commands to timeout early
523 without causing resets. All other commands should be retried.
525 if (SCpnt
->cmnd
[0] != TEST_UNIT_READY
&&
526 SCpnt
->cmnd
[0] != INQUIRY
)
528 exit
= (DRIVER_TIMEOUT
| SUGGEST_ABORT
);
531 printk("Retrying.\n");
533 SCpnt
->flags
|= WAS_TIMEDOUT
;
534 SCpnt
->internal_timeout
&= ~IN_ABORT
;
544 printk("Couldn't connect.\n");
546 exit
= (DRIVER_HARD
| SUGGEST_ABORT
);
550 exit
= (DRIVER_HARD
| SUGGEST_ABORT
);
554 exit
= (DRIVER_INVALID
| SUGGEST_ABORT
);
557 if (SCpnt
->flags
& IS_RESETTING
) {
558 SCpnt
->flags
&= ~IS_RESETTING
;
562 if (msg_byte(result
) == GOOD
&&
563 status_byte(result
) == CHECK_CONDITION
) {
564 switch (check_sense(SCpnt
)) {
566 update_timeout(SCpnt
, oldto
);
572 exit
= DRIVER_SENSE
| SUGGEST_RETRY
;
575 status
= CMD_FINISHED
;
576 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
579 scsi_request_sense(SCpnt
);
585 exit
= SUGGEST_RETRY
;
589 exit
= (DRIVER_ERROR
| SUGGEST_DIE
);
598 printk("In MAYREDO, allowing %d retries, have %d\n",
599 SCpnt
->allowed
, SCpnt
->retries
);
601 if ((++SCpnt
->retries
) < SCpnt
->allowed
) {
602 if ((SCpnt
->retries
>= (SCpnt
->allowed
>> 1))
603 && !(SCpnt
->host
->resetting
&& time_before(jiffies
, SCpnt
->host
->last_reset
+ MIN_RESET_PERIOD
))
604 && !(SCpnt
->flags
& WAS_RESET
)) {
605 printk("scsi%d channel %d : resetting for second half of retries.\n",
606 SCpnt
->host
->host_no
, SCpnt
->channel
);
607 scsi_reset(SCpnt
, SCSI_RESET_SYNCHRONOUS
);
608 /* fall through to REDO */
611 status
= CMD_FINISHED
;
614 /* fall through to REDO */
618 if (SCpnt
->flags
& WAS_SENSE
)
619 scsi_request_sense(SCpnt
);
621 memcpy((void *) SCpnt
->cmnd
,
622 (void *) SCpnt
->data_cmnd
,
623 sizeof(SCpnt
->data_cmnd
));
624 memset((void *) SCpnt
->sense_buffer
, 0,
625 sizeof(SCpnt
->sense_buffer
));
626 SCpnt
->request_buffer
= SCpnt
->buffer
;
627 SCpnt
->request_bufflen
= SCpnt
->bufflen
;
628 SCpnt
->use_sg
= SCpnt
->old_use_sg
;
629 SCpnt
->cmd_len
= SCpnt
->old_cmd_len
;
631 internal_cmnd(SCpnt
);
638 if (status
== CMD_FINISHED
) {
640 printk("Calling done function - at address %p\n", SCpnt
->done
);
642 host
->host_busy
--; /* Indicate that we are free */
644 if (host
->block
&& host
->host_busy
== 0) {
647 /* For block devices "wake_up" is done in end_scsi_request */
648 if (!SCSI_BLK_MAJOR(MAJOR(SCpnt
->request
.rq_dev
))) {
649 struct Scsi_Host
*next
;
651 for (next
= host
->block
; next
!= host
; next
= next
->block
)
652 wake_up(&next
->host_wait
);
655 wake_up(&host
->host_wait
);
656 SCpnt
->result
= result
| ((exit
& 0xff) << 24);
657 SCpnt
->use_sg
= SCpnt
->old_use_sg
;
658 SCpnt
->cmd_len
= SCpnt
->old_cmd_len
;
668 * The scsi_abort function interfaces with the abort() function of the host
669 * we are aborting, and causes the current command to not complete. The
670 * caller should deal with any error messages or status returned on the
673 * This will not be called reentrantly for a given host.
677 * Since we're nice guys and specified that abort() and reset()
678 * can be non-reentrant. The internal_timeout flags are used for
683 static int scsi_abort(Scsi_Cmnd
* SCpnt
, int why
)
686 struct Scsi_Host
*host
= SCpnt
->host
;
691 * Protect against races here. If the command is done, or we are
692 * on a different command forget it.
694 if (SCpnt
->serial_number
!= SCpnt
->serial_number_at_timeout
) {
697 if (SCpnt
->internal_timeout
& IN_ABORT
) {
698 spin_unlock_irq(&io_request_lock
);
699 while (SCpnt
->internal_timeout
& IN_ABORT
)
701 spin_lock_irq(&io_request_lock
);
703 SCpnt
->internal_timeout
|= IN_ABORT
;
704 oldto
= update_timeout(SCpnt
, ABORT_TIMEOUT
);
706 if ((SCpnt
->flags
& IS_RESETTING
) && SCpnt
->device
->soft_reset
) {
707 /* OK, this command must have died when we did the
708 * reset. The device itself must have lied.
710 printk("Stale command on %d %d:%d appears to have died when"
711 " the bus was reset\n",
712 SCpnt
->channel
, SCpnt
->target
, SCpnt
->lun
);
714 if (!host
->host_busy
) {
715 SCpnt
->internal_timeout
&= ~IN_ABORT
;
716 update_timeout(SCpnt
, oldto
);
719 printk("scsi : aborting command due to timeout : pid %lu, scsi%d,"
720 " channel %d, id %d, lun %d ",
721 SCpnt
->pid
, SCpnt
->host
->host_no
, (int) SCpnt
->channel
,
722 (int) SCpnt
->target
, (int) SCpnt
->lun
);
723 print_command(SCpnt
->cmnd
);
724 if (SCpnt
->serial_number
!= SCpnt
->serial_number_at_timeout
)
726 SCpnt
->abort_reason
= why
;
727 switch (host
->hostt
->abort(SCpnt
)) {
728 /* We do not know how to abort. Try waiting another
729 * time increment and see if this helps. Set the
730 * WAS_TIMEDOUT flag set so we do not try this twice
732 case SCSI_ABORT_BUSY
: /* Tough call - returning 1 from
735 case SCSI_ABORT_SNOOZE
:
736 if (why
== DID_TIME_OUT
) {
737 SCpnt
->internal_timeout
&= ~IN_ABORT
;
738 if (SCpnt
->flags
& WAS_TIMEDOUT
) {
739 return 1; /* Indicate we cannot handle this.
740 * We drop down into the reset handler
744 SCpnt
->flags
|= WAS_TIMEDOUT
;
745 oldto
= SCpnt
->timeout_per_command
;
746 update_timeout(SCpnt
, oldto
);
750 case SCSI_ABORT_PENDING
:
751 if (why
!= DID_TIME_OUT
) {
752 update_timeout(SCpnt
, oldto
);
755 case SCSI_ABORT_SUCCESS
:
756 /* We should have already aborted this one. No
757 * need to adjust timeout
759 SCpnt
->internal_timeout
&= ~IN_ABORT
;
761 case SCSI_ABORT_NOT_RUNNING
:
762 SCpnt
->internal_timeout
&= ~IN_ABORT
;
763 update_timeout(SCpnt
, 0);
765 case SCSI_ABORT_ERROR
:
767 SCpnt
->internal_timeout
&= ~IN_ABORT
;
775 /* Mark a single SCSI Device as having been reset. */
777 static inline void scsi_mark_device_reset(Scsi_Device
* Device
)
779 Device
->was_reset
= 1;
780 Device
->expecting_cc_ua
= 1;
784 /* Mark all SCSI Devices on a specific Host as having been reset. */
786 void scsi_mark_host_reset(struct Scsi_Host
*Host
)
791 for (SDpnt
= Host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
792 for (SCpnt
= SDpnt
->device_queue
; SCpnt
; SCpnt
= SCpnt
->next
)
793 scsi_mark_device_reset(SCpnt
->device
);
798 /* Mark all SCSI Devices on a specific Host Bus as having been reset. */
800 static void scsi_mark_bus_reset(struct Scsi_Host
*Host
, int channel
)
805 for (SDpnt
= Host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
806 for (SCpnt
= SDpnt
->device_queue
; SCpnt
; SCpnt
= SCpnt
->next
)
807 if (SCpnt
->channel
== channel
)
808 scsi_mark_device_reset(SCpnt
->device
);
813 static int scsi_reset(Scsi_Cmnd
* SCpnt
, unsigned int reset_flags
)
818 struct Scsi_Host
*host
= SCpnt
->host
;
820 printk("SCSI bus is being reset for host %d channel %d.\n",
821 host
->host_no
, SCpnt
->channel
);
825 * First of all, we need to make a recommendation to the low-level
826 * driver as to whether a BUS_DEVICE_RESET should be performed,
827 * or whether we should do a full BUS_RESET. There is no simple
828 * algorithm here - we basically use a series of heuristics
829 * to determine what we should do.
831 SCpnt
->host
->suggest_bus_reset
= FALSE
;
834 * First see if all of the active devices on the bus have
835 * been jammed up so that we are attempting resets. If so,
836 * then suggest a bus reset. Forcing a bus reset could
837 * result in some race conditions, but no more than
838 * you would usually get with timeouts. We will cross
839 * that bridge when we come to it.
841 * This is actually a pretty bad idea, since a sequence of
842 * commands will often timeout together and this will cause a
843 * Bus Device Reset followed immediately by a SCSI Bus Reset.
844 * If all of the active devices really are jammed up, the
845 * Bus Device Reset will quickly timeout and scsi_times_out
846 * will follow up with a SCSI Bus Reset anyway.
848 SCpnt1
= host
->host_queue
;
850 if (SCpnt1
->request
.rq_status
!= RQ_INACTIVE
851 && (SCpnt1
->flags
& (WAS_RESET
| IS_RESETTING
)) == 0)
853 SCpnt1
= SCpnt1
->next
;
855 if (SCpnt1
== NULL
) {
856 reset_flags
|= SCSI_RESET_SUGGEST_BUS_RESET
;
859 * If the code that called us is suggesting a hard reset, then
860 * definitely request it. This usually occurs because a
861 * BUS_DEVICE_RESET times out.
863 * Passing reset_flags along takes care of this automatically.
865 if (reset_flags
& SCSI_RESET_SUGGEST_BUS_RESET
) {
866 SCpnt
->host
->suggest_bus_reset
= TRUE
;
873 * Protect against races here. If the command is done, or we are
874 * on a different command forget it.
876 if (reset_flags
& SCSI_RESET_ASYNCHRONOUS
)
877 if (SCpnt
->serial_number
!= SCpnt
->serial_number_at_timeout
) {
880 if (SCpnt
->internal_timeout
& IN_RESET
) {
881 spin_unlock_irq(&io_request_lock
);
882 while (SCpnt
->internal_timeout
& IN_RESET
)
884 spin_lock_irq(&io_request_lock
);
886 SCpnt
->internal_timeout
|= IN_RESET
;
887 update_timeout(SCpnt
, RESET_TIMEOUT
);
889 if (reset_flags
& SCSI_RESET_SYNCHRONOUS
)
890 SCpnt
->flags
|= SYNC_RESET
;
891 if (host
->host_busy
) {
892 for (SDpnt
= host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
893 SCpnt1
= SDpnt
->device_queue
;
895 if (SCpnt1
->request
.rq_status
!= RQ_INACTIVE
) {
897 if (!(SCpnt1
->flags
& IS_RESETTING
) &&
898 !(SCpnt1
->internal_timeout
& IN_ABORT
))
899 scsi_abort(SCpnt1
, DID_RESET
);
901 SCpnt1
->flags
|= (WAS_RESET
| IS_RESETTING
);
903 SCpnt1
= SCpnt1
->next
;
907 host
->last_reset
= jiffies
;
910 * I suppose that the host reset callback will not play
911 * with the resetting field. We have just set the resetting
914 temp
= host
->hostt
->reset(SCpnt
, reset_flags
);
916 This test allows the driver to introduce an additional bus
917 settle time delay by setting last_reset up to 20 seconds in
918 the future. In the normal case where the driver does not
919 modify last_reset, it must be assumed that the actual bus
920 reset occurred immediately prior to the return to this code,
921 and so last_reset must be updated to the current time, so
922 that the delay in internal_cmnd will guarantee at least a
923 MIN_RESET_DELAY bus settle time.
925 if (host
->last_reset
- jiffies
> 20UL * HZ
)
926 host
->last_reset
= jiffies
;
930 host
->last_reset
= jiffies
;
932 SCpnt
->flags
|= (WAS_RESET
| IS_RESETTING
);
934 * I suppose that the host reset callback will not play
935 * with the resetting field. We have just set the resetting
938 temp
= host
->hostt
->reset(SCpnt
, reset_flags
);
939 if (time_before(host
->last_reset
, jiffies
) ||
940 (time_after(host
->last_reset
, jiffies
+ 20 * HZ
)))
941 host
->last_reset
= jiffies
;
945 if (reset_flags
& SCSI_RESET_SYNCHRONOUS
)
946 SCpnt
->flags
&= ~SYNC_RESET
;
949 printk("scsi reset function returned %d\n", temp
);
953 * Now figure out what we need to do, based upon
954 * what the low level driver said that it did.
955 * If the result is SCSI_RESET_SUCCESS, SCSI_RESET_PENDING,
956 * or SCSI_RESET_WAKEUP, then the low level driver did a
957 * bus device reset or bus reset, so we should go through
958 * and mark one or all of the devices on that bus
959 * as having been reset.
961 switch (temp
& SCSI_RESET_ACTION
) {
962 case SCSI_RESET_SUCCESS
:
963 if (temp
& SCSI_RESET_HOST_RESET
)
964 scsi_mark_host_reset(host
);
965 else if (temp
& SCSI_RESET_BUS_RESET
)
966 scsi_mark_bus_reset(host
, SCpnt
->channel
);
968 scsi_mark_device_reset(SCpnt
->device
);
969 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
| IN_RESET3
);
971 case SCSI_RESET_PENDING
:
972 if (temp
& SCSI_RESET_HOST_RESET
)
973 scsi_mark_host_reset(host
);
974 else if (temp
& SCSI_RESET_BUS_RESET
)
975 scsi_mark_bus_reset(host
, SCpnt
->channel
);
977 scsi_mark_device_reset(SCpnt
->device
);
978 case SCSI_RESET_NOT_RUNNING
:
980 case SCSI_RESET_PUNT
:
981 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
| IN_RESET3
);
982 scsi_request_sense(SCpnt
);
984 case SCSI_RESET_WAKEUP
:
985 if (temp
& SCSI_RESET_HOST_RESET
)
986 scsi_mark_host_reset(host
);
987 else if (temp
& SCSI_RESET_BUS_RESET
)
988 scsi_mark_bus_reset(host
, SCpnt
->channel
);
990 scsi_mark_device_reset(SCpnt
->device
);
991 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
| IN_RESET3
);
992 scsi_request_sense(SCpnt
);
994 * If a bus reset was performed, we
995 * need to wake up each and every command
996 * that was active on the bus or if it was a HBA
997 * reset all active commands on all channels
999 if (temp
& SCSI_RESET_HOST_RESET
) {
1000 for (SDpnt
= host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
1001 SCpnt1
= SDpnt
->device_queue
;
1003 if (SCpnt1
->request
.rq_status
!= RQ_INACTIVE
1005 scsi_request_sense(SCpnt1
);
1006 SCpnt1
= SCpnt1
->next
;
1009 } else if (temp
& SCSI_RESET_BUS_RESET
) {
1010 for (SDpnt
= host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
1011 SCpnt1
= SDpnt
->device_queue
;
1013 if (SCpnt1
->request
.rq_status
!= RQ_INACTIVE
1015 && SCpnt1
->channel
== SCpnt
->channel
)
1016 scsi_request_sense(SCpnt
);
1017 SCpnt1
= SCpnt1
->next
;
1022 case SCSI_RESET_SNOOZE
:
1023 /* In this case, we set the timeout field to 0
1024 * so that this command does not time out any more,
1025 * and we return 1 so that we get a message on the
1028 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
| IN_RESET3
);
1029 update_timeout(SCpnt
, 0);
1030 /* If you snooze, you lose... */
1031 case SCSI_RESET_ERROR
:
1042 * The strategy is to cause the timer code to call scsi_times_out()
1043 * when the soonest timeout is pending.
1044 * The arguments are used when we are queueing a new command, because
1045 * we do not want to subtract the time used from this time, but when we
1046 * set the timer, we want to take this value into account.
1049 int update_timeout(Scsi_Cmnd
* SCset
, int timeout
)
1054 * We are using the new error handling code to actually register/deregister
1055 * timers for timeout.
1058 if (!timer_pending(&SCset
->eh_timeout
)) {
1061 rtn
= SCset
->eh_timeout
.expires
- jiffies
;
1065 scsi_delete_timer(SCset
);
1067 scsi_add_timer(SCset
, timeout
, scsi_old_times_out
);
1075 * Overrides for Emacs so that we follow Linus's tabbing style.
1076 * Emacs will notice this stuff at the end of the file and automatically
1077 * adjust the settings for this buffer only. This must remain at the end
1079 * ---------------------------------------------------------------------------
1082 * c-brace-imaginary-offset: 0
1083 * c-brace-offset: -4
1084 * c-argdecl-indent: 4
1085 * c-label-offset: -4
1086 * c-continued-statement-offset: 4
1087 * c-continued-brace-offset: 0
1088 * indent-tabs-mode: nil