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

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