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