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

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