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