root/drivers/scsi/scsi.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. blacklisted
  2. restart_all
  3. scan_scsis_done
  4. scsi_luns_setup
  5. scan_scsis
  6. scsi_times_out
  7. request_queueable
  8. allocate_device
  9. internal_cmnd
  10. scsi_request_sense
  11. scsi_do_cmd
  12. reset
  13. check_sense
  14. scsi_done
  15. scsi_abort
  16. scsi_reset
  17. scsi_main_timeout
  18. update_timeout
  19. scsi_malloc
  20. scsi_free
  21. scsi_init_malloc
  22. scsi_init_free
  23. scsi_dev_init
  24. print_inquiry
  25. scsi_register_host
  26. scsi_unregister_host
  27. scsi_register_module
  28. scsi_unregister_module
  29. scsi_dump_status

   1 /*
   2  *      scsi.c Copyright (C) 1992 Drew Eckhardt 
   3  *             Copyright (C) 1993, 1994, 1995 Eric Youngdale
   4  *
   5  *      generic mid-level SCSI driver
   6  *              Initial versions: Drew Eckhardt 
   7  *              Subsequent revisions: Eric Youngdale
   8  *
   9  *      <drew@colorado.edu>
  10  *
  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>
  15  * 
  16  *       Modified by Eric Youngdale ericy@cais.com to
  17  *       add scatter-gather, multiple outstanding request, and other
  18  *       enhancements.
  19  */
  20 
  21 #include <asm/system.h>
  22 #include <linux/sched.h>
  23 #include <linux/timer.h>
  24 #include <linux/string.h>
  25 #include <linux/malloc.h>
  26 #include <asm/irq.h>
  27 #include <asm/dma.h>
  28 #include <linux/ioport.h>
  29 
  30 #include "../block/blk.h"
  31 #include "scsi.h"
  32 #include "hosts.h"
  33 #include "constants.h"
  34 
  35 /*
  36 static const char RCSid[] = "$Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/scsi.c,v 1.5 1993/09/24 12:45:18 drew Exp drew $";
  37 */
  38 
  39 /* Command groups 3 and 4 are reserved and should never be used.  */
  40 const unsigned char scsi_command_size[8] = { 6, 10, 10, 12, 12, 12, 10, 10 };
  41 
  42 #define INTERNAL_ERROR (panic ("Internal error in file %s, line %d.\n", __FILE__, __LINE__))
  43 
  44 static void scsi_done (Scsi_Cmnd *SCpnt);
  45 static int update_timeout (Scsi_Cmnd *, int);
  46 static void print_inquiry(unsigned char *data);
  47 static void scsi_times_out (Scsi_Cmnd * SCpnt, int pid);
  48 
  49 static int time_start;
  50 static int time_elapsed;
  51 static int scsi_maybe_deadlocked = 0;
  52 static int max_active = 0;
  53 static struct Scsi_Host * host_active = NULL;
  54 static struct Scsi_Host * host_next = NULL;
  55 
  56 #define MAX_SCSI_DEVICE_CODE 10
  57 const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] =
  58 {
  59  "Direct-Access    ",
  60  "Sequential-Access",
  61  "Printer          ",
  62  "Processor        ",
  63  "WORM             ",
  64  "CD-ROM           ",
  65  "Scanner          ",
  66  "Optical Device   ",
  67  "Medium Changer   ",
  68  "Communications   "
  69 };
  70 
  71 
  72 /*
  73         global variables : 
  74         scsi_devices an array of these specifying the address for each 
  75         (host, id, LUN)
  76 */
  77 
  78 Scsi_Device * scsi_devices = NULL;
  79 
  80 /* Process ID of SCSI commands */
  81 unsigned long scsi_pid = 0;
  82 
  83 static unsigned char generic_sense[6] = {REQUEST_SENSE, 0,0,0, 255, 0};
  84 
  85 /* This variable is merely a hook so that we can debug the kernel with gdb. */
  86 Scsi_Cmnd * last_cmnd = NULL;
  87 
  88 /*
  89  *      As the scsi do command functions are intelligent, and may need to 
  90  *      redo a command, we need to keep track of the last command 
  91  *      executed on each one.
  92  */
  93 
  94 #define WAS_RESET       0x01
  95 #define WAS_TIMEDOUT    0x02
  96 #define WAS_SENSE       0x04
  97 #define IS_RESETTING    0x08
  98 #define IS_ABORTING     0x10
  99 #define ASKED_FOR_SENSE 0x20
 100 
 101 /*
 102  *      This is the number  of clock ticks we should wait before we time out 
 103  *      and abort the command.  This is for  where the scsi.c module generates 
 104  *      the command, not where it originates from a higher level, in which
 105  *      case the timeout is specified there.
 106  *
 107  *      ABORT_TIMEOUT and RESET_TIMEOUT are the timeouts for RESET and ABORT
 108  *      respectively.
 109  */
 110 
 111 #ifdef DEBUG_TIMEOUT
 112 static void scsi_dump_status(void);
 113 #endif
 114 
 115 
 116 #ifdef DEBUG
 117         #define SCSI_TIMEOUT 500
 118 #else
 119         #define SCSI_TIMEOUT 100
 120 #endif
 121 
 122 #ifdef DEBUG
 123         #define SENSE_TIMEOUT SCSI_TIMEOUT
 124         #define ABORT_TIMEOUT SCSI_TIMEOUT
 125         #define RESET_TIMEOUT SCSI_TIMEOUT
 126 #else
 127         #define SENSE_TIMEOUT 50
 128         #define RESET_TIMEOUT 50
 129         #define ABORT_TIMEOUT 50
 130         #define MIN_RESET_DELAY 100
 131 #endif
 132 
 133 /* The following devices are known not to tolerate a lun != 0 scan for
 134    one reason or another.  Some will respond to all luns, others will
 135    lock up. */
 136 
 137      struct blist{
 138        char * vendor;
 139        char * model;
 140        char * revision; /* Latest revision known to be bad.  Not used yet */
 141      };
 142 
 143 static struct blist blacklist[] = 
 144 {
 145    {"CHINON","CD-ROM CDS-431","H42"},  /* Locks up if polled for lun != 0 */
 146    {"CHINON","CD-ROM CDS-535","Q14"}, /* Lockup if polled for lun != 0 */
 147    {"DENON","DRD-25X","V"},   /* A cdrom that locks up when probed at lun != 0 */
 148    {"IMS", "CDD521/10","2.06"},   /* Locks-up when LUN>0 polled. */
 149    {"MAXTOR","XT-3280","PR02"},   /* Locks-up when LUN>0 polled. */
 150    {"MAXTOR","XT-4380S","B3C"},   /* Locks-up when LUN>0 polled. */
 151    {"MAXTOR","MXT-1240S","I1.2"}, /* Locks up when LUN > 0 polled */
 152    {"MAXTOR","XT-4170S","B5A"},   /* Locks-up sometimes when LUN>0 polled. */
 153    {"MAXTOR","XT-8760S","B7B"},   /* guess what? */
 154    {"NEC","CD-ROM DRIVE:841","1.0"},  /* Locks-up when LUN>0 polled. */
 155    {"RODIME","RO3000S","2.33"},  /* Locks up if polled for lun != 0 */
 156    {"SEAGATE", "ST157N", "\004|j"}, /* causes failed REQUEST SENSE on lun 1 for aha152x
 157                                      * controller, which causes SCSI code to reset bus.*/
 158    {"SEAGATE", "ST296","921"},   /* Responds to all lun */
 159    {"SONY","CD-ROM CDU-541","4.3d"},
 160    {"SONY","CD-ROM CDU-55S","1.0i"},
 161    {"TANDBERG","TDC 3600","U07"},  /* Locks up if polled for lun != 0 */
 162    {"TEAC","CD-ROM","1.06"},    /* causes failed REQUEST SENSE on lun 1 for seagate
 163                                  * controller, which causes SCSI code to reset bus.*/
 164    {"TEXEL","CD-ROM","1.06"},   /* causes failed REQUEST SENSE on lun 1 for seagate
 165                                  * controller, which causes SCSI code to reset bus.*/
 166    {"QUANTUM","LPS525S","3110"},/* Locks sometimes if polled for lun != 0 */
 167    {"QUANTUM","PD1225S","3110"},/* Locks sometimes if polled for lun != 0 */
 168    {"MEDIAVIS","CDR-H93MV","1.31"},  /* Locks up if polled for lun != 0 */
 169    {"SANKYO", "CP525","6.64"},  /* causes failed REQ SENSE, extra reset */
 170    {"HP", "C1750A", "3226"},    /* scanjet iic */
 171    {"HP", "C1790A", ""},        /* scanjet iip */
 172    {"HP", "C2500A", ""},        /* scanjet iicx */
 173    {NULL, NULL, NULL}}; 
 174 
 175 static int blacklisted(unsigned char * response_data){
     /* [previous][next][first][last][top][bottom][index][help] */
 176   int i = 0;
 177   unsigned char * pnt;
 178   for(i=0; 1; i++){
 179     if(blacklist[i].vendor == NULL) return 0;
 180     pnt = &response_data[8];
 181     while(*pnt && *pnt == ' ') pnt++;
 182     if(memcmp(blacklist[i].vendor, pnt,
 183                strlen(blacklist[i].vendor))) continue;
 184     pnt = &response_data[16];
 185     while(*pnt && *pnt == ' ') pnt++;
 186     if(memcmp(blacklist[i].model, pnt,
 187                strlen(blacklist[i].model))) continue;
 188     return 1;
 189   };    
 190 };
 191 
 192 /*
 193  *      As the actual SCSI command runs in the background, we must set up a 
 194  *      flag that tells scan_scsis() when the result it has is valid.  
 195  *      scan_scsis can set the_result to -1, and watch for it to become the 
 196  *      actual return code for that call.  the scan_scsis_done function() is 
 197  *      our user specified completion function that is passed on to the  
 198  *      scsi_do_cmd() function.
 199  */
 200 
 201 volatile int in_scan_scsis = 0;
 202 static int the_result;
 203 
 204 static void restart_all(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
 205  /*
 206   * If we might have deadlocked, get things started again. Only
 207   * for block devices. Character devices should never deadlock.
 208   */
 209   struct Scsi_Device_Template * sdtpnt;
 210 
 211   for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
 212 
 213      if (sdtpnt->blk && blk_dev[sdtpnt->major].request_fn)
 214         (*blk_dev[sdtpnt->major].request_fn)();
 215 
 216   }
 217 
 218 static void scan_scsis_done (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 219         {
 220         
 221 #ifdef DEBUG
 222         printk ("scan_scsis_done(%d, %06x)\n", SCpnt->host, SCpnt->result);
 223 #endif  
 224         SCpnt->request.dev = 0xfffe;
 225 
 226         if (SCpnt->request.sem != NULL)
 227           up(SCpnt->request.sem);
 228         }
 229 
 230 #ifdef NO_MULTI_LUN
 231 static int max_scsi_luns = 1;
 232 #else
 233 static int max_scsi_luns = 8;
 234 #endif
 235 
 236 void scsi_luns_setup(char *str, int *ints) {
     /* [previous][next][first][last][top][bottom][index][help] */
 237     if (ints[0] != 1) 
 238         printk("scsi_luns_setup : usage max_scsi_luns=n (n should be between 1 and 8)\n");
 239     else
 240         max_scsi_luns = ints[1];
 241 }
 242 
 243 /*
 244  *      Detecting SCSI devices :        
 245  *      We scan all present host adapter's busses,  from ID 0 to ID 6.  
 246  *      We use the INQUIRY command, determine device type, and pass the ID / 
 247  *      lun address of all sequential devices to the tape driver, all random 
 248  *      devices to the disk driver.
 249  */
 250 
 251 void scan_scsis (struct Scsi_Host * shpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 252 {
 253   int dev, lun, type;
 254   unsigned char scsi_cmd [12];
 255   unsigned char scsi_result0 [256];
 256   unsigned char * scsi_result;
 257   Scsi_Device * SDpnt, *SDtail;
 258   struct Scsi_Device_Template * sdtpnt;
 259   Scsi_Cmnd  SCmd;
 260   
 261   ++in_scan_scsis;
 262   lun = 0;
 263   type = -1;
 264   SCmd.next = NULL;
 265   SCmd.prev = NULL;
 266   SDpnt = (Scsi_Device *) scsi_init_malloc(sizeof (Scsi_Device), GFP_ATOMIC);
 267   SDtail = scsi_devices;
 268   if(scsi_devices) {
 269     while(SDtail->next) SDtail = SDtail->next;
 270   }
 271 
 272   /* Make sure we have something that is valid for DMA purposes */
 273   scsi_result = ((current == task[0]  || !shpnt->unchecked_isa_dma) 
 274                  ?  &scsi_result0[0] : scsi_malloc(512));
 275             
 276 
 277   shpnt->host_queue = &SCmd;  /* We need this so that
 278                                          commands can time out */
 279   for (dev = 0; dev < 8; ++dev)
 280     if (shpnt->this_id != dev)
 281 /*
 282  * We need the for so our continue, etc. work fine.
 283  */
 284 
 285       for (lun = 0; lun < max_scsi_luns; ++lun)
 286         {
 287           SDpnt->host = shpnt;
 288           SDpnt->id = dev;
 289           SDpnt->lun = lun;
 290           SDpnt->device_wait = NULL;
 291           SDpnt->next = NULL;
 292           SDpnt->attached = 0;
 293 /*
 294  * Assume that the device will have handshaking problems, and then 
 295  * fix this field later if it turns out it doesn't.
 296  */
 297           SDpnt->borken = 1;
 298           
 299           scsi_cmd[0] = TEST_UNIT_READY;
 300           scsi_cmd[1] = lun << 5;
 301           scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[5] = 0;
 302           scsi_cmd[4] = 0;
 303           
 304           SCmd.host = shpnt;
 305           SCmd.target = dev;
 306           SCmd.lun = lun;
 307 
 308           SCmd.request.sem = NULL;  /* Used for mutex if loading devices after boot */
 309           SCmd.request.dev = 0xffff; /* Mark not busy */
 310           SCmd.use_sg  = 0;
 311           SCmd.cmd_len = 0;
 312           SCmd.old_use_sg  = 0;
 313           SCmd.transfersize = 0;
 314           SCmd.underflow = 0;
 315           
 316           scsi_do_cmd (&SCmd,
 317                        (void *)  scsi_cmd, (void *) 
 318                        scsi_result, 256,  scan_scsis_done, 
 319                        SCSI_TIMEOUT + 400, 5);
 320           
 321           /* Wait for command to finish.  Use simple wait if we are booting, else
 322              do it right and use a mutex */
 323 
 324           if (current == task[0]){
 325             while (SCmd.request.dev != 0xfffe);
 326           } else {
 327             if (SCmd.request.dev != 0xfffe){
 328               struct semaphore sem = MUTEX_LOCKED;
 329               SCmd.request.sem = &sem;
 330               down(&sem);
 331               /* Hmm.. Have to ask about this one */
 332               while (SCmd.request.dev != 0xfffe) schedule();
 333             }
 334           }
 335 
 336 #if defined(DEBUG) || defined(DEBUG_INIT)
 337           printk("scsi: scan SCSIS id %d lun %d\n", dev, lun);
 338           printk("scsi: return code %08x\n", SCmd.result);
 339 #endif
 340           
 341           
 342           if(SCmd.result) {
 343             if ((driver_byte(SCmd.result)  & DRIVER_SENSE) &&
 344                 ((SCmd.sense_buffer[0] & 0x70) >> 4) == 7) {
 345               if (SCmd.sense_buffer[2] &0xe0)
 346                 continue; /* No devices here... */
 347               if(((SCmd.sense_buffer[2] & 0xf) != NOT_READY) &&
 348                  ((SCmd.sense_buffer[2] & 0xf) != UNIT_ATTENTION))
 349                 continue;
 350             }
 351             else
 352               break;
 353           };
 354           
 355 #if defined (DEBUG) || defined(DEBUG_INIT)
 356           printk("scsi: performing INQUIRY\n");
 357 #endif
 358           
 359           /*
 360            * Build an INQUIRY command block.  
 361            */
 362           
 363           scsi_cmd[0] = INQUIRY;
 364           scsi_cmd[1] = (lun << 5) & 0xe0;
 365           scsi_cmd[2] = 0;
 366           scsi_cmd[3] = 0;
 367           scsi_cmd[4] = 255;
 368           scsi_cmd[5] = 0;
 369           
 370           SCmd.request.dev = 0xffff; /* Mark not busy */
 371           SCmd.cmd_len = 0;
 372           
 373           scsi_do_cmd (&SCmd,
 374                        (void *)  scsi_cmd, (void *) 
 375                        scsi_result, 256,  scan_scsis_done, 
 376                        SCSI_TIMEOUT, 3);
 377           
 378           if (current == task[0]){
 379             while (SCmd.request.dev != 0xfffe);
 380           } else {
 381             if (SCmd.request.dev != 0xfffe){
 382               struct semaphore sem = MUTEX_LOCKED;
 383               SCmd.request.sem = &sem;
 384               down(&sem);
 385               /* Hmm.. Have to ask about this one */
 386               while (SCmd.request.dev != 0xfffe) schedule();
 387             }
 388           }
 389 
 390           the_result = SCmd.result;
 391           
 392 #if defined(DEBUG) || defined(DEBUG_INIT)
 393           if (!the_result)
 394             printk("scsi: INQUIRY successful\n");
 395           else
 396             printk("scsi: INQUIRY failed with code %08x\n", the_result);
 397 #endif
 398           
 399           if(the_result) break; 
 400           
 401           /* skip other luns on this device */
 402           
 403           if (!the_result)
 404             {
 405                 /* It would seem some TOSHIBA CD-ROM gets things wrong */
 406                 if (!strncmp(scsi_result+8,"TOSHIBA",7) &&
 407                     !strncmp(scsi_result+16,"CD-ROM",6) &&
 408                     scsi_result[0] == TYPE_DISK) {
 409                         scsi_result[0] = TYPE_ROM;
 410                         scsi_result[1] |= 0x80;  /* removable */
 411                 }
 412 
 413               SDpnt->manufacturer = SCSI_MAN_UNKNOWN;
 414               if (!strncmp(scsi_result+8,"NEC",3))
 415                 SDpnt->manufacturer = SCSI_MAN_NEC;
 416               if (!strncmp(scsi_result+8,"TOSHIBA",7))
 417                 SDpnt->manufacturer = SCSI_MAN_TOSHIBA;
 418 
 419               SDpnt->removable = (0x80 & 
 420                                   scsi_result[1]) >> 7;
 421               SDpnt->lockable = SDpnt->removable;
 422               SDpnt->changed = 0;
 423               SDpnt->access_count = 0;
 424               SDpnt->busy = 0;
 425 /* 
 426  *      Currently, all sequential devices are assumed to be tapes,
 427  *      all random devices disk, with the appropriate read only 
 428  *      flags set for ROM / WORM treated as RO.
 429  */ 
 430 
 431               switch (type = (scsi_result[0] & 0x1f))
 432                 {
 433                 case TYPE_TAPE :
 434                 case TYPE_DISK :
 435                 case TYPE_MOD :
 436                 case TYPE_PROCESSOR :
 437                 case TYPE_SCANNER :
 438                   SDpnt->writeable = 1;
 439                   break;
 440                 case TYPE_WORM :
 441                 case TYPE_ROM :
 442                   SDpnt->writeable = 0;
 443                   break;
 444                 default :
 445 #if 0
 446 #ifdef DEBUG
 447                   printk("scsi: unknown type %d\n", type);
 448                   print_inquiry(scsi_result);
 449 #endif
 450                   type = -1;
 451 #endif
 452                 }
 453               
 454               SDpnt->soft_reset = 
 455                 (scsi_result[7] & 1) && ((scsi_result[3] & 7) == 2);
 456               SDpnt->random = (type == TYPE_TAPE) ? 0 : 1;
 457               SDpnt->type = (type & 0x1f);
 458               
 459               if (type != -1)
 460                 {
 461                   print_inquiry(scsi_result);
 462 
 463                   for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
 464                     if(sdtpnt->detect) SDpnt->attached +=
 465                       (*sdtpnt->detect)(SDpnt);
 466 
 467                   SDpnt->scsi_level = scsi_result[2] & 0x07;
 468                   if (SDpnt->scsi_level >= 2 ||
 469                       (SDpnt->scsi_level == 1 &&
 470                        (scsi_result[3] & 0x0f) == 1))
 471                     SDpnt->scsi_level++;
 472 /* 
 473  * Set the tagged_queue flag for SCSI-II devices that purport to support
 474  * tagged queuing in the INQUIRY data.
 475  */
 476                   
 477                   SDpnt->tagged_queue = 0;
 478                   
 479                   if ((SDpnt->scsi_level >= SCSI_2) &&
 480                       (scsi_result[7] & 2)) {
 481                     SDpnt->tagged_supported = 1;
 482                     SDpnt->current_tag = 0;
 483                   }
 484                   
 485 /*
 486  * Accommodate drivers that want to sleep when they should be in a polling
 487  * loop.
 488  */
 489 
 490                   SDpnt->disconnect = 0;
 491 
 492 /*
 493  * Some revisions of the Texel CD ROM drives have handshaking
 494  * problems when used with the Seagate controllers.  Before we
 495  * know what type of device we're talking to, we assume it's 
 496  * borken and then change it here if it turns out that it isn't
 497  * a TEXEL drive.
 498  */
 499 
 500                   if(strncmp("TEXEL", (char *) &scsi_result[8], 5) != 0 ||
 501                      strncmp("CD-ROM", (char *) &scsi_result[16], 6) != 0 
 502 /* 
 503  * XXX 1.06 has problems, some one should figure out the others too so
 504  * ALL TEXEL drives don't suffer in performance, especially when I finish
 505  * integrating my seagate patches which do multiple I_T_L nexuses.
 506  */
 507 
 508 #ifdef notyet
 509                      || (strncmp("1.06", (char *) &scsi_result[[, 4) != 0)))
 510 #endif
 511                                  )
 512                     SDpnt->borken = 0;
 513                   
 514                   
 515                   /* These devices need this "key" to unlock the device
 516                      so we can use it */
 517                   if(memcmp("INSITE", &scsi_result[8], 6) == 0 &&
 518                      (memcmp("Floptical   F*8I", &scsi_result[16], 16) == 0
 519                       || memcmp("I325VM", &scsi_result[16], 6) == 0)) {
 520                     printk("Unlocked floptical drive.\n");
 521                     SDpnt->lockable = 0;
 522                     scsi_cmd[0] = MODE_SENSE;
 523                     scsi_cmd[1] = (lun << 5) & 0xe0;
 524                     scsi_cmd[2] = 0x2e;
 525                     scsi_cmd[3] = 0;
 526                     scsi_cmd[4] = 0x2a;
 527                     scsi_cmd[5] = 0;
 528                     
 529                     SCmd.request.dev = 0xffff; /* Mark not busy */
 530                     SCmd.cmd_len = 0;
 531                     
 532                     scsi_do_cmd (&SCmd,
 533                                  (void *)  scsi_cmd, (void *) 
 534                                  scsi_result, 0x2a,  scan_scsis_done, 
 535                                  SCSI_TIMEOUT, 3);
 536                     
 537                     if (current == task[0]){
 538                       while (SCmd.request.dev != 0xfffe);
 539                     } else {
 540                       if (SCmd.request.dev != 0xfffe){
 541                         struct semaphore sem = MUTEX_LOCKED;
 542                         SCmd.request.sem = &sem;
 543                         down(&sem);
 544                         /* Hmm.. Have to ask about this one */
 545                         while (SCmd.request.dev != 0xfffe) schedule();
 546                       }
 547                     }
 548                   }
 549                   /* Add this device to the linked list at the end */
 550                   if(SDtail)
 551                     SDtail->next = SDpnt;
 552                   else
 553                     scsi_devices = SDpnt;
 554                   SDtail = SDpnt;
 555 
 556                   SDpnt = (Scsi_Device *) scsi_init_malloc(sizeof (Scsi_Device), GFP_ATOMIC);
 557                   /* Some scsi devices cannot be polled for lun != 0
 558                      due to firmware bugs */
 559                   if(blacklisted(scsi_result)) break;
 560                   /* Old drives like the MAXTOR XT-3280 say vers=0 */
 561                   if ((scsi_result[2] & 0x07) == 0)
 562                     break;
 563                   /* Some scsi-1 peripherals do not handle lun != 0.
 564                      I am assuming that scsi-2 peripherals do better */
 565                   if((scsi_result[2] & 0x07) == 1 && 
 566                      (scsi_result[3] & 0x0f) == 0) break;
 567                 }
 568             }       /* if result == DID_OK ends */
 569         }       /* for lun ends */
 570   shpnt->host_queue = NULL;  /* No longer needed here */
 571   
 572   printk("scsi : detected ");
 573   for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
 574     if(sdtpnt->dev_noticed && sdtpnt->name)
 575       printk("%d SCSI %s%s ", sdtpnt->dev_noticed, sdtpnt->name,
 576              (sdtpnt->dev_noticed != 1) ? "s" : "");
 577 
 578   printk("total.\n");
 579   
 580   /* Last device block does not exist.  Free memory. */
 581   scsi_init_free((char *) SDpnt, sizeof(Scsi_Device));
 582   
 583 
 584   /* If we allocated a buffer so we could do DMA, free it now */
 585   if (scsi_result != &scsi_result0[0]) scsi_free(scsi_result, 512);
 586 
 587   in_scan_scsis = 0;
 588 }       /* scan_scsis  ends */
 589 
 590 /*
 591  *      Flag bits for the internal_timeout array 
 592  */
 593 
 594 #define NORMAL_TIMEOUT 0
 595 #define IN_ABORT 1
 596 #define IN_RESET 2
 597 /*
 598         This is our time out function, called when the timer expires for a 
 599         given host adapter.  It will attempt to abort the currently executing 
 600         command, that failing perform a kernel panic.
 601 */ 
 602 
 603 static void scsi_times_out (Scsi_Cmnd * SCpnt, int pid)
     /* [previous][next][first][last][top][bottom][index][help] */
 604         {
 605         
 606         switch (SCpnt->internal_timeout & (IN_ABORT | IN_RESET))
 607                 {
 608                 case NORMAL_TIMEOUT:
 609                         if (!in_scan_scsis) {
 610 #ifdef DEBUG_TIMEOUT
 611                           scsi_dump_status();
 612 #endif
 613                         }
 614                         
 615                         if (!scsi_abort (SCpnt, DID_TIME_OUT, pid))
 616                                 return;                         
 617                 case IN_ABORT:
 618                         printk("SCSI host %d abort() timed out - resetting\n",
 619                                 SCpnt->host->host_no);
 620                         if (!scsi_reset (SCpnt)) 
 621                                 return;
 622                 case IN_RESET:
 623                 case (IN_ABORT | IN_RESET):
 624                   /* This might be controversial, but if there is a bus hang,
 625                      you might conceivably want the machine up and running
 626                      esp if you have an ide disk. */
 627                         printk("Unable to reset scsi host %d - ",SCpnt->host->host_no);
 628                         printk("probably a SCSI bus hang.\n");
 629                         return;
 630 
 631                 default:
 632                         INTERNAL_ERROR;
 633                 }
 634                                         
 635         }
 636 
 637 
 638 /* This function takes a quick look at a request, and decides if it
 639 can be queued now, or if there would be a stall while waiting for
 640 something else to finish.  This routine assumes that interrupts are
 641 turned off when entering the routine.  It is the responsibility
 642 of the calling code to ensure that this is the case. */
 643 
 644 Scsi_Cmnd * request_queueable (struct request * req, Scsi_Device * device)
     /* [previous][next][first][last][top][bottom][index][help] */
 645 {
 646   Scsi_Cmnd * SCpnt = NULL;
 647   int tablesize;
 648   struct buffer_head * bh, *bhp;
 649 
 650   if (!device)
 651     panic ("No device passed to request_queueable().\n");
 652   
 653   if (req && req->dev <= 0)
 654     panic("Invalid device in request_queueable");
 655   
 656   SCpnt =  device->host->host_queue;
 657     while(SCpnt){
 658       if(SCpnt->target == device->id &&
 659          SCpnt->lun == device->lun)
 660         if(SCpnt->request.dev < 0) break;
 661       SCpnt = SCpnt->next;
 662     };
 663 
 664   if (!SCpnt) return NULL;
 665 
 666   if (device->host->can_queue &&
 667        ((device->host->block && host_active && device->host != host_active) || 
 668         (device->host->block && host_next && device->host != host_next) ||
 669         device->host->host_busy >= device->host->can_queue)) {
 670 
 671      if (device->host->block && !host_next && host_active 
 672                              && device->host != host_active) 
 673         host_next = device->host;
 674 
 675      return NULL;
 676      }
 677 
 678   if (req) {
 679     memcpy(&SCpnt->request, req, sizeof(struct request));
 680     tablesize = device->host->sg_tablesize;
 681     bhp = bh = req->bh;
 682     if(!tablesize) bh = NULL;
 683     /* Take a quick look through the table to see how big it is.  We already
 684        have our copy of req, so we can mess with that if we want to.  */
 685     while(req->nr_sectors && bh){
 686             bhp = bhp->b_reqnext;
 687             if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
 688             req->nr_sectors -= bh->b_size >> 9;
 689             req->sector += bh->b_size >> 9;
 690             if(!tablesize) break;
 691             bh = bhp;
 692     };
 693     if(req->nr_sectors && bh && bh->b_reqnext){  /* Any leftovers? */
 694       SCpnt->request.bhtail = bh;
 695       req->bh = bh->b_reqnext; /* Divide request */
 696       bh->b_reqnext = NULL;
 697       bh = req->bh;
 698 
 699       /* Now reset things so that req looks OK */
 700       SCpnt->request.nr_sectors -= req->nr_sectors;
 701       req->current_nr_sectors = bh->b_size >> 9;
 702       req->buffer = bh->b_data;
 703       SCpnt->request.sem = NULL; /* Wait until whole thing done */
 704     } else {
 705       req->dev = -1;
 706       wake_up(&wait_for_request);
 707     };      
 708   } else {
 709     SCpnt->request.dev = 0xffff; /* Busy, but no request */
 710     SCpnt->request.sem = NULL;  /* And no one is waiting for the device either */
 711   };
 712 
 713   SCpnt->use_sg = 0;  /* Reset the scatter-gather flag */
 714   SCpnt->old_use_sg  = 0;
 715   SCpnt->transfersize = 0;
 716   SCpnt->underflow = 0;
 717   SCpnt->cmd_len = 0;
 718   return SCpnt;
 719 }
 720 
 721 /* This function returns a structure pointer that will be valid for
 722 the device.  The wait parameter tells us whether we should wait for
 723 the unit to become free or not.  We are also able to tell this routine
 724 not to return a descriptor if the host is unable to accept any more
 725 commands for the time being.  We need to keep in mind that there is no
 726 guarantee that the host remain not busy.  Keep in mind the
 727 request_queueable function also knows the internal allocation scheme
 728 of the packets for each device */
 729 
 730 Scsi_Cmnd * allocate_device (struct request ** reqp, Scsi_Device * device,
     /* [previous][next][first][last][top][bottom][index][help] */
 731                              int wait)
 732 {
 733   int dev = -1;
 734   struct request * req = NULL;
 735   int tablesize;
 736   unsigned int flags;
 737   struct buffer_head * bh, *bhp;
 738   struct Scsi_Host * host;
 739   Scsi_Cmnd * SCpnt = NULL;
 740   Scsi_Cmnd * SCwait = NULL;
 741 
 742   if (!device)
 743     panic ("No device passed to allocate_device().\n");
 744   
 745   if (reqp) req = *reqp;
 746 
 747     /* See if this request has already been queued by an interrupt routine */
 748   if (req && (dev = req->dev) <= 0) return NULL;
 749   
 750   host = device->host;
 751   
 752   if (intr_count && host->can_queue &&
 753                       ((host->block && host_active && host != host_active) ||
 754                        (host->block && host_next && host != host_next) ||
 755                        host->host_busy >= host->can_queue)) {
 756 
 757      scsi_maybe_deadlocked = 1;
 758 
 759      if (host->block && !host_next && host_active && host != host_active) 
 760         host_next = host;
 761 
 762      return NULL;
 763      }
 764 
 765   while (1==1){
 766     SCpnt = host->host_queue;
 767     while(SCpnt){
 768       if(SCpnt->target == device->id &&
 769          SCpnt->lun == device->lun) {
 770         SCwait = SCpnt;
 771         if(SCpnt->request.dev < 0) break;
 772       };
 773       SCpnt = SCpnt->next;
 774     };
 775     save_flags(flags);
 776     cli();
 777     /* See if this request has already been queued by an interrupt routine */
 778     if (req && ((req->dev < 0) || (req->dev != dev))) {
 779       restore_flags(flags);
 780       return NULL;
 781     };
 782     if (!SCpnt || SCpnt->request.dev >= 0)  /* Might have changed */
 783       {
 784         restore_flags(flags);
 785         if(!wait) return NULL;
 786         if (!SCwait) {
 787           printk("Attempt to allocate device target %d, lun %d\n",
 788                  device->id ,device->lun);
 789           panic("No device found in allocate_device\n");
 790         };
 791         SCSI_SLEEP(&device->device_wait, 
 792                    (SCwait->request.dev > 0));
 793       } else {
 794         if (req) {
 795           memcpy(&SCpnt->request, req, sizeof(struct request));
 796           tablesize = device->host->sg_tablesize;
 797           bhp = bh = req->bh;
 798           if(!tablesize) bh = NULL;
 799           /* Take a quick look through the table to see how big it is.  We already
 800              have our copy of req, so we can mess with that if we want to.  */
 801           while(req->nr_sectors && bh){
 802             bhp = bhp->b_reqnext;
 803             if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
 804             req->nr_sectors -= bh->b_size >> 9;
 805             req->sector += bh->b_size >> 9;
 806             if(!tablesize) break;
 807             bh = bhp;
 808           };
 809           if(req->nr_sectors && bh && bh->b_reqnext){  /* Any leftovers? */
 810             SCpnt->request.bhtail = bh;
 811             req->bh = bh->b_reqnext; /* Divide request */
 812             bh->b_reqnext = NULL;
 813             bh = req->bh;
 814             /* Now reset things so that req looks OK */
 815             SCpnt->request.nr_sectors -= req->nr_sectors;
 816             req->current_nr_sectors = bh->b_size >> 9;
 817             req->buffer = bh->b_data;
 818             SCpnt->request.sem = NULL; /* Wait until whole thing done */
 819           }
 820           else 
 821             {
 822               req->dev = -1;
 823               *reqp = req->next;
 824               wake_up(&wait_for_request);
 825             };
 826         } else {
 827           SCpnt->request.dev = 0xffff; /* Busy */
 828           SCpnt->request.sem = NULL;  /* And no one is waiting for this to complete */
 829         };
 830         restore_flags(flags);
 831         break;
 832       };
 833   };
 834 
 835   SCpnt->use_sg = 0;  /* Reset the scatter-gather flag */
 836   SCpnt->old_use_sg  = 0;
 837   SCpnt->transfersize = 0;      /* No default transfer size */
 838   SCpnt->cmd_len = 0;
 839   SCpnt->underflow = 0;         /* Do not flag underflow conditions */
 840   return SCpnt;
 841 }
 842 
 843 /*
 844         This is inline because we have stack problemes if we recurse to deeply.
 845 */
 846                          
 847 inline void internal_cmnd (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 848         {
 849         int temp;
 850         struct Scsi_Host * host;
 851 #ifdef DEBUG_DELAY      
 852         int clock;
 853 #endif
 854 
 855         if ((unsigned long) &SCpnt < current->kernel_stack_page)
 856           panic("Kernel stack overflow.");
 857 
 858         host = SCpnt->host;
 859 
 860 /*
 861         We will wait MIN_RESET_DELAY clock ticks after the last reset so 
 862         we can avoid the drive not being ready.
 863 */ 
 864 temp = host->last_reset;
 865 while (jiffies < temp);
 866 
 867 update_timeout(SCpnt, SCpnt->timeout_per_command);
 868 
 869 /*
 870         We will use a queued command if possible, otherwise we will emulate the
 871         queuing and calling of completion function ourselves. 
 872 */
 873 #ifdef DEBUG
 874         printk("internal_cmnd (host = %d, target = %d, command = %08x, buffer =  %08x, \n"
 875                 "bufflen = %d, done = %08x)\n", SCpnt->host->host_no, SCpnt->target, SCpnt->cmnd, SCpnt->buffer, SCpnt->bufflen, SCpnt->done);
 876 #endif
 877 
 878         if (host->can_queue)
 879                 {
 880 #ifdef DEBUG
 881         printk("queuecommand : routine at %08x\n", 
 882                 host->hostt->queuecommand);
 883 #endif
 884                   /* This locking tries to prevent all sorts of races between
 885                      queuecommand and the interrupt code.  In effect,
 886                      we are only allowed to be in queuecommand once at
 887                      any given time, and we can only be in the interrupt
 888                      handler and the queuecommand function at the same time
 889                      when queuecommand is called while servicing the
 890                      interrupt. */
 891 
 892                 if(!intr_count && SCpnt->host->irq)
 893                   disable_irq(SCpnt->host->irq);
 894 
 895                 host->hostt->queuecommand (SCpnt, scsi_done);
 896 
 897                 if(!intr_count && SCpnt->host->irq)
 898                   enable_irq(SCpnt->host->irq);
 899                 }
 900         else
 901                 {
 902 
 903 #ifdef DEBUG
 904         printk("command() :  routine at %08x\n", host->hostt->command);
 905 #endif
 906                 temp=host->hostt->command (SCpnt);
 907                 SCpnt->result = temp;
 908 #ifdef DEBUG_DELAY
 909         clock = jiffies + 400;
 910         while (jiffies < clock);
 911         printk("done(host = %d, result = %04x) : routine at %08x\n", host->host_no, temp, done);
 912 #endif
 913                 scsi_done(SCpnt);
 914                 }       
 915 #ifdef DEBUG
 916         printk("leaving internal_cmnd()\n");
 917 #endif
 918         }       
 919 
 920 static void scsi_request_sense (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 921         {
 922         unsigned int flags;
 923         
 924         save_flags(flags);
 925         cli();
 926         SCpnt->flags |= WAS_SENSE | ASKED_FOR_SENSE;
 927         update_timeout(SCpnt, SENSE_TIMEOUT);
 928         restore_flags(flags);
 929         
 930 
 931         memcpy ((void *) SCpnt->cmnd , (void *) generic_sense,
 932                 sizeof(generic_sense));
 933 
 934         SCpnt->cmnd[1] = SCpnt->lun << 5;       
 935         SCpnt->cmnd[4] = sizeof(SCpnt->sense_buffer);
 936 
 937         SCpnt->request_buffer = &SCpnt->sense_buffer;
 938         SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
 939         SCpnt->use_sg = 0;
 940         SCpnt->cmd_len = COMMAND_SIZE(SCpnt->cmnd[0]);
 941         internal_cmnd (SCpnt);
 942         }
 943 
 944 
 945 
 946 /*
 947         scsi_do_cmd sends all the commands out to the low-level driver.  It 
 948         handles the specifics required for each low level driver - ie queued 
 949         or non queued.  It also prevents conflicts when different high level 
 950         drivers go for the same host at the same time.
 951 */
 952 
 953 void scsi_do_cmd (Scsi_Cmnd * SCpnt, const void *cmnd , 
     /* [previous][next][first][last][top][bottom][index][help] */
 954                   void *buffer, unsigned bufflen, void (*done)(Scsi_Cmnd *),
 955                   int timeout, int retries 
 956                    )
 957         {
 958         unsigned long flags;
 959         struct Scsi_Host * host = SCpnt->host;
 960 
 961 #ifdef DEBUG
 962         {
 963         int i;  
 964         int target = SCpnt->target;
 965         printk ("scsi_do_cmd (host = %d, target = %d, buffer =%08x, "
 966                 "bufflen = %d, done = %08x, timeout = %d, retries = %d)\n"
 967                 "command : " , host->host_no, target, buffer, bufflen, done, timeout, retries);
 968         for (i = 0; i < 10; ++i)
 969                 printk ("%02x  ", ((unsigned char *) cmnd)[i]); 
 970         printk("\n");
 971       };
 972 #endif
 973         
 974         if (!host)
 975                 {
 976                 panic ("Invalid or not present host.\n");
 977                 }
 978 
 979         
 980 /*
 981         We must prevent reentrancy to the lowlevel host driver.  This prevents 
 982         it - we enter a loop until the host we want to talk to is not busy.   
 983         Race conditions are prevented, as interrupts are disabled in between the
 984         time we check for the host being not busy, and the time we mark it busy
 985         ourselves.
 986 */
 987 
 988         SCpnt->pid = scsi_pid++; 
 989 
 990         for(;;) {
 991 
 992           save_flags(flags);
 993           cli();
 994 
 995           if (host->can_queue &&
 996                 ((host->block && host_active && host != host_active) ||
 997                  (host->block && host_next && host != host_next) ||
 998                  host->host_busy >= host->can_queue)) {
 999 
1000              if (intr_count) 
1001                 panic("scsi: queueing to inactive host while in interrupt.\n");
1002 
1003              if (host->block && !host_next && host_active 
1004                                            && host != host_active) 
1005                 host_next = host;
1006 
1007              restore_flags(flags);
1008              SCSI_SLEEP(&host->host_wait, 
1009                        ((host->block && host_active && host != host_active) ||
1010                         (host->block && host_next && host != host_next) ||
1011                         host->host_busy >= host->can_queue));
1012              } 
1013 
1014           else {
1015              host->host_busy++;
1016 
1017              if (host->block) {
1018 
1019                 if (!host_active) {
1020                    max_active = 0;
1021                    host_active = host;
1022                    host_next = NULL;
1023                    }
1024                 else if (max_active > 7 && !host_next) 
1025                    host_next = host->block;
1026 
1027                 max_active++;
1028                 }
1029 
1030              restore_flags(flags);
1031              break;
1032              }
1033           }
1034 /*
1035         Our own function scsi_done (which marks the host as not busy, disables 
1036         the timeout counter, etc) will be called by us or by the 
1037         scsi_hosts[host].queuecommand() function needs to also call
1038         the completion function for the high level driver.
1039 
1040 */
1041 
1042         memcpy ((void *) SCpnt->data_cmnd , (void *) cmnd, 12);
1043 #if 0
1044         SCpnt->host = host;
1045         SCpnt->target = target;
1046         SCpnt->lun = (SCpnt->data_cmnd[1] >> 5);
1047 #endif
1048         SCpnt->bufflen = bufflen;
1049         SCpnt->buffer = buffer;
1050         SCpnt->flags=0;
1051         SCpnt->retries=0;
1052         SCpnt->allowed=retries;
1053         SCpnt->done = done;
1054         SCpnt->timeout_per_command = timeout;
1055                                 
1056         memcpy ((void *) SCpnt->cmnd , (void *) cmnd, 12);
1057         /* Zero the sense buffer.  Some host adapters automatically request
1058            sense on error.  0 is not a valid sense code.  */
1059         memset ((void *) SCpnt->sense_buffer, 0, sizeof SCpnt->sense_buffer);
1060         SCpnt->request_buffer = buffer;
1061         SCpnt->request_bufflen = bufflen;
1062         SCpnt->old_use_sg = SCpnt->use_sg;
1063         if (SCpnt->cmd_len == 0)
1064                 SCpnt->cmd_len = COMMAND_SIZE(SCpnt->cmnd[0]);
1065         SCpnt->old_cmd_len = SCpnt->cmd_len;
1066 
1067         /* Start the timer ticking.  */
1068 
1069         SCpnt->internal_timeout = 0;
1070         SCpnt->abort_reason = 0;
1071         internal_cmnd (SCpnt);
1072 
1073 #ifdef DEBUG
1074         printk ("Leaving scsi_do_cmd()\n");
1075 #endif
1076         }
1077 
1078 
1079 
1080 /*
1081         The scsi_done() function disables the timeout timer for the scsi host, 
1082         marks the host as not busy, and calls the user specified completion 
1083         function for that host's current command.
1084 */
1085 
1086 static void reset (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1087 {
1088 #ifdef DEBUG
1089         printk("scsi: reset(%d)\n", SCpnt->host->host_no);
1090 #endif
1091         
1092         SCpnt->flags |= (WAS_RESET | IS_RESETTING);
1093         scsi_reset(SCpnt);
1094         
1095 #ifdef DEBUG
1096         printk("performing request sense\n");
1097 #endif
1098         
1099 #if 0  /* FIXME - remove this when done */
1100         if(SCpnt->flags & NEEDS_JUMPSTART) {
1101           SCpnt->flags &= ~NEEDS_JUMPSTART;
1102           scsi_request_sense (SCpnt);
1103         };
1104 #endif
1105 }
1106         
1107         
1108 
1109 static int check_sense (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1110         {
1111   /* If there is no sense information, request it.  If we have already
1112      requested it, there is no point in asking again - the firmware must be
1113      confused. */
1114   if (((SCpnt->sense_buffer[0] & 0x70) >> 4) != 7) {
1115     if(!(SCpnt->flags & ASKED_FOR_SENSE))
1116       return SUGGEST_SENSE;
1117     else
1118       return SUGGEST_RETRY;
1119       }
1120   
1121   SCpnt->flags &= ~ASKED_FOR_SENSE;
1122 
1123 #ifdef DEBUG_INIT
1124         printk("scsi%d : ", SCpnt->host->host_no);
1125         print_sense("", SCpnt);
1126         printk("\n");
1127 #endif
1128                 if (SCpnt->sense_buffer[2] &0xe0)
1129                   return SUGGEST_ABORT;
1130 
1131                 switch (SCpnt->sense_buffer[2] & 0xf)
1132                 {
1133                 case NO_SENSE:
1134                         return 0;
1135                 case RECOVERED_ERROR:
1136                         return SUGGEST_IS_OK;
1137 
1138                 case ABORTED_COMMAND:
1139                         return SUGGEST_RETRY;   
1140                 case NOT_READY:
1141                 case UNIT_ATTENTION:
1142                         return SUGGEST_ABORT;
1143 
1144                 /* these three are not supported */     
1145                 case COPY_ABORTED:
1146                 case VOLUME_OVERFLOW:
1147                 case MISCOMPARE:
1148         
1149                 case MEDIUM_ERROR:
1150                         return SUGGEST_REMAP;
1151                 case BLANK_CHECK:
1152                 case DATA_PROTECT:
1153                 case HARDWARE_ERROR:
1154                 case ILLEGAL_REQUEST:
1155                 default:
1156                         return SUGGEST_ABORT;
1157                 }
1158               }
1159 
1160 /* This function is the mid-level interrupt routine, which decides how
1161  *  to handle error conditions.  Each invocation of this function must
1162  *  do one and *only* one of the following:
1163  *
1164  *  (1) Call last_cmnd[host].done.  This is done for fatal errors and
1165  *      normal completion, and indicates that the handling for this
1166  *      request is complete.
1167  *  (2) Call internal_cmnd to requeue the command.  This will result in
1168  *      scsi_done being called again when the retry is complete.
1169  *  (3) Call scsi_request_sense.  This asks the host adapter/drive for
1170  *      more information about the error condition.  When the information
1171  *      is available, scsi_done will be called again.
1172  *  (4) Call reset().  This is sort of a last resort, and the idea is that
1173  *      this may kick things loose and get the drive working again.  reset()
1174  *      automatically calls scsi_request_sense, and thus scsi_done will be
1175  *      called again once the reset is complete.
1176  *
1177  *      If none of the above actions are taken, the drive in question
1178  * will hang. If more than one of the above actions are taken by
1179  * scsi_done, then unpredictable behavior will result.
1180  */
1181 static void scsi_done (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1182         {
1183         int status=0;
1184         int exit=0;
1185         int checked;
1186         int oldto;
1187         struct Scsi_Host * host = SCpnt->host;
1188         int result = SCpnt->result;
1189         oldto = update_timeout(SCpnt, 0);
1190 
1191 #ifdef DEBUG_TIMEOUT
1192         if(result) printk("Non-zero result in scsi_done %x %d:%d\n",
1193                           result, SCpnt->target, SCpnt->lun);
1194 #endif
1195 
1196         /* If we requested an abort, (and we got it) then fix up the return
1197            status to say why */
1198         if(host_byte(result) == DID_ABORT && SCpnt->abort_reason)
1199           SCpnt->result = result = (result & 0xff00ffff) | 
1200             (SCpnt->abort_reason << 16);
1201 
1202 
1203 #define FINISHED 0
1204 #define MAYREDO  1
1205 #define REDO     3
1206 #define PENDING  4
1207 
1208 #ifdef DEBUG
1209         printk("In scsi_done(host = %d, result = %06x)\n", host->host_no, result);
1210 #endif
1211 
1212         if(SCpnt->flags & WAS_SENSE)
1213         {
1214                 SCpnt->use_sg = SCpnt->old_use_sg;
1215                 SCpnt->cmd_len = SCpnt->old_cmd_len;
1216         }
1217 
1218         switch (host_byte(result))      
1219         {
1220         case DID_OK:
1221                 if (status_byte(result) && (SCpnt->flags & WAS_SENSE))
1222                         /* Failed to obtain sense information */
1223                         {
1224                         SCpnt->flags &= ~WAS_SENSE;
1225                         SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1226 
1227                         if (!(SCpnt->flags & WAS_RESET))
1228                                 {
1229                                 printk("scsi%d : target %d lun %d request sense failed, performing reset.\n", 
1230                                         SCpnt->host->host_no, SCpnt->target, SCpnt->lun);
1231                                 reset(SCpnt);
1232                                 return;
1233                                 }
1234                         else
1235                                 {
1236                                 exit = (DRIVER_HARD | SUGGEST_ABORT);
1237                                 status = FINISHED;
1238                                 }
1239                         }
1240                 else switch(msg_byte(result))
1241                         {
1242                         case COMMAND_COMPLETE:
1243                         switch (status_byte(result))
1244                         {
1245                         case GOOD:
1246                                 if (SCpnt->flags & WAS_SENSE)
1247                                         {
1248 #ifdef DEBUG
1249         printk ("In scsi_done, GOOD status, COMMAND COMPLETE, parsing sense information.\n");
1250 #endif
1251 
1252                                         SCpnt->flags &= ~WAS_SENSE;
1253                                         SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1254         
1255                                         switch (checked = check_sense(SCpnt))
1256                                         {
1257                                         case SUGGEST_SENSE:
1258                                         case 0: 
1259 #ifdef DEBUG
1260         printk("NO SENSE.  status = REDO\n");
1261 #endif
1262 
1263                                                 update_timeout(SCpnt, oldto);
1264                                                 status = REDO;
1265                                                 break;
1266                                         case SUGGEST_IS_OK:
1267                                                 break;
1268                                         case SUGGEST_REMAP:                     
1269                                         case SUGGEST_RETRY: 
1270 #ifdef DEBUG
1271         printk("SENSE SUGGEST REMAP or SUGGEST RETRY - status = MAYREDO\n");
1272 #endif
1273 
1274                                                 status = MAYREDO;
1275                                                 exit = DRIVER_SENSE | SUGGEST_RETRY;
1276                                                 break;
1277                                         case SUGGEST_ABORT:
1278 #ifdef DEBUG
1279         printk("SENSE SUGGEST ABORT - status = FINISHED");
1280 #endif
1281 
1282                                                 status = FINISHED;
1283                                                 exit =  DRIVER_SENSE | SUGGEST_ABORT;
1284                                                 break;
1285                                         default:
1286                                                 printk ("Internal error %s %d \n", __FILE__, 
1287                                                         __LINE__);
1288                                         }                          
1289                                         }       
1290                                 else
1291                                         {
1292 #ifdef DEBUG
1293         printk("COMMAND COMPLETE message returned, status = FINISHED. \n");
1294 #endif
1295 
1296                                         exit =  DRIVER_OK;
1297                                         status = FINISHED;
1298                                         }
1299                                 break;  
1300 
1301                         case CHECK_CONDITION:
1302                                 switch (check_sense(SCpnt))
1303                                   {
1304                                   case 0: 
1305                                     update_timeout(SCpnt, oldto);
1306                                     status = REDO;
1307                                     break;
1308                                   case SUGGEST_REMAP:                   
1309                                   case SUGGEST_RETRY:
1310                                     status = MAYREDO;
1311                                     exit = DRIVER_SENSE | SUGGEST_RETRY;
1312                                     break;
1313                                   case SUGGEST_ABORT:
1314                                     status = FINISHED;
1315                                     exit =  DRIVER_SENSE | SUGGEST_ABORT;
1316                                     break;
1317                                   case SUGGEST_SENSE:
1318                                 scsi_request_sense (SCpnt);
1319                                 status = PENDING;
1320                                 break;          
1321                                   }
1322                                 break;          
1323                         
1324                         case CONDITION_GOOD:
1325                         case INTERMEDIATE_GOOD:
1326                         case INTERMEDIATE_C_GOOD:
1327                                 break;
1328                                 
1329                         case BUSY:
1330                                 update_timeout(SCpnt, oldto);
1331                                 status = REDO;
1332                                 break;
1333 
1334                         case RESERVATION_CONFLICT:
1335                                 printk("scsi%d : RESERVATION CONFLICT performing reset.\n", 
1336                                         SCpnt->host->host_no);
1337                                 reset(SCpnt);
1338                                 return;
1339 #if 0
1340                                 exit = DRIVER_SOFT | SUGGEST_ABORT;
1341                                 status = MAYREDO;
1342                                 break;
1343 #endif
1344                         default:
1345                                 printk ("Internal error %s %d \n"
1346                                         "status byte = %d \n", __FILE__, 
1347                                         __LINE__, status_byte(result));
1348                                 
1349                         }
1350                         break;
1351                         default:
1352                                 panic("scsi: unsupported message byte %d received\n", msg_byte(result)); 
1353                         }
1354                         break;
1355         case DID_TIME_OUT:      
1356 #ifdef DEBUG
1357         printk("Host returned DID_TIME_OUT - ");
1358 #endif
1359 
1360                 if (SCpnt->flags & WAS_TIMEDOUT)
1361                         {
1362 #ifdef DEBUG
1363         printk("Aborting\n");
1364 #endif  
1365                         exit = (DRIVER_TIMEOUT | SUGGEST_ABORT);
1366                         }               
1367                 else 
1368                         {
1369 #ifdef DEBUG
1370                         printk ("Retrying.\n");
1371 #endif
1372                         SCpnt->flags  |= WAS_TIMEDOUT;
1373                         SCpnt->internal_timeout &= ~IN_ABORT;
1374                         status = REDO;
1375                         }
1376                 break;
1377         case DID_BUS_BUSY:
1378         case DID_PARITY:
1379                 status = REDO;
1380                 break;
1381         case DID_NO_CONNECT:
1382 #ifdef DEBUG
1383                 printk("Couldn't connect.\n");
1384 #endif
1385                 exit  = (DRIVER_HARD | SUGGEST_ABORT);
1386                 break;
1387         case DID_ERROR: 
1388                 status = MAYREDO;
1389                 exit = (DRIVER_HARD | SUGGEST_ABORT);
1390                 break;
1391         case DID_BAD_TARGET:
1392         case DID_ABORT:
1393                 exit = (DRIVER_INVALID | SUGGEST_ABORT);
1394                 break;  
1395         case DID_RESET:
1396                 if (SCpnt->flags & IS_RESETTING)
1397                         {
1398                         SCpnt->flags &= ~IS_RESETTING;
1399                         status = REDO;
1400                         break;
1401                         }
1402 
1403                 if(msg_byte(result) == GOOD &&
1404                       status_byte(result) == CHECK_CONDITION) {
1405                         switch (check_sense(SCpnt)) {
1406                         case 0: 
1407                             update_timeout(SCpnt, oldto);
1408                             status = REDO;
1409                             break;
1410                         case SUGGEST_REMAP:                     
1411                         case SUGGEST_RETRY:
1412                             status = MAYREDO;
1413                             exit = DRIVER_SENSE | SUGGEST_RETRY;
1414                             break;
1415                         case SUGGEST_ABORT:
1416                             status = FINISHED;
1417                             exit =  DRIVER_SENSE | SUGGEST_ABORT;
1418                             break;
1419                         case SUGGEST_SENSE:
1420                               scsi_request_sense (SCpnt);
1421                               status = PENDING;
1422                               break;
1423                         }
1424                 } else {
1425                 status=REDO;
1426                 exit = SUGGEST_RETRY;
1427                 }
1428                 break;
1429         default :               
1430                 exit = (DRIVER_ERROR | SUGGEST_DIE);
1431         }
1432 
1433         switch (status) 
1434                 {
1435                 case FINISHED:
1436                 case PENDING:
1437                         break;
1438                 case MAYREDO:
1439 
1440 #ifdef DEBUG
1441         printk("In MAYREDO, allowing %d retries, have %d\n",
1442                SCpnt->allowed, SCpnt->retries);
1443 #endif
1444 
1445                         if ((++SCpnt->retries) < SCpnt->allowed)
1446                         {
1447                         if ((SCpnt->retries >= (SCpnt->allowed >> 1))
1448                             && !(SCpnt->flags & WAS_RESET))
1449                                 {
1450                                         printk("scsi%d : resetting for second half of retries.\n",
1451                                                 SCpnt->host->host_no);
1452                                         reset(SCpnt);
1453                                         break;
1454                                 }
1455 
1456                         }
1457                         else
1458                                 {
1459                                 status = FINISHED;
1460                                 break;
1461                                 }
1462                         /* fall through to REDO */
1463 
1464                 case REDO:
1465 
1466                         if (host->block) scsi_maybe_deadlocked = 1;
1467 
1468                         if (SCpnt->flags & WAS_SENSE)                   
1469                                 scsi_request_sense(SCpnt);      
1470                         else    
1471                           {
1472                             memcpy ((void *) SCpnt->cmnd,
1473                                     (void*) SCpnt->data_cmnd, 
1474                                     sizeof(SCpnt->data_cmnd));
1475                             SCpnt->request_buffer = SCpnt->buffer;
1476                             SCpnt->request_bufflen = SCpnt->bufflen;
1477                             SCpnt->use_sg = SCpnt->old_use_sg;
1478                             SCpnt->cmd_len = SCpnt->old_cmd_len;
1479                             internal_cmnd (SCpnt);
1480                           };
1481                         break;  
1482                 default: 
1483                         INTERNAL_ERROR;
1484                 }
1485 
1486 
1487         if (status == FINISHED) {
1488 #ifdef DEBUG
1489            printk("Calling done function - at address %08x\n", SCpnt->done);
1490 #endif
1491            host->host_busy--; /* Indicate that we are free */
1492 
1493            if (host->block && host->host_busy == 0) {
1494               struct Scsi_Host * block;
1495 
1496               block = host_next;
1497               host_active = NULL;
1498 
1499               if (block) wake_up(&block->host_wait);
1500 
1501               for (block = host->block; block != host; block = block->block)
1502                  wake_up(&block->host_wait);
1503 
1504               host_next = NULL;
1505 
1506               if (scsi_maybe_deadlocked) {
1507                  scsi_maybe_deadlocked = 0;
1508                  restart_all();
1509                  }
1510 
1511               }
1512 
1513            wake_up(&host->host_wait);
1514            SCpnt->result = result | ((exit & 0xff) << 24);
1515            SCpnt->use_sg = SCpnt->old_use_sg;
1516            SCpnt->cmd_len = SCpnt->old_cmd_len;
1517            SCpnt->done (SCpnt);
1518            }
1519 
1520 #undef FINISHED
1521 #undef REDO
1522 #undef MAYREDO
1523 #undef PENDING
1524         }
1525 
1526 /*
1527         The scsi_abort function interfaces with the abort() function of the host
1528         we are aborting, and causes the current command to not complete.  The 
1529         caller should deal with any error messages or status returned on the 
1530         next call.
1531         
1532         This will not be called reentrantly for a given host.
1533 */
1534         
1535 /*
1536         Since we're nice guys and specified that abort() and reset()
1537         can be non-reentrant.  The internal_timeout flags are used for
1538         this.
1539 */
1540 
1541 
1542 int scsi_abort (Scsi_Cmnd * SCpnt, int why, int pid)
     /* [previous][next][first][last][top][bottom][index][help] */
1543         {
1544         int oldto;
1545         unsigned long flags;
1546         struct Scsi_Host * host = SCpnt->host;
1547         
1548         while(1)        
1549                 {
1550                 save_flags(flags);
1551                 cli();
1552 
1553                 /*
1554                  * Protect against races here.  If the command is done, or we are
1555                  * on a different command forget it.
1556                  */
1557                 if (SCpnt->request.dev == -1 || pid != SCpnt->pid) {
1558                   restore_flags(flags);
1559                   return 0;
1560                 }
1561 
1562                 if (SCpnt->internal_timeout & IN_ABORT) 
1563                         {
1564                         restore_flags(flags);
1565                         while (SCpnt->internal_timeout & IN_ABORT);
1566                         }
1567                 else
1568                         {       
1569                         SCpnt->internal_timeout |= IN_ABORT;
1570                         oldto = update_timeout(SCpnt, ABORT_TIMEOUT);
1571 
1572                         if ((SCpnt->flags & IS_RESETTING) && 
1573                             SCpnt->device->soft_reset) {
1574                           /* OK, this command must have died when we did the
1575                              reset.  The device itself must have lied. */
1576                           printk("Stale command on %d:%d appears to have died when"
1577                                  " the bus was reset\n", SCpnt->target, SCpnt->lun);
1578                         }
1579                         
1580                         restore_flags(flags);
1581                         if (!host->host_busy) {
1582                           SCpnt->internal_timeout &= ~IN_ABORT;
1583                           update_timeout(SCpnt, oldto);
1584                           return 0;
1585                         }
1586                         printk("scsi : aborting command due to timeout : pid %lu, scsi%d, id %d, lun %d ",
1587                                SCpnt->pid, SCpnt->host->host_no, (int) SCpnt->target, (int) 
1588                                SCpnt->lun);
1589                         print_command (SCpnt->cmnd);
1590                         if (SCpnt->request.dev == -1 || pid != SCpnt->pid)
1591                           return 0;
1592                         SCpnt->abort_reason = why;
1593                         switch(host->hostt->abort(SCpnt)) {
1594                           /* We do not know how to abort.  Try waiting another
1595                              time increment and see if this helps. Set the
1596                              WAS_TIMEDOUT flag set so we do not try this twice
1597                              */
1598                         case SCSI_ABORT_BUSY: /* Tough call - returning 1 from
1599                                                  this is too severe */
1600                         case SCSI_ABORT_SNOOZE:
1601                           if(why == DID_TIME_OUT) {
1602                             save_flags(flags);
1603                             cli();
1604                             SCpnt->internal_timeout &= ~IN_ABORT;
1605                             if(SCpnt->flags & WAS_TIMEDOUT) {
1606                               restore_flags(flags);
1607                               return 1; /* Indicate we cannot handle this.
1608                                            We drop down into the reset handler
1609                                            and try again */
1610                             } else {
1611                               SCpnt->flags |= WAS_TIMEDOUT;
1612                               oldto = SCpnt->timeout_per_command;
1613                               update_timeout(SCpnt, oldto);
1614                             }
1615                             restore_flags(flags);
1616                           }
1617                           return 0;
1618                         case SCSI_ABORT_PENDING:
1619                           if(why != DID_TIME_OUT) {
1620                             save_flags(flags);
1621                             cli();
1622                             update_timeout(SCpnt, oldto);
1623                             restore_flags(flags);
1624                           }
1625                           return 0;
1626                         case SCSI_ABORT_SUCCESS:
1627                           /* We should have already aborted this one.  No
1628                              need to adjust timeout */
1629                         case SCSI_ABORT_NOT_RUNNING:
1630                           SCpnt->internal_timeout &= ~IN_ABORT;
1631                           update_timeout(SCpnt, 0);
1632                           return 0;
1633                         case SCSI_ABORT_ERROR:
1634                         default:
1635                           SCpnt->internal_timeout &= ~IN_ABORT;
1636                           return 1;
1637                         }
1638                       }
1639               } 
1640       }
1641      
1642 int scsi_reset (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1643         {
1644         int temp, oldto;
1645         unsigned long flags;
1646         Scsi_Cmnd * SCpnt1;
1647         struct Scsi_Host * host = SCpnt->host;
1648         
1649 #ifdef DEBUG
1650         printk("Danger Will Robinson! - SCSI bus for host %d is being reset.\n",host->host_no);
1651 #endif
1652         while (1) {
1653                 save_flags(flags);
1654                 cli();
1655                 if (SCpnt->internal_timeout & IN_RESET)
1656                         {
1657                         restore_flags(flags);
1658                         while (SCpnt->internal_timeout & IN_RESET);
1659                         }
1660                 else
1661                         {
1662                         SCpnt->internal_timeout |= IN_RESET;
1663                         oldto = update_timeout(SCpnt, RESET_TIMEOUT);   
1664                                         
1665                         if (host->host_busy)
1666                                 {       
1667                                 restore_flags(flags);
1668                                 SCpnt1 = host->host_queue;
1669                                 while(SCpnt1) {
1670                                   if (SCpnt1->request.dev > 0) {
1671 #if 0                             
1672                                     if (!(SCpnt1->flags & IS_RESETTING) && 
1673                                       !(SCpnt1->internal_timeout & IN_ABORT))
1674                                     scsi_abort(SCpnt1, DID_RESET, SCpnt->pid);
1675 #endif
1676                                     SCpnt1->flags |= IS_RESETTING;
1677                                   }
1678                                   SCpnt1 = SCpnt1->next;
1679                                 };
1680 
1681                                 temp = host->hostt->reset(SCpnt);       
1682                                 }                               
1683                         else
1684                                 {
1685                                 host->host_busy++;
1686 
1687                                 if (host->block) {
1688                                    host_active = host;
1689                                    host_next = NULL;
1690                                    }
1691         
1692                                 restore_flags(flags);
1693                                 temp = host->hostt->reset(SCpnt);
1694                                 host->last_reset = jiffies;
1695                                 host->host_busy--;
1696 
1697                                 }
1698 
1699                         if (host->block && host->host_busy == 0) {
1700                            host_active = NULL;
1701                            host_next = NULL;
1702                            restart_all();
1703                            }
1704 
1705 
1706 #ifdef DEBUG
1707                         printk("scsi reset function returned %d\n", temp);
1708 #endif
1709                         switch(temp) {
1710                         case SCSI_RESET_SUCCESS:
1711                           save_flags(flags);
1712                           cli();
1713                           SCpnt->internal_timeout &= ~IN_RESET;
1714                           update_timeout(SCpnt, oldto);
1715                           restore_flags(flags);
1716                           return 0;
1717                         case SCSI_RESET_PENDING:
1718                           return 0;
1719                         case SCSI_RESET_PUNT:
1720                         case SCSI_RESET_WAKEUP:
1721                           SCpnt->internal_timeout &= ~IN_RESET;
1722                           scsi_request_sense (SCpnt);
1723                           return 0;
1724                         case SCSI_RESET_SNOOZE:                   
1725                           /* In this case, we set the timeout field to 0
1726                              so that this command does not time out any more,
1727                              and we return 1 so that we get a message on the
1728                              screen. */
1729                           save_flags(flags);
1730                           cli();
1731                           SCpnt->internal_timeout &= ~IN_RESET;
1732                           update_timeout(SCpnt, 0);
1733                           restore_flags(flags);
1734                           /* If you snooze, you lose... */
1735                         case SCSI_RESET_ERROR:
1736                         default:
1737                           return 1;
1738                         }
1739         
1740                         return temp;    
1741                         }
1742                 }
1743         }
1744                          
1745 
1746 static void scsi_main_timeout(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1747         {
1748         /*
1749                 We must not enter update_timeout with a timeout condition still pending.
1750         */
1751 
1752         int timed_out, pid;
1753         unsigned long flags;
1754         struct Scsi_Host * host;
1755         Scsi_Cmnd * SCpnt = NULL;
1756 
1757         do      {       
1758                 save_flags(flags);
1759                 cli();
1760 
1761                 update_timeout(NULL, 0);
1762         /*
1763                 Find all timers such that they have 0 or negative (shouldn't happen)
1764                 time remaining on them.
1765         */
1766                         
1767                 timed_out = 0;
1768                 for(host = scsi_hostlist; host; host = host->next) {
1769                   for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
1770                     if (SCpnt->timeout == -1)
1771                       {
1772                         SCpnt->timeout = 0;
1773                         pid = SCpnt->pid;
1774                         restore_flags(flags);
1775                         scsi_times_out(SCpnt, pid);
1776                         ++timed_out; 
1777                         save_flags(flags);
1778                         cli();
1779                       }
1780                 };
1781               } while (timed_out);      
1782         restore_flags(flags);
1783       }
1784 
1785 /*
1786         The strategy is to cause the timer code to call scsi_times_out()
1787         when the soonest timeout is pending.  
1788         The arguments are used when we are queueing a new command, because
1789         we do not want to subtract the time used from this time, but when we
1790         set the timer, we want to take this value into account.
1791 */
1792         
1793 static int update_timeout(Scsi_Cmnd * SCset, int timeout)
     /* [previous][next][first][last][top][bottom][index][help] */
1794         {
1795         unsigned int least, used;
1796         unsigned int oldto;
1797         unsigned long flags;
1798         struct Scsi_Host * host;
1799         Scsi_Cmnd * SCpnt = NULL;
1800 
1801         save_flags(flags);
1802         cli();
1803 
1804 /* 
1805         Figure out how much time has passed since the last time the timeouts 
1806         were updated 
1807 */
1808         used = (time_start) ? (jiffies - time_start) : 0;
1809 
1810 /*
1811         Find out what is due to timeout soonest, and adjust all timeouts for
1812         the amount of time that has passed since the last time we called 
1813         update_timeout. 
1814 */
1815         
1816         oldto = 0;
1817 
1818         if(SCset){
1819           oldto = SCset->timeout - used;
1820           SCset->timeout = timeout + used;
1821         };
1822 
1823         least = 0xffffffff;
1824 
1825         for(host = scsi_hostlist; host; host = host->next)
1826           for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
1827             if (SCpnt->timeout > 0) {
1828               SCpnt->timeout -= used;
1829               if(SCpnt->timeout <= 0) SCpnt->timeout = -1;
1830               if(SCpnt->timeout > 0 && SCpnt->timeout < least)
1831                 least = SCpnt->timeout;
1832             };
1833 
1834 /*
1835         If something is due to timeout again, then we will set the next timeout 
1836         interrupt to occur.  Otherwise, timeouts are disabled.
1837 */
1838         
1839         if (least != 0xffffffff)
1840                 {
1841                 time_start = jiffies;   
1842                 timer_table[SCSI_TIMER].expires = (time_elapsed = least) + jiffies;     
1843                 timer_active |= 1 << SCSI_TIMER;
1844                 }
1845         else
1846                 {
1847                 timer_table[SCSI_TIMER].expires = time_start = time_elapsed = 0;
1848                 timer_active &= ~(1 << SCSI_TIMER);
1849                 }       
1850         restore_flags(flags);
1851         return oldto;
1852         }               
1853 
1854 
1855 static unsigned char * dma_malloc_freelist = NULL;
1856 static int scsi_need_isa_bounce_buffers;
1857 static unsigned int dma_sectors = 0;
1858 unsigned int dma_free_sectors = 0;
1859 unsigned int need_isa_buffer = 0;
1860 static unsigned char ** dma_malloc_pages = NULL;
1861 #define MALLOC_PAGEBITS 12
1862 
1863 static int scsi_register_host(Scsi_Host_Template *);
1864 static void scsi_unregister_host(Scsi_Host_Template *);
1865 
1866 void *scsi_malloc(unsigned int len)
     /* [previous][next][first][last][top][bottom][index][help] */
1867 {
1868   unsigned int nbits, mask;
1869   unsigned long flags;
1870   int i, j;
1871   if((len & 0x1ff) || len > (1<<MALLOC_PAGEBITS))
1872     return NULL;
1873   
1874   save_flags(flags);
1875   cli();
1876   nbits = len >> 9;
1877   mask = (1 << nbits) - 1;
1878   
1879   for(i=0;i < (dma_sectors >> (MALLOC_PAGEBITS - 9)); i++)
1880     for(j=0; j<=(sizeof(*dma_malloc_freelist) * 8) - nbits; j++){
1881       if ((dma_malloc_freelist[i] & (mask << j)) == 0){
1882         dma_malloc_freelist[i] |= (mask << j);
1883         restore_flags(flags);
1884         dma_free_sectors -= nbits;
1885 #ifdef DEBUG
1886         printk("SMalloc: %d %x ",len, dma_malloc_pages[i] + (j << 9));
1887 #endif
1888         return (void *) ((unsigned long) dma_malloc_pages[i] + (j << 9));
1889       };
1890     };
1891   restore_flags(flags);
1892   return NULL;  /* Nope.  No more */
1893 }
1894 
1895 int scsi_free(void *obj, unsigned int len)
     /* [previous][next][first][last][top][bottom][index][help] */
1896 {
1897   int page, sector, nbits, mask;
1898   long offset;
1899   unsigned long flags;
1900 
1901 #ifdef DEBUG
1902   printk("Sfree %x %d\n",obj, len);
1903 #endif
1904 
1905    offset = -1;
1906   for (page = 0; page < (dma_sectors >> 3); page++)
1907         if ((unsigned long) obj >= (unsigned long) dma_malloc_pages[page] &&
1908                 (unsigned long) obj < (unsigned long) dma_malloc_pages[page] + (1 << MALLOC_PAGEBITS))
1909                 {
1910                         offset = ((unsigned long) obj) - ((unsigned long)dma_malloc_pages[page]);
1911                         break;
1912                 }
1913                  
1914   if (page == (dma_sectors >> 3)) panic("Bad offset");
1915   sector = offset >> 9;
1916   if(sector >= dma_sectors) panic ("Bad page");
1917 
1918   sector = (offset >> 9) & (sizeof(*dma_malloc_freelist) * 8 - 1);
1919   nbits = len >> 9;
1920   mask = (1 << nbits) - 1;
1921 
1922   if ((mask << sector) > 0xffff) panic ("Bad memory alignment");
1923 
1924   save_flags(flags);
1925   cli();
1926   if(dma_malloc_freelist[page] & (mask << sector) != (mask<<sector))
1927     panic("Trying to free unused memory");
1928 
1929   dma_free_sectors += nbits;
1930   dma_malloc_freelist[page] &= ~(mask << sector);
1931   restore_flags(flags);
1932   return 0;
1933 }
1934 
1935 
1936 /* These are special functions that can be used to obtain memory at boot time.
1937    They act line a malloc function, but they simply take memory from the
1938    pool */
1939 
1940 static unsigned long scsi_init_memory_start = 0;
1941 int scsi_loadable_module_flag; /* Set after we scan builtin drivers */
1942 
1943 void * scsi_init_malloc(unsigned int size, int priority)
     /* [previous][next][first][last][top][bottom][index][help] */
1944 {
1945   unsigned long retval;
1946   if(scsi_loadable_module_flag) {
1947     retval = (unsigned long) kmalloc(size, priority);
1948   } else {
1949     retval = scsi_init_memory_start;
1950     scsi_init_memory_start += size;
1951   }
1952   return (void *) retval;
1953 }
1954 
1955 
1956 void scsi_init_free(char * ptr, unsigned int size)
     /* [previous][next][first][last][top][bottom][index][help] */
1957 { /* FIXME - not right.  We need to compare addresses to see whether this was
1958      kmalloc'd or not */
1959   if((unsigned long) ptr > scsi_init_memory_start) {
1960     kfree(ptr);
1961   } else {
1962     if(((unsigned long) ptr) + size == scsi_init_memory_start)
1963       scsi_init_memory_start = (unsigned long) ptr;
1964   }
1965 }
1966 
1967 /*
1968         scsi_dev_init() is our initialization routine, which in turn calls host 
1969         initialization, bus scanning, and sd/st initialization routines.  It 
1970         should be called from main().
1971 */
1972 
1973 unsigned long scsi_dev_init (unsigned long memory_start,unsigned long memory_end)
     /* [previous][next][first][last][top][bottom][index][help] */
1974         {
1975         struct Scsi_Host * host = NULL;
1976         Scsi_Device * SDpnt;
1977         struct Scsi_Host * shpnt;
1978         struct Scsi_Device_Template * sdtpnt;
1979         Scsi_Cmnd * SCpnt;
1980         int i;
1981 #ifdef FOO_ON_YOU
1982         return;
1983 #endif  
1984 
1985         /* Init a few things so we can "malloc" memory. */
1986         scsi_loadable_module_flag = 0;
1987         scsi_init_memory_start = memory_start;
1988 
1989         timer_table[SCSI_TIMER].fn = scsi_main_timeout;
1990         timer_table[SCSI_TIMER].expires = 0;
1991 
1992         /* initialize all hosts */
1993         scsi_init(); 
1994                                 
1995         scsi_devices = (Scsi_Device *) NULL;
1996 
1997         for (shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
1998           scan_scsis(shpnt);           /* scan for scsi devices */
1999 
2000         for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2001           if(sdtpnt->init && sdtpnt->dev_noticed) (*sdtpnt->init)();
2002 
2003         for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
2004           int j;
2005           SDpnt->scsi_request_fn = NULL;
2006           for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2007               if(sdtpnt->attach) (*sdtpnt->attach)(SDpnt);
2008 
2009           if(SDpnt->attached){
2010             for(j=0;j<SDpnt->host->cmd_per_lun;j++){
2011               SCpnt = (Scsi_Cmnd *) scsi_init_malloc(sizeof(Scsi_Cmnd), GFP_ATOMIC);
2012               SCpnt->host = SDpnt->host;
2013               SCpnt->device = SDpnt;
2014               SCpnt->target = SDpnt->id;
2015               SCpnt->lun = SDpnt->lun;
2016               SCpnt->request.dev = -1; /* Mark not busy */
2017               SCpnt->use_sg = 0;
2018               SCpnt->old_use_sg = 0;
2019               SCpnt->old_cmd_len = 0;
2020               SCpnt->timeout = 0;
2021               SCpnt->underflow = 0;
2022               SCpnt->transfersize = 0;
2023               SCpnt->host_scribble = NULL;
2024               host = SDpnt->host;
2025               if(host->host_queue)
2026                 host->host_queue->prev = SCpnt;
2027               SCpnt->next = host->host_queue;
2028               SCpnt->prev = NULL;
2029               host->host_queue = SCpnt;
2030             };
2031           };
2032         };
2033 
2034         if (scsi_devicelist)
2035           dma_sectors = 16;  /* Base value we use */
2036 
2037         if (memory_end-1 > ISA_DMA_THRESHOLD)
2038           scsi_need_isa_bounce_buffers = 1;
2039         else
2040           scsi_need_isa_bounce_buffers = 0;
2041 
2042         for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
2043           host = SDpnt->host;
2044           
2045           if(SDpnt->type != TYPE_TAPE)
2046             dma_sectors += ((host->sg_tablesize * 
2047                              sizeof(struct scatterlist) + 511) >> 9) * 
2048                                host->cmd_per_lun;
2049           
2050           if(host->unchecked_isa_dma &&
2051              memory_end - 1 > ISA_DMA_THRESHOLD &&
2052              SDpnt->type != TYPE_TAPE) {
2053             dma_sectors += (PAGE_SIZE >> 9) * host->sg_tablesize *
2054               host->cmd_per_lun;
2055             need_isa_buffer++;
2056           };
2057         };
2058 
2059         dma_sectors = (dma_sectors + 15) & 0xfff0;
2060         dma_free_sectors = dma_sectors;  /* This must be a multiple of 16 */
2061 
2062         scsi_init_memory_start = (scsi_init_memory_start + 3) & 0xfffffffc;
2063         dma_malloc_freelist = (unsigned char *) 
2064           scsi_init_malloc(dma_sectors >> 3, GFP_ATOMIC);
2065         memset(dma_malloc_freelist, 0, dma_sectors >> 3);
2066 
2067         dma_malloc_pages = (unsigned char **) 
2068           scsi_init_malloc(dma_sectors >> 1, GFP_ATOMIC);
2069         memset(dma_malloc_pages, 0, dma_sectors >> 1);
2070  
2071         /* Some host adapters require buffers to be word aligned */
2072         if(scsi_init_memory_start & 1) scsi_init_memory_start++;
2073         
2074         for(i=0; i< dma_sectors >> 3; i++)
2075           dma_malloc_pages[i] = (unsigned char *) 
2076             scsi_init_malloc(PAGE_SIZE, GFP_ATOMIC | GFP_DMA);
2077 
2078 
2079         /* OK, now we finish the initialization by doing spin-up, read
2080            capacity, etc, etc */
2081         for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2082           if(sdtpnt->finish && sdtpnt->nr_dev)
2083             (*sdtpnt->finish)();
2084         
2085         scsi_loadable_module_flag = 1;
2086         return scsi_init_memory_start;
2087         }
2088 
2089 static void print_inquiry(unsigned char *data)
     /* [previous][next][first][last][top][bottom][index][help] */
2090 {
2091         int i;
2092 
2093         printk("  Vendor: ");
2094         for (i = 8; i < 16; i++)
2095                 {
2096                 if (data[i] >= 0x20 && i < data[4] + 5)
2097                         printk("%c", data[i]);
2098                 else
2099                         printk(" ");
2100                 }
2101 
2102         printk("  Model: ");
2103         for (i = 16; i < 32; i++)
2104                 {
2105                 if (data[i] >= 0x20 && i < data[4] + 5)
2106                         printk("%c", data[i]);
2107                 else
2108                         printk(" ");
2109                 }
2110 
2111         printk("  Rev: ");
2112         for (i = 32; i < 36; i++)
2113                 {
2114                 if (data[i] >= 0x20 && i < data[4] + 5)
2115                         printk("%c", data[i]);
2116                 else
2117                         printk(" ");
2118                 }
2119 
2120         printk("\n");
2121 
2122         i = data[0] & 0x1f;
2123 
2124         printk("  Type:   %s ",
2125                i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown          " );
2126         printk("                 ANSI SCSI revision: %02x", data[2] & 0x07);
2127         if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
2128           printk(" CCS\n");
2129         else
2130           printk("\n");
2131 }
2132 
2133 /*
2134  * This entry point should be called by a loadable module if it is trying
2135  * add a low level scsi driver to the system.
2136  */
2137 static int scsi_register_host(Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
2138 {
2139   int pcount;
2140   struct Scsi_Host * shpnt;
2141   struct Scsi_Host * host = NULL;
2142   unsigned long flags;
2143   Scsi_Device * SDpnt;
2144   Scsi_Cmnd * SCpnt;
2145   struct Scsi_Device_Template * sdtpnt;
2146   int j, i;
2147   const char * name;
2148 
2149   if (tpnt->next || !tpnt->detect) return 1;  /* Must be already loaded, or
2150                                                no detect routine available */
2151   pcount = next_scsi_host;
2152   if ((tpnt->present = tpnt->detect(tpnt)))
2153     {
2154       if(pcount == next_scsi_host) {
2155         if(tpnt->present > 1) {
2156           printk("Failure to register low-level scsi driver");
2157           scsi_unregister_host(tpnt);
2158           return 1;
2159         }
2160         /* The low-level driver failed to register a driver.  We
2161            can do this now. */
2162         scsi_register(tpnt,0);
2163       }
2164       tpnt->next = scsi_hosts; /* Add to the linked list */
2165       scsi_hosts = tpnt;
2166 
2167       for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
2168         if(shpnt->hostt == tpnt)
2169           {
2170             if(tpnt->info)
2171               name = tpnt->info(shpnt);
2172             else
2173               name = tpnt->name;
2174             printk ("scsi%d : %s\n", /* And print a little message */
2175                     shpnt->host_no, name);
2176           }
2177       /* The next step is to call scan_scsis here.  This generates the
2178          Scsi_Devices entries */
2179 
2180       for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
2181         if(shpnt->hostt == tpnt) scan_scsis(shpnt);
2182 
2183       for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2184         if(sdtpnt->init && sdtpnt->dev_noticed) (*sdtpnt->init)();
2185 
2186       /* Next we create the Scsi_Cmnd structures for this host */
2187 
2188       for(SDpnt = scsi_devices; SDpnt; SDpnt = SDpnt->next)
2189         if(SDpnt->host->hostt == tpnt)
2190           {
2191             for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2192               if(sdtpnt->attach) (*sdtpnt->attach)(SDpnt);
2193             if(SDpnt->attached){
2194               for(j=0;j<SDpnt->host->cmd_per_lun;j++){
2195                 SCpnt = (Scsi_Cmnd *) scsi_init_malloc(sizeof(Scsi_Cmnd), GFP_ATOMIC);
2196                 SCpnt->host = SDpnt->host;
2197                 SCpnt->device = SDpnt;
2198                 SCpnt->target = SDpnt->id;
2199                 SCpnt->lun = SDpnt->lun;
2200                 SCpnt->request.dev = -1; /* Mark not busy */
2201                 SCpnt->request.sem = NULL;
2202                 SCpnt->use_sg = 0;
2203                 SCpnt->old_use_sg = 0;
2204                 SCpnt->underflow = 0;
2205                 SCpnt->timeout = 0;
2206                 SCpnt->transfersize = 0;
2207                 SCpnt->host_scribble = NULL;
2208                 host = SDpnt->host;
2209                 SCpnt->next = host->host_queue;
2210                 SCpnt->prev = NULL;
2211                 host->host_queue = SCpnt;
2212                 if(host->host_queue)
2213                   host->host_queue->prev = SCpnt;
2214               };
2215             };
2216           }
2217         /* Next, check to see if we need to extend the DMA buffer pool */
2218       {
2219           unsigned char * new_dma_malloc_freelist = NULL;
2220           unsigned int new_dma_sectors = 0;
2221           unsigned int new_need_isa_buffer = 0;
2222           unsigned char ** new_dma_malloc_pages = NULL;
2223           
2224           if (scsi_devicelist)
2225             new_dma_sectors = 16;  /* Base value we use */
2226           
2227           for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
2228             host = SDpnt->host;
2229             
2230             if(SDpnt->type != TYPE_TAPE)
2231               new_dma_sectors += ((host->sg_tablesize * 
2232                                    sizeof(struct scatterlist) + 511) >> 9) * 
2233                                      host->cmd_per_lun;
2234             
2235             if(host->unchecked_isa_dma &&
2236                scsi_need_isa_bounce_buffers &&
2237                SDpnt->type != TYPE_TAPE) {
2238               new_dma_sectors += (PAGE_SIZE >> 9) * host->sg_tablesize *
2239                 host->cmd_per_lun;
2240               new_need_isa_buffer++;
2241             };
2242           };
2243           
2244           new_dma_sectors = (new_dma_sectors + 15) & 0xfff0;
2245 
2246           new_dma_malloc_freelist = (unsigned char *) 
2247             scsi_init_malloc(new_dma_sectors >> 3, GFP_ATOMIC);
2248           memset(new_dma_malloc_freelist, 0, new_dma_sectors >> 3);
2249           
2250           new_dma_malloc_pages = (unsigned char **) 
2251             scsi_init_malloc(new_dma_sectors >> 1, GFP_ATOMIC);
2252           memset(new_dma_malloc_pages, 0, new_dma_sectors >> 1);
2253           
2254           for(i=dma_sectors >> 3; i< new_dma_sectors >> 3; i++)
2255             new_dma_malloc_pages[i] = (unsigned char *) 
2256               scsi_init_malloc(PAGE_SIZE, GFP_ATOMIC | GFP_DMA);
2257           
2258 
2259           /* When we dick with the actual DMA list, we need to protect things */
2260 
2261           save_flags(flags);
2262           cli();
2263           memcpy(new_dma_malloc_freelist, dma_malloc_freelist, dma_sectors >> 3);
2264           scsi_init_free(dma_malloc_freelist, dma_sectors>>3);
2265           dma_malloc_freelist = new_dma_malloc_freelist;
2266           
2267           memcpy(new_dma_malloc_pages, dma_malloc_pages, dma_sectors >> 1);
2268           scsi_init_free((char *) dma_malloc_pages, dma_sectors>>1);
2269           
2270           dma_free_sectors += new_dma_sectors - dma_sectors;
2271           dma_malloc_pages = new_dma_malloc_pages;
2272           dma_sectors = new_dma_sectors;
2273           need_isa_buffer = new_need_isa_buffer;
2274           restore_flags(flags);
2275 
2276           
2277         }
2278       /* This does any final handling that is required. */
2279       for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2280         if(sdtpnt->finish) (*sdtpnt->finish)();
2281     }
2282   return 0;
2283 }
2284 
2285 /*
2286  * Similarly, this entry point should be called by a loadable module if it
2287  * is trying to remove a low level scsi driver from the system.
2288  */
2289 static void scsi_unregister_host(Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
2290 {  
2291   Scsi_Host_Template * SHT, *SHTp;
2292   Scsi_Device *sdpnt, * sdppnt, * sdpnt1;
2293   Scsi_Cmnd * SCpnt;
2294   unsigned long flags;
2295   struct Scsi_Device_Template * sdtpnt;
2296   struct Scsi_Host * shpnt, *sh1;
2297   int pcount;
2298 
2299   /* First verify that this host adapter is completely free with no pending
2300      commands */
2301 
2302   for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt->next)
2303     if(sdpnt->host->hostt == tpnt && *sdpnt->host->hostt->usage_count) return;
2304 
2305   for(shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
2306     {
2307       if (shpnt->hostt != tpnt) continue;
2308       for(SCpnt = shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
2309         {
2310           save_flags(flags);
2311           cli();
2312           if(SCpnt->request.dev != -1) {
2313             restore_flags(flags);
2314             for(SCpnt = shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
2315               if(SCpnt->request.dev == 0xffe0) SCpnt->request.dev = -1;
2316             printk("Device busy???\n");
2317             return;
2318           }
2319           SCpnt->request.dev = 0xffe0;  /* Mark as busy */
2320         }
2321     }
2322   /* Next we detach the high level drivers from the Scsi_Device structures */
2323 
2324   for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt->next)
2325     if(sdpnt->host->hostt == tpnt)
2326       {
2327         for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2328           if(sdtpnt->detach) (*sdtpnt->detach)(sdpnt);
2329         /* If something still attached, punt */
2330         if (sdpnt->attached) {
2331           printk("Attached usage count = %d\n", sdpnt->attached);
2332           return;
2333         }
2334       }
2335   
2336   /* Next we free up the Scsi_Cmnd structures for this host */
2337 
2338   for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt->next)
2339     if(sdpnt->host->hostt == tpnt)
2340       while (sdpnt->host->host_queue) {
2341         SCpnt = sdpnt->host->host_queue->next;
2342         scsi_init_free((char *) sdpnt->host->host_queue, sizeof(Scsi_Cmnd));
2343         sdpnt->host->host_queue = SCpnt;
2344         if (SCpnt) SCpnt->prev = NULL;
2345       }
2346   
2347   /* Next free up the Scsi_Device structures for this host */
2348 
2349   sdppnt = NULL;
2350   for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt1)
2351     {
2352       sdpnt1 = sdpnt->next;
2353       if (sdpnt->host->hostt == tpnt) {
2354         if (sdppnt)
2355           sdppnt->next = sdpnt->next;
2356         else
2357           scsi_devices = sdpnt->next;
2358         scsi_init_free((char *) sdpnt, sizeof (Scsi_Device));
2359       } else
2360         sdppnt = sdpnt;
2361     }
2362 
2363   /* Next we go through and remove the instances of the individual hosts
2364      that were detected */
2365 
2366   shpnt = scsi_hostlist;
2367   while(shpnt) { 
2368    sh1 = shpnt->next;
2369     if(shpnt->hostt == tpnt) {
2370       if(shpnt->loaded_as_module) {
2371         pcount = next_scsi_host;
2372         if(tpnt->release)
2373           (*tpnt->release)(shpnt);
2374         else {
2375           /* This is the default case for the release function.  It should do the right
2376              thing for most correctly written host adapters. */
2377           if (shpnt->irq) free_irq(shpnt->irq);
2378           if (shpnt->dma_channel != 0xff) free_dma(shpnt->dma_channel);
2379           if (shpnt->io_port && shpnt->n_io_port) 
2380             release_region(shpnt->io_port, shpnt->n_io_port);
2381         }
2382         if(pcount == next_scsi_host) scsi_unregister(shpnt);
2383         tpnt->present--;
2384       }
2385     }
2386     shpnt = sh1;
2387   }
2388 
2389   /* There were some hosts that were loaded at boot time, so we cannot
2390      do any more than this */
2391   if (tpnt->present) return;
2392 
2393   /* OK, this is the very last step.  Remove this host adapter from the
2394      linked list. */
2395   for(SHTp=NULL, SHT=scsi_hosts; SHT; SHTp=SHT, SHT=SHT->next)
2396     if(SHT == tpnt) {
2397       if(SHTp)
2398         SHTp->next = SHT->next;
2399       else
2400         scsi_hosts = SHT->next;
2401       SHT->next = NULL;
2402       break;
2403     }
2404 }
2405 
2406 int scsi_register_module(int module_type, void * ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
2407 {
2408   switch(module_type){
2409   case MODULE_SCSI_HA:
2410     return scsi_register_host((Scsi_Host_Template *) ptr);
2411     /* The rest of these are not yet implemented */
2412 
2413     /* Load constants.o */
2414   case MODULE_SCSI_CONST:
2415 
2416     /* Load specialized ioctl handler for some device.  Intended for cdroms that
2417        have non-SCSI2 audio command sets. */
2418   case MODULE_SCSI_IOCTL:
2419 
2420     /* Load upper level device handler of some kind */
2421   case MODULE_SCSI_DEV:
2422   default:
2423     return 1;
2424   }
2425 }
2426 
2427 void scsi_unregister_module(int module_type, void * ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
2428 {
2429   switch(module_type) {
2430   case MODULE_SCSI_HA:
2431     scsi_unregister_host((Scsi_Host_Template *) ptr);
2432     break;
2433     /* The rest of these are not yet implemented. */
2434   case MODULE_SCSI_CONST:
2435   case MODULE_SCSI_IOCTL:
2436   case MODULE_SCSI_DEV:
2437   default:
2438   }
2439   return;
2440 }
2441 
2442 #ifdef DEBUG_TIMEOUT
2443 static void 
2444 scsi_dump_status(void)
     /* [previous][next][first][last][top][bottom][index][help] */
2445 {
2446   int i;
2447   struct Scsi_Host * shpnt;
2448   Scsi_Cmnd * SCpnt;
2449   printk("Dump of scsi parameters:\n");
2450   i = 0;
2451   for(shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
2452     for(SCpnt=shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
2453       {
2454         /*  (0) 0:0:0 (802 123434 8 8 0) (3 3 2) (%d %d %d) %d %x      */
2455         printk("(%d) %d:%d:%d (%4.4x %ld %ld %ld %ld) (%d %d %x) (%d %d %d) %x %x %x\n",
2456                i++, SCpnt->host->host_no,
2457                SCpnt->target,
2458                SCpnt->lun,
2459                SCpnt->request.dev,
2460                SCpnt->request.sector,
2461                SCpnt->request.nr_sectors,
2462                SCpnt->request.current_nr_sectors,
2463                SCpnt->use_sg,
2464                SCpnt->retries,
2465                SCpnt->allowed,
2466                SCpnt->flags,
2467                SCpnt->timeout_per_command,
2468                SCpnt->timeout,
2469                SCpnt->internal_timeout,
2470                SCpnt->cmnd[0],
2471                SCpnt->sense_buffer[2],
2472                SCpnt->result);
2473       };
2474   printk("wait_for_request = %p\n", wait_for_request);
2475   /* Now dump the request lists for each block device */
2476   printk("Dump of pending block device requests\n");
2477   for(i=0; i<MAX_BLKDEV; i++)
2478     if(blk_dev[i].current_request)
2479       {
2480         struct request * req;
2481         printk("%d: ", i);
2482         req = blk_dev[i].current_request;
2483         while(req) {
2484           printk("(%x %d %ld %ld %ld) ",
2485                  req->dev,
2486                  req->cmd,
2487                  req->sector,
2488                  req->nr_sectors,
2489                  req->current_nr_sectors);
2490           req = req->next;
2491         }
2492         printk("\n");
2493       }
2494 }
2495 #endif

/* [previous][next][first][last][top][bottom][index][help] */