xref: /titanic_50/usr/src/uts/common/io/igb/e1000_osdep.h (revision 10d63b7db37a83b39c7f511cf9426c9d03ea0760)
1 /*
2  * CDDL HEADER START
3  *
4  * Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at:
10  *	http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When using or redistributing this file, you may do so under the
15  * License only. No other modification of this header is permitted.
16  *
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  */
23 
24 /*
25  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms of the CDDL.
27  */
28 
29 #ifndef	_IGB_OSDEP_H
30 #define	_IGB_OSDEP_H
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/conf.h>
38 #include <sys/debug.h>
39 #include <sys/stropts.h>
40 #include <sys/stream.h>
41 #include <sys/strlog.h>
42 #include <sys/kmem.h>
43 #include <sys/stat.h>
44 #include <sys/kstat.h>
45 #include <sys/modctl.h>
46 #include <sys/errno.h>
47 #include <sys/ddi.h>
48 #include <sys/dditypes.h>
49 #include <sys/sunddi.h>
50 #include <sys/pci.h>
51 #include <sys/pci_cap.h>
52 #include <sys/atomic.h>
53 #include <sys/note.h>
54 #include "igb_debug.h"
55 
56 #define	usec_delay(x)		drv_usecwait(x)
57 #define	usec_delay_irq		usec_delay
58 #define	msec_delay(x)		drv_usecwait(x * 1000)
59 #define	msec_delay_irq		msec_delay
60 
61 #ifdef IGB_DEBUG
62 #define	DEBUGOUT(S)		IGB_DEBUGLOG_0(NULL, S)
63 #define	DEBUGOUT1(S, A)		IGB_DEBUGLOG_1(NULL, S, A)
64 #define	DEBUGOUT2(S, A, B)	IGB_DEBUGLOG_2(NULL, S, A, B)
65 #define	DEBUGOUT3(S, A, B, C)	IGB_DEBUGLOG_3(NULL, S, A, B, C)
66 #else
67 #define	DEBUGOUT(S)
68 #define	DEBUGOUT1(S, A)
69 #define	DEBUGOUT2(S, A, B)
70 #define	DEBUGOUT3(S, A, B, C)
71 #endif
72 
73 #define	DEBUGFUNC(f)
74 
75 #define	OS_DEP(hw)		((struct igb_osdep *)((hw)->back))
76 
77 #define	false			B_FALSE
78 #define	true			B_TRUE
79 #define	FALSE			false
80 #define	TRUE			true
81 
82 #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
83 #define	PCI_COMMAND_REGISTER	0x04
84 #define	PCI_EX_CONF_CAP		0xE0
85 
86 
87 /*
88  * Constants used in setting flow control thresholds
89  */
90 #define	E1000_PBA_MASK		0xffff
91 #define	E1000_PBA_SHIFT		10
92 #define	E1000_FC_HIGH_DIFF	0x1638 /* High: 5688 bytes below Rx FIFO size */
93 #define	E1000_FC_LOW_DIFF	0x1640 /* Low: 5696 bytes below Rx FIFO size */
94 #define	E1000_FC_PAUSE_TIME	0x0680 /* 858 usec */
95 
96 /* PHY Extended Status Register */
97 #define	IEEE_ESR_1000T_HD_CAPS	0x1000	/* 1000T HD capable */
98 #define	IEEE_ESR_1000T_FD_CAPS	0x2000	/* 1000T FD capable */
99 #define	IEEE_ESR_1000X_HD_CAPS	0x4000	/* 1000X HD capable */
100 #define	IEEE_ESR_1000X_FD_CAPS	0x8000	/* 1000X FD capable */
101 
102 /* VMDq MODE supported by hardware */
103 #define	E1000_VMDQ_OFF		0
104 #define	E1000_VMDQ_MAC		1
105 #define	E1000_VMDQ_MAC_RSS	2
106 
107 /* VMDq based on packet destination MAC address */
108 #define	E1000_MRQC_ENABLE_VMDQ_MAC_GROUP	0x00000003
109 /* VMDq based on packet destination MAC address and RSS */
110 #define	E1000_MRQC_ENABLE_VMDQ_MAC_RSS_GROUP	0x00000005
111 /* The default queue in each VMDqs */
112 #define	E1000_VMDQ_MAC_GROUP_DEFAULT_QUEUE	0x100
113 
114 #define	E1000_WRITE_FLUSH(a)	(void) E1000_READ_REG(a, E1000_STATUS)
115 
116 #define	E1000_WRITE_REG(hw, reg, value)	\
117 	ddi_put32((OS_DEP(hw))->reg_handle, \
118 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg), (value))
119 
120 #define	E1000_READ_REG(hw, reg)	\
121 	ddi_get32((OS_DEP(hw))->reg_handle, \
122 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg))
123 
124 #define	E1000_WRITE_REG_ARRAY(hw, reg, offset, value)	\
125 	ddi_put32((OS_DEP(hw))->reg_handle, \
126 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg + ((offset) << 2)), \
127 	    (value))
128 
129 #define	E1000_READ_REG_ARRAY(hw, reg, offset)	\
130 	ddi_get32((OS_DEP(hw))->reg_handle, \
131 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg + ((offset) << 2)))
132 
133 #define	E1000_WRITE_REG_ARRAY_DWORD(a, reg, offset, value)	\
134 	E1000_WRITE_REG_ARRAY(a, reg, offset, value)
135 #define	E1000_READ_REG_ARRAY_DWORD(a, reg, offset)		\
136 	E1000_READ_REG_ARRAY(a, reg, offset)
137 
138 
139 #define	E1000_READ_FLASH_REG(hw, reg)	\
140 	ddi_get32((OS_DEP(hw))->ich_flash_handle, \
141 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)))
142 
143 #define	E1000_READ_FLASH_REG16(hw, reg)	\
144 	ddi_get16((OS_DEP(hw))->ich_flash_handle, \
145 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)))
146 
147 #define	E1000_WRITE_FLASH_REG(hw, reg, value)	\
148 	ddi_put32((OS_DEP(hw))->ich_flash_handle, \
149 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
150 
151 #define	E1000_WRITE_FLASH_REG16(hw, reg, value)	\
152 	ddi_put16((OS_DEP(hw))->ich_flash_handle, \
153 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
154 
155 #define	UNREFERENCED_1PARAMETER(_p)		_NOTE(ARGUNUSED(_p))
156 #define	UNREFERENCED_2PARAMETER(_p, _q)		_NOTE(ARGUNUSED(_p, _q))
157 #define	UNREFERENCED_3PARAMETER(_p, _q, _r)	_NOTE(ARGUNUSED(_p, _q, _r))
158 #define	UNREFERENCED_4PARAMETER(_p, _q, _r, _s)	_NOTE(ARGUNUSED(_p, _q, _r, _s))
159 #define	UNREFERENCED_5PARAMETER(_p, _q, _r, _s, _t)	\
160 	_NOTE(ARGUNUSED(_p, _q, _r, _s, _t))
161 
162 #define	__le16		u16
163 #define	__le32		u32
164 #define	__le64		u64
165 
166 typedef	int8_t		s8;
167 typedef	int16_t		s16;
168 typedef	int32_t		s32;
169 typedef	int64_t		s64;
170 typedef uint8_t		u8;
171 typedef	uint16_t 	u16;
172 typedef	uint32_t	u32;
173 typedef	uint64_t	u64;
174 typedef	boolean_t	bool;
175 
176 /*
177  * igb only uses the first two of the ddi_acc_handle_t, the latter end up coming
178  * from the common code for devices that igb doesn't support. For now, we end up
179  * bringing in those other two handles just for making life easier for sharin
180  * code.
181  */
182 struct igb_osdep {
183 	ddi_acc_handle_t reg_handle;
184 	ddi_acc_handle_t cfg_handle;
185 	ddi_acc_handle_t ich_flash_handle; /* UNUSED */
186 	ddi_acc_handle_t io_reg_handle; /* UNUSED */
187 	struct igb *igb;
188 };
189 
190 /* Shared Code Mutex Defines */
191 #define	E1000_MUTEX			kmutex_t
192 #define	E1000_MUTEX_INIT(mutex)		mutex_init(mutex, NULL, \
193 	MUTEX_DRIVER, NULL)
194 #define	E1000_MUTEX_DESTROY(mutex)	mutex_destroy(mutex)
195 
196 #define	E1000_MUTEX_LOCK(mutex)		mutex_enter(mutex)
197 #define	E1000_MUTEX_TRYLOCK(mutex)	mutex_tryenter(mutex)
198 #define	E1000_MUTEX_UNLOCK(mutex)	mutex_exit(mutex)
199 
200 #ifdef __sparc	/* on SPARC, use only memory-mapped routines */
201 #define	E1000_WRITE_REG_IO	E1000_WRITE_REG
202 #else	/* on x86, use port io routines */
203 #define	E1000_WRITE_REG_IO(a, reg, val)	{ \
204 	ddi_put32((OS_DEP(a))->io_reg_handle, \
205 	    (uint32_t *)(a)->io_base, \
206 	    reg); \
207 	ddi_put32((OS_DEP(a))->io_reg_handle, \
208 	    (uint32_t *)((a)->io_base + 4), \
209 	    val); \
210 }
211 #endif	/* __sparc */
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 
217 #endif	/* _IGB_OSDEP_H */
218