xref: /freebsd/sys/dev/aic7xxx/ahc_pci.c (revision 0640d357f29fb1c0daaaffadd0416c5981413afd)
1 /*
2  * Product specific probe and attach routines for:
3  *      3940, 2940, aic7895, aic7890, aic7880,
4  *	aic7870, aic7860 and aic7850 SCSI controllers
5  *
6  * Copyright (c) 1995, 1996, 1997, 1998 Justin T. Gibbs
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions, and the following disclaimer,
14  *    without modification, immediately at the beginning of the file.
15  * 2. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * Where this Software is combined with software released under the terms of
19  * the GNU Public License ("GPL") and the terms of the GPL would require the
20  * combined work to also be released under the terms of the GPL, the terms
21  * and conditions of this License will apply in addition to those of the
22  * GPL with the exception of any terms or conditions of this License that
23  * conflict with, or are expressly prohibited by, the GPL.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
29  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *	$Id: ahc_pci.c,v 1.1 1998/09/15 07:25:33 gibbs Exp $
38  */
39 
40 #include <pci.h>
41 #if NPCI > 0
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
45 #include <sys/queue.h>
46 
47 #include <pci/pcireg.h>
48 #include <pci/pcivar.h>
49 
50 #include <machine/bus_memio.h>
51 #include <machine/bus_pio.h>
52 #include <machine/bus.h>
53 #include <machine/clock.h>
54 
55 #include <cam/cam.h>
56 #include <cam/cam_ccb.h>
57 #include <cam/cam_sim.h>
58 
59 #include <cam/scsi/scsi_all.h>
60 
61 #include <dev/aic7xxx/aic7xxx.h>
62 #include <dev/aic7xxx/93cx6.h>
63 
64 #include <aic7xxx_reg.h>
65 
66 #define PCI_BASEADR0	PCI_MAP_REG_START	/* I/O Address */
67 #define PCI_BASEADR1	PCI_MAP_REG_START + 4	/* Mem I/O Address */
68 
69 #define PCI_DEVICE_ID_ADAPTEC_398XU	0x83789004ul
70 #define PCI_DEVICE_ID_ADAPTEC_3940U	0x82789004ul
71 #define PCI_DEVICE_ID_ADAPTEC_2944U	0x84789004ul
72 #define PCI_DEVICE_ID_ADAPTEC_2940U	0x81789004ul
73 #define PCI_DEVICE_ID_ADAPTEC_2940AU	0x61789004ul
74 #define PCI_DEVICE_ID_ADAPTEC_2940U2	0x00109005ul
75 #define PCI_DEVICE_ID_ADAPTEC_398X	0x73789004ul
76 #define PCI_DEVICE_ID_ADAPTEC_3940	0x72789004ul
77 #define PCI_DEVICE_ID_ADAPTEC_2944	0x74789004ul
78 #define PCI_DEVICE_ID_ADAPTEC_2940	0x71789004ul
79 #define PCI_DEVICE_ID_ADAPTEC_AIC7890	0x001F9005ul
80 #define PCI_DEVICE_ID_ADAPTEC_AIC7895	0x78959004ul
81 #define PCI_DEVICE_ID_ADAPTEC_AIC7896	0x005F9005ul
82 #define PCI_DEVICE_ID_ADAPTEC_AIC7880	0x80789004ul
83 #define PCI_DEVICE_ID_ADAPTEC_AIC7870	0x70789004ul
84 #define PCI_DEVICE_ID_ADAPTEC_AIC7860	0x60789004ul
85 #define PCI_DEVICE_ID_ADAPTEC_AIC7855	0x55789004ul
86 #define PCI_DEVICE_ID_ADAPTEC_AIC7850	0x50789004ul
87 #define PCI_DEVICE_ID_ADAPTEC_AIC7810	0x10789004ul
88 
89 #define AHC_394X_SLOT_CHANNEL_A	4
90 #define AHC_394X_SLOT_CHANNEL_B	5
91 
92 #define AHC_398X_SLOT_CHANNEL_A	4
93 #define AHC_398X_SLOT_CHANNEL_B	8
94 #define AHC_398X_SLOT_CHANNEL_C	12
95 
96 #define	DEVCONFIG		0x40
97 #define		SCBSIZE32	0x00010000ul	/* aic789X only */
98 #define		MPORTMODE	0x00000400ul	/* aic7870 only */
99 #define		RAMPSM		0x00000200ul	/* aic7870 only */
100 #define		VOLSENSE	0x00000100ul
101 #define		SCBRAMSEL	0x00000080ul
102 #define		MRDCEN		0x00000040ul
103 #define		EXTSCBTIME	0x00000020ul	/* aic7870 only */
104 #define		EXTSCBPEN	0x00000010ul	/* aic7870 only */
105 #define		BERREN		0x00000008ul
106 #define		DACEN		0x00000004ul
107 #define		STPWLEVEL	0x00000002ul
108 #define		DIFACTNEGEN	0x00000001ul	/* aic7870 only */
109 
110 #define	CSIZE_LATTIME		0x0c
111 #define		CACHESIZE	0x0000003ful	/* only 5 bits */
112 #define		LATTIME		0x0000ff00ul
113 
114 static void check_extport(struct ahc_softc *ahc, u_int8_t *sxfrctl1);
115 static void configure_termination(struct ahc_softc *ahc,
116 				  struct seeprom_config *sc,
117 				  struct seeprom_descriptor *sd,
118 	 			  u_int8_t *sxfrctl1);
119 
120 static void ahc_ultra2_term_detect(struct ahc_softc *ahc,
121 				   int *enableSEC_low,
122 				   int *enableSEC_high,
123 				   int *enablePRI_low,
124 				   int *enablePRI_high,
125 				   int *eeprom_present);
126 static void aic787X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
127 				 int *internal68_present,
128 				 int *externalcable_present,
129 				 int *eeprom_present);
130 static void aic785X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
131 				 int *externalcable_present,
132 				 int *eeprom_present);
133 static int acquire_seeprom(struct ahc_softc *ahc,
134 			   struct seeprom_descriptor *sd);
135 static void release_seeprom(struct seeprom_descriptor *sd);
136 static void write_brdctl(struct ahc_softc *ahc, u_int8_t value);
137 static u_int8_t read_brdctl(struct ahc_softc *ahc);
138 
139 static struct ahc_softc *first_398X;
140 
141 static char* ahc_pci_probe(pcici_t tag, pcidi_t type);
142 static void ahc_pci_attach(pcici_t config_id, int unit);
143 
144 /* Exported for use in the ahc_intr routine */
145 void ahc_pci_intr(struct ahc_softc *ahc);
146 
147 static struct  pci_device ahc_pci_driver = {
148 	"ahc",
149         ahc_pci_probe,
150         ahc_pci_attach,
151         &ahc_unit,
152 	NULL
153 };
154 
155 DATA_SET (pcidevice_set, ahc_pci_driver);
156 
157 static  char*
158 ahc_pci_probe (pcici_t tag, pcidi_t type)
159 {
160 	switch (type) {
161 	case PCI_DEVICE_ID_ADAPTEC_398XU:
162 		return ("Adaptec 398X Ultra SCSI RAID adapter");
163 		break;
164 	case PCI_DEVICE_ID_ADAPTEC_3940U:
165 		return ("Adaptec 3940 Ultra SCSI host adapter");
166 		break;
167 	case PCI_DEVICE_ID_ADAPTEC_398X:
168 		return ("Adaptec 398X SCSI RAID adapter");
169 		break;
170 	case PCI_DEVICE_ID_ADAPTEC_3940:
171 		return ("Adaptec 3940 SCSI adapter");
172 		break;
173 	case PCI_DEVICE_ID_ADAPTEC_2944U:
174 		return ("Adaptec 2944 Ultra SCSI adapter");
175 		break;
176 	case PCI_DEVICE_ID_ADAPTEC_2940U:
177 		return ("Adaptec 2940 Ultra SCSI adapter");
178 		break;
179 	case PCI_DEVICE_ID_ADAPTEC_2940U2:
180 		return ("Adaptec 2940 Ultra2 SCSI adapter");
181 		break;
182 	case PCI_DEVICE_ID_ADAPTEC_2944:
183 		return ("Adaptec 2944 SCSI adapter");
184 		break;
185 	case PCI_DEVICE_ID_ADAPTEC_2940:
186 		return ("Adaptec 2940 SCSI adapter");
187 		break;
188 	case PCI_DEVICE_ID_ADAPTEC_2940AU:
189 		return ("Adaptec 2940A Ultra SCSI adapter");
190 		break;
191 	case PCI_DEVICE_ID_ADAPTEC_AIC7895:
192 		return ("Adaptec aic7895 Ultra SCSI adapter");
193 		break;
194 	case PCI_DEVICE_ID_ADAPTEC_AIC7890:
195 		return ("Adaptec aic7890/91 Ultra2 SCSI adapter");
196 		break;
197 	case PCI_DEVICE_ID_ADAPTEC_AIC7896:
198 		return ("Adaptec aic7896/97 Ultra2 SCSI adapter");
199 		break;
200 	case PCI_DEVICE_ID_ADAPTEC_AIC7880:
201 		return ("Adaptec aic7880 Ultra SCSI adapter");
202 		break;
203 	case PCI_DEVICE_ID_ADAPTEC_AIC7870:
204 		return ("Adaptec aic7870 SCSI adapter");
205 		break;
206 	case PCI_DEVICE_ID_ADAPTEC_AIC7860:
207 		return ("Adaptec aic7860 SCSI adapter");
208 		break;
209 	case PCI_DEVICE_ID_ADAPTEC_AIC7855:
210 		return ("Adaptec aic7855 SCSI adapter");
211 		break;
212 	case PCI_DEVICE_ID_ADAPTEC_AIC7850:
213 		return ("Adaptec aic7850 SCSI adapter");
214 		break;
215 	case PCI_DEVICE_ID_ADAPTEC_AIC7810:
216 		return ("Adaptec aic7810 RAID memory controller");
217 		break;
218 	default:
219 		break;
220 	}
221 	return (0);
222 
223 }
224 
225 static void
226 ahc_pci_attach(pcici_t config_id, int unit)
227 {
228 	u_int16_t io_port;
229 	struct	  ahc_softc *ahc;
230 	u_int32_t id;
231 	u_int32_t command;
232 	struct scb_data *shared_scb_data;
233 	int opri;
234 	ahc_chip    ahc_t = AHC_NONE;
235 	ahc_feature ahc_fe = AHC_FENONE;
236 	ahc_flag    ahc_f = AHC_FNONE;
237 	vm_offset_t vaddr;
238 	vm_offset_t paddr;
239 	u_int8_t    our_id = 0;
240 	u_int8_t    sxfrctl1;
241 	u_int8_t    scsiseq;
242 	int	    error;
243 	char	    channel;
244 
245 	if (config_id->func == 1)
246 		channel = 'B';
247 	else
248 		channel = 'A';
249 	shared_scb_data = NULL;
250 	vaddr = NULL;
251 	paddr = NULL;
252 	io_port = 0;
253 	command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
254 #ifdef AHC_ALLOW_MEMIO
255 	if ((command & PCI_COMMAND_MEM_ENABLE) == 0
256 	 || (pci_map_mem(config_id, PCI_BASEADR1, &vaddr, &paddr)) == 0)
257 #endif
258 		if ((command & PCI_COMMAND_IO_ENABLE) == 0
259 		 || (pci_map_port(config_id, PCI_BASEADR0, &io_port)) == 0)
260 			return;
261 
262 	switch ((id = pci_conf_read(config_id, PCI_ID_REG))) {
263 	case PCI_DEVICE_ID_ADAPTEC_398XU:
264 	case PCI_DEVICE_ID_ADAPTEC_398X:
265 		if (id == PCI_DEVICE_ID_ADAPTEC_398XU) {
266 			ahc_t = AHC_AIC7880;
267 			ahc_fe = AHC_AIC7880_FE;
268 		} else {
269 			ahc_t = AHC_AIC7870;
270 			ahc_fe = AHC_AIC7870_FE;
271 		}
272 
273 		switch (config_id->slot) {
274 		case AHC_398X_SLOT_CHANNEL_A:
275 			break;
276 		case AHC_398X_SLOT_CHANNEL_B:
277 			channel = 'B';
278 			break;
279 		case AHC_398X_SLOT_CHANNEL_C:
280 			channel = 'C';
281 			break;
282 		default:
283 			printf("adapter at unexpected slot %d\n"
284 			       "unable to map to a channel\n",
285 			       config_id->slot);
286 		}
287 		ahc_f |= AHC_LARGE_SEEPROM;
288 		break;
289 	case PCI_DEVICE_ID_ADAPTEC_3940U:
290 	case PCI_DEVICE_ID_ADAPTEC_3940:
291 		if (id == PCI_DEVICE_ID_ADAPTEC_3940U) {
292 			ahc_t = AHC_AIC7880;
293 			ahc_fe = AHC_AIC7880_FE;
294 		} else {
295 			ahc_t = AHC_AIC7870;
296 			ahc_fe = AHC_AIC7870_FE;
297 		}
298 
299 		switch (config_id->slot) {
300 		case AHC_394X_SLOT_CHANNEL_A:
301 			break;
302 		case AHC_394X_SLOT_CHANNEL_B:
303 			channel = 'B';
304 			break;
305 		default:
306 			printf("adapter at unexpected slot %d\n"
307 			       "unable to map to a channel\n",
308 			       config_id->slot);
309 		}
310 		break;
311 	case PCI_DEVICE_ID_ADAPTEC_AIC7890:
312 	case PCI_DEVICE_ID_ADAPTEC_2940U2:
313 	{
314 		ahc_t = AHC_AIC7890;
315 		ahc_fe = AHC_AIC7890_FE;
316 		break;
317 	}
318 	case PCI_DEVICE_ID_ADAPTEC_AIC7896:
319 	{
320 		ahc_t = AHC_AIC7896;
321 		ahc_fe = AHC_AIC7896_FE;
322 		break;
323 	}
324 	case PCI_DEVICE_ID_ADAPTEC_2944U:
325 	case PCI_DEVICE_ID_ADAPTEC_2940U:
326 	case PCI_DEVICE_ID_ADAPTEC_AIC7880:
327 		ahc_t = AHC_AIC7880;
328 		ahc_fe = AHC_AIC7880_FE;
329 		break;
330 	case PCI_DEVICE_ID_ADAPTEC_2944:
331 	case PCI_DEVICE_ID_ADAPTEC_2940:
332 	case PCI_DEVICE_ID_ADAPTEC_AIC7870:
333 		ahc_t = AHC_AIC7870;
334 		ahc_fe = AHC_AIC7870_FE;
335 		break;
336 	case PCI_DEVICE_ID_ADAPTEC_2940AU:
337 	case PCI_DEVICE_ID_ADAPTEC_AIC7860:
338 		ahc_fe = AHC_AIC7860_FE;
339 		ahc_t = AHC_AIC7860;
340 		break;
341 	case PCI_DEVICE_ID_ADAPTEC_AIC7895:
342 	{
343 		u_int32_t devconfig;
344 
345 		ahc_t = AHC_AIC7895;
346 		ahc_fe = AHC_AIC7895_FE;
347 		devconfig = pci_conf_read(config_id, DEVCONFIG);
348 		devconfig &= ~SCBSIZE32;
349 		pci_conf_write(config_id, DEVCONFIG, devconfig);
350 		break;
351 	}
352 	case PCI_DEVICE_ID_ADAPTEC_AIC7855:
353 	case PCI_DEVICE_ID_ADAPTEC_AIC7850:
354 		ahc_t = AHC_AIC7850;
355 		ahc_fe = AHC_AIC7850_FE;
356 		break;
357 	case PCI_DEVICE_ID_ADAPTEC_AIC7810:
358 		printf("RAID functionality unsupported\n");
359 		return;
360 	default:
361 		break;
362 	}
363 
364 	/* On all PCI adapters, we allow SCB paging */
365 	ahc_f |= AHC_PAGESCBS;
366 	if ((ahc = ahc_alloc(unit, io_port, vaddr, ahc_t|AHC_PCI, ahc_fe, ahc_f,
367 	     shared_scb_data)) == NULL)
368 		return;  /* XXX PCI code should take return status */
369 
370 	ahc->channel = channel;
371 
372 	/* Allocate a dmatag for our SCB DMA maps */
373 	/* XXX Should be a child of the PCI bus dma tag */
374 	error = bus_dma_tag_create(/*parent*/NULL, /*alignment*/0,
375 				   /*boundary*/0,
376 				   /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
377 				   /*highaddr*/BUS_SPACE_MAXADDR,
378 				   /*filter*/NULL, /*filterarg*/NULL,
379 				   /*maxsize*/MAXBSIZE, /*nsegments*/AHC_NSEG,
380 				   /*maxsegsz*/AHC_MAXTRANSFER_SIZE,
381 				    /*flags*/BUS_DMA_ALLOCNOW, &ahc->dmat);
382 
383 	if (error != 0) {
384 		printf("%s: Could not allocate DMA tag - error %d\n",
385 		       ahc_name(ahc), error);
386 		ahc_free(ahc);
387 		return;
388 	}
389 
390 
391 	/* Store our PCI bus information for use in our PCI error handler */
392 	ahc->pci_config_id = config_id;
393 
394 	/* Remeber how the card was setup in case there is no SEEPROM */
395 	ahc_outb(ahc, HCNTRL, ahc->pause);
396 	if ((ahc->features & AHC_ULTRA2) != 0)
397 		our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
398 	else
399 		our_id = ahc_inb(ahc, SCSIID) & OID;
400 	sxfrctl1 = ahc_inb(ahc, SXFRCTL1) & STPWEN;
401 	scsiseq = ahc_inb(ahc, SCSISEQ);
402 
403 	if (ahc_reset(ahc) != 0) {
404 		/* Failed */
405 		ahc_free(ahc);
406 		return;
407 	}
408 
409 	/*
410 	 * Take a look to see if we have external SRAM.
411 	 * We currently do not attempt to use SRAM that is
412 	 * shared among multiple controllers.
413 	 */
414 	if ((ahc->features & AHC_ULTRA2) != 0) {
415 		u_int dscommand0;
416 
417 		dscommand0 = ahc_inb(ahc, DSCOMMAND0);
418 		if ((dscommand0 & RAMPS) != 0) {
419 			u_int32_t devconfig;
420 
421 			devconfig = pci_conf_read(config_id, DEVCONFIG);
422 			if ((devconfig & MPORTMODE) != 0) {
423 				/* Single user mode */
424 
425 				/*
426 				 * XXX Assume 9bit SRAM and enable
427 				 * parity checking
428 				 */
429 				devconfig |= EXTSCBPEN;
430 				pci_conf_write(config_id, DEVCONFIG, devconfig);
431 
432 				/*
433 				 * Set the bank select apropriately.
434 				 */
435 				if (ahc->channel == 'B')
436 					ahc_outb(ahc, SCBBADDR, 1);
437 				else
438 					ahc_outb(ahc, SCBBADDR, 0);
439 
440 				/* Select external SCB SRAM */
441 				dscommand0 &= ~INTSCBRAMSEL;
442 				ahc_outb(ahc, DSCOMMAND0, dscommand0);
443 
444 				if (ahc_probe_scbs(ahc) == 0) {
445 					/* External ram isn't really there */
446 					dscommand0 |= INTSCBRAMSEL;
447 					ahc_outb(ahc, DSCOMMAND0, dscommand0);
448 				} else if (bootverbose)
449 					printf("%s: External SRAM bank%d\n",
450 					       ahc_name(ahc),
451 					       ahc->channel == 'B' ? 1 : 0);
452 			}
453 
454 		}
455 	} else if ((ahc->chip & AHC_CHIPID_MASK) >= AHC_AIC7870) {
456 		u_int32_t devconfig = pci_conf_read(config_id, DEVCONFIG);
457 		if ((devconfig & RAMPSM) != 0
458 		 && (devconfig & MPORTMODE) != 0) {
459 
460 			/* XXX Assume 9bit SRAM and enable parity checking */
461 			devconfig |= EXTSCBPEN;
462 
463 			/* XXX Assume fast SRAM */
464 			devconfig &= ~EXTSCBTIME;
465 
466 			/*
467 			 * Set the bank select apropriately.
468 			 */
469 			if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
470 				if (ahc->channel == 'B')
471 					ahc_outb(ahc, SCBBADDR, 1);
472 				else
473 					ahc_outb(ahc, SCBBADDR, 0);
474 			}
475 
476 			/* Select external SRAM */
477 			devconfig &= ~SCBRAMSEL;
478 			pci_conf_write(config_id, DEVCONFIG, devconfig);
479 
480 			if (ahc_probe_scbs(ahc) == 0) {
481 				/* External ram isn't really there */
482 				devconfig |= SCBRAMSEL;
483 				pci_conf_write(config_id, DEVCONFIG, devconfig);
484 			} else if (bootverbose)
485 				printf("%s: External SRAM bank%d\n",
486 				       ahc_name(ahc),
487 				       ahc->channel == 'B' ? 1 : 0);
488 		}
489 	}
490 
491 	if (!(pci_map_int(config_id, ahc_intr, (void *)ahc, &cam_imask))) {
492 		ahc_free(ahc);
493 		return;
494 	}
495 	/*
496 	 * Protect ourself from spurrious interrupts during
497 	 * intialization.
498 	 */
499 	opri = splcam();
500 
501 	/*
502 	 * Do aic7880/aic7870/aic7860/aic7850 specific initialization
503 	 */
504 	{
505 		u_int8_t sblkctl;
506 		char	 *id_string;
507 
508 		switch(ahc_t) {
509 		case AHC_AIC7896:
510 		{
511 			u_int dscommand0;
512 
513 			/*
514 			 * DPARCKEN doesn't work correctly on
515 			 * some MBs so don't use it.
516 			 */
517 			id_string = "aic7896/97 ";
518 			dscommand0 = ahc_inb(ahc, DSCOMMAND0);
519 			dscommand0 &= ~(USCBSIZE32|DPARCKEN);
520 			dscommand0 |= CACHETHEN|MPARCKEN;
521 			ahc_outb(ahc, DSCOMMAND0, dscommand0);
522 			break;
523 		}
524 		case AHC_AIC7890:
525 		{
526 			u_int dscommand0;
527 
528 			/*
529 			 * DPARCKEN doesn't work correctly on
530 			 * some MBs so don't use it.
531 			 */
532 			id_string = "aic7890/91 ";
533 			dscommand0 = ahc_inb(ahc, DSCOMMAND0);
534 			dscommand0 &= ~(USCBSIZE32|DPARCKEN);
535 			dscommand0 |= CACHETHEN|MPARCKEN;
536 			ahc_outb(ahc, DSCOMMAND0, dscommand0);
537 			break;
538 		}
539 		case AHC_AIC7895:
540 			id_string = "aic7895 ";
541 			break;
542 		case AHC_AIC7880:
543 			id_string = "aic7880 ";
544 			break;
545 		case AHC_AIC7870:
546 			id_string = "aic7870 ";
547 			break;
548 		case AHC_AIC7860:
549 			id_string = "aic7860 ";
550 			break;
551 		case AHC_AIC7850:
552 			id_string = "aic7850 ";
553 			break;
554 		default:
555 			printf("ahc: Unknown controller type.  Ignoring.\n");
556 			ahc_free(ahc);
557 			splx(opri);
558 			return;
559 		}
560 
561 		/* See if we have an SEEPROM and perform auto-term */
562 		check_extport(ahc, &sxfrctl1);
563 
564 		/*
565 		 * Take the LED out of diagnostic mode
566 		 */
567 		sblkctl = ahc_inb(ahc, SBLKCTL);
568 		ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
569 
570 		/*
571 		 * I don't know where this is set in the SEEPROM or by the
572 		 * BIOS, so we default to 100% on Ultra or slower controllers
573 		 * and 75% on ULTRA2 controllers.
574 		 */
575 		if ((ahc->features & AHC_ULTRA2) != 0) {
576 			ahc_outb(ahc, DFF_THRSH, RD_DFTHRSH_75|WR_DFTHRSH_75);
577 		} else {
578 			ahc_outb(ahc, DSPCISTATUS, DFTHRSH_100);
579 		}
580 
581 		if (ahc->flags & AHC_USEDEFAULTS) {
582 			/*
583 			 * PCI Adapter default setup
584 			 * Should only be used if the adapter does not have
585 			 * an SEEPROM.
586 			 */
587 			/* See if someone else set us up already */
588 			if (scsiseq != 0) {
589 				printf("%s: Using left over BIOS settings\n",
590 					ahc_name(ahc));
591 				ahc->flags &= ~AHC_USEDEFAULTS;
592 			} else {
593 				/*
594 				 * Assume only one connector and always turn
595 				 * on termination.
596 				 */
597  				our_id = 0x07;
598 				sxfrctl1 = STPWEN;
599 			}
600 			ahc_outb(ahc, SCSICONF,
601 				 (our_id & 0x07)|ENSPCHK|RESET_SCSI);
602 
603 			ahc->our_id = our_id;
604 		}
605 
606 		printf("%s: %s", ahc_name(ahc), id_string);
607 	}
608 
609 	/*
610 	 * Record our termination setting for the
611 	 * generic initialization routine.
612 	 */
613 	if ((sxfrctl1 & STPWEN) != 0)
614 		ahc->flags |= AHC_TERM_ENB_A;
615 
616 	if (ahc_init(ahc)) {
617 		ahc_free(ahc);
618 		splx(opri);
619 		return; /* XXX PCI code should take return status */
620 	}
621 
622 	/* XXX Crude hack - fix sometime */
623 	if (ahc->flags & AHC_SHARED_SRAM) {
624 		/* Only set this once we've successfully probed */
625 		if (shared_scb_data == NULL)
626 			first_398X = ahc;
627 	}
628 
629 	splx(opri);
630 
631 	ahc_attach(ahc);
632 }
633 
634 /*
635  * Check the external port logic for a serial eeprom
636  * and termination/cable detection contrls.
637  */
638 static void
639 check_extport(struct ahc_softc *ahc, u_int8_t *sxfrctl1)
640 {
641 	struct	  seeprom_descriptor sd;
642 	struct	  seeprom_config sc;
643 	u_int8_t  scsi_conf;
644 	int	  have_seeprom;
645 
646 	sd.sd_tag = ahc->tag;
647 	sd.sd_bsh = ahc->bsh;
648 	sd.sd_control_offset = SEECTL;
649 	sd.sd_status_offset = SEECTL;
650 	sd.sd_dataout_offset = SEECTL;
651 
652 	/*
653 	 * For some multi-channel devices, the c46 is simply too
654 	 * small to work.  For the other controller types, we can
655 	 * get our information from either SEEPROM type.  Set the
656 	 * type to start our probe with accordingly.
657 	 */
658 	if (ahc->flags & AHC_LARGE_SEEPROM)
659 		sd.sd_chip = C56_66;
660 	else
661 		sd.sd_chip = C46;
662 
663 	sd.sd_MS = SEEMS;
664 	sd.sd_RDY = SEERDY;
665 	sd.sd_CS = SEECS;
666 	sd.sd_CK = SEECK;
667 	sd.sd_DO = SEEDO;
668 	sd.sd_DI = SEEDI;
669 
670 	have_seeprom = acquire_seeprom(ahc, &sd);
671 
672 	if (have_seeprom) {
673 
674 		if (bootverbose)
675 			printf("%s: Reading SEEPROM...", ahc_name(ahc));
676 
677 		for (;;) {
678 			bus_size_t start_addr;
679 
680 			start_addr = 32 * (ahc->channel - 'A');
681 
682 			have_seeprom = read_seeprom(&sd, (u_int16_t *)&sc,
683 						    start_addr, sizeof(sc)/2);
684 
685 			if (have_seeprom) {
686 				/* Check checksum */
687 				int i;
688 				int maxaddr;
689 				u_int16_t *scarray;
690 				u_int16_t checksum;
691 
692 				maxaddr = (sizeof(sc)/2) - 1;
693 				checksum = 0;
694 				scarray = (u_int16_t *)&sc;
695 
696 				for (i = 0; i < maxaddr; i++)
697 					checksum = checksum + scarray[i];
698 				if (checksum == 0 || checksum != sc.checksum) {
699 					if (bootverbose && sd.sd_chip == C56_66)
700 						printf ("checksum error\n");
701 					have_seeprom = 0;
702 				} else {
703 					if (bootverbose)
704 						printf("done.\n");
705 					break;
706 				}
707 			}
708 
709 			if (sd.sd_chip == C56_66)
710 				break;
711 			sd.sd_chip = C56_66;
712 		}
713 	}
714 
715 	if (!have_seeprom) {
716 		if (bootverbose)
717 			printf("%s: No SEEPROM available.\n", ahc_name(ahc));
718 		ahc->flags |= AHC_USEDEFAULTS;
719 	} else {
720 		/*
721 		 * Put the data we've collected down into SRAM
722 		 * where ahc_init will find it.
723 		 */
724 		int i;
725 		int max_targ = sc.max_targets & CFMAXTARG;
726 
727 		if ((sc.adapter_control & CFULTRAEN) != 0) {
728 			/*
729 			 * Determine if this adapter has a "newstyle"
730 			 * SEEPROM format.
731 			 */
732 			for (i = 0; i < max_targ; i++) {
733 				if ((sc.device_flags[i] & CFSYNCHISULTRA) != 0){
734 					ahc->flags |= AHC_NEWEEPROM_FMT;
735 					break;
736 				}
737 			}
738 		}
739 
740 		for (i = 0; i < max_targ; i++) {
741 			u_int     scsirate;
742 			u_int16_t target_mask;
743 
744 			target_mask = 0x01 << i;
745 			if (sc.device_flags[i] & CFDISC)
746 				ahc->discenable |= target_mask;
747 			if ((ahc->flags & AHC_NEWEEPROM_FMT) != 0) {
748 				if ((sc.device_flags[i] & CFSYNCHISULTRA) != 0)
749 					ahc->ultraenb |= target_mask;
750 			} else if ((sc.adapter_control & CFULTRAEN) != 0) {
751 				ahc->ultraenb |= target_mask;
752 			}
753 			if ((sc.device_flags[i] & CFXFER) == 0x04
754 			 && (ahc->ultraenb & target_mask) != 0) {
755 				/* Treat 10MHz as a non-ultra speed */
756 				sc.device_flags[i] &= ~CFXFER;
757 			 	ahc->ultraenb &= ~target_mask;
758 			}
759 			if ((ahc->features & AHC_ULTRA2) != 0) {
760 				u_int offset;
761 
762 				if (sc.device_flags[i] & CFSYNCH)
763 					offset = MAX_OFFSET_ULTRA2;
764 				else
765 					offset = 0;
766 				ahc_outb(ahc, TARG_OFFSET + i, offset);
767 
768 				scsirate = (sc.device_flags[i] & CFXFER)
769 					 | ((ahc->ultraenb & target_mask)
770 					    ? 0x18 : 0x10);
771 				if (sc.device_flags[i] & CFWIDEB)
772 					scsirate |= WIDEXFER;
773 			} else {
774 				scsirate = (sc.device_flags[i] & CFXFER) << 4;
775 				if (sc.device_flags[i] & CFSYNCH)
776 					scsirate |= SOFS;
777 				if (sc.device_flags[i] & CFWIDEB)
778 					scsirate |= WIDEXFER;
779 			}
780 			ahc_outb(ahc, TARG_SCSIRATE + i, scsirate);
781 		}
782 		ahc_outb(ahc, DISC_DSB, ~(ahc->discenable & 0xff));
783 		ahc_outb(ahc, DISC_DSB + 1, ~((ahc->discenable >> 8) & 0xff));
784 		ahc_outb(ahc, ULTRA_ENB, ahc->ultraenb & 0xff);
785 		ahc_outb(ahc, ULTRA_ENB + 1, (ahc->ultraenb >> 8) & 0xff);
786 
787 		ahc->our_id = sc.brtime_id & CFSCSIID;
788 
789 		scsi_conf = (ahc->our_id & 0x7);
790 		if (sc.adapter_control & CFSPARITY)
791 			scsi_conf |= ENSPCHK;
792 		if (sc.adapter_control & CFRESETB)
793 			scsi_conf |= RESET_SCSI;
794 
795 		if (sc.bios_control & CFEXTEND)
796 			ahc->flags |= AHC_EXTENDED_TRANS_A;
797 		if (ahc->features & AHC_ULTRA
798 		 && (ahc->flags & AHC_NEWEEPROM_FMT) == 0) {
799 			/* Should we enable Ultra mode? */
800 			if (!(sc.adapter_control & CFULTRAEN))
801 				/* Treat us as a non-ultra card */
802 				ahc->ultraenb = 0;
803 		}
804 		/* Set SCSICONF info */
805 		ahc_outb(ahc, SCSICONF, scsi_conf);
806 	}
807 
808 	if ((ahc->features & AHC_SPIOCAP) != 0) {
809 		if ((ahc_inb(ahc, SPIOCAP) & SSPIOCPS) != 0) {
810 			configure_termination(ahc, &sc, &sd, sxfrctl1);
811 		}
812 	} else if (have_seeprom) {
813 		configure_termination(ahc, &sc, &sd, sxfrctl1);
814 	}
815 
816 	release_seeprom(&sd);
817 }
818 
819 static void
820 configure_termination(struct ahc_softc *ahc,
821 		      struct seeprom_config *sc,
822 		      struct seeprom_descriptor *sd,
823 		      u_int8_t *sxfrctl1)
824 {
825 	int max_targ = sc->max_targets & CFMAXTARG;
826 	u_int8_t brddat;
827 
828 	brddat = 0;
829 
830 	/*
831 	 * Update the settings in sxfrctl1 to match the
832 	 *termination settings
833 	 */
834 	*sxfrctl1 = 0;
835 
836 	/*
837 	 * SEECS must be on for the GALS to latch
838 	 * the data properly.  Be sure to leave MS
839 	 * on or we will release the seeprom.
840 	 */
841 	SEEPROM_OUTB(sd, sd->sd_MS | sd->sd_CS);
842 	if ((sc->adapter_control & CFAUTOTERM) != 0
843 	 || (ahc->features & AHC_ULTRA2) != 0) {
844 		int internal50_present;
845 		int internal68_present;
846 		int externalcable_present;
847 		int eeprom_present;
848 		int enableSEC_low;
849 		int enableSEC_high;
850 		int enablePRI_low;
851 		int enablePRI_high;
852 
853 		enableSEC_low = 0;
854 		enableSEC_high = 0;
855 		enablePRI_low = 0;
856 		enablePRI_high = 0;
857 		if (ahc->features & AHC_ULTRA2) {
858 			ahc_ultra2_term_detect(ahc, &enableSEC_low,
859 					       &enableSEC_high,
860 					       &enablePRI_low,
861 					       &enablePRI_high,
862 					       &eeprom_present);
863 			if ((sc->adapter_control & CFSEAUTOTERM) == 0) {
864 				enableSEC_low = (sc->adapter_control & CFSTERM);
865 				enableSEC_high =
866 				    (sc->adapter_control & CFWSTERM);
867 			}
868 			if ((sc->adapter_control & CFAUTOTERM) == 0) {
869 				enablePRI_low = enablePRI_high =
870 				    (sc->adapter_control & CFLVDSTERM);
871 			}
872 			/* Make the table calculations below happy */
873 			internal50_present = 0;
874 			internal68_present = 1;
875 			externalcable_present = 1;
876 		} else if ((ahc->features & AHC_SPIOCAP) != 0) {
877 			aic785X_cable_detect(ahc, &internal50_present,
878 					     &externalcable_present,
879 					     &eeprom_present);
880 		} else {
881 			aic787X_cable_detect(ahc, &internal50_present,
882 					     &internal68_present,
883 					     &externalcable_present,
884 					     &eeprom_present);
885 		}
886 
887 		if (max_targ <= 8) {
888 			internal68_present = 0;
889 		}
890 
891 		if (bootverbose) {
892 			if ((ahc->features & AHC_ULTRA2) == 0) {
893 				printf("%s: internal 50 cable %s present, "
894 				       "internal 68 cable %s present\n",
895 				       ahc_name(ahc),
896 				       internal50_present ? "is":"not",
897 				       internal68_present ? "is":"not");
898 
899 				printf("%s: external cable %s present\n",
900 				       ahc_name(ahc),
901 				       externalcable_present ? "is":"not");
902 			}
903 			printf("%s: BIOS eeprom %s present\n",
904 			       ahc_name(ahc), eeprom_present ? "is" : "not");
905 
906 		}
907 
908 		/*
909 		 * Now set the termination based on what
910 		 * we found.
911 		 * Flash Enable = BRDDAT7
912 		 * Secondary High Term Enable = BRDDAT6
913 		 * Secondary Low Term Enable = BRDDAT5 (7890)
914 		 * Primary High Term Enable = BRDDAT4 (7890)
915 		 */
916 		if ((ahc->features & AHC_ULTRA2) == 0
917 		    && (internal50_present != 0)
918 		    && (internal68_present != 0)
919 		    && (externalcable_present != 0)) {
920 			printf("%s: Illegal cable configuration!!. "
921 			       "Only two connectors on the "
922 			       "adapter may be used at a "
923 			       "time!\n", ahc_name(ahc));
924 		}
925 
926 		if ((max_targ > 8)
927 		 && ((externalcable_present == 0)
928 		  || (internal68_present == 0)
929 		  || (enableSEC_high != 0))) {
930 			brddat |= BRDDAT6;
931 			if (bootverbose)
932 				printf("%s: %sHigh byte termination Enabled\n",
933 				       ahc_name(ahc),
934 				       enableSEC_high ? "Secondary " : "");
935 		}
936 
937 		if (((internal50_present ? 1 : 0)
938 		   + (internal68_present ? 1 : 0)
939 		   + (externalcable_present ? 1 : 0)) <= 1
940 		 || (enableSEC_low != 0)) {
941 			if ((ahc->features & AHC_ULTRA2) != 0)
942 				brddat |= BRDDAT5;
943 			else
944 				*sxfrctl1 |= STPWEN;
945 			if (bootverbose)
946 				printf("%s: %sLow byte termination Enabled\n",
947 				       ahc_name(ahc),
948 				       enableSEC_low ? "Secondary " : "");
949 		}
950 
951 		if (enablePRI_low != 0) {
952 			*sxfrctl1 |= STPWEN;
953 			if (bootverbose)
954 				printf("%s: Primary Low Byte termination "
955 				       "Enabled\n", ahc_name(ahc));
956 		}
957 
958 		if (enablePRI_high != 0) {
959 			brddat |= BRDDAT4;
960 			if (bootverbose)
961 				printf("%s: Primary High Byte "
962 				       "termination Enabled\n",
963 				       ahc_name(ahc));
964 		}
965 
966 		write_brdctl(ahc, brddat);
967 
968 	} else {
969 		if (sc->adapter_control & CFSTERM) {
970 			if ((ahc->features & AHC_ULTRA2) != 0)
971 				brddat |= BRDDAT5;
972 			else
973 				*sxfrctl1 |= STPWEN;
974 
975 			if (bootverbose)
976 				printf("%s: %sLow byte termination Enabled\n",
977 				       ahc_name(ahc),
978 				       (ahc->features & AHC_ULTRA2) ? "Primary "
979 								    : "");
980 		}
981 
982 		if (sc->adapter_control & CFWSTERM) {
983 			brddat |= BRDDAT6;
984 			if (bootverbose)
985 				printf("%s: %sHigh byte termination Enabled\n",
986 				       ahc_name(ahc),
987 				       (ahc->features & AHC_ULTRA2)
988 				     ? "Secondary " : "");
989 		}
990 
991 		write_brdctl(ahc, brddat);
992 	}
993 	SEEPROM_OUTB(sd, sd->sd_MS); /* Clear CS */
994 }
995 
996 static void
997 ahc_ultra2_term_detect(struct ahc_softc *ahc, int *enableSEC_low,
998 		      int *enableSEC_high, int *enablePRI_low,
999 		      int *enablePRI_high, int *eeprom_present)
1000 {
1001 	u_int8_t brdctl;
1002 
1003 	/*
1004 	 * BRDDAT7 = Eeprom
1005 	 * BRDDAT6 = Enable Secondary High Byte termination
1006 	 * BRDDAT5 = Enable Secondary Low Byte termination
1007 	 * BRDDAT4 = Enable Primary low byte termination
1008 	 * BRDDAT3 = Enable Primary high byte termination
1009 	 */
1010 	brdctl = read_brdctl(ahc);
1011 
1012 	*eeprom_present = brdctl & BRDDAT7;
1013 	*enableSEC_high = (brdctl & BRDDAT6);
1014 	*enableSEC_low = (brdctl & BRDDAT5);
1015 	*enablePRI_low = (brdctl & BRDDAT4);
1016 	*enablePRI_high = (brdctl & BRDDAT3);
1017 }
1018 
1019 static void
1020 aic787X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
1021 		     int *internal68_present, int *externalcable_present,
1022 		     int *eeprom_present)
1023 {
1024 	u_int8_t brdctl;
1025 
1026 	/*
1027 	 * First read the status of our cables.
1028 	 * Set the rom bank to 0 since the
1029 	 * bank setting serves as a multiplexor
1030 	 * for the cable detection logic.
1031 	 * BRDDAT5 controls the bank switch.
1032 	 */
1033 	write_brdctl(ahc, 0);
1034 
1035 	/*
1036 	 * Now read the state of the internal
1037 	 * connectors.  BRDDAT6 is INT50 and
1038 	 * BRDDAT7 is INT68.
1039 	 */
1040 	brdctl = read_brdctl(ahc);
1041 	*internal50_present = !(brdctl & BRDDAT6);
1042 	*internal68_present = !(brdctl & BRDDAT7);
1043 
1044 	/*
1045 	 * Set the rom bank to 1 and determine
1046 	 * the other signals.
1047 	 */
1048 	write_brdctl(ahc, BRDDAT5);
1049 
1050 	/*
1051 	 * Now read the state of the external
1052 	 * connectors.  BRDDAT6 is EXT68 and
1053 	 * BRDDAT7 is EPROMPS.
1054 	 */
1055 	brdctl = read_brdctl(ahc);
1056 	*externalcable_present = !(brdctl & BRDDAT6);
1057 	*eeprom_present = brdctl & BRDDAT7;
1058 }
1059 
1060 static void
1061 aic785X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
1062 		     int *externalcable_present, int *eeprom_present)
1063 {
1064 	u_int8_t brdctl;
1065 
1066 	ahc_outb(ahc, BRDCTL, BRDRW|BRDCS);
1067 	ahc_outb(ahc, BRDCTL, 0);
1068 	brdctl = ahc_inb(ahc, BRDCTL);
1069 	*internal50_present = !(brdctl & BRDDAT5);
1070 	*externalcable_present = !(brdctl & BRDDAT6);
1071 
1072 	*eeprom_present = (ahc_inb(ahc, SPIOCAP) & EEPROM) != 0;
1073 }
1074 
1075 static int
1076 acquire_seeprom(struct ahc_softc *ahc, struct seeprom_descriptor *sd)
1077 {
1078 	int wait;
1079 
1080 	if ((ahc->features & AHC_SPIOCAP) != 0
1081 	 && (ahc_inb(ahc, SPIOCAP) & SEEPROM) == 0)
1082 			return (0);
1083 
1084 	/*
1085 	 * Request access of the memory port.  When access is
1086 	 * granted, SEERDY will go high.  We use a 1 second
1087 	 * timeout which should be near 1 second more than
1088 	 * is needed.  Reason: after the chip reset, there
1089 	 * should be no contention.
1090 	 */
1091 	SEEPROM_OUTB(sd, sd->sd_MS);
1092 	wait = 1000;  /* 1 second timeout in msec */
1093 	while (--wait && ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0)) {
1094 		DELAY(1000);  /* delay 1 msec */
1095 	}
1096 	if ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0) {
1097 		SEEPROM_OUTB(sd, 0);
1098 		return (0);
1099 	}
1100 	return(1);
1101 }
1102 
1103 static void
1104 release_seeprom(sd)
1105 	struct seeprom_descriptor *sd;
1106 {
1107 	/* Release access to the memory port and the serial EEPROM. */
1108 	SEEPROM_OUTB(sd, 0);
1109 }
1110 
1111 static void
1112 write_brdctl(ahc, value)
1113 	struct 	ahc_softc *ahc;
1114 	u_int8_t value;
1115 {
1116 	u_int8_t brdctl;
1117 
1118 	if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
1119 		brdctl = BRDSTB;
1120 	 	if (ahc->channel == 'B')
1121 			brdctl |= BRDCS;
1122 	} else if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7890) {
1123 		brdctl = 0;
1124 	} else {
1125 		brdctl = BRDSTB|BRDCS;
1126 	}
1127 	ahc_outb(ahc, BRDCTL, brdctl);
1128 	brdctl |= value;
1129 	ahc_outb(ahc, BRDCTL, brdctl);
1130 	if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7890)
1131 		brdctl |= BRDSTB_ULTRA2;
1132 	else
1133 		brdctl &= ~BRDSTB;
1134 	ahc_outb(ahc, BRDCTL, brdctl);
1135 	if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7890)
1136 		brdctl = 0;
1137 	else
1138 		brdctl &= ~BRDCS;
1139 	ahc_outb(ahc, BRDCTL, brdctl);
1140 }
1141 
1142 static u_int8_t
1143 read_brdctl(ahc)
1144 	struct 	ahc_softc *ahc;
1145 {
1146 	u_int8_t brdctl;
1147 	u_int8_t value;
1148 
1149 	if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
1150 		brdctl = BRDRW;
1151 	 	if (ahc->channel == 'B')
1152 			brdctl |= BRDCS;
1153 	} else if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7890) {
1154 		brdctl = BRDRW_ULTRA2;
1155 	} else {
1156 		brdctl = BRDRW|BRDCS;
1157 	}
1158 	ahc_outb(ahc, BRDCTL, brdctl);
1159 	value = ahc_inb(ahc, BRDCTL);
1160 	ahc_outb(ahc, BRDCTL, 0);
1161 	return (value);
1162 }
1163 
1164 #define	DPE	0x80
1165 #define SSE	0x40
1166 #define	RMA	0x20
1167 #define	RTA	0x10
1168 #define STA	0x08
1169 #define DPR	0x01
1170 
1171 void
1172 ahc_pci_intr(struct ahc_softc *ahc)
1173 {
1174 	u_int8_t status1;
1175 	pcici_t config_id;
1176 
1177 	status1 = pci_cfgread(ahc->pci_config_id, PCIR_STATUS + 1, /*bytes*/1);
1178 
1179 	if (status1 & DPE) {
1180 		printf("%s: Data Parity Error Detected during address "
1181 		       "or write data phase\n", ahc_name(ahc));
1182 	}
1183 	if (status1 & SSE) {
1184 		printf("%s: Signal System Error Detected\n", ahc_name(ahc));
1185 	}
1186 	if (status1 & RMA) {
1187 		printf("%s: Received a Master Abort\n", ahc_name(ahc));
1188 	}
1189 	if (status1 & RTA) {
1190 		printf("%s: Received a Target Abort\n", ahc_name(ahc));
1191 	}
1192 	if (status1 & STA) {
1193 		printf("%s: Signaled a Target Abort\n", ahc_name(ahc));
1194 	}
1195 	if (status1 & DPR) {
1196 		printf("%s: Data Parity Error has been reported via PERR#\n",
1197 		       ahc_name(ahc));
1198 	}
1199 	if ((status1 & (DPE|SSE|RMA|RTA|STA|DPR)) == 0) {
1200 		printf("%s: Latched PCIERR interrupt with "
1201 		       "no status bits set\n", ahc_name(ahc));
1202 	}
1203 	pci_cfgwrite(ahc->pci_config_id, PCIR_STATUS + 1, status1, /*bytes*/1);
1204 
1205 	if (status1 & (DPR|RMA|RTA)) {
1206 		ahc_outb(ahc, CLRINT, CLRPARERR);
1207 	}
1208 }
1209 
1210 #endif /* NPCI > 0 */
1211