Home | History | Annotate | Line # | Download | only in pci
isp_pci.c revision 1.14.2.1
      1  1.14.2.1   bouyer /*	$NetBSD: isp_pci.c,v 1.14.2.1 1997/07/01 17:35:35 bouyer Exp $	*/
      2       1.1      cgd 
      3       1.1      cgd /*
      4       1.1      cgd  * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
      5       1.1      cgd  *
      6       1.1      cgd  * Copyright (c) 1997 by Matthew Jacob
      7       1.1      cgd  * NASA AMES Research Center
      8       1.1      cgd  * All rights reserved.
      9       1.1      cgd  *
     10       1.1      cgd  * Redistribution and use in source and binary forms, with or without
     11       1.1      cgd  * modification, are permitted provided that the following conditions
     12       1.1      cgd  * are met:
     13       1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     14       1.1      cgd  *    notice immediately at the beginning of the file, without modification,
     15       1.1      cgd  *    this list of conditions, and the following disclaimer.
     16       1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     18       1.1      cgd  *    documentation and/or other materials provided with the distribution.
     19       1.1      cgd  * 3. The name of the author may not be used to endorse or promote products
     20       1.1      cgd  *    derived from this software without specific prior written permission.
     21       1.1      cgd  *
     22       1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     23       1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24       1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25       1.1      cgd  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     26       1.1      cgd  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27       1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28       1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29       1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30       1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31       1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32       1.1      cgd  * SUCH DAMAGE.
     33       1.1      cgd  */
     34       1.1      cgd 
     35       1.1      cgd #include <sys/param.h>
     36       1.1      cgd #include <sys/systm.h>
     37       1.1      cgd #include <sys/malloc.h>
     38       1.1      cgd #include <sys/kernel.h>
     39       1.1      cgd #include <sys/queue.h>
     40       1.1      cgd #include <sys/device.h>
     41       1.1      cgd #include <machine/bus.h>
     42       1.1      cgd #include <machine/intr.h>
     43  1.14.2.1   bouyer #include <dev/scsipi/scsi_all.h>
     44  1.14.2.1   bouyer #include <dev/scsipi/scsipi_all.h>
     45  1.14.2.1   bouyer #include <dev/scsipi/scsiconf.h>
     46       1.1      cgd #include <dev/pci/pcireg.h>
     47       1.1      cgd #include <dev/pci/pcivar.h>
     48       1.1      cgd #include <dev/pci/pcidevs.h>
     49       1.3      cgd #include <vm/vm.h>
     50       1.1      cgd 
     51       1.1      cgd #include <dev/ic/ispreg.h>
     52       1.1      cgd #include <dev/ic/ispvar.h>
     53       1.1      cgd #include <dev/ic/ispmbox.h>
     54       1.1      cgd #include <dev/microcode/isp/asm_pci.h>
     55       1.3      cgd 
     56       1.1      cgd static u_int16_t isp_pci_rd_reg __P((struct ispsoftc *, int));
     57       1.1      cgd static void isp_pci_wr_reg __P((struct ispsoftc *, int, u_int16_t));
     58      1.13  thorpej static int isp_pci_mbxdma __P((struct ispsoftc *));
     59  1.14.2.1   bouyer static int isp_pci_dmasetup __P((struct ispsoftc *, struct scsipi_xfer *,
     60      1.13  thorpej 	ispreq_t *, u_int8_t *, u_int8_t));
     61  1.14.2.1   bouyer static void isp_pci_dmateardown __P((struct ispsoftc *, struct scsipi_xfer *,
     62      1.13  thorpej 	u_int32_t));
     63       1.1      cgd 
     64       1.1      cgd static void isp_pci_reset1 __P((struct ispsoftc *));
     65       1.1      cgd 
     66       1.1      cgd static struct ispmdvec mdvec = {
     67       1.1      cgd 	isp_pci_rd_reg,
     68       1.1      cgd 	isp_pci_wr_reg,
     69       1.1      cgd 	isp_pci_mbxdma,
     70       1.1      cgd 	isp_pci_dmasetup,
     71      1.13  thorpej 	isp_pci_dmateardown,
     72       1.1      cgd 	NULL,
     73       1.1      cgd 	isp_pci_reset1,
     74       1.5      cgd 	ISP_RISC_CODE,
     75       1.1      cgd 	ISP_CODE_LENGTH,
     76       1.1      cgd 	ISP_CODE_ORG,
     77      1.10   mjacob 	BIU_PCI_CONF1_FIFO_16 | BIU_BURST_ENABLE,
     78      1.10   mjacob 	60	/* MAGIC- all known PCI card implementations are 60MHz */
     79       1.1      cgd };
     80       1.1      cgd 
     81       1.1      cgd #define	PCI_QLOGIC_ISP	\
     82       1.1      cgd 	((PCI_PRODUCT_QLOGIC_ISP1020 << 16) | PCI_VENDOR_QLOGIC)
     83       1.1      cgd 
     84       1.6      cgd #define IO_MAP_REG	0x10
     85       1.6      cgd #define MEM_MAP_REG	0x14
     86       1.6      cgd 
     87       1.1      cgd 
     88       1.1      cgd #ifdef	__BROKEN_INDIRECT_CONFIG
     89       1.1      cgd static int isp_pci_probe __P((struct device *, void *, void *));
     90       1.1      cgd #else
     91       1.1      cgd static int isp_pci_probe __P((struct device *, struct cfdata *, void *));
     92       1.1      cgd #endif
     93       1.1      cgd static void isp_pci_attach __P((struct device *, struct device *, void *));
     94       1.1      cgd 
     95       1.1      cgd struct isp_pcisoftc {
     96       1.1      cgd 	struct ispsoftc		pci_isp;
     97       1.6      cgd 	bus_space_tag_t		pci_st;
     98       1.6      cgd 	bus_space_handle_t	pci_sh;
     99      1.13  thorpej 	bus_dma_tag_t		pci_dmat;
    100      1.13  thorpej 	bus_dmamap_t		pci_rquest_dmap;
    101      1.13  thorpej 	bus_dmamap_t		pci_result_dmap;
    102      1.13  thorpej 	bus_dmamap_t		pci_xfer_dmap[RQUEST_QUEUE_LEN];
    103       1.1      cgd 	void *			pci_ih;
    104       1.1      cgd };
    105       1.1      cgd 
    106       1.1      cgd struct cfattach isp_pci_ca = {
    107       1.1      cgd 	sizeof (struct isp_pcisoftc), isp_pci_probe, isp_pci_attach
    108       1.1      cgd };
    109       1.1      cgd 
    110       1.1      cgd static int
    111       1.1      cgd isp_pci_probe(parent, match, aux)
    112       1.1      cgd         struct device *parent;
    113       1.1      cgd #ifdef	__BROKEN_INDIRECT_CONFIG
    114       1.1      cgd         void *match, *aux;
    115       1.1      cgd #else
    116       1.1      cgd         struct cfdata *match;
    117       1.1      cgd 	void *aux;
    118       1.1      cgd #endif
    119       1.1      cgd {
    120       1.1      cgd         struct pci_attach_args *pa = aux;
    121       1.1      cgd 
    122       1.1      cgd 	if (pa->pa_id == PCI_QLOGIC_ISP) {
    123       1.1      cgd 		return (1);
    124       1.1      cgd 	} else {
    125       1.1      cgd 		return (0);
    126       1.1      cgd 	}
    127       1.1      cgd }
    128       1.1      cgd 
    129       1.1      cgd 
    130       1.1      cgd static void
    131       1.1      cgd isp_pci_attach(parent, self, aux)
    132       1.1      cgd         struct device *parent, *self;
    133       1.1      cgd         void *aux;
    134       1.1      cgd {
    135       1.1      cgd 	struct pci_attach_args *pa = aux;
    136       1.1      cgd 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) self;
    137      1.11      cgd 	bus_space_tag_t st, iot, memt;
    138      1.11      cgd 	bus_space_handle_t sh, ioh, memh;
    139       1.1      cgd 	pci_intr_handle_t ih;
    140       1.1      cgd 	const char *intrstr;
    141      1.11      cgd 	int ioh_valid, memh_valid;
    142      1.13  thorpej 	int i;
    143       1.1      cgd 
    144      1.12      cgd 	ioh_valid = (pci_mapreg_map(pa, IO_MAP_REG,
    145      1.11      cgd 	    PCI_MAPREG_TYPE_IO, 0,
    146      1.11      cgd 	    &iot, &ioh, NULL, NULL) == 0);
    147      1.12      cgd 	memh_valid = (pci_mapreg_map(pa, MEM_MAP_REG,
    148      1.11      cgd 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
    149      1.11      cgd 	    &memt, &memh, NULL, NULL) == 0);
    150      1.11      cgd 
    151      1.11      cgd 	if (memh_valid) {
    152      1.11      cgd 		st = memt;
    153      1.11      cgd 		sh = memh;
    154      1.11      cgd 	} else if (ioh_valid) {
    155      1.11      cgd 		st = iot;
    156      1.11      cgd 		sh = ioh;
    157       1.6      cgd 	} else {
    158      1.11      cgd 		printf(": unable to map device registers\n");
    159       1.9      cgd 		return;
    160       1.1      cgd 	}
    161       1.1      cgd 	printf("\n");
    162       1.1      cgd 
    163       1.6      cgd 	pcs->pci_st = st;
    164       1.6      cgd 	pcs->pci_sh = sh;
    165      1.13  thorpej 	pcs->pci_dmat = pa->pa_dmat;
    166       1.1      cgd 	pcs->pci_isp.isp_mdvec = &mdvec;
    167       1.1      cgd 	isp_reset(&pcs->pci_isp);
    168       1.1      cgd 	if (pcs->pci_isp.isp_state != ISP_RESETSTATE) {
    169       1.1      cgd 		return;
    170       1.1      cgd 	}
    171       1.1      cgd 	isp_init(&pcs->pci_isp);
    172       1.1      cgd 	if (pcs->pci_isp.isp_state != ISP_INITSTATE) {
    173       1.1      cgd 		isp_uninit(&pcs->pci_isp);
    174       1.1      cgd 		return;
    175       1.1      cgd 	}
    176       1.1      cgd 
    177       1.1      cgd 	if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
    178       1.1      cgd 			 pa->pa_intrline, &ih)) {
    179       1.1      cgd 		printf("%s: couldn't map interrupt\n", pcs->pci_isp.isp_name);
    180       1.1      cgd 		isp_uninit(&pcs->pci_isp);
    181       1.1      cgd 		return;
    182       1.1      cgd 	}
    183       1.1      cgd 
    184       1.1      cgd 	intrstr = pci_intr_string(pa->pa_pc, ih);
    185       1.1      cgd 	if (intrstr == NULL)
    186       1.1      cgd 		intrstr = "<I dunno>";
    187       1.1      cgd 	pcs->pci_ih =
    188       1.1      cgd 	  pci_intr_establish(pa->pa_pc, ih, IPL_BIO, isp_intr, &pcs->pci_isp);
    189       1.1      cgd 	if (pcs->pci_ih == NULL) {
    190       1.1      cgd 		printf("%s: couldn't establish interrupt at %s\n",
    191       1.1      cgd 			pcs->pci_isp.isp_name, intrstr);
    192       1.1      cgd 		isp_uninit(&pcs->pci_isp);
    193       1.1      cgd 		return;
    194       1.1      cgd 	}
    195       1.1      cgd 	printf("%s: interrupting at %s\n", pcs->pci_isp.isp_name, intrstr);
    196       1.1      cgd 
    197       1.1      cgd 	/*
    198      1.13  thorpej 	 * Create the DMA maps for the data transfers.
    199      1.13  thorpej 	 */
    200      1.13  thorpej 	for (i = 0; i < RQUEST_QUEUE_LEN; i++) {
    201      1.13  thorpej 		if (bus_dmamap_create(pcs->pci_dmat, MAXPHYS,
    202      1.13  thorpej 		    (MAXPHYS / NBPG) + 1, MAXPHYS, 0, BUS_DMA_NOWAIT,
    203      1.13  thorpej 		    &pcs->pci_xfer_dmap[i])) {
    204      1.13  thorpej 			printf("%s: can't create dma maps\n",
    205      1.13  thorpej 			    pcs->pci_isp.isp_name);
    206      1.13  thorpej 			isp_uninit(&pcs->pci_isp);
    207      1.13  thorpej 			return;
    208      1.13  thorpej 		}
    209      1.13  thorpej 	}
    210      1.13  thorpej 
    211      1.13  thorpej 	/*
    212       1.1      cgd 	 * Do Generic attach now.
    213       1.1      cgd 	 */
    214       1.1      cgd 	isp_attach(&pcs->pci_isp);
    215       1.1      cgd 	if (pcs->pci_isp.isp_state != ISP_RUNSTATE) {
    216       1.1      cgd 		isp_uninit(&pcs->pci_isp);
    217       1.1      cgd 	}
    218       1.1      cgd }
    219       1.1      cgd 
    220       1.1      cgd #define  PCI_BIU_REGS_OFF		0x00
    221       1.1      cgd #define	 PCI_MBOX_REGS_OFF		0x70
    222       1.1      cgd #define	 PCI_SXP_REGS_OFF		0x80
    223       1.1      cgd #define	 PCI_RISC_REGS_OFF		0x80
    224       1.1      cgd 
    225       1.1      cgd static u_int16_t
    226       1.1      cgd isp_pci_rd_reg(isp, regoff)
    227       1.1      cgd 	struct ispsoftc *isp;
    228       1.1      cgd 	int regoff;
    229       1.1      cgd {
    230       1.1      cgd 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    231       1.1      cgd 	int offset;
    232       1.1      cgd 	if ((regoff & BIU_BLOCK) != 0) {
    233       1.1      cgd 		offset = PCI_BIU_REGS_OFF;
    234       1.1      cgd 	} else if ((regoff & MBOX_BLOCK) != 0) {
    235       1.1      cgd 		offset = PCI_MBOX_REGS_OFF;
    236       1.1      cgd 	} else if ((regoff & SXP_BLOCK) != 0) {
    237       1.1      cgd 		offset = PCI_SXP_REGS_OFF;
    238       1.1      cgd 		/*
    239       1.1      cgd 		 * XXX
    240       1.1      cgd 		 */
    241       1.1      cgd 		panic("SXP Registers not accessible yet!");
    242       1.1      cgd 	} else {
    243       1.1      cgd 		offset = PCI_RISC_REGS_OFF;
    244       1.1      cgd 	}
    245       1.1      cgd 	regoff &= 0xff;
    246       1.1      cgd 	offset += regoff;
    247       1.6      cgd 	return bus_space_read_2(pcs->pci_st, pcs->pci_sh, offset);
    248       1.1      cgd }
    249       1.1      cgd 
    250       1.1      cgd static void
    251       1.1      cgd isp_pci_wr_reg(isp, regoff, val)
    252       1.1      cgd 	struct ispsoftc *isp;
    253       1.1      cgd 	int regoff;
    254       1.1      cgd 	u_int16_t val;
    255       1.1      cgd {
    256       1.1      cgd 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    257       1.1      cgd 	int offset;
    258       1.1      cgd 	if ((regoff & BIU_BLOCK) != 0) {
    259       1.1      cgd 		offset = PCI_BIU_REGS_OFF;
    260       1.1      cgd 	} else if ((regoff & MBOX_BLOCK) != 0) {
    261       1.1      cgd 		offset = PCI_MBOX_REGS_OFF;
    262       1.1      cgd 	} else if ((regoff & SXP_BLOCK) != 0) {
    263       1.1      cgd 		offset = PCI_SXP_REGS_OFF;
    264       1.1      cgd 		/*
    265       1.1      cgd 		 * XXX
    266       1.1      cgd 		 */
    267       1.1      cgd 		panic("SXP Registers not accessible yet!");
    268       1.1      cgd 	} else {
    269       1.1      cgd 		offset = PCI_RISC_REGS_OFF;
    270       1.1      cgd 	}
    271       1.1      cgd 	regoff &= 0xff;
    272       1.1      cgd 	offset += regoff;
    273       1.6      cgd 	bus_space_write_2(pcs->pci_st, pcs->pci_sh, offset, val);
    274       1.1      cgd }
    275       1.1      cgd 
    276      1.13  thorpej static int
    277      1.13  thorpej isp_pci_mbxdma(isp)
    278       1.1      cgd 	struct ispsoftc *isp;
    279       1.1      cgd {
    280      1.13  thorpej 	struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp;
    281      1.13  thorpej 	bus_dma_segment_t seg;
    282      1.13  thorpej 	bus_size_t len;
    283      1.13  thorpej 	int rseg;
    284      1.13  thorpej 
    285      1.13  thorpej 	/*
    286      1.13  thorpej 	 * Allocate and map the request queue.
    287      1.13  thorpej 	 */
    288      1.13  thorpej 	len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN);
    289      1.13  thorpej 	if (bus_dmamem_alloc(pci->pci_dmat, len, NBPG, 0, &seg, 1, &rseg,
    290      1.13  thorpej 	      BUS_DMA_NOWAIT) ||
    291      1.13  thorpej 	    bus_dmamem_map(pci->pci_dmat, &seg, rseg, len,
    292      1.13  thorpej 	      (caddr_t *)&isp->isp_rquest, BUS_DMA_NOWAIT|BUS_DMAMEM_NOSYNC))
    293      1.13  thorpej 		return (1);
    294      1.13  thorpej 	if (bus_dmamap_create(pci->pci_dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
    295      1.13  thorpej 	      &pci->pci_rquest_dmap) ||
    296      1.13  thorpej 	    bus_dmamap_load(pci->pci_dmat, pci->pci_rquest_dmap,
    297      1.13  thorpej 	      (caddr_t)isp->isp_rquest, len, NULL, BUS_DMA_NOWAIT))
    298      1.13  thorpej 		return (1);
    299      1.13  thorpej 
    300      1.13  thorpej 	isp->isp_rquest_dma = pci->pci_rquest_dmap->dm_segs[0].ds_addr;
    301      1.13  thorpej 
    302      1.13  thorpej 	/*
    303      1.13  thorpej 	 * Allocate and map the result queue.
    304      1.13  thorpej 	 */
    305      1.13  thorpej 	len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN);
    306      1.13  thorpej 	if (bus_dmamem_alloc(pci->pci_dmat, len, NBPG, 0, &seg, 1, &rseg,
    307      1.13  thorpej 	      BUS_DMA_NOWAIT) ||
    308      1.13  thorpej 	    bus_dmamem_map(pci->pci_dmat, &seg, rseg, len,
    309      1.13  thorpej 	      (caddr_t *)&isp->isp_result, BUS_DMA_NOWAIT|BUS_DMAMEM_NOSYNC))
    310      1.13  thorpej 		return (1);
    311      1.13  thorpej 	if (bus_dmamap_create(pci->pci_dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
    312      1.13  thorpej 	      &pci->pci_result_dmap) ||
    313      1.13  thorpej 	    bus_dmamap_load(pci->pci_dmat, pci->pci_result_dmap,
    314      1.13  thorpej 	      (caddr_t)isp->isp_result, len, NULL, BUS_DMA_NOWAIT))
    315      1.13  thorpej 		return (1);
    316       1.1      cgd 
    317      1.13  thorpej 	isp->isp_result_dma = pci->pci_result_dmap->dm_segs[0].ds_addr;
    318       1.1      cgd 
    319      1.13  thorpej 	return (0);
    320       1.1      cgd }
    321       1.1      cgd 
    322       1.1      cgd static int
    323       1.1      cgd isp_pci_dmasetup(isp, xs, rq, iptrp, optr)
    324       1.1      cgd 	struct ispsoftc *isp;
    325  1.14.2.1   bouyer 	struct scsipi_xfer *xs;
    326       1.1      cgd 	ispreq_t *rq;
    327       1.1      cgd 	u_int8_t *iptrp;
    328       1.1      cgd 	u_int8_t optr;
    329       1.1      cgd {
    330      1.13  thorpej 	struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp;
    331      1.13  thorpej 	bus_dmamap_t dmap = pci->pci_xfer_dmap[rq->req_handle];
    332       1.1      cgd 	ispcontreq_t *crq;
    333      1.13  thorpej 	int segcnt, seg, error, ovseg;
    334       1.1      cgd 
    335       1.1      cgd 	if (xs->datalen == 0) {
    336       1.1      cgd 		rq->req_seg_count = 1;
    337       1.1      cgd 		rq->req_flags |= REQFLAG_DATA_IN;
    338       1.1      cgd 		return (0);
    339       1.1      cgd 	}
    340       1.1      cgd 
    341      1.13  thorpej 	if (rq->req_handle >= RQUEST_QUEUE_LEN) {
    342      1.14  thorpej 		panic("%s: bad handle (%d) in isp_pci_dmasetup\n",
    343      1.13  thorpej 		    isp->isp_name, rq->req_handle);
    344      1.13  thorpej 		/* NOTREACHED */
    345      1.13  thorpej 	}
    346      1.13  thorpej 
    347       1.1      cgd 	if (xs->flags & SCSI_DATA_IN) {
    348       1.1      cgd 		rq->req_flags |= REQFLAG_DATA_IN;
    349       1.1      cgd 	} else {
    350       1.1      cgd 		rq->req_flags |= REQFLAG_DATA_OUT;
    351       1.1      cgd 	}
    352       1.1      cgd 
    353      1.13  thorpej 	error = bus_dmamap_load(pci->pci_dmat, dmap, xs->data, xs->datalen,
    354      1.13  thorpej 	    NULL, xs->flags & SCSI_NOSLEEP ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
    355      1.13  thorpej 	if (error)
    356      1.13  thorpej 		return (error);
    357      1.13  thorpej 
    358      1.13  thorpej 	segcnt = dmap->dm_nsegs;
    359      1.13  thorpej 
    360      1.13  thorpej 	for (seg = 0, rq->req_seg_count = 0;
    361      1.13  thorpej 	    seg < segcnt && rq->req_seg_count < ISP_RQDSEG;
    362      1.13  thorpej 	    seg++, rq->req_seg_count++) {
    363      1.13  thorpej 		rq->req_dataseg[rq->req_seg_count].ds_count =
    364      1.13  thorpej 		    dmap->dm_segs[seg].ds_len;
    365      1.13  thorpej 		rq->req_dataseg[rq->req_seg_count].ds_base =
    366      1.13  thorpej 		    dmap->dm_segs[seg].ds_addr;
    367       1.1      cgd 	}
    368       1.1      cgd 
    369      1.13  thorpej 	if (seg == segcnt)
    370      1.13  thorpej 		goto mapsync;
    371       1.1      cgd 
    372       1.1      cgd 	do {
    373      1.13  thorpej 		crq = (ispcontreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest,
    374      1.13  thorpej 		    *iptrp);
    375       1.1      cgd 		*iptrp = (*iptrp + 1) & (RQUEST_QUEUE_LEN - 1);
    376       1.1      cgd 		if (*iptrp == optr) {
    377       1.1      cgd 			printf("%s: Request Queue Overflow++\n",
    378       1.1      cgd 			       isp->isp_name);
    379      1.13  thorpej 			bus_dmamap_unload(pci->pci_dmat, dmap);
    380      1.13  thorpej 			return (EFBIG);
    381       1.1      cgd 		}
    382       1.1      cgd 		rq->req_header.rqs_entry_count++;
    383       1.1      cgd 		bzero((void *)crq, sizeof (*crq));
    384       1.1      cgd 		crq->req_header.rqs_entry_count = 1;
    385       1.1      cgd 		crq->req_header.rqs_entry_type = RQSTYPE_DATASEG;
    386      1.13  thorpej 
    387      1.13  thorpej 		for (ovseg = 0; seg < segcnt && ovseg < ISP_CDSEG;
    388      1.13  thorpej 		    rq->req_seg_count++, seg++, ovseg++) {
    389      1.13  thorpej 			crq->req_dataseg[ovseg].ds_count =
    390      1.13  thorpej 			    dmap->dm_segs[seg].ds_len;
    391      1.13  thorpej 			crq->req_dataseg[ovseg].ds_base =
    392      1.13  thorpej 			    dmap->dm_segs[seg].ds_addr;
    393       1.1      cgd 		}
    394      1.13  thorpej 	} while (seg < segcnt);
    395      1.13  thorpej 
    396      1.13  thorpej  mapsync:
    397      1.13  thorpej 	bus_dmamap_sync(pci->pci_dmat, dmap, xs->flags & SCSI_DATA_IN ?
    398      1.13  thorpej 	    BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
    399       1.1      cgd 	return (0);
    400      1.13  thorpej }
    401      1.13  thorpej 
    402      1.13  thorpej static void
    403      1.13  thorpej isp_pci_dmateardown(isp, xs, handle)
    404      1.13  thorpej 	struct ispsoftc *isp;
    405  1.14.2.1   bouyer 	struct scsipi_xfer *xs;
    406      1.13  thorpej 	u_int32_t handle;
    407      1.13  thorpej {
    408      1.13  thorpej 	struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp;
    409      1.13  thorpej 	bus_dmamap_t dmap = pci->pci_xfer_dmap[handle];
    410      1.13  thorpej 
    411      1.13  thorpej 	bus_dmamap_sync(pci->pci_dmat, dmap, xs->flags & SCSI_DATA_IN ?
    412      1.13  thorpej 	    BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
    413      1.13  thorpej 
    414      1.13  thorpej 	bus_dmamap_unload(pci->pci_dmat, dmap);
    415       1.1      cgd }
    416       1.1      cgd 
    417       1.1      cgd static void
    418       1.1      cgd isp_pci_reset1(isp)
    419       1.1      cgd 	struct ispsoftc *isp;
    420       1.1      cgd {
    421       1.1      cgd 	/* Make sure the BIOS is disabled */
    422       1.1      cgd 	isp_pci_wr_reg(isp, HCCR, PCI_HCCR_CMD_BIOS);
    423       1.1      cgd }
    424