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

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