root/drivers/scsi/hosts.c

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

DEFINITIONS

This source file includes following definitions.
  1. scsi_unregister
  2. scsi_register
  3. scsi_register_device
  4. scsi_init

   1 /*
   2  *  hosts.c Copyright (C) 1992 Drew Eckhardt
   3  *          Copyright (C) 1993, 1994, 1995 Eric Youngdale
   4  *
   5  *  mid to lowlevel SCSI driver interface
   6  *      Initial versions: Drew Eckhardt
   7  *      Subsequent revisions: Eric Youngdale
   8  *
   9  *  <drew@colorado.edu>
  10  */
  11 
  12 
  13 /*
  14  *  This file contains the medium level SCSI
  15  *  host interface initialization, as well as the scsi_hosts array of SCSI
  16  *  hosts currently present in the system.
  17  */
  18 
  19 /*
  20  * Don't import our own symbols, as this would severely mess up our
  21  * symbol tables.
  22  */
  23 #define _SCSI_SYMS_VER_
  24 #define __NO_VERSION__
  25 #include <linux/module.h>
  26 
  27 #include <linux/config.h>
  28 #include <linux/blk.h>
  29 #include <linux/kernel.h>
  30 #include <linux/string.h>
  31 #include <linux/mm.h>
  32 #include <linux/proc_fs.h>
  33 
  34 #include "scsi.h"
  35 
  36 #ifndef NULL
  37 #define NULL 0L
  38 #endif
  39 
  40 #define HOSTS_C
  41 
  42 #include "hosts.h"
  43 
  44 #ifdef CONFIG_A3000_SCSI
  45 #include "a3000.h"
  46 #endif
  47 
  48 #ifdef CONFIG_A2091_SCSI
  49 #include "a2091.h"
  50 #endif
  51 
  52 #ifdef CONFIG_GVP11_SCSI
  53 #include "gvp11.h"
  54 #endif
  55 
  56 #ifdef CONFIG_ATARI_SCSI
  57 #include "atari_scsi.h"
  58 #endif
  59 
  60 #ifdef CONFIG_SCSI_ADVANSYS
  61 #include "advansys.h"
  62 #endif
  63 
  64 #ifdef CONFIG_SCSI_AHA152X
  65 #include "aha152x.h"
  66 #endif
  67 
  68 #ifdef CONFIG_SCSI_AHA1542
  69 #include "aha1542.h"
  70 #endif
  71 
  72 #ifdef CONFIG_SCSI_AHA1740
  73 #include "aha1740.h"
  74 #endif
  75 
  76 #ifdef CONFIG_SCSI_AIC7XXX
  77 #include "aic7xxx.h"
  78 #endif
  79 
  80 #ifdef CONFIG_SCSI_BUSLOGIC
  81 #include "BusLogic.h"
  82 #endif
  83 
  84 #ifdef CONFIG_SCSI_EATA_DMA
  85 #include "eata_dma.h"
  86 #endif
  87 
  88 #ifdef CONFIG_SCSI_EATA_PIO
  89 #include "eata_pio.h"
  90 #endif
  91 
  92 #ifdef CONFIG_SCSI_U14_34F
  93 #include "u14-34f.h"
  94 #endif
  95 
  96 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
  97 #include "fdomain.h"
  98 #endif
  99 
 100 #ifdef CONFIG_SCSI_GENERIC_NCR5380
 101 #include "g_NCR5380.h"
 102 #endif
 103 
 104 #ifdef CONFIG_SCSI_IN2000
 105 #include "in2000.h"
 106 #endif
 107 
 108 #ifdef CONFIG_SCSI_PAS16
 109 #include "pas16.h"
 110 #endif
 111 
 112 #ifdef CONFIG_SCSI_QLOGIC
 113 #include "qlogic.h"
 114 #endif
 115 
 116 #ifdef CONFIG_SCSI_SEAGATE
 117 #include "seagate.h"
 118 #endif
 119 
 120 #ifdef CONFIG_SCSI_T128
 121 #include "t128.h"
 122 #endif
 123 
 124 #ifdef CONFIG_SCSI_DTC3280
 125 #include "dtc.h"
 126 #endif
 127 
 128 #ifdef CONFIG_SCSI_NCR53C7xx
 129 #include "53c7,8xx.h"
 130 #endif
 131 
 132 #ifdef CONFIG_SCSI_ULTRASTOR
 133 #include "ultrastor.h"
 134 #endif
 135 
 136 #ifdef CONFIG_SCSI_7000FASST
 137 #include "wd7000.h"
 138 #endif
 139 
 140 #ifdef CONFIG_SCSI_EATA
 141 #include "eata.h"
 142 #endif
 143 
 144 #ifdef CONFIG_SCSI_NCR53C406A
 145 #include "NCR53c406a.h"
 146 #endif
 147 
 148 #ifdef CONFIG_SCSI_AM53C974
 149 #include "AM53C974.h"
 150 #endif
 151 
 152 #ifdef CONFIG_SCSI_PPA
 153 #include "ppa.h"
 154 #endif
 155 
 156 #ifdef CONFIG_SCSI_SUNESP
 157 #include "esp.h"
 158 #endif
 159 
 160 #ifdef CONFIG_SCSI_DEBUG
 161 #include "scsi_debug.h"
 162 #endif
 163 
 164 
 165 /*
 166 static const char RCSid[] = "$Header: /usr/src/linux-1.3.95/drivers/scsi/RCS/hosts.c,v 1.7 1996/04/25 22:21:56 root Exp root $";
 167 */
 168 
 169 /*
 170  *  The scsi host entries should be in the order you wish the
 171  *  cards to be detected.  A driver may appear more than once IFF
 172  *  it can deal with being detected (and therefore initialized)
 173  *  with more than one simultaneous host number, can handle being
 174  *  reentrant, etc.
 175  *
 176  *  They may appear in any order, as each SCSI host is told which host 
 177  *  number it is during detection.
 178  */
 179 
 180 /* This is a placeholder for controllers that are not configured into
 181  * the system - we do this to ensure that the controller numbering is
 182  * always consistent, no matter how the kernel is configured. */
 183 
 184 #define NO_CONTROLLER {NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
 185                            NULL, NULL, 0, 0, 0, 0, 0, 0}
 186 
 187 /*
 188  *  When figure is run, we don't want to link to any object code.  Since
 189  *  the macro for each host will contain function pointers, we cannot
 190  *  use it and instead must use a "blank" that does no such
 191  *  idiocy.
 192  */
 193 
 194 Scsi_Host_Template * scsi_hosts = NULL;
 195 
 196 static Scsi_Host_Template builtin_scsi_hosts[] =
 197 {
 198 #ifdef CONFIG_AMIGA
 199 #ifdef CONFIG_A3000_SCSI
 200         A3000_SCSI,
 201 #endif
 202 #ifdef CONFIG_A2091_SCSI
 203         A2091_SCSI,
 204 #endif
 205 #ifdef CONFIG_GVP11_SCSI
 206         GVP11_SCSI,
 207 #endif
 208 #endif
 209 
 210 #ifdef CONFIG_ATARI
 211 #ifdef CONFIG_ATARI_SCSI
 212         ATARI_SCSI,
 213 #endif
 214 #endif
 215 
 216 #ifdef CONFIG_SCSI_ADVANSYS
 217         ADVANSYS,
 218 #endif
 219 /* BusLogic must come before aha1542.c */
 220 #ifdef CONFIG_SCSI_BUSLOGIC
 221     BUSLOGIC,
 222 #endif
 223 #ifdef CONFIG_SCSI_U14_34F
 224     ULTRASTOR_14_34F,
 225 #endif
 226 #ifdef CONFIG_SCSI_ULTRASTOR
 227     ULTRASTOR_14F,
 228 #endif
 229 #ifdef CONFIG_SCSI_AHA152X
 230     AHA152X,
 231 #endif
 232 #ifdef CONFIG_SCSI_AHA1542
 233     AHA1542,
 234 #endif
 235 #ifdef CONFIG_SCSI_AHA1740
 236     AHA1740,
 237 #endif
 238 #ifdef CONFIG_SCSI_AIC7XXX
 239     AIC7XXX,
 240 #endif
 241 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
 242     FDOMAIN_16X0,
 243 #endif
 244 #ifdef CONFIG_SCSI_IN2000
 245     IN2000,
 246 #endif
 247 #ifdef CONFIG_SCSI_GENERIC_NCR5380
 248     GENERIC_NCR5380,
 249 #endif
 250 #ifdef CONFIG_SCSI_NCR53C406A   /* 53C406A should come before QLOGIC */
 251     NCR53c406a,
 252 #endif
 253 #ifdef CONFIG_SCSI_QLOGIC
 254     QLOGIC,
 255 #endif
 256 #ifdef CONFIG_SCSI_PAS16
 257     MV_PAS16,
 258 #endif
 259 #ifdef CONFIG_SCSI_SEAGATE
 260     SEAGATE_ST0X,
 261 #endif
 262 #ifdef CONFIG_SCSI_T128
 263     TRANTOR_T128,
 264 #endif
 265 #ifdef CONFIG_SCSI_DTC3280
 266         DTC3x80,
 267 #endif
 268 #ifdef CONFIG_SCSI_NCR53C7xx
 269     NCR53c7xx,
 270 #endif
 271 #ifdef CONFIG_SCSI_EATA_DMA
 272     EATA_DMA,
 273 #endif
 274 #ifdef CONFIG_SCSI_EATA_PIO
 275     EATA_PIO,
 276 #endif
 277 #ifdef CONFIG_SCSI_7000FASST
 278     WD7000,
 279 #endif
 280 #ifdef CONFIG_SCSI_EATA
 281     EATA,
 282 #endif
 283 #ifdef CONFIG_SCSI_AM53C974
 284     AM53C974,
 285 #endif
 286 #ifdef CONFIG_SCSI_PPA
 287     PPA,
 288 #endif
 289 #ifdef CONFIG_SCSI_SUNESP
 290     SCSI_SPARC_ESP,
 291 #endif
 292 #ifdef CONFIG_SCSI_DEBUG
 293     SCSI_DEBUG,
 294 #endif
 295 };
 296 
 297 #define MAX_SCSI_HOSTS (sizeof(builtin_scsi_hosts) / sizeof(Scsi_Host_Template))
 298 
 299 
 300 /*
 301  *  Our semaphores and timeout counters, where size depends on 
 302  *      MAX_SCSI_HOSTS here.
 303  */
 304 
 305 struct Scsi_Host * scsi_hostlist = NULL;
 306 struct Scsi_Device_Template * scsi_devicelist = NULL;
 307 
 308 int max_scsi_hosts = 0;
 309 int next_scsi_host = 0;
 310 
 311 void
 312 scsi_unregister(struct Scsi_Host * sh){
     /* [previous][next][first][last][top][bottom][index][help] */
 313     struct Scsi_Host * shpnt;
 314     
 315     if(scsi_hostlist == sh)
 316         scsi_hostlist = sh->next;
 317     else {
 318         shpnt = scsi_hostlist;
 319         while(shpnt->next != sh) shpnt = shpnt->next;
 320         shpnt->next = shpnt->next->next;
 321     }
 322     
 323     /* If we are removing the last host registered, it is safe to reuse
 324      * its host number (this avoids "holes" at boot time) (DB) 
 325      */
 326     if (max_scsi_hosts == next_scsi_host && !scsi_loadable_module_flag)
 327         max_scsi_hosts--;
 328     
 329     next_scsi_host--;
 330     scsi_init_free((char *) sh, sizeof(struct Scsi_Host) + sh->extra_bytes);
 331 }
 332 
 333 /* We call this when we come across a new host adapter. We only do this
 334  * once we are 100% sure that we want to use this host adapter -  it is a
 335  * pain to reverse this, so we try and avoid it 
 336  */
 337 
 338 struct Scsi_Host * scsi_register(Scsi_Host_Template * tpnt, int j){
     /* [previous][next][first][last][top][bottom][index][help] */
 339     struct Scsi_Host * retval, *shpnt;
 340     retval = (struct Scsi_Host *)scsi_init_malloc(sizeof(struct Scsi_Host) + j,
 341                                                   (tpnt->unchecked_isa_dma && j ? GFP_DMA : 0) | GFP_ATOMIC);
 342     retval->host_busy = 0;
 343     retval->block = NULL;
 344     retval->wish_block = 0;
 345     if(j > 0xffff) panic("Too many extra bytes requested\n");
 346     retval->extra_bytes = j;
 347     retval->loaded_as_module = scsi_loadable_module_flag;
 348     retval->host_no = max_scsi_hosts++; /* never reuse host_no (DB) */
 349     next_scsi_host++;
 350     retval->host_queue = NULL;
 351     retval->host_wait = NULL;
 352     retval->last_reset = 0;
 353     retval->irq = 0;
 354     retval->dma_channel = 0xff;
 355 
 356     /* These three are default values which can be overridden */
 357     retval->max_channel = 0; 
 358     retval->max_id = 8;      
 359     retval->max_lun = 8;
 360 
 361     retval->unique_id = 0;
 362     retval->io_port = 0;
 363     retval->hostt = tpnt;
 364     retval->next = NULL;
 365 #ifdef DEBUG
 366     printk("Register %x %x: %d\n", (int)retval, (int)retval->hostt, j);
 367 #endif
 368 
 369     /* The next six are the default values which can be overridden
 370      * if need be */
 371     retval->this_id = tpnt->this_id;
 372     retval->can_queue = tpnt->can_queue;
 373     retval->sg_tablesize = tpnt->sg_tablesize;
 374     retval->cmd_per_lun = tpnt->cmd_per_lun;
 375     retval->unchecked_isa_dma = tpnt->unchecked_isa_dma;
 376     retval->use_clustering = tpnt->use_clustering;   
 377 
 378     retval->select_queue_depths = NULL;
 379 
 380     if(!scsi_hostlist)
 381         scsi_hostlist = retval;
 382     else
 383     {
 384         shpnt = scsi_hostlist;
 385         while(shpnt->next) shpnt = shpnt->next;
 386         shpnt->next = retval;
 387     }
 388     
 389     return retval;
 390 }
 391 
 392 int
 393 scsi_register_device(struct Scsi_Device_Template * sdpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 394 {
 395     if(sdpnt->next) panic("Device already registered");
 396     sdpnt->next = scsi_devicelist;
 397     scsi_devicelist = sdpnt;
 398     return 0;
 399 }
 400 
 401 unsigned int scsi_init()
     /* [previous][next][first][last][top][bottom][index][help] */
 402 {
 403     static int called = 0;
 404     int i, pcount;
 405     Scsi_Host_Template * tpnt;
 406     struct Scsi_Host * shpnt;
 407     const char * name;
 408     
 409     if(called) return 0;
 410     
 411     called = 1;
 412     for (tpnt = &builtin_scsi_hosts[0], i = 0; i < MAX_SCSI_HOSTS; ++i, tpnt++)
 413     {
 414         /*
 415          * Initialize our semaphores.  -1 is interpreted to mean
 416          * "inactive" - where as 0 will indicate a time out condition.
 417          */
 418         
 419         pcount = next_scsi_host;
 420         if ((tpnt->detect) &&
 421             (tpnt->present =
 422              tpnt->detect(tpnt)))
 423         {
 424             /* The only time this should come up is when people use
 425              * some kind of patched driver of some kind or another. */
 426             if(pcount == next_scsi_host) {
 427                 if(tpnt->present > 1)
 428                     panic("Failure to register low-level scsi driver");
 429                 /* The low-level driver failed to register a driver.  We
 430                  * can do this now. */
 431                 scsi_register(tpnt,0);
 432             }
 433             tpnt->next = scsi_hosts;
 434             scsi_hosts = tpnt;
 435 
 436             /* Add the driver to /proc/scsi */
 437 #if CONFIG_PROC_FS 
 438             build_proc_dir_entries(tpnt);    
 439 #endif
 440         }
 441     }
 442         
 443     for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
 444     {
 445         if(shpnt->hostt->info)
 446             name = shpnt->hostt->info(shpnt);
 447         else
 448             name = shpnt->hostt->name;
 449         printk ("scsi%d : %s\n", /* And print a little message */
 450                 shpnt->host_no, name);
 451     }
 452     
 453     printk ("scsi : %d host%s.\n", next_scsi_host,
 454             (next_scsi_host == 1) ? "" : "s");
 455     
 456     scsi_make_blocked_list();
 457     
 458     /* Now attach the high level drivers */
 459 #ifdef CONFIG_BLK_DEV_SD
 460     scsi_register_device(&sd_template);
 461 #endif
 462 #ifdef CONFIG_BLK_DEV_SR
 463     scsi_register_device(&sr_template);
 464 #endif
 465 #ifdef CONFIG_CHR_DEV_ST
 466     scsi_register_device(&st_template);
 467 #endif
 468 #ifdef CONFIG_CHR_DEV_SG
 469     scsi_register_device(&sg_template);
 470 #endif
 471     
 472 #if 0      
 473     max_scsi_hosts = next_scsi_host;
 474 #endif
 475     return 0;
 476 }
 477 
 478 /*
 479  * Overrides for Emacs so that we follow Linus's tabbing style.
 480  * Emacs will notice this stuff at the end of the file and automatically
 481  * adjust the settings for this buffer only.  This must remain at the end
 482  * of the file.
 483  * ---------------------------------------------------------------------------
 484  * Local variables:
 485  * c-indent-level: 4
 486  * c-brace-imaginary-offset: 0
 487  * c-brace-offset: -4
 488  * c-argdecl-indent: 4
 489  * c-label-offset: -4
 490  * c-continued-statement-offset: 4
 491  * c-continued-brace-offset: 0
 492  * indent-tabs-mode: nil
 493  * tab-width: 8
 494  * End:
 495  */

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