ahc_eisa.c revision 1.13 1 /* $NetBSD: ahc_eisa.c,v 1.13 1997/08/27 11:24:42 bouyer Exp $ */
2
3 /*
4 * Product specific probe and attach routines for:
5 * 27/284X and aic7770 motherboard SCSI controllers
6 *
7 * Copyright (c) 1994, 1995, 1996 Justin T. Gibbs.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * from Id: aic7770.c,v 1.29 1996/05/30 07:18:52 gibbs Exp
35 */
36
37 #if defined(__FreeBSD__)
38 #include <eisa.h>
39 #endif
40 #if NEISA > 0 || defined(__NetBSD__)
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #if defined(__FreeBSD__)
45 #include <sys/devconf.h>
46 #endif
47 #include <sys/kernel.h>
48
49 #if defined(__NetBSD__)
50 #include <sys/device.h>
51 #include <machine/bus.h>
52 #include <machine/intr.h>
53 #endif /* defined(__NetBSD__) */
54
55 #include <dev/scsipi/scsi_all.h>
56 #include <dev/scsipi/scsipi_all.h>
57 #include <dev/scsipi/scsiconf.h>
58
59 #if defined(__FreeBSD__)
60
61 #include <machine/clock.h>
62
63 #include <i386/eisa/eisaconf.h>
64 #include <i386/scsi/aic7xxx.h>
65 #include <dev/aic7xxx/aic7xxx_reg.h>
66
67 #define EISA_DEVICE_ID_ADAPTEC_AIC7770 0x04907770
68 #define EISA_DEVICE_ID_ADAPTEC_274x 0x04907771
69 #define EISA_DEVICE_ID_ADAPTEC_284xB 0x04907756 /* BIOS enabled */
70 #define EISA_DEVICE_ID_ADAPTEC_284x 0x04907757 /* BIOS disabled*/
71
72 #elif defined(__NetBSD__)
73
74 #include <dev/eisa/eisareg.h>
75 #include <dev/eisa/eisavar.h>
76 #include <dev/eisa/eisadevs.h>
77
78 #include <dev/ic/aic7xxxreg.h>
79 #include <dev/ic/aic7xxxvar.h>
80
81 #endif /* defined(__NetBSD__) */
82
83 #define AHC_EISA_SLOT_OFFSET 0xc00
84 #define AHC_EISA_IOSIZE 0x100
85 #define INTDEF 0x5cul /* Interrupt Definition Register */
86
87 #if defined(__FreeBSD__)
88
89 static int aic7770probe __P((void));
90 static int aic7770_attach __P((struct eisa_device *e_dev));
91
92 static struct eisa_driver ahc_eisa_driver = {
93 "ahc",
94 aic7770probe,
95 aic7770_attach,
96 /*shutdown*/NULL,
97 &ahc_unit
98 };
99
100 DATA_SET (eisadriver_set, ahc_eisa_driver);
101
102 static struct kern_devconf kdc_aic7770 = {
103 0, 0, 0, /* filled in by dev_attach */
104 "ahc", 0, { MDDT_EISA, 0, "bio" },
105 eisa_generic_externalize, 0, 0, EISA_EXTERNALLEN,
106 &kdc_eisa0, /* parent */
107 0, /* parentdata */
108 DC_UNCONFIGURED, /* always start out here */
109 NULL,
110 DC_CLS_MISC /* host adapters aren't special */
111 };
112
113
114 static char *aic7770_match __P((eisa_id_t type));
115
116 static char*
117 aic7770_match(type)
118 eisa_id_t type;
119 {
120 switch(type) {
121 case EISA_DEVICE_ID_ADAPTEC_AIC7770:
122 return ("Adaptec aic7770 SCSI host adapter");
123 break;
124 case EISA_DEVICE_ID_ADAPTEC_274x:
125 return ("Adaptec 274X SCSI host adapter");
126 break;
127 case EISA_DEVICE_ID_ADAPTEC_284xB:
128 case EISA_DEVICE_ID_ADAPTEC_284x:
129 return ("Adaptec 284X SCSI host adapter");
130 break;
131 default:
132 break;
133 }
134 return (NULL);
135 }
136
137 static int
138 aic7770probe(void)
139 {
140 u_long iobase;
141 char intdef;
142 u_long irq;
143 struct eisa_device *e_dev = NULL;
144 int count;
145
146 count = 0;
147 while ((e_dev = eisa_match_dev(e_dev, aic7770_match))) {
148 iobase = (e_dev->ioconf.slot * EISA_SLOT_SIZE)
149 + AHC_EISA_SLOT_OFFSET;
150 ahc_reset(iobase);
151
152 eisa_add_iospace(e_dev, iobase, AHC_EISA_IOSIZE, RESVADDR_NONE);
153 intdef = inb(INTDEF + iobase);
154 switch (intdef & 0xf) {
155 case 9:
156 irq = 9;
157 break;
158 case 10:
159 irq = 10;
160 break;
161 case 11:
162 irq = 11;
163 break;
164 case 12:
165 irq = 12;
166 break;
167 case 14:
168 irq = 14;
169 break;
170 case 15:
171 irq = 15;
172 break;
173 default:
174 printf("aic7770 at slot %d: illegal "
175 "irq setting %d\n", e_dev->ioconf.slot,
176 intdef);
177 continue;
178 }
179 eisa_add_intr(e_dev, irq);
180 eisa_registerdev(e_dev, &ahc_eisa_driver, &kdc_aic7770);
181 if(e_dev->id == EISA_DEVICE_ID_ADAPTEC_284xB
182 || e_dev->id == EISA_DEVICE_ID_ADAPTEC_284x) {
183 /* Our real parent is the isa bus. Say so. */
184 e_dev->kdc->kdc_parent = &kdc_isa0;
185 }
186 count++;
187 }
188 return count;
189 }
190
191 #elif defined(__NetBSD__)
192
193 /*
194 * Under normal circumstances, these messages are unnecessary
195 * and not terribly cosmetic.
196 */
197 #ifdef DEBUG
198 #define bootverbose 1
199 #else
200 #define bootverbose 0
201 #endif
202
203 int ahc_eisa_irq __P((bus_space_tag_t, bus_space_handle_t));
204 #ifdef __BROKEN_INDIRECT_CONFIG
205 int ahc_eisa_match __P((struct device *, void *, void *));
206 #else
207 int ahc_eisa_match __P((struct device *, struct cfdata *, void *));
208 #endif
209 void ahc_eisa_attach __P((struct device *, struct device *, void *));
210
211
212 struct cfattach ahc_eisa_ca = {
213 sizeof(struct ahc_data), ahc_eisa_match, ahc_eisa_attach
214 };
215
216 /*
217 * Return irq setting of the board, otherwise -1.
218 */
219 int
220 ahc_eisa_irq(iot, ioh)
221 bus_space_tag_t iot;
222 bus_space_handle_t ioh;
223 {
224 int irq;
225 u_char intdef;
226
227 ahc_reset("ahc_eisa", iot, ioh);
228 intdef = bus_space_read_1(iot, ioh, INTDEF);
229 switch (irq = (intdef & 0xf)) {
230 case 9:
231 case 10:
232 case 11:
233 case 12:
234 case 14:
235 case 15:
236 break;
237 default:
238 printf("ahc_eisa_irq: illegal irq setting %d\n", intdef);
239 return -1;
240 }
241
242 /* Note that we are going and return (to probe) */
243 return irq;
244 }
245
246 /*
247 * Check the slots looking for a board we recognise
248 * If we find one, note it's address (slot) and call
249 * the actual probe routine to check it out.
250 */
251 int
252 ahc_eisa_match(parent, match, aux)
253 struct device *parent;
254 #ifdef __BROKEN_INDIRECT_CONFIG
255 void *match;
256 #else
257 struct cfdata *match;
258 #endif
259 void *aux;
260 {
261 struct eisa_attach_args *ea = aux;
262 bus_space_tag_t iot = ea->ea_iot;
263 bus_space_handle_t ioh;
264 int irq;
265
266 /* must match one of our known ID strings */
267 if (strcmp(ea->ea_idstring, "ADP7770") &&
268 strcmp(ea->ea_idstring, "ADP7771")
269 #if 0
270 && strcmp(ea->ea_idstring, "ADP7756") /* not EISA, but VL */
271 && strcmp(ea->ea_idstring, "ADP7757") /* not EISA, but VL */
272 #endif
273 )
274 return (0);
275
276 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
277 AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
278 return (0);
279
280 irq = ahc_eisa_irq(iot, ioh);
281
282 bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
283
284 return (irq >= 0);
285 }
286
287 #endif /* defined(__NetBSD__) */
288
289 #if defined(__FreeBSD__)
290 static int
291 aic7770_attach(e_dev)
292 struct eisa_device *e_dev;
293 #elif defined(__NetBSD__)
294 void
295 ahc_eisa_attach(parent, self, aux)
296 struct device *parent, *self;
297 void *aux;
298 #endif
299 {
300 ahc_type type;
301
302 #if defined(__FreeBSD__)
303 struct ahc_data *ahc;
304 resvaddr_t *iospace;
305 int unit = e_dev->unit;
306 int irq = ffs(e_dev->ioconf.irq) - 1;
307
308 iospace = e_dev->ioconf.ioaddrs.lh_first;
309
310 if(!iospace)
311 return -1;
312
313 switch(e_dev->id) {
314 case EISA_DEVICE_ID_ADAPTEC_AIC7770:
315 type = AHC_AIC7770;
316 break;
317 case EISA_DEVICE_ID_ADAPTEC_274x:
318 type = AHC_274;
319 break;
320 case EISA_DEVICE_ID_ADAPTEC_284xB:
321 case EISA_DEVICE_ID_ADAPTEC_284x:
322 type = AHC_284;
323 break;
324 default:
325 printf("aic7770_attach: Unknown device type!\n");
326 return -1;
327 break;
328 }
329
330 if(!(ahc = ahc_alloc(unit, iospace->addr, type, AHC_FNONE)))
331 return -1;
332
333 eisa_reg_start(e_dev);
334 if(eisa_reg_iospace(e_dev, iospace)) {
335 ahc_free(ahc);
336 return -1;
337 }
338
339 /*
340 * The IRQMS bit enables level sensitive interrupts. Only allow
341 * IRQ sharing if it's set.
342 */
343 if(eisa_reg_intr(e_dev, irq, ahc_intr, (void *)ahc, &bio_imask,
344 /*shared ==*/ahc->pause & IRQMS)) {
345 ahc_free(ahc);
346 return -1;
347 }
348 eisa_reg_end(e_dev);
349
350 #elif defined(__NetBSD__)
351
352 struct ahc_data *ahc = (void *)self;
353 struct eisa_attach_args *ea = aux;
354 bus_space_tag_t iot = ea->ea_iot;
355 bus_space_handle_t ioh;
356 int irq;
357 eisa_chipset_tag_t ec = ea->ea_ec;
358 eisa_intr_handle_t ih;
359 const char *model, *intrstr;
360
361 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
362 AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
363 panic("ahc_eisa_attach: could not map I/O addresses");
364 if ((irq = ahc_eisa_irq(iot, ioh)) < 0)
365 panic("ahc_eisa_attach: ahc_eisa_irq failed!");
366
367 if (strcmp(ea->ea_idstring, "ADP7770") == 0) {
368 model = EISA_PRODUCT_ADP7770;
369 type = AHC_AIC7770;
370 } else if (strcmp(ea->ea_idstring, "ADP7771") == 0) {
371 model = EISA_PRODUCT_ADP7771;
372 type = AHC_274;
373 #if 0
374 } else if (strcmp(ea->ea_idstring, "ADP7756") == 0) {
375 model = EISA_PRODUCT_ADP7756;
376 type = AHC_284;
377 } else if (strcmp(ea->ea_idstring, "ADP7757") == 0) {
378 model = EISA_PRODUCT_ADP7757;
379 type = AHC_284;
380 #endif
381 } else {
382 panic("ahc_eisa_attach: Unknown device type %s\n",
383 ea->ea_idstring);
384 }
385 printf(": %s\n", model);
386
387 ahc_construct(ahc, iot, ioh, type, AHC_FNONE);
388 if (eisa_intr_map(ec, irq, &ih)) {
389 printf("%s: couldn't map interrupt (%d)\n",
390 ahc->sc_dev.dv_xname, irq);
391 return;
392 }
393 #endif /* defined(__NetBSD__) */
394
395 /*
396 * Tell the user what type of interrupts we're using.
397 * usefull for debugging irq problems
398 */
399 if(bootverbose) {
400 printf("%s: Using %s Interrupts\n",
401 ahc_name(ahc),
402 ahc->pause & IRQMS ? "Level Sensitive" : "Edge Triggered");
403 }
404
405 /*
406 * Now that we know we own the resources we need, do the
407 * card initialization.
408 *
409 * First, the aic7770 card specific setup.
410 */
411 switch( ahc->type ) {
412 case AHC_AIC7770:
413 case AHC_274:
414 {
415 u_char biosctrl = AHC_INB(ahc, HA_274_BIOSCTRL);
416
417 /* Get the primary channel information */
418 ahc->flags |= (biosctrl & CHANNEL_B_PRIMARY);
419
420 if((biosctrl & BIOSMODE) == BIOSDISABLED)
421 ahc->flags |= AHC_USEDEFAULTS;
422 break;
423 }
424 case AHC_284:
425 {
426 /* XXX
427 * All values are automagically intialized at
428 * POST for these cards, so we can always rely
429 * on the Scratch Ram values. However, we should
430 * read the SEEPROM here (Dan has the code to do
431 * it) so we can say what kind of translation the
432 * BIOS is using. Printing out the geometry could
433 * save a lot of users the grief of failed installs.
434 */
435 break;
436 }
437 default:
438 break;
439 }
440
441 /*
442 * See if we have a Rev E or higher aic7770. Anything below a
443 * Rev E will have a R/O autoflush disable configuration bit.
444 * It's still not clear exactly what is differenent about the Rev E.
445 * We think it allows 8 bit entries in the QOUTFIFO to support
446 * "paging" SCBs so you can have more than 4 commands active at
447 * once.
448 */
449 {
450 char *id_string;
451 u_char sblkctl;
452 u_char sblkctl_orig;
453
454 sblkctl_orig = AHC_INB(ahc, SBLKCTL);
455 sblkctl = sblkctl_orig ^ AUTOFLUSHDIS;
456 AHC_OUTB(ahc, SBLKCTL, sblkctl);
457 sblkctl = AHC_INB(ahc, SBLKCTL);
458 if(sblkctl != sblkctl_orig)
459 {
460 id_string = "aic7770 >= Rev E, ";
461 /*
462 * Ensure autoflush is enabled
463 */
464 sblkctl &= ~AUTOFLUSHDIS;
465 AHC_OUTB(ahc, SBLKCTL, sblkctl);
466
467 /* Allow paging on this adapter */
468 ahc->flags |= AHC_PAGESCBS;
469 }
470 else
471 id_string = "aic7770 <= Rev C, ";
472
473 printf("%s: %s", ahc_name(ahc), id_string);
474 }
475
476 /* Setup the FIFO threshold and the bus off time */
477 {
478 u_char hostconf = AHC_INB(ahc, HOSTCONF);
479 AHC_OUTB(ahc, BUSSPD, hostconf & DFTHRSH);
480 AHC_OUTB(ahc, BUSTIME, (hostconf << 2) & BOFF);
481 }
482
483 /*
484 * Generic aic7xxx initialization.
485 */
486 if(ahc_init(ahc)){
487 #if defined(__FreeBSD__)
488 ahc_free(ahc);
489 /*
490 * The board's IRQ line is not yet enabled so it's safe
491 * to release the irq.
492 */
493 eisa_release_intr(e_dev, irq, ahc_intr);
494 return -1;
495 #elif defined(__NetBSD__)
496 ahc_free(ahc);
497 return;
498 #endif
499 }
500
501 /*
502 * Enable the board's BUS drivers
503 */
504 AHC_OUTB(ahc, BCTL, ENABLE);
505
506 #if defined(__FreeBSD__)
507 /*
508 * Enable our interrupt handler.
509 */
510 if(eisa_enable_intr(e_dev, irq)) {
511 ahc_free(ahc);
512 eisa_release_intr(e_dev, irq, ahc_intr);
513 return -1;
514 }
515
516 e_dev->kdc->kdc_state = DC_BUSY; /* host adapters always busy */
517 #elif defined(__NetBSD__)
518 intrstr = eisa_intr_string(ec, ih);
519 /*
520 * The IRQMS bit enables level sensitive interrupts only allow
521 * IRQ sharing if its set.
522 */
523 ahc->sc_ih = eisa_intr_establish(ec, ih,
524 ahc->pause & IRQMS ? IST_LEVEL : IST_EDGE, IPL_BIO, ahc_intr, ahc);
525 if (ahc->sc_ih == NULL) {
526 printf("%s: couldn't establish interrupt",
527 ahc->sc_dev.dv_xname);
528 if (intrstr != NULL)
529 printf(" at %s", intrstr);
530 printf("\n");
531 ahc_free(ahc);
532 return;
533 }
534 if (intrstr != NULL)
535 printf("%s: interrupting at %s\n", ahc->sc_dev.dv_xname,
536 intrstr);
537 #endif /* defined(__NetBSD__) */
538
539 /* Attach sub-devices - always succeeds */
540 ahc_attach(ahc);
541
542 #if defined(__FreeBSD__)
543 return 0;
544 #endif
545 }
546
547 #endif /* NEISA > 0 */
548