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_dev_init
  21. print_inquiry
  22. 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 <asm/irq.h>
  25 
  26 #include "../block/blk.h"
  27 #include "scsi.h"
  28 #include "hosts.h"
  29 #include "constants.h"
  30 
  31 /*
  32 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 $";
  33 */
  34 
  35 /* Command groups 3 and 4 are reserved and should never be used.  */
  36 const unsigned char scsi_command_size[8] = { 6, 10, 10, 12, 12, 12, 10, 10 };
  37 
  38 #define INTERNAL_ERROR (panic ("Internal error in file %s, line %d.\n", __FILE__, __LINE__))
  39 
  40 static void scsi_done (Scsi_Cmnd *SCpnt);
  41 static int update_timeout (Scsi_Cmnd *, int);
  42 static void print_inquiry(unsigned char *data);
  43 static void scsi_times_out (Scsi_Cmnd * SCpnt);
  44 
  45 static int time_start;
  46 static int time_elapsed;
  47 
  48 #define MAX_SCSI_DEVICE_CODE 10
  49 const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] =
  50 {
  51  "Direct-Access    ",
  52  "Sequential-Access",
  53  "Printer          ",
  54  "Processor        ",
  55  "WORM             ",
  56  "CD-ROM           ",
  57  "Scanner          ",
  58  "Optical Device   ",
  59  "Medium Changer   ",
  60  "Communications   "
  61 };
  62 
  63 
  64 /*
  65         global variables : 
  66         NR_SCSI_DEVICES is the number of SCSI devices we have detected, 
  67         scsi_devices an array of these specifing the address for each 
  68         (host, id, LUN)
  69 */
  70         
  71 int NR_SCSI_DEVICES=0;
  72 
  73 Scsi_Device * scsi_devices = NULL;
  74 
  75 static unsigned char generic_sense[6] = {REQUEST_SENSE, 0,0,0, 255, 0};
  76 
  77 /* We make this not static so that we can read the array with gdb. */
  78 /* static */ Scsi_Cmnd * last_cmnd = NULL;
  79 
  80 /*
  81  *      As the scsi do command functions are inteligent, and may need to 
  82  *      redo a command, we need to keep track of the last command 
  83  *      executed on each one.
  84  */
  85 
  86 #define WAS_RESET       0x01
  87 #define WAS_TIMEDOUT    0x02
  88 #define WAS_SENSE       0x04
  89 #define IS_RESETTING    0x08
  90 #define IS_ABORTING     0x10
  91 #define ASKED_FOR_SENSE 0x20
  92 
  93 /*
  94  *      This is the number  of clock ticks we should wait before we time out 
  95  *      and abort the command.  This is for  where the scsi.c module generates 
  96  *      the command, not where it originates from a higher level, in which
  97  *      case the timeout is specified there.
  98  *
  99  *      ABORT_TIMEOUT and RESET_TIMEOUT are the timeouts for RESET and ABORT
 100  *      respectively.
 101  */
 102 
 103 #ifdef DEBUG_TIMEOUT
 104 static void scsi_dump_status(void);
 105 #endif
 106 
 107 
 108 #ifdef DEBUG
 109         #define SCSI_TIMEOUT 500
 110 #else
 111         #define SCSI_TIMEOUT 100
 112 #endif
 113 
 114 #ifdef DEBUG
 115         #define SENSE_TIMEOUT SCSI_TIMEOUT
 116         #define ABORT_TIMEOUT SCSI_TIMEOUT
 117         #define RESET_TIMEOUT SCSI_TIMEOUT
 118 #else
 119         #define SENSE_TIMEOUT 50
 120         #define RESET_TIMEOUT 50
 121         #define ABORT_TIMEOUT 50
 122         #define MIN_RESET_DELAY 100
 123 #endif
 124 
 125 /* The following devices are known not to tolerate a lun != 0 scan for
 126    one reason or another.  Some will respond to all luns, others will
 127    lock up. */
 128 
 129      struct blist{
 130        char * vendor;
 131        char * model;
 132        char * revision; /* Latest revision known to be bad.  Not used yet */
 133      };
 134 
 135 static struct blist blacklist[] = 
 136 {
 137    {"CHINON","CD-ROM CDS-431","H42"},  /* Locks up if polled for lun != 0 */
 138    {"CHINON","CD-ROM CDS-535","Q14"}, /* Lockup if polled for lun != 0 */
 139    {"DENON","DRD-25X","V"},   /* A cdrom that locks up when probed at lun != 0 */
 140    {"IMS", "CDD521/10","2.06"},   /* Locks-up when LUN>0 polled. */
 141    {"MAXTOR","XT-3280","PR02"},   /* Locks-up when LUN>0 polled. */
 142    {"MAXTOR","XT-4380S","B3C"},   /* Locks-up when LUN>0 polled. */
 143    {"MAXTOR","MXT-1240S","I1.2"}, /* Locks up when LUN > 0 polled */
 144    {"MAXTOR","XT-4170S","B5A"},   /* Locks-up sometimes when LUN>0 polled. */
 145    {"MAXTOR","XT-8760S","B7B"},   /* guess what? */
 146    {"NEC","CD-ROM DRIVE:841","1.0"},  /* Locks-up when LUN>0 polled. */
 147    {"RODIME","RO3000S","2.33"},  /* Locks up if polled for lun != 0 */
 148    {"SEAGATE", "ST157N", "\004|j"}, /* causes failed REQUEST SENSE on lun 1 for aha152x
 149                                      * controller, which causes SCSI code to reset bus.*/
 150    {"SEAGATE", "ST296","921"},   /* Responds to all lun */
 151    {"SONY","CD-ROM CDU-541","4.3d"},
 152    {"TANDBERG","TDC 3600","U07"},  /* Locks up if polled for lun != 0 */
 153    {"TEAC","CD-ROM","1.06"},    /* causes failed REQUEST SENSE on lun 1 for seagate
 154                                  * controller, which causes SCSI code to reset bus.*/
 155    {"TEXEL","CD-ROM","1.06"},   /* causes failed REQUEST SENSE on lun 1 for seagate
 156                                  * controller, which causes SCSI code to reset bus.*/
 157    {NULL, NULL, NULL}}; 
 158 
 159 static int blacklisted(unsigned char * response_data){
     /* [previous][next][first][last][top][bottom][index][help] */
 160   int i = 0;
 161   unsigned char * pnt;
 162   for(i=0; 1; i++){
 163     if(blacklist[i].vendor == NULL) return 0;
 164     pnt = &response_data[8];
 165     while(*pnt && *pnt == ' ') pnt++;
 166     if(memcmp(blacklist[i].vendor, pnt,
 167                strlen(blacklist[i].vendor))) continue;
 168     pnt = &response_data[16];
 169     while(*pnt && *pnt == ' ') pnt++;
 170     if(memcmp(blacklist[i].model, pnt,
 171                strlen(blacklist[i].model))) continue;
 172     return 1;
 173   };    
 174 };
 175 
 176 /*
 177  *      As the actual SCSI command runs in the background, we must set up a 
 178  *      flag that tells scan_scsis() when the result it has is valid.  
 179  *      scan_scsis can set the_result to -1, and watch for it to become the 
 180  *      actual return code for that call.  the scan_scsis_done function() is 
 181  *      our user specified completion function that is passed on to the  
 182  *      scsi_do_cmd() function.
 183  */
 184 
 185 static volatile int in_scan = 0;
 186 static int the_result;
 187 static void scan_scsis_done (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 188         {
 189         
 190 #ifdef DEBUG
 191         printk ("scan_scsis_done(%d, %06x)\n", SCpnt->host, SCpnt->result);
 192 #endif  
 193         SCpnt->request.dev = 0xfffe;
 194         }
 195 
 196 #ifdef NO_MULTI_LUN
 197 static int max_scsi_luns = 1;
 198 #else
 199 static int max_scsi_luns = 8;
 200 #endif
 201 
 202 void scsi_luns_setup(char *str, int *ints) {
     /* [previous][next][first][last][top][bottom][index][help] */
 203     if (ints[0] != 1) 
 204         printk("scsi_luns_setup : usage max_scsi_luns=n (n should be between 1 and 8)\n");
 205     else
 206         max_scsi_luns = ints[1];
 207 }
 208 
 209 /*
 210  *      Detecting SCSI devices :        
 211  *      We scan all present host adapter's busses,  from ID 0 to ID 6.  
 212  *      We use the INQUIRY command, determine device type, and pass the ID / 
 213  *      lun address of all sequential devices to the tape driver, all random 
 214  *      devices to the disk driver.
 215  */
 216 
 217 static void scan_scsis (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 218 {
 219   int dev, lun, type;
 220   unsigned char scsi_cmd [12];
 221   unsigned char scsi_result [256];
 222   struct Scsi_Host * shpnt;
 223   Scsi_Cmnd  SCmd;
 224   
 225   ++in_scan;
 226   lun = 0;
 227   
 228   SCmd.next = NULL;
 229   SCmd.prev = NULL;
 230   for (shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
 231       {
 232         shpnt->host_queue = &SCmd;  /* We need this so that
 233                                          commands can time out */
 234         for (dev = 0; dev < 8; ++dev)
 235           if (shpnt->this_id != dev)
 236 /*
 237  * We need the for so our continue, etc. work fine.
 238  */
 239 
 240             for (lun = 0; lun < max_scsi_luns; ++lun)
 241               {
 242                 scsi_devices[NR_SCSI_DEVICES].host = shpnt;
 243                 scsi_devices[NR_SCSI_DEVICES].id = dev;
 244                 scsi_devices[NR_SCSI_DEVICES].lun = lun;
 245                 scsi_devices[NR_SCSI_DEVICES].index = NR_SCSI_DEVICES;
 246                 scsi_devices[NR_SCSI_DEVICES].device_wait = NULL;
 247 /*
 248  * Assume that the device will have handshaking problems, and then 
 249  * fix this field later if it turns out it doesn't.
 250  */
 251                 scsi_devices[NR_SCSI_DEVICES].borken = 1;
 252                 
 253                 scsi_cmd[0] = TEST_UNIT_READY;
 254                 scsi_cmd[1] = lun << 5;
 255                 scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[5] = 0;
 256                 scsi_cmd[4] = 0;
 257 
 258                 SCmd.host = shpnt;
 259                 SCmd.target = dev;
 260                 SCmd.lun = lun;
 261 
 262                 SCmd.request.dev = 0xffff; /* Mark not busy */
 263                 SCmd.use_sg  = 0;
 264                 SCmd.old_use_sg  = 0;
 265                 SCmd.transfersize = 0;
 266                 SCmd.underflow = 0;
 267                 SCmd.index = NR_SCSI_DEVICES;
 268 
 269                 scsi_do_cmd (&SCmd,
 270                              (void *)  scsi_cmd, (void *) 
 271                              scsi_result, 256,  scan_scsis_done, 
 272                              SCSI_TIMEOUT + 400, 5);
 273                 
 274                 while (SCmd.request.dev != 0xfffe);
 275 #if defined(DEBUG) || defined(DEBUG_INIT)
 276                 printk("scsi: scan SCSIS id %d lun %d\n", dev, lun);
 277                 printk("scsi: return code %08x\n", SCmd.result);
 278 #endif
 279 
 280 
 281                 if(SCmd.result) {
 282                   if ((driver_byte(SCmd.result)  & DRIVER_SENSE) &&
 283                       ((SCmd.sense_buffer[0] & 0x70) >> 4) == 7) {
 284                     if (SCmd.sense_buffer[2] &0xe0)
 285                       continue; /* No devices here... */
 286                     if(((SCmd.sense_buffer[2] & 0xf) != NOT_READY) &&
 287                        ((SCmd.sense_buffer[2] & 0xf) != UNIT_ATTENTION))
 288                       continue;
 289                   }
 290                   else
 291                     break;
 292                 };
 293 
 294 #if defined (DEBUG) || defined(DEBUG_INIT)
 295                 printk("scsi: performing INQUIRY\n");
 296 #endif
 297 
 298                 /*
 299                  * Build an INQUIRY command block.  
 300                  */
 301                 
 302                 scsi_cmd[0] = INQUIRY;
 303                 scsi_cmd[1] = (lun << 5) & 0xe0;
 304                 scsi_cmd[2] = 0;
 305                 scsi_cmd[3] = 0;
 306                 scsi_cmd[4] = 255;
 307                 scsi_cmd[5] = 0;
 308                 
 309                 SCmd.request.dev = 0xffff; /* Mark not busy */
 310                 
 311                 scsi_do_cmd (&SCmd,
 312                              (void *)  scsi_cmd, (void *) 
 313                              scsi_result, 256,  scan_scsis_done, 
 314                              SCSI_TIMEOUT, 3);
 315                 
 316                 while (SCmd.request.dev != 0xfffe);
 317                 
 318                 the_result = SCmd.result;
 319                 
 320 #if defined(DEBUG) || defined(DEBUG_INIT)
 321                 if (!the_result)
 322                         printk("scsi: INQUIRY successful\n");
 323                 else
 324                         printk("scsi: INQUIRY failed with code %08x\n");
 325 #endif
 326 
 327                 if(the_result) break; 
 328 
 329                 /* skip other luns on this device */
 330                 
 331                 if (!the_result)
 332                   {
 333                     scsi_devices[NR_SCSI_DEVICES].
 334                       removable = (0x80 & 
 335                                    scsi_result[1]) >> 7;
 336                     scsi_devices[NR_SCSI_DEVICES].lockable =
 337                       scsi_devices[NR_SCSI_DEVICES].removable;
 338                     scsi_devices[NR_SCSI_DEVICES].
 339                       changed = 0;
 340                     scsi_devices[NR_SCSI_DEVICES].
 341                       access_count = 0;
 342                     scsi_devices[NR_SCSI_DEVICES].
 343                       busy = 0;
 344 /* 
 345  *      Currently, all sequential devices are assumed to be tapes,
 346  *      all random devices disk, with the appropriate read only 
 347  *      flags set for ROM / WORM treated as RO.
 348  */ 
 349 
 350                     switch (type = scsi_result[0])
 351                       {
 352                       case TYPE_TAPE :
 353                       case TYPE_DISK :
 354                       case TYPE_MOD :
 355                         scsi_devices[NR_SCSI_DEVICES].writeable = 1;
 356                         break;
 357                       case TYPE_WORM :
 358                       case TYPE_ROM :
 359                         scsi_devices[NR_SCSI_DEVICES].writeable = 0;
 360                         break;
 361                         default :
 362 #if 0
 363 #ifdef DEBUG
 364                         printk("scsi: unknown type %d\n", type);
 365                         print_inquiry(scsi_result);
 366 #endif
 367 #endif
 368                           type = -1;
 369                       }
 370 
 371                     scsi_devices[NR_SCSI_DEVICES].soft_reset = 
 372                       (scsi_result[7] & 1) && ((scsi_result[3] & 7) == 2);
 373                     scsi_devices[NR_SCSI_DEVICES].random = 
 374                       (type == TYPE_TAPE) ? 0 : 1;
 375                     scsi_devices[NR_SCSI_DEVICES].type = type;
 376 
 377                     if (type != -1)
 378                       {
 379                         print_inquiry(scsi_result);
 380                         switch(type){
 381                         case TYPE_TAPE:
 382                           printk("Detected scsi tape st%d at scsi%d, id %d, lun %d\n", MAX_ST,
 383                                  shpnt->host_no , dev, lun); 
 384                           if(NR_ST != -1) ++MAX_ST;
 385                           break;
 386                         case TYPE_ROM:
 387                           printk("Detected scsi CD-ROM sr%d at scsi%d, id %d, lun %d\n", MAX_SR,
 388                                  shpnt->host_no , dev, lun); 
 389                           if(NR_SR != -1) ++MAX_SR;
 390                           break;
 391                         case TYPE_DISK:
 392                         case TYPE_MOD:
 393                           printk("Detected scsi disk sd%c at scsi%d, id %d, lun %d\n", 'a'+MAX_SD,
 394                                  shpnt->host_no , dev, lun); 
 395                           if(NR_SD != -1) ++MAX_SD;
 396                           break;
 397                         default:
 398                           break;
 399                         };
 400 
 401                         if(NR_SG != -1) ++MAX_SG;
 402 
 403                         scsi_devices[NR_SCSI_DEVICES].scsi_level =
 404                           scsi_result[2] & 0x07;
 405                         if (scsi_devices[NR_SCSI_DEVICES].scsi_level >= 2 ||
 406                             (scsi_devices[NR_SCSI_DEVICES].scsi_level == 1 &&
 407                              (scsi_result[3] & 0x0f) == 1))
 408                           scsi_devices[NR_SCSI_DEVICES].scsi_level++;
 409 /* 
 410  * Set the tagged_queue flag for SCSI-II devices that purport to support
 411  * tagged queuing in the INQUIRY data.
 412  */
 413 
 414                         scsi_devices[NR_SCSI_DEVICES].tagged_queue = 0;
 415 
 416                         if ((scsi_devices[NR_SCSI_DEVICES].scsi_level >= SCSI_2) &&
 417                             (scsi_result[7] & 2)) {
 418                             scsi_devices[NR_SCSI_DEVICES].tagged_supported = 1;
 419                             scsi_devices[NR_SCSI_DEVICES].current_tag = 0;
 420                         }
 421 
 422 /*
 423  * Accomodate drivers that want to sleep when they should be in a polling
 424  * loop.
 425  */
 426 
 427                         scsi_devices[NR_SCSI_DEVICES].disconnect = 0;
 428 
 429 /*
 430  * Some revisions of the Texel CD ROM drives have handshaking
 431  * problems when used with the Seagate controllers.  Before we
 432  * know what type of device we're talking to, we assume it's 
 433  * borken and then change it here if it turns out that it isn't
 434  * a TEXEL drive.
 435  */
 436 
 437                         if(strncmp("TEXEL", (char *) &scsi_result[8], 5) != 0 ||
 438                           strncmp("CD-ROM", (char *) &scsi_result[16], 6) != 0 
 439 /* 
 440  * XXX 1.06 has problems, some one should figure out the others too so
 441  * ALL TEXEL drives don't suffer in performance, especially when I finish
 442  * integrating my seagate patches which do multiple I_T_L nexuses.
 443  */
 444 
 445 #ifdef notyet
 446                            || (strncmp("1.06", (char *) &scsi_result[[, 4) != 0)
 447 #endif
 448                            )
 449                            scsi_devices[NR_SCSI_DEVICES].borken = 0;
 450 
 451 
 452                         /* These devices need this "key" to unlock the device
 453                            so we can use it */
 454                         if(memcmp("INSITE", &scsi_result[8], 6) == 0 &&
 455                            (memcmp("Floptical   F*8I", &scsi_result[16], 16) == 0
 456                             || memcmp("I325VM", &scsi_result[16], 6) == 0)) {
 457                           printk("Unlocked floptical drive.\n");
 458                           scsi_devices[NR_SCSI_DEVICES].lockable = 0;
 459                           scsi_cmd[0] = MODE_SENSE;
 460                           scsi_cmd[1] = (lun << 5) & 0xe0;
 461                           scsi_cmd[2] = 0x2e;
 462                           scsi_cmd[3] = 0;
 463                           scsi_cmd[4] = 0x2a;
 464                           scsi_cmd[5] = 0;
 465                 
 466                           SCmd.request.dev = 0xffff; /* Mark not busy */
 467                           
 468                           scsi_do_cmd (&SCmd,
 469                                        (void *)  scsi_cmd, (void *) 
 470                                        scsi_result, 0x2a,  scan_scsis_done, 
 471                                        SCSI_TIMEOUT, 3);
 472                 
 473                           while (SCmd.request.dev != 0xfffe);
 474                         };
 475 
 476                         ++NR_SCSI_DEVICES;
 477                         /* Some scsi devices cannot be polled for lun != 0
 478                            due to firmware bugs */
 479                         if(blacklisted(scsi_result)) break;
 480                         /* Old drives like the MAXTOR XT-3280 say vers=0 */
 481                         if ((scsi_result[2] & 0x07) == 0)
 482                             break;
 483                         /* Some scsi-1 peripherals do not handle lun != 0.
 484                            I am assuming that scsi-2 peripherals do better */
 485                         if((scsi_result[2] & 0x07) == 1 && 
 486                            (scsi_result[3] & 0x0f) == 0) break;
 487                         }
 488                   }       /* if result == DID_OK ends */
 489               }       /* for lun ends */
 490         shpnt->host_queue = NULL;  /* No longer needed here */
 491       }         /* if present */  
 492   
 493   printk("scsi : detected ");
 494   if(NR_SD != -1)
 495     printk("%d SCSI disk%s ", MAX_SD, (MAX_SD != 1) ? "s" : "");
 496          
 497   if(NR_ST != -1)
 498     printk("%d tape%s ", MAX_ST, (MAX_ST != 1) ? "s" : "");
 499 
 500   if(NR_SR != -1)
 501     printk("%d CD-ROM drive%s ", MAX_SR, (MAX_SR != 1) ? "s" : "");
 502 
 503   printk("total.\n");
 504   in_scan = 0;
 505 }       /* scan_scsis  ends */
 506 
 507 /*
 508  *      Flag bits for the internal_timeout array 
 509  */
 510 
 511 #define NORMAL_TIMEOUT 0
 512 #define IN_ABORT 1
 513 #define IN_RESET 2
 514 /*
 515         This is our time out function, called when the timer expires for a 
 516         given host adapter.  It will attempt to abort the currently executing 
 517         command, that failing perform a kernel panic.
 518 */ 
 519 
 520 static void scsi_times_out (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 521         {
 522         
 523         switch (SCpnt->internal_timeout & (IN_ABORT | IN_RESET))
 524                 {
 525                 case NORMAL_TIMEOUT:
 526                         if (!in_scan) {
 527                           printk("SCSI host %d timed out - aborting command\n",
 528                                  SCpnt->host->host_no);
 529 #ifdef DEBUG_TIMEOUT
 530                           scsi_dump_status();
 531 #endif
 532                         }
 533                         
 534                         if (!scsi_abort (SCpnt, DID_TIME_OUT))
 535                                 return;                         
 536                 case IN_ABORT:
 537                         printk("SCSI host %d abort() timed out - reseting\n",
 538                                 SCpnt->host->host_no);
 539                         if (!scsi_reset (SCpnt)) 
 540                                 return;
 541                 case IN_RESET:
 542                 case (IN_ABORT | IN_RESET):
 543                   /* This might be controversial, but if there is a bus hang,
 544                      you might conceivably want the machine up and running
 545                      esp if you have an ide disk. */
 546                         printk("Unable to reset scsi host %d - ",SCpnt->host->host_no);
 547                         printk("probably a SCSI bus hang.\n");
 548                         return;
 549 
 550                 default:
 551                         INTERNAL_ERROR;
 552                 }
 553                                         
 554         }
 555 
 556 
 557 /* This function takes a quick look at a request, and decides if it
 558 can be queued now, or if there would be a stall while waiting for
 559 something else to finish.  This routine assumes that interrupts are
 560 turned off when entering the routine.  It is the responsibility
 561 of the calling code to ensure that this is the case. */
 562 
 563 Scsi_Cmnd * request_queueable (struct request * req, int index)
     /* [previous][next][first][last][top][bottom][index][help] */
 564 {
 565   Scsi_Cmnd * SCpnt = NULL;
 566   int tablesize;
 567   struct buffer_head * bh, *bhp;
 568 
 569   if ((index < 0) ||  (index > NR_SCSI_DEVICES))
 570     panic ("Index number in allocate_device() is out of range.\n");
 571   
 572   if (req && req->dev <= 0)
 573     panic("Invalid device in allocate_device");
 574   
 575   SCpnt =  scsi_devices[index].host->host_queue;
 576     while(SCpnt){
 577       if(SCpnt->target == scsi_devices[index].id &&
 578          SCpnt->lun == scsi_devices[index].lun)
 579         if(SCpnt->request.dev < 0) break;
 580       SCpnt = SCpnt->next;
 581     };
 582 
 583   if (!SCpnt) return NULL;
 584 
 585   if (scsi_devices[index].host->hostt->can_queue
 586       && scsi_devices[index].host->host_busy >= scsi_devices[index].host->hostt->can_queue) return NULL;
 587 
 588   if (req) {
 589     memcpy(&SCpnt->request, req, sizeof(struct request));
 590     tablesize = scsi_devices[index].host->sg_tablesize;
 591     bhp = bh = req->bh;
 592     if(!tablesize) bh = NULL;
 593     /* Take a quick look through the table to see how big it is.  We already
 594        have our copy of req, so we can mess with that if we want to.  */
 595     while(req->nr_sectors && bh){
 596             bhp = bhp->b_reqnext;
 597             if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
 598             req->nr_sectors -= bh->b_size >> 9;
 599             req->sector += bh->b_size >> 9;
 600             if(!tablesize) break;
 601             bh = bhp;
 602     };
 603     if(req->nr_sectors && bh && bh->b_reqnext){  /* Any leftovers? */
 604       SCpnt->request.bhtail = bh;
 605       req->bh = bh->b_reqnext; /* Divide request */
 606       bh->b_reqnext = NULL;
 607       bh = req->bh;
 608 
 609       /* Now reset things so that req looks OK */
 610       SCpnt->request.nr_sectors -= req->nr_sectors;
 611       req->current_nr_sectors = bh->b_size >> 9;
 612       req->buffer = bh->b_data;
 613       SCpnt->request.waiting = NULL; /* Wait until whole thing done */
 614     } else {
 615       req->dev = -1;
 616       wake_up(&wait_for_request);
 617     };      
 618   } else {
 619     SCpnt->request.dev = 0xffff; /* Busy, but no request */
 620     SCpnt->request.waiting = NULL;  /* And no one is waiting for the device either */
 621   };
 622 
 623   SCpnt->use_sg = 0;  /* Reset the scatter-gather flag */
 624   SCpnt->old_use_sg  = 0;
 625   SCpnt->transfersize = 0;
 626   SCpnt->underflow = 0;
 627   return SCpnt;
 628 }
 629 
 630 /* This function returns a structure pointer that will be valid for
 631 the device.  The wait parameter tells us whether we should wait for
 632 the unit to become free or not.  We are also able to tell this routine
 633 not to return a descriptor if the host is unable to accept any more
 634 commands for the time being.  We need to keep in mind that there is no
 635 guarantee that the host remain not busy.  Keep in mind the
 636 request_queueable function also knows the internal allocation scheme
 637 of the packets for each device */
 638 
 639 Scsi_Cmnd * allocate_device (struct request ** reqp, int index, int wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 640 {
 641   int dev = -1;
 642   struct request * req = NULL;
 643   int tablesize;
 644   struct buffer_head * bh, *bhp;
 645   struct Scsi_Host * host;
 646   Scsi_Cmnd * SCpnt = NULL;
 647   Scsi_Cmnd * SCwait = NULL;
 648 
 649   if ((index < 0) ||  (index > NR_SCSI_DEVICES))
 650     panic ("Index number in allocate_device() is out of range.\n");
 651   
 652   if (reqp) req = *reqp;
 653 
 654     /* See if this request has already been queued by an interrupt routine */
 655   if (req && (dev = req->dev) <= 0) return NULL;
 656   
 657   host = scsi_devices[index].host;
 658   
 659   while (1==1){
 660     SCpnt = host->host_queue;
 661     while(SCpnt){
 662       if(SCpnt->target == scsi_devices[index].id &&
 663          SCpnt->lun == scsi_devices[index].lun) {
 664         SCwait = SCpnt;
 665         if(SCpnt->request.dev < 0) break;
 666       };
 667       SCpnt = SCpnt->next;
 668     };
 669     cli();
 670     /* See if this request has already been queued by an interrupt routine */
 671     if (req && ((req->dev < 0) || (req->dev != dev))) {
 672       sti();
 673       return NULL;
 674     };
 675     if (!SCpnt || SCpnt->request.dev >= 0)  /* Might have changed */
 676       {
 677         sti();
 678         if(!wait) return NULL;
 679         if (!SCwait) {
 680           printk("Attempt to allocate device index %d, target %d, lun %d\n",
 681                  index, scsi_devices[index].id ,scsi_devices[index].lun);
 682           panic("No device found in allocate_device\n");
 683         };
 684         SCSI_SLEEP(&scsi_devices[SCwait->index].device_wait, 
 685                    (SCwait->request.dev > 0));
 686       } else {
 687         if (req) {
 688           memcpy(&SCpnt->request, req, sizeof(struct request));
 689           tablesize = scsi_devices[index].host->sg_tablesize;
 690           bhp = bh = req->bh;
 691           if(!tablesize) bh = NULL;
 692           /* Take a quick look through the table to see how big it is.  We already
 693              have our copy of req, so we can mess with that if we want to.  */
 694           while(req->nr_sectors && bh){
 695             bhp = bhp->b_reqnext;
 696             if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
 697             req->nr_sectors -= bh->b_size >> 9;
 698             req->sector += bh->b_size >> 9;
 699             if(!tablesize) break;
 700             bh = bhp;
 701           };
 702           if(req->nr_sectors && bh && bh->b_reqnext){  /* Any leftovers? */
 703             SCpnt->request.bhtail = bh;
 704             req->bh = bh->b_reqnext; /* Divide request */
 705             bh->b_reqnext = NULL;
 706             bh = req->bh;
 707             /* Now reset things so that req looks OK */
 708             SCpnt->request.nr_sectors -= req->nr_sectors;
 709             req->current_nr_sectors = bh->b_size >> 9;
 710             req->buffer = bh->b_data;
 711             SCpnt->request.waiting = NULL; /* Wait until whole thing done */
 712           }
 713           else 
 714             {
 715               req->dev = -1;
 716               *reqp = req->next;
 717               wake_up(&wait_for_request);
 718             };
 719         } else {
 720           SCpnt->request.dev = 0xffff; /* Busy */
 721           SCpnt->request.waiting = NULL;  /* And no one is waiting for this to complete */
 722         };
 723         sti();
 724         break;
 725       };
 726   };
 727 
 728   SCpnt->use_sg = 0;  /* Reset the scatter-gather flag */
 729   SCpnt->old_use_sg  = 0;
 730   SCpnt->transfersize = 0;      /* No default transfer size */
 731   SCpnt->underflow = 0;         /* Do not flag underflow conditions */
 732   return SCpnt;
 733 }
 734 
 735 /*
 736         This is inline because we have stack problemes if we recurse to deeply.
 737 */
 738                          
 739 inline void internal_cmnd (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 740         {
 741         int temp;
 742         struct Scsi_Host * host;
 743 #ifdef DEBUG_DELAY      
 744         int clock;
 745 #endif
 746 
 747         if ((unsigned long) &SCpnt < current->kernel_stack_page)
 748           panic("Kernel stack overflow.");
 749 
 750         host = SCpnt->host;
 751 
 752 /*
 753         We will wait MIN_RESET_DELAY clock ticks after the last reset so 
 754         we can avoid the drive not being ready.
 755 */ 
 756 temp = host->last_reset;
 757 while (jiffies < temp);
 758 
 759 update_timeout(SCpnt, SCpnt->timeout_per_command);
 760 
 761 /*
 762         We will use a queued command if possible, otherwise we will emulate the
 763         queing and calling of completion function ourselves. 
 764 */
 765 #ifdef DEBUG
 766         printk("internal_cmnd (host = %d, target = %d, command = %08x, buffer =  %08x, \n"
 767                 "bufflen = %d, done = %08x)\n", SCpnt->host->host_no, SCpnt->target, SCpnt->cmnd, SCpnt->buffer, SCpnt->bufflen, SCpnt->done);
 768 #endif
 769 
 770         if (host->hostt->can_queue)
 771                 {
 772                   extern unsigned long intr_count;
 773 #ifdef DEBUG
 774         printk("queuecommand : routine at %08x\n", 
 775                 host->hostt->queuecommand);
 776 #endif
 777                   /* This locking tries to prevent all sorts of races between
 778                      queuecommand and the interrupt code.  In effect,
 779                      we are only allowed to be in queuecommand once at
 780                      any given time, and we can only be in the interrupt
 781                      handler and the queuecommand function at the same time
 782                      when queuecommand is called while servicing the
 783                      interrupt. */
 784 
 785                 if(!intr_count && SCpnt->host->irq)
 786                   disable_irq(SCpnt->host->irq);
 787 
 788                 host->hostt->queuecommand (SCpnt, scsi_done);
 789 
 790                 if(!intr_count && SCpnt->host->irq)
 791                   enable_irq(SCpnt->host->irq);
 792                 }
 793         else
 794                 {
 795 
 796 #ifdef DEBUG
 797         printk("command() :  routine at %08x\n", host->hostt->command);
 798 #endif
 799                 temp=host->hostt->command (SCpnt);
 800                 SCpnt->result = temp;
 801 #ifdef DEBUG_DELAY
 802         clock = jiffies + 400;
 803         while (jiffies < clock);
 804         printk("done(host = %d, result = %04x) : routine at %08x\n", host->host_no, temp, done);
 805 #endif
 806                 scsi_done(SCpnt);
 807                 }       
 808 #ifdef DEBUG
 809         printk("leaving internal_cmnd()\n");
 810 #endif
 811         }       
 812 
 813 static void scsi_request_sense (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 814         {
 815         cli();
 816         SCpnt->flags |= WAS_SENSE | ASKED_FOR_SENSE;
 817         update_timeout(SCpnt, SENSE_TIMEOUT);
 818         sti();
 819         
 820 
 821         memcpy ((void *) SCpnt->cmnd , (void *) generic_sense,
 822                 sizeof(generic_sense));
 823 
 824         SCpnt->cmnd[1] = SCpnt->lun << 5;       
 825         SCpnt->cmnd[4] = sizeof(SCpnt->sense_buffer);
 826 
 827         SCpnt->request_buffer = &SCpnt->sense_buffer;
 828         SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
 829         SCpnt->use_sg = 0;
 830         internal_cmnd (SCpnt);
 831         SCpnt->use_sg = SCpnt->old_use_sg;
 832         }
 833 
 834 
 835 
 836 /*
 837         scsi_do_cmd sends all the commands out to the low-level driver.  It 
 838         handles the specifics required for each low level driver - ie queued 
 839         or non queud.  It also prevents conflicts when different high level 
 840         drivers go for the same host at the same time.
 841 */
 842 
 843 void scsi_do_cmd (Scsi_Cmnd * SCpnt, const void *cmnd , 
     /* [previous][next][first][last][top][bottom][index][help] */
 844                   void *buffer, unsigned bufflen, void (*done)(Scsi_Cmnd *),
 845                   int timeout, int retries 
 846                    )
 847         {
 848         struct Scsi_Host * host = SCpnt->host;
 849 
 850 #ifdef DEBUG
 851         {
 852         int i;  
 853         int target = SCpnt->target;
 854         printk ("scsi_do_cmd (host = %d, target = %d, buffer =%08x, "
 855                 "bufflen = %d, done = %08x, timeout = %d, retries = %d)\n"
 856                 "command : " , host->host_no, target, buffer, bufflen, done, timeout, retries);
 857         for (i = 0; i < 10; ++i)
 858                 printk ("%02x  ", ((unsigned char *) cmnd)[i]); 
 859         printk("\n");
 860       };
 861 #endif
 862         
 863         if (!host)
 864                 {
 865                 panic ("Invalid or not present host. %d\n", host->host_no);
 866                 }
 867 
 868         
 869 /*
 870         We must prevent reentrancy to the lowlevel host driver.  This prevents 
 871         it - we enter a loop until the host we want to talk to is not busy.   
 872         Race conditions are prevented, as interrupts are disabled inbetween the
 873         time we check for the host being not busy, and the time we mark it busy
 874         ourselves.
 875 */
 876 
 877         while (1==1){
 878           cli();
 879           if (host->hostt->can_queue
 880               && host->host_busy >= host->hostt->can_queue)
 881             {
 882               sti();
 883               SCSI_SLEEP(&host->host_wait, 
 884                          (host->host_busy >= host->hostt->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 (scsi_devices[SCpnt->index].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 recieved\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 rentrantly 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                         switch(temp) {
1496                         case SCSI_RESET_SUCCESS:
1497                           cli();
1498                           SCpnt->internal_timeout &= ~IN_RESET;
1499                           update_timeout(SCpnt, oldto);
1500                           sti();
1501                           return 0;
1502                         case SCSI_RESET_PENDING:
1503                           return 0;
1504                         case SCSI_RESET_PUNT:
1505                         case SCSI_RESET_WAKEUP:
1506                           SCpnt->internal_timeout &= ~IN_RESET;
1507                           scsi_request_sense (SCpnt);
1508                           return 0;
1509                         case SCSI_RESET_SNOOZE:                   
1510                           /* In this case, we set the timeout field to 0
1511                              so that this command does not time out any more,
1512                              and we return 1 so that we get a message on the
1513                              screen. */
1514                           cli();
1515                           SCpnt->internal_timeout &= ~IN_RESET;
1516                           update_timeout(SCpnt, 0);
1517                           sti();
1518                           /* If you snooze, you lose... */
1519                         case SCSI_RESET_ERROR:
1520                         default:
1521                           return 1;
1522                         }
1523         
1524                         return temp;    
1525                         }
1526                 }
1527         }
1528                          
1529 
1530 static void scsi_main_timeout(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1531         {
1532         /*
1533                 We must not enter update_timeout with a timeout condition still pending.
1534         */
1535 
1536         int timed_out;
1537         struct Scsi_Host * host;
1538         Scsi_Cmnd * SCpnt = NULL;
1539 
1540         do      {       
1541                 cli();
1542 
1543                 update_timeout(NULL, 0);
1544         /*
1545                 Find all timers such that they have 0 or negative (shouldn't happen)
1546                 time remaining on them.
1547         */
1548                         
1549                 timed_out = 0;
1550                 for(host = scsi_hostlist; host; host = host->next) {
1551                   for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
1552                     if (SCpnt->timeout == -1)
1553                       {
1554                         sti();
1555                         SCpnt->timeout = 0;
1556                         scsi_times_out(SCpnt);
1557                         ++timed_out; 
1558                         cli();
1559                       }
1560                 };
1561               } while (timed_out);      
1562         sti();
1563       }
1564 
1565 /*
1566         The strategy is to cause the timer code to call scsi_times_out()
1567         when the soonest timeout is pending.  
1568         The arguments are used when we are queueing a new command, because
1569         we do not want to subtract the time used from this time, but when we
1570         set the timer, we want to take this value into account.
1571 */
1572         
1573 static int update_timeout(Scsi_Cmnd * SCset, int timeout)
     /* [previous][next][first][last][top][bottom][index][help] */
1574         {
1575         unsigned int least, used;
1576         unsigned int oldto;
1577         struct Scsi_Host * host;
1578         Scsi_Cmnd * SCpnt = NULL;
1579 
1580         cli();
1581 
1582 /* 
1583         Figure out how much time has passed since the last time the timeouts 
1584         were updated 
1585 */
1586         used = (time_start) ? (jiffies - time_start) : 0;
1587 
1588 /*
1589         Find out what is due to timeout soonest, and adjust all timeouts for
1590         the amount of time that has passed since the last time we called 
1591         update_timeout. 
1592 */
1593         
1594         oldto = 0;
1595 
1596         if(SCset){
1597           oldto = SCset->timeout - used;
1598           SCset->timeout = timeout + used;
1599         };
1600 
1601         least = 0xffffffff;
1602 
1603         for(host = scsi_hostlist; host; host = host->next)
1604           for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
1605             if (SCpnt->timeout > 0) {
1606               SCpnt->timeout -= used;
1607               if(SCpnt->timeout <= 0) SCpnt->timeout = -1;
1608               if(SCpnt->timeout > 0 && SCpnt->timeout < least)
1609                 least = SCpnt->timeout;
1610             };
1611 
1612 /*
1613         If something is due to timeout again, then we will set the next timeout 
1614         interrupt to occur.  Otherwise, timeouts are disabled.
1615 */
1616         
1617         if (least != 0xffffffff)
1618                 {
1619                 time_start = jiffies;   
1620                 timer_table[SCSI_TIMER].expires = (time_elapsed = least) + jiffies;     
1621                 timer_active |= 1 << SCSI_TIMER;
1622                 }
1623         else
1624                 {
1625                 timer_table[SCSI_TIMER].expires = time_start = time_elapsed = 0;
1626                 timer_active &= ~(1 << SCSI_TIMER);
1627                 }       
1628         sti();
1629         return oldto;
1630         }               
1631 
1632 
1633 static unsigned short * dma_malloc_freelist = NULL;
1634 static unsigned int dma_sectors = 0;
1635 unsigned int dma_free_sectors = 0;
1636 unsigned int need_isa_buffer = 0;
1637 static unsigned char * dma_malloc_buffer = NULL;
1638 
1639 void *scsi_malloc(unsigned int len)
     /* [previous][next][first][last][top][bottom][index][help] */
1640 {
1641   unsigned int nbits, mask;
1642   int i, j;
1643   if((len & 0x1ff) || len > 8192)
1644     return NULL;
1645   
1646   cli();
1647   nbits = len >> 9;
1648   mask = (1 << nbits) - 1;
1649   
1650   for(i=0;i < (dma_sectors >> 4); i++)
1651     for(j=0; j<17-nbits; j++){
1652       if ((dma_malloc_freelist[i] & (mask << j)) == 0){
1653         dma_malloc_freelist[i] |= (mask << j);
1654         sti();
1655         dma_free_sectors -= nbits;
1656 #ifdef DEBUG
1657         printk("SMalloc: %d %x ",len, dma_malloc_buffer + (i << 13) + (j << 9));
1658 #endif
1659         return (void *) ((unsigned long) dma_malloc_buffer + (i << 13) + (j << 9));
1660       };
1661     };
1662   sti();
1663   return NULL;  /* Nope.  No more */
1664 }
1665 
1666 int scsi_free(void *obj, unsigned int len)
     /* [previous][next][first][last][top][bottom][index][help] */
1667 {
1668   int offset;
1669   int page, sector, nbits, mask;
1670 
1671 #ifdef DEBUG
1672   printk("Sfree %x %d\n",obj, len);
1673 #endif
1674 
1675   offset = ((int) obj) - ((int) dma_malloc_buffer);
1676 
1677   if (offset < 0) panic("Bad offset");
1678   page = offset >> 13;
1679   sector = offset >> 9;
1680   if(sector >= dma_sectors) panic ("Bad page");
1681 
1682   sector = (offset >> 9) & 15;
1683   nbits = len >> 9;
1684   mask = (1 << nbits) - 1;
1685 
1686   if ((mask << sector) > 0xffff) panic ("Bad memory alignment");
1687 
1688   cli();
1689   if(dma_malloc_freelist[page] & (mask << sector) != (mask<<sector))
1690     panic("Trying to free unused memory");
1691 
1692   dma_free_sectors += nbits;
1693   dma_malloc_freelist[page] &= ~(mask << sector);
1694   sti();
1695   return 0;
1696 }
1697 
1698 /*
1699         scsi_dev_init() is our initialization routine, which inturn calls host 
1700         initialization, bus scanning, and sd/st initialization routines.  It 
1701         should be called from main().
1702 */
1703 
1704 unsigned long scsi_dev_init (unsigned long memory_start,unsigned long memory_end)
     /* [previous][next][first][last][top][bottom][index][help] */
1705         {
1706         int i;
1707         struct Scsi_Host * host;
1708         Scsi_Cmnd * SCpnt;
1709 #ifdef FOO_ON_YOU
1710         return;
1711 #endif  
1712         timer_table[SCSI_TIMER].fn = scsi_main_timeout;
1713         timer_table[SCSI_TIMER].expires = 0;
1714 
1715         /* initialize all hosts */
1716         memory_start = scsi_init(memory_start, memory_end); 
1717                                 
1718         scsi_devices = (Scsi_Device *) memory_start;
1719         scan_scsis();           /* scan for scsi devices */
1720         memory_start += NR_SCSI_DEVICES * sizeof(Scsi_Device);
1721 
1722         memory_start = sd_init1(memory_start, memory_end);
1723         memory_start = st_init1(memory_start, memory_end);
1724         memory_start = sr_init1(memory_start, memory_end);
1725         memory_start = sg_init1(memory_start, memory_end);
1726 
1727         last_cmnd = (Scsi_Cmnd *) memory_start;
1728 
1729         SCpnt = last_cmnd;
1730 
1731         for (i=0; i< NR_SCSI_DEVICES; i++) {
1732           int j;
1733           scsi_devices[i].scsi_request_fn = NULL;
1734           switch (scsi_devices[i].type)
1735             {
1736             case TYPE_TAPE :
1737               st_attach(&scsi_devices[i]);
1738               break;
1739             case TYPE_ROM:
1740               sr_attach(&scsi_devices[i]);
1741               break;
1742             case TYPE_DISK:
1743             case TYPE_MOD:
1744               sd_attach(&scsi_devices[i]);
1745             default:
1746               break;
1747             };
1748           sg_attach(&scsi_devices[i]);
1749           if(scsi_devices[i].type != -1){
1750             for(j=0;j<scsi_devices[i].host->hostt->cmd_per_lun;j++){
1751               SCpnt->host = scsi_devices[i].host;
1752               SCpnt->device = &scsi_devices[i];
1753               SCpnt->target = scsi_devices[i].id;
1754               SCpnt->lun = scsi_devices[i].lun;
1755               SCpnt->index = i;
1756               SCpnt->request.dev = -1; /* Mark not busy */
1757               SCpnt->use_sg = 0;
1758               SCpnt->old_use_sg = 0;
1759               SCpnt->underflow = 0;
1760               SCpnt->transfersize = 0;
1761               SCpnt->host_scribble = NULL;
1762               host = scsi_devices[i].host;
1763               if(host->host_queue)
1764                 host->host_queue->prev = SCpnt;
1765               SCpnt->next = host->host_queue;
1766               SCpnt->prev = NULL;
1767               host->host_queue = SCpnt;
1768               SCpnt++;
1769             };
1770           };
1771         };
1772 
1773         memory_start = (int) SCpnt;
1774 
1775         if (NR_SD > 0 || NR_SR > 0 || NR_ST > 0)
1776           dma_sectors = 16;  /* Base value we use */
1777 
1778         for (i = 0; i < NR_SCSI_DEVICES; ++i) {
1779           struct Scsi_Host * host;
1780           host = scsi_devices[i].host;
1781           
1782           if(scsi_devices[i].type != TYPE_TAPE)
1783             dma_sectors += ((host->sg_tablesize * 
1784                              sizeof(struct scatterlist) + 511) >> 9) * 
1785                                host->hostt->cmd_per_lun;
1786           
1787           if(host->unchecked_isa_dma &&
1788              memory_end > ISA_DMA_THRESHOLD &&
1789              scsi_devices[i].type != TYPE_TAPE) {
1790             dma_sectors += (PAGE_SIZE >> 9) * host->sg_tablesize *
1791               host->hostt->cmd_per_lun;
1792             need_isa_buffer++;
1793           };
1794         };
1795 
1796         dma_sectors = (dma_sectors + 15) & 0xfff0;
1797         dma_free_sectors = dma_sectors;  /* This must be a multiple of 16 */
1798 
1799         memory_start = (memory_start + 3) & 0xfffffffc;
1800         dma_malloc_freelist = (unsigned short *) memory_start;
1801         memory_start += dma_sectors >> 3;
1802         memset(dma_malloc_freelist, 0, dma_sectors >> 3);
1803 
1804         if(memory_start & 1) memory_start++; /* Some host adapters require
1805                                                 buffers to be word aligned */
1806         dma_malloc_buffer = (unsigned char *) memory_start;
1807         memory_start += dma_sectors << 9;
1808 
1809         memory_start = sd_init(memory_start, memory_end); /* init scsi disks */
1810         memory_start = st_init(memory_start, memory_end); /* init scsi tapes */
1811         memory_start = sr_init(memory_start, memory_end); /* init scsi CDROMs */
1812         memory_start = sg_init(memory_start, memory_end); /* init scsi generic */
1813         
1814         return memory_start;
1815         }
1816 
1817 static void print_inquiry(unsigned char *data)
     /* [previous][next][first][last][top][bottom][index][help] */
1818 {
1819         int i;
1820 
1821         printk("  Vendor: ");
1822         for (i = 8; i < 16; i++)
1823                 {
1824                 if (data[i] >= 0x20 && i < data[4] + 5)
1825                         printk("%c", data[i]);
1826                 else
1827                         printk(" ");
1828                 }
1829 
1830         printk("  Model: ");
1831         for (i = 16; i < 32; i++)
1832                 {
1833                 if (data[i] >= 0x20 && i < data[4] + 5)
1834                         printk("%c", data[i]);
1835                 else
1836                         printk(" ");
1837                 }
1838 
1839         printk("  Rev: ");
1840         for (i = 32; i < 36; i++)
1841                 {
1842                 if (data[i] >= 0x20 && i < data[4] + 5)
1843                         printk("%c", data[i]);
1844                 else
1845                         printk(" ");
1846                 }
1847 
1848         printk("\n");
1849 
1850         i = data[0] & 0x1f;
1851 
1852         printk("  Type:   %s ",
1853                i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown          " );
1854         printk("                 ANSI SCSI revision: %02x", data[2] & 0x07);
1855         if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
1856           printk(" CCS\n");
1857         else
1858           printk("\n");
1859 }
1860 
1861 #ifdef DEBUG_TIMEOUT
1862 static void 
1863 scsi_dump_status(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1864 {
1865   int i, i1;
1866   Scsi_Cmnd * SCpnt;
1867   printk("Dump of scsi parameters:\n");
1868   SCpnt = last_cmnd;
1869   for(i=0; i<NR_SCSI_DEVICES; i++)
1870     for(i1=0; i1<scsi_devices[i].host->hostt->cmd_per_lun;i1++)
1871       {
1872         /*  (0) 0:0:0 (802 123434 8 8 0) (3 3 2) (%d %d %d) %d %x      */
1873         printk("(%d) %d:%d:%d (%4.4x %d %d %d %d) (%d %d %x) (%d %d %d) %x %x %d %x\n",
1874                i, SCpnt->host->host_no,
1875                SCpnt->target,
1876                SCpnt->lun,
1877                SCpnt->request.dev,
1878                SCpnt->request.sector,
1879                SCpnt->request.nr_sectors,
1880                SCpnt->request.current_nr_sectors,
1881                SCpnt->use_sg,
1882                SCpnt->retries,
1883                SCpnt->allowed,
1884                SCpnt->flags,
1885                SCpnt->timeout_per_command,
1886                SCpnt->timeout,
1887                SCpnt->internal_timeout,
1888                SCpnt->cmnd[0],
1889                SCpnt->sense_buffer[2],
1890                (SCpnt->request.waiting ? 
1891                 SCpnt->request.waiting->pid : 0),
1892                SCpnt->result);
1893         SCpnt++;
1894       };
1895   printk("wait_for_request = %x\n", wait_for_request);
1896   /* Now dump the request lists for each block device */
1897   printk("Dump of pending block device requests\n");
1898   for(i=0; i<MAX_BLKDEV; i++)
1899     if(blk_dev[i].current_request)
1900       {
1901         struct request * req;
1902         printk("%d: ", i);
1903         req = blk_dev[i].current_request;
1904         while(req) {
1905           printk("(%x %d %d %d %d %d) ",
1906                  req->dev,
1907                  req->cmd,
1908                  req->sector,
1909                  req->nr_sectors,
1910                  req->current_nr_sectors,
1911                  (req->waiting ? 
1912                   req->waiting->pid : 0));
1913           req = req->next;
1914         }
1915         printk("\n");
1916       }
1917 }
1918 #endif

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