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