root/drivers/scsi/scsi.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_device_flags
  2. scsi_make_blocked_list
  3. scan_scsis_done
  4. scsi_luns_setup
  5. scan_scsis
  6. scsi_times_out
  7. request_queueable
  8. allocate_device
  9. internal_cmnd
  10. scsi_request_sense
  11. scsi_do_cmd
  12. reset
  13. check_sense
  14. scsi_done
  15. scsi_abort
  16. scsi_reset
  17. scsi_main_timeout
  18. update_timeout
  19. scsi_malloc
  20. scsi_free
  21. scsi_init_malloc
  22. scsi_init_free
  23. scsi_build_commandblocks
  24. scsi_dev_init
  25. print_inquiry
  26. scsi_proc_info
  27. scsi_register_host
  28. scsi_unregister_host
  29. scsi_register_device_module
  30. scsi_unregister_device
  31. scsi_register_module
  32. scsi_unregister_module
  33. scsi_dump_status
  34. init_module
  35. cleanup_module

   1 /*
   2  *  scsi.c Copyright (C) 1992 Drew Eckhardt
   3  *         Copyright (C) 1993, 1994, 1995 Eric Youngdale
   4  *
   5  *  generic mid-level SCSI driver
   6  *      Initial versions: Drew Eckhardt
   7  *      Subsequent revisions: Eric Youngdale
   8  *
   9  *  <drew@colorado.edu>
  10  *
  11  *  Bug correction thanks go to :
  12  *      Rik Faith <faith@cs.unc.edu>
  13  *      Tommy Thorn <tthorn>
  14  *      Thomas Wuensche <tw@fgb1.fgb.mw.tu-muenchen.de>
  15  *
  16  *  Modified by Eric Youngdale ericy@cais.com to
  17  *  add scatter-gather, multiple outstanding request, and other
  18  *  enhancements.
  19  *
  20  *  Native multichannel and wide scsi support added 
  21  *  by Michael Neuffer neuffer@goofy.zdv.uni-mainz.de
  22  */
  23 #ifdef MODULE
  24 /*
  25  * Don't import our own symbols, as this would severely mess up our
  26  * symbol tables.
  27  */
  28 #define _SCSI_SYMS_VER_
  29 #include <linux/autoconf.h>
  30 #include <linux/module.h>
  31 #include <linux/version.h>
  32 #else
  33 #define MOD_INC_USE_COUNT
  34 #define MOD_DEC_USE_COUNT
  35 #endif
  36 
  37 #include <asm/system.h>
  38 #include <linux/sched.h>
  39 #include <linux/timer.h>
  40 #include <linux/string.h>
  41 #include <linux/malloc.h>
  42 #include <asm/irq.h>
  43 #include <asm/dma.h>
  44 #include <linux/ioport.h>
  45 #include <linux/kernel.h>
  46 
  47 #include "../block/blk.h"
  48 #include "scsi.h"
  49 #include "hosts.h"
  50 #include "constants.h"
  51 
  52 #undef USE_STATIC_SCSI_MEMORY
  53 
  54 /*
  55 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 $";
  56 */
  57 
  58 /* Command groups 3 and 4 are reserved and should never be used.  */
  59 const unsigned char scsi_command_size[8] = { 6, 10, 10, 12, 12, 12, 10, 10 };
  60 
  61 #define INTERNAL_ERROR (panic ("Internal error in file %s, line %d.\n", __FILE__, __LINE__))
  62 
  63 static void scsi_done (Scsi_Cmnd *SCpnt);
  64 static int update_timeout (Scsi_Cmnd *, int);
  65 static void print_inquiry(unsigned char *data);
  66 static void scsi_times_out (Scsi_Cmnd * SCpnt, int pid);
  67 
  68 static int time_start;
  69 static int time_elapsed;
  70 static volatile struct Scsi_Host * host_active = NULL;
  71 #define SCSI_BLOCK(HOST) ((HOST->block && host_active && HOST != host_active) \
  72                           || (HOST->can_queue && HOST->host_busy >= HOST->can_queue))
  73 
  74 #define MAX_SCSI_DEVICE_CODE 10
  75 const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] =
  76 {
  77     "Direct-Access    ",
  78     "Sequential-Access",
  79     "Printer          ",
  80     "Processor        ",
  81     "WORM             ",
  82     "CD-ROM           ",
  83     "Scanner          ",
  84     "Optical Device   ",
  85     "Medium Changer   ",
  86     "Communications   "
  87 };
  88 
  89 
  90 /*
  91  * global variables :
  92  * scsi_devices an array of these specifying the address for each
  93  * (host, id, LUN)
  94  */
  95 
  96 Scsi_Device * scsi_devices = NULL;
  97 
  98 /* Process ID of SCSI commands */
  99 unsigned long scsi_pid = 0;
 100 
 101 static unsigned char generic_sense[6] = {REQUEST_SENSE, 0,0,0, 255, 0};
 102 
 103 /* This variable is merely a hook so that we can debug the kernel with gdb. */
 104 Scsi_Cmnd * last_cmnd = NULL;
 105 
 106 /* This is the pointer to the /proc/scsi code. 
 107  * It is only initialized to !=0 if the scsi code is present 
 108  */ 
 109 extern int (* dispatch_scsi_info_ptr)(int ino, char *buffer, char **start, off_t offset, int length, int inout); 
 110 extern int dispatch_scsi_info(int ino, char *buffer, char **start, off_t offset, int length, int inout); 
 111 
 112 /*
 113  *  As the scsi do command functions are intelligent, and may need to
 114  *  redo a command, we need to keep track of the last command
 115  *  executed on each one.
 116  */
 117 
 118 #define WAS_RESET       0x01
 119 #define WAS_TIMEDOUT    0x02
 120 #define WAS_SENSE       0x04
 121 #define IS_RESETTING    0x08
 122 #define IS_ABORTING     0x10
 123 #define ASKED_FOR_SENSE 0x20
 124 
 125 /*
 126  *  This is the number  of clock ticks we should wait before we time out
 127  *  and abort the command.  This is for  where the scsi.c module generates
 128  *  the command, not where it originates from a higher level, in which
 129  *  case the timeout is specified there.
 130  *
 131  *  ABORT_TIMEOUT and RESET_TIMEOUT are the timeouts for RESET and ABORT
 132  *  respectively.
 133  */
 134 
 135 #ifdef DEBUG_TIMEOUT
 136 static void scsi_dump_status(void);
 137 #endif
 138 
 139 
 140 #ifdef DEBUG
 141     #define SCSI_TIMEOUT (5*HZ)
 142 #else
 143     #define SCSI_TIMEOUT (1*HZ)
 144 #endif
 145 
 146 #ifdef DEBUG
 147     #define SENSE_TIMEOUT SCSI_TIMEOUT
 148     #define ABORT_TIMEOUT SCSI_TIMEOUT
 149     #define RESET_TIMEOUT SCSI_TIMEOUT
 150 #else
 151     #define SENSE_TIMEOUT (5*HZ/10)
 152     #define RESET_TIMEOUT (5*HZ/10)
 153     #define ABORT_TIMEOUT (5*HZ/10)
 154 #endif
 155 
 156 #define MIN_RESET_DELAY (1*HZ)
 157 
 158 /* Do not call reset on error if we just did a reset within 10 sec. */
 159 #define MIN_RESET_PERIOD (10*HZ)
 160 
 161 /* The following devices are known not to tolerate a lun != 0 scan for
 162  * one reason or another.  Some will respond to all luns, others will
 163  * lock up. 
 164  */
 165 
 166 #define BLIST_NOLUN     0x01
 167 #define BLIST_FORCELUN  0x02
 168 #define BLIST_BORKEN    0x04
 169 #define BLIST_KEY       0x08
 170 #define BLIST_SINGLELUN 0x10
 171 
 172 struct dev_info{
 173     char * vendor;
 174     char * model;
 175     char * revision; /* Latest revision known to be bad.  Not used yet */
 176     unsigned flags;
 177 };
 178 
 179 /*
 180  * This is what was previously known as the blacklist.  The concept
 181  * has been expanded so that we can specify other 
 182  * The blacklist is used to determine which devices cannot tolerate a
 183  * lun probe because of buggy firmware.  Far too many for my liking,
 184  * which is why the default is now for there to be no lun scan. 
 185  */
 186 static struct dev_info device_list[] =
 187 {
 188 {"CHINON","CD-ROM CDS-431","H42", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
 189 {"CHINON","CD-ROM CDS-535","Q14", BLIST_NOLUN}, /* Locks up if polled for lun != 0 */
 190 {"DENON","DRD-25X","V", BLIST_NOLUN},           /* Locks up if probed for lun != 0 */
 191 {"HITACHI","DK312C","CM81", BLIST_NOLUN},       /* Responds to all lun - dtg */
 192 {"HITACHI","DK314C","CR21" , BLIST_NOLUN},      /* responds to all lun */
 193 {"IMS", "CDD521/10","2.06", BLIST_NOLUN},       /* Locks-up when LUN>0 polled. */
 194 {"MAXTOR","XT-3280","PR02", BLIST_NOLUN},       /* Locks-up when LUN>0 polled. */
 195 {"MAXTOR","XT-4380S","B3C", BLIST_NOLUN},       /* Locks-up when LUN>0 polled. */
 196 {"MAXTOR","MXT-1240S","I1.2", BLIST_NOLUN},     /* Locks up when LUN>0 polled */
 197 {"MAXTOR","XT-4170S","B5A", BLIST_NOLUN},       /* Locks-up sometimes when LUN>0 polled. */
 198 {"MAXTOR","XT-8760S","B7B", BLIST_NOLUN},       /* guess what? */
 199 {"NEC","CD-ROM DRIVE:841","1.0", BLIST_NOLUN},  /* Locks-up when LUN>0 polled. */
 200 {"RODIME","RO3000S","2.33", BLIST_NOLUN},       /* Locks up if polled for lun != 0 */
 201 {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN},   /* causes failed REQUEST SENSE on lun 1 
 202                                                  * for aha152x controller, which causes 
 203                                                  * SCSI code to reset bus.*/
 204 {"SEAGATE", "ST296","921", BLIST_NOLUN},        /* Responds to all lun */
 205 {"SONY","CD-ROM CDU-541","4.3d", BLIST_NOLUN},
 206 {"SONY","CD-ROM CDU-55S","1.0i", BLIST_NOLUN},
 207 {"SONY","CD-ROM CDU-561","1.7x", BLIST_NOLUN},
 208 {"TANDBERG","TDC 3600","U07", BLIST_NOLUN},     /* Locks up if polled for lun != 0 */
 209 {"TEAC","CD-ROM","1.06", BLIST_NOLUN},          /* causes failed REQUEST SENSE on lun 1 
 210                                                  * for seagate controller, which causes 
 211                                                  * SCSI code to reset bus.*/
 212 {"TEXEL","CD-ROM","1.06", BLIST_NOLUN},         /* causes failed REQUEST SENSE on lun 1 
 213                                                  * for seagate controller, which causes 
 214                                                  * SCSI code to reset bus.*/
 215 {"QUANTUM","LPS525S","3110", BLIST_NOLUN},      /* Locks sometimes if polled for lun != 0 */
 216 {"QUANTUM","PD1225S","3110", BLIST_NOLUN},      /* Locks sometimes if polled for lun != 0 */
 217 {"MEDIAVIS","CDR-H93MV","1.31", BLIST_NOLUN},   /* Locks up if polled for lun != 0 */
 218 {"SANKYO", "CP525","6.64", BLIST_NOLUN},        /* causes failed REQ SENSE, extra reset */
 219 {"HP", "C1750A", "3226", BLIST_NOLUN},          /* scanjet iic */
 220 {"HP", "C1790A", "", BLIST_NOLUN},              /* scanjet iip */
 221 {"HP", "C2500A", "", BLIST_NOLUN},              /* scanjet iicx */
 222 
 223 /*
 224  * Other types of devices that have special flags.
 225  */
 226 {"SONY","CD-ROM CDU-8001","*", BLIST_BORKEN},
 227 {"TEXEL","CD-ROM","1.06", BLIST_BORKEN},
 228 {"INSITE","Floptical   F*8I","*", BLIST_KEY},
 229 {"INSITE","I325VM","*", BLIST_KEY},
 230 {"PIONEER","CD-ROMDRM-602X","*", BLIST_FORCELUN | BLIST_SINGLELUN},
 231 {"PIONEER","CD-ROMDRM-604X","*", BLIST_FORCELUN | BLIST_SINGLELUN},
 232 /*
 233  * Must be at end of list...
 234  */
 235 {NULL, NULL, NULL}
 236 };
 237 
 238 static int get_device_flags(unsigned char * response_data){
     /* [previous][next][first][last][top][bottom][index][help] */
 239     int i = 0;
 240     unsigned char * pnt;
 241     for(i=0; 1; i++){
 242         if(device_list[i].vendor == NULL) return 0;
 243         pnt = &response_data[8];
 244         while(*pnt && *pnt == ' ') pnt++;
 245         if(memcmp(device_list[i].vendor, pnt,
 246                   strlen(device_list[i].vendor))) continue;
 247         pnt = &response_data[16];
 248         while(*pnt && *pnt == ' ') pnt++;
 249         if(memcmp(device_list[i].model, pnt,
 250                   strlen(device_list[i].model))) continue;
 251         return device_list[i].flags;
 252     }
 253     return 0;
 254 }
 255 
 256 /*
 257  *  As the actual SCSI command runs in the background, we must set up a
 258  *  flag that tells scan_scsis() when the result it has is valid.
 259  *  scan_scsis can set the_result to -1, and watch for it to become the
 260  *  actual return code for that call.  the scan_scsis_done function() is
 261  *  our user specified completion function that is passed on to the
 262  *  scsi_do_cmd() function.
 263  */
 264 
 265 volatile int in_scan_scsis = 0;
 266 static int the_result;
 267 
 268 void scsi_make_blocked_list(void)  {
     /* [previous][next][first][last][top][bottom][index][help] */
 269     int block_count = 0, index;
 270     unsigned int flags;
 271     struct Scsi_Host * sh[128], * shpnt;
 272     
 273     /*
 274      * Create a circular linked list from the scsi hosts which have
 275      * the "wish_block" field in the Scsi_Host structure set.
 276      * The blocked list should include all the scsi hosts using ISA DMA.
 277      * In some systems, using two dma channels simultaneously causes
 278      * unpredictable results.
 279      * Among the scsi hosts in the blocked list, only one host at a time
 280      * is allowed to have active commands queued. The transition from
 281      * one active host to the next one is allowed only when host_busy == 0
 282      * for the active host (which implies host_busy == 0 for all the hosts
 283      * in the list). Moreover for block devices the transition to a new
 284      * active host is allowed only when a request is completed, since a
 285      * block device request can be divided into multiple scsi commands
 286      * (when there are few sg lists or clustering is disabled).
 287      *
 288      * (DB, 4 Feb 1995)
 289      */
 290     
 291     save_flags(flags);
 292     cli();
 293     host_active = NULL;
 294     
 295     for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next) {
 296         
 297 #if 0
 298         /*
 299          * Is this is a candidate for the blocked list?
 300          * Useful to put into the blocked list all the hosts whose driver
 301          * does not know about the host->block feature.
 302          */
 303         if (shpnt->unchecked_isa_dma) shpnt->wish_block = 1;
 304 #endif
 305         
 306         if (shpnt->wish_block) sh[block_count++] = shpnt;
 307     }
 308     
 309     if (block_count == 1) sh[0]->block = NULL;
 310     
 311     else if (block_count > 1) {
 312         
 313         for(index = 0; index < block_count - 1; index++) {
 314             sh[index]->block = sh[index + 1];
 315             printk("scsi%d : added to blocked host list.\n",
 316                    sh[index]->host_no);
 317         }
 318         
 319         sh[block_count - 1]->block = sh[0];
 320         printk("scsi%d : added to blocked host list.\n",
 321                sh[index]->host_no);
 322     }
 323     
 324     restore_flags(flags);
 325 }
 326 
 327 static void scan_scsis_done (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 328 {
 329     
 330 #ifdef DEBUG
 331     printk ("scan_scsis_done(%p, %06x)\n", SCpnt->host, SCpnt->result);
 332 #endif
 333     SCpnt->request.dev = 0xfffe;
 334     
 335     if (SCpnt->request.sem != NULL)
 336         up(SCpnt->request.sem);
 337 }
 338 
 339 #ifdef CONFIG_SCSI_MULTI_LUN
 340 static int max_scsi_luns = 8;
 341 #else
 342 static int max_scsi_luns = 1;
 343 #endif
 344 
 345 void scsi_luns_setup(char *str, int *ints) {
     /* [previous][next][first][last][top][bottom][index][help] */
 346     if (ints[0] != 1)
 347         printk("scsi_luns_setup : usage max_scsi_luns=n (n should be between 1 and 8)\n");
 348     else
 349         max_scsi_luns = ints[1];
 350 }
 351 
 352 /*
 353  *  Detecting SCSI devices :
 354  *  We scan all present host adapter's busses,  from ID 0 to ID (max_id).
 355  *  We use the INQUIRY command, determine device type, and pass the ID /
 356  *  lun address of all sequential devices to the tape driver, all random
 357  *  devices to the disk driver.
 358  */
 359 
 360 void scan_scsis (struct Scsi_Host * shpnt, unchar hardcoded, 
     /* [previous][next][first][last][top][bottom][index][help] */
 361                  unchar hchannel, unchar hid, unchar hlun)
 362 {
 363     int dev, lun, type, channel;
 364     unsigned char scsi_cmd [12];
 365     unsigned char scsi_result0 [256];
 366     unsigned char * scsi_result;
 367     Scsi_Device * SDpnt, *SDtail;
 368     struct Scsi_Device_Template * sdtpnt;
 369     int                 bflags;
 370     int                 max_dev_lun = 0;
 371     Scsi_Cmnd  *SCpnt;
 372     
 373     ++in_scan_scsis;
 374     lun = 0;
 375     type = -1;
 376     SCpnt = (Scsi_Cmnd *) scsi_init_malloc(sizeof(Scsi_Cmnd), GFP_ATOMIC|GFP_DMA);
 377     SDpnt = (Scsi_Device *) scsi_init_malloc(sizeof (Scsi_Device), GFP_ATOMIC);
 378     SDtail = scsi_devices;
 379     
 380     if(scsi_devices) while(SDtail->next) SDtail = SDtail->next;
 381     
 382     /* Make sure we have something that is valid for DMA purposes */
 383     scsi_result = ((current->pid == 0  || !shpnt->unchecked_isa_dma)
 384                    ?  &scsi_result0[0] : scsi_malloc(512));
 385     
 386     if(scsi_result == NULL) {
 387         printk("Unable to obtain scsi_result buffer\n");
 388         goto leave;
 389     }
 390     
 391     shpnt->host_queue = SCpnt; /* We need this so that commands can time out */
 392 
 393     if(hardcoded == 1) {
 394         channel = hchannel;
 395         dev = hid;
 396         lun = hlun;
 397         goto crude; /* Anyone remember good ol' BASIC ?  :-) */
 398     }
 399 
 400     for (channel = 0; channel <= shpnt->max_channel; channel++)
 401     {
 402         for (dev = 0; dev < shpnt->max_id; ++dev) {
 403             if (shpnt->this_id != dev) {
 404                 
 405                 /*
 406                  * We need the for so our continue, etc. work fine.
 407                  * We put this in a variable so that we can override
 408                  * it during the scan if we detect a device *KNOWN*
 409                  * to have multiple logical units.
 410                  */
 411                 max_dev_lun = (max_scsi_luns < shpnt->max_lun ? 
 412                                max_scsi_luns : shpnt->max_lun);
 413 
 414                 for (lun = 0; lun < max_dev_lun; ++lun)
 415                 {
 416                 crude:
 417                     memset(SDpnt, 0, sizeof(Scsi_Device));
 418                     SDpnt->host = shpnt;
 419                     SDpnt->id = dev;
 420                     SDpnt->lun = lun;
 421                     SDpnt->channel = channel;
 422 
 423                     /* Some low level driver could use device->type (DB) */
 424                     SDpnt->type = -1;
 425                     /*
 426                      * Assume that the device will have handshaking problems, 
 427                      * and then fix this field later if it turns out it doesn't
 428                      */
 429                     SDpnt->borken = 1;
 430                     
 431                     scsi_cmd[0] = TEST_UNIT_READY;
 432                     scsi_cmd[1] = lun << 5;
 433                     scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[4] = scsi_cmd[5] = 0;
 434                     
 435                     memset(SCpnt, 0,  sizeof(Scsi_Cmnd));
 436                     SCpnt->host = SDpnt->host;
 437                     SCpnt->device = SDpnt;
 438                     SCpnt->target = SDpnt->id;
 439                     SCpnt->lun = SDpnt->lun;
 440                     SCpnt->channel = SDpnt->channel;
 441 
 442                     /* Used for mutex if loading devices after boot */
 443                     SCpnt->request.sem = NULL;
 444                     
 445                     SCpnt->request.dev = 0xffff; /* Mark not busy */
 446                     
 447                     scsi_do_cmd (SCpnt, (void *)  scsi_cmd, 
 448                                  (void *) scsi_result,
 449                                  256,  scan_scsis_done, SCSI_TIMEOUT + 4 * HZ, 5);
 450                     
 451                     /* 
 452                      * Wait for command to finish. Use simple wait if we are 
 453                      * booting, else do it right and use a mutex 
 454                      */
 455                     
 456                     if (current->pid == 0)
 457                         while (SCpnt->request.dev != 0xfffe) 
 458                             barrier();
 459                     else if (SCpnt->request.dev != 0xfffe) {
 460                         struct semaphore sem = MUTEX_LOCKED;
 461                         
 462                         SCpnt->request.sem = &sem;
 463                         down(&sem);
 464                         
 465                         /* Hmm.. Have to ask about this one */
 466                         while (SCpnt->request.dev != 0xfffe) schedule();
 467                     }
 468                     
 469 #if defined(DEBUG) || defined(DEBUG_INIT)
 470                     printk("scsi: scan SCSIS id %d lun %d\n", dev, lun);
 471                     printk("scsi: return code %08x\n", SCpnt->result);
 472 #endif
 473 
 474                     if(SCpnt->result) {
 475                         if (((driver_byte(SCpnt->result) & DRIVER_SENSE) ||
 476                              (status_byte(SCpnt->result) & CHECK_CONDITION)) &&
 477                             ((SCpnt->sense_buffer[0] & 0x70) >> 4) == 7) {
 478                             if (SCpnt->sense_buffer[2] &0xe0)
 479                                 continue; /* No devices here... */
 480                             if(((SCpnt->sense_buffer[2] & 0xf) != NOT_READY) &&
 481                                ((SCpnt->sense_buffer[2] & 0xf) != UNIT_ATTENTION))
 482                                 continue;
 483                         }
 484                         else
 485                             break;
 486                     }
 487                     
 488 #if defined (DEBUG) || defined(DEBUG_INIT)
 489                     printk("scsi: performing INQUIRY\n");
 490 #endif
 491 
 492                     /*
 493                      * Build an INQUIRY command block.
 494                      */
 495                     scsi_cmd[0] = INQUIRY;
 496                     scsi_cmd[1] = (lun << 5) & 0xe0;
 497                     scsi_cmd[2] = 0;
 498                     scsi_cmd[3] = 0;
 499                     scsi_cmd[4] = 255;
 500                     scsi_cmd[5] = 0;
 501                     
 502                     SCpnt->request.dev = 0xffff; /* Mark not busy */
 503                     SCpnt->cmd_len = 0;
 504 
 505                     scsi_do_cmd (SCpnt, (void *)  scsi_cmd, 
 506                                  (void *) scsi_result,
 507                                  256,  scan_scsis_done, SCSI_TIMEOUT, 3);
 508                     
 509                     if (current->pid == 0)
 510                         while (SCpnt->request.dev != 0xfffe) 
 511                             barrier();
 512                     else if (SCpnt->request.dev != 0xfffe) {
 513                         struct semaphore sem = MUTEX_LOCKED;
 514                         
 515                         SCpnt->request.sem = &sem;
 516                         down(&sem);
 517                         
 518                         /* Hmm.. Have to ask about this one */
 519                         while (SCpnt->request.dev != 0xfffe) schedule();
 520                     }
 521                     
 522                     the_result = SCpnt->result;
 523                     
 524 #if defined(DEBUG) || defined(DEBUG_INIT)
 525                     if (!the_result)
 526                         printk("scsi: INQUIRY successful\n");
 527                     else
 528                         printk("scsi: INQUIRY failed with code %08x\n", the_result);
 529 #endif
 530                     
 531                     if(the_result) break;
 532                     
 533                     /* skip other luns on this device */
 534                     
 535                     if (!the_result)
 536                     {
 537                         /* It would seem some TOSHIBA CDROM 
 538                          * gets things wrong 
 539                          */
 540                         if (!strncmp(scsi_result+8,"TOSHIBA",7) &&
 541                             !strncmp(scsi_result+16,"CD-ROM",6) &&
 542                             scsi_result[0] == TYPE_DISK) {
 543                             scsi_result[0] = TYPE_ROM;
 544                             scsi_result[1] |= 0x80;  /* removable */
 545                         }
 546                         
 547                         if (!strncmp(scsi_result+8,"NEC",3)) {
 548                             if (!strncmp(scsi_result+16,"CD-ROM DRIVE:84 ",16) || 
 549                                 !strncmp(scsi_result+16,"CD-ROM DRIVE:25",15))
 550                                 SDpnt->manufacturer = SCSI_MAN_NEC_OLDCDR;
 551                             else
 552                                 SDpnt->manufacturer = SCSI_MAN_NEC;
 553                         } else if (!strncmp(scsi_result+8,"TOSHIBA",7))
 554                             SDpnt->manufacturer = SCSI_MAN_TOSHIBA;
 555                         else if (!strncmp(scsi_result+8,"SONY",4))
 556                             SDpnt->manufacturer = SCSI_MAN_SONY;
 557                         else
 558                             SDpnt->manufacturer = SCSI_MAN_UNKNOWN;
 559                         
 560                         memcpy(SDpnt->vendor, scsi_result+8, 8);
 561                         memcpy(SDpnt->model, scsi_result+16, 16);
 562                         memcpy(SDpnt->rev, scsi_result+32, 4);
 563  
 564                         SDpnt->removable = (0x80 & scsi_result[1]) >> 7;
 565                         SDpnt->lockable = SDpnt->removable;
 566                         SDpnt->changed = 0;
 567                         SDpnt->access_count = 0;
 568                         SDpnt->busy = 0;
 569                         SDpnt->has_cmdblocks = 0;
 570                         /*
 571                          * Currently, all sequential devices are assumed to be
 572                          * tapes, all random devices disk, with the appropriate
 573                          * read only flags set for ROM / WORM treated as RO.
 574                          */
 575                         
 576                         switch (type = (scsi_result[0] & 0x1f))
 577                         {
 578                         case TYPE_TAPE :
 579                         case TYPE_DISK :
 580                         case TYPE_MOD :
 581                         case TYPE_PROCESSOR :
 582                         case TYPE_SCANNER :
 583                             SDpnt->writeable = 1;
 584                             break;
 585                         case TYPE_WORM :
 586                         case TYPE_ROM :
 587                             SDpnt->writeable = 0;
 588                             break;
 589                         default :
 590 #if 0
 591 #ifdef DEBUG
 592                             printk("scsi: unknown type %d\n", type);
 593                             print_inquiry(scsi_result);
 594 #endif
 595                             type = -1;
 596 #endif
 597                         }
 598                         
 599                         SDpnt->single_lun = 0;
 600                         SDpnt->soft_reset =
 601                             (scsi_result[7] & 1) && ((scsi_result[3] &7) == 2);
 602                         SDpnt->random = (type == TYPE_TAPE) ? 0 : 1;
 603                         SDpnt->type = (type & 0x1f);
 604                         
 605                         if (type != -1)
 606                         {
 607                             print_inquiry(scsi_result);
 608                             
 609                             for(sdtpnt = scsi_devicelist; sdtpnt; 
 610                                 sdtpnt = sdtpnt->next)
 611                                 if(sdtpnt->detect) SDpnt->attached +=
 612                                     (*sdtpnt->detect)(SDpnt);
 613                             
 614                             SDpnt->scsi_level = scsi_result[2] & 0x07;
 615                             if (SDpnt->scsi_level >= 2 ||
 616                                 (SDpnt->scsi_level == 1 &&
 617                                  (scsi_result[3] & 0x0f) == 1))
 618                                 SDpnt->scsi_level++;
 619                             /*
 620                              * Set the tagged_queue flag for SCSI-II devices 
 621                              * that purport to support
 622                              * tagged queuing in the INQUIRY data.
 623                              */
 624                             
 625                             SDpnt->tagged_queue = 0;
 626                             
 627                             if ((SDpnt->scsi_level >= SCSI_2) &&
 628                                 (scsi_result[7] & 2)) {
 629                                 SDpnt->tagged_supported = 1;
 630                                 SDpnt->current_tag = 0;
 631                             }
 632                             
 633                             /*
 634                              * Accommodate drivers that want to sleep when 
 635                              * they should be in a polling loop.
 636                              */
 637 
 638                             SDpnt->disconnect = 0;
 639 
 640                             /*
 641                              * Get any flags for this device.
 642                              */
 643                             bflags = get_device_flags(scsi_result);
 644 
 645                             
 646                             /*
 647                              * Some revisions of the Texel CD ROM drives have 
 648                              * handshaking problems when used with the Seagate
 649                              * controllers.  Before we know what type of device
 650                              * we're talking to, we assume it's borken and then
 651                              * change it here if it turns out that it isn't
 652                              * a TEXEL drive.
 653                              */
 654                             if( (bflags & BLIST_BORKEN) == 0 )
 655                             {
 656                                 SDpnt->borken = 0;
 657                             }
 658                             
 659                             
 660                             /* These devices need this "key" to unlock the
 661                              * devices so we can use it 
 662                              */
 663                             if( (bflags & BLIST_KEY) != 0 ) {
 664                                 printk("Unlocked floptical drive.\n");
 665                                 SDpnt->lockable = 0;
 666                                 scsi_cmd[0] = MODE_SENSE;
 667                                 scsi_cmd[1] = (lun << 5) & 0xe0;
 668                                 scsi_cmd[2] = 0x2e;
 669                                 scsi_cmd[3] = 0;
 670                                 scsi_cmd[4] = 0x2a;
 671                                 scsi_cmd[5] = 0;
 672                                 
 673                                 SCpnt->request.dev = 0xffff; /* Mark not busy */
 674                                 SCpnt->cmd_len = 0;
 675                                 
 676                                 scsi_do_cmd (SCpnt, (void *)  scsi_cmd,
 677                                              (void *) scsi_result, 0x2a,  
 678                                              scan_scsis_done, SCSI_TIMEOUT, 3);
 679                                 
 680                                 if (current->pid == 0)
 681                                     while (SCpnt->request.dev != 0xfffe);
 682                                 else if (SCpnt->request.dev != 0xfffe) {
 683                                     struct semaphore sem = MUTEX_LOCKED;
 684                                     
 685                                     SCpnt->request.sem = &sem;
 686                                     down(&sem);
 687                                     
 688                                     /* Hmm.. Have to ask about this one */
 689                                     while (SCpnt->request.dev != 0xfffe) 
 690                                         schedule();
 691                                 }
 692                             }
 693                             /* Add this device to the linked list at the end */
 694                             if(SDtail)
 695                                 SDtail->next = SDpnt;
 696                             else
 697                                 scsi_devices = SDpnt;
 698                             SDtail = SDpnt;
 699                             
 700                             SDpnt = (Scsi_Device *) scsi_init_malloc(sizeof (Scsi_Device), GFP_ATOMIC);
 701                             /* Some scsi devices cannot be polled for lun != 0
 702                              * due to firmware bugs 
 703                              */
 704                             if(bflags & BLIST_NOLUN) break;
 705 
 706                             /*
 707                              * If we want to only allow I/O to one of the luns
 708                              * attached to this device at a time, then we set this
 709                              * flag.
 710                              */
 711                             if(bflags & BLIST_SINGLELUN)
 712                             {
 713                                 SDpnt->single_lun = 1;
 714                             }
 715 
 716                             /*
 717                              * If this device is known to support multiple units, override
 718                              * the other settings, and scan all of them.
 719                              */
 720                             if(bflags & BLIST_FORCELUN)
 721                             {
 722                                 /*
 723                                  * We probably want to make this a variable, but this
 724                                  * will do for now.
 725                                  */
 726                                 max_dev_lun = 8;
 727                             }
 728  
 729 
 730                             /* Old drives like the MAXTOR XT-3280 say vers=0 */
 731                             if ((scsi_result[2] & 0x07) == 0)
 732                                 break;
 733                             /* Some scsi-1 peripherals do not handle lun != 0.
 734                              * I am assuming that scsi-2 peripherals do better 
 735                              */
 736                             if((scsi_result[2] & 0x07) == 1 &&
 737                                (scsi_result[3] & 0x0f) == 0) break;
 738                         }
 739                     }       /* if result == DID_OK ends */
 740 
 741                     /*
 742                      * This might screw us up with multi-lun devices, but the user can
 743                      * scan for them too.
 744                      */
 745                     if(hardcoded == 1)
 746                         goto leave;
 747                 } /* for lun ends */
 748             } /* if this_id != id ends */
 749         } /* for dev ends */
 750     } /* for channel ends */
 751     
 752  leave:
 753     shpnt->host_queue = NULL;  /* No longer needed here */
 754     
 755     
 756     /* Last device block does not exist.  Free memory. */
 757     if(SDpnt != NULL)
 758         scsi_init_free((char *) SDpnt, sizeof(Scsi_Device));
 759     
 760     if(SCpnt != NULL)
 761         scsi_init_free((char *) SCpnt, sizeof(Scsi_Cmnd));
 762     
 763     /* If we allocated a buffer so we could do DMA, free it now */
 764     if (scsi_result != &scsi_result0[0] && scsi_result != NULL) 
 765         scsi_free(scsi_result, 512);
 766     
 767     in_scan_scsis = 0;
 768 }       /* scan_scsis  ends */
 769 
 770 /*
 771  *  Flag bits for the internal_timeout array
 772  */
 773 
 774 #define NORMAL_TIMEOUT 0
 775 #define IN_ABORT 1
 776 #define IN_RESET 2
 777 
 778 /*
 779  * This is our time out function, called when the timer expires for a
 780  * given host adapter.  It will attempt to abort the currently executing
 781  * command, that failing perform a kernel panic.
 782  */
 783 
 784 static void scsi_times_out (Scsi_Cmnd * SCpnt, int pid)
     /* [previous][next][first][last][top][bottom][index][help] */
 785 {
 786     
 787     switch (SCpnt->internal_timeout & (IN_ABORT | IN_RESET))
 788     {
 789     case NORMAL_TIMEOUT:
 790         if (!in_scan_scsis) {
 791 #ifdef DEBUG_TIMEOUT
 792             scsi_dump_status();
 793 #endif
 794         }
 795         
 796         if (!scsi_abort (SCpnt, DID_TIME_OUT, pid))
 797             return;
 798     case IN_ABORT:
 799         printk("SCSI host %d abort() timed out - resetting\n",
 800                SCpnt->host->host_no);
 801         if (!scsi_reset (SCpnt))
 802             return;
 803     case IN_RESET:
 804     case (IN_ABORT | IN_RESET):
 805         /* This might be controversial, but if there is a bus hang,
 806          * you might conceivably want the machine up and running
 807          * esp if you have an ide disk. 
 808          */
 809         printk("Unable to reset scsi host %d - ", SCpnt->host->host_no);
 810         printk("probably a SCSI bus hang.\n");
 811         return;
 812         
 813     default:
 814         INTERNAL_ERROR;
 815     }
 816     
 817 }
 818 
 819 
 820 /* This function takes a quick look at a request, and decides if it
 821  * can be queued now, or if there would be a stall while waiting for
 822  * something else to finish.  This routine assumes that interrupts are
 823  * turned off when entering the routine.  It is the responsibility
 824  * of the calling code to ensure that this is the case. 
 825  */
 826 
 827 Scsi_Cmnd * request_queueable (struct request * req, Scsi_Device * device)
     /* [previous][next][first][last][top][bottom][index][help] */
 828 {
 829     Scsi_Cmnd * SCpnt = NULL;
 830     int tablesize;
 831     Scsi_Cmnd * found = NULL;
 832     struct buffer_head * bh, *bhp;
 833     
 834     if (!device)
 835         panic ("No device passed to request_queueable().\n");
 836     
 837     if (req && req->dev <= 0)
 838         panic("Invalid device in request_queueable");
 839     
 840     SCpnt =  device->host->host_queue;
 841 
 842     /*
 843      * Look for a free command block.  If we have been instructed not to queue
 844      * multiple commands to multi-lun devices, then check to see what else is going on
 845      * for this device first.
 846      */
 847       
 848     SCpnt = device->host->host_queue;
 849     if (!device->single_lun) {
 850         while(SCpnt){
 851             if(SCpnt->target == device->id &&
 852                SCpnt->lun == device->lun) {
 853                 if(SCpnt->request.dev < 0) break;
 854             }
 855             SCpnt = SCpnt->next;
 856         }
 857     } else {
 858         while(SCpnt){
 859             if(SCpnt->target == device->id) {
 860                 if (SCpnt->lun == device->lun) {
 861                     if(found == NULL 
 862                        && SCpnt->request.dev < 0) 
 863                     {
 864                         found=SCpnt;
 865                     }
 866                 } 
 867                 if(SCpnt->request.dev >= 0) {
 868                     /*
 869                      * I think that we should really limit things to one
 870                      * outstanding command per device - this is what tends to trip
 871                      * up buggy firmware.
 872                      */
 873                     return NULL;
 874                 }
 875             }
 876             SCpnt = SCpnt->next;
 877         }
 878         SCpnt = found;
 879     }
 880     
 881     if (!SCpnt) return NULL;
 882     
 883     if (SCSI_BLOCK(device->host)) return NULL;
 884     
 885     if (req) {
 886         memcpy(&SCpnt->request, req, sizeof(struct request));
 887         tablesize = device->host->sg_tablesize;
 888         bhp = bh = req->bh;
 889         if(!tablesize) bh = NULL;
 890         /* Take a quick look through the table to see how big it is.  
 891          * We already have our copy of req, so we can mess with that 
 892          * if we want to. 
 893          */
 894         while(req->nr_sectors && bh){
 895             bhp = bhp->b_reqnext;
 896             if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
 897             req->nr_sectors -= bh->b_size >> 9;
 898             req->sector += bh->b_size >> 9;
 899             if(!tablesize) break;
 900             bh = bhp;
 901         }
 902         if(req->nr_sectors && bh && bh->b_reqnext){  /* Any leftovers? */
 903             SCpnt->request.bhtail = bh;
 904             req->bh = bh->b_reqnext; /* Divide request */
 905             bh->b_reqnext = NULL;
 906             bh = req->bh;
 907             
 908             /* Now reset things so that req looks OK */
 909             SCpnt->request.nr_sectors -= req->nr_sectors;
 910             req->current_nr_sectors = bh->b_size >> 9;
 911             req->buffer = bh->b_data;
 912             SCpnt->request.sem = NULL; /* Wait until whole thing done */
 913         } else {
 914             req->dev = -1;
 915             wake_up(&wait_for_request);
 916         }
 917     } else {
 918         SCpnt->request.dev = 0xffff; /* Busy, but no request */
 919         SCpnt->request.sem = NULL;   /* And no one is waiting for the device 
 920                                       * either */
 921     }
 922     
 923     SCpnt->use_sg = 0;               /* Reset the scatter-gather flag */
 924     SCpnt->old_use_sg  = 0;
 925     SCpnt->transfersize = 0;
 926     SCpnt->underflow = 0;
 927     SCpnt->cmd_len = 0;
 928 
 929 /* Since not everyone seems to set the device info correctly
 930  * before Scsi_Cmnd gets send out to scsi_do_command, we do it here.
 931  */ 
 932     SCpnt->channel = device->channel;
 933     SCpnt->lun = device->lun;
 934     SCpnt->target = device->id;
 935 
 936     return SCpnt;
 937 }
 938 
 939 /* This function returns a structure pointer that will be valid for
 940  * the device.  The wait parameter tells us whether we should wait for
 941  * the unit to become free or not.  We are also able to tell this routine
 942  * not to return a descriptor if the host is unable to accept any more
 943  * commands for the time being.  We need to keep in mind that there is no
 944  * guarantee that the host remain not busy.  Keep in mind the
 945  * request_queueable function also knows the internal allocation scheme
 946  * of the packets for each device 
 947  */
 948 
 949 Scsi_Cmnd * allocate_device (struct request ** reqp, Scsi_Device * device,
     /* [previous][next][first][last][top][bottom][index][help] */
 950                              int wait)
 951 {
 952     int dev = -1;
 953     struct request * req = NULL;
 954     int tablesize;
 955     unsigned int flags;
 956     struct buffer_head * bh, *bhp;
 957     struct Scsi_Host * host;
 958     Scsi_Cmnd * SCpnt = NULL;
 959     Scsi_Cmnd * SCwait = NULL;
 960     Scsi_Cmnd * found = NULL;
 961     
 962     if (!device)
 963         panic ("No device passed to allocate_device().\n");
 964     
 965     if (reqp) req = *reqp;
 966     
 967     /* See if this request has already been queued by an interrupt routine */
 968     if (req && (dev = req->dev) <= 0) return NULL;
 969     
 970     host = device->host;
 971     
 972     if (intr_count && SCSI_BLOCK(host)) return NULL;
 973     
 974     while (1==1){
 975         SCpnt = device->host->host_queue;
 976         if (!device->single_lun) {
 977             while(SCpnt){
 978                 if(SCpnt->target == device->id &&
 979                    SCpnt->lun == device->lun) {
 980                     if(SCpnt->request.dev < 0) break;
 981                 }
 982                 SCpnt = SCpnt->next;
 983             }
 984         } else {
 985             while(SCpnt){
 986                 if(SCpnt->target == device->id) {
 987                     if (SCpnt->lun == device->lun) {
 988                         if(found == NULL 
 989                            && SCpnt->request.dev < 0) 
 990                         {
 991                             found=SCpnt;
 992                         }
 993                     } 
 994                     if(SCpnt->request.dev >= 0) {
 995                         /*
 996                          * I think that we should really limit things to one
 997                          * outstanding command per device - this is what tends to trip
 998                          * up buggy firmware.
 999                          */
1000                         found = NULL;
1001                         break;
1002                     }
1003                 }
1004                 SCpnt = SCpnt->next;
1005             }
1006             SCpnt = found;
1007         }
1008 
1009         save_flags(flags);
1010         cli();
1011         /* See if this request has already been queued by an interrupt routine
1012          */
1013         if (req && ((req->dev < 0) || (req->dev != dev))) {
1014             restore_flags(flags);
1015             return NULL;
1016         }
1017         if (!SCpnt || SCpnt->request.dev >= 0)  /* Might have changed */
1018         {
1019             restore_flags(flags);
1020             if(!wait) return NULL;
1021             if (!SCwait) {
1022                 printk("Attempt to allocate device channel %d, target %d, "
1023                        "lun %d\n", device->channel, device->id, device->lun);
1024                 panic("No device found in allocate_device\n");
1025             }
1026             SCSI_SLEEP(&device->device_wait,
1027                        (SCwait->request.dev > 0));
1028         } else {
1029             if (req) {
1030                 memcpy(&SCpnt->request, req, sizeof(struct request));
1031                 tablesize = device->host->sg_tablesize;
1032                 bhp = bh = req->bh;
1033                 if(!tablesize) bh = NULL;
1034                 /* Take a quick look through the table to see how big it is.  
1035                  * We already have our copy of req, so we can mess with that 
1036                  * if we want to.  
1037                  */
1038                 while(req->nr_sectors && bh){
1039                     bhp = bhp->b_reqnext;
1040                     if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
1041                     req->nr_sectors -= bh->b_size >> 9;
1042                     req->sector += bh->b_size >> 9;
1043                     if(!tablesize) break;
1044                     bh = bhp;
1045                 }
1046                 if(req->nr_sectors && bh && bh->b_reqnext){/* Any leftovers? */
1047                     SCpnt->request.bhtail = bh;
1048                     req->bh = bh->b_reqnext; /* Divide request */
1049                     bh->b_reqnext = NULL;
1050                     bh = req->bh;
1051                     /* Now reset things so that req looks OK */
1052                     SCpnt->request.nr_sectors -= req->nr_sectors;
1053                     req->current_nr_sectors = bh->b_size >> 9;
1054                     req->buffer = bh->b_data;
1055                     SCpnt->request.sem = NULL; /* Wait until whole thing done*/
1056                 }
1057                 else
1058                 {
1059                     req->dev = -1;
1060                     *reqp = req->next;
1061                     wake_up(&wait_for_request);
1062                 }
1063             } else {
1064                 SCpnt->request.dev = 0xffff; /* Busy */
1065                 SCpnt->request.sem = NULL;   /* And no one is waiting for this 
1066                                               * to complete */
1067             }
1068             restore_flags(flags);
1069             break;
1070         }
1071     }
1072     
1073     SCpnt->use_sg = 0;            /* Reset the scatter-gather flag */
1074     SCpnt->old_use_sg  = 0;
1075     SCpnt->transfersize = 0;      /* No default transfer size */
1076     SCpnt->cmd_len = 0;
1077 
1078     SCpnt->underflow = 0;         /* Do not flag underflow conditions */
1079 
1080     /* Since not everyone seems to set the device info correctly
1081      * before Scsi_Cmnd gets send out to scsi_do_command, we do it here.
1082      */ 
1083     SCpnt->channel = device->channel;
1084     SCpnt->lun = device->lun;
1085     SCpnt->target = device->id;
1086 
1087     return SCpnt;
1088 }
1089 
1090 /*
1091  * This is inline because we have stack problemes if we recurse to deeply.
1092  */
1093 
1094 inline void internal_cmnd (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1095 {
1096     int temp;
1097     struct Scsi_Host * host;
1098     unsigned int flags;
1099 #ifdef DEBUG_DELAY
1100     int clock;
1101 #endif
1102     
1103     host = SCpnt->host;
1104     
1105     /*
1106      * We will wait MIN_RESET_DELAY clock ticks after the last reset so
1107      * we can avoid the drive not being ready.
1108      */
1109     save_flags(flags);
1110     sti();
1111     temp = host->last_reset + MIN_RESET_DELAY;
1112     while (jiffies < temp);
1113     restore_flags(flags);
1114     
1115     update_timeout(SCpnt, SCpnt->timeout_per_command);
1116     
1117     /*
1118      * We will use a queued command if possible, otherwise we will emulate the
1119      * queuing and calling of completion function ourselves.
1120      */
1121 #ifdef DEBUG
1122     printk("internal_cmnd (host = %d, channel = %d, target = %d, "
1123            "command = %p, buffer = %p, \nbufflen = %d, done = %p)\n", 
1124            SCpnt->host->host_no, SCpnt->channel, SCpnt->target, SCpnt->cmnd, 
1125            SCpnt->buffer, SCpnt->bufflen, SCpnt->done);
1126 #endif
1127     
1128     if (host->can_queue)
1129     {
1130 #ifdef DEBUG
1131         printk("queuecommand : routine at %p\n",
1132                host->hostt->queuecommand);
1133 #endif
1134         /* This locking tries to prevent all sorts of races between
1135          * queuecommand and the interrupt code.  In effect,
1136          * we are only allowed to be in queuecommand once at
1137          * any given time, and we can only be in the interrupt
1138          * handler and the queuecommand function at the same time
1139          * when queuecommand is called while servicing the
1140          * interrupt. 
1141          */
1142         
1143         if(!intr_count && SCpnt->host->irq)
1144             disable_irq(SCpnt->host->irq);
1145         
1146         host->hostt->queuecommand (SCpnt, scsi_done);
1147         
1148         if(!intr_count && SCpnt->host->irq)
1149             enable_irq(SCpnt->host->irq);
1150     }
1151     else
1152     {
1153         
1154 #ifdef DEBUG
1155         printk("command() :  routine at %p\n", host->hostt->command);
1156 #endif
1157         temp=host->hostt->command (SCpnt);
1158         SCpnt->result = temp;
1159 #ifdef DEBUG_DELAY
1160         clock = jiffies + 4 * HZ;
1161         while (jiffies < clock);
1162         printk("done(host = %d, result = %04x) : routine at %08x\n", 
1163                host->host_no, temp);
1164 #endif
1165         scsi_done(SCpnt);
1166     }
1167 #ifdef DEBUG
1168     printk("leaving internal_cmnd()\n");
1169 #endif
1170 }
1171 
1172 static void scsi_request_sense (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1173 {
1174     unsigned int flags;
1175     
1176     save_flags(flags);
1177     cli();
1178     SCpnt->flags |= WAS_SENSE | ASKED_FOR_SENSE;
1179     update_timeout(SCpnt, SENSE_TIMEOUT);
1180     restore_flags(flags);
1181     
1182     
1183     memcpy ((void *) SCpnt->cmnd , (void *) generic_sense, 
1184             sizeof(generic_sense));
1185     
1186     SCpnt->cmnd[1] = SCpnt->lun << 5;
1187     SCpnt->cmnd[4] = sizeof(SCpnt->sense_buffer);
1188     
1189     SCpnt->request_buffer = &SCpnt->sense_buffer;
1190     SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
1191     SCpnt->use_sg = 0;
1192     SCpnt->cmd_len = COMMAND_SIZE(SCpnt->cmnd[0]);
1193     internal_cmnd (SCpnt);
1194 }
1195 
1196 
1197 
1198 /*
1199  * scsi_do_cmd sends all the commands out to the low-level driver.  It
1200  * handles the specifics required for each low level driver - ie queued
1201  * or non queued.  It also prevents conflicts when different high level
1202  * drivers go for the same host at the same time.
1203  */
1204 
1205 void scsi_do_cmd (Scsi_Cmnd * SCpnt, const void *cmnd ,
     /* [previous][next][first][last][top][bottom][index][help] */
1206                   void *buffer, unsigned bufflen, void (*done)(Scsi_Cmnd *),
1207                   int timeout, int retries)
1208 {
1209     unsigned long flags;
1210     struct Scsi_Host * host = SCpnt->host;
1211     
1212 #ifdef DEBUG
1213     {
1214         int i;
1215         int target = SCpnt->target;
1216         printk ("scsi_do_cmd (host = %d, channel = %d target = %d, "
1217                 "buffer =%p, bufflen = %d, done = %p, timeout = %d, "
1218                 "retries = %d)\n"
1219                 "command : " , host->host_no, SCpnt->channel, target, buffer, 
1220                 bufflen, done, timeout, retries);
1221         for (i = 0; i < 10; ++i)
1222             printk ("%02x  ", ((unsigned char *) cmnd)[i]);
1223         printk("\n");
1224     }
1225 #endif
1226     
1227     if (!host)
1228     {
1229         panic ("Invalid or not present host.\n");
1230     }
1231     
1232     
1233     /*
1234      * We must prevent reentrancy to the lowlevel host driver.  This prevents
1235      * it - we enter a loop until the host we want to talk to is not busy.
1236      * Race conditions are prevented, as interrupts are disabled in between the
1237      * time we check for the host being not busy, and the time we mark it busy
1238      * ourselves.
1239      */
1240 
1241     save_flags(flags);
1242     cli();
1243     SCpnt->pid = scsi_pid++;
1244     
1245     while (SCSI_BLOCK(host)) {
1246         restore_flags(flags);
1247         SCSI_SLEEP(&host->host_wait, SCSI_BLOCK(host));
1248         cli();
1249     }
1250     
1251     if (host->block) host_active = host;
1252     
1253     host->host_busy++;
1254     restore_flags(flags);
1255     
1256     /*
1257      * Our own function scsi_done (which marks the host as not busy, disables
1258      * the timeout counter, etc) will be called by us or by the
1259      * scsi_hosts[host].queuecommand() function needs to also call
1260      * the completion function for the high level driver.
1261      */
1262     
1263     memcpy ((void *) SCpnt->data_cmnd , (void *) cmnd, 12);
1264 #if 0
1265     SCpnt->host = host;
1266     SCpnt->channel = channel;
1267     SCpnt->target = target;
1268     SCpnt->lun = (SCpnt->data_cmnd[1] >> 5);
1269 #endif
1270     SCpnt->bufflen = bufflen;
1271     SCpnt->buffer = buffer;
1272     SCpnt->flags=0;
1273     SCpnt->retries=0;
1274     SCpnt->allowed=retries;
1275     SCpnt->done = done;
1276     SCpnt->timeout_per_command = timeout;
1277 
1278     memcpy ((void *) SCpnt->cmnd , (void *) cmnd, 12);
1279     /* Zero the sense buffer.  Some host adapters automatically request
1280      * sense on error.  0 is not a valid sense code.  
1281      */
1282     memset ((void *) SCpnt->sense_buffer, 0, sizeof SCpnt->sense_buffer);
1283     SCpnt->request_buffer = buffer;
1284     SCpnt->request_bufflen = bufflen;
1285     SCpnt->old_use_sg = SCpnt->use_sg;
1286     if (SCpnt->cmd_len == 0)
1287         SCpnt->cmd_len = COMMAND_SIZE(SCpnt->cmnd[0]);
1288     SCpnt->old_cmd_len = SCpnt->cmd_len;
1289 
1290     /* Start the timer ticking.  */
1291 
1292     SCpnt->internal_timeout = 0;
1293     SCpnt->abort_reason = 0;
1294     internal_cmnd (SCpnt);
1295 
1296 #ifdef DEBUG
1297     printk ("Leaving scsi_do_cmd()\n");
1298 #endif
1299 }
1300 
1301 
1302 
1303 /*
1304  * The scsi_done() function disables the timeout timer for the scsi host,
1305  * marks the host as not busy, and calls the user specified completion
1306  * function for that host's current command.
1307  */
1308 
1309 static void reset (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1310 {
1311 #ifdef DEBUG
1312     printk("scsi: reset(%d, channel %d)\n", SCpnt->host->host_no, 
1313            SCpnt->channel);
1314 #endif
1315 
1316     SCpnt->flags |= (WAS_RESET | IS_RESETTING);
1317     scsi_reset(SCpnt);
1318 
1319 #ifdef DEBUG
1320     printk("performing request sense\n");
1321 #endif
1322 
1323 #if 0  /* FIXME - remove this when done */
1324     if(SCpnt->flags & NEEDS_JUMPSTART) {
1325         SCpnt->flags &= ~NEEDS_JUMPSTART;
1326         scsi_request_sense (SCpnt);
1327     }
1328 #endif
1329 }
1330 
1331 
1332 
1333 static int check_sense (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1334 {
1335     /* If there is no sense information, request it.  If we have already
1336      * requested it, there is no point in asking again - the firmware must
1337      * be confused. 
1338      */
1339     if (((SCpnt->sense_buffer[0] & 0x70) >> 4) != 7) {
1340         if(!(SCpnt->flags & ASKED_FOR_SENSE))
1341             return SUGGEST_SENSE;
1342         else
1343             return SUGGEST_RETRY;
1344     }
1345     
1346     SCpnt->flags &= ~ASKED_FOR_SENSE;
1347     
1348 #ifdef DEBUG_INIT
1349     printk("scsi%d, channel%d : ", SCpnt->host->host_no, SCpnt->channel);
1350     print_sense("", SCpnt);
1351     printk("\n");
1352 #endif
1353     if (SCpnt->sense_buffer[2] & 0xe0)
1354         return SUGGEST_ABORT;
1355     
1356     switch (SCpnt->sense_buffer[2] & 0xf)
1357     {
1358     case NO_SENSE:
1359         return 0;
1360     case RECOVERED_ERROR:
1361         return SUGGEST_IS_OK;
1362         
1363     case ABORTED_COMMAND:
1364         return SUGGEST_RETRY;
1365     case NOT_READY:
1366     case UNIT_ATTENTION:
1367         return SUGGEST_ABORT;
1368         
1369     /* these three are not supported */
1370     case COPY_ABORTED:
1371     case VOLUME_OVERFLOW:
1372     case MISCOMPARE:
1373         
1374     case MEDIUM_ERROR:
1375         return SUGGEST_REMAP;
1376     case BLANK_CHECK:
1377     case DATA_PROTECT:
1378     case HARDWARE_ERROR:
1379     case ILLEGAL_REQUEST:
1380     default:
1381         return SUGGEST_ABORT;
1382     }
1383 }
1384 
1385 /* This function is the mid-level interrupt routine, which decides how
1386  *  to handle error conditions.  Each invocation of this function must
1387  *  do one and *only* one of the following:
1388  *
1389  *  (1) Call last_cmnd[host].done.  This is done for fatal errors and
1390  *      normal completion, and indicates that the handling for this
1391  *      request is complete.
1392  *  (2) Call internal_cmnd to requeue the command.  This will result in
1393  *      scsi_done being called again when the retry is complete.
1394  *  (3) Call scsi_request_sense.  This asks the host adapter/drive for
1395  *      more information about the error condition.  When the information
1396  *      is available, scsi_done will be called again.
1397  *  (4) Call reset().  This is sort of a last resort, and the idea is that
1398  *      this may kick things loose and get the drive working again.  reset()
1399  *      automatically calls scsi_request_sense, and thus scsi_done will be
1400  *      called again once the reset is complete.
1401  *
1402  *      If none of the above actions are taken, the drive in question
1403  *      will hang. If more than one of the above actions are taken by
1404  *      scsi_done, then unpredictable behavior will result.
1405  */
1406 static void scsi_done (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1407 {
1408     int status=0;
1409     int exit=0;
1410     int checked;
1411     int oldto;
1412     struct Scsi_Host * host = SCpnt->host;
1413     int result = SCpnt->result;
1414     oldto = update_timeout(SCpnt, 0);
1415     
1416 #ifdef DEBUG_TIMEOUT
1417     if(result) printk("Non-zero result in scsi_done %x %d:%d\n",
1418                       result, SCpnt->target, SCpnt->lun);
1419 #endif
1420     
1421     /* If we requested an abort, (and we got it) then fix up the return
1422      *  status to say why 
1423      */
1424     if(host_byte(result) == DID_ABORT && SCpnt->abort_reason)
1425         SCpnt->result = result = (result & 0xff00ffff) |
1426             (SCpnt->abort_reason << 16);
1427 
1428 
1429 #define FINISHED 0
1430 #define MAYREDO  1
1431 #define REDO     3
1432 #define PENDING  4
1433 
1434 #ifdef DEBUG
1435     printk("In scsi_done(host = %d, result = %06x)\n", host->host_no, result);
1436 #endif
1437 
1438     if(SCpnt->flags & WAS_SENSE)
1439     {
1440         SCpnt->use_sg = SCpnt->old_use_sg;
1441         SCpnt->cmd_len = SCpnt->old_cmd_len;
1442     }
1443 
1444     switch (host_byte(result))
1445     {
1446     case DID_OK:
1447         if (status_byte(result) && (SCpnt->flags & WAS_SENSE))
1448             /* Failed to obtain sense information */
1449         {
1450             SCpnt->flags &= ~WAS_SENSE;
1451             SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1452             
1453             if (!(SCpnt->flags & WAS_RESET))
1454             {
1455                 printk("scsi%d : channel %d target %d lun %d request sense"
1456                        " failed, performing reset.\n",
1457                        SCpnt->host->host_no, SCpnt->channel, SCpnt->target, 
1458                        SCpnt->lun);
1459                 reset(SCpnt);
1460                 return;
1461             }
1462             else
1463             {
1464                 exit = (DRIVER_HARD | SUGGEST_ABORT);
1465                 status = FINISHED;
1466             }
1467         }
1468         else switch(msg_byte(result))
1469         {
1470         case COMMAND_COMPLETE:
1471             switch (status_byte(result))
1472             {
1473             case GOOD:
1474                 if (SCpnt->flags & WAS_SENSE)
1475                 {
1476 #ifdef DEBUG
1477                     printk ("In scsi_done, GOOD status, COMMAND COMPLETE, parsing sense information.\n");
1478 #endif
1479                     SCpnt->flags &= ~WAS_SENSE;
1480                     SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1481                     
1482                     switch (checked = check_sense(SCpnt))
1483                     {
1484                     case SUGGEST_SENSE:
1485                     case 0:
1486 #ifdef DEBUG
1487                         printk("NO SENSE.  status = REDO\n");
1488 #endif
1489                         update_timeout(SCpnt, oldto);
1490                         status = REDO;
1491                         break;
1492                     case SUGGEST_IS_OK:
1493                         break;
1494                     case SUGGEST_REMAP:
1495                     case SUGGEST_RETRY:
1496 #ifdef DEBUG
1497                         printk("SENSE SUGGEST REMAP or SUGGEST RETRY - status = MAYREDO\n");
1498 #endif
1499                         status = MAYREDO;
1500                         exit = DRIVER_SENSE | SUGGEST_RETRY;
1501                         break;
1502                     case SUGGEST_ABORT:
1503 #ifdef DEBUG
1504                         printk("SENSE SUGGEST ABORT - status = FINISHED");
1505 #endif
1506                         status = FINISHED;
1507                         exit =  DRIVER_SENSE | SUGGEST_ABORT;
1508                         break;
1509                     default:
1510                         printk ("Internal error %s %d \n", __FILE__,
1511                                 __LINE__);
1512                     }
1513                 }
1514                 else
1515                 {
1516 #ifdef DEBUG
1517                     printk("COMMAND COMPLETE message returned, status = FINISHED. \n");
1518 #endif
1519                     exit =  DRIVER_OK;
1520                     status = FINISHED;
1521                 }
1522                 break;
1523                 
1524             case CHECK_CONDITION:
1525                 switch (check_sense(SCpnt))
1526                 {
1527                 case 0:
1528                     update_timeout(SCpnt, oldto);
1529                     status = REDO;
1530                     break;
1531                 case SUGGEST_REMAP:
1532                 case SUGGEST_RETRY:
1533                     status = MAYREDO;
1534                     exit = DRIVER_SENSE | SUGGEST_RETRY;
1535                     break;
1536                 case SUGGEST_ABORT:
1537                     status = FINISHED;
1538                     exit =  DRIVER_SENSE | SUGGEST_ABORT;
1539                     break;
1540                 case SUGGEST_SENSE:
1541                     scsi_request_sense (SCpnt);
1542                     status = PENDING;
1543                     break;
1544                 }
1545                 break;
1546                 
1547             case CONDITION_GOOD:
1548             case INTERMEDIATE_GOOD:
1549             case INTERMEDIATE_C_GOOD:
1550                 break;
1551                 
1552             case BUSY:
1553                 update_timeout(SCpnt, oldto);
1554                 status = REDO;
1555                 break;
1556                 
1557             case RESERVATION_CONFLICT:
1558                 printk("scsi%d, channel %d : RESERVATION CONFLICT performing"
1559                        " reset.\n", SCpnt->host->host_no, SCpnt->channel);
1560                 reset(SCpnt);
1561                 return;
1562 #if 0
1563                 exit = DRIVER_SOFT | SUGGEST_ABORT;
1564                 status = MAYREDO;
1565                 break;
1566 #endif
1567             default:
1568                 printk ("Internal error %s %d \n"
1569                         "status byte = %d \n", __FILE__,
1570                         __LINE__, status_byte(result));
1571                 
1572             }
1573             break;
1574         default:
1575             panic("scsi: unsupported message byte %d received\n", 
1576                   msg_byte(result));
1577         }
1578         break;
1579     case DID_TIME_OUT:
1580 #ifdef DEBUG
1581         printk("Host returned DID_TIME_OUT - ");
1582 #endif
1583         
1584         if (SCpnt->flags & WAS_TIMEDOUT)
1585         {
1586 #ifdef DEBUG
1587             printk("Aborting\n");
1588 #endif
1589             exit = (DRIVER_TIMEOUT | SUGGEST_ABORT);
1590         }
1591         else
1592         {
1593 #ifdef DEBUG
1594             printk ("Retrying.\n");
1595 #endif
1596             SCpnt->flags  |= WAS_TIMEDOUT;
1597             SCpnt->internal_timeout &= ~IN_ABORT;
1598             status = REDO;
1599         }
1600         break;
1601     case DID_BUS_BUSY:
1602     case DID_PARITY:
1603         status = REDO;
1604         break;
1605     case DID_NO_CONNECT:
1606 #ifdef DEBUG
1607         printk("Couldn't connect.\n");
1608 #endif
1609         exit  = (DRIVER_HARD | SUGGEST_ABORT);
1610         break;
1611     case DID_ERROR:
1612         status = MAYREDO;
1613         exit = (DRIVER_HARD | SUGGEST_ABORT);
1614         break;
1615     case DID_BAD_TARGET:
1616     case DID_ABORT:
1617         exit = (DRIVER_INVALID | SUGGEST_ABORT);
1618         break;
1619     case DID_RESET:
1620         if (SCpnt->flags & IS_RESETTING)
1621         {
1622             SCpnt->flags &= ~IS_RESETTING;
1623             status = REDO;
1624             break;
1625         }
1626         
1627         if(msg_byte(result) == GOOD &&
1628            status_byte(result) == CHECK_CONDITION) {
1629             switch (check_sense(SCpnt)) {
1630             case 0:
1631                 update_timeout(SCpnt, oldto);
1632                 status = REDO;
1633                 break;
1634             case SUGGEST_REMAP:
1635             case SUGGEST_RETRY:
1636                 status = MAYREDO;
1637                 exit = DRIVER_SENSE | SUGGEST_RETRY;
1638                 break;
1639             case SUGGEST_ABORT:
1640                 status = FINISHED;
1641                 exit =  DRIVER_SENSE | SUGGEST_ABORT;
1642                 break;
1643             case SUGGEST_SENSE:
1644                 scsi_request_sense (SCpnt);
1645                 status = PENDING;
1646                 break;
1647             }
1648         } else {
1649             status=REDO;
1650             exit = SUGGEST_RETRY;
1651         }
1652         break;
1653     default :
1654         exit = (DRIVER_ERROR | SUGGEST_DIE);
1655     }
1656     
1657     switch (status)
1658     {
1659     case FINISHED:
1660     case PENDING:
1661         break;
1662     case MAYREDO:
1663 #ifdef DEBUG
1664         printk("In MAYREDO, allowing %d retries, have %d\n",
1665                SCpnt->allowed, SCpnt->retries);
1666 #endif
1667         if ((++SCpnt->retries) < SCpnt->allowed)
1668         {
1669             if ((SCpnt->retries >= (SCpnt->allowed >> 1))
1670                 && !(jiffies < SCpnt->host->last_reset + MIN_RESET_PERIOD)
1671                 && !(SCpnt->flags & WAS_RESET))
1672             {
1673                 printk("scsi%d channel %d : resetting for second half of retries.\n",
1674                        SCpnt->host->host_no, SCpnt->channel);
1675                 reset(SCpnt);
1676                 break;
1677             }
1678             
1679         }
1680         else
1681         {
1682             status = FINISHED;
1683             break;
1684         }
1685         /* fall through to REDO */
1686         
1687     case REDO:
1688         
1689         if (SCpnt->flags & WAS_SENSE)
1690             scsi_request_sense(SCpnt);
1691         else
1692         {
1693             memcpy ((void *) SCpnt->cmnd,
1694                     (void*) SCpnt->data_cmnd,
1695                     sizeof(SCpnt->data_cmnd));
1696             SCpnt->request_buffer = SCpnt->buffer;
1697             SCpnt->request_bufflen = SCpnt->bufflen;
1698             SCpnt->use_sg = SCpnt->old_use_sg;
1699             SCpnt->cmd_len = SCpnt->old_cmd_len;
1700             internal_cmnd (SCpnt);
1701         }
1702         break;
1703     default:
1704         INTERNAL_ERROR;
1705     }
1706     
1707     if (status == FINISHED) {
1708 #ifdef DEBUG
1709         printk("Calling done function - at address %p\n", SCpnt->done);
1710 #endif
1711         host->host_busy--; /* Indicate that we are free */
1712         
1713         if (host->block && host->host_busy == 0) {
1714             host_active = NULL;
1715             
1716             /* For block devices "wake_up" is done in end_scsi_request */
1717             if (MAJOR(SCpnt->request.dev) != SCSI_DISK_MAJOR &&
1718                 MAJOR(SCpnt->request.dev) != SCSI_CDROM_MAJOR) {
1719                 struct Scsi_Host * next;
1720                 
1721                 for (next = host->block; next != host; next = next->block)
1722                     wake_up(&next->host_wait);
1723             }
1724             
1725         }
1726         
1727         wake_up(&host->host_wait);
1728         SCpnt->result = result | ((exit & 0xff) << 24);
1729         SCpnt->use_sg = SCpnt->old_use_sg;
1730         SCpnt->cmd_len = SCpnt->old_cmd_len;
1731         SCpnt->done (SCpnt);
1732     }
1733     
1734 #undef FINISHED
1735 #undef REDO
1736 #undef MAYREDO
1737 #undef PENDING
1738 }
1739 
1740 /*
1741  * The scsi_abort function interfaces with the abort() function of the host
1742  * we are aborting, and causes the current command to not complete.  The
1743  * caller should deal with any error messages or status returned on the
1744  * next call.
1745  * 
1746  * This will not be called reentrantly for a given host.
1747  */
1748 
1749 /*
1750  * Since we're nice guys and specified that abort() and reset()
1751  * can be non-reentrant.  The internal_timeout flags are used for
1752  * this.
1753  */
1754 
1755 
1756 int scsi_abort (Scsi_Cmnd * SCpnt, int why, int pid)
     /* [previous][next][first][last][top][bottom][index][help] */
1757 {
1758     int oldto;
1759     unsigned long flags;
1760     struct Scsi_Host * host = SCpnt->host;
1761     
1762     while(1)
1763     {
1764         save_flags(flags);
1765         cli();
1766         
1767         /*
1768          * Protect against races here.  If the command is done, or we are
1769          * on a different command forget it.
1770          */
1771         if (SCpnt->request.dev == -1 || pid != SCpnt->pid) {
1772             restore_flags(flags);
1773             return 0;
1774         }
1775 
1776         if (SCpnt->internal_timeout & IN_ABORT)
1777         {
1778             restore_flags(flags);
1779             while (SCpnt->internal_timeout & IN_ABORT)
1780                 barrier();
1781         }
1782         else
1783         {
1784             SCpnt->internal_timeout |= IN_ABORT;
1785             oldto = update_timeout(SCpnt, ABORT_TIMEOUT);
1786             
1787             if ((SCpnt->flags & IS_RESETTING) &&
1788                 SCpnt->device->soft_reset) {
1789                 /* OK, this command must have died when we did the
1790                  *  reset.  The device itself must have lied. 
1791                  */
1792                 printk("Stale command on %d %d:%d appears to have died when"
1793                        " the bus was reset\n", 
1794                        SCpnt->channel, SCpnt->target, SCpnt->lun);
1795             }
1796             
1797             restore_flags(flags);
1798             if (!host->host_busy) {
1799                 SCpnt->internal_timeout &= ~IN_ABORT;
1800                 update_timeout(SCpnt, oldto);
1801                 return 0;
1802             }
1803             printk("scsi : aborting command due to timeout : pid %lu, scsi%d,"
1804                    " channel %d, id %d, lun %d ",
1805                    SCpnt->pid, SCpnt->host->host_no, (int) SCpnt->channel, 
1806                    (int) SCpnt->target, (int) SCpnt->lun);
1807             print_command (SCpnt->cmnd);
1808             if (SCpnt->request.dev == -1 || pid != SCpnt->pid)
1809                 return 0;
1810             SCpnt->abort_reason = why;
1811             switch(host->hostt->abort(SCpnt)) {
1812                 /* We do not know how to abort.  Try waiting another
1813                  * time increment and see if this helps. Set the
1814                  * WAS_TIMEDOUT flag set so we do not try this twice
1815                  */
1816             case SCSI_ABORT_BUSY: /* Tough call - returning 1 from
1817                                    * this is too severe 
1818                                    */
1819             case SCSI_ABORT_SNOOZE:
1820                 if(why == DID_TIME_OUT) {
1821                     save_flags(flags);
1822                     cli();
1823                     SCpnt->internal_timeout &= ~IN_ABORT;
1824                     if(SCpnt->flags & WAS_TIMEDOUT) {
1825                         restore_flags(flags);
1826                         return 1; /* Indicate we cannot handle this.
1827                                    * We drop down into the reset handler
1828                                    * and try again 
1829                                    */
1830                     } else {
1831                         SCpnt->flags |= WAS_TIMEDOUT;
1832                         oldto = SCpnt->timeout_per_command;
1833                         update_timeout(SCpnt, oldto);
1834                     }
1835                     restore_flags(flags);
1836                 }
1837                 return 0;
1838             case SCSI_ABORT_PENDING:
1839                 if(why != DID_TIME_OUT) {
1840                     save_flags(flags);
1841                     cli();
1842                     update_timeout(SCpnt, oldto);
1843                     restore_flags(flags);
1844                 }
1845                 return 0;
1846             case SCSI_ABORT_SUCCESS:
1847                 /* We should have already aborted this one.  No
1848                  * need to adjust timeout 
1849                  */
1850             case SCSI_ABORT_NOT_RUNNING:
1851                 SCpnt->internal_timeout &= ~IN_ABORT;
1852                 update_timeout(SCpnt, 0);
1853                 return 0;
1854             case SCSI_ABORT_ERROR:
1855             default:
1856                 SCpnt->internal_timeout &= ~IN_ABORT;
1857                 return 1;
1858             }
1859         }
1860     }
1861 }
1862 
1863 int scsi_reset (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1864 {
1865     int temp, oldto;
1866     unsigned long flags;
1867     Scsi_Cmnd * SCpnt1;
1868     struct Scsi_Host * host = SCpnt->host;
1869 
1870 #ifdef DEBUG
1871     printk("Danger Will Robinson! - SCSI bus for host %d is being reset.\n",
1872            host->host_no);
1873 #endif
1874     while (1) {
1875         save_flags(flags);
1876         cli();
1877         if (SCpnt->internal_timeout & IN_RESET)
1878         {
1879             restore_flags(flags);
1880             while (SCpnt->internal_timeout & IN_RESET)
1881                 barrier();
1882         }
1883         else
1884         {
1885             SCpnt->internal_timeout |= IN_RESET;
1886             oldto = update_timeout(SCpnt, RESET_TIMEOUT);
1887             
1888             if (host->host_busy)
1889             {
1890                 restore_flags(flags);
1891                 SCpnt1 = host->host_queue;
1892                 while(SCpnt1) {
1893                     if (SCpnt1->request.dev > 0) {
1894 #if 0
1895                         if (!(SCpnt1->flags & IS_RESETTING) &&
1896                             !(SCpnt1->internal_timeout & IN_ABORT))
1897                             scsi_abort(SCpnt1, DID_RESET, SCpnt->pid);
1898 #endif
1899                         SCpnt1->flags |= IS_RESETTING;
1900                     }
1901                     SCpnt1 = SCpnt1->next;
1902                 }
1903                 
1904                 host->last_reset = jiffies;
1905                 temp = host->hostt->reset(SCpnt);
1906                 host->last_reset = jiffies;
1907             }
1908             else
1909             {
1910                 if (!host->block) host->host_busy++;
1911                 restore_flags(flags);
1912                 host->last_reset = jiffies;
1913                 temp = host->hostt->reset(SCpnt);
1914                 host->last_reset = jiffies;
1915                 if (!host->block) host->host_busy--;
1916             }
1917             
1918 #ifdef DEBUG
1919             printk("scsi reset function returned %d\n", temp);
1920 #endif
1921             switch(temp) {
1922             case SCSI_RESET_SUCCESS:
1923                 save_flags(flags);
1924                 cli();
1925                 SCpnt->internal_timeout &= ~IN_RESET;
1926                 update_timeout(SCpnt, oldto);
1927                 restore_flags(flags);
1928                 return 0;
1929             case SCSI_RESET_PENDING:
1930                 return 0;
1931             case SCSI_RESET_PUNT:
1932             case SCSI_RESET_WAKEUP:
1933                 SCpnt->internal_timeout &= ~IN_RESET;
1934                 scsi_request_sense (SCpnt);
1935                 return 0;
1936             case SCSI_RESET_SNOOZE:
1937                 /* In this case, we set the timeout field to 0
1938                  * so that this command does not time out any more,
1939                  * and we return 1 so that we get a message on the
1940                  * screen. 
1941                  */
1942                 save_flags(flags);
1943                 cli();
1944                 SCpnt->internal_timeout &= ~IN_RESET;
1945                 update_timeout(SCpnt, 0);
1946                 restore_flags(flags);
1947                 /* If you snooze, you lose... */
1948             case SCSI_RESET_ERROR:
1949             default:
1950                 return 1;
1951             }
1952             
1953             return temp;
1954         }
1955     }
1956 }
1957 
1958 
1959 static void scsi_main_timeout(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1960 {
1961     /*
1962      * We must not enter update_timeout with a timeout condition still pending.
1963      */
1964     
1965     int timed_out, pid;
1966     unsigned long flags;
1967     struct Scsi_Host * host;
1968     Scsi_Cmnd * SCpnt = NULL;
1969     
1970     do {
1971         save_flags(flags);
1972         cli();
1973         
1974         update_timeout(NULL, 0);
1975         /*
1976          * Find all timers such that they have 0 or negative (shouldn't happen)
1977          * time remaining on them.
1978          */
1979         
1980         timed_out = 0;
1981         for(host = scsi_hostlist; host; host = host->next) {
1982             for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
1983                 if (SCpnt->timeout == -1)
1984                 {
1985                     SCpnt->timeout = 0;
1986                     pid = SCpnt->pid;
1987                     restore_flags(flags);
1988                     scsi_times_out(SCpnt, pid);
1989                     ++timed_out;
1990                     save_flags(flags);
1991                     cli();
1992                 }
1993         }
1994     } while (timed_out);
1995     restore_flags(flags);
1996 }
1997 
1998 /*
1999  * The strategy is to cause the timer code to call scsi_times_out()
2000  * when the soonest timeout is pending.
2001  * The arguments are used when we are queueing a new command, because
2002  * we do not want to subtract the time used from this time, but when we
2003  * set the timer, we want to take this value into account.
2004  */
2005 
2006 static int update_timeout(Scsi_Cmnd * SCset, int timeout)
     /* [previous][next][first][last][top][bottom][index][help] */
2007 {
2008     unsigned int least, used;
2009     unsigned int oldto;
2010     unsigned long flags;
2011     struct Scsi_Host * host;
2012     Scsi_Cmnd * SCpnt = NULL;
2013 
2014     save_flags(flags);
2015     cli();
2016 
2017     /*
2018      * Figure out how much time has passed since the last time the timeouts
2019      * were updated
2020      */
2021     used = (time_start) ? (jiffies - time_start) : 0;
2022 
2023     /*
2024      * Find out what is due to timeout soonest, and adjust all timeouts for
2025      * the amount of time that has passed since the last time we called
2026      * update_timeout.
2027      */
2028 
2029     oldto = 0;
2030     
2031     if(SCset){
2032         oldto = SCset->timeout - used;
2033         SCset->timeout = timeout + used;
2034     }
2035 
2036     least = 0xffffffff;
2037     
2038     for(host = scsi_hostlist; host; host = host->next)
2039         for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
2040             if (SCpnt->timeout > 0) {
2041                 SCpnt->timeout -= used;
2042                 if(SCpnt->timeout <= 0) SCpnt->timeout = -1;
2043                 if(SCpnt->timeout > 0 && SCpnt->timeout < least)
2044                     least = SCpnt->timeout;
2045             }
2046     
2047     /*
2048      * If something is due to timeout again, then we will set the next timeout
2049      * interrupt to occur.  Otherwise, timeouts are disabled.
2050      */
2051     
2052     if (least != 0xffffffff)
2053     {
2054         time_start = jiffies;
2055         timer_table[SCSI_TIMER].expires = (time_elapsed = least) + jiffies;
2056         timer_active |= 1 << SCSI_TIMER;
2057     }
2058     else
2059     {
2060         timer_table[SCSI_TIMER].expires = time_start = time_elapsed = 0;
2061         timer_active &= ~(1 << SCSI_TIMER);
2062     }
2063     restore_flags(flags);
2064     return oldto;
2065 }
2066 
2067 
2068 static unsigned char * dma_malloc_freelist = NULL;
2069 static int scsi_need_isa_bounce_buffers;
2070 static unsigned int dma_sectors = 0;
2071 unsigned int dma_free_sectors = 0;
2072 unsigned int need_isa_buffer = 0;
2073 static unsigned char ** dma_malloc_pages = NULL;
2074 #define MALLOC_PAGEBITS 12
2075 
2076 static int scsi_register_host(Scsi_Host_Template *);
2077 static void scsi_unregister_host(Scsi_Host_Template *);
2078 
2079 void *scsi_malloc(unsigned int len)
     /* [previous][next][first][last][top][bottom][index][help] */
2080 {
2081     unsigned int nbits, mask;
2082     unsigned long flags;
2083     int i, j;
2084     if((len & 0x1ff) || len > (1<<MALLOC_PAGEBITS))
2085         return NULL;
2086     
2087     save_flags(flags);
2088     cli();
2089     nbits = len >> 9;
2090     mask = (1 << nbits) - 1;
2091     
2092     for(i=0;i < (dma_sectors >> (MALLOC_PAGEBITS - 9)); i++)
2093         for(j=0; j<=(sizeof(*dma_malloc_freelist) * 8) - nbits; j++){
2094             if ((dma_malloc_freelist[i] & (mask << j)) == 0){
2095                 dma_malloc_freelist[i] |= (mask << j);
2096                 restore_flags(flags);
2097                 dma_free_sectors -= nbits;
2098 #ifdef DEBUG
2099                 printk("SMalloc: %d %p ",len, dma_malloc_pages[i] + (j << 9));
2100 #endif
2101                 return (void *) ((unsigned long) dma_malloc_pages[i] + (j << 9));
2102             }
2103         }
2104     restore_flags(flags);
2105     return NULL;  /* Nope.  No more */
2106 }
2107 
2108 int scsi_free(void *obj, unsigned int len)
     /* [previous][next][first][last][top][bottom][index][help] */
2109 {
2110     int page, sector, nbits, mask;
2111     long offset;
2112     unsigned long flags;
2113     
2114 #ifdef DEBUG
2115     printk("Sfree %p %d\n",obj, len);
2116 #endif
2117     
2118     offset = -1;
2119     for (page = 0; page < (dma_sectors >> 3); page++)
2120         if ((unsigned long) obj >= (unsigned long) dma_malloc_pages[page] &&
2121             (unsigned long) obj < (unsigned long) dma_malloc_pages[page] 
2122             + (1 << MALLOC_PAGEBITS))
2123         {
2124             offset = ((unsigned long) obj) - ((unsigned long)dma_malloc_pages[page]);
2125             break;
2126         }
2127     
2128     if (page == (dma_sectors >> 3)) panic("Bad offset");
2129     sector = offset >> 9;
2130     if(sector >= dma_sectors) panic ("Bad page");
2131     
2132     sector = (offset >> 9) & (sizeof(*dma_malloc_freelist) * 8 - 1);
2133     nbits = len >> 9;
2134     mask = (1 << nbits) - 1;
2135     
2136     if ((mask << sector) > 0xffff) panic ("Bad memory alignment");
2137     
2138     save_flags(flags);
2139     cli();
2140     if((dma_malloc_freelist[page] & (mask << sector)) != (mask<<sector))
2141         panic("Trying to free unused memory");
2142     
2143     dma_free_sectors += nbits;
2144     dma_malloc_freelist[page] &= ~(mask << sector);
2145     restore_flags(flags);
2146     return 0;
2147 }
2148 
2149 /*
2150  * These are special functions that can be used to obtain memory at boot time.
2151  * They act line a malloc function, but they simply take memory from the pool 
2152  */
2153 
2154 static unsigned long scsi_init_memory_start = 0;
2155 static unsigned long scsi_memory_lower_value = 0;
2156 static unsigned long scsi_memory_upper_value = 0;
2157 int scsi_loadable_module_flag; /* Set after we scan builtin drivers */
2158 
2159 void * scsi_init_malloc(unsigned int size, int priority)
     /* [previous][next][first][last][top][bottom][index][help] */
2160 {
2161     unsigned long retval;
2162     
2163     /* Use the statically allocated memory instead of kmalloc  (DB) */
2164 #if defined(USE_STATIC_SCSI_MEMORY)
2165     if(scsi_loadable_module_flag && !(priority & GFP_DMA))
2166 #else
2167         if(scsi_loadable_module_flag)
2168 #endif
2169         {
2170             /*
2171              * For buffers used by the DMA pool, we assume page aligned 
2172              * structures.
2173              */
2174             if(size == PAGE_SIZE)
2175                 retval = (unsigned long) __get_dma_pages(priority & GFP_LEVEL_MASK, 0);
2176             else
2177                 retval = (unsigned long) kmalloc(size, priority);
2178         } else {
2179             /*
2180              * Keep all memory aligned on 16-byte boundaries. Some host 
2181              * adaptors (e.g. BusLogic BT-445S) require DMA buffers to be 
2182              * aligned that way.
2183              */
2184             size = (size + 15) & ~15;
2185             
2186             if(scsi_loadable_module_flag &&
2187                (scsi_init_memory_start + size) > scsi_memory_upper_value) {
2188                 retval = 0;
2189                 printk("scsi_init_malloc: no more statically allocated memory.\n");
2190             }
2191             else {
2192                 retval = scsi_init_memory_start;
2193                 scsi_init_memory_start += size;
2194             }
2195         }
2196     memset((void *) retval, 0, size);
2197     return (void *) retval;
2198 }
2199 
2200 
2201 void scsi_init_free(char * ptr, unsigned int size)
     /* [previous][next][first][last][top][bottom][index][help] */
2202 { 
2203     /* We need to compare addresses to see whether this was kmalloc'd or not */
2204     
2205     if((unsigned long) ptr >= scsi_init_memory_start ||
2206        (unsigned long) ptr <  scsi_memory_lower_value) {
2207         /*
2208          * We need this special code here because the DMA pool assumes
2209          * page aligned data.  Besides, it is wasteful to allocate
2210          * page sized chunks with kmalloc.
2211          */
2212         if(size == PAGE_SIZE)
2213             free_pages((unsigned long)ptr, 0);
2214         else
2215             kfree(ptr);
2216     } else {
2217         /* Use the same alignment as scsi_init_malloc() */
2218         size = (size + 15) & ~15;
2219         
2220         if(((unsigned long) ptr) + size == scsi_init_memory_start)
2221             scsi_init_memory_start = (unsigned long) ptr;
2222     }
2223 }
2224 
2225 void scsi_build_commandblocks(Scsi_Device * SDpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
2226 {
2227     int j;
2228     Scsi_Cmnd * SCpnt;
2229     struct Scsi_Host * host = NULL;
2230     
2231     for(j=0;j<SDpnt->host->cmd_per_lun;j++){
2232         SCpnt = (Scsi_Cmnd *) scsi_init_malloc(sizeof(Scsi_Cmnd), GFP_ATOMIC);
2233         SCpnt->host = SDpnt->host;
2234         SCpnt->device = SDpnt;
2235         SCpnt->target = SDpnt->id;
2236         SCpnt->lun = SDpnt->lun;
2237         SCpnt->channel = SDpnt->channel;
2238         SCpnt->request.dev = -1; /* Mark not busy */
2239         SCpnt->use_sg = 0;
2240         SCpnt->old_use_sg = 0;
2241         SCpnt->old_cmd_len = 0;
2242         SCpnt->timeout = 0;
2243         SCpnt->underflow = 0;
2244         SCpnt->transfersize = 0;
2245         SCpnt->host_scribble = NULL;
2246         host = SDpnt->host;
2247         if(host->host_queue)
2248             host->host_queue->prev = SCpnt;
2249         SCpnt->next = host->host_queue;
2250         SCpnt->prev = NULL;
2251         host->host_queue = SCpnt;
2252     }
2253     SDpnt->has_cmdblocks = 1;
2254 }
2255 
2256 /*
2257  * scsi_dev_init() is our initialization routine, which in turn calls host
2258  * initialization, bus scanning, and sd/st initialization routines.  It
2259  * should be called from main().
2260  */
2261 
2262 unsigned long scsi_dev_init (unsigned long memory_start, unsigned long memory_end)
     /* [previous][next][first][last][top][bottom][index][help] */
2263 {
2264     struct Scsi_Host * host = NULL;
2265     Scsi_Device * SDpnt;
2266     struct Scsi_Host * shpnt;
2267     struct Scsi_Device_Template * sdtpnt;
2268     int i;
2269 #ifdef FOO_ON_YOU
2270     return;
2271 #endif
2272 
2273     /* Yes we're here... */
2274     dispatch_scsi_info_ptr = dispatch_scsi_info;
2275 
2276     /* Init a few things so we can "malloc" memory. */
2277     scsi_loadable_module_flag = 0;
2278     
2279     /* Align everything on 16-byte boundaries. */
2280     scsi_init_memory_start = (memory_start + 15) & ~ 15;
2281     scsi_memory_lower_value = scsi_init_memory_start;
2282     
2283     timer_table[SCSI_TIMER].fn = scsi_main_timeout;
2284     timer_table[SCSI_TIMER].expires = 0;
2285 
2286     /* initialize all hosts */
2287     scsi_init();
2288 
2289     scsi_devices = (Scsi_Device *) NULL;
2290 
2291     for (shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
2292         scan_scsis(shpnt,0,0,0,0);           /* scan for scsi devices */
2293 
2294     printk("scsi : detected ");
2295     for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2296         if (sdtpnt->dev_noticed && sdtpnt->name)
2297             printk("%d SCSI %s%s ", sdtpnt->dev_noticed, sdtpnt->name,
2298                    (sdtpnt->dev_noticed != 1) ? "s" : "");
2299     printk("total.\n");
2300     
2301     for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2302         if(sdtpnt->init && sdtpnt->dev_noticed) (*sdtpnt->init)();
2303 
2304     for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
2305         SDpnt->scsi_request_fn = NULL;
2306         for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2307             if(sdtpnt->attach) (*sdtpnt->attach)(SDpnt);
2308         if(SDpnt->attached) scsi_build_commandblocks(SDpnt);
2309     }
2310     
2311 
2312     if (scsi_devicelist)
2313         dma_sectors = 16;  /* Base value we use */
2314     
2315     if (memory_end-1 > ISA_DMA_THRESHOLD)
2316         scsi_need_isa_bounce_buffers = 1;
2317     else
2318         scsi_need_isa_bounce_buffers = 0;
2319     
2320     for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
2321         host = SDpnt->host;
2322         
2323         if(SDpnt->type != TYPE_TAPE)
2324             dma_sectors += ((host->sg_tablesize *
2325                              sizeof(struct scatterlist) + 511) >> 9) *
2326                                  host->cmd_per_lun;
2327         
2328         if(host->unchecked_isa_dma &&
2329            memory_end - 1 > ISA_DMA_THRESHOLD &&
2330            SDpnt->type != TYPE_TAPE) {
2331             dma_sectors += (PAGE_SIZE >> 9) * host->sg_tablesize *
2332                 host->cmd_per_lun;
2333             need_isa_buffer++;
2334         }
2335     }
2336     
2337     dma_sectors = (dma_sectors + 15) & 0xfff0;
2338     dma_free_sectors = dma_sectors;  /* This must be a multiple of 16 */
2339     
2340     dma_malloc_freelist = (unsigned char *)
2341         scsi_init_malloc(dma_sectors >> 3, GFP_ATOMIC);
2342     memset(dma_malloc_freelist, 0, dma_sectors >> 3);
2343     
2344     dma_malloc_pages = (unsigned char **)
2345         scsi_init_malloc(dma_sectors >> 1, GFP_ATOMIC);
2346     memset(dma_malloc_pages, 0, dma_sectors >> 1);
2347     
2348     for(i=0; i< dma_sectors >> 3; i++)
2349         dma_malloc_pages[i] = (unsigned char *)
2350             scsi_init_malloc(PAGE_SIZE, GFP_ATOMIC | GFP_DMA);
2351     
2352     /* OK, now we finish the initialization by doing spin-up, read
2353      * capacity, etc, etc 
2354      */
2355     for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2356         if(sdtpnt->finish && sdtpnt->nr_dev)
2357             (*sdtpnt->finish)();
2358     
2359     scsi_loadable_module_flag = 1;
2360     
2361     /* This allocates statically some extra memory to be used for modules,
2362      * until the kmalloc problem is fixed (DB) 
2363      */
2364     
2365 #if defined(USE_STATIC_SCSI_MEMORY)
2366     scsi_memory_upper_value = scsi_init_memory_start + 256 * 1024;
2367     printk ("SCSI memory: total %ldKb, used %ldKb, free %ldKb.\n",
2368             (scsi_memory_upper_value - scsi_memory_lower_value) / 1024,
2369             (scsi_init_memory_start - scsi_memory_lower_value) / 1024,
2370             (scsi_memory_upper_value - scsi_init_memory_start) / 1024);
2371     return scsi_memory_upper_value;
2372 #else
2373     return scsi_init_memory_start;
2374 #endif
2375 }
2376 
2377 static void print_inquiry(unsigned char *data)
     /* [previous][next][first][last][top][bottom][index][help] */
2378 {
2379     int i;
2380     
2381     printk("  Vendor: ");
2382     for (i = 8; i < 16; i++)
2383     {
2384         if (data[i] >= 0x20 && i < data[4] + 5)
2385             printk("%c", data[i]);
2386         else
2387             printk(" ");
2388     }
2389     
2390     printk("  Model: ");
2391     for (i = 16; i < 32; i++)
2392     {
2393         if (data[i] >= 0x20 && i < data[4] + 5)
2394             printk("%c", data[i]);
2395         else
2396             printk(" ");
2397     }
2398     
2399     printk("  Rev: ");
2400     for (i = 32; i < 36; i++)
2401     {
2402         if (data[i] >= 0x20 && i < data[4] + 5)
2403             printk("%c", data[i]);
2404         else
2405             printk(" ");
2406     }
2407     
2408     printk("\n");
2409     
2410     i = data[0] & 0x1f;
2411     
2412     printk("  Type:   %s ",
2413            i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown          " );
2414     printk("                 ANSI SCSI revision: %02x", data[2] & 0x07);
2415     if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
2416         printk(" CCS\n");
2417     else
2418         printk("\n");
2419 }
2420 
2421 
2422 #ifdef CONFIG_PROC_FS
2423 int scsi_proc_info(char *buffer, char **start, off_t offset, int length, 
     /* [previous][next][first][last][top][bottom][index][help] */
2424                     int hostno, int inout)
2425 {
2426     Scsi_Device *scd;
2427     struct Scsi_Host *HBA_ptr;
2428     int  parameter[4];
2429     char *p;
2430 
2431     scd = scsi_devices;
2432     HBA_ptr = scsi_hostlist;
2433 
2434     if(inout == 0)    /* We can only write to this file right now */
2435         return(-ENOSYS);  /* This is still a no-op */
2436 
2437     if(!buffer || length < 25 || strncmp("scsi", buffer, 4))
2438         return(-EINVAL);
2439 
2440     if(!strncmp("singledevice", buffer + 5, 12)) {
2441         p = buffer + 17;
2442 
2443         parameter[0] = simple_strtoul(p , &p, 0);
2444         parameter[1] = simple_strtoul(p , &p, 0);
2445         parameter[2] = simple_strtoul(p , &p, 0);
2446         parameter[3] = simple_strtoul(p , &p, 0);
2447 
2448         while(scd && scd->host->host_no != parameter[0] 
2449               && scd->channel != parameter[1] 
2450               && scd->id != parameter[2] 
2451               && scd->lun != parameter[3]) {
2452             scd = scd->next;
2453         }
2454         if(scd)
2455             return(-ENOSYS);  /* We do not yet support unplugging */
2456         while(HBA_ptr && HBA_ptr->host_no != parameter[0])
2457             HBA_ptr = HBA_ptr->next;
2458 
2459         if(!HBA_ptr)
2460             return(-ENXIO);
2461 
2462         scan_scsis (HBA_ptr, 1, parameter[1], parameter[2], parameter[3]);
2463         return(0);
2464     }
2465     return(-EINVAL);
2466 }
2467 #endif
2468 
2469 
2470 /*
2471  * This entry point should be called by a loadable module if it is trying
2472  * add a low level scsi driver to the system.
2473  */
2474 static int scsi_register_host(Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
2475 {
2476     int pcount;
2477     struct Scsi_Host * shpnt;
2478     struct Scsi_Host * host = NULL;
2479     unsigned long flags;
2480     Scsi_Device * SDpnt;
2481     struct Scsi_Device_Template * sdtpnt;
2482     int i;
2483     const char * name;
2484     
2485     if (tpnt->next || !tpnt->detect) return 1;/* Must be already loaded, or
2486                                                * no detect routine available 
2487                                                */
2488     pcount = next_scsi_host;
2489     if ((tpnt->present = tpnt->detect(tpnt)))
2490     {
2491         if(pcount == next_scsi_host) {
2492             if(tpnt->present > 1) {
2493                 printk("Failure to register low-level scsi driver");
2494                 scsi_unregister_host(tpnt);
2495                 return 1;
2496             }
2497             /* The low-level driver failed to register a driver.  We
2498              *  can do this now. 
2499              */
2500             scsi_register(tpnt,0);
2501         }
2502         tpnt->next = scsi_hosts; /* Add to the linked list */
2503         scsi_hosts = tpnt;
2504         
2505         /* Add the new driver to /proc/scsi */
2506 #if CONFIG_PROC_FS 
2507         build_proc_dir_entries();
2508 #endif
2509         
2510         for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
2511             if(shpnt->hostt == tpnt)
2512             {
2513                 if(tpnt->info)
2514                     name = tpnt->info(shpnt);
2515                 else
2516                     name = tpnt->name;
2517                 printk ("scsi%d : %s\n", /* And print a little message */
2518                         shpnt->host_no, name);
2519             }
2520         
2521         printk ("scsi : %d host%s.\n", next_scsi_host,
2522                 (next_scsi_host == 1) ? "" : "s");
2523         
2524         scsi_make_blocked_list();
2525         
2526         /* The next step is to call scan_scsis here.  This generates the
2527          * Scsi_Devices entries 
2528          */
2529         
2530         for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
2531             if(shpnt->hostt == tpnt) scan_scsis(shpnt,0,0,0,0);
2532         
2533         for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2534             if(sdtpnt->init && sdtpnt->dev_noticed) (*sdtpnt->init)();
2535         
2536         /* Next we create the Scsi_Cmnd structures for this host */
2537         
2538         for(SDpnt = scsi_devices; SDpnt; SDpnt = SDpnt->next)
2539             if(SDpnt->host->hostt == tpnt)
2540             {
2541                 for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2542                     if(sdtpnt->attach) (*sdtpnt->attach)(SDpnt);
2543                 if(SDpnt->attached) scsi_build_commandblocks(SDpnt);
2544             }
2545         
2546         /* Next, check to see if we need to extend the DMA buffer pool */
2547     {
2548         unsigned char * new_dma_malloc_freelist = NULL;
2549         unsigned int new_dma_sectors = 0;
2550         unsigned int new_need_isa_buffer = 0;
2551         unsigned char ** new_dma_malloc_pages = NULL;
2552         
2553         new_dma_sectors = 16;  /* Base value we use */
2554         if (scsi_devicelist)
2555             for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
2556                 new_dma_sectors += 8;  /* Increment for each host */
2557         
2558         for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
2559             host = SDpnt->host;
2560             
2561             if(SDpnt->type != TYPE_TAPE)
2562                 new_dma_sectors += ((host->sg_tablesize *
2563                                      sizeof(struct scatterlist) + 511) >> 9) *
2564                                          host->cmd_per_lun;
2565             
2566             if(host->unchecked_isa_dma &&
2567                scsi_need_isa_bounce_buffers &&
2568                SDpnt->type != TYPE_TAPE) {
2569                 new_dma_sectors += (PAGE_SIZE >> 9) * host->sg_tablesize *
2570                     host->cmd_per_lun;
2571                 new_need_isa_buffer++;
2572             }
2573         }
2574         
2575         new_dma_sectors = (new_dma_sectors + 15) & 0xfff0;
2576         
2577         /*
2578          * We never shrink the buffers - this leads to
2579          * race conditions that I would rather not even think
2580          * about right now.
2581          */
2582         if( new_dma_sectors < dma_sectors )
2583             new_dma_sectors = dma_sectors;
2584         
2585         new_dma_malloc_freelist = (unsigned char *)
2586             scsi_init_malloc(new_dma_sectors >> 3, GFP_ATOMIC);
2587         memset(new_dma_malloc_freelist, 0, new_dma_sectors >> 3);
2588         
2589         new_dma_malloc_pages = (unsigned char **)
2590             scsi_init_malloc(new_dma_sectors >> 1, GFP_ATOMIC);
2591         memset(new_dma_malloc_pages, 0, new_dma_sectors >> 1);
2592         
2593         /*
2594          * If we need more buffers, expand the list.
2595          */
2596         if( new_dma_sectors > dma_sectors ) { 
2597             for(i=dma_sectors >> 3; i< new_dma_sectors >> 3; i++)
2598                 new_dma_malloc_pages[i] = (unsigned char *)
2599               scsi_init_malloc(PAGE_SIZE, GFP_ATOMIC | GFP_DMA);
2600         }
2601         
2602         /* When we dick with the actual DMA list, we need to 
2603          * protect things 
2604          */
2605         save_flags(flags);
2606         cli();
2607         memcpy(new_dma_malloc_freelist, dma_malloc_freelist, dma_sectors >> 3);
2608         scsi_init_free(dma_malloc_freelist, dma_sectors>>3);
2609         dma_malloc_freelist = new_dma_malloc_freelist;
2610         
2611         memcpy(new_dma_malloc_pages, dma_malloc_pages, dma_sectors >> 1);
2612         scsi_init_free((char *) dma_malloc_pages, dma_sectors>>1);
2613         
2614         dma_free_sectors += new_dma_sectors - dma_sectors;
2615         dma_malloc_pages = new_dma_malloc_pages;
2616         dma_sectors = new_dma_sectors;
2617         need_isa_buffer = new_need_isa_buffer;
2618         restore_flags(flags);
2619     }
2620         
2621         /* This does any final handling that is required. */
2622         for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2623             if(sdtpnt->finish && sdtpnt->nr_dev)
2624                 (*sdtpnt->finish)();
2625     }
2626     
2627 #if defined(USE_STATIC_SCSI_MEMORY)
2628     printk ("SCSI memory: total %ldKb, used %ldKb, free %ldKb.\n",
2629             (scsi_memory_upper_value - scsi_memory_lower_value) / 1024,
2630             (scsi_init_memory_start - scsi_memory_lower_value) / 1024,
2631             (scsi_memory_upper_value - scsi_init_memory_start) / 1024);
2632 #endif
2633     
2634     MOD_INC_USE_COUNT;
2635     return 0;
2636 }
2637 
2638 /*
2639  * Similarly, this entry point should be called by a loadable module if it
2640  * is trying to remove a low level scsi driver from the system.
2641  */
2642 static void scsi_unregister_host(Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
2643 {
2644     Scsi_Host_Template * SHT, *SHTp;
2645     Scsi_Device *sdpnt, * sdppnt, * sdpnt1;
2646     Scsi_Cmnd * SCpnt;
2647     unsigned long flags;
2648     struct Scsi_Device_Template * sdtpnt;
2649     struct Scsi_Host * shpnt, *sh1;
2650     int pcount;
2651     
2652     /* First verify that this host adapter is completely free with no pending
2653      * commands */
2654     
2655     for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt->next)
2656         if(sdpnt->host->hostt == tpnt && sdpnt->host->hostt->usage_count
2657            && *sdpnt->host->hostt->usage_count) return;
2658     
2659     for(shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
2660     {
2661         if (shpnt->hostt != tpnt) continue;
2662         for(SCpnt = shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
2663         {
2664             save_flags(flags);
2665             cli();
2666             if(SCpnt->request.dev != -1) {
2667                 restore_flags(flags);
2668                 for(SCpnt = shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
2669                     if(SCpnt->request.dev == 0xffe0) SCpnt->request.dev = -1;
2670                 printk("Device busy???\n");
2671                 return;
2672             }
2673             SCpnt->request.dev = 0xffe0;  /* Mark as busy */
2674             restore_flags(flags);
2675         }
2676     }
2677     /* Next we detach the high level drivers from the Scsi_Device structures */
2678     
2679     for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt->next)
2680         if(sdpnt->host->hostt == tpnt)
2681         {
2682             for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2683                 if(sdtpnt->detach) (*sdtpnt->detach)(sdpnt);
2684             /* If something still attached, punt */
2685             if (sdpnt->attached) {
2686                 printk("Attached usage count = %d\n", sdpnt->attached);
2687                 return;
2688             }
2689         }
2690     
2691     /* Next we free up the Scsi_Cmnd structures for this host */
2692     
2693     for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt->next)
2694         if(sdpnt->host->hostt == tpnt)
2695             while (sdpnt->host->host_queue) {
2696                 SCpnt = sdpnt->host->host_queue->next;
2697                 scsi_init_free((char *) sdpnt->host->host_queue, sizeof(Scsi_Cmnd));
2698                 sdpnt->host->host_queue = SCpnt;
2699                 if (SCpnt) SCpnt->prev = NULL;
2700                 sdpnt->has_cmdblocks = 0;
2701             }
2702     
2703     /* Next free up the Scsi_Device structures for this host */
2704     
2705     sdppnt = NULL;
2706     for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt1)
2707     {
2708         sdpnt1 = sdpnt->next;
2709         if (sdpnt->host->hostt == tpnt) {
2710             if (sdppnt)
2711                 sdppnt->next = sdpnt->next;
2712             else
2713                 scsi_devices = sdpnt->next;
2714             scsi_init_free((char *) sdpnt, sizeof (Scsi_Device));
2715         } else
2716             sdppnt = sdpnt;
2717     }
2718     
2719     /* Next we go through and remove the instances of the individual hosts
2720      * that were detected */
2721     
2722     shpnt = scsi_hostlist;
2723     while(shpnt) {
2724         sh1 = shpnt->next;
2725         if(shpnt->hostt == tpnt) {
2726             if(shpnt->loaded_as_module) {
2727                 pcount = next_scsi_host;
2728                 if(tpnt->release)
2729                     (*tpnt->release)(shpnt);
2730                 else {
2731                     /* This is the default case for the release function.  
2732                      * It should do the right thing for most correctly 
2733                      * written host adapters. 
2734                      */
2735                     if (shpnt->irq) free_irq(shpnt->irq);
2736                     if (shpnt->dma_channel != 0xff) free_dma(shpnt->dma_channel);
2737                     if (shpnt->io_port && shpnt->n_io_port)
2738                         release_region(shpnt->io_port, shpnt->n_io_port);
2739                 }
2740                 if(pcount == next_scsi_host) scsi_unregister(shpnt);
2741                 tpnt->present--;
2742             }
2743         }
2744         shpnt = sh1;
2745     }
2746     
2747     printk ("scsi : %d host%s.\n", next_scsi_host,
2748             (next_scsi_host == 1) ? "" : "s");
2749     
2750 #if defined(USE_STATIC_SCSI_MEMORY)
2751     printk ("SCSI memory: total %ldKb, used %ldKb, free %ldKb.\n",
2752             (scsi_memory_upper_value - scsi_memory_lower_value) / 1024,
2753             (scsi_init_memory_start - scsi_memory_lower_value) / 1024,
2754             (scsi_memory_upper_value - scsi_init_memory_start) / 1024);
2755 #endif
2756     
2757     scsi_make_blocked_list();
2758     
2759     /* There were some hosts that were loaded at boot time, so we cannot
2760        do any more than this */
2761     if (tpnt->present) return;
2762     
2763     /* OK, this is the very last step.  Remove this host adapter from the
2764        linked list. */
2765     for(SHTp=NULL, SHT=scsi_hosts; SHT; SHTp=SHT, SHT=SHT->next)
2766         if(SHT == tpnt) {
2767             if(SHTp)
2768                 SHTp->next = SHT->next;
2769             else
2770                 scsi_hosts = SHT->next;
2771             SHT->next = NULL;
2772             break;
2773         }
2774     
2775     /* Rebuild the /proc/scsi directory entries */
2776 #if CONFIG_PROC_FS 
2777     build_proc_dir_entries();
2778 #endif
2779     MOD_DEC_USE_COUNT;
2780 }
2781 
2782 /*
2783  * This entry point should be called by a loadable module if it is trying
2784  * add a high level scsi driver to the system.
2785  */
2786 static int scsi_register_device_module(struct Scsi_Device_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
2787 {
2788     Scsi_Device * SDpnt;
2789     
2790     if (tpnt->next) return 1;
2791     
2792     scsi_register_device(tpnt);
2793     /*
2794      * First scan the devices that we know about, and see if we notice them.
2795      */
2796     
2797     for(SDpnt = scsi_devices; SDpnt; SDpnt = SDpnt->next)
2798         if(tpnt->detect) SDpnt->attached += (*tpnt->detect)(SDpnt);
2799     
2800     /*
2801      * If any of the devices would match this driver, then perform the
2802      * init function.
2803      */
2804     if(tpnt->init && tpnt->dev_noticed) (*tpnt->init)();
2805     
2806     /*
2807      * Now actually connect the devices to the new driver.
2808      */
2809     for(SDpnt = scsi_devices; SDpnt; SDpnt = SDpnt->next)
2810     {
2811         if(tpnt->attach)  (*tpnt->attach)(SDpnt);
2812         /*
2813          * If this driver attached to the device, and we no longer
2814          * have anything attached, release the scso command blocks.
2815          */
2816         if(SDpnt->attached && SDpnt->has_cmdblocks == 0)
2817             scsi_build_commandblocks(SDpnt);
2818     }
2819     
2820     /*
2821      * This does any final handling that is required. 
2822      */
2823     if(tpnt->finish && tpnt->nr_dev)  (*tpnt->finish)();
2824     MOD_INC_USE_COUNT;
2825     return 0;
2826 }
2827 
2828 static int scsi_unregister_device(struct Scsi_Device_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
2829 {
2830     Scsi_Device * SDpnt;
2831     Scsi_Cmnd * SCpnt;
2832     struct Scsi_Device_Template * spnt;
2833     struct Scsi_Device_Template * prev_spnt;
2834     
2835     /*
2836      * If we are busy, this is not going to fly.
2837      */
2838     if( *tpnt->usage_count != 0) return 0;
2839     /*
2840      * Next, detach the devices from the driver.
2841      */
2842     
2843     for(SDpnt = scsi_devices; SDpnt; SDpnt = SDpnt->next)
2844     {
2845         if(tpnt->detach) (*tpnt->detach)(SDpnt);
2846         if(SDpnt->attached == 0)
2847         {
2848             /*
2849              * Nobody is using this device any more.  Free all of the
2850              * command structures.
2851              */
2852             for(SCpnt = SDpnt->host->host_queue; SCpnt; SCpnt = SCpnt->next)
2853             {
2854                 if(SCpnt->device == SDpnt)
2855                 {
2856                     if(SCpnt->prev != NULL)
2857                         SCpnt->prev->next = SCpnt->next;
2858                     if(SCpnt->next != NULL)
2859                         SCpnt->next->prev = SCpnt->prev;
2860                     if(SCpnt == SDpnt->host->host_queue)
2861                         SDpnt->host->host_queue = SCpnt->next;
2862                     scsi_init_free((char *) SCpnt, sizeof(*SCpnt));
2863                 }
2864             }
2865             SDpnt->has_cmdblocks = 0;
2866         }
2867     }
2868     /*
2869      * Extract the template from the linked list.
2870      */
2871     spnt = scsi_devicelist;
2872     prev_spnt = NULL;
2873     while(spnt != tpnt)
2874     {
2875         prev_spnt = spnt;
2876         spnt = spnt->next;
2877     }
2878     if(prev_spnt == NULL)
2879         scsi_devicelist = tpnt->next;
2880     else
2881         prev_spnt->next = spnt->next;
2882     
2883     MOD_DEC_USE_COUNT;
2884     /*
2885      * Final cleanup for the driver is done in the driver sources in the 
2886      * cleanup function.
2887      */
2888     return 0;
2889 }
2890 
2891 
2892 int scsi_register_module(int module_type, void * ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
2893 {
2894     switch(module_type){
2895     case MODULE_SCSI_HA:
2896         return scsi_register_host((Scsi_Host_Template *) ptr);
2897         
2898         /* Load upper level device handler of some kind */
2899     case MODULE_SCSI_DEV:
2900         return scsi_register_device_module((struct Scsi_Device_Template *) ptr);
2901         /* The rest of these are not yet implemented */
2902         
2903         /* Load constants.o */
2904     case MODULE_SCSI_CONST:
2905         
2906         /* Load specialized ioctl handler for some device.  Intended for 
2907          * cdroms that have non-SCSI2 audio command sets. */
2908     case MODULE_SCSI_IOCTL:
2909         
2910     default:
2911         return 1;
2912     }
2913 }
2914 
2915 void scsi_unregister_module(int module_type, void * ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
2916 {
2917     switch(module_type) {
2918     case MODULE_SCSI_HA:
2919         scsi_unregister_host((Scsi_Host_Template *) ptr);
2920         break;
2921     case MODULE_SCSI_DEV:
2922         scsi_unregister_device((struct Scsi_Device_Template *) ptr);
2923         break;
2924         /* The rest of these are not yet implemented. */
2925     case MODULE_SCSI_CONST:
2926     case MODULE_SCSI_IOCTL:
2927         break;
2928     default:
2929     }
2930     return;
2931 }
2932 
2933 #ifdef DEBUG_TIMEOUT
2934 static void
2935 scsi_dump_status(void)
     /* [previous][next][first][last][top][bottom][index][help] */
2936 {
2937     int i;
2938     struct Scsi_Host * shpnt;
2939     Scsi_Cmnd * SCpnt;
2940     printk("Dump of scsi parameters:\n");
2941     i = 0;
2942     for(shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
2943         for(SCpnt=shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
2944         {
2945             /*  (0) 0:0:0:0 (802 123434 8 8 0) (3 3 2) (%d %d %d) %d %x      */
2946             printk("(%d) %d:%d:%d:%d (%4.4x %ld %ld %ld %ld) (%d %d %x) (%d %d %d) %x %x %x\n",
2947                    i++, SCpnt->host->host_no,
2948                    SCpnt->channel,
2949                    SCpnt->target,
2950                    SCpnt->lun,
2951                    SCpnt->request.dev,
2952                    SCpnt->request.sector,
2953                    SCpnt->request.nr_sectors,
2954                    SCpnt->request.current_nr_sectors,
2955                    SCpnt->use_sg,
2956                    SCpnt->retries,
2957                    SCpnt->allowed,
2958                    SCpnt->flags,
2959                    SCpnt->timeout_per_command,
2960                    SCpnt->timeout,
2961                    SCpnt->internal_timeout,
2962                    SCpnt->cmnd[0],
2963                    SCpnt->sense_buffer[2],
2964                    SCpnt->result);
2965         }
2966     printk("wait_for_request = %p\n", wait_for_request);
2967     /* Now dump the request lists for each block device */
2968     printk("Dump of pending block device requests\n");
2969     for(i=0; i<MAX_BLKDEV; i++)
2970         if(blk_dev[i].current_request)
2971         {
2972             struct request * req;
2973             printk("%d: ", i);
2974             req = blk_dev[i].current_request;
2975             while(req) {
2976                 printk("(%x %d %ld %ld %ld) ",
2977                        req->dev,
2978                        req->cmd,
2979                        req->sector,
2980                        req->nr_sectors,
2981                        req->current_nr_sectors);
2982                 req = req->next;
2983             }
2984             printk("\n");
2985         }
2986 }
2987 #endif
2988 
2989 #ifdef MODULE
2990 
2991 
2992 char kernel_version[] = UTS_RELEASE;
2993 
2994 extern struct symbol_table scsi_symbol_table;
2995 
2996 int init_module(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
2997 
2998 #if CONFIG_PROC_FS 
2999     /*
3000      * This will initialize the directory so that we do not have
3001      * random crap in there.
3002      */
3003     build_proc_dir_entries();
3004 #endif
3005 
3006     /*
3007      * This makes the real /proc/scsi visible.
3008      */
3009     dispatch_scsi_info_ptr = dispatch_scsi_info;
3010 
3011     timer_table[SCSI_TIMER].fn = scsi_main_timeout;
3012     timer_table[SCSI_TIMER].expires = 0;
3013     register_symtab(&scsi_symbol_table);
3014     scsi_loadable_module_flag = 1;
3015     
3016     dma_sectors = PAGE_SIZE / 512;
3017     /*
3018      * Set up a minimal DMA buffer list - this will be used during scan_scsis
3019      * in some cases.
3020      */
3021     
3022     /* One bit per sector to indicate free/busy */
3023     dma_malloc_freelist = (unsigned char *)
3024         scsi_init_malloc(dma_sectors >> 3, GFP_ATOMIC);
3025     memset(dma_malloc_freelist, 0, dma_sectors >> 3);
3026     
3027     /* One pointer per page for the page list */
3028     dma_malloc_pages = (unsigned char **)
3029         scsi_init_malloc(dma_sectors >> 1, GFP_ATOMIC);
3030     dma_malloc_pages[0] = (unsigned char *)
3031         scsi_init_malloc(PAGE_SIZE, GFP_ATOMIC | GFP_DMA);
3032     return 0;
3033 }
3034 
3035 void cleanup_module( void) 
     /* [previous][next][first][last][top][bottom][index][help] */
3036 {
3037     int i;
3038     
3039     if (MOD_IN_USE) {
3040         printk(KERN_INFO __FILE__ ": module is in use, remove rejected\n");
3041         return;
3042     }
3043     
3044     /* No, we're not here anymore. Don't show the /proc/scsi files. */
3045     dispatch_scsi_info_ptr = 0L;
3046 
3047     /*
3048      * Free up the DMA pool.
3049      */
3050     for(i=0; i < dma_sectors >> 3; i++)
3051         scsi_init_free(dma_malloc_pages[i], PAGE_SIZE);
3052     scsi_init_free((char *) dma_malloc_pages, dma_sectors>>1);
3053     scsi_init_free(dma_malloc_freelist, dma_sectors>>3);
3054     
3055     timer_table[SCSI_TIMER].fn = NULL;
3056     timer_table[SCSI_TIMER].expires = 0;
3057     /*
3058      * Supposedly you just do this, and the last symtab registered will
3059      * be removed.  If someone else registered a symtab, this could
3060      * blow up in our faces.  FIXME.
3061      */
3062     register_symtab(0);
3063 }
3064 #endif /* MODULE */
3065 
3066 /*
3067  * Overrides for Emacs so that we follow Linus's tabbing style.
3068  * Emacs will notice this stuff at the end of the file and automatically
3069  * adjust the settings for this buffer only.  This must remain at the end
3070  * of the file.
3071  * ---------------------------------------------------------------------------
3072  * Local variables:
3073  * c-indent-level: 4
3074  * c-brace-imaginary-offset: 0
3075  * c-brace-offset: -4
3076  * c-argdecl-indent: 4
3077  * c-label-offset: -4
3078  * c-continued-statement-offset: 4
3079  * c-continued-brace-offset: 0
3080  * indent-tabs-mode: nil
3081  * tab-width: 8
3082  * End:
3083  */

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