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