ia64/xen-unstable

changeset 228:5636f106ea84

bitkeeper revision 1.86 (3e5642098LDC0gOvsZ9mA8en6CWGDw)

.del-scsi_obsolete.c~e09c2878e9b9eabb:
Delete: xen-2.4.16/drivers/scsi/scsi_obsolete.c
.del-scsi_module.c~41e587a3142bba30:
Delete: xen-2.4.16/drivers/scsi/scsi_module.c
author kaf24@labyrinth.cl.cam.ac.uk
date Fri Feb 21 15:13:13 2003 +0000 (2003-02-21)
parents ef5e27f96b09
children fa6d46f14a6e
files .rootkeys xen-2.4.16/drivers/scsi/scsi_module.c xen-2.4.16/drivers/scsi/scsi_obsolete.c
line diff
     1.1 --- a/.rootkeys	Fri Feb 21 15:10:37 2003 +0000
     1.2 +++ b/.rootkeys	Fri Feb 21 15:13:13 2003 +0000
     1.3 @@ -145,9 +145,7 @@ 3ddb79beDrImFCFGgB_GLgUbeuHjog xen-2.4.1
     1.4  3ddb79bepDvUltYDsInaUsH9lII9Sw xen-2.4.16/drivers/scsi/scsi_ioctl.c
     1.5  3ddb79berPStE_-ILQHgcl1BLDLywA xen-2.4.16/drivers/scsi/scsi_lib.c
     1.6  3ddb79beRXjB7_nNUbJMIRyjDmeByQ xen-2.4.16/drivers/scsi/scsi_merge.c
     1.7 -3ddb79beGNb7Es1bATZAGsPZEu5F2Q xen-2.4.16/drivers/scsi/scsi_module.c
     1.8  3e56412a_O2cnz-e36volrKvofGe-Q xen-2.4.16/drivers/scsi/scsi_module.c.inc
     1.9 -3ddb79beZ--AZB0twliIm3qmQJO8Zg xen-2.4.16/drivers/scsi/scsi_obsolete.c
    1.10  3ddb79beQgG_st0eBZUX8AQI7kBkHA xen-2.4.16/drivers/scsi/scsi_obsolete.h
    1.11  3ddb79beK65cNRldY0CFGXjZ3-A74Q xen-2.4.16/drivers/scsi/scsi_proc.c
    1.12  3ddb79beeIuwGDE0Ldl8wy6mt86Bag xen-2.4.16/drivers/scsi/scsi_queue.c
     2.1 --- a/xen-2.4.16/drivers/scsi/scsi_module.c	Fri Feb 21 15:10:37 2003 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,71 +0,0 @@
     2.4 -/*
     2.5 - *  scsi_module.c Copyright (1994, 1995) Eric Youngdale.
     2.6 - *
     2.7 - * Support for loading low-level scsi drivers using the linux kernel loadable
     2.8 - * module interface.
     2.9 - *
    2.10 - * To use, the host adapter should first define and initialize the variable
    2.11 - * driver_template (datatype Scsi_Host_Template), and then include this file.
    2.12 - * This should also be wrapped in a #ifdef MODULE/#endif.
    2.13 - *
    2.14 - * The low -level driver must also define a release function which will
    2.15 - * free any irq assignments, release any dma channels, release any I/O
    2.16 - * address space that might be reserved, and otherwise clean up after itself.
    2.17 - * The idea is that the same driver should be able to be reloaded without
    2.18 - * any difficulty.  This makes debugging new drivers easier, as you should
    2.19 - * be able to load the driver, test it, unload, modify and reload.
    2.20 - *
    2.21 - * One *very* important caveat.  If the driver may need to do DMA on the
    2.22 - * ISA bus, you must have unchecked_isa_dma set in the device template,
    2.23 - * even if this might be changed during the detect routine.  This is
    2.24 - * because the shpnt structure will be allocated in a special way so that
    2.25 - * it will be below the appropriate DMA limit - thus if your driver uses
    2.26 - * the hostdata field of shpnt, and the board must be able to access this
    2.27 - * via DMA, the shpnt structure must be in a DMA accessible region of
    2.28 - * memory.  This comment would be relevant for something like the buslogic
    2.29 - * driver where there are many boards, only some of which do DMA onto the
    2.30 - * ISA bus.  There is no convenient way of specifying whether the host
    2.31 - * needs to be in a ISA DMA accessible region of memory when you call
    2.32 - * scsi_register.
    2.33 - */
    2.34 -
    2.35 -#include <linux/module.h>
    2.36 -#include <linux/init.h>
    2.37 -
    2.38 -static int __init init_this_scsi_driver(void)
    2.39 -{
    2.40 -	driver_template.module = THIS_MODULE;
    2.41 -	scsi_register_module(MODULE_SCSI_HA, &driver_template);
    2.42 -	if (driver_template.present)
    2.43 -		return 0;
    2.44 -
    2.45 -	scsi_unregister_module(MODULE_SCSI_HA, &driver_template);
    2.46 -	return -ENODEV;
    2.47 -}
    2.48 -
    2.49 -static void __exit exit_this_scsi_driver(void)
    2.50 -{
    2.51 -	scsi_unregister_module(MODULE_SCSI_HA, &driver_template);
    2.52 -}
    2.53 -
    2.54 -module_init(init_this_scsi_driver);
    2.55 -module_exit(exit_this_scsi_driver);
    2.56 -
    2.57 -/*
    2.58 - * Overrides for Emacs so that we almost follow Linus's tabbing style.
    2.59 - * Emacs will notice this stuff at the end of the file and automatically
    2.60 - * adjust the settings for this buffer only.  This must remain at the end
    2.61 - * of the file.
    2.62 - * ---------------------------------------------------------------------------
    2.63 - * Local variables:
    2.64 - * c-indent-level: 4
    2.65 - * c-brace-imaginary-offset: 0
    2.66 - * c-brace-offset: -4
    2.67 - * c-argdecl-indent: 4
    2.68 - * c-label-offset: -4
    2.69 - * c-continued-statement-offset: 4
    2.70 - * c-continued-brace-offset: 0
    2.71 - * indent-tabs-mode: nil
    2.72 - * tab-width: 8
    2.73 - * End:
    2.74 - */
     3.1 --- a/xen-2.4.16/drivers/scsi/scsi_obsolete.c	Fri Feb 21 15:10:37 2003 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,1162 +0,0 @@
     3.4 -/*
     3.5 - *  scsi_obsolete.c Copyright (C) 1992 Drew Eckhardt
     3.6 - *         Copyright (C) 1993, 1994, 1995 Eric Youngdale
     3.7 - *
     3.8 - *  generic mid-level SCSI driver
     3.9 - *      Initial versions: Drew Eckhardt
    3.10 - *      Subsequent revisions: Eric Youngdale
    3.11 - *
    3.12 - *  <drew@colorado.edu>
    3.13 - *
    3.14 - *  Bug correction thanks go to :
    3.15 - *      Rik Faith <faith@cs.unc.edu>
    3.16 - *      Tommy Thorn <tthorn>
    3.17 - *      Thomas Wuensche <tw@fgb1.fgb.mw.tu-muenchen.de>
    3.18 - *
    3.19 - *  Modified by Eric Youngdale eric@andante.org to
    3.20 - *  add scatter-gather, multiple outstanding request, and other
    3.21 - *  enhancements.
    3.22 - *
    3.23 - *  Native multichannel, wide scsi, /proc/scsi and hot plugging
    3.24 - *  support added by Michael Neuffer <mike@i-connect.net>
    3.25 - *
    3.26 - *  Major improvements to the timeout, abort, and reset processing,
    3.27 - *  as well as performance modifications for large queue depths by
    3.28 - *  Leonard N. Zubkoff <lnz@dandelion.com>
    3.29 - *
    3.30 - *  Improved compatibility with 2.0 behaviour by Manfred Spraul
    3.31 - *  <masp0008@stud.uni-sb.de>
    3.32 - */
    3.33 -
    3.34 -/*
    3.35 - *#########################################################################
    3.36 - *#########################################################################
    3.37 - *#########################################################################
    3.38 - *#########################################################################
    3.39 - *              NOTE - NOTE - NOTE - NOTE - NOTE - NOTE - NOTE
    3.40 - *
    3.41 - *#########################################################################
    3.42 - *#########################################################################
    3.43 - *#########################################################################
    3.44 - *#########################################################################
    3.45 - *
    3.46 - * This file contains the 'old' scsi error handling.  It is only present
    3.47 - * while the new error handling code is being debugged, and while the low
    3.48 - * level drivers are being converted to use the new code.  Once the last
    3.49 - * driver uses the new code this *ENTIRE* file will be nuked.
    3.50 - */
    3.51 -
    3.52 -#define __NO_VERSION__
    3.53 -#include <linux/module.h>
    3.54 -
    3.55 -#include <linux/sched.h>
    3.56 -#include <linux/timer.h>
    3.57 -#include <linux/string.h>
    3.58 -#include <linux/slab.h>
    3.59 -#include <linux/ioport.h>
    3.60 -#include <linux/kernel.h>
    3.61 -#include <linux/stat.h>
    3.62 -#include <linux/blk.h>
    3.63 -#include <linux/interrupt.h>
    3.64 -#include <linux/delay.h>
    3.65 -
    3.66 -#include <asm/system.h>
    3.67 -#include <asm/irq.h>
    3.68 -#include <asm/dma.h>
    3.69 -
    3.70 -#include "scsi.h"
    3.71 -#include "hosts.h"
    3.72 -#include "constants.h"
    3.73 -
    3.74 -#undef USE_STATIC_SCSI_MEMORY
    3.75 -
    3.76 -/*
    3.77 -   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 $";
    3.78 - */
    3.79 -
    3.80 -
    3.81 -#define INTERNAL_ERROR (panic ("Internal error in file %s, line %d.\n", __FILE__, __LINE__))
    3.82 -
    3.83 -
    3.84 -static int scsi_abort(Scsi_Cmnd *, int code);
    3.85 -static int scsi_reset(Scsi_Cmnd *, unsigned int);
    3.86 -
    3.87 -extern void scsi_old_done(Scsi_Cmnd * SCpnt);
    3.88 -int update_timeout(Scsi_Cmnd *, int);
    3.89 -extern void scsi_old_times_out(Scsi_Cmnd * SCpnt);
    3.90 -
    3.91 -extern int scsi_dispatch_cmd(Scsi_Cmnd * SCpnt);
    3.92 -
    3.93 -#define SCSI_BLOCK(HOST) (HOST->can_queue && HOST->host_busy >= HOST->can_queue)
    3.94 -
    3.95 -static unsigned char generic_sense[6] =
    3.96 -{REQUEST_SENSE, 0, 0, 0, 255, 0};
    3.97 -
    3.98 -/*
    3.99 - *  This is the number  of clock ticks we should wait before we time out
   3.100 - *  and abort the command.  This is for  where the scsi.c module generates
   3.101 - *  the command, not where it originates from a higher level, in which
   3.102 - *  case the timeout is specified there.
   3.103 - *
   3.104 - *  ABORT_TIMEOUT and RESET_TIMEOUT are the timeouts for RESET and ABORT
   3.105 - *  respectively.
   3.106 - */
   3.107 -
   3.108 -#ifdef DEBUG_TIMEOUT
   3.109 -static void scsi_dump_status(void);
   3.110 -#endif
   3.111 -
   3.112 -
   3.113 -#ifdef DEBUG
   3.114 -#define SCSI_TIMEOUT (5*HZ)
   3.115 -#else
   3.116 -#define SCSI_TIMEOUT (2*HZ)
   3.117 -#endif
   3.118 -
   3.119 -#ifdef DEBUG
   3.120 -#define SENSE_TIMEOUT SCSI_TIMEOUT
   3.121 -#define ABORT_TIMEOUT SCSI_TIMEOUT
   3.122 -#define RESET_TIMEOUT SCSI_TIMEOUT
   3.123 -#else
   3.124 -#define SENSE_TIMEOUT (5*HZ/10)
   3.125 -#define RESET_TIMEOUT (5*HZ/10)
   3.126 -#define ABORT_TIMEOUT (5*HZ/10)
   3.127 -#endif
   3.128 -
   3.129 -
   3.130 -/* Do not call reset on error if we just did a reset within 15 sec. */
   3.131 -#define MIN_RESET_PERIOD (15*HZ)
   3.132 -
   3.133 -
   3.134 -
   3.135 -/*
   3.136 - *  Flag bits for the internal_timeout array
   3.137 - */
   3.138 -#define IN_ABORT  1
   3.139 -#define IN_RESET  2
   3.140 -#define IN_RESET2 4
   3.141 -#define IN_RESET3 8
   3.142 -
   3.143 -/*
   3.144 - * This is our time out function, called when the timer expires for a
   3.145 - * given host adapter.  It will attempt to abort the currently executing
   3.146 - * command, that failing perform a kernel panic.
   3.147 - */
   3.148 -
   3.149 -void scsi_old_times_out(Scsi_Cmnd * SCpnt)
   3.150 -{
   3.151 -	unsigned long flags;
   3.152 -
   3.153 -	spin_lock_irqsave(&io_request_lock, flags);
   3.154 -
   3.155 -	/* Set the serial_number_at_timeout to the current serial_number */
   3.156 -	SCpnt->serial_number_at_timeout = SCpnt->serial_number;
   3.157 -
   3.158 -	switch (SCpnt->internal_timeout & (IN_ABORT | IN_RESET | IN_RESET2 | IN_RESET3)) {
   3.159 -	case NORMAL_TIMEOUT:
   3.160 -		{
   3.161 -#ifdef DEBUG_TIMEOUT
   3.162 -			scsi_dump_status();
   3.163 -#endif
   3.164 -		}
   3.165 -
   3.166 -		if (!scsi_abort(SCpnt, DID_TIME_OUT))
   3.167 -			break;
   3.168 -	case IN_ABORT:
   3.169 -		printk("SCSI host %d abort (pid %ld) timed out - resetting\n",
   3.170 -		       SCpnt->host->host_no, SCpnt->pid);
   3.171 -		if (!scsi_reset(SCpnt, SCSI_RESET_ASYNCHRONOUS))
   3.172 -			break;
   3.173 -	case IN_RESET:
   3.174 -	case (IN_ABORT | IN_RESET):
   3.175 -		/* This might be controversial, but if there is a bus hang,
   3.176 -		 * you might conceivably want the machine up and running
   3.177 -		 * esp if you have an ide disk.
   3.178 -		 */
   3.179 -		printk("SCSI host %d channel %d reset (pid %ld) timed out - "
   3.180 -		       "trying harder\n",
   3.181 -		       SCpnt->host->host_no, SCpnt->channel, SCpnt->pid);
   3.182 -		SCpnt->internal_timeout &= ~IN_RESET;
   3.183 -		SCpnt->internal_timeout |= IN_RESET2;
   3.184 -		scsi_reset(SCpnt,
   3.185 -		 SCSI_RESET_ASYNCHRONOUS | SCSI_RESET_SUGGEST_BUS_RESET);
   3.186 -		break;
   3.187 -	case IN_RESET2:
   3.188 -	case (IN_ABORT | IN_RESET2):
   3.189 -		/* Obviously the bus reset didn't work.
   3.190 -		 * Let's try even harder and call for an HBA reset.
   3.191 -		 * Maybe the HBA itself crashed and this will shake it loose.
   3.192 -		 */
   3.193 -		printk("SCSI host %d reset (pid %ld) timed out - trying to shake it loose\n",
   3.194 -		       SCpnt->host->host_no, SCpnt->pid);
   3.195 -		SCpnt->internal_timeout &= ~(IN_RESET | IN_RESET2);
   3.196 -		SCpnt->internal_timeout |= IN_RESET3;
   3.197 -		scsi_reset(SCpnt,
   3.198 -		SCSI_RESET_ASYNCHRONOUS | SCSI_RESET_SUGGEST_HOST_RESET);
   3.199 -		break;
   3.200 -
   3.201 -	default:
   3.202 -		printk("SCSI host %d reset (pid %ld) timed out again -\n",
   3.203 -		       SCpnt->host->host_no, SCpnt->pid);
   3.204 -		printk("probably an unrecoverable SCSI bus or device hang.\n");
   3.205 -		break;
   3.206 -
   3.207 -	}
   3.208 -	spin_unlock_irqrestore(&io_request_lock, flags);
   3.209 -
   3.210 -}
   3.211 -
   3.212 -/*
   3.213 - *  From what I can find in scsi_obsolete.c, this function is only called
   3.214 - *  by scsi_old_done and scsi_reset.  Both of these functions run with the
   3.215 - *  io_request_lock already held, so we need do nothing here about grabbing
   3.216 - *  any locks.
   3.217 - */
   3.218 -static void scsi_request_sense(Scsi_Cmnd * SCpnt)
   3.219 -{
   3.220 -	SCpnt->flags |= WAS_SENSE | ASKED_FOR_SENSE;
   3.221 -	update_timeout(SCpnt, SENSE_TIMEOUT);
   3.222 -
   3.223 -
   3.224 -	memcpy((void *) SCpnt->cmnd, (void *) generic_sense,
   3.225 -	       sizeof(generic_sense));
   3.226 -	memset((void *) SCpnt->sense_buffer, 0,
   3.227 -	       sizeof(SCpnt->sense_buffer));
   3.228 -
   3.229 -	if (SCpnt->device->scsi_level <= SCSI_2)
   3.230 -		SCpnt->cmnd[1] = SCpnt->lun << 5;
   3.231 -	SCpnt->cmnd[4] = sizeof(SCpnt->sense_buffer);
   3.232 -
   3.233 -	SCpnt->request_buffer = &SCpnt->sense_buffer;
   3.234 -	SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
   3.235 -	SCpnt->use_sg = 0;
   3.236 -	SCpnt->cmd_len = COMMAND_SIZE(SCpnt->cmnd[0]);
   3.237 -	SCpnt->result = 0;
   3.238 -	SCpnt->sc_data_direction = SCSI_DATA_READ;
   3.239 -
   3.240 -        /*
   3.241 -         * Ugly, ugly.  The newer interfaces all assume that the lock
   3.242 -         * isn't held.  Mustn't disappoint, or we deadlock the system.
   3.243 -         */
   3.244 -        spin_unlock_irq(&io_request_lock);
   3.245 -	scsi_dispatch_cmd(SCpnt);
   3.246 -        spin_lock_irq(&io_request_lock);
   3.247 -}
   3.248 -
   3.249 -
   3.250 -
   3.251 -
   3.252 -static int check_sense(Scsi_Cmnd * SCpnt)
   3.253 -{
   3.254 -	/* If there is no sense information, request it.  If we have already
   3.255 -	 * requested it, there is no point in asking again - the firmware must
   3.256 -	 * be confused.
   3.257 -	 */
   3.258 -	if (((SCpnt->sense_buffer[0] & 0x70) >> 4) != 7) {
   3.259 -		if (!(SCpnt->flags & ASKED_FOR_SENSE))
   3.260 -			return SUGGEST_SENSE;
   3.261 -		else
   3.262 -			return SUGGEST_RETRY;
   3.263 -	}
   3.264 -	SCpnt->flags &= ~ASKED_FOR_SENSE;
   3.265 -
   3.266 -#ifdef DEBUG_INIT
   3.267 -	printk("scsi%d, channel%d : ", SCpnt->host->host_no, SCpnt->channel);
   3.268 -	print_sense("", SCpnt);
   3.269 -	printk("\n");
   3.270 -#endif
   3.271 -	if (SCpnt->sense_buffer[2] & 0xe0)
   3.272 -		return SUGGEST_ABORT;
   3.273 -
   3.274 -	switch (SCpnt->sense_buffer[2] & 0xf) {
   3.275 -	case NO_SENSE:
   3.276 -		return 0;
   3.277 -	case RECOVERED_ERROR:
   3.278 -		return SUGGEST_IS_OK;
   3.279 -
   3.280 -	case ABORTED_COMMAND:
   3.281 -		return SUGGEST_RETRY;
   3.282 -	case NOT_READY:
   3.283 -	case UNIT_ATTENTION:
   3.284 -		/*
   3.285 -		 * If we are expecting a CC/UA because of a bus reset that we
   3.286 -		 * performed, treat this just as a retry.  Otherwise this is
   3.287 -		 * information that we should pass up to the upper-level driver
   3.288 -		 * so that we can deal with it there.
   3.289 -		 */
   3.290 -		if (SCpnt->device->expecting_cc_ua) {
   3.291 -			SCpnt->device->expecting_cc_ua = 0;
   3.292 -			return SUGGEST_RETRY;
   3.293 -		}
   3.294 -		return SUGGEST_ABORT;
   3.295 -
   3.296 -		/* these three are not supported */
   3.297 -	case COPY_ABORTED:
   3.298 -	case VOLUME_OVERFLOW:
   3.299 -	case MISCOMPARE:
   3.300 -
   3.301 -	case MEDIUM_ERROR:
   3.302 -		return SUGGEST_REMAP;
   3.303 -	case BLANK_CHECK:
   3.304 -	case DATA_PROTECT:
   3.305 -	case HARDWARE_ERROR:
   3.306 -	case ILLEGAL_REQUEST:
   3.307 -	default:
   3.308 -		return SUGGEST_ABORT;
   3.309 -	}
   3.310 -}
   3.311 -
   3.312 -/* This function is the mid-level interrupt routine, which decides how
   3.313 - *  to handle error conditions.  Each invocation of this function must
   3.314 - *  do one and *only* one of the following:
   3.315 - *
   3.316 - *  (1) Call last_cmnd[host].done.  This is done for fatal errors and
   3.317 - *      normal completion, and indicates that the handling for this
   3.318 - *      request is complete.
   3.319 - *  (2) Call internal_cmnd to requeue the command.  This will result in
   3.320 - *      scsi_done being called again when the retry is complete.
   3.321 - *  (3) Call scsi_request_sense.  This asks the host adapter/drive for
   3.322 - *      more information about the error condition.  When the information
   3.323 - *      is available, scsi_done will be called again.
   3.324 - *  (4) Call reset().  This is sort of a last resort, and the idea is that
   3.325 - *      this may kick things loose and get the drive working again.  reset()
   3.326 - *      automatically calls scsi_request_sense, and thus scsi_done will be
   3.327 - *      called again once the reset is complete.
   3.328 - *
   3.329 - *      If none of the above actions are taken, the drive in question
   3.330 - *      will hang. If more than one of the above actions are taken by
   3.331 - *      scsi_done, then unpredictable behavior will result.
   3.332 - */
   3.333 -void scsi_old_done(Scsi_Cmnd * SCpnt)
   3.334 -{
   3.335 -	int status = 0;
   3.336 -	int exit = 0;
   3.337 -	int checked;
   3.338 -	int oldto;
   3.339 -	struct Scsi_Host *host = SCpnt->host;
   3.340 -        Scsi_Device * device = SCpnt->device;
   3.341 -	int result = SCpnt->result;
   3.342 -	SCpnt->serial_number = 0;
   3.343 -	SCpnt->serial_number_at_timeout = 0;
   3.344 -	oldto = update_timeout(SCpnt, 0);
   3.345 -
   3.346 -#ifdef DEBUG_TIMEOUT
   3.347 -	if (result)
   3.348 -		printk("Non-zero result in scsi_done %x %d:%d\n",
   3.349 -		       result, SCpnt->target, SCpnt->lun);
   3.350 -#endif
   3.351 -
   3.352 -	/* If we requested an abort, (and we got it) then fix up the return
   3.353 -	 *  status to say why
   3.354 -	 */
   3.355 -	if (host_byte(result) == DID_ABORT && SCpnt->abort_reason)
   3.356 -		SCpnt->result = result = (result & 0xff00ffff) |
   3.357 -		    (SCpnt->abort_reason << 16);
   3.358 -
   3.359 -
   3.360 -#define CMD_FINISHED 0
   3.361 -#define MAYREDO  1
   3.362 -#define REDO     3
   3.363 -#define PENDING  4
   3.364 -
   3.365 -#ifdef DEBUG
   3.366 -	printk("In scsi_done(host = %d, result = %06x)\n", host->host_no, result);
   3.367 -#endif
   3.368 -
   3.369 -	if (SCpnt->flags & SYNC_RESET) {
   3.370 -		/*
   3.371 -		   * The behaviou of scsi_reset(SYNC) was changed in 2.1.? .
   3.372 -		   * The scsi mid-layer does a REDO after every sync reset, the driver
   3.373 -		   * must not do that any more. In order to prevent old drivers from
   3.374 -		   * crashing, all scsi_done() calls during sync resets are ignored.
   3.375 -		 */
   3.376 -		printk("scsi%d: device driver called scsi_done() "
   3.377 -		       "for a synchronous reset.\n", SCpnt->host->host_no);
   3.378 -		return;
   3.379 -	}
   3.380 -	if (SCpnt->flags & WAS_SENSE) {
   3.381 -		SCpnt->use_sg = SCpnt->old_use_sg;
   3.382 -		SCpnt->cmd_len = SCpnt->old_cmd_len;
   3.383 -		SCpnt->sc_data_direction = SCpnt->sc_old_data_direction;
   3.384 -		SCpnt->underflow = SCpnt->old_underflow;
   3.385 -	}
   3.386 -	switch (host_byte(result)) {
   3.387 -	case DID_OK:
   3.388 -		if (status_byte(result) && (SCpnt->flags & WAS_SENSE))
   3.389 -			/* Failed to obtain sense information */
   3.390 -		{
   3.391 -			SCpnt->flags &= ~WAS_SENSE;
   3.392 -#if 0				/* This cannot possibly be correct. */
   3.393 -			SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
   3.394 -#endif
   3.395 -
   3.396 -			if (!(SCpnt->flags & WAS_RESET)) {
   3.397 -				printk("scsi%d : channel %d target %d lun %d request sense"
   3.398 -				       " failed, performing reset.\n",
   3.399 -				       SCpnt->host->host_no, SCpnt->channel, SCpnt->target,
   3.400 -				       SCpnt->lun);
   3.401 -				scsi_reset(SCpnt, SCSI_RESET_SYNCHRONOUS);
   3.402 -				status = REDO;
   3.403 -				break;
   3.404 -			} else {
   3.405 -				exit = (DRIVER_HARD | SUGGEST_ABORT);
   3.406 -				status = CMD_FINISHED;
   3.407 -			}
   3.408 -		} else
   3.409 -			switch (msg_byte(result)) {
   3.410 -			case COMMAND_COMPLETE:
   3.411 -				switch (status_byte(result)) {
   3.412 -				case GOOD:
   3.413 -					if (SCpnt->flags & WAS_SENSE) {
   3.414 -#ifdef DEBUG
   3.415 -						printk("In scsi_done, GOOD status, COMMAND COMPLETE, "
   3.416 -						       "parsing sense information.\n");
   3.417 -#endif
   3.418 -						SCpnt->flags &= ~WAS_SENSE;
   3.419 -#if 0				/* This cannot possibly be correct. */
   3.420 -						SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
   3.421 -#endif
   3.422 -
   3.423 -						switch (checked = check_sense(SCpnt)) {
   3.424 -						case SUGGEST_SENSE:
   3.425 -						case 0:
   3.426 -#ifdef DEBUG
   3.427 -							printk("NO SENSE.  status = REDO\n");
   3.428 -#endif
   3.429 -							update_timeout(SCpnt, oldto);
   3.430 -							status = REDO;
   3.431 -							break;
   3.432 -						case SUGGEST_IS_OK:
   3.433 -							break;
   3.434 -						case SUGGEST_REMAP:
   3.435 -#ifdef DEBUG
   3.436 -							printk("SENSE SUGGEST REMAP - status = CMD_FINISHED\n");
   3.437 -#endif
   3.438 -							status = CMD_FINISHED;
   3.439 -							exit = DRIVER_SENSE | SUGGEST_ABORT;
   3.440 -							break;
   3.441 -						case SUGGEST_RETRY:
   3.442 -#ifdef DEBUG
   3.443 -							printk("SENSE SUGGEST RETRY - status = MAYREDO\n");
   3.444 -#endif
   3.445 -							status = MAYREDO;
   3.446 -							exit = DRIVER_SENSE | SUGGEST_RETRY;
   3.447 -							break;
   3.448 -						case SUGGEST_ABORT:
   3.449 -#ifdef DEBUG
   3.450 -							printk("SENSE SUGGEST ABORT - status = CMD_FINISHED");
   3.451 -#endif
   3.452 -							status = CMD_FINISHED;
   3.453 -							exit = DRIVER_SENSE | SUGGEST_ABORT;
   3.454 -							break;
   3.455 -						default:
   3.456 -							printk("Internal error %s %d \n", __FILE__,
   3.457 -							       __LINE__);
   3.458 -						}
   3.459 -					}
   3.460 -					/* end WAS_SENSE */
   3.461 -					else {
   3.462 -#ifdef DEBUG
   3.463 -						printk("COMMAND COMPLETE message returned, "
   3.464 -						       "status = CMD_FINISHED. \n");
   3.465 -#endif
   3.466 -						exit = DRIVER_OK;
   3.467 -						status = CMD_FINISHED;
   3.468 -					}
   3.469 -					break;
   3.470 -
   3.471 -				case CHECK_CONDITION:
   3.472 -				case COMMAND_TERMINATED:
   3.473 -					switch (check_sense(SCpnt)) {
   3.474 -					case 0:
   3.475 -						update_timeout(SCpnt, oldto);
   3.476 -						status = REDO;
   3.477 -						break;
   3.478 -					case SUGGEST_REMAP:
   3.479 -						status = CMD_FINISHED;
   3.480 -						exit = DRIVER_SENSE | SUGGEST_ABORT;
   3.481 -						break;
   3.482 -					case SUGGEST_RETRY:
   3.483 -						status = MAYREDO;
   3.484 -						exit = DRIVER_SENSE | SUGGEST_RETRY;
   3.485 -						break;
   3.486 -					case SUGGEST_ABORT:
   3.487 -						status = CMD_FINISHED;
   3.488 -						exit = DRIVER_SENSE | SUGGEST_ABORT;
   3.489 -						break;
   3.490 -					case SUGGEST_SENSE:
   3.491 -						scsi_request_sense(SCpnt);
   3.492 -						status = PENDING;
   3.493 -						break;
   3.494 -					}
   3.495 -					break;
   3.496 -
   3.497 -				case CONDITION_GOOD:
   3.498 -				case INTERMEDIATE_GOOD:
   3.499 -				case INTERMEDIATE_C_GOOD:
   3.500 -					break;
   3.501 -
   3.502 -				case BUSY:
   3.503 -				case QUEUE_FULL:
   3.504 -					update_timeout(SCpnt, oldto);
   3.505 -					status = REDO;
   3.506 -					break;
   3.507 -
   3.508 -				case RESERVATION_CONFLICT:
   3.509 -					/*
   3.510 -					 * Most HAs will return an error for
   3.511 -					 * this, so usually reservation
   3.512 -					 * conflicts will  be processed under
   3.513 -					 * DID_ERROR code
   3.514 -					 */
   3.515 -					printk("scsi%d (%d,%d,%d) : RESERVATION CONFLICT\n", 
   3.516 -					       SCpnt->host->host_no, SCpnt->channel,
   3.517 -					       SCpnt->device->id, SCpnt->device->lun);
   3.518 -					status = CMD_FINISHED; /* returns I/O error */
   3.519 -					break;
   3.520 -                                        
   3.521 -				default:
   3.522 -					printk("Internal error %s %d \n"
   3.523 -					 "status byte = %d \n", __FILE__,
   3.524 -					  __LINE__, status_byte(result));
   3.525 -
   3.526 -				}
   3.527 -				break;
   3.528 -			default:
   3.529 -				panic("scsi: unsupported message byte %d received\n",
   3.530 -				      msg_byte(result));
   3.531 -			}
   3.532 -		break;
   3.533 -	case DID_TIME_OUT:
   3.534 -#ifdef DEBUG
   3.535 -		printk("Host returned DID_TIME_OUT - ");
   3.536 -#endif
   3.537 -
   3.538 -		if (SCpnt->flags & WAS_TIMEDOUT) {
   3.539 -#ifdef DEBUG
   3.540 -			printk("Aborting\n");
   3.541 -#endif
   3.542 -			/*
   3.543 -			   Allow TEST_UNIT_READY and INQUIRY commands to timeout early
   3.544 -			   without causing resets.  All other commands should be retried.
   3.545 -			 */
   3.546 -			if (SCpnt->cmnd[0] != TEST_UNIT_READY &&
   3.547 -			    SCpnt->cmnd[0] != INQUIRY)
   3.548 -				status = MAYREDO;
   3.549 -			exit = (DRIVER_TIMEOUT | SUGGEST_ABORT);
   3.550 -		} else {
   3.551 -#ifdef DEBUG
   3.552 -			printk("Retrying.\n");
   3.553 -#endif
   3.554 -			SCpnt->flags |= WAS_TIMEDOUT;
   3.555 -			SCpnt->internal_timeout &= ~IN_ABORT;
   3.556 -			status = REDO;
   3.557 -		}
   3.558 -		break;
   3.559 -	case DID_BUS_BUSY:
   3.560 -	case DID_PARITY:
   3.561 -		status = REDO;
   3.562 -		break;
   3.563 -	case DID_NO_CONNECT:
   3.564 -#ifdef DEBUG
   3.565 -		printk("Couldn't connect.\n");
   3.566 -#endif
   3.567 -		exit = (DRIVER_HARD | SUGGEST_ABORT);
   3.568 -		break;
   3.569 -	case DID_ERROR:
   3.570 -		if (msg_byte(result) == COMMAND_COMPLETE &&
   3.571 -		    status_byte(result) == RESERVATION_CONFLICT) {
   3.572 -			printk("scsi%d (%d,%d,%d) : RESERVATION CONFLICT\n", 
   3.573 -			       SCpnt->host->host_no, SCpnt->channel,
   3.574 -			       SCpnt->device->id, SCpnt->device->lun);
   3.575 -			status = CMD_FINISHED; /* returns I/O error */
   3.576 -			break;
   3.577 -		}
   3.578 -		status = MAYREDO;
   3.579 -		exit = (DRIVER_HARD | SUGGEST_ABORT);
   3.580 -		break;
   3.581 -	case DID_BAD_TARGET:
   3.582 -	case DID_ABORT:
   3.583 -		exit = (DRIVER_INVALID | SUGGEST_ABORT);
   3.584 -		break;
   3.585 -	case DID_RESET:
   3.586 -		if (SCpnt->flags & IS_RESETTING) {
   3.587 -			SCpnt->flags &= ~IS_RESETTING;
   3.588 -			status = REDO;
   3.589 -			break;
   3.590 -		}
   3.591 -		if (msg_byte(result) == GOOD &&
   3.592 -		    status_byte(result) == CHECK_CONDITION) {
   3.593 -			switch (check_sense(SCpnt)) {
   3.594 -			case 0:
   3.595 -				update_timeout(SCpnt, oldto);
   3.596 -				status = REDO;
   3.597 -				break;
   3.598 -			case SUGGEST_REMAP:
   3.599 -			case SUGGEST_RETRY:
   3.600 -				status = MAYREDO;
   3.601 -				exit = DRIVER_SENSE | SUGGEST_RETRY;
   3.602 -				break;
   3.603 -			case SUGGEST_ABORT:
   3.604 -				status = CMD_FINISHED;
   3.605 -				exit = DRIVER_SENSE | SUGGEST_ABORT;
   3.606 -				break;
   3.607 -			case SUGGEST_SENSE:
   3.608 -				scsi_request_sense(SCpnt);
   3.609 -				status = PENDING;
   3.610 -				break;
   3.611 -			}
   3.612 -		} else {
   3.613 -			status = REDO;
   3.614 -			exit = SUGGEST_RETRY;
   3.615 -		}
   3.616 -		break;
   3.617 -	default:
   3.618 -		exit = (DRIVER_ERROR | SUGGEST_DIE);
   3.619 -	}
   3.620 -
   3.621 -	switch (status) {
   3.622 -	case CMD_FINISHED:
   3.623 -	case PENDING:
   3.624 -		break;
   3.625 -	case MAYREDO:
   3.626 -#ifdef DEBUG
   3.627 -		printk("In MAYREDO, allowing %d retries, have %d\n",
   3.628 -		       SCpnt->allowed, SCpnt->retries);
   3.629 -#endif
   3.630 -		if ((++SCpnt->retries) < SCpnt->allowed) {
   3.631 -			if ((SCpnt->retries >= (SCpnt->allowed >> 1))
   3.632 -			    && !(SCpnt->host->resetting && time_before(jiffies, SCpnt->host->last_reset + MIN_RESET_PERIOD))
   3.633 -			    && !(SCpnt->flags & WAS_RESET)) {
   3.634 -				printk("scsi%d channel %d : resetting for second half of retries.\n",
   3.635 -				   SCpnt->host->host_no, SCpnt->channel);
   3.636 -				scsi_reset(SCpnt, SCSI_RESET_SYNCHRONOUS);
   3.637 -				/* fall through to REDO */
   3.638 -			}
   3.639 -		} else {
   3.640 -			status = CMD_FINISHED;
   3.641 -			break;
   3.642 -		}
   3.643 -		/* fall through to REDO */
   3.644 -
   3.645 -	case REDO:
   3.646 -
   3.647 -		if (SCpnt->flags & WAS_SENSE)
   3.648 -			scsi_request_sense(SCpnt);
   3.649 -		else {
   3.650 -			memcpy((void *) SCpnt->cmnd,
   3.651 -			       (void *) SCpnt->data_cmnd,
   3.652 -			       sizeof(SCpnt->data_cmnd));
   3.653 -			memset((void *) SCpnt->sense_buffer, 0,
   3.654 -			       sizeof(SCpnt->sense_buffer));
   3.655 -			SCpnt->request_buffer = SCpnt->buffer;
   3.656 -			SCpnt->request_bufflen = SCpnt->bufflen;
   3.657 -			SCpnt->use_sg = SCpnt->old_use_sg;
   3.658 -			SCpnt->cmd_len = SCpnt->old_cmd_len;
   3.659 -			SCpnt->sc_data_direction = SCpnt->sc_old_data_direction;
   3.660 -			SCpnt->underflow = SCpnt->old_underflow;
   3.661 -			SCpnt->result = 0;
   3.662 -                        /*
   3.663 -                         * Ugly, ugly.  The newer interfaces all
   3.664 -                         * assume that the lock isn't held.  Mustn't
   3.665 -                         * disappoint, or we deadlock the system.  
   3.666 -                         */
   3.667 -                        spin_unlock_irq(&io_request_lock);
   3.668 -			scsi_dispatch_cmd(SCpnt);
   3.669 -                        spin_lock_irq(&io_request_lock);
   3.670 -		}
   3.671 -		break;
   3.672 -	default:
   3.673 -		INTERNAL_ERROR;
   3.674 -	}
   3.675 -
   3.676 -	if (status == CMD_FINISHED) {
   3.677 -		Scsi_Request *SRpnt;
   3.678 -#ifdef DEBUG
   3.679 -		printk("Calling done function - at address %p\n", SCpnt->done);
   3.680 -#endif
   3.681 -		host->host_busy--;	/* Indicate that we are free */
   3.682 -                device->device_busy--;	/* Decrement device usage counter. */
   3.683 -
   3.684 -		SCpnt->result = result | ((exit & 0xff) << 24);
   3.685 -		SCpnt->use_sg = SCpnt->old_use_sg;
   3.686 -		SCpnt->cmd_len = SCpnt->old_cmd_len;
   3.687 -		SCpnt->sc_data_direction = SCpnt->sc_old_data_direction;
   3.688 -		SCpnt->underflow = SCpnt->old_underflow;
   3.689 -                /*
   3.690 -                 * The upper layers assume the lock isn't held.  We mustn't
   3.691 -                 * disappoint them.  When the new error handling code is in
   3.692 -                 * use, the upper code is run from a bottom half handler, so
   3.693 -                 * it isn't an issue.
   3.694 -                 */
   3.695 -                spin_unlock_irq(&io_request_lock);
   3.696 -		SRpnt = SCpnt->sc_request;
   3.697 -		if( SRpnt != NULL ) {
   3.698 -			SRpnt->sr_result = SRpnt->sr_command->result;
   3.699 -			if( SRpnt->sr_result != 0 ) {
   3.700 -				memcpy(SRpnt->sr_sense_buffer,
   3.701 -				       SRpnt->sr_command->sense_buffer,
   3.702 -				       sizeof(SRpnt->sr_sense_buffer));
   3.703 -			}
   3.704 -		}
   3.705 -
   3.706 -		SCpnt->done(SCpnt);
   3.707 -                spin_lock_irq(&io_request_lock);
   3.708 -	}
   3.709 -#undef CMD_FINISHED
   3.710 -#undef REDO
   3.711 -#undef MAYREDO
   3.712 -#undef PENDING
   3.713 -}
   3.714 -
   3.715 -/*
   3.716 - * The scsi_abort function interfaces with the abort() function of the host
   3.717 - * we are aborting, and causes the current command to not complete.  The
   3.718 - * caller should deal with any error messages or status returned on the
   3.719 - * next call.
   3.720 - *
   3.721 - * This will not be called reentrantly for a given host.
   3.722 - */
   3.723 -
   3.724 -/*
   3.725 - * Since we're nice guys and specified that abort() and reset()
   3.726 - * can be non-reentrant.  The internal_timeout flags are used for
   3.727 - * this.
   3.728 - */
   3.729 -
   3.730 -
   3.731 -static int scsi_abort(Scsi_Cmnd * SCpnt, int why)
   3.732 -{
   3.733 -	int oldto;
   3.734 -	struct Scsi_Host *host = SCpnt->host;
   3.735 -
   3.736 -	while (1) {
   3.737 -
   3.738 -		/*
   3.739 -		 * Protect against races here.  If the command is done, or we are
   3.740 -		 * on a different command forget it.
   3.741 -		 */
   3.742 -		if (SCpnt->serial_number != SCpnt->serial_number_at_timeout) {
   3.743 -			return 0;
   3.744 -		}
   3.745 -		if (SCpnt->internal_timeout & IN_ABORT) {
   3.746 -			spin_unlock_irq(&io_request_lock);
   3.747 -			while (SCpnt->internal_timeout & IN_ABORT)
   3.748 -				barrier();
   3.749 -			spin_lock_irq(&io_request_lock);
   3.750 -		} else {
   3.751 -			SCpnt->internal_timeout |= IN_ABORT;
   3.752 -			oldto = update_timeout(SCpnt, ABORT_TIMEOUT);
   3.753 -
   3.754 -			if ((SCpnt->flags & IS_RESETTING) && SCpnt->device->soft_reset) {
   3.755 -				/* OK, this command must have died when we did the
   3.756 -				 *  reset.  The device itself must have lied.
   3.757 -				 */
   3.758 -				printk("Stale command on %d %d:%d appears to have died when"
   3.759 -				       " the bus was reset\n",
   3.760 -				       SCpnt->channel, SCpnt->target, SCpnt->lun);
   3.761 -			}
   3.762 -			if (!host->host_busy) {
   3.763 -				SCpnt->internal_timeout &= ~IN_ABORT;
   3.764 -				update_timeout(SCpnt, oldto);
   3.765 -				return 0;
   3.766 -			}
   3.767 -			printk("scsi : aborting command due to timeout : pid %lu, scsi%d,"
   3.768 -			       " channel %d, id %d, lun %d ",
   3.769 -			       SCpnt->pid, SCpnt->host->host_no, (int) SCpnt->channel,
   3.770 -			       (int) SCpnt->target, (int) SCpnt->lun);
   3.771 -			print_command(SCpnt->cmnd);
   3.772 -			if (SCpnt->serial_number != SCpnt->serial_number_at_timeout)
   3.773 -				return 0;
   3.774 -			SCpnt->abort_reason = why;
   3.775 -			switch (host->hostt->abort(SCpnt)) {
   3.776 -				/* We do not know how to abort.  Try waiting another
   3.777 -				 * time increment and see if this helps. Set the
   3.778 -				 * WAS_TIMEDOUT flag set so we do not try this twice
   3.779 -				 */
   3.780 -			case SCSI_ABORT_BUSY:	/* Tough call - returning 1 from
   3.781 -						 * this is too severe
   3.782 -						 */
   3.783 -			case SCSI_ABORT_SNOOZE:
   3.784 -				if (why == DID_TIME_OUT) {
   3.785 -					SCpnt->internal_timeout &= ~IN_ABORT;
   3.786 -					if (SCpnt->flags & WAS_TIMEDOUT) {
   3.787 -						return 1;	/* Indicate we cannot handle this.
   3.788 -								 * We drop down into the reset handler
   3.789 -								 * and try again
   3.790 -								 */
   3.791 -					} else {
   3.792 -						SCpnt->flags |= WAS_TIMEDOUT;
   3.793 -						oldto = SCpnt->timeout_per_command;
   3.794 -						update_timeout(SCpnt, oldto);
   3.795 -					}
   3.796 -				}
   3.797 -				return 0;
   3.798 -			case SCSI_ABORT_PENDING:
   3.799 -				if (why != DID_TIME_OUT) {
   3.800 -					update_timeout(SCpnt, oldto);
   3.801 -				}
   3.802 -				return 0;
   3.803 -			case SCSI_ABORT_SUCCESS:
   3.804 -				/* We should have already aborted this one.  No
   3.805 -				 * need to adjust timeout
   3.806 -				 */
   3.807 -				SCpnt->internal_timeout &= ~IN_ABORT;
   3.808 -				return 0;
   3.809 -			case SCSI_ABORT_NOT_RUNNING:
   3.810 -				SCpnt->internal_timeout &= ~IN_ABORT;
   3.811 -				update_timeout(SCpnt, 0);
   3.812 -				return 0;
   3.813 -			case SCSI_ABORT_ERROR:
   3.814 -			default:
   3.815 -				SCpnt->internal_timeout &= ~IN_ABORT;
   3.816 -				return 1;
   3.817 -			}
   3.818 -		}
   3.819 -	}
   3.820 -}
   3.821 -
   3.822 -
   3.823 -/* Mark a single SCSI Device as having been reset. */
   3.824 -
   3.825 -static inline void scsi_mark_device_reset(Scsi_Device * Device)
   3.826 -{
   3.827 -	Device->was_reset = 1;
   3.828 -	Device->expecting_cc_ua = 1;
   3.829 -}
   3.830 -
   3.831 -
   3.832 -/* Mark all SCSI Devices on a specific Host as having been reset. */
   3.833 -
   3.834 -void scsi_mark_host_reset(struct Scsi_Host *Host)
   3.835 -{
   3.836 -	Scsi_Cmnd *SCpnt;
   3.837 -	Scsi_Device *SDpnt;
   3.838 -
   3.839 -	for (SDpnt = Host->host_queue; SDpnt; SDpnt = SDpnt->next) {
   3.840 -		for (SCpnt = SDpnt->device_queue; SCpnt; SCpnt = SCpnt->next)
   3.841 -			scsi_mark_device_reset(SCpnt->device);
   3.842 -	}
   3.843 -}
   3.844 -
   3.845 -
   3.846 -/* Mark all SCSI Devices on a specific Host Bus as having been reset. */
   3.847 -
   3.848 -static void scsi_mark_bus_reset(struct Scsi_Host *Host, int channel)
   3.849 -{
   3.850 -	Scsi_Cmnd *SCpnt;
   3.851 -	Scsi_Device *SDpnt;
   3.852 -
   3.853 -	for (SDpnt = Host->host_queue; SDpnt; SDpnt = SDpnt->next) {
   3.854 -		for (SCpnt = SDpnt->device_queue; SCpnt; SCpnt = SCpnt->next)
   3.855 -			if (SCpnt->channel == channel)
   3.856 -				scsi_mark_device_reset(SCpnt->device);
   3.857 -	}
   3.858 -}
   3.859 -
   3.860 -
   3.861 -static int scsi_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
   3.862 -{
   3.863 -	int temp;
   3.864 -	Scsi_Cmnd *SCpnt1;
   3.865 -	Scsi_Device *SDpnt;
   3.866 -	struct Scsi_Host *host = SCpnt->host;
   3.867 -
   3.868 -	printk("SCSI bus is being reset for host %d channel %d.\n",
   3.869 -	       host->host_no, SCpnt->channel);
   3.870 -
   3.871 -#if 0
   3.872 -	/*
   3.873 -	 * First of all, we need to make a recommendation to the low-level
   3.874 -	 * driver as to whether a BUS_DEVICE_RESET should be performed,
   3.875 -	 * or whether we should do a full BUS_RESET.  There is no simple
   3.876 -	 * algorithm here - we basically use a series of heuristics
   3.877 -	 * to determine what we should do.
   3.878 -	 */
   3.879 -	SCpnt->host->suggest_bus_reset = FALSE;
   3.880 -
   3.881 -	/*
   3.882 -	 * First see if all of the active devices on the bus have
   3.883 -	 * been jammed up so that we are attempting resets.  If so,
   3.884 -	 * then suggest a bus reset.  Forcing a bus reset could
   3.885 -	 * result in some race conditions, but no more than
   3.886 -	 * you would usually get with timeouts.  We will cross
   3.887 -	 * that bridge when we come to it.
   3.888 -	 *
   3.889 -	 * This is actually a pretty bad idea, since a sequence of
   3.890 -	 * commands will often timeout together and this will cause a
   3.891 -	 * Bus Device Reset followed immediately by a SCSI Bus Reset.
   3.892 -	 * If all of the active devices really are jammed up, the
   3.893 -	 * Bus Device Reset will quickly timeout and scsi_times_out
   3.894 -	 * will follow up with a SCSI Bus Reset anyway.
   3.895 -	 */
   3.896 -	SCpnt1 = host->host_queue;
   3.897 -	while (SCpnt1) {
   3.898 -		if (SCpnt1->request.rq_status != RQ_INACTIVE
   3.899 -		    && (SCpnt1->flags & (WAS_RESET | IS_RESETTING)) == 0)
   3.900 -			break;
   3.901 -		SCpnt1 = SCpnt1->next;
   3.902 -	}
   3.903 -	if (SCpnt1 == NULL) {
   3.904 -		reset_flags |= SCSI_RESET_SUGGEST_BUS_RESET;
   3.905 -	}
   3.906 -	/*
   3.907 -	 * If the code that called us is suggesting a hard reset, then
   3.908 -	 * definitely request it.  This usually occurs because a
   3.909 -	 * BUS_DEVICE_RESET times out.
   3.910 -	 *
   3.911 -	 * Passing reset_flags along takes care of this automatically.
   3.912 -	 */
   3.913 -	if (reset_flags & SCSI_RESET_SUGGEST_BUS_RESET) {
   3.914 -		SCpnt->host->suggest_bus_reset = TRUE;
   3.915 -	}
   3.916 -#endif
   3.917 -
   3.918 -	while (1) {
   3.919 -
   3.920 -		/*
   3.921 -		 * Protect against races here.  If the command is done, or we are
   3.922 -		 * on a different command forget it.
   3.923 -		 */
   3.924 -		if (reset_flags & SCSI_RESET_ASYNCHRONOUS)
   3.925 -			if (SCpnt->serial_number != SCpnt->serial_number_at_timeout) {
   3.926 -				return 0;
   3.927 -			}
   3.928 -		if (SCpnt->internal_timeout & IN_RESET) {
   3.929 -			spin_unlock_irq(&io_request_lock);
   3.930 -			while (SCpnt->internal_timeout & IN_RESET)
   3.931 -				barrier();
   3.932 -			spin_lock_irq(&io_request_lock);
   3.933 -		} else {
   3.934 -			SCpnt->internal_timeout |= IN_RESET;
   3.935 -			update_timeout(SCpnt, RESET_TIMEOUT);
   3.936 -
   3.937 -			if (reset_flags & SCSI_RESET_SYNCHRONOUS)
   3.938 -				SCpnt->flags |= SYNC_RESET;
   3.939 -			if (host->host_busy) {
   3.940 -				for (SDpnt = host->host_queue; SDpnt; SDpnt = SDpnt->next) {
   3.941 -					SCpnt1 = SDpnt->device_queue;
   3.942 -					while (SCpnt1) {
   3.943 -						if (SCpnt1->request.rq_status != RQ_INACTIVE) {
   3.944 -#if 0
   3.945 -							if (!(SCpnt1->flags & IS_RESETTING) &&
   3.946 -							    !(SCpnt1->internal_timeout & IN_ABORT))
   3.947 -								scsi_abort(SCpnt1, DID_RESET);
   3.948 -#endif
   3.949 -							SCpnt1->flags |= (WAS_RESET | IS_RESETTING);
   3.950 -						}
   3.951 -						SCpnt1 = SCpnt1->next;
   3.952 -					}
   3.953 -				}
   3.954 -
   3.955 -				host->last_reset = jiffies;
   3.956 -				host->resetting = 1;
   3.957 -				/*
   3.958 -				 * I suppose that the host reset callback will not play
   3.959 -				 * with the resetting field. We have just set the resetting
   3.960 -				 * flag here. -arca
   3.961 -				 */
   3.962 -				temp = host->hostt->reset(SCpnt, reset_flags);
   3.963 -				/*
   3.964 -				   This test allows the driver to introduce an additional bus
   3.965 -				   settle time delay by setting last_reset up to 20 seconds in
   3.966 -				   the future.  In the normal case where the driver does not
   3.967 -				   modify last_reset, it must be assumed that the actual bus
   3.968 -				   reset occurred immediately prior to the return to this code,
   3.969 -				   and so last_reset must be updated to the current time, so
   3.970 -				   that the delay in internal_cmnd will guarantee at least a
   3.971 -				   MIN_RESET_DELAY bus settle time.
   3.972 -				 */
   3.973 -				if (host->last_reset - jiffies > 20UL * HZ)
   3.974 -					host->last_reset = jiffies;
   3.975 -			} else {
   3.976 -				host->host_busy++;
   3.977 -				host->last_reset = jiffies;
   3.978 -				host->resetting = 1;
   3.979 -				SCpnt->flags |= (WAS_RESET | IS_RESETTING);
   3.980 -				/*
   3.981 -				 * I suppose that the host reset callback will not play
   3.982 -				 * with the resetting field. We have just set the resetting
   3.983 -				 * flag here. -arca
   3.984 -				 */
   3.985 -				temp = host->hostt->reset(SCpnt, reset_flags);
   3.986 -				if (time_before(host->last_reset, jiffies) ||
   3.987 -				    (time_after(host->last_reset, jiffies + 20 * HZ)))
   3.988 -					host->last_reset = jiffies;
   3.989 -				host->host_busy--;
   3.990 -			}
   3.991 -			if (reset_flags & SCSI_RESET_SYNCHRONOUS)
   3.992 -				SCpnt->flags &= ~SYNC_RESET;
   3.993 -
   3.994 -#ifdef DEBUG
   3.995 -			printk("scsi reset function returned %d\n", temp);
   3.996 -#endif
   3.997 -
   3.998 -			/*
   3.999 -			 * Now figure out what we need to do, based upon
  3.1000 -			 * what the low level driver said that it did.
  3.1001 -			 * If the result is SCSI_RESET_SUCCESS, SCSI_RESET_PENDING,
  3.1002 -			 * or SCSI_RESET_WAKEUP, then the low level driver did a
  3.1003 -			 * bus device reset or bus reset, so we should go through
  3.1004 -			 * and mark one or all of the devices on that bus
  3.1005 -			 * as having been reset.
  3.1006 -			 */
  3.1007 -			switch (temp & SCSI_RESET_ACTION) {
  3.1008 -			case SCSI_RESET_SUCCESS:
  3.1009 -				if (temp & SCSI_RESET_HOST_RESET)
  3.1010 -					scsi_mark_host_reset(host);
  3.1011 -				else if (temp & SCSI_RESET_BUS_RESET)
  3.1012 -					scsi_mark_bus_reset(host, SCpnt->channel);
  3.1013 -				else
  3.1014 -					scsi_mark_device_reset(SCpnt->device);
  3.1015 -				SCpnt->internal_timeout &= ~(IN_RESET | IN_RESET2 | IN_RESET3);
  3.1016 -				return 0;
  3.1017 -			case SCSI_RESET_PENDING:
  3.1018 -				if (temp & SCSI_RESET_HOST_RESET)
  3.1019 -					scsi_mark_host_reset(host);
  3.1020 -				else if (temp & SCSI_RESET_BUS_RESET)
  3.1021 -					scsi_mark_bus_reset(host, SCpnt->channel);
  3.1022 -				else
  3.1023 -					scsi_mark_device_reset(SCpnt->device);
  3.1024 -			case SCSI_RESET_NOT_RUNNING:
  3.1025 -				return 0;
  3.1026 -			case SCSI_RESET_PUNT:
  3.1027 -				SCpnt->internal_timeout &= ~(IN_RESET | IN_RESET2 | IN_RESET3);
  3.1028 -				scsi_request_sense(SCpnt);
  3.1029 -				return 0;
  3.1030 -			case SCSI_RESET_WAKEUP:
  3.1031 -				if (temp & SCSI_RESET_HOST_RESET)
  3.1032 -					scsi_mark_host_reset(host);
  3.1033 -				else if (temp & SCSI_RESET_BUS_RESET)
  3.1034 -					scsi_mark_bus_reset(host, SCpnt->channel);
  3.1035 -				else
  3.1036 -					scsi_mark_device_reset(SCpnt->device);
  3.1037 -				SCpnt->internal_timeout &= ~(IN_RESET | IN_RESET2 | IN_RESET3);
  3.1038 -				scsi_request_sense(SCpnt);
  3.1039 -				/*
  3.1040 -				 * If a bus reset was performed, we
  3.1041 -				 * need to wake up each and every command
  3.1042 -				 * that was active on the bus or if it was a HBA
  3.1043 -				 * reset all active commands on all channels
  3.1044 -				 */
  3.1045 -				if (temp & SCSI_RESET_HOST_RESET) {
  3.1046 -					for (SDpnt = host->host_queue; SDpnt; SDpnt = SDpnt->next) {
  3.1047 -						SCpnt1 = SDpnt->device_queue;
  3.1048 -						while (SCpnt1) {
  3.1049 -							if (SCpnt1->request.rq_status != RQ_INACTIVE
  3.1050 -							    && SCpnt1 != SCpnt)
  3.1051 -								scsi_request_sense(SCpnt1);
  3.1052 -							SCpnt1 = SCpnt1->next;
  3.1053 -						}
  3.1054 -					}
  3.1055 -				} else if (temp & SCSI_RESET_BUS_RESET) {
  3.1056 -					for (SDpnt = host->host_queue; SDpnt; SDpnt = SDpnt->next) {
  3.1057 -						SCpnt1 = SDpnt->device_queue;
  3.1058 -						while (SCpnt1) {
  3.1059 -							if (SCpnt1->request.rq_status != RQ_INACTIVE
  3.1060 -							&& SCpnt1 != SCpnt
  3.1061 -							    && SCpnt1->channel == SCpnt->channel)
  3.1062 -								scsi_request_sense(SCpnt);
  3.1063 -							SCpnt1 = SCpnt1->next;
  3.1064 -						}
  3.1065 -					}
  3.1066 -				}
  3.1067 -				return 0;
  3.1068 -			case SCSI_RESET_SNOOZE:
  3.1069 -				/* In this case, we set the timeout field to 0
  3.1070 -				 * so that this command does not time out any more,
  3.1071 -				 * and we return 1 so that we get a message on the
  3.1072 -				 * screen.
  3.1073 -				 */
  3.1074 -				SCpnt->internal_timeout &= ~(IN_RESET | IN_RESET2 | IN_RESET3);
  3.1075 -				update_timeout(SCpnt, 0);
  3.1076 -				/* If you snooze, you lose... */
  3.1077 -			case SCSI_RESET_ERROR:
  3.1078 -			default:
  3.1079 -				return 1;
  3.1080 -			}
  3.1081 -
  3.1082 -			return temp;
  3.1083 -		}
  3.1084 -	}
  3.1085 -}
  3.1086 -
  3.1087 -/*
  3.1088 - * The strategy is to cause the timer code to call scsi_times_out()
  3.1089 - * when the soonest timeout is pending.
  3.1090 - * The arguments are used when we are queueing a new command, because
  3.1091 - * we do not want to subtract the time used from this time, but when we
  3.1092 - * set the timer, we want to take this value into account.
  3.1093 - */
  3.1094 -
  3.1095 -int update_timeout(Scsi_Cmnd * SCset, int timeout)
  3.1096 -{
  3.1097 -	int rtn;
  3.1098 -
  3.1099 -	/*
  3.1100 -	 * We are using the new error handling code to actually register/deregister
  3.1101 -	 * timers for timeout.
  3.1102 -	 */
  3.1103 -
  3.1104 -	if (!timer_pending(&SCset->eh_timeout)) {
  3.1105 -		rtn = 0;
  3.1106 -	} else {
  3.1107 -		rtn = SCset->eh_timeout.expires - jiffies;
  3.1108 -	}
  3.1109 -
  3.1110 -	if (timeout == 0) {
  3.1111 -		scsi_delete_timer(SCset);
  3.1112 -	} else {
  3.1113 -		scsi_add_timer(SCset, timeout, scsi_old_times_out);
  3.1114 -	}
  3.1115 -
  3.1116 -	return rtn;
  3.1117 -}
  3.1118 -
  3.1119 -
  3.1120 -/*
  3.1121 - * This function exports SCSI Bus, Device or Host reset capability
  3.1122 - * and is for use with the SCSI generic driver.
  3.1123 - */
  3.1124 -int
  3.1125 -scsi_old_reset(Scsi_Cmnd *SCpnt, unsigned int flag)
  3.1126 -{
  3.1127 -	unsigned int old_flags = SCSI_RESET_SYNCHRONOUS;
  3.1128 -
  3.1129 -	switch(flag) {
  3.1130 -	case SCSI_TRY_RESET_DEVICE:
  3.1131 -		/* no suggestion flags to add, device reset is default */
  3.1132 -		break;
  3.1133 -	case SCSI_TRY_RESET_BUS:
  3.1134 -		old_flags |= SCSI_RESET_SUGGEST_BUS_RESET;
  3.1135 -		break;
  3.1136 -	case SCSI_TRY_RESET_HOST:
  3.1137 -		old_flags |= SCSI_RESET_SUGGEST_HOST_RESET;
  3.1138 -		break;
  3.1139 -	default:
  3.1140 -		return FAILED;
  3.1141 -	}
  3.1142 -
  3.1143 -	if (scsi_reset(SCpnt, old_flags))
  3.1144 -		return FAILED;
  3.1145 -	return SUCCESS;
  3.1146 -}
  3.1147 -
  3.1148 -/*
  3.1149 - * Overrides for Emacs so that we follow Linus's tabbing style.
  3.1150 - * Emacs will notice this stuff at the end of the file and automatically
  3.1151 - * adjust the settings for this buffer only.  This must remain at the end
  3.1152 - * of the file.
  3.1153 - * ---------------------------------------------------------------------------
  3.1154 - * Local variables:
  3.1155 - * c-indent-level: 4
  3.1156 - * c-brace-imaginary-offset: 0
  3.1157 - * c-brace-offset: -4
  3.1158 - * c-argdecl-indent: 4
  3.1159 - * c-label-offset: -4
  3.1160 - * c-continued-statement-offset: 4
  3.1161 - * c-continued-brace-offset: 0
  3.1162 - * indent-tabs-mode: nil
  3.1163 - * tab-width: 8
  3.1164 - * End:
  3.1165 - */