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

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