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_DMX3191D
209 #include "dmx3191d.h"
212 #ifdef CONFIG_SCSI_DTC3280
216 #ifdef CONFIG_SCSI_NCR53C7xx
217 #include "53c7,8xx.h"
220 #ifdef CONFIG_SCSI_SYM53C8XX
221 #include "sym53c8xx.h"
224 #ifdef CONFIG_SCSI_NCR53C8XX
225 #include "ncr53c8xx.h"
228 #ifdef CONFIG_SCSI_ULTRASTOR
229 #include "ultrastor.h"
232 #ifdef CONFIG_SCSI_7000FASST
236 #ifdef CONFIG_SCSI_MCA_53C9X
237 #include "mca_53c9x.h"
240 #ifdef CONFIG_SCSI_IBMMCA
244 #ifdef CONFIG_SCSI_EATA
248 #ifdef CONFIG_SCSI_NCR53C406A
249 #include "NCR53c406a.h"
252 #ifdef CONFIG_SCSI_SYM53C416
253 #include "sym53c416.h"
256 #ifdef CONFIG_SCSI_DC390T
260 #ifdef CONFIG_SCSI_AM53C974
261 #include "AM53C974.h"
264 #ifdef CONFIG_SCSI_MEGARAID
265 #include "megaraid.h"
268 #ifdef CONFIG_SCSI_ACARD
272 #ifdef CONFIG_SCSI_SUNESP
276 #ifdef CONFIG_SCSI_SGIWD93
280 #ifdef CONFIG_SCSI_QLOGICPTI
281 #include "qlogicpti.h"
284 #ifdef CONFIG_BLK_DEV_IDESCSI
285 #include "ide-scsi.h"
288 #ifdef CONFIG_SCSI_MESH
292 #ifdef CONFIG_SCSI_MAC53C94
293 #include "mac53c94.h"
296 #ifdef CONFIG_SCSI_GDTH
300 #ifdef CONFIG_SCSI_PCI2000
304 #ifdef CONFIG_SCSI_PCI2220I
305 #include "pci2220i.h"
308 #ifdef CONFIG_SCSI_PSI240I
312 #ifdef CONFIG_SCSI_PLUTO
316 #ifdef CONFIG_SCSI_INITIO
317 #include "ini9100u.h"
320 #ifdef CONFIG_SCSI_INIA100
324 #ifdef CONFIG_SCSI_DEBUG
325 #include "scsi_debug.h"
328 #ifdef CONFIG_SCSI_ACORNSCSI_3
329 #include "../acorn/scsi/acornscsi.h"
332 #ifdef CONFIG_SCSI_CUMANA_1
333 #include "../acorn/scsi/cumana_1.h"
336 #ifdef CONFIG_SCSI_CUMANA_2
337 #include "../acorn/scsi/cumana_2.h"
340 #ifdef CONFIG_SCSI_ECOSCSI
341 #include "../acorn/scsi/ecoscsi.h"
344 #ifdef CONFIG_SCSI_OAK1
345 #include "../acorn/scsi/oak.h"
348 #ifdef CONFIG_SCSI_POWERTECSCSI
349 #include "../acorn/scsi/powertec.h"
352 #ifdef CONFIG_JAZZ_ESP
353 #include "jazz_esp.h"
356 #ifdef CONFIG_SCSI_DECNCR
360 #ifdef CONFIG_SUN3X_ESP
361 #include "sun3x_esp.h"
364 #ifdef CONFIG_IPHASE5526
365 #include "../net/fc/iph5526_scsi.h"
368 #ifdef CONFIG_BLK_DEV_3W_XXXX_RAID
373 * Moved ppa driver to the end of the probe list
374 * since it is a removable host adapter.
375 * This means the parallel ZIP drive will not bump
376 * the order of the /dev/sd devices - campbell@torque.net
378 #ifdef CONFIG_SCSI_PPA
382 #ifdef CONFIG_SCSI_IMM
387 static const char RCSid[] = "$Header: /vger/u4/cvs/linux/drivers/scsi/hosts.c,v 1.20 1996/12/12 19:18:32 davem Exp $";
391 * The scsi host entries should be in the order you wish the
392 * cards to be detected. A driver may appear more than once IFF
393 * it can deal with being detected (and therefore initialized)
394 * with more than one simultaneous host number, can handle being
397 * They may appear in any order, as each SCSI host is told which host
398 * number it is during detection.
401 /* This is a placeholder for controllers that are not configured into
402 * the system - we do this to ensure that the controller numbering is
403 * always consistent, no matter how the kernel is configured. */
405 #define NO_CONTROLLER {NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
406 NULL, NULL, 0, 0, 0, 0, 0, 0}
409 * When figure is run, we don't want to link to any object code. Since
410 * the macro for each host will contain function pointers, we cannot
411 * use it and instead must use a "blank" that does no such
415 Scsi_Host_Template
* scsi_hosts
= NULL
;
417 static Scsi_Host_Template builtin_scsi_hosts
[] =
420 #ifdef AMIGA7XXCONFIG
423 #ifdef CONFIG_A3000_SCSI
426 #ifdef CONFIG_A2091_SCSI
429 #ifdef CONFIG_GVP11_SCSI
432 #ifdef CONFIG_CYBERSTORM_SCSI
435 #ifdef CONFIG_CYBERSTORMII_SCSI
438 #ifdef CONFIG_BLZ2060_SCSI
441 #ifdef CONFIG_BLZ1230_SCSI
444 #ifdef CONFIG_FASTLANE_SCSI
447 #ifdef CONFIG_OKTAGON_SCSI
453 #ifdef CONFIG_ATARI_SCSI
459 #ifdef CONFIG_MAC_SCSI_OLD
462 #ifdef CONFIG_SCSI_MAC_ESP
465 #ifdef CONFIG_MAC_SCSI
470 #ifdef CONFIG_SUN3_SCSI
474 #ifdef CONFIG_MVME16x_SCSI
477 #ifdef CONFIG_BVME6000_SCSI
480 #ifdef CONFIG_SCSI_SIM710
483 #ifdef CONFIG_SCSI_ADVANSYS
487 #ifdef CONFIG_SCSI_PCI2000
490 #ifdef CONFIG_SCSI_PCI2220I
493 #ifdef CONFIG_SCSI_PSI240I
497 /* BusLogic must come before aha1542.c */
498 #ifdef CONFIG_SCSI_BUSLOGIC
501 #ifdef CONFIG_SCSI_U14_34F
504 #ifdef CONFIG_SCSI_ULTRASTOR
507 #ifdef CONFIG_SCSI_AHA152X
510 #ifdef CONFIG_SCSI_AHA1542
513 #ifdef CONFIG_SCSI_AHA1740
516 #ifdef CONFIG_SCSI_AIC7XXX
519 #ifdef CONFIG_SCSI_IPS
522 #ifdef CONFIG_SCSI_FD_MCS
525 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
528 #ifdef CONFIG_SCSI_IN2000
531 #ifdef CONFIG_SCSI_GENERIC_NCR5380
534 #ifdef CONFIG_SCSI_NCR53C406A /* 53C406A should come before QLOGIC */
537 #ifdef CONFIG_SCSI_SYM53C416
540 #ifdef CONFIG_SCSI_QLOGIC_FAS
543 #ifdef CONFIG_SCSI_QLOGIC_ISP
546 #ifdef CONFIG_SCSI_QLOGIC_FC
549 #ifdef CONFIG_SCSI_QLOGIC_1280
550 QLA1280_LINUX_TEMPLATE
,
552 #ifdef CONFIG_SCSI_PAS16
555 #ifdef CONFIG_SCSI_SEAGATE
558 #ifdef CONFIG_SCSI_T128
561 #ifdef CONFIG_SCSI_DMX3191D
564 #ifdef CONFIG_SCSI_DTC3280
567 #ifdef CONFIG_SCSI_NCR53C7xx
570 #ifdef CONFIG_SCSI_SYM53C8XX
573 #ifdef CONFIG_SCSI_NCR53C8XX
576 #ifdef CONFIG_SCSI_EATA_DMA
579 #ifdef CONFIG_SCSI_EATA_PIO
582 #ifdef CONFIG_SCSI_7000FASST
585 #ifdef CONFIG_SCSI_MCA_53C9X
588 #ifdef CONFIG_SCSI_IBMMCA
591 #ifdef CONFIG_SCSI_EATA
594 #ifdef CONFIG_SCSI_DC390T
597 #ifdef CONFIG_SCSI_AM53C974
600 #ifdef CONFIG_SCSI_MEGARAID
603 #ifdef CONFIG_SCSI_ACARD
606 #ifdef CONFIG_SCSI_SUNESP
609 #ifdef CONFIG_SCSI_GDTH
612 #ifdef CONFIG_SCSI_INITIO
615 #ifdef CONFIG_SCSI_INIA100
618 #ifdef CONFIG_SCSI_QLOGICPTI
621 #ifdef CONFIG_BLK_DEV_IDESCSI
624 #ifdef CONFIG_SCSI_MESH
627 #ifdef CONFIG_SCSI_MAC53C94
630 #ifdef CONFIG_SCSI_PLUTO
633 #ifdef CONFIG_ARCH_ACORN
634 #ifdef CONFIG_SCSI_ACORNSCSI_3
637 #ifdef CONFIG_SCSI_CUMANA_1
640 #ifdef CONFIG_SCSI_CUMANA_2
643 #ifdef CONFIG_SCSI_ECOSCSI
646 #ifdef CONFIG_SCSI_OAK1
649 #ifdef CONFIG_SCSI_POWERTECSCSI
653 #ifdef CONFIG_IPHASE5526
656 #ifdef CONFIG_SCSI_DECNCR
659 #ifdef CONFIG_BLK_DEV_3W_XXXX_RAID
662 /* "Removable host adapters" below this line (Parallel Port/USB/other) */
663 #ifdef CONFIG_SCSI_PPA
666 #ifdef CONFIG_SCSI_IMM
669 #ifdef CONFIG_SCSI_SGIWD93
672 #ifdef CONFIG_JAZZ_ESP
675 #ifdef CONFIG_SUN3X_ESP
678 #ifdef CONFIG_SCSI_DEBUG
683 #define MAX_SCSI_HOSTS (sizeof(builtin_scsi_hosts) / sizeof(Scsi_Host_Template))
687 * Our semaphores and timeout counters, where size depends on
688 * MAX_SCSI_HOSTS here.
691 Scsi_Host_Name
* scsi_host_no_list
= NULL
;
692 struct Scsi_Host
* scsi_hostlist
= NULL
;
693 struct Scsi_Device_Template
* scsi_devicelist
= NULL
;
695 int max_scsi_hosts
= 0;
696 int next_scsi_host
= 0;
699 scsi_unregister(struct Scsi_Host
* sh
){
700 struct Scsi_Host
* shpnt
;
703 if(scsi_hostlist
== sh
)
704 scsi_hostlist
= sh
->next
;
706 shpnt
= scsi_hostlist
;
707 while(shpnt
->next
!= sh
) shpnt
= shpnt
->next
;
708 shpnt
->next
= shpnt
->next
->next
;
712 * We have to unregister the host from the scsi_host_no_list as well.
713 * Decide by the host_no not by the name because most host drivers are
714 * able to handle more than one adapters from the same kind (or family).
716 for ( shn
=scsi_host_no_list
; shn
&& (sh
->host_no
!= shn
->host_no
);
718 if (shn
) shn
->host_registered
= 0;
719 /* else {} : This should not happen, we should panic here... */
721 /* If we are removing the last host registered, it is safe to reuse
722 * its host number (this avoids "holes" at boot time) (DB)
723 * It is also safe to reuse those of numbers directly below which have
724 * been released earlier (to avoid some holes in numbering).
726 if(sh
->host_no
== max_scsi_hosts
- 1) {
727 while(--max_scsi_hosts
>= next_scsi_host
) {
728 shpnt
= scsi_hostlist
;
729 while(shpnt
&& shpnt
->host_no
!= max_scsi_hosts
- 1)
739 /* We call this when we come across a new host adapter. We only do this
740 * once we are 100% sure that we want to use this host adapter - it is a
741 * pain to reverse this, so we try to avoid it
744 struct Scsi_Host
* scsi_register(Scsi_Host_Template
* tpnt
, int j
){
745 struct Scsi_Host
* retval
, *shpnt
;
746 Scsi_Host_Name
*shn
, *shn2
;
748 retval
= (struct Scsi_Host
*)kmalloc(sizeof(struct Scsi_Host
) + j
,
749 (tpnt
->unchecked_isa_dma
&& j
? GFP_DMA
: 0) | GFP_ATOMIC
);
750 memset(retval
, 0, sizeof(struct Scsi_Host
) + j
);
752 /* trying to find a reserved entry (host_no) */
753 for (shn
= scsi_host_no_list
;shn
;shn
= shn
->next
)
754 if (!(shn
->host_registered
) && shn
->loaded_as_module
&& tpnt
->proc_dir
&&
755 tpnt
->proc_dir
->name
&& !strncmp(tpnt
->proc_dir
->name
, shn
->name
, strlen(tpnt
->proc_dir
->name
))) {
757 retval
->host_no
= shn
->host_no
;
758 shn
->host_registered
= 1;
759 shn
->loaded_as_module
= scsi_loadable_module_flag
;
762 atomic_set(&retval
->host_active
,0);
763 retval
->host_busy
= 0;
764 retval
->host_failed
= 0;
765 if(j
> 0xffff) panic("Too many extra bytes requested\n");
766 retval
->extra_bytes
= j
;
767 retval
->loaded_as_module
= scsi_loadable_module_flag
;
770 shn
= (Scsi_Host_Name
*) kmalloc(sizeof(Scsi_Host_Name
), GFP_ATOMIC
);
772 len
= strlen(tpnt
->proc_dir
->name
);
773 shn
->name
= kmalloc(len
+1, GFP_ATOMIC
);
775 strncpy(shn
->name
, tpnt
->proc_dir
->name
, len
);
777 shn
->host_no
= max_scsi_hosts
++;
778 shn
->host_registered
= 1;
779 shn
->loaded_as_module
= scsi_loadable_module_flag
;
781 if (scsi_host_no_list
) {
782 for (shn2
= scsi_host_no_list
;shn2
->next
;shn2
= shn2
->next
)
787 scsi_host_no_list
= shn
;
788 retval
->host_no
= shn
->host_no
;
791 retval
->host_queue
= NULL
;
792 init_waitqueue_head(&retval
->host_wait
);
793 retval
->resetting
= 0;
794 retval
->last_reset
= 0;
796 retval
->dma_channel
= 0xff;
798 /* These three are default values which can be overridden */
799 retval
->max_channel
= 0;
804 * All drivers right now should be able to handle 12 byte commands.
805 * Every so often there are requests for 16 byte commands, but individual
806 * low-level drivers need to certify that they actually do something
807 * sensible with such commands.
809 retval
->max_cmd_len
= 12;
811 retval
->unique_id
= 0;
813 retval
->hostt
= tpnt
;
815 retval
->in_recovery
= 0;
816 retval
->ehandler
= NULL
; /* Initial value until the thing starts up. */
817 retval
->eh_notify
= NULL
; /* Who we notify when we exit. */
820 retval
->host_blocked
= FALSE
;
821 retval
->host_self_blocked
= FALSE
;
824 printk("Register %x %x: %d\n", (int)retval
, (int)retval
->hostt
, j
);
827 /* The next six are the default values which can be overridden
829 retval
->this_id
= tpnt
->this_id
;
830 retval
->can_queue
= tpnt
->can_queue
;
831 retval
->sg_tablesize
= tpnt
->sg_tablesize
;
832 retval
->cmd_per_lun
= tpnt
->cmd_per_lun
;
833 retval
->unchecked_isa_dma
= tpnt
->unchecked_isa_dma
;
834 retval
->use_clustering
= tpnt
->use_clustering
;
836 retval
->select_queue_depths
= tpnt
->select_queue_depths
;
839 scsi_hostlist
= retval
;
842 shpnt
= scsi_hostlist
;
843 while(shpnt
->next
) shpnt
= shpnt
->next
;
844 shpnt
->next
= retval
;
851 scsi_register_device(struct Scsi_Device_Template
* sdpnt
)
853 if(sdpnt
->next
) panic("Device already registered");
854 sdpnt
->next
= scsi_devicelist
;
855 scsi_devicelist
= sdpnt
;
860 * Why is this a separate function? Because the kernel_thread code
861 * effectively does a fork, and there is a builtin exit() call when
862 * the child returns. The difficulty is that scsi_init() is
863 * marked __init, which means the memory is unmapped after bootup
864 * is complete, which means that the thread's exit() call gets wiped.
866 * The lesson is to *NEVER*, *NEVER* call kernel_thread() from an
867 * __init function, if that function could ever return.
869 static void launch_error_handler_thread(struct Scsi_Host
* shpnt
)
871 DECLARE_MUTEX_LOCKED(sem
);
873 shpnt
->eh_notify
= &sem
;
875 kernel_thread((int (*)(void *))scsi_error_handler
,
879 * Now wait for the kernel error thread to initialize itself
880 * as it might be needed when we scan the bus.
883 shpnt
->eh_notify
= NULL
;
886 unsigned int __init
scsi_init(void)
888 static int called
= 0;
891 Scsi_Host_Template
* tpnt
;
892 struct Scsi_Host
* shpnt
;
898 for (tpnt
= &builtin_scsi_hosts
[0], i
= 0; i
< MAX_SCSI_HOSTS
; ++i
, tpnt
++)
901 * Initialize our semaphores. -1 is interpreted to mean
902 * "inactive" - where as 0 will indicate a time out condition.
905 pcount
= next_scsi_host
;
908 /* The detect routine must carefully spinunlock/spinlock if
909 it enables interrupts, since all interrupt handlers do
911 All lame drivers are going to fail due to the following
912 spinlock. For the time beeing let's use it only for drivers
913 using the new scsi code. NOTE: the detect routine could
914 redefine the value tpnt->use_new_eh_code. (DB, 13 May 1998) */
916 if (tpnt
->use_new_eh_code
) {
917 spin_lock_irqsave(&io_request_lock
, flags
);
918 tpnt
->present
= tpnt
->detect(tpnt
);
919 spin_unlock_irqrestore(&io_request_lock
, flags
);
922 tpnt
->present
= tpnt
->detect(tpnt
);
926 if (tpnt
->detect
&& tpnt
->present
)
928 /* The only time this should come up is when people use
929 * some kind of patched driver of some kind or another. */
930 if(pcount
== next_scsi_host
) {
931 if(tpnt
->present
> 1)
932 panic("Failure to register low-level scsi driver");
933 /* The low-level driver failed to register a driver. We
934 * can do this now. */
935 scsi_register(tpnt
,0);
937 tpnt
->next
= scsi_hosts
;
940 /* Add the driver to /proc/scsi */
942 build_proc_dir_entries(tpnt
);
947 for(shpnt
=scsi_hostlist
; shpnt
; shpnt
= shpnt
->next
)
949 if(shpnt
->hostt
->info
)
950 name
= shpnt
->hostt
->info(shpnt
);
952 name
= shpnt
->hostt
->name
;
953 printk ("scsi%d : %s\n", /* And print a little message */
954 shpnt
->host_no
, name
);
957 * Now start the error recovery thread for the host.
959 if( shpnt
->hostt
->use_new_eh_code
)
961 launch_error_handler_thread(shpnt
);
965 printk ("scsi : %d host%s.\n", next_scsi_host
,
966 (next_scsi_host
== 1) ? "" : "s");
968 /* Now attach the high level drivers */
969 #ifdef CONFIG_BLK_DEV_SD
970 scsi_register_device(&sd_template
);
972 #ifdef CONFIG_BLK_DEV_SR
973 scsi_register_device(&sr_template
);
975 #ifdef CONFIG_CHR_DEV_ST
976 scsi_register_device(&st_template
);
978 #ifdef CONFIG_CHR_DEV_SG
979 scsi_register_device(&sg_template
);
983 max_scsi_hosts
= next_scsi_host
;
989 * Overrides for Emacs so that we follow Linus's tabbing style.
990 * Emacs will notice this stuff at the end of the file and automatically
991 * adjust the settings for this buffer only. This must remain at the end
993 * ---------------------------------------------------------------------------
996 * c-brace-imaginary-offset: 0
998 * c-argdecl-indent: 4
1000 * c-continued-statement-offset: 4
1001 * c-continued-brace-offset: 0
1002 * indent-tabs-mode: nil