xref: /titanic_52/usr/src/uts/sun/io/eri/eri.h (revision bd78278b44cf0dd342373c15544ad2be9fdb6807)
1297a64e7Sgd78059 /*
2297a64e7Sgd78059  * CDDL HEADER START
3297a64e7Sgd78059  *
4297a64e7Sgd78059  * The contents of this file are subject to the terms of the
5297a64e7Sgd78059  * Common Development and Distribution License (the "License").
6297a64e7Sgd78059  * You may not use this file except in compliance with the License.
7297a64e7Sgd78059  *
8297a64e7Sgd78059  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9297a64e7Sgd78059  * or http://www.opensolaris.org/os/licensing.
10297a64e7Sgd78059  * See the License for the specific language governing permissions
11297a64e7Sgd78059  * and limitations under the License.
12297a64e7Sgd78059  *
13297a64e7Sgd78059  * When distributing Covered Code, include this CDDL HEADER in each
14297a64e7Sgd78059  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15297a64e7Sgd78059  * If applicable, add the following below this CDDL HEADER, with the
16297a64e7Sgd78059  * fields enclosed by brackets "[]" replaced with your own identifying
17297a64e7Sgd78059  * information: Portions Copyright [yyyy] [name of copyright owner]
18297a64e7Sgd78059  *
19297a64e7Sgd78059  * CDDL HEADER END
20297a64e7Sgd78059  */
21297a64e7Sgd78059 /*
22*bd78278bSGarrett D'Amore  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23297a64e7Sgd78059  * Use is subject to license terms.
24297a64e7Sgd78059  */
25297a64e7Sgd78059 
26297a64e7Sgd78059 #ifndef	_SYS_ERI_H
27297a64e7Sgd78059 #define	_SYS_ERI_H
28297a64e7Sgd78059 
29297a64e7Sgd78059 #ifdef	__cplusplus
30297a64e7Sgd78059 extern "C" {
31297a64e7Sgd78059 #endif
32297a64e7Sgd78059 
33297a64e7Sgd78059 
34297a64e7Sgd78059 #ifdef _KERNEL
35297a64e7Sgd78059 
36297a64e7Sgd78059 /* Named Dispatch Parameter Management Structure */
37297a64e7Sgd78059 typedef struct param_s {
38297a64e7Sgd78059 	uint32_t param_min;
39297a64e7Sgd78059 	uint32_t param_max;
40297a64e7Sgd78059 	uint32_t param_val;
41297a64e7Sgd78059 	char   *param_name;
42297a64e7Sgd78059 } param_t;
43297a64e7Sgd78059 
44297a64e7Sgd78059 #define	ERI_PARAM_CNT	51
45297a64e7Sgd78059 
46297a64e7Sgd78059 typedef enum  {
47297a64e7Sgd78059 	MIF_POLL_STOP,
48297a64e7Sgd78059 	MIF_POLL_START
49297a64e7Sgd78059 } soft_mif_enable_t;
50297a64e7Sgd78059 
51297a64e7Sgd78059 
52297a64e7Sgd78059 /*
53297a64e7Sgd78059  * kstats
54297a64e7Sgd78059  */
55297a64e7Sgd78059 typedef struct stats {
56297a64e7Sgd78059 	/*
57297a64e7Sgd78059 	 * Link Input/Output stats
58297a64e7Sgd78059 	 * ifspeed is now in bits/second.
59297a64e7Sgd78059 	 */
60297a64e7Sgd78059 	uint64_t	ipackets64;
61297a64e7Sgd78059 	uint64_t	iipackets64;
62297a64e7Sgd78059 	uint32_t	ierrors;
63297a64e7Sgd78059 	uint64_t	opackets64;
64297a64e7Sgd78059 	uint64_t	oerrors;
65297a64e7Sgd78059 	uint32_t	collisions;
66297a64e7Sgd78059 	uint64_t	ifspeed;
67297a64e7Sgd78059 
68297a64e7Sgd78059 	/*
69297a64e7Sgd78059 	 * MAC TX Event stats
70297a64e7Sgd78059 	 */
71297a64e7Sgd78059 	uint32_t	txmac_urun;
72297a64e7Sgd78059 	uint32_t	txmac_maxpkt_err;
73297a64e7Sgd78059 	uint32_t	excessive_coll;
74297a64e7Sgd78059 	uint32_t	late_coll;
75297a64e7Sgd78059 	uint32_t	first_coll;
76297a64e7Sgd78059 	uint32_t	defer_timer_exp;
77297a64e7Sgd78059 	uint32_t	peak_attempt_cnt;
78297a64e7Sgd78059 	uint32_t	tx_hang;
79297a64e7Sgd78059 
80297a64e7Sgd78059 	/*
81297a64e7Sgd78059 	 * MAC RX Event stats
82297a64e7Sgd78059 	 */
83297a64e7Sgd78059 	uint32_t	rx_corr;
84297a64e7Sgd78059 	uint32_t	no_free_rx_desc;	/* no free rx desc. */
85297a64e7Sgd78059 	uint32_t	rx_overflow;
86297a64e7Sgd78059 	uint32_t	rx_ovrflpkts;
87297a64e7Sgd78059 	uint32_t	rx_hang;
88297a64e7Sgd78059 	uint32_t	rx_align_err;
89297a64e7Sgd78059 	uint32_t	rx_crc_err;
90297a64e7Sgd78059 	uint32_t	rx_length_err;
91297a64e7Sgd78059 	uint32_t	rx_code_viol_err;
92297a64e7Sgd78059 
93297a64e7Sgd78059 	/*
94297a64e7Sgd78059 	 * MAC Control event stats
95297a64e7Sgd78059 	 */
96297a64e7Sgd78059 	uint32_t	pause_rxcount;	/* PAUSE Receive cnt */
97297a64e7Sgd78059 	uint32_t	pause_oncount;
98297a64e7Sgd78059 	uint32_t	pause_offcount;
99297a64e7Sgd78059 	uint32_t	pause_time_count;
100297a64e7Sgd78059 	uint32_t	pausing;
101297a64e7Sgd78059 
102297a64e7Sgd78059 	/*
103297a64e7Sgd78059 	 * Software event stats
104297a64e7Sgd78059 	 */
105297a64e7Sgd78059 	uint32_t	inits;
106297a64e7Sgd78059 	uint32_t	rx_inits;
107297a64e7Sgd78059 	uint32_t	tx_inits;
108297a64e7Sgd78059 	uint32_t	tnocar;	/* Link down counter */
109297a64e7Sgd78059 
110297a64e7Sgd78059 	uint32_t	jab;
111297a64e7Sgd78059 	uint32_t	notmds;
112297a64e7Sgd78059 	uint32_t	nocanput;
113297a64e7Sgd78059 	uint32_t	allocbfail;
114297a64e7Sgd78059 	uint32_t	drop;
115297a64e7Sgd78059 	uint32_t	rx_corrupted;
116297a64e7Sgd78059 	uint32_t	rx_bad_pkts;
117297a64e7Sgd78059 	uint32_t	rx_runt;
118297a64e7Sgd78059 	uint32_t	rx_toolong_pkts;
119297a64e7Sgd78059 
120297a64e7Sgd78059 
121297a64e7Sgd78059 	/*
122297a64e7Sgd78059 	 * Fatal errors
123297a64e7Sgd78059 	 */
124297a64e7Sgd78059 	uint32_t	rxtag_err;
125297a64e7Sgd78059 
126297a64e7Sgd78059 	/*
127297a64e7Sgd78059 	 * parity error
128297a64e7Sgd78059 	 */
129297a64e7Sgd78059 	uint32_t	parity_error;
130297a64e7Sgd78059 
131297a64e7Sgd78059 	/*
132297a64e7Sgd78059 	 * Fatal error stats
133297a64e7Sgd78059 	 */
134297a64e7Sgd78059 	uint32_t	pci_error_int;	/* PCI error interrupt */
135297a64e7Sgd78059 	uint32_t	unknown_fatal;	/* unknown fatal errors */
136297a64e7Sgd78059 
137297a64e7Sgd78059 	/*
138297a64e7Sgd78059 	 * PCI Configuration space staus register
139297a64e7Sgd78059 	 */
140297a64e7Sgd78059 	uint32_t	pci_data_parity_err;	/* Data parity err */
141297a64e7Sgd78059 	uint32_t	pci_signal_target_abort;
142297a64e7Sgd78059 	uint32_t	pci_rcvd_target_abort;
143297a64e7Sgd78059 	uint32_t	pci_rcvd_master_abort;
144297a64e7Sgd78059 	uint32_t	pci_signal_system_err;
145297a64e7Sgd78059 	uint32_t	pci_det_parity_err;
146297a64e7Sgd78059 
147297a64e7Sgd78059 	/*
148297a64e7Sgd78059 	 * MIB II variables
149297a64e7Sgd78059 	 */
150297a64e7Sgd78059 	uint64_t	rbytes64;	/* # bytes received */
151297a64e7Sgd78059 	uint64_t	obytes64;	/* # bytes transmitted */
152297a64e7Sgd78059 	uint32_t	multircv;	/* # multicast packets received */
153297a64e7Sgd78059 	uint32_t	multixmt;	/* # multicast packets for xmit */
154297a64e7Sgd78059 	uint32_t	brdcstrcv;	/* # broadcast packets received */
155297a64e7Sgd78059 	uint32_t	brdcstxmt;	/* # broadcast packets for xmit */
156297a64e7Sgd78059 	uint32_t	norcvbuf;	/* # rcv packets discarded */
157297a64e7Sgd78059 	uint32_t	noxmtbuf;	/* # xmit packets discarded */
158297a64e7Sgd78059 
159297a64e7Sgd78059 	uint32_t	pmcap;		/* power management */
160297a64e7Sgd78059 
161297a64e7Sgd78059 	/*
162297a64e7Sgd78059 	 * Link Status
163297a64e7Sgd78059 	 */
164297a64e7Sgd78059 	uint32_t	link_up;
165297a64e7Sgd78059 	uint32_t	link_duplex;
166297a64e7Sgd78059 } stats_t;
167297a64e7Sgd78059 
168297a64e7Sgd78059 #define	HSTAT(erip, x)		erip->stats.x++;
169297a64e7Sgd78059 #define	HSTATN(erip, x, n)	erip->stats.x += n;
170297a64e7Sgd78059 
171297a64e7Sgd78059 
172297a64e7Sgd78059 #define	RX_BCOPY_MAX		704	/* bcopy for packets < 704 bytes */
173297a64e7Sgd78059 
174297a64e7Sgd78059 /*
175297a64e7Sgd78059  * Per-Stream instance state information.
176297a64e7Sgd78059  *
177297a64e7Sgd78059  * Each instance is dynamically allocated at open() and free'd
178297a64e7Sgd78059  * at close().  Each per-Stream instance points to at most one
179297a64e7Sgd78059  * per-device structure using the sb_erip field.  All instances
180297a64e7Sgd78059  * are threaded together into one list of active instances
181297a64e7Sgd78059  * ordered on minor device number.
182297a64e7Sgd78059  */
183297a64e7Sgd78059 
184297a64e7Sgd78059 #define	NMCFILTER_BITS	256		/* # of multicast filter bits */
185297a64e7Sgd78059 
186297a64e7Sgd78059 
187297a64e7Sgd78059 /*
188297a64e7Sgd78059  * Maximum number of receive descriptors posted to the chip.
189297a64e7Sgd78059  */
190297a64e7Sgd78059 #define	ERI_RPENDING		(erip->rpending)
191297a64e7Sgd78059 
192297a64e7Sgd78059 /*
193297a64e7Sgd78059  * Maximum number of transmit descriptors for lazy reclaim.
194297a64e7Sgd78059  */
195297a64e7Sgd78059 #define	ERI_TPENDING	(erip->tpending)
196297a64e7Sgd78059 
197297a64e7Sgd78059 /*
198297a64e7Sgd78059  * Return the address of an adjacent descriptor in the given ring.
199297a64e7Sgd78059  */
200297a64e7Sgd78059 #define	NEXTRMD(erip, rmdp)	(((rmdp) + 1) == (erip)->rmdlimp ?	\
201297a64e7Sgd78059 	(erip)->rmdp : ((rmdp) + 1))
202297a64e7Sgd78059 #define	NEXTTMD(erip, tmdp)	(((tmdp) + 1) == (erip)->eri_tmdlimp ?	\
203297a64e7Sgd78059 	(erip)->eri_tmdp : ((tmdp) + 1))
204297a64e7Sgd78059 #define	PREVTMD(erip, tmdp)	((tmdp) == (erip)->eri_tmdp ?		\
205297a64e7Sgd78059 	((erip)->eri_tmdlimp - 1) : ((tmdp) - 1))
206297a64e7Sgd78059 
207297a64e7Sgd78059 #define	MSECOND(t)	t
208297a64e7Sgd78059 #define	SECOND(t)	t*1000
209297a64e7Sgd78059 #define	ERI_TICKS	MSECOND(100)
210297a64e7Sgd78059 
211297a64e7Sgd78059 #define	ERI_NTRIES_LOW		(SECOND(5)/ERI_TICKS)   /* 5 Seconds */
212297a64e7Sgd78059 #define	ERI_NTRIES_HIGH		(SECOND(5)/ERI_TICKS)   /* 5 Seconds */
213297a64e7Sgd78059 #define	ERI_NTRIES_LOW_10	(SECOND(2)/ERI_TICKS)   /* 2 Seconds */
214297a64e7Sgd78059 #define	ERI_LINKDOWN_TIME	(SECOND(2)/ERI_TICKS)   /* 2 Seconds */
215297a64e7Sgd78059 
216297a64e7Sgd78059 
217297a64e7Sgd78059 /*
218297a64e7Sgd78059  * ERI ASIC Revision Numbers
219297a64e7Sgd78059  */
220297a64e7Sgd78059 #define	ERI_ERIREV_1_0	0x1
221297a64e7Sgd78059 
222297a64e7Sgd78059 /*
223297a64e7Sgd78059  * Link poll interval for detecting change of transceivers
224297a64e7Sgd78059  */
225297a64e7Sgd78059 #define	ERI_LINKCHECK_TIMER	SECOND(3)
226297a64e7Sgd78059 
227297a64e7Sgd78059 /*
228297a64e7Sgd78059  * Parallel detection Fault restart timer
229297a64e7Sgd78059  */
230297a64e7Sgd78059 #define	ERI_P_FAULT_TIMER	SECOND(3)
231297a64e7Sgd78059 
232297a64e7Sgd78059 /*
233297a64e7Sgd78059  * Check rmac hang restart timer
234297a64e7Sgd78059  */
235297a64e7Sgd78059 #define	ERI_CHECK_HANG_TIMER	MSECOND(400)
236297a64e7Sgd78059 #define	ERI_RMAC_HANG_WORKAROUND
237297a64e7Sgd78059 
238297a64e7Sgd78059 /*
239297a64e7Sgd78059  * undefine ERI_PM_WORKAROUND this time. With ERI_PM_WORKAROUND defined,
240297a64e7Sgd78059  * each non_fatal error causes pci clock to go up for 30 seconds. Therefore,
241297a64e7Sgd78059  * no TXMAC_UNDERRUN or excessive RXFIFO_OVERFLOW should happen.
242297a64e7Sgd78059  */
243297a64e7Sgd78059 
244297a64e7Sgd78059 
245297a64e7Sgd78059 /*
246297a64e7Sgd78059  * Link bringup modes
247297a64e7Sgd78059  */
248297a64e7Sgd78059 #define	ERI_AUTO_BRINGUP	0
249297a64e7Sgd78059 #define	ERI_FORCED_BRINGUP	1
250297a64e7Sgd78059 
251297a64e7Sgd78059 /*
252297a64e7Sgd78059  * Transceivers selected for use by the driver.
253297a64e7Sgd78059  */
254297a64e7Sgd78059 #define	NO_XCVR		2
255297a64e7Sgd78059 #define	INTERNAL_XCVR	0
256297a64e7Sgd78059 #define	EXTERNAL_XCVR	1
257297a64e7Sgd78059 
258297a64e7Sgd78059 /*
259297a64e7Sgd78059  * states for manually creating the link down condition
260297a64e7Sgd78059  */
261297a64e7Sgd78059 #define	ERI_LINKDOWN_OK		0
262297a64e7Sgd78059 #define	ERI_FORCE_LINKDOWN	1
263297a64e7Sgd78059 #define	ERI_LINKDOWN_STARTED	2
264297a64e7Sgd78059 #define	ERI_LINKDOWN_DONE	3
265297a64e7Sgd78059 
266297a64e7Sgd78059 /*
267297a64e7Sgd78059  * states for bringing up the link in auto-negotiation mode
268297a64e7Sgd78059  */
269297a64e7Sgd78059 #define	ERI_HWAN_TRY		0 /* Try Hardware autonegotiation */
270297a64e7Sgd78059 #define	ERI_HWAN_INPROGRESS	1 /* Hardware autonegotiation in progress */
271297a64e7Sgd78059 #define	ERI_HWAN_SUCCESFUL	2 /* Hardware autonegotiation succesful */
272297a64e7Sgd78059 #define	ERI_HWAN_FAILED		3 /* Hardware autonegotiation failed */
273297a64e7Sgd78059 
274297a64e7Sgd78059 /*
275297a64e7Sgd78059  * states for resetting the transceiver
276297a64e7Sgd78059  */
277297a64e7Sgd78059 #define	RESET_TO_BE_ISSUED	0 /* Reset command to be issued to the PHY */
278297a64e7Sgd78059 #define	RESET_ISSUED		1 /* Reset command has been issued */
279297a64e7Sgd78059 #define	ISOLATE_ISSUED		2 /* Isolate-remove command has been issued */
280297a64e7Sgd78059 
281297a64e7Sgd78059 /*
282297a64e7Sgd78059  * ERI Supported PHY devices
283297a64e7Sgd78059  * ERI ASIC supports a built in Gigabit Serial LInk Interface and MII
284297a64e7Sgd78059  * External SERDES interfaces with shared pins.
285297a64e7Sgd78059  * On some product implementations, the built-in Serial Link may not be present
286297a64e7Sgd78059  * either because the Serial Link circuitry does not work or because the product
287297a64e7Sgd78059  * needs to use only the MII interface.
288297a64e7Sgd78059  * When both the Serial Link and MII PHY's are present, the driver normally
289297a64e7Sgd78059  * tries to bring up both the links. If both of them come up, it will select the
290297a64e7Sgd78059  * link defined by the "eri_default_link" variable by default.
291297a64e7Sgd78059  * The user may use the configuration variable
292297a64e7Sgd78059  * eri_select_link to manually select
293297a64e7Sgd78059  * either the Serial Link or the MII PHY to be used.
294297a64e7Sgd78059  */
295297a64e7Sgd78059 
296297a64e7Sgd78059 /*
297297a64e7Sgd78059  * Values for the eri_serial_link field
298297a64e7Sgd78059  */
299297a64e7Sgd78059 #define	ERI_SERIAL_LINK_NOT_PRESENT	0
300297a64e7Sgd78059 #define	ERI_SERIAL_LINK_PRESENT		1
301297a64e7Sgd78059 
302297a64e7Sgd78059 /*
303297a64e7Sgd78059  * Values for the eri_non-serial-link field
304297a64e7Sgd78059  */
305297a64e7Sgd78059 #define	ERI_NO_SHARED_PIN_PHY		0
306297a64e7Sgd78059 #define	ERI_MII_PRESENT			1
307297a64e7Sgd78059 #define	ERI_SERDES_PRESENT		2
308297a64e7Sgd78059 
309297a64e7Sgd78059 /*
310297a64e7Sgd78059  * Values for the default selection when both the serial link and
311297a64e7Sgd78059  * the MII links are present.
312297a64e7Sgd78059  */
313297a64e7Sgd78059 #define	ERI_DEFAULT_SERIAL_LINK	0
314297a64e7Sgd78059 #define	ERI_DEFAULT_MII_LINK	1
315297a64e7Sgd78059 
316297a64e7Sgd78059 /*
317297a64e7Sgd78059  * Values for the eri_select_link field to manually select the PHY
318297a64e7Sgd78059  */
319297a64e7Sgd78059 #define	ERI_AUTO_PHY			0	/* Select PHY automatically */
320297a64e7Sgd78059 #define	ERI_USE_SERIAL_LINK		1	/* Select serial-link */
321297a64e7Sgd78059 #define	ERI_USE_NON_SERIAL_LINK		2	/* Select non-serial-link */
322297a64e7Sgd78059 
323297a64e7Sgd78059 /*
324297a64e7Sgd78059  * eri_linkup_state" definitions
325297a64e7Sgd78059  */
326297a64e7Sgd78059 #define	ERI_START_LINK_BRINGUP	0
327297a64e7Sgd78059 #define	ERI_SERIAL_LINK_BRINGUP	1
328297a64e7Sgd78059 #define	ERI_SERDES_LINK_BRINGUP	2
329297a64e7Sgd78059 #define	ERI_MII_LINK_BRINGUP	3
330297a64e7Sgd78059 #define	ERI_DEFAULT_LINK_BRINGUP	4
331297a64e7Sgd78059 #define	ERI_ALT_LINK_BRINGUP	5
332297a64e7Sgd78059 
333297a64e7Sgd78059 /*
334297a64e7Sgd78059  * structure used to detect tx hang condition
335297a64e7Sgd78059  */
336297a64e7Sgd78059 struct	erisave {
337297a64e7Sgd78059 	ulong_t	starts;		  /* # of tx packets posted to the hw */
338297a64e7Sgd78059 	uint64_t reclaim_opackets; /* # of tx packets reclaimed */
339297a64e7Sgd78059 };
340297a64e7Sgd78059 
341297a64e7Sgd78059 /*
342297a64e7Sgd78059  * ERI Device Channel instance state information.
343297a64e7Sgd78059  *
344297a64e7Sgd78059  * Each instance is dynamically allocated on first attach.
345297a64e7Sgd78059  */
346297a64e7Sgd78059 struct	eri {
347297a64e7Sgd78059 	mac_handle_t		mh;		/* GLDv3 handle */
348297a64e7Sgd78059 	dev_info_t		*dip;		/* associated dev_info */
349297a64e7Sgd78059 	uint_t			instance;	/* instance */
350297a64e7Sgd78059 
351297a64e7Sgd78059 	int			pci_mode;	/* sbus/pci device (future) */
352297a64e7Sgd78059 	int			cpci_mode;	/* compact pci dev (future) */
353297a64e7Sgd78059 	int			low_power_mode; /* E* (low power) */
354297a64e7Sgd78059 	int			asic_rev;	/* ERI ASIC rev no. */
355297a64e7Sgd78059 	int			board_rev;	/* ERI ASIC rev no. */
356297a64e7Sgd78059 	int			burstsizes;	/* binary encoded val */
357297a64e7Sgd78059 	int			pagesize;	/* btop(9f) */
358297a64e7Sgd78059 	uint32_t		rxfifo_size;	/* RX FIFO size */
359297a64e7Sgd78059 
360297a64e7Sgd78059 	int			rpending;	/* Max.no. of RX bufs post */
361297a64e7Sgd78059 	int			tpending;	/* Max.no. of tX bufs post */
362297a64e7Sgd78059 	int			tx_cur_cnt;	/* # of packets for int_me */
363297a64e7Sgd78059 
364297a64e7Sgd78059 	uint_t			multi_refcnt;
365297a64e7Sgd78059 	boolean_t		promisc;
366297a64e7Sgd78059 
367297a64e7Sgd78059 	int			mifpoll_enable;
368297a64e7Sgd78059 	int			frame_enable;
369297a64e7Sgd78059 	int			lance_mode_enable;
370297a64e7Sgd78059 	int			ngu_enable;
371297a64e7Sgd78059 	int			link_pulse_disabled;
372297a64e7Sgd78059 	int			xmit_dma_mode;
373297a64e7Sgd78059 	int			rcv_dma_mode;
374297a64e7Sgd78059 	uint8_t			ouraddr[ETHERADDRL];	/* unicast address */
375297a64e7Sgd78059 	uint32_t		flags;		/* misc. flags */
376297a64e7Sgd78059 	uint32_t		alloc_flag;	/* Buff alloc. status flags */
377297a64e7Sgd78059 	boolean_t		wantw;		/* xmit: out of resources */
378297a64e7Sgd78059 
379297a64e7Sgd78059 	uint16_t		ladrf[NMCFILTER_BITS/16]; /* Multicast filter */
380297a64e7Sgd78059 	uint16_t		ladrf_refcnt[NMCFILTER_BITS];
381297a64e7Sgd78059 
382297a64e7Sgd78059 	volatile struct	global	*globregp;	/* ERI global regs */
383297a64e7Sgd78059 	volatile struct	etx	*etxregp;	/* ERI ETX regs */
384297a64e7Sgd78059 	volatile struct	erx	*erxregp;	/* ERI ERX regs */
385297a64e7Sgd78059 
386297a64e7Sgd78059 	volatile struct	bmac	*bmacregp;	/* MAC regs */
387297a64e7Sgd78059 	volatile struct	mif	*mifregp;	/* ERI transceiver */
388297a64e7Sgd78059 	volatile struct	pcslink	*pcsregp;	/* ERI PCS regs */
389297a64e7Sgd78059 
390297a64e7Sgd78059 	uint32_t		*sw_reset_reg;
391297a64e7Sgd78059 
392297a64e7Sgd78059 	uint32_t		rx_kick;	/* RX kick register val */
393297a64e7Sgd78059 	uint32_t		rx_completion;	/* RX completion reg val */
394297a64e7Sgd78059 #ifdef	RCV_OVRFLOW_CORRUPTION_BUG
395297a64e7Sgd78059 	uint32_t		rx_ovrflpks;	/* RX recompute checksum */
396297a64e7Sgd78059 #endif
397297a64e7Sgd78059 	uint32_t		tx_kick;	/* TX kick register val */
398297a64e7Sgd78059 	uint32_t		tx_completion;	/* TX completion reg val */
399297a64e7Sgd78059 
400297a64e7Sgd78059 	struct	rmd		*rmdp;		/* rcv descript  ring start */
401297a64e7Sgd78059 	struct	rmd		*rmdlimp;	/* rcv  descript ring end */
402297a64e7Sgd78059 	struct	eri_tmd		*eri_tmdp;	/* xmit descript ring start */
403297a64e7Sgd78059 	struct	eri_tmd		*eri_tmdlimp;	/* xmit descript ring end */
404297a64e7Sgd78059 	volatile struct	rmd	*rnextp;	/* next chip rmd */
405297a64e7Sgd78059 	volatile struct	rmd	*rlastp;	/* last free rmd */
406297a64e7Sgd78059 	volatile struct	eri_tmd	*tnextp;	/* next free tmd */
407297a64e7Sgd78059 
408297a64e7Sgd78059 	volatile struct	eri_tmd	*tcurp;	/* nxt tmd to reclaim(used) */
409297a64e7Sgd78059 	/*
410297a64e7Sgd78059 	 * these are handles for the dvma resources reserved
411297a64e7Sgd78059 	 * by dvma_reserve
412297a64e7Sgd78059 	 */
413297a64e7Sgd78059 	ddi_dma_handle_t	eri_dvmarh;	/* dvma recv handle */
414297a64e7Sgd78059 
415297a64e7Sgd78059 	/*
416297a64e7Sgd78059 	 * these are used if dvma reserve fails, and we have to fall
417297a64e7Sgd78059 	 * back on the older ddi_dma_addr_setup routines
418297a64e7Sgd78059 	 */
419297a64e7Sgd78059 	ddi_dma_handle_t	ndmarh[ERI_RMDMAX];
420297a64e7Sgd78059 
421297a64e7Sgd78059 	ddi_dma_handle_t	tbuf_handle;
422*bd78278bSGarrett D'Amore 	ddi_acc_handle_t	tbuf_acch;
423297a64e7Sgd78059 	caddr_t			tbuf_kaddr;
424297a64e7Sgd78059 	uint32_t		tbuf_ioaddr;
425297a64e7Sgd78059 
426297a64e7Sgd78059 	int			rcv_handle_cnt;
427297a64e7Sgd78059 
428297a64e7Sgd78059 	int			rx_reset_issued;
429297a64e7Sgd78059 	int			tx_reset_issued;
430297a64e7Sgd78059 	int			rxmac_reset_issued;
431297a64e7Sgd78059 	int			txmac_reset_issued;
432297a64e7Sgd78059 
433297a64e7Sgd78059 	int			global_reset_issued;
434297a64e7Sgd78059 	uint32_t		rpending_mask;
435297a64e7Sgd78059 	int			rmdmax_mask;
436297a64e7Sgd78059 	int			init_macregs;
437297a64e7Sgd78059 
438297a64e7Sgd78059 	int			phyad;	/* addr of the PHY in use */
439297a64e7Sgd78059 	int			xcvr;  /* current PHY in use */
440297a64e7Sgd78059 
441297a64e7Sgd78059 	int			openloop_autoneg;
442297a64e7Sgd78059 
443297a64e7Sgd78059 	uint16_t		mif_config;
444297a64e7Sgd78059 	uint16_t		mif_mask;
445297a64e7Sgd78059 
446297a64e7Sgd78059 	uint32_t		tx_config;
447297a64e7Sgd78059 
448297a64e7Sgd78059 	uint32_t		vendor_id;	/* Vendor ID	*/
449297a64e7Sgd78059 	uint16_t		device_id;	/* Device Model	*/
450297a64e7Sgd78059 	uint16_t		device_rev;	/* Device Rev.	*/
451297a64e7Sgd78059 	uint32_t		phy_address;	/* PHY Address	*/
452297a64e7Sgd78059 	uint32_t		xcvr_status;	/* xcvr_status	*/
453297a64e7Sgd78059 	uint32_t		xcvr_state;	/* xcvr_state	*/
454297a64e7Sgd78059 	uint32_t		bringup_mode;	/* Bringup Mode	*/
455297a64e7Sgd78059 	uint32_t		speed;		/* Current speed */
456297a64e7Sgd78059 	uint32_t		duplex;		/* Xcvr Duplex	*/
457297a64e7Sgd78059 	uint32_t		capability;	/* Xcvr Capability */
458297a64e7Sgd78059 
459297a64e7Sgd78059 	uint16_t		mii_control;
460297a64e7Sgd78059 	uint16_t		mii_status;
461297a64e7Sgd78059 	uint16_t		mii_anar;
462297a64e7Sgd78059 	uint16_t		mii_lpanar;
463297a64e7Sgd78059 
464297a64e7Sgd78059 	int			autoneg;
465297a64e7Sgd78059 	int			force_linkdown;
466297a64e7Sgd78059 	int			mode;
467297a64e7Sgd78059 
468297a64e7Sgd78059 	int			linkup_10;
469297a64e7Sgd78059 	int			pace_count;	/* pacing pkt count */
470297a64e7Sgd78059 
471297a64e7Sgd78059 	int			nlasttries;
472297a64e7Sgd78059 	int			ntries;
473297a64e7Sgd78059 	int			delay;
474297a64e7Sgd78059 	int			linkup_attempts;
475297a64e7Sgd78059 
476297a64e7Sgd78059 	int			polling_on;
477297a64e7Sgd78059 	int			mifpoll_data;
478297a64e7Sgd78059 	int			mifpoll_flag; /* indicates MIF intr */
479297a64e7Sgd78059 
480297a64e7Sgd78059 	int			pauseTX;	/* pcs link-pause TX enable */
481297a64e7Sgd78059 	int			pauseRX;	/* pcs link-pause RX enable */
482297a64e7Sgd78059 	int			macfdx;	/* mac full-duplex mode */
483297a64e7Sgd78059 	timeout_id_t		timerid;	/* timer id for links */
484297a64e7Sgd78059 	int			linkup_cnt;
485297a64e7Sgd78059 
486297a64e7Sgd78059 	uint16_t		aner;	/* MII ANER register */
487297a64e7Sgd78059 
488297a64e7Sgd78059 	int			linkup;		/* selected link status */
489297a64e7Sgd78059 	int			linkup_state; /* link bringup state */
490297a64e7Sgd78059 	int			linkup_changed; /* link bringup state */
491297a64e7Sgd78059 
492297a64e7Sgd78059 	int			linkcheck;
493297a64e7Sgd78059 	caddr_t			g_nd;	/* head of the */
494297a64e7Sgd78059 						/* named dispatch table */
495297a64e7Sgd78059 
496297a64e7Sgd78059 	ddi_device_acc_attr_t	dev_attr;
497297a64e7Sgd78059 	ddi_iblock_cookie_t	cookie;	/* interrupt cookie */
498297a64e7Sgd78059 	ddi_acc_handle_t	globregh;   /* ERI global regs */
499297a64e7Sgd78059 	ddi_acc_handle_t	etxregh;    /* ERI ETX regs */
500297a64e7Sgd78059 	ddi_acc_handle_t	erxregh;    /* ERI ERX regs */
501297a64e7Sgd78059 	ddi_acc_handle_t	bmacregh;   /* BigMAC registers */
502297a64e7Sgd78059 	ddi_acc_handle_t	mifregh;    /* ERI transceiver */
503297a64e7Sgd78059 	ddi_acc_handle_t	pcsregh;    /* ERI PCS regs */
504297a64e7Sgd78059 
505297a64e7Sgd78059 	ddi_acc_handle_t	sw_reset_regh;	/* ERI Reset Reg */
506297a64e7Sgd78059 
507297a64e7Sgd78059 	ddi_dma_cookie_t	md_c;	/* trmd dma cookie */
508297a64e7Sgd78059 	ddi_acc_handle_t	mdm_h;	/* trmd memory handle */
509297a64e7Sgd78059 	ddi_dma_handle_t	md_h;	/* trmdp dma handle */
510297a64e7Sgd78059 
511297a64e7Sgd78059 	ddi_acc_handle_t	pci_config_handle; /* ERI PCI config */
512297a64e7Sgd78059 
513297a64e7Sgd78059 	/*
514297a64e7Sgd78059 	 * DDI dma handle, kernel virtual base,
515297a64e7Sgd78059 	 * and io virtual base of IOPB area.
516297a64e7Sgd78059 	 */
517297a64e7Sgd78059 	ddi_dma_handle_t	iopbhandle;
518297a64e7Sgd78059 	uintptr_t		iopbkbase;
519297a64e7Sgd78059 	uintptr_t		iopbiobase;
520297a64e7Sgd78059 	kstat_t			*ksp;		/* kstat pointer */
521297a64e7Sgd78059 
522297a64e7Sgd78059 	kmutex_t		xmitlock;	/* protect xmit-side fields */
523297a64e7Sgd78059 	kmutex_t		xcvrlock;	/* */
524297a64e7Sgd78059 	kmutex_t		intrlock;	/* protect intr-side fields */
525297a64e7Sgd78059 	kmutex_t		linklock;	/* protect link-side fields */
526297a64e7Sgd78059 
527297a64e7Sgd78059 	mblk_t		*tmblkp[ERI_TMDMAX]; /* mblks assoc with TMD */
528297a64e7Sgd78059 	mblk_t		*rmblkp[ERI_RMDMAX]; /* mblks assoc with RMD */
529297a64e7Sgd78059 	param_t		param_arr[ERI_PARAM_CNT];
530297a64e7Sgd78059 
531297a64e7Sgd78059 	struct	stats stats;	/* kstats */
532297a64e7Sgd78059 
533297a64e7Sgd78059 	/*
534297a64e7Sgd78059 	 * Check if transmitter is hung
535297a64e7Sgd78059 	 */
536297a64e7Sgd78059 	uint32_t	starts;
537297a64e7Sgd78059 	uint32_t	txhung;
538297a64e7Sgd78059 	struct		erisave erisave;
539297a64e7Sgd78059 
540297a64e7Sgd78059 	uint64_t	ifspeed_old;
541297a64e7Sgd78059 
542297a64e7Sgd78059 #ifdef ERI_RMAC_HANG_WORKAROUND
543297a64e7Sgd78059 	uint32_t	check_rmac_hang;
544297a64e7Sgd78059 	uint32_t	check2_rmac_hang;
545297a64e7Sgd78059 	uint32_t	rxfifo_wr_ptr;
546297a64e7Sgd78059 	uint32_t	rxfifo_rd_ptr;
547297a64e7Sgd78059 	uint32_t	rxfifo_wr_ptr_c;
548297a64e7Sgd78059 	uint32_t	rxfifo_rd_ptr_c;
549297a64e7Sgd78059 #endif
550297a64e7Sgd78059 	uint32_t	tx_int_me;
551297a64e7Sgd78059 };
552297a64e7Sgd78059 
553297a64e7Sgd78059 /*
554297a64e7Sgd78059  * LADRF bit array manipulation macros.  These are for working within the
555297a64e7Sgd78059  * array of words defined by erip->ladrf, converting a bit (0-255) into
556297a64e7Sgd78059  * the index and offset in the ladrf bit array.  Note that the array is
557297a64e7Sgd78059  * provided in "Big Endian" order.
558297a64e7Sgd78059  */
559297a64e7Sgd78059 #define	LADRF_MASK(bit)		(1 << ((bit) % 16))
560297a64e7Sgd78059 #define	LADRF_WORD(erip, bit)	erip->ladrf[(15 - ((bit) / 16))]
561297a64e7Sgd78059 #define	LADRF_SET(erip, bit)	(LADRF_WORD(erip, bit) |= LADRF_MASK(bit))
562297a64e7Sgd78059 #define	LADRF_CLR(erip, bit)	(LADRF_WORD(erip, bit) &= ~LADRF_MASK(bit))
563297a64e7Sgd78059 
564297a64e7Sgd78059 /*
565297a64e7Sgd78059  * ERI IOCTLS.
566297a64e7Sgd78059  * Change : TODO : MBE
567297a64e7Sgd78059  */
568297a64e7Sgd78059 #define	ERIIOC		('G' << 8)
569297a64e7Sgd78059 #define	ERI_SET_LOOP_MODE	(ERIIOC|1)	/* Set Rio Loopback mode */
570297a64e7Sgd78059 #define	ERI_GET_LOOP_MODE	(ERIIOC|2)	/* Get Rio Loopback modes */
571297a64e7Sgd78059 #define	ERI_GET_LOOP_IFCNT	(ERIIOC|4)	/* Get Rio IF Count */
572297a64e7Sgd78059 
573297a64e7Sgd78059 /*
574297a64e7Sgd78059  * Loopback modes: For diagnostic testing purposes the ERI card
575297a64e7Sgd78059  * can be placed in loopback mode.
576297a64e7Sgd78059  * There are three modes of loopback provided by the driver,
577297a64e7Sgd78059  * Mac loopback, PCS loopback and Serdes loopback.
578297a64e7Sgd78059  */
579297a64e7Sgd78059 #define	ERI_LOOPBACK_OFF		0
580297a64e7Sgd78059 #define	ERI_MAC_LOOPBACK_ON		1
581297a64e7Sgd78059 #define	ERI_PCS_LOOPBACK_ON 		2
582297a64e7Sgd78059 #define	ERI_SER_LOOPBACK_ON 		4
583297a64e7Sgd78059 typedef struct {
584297a64e7Sgd78059 	int loopback;
585297a64e7Sgd78059 } loopback_t;
586297a64e7Sgd78059 
587297a64e7Sgd78059 
588297a64e7Sgd78059 /*
589297a64e7Sgd78059  * flags
590297a64e7Sgd78059  * TODO : MBE
591297a64e7Sgd78059  */
592297a64e7Sgd78059 #define	ERI_UNKOWN	0x00	/* unknown state	*/
593297a64e7Sgd78059 #define	ERI_RUNNING	0x01	/* chip is initialized	*/
594297a64e7Sgd78059 #define	ERI_STARTED	0x02	/* mac layer started */
595297a64e7Sgd78059 #define	ERI_SUSPENDED	0x08	/* suspended interface	*/
596297a64e7Sgd78059 #define	ERI_INITIALIZED	0x10	/* interface initialized */
597297a64e7Sgd78059 #define	ERI_NOTIMEOUTS	0x20	/* disallow timeout rescheduling */
598297a64e7Sgd78059 #define	ERI_TXINIT	0x40	/* TX Portion Init'ed	*/
599297a64e7Sgd78059 #define	ERI_RXINIT	0x80	/* RX Portion Init'ed	*/
600297a64e7Sgd78059 #define	ERI_MACLOOPBACK	0x100	/* device has MAC int lpbk (DIAG) */
601297a64e7Sgd78059 #define	ERI_SERLOOPBACK	0x200	/* device has SERDES int lpbk (DIAG) */
602297a64e7Sgd78059 #define	ERI_DLPI_LINKUP	0x400	/* */
603297a64e7Sgd78059 
604297a64e7Sgd78059 /*
605297a64e7Sgd78059  * Mac address flags
606297a64e7Sgd78059  */
607297a64e7Sgd78059 #define	ERI_FACTADDR_PRESENT	0x01	/* factory MAC id present */
608297a64e7Sgd78059 #define	ERI_FACTADDR_USE	0x02	/* use factory MAC id */
609297a64e7Sgd78059 
610297a64e7Sgd78059 struct erikstat {
611297a64e7Sgd78059 	/*
612297a64e7Sgd78059 	 * Software event stats
613297a64e7Sgd78059 	 */
614297a64e7Sgd78059 	struct kstat_named	erik_inits;
615297a64e7Sgd78059 	struct kstat_named	erik_rx_inits;
616297a64e7Sgd78059 	struct kstat_named	erik_tx_inits;
617297a64e7Sgd78059 
618297a64e7Sgd78059 	struct kstat_named	erik_allocbfail;
619297a64e7Sgd78059 	struct kstat_named	erik_drop;
620297a64e7Sgd78059 
621297a64e7Sgd78059 	/*
622297a64e7Sgd78059 	 * MAC Control event stats
623297a64e7Sgd78059 	 */
624297a64e7Sgd78059 	struct kstat_named	erik_pause_rxcount; /* PAUSE Receive count */
625297a64e7Sgd78059 	struct kstat_named	erik_pause_oncount;
626297a64e7Sgd78059 	struct kstat_named	erik_pause_offcount;
627297a64e7Sgd78059 	struct kstat_named	erik_pause_time_count;
628297a64e7Sgd78059 
629297a64e7Sgd78059 	/*
630297a64e7Sgd78059 	 * MAC TX Event stats
631297a64e7Sgd78059 	 */
632297a64e7Sgd78059 	struct kstat_named	erik_txmac_maxpkt_err;
633297a64e7Sgd78059 	struct kstat_named	erik_defer_timer_exp;
634297a64e7Sgd78059 	struct kstat_named	erik_peak_attempt_cnt;
635297a64e7Sgd78059 	struct kstat_named	erik_jab;
636297a64e7Sgd78059 	struct kstat_named	erik_notmds;
637297a64e7Sgd78059 	struct kstat_named	erik_tx_hang;
638297a64e7Sgd78059 
639297a64e7Sgd78059 	/*
640297a64e7Sgd78059 	 * MAC RX Event stats
641297a64e7Sgd78059 	 */
642297a64e7Sgd78059 	struct kstat_named	erik_no_free_rx_desc; /* no free rx desc. */
643297a64e7Sgd78059 	struct kstat_named	erik_rx_hang;
644297a64e7Sgd78059 	struct kstat_named	erik_rx_length_err;
645297a64e7Sgd78059 	struct kstat_named	erik_rx_code_viol_err;
646297a64e7Sgd78059 	struct kstat_named	erik_rx_bad_pkts;
647297a64e7Sgd78059 
648297a64e7Sgd78059 	/*
649297a64e7Sgd78059 	 * Fatal errors
650297a64e7Sgd78059 	 */
651297a64e7Sgd78059 	struct kstat_named	erik_rxtag_err;
652297a64e7Sgd78059 
653297a64e7Sgd78059 	/*
654297a64e7Sgd78059 	 * Parity error
655297a64e7Sgd78059 	 */
656297a64e7Sgd78059 	struct kstat_named	erik_parity_error;
657297a64e7Sgd78059 
658297a64e7Sgd78059 	/*
659297a64e7Sgd78059 	 * PCI fatal error stats
660297a64e7Sgd78059 	 */
661297a64e7Sgd78059 	struct kstat_named	erik_pci_error_int;  /* PCI error interrupt */
662297a64e7Sgd78059 	struct kstat_named	erik_unknown_fatal;	/* unknow fatal error */
663297a64e7Sgd78059 
664297a64e7Sgd78059 	/*
665297a64e7Sgd78059 	 * PCI Configuration space staus register
666297a64e7Sgd78059 	 */
667297a64e7Sgd78059 	struct kstat_named	erik_pci_data_parity_err; /* dparity err */
668297a64e7Sgd78059 	struct kstat_named	erik_pci_signal_target_abort;
669297a64e7Sgd78059 	struct kstat_named	erik_pci_rcvd_target_abort;
670297a64e7Sgd78059 	struct kstat_named	erik_pci_rcvd_master_abort;
671297a64e7Sgd78059 	struct kstat_named	erik_pci_signal_system_err;
672297a64e7Sgd78059 	struct kstat_named	erik_pci_det_parity_err;
673297a64e7Sgd78059 
674297a64e7Sgd78059 
675297a64e7Sgd78059 	struct kstat_named	erik_pmcap;	/* Power management */
676297a64e7Sgd78059 };
677297a64e7Sgd78059 
678297a64e7Sgd78059 /* TBD: new value ? */
679297a64e7Sgd78059 #define	ERI_DRAINTIME	(400000)	/* # microseconds xmit drain */
680297a64e7Sgd78059 
681297a64e7Sgd78059 #define	ROUNDUP(a, n)	(((a) + ((n) - 1)) & ~((n) - 1))
682297a64e7Sgd78059 #define	ROUNDUP2(a, n)	(uchar_t *)((((uintptr_t)(a)) + ((n) - 1)) & ~((n) - 1))
683297a64e7Sgd78059 
684297a64e7Sgd78059 /*
685297a64e7Sgd78059  * Xmit/receive buffer structure.
686297a64e7Sgd78059  * This structure is organized to meet the following requirements:
687297a64e7Sgd78059  * - hb_buf starts on an ERI_BURSTSIZE boundary.
688297a64e7Sgd78059  * - eribuf is an even multiple of ERI_BURSTSIZE
689297a64e7Sgd78059  * - hb_buf[] is large enough to contain max frame (1518) plus
690297a64e7Sgd78059  *   (3 x ERI_BURSTSIZE) rounded up to the next ERI_BURSTSIZE
691297a64e7Sgd78059  */
692297a64e7Sgd78059 /*
693297a64e7Sgd78059  * #define		ERI_BURSTSIZE	(64)
694297a64e7Sgd78059  */
695297a64e7Sgd78059 #define		ERI_BURSTSIZE	(128)
696297a64e7Sgd78059 #define		ERI_BURSTMASK	(ERIBURSTSIZE - 1)
697297a64e7Sgd78059 #define		ERI_BUFSIZE	(1728)	/* (ETHERMTU + 228) */
698297a64e7Sgd78059 #define		ERI_HEADROOM	(34)
699297a64e7Sgd78059 
700297a64e7Sgd78059 /* Offset for the first byte in the receive buffer */
701297a64e7Sgd78059 #define	ERI_FSTBYTE_OFFSET	2
702297a64e7Sgd78059 #define	ERI_CKSUM_OFFSET	14
703297a64e7Sgd78059 
704297a64e7Sgd78059 
705297a64e7Sgd78059 #define	ERI_PMCAP_NONE	0
706297a64e7Sgd78059 #define	ERI_PMCAP_4MHZ	4
707297a64e7Sgd78059 
708297a64e7Sgd78059 #endif	/* _KERNEL */
709297a64e7Sgd78059 
710297a64e7Sgd78059 #ifdef	__cplusplus
711297a64e7Sgd78059 }
712297a64e7Sgd78059 #endif
713297a64e7Sgd78059 
714297a64e7Sgd78059 #endif	/* _SYS_ERI_H */
715