1 /* $NetBSD: ahc_isa.c,v 1.36 2009/05/04 12:14:31 cegger Exp $ */
4 * Product specific probe and attach routines for:
5 * AHA-284X VL-bus SCSI controllers
7 * Copyright (c) 1994, 1995, 1996, 1997, 1998 Justin T. Gibbs.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.15 2000/01/29 14:22:19 peter Exp $
35 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
36 * All rights reserved.
38 * This code is derived from software contributed to The NetBSD Foundation
39 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
40 * NASA Ames Research Center.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
51 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
52 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
53 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
54 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
55 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
56 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
57 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
58 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
59 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
61 * POSSIBILITY OF SUCH DAMAGE.
65 * Copyright (c) 1995, 1996 Christopher G. Demetriou
66 * All rights reserved.
68 * Redistribution and use in source and binary forms, with or without
69 * modification, are permitted provided that the following conditions
71 * 1. Redistributions of source code must retain the above copyright
72 * notice, this list of conditions and the following disclaimer.
73 * 2. Redistributions in binary form must reproduce the above copyright
74 * notice, this list of conditions and the following disclaimer in the
75 * documentation and/or other materials provided with the distribution.
76 * 3. All advertising materials mentioning features or use of this software
77 * must display the following acknowledgement:
78 * This product includes software developed by Christopher G. Demetriou
79 * for the NetBSD Project.
80 * 4. The name of the author may not be used to endorse or promote products
81 * derived from this software without specific prior written permission
83 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
84 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
85 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
86 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
87 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
88 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
89 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
90 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
91 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
92 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96 * This front-end driver is really sort of a hack. The AHA-284X likes
97 * to masquerade as an EISA device. However, on VLbus machines with
98 * no EISA signature in the BIOS, the EISA bus will never be scanned.
99 * This is intended to catch the 284X controllers on those systems
100 * by looking in "EISA i/o space" for 284X controllers.
102 * This relies heavily on i/o port accounting. We also just use the
103 * EISA macros for everything ... it's a real waste to redefine them.
105 * Note: there isn't any #ifdef for FreeBSD in this file, since the
106 * FreeBSD EISA driver handles all cases of the 284X.
108 * -- Jason R. Thorpe <thorpej@NetBSD.org>
112 #include <sys/cdefs.h>
113 __KERNEL_RCSID(0, "$NetBSD: ahc_isa.c,v 1.36 2009/05/04 12:14:31 cegger Exp $");
115 #include <sys/param.h>
116 #include <sys/systm.h>
117 #include <sys/kernel.h>
118 #include <sys/device.h>
119 #include <sys/queue.h>
120 #include <sys/malloc.h>
121 #include <sys/reboot.h>
123 #include <machine/bus.h>
124 #include <machine/intr.h>
126 #include <dev/scsipi/scsi_all.h>
127 #include <dev/scsipi/scsipi_all.h>
128 #include <dev/scsipi/scsiconf.h>
130 #include <dev/isa/isavar.h>
132 #include <dev/eisa/eisareg.h>
133 #include <dev/eisa/eisavar.h>
134 #include <dev/eisa/eisadevs.h>
136 #include <dev/ic/aic7xxx_osm.h>
137 #include <dev/ic/aic7xxx_inline.h>
138 #include <dev/ic/aic77xxreg.h>
139 #include <dev/ic/aic77xxvar.h>
140 #include <dev/ic/smc93cx6var.h>
142 /* IO port address setting range as EISA slot number */
143 #define AHC_ISA_MIN_SLOT 0x1 /* from iobase = 0x1c00 */
144 #define AHC_ISA_MAX_SLOT 0xe /* to iobase = 0xec00 */
146 #define AHC_ISA_SLOT_OFFSET AHC_EISA_SLOT_OFFSET
147 #define AHC_ISA_IOSIZE AHC_EISA_IOSIZE
152 #define AHC_ISA_VID (EISA_SLOTOFF_VID - AHC_ISA_SLOT_OFFSET)
153 #define AHC_ISA_PID (EISA_SLOTOFF_PID - AHC_ISA_SLOT_OFFSET)
154 #define AHC_ISA_PRIMING AHC_ISA_VID /* enable vendor/product ID */
157 * AHC_ISA_PRIMING register values (write)
159 #define AHC_ISA_PRIMING_VID(index) (AHC_ISA_VID + (index))
160 #define AHC_ISA_PRIMING_PID(index) (AHC_ISA_PID + (index))
162 int ahc_isa_idstring(bus_space_tag_t
, bus_space_handle_t
, char *);
163 int ahc_isa_match(struct isa_attach_args
*, bus_addr_t
);
165 int ahc_isa_probe(device_t
, cfdata_t
, void *);
166 void ahc_isa_attach(device_t
, device_t
, void *);
167 void aha2840_load_seeprom(struct ahc_softc
*ahc
);
168 static int verify_seeprom_cksum(struct seeprom_config
*sc
);
170 CFATTACH_DECL_NEW(ahc_isa
, sizeof(struct ahc_softc
),
171 ahc_isa_probe
, ahc_isa_attach
, NULL
, NULL
);
174 * This keeps track of which slots are to be checked next if the
175 * iobase locator is a wildcard. A simple static variable isn't enough,
176 * since it's conceivable that a system might have more than one ISA
179 * The "bus" member is the unit number of the parent ISA bus, e.g. "0"
182 struct ahc_isa_slot
{
183 LIST_ENTRY(ahc_isa_slot
) link
;
187 static LIST_HEAD(, ahc_isa_slot
) ahc_isa_all_slots
;
188 static int ahc_isa_slot_initialized
;
191 ahc_isa_idstring(bus_space_tag_t iot
, bus_space_handle_t ioh
, char *idstring
)
193 uint8_t vid
[EISA_NVIDREGS
], pid
[EISA_NPIDREGS
];
196 /* Get the vendor ID bytes */
197 for (i
= 0; i
< EISA_NVIDREGS
; i
++) {
198 bus_space_write_1(iot
, ioh
, AHC_ISA_PRIMING
,
199 AHC_ISA_PRIMING_VID(i
));
200 vid
[i
] = bus_space_read_1(iot
, ioh
, AHC_ISA_VID
+ i
);
203 /* Check for device existence */
204 if (EISA_VENDID_NODEV(vid
)) {
206 aprint_error("ahc_isa_idstring: no device at 0x%lx\n",
207 ioh
); /* XXX knows about ioh guts */
208 aprint_error("\t(0x%x, 0x%x)\n", vid
[0], vid
[1]);
213 /* And check that the firmware didn't biff something badly */
214 if (EISA_VENDID_IDDELAY(vid
)) {
215 aprint_error("ahc_isa_idstring: BIOS biffed it at 0x%lx\n",
216 ioh
); /* XXX knows about ioh guts */
220 /* Get the product ID bytes */
221 for (i
= 0; i
< EISA_NPIDREGS
; i
++) {
222 bus_space_write_1(iot
, ioh
, AHC_ISA_PRIMING
,
223 AHC_ISA_PRIMING_PID(i
));
224 pid
[i
] = bus_space_read_1(iot
, ioh
, AHC_ISA_PID
+ i
);
227 /* Create the ID string from the vendor and product IDs */
228 idstring
[0] = EISA_VENDID_0(vid
);
229 idstring
[1] = EISA_VENDID_1(vid
);
230 idstring
[2] = EISA_VENDID_2(vid
);
231 idstring
[3] = EISA_PRODID_0(pid
);
232 idstring
[4] = EISA_PRODID_1(pid
);
233 idstring
[5] = EISA_PRODID_2(pid
);
234 idstring
[6] = EISA_PRODID_3(pid
);
235 idstring
[7] = '\0'; /* sanity */
241 ahc_isa_match(struct isa_attach_args
*ia
, bus_addr_t iobase
)
243 bus_space_tag_t iot
= ia
->ia_iot
;
244 bus_space_handle_t ioh
;
246 char idstring
[EISA_IDSTRINGLEN
];
249 * Get a mapping for the while slot-specific address
250 * space. If we can't, assume nothing's there, but
253 if (bus_space_map(iot
, iobase
, AHC_ISA_IOSIZE
, 0, &ioh
)) {
256 * Don't print anything out here, since this could
257 * be common on machines configured to look for
258 * ahc_eisa and ahc_isa.
260 aprint_error("ahc_isa_match: can't map I/O space for 0x%x\n",
266 if (!ahc_isa_idstring(iot
, ioh
, idstring
))
267 irq
= -1; /* cannot get the ID string */
268 else if (strcmp(idstring
, "ADP7756") &&
269 strcmp(idstring
, "ADP7757"))
270 irq
= -1; /* unknown ID strings */
272 irq
= ahc_aic77xx_irq(iot
, ioh
);
274 bus_space_unmap(iot
, ioh
, AHC_ISA_IOSIZE
);
279 if (ia
->ia_irq
[0].ir_irq
!= ISA_UNKNOWN_IRQ
&&
280 ia
->ia_irq
[0].ir_irq
!= irq
) {
281 aprint_error("ahc_isa_match: irq mismatch (kernel %d, card %d)\n",
282 ia
->ia_irq
[0].ir_irq
, irq
);
286 /* We have a match */
288 ia
->ia_io
[0].ir_addr
= iobase
;
289 ia
->ia_io
[0].ir_size
= AHC_ISA_IOSIZE
;
292 ia
->ia_irq
[0].ir_irq
= irq
;
301 * Check the slots looking for a board we recognise
302 * If we find one, note it's address (slot) and call
303 * the actual probe routine to check it out.
306 ahc_isa_probe(device_t parent
, cfdata_t match
, void *aux
)
308 struct isa_attach_args
*ia
= aux
;
309 struct ahc_isa_slot
*as
;
311 if (ahc_isa_slot_initialized
== 0) {
312 LIST_INIT(&ahc_isa_all_slots
);
313 ahc_isa_slot_initialized
= 1;
321 if (ISA_DIRECT_CONFIG(ia
))
324 if (ia
->ia_io
[0].ir_addr
!= ISA_UNKNOWN_PORT
)
325 return (ahc_isa_match(ia
, ia
->ia_io
[0].ir_addr
));
328 * Find this bus's state. If we don't yet have a slot
329 * marker, allocate and initialize one.
331 for (as
= ahc_isa_all_slots
.lh_first
; as
!= NULL
;
332 as
= as
->link
.le_next
)
333 if (as
->bus
== device_unit(parent
))
334 goto found_slot_marker
;
337 * Don't have one, so make one.
339 as
= (struct ahc_isa_slot
*)
340 malloc(sizeof(struct ahc_isa_slot
), M_DEVBUF
, M_NOWAIT
);
342 panic("ahc_isa_probe: can't allocate slot marker");
344 as
->bus
= device_unit(parent
);
345 as
->slot
= AHC_ISA_MIN_SLOT
;
346 LIST_INSERT_HEAD(&ahc_isa_all_slots
, as
, link
);
350 for (; as
->slot
<= AHC_ISA_MAX_SLOT
; as
->slot
++) {
351 if (ahc_isa_match(ia
, EISA_SLOT_ADDR(as
->slot
) +
352 AHC_ISA_SLOT_OFFSET
)) {
353 as
->slot
++; /* next slot to search */
358 /* No matching cards were found. */
363 ahc_isa_attach(device_t parent
, device_t self
, void *aux
)
365 struct ahc_softc
*ahc
= device_private(self
);
366 struct isa_attach_args
*ia
= aux
;
367 bus_space_tag_t iot
= ia
->ia_iot
;
368 bus_space_handle_t ioh
;
370 const char *intrtypestr
;
371 char idstring
[EISA_IDSTRINGLEN
];
375 aprint_naive(": SCSI controller\n");
377 if (bus_space_map(iot
, ia
->ia_io
[0].ir_addr
, ia
->ia_io
[0].ir_size
,
379 aprint_error(": can't map i/o space\n");
382 if (!ahc_isa_idstring(iot
, ioh
, idstring
)) {
383 aprint_error(": can't read ID string\n");
386 if ((irq
= ahc_aic77xx_irq(iot
, ioh
)) < 0) {
387 aprint_error(": ahc_aic77xx_irq failed\n");
391 if (strcmp(idstring
, "ADP7756") == 0) {
392 aprint_normal(": %s\n", EISA_PRODUCT_ADP7756
);
393 } else if (strcmp(idstring
, "ADP7757") == 0) {
394 aprint_normal(": %s\n", EISA_PRODUCT_ADP7757
);
396 aprint_error(": unknown device type %s\n", idstring
);
401 * Tell the bus-DMA interface that we can do 32bit DMA
402 * NOTE: this variable is first referenced in ahc_init().
404 ahc
->sc_dmaflags
= ISABUS_DMA_32BIT
;
406 ahc_set_name(ahc
, device_xname(ahc
->sc_dev
));
407 ahc
->parent_dmat
= ia
->ia_dmat
;
409 ahc
->chip
= AHC_AIC7770
|AHC_VL
;
410 ahc
->features
= AHC_AIC7770_FE
;
411 ahc
->bugs
|= AHC_TMODE_WIDEODD_BUG
;
412 ahc
->flags
|= AHC_PAGESCBS
;
416 if (ahc_softc_init(ahc
) != 0)
419 ahc_intr_enable(ahc
, false);
421 if (ahc_reset(ahc
) != 0)
424 intdef
= bus_space_read_1(iot
, ioh
, INTDEF
);
426 if (intdef
& EDGE_TRIG
) {
428 intrtypestr
= "edge triggered";
430 intrtype
= IST_LEVEL
;
431 intrtypestr
= "level sensitive";
433 ahc
->ih
= isa_intr_establish(ia
->ia_ic
, irq
,
434 intrtype
, IPL_BIO
, ahc_intr
, ahc
);
435 if (ahc
->ih
== NULL
) {
436 aprint_error_dev(ahc
->sc_dev
, "couldn't establish %s interrupt\n",
442 * Tell the user what type of interrupts we're using.
443 * usefull for debugging irq problems
446 aprint_verbose_dev(ahc
->sc_dev
, "Using %s interrupts\n",
451 * Now that we know we own the resources we need, do the
452 * card initialization.
454 aha2840_load_seeprom(ahc
);
456 /* Attach sub-devices */
457 if (ahc_aic77xx_attach(ahc
) == 0)
458 return; /* succeed */
461 isa_intr_disestablish(ia
->ia_ic
, ahc
->ih
);
463 bus_space_unmap(iot
, ioh
, ia
->ia_io
[0].ir_size
);
467 * Read the 284x SEEPROM.
470 aha2840_load_seeprom(struct ahc_softc
*ahc
)
472 struct seeprom_descriptor sd
;
473 struct seeprom_config sc
;
477 sd
.sd_tag
= ahc
->tag
;
478 sd
.sd_bsh
= ahc
->bsh
;
479 sd
.sd_control_offset
= SEECTL_2840
;
480 sd
.sd_status_offset
= STATUS_2840
;
481 sd
.sd_dataout_offset
= STATUS_2840
;
484 sd
.sd_RDY
= EEPROM_TF
;
491 aprint_verbose("%s: Reading SEEPROM...", ahc_name(ahc
));
492 have_seeprom
= read_seeprom(&sd
, (uint16_t *)&sc
,
493 /*start_addr*/0, sizeof(sc
)/2);
496 if (verify_seeprom_cksum(&sc
) == 0) {
498 aprint_verbose ("checksum error\n");
500 } else if (bootverbose
) {
501 aprint_verbose("done.\n");
507 aprint_verbose("%s: No SEEPROM available\n",
509 ahc
->flags
|= AHC_USEDEFAULTS
;
512 * Put the data we've collected down into SRAM
513 * where ahc_init will find it.
516 int max_targ
= (ahc
->features
& AHC_WIDE
) != 0 ? 16 : 8;
520 for (i
= 0; i
< max_targ
; i
++){
521 uint8_t target_settings
;
522 target_settings
= (sc
.device_flags
[i
] & CFXFER
) << 4;
523 if (sc
.device_flags
[i
] & CFSYNCH
)
524 target_settings
|= SOFS
;
525 if (sc
.device_flags
[i
] & CFWIDEB
)
526 target_settings
|= WIDEXFER
;
527 if (sc
.device_flags
[i
] & CFDISC
)
528 discenable
|= (0x01 << i
);
529 ahc_outb(ahc
, TARG_SCSIRATE
+ i
, target_settings
);
531 ahc_outb(ahc
, DISC_DSB
, ~(discenable
& 0xff));
532 ahc_outb(ahc
, DISC_DSB
+ 1, ~((discenable
>> 8) & 0xff));
534 ahc
->our_id
= sc
.brtime_id
& CFSCSIID
;
536 scsi_conf
= (ahc
->our_id
& 0x7);
537 if (sc
.adapter_control
& CFSPARITY
)
538 scsi_conf
|= ENSPCHK
;
539 if (sc
.adapter_control
& CFRESETB
)
540 scsi_conf
|= RESET_SCSI
;
542 if (sc
.bios_control
& CF284XEXTEND
)
543 ahc
->flags
|= AHC_EXTENDED_TRANS_A
;
544 /* Set SCSICONF info */
545 ahc_outb(ahc
, SCSICONF
, scsi_conf
);
547 if (sc
.adapter_control
& CF284XSTERM
)
548 ahc
->flags
|= AHC_TERM_ENB_A
;
553 verify_seeprom_cksum(struct seeprom_config
*sc
)
560 maxaddr
= (sizeof(*sc
)/2) - 1;
562 scarray
= (uint16_t *)sc
;
564 for (i
= 0; i
< maxaddr
; i
++)
565 checksum
= checksum
+ scarray
[i
];
567 || (checksum
& 0xFFFF) != sc
->checksum
) {