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. scan_scsis
  4. scsi_times_out
  5. request_queueable
  6. allocate_device
  7. internal_cmnd
  8. scsi_request_sense
  9. scsi_do_cmd
  10. reset
  11. check_sense
  12. scsi_done
  13. scsi_abort
  14. scsi_reset
  15. scsi_main_timeout
  16. update_timeout
  17. scsi_malloc
  18. scsi_free
  19. scsi_dev_init
  20. print_inquiry
  21. scsi_dump_status

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

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