home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.2 / LINUX-1.2 / LINUX-1 / linux / drivers / scsi / hosts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-19  |  9.1 KB  |  407 lines

  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){
  218.     struct Scsi_Host * shpnt;
  219.  
  220.     if(scsi_hostlist == sh)
  221.         scsi_hostlist = sh->next;
  222.     else {
  223.         shpnt = scsi_hostlist;
  224.         while(shpnt->next != sh) shpnt = shpnt->next;
  225.         shpnt->next = shpnt->next->next;
  226.     };
  227.  
  228.         /* If we are removing the last host registered, it is safe to reuse
  229.            its host number (this avoids "holes" at boot time) (DB) */
  230.         if (max_scsi_hosts == next_scsi_host && !scsi_loadable_module_flag)
  231.            max_scsi_hosts--;
  232.  
  233.     next_scsi_host--;
  234.     scsi_init_free((char *) sh, sizeof(struct Scsi_Host) + sh->extra_bytes);
  235. }
  236.  
  237. /* We call this when we come across a new host adapter. We only do this
  238.    once we are 100% sure that we want to use this host adapter -  it is a
  239.    pain to reverse this, so we try and avoid it */
  240.  
  241. struct Scsi_Host * scsi_register(Scsi_Host_Template * tpnt, int j){
  242.     struct Scsi_Host * retval, *shpnt;
  243.     retval = (struct Scsi_Host *)scsi_init_malloc(sizeof(struct Scsi_Host) + j,
  244.                               (tpnt->unchecked_isa_dma && j ? GFP_DMA : 0) | GFP_ATOMIC);
  245.     retval->host_busy = 0;
  246.     retval->block = NULL;
  247.     retval->wish_block = 0;
  248.     if(j > 0xffff) panic("Too many extra bytes requested\n");
  249.     retval->extra_bytes = j;
  250.     retval->loaded_as_module = scsi_loadable_module_flag;
  251.     retval->host_no = max_scsi_hosts++; /* never reuse host_no (DB) */
  252.     next_scsi_host++;
  253.     retval->host_queue = NULL;
  254.     retval->host_wait = NULL;
  255.     retval->last_reset = 0;
  256.     retval->irq = 0;
  257.     retval->dma_channel = 0xff;
  258.     retval->io_port = 0;
  259.     retval->forbidden_addr = 0;
  260.     retval->forbidden_size = 0;
  261.     retval->hostt = tpnt;
  262.     retval->next = NULL;
  263. #ifdef DEBUG
  264.     printk("Register %x %x: %d\n", (int)retval, (int)retval->hostt, j);
  265. #endif
  266.  
  267.     /* The next four are the default values which can be overridden
  268.        if need be */
  269.     retval->this_id = tpnt->this_id;
  270.     retval->can_queue = tpnt->can_queue;
  271.     retval->sg_tablesize = tpnt->sg_tablesize;
  272.     retval->cmd_per_lun = tpnt->cmd_per_lun;
  273.     retval->unchecked_isa_dma = tpnt->unchecked_isa_dma;
  274.  
  275.     if(!scsi_hostlist)
  276.         scsi_hostlist = retval;
  277.     else
  278.     {
  279.         shpnt = scsi_hostlist;
  280.         while(shpnt->next) shpnt = shpnt->next;
  281.         shpnt->next = retval;
  282.     }
  283.  
  284.     return retval;
  285. }
  286.  
  287. int
  288. scsi_register_device(struct Scsi_Device_Template * sdpnt)
  289. {
  290.   if(sdpnt->next) panic("Device already registered");
  291.   sdpnt->next = scsi_devicelist;
  292.   scsi_devicelist = sdpnt;
  293.   return 0;
  294. }
  295.  
  296. unsigned int scsi_init()
  297. {
  298.     static int called = 0;
  299.     int i, pcount;
  300.     Scsi_Host_Template * tpnt;
  301.     struct Scsi_Host * shpnt;
  302.     const char * name;
  303.  
  304.     if(called) return 0;
  305.  
  306.     called = 1;
  307.     for (tpnt = &builtin_scsi_hosts[0], i = 0; i < MAX_SCSI_HOSTS; ++i, tpnt++)
  308.     {
  309.         /*
  310.          * Initialize our semaphores.  -1 is interpreted to mean
  311.          * "inactive" - where as 0 will indicate a time out condition.
  312.          */
  313.  
  314.         pcount = next_scsi_host;
  315.         if ((tpnt->detect) &&
  316.             (tpnt->present =
  317.              tpnt->detect(tpnt)))
  318.         {
  319.             /* The only time this should come up is when people use
  320.                some kind of patched driver of some kind or another. */
  321.             if(pcount == next_scsi_host) {
  322.                 if(tpnt->present > 1)
  323.                     panic("Failure to register low-level scsi driver");
  324.                 /* The low-level driver failed to register a driver.  We
  325.                     can do this now. */
  326.                 scsi_register(tpnt,0);
  327.             };
  328.             tpnt->next = scsi_hosts;
  329.             scsi_hosts = tpnt;
  330.         }
  331.     }
  332.  
  333.  
  334.     for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
  335.         {
  336.           if(shpnt->hostt->info)
  337.         name = shpnt->hostt->info(shpnt);
  338.           else
  339.         name = shpnt->hostt->name;
  340.           printk ("scsi%d : %s\n", /* And print a little message */
  341.               shpnt->host_no, name);
  342.         }
  343.  
  344.     printk ("scsi : %d host%s.\n", next_scsi_host,
  345.         (next_scsi_host == 1) ? "" : "s");
  346.  
  347.     scsi_make_blocked_list();
  348.  
  349.     /* Now attach the high level drivers */
  350. #ifdef CONFIG_BLK_DEV_SD
  351.     scsi_register_device(&sd_template);
  352. #endif
  353. #ifdef CONFIG_BLK_DEV_SR
  354.     scsi_register_device(&sr_template);
  355. #endif
  356. #ifdef CONFIG_CHR_DEV_ST
  357.     scsi_register_device(&st_template);
  358. #endif
  359. #ifdef CONFIG_CHR_DEV_SG
  360.     scsi_register_device(&sg_template);
  361. #endif
  362.  
  363. #if 0      
  364.     max_scsi_hosts = next_scsi_host;
  365. #endif
  366.     return 0;
  367. }
  368.  
  369.  
  370. void scsi_mem_init(unsigned long memory_end)
  371. {
  372.     struct Scsi_Host *Host;
  373.     long High8, Low24;
  374.     for (Host = scsi_hostlist; Host != NULL; Host = Host->next) {
  375.     if (Host->forbidden_addr > 0 && Host->forbidden_size > 0) {
  376.         for (High8 = 1<<24; High8 < memory_end; High8 += 1<<24) {
  377.         for (Low24 = Host->forbidden_addr;
  378.              Low24 < Host->forbidden_addr + Host->forbidden_size;
  379.              Low24 += PAGE_SIZE) {
  380.             unsigned long ForbiddenAddress = High8 + Low24;
  381.             if (ForbiddenAddress >= memory_end) goto next_host;
  382.             mem_map[MAP_NR(ForbiddenAddress)] = MAP_PAGE_RESERVED;
  383.         }
  384.         }
  385.     }
  386.       next_host:
  387.     continue;
  388.     }
  389. }
  390.  
  391. /*
  392.  * Overrides for Emacs so that we follow Linus's tabbing style.
  393.  * Emacs will notice this stuff at the end of the file and automatically
  394.  * adjust the settings for this buffer only.  This must remain at the end
  395.  * of the file.
  396.  * ---------------------------------------------------------------------------
  397.  * Local variables:
  398.  * c-indent-level: 8
  399.  * c-brace-imaginary-offset: 0
  400.  * c-brace-offset: -8
  401.  * c-argdecl-indent: 8
  402.  * c-label-offset: -8
  403.  * c-continued-statement-offset: 8
  404.  * c-continued-brace-offset: 0
  405.  * End:
  406.  */
  407.