summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorthorpej <thorpej@NetBSD.org>2001-06-30 15:39:51 +0000
committerthorpej <thorpej@NetBSD.org>2001-06-30 15:39:51 +0000
commitd2a3ac835c55deeae879bbaa6d007abc3b986fb7 (patch)
tree29f152a0aa9acfca5ff6bf2f510086777f1f9bf2 /sys/dev
parent2e95360b2f22d205f6034175862f7d91c436c93b (diff)
Use macros (like those in every other network driver I have written)
to compute the offset of a structure in the DMA'd control data, and the DMA address of that structure.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/if_ti.c38
-rw-r--r--sys/dev/pci/if_tireg.h27
2 files changed, 39 insertions, 26 deletions
diff --git a/sys/dev/pci/if_ti.c b/sys/dev/pci/if_ti.c
index cc5407818e9..a8003266f6b 100644
--- a/sys/dev/pci/if_ti.c
+++ b/sys/dev/pci/if_ti.c
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ti.c,v 1.32 2001/06/30 14:56:59 thorpej Exp $ */
+/* $NetBSD: if_ti.c,v 1.33 2001/06/30 15:39:51 thorpej Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@@ -1445,8 +1445,7 @@ static int ti_gibinit(sc)
/* Tell the chip where to find the general information block. */
CSR_WRITE_4(sc, TI_GCR_GENINFO_HI, 0);
- CSR_WRITE_4(sc, TI_GCR_GENINFO_LO, sc->info_dmaaddr +
- ((caddr_t)&sc->ti_rdata->ti_info - (caddr_t)sc->ti_rdata));
+ CSR_WRITE_4(sc, TI_GCR_GENINFO_LO, TI_CDGIBADDR(sc));
/* Load the firmware into SRAM. */
ti_loadfw(sc);
@@ -1456,12 +1455,11 @@ static int ti_gibinit(sc)
/* Set up the event ring and producer pointer. */
rcb = &sc->ti_rdata->ti_info.ti_ev_rcb;
- TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
- ((caddr_t)&sc->ti_rdata->ti_event_ring - (caddr_t)sc->ti_rdata);
+ TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDEVENTADDR(sc, 0);
rcb->ti_flags = 0;
TI_HOSTADDR(sc->ti_rdata->ti_info.ti_ev_prodidx_ptr) =
- sc->info_dmaaddr + ((caddr_t)&sc->ti_rdata->ti_ev_prodidx_r
- - (caddr_t)sc->ti_rdata);
+ TI_CDEVPRODADDR(sc);
+
sc->ti_ev_prodidx.ti_idx = 0;
CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, 0);
sc->ti_ev_saved_considx = 0;
@@ -1485,14 +1483,11 @@ static int ti_gibinit(sc)
* conserve memory.
*/
TI_HOSTADDR(sc->ti_rdata->ti_info.ti_refresh_stats_ptr) =
- sc->info_dmaaddr + ((caddr_t)&sc->ti_rdata->ti_info.ti_stats
- - (caddr_t)sc->ti_rdata);
+ TI_CDSTATSADDR(sc);
/* Set up the standard receive ring. */
rcb = &sc->ti_rdata->ti_info.ti_std_rx_rcb;
- TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
- ((caddr_t)&sc->ti_rdata->ti_rx_std_ring
- - (caddr_t)sc->ti_rdata);
+ TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDRXSTDADDR(sc, 0);
rcb->ti_max_len = ETHER_MAX_LEN;
rcb->ti_flags = 0;
if (ifp->if_capenable & IFCAP_CSUM_IPv4)
@@ -1504,8 +1499,7 @@ static int ti_gibinit(sc)
/* Set up the jumbo receive ring. */
rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
- TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
- ((caddr_t)&sc->ti_rdata->ti_rx_jumbo_ring - (caddr_t)sc->ti_rdata);
+ TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDRXJUMBOADDR(sc, 0);
rcb->ti_max_len = ETHER_MAX_LEN_JUMBO;
rcb->ti_flags = 0;
if (ifp->if_capenable & IFCAP_CSUM_IPv4)
@@ -1521,8 +1515,7 @@ static int ti_gibinit(sc)
* still there on the Tigon 1.
*/
rcb = &sc->ti_rdata->ti_info.ti_mini_rx_rcb;
- TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
- ((caddr_t)&sc->ti_rdata->ti_rx_mini_ring - (caddr_t)sc->ti_rdata);
+ TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDRXMINIADDR(sc, 0);
rcb->ti_max_len = MHLEN - ETHER_ALIGN;
if (sc->ti_hwrev == TI_HWREV_TIGON)
rcb->ti_flags = TI_RCB_FLAG_RING_DISABLED;
@@ -1539,13 +1532,11 @@ static int ti_gibinit(sc)
* Set up the receive return ring.
*/
rcb = &sc->ti_rdata->ti_info.ti_return_rcb;
- TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
- ((caddr_t)&sc->ti_rdata->ti_rx_return_ring - (caddr_t)sc->ti_rdata);
+ TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDRXRTNADDR(sc, 0);
rcb->ti_flags = 0;
rcb->ti_max_len = TI_RETURN_RING_CNT;
TI_HOSTADDR(sc->ti_rdata->ti_info.ti_return_prodidx_ptr) =
- sc->info_dmaaddr + ((caddr_t)&sc->ti_rdata->ti_return_prodidx_r
- - (caddr_t)sc->ti_rdata);
+ TI_CDRTNPRODADDR(sc);
/*
* Set up the tx ring. Note: for the Tigon 2, we have the option
@@ -1584,12 +1575,9 @@ static int ti_gibinit(sc)
if (sc->ti_hwrev == TI_HWREV_TIGON)
TI_HOSTADDR(rcb->ti_hostaddr) = TI_TX_RING_BASE;
else
- TI_HOSTADDR(rcb->ti_hostaddr) = sc->info_dmaaddr +
- ((caddr_t)&sc->ti_rdata->ti_tx_ring
- - (caddr_t)sc->ti_rdata);
+ TI_HOSTADDR(rcb->ti_hostaddr) = TI_CDTXADDR(sc, 0);
TI_HOSTADDR(sc->ti_rdata->ti_info.ti_tx_considx_ptr) =
- sc->info_dmaaddr + ((caddr_t)&sc->ti_rdata->ti_tx_considx_r
- - (caddr_t)sc->ti_rdata);
+ TI_CDTXCONSADDR(sc);
/* Set up tuneables */
if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN) ||
diff --git a/sys/dev/pci/if_tireg.h b/sys/dev/pci/if_tireg.h
index f572642be7f..7ef0583f42b 100644
--- a/sys/dev/pci/if_tireg.h
+++ b/sys/dev/pci/if_tireg.h
@@ -1,4 +1,4 @@
-/* $NetBSD: if_tireg.h,v 1.8 2001/06/30 14:57:00 thorpej Exp $ */
+/* $NetBSD: if_tireg.h,v 1.9 2001/06/30 15:39:51 thorpej Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@@ -1023,6 +1023,19 @@ struct ti_ring_data {
struct ti_gib ti_info;
};
+#define TI_CDOFF(x) offsetof(struct ti_ring_data, x)
+#define TI_CDRXSTDOFF(x) TI_CDOFF(ti_rx_std_ring[(x)])
+#define TI_CDRXJUMBOOFF(x) TI_CDOFF(ti_rx_jumbo_ring[(x)])
+#define TI_CDRXMINIOFF(x) TI_CDOFF(ti_rx_mini_ring[(x)])
+#define TI_CDRXRTNOFF(x) TI_CDOFF(ti_rx_return_ring[(x)])
+#define TI_CDEVENTOFF(x) TI_CDOFF(ti_event_ring[(x)])
+#define TI_CDTXOFF(x) TI_CDOFF(ti_tx_ring[(x)])
+#define TI_CDEVPRODOFF TI_CDOFF(ti_ev_prodidx_r)
+#define TI_CDRTNPRODOFF TI_CDOFF(ti_return_prodidx_r)
+#define TI_CDTXCONSOFF TI_CDOFF(ti_tx_considx_r)
+#define TI_CDGIBOFF TI_CDOFF(ti_info)
+#define TI_CDSTATSOFF TI_CDOFF(ti_info.ti_stats)
+
/*
* Mbuf pointers. We need these to keep track of the virtual addresses
* of our mbuf chains since we can only convert from physical to virtual,
@@ -1123,6 +1136,18 @@ struct ti_softc {
struct txdmamap_pool_entry *txdma[TI_TX_RING_CNT];
};
+#define TI_CDRXSTDADDR(sc, x) ((sc)->info_dmaaddr + TI_CDRXSTDOFF((x)))
+#define TI_CDRXJUMBOADDR(sc, x) ((sc)->info_dmaaddr + TI_CDRXJUMBOOFF((x)))
+#define TI_CDRXMINIADDR(sc, x) ((sc)->info_dmaaddr + TI_CDRXMINIOFF((x)))
+#define TI_CDRXRTNADDR(sc, x) ((sc)->info_dmaaddr + TI_CDRXRTNOFF((x)))
+#define TI_CDEVENTADDR(sc, x) ((sc)->info_dmaaddr + TI_CDEVENTOFF((x)))
+#define TI_CDTXADDR(sc, x) ((sc)->info_dmaaddr + TI_CDTXOFF((x)))
+#define TI_CDEVPRODADDR(sc) ((sc)->info_dmaaddr + TI_CDEVPRODOFF)
+#define TI_CDRTNPRODADDR(sc) ((sc)->info_dmaaddr + TI_CDRTNPRODOFF)
+#define TI_CDTXCONSADDR(sc) ((sc)->info_dmaaddr + TI_CDTXCONSOFF)
+#define TI_CDGIBADDR(sc) ((sc)->info_dmaaddr + TI_CDGIBOFF)
+#define TI_CDSTATSADDR(sc) ((sc)->info_dmaaddr + TI_CDSTATSOFF)
+
/*
* Microchip Technology 24Cxx EEPROM control bytes
*/