xref: /titanic_41/usr/src/uts/common/io/bge/bge_impl.h (revision 9fb67ea305c66b6a297583b9b0db6796b0dfe497)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _BGE_IMPL_H
28 #define	_BGE_IMPL_H
29 
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/types.h>
36 #include <sys/stream.h>
37 #include <sys/strsun.h>
38 #include <sys/strsubr.h>
39 #include <sys/stat.h>
40 #include <sys/pci.h>
41 #include <sys/note.h>
42 #include <sys/modctl.h>
43 #include <sys/crc32.h>
44 #ifdef	__sparcv9
45 #include <v9/sys/membar.h>
46 #endif	/* __sparcv9 */
47 #include <sys/kstat.h>
48 #include <sys/ethernet.h>
49 #include <sys/vlan.h>
50 #include <sys/errno.h>
51 #include <sys/dlpi.h>
52 #include <sys/devops.h>
53 #include <sys/debug.h>
54 #include <sys/conf.h>
55 
56 #include <netinet/ip6.h>
57 
58 #include <inet/common.h>
59 #include <inet/ip.h>
60 #include <inet/mi.h>
61 #include <inet/nd.h>
62 #include <sys/pattr.h>
63 
64 #include <sys/disp.h>
65 #include <sys/cmn_err.h>
66 #include <sys/ddi.h>
67 #include <sys/sunddi.h>
68 
69 #include <sys/ddifm.h>
70 #include <sys/fm/protocol.h>
71 #include <sys/fm/util.h>
72 #include <sys/fm/io/ddi.h>
73 
74 #include <sys/mac_provider.h>
75 #include <sys/mac_ether.h>
76 
77 #ifdef __amd64
78 #include <sys/x86_archext.h>
79 #endif
80 
81 /*
82  * <sys/ethernet.h> *may* already have provided the typedef ether_addr_t;
83  * but of course C doesn't provide a way to check this directly.  So here
84  * we rely on the fact that the symbol ETHERTYPE_AT was added to the
85  * header file (as a #define, which we *can* test for) at the same time
86  * as the typedef for ether_addr_t ;-!
87  */
88 #ifndef	ETHERTYPE_AT
89 typedef uchar_t ether_addr_t[ETHERADDRL];
90 #endif	/* ETHERTYPE_AT */
91 
92 /*
93  * Reconfiguring the network devices requires the net_config privilege
94  * in Solaris 10+.
95  */
96 extern int secpolicy_net_config(const cred_t *, boolean_t);
97 
98 #include <sys/netlb.h>			/* originally from cassini	*/
99 #include <sys/miiregs.h>		/* by fjlite out of intel 	*/
100 
101 #include "bge.h"
102 #include "bge_hw.h"
103 
104 /*
105  * Compile-time feature switches ...
106  */
107 #define	BGE_DO_PPIO		0	/* peek/poke ioctls		*/
108 #define	BGE_RX_SOFTINT		0	/* softint per receive ring	*/
109 #define	BGE_CHOOSE_SEND_METHOD	0	/* send by copying only		*/
110 
111 /*
112  * NOTES:
113  *
114  * #defines:
115  *
116  *	BGE_PCI_CONFIG_RNUMBER and BGE_PCI_OPREGS_RNUMBER are the
117  *	register-set numbers to use for the config space registers
118  *	and the operating registers respectively.  On an OBP-based
119  *	machine, regset 0 refers to CONFIG space, and regset 1 will
120  *	be the operating registers in MEMORY space.  If an expansion
121  *	ROM is fitted, it may appear as a further register set.
122  *
123  *	BGE_DMA_MODE defines the mode (STREAMING/CONSISTENT) used
124  *	for the data buffers.  The descriptors are always set up
125  *	in CONSISTENT mode.
126  *
127  *	BGE_HEADROOM defines how much space we'll leave in allocated
128  *	mblks before the first valid data byte.  This should be chosen
129  *	to be 2 modulo 4, so that once the ethernet header (14 bytes)
130  *	has been stripped off, the packet data will be 4-byte aligned.
131  *	The remaining space can be used by upstream modules to prepend
132  *	any headers required.
133  */
134 
135 #define	BGE_PCI_CONFIG_RNUMBER	0
136 #define	BGE_PCI_OPREGS_RNUMBER	1
137 #define	BGE_DMA_MODE		DDI_DMA_STREAMING
138 #define	BGE_HEADROOM		34
139 
140 /*
141  *	BGE_HALFTICK is half the period of the cyclic callback (in
142  *	nanoseconds), chosen so that 0.5s <= cyclic period <= 1s.
143  *	Other time values are derived as odd multiples of this value
144  *	so that there's little chance of ambiguity w.r.t. which tick
145  *	a timeout expires on.
146  *
147  *	BGE_PHY_STABLE_TIME is the period for which the contents of the
148  *	PHY's status register must remain unchanging before we accept
149  *	that the link has come up.  [Sometimes the link comes up, only
150  *	to go down again within a short time as the autonegotiation
151  *	process cycles through various options before finding the best
152  *	compatible mode.  We don't want to report repeated link up/down
153  *	cycles, so we wait until we think it's stable.]
154  *
155  *	BGE_SERDES_STABLE_TIME is the analogous value for the SerDes
156  *	interface.  It's much shorter, 'cos the SerDes doesn't show
157  *	these effects as much as the copper PHY.
158  *
159  *	BGE_LINK_SETTLE_TIME is the period during which we regard link
160  *	up/down cycles as an normal event after resetting/reprogramming
161  *	the PHY.  During this time, link up/down messages are sent to
162  *	the log only, not the console.  At any other time, link change
163  *	events are regarded as unexpected and sent to both console & log.
164  *
165  *	These latter two values have no theoretical justification, but
166  *	are derived from observations and heuristics - the values below
167  *	just seem to work quite well.
168  */
169 
170 #define	BGE_HALFTICK		268435456LL		/* 2**28 ns!	*/
171 #define	BGE_CYCLIC_PERIOD	(2*BGE_HALFTICK)	/*    ~0.5s	*/
172 #define	BGE_SERDES_STABLE_TIME	(3*BGE_HALFTICK)	/*    ~0.8s	*/
173 #define	BGE_PHY_STABLE_TIME	(11*BGE_HALFTICK)	/*    ~3.0s	*/
174 #define	BGE_LINK_SETTLE_TIME	(111*BGE_HALFTICK)	/*   ~30.0s	*/
175 
176 /*
177  * Indices used to identify the different buffer rings internally
178  */
179 #define	BGE_STD_BUFF_RING	0
180 #define	BGE_JUMBO_BUFF_RING	1
181 #define	BGE_MINI_BUFF_RING	2
182 
183 /*
184  * Current implementation limits
185  */
186 #define	BGE_BUFF_RINGS_USED	2		/* std & jumbo ring	*/
187 						/* for now		*/
188 #define	BGE_RECV_RINGS_USED	16		/* up to 16 rtn rings	*/
189 						/* for now		*/
190 #define	BGE_SEND_RINGS_USED	4		/* up to 4 tx rings	*/
191 						/* for now		*/
192 #define	BGE_HASH_TABLE_SIZE	128		/* may be 256 later	*/
193 
194 /*
195  * Ring/buffer size parameters
196  *
197  * All of the (up to) 16 TX rings & and the corresponding buffers are the
198  * same size.
199  *
200  * Each of the (up to) 3 receive producer (aka buffer) rings is a different
201  * size and has different sized buffers associated with it too.
202  *
203  * The (up to) 16 receive return rings have no buffers associated with them.
204  * The number of slots per receive return ring must be 2048 if the mini
205  * ring is enabled, otherwise it may be 1024.  See Broadcom document
206  * 570X-PG102-R page 56.
207  *
208  * Note: only the 5700 supported external memory (and therefore the mini
209  * ring); the 5702/3/4 don't.  This driver doesn't support the original
210  * 5700, so we won't ever use the mini ring capability.
211  */
212 
213 #define	BGE_SEND_RINGS_DEFAULT		1
214 #define	BGE_RECV_RINGS_DEFAULT		1
215 
216 #define	BGE_SEND_BUFF_SIZE_DEFAULT	1536
217 #define	BGE_SEND_BUFF_SIZE_JUMBO	9022
218 #define	BGE_SEND_SLOTS_USED	512
219 
220 #define	BGE_STD_BUFF_SIZE	1536		/* 0x600		*/
221 #define	BGE_STD_SLOTS_USED	512
222 
223 #define	BGE_JUMBO_BUFF_SIZE	9022		/* 9k			*/
224 #define	BGE_JUMBO_SLOTS_USED	256
225 
226 #define	BGE_MINI_BUFF_SIZE	128		/* 64? 256?		*/
227 #define	BGE_MINI_SLOTS_USED	0		/* must be 0; see above	*/
228 
229 #define	BGE_RECV_BUFF_SIZE	0
230 #if	BGE_MINI_SLOTS_USED > 0
231 #define	BGE_RECV_SLOTS_USED	2048		/* required		*/
232 #else
233 #define	BGE_RECV_SLOTS_USED	1024		/* could be 2048 anyway	*/
234 #endif
235 
236 #define	BGE_SEND_BUF_NUM	512
237 #define	BGE_SEND_BUF_ARRAY	16
238 #define	BGE_SEND_BUF_ARRAY_JUMBO	3
239 #define	BGE_SEND_BUF_MAX	(BGE_SEND_BUF_NUM*BGE_SEND_BUF_ARRAY)
240 
241 /*
242  * PCI type. PCI-Express or PCI/PCIX
243  */
244 #define	BGE_PCI		0
245 #define	BGE_PCI_E	1
246 #define	BGE_PCI_X	2
247 
248 /*
249  * Statistic type. There are two type of statistic:
250  * statistic block and statistic registers
251  */
252 #define	BGE_STAT_BLK	1
253 #define	BGE_STAT_REG	2
254 
255 /*
256  * MTU.for all chipsets ,the default is 1500 ,and some chipsets
257  * support 9k jumbo frames size
258  */
259 #define	BGE_DEFAULT_MTU		1500
260 #define	BGE_MAXIMUM_MTU		9000
261 
262 /*
263  * Pad the h/w defined status block (which can be up to 80 bytes long)
264  * to a power-of-two boundary
265  */
266 #define	BGE_STATUS_PADDING	(128 - sizeof (bge_status_t))
267 
268 /*
269  * On platforms which support DVMA, we can simply allocate one big piece
270  * of memory for all the Tx buffers and another for the Rx buffers, and
271  * then carve them up as required.  It doesn't matter if they aren't just
272  * one physically contiguous piece each, because both the CPU *and* the
273  * I/O device can see them *as though they were*.
274  *
275  * However, if only physically-addressed DMA is possible, this doesn't
276  * work; we can't expect to get enough contiguously-addressed memory for
277  * all the buffers of each type, so in this case we request a number of
278  * smaller pieces, each still large enough for several buffers but small
279  * enough to fit within "an I/O page" (e.g. 64K).
280  *
281  * The #define below specifies how many pieces of memory are to be used;
282  * 16 has been shown to work on an i86pc architecture but this could be
283  * different on other non-DVMA platforms ...
284  */
285 #ifdef	_DMA_USES_VIRTADDR
286 #define	BGE_SPLIT		1		/* no split required	*/
287 #else
288 #if ((BGE_BUFF_RINGS_USED > 1) || (BGE_SEND_RINGS_USED > 1) || \
289 	(BGE_RECV_RINGS_USED > 1))
290 #define	BGE_SPLIT		128		/* split 128 ways	*/
291 #else
292 #define	BGE_SPLIT		16		/* split 16 ways	*/
293 #endif
294 #endif	/* _DMA_USES_VIRTADDR */
295 
296 #define	BGE_RECV_RINGS_SPLIT	(BGE_RECV_RINGS_MAX + 1)
297 
298 /*
299  * STREAMS parameters
300  */
301 #define	BGE_IDNUM		0		/* zero seems to work	*/
302 #define	BGE_LOWAT		(256)
303 #define	BGE_HIWAT		(256*1024)
304 
305 
306 /*
307  * Basic data types, for clarity in distinguishing 'numbers'
308  * used for different purposes ...
309  *
310  * A <bge_regno_t> is a register 'address' (offset) in any one of
311  * various address spaces (PCI config space, PCI memory-mapped I/O
312  * register space, MII registers, etc).  None of these exceeds 64K,
313  * so we could use a 16-bit representation but pointer-sized objects
314  * are more "natural" in most architectures; they seem to be handled
315  * more efficiently on SPARC and no worse on x86.
316  *
317  * BGE_REGNO_NONE represents the non-existent value in this space.
318  */
319 typedef uintptr_t bge_regno_t;			/* register # (offset)	*/
320 #define	BGE_REGNO_NONE		(~(uintptr_t)0u)
321 
322 /*
323  * Describes one chunk of allocated DMA-able memory
324  *
325  * In some cases, this is a single chunk as allocated from the system;
326  * but we also use this structure to represent slices carved off such
327  * a chunk.  Even when we don't really need all the information, we
328  * use this structure as a convenient way of correlating the various
329  * ways of looking at a piece of memory (kernel VA, IO space DVMA,
330  * handle+offset, etc).
331  */
332 typedef struct {
333 	ddi_acc_handle_t	acc_hdl;	/* handle for memory	*/
334 	void			*mem_va;	/* CPU VA of memory	*/
335 	uint32_t		nslots;		/* number of slots	*/
336 	uint32_t		size;		/* size per slot	*/
337 	size_t			alength;	/* allocated size	*/
338 						/* >= product of above	*/
339 
340 	ddi_dma_handle_t	dma_hdl;	/* DMA handle		*/
341 	offset_t		offset;		/* relative to handle	*/
342 	ddi_dma_cookie_t	cookie;		/* associated cookie	*/
343 	uint32_t		ncookies;	/* must be 1		*/
344 	uint32_t		token;		/* arbitrary identifier	*/
345 } dma_area_t;					/* 0x50 (80) bytes	*/
346 
347 typedef struct bge_queue_item {
348 	struct bge_queue_item	*next;
349 	void			*item;
350 } bge_queue_item_t;
351 
352 typedef struct bge_queue {
353 	bge_queue_item_t	*head;
354 	uint32_t		count;
355 	kmutex_t		*lock;
356 } bge_queue_t;
357 /*
358  * Software version of the Receive Buffer Descriptor
359  * There's one of these for each receive buffer (up to 256/512/1024 per ring).
360  */
361 typedef struct sw_rbd {
362 	dma_area_t		pbuf;		/* (const) related	*/
363 						/* buffer area		*/
364 } sw_rbd_t;					/* 0x50 (80) bytes	*/
365 
366 /*
367  * Software Receive Buffer (Producer) Ring Control Block
368  * There's one of these for each receiver producer ring (up to 3),
369  * but each holds buffers of a different size.
370  */
371 typedef struct buff_ring {
372 	dma_area_t		desc;		/* (const) related h/w	*/
373 						/* descriptor area	*/
374 	dma_area_t		buf[BGE_SPLIT];	/* (const) related	*/
375 						/* buffer area(s)	*/
376 	bge_rcb_t		hw_rcb;		/* (const) image of h/w	*/
377 						/* RCB, and used to	*/
378 	struct bge		*bgep;		/* (const) containing	*/
379 						/* driver soft state	*/
380 						/* initialise same	*/
381 	volatile uint16_t	*cons_index_p;	/* (const) ptr to h/w	*/
382 						/* "consumer index"	*/
383 						/* (in status block)	*/
384 
385 	/*
386 	 * The rf_lock must be held when updating the h/w producer index
387 	 * mailbox register (*chip_mbox_reg), or the s/w producer index
388 	 * (rf_next).
389 	 */
390 	bge_regno_t		chip_mbx_reg;	/* (const) h/w producer	*/
391 						/* index mailbox offset	*/
392 	kmutex_t		rf_lock[1];	/* serialize refill	*/
393 	uint64_t		rf_next;	/* next slot to refill	*/
394 						/* ("producer index")	*/
395 
396 	sw_rbd_t		*sw_rbds; 	/* software descriptors	*/
397 	void			*spare[4];	/* padding		*/
398 } buff_ring_t;					/* 0x100 (256) bytes	*/
399 
400 typedef struct bge_multi_mac {
401 	int		naddr;		/* total supported addresses */
402 	int		naddrfree;	/* free addresses slots */
403 	ether_addr_t	mac_addr[MAC_ADDRESS_REGS_MAX];
404 	boolean_t	mac_addr_set[MAC_ADDRESS_REGS_MAX];
405 } bge_multi_mac_t;
406 
407 /*
408  * Software Receive (Return) Ring Control Block
409  * There's one of these for each receiver return ring (up to 16).
410  */
411 typedef struct recv_ring {
412 	/*
413 	 * The elements flagged (const) in the comments below are
414 	 * set up once during initialiation and thereafter unchanged.
415 	 */
416 	dma_area_t		desc;		/* (const) related h/w	*/
417 						/* descriptor area	*/
418 	bge_rcb_t		hw_rcb;		/* (const) image of h/w	*/
419 						/* RCB, and used to	*/
420 						/* initialise same	*/
421 	struct bge		*bgep;		/* (const) containing	*/
422 						/* driver soft state	*/
423 	ddi_softintr_t		rx_softint;	/* (const) per-ring	*/
424 						/* receive callback	*/
425 	volatile uint16_t	*prod_index_p;	/* (const) ptr to h/w	*/
426 						/* "producer index"	*/
427 						/* (in status block)	*/
428 	/*
429 	 * The rx_lock must be held when updating the h/w consumer index
430 	 * mailbox register (*chip_mbox_reg), or the s/w consumer index
431 	 * (rx_next).
432 	 */
433 	bge_regno_t		chip_mbx_reg;	/* (const) h/w consumer	*/
434 						/* index mailbox offset	*/
435 	kmutex_t		rx_lock[1];	/* serialize receive	*/
436 	uint64_t		rx_next;	/* next slot to examine	*/
437 
438 	mac_ring_handle_t	ring_handle;
439 	mac_group_handle_t	ring_group_handle;
440 	uint64_t		ring_gen_num;
441 	bge_rule_info_t		*mac_addr_rule;
442 	uint8_t			mac_addr_val[ETHERADDRL];
443 	int			poll_flag;	/* Polling flag		*/
444 
445 	/* Per-ring statistics */
446 	uint64_t		rx_pkts;	/* Received Packets Count */
447 	uint64_t		rx_bytes;	/* Received Bytes Count */
448 } recv_ring_t;
449 
450 
451 /*
452  * Send packet structure
453  */
454 typedef struct send_pkt {
455 	uint16_t		vlan_tci;
456 	uint32_t		pflags;
457 	boolean_t		tx_ready;
458 	bge_queue_item_t	*txbuf_item;
459 } send_pkt_t;
460 
461 /*
462  * Software version of tx buffer structure
463  */
464 typedef struct sw_txbuf {
465 	dma_area_t		buf;
466 	uint32_t		copy_len;
467 } sw_txbuf_t;
468 
469 /*
470  * Software version of the Send Buffer Descriptor
471  * There's one of these for each send buffer (up to 512 per ring)
472  */
473 typedef struct sw_sbd {
474 	dma_area_t		desc;		/* (const) related h/w	*/
475 						/* descriptor area	*/
476 	bge_queue_item_t	*pbuf;		/* (const) related	*/
477 						/* buffer area		*/
478 } sw_sbd_t;
479 
480 /*
481  * Software Send Ring Control Block
482  * There's one of these for each of (up to) 16 send rings
483  */
484 typedef struct send_ring {
485 	/*
486 	 * The elements flagged (const) in the comments below are
487 	 * set up once during initialiation and thereafter unchanged.
488 	 */
489 	dma_area_t		desc;		/* (const) related h/w	*/
490 						/* descriptor area	*/
491 	dma_area_t		buf[BGE_SEND_BUF_ARRAY][BGE_SPLIT];
492 						/* buffer area(s)	*/
493 	bge_rcb_t		hw_rcb;		/* (const) image of h/w	*/
494 						/* RCB, and used to	*/
495 						/* initialise same	*/
496 	struct bge		*bgep;		/* (const) containing	*/
497 						/* driver soft state	*/
498 	volatile uint16_t	*cons_index_p;	/* (const) ptr to h/w	*/
499 						/* "consumer index"	*/
500 						/* (in status block)	*/
501 
502 	bge_regno_t		chip_mbx_reg;	/* (const) h/w producer	*/
503 						/* index mailbox offset	*/
504 	/*
505 	 * Tx buffer queue
506 	 */
507 	bge_queue_t		txbuf_queue;
508 	bge_queue_t		freetxbuf_queue;
509 	bge_queue_t		*txbuf_push_queue;
510 	bge_queue_t		*txbuf_pop_queue;
511 	kmutex_t		txbuf_lock[1];
512 	kmutex_t		freetxbuf_lock[1];
513 	bge_queue_item_t	*txbuf_head;
514 	send_pkt_t		*pktp;
515 	uint64_t		txpkt_next;
516 	uint64_t		txfill_next;
517 	sw_txbuf_t		*txbuf;
518 	uint32_t		tx_buffers;
519 	uint32_t		tx_buffers_low;
520 	uint32_t		tx_array_max;
521 	uint32_t		tx_array;
522 	kmutex_t		tx_lock[1];	/* serialize h/w update	*/
523 						/* ("producer index")	*/
524 	uint64_t		tx_next;	/* next slot to use	*/
525 	uint64_t		tx_flow;	/* # concurrent sends	*/
526 	uint64_t		tx_block;
527 	uint64_t		tx_nobd;
528 	uint64_t		tx_nobuf;
529 	uint64_t		tx_alloc_fail;
530 
531 	/*
532 	 * These counters/indexes are manipulated in the transmit
533 	 * path using atomics rather than mutexes for speed
534 	 */
535 	uint64_t		tx_free;	/* # of slots available	*/
536 
537 	/*
538 	 * The tc_lock must be held while manipulating the s/w consumer
539 	 * index (tc_next).
540 	 */
541 	kmutex_t		tc_lock[1];	/* serialize recycle	*/
542 	uint64_t		tc_next;	/* next slot to recycle	*/
543 						/* ("consumer index")	*/
544 
545 	sw_sbd_t		*sw_sbds; 	/* software descriptors	*/
546 	uint64_t		mac_resid;	/* special per resource id */
547 	uint64_t		pushed_bytes;
548 } send_ring_t;					/* 0x100 (256) bytes	*/
549 
550 typedef struct {
551 	ether_addr_t		addr;		/* in canonical form	*/
552 	uint8_t			spare;
553 	boolean_t		set;		/* B_TRUE => valid	*/
554 } bge_mac_addr_t;
555 
556 /*
557  * The original 5700/01 supported only SEEPROMs.  Later chips (5702+)
558  * support both SEEPROMs (using the same 2-wire CLK/DATA interface for
559  * the hardware and a backwards-compatible software access method), and
560  * buffered or unbuffered FLASH devices connected to the 4-wire SPI bus
561  * and using a new software access method.
562  *
563  * The access methods for SEEPROM and Flash are generally similar, with
564  * the chip handling the serialisation/deserialisation and handshaking,
565  * but the registers used are different, as are a few details of the
566  * protocol, and the timing, so we have to determine which (if any) is
567  * fitted.
568  *
569  * The value UNKNOWN means just that; we haven't yet tried to determine
570  * the device type.
571  *
572  * The value NONE can indicate either that a real and definite absence of
573  * any NVmem has been detected, or that there may be NVmem but we can't
574  * determine its type, perhaps because the NVconfig pins on the chip have
575  * been wired up incorrectly.  In either case, access to the NVmem (if any)
576  * is not supported.
577  */
578 enum bge_nvmem_type {
579 	BGE_NVTYPE_NONE = -1,			/* (or indeterminable)	*/
580 	BGE_NVTYPE_UNKNOWN,			/* not yet checked	*/
581 	BGE_NVTYPE_SEEPROM,			/* BCM5700/5701 only	*/
582 	BGE_NVTYPE_LEGACY_SEEPROM,		/* 5702+		*/
583 	BGE_NVTYPE_UNBUFFERED_FLASH,		/* 5702+		*/
584 	BGE_NVTYPE_BUFFERED_FLASH		/* 5702+		*/
585 };
586 
587 /*
588  * Describes the characteristics of a specific chip
589  *
590  * Note: elements from <businfo> to <latency> are filled in by during
591  * the first phase of chip initialisation (see bge_chip_cfg_init()).
592  * The remaining ones are determined just after the first RESET, in
593  * bge_poll_firmware().  Thereafter, the entire structure is readonly.
594  */
595 typedef struct {
596 	uint32_t		asic_rev;	/* masked from MHCR	*/
597 	uint32_t		businfo;	/* from private reg	*/
598 	uint16_t		command;	/* saved during attach	*/
599 
600 	uint16_t		vendor;		/* vendor-id		*/
601 	uint16_t		device;		/* device-id		*/
602 	uint16_t		subven;		/* subsystem-vendor-id	*/
603 	uint16_t		subdev;		/* subsystem-id		*/
604 	uint8_t			revision;	/* revision-id		*/
605 	uint8_t			clsize;		/* cache-line-size	*/
606 	uint8_t			latency;	/* latency-timer	*/
607 
608 	uint8_t			flags;
609 	uint16_t		chip_label;	/* numeric part only	*/
610 						/* (e.g. 5703/5794/etc)	*/
611 	uint32_t		mbuf_base;	/* Mbuf pool parameters */
612 	uint32_t		mbuf_length;	/* depend on chiptype	*/
613 	uint32_t		pci_type;
614 	uint32_t		statistic_type;
615 	uint32_t		bge_dma_rwctrl;
616 	uint32_t		bge_mlcr_default;
617 	uint32_t		recv_slots;	/* receive ring size    */
618 	enum bge_nvmem_type	nvtype;		/* SEEPROM or Flash	*/
619 
620 	uint16_t		jumbo_slots;
621 	uint16_t		ethmax_size;
622 	uint16_t		snd_buff_size;
623 	uint16_t		recv_jumbo_size;
624 	uint16_t		std_buf_size;
625 	uint32_t		mbuf_hi_water;
626 	uint32_t		mbuf_lo_water_rmac;
627 	uint32_t		mbuf_lo_water_rdma;
628 
629 	uint32_t		rx_rings;	/* from bge.conf	*/
630 	uint32_t		tx_rings;	/* from bge.conf	*/
631 	uint32_t		default_mtu;	/* from bge.conf	*/
632 
633 	uint64_t		hw_mac_addr;	/* from chip register	*/
634 	bge_mac_addr_t		vendor_addr;	/* transform of same	*/
635 	boolean_t		msi_enabled;	/* default to true */
636 
637 	uint32_t		rx_ticks_norm;
638 	uint32_t		rx_count_norm;
639 	uint32_t		tx_ticks_norm;
640 	uint32_t		tx_count_norm;
641 } chip_id_t;
642 
643 #define	CHIP_FLAG_SUPPORTED	0x80
644 #define	CHIP_FLAG_SERDES	0x40
645 #define	CHIP_FLAG_PARTIAL_CSUM	0x20
646 #define	CHIP_FLAG_NO_JUMBO	0x1
647 
648 /*
649  * Collection of physical-layer functions to:
650  *	(re)initialise the physical layer
651  *	update it to match software settings
652  *	check for link status change
653  */
654 typedef struct {
655 	int			(*phys_restart)(struct bge *, boolean_t);
656 	int			(*phys_update)(struct bge *);
657 	boolean_t		(*phys_check)(struct bge *, boolean_t);
658 } phys_ops_t;
659 
660 
661 /*
662  * Actual state of the BCM570x chip
663  */
664 enum bge_chip_state {
665 	BGE_CHIP_FAULT = -2,			/* fault, need reset	*/
666 	BGE_CHIP_ERROR,				/* error, want reset	*/
667 	BGE_CHIP_INITIAL,			/* Initial state only	*/
668 	BGE_CHIP_RESET,				/* reset, need init	*/
669 	BGE_CHIP_STOPPED,			/* Tx/Rx stopped	*/
670 	BGE_CHIP_RUNNING			/* with interrupts	*/
671 };
672 
673 enum bge_mac_state {
674 	BGE_MAC_STOPPED = 0,
675 	BGE_MAC_STARTED
676 };
677 
678 /*
679  * (Internal) return values from ioctl subroutines
680  */
681 enum ioc_reply {
682 	IOC_INVAL = -1,				/* bad, NAK with EINVAL	*/
683 	IOC_DONE,				/* OK, reply sent	*/
684 	IOC_ACK,				/* OK, just send ACK	*/
685 	IOC_REPLY,				/* OK, just send reply	*/
686 	IOC_RESTART_ACK,			/* OK, restart & ACK	*/
687 	IOC_RESTART_REPLY			/* OK, restart & reply	*/
688 };
689 
690 /*
691  * (Internal) return values from send_msg subroutines
692  */
693 enum send_status {
694 	SEND_FAIL = -1,				/* Not OK		*/
695 	SEND_KEEP,				/* OK, msg queued	*/
696 	SEND_FREE				/* OK, free msg		*/
697 };
698 
699 /*
700  * (Internal) enumeration of this driver's kstats
701  */
702 enum {
703 	BGE_KSTAT_RAW = 0,
704 	BGE_KSTAT_STATS,
705 	BGE_KSTAT_CHIPID,
706 	BGE_KSTAT_DRIVER,
707 	BGE_KSTAT_PHYS,
708 
709 	BGE_KSTAT_COUNT
710 };
711 
712 #define	BGE_MAX_RESOURCES 255
713 
714 /*
715  * Per-instance soft-state structure
716  */
717 typedef struct bge {
718 	/*
719 	 * These fields are set by attach() and unchanged thereafter ...
720 	 */
721 	dev_info_t		*devinfo;	/* device instance	*/
722 	mac_handle_t		mh;		/* mac module handle	*/
723 	ddi_acc_handle_t	cfg_handle;	/* DDI I/O handle	*/
724 	ddi_acc_handle_t	io_handle;	/* DDI I/O handle	*/
725 	void			*io_regs;	/* mapped registers	*/
726 	ddi_periodic_t		periodic_id;	/* periodical callback	*/
727 	ddi_softintr_t		factotum_id;	/* factotum callback	*/
728 	ddi_softintr_t		drain_id;	/* reschedule callback	*/
729 
730 	ddi_intr_handle_t 	*htable;	/* For array of interrupts */
731 	int			intr_type;	/* What type of interrupt */
732 	int			intr_cnt;	/* # of intrs count returned */
733 	uint_t			intr_pri;	/* Interrupt priority	*/
734 	int			intr_cap;	/* Interrupt capabilities */
735 	uint32_t		progress;	/* attach tracking	*/
736 	uint32_t		debug;		/* per-instance debug	*/
737 	chip_id_t		chipid;
738 	const phys_ops_t	*physops;
739 	char			ifname[8];	/* "bge0" ... "bge999"	*/
740 
741 	int			fm_capabilities;	/* FMA capabilities */
742 
743 	/*
744 	 * These structures describe the blocks of memory allocated during
745 	 * attach().  They remain unchanged thereafter, although the memory
746 	 * they describe is carved up into various separate regions and may
747 	 * therefore be described by other structures as well.
748 	 */
749 	dma_area_t		tx_desc;	/* transmit descriptors	*/
750 	dma_area_t		rx_desc[BGE_RECV_RINGS_SPLIT];
751 						/* receive descriptors	*/
752 	dma_area_t		tx_buff[BGE_SPLIT];
753 	dma_area_t		rx_buff[BGE_SPLIT];
754 
755 	/*
756 	 * The memory described by the <dma_area> structures above
757 	 * is carved up into various pieces, which are described by
758 	 * the structures below.
759 	 */
760 	dma_area_t		statistics;	/* describes hardware	*/
761 						/* statistics area	*/
762 	dma_area_t		status_block;	/* describes hardware	*/
763 						/* status block		*/
764 	/*
765 	 * For the BCM5705/5788/5721/5751/5752/5714 and 5715,
766 	 * the statistic block is not available,the statistic counter must
767 	 * be gotten from statistic registers.And bge_statistics_reg_t record
768 	 * the statistic registers value
769 	 */
770 	bge_statistics_reg_t	*pstats;
771 
772 	/*
773 	 * Runtime read-write data starts here ...
774 	 *
775 	 * 3 Buffer Rings (std/jumbo/mini)
776 	 * 16 Receive (Return) Rings
777 	 * 16 Send Rings
778 	 *
779 	 * Note: they're not necessarily all used.
780 	 */
781 	buff_ring_t		buff[BGE_BUFF_RINGS_MAX]; /*  3*0x0100	*/
782 
783 	/* may be obsoleted */
784 	recv_ring_t		recv[BGE_RECV_RINGS_MAX]; /* 16*0x0090	*/
785 	send_ring_t		send[BGE_SEND_RINGS_MAX]; /* 16*0x0100	*/
786 
787 	/*
788 	 * Locks:
789 	 *
790 	 * Each buffer ring contains its own <rf_lock> which regulates
791 	 *	ring refilling.
792 	 *
793 	 * Each receive (return) ring contains its own <rx_lock> which
794 	 *	protects the critical cyclic counters etc.
795 	 *
796 	 * Each send ring contains two locks: <tx_lock> for the send-path
797 	 * 	protocol data and <tc_lock> for send-buffer recycling.
798 	 *
799 	 * Finally <genlock> is a general lock, protecting most other
800 	 *	operational data in the state structure and chip register
801 	 *	accesses.  It is acquired by the interrupt handler and
802 	 *	most "mode-control" routines.
803 	 *
804 	 * Any of the locks can be acquired singly, but where multiple
805 	 * locks are acquired, they *must* be in the order:
806 	 *
807 	 *	genlock >>> rx_lock >>> rf_lock >>> tx_lock >>> tc_lock.
808 	 *
809 	 * and within any one class of lock the rings must be locked in
810 	 * ascending order (send[0].tc_lock >>> send[1].tc_lock), etc.
811 	 *
812 	 * Note: actually I don't believe there's any need to acquire
813 	 * locks on multiple rings, or even locks of all these classes
814 	 * concurrently; but I've set out the above order so there is a
815 	 * clear definition of lock hierarchy in case it's ever needed.
816 	 *
817 	 * Note: the combinations of locks that are actually held
818 	 * concurrently are:
819 	 *
820 	 *	genlock >>>			(bge_chip_interrupt())
821 	 *		rx_lock[i] >>>		(bge_receive())
822 	 *			rf_lock[n]	(bge_refill())
823 	 *		tc_lock[i]		(bge_recycle())
824 	 */
825 	kmutex_t		genlock[1];
826 	krwlock_t		errlock[1];
827 	kmutex_t		softintrlock[1];
828 
829 	/*
830 	 * Current Ethernet addresses and multicast hash (bitmap) and
831 	 * refcount tables, protected by <genlock>
832 	 */
833 	bge_mac_addr_t		curr_addr[MAC_ADDRESS_REGS_MAX];
834 	uint32_t		mcast_hash[BGE_HASH_TABLE_SIZE/32];
835 	uint8_t			mcast_refs[BGE_HASH_TABLE_SIZE];
836 	uint32_t		unicst_addr_total; /* total unicst addresses */
837 	uint32_t		unicst_addr_avail;
838 					/* unused unicst addr slots */
839 
840 	/*
841 	 * Link state data (protected by genlock)
842 	 */
843 	link_state_t		link_state;
844 
845 	/*
846 	 * Physical layer: copper only
847 	 */
848 	bge_regno_t		phy_mii_addr;	/* should be (const) 1!	*/
849 	uint16_t		phy_gen_status;
850 	uint16_t		phy_aux_status;
851 
852 	/*
853 	 * Physical layer: serdes only
854 	 */
855 	uint32_t		serdes_status;
856 	uint32_t		serdes_advert;
857 	uint32_t		serdes_lpadv;
858 
859 	/*
860 	 * Driver kstats, protected by <genlock> where necessary
861 	 */
862 	kstat_t			*bge_kstats[BGE_KSTAT_COUNT];
863 
864 	/*
865 	 * Miscellaneous operating variables (protected by genlock)
866 	 */
867 	uint64_t		chip_resets;	/* # of chip RESETs	*/
868 	uint64_t		missed_dmas;	/* # of missed DMAs	*/
869 	uint64_t		missed_updates;	/* # of missed updates	*/
870 	enum bge_mac_state	bge_mac_state;	/* definitions above	*/
871 	enum bge_chip_state	bge_chip_state;	/* definitions above	*/
872 	boolean_t		send_hw_tcp_csum;
873 	boolean_t		recv_hw_tcp_csum;
874 	boolean_t		promisc;
875 	boolean_t		manual_reset;
876 
877 	/*
878 	 * Miscellaneous operating variables (not synchronised)
879 	 */
880 	uint32_t		watchdog;	/* watches for Tx stall	*/
881 	boolean_t		bge_intr_running;
882 	boolean_t		bge_dma_error;
883 	boolean_t		tx_resched_needed;
884 	uint64_t		tx_resched;
885 	uint32_t		factotum_flag;	/* softint pending	*/
886 	uintptr_t		pagemask;
887 
888 	/*
889 	 * NDD parameters (protected by genlock)
890 	 */
891 	caddr_t			nd_data_p;
892 
893 	/*
894 	 * A flag to prevent excessive config space accesses
895 	 * on platforms having BCM5714C/15C
896 	 */
897 	boolean_t		lastWriteZeroData;
898 
899 	/*
900 	 * Spare space, plus guard element used to check data integrity
901 	 */
902 	uint64_t		spare[5];
903 	uint64_t		bge_guard;
904 
905 	/*
906 	 * Receive rules configure
907 	 */
908 	bge_recv_rule_t	recv_rules[RECV_RULES_NUM_MAX];
909 
910 #ifdef BGE_IPMI_ASF
911 	boolean_t		asf_enabled;
912 	boolean_t		asf_wordswapped;
913 	boolean_t		asf_newhandshake;
914 	boolean_t		asf_pseudostop;
915 
916 	uint32_t		asf_status;
917 	timeout_id_t		asf_timeout_id;
918 #endif
919 	uint32_t		param_en_pause:1,
920 				param_en_asym_pause:1,
921 				param_en_1000hdx:1,
922 				param_en_1000fdx:1,
923 				param_en_100fdx:1,
924 				param_en_100hdx:1,
925 				param_en_10fdx:1,
926 				param_en_10hdx:1,
927 				param_adv_autoneg:1,
928 				param_adv_1000fdx:1,
929 				param_adv_1000hdx:1,
930 				param_adv_100fdx:1,
931 				param_adv_100hdx:1,
932 				param_adv_10fdx:1,
933 				param_adv_10hdx:1,
934 				param_lp_autoneg:1,
935 				param_lp_pause:1,
936 				param_lp_asym_pause:1,
937 				param_lp_1000fdx:1,
938 				param_lp_1000hdx:1,
939 				param_lp_100fdx:1,
940 				param_lp_100hdx:1,
941 				param_lp_10fdx:1,
942 				param_lp_10hdx:1,
943 				param_link_up:1,
944 				param_link_autoneg:1,
945 				param_adv_pause:1,
946 				param_adv_asym_pause:1,
947 				param_link_rx_pause:1,
948 				param_link_tx_pause:1,
949 				param_pad_to_32:2;
950 
951 	uint32_t		param_loop_mode;
952 	uint32_t		param_msi_cnt;
953 	uint32_t 		param_drain_max;
954 	uint64_t		param_link_speed;
955 	link_duplex_t		param_link_duplex;
956 
957 
958 	uint32_t		link_update_timer;
959 } bge_t;
960 
961 /*
962  * 'Progress' bit flags ...
963  */
964 #define	PROGRESS_CFG		0x0001	/* config space mapped		*/
965 #define	PROGRESS_REGS		0x0002	/* registers mapped		*/
966 #define	PROGRESS_BUFS		0x0004	/* ring buffers allocated	*/
967 #define	PROGRESS_RESCHED	0x0010	/* resched softint registered	*/
968 #define	PROGRESS_FACTOTUM	0x0020	/* factotum softint registered	*/
969 #define	PROGRESS_HWINT		0x0040	/* h/w interrupt registered	*/
970 					/* and mutexen initialised	*/
971 #define	PROGRESS_INTR		0x0080	/* Intrs enabled		*/
972 #define	PROGRESS_PHY		0x0100	/* PHY initialised		*/
973 #define	PROGRESS_NDD		0x1000	/* NDD parameters set up	*/
974 #define	PROGRESS_KSTATS		0x2000	/* kstats created		*/
975 #define	PROGRESS_READY		0x8000	/* ready for work		*/
976 
977 
978 /*
979  * Sync a DMA area described by a dma_area_t
980  */
981 #define	DMA_SYNC(area, flag)	((void) ddi_dma_sync((area).dma_hdl,	\
982 				    (area).offset, (area).alength, (flag)))
983 
984 /*
985  * Find the (kernel virtual) address of block of memory
986  * described by a dma_area_t
987  */
988 #define	DMA_VPTR(area)		((area).mem_va)
989 
990 /*
991  * Zero a block of memory described by a dma_area_t
992  */
993 #define	DMA_ZERO(area)		bzero(DMA_VPTR(area), (area).alength)
994 
995 /*
996  * Next value of a cyclic index
997  */
998 #define	NEXT(index, limit)	((index)+1 < (limit) ? (index)+1 : 0)
999 
1000 /*
1001  * Property lookups
1002  */
1003 #define	BGE_PROP_EXISTS(d, n)	ddi_prop_exists(DDI_DEV_T_ANY, (d),	\
1004 					DDI_PROP_DONTPASS, (n))
1005 #define	BGE_PROP_GET_INT(d, n)	ddi_prop_get_int(DDI_DEV_T_ANY, (d),	\
1006 					DDI_PROP_DONTPASS, (n), -1)
1007 
1008 /*
1009  * Copy an ethernet address
1010  */
1011 #define	ethaddr_copy(src, dst)	bcopy((src), (dst), ETHERADDRL)
1012 
1013 /*
1014  * Endian swap
1015  */
1016 /* BEGIN CSTYLED */
1017 #define BGE_BSWAP_32(x)		((((x) & 0xff000000) >> 24)  |		\
1018                                  (((x) & 0x00ff0000) >> 8)   |		\
1019                                  (((x) & 0x0000ff00) << 8)   |		\
1020                                  (((x) & 0x000000ff) << 24))
1021 /* END CSTYLED */
1022 
1023 /*
1024  * Marker value placed at the end of the driver's state
1025  */
1026 #define	BGE_GUARD		0x1919306009031802
1027 
1028 /*
1029  * Bit flags in the 'debug' word ...
1030  */
1031 #define	BGE_DBG_STOP		0x00000001	/* early debug_enter()	*/
1032 #define	BGE_DBG_TRACE		0x00000002	/* general flow tracing	*/
1033 
1034 #define	BGE_DBG_REGS		0x00000010	/* low-level accesses	*/
1035 #define	BGE_DBG_MII		0x00000020	/* low-level MII access	*/
1036 #define	BGE_DBG_SEEPROM		0x00000040	/* low-level SEEPROM IO	*/
1037 #define	BGE_DBG_CHIP		0x00000080	/* low(ish)-level code	*/
1038 
1039 #define	BGE_DBG_RECV		0x00000100	/* receive-side code	*/
1040 #define	BGE_DBG_SEND		0x00000200	/* packet-send code	*/
1041 
1042 #define	BGE_DBG_INT		0x00001000	/* interrupt handler	*/
1043 #define	BGE_DBG_FACT		0x00002000	/* factotum (softint)	*/
1044 
1045 #define	BGE_DBG_PHY		0x00010000	/* Copper PHY code	*/
1046 #define	BGE_DBG_SERDES		0x00020000	/* SerDes code		*/
1047 #define	BGE_DBG_PHYS		0x00040000	/* Physical layer code	*/
1048 #define	BGE_DBG_LINK		0x00080000	/* Link status check	*/
1049 
1050 #define	BGE_DBG_INIT		0x00100000	/* initialisation	*/
1051 #define	BGE_DBG_NEMO		0x00200000	/* nemo interaction	*/
1052 #define	BGE_DBG_ADDR		0x00400000	/* address-setting code	*/
1053 #define	BGE_DBG_STATS		0x00800000	/* statistics		*/
1054 
1055 #define	BGE_DBG_IOCTL		0x01000000	/* ioctl handling	*/
1056 #define	BGE_DBG_LOOP		0x02000000	/* loopback ioctl code	*/
1057 #define	BGE_DBG_PPIO		0x04000000	/* Peek/poke ioctls	*/
1058 #define	BGE_DBG_BADIOC		0x08000000	/* unknown ioctls	*/
1059 
1060 #define	BGE_DBG_MCTL		0x10000000	/* mctl (csum) code	*/
1061 #define	BGE_DBG_NDD		0x20000000	/* NDD operations	*/
1062 
1063 /*
1064  * Debugging ...
1065  */
1066 #ifdef	DEBUG
1067 #define	BGE_DEBUGGING		1
1068 #else
1069 #define	BGE_DEBUGGING		0
1070 #endif	/* DEBUG */
1071 
1072 
1073 /*
1074  * 'Do-if-debugging' macro.  The parameter <command> should be one or more
1075  * C statements (but without the *final* semicolon), which will either be
1076  * compiled inline or completely ignored, depending on the BGE_DEBUGGING
1077  * compile-time flag.
1078  *
1079  * You should get a compile-time error (at least on a DEBUG build) if
1080  * your statement isn't actually a statement, rather than unexpected
1081  * run-time behaviour caused by unintended matching of if-then-elses etc.
1082  *
1083  * Note that the BGE_DDB() macro itself can only be used as a statement,
1084  * not an expression, and should always be followed by a semicolon.
1085  */
1086 #if	BGE_DEBUGGING
1087 #define	BGE_DDB(command)	do {					\
1088 					{ command; }			\
1089 					_NOTE(CONSTANTCONDITION)	\
1090 				} while (0)
1091 #else 	/* BGE_DEBUGGING */
1092 #define	BGE_DDB(command)	do {					\
1093 					{ _NOTE(EMPTY); }		\
1094 					_NOTE(CONSTANTCONDITION)	\
1095 				} while (0)
1096 #endif	/* BGE_DEBUGGING */
1097 
1098 /*
1099  * 'Internal' macros used to construct the TRACE/DEBUG macros below.
1100  * These provide the primitive conditional-call capability required.
1101  * Note: the parameter <args> is a parenthesised list of the actual
1102  * printf-style arguments to be passed to the debug function ...
1103  */
1104 #define	BGE_XDB(b, w, f, args)	BGE_DDB(if ((b) & (w)) f args)
1105 #define	BGE_GDB(b, args)	BGE_XDB(b, bge_debug, (*bge_gdb()), args)
1106 #define	BGE_LDB(b, args)	BGE_XDB(b, bgep->debug, (*bge_db(bgep)), args)
1107 #define	BGE_CDB(f, args)	BGE_XDB(BGE_DBG, bgep->debug, f, args)
1108 
1109 /*
1110  * Conditional-print macros.
1111  *
1112  * Define BGE_DBG to be the relevant member of the set of BGE_DBG_* values
1113  * above before using the BGE_GDEBUG() or BGE_DEBUG() macros.  The 'G'
1114  * versions look at the Global debug flag word (bge_debug); the non-G
1115  * versions look in the per-instance data (bgep->debug) and so require a
1116  * variable called 'bgep' to be in scope (and initialised!) before use.
1117  *
1118  * You could redefine BGE_TRC too if you really need two different
1119  * flavours of debugging output in the same area of code, but I don't
1120  * really recommend it.
1121  *
1122  * Note: the parameter <args> is a parenthesised list of the actual
1123  * arguments to be passed to the debug function, usually a printf-style
1124  * format string and corresponding values to be formatted.
1125  */
1126 
1127 #define	BGE_TRC			BGE_DBG_TRACE	/* default 'trace' bit	*/
1128 #define	BGE_GTRACE(args)	BGE_GDB(BGE_TRC, args)
1129 #define	BGE_GDEBUG(args)	BGE_GDB(BGE_DBG, args)
1130 #define	BGE_TRACE(args)		BGE_LDB(BGE_TRC, args)
1131 #define	BGE_DEBUG(args)		BGE_LDB(BGE_DBG, args)
1132 
1133 /*
1134  * Debug-only action macros
1135  */
1136 #define	BGE_BRKPT(bgep, s)	BGE_DDB(bge_dbg_enter(bgep, s))
1137 #define	BGE_MARK(bgep)		BGE_DDB(bge_led_mark(bgep))
1138 #define	BGE_PCICHK(bgep)	BGE_DDB(bge_pci_check(bgep))
1139 #define	BGE_PKTDUMP(args)	BGE_DDB(bge_pkt_dump args)
1140 #define	BGE_REPORT(args)	BGE_DDB(bge_log args)
1141 
1142 /*
1143  * Inter-source-file linkage ...
1144  */
1145 
1146 /* bge_chip.c */
1147 uint16_t bge_mii_get16(bge_t *bgep, bge_regno_t regno);
1148 void bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t value);
1149 uint32_t bge_reg_get32(bge_t *bgep, bge_regno_t regno);
1150 void bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t value);
1151 void bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits);
1152 void bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits);
1153 void bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t value);
1154 void bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma);
1155 int bge_chip_id_init(bge_t *bgep);
1156 void bge_chip_coalesce_update(bge_t *bgep);
1157 int bge_chip_start(bge_t *bgep, boolean_t reset_phy);
1158 void bge_chip_stop(bge_t *bgep, boolean_t fault);
1159 #ifndef __sparc
1160 void bge_chip_stop_nonblocking(bge_t *bgep);
1161 #endif
1162 #ifdef BGE_IPMI_ASF
1163 void bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data);
1164 #pragma	inline(bge_nic_put32)
1165 uint32_t bge_nic_read32(bge_t *bgep, bge_regno_t addr);
1166 void bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val);
1167 #pragma inline(bge_ind_put32)
1168 uint32_t bge_ind_get32(bge_t *bgep, bge_regno_t regno);
1169 #pragma inline(bge_ind_get32)
1170 void bge_asf_update_status(bge_t *bgep);
1171 void bge_asf_heartbeat(void *bgep);
1172 void bge_asf_stop_timer(bge_t *bgep);
1173 void bge_asf_get_config(bge_t *bgep);
1174 void bge_asf_pre_reset_operations(bge_t *bgep, uint32_t mode);
1175 void bge_asf_post_reset_old_mode(bge_t *bgep, uint32_t mode);
1176 void bge_asf_post_reset_new_mode(bge_t *bgep, uint32_t mode);
1177 int bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode);
1178 int bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive);
1179 #else
1180 int bge_chip_reset(bge_t *bgep, boolean_t enable_dma);
1181 int bge_chip_sync(bge_t *bgep);
1182 #endif
1183 void bge_chip_blank(void *arg, time_t ticks, uint_t count, int flag);
1184 extern mblk_t *bge_poll_ring(void *, int);
1185 uint_t bge_chip_factotum(caddr_t arg);
1186 void bge_chip_cyclic(void *arg);
1187 enum ioc_reply bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp,
1188 	struct iocblk *iocp);
1189 uint_t bge_intr(caddr_t arg1, caddr_t arg2);
1190 void bge_sync_mac_modes(bge_t *);
1191 extern uint32_t bge_rx_ticks_norm;
1192 extern uint32_t bge_tx_ticks_norm;
1193 extern uint32_t bge_rx_count_norm;
1194 extern uint32_t bge_tx_count_norm;
1195 extern boolean_t bge_relaxed_ordering;
1196 
1197 void   bge_chip_msi_trig(bge_t *bgep);
1198 
1199 /* bge_kstats.c */
1200 void bge_init_kstats(bge_t *bgep, int instance);
1201 void bge_fini_kstats(bge_t *bgep);
1202 int bge_m_stat(void *arg, uint_t stat, uint64_t *val);
1203 int bge_rx_ring_stat(mac_ring_driver_t, uint_t, uint64_t *);
1204 
1205 /* bge_log.c */
1206 #if	BGE_DEBUGGING
1207 void (*bge_db(bge_t *bgep))(const char *fmt, ...);
1208 void (*bge_gdb(void))(const char *fmt, ...);
1209 void bge_pkt_dump(bge_t *bgep, bge_rbd_t *hbp, sw_rbd_t *sdp, const char *msg);
1210 void bge_dbg_enter(bge_t *bgep, const char *msg);
1211 #endif	/* BGE_DEBUGGING */
1212 void bge_problem(bge_t *bgep, const char *fmt, ...);
1213 void bge_log(bge_t *bgep, const char *fmt, ...);
1214 void bge_error(bge_t *bgep, const char *fmt, ...);
1215 void bge_fm_ereport(bge_t *bgep, char *detail);
1216 extern kmutex_t bge_log_mutex[1];
1217 extern uint32_t bge_debug;
1218 
1219 /* bge_main.c */
1220 int bge_restart(bge_t *bgep, boolean_t reset_phy);
1221 int bge_check_acc_handle(bge_t *bgep, ddi_acc_handle_t handle);
1222 int bge_check_dma_handle(bge_t *bgep, ddi_dma_handle_t handle);
1223 void bge_init_rings(bge_t *bgep);
1224 void bge_fini_rings(bge_t *bgep);
1225 bge_queue_item_t *bge_alloc_txbuf_array(bge_t *bgep, send_ring_t *srp);
1226 void bge_free_txbuf_arrays(send_ring_t *srp);
1227 int bge_alloc_bufs(bge_t *bgep);
1228 void bge_free_bufs(bge_t *bgep);
1229 void bge_intr_enable(bge_t *bgep);
1230 void bge_intr_disable(bge_t *bgep);
1231 int bge_reprogram(bge_t *);
1232 
1233 /* bge_phys.c */
1234 int bge_phys_init(bge_t *bgep);
1235 void bge_phys_reset(bge_t *bgep);
1236 int bge_phys_idle(bge_t *bgep);
1237 int bge_phys_update(bge_t *bgep);
1238 boolean_t bge_phys_check(bge_t *bgep);
1239 
1240 /* bge_ndd.c */
1241 int bge_nd_init(bge_t *bgep);
1242 
1243 /* bge_recv.c */
1244 void bge_receive(bge_t *bgep, bge_status_t *bsp);
1245 
1246 /* bge_send.c */
1247 mblk_t *bge_m_tx(void *arg, mblk_t *mp);
1248 mblk_t *bge_ring_tx(void *arg, mblk_t *mp);
1249 void bge_recycle(bge_t *bgep, bge_status_t *bsp);
1250 uint_t bge_send_drain(caddr_t arg);
1251 
1252 /* bge_atomic.c */
1253 uint64_t bge_atomic_reserve(uint64_t *count_p, uint64_t n);
1254 void bge_atomic_renounce(uint64_t *count_p, uint64_t n);
1255 uint64_t bge_atomic_claim(uint64_t *count_p, uint64_t limit);
1256 uint64_t bge_atomic_next(uint64_t *sp, uint64_t limit);
1257 void bge_atomic_sub64(uint64_t *count_p, uint64_t n);
1258 uint64_t bge_atomic_clr64(uint64_t *sp, uint64_t bits);
1259 uint32_t bge_atomic_shl32(uint32_t *sp, uint_t count);
1260 
1261 /* bge_mii_5906.c */
1262 void bge_adj_volt_5906(bge_t *bgep);
1263 
1264 /*
1265  * Reset type
1266  */
1267 #define	BGE_SHUTDOWN_RESET	0
1268 #define	BGE_INIT_RESET		1
1269 #define	BGE_SUSPEND_RESET	2
1270 
1271 /* For asf_status */
1272 #define	ASF_STAT_NONE		0
1273 #define	ASF_STAT_STOP		1
1274 #define	ASF_STAT_RUN		2
1275 #define	ASF_STAT_RUN_INIT	3	/* attached but don't plumb */
1276 
1277 /* ASF modes for bge_reset() and bge_chip_reset() */
1278 #define	ASF_MODE_NONE		0	/* don't launch asf	 */
1279 #define	ASF_MODE_SHUTDOWN	1	/* asf shutdown mode	 */
1280 #define	ASF_MODE_INIT		2	/* asf init mode	 */
1281 #define	ASF_MODE_POST_SHUTDOWN	3	/* only do post-shutdown */
1282 #define	ASF_MODE_POST_INIT	4	/* only do post-init	 */
1283 
1284 #define	BGE_ASF_HEARTBEAT_INTERVAL		1500000
1285 
1286 #define	BGE_LINK_UPDATE_TIMEOUT	10	/* ~ 5 sec */
1287 #define	BGE_LINK_UPDATE_DONE	(BGE_LINK_UPDATE_TIMEOUT+1)
1288 
1289 #ifdef __cplusplus
1290 }
1291 #endif
1292 
1293 #endif	/* _BGE_IMPL_H */
1294