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

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