root/drivers/scsi/scsi.c

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

DEFINITIONS

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

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

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