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