aevar.h revision 1.2 1 /* $NetBSD: aevar.h,v 1.2 2006/09/04 05:17:26 gdamore Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #ifndef _MIPS_ATHEROS_DEV_AEVAR_H_
41 #define _MIPS_ATHEROS_DEV_AEVAR_H_
42
43 #include "rnd.h"
44
45 #include <sys/queue.h>
46 #include <sys/callout.h>
47
48 #if NRND > 0
49 #include <sys/rnd.h>
50 #endif
51
52 /*
53 * Misc. definitions for the Digital Semiconductor ``Tulip'' (21x4x)
54 * Ethernet controller family driver.
55 */
56
57 /*
58 * Transmit descriptor list size. This is arbitrary, but allocate
59 * enough descriptors for 64 pending transmissions and 16 segments
60 * per packet. Since a descriptor holds 2 buffer addresses, that's
61 * 8 descriptors per packet. This MUST work out to a power of 2.
62 */
63 #define AE_NTXSEGS 16
64
65 #define AE_TXQUEUELEN 64
66 #define AE_NTXDESC (AE_TXQUEUELEN * AE_NTXSEGS)
67 #define AE_NTXDESC_MASK (AE_NTXDESC - 1)
68 #define AE_NEXTTX(x) ((x + 1) & AE_NTXDESC_MASK)
69
70 /*
71 * Receive descriptor list size. We have one Rx buffer per incoming
72 * packet, so this logic is a little simpler.
73 */
74 #define AE_NRXDESC 64
75 #define AE_NRXDESC_MASK (AE_NRXDESC - 1)
76 #define AE_NEXTRX(x) ((x + 1) & AE_NRXDESC_MASK)
77
78 /*
79 * Control structures are DMA'd to the TULIP chip. We allocate them in
80 * a single clump that maps to a single DMA segment to make several things
81 * easier.
82 */
83 struct ae_control_data {
84 /*
85 * The transmit descriptors.
86 */
87 struct ae_desc acd_txdescs[AE_NTXDESC];
88
89 /*
90 * The receive descriptors.
91 */
92 struct ae_desc acd_rxdescs[AE_NRXDESC];
93 };
94
95 #define AE_CDOFF(x) offsetof(struct ae_control_data, x)
96 #define AE_CDTXOFF(x) AE_CDOFF(acd_txdescs[(x)])
97 #define AE_CDRXOFF(x) AE_CDOFF(acd_rxdescs[(x)])
98
99 /*
100 * Software state for transmit jobs.
101 */
102 struct ae_txsoft {
103 struct mbuf *txs_mbuf; /* head of our mbuf chain */
104 bus_dmamap_t txs_dmamap; /* our DMA map */
105 int txs_firstdesc; /* first descriptor in packet */
106 int txs_lastdesc; /* last descriptor in packet */
107 int txs_ndescs; /* number of descriptors */
108 SIMPLEQ_ENTRY(ae_txsoft) txs_q;
109 };
110
111 SIMPLEQ_HEAD(ae_txsq, ae_txsoft);
112
113 /*
114 * Software state for receive jobs.
115 */
116 struct ae_rxsoft {
117 struct mbuf *rxs_mbuf; /* head of our mbuf chain */
118 bus_dmamap_t rxs_dmamap; /* our DMA map */
119 };
120
121 struct ae_softc;
122
123 /*
124 * Some misc. statics, useful for debugging.
125 */
126 struct ae_stats {
127 u_long ts_tx_uf; /* transmit underflow errors */
128 u_long ts_tx_to; /* transmit jabber timeouts */
129 u_long ts_tx_ec; /* excessive collision count */
130 u_long ts_tx_lc; /* late collision count */
131 };
132
133 #ifndef _STANDALONE
134 /*
135 * Software state per device.
136 */
137 struct ae_softc {
138 struct device sc_dev; /* generic device information */
139 bus_space_tag_t sc_st; /* bus space tag */
140 bus_space_handle_t sc_sh; /* bus space handle */
141 bus_size_t sc_size; /* bus space size */
142 bus_dma_tag_t sc_dmat; /* bus DMA tag */
143 void *sc_ih; /* interrupt handle */
144 int sc_cirq; /* interrupt request line (cpu) */
145 int sc_mirq; /* interrupt request line (misc) */
146 struct ethercom sc_ethercom; /* ethernet common data */
147 void *sc_sdhook; /* shutdown hook */
148 void *sc_powerhook; /* power management hook */
149
150 struct ae_stats sc_stats; /* debugging stats */
151
152 int sc_flags; /* misc flags. */
153
154 struct mii_data sc_mii; /* MII/media information */
155
156 int sc_txthresh; /* current transmit threshold */
157
158 /* Media tick function. */
159 void (*sc_tick)(void *);
160 struct callout sc_tick_callout;
161
162 u_int32_t sc_inten; /* copy of CSR_INTEN */
163
164 u_int32_t sc_rxint_mask; /* mask of Rx interrupts we want */
165 u_int32_t sc_txint_mask; /* mask of Tx interrupts we want */
166
167 bus_dma_segment_t sc_cdseg; /* control data memory */
168 int sc_cdnseg; /* number of segments */
169 bus_dmamap_t sc_cddmamap; /* control data DMA map */
170 #define sc_cddma sc_cddmamap->dm_segs[0].ds_addr
171
172 /*
173 * Software state for transmit and receive descriptors.
174 */
175 struct ae_txsoft sc_txsoft[AE_TXQUEUELEN];
176 struct ae_rxsoft sc_rxsoft[AE_NRXDESC];
177
178 /*
179 * Control data structures.
180 */
181 struct ae_control_data *sc_control_data;
182 #define sc_txdescs sc_control_data->acd_txdescs
183 #define sc_rxdescs sc_control_data->acd_rxdescs
184 #define sc_setup_desc sc_control_data->acd_setup_desc
185
186 int sc_txfree; /* number of free Tx descriptors */
187 int sc_txnext; /* next ready Tx descriptor */
188
189 struct ae_txsq sc_txfreeq; /* free Tx descsofts */
190 struct ae_txsq sc_txdirtyq; /* dirty Tx descsofts */
191
192 short sc_if_flags;
193
194 int sc_rxptr; /* next ready RX descriptor/descsoft */
195
196 #if NRND > 0
197 rndsource_element_t sc_rnd_source; /* random source */
198 #endif
199 };
200 #endif
201
202 /* sc_flags */
203 #define AE_ATTACHED 0x00000800 /* attach has succeeded */
204 #define AE_ENABLED 0x00001000 /* chip is enabled */
205
206 #define AE_IS_ENABLED(sc) ((sc)->sc_flags & AE_ENABLED)
207
208 /*
209 * This macro returns the current media entry.
210 */
211 #define AE_CURRENT_MEDIA(sc) ((sc)->sc_mii.mii_media.ifm_cur)
212
213 /*
214 * This macro determines if a change to media-related OPMODE bits requires
215 * a chip reset.
216 */
217 #define TULIP_MEDIA_NEEDSRESET(sc, newbits) \
218 (((sc)->sc_opmode & OPMODE_MEDIA_BITS) != \
219 ((newbits) & OPMODE_MEDIA_BITS))
220
221 #define AE_CDTXADDR(sc, x) ((sc)->sc_cddma + AE_CDTXOFF((x)))
222 #define AE_CDRXADDR(sc, x) ((sc)->sc_cddma + AE_CDRXOFF((x)))
223
224 #define AE_CDTXSYNC(sc, x, n, ops) \
225 do { \
226 int __x, __n; \
227 \
228 __x = (x); \
229 __n = (n); \
230 \
231 /* If it will wrap around, sync to the end of the ring. */ \
232 if ((__x + __n) > AE_NTXDESC) { \
233 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
234 AE_CDTXOFF(__x), sizeof(struct ae_desc) * \
235 (AE_NTXDESC - __x), (ops)); \
236 __n -= (AE_NTXDESC - __x); \
237 __x = 0; \
238 } \
239 \
240 /* Now sync whatever is left. */ \
241 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
242 AE_CDTXOFF(__x), sizeof(struct ae_desc) * __n, (ops)); \
243 } while (0)
244
245 #define AE_CDRXSYNC(sc, x, ops) \
246 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
247 AE_CDRXOFF((x)), sizeof(struct ae_desc), (ops))
248
249 /*
250 * Note we rely on MCLBYTES being a power of two. Because the `length'
251 * field is only 11 bits, we must subtract 1 from the length to avoid
252 * having it truncated to 0!
253 */
254 #define AE_INIT_RXDESC(sc, x) \
255 do { \
256 struct ae_rxsoft *__rxs = &sc->sc_rxsoft[(x)]; \
257 struct ae_desc *__rxd = &sc->sc_rxdescs[(x)]; \
258 struct mbuf *__m = __rxs->rxs_mbuf; \
259 \
260 __m->m_data = __m->m_ext.ext_buf; \
261 __rxd->ad_bufaddr1 = \
262 (__rxs->rxs_dmamap->dm_segs[0].ds_addr); \
263 __rxd->ad_bufaddr2 = \
264 AE_CDRXADDR((sc), AE_NEXTRX((x))); \
265 __rxd->ad_ctl = \
266 ((((__m->m_ext.ext_size - 1) & ~0x3U) \
267 << ADCTL_SIZE1_SHIFT) | \
268 ((x) == (AE_NRXDESC - 1) ? ADCTL_ER : 0)); \
269 __rxd->ad_status = ADSTAT_OWN|ADSTAT_Rx_FS|ADSTAT_Rx_LS; \
270 AE_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
271 } while (0)
272
273 /* CSR access */
274
275 #define AE_READ(sc, reg) \
276 bus_space_read_4((sc)->sc_st, (sc)->sc_sh, (reg))
277
278 #define AE_WRITE(sc, reg, val) \
279 bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val))
280
281 #define AE_SET(sc, reg, mask) \
282 AE_WRITE((sc), (reg), AE_READ((sc), (reg)) | (mask))
283
284 #define AE_CLR(sc, reg, mask) \
285 AE_WRITE((sc), (reg), AE_READ((sc), (reg)) & ~(mask))
286
287 #define AE_ISSET(sc, reg, mask) \
288 (AE_READ((sc), (reg)) & (mask))
289
290 #define AE_BARRIER(sc) \
291 bus_space_barrier((sc)->sc_st, (sc)->sc_sh, 0, (sc)->sc_size, \
292 BUS_SPACE_BARRIER_WRITE)
293
294 #endif /* _MIPS_ATHEROS_DEV_AEVAR_H_ */
295