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

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