xref: /titanic_51/usr/src/uts/common/io/e1000g/e1000_osdep.h (revision 0cd13cbfb4270b840b4bd22ec5f673b2b6a2c02b)
1 /*
2  * This file is provided under a CDDLv1 license.  When using or
3  * redistributing this file, you may do so under this license.
4  * In redistributing this file this license must be included
5  * and no other modification of this header file is permitted.
6  *
7  * CDDL LICENSE SUMMARY
8  *
9  * Copyright(c) 1999 - 2007 Intel Corporation. All rights reserved.
10  *
11  * The contents of this file are subject to the terms of Version
12  * 1.0 of the Common Development and Distribution License (the "License").
13  *
14  * You should have received a copy of the License with this software.
15  * You can obtain a copy of the License at
16  *	http://www.opensolaris.org/os/licensing.
17  * See the License for the specific language governing permissions
18  * and limitations under the License.
19  */
20 
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms of the CDDLv1.
24  */
25 
26 #ifndef _E1000_OSDEP_H
27 #define	_E1000_OSDEP_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/types.h>
36 #include <sys/conf.h>
37 #include <sys/debug.h>
38 #include <sys/stropts.h>
39 #include <sys/stream.h>
40 #include <sys/strlog.h>
41 #include <sys/kmem.h>
42 #include <sys/stat.h>
43 #include <sys/kstat.h>
44 #include <sys/modctl.h>
45 #include <sys/errno.h>
46 #include <sys/ddi.h>
47 #include <sys/sunddi.h>
48 #include <sys/pci.h>
49 #include <sys/atomic.h>
50 #include "e1000g_debug.h"
51 
52 /*
53  * === BEGIN CONTENT FORMERLY IN FXHW.H ===
54  */
55 #define	usec_delay(x)		drv_usecwait(x)
56 #define	msec_delay(x)		drv_usecwait(x * 1000)
57 
58 #ifdef E1000G_DEBUG
59 #define	DEBUGOUT(S)		\
60 	E1000G_DEBUGLOG_0(NULL, E1000G_INFO_LEVEL, S)
61 #define	DEBUGOUT1(S, A)		\
62 	E1000G_DEBUGLOG_1(NULL, E1000G_INFO_LEVEL, S, A)
63 #define	DEBUGOUT2(S, A, B)	\
64 	E1000G_DEBUGLOG_2(NULL, E1000G_INFO_LEVEL, S, A, B)
65 #define	DEBUGOUT3(S, A, B, C)	\
66 	E1000G_DEBUGLOG_3(NULL, E1000G_INFO_LEVEL, S, A, B, C)
67 #define	DEBUGFUNC(F)		\
68 	E1000G_DEBUGLOG_0(NULL, E1000G_TRACE_LEVEL, F)
69 #else
70 #define	DEBUGOUT(S)
71 #define	DEBUGOUT1(S, A)
72 #define	DEBUGOUT2(S, A, B)
73 #define	DEBUGOUT3(S, A, B, C)
74 #define	DEBUGFUNC(F)
75 #endif
76 
77 #define	OS_DEP(hw)		((struct e1000g_osdep *)((hw)->back))
78 
79 #define	FALSE		0
80 #define	TRUE		1
81 #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
82 #define	PCI_COMMAND_REGISTER	0x04
83 #define	PCI_EX_CONF_CAP		0xE0
84 #define	ICH_FLASH_REG_SET	2	/* solaris mapping of flash memory */
85 
86 #define	RECEIVE_BUFFER_ALIGN_SIZE	256
87 #define	E1000_MDALIGN			4096
88 #define	E1000_ERT_2048			0x100
89 
90 /* PHY Extended Status Register */
91 #define	IEEE_ESR_1000T_HD_CAPS	0x1000	/* 1000T HD capable */
92 #define	IEEE_ESR_1000T_FD_CAPS	0x2000	/* 1000T FD capable */
93 #define	IEEE_ESR_1000X_HD_CAPS	0x4000	/* 1000X HD capable */
94 #define	IEEE_ESR_1000X_FD_CAPS	0x8000	/* 1000X FD capable */
95 
96 #define	E1000_WRITE_FLUSH(a)	E1000_READ_REG(a, E1000_STATUS)
97 
98 #ifdef NO_82542_SUPPORT
99 #define	E1000_WRITE_REG(hw, reg, value)	\
100 	ddi_put32((OS_DEP(hw))->reg_handle, \
101 	    (uint32_t *)((hw)->hw_addr + reg), (value))
102 
103 #define	E1000_READ_REG(hw, reg)	\
104 	ddi_get32((OS_DEP(hw))->reg_handle, \
105 	    (uint32_t *)((hw)->hw_addr + reg))
106 
107 #define	E1000_WRITE_REG_ARRAY(hw, reg, offset, value)	\
108 	ddi_put32((OS_DEP(hw))->reg_handle, \
109 	    (uint32_t *)((hw)->hw_addr + reg + ((offset) << 2)), \
110 	    (value))
111 
112 #define	E1000_READ_REG_ARRAY(hw, reg, offset)	\
113 	ddi_get32((OS_DEP(hw))->reg_handle, \
114 	    (uint32_t *)((hw)->hw_addr + reg + ((offset) << 2)))
115 
116 #else	/* NO_82542_SUPPORT */
117 
118 #define	E1000_WRITE_REG(hw, reg, value)	\
119 {\
120 	if ((hw)->mac.type != e1000_82542) \
121 		ddi_put32((OS_DEP(hw))->reg_handle, \
122 		    (uint32_t *)((hw)->hw_addr + reg), \
123 		    value); \
124 	else \
125 		ddi_put32((OS_DEP(hw))->reg_handle, \
126 		    (uint32_t *)((hw)->hw_addr + \
127 		    e1000_translate_register_82542(reg)), \
128 		    value); \
129 }
130 
131 #define	E1000_READ_REG(hw, reg) (\
132 	((hw)->mac.type != e1000_82542) ? \
133 	    ddi_get32((OS_DEP(hw))->reg_handle, \
134 		(uint32_t *)((hw)->hw_addr + reg)) : \
135 	    ddi_get32((OS_DEP(hw))->reg_handle, \
136 		(uint32_t *)((hw)->hw_addr + \
137 		e1000_translate_register_82542(reg))))
138 
139 #define	E1000_WRITE_REG_ARRAY(hw, reg, offset, value) \
140 {\
141 	if ((hw)->mac.type != e1000_82542) \
142 		ddi_put32((OS_DEP(hw))->reg_handle, \
143 		    (uint32_t *)((hw)->hw_addr + reg + ((offset) << 2)),\
144 		    value); \
145 	else \
146 		ddi_put32((OS_DEP(hw))->reg_handle, \
147 		    (uint32_t *)((hw)->hw_addr + \
148 		    e1000_translate_register_82542(reg) + \
149 		    ((offset) << 2)), value); \
150 }
151 
152 #define	E1000_READ_REG_ARRAY(hw, reg, offset) (\
153 	((hw)->mac.type != e1000_82542) ? \
154 	    ddi_get32((OS_DEP(hw))->reg_handle, \
155 		(uint32_t *)((hw)->hw_addr + reg + ((offset) << 2))) : \
156 	    ddi_get32((OS_DEP(hw))->reg_handle, \
157 		(uint32_t *)((hw)->hw_addr + \
158 		e1000_translate_register_82542(reg) + \
159 		((offset) << 2))))
160 #endif	/* NO_82542_SUPPORT */
161 
162 
163 #define	E1000_WRITE_REG_ARRAY_BYTE(a, reg, offset, value)	NULL
164 #define	E1000_WRITE_REG_ARRAY_WORD(a, reg, offset, value)	NULL
165 #define	E1000_WRITE_REG_ARRAY_DWORD(a, reg, offset, value)	NULL
166 #define	E1000_READ_REG_ARRAY_BYTE(a, reg, offset)		NULL
167 #define	E1000_READ_REG_ARRAY_WORD(a, reg, offset)		NULL
168 #define	E1000_READ_REG_ARRAY_DWORD(a, reg, offset)		NULL
169 
170 
171 #define	E1000_READ_FLASH_REG(hw, reg)	\
172 	ddi_get32((OS_DEP(hw))->ich_flash_handle, \
173 		(uint32_t *)((hw)->flash_address + (reg)))
174 
175 #define	E1000_READ_FLASH_REG16(hw, reg)	\
176 	ddi_get16((OS_DEP(hw))->ich_flash_handle, \
177 		(uint16_t *)((hw)->flash_address + (reg)))
178 
179 #define	E1000_WRITE_FLASH_REG(hw, reg, value)	\
180 	ddi_put32((OS_DEP(hw))->ich_flash_handle, \
181 		(uint32_t *)((hw)->flash_address + (reg)), (value))
182 
183 #define	E1000_WRITE_FLASH_REG16(hw, reg, value)	\
184 	ddi_put16((OS_DEP(hw))->ich_flash_handle, \
185 		(uint16_t *)((hw)->flash_address + (reg)), (value))
186 
187 /*
188  * === END CONTENT FORMERLY IN FXHW.H ===
189  */
190 
191 #define	msec_delay_irq	msec_delay
192 
193 typedef	int8_t		s8;
194 typedef	int16_t		s16;
195 typedef	int32_t		s32;
196 typedef	int64_t		s64;
197 typedef	uint8_t		u8;
198 typedef	uint16_t	u16;
199 typedef	uint32_t	u32;
200 typedef	uint64_t	u64;
201 
202 typedef uint8_t		UCHAR;	/* 8-bit unsigned */
203 typedef UCHAR		UINT8;	/* 8-bit unsigned */
204 typedef uint16_t	USHORT;	/* 16-bit unsigned */
205 typedef uint16_t	UINT16;	/* 16-bit unsigned */
206 typedef uint32_t	ULONG;	/* 32-bit unsigned */
207 typedef uint32_t	UINT32;
208 typedef uint32_t	UINT;	/* 32-bit unsigned */
209 typedef UCHAR		BOOLEAN;
210 typedef UCHAR		*PUCHAR;
211 typedef UINT		*PUINT;
212 typedef ULONG		*PLONG;
213 typedef ULONG		NDIS_STATUS;
214 typedef USHORT		*PUSHORT;
215 typedef PUSHORT		PUINT16; /* 16-bit unsigned pointer */
216 typedef ULONG		E1000_32_BIT_PHYSICAL_ADDRESS,
217 	*PFX_32_BIT_PHYSICAL_ADDRESS;
218 typedef uint64_t	E1000_64_BIT_PHYSICAL_ADDRESS,
219 	*PFX_64_BIT_PHYSICAL_ADDRESS;
220 
221 struct e1000g_osdep {
222 	ddi_acc_handle_t reg_handle;
223 	ddi_acc_handle_t cfg_handle;
224 	ddi_acc_handle_t ich_flash_handle;
225 	struct e1000g *adapter;
226 };
227 
228 #ifdef __sparc	/* on SPARC, use only memory-mapped routines */
229 #define	E1000_WRITE_REG_IO	E1000_WRITE_REG
230 #else	/* on x86, use port io routines */
231 #define	E1000_WRITE_REG_IO(a, reg, val)	{ \
232 	outl(((a)->io_base), reg); \
233 	outl(((a)->io_base + 4), val); }
234 #endif	/* __sparc */
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif	/* _E1000_OSDEP_H */
241