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

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