xref: /illumos-gate/usr/src/uts/common/io/e1000g/e1000g_sw.h (revision 1b83305cfc332b1e19ad6a194b73b2975e6bf79a)
1 /*
2  * This file is provided under a CDDLv1 license.  When using or
3  * redistributing this file, you may do so under this license.
4  * In redistributing this file this license must be included
5  * and no other modification of this header file is permitted.
6  *
7  * CDDL LICENSE SUMMARY
8  *
9  * Copyright(c) 1999 - 2008 Intel Corporation. All rights reserved.
10  *
11  * The contents of this file are subject to the terms of Version
12  * 1.0 of the Common Development and Distribution License (the "License").
13  *
14  * You should have received a copy of the License with this software.
15  * You can obtain a copy of the License at
16  *	http://www.opensolaris.org/os/licensing.
17  * See the License for the specific language governing permissions
18  * and limitations under the License.
19  */
20 
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms of the CDDLv1.
24  */
25 
26 #ifndef _E1000G_SW_H
27 #define	_E1000G_SW_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * **********************************************************************
37  * Module Name:								*
38  *   e1000g_sw.h							*
39  *									*
40  * Abstract:								*
41  *   This header file contains Software-related data structures		*
42  *   definitions.							*
43  *									*
44  * **********************************************************************
45  */
46 
47 #include <sys/types.h>
48 #include <sys/conf.h>
49 #include <sys/debug.h>
50 #include <sys/stropts.h>
51 #include <sys/stream.h>
52 #include <sys/strsun.h>
53 #include <sys/strlog.h>
54 #include <sys/kmem.h>
55 #include <sys/stat.h>
56 #include <sys/kstat.h>
57 #include <sys/modctl.h>
58 #include <sys/errno.h>
59 #include <sys/mac.h>
60 #include <sys/mac_ether.h>
61 #include <sys/vlan.h>
62 #include <sys/ddi.h>
63 #include <sys/sunddi.h>
64 #include <sys/disp.h>
65 #include <sys/pci.h>
66 #include <sys/sdt.h>
67 #include <sys/ethernet.h>
68 #include <sys/pattr.h>
69 #include <sys/strsubr.h>
70 #include <sys/netlb.h>
71 #include <inet/common.h>
72 #include <inet/ip.h>
73 #include <inet/mi.h>
74 #include <inet/nd.h>
75 #include <sys/ddifm.h>
76 #include <sys/fm/protocol.h>
77 #include <sys/fm/util.h>
78 #include <sys/fm/io/ddi.h>
79 #include "e1000_api.h"
80 
81 
82 #define	JUMBO_FRAG_LENGTH		4096
83 
84 #define	LAST_RAR_ENTRY			(E1000_RAR_ENTRIES - 1)
85 #define	MAX_NUM_UNICAST_ADDRESSES	E1000_RAR_ENTRIES
86 #define	MAX_NUM_MULTICAST_ADDRESSES	256
87 
88 #define	MAX_TX_DESC_PER_PACKET		16
89 
90 /*
91  * constants used in setting flow control thresholds
92  */
93 #define	E1000_PBA_MASK		0xffff
94 #define	E1000_PBA_SHIFT		10
95 #define	E1000_FC_HIGH_DIFF	0x1638 /* High: 5688 bytes below Rx FIFO size */
96 #define	E1000_FC_LOW_DIFF	0x1640 /* Low: 5696 bytes below Rx FIFO size */
97 #define	E1000_FC_PAUSE_TIME	0x0680 /* 858 usec */
98 
99 #define	MAX_NUM_TX_DESCRIPTOR		4096
100 #define	MAX_NUM_RX_DESCRIPTOR		4096
101 #define	MAX_NUM_RX_FREELIST		4096
102 #define	MAX_NUM_TX_FREELIST		4096
103 #define	MAX_RX_LIMIT_ON_INTR		4096
104 #define	MAX_RX_INTR_DELAY		65535
105 #define	MAX_RX_INTR_ABS_DELAY		65535
106 #define	MAX_TX_INTR_DELAY		65535
107 #define	MAX_TX_INTR_ABS_DELAY		65535
108 #define	MAX_INTR_THROTTLING		65535
109 #define	MAX_RX_BCOPY_THRESHOLD		E1000_RX_BUFFER_SIZE_2K
110 #define	MAX_TX_BCOPY_THRESHOLD		E1000_TX_BUFFER_SIZE_2K
111 #define	MAX_TX_RECYCLE_THRESHOLD	MAX_NUM_TX_DESCRIPTOR
112 #define	MAX_TX_RECYCLE_NUM		MAX_NUM_TX_DESCRIPTOR
113 
114 #define	MIN_NUM_TX_DESCRIPTOR		80
115 #define	MIN_NUM_RX_DESCRIPTOR		80
116 #define	MIN_NUM_RX_FREELIST		64
117 #define	MIN_NUM_TX_FREELIST		80
118 #define	MIN_RX_LIMIT_ON_INTR		16
119 #define	MIN_RX_INTR_DELAY		0
120 #define	MIN_RX_INTR_ABS_DELAY		0
121 #define	MIN_TX_INTR_DELAY		0
122 #define	MIN_TX_INTR_ABS_DELAY		0
123 #define	MIN_INTR_THROTTLING		0
124 #define	MIN_RX_BCOPY_THRESHOLD		0
125 #define	MIN_TX_BCOPY_THRESHOLD		MINIMUM_ETHERNET_PACKET_SIZE
126 #define	MIN_TX_RECYCLE_THRESHOLD	0
127 #define	MIN_TX_RECYCLE_NUM		MAX_TX_DESC_PER_PACKET
128 
129 #define	DEFAULT_NUM_RX_DESCRIPTOR	2048
130 #define	DEFAULT_NUM_TX_DESCRIPTOR	2048
131 #define	DEFAULT_NUM_RX_FREELIST		4096
132 #define	DEFAULT_NUM_TX_FREELIST		2304
133 #define	DEFAULT_RX_LIMIT_ON_INTR	128
134 
135 #ifdef __sparc
136 #define	MAX_INTR_PER_SEC		7100
137 #define	MIN_INTR_PER_SEC		3000
138 #define	DEFAULT_INTR_PACKET_LOW		5
139 #define	DEFAULT_INTR_PACKET_HIGH	128
140 #define	DEFAULT_TX_RECYCLE_THRESHOLD	512
141 #else
142 #define	MAX_INTR_PER_SEC		15000
143 #define	MIN_INTR_PER_SEC		4000
144 #define	DEFAULT_INTR_PACKET_LOW		10
145 #define	DEFAULT_INTR_PACKET_HIGH	48
146 #define	DEFAULT_TX_RECYCLE_THRESHOLD	DEFAULT_TX_NO_RESOURCE
147 #endif
148 
149 #define	DEFAULT_RX_INTR_DELAY		0
150 #define	DEFAULT_RX_INTR_ABS_DELAY	64
151 #define	DEFAULT_TX_INTR_DELAY		64
152 #define	DEFAULT_TX_INTR_ABS_DELAY	64
153 #define	DEFAULT_INTR_THROTTLING_HIGH    1000000000/(MIN_INTR_PER_SEC*256)
154 #define	DEFAULT_INTR_THROTTLING_LOW	1000000000/(MAX_INTR_PER_SEC*256)
155 #define	DEFAULT_INTR_THROTTLING		DEFAULT_INTR_THROTTLING_LOW
156 
157 #define	DEFAULT_RX_BCOPY_THRESHOLD	128
158 #define	DEFAULT_TX_BCOPY_THRESHOLD	512
159 #define	DEFAULT_TX_RECYCLE_NUM		64
160 #define	DEFAULT_TX_UPDATE_THRESHOLD	256
161 #define	DEFAULT_TX_NO_RESOURCE		6
162 
163 #define	DEFAULT_TX_INTR_ENABLE		1
164 #define	DEFAULT_FLOW_CONTROL		3
165 #define	DEFAULT_MASTER_LATENCY_TIMER	0	/* BIOS should decide */
166 						/* which is normally 0x040 */
167 #define	DEFAULT_TBI_COMPAT_ENABLE	1	/* Enable SBP workaround */
168 #define	DEFAULT_MSI_ENABLE		1	/* MSI Enable */
169 
170 #define	TX_DRAIN_TIME		(200)	/* # milliseconds xmit drain */
171 
172 /*
173  * The size of the receive/transmite buffers
174  */
175 #define	E1000_RX_BUFFER_SIZE_2K		(2048)
176 #define	E1000_RX_BUFFER_SIZE_4K		(4096)
177 #define	E1000_RX_BUFFER_SIZE_8K		(8192)
178 #define	E1000_RX_BUFFER_SIZE_16K	(16384)
179 
180 #define	E1000_TX_BUFFER_SIZE_2K		(2048)
181 #define	E1000_TX_BUFFER_SIZE_4K		(4096)
182 #define	E1000_TX_BUFFER_SIZE_8K		(8192)
183 #define	E1000_TX_BUFFER_SIZE_16K	(16384)
184 
185 #define	FORCE_BCOPY_EXCEED_FRAGS	0x1
186 #define	FORCE_BCOPY_UNDER_SIZE		0x2
187 
188 #define	E1000G_RX_SW_FREE		0x0
189 #define	E1000G_RX_SW_SENDUP		0x1
190 #define	E1000G_RX_SW_STOP		0x2
191 #define	E1000G_RX_SW_DETACH		0x3
192 
193 /*
194  * definitions for smartspeed workaround
195  */
196 #define	  E1000_SMARTSPEED_MAX		30	/* 30 watchdog iterations */
197 						/* or 30 seconds */
198 #define	  E1000_SMARTSPEED_DOWNSHIFT	6	/* 6 watchdog iterations */
199 						/* or 6 seconds */
200 
201 /*
202  * Definitions for module_info.
203  */
204 #define	 WSNAME			"e1000g"	/* module name */
205 
206 /*
207  * Defined for IP header alignment. We also need to preserve space for
208  * VLAN tag (4 bytes)
209  */
210 #define	E1000G_IPALIGNROOM		6
211 #define	E1000G_IPALIGNPRESERVEROOM	64
212 
213 /*
214  * bit flags for 'attach_progress' which is a member variable in struct e1000g
215  */
216 #define	ATTACH_PROGRESS_PCI_CONFIG	0x0001	/* PCI config setup */
217 #define	ATTACH_PROGRESS_REGS_MAP	0x0002	/* Registers mapped */
218 #define	ATTACH_PROGRESS_SETUP		0x0004	/* Setup driver parameters */
219 #define	ATTACH_PROGRESS_ADD_INTR	0x0008	/* Interrupt added */
220 #define	ATTACH_PROGRESS_LOCKS		0x0010	/* Locks initialized */
221 #define	ATTACH_PROGRESS_SOFT_INTR	0x0020	/* Soft interrupt added */
222 #define	ATTACH_PROGRESS_KSTATS		0x0040	/* Kstats created */
223 #define	ATTACH_PROGRESS_ALLOC		0x0080	/* DMA resources allocated */
224 #define	ATTACH_PROGRESS_INIT		0x0100	/* Driver initialization */
225 #define	ATTACH_PROGRESS_NDD		0x0200	/* NDD initialized */
226 #define	ATTACH_PROGRESS_MAC		0x0400	/* MAC registered */
227 #define	ATTACH_PROGRESS_ENABLE_INTR	0x0800	/* DDI interrupts enabled */
228 #define	ATTACH_PROGRESS_FMINIT		0x1000	/* FMA initiated */
229 
230 /*
231  * Speed and Duplex Settings
232  */
233 #define	GDIAG_10_HALF		1
234 #define	GDIAG_10_FULL		2
235 #define	GDIAG_100_HALF		3
236 #define	GDIAG_100_FULL		4
237 #define	GDIAG_1000_FULL		6
238 #define	GDIAG_ANY		7
239 
240 /*
241  * Coexist Workaround RP: 07/04/03
242  * 82544 Workaround : Co-existence
243  */
244 #define	MAX_TX_BUF_SIZE		(8 * 1024)
245 
246 #define	ROUNDOFF		0x1000
247 
248 /*
249  * Defines for Jumbo Frame
250  */
251 #define	FRAME_SIZE_UPTO_2K	2048
252 #define	FRAME_SIZE_UPTO_4K	4096
253 #define	FRAME_SIZE_UPTO_8K	8192
254 #define	FRAME_SIZE_UPTO_16K	16384
255 #define	FRAME_SIZE_UPTO_9K	9234
256 
257 /* The sizes (in bytes) of a ethernet packet */
258 #define	MAXIMUM_ETHERNET_FRAME_SIZE	1518 /* With FCS */
259 #define	MINIMUM_ETHERNET_FRAME_SIZE	64   /* With FCS */
260 #define	ETHERNET_FCS_SIZE		4
261 #define	MAXIMUM_ETHERNET_PACKET_SIZE	\
262 	(MAXIMUM_ETHERNET_FRAME_SIZE - ETHERNET_FCS_SIZE)
263 #define	MINIMUM_ETHERNET_PACKET_SIZE	\
264 	(MINIMUM_ETHERNET_FRAME_SIZE - ETHERNET_FCS_SIZE)
265 #define	CRC_LENGTH			ETHERNET_FCS_SIZE
266 
267 /* Defines for Tx stall check */
268 #define	E1000G_STALL_WATCHDOG_COUNT	8
269 
270 #define	MAX_TX_LINK_DOWN_TIMEOUT	8
271 
272 /* Defines for DVMA */
273 #ifdef __sparc
274 #define	E1000G_DEFAULT_DVMA_PAGE_NUM	2
275 #endif
276 
277 /*
278  * Loopback definitions
279  */
280 #define	E1000G_LB_NONE			0
281 #define	E1000G_LB_EXTERNAL_1000		1
282 #define	E1000G_LB_EXTERNAL_100		2
283 #define	E1000G_LB_EXTERNAL_10		3
284 #define	E1000G_LB_INTERNAL_PHY		4
285 
286 /*
287  * Private dip list definitions
288  */
289 #define	E1000G_PRIV_DEVI_ATTACH	0x0
290 #define	E1000G_PRIV_DEVI_DETACH	0x1
291 
292 /*
293  * QUEUE_INIT_LIST -- Macro which will init ialize a queue to NULL.
294  */
295 #define	QUEUE_INIT_LIST(_LH)	\
296 	(_LH)->Flink = (_LH)->Blink = (PSINGLE_LIST_LINK)0
297 
298 /*
299  * IS_QUEUE_EMPTY -- Macro which checks to see if a queue is empty.
300  */
301 #define	IS_QUEUE_EMPTY(_LH)	\
302 	((_LH)->Flink == (PSINGLE_LIST_LINK)0)
303 
304 /*
305  * QUEUE_GET_HEAD -- Macro which returns the head of the queue, but does
306  * not remove the head from the queue.
307  */
308 #define	QUEUE_GET_HEAD(_LH)	((PSINGLE_LIST_LINK)((_LH)->Flink))
309 
310 /*
311  * QUEUE_REMOVE_HEAD -- Macro which removes the head of the head of a queue.
312  */
313 #define	QUEUE_REMOVE_HEAD(_LH)	\
314 { \
315 	PSINGLE_LIST_LINK ListElem; \
316 	if (ListElem = (_LH)->Flink) \
317 	{ \
318 		if (!((_LH)->Flink = ListElem->Flink)) \
319 			(_LH)->Blink = (PSINGLE_LIST_LINK) 0; \
320 	} \
321 }
322 
323 /*
324  * QUEUE_POP_HEAD -- Macro which  will pop the head off of a queue (list),
325  *	and return it (this differs from QUEUE_REMOVE_HEAD only in
326  *	the 1st line).
327  */
328 #define	QUEUE_POP_HEAD(_LH)	\
329 	(PSINGLE_LIST_LINK)(_LH)->Flink; \
330 	{ \
331 		PSINGLE_LIST_LINK ListElem; \
332 		ListElem = (_LH)->Flink; \
333 		if (ListElem) \
334 		{ \
335 			(_LH)->Flink = ListElem->Flink; \
336 			if (!(_LH)->Flink) \
337 				(_LH)->Blink = (PSINGLE_LIST_LINK)0; \
338 		} \
339 	}
340 
341 /*
342  * QUEUE_GET_TAIL -- Macro which returns the tail of the queue, but does not
343  *	remove the tail from the queue.
344  */
345 #define	QUEUE_GET_TAIL(_LH)	((PSINGLE_LIST_LINK)((_LH)->Blink))
346 
347 /*
348  * QUEUE_PUSH_TAIL -- Macro which puts an element at the tail (end) of the queue
349  */
350 #define	QUEUE_PUSH_TAIL(_LH, _E)	\
351 	if ((_LH)->Blink) \
352 	{ \
353 		((PSINGLE_LIST_LINK)(_LH)->Blink)->Flink = \
354 			(PSINGLE_LIST_LINK)(_E); \
355 		(_LH)->Blink = (PSINGLE_LIST_LINK)(_E); \
356 	} else { \
357 		(_LH)->Flink = \
358 			(_LH)->Blink = (PSINGLE_LIST_LINK)(_E); \
359 	} \
360 	(_E)->Flink = (PSINGLE_LIST_LINK)0;
361 
362 /*
363  * QUEUE_PUSH_HEAD -- Macro which puts an element at the head of the queue.
364  */
365 #define	QUEUE_PUSH_HEAD(_LH, _E)	\
366 	if (!((_E)->Flink = (_LH)->Flink)) \
367 	{ \
368 		(_LH)->Blink = (PSINGLE_LIST_LINK)(_E); \
369 	} \
370 	(_LH)->Flink = (PSINGLE_LIST_LINK)(_E);
371 
372 /*
373  * QUEUE_GET_NEXT -- Macro which returns the next element linked to the
374  *	current element.
375  */
376 #define	QUEUE_GET_NEXT(_LH, _E)		\
377 	(PSINGLE_LIST_LINK)((((_LH)->Blink) == (_E)) ? \
378 	(0) : ((_E)->Flink))
379 
380 /*
381  * QUEUE_APPEND -- Macro which appends a queue to the tail of another queue
382  */
383 #define	QUEUE_APPEND(_LH1, _LH2)	\
384 	if ((_LH2)->Flink) { \
385 		if ((_LH1)->Flink) { \
386 			((PSINGLE_LIST_LINK)(_LH1)->Blink)->Flink = \
387 				((PSINGLE_LIST_LINK)(_LH2)->Flink); \
388 		} else { \
389 			(_LH1)->Flink = \
390 				((PSINGLE_LIST_LINK)(_LH2)->Flink); \
391 		} \
392 		(_LH1)->Blink = ((PSINGLE_LIST_LINK)(_LH2)->Blink); \
393 	}
394 
395 /*
396  * Property lookups
397  */
398 #define	E1000G_PROP_EXISTS(d, n)	ddi_prop_exists(DDI_DEV_T_ANY, (d), \
399 						DDI_PROP_DONTPASS, (n))
400 #define	E1000G_PROP_GET_INT(d, n)	ddi_prop_get_int(DDI_DEV_T_ANY, (d), \
401 						DDI_PROP_DONTPASS, (n), -1)
402 
403 /*
404  * Shorthand for the NDD parameters
405  */
406 #define	param_adv_autoneg	nd_params[PARAM_ADV_AUTONEG_CAP].ndp_val
407 #define	param_adv_pause		nd_params[PARAM_ADV_PAUSE_CAP].ndp_val
408 #define	param_adv_asym_pause	nd_params[PARAM_ADV_ASYM_PAUSE_CAP].ndp_val
409 #define	param_adv_1000fdx	nd_params[PARAM_ADV_1000FDX_CAP].ndp_val
410 #define	param_adv_1000hdx	nd_params[PARAM_ADV_1000HDX_CAP].ndp_val
411 #define	param_adv_100fdx	nd_params[PARAM_ADV_100FDX_CAP].ndp_val
412 #define	param_adv_100hdx	nd_params[PARAM_ADV_100HDX_CAP].ndp_val
413 #define	param_adv_10fdx		nd_params[PARAM_ADV_10FDX_CAP].ndp_val
414 #define	param_adv_10hdx		nd_params[PARAM_ADV_10HDX_CAP].ndp_val
415 #define	param_force_speed_duplex nd_params[PARAM_FORCE_SPEED_DUPLEX].ndp_val
416 
417 #ifdef E1000G_DEBUG
418 /*
419  * E1000G-specific ioctls ...
420  */
421 #define	E1000G_IOC		((((((('E' << 4) + '1') << 4) \
422 				+ 'K') << 4) + 'G') << 4)
423 
424 /*
425  * These diagnostic IOCTLS are enabled only in DEBUG drivers
426  */
427 #define	E1000G_IOC_REG_PEEK	(E1000G_IOC | 1)
428 #define	E1000G_IOC_REG_POKE	(E1000G_IOC | 2)
429 #define	E1000G_IOC_CHIP_RESET	(E1000G_IOC | 3)
430 
431 #define	E1000G_PP_SPACE_REG	0	/* PCI memory space	*/
432 #define	E1000G_PP_SPACE_E1000G	1	/* driver's soft state	*/
433 
434 typedef struct {
435 	uint64_t pp_acc_size;	/* It's 1, 2, 4 or 8	*/
436 	uint64_t pp_acc_space;	/* See #defines below	*/
437 	uint64_t pp_acc_offset;	/* See regs definition	*/
438 	uint64_t pp_acc_data;	/* output for peek	*/
439 				/* input for poke	*/
440 } e1000g_peekpoke_t;
441 #endif	/* E1000G_DEBUG */
442 
443 /*
444  * (Internal) return values from ioctl subroutines
445  */
446 enum ioc_reply {
447 	IOC_INVAL = -1,		/* bad, NAK with EINVAL	*/
448 	IOC_DONE,		/* OK, reply sent	*/
449 	IOC_ACK,		/* OK, just send ACK	*/
450 	IOC_REPLY		/* OK, just send reply	*/
451 };
452 
453 /*
454  * Named Data (ND) Parameter Management Structure
455  */
456 typedef struct {
457 	uint32_t ndp_info;
458 	uint32_t ndp_min;
459 	uint32_t ndp_max;
460 	uint32_t ndp_val;
461 	struct e1000g *ndp_instance;
462 	char *ndp_name;
463 } nd_param_t;
464 
465 /*
466  * NDD parameter indexes, divided into:
467  *
468  *	read-only parameters describing the hardware's capabilities
469  *	read-write parameters controlling the advertised capabilities
470  *	read-only parameters describing the partner's capabilities
471  *	read-write parameters controlling the force speed and duplex
472  *	read-only parameters describing the link state
473  *	read-only parameters describing the driver properties
474  *	read-write parameters controlling the driver properties
475  */
476 enum {
477 	PARAM_AUTONEG_CAP,
478 	PARAM_PAUSE_CAP,
479 	PARAM_ASYM_PAUSE_CAP,
480 	PARAM_1000FDX_CAP,
481 	PARAM_1000HDX_CAP,
482 	PARAM_100T4_CAP,
483 	PARAM_100FDX_CAP,
484 	PARAM_100HDX_CAP,
485 	PARAM_10FDX_CAP,
486 	PARAM_10HDX_CAP,
487 
488 	PARAM_ADV_AUTONEG_CAP,
489 	PARAM_ADV_PAUSE_CAP,
490 	PARAM_ADV_ASYM_PAUSE_CAP,
491 	PARAM_ADV_1000FDX_CAP,
492 	PARAM_ADV_1000HDX_CAP,
493 	PARAM_ADV_100T4_CAP,
494 	PARAM_ADV_100FDX_CAP,
495 	PARAM_ADV_100HDX_CAP,
496 	PARAM_ADV_10FDX_CAP,
497 	PARAM_ADV_10HDX_CAP,
498 
499 	PARAM_LP_AUTONEG_CAP,
500 	PARAM_LP_PAUSE_CAP,
501 	PARAM_LP_ASYM_PAUSE_CAP,
502 	PARAM_LP_1000FDX_CAP,
503 	PARAM_LP_1000HDX_CAP,
504 	PARAM_LP_100T4_CAP,
505 	PARAM_LP_100FDX_CAP,
506 	PARAM_LP_100HDX_CAP,
507 	PARAM_LP_10FDX_CAP,
508 	PARAM_LP_10HDX_CAP,
509 
510 	PARAM_FORCE_SPEED_DUPLEX,
511 
512 	PARAM_LINK_STATUS,
513 	PARAM_LINK_SPEED,
514 	PARAM_LINK_DUPLEX,
515 	PARAM_LINK_AUTONEG,
516 
517 	PARAM_MAX_FRAME_SIZE,
518 	PARAM_LOOP_MODE,
519 	PARAM_INTR_TYPE,
520 
521 	PARAM_TX_BCOPY_THRESHOLD,
522 	PARAM_TX_INTR_ENABLE,
523 	PARAM_TX_TIDV,
524 	PARAM_TX_TADV,
525 	PARAM_RX_BCOPY_THRESHOLD,
526 	PARAM_RX_PKT_ON_INTR,
527 	PARAM_RX_RDTR,
528 	PARAM_RX_RADV,
529 
530 	PARAM_COUNT
531 };
532 
533 /*
534  * The entry of the private dip list
535  */
536 typedef struct _private_devi_list {
537 	dev_info_t *priv_dip;
538 	uint16_t flag;
539 	struct _private_devi_list *next;
540 } private_devi_list_t;
541 
542 /*
543  * A structure that points to the next entry in the queue.
544  */
545 typedef struct _SINGLE_LIST_LINK {
546 	struct _SINGLE_LIST_LINK *Flink;
547 } SINGLE_LIST_LINK, *PSINGLE_LIST_LINK;
548 
549 /*
550  * A "ListHead" structure that points to the head and tail of a queue
551  */
552 typedef struct _LIST_DESCRIBER {
553 	struct _SINGLE_LIST_LINK *volatile Flink;
554 	struct _SINGLE_LIST_LINK *volatile Blink;
555 } LIST_DESCRIBER, *PLIST_DESCRIBER;
556 
557 /*
558  * Address-Length pair structure that stores descriptor info
559  */
560 typedef struct _sw_desc {
561 	uint64_t address;
562 	uint32_t length;
563 } sw_desc_t, *p_sw_desc_t;
564 
565 typedef struct _desc_array {
566 	sw_desc_t descriptor[4];
567 	uint32_t elements;
568 } desc_array_t, *p_desc_array_t;
569 
570 typedef enum {
571 	USE_NONE,
572 	USE_BCOPY,
573 	USE_DVMA,
574 	USE_DMA
575 } dma_type_t;
576 
577 typedef enum {
578 	E1000G_STOP,
579 	E1000G_START,
580 	E1000G_ERROR
581 } chip_state_t;
582 
583 typedef struct _dma_buffer {
584 	caddr_t address;
585 	uint64_t dma_address;
586 	ddi_acc_handle_t acc_handle;
587 	ddi_dma_handle_t dma_handle;
588 	size_t size;
589 	size_t len;
590 } dma_buffer_t, *p_dma_buffer_t;
591 
592 /*
593  * Transmit Control Block (TCB), Ndis equiv of SWPacket This
594  * structure stores the additional information that is
595  * associated with every packet to be transmitted. It stores the
596  * message block pointer and the TBD addresses associated with
597  * the m_blk and also the link to the next tcb in the chain
598  */
599 typedef struct _tx_sw_packet {
600 	/* Link to the next tx_sw_packet in the list */
601 	SINGLE_LIST_LINK Link;
602 	mblk_t *mp;
603 	uint32_t num_desc;
604 	uint32_t num_mblk_frag;
605 	dma_type_t dma_type;
606 	dma_type_t data_transfer_type;
607 	ddi_dma_handle_t tx_dma_handle;
608 	dma_buffer_t tx_buf[1];
609 	sw_desc_t desc[MAX_TX_DESC_PER_PACKET];
610 } tx_sw_packet_t, *p_tx_sw_packet_t;
611 
612 /*
613  * This structure is similar to the rx_sw_packet structure used
614  * for Ndis. This structure stores information about the 2k
615  * aligned receive buffer into which the FX1000 DMA's frames.
616  * This structure is maintained as a linked list of many
617  * receiver buffer pointers.
618  */
619 typedef struct _rx_sw_packet {
620 	/* Link to the next rx_sw_packet_t in the list */
621 	SINGLE_LIST_LINK Link;
622 	struct _rx_sw_packet *next;
623 	uint16_t flag;
624 	mblk_t *mp;
625 	caddr_t rx_ring;
626 	dma_type_t dma_type;
627 	frtn_t free_rtn;
628 	dma_buffer_t rx_buf[1];
629 } rx_sw_packet_t, *p_rx_sw_packet_t;
630 
631 typedef struct _mblk_list {
632 	mblk_t *head;
633 	mblk_t *tail;
634 } mblk_list_t, *p_mblk_list_t;
635 
636 typedef struct _cksum_data {
637 	uint32_t ether_header_size;
638 	uint32_t cksum_flags;
639 	uint32_t cksum_start;
640 	uint32_t cksum_stuff;
641 } cksum_data_t;
642 
643 typedef union _e1000g_ether_addr {
644 	struct {
645 		uint32_t high;
646 		uint32_t low;
647 	} reg;
648 	struct {
649 		uint8_t set;
650 		uint8_t redundant;
651 		uint8_t addr[ETHERADDRL];
652 	} mac;
653 } e1000g_ether_addr_t;
654 
655 typedef struct _e1000g_stat {
656 
657 	kstat_named_t link_speed;	/* Link Speed */
658 	kstat_named_t reset_count;	/* Reset Count */
659 
660 	kstat_named_t rx_error;		/* Rx Error in Packet */
661 	kstat_named_t rx_esballoc_fail;	/* Rx Desballoc Failure */
662 	kstat_named_t rx_allocb_fail;	/* Rx Allocb Failure */
663 
664 	kstat_named_t tx_no_desc;	/* Tx No Desc */
665 	kstat_named_t tx_no_swpkt;	/* Tx No Pkt Buffer */
666 	kstat_named_t tx_send_fail;	/* Tx SendPkt Failure */
667 	kstat_named_t tx_over_size;	/* Tx Pkt Too Long */
668 	kstat_named_t tx_reschedule;	/* Tx Reschedule */
669 
670 #ifdef E1000G_DEBUG
671 	kstat_named_t rx_none;		/* Rx No Incoming Data */
672 	kstat_named_t rx_multi_desc;	/* Rx Multi Spanned Pkt */
673 	kstat_named_t rx_no_freepkt;	/* Rx No Free Pkt */
674 	kstat_named_t rx_avail_freepkt;	/* Rx Freelist Avail Buffers */
675 
676 	kstat_named_t tx_under_size;	/* Tx Packet Under Size */
677 	kstat_named_t tx_empty_frags;	/* Tx Empty Frags */
678 	kstat_named_t tx_exceed_frags;	/* Tx Exceed Max Frags */
679 	kstat_named_t tx_recycle;	/* Tx Recycle */
680 	kstat_named_t tx_recycle_intr;	/* Tx Recycle in Intr */
681 	kstat_named_t tx_recycle_retry;	/* Tx Recycle Retry */
682 	kstat_named_t tx_recycle_none;	/* Tx No Desc Recycled */
683 	kstat_named_t tx_copy;		/* Tx Send Copy */
684 	kstat_named_t tx_bind;		/* Tx Send Bind */
685 	kstat_named_t tx_multi_copy;	/* Tx Copy Multi Fragments */
686 	kstat_named_t tx_multi_cookie;	/* Tx Pkt Span Multi Cookies */
687 	kstat_named_t tx_lack_desc;	/* Tx Lack of Desc */
688 #endif
689 
690 	kstat_named_t Crcerrs;	/* CRC Error Count */
691 	kstat_named_t Symerrs;	/* Symbol Error Count */
692 	kstat_named_t Mpc;	/* Missed Packet Count */
693 	kstat_named_t Scc;	/* Single Collision Count */
694 	kstat_named_t Ecol;	/* Excessive Collision Count */
695 	kstat_named_t Mcc;	/* Multiple Collision Count */
696 	kstat_named_t Latecol;	/* Late Collision Count */
697 	kstat_named_t Colc;	/* Collision Count */
698 	kstat_named_t Dc;	/* Defer Count */
699 	kstat_named_t Sec;	/* Sequence Error Count */
700 	kstat_named_t Rlec;	/* Receive Length Error Count */
701 	kstat_named_t Xonrxc;	/* XON Received Count */
702 	kstat_named_t Xontxc;	/* XON Xmitted Count */
703 	kstat_named_t Xoffrxc;	/* XOFF Received Count */
704 	kstat_named_t Xofftxc;	/* Xoff Xmitted Count */
705 	kstat_named_t Fcruc;	/* Unknown Flow Conrol Packet Rcvd Count */
706 #ifdef E1000G_DEBUG
707 	kstat_named_t Prc64;	/* Packets Received - 64b */
708 	kstat_named_t Prc127;	/* Packets Received - 65-127b */
709 	kstat_named_t Prc255;	/* Packets Received - 127-255b */
710 	kstat_named_t Prc511;	/* Packets Received - 256-511b */
711 	kstat_named_t Prc1023;	/* Packets Received - 511-1023b */
712 	kstat_named_t Prc1522;	/* Packets Received - 1024-1522b */
713 #endif
714 	kstat_named_t Gprc;	/* Good Packets Received Count */
715 	kstat_named_t Bprc;	/* Broadcasts Pkts Received Count */
716 	kstat_named_t Mprc;	/* Multicast Pkts Received Count */
717 	kstat_named_t Gptc;	/* Good Packets Xmitted Count */
718 	kstat_named_t Gorl;	/* Good Octets Recvd Lo Count */
719 	kstat_named_t Gorh;	/* Good Octets Recvd Hi Count */
720 	kstat_named_t Gotl;	/* Good Octets Xmitd Lo Count */
721 	kstat_named_t Goth;	/* Good Octets Xmitd Hi Count */
722 	kstat_named_t Rnbc;	/* Receive No Buffers Count */
723 	kstat_named_t Ruc;	/* Receive Undersize Count */
724 	kstat_named_t Rfc;	/* Receive Frag Count */
725 	kstat_named_t Roc;	/* Receive Oversize Count */
726 	kstat_named_t Rjc;	/* Receive Jabber Count */
727 	kstat_named_t Torl;	/* Total Octets Recvd Lo Count */
728 	kstat_named_t Torh;	/* Total Octets Recvd Hi Count */
729 	kstat_named_t Totl;	/* Total Octets Xmted Lo Count */
730 	kstat_named_t Toth;	/* Total Octets Xmted Hi Count */
731 	kstat_named_t Tpr;	/* Total Packets Received */
732 	kstat_named_t Tpt;	/* Total Packets Xmitted */
733 #ifdef E1000G_DEBUG
734 	kstat_named_t Ptc64;	/* Packets Xmitted (64b) */
735 	kstat_named_t Ptc127;	/* Packets Xmitted (64-127b) */
736 	kstat_named_t Ptc255;	/* Packets Xmitted (128-255b) */
737 	kstat_named_t Ptc511;	/* Packets Xmitted (255-511b) */
738 	kstat_named_t Ptc1023;	/* Packets Xmitted (512-1023b) */
739 	kstat_named_t Ptc1522;	/* Packets Xmitted (1024-1522b */
740 #endif
741 	kstat_named_t Mptc;	/* Multicast Packets Xmited Count */
742 	kstat_named_t Bptc;	/* Broadcast Packets Xmited Count */
743 	kstat_named_t Algnerrc;	/* Alignment Error count */
744 	kstat_named_t Tuc;	/* Transmit Underrun count */
745 	kstat_named_t Rxerrc;	/* Rx Error Count */
746 	kstat_named_t Tncrs;	/* Transmit with no CRS */
747 	kstat_named_t Cexterr;	/* Carrier Extension Error count */
748 	kstat_named_t Rutec;	/* Receive DMA too Early count */
749 	kstat_named_t Tsctc;	/* TCP seg contexts xmit count */
750 	kstat_named_t Tsctfc;	/* TCP seg contexts xmit fail count */
751 } e1000g_stat_t, *p_e1000g_stat_t;
752 
753 typedef struct _e1000g_tx_ring {
754 	kmutex_t tx_lock;
755 	kmutex_t freelist_lock;
756 	kmutex_t usedlist_lock;
757 	/*
758 	 * Descriptor queue definitions
759 	 */
760 	ddi_dma_handle_t tbd_dma_handle;
761 	ddi_acc_handle_t tbd_acc_handle;
762 	struct e1000_tx_desc *tbd_area;
763 	uint64_t tbd_dma_addr;
764 	struct e1000_tx_desc *tbd_first;
765 	struct e1000_tx_desc *tbd_last;
766 	struct e1000_tx_desc *tbd_oldest;
767 	struct e1000_tx_desc *tbd_next;
768 	uint32_t tbd_avail;
769 	/*
770 	 * Software packet structures definitions
771 	 */
772 	p_tx_sw_packet_t packet_area;
773 	LIST_DESCRIBER used_list;
774 	LIST_DESCRIBER free_list;
775 	/*
776 	 * TCP/UDP checksum offload
777 	 */
778 	cksum_data_t cksum_data;
779 	/*
780 	 * Timer definitions for 82547
781 	 */
782 	timeout_id_t timer_id_82547;
783 	boolean_t timer_enable_82547;
784 	/*
785 	 * reschedule when tx resource is available
786 	 */
787 	boolean_t resched_needed;
788 	uint32_t frags_limit;
789 	uint32_t stall_watchdog;
790 	uint32_t recycle_fail;
791 	mblk_list_t mblks;
792 	/*
793 	 * Statistics
794 	 */
795 	uint32_t stat_no_swpkt;
796 	uint32_t stat_no_desc;
797 	uint32_t stat_send_fail;
798 	uint32_t stat_reschedule;
799 	uint32_t stat_over_size;
800 #ifdef E1000G_DEBUG
801 	uint32_t stat_under_size;
802 	uint32_t stat_exceed_frags;
803 	uint32_t stat_empty_frags;
804 	uint32_t stat_recycle;
805 	uint32_t stat_recycle_intr;
806 	uint32_t stat_recycle_retry;
807 	uint32_t stat_recycle_none;
808 	uint32_t stat_copy;
809 	uint32_t stat_bind;
810 	uint32_t stat_multi_copy;
811 	uint32_t stat_multi_cookie;
812 	uint32_t stat_lack_desc;
813 #endif
814 	/*
815 	 * Pointer to the adapter
816 	 */
817 	struct e1000g *adapter;
818 } e1000g_tx_ring_t, *pe1000g_tx_ring_t;
819 
820 typedef struct _e1000g_rx_ring {
821 	kmutex_t rx_lock;
822 	kmutex_t freelist_lock;
823 	/*
824 	 * Descriptor queue definitions
825 	 */
826 	ddi_dma_handle_t rbd_dma_handle;
827 	ddi_acc_handle_t rbd_acc_handle;
828 	struct e1000_rx_desc *rbd_area;
829 	uint64_t rbd_dma_addr;
830 	struct e1000_rx_desc *rbd_first;
831 	struct e1000_rx_desc *rbd_last;
832 	struct e1000_rx_desc *rbd_next;
833 	/*
834 	 * Software packet structures definitions
835 	 */
836 	p_rx_sw_packet_t packet_area;
837 	LIST_DESCRIBER recv_list;
838 	LIST_DESCRIBER free_list;
839 
840 	p_rx_sw_packet_t pending_list;
841 	uint32_t pending_count;
842 	uint32_t avail_freepkt;
843 	uint32_t rx_mblk_len;
844 	mblk_t *rx_mblk;
845 	mblk_t *rx_mblk_tail;
846 	/*
847 	 * Statistics
848 	 */
849 	uint32_t stat_error;
850 	uint32_t stat_esballoc_fail;
851 	uint32_t stat_allocb_fail;
852 	uint32_t stat_exceed_pkt;
853 #ifdef E1000G_DEBUG
854 	uint32_t stat_none;
855 	uint32_t stat_multi_desc;
856 	uint32_t stat_no_freepkt;
857 #endif
858 	/*
859 	 * Pointer to the adapter
860 	 */
861 	struct e1000g *adapter;
862 } e1000g_rx_ring_t, *pe1000g_rx_ring_t;
863 
864 typedef struct e1000g {
865 	int instance;
866 	dev_info_t *dip;
867 	dev_info_t *priv_dip;
868 	mac_handle_t mh;
869 	mac_resource_handle_t mrh;
870 	struct e1000_hw shared;
871 	struct e1000g_osdep osdep;
872 
873 	chip_state_t chip_state;
874 	boolean_t e1000g_promisc;
875 	boolean_t strip_crc;
876 	boolean_t rx_buffer_setup;
877 	link_state_t link_state;
878 	uint32_t link_speed;
879 	uint32_t link_duplex;
880 	uint32_t master_latency_timer;
881 	uint32_t smartspeed;	/* smartspeed w/a counter */
882 	uint32_t init_count;
883 	uint32_t reset_count;
884 	uint32_t attach_progress;	/* attach tracking */
885 	uint32_t loopback_mode;
886 
887 	uint32_t tx_desc_num;
888 	uint32_t tx_freelist_num;
889 	uint32_t rx_desc_num;
890 	uint32_t rx_freelist_num;
891 	uint32_t tx_buffer_size;
892 	uint32_t rx_buffer_size;
893 
894 	uint32_t tx_link_down_timeout;
895 	uint32_t tx_bcopy_thresh;
896 	uint32_t rx_limit_onintr;
897 	uint32_t rx_bcopy_thresh;
898 #ifndef NO_82542_SUPPORT
899 	uint32_t rx_buf_align;
900 #endif
901 
902 	boolean_t intr_adaptive;
903 	boolean_t tx_intr_enable;
904 	uint32_t tx_recycle_thresh;
905 	uint32_t tx_recycle_num;
906 	uint32_t tx_intr_delay;
907 	uint32_t tx_intr_abs_delay;
908 	uint32_t rx_intr_delay;
909 	uint32_t rx_intr_abs_delay;
910 	uint32_t intr_throttling_rate;
911 
912 	boolean_t watchdog_timer_enabled;
913 	boolean_t watchdog_timer_started;
914 	timeout_id_t watchdog_tid;
915 	boolean_t link_complete;
916 	timeout_id_t link_tid;
917 
918 	e1000g_rx_ring_t rx_ring[1];
919 	e1000g_tx_ring_t tx_ring[1];
920 
921 	/*
922 	 * Rx and Tx packet count for interrupt adaptive setting
923 	 */
924 	uint32_t rx_pkt_cnt;
925 	uint32_t tx_pkt_cnt;
926 
927 	/*
928 	 * The watchdog_lock must be held when updateing the
929 	 * timeout fields in struct e1000g, that is,
930 	 * watchdog_tid, watchdog_timer_started.
931 	 */
932 	kmutex_t watchdog_lock;
933 	/*
934 	 * The link_lock protects the link fields in struct e1000g,
935 	 * such as link_state, link_speed, link_duplex, link_complete, and
936 	 * link_tid.
937 	 */
938 	kmutex_t link_lock;
939 	/*
940 	 * The chip_lock assures that the Rx/Tx process must be
941 	 * stopped while other functions change the hardware
942 	 * configuration of e1000g card, such as e1000g_reset(),
943 	 * e1000g_reset_hw() etc are executed.
944 	 */
945 	krwlock_t chip_lock;
946 
947 	boolean_t unicst_init;
948 	uint32_t unicst_avail;
949 	uint32_t unicst_total;
950 	e1000g_ether_addr_t unicst_addr[MAX_NUM_UNICAST_ADDRESSES];
951 
952 	uint32_t mcast_count;
953 	struct ether_addr mcast_table[MAX_NUM_MULTICAST_ADDRESSES];
954 
955 #ifdef __sparc
956 	ulong_t sys_page_sz;
957 	uint_t dvma_page_num;
958 #endif
959 
960 	boolean_t msi_enabled;
961 	int intr_type;
962 	int intr_cnt;
963 	int intr_cap;
964 	size_t intr_size;
965 	uint_t intr_pri;
966 	ddi_intr_handle_t *htable;
967 
968 	int tx_softint_pri;
969 	ddi_softint_handle_t tx_softint_handle;
970 
971 	kstat_t *e1000g_ksp;
972 
973 	/*
974 	 * NDD parameters
975 	 */
976 	caddr_t nd_data;
977 	nd_param_t nd_params[PARAM_COUNT];
978 
979 	uint16_t phy_ctrl;		/* contents of PHY_CTRL */
980 	uint16_t phy_status;		/* contents of PHY_STATUS */
981 	uint16_t phy_an_adv;		/* contents of PHY_AUTONEG_ADV */
982 	uint16_t phy_an_exp;		/* contents of PHY_AUTONEG_EXP */
983 	uint16_t phy_ext_status;	/* contents of PHY_EXT_STATUS */
984 	uint16_t phy_1000t_ctrl;	/* contents of PHY_1000T_CTRL */
985 	uint16_t phy_1000t_status;	/* contents of PHY_1000T_STATUS */
986 	uint16_t phy_lp_able;		/* contents of PHY_LP_ABILITY */
987 
988 	/*
989 	 * FMA capabilities
990 	 */
991 	int fm_capabilities;
992 } e1000g_t;
993 
994 
995 /*
996  * Function prototypes
997  */
998 int e1000g_alloc_dma_resources(struct e1000g *Adapter);
999 void e1000g_release_dma_resources(struct e1000g *Adapter);
1000 void e1000g_free_rx_sw_packet(p_rx_sw_packet_t packet);
1001 void e1000g_tx_setup(struct e1000g *Adapter);
1002 void e1000g_rx_setup(struct e1000g *Adapter);
1003 void e1000g_setup_multicast(struct e1000g *Adapter);
1004 boolean_t e1000g_reset(struct e1000g *Adapter);
1005 
1006 int e1000g_recycle(e1000g_tx_ring_t *tx_ring);
1007 void e1000g_free_tx_swpkt(p_tx_sw_packet_t packet);
1008 void e1000g_tx_freemsg(e1000g_tx_ring_t *tx_ring);
1009 uint_t e1000g_tx_softint_worker(caddr_t arg1, caddr_t arg2);
1010 mblk_t *e1000g_m_tx(void *arg, mblk_t *mp);
1011 mblk_t *e1000g_receive(struct e1000g *Adapter);
1012 void e1000g_rxfree_func(p_rx_sw_packet_t packet);
1013 
1014 int e1000g_m_stat(void *arg, uint_t stat, uint64_t *val);
1015 int e1000g_init_stats(struct e1000g *Adapter);
1016 void e1000_tbi_adjust_stats(struct e1000g *Adapter,
1017     uint32_t frame_len, uint8_t *mac_addr);
1018 enum ioc_reply e1000g_nd_ioctl(struct e1000g *Adapter,
1019     queue_t *wq, mblk_t *mp, struct iocblk *iocp);
1020 void e1000g_nd_cleanup(struct e1000g *Adapter);
1021 int e1000g_nd_init(struct e1000g *Adapter);
1022 
1023 void e1000g_clear_interrupt(struct e1000g *Adapter);
1024 void e1000g_mask_interrupt(struct e1000g *Adapter);
1025 void e1000g_clear_all_interrupts(struct e1000g *Adapter);
1026 void e1000g_clear_tx_interrupt(struct e1000g *Adapter);
1027 void e1000g_mask_tx_interrupt(struct e1000g *Adapter);
1028 void phy_spd_state(struct e1000_hw *hw, boolean_t enable);
1029 void e1000_enable_pciex_master(struct e1000_hw *hw);
1030 void e1000g_get_driver_control(struct e1000_hw *hw);
1031 int e1000g_check_acc_handle(ddi_acc_handle_t handle);
1032 int e1000g_check_dma_handle(ddi_dma_handle_t handle);
1033 void e1000g_fm_ereport(struct e1000g *Adapter, char *detail);
1034 void e1000g_set_fma_flags(struct e1000g *Adapter, int acc_flag, int dma_flag);
1035 
1036 #pragma inline(e1000_rar_set)
1037 
1038 /*
1039  * Global variables
1040  */
1041 extern boolean_t e1000g_force_detach;
1042 extern uint32_t e1000g_mblks_pending;
1043 extern krwlock_t e1000g_rx_detach_lock;
1044 extern private_devi_list_t *e1000g_private_devi_list;
1045 
1046 #ifdef __cplusplus
1047 }
1048 #endif
1049 
1050 #endif	/* _E1000G_SW_H */
1051