xref: /illumos-gate/usr/src/uts/common/io/nge/nge.h (revision 44bac77bf8165ebe38afb85dda247b928d88edf8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_NGE_H
28 #define	_SYS_NGE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 
37 #include <sys/types.h>
38 #include <sys/stream.h>
39 #include <sys/strsun.h>
40 #include <sys/strsubr.h>
41 #include <sys/stat.h>
42 #include <sys/pci.h>
43 #include <sys/note.h>
44 #include <sys/modctl.h>
45 #include <sys/kstat.h>
46 #include <sys/ethernet.h>
47 #include <sys/pattr.h>
48 #include <sys/errno.h>
49 #include <sys/dlpi.h>
50 #include <sys/devops.h>
51 #include <sys/debug.h>
52 #include <sys/conf.h>
53 #include <sys/callb.h>
54 
55 #include <netinet/ip6.h>
56 
57 #include <inet/common.h>
58 #include <inet/ip.h>
59 #include <netinet/udp.h>
60 #include <inet/mi.h>
61 #include <inet/nd.h>
62 
63 #include <sys/ddi.h>
64 #include <sys/sunddi.h>
65 
66 #include <sys/mac.h>
67 #include <sys/mac_ether.h>
68 
69 /*
70  * Reconfiguring the network devices requires the net_config privilege
71  * in Solaris 10+.
72  */
73 extern int secpolicy_net_config(const cred_t *, boolean_t);
74 
75 #include <sys/netlb.h>
76 #include <sys/miiregs.h>
77 
78 #include <sys/dld.h>
79 
80 #include "nge_chip.h"
81 
82 #define	PIO_ADDR(ngep, offset)	((void *)((caddr_t)(ngep)->io_regs+(offset)))
83 /*
84  * Copy an ethernet address
85  */
86 #define	ethaddr_copy(src, dst)	bcopy((src), (dst), ETHERADDRL)
87 #define	ether_eq(a, b) (bcmp((caddr_t)(a), (caddr_t)(b), (ETHERADDRL)) == 0)
88 
89 #define	BIS(w, b)	(((w) & (b)) ? B_TRUE : B_FALSE)
90 #define	BIC(w, b)	(((w) & (b)) ? B_FALSE : B_TRUE)
91 #define	UPORDOWN(x)	((x) ? "up" : "down")
92 
93 #define	NGE_DRIVER_NAME		"nge"
94 
95 /*
96  * 'Progress' bit flags ...
97  */
98 #define	PROGRESS_CFG		0x0001	/* config space mapped		*/
99 #define	PROGRESS_REGS		0x0002	/* registers mapped		*/
100 #define	PROGRESS_BUFS		0x0004	/* registers mapped		*/
101 #define	PROGRESS_RESCHED	0x0008	/* resched softint registered	*/
102 #define	PROGRESS_FACTOTUM	0x0010	/* factotum softint registered	*/
103 #define	PROGRESS_SWINT		0x0020	/* s/w interrupt registered	*/
104 #define	PROGRESS_INTR		0x0040	/* h/w interrupt registered	*/
105 					/* and mutexen initialised	*/
106 #define	PROGRESS_HWINT		0x0080
107 #define	PROGRESS_PHY		0x0100	/* PHY initialised		*/
108 #define	PROGRESS_NDD		0x0200	/* NDD parameters set up	*/
109 #define	PROGRESS_KSTATS		0x0400	/* kstats created		*/
110 #define	PROGRESS_READY		0x0800	/* ready for work		*/
111 
112 #define	NGE_HW_ERR		0x00
113 #define	NGE_HW_LINK		0x01
114 #define	NGE_HW_BM		0x02
115 #define	NGE_HW_RCHAN		0x03
116 #define	NGE_HW_TCHAN		0x04
117 #define	NGE_HW_ROM		0x05
118 #define	NGE_SW_PROBLEM_ID	0x06
119 
120 
121 /*
122  * NOTES:
123  *
124  * #defines:
125  *
126  *	NGE_PCI_CONFIG_RNUMBER and NGE_PCI_OPREGS_RNUMBER are the
127  *	register-set numbers to use for the config space registers
128  *	and the operating registers respectively.  On an OBP-based
129  *	machine, regset 0 refers to CONFIG space, and regset 1 will
130  *	be the operating registers in MEMORY space.  If an expansion
131  *	ROM is fitted, it may appear as a further register set.
132  *
133  *	NGE_DMA_MODE defines the mode (STREAMING/CONSISTENT) used
134  *	for the data buffers.  The descriptors are always set up
135  *	in CONSISTENT mode.
136  *
137  *	NGE_HEADROOM defines how much space we'll leave in allocated
138  *	mblks before the first valid data byte.  This should be chosen
139  *	to be 2 modulo 4, so that once the ethernet header (14 bytes)
140  *	has been stripped off, the packet data will be 4-byte aligned.
141  *	The remaining space can be used by upstream modules to prepend
142  *	any headers required.
143  */
144 
145 
146 #define	NGE_PCI_OPREGS_RNUMBER	1
147 #define	NGE_DMA_MODE		DDI_DMA_STREAMING
148 #define	NGE_HEADROOM		6
149 #define	ETHER_HEAD_LEN		14
150 #ifndef	VTAG_SIZE
151 #define	VTAG_SIZE		4
152 #endif
153 
154 #define	NGE_HALFTICK		268435456LL		/* 2**28 ns!	*/
155 #define	NGE_CYCLIC_PERIOD	(4*NGE_HALFTICK)	/*    ~0.5s	*/
156 
157 #define	NGE_DEFAULT_MTU		1500
158 #define	NGE_DEFAULT_SDU		1518
159 #define	NGE_MTU_2500		2500
160 #define	NGE_MTU_4500		4500
161 #define	NGE_MAX_MTU		9000
162 #define	NGE_MAX_SDU		9018
163 
164 #define	NGE_DESC_MIN		0x200
165 
166 #define	NGE_STD_BUFSZ		1792
167 #define	NGE_JB2500_BUFSZ	(3*1024)
168 #define	NGE_JB4500_BUFSZ	(5*1024)
169 #define	NGE_JB9000_BUFSZ	(9*1024)
170 
171 #define	NGE_SEND_SLOTS_DESC_1024	1024
172 #define	NGE_SEND_SLOTS_DESC_3072	3072
173 #define	NGE_SEND_JB2500_SLOTS_DESC	3072
174 #define	NGE_SEND_JB4500_SLOTS_DESC	2048
175 #define	NGE_SEND_JB9000_SLOTS_DESC	1024
176 #define	NGE_SEND_LOWMEM_SLOTS_DESC	1024
177 #define	NGE_SEND_SLOTS_BUF		3072
178 
179 #define	NGE_RECV_SLOTS_DESC_1024	1024
180 #define	NGE_RECV_SLOTS_DESC_3072	3072
181 #define	NGE_RECV_JB2500_SLOTS_DESC	3072
182 #define	NGE_RECV_JB4500_SLOTS_DESC	2048
183 #define	NGE_RECV_JB9000_SLOTS_DESC	1024
184 #define	NGE_RECV_LOWMEM_SLOTS_DESC	1024
185 #define	NGE_RECV_SLOTS_BUF		6144
186 
187 #define	NGE_SPLIT_32		32
188 #define	NGE_SPLIT_96		96
189 #define	NGE_SPLIT_256		256
190 
191 #define	NGE_RX_COPY_SIZE	512
192 #define	NGE_TX_COPY_SIZE	512
193 #define	NGE_MAP_FRAGS		3
194 #define	NGE_MAX_COOKIES		3
195 #define	NGE_MAX_DMA_HDR		(4*1024)
196 
197 /* Used by interrupt moderation */
198 #define	NGE_POLL_QUIET_TIME	100
199 #define	NGE_POLL_BUSY_TIME	2
200 #define	NGE_TX_N_INTR		128
201 
202 /*
203  * NGE-specific ioctls ...
204  */
205 #define	NGE_IOC			((((('N' << 8) + 'G') << 8) + 'E') << 8)
206 
207 /*
208  * PHY register read/write ioctls, used by cable test software
209  */
210 #define	NGE_MII_READ		(NGE_IOC|1)
211 #define	NGE_MII_WRITE		(NGE_IOC|2)
212 
213 /*
214  * SEEPROM read/write ioctls, for use by SEEPROM upgrade utility
215  *
216  * Note: SEEPROMs can only be accessed as 32-bit words, so <see_addr>
217  * must be a multiple of 4.  Not all systems have a SEEPROM fitted!
218  */
219 #define	NGE_SEE_READ		(NGE_IOC|3)
220 #define	NGE_SEE_WRITE		(NGE_IOC|4)
221 
222 
223 /*
224  * These diagnostic IOCTLS are enabled only in DEBUG drivers
225  */
226 #define	NGE_DIAG		(NGE_IOC|5)	/* currently a no-op	*/
227 #define	NGE_PEEK		(NGE_IOC|6)
228 #define	NGE_POKE		(NGE_IOC|7)
229 #define	NGE_PHY_RESET		(NGE_IOC|8)
230 #define	NGE_SOFT_RESET		(NGE_IOC|9)
231 #define	NGE_HARD_RESET		(NGE_IOC|10)
232 
233 
234 enum NGE_HW_OP {
235 	NGE_CLEAR = 0,
236 	NGE_SET
237 };
238 
239 /*
240  * Required state according to GLD
241  */
242 enum nge_mac_state {
243 	NGE_MAC_UNKNOWN,
244 	NGE_MAC_RESET,
245 	NGE_MAC_STOPPED,
246 	NGE_MAC_STARTED,
247 	NGE_MAC_UNATTACH
248 };
249 enum loop_type {
250 	NGE_LOOP_NONE = 0,
251 	NGE_LOOP_EXTERNAL_100,
252 	NGE_LOOP_EXTERNAL_10,
253 	NGE_LOOP_INTERNAL_PHY,
254 };
255 
256 /*
257  * (Internal) return values from send_msg subroutines
258  */
259 enum send_status {
260 	SEND_COPY_FAIL = -1,		/* => GLD_NORESOURCES	*/
261 	SEND_MAP_FAIL,			/* => GLD_NORESOURCES	*/
262 	SEND_COPY_SUCESS,		/* OK, msg queued	*/
263 	SEND_MAP_SUCCESS		/* OK, free msg		*/
264 };
265 
266 /*
267  * (Internal) return values from ioctl subroutines
268  */
269 enum ioc_reply {
270 	IOC_INVAL = -1,			/* bad, NAK with EINVAL	*/
271 	IOC_DONE,			/* OK, reply sent	*/
272 	IOC_ACK,			/* OK, just send ACK	*/
273 	IOC_REPLY,			/* OK, just send reply	*/
274 	IOC_RESTART_ACK,		/* OK, restart & ACK	*/
275 	IOC_RESTART_REPLY		/* OK, restart & reply	*/
276 };
277 
278 enum nge_pp_type {
279 	NGE_PP_SPACE_CFG = 0,
280 	NGE_PP_SPACE_REG,
281 	NGE_PP_SPACE_NIC,
282 	NGE_PP_SPACE_MII,
283 	NGE_PP_SPACE_NGE,
284 	NGE_PP_SPACE_TXDESC,
285 	NGE_PP_SPACE_TXBUFF,
286 	NGE_PP_SPACE_RXDESC,
287 	NGE_PP_SPACE_RXBUFF,
288 	NGE_PP_SPACE_STATISTICS,
289 	NGE_PP_SPACE_SEEPROM,
290 	NGE_PP_SPACE_FLASH
291 };
292 
293 /*
294  * Flag to kstat type
295  */
296 enum nge_kstat_type {
297 	NGE_KSTAT_RAW = 0,
298 	NGE_KSTAT_STATS,
299 	NGE_KSTAT_CHIPID,
300 	NGE_KSTAT_DEBUG,
301 	NGE_KSTAT_COUNT
302 };
303 
304 
305 /*
306  * Actual state of the nvidia's chip
307  */
308 enum nge_chip_state {
309 	NGE_CHIP_FAULT = -2,		/* fault, need reset	*/
310 	NGE_CHIP_ERROR,			/* error, want reset	*/
311 	NGE_CHIP_INITIAL,		/* Initial state only	*/
312 	NGE_CHIP_RESET,			/* reset, need init	*/
313 	NGE_CHIP_STOPPED,		/* Tx/Rx stopped	*/
314 	NGE_CHIP_RUNNING		/* with interrupts	*/
315 };
316 
317 enum nge_eeprom_size {
318 	EEPROM_1K = 0,
319 	EEPROM_2K,
320 	EEPROM_4K,
321 	EEPROM_8K,
322 	EEPROM_16K,
323 	EEPROM_32K,
324 	EEPROM_64K
325 };
326 
327 enum nge_eeprom_access_wid {
328 	ACCESS_8BIT = 0,
329 	ACCESS_16BIT
330 };
331 
332 /*
333  * MDIO operation
334  */
335 enum nge_mdio_operation {
336 	NGE_MDIO_READ = 0,
337 	NGE_MDIO_WRITE
338 };
339 
340 /*
341  * Speed selection
342  */
343 enum nge_speed {
344 	UNKOWN_SPEED = 0,
345 	NGE_10M,
346 	NGE_100M,
347 	NGE_1000M
348 };
349 
350 /*
351  * Duplex selection
352  */
353 enum nge_duplex {
354 	UNKOWN_DUPLEX = 0,
355 	NGE_HD,
356 	NGE_FD
357 };
358 
359 typedef struct {
360 	ether_addr_t		addr;		/* in canonical form	*/
361 	uint8_t			spare;
362 	uint8_t			set;		/* nonzero => valid	*/
363 } nge_mac_addr_t;
364 
365 struct nge;
366 
367 
368 #define	CHIP_FLAG_COPPER	0x40
369 
370 /*
371  * Collection of physical-layer functions to:
372  *	(re)initialise the physical layer
373  *	update it to match software settings
374  *	check for link status change
375  */
376 typedef struct {
377 	boolean_t	(*phys_restart)(struct nge *);
378 	void		(*phys_update)(struct nge *);
379 	boolean_t	(*phys_check)(struct nge *);
380 } phys_ops_t;
381 
382 struct nge_see_rw {
383 	uint32_t	see_addr;	/* Byte offset within SEEPROM	*/
384 	uint32_t	see_data;	/* Data read/data to write	*/
385 };
386 
387 typedef struct {
388 	uint64_t	pp_acc_size;	/* in bytes: 1,2,4,8	*/
389 	uint64_t	pp_acc_space;	/* See #defines below	*/
390 	uint64_t	pp_acc_offset;
391 	uint64_t	pp_acc_data;	/* output for peek	*/
392 					/* input for poke	*/
393 } nge_peekpoke_t;
394 
395 typedef uintptr_t 	nge_regno_t;	/* register # (offset)	*/
396 
397 typedef struct _mul_list {
398 	struct _mul_list *next;
399 	uint32_t ref_cnt;
400 	ether_addr_t mul_addr;
401 }mul_item, *pmul_item;
402 
403 /*
404  * Describes one chunk of allocated DMA-able memory
405  *
406  * In some cases, this is a single chunk as allocated from the system;
407  * but we also use this structure to represent slices carved off such
408  * a chunk.  Even when we don't really need all the information, we
409  * use this structure as a convenient way of correlating the various
410  * ways of looking at a piece of memory (kernel VA, IO space DVMA,
411  * handle+offset, etc).
412  */
413 typedef struct dma_area
414 {
415 
416 	caddr_t			private;	/* pointer to nge */
417 	frtn_t			rx_recycle;	/* recycle function */
418 	mblk_t			*mp;
419 	ddi_acc_handle_t	acc_hdl;	/* handle for memory	*/
420 	void			*mem_va;	/* CPU VA of memory	*/
421 	uint32_t		nslots;		/* number of slots	*/
422 	uint32_t		size;		/* size per slot	*/
423 	size_t			alength;	/* allocated size	*/
424 						/* >= product of above	*/
425 	ddi_dma_handle_t	dma_hdl;	/* DMA handle		*/
426 	offset_t		offset;		/* relative to handle	*/
427 	ddi_dma_cookie_t	cookie;		/* associated cookie	*/
428 	uint32_t		ncookies;
429 	uint32_t		signature;	/* buffer signature	*/
430 						/* for deciding to free */
431 						/* or to reuse buffers	*/
432 	boolean_t		rx_delivered;	/* hold by upper layer	*/
433 	struct dma_area		*next;
434 } dma_area_t;
435 
436 #define	HOST_OWN	0x00000000
437 #define	CONTROLER_OWN	0x00000001
438 #define	NGE_END_PACKET	0x00000002
439 
440 
441 typedef struct nge_dmah_node
442 {
443 	struct nge_dmah_node	*next;
444 	ddi_dma_handle_t	hndl;
445 } nge_dmah_node_t;
446 
447 typedef struct nge_dmah_list
448 {
449 	nge_dmah_node_t	*head;
450 	nge_dmah_node_t	*tail;
451 } nge_dmah_list_t;
452 
453 /*
454  * Software version of the Recv Descriptor
455  * There's one of these for each recv buffer (up to 512 per ring)
456  */
457 typedef struct sw_rx_sbd {
458 
459 	dma_area_t		desc;		/* (const) related h/w	*/
460 						/* descriptor area	*/
461 	dma_area_t		*bufp;		/* (const) related	*/
462 						/* buffer area		*/
463 	uint8_t			flags;
464 } sw_rx_sbd_t;
465 
466 /*
467  * Software version of the send Buffer Descriptor
468  * There's one of these for each send buffer (up to 512 per ring)
469  */
470 typedef struct sw_tx_sbd {
471 
472 	dma_area_t		desc;		/* (const) related h/w	*/
473 						/* descriptor area	*/
474 	dma_area_t		pbuf;		/* (const) related	*/
475 						/* buffer area		*/
476 	void			(*tx_recycle)(struct sw_tx_sbd *);
477 	uint32_t		flags;
478 	mblk_t			*mp;		/* related mblk, if any	*/
479 	nge_dmah_list_t		mp_hndl;
480 	uint32_t		frags;
481 	uint32_t		ncookies;	/* dma cookie number */
482 
483 } sw_tx_sbd_t;
484 
485 /*
486  * Software Receive Buffer (Producer) Ring Control Block
487  * There's one of these for each receiver producer ring (up to 3),
488  * but each holds buffers of a different size.
489  */
490 typedef struct buff_ring {
491 
492 	uint64_t		nslots;		/* descriptor area	*/
493 	struct nge		*ngep;		/* (const) containing	*/
494 						/* driver soft state	*/
495 						/* initialise same	*/
496 	uint64_t		rx_hold;
497 	sw_rx_sbd_t		*sw_rbds; 	/* software descriptors	*/
498 	sw_rx_sbd_t		*free_rbds;	/* free ring */
499 	dma_area_t		*free_list;	/* available buffer queue */
500 	dma_area_t		*recycle_list;	/* recycling buffer queue */
501 	kmutex_t		recycle_lock[1];
502 	uint32_t		buf_sign;	/* buffer ring signature */
503 						/* for deciding to free  */
504 						/* or to reuse buffers   */
505 	boolean_t		rx_bcopy;
506 } buff_ring_t;
507 
508 /*
509  * Software Receive (Return) Ring Control Block
510  * There's one of these for each receiver return ring (up to 16).
511  */
512 typedef struct recv_ring {
513 	/*
514 	 * The elements flagged (const) in the comments below are
515 	 * set up once during initialiation and thereafter unchanged.
516 	 */
517 	dma_area_t		desc;		/* (const) related h/w	*/
518 						/* descriptor area	*/
519 	struct nge		*ngep;		/* (const) containing	*/
520 						/* driver soft state	*/
521 	uint16_t		prod_index;	/* (const) ptr to h/w	*/
522 						/* "producer index"	*/
523 	mac_resource_handle_t	handle;
524 } recv_ring_t;
525 
526 
527 
528 /*
529  * Software Send Ring Control Block
530  * There's one of these for each of (up to) 1 send rings
531  */
532 typedef struct send_ring {
533 	/*
534 	 * The elements flagged (const) in the comments below are
535 	 * set up once during initialiation and thereafter unchanged.
536 	 */
537 	dma_area_t		desc;		/* (const) related h/w	*/
538 						/* descriptor area	*/
539 	dma_area_t		buf[NGE_SEND_SLOTS_BUF];
540 						/* buffer area(s)	*/
541 	struct nge		*ngep;		/* (const) containing	*/
542 						/* driver soft state	*/
543 
544 	uint64_t		tx_hwmark;
545 	uint64_t		tx_lwmark;
546 
547 	/*
548 	 * The tx_lock must be held when updating
549 	 * the s/w producer index
550 	 * (tx_next)
551 	 */
552 	kmutex_t		tx_lock[1];	/* serialize h/w update	*/
553 	uint64_t		tx_next;	/* next slot to use	*/
554 	uint64_t		tx_flow;
555 
556 	/*
557 	 * These counters/indexes are manipulated in the transmit
558 	 * path using atomics rather than mutexes for speed
559 	 */
560 	uint64_t		tx_free;	/* # of slots available	*/
561 
562 	/*
563 	 * index (tc_next).
564 	 */
565 	kmutex_t		tc_lock[1];
566 	uint64_t		tc_next;	/* next slot to recycle	*/
567 						/* ("consumer index")	*/
568 
569 	sw_tx_sbd_t		*sw_sbds; 	/* software descriptors	*/
570 
571 	kmutex_t		dmah_lock;
572 	nge_dmah_list_t		dmah_free;
573 	nge_dmah_node_t		dmahndl[NGE_MAX_DMA_HDR];
574 
575 } send_ring_t;
576 
577 
578 typedef struct {
579 	uint32_t		businfo;	/* from private reg	*/
580 	uint16_t		command;	/* saved during attach	*/
581 
582 	uint16_t		vendor;		/* vendor-id		*/
583 	uint16_t		device;		/* device-id		*/
584 	uint16_t		subven;		/* subsystem-vendor-id	*/
585 	uint16_t		subdev;		/* subsystem-id		*/
586 	uint8_t			class_code;
587 	uint8_t			revision;	/* revision-id		*/
588 	uint8_t			clsize;		/* cache-line-size	*/
589 	uint8_t			latency;	/* latency-timer	*/
590 	uint8_t			flags;
591 
592 	uint16_t		phy_type;	/* Fiber module type 	*/
593 	uint64_t		hw_mac_addr;	/* from chip register	*/
594 	nge_mac_addr_t		vendor_addr;	/* transform of same	*/
595 } chip_info_t;
596 
597 
598 typedef struct {
599 	offset_t	index;
600 	char		*name;
601 } nge_ksindex_t;
602 
603 typedef struct {
604 	uint64_t tso_err_mss;
605 	uint64_t tso_dis;
606 	uint64_t tso_err_nosum;
607 	uint64_t tso_err_hov;
608 	uint64_t tso_err_huf;
609 	uint64_t tso_err_l2;
610 	uint64_t tso_err_ip;
611 	uint64_t tso_err_l4;
612 	uint64_t tso_err_tcp;
613 	uint64_t hsum_err_ip;
614 	uint64_t hsum_err_l4;
615 }fe_statistics_t;
616 
617 /*
618  * statistics parameters to tune the driver
619  */
620 typedef struct {
621 	uint64_t		intr_count;
622 	uint64_t		intr_lval;
623 	uint64_t		recv_realloc;
624 	uint64_t		poll_time;
625 	uint64_t		recy_free;
626 	uint64_t		recv_count;
627 	uint64_t		xmit_count;
628 	uint64_t		obytes;
629 	uint64_t		rbytes;
630 	uint64_t		mp_alloc_err;
631 	uint64_t		dma_alloc_err;
632 	uint64_t		kmem_alloc_err;
633 	uint64_t		load_context;
634 	uint64_t		ip_hwsum_err;
635 	uint64_t		tcp_hwsum_err;
636 	uint64_t		rx_nobuffer;
637 	uint64_t		rx_err;
638 	uint64_t		tx_stop_err;
639 	uint64_t		tx_stall;
640 	uint64_t		tx_rsrv_fail;
641 	uint64_t		tx_resched;
642 	fe_statistics_t	fe_err;
643 }nge_sw_statistics_t;
644 
645 typedef struct {
646 	nge_hw_statistics_t	hw_statistics;
647 	nge_sw_statistics_t	sw_statistics;
648 }nge_statistics_t;
649 
650 struct nge_desc_attr	{
651 
652 	size_t	rxd_size;
653 	size_t	txd_size;
654 
655 	ddi_dma_attr_t	*dma_attr;
656 	ddi_dma_attr_t	*tx_dma_attr;
657 
658 	void (*rxd_fill)(void *, const ddi_dma_cookie_t *, size_t);
659 	uint32_t (*rxd_check)(const void *, size_t *);
660 
661 	void (*txd_fill)(void *, const ddi_dma_cookie_t *, size_t,
662 			uint32_t, boolean_t);
663 
664 	uint32_t (*txd_check)(const void *, size_t *);
665 };
666 
667 typedef struct nge_desc_attr nge_desc_attr_t;
668 
669 /*
670  * Structure used to hold the device-specific config parameters.
671  * The setting of such parameters may not consistent with the
672  * hardware feature of the device. It's used for software purpose.
673  */
674 typedef struct nge_dev_spec_param {
675 	boolean_t	msi;		/* specifies msi support */
676 	boolean_t	msi_x;		/* specifies msi_x support */
677 	boolean_t	vlan;		/* specifies vlan support */
678 	boolean_t	advanced_pm;	/* advanced power management support */
679 	boolean_t	tx_pause_frame;	/* specifies tx pause frame support */
680 	boolean_t	rx_pause_frame;	/* specifies rx pause frame support */
681 	boolean_t	jumbo;		/* jumbo frame support */
682 	boolean_t	tx_rx_64byte;	/* set the max tx/rx prd fetch size */
683 	boolean_t	rx_hw_checksum;	/* specifies tx hw checksum feature */
684 	uint32_t	tx_hw_checksum;	/* specifies rx hw checksum feature */
685 	uint32_t	desc_type;	/* specifies descriptor type */
686 	uint32_t	rx_desc_num;	/* specifies rx descriptor number */
687 	uint32_t	tx_desc_num;	/* specifies tx descriptor number */
688 	uint32_t	nge_split;	/* specifies the split number */
689 } nge_dev_spec_param_t;
690 
691 typedef struct nge {
692 	/*
693 	 * These fields are set by attach() and unchanged thereafter ...
694 	 */
695 	dev_info_t		*devinfo;	/* device instance	*/
696 	mac_handle_t		mh;		/* mac module handle    */
697 	chip_info_t		chipinfo;
698 	ddi_acc_handle_t	cfg_handle;	/* DDI I/O handle	*/
699 	ddi_acc_handle_t	io_handle;	/* DDI I/O handle	*/
700 	void			*io_regs;	/* mapped registers	*/
701 
702 	ddi_periodic_t		periodic_id;	/* periodical callback	*/
703 	uint32_t		factotum_flag;
704 	ddi_softint_handle_t	factotum_hdl;	/* factotum callback	*/
705 	ddi_softint_handle_t	resched_hdl;	/* reschedule callback	*/
706 	uint_t			soft_pri;
707 
708 	ddi_intr_handle_t 	*htable;	/* for array of interrupts */
709 	int			intr_type;	/* type of interrupt */
710 	int			intr_actual_cnt; /* alloc intrs count */
711 	int			intr_req_cnt;	/* request intrs count */
712 	uint_t			intr_pri;	/* interrupt priority	*/
713 	int			intr_cap;	/* interrupt capabilities */
714 
715 	uint32_t		progress;	/* attach tracking	*/
716 	uint32_t		debug;		/* flag to debug function */
717 
718 	char			ifname[8];	/* "nge0" ... "nge999" */
719 
720 
721 	enum nge_mac_state	nge_mac_state;	/* definitions above	*/
722 	enum nge_chip_state	nge_chip_state; /* definitions above	*/
723 	boolean_t		promisc;
724 	boolean_t		suspended;
725 
726 	int			resched_needed;
727 	uint32_t		default_mtu;
728 	uint32_t		max_sdu;
729 	uint32_t		buf_size;
730 	uint32_t		rx_desc;
731 	uint32_t		tx_desc;
732 	uint32_t		rx_buf;
733 	uint32_t		nge_split;
734 	uint32_t		watchdog;
735 	uint32_t		lowmem_mode;
736 
737 
738 	/*
739 	 * Runtime read-write data starts here ...
740 	 * 1 Receive Rings
741 	 * 1 Send Rings
742 	 *
743 	 * Note: they're not necessarily all used.
744 	 */
745 	struct buff_ring	buff[1];
746 	struct recv_ring	recv[1];
747 	struct send_ring	send[1];
748 
749 
750 	kmutex_t		genlock[1];
751 	krwlock_t		rwlock[1];
752 	kmutex_t		softlock[1];
753 	uint32_t		intr_masks;
754 	boolean_t		poll;
755 	boolean_t		ch_intr_mode;
756 	boolean_t		intr_moderation;
757 	uint32_t		recv_count;
758 	uint32_t		quiet_time;
759 	uint32_t		busy_time;
760 	uint32_t		stint_count;
761 	uint32_t		sw_intr_intv;
762 	nge_mac_addr_t		cur_uni_addr;
763 	uint32_t		rx_datahwm;
764 	uint32_t		rx_prdlwm;
765 	uint32_t		rx_prdhwm;
766 	uint32_t		rx_def;
767 	uint32_t		desc_mode;
768 
769 	mul_item		*pcur_mulist;
770 	nge_mac_addr_t		cur_mul_addr;
771 	nge_mac_addr_t		cur_mul_mask;
772 
773 	nge_desc_attr_t		desc_attr;
774 
775 	/*
776 	 * Link state data (protected by genlock)
777 	 */
778 	int32_t			link_state;	/* See GLD #defines	*/
779 	uint32_t		stall_cknum;	/* Stall check number */
780 
781 	uint32_t		phy_xmii_addr;
782 	uint32_t		phy_id;
783 	uint32_t		phy_mode;
784 	const phys_ops_t	*physops;
785 	uint16_t		phy_gen_status;
786 
787 	uint32_t		param_loop_mode;
788 
789 	kstat_t			*nge_kstats[NGE_KSTAT_COUNT];
790 	nge_statistics_t	statistics;
791 
792 	nge_dev_spec_param_t	dev_spec_param;
793 
794 	uint32_t		param_en_pause:1,
795 				param_en_asym_pause:1,
796 				param_en_1000hdx:1,
797 				param_en_1000fdx:1,
798 				param_en_100fdx:1,
799 				param_en_100hdx:1,
800 				param_en_10fdx:1,
801 				param_en_10hdx:1,
802 				param_adv_autoneg:1,
803 				param_adv_pause:1,
804 				param_adv_asym_pause:1,
805 				param_adv_1000fdx:1,
806 				param_adv_1000hdx:1,
807 				param_adv_100fdx:1,
808 				param_adv_100hdx:1,
809 				param_adv_10fdx:1,
810 				param_adv_10hdx:1,
811 				param_lp_autoneg:1,
812 				param_lp_pause:1,
813 				param_lp_asym_pause:1,
814 				param_lp_1000fdx:1,
815 				param_lp_1000hdx:1,
816 				param_lp_100fdx:1,
817 				param_lp_100hdx:1,
818 				param_lp_10fdx:1,
819 				param_lp_10hdx:1,
820 				param_link_up:1,
821 				param_link_autoneg:1,
822 				param_link_rx_pause:1,
823 				param_link_tx_pause:1,
824 				param_pad_to_32:2;
825 	uint64_t		param_link_speed;
826 	link_duplex_t		param_link_duplex;
827 	int			param_txbcopy_threshold;
828 	int			param_rxbcopy_threshold;
829 	int			param_recv_max_packet;
830 	int			param_poll_quiet_time;
831 	int			param_poll_busy_time;
832 	int			param_rx_intr_hwater;
833 	int			param_rx_intr_lwater;
834 	int			param_tx_n_intr;
835 } nge_t;
836 
837 extern const nge_ksindex_t nge_statistics[];
838 
839 /*
840  * Sync a DMA area described by a dma_area_t
841  */
842 #define	DMA_SYNC(area, flag)	((void) ddi_dma_sync((area).dma_hdl,	\
843 				    (area).offset, (area).alength, (flag)))
844 
845 /*
846  * Find the (kernel virtual) address of block of memory
847  * described by a dma_area_t
848  */
849 #define	DMA_VPTR(area)		((area).mem_va)
850 
851 /*
852  * Zero a block of memory described by a dma_area_t
853  */
854 #define	DMA_ZERO(area)		bzero(DMA_VPTR(area), (area).alength)
855 
856 /*
857  * Next/Prev value of a cyclic index
858  */
859 #define	NEXT(index, limit)	((index) + 1 < (limit) ? (index) + 1 : 0)
860 #define	PREV(index, limit)	(0 == (index) ? (limit - 1) : (index) - 1)
861 
862 #define	NEXT_INDEX(ndx, num, lim)\
863 	(((ndx) + (num) < (lim)) ? ((ndx) + (num)) : ((ndx) + (num) - (lim)))
864 
865 
866 /*
867  * Property lookups
868  */
869 #define	NGE_PROP_EXISTS(d, n)	ddi_prop_exists(DDI_DEV_T_ANY, (d),	\
870 					DDI_PROP_DONTPASS, (n))
871 #define	NGE_PROP_GET_INT(d, n)	ddi_prop_get_int(DDI_DEV_T_ANY, (d),	\
872 					DDI_PROP_DONTPASS, (n), -1)
873 
874 
875 /*
876  * Debugging ...
877  */
878 #ifdef	DEBUG
879 #define	NGE_DEBUGGING		1
880 #else
881 #define	NGE_DEBUGGING		0
882 #endif	/* DEBUG */
883 
884 /*
885  * Bit flags in the 'debug' word ...
886  */
887 #define	NGE_DBG_STOP		0x00000001	/* early debug_enter()	*/
888 #define	NGE_DBG_TRACE		0x00000002	/* general flow tracing	*/
889 
890 #define	NGE_DBG_MII		0x00000010	/* low-level MII access	*/
891 #define	NGE_DBG_CHIP		0x00000020	/* low(ish)-level code	*/
892 
893 #define	NGE_DBG_RECV		0x00000100	/* receive-side code	*/
894 #define	NGE_DBG_SEND		0x00000200	/* packet-send code	*/
895 
896 #define	NGE_DBG_INIT		0x00100000	/* initialisation	*/
897 #define	NGE_DBG_NEMO		0x00200000	/* MAC layer entry points */
898 #define	NGE_DBG_STATS		0x00400000	/* statistics		*/
899 
900 #define	NGE_DBG_BADIOC		0x01000000	/* unknown ioctls	*/
901 
902 #define	NGE_DBG_NDD		0x10000000	/* NDD operations	*/
903 
904 
905 
906 /*
907  * 'Do-if-debugging' macro.  The parameter <command> should be one or more
908  * C statements (but without the *final* semicolon), which will either be
909  * compiled inline or completely ignored, depending on the NGE_DEBUGGING
910  * compile-time flag.
911  *
912  * You should get a compile-time error (at least on a DEBUG build) if
913  * your statement isn't actually a statement, rather than unexpected
914  * run-time behaviour caused by unintended matching of if-then-elses etc.
915  *
916  * Note that the NGE_DDB() macro itself can only be used as a statement,
917  * not an expression, and should always be followed by a semicolon.
918  */
919 #if NGE_DEBUGGING
920 #define	NGE_DDB(command)	do {					\
921 					{ command; }			\
922 					_NOTE(CONSTANTCONDITION)	\
923 				} while (0)
924 #else 	/* NGE_DEBUGGING */
925 #define	NGE_DDB(command)
926 /*
927  * Old way of debugging.  This is a poor way, as it leeaves empty
928  * statements that cause lint to croak.
929  * #define	NGE_DDB(command)	do {				\
930  * 					{ _NOTE(EMPTY); }		\
931  * 					_NOTE(CONSTANTCONDITION)	\
932  * 				} while (0)
933  */
934 #endif	/* NGE_DEBUGGING */
935 
936 /*
937  * 'Internal' macros used to construct the TRACE/DEBUG macros below.
938  * These provide the primitive conditional-call capability required.
939  * Note: the parameter <args> is a parenthesised list of the actual
940  * printf-style arguments to be passed to the debug function ...
941  */
942 #define	NGE_XDB(b, w, f, args)	NGE_DDB(if ((b) & (w)) f args)
943 #define	NGE_GDB(b, args)	NGE_XDB(b, nge_debug, (*nge_gdb()), args)
944 #define	NGE_LDB(b, args)	NGE_XDB(b, ngep->debug, \
945 				    (*nge_db(ngep)), args)
946 #define	NGE_CDB(f, args)	NGE_XDB(NGE_DBG, ngep->debug, f, args)
947 
948 /*
949  * Conditional-print macros.
950  *
951  * Define NGE_DBG to be the relevant member of the set of NGE_DBG_* values
952  * above before using the NGE_GDEBUG() or NGE_DEBUG() macros.  The 'G'
953  * versions look at the Global debug flag word (nge_debug); the non-G
954  * versions look in the per-instance data (ngep->debug) and so require a
955  * variable called 'ngep' to be in scope (and initialised!) before use.
956  *
957  * You could redefine NGE_TRC too if you really need two different
958  * flavours of debugging output in the same area of code, but I don't
959  * really recommend it.
960  *
961  * Note: the parameter <args> is a parenthesised list of the actual
962  * arguments to be passed to the debug function, usually a printf-style
963  * format string and corresponding values to be formatted.
964  */
965 
966 #define	NGE_TRC	NGE_DBG_TRACE
967 
968 #define	NGE_GTRACE(args)	NGE_GDB(NGE_TRC, args)
969 #define	NGE_GDEBUG(args)	NGE_GDB(NGE_DBG, args)
970 #define	NGE_TRACE(args)		NGE_LDB(NGE_TRC, args)
971 #define	NGE_DEBUG(args)		NGE_LDB(NGE_DBG, args)
972 
973 /*
974  * Debug-only action macros
975  */
976 
977 
978 #define	NGE_REPORT(args)	NGE_DDB(nge_log args)
979 
980 boolean_t nge_atomic_decrease(uint64_t *count_p, uint64_t n);
981 void nge_atomic_increase(uint64_t *count_p, uint64_t n);
982 
983 int nge_alloc_dma_mem(nge_t *ngep, size_t memsize,
984     ddi_device_acc_attr_t *attr_p, uint_t dma_flags, dma_area_t *dma_p);
985 void nge_free_dma_mem(dma_area_t *dma_p);
986 int nge_restart(nge_t *ngep);
987 void nge_wake_factotum(nge_t *ngep);
988 
989 uint8_t nge_reg_get8(nge_t *ngep, nge_regno_t regno);
990 void nge_reg_put8(nge_t *ngep, nge_regno_t regno, uint8_t data);
991 uint16_t nge_reg_get16(nge_t *ngep, nge_regno_t regno);
992 void nge_reg_put16(nge_t *ngep, nge_regno_t regno, uint16_t data);
993 uint32_t nge_reg_get32(nge_t *ngep, nge_regno_t regno);
994 void nge_reg_put32(nge_t *ngep, nge_regno_t regno, uint32_t data);
995 uint_t nge_chip_factotum(caddr_t args1, caddr_t args2);
996 void nge_chip_cfg_init(nge_t *ngep, chip_info_t *infop, boolean_t reset);
997 void nge_init_dev_spec_param(nge_t *ngep);
998 int nge_chip_stop(nge_t *ngep, boolean_t fault);
999 void nge_restore_mac_addr(nge_t *ngep);
1000 int nge_chip_reset(nge_t *ngep);
1001 int nge_chip_start(nge_t *ngep);
1002 void nge_chip_sync(nge_t *ngep);
1003 
1004 uint_t nge_chip_intr(caddr_t arg1, caddr_t arg2);
1005 enum ioc_reply nge_chip_ioctl(nge_t *ngep, mblk_t *mp, struct iocblk *iocp);
1006 
1007 void nge_phys_init(nge_t *ngep);
1008 boolean_t nge_phy_reset(nge_t *ngep);
1009 uint16_t nge_mii_get16(nge_t *ngep, nge_regno_t regno);
1010 void nge_mii_put16(nge_t *ngep, nge_regno_t regno, uint16_t data);
1011 
1012 void nge_recv_recycle(caddr_t arg);
1013 void nge_receive(nge_t *ngep);
1014 
1015 uint_t nge_reschedule(caddr_t args1, caddr_t args2);
1016 mblk_t *nge_m_tx(void *arg, mblk_t *mp);
1017 
1018 void nge_tx_recycle(nge_t *ngep, boolean_t is_intr);
1019 void nge_tx_recycle_all(nge_t *ngep);
1020 
1021 int nge_nd_init(nge_t *ngep);
1022 void nge_nd_cleanup(nge_t *ngep);
1023 
1024 
1025 void nge_init_kstats(nge_t *ngep, int instance);
1026 void nge_fini_kstats(nge_t *ngep);
1027 int nge_m_stat(void *arg, uint_t stat, uint64_t *val);
1028 
1029 uint32_t nge_atomic_shl32(uint32_t *sp, uint_t count);
1030 
1031 void nge_log(nge_t *ngep, const char *fmt, ...);
1032 void nge_problem(nge_t *ngep, const char *fmt, ...);
1033 void nge_error(nge_t *ngep, const char *fmt, ...);
1034 void
1035 nge_report(nge_t *ngep, uint8_t error_id);
1036 
1037 void (*nge_db(nge_t *ngep))(const char *fmt, ...);
1038 void (*nge_gdb(void))(const char *fmt, ...);
1039 extern	uint32_t nge_debug;
1040 
1041 /*
1042  * DESC MODE 2
1043  */
1044 
1045 extern void nge_sum_rxd_fill(void *, const ddi_dma_cookie_t *, size_t);
1046 extern uint32_t nge_sum_rxd_check(const void *, size_t *);
1047 
1048 extern void nge_sum_txd_fill(void *, const ddi_dma_cookie_t *,
1049 				size_t, uint32_t, boolean_t);
1050 extern uint32_t nge_sum_txd_check(const void *, size_t *);
1051 
1052 /*
1053  * DESC MODE 3
1054  */
1055 
1056 extern void nge_hot_rxd_fill(void *, const ddi_dma_cookie_t *, size_t);
1057 extern uint32_t nge_hot_rxd_check(const void *, size_t *);
1058 
1059 extern void nge_hot_txd_fill(void *, const ddi_dma_cookie_t *,
1060 				size_t, uint32_t, boolean_t);
1061 extern uint32_t nge_hot_txd_check(const void *, size_t *);
1062 
1063 #ifdef __cplusplus
1064 }
1065 #endif
1066 
1067 #endif	/* _SYS_NGE_H */
1068