summaryrefslogtreecommitdiff
path: root/sys/arch/macppc/dev
diff options
context:
space:
mode:
authorGordon Willem Klok <gwk@cvs.openbsd.org>2007-03-23 17:17:24 +0000
committerGordon Willem Klok <gwk@cvs.openbsd.org>2007-03-23 17:17:24 +0000
commitbc68e87d50e67a0d16927f88232ac3b56d4dd6d5 (patch)
treee4f95eef08335f4e3900aca1a5a586822a520666 /sys/arch/macppc/dev
parent4760f02e57586417cf6d7ec70e931d3fe5f5f104 (diff)
Clean up the failure path of the attach routine, check the return value of
dbdma_alloc, and mapiodev, and some whitespace/long line cleanup. Tested on 9500MP and 9600MP. ok martin@
Diffstat (limited to 'sys/arch/macppc/dev')
-rw-r--r--sys/arch/macppc/dev/if_mc.c99
1 files changed, 62 insertions, 37 deletions
diff --git a/sys/arch/macppc/dev/if_mc.c b/sys/arch/macppc/dev/if_mc.c
index 850579701db..762e01f1372 100644
--- a/sys/arch/macppc/dev/if_mc.c
+++ b/sys/arch/macppc/dev/if_mc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_mc.c,v 1.7 2007/01/03 06:57:54 gwk Exp $ */
+/* $OpenBSD: if_mc.c,v 1.8 2007/03/23 17:17:23 gwk Exp $ */
/* $NetBSD: if_mc.c,v 1.9.16.1 2006/06/21 14:53:13 yamt Exp $ */
/*-
@@ -363,8 +363,8 @@ mc_attach(struct device *parent, struct device *self, void *aux)
u_int8_t lladdr[ETHER_ADDR_LEN];
int nseg, error;
- if (OF_getprop(ca->ca_node, "local-mac-address", lladdr, ETHER_ADDR_LEN)
- != ETHER_ADDR_LEN) {
+ if (OF_getprop(ca->ca_node, "local-mac-address", lladdr,
+ ETHER_ADDR_LEN) != ETHER_ADDR_LEN) {
printf(": failed to get MAC address.\n");
return;
}
@@ -373,57 +373,64 @@ mc_attach(struct device *parent, struct device *self, void *aux)
ca->ca_reg[2] += ca->ca_baseaddr;
ca->ca_reg[4] += ca->ca_baseaddr;
- sc->sc_reg = mapiodev(ca->ca_reg[0], ca->ca_reg[1]);
- sc->sc_dmat = ca->ca_dmat;
- sc->sc_txdma = mapiodev(ca->ca_reg[2], ca->ca_reg[3]);
- sc->sc_rxdma = mapiodev(ca->ca_reg[4], ca->ca_reg[5]);
+ if ((sc->sc_reg = mapiodev(ca->ca_reg[0], ca->ca_reg[1])) == NULL) {
+ printf(": cannot map registers\n");
+ return;
+ }
- sc->sc_txdbdma = dbdma_alloc(sc->sc_dmat, 2);
+ sc->sc_dmat = ca->ca_dmat;
sc->sc_tail = 0;
+
+ if ((sc->sc_txdma = mapiodev(ca->ca_reg[2], ca->ca_reg[3])) == NULL) {
+ printf(": cannot map TX DMA registers\n");
+ goto notxdma;
+ }
+ if ((sc->sc_rxdma = mapiodev(ca->ca_reg[4], ca->ca_reg[5])) == NULL) {
+ printf(": cannot map RX DMA registers\n");
+ goto norxdma;
+ }
+ if ((sc->sc_txdbdma = dbdma_alloc(sc->sc_dmat, 2)) == NULL) {
+ printf(": cannot alloc TX DMA descriptors\n");
+ goto notxdbdma;
+ }
sc->sc_txdmacmd = sc->sc_txdbdma->d_addr;
- sc->sc_rxdbdma = dbdma_alloc(sc->sc_dmat, 8 + 1);
+
+ if ((sc->sc_rxdbdma = dbdma_alloc(sc->sc_dmat, 8 + 1)) == NULL) {
+ printf(": cannot alloc RX DMA descriptors\n");
+ goto norxdbdma;
+ }
sc->sc_rxdmacmd = sc->sc_rxdbdma->d_addr;
- error = bus_dmamem_alloc(sc->sc_dmat, MACE_BUFSZ,
- PAGE_SIZE, 0, sc->sc_bufseg, 1, &nseg, BUS_DMA_NOWAIT);
- if (error) {
- printf(": cannot allocate buffers (%d)\n", error);
- return;
+ if ((error = bus_dmamem_alloc(sc->sc_dmat, MACE_BUFSZ, PAGE_SIZE, 0,
+ sc->sc_bufseg, 1, &nseg, BUS_DMA_NOWAIT))) {
+ printf(": cannot allocate DMA mem (%d)\n", error);
+ goto nodmamem;
}
- error = bus_dmamem_map(sc->sc_dmat, sc->sc_bufseg, nseg,
- MACE_BUFSZ, &sc->sc_txbuf, BUS_DMA_NOWAIT);
- if (error) {
- printf(": cannot map buffers (%d)\n", error);
- bus_dmamem_free(sc->sc_dmat, sc->sc_bufseg, 1);
- return;
+ if ((error = bus_dmamem_map(sc->sc_dmat, sc->sc_bufseg, nseg,
+ MACE_BUFSZ, &sc->sc_txbuf, BUS_DMA_NOWAIT))) {
+ printf(": cannot map DMA mem (%d)\n", error);
+ goto nodmamap;
}
- error = bus_dmamap_create(sc->sc_dmat, MACE_BUFSZ, 1, MACE_BUFSZ, 0,
- BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &sc->sc_bufmap);
- if (error) {
- printf(": cannot create buffer dmamap (%d)\n", error);
- bus_dmamem_unmap(sc->sc_dmat, sc->sc_txbuf, MACE_BUFSZ);
- bus_dmamem_free(sc->sc_dmat, sc->sc_bufseg, 1);
- return;
+ if ((error = bus_dmamap_create(sc->sc_dmat, MACE_BUFSZ, 1, MACE_BUFSZ,
+ 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &sc->sc_bufmap))) {
+ printf(": cannot create DMA map (%d)\n", error);
+ goto nodmacreate;
}
- error = bus_dmamap_load(sc->sc_dmat, sc->sc_bufmap, sc->sc_txbuf,
- MACE_BUFSZ, NULL, BUS_DMA_NOWAIT);
- if (error) {
- printf(": cannot load buffers dmamap (%d)\n", error);
- bus_dmamap_destroy(sc->sc_dmat, sc->sc_bufmap);
- bus_dmamem_unmap(sc->sc_dmat, sc->sc_txbuf, MACE_BUFSZ);
- bus_dmamem_free(sc->sc_dmat, sc->sc_bufseg, nseg);
- return;
+ if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_bufmap, sc->sc_txbuf,
+ MACE_BUFSZ, NULL, BUS_DMA_NOWAIT))) {
+ printf(": cannot load DMA map (%d)\n", error);
+ goto nodmaload;
}
sc->sc_txbuf_pa = sc->sc_bufmap->dm_segs->ds_addr;
sc->sc_rxbuf = sc->sc_txbuf + MACE_BUFLEN * MACE_TXBUFS;
sc->sc_rxbuf_pa = sc->sc_txbuf_pa + MACE_BUFLEN * MACE_TXBUFS;
- printf(": irq %d,%d,%d",
- ca->ca_intr[0], ca->ca_intr[1], ca->ca_intr[2]);
+ printf(": irq %d,%d,%d", ca->ca_intr[0], ca->ca_intr[1],
+ ca->ca_intr[2]);
/* disable receive DMA */
dbdma_reset(sc->sc_rxdma);
@@ -464,6 +471,24 @@ mc_attach(struct device *parent, struct device *self, void *aux)
if_attach(ifp);
ether_ifattach(ifp);
+
+ return;
+nodmaload:
+ bus_dmamap_destroy(sc->sc_dmat, sc->sc_bufmap);
+nodmacreate:
+ bus_dmamem_unmap(sc->sc_dmat, sc->sc_txbuf, MACE_BUFSZ);
+nodmamap:
+ bus_dmamem_free(sc->sc_dmat, sc->sc_bufseg, 1);
+nodmamem:
+ dbdma_free(sc->sc_rxdbdma);
+norxdbdma:
+ dbdma_free(sc->sc_txdbdma);
+notxdbdma:
+ unmapiodev((void *)ca->ca_reg[4], ca->ca_reg[5]);
+norxdma:
+ unmapiodev((void *)ca->ca_reg[2], ca->ca_reg[3]);
+notxdma:
+ unmapiodev((void *)ca->ca_reg[0], ca->ca_reg[1]);
}
int