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

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