gemvar.h revision 1.1.4.3 1 1.1.4.3 fvdl /* $NetBSD: gemvar.h,v 1.1.4.3 2001/10/11 00:02:03 fvdl Exp $ */
2 1.1.4.2 fvdl
3 1.1.4.2 fvdl /*
4 1.1.4.2 fvdl *
5 1.1.4.2 fvdl * Copyright (C) 2001 Eduardo Horvath.
6 1.1.4.2 fvdl * All rights reserved.
7 1.1.4.2 fvdl *
8 1.1.4.2 fvdl *
9 1.1.4.2 fvdl * Redistribution and use in source and binary forms, with or without
10 1.1.4.2 fvdl * modification, are permitted provided that the following conditions
11 1.1.4.2 fvdl * are met:
12 1.1.4.2 fvdl * 1. Redistributions of source code must retain the above copyright
13 1.1.4.2 fvdl * notice, this list of conditions and the following disclaimer.
14 1.1.4.2 fvdl * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.4.2 fvdl * notice, this list of conditions and the following disclaimer in the
16 1.1.4.2 fvdl * documentation and/or other materials provided with the distribution.
17 1.1.4.2 fvdl *
18 1.1.4.2 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
19 1.1.4.2 fvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 1.1.4.2 fvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 1.1.4.2 fvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
22 1.1.4.2 fvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 1.1.4.2 fvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 1.1.4.2 fvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.1.4.2 fvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 1.1.4.2 fvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1.4.2 fvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1.4.2 fvdl * SUCH DAMAGE.
29 1.1.4.2 fvdl *
30 1.1.4.2 fvdl */
31 1.1.4.2 fvdl
32 1.1.4.2 fvdl #ifndef _IF_GEMVAR_H
33 1.1.4.2 fvdl #define _IF_GEMVAR_H
34 1.1.4.2 fvdl
35 1.1.4.2 fvdl
36 1.1.4.2 fvdl #include "rnd.h"
37 1.1.4.2 fvdl
38 1.1.4.2 fvdl #include <sys/queue.h>
39 1.1.4.2 fvdl #include <sys/callout.h>
40 1.1.4.2 fvdl
41 1.1.4.2 fvdl #if NRND > 0
42 1.1.4.2 fvdl #include <sys/rnd.h>
43 1.1.4.2 fvdl #endif
44 1.1.4.2 fvdl
45 1.1.4.2 fvdl /*
46 1.1.4.2 fvdl * Misc. definitions for the Sun ``Gem'' Ethernet controller family driver.
47 1.1.4.2 fvdl */
48 1.1.4.2 fvdl
49 1.1.4.2 fvdl /*
50 1.1.4.2 fvdl * Transmit descriptor list size. This is arbitrary, but allocate
51 1.1.4.2 fvdl * enough descriptors for 64 pending transmissions and 16 segments
52 1.1.4.2 fvdl * per packet.
53 1.1.4.2 fvdl */
54 1.1.4.2 fvdl #define GEM_NTXSEGS 16
55 1.1.4.2 fvdl
56 1.1.4.2 fvdl #define GEM_TXQUEUELEN 64
57 1.1.4.2 fvdl #define GEM_NTXDESC (GEM_TXQUEUELEN * GEM_NTXSEGS)
58 1.1.4.2 fvdl #define GEM_NTXDESC_MASK (GEM_NTXDESC - 1)
59 1.1.4.2 fvdl #define GEM_NEXTTX(x) ((x + 1) & GEM_NTXDESC_MASK)
60 1.1.4.2 fvdl
61 1.1.4.2 fvdl /*
62 1.1.4.2 fvdl * Receive descriptor list size. We have one Rx buffer per incoming
63 1.1.4.2 fvdl * packet, so this logic is a little simpler.
64 1.1.4.2 fvdl */
65 1.1.4.3 fvdl #define GEM_NRXDESC 128
66 1.1.4.2 fvdl #define GEM_NRXDESC_MASK (GEM_NRXDESC - 1)
67 1.1.4.2 fvdl #define GEM_NEXTRX(x) ((x + 1) & GEM_NRXDESC_MASK)
68 1.1.4.2 fvdl
69 1.1.4.2 fvdl /*
70 1.1.4.2 fvdl * Control structures are DMA'd to the GEM chip. We allocate them in
71 1.1.4.2 fvdl * a single clump that maps to a single DMA segment to make several things
72 1.1.4.2 fvdl * easier.
73 1.1.4.2 fvdl */
74 1.1.4.2 fvdl struct gem_control_data {
75 1.1.4.2 fvdl /*
76 1.1.4.2 fvdl * The transmit descriptors.
77 1.1.4.2 fvdl */
78 1.1.4.2 fvdl struct gem_desc gcd_txdescs[GEM_NTXDESC];
79 1.1.4.2 fvdl
80 1.1.4.2 fvdl /*
81 1.1.4.2 fvdl * The receive descriptors.
82 1.1.4.2 fvdl */
83 1.1.4.2 fvdl struct gem_desc gcd_rxdescs[GEM_NRXDESC];
84 1.1.4.2 fvdl };
85 1.1.4.2 fvdl
86 1.1.4.2 fvdl #define GEM_CDOFF(x) offsetof(struct gem_control_data, x)
87 1.1.4.2 fvdl #define GEM_CDTXOFF(x) GEM_CDOFF(gcd_txdescs[(x)])
88 1.1.4.2 fvdl #define GEM_CDRXOFF(x) GEM_CDOFF(gcd_rxdescs[(x)])
89 1.1.4.2 fvdl
90 1.1.4.2 fvdl /*
91 1.1.4.2 fvdl * Software state for transmit jobs.
92 1.1.4.2 fvdl */
93 1.1.4.2 fvdl struct gem_txsoft {
94 1.1.4.2 fvdl struct mbuf *txs_mbuf; /* head of our mbuf chain */
95 1.1.4.2 fvdl bus_dmamap_t txs_dmamap; /* our DMA map */
96 1.1.4.2 fvdl int txs_firstdesc; /* first descriptor in packet */
97 1.1.4.2 fvdl int txs_lastdesc; /* last descriptor in packet */
98 1.1.4.2 fvdl int txs_ndescs; /* number of descriptors */
99 1.1.4.2 fvdl SIMPLEQ_ENTRY(gem_txsoft) txs_q;
100 1.1.4.2 fvdl };
101 1.1.4.2 fvdl
102 1.1.4.2 fvdl SIMPLEQ_HEAD(gem_txsq, gem_txsoft);
103 1.1.4.2 fvdl
104 1.1.4.2 fvdl /*
105 1.1.4.2 fvdl * Software state for receive jobs.
106 1.1.4.2 fvdl */
107 1.1.4.2 fvdl struct gem_rxsoft {
108 1.1.4.2 fvdl struct mbuf *rxs_mbuf; /* head of our mbuf chain */
109 1.1.4.2 fvdl bus_dmamap_t rxs_dmamap; /* our DMA map */
110 1.1.4.2 fvdl };
111 1.1.4.2 fvdl
112 1.1.4.2 fvdl
113 1.1.4.2 fvdl /*
114 1.1.4.2 fvdl * Table which describes the transmit threshold mode. We generally
115 1.1.4.2 fvdl * start at index 0. Whenever we get a transmit underrun, we increment
116 1.1.4.2 fvdl * our index, falling back if we encounter the NULL terminator.
117 1.1.4.2 fvdl */
118 1.1.4.2 fvdl struct gem_txthresh_tab {
119 1.1.4.2 fvdl u_int32_t txth_opmode; /* OPMODE bits */
120 1.1.4.2 fvdl const char *txth_name; /* name of mode */
121 1.1.4.2 fvdl };
122 1.1.4.2 fvdl
123 1.1.4.2 fvdl /*
124 1.1.4.2 fvdl * Some misc. statics, useful for debugging.
125 1.1.4.2 fvdl */
126 1.1.4.2 fvdl struct gem_stats {
127 1.1.4.2 fvdl u_long ts_tx_uf; /* transmit underflow errors */
128 1.1.4.2 fvdl u_long ts_tx_to; /* transmit jabber timeouts */
129 1.1.4.2 fvdl u_long ts_tx_ec; /* excessve collision count */
130 1.1.4.2 fvdl u_long ts_tx_lc; /* late collision count */
131 1.1.4.2 fvdl };
132 1.1.4.2 fvdl
133 1.1.4.2 fvdl /*
134 1.1.4.2 fvdl * Software state per device.
135 1.1.4.2 fvdl */
136 1.1.4.2 fvdl struct gem_softc {
137 1.1.4.2 fvdl struct device sc_dev; /* generic device information */
138 1.1.4.2 fvdl struct ethercom sc_ethercom; /* ethernet common data */
139 1.1.4.2 fvdl struct mii_data sc_mii; /* MII media control */
140 1.1.4.2 fvdl #define sc_media sc_mii.mii_media/* shorthand */
141 1.1.4.2 fvdl struct callout sc_tick_ch; /* tick callout */
142 1.1.4.2 fvdl
143 1.1.4.2 fvdl /* The following bus handles are to be provided by the bus front-end */
144 1.1.4.2 fvdl bus_space_tag_t sc_bustag; /* bus tag */
145 1.1.4.2 fvdl bus_dma_tag_t sc_dmatag; /* bus dma tag */
146 1.1.4.2 fvdl bus_dmamap_t sc_dmamap; /* bus dma handle */
147 1.1.4.2 fvdl bus_space_handle_t sc_h; /* bus space handle for all regs */
148 1.1.4.2 fvdl #if 0
149 1.1.4.2 fvdl /* The following may be needed for SBus */
150 1.1.4.2 fvdl bus_space_handle_t sc_seb; /* HME Global registers */
151 1.1.4.2 fvdl bus_space_handle_t sc_erx; /* HME ERX registers */
152 1.1.4.2 fvdl bus_space_handle_t sc_etx; /* HME ETX registers */
153 1.1.4.2 fvdl bus_space_handle_t sc_mac; /* HME MAC registers */
154 1.1.4.2 fvdl bus_space_handle_t sc_mif; /* HME MIF registers */
155 1.1.4.2 fvdl #endif
156 1.1.4.2 fvdl int sc_burst; /* DVMA burst size in effect */
157 1.1.4.2 fvdl int sc_phys[2]; /* MII instance -> PHY map */
158 1.1.4.2 fvdl
159 1.1.4.2 fvdl int sc_mif_config; /* Selected MII reg setting */
160 1.1.4.2 fvdl
161 1.1.4.2 fvdl int sc_pci; /* XXXXX -- PCI buses are LE. */
162 1.1.4.2 fvdl
163 1.1.4.2 fvdl void *sc_sdhook; /* shutdown hook */
164 1.1.4.2 fvdl void *sc_powerhook; /* power management hook */
165 1.1.4.2 fvdl
166 1.1.4.2 fvdl struct gem_stats sc_stats; /* debugging stats */
167 1.1.4.2 fvdl
168 1.1.4.2 fvdl /*
169 1.1.4.2 fvdl * Ring buffer DMA stuff.
170 1.1.4.2 fvdl */
171 1.1.4.2 fvdl bus_dma_segment_t sc_cdseg; /* control data memory */
172 1.1.4.2 fvdl int sc_cdnseg; /* number of segments */
173 1.1.4.2 fvdl bus_dmamap_t sc_cddmamap; /* control data DMA map */
174 1.1.4.2 fvdl #define sc_cddma sc_cddmamap->dm_segs[0].ds_addr
175 1.1.4.2 fvdl
176 1.1.4.2 fvdl /*
177 1.1.4.2 fvdl * Software state for transmit and receive descriptors.
178 1.1.4.2 fvdl */
179 1.1.4.2 fvdl struct gem_txsoft sc_txsoft[GEM_TXQUEUELEN];
180 1.1.4.2 fvdl struct gem_rxsoft sc_rxsoft[GEM_NRXDESC];
181 1.1.4.2 fvdl
182 1.1.4.2 fvdl /*
183 1.1.4.2 fvdl * Control data structures.
184 1.1.4.2 fvdl */
185 1.1.4.2 fvdl struct gem_control_data *sc_control_data;
186 1.1.4.2 fvdl #define sc_txdescs sc_control_data->gcd_txdescs
187 1.1.4.2 fvdl #define sc_rxdescs sc_control_data->gcd_rxdescs
188 1.1.4.2 fvdl
189 1.1.4.2 fvdl int sc_txfree; /* number of free Tx descriptors */
190 1.1.4.2 fvdl int sc_txnext; /* next ready Tx descriptor */
191 1.1.4.2 fvdl
192 1.1.4.2 fvdl u_int32_t sc_tdctl_ch; /* conditional desc chaining */
193 1.1.4.2 fvdl u_int32_t sc_tdctl_er; /* conditional desc end-of-ring */
194 1.1.4.2 fvdl
195 1.1.4.2 fvdl u_int32_t sc_setup_fsls; /* FS|LS on setup descriptor */
196 1.1.4.2 fvdl
197 1.1.4.2 fvdl struct gem_txsq sc_txfreeq; /* free Tx descsofts */
198 1.1.4.2 fvdl struct gem_txsq sc_txdirtyq; /* dirty Tx descsofts */
199 1.1.4.2 fvdl
200 1.1.4.2 fvdl int sc_rxptr; /* next ready RX descriptor/descsoft */
201 1.1.4.2 fvdl
202 1.1.4.2 fvdl /* ========== */
203 1.1.4.2 fvdl int sc_inited;
204 1.1.4.2 fvdl int sc_debug;
205 1.1.4.2 fvdl void *sc_sh; /* shutdownhook cookie */
206 1.1.4.2 fvdl u_int8_t sc_enaddr[ETHER_ADDR_LEN]; /* MAC address */
207 1.1.4.2 fvdl
208 1.1.4.2 fvdl /* Special hardware hooks */
209 1.1.4.2 fvdl void (*sc_hwreset) __P((struct gem_softc *));
210 1.1.4.2 fvdl void (*sc_hwinit) __P((struct gem_softc *));
211 1.1.4.2 fvdl
212 1.1.4.2 fvdl #if NRND > 0
213 1.1.4.2 fvdl rndsource_element_t rnd_source;
214 1.1.4.2 fvdl #endif
215 1.1.4.2 fvdl };
216 1.1.4.2 fvdl
217 1.1.4.2 fvdl
218 1.1.4.3 fvdl #define GEM_DMA_READ(sc, v) (((sc)->sc_pci) ? le64toh(v) : be64toh(v))
219 1.1.4.3 fvdl #define GEM_DMA_WRITE(sc, v) (((sc)->sc_pci) ? htole64(v) : htobe64(v))
220 1.1.4.2 fvdl
221 1.1.4.2 fvdl /*
222 1.1.4.2 fvdl * This macro returns the current media entry for *non-MII* media.
223 1.1.4.2 fvdl */
224 1.1.4.2 fvdl #define GEM_CURRENT_MEDIA(sc) \
225 1.1.4.2 fvdl (IFM_SUBTYPE((sc)->sc_mii.mii_media.ifm_cur->ifm_media) != IFM_AUTO ? \
226 1.1.4.2 fvdl (sc)->sc_mii.mii_media.ifm_cur : (sc)->sc_nway_active)
227 1.1.4.2 fvdl
228 1.1.4.2 fvdl /*
229 1.1.4.2 fvdl * This macro determines if a change to media-related OPMODE bits requires
230 1.1.4.2 fvdl * a chip reset.
231 1.1.4.2 fvdl */
232 1.1.4.2 fvdl #define GEM_MEDIA_NEEDSRESET(sc, newbits) \
233 1.1.4.2 fvdl (((sc)->sc_opmode & OPMODE_MEDIA_BITS) != \
234 1.1.4.2 fvdl ((newbits) & OPMODE_MEDIA_BITS))
235 1.1.4.2 fvdl
236 1.1.4.2 fvdl #define GEM_CDTXADDR(sc, x) ((sc)->sc_cddma + GEM_CDTXOFF((x)))
237 1.1.4.2 fvdl #define GEM_CDRXADDR(sc, x) ((sc)->sc_cddma + GEM_CDRXOFF((x)))
238 1.1.4.2 fvdl
239 1.1.4.2 fvdl #define GEM_CDSPADDR(sc) ((sc)->sc_cddma + GEM_CDSPOFF)
240 1.1.4.2 fvdl
241 1.1.4.2 fvdl #define GEM_CDTXSYNC(sc, x, n, ops) \
242 1.1.4.2 fvdl do { \
243 1.1.4.2 fvdl int __x, __n; \
244 1.1.4.2 fvdl \
245 1.1.4.2 fvdl __x = (x); \
246 1.1.4.2 fvdl __n = (n); \
247 1.1.4.2 fvdl \
248 1.1.4.2 fvdl /* If it will wrap around, sync to the end of the ring. */ \
249 1.1.4.2 fvdl if ((__x + __n) > GEM_NTXDESC) { \
250 1.1.4.2 fvdl bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap, \
251 1.1.4.2 fvdl GEM_CDTXOFF(__x), sizeof(struct gem_desc) * \
252 1.1.4.2 fvdl (GEM_NTXDESC - __x), (ops)); \
253 1.1.4.2 fvdl __n -= (GEM_NTXDESC - __x); \
254 1.1.4.2 fvdl __x = 0; \
255 1.1.4.2 fvdl } \
256 1.1.4.2 fvdl \
257 1.1.4.2 fvdl /* Now sync whatever is left. */ \
258 1.1.4.2 fvdl bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap, \
259 1.1.4.2 fvdl GEM_CDTXOFF(__x), sizeof(struct gem_desc) * __n, (ops)); \
260 1.1.4.2 fvdl } while (0)
261 1.1.4.2 fvdl
262 1.1.4.2 fvdl #define GEM_CDRXSYNC(sc, x, ops) \
263 1.1.4.2 fvdl bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap, \
264 1.1.4.2 fvdl GEM_CDRXOFF((x)), sizeof(struct gem_desc), (ops))
265 1.1.4.2 fvdl
266 1.1.4.2 fvdl #define GEM_CDSPSYNC(sc, ops) \
267 1.1.4.2 fvdl bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap, \
268 1.1.4.2 fvdl GEM_CDSPOFF, GEM_SETUP_PACKET_LEN, (ops))
269 1.1.4.2 fvdl
270 1.1.4.2 fvdl #define GEM_INIT_RXDESC(sc, x) \
271 1.1.4.2 fvdl do { \
272 1.1.4.2 fvdl struct gem_rxsoft *__rxs = &sc->sc_rxsoft[(x)]; \
273 1.1.4.2 fvdl struct gem_desc *__rxd = &sc->sc_rxdescs[(x)]; \
274 1.1.4.2 fvdl struct mbuf *__m = __rxs->rxs_mbuf; \
275 1.1.4.2 fvdl \
276 1.1.4.2 fvdl __m->m_data = __m->m_ext.ext_buf; \
277 1.1.4.2 fvdl __rxd->gd_addr = \
278 1.1.4.3 fvdl GEM_DMA_WRITE((sc), __rxs->rxs_dmamap->dm_segs[0].ds_addr); \
279 1.1.4.2 fvdl __rxd->gd_flags = \
280 1.1.4.3 fvdl GEM_DMA_WRITE((sc), \
281 1.1.4.3 fvdl (((__m->m_ext.ext_size)<<GEM_RD_BUFSHIFT) \
282 1.1.4.3 fvdl & GEM_RD_BUFSIZE) | GEM_RD_OWN); \
283 1.1.4.2 fvdl GEM_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
284 1.1.4.2 fvdl } while (0)
285 1.1.4.2 fvdl
286 1.1.4.2 fvdl #ifdef _KERNEL
287 1.1.4.2 fvdl void gem_attach __P((struct gem_softc *, const u_int8_t *));
288 1.1.4.2 fvdl int gem_activate __P((struct device *, enum devact));
289 1.1.4.2 fvdl int gem_detach __P((struct gem_softc *));
290 1.1.4.2 fvdl int gem_intr __P((void *));
291 1.1.4.2 fvdl int gem_read_srom __P((struct gem_softc *));
292 1.1.4.2 fvdl int gem_srom_crcok __P((const u_int8_t *));
293 1.1.4.2 fvdl int gem_isv_srom __P((const u_int8_t *));
294 1.1.4.2 fvdl int gem_isv_srom_enaddr __P((struct gem_softc *, u_int8_t *));
295 1.1.4.2 fvdl int gem_parse_old_srom __P((struct gem_softc *, u_int8_t *));
296 1.1.4.2 fvdl
297 1.1.4.2 fvdl int gem_mediachange __P((struct ifnet *));
298 1.1.4.2 fvdl void gem_mediastatus __P((struct ifnet *, struct ifmediareq *));
299 1.1.4.2 fvdl
300 1.1.4.2 fvdl void gem_config __P((struct gem_softc *));
301 1.1.4.2 fvdl void gem_reset __P((struct gem_softc *));
302 1.1.4.2 fvdl int gem_intr __P((void *));
303 1.1.4.2 fvdl #endif /* _KERNEL */
304 1.1.4.2 fvdl
305 1.1.4.2 fvdl
306 1.1.4.2 fvdl #endif
307