diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-12-01 02:15:22 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-12-01 02:15:22 +0000 |
commit | 4019d73011a8b3b779e2ed396a513ebead3636c2 (patch) | |
tree | 183179dce650a7aaaa046ce0d45972795e72dde1 /sys/dev | |
parent | 7777fa4686ac8837e210b415f1dadce7f056d724 (diff) |
bus_dma code clean up. No functional change. Polished form of diff
from marco@.
ok marco@
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/ic/mpt.c | 4 | ||||
-rw-r--r-- | sys/dev/ic/mpt.h | 4 | ||||
-rw-r--r-- | sys/dev/ic/mpt_openbsd.c | 130 | ||||
-rw-r--r-- | sys/dev/ic/mpt_openbsd.h | 3 |
4 files changed, 73 insertions, 68 deletions
diff --git a/sys/dev/ic/mpt.c b/sys/dev/ic/mpt.c index 747f49434f6..acb5415c10d 100644 --- a/sys/dev/ic/mpt.c +++ b/sys/dev/ic/mpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpt.c,v 1.17 2005/11/16 04:31:32 marco Exp $ */ +/* $OpenBSD: mpt.c,v 1.18 2005/12/01 02:15:21 krw Exp $ */ /* $NetBSD: mpt.c,v 1.4 2003/11/02 11:07:45 wiz Exp $ */ /* @@ -1785,7 +1785,7 @@ mpt_do_upload(mpt_softc_t *mpt) sizeof(SGE_MPI_UNION) - sizeof(FWUploadTCSGE_t)) / sizeof(SGE_SIMPLE32); - error = mpt_alloc_fw_mem(mpt, mpt->fw_image_size, maxsgl); + error = mpt_alloc_fw_mem(mpt, maxsgl); if (error) { mpt_prt(mpt,"mpt_alloc_fw_mem error: %d", error); return error; diff --git a/sys/dev/ic/mpt.h b/sys/dev/ic/mpt.h index 5a55d92caa7..df38e00b585 100644 --- a/sys/dev/ic/mpt.h +++ b/sys/dev/ic/mpt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mpt.h,v 1.5 2005/11/16 04:31:32 marco Exp $ */ +/* $OpenBSD: mpt.h,v 1.6 2005/12/01 02:15:21 krw Exp $ */ /* $NetBSD: mpt.h,v 1.2 2003/07/08 10:06:31 itojun Exp $ */ /* @@ -183,7 +183,7 @@ int mpt_read_cfg_header(mpt_softc_t *, int, int, int, CONFIG_PAGE_HEADER *); /* FW Download Boot */ int mpt_downloadboot(mpt_softc_t *); int mpt_do_upload(mpt_softc_t *); -int mpt_alloc_fw_mem(mpt_softc_t *, uint32_t , int); +int mpt_alloc_fw_mem(mpt_softc_t *, int); void mpt_free_fw_mem(mpt_softc_t *); /* mpt_debug.c functions */ diff --git a/sys/dev/ic/mpt_openbsd.c b/sys/dev/ic/mpt_openbsd.c index 4006b611432..6d67292c16a 100644 --- a/sys/dev/ic/mpt_openbsd.c +++ b/sys/dev/ic/mpt_openbsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpt_openbsd.c,v 1.29 2005/11/28 23:24:31 krw Exp $ */ +/* $OpenBSD: mpt_openbsd.c,v 1.30 2005/12/01 02:15:21 krw Exp $ */ /* $NetBSD: mpt_netbsd.c,v 1.7 2003/07/14 15:47:11 lukem Exp $ */ /* @@ -478,15 +478,24 @@ mpt_dma_mem_alloc(mpt_softc_t *mpt) return (ENOMEM); } bzero(mpt->request_pool, len); + /* * Allocate DMA resources for reply buffers. */ + error = bus_dmamap_create(mpt->sc_dmat, PAGE_SIZE, 1, PAGE_SIZE, + 0, 0, &mpt->reply_dmap); + if (error) { + printf("%s: unable to create reply DMA map, error = %d\n", + mpt->mpt_dev.dv_xname, error); + goto free_request_pool; + } + error = bus_dmamem_alloc(mpt->sc_dmat, PAGE_SIZE, PAGE_SIZE, 0, &reply_seg, 1, &reply_rseg, 0); if (error) { printf("%s: unable to allocate reply area, error = %d\n", mpt->mpt_dev.dv_xname, error); - goto fail_0; + goto destroy_reply; } error = bus_dmamem_map(mpt->sc_dmat, &reply_seg, reply_rseg, PAGE_SIZE, @@ -494,15 +503,7 @@ mpt_dma_mem_alloc(mpt_softc_t *mpt) if (error) { printf("%s: unable to map reply area, error = %d\n", mpt->mpt_dev.dv_xname, error); - goto fail_1; - } - - error = bus_dmamap_create(mpt->sc_dmat, PAGE_SIZE, 1, PAGE_SIZE, - 0, 0, &mpt->reply_dmap); - if (error) { - printf("%s: unable to create reply DMA map, error = %d\n", - mpt->mpt_dev.dv_xname, error); - goto fail_2; + goto free_reply; } error = bus_dmamap_load(mpt->sc_dmat, mpt->reply_dmap, mpt->reply, @@ -510,19 +511,26 @@ mpt_dma_mem_alloc(mpt_softc_t *mpt) if (error) { printf("%s: unable to load reply DMA map, error = %d\n", mpt->mpt_dev.dv_xname, error); - goto fail_3; + goto unmap_reply; } - mpt->reply_phys = mpt->reply_dmap->dm_segs[0].ds_addr; /* * Allocate DMA resources for request buffers. */ + error = bus_dmamap_create(mpt->sc_dmat, MPT_REQ_MEM_SIZE(mpt), 1, + MPT_REQ_MEM_SIZE(mpt), 0, 0, &mpt->request_dmap); + if (error) { + printf("%s: unable to create request DMA map, error = %d\n", + mpt->mpt_dev.dv_xname, error); + goto unload_reply; + } + error = bus_dmamem_alloc(mpt->sc_dmat, MPT_REQ_MEM_SIZE(mpt), PAGE_SIZE, 0, &request_seg, 1, &request_rseg, 0); if (error) { printf("%s: unable to allocate request area, error = %d\n", mpt->mpt_dev.dv_xname, error); - goto fail_4; + goto destroy_request; } error = bus_dmamem_map(mpt->sc_dmat, &request_seg, request_rseg, @@ -530,15 +538,7 @@ mpt_dma_mem_alloc(mpt_softc_t *mpt) if (error) { printf("%s: unable to map request area, error = %d\n", mpt->mpt_dev.dv_xname, error); - goto fail_5; - } - - error = bus_dmamap_create(mpt->sc_dmat, MPT_REQ_MEM_SIZE(mpt), 1, - MPT_REQ_MEM_SIZE(mpt), 0, 0, &mpt->request_dmap); - if (error) { - printf("%s: unable to create request DMA map, error = %d\n", - mpt->mpt_dev.dv_xname, error); - goto fail_6; + goto free_request; } error = bus_dmamap_load(mpt->sc_dmat, mpt->request_dmap, mpt->request, @@ -546,11 +546,10 @@ mpt_dma_mem_alloc(mpt_softc_t *mpt) if (error) { printf("%s: unable to load request DMA map, error = %d\n", mpt->mpt_dev.dv_xname, error); - goto fail_7; + goto unmap_request; } - mpt->request_phys = mpt->request_dmap->dm_segs[0].ds_addr; - pptr = mpt->request_phys; + pptr = mpt->request_dmap->dm_segs[0].ds_addr; vptr = (caddr_t) mpt->request; end = pptr + MPT_REQ_MEM_SIZE(mpt); @@ -573,34 +572,38 @@ mpt_dma_mem_alloc(mpt_softc_t *mpt) if (error) { printf("%s: unable to create req %d DMA map, error = ", "%d", mpt->mpt_dev.dv_xname, i, error); - goto fail_8; + goto unload_request; } } + mpt->request_phys = mpt->request_dmap->dm_segs[0].ds_addr; + mpt->reply_phys = mpt->reply_dmap->dm_segs[0].ds_addr; return (0); - fail_8: +unload_request: for (--i; i >= 0; i--) { request_t *req = &mpt->request_pool[i]; if (req->dmap != NULL) bus_dmamap_destroy(mpt->sc_dmat, req->dmap); } bus_dmamap_unload(mpt->sc_dmat, mpt->request_dmap); - fail_7: - bus_dmamap_destroy(mpt->sc_dmat, mpt->request_dmap); - fail_6: +unmap_request: bus_dmamem_unmap(mpt->sc_dmat, (caddr_t)mpt->request, PAGE_SIZE); - fail_5: - bus_dmamem_free(mpt->sc_dmat, &request_seg, request_rseg); - fail_4: +free_request: + bus_dmamem_free(mpt->sc_dmat, &request_seg, 1); +destroy_request: + bus_dmamap_destroy(mpt->sc_dmat, mpt->request_dmap); + +unload_reply: bus_dmamap_unload(mpt->sc_dmat, mpt->reply_dmap); - fail_3: - bus_dmamap_destroy(mpt->sc_dmat, mpt->reply_dmap); - fail_2: +unmap_reply: bus_dmamem_unmap(mpt->sc_dmat, (caddr_t)mpt->reply, PAGE_SIZE); - fail_1: - bus_dmamem_free(mpt->sc_dmat, &reply_seg, reply_rseg); - fail_0: +free_reply: + bus_dmamem_free(mpt->sc_dmat, &reply_seg, 1); +destroy_reply: + bus_dmamap_destroy(mpt->sc_dmat, mpt->reply_dmap); + +free_request_pool: free(mpt->request_pool, M_DEVBUF); mpt->reply = NULL; @@ -1513,49 +1516,52 @@ mpt_minphys(struct buf *bp) * maxsgl : maximum number of DMA segments */ int -mpt_alloc_fw_mem(mpt_softc_t *mpt, uint32_t img_sz, int maxsgl) +mpt_alloc_fw_mem(mpt_softc_t *mpt, int maxsgl) { - int error; + int error, rseg; - error = bus_dmamap_create(mpt->sc_dmat, img_sz, maxsgl, img_sz, - 0, 0, &mpt->fw_dmap); + error = bus_dmamap_create(mpt->sc_dmat, mpt->fw_image_size, maxsgl, + mpt->fw_image_size, 0, 0, &mpt->fw_dmap); if (error) { mpt_prt(mpt, "unable to create request DMA map, error = %d", error); - goto fw_fail0; + return (error); } - error = bus_dmamem_alloc(mpt->sc_dmat, img_sz, PAGE_SIZE, 0, - &mpt->fw_seg, 1, &mpt->fw_rseg, 0); + error = bus_dmamem_alloc(mpt->sc_dmat, mpt->fw_image_size, PAGE_SIZE, 0, + &mpt->fw_seg, 1, &rseg, 0); if (error) { mpt_prt(mpt, "unable to allocate fw memory, error = %d", error); - goto fw_fail1; + goto destroy; } - error = bus_dmamem_map(mpt->sc_dmat, &mpt->fw_seg, mpt->fw_rseg, img_sz, - (caddr_t *)&mpt->fw, BUS_DMA_COHERENT); + error = bus_dmamem_map(mpt->sc_dmat, &mpt->fw_seg, 1, + mpt->fw_image_size, (caddr_t *)&mpt->fw, BUS_DMA_COHERENT); if (error) { mpt_prt(mpt, "unable to map fw area, error = %d", error); - goto fw_fail2; + goto free; } - error = bus_dmamap_load(mpt->sc_dmat, mpt->fw_dmap, mpt->fw, img_sz, - NULL, 0); + error = bus_dmamap_load(mpt->sc_dmat, mpt->fw_dmap, mpt->fw, + mpt->fw_image_size, NULL, 0); if (error) { - mpt_prt(mpt, "unable to load request DMA map, error = %d", error); - goto fw_fail3; + mpt_prt(mpt, "unable to load request DMA map, error = %d", + error); + goto unmap; } return(error); -fw_fail3: - bus_dmamem_unmap(mpt->sc_dmat, (caddr_t)mpt->fw, img_sz); -fw_fail2: - bus_dmamem_free(mpt->sc_dmat, &mpt->fw_seg, mpt->fw_rseg); -fw_fail1: +unmap: + bus_dmamem_unmap(mpt->sc_dmat, (caddr_t)mpt->fw, mpt->fw_image_size); +free: + bus_dmamem_free(mpt->sc_dmat, &mpt->fw_seg, 1); +destroy: bus_dmamap_destroy(mpt->sc_dmat, mpt->fw_dmap); -fw_fail0: + mpt->fw = NULL; + bzero(&mpt->fw_seg, sizeof(mpt->fw_seg)); + return (error); } @@ -1564,6 +1570,6 @@ mpt_free_fw_mem(mpt_softc_t *mpt) { bus_dmamap_unload(mpt->sc_dmat, mpt->fw_dmap); bus_dmamem_unmap(mpt->sc_dmat, (caddr_t)mpt->fw, mpt->fw_image_size); - bus_dmamem_free(mpt->sc_dmat, &mpt->fw_seg, mpt->fw_rseg); + bus_dmamem_free(mpt->sc_dmat, &mpt->fw_seg, 1); bus_dmamap_destroy(mpt->sc_dmat, mpt->fw_dmap); } diff --git a/sys/dev/ic/mpt_openbsd.h b/sys/dev/ic/mpt_openbsd.h index 53c233da215..ef413aadb7d 100644 --- a/sys/dev/ic/mpt_openbsd.h +++ b/sys/dev/ic/mpt_openbsd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mpt_openbsd.h,v 1.17 2005/11/16 04:31:32 marco Exp $ */ +/* $OpenBSD: mpt_openbsd.h,v 1.18 2005/12/01 02:15:21 krw Exp $ */ /* $NetBSD: mpt_netbsd.h,v 1.2 2003/04/16 23:02:14 thorpej Exp $ */ /* @@ -321,7 +321,6 @@ typedef struct mpt_softc { uint8_t upload_fw; /* If set, do a fw upload */ /* Firmware memory */ bus_dmamap_t fw_dmap; - int fw_rseg; bus_dma_segment_t fw_seg; char *fw; |