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