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