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

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