Home | History | Annotate | Line # | Download | only in pci
isp_pci.c revision 1.62
      1 /* $NetBSD: isp_pci.c,v 1.62 2000/12/23 01:38:01 wiz Exp $ */
      2 /*
      3  * This driver, which is contained in NetBSD in the files:
      4  *
      5  *	sys/dev/ic/isp.c
      6  *	sys/dev/ic/isp_inline.h
      7  *	sys/dev/ic/isp_netbsd.c
      8  *	sys/dev/ic/isp_netbsd.h
      9  *	sys/dev/ic/isp_target.c
     10  *	sys/dev/ic/isp_target.h
     11  *	sys/dev/ic/isp_tpublic.h
     12  *	sys/dev/ic/ispmbox.h
     13  *	sys/dev/ic/ispreg.h
     14  *	sys/dev/ic/ispvar.h
     15  *	sys/microcode/isp/asm_sbus.h
     16  *	sys/microcode/isp/asm_1040.h
     17  *	sys/microcode/isp/asm_1080.h
     18  *	sys/microcode/isp/asm_12160.h
     19  *	sys/microcode/isp/asm_2100.h
     20  *	sys/microcode/isp/asm_2200.h
     21  *	sys/pci/isp_pci.c
     22  *	sys/sbus/isp_sbus.c
     23  *
     24  * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
     25  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
     26  * Linux versions. This tends to be an interesting maintenance problem.
     27  *
     28  * Please coordinate with Matthew Jacob on changes you wish to make here.
     29  */
     30 /*
     31  * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
     32  * Matthew Jacob (mjacob (at) nas.nasa.gov)
     33  */
     34 /*
     35  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
     36  * All rights reserved.
     37  *
     38  * Redistribution and use in source and binary forms, with or without
     39  * modification, are permitted provided that the following conditions
     40  * are met:
     41  * 1. Redistributions of source code must retain the above copyright
     42  *    notice, this list of conditions and the following disclaimer.
     43  * 2. Redistributions in binary form must reproduce the above copyright
     44  *    notice, this list of conditions and the following disclaimer in the
     45  *    documentation and/or other materials provided with the distribution.
     46  * 3. The name of the author may not be used to endorse or promote products
     47  *    derived from this software without specific prior written permission
     48  *
     49  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     50  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     51  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     52  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     53  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     54  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     55  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     56  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     57  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     58  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     59  */
     60 
     61 #include <dev/ic/isp_netbsd.h>
     62 #include <dev/pci/pcireg.h>
     63 #include <dev/pci/pcivar.h>
     64 #include <dev/pci/pcidevs.h>
     65 #include <uvm/uvm_extern.h>
     66 
     67 static u_int16_t isp_pci_rd_reg __P((struct ispsoftc *, int));
     68 static void isp_pci_wr_reg __P((struct ispsoftc *, int, u_int16_t));
     69 #if !(defined(ISP_DISABLE_1080_SUPPORT) && defined(ISP_DISABLE_12160_SUPPORT))
     70 static u_int16_t isp_pci_rd_reg_1080 __P((struct ispsoftc *, int));
     71 static void isp_pci_wr_reg_1080 __P((struct ispsoftc *, int, u_int16_t));
     72 #endif
     73 static int isp_pci_mbxdma __P((struct ispsoftc *));
     74 static int isp_pci_dmasetup __P((struct ispsoftc *, struct scsipi_xfer *,
     75 	ispreq_t *, u_int16_t *, u_int16_t));
     76 static void isp_pci_dmateardown __P((struct ispsoftc *, struct scsipi_xfer *,
     77 	u_int32_t));
     78 static void isp_pci_reset1 __P((struct ispsoftc *));
     79 static void isp_pci_dumpregs __P((struct ispsoftc *, const char *));
     80 static int isp_pci_intr __P((void *));
     81 
     82 #if	defined(ISP_DISABLE_1020_SUPPORT)
     83 #define	ISP_1040_RISC_CODE	NULL
     84 #else
     85 #define	ISP_1040_RISC_CODE	isp_1040_risc_code
     86 #include <dev/microcode/isp/asm_1040.h>
     87 #endif
     88 
     89 #if	defined(ISP_DISABLE_1080_SUPPORT)
     90 #define	ISP_1080_RISC_CODE	NULL
     91 #else
     92 #define	ISP_1080_RISC_CODE	isp_1080_risc_code
     93 #include <dev/microcode/isp/asm_1080.h>
     94 #endif
     95 
     96 #if	defined(ISP_DISABLE_12160_SUPPORT)
     97 #define	ISP_12160_RISC_CODE	NULL
     98 #else
     99 #define	ISP_12160_RISC_CODE	isp_12160_risc_code
    100 #include <dev/microcode/isp/asm_12160.h>
    101 #endif
    102 
    103 #if	defined(ISP_DISABLE_2100_SUPPORT)
    104 #define	ISP_2100_RISC_CODE	NULL
    105 #else
    106 #define	ISP_2100_RISC_CODE	isp_2100_risc_code
    107 #include <dev/microcode/isp/asm_2100.h>
    108 #endif
    109 
    110 #if	defined(ISP_DISABLE_2200_SUPPORT)
    111 #define	ISP_2200_RISC_CODE	NULL
    112 #else
    113 #define	ISP_2200_RISC_CODE	isp_2200_risc_code
    114 #include <dev/microcode/isp/asm_2200.h>
    115 #endif
    116 
    117 #ifndef	ISP_DISABLE_1020_SUPPORT
    118 static struct ispmdvec mdvec = {
    119 	isp_pci_rd_reg,
    120 	isp_pci_wr_reg,
    121 	isp_pci_mbxdma,
    122 	isp_pci_dmasetup,
    123 	isp_pci_dmateardown,
    124 	NULL,
    125 	isp_pci_reset1,
    126 	isp_pci_dumpregs,
    127 	ISP_1040_RISC_CODE,
    128 	BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64
    129 };
    130 #endif
    131 
    132 #ifndef	ISP_DISABLE_1080_SUPPORT
    133 static struct ispmdvec mdvec_1080 = {
    134 	isp_pci_rd_reg_1080,
    135 	isp_pci_wr_reg_1080,
    136 	isp_pci_mbxdma,
    137 	isp_pci_dmasetup,
    138 	isp_pci_dmateardown,
    139 	NULL,
    140 	isp_pci_reset1,
    141 	isp_pci_dumpregs,
    142 	ISP_1080_RISC_CODE,
    143 	BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64
    144 };
    145 #endif
    146 
    147 #ifndef	ISP_DISABLE_12160_SUPPORT
    148 static struct ispmdvec mdvec_12160 = {
    149 	isp_pci_rd_reg_1080,
    150 	isp_pci_wr_reg_1080,
    151 	isp_pci_mbxdma,
    152 	isp_pci_dmasetup,
    153 	isp_pci_dmateardown,
    154 	NULL,
    155 	isp_pci_reset1,
    156 	isp_pci_dumpregs,
    157 	ISP_12160_RISC_CODE,
    158 	BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64
    159 };
    160 #endif
    161 
    162 #ifndef	ISP_DISABLE_2100_SUPPORT
    163 static struct ispmdvec mdvec_2100 = {
    164 	isp_pci_rd_reg,
    165 	isp_pci_wr_reg,
    166 	isp_pci_mbxdma,
    167 	isp_pci_dmasetup,
    168 	isp_pci_dmateardown,
    169 	NULL,
    170 	isp_pci_reset1,
    171 	isp_pci_dumpregs,
    172 	ISP_2100_RISC_CODE
    173 };
    174 #endif
    175 
    176 #ifndef	ISP_DISABLE_2200_SUPPORT
    177 static struct ispmdvec mdvec_2200 = {
    178 	isp_pci_rd_reg,
    179 	isp_pci_wr_reg,
    180 	isp_pci_mbxdma,
    181 	isp_pci_dmasetup,
    182 	isp_pci_dmateardown,
    183 	NULL,
    184 	isp_pci_reset1,
    185 	isp_pci_dumpregs,
    186 	ISP_2200_RISC_CODE
    187 };
    188 #endif
    189 
    190 #ifndef	PCI_VENDOR_QLOGIC
    191 #define	PCI_VENDOR_QLOGIC	0x1077
    192 #endif
    193 
    194 #ifndef	PCI_PRODUCT_QLOGIC_ISP1020
    195 #define	PCI_PRODUCT_QLOGIC_ISP1020	0x1020
    196 #endif
    197 
    198 #ifndef	PCI_PRODUCT_QLOGIC_ISP1080
    199 #define	PCI_PRODUCT_QLOGIC_ISP1080	0x1080
    200 #endif
    201 
    202 #ifndef	PCI_PRODUCT_QLOGIC_ISP1240
    203 #define	PCI_PRODUCT_QLOGIC_ISP1240	0x1240
    204 #endif
    205 
    206 #ifndef	PCI_PRODUCT_QLOGIC_ISP1280
    207 #define	PCI_PRODUCT_QLOGIC_ISP1280	0x1280
    208 #endif
    209 
    210 #ifndef	PCI_PRODUCT_QLOGIC_ISP12160
    211 #define	PCI_PRODUCT_QLOGIC_ISP12160	0x1216
    212 #endif
    213 
    214 #ifndef	PCI_PRODUCT_QLOGIC_ISP2100
    215 #define	PCI_PRODUCT_QLOGIC_ISP2100	0x2100
    216 #endif
    217 
    218 #ifndef	PCI_PRODUCT_QLOGIC_ISP2200
    219 #define	PCI_PRODUCT_QLOGIC_ISP2200	0x2200
    220 #endif
    221 
    222 #define	PCI_QLOGIC_ISP	((PCI_PRODUCT_QLOGIC_ISP1020 << 16) | PCI_VENDOR_QLOGIC)
    223 
    224 #define	PCI_QLOGIC_ISP1080	\
    225 	((PCI_PRODUCT_QLOGIC_ISP1080 << 16) | PCI_VENDOR_QLOGIC)
    226 
    227 #define	PCI_QLOGIC_ISP1240	\
    228 	((PCI_PRODUCT_QLOGIC_ISP1240 << 16) | PCI_VENDOR_QLOGIC)
    229 
    230 #define	PCI_QLOGIC_ISP1280	\
    231 	((PCI_PRODUCT_QLOGIC_ISP1280 << 16) | PCI_VENDOR_QLOGIC)
    232 
    233 #define	PCI_QLOGIC_ISP12160	\
    234 	((PCI_PRODUCT_QLOGIC_ISP12160 << 16) | PCI_VENDOR_QLOGIC)
    235 
    236 #define	PCI_QLOGIC_ISP2100	\
    237 	((PCI_PRODUCT_QLOGIC_ISP2100 << 16) | PCI_VENDOR_QLOGIC)
    238 
    239 #define	PCI_QLOGIC_ISP2200	\
    240 	((PCI_PRODUCT_QLOGIC_ISP2200 << 16) | PCI_VENDOR_QLOGIC)
    241 
    242 #define	IO_MAP_REG	0x10
    243 #define	MEM_MAP_REG	0x14
    244 #define	PCIR_ROMADDR	0x30
    245 
    246 #define	PCI_DFLT_LTNCY	0x40
    247 #define	PCI_DFLT_LNSZ	0x10
    248 
    249 
    250 static int isp_pci_probe __P((struct device *, struct cfdata *, void *));
    251 static void isp_pci_attach __P((struct device *, struct device *, void *));
    252 
    253 struct isp_pcisoftc {
    254 	struct ispsoftc		pci_isp;
    255 	pci_chipset_tag_t	pci_pc;
    256 	pcitag_t		pci_tag;
    257 	bus_space_tag_t		pci_st;
    258 	bus_space_handle_t	pci_sh;
    259 	bus_dma_tag_t		pci_dmat;
    260 	bus_dmamap_t		pci_scratch_dmap;	/* for fcp only */
    261 	bus_dmamap_t		pci_rquest_dmap;
    262 	bus_dmamap_t		pci_result_dmap;
    263 	bus_dmamap_t		*pci_xfer_dmap;
    264 	void *			pci_ih;
    265 	int16_t			pci_poff[_NREG_BLKS];
    266 };
    267 
    268 struct cfattach isp_pci_ca = {
    269 	sizeof (struct isp_pcisoftc), isp_pci_probe, isp_pci_attach
    270 };
    271 
    272 #ifdef	DEBUG
    273 static char *vstring =
    274     "Qlogic ISP Driver, NetBSD (pci) Platform Version %d.%d Core Version %d.%d";
    275 #endif
    276 
    277 static int
    278 isp_pci_probe(parent, match, aux)
    279 	struct device *parent;
    280 	struct cfdata *match;
    281 	void *aux;
    282 {
    283 	struct pci_attach_args *pa = aux;
    284 	switch (pa->pa_id) {
    285 #ifndef	ISP_DISABLE_1020_SUPPORT
    286 	case PCI_QLOGIC_ISP:
    287 		return (1);
    288 #endif
    289 #ifndef	ISP_DISABLE_1080_SUPPORT
    290 	case PCI_QLOGIC_ISP1080:
    291 	case PCI_QLOGIC_ISP1240:
    292 	case PCI_QLOGIC_ISP1280:
    293 		return (1);
    294 #endif
    295 #ifndef	ISP_DISABLE_12160_SUPPORT
    296 	case PCI_QLOGIC_ISP12160:
    297 		return (1);
    298 #endif
    299 #ifndef	ISP_DISABLE_2100_SUPPORT
    300 	case PCI_QLOGIC_ISP2100:
    301 		return (1);
    302 #endif
    303 #ifndef	ISP_DISABLE_2200_SUPPORT
    304 	case PCI_QLOGIC_ISP2200:
    305 		return (1);
    306 #endif
    307 	default:
    308 		return (0);
    309 	}
    310 }
    311 
    312 
    313 static void
    314 isp_pci_attach(parent, self, aux)
    315 	struct device *parent, *self;
    316 	void *aux;
    317 {
    318 #ifdef	DEBUG
    319 	static char oneshot = 1;
    320 #endif
    321 	static char *nomem = "%s: no mem for sdparam table\n";
    322 	u_int32_t data, rev, linesz = PCI_DFLT_LNSZ;
    323 	struct pci_attach_args *pa = aux;
    324 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) self;
    325 	struct ispsoftc *isp = &pcs->pci_isp;
    326 	bus_space_tag_t st, iot, memt;
    327 	bus_space_handle_t sh, ioh, memh;
    328 	pci_intr_handle_t ih;
    329 	const char *intrstr;
    330 	int ioh_valid, memh_valid;
    331 
    332 	ioh_valid = (pci_mapreg_map(pa, IO_MAP_REG,
    333 	    PCI_MAPREG_TYPE_IO, 0,
    334 	    &iot, &ioh, NULL, NULL) == 0);
    335 	memh_valid = (pci_mapreg_map(pa, MEM_MAP_REG,
    336 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
    337 	    &memt, &memh, NULL, NULL) == 0);
    338 
    339 	if (memh_valid) {
    340 		st = memt;
    341 		sh = memh;
    342 	} else if (ioh_valid) {
    343 		st = iot;
    344 		sh = ioh;
    345 	} else {
    346 		printf(": unable to map device registers\n");
    347 		return;
    348 	}
    349 	printf("\n");
    350 
    351 	pcs->pci_st = st;
    352 	pcs->pci_sh = sh;
    353 	pcs->pci_dmat = pa->pa_dmat;
    354 	pcs->pci_pc = pa->pa_pc;
    355 	pcs->pci_tag = pa->pa_tag;
    356 	pcs->pci_poff[BIU_BLOCK >> _BLK_REG_SHFT] = BIU_REGS_OFF;
    357 	pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS_OFF;
    358 	pcs->pci_poff[SXP_BLOCK >> _BLK_REG_SHFT] = PCI_SXP_REGS_OFF;
    359 	pcs->pci_poff[RISC_BLOCK >> _BLK_REG_SHFT] = PCI_RISC_REGS_OFF;
    360 	pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] = DMA_REGS_OFF;
    361 	rev = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG) & 0xff;
    362 
    363 #ifndef	ISP_DISABLE_1020_SUPPORT
    364 	if (pa->pa_id == PCI_QLOGIC_ISP) {
    365 		isp->isp_mdvec = &mdvec;
    366 		isp->isp_type = ISP_HA_SCSI_UNKNOWN;
    367 		isp->isp_param = malloc(sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    368 		if (isp->isp_param == NULL) {
    369 			printf(nomem, isp->isp_name);
    370 			return;
    371 		}
    372 		bzero(isp->isp_param, sizeof (sdparam));
    373 	}
    374 #endif
    375 #ifndef	ISP_DISABLE_1080_SUPPORT
    376 	if (pa->pa_id == PCI_QLOGIC_ISP1080) {
    377 		isp->isp_mdvec = &mdvec_1080;
    378 		isp->isp_type = ISP_HA_SCSI_1080;
    379 		isp->isp_param = malloc(sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    380 		if (isp->isp_param == NULL) {
    381 			printf(nomem, isp->isp_name);
    382 			return;
    383 		}
    384 		bzero(isp->isp_param, sizeof (sdparam));
    385 		pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
    386 		    ISP1080_DMA_REGS_OFF;
    387 	}
    388 	if (pa->pa_id == PCI_QLOGIC_ISP1240) {
    389 		isp->isp_mdvec = &mdvec_1080;
    390 		isp->isp_type = ISP_HA_SCSI_1240;
    391 		isp->isp_param =
    392 		    malloc(2 * sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    393 		if (isp->isp_param == NULL) {
    394 			printf(nomem, isp->isp_name);
    395 			return;
    396 		}
    397 		bzero(isp->isp_param, 2 * sizeof (sdparam));
    398 		pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
    399 		    ISP1080_DMA_REGS_OFF;
    400 	}
    401 	if (pa->pa_id == PCI_QLOGIC_ISP1280) {
    402 		isp->isp_mdvec = &mdvec_1080;
    403 		isp->isp_type = ISP_HA_SCSI_1280;
    404 		isp->isp_param =
    405 		    malloc(2 * sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    406 		if (isp->isp_param == NULL) {
    407 			printf(nomem, isp->isp_name);
    408 			return;
    409 		}
    410 		bzero(isp->isp_param, 2 * sizeof (sdparam));
    411 		pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
    412 		    ISP1080_DMA_REGS_OFF;
    413 	}
    414 #endif
    415 #ifndef	ISP_DISABLE_12160_SUPPORT
    416 	if (pa->pa_id == PCI_QLOGIC_ISP12160) {
    417 		isp->isp_mdvec = &mdvec_12160;
    418 		isp->isp_type = ISP_HA_SCSI_12160;
    419 		isp->isp_param =
    420 		    malloc(2 * sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    421 		if (isp->isp_param == NULL) {
    422 			printf(nomem, isp->isp_name);
    423 			return;
    424 		}
    425 		bzero(isp->isp_param, 2 * sizeof (sdparam));
    426 		pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
    427 		    ISP1080_DMA_REGS_OFF;
    428 	}
    429 #endif
    430 #ifndef	ISP_DISABLE_2100_SUPPORT
    431 	if (pa->pa_id == PCI_QLOGIC_ISP2100) {
    432 		isp->isp_mdvec = &mdvec_2100;
    433 		isp->isp_type = ISP_HA_FC_2100;
    434 		isp->isp_param = malloc(sizeof (fcparam), M_DEVBUF, M_NOWAIT);
    435 		if (isp->isp_param == NULL) {
    436 			printf(nomem, isp->isp_name);
    437 			return;
    438 		}
    439 		bzero(isp->isp_param, sizeof (fcparam));
    440 		pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] =
    441 		    PCI_MBOX_REGS2100_OFF;
    442 		if (rev < 3) {
    443 			/*
    444 			 * XXX: Need to get the actual revision
    445 			 * XXX: number of the 2100 FB. At any rate,
    446 			 * XXX: lower cache line size for early revision
    447 			 * XXX; boards.
    448 			 */
    449 			linesz = 1;
    450 		}
    451 	}
    452 #endif
    453 #ifndef	ISP_DISABLE_2200_SUPPORT
    454 	if (pa->pa_id == PCI_QLOGIC_ISP2200) {
    455 		isp->isp_mdvec = &mdvec_2200;
    456 		isp->isp_type = ISP_HA_FC_2200;
    457 		isp->isp_param = malloc(sizeof (fcparam), M_DEVBUF, M_NOWAIT);
    458 		if (isp->isp_param == NULL) {
    459 			printf(nomem, isp->isp_name);
    460 			return;
    461 		}
    462 		bzero(isp->isp_param, sizeof (fcparam));
    463 		pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] =
    464 		    PCI_MBOX_REGS2100_OFF;
    465 		data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG);
    466 	}
    467 #endif
    468 	/*
    469 	 * Set up logging levels.
    470 	 */
    471 #ifdef	ISP_LOGDEFAULT
    472 	isp->isp_dblev = ISP_LOGDEFAULT;
    473 #else
    474 	isp->isp_dblev = ISP_LOGCONFIG|ISP_LOGWARN|ISP_LOGERR;
    475 #ifdef	SCSIDEBUG
    476 	isp->isp_dblev |= ISP_LOGDEBUG1|ISP_LOGDEBUG2;
    477 #endif
    478 #ifdef	DEBUG
    479 	isp->isp_dblev |= ISP_LOGDEBUG0|ISP_LOGINFO;
    480 #endif
    481 #endif
    482 
    483 #ifdef	DEBUG
    484 	if (oneshot) {
    485 		oneshot = 0;
    486 		isp_prt(isp, ISP_LOGCONFIG, vstring,
    487 		    ISP_PLATFORM_VERSION_MAJOR, ISP_PLATFORM_VERSION_MINOR,
    488 		    ISP_CORE_VERSION_MAJOR, ISP_CORE_VERSION_MINOR);
    489 	}
    490 #endif
    491 
    492 	isp->isp_revision = rev;
    493 
    494 	/*
    495 	 * Make sure that command register set sanely.
    496 	 */
    497 	data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    498 	data |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_INVALIDATE_ENABLE;
    499 
    500 	/*
    501 	 * Not so sure about these- but I think it's important that they get
    502 	 * enabled......
    503 	 */
    504 	data |= PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE;
    505 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, data);
    506 
    507 	/*
    508 	 * Make sure that the latency timer, cache line size,
    509 	 * and ROM is disabled.
    510 	 */
    511 	data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
    512 	data &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
    513 	data &= ~(PCI_CACHELINE_MASK << PCI_CACHELINE_SHIFT);
    514 	data |= (PCI_DFLT_LTNCY	<< PCI_LATTIMER_SHIFT);
    515 	data |= (linesz << PCI_CACHELINE_SHIFT);
    516 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG, data);
    517 
    518 	data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCIR_ROMADDR);
    519 	data &= ~1;
    520 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCIR_ROMADDR, data);
    521 
    522 	if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
    523 	    pa->pa_intrline, &ih)) {
    524 		printf("%s: couldn't map interrupt\n", isp->isp_name);
    525 		free(isp->isp_param, M_DEVBUF);
    526 		return;
    527 	}
    528 	intrstr = pci_intr_string(pa->pa_pc, ih);
    529 	if (intrstr == NULL)
    530 		intrstr = "<I dunno>";
    531 	pcs->pci_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO,
    532 	    isp_pci_intr, isp);
    533 	if (pcs->pci_ih == NULL) {
    534 		printf("%s: couldn't establish interrupt at %s\n",
    535 			isp->isp_name, intrstr);
    536 		free(isp->isp_param, M_DEVBUF);
    537 		return;
    538 	}
    539 
    540 	printf("%s: interrupting at %s\n", isp->isp_name, intrstr);
    541 
    542 	if (IS_FC(isp)) {
    543 		DEFAULT_NODEWWN(isp) = 0x400000007F000002;
    544 		DEFAULT_PORTWWN(isp) = 0x400000007F000002;
    545 	}
    546 
    547 	isp->isp_confopts = self->dv_cfdata->cf_flags;
    548 	ISP_LOCK(isp);
    549 	isp->isp_osinfo.no_mbox_ints = 1;
    550 	isp_reset(isp);
    551 	if (isp->isp_state != ISP_RESETSTATE) {
    552 		ISP_UNLOCK(isp);
    553 		free(isp->isp_param, M_DEVBUF);
    554 		return;
    555 	}
    556 	ENABLE_INTS(isp);
    557 	isp_init(isp);
    558 	if (isp->isp_state != ISP_INITSTATE) {
    559 		isp_uninit(isp);
    560 		ISP_UNLOCK(isp);
    561 		free(isp->isp_param, M_DEVBUF);
    562 		return;
    563 	}
    564 	/*
    565 	 * Do platform attach.
    566 	 */
    567 	ISP_UNLOCK(isp);
    568 	isp_attach(isp);
    569 	if (isp->isp_state != ISP_RUNSTATE) {
    570 		ISP_LOCK(isp);
    571 		isp_uninit(isp);
    572 		free(isp->isp_param, M_DEVBUF);
    573 		ISP_UNLOCK(isp);
    574 	}
    575 }
    576 
    577 static u_int16_t
    578 isp_pci_rd_reg(isp, regoff)
    579 	struct ispsoftc *isp;
    580 	int regoff;
    581 {
    582 	u_int16_t rv;
    583 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    584 	int offset, oldconf = 0;
    585 
    586 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    587 		/*
    588 		 * We will assume that someone has paused the RISC processor.
    589 		 */
    590 		oldconf = isp_pci_rd_reg(isp, BIU_CONF1);
    591 		isp_pci_wr_reg(isp, BIU_CONF1, oldconf | BIU_PCI_CONF1_SXP);
    592 		delay(250);
    593 	}
    594 	offset = pcs->pci_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
    595 	offset += (regoff & 0xff);
    596 	rv = bus_space_read_2(pcs->pci_st, pcs->pci_sh, offset);
    597 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    598 		isp_pci_wr_reg(isp, BIU_CONF1, oldconf);
    599 		delay(250);
    600 	}
    601 	return (rv);
    602 }
    603 
    604 static void
    605 isp_pci_wr_reg(isp, regoff, val)
    606 	struct ispsoftc *isp;
    607 	int regoff;
    608 	u_int16_t val;
    609 {
    610 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    611 	int offset, oldconf = 0;
    612 
    613 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    614 		/*
    615 		 * We will assume that someone has paused the RISC processor.
    616 		 */
    617 		oldconf = isp_pci_rd_reg(isp, BIU_CONF1);
    618 		isp_pci_wr_reg(isp, BIU_CONF1, oldconf | BIU_PCI_CONF1_SXP);
    619 		delay(250);
    620 	}
    621 	offset = pcs->pci_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
    622 	offset += (regoff & 0xff);
    623 	bus_space_write_2(pcs->pci_st, pcs->pci_sh, offset, val);
    624 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    625 		isp_pci_wr_reg(isp, BIU_CONF1, oldconf);
    626 		delay(250);
    627 	}
    628 }
    629 
    630 #if !(defined(ISP_DISABLE_1080_SUPPORT) && defined(ISP_DISABLE_12160_SUPPORT))
    631 static u_int16_t
    632 isp_pci_rd_reg_1080(isp, regoff)
    633 	struct ispsoftc *isp;
    634 	int regoff;
    635 {
    636 	u_int16_t rv, oc = 0;
    637 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    638 	int offset;
    639 
    640 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    641 		u_int16_t tc;
    642 		/*
    643 		 * We will assume that someone has paused the RISC processor.
    644 		 */
    645 		oc = isp_pci_rd_reg(isp, BIU_CONF1);
    646 		tc = oc & ~BIU_PCI1080_CONF1_DMA;
    647 		if (IS_1280(isp)) {
    648 			if (regoff & SXP_BANK1_SELECT)
    649 				tc |= BIU_PCI1080_CONF1_SXP0;
    650 			else
    651 				tc |= BIU_PCI1080_CONF1_SXP1;
    652 		} else {
    653 			tc |= BIU_PCI1080_CONF1_SXP0;
    654 		}
    655 		isp_pci_wr_reg(isp, BIU_CONF1, tc);
    656 		delay(250);
    657 	} else if ((regoff & _BLK_REG_MASK) == DMA_BLOCK) {
    658 		oc = isp_pci_rd_reg(isp, BIU_CONF1);
    659 		isp_pci_wr_reg(isp, BIU_CONF1, oc | BIU_PCI1080_CONF1_DMA);
    660 		delay(250);
    661 	}
    662 	offset = pcs->pci_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
    663 	offset += (regoff & 0xff);
    664 	rv = bus_space_read_2(pcs->pci_st, pcs->pci_sh, offset);
    665 	/*
    666 	 * Okay, because BIU_CONF1 is always nonzero
    667 	 */
    668 	if (oc) {
    669 		isp_pci_wr_reg(isp, BIU_CONF1, oc);
    670 		delay(250);
    671 	}
    672 	return (rv);
    673 }
    674 
    675 static void
    676 isp_pci_wr_reg_1080(isp, regoff, val)
    677 	struct ispsoftc *isp;
    678 	int regoff;
    679 	u_int16_t val;
    680 {
    681 	u_int16_t oc = 0;
    682 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    683 	int offset;
    684 
    685 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    686 		u_int16_t tc;
    687 		/*
    688 		 * We will assume that someone has paused the RISC processor.
    689 		 */
    690 		oc = isp_pci_rd_reg(isp, BIU_CONF1);
    691 		tc = oc & ~BIU_PCI1080_CONF1_DMA;
    692 		if (IS_1280(isp)) {
    693 			if (regoff & SXP_BANK1_SELECT)
    694 				tc |= BIU_PCI1080_CONF1_SXP0;
    695 			else
    696 				tc |= BIU_PCI1080_CONF1_SXP1;
    697 		} else {
    698 			tc |= BIU_PCI1080_CONF1_SXP0;
    699 		}
    700 		isp_pci_wr_reg(isp, BIU_CONF1, tc);
    701 		delay(250);
    702 	} else if ((regoff & _BLK_REG_MASK) == DMA_BLOCK) {
    703 		oc = isp_pci_rd_reg(isp, BIU_CONF1);
    704 		isp_pci_wr_reg(isp, BIU_CONF1, oc | BIU_PCI1080_CONF1_DMA);
    705 		delay(250);
    706 	}
    707 	offset = pcs->pci_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
    708 	offset += (regoff & 0xff);
    709 	bus_space_write_2(pcs->pci_st, pcs->pci_sh, offset, val);
    710 	/*
    711 	 * Okay, because BIU_CONF1 is always nonzero
    712 	 */
    713 	if (oc) {
    714 		isp_pci_wr_reg(isp, BIU_CONF1, oc);
    715 		delay(250);
    716 	}
    717 }
    718 #endif
    719 
    720 static int
    721 isp_pci_mbxdma(isp)
    722 	struct ispsoftc *isp;
    723 {
    724 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp;
    725 	bus_dma_tag_t dmat = pcs->pci_dmat;
    726 	bus_dma_segment_t sg;
    727 	bus_size_t len;
    728 	fcparam *fcp;
    729 	int rs, i;
    730 
    731 	if (isp->isp_rquest_dma)	/* been here before? */
    732 		return (0);
    733 
    734 	len = isp->isp_maxcmds * sizeof (XS_T);
    735 	isp->isp_xflist = (XS_T **) malloc(len, M_DEVBUF, M_WAITOK);
    736 	if (isp->isp_xflist == NULL) {
    737 		isp_prt(isp, ISP_LOGERR, "cannot malloc xflist array");
    738 		return (1);
    739 	}
    740 	bzero(isp->isp_xflist, len);
    741 	len = isp->isp_maxcmds * sizeof (bus_dmamap_t);
    742 	pcs->pci_xfer_dmap = (bus_dmamap_t *) malloc(len, M_DEVBUF, M_WAITOK);
    743 	if (pcs->pci_xfer_dmap == NULL) {
    744 		free(isp->isp_xflist, M_DEVBUF);
    745 		isp->isp_xflist = NULL;
    746 		isp_prt(isp, ISP_LOGERR, "cannot malloc dma map array");
    747 		return (1);
    748 	}
    749 	for (i = 0; i < isp->isp_maxcmds; i++) {
    750 		if (bus_dmamap_create(dmat, MAXPHYS, (MAXPHYS / PAGE_SIZE) + 1,
    751 		    MAXPHYS, 0, BUS_DMA_NOWAIT, &pcs->pci_xfer_dmap[i])) {
    752 			isp_prt(isp, ISP_LOGERR, "cannot create dma maps");
    753 			break;
    754 		}
    755 	}
    756 	if (i < isp->isp_maxcmds) {
    757 		while (--i >= 0) {
    758 			bus_dmamap_destroy(dmat, pcs->pci_xfer_dmap[i]);
    759 		}
    760 		free(isp->isp_xflist, M_DEVBUF);
    761 		free(pcs->pci_xfer_dmap, M_DEVBUF);
    762 		isp->isp_xflist = NULL;
    763 		pcs->pci_xfer_dmap = NULL;
    764 		return (1);
    765 	}
    766 
    767 	/*
    768 	 * Allocate and map the request queue.
    769 	 */
    770 	len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp));
    771 	if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs,
    772 			     BUS_DMA_NOWAIT) ||
    773 	    bus_dmamem_map(pcs->pci_dmat, &sg, rs, len,
    774 	    (caddr_t *)&isp->isp_rquest, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
    775 		goto dmafail;
    776 	}
    777 
    778 	if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
    779 	    &pcs->pci_rquest_dmap) || bus_dmamap_load(dmat,
    780 	    pcs->pci_rquest_dmap, (caddr_t)isp->isp_rquest, len, NULL,
    781 	    BUS_DMA_NOWAIT)) {
    782 		goto dmafail;
    783 	}
    784 
    785 	isp->isp_rquest_dma = pcs->pci_rquest_dmap->dm_segs[0].ds_addr;
    786 
    787 	/*
    788 	 * Allocate and map the result queue.
    789 	 */
    790 	len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp));
    791 	if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs,
    792 			     BUS_DMA_NOWAIT) ||
    793 	    bus_dmamem_map(dmat, &sg, rs, len, (caddr_t *)&isp->isp_result,
    794 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
    795 		goto dmafail;
    796 	}
    797 	if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
    798 	    &pcs->pci_result_dmap) || bus_dmamap_load(pcs->pci_dmat,
    799 	    pcs->pci_result_dmap, (caddr_t)isp->isp_result, len, NULL,
    800 	    BUS_DMA_NOWAIT)) {
    801 		goto dmafail;
    802 	}
    803 	isp->isp_result_dma = pcs->pci_result_dmap->dm_segs[0].ds_addr;
    804 
    805 	if (IS_SCSI(isp)) {
    806 		return (0);
    807 	}
    808 
    809 	fcp = isp->isp_param;
    810 	len = ISP2100_SCRLEN;
    811 	if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs,
    812 			     BUS_DMA_NOWAIT) ||
    813 	    bus_dmamem_map(dmat, &sg, rs, len, (caddr_t *)&fcp->isp_scratch,
    814 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
    815 		goto dmafail;
    816 	}
    817 	if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
    818 	    &pcs->pci_scratch_dmap) || bus_dmamap_load(dmat,
    819 	    pcs->pci_scratch_dmap, (caddr_t)fcp->isp_scratch, len, NULL,
    820 	    BUS_DMA_NOWAIT)) {
    821 		goto dmafail;
    822 	}
    823 	fcp->isp_scdma = pcs->pci_scratch_dmap->dm_segs[0].ds_addr;
    824 	return (0);
    825 dmafail:
    826 	isp_prt(isp, ISP_LOGERR, "mailbox dma setup failure");
    827 	for (i = 0; i < isp->isp_maxcmds; i++) {
    828 		bus_dmamap_destroy(dmat, pcs->pci_xfer_dmap[i]);
    829 	}
    830 	free(isp->isp_xflist, M_DEVBUF);
    831 	free(pcs->pci_xfer_dmap, M_DEVBUF);
    832 	isp->isp_xflist = NULL;
    833 	pcs->pci_xfer_dmap = NULL;
    834 	return (1);
    835 }
    836 
    837 static int
    838 isp_pci_dmasetup(isp, xs, rq, iptrp, optr)
    839 	struct ispsoftc *isp;
    840 	struct scsipi_xfer *xs;
    841 	ispreq_t *rq;
    842 	u_int16_t *iptrp;
    843 	u_int16_t optr;
    844 {
    845 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp;
    846 	bus_dmamap_t dmap;
    847 	ispcontreq_t *crq;
    848 	int segcnt, seg, error, ovseg, seglim, drq;
    849 
    850 	dmap = pcs->pci_xfer_dmap[isp_handle_index(rq->req_handle)];
    851 
    852 	if (xs->datalen == 0) {
    853 		rq->req_seg_count = 1;
    854 		goto mbxsync;
    855 	}
    856 	if (xs->xs_control & XS_CTL_DATA_IN) {
    857 		drq = REQFLAG_DATA_IN;
    858 	} else {
    859 		drq = REQFLAG_DATA_OUT;
    860 	}
    861 
    862 	if (IS_FC(isp)) {
    863 		seglim = ISP_RQDSEG_T2;
    864 		((ispreqt2_t *)rq)->req_totalcnt = xs->datalen;
    865 		((ispreqt2_t *)rq)->req_flags |= drq;
    866 	} else {
    867 		rq->req_flags |= drq;
    868 		if (XS_CDBLEN(xs) > 12) {
    869 			seglim = 0;
    870 		} else {
    871 			seglim = ISP_RQDSEG;
    872 		}
    873 	}
    874 	error = bus_dmamap_load(pcs->pci_dmat, dmap, xs->data, xs->datalen,
    875 	    NULL, xs->xs_control & XS_CTL_NOSLEEP ?
    876 	    BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
    877 	if (error) {
    878 		XS_SETERR(xs, HBA_BOTCH);
    879 		return (CMD_COMPLETE);
    880 	}
    881 
    882 	segcnt = dmap->dm_nsegs;
    883 
    884 	isp_prt(isp, ISP_LOGDEBUG2, "%d byte %s %p in %d segs",
    885 	    xs->datalen, (xs->xs_control & XS_CTL_DATA_IN)? "read to" :
    886 	    "write from", xs->data, segcnt);
    887 
    888 	for (seg = 0, rq->req_seg_count = 0;
    889 	    seglim && seg < segcnt && rq->req_seg_count < seglim;
    890 	    seg++, rq->req_seg_count++) {
    891 		if (IS_FC(isp)) {
    892 			ispreqt2_t *rq2 = (ispreqt2_t *)rq;
    893 #if	_BYTE_ORDER == _BIG_ENDIAN
    894 			rq2->req_dataseg[rq2->req_seg_count].ds_count =
    895 			    bswap32(dmap->dm_segs[seg].ds_len);
    896 			rq2->req_dataseg[rq2->req_seg_count].ds_base =
    897 			    bswap32(dmap->dm_segs[seg].ds_addr);
    898 #else
    899 			rq2->req_dataseg[rq2->req_seg_count].ds_count =
    900 			    dmap->dm_segs[seg].ds_len;
    901 			rq2->req_dataseg[rq2->req_seg_count].ds_base =
    902 			    dmap->dm_segs[seg].ds_addr;
    903 #endif
    904 		} else {
    905 #if	_BYTE_ORDER == _BIG_ENDIAN
    906 			rq->req_dataseg[rq->req_seg_count].ds_count =
    907 			    bswap32(dmap->dm_segs[seg].ds_len);
    908 			rq->req_dataseg[rq->req_seg_count].ds_base =
    909 			    bswap32(dmap->dm_segs[seg].ds_addr);
    910 #else
    911 			rq->req_dataseg[rq->req_seg_count].ds_count =
    912 			    dmap->dm_segs[seg].ds_len;
    913 			rq->req_dataseg[rq->req_seg_count].ds_base =
    914 			    dmap->dm_segs[seg].ds_addr;
    915 #endif
    916 		}
    917 		isp_prt(isp, ISP_LOGDEBUG2, "seg0.[%d]={0x%x,%d}",
    918 		    rq->req_seg_count, dmap->dm_segs[seg].ds_addr,
    919 		    dmap->dm_segs[seg].ds_len);
    920 	}
    921 
    922 	if (seg == segcnt)
    923 		goto dmasync;
    924 
    925 	do {
    926 		crq = (ispcontreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, *iptrp);
    927 		*iptrp = ISP_NXT_QENTRY(*iptrp, RQUEST_QUEUE_LEN(isp));
    928 		if (*iptrp == optr) {
    929 			isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow++");
    930 			bus_dmamap_unload(pcs->pci_dmat, dmap);
    931 			XS_SETERR(xs, HBA_BOTCH);
    932 			return (CMD_EAGAIN);
    933 		}
    934 		rq->req_header.rqs_entry_count++;
    935 		bzero((void *)crq, sizeof (*crq));
    936 		crq->req_header.rqs_entry_count = 1;
    937 		crq->req_header.rqs_entry_type = RQSTYPE_DATASEG;
    938 
    939 		for (ovseg = 0; seg < segcnt && ovseg < ISP_CDSEG;
    940 		    rq->req_seg_count++, seg++, ovseg++) {
    941 #if	_BYTE_ORDER == _BIG_ENDIAN
    942 			crq->req_dataseg[ovseg].ds_count =
    943 			    bswap32(dmap->dm_segs[seg].ds_len);
    944 			crq->req_dataseg[ovseg].ds_base =
    945 			    bswap32(dmap->dm_segs[seg].ds_addr);
    946 #else
    947 			crq->req_dataseg[ovseg].ds_count =
    948 			    dmap->dm_segs[seg].ds_len;
    949 			crq->req_dataseg[ovseg].ds_base =
    950 			    dmap->dm_segs[seg].ds_addr;
    951 #endif
    952 			isp_prt(isp, ISP_LOGDEBUG2, "seg%d.[%d]={0x%x,%d}",
    953 			    rq->req_header.rqs_entry_count - 1,
    954 			    rq->req_seg_count, dmap->dm_segs[seg].ds_addr,
    955 			    dmap->dm_segs[seg].ds_len);
    956 		}
    957 	} while (seg < segcnt);
    958 
    959 
    960 dmasync:
    961 	bus_dmamap_sync(pcs->pci_dmat, dmap, 0, dmap->dm_mapsize,
    962 	    (xs->xs_control & XS_CTL_DATA_IN) ?  BUS_DMASYNC_PREREAD :
    963 	    BUS_DMASYNC_PREWRITE);
    964 
    965 mbxsync:
    966 	ISP_SWIZZLE_REQUEST(isp, rq);
    967 	bus_dmamap_sync(pcs->pci_dmat, pcs->pci_rquest_dmap, 0,
    968 	    pcs->pci_rquest_dmap->dm_mapsize, BUS_DMASYNC_PREWRITE);
    969 	return (CMD_QUEUED);
    970 }
    971 
    972 static int
    973 isp_pci_intr(arg)
    974 	void *arg;
    975 {
    976 	int rv;
    977 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)arg;
    978 	bus_dmamap_sync(pcs->pci_dmat, pcs->pci_result_dmap, 0,
    979 	    pcs->pci_result_dmap->dm_mapsize, BUS_DMASYNC_POSTREAD);
    980 	pcs->pci_isp.isp_osinfo.onintstack = 1;
    981 	rv = isp_intr(arg);
    982 	pcs->pci_isp.isp_osinfo.onintstack = 0;
    983 	return (rv);
    984 }
    985 
    986 static void
    987 isp_pci_dmateardown(isp, xs, handle)
    988 	struct ispsoftc *isp;
    989 	struct scsipi_xfer *xs;
    990 	u_int32_t handle;
    991 {
    992 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp;
    993 	bus_dmamap_t dmap = pcs->pci_xfer_dmap[isp_handle_index(handle)];
    994 	bus_dmamap_sync(pcs->pci_dmat, dmap, 0, dmap->dm_mapsize,
    995 	    xs->xs_control & XS_CTL_DATA_IN ?
    996 	    BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
    997 	bus_dmamap_unload(pcs->pci_dmat, dmap);
    998 }
    999 
   1000 static void
   1001 isp_pci_reset1(isp)
   1002 	struct ispsoftc *isp;
   1003 {
   1004 	/* Make sure the BIOS is disabled */
   1005 	isp_pci_wr_reg(isp, HCCR, PCI_HCCR_CMD_BIOS);
   1006 }
   1007 
   1008 static void
   1009 isp_pci_dumpregs(isp, msg)
   1010 	struct ispsoftc *isp;
   1011 	const char *msg;
   1012 {
   1013 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp;
   1014 	if (msg)
   1015 		printf("%s: %s\n", isp->isp_name, msg);
   1016 	if (IS_SCSI(isp))
   1017 		printf("    biu_conf1=%x", ISP_READ(isp, BIU_CONF1));
   1018 	else
   1019 		printf("    biu_csr=%x", ISP_READ(isp, BIU2100_CSR));
   1020 	printf(" biu_icr=%x biu_isr=%x biu_sema=%x ", ISP_READ(isp, BIU_ICR),
   1021 	    ISP_READ(isp, BIU_ISR), ISP_READ(isp, BIU_SEMA));
   1022 	printf("risc_hccr=%x\n", ISP_READ(isp, HCCR));
   1023 
   1024 
   1025 	if (IS_SCSI(isp)) {
   1026 		ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
   1027 		printf("    cdma_conf=%x cdma_sts=%x cdma_fifostat=%x\n",
   1028 			ISP_READ(isp, CDMA_CONF), ISP_READ(isp, CDMA_STATUS),
   1029 			ISP_READ(isp, CDMA_FIFO_STS));
   1030 		printf("    ddma_conf=%x ddma_sts=%x ddma_fifostat=%x\n",
   1031 			ISP_READ(isp, DDMA_CONF), ISP_READ(isp, DDMA_STATUS),
   1032 			ISP_READ(isp, DDMA_FIFO_STS));
   1033 		printf("    sxp_int=%x sxp_gross=%x sxp(scsi_ctrl)=%x\n",
   1034 			ISP_READ(isp, SXP_INTERRUPT),
   1035 			ISP_READ(isp, SXP_GROSS_ERR),
   1036 			ISP_READ(isp, SXP_PINS_CTRL));
   1037 		ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
   1038 	}
   1039 	printf("    mbox regs: %x %x %x %x %x\n",
   1040 	    ISP_READ(isp, OUTMAILBOX0), ISP_READ(isp, OUTMAILBOX1),
   1041 	    ISP_READ(isp, OUTMAILBOX2), ISP_READ(isp, OUTMAILBOX3),
   1042 	    ISP_READ(isp, OUTMAILBOX4));
   1043 	printf("    PCI Status Command/Status=%x\n",
   1044 	    pci_conf_read(pcs->pci_pc, pcs->pci_tag, PCI_COMMAND_STATUS_REG));
   1045 }
   1046