2 * hosts.c Copyright (C) 1992 Drew Eckhardt
3 * Copyright (C) 1993, 1994, 1995 Eric Youngdale
5 * mid to lowlevel SCSI driver interface
6 * Initial versions: Drew Eckhardt
7 * Subsequent revisions: Eric Youngdale
11 * Jiffies wrap fixes (host->resetting), 3 Dec 1998 Andrea Arcangeli
12 * Added QLOGIC QLA1280 SCSI controller kernel host support.
13 * August 4, 1999 Fred Lewis, Intel DuPont
18 * This file contains the medium level SCSI
19 * host interface initialization, as well as the scsi_hosts array of SCSI
20 * hosts currently present in the system.
23 #define __NO_VERSION__
24 #include <linux/module.h>
26 #include <linux/config.h>
27 #include <linux/blk.h>
28 #include <linux/kernel.h>
29 #include <linux/string.h>
31 #include <linux/proc_fs.h>
32 #include <linux/init.h>
34 #define __KERNEL_SYSCALLS__
36 #include <linux/unistd.h>
48 #if defined(CONFIG_A4000T_SCSI) || \
49 defined(CONFIG_WARPENGINE_SCSI) || \
50 defined(CONFIG_A4091_SCSI) || \
51 defined (CONFIG_GVP_TURBO_SCSI) || \
52 defined (CONFIG_BLZ603EPLUS_SCSI)
53 #define AMIGA7XXCONFIG
60 #ifdef CONFIG_MVME16x_SCSI
64 #ifdef CONFIG_BVME6000_SCSI
68 #ifdef CONFIG_SCSI_SIM710
72 #ifdef CONFIG_A3000_SCSI
76 #ifdef CONFIG_A2091_SCSI
80 #ifdef CONFIG_GVP11_SCSI
84 #ifdef CONFIG_CYBERSTORM_SCSI
85 #include "cyberstorm.h"
88 #ifdef CONFIG_CYBERSTORMII_SCSI
89 #include "cyberstormII.h"
92 #ifdef CONFIG_BLZ2060_SCSI
96 #ifdef CONFIG_BLZ1230_SCSI
100 #ifdef CONFIG_FASTLANE_SCSI
101 #include "fastlane.h"
104 #ifdef CONFIG_OKTAGON_SCSI
105 #include "oktagon_esp.h"
108 #ifdef CONFIG_ATARI_SCSI
109 #include "atari_scsi.h"
112 #if defined(CONFIG_MAC_SCSI) || defined(CONFIG_MAC_SCSI_OLD)
113 #include "mac_scsi.h"
116 #ifdef CONFIG_SUN3_SCSI
117 #include "sun3_scsi.h"
120 #ifdef CONFIG_SCSI_MAC_ESP
124 #ifdef CONFIG_SCSI_ADVANSYS
125 #include "advansys.h"
128 #ifdef CONFIG_SCSI_AHA152X
132 #ifdef CONFIG_SCSI_AHA1542
136 #ifdef CONFIG_SCSI_AHA1740
140 #ifdef CONFIG_SCSI_AIC7XXX
144 #ifdef CONFIG_SCSI_IPS
148 #ifdef CONFIG_SCSI_BUSLOGIC
149 #include "BusLogic.h"
152 #ifdef CONFIG_SCSI_EATA_DMA
153 #include "eata_dma.h"
156 #ifdef CONFIG_SCSI_EATA_PIO
157 #include "eata_pio.h"
160 #ifdef CONFIG_SCSI_U14_34F
164 #ifdef CONFIG_SCSI_FD_MCS
168 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
172 #ifdef CONFIG_SCSI_GENERIC_NCR5380
173 #include "g_NCR5380.h"
176 #ifdef CONFIG_SCSI_IN2000
180 #ifdef CONFIG_SCSI_PAS16
184 #ifdef CONFIG_SCSI_QLOGIC_FAS
185 #include "qlogicfas.h"
188 #ifdef CONFIG_SCSI_QLOGIC_ISP
189 #include "qlogicisp.h"
192 #ifdef CONFIG_SCSI_QLOGIC_FC
193 #include "qlogicfc.h"
196 #ifdef CONFIG_SCSI_QLOGIC_1280
200 #ifdef CONFIG_SCSI_SEAGATE
204 #ifdef CONFIG_SCSI_T128
208 #ifdef CONFIG_SCSI_DTC3280
212 #ifdef CONFIG_SCSI_NCR53C7xx
213 #include "53c7,8xx.h"
216 #ifdef CONFIG_SCSI_SYM53C8XX
217 #include "sym53c8xx.h"
220 #ifdef CONFIG_SCSI_NCR53C8XX
221 #include "ncr53c8xx.h"
224 #ifdef CONFIG_SCSI_ULTRASTOR
225 #include "ultrastor.h"
228 #ifdef CONFIG_SCSI_7000FASST
232 #ifdef CONFIG_SCSI_MCA_53C9X
233 #include "mca_53c9x.h"
236 #ifdef CONFIG_SCSI_IBMMCA
240 #ifdef CONFIG_SCSI_EATA
244 #ifdef CONFIG_SCSI_NCR53C406A
245 #include "NCR53c406a.h"
248 #ifdef CONFIG_SCSI_SYM53C416
249 #include "sym53c416.h"
252 #ifdef CONFIG_SCSI_DC390T
256 #ifdef CONFIG_SCSI_AM53C974
257 #include "AM53C974.h"
260 #ifdef CONFIG_SCSI_MEGARAID
261 #include "megaraid.h"
264 #ifdef CONFIG_SCSI_ACARD
268 #ifdef CONFIG_SCSI_SUNESP
272 #ifdef CONFIG_SCSI_QLOGICPTI
273 #include "qlogicpti.h"
276 #ifdef CONFIG_BLK_DEV_IDESCSI
277 #include "ide-scsi.h"
280 #ifdef CONFIG_SCSI_MESH
284 #ifdef CONFIG_SCSI_MAC53C94
285 #include "mac53c94.h"
288 #ifdef CONFIG_SCSI_GDTH
292 #ifdef CONFIG_SCSI_PCI2000
296 #ifdef CONFIG_SCSI_PCI2220I
297 #include "pci2220i.h"
300 #ifdef CONFIG_SCSI_PSI240I
304 #ifdef CONFIG_SCSI_PLUTO
308 #ifdef CONFIG_SCSI_INITIO
309 #include "ini9100u.h"
312 #ifdef CONFIG_SCSI_INIA100
316 #ifdef CONFIG_SCSI_DEBUG
317 #include "scsi_debug.h"
320 #ifdef CONFIG_SCSI_ACORNSCSI_3
321 #include "../acorn/scsi/acornscsi.h"
324 #ifdef CONFIG_SCSI_CUMANA_1
325 #include "../acorn/scsi/cumana_1.h"
328 #ifdef CONFIG_SCSI_CUMANA_2
329 #include "../acorn/scsi/cumana_2.h"
332 #ifdef CONFIG_SCSI_ECOSCSI
333 #include "../acorn/scsi/ecoscsi.h"
336 #ifdef CONFIG_SCSI_OAK1
337 #include "../acorn/scsi/oak.h"
340 #ifdef CONFIG_SCSI_POWERTECSCSI
341 #include "../acorn/scsi/powertec.h"
344 #ifdef CONFIG_JAZZ_ESP
345 #include "jazz_esp.h"
348 #ifdef CONFIG_SUN3X_ESP
349 #include "sun3x_esp.h"
352 #ifdef CONFIG_IPHASE5526
353 #include "../net/fc/iph5526_scsi.h"
356 #ifdef CONFIG_BLK_DEV_3W_XXXX_RAID
361 * Moved ppa driver to the end of the probe list
362 * since it is a removable host adapter.
363 * This means the parallel ZIP drive will not bump
364 * the order of the /dev/sd devices - campbell@torque.net
366 #ifdef CONFIG_SCSI_PPA
370 #ifdef CONFIG_SCSI_IMM
375 static const char RCSid[] = "$Header: /vger/u4/cvs/linux/drivers/scsi/hosts.c,v 1.20 1996/12/12 19:18:32 davem Exp $";
379 * The scsi host entries should be in the order you wish the
380 * cards to be detected. A driver may appear more than once IFF
381 * it can deal with being detected (and therefore initialized)
382 * with more than one simultaneous host number, can handle being
385 * They may appear in any order, as each SCSI host is told which host
386 * number it is during detection.
389 /* This is a placeholder for controllers that are not configured into
390 * the system - we do this to ensure that the controller numbering is
391 * always consistent, no matter how the kernel is configured. */
393 #define NO_CONTROLLER {NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
394 NULL, NULL, 0, 0, 0, 0, 0, 0}
397 * When figure is run, we don't want to link to any object code. Since
398 * the macro for each host will contain function pointers, we cannot
399 * use it and instead must use a "blank" that does no such
403 Scsi_Host_Template
* scsi_hosts
= NULL
;
405 static Scsi_Host_Template builtin_scsi_hosts
[] =
408 #ifdef AMIGA7XXCONFIG
411 #ifdef CONFIG_A3000_SCSI
414 #ifdef CONFIG_A2091_SCSI
417 #ifdef CONFIG_GVP11_SCSI
420 #ifdef CONFIG_CYBERSTORM_SCSI
423 #ifdef CONFIG_CYBERSTORMII_SCSI
426 #ifdef CONFIG_BLZ2060_SCSI
429 #ifdef CONFIG_BLZ1230_SCSI
432 #ifdef CONFIG_FASTLANE_SCSI
435 #ifdef CONFIG_OKTAGON_SCSI
441 #ifdef CONFIG_ATARI_SCSI
447 #ifdef CONFIG_MAC_SCSI_OLD
450 #ifdef CONFIG_SCSI_MAC_ESP
453 #ifdef CONFIG_MAC_SCSI
458 #ifdef CONFIG_SUN3_SCSI
462 #ifdef CONFIG_MVME16x_SCSI
465 #ifdef CONFIG_BVME6000_SCSI
468 #ifdef CONFIG_SCSI_SIM710
471 #ifdef CONFIG_SCSI_ADVANSYS
475 #ifdef CONFIG_SCSI_PCI2000
478 #ifdef CONFIG_SCSI_PCI2220I
481 #ifdef CONFIG_SCSI_PSI240I
485 /* BusLogic must come before aha1542.c */
486 #ifdef CONFIG_SCSI_BUSLOGIC
489 #ifdef CONFIG_SCSI_U14_34F
492 #ifdef CONFIG_SCSI_ULTRASTOR
495 #ifdef CONFIG_SCSI_AHA152X
498 #ifdef CONFIG_SCSI_AHA1542
501 #ifdef CONFIG_SCSI_AHA1740
504 #ifdef CONFIG_SCSI_AIC7XXX
507 #ifdef CONFIG_SCSI_IPS
510 #ifdef CONFIG_SCSI_FD_MCS
513 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
516 #ifdef CONFIG_SCSI_IN2000
519 #ifdef CONFIG_SCSI_GENERIC_NCR5380
522 #ifdef CONFIG_SCSI_NCR53C406A /* 53C406A should come before QLOGIC */
525 #ifdef CONFIG_SCSI_SYM53C416
528 #ifdef CONFIG_SCSI_QLOGIC_FAS
531 #ifdef CONFIG_SCSI_QLOGIC_ISP
534 #ifdef CONFIG_SCSI_QLOGIC_FC
537 #ifdef CONFIG_SCSI_QLOGIC_1280
538 QLA1280_LINUX_TEMPLATE
,
540 #ifdef CONFIG_SCSI_PAS16
543 #ifdef CONFIG_SCSI_SEAGATE
546 #ifdef CONFIG_SCSI_T128
549 #ifdef CONFIG_SCSI_DTC3280
552 #ifdef CONFIG_SCSI_NCR53C7xx
555 #ifdef CONFIG_SCSI_SYM53C8XX
558 #ifdef CONFIG_SCSI_NCR53C8XX
561 #ifdef CONFIG_SCSI_EATA_DMA
564 #ifdef CONFIG_SCSI_EATA_PIO
567 #ifdef CONFIG_SCSI_7000FASST
570 #ifdef CONFIG_SCSI_MCA_53C9X
573 #ifdef CONFIG_SCSI_IBMMCA
576 #ifdef CONFIG_SCSI_EATA
579 #ifdef CONFIG_SCSI_DC390T
582 #ifdef CONFIG_SCSI_AM53C974
585 #ifdef CONFIG_SCSI_MEGARAID
588 #ifdef CONFIG_SCSI_ACARD
591 #ifdef CONFIG_SCSI_SUNESP
594 #ifdef CONFIG_SCSI_GDTH
597 #ifdef CONFIG_SCSI_INITIO
600 #ifdef CONFIG_SCSI_INIA100
603 #ifdef CONFIG_SCSI_QLOGICPTI
606 #ifdef CONFIG_BLK_DEV_IDESCSI
609 #ifdef CONFIG_SCSI_MESH
612 #ifdef CONFIG_SCSI_MAC53C94
615 #ifdef CONFIG_SCSI_PLUTO
618 #ifdef CONFIG_ARCH_ACORN
619 #ifdef CONFIG_SCSI_ACORNSCSI_3
622 #ifdef CONFIG_SCSI_CUMANA_1
625 #ifdef CONFIG_SCSI_CUMANA_2
628 #ifdef CONFIG_SCSI_ECOSCSI
631 #ifdef CONFIG_SCSI_OAK1
634 #ifdef CONFIG_SCSI_POWERTECSCSI
638 #ifdef CONFIG_IPHASE5526
641 #ifdef CONFIG_BLK_DEV_3W_XXXX_RAID
645 /* "Removable host adapters" below this line (Parallel Port/USB/other) */
646 #ifdef CONFIG_SCSI_PPA
649 #ifdef CONFIG_SCSI_IMM
652 #ifdef CONFIG_SUN3X_ESP
655 #ifdef CONFIG_SCSI_DEBUG
660 #define MAX_SCSI_HOSTS (sizeof(builtin_scsi_hosts) / sizeof(Scsi_Host_Template))
664 * Our semaphores and timeout counters, where size depends on
665 * MAX_SCSI_HOSTS here.
668 Scsi_Host_Name
* scsi_host_no_list
= NULL
;
669 struct Scsi_Host
* scsi_hostlist
= NULL
;
670 struct Scsi_Device_Template
* scsi_devicelist
= NULL
;
672 int max_scsi_hosts
= 0;
673 int next_scsi_host
= 0;
676 scsi_unregister(struct Scsi_Host
* sh
){
677 struct Scsi_Host
* shpnt
;
680 if(scsi_hostlist
== sh
)
681 scsi_hostlist
= sh
->next
;
683 shpnt
= scsi_hostlist
;
684 while(shpnt
->next
!= sh
) shpnt
= shpnt
->next
;
685 shpnt
->next
= shpnt
->next
->next
;
689 * We have to unregister the host from the scsi_host_no_list as well.
690 * Decide by the host_no not by the name because most host drivers are
691 * able to handle more than one adapters from the same kind (or family).
693 for ( shn
=scsi_host_no_list
; shn
&& (sh
->host_no
!= shn
->host_no
);
695 if (shn
) shn
->host_registered
= 0;
696 /* else {} : This should not happen, we should panic here... */
698 /* If we are removing the last host registered, it is safe to reuse
699 * its host number (this avoids "holes" at boot time) (DB)
700 * It is also safe to reuse those of numbers directly below which have
701 * been released earlier (to avoid some holes in numbering).
703 if(sh
->host_no
== max_scsi_hosts
- 1) {
704 while(--max_scsi_hosts
>= next_scsi_host
) {
705 shpnt
= scsi_hostlist
;
706 while(shpnt
&& shpnt
->host_no
!= max_scsi_hosts
- 1)
716 /* We call this when we come across a new host adapter. We only do this
717 * once we are 100% sure that we want to use this host adapter - it is a
718 * pain to reverse this, so we try to avoid it
721 struct Scsi_Host
* scsi_register(Scsi_Host_Template
* tpnt
, int j
){
722 struct Scsi_Host
* retval
, *shpnt
;
723 Scsi_Host_Name
*shn
, *shn2
;
725 retval
= (struct Scsi_Host
*)kmalloc(sizeof(struct Scsi_Host
) + j
,
726 (tpnt
->unchecked_isa_dma
&& j
? GFP_DMA
: 0) | GFP_ATOMIC
);
727 memset(retval
, 0, sizeof(struct Scsi_Host
) + j
);
729 /* trying to find a reserved entry (host_no) */
730 for (shn
= scsi_host_no_list
;shn
;shn
= shn
->next
)
731 if (!(shn
->host_registered
) && shn
->loaded_as_module
&& tpnt
->proc_dir
&&
732 tpnt
->proc_dir
->name
&& !strncmp(tpnt
->proc_dir
->name
, shn
->name
, strlen(tpnt
->proc_dir
->name
))) {
734 retval
->host_no
= shn
->host_no
;
735 shn
->host_registered
= 1;
736 shn
->loaded_as_module
= scsi_loadable_module_flag
;
739 atomic_set(&retval
->host_active
,0);
740 retval
->host_busy
= 0;
741 retval
->host_failed
= 0;
742 if(j
> 0xffff) panic("Too many extra bytes requested\n");
743 retval
->extra_bytes
= j
;
744 retval
->loaded_as_module
= scsi_loadable_module_flag
;
747 shn
= (Scsi_Host_Name
*) kmalloc(sizeof(Scsi_Host_Name
), GFP_ATOMIC
);
749 len
= strlen(tpnt
->proc_dir
->name
);
750 shn
->name
= kmalloc(len
+1, GFP_ATOMIC
);
752 strncpy(shn
->name
, tpnt
->proc_dir
->name
, len
);
754 shn
->host_no
= max_scsi_hosts
++;
755 shn
->host_registered
= 1;
756 shn
->loaded_as_module
= scsi_loadable_module_flag
;
758 if (scsi_host_no_list
) {
759 for (shn2
= scsi_host_no_list
;shn2
->next
;shn2
= shn2
->next
)
764 scsi_host_no_list
= shn
;
765 retval
->host_no
= shn
->host_no
;
768 retval
->host_queue
= NULL
;
769 init_waitqueue_head(&retval
->host_wait
);
770 retval
->resetting
= 0;
771 retval
->last_reset
= 0;
773 retval
->dma_channel
= 0xff;
775 /* These three are default values which can be overridden */
776 retval
->max_channel
= 0;
780 retval
->unique_id
= 0;
782 retval
->hostt
= tpnt
;
784 retval
->in_recovery
= 0;
785 retval
->ehandler
= NULL
; /* Initial value until the thing starts up. */
786 retval
->eh_notify
= NULL
; /* Who we notify when we exit. */
789 retval
->host_blocked
= FALSE
;
792 printk("Register %x %x: %d\n", (int)retval
, (int)retval
->hostt
, j
);
795 /* The next six are the default values which can be overridden
797 retval
->this_id
= tpnt
->this_id
;
798 retval
->can_queue
= tpnt
->can_queue
;
799 retval
->sg_tablesize
= tpnt
->sg_tablesize
;
800 retval
->cmd_per_lun
= tpnt
->cmd_per_lun
;
801 retval
->unchecked_isa_dma
= tpnt
->unchecked_isa_dma
;
802 retval
->use_clustering
= tpnt
->use_clustering
;
804 retval
->select_queue_depths
= tpnt
->select_queue_depths
;
807 scsi_hostlist
= retval
;
810 shpnt
= scsi_hostlist
;
811 while(shpnt
->next
) shpnt
= shpnt
->next
;
812 shpnt
->next
= retval
;
819 scsi_register_device(struct Scsi_Device_Template
* sdpnt
)
821 if(sdpnt
->next
) panic("Device already registered");
822 sdpnt
->next
= scsi_devicelist
;
823 scsi_devicelist
= sdpnt
;
828 * Why is this a separate function? Because the kernel_thread code
829 * effectively does a fork, and there is a builtin exit() call when
830 * the child returns. The difficulty is that scsi_init() is
831 * marked __init, which means the memory is unmapped after bootup
832 * is complete, which means that the thread's exit() call gets wiped.
834 * The lesson is to *NEVER*, *NEVER* call kernel_thread() from an
835 * __init function, if that function could ever return.
837 static void launch_error_handler_thread(struct Scsi_Host
* shpnt
)
839 DECLARE_MUTEX_LOCKED(sem
);
841 shpnt
->eh_notify
= &sem
;
843 kernel_thread((int (*)(void *))scsi_error_handler
,
847 * Now wait for the kernel error thread to initialize itself
848 * as it might be needed when we scan the bus.
851 shpnt
->eh_notify
= NULL
;
854 unsigned int __init
scsi_init(void)
856 static int called
= 0;
859 Scsi_Host_Template
* tpnt
;
860 struct Scsi_Host
* shpnt
;
866 for (tpnt
= &builtin_scsi_hosts
[0], i
= 0; i
< MAX_SCSI_HOSTS
; ++i
, tpnt
++)
869 * Initialize our semaphores. -1 is interpreted to mean
870 * "inactive" - where as 0 will indicate a time out condition.
873 pcount
= next_scsi_host
;
876 /* The detect routine must carefully spinunlock/spinlock if
877 it enables interrupts, since all interrupt handlers do
879 All lame drivers are going to fail due to the following
880 spinlock. For the time beeing let's use it only for drivers
881 using the new scsi code. NOTE: the detect routine could
882 redefine the value tpnt->use_new_eh_code. (DB, 13 May 1998) */
884 if (tpnt
->use_new_eh_code
) {
885 spin_lock_irqsave(&io_request_lock
, flags
);
886 tpnt
->present
= tpnt
->detect(tpnt
);
887 spin_unlock_irqrestore(&io_request_lock
, flags
);
890 tpnt
->present
= tpnt
->detect(tpnt
);
894 if (tpnt
->detect
&& tpnt
->present
)
896 /* The only time this should come up is when people use
897 * some kind of patched driver of some kind or another. */
898 if(pcount
== next_scsi_host
) {
899 if(tpnt
->present
> 1)
900 panic("Failure to register low-level scsi driver");
901 /* The low-level driver failed to register a driver. We
902 * can do this now. */
903 scsi_register(tpnt
,0);
905 tpnt
->next
= scsi_hosts
;
908 /* Add the driver to /proc/scsi */
910 build_proc_dir_entries(tpnt
);
915 for(shpnt
=scsi_hostlist
; shpnt
; shpnt
= shpnt
->next
)
917 if(shpnt
->hostt
->info
)
918 name
= shpnt
->hostt
->info(shpnt
);
920 name
= shpnt
->hostt
->name
;
921 printk ("scsi%d : %s\n", /* And print a little message */
922 shpnt
->host_no
, name
);
925 * Now start the error recovery thread for the host.
927 if( shpnt
->hostt
->use_new_eh_code
)
929 launch_error_handler_thread(shpnt
);
933 printk ("scsi : %d host%s.\n", next_scsi_host
,
934 (next_scsi_host
== 1) ? "" : "s");
936 /* Now attach the high level drivers */
937 #ifdef CONFIG_BLK_DEV_SD
938 scsi_register_device(&sd_template
);
940 #ifdef CONFIG_BLK_DEV_SR
941 scsi_register_device(&sr_template
);
943 #ifdef CONFIG_CHR_DEV_ST
944 scsi_register_device(&st_template
);
946 #ifdef CONFIG_CHR_DEV_SG
947 scsi_register_device(&sg_template
);
951 max_scsi_hosts
= next_scsi_host
;
957 * Overrides for Emacs so that we follow Linus's tabbing style.
958 * Emacs will notice this stuff at the end of the file and automatically
959 * adjust the settings for this buffer only. This must remain at the end
961 * ---------------------------------------------------------------------------
964 * c-brace-imaginary-offset: 0
966 * c-argdecl-indent: 4
968 * c-continued-statement-offset: 4
969 * c-continued-brace-offset: 0
970 * indent-tabs-mode: nil