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

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