ahc_eisa.c revision 1.6 1 /* $NetBSD: ahc_eisa.c,v 1.6 1996/08/05 21:18:56 soda 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 #define bootverbose 1
193
194 int ahc_eisa_irq __P((bus_chipset_tag_t, bus_io_handle_t));
195 int ahc_eisa_match __P((struct device *, void *, void *));
196 void ahc_eisa_attach __P((struct device *, struct device *, void *));
197
198
199 struct cfattach ahc_eisa_ca = {
200 sizeof(struct ahc_data), ahc_eisa_match, ahc_eisa_attach
201 };
202
203 /*
204 * Return irq setting of the board, otherwise -1.
205 */
206 int
207 ahc_eisa_irq(bc, ioh)
208 bus_chipset_tag_t bc;
209 bus_io_handle_t ioh;
210 {
211 int irq;
212 u_char intdef;
213
214 ahc_reset("ahc_eisa", bc, ioh);
215 intdef = bus_io_read_1(bc, ioh, INTDEF);
216 switch (irq = (intdef & 0xf)) {
217 case 9:
218 case 10:
219 case 11:
220 case 12:
221 case 14:
222 case 15:
223 break;
224 default:
225 printf("ahc_eisa_irq: illegal irq setting %d\n", intdef);
226 return -1;
227 }
228
229 /* Note that we are going and return (to probe) */
230 return irq;
231 }
232
233 /*
234 * Check the slots looking for a board we recognise
235 * If we find one, note it's address (slot) and call
236 * the actual probe routine to check it out.
237 */
238 int
239 ahc_eisa_match(parent, match, aux)
240 struct device *parent;
241 void *match, *aux;
242 {
243 struct eisa_attach_args *ea = aux;
244 bus_chipset_tag_t bc = ea->ea_bc;
245 bus_io_handle_t ioh;
246 int irq;
247
248 /* must match one of our known ID strings */
249 if (strcmp(ea->ea_idstring, "ADP7770") &&
250 strcmp(ea->ea_idstring, "ADP7771")
251 #if 0
252 && strcmp(ea->ea_idstring, "ADP7756") /* not EISA, but VL */
253 && strcmp(ea->ea_idstring, "ADP7757") /* not EISA, but VL */
254 #endif
255 )
256 return (0);
257
258 if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot) + AHC_EISA_SLOT_OFFSET,
259 AHC_EISA_IOSIZE, &ioh))
260 return (0);
261
262 irq = ahc_eisa_irq(bc, ioh);
263
264 bus_io_unmap(bc, ioh, AHC_EISA_IOSIZE);
265
266 return (irq >= 0);
267 }
268
269 #endif /* defined(__NetBSD__) */
270
271 #if defined(__FreeBSD__)
272 static int
273 aic7770_attach(e_dev)
274 struct eisa_device *e_dev;
275 #elif defined(__NetBSD__)
276 void
277 ahc_eisa_attach(parent, self, aux)
278 struct device *parent, *self;
279 void *aux;
280 #endif
281 {
282 ahc_type type;
283
284 #if defined(__FreeBSD__)
285 struct ahc_data *ahc;
286 resvaddr_t *iospace;
287 int unit = e_dev->unit;
288 int irq = ffs(e_dev->ioconf.irq) - 1;
289
290 iospace = e_dev->ioconf.ioaddrs.lh_first;
291
292 if(!iospace)
293 return -1;
294
295 switch(e_dev->id) {
296 case EISA_DEVICE_ID_ADAPTEC_AIC7770:
297 type = AHC_AIC7770;
298 break;
299 case EISA_DEVICE_ID_ADAPTEC_274x:
300 type = AHC_274;
301 break;
302 case EISA_DEVICE_ID_ADAPTEC_284xB:
303 case EISA_DEVICE_ID_ADAPTEC_284x:
304 type = AHC_284;
305 break;
306 default:
307 printf("aic7770_attach: Unknown device type!\n");
308 return -1;
309 break;
310 }
311
312 if(!(ahc = ahc_alloc(unit, iospace->addr, type, AHC_FNONE)))
313 return -1;
314
315 eisa_reg_start(e_dev);
316 if(eisa_reg_iospace(e_dev, iospace)) {
317 ahc_free(ahc);
318 return -1;
319 }
320
321 /*
322 * The IRQMS bit enables level sensitive interrupts. Only allow
323 * IRQ sharing if it's set.
324 */
325 if(eisa_reg_intr(e_dev, irq, ahc_intr, (void *)ahc, &bio_imask,
326 /*shared ==*/ahc->pause & IRQMS)) {
327 ahc_free(ahc);
328 return -1;
329 }
330 eisa_reg_end(e_dev);
331
332 #elif defined(__NetBSD__)
333
334 struct ahc_data *ahc = (void *)self;
335 struct eisa_attach_args *ea = aux;
336 bus_chipset_tag_t bc = ea->ea_bc;
337 bus_io_handle_t ioh;
338 int irq;
339 eisa_chipset_tag_t ec = ea->ea_ec;
340 eisa_intr_handle_t ih;
341 const char *model, *intrstr;
342
343 if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot) + AHC_EISA_SLOT_OFFSET,
344 AHC_EISA_IOSIZE, &ioh))
345 panic("ahc_eisa_attach: could not map I/O addresses");
346 if ((irq = ahc_eisa_irq(bc, ioh)) < 0)
347 panic("ahc_eisa_attach: ahc_eisa_irq failed!");
348
349 if (strcmp(ea->ea_idstring, "ADP7770") == 0) {
350 model = EISA_PRODUCT_ADP7770;
351 type = AHC_AIC7770;
352 } else if (strcmp(ea->ea_idstring, "ADP7771") == 0) {
353 model = EISA_PRODUCT_ADP7771;
354 type = AHC_274;
355 #if 0
356 } else if (strcmp(ea->ea_idstring, "ADP7756") == 0) {
357 model = EISA_PRODUCT_ADP7756;
358 type = AHC_284;
359 } else if (strcmp(ea->ea_idstring, "ADP7757") == 0) {
360 model = EISA_PRODUCT_ADP7757;
361 type = AHC_284;
362 #endif
363 } else {
364 panic("ahc_eisa_attach: Unknown device type %s\n",
365 ea->ea_idstring);
366 }
367 printf(": %s\n", model);
368
369 ahc_construct(ahc, bc, ioh, type, AHC_FNONE);
370 if (eisa_intr_map(ec, irq, &ih)) {
371 printf("%s: couldn't map interrupt (%d)\n",
372 ahc->sc_dev.dv_xname, irq);
373 return;
374 }
375 #endif /* defined(__NetBSD__) */
376
377 /*
378 * Tell the user what type of interrupts we're using.
379 * usefull for debugging irq problems
380 */
381 if(bootverbose) {
382 printf("%s: Using %s Interrupts\n",
383 ahc_name(ahc),
384 ahc->pause & IRQMS ?
385 "Level Sensitive" : "Edge Triggered");
386 }
387
388 /*
389 * Now that we know we own the resources we need, do the
390 * card initialization.
391 *
392 * First, the aic7770 card specific setup.
393 */
394 switch( ahc->type ) {
395 case AHC_AIC7770:
396 case AHC_274:
397 {
398 u_char biosctrl = AHC_INB(ahc, HA_274_BIOSCTRL);
399
400 /* Get the primary channel information */
401 ahc->flags |= (biosctrl & CHANNEL_B_PRIMARY);
402
403 if((biosctrl & BIOSMODE) == BIOSDISABLED)
404 ahc->flags |= AHC_USEDEFAULTS;
405 break;
406 }
407 case AHC_284:
408 {
409 /* XXX
410 * All values are automagically intialized at
411 * POST for these cards, so we can always rely
412 * on the Scratch Ram values. However, we should
413 * read the SEEPROM here (Dan has the code to do
414 * it) so we can say what kind of translation the
415 * BIOS is using. Printing out the geometry could
416 * save a lot of users the grief of failed installs.
417 */
418 break;
419 }
420 default:
421 break;
422 }
423
424 /*
425 * See if we have a Rev E or higher aic7770. Anything below a
426 * Rev E will have a R/O autoflush disable configuration bit.
427 * It's still not clear exactly what is differenent about the Rev E.
428 * We think it allows 8 bit entries in the QOUTFIFO to support
429 * "paging" SCBs so you can have more than 4 commands active at
430 * once.
431 */
432 {
433 char *id_string;
434 u_char sblkctl;
435 u_char sblkctl_orig;
436
437 sblkctl_orig = AHC_INB(ahc, SBLKCTL);
438 sblkctl = sblkctl_orig ^ AUTOFLUSHDIS;
439 AHC_OUTB(ahc, SBLKCTL, sblkctl);
440 sblkctl = AHC_INB(ahc, SBLKCTL);
441 if(sblkctl != sblkctl_orig)
442 {
443 id_string = "aic7770 >= Rev E, ";
444 /*
445 * Ensure autoflush is enabled
446 */
447 sblkctl &= ~AUTOFLUSHDIS;
448 AHC_OUTB(ahc, SBLKCTL, sblkctl);
449
450 /* Allow paging on this adapter */
451 ahc->flags |= AHC_PAGESCBS;
452 }
453 else
454 id_string = "aic7770 <= Rev C, ";
455
456 printf("%s: %s", ahc_name(ahc), id_string);
457 }
458
459 /* Setup the FIFO threshold and the bus off time */
460 {
461 u_char hostconf = AHC_INB(ahc, HOSTCONF);
462 AHC_OUTB(ahc, BUSSPD, hostconf & DFTHRSH);
463 AHC_OUTB(ahc, BUSTIME, (hostconf << 2) & BOFF);
464 }
465
466 /*
467 * Generic aic7xxx initialization.
468 */
469 if(ahc_init(ahc)){
470 #if defined(__FreeBSD__)
471 ahc_free(ahc);
472 /*
473 * The board's IRQ line is not yet enabled so it's safe
474 * to release the irq.
475 */
476 eisa_release_intr(e_dev, irq, ahc_intr);
477 return -1;
478 #elif defined(__NetBSD__)
479 ahc_free(ahc);
480 return;
481 #endif
482 }
483
484 /*
485 * Enable the board's BUS drivers
486 */
487 AHC_OUTB(ahc, BCTL, ENABLE);
488
489 #if defined(__FreeBSD__)
490 /*
491 * Enable our interrupt handler.
492 */
493 if(eisa_enable_intr(e_dev, irq)) {
494 ahc_free(ahc);
495 eisa_release_intr(e_dev, irq, ahc_intr);
496 return -1;
497 }
498
499 e_dev->kdc->kdc_state = DC_BUSY; /* host adapters always busy */
500 #elif defined(__NetBSD__)
501 intrstr = eisa_intr_string(ec, ih);
502 /*
503 * The IRQMS bit enables level sensitive interrupts only allow
504 * IRQ sharing if its set.
505 */
506 ahc->sc_ih = eisa_intr_establish(ec, ih,
507 ahc->pause & IRQMS ? IST_LEVEL : IST_EDGE, IPL_BIO, ahc_intr, ahc
508 #ifdef __OpenBSD__
509 , ahc->sc_dev.dv_xname
510 #endif
511 );
512 if (ahc->sc_ih == NULL) {
513 printf("%s: couldn't establish interrupt",
514 ahc->sc_dev.dv_xname);
515 if (intrstr != NULL)
516 printf(" at %s", intrstr);
517 printf("\n");
518 ahc_free(ahc);
519 return;
520 }
521 if (intrstr != NULL)
522 printf("%s: interrupting at %s\n", ahc->sc_dev.dv_xname,
523 intrstr);
524 #endif /* defined(__NetBSD__) */
525
526 /* Attach sub-devices - always succeeds */
527 ahc_attach(ahc);
528
529 #if defined(__FreeBSD__)
530 return 0;
531 #endif
532 }
533
534 #endif /* NEISA > 0 */
535