summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2005-07-30 04:25:01 +0000
committerBrad Smith <brad@cvs.openbsd.org>2005-07-30 04:25:01 +0000
commita89d48f8be0e2f5604b44bef1a73e33668af9ebc (patch)
tree5201f9a4ab22bf477c68fd6ffa7eb3171054e741 /sys/dev
parent8c0dc0dbd242f56c81f7801e86c9b3b5e86b4e69 (diff)
sync nge/ti_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/if_nge.c59
-rw-r--r--sys/dev/pci/if_ti.c61
2 files changed, 80 insertions, 40 deletions
diff --git a/sys/dev/pci/if_nge.c b/sys/dev/pci/if_nge.c
index 1254de3a0dd..b5770cb05f5 100644
--- a/sys/dev/pci/if_nge.c
+++ b/sys/dev/pci/if_nge.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_nge.c,v 1.42 2005/07/25 00:49:44 brad Exp $ */
+/* $OpenBSD: if_nge.c,v 1.43 2005/07/30 04:25:00 brad Exp $ */
/*
* Copyright (c) 2001 Wind River Systems
* Copyright (c) 1997, 1998, 1999, 2000, 2001
@@ -1122,36 +1122,44 @@ nge_alloc_jumbo_mem(sc)
caddr_t ptr, kva;
bus_dma_segment_t seg;
bus_dmamap_t dmamap;
- int i, rseg;
+ int i, rseg, state, error;
struct nge_jpool_entry *entry;
+ state = error = 0;
+
if (bus_dmamem_alloc(sc->sc_dmatag, NGE_JMEM, PAGE_SIZE, 0,
&seg, 1, &rseg, BUS_DMA_NOWAIT)) {
printf("%s: can't alloc rx buffers\n", sc->sc_dv.dv_xname);
- return (ENOBUFS);
+ error = ENOBUFS;
+ goto out;
}
+
+ state = 1;
if (bus_dmamem_map(sc->sc_dmatag, &seg, rseg, NGE_JMEM, &kva,
BUS_DMA_NOWAIT)) {
printf("%s: can't map dma buffers (%d bytes)\n",
sc->sc_dv.dv_xname, NGE_JMEM);
- bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
- return (ENOBUFS);
+ error = ENOBUFS;
+ goto out;
}
+
+ state = 2;
if (bus_dmamap_create(sc->sc_dmatag, NGE_JMEM, 1,
NGE_JMEM, 0, BUS_DMA_NOWAIT, &dmamap)) {
printf("%s: can't create dma map\n", sc->sc_dv.dv_xname);
- bus_dmamem_unmap(sc->sc_dmatag, kva, NGE_JMEM);
- bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
- return (ENOBUFS);
+ error = ENOBUFS;
+ goto out;
}
+
+ state = 3;
if (bus_dmamap_load(sc->sc_dmatag, dmamap, kva, NGE_JMEM,
NULL, BUS_DMA_NOWAIT)) {
printf("%s: can't load dma map\n", sc->sc_dv.dv_xname);
- bus_dmamap_destroy(sc->sc_dmatag, dmamap);
- bus_dmamem_unmap(sc->sc_dmatag, kva, NGE_JMEM);
- bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
- return (ENOBUFS);
+ error = ENOBUFS;
+ goto out;
}
+
+ state = 4;
sc->nge_cdata.nge_jumbo_buf = (caddr_t)kva;
DPRINTFN(1,("%s: nge_jumbo_buf=%#x, NGE_MCLBYTES=%#x\n",
sc->sc_dv.dv_xname , sc->nge_cdata.nge_jumbo_buf,
@@ -1176,21 +1184,34 @@ nge_alloc_jumbo_mem(sc)
entry = malloc(sizeof(struct nge_jpool_entry),
M_DEVBUF, M_NOWAIT);
if (entry == NULL) {
- bus_dmamap_unload(sc->sc_dmatag, dmamap);
- bus_dmamap_destroy(sc->sc_dmatag, dmamap);
- bus_dmamem_unmap(sc->sc_dmatag, kva, NGE_JMEM);
- bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
sc->nge_cdata.nge_jumbo_buf = NULL;
printf("%s: no memory for jumbo buffer queue!\n",
sc->sc_dv.dv_xname);
- return(ENOBUFS);
+ error = ENOBUFS;
+ goto out;
}
entry->slot = i;
LIST_INSERT_HEAD(&sc->nge_jfree_listhead, entry,
jpool_entries);
}
-
- return(0);
+out:
+ if (error != 0) {
+ switch (state) {
+ case 4:
+ bus_dmamap_unload(sc->sc_dmatag, dmamap);
+ case 3:
+ bus_dmamap_destroy(sc->sc_dmatag, dmamap);
+ case 2:
+ bus_dmamem_unmap(sc->sc_dmatag, kva, NGE_JMEM);
+ case 1:
+ bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ return (error);
}
/*
diff --git a/sys/dev/pci/if_ti.c b/sys/dev/pci/if_ti.c
index 5a53de00b2a..3e364596fbd 100644
--- a/sys/dev/pci/if_ti.c
+++ b/sys/dev/pci/if_ti.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ti.c,v 1.70 2005/07/25 00:49:43 brad Exp $ */
+/* $OpenBSD: if_ti.c,v 1.71 2005/07/30 04:25:00 brad Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@@ -594,38 +594,44 @@ int ti_alloc_jumbo_mem(sc)
{
caddr_t ptr, kva;
bus_dma_segment_t seg;
- int i, rseg;
+ int i, rseg, state, error;
struct ti_jpool_entry *entry;
+ state = error = 0;
+
/* Grab a big chunk o' storage. */
if (bus_dmamem_alloc(sc->sc_dmatag, TI_JMEM, PAGE_SIZE, 0,
&seg, 1, &rseg, BUS_DMA_NOWAIT)) {
printf("%s: can't alloc rx buffers\n", sc->sc_dv.dv_xname);
return (ENOBUFS);
}
+
+ state = 1;
if (bus_dmamem_map(sc->sc_dmatag, &seg, rseg, TI_JMEM, &kva,
BUS_DMA_NOWAIT)) {
printf("%s: can't map dma buffers (%d bytes)\n",
sc->sc_dv.dv_xname, TI_JMEM);
- bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
- return (ENOBUFS);
+ error = ENOBUFS;
+ goto out;
}
+
+ state = 2;
if (bus_dmamap_create(sc->sc_dmatag, TI_JMEM, 1, TI_JMEM, 0,
BUS_DMA_NOWAIT, &sc->ti_cdata.ti_rx_jumbo_map)) {
printf("%s: can't create dma map\n", sc->sc_dv.dv_xname);
- bus_dmamem_unmap(sc->sc_dmatag, kva, TI_JMEM);
- bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
- return (ENOBUFS);
+ error = ENOBUFS;
+ goto out;
}
+
+ state = 3;
if (bus_dmamap_load(sc->sc_dmatag, sc->ti_cdata.ti_rx_jumbo_map, kva,
TI_JMEM, NULL, BUS_DMA_NOWAIT)) {
printf("%s: can't load dma map\n", sc->sc_dv.dv_xname);
- bus_dmamap_destroy(sc->sc_dmatag,
- sc->ti_cdata.ti_rx_jumbo_map);
- bus_dmamem_unmap(sc->sc_dmatag, kva, TI_JMEM);
- bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
- return (ENOBUFS);
+ error = ENOBUFS;
+ goto out;
}
+
+ state = 4;
sc->ti_cdata.ti_jumbo_buf = (caddr_t)kva;
SLIST_INIT(&sc->ti_jfree_listhead);
@@ -643,22 +649,35 @@ int ti_alloc_jumbo_mem(sc)
entry = malloc(sizeof(struct ti_jpool_entry),
M_DEVBUF, M_NOWAIT);
if (entry == NULL) {
- bus_dmamap_unload(sc->sc_dmatag,
- sc->ti_cdata.ti_rx_jumbo_map);
- bus_dmamap_destroy(sc->sc_dmatag,
- sc->ti_cdata.ti_rx_jumbo_map);
- bus_dmamem_unmap(sc->sc_dmatag, kva, TI_JMEM);
- bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
sc->ti_cdata.ti_jumbo_buf = NULL;
printf("%s: no memory for jumbo buffer queue\n",
sc->sc_dv.dv_xname);
- return(ENOBUFS);
+ error = ENOBUFS;
+ goto out;
}
entry->slot = i;
SLIST_INSERT_HEAD(&sc->ti_jfree_listhead, entry, jpool_entries);
}
-
- return(0);
+out:
+ if (error != 0) {
+ switch (state) {
+ case 4:
+ bus_dmamap_unload(sc->sc_dmatag,
+ sc->ti_cdata.ti_rx_jumbo_map);
+ case 3:
+ bus_dmamap_destroy(sc->sc_dmatag,
+ sc->ti_cdata.ti_rx_jumbo_map);
+ case 2:
+ bus_dmamem_unmap(sc->sc_dmatag, kva, TI_JMEM);
+ case 1:
+ bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ return (error);
}
/*