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

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