Merge with Linux 2.3.99-pre4.
[linux-2.6/linux-mips.git] / drivers / scsi / hosts.c
blob56c441a626c43cc948db27ae42f1c8903f79a883
1 /*
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
9 * <drew@colorado.edu>
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>
30 #include <linux/mm.h>
31 #include <linux/proc_fs.h>
32 #include <linux/init.h>
34 #define __KERNEL_SYSCALLS__
36 #include <linux/unistd.h>
38 #include "scsi.h"
40 #ifndef NULL
41 #define NULL 0L
42 #endif
44 #define HOSTS_C
46 #include "hosts.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
54 #endif
56 #ifdef AMIGA7XXCONFIG
57 #include "amiga7xx.h"
58 #endif
60 #ifdef CONFIG_MVME16x_SCSI
61 #include "mvme16x.h"
62 #endif
64 #ifdef CONFIG_BVME6000_SCSI
65 #include "bvme6000.h"
66 #endif
68 #ifdef CONFIG_SCSI_SIM710
69 #include "sim710.h"
70 #endif
72 #ifdef CONFIG_A3000_SCSI
73 #include "a3000.h"
74 #endif
76 #ifdef CONFIG_A2091_SCSI
77 #include "a2091.h"
78 #endif
80 #ifdef CONFIG_GVP11_SCSI
81 #include "gvp11.h"
82 #endif
84 #ifdef CONFIG_CYBERSTORM_SCSI
85 #include "cyberstorm.h"
86 #endif
88 #ifdef CONFIG_CYBERSTORMII_SCSI
89 #include "cyberstormII.h"
90 #endif
92 #ifdef CONFIG_BLZ2060_SCSI
93 #include "blz2060.h"
94 #endif
96 #ifdef CONFIG_BLZ1230_SCSI
97 #include "blz1230.h"
98 #endif
100 #ifdef CONFIG_FASTLANE_SCSI
101 #include "fastlane.h"
102 #endif
104 #ifdef CONFIG_OKTAGON_SCSI
105 #include "oktagon_esp.h"
106 #endif
108 #ifdef CONFIG_ATARI_SCSI
109 #include "atari_scsi.h"
110 #endif
112 #if defined(CONFIG_MAC_SCSI) || defined(CONFIG_MAC_SCSI_OLD)
113 #include "mac_scsi.h"
114 #endif
116 #ifdef CONFIG_SUN3_SCSI
117 #include "sun3_scsi.h"
118 #endif
120 #ifdef CONFIG_SCSI_MAC_ESP
121 #include "mac_esp.h"
122 #endif
124 #ifdef CONFIG_SCSI_ADVANSYS
125 #include "advansys.h"
126 #endif
128 #ifdef CONFIG_SCSI_AHA152X
129 #include "aha152x.h"
130 #endif
132 #ifdef CONFIG_SCSI_AHA1542
133 #include "aha1542.h"
134 #endif
136 #ifdef CONFIG_SCSI_AHA1740
137 #include "aha1740.h"
138 #endif
140 #ifdef CONFIG_SCSI_AIC7XXX
141 #include "aic7xxx.h"
142 #endif
144 #ifdef CONFIG_SCSI_IPS
145 #include "ips.h"
146 #endif
148 #ifdef CONFIG_SCSI_BUSLOGIC
149 #include "BusLogic.h"
150 #endif
152 #ifdef CONFIG_SCSI_EATA_DMA
153 #include "eata_dma.h"
154 #endif
156 #ifdef CONFIG_SCSI_EATA_PIO
157 #include "eata_pio.h"
158 #endif
160 #ifdef CONFIG_SCSI_U14_34F
161 #include "u14-34f.h"
162 #endif
164 #ifdef CONFIG_SCSI_FD_MCS
165 #include "fd_mcs.h"
166 #endif
168 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
169 #include "fdomain.h"
170 #endif
172 #ifdef CONFIG_SCSI_GENERIC_NCR5380
173 #include "g_NCR5380.h"
174 #endif
176 #ifdef CONFIG_SCSI_IN2000
177 #include "in2000.h"
178 #endif
180 #ifdef CONFIG_SCSI_PAS16
181 #include "pas16.h"
182 #endif
184 #ifdef CONFIG_SCSI_QLOGIC_FAS
185 #include "qlogicfas.h"
186 #endif
188 #ifdef CONFIG_SCSI_QLOGIC_ISP
189 #include "qlogicisp.h"
190 #endif
192 #ifdef CONFIG_SCSI_QLOGIC_FC
193 #include "qlogicfc.h"
194 #endif
196 #ifdef CONFIG_SCSI_QLOGIC_1280
197 #include "qla1280.h"
198 #endif
200 #ifdef CONFIG_SCSI_SEAGATE
201 #include "seagate.h"
202 #endif
204 #ifdef CONFIG_SCSI_T128
205 #include "t128.h"
206 #endif
208 #ifdef CONFIG_SCSI_DMX3191D
209 #include "dmx3191d.h"
210 #endif
212 #ifdef CONFIG_SCSI_DTC3280
213 #include "dtc.h"
214 #endif
216 #ifdef CONFIG_SCSI_NCR53C7xx
217 #include "53c7,8xx.h"
218 #endif
220 #ifdef CONFIG_SCSI_SYM53C8XX
221 #include "sym53c8xx.h"
222 #endif
224 #ifdef CONFIG_SCSI_NCR53C8XX
225 #include "ncr53c8xx.h"
226 #endif
228 #ifdef CONFIG_SCSI_ULTRASTOR
229 #include "ultrastor.h"
230 #endif
232 #ifdef CONFIG_SCSI_7000FASST
233 #include "wd7000.h"
234 #endif
236 #ifdef CONFIG_SCSI_MCA_53C9X
237 #include "mca_53c9x.h"
238 #endif
240 #ifdef CONFIG_SCSI_IBMMCA
241 #include "ibmmca.h"
242 #endif
244 #ifdef CONFIG_SCSI_EATA
245 #include "eata.h"
246 #endif
248 #ifdef CONFIG_SCSI_NCR53C406A
249 #include "NCR53c406a.h"
250 #endif
252 #ifdef CONFIG_SCSI_SYM53C416
253 #include "sym53c416.h"
254 #endif
256 #ifdef CONFIG_SCSI_DC390T
257 #include "dc390.h"
258 #endif
260 #ifdef CONFIG_SCSI_AM53C974
261 #include "AM53C974.h"
262 #endif
264 #ifdef CONFIG_SCSI_MEGARAID
265 #include "megaraid.h"
266 #endif
268 #ifdef CONFIG_SCSI_ACARD
269 #include "atp870u.h"
270 #endif
272 #ifdef CONFIG_SCSI_SUNESP
273 #include "esp.h"
274 #endif
276 #ifdef CONFIG_SCSI_SGIWD93
277 #include "sgiwd93.h"
278 #endif
280 #ifdef CONFIG_SCSI_QLOGICPTI
281 #include "qlogicpti.h"
282 #endif
284 #ifdef CONFIG_BLK_DEV_IDESCSI
285 #include "ide-scsi.h"
286 #endif
288 #ifdef CONFIG_SCSI_MESH
289 #include "mesh.h"
290 #endif
292 #ifdef CONFIG_SCSI_MAC53C94
293 #include "mac53c94.h"
294 #endif
296 #ifdef CONFIG_SCSI_GDTH
297 #include "gdth.h"
298 #endif
300 #ifdef CONFIG_SCSI_PCI2000
301 #include "pci2000.h"
302 #endif
304 #ifdef CONFIG_SCSI_PCI2220I
305 #include "pci2220i.h"
306 #endif
308 #ifdef CONFIG_SCSI_PSI240I
309 #include "psi240i.h"
310 #endif
312 #ifdef CONFIG_SCSI_PLUTO
313 #include "pluto.h"
314 #endif
316 #ifdef CONFIG_SCSI_INITIO
317 #include "ini9100u.h"
318 #endif
320 #ifdef CONFIG_SCSI_INIA100
321 #include "inia100.h"
322 #endif
324 #ifdef CONFIG_SCSI_DEBUG
325 #include "scsi_debug.h"
326 #endif
328 #ifdef CONFIG_SCSI_ACORNSCSI_3
329 #include "../acorn/scsi/acornscsi.h"
330 #endif
332 #ifdef CONFIG_SCSI_CUMANA_1
333 #include "../acorn/scsi/cumana_1.h"
334 #endif
336 #ifdef CONFIG_SCSI_CUMANA_2
337 #include "../acorn/scsi/cumana_2.h"
338 #endif
340 #ifdef CONFIG_SCSI_ECOSCSI
341 #include "../acorn/scsi/ecoscsi.h"
342 #endif
344 #ifdef CONFIG_SCSI_OAK1
345 #include "../acorn/scsi/oak.h"
346 #endif
348 #ifdef CONFIG_SCSI_POWERTECSCSI
349 #include "../acorn/scsi/powertec.h"
350 #endif
352 #ifdef CONFIG_JAZZ_ESP
353 #include "jazz_esp.h"
354 #endif
356 #ifdef CONFIG_SCSI_DECNCR
357 #include "dec_esp.h"
358 #endif
360 #ifdef CONFIG_SUN3X_ESP
361 #include "sun3x_esp.h"
362 #endif
364 #ifdef CONFIG_IPHASE5526
365 #include "../net/fc/iph5526_scsi.h"
366 #endif
368 #ifdef CONFIG_BLK_DEV_3W_XXXX_RAID
369 #include "3w-xxxx.h"
370 #endif
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
379 #include "ppa.h"
380 #endif
382 #ifdef CONFIG_SCSI_IMM
383 #include "imm.h"
384 #endif
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
395 * reentrant, etc.
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
412 * idiocy.
415 Scsi_Host_Template * scsi_hosts = NULL;
417 static Scsi_Host_Template builtin_scsi_hosts[] =
419 #ifdef CONFIG_AMIGA
420 #ifdef AMIGA7XXCONFIG
421 AMIGA7XX_SCSI,
422 #endif
423 #ifdef CONFIG_A3000_SCSI
424 A3000_SCSI,
425 #endif
426 #ifdef CONFIG_A2091_SCSI
427 A2091_SCSI,
428 #endif
429 #ifdef CONFIG_GVP11_SCSI
430 GVP11_SCSI,
431 #endif
432 #ifdef CONFIG_CYBERSTORM_SCSI
433 SCSI_CYBERSTORM,
434 #endif
435 #ifdef CONFIG_CYBERSTORMII_SCSI
436 SCSI_CYBERSTORMII,
437 #endif
438 #ifdef CONFIG_BLZ2060_SCSI
439 SCSI_BLZ2060,
440 #endif
441 #ifdef CONFIG_BLZ1230_SCSI
442 SCSI_BLZ1230,
443 #endif
444 #ifdef CONFIG_FASTLANE_SCSI
445 SCSI_FASTLANE,
446 #endif
447 #ifdef CONFIG_OKTAGON_SCSI
448 SCSI_OKTAGON_ESP,
449 #endif
450 #endif
452 #ifdef CONFIG_ATARI
453 #ifdef CONFIG_ATARI_SCSI
454 ATARI_SCSI,
455 #endif
456 #endif
458 #ifdef CONFIG_MAC
459 #ifdef CONFIG_MAC_SCSI_OLD
460 MAC_SCSI,
461 #endif
462 #ifdef CONFIG_SCSI_MAC_ESP
463 SCSI_MAC_ESP,
464 #endif
465 #ifdef CONFIG_MAC_SCSI
466 MAC_NCR5380,
467 #endif
468 #endif
470 #ifdef CONFIG_SUN3_SCSI
471 SUN3_NCR5380,
472 #endif
474 #ifdef CONFIG_MVME16x_SCSI
475 MVME16x_SCSI,
476 #endif
477 #ifdef CONFIG_BVME6000_SCSI
478 BVME6000_SCSI,
479 #endif
480 #ifdef CONFIG_SCSI_SIM710
481 SIM710_SCSI,
482 #endif
483 #ifdef CONFIG_SCSI_ADVANSYS
484 ADVANSYS,
485 #endif
487 #ifdef CONFIG_SCSI_PCI2000
488 PCI2000,
489 #endif
490 #ifdef CONFIG_SCSI_PCI2220I
491 PCI2220I,
492 #endif
493 #ifdef CONFIG_SCSI_PSI240I
494 PSI240I,
495 #endif
497 /* BusLogic must come before aha1542.c */
498 #ifdef CONFIG_SCSI_BUSLOGIC
499 BUSLOGIC,
500 #endif
501 #ifdef CONFIG_SCSI_U14_34F
502 ULTRASTOR_14_34F,
503 #endif
504 #ifdef CONFIG_SCSI_ULTRASTOR
505 ULTRASTOR_14F,
506 #endif
507 #ifdef CONFIG_SCSI_AHA152X
508 AHA152X,
509 #endif
510 #ifdef CONFIG_SCSI_AHA1542
511 AHA1542,
512 #endif
513 #ifdef CONFIG_SCSI_AHA1740
514 AHA1740,
515 #endif
516 #ifdef CONFIG_SCSI_AIC7XXX
517 AIC7XXX,
518 #endif
519 #ifdef CONFIG_SCSI_IPS
520 IPS,
521 #endif
522 #ifdef CONFIG_SCSI_FD_MCS
523 FD_MCS,
524 #endif
525 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
526 FDOMAIN_16X0,
527 #endif
528 #ifdef CONFIG_SCSI_IN2000
529 IN2000,
530 #endif
531 #ifdef CONFIG_SCSI_GENERIC_NCR5380
532 GENERIC_NCR5380,
533 #endif
534 #ifdef CONFIG_SCSI_NCR53C406A /* 53C406A should come before QLOGIC */
535 NCR53c406a,
536 #endif
537 #ifdef CONFIG_SCSI_SYM53C416
538 SYM53C416,
539 #endif
540 #ifdef CONFIG_SCSI_QLOGIC_FAS
541 QLOGICFAS,
542 #endif
543 #ifdef CONFIG_SCSI_QLOGIC_ISP
544 QLOGICISP,
545 #endif
546 #ifdef CONFIG_SCSI_QLOGIC_FC
547 QLOGICFC,
548 #endif
549 #ifdef CONFIG_SCSI_QLOGIC_1280
550 QLA1280_LINUX_TEMPLATE,
551 #endif
552 #ifdef CONFIG_SCSI_PAS16
553 MV_PAS16,
554 #endif
555 #ifdef CONFIG_SCSI_SEAGATE
556 SEAGATE_ST0X,
557 #endif
558 #ifdef CONFIG_SCSI_T128
559 TRANTOR_T128,
560 #endif
561 #ifdef CONFIG_SCSI_DMX3191D
562 DMX3191D,
563 #endif
564 #ifdef CONFIG_SCSI_DTC3280
565 DTC3x80,
566 #endif
567 #ifdef CONFIG_SCSI_NCR53C7xx
568 NCR53c7xx,
569 #endif
570 #ifdef CONFIG_SCSI_SYM53C8XX
571 SYM53C8XX,
572 #endif
573 #ifdef CONFIG_SCSI_NCR53C8XX
574 NCR53C8XX,
575 #endif
576 #ifdef CONFIG_SCSI_EATA_DMA
577 EATA_DMA,
578 #endif
579 #ifdef CONFIG_SCSI_EATA_PIO
580 EATA_PIO,
581 #endif
582 #ifdef CONFIG_SCSI_7000FASST
583 WD7000,
584 #endif
585 #ifdef CONFIG_SCSI_MCA_53C9X
586 MCA_53C9X,
587 #endif
588 #ifdef CONFIG_SCSI_IBMMCA
589 IBMMCA,
590 #endif
591 #ifdef CONFIG_SCSI_EATA
592 EATA,
593 #endif
594 #ifdef CONFIG_SCSI_DC390T
595 DC390_T,
596 #endif
597 #ifdef CONFIG_SCSI_AM53C974
598 AM53C974,
599 #endif
600 #ifdef CONFIG_SCSI_MEGARAID
601 MEGARAID,
602 #endif
603 #ifdef CONFIG_SCSI_ACARD
604 ATP870U,
605 #endif
606 #ifdef CONFIG_SCSI_SUNESP
607 SCSI_SPARC_ESP,
608 #endif
609 #ifdef CONFIG_SCSI_GDTH
610 GDTH,
611 #endif
612 #ifdef CONFIG_SCSI_INITIO
613 INI9100U,
614 #endif
615 #ifdef CONFIG_SCSI_INIA100
616 INIA100,
617 #endif
618 #ifdef CONFIG_SCSI_QLOGICPTI
619 QLOGICPTI,
620 #endif
621 #ifdef CONFIG_BLK_DEV_IDESCSI
622 IDESCSI,
623 #endif
624 #ifdef CONFIG_SCSI_MESH
625 SCSI_MESH,
626 #endif
627 #ifdef CONFIG_SCSI_MAC53C94
628 SCSI_MAC53C94,
629 #endif
630 #ifdef CONFIG_SCSI_PLUTO
631 PLUTO,
632 #endif
633 #ifdef CONFIG_ARCH_ACORN
634 #ifdef CONFIG_SCSI_ACORNSCSI_3
635 ACORNSCSI_3,
636 #endif
637 #ifdef CONFIG_SCSI_CUMANA_1
638 CUMANA_NCR5380,
639 #endif
640 #ifdef CONFIG_SCSI_CUMANA_2
641 CUMANA_FAS216,
642 #endif
643 #ifdef CONFIG_SCSI_ECOSCSI
644 ECOSCSI_NCR5380,
645 #endif
646 #ifdef CONFIG_SCSI_OAK1
647 OAK_NCR5380,
648 #endif
649 #ifdef CONFIG_SCSI_POWERTECSCSI
650 POWERTECSCSI,
651 #endif
652 #endif
653 #ifdef CONFIG_IPHASE5526
654 IPH5526_SCSI_FC,
655 #endif
656 #ifdef CONFIG_SCSI_DECNCR
657 SCSI_DEC_ESP,
658 #endif
659 #ifdef CONFIG_BLK_DEV_3W_XXXX_RAID
660 TWXXXX,
661 #endif
662 /* "Removable host adapters" below this line (Parallel Port/USB/other) */
663 #ifdef CONFIG_SCSI_PPA
664 PPA,
665 #endif
666 #ifdef CONFIG_SCSI_IMM
667 IMM,
668 #endif
669 #ifdef CONFIG_SCSI_SGIWD93
670 SGIWD93_SCSI,
671 #endif
672 #ifdef CONFIG_JAZZ_ESP
673 SCSI_JAZZ_ESP,
674 #endif
675 #ifdef CONFIG_SUN3X_ESP
676 SCSI_SUN3X_ESP,
677 #endif
678 #ifdef CONFIG_SCSI_DEBUG
679 SCSI_DEBUG,
680 #endif
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;
698 void
699 scsi_unregister(struct Scsi_Host * sh){
700 struct Scsi_Host * shpnt;
701 Scsi_Host_Name *shn;
703 if(scsi_hostlist == sh)
704 scsi_hostlist = sh->next;
705 else {
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);
717 shn=shn->next);
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)
730 shpnt = shpnt->next;
731 if(shpnt)
732 break;
735 next_scsi_host--;
736 kfree((char *) sh);
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;
747 int new = 1;
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))) {
756 new = 0;
757 retval->host_no = shn->host_no;
758 shn->host_registered = 1;
759 shn->loaded_as_module = scsi_loadable_module_flag;
760 break;
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;
768 if (new) {
769 int len = 0;
770 shn = (Scsi_Host_Name *) kmalloc(sizeof(Scsi_Host_Name), GFP_ATOMIC);
771 if (tpnt->proc_dir)
772 len = strlen(tpnt->proc_dir->name);
773 shn->name = kmalloc(len+1, GFP_ATOMIC);
774 if (tpnt->proc_dir)
775 strncpy(shn->name, tpnt->proc_dir->name, len);
776 shn->name[len] = 0;
777 shn->host_no = max_scsi_hosts++;
778 shn->host_registered = 1;
779 shn->loaded_as_module = scsi_loadable_module_flag;
780 shn->next = NULL;
781 if (scsi_host_no_list) {
782 for (shn2 = scsi_host_no_list;shn2->next;shn2 = shn2->next)
784 shn2->next = shn;
786 else
787 scsi_host_no_list = shn;
788 retval->host_no = shn->host_no;
790 next_scsi_host++;
791 retval->host_queue = NULL;
792 init_waitqueue_head(&retval->host_wait);
793 retval->resetting = 0;
794 retval->last_reset = 0;
795 retval->irq = 0;
796 retval->dma_channel = 0xff;
798 /* These three are default values which can be overridden */
799 retval->max_channel = 0;
800 retval->max_id = 8;
801 retval->max_lun = 8;
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;
812 retval->io_port = 0;
813 retval->hostt = tpnt;
814 retval->next = NULL;
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;
823 #ifdef DEBUG
824 printk("Register %x %x: %d\n", (int)retval, (int)retval->hostt, j);
825 #endif
827 /* The next six are the default values which can be overridden
828 * if need be */
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;
838 if(!scsi_hostlist)
839 scsi_hostlist = retval;
840 else
842 shpnt = scsi_hostlist;
843 while(shpnt->next) shpnt = shpnt->next;
844 shpnt->next = retval;
847 return 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;
856 return 0;
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,
876 (void *) shpnt, 0);
879 * Now wait for the kernel error thread to initialize itself
880 * as it might be needed when we scan the bus.
882 down (&sem);
883 shpnt->eh_notify = NULL;
886 unsigned int __init scsi_init(void)
888 static int called = 0;
889 int i, pcount;
890 unsigned long flags;
891 Scsi_Host_Template * tpnt;
892 struct Scsi_Host * shpnt;
893 const char * name;
895 if(called) return 0;
897 called = 1;
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;
906 if (tpnt->detect) {
908 /* The detect routine must carefully spinunlock/spinlock if
909 it enables interrupts, since all interrupt handlers do
910 spinlock as well.
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);
921 else
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;
938 scsi_hosts = tpnt;
940 /* Add the driver to /proc/scsi */
941 #if CONFIG_PROC_FS
942 build_proc_dir_entries(tpnt);
943 #endif
947 for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
949 if(shpnt->hostt->info)
950 name = shpnt->hostt->info(shpnt);
951 else
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);
971 #endif
972 #ifdef CONFIG_BLK_DEV_SR
973 scsi_register_device(&sr_template);
974 #endif
975 #ifdef CONFIG_CHR_DEV_ST
976 scsi_register_device(&st_template);
977 #endif
978 #ifdef CONFIG_CHR_DEV_SG
979 scsi_register_device(&sg_template);
980 #endif
982 #if 0
983 max_scsi_hosts = next_scsi_host;
984 #endif
985 return 0;
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
992 * of the file.
993 * ---------------------------------------------------------------------------
994 * Local variables:
995 * c-indent-level: 4
996 * c-brace-imaginary-offset: 0
997 * c-brace-offset: -4
998 * c-argdecl-indent: 4
999 * c-label-offset: -4
1000 * c-continued-statement-offset: 4
1001 * c-continued-brace-offset: 0
1002 * indent-tabs-mode: nil
1003 * tab-width: 8
1004 * End: