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

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