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

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