if_devar.h revision 1.21
1/*	$OpenBSD: if_devar.h,v 1.21 2005/09/08 01:09:58 brad Exp $	*/
2/*	$NetBSD: if_devar.h,v 1.13 1997/06/08 18:46:36 thorpej Exp $	*/
3
4/*-
5 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. The name of the author may not be used to endorse or promote products
14 *    derived from this software without specific prior written permission
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Id: if_devar.h,v 1.23 1997/06/03 18:51:16 thomas Exp
28 */
29
30typedef bus_addr_t tulip_csrptr_t;
31
32#define TULIP_CSR_READ(sc, csr) \
33    bus_space_read_4((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr)
34#define TULIP_CSR_WRITE(sc, csr, val) \
35    bus_space_write_4((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr, (val))
36
37#define TULIP_CSR_READBYTE(sc, csr) \
38    bus_space_read_1((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr)
39#define TULIP_CSR_WRITEBYTE(sc, csr, val) \
40    bus_space_write_1((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr, (val))
41
42#ifdef TULIP_IOMAPPED
43#define	TULIP_EISA_CSRSIZE	16
44#define	TULIP_EISA_CSROFFSET	0
45#define	TULIP_PCI_CSRSIZE	8
46#define	TULIP_PCI_CSROFFSET	0
47#else /* TULIP_IOMAPPED */
48#define	TULIP_PCI_CSRSIZE	8
49#define	TULIP_PCI_CSROFFSET	0
50#endif /* TULIP_IOMAPPED */
51
52/*
53 *  Swap macro to access certain data types.
54 */
55#if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN
56__inline__ static u_int32_t FILT_BO(u_int32_t);
57__inline__ static u_int32_t DESC_BO(u_int32_t);
58
59__inline__ static u_int32_t
60FILT_BO(x)
61    u_int32_t x;
62{
63	u_int32_t s;
64
65	s = (x & 0xffff) << 16 | ((x & 0xff) << 8) | ((x & 0xff00) >> 8);
66	return s;
67}
68
69__inline__ static u_int32_t
70DESC_BO(x)
71    u_int32_t x;
72{
73	u_int32_t s;
74
75	s = x;
76	x = (((s) >> 24) | (((s) >> 8) & 0xff00) |
77             ((s) << 24) | (((s) & 0xff00) << 8));
78	return x;
79}
80
81#else
82#define FILT_BO(x)	(x)
83#define DESC_BO(x)	(x)
84#endif
85
86/*
87 * This structure contains "pointers" for the registers on
88 * the various 21x4x chips.  CSR0 through CSR8 are common
89 * to all chips.  After that, it gets messy...
90 */
91typedef struct {
92    tulip_csrptr_t csr_busmode;			/* CSR0 */
93    tulip_csrptr_t csr_txpoll;			/* CSR1 */
94    tulip_csrptr_t csr_rxpoll;			/* CSR2 */
95    tulip_csrptr_t csr_rxlist;			/* CSR3 */
96    tulip_csrptr_t csr_txlist;			/* CSR4 */
97    tulip_csrptr_t csr_status;			/* CSR5 */
98    tulip_csrptr_t csr_command;			/* CSR6 */
99    tulip_csrptr_t csr_intr;			/* CSR7 */
100    tulip_csrptr_t csr_missed_frames;		/* CSR8 */
101    tulip_csrptr_t csr_9;			/* CSR9 */
102    tulip_csrptr_t csr_10;			/* CSR10 */
103    tulip_csrptr_t csr_11;			/* CSR11 */
104    tulip_csrptr_t csr_12;			/* CSR12 */
105    tulip_csrptr_t csr_13;			/* CSR13 */
106    tulip_csrptr_t csr_14;			/* CSR14 */
107    tulip_csrptr_t csr_15;			/* CSR15 */
108} tulip_regfile_t;
109
110#define	csr_enetrom		csr_9	/* 21040 */
111#define	csr_reserved		csr_10	/* 21040 */
112#define	csr_full_duplex		csr_11	/* 21040 */
113#define	csr_bootrom		csr_10	/* 21041/21140A/?? */
114#define	csr_gp			csr_12	/* 21140* */
115#define	csr_watchdog		csr_15	/* 21140* */
116#define	csr_gp_timer		csr_11	/* 21041/21140* */
117#define	csr_srom_mii		csr_9	/* 21041/21140* */
118#define	csr_sia_status		csr_12	/* 2104x */
119#define csr_sia_connectivity	csr_13	/* 2104x */
120#define csr_sia_tx_rx		csr_14	/* 2104x */
121#define csr_sia_general		csr_15	/* 2104x */
122
123/*
124 * While 21x4x allows chaining of its descriptors, this driver
125 * doesn't take advantage of it.  We keep the descriptors in a
126 * traditional FIFO ring.
127 */
128typedef struct {
129    tulip_desc_t *ri_first;	/* first entry in ring */
130    tulip_desc_t *ri_last;	/* one after last entry */
131    tulip_desc_t *ri_nextin;	/* next to processed by host */
132    tulip_desc_t *ri_nextout;	/* next to processed by adapter */
133    int ri_max;
134    int ri_free;
135} tulip_ringinfo_t;
136
137/*
138 * The 21040 has a stupid restriction in that the receive
139 * buffers must be longword aligned.  But since Ethernet
140 * headers are not a multiple of longwords in size this forces
141 * the data to non-longword aligned.  Since IP requires the
142 * data to be longword aligned, we need to copy it after it has
143 * been DMA'ed in our memory.
144 *
145 * Since we have to copy it anyways, we might as well as allocate
146 * dedicated receive space for the input.  This allows to use a
147 * small receive buffer size and more ring entries to be able to
148 * better keep with a flood of tiny Ethernet packets.
149 *
150 * The receive space MUST ALWAYS be a multiple of the page size.
151 * And the number of receive descriptors multiplied by the size
152 * of the receive buffers must equal the recevive space.  This
153 * is so that we can manipulate the page tables so that even if a
154 * packet wraps around the end of the receive space, we can
155 * treat it as virtually contiguous.
156 *
157 * The above used to be true (the stupid restriction is still true)
158 * but we gone to directly DMA'ing into MBUFs (unless it's on an
159 * architecture which can't handle unaligned accesses) because with
160 * 100Mb/s cards the copying is just too much of a hit.
161 */
162#if defined(__alpha__) || defined(__mips__)
163#define	TULIP_COPY_RXDATA	1
164#endif
165
166#define	TULIP_TXTIMER		4
167#define	TULIP_RXDESCS		48
168#define	TULIP_TXDESCS		128
169#define	TULIP_RXQ_TARGET	32
170#if TULIP_RXQ_TARGET >= TULIP_RXDESCS
171#error TULIP_RXQ_TARGET must be less than TULIP_RXDESCS
172#endif
173#define	TULIP_RX_BUFLEN		((MCLBYTES < 2048 ? MCLBYTES : 2048) - 16)
174
175/*
176 * Forward reference to make C happy.
177 */
178typedef struct _tulip_softc_t tulip_softc_t;
179
180/*
181 * The various controllers support.  Technically the DE425 is just
182 * a 21040 on EISA.  But since it remarkably difference from normal
183 * 21040s, we give it its own chip id.
184 */
185
186typedef enum {
187    TULIP_21040, TULIP_DE425,
188    TULIP_21041,
189    TULIP_21140, TULIP_21140A, TULIP_21142,
190    TULIP_21143,
191    TULIP_CHIPID_UNKNOWN
192} tulip_chipid_t;
193
194/*
195 * Various physical media types supported.
196 * BNCAUI is BNC or AUI since on the 21040 you can't really tell
197 * which is in use.
198 */
199typedef enum {
200    TULIP_MEDIA_UNKNOWN,
201    TULIP_MEDIA_10BASET,
202    TULIP_MEDIA_10BASET_FD,
203    TULIP_MEDIA_BNC,
204    TULIP_MEDIA_AUI,
205    TULIP_MEDIA_EXTSIA,
206    TULIP_MEDIA_AUIBNC,
207    TULIP_MEDIA_100BASETX,
208    TULIP_MEDIA_100BASETX_FD,
209    TULIP_MEDIA_100BASET4,
210    TULIP_MEDIA_100BASEFX,
211    TULIP_MEDIA_100BASEFX_FD,
212    TULIP_MEDIA_MAX
213} tulip_media_t;
214
215#define	TULIP_BIT(b)		(1L << ((int)(b)))
216#define	TULIP_FDBIT(m)		(1L << ((int)TULIP_MEDIA_ ## m ## _FD))
217#define	TULIP_MBIT(m)		(1L << ((int)TULIP_MEDIA_ ## m ))
218#define	TULIP_IS_MEDIA_FD(m)	(TULIP_BIT(m) & \
219				 (TULIP_FDBIT(10BASET) \
220				  |TULIP_FDBIT(100BASETX) \
221				  |TULIP_FDBIT(100BASEFX)))
222#define	TULIP_CAN_MEDIA_FD(m)	(TULIP_BIT(m) & \
223				 (TULIP_MBIT(10BASET) \
224				  |TULIP_MBIT(100BASETX) \
225				  |TULIP_MBIT(100BASEFX)))
226#define	TULIP_FD_MEDIA_OF(m)	((tulip_media_t)((m) + 1))
227#define	TULIP_HD_MEDIA_OF(m)	((tulip_media_t)((m) - 1))
228#define	TULIP_IS_MEDIA_100MB(m)	((m) >= TULIP_MEDIA_100BASETX)
229#define	TULIP_IS_MEDIA_TP(m)	((TULIP_BIT(m) & \
230				  (TULIP_MBIT(BNC) \
231				   |TULIP_MBIT(AUI) \
232				   |TULIP_MBIT(AUIBNC) \
233				   |TULIP_MBIT(EXTSIA))) == 0)
234
235#define	TULIP_SROM_ATTR_MII		0x0100
236#define	TULIP_SROM_ATTR_NWAY		0x0200
237#define	TULIP_SROM_ATTR_AUTOSENSE	0x0400
238#define	TULIP_SROM_ATTR_POWERUP		0x0800
239#define	TULIP_SROM_ATTR_NOLINKPASS	0x1000
240
241typedef struct {
242    enum {
243	TULIP_MEDIAINFO_NONE,
244	TULIP_MEDIAINFO_SIA,
245	TULIP_MEDIAINFO_GPR,
246	TULIP_MEDIAINFO_MII,
247	TULIP_MEDIAINFO_RESET,
248	TULIP_MEDIAINFO_SYM
249    } mi_type;
250    union {
251	struct {
252	    u_int16_t sia_connectivity;
253	    u_int16_t sia_tx_rx;
254	    u_int16_t sia_general;
255	    u_int32_t sia_gp_control;	/* 21142/21143 */
256	    u_int32_t sia_gp_data;	/* 21142/21143 */
257	} un_sia;
258	struct {
259	    u_int32_t gpr_cmdmode;
260	    u_int32_t gpr_gpcontrol;	/* 21142/21143 */
261	    u_int32_t gpr_gpdata;
262	    u_int8_t gpr_actmask;
263	    u_int8_t gpr_actdata;
264	    u_int8_t gpr_default : 1;
265	} un_gpr;
266	struct {
267	    u_int32_t mii_mediamask;
268	    u_int16_t mii_capabilities;
269	    u_int16_t mii_advertisement;
270	    u_int16_t mii_full_duplex;
271	    u_int16_t mii_tx_threshold;
272	    u_int16_t mii_interrupt;	/* 21142/21143 */
273	    u_int8_t mii_phyaddr;
274	    u_int8_t mii_gpr_length;
275	    u_int8_t mii_gpr_offset;
276	    u_int8_t mii_reset_length;
277	    u_int8_t mii_reset_offset;
278	    u_int32_t mii_phyid;
279	} un_mii;
280    } mi_un;
281} tulip_media_info_t;
282
283#define	mi_sia_connectivity	mi_un.un_sia.sia_connectivity
284#define	mi_sia_tx_rx		mi_un.un_sia.sia_tx_rx
285#define mi_sia_general		mi_un.un_sia.sia_general
286#define	mi_sia_gp_control	mi_un.un_sia.sia_gp_control
287#define	mi_sia_gp_data		mi_un.un_sia.sia_gp_data
288
289#define	mi_gpcontrol		mi_un.un_gpr.gpr_gpcontrol
290#define	mi_gpdata		mi_un.un_gpr.gpr_gpdata
291#define	mi_actmask		mi_un.un_gpr.gpr_actmask
292#define	mi_actdata		mi_un.un_gpr.gpr_actdata
293#define	mi_default		mi_un.un_gpr.gpr_default
294#define	mi_cmdmode		mi_un.un_gpr.gpr_cmdmode
295
296#define	mi_phyaddr		mi_un.un_mii.mii_phyaddr
297#define	mi_gpr_length		mi_un.un_mii.mii_gpr_length
298#define	mi_gpr_offset		mi_un.un_mii.mii_gpr_offset
299#define	mi_reset_length		mi_un.un_mii.mii_reset_length
300#define	mi_reset_offset		mi_un.un_mii.mii_reset_offset
301#define	mi_capabilities		mi_un.un_mii.mii_capabilities
302#define	mi_advertisement	mi_un.un_mii.mii_advertisement
303#define	mi_full_duplex		mi_un.un_mii.mii_full_duplex
304#define	mi_tx_threshold		mi_un.un_mii.mii_tx_threshold
305#define	mi_mediamask		mi_un.un_mii.mii_mediamask
306#define	mi_mii_interrupt	mi_un.un_mii.mii_interrupt
307#define	mi_phyid		mi_un.un_mii.mii_phyid
308
309#define	TULIP_MEDIAINFO_SIA_INIT(sc, mi, chipid, media) do { \
310    (mi)->mi_type = TULIP_MEDIAINFO_SIA; \
311    sc->tulip_mediums[TULIP_MEDIA_ ## media] = (mi); \
312    (mi)->mi_sia_connectivity = TULIP_ ## chipid ## _SIACONN_ ## media; \
313    (mi)->mi_sia_tx_rx        = TULIP_ ## chipid ## _SIATXRX_ ## media; \
314    (mi)->mi_sia_general      = TULIP_ ## chipid ## _SIAGEN_ ## media; \
315} while (0)
316
317#define TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, media) do {	\
318    if ((sc)->tulip_mediums[TULIP_MEDIA_ ## media] == NULL	\
319	    && ((mi)->mi_capabilities & PHYSTS_ ## media)) {	\
320	(sc)->tulip_mediums[TULIP_MEDIA_ ## media] = (mi);	\
321	(mi)->mi_mediamask |= TULIP_BIT(TULIP_MEDIA_ ## media);	\
322    } \
323} while (0)
324
325#define	TULIP_MII_NOPHY		32
326/*
327 * Some boards need to treated specially.  The following enumeration
328 * identifies the cards with quirks (or those we just want to single
329 * out for special merit or scorn).
330 */
331typedef enum {
332    TULIP_21040_GENERIC,		/* Generic 21040 (works with most any board) */
333    TULIP_21140_ISV,			/* Digital Semicondutor 21140 ISV SROM Format */
334    TULIP_21142_ISV,			/* Digital Semicondutor 21142 ISV SROM Format */
335    TULIP_21143_ISV,			/* Digital Semicondutor 21143 ISV SROM Format */
336    TULIP_21140_DEC_EB,			/* Digital Semicondutor 21140 Evaluation Board */
337    TULIP_21140_MII,			/* 21140[A] with MII */
338    TULIP_21140_DEC_DE500,		/* Digital DE500-?? 10/100 */
339    TULIP_21140_SMC_9332,		/* SMC 9332 */
340    TULIP_21140_COGENT_EM100,		/* Cogent EM100 100 only */
341    TULIP_21140_ZNYX_ZX34X,		/* ZNYX ZX342 10/100 */
342    TULIP_21140_ASANTE,			/* AsanteFast 10/100 */
343    TULIP_21140_EN1207,			/* Accton EN2107 10/100 BNC */
344    TULIP_21041_GENERIC			/* Generic 21041 card */
345} tulip_board_t;
346
347typedef enum {
348    TULIP_MEDIAPOLL_TIMER,		/* 100ms timer fired */
349    TULIP_MEDIAPOLL_FASTTIMER,		/* <100ms timer fired */
350    TULIP_MEDIAPOLL_LINKFAIL,		/* called from interrupt routine */
351    TULIP_MEDIAPOLL_LINKPASS,		/* called from interrupt routine */
352    TULIP_MEDIAPOLL_START,		/* start a media probe (called from reset) */
353    TULIP_MEDIAPOLL_TXPROBE_OK,		/* txprobe succeeded */
354    TULIP_MEDIAPOLL_TXPROBE_FAILED,	/* txprobe failed */
355    TULIP_MEDIAPOLL_MAX
356} tulip_mediapoll_event_t;
357
358typedef enum {
359    TULIP_LINK_DOWN,			/* Link is down */
360    TULIP_LINK_UP,			/* link is ok */
361    TULIP_LINK_UNKNOWN			/* we can't tell either way */
362} tulip_link_status_t;
363
364
365/*
366 * This data structure is used to abstract out the quirks.
367 * media_probe  = tries to determine the media type.
368 * media_select = enables the current media (or autosenses)
369 * media_poll	= autosenses media
370 * media_preset = 21140, etal requires bit to set before the
371 *		  the software reset; hence pre-set.  Should be
372 *		  pre-reset but that's ugly.
373 */
374
375typedef struct {
376    tulip_board_t bd_type;
377    void (*bd_media_probe)(tulip_softc_t * const sc);
378    void (*bd_media_select)(tulip_softc_t * const sc);
379    void (*bd_media_poll)(tulip_softc_t * const sc, tulip_mediapoll_event_t event);
380    void (*bd_media_preset)(tulip_softc_t * const sc);
381} tulip_boardsw_t;
382
383/*
384 * The next few declarations are for MII/PHY based board.
385 *
386 *    The first enumeration identifies a superset of various datums
387 * that can be obtained from various PHY chips.  Not all PHYs will
388 * support all datums.
389 *    The modedata structure indicates what register contains
390 * a datum, what mask is applied the register contents, and what the
391 * result should be.
392 *    The attr structure records information about a supported PHY.
393 *    The phy structure records information about a PHY instance.
394 */
395
396typedef enum {
397    PHY_MODE_10T,
398    PHY_MODE_100TX,
399    PHY_MODE_100T4,
400    PHY_MODE_FULLDUPLEX,
401    PHY_MODE_MAX
402} tulip_phy_mode_t;
403
404typedef struct {
405    u_int16_t pm_regno;
406    u_int16_t pm_mask;
407    u_int16_t pm_value;
408} tulip_phy_modedata_t;
409
410typedef struct {
411    u_int32_t attr_id;
412    u_int16_t attr_flags;
413#define	PHY_NEED_HARD_RESET	0x0001
414#define	PHY_DUAL_CYCLE_TA	0x0002
415    tulip_phy_modedata_t attr_modes[PHY_MODE_MAX];
416#ifdef TULIP_DEBUG
417    const char *attr_name;
418#endif
419} tulip_phy_attr_t;
420
421/*
422 * Various probe states used when trying to autosense the media.
423 */
424
425typedef enum {
426    TULIP_PROBE_INACTIVE,
427    TULIP_PROBE_PHYRESET,
428    TULIP_PROBE_PHYAUTONEG,
429    TULIP_PROBE_GPRTEST,
430    TULIP_PROBE_MEDIATEST,
431    TULIP_PROBE_FAILED
432} tulip_probe_state_t;
433
434typedef struct {
435    /*
436     * Transmit Statistics
437     */
438    u_int32_t dot3StatsSingleCollisionFrames;
439    u_int32_t dot3StatsMultipleCollisionFrames;
440    u_int32_t dot3StatsSQETestErrors;
441    u_int32_t dot3StatsDeferredTransmissions;
442    u_int32_t dot3StatsLateCollisions;
443    u_int32_t dot3StatsExcessiveCollisions;
444    u_int32_t dot3StatsCarrierSenseErrors;
445    u_int32_t dot3StatsInternalMacTransmitErrors;
446    u_int32_t dot3StatsInternalTransmitUnderflows;	/* not in rfc1650! */
447    u_int32_t dot3StatsInternalTransmitBabbles;		/* not in rfc1650! */
448    /*
449     * Receive Statistics
450     */
451    u_int32_t dot3StatsMissedFrames;	/* not in rfc1650! */
452    u_int32_t dot3StatsAlignmentErrors;
453    u_int32_t dot3StatsFCSErrors;
454    u_int32_t dot3StatsFrameTooLongs;
455    u_int32_t dot3StatsInternalMacReceiveErrors;
456} tulip_dot3_stats_t;
457
458/*
459 * Now to important stuff.  This is softc structure (where does softc
460 * come from??? No idea) for the tulip device.
461 *
462 */
463struct _tulip_softc_t {
464    struct device tulip_dev;		/* base device */
465    void *tulip_ih;			/* intrrupt vectoring */
466    void *tulip_ats;			/* shutdown hook */
467
468    bus_space_tag_t tulip_bustag;	/* tag of CSR region being used */
469    bus_space_handle_t tulip_bushandle;	/* handle for CSR region being used */
470    pci_chipset_tag_t tulip_pc;
471    u_int8_t tulip_enaddr[ETHER_ADDR_LEN];
472    struct ifmedia tulip_ifmedia;
473    struct arpcom tulip_ac;
474    struct timeout tulip_ftmo, tulip_stmo;
475    tulip_regfile_t tulip_csrs;
476    u_int32_t tulip_flags;
477#define	TULIP_WANTSETUP		0x00000001
478#define	TULIP_WANTHASHPERFECT	0x00000002
479#define	TULIP_WANTHASHONLY	0x00000004
480#define	TULIP_DOINGSETUP	0x00000008
481#define	TULIP_PRINTMEDIA	0x00000010
482#define	TULIP_TXPROBE_ACTIVE	0x00000020
483#define	TULIP_ALLMULTI		0x00000040
484#define	TULIP_WANTRXACT		0x00000080
485#define	TULIP_RXACT		0x00000100
486#define	TULIP_INRESET		0x00000200
487#define	TULIP_NEEDRESET		0x00000400
488#define	TULIP_SQETEST		0x00000800
489#define	TULIP_FULLDUPLEX	0x00001000
490#define	TULIP_xxxxxx1		0x00002000
491#define	TULIP_WANTTXSTART	0x00004000
492#define	TULIP_NEWTXTHRESH	0x00008000
493#define	TULIP_NOAUTOSENSE	0x00010000
494#define	TULIP_PRINTLINKUP	0x00020000
495#define	TULIP_LINKUP		0x00040000
496#define	TULIP_RXBUFSLOW		0x00080000
497#define	TULIP_NOMESSAGES	0x00100000
498#define	TULIP_SYSTEMERROR	0x00200000
499#define	TULIP_TIMEOUTPENDING	0x00400000
500#define	TULIP_xxxxxx2		0x00800000
501#define	TULIP_TRYNWAY		0x01000000
502#define	TULIP_DIDNWAY		0x02000000
503#define	TULIP_RXIGNORE		0x04000000
504#define	TULIP_PROBE1STPASS	0x08000000
505#define	TULIP_DEVICEPROBE	0x10000000
506#define	TULIP_PROMISC		0x20000000
507#define	TULIP_HASHONLY		0x40000000
508#define	TULIP_xxxxxx3		0x80000000
509    /* only 4 bits left! */
510    u_int32_t tulip_features;	/* static bits indicating features of chip */
511#define	TULIP_HAVE_GPR		0x00000001	/* have gp register (140[A]) */
512#define	TULIP_HAVE_RXBADOVRFLW	0x00000002	/* RX corrupts on overflow */
513#define	TULIP_HAVE_POWERMGMT	0x00000004	/* Snooze/sleep modes */
514#define	TULIP_HAVE_MII		0x00000008	/* Some medium on MII */
515#define	TULIP_HAVE_SIANWAY	0x00000010	/* SIA does NWAY */
516#define	TULIP_HAVE_DUALSENSE	0x00000020	/* SIA senses both AUI & TP */
517#define	TULIP_HAVE_SIAGP	0x00000040	/* SIA has a GP port */
518#define	TULIP_HAVE_BROKEN_HASH	0x00000080	/* Broken Multicast Hash */
519#define	TULIP_HAVE_ISVSROM	0x00000100	/* uses ISV SROM Format */
520#define	TULIP_HAVE_BASEROM	0x00000200	/* Board ROM can be cloned */
521#define	TULIP_HAVE_SLAVEDROM	0x00000400	/* Board ROM cloned */
522#define	TULIP_HAVE_SLAVEDINTR	0x00000800	/* Board slaved interrupt */
523#define	TULIP_HAVE_SHAREDINTR	0x00001000	/* Board shares interrupts */
524#define	TULIP_HAVE_OKROM	0x00002000	/* ROM was recognized */
525#define	TULIP_HAVE_NOMEDIA	0x00004000	/* did not detect any media */
526#define	TULIP_HAVE_STOREFWD	0x00008000	/* have CMD_STOREFWD */
527#define	TULIP_HAVE_SIA100	0x00010000	/* has LS100 in SIA status */
528#define	TULIP_HAVE_OKSROM	0x00020000	/* SROM CRC is OK */
529    u_int32_t tulip_intrmask;	/* our copy of csr_intr */
530    u_int32_t tulip_cmdmode;	/* our copy of csr_cmdmode */
531    u_int32_t tulip_last_system_error : 3;	/* last system error (only value is
532						   TULIP_SYSTEMERROR is also set) */
533    u_int32_t tulip_txtimer : 2;	/* transmission timer */
534    u_int32_t tulip_system_errors;	/* number of system errors encountered */
535    u_int32_t tulip_statusbits;	/* status bits from CSR5 that may need to be printed */
536
537    tulip_media_info_t *tulip_mediums[TULIP_MEDIA_MAX];	/* indexes into mediainfo */
538    tulip_media_t tulip_media;			/* current media type */
539    u_int32_t tulip_abilities;	/* remote system's abiltities (as defined in IEEE 802.3u) */
540
541    u_int8_t tulip_revinfo;			/* revision of chip */
542    u_int8_t tulip_phyaddr;			/* 0..31 -- address of current phy */
543    u_int8_t tulip_gpinit;			/* active pins on 21140 */
544    u_int8_t tulip_gpdata;			/* default gpdata for 21140 */
545
546    struct {
547	u_int8_t probe_count;			/* count of probe operations */
548	int32_t probe_timeout;			/* time in ms of probe timeout */
549	tulip_probe_state_t probe_state;	/* current media probe state */
550	tulip_media_t probe_media;		/* current media being probed */
551	u_int32_t probe_mediamask;		/* medias checked */
552	u_int32_t probe_passes;			/* times autosense failed */
553	u_int32_t probe_txprobes;		/* txprobes attempted */
554    } tulip_probe;
555#define	tulip_probe_count	tulip_probe.probe_count
556#define	tulip_probe_timeout	tulip_probe.probe_timeout
557#define	tulip_probe_state	tulip_probe.probe_state
558#define	tulip_probe_media	tulip_probe.probe_media
559#define	tulip_probe_mediamask	tulip_probe.probe_mediamask
560#define	tulip_probe_passes	tulip_probe.probe_passes
561
562    tulip_chipid_t tulip_chipid;		/* type of chip we are using */
563    const tulip_boardsw_t *tulip_boardsw;	/* board/chip characteristics */
564    tulip_softc_t *tulip_slaves;		/* slaved devices (ZX3xx) */
565#if defined(TULIP_DEBUG)
566    /*
567     * Debugging/Statistical information
568     */
569    struct {
570	tulip_media_t dbg_last_media;
571	u_int32_t dbg_intrs;
572	u_int32_t dbg_media_probes;
573	u_int32_t dbg_txprobe_nocarr;
574	u_int32_t dbg_txprobe_exccoll;
575	u_int32_t dbg_link_downed;
576	u_int32_t dbg_link_suspected;
577	u_int32_t dbg_link_intrs;
578	u_int32_t dbg_link_pollintrs;
579	u_int32_t dbg_link_failures;
580	u_int32_t dbg_nway_starts;
581	u_int32_t dbg_nway_failures;
582	u_int16_t dbg_phyregs[32][4];
583	u_int32_t dbg_rxlowbufs;
584	u_int32_t dbg_rxintrs;
585	u_int32_t dbg_last_rxintrs;
586	u_int32_t dbg_high_rxintrs_hz;
587	u_int32_t dbg_txprobes_ok[TULIP_MEDIA_MAX];
588	u_int32_t dbg_txprobes_failed[TULIP_MEDIA_MAX];
589	u_int32_t dbg_events[TULIP_MEDIAPOLL_MAX];
590	u_int32_t dbg_rxpktsperintr[TULIP_RXDESCS];
591    } tulip_dbg;
592#endif
593#if defined(TULIP_PERFSTATS)
594#define	TULIP_PERF_CURRENT	0
595#define	TULIP_PERF_PREVIOUS	1
596#define	TULIP_PERF_TOTAL	2
597#define	TULIP_PERF_MAX		3
598    struct tulip_perfstats {
599	u_quad_t perf_intr_cycles;
600	u_quad_t perf_ifstart_cycles;
601	u_quad_t perf_ifstart_one_cycles;
602	u_quad_t perf_ifioctl_cycles;
603	u_quad_t perf_ifwatchdog_cycles;
604	u_quad_t perf_timeout_cycles;
605	u_quad_t perf_txput_cycles;
606	u_quad_t perf_txintr_cycles;
607	u_quad_t perf_rxintr_cycles;
608	u_quad_t perf_rxget_cycles;
609	unsigned perf_intr;
610	unsigned perf_ifstart;
611	unsigned perf_ifstart_one;
612	unsigned perf_ifioctl;
613	unsigned perf_ifwatchdog;
614	unsigned perf_timeout;
615	unsigned perf_txput;
616	unsigned perf_txintr;
617	unsigned perf_rxintr;
618	unsigned perf_rxget;
619    } tulip_perfstats[TULIP_PERF_MAX];
620#define	tulip_curperfstats		tulip_perfstats[TULIP_PERF_CURRENT]
621#endif
622    struct ifqueue tulip_txq;
623    struct ifqueue tulip_rxq;
624    tulip_dot3_stats_t tulip_dot3stats;
625    tulip_ringinfo_t tulip_rxinfo;
626    tulip_ringinfo_t tulip_txinfo;
627    tulip_media_info_t tulip_mediainfo[10];
628    /*
629     * The setup buffers for sending the setup frame to the chip.
630     * one is the one being sent while the other is the one being
631     * filled.
632     */
633    u_int32_t tulip_setupbuf[192/sizeof(u_int32_t)];
634    u_int32_t tulip_setupdata[192/sizeof(u_int32_t)];
635    char tulip_boardid[16];		/* buffer for board ID */
636    u_int8_t tulip_rombuf[128];
637    struct device *tulip_pci_busno;	/* needed for multiport boards */
638    u_int8_t tulip_pci_devno;		/* needed for multiport boards */
639    u_int8_t tulip_connidx;
640    tulip_srom_connection_t tulip_conntype;
641    tulip_desc_t tulip_rxdescs[TULIP_RXDESCS];
642    tulip_desc_t tulip_txdescs[TULIP_TXDESCS];
643};
644
645#define	TULIP_DO_AUTOSENSE(sc)	(IFM_SUBTYPE((sc)->tulip_ifmedia.ifm_media) == IFM_AUTO)
646
647#ifdef TULIP_DEBUG
648static const char * const tulip_chipdescs[] = {
649    "21040 [10Mb/s]",
650#if defined(TULIP_EISA)
651    "DE425 [10Mb/s]",
652#else
653    NULL,
654#endif
655    "21041 [10Mb/s]",
656    "21140 [10-100Mb/s]",
657    "21140A [10-100Mb/s]",
658    "21142 [10-100Mb/s]",
659    "21143 [10-100Mb/s]",
660    "82C168 [10-100Mb/s]",
661};
662#endif
663
664#ifdef TULIP_DEBUG
665static const char * const tulip_mediums[] = {
666    "unknown",			/* TULIP_MEDIA_UNKNOWN */
667    "10baseT",			/* TULIP_MEDIA_10BASET */
668    "Full Duplex 10baseT",	/* TULIP_MEDIA_10BASET_FD */
669    "BNC",			/* TULIP_MEDIA_BNC */
670    "AUI",			/* TULIP_MEDIA_AUI */
671    "External SIA",		/* TULIP_MEDIA_EXTSIA */
672    "AUI/BNC",			/* TULIP_MEDIA_AUIBNC */
673    "100baseTX",		/* TULIP_MEDIA_100BASET */
674    "Full Duplex 100baseTX",	/* TULIP_MEDIA_100BASET_FD */
675    "100baseT4",		/* TULIP_MEDIA_100BASET4 */
676    "100baseFX",		/* TULIP_MEDIA_100BASEFX */
677    "Full Duplex 100baseFX",	/* TULIP_MEDIA_100BASEFX_FD */
678};
679#endif
680
681static const int tulip_media_to_ifmedia[] = {
682    IFM_ETHER | IFM_NONE,		/* TULIP_MEDIA_UNKNOWN */
683    IFM_ETHER | IFM_10_T,		/* TULIP_MEDIA_10BASET */
684    IFM_ETHER | IFM_10_T | IFM_FDX,	/* TULIP_MEDIA_10BASET_FD */
685    IFM_ETHER | IFM_10_2,		/* TULIP_MEDIA_BNC */
686    IFM_ETHER | IFM_10_5,		/* TULIP_MEDIA_AUI */
687    IFM_ETHER | IFM_MANUAL,		/* TULIP_MEDIA_EXTSIA */
688    IFM_ETHER | IFM_10_5,		/* TULIP_MEDIA_AUIBNC */
689    IFM_ETHER | IFM_100_TX,		/* TULIP_MEDIA_100BASET */
690    IFM_ETHER | IFM_100_TX | IFM_FDX,	/* TULIP_MEDIA_100BASET_FD */
691    IFM_ETHER | IFM_100_T4,		/* TULIP_MEDIA_100BASET4 */
692    IFM_ETHER | IFM_100_FX,		/* TULIP_MEDIA_100BASEFX */
693    IFM_ETHER | IFM_100_FX | IFM_FDX,	/* TULIP_MEDIA_100BASEFX_FD */
694};
695
696#ifdef TULIP_DEBUG
697static const char * const tulip_system_errors[] = {
698    "parity error",
699    "master abort",
700    "target abort",
701    "reserved #3",
702    "reserved #4",
703    "reserved #5",
704    "reserved #6",
705    "reserved #7",
706};
707
708static const char * const tulip_status_bits[] = {
709    NULL,
710    "transmit process stopped",
711    NULL,
712    "transmit jabber timeout",
713
714    NULL,
715    "transmit underflow",
716    NULL,
717    "receive underflow",
718
719    "receive process stopped",
720    "receive watchdog timeout",
721    NULL,
722    NULL,
723
724    "link failure",
725    NULL,
726    NULL,
727};
728#endif
729
730static const struct {
731    tulip_srom_connection_t sc_type;
732    tulip_media_t sc_media;
733    u_int32_t sc_attrs;
734} tulip_srom_conninfo[] = {
735    { TULIP_SROM_CONNTYPE_10BASET,		TULIP_MEDIA_10BASET },
736    { TULIP_SROM_CONNTYPE_BNC,			TULIP_MEDIA_BNC },
737    { TULIP_SROM_CONNTYPE_AUI,			TULIP_MEDIA_AUI },
738    { TULIP_SROM_CONNTYPE_100BASETX,		TULIP_MEDIA_100BASETX },
739    { TULIP_SROM_CONNTYPE_100BASET4,		TULIP_MEDIA_100BASET4 },
740    { TULIP_SROM_CONNTYPE_100BASEFX,		TULIP_MEDIA_100BASEFX },
741    { TULIP_SROM_CONNTYPE_MII_10BASET,		TULIP_MEDIA_10BASET,
742		TULIP_SROM_ATTR_MII },
743    { TULIP_SROM_CONNTYPE_MII_100BASETX,	TULIP_MEDIA_100BASETX,
744		TULIP_SROM_ATTR_MII },
745    { TULIP_SROM_CONNTYPE_MII_100BASET4,	TULIP_MEDIA_100BASET4,
746		TULIP_SROM_ATTR_MII },
747    { TULIP_SROM_CONNTYPE_MII_100BASEFX,	TULIP_MEDIA_100BASEFX,
748		TULIP_SROM_ATTR_MII },
749    { TULIP_SROM_CONNTYPE_10BASET_NWAY,		TULIP_MEDIA_10BASET,
750		TULIP_SROM_ATTR_NWAY },
751    { TULIP_SROM_CONNTYPE_10BASET_FD,		TULIP_MEDIA_10BASET_FD },
752    { TULIP_SROM_CONNTYPE_MII_10BASET_FD,	TULIP_MEDIA_10BASET_FD,
753		TULIP_SROM_ATTR_MII },
754    { TULIP_SROM_CONNTYPE_100BASETX_FD,		TULIP_MEDIA_100BASETX_FD },
755    { TULIP_SROM_CONNTYPE_MII_100BASETX_FD,	TULIP_MEDIA_100BASETX_FD,
756		TULIP_SROM_ATTR_MII },
757    { TULIP_SROM_CONNTYPE_10BASET_NOLINKPASS,	TULIP_MEDIA_10BASET,
758		TULIP_SROM_ATTR_NOLINKPASS },
759    { TULIP_SROM_CONNTYPE_AUTOSENSE,		TULIP_MEDIA_UNKNOWN,
760		TULIP_SROM_ATTR_AUTOSENSE },
761    { TULIP_SROM_CONNTYPE_AUTOSENSE_POWERUP,	TULIP_MEDIA_UNKNOWN,
762		TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_POWERUP },
763    { TULIP_SROM_CONNTYPE_AUTOSENSE_NWAY,	TULIP_MEDIA_UNKNOWN,
764		TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_NWAY },
765    { TULIP_SROM_CONNTYPE_NOT_USED,		TULIP_MEDIA_UNKNOWN }
766};
767#define	TULIP_SROM_LASTCONNIDX	\
768		(sizeof(tulip_srom_conninfo)/sizeof(tulip_srom_conninfo[0]) - 1)
769
770static const struct {
771    tulip_media_t sm_type;
772    tulip_srom_media_t sm_srom_type;
773} tulip_srom_mediums[] = {
774    { 	TULIP_MEDIA_100BASEFX_FD,	TULIP_SROM_MEDIA_100BASEFX_FD	},
775    {	TULIP_MEDIA_100BASEFX,		TULIP_SROM_MEDIA_100BASEFX	},
776    {	TULIP_MEDIA_100BASET4,		TULIP_SROM_MEDIA_100BASET4	},
777    {	TULIP_MEDIA_100BASETX_FD,	TULIP_SROM_MEDIA_100BASETX_FD	},
778    {	TULIP_MEDIA_100BASETX,		TULIP_SROM_MEDIA_100BASETX	},
779    {	TULIP_MEDIA_10BASET_FD,		TULIP_SROM_MEDIA_10BASET_FD	},
780    {	TULIP_MEDIA_AUI,		TULIP_SROM_MEDIA_AUI		},
781    {	TULIP_MEDIA_BNC,		TULIP_SROM_MEDIA_BNC		},
782    {	TULIP_MEDIA_10BASET,		TULIP_SROM_MEDIA_10BASET	},
783    {	TULIP_MEDIA_UNKNOWN						}
784};
785
786/*
787 * This driver supports a maximum of 32 tulip boards.
788 * This should be enough for the forseeable future.
789 */
790#define	TULIP_MAX_DEVICES	32
791
792typedef void ifnet_ret_t;
793typedef u_long ioctl_cmd_t;
794extern struct cfattach de_ca;
795extern struct cfdriver de_cd;
796#define	TULIP_UNIT_TO_SOFTC(unit)	((tulip_softc_t *) de_cd.cd_devs[unit])
797#define TULIP_IFP_TO_SOFTC(ifp)         ((tulip_softc_t *)((ifp)->if_softc))
798#define	tulip_unit			tulip_dev.dv_unit
799#define tulip_xname                     tulip_dev.dv_cfdata->cf_driver->cd_name
800
801#if NBPFILTER > 0
802#define	TULIP_BPF_MTAP(sc, m)	bpf_mtap((sc)->tulip_if.if_bpf, m)
803#define	TULIP_BPF_TAP(sc, p, l)	bpf_tap((sc)->tulip_if.if_bpf, p, l)
804#define	TULIP_BPF_ATTACH(sc)
805#endif
806
807#define	TULIP_RAISESPL()		splnet()
808#define	TULIP_RAISESOFTSPL()		splsoftnet()
809#define	TULIP_RESTORESPL(s)		splx(s)
810#define	loudprintf			printf
811
812#define	TULIP_PRINTF_FMT		"%s%d"
813#define	TULIP_PRINTF_ARGS		sc->tulip_xname, sc->tulip_unit
814
815#if defined(__alpha__)
816/* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */
817#define TULIP_KVATOPHYS(sc, va)		alpha_XXX_dmamap((vm_offset_t)(va))
818#endif
819
820#define	TULIP_BURSTSIZE(unit)		3
821
822#define	tulip_if	tulip_ac.ac_if
823#define	tulip_name	tulip_if.if_name
824#define	tulip_enaddr	tulip_ac.ac_enaddr
825#define	tulip_multicnt	tulip_ac.ac_multicnt
826
827#define	tulip_bpf	tulip_if.if_bpf
828
829#define	tulip_intrfunc_t	int
830
831#if !defined(TULIP_KVATOPHYS)
832#define	TULIP_KVATOPHYS(sc, va)	vtophys((vaddr_t)va)
833#endif
834
835#if defined(TULIP_PERFSTATS)
836#define	TULIP_PERFMERGE(sc, member) \
837	do { (sc)->tulip_perfstats[TULIP_PERF_TOTAL].member \
838	     += (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \
839	 (sc)->tulip_perfstats[TULIP_PERF_PREVIOUS].member \
840	      = (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \
841	    (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member = 0; } while (0)
842#define	TULIP_PERFSTART(name) const tulip_cycle_t perfstart_ ## name = TULIP_PERFREAD();
843#define	TULIP_PERFEND(name)	do { \
844	    (sc)->tulip_curperfstats.perf_ ## name ## _cycles += TULIP_PERFDIFF(perfstart_ ## name, TULIP_PERFREAD()); \
845	    (sc)->tulip_curperfstats.perf_ ## name++; \
846	} while (0)
847#if defined(__i386__)
848typedef u_quad_t tulip_cycle_t;
849static __inline__ tulip_cycle_t
850TULIP_PERFREAD(
851    void)
852{
853    tulip_cycle_t x;
854    __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
855    return x;
856}
857#define	TULIP_PERFDIFF(s, f)	((f) - (s))
858#elif defined(__alpha__)
859typedef unsigned long tulip_cycle_t;
860static __inline__ tulip_cycle_t
861TULIP_PERFREAD(
862    void)
863{
864    tulip_cycle_t x;
865    __asm__ volatile ("rpcc %0" : "=r" (x));
866    return x;
867}
868#define	TULIP_PERFDIFF(s, f)	((unsigned int) ((f) - (s)))
869#endif
870#else
871#define	TULIP_PERFSTART(name)
872#define	TULIP_PERFEND(name)	do { } while (0)
873#define	TULIP_PERFMERGE(s,n)	do { } while (0)
874#endif /* TULIP_PERFSTATS */
875
876#define	TULIP_EADDR_FMT		"%s"
877#define	TULIP_EADDR_ARGS(addr)	ether_sprintf(addr)
878
879#define	TULIP_CRC32_POLY	0xEDB88320UL	/* CRC-32 Poly -- Little Endian */
880#define	TULIP_MAX_TXSEG		30
881
882#define	TULIP_ADDREQUAL(a1, a2) \
883	(((u_int16_t *)a1)[0] == ((u_int16_t *)a2)[0] \
884	 && ((u_int16_t *)a1)[1] == ((u_int16_t *)a2)[1] \
885	 && ((u_int16_t *)a1)[2] == ((u_int16_t *)a2)[2])
886#define	TULIP_ADDRBRDCST(a1) \
887	(((u_int16_t *)a1)[0] == 0xFFFFU \
888	 && ((u_int16_t *)a1)[1] == 0xFFFFU \
889	 && ((u_int16_t *)a1)[2] == 0xFFFFU)
890
891typedef int tulip_spl_t;
892