root/drivers/scsi/scsi.c

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

DEFINITIONS

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

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

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