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->unique_id = 0;
 291     retval->io_port = 0;
 292     retval->forbidden_addr = 0;
 293     retval->forbidden_size = 0;
 294     retval->hostt = tpnt;
 295     retval->next = NULL;
 296 #ifdef DEBUG
 297     printk("Register %x %x: %d\n", (int)retval, (int)retval->hostt, j);
 298 #endif
 299 
 300     /* The next six are the default values which can be overridden
 301      * if need be */
 302     retval->this_id = tpnt->this_id;
 303     retval->can_queue = tpnt->can_queue;
 304     retval->sg_tablesize = tpnt->sg_tablesize;
 305     retval->cmd_per_lun = tpnt->cmd_per_lun;
 306     retval->unchecked_isa_dma = tpnt->unchecked_isa_dma;
 307     retval->use_clustering = tpnt->use_clustering;   
 308     if(!scsi_hostlist)
 309         scsi_hostlist = retval;
 310     else
 311     {
 312         shpnt = scsi_hostlist;
 313         while(shpnt->next) shpnt = shpnt->next;
 314         shpnt->next = retval;
 315     }
 316     
 317     return retval;
 318 }
 319 
 320 int
 321 scsi_register_device(struct Scsi_Device_Template * sdpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 322 {
 323     if(sdpnt->next) panic("Device already registered");
 324     sdpnt->next = scsi_devicelist;
 325     scsi_devicelist = sdpnt;
 326     return 0;
 327 }
 328 
 329 unsigned int scsi_init()
     /* [previous][next][first][last][top][bottom][index][help] */
 330 {
 331     static int called = 0;
 332     int i, pcount;
 333     Scsi_Host_Template * tpnt;
 334     struct Scsi_Host * shpnt;
 335     const char * name;
 336     
 337     if(called) return 0;
 338     
 339     called = 1;
 340     for (tpnt = &builtin_scsi_hosts[0], i = 0; i < MAX_SCSI_HOSTS; ++i, tpnt++)
 341     {
 342         /*
 343          * Initialize our semaphores.  -1 is interpreted to mean
 344          * "inactive" - where as 0 will indicate a time out condition.
 345          */
 346         
 347         pcount = next_scsi_host;
 348         if ((tpnt->detect) &&
 349             (tpnt->present =
 350              tpnt->detect(tpnt)))
 351         {
 352             /* The only time this should come up is when people use
 353              * some kind of patched driver of some kind or another. */
 354             if(pcount == next_scsi_host) {
 355                 if(tpnt->present > 1)
 356                     panic("Failure to register low-level scsi driver");
 357                 /* The low-level driver failed to register a driver.  We
 358                  * can do this now. */
 359                 scsi_register(tpnt,0);
 360             }
 361             tpnt->next = scsi_hosts;
 362             scsi_hosts = tpnt;
 363         }
 364     }
 365     
 366     /* Add the drivers to /proc/scsi */
 367 #if CONFIG_PROC_FS 
 368     build_proc_dir_entries();    
 369 #endif
 370     
 371     for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
 372     {
 373         if(shpnt->hostt->info)
 374             name = shpnt->hostt->info(shpnt);
 375         else
 376             name = shpnt->hostt->name;
 377         printk ("scsi%d : %s\n", /* And print a little message */
 378                 shpnt->host_no, name);
 379     }
 380     
 381     printk ("scsi : %d host%s.\n", next_scsi_host,
 382             (next_scsi_host == 1) ? "" : "s");
 383     
 384     scsi_make_blocked_list();
 385     
 386     /* Now attach the high level drivers */
 387 #ifdef CONFIG_BLK_DEV_SD
 388     scsi_register_device(&sd_template);
 389 #endif
 390 #ifdef CONFIG_BLK_DEV_SR
 391     scsi_register_device(&sr_template);
 392 #endif
 393 #ifdef CONFIG_CHR_DEV_ST
 394     scsi_register_device(&st_template);
 395 #endif
 396 #ifdef CONFIG_CHR_DEV_SG
 397     scsi_register_device(&sg_template);
 398 #endif
 399     
 400 #if 0      
 401     max_scsi_hosts = next_scsi_host;
 402 #endif
 403     return 0;
 404 }
 405 
 406 
 407 void scsi_mem_init(unsigned long memory_end)
     /* [previous][next][first][last][top][bottom][index][help] */
 408 {
 409     struct Scsi_Host *Host;
 410     long High8, Low24;
 411     for (Host = scsi_hostlist; Host != NULL; Host = Host->next) {
 412         if (Host->forbidden_addr > 0 && Host->forbidden_size > 0) {
 413             for (High8 = 1<<24; High8 < memory_end; High8 += 1<<24) {
 414                 for (Low24 = Host->forbidden_addr;
 415                      Low24 < Host->forbidden_addr + Host->forbidden_size;
 416                      Low24 += PAGE_SIZE) {
 417                     unsigned long ForbiddenAddress = High8 + Low24;
 418                     if (ForbiddenAddress >= memory_end) goto next_host;
 419                     mem_map[MAP_NR(ForbiddenAddress)] = MAP_PAGE_RESERVED;
 420                 }
 421             }
 422         }
 423     next_host:
 424         continue;
 425     }
 426 }
 427 
 428 /*
 429  * Overrides for Emacs so that we follow Linus's tabbing style.
 430  * Emacs will notice this stuff at the end of the file and automatically
 431  * adjust the settings for this buffer only.  This must remain at the end
 432  * of the file.
 433  * ---------------------------------------------------------------------------
 434  * Local variables:
 435  * c-indent-level: 4
 436  * c-brace-imaginary-offset: 0
 437  * c-brace-offset: -4
 438  * c-argdecl-indent: 4
 439  * c-label-offset: -4
 440  * c-continued-statement-offset: 4
 441  * c-continued-brace-offset: 0
 442  * indent-tabs-mode: nil
 443  * tab-width: 8
 444  * End:
 445  */

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