Import 2.3.46pre5
[davej-history.git] / drivers / scsi / hosts.c
blob82a1f2ef1bde7bc39a048265da56cb465683748a
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_DTC3280
209 #include "dtc.h"
210 #endif
212 #ifdef CONFIG_SCSI_NCR53C7xx
213 #include "53c7,8xx.h"
214 #endif
216 #ifdef CONFIG_SCSI_SYM53C8XX
217 #include "sym53c8xx.h"
218 #endif
220 #ifdef CONFIG_SCSI_NCR53C8XX
221 #include "ncr53c8xx.h"
222 #endif
224 #ifdef CONFIG_SCSI_ULTRASTOR
225 #include "ultrastor.h"
226 #endif
228 #ifdef CONFIG_SCSI_7000FASST
229 #include "wd7000.h"
230 #endif
232 #ifdef CONFIG_SCSI_MCA_53C9X
233 #include "mca_53c9x.h"
234 #endif
236 #ifdef CONFIG_SCSI_IBMMCA
237 #include "ibmmca.h"
238 #endif
240 #ifdef CONFIG_SCSI_EATA
241 #include "eata.h"
242 #endif
244 #ifdef CONFIG_SCSI_NCR53C406A
245 #include "NCR53c406a.h"
246 #endif
248 #ifdef CONFIG_SCSI_SYM53C416
249 #include "sym53c416.h"
250 #endif
252 #ifdef CONFIG_SCSI_DC390T
253 #include "dc390.h"
254 #endif
256 #ifdef CONFIG_SCSI_AM53C974
257 #include "AM53C974.h"
258 #endif
260 #ifdef CONFIG_SCSI_MEGARAID
261 #include "megaraid.h"
262 #endif
264 #ifdef CONFIG_SCSI_ACARD
265 #include "atp870u.h"
266 #endif
268 #ifdef CONFIG_SCSI_SUNESP
269 #include "esp.h"
270 #endif
272 #ifdef CONFIG_SCSI_QLOGICPTI
273 #include "qlogicpti.h"
274 #endif
276 #ifdef CONFIG_BLK_DEV_IDESCSI
277 #include "ide-scsi.h"
278 #endif
280 #ifdef CONFIG_SCSI_MESH
281 #include "mesh.h"
282 #endif
284 #ifdef CONFIG_SCSI_MAC53C94
285 #include "mac53c94.h"
286 #endif
288 #ifdef CONFIG_SCSI_GDTH
289 #include "gdth.h"
290 #endif
292 #ifdef CONFIG_SCSI_PCI2000
293 #include "pci2000.h"
294 #endif
296 #ifdef CONFIG_SCSI_PCI2220I
297 #include "pci2220i.h"
298 #endif
300 #ifdef CONFIG_SCSI_PSI240I
301 #include "psi240i.h"
302 #endif
304 #ifdef CONFIG_SCSI_PLUTO
305 #include "pluto.h"
306 #endif
308 #ifdef CONFIG_SCSI_INITIO
309 #include "ini9100u.h"
310 #endif
312 #ifdef CONFIG_SCSI_INIA100
313 #include "inia100.h"
314 #endif
316 #ifdef CONFIG_SCSI_DEBUG
317 #include "scsi_debug.h"
318 #endif
320 #ifdef CONFIG_SCSI_ACORNSCSI_3
321 #include "../acorn/scsi/acornscsi.h"
322 #endif
324 #ifdef CONFIG_SCSI_CUMANA_1
325 #include "../acorn/scsi/cumana_1.h"
326 #endif
328 #ifdef CONFIG_SCSI_CUMANA_2
329 #include "../acorn/scsi/cumana_2.h"
330 #endif
332 #ifdef CONFIG_SCSI_ECOSCSI
333 #include "../acorn/scsi/ecoscsi.h"
334 #endif
336 #ifdef CONFIG_SCSI_OAK1
337 #include "../acorn/scsi/oak.h"
338 #endif
340 #ifdef CONFIG_SCSI_POWERTECSCSI
341 #include "../acorn/scsi/powertec.h"
342 #endif
344 #ifdef CONFIG_JAZZ_ESP
345 #include "jazz_esp.h"
346 #endif
348 #ifdef CONFIG_SUN3X_ESP
349 #include "sun3x_esp.h"
350 #endif
352 #ifdef CONFIG_IPHASE5526
353 #include "../net/fc/iph5526_scsi.h"
354 #endif
356 #ifdef CONFIG_BLK_DEV_3W_XXXX_RAID
357 #include "3w-xxxx.h"
358 #endif
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
367 #include "ppa.h"
368 #endif
370 #ifdef CONFIG_SCSI_IMM
371 #include "imm.h"
372 #endif
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
383 * reentrant, etc.
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
400 * idiocy.
403 Scsi_Host_Template * scsi_hosts = NULL;
405 static Scsi_Host_Template builtin_scsi_hosts[] =
407 #ifdef CONFIG_AMIGA
408 #ifdef AMIGA7XXCONFIG
409 AMIGA7XX_SCSI,
410 #endif
411 #ifdef CONFIG_A3000_SCSI
412 A3000_SCSI,
413 #endif
414 #ifdef CONFIG_A2091_SCSI
415 A2091_SCSI,
416 #endif
417 #ifdef CONFIG_GVP11_SCSI
418 GVP11_SCSI,
419 #endif
420 #ifdef CONFIG_CYBERSTORM_SCSI
421 SCSI_CYBERSTORM,
422 #endif
423 #ifdef CONFIG_CYBERSTORMII_SCSI
424 SCSI_CYBERSTORMII,
425 #endif
426 #ifdef CONFIG_BLZ2060_SCSI
427 SCSI_BLZ2060,
428 #endif
429 #ifdef CONFIG_BLZ1230_SCSI
430 SCSI_BLZ1230,
431 #endif
432 #ifdef CONFIG_FASTLANE_SCSI
433 SCSI_FASTLANE,
434 #endif
435 #ifdef CONFIG_OKTAGON_SCSI
436 SCSI_OKTAGON_ESP,
437 #endif
438 #endif
440 #ifdef CONFIG_ATARI
441 #ifdef CONFIG_ATARI_SCSI
442 ATARI_SCSI,
443 #endif
444 #endif
446 #ifdef CONFIG_MAC
447 #ifdef CONFIG_MAC_SCSI_OLD
448 MAC_SCSI,
449 #endif
450 #ifdef CONFIG_SCSI_MAC_ESP
451 SCSI_MAC_ESP,
452 #endif
453 #ifdef CONFIG_MAC_SCSI
454 MAC_NCR5380,
455 #endif
456 #endif
458 #ifdef CONFIG_SUN3_SCSI
459 SUN3_NCR5380,
460 #endif
462 #ifdef CONFIG_MVME16x_SCSI
463 MVME16x_SCSI,
464 #endif
465 #ifdef CONFIG_BVME6000_SCSI
466 BVME6000_SCSI,
467 #endif
468 #ifdef CONFIG_SCSI_SIM710
469 SIM710_SCSI,
470 #endif
471 #ifdef CONFIG_SCSI_ADVANSYS
472 ADVANSYS,
473 #endif
475 #ifdef CONFIG_SCSI_PCI2000
476 PCI2000,
477 #endif
478 #ifdef CONFIG_SCSI_PCI2220I
479 PCI2220I,
480 #endif
481 #ifdef CONFIG_SCSI_PSI240I
482 PSI240I,
483 #endif
485 /* BusLogic must come before aha1542.c */
486 #ifdef CONFIG_SCSI_BUSLOGIC
487 BUSLOGIC,
488 #endif
489 #ifdef CONFIG_SCSI_U14_34F
490 ULTRASTOR_14_34F,
491 #endif
492 #ifdef CONFIG_SCSI_ULTRASTOR
493 ULTRASTOR_14F,
494 #endif
495 #ifdef CONFIG_SCSI_AHA152X
496 AHA152X,
497 #endif
498 #ifdef CONFIG_SCSI_AHA1542
499 AHA1542,
500 #endif
501 #ifdef CONFIG_SCSI_AHA1740
502 AHA1740,
503 #endif
504 #ifdef CONFIG_SCSI_AIC7XXX
505 AIC7XXX,
506 #endif
507 #ifdef CONFIG_SCSI_IPS
508 IPS,
509 #endif
510 #ifdef CONFIG_SCSI_FD_MCS
511 FD_MCS,
512 #endif
513 #ifdef CONFIG_SCSI_FUTURE_DOMAIN
514 FDOMAIN_16X0,
515 #endif
516 #ifdef CONFIG_SCSI_IN2000
517 IN2000,
518 #endif
519 #ifdef CONFIG_SCSI_GENERIC_NCR5380
520 GENERIC_NCR5380,
521 #endif
522 #ifdef CONFIG_SCSI_NCR53C406A /* 53C406A should come before QLOGIC */
523 NCR53c406a,
524 #endif
525 #ifdef CONFIG_SCSI_SYM53C416
526 SYM53C416,
527 #endif
528 #ifdef CONFIG_SCSI_QLOGIC_FAS
529 QLOGICFAS,
530 #endif
531 #ifdef CONFIG_SCSI_QLOGIC_ISP
532 QLOGICISP,
533 #endif
534 #ifdef CONFIG_SCSI_QLOGIC_FC
535 QLOGICFC,
536 #endif
537 #ifdef CONFIG_SCSI_QLOGIC_1280
538 QLA1280_LINUX_TEMPLATE,
539 #endif
540 #ifdef CONFIG_SCSI_PAS16
541 MV_PAS16,
542 #endif
543 #ifdef CONFIG_SCSI_SEAGATE
544 SEAGATE_ST0X,
545 #endif
546 #ifdef CONFIG_SCSI_T128
547 TRANTOR_T128,
548 #endif
549 #ifdef CONFIG_SCSI_DTC3280
550 DTC3x80,
551 #endif
552 #ifdef CONFIG_SCSI_NCR53C7xx
553 NCR53c7xx,
554 #endif
555 #ifdef CONFIG_SCSI_SYM53C8XX
556 SYM53C8XX,
557 #endif
558 #ifdef CONFIG_SCSI_NCR53C8XX
559 NCR53C8XX,
560 #endif
561 #ifdef CONFIG_SCSI_EATA_DMA
562 EATA_DMA,
563 #endif
564 #ifdef CONFIG_SCSI_EATA_PIO
565 EATA_PIO,
566 #endif
567 #ifdef CONFIG_SCSI_7000FASST
568 WD7000,
569 #endif
570 #ifdef CONFIG_SCSI_MCA_53C9X
571 MCA_53C9X,
572 #endif
573 #ifdef CONFIG_SCSI_IBMMCA
574 IBMMCA,
575 #endif
576 #ifdef CONFIG_SCSI_EATA
577 EATA,
578 #endif
579 #ifdef CONFIG_SCSI_DC390T
580 DC390_T,
581 #endif
582 #ifdef CONFIG_SCSI_AM53C974
583 AM53C974,
584 #endif
585 #ifdef CONFIG_SCSI_MEGARAID
586 MEGARAID,
587 #endif
588 #ifdef CONFIG_SCSI_ACARD
589 ATP870U,
590 #endif
591 #ifdef CONFIG_SCSI_SUNESP
592 SCSI_SPARC_ESP,
593 #endif
594 #ifdef CONFIG_SCSI_GDTH
595 GDTH,
596 #endif
597 #ifdef CONFIG_SCSI_INITIO
598 INI9100U,
599 #endif
600 #ifdef CONFIG_SCSI_INIA100
601 INIA100,
602 #endif
603 #ifdef CONFIG_SCSI_QLOGICPTI
604 QLOGICPTI,
605 #endif
606 #ifdef CONFIG_BLK_DEV_IDESCSI
607 IDESCSI,
608 #endif
609 #ifdef CONFIG_SCSI_MESH
610 SCSI_MESH,
611 #endif
612 #ifdef CONFIG_SCSI_MAC53C94
613 SCSI_MAC53C94,
614 #endif
615 #ifdef CONFIG_SCSI_PLUTO
616 PLUTO,
617 #endif
618 #ifdef CONFIG_ARCH_ACORN
619 #ifdef CONFIG_SCSI_ACORNSCSI_3
620 ACORNSCSI_3,
621 #endif
622 #ifdef CONFIG_SCSI_CUMANA_1
623 CUMANA_NCR5380,
624 #endif
625 #ifdef CONFIG_SCSI_CUMANA_2
626 CUMANA_FAS216,
627 #endif
628 #ifdef CONFIG_SCSI_ECOSCSI
629 ECOSCSI_NCR5380,
630 #endif
631 #ifdef CONFIG_SCSI_OAK1
632 OAK_NCR5380,
633 #endif
634 #ifdef CONFIG_SCSI_POWERTECSCSI
635 POWERTECSCSI,
636 #endif
637 #endif
638 #ifdef CONFIG_IPHASE5526
639 IPH5526_SCSI_FC,
640 #endif
641 #ifdef CONFIG_BLK_DEV_3W_XXXX_RAID
642 TWXXXX,
643 #endif
645 /* "Removable host adapters" below this line (Parallel Port/USB/other) */
646 #ifdef CONFIG_SCSI_PPA
647 PPA,
648 #endif
649 #ifdef CONFIG_SCSI_IMM
650 IMM,
651 #endif
652 #ifdef CONFIG_SUN3X_ESP
653 SCSI_SUN3X_ESP,
654 #endif
655 #ifdef CONFIG_SCSI_DEBUG
656 SCSI_DEBUG,
657 #endif
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;
675 void
676 scsi_unregister(struct Scsi_Host * sh){
677 struct Scsi_Host * shpnt;
678 Scsi_Host_Name *shn;
680 if(scsi_hostlist == sh)
681 scsi_hostlist = sh->next;
682 else {
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);
694 shn=shn->next);
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)
707 shpnt = shpnt->next;
708 if(shpnt)
709 break;
712 next_scsi_host--;
713 kfree((char *) sh);
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;
724 int new = 1;
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))) {
733 new = 0;
734 retval->host_no = shn->host_no;
735 shn->host_registered = 1;
736 shn->loaded_as_module = scsi_loadable_module_flag;
737 break;
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;
745 if (new) {
746 int len = 0;
747 shn = (Scsi_Host_Name *) kmalloc(sizeof(Scsi_Host_Name), GFP_ATOMIC);
748 if (tpnt->proc_dir)
749 len = strlen(tpnt->proc_dir->name);
750 shn->name = kmalloc(len+1, GFP_ATOMIC);
751 if (tpnt->proc_dir)
752 strncpy(shn->name, tpnt->proc_dir->name, len);
753 shn->name[len] = 0;
754 shn->host_no = max_scsi_hosts++;
755 shn->host_registered = 1;
756 shn->loaded_as_module = scsi_loadable_module_flag;
757 shn->next = NULL;
758 if (scsi_host_no_list) {
759 for (shn2 = scsi_host_no_list;shn2->next;shn2 = shn2->next)
761 shn2->next = shn;
763 else
764 scsi_host_no_list = shn;
765 retval->host_no = shn->host_no;
767 next_scsi_host++;
768 retval->host_queue = NULL;
769 init_waitqueue_head(&retval->host_wait);
770 retval->resetting = 0;
771 retval->last_reset = 0;
772 retval->irq = 0;
773 retval->dma_channel = 0xff;
775 /* These three are default values which can be overridden */
776 retval->max_channel = 0;
777 retval->max_id = 8;
778 retval->max_lun = 8;
780 retval->unique_id = 0;
781 retval->io_port = 0;
782 retval->hostt = tpnt;
783 retval->next = NULL;
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;
791 #ifdef DEBUG
792 printk("Register %x %x: %d\n", (int)retval, (int)retval->hostt, j);
793 #endif
795 /* The next six are the default values which can be overridden
796 * if need be */
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;
806 if(!scsi_hostlist)
807 scsi_hostlist = retval;
808 else
810 shpnt = scsi_hostlist;
811 while(shpnt->next) shpnt = shpnt->next;
812 shpnt->next = retval;
815 return 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;
824 return 0;
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,
844 (void *) shpnt, 0);
847 * Now wait for the kernel error thread to initialize itself
848 * as it might be needed when we scan the bus.
850 down (&sem);
851 shpnt->eh_notify = NULL;
854 unsigned int __init scsi_init(void)
856 static int called = 0;
857 int i, pcount;
858 unsigned long flags;
859 Scsi_Host_Template * tpnt;
860 struct Scsi_Host * shpnt;
861 const char * name;
863 if(called) return 0;
865 called = 1;
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;
874 if (tpnt->detect) {
876 /* The detect routine must carefully spinunlock/spinlock if
877 it enables interrupts, since all interrupt handlers do
878 spinlock as well.
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);
889 else
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;
906 scsi_hosts = tpnt;
908 /* Add the driver to /proc/scsi */
909 #if CONFIG_PROC_FS
910 build_proc_dir_entries(tpnt);
911 #endif
915 for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
917 if(shpnt->hostt->info)
918 name = shpnt->hostt->info(shpnt);
919 else
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);
939 #endif
940 #ifdef CONFIG_BLK_DEV_SR
941 scsi_register_device(&sr_template);
942 #endif
943 #ifdef CONFIG_CHR_DEV_ST
944 scsi_register_device(&st_template);
945 #endif
946 #ifdef CONFIG_CHR_DEV_SG
947 scsi_register_device(&sg_template);
948 #endif
950 #if 0
951 max_scsi_hosts = next_scsi_host;
952 #endif
953 return 0;
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
960 * of the file.
961 * ---------------------------------------------------------------------------
962 * Local variables:
963 * c-indent-level: 4
964 * c-brace-imaginary-offset: 0
965 * c-brace-offset: -4
966 * c-argdecl-indent: 4
967 * c-label-offset: -4
968 * c-continued-statement-offset: 4
969 * c-continued-brace-offset: 0
970 * indent-tabs-mode: nil
971 * tab-width: 8
972 * End: