diff options
| author | 2001-12-14 00:20:54 +0000 | |
|---|---|---|
| committer | 2001-12-14 00:20:54 +0000 | |
| commit | 408644beda554b29623e8534b77de8e7e3883fa3 (patch) | |
| tree | ae7353913a5b1a3dbf777ea0b6396a106367d4fe /sys/dev/pci/isp_pci.c | |
| parent | Roll f/w to latest && greatest for 2100 and 2200 cards. (diff) | |
| download | wireguard-openbsd-408644beda554b29623e8534b77de8e7e3883fa3.tar.xz wireguard-openbsd-408644beda554b29623e8534b77de8e7e3883fa3.zip | |
Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.
The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it).
One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.
Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.
For OpenSD, it does a ddi_dmamap_sync as appropriate. This gets us out of
the explicit ddi_dmamap_sync on the whole response queue that we did for SBus
cards at each interrupt. Now, because SBus/sparc doesn't use bus_dma, some
shenanigans were done to support this. But Jason was nice enough to test the
SBus/sparcv9 changes for me, and they did the right thing as well.
Set things up so that platforms that cannot have an SBus don't get a lot of
the SBus code checks (dead coded out).
Additional changes:
Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.
Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).
Explicitly decode GetAllNext SNS Response back *as* a GetAllNext response.
Otherwise, we won't unswizzle it correctly.
Nuke some additional __P macros.
Diffstat (limited to 'sys/dev/pci/isp_pci.c')
| -rw-r--r-- | sys/dev/pci/isp_pci.c | 234 |
1 files changed, 145 insertions, 89 deletions
diff --git a/sys/dev/pci/isp_pci.c b/sys/dev/pci/isp_pci.c index 063c5033aec..405803a2180 100644 --- a/sys/dev/pci/isp_pci.c +++ b/sys/dev/pci/isp_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isp_pci.c,v 1.26 2001/11/05 17:25:58 art Exp $ */ +/* $OpenBSD: isp_pci.c,v 1.27 2001/12/14 00:20:55 mjacob Exp $ */ /* * PCI specific probe and attach routines for Qlogic ISP SCSI adapters. * @@ -299,10 +299,6 @@ struct isp_pcisoftc { pcitag_t pci_tag; bus_space_tag_t pci_st; bus_space_handle_t pci_sh; - bus_dma_tag_t pci_dmat; - bus_dmamap_t pci_scratch_dmap; /* for fcp only */ - bus_dmamap_t pci_rquest_dmap; - bus_dmamap_t pci_result_dmap; bus_dmamap_t *pci_xfer_dmap; void * pci_ih; int16_t pci_poff[_NREG_BLKS]; @@ -371,7 +367,7 @@ isp_pci_attach(struct device *parent, struct device *self, void *aux) bus_space_handle_t sh, ioh, memh; pci_intr_handle_t ih; const char *intrstr; - int ioh_valid, memh_valid, i; + int ioh_valid, memh_valid; bus_addr_t iobase, mbase; bus_size_t iosize, msize; @@ -437,7 +433,6 @@ isp_pci_attach(struct device *parent, struct device *self, void *aux) pcs->pci_st = st; pcs->pci_sh = sh; - pcs->pci_dmat = pa->pa_dmat; pcs->pci_pc = pa->pa_pc; pcs->pci_tag = pa->pa_tag; pcs->pci_poff[BIU_BLOCK >> _BLK_REG_SHFT] = BIU_REGS_OFF; @@ -591,6 +586,7 @@ isp_pci_attach(struct device *parent, struct device *self, void *aux) } #endif + isp->isp_dmatag = pa->pa_dmat; isp->isp_revision = rev; /* @@ -663,23 +659,6 @@ isp_pci_attach(struct device *parent, struct device *self, void *aux) free(isp->isp_param, M_DEVBUF); return; } - - /* - * Create the DMA maps for the data transfers. - */ - for (i = 0; i < isp->isp_maxcmds; i++) { - if (bus_dmamap_create(pcs->pci_dmat, MAXPHYS, - (MAXPHYS / NBPG) + 1, MAXPHYS, 0, BUS_DMA_NOWAIT, - &pcs->pci_xfer_dmap[i])) { - printf("%s: can't create dma maps\n", isp->isp_name); - isp_uninit(isp); - ISP_UNLOCK(isp); - free(isp->isp_param, M_DEVBUF); - return; - } - } - - /* * Do Generic attach now. */ @@ -908,51 +887,87 @@ isp_pci_wr_reg_1080(struct ispsoftc *isp, int regoff, u_int16_t val) static int isp_pci_mbxdma(struct ispsoftc *isp) { - struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; - bus_dma_segment_t seg; + struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp; + bus_dma_tag_t dmat = isp->isp_dmatag; + bus_dma_segment_t sg; bus_size_t len; fcparam *fcp; - int rseg; + int rs, i; if (isp->isp_rquest_dma) /* been here before? */ return (0); - len = isp->isp_maxcmds * sizeof (XS_T); + len = isp->isp_maxcmds * sizeof (XS_T *); isp->isp_xflist = (XS_T **) malloc(len, M_DEVBUF, M_WAITOK); + if (isp->isp_xflist == NULL) { + isp_prt(isp, ISP_LOGERR, "cannot malloc xflist array"); + return (1); + } bzero(isp->isp_xflist, len); len = isp->isp_maxcmds * sizeof (bus_dmamap_t); - pci->pci_xfer_dmap = (bus_dmamap_t *) malloc(len, M_DEVBUF, M_WAITOK); + pcs->pci_xfer_dmap = (bus_dmamap_t *) malloc(len, M_DEVBUF, M_WAITOK); + if (pcs->pci_xfer_dmap == NULL) { + free(isp->isp_xflist, M_DEVBUF); + isp->isp_xflist = NULL; + isp_prt(isp, ISP_LOGERR, "cannot malloc dma map array"); + return (1); + } + + for (i = 0; i < isp->isp_maxcmds; i++) { + if (bus_dmamap_create(dmat, MAXPHYS, (MAXPHYS / NBPG) + 1, + MAXPHYS, 0, BUS_DMA_NOWAIT, &pcs->pci_xfer_dmap[i])) { + isp_prt(isp, ISP_LOGERR, "cannot create dma maps"); + break; + } + } + + if (i < isp->isp_maxcmds) { + while (--i >= 0) { + bus_dmamap_destroy(dmat, pcs->pci_xfer_dmap[i]); + } + free(isp->isp_xflist, M_DEVBUF); + free(pcs->pci_xfer_dmap, M_DEVBUF); + isp->isp_xflist = NULL; + pcs->pci_xfer_dmap = NULL; + return (1); + } /* * Allocate and map the request queue. */ len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)); - if (bus_dmamem_alloc(pci->pci_dmat, len, NBPG, 0, &seg, 1, &rseg, - BUS_DMA_NOWAIT) || bus_dmamem_map(pci->pci_dmat, &seg, rseg, len, - (caddr_t *)&isp->isp_rquest, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) - return (1); - if (bus_dmamap_create(pci->pci_dmat, len, 1, len, 0, BUS_DMA_NOWAIT, - &pci->pci_rquest_dmap) || - bus_dmamap_load(pci->pci_dmat, pci->pci_rquest_dmap, - (caddr_t)isp->isp_rquest, len, NULL, BUS_DMA_NOWAIT)) - return (1); + if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs, + BUS_DMA_NOWAIT) || + bus_dmamem_map(isp->isp_dmatag, &sg, rs, len, + (caddr_t *)&isp->isp_rquest, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) { + goto dmafail; + } - isp->isp_rquest_dma = pci->pci_rquest_dmap->dm_segs[0].ds_addr; + if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT, + &isp->isp_rqdmap) || bus_dmamap_load(dmat, isp->isp_rqdmap, + (caddr_t)isp->isp_rquest, len, NULL, + BUS_DMA_NOWAIT)) { + goto dmafail; + } + isp->isp_rquest_dma = isp->isp_rqdmap->dm_segs[0].ds_addr; /* * Allocate and map the result queue. */ len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp)); - if (bus_dmamem_alloc(pci->pci_dmat, len, NBPG, 0, &seg, 1, &rseg, - BUS_DMA_NOWAIT) || bus_dmamem_map(pci->pci_dmat, &seg, rseg, len, - (caddr_t *)&isp->isp_result, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) - return (1); - if (bus_dmamap_create(pci->pci_dmat, len, 1, len, 0, BUS_DMA_NOWAIT, - &pci->pci_result_dmap) || - bus_dmamap_load(pci->pci_dmat, pci->pci_result_dmap, - (caddr_t)isp->isp_result, len, NULL, BUS_DMA_NOWAIT)) - return (1); - isp->isp_result_dma = pci->pci_result_dmap->dm_segs[0].ds_addr; + if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs, + BUS_DMA_NOWAIT) || + bus_dmamem_map(dmat, &sg, rs, len, (caddr_t *)&isp->isp_result, + BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) { + goto dmafail; + } + if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT, + &isp->isp_rsdmap) || bus_dmamap_load(isp->isp_dmatag, + isp->isp_rsdmap, (caddr_t)isp->isp_result, len, NULL, + BUS_DMA_NOWAIT)) { + goto dmafail; + } + isp->isp_result_dma = isp->isp_rsdmap->dm_segs[0].ds_addr; if (IS_SCSI(isp)) { return (0); @@ -960,30 +975,44 @@ isp_pci_mbxdma(struct ispsoftc *isp) fcp = isp->isp_param; len = ISP2100_SCRLEN; - if (bus_dmamem_alloc(pci->pci_dmat, len, NBPG, 0, &seg, 1, &rseg, - BUS_DMA_NOWAIT) || bus_dmamem_map(pci->pci_dmat, &seg, rseg, len, - (caddr_t *)&fcp->isp_scratch, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) - return (1); - if (bus_dmamap_create(pci->pci_dmat, len, 1, len, 0, BUS_DMA_NOWAIT, - &pci->pci_scratch_dmap) || bus_dmamap_load(pci->pci_dmat, - pci->pci_scratch_dmap, (caddr_t)fcp->isp_scratch, len, NULL, - BUS_DMA_NOWAIT)) - return (1); - fcp->isp_scdma = pci->pci_scratch_dmap->dm_segs[0].ds_addr; + if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs, + BUS_DMA_NOWAIT) || + bus_dmamem_map(dmat, &sg, rs, len, (caddr_t *)&fcp->isp_scratch, + BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) { + goto dmafail; + } + if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT, + &isp->isp_scdmap) || bus_dmamap_load(dmat, + isp->isp_scdmap, (caddr_t)fcp->isp_scratch, len, NULL, + BUS_DMA_NOWAIT)) { + goto dmafail; + } + fcp->isp_scdma = isp->isp_scdmap->dm_segs[0].ds_addr; return (0); +dmafail: + isp_prt(isp, ISP_LOGERR, "mailbox dma setup failure"); + for (i = 0; i < isp->isp_maxcmds; i++) { + bus_dmamap_destroy(dmat, pcs->pci_xfer_dmap[i]); + } + free(isp->isp_xflist, M_DEVBUF); + free(pcs->pci_xfer_dmap, M_DEVBUF); + isp->isp_xflist = NULL; + pcs->pci_xfer_dmap = NULL; + return (1); } static int -isp_pci_dmasetup(struct ispsoftc *isp, XS_T *xs, ispreq_t *rq, u_int16_t *iptrp, - u_int16_t optr) +isp_pci_dmasetup(struct ispsoftc *isp, XS_T *xs, ispreq_t *rq, + u_int16_t *nxtip, u_int16_t optr) { - struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; + struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp; bus_dmamap_t dmap; - ispcontreq_t *crq; + u_int16_t starti = isp->isp_reqidx, nxti = *nxtip; + ispreq_t *qep; int segcnt, seg, error, ovseg, seglim, drq; - dmap = pci->pci_xfer_dmap[isp_handle_index(rq->req_handle)]; - + qep = (ispreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, starti); + dmap = pcs->pci_xfer_dmap[isp_handle_index(rq->req_handle)]; if (xs->datalen == 0) { rq->req_seg_count = 1; goto mbxsync; @@ -1000,14 +1029,14 @@ isp_pci_dmasetup(struct ispsoftc *isp, XS_T *xs, ispreq_t *rq, u_int16_t *iptrp, ((ispreqt2_t *)rq)->req_totalcnt = xs->datalen; ((ispreqt2_t *)rq)->req_flags |= drq; } else { + rq->req_flags |= drq; if (XS_CDBLEN(xs) > 12) seglim = 0; else seglim = ISP_RQDSEG; - rq->req_flags |= drq; } - error = bus_dmamap_load(pci->pci_dmat, dmap, xs->data, xs->datalen, - NULL, xs->flags & SCSI_NOSLEEP ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK); + error = bus_dmamap_load(isp->isp_dmatag, dmap, xs->data, xs->datalen, + NULL, (xs->flags & SCSI_NOSLEEP) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK); if (error) { XS_SETERR(xs, HBA_BOTCH); return (CMD_COMPLETE); @@ -1015,6 +1044,10 @@ isp_pci_dmasetup(struct ispsoftc *isp, XS_T *xs, ispreq_t *rq, u_int16_t *iptrp, segcnt = dmap->dm_nsegs; + isp_prt(isp, ISP_LOGDEBUG2, "%d byte %s %p in %d segs", + xs->datalen, (xs->flags & SCSI_DATA_IN)? "read to" : + "write from", xs->data, segcnt); + for (seg = 0, rq->req_seg_count = 0; seg < segcnt && rq->req_seg_count < seglim; seg++, rq->req_seg_count++) { @@ -1030,17 +1063,27 @@ isp_pci_dmasetup(struct ispsoftc *isp, XS_T *xs, ispreq_t *rq, u_int16_t *iptrp, rq->req_dataseg[rq->req_seg_count].ds_base = dmap->dm_segs[seg].ds_addr; } + isp_prt(isp, ISP_LOGDEBUG2, "seg0.[%d]={0x%lx,%lu}", + rq->req_seg_count, (long) dmap->dm_segs[seg].ds_addr, + (unsigned long) dmap->dm_segs[seg].ds_len); } - if (seg == segcnt) + if (seg == segcnt) { goto dmasync; + } do { - crq = (ispcontreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, *iptrp); - *iptrp = ISP_NXT_QENTRY(*iptrp, RQUEST_QUEUE_LEN(isp)); - if (*iptrp == optr) { + u_int16_t onxti; + ispcontreq_t *crq, *cqe, local; + + crq = &local; + + cqe = (ispcontreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, nxti); + onxti = nxti; + nxti = ISP_NXT_QENTRY(onxti, RQUEST_QUEUE_LEN(isp)); + if (nxti == optr) { isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow++"); - bus_dmamap_unload(pci->pci_dmat, dmap); + bus_dmamap_unload(isp->isp_dmatag, dmap); XS_SETERR(xs, HBA_BOTCH); return (CMD_EAGAIN); } @@ -1055,18 +1098,34 @@ isp_pci_dmasetup(struct ispsoftc *isp, XS_T *xs, ispreq_t *rq, u_int16_t *iptrp, dmap->dm_segs[seg].ds_len; crq->req_dataseg[ovseg].ds_base = dmap->dm_segs[seg].ds_addr; + isp_prt(isp, ISP_LOGDEBUG2, "seg%d.[%d]={0x%lx,%lu}", + rq->req_header.rqs_entry_count - 1, + rq->req_seg_count, (long)dmap->dm_segs[seg].ds_addr, + (unsigned long) dmap->dm_segs[seg].ds_len); } + isp_put_cont_req(isp, crq, cqe); + MEMORYBARRIER(isp, SYNC_REQUEST, onxti, QENTRY_LEN); } while (seg < segcnt); dmasync: - bus_dmamap_sync(pci->pci_dmat, dmap, 0, dmap->dm_mapsize, - (xs->flags & SCSI_DATA_IN) ? - BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(isp->isp_dmatag, dmap, 0, dmap->dm_mapsize, + (xs->flags & SCSI_DATA_IN) ? BUS_DMASYNC_PREREAD : + BUS_DMASYNC_PREWRITE); mbxsync: - ISP_SWIZZLE_REQUEST(isp, rq); - bus_dmamap_sync(pci->pci_dmat, pci->pci_rquest_dmap, 0, - pci->pci_rquest_dmap->dm_mapsize, BUS_DMASYNC_PREWRITE); + switch (rq->req_header.rqs_entry_type) { + case RQSTYPE_REQUEST: + isp_put_request(isp, rq, qep); + break; + case RQSTYPE_CMDONLY: + isp_put_extended_request(isp, (ispextreq_t *)rq, + (ispextreq_t *)qep); + break; + case RQSTYPE_T2RQS: + isp_put_request_t2(isp, (ispreqt2_t *) rq, (ispreqt2_t *) qep); + break; + } + *nxtip = nxti; return (CMD_QUEUED); } @@ -1075,15 +1134,12 @@ isp_pci_intr(void *arg) { u_int16_t isr, sema, mbox; struct ispsoftc *isp = (struct ispsoftc *)arg; - struct isp_pcisoftc *p = (struct isp_pcisoftc *)isp; isp->isp_intcnt++; if (ISP_READ_ISR(isp, &isr, &sema, &mbox) == 0) { isp->isp_intbogus++; return (0); } else { - bus_dmamap_sync(p->pci_dmat, p->pci_result_dmap, 0, - p->pci_result_dmap->dm_mapsize, BUS_DMASYNC_POSTREAD); isp->isp_osinfo.onintstack = 1; isp_intr(isp, isr, sema, mbox); isp->isp_osinfo.onintstack = 0; @@ -1094,12 +1150,12 @@ isp_pci_intr(void *arg) static void isp_pci_dmateardown(struct ispsoftc *isp, XS_T *xs, u_int16_t handle) { - struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; - bus_dmamap_t dmap = pci->pci_xfer_dmap[isp_handle_index(handle)]; - bus_dmamap_sync(pci->pci_dmat, dmap, 0, dmap->dm_mapsize, - xs->flags & SCSI_DATA_IN ? + struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp; + bus_dmamap_t dmap = pcs->pci_xfer_dmap[isp_handle_index(handle)]; + bus_dmamap_sync(isp->isp_dmatag, dmap, 0, dmap->dm_mapsize, + (xs->flags & SCSI_DATA_IN)? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(pci->pci_dmat, dmap); + bus_dmamap_unload(isp->isp_dmatag, dmap); } static void @@ -1112,9 +1168,9 @@ isp_pci_reset1(struct ispsoftc *isp) static void isp_pci_dumpregs(struct ispsoftc *isp, const char *msg) { - struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; + struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp; if (msg) isp_prt(isp, ISP_LOGERR, "%s", msg); isp_prt(isp, ISP_LOGERR, "PCI Status Command/Status=%x\n", - pci_conf_read(pci->pci_pc, pci->pci_tag, PCI_COMMAND_STATUS_REG)); + pci_conf_read(pcs->pci_pc, pcs->pci_tag, PCI_COMMAND_STATUS_REG)); } |
