xref: /onnv-gate/usr/src/uts/common/io/bge/bge_impl.h (revision 12547:dac3288623c0)
12675Szh199473 /*
22675Szh199473  * CDDL HEADER START
32675Szh199473  *
42675Szh199473  * The contents of this file are subject to the terms of the
52675Szh199473  * Common Development and Distribution License (the "License").
62675Szh199473  * You may not use this file except in compliance with the License.
72675Szh199473  *
82675Szh199473  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92675Szh199473  * or http://www.opensolaris.org/os/licensing.
102675Szh199473  * See the License for the specific language governing permissions
112675Szh199473  * and limitations under the License.
122675Szh199473  *
132675Szh199473  * When distributing Covered Code, include this CDDL HEADER in each
142675Szh199473  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152675Szh199473  * If applicable, add the following below this CDDL HEADER, with the
162675Szh199473  * fields enclosed by brackets "[]" replaced with your own identifying
172675Szh199473  * information: Portions Copyright [yyyy] [name of copyright owner]
182675Szh199473  *
192675Szh199473  * CDDL HEADER END
202675Szh199473  */
212675Szh199473 
222675Szh199473 /*
23*12547SYong.Tan@Sun.COM  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
242675Szh199473  */
252675Szh199473 
263334Sgs150176 #ifndef _BGE_IMPL_H
273334Sgs150176 #define	_BGE_IMPL_H
282675Szh199473 
292675Szh199473 
302675Szh199473 #ifdef __cplusplus
312675Szh199473 extern "C" {
322675Szh199473 #endif
332675Szh199473 
342675Szh199473 #include <sys/types.h>
352675Szh199473 #include <sys/stream.h>
362675Szh199473 #include <sys/strsun.h>
372675Szh199473 #include <sys/strsubr.h>
382675Szh199473 #include <sys/stat.h>
392675Szh199473 #include <sys/pci.h>
402675Szh199473 #include <sys/note.h>
412675Szh199473 #include <sys/modctl.h>
422675Szh199473 #include <sys/crc32.h>
432675Szh199473 #ifdef	__sparcv9
442675Szh199473 #include <v9/sys/membar.h>
452675Szh199473 #endif	/* __sparcv9 */
462675Szh199473 #include <sys/kstat.h>
472675Szh199473 #include <sys/ethernet.h>
482675Szh199473 #include <sys/vlan.h>
492675Szh199473 #include <sys/errno.h>
502675Szh199473 #include <sys/dlpi.h>
512675Szh199473 #include <sys/devops.h>
522675Szh199473 #include <sys/debug.h>
532675Szh199473 #include <sys/conf.h>
542675Szh199473 
552675Szh199473 #include <netinet/ip6.h>
562675Szh199473 
572675Szh199473 #include <inet/common.h>
582675Szh199473 #include <inet/ip.h>
592675Szh199473 #include <inet/mi.h>
602675Szh199473 #include <inet/nd.h>
612675Szh199473 #include <sys/pattr.h>
622675Szh199473 
635107Seota #include <sys/disp.h>
645903Ssowmini #include <sys/cmn_err.h>
652675Szh199473 #include <sys/ddi.h>
662675Szh199473 #include <sys/sunddi.h>
672675Szh199473 
682675Szh199473 #include <sys/ddifm.h>
692675Szh199473 #include <sys/fm/protocol.h>
702675Szh199473 #include <sys/fm/util.h>
712675Szh199473 #include <sys/fm/io/ddi.h>
722675Szh199473 
738275SEric Cheng #include <sys/mac_provider.h>
742675Szh199473 #include <sys/mac_ether.h>
752675Szh199473 
762675Szh199473 #ifdef __amd64
772675Szh199473 #include <sys/x86_archext.h>
782675Szh199473 #endif
792675Szh199473 
802675Szh199473 /*
812675Szh199473  * <sys/ethernet.h> *may* already have provided the typedef ether_addr_t;
822675Szh199473  * but of course C doesn't provide a way to check this directly.  So here
832675Szh199473  * we rely on the fact that the symbol ETHERTYPE_AT was added to the
842675Szh199473  * header file (as a #define, which we *can* test for) at the same time
852675Szh199473  * as the typedef for ether_addr_t ;-!
862675Szh199473  */
872675Szh199473 #ifndef	ETHERTYPE_AT
882675Szh199473 typedef uchar_t ether_addr_t[ETHERADDRL];
892675Szh199473 #endif	/* ETHERTYPE_AT */
902675Szh199473 
912675Szh199473 /*
922675Szh199473  * Reconfiguring the network devices requires the net_config privilege
932681Sgs150176  * in Solaris 10+.
942675Szh199473  */
952675Szh199473 extern int secpolicy_net_config(const cred_t *, boolean_t);
962675Szh199473 
972675Szh199473 #include <sys/netlb.h>			/* originally from cassini	*/
982675Szh199473 #include <sys/miiregs.h>		/* by fjlite out of intel 	*/
992675Szh199473 
1002675Szh199473 #include "bge.h"
1012675Szh199473 #include "bge_hw.h"
1022675Szh199473 
1032675Szh199473 /*
1042675Szh199473  * Compile-time feature switches ...
1052675Szh199473  */
1062675Szh199473 #define	BGE_DO_PPIO		0	/* peek/poke ioctls		*/
1072675Szh199473 #define	BGE_RX_SOFTINT		0	/* softint per receive ring	*/
1082675Szh199473 #define	BGE_CHOOSE_SEND_METHOD	0	/* send by copying only		*/
1092675Szh199473 
1102675Szh199473 /*
1112675Szh199473  * NOTES:
1122675Szh199473  *
1132675Szh199473  * #defines:
1142675Szh199473  *
1152675Szh199473  *	BGE_PCI_CONFIG_RNUMBER and BGE_PCI_OPREGS_RNUMBER are the
1162675Szh199473  *	register-set numbers to use for the config space registers
1172675Szh199473  *	and the operating registers respectively.  On an OBP-based
1182675Szh199473  *	machine, regset 0 refers to CONFIG space, and regset 1 will
1192675Szh199473  *	be the operating registers in MEMORY space.  If an expansion
1202675Szh199473  *	ROM is fitted, it may appear as a further register set.
1212675Szh199473  *
1222675Szh199473  *	BGE_DMA_MODE defines the mode (STREAMING/CONSISTENT) used
1232675Szh199473  *	for the data buffers.  The descriptors are always set up
1242675Szh199473  *	in CONSISTENT mode.
1252675Szh199473  *
1262675Szh199473  *	BGE_HEADROOM defines how much space we'll leave in allocated
1272675Szh199473  *	mblks before the first valid data byte.  This should be chosen
1282675Szh199473  *	to be 2 modulo 4, so that once the ethernet header (14 bytes)
1292675Szh199473  *	has been stripped off, the packet data will be 4-byte aligned.
1302675Szh199473  *	The remaining space can be used by upstream modules to prepend
1312675Szh199473  *	any headers required.
1322675Szh199473  */
1332675Szh199473 
1342675Szh199473 #define	BGE_PCI_CONFIG_RNUMBER	0
1352675Szh199473 #define	BGE_PCI_OPREGS_RNUMBER	1
1362675Szh199473 #define	BGE_DMA_MODE		DDI_DMA_STREAMING
1372675Szh199473 #define	BGE_HEADROOM		34
1382675Szh199473 
1392675Szh199473 /*
1402675Szh199473  *	BGE_HALFTICK is half the period of the cyclic callback (in
1412675Szh199473  *	nanoseconds), chosen so that 0.5s <= cyclic period <= 1s.
1422675Szh199473  *	Other time values are derived as odd multiples of this value
1432675Szh199473  *	so that there's little chance of ambiguity w.r.t. which tick
1442675Szh199473  *	a timeout expires on.
1452675Szh199473  *
1462675Szh199473  *	BGE_PHY_STABLE_TIME is the period for which the contents of the
1472675Szh199473  *	PHY's status register must remain unchanging before we accept
1482675Szh199473  *	that the link has come up.  [Sometimes the link comes up, only
1492675Szh199473  *	to go down again within a short time as the autonegotiation
1502675Szh199473  *	process cycles through various options before finding the best
1512675Szh199473  *	compatible mode.  We don't want to report repeated link up/down
1522675Szh199473  *	cycles, so we wait until we think it's stable.]
1532675Szh199473  *
1542675Szh199473  *	BGE_SERDES_STABLE_TIME is the analogous value for the SerDes
1552675Szh199473  *	interface.  It's much shorter, 'cos the SerDes doesn't show
1562675Szh199473  *	these effects as much as the copper PHY.
1572675Szh199473  *
1582675Szh199473  *	BGE_LINK_SETTLE_TIME is the period during which we regard link
1592675Szh199473  *	up/down cycles as an normal event after resetting/reprogramming
1602675Szh199473  *	the PHY.  During this time, link up/down messages are sent to
1612675Szh199473  *	the log only, not the console.  At any other time, link change
1622675Szh199473  *	events are regarded as unexpected and sent to both console & log.
1632675Szh199473  *
1642675Szh199473  *	These latter two values have no theoretical justification, but
1652675Szh199473  *	are derived from observations and heuristics - the values below
1662675Szh199473  *	just seem to work quite well.
1672675Szh199473  */
1682675Szh199473 
1692675Szh199473 #define	BGE_HALFTICK		268435456LL		/* 2**28 ns!	*/
170*12547SYong.Tan@Sun.COM #define	BGE_CYCLIC_PERIOD	(4*BGE_HALFTICK)	/*    ~1.0s	*/
1712675Szh199473 #define	BGE_SERDES_STABLE_TIME	(3*BGE_HALFTICK)	/*    ~0.8s	*/
1722675Szh199473 #define	BGE_PHY_STABLE_TIME	(11*BGE_HALFTICK)	/*    ~3.0s	*/
1732675Szh199473 #define	BGE_LINK_SETTLE_TIME	(111*BGE_HALFTICK)	/*   ~30.0s	*/
1742675Szh199473 
1752675Szh199473 /*
1762675Szh199473  * Indices used to identify the different buffer rings internally
1772675Szh199473  */
1782675Szh199473 #define	BGE_STD_BUFF_RING	0
1792675Szh199473 #define	BGE_JUMBO_BUFF_RING	1
1802675Szh199473 #define	BGE_MINI_BUFF_RING	2
1812675Szh199473 
1822675Szh199473 /*
1832675Szh199473  * Current implementation limits
1842675Szh199473  */
1852675Szh199473 #define	BGE_BUFF_RINGS_USED	2		/* std & jumbo ring	*/
1862675Szh199473 						/* for now		*/
1872675Szh199473 #define	BGE_RECV_RINGS_USED	16		/* up to 16 rtn rings	*/
1882675Szh199473 						/* for now		*/
1892675Szh199473 #define	BGE_SEND_RINGS_USED	4		/* up to 4 tx rings	*/
1902675Szh199473 						/* for now		*/
1912675Szh199473 #define	BGE_HASH_TABLE_SIZE	128		/* may be 256 later	*/
1922675Szh199473 
1932675Szh199473 /*
1942675Szh199473  * Ring/buffer size parameters
1952675Szh199473  *
1962675Szh199473  * All of the (up to) 16 TX rings & and the corresponding buffers are the
1972675Szh199473  * same size.
1982675Szh199473  *
1992675Szh199473  * Each of the (up to) 3 receive producer (aka buffer) rings is a different
2002675Szh199473  * size and has different sized buffers associated with it too.
2012675Szh199473  *
2022675Szh199473  * The (up to) 16 receive return rings have no buffers associated with them.
2032675Szh199473  * The number of slots per receive return ring must be 2048 if the mini
2042675Szh199473  * ring is enabled, otherwise it may be 1024.  See Broadcom document
2052675Szh199473  * 570X-PG102-R page 56.
2062675Szh199473  *
2072675Szh199473  * Note: only the 5700 supported external memory (and therefore the mini
2082675Szh199473  * ring); the 5702/3/4 don't.  This driver doesn't support the original
2092675Szh199473  * 5700, so we won't ever use the mini ring capability.
2102675Szh199473  */
2112675Szh199473 
2122675Szh199473 #define	BGE_SEND_RINGS_DEFAULT		1
2132675Szh199473 #define	BGE_RECV_RINGS_DEFAULT		1
2142675Szh199473 
2152675Szh199473 #define	BGE_SEND_BUFF_SIZE_DEFAULT	1536
2162675Szh199473 #define	BGE_SEND_BUFF_SIZE_JUMBO	9022
2172675Szh199473 #define	BGE_SEND_SLOTS_USED	512
2182675Szh199473 
2192675Szh199473 #define	BGE_STD_BUFF_SIZE	1536		/* 0x600		*/
2202675Szh199473 #define	BGE_STD_SLOTS_USED	512
2212675Szh199473 
2222675Szh199473 #define	BGE_JUMBO_BUFF_SIZE	9022		/* 9k			*/
2232675Szh199473 #define	BGE_JUMBO_SLOTS_USED	256
2242675Szh199473 
2252675Szh199473 #define	BGE_MINI_BUFF_SIZE	128		/* 64? 256?		*/
2262675Szh199473 #define	BGE_MINI_SLOTS_USED	0		/* must be 0; see above	*/
2272675Szh199473 
2282675Szh199473 #define	BGE_RECV_BUFF_SIZE	0
2292675Szh199473 #if	BGE_MINI_SLOTS_USED > 0
2302675Szh199473 #define	BGE_RECV_SLOTS_USED	2048		/* required		*/
2312675Szh199473 #else
2322675Szh199473 #define	BGE_RECV_SLOTS_USED	1024		/* could be 2048 anyway	*/
2332675Szh199473 #endif
2342675Szh199473 
2353334Sgs150176 #define	BGE_SEND_BUF_NUM	512
2363334Sgs150176 #define	BGE_SEND_BUF_ARRAY	16
2373334Sgs150176 #define	BGE_SEND_BUF_ARRAY_JUMBO	3
2383334Sgs150176 #define	BGE_SEND_BUF_MAX	(BGE_SEND_BUF_NUM*BGE_SEND_BUF_ARRAY)
2393334Sgs150176 
2402675Szh199473 /*
2412675Szh199473  * PCI type. PCI-Express or PCI/PCIX
2422675Szh199473  */
2432675Szh199473 #define	BGE_PCI		0
2442675Szh199473 #define	BGE_PCI_E	1
2452675Szh199473 #define	BGE_PCI_X	2
2462675Szh199473 
2472675Szh199473 /*
2482675Szh199473  * Statistic type. There are two type of statistic:
2492675Szh199473  * statistic block and statistic registers
2502675Szh199473  */
2512675Szh199473 #define	BGE_STAT_BLK	1
2522675Szh199473 #define	BGE_STAT_REG	2
2532675Szh199473 
2542675Szh199473 /*
2552675Szh199473  * MTU.for all chipsets ,the default is 1500 ,and some chipsets
2562675Szh199473  * support 9k jumbo frames size
2572675Szh199473  */
2582675Szh199473 #define	BGE_DEFAULT_MTU		1500
2592675Szh199473 #define	BGE_MAXIMUM_MTU		9000
2602675Szh199473 
2612675Szh199473 /*
2622675Szh199473  * Pad the h/w defined status block (which can be up to 80 bytes long)
2632675Szh199473  * to a power-of-two boundary
2642675Szh199473  */
2652675Szh199473 #define	BGE_STATUS_PADDING	(128 - sizeof (bge_status_t))
2662675Szh199473 
2672675Szh199473 /*
2682675Szh199473  * On platforms which support DVMA, we can simply allocate one big piece
2692675Szh199473  * of memory for all the Tx buffers and another for the Rx buffers, and
2702675Szh199473  * then carve them up as required.  It doesn't matter if they aren't just
2712675Szh199473  * one physically contiguous piece each, because both the CPU *and* the
2722675Szh199473  * I/O device can see them *as though they were*.
2732675Szh199473  *
2742675Szh199473  * However, if only physically-addressed DMA is possible, this doesn't
2752675Szh199473  * work; we can't expect to get enough contiguously-addressed memory for
2762675Szh199473  * all the buffers of each type, so in this case we request a number of
2772675Szh199473  * smaller pieces, each still large enough for several buffers but small
2782675Szh199473  * enough to fit within "an I/O page" (e.g. 64K).
2792675Szh199473  *
2802675Szh199473  * The #define below specifies how many pieces of memory are to be used;
2812675Szh199473  * 16 has been shown to work on an i86pc architecture but this could be
2822675Szh199473  * different on other non-DVMA platforms ...
2832675Szh199473  */
2842675Szh199473 #ifdef	_DMA_USES_VIRTADDR
2852675Szh199473 #define	BGE_SPLIT		1		/* no split required	*/
2862675Szh199473 #else
2872675Szh199473 #if ((BGE_BUFF_RINGS_USED > 1) || (BGE_SEND_RINGS_USED > 1) || \
2882675Szh199473 	(BGE_RECV_RINGS_USED > 1))
2892675Szh199473 #define	BGE_SPLIT		128		/* split 128 ways	*/
2902675Szh199473 #else
2912675Szh199473 #define	BGE_SPLIT		16		/* split 16 ways	*/
2922675Szh199473 #endif
2932675Szh199473 #endif	/* _DMA_USES_VIRTADDR */
2942675Szh199473 
2952675Szh199473 #define	BGE_RECV_RINGS_SPLIT	(BGE_RECV_RINGS_MAX + 1)
2962675Szh199473 
2972675Szh199473 /*
2982675Szh199473  * STREAMS parameters
2992675Szh199473  */
3002675Szh199473 #define	BGE_IDNUM		0		/* zero seems to work	*/
3012675Szh199473 #define	BGE_LOWAT		(256)
3022675Szh199473 #define	BGE_HIWAT		(256*1024)
3032675Szh199473 
3042675Szh199473 
3052675Szh199473 /*
3062675Szh199473  * Basic data types, for clarity in distinguishing 'numbers'
3072675Szh199473  * used for different purposes ...
3082675Szh199473  *
3092675Szh199473  * A <bge_regno_t> is a register 'address' (offset) in any one of
3102675Szh199473  * various address spaces (PCI config space, PCI memory-mapped I/O
3112675Szh199473  * register space, MII registers, etc).  None of these exceeds 64K,
3122675Szh199473  * so we could use a 16-bit representation but pointer-sized objects
3132675Szh199473  * are more "natural" in most architectures; they seem to be handled
3142675Szh199473  * more efficiently on SPARC and no worse on x86.
3152675Szh199473  *
3162675Szh199473  * BGE_REGNO_NONE represents the non-existent value in this space.
3172675Szh199473  */
3182675Szh199473 typedef uintptr_t bge_regno_t;			/* register # (offset)	*/
3192675Szh199473 #define	BGE_REGNO_NONE		(~(uintptr_t)0u)
3202675Szh199473 
3212675Szh199473 /*
3222675Szh199473  * Describes one chunk of allocated DMA-able memory
3232675Szh199473  *
3242675Szh199473  * In some cases, this is a single chunk as allocated from the system;
3252675Szh199473  * but we also use this structure to represent slices carved off such
3262675Szh199473  * a chunk.  Even when we don't really need all the information, we
3272675Szh199473  * use this structure as a convenient way of correlating the various
3282675Szh199473  * ways of looking at a piece of memory (kernel VA, IO space DVMA,
3292675Szh199473  * handle+offset, etc).
3302675Szh199473  */
3312675Szh199473 typedef struct {
3322675Szh199473 	ddi_acc_handle_t	acc_hdl;	/* handle for memory	*/
3332675Szh199473 	void			*mem_va;	/* CPU VA of memory	*/
3342675Szh199473 	uint32_t		nslots;		/* number of slots	*/
3352675Szh199473 	uint32_t		size;		/* size per slot	*/
3362675Szh199473 	size_t			alength;	/* allocated size	*/
3372675Szh199473 						/* >= product of above	*/
3382675Szh199473 
3392675Szh199473 	ddi_dma_handle_t	dma_hdl;	/* DMA handle		*/
3402675Szh199473 	offset_t		offset;		/* relative to handle	*/
3412675Szh199473 	ddi_dma_cookie_t	cookie;		/* associated cookie	*/
3422675Szh199473 	uint32_t		ncookies;	/* must be 1		*/
3432675Szh199473 	uint32_t		token;		/* arbitrary identifier	*/
3442675Szh199473 } dma_area_t;					/* 0x50 (80) bytes	*/
3452675Szh199473 
3463334Sgs150176 typedef struct bge_queue_item {
3473334Sgs150176 	struct bge_queue_item	*next;
3483334Sgs150176 	void			*item;
3493334Sgs150176 } bge_queue_item_t;
3503334Sgs150176 
3513334Sgs150176 typedef struct bge_queue {
3523334Sgs150176 	bge_queue_item_t	*head;
3533334Sgs150176 	uint32_t		count;
3543334Sgs150176 	kmutex_t		*lock;
3553334Sgs150176 } bge_queue_t;
3562675Szh199473 /*
3572675Szh199473  * Software version of the Receive Buffer Descriptor
3582675Szh199473  * There's one of these for each receive buffer (up to 256/512/1024 per ring).
3592675Szh199473  */
3602675Szh199473 typedef struct sw_rbd {
3612675Szh199473 	dma_area_t		pbuf;		/* (const) related	*/
3622675Szh199473 						/* buffer area		*/
3632675Szh199473 } sw_rbd_t;					/* 0x50 (80) bytes	*/
3642675Szh199473 
3652675Szh199473 /*
3662675Szh199473  * Software Receive Buffer (Producer) Ring Control Block
3672675Szh199473  * There's one of these for each receiver producer ring (up to 3),
3682675Szh199473  * but each holds buffers of a different size.
3692675Szh199473  */
3702675Szh199473 typedef struct buff_ring {
3712675Szh199473 	dma_area_t		desc;		/* (const) related h/w	*/
3722675Szh199473 						/* descriptor area	*/
3732675Szh199473 	dma_area_t		buf[BGE_SPLIT];	/* (const) related	*/
3742675Szh199473 						/* buffer area(s)	*/
3752675Szh199473 	bge_rcb_t		hw_rcb;		/* (const) image of h/w	*/
3762675Szh199473 						/* RCB, and used to	*/
3772675Szh199473 	struct bge		*bgep;		/* (const) containing	*/
3782675Szh199473 						/* driver soft state	*/
3792675Szh199473 						/* initialise same	*/
3802675Szh199473 	volatile uint16_t	*cons_index_p;	/* (const) ptr to h/w	*/
3812675Szh199473 						/* "consumer index"	*/
3822675Szh199473 						/* (in status block)	*/
3832675Szh199473 
3842675Szh199473 	/*
3852675Szh199473 	 * The rf_lock must be held when updating the h/w producer index
3862675Szh199473 	 * mailbox register (*chip_mbox_reg), or the s/w producer index
3872675Szh199473 	 * (rf_next).
3882675Szh199473 	 */
3892675Szh199473 	bge_regno_t		chip_mbx_reg;	/* (const) h/w producer	*/
3902675Szh199473 						/* index mailbox offset	*/
3912675Szh199473 	kmutex_t		rf_lock[1];	/* serialize refill	*/
3922675Szh199473 	uint64_t		rf_next;	/* next slot to refill	*/
3932675Szh199473 						/* ("producer index")	*/
3942675Szh199473 
3952675Szh199473 	sw_rbd_t		*sw_rbds; 	/* software descriptors	*/
3962675Szh199473 	void			*spare[4];	/* padding		*/
3972675Szh199473 } buff_ring_t;					/* 0x100 (256) bytes	*/
3982675Szh199473 
3998275SEric Cheng typedef struct bge_multi_mac {
4008275SEric Cheng 	int		naddr;		/* total supported addresses */
4018275SEric Cheng 	int		naddrfree;	/* free addresses slots */
4028275SEric Cheng 	ether_addr_t	mac_addr[MAC_ADDRESS_REGS_MAX];
4038275SEric Cheng 	boolean_t	mac_addr_set[MAC_ADDRESS_REGS_MAX];
4048275SEric Cheng } bge_multi_mac_t;
4058275SEric Cheng 
4062675Szh199473 /*
4072675Szh199473  * Software Receive (Return) Ring Control Block
4082675Szh199473  * There's one of these for each receiver return ring (up to 16).
4092675Szh199473  */
4102675Szh199473 typedef struct recv_ring {
4112675Szh199473 	/*
4122675Szh199473 	 * The elements flagged (const) in the comments below are
4132675Szh199473 	 * set up once during initialiation and thereafter unchanged.
4142675Szh199473 	 */
4152675Szh199473 	dma_area_t		desc;		/* (const) related h/w	*/
4162675Szh199473 						/* descriptor area	*/
4172675Szh199473 	bge_rcb_t		hw_rcb;		/* (const) image of h/w	*/
4182675Szh199473 						/* RCB, and used to	*/
4192675Szh199473 						/* initialise same	*/
4202675Szh199473 	struct bge		*bgep;		/* (const) containing	*/
4212675Szh199473 						/* driver soft state	*/
4222675Szh199473 	ddi_softintr_t		rx_softint;	/* (const) per-ring	*/
4232675Szh199473 						/* receive callback	*/
4242675Szh199473 	volatile uint16_t	*prod_index_p;	/* (const) ptr to h/w	*/
4252675Szh199473 						/* "producer index"	*/
4262675Szh199473 						/* (in status block)	*/
4272675Szh199473 	/*
4282675Szh199473 	 * The rx_lock must be held when updating the h/w consumer index
4292675Szh199473 	 * mailbox register (*chip_mbox_reg), or the s/w consumer index
4302675Szh199473 	 * (rx_next).
4312675Szh199473 	 */
4322675Szh199473 	bge_regno_t		chip_mbx_reg;	/* (const) h/w consumer	*/
4332675Szh199473 						/* index mailbox offset	*/
4342675Szh199473 	kmutex_t		rx_lock[1];	/* serialize receive	*/
4352675Szh199473 	uint64_t		rx_next;	/* next slot to examine	*/
4368275SEric Cheng 
4378275SEric Cheng 	mac_ring_handle_t	ring_handle;
4388275SEric Cheng 	mac_group_handle_t	ring_group_handle;
4398275SEric Cheng 	uint64_t		ring_gen_num;
4408275SEric Cheng 	bge_rule_info_t		*mac_addr_rule;
4418275SEric Cheng 	uint8_t			mac_addr_val[ETHERADDRL];
4428275SEric Cheng 	int			poll_flag;	/* Polling flag		*/
44311878SVenu.Iyer@Sun.COM 
44411878SVenu.Iyer@Sun.COM 	/* Per-ring statistics */
44511878SVenu.Iyer@Sun.COM 	uint64_t		rx_pkts;	/* Received Packets Count */
44611878SVenu.Iyer@Sun.COM 	uint64_t		rx_bytes;	/* Received Bytes Count */
44711878SVenu.Iyer@Sun.COM } recv_ring_t;
4482675Szh199473 
4498275SEric Cheng 
4502675Szh199473 /*
4513334Sgs150176  * Send packet structure
4523334Sgs150176  */
4533334Sgs150176 typedef struct send_pkt {
4543334Sgs150176 	uint16_t		vlan_tci;
4553334Sgs150176 	uint32_t		pflags;
4563334Sgs150176 	boolean_t		tx_ready;
4573334Sgs150176 	bge_queue_item_t	*txbuf_item;
4583334Sgs150176 } send_pkt_t;
4593334Sgs150176 
4603334Sgs150176 /*
4613334Sgs150176  * Software version of tx buffer structure
4623334Sgs150176  */
4633334Sgs150176 typedef struct sw_txbuf {
4643334Sgs150176 	dma_area_t		buf;
4653334Sgs150176 	uint32_t		copy_len;
4663334Sgs150176 } sw_txbuf_t;
4673334Sgs150176 
4683334Sgs150176 /*
4692675Szh199473  * Software version of the Send Buffer Descriptor
4702675Szh199473  * There's one of these for each send buffer (up to 512 per ring)
4712675Szh199473  */
4722675Szh199473 typedef struct sw_sbd {
4732675Szh199473 	dma_area_t		desc;		/* (const) related h/w	*/
4742675Szh199473 						/* descriptor area	*/
4753334Sgs150176 	bge_queue_item_t	*pbuf;		/* (const) related	*/
4762675Szh199473 						/* buffer area		*/
4773334Sgs150176 } sw_sbd_t;
4782675Szh199473 
4792675Szh199473 /*
4802675Szh199473  * Software Send Ring Control Block
4812675Szh199473  * There's one of these for each of (up to) 16 send rings
4822675Szh199473  */
4832675Szh199473 typedef struct send_ring {
4842675Szh199473 	/*
4852675Szh199473 	 * The elements flagged (const) in the comments below are
4862675Szh199473 	 * set up once during initialiation and thereafter unchanged.
4872675Szh199473 	 */
4882675Szh199473 	dma_area_t		desc;		/* (const) related h/w	*/
4892675Szh199473 						/* descriptor area	*/
4903334Sgs150176 	dma_area_t		buf[BGE_SEND_BUF_ARRAY][BGE_SPLIT];
4912675Szh199473 						/* buffer area(s)	*/
4922675Szh199473 	bge_rcb_t		hw_rcb;		/* (const) image of h/w	*/
4932675Szh199473 						/* RCB, and used to	*/
4942675Szh199473 						/* initialise same	*/
4952675Szh199473 	struct bge		*bgep;		/* (const) containing	*/
4962675Szh199473 						/* driver soft state	*/
4972675Szh199473 	volatile uint16_t	*cons_index_p;	/* (const) ptr to h/w	*/
4982675Szh199473 						/* "consumer index"	*/
4992675Szh199473 						/* (in status block)	*/
5002675Szh199473 
5012675Szh199473 	bge_regno_t		chip_mbx_reg;	/* (const) h/w producer	*/
5022675Szh199473 						/* index mailbox offset	*/
5033334Sgs150176 	/*
5043334Sgs150176 	 * Tx buffer queue
5053334Sgs150176 	 */
5063334Sgs150176 	bge_queue_t		txbuf_queue;
5073334Sgs150176 	bge_queue_t		freetxbuf_queue;
5083334Sgs150176 	bge_queue_t		*txbuf_push_queue;
5093334Sgs150176 	bge_queue_t		*txbuf_pop_queue;
5103334Sgs150176 	kmutex_t		txbuf_lock[1];
5113334Sgs150176 	kmutex_t		freetxbuf_lock[1];
5123334Sgs150176 	bge_queue_item_t	*txbuf_head;
5133334Sgs150176 	send_pkt_t		*pktp;
5143334Sgs150176 	uint64_t		txpkt_next;
5153334Sgs150176 	uint64_t		txfill_next;
5163334Sgs150176 	sw_txbuf_t		*txbuf;
5173334Sgs150176 	uint32_t		tx_buffers;
5183334Sgs150176 	uint32_t		tx_buffers_low;
5193334Sgs150176 	uint32_t		tx_array_max;
5203334Sgs150176 	uint32_t		tx_array;
5212675Szh199473 	kmutex_t		tx_lock[1];	/* serialize h/w update	*/
5222675Szh199473 						/* ("producer index")	*/
5232675Szh199473 	uint64_t		tx_next;	/* next slot to use	*/
5242675Szh199473 	uint64_t		tx_flow;	/* # concurrent sends	*/
5253334Sgs150176 	uint64_t		tx_block;
5263334Sgs150176 	uint64_t		tx_nobd;
5273334Sgs150176 	uint64_t		tx_nobuf;
5283334Sgs150176 	uint64_t		tx_alloc_fail;
5292675Szh199473 
5302675Szh199473 	/*
5312675Szh199473 	 * These counters/indexes are manipulated in the transmit
5322675Szh199473 	 * path using atomics rather than mutexes for speed
5332675Szh199473 	 */
5342675Szh199473 	uint64_t		tx_free;	/* # of slots available	*/
5352675Szh199473 
5362675Szh199473 	/*
5372675Szh199473 	 * The tc_lock must be held while manipulating the s/w consumer
5382675Szh199473 	 * index (tc_next).
5392675Szh199473 	 */
5402675Szh199473 	kmutex_t		tc_lock[1];	/* serialize recycle	*/
5412675Szh199473 	uint64_t		tc_next;	/* next slot to recycle	*/
5422675Szh199473 						/* ("consumer index")	*/
5432675Szh199473 
5442675Szh199473 	sw_sbd_t		*sw_sbds; 	/* software descriptors	*/
5452675Szh199473 	uint64_t		mac_resid;	/* special per resource id */
5468275SEric Cheng 	uint64_t		pushed_bytes;
5472675Szh199473 } send_ring_t;					/* 0x100 (256) bytes	*/
5482675Szh199473 
5492675Szh199473 typedef struct {
5502675Szh199473 	ether_addr_t		addr;		/* in canonical form	*/
5512675Szh199473 	uint8_t			spare;
5522675Szh199473 	boolean_t		set;		/* B_TRUE => valid	*/
5532675Szh199473 } bge_mac_addr_t;
5542675Szh199473 
5552675Szh199473 /*
5562675Szh199473  * The original 5700/01 supported only SEEPROMs.  Later chips (5702+)
5572675Szh199473  * support both SEEPROMs (using the same 2-wire CLK/DATA interface for
5582675Szh199473  * the hardware and a backwards-compatible software access method), and
5592675Szh199473  * buffered or unbuffered FLASH devices connected to the 4-wire SPI bus
5602675Szh199473  * and using a new software access method.
5612675Szh199473  *
5622675Szh199473  * The access methods for SEEPROM and Flash are generally similar, with
5632675Szh199473  * the chip handling the serialisation/deserialisation and handshaking,
5642675Szh199473  * but the registers used are different, as are a few details of the
5652675Szh199473  * protocol, and the timing, so we have to determine which (if any) is
5662675Szh199473  * fitted.
5672675Szh199473  *
5682675Szh199473  * The value UNKNOWN means just that; we haven't yet tried to determine
5692675Szh199473  * the device type.
5702675Szh199473  *
5712675Szh199473  * The value NONE can indicate either that a real and definite absence of
5722675Szh199473  * any NVmem has been detected, or that there may be NVmem but we can't
5732675Szh199473  * determine its type, perhaps because the NVconfig pins on the chip have
5742675Szh199473  * been wired up incorrectly.  In either case, access to the NVmem (if any)
5752675Szh199473  * is not supported.
5762675Szh199473  */
5772675Szh199473 enum bge_nvmem_type {
5782675Szh199473 	BGE_NVTYPE_NONE = -1,			/* (or indeterminable)	*/
5792675Szh199473 	BGE_NVTYPE_UNKNOWN,			/* not yet checked	*/
5802675Szh199473 	BGE_NVTYPE_SEEPROM,			/* BCM5700/5701 only	*/
5812675Szh199473 	BGE_NVTYPE_LEGACY_SEEPROM,		/* 5702+		*/
5822675Szh199473 	BGE_NVTYPE_UNBUFFERED_FLASH,		/* 5702+		*/
5832675Szh199473 	BGE_NVTYPE_BUFFERED_FLASH		/* 5702+		*/
5842675Szh199473 };
5852675Szh199473 
5862675Szh199473 /*
5872675Szh199473  * Describes the characteristics of a specific chip
5882675Szh199473  *
5892675Szh199473  * Note: elements from <businfo> to <latency> are filled in by during
5902675Szh199473  * the first phase of chip initialisation (see bge_chip_cfg_init()).
5912675Szh199473  * The remaining ones are determined just after the first RESET, in
5922675Szh199473  * bge_poll_firmware().  Thereafter, the entire structure is readonly.
5932675Szh199473  */
5942675Szh199473 typedef struct {
5952675Szh199473 	uint32_t		asic_rev;	/* masked from MHCR	*/
5962675Szh199473 	uint32_t		businfo;	/* from private reg	*/
5972675Szh199473 	uint16_t		command;	/* saved during attach	*/
5982675Szh199473 
5992675Szh199473 	uint16_t		vendor;		/* vendor-id		*/
6002675Szh199473 	uint16_t		device;		/* device-id		*/
6012675Szh199473 	uint16_t		subven;		/* subsystem-vendor-id	*/
6022675Szh199473 	uint16_t		subdev;		/* subsystem-id		*/
6032675Szh199473 	uint8_t			revision;	/* revision-id		*/
6042675Szh199473 	uint8_t			clsize;		/* cache-line-size	*/
6052675Szh199473 	uint8_t			latency;	/* latency-timer	*/
6062675Szh199473 
6072675Szh199473 	uint8_t			flags;
6082675Szh199473 	uint16_t		chip_label;	/* numeric part only	*/
6092675Szh199473 						/* (e.g. 5703/5794/etc)	*/
6102675Szh199473 	uint32_t		mbuf_base;	/* Mbuf pool parameters */
6112675Szh199473 	uint32_t		mbuf_length;	/* depend on chiptype	*/
6122675Szh199473 	uint32_t		pci_type;
6132675Szh199473 	uint32_t		statistic_type;
6142675Szh199473 	uint32_t		bge_dma_rwctrl;
6152675Szh199473 	uint32_t		bge_mlcr_default;
6162675Szh199473 	uint32_t		recv_slots;	/* receive ring size    */
6172675Szh199473 	enum bge_nvmem_type	nvtype;		/* SEEPROM or Flash	*/
6182675Szh199473 
6192675Szh199473 	uint16_t		jumbo_slots;
6202675Szh199473 	uint16_t		ethmax_size;
6212675Szh199473 	uint16_t		snd_buff_size;
6222675Szh199473 	uint16_t		recv_jumbo_size;
6232675Szh199473 	uint16_t		std_buf_size;
6242675Szh199473 	uint32_t		mbuf_hi_water;
6252675Szh199473 	uint32_t		mbuf_lo_water_rmac;
6262675Szh199473 	uint32_t		mbuf_lo_water_rdma;
6272675Szh199473 
6283334Sgs150176 	uint32_t		rx_rings;	/* from bge.conf	*/
6293334Sgs150176 	uint32_t		tx_rings;	/* from bge.conf	*/
6303334Sgs150176 	uint32_t		default_mtu;	/* from bge.conf	*/
6312675Szh199473 
6322675Szh199473 	uint64_t		hw_mac_addr;	/* from chip register	*/
6332675Szh199473 	bge_mac_addr_t		vendor_addr;	/* transform of same	*/
6342675Szh199473 	boolean_t		msi_enabled;	/* default to true */
6355903Ssowmini 
6365903Ssowmini 	uint32_t		rx_ticks_norm;
6375903Ssowmini 	uint32_t		rx_count_norm;
6389731SYong.Tan@Sun.COM 	uint32_t		tx_ticks_norm;
6399731SYong.Tan@Sun.COM 	uint32_t		tx_count_norm;
64011968SYong.Tan@Sun.COM 	uint32_t		mask_pci_int;
6412675Szh199473 } chip_id_t;
6422675Szh199473 
6432675Szh199473 #define	CHIP_FLAG_SUPPORTED	0x80
6442675Szh199473 #define	CHIP_FLAG_SERDES	0x40
6452675Szh199473 #define	CHIP_FLAG_PARTIAL_CSUM	0x20
6462675Szh199473 #define	CHIP_FLAG_NO_JUMBO	0x1
6472675Szh199473 
6482675Szh199473 /*
6492675Szh199473  * Collection of physical-layer functions to:
6502675Szh199473  *	(re)initialise the physical layer
6512675Szh199473  *	update it to match software settings
6522675Szh199473  *	check for link status change
6532675Szh199473  */
6542675Szh199473 typedef struct {
6552675Szh199473 	int			(*phys_restart)(struct bge *, boolean_t);
6562675Szh199473 	int			(*phys_update)(struct bge *);
6572675Szh199473 	boolean_t		(*phys_check)(struct bge *, boolean_t);
6582675Szh199473 } phys_ops_t;
6592675Szh199473 
6602675Szh199473 
6612675Szh199473 /*
6622675Szh199473  * Actual state of the BCM570x chip
6632675Szh199473  */
6642675Szh199473 enum bge_chip_state {
6652675Szh199473 	BGE_CHIP_FAULT = -2,			/* fault, need reset	*/
6662675Szh199473 	BGE_CHIP_ERROR,				/* error, want reset	*/
6672675Szh199473 	BGE_CHIP_INITIAL,			/* Initial state only	*/
6682675Szh199473 	BGE_CHIP_RESET,				/* reset, need init	*/
6692675Szh199473 	BGE_CHIP_STOPPED,			/* Tx/Rx stopped	*/
6702675Szh199473 	BGE_CHIP_RUNNING			/* with interrupts	*/
6712675Szh199473 };
6722675Szh199473 
6732675Szh199473 enum bge_mac_state {
6742675Szh199473 	BGE_MAC_STOPPED = 0,
6752675Szh199473 	BGE_MAC_STARTED
6762675Szh199473 };
6772675Szh199473 
6782675Szh199473 /*
6792675Szh199473  * (Internal) return values from ioctl subroutines
6802675Szh199473  */
6812675Szh199473 enum ioc_reply {
6822675Szh199473 	IOC_INVAL = -1,				/* bad, NAK with EINVAL	*/
6832675Szh199473 	IOC_DONE,				/* OK, reply sent	*/
6842675Szh199473 	IOC_ACK,				/* OK, just send ACK	*/
6852675Szh199473 	IOC_REPLY,				/* OK, just send reply	*/
6862675Szh199473 	IOC_RESTART_ACK,			/* OK, restart & ACK	*/
6872675Szh199473 	IOC_RESTART_REPLY			/* OK, restart & reply	*/
6882675Szh199473 };
6892675Szh199473 
6902675Szh199473 /*
6912675Szh199473  * (Internal) return values from send_msg subroutines
6922675Szh199473  */
6932675Szh199473 enum send_status {
6942675Szh199473 	SEND_FAIL = -1,				/* Not OK		*/
6952675Szh199473 	SEND_KEEP,				/* OK, msg queued	*/
6962675Szh199473 	SEND_FREE				/* OK, free msg		*/
6972675Szh199473 };
6982675Szh199473 
6992675Szh199473 /*
7002675Szh199473  * (Internal) enumeration of this driver's kstats
7012675Szh199473  */
7022675Szh199473 enum {
7032675Szh199473 	BGE_KSTAT_RAW = 0,
7042675Szh199473 	BGE_KSTAT_STATS,
7052675Szh199473 	BGE_KSTAT_CHIPID,
7062675Szh199473 	BGE_KSTAT_DRIVER,
7072675Szh199473 	BGE_KSTAT_PHYS,
7082675Szh199473 
7092675Szh199473 	BGE_KSTAT_COUNT
7102675Szh199473 };
7112675Szh199473 
7122675Szh199473 #define	BGE_MAX_RESOURCES 255
7132675Szh199473 
7142675Szh199473 /*
7152675Szh199473  * Per-instance soft-state structure
7162675Szh199473  */
7172675Szh199473 typedef struct bge {
7182675Szh199473 	/*
7192675Szh199473 	 * These fields are set by attach() and unchanged thereafter ...
7202675Szh199473 	 */
7212675Szh199473 	dev_info_t		*devinfo;	/* device instance	*/
7222675Szh199473 	mac_handle_t		mh;		/* mac module handle	*/
7232675Szh199473 	ddi_acc_handle_t	cfg_handle;	/* DDI I/O handle	*/
7242675Szh199473 	ddi_acc_handle_t	io_handle;	/* DDI I/O handle	*/
7252675Szh199473 	void			*io_regs;	/* mapped registers	*/
7265107Seota 	ddi_periodic_t		periodic_id;	/* periodical callback	*/
7272675Szh199473 	ddi_softintr_t		factotum_id;	/* factotum callback	*/
7283334Sgs150176 	ddi_softintr_t		drain_id;	/* reschedule callback	*/
7292675Szh199473 
7302675Szh199473 	ddi_intr_handle_t 	*htable;	/* For array of interrupts */
7312675Szh199473 	int			intr_type;	/* What type of interrupt */
7322675Szh199473 	int			intr_cnt;	/* # of intrs count returned */
7332675Szh199473 	uint_t			intr_pri;	/* Interrupt priority	*/
7342675Szh199473 	int			intr_cap;	/* Interrupt capabilities */
7352675Szh199473 	uint32_t		progress;	/* attach tracking	*/
7362675Szh199473 	uint32_t		debug;		/* per-instance debug	*/
7372675Szh199473 	chip_id_t		chipid;
7382675Szh199473 	const phys_ops_t	*physops;
7392675Szh199473 	char			ifname[8];	/* "bge0" ... "bge999"	*/
7402675Szh199473 
7412675Szh199473 	int			fm_capabilities;	/* FMA capabilities */
7422675Szh199473 
7432675Szh199473 	/*
7442675Szh199473 	 * These structures describe the blocks of memory allocated during
7452675Szh199473 	 * attach().  They remain unchanged thereafter, although the memory
7462675Szh199473 	 * they describe is carved up into various separate regions and may
7472675Szh199473 	 * therefore be described by other structures as well.
7482675Szh199473 	 */
7492675Szh199473 	dma_area_t		tx_desc;	/* transmit descriptors	*/
7502675Szh199473 	dma_area_t		rx_desc[BGE_RECV_RINGS_SPLIT];
7512675Szh199473 						/* receive descriptors	*/
7522675Szh199473 	dma_area_t		tx_buff[BGE_SPLIT];
7532675Szh199473 	dma_area_t		rx_buff[BGE_SPLIT];
7542675Szh199473 
7552675Szh199473 	/*
7562675Szh199473 	 * The memory described by the <dma_area> structures above
7572675Szh199473 	 * is carved up into various pieces, which are described by
7582675Szh199473 	 * the structures below.
7592675Szh199473 	 */
7602675Szh199473 	dma_area_t		statistics;	/* describes hardware	*/
7612675Szh199473 						/* statistics area	*/
7622675Szh199473 	dma_area_t		status_block;	/* describes hardware	*/
7632675Szh199473 						/* status block		*/
7642675Szh199473 	/*
7652675Szh199473 	 * For the BCM5705/5788/5721/5751/5752/5714 and 5715,
7662675Szh199473 	 * the statistic block is not available,the statistic counter must
7672675Szh199473 	 * be gotten from statistic registers.And bge_statistics_reg_t record
7682675Szh199473 	 * the statistic registers value
7692675Szh199473 	 */
7703334Sgs150176 	bge_statistics_reg_t	*pstats;
7712675Szh199473 
7722675Szh199473 	/*
7732675Szh199473 	 * Runtime read-write data starts here ...
7742675Szh199473 	 *
7752675Szh199473 	 * 3 Buffer Rings (std/jumbo/mini)
7762675Szh199473 	 * 16 Receive (Return) Rings
7772675Szh199473 	 * 16 Send Rings
7782675Szh199473 	 *
7792675Szh199473 	 * Note: they're not necessarily all used.
7802675Szh199473 	 */
7812675Szh199473 	buff_ring_t		buff[BGE_BUFF_RINGS_MAX]; /*  3*0x0100	*/
7828275SEric Cheng 
7838275SEric Cheng 	/* may be obsoleted */
7842675Szh199473 	recv_ring_t		recv[BGE_RECV_RINGS_MAX]; /* 16*0x0090	*/
7852675Szh199473 	send_ring_t		send[BGE_SEND_RINGS_MAX]; /* 16*0x0100	*/
7862675Szh199473 
7872675Szh199473 	/*
7882675Szh199473 	 * Locks:
7892675Szh199473 	 *
7902675Szh199473 	 * Each buffer ring contains its own <rf_lock> which regulates
7912675Szh199473 	 *	ring refilling.
7922675Szh199473 	 *
7932675Szh199473 	 * Each receive (return) ring contains its own <rx_lock> which
7942675Szh199473 	 *	protects the critical cyclic counters etc.
7952675Szh199473 	 *
7962675Szh199473 	 * Each send ring contains two locks: <tx_lock> for the send-path
7972675Szh199473 	 * 	protocol data and <tc_lock> for send-buffer recycling.
7982675Szh199473 	 *
7992675Szh199473 	 * Finally <genlock> is a general lock, protecting most other
8002675Szh199473 	 *	operational data in the state structure and chip register
8012675Szh199473 	 *	accesses.  It is acquired by the interrupt handler and
8022675Szh199473 	 *	most "mode-control" routines.
8032675Szh199473 	 *
8042675Szh199473 	 * Any of the locks can be acquired singly, but where multiple
8052675Szh199473 	 * locks are acquired, they *must* be in the order:
8062675Szh199473 	 *
8072675Szh199473 	 *	genlock >>> rx_lock >>> rf_lock >>> tx_lock >>> tc_lock.
8082675Szh199473 	 *
8092675Szh199473 	 * and within any one class of lock the rings must be locked in
8102675Szh199473 	 * ascending order (send[0].tc_lock >>> send[1].tc_lock), etc.
8112675Szh199473 	 *
8122675Szh199473 	 * Note: actually I don't believe there's any need to acquire
8132675Szh199473 	 * locks on multiple rings, or even locks of all these classes
8142675Szh199473 	 * concurrently; but I've set out the above order so there is a
8152675Szh199473 	 * clear definition of lock hierarchy in case it's ever needed.
8162675Szh199473 	 *
8172675Szh199473 	 * Note: the combinations of locks that are actually held
8182675Szh199473 	 * concurrently are:
8192675Szh199473 	 *
8202675Szh199473 	 *	genlock >>>			(bge_chip_interrupt())
8212675Szh199473 	 *		rx_lock[i] >>>		(bge_receive())
8222675Szh199473 	 *			rf_lock[n]	(bge_refill())
8232675Szh199473 	 *		tc_lock[i]		(bge_recycle())
8242675Szh199473 	 */
8252675Szh199473 	kmutex_t		genlock[1];
8262675Szh199473 	krwlock_t		errlock[1];
8272675Szh199473 	kmutex_t		softintrlock[1];
8282675Szh199473 
8292675Szh199473 	/*
8302675Szh199473 	 * Current Ethernet addresses and multicast hash (bitmap) and
8312675Szh199473 	 * refcount tables, protected by <genlock>
8322675Szh199473 	 */
8332675Szh199473 	bge_mac_addr_t		curr_addr[MAC_ADDRESS_REGS_MAX];
8342675Szh199473 	uint32_t		mcast_hash[BGE_HASH_TABLE_SIZE/32];
8352675Szh199473 	uint8_t			mcast_refs[BGE_HASH_TABLE_SIZE];
8362675Szh199473 	uint32_t		unicst_addr_total; /* total unicst addresses */
8372675Szh199473 	uint32_t		unicst_addr_avail;
8382675Szh199473 					/* unused unicst addr slots */
8392675Szh199473 
8402675Szh199473 	/*
8412675Szh199473 	 * Link state data (protected by genlock)
8422675Szh199473 	 */
8432675Szh199473 	link_state_t		link_state;
8442675Szh199473 
8452675Szh199473 	/*
8462675Szh199473 	 * Physical layer: copper only
8472675Szh199473 	 */
8482675Szh199473 	bge_regno_t		phy_mii_addr;	/* should be (const) 1!	*/
8492675Szh199473 	uint16_t		phy_gen_status;
8502675Szh199473 	uint16_t		phy_aux_status;
8512675Szh199473 
8522675Szh199473 	/*
8532675Szh199473 	 * Physical layer: serdes only
8542675Szh199473 	 */
8552675Szh199473 	uint32_t		serdes_status;
8562675Szh199473 	uint32_t		serdes_advert;
8572675Szh199473 	uint32_t		serdes_lpadv;
8582675Szh199473 
8592675Szh199473 	/*
8602675Szh199473 	 * Driver kstats, protected by <genlock> where necessary
8612675Szh199473 	 */
8622675Szh199473 	kstat_t			*bge_kstats[BGE_KSTAT_COUNT];
8632675Szh199473 
8642675Szh199473 	/*
8652675Szh199473 	 * Miscellaneous operating variables (protected by genlock)
8662675Szh199473 	 */
8672675Szh199473 	uint64_t		chip_resets;	/* # of chip RESETs	*/
8682675Szh199473 	uint64_t		missed_dmas;	/* # of missed DMAs	*/
8693907Szh199473 	uint64_t		missed_updates;	/* # of missed updates	*/
8702675Szh199473 	enum bge_mac_state	bge_mac_state;	/* definitions above	*/
8712675Szh199473 	enum bge_chip_state	bge_chip_state;	/* definitions above	*/
8722675Szh199473 	boolean_t		send_hw_tcp_csum;
8732675Szh199473 	boolean_t		recv_hw_tcp_csum;
8742675Szh199473 	boolean_t		promisc;
8755903Ssowmini 	boolean_t		manual_reset;
8762675Szh199473 
8772675Szh199473 	/*
8782675Szh199473 	 * Miscellaneous operating variables (not synchronised)
8792675Szh199473 	 */
8802675Szh199473 	uint32_t		watchdog;	/* watches for Tx stall	*/
8812675Szh199473 	boolean_t		bge_intr_running;
8822675Szh199473 	boolean_t		bge_dma_error;
8833334Sgs150176 	boolean_t		tx_resched_needed;
8843334Sgs150176 	uint64_t		tx_resched;
8852675Szh199473 	uint32_t		factotum_flag;	/* softint pending	*/
8862675Szh199473 	uintptr_t		pagemask;
8872675Szh199473 
8882675Szh199473 	/*
8892675Szh199473 	 * NDD parameters (protected by genlock)
8902675Szh199473 	 */
8912675Szh199473 	caddr_t			nd_data_p;
8922675Szh199473 
8932675Szh199473 	/*
8942675Szh199473 	 * A flag to prevent excessive config space accesses
8952675Szh199473 	 * on platforms having BCM5714C/15C
8962675Szh199473 	 */
8972675Szh199473 	boolean_t		lastWriteZeroData;
8982675Szh199473 
8992675Szh199473 	/*
9002675Szh199473 	 * Spare space, plus guard element used to check data integrity
9012675Szh199473 	 */
9022675Szh199473 	uint64_t		spare[5];
9032675Szh199473 	uint64_t		bge_guard;
9042675Szh199473 
9052675Szh199473 	/*
9062675Szh199473 	 * Receive rules configure
9072675Szh199473 	 */
9082675Szh199473 	bge_recv_rule_t	recv_rules[RECV_RULES_NUM_MAX];
9092675Szh199473 
9102675Szh199473 #ifdef BGE_IPMI_ASF
9112675Szh199473 	boolean_t		asf_enabled;
9122675Szh199473 	boolean_t		asf_wordswapped;
9132675Szh199473 	boolean_t		asf_newhandshake;
9142675Szh199473 	boolean_t		asf_pseudostop;
9152675Szh199473 
9162675Szh199473 	uint32_t		asf_status;
9172675Szh199473 	timeout_id_t		asf_timeout_id;
9182675Szh199473 #endif
9195903Ssowmini 	uint32_t		param_en_pause:1,
9205903Ssowmini 				param_en_asym_pause:1,
9215903Ssowmini 				param_en_1000hdx:1,
9225903Ssowmini 				param_en_1000fdx:1,
9235903Ssowmini 				param_en_100fdx:1,
9245903Ssowmini 				param_en_100hdx:1,
9255903Ssowmini 				param_en_10fdx:1,
9265903Ssowmini 				param_en_10hdx:1,
9276512Ssowmini 				param_adv_autoneg:1,
9286512Ssowmini 				param_adv_1000fdx:1,
9296512Ssowmini 				param_adv_1000hdx:1,
9306512Ssowmini 				param_adv_100fdx:1,
9316512Ssowmini 				param_adv_100hdx:1,
9326512Ssowmini 				param_adv_10fdx:1,
9336512Ssowmini 				param_adv_10hdx:1,
9346512Ssowmini 				param_lp_autoneg:1,
9356512Ssowmini 				param_lp_pause:1,
9366512Ssowmini 				param_lp_asym_pause:1,
9376512Ssowmini 				param_lp_1000fdx:1,
9386512Ssowmini 				param_lp_1000hdx:1,
9396512Ssowmini 				param_lp_100fdx:1,
9406512Ssowmini 				param_lp_100hdx:1,
9416512Ssowmini 				param_lp_10fdx:1,
9426512Ssowmini 				param_lp_10hdx:1,
9436512Ssowmini 				param_link_up:1,
9446512Ssowmini 				param_link_autoneg:1,
9456512Ssowmini 				param_adv_pause:1,
9466512Ssowmini 				param_adv_asym_pause:1,
9476512Ssowmini 				param_link_rx_pause:1,
9486512Ssowmini 				param_link_tx_pause:1,
9496512Ssowmini 				param_pad_to_32:2;
9505903Ssowmini 
9515903Ssowmini 	uint32_t		param_loop_mode;
9526512Ssowmini 	uint32_t		param_msi_cnt;
9536512Ssowmini 	uint32_t 		param_drain_max;
9546512Ssowmini 	uint64_t		param_link_speed;
9556512Ssowmini 	link_duplex_t		param_link_duplex;
9566512Ssowmini 
9576546Sgh162552 
9586546Sgh162552 	uint32_t		link_update_timer;
959*12547SYong.Tan@Sun.COM 	uint64_t		timestamp;
9602675Szh199473 } bge_t;
9612675Szh199473 
9622675Szh199473 /*
9632675Szh199473  * 'Progress' bit flags ...
9642675Szh199473  */
9652675Szh199473 #define	PROGRESS_CFG		0x0001	/* config space mapped		*/
9662675Szh199473 #define	PROGRESS_REGS		0x0002	/* registers mapped		*/
9672675Szh199473 #define	PROGRESS_BUFS		0x0004	/* ring buffers allocated	*/
9682675Szh199473 #define	PROGRESS_RESCHED	0x0010	/* resched softint registered	*/
9692675Szh199473 #define	PROGRESS_FACTOTUM	0x0020	/* factotum softint registered	*/
9702675Szh199473 #define	PROGRESS_HWINT		0x0040	/* h/w interrupt registered	*/
9712675Szh199473 					/* and mutexen initialised	*/
9722675Szh199473 #define	PROGRESS_INTR		0x0080	/* Intrs enabled		*/
9732675Szh199473 #define	PROGRESS_PHY		0x0100	/* PHY initialised		*/
9742675Szh199473 #define	PROGRESS_NDD		0x1000	/* NDD parameters set up	*/
9752675Szh199473 #define	PROGRESS_KSTATS		0x2000	/* kstats created		*/
9762675Szh199473 #define	PROGRESS_READY		0x8000	/* ready for work		*/
9772675Szh199473 
9782675Szh199473 
9792675Szh199473 /*
9802675Szh199473  * Sync a DMA area described by a dma_area_t
9812675Szh199473  */
9822675Szh199473 #define	DMA_SYNC(area, flag)	((void) ddi_dma_sync((area).dma_hdl,	\
9832675Szh199473 				    (area).offset, (area).alength, (flag)))
9842675Szh199473 
9852675Szh199473 /*
9862675Szh199473  * Find the (kernel virtual) address of block of memory
9872675Szh199473  * described by a dma_area_t
9882675Szh199473  */
9892675Szh199473 #define	DMA_VPTR(area)		((area).mem_va)
9902675Szh199473 
9912675Szh199473 /*
9922675Szh199473  * Zero a block of memory described by a dma_area_t
9932675Szh199473  */
9942675Szh199473 #define	DMA_ZERO(area)		bzero(DMA_VPTR(area), (area).alength)
9952675Szh199473 
9962675Szh199473 /*
9972675Szh199473  * Next value of a cyclic index
9982675Szh199473  */
9993334Sgs150176 #define	NEXT(index, limit)	((index)+1 < (limit) ? (index)+1 : 0)
10002675Szh199473 
10012675Szh199473 /*
10022675Szh199473  * Property lookups
10032675Szh199473  */
10042675Szh199473 #define	BGE_PROP_EXISTS(d, n)	ddi_prop_exists(DDI_DEV_T_ANY, (d),	\
10052675Szh199473 					DDI_PROP_DONTPASS, (n))
10062675Szh199473 #define	BGE_PROP_GET_INT(d, n)	ddi_prop_get_int(DDI_DEV_T_ANY, (d),	\
10072675Szh199473 					DDI_PROP_DONTPASS, (n), -1)
10082675Szh199473 
10092675Szh199473 /*
10102675Szh199473  * Copy an ethernet address
10112675Szh199473  */
10122675Szh199473 #define	ethaddr_copy(src, dst)	bcopy((src), (dst), ETHERADDRL)
10132675Szh199473 
10142675Szh199473 /*
10152675Szh199473  * Endian swap
10162675Szh199473  */
10172675Szh199473 /* BEGIN CSTYLED */
10182675Szh199473 #define BGE_BSWAP_32(x)		((((x) & 0xff000000) >> 24)  |		\
10192675Szh199473                                  (((x) & 0x00ff0000) >> 8)   |		\
10202675Szh199473                                  (((x) & 0x0000ff00) << 8)   |		\
10212675Szh199473                                  (((x) & 0x000000ff) << 24))
10222675Szh199473 /* END CSTYLED */
10232675Szh199473 
10242675Szh199473 /*
10252675Szh199473  * Marker value placed at the end of the driver's state
10262675Szh199473  */
10272675Szh199473 #define	BGE_GUARD		0x1919306009031802
10282675Szh199473 
10292675Szh199473 /*
10302675Szh199473  * Bit flags in the 'debug' word ...
10312675Szh199473  */
10322675Szh199473 #define	BGE_DBG_STOP		0x00000001	/* early debug_enter()	*/
10332675Szh199473 #define	BGE_DBG_TRACE		0x00000002	/* general flow tracing	*/
10342675Szh199473 
10352675Szh199473 #define	BGE_DBG_REGS		0x00000010	/* low-level accesses	*/
10362675Szh199473 #define	BGE_DBG_MII		0x00000020	/* low-level MII access	*/
10372675Szh199473 #define	BGE_DBG_SEEPROM		0x00000040	/* low-level SEEPROM IO	*/
10382675Szh199473 #define	BGE_DBG_CHIP		0x00000080	/* low(ish)-level code	*/
10392675Szh199473 
10402675Szh199473 #define	BGE_DBG_RECV		0x00000100	/* receive-side code	*/
10412675Szh199473 #define	BGE_DBG_SEND		0x00000200	/* packet-send code	*/
10422675Szh199473 
10432675Szh199473 #define	BGE_DBG_INT		0x00001000	/* interrupt handler	*/
10442675Szh199473 #define	BGE_DBG_FACT		0x00002000	/* factotum (softint)	*/
10452675Szh199473 
10462675Szh199473 #define	BGE_DBG_PHY		0x00010000	/* Copper PHY code	*/
10472675Szh199473 #define	BGE_DBG_SERDES		0x00020000	/* SerDes code		*/
10482675Szh199473 #define	BGE_DBG_PHYS		0x00040000	/* Physical layer code	*/
10492675Szh199473 #define	BGE_DBG_LINK		0x00080000	/* Link status check	*/
10502675Szh199473 
10512675Szh199473 #define	BGE_DBG_INIT		0x00100000	/* initialisation	*/
10522675Szh199473 #define	BGE_DBG_NEMO		0x00200000	/* nemo interaction	*/
10532675Szh199473 #define	BGE_DBG_ADDR		0x00400000	/* address-setting code	*/
10542675Szh199473 #define	BGE_DBG_STATS		0x00800000	/* statistics		*/
10552675Szh199473 
10562675Szh199473 #define	BGE_DBG_IOCTL		0x01000000	/* ioctl handling	*/
10572675Szh199473 #define	BGE_DBG_LOOP		0x02000000	/* loopback ioctl code	*/
10582675Szh199473 #define	BGE_DBG_PPIO		0x04000000	/* Peek/poke ioctls	*/
10592675Szh199473 #define	BGE_DBG_BADIOC		0x08000000	/* unknown ioctls	*/
10602675Szh199473 
10612675Szh199473 #define	BGE_DBG_MCTL		0x10000000	/* mctl (csum) code	*/
10622675Szh199473 #define	BGE_DBG_NDD		0x20000000	/* NDD operations	*/
10632675Szh199473 
10642675Szh199473 /*
10652675Szh199473  * Debugging ...
10662675Szh199473  */
10672675Szh199473 #ifdef	DEBUG
10682675Szh199473 #define	BGE_DEBUGGING		1
10692675Szh199473 #else
10702675Szh199473 #define	BGE_DEBUGGING		0
10712675Szh199473 #endif	/* DEBUG */
10722675Szh199473 
10732675Szh199473 
10742675Szh199473 /*
10752675Szh199473  * 'Do-if-debugging' macro.  The parameter <command> should be one or more
10762675Szh199473  * C statements (but without the *final* semicolon), which will either be
10772675Szh199473  * compiled inline or completely ignored, depending on the BGE_DEBUGGING
10782675Szh199473  * compile-time flag.
10792675Szh199473  *
10802675Szh199473  * You should get a compile-time error (at least on a DEBUG build) if
10812675Szh199473  * your statement isn't actually a statement, rather than unexpected
10822675Szh199473  * run-time behaviour caused by unintended matching of if-then-elses etc.
10832675Szh199473  *
10842675Szh199473  * Note that the BGE_DDB() macro itself can only be used as a statement,
10852675Szh199473  * not an expression, and should always be followed by a semicolon.
10862675Szh199473  */
10872675Szh199473 #if	BGE_DEBUGGING
10882675Szh199473 #define	BGE_DDB(command)	do {					\
10892675Szh199473 					{ command; }			\
10902675Szh199473 					_NOTE(CONSTANTCONDITION)	\
10912675Szh199473 				} while (0)
10922675Szh199473 #else 	/* BGE_DEBUGGING */
10932675Szh199473 #define	BGE_DDB(command)	do {					\
10942675Szh199473 					{ _NOTE(EMPTY); }		\
10952675Szh199473 					_NOTE(CONSTANTCONDITION)	\
10962675Szh199473 				} while (0)
10972675Szh199473 #endif	/* BGE_DEBUGGING */
10982675Szh199473 
10992675Szh199473 /*
11002675Szh199473  * 'Internal' macros used to construct the TRACE/DEBUG macros below.
11012675Szh199473  * These provide the primitive conditional-call capability required.
11022675Szh199473  * Note: the parameter <args> is a parenthesised list of the actual
11032675Szh199473  * printf-style arguments to be passed to the debug function ...
11042675Szh199473  */
11052675Szh199473 #define	BGE_XDB(b, w, f, args)	BGE_DDB(if ((b) & (w)) f args)
11062675Szh199473 #define	BGE_GDB(b, args)	BGE_XDB(b, bge_debug, (*bge_gdb()), args)
11072675Szh199473 #define	BGE_LDB(b, args)	BGE_XDB(b, bgep->debug, (*bge_db(bgep)), args)
11082675Szh199473 #define	BGE_CDB(f, args)	BGE_XDB(BGE_DBG, bgep->debug, f, args)
11092675Szh199473 
11102675Szh199473 /*
11112675Szh199473  * Conditional-print macros.
11122675Szh199473  *
11132675Szh199473  * Define BGE_DBG to be the relevant member of the set of BGE_DBG_* values
11142675Szh199473  * above before using the BGE_GDEBUG() or BGE_DEBUG() macros.  The 'G'
11152675Szh199473  * versions look at the Global debug flag word (bge_debug); the non-G
11162675Szh199473  * versions look in the per-instance data (bgep->debug) and so require a
11172675Szh199473  * variable called 'bgep' to be in scope (and initialised!) before use.
11182675Szh199473  *
11192675Szh199473  * You could redefine BGE_TRC too if you really need two different
11202675Szh199473  * flavours of debugging output in the same area of code, but I don't
11212675Szh199473  * really recommend it.
11222675Szh199473  *
11232675Szh199473  * Note: the parameter <args> is a parenthesised list of the actual
11242675Szh199473  * arguments to be passed to the debug function, usually a printf-style
11252675Szh199473  * format string and corresponding values to be formatted.
11262675Szh199473  */
11272675Szh199473 
11282675Szh199473 #define	BGE_TRC			BGE_DBG_TRACE	/* default 'trace' bit	*/
11292675Szh199473 #define	BGE_GTRACE(args)	BGE_GDB(BGE_TRC, args)
11302675Szh199473 #define	BGE_GDEBUG(args)	BGE_GDB(BGE_DBG, args)
11312675Szh199473 #define	BGE_TRACE(args)		BGE_LDB(BGE_TRC, args)
11322675Szh199473 #define	BGE_DEBUG(args)		BGE_LDB(BGE_DBG, args)
11332675Szh199473 
11342675Szh199473 /*
11352675Szh199473  * Debug-only action macros
11362675Szh199473  */
11372675Szh199473 #define	BGE_BRKPT(bgep, s)	BGE_DDB(bge_dbg_enter(bgep, s))
11382675Szh199473 #define	BGE_MARK(bgep)		BGE_DDB(bge_led_mark(bgep))
11392675Szh199473 #define	BGE_PCICHK(bgep)	BGE_DDB(bge_pci_check(bgep))
11402675Szh199473 #define	BGE_PKTDUMP(args)	BGE_DDB(bge_pkt_dump args)
11412675Szh199473 #define	BGE_REPORT(args)	BGE_DDB(bge_log args)
11422675Szh199473 
11432675Szh199473 /*
11442675Szh199473  * Inter-source-file linkage ...
11452675Szh199473  */
11462675Szh199473 
11472675Szh199473 /* bge_chip.c */
11482675Szh199473 uint16_t bge_mii_get16(bge_t *bgep, bge_regno_t regno);
11492675Szh199473 void bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t value);
11502675Szh199473 uint32_t bge_reg_get32(bge_t *bgep, bge_regno_t regno);
11512675Szh199473 void bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t value);
11522675Szh199473 void bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits);
11532675Szh199473 void bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits);
11542675Szh199473 void bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t value);
11552675Szh199473 void bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma);
11562675Szh199473 int bge_chip_id_init(bge_t *bgep);
11579731SYong.Tan@Sun.COM void bge_chip_coalesce_update(bge_t *bgep);
11582675Szh199473 int bge_chip_start(bge_t *bgep, boolean_t reset_phy);
11592675Szh199473 void bge_chip_stop(bge_t *bgep, boolean_t fault);
11607656SSherry.Moore@Sun.COM #ifndef __sparc
11617656SSherry.Moore@Sun.COM void bge_chip_stop_nonblocking(bge_t *bgep);
11627656SSherry.Moore@Sun.COM #endif
11632675Szh199473 #ifdef BGE_IPMI_ASF
11642675Szh199473 void bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data);
11652675Szh199473 #pragma	inline(bge_nic_put32)
11662675Szh199473 uint32_t bge_nic_read32(bge_t *bgep, bge_regno_t addr);
11673918Sml149210 void bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val);
11683918Sml149210 #pragma inline(bge_ind_put32)
11693918Sml149210 uint32_t bge_ind_get32(bge_t *bgep, bge_regno_t regno);
11703918Sml149210 #pragma inline(bge_ind_get32)
11712675Szh199473 void bge_asf_update_status(bge_t *bgep);
11722675Szh199473 void bge_asf_heartbeat(void *bgep);
11732675Szh199473 void bge_asf_stop_timer(bge_t *bgep);
11742675Szh199473 void bge_asf_get_config(bge_t *bgep);
11752675Szh199473 void bge_asf_pre_reset_operations(bge_t *bgep, uint32_t mode);
11762675Szh199473 void bge_asf_post_reset_old_mode(bge_t *bgep, uint32_t mode);
11772675Szh199473 void bge_asf_post_reset_new_mode(bge_t *bgep, uint32_t mode);
11782675Szh199473 int bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode);
11792675Szh199473 int bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive);
11802675Szh199473 #else
11812675Szh199473 int bge_chip_reset(bge_t *bgep, boolean_t enable_dma);
11822675Szh199473 int bge_chip_sync(bge_t *bgep);
11832675Szh199473 #endif
11848275SEric Cheng void bge_chip_blank(void *arg, time_t ticks, uint_t count, int flag);
11858275SEric Cheng extern mblk_t *bge_poll_ring(void *, int);
11862675Szh199473 uint_t bge_chip_factotum(caddr_t arg);
11872675Szh199473 void bge_chip_cyclic(void *arg);
11882675Szh199473 enum ioc_reply bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp,
11892675Szh199473 	struct iocblk *iocp);
11902675Szh199473 uint_t bge_intr(caddr_t arg1, caddr_t arg2);
11915903Ssowmini void bge_sync_mac_modes(bge_t *);
11922675Szh199473 extern uint32_t bge_rx_ticks_norm;
11932675Szh199473 extern uint32_t bge_tx_ticks_norm;
11942675Szh199473 extern uint32_t bge_rx_count_norm;
11952675Szh199473 extern uint32_t bge_tx_count_norm;
11963907Szh199473 extern boolean_t bge_relaxed_ordering;
11973907Szh199473 
11982675Szh199473 void   bge_chip_msi_trig(bge_t *bgep);
11992675Szh199473 
12002675Szh199473 /* bge_kstats.c */
12012675Szh199473 void bge_init_kstats(bge_t *bgep, int instance);
12022675Szh199473 void bge_fini_kstats(bge_t *bgep);
12032675Szh199473 int bge_m_stat(void *arg, uint_t stat, uint64_t *val);
120411878SVenu.Iyer@Sun.COM int bge_rx_ring_stat(mac_ring_driver_t, uint_t, uint64_t *);
12052675Szh199473 
12062675Szh199473 /* bge_log.c */
12072675Szh199473 #if	BGE_DEBUGGING
12082675Szh199473 void (*bge_db(bge_t *bgep))(const char *fmt, ...);
12092675Szh199473 void (*bge_gdb(void))(const char *fmt, ...);
12102675Szh199473 void bge_pkt_dump(bge_t *bgep, bge_rbd_t *hbp, sw_rbd_t *sdp, const char *msg);
12112675Szh199473 void bge_dbg_enter(bge_t *bgep, const char *msg);
12122675Szh199473 #endif	/* BGE_DEBUGGING */
12132675Szh199473 void bge_problem(bge_t *bgep, const char *fmt, ...);
12142675Szh199473 void bge_log(bge_t *bgep, const char *fmt, ...);
12152675Szh199473 void bge_error(bge_t *bgep, const char *fmt, ...);
12162675Szh199473 void bge_fm_ereport(bge_t *bgep, char *detail);
12172675Szh199473 extern kmutex_t bge_log_mutex[1];
12182675Szh199473 extern uint32_t bge_debug;
12192675Szh199473 
12202675Szh199473 /* bge_main.c */
12212675Szh199473 int bge_restart(bge_t *bgep, boolean_t reset_phy);
12222675Szh199473 int bge_check_acc_handle(bge_t *bgep, ddi_acc_handle_t handle);
12232675Szh199473 int bge_check_dma_handle(bge_t *bgep, ddi_dma_handle_t handle);
12242675Szh199473 void bge_init_rings(bge_t *bgep);
12252675Szh199473 void bge_fini_rings(bge_t *bgep);
12263334Sgs150176 bge_queue_item_t *bge_alloc_txbuf_array(bge_t *bgep, send_ring_t *srp);
12273334Sgs150176 void bge_free_txbuf_arrays(send_ring_t *srp);
12282675Szh199473 int bge_alloc_bufs(bge_t *bgep);
12292675Szh199473 void bge_free_bufs(bge_t *bgep);
12302675Szh199473 void bge_intr_enable(bge_t *bgep);
12312675Szh199473 void bge_intr_disable(bge_t *bgep);
12325903Ssowmini int bge_reprogram(bge_t *);
12332675Szh199473 
12342675Szh199473 /* bge_phys.c */
12352675Szh199473 int bge_phys_init(bge_t *bgep);
12362675Szh199473 void bge_phys_reset(bge_t *bgep);
12372675Szh199473 int bge_phys_idle(bge_t *bgep);
12382675Szh199473 int bge_phys_update(bge_t *bgep);
12392675Szh199473 boolean_t bge_phys_check(bge_t *bgep);
12402675Szh199473 
12412675Szh199473 /* bge_ndd.c */
12422675Szh199473 int bge_nd_init(bge_t *bgep);
12432675Szh199473 
12442675Szh199473 /* bge_recv.c */
12452675Szh199473 void bge_receive(bge_t *bgep, bge_status_t *bsp);
12462675Szh199473 
12472675Szh199473 /* bge_send.c */
12482675Szh199473 mblk_t *bge_m_tx(void *arg, mblk_t *mp);
12498275SEric Cheng mblk_t *bge_ring_tx(void *arg, mblk_t *mp);
1250*12547SYong.Tan@Sun.COM boolean_t bge_recycle(bge_t *bgep, bge_status_t *bsp);
12513334Sgs150176 uint_t bge_send_drain(caddr_t arg);
12522675Szh199473 
12533334Sgs150176 /* bge_atomic.c */
12542675Szh199473 uint64_t bge_atomic_reserve(uint64_t *count_p, uint64_t n);
12552675Szh199473 void bge_atomic_renounce(uint64_t *count_p, uint64_t n);
12562675Szh199473 uint64_t bge_atomic_claim(uint64_t *count_p, uint64_t limit);
12573334Sgs150176 uint64_t bge_atomic_next(uint64_t *sp, uint64_t limit);
12583334Sgs150176 void bge_atomic_sub64(uint64_t *count_p, uint64_t n);
12592675Szh199473 uint64_t bge_atomic_clr64(uint64_t *sp, uint64_t bits);
12602675Szh199473 uint32_t bge_atomic_shl32(uint32_t *sp, uint_t count);
12612675Szh199473 
12627808SYong.Tan@Sun.COM /* bge_mii_5906.c */
12637808SYong.Tan@Sun.COM void bge_adj_volt_5906(bge_t *bgep);
12647808SYong.Tan@Sun.COM 
12652675Szh199473 /*
12662675Szh199473  * Reset type
12672675Szh199473  */
12682675Szh199473 #define	BGE_SHUTDOWN_RESET	0
12692675Szh199473 #define	BGE_INIT_RESET		1
12702675Szh199473 #define	BGE_SUSPEND_RESET	2
12712675Szh199473 
12722675Szh199473 /* For asf_status */
12732675Szh199473 #define	ASF_STAT_NONE		0
12742675Szh199473 #define	ASF_STAT_STOP		1
12752675Szh199473 #define	ASF_STAT_RUN		2
12762675Szh199473 #define	ASF_STAT_RUN_INIT	3	/* attached but don't plumb */
12772675Szh199473 
12782675Szh199473 /* ASF modes for bge_reset() and bge_chip_reset() */
12792675Szh199473 #define	ASF_MODE_NONE		0	/* don't launch asf	 */
12802675Szh199473 #define	ASF_MODE_SHUTDOWN	1	/* asf shutdown mode	 */
12812675Szh199473 #define	ASF_MODE_INIT		2	/* asf init mode	 */
12822675Szh199473 #define	ASF_MODE_POST_SHUTDOWN	3	/* only do post-shutdown */
12832675Szh199473 #define	ASF_MODE_POST_INIT	4	/* only do post-init	 */
12842675Szh199473 
12852675Szh199473 #define	BGE_ASF_HEARTBEAT_INTERVAL		1500000
12862675Szh199473 
12876546Sgh162552 #define	BGE_LINK_UPDATE_TIMEOUT	10	/* ~ 5 sec */
12886546Sgh162552 #define	BGE_LINK_UPDATE_DONE	(BGE_LINK_UPDATE_TIMEOUT+1)
12896546Sgh162552 
12902675Szh199473 #ifdef __cplusplus
12912675Szh199473 }
12922675Szh199473 #endif
12932675Szh199473 
12943334Sgs150176 #endif	/* _BGE_IMPL_H */
1295