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

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