tulipvar.h revision 1.16 1 /* $NetBSD: tulipvar.h,v 1.16 1999/09/29 18:52:19 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 1999 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 _DEV_IC_TULIPVAR_H_
41 #define _DEV_IC_TULIPVAR_H_
42
43 #include <sys/queue.h>
44
45 /*
46 * Misc. definitions for the Digital Semiconductor ``Tulip'' (21x4x)
47 * Ethernet controller family driver.
48 */
49
50 /*
51 * Transmit descriptor list size. This is arbitrary, but allocate
52 * enough descriptors for 64 pending transmissions and 16 segments
53 * per packet. Since a descriptor holds 2 buffer addresses, that's
54 * 8 descriptors per packet. This MUST work out to a power of 2.
55 */
56 #define TULIP_NTXSEGS 16
57
58 #define TULIP_TXQUEUELEN 64
59 #define TULIP_NTXDESC (TULIP_TXQUEUELEN * TULIP_NTXSEGS)
60 #define TULIP_NTXDESC_MASK (TULIP_NTXDESC - 1)
61 #define TULIP_NEXTTX(x) ((x + 1) & TULIP_NTXDESC_MASK)
62
63 /*
64 * Receive descriptor list size. We have one Rx buffer per incoming
65 * packet, so this logic is a little simpler.
66 */
67 #define TULIP_NRXDESC 64
68 #define TULIP_NRXDESC_MASK (TULIP_NRXDESC - 1)
69 #define TULIP_NEXTRX(x) ((x + 1) & TULIP_NRXDESC_MASK)
70
71 /*
72 * Control structures are DMA'd to the TULIP chip. We allocate them in
73 * a single clump that maps to a single DMA segment to make several things
74 * easier.
75 */
76 struct tulip_control_data {
77 /*
78 * The transmit descriptors.
79 */
80 struct tulip_desc tcd_txdescs[TULIP_NTXDESC];
81
82 /*
83 * The receive descriptors.
84 */
85 struct tulip_desc tcd_rxdescs[TULIP_NRXDESC];
86
87 /*
88 * The setup descriptor.
89 */
90 struct tulip_desc tcd_setup_desc;
91
92 /*
93 * The setup packet.
94 */
95 u_int32_t tcd_setup_packet[TULIP_SETUP_PACKET_LEN / sizeof(u_int32_t)];
96 };
97
98 #define TULIP_CDOFF(x) offsetof(struct tulip_control_data, x)
99 #define TULIP_CDTXOFF(x) TULIP_CDOFF(tcd_txdescs[(x)])
100 #define TULIP_CDRXOFF(x) TULIP_CDOFF(tcd_rxdescs[(x)])
101 #define TULIP_CDSDOFF TULIP_CDOFF(tcd_setup_desc)
102 #define TULIP_CDSPOFF TULIP_CDOFF(tcd_setup_packet)
103
104 /*
105 * Software state for transmit jobs.
106 */
107 struct tulip_txsoft {
108 struct mbuf *txs_mbuf; /* head of our mbuf chain */
109 bus_dmamap_t txs_dmamap; /* our DMA map */
110 int txs_firstdesc; /* first descriptor in packet */
111 int txs_lastdesc; /* last descriptor in packet */
112 SIMPLEQ_ENTRY(tulip_txsoft) txs_q;
113 };
114
115 SIMPLEQ_HEAD(tulip_txsq, tulip_txsoft);
116
117 /*
118 * Software state for receive jobs.
119 */
120 struct tulip_rxsoft {
121 struct mbuf *rxs_mbuf; /* head of our mbuf chain */
122 bus_dmamap_t rxs_dmamap; /* our DMA map */
123 };
124
125 /*
126 * Type of Tulip chip we're dealing with.
127 */
128 typedef enum {
129 TULIP_CHIP_INVALID = 0, /* invalid chip type */
130 TULIP_CHIP_DE425 = 1, /* DE-425 EISA */
131 TULIP_CHIP_21040 = 2, /* DECchip 21040 */
132 TULIP_CHIP_21041 = 3, /* DECchip 21041 */
133 TULIP_CHIP_21140 = 4, /* DECchip 21140 */
134 TULIP_CHIP_21140A = 5, /* DECchip 21140A */
135 TULIP_CHIP_21142 = 6, /* DECchip 21142 */
136 TULIP_CHIP_21143 = 7, /* DECchip 21143 */
137 TULIP_CHIP_82C168 = 8, /* Lite-On 82C168 PNIC */
138 TULIP_CHIP_82C169 = 9, /* Lite-On 82C169 PNIC */
139 TULIP_CHIP_82C115 = 10, /* Lite-On 82C115 PNIC II */
140 TULIP_CHIP_MX98713 = 11, /* Macronix 98713 PMAC */
141 TULIP_CHIP_MX98713A = 12, /* Macronix 98713A PMAC */
142 TULIP_CHIP_MX98715 = 13, /* Macronix 98715, 98715A PMAC */
143 TULIP_CHIP_MX98725 = 14, /* Macronix 98725 PMAC */
144 TULIP_CHIP_WB89C840F = 15, /* Winbond 89C840F */
145 TULIP_CHIP_DM9102 = 16, /* Davicom DM9102 */
146 TULIP_CHIP_AL981 = 17, /* ADMtek AL981 */
147 TULIP_CHIP_AX88140 = 18, /* ASIX AX88140 */
148 TULIP_CHIP_AX88141 = 19, /* ASIX AX88141 */
149 } tulip_chip_t;
150
151 #define TULIP_CHIP_NAMES \
152 { \
153 NULL, \
154 "DE-425", \
155 "DECchip 21040", \
156 "DECchip 21041", \
157 "DECchip 21140", \
158 "DECchip 21140A", \
159 "DECchip 21142", \
160 "DECchip 21143", \
161 "Lite-On 82C168", \
162 "Lite-On 82C169", \
163 "Lite-On 82C115", \
164 "Macronix MX98713", \
165 "Macronix MX98713A", \
166 "Macronix MX98715", \
167 "Macronix MX98725", \
168 "Winbond 89C840F", \
169 "Davicom DM9102", \
170 "ADMtek AL981", \
171 "ASIX AX88140", \
172 "ASIX AX88141", \
173 }
174
175 struct tulip_softc;
176
177 /*
178 * Media init, change, status function pointers.
179 */
180 struct tulip_mediasw {
181 void (*tmsw_init) __P((struct tulip_softc *));
182 void (*tmsw_get) __P((struct tulip_softc *, struct ifmediareq *));
183 int (*tmsw_set) __P((struct tulip_softc *));
184 };
185
186 /*
187 * Table which describes the transmit threshold mode.
188 */
189 struct tulip_txthresh_tab {
190 u_int32_t txth_opmode; /* OPMODE bits */
191 const char *txth_name; /* name of mode */
192 };
193
194 /*
195 * Description of 21040/21041 SIA media.
196 */
197 struct tulip_21040_21041_sia_media {
198 u_int32_t tsm_siaconn; /* CSR13 value */
199 u_int32_t tsm_siatxrx; /* CSR14 value */
200 u_int32_t tsm_siagen; /* CSR15 value */
201 };
202
203 /*
204 * Description of 2114x media.
205 */
206 struct tulip_2114x_media {
207 int tm_type; /* type of media; see tulipreg.h */
208 const char *tm_name; /* name of media */
209
210 void (*tm_get) __P((struct tulip_softc *,
211 struct ifmediareq *));
212 int (*tm_set) __P((struct tulip_softc *));
213
214 int tm_phyno; /* PHY # on MII */
215
216 int tm_gp_length; /* MII select sequence length */
217 int tm_gp_offset; /* MII select sequence offset */
218
219 int tm_reset_length;/* MII reset sequence length */
220 int tm_reset_offset;/* MII reset sequence offset */
221
222 u_int32_t tm_opmode; /* OPMODE bits for this media */
223 u_int32_t tm_gpdata; /* GPIO bits for this media */
224 u_int32_t tm_actmask; /* `active' bits for this data */
225 u_int32_t tm_actdata; /* active high/low info */
226 };
227
228 /*
229 * Table for converting Tulip SROM media info into ifmedia data.
230 */
231 struct tulip_srom_to_ifmedia {
232 u_int8_t tsti_srom; /* SROM media type */
233 int tsti_subtype; /* ifmedia subtype */
234 int tsti_options; /* ifmedia options */
235 const char *tsti_name; /* media name */
236
237 /*
238 * These members provide 21041 SIA default settings in case
239 * the SROM doesn't have them.
240 */
241 u_int32_t tsti_21041_siaconn;
242 u_int32_t tsti_21041_siatxrx;
243 u_int32_t tsti_21041_siagen;
244 };
245
246 /*
247 * Software state per device.
248 */
249 struct tulip_softc {
250 struct device sc_dev; /* generic device information */
251 bus_space_tag_t sc_st; /* bus space tag */
252 bus_space_handle_t sc_sh; /* bus space handle */
253 bus_dma_tag_t sc_dmat; /* bus DMA tag */
254 struct ethercom sc_ethercom; /* ethernet common data */
255 void *sc_sdhook; /* shutdown hook */
256
257 /*
258 * Contents of the SROM.
259 */
260 u_int8_t sc_srom[TULIP_MAX_ROM_SIZE];
261
262 /*
263 * Media access functions for this chip.
264 */
265 const struct tulip_mediasw *sc_mediasw;
266
267 /*
268 * For chips with built-in NWay blocks, these are state
269 * variables required for autonegotiation.
270 */
271 int sc_nway_ticks; /* tick counter */
272 int sc_nway_active; /* last active media */
273
274 tulip_chip_t sc_chip; /* chip type */
275 int sc_rev; /* chip revision */
276 int sc_flags; /* misc flags. */
277 char sc_name[16]; /* board name */
278 u_int32_t sc_cacheline; /* cache line size */
279 int sc_devno; /* PCI device # */
280
281 struct mii_data sc_mii; /* MII/media information */
282
283 const struct tulip_txthresh_tab *sc_txth;
284 int sc_txthresh; /* current transmit threshold */
285
286 u_int8_t sc_gp_dir; /* GPIO pin direction bits */
287
288 /* Reset function. */
289 void (*sc_reset) __P((struct tulip_softc *));
290
291 /* Pre-init function. */
292 void (*sc_preinit) __P((struct tulip_softc *));
293
294 /* Filter setup function. */
295 void (*sc_filter_setup) __P((struct tulip_softc *));
296
297 /* Media status update function. */
298 void (*sc_statchg) __P((struct device *));
299
300 /* Media tick function. */
301 void (*sc_tick) __P((void *));
302
303 /*
304 * The Winbond 89C840F places registers 4 bytes apart, instead
305 * of 8.
306 */
307 int sc_regshift;
308
309 u_int32_t sc_busmode; /* copy of CSR_BUSMODE */
310 u_int32_t sc_opmode; /* copy of CSR_OPMODE */
311 u_int32_t sc_inten; /* copy of CSR_INTEN */
312
313 u_int32_t sc_rxint_mask; /* mask of Rx interrupts we want */
314 u_int32_t sc_txint_mask; /* mask of Tx interrupts we want */
315
316 u_int32_t sc_filtmode; /* filter mode we're using */
317
318 bus_dmamap_t sc_cddmamap; /* control data DMA map */
319 #define sc_cddma sc_cddmamap->dm_segs[0].ds_addr
320
321 /*
322 * Software state for transmit and receive descriptors.
323 */
324 struct tulip_txsoft sc_txsoft[TULIP_TXQUEUELEN];
325 struct tulip_rxsoft sc_rxsoft[TULIP_NRXDESC];
326
327 /*
328 * Control data structures.
329 */
330 struct tulip_control_data *sc_control_data;
331 #define sc_txdescs sc_control_data->tcd_txdescs
332 #define sc_rxdescs sc_control_data->tcd_rxdescs
333 #define sc_setup_desc sc_control_data->tcd_setup_desc
334
335 int sc_txfree; /* number of free Tx descriptors */
336 int sc_txnext; /* next ready Tx descriptor */
337
338 struct tulip_txsq sc_txfreeq; /* free Tx descsofts */
339 struct tulip_txsq sc_txdirtyq; /* dirty Tx descsofts */
340
341 int sc_rxptr; /* next ready RX descriptor/descsoft */
342 };
343
344 /* sc_flags */
345 #define TULIPF_WANT_SETUP 0x00000001 /* want filter setup */
346 #define TULIPF_DOING_SETUP 0x00000002 /* doing multicast setup */
347 #define TULIPF_HAS_MII 0x00000004 /* has media on MII */
348 #define TULIPF_IC_FS 0x00000008 /* IC bit on first tx seg */
349 #define TULIPF_LINK_UP 0x00000010 /* link is up (non-MII) */
350 #define TULIPF_DOINGAUTO 0x00000020 /* doing autoneg (non-MII) */
351
352 #define TULIP_CDTXADDR(sc, x) ((sc)->sc_cddma + TULIP_CDTXOFF((x)))
353 #define TULIP_CDRXADDR(sc, x) ((sc)->sc_cddma + TULIP_CDRXOFF((x)))
354
355 #define TULIP_CDSDADDR(sc) ((sc)->sc_cddma + TULIP_CDSDOFF)
356 #define TULIP_CDSPADDR(sc) ((sc)->sc_cddma + TULIP_CDSPOFF)
357
358 #define TULIP_CDSP(sc) ((sc)->sc_control_data->tcd_setup_packet)
359
360 #define TULIP_CDTXSYNC(sc, x, n, ops) \
361 do { \
362 int __x, __n; \
363 \
364 __x = (x); \
365 __n = (n); \
366 \
367 /* If it will wrap around, sync to the end of the ring. */ \
368 if ((__x + __n) > TULIP_NTXDESC) { \
369 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
370 TULIP_CDTXOFF(__x), sizeof(struct tulip_desc) * \
371 (TULIP_NTXDESC - __x), (ops)); \
372 __n -= (TULIP_NTXDESC - __x); \
373 __x = 0; \
374 } \
375 \
376 /* Now sync whatever is left. */ \
377 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
378 TULIP_CDTXOFF(__x), sizeof(struct tulip_desc) * __n, (ops)); \
379 } while (0)
380
381 #define TULIP_CDRXSYNC(sc, x, ops) \
382 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
383 TULIP_CDRXOFF((x)), sizeof(struct tulip_desc), (ops))
384
385 #define TULIP_CDSDSYNC(sc, ops) \
386 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
387 TULIP_CDSDOFF, sizeof(struct tulip_desc), (ops))
388
389 #define TULIP_CDSPSYNC(sc, ops) \
390 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
391 TULIP_CDSPOFF, TULIP_SETUP_PACKET_LEN, (ops))
392
393 /*
394 * Note we rely on MCLBYTES being a power of two. Because the `length'
395 * field is only 11 bits, we must subtract 1 from the length to avoid
396 * having it truncated to 0!
397 */
398 #define TULIP_INIT_RXDESC(sc, x) \
399 do { \
400 struct tulip_rxsoft *__rxs = &sc->sc_rxsoft[(x)]; \
401 struct tulip_desc *__rxd = &sc->sc_rxdescs[(x)]; \
402 struct mbuf *__m = __rxs->rxs_mbuf; \
403 \
404 __m->m_data = __m->m_ext.ext_buf; \
405 __rxd->td_bufaddr1 = __rxs->rxs_dmamap->dm_segs[0].ds_addr; \
406 __rxd->td_bufaddr2 = TULIP_CDRXADDR((sc), TULIP_NEXTRX((x))); \
407 __rxd->td_ctl = \
408 ((__m->m_ext.ext_size - 1) << TDCTL_SIZE1_SHIFT) | TDCTL_CH; \
409 __rxd->td_status = TDSTAT_OWN|TDSTAT_Rx_FS|TDSTAT_Rx_LS; \
410 TULIP_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
411 } while (0)
412
413 /* CSR access */
414 #define TULIP_CSR_OFFSET(sc, csr) \
415 (TULIP_CSR_INDEX(csr) << (sc)->sc_regshift)
416
417 #define TULIP_READ(sc, reg) \
418 bus_space_read_4((sc)->sc_st, (sc)->sc_sh, \
419 TULIP_CSR_OFFSET((sc), (reg)))
420
421 #define TULIP_WRITE(sc, reg, val) \
422 bus_space_write_4((sc)->sc_st, (sc)->sc_sh, \
423 TULIP_CSR_OFFSET((sc), (reg)), (val))
424
425 #define TULIP_SET(sc, reg, mask) \
426 TULIP_WRITE((sc), (reg), TULIP_READ((sc), (reg)) | (mask))
427
428 #define TULIP_CLR(sc, reg, mask) \
429 TULIP_WRITE((sc), (reg), TULIP_READ((sc), (reg)) & ~(mask))
430
431 #define TULIP_ISSET(sc, reg, mask) \
432 (TULIP_READ((sc), (reg)) & (mask))
433
434 #ifdef _KERNEL
435 extern const struct tulip_mediasw tlp_21040_mediasw;
436 extern const struct tulip_mediasw tlp_21040_tp_mediasw;
437 extern const struct tulip_mediasw tlp_21040_auibnc_mediasw;
438 extern const struct tulip_mediasw tlp_21041_mediasw;
439 extern const struct tulip_mediasw tlp_2114x_isv_mediasw;
440 extern const struct tulip_mediasw tlp_sio_mii_mediasw;
441 extern const struct tulip_mediasw tlp_pnic_mediasw;
442 extern const struct tulip_mediasw tlp_pmac_mediasw;
443 extern const struct tulip_mediasw tlp_al981_mediasw;
444
445 void tlp_attach __P((struct tulip_softc *, const u_int8_t *));
446 int tlp_intr __P((void *));
447 void tlp_read_srom __P((struct tulip_softc *, int, int, u_int8_t *));
448 int tlp_srom_crcok __P((const u_int8_t *));
449 int tlp_isv_srom __P((const u_int8_t *));
450 int tlp_isv_srom_enaddr __P((struct tulip_softc *, u_int8_t *));
451 int tlp_parse_old_srom __P((struct tulip_softc *, u_int8_t *));
452
453 int tlp_mediachange __P((struct ifnet *));
454 void tlp_mediastatus __P((struct ifnet *, struct ifmediareq *));
455 #endif /* _KERNEL */
456
457 #endif /* _DEV_IC_TULIPVAR_H_ */
458