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