tulipvar.h revision 1.30 1 /* $NetBSD: tulipvar.h,v 1.30 2000/03/15 18:39:51 thorpej 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 _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 packet.
89 */
90 u_int32_t tcd_setup_packet[TULIP_SETUP_PACKET_LEN / sizeof(u_int32_t)];
91 };
92
93 #define TULIP_CDOFF(x) offsetof(struct tulip_control_data, x)
94 #define TULIP_CDTXOFF(x) TULIP_CDOFF(tcd_txdescs[(x)])
95 #define TULIP_CDRXOFF(x) TULIP_CDOFF(tcd_rxdescs[(x)])
96 #define TULIP_CDSPOFF TULIP_CDOFF(tcd_setup_packet)
97
98 /*
99 * Software state for transmit jobs.
100 */
101 struct tulip_txsoft {
102 struct mbuf *txs_mbuf; /* head of our mbuf chain */
103 bus_dmamap_t txs_dmamap; /* our DMA map */
104 int txs_firstdesc; /* first descriptor in packet */
105 int txs_lastdesc; /* last descriptor in packet */
106 int txs_ndescs; /* number of descriptors */
107 SIMPLEQ_ENTRY(tulip_txsoft) txs_q;
108 };
109
110 SIMPLEQ_HEAD(tulip_txsq, tulip_txsoft);
111
112 /*
113 * Software state for receive jobs.
114 */
115 struct tulip_rxsoft {
116 struct mbuf *rxs_mbuf; /* head of our mbuf chain */
117 bus_dmamap_t rxs_dmamap; /* our DMA map */
118 };
119
120 /*
121 * Type of Tulip chip we're dealing with.
122 */
123 typedef enum {
124 TULIP_CHIP_INVALID = 0, /* invalid chip type */
125 TULIP_CHIP_DE425 = 1, /* DE-425 EISA */
126 TULIP_CHIP_21040 = 2, /* DECchip 21040 */
127 TULIP_CHIP_21041 = 3, /* DECchip 21041 */
128 TULIP_CHIP_21140 = 4, /* DECchip 21140 */
129 TULIP_CHIP_21140A = 5, /* DECchip 21140A */
130 TULIP_CHIP_21142 = 6, /* DECchip 21142 */
131 TULIP_CHIP_21143 = 7, /* DECchip 21143 */
132 TULIP_CHIP_82C168 = 8, /* Lite-On 82C168 PNIC */
133 TULIP_CHIP_82C169 = 9, /* Lite-On 82C169 PNIC */
134 TULIP_CHIP_82C115 = 10, /* Lite-On 82C115 PNIC II */
135 TULIP_CHIP_MX98713 = 11, /* Macronix 98713 PMAC */
136 TULIP_CHIP_MX98713A = 12, /* Macronix 98713A PMAC */
137 TULIP_CHIP_MX98715 = 13, /* Macronix 98715 PMAC */
138 TULIP_CHIP_MX98715A = 14, /* Macronix 98715A PMAC */
139 TULIP_CHIP_MX98725 = 15, /* Macronix 98725 PMAC */
140 TULIP_CHIP_WB89C840F = 16, /* Winbond 89C840F */
141 TULIP_CHIP_DM9102 = 17, /* Davicom DM9102 */
142 TULIP_CHIP_AL981 = 18, /* ADMtek AL981 */
143 TULIP_CHIP_AX88140 = 19, /* ASIX AX88140 */
144 TULIP_CHIP_AX88141 = 20, /* ASIX AX88141 */
145 TULIP_CHIP_X3201_3 = 21, /* Xircom X3201-3 */
146 } tulip_chip_t;
147
148 #define TULIP_CHIP_NAMES \
149 { \
150 NULL, \
151 "DE-425", \
152 "DECchip 21040", \
153 "DECchip 21041", \
154 "DECchip 21140", \
155 "DECchip 21140A", \
156 "DECchip 21142", \
157 "DECchip 21143", \
158 "Lite-On 82C168", \
159 "Lite-On 82C169", \
160 "Lite-On 82C115", \
161 "Macronix MX98713", \
162 "Macronix MX98713A", \
163 "Macronix MX98715", \
164 "Macronix MX98715A", \
165 "Macronix MX98725", \
166 "Winbond 89C840F", \
167 "Davicom DM9102", \
168 "ADMtek AL981", \
169 "ASIX AX88140", \
170 "ASIX AX88141", \
171 "Xircom X3201-3", \
172 }
173
174 struct tulip_softc;
175
176 /*
177 * Media init, change, status function pointers.
178 */
179 struct tulip_mediasw {
180 void (*tmsw_init) __P((struct tulip_softc *));
181 void (*tmsw_get) __P((struct tulip_softc *, struct ifmediareq *));
182 int (*tmsw_set) __P((struct tulip_softc *));
183 };
184
185 /*
186 * Table which describes the transmit threshold mode.
187 */
188 struct tulip_txthresh_tab {
189 u_int32_t txth_opmode; /* OPMODE bits */
190 const char *txth_name; /* name of mode */
191 };
192
193 /*
194 * Settings for Tulip SIA media.
195 */
196 struct tulip_sia_media {
197 u_int32_t tsm_siaconn; /* CSR13 value */
198 u_int32_t tsm_siatxrx; /* CSR14 value */
199 u_int32_t tsm_siagen; /* CSR15 value */
200 };
201
202 /*
203 * Description of 2x14x media.
204 */
205 struct tulip_21x4x_media {
206 int tm_type; /* type of media; see tulipreg.h */
207 const char *tm_name; /* name of media */
208
209 void (*tm_get) __P((struct tulip_softc *,
210 struct ifmediareq *));
211 int (*tm_set) __P((struct tulip_softc *));
212
213 int tm_phyno; /* PHY # on MII */
214
215 int tm_gp_length; /* MII select sequence length */
216 int tm_gp_offset; /* MII select sequence offset */
217
218 int tm_reset_length;/* MII reset sequence length */
219 int tm_reset_offset;/* MII reset sequence offset */
220
221 u_int32_t tm_opmode; /* OPMODE bits for this media */
222 u_int32_t tm_gpctl; /* GPIO control 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 struct tulip_sia_media tm_sia; /* SIA settings */
228 #define tm_siaconn tm_sia.tsm_siaconn
229 #define tm_siatxrx tm_sia.tsm_siatxrx
230 #define tm_siagen tm_sia.tsm_siagen
231 };
232
233 /*
234 * Table for converting Tulip SROM media info into ifmedia data.
235 */
236 struct tulip_srom_to_ifmedia {
237 u_int8_t tsti_srom; /* SROM media type */
238 int tsti_subtype; /* ifmedia subtype */
239 int tsti_options; /* ifmedia options */
240 const char *tsti_name; /* media name */
241
242 u_int32_t tsti_opmode; /* OPMODE bits for this media */
243
244 /*
245 * Settings for 21040, 21041, and 21142/21143 SIA, in the event
246 * the SROM doesn't have them.
247 */
248 struct tulip_sia_media tsti_21040;
249 struct tulip_sia_media tsti_21041;
250 struct tulip_sia_media tsti_21142;
251 };
252
253 /*
254 * Some misc. statics, useful for debugging.
255 */
256 struct tulip_stats {
257 u_long ts_tx_uf; /* transmit underflow errors */
258 u_long ts_tx_to; /* transmit jabber timeouts */
259 u_long ts_tx_ec; /* excessve collision count */
260 u_long ts_tx_lc; /* late collision count */
261 };
262
263 /*
264 * Software state per device.
265 */
266 struct tulip_softc {
267 struct device sc_dev; /* generic device information */
268 bus_space_tag_t sc_st; /* bus space tag */
269 bus_space_handle_t sc_sh; /* bus space handle */
270 bus_dma_tag_t sc_dmat; /* bus DMA tag */
271 struct ethercom sc_ethercom; /* ethernet common data */
272 void *sc_sdhook; /* shutdown hook */
273
274 struct tulip_stats sc_stats; /* debugging stats */
275
276 /*
277 * Contents of the SROM.
278 */
279 u_int8_t *sc_srom;
280 int sc_srom_addrbits;
281
282 /*
283 * Media access functions for this chip.
284 */
285 const struct tulip_mediasw *sc_mediasw;
286 mii_bitbang_ops_t sc_bitbang_ops;
287
288 /*
289 * For chips with built-in NWay blocks, these are state
290 * variables required for autonegotiation.
291 */
292 int sc_nway_ticks; /* tick counter */
293 struct ifmedia_entry *sc_nway_active; /* the active media */
294
295 tulip_chip_t sc_chip; /* chip type */
296 int sc_rev; /* chip revision */
297 int sc_flags; /* misc flags. */
298 char sc_name[16]; /* board name */
299 u_int32_t sc_cacheline; /* cache line size */
300 int sc_devno; /* PCI device # */
301
302 struct mii_data sc_mii; /* MII/media information */
303
304 const struct tulip_txthresh_tab *sc_txth;
305 int sc_txthresh; /* current transmit threshold */
306
307 u_int8_t sc_gp_dir; /* GPIO pin direction bits (21140) */
308 int sc_media_seen; /* ISV media block types seen */
309 int sc_tlp_minst; /* Tulip internal media instance */
310
311 /* Reset function. */
312 void (*sc_reset) __P((struct tulip_softc *));
313
314 /* Pre-init function. */
315 void (*sc_preinit) __P((struct tulip_softc *));
316
317 /* Filter setup function. */
318 void (*sc_filter_setup) __P((struct tulip_softc *));
319
320 /* Media status update function. */
321 void (*sc_statchg) __P((struct device *));
322
323 /* Media tick function. */
324 void (*sc_tick) __P((void *));
325
326 /* Power management hooks. */
327 int (*sc_enable) __P((struct tulip_softc *));
328 void (*sc_disable) __P((struct tulip_softc *));
329
330 /*
331 * The Winbond 89C840F places registers 4 bytes apart, instead
332 * of 8.
333 */
334 int sc_regshift;
335
336 u_int32_t sc_busmode; /* copy of CSR_BUSMODE */
337 u_int32_t sc_opmode; /* copy of CSR_OPMODE */
338 u_int32_t sc_inten; /* copy of CSR_INTEN */
339
340 u_int32_t sc_rxint_mask; /* mask of Rx interrupts we want */
341 u_int32_t sc_txint_mask; /* mask of Tx interrupts we want */
342
343 u_int32_t sc_filtmode; /* filter mode we're using */
344
345 bus_dma_segment_t sc_cdseg; /* control data memory */
346 int sc_cdnseg; /* number of segments */
347 bus_dmamap_t sc_cddmamap; /* control data DMA map */
348 #define sc_cddma sc_cddmamap->dm_segs[0].ds_addr
349
350 /*
351 * Software state for transmit and receive descriptors.
352 */
353 struct tulip_txsoft sc_txsoft[TULIP_TXQUEUELEN];
354 struct tulip_rxsoft sc_rxsoft[TULIP_NRXDESC];
355
356 /*
357 * Control data structures.
358 */
359 struct tulip_control_data *sc_control_data;
360 #define sc_txdescs sc_control_data->tcd_txdescs
361 #define sc_rxdescs sc_control_data->tcd_rxdescs
362 #define sc_setup_desc sc_control_data->tcd_setup_desc
363
364 int sc_txfree; /* number of free Tx descriptors */
365 int sc_txnext; /* next ready Tx descriptor */
366 int sc_ntxsegs; /* number of transmit segs per pkt */
367
368 u_int32_t sc_tdctl_ch; /* conditional desc chaining */
369 u_int32_t sc_tdctl_er; /* conditional desc end-of-ring */
370
371 struct tulip_txsq sc_txfreeq; /* free Tx descsofts */
372 struct tulip_txsq sc_txdirtyq; /* dirty Tx descsofts */
373
374 int sc_rxptr; /* next ready RX descriptor/descsoft */
375 };
376
377 /* sc_flags */
378 #define TULIPF_WANT_SETUP 0x00000001 /* want filter setup */
379 #define TULIPF_DOING_SETUP 0x00000002 /* doing multicast setup */
380 #define TULIPF_HAS_MII 0x00000004 /* has media on MII */
381 #define TULIPF_IC_FS 0x00000008 /* IC bit on first tx seg */
382 #define TULIPF_MRL 0x00000010 /* memory read line okay */
383 #define TULIPF_MRM 0x00000020 /* memory read multi okay */
384 #define TULIPF_MWI 0x00000040 /* memory write inval okay */
385 #define TULIPF_LINK_UP 0x00000100 /* link is up (non-MII) */
386 #define TULIPF_LINK_VALID 0x00000200 /* link state valid */
387 #define TULIPF_DOINGAUTO 0x00000400 /* doing autoneg (non-MII) */
388 #define TULIPF_ATTACHED 0x00000800 /* attach has succeeded */
389 #define TULIPF_ENABLED 0x00001000 /* chip is enabled */
390
391 #define TULIP_IS_ENABLED(sc) ((sc)->sc_flags & TULIPF_ENABLED)
392
393 /*
394 * This macro returns the current media entry for *non-MII* media.
395 */
396 #define TULIP_CURRENT_MEDIA(sc) \
397 (IFM_SUBTYPE((sc)->sc_mii.mii_media.ifm_cur->ifm_media) != IFM_AUTO ? \
398 (sc)->sc_mii.mii_media.ifm_cur : (sc)->sc_nway_active)
399
400 /*
401 * This macro determines if a change to media-related OPMODE bits requires
402 * a chip reset.
403 */
404 #define TULIP_MEDIA_NEEDSRESET(sc, newbits) \
405 (((sc)->sc_opmode & OPMODE_MEDIA_BITS) != \
406 ((newbits) & OPMODE_MEDIA_BITS))
407
408 #define TULIP_CDTXADDR(sc, x) ((sc)->sc_cddma + TULIP_CDTXOFF((x)))
409 #define TULIP_CDRXADDR(sc, x) ((sc)->sc_cddma + TULIP_CDRXOFF((x)))
410
411 #define TULIP_CDSPADDR(sc) ((sc)->sc_cddma + TULIP_CDSPOFF)
412
413 #define TULIP_CDSP(sc) ((sc)->sc_control_data->tcd_setup_packet)
414
415 #define TULIP_CDTXSYNC(sc, x, n, ops) \
416 do { \
417 int __x, __n; \
418 \
419 __x = (x); \
420 __n = (n); \
421 \
422 /* If it will wrap around, sync to the end of the ring. */ \
423 if ((__x + __n) > TULIP_NTXDESC) { \
424 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
425 TULIP_CDTXOFF(__x), sizeof(struct tulip_desc) * \
426 (TULIP_NTXDESC - __x), (ops)); \
427 __n -= (TULIP_NTXDESC - __x); \
428 __x = 0; \
429 } \
430 \
431 /* Now sync whatever is left. */ \
432 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
433 TULIP_CDTXOFF(__x), sizeof(struct tulip_desc) * __n, (ops)); \
434 } while (0)
435
436 #define TULIP_CDRXSYNC(sc, x, ops) \
437 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
438 TULIP_CDRXOFF((x)), sizeof(struct tulip_desc), (ops))
439
440 #define TULIP_CDSPSYNC(sc, ops) \
441 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
442 TULIP_CDSPOFF, TULIP_SETUP_PACKET_LEN, (ops))
443
444 /*
445 * Note we rely on MCLBYTES being a power of two. Because the `length'
446 * field is only 11 bits, we must subtract 1 from the length to avoid
447 * having it truncated to 0!
448 */
449 #define TULIP_INIT_RXDESC(sc, x) \
450 do { \
451 struct tulip_rxsoft *__rxs = &sc->sc_rxsoft[(x)]; \
452 struct tulip_desc *__rxd = &sc->sc_rxdescs[(x)]; \
453 struct mbuf *__m = __rxs->rxs_mbuf; \
454 \
455 __m->m_data = __m->m_ext.ext_buf; \
456 __rxd->td_bufaddr1 = \
457 htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr); \
458 __rxd->td_bufaddr2 = \
459 htole32(TULIP_CDRXADDR((sc), TULIP_NEXTRX((x)))); \
460 __rxd->td_ctl = \
461 htole32(((__m->m_ext.ext_size - 1) << TDCTL_SIZE1_SHIFT) | \
462 (sc)->sc_tdctl_ch | \
463 ((x) == (TULIP_NRXDESC - 1) ? sc->sc_tdctl_er : 0)); \
464 __rxd->td_status = htole32(TDSTAT_OWN|TDSTAT_Rx_FS|TDSTAT_Rx_LS); \
465 TULIP_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
466 } while (0)
467
468 /* CSR access */
469 #define TULIP_CSR_OFFSET(sc, csr) \
470 (TULIP_CSR_INDEX(csr) << (sc)->sc_regshift)
471
472 #define TULIP_READ(sc, reg) \
473 bus_space_read_4((sc)->sc_st, (sc)->sc_sh, \
474 TULIP_CSR_OFFSET((sc), (reg)))
475
476 #define TULIP_WRITE(sc, reg, val) \
477 bus_space_write_4((sc)->sc_st, (sc)->sc_sh, \
478 TULIP_CSR_OFFSET((sc), (reg)), (val))
479
480 #define TULIP_SET(sc, reg, mask) \
481 TULIP_WRITE((sc), (reg), TULIP_READ((sc), (reg)) | (mask))
482
483 #define TULIP_CLR(sc, reg, mask) \
484 TULIP_WRITE((sc), (reg), TULIP_READ((sc), (reg)) & ~(mask))
485
486 #define TULIP_ISSET(sc, reg, mask) \
487 (TULIP_READ((sc), (reg)) & (mask))
488
489 #if BYTE_ORDER == BIG_ENDIAN
490 #define TULIP_SP_FIELD_C(x) ((x) << 16)
491 #else
492 #define TULIP_SP_FIELD_C(x) (x)
493 #endif
494 #define TULIP_SP_FIELD(x, f) TULIP_SP_FIELD_C(((u_int16_t *)(x))[(f)])
495
496 #ifdef _KERNEL
497 extern const char *tlp_chip_names[];
498
499 extern const struct tulip_mediasw tlp_21040_mediasw;
500 extern const struct tulip_mediasw tlp_21040_tp_mediasw;
501 extern const struct tulip_mediasw tlp_21040_auibnc_mediasw;
502 extern const struct tulip_mediasw tlp_21041_mediasw;
503 extern const struct tulip_mediasw tlp_2114x_isv_mediasw;
504 extern const struct tulip_mediasw tlp_sio_mii_mediasw;
505 extern const struct tulip_mediasw tlp_pnic_mediasw;
506 extern const struct tulip_mediasw tlp_pmac_mediasw;
507 extern const struct tulip_mediasw tlp_al981_mediasw;
508
509 void tlp_attach __P((struct tulip_softc *, const u_int8_t *));
510 int tlp_activate __P((struct device *, enum devact));
511 int tlp_detach __P((struct tulip_softc *));
512 int tlp_intr __P((void *));
513 int tlp_read_srom __P((struct tulip_softc *));
514 int tlp_srom_crcok __P((const u_int8_t *));
515 int tlp_isv_srom __P((const u_int8_t *));
516 int tlp_isv_srom_enaddr __P((struct tulip_softc *, u_int8_t *));
517 int tlp_parse_old_srom __P((struct tulip_softc *, u_int8_t *));
518
519 int tlp_mediachange __P((struct ifnet *));
520 void tlp_mediastatus __P((struct ifnet *, struct ifmediareq *));
521 #endif /* _KERNEL */
522
523 #endif /* _DEV_IC_TULIPVAR_H_ */
524