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  */
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  */
29c869993eSxy #ifndef	_IGB_OSDEP_H
30c869993eSxy #define	_IGB_OSDEP_H
32c869993eSxy #ifdef __cplusplus
33c869993eSxy extern "C" {
34c869993eSxy #endif
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"
56c869993eSxy #define	usec_delay(x)		drv_usecwait(x)
57c124a83eSRobert 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
61c869993eSxy #define	DEBUGOUT(S)		IGB_DEBUGLOG_0(NULL, S)
62c869993eSxy #define	DEBUGOUT1(S, A)		IGB_DEBUGLOG_1(NULL, S, A)
63c869993eSxy #define	DEBUGOUT2(S, A, B)	IGB_DEBUGLOG_2(NULL, S, A, B)
64c869993eSxy #define	DEBUGOUT3(S, A, B, C)	IGB_DEBUGLOG_3(NULL, S, A, B, C)
65*fa4e188eSYuri Pankov 
66*fa4e188eSYuri Pankov #ifdef IGB_DEBUG
67*fa4e188eSYuri Pankov #define	DEBUGFUNC(F)		IGB_DEBUGFUNC(F)
68c869993eSxy #else
69*fa4e188eSYuri Pankov #define	DEBUGFUNC(F)
70c869993eSxy #endif
72c869993eSxy #define	OS_DEP(hw)		((struct igb_osdep *)((hw)->back))
7480a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	false			B_FALSE
7580a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	true			B_TRUE
7675eba5b6SRobert Mustacchi #define	FALSE			false
7775eba5b6SRobert Mustacchi #define	TRUE			true
79c869993eSxy #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
80c869993eSxy #define	PCI_COMMAND_REGISTER	0x04
81c869993eSxy #define	PCI_EX_CONF_CAP		0xE0
84c869993eSxy /*
85c869993eSxy  * Constants used in setting flow control thresholds
86c869993eSxy  */
87c869993eSxy #define	E1000_PBA_MASK		0xffff
88c869993eSxy #define	E1000_PBA_SHIFT		10
89c869993eSxy #define	E1000_FC_HIGH_DIFF	0x1638 /* High: 5688 bytes below Rx FIFO size */
90c869993eSxy #define	E1000_FC_LOW_DIFF	0x1640 /* Low: 5696 bytes below Rx FIFO size */
91c869993eSxy #define	E1000_FC_PAUSE_TIME	0x0680 /* 858 usec */
93c869993eSxy /* PHY Extended Status Register */
94c869993eSxy #define	IEEE_ESR_1000T_HD_CAPS	0x1000	/* 1000T HD capable */
95c869993eSxy #define	IEEE_ESR_1000T_FD_CAPS	0x2000	/* 1000T FD capable */
96c869993eSxy #define	IEEE_ESR_1000X_HD_CAPS	0x4000	/* 1000X HD capable */
97c869993eSxy #define	IEEE_ESR_1000X_FD_CAPS	0x8000	/* 1000X FD capable */
99da14cebeSEric Cheng /* VMDq MODE supported by hardware */
100da14cebeSEric Cheng #define	E1000_VMDQ_OFF		0
101da14cebeSEric Cheng #define	E1000_VMDQ_MAC		1
102da14cebeSEric Cheng #define	E1000_VMDQ_MAC_RSS	2
103da14cebeSEric Cheng 
104da14cebeSEric Cheng /* VMDq based on packet destination MAC address */
105da14cebeSEric Cheng #define	E1000_MRQC_ENABLE_VMDQ_MAC_GROUP	0x00000003
106da14cebeSEric Cheng /* VMDq based on packet destination MAC address and RSS */
107da14cebeSEric Cheng #define	E1000_MRQC_ENABLE_VMDQ_MAC_RSS_GROUP	0x00000005
108da14cebeSEric Cheng /* The default queue in each VMDqs */
109da14cebeSEric Cheng #define	E1000_VMDQ_MAC_GROUP_DEFAULT_QUEUE	0x100
110da14cebeSEric Cheng 
111c869993eSxy #define	E1000_WRITE_FLUSH(a)	(void) E1000_READ_REG(a, E1000_STATUS)
113c869993eSxy #define	E1000_WRITE_REG(hw, reg, value)	\
114c869993eSxy 	ddi_put32((OS_DEP(hw))->reg_handle, \
115c869993eSxy 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg), (value))
117c869993eSxy #define	E1000_READ_REG(hw, reg)	\
118c869993eSxy 	ddi_get32((OS_DEP(hw))->reg_handle, \
119c869993eSxy 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg))
121c869993eSxy #define	E1000_WRITE_REG_ARRAY(hw, reg, offset, value)	\
122c869993eSxy 	ddi_put32((OS_DEP(hw))->reg_handle, \
123c869993eSxy 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg + ((offset) << 2)), \
124c869993eSxy 	    (value))
126c869993eSxy #define	E1000_READ_REG_ARRAY(hw, reg, offset)	\
127c869993eSxy 	ddi_get32((OS_DEP(hw))->reg_handle, \
128c869993eSxy 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg + ((offset) << 2)))
130c869993eSxy #define	E1000_WRITE_REG_ARRAY_DWORD(a, reg, offset, value)	\
131c869993eSxy 	E1000_WRITE_REG_ARRAY(a, reg, offset, value)
132c869993eSxy #define	E1000_READ_REG_ARRAY_DWORD(a, reg, offset)		\
133c869993eSxy 	E1000_READ_REG_ARRAY(a, reg, offset)
13575eba5b6SRobert Mustacchi 
13675eba5b6SRobert Mustacchi #define	E1000_READ_FLASH_REG(hw, reg)	\
13775eba5b6SRobert Mustacchi 	ddi_get32((OS_DEP(hw))->ich_flash_handle, \
13875eba5b6SRobert Mustacchi 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)))
13975eba5b6SRobert Mustacchi 
14075eba5b6SRobert Mustacchi #define	E1000_READ_FLASH_REG16(hw, reg)	\
14175eba5b6SRobert Mustacchi 	ddi_get16((OS_DEP(hw))->ich_flash_handle, \
14275eba5b6SRobert Mustacchi 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)))
14375eba5b6SRobert Mustacchi 
14475eba5b6SRobert Mustacchi #define	E1000_WRITE_FLASH_REG(hw, reg, value)	\
14575eba5b6SRobert Mustacchi 	ddi_put32((OS_DEP(hw))->ich_flash_handle, \
14675eba5b6SRobert Mustacchi 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
14775eba5b6SRobert Mustacchi 
14875eba5b6SRobert Mustacchi #define	E1000_WRITE_FLASH_REG16(hw, reg, value)	\
14975eba5b6SRobert Mustacchi 	ddi_put16((OS_DEP(hw))->ich_flash_handle, \
15075eba5b6SRobert Mustacchi 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
15175eba5b6SRobert Mustacchi 
15280a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_1PARAMETER(_p)		_NOTE(ARGUNUSED(_p))
15380a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_2PARAMETER(_p, _q)		_NOTE(ARGUNUSED(_p, _q))
15480a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_3PARAMETER(_p, _q, _r)	_NOTE(ARGUNUSED(_p, _q, _r))
15580a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_4PARAMETER(_p, _q, _r, _s)	_NOTE(ARGUNUSED(_p, _q, _r, _s))
15680a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	UNREFERENCED_5PARAMETER(_p, _q, _r, _s, _t)	\
15780a11ad2Schenlu chen - Sun Microsystems - Beijing China 	_NOTE(ARGUNUSED(_p, _q, _r, _s, _t))
15980a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	__le16		u16
16080a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	__le32		u32
16180a11ad2Schenlu chen - Sun Microsystems - Beijing China #define	__le64		u64
163c869993eSxy typedef	int8_t		s8;
164c869993eSxy typedef	int16_t		s16;
165c869993eSxy typedef	int32_t		s32;
166c869993eSxy typedef	int64_t		s64;
167c869993eSxy typedef uint8_t		u8;
168c869993eSxy typedef	uint16_t 	u16;
169c869993eSxy typedef	uint32_t	u32;
170c869993eSxy typedef	uint64_t	u64;
171fa25784cSxy typedef	boolean_t	bool;
17375eba5b6SRobert Mustacchi /*
17475eba5b6SRobert Mustacchi  * igb only uses the first two of the ddi_acc_handle_t, the latter end up coming
17575eba5b6SRobert Mustacchi  * from the common code for devices that igb doesn't support. For now, we end up
17675eba5b6SRobert Mustacchi  * bringing in those other two handles just for making life easier for sharin
17775eba5b6SRobert Mustacchi  * code.
17875eba5b6SRobert Mustacchi  */
179c869993eSxy struct igb_osdep {
180c869993eSxy 	ddi_acc_handle_t reg_handle;
181c869993eSxy 	ddi_acc_handle_t cfg_handle;
18275eba5b6SRobert Mustacchi 	ddi_acc_handle_t ich_flash_handle; /* UNUSED */
18375eba5b6SRobert Mustacchi 	ddi_acc_handle_t io_reg_handle; /* UNUSED */
184c869993eSxy 	struct igb *igb;
185c869993eSxy };
18775eba5b6SRobert Mustacchi /* Shared Code Mutex Defines */
18875eba5b6SRobert Mustacchi #define	E1000_MUTEX			kmutex_t
18975eba5b6SRobert Mustacchi #define	E1000_MUTEX_INIT(mutex)		mutex_init(mutex, NULL, \
19075eba5b6SRobert Mustacchi 	MUTEX_DRIVER, NULL)
19175eba5b6SRobert Mustacchi #define	E1000_MUTEX_DESTROY(mutex)	mutex_destroy(mutex)
19275eba5b6SRobert Mustacchi 
19375eba5b6SRobert Mustacchi #define	E1000_MUTEX_LOCK(mutex)		mutex_enter(mutex)
19475eba5b6SRobert Mustacchi #define	E1000_MUTEX_TRYLOCK(mutex)	mutex_tryenter(mutex)
19575eba5b6SRobert Mustacchi #define	E1000_MUTEX_UNLOCK(mutex)	mutex_exit(mutex)
19675eba5b6SRobert Mustacchi 
19775eba5b6SRobert Mustacchi #ifdef __sparc	/* on SPARC, use only memory-mapped routines */
19875eba5b6SRobert Mustacchi #define	E1000_WRITE_REG_IO	E1000_WRITE_REG
19975eba5b6SRobert Mustacchi #else	/* on x86, use port io routines */
20075eba5b6SRobert Mustacchi #define	E1000_WRITE_REG_IO(a, reg, val)	{ \
20175eba5b6SRobert Mustacchi 	ddi_put32((OS_DEP(a))->io_reg_handle, \
20275eba5b6SRobert Mustacchi 	    (uint32_t *)(a)->io_base, \
20375eba5b6SRobert Mustacchi 	    reg); \
20475eba5b6SRobert Mustacchi 	ddi_put32((OS_DEP(a))->io_reg_handle, \
20575eba5b6SRobert Mustacchi 	    (uint32_t *)((a)->io_base + 4), \
20675eba5b6SRobert Mustacchi 	    val); \
20775eba5b6SRobert Mustacchi }
20875eba5b6SRobert Mustacchi #endif	/* __sparc */
210c869993eSxy #ifdef __cplusplus
211c869993eSxy }
212c869993eSxy #endif
214c869993eSxy #endif	/* _IGB_OSDEP_H */