tulipvar.h revision 1.52 1 1.52 perry /* $NetBSD: tulipvar.h,v 1.52 2005/02/04 02:10:37 perry Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.24 thorpej * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 thorpej * NASA Ames Research Center.
10 1.1 thorpej *
11 1.1 thorpej * Redistribution and use in source and binary forms, with or without
12 1.1 thorpej * modification, are permitted provided that the following conditions
13 1.1 thorpej * are met:
14 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer.
16 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.1 thorpej * documentation and/or other materials provided with the distribution.
19 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
20 1.1 thorpej * must display the following acknowledgement:
21 1.1 thorpej * This product includes software developed by the NetBSD
22 1.1 thorpej * Foundation, Inc. and its contributors.
23 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 thorpej * contributors may be used to endorse or promote products derived
25 1.1 thorpej * from this software without specific prior written permission.
26 1.1 thorpej *
27 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
38 1.1 thorpej */
39 1.1 thorpej
40 1.1 thorpej #ifndef _DEV_IC_TULIPVAR_H_
41 1.15 enami #define _DEV_IC_TULIPVAR_H_
42 1.1 thorpej
43 1.40 enami #include "rnd.h"
44 1.40 enami
45 1.1 thorpej #include <sys/queue.h>
46 1.32 thorpej #include <sys/callout.h>
47 1.40 enami
48 1.40 enami #if NRND > 0
49 1.40 enami #include <sys/rnd.h>
50 1.40 enami #endif
51 1.1 thorpej
52 1.1 thorpej /*
53 1.1 thorpej * Misc. definitions for the Digital Semiconductor ``Tulip'' (21x4x)
54 1.1 thorpej * Ethernet controller family driver.
55 1.1 thorpej */
56 1.1 thorpej
57 1.1 thorpej /*
58 1.1 thorpej * Transmit descriptor list size. This is arbitrary, but allocate
59 1.1 thorpej * enough descriptors for 64 pending transmissions and 16 segments
60 1.1 thorpej * per packet. Since a descriptor holds 2 buffer addresses, that's
61 1.1 thorpej * 8 descriptors per packet. This MUST work out to a power of 2.
62 1.1 thorpej */
63 1.1 thorpej #define TULIP_NTXSEGS 16
64 1.1 thorpej
65 1.1 thorpej #define TULIP_TXQUEUELEN 64
66 1.1 thorpej #define TULIP_NTXDESC (TULIP_TXQUEUELEN * TULIP_NTXSEGS)
67 1.1 thorpej #define TULIP_NTXDESC_MASK (TULIP_NTXDESC - 1)
68 1.1 thorpej #define TULIP_NEXTTX(x) ((x + 1) & TULIP_NTXDESC_MASK)
69 1.1 thorpej
70 1.1 thorpej /*
71 1.1 thorpej * Receive descriptor list size. We have one Rx buffer per incoming
72 1.1 thorpej * packet, so this logic is a little simpler.
73 1.1 thorpej */
74 1.1 thorpej #define TULIP_NRXDESC 64
75 1.1 thorpej #define TULIP_NRXDESC_MASK (TULIP_NRXDESC - 1)
76 1.1 thorpej #define TULIP_NEXTRX(x) ((x + 1) & TULIP_NRXDESC_MASK)
77 1.1 thorpej
78 1.1 thorpej /*
79 1.1 thorpej * Control structures are DMA'd to the TULIP chip. We allocate them in
80 1.1 thorpej * a single clump that maps to a single DMA segment to make several things
81 1.1 thorpej * easier.
82 1.1 thorpej */
83 1.1 thorpej struct tulip_control_data {
84 1.1 thorpej /*
85 1.1 thorpej * The transmit descriptors.
86 1.1 thorpej */
87 1.1 thorpej struct tulip_desc tcd_txdescs[TULIP_NTXDESC];
88 1.1 thorpej
89 1.1 thorpej /*
90 1.1 thorpej * The receive descriptors.
91 1.1 thorpej */
92 1.1 thorpej struct tulip_desc tcd_rxdescs[TULIP_NRXDESC];
93 1.1 thorpej
94 1.1 thorpej /*
95 1.1 thorpej * The setup packet.
96 1.1 thorpej */
97 1.1 thorpej u_int32_t tcd_setup_packet[TULIP_SETUP_PACKET_LEN / sizeof(u_int32_t)];
98 1.1 thorpej };
99 1.1 thorpej
100 1.1 thorpej #define TULIP_CDOFF(x) offsetof(struct tulip_control_data, x)
101 1.1 thorpej #define TULIP_CDTXOFF(x) TULIP_CDOFF(tcd_txdescs[(x)])
102 1.1 thorpej #define TULIP_CDRXOFF(x) TULIP_CDOFF(tcd_rxdescs[(x)])
103 1.1 thorpej #define TULIP_CDSPOFF TULIP_CDOFF(tcd_setup_packet)
104 1.1 thorpej
105 1.1 thorpej /*
106 1.1 thorpej * Software state for transmit jobs.
107 1.1 thorpej */
108 1.1 thorpej struct tulip_txsoft {
109 1.1 thorpej struct mbuf *txs_mbuf; /* head of our mbuf chain */
110 1.1 thorpej bus_dmamap_t txs_dmamap; /* our DMA map */
111 1.1 thorpej int txs_firstdesc; /* first descriptor in packet */
112 1.1 thorpej int txs_lastdesc; /* last descriptor in packet */
113 1.26 thorpej int txs_ndescs; /* number of descriptors */
114 1.1 thorpej SIMPLEQ_ENTRY(tulip_txsoft) txs_q;
115 1.1 thorpej };
116 1.1 thorpej
117 1.1 thorpej SIMPLEQ_HEAD(tulip_txsq, tulip_txsoft);
118 1.1 thorpej
119 1.1 thorpej /*
120 1.1 thorpej * Software state for receive jobs.
121 1.1 thorpej */
122 1.1 thorpej struct tulip_rxsoft {
123 1.1 thorpej struct mbuf *rxs_mbuf; /* head of our mbuf chain */
124 1.1 thorpej bus_dmamap_t rxs_dmamap; /* our DMA map */
125 1.1 thorpej };
126 1.1 thorpej
127 1.1 thorpej /*
128 1.1 thorpej * Type of Tulip chip we're dealing with.
129 1.1 thorpej */
130 1.1 thorpej typedef enum {
131 1.1 thorpej TULIP_CHIP_INVALID = 0, /* invalid chip type */
132 1.1 thorpej TULIP_CHIP_DE425 = 1, /* DE-425 EISA */
133 1.1 thorpej TULIP_CHIP_21040 = 2, /* DECchip 21040 */
134 1.1 thorpej TULIP_CHIP_21041 = 3, /* DECchip 21041 */
135 1.1 thorpej TULIP_CHIP_21140 = 4, /* DECchip 21140 */
136 1.1 thorpej TULIP_CHIP_21140A = 5, /* DECchip 21140A */
137 1.1 thorpej TULIP_CHIP_21142 = 6, /* DECchip 21142 */
138 1.1 thorpej TULIP_CHIP_21143 = 7, /* DECchip 21143 */
139 1.1 thorpej TULIP_CHIP_82C168 = 8, /* Lite-On 82C168 PNIC */
140 1.1 thorpej TULIP_CHIP_82C169 = 9, /* Lite-On 82C169 PNIC */
141 1.5 thorpej TULIP_CHIP_82C115 = 10, /* Lite-On 82C115 PNIC II */
142 1.5 thorpej TULIP_CHIP_MX98713 = 11, /* Macronix 98713 PMAC */
143 1.5 thorpej TULIP_CHIP_MX98713A = 12, /* Macronix 98713A PMAC */
144 1.18 thorpej TULIP_CHIP_MX98715 = 13, /* Macronix 98715 PMAC */
145 1.18 thorpej TULIP_CHIP_MX98715A = 14, /* Macronix 98715A PMAC */
146 1.37 castor TULIP_CHIP_MX98715AEC_X = 15, /* Macronix 98715AEC-C, -E PMAC */
147 1.37 castor TULIP_CHIP_MX98725 = 16, /* Macronix 98725 PMAC */
148 1.37 castor TULIP_CHIP_WB89C840F = 17, /* Winbond 89C840F */
149 1.37 castor TULIP_CHIP_DM9102 = 18, /* Davicom DM9102 */
150 1.37 castor TULIP_CHIP_DM9102A = 19, /* Davicom DM9102A */
151 1.37 castor TULIP_CHIP_AL981 = 20, /* ADMtek AL981 */
152 1.38 thorpej TULIP_CHIP_AN983 = 21, /* ADMtek AN983 */
153 1.38 thorpej TULIP_CHIP_AN985 = 22, /* ADMtek AN985 */
154 1.38 thorpej TULIP_CHIP_AX88140 = 23, /* ASIX AX88140 */
155 1.38 thorpej TULIP_CHIP_AX88141 = 24, /* ASIX AX88141 */
156 1.45 lukem TULIP_CHIP_X3201_3 = 25 /* Xircom X3201-3 */
157 1.1 thorpej } tulip_chip_t;
158 1.1 thorpej
159 1.1 thorpej #define TULIP_CHIP_NAMES \
160 1.1 thorpej { \
161 1.1 thorpej NULL, \
162 1.1 thorpej "DE-425", \
163 1.1 thorpej "DECchip 21040", \
164 1.1 thorpej "DECchip 21041", \
165 1.1 thorpej "DECchip 21140", \
166 1.1 thorpej "DECchip 21140A", \
167 1.1 thorpej "DECchip 21142", \
168 1.1 thorpej "DECchip 21143", \
169 1.1 thorpej "Lite-On 82C168", \
170 1.1 thorpej "Lite-On 82C169", \
171 1.5 thorpej "Lite-On 82C115", \
172 1.1 thorpej "Macronix MX98713", \
173 1.1 thorpej "Macronix MX98713A", \
174 1.1 thorpej "Macronix MX98715", \
175 1.18 thorpej "Macronix MX98715A", \
176 1.37 castor "Macronix MX98715AEC-x", \
177 1.1 thorpej "Macronix MX98725", \
178 1.1 thorpej "Winbond 89C840F", \
179 1.5 thorpej "Davicom DM9102", \
180 1.36 thorpej "Davicom DM9102A", \
181 1.5 thorpej "ADMtek AL981", \
182 1.38 thorpej "ADMtek AN983", \
183 1.38 thorpej "ADMtek AN985", \
184 1.5 thorpej "ASIX AX88140", \
185 1.5 thorpej "ASIX AX88141", \
186 1.24 thorpej "Xircom X3201-3", \
187 1.1 thorpej }
188 1.1 thorpej
189 1.1 thorpej struct tulip_softc;
190 1.1 thorpej
191 1.1 thorpej /*
192 1.1 thorpej * Media init, change, status function pointers.
193 1.1 thorpej */
194 1.1 thorpej struct tulip_mediasw {
195 1.52 perry void (*tmsw_init)(struct tulip_softc *);
196 1.52 perry void (*tmsw_get)(struct tulip_softc *, struct ifmediareq *);
197 1.52 perry int (*tmsw_set)(struct tulip_softc *);
198 1.1 thorpej };
199 1.1 thorpej
200 1.1 thorpej /*
201 1.33 thorpej * Table which describes the transmit threshold mode. We generally
202 1.33 thorpej * start at index 0. Whenever we get a transmit underrun, we increment
203 1.33 thorpej * our index, falling back if we encounter the NULL terminator.
204 1.1 thorpej */
205 1.1 thorpej struct tulip_txthresh_tab {
206 1.1 thorpej u_int32_t txth_opmode; /* OPMODE bits */
207 1.1 thorpej const char *txth_name; /* name of mode */
208 1.1 thorpej };
209 1.1 thorpej
210 1.33 thorpej #define TLP_TXTHRESH_TAB_10 { \
211 1.33 thorpej { OPMODE_TR_72, "72 bytes" }, \
212 1.33 thorpej { OPMODE_TR_96, "96 bytes" }, \
213 1.33 thorpej { OPMODE_TR_128, "128 bytes" }, \
214 1.33 thorpej { OPMODE_TR_160, "160 bytes" }, \
215 1.33 thorpej { 0, NULL }, \
216 1.33 thorpej }
217 1.33 thorpej
218 1.33 thorpej #define TLP_TXTHRESH_TAB_10_100 { \
219 1.33 thorpej { OPMODE_TR_72, "72/128 bytes" }, \
220 1.33 thorpej { OPMODE_TR_96, "96/256 bytes" }, \
221 1.33 thorpej { OPMODE_TR_128, "128/512 bytes" }, \
222 1.33 thorpej { OPMODE_TR_160, "160/1024 bytes" }, \
223 1.33 thorpej { OPMODE_SF, "store and forward mode" }, \
224 1.33 thorpej { 0, NULL }, \
225 1.33 thorpej }
226 1.33 thorpej
227 1.33 thorpej #define TXTH_72 0
228 1.33 thorpej #define TXTH_96 1
229 1.33 thorpej #define TXTH_128 2
230 1.33 thorpej #define TXTH_160 3
231 1.33 thorpej #define TXTH_SF 4
232 1.33 thorpej
233 1.36 thorpej #define TLP_TXTHRESH_TAB_DM9102 { \
234 1.36 thorpej { OPMODE_TR_72, "72/128 bytes" }, \
235 1.36 thorpej { OPMODE_TR_96, "96/256 bytes" }, \
236 1.36 thorpej { OPMODE_TR_128, "128/512 bytes" }, \
237 1.36 thorpej { OPMODE_SF, "store and forward mode" }, \
238 1.36 thorpej { 0, NULL }, \
239 1.36 thorpej }
240 1.36 thorpej
241 1.36 thorpej #define TXTH_DM9102_72 0
242 1.36 thorpej #define TXTH_DM9102_96 1
243 1.36 thorpej #define TXTH_DM9102_128 2
244 1.36 thorpej #define TXTH_DM9102_SF 3
245 1.36 thorpej
246 1.33 thorpej /*
247 1.33 thorpej * The Winbond 89C840F does transmit threshold control totally
248 1.33 thorpej * differently. It simply has a 7-bit field which indicates
249 1.33 thorpej * the threshold:
250 1.33 thorpej *
251 1.33 thorpej * txth = ((OPMODE & OPMODE_WINB_TTH) >> OPMODE_WINB_TTH_SHIFT) * 16;
252 1.33 thorpej *
253 1.33 thorpej * However, we just do Store-and-Forward mode on these chips, since
254 1.33 thorpej * the DMA engines seem to be flaky.
255 1.33 thorpej */
256 1.33 thorpej #define TLP_TXTHRESH_TAB_WINB { \
257 1.33 thorpej { 0, "store and forward mode" }, \
258 1.33 thorpej { 0, NULL }, \
259 1.33 thorpej }
260 1.33 thorpej
261 1.33 thorpej #define TXTH_WINB_SF 0
262 1.33 thorpej
263 1.1 thorpej /*
264 1.19 thorpej * Settings for Tulip SIA media.
265 1.7 thorpej */
266 1.19 thorpej struct tulip_sia_media {
267 1.7 thorpej u_int32_t tsm_siaconn; /* CSR13 value */
268 1.7 thorpej u_int32_t tsm_siatxrx; /* CSR14 value */
269 1.7 thorpej u_int32_t tsm_siagen; /* CSR15 value */
270 1.7 thorpej };
271 1.7 thorpej
272 1.7 thorpej /*
273 1.19 thorpej * Description of 2x14x media.
274 1.12 thorpej */
275 1.19 thorpej struct tulip_21x4x_media {
276 1.12 thorpej int tm_type; /* type of media; see tulipreg.h */
277 1.14 thorpej const char *tm_name; /* name of media */
278 1.12 thorpej
279 1.52 perry void (*tm_get)(struct tulip_softc *, struct ifmediareq *);
280 1.52 perry int (*tm_set)(struct tulip_softc *);
281 1.12 thorpej
282 1.12 thorpej int tm_phyno; /* PHY # on MII */
283 1.12 thorpej
284 1.12 thorpej int tm_gp_length; /* MII select sequence length */
285 1.12 thorpej int tm_gp_offset; /* MII select sequence offset */
286 1.12 thorpej
287 1.12 thorpej int tm_reset_length;/* MII reset sequence length */
288 1.12 thorpej int tm_reset_offset;/* MII reset sequence offset */
289 1.12 thorpej
290 1.12 thorpej u_int32_t tm_opmode; /* OPMODE bits for this media */
291 1.19 thorpej u_int32_t tm_gpctl; /* GPIO control bits for this media */
292 1.14 thorpej u_int32_t tm_gpdata; /* GPIO bits for this media */
293 1.14 thorpej u_int32_t tm_actmask; /* `active' bits for this data */
294 1.14 thorpej u_int32_t tm_actdata; /* active high/low info */
295 1.19 thorpej
296 1.19 thorpej struct tulip_sia_media tm_sia; /* SIA settings */
297 1.19 thorpej #define tm_siaconn tm_sia.tsm_siaconn
298 1.19 thorpej #define tm_siatxrx tm_sia.tsm_siatxrx
299 1.19 thorpej #define tm_siagen tm_sia.tsm_siagen
300 1.14 thorpej };
301 1.14 thorpej
302 1.14 thorpej /*
303 1.14 thorpej * Table for converting Tulip SROM media info into ifmedia data.
304 1.14 thorpej */
305 1.14 thorpej struct tulip_srom_to_ifmedia {
306 1.14 thorpej u_int8_t tsti_srom; /* SROM media type */
307 1.14 thorpej int tsti_subtype; /* ifmedia subtype */
308 1.14 thorpej int tsti_options; /* ifmedia options */
309 1.14 thorpej const char *tsti_name; /* media name */
310 1.14 thorpej
311 1.19 thorpej u_int32_t tsti_opmode; /* OPMODE bits for this media */
312 1.48 thorpej u_int32_t tsti_sia_cap; /* "MII" capabilities for this media */
313 1.19 thorpej
314 1.14 thorpej /*
315 1.19 thorpej * Settings for 21040, 21041, and 21142/21143 SIA, in the event
316 1.14 thorpej * the SROM doesn't have them.
317 1.14 thorpej */
318 1.19 thorpej struct tulip_sia_media tsti_21040;
319 1.19 thorpej struct tulip_sia_media tsti_21041;
320 1.19 thorpej struct tulip_sia_media tsti_21142;
321 1.12 thorpej };
322 1.12 thorpej
323 1.12 thorpej /*
324 1.17 thorpej * Some misc. statics, useful for debugging.
325 1.17 thorpej */
326 1.17 thorpej struct tulip_stats {
327 1.17 thorpej u_long ts_tx_uf; /* transmit underflow errors */
328 1.17 thorpej u_long ts_tx_to; /* transmit jabber timeouts */
329 1.49 wiz u_long ts_tx_ec; /* excessive collision count */
330 1.17 thorpej u_long ts_tx_lc; /* late collision count */
331 1.17 thorpej };
332 1.17 thorpej
333 1.37 castor #ifndef _STANDALONE
334 1.17 thorpej /*
335 1.1 thorpej * Software state per device.
336 1.1 thorpej */
337 1.1 thorpej struct tulip_softc {
338 1.1 thorpej struct device sc_dev; /* generic device information */
339 1.1 thorpej bus_space_tag_t sc_st; /* bus space tag */
340 1.1 thorpej bus_space_handle_t sc_sh; /* bus space handle */
341 1.1 thorpej bus_dma_tag_t sc_dmat; /* bus DMA tag */
342 1.1 thorpej struct ethercom sc_ethercom; /* ethernet common data */
343 1.1 thorpej void *sc_sdhook; /* shutdown hook */
344 1.31 thorpej void *sc_powerhook; /* power management hook */
345 1.17 thorpej
346 1.17 thorpej struct tulip_stats sc_stats; /* debugging stats */
347 1.1 thorpej
348 1.1 thorpej /*
349 1.7 thorpej * Contents of the SROM.
350 1.7 thorpej */
351 1.29 mycroft u_int8_t *sc_srom;
352 1.21 thorpej int sc_srom_addrbits;
353 1.7 thorpej
354 1.7 thorpej /*
355 1.1 thorpej * Media access functions for this chip.
356 1.1 thorpej */
357 1.1 thorpej const struct tulip_mediasw *sc_mediasw;
358 1.21 thorpej mii_bitbang_ops_t sc_bitbang_ops;
359 1.1 thorpej
360 1.6 thorpej /*
361 1.6 thorpej * For chips with built-in NWay blocks, these are state
362 1.6 thorpej * variables required for autonegotiation.
363 1.6 thorpej */
364 1.6 thorpej int sc_nway_ticks; /* tick counter */
365 1.19 thorpej struct ifmedia_entry *sc_nway_active; /* the active media */
366 1.32 thorpej struct callout sc_nway_callout;
367 1.6 thorpej
368 1.1 thorpej tulip_chip_t sc_chip; /* chip type */
369 1.1 thorpej int sc_rev; /* chip revision */
370 1.1 thorpej int sc_flags; /* misc flags. */
371 1.51 christos char sc_name[32]; /* board name */
372 1.1 thorpej u_int32_t sc_cacheline; /* cache line size */
373 1.41 onoe u_int32_t sc_maxburst; /* maximum burst length */
374 1.10 thorpej int sc_devno; /* PCI device # */
375 1.1 thorpej
376 1.1 thorpej struct mii_data sc_mii; /* MII/media information */
377 1.1 thorpej
378 1.1 thorpej const struct tulip_txthresh_tab *sc_txth;
379 1.1 thorpej int sc_txthresh; /* current transmit threshold */
380 1.1 thorpej
381 1.19 thorpej u_int8_t sc_gp_dir; /* GPIO pin direction bits (21140) */
382 1.19 thorpej int sc_media_seen; /* ISV media block types seen */
383 1.19 thorpej int sc_tlp_minst; /* Tulip internal media instance */
384 1.48 thorpej u_int32_t sc_sia_cap; /* SIA media capabilities (21143) */
385 1.12 thorpej
386 1.12 thorpej /* Reset function. */
387 1.52 perry void (*sc_reset)(struct tulip_softc *);
388 1.12 thorpej
389 1.11 thorpej /* Pre-init function. */
390 1.52 perry void (*sc_preinit)(struct tulip_softc *);
391 1.11 thorpej
392 1.1 thorpej /* Filter setup function. */
393 1.52 perry void (*sc_filter_setup)(struct tulip_softc *);
394 1.1 thorpej
395 1.6 thorpej /* Media status update function. */
396 1.52 perry void (*sc_statchg)(struct device *);
397 1.4 thorpej
398 1.6 thorpej /* Media tick function. */
399 1.52 perry void (*sc_tick)(void *);
400 1.32 thorpej struct callout sc_tick_callout;
401 1.6 thorpej
402 1.30 thorpej /* Power management hooks. */
403 1.52 perry int (*sc_enable)(struct tulip_softc *);
404 1.52 perry void (*sc_disable)(struct tulip_softc *);
405 1.52 perry void (*sc_power)(struct tulip_softc *, int);
406 1.30 thorpej
407 1.1 thorpej /*
408 1.1 thorpej * The Winbond 89C840F places registers 4 bytes apart, instead
409 1.1 thorpej * of 8.
410 1.1 thorpej */
411 1.1 thorpej int sc_regshift;
412 1.1 thorpej
413 1.1 thorpej u_int32_t sc_busmode; /* copy of CSR_BUSMODE */
414 1.1 thorpej u_int32_t sc_opmode; /* copy of CSR_OPMODE */
415 1.1 thorpej u_int32_t sc_inten; /* copy of CSR_INTEN */
416 1.4 thorpej
417 1.4 thorpej u_int32_t sc_rxint_mask; /* mask of Rx interrupts we want */
418 1.4 thorpej u_int32_t sc_txint_mask; /* mask of Tx interrupts we want */
419 1.1 thorpej
420 1.1 thorpej u_int32_t sc_filtmode; /* filter mode we're using */
421 1.1 thorpej
422 1.28 thorpej bus_dma_segment_t sc_cdseg; /* control data memory */
423 1.28 thorpej int sc_cdnseg; /* number of segments */
424 1.1 thorpej bus_dmamap_t sc_cddmamap; /* control data DMA map */
425 1.1 thorpej #define sc_cddma sc_cddmamap->dm_segs[0].ds_addr
426 1.1 thorpej
427 1.1 thorpej /*
428 1.1 thorpej * Software state for transmit and receive descriptors.
429 1.1 thorpej */
430 1.1 thorpej struct tulip_txsoft sc_txsoft[TULIP_TXQUEUELEN];
431 1.1 thorpej struct tulip_rxsoft sc_rxsoft[TULIP_NRXDESC];
432 1.1 thorpej
433 1.1 thorpej /*
434 1.1 thorpej * Control data structures.
435 1.1 thorpej */
436 1.1 thorpej struct tulip_control_data *sc_control_data;
437 1.1 thorpej #define sc_txdescs sc_control_data->tcd_txdescs
438 1.1 thorpej #define sc_rxdescs sc_control_data->tcd_rxdescs
439 1.1 thorpej #define sc_setup_desc sc_control_data->tcd_setup_desc
440 1.1 thorpej
441 1.1 thorpej int sc_txfree; /* number of free Tx descriptors */
442 1.1 thorpej int sc_txnext; /* next ready Tx descriptor */
443 1.25 thorpej int sc_ntxsegs; /* number of transmit segs per pkt */
444 1.1 thorpej
445 1.27 thorpej u_int32_t sc_tdctl_ch; /* conditional desc chaining */
446 1.27 thorpej u_int32_t sc_tdctl_er; /* conditional desc end-of-ring */
447 1.35 thorpej
448 1.35 thorpej u_int32_t sc_setup_fsls; /* FS|LS on setup descriptor */
449 1.27 thorpej
450 1.1 thorpej struct tulip_txsq sc_txfreeq; /* free Tx descsofts */
451 1.1 thorpej struct tulip_txsq sc_txdirtyq; /* dirty Tx descsofts */
452 1.1 thorpej
453 1.1 thorpej int sc_rxptr; /* next ready RX descriptor/descsoft */
454 1.39 enami
455 1.39 enami #if NRND > 0
456 1.39 enami rndsource_element_t sc_rnd_source; /* random source */
457 1.39 enami #endif
458 1.1 thorpej };
459 1.37 castor #endif
460 1.1 thorpej
461 1.1 thorpej /* sc_flags */
462 1.1 thorpej #define TULIPF_WANT_SETUP 0x00000001 /* want filter setup */
463 1.3 thorpej #define TULIPF_DOING_SETUP 0x00000002 /* doing multicast setup */
464 1.3 thorpej #define TULIPF_HAS_MII 0x00000004 /* has media on MII */
465 1.3 thorpej #define TULIPF_IC_FS 0x00000008 /* IC bit on first tx seg */
466 1.20 thorpej #define TULIPF_MRL 0x00000010 /* memory read line okay */
467 1.20 thorpej #define TULIPF_MRM 0x00000020 /* memory read multi okay */
468 1.20 thorpej #define TULIPF_MWI 0x00000040 /* memory write inval okay */
469 1.33 thorpej #define TULIPF_AUTOPOLL 0x00000080 /* chip supports auto-poll */
470 1.20 thorpej #define TULIPF_LINK_UP 0x00000100 /* link is up (non-MII) */
471 1.20 thorpej #define TULIPF_LINK_VALID 0x00000200 /* link state valid */
472 1.20 thorpej #define TULIPF_DOINGAUTO 0x00000400 /* doing autoneg (non-MII) */
473 1.30 thorpej #define TULIPF_ATTACHED 0x00000800 /* attach has succeeded */
474 1.30 thorpej #define TULIPF_ENABLED 0x00001000 /* chip is enabled */
475 1.41 onoe #define TULIPF_BLE 0x00002000 /* data is big endian */
476 1.42 onoe #define TULIPF_DBO 0x00004000 /* descriptor is big endian */
477 1.50 thorpej #define TULIPF_VPC 0x00008000 /* Virtual PC Ethernet */
478 1.30 thorpej
479 1.30 thorpej #define TULIP_IS_ENABLED(sc) ((sc)->sc_flags & TULIPF_ENABLED)
480 1.19 thorpej
481 1.19 thorpej /*
482 1.47 chs * This macro returns the current media entry.
483 1.19 thorpej */
484 1.47 chs #define TULIP_CURRENT_MEDIA(sc) ((sc)->sc_mii.mii_media.ifm_cur)
485 1.19 thorpej
486 1.19 thorpej /*
487 1.19 thorpej * This macro determines if a change to media-related OPMODE bits requires
488 1.19 thorpej * a chip reset.
489 1.19 thorpej */
490 1.19 thorpej #define TULIP_MEDIA_NEEDSRESET(sc, newbits) \
491 1.19 thorpej (((sc)->sc_opmode & OPMODE_MEDIA_BITS) != \
492 1.19 thorpej ((newbits) & OPMODE_MEDIA_BITS))
493 1.1 thorpej
494 1.1 thorpej #define TULIP_CDTXADDR(sc, x) ((sc)->sc_cddma + TULIP_CDTXOFF((x)))
495 1.1 thorpej #define TULIP_CDRXADDR(sc, x) ((sc)->sc_cddma + TULIP_CDRXOFF((x)))
496 1.1 thorpej
497 1.1 thorpej #define TULIP_CDSPADDR(sc) ((sc)->sc_cddma + TULIP_CDSPOFF)
498 1.1 thorpej
499 1.1 thorpej #define TULIP_CDSP(sc) ((sc)->sc_control_data->tcd_setup_packet)
500 1.1 thorpej
501 1.1 thorpej #define TULIP_CDTXSYNC(sc, x, n, ops) \
502 1.1 thorpej do { \
503 1.1 thorpej int __x, __n; \
504 1.1 thorpej \
505 1.1 thorpej __x = (x); \
506 1.1 thorpej __n = (n); \
507 1.1 thorpej \
508 1.1 thorpej /* If it will wrap around, sync to the end of the ring. */ \
509 1.1 thorpej if ((__x + __n) > TULIP_NTXDESC) { \
510 1.1 thorpej bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
511 1.1 thorpej TULIP_CDTXOFF(__x), sizeof(struct tulip_desc) * \
512 1.1 thorpej (TULIP_NTXDESC - __x), (ops)); \
513 1.1 thorpej __n -= (TULIP_NTXDESC - __x); \
514 1.1 thorpej __x = 0; \
515 1.1 thorpej } \
516 1.1 thorpej \
517 1.1 thorpej /* Now sync whatever is left. */ \
518 1.1 thorpej bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
519 1.1 thorpej TULIP_CDTXOFF(__x), sizeof(struct tulip_desc) * __n, (ops)); \
520 1.1 thorpej } while (0)
521 1.1 thorpej
522 1.1 thorpej #define TULIP_CDRXSYNC(sc, x, ops) \
523 1.1 thorpej bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
524 1.1 thorpej TULIP_CDRXOFF((x)), sizeof(struct tulip_desc), (ops))
525 1.1 thorpej
526 1.1 thorpej #define TULIP_CDSPSYNC(sc, ops) \
527 1.1 thorpej bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
528 1.1 thorpej TULIP_CDSPOFF, TULIP_SETUP_PACKET_LEN, (ops))
529 1.1 thorpej
530 1.1 thorpej /*
531 1.1 thorpej * Note we rely on MCLBYTES being a power of two. Because the `length'
532 1.1 thorpej * field is only 11 bits, we must subtract 1 from the length to avoid
533 1.1 thorpej * having it truncated to 0!
534 1.1 thorpej */
535 1.1 thorpej #define TULIP_INIT_RXDESC(sc, x) \
536 1.1 thorpej do { \
537 1.1 thorpej struct tulip_rxsoft *__rxs = &sc->sc_rxsoft[(x)]; \
538 1.1 thorpej struct tulip_desc *__rxd = &sc->sc_rxdescs[(x)]; \
539 1.1 thorpej struct mbuf *__m = __rxs->rxs_mbuf; \
540 1.1 thorpej \
541 1.1 thorpej __m->m_data = __m->m_ext.ext_buf; \
542 1.23 thorpej __rxd->td_bufaddr1 = \
543 1.23 thorpej htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr); \
544 1.23 thorpej __rxd->td_bufaddr2 = \
545 1.23 thorpej htole32(TULIP_CDRXADDR((sc), TULIP_NEXTRX((x)))); \
546 1.1 thorpej __rxd->td_ctl = \
547 1.34 thorpej htole32((((__m->m_ext.ext_size - 1) & ~0x3U) \
548 1.34 thorpej << TDCTL_SIZE1_SHIFT) | (sc)->sc_tdctl_ch | \
549 1.27 thorpej ((x) == (TULIP_NRXDESC - 1) ? sc->sc_tdctl_er : 0)); \
550 1.23 thorpej __rxd->td_status = htole32(TDSTAT_OWN|TDSTAT_Rx_FS|TDSTAT_Rx_LS); \
551 1.1 thorpej TULIP_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
552 1.1 thorpej } while (0)
553 1.1 thorpej
554 1.1 thorpej /* CSR access */
555 1.8 thorpej #define TULIP_CSR_OFFSET(sc, csr) \
556 1.8 thorpej (TULIP_CSR_INDEX(csr) << (sc)->sc_regshift)
557 1.8 thorpej
558 1.1 thorpej #define TULIP_READ(sc, reg) \
559 1.1 thorpej bus_space_read_4((sc)->sc_st, (sc)->sc_sh, \
560 1.8 thorpej TULIP_CSR_OFFSET((sc), (reg)))
561 1.1 thorpej
562 1.1 thorpej #define TULIP_WRITE(sc, reg, val) \
563 1.1 thorpej bus_space_write_4((sc)->sc_st, (sc)->sc_sh, \
564 1.8 thorpej TULIP_CSR_OFFSET((sc), (reg)), (val))
565 1.1 thorpej
566 1.1 thorpej #define TULIP_SET(sc, reg, mask) \
567 1.1 thorpej TULIP_WRITE((sc), (reg), TULIP_READ((sc), (reg)) | (mask))
568 1.1 thorpej
569 1.1 thorpej #define TULIP_CLR(sc, reg, mask) \
570 1.1 thorpej TULIP_WRITE((sc), (reg), TULIP_READ((sc), (reg)) & ~(mask))
571 1.1 thorpej
572 1.1 thorpej #define TULIP_ISSET(sc, reg, mask) \
573 1.1 thorpej (TULIP_READ((sc), (reg)) & (mask))
574 1.22 thorpej
575 1.22 thorpej #if BYTE_ORDER == BIG_ENDIAN
576 1.22 thorpej #define TULIP_SP_FIELD_C(x) ((x) << 16)
577 1.22 thorpej #else
578 1.22 thorpej #define TULIP_SP_FIELD_C(x) (x)
579 1.22 thorpej #endif
580 1.22 thorpej #define TULIP_SP_FIELD(x, f) TULIP_SP_FIELD_C(((u_int16_t *)(x))[(f)])
581 1.1 thorpej
582 1.1 thorpej #ifdef _KERNEL
583 1.44 jdolecek extern const char * const tlp_chip_names[];
584 1.24 thorpej
585 1.7 thorpej extern const struct tulip_mediasw tlp_21040_mediasw;
586 1.7 thorpej extern const struct tulip_mediasw tlp_21040_tp_mediasw;
587 1.7 thorpej extern const struct tulip_mediasw tlp_21040_auibnc_mediasw;
588 1.11 thorpej extern const struct tulip_mediasw tlp_21041_mediasw;
589 1.12 thorpej extern const struct tulip_mediasw tlp_2114x_isv_mediasw;
590 1.1 thorpej extern const struct tulip_mediasw tlp_sio_mii_mediasw;
591 1.1 thorpej extern const struct tulip_mediasw tlp_pnic_mediasw;
592 1.16 thorpej extern const struct tulip_mediasw tlp_pmac_mediasw;
593 1.16 thorpej extern const struct tulip_mediasw tlp_al981_mediasw;
594 1.43 thorpej extern const struct tulip_mediasw tlp_an985_mediasw;
595 1.36 thorpej extern const struct tulip_mediasw tlp_dm9102_mediasw;
596 1.1 thorpej
597 1.52 perry void tlp_attach(struct tulip_softc *, const u_int8_t *);
598 1.52 perry int tlp_activate(struct device *, enum devact);
599 1.52 perry int tlp_detach(struct tulip_softc *);
600 1.52 perry int tlp_intr(void *);
601 1.52 perry int tlp_read_srom(struct tulip_softc *);
602 1.52 perry int tlp_srom_crcok(const u_int8_t *);
603 1.52 perry int tlp_isv_srom(const u_int8_t *);
604 1.52 perry int tlp_isv_srom_enaddr(struct tulip_softc *, u_int8_t *);
605 1.52 perry int tlp_parse_old_srom(struct tulip_softc *, u_int8_t *);
606 1.52 perry void tlp_reset(struct tulip_softc *);
607 1.52 perry
608 1.52 perry int tlp_mediachange(struct ifnet *);
609 1.52 perry void tlp_mediastatus(struct ifnet *, struct ifmediareq *);
610 1.52 perry
611 1.52 perry void tlp_21140_gpio_get(struct tulip_softc *sc, struct ifmediareq *ifmr);
612 1.52 perry int tlp_21140_gpio_set(struct tulip_softc *sc);
613 1.46 chs
614 1.1 thorpej #endif /* _KERNEL */
615 1.1 thorpej
616 1.1 thorpej #endif /* _DEV_IC_TULIPVAR_H_ */
617