root/drivers/scsi/scsi.c

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

DEFINITIONS

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

   1 /*
   2  *      scsi.c Copyright (C) 1992 Drew Eckhardt 
   3  *             Copyright (C) 1993, 1994 Eric Youngdale
   4  *
   5  *      generic mid-level SCSI driver by
   6  *              Drew Eckhardt 
   7  *
   8  *      <drew@colorado.edu>
   9  *
  10  *      Bug correction thanks go to : 
  11  *              Rik Faith <faith@cs.unc.edu>
  12  *              Tommy Thorn <tthorn>
  13  *              Thomas Wuensche <tw@fgb1.fgb.mw.tu-muenchen.de>
  14  * 
  15  *       Modified by Eric Youngdale ericy@cais.com to
  16  *       add scatter-gather, multiple outstanding request, and other
  17  *       enhancements.
  18  */
  19 
  20 #include <asm/system.h>
  21 #include <linux/sched.h>
  22 #include <linux/timer.h>
  23 #include <linux/string.h>
  24 #include <linux/malloc.h>
  25 #include <asm/irq.h>
  26 
  27 #include "../block/blk.h"
  28 #include "scsi.h"
  29 #include "hosts.h"
  30 #include "constants.h"
  31 
  32 /*
  33 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 $";
  34 */
  35 
  36 /* Command groups 3 and 4 are reserved and should never be used.  */
  37 const unsigned char scsi_command_size[8] = { 6, 10, 10, 12, 12, 12, 10, 10 };
  38 
  39 #define INTERNAL_ERROR (panic ("Internal error in file %s, line %d.\n", __FILE__, __LINE__))
  40 
  41 static void scsi_done (Scsi_Cmnd *SCpnt);
  42 static int update_timeout (Scsi_Cmnd *, int);
  43 static void print_inquiry(unsigned char *data);
  44 static void scsi_times_out (Scsi_Cmnd * SCpnt);
  45 
  46 static int time_start;
  47 static int time_elapsed;
  48 
  49 #define MAX_SCSI_DEVICE_CODE 10
  50 const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] =
  51 {
  52  "Direct-Access    ",
  53  "Sequential-Access",
  54  "Printer          ",
  55  "Processor        ",
  56  "WORM             ",
  57  "CD-ROM           ",
  58  "Scanner          ",
  59  "Optical Device   ",
  60  "Medium Changer   ",
  61  "Communications   "
  62 };
  63 
  64 
  65 /*
  66         global variables : 
  67         NR_SCSI_DEVICES is the number of SCSI devices we have detected, 
  68         scsi_devices an array of these specifing the address for each 
  69         (host, id, LUN)
  70 */
  71         
  72 int NR_SCSI_DEVICES=0;
  73 
  74 Scsi_Device * scsi_devices = NULL;
  75 
  76 static unsigned char generic_sense[6] = {REQUEST_SENSE, 0,0,0, 255, 0};
  77 
  78 /* This variable is merely a hook so that we can debug the kernel with gdb. */
  79 Scsi_Cmnd * last_cmnd = NULL;
  80 
  81 /*
  82  *      As the scsi do command functions are inteligent, and may need to 
  83  *      redo a command, we need to keep track of the last command 
  84  *      executed on each one.
  85  */
  86 
  87 #define WAS_RESET       0x01
  88 #define WAS_TIMEDOUT    0x02
  89 #define WAS_SENSE       0x04
  90 #define IS_RESETTING    0x08
  91 #define IS_ABORTING     0x10
  92 #define ASKED_FOR_SENSE 0x20
  93 
  94 /*
  95  *      This is the number  of clock ticks we should wait before we time out 
  96  *      and abort the command.  This is for  where the scsi.c module generates 
  97  *      the command, not where it originates from a higher level, in which
  98  *      case the timeout is specified there.
  99  *
 100  *      ABORT_TIMEOUT and RESET_TIMEOUT are the timeouts for RESET and ABORT
 101  *      respectively.
 102  */
 103 
 104 #ifdef DEBUG_TIMEOUT
 105 static void scsi_dump_status(void);
 106 #endif
 107 
 108 
 109 #ifdef DEBUG
 110         #define SCSI_TIMEOUT 500
 111 #else
 112         #define SCSI_TIMEOUT 100
 113 #endif
 114 
 115 #ifdef DEBUG
 116         #define SENSE_TIMEOUT SCSI_TIMEOUT
 117         #define ABORT_TIMEOUT SCSI_TIMEOUT
 118         #define RESET_TIMEOUT SCSI_TIMEOUT
 119 #else
 120         #define SENSE_TIMEOUT 50
 121         #define RESET_TIMEOUT 50
 122         #define ABORT_TIMEOUT 50
 123         #define MIN_RESET_DELAY 100
 124 #endif
 125 
 126 /* The following devices are known not to tolerate a lun != 0 scan for
 127    one reason or another.  Some will respond to all luns, others will
 128    lock up. */
 129 
 130      struct blist{
 131        char * vendor;
 132        char * model;
 133        char * revision; /* Latest revision known to be bad.  Not used yet */
 134      };
 135 
 136 static struct blist blacklist[] = 
 137 {
 138    {"CHINON","CD-ROM CDS-431","H42"},  /* Locks up if polled for lun != 0 */
 139    {"CHINON","CD-ROM CDS-535","Q14"}, /* Lockup if polled for lun != 0 */
 140    {"DENON","DRD-25X","V"},   /* A cdrom that locks up when probed at lun != 0 */
 141    {"IMS", "CDD521/10","2.06"},   /* Locks-up when LUN>0 polled. */
 142    {"MAXTOR","XT-3280","PR02"},   /* Locks-up when LUN>0 polled. */
 143    {"MAXTOR","XT-4380S","B3C"},   /* Locks-up when LUN>0 polled. */
 144    {"MAXTOR","MXT-1240S","I1.2"}, /* Locks up when LUN > 0 polled */
 145    {"MAXTOR","XT-4170S","B5A"},   /* Locks-up sometimes when LUN>0 polled. */
 146    {"MAXTOR","XT-8760S","B7B"},   /* guess what? */
 147    {"NEC","CD-ROM DRIVE:841","1.0"},  /* Locks-up when LUN>0 polled. */
 148    {"RODIME","RO3000S","2.33"},  /* Locks up if polled for lun != 0 */
 149    {"SEAGATE", "ST157N", "\004|j"}, /* causes failed REQUEST SENSE on lun 1 for aha152x
 150                                      * controller, which causes SCSI code to reset bus.*/
 151    {"SEAGATE", "ST296","921"},   /* Responds to all lun */
 152    {"SONY","CD-ROM CDU-541","4.3d"},
 153    {"TANDBERG","TDC 3600","U07"},  /* Locks up if polled for lun != 0 */
 154    {"TEAC","CD-ROM","1.06"},    /* causes failed REQUEST SENSE on lun 1 for seagate
 155                                  * controller, which causes SCSI code to reset bus.*/
 156    {"TEXEL","CD-ROM","1.06"},   /* causes failed REQUEST SENSE on lun 1 for seagate
 157                                  * controller, which causes SCSI code to reset bus.*/
 158    {NULL, NULL, NULL}}; 
 159 
 160 static int blacklisted(unsigned char * response_data){
     /* [previous][next][first][last][top][bottom][index][help] */
 161   int i = 0;
 162   unsigned char * pnt;
 163   for(i=0; 1; i++){
 164     if(blacklist[i].vendor == NULL) return 0;
 165     pnt = &response_data[8];
 166     while(*pnt && *pnt == ' ') pnt++;
 167     if(memcmp(blacklist[i].vendor, pnt,
 168                strlen(blacklist[i].vendor))) continue;
 169     pnt = &response_data[16];
 170     while(*pnt && *pnt == ' ') pnt++;
 171     if(memcmp(blacklist[i].model, pnt,
 172                strlen(blacklist[i].model))) continue;
 173     return 1;
 174   };    
 175 };
 176 
 177 /*
 178  *      As the actual SCSI command runs in the background, we must set up a 
 179  *      flag that tells scan_scsis() when the result it has is valid.  
 180  *      scan_scsis can set the_result to -1, and watch for it to become the 
 181  *      actual return code for that call.  the scan_scsis_done function() is 
 182  *      our user specified completion function that is passed on to the  
 183  *      scsi_do_cmd() function.
 184  */
 185 
 186 static volatile int in_scan = 0;
 187 static int the_result;
 188 static void scan_scsis_done (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 189         {
 190         
 191 #ifdef DEBUG
 192         printk ("scan_scsis_done(%d, %06x)\n", SCpnt->host, SCpnt->result);
 193 #endif  
 194         SCpnt->request.dev = 0xfffe;
 195         }
 196 
 197 #ifdef NO_MULTI_LUN
 198 static int max_scsi_luns = 1;
 199 #else
 200 static int max_scsi_luns = 8;
 201 #endif
 202 
 203 void scsi_luns_setup(char *str, int *ints) {
     /* [previous][next][first][last][top][bottom][index][help] */
 204     if (ints[0] != 1) 
 205         printk("scsi_luns_setup : usage max_scsi_luns=n (n should be between 1 and 8)\n");
 206     else
 207         max_scsi_luns = ints[1];
 208 }
 209 
 210 /*
 211  *      Detecting SCSI devices :        
 212  *      We scan all present host adapter's busses,  from ID 0 to ID 6.  
 213  *      We use the INQUIRY command, determine device type, and pass the ID / 
 214  *      lun address of all sequential devices to the tape driver, all random 
 215  *      devices to the disk driver.
 216  */
 217 
 218 static void scan_scsis (struct Scsi_Host * shpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 219 {
 220   int dev, lun, type;
 221   unsigned char scsi_cmd [12];
 222   unsigned char scsi_result [256];
 223   Scsi_Device * SDpnt, *SDtail;
 224   Scsi_Cmnd  SCmd;
 225   
 226   ++in_scan;
 227   lun = 0;
 228   type = -1;
 229   SCmd.next = NULL;
 230   SCmd.prev = NULL;
 231   SDpnt = (Scsi_Device *) scsi_init_malloc(sizeof (Scsi_Device));
 232   SDtail = scsi_devices;
 233   if(scsi_devices) {
 234     while(SDtail->next) SDtail = SDtail->next;
 235   }
 236 
 237   shpnt->host_queue = &SCmd;  /* We need this so that
 238                                          commands can time out */
 239   for (dev = 0; dev < 8; ++dev)
 240     if (shpnt->this_id != dev)
 241 /*
 242  * We need the for so our continue, etc. work fine.
 243  */
 244 
 245       for (lun = 0; lun < max_scsi_luns; ++lun)
 246         {
 247           SDpnt->host = shpnt;
 248           SDpnt->id = dev;
 249           SDpnt->lun = lun;
 250           SDpnt->device_wait = NULL;
 251           SDpnt->next = NULL;
 252 /*
 253  * Assume that the device will have handshaking problems, and then 
 254  * fix this field later if it turns out it doesn't.
 255  */
 256           SDpnt->borken = 1;
 257           
 258           scsi_cmd[0] = TEST_UNIT_READY;
 259           scsi_cmd[1] = lun << 5;
 260           scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[5] = 0;
 261           scsi_cmd[4] = 0;
 262           
 263           SCmd.host = shpnt;
 264           SCmd.target = dev;
 265           SCmd.lun = lun;
 266 
 267           SCmd.request.dev = 0xffff; /* Mark not busy */
 268           SCmd.use_sg  = 0;
 269           SCmd.old_use_sg  = 0;
 270           SCmd.transfersize = 0;
 271           SCmd.underflow = 0;
 272           
 273           scsi_do_cmd (&SCmd,
 274                        (void *)  scsi_cmd, (void *) 
 275                        scsi_result, 256,  scan_scsis_done, 
 276                        SCSI_TIMEOUT + 400, 5);
 277           
 278           while (SCmd.request.dev != 0xfffe);
 279 #if defined(DEBUG) || defined(DEBUG_INIT)
 280           printk("scsi: scan SCSIS id %d lun %d\n", dev, lun);
 281           printk("scsi: return code %08x\n", SCmd.result);
 282 #endif
 283           
 284           
 285           if(SCmd.result) {
 286             if ((driver_byte(SCmd.result)  & DRIVER_SENSE) &&
 287                 ((SCmd.sense_buffer[0] & 0x70) >> 4) == 7) {
 288               if (SCmd.sense_buffer[2] &0xe0)
 289                 continue; /* No devices here... */
 290               if(((SCmd.sense_buffer[2] & 0xf) != NOT_READY) &&
 291                  ((SCmd.sense_buffer[2] & 0xf) != UNIT_ATTENTION))
 292                 continue;
 293             }
 294             else
 295               break;
 296           };
 297           
 298 #if defined (DEBUG) || defined(DEBUG_INIT)
 299           printk("scsi: performing INQUIRY\n");
 300 #endif
 301           
 302           /*
 303            * Build an INQUIRY command block.  
 304            */
 305           
 306           scsi_cmd[0] = INQUIRY;
 307           scsi_cmd[1] = (lun << 5) & 0xe0;
 308           scsi_cmd[2] = 0;
 309           scsi_cmd[3] = 0;
 310           scsi_cmd[4] = 255;
 311           scsi_cmd[5] = 0;
 312           
 313           SCmd.request.dev = 0xffff; /* Mark not busy */
 314           
 315           scsi_do_cmd (&SCmd,
 316                        (void *)  scsi_cmd, (void *) 
 317                        scsi_result, 256,  scan_scsis_done, 
 318                        SCSI_TIMEOUT, 3);
 319           
 320           while (SCmd.request.dev != 0xfffe);
 321           
 322           the_result = SCmd.result;
 323           
 324 #if defined(DEBUG) || defined(DEBUG_INIT)
 325           if (!the_result)
 326             printk("scsi: INQUIRY successful\n");
 327           else
 328             printk("scsi: INQUIRY failed with code %08x\n");
 329 #endif
 330           
 331           if(the_result) break; 
 332           
 333           /* skip other luns on this device */
 334           
 335           if (!the_result)
 336             {
 337               SDpnt->removable = (0x80 & 
 338                                   scsi_result[1]) >> 7;
 339               SDpnt->lockable = SDpnt->removable;
 340               SDpnt->changed = 0;
 341               SDpnt->access_count = 0;
 342               SDpnt->busy = 0;
 343 /* 
 344  *      Currently, all sequential devices are assumed to be tapes,
 345  *      all random devices disk, with the appropriate read only 
 346  *      flags set for ROM / WORM treated as RO.
 347  */ 
 348 
 349               switch (type = scsi_result[0])
 350                 {
 351                 case TYPE_TAPE :
 352                 case TYPE_DISK :
 353                 case TYPE_MOD :
 354                   SDpnt->writeable = 1;
 355                   break;
 356                 case TYPE_WORM :
 357                 case TYPE_ROM :
 358                   SDpnt->writeable = 0;
 359                   break;
 360                 default :
 361 #if 0
 362 #ifdef DEBUG
 363                   printk("scsi: unknown type %d\n", type);
 364                   print_inquiry(scsi_result);
 365 #endif
 366 #endif
 367                   type = -1;
 368                 }
 369               
 370               SDpnt->soft_reset = 
 371                 (scsi_result[7] & 1) && ((scsi_result[3] & 7) == 2);
 372               SDpnt->random = (type == TYPE_TAPE) ? 0 : 1;
 373               SDpnt->type = type;
 374               
 375               if (type != -1)
 376                 {
 377                   print_inquiry(scsi_result);
 378                   switch(type){
 379                   case TYPE_TAPE:
 380                     printk("Detected scsi tape st%d at scsi%d, id %d, lun %d\n", MAX_ST,
 381                            shpnt->host_no , dev, lun); 
 382                     if(NR_ST != -1) ++MAX_ST;
 383                     break;
 384                   case TYPE_ROM:
 385                     printk("Detected scsi CD-ROM sr%d at scsi%d, id %d, lun %d\n", MAX_SR,
 386                            shpnt->host_no , dev, lun); 
 387                     if(NR_SR != -1) ++MAX_SR;
 388                     break;
 389                   case TYPE_DISK:
 390                   case TYPE_MOD:
 391                     printk("Detected scsi disk sd%c at scsi%d, id %d, lun %d\n", 'a'+MAX_SD,
 392                            shpnt->host_no , dev, lun); 
 393                     if(NR_SD != -1) ++MAX_SD;
 394                     break;
 395                   default:
 396                     break;
 397                   };
 398                   
 399                   if(NR_SG != -1) ++MAX_SG;
 400                   
 401                   SDpnt->scsi_level = scsi_result[2] & 0x07;
 402                   if (SDpnt->scsi_level >= 2 ||
 403                       (SDpnt->scsi_level == 1 &&
 404                        (scsi_result[3] & 0x0f) == 1))
 405                     SDpnt->scsi_level++;
 406 /* 
 407  * Set the tagged_queue flag for SCSI-II devices that purport to support
 408  * tagged queuing in the INQUIRY data.
 409  */
 410                   
 411                   SDpnt->tagged_queue = 0;
 412                   
 413                   if ((SDpnt->scsi_level >= SCSI_2) &&
 414                       (scsi_result[7] & 2)) {
 415                     SDpnt->tagged_supported = 1;
 416                     SDpnt->current_tag = 0;
 417                   }
 418                   
 419 /*
 420  * Accomodate drivers that want to sleep when they should be in a polling
 421  * loop.
 422  */
 423 
 424                   SDpnt->disconnect = 0;
 425 
 426 /*
 427  * Some revisions of the Texel CD ROM drives have handshaking
 428  * problems when used with the Seagate controllers.  Before we
 429  * know what type of device we're talking to, we assume it's 
 430  * borken and then change it here if it turns out that it isn't
 431  * a TEXEL drive.
 432  */
 433 
 434                   if(strncmp("TEXEL", (char *) &scsi_result[8], 5) != 0 ||
 435                      strncmp("CD-ROM", (char *) &scsi_result[16], 6) != 0 
 436 /* 
 437  * XXX 1.06 has problems, some one should figure out the others too so
 438  * ALL TEXEL drives don't suffer in performance, especially when I finish
 439  * integrating my seagate patches which do multiple I_T_L nexuses.
 440  */
 441 
 442 #ifdef notyet
 443                      || (strncmp("1.06", (char *) &scsi_result[[, 4) != 0)))
 444 #endif
 445                                  )
 446                     SDpnt->borken = 0;
 447                   
 448                   
 449                   /* These devices need this "key" to unlock the device
 450                      so we can use it */
 451                   if(memcmp("INSITE", &scsi_result[8], 6) == 0 &&
 452                      (memcmp("Floptical   F*8I", &scsi_result[16], 16) == 0
 453                       || memcmp("I325VM", &scsi_result[16], 6) == 0)) {
 454                     printk("Unlocked floptical drive.\n");
 455                     SDpnt->lockable = 0;
 456                     scsi_cmd[0] = MODE_SENSE;
 457                     scsi_cmd[1] = (lun << 5) & 0xe0;
 458                     scsi_cmd[2] = 0x2e;
 459                     scsi_cmd[3] = 0;
 460                     scsi_cmd[4] = 0x2a;
 461                     scsi_cmd[5] = 0;
 462                     
 463                     SCmd.request.dev = 0xffff; /* Mark not busy */
 464                     
 465                     scsi_do_cmd (&SCmd,
 466                                  (void *)  scsi_cmd, (void *) 
 467                                  scsi_result, 0x2a,  scan_scsis_done, 
 468                                  SCSI_TIMEOUT, 3);
 469                     
 470                     while (SCmd.request.dev != 0xfffe);
 471                   };
 472                   /* Add this device to the linked list at the end */
 473                   if(SDtail)
 474                     SDtail->next = SDpnt;
 475                   else
 476                     scsi_devices = SDpnt;
 477                   SDtail = SDpnt;
 478 
 479                   ++NR_SCSI_DEVICES;
 480                   SDpnt = (Scsi_Device *) scsi_init_malloc(sizeof (Scsi_Device));
 481                   /* Some scsi devices cannot be polled for lun != 0
 482                      due to firmware bugs */
 483                   if(blacklisted(scsi_result)) break;
 484                   /* Old drives like the MAXTOR XT-3280 say vers=0 */
 485                   if ((scsi_result[2] & 0x07) == 0)
 486                     break;
 487                   /* Some scsi-1 peripherals do not handle lun != 0.
 488                      I am assuming that scsi-2 peripherals do better */
 489                   if((scsi_result[2] & 0x07) == 1 && 
 490                      (scsi_result[3] & 0x0f) == 0) break;
 491                 }
 492             }       /* if result == DID_OK ends */
 493         }       /* for lun ends */
 494   shpnt->host_queue = NULL;  /* No longer needed here */
 495   
 496   printk("scsi : detected ");
 497   if(NR_SD != -1)
 498     printk("%d SCSI disk%s ", MAX_SD, (MAX_SD != 1) ? "s" : "");
 499   
 500   if(NR_ST != -1)
 501     printk("%d tape%s ", MAX_ST, (MAX_ST != 1) ? "s" : "");
 502   
 503   if(NR_SR != -1)
 504     printk("%d CD-ROM drive%s ", MAX_SR, (MAX_SR != 1) ? "s" : "");
 505   
 506   printk("total.\n");
 507   
 508   /* Last device block does not exist.  Free memory. */
 509   scsi_init_free((char *) SDpnt, sizeof(Scsi_Device));
 510   
 511   in_scan = 0;
 512 }       /* scan_scsis  ends */
 513 
 514 /*
 515  *      Flag bits for the internal_timeout array 
 516  */
 517 
 518 #define NORMAL_TIMEOUT 0
 519 #define IN_ABORT 1
 520 #define IN_RESET 2
 521 /*
 522         This is our time out function, called when the timer expires for a 
 523         given host adapter.  It will attempt to abort the currently executing 
 524         command, that failing perform a kernel panic.
 525 */ 
 526 
 527 static void scsi_times_out (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 528         {
 529         
 530         switch (SCpnt->internal_timeout & (IN_ABORT | IN_RESET))
 531                 {
 532                 case NORMAL_TIMEOUT:
 533                         if (!in_scan) {
 534                           printk("SCSI host %d timed out - aborting command\n",
 535                                  SCpnt->host->host_no);
 536 #ifdef DEBUG_TIMEOUT
 537                           scsi_dump_status();
 538 #endif
 539                         }
 540                         
 541                         if (!scsi_abort (SCpnt, DID_TIME_OUT))
 542                                 return;                         
 543                 case IN_ABORT:
 544                         printk("SCSI host %d abort() timed out - reseting\n",
 545                                 SCpnt->host->host_no);
 546                         if (!scsi_reset (SCpnt)) 
 547                                 return;
 548                 case IN_RESET:
 549                 case (IN_ABORT | IN_RESET):
 550                   /* This might be controversial, but if there is a bus hang,
 551                      you might conceivably want the machine up and running
 552                      esp if you have an ide disk. */
 553                         printk("Unable to reset scsi host %d - ",SCpnt->host->host_no);
 554                         printk("probably a SCSI bus hang.\n");
 555                         return;
 556 
 557                 default:
 558                         INTERNAL_ERROR;
 559                 }
 560                                         
 561         }
 562 
 563 
 564 /* This function takes a quick look at a request, and decides if it
 565 can be queued now, or if there would be a stall while waiting for
 566 something else to finish.  This routine assumes that interrupts are
 567 turned off when entering the routine.  It is the responsibility
 568 of the calling code to ensure that this is the case. */
 569 
 570 Scsi_Cmnd * request_queueable (struct request * req, Scsi_Device * device)
     /* [previous][next][first][last][top][bottom][index][help] */
 571 {
 572   Scsi_Cmnd * SCpnt = NULL;
 573   int tablesize;
 574   struct buffer_head * bh, *bhp;
 575 
 576   if (!device)
 577     panic ("No device passed to allocate_device().\n");
 578   
 579   if (req && req->dev <= 0)
 580     panic("Invalid device in allocate_device");
 581   
 582   SCpnt =  device->host->host_queue;
 583     while(SCpnt){
 584       if(SCpnt->target == device->id &&
 585          SCpnt->lun == device->lun)
 586         if(SCpnt->request.dev < 0) break;
 587       SCpnt = SCpnt->next;
 588     };
 589 
 590   if (!SCpnt) return NULL;
 591 
 592   if (device->host->hostt->can_queue
 593       && device->host->host_busy >= device->host->hostt->can_queue) return NULL;
 594 
 595   if (req) {
 596     memcpy(&SCpnt->request, req, sizeof(struct request));
 597     tablesize = device->host->sg_tablesize;
 598     bhp = bh = req->bh;
 599     if(!tablesize) bh = NULL;
 600     /* Take a quick look through the table to see how big it is.  We already
 601        have our copy of req, so we can mess with that if we want to.  */
 602     while(req->nr_sectors && bh){
 603             bhp = bhp->b_reqnext;
 604             if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
 605             req->nr_sectors -= bh->b_size >> 9;
 606             req->sector += bh->b_size >> 9;
 607             if(!tablesize) break;
 608             bh = bhp;
 609     };
 610     if(req->nr_sectors && bh && bh->b_reqnext){  /* Any leftovers? */
 611       SCpnt->request.bhtail = bh;
 612       req->bh = bh->b_reqnext; /* Divide request */
 613       bh->b_reqnext = NULL;
 614       bh = req->bh;
 615 
 616       /* Now reset things so that req looks OK */
 617       SCpnt->request.nr_sectors -= req->nr_sectors;
 618       req->current_nr_sectors = bh->b_size >> 9;
 619       req->buffer = bh->b_data;
 620       SCpnt->request.waiting = NULL; /* Wait until whole thing done */
 621     } else {
 622       req->dev = -1;
 623       wake_up(&wait_for_request);
 624     };      
 625   } else {
 626     SCpnt->request.dev = 0xffff; /* Busy, but no request */
 627     SCpnt->request.waiting = NULL;  /* And no one is waiting for the device either */
 628   };
 629 
 630   SCpnt->use_sg = 0;  /* Reset the scatter-gather flag */
 631   SCpnt->old_use_sg  = 0;
 632   SCpnt->transfersize = 0;
 633   SCpnt->underflow = 0;
 634   return SCpnt;
 635 }
 636 
 637 /* This function returns a structure pointer that will be valid for
 638 the device.  The wait parameter tells us whether we should wait for
 639 the unit to become free or not.  We are also able to tell this routine
 640 not to return a descriptor if the host is unable to accept any more
 641 commands for the time being.  We need to keep in mind that there is no
 642 guarantee that the host remain not busy.  Keep in mind the
 643 request_queueable function also knows the internal allocation scheme
 644 of the packets for each device */
 645 
 646 Scsi_Cmnd * allocate_device (struct request ** reqp, Scsi_Device * device,
     /* [previous][next][first][last][top][bottom][index][help] */
 647                              int wait)
 648 {
 649   int dev = -1;
 650   struct request * req = NULL;
 651   int tablesize;
 652   struct buffer_head * bh, *bhp;
 653   struct Scsi_Host * host;
 654   Scsi_Cmnd * SCpnt = NULL;
 655   Scsi_Cmnd * SCwait = NULL;
 656 
 657   if (!device)
 658     panic ("No device passed to allocate_device().\n");
 659   
 660   if (reqp) req = *reqp;
 661 
 662     /* See if this request has already been queued by an interrupt routine */
 663   if (req && (dev = req->dev) <= 0) return NULL;
 664   
 665   host = device->host;
 666   
 667   while (1==1){
 668     SCpnt = host->host_queue;
 669     while(SCpnt){
 670       if(SCpnt->target == device->id &&
 671          SCpnt->lun == device->lun) {
 672         SCwait = SCpnt;
 673         if(SCpnt->request.dev < 0) break;
 674       };
 675       SCpnt = SCpnt->next;
 676     };
 677     cli();
 678     /* See if this request has already been queued by an interrupt routine */
 679     if (req && ((req->dev < 0) || (req->dev != dev))) {
 680       sti();
 681       return NULL;
 682     };
 683     if (!SCpnt || SCpnt->request.dev >= 0)  /* Might have changed */
 684       {
 685         sti();
 686         if(!wait) return NULL;
 687         if (!SCwait) {
 688           printk("Attempt to allocate device target %d, lun %d\n",
 689                  device->id ,device->lun);
 690           panic("No device found in allocate_device\n");
 691         };
 692         SCSI_SLEEP(&device->device_wait, 
 693                    (SCwait->request.dev > 0));
 694       } else {
 695         if (req) {
 696           memcpy(&SCpnt->request, req, sizeof(struct request));
 697           tablesize = device->host->sg_tablesize;
 698           bhp = bh = req->bh;
 699           if(!tablesize) bh = NULL;
 700           /* Take a quick look through the table to see how big it is.  We already
 701              have our copy of req, so we can mess with that if we want to.  */
 702           while(req->nr_sectors && bh){
 703             bhp = bhp->b_reqnext;
 704             if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
 705             req->nr_sectors -= bh->b_size >> 9;
 706             req->sector += bh->b_size >> 9;
 707             if(!tablesize) break;
 708             bh = bhp;
 709           };
 710           if(req->nr_sectors && bh && bh->b_reqnext){  /* Any leftovers? */
 711             SCpnt->request.bhtail = bh;
 712             req->bh = bh->b_reqnext; /* Divide request */
 713             bh->b_reqnext = NULL;
 714             bh = req->bh;
 715             /* Now reset things so that req looks OK */
 716             SCpnt->request.nr_sectors -= req->nr_sectors;
 717             req->current_nr_sectors = bh->b_size >> 9;
 718             req->buffer = bh->b_data;
 719             SCpnt->request.waiting = NULL; /* Wait until whole thing done */
 720           }
 721           else 
 722             {
 723               req->dev = -1;
 724               *reqp = req->next;
 725               wake_up(&wait_for_request);
 726             };
 727         } else {
 728           SCpnt->request.dev = 0xffff; /* Busy */
 729           SCpnt->request.waiting = NULL;  /* And no one is waiting for this to complete */
 730         };
 731         sti();
 732         break;
 733       };
 734   };
 735 
 736   SCpnt->use_sg = 0;  /* Reset the scatter-gather flag */
 737   SCpnt->old_use_sg  = 0;
 738   SCpnt->transfersize = 0;      /* No default transfer size */
 739   SCpnt->underflow = 0;         /* Do not flag underflow conditions */
 740   return SCpnt;
 741 }
 742 
 743 /*
 744         This is inline because we have stack problemes if we recurse to deeply.
 745 */
 746                          
 747 inline void internal_cmnd (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 748         {
 749         int temp;
 750         struct Scsi_Host * host;
 751 #ifdef DEBUG_DELAY      
 752         int clock;
 753 #endif
 754 
 755         if ((unsigned long) &SCpnt < current->kernel_stack_page)
 756           panic("Kernel stack overflow.");
 757 
 758         host = SCpnt->host;
 759 
 760 /*
 761         We will wait MIN_RESET_DELAY clock ticks after the last reset so 
 762         we can avoid the drive not being ready.
 763 */ 
 764 temp = host->last_reset;
 765 while (jiffies < temp);
 766 
 767 update_timeout(SCpnt, SCpnt->timeout_per_command);
 768 
 769 /*
 770         We will use a queued command if possible, otherwise we will emulate the
 771         queing and calling of completion function ourselves. 
 772 */
 773 #ifdef DEBUG
 774         printk("internal_cmnd (host = %d, target = %d, command = %08x, buffer =  %08x, \n"
 775                 "bufflen = %d, done = %08x)\n", SCpnt->host->host_no, SCpnt->target, SCpnt->cmnd, SCpnt->buffer, SCpnt->bufflen, SCpnt->done);
 776 #endif
 777 
 778         if (host->hostt->can_queue)
 779                 {
 780                   extern unsigned long intr_count;
 781 #ifdef DEBUG
 782         printk("queuecommand : routine at %08x\n", 
 783                 host->hostt->queuecommand);
 784 #endif
 785                   /* This locking tries to prevent all sorts of races between
 786                      queuecommand and the interrupt code.  In effect,
 787                      we are only allowed to be in queuecommand once at
 788                      any given time, and we can only be in the interrupt
 789                      handler and the queuecommand function at the same time
 790                      when queuecommand is called while servicing the
 791                      interrupt. */
 792 
 793                 if(!intr_count && SCpnt->host->irq)
 794                   disable_irq(SCpnt->host->irq);
 795 
 796                 host->hostt->queuecommand (SCpnt, scsi_done);
 797 
 798                 if(!intr_count && SCpnt->host->irq)
 799                   enable_irq(SCpnt->host->irq);
 800                 }
 801         else
 802                 {
 803 
 804 #ifdef DEBUG
 805         printk("command() :  routine at %08x\n", host->hostt->command);
 806 #endif
 807                 temp=host->hostt->command (SCpnt);
 808                 SCpnt->result = temp;
 809 #ifdef DEBUG_DELAY
 810         clock = jiffies + 400;
 811         while (jiffies < clock);
 812         printk("done(host = %d, result = %04x) : routine at %08x\n", host->host_no, temp, done);
 813 #endif
 814                 scsi_done(SCpnt);
 815                 }       
 816 #ifdef DEBUG
 817         printk("leaving internal_cmnd()\n");
 818 #endif
 819         }       
 820 
 821 static void scsi_request_sense (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 822         {
 823         cli();
 824         SCpnt->flags |= WAS_SENSE | ASKED_FOR_SENSE;
 825         update_timeout(SCpnt, SENSE_TIMEOUT);
 826         sti();
 827         
 828 
 829         memcpy ((void *) SCpnt->cmnd , (void *) generic_sense,
 830                 sizeof(generic_sense));
 831 
 832         SCpnt->cmnd[1] = SCpnt->lun << 5;       
 833         SCpnt->cmnd[4] = sizeof(SCpnt->sense_buffer);
 834 
 835         SCpnt->request_buffer = &SCpnt->sense_buffer;
 836         SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
 837         SCpnt->use_sg = 0;
 838         internal_cmnd (SCpnt);
 839         SCpnt->use_sg = SCpnt->old_use_sg;
 840         }
 841 
 842 
 843 
 844 /*
 845         scsi_do_cmd sends all the commands out to the low-level driver.  It 
 846         handles the specifics required for each low level driver - ie queued 
 847         or non queud.  It also prevents conflicts when different high level 
 848         drivers go for the same host at the same time.
 849 */
 850 
 851 void scsi_do_cmd (Scsi_Cmnd * SCpnt, const void *cmnd , 
     /* [previous][next][first][last][top][bottom][index][help] */
 852                   void *buffer, unsigned bufflen, void (*done)(Scsi_Cmnd *),
 853                   int timeout, int retries 
 854                    )
 855         {
 856         struct Scsi_Host * host = SCpnt->host;
 857 
 858 #ifdef DEBUG
 859         {
 860         int i;  
 861         int target = SCpnt->target;
 862         printk ("scsi_do_cmd (host = %d, target = %d, buffer =%08x, "
 863                 "bufflen = %d, done = %08x, timeout = %d, retries = %d)\n"
 864                 "command : " , host->host_no, target, buffer, bufflen, done, timeout, retries);
 865         for (i = 0; i < 10; ++i)
 866                 printk ("%02x  ", ((unsigned char *) cmnd)[i]); 
 867         printk("\n");
 868       };
 869 #endif
 870         
 871         if (!host)
 872                 {
 873                 panic ("Invalid or not present host. %d\n", host->host_no);
 874                 }
 875 
 876         
 877 /*
 878         We must prevent reentrancy to the lowlevel host driver.  This prevents 
 879         it - we enter a loop until the host we want to talk to is not busy.   
 880         Race conditions are prevented, as interrupts are disabled inbetween the
 881         time we check for the host being not busy, and the time we mark it busy
 882         ourselves.
 883 */
 884 
 885         while (1==1){
 886           cli();
 887           if (host->hostt->can_queue
 888               && host->host_busy >= host->hostt->can_queue)
 889             {
 890               sti();
 891               SCSI_SLEEP(&host->host_wait, 
 892                          (host->host_busy >= host->hostt->can_queue));
 893             } else {
 894               host->host_busy++;
 895               sti();
 896               break;
 897             };
 898       };
 899 /*
 900         Our own function scsi_done (which marks the host as not busy, disables 
 901         the timeout counter, etc) will be called by us or by the 
 902         scsi_hosts[host].queuecommand() function needs to also call
 903         the completion function for the high level driver.
 904 
 905 */
 906 
 907         memcpy ((void *) SCpnt->data_cmnd , (void *) cmnd, 12);
 908 #if 0
 909         SCpnt->host = host;
 910         SCpnt->target = target;
 911         SCpnt->lun = (SCpnt->data_cmnd[1] >> 5);
 912 #endif
 913         SCpnt->bufflen = bufflen;
 914         SCpnt->buffer = buffer;
 915         SCpnt->flags=0;
 916         SCpnt->retries=0;
 917         SCpnt->allowed=retries;
 918         SCpnt->done = done;
 919         SCpnt->timeout_per_command = timeout;
 920                                 
 921         memcpy ((void *) SCpnt->cmnd , (void *) cmnd, 12);
 922         /* Zero the sense buffer.  Some host adapters automatically request
 923            sense on error.  0 is not a valid sense code.  */
 924         memset ((void *) SCpnt->sense_buffer, 0, sizeof SCpnt->sense_buffer);
 925         SCpnt->request_buffer = buffer;
 926         SCpnt->request_bufflen = bufflen;
 927         SCpnt->old_use_sg = SCpnt->use_sg;
 928 
 929         /* Start the timer ticking.  */
 930 
 931         SCpnt->internal_timeout = 0;
 932         SCpnt->abort_reason = 0;
 933         internal_cmnd (SCpnt);
 934 
 935 #ifdef DEBUG
 936         printk ("Leaving scsi_do_cmd()\n");
 937 #endif
 938         }
 939 
 940 
 941 
 942 /*
 943         The scsi_done() function disables the timeout timer for the scsi host, 
 944         marks the host as not busy, and calls the user specified completion 
 945         function for that host's current command.
 946 */
 947 
 948 static void reset (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 949 {
 950 #ifdef DEBUG
 951         printk("scsi: reset(%d)\n", SCpnt->host->host_no);
 952 #endif
 953         
 954         SCpnt->flags |= (WAS_RESET | IS_RESETTING);
 955         scsi_reset(SCpnt);
 956         
 957 #ifdef DEBUG
 958         printk("performing request sense\n");
 959 #endif
 960         
 961 #if 0  /* FIXME - remove this when done */
 962         if(SCpnt->flags & NEEDS_JUMPSTART) {
 963           SCpnt->flags &= ~NEEDS_JUMPSTART;
 964           scsi_request_sense (SCpnt);
 965         };
 966 #endif
 967 }
 968         
 969         
 970 
 971 static int check_sense (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 972         {
 973   /* If there is no sense information, request it.  If we have already
 974      requested it, there is no point in asking again - the firmware must be
 975      confused. */
 976   if (((SCpnt->sense_buffer[0] & 0x70) >> 4) != 7) {
 977     if(!(SCpnt->flags & ASKED_FOR_SENSE))
 978       return SUGGEST_SENSE;
 979     else
 980       return SUGGEST_RETRY;
 981       }
 982   
 983   SCpnt->flags &= ~ASKED_FOR_SENSE;
 984 
 985 #ifdef DEBUG_INIT
 986         printk("scsi%d : ", SCpnt->host->host_no);
 987         print_sense("", SCpnt);
 988         printk("\n");
 989 #endif
 990                 if (SCpnt->sense_buffer[2] &0xe0)
 991                   return SUGGEST_ABORT;
 992 
 993                 switch (SCpnt->sense_buffer[2] & 0xf)
 994                 {
 995                 case NO_SENSE:
 996                         return 0;
 997                 case RECOVERED_ERROR:
 998                         if (SCpnt->device->type == TYPE_TAPE)
 999                           return SUGGEST_IS_OK;
1000                         else
1001                           return 0;
1002 
1003                 case ABORTED_COMMAND:
1004                         return SUGGEST_RETRY;   
1005                 case NOT_READY:
1006                 case UNIT_ATTENTION:
1007                         return SUGGEST_ABORT;
1008 
1009                 /* these three are not supported */     
1010                 case COPY_ABORTED:
1011                 case VOLUME_OVERFLOW:
1012                 case MISCOMPARE:
1013         
1014                 case MEDIUM_ERROR:
1015                         return SUGGEST_REMAP;
1016                 case BLANK_CHECK:
1017                 case DATA_PROTECT:
1018                 case HARDWARE_ERROR:
1019                 case ILLEGAL_REQUEST:
1020                 default:
1021                         return SUGGEST_ABORT;
1022                 }
1023               }
1024 
1025 /* This function is the mid-level interrupt routine, which decides how
1026  *  to handle error conditions.  Each invocation of this function must
1027  *  do one and *only* one of the following:
1028  *
1029  *  (1) Call last_cmnd[host].done.  This is done for fatal errors and
1030  *      normal completion, and indicates that the handling for this
1031  *      request is complete.
1032  *  (2) Call internal_cmnd to requeue the command.  This will result in
1033  *      scsi_done being called again when the retry is complete.
1034  *  (3) Call scsi_request_sense.  This asks the host adapter/drive for
1035  *      more information about the error condition.  When the information
1036  *      is available, scsi_done will be called again.
1037  *  (4) Call reset().  This is sort of a last resort, and the idea is that
1038  *      this may kick things loose and get the drive working again.  reset()
1039  *      automatically calls scsi_request_sense, and thus scsi_done will be
1040  *      called again once the reset is complete.
1041  *
1042  *      If none of the above actions are taken, the drive in question
1043  * will hang. If more than one of the above actions are taken by
1044  * scsi_done, then unpredictable behavior will result.
1045  */
1046 static void scsi_done (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1047         {
1048         int status=0;
1049         int exit=0;
1050         int checked;
1051         int oldto;
1052         struct Scsi_Host * host = SCpnt->host;
1053         int result = SCpnt->result;
1054         oldto = update_timeout(SCpnt, 0);
1055 
1056 #ifdef DEBUG_TIMEOUT
1057         if(result) printk("Non-zero result in scsi_done %x %d:%d\n",
1058                           result, SCpnt->target, SCpnt->lun);
1059 #endif
1060 
1061         /* If we requested an abort, (and we got it) then fix up the return
1062            status to say why */
1063         if(host_byte(result) == DID_ABORT && SCpnt->abort_reason)
1064           SCpnt->result = result = (result & 0xff00ffff) | 
1065             (SCpnt->abort_reason << 16);
1066 
1067 
1068 #define FINISHED 0
1069 #define MAYREDO  1
1070 #define REDO     3
1071 #define PENDING  4
1072 
1073 #ifdef DEBUG
1074         printk("In scsi_done(host = %d, result = %06x)\n", host->host_no, result);
1075 #endif
1076         switch (host_byte(result))      
1077         {
1078         case DID_OK:
1079                 if (status_byte(result) && (SCpnt->flags & WAS_SENSE))
1080                         /* Failed to obtain sense information */
1081                         {
1082                         SCpnt->flags &= ~WAS_SENSE;
1083                         SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1084 
1085                         if (!(SCpnt->flags & WAS_RESET))
1086                                 {
1087                                 printk("scsi%d : target %d lun %d request sense failed, performing reset.\n", 
1088                                         SCpnt->host->host_no, SCpnt->target, SCpnt->lun);
1089                                 reset(SCpnt);
1090                                 return;
1091                                 }
1092                         else
1093                                 {
1094                                 exit = (DRIVER_HARD | SUGGEST_ABORT);
1095                                 status = FINISHED;
1096                                 }
1097                         }
1098                 else switch(msg_byte(result))
1099                         {
1100                         case COMMAND_COMPLETE:
1101                         switch (status_byte(result))
1102                         {
1103                         case GOOD:
1104                                 if (SCpnt->flags & WAS_SENSE)
1105                                         {
1106 #ifdef DEBUG
1107         printk ("In scsi_done, GOOD status, COMMAND COMPLETE, parsing sense information.\n");
1108 #endif
1109 
1110                                         SCpnt->flags &= ~WAS_SENSE;
1111                                         SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1112         
1113                                         switch (checked = check_sense(SCpnt))
1114                                         {
1115                                         case SUGGEST_SENSE:
1116                                         case 0: 
1117 #ifdef DEBUG
1118         printk("NO SENSE.  status = REDO\n");
1119 #endif
1120 
1121                                                 update_timeout(SCpnt, oldto);
1122                                                 status = REDO;
1123                                                 break;
1124                                         case SUGGEST_IS_OK:
1125                                                 break;
1126                                         case SUGGEST_REMAP:                     
1127                                         case SUGGEST_RETRY: 
1128 #ifdef DEBUG
1129         printk("SENSE SUGGEST REMAP or SUGGEST RETRY - status = MAYREDO\n");
1130 #endif
1131 
1132                                                 status = MAYREDO;
1133                                                 exit = DRIVER_SENSE | SUGGEST_RETRY;
1134                                                 break;
1135                                         case SUGGEST_ABORT:
1136 #ifdef DEBUG
1137         printk("SENSE SUGGEST ABORT - status = FINISHED");
1138 #endif
1139 
1140                                                 status = FINISHED;
1141                                                 exit =  DRIVER_SENSE | SUGGEST_ABORT;
1142                                                 break;
1143                                         default:
1144                                                 printk ("Internal error %s %d \n", __FILE__, 
1145                                                         __LINE__);
1146                                         }                          
1147                                         }       
1148                                 else
1149                                         {
1150 #ifdef DEBUG
1151         printk("COMMAND COMPLETE message returned, status = FINISHED. \n");
1152 #endif
1153 
1154                                         exit =  DRIVER_OK;
1155                                         status = FINISHED;
1156                                         }
1157                                 break;  
1158 
1159                         case CHECK_CONDITION:
1160                                 switch (check_sense(SCpnt))
1161                                   {
1162                                   case 0: 
1163                                     update_timeout(SCpnt, oldto);
1164                                     status = REDO;
1165                                     break;
1166                                   case SUGGEST_REMAP:                   
1167                                   case SUGGEST_RETRY:
1168                                     status = MAYREDO;
1169                                     exit = DRIVER_SENSE | SUGGEST_RETRY;
1170                                     break;
1171                                   case SUGGEST_ABORT:
1172                                     status = FINISHED;
1173                                     exit =  DRIVER_SENSE | SUGGEST_ABORT;
1174                                     break;
1175                                   case SUGGEST_SENSE:
1176                                 scsi_request_sense (SCpnt);
1177                                 status = PENDING;
1178                                 break;          
1179                                   }
1180                                 break;          
1181                         
1182                         case CONDITION_GOOD:
1183                         case INTERMEDIATE_GOOD:
1184                         case INTERMEDIATE_C_GOOD:
1185                                 break;
1186                                 
1187                         case BUSY:
1188                                 update_timeout(SCpnt, oldto);
1189                                 status = REDO;
1190                                 break;
1191 
1192                         case RESERVATION_CONFLICT:
1193                                 printk("scsi%d : RESERVATION CONFLICT performing reset.\n", 
1194                                         SCpnt->host->host_no);
1195                                 reset(SCpnt);
1196                                 return;
1197 #if 0
1198                                 exit = DRIVER_SOFT | SUGGEST_ABORT;
1199                                 status = MAYREDO;
1200                                 break;
1201 #endif
1202                         default:
1203                                 printk ("Internal error %s %d \n"
1204                                         "status byte = %d \n", __FILE__, 
1205                                         __LINE__, status_byte(result));
1206                                 
1207                         }
1208                         break;
1209                         default:
1210                                 panic("scsi: unsupported message byte %d recieved\n", msg_byte(result)); 
1211                         }
1212                         break;
1213         case DID_TIME_OUT:      
1214 #ifdef DEBUG
1215         printk("Host returned DID_TIME_OUT - ");
1216 #endif
1217 
1218                 if (SCpnt->flags & WAS_TIMEDOUT)
1219                         {
1220 #ifdef DEBUG
1221         printk("Aborting\n");
1222 #endif  
1223                         exit = (DRIVER_TIMEOUT | SUGGEST_ABORT);
1224                         }               
1225                 else 
1226                         {
1227 #ifdef DEBUG
1228                         printk ("Retrying.\n");
1229 #endif
1230                         SCpnt->flags  |= WAS_TIMEDOUT;
1231                         SCpnt->internal_timeout &= ~IN_ABORT;
1232                         status = REDO;
1233                         }
1234                 break;
1235         case DID_BUS_BUSY:
1236         case DID_PARITY:
1237                 status = REDO;
1238                 break;
1239         case DID_NO_CONNECT:
1240 #ifdef DEBUG
1241                 printk("Couldn't connect.\n");
1242 #endif
1243                 exit  = (DRIVER_HARD | SUGGEST_ABORT);
1244                 break;
1245         case DID_ERROR: 
1246                 status = MAYREDO;
1247                 exit = (DRIVER_HARD | SUGGEST_ABORT);
1248                 break;
1249         case DID_BAD_TARGET:
1250         case DID_ABORT:
1251                 exit = (DRIVER_INVALID | SUGGEST_ABORT);
1252                 break;  
1253         case DID_RESET:
1254                 if (SCpnt->flags & IS_RESETTING)
1255                         {
1256                         SCpnt->flags &= ~IS_RESETTING;
1257                         status = REDO;
1258                         break;
1259                         }
1260 
1261                 if(msg_byte(result) == GOOD &&
1262                       status_byte(result) == CHECK_CONDITION) {
1263                         switch (check_sense(SCpnt)) {
1264                         case 0: 
1265                             update_timeout(SCpnt, oldto);
1266                             status = REDO;
1267                             break;
1268                         case SUGGEST_REMAP:                     
1269                         case SUGGEST_RETRY:
1270                             status = MAYREDO;
1271                             exit = DRIVER_SENSE | SUGGEST_RETRY;
1272                             break;
1273                         case SUGGEST_ABORT:
1274                             status = FINISHED;
1275                             exit =  DRIVER_SENSE | SUGGEST_ABORT;
1276                             break;
1277                         case SUGGEST_SENSE:
1278                               scsi_request_sense (SCpnt);
1279                               status = PENDING;
1280                               break;
1281                         }
1282                 } else {
1283                 status=REDO;
1284                 exit = SUGGEST_RETRY;
1285                 }
1286                 break;
1287         default :               
1288                 exit = (DRIVER_ERROR | SUGGEST_DIE);
1289         }
1290 
1291         switch (status) 
1292                 {
1293                 case FINISHED:
1294                 case PENDING:
1295                         break;
1296                 case MAYREDO:
1297 
1298 #ifdef DEBUG
1299         printk("In MAYREDO, allowing %d retries, have %d\n",
1300                SCpnt->allowed, SCpnt->retries);
1301 #endif
1302 
1303                         if ((++SCpnt->retries) < SCpnt->allowed)
1304                         {
1305                         if ((SCpnt->retries >= (SCpnt->allowed >> 1))
1306                             && !(SCpnt->flags & WAS_RESET))
1307                                 {
1308                                         printk("scsi%d : reseting for second half of retries.\n",
1309                                                 SCpnt->host->host_no);
1310                                         reset(SCpnt);
1311                                         break;
1312                                 }
1313 
1314                         }
1315                         else
1316                                 {
1317                                 status = FINISHED;
1318                                 break;
1319                                 }
1320                         /* fall through to REDO */
1321 
1322                 case REDO:
1323                         if (SCpnt->flags & WAS_SENSE)                   
1324                                 scsi_request_sense(SCpnt);      
1325                         else    
1326                           {
1327                             memcpy ((void *) SCpnt->cmnd,
1328                                     (void*) SCpnt->data_cmnd, 
1329                                     sizeof(SCpnt->data_cmnd));
1330                             SCpnt->request_buffer = SCpnt->buffer;
1331                             SCpnt->request_bufflen = SCpnt->bufflen;
1332                             SCpnt->use_sg = SCpnt->old_use_sg;
1333                             internal_cmnd (SCpnt);
1334                           };
1335                         break;  
1336                 default: 
1337                         INTERNAL_ERROR;
1338                 }
1339 
1340         if (status == FINISHED) 
1341                 {
1342                 #ifdef DEBUG
1343                         printk("Calling done function - at address %08x\n", SCpnt->done);
1344                 #endif
1345                 host->host_busy--; /* Indicate that we are free */
1346                 wake_up(&host->host_wait);
1347                 SCpnt->result = result | ((exit & 0xff) << 24);
1348                 SCpnt->use_sg = SCpnt->old_use_sg;
1349                 SCpnt->done (SCpnt);
1350                 }
1351 
1352 
1353 #undef FINISHED
1354 #undef REDO
1355 #undef MAYREDO
1356 #undef PENDING
1357         }
1358 
1359 /*
1360         The scsi_abort function interfaces with the abort() function of the host
1361         we are aborting, and causes the current command to not complete.  The 
1362         caller should deal with any error messages or status returned on the 
1363         next call.
1364         
1365         This will not be called rentrantly for a given host.
1366 */
1367         
1368 /*
1369         Since we're nice guys and specified that abort() and reset()
1370         can be non-reentrant.  The internal_timeout flags are used for
1371         this.
1372 */
1373 
1374 
1375 int scsi_abort (Scsi_Cmnd * SCpnt, int why)
     /* [previous][next][first][last][top][bottom][index][help] */
1376         {
1377         int oldto;
1378         struct Scsi_Host * host = SCpnt->host;
1379         
1380         while(1)        
1381                 {
1382                 cli();
1383                 if (SCpnt->internal_timeout & IN_ABORT) 
1384                         {
1385                         sti();
1386                         while (SCpnt->internal_timeout & IN_ABORT);
1387                         }
1388                 else
1389                         {       
1390                         SCpnt->internal_timeout |= IN_ABORT;
1391                         oldto = update_timeout(SCpnt, ABORT_TIMEOUT);
1392 
1393                         if ((SCpnt->flags & IS_RESETTING) && 
1394                             SCpnt->device->soft_reset) {
1395                           /* OK, this command must have died when we did the
1396                              reset.  The device itself must have lied. */
1397                           printk("Stale command on %d:%d appears to have died when"
1398                                  " the bus was reset\n", SCpnt->target, SCpnt->lun);
1399                         }
1400                         
1401                         sti();
1402                         if (!host->host_busy) {
1403                           SCpnt->internal_timeout &= ~IN_ABORT;
1404                           update_timeout(SCpnt, oldto);
1405                           return 0;
1406                         }
1407                         SCpnt->abort_reason = why;
1408                         switch(host->hostt->abort(SCpnt)) {
1409                           /* We do not know how to abort.  Try waiting another
1410                              time increment and see if this helps. Set the
1411                              WAS_TIMEDOUT flag set so we do not try this twice
1412                              */
1413                         case SCSI_ABORT_BUSY: /* Tough call - returning 1 from
1414                                                  this is too severe */
1415                         case SCSI_ABORT_SNOOZE:
1416                           if(why == DID_TIME_OUT) {
1417                             cli();
1418                             SCpnt->internal_timeout &= ~IN_ABORT;
1419                             if(SCpnt->flags & WAS_TIMEDOUT) {
1420                               sti();
1421                               return 1; /* Indicate we cannot handle this.
1422                                            We drop down into the reset handler
1423                                            and try again */
1424                             } else {
1425                               SCpnt->flags |= WAS_TIMEDOUT;
1426                               oldto = SCpnt->timeout_per_command;
1427                               update_timeout(SCpnt, oldto);
1428                             }
1429                             sti();
1430                           }
1431                           return 0;
1432                         case SCSI_ABORT_PENDING:
1433                           if(why != DID_TIME_OUT) {
1434                             cli();
1435                             update_timeout(SCpnt, oldto);
1436                             sti();
1437                           }
1438                           return 0;
1439                         case SCSI_ABORT_SUCCESS:
1440                           /* We should have already aborted this one.  No
1441                              need to adjust timeout */
1442                         case SCSI_ABORT_NOT_RUNNING:
1443                           SCpnt->internal_timeout &= ~IN_ABORT;
1444                           return 0;
1445                         case SCSI_ABORT_ERROR:
1446                         default:
1447                           SCpnt->internal_timeout &= ~IN_ABORT;
1448                           return 1;
1449                         }
1450                       }
1451               } 
1452       }
1453      
1454 int scsi_reset (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1455         {
1456         int temp, oldto;
1457         Scsi_Cmnd * SCpnt1;
1458         struct Scsi_Host * host = SCpnt->host;
1459         
1460 #ifdef DEBUG
1461         printk("Danger Will Robinson! - SCSI bus for host %d is being reset.\n",host->host_no);
1462 #endif
1463         while (1) {
1464                 cli();  
1465                 if (SCpnt->internal_timeout & IN_RESET)
1466                         {
1467                         sti();
1468                         while (SCpnt->internal_timeout & IN_RESET);
1469                         }
1470                 else
1471                         {
1472                         SCpnt->internal_timeout |= IN_RESET;
1473                         oldto = update_timeout(SCpnt, RESET_TIMEOUT);   
1474                                         
1475                         if (host->host_busy)
1476                                 {       
1477                                 sti();
1478                                 SCpnt1 = host->host_queue;
1479                                 while(SCpnt1) {
1480                                   if (SCpnt1->request.dev > 0) {
1481 #if 0                             
1482                                     if (!(SCpnt1->flags & IS_RESETTING) && 
1483                                       !(SCpnt1->internal_timeout & IN_ABORT))
1484                                     scsi_abort(SCpnt1, DID_RESET);
1485 #endif
1486                                     SCpnt1->flags |= IS_RESETTING;
1487                                   }
1488                                   SCpnt1 = SCpnt1->next;
1489                                 };
1490 
1491                                 temp = host->hostt->reset(SCpnt);       
1492                                 }                               
1493                         else
1494                                 {
1495                                 host->host_busy++;
1496         
1497                                 sti();
1498                                 temp = host->hostt->reset(SCpnt);
1499                                 host->last_reset = jiffies;
1500                                 host->host_busy--;
1501                                 }
1502 
1503 #ifdef DEBUG
1504                         printk("scsi reset function returned %d\n", temp);
1505 #endif
1506                         switch(temp) {
1507                         case SCSI_RESET_SUCCESS:
1508                           cli();
1509                           SCpnt->internal_timeout &= ~IN_RESET;
1510                           update_timeout(SCpnt, oldto);
1511                           sti();
1512                           return 0;
1513                         case SCSI_RESET_PENDING:
1514                           return 0;
1515                         case SCSI_RESET_PUNT:
1516                         case SCSI_RESET_WAKEUP:
1517                           SCpnt->internal_timeout &= ~IN_RESET;
1518                           scsi_request_sense (SCpnt);
1519                           return 0;
1520                         case SCSI_RESET_SNOOZE:                   
1521                           /* In this case, we set the timeout field to 0
1522                              so that this command does not time out any more,
1523                              and we return 1 so that we get a message on the
1524                              screen. */
1525                           cli();
1526                           SCpnt->internal_timeout &= ~IN_RESET;
1527                           update_timeout(SCpnt, 0);
1528                           sti();
1529                           /* If you snooze, you lose... */
1530                         case SCSI_RESET_ERROR:
1531                         default:
1532                           return 1;
1533                         }
1534         
1535                         return temp;    
1536                         }
1537                 }
1538         }
1539                          
1540 
1541 static void scsi_main_timeout(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1542         {
1543         /*
1544                 We must not enter update_timeout with a timeout condition still pending.
1545         */
1546 
1547         int timed_out;
1548         struct Scsi_Host * host;
1549         Scsi_Cmnd * SCpnt = NULL;
1550 
1551         do      {       
1552                 cli();
1553 
1554                 update_timeout(NULL, 0);
1555         /*
1556                 Find all timers such that they have 0 or negative (shouldn't happen)
1557                 time remaining on them.
1558         */
1559                         
1560                 timed_out = 0;
1561                 for(host = scsi_hostlist; host; host = host->next) {
1562                   for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
1563                     if (SCpnt->timeout == -1)
1564                       {
1565                         sti();
1566                         SCpnt->timeout = 0;
1567                         scsi_times_out(SCpnt);
1568                         ++timed_out; 
1569                         cli();
1570                       }
1571                 };
1572               } while (timed_out);      
1573         sti();
1574       }
1575 
1576 /*
1577         The strategy is to cause the timer code to call scsi_times_out()
1578         when the soonest timeout is pending.  
1579         The arguments are used when we are queueing a new command, because
1580         we do not want to subtract the time used from this time, but when we
1581         set the timer, we want to take this value into account.
1582 */
1583         
1584 static int update_timeout(Scsi_Cmnd * SCset, int timeout)
     /* [previous][next][first][last][top][bottom][index][help] */
1585         {
1586         unsigned int least, used;
1587         unsigned int oldto;
1588         struct Scsi_Host * host;
1589         Scsi_Cmnd * SCpnt = NULL;
1590 
1591         cli();
1592 
1593 /* 
1594         Figure out how much time has passed since the last time the timeouts 
1595         were updated 
1596 */
1597         used = (time_start) ? (jiffies - time_start) : 0;
1598 
1599 /*
1600         Find out what is due to timeout soonest, and adjust all timeouts for
1601         the amount of time that has passed since the last time we called 
1602         update_timeout. 
1603 */
1604         
1605         oldto = 0;
1606 
1607         if(SCset){
1608           oldto = SCset->timeout - used;
1609           SCset->timeout = timeout + used;
1610         };
1611 
1612         least = 0xffffffff;
1613 
1614         for(host = scsi_hostlist; host; host = host->next)
1615           for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
1616             if (SCpnt->timeout > 0) {
1617               SCpnt->timeout -= used;
1618               if(SCpnt->timeout <= 0) SCpnt->timeout = -1;
1619               if(SCpnt->timeout > 0 && SCpnt->timeout < least)
1620                 least = SCpnt->timeout;
1621             };
1622 
1623 /*
1624         If something is due to timeout again, then we will set the next timeout 
1625         interrupt to occur.  Otherwise, timeouts are disabled.
1626 */
1627         
1628         if (least != 0xffffffff)
1629                 {
1630                 time_start = jiffies;   
1631                 timer_table[SCSI_TIMER].expires = (time_elapsed = least) + jiffies;     
1632                 timer_active |= 1 << SCSI_TIMER;
1633                 }
1634         else
1635                 {
1636                 timer_table[SCSI_TIMER].expires = time_start = time_elapsed = 0;
1637                 timer_active &= ~(1 << SCSI_TIMER);
1638                 }       
1639         sti();
1640         return oldto;
1641         }               
1642 
1643 
1644 static unsigned short * dma_malloc_freelist = NULL;
1645 static unsigned int dma_sectors = 0;
1646 unsigned int dma_free_sectors = 0;
1647 unsigned int need_isa_buffer = 0;
1648 static unsigned char * dma_malloc_buffer = NULL;
1649 
1650 void *scsi_malloc(unsigned int len)
     /* [previous][next][first][last][top][bottom][index][help] */
1651 {
1652   unsigned int nbits, mask;
1653   int i, j;
1654   if((len & 0x1ff) || len > 8192)
1655     return NULL;
1656   
1657   cli();
1658   nbits = len >> 9;
1659   mask = (1 << nbits) - 1;
1660   
1661   for(i=0;i < (dma_sectors >> 4); i++)
1662     for(j=0; j<17-nbits; j++){
1663       if ((dma_malloc_freelist[i] & (mask << j)) == 0){
1664         dma_malloc_freelist[i] |= (mask << j);
1665         sti();
1666         dma_free_sectors -= nbits;
1667 #ifdef DEBUG
1668         printk("SMalloc: %d %x ",len, dma_malloc_buffer + (i << 13) + (j << 9));
1669 #endif
1670         return (void *) ((unsigned long) dma_malloc_buffer + (i << 13) + (j << 9));
1671       };
1672     };
1673   sti();
1674   return NULL;  /* Nope.  No more */
1675 }
1676 
1677 int scsi_free(void *obj, unsigned int len)
     /* [previous][next][first][last][top][bottom][index][help] */
1678 {
1679   int offset;
1680   int page, sector, nbits, mask;
1681 
1682 #ifdef DEBUG
1683   printk("Sfree %x %d\n",obj, len);
1684 #endif
1685 
1686   offset = ((int) obj) - ((int) dma_malloc_buffer);
1687 
1688   if (offset < 0) panic("Bad offset");
1689   page = offset >> 13;
1690   sector = offset >> 9;
1691   if(sector >= dma_sectors) panic ("Bad page");
1692 
1693   sector = (offset >> 9) & 15;
1694   nbits = len >> 9;
1695   mask = (1 << nbits) - 1;
1696 
1697   if ((mask << sector) > 0xffff) panic ("Bad memory alignment");
1698 
1699   cli();
1700   if(dma_malloc_freelist[page] & (mask << sector) != (mask<<sector))
1701     panic("Trying to free unused memory");
1702 
1703   dma_free_sectors += nbits;
1704   dma_malloc_freelist[page] &= ~(mask << sector);
1705   sti();
1706   return 0;
1707 }
1708 
1709 
1710 /* These are special functions that can be used to obtain memory at boot time.
1711    They act line a malloc function, but they simply take memory from the
1712    pool */
1713 
1714 static unsigned int scsi_init_memory_start = 0;
1715 int scsi_loadable_module_flag; /* Set after we scan builtin drivers */
1716 
1717 void * scsi_init_malloc(unsigned int size)
     /* [previous][next][first][last][top][bottom][index][help] */
1718 {
1719   unsigned int retval;
1720   if(scsi_loadable_module_flag) {
1721     retval = (unsigned int) kmalloc(size, GFP_ATOMIC);
1722   } else {
1723     retval = scsi_init_memory_start;
1724     scsi_init_memory_start += size;
1725   }
1726   return (void *) retval;
1727 }
1728 
1729 
1730 void scsi_init_free(char * ptr, unsigned int size)
     /* [previous][next][first][last][top][bottom][index][help] */
1731 { /* FIXME - not right.  We need to comare addresses to see whether this was
1732      kmalloc'd or not */
1733   if((unsigned int) ptr < scsi_loadable_module_flag) {
1734     kfree(ptr);
1735   } else {
1736     if(((unsigned int) ptr) + size == scsi_init_memory_start)
1737       scsi_init_memory_start = (unsigned int) ptr;
1738   }
1739 }
1740 
1741 /*
1742         scsi_dev_init() is our initialization routine, which inturn calls host 
1743         initialization, bus scanning, and sd/st initialization routines.  It 
1744         should be called from main().
1745 */
1746 
1747 unsigned long scsi_dev_init (unsigned long memory_start,unsigned long memory_end)
     /* [previous][next][first][last][top][bottom][index][help] */
1748         {
1749         struct Scsi_Host * host = NULL;
1750         Scsi_Device * SDpnt;
1751         struct Scsi_Host * shpnt;
1752         Scsi_Cmnd * SCpnt;
1753 #ifdef FOO_ON_YOU
1754         return;
1755 #endif  
1756 
1757         /* Init a few things so we can "malloc" memory. */
1758         scsi_loadable_module_flag = 0;
1759         scsi_init_memory_start = memory_start;
1760 
1761         timer_table[SCSI_TIMER].fn = scsi_main_timeout;
1762         timer_table[SCSI_TIMER].expires = 0;
1763 
1764         /* initialize all hosts */
1765         scsi_init(); 
1766                                 
1767         scsi_devices = (Scsi_Device *) NULL;
1768 
1769         for (shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
1770           scan_scsis(shpnt);           /* scan for scsi devices */
1771 
1772         sd_init1();
1773         st_init1();
1774         sr_init1();
1775         sg_init1();
1776 
1777         for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
1778           int j;
1779           SDpnt->scsi_request_fn = NULL;
1780           switch (SDpnt->type)
1781             {
1782             case TYPE_TAPE :
1783               st_attach(SDpnt);
1784               break;
1785             case TYPE_ROM:
1786               sr_attach(SDpnt);
1787               break;
1788             case TYPE_DISK:
1789             case TYPE_MOD:
1790               sd_attach(SDpnt);
1791             default:
1792               break;
1793             };
1794           sg_attach(SDpnt);
1795           if(SDpnt->type != -1){
1796             for(j=0;j<SDpnt->host->hostt->cmd_per_lun;j++){
1797               SCpnt = (Scsi_Cmnd *) scsi_init_malloc(sizeof(Scsi_Cmnd));
1798               SCpnt->host = SDpnt->host;
1799               SCpnt->device = SDpnt;
1800               SCpnt->target = SDpnt->id;
1801               SCpnt->lun = SDpnt->lun;
1802               SCpnt->request.dev = -1; /* Mark not busy */
1803               SCpnt->use_sg = 0;
1804               SCpnt->old_use_sg = 0;
1805               SCpnt->underflow = 0;
1806               SCpnt->transfersize = 0;
1807               SCpnt->host_scribble = NULL;
1808               host = SDpnt->host;
1809               if(host->host_queue)
1810                 host->host_queue->prev = SCpnt;
1811               SCpnt->next = host->host_queue;
1812               SCpnt->prev = NULL;
1813               host->host_queue = SCpnt;
1814             };
1815           };
1816         };
1817 
1818         memory_start = scsi_init_memory_start;
1819         if (NR_SD > 0 || NR_SR > 0 || NR_ST > 0)
1820           dma_sectors = 16;  /* Base value we use */
1821 
1822         for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
1823           host = SDpnt->host;
1824           
1825           if(SDpnt->type != TYPE_TAPE)
1826             dma_sectors += ((host->sg_tablesize * 
1827                              sizeof(struct scatterlist) + 511) >> 9) * 
1828                                host->hostt->cmd_per_lun;
1829           
1830           if(host->unchecked_isa_dma &&
1831              memory_end > ISA_DMA_THRESHOLD &&
1832              SDpnt->type != TYPE_TAPE) {
1833             dma_sectors += (PAGE_SIZE >> 9) * host->sg_tablesize *
1834               host->hostt->cmd_per_lun;
1835             need_isa_buffer++;
1836           };
1837         };
1838 
1839         dma_sectors = (dma_sectors + 15) & 0xfff0;
1840         dma_free_sectors = dma_sectors;  /* This must be a multiple of 16 */
1841 
1842         memory_start = (memory_start + 3) & 0xfffffffc;
1843         dma_malloc_freelist = (unsigned short *) memory_start;
1844         memory_start += dma_sectors >> 3;
1845         memset(dma_malloc_freelist, 0, dma_sectors >> 3);
1846 
1847         if(memory_start & 1) memory_start++; /* Some host adapters require
1848                                                 buffers to be word aligned */
1849         dma_malloc_buffer = (unsigned char *) memory_start;
1850         memory_start += dma_sectors << 9;
1851 
1852         memory_start = sd_init(memory_start, memory_end); /* init scsi disks */
1853         memory_start = st_init(memory_start, memory_end); /* init scsi tapes */
1854         memory_start = sr_init(memory_start, memory_end); /* init scsi CDROMs */
1855         memory_start = sg_init(memory_start, memory_end); /* init scsi generic */
1856         
1857         scsi_loadable_module_flag = 1;
1858         return memory_start;
1859         }
1860 
1861 static void print_inquiry(unsigned char *data)
     /* [previous][next][first][last][top][bottom][index][help] */
1862 {
1863         int i;
1864 
1865         printk("  Vendor: ");
1866         for (i = 8; i < 16; i++)
1867                 {
1868                 if (data[i] >= 0x20 && i < data[4] + 5)
1869                         printk("%c", data[i]);
1870                 else
1871                         printk(" ");
1872                 }
1873 
1874         printk("  Model: ");
1875         for (i = 16; i < 32; i++)
1876                 {
1877                 if (data[i] >= 0x20 && i < data[4] + 5)
1878                         printk("%c", data[i]);
1879                 else
1880                         printk(" ");
1881                 }
1882 
1883         printk("  Rev: ");
1884         for (i = 32; i < 36; i++)
1885                 {
1886                 if (data[i] >= 0x20 && i < data[4] + 5)
1887                         printk("%c", data[i]);
1888                 else
1889                         printk(" ");
1890                 }
1891 
1892         printk("\n");
1893 
1894         i = data[0] & 0x1f;
1895 
1896         printk("  Type:   %s ",
1897                i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown          " );
1898         printk("                 ANSI SCSI revision: %02x", data[2] & 0x07);
1899         if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
1900           printk(" CCS\n");
1901         else
1902           printk("\n");
1903 }
1904 
1905 #ifdef DEBUG_TIMEOUT
1906 static void 
1907 scsi_dump_status(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1908 {
1909   int i, i1;
1910   Scsi_Host * shpnt;
1911   Scsi_Cmnd * SCpnt;
1912   printk("Dump of scsi parameters:\n");
1913   for(shpnt = scsi_hosts; shpnt; shpnt = shpnt->next)
1914     for(SCpnt=shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
1915       {
1916         /*  (0) 0:0:0 (802 123434 8 8 0) (3 3 2) (%d %d %d) %d %x      */
1917         printk("(%d) %d:%d:%d (%4.4x %d %d %d %d) (%d %d %x) (%d %d %d) %x %x %d %x\n",
1918                i, SCpnt->host->host_no,
1919                SCpnt->target,
1920                SCpnt->lun,
1921                SCpnt->request.dev,
1922                SCpnt->request.sector,
1923                SCpnt->request.nr_sectors,
1924                SCpnt->request.current_nr_sectors,
1925                SCpnt->use_sg,
1926                SCpnt->retries,
1927                SCpnt->allowed,
1928                SCpnt->flags,
1929                SCpnt->timeout_per_command,
1930                SCpnt->timeout,
1931                SCpnt->internal_timeout,
1932                SCpnt->cmnd[0],
1933                SCpnt->sense_buffer[2],
1934                (SCpnt->request.waiting ? 
1935                 SCpnt->request.waiting->pid : 0),
1936                SCpnt->result);
1937       };
1938   printk("wait_for_request = %x\n", wait_for_request);
1939   /* Now dump the request lists for each block device */
1940   printk("Dump of pending block device requests\n");
1941   for(i=0; i<MAX_BLKDEV; i++)
1942     if(blk_dev[i].current_request)
1943       {
1944         struct request * req;
1945         printk("%d: ", i);
1946         req = blk_dev[i].current_request;
1947         while(req) {
1948           printk("(%x %d %d %d %d %d) ",
1949                  req->dev,
1950                  req->cmd,
1951                  req->sector,
1952                  req->nr_sectors,
1953                  req->current_nr_sectors,
1954                  (req->waiting ? 
1955                   req->waiting->pid : 0));
1956           req = req->next;
1957         }
1958         printk("\n");
1959       }
1960 }
1961 #endif
1962 
1963 

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