2 * scsi_obsolete.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@andante.org 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
);
88 extern int scsi_dispatch_cmd(Scsi_Cmnd
* SCpnt
);
90 #define SCSI_BLOCK(HOST) (HOST->can_queue && HOST->host_busy >= HOST->can_queue)
92 static unsigned char generic_sense
[6] =
93 {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
141 * This is our time out function, called when the timer expires for a
142 * given host adapter. It will attempt to abort the currently executing
143 * command, that failing perform a kernel panic.
146 void scsi_old_times_out(Scsi_Cmnd
* SCpnt
)
150 spin_lock_irqsave(&io_request_lock
, flags
);
152 /* Set the serial_number_at_timeout to the current serial_number */
153 SCpnt
->serial_number_at_timeout
= SCpnt
->serial_number
;
155 switch (SCpnt
->internal_timeout
& (IN_ABORT
| IN_RESET
| IN_RESET2
| IN_RESET3
)) {
163 if (!scsi_abort(SCpnt
, DID_TIME_OUT
))
166 printk("SCSI host %d abort (pid %ld) timed out - resetting\n",
167 SCpnt
->host
->host_no
, SCpnt
->pid
);
168 if (!scsi_reset(SCpnt
, SCSI_RESET_ASYNCHRONOUS
))
171 case (IN_ABORT
| IN_RESET
):
172 /* This might be controversial, but if there is a bus hang,
173 * you might conceivably want the machine up and running
174 * esp if you have an ide disk.
176 printk("SCSI host %d channel %d reset (pid %ld) timed out - "
178 SCpnt
->host
->host_no
, SCpnt
->channel
, SCpnt
->pid
);
179 SCpnt
->internal_timeout
&= ~IN_RESET
;
180 SCpnt
->internal_timeout
|= IN_RESET2
;
182 SCSI_RESET_ASYNCHRONOUS
| SCSI_RESET_SUGGEST_BUS_RESET
);
185 case (IN_ABORT
| IN_RESET2
):
186 /* Obviously the bus reset didn't work.
187 * Let's try even harder and call for an HBA reset.
188 * Maybe the HBA itself crashed and this will shake it loose.
190 printk("SCSI host %d reset (pid %ld) timed out - trying to shake it loose\n",
191 SCpnt
->host
->host_no
, SCpnt
->pid
);
192 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
);
193 SCpnt
->internal_timeout
|= IN_RESET3
;
195 SCSI_RESET_ASYNCHRONOUS
| SCSI_RESET_SUGGEST_HOST_RESET
);
199 printk("SCSI host %d reset (pid %ld) timed out again -\n",
200 SCpnt
->host
->host_no
, SCpnt
->pid
);
201 printk("probably an unrecoverable SCSI bus or device hang.\n");
205 spin_unlock_irqrestore(&io_request_lock
, flags
);
210 * From what I can find in scsi_obsolete.c, this function is only called
211 * by scsi_old_done and scsi_reset. Both of these functions run with the
212 * io_request_lock already held, so we need do nothing here about grabbing
215 static void scsi_request_sense(Scsi_Cmnd
* SCpnt
)
217 SCpnt
->flags
|= WAS_SENSE
| ASKED_FOR_SENSE
;
218 update_timeout(SCpnt
, SENSE_TIMEOUT
);
221 memcpy((void *) SCpnt
->cmnd
, (void *) generic_sense
,
222 sizeof(generic_sense
));
223 memset((void *) SCpnt
->sense_buffer
, 0,
224 sizeof(SCpnt
->sense_buffer
));
226 SCpnt
->cmnd
[1] = SCpnt
->lun
<< 5;
227 SCpnt
->cmnd
[4] = sizeof(SCpnt
->sense_buffer
);
229 SCpnt
->request_buffer
= &SCpnt
->sense_buffer
;
230 SCpnt
->request_bufflen
= sizeof(SCpnt
->sense_buffer
);
232 SCpnt
->cmd_len
= COMMAND_SIZE(SCpnt
->cmnd
[0]);
234 SCpnt
->sc_data_direction
= SCSI_DATA_READ
;
237 * Ugly, ugly. The newer interfaces all assume that the lock
238 * isn't held. Mustn't disappoint, or we deadlock the system.
240 spin_unlock_irq(&io_request_lock
);
241 scsi_dispatch_cmd(SCpnt
);
242 spin_lock_irq(&io_request_lock
);
248 static int check_sense(Scsi_Cmnd
* SCpnt
)
250 /* If there is no sense information, request it. If we have already
251 * requested it, there is no point in asking again - the firmware must
254 if (((SCpnt
->sense_buffer
[0] & 0x70) >> 4) != 7) {
255 if (!(SCpnt
->flags
& ASKED_FOR_SENSE
))
256 return SUGGEST_SENSE
;
258 return SUGGEST_RETRY
;
260 SCpnt
->flags
&= ~ASKED_FOR_SENSE
;
263 printk("scsi%d, channel%d : ", SCpnt
->host
->host_no
, SCpnt
->channel
);
264 print_sense("", SCpnt
);
267 if (SCpnt
->sense_buffer
[2] & 0xe0)
268 return SUGGEST_ABORT
;
270 switch (SCpnt
->sense_buffer
[2] & 0xf) {
273 case RECOVERED_ERROR
:
274 return SUGGEST_IS_OK
;
276 case ABORTED_COMMAND
:
277 return SUGGEST_RETRY
;
281 * If we are expecting a CC/UA because of a bus reset that we
282 * performed, treat this just as a retry. Otherwise this is
283 * information that we should pass up to the upper-level driver
284 * so that we can deal with it there.
286 if (SCpnt
->device
->expecting_cc_ua
) {
287 SCpnt
->device
->expecting_cc_ua
= 0;
288 return SUGGEST_RETRY
;
290 return SUGGEST_ABORT
;
292 /* these three are not supported */
294 case VOLUME_OVERFLOW
:
298 return SUGGEST_REMAP
;
302 case ILLEGAL_REQUEST
:
304 return SUGGEST_ABORT
;
308 /* This function is the mid-level interrupt routine, which decides how
309 * to handle error conditions. Each invocation of this function must
310 * do one and *only* one of the following:
312 * (1) Call last_cmnd[host].done. This is done for fatal errors and
313 * normal completion, and indicates that the handling for this
314 * request is complete.
315 * (2) Call internal_cmnd to requeue the command. This will result in
316 * scsi_done being called again when the retry is complete.
317 * (3) Call scsi_request_sense. This asks the host adapter/drive for
318 * more information about the error condition. When the information
319 * is available, scsi_done will be called again.
320 * (4) Call reset(). This is sort of a last resort, and the idea is that
321 * this may kick things loose and get the drive working again. reset()
322 * automatically calls scsi_request_sense, and thus scsi_done will be
323 * called again once the reset is complete.
325 * If none of the above actions are taken, the drive in question
326 * will hang. If more than one of the above actions are taken by
327 * scsi_done, then unpredictable behavior will result.
329 void scsi_old_done(Scsi_Cmnd
* SCpnt
)
335 struct Scsi_Host
*host
= SCpnt
->host
;
336 Scsi_Device
* device
= SCpnt
->device
;
337 int result
= SCpnt
->result
;
338 SCpnt
->serial_number
= 0;
339 SCpnt
->serial_number_at_timeout
= 0;
340 oldto
= update_timeout(SCpnt
, 0);
344 printk("Non-zero result in scsi_done %x %d:%d\n",
345 result
, SCpnt
->target
, SCpnt
->lun
);
348 /* If we requested an abort, (and we got it) then fix up the return
351 if (host_byte(result
) == DID_ABORT
&& SCpnt
->abort_reason
)
352 SCpnt
->result
= result
= (result
& 0xff00ffff) |
353 (SCpnt
->abort_reason
<< 16);
356 #define CMD_FINISHED 0
362 printk("In scsi_done(host = %d, result = %06x)\n", host
->host_no
, result
);
365 if (SCpnt
->flags
& SYNC_RESET
) {
367 * The behaviou of scsi_reset(SYNC) was changed in 2.1.? .
368 * The scsi mid-layer does a REDO after every sync reset, the driver
369 * must not do that any more. In order to prevent old drivers from
370 * crashing, all scsi_done() calls during sync resets are ignored.
372 printk("scsi%d: device driver called scsi_done() "
373 "for a synchronous reset.\n", SCpnt
->host
->host_no
);
376 if (SCpnt
->flags
& WAS_SENSE
) {
377 SCpnt
->use_sg
= SCpnt
->old_use_sg
;
378 SCpnt
->cmd_len
= SCpnt
->old_cmd_len
;
379 SCpnt
->sc_data_direction
= SCpnt
->sc_old_data_direction
;
380 SCpnt
->underflow
= SCpnt
->old_underflow
;
382 switch (host_byte(result
)) {
384 if (status_byte(result
) && (SCpnt
->flags
& WAS_SENSE
))
385 /* Failed to obtain sense information */
387 SCpnt
->flags
&= ~WAS_SENSE
;
388 #if 0 /* This cannot possibly be correct. */
389 SCpnt
->internal_timeout
&= ~SENSE_TIMEOUT
;
392 if (!(SCpnt
->flags
& WAS_RESET
)) {
393 printk("scsi%d : channel %d target %d lun %d request sense"
394 " failed, performing reset.\n",
395 SCpnt
->host
->host_no
, SCpnt
->channel
, SCpnt
->target
,
397 scsi_reset(SCpnt
, SCSI_RESET_SYNCHRONOUS
);
401 exit
= (DRIVER_HARD
| SUGGEST_ABORT
);
402 status
= CMD_FINISHED
;
405 switch (msg_byte(result
)) {
406 case COMMAND_COMPLETE
:
407 switch (status_byte(result
)) {
409 if (SCpnt
->flags
& WAS_SENSE
) {
411 printk("In scsi_done, GOOD status, COMMAND COMPLETE, "
412 "parsing sense information.\n");
414 SCpnt
->flags
&= ~WAS_SENSE
;
415 #if 0 /* This cannot possibly be correct. */
416 SCpnt
->internal_timeout
&= ~SENSE_TIMEOUT
;
419 switch (checked
= check_sense(SCpnt
)) {
423 printk("NO SENSE. status = REDO\n");
425 update_timeout(SCpnt
, oldto
);
432 printk("SENSE SUGGEST REMAP - status = CMD_FINISHED\n");
434 status
= CMD_FINISHED
;
435 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
439 printk("SENSE SUGGEST RETRY - status = MAYREDO\n");
442 exit
= DRIVER_SENSE
| SUGGEST_RETRY
;
446 printk("SENSE SUGGEST ABORT - status = CMD_FINISHED");
448 status
= CMD_FINISHED
;
449 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
452 printk("Internal error %s %d \n", __FILE__
,
459 printk("COMMAND COMPLETE message returned, "
460 "status = CMD_FINISHED. \n");
463 status
= CMD_FINISHED
;
467 case CHECK_CONDITION
:
468 case COMMAND_TERMINATED
:
469 switch (check_sense(SCpnt
)) {
471 update_timeout(SCpnt
, oldto
);
475 status
= CMD_FINISHED
;
476 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
480 exit
= DRIVER_SENSE
| SUGGEST_RETRY
;
483 status
= CMD_FINISHED
;
484 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
487 scsi_request_sense(SCpnt
);
494 case INTERMEDIATE_GOOD
:
495 case INTERMEDIATE_C_GOOD
:
500 update_timeout(SCpnt
, oldto
);
504 case RESERVATION_CONFLICT
:
505 printk("scsi%d, channel %d : RESERVATION CONFLICT performing"
506 " reset.\n", SCpnt
->host
->host_no
, SCpnt
->channel
);
507 scsi_reset(SCpnt
, SCSI_RESET_SYNCHRONOUS
);
511 printk("Internal error %s %d \n"
512 "status byte = %d \n", __FILE__
,
513 __LINE__
, status_byte(result
));
518 panic("scsi: unsupported message byte %d received\n",
524 printk("Host returned DID_TIME_OUT - ");
527 if (SCpnt
->flags
& WAS_TIMEDOUT
) {
529 printk("Aborting\n");
532 Allow TEST_UNIT_READY and INQUIRY commands to timeout early
533 without causing resets. All other commands should be retried.
535 if (SCpnt
->cmnd
[0] != TEST_UNIT_READY
&&
536 SCpnt
->cmnd
[0] != INQUIRY
)
538 exit
= (DRIVER_TIMEOUT
| SUGGEST_ABORT
);
541 printk("Retrying.\n");
543 SCpnt
->flags
|= WAS_TIMEDOUT
;
544 SCpnt
->internal_timeout
&= ~IN_ABORT
;
554 printk("Couldn't connect.\n");
556 exit
= (DRIVER_HARD
| SUGGEST_ABORT
);
560 exit
= (DRIVER_HARD
| SUGGEST_ABORT
);
564 exit
= (DRIVER_INVALID
| SUGGEST_ABORT
);
567 if (SCpnt
->flags
& IS_RESETTING
) {
568 SCpnt
->flags
&= ~IS_RESETTING
;
572 if (msg_byte(result
) == GOOD
&&
573 status_byte(result
) == CHECK_CONDITION
) {
574 switch (check_sense(SCpnt
)) {
576 update_timeout(SCpnt
, oldto
);
582 exit
= DRIVER_SENSE
| SUGGEST_RETRY
;
585 status
= CMD_FINISHED
;
586 exit
= DRIVER_SENSE
| SUGGEST_ABORT
;
589 scsi_request_sense(SCpnt
);
595 exit
= SUGGEST_RETRY
;
599 exit
= (DRIVER_ERROR
| SUGGEST_DIE
);
608 printk("In MAYREDO, allowing %d retries, have %d\n",
609 SCpnt
->allowed
, SCpnt
->retries
);
611 if ((++SCpnt
->retries
) < SCpnt
->allowed
) {
612 if ((SCpnt
->retries
>= (SCpnt
->allowed
>> 1))
613 && !(SCpnt
->host
->resetting
&& time_before(jiffies
, SCpnt
->host
->last_reset
+ MIN_RESET_PERIOD
))
614 && !(SCpnt
->flags
& WAS_RESET
)) {
615 printk("scsi%d channel %d : resetting for second half of retries.\n",
616 SCpnt
->host
->host_no
, SCpnt
->channel
);
617 scsi_reset(SCpnt
, SCSI_RESET_SYNCHRONOUS
);
618 /* fall through to REDO */
621 status
= CMD_FINISHED
;
624 /* fall through to REDO */
628 if (SCpnt
->flags
& WAS_SENSE
)
629 scsi_request_sense(SCpnt
);
631 memcpy((void *) SCpnt
->cmnd
,
632 (void *) SCpnt
->data_cmnd
,
633 sizeof(SCpnt
->data_cmnd
));
634 memset((void *) SCpnt
->sense_buffer
, 0,
635 sizeof(SCpnt
->sense_buffer
));
636 SCpnt
->request_buffer
= SCpnt
->buffer
;
637 SCpnt
->request_bufflen
= SCpnt
->bufflen
;
638 SCpnt
->use_sg
= SCpnt
->old_use_sg
;
639 SCpnt
->cmd_len
= SCpnt
->old_cmd_len
;
640 SCpnt
->sc_data_direction
= SCpnt
->sc_old_data_direction
;
641 SCpnt
->underflow
= SCpnt
->old_underflow
;
644 * Ugly, ugly. The newer interfaces all
645 * assume that the lock isn't held. Mustn't
646 * disappoint, or we deadlock the system.
648 spin_unlock_irq(&io_request_lock
);
649 scsi_dispatch_cmd(SCpnt
);
650 spin_lock_irq(&io_request_lock
);
657 if (status
== CMD_FINISHED
) {
660 printk("Calling done function - at address %p\n", SCpnt
->done
);
662 host
->host_busy
--; /* Indicate that we are free */
663 device
->device_busy
--; /* Decrement device usage counter. */
665 SCpnt
->result
= result
| ((exit
& 0xff) << 24);
666 SCpnt
->use_sg
= SCpnt
->old_use_sg
;
667 SCpnt
->cmd_len
= SCpnt
->old_cmd_len
;
668 SCpnt
->sc_data_direction
= SCpnt
->sc_old_data_direction
;
669 SCpnt
->underflow
= SCpnt
->old_underflow
;
671 * The upper layers assume the lock isn't held. We mustn't
672 * disappoint them. When the new error handling code is in
673 * use, the upper code is run from a bottom half handler, so
676 spin_unlock_irq(&io_request_lock
);
677 SRpnt
= SCpnt
->sc_request
;
678 if( SRpnt
!= NULL
) {
679 SRpnt
->sr_result
= SRpnt
->sr_command
->result
;
680 if( SRpnt
->sr_result
!= 0 ) {
681 memcpy(SRpnt
->sr_sense_buffer
,
682 SRpnt
->sr_command
->sense_buffer
,
683 sizeof(SRpnt
->sr_sense_buffer
));
688 spin_lock_irq(&io_request_lock
);
697 * The scsi_abort function interfaces with the abort() function of the host
698 * we are aborting, and causes the current command to not complete. The
699 * caller should deal with any error messages or status returned on the
702 * This will not be called reentrantly for a given host.
706 * Since we're nice guys and specified that abort() and reset()
707 * can be non-reentrant. The internal_timeout flags are used for
712 static int scsi_abort(Scsi_Cmnd
* SCpnt
, int why
)
715 struct Scsi_Host
*host
= SCpnt
->host
;
720 * Protect against races here. If the command is done, or we are
721 * on a different command forget it.
723 if (SCpnt
->serial_number
!= SCpnt
->serial_number_at_timeout
) {
726 if (SCpnt
->internal_timeout
& IN_ABORT
) {
727 spin_unlock_irq(&io_request_lock
);
728 while (SCpnt
->internal_timeout
& IN_ABORT
)
730 spin_lock_irq(&io_request_lock
);
732 SCpnt
->internal_timeout
|= IN_ABORT
;
733 oldto
= update_timeout(SCpnt
, ABORT_TIMEOUT
);
735 if ((SCpnt
->flags
& IS_RESETTING
) && SCpnt
->device
->soft_reset
) {
736 /* OK, this command must have died when we did the
737 * reset. The device itself must have lied.
739 printk("Stale command on %d %d:%d appears to have died when"
740 " the bus was reset\n",
741 SCpnt
->channel
, SCpnt
->target
, SCpnt
->lun
);
743 if (!host
->host_busy
) {
744 SCpnt
->internal_timeout
&= ~IN_ABORT
;
745 update_timeout(SCpnt
, oldto
);
748 printk("scsi : aborting command due to timeout : pid %lu, scsi%d,"
749 " channel %d, id %d, lun %d ",
750 SCpnt
->pid
, SCpnt
->host
->host_no
, (int) SCpnt
->channel
,
751 (int) SCpnt
->target
, (int) SCpnt
->lun
);
752 print_command(SCpnt
->cmnd
);
753 if (SCpnt
->serial_number
!= SCpnt
->serial_number_at_timeout
)
755 SCpnt
->abort_reason
= why
;
756 switch (host
->hostt
->abort(SCpnt
)) {
757 /* We do not know how to abort. Try waiting another
758 * time increment and see if this helps. Set the
759 * WAS_TIMEDOUT flag set so we do not try this twice
761 case SCSI_ABORT_BUSY
: /* Tough call - returning 1 from
764 case SCSI_ABORT_SNOOZE
:
765 if (why
== DID_TIME_OUT
) {
766 SCpnt
->internal_timeout
&= ~IN_ABORT
;
767 if (SCpnt
->flags
& WAS_TIMEDOUT
) {
768 return 1; /* Indicate we cannot handle this.
769 * We drop down into the reset handler
773 SCpnt
->flags
|= WAS_TIMEDOUT
;
774 oldto
= SCpnt
->timeout_per_command
;
775 update_timeout(SCpnt
, oldto
);
779 case SCSI_ABORT_PENDING
:
780 if (why
!= DID_TIME_OUT
) {
781 update_timeout(SCpnt
, oldto
);
784 case SCSI_ABORT_SUCCESS
:
785 /* We should have already aborted this one. No
786 * need to adjust timeout
788 SCpnt
->internal_timeout
&= ~IN_ABORT
;
790 case SCSI_ABORT_NOT_RUNNING
:
791 SCpnt
->internal_timeout
&= ~IN_ABORT
;
792 update_timeout(SCpnt
, 0);
794 case SCSI_ABORT_ERROR
:
796 SCpnt
->internal_timeout
&= ~IN_ABORT
;
804 /* Mark a single SCSI Device as having been reset. */
806 static inline void scsi_mark_device_reset(Scsi_Device
* Device
)
808 Device
->was_reset
= 1;
809 Device
->expecting_cc_ua
= 1;
813 /* Mark all SCSI Devices on a specific Host as having been reset. */
815 void scsi_mark_host_reset(struct Scsi_Host
*Host
)
820 for (SDpnt
= Host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
821 for (SCpnt
= SDpnt
->device_queue
; SCpnt
; SCpnt
= SCpnt
->next
)
822 scsi_mark_device_reset(SCpnt
->device
);
827 /* Mark all SCSI Devices on a specific Host Bus as having been reset. */
829 static void scsi_mark_bus_reset(struct Scsi_Host
*Host
, int channel
)
834 for (SDpnt
= Host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
835 for (SCpnt
= SDpnt
->device_queue
; SCpnt
; SCpnt
= SCpnt
->next
)
836 if (SCpnt
->channel
== channel
)
837 scsi_mark_device_reset(SCpnt
->device
);
842 static int scsi_reset(Scsi_Cmnd
* SCpnt
, unsigned int reset_flags
)
847 struct Scsi_Host
*host
= SCpnt
->host
;
849 printk("SCSI bus is being reset for host %d channel %d.\n",
850 host
->host_no
, SCpnt
->channel
);
854 * First of all, we need to make a recommendation to the low-level
855 * driver as to whether a BUS_DEVICE_RESET should be performed,
856 * or whether we should do a full BUS_RESET. There is no simple
857 * algorithm here - we basically use a series of heuristics
858 * to determine what we should do.
860 SCpnt
->host
->suggest_bus_reset
= FALSE
;
863 * First see if all of the active devices on the bus have
864 * been jammed up so that we are attempting resets. If so,
865 * then suggest a bus reset. Forcing a bus reset could
866 * result in some race conditions, but no more than
867 * you would usually get with timeouts. We will cross
868 * that bridge when we come to it.
870 * This is actually a pretty bad idea, since a sequence of
871 * commands will often timeout together and this will cause a
872 * Bus Device Reset followed immediately by a SCSI Bus Reset.
873 * If all of the active devices really are jammed up, the
874 * Bus Device Reset will quickly timeout and scsi_times_out
875 * will follow up with a SCSI Bus Reset anyway.
877 SCpnt1
= host
->host_queue
;
879 if (SCpnt1
->request
.rq_status
!= RQ_INACTIVE
880 && (SCpnt1
->flags
& (WAS_RESET
| IS_RESETTING
)) == 0)
882 SCpnt1
= SCpnt1
->next
;
884 if (SCpnt1
== NULL
) {
885 reset_flags
|= SCSI_RESET_SUGGEST_BUS_RESET
;
888 * If the code that called us is suggesting a hard reset, then
889 * definitely request it. This usually occurs because a
890 * BUS_DEVICE_RESET times out.
892 * Passing reset_flags along takes care of this automatically.
894 if (reset_flags
& SCSI_RESET_SUGGEST_BUS_RESET
) {
895 SCpnt
->host
->suggest_bus_reset
= TRUE
;
902 * Protect against races here. If the command is done, or we are
903 * on a different command forget it.
905 if (reset_flags
& SCSI_RESET_ASYNCHRONOUS
)
906 if (SCpnt
->serial_number
!= SCpnt
->serial_number_at_timeout
) {
909 if (SCpnt
->internal_timeout
& IN_RESET
) {
910 spin_unlock_irq(&io_request_lock
);
911 while (SCpnt
->internal_timeout
& IN_RESET
)
913 spin_lock_irq(&io_request_lock
);
915 SCpnt
->internal_timeout
|= IN_RESET
;
916 update_timeout(SCpnt
, RESET_TIMEOUT
);
918 if (reset_flags
& SCSI_RESET_SYNCHRONOUS
)
919 SCpnt
->flags
|= SYNC_RESET
;
920 if (host
->host_busy
) {
921 for (SDpnt
= host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
922 SCpnt1
= SDpnt
->device_queue
;
924 if (SCpnt1
->request
.rq_status
!= RQ_INACTIVE
) {
926 if (!(SCpnt1
->flags
& IS_RESETTING
) &&
927 !(SCpnt1
->internal_timeout
& IN_ABORT
))
928 scsi_abort(SCpnt1
, DID_RESET
);
930 SCpnt1
->flags
|= (WAS_RESET
| IS_RESETTING
);
932 SCpnt1
= SCpnt1
->next
;
936 host
->last_reset
= jiffies
;
939 * I suppose that the host reset callback will not play
940 * with the resetting field. We have just set the resetting
943 temp
= host
->hostt
->reset(SCpnt
, reset_flags
);
945 This test allows the driver to introduce an additional bus
946 settle time delay by setting last_reset up to 20 seconds in
947 the future. In the normal case where the driver does not
948 modify last_reset, it must be assumed that the actual bus
949 reset occurred immediately prior to the return to this code,
950 and so last_reset must be updated to the current time, so
951 that the delay in internal_cmnd will guarantee at least a
952 MIN_RESET_DELAY bus settle time.
954 if (host
->last_reset
- jiffies
> 20UL * HZ
)
955 host
->last_reset
= jiffies
;
958 host
->last_reset
= jiffies
;
960 SCpnt
->flags
|= (WAS_RESET
| IS_RESETTING
);
962 * I suppose that the host reset callback will not play
963 * with the resetting field. We have just set the resetting
966 temp
= host
->hostt
->reset(SCpnt
, reset_flags
);
967 if (time_before(host
->last_reset
, jiffies
) ||
968 (time_after(host
->last_reset
, jiffies
+ 20 * HZ
)))
969 host
->last_reset
= jiffies
;
972 if (reset_flags
& SCSI_RESET_SYNCHRONOUS
)
973 SCpnt
->flags
&= ~SYNC_RESET
;
976 printk("scsi reset function returned %d\n", temp
);
980 * Now figure out what we need to do, based upon
981 * what the low level driver said that it did.
982 * If the result is SCSI_RESET_SUCCESS, SCSI_RESET_PENDING,
983 * or SCSI_RESET_WAKEUP, then the low level driver did a
984 * bus device reset or bus reset, so we should go through
985 * and mark one or all of the devices on that bus
986 * as having been reset.
988 switch (temp
& SCSI_RESET_ACTION
) {
989 case SCSI_RESET_SUCCESS
:
990 if (temp
& SCSI_RESET_HOST_RESET
)
991 scsi_mark_host_reset(host
);
992 else if (temp
& SCSI_RESET_BUS_RESET
)
993 scsi_mark_bus_reset(host
, SCpnt
->channel
);
995 scsi_mark_device_reset(SCpnt
->device
);
996 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
| IN_RESET3
);
998 case SCSI_RESET_PENDING
:
999 if (temp
& SCSI_RESET_HOST_RESET
)
1000 scsi_mark_host_reset(host
);
1001 else if (temp
& SCSI_RESET_BUS_RESET
)
1002 scsi_mark_bus_reset(host
, SCpnt
->channel
);
1004 scsi_mark_device_reset(SCpnt
->device
);
1005 case SCSI_RESET_NOT_RUNNING
:
1007 case SCSI_RESET_PUNT
:
1008 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
| IN_RESET3
);
1009 scsi_request_sense(SCpnt
);
1011 case SCSI_RESET_WAKEUP
:
1012 if (temp
& SCSI_RESET_HOST_RESET
)
1013 scsi_mark_host_reset(host
);
1014 else if (temp
& SCSI_RESET_BUS_RESET
)
1015 scsi_mark_bus_reset(host
, SCpnt
->channel
);
1017 scsi_mark_device_reset(SCpnt
->device
);
1018 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
| IN_RESET3
);
1019 scsi_request_sense(SCpnt
);
1021 * If a bus reset was performed, we
1022 * need to wake up each and every command
1023 * that was active on the bus or if it was a HBA
1024 * reset all active commands on all channels
1026 if (temp
& SCSI_RESET_HOST_RESET
) {
1027 for (SDpnt
= host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
1028 SCpnt1
= SDpnt
->device_queue
;
1030 if (SCpnt1
->request
.rq_status
!= RQ_INACTIVE
1032 scsi_request_sense(SCpnt1
);
1033 SCpnt1
= SCpnt1
->next
;
1036 } else if (temp
& SCSI_RESET_BUS_RESET
) {
1037 for (SDpnt
= host
->host_queue
; SDpnt
; SDpnt
= SDpnt
->next
) {
1038 SCpnt1
= SDpnt
->device_queue
;
1040 if (SCpnt1
->request
.rq_status
!= RQ_INACTIVE
1042 && SCpnt1
->channel
== SCpnt
->channel
)
1043 scsi_request_sense(SCpnt
);
1044 SCpnt1
= SCpnt1
->next
;
1049 case SCSI_RESET_SNOOZE
:
1050 /* In this case, we set the timeout field to 0
1051 * so that this command does not time out any more,
1052 * and we return 1 so that we get a message on the
1055 SCpnt
->internal_timeout
&= ~(IN_RESET
| IN_RESET2
| IN_RESET3
);
1056 update_timeout(SCpnt
, 0);
1057 /* If you snooze, you lose... */
1058 case SCSI_RESET_ERROR
:
1069 * The strategy is to cause the timer code to call scsi_times_out()
1070 * when the soonest timeout is pending.
1071 * The arguments are used when we are queueing a new command, because
1072 * we do not want to subtract the time used from this time, but when we
1073 * set the timer, we want to take this value into account.
1076 int update_timeout(Scsi_Cmnd
* SCset
, int timeout
)
1081 * We are using the new error handling code to actually register/deregister
1082 * timers for timeout.
1085 if (!timer_pending(&SCset
->eh_timeout
)) {
1088 rtn
= SCset
->eh_timeout
.expires
- jiffies
;
1092 scsi_delete_timer(SCset
);
1094 scsi_add_timer(SCset
, timeout
, scsi_old_times_out
);
1102 * Overrides for Emacs so that we follow Linus's tabbing style.
1103 * Emacs will notice this stuff at the end of the file and automatically
1104 * adjust the settings for this buffer only. This must remain at the end
1106 * ---------------------------------------------------------------------------
1109 * c-brace-imaginary-offset: 0
1110 * c-brace-offset: -4
1111 * c-argdecl-indent: 4
1112 * c-label-offset: -4
1113 * c-continued-statement-offset: 4
1114 * c-continued-brace-offset: 0
1115 * indent-tabs-mode: nil