1c869993eSxy /*
2c869993eSxy  * CDDL HEADER START
3c869993eSxy  *
480a11ad2Schenlu chen - Sun Microsystems - Beijing China  * Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
5c869993eSxy  * The contents of this file are subject to the terms of the
6c869993eSxy  * Common Development and Distribution License (the "License").
7c869993eSxy  * You may not use this file except in compliance with the License.
8c869993eSxy  *
980a11ad2Schenlu chen - Sun Microsystems - Beijing China  * You can obtain a copy of the license at:
1080a11ad2Schenlu chen - Sun Microsystems - Beijing China  *	http://www.opensolaris.org/os/licensing.
11c869993eSxy  * See the License for the specific language governing permissions
12c869993eSxy  * and limitations under the License.
13c869993eSxy  *
1480a11ad2Schenlu chen - Sun Microsystems - Beijing China  * When using or redistributing this file, you may do so under the
1580a11ad2Schenlu chen - Sun Microsystems - Beijing China  * License only. No other modification of this header is permitted.
1680a11ad2Schenlu chen - Sun Microsystems - Beijing China  *
17c869993eSxy  * If applicable, add the following below this CDDL HEADER, with the
18c869993eSxy  * fields enclosed by brackets "[]" replaced with your own identifying
19c869993eSxy  * information: Portions Copyright [yyyy] [name of copyright owner]
20c869993eSxy  *
21c869993eSxy  * CDDL HEADER END
22c869993eSxy  */
23c869993eSxy 
24da14cebeSEric Cheng /*
2580a11ad2Schenlu chen - Sun Microsystems - Beijing China  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2680a11ad2Schenlu chen - Sun Microsystems - Beijing China  * Use is subject to license terms of the CDDL.
27c869993eSxy  */
28c869993eSxy 
29c869993eSxy #ifndef	_IGB_OSDEP_H
30c869993eSxy #define	_IGB_OSDEP_H
31c869993eSxy 
32c869993eSxy #ifdef __cplusplus
33c869993eSxy extern "C" {
34c869993eSxy #endif
35c869993eSxy 
36c869993eSxy #include <sys/types.h>
37c869993eSxy #include <sys/conf.h>
38c869993eSxy #include <sys/debug.h>
39c869993eSxy #include <sys/stropts.h>
40c869993eSxy #include <sys/stream.h>
41c869993eSxy #include <sys/strlog.h>
42c869993eSxy #include <sys/kmem.h>
43c869993eSxy #include <sys/stat.h>
44c869993eSxy #include <sys/kstat.h>
45c869993eSxy #include <sys/modctl.h>
46c869993eSxy #include <sys/errno.h>
47c869993eSxy #include <sys/ddi.h>
48c869993eSxy #include <sys/dditypes.h>
49c869993eSxy #include <sys/sunddi.h>
50c869993eSxy #include <sys/pci.h>
517d46e7adSzhefeng xu - Sun Microsystems - Beijing China #include <sys/pci_cap.h>
52c869993eSxy #include <sys/atomic.h>
53c869993eSxy #include <sys/note.h>
54c869993eSxy #include "igb_debug.h"
55c869993eSxy 
56c869993eSxy #define	usec_delay(x)		drv_usecwait(x)
57*c124a83eSRobert Mustacchi #define	usec_delay_irq		usec_delay
58c869993eSxy #define	msec_delay(x)		drv_usecwait(x * 1000)
5980a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	msec_delay_irq		msec_delay
60c869993eSxy 
61c869993eSxy #ifdef IGB_DEBUG
62c869993eSxy #define	DEBUGOUT(S)		IGB_DEBUGLOG_0(NULL, S)
63c869993eSxy #define	DEBUGOUT1(S, A)		IGB_DEBUGLOG_1(NULL, S, A)
64c869993eSxy #define	DEBUGOUT2(S, A, B)	IGB_DEBUGLOG_2(NULL, S, A, B)
65c869993eSxy #define	DEBUGOUT3(S, A, B, C)	IGB_DEBUGLOG_3(NULL, S, A, B, C)
66c869993eSxy #else
67c869993eSxy #define	DEBUGOUT(S)
68c869993eSxy #define	DEBUGOUT1(S, A)
69c869993eSxy #define	DEBUGOUT2(S, A, B)
70c869993eSxy #define	DEBUGOUT3(S, A, B, C)
71c869993eSxy #endif
72c869993eSxy 
733f7e60a6Szhefeng xu - Sun Microsystems - Beijing China #define	DEBUGFUNC(f)
7480a11ad2Schenlu chen - Sun Microsystems - Beijing China 
75c869993eSxy #define	OS_DEP(hw)		((struct igb_osdep *)((hw)->back))
76c869993eSxy 
7780a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	false			B_FALSE
7880a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	true			B_TRUE
7975eba5b6SRobert Mustacchi #define	FALSE			false
8075eba5b6SRobert Mustacchi #define	TRUE			true
81c869993eSxy 
82c869993eSxy #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
83c869993eSxy #define	PCI_COMMAND_REGISTER	0x04
84c869993eSxy #define	PCI_EX_CONF_CAP		0xE0
85c869993eSxy 
86c869993eSxy 
87c869993eSxy /*
88c869993eSxy  * Constants used in setting flow control thresholds
89c869993eSxy  */
90c869993eSxy #define	E1000_PBA_MASK		0xffff
91c869993eSxy #define	E1000_PBA_SHIFT		10
92c869993eSxy #define	E1000_FC_HIGH_DIFF	0x1638 /* High: 5688 bytes below Rx FIFO size */
93c869993eSxy #define	E1000_FC_LOW_DIFF	0x1640 /* Low: 5696 bytes below Rx FIFO size */
94c869993eSxy #define	E1000_FC_PAUSE_TIME	0x0680 /* 858 usec */
95c869993eSxy 
96c869993eSxy /* PHY Extended Status Register */
97c869993eSxy #define	IEEE_ESR_1000T_HD_CAPS	0x1000	/* 1000T HD capable */
98c869993eSxy #define	IEEE_ESR_1000T_FD_CAPS	0x2000	/* 1000T FD capable */
99c869993eSxy #define	IEEE_ESR_1000X_HD_CAPS	0x4000	/* 1000X HD capable */
100c869993eSxy #define	IEEE_ESR_1000X_FD_CAPS	0x8000	/* 1000X FD capable */
101c869993eSxy 
102da14cebeSEric Cheng /* VMDq MODE supported by hardware */
103da14cebeSEric Cheng #define	E1000_VMDQ_OFF		0
104da14cebeSEric Cheng #define	E1000_VMDQ_MAC		1
105da14cebeSEric Cheng #define	E1000_VMDQ_MAC_RSS	2
106da14cebeSEric Cheng 
107da14cebeSEric Cheng /* VMDq based on packet destination MAC address */
108da14cebeSEric Cheng #define	E1000_MRQC_ENABLE_VMDQ_MAC_GROUP	0x00000003
109da14cebeSEric Cheng /* VMDq based on packet destination MAC address and RSS */
110da14cebeSEric Cheng #define	E1000_MRQC_ENABLE_VMDQ_MAC_RSS_GROUP	0x00000005
111da14cebeSEric Cheng /* The default queue in each VMDqs */
112da14cebeSEric Cheng #define	E1000_VMDQ_MAC_GROUP_DEFAULT_QUEUE	0x100
113da14cebeSEric Cheng 
114c869993eSxy #define	E1000_WRITE_FLUSH(a)	(void) E1000_READ_REG(a, E1000_STATUS)
115c869993eSxy 
116c869993eSxy #define	E1000_WRITE_REG(hw, reg, value)	\
117c869993eSxy 	ddi_put32((OS_DEP(hw))->reg_handle, \
118c869993eSxy 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg), (value))
119c869993eSxy 
120c869993eSxy #define	E1000_READ_REG(hw, reg)	\
121c869993eSxy 	ddi_get32((OS_DEP(hw))->reg_handle, \
122c869993eSxy 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg))
123c869993eSxy 
124c869993eSxy #define	E1000_WRITE_REG_ARRAY(hw, reg, offset, value)	\
125c869993eSxy 	ddi_put32((OS_DEP(hw))->reg_handle, \
126c869993eSxy 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg + ((offset) << 2)), \
127c869993eSxy 	    (value))
128c869993eSxy 
129c869993eSxy #define	E1000_READ_REG_ARRAY(hw, reg, offset)	\
130c869993eSxy 	ddi_get32((OS_DEP(hw))->reg_handle, \
131c869993eSxy 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg + ((offset) << 2)))
132c869993eSxy 
133c869993eSxy #define	E1000_WRITE_REG_ARRAY_DWORD(a, reg, offset, value)	\
134c869993eSxy 	E1000_WRITE_REG_ARRAY(a, reg, offset, value)
135c869993eSxy #define	E1000_READ_REG_ARRAY_DWORD(a, reg, offset)		\
136c869993eSxy 	E1000_READ_REG_ARRAY(a, reg, offset)
137c869993eSxy 
13875eba5b6SRobert Mustacchi 
13975eba5b6SRobert Mustacchi #define	E1000_READ_FLASH_REG(hw, reg)	\
14075eba5b6SRobert Mustacchi 	ddi_get32((OS_DEP(hw))->ich_flash_handle, \
14175eba5b6SRobert Mustacchi 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)))
14275eba5b6SRobert Mustacchi 
14375eba5b6SRobert Mustacchi #define	E1000_READ_FLASH_REG16(hw, reg)	\
14475eba5b6SRobert Mustacchi 	ddi_get16((OS_DEP(hw))->ich_flash_handle, \
14575eba5b6SRobert Mustacchi 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)))
14675eba5b6SRobert Mustacchi 
14775eba5b6SRobert Mustacchi #define	E1000_WRITE_FLASH_REG(hw, reg, value)	\
14875eba5b6SRobert Mustacchi 	ddi_put32((OS_DEP(hw))->ich_flash_handle, \
14975eba5b6SRobert Mustacchi 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
15075eba5b6SRobert Mustacchi 
15175eba5b6SRobert Mustacchi #define	E1000_WRITE_FLASH_REG16(hw, reg, value)	\
15275eba5b6SRobert Mustacchi 	ddi_put16((OS_DEP(hw))->ich_flash_handle, \
15375eba5b6SRobert Mustacchi 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
15475eba5b6SRobert Mustacchi 
15580a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_1PARAMETER(_p)		_NOTE(ARGUNUSED(_p))
15680a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_2PARAMETER(_p, _q)		_NOTE(ARGUNUSED(_p, _q))
15780a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_3PARAMETER(_p, _q, _r)	_NOTE(ARGUNUSED(_p, _q, _r))
15880a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_4PARAMETER(_p, _q, _r, _s)	_NOTE(ARGUNUSED(_p, _q, _r, _s))
15980a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_5PARAMETER(_p, _q, _r, _s, _t)	\
16080a11ad2Schenlu chen - Sun Microsystems - Beijing China 	_NOTE(ARGUNUSED(_p, _q, _r, _s, _t))
161c869993eSxy 
16280a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	__le16		u16
16380a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	__le32		u32
16480a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	__le64		u64
165c869993eSxy 
166c869993eSxy typedef	int8_t		s8;
167c869993eSxy typedef	int16_t		s16;
168c869993eSxy typedef	int32_t		s32;
169c869993eSxy typedef	int64_t		s64;
170c869993eSxy typedef uint8_t		u8;
171c869993eSxy typedef	uint16_t 	u16;
172c869993eSxy typedef	uint32_t	u32;
173c869993eSxy typedef	uint64_t	u64;
174fa25784cSxy typedef	boolean_t	bool;
175c869993eSxy 
17675eba5b6SRobert Mustacchi /*
17775eba5b6SRobert Mustacchi  * igb only uses the first two of the ddi_acc_handle_t, the latter end up coming
17875eba5b6SRobert Mustacchi  * from the common code for devices that igb doesn't support. For now, we end up
17975eba5b6SRobert Mustacchi  * bringing in those other two handles just for making life easier for sharin
18075eba5b6SRobert Mustacchi  * code.
18175eba5b6SRobert Mustacchi  */
182c869993eSxy struct igb_osdep {
183c869993eSxy 	ddi_acc_handle_t reg_handle;
184c869993eSxy 	ddi_acc_handle_t cfg_handle;
18575eba5b6SRobert Mustacchi 	ddi_acc_handle_t ich_flash_handle; /* UNUSED */
18675eba5b6SRobert Mustacchi 	ddi_acc_handle_t io_reg_handle; /* UNUSED */
187c869993eSxy 	struct igb *igb;
188c869993eSxy };
189c869993eSxy 
19075eba5b6SRobert Mustacchi /* Shared Code Mutex Defines */
19175eba5b6SRobert Mustacchi #define	E1000_MUTEX			kmutex_t
19275eba5b6SRobert Mustacchi #define	E1000_MUTEX_INIT(mutex)		mutex_init(mutex, NULL, \
19375eba5b6SRobert Mustacchi 	MUTEX_DRIVER, NULL)
19475eba5b6SRobert Mustacchi #define	E1000_MUTEX_DESTROY(mutex)	mutex_destroy(mutex)
19575eba5b6SRobert Mustacchi 
19675eba5b6SRobert Mustacchi #define	E1000_MUTEX_LOCK(mutex)		mutex_enter(mutex)
19775eba5b6SRobert Mustacchi #define	E1000_MUTEX_TRYLOCK(mutex)	mutex_tryenter(mutex)
19875eba5b6SRobert Mustacchi #define	E1000_MUTEX_UNLOCK(mutex)	mutex_exit(mutex)
19975eba5b6SRobert Mustacchi 
20075eba5b6SRobert Mustacchi #ifdef __sparc	/* on SPARC, use only memory-mapped routines */
20175eba5b6SRobert Mustacchi #define	E1000_WRITE_REG_IO	E1000_WRITE_REG
20275eba5b6SRobert Mustacchi #else	/* on x86, use port io routines */
20375eba5b6SRobert Mustacchi #define	E1000_WRITE_REG_IO(a, reg, val)	{ \
20475eba5b6SRobert Mustacchi 	ddi_put32((OS_DEP(a))->io_reg_handle, \
20575eba5b6SRobert Mustacchi 	    (uint32_t *)(a)->io_base, \
20675eba5b6SRobert Mustacchi 	    reg); \
20775eba5b6SRobert Mustacchi 	ddi_put32((OS_DEP(a))->io_reg_handle, \
20875eba5b6SRobert Mustacchi 	    (uint32_t *)((a)->io_base + 4), \
20975eba5b6SRobert Mustacchi 	    val); \
21075eba5b6SRobert Mustacchi }
21175eba5b6SRobert Mustacchi #endif	/* __sparc */
212c869993eSxy 
213c869993eSxy #ifdef __cplusplus
214c869993eSxy }
215c869993eSxy #endif
216c869993eSxy 
217c869993eSxy #endif	/* _IGB_OSDEP_H */
218