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

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