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

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