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