xref: /titanic_52/usr/src/uts/common/io/e1000g/e1000_osdep.h (revision 0a0e9771ca0211c15f3ac4466b661c145feeb9e4)
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 - 2009 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 2009 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 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/types.h>
34 #include <sys/conf.h>
35 #include <sys/debug.h>
36 #include <sys/stropts.h>
37 #include <sys/stream.h>
38 #include <sys/strlog.h>
39 #include <sys/kmem.h>
40 #include <sys/stat.h>
41 #include <sys/kstat.h>
42 #include <sys/modctl.h>
43 #include <sys/errno.h>
44 #include <sys/ddi.h>
45 #include <sys/sunddi.h>
46 #include <sys/pci.h>
47 #include <sys/atomic.h>
48 #include <sys/note.h>
49 #include "e1000g_debug.h"
50 
51 #define	usec_delay(x)		drv_usecwait(x)
52 #define	msec_delay(x)		drv_usecwait(x * 1000)
53 #define	msec_delay_irq		msec_delay
54 
55 #ifdef E1000G_DEBUG
56 #define	DEBUGOUT(S)		\
57 	E1000G_DEBUGLOG_0(NULL, E1000G_INFO_LEVEL, S)
58 #define	DEBUGOUT1(S, A)		\
59 	E1000G_DEBUGLOG_1(NULL, E1000G_INFO_LEVEL, S, A)
60 #define	DEBUGOUT2(S, A, B)	\
61 	E1000G_DEBUGLOG_2(NULL, E1000G_INFO_LEVEL, S, A, B)
62 #define	DEBUGOUT3(S, A, B, C)	\
63 	E1000G_DEBUGLOG_3(NULL, E1000G_INFO_LEVEL, S, A, B, C)
64 #define	DEBUGFUNC(F)		\
65 	E1000G_DEBUGLOG_0(NULL, E1000G_TRACE_LEVEL, F)
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 #define	DEBUGFUNC(F)
72 #endif
73 
74 #define	OS_DEP(hw)		((struct e1000g_osdep *)((hw)->back))
75 
76 #define	false		0
77 #define	true		1
78 #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
79 #define	PCI_COMMAND_REGISTER	0x04
80 #define	PCI_EX_CONF_CAP		0xE0
81 #define	ADAPTER_REG_SET		1 /* solaris mapping of adapter registers */
82 #define	ICH_FLASH_REG_SET	2	/* solaris mapping of flash memory */
83 
84 #define	RECEIVE_BUFFER_ALIGN_SIZE	256
85 #define	E1000_MDALIGN			4096
86 #define	E1000_MDALIGN_82546		65536
87 #define	E1000_ERT_2048			0x100
88 
89 /* PHY Extended Status Register */
90 #define	IEEE_ESR_1000T_HD_CAPS	0x1000	/* 1000T HD capable */
91 #define	IEEE_ESR_1000T_FD_CAPS	0x2000	/* 1000T FD capable */
92 #define	IEEE_ESR_1000X_HD_CAPS	0x4000	/* 1000X HD capable */
93 #define	IEEE_ESR_1000X_FD_CAPS	0x8000	/* 1000X FD capable */
94 
95 /*
96  * required by shared code
97  */
98 #define	E1000_WRITE_FLUSH(a)	(void)E1000_READ_REG(a, E1000_STATUS)
99 
100 #define	E1000_WRITE_REG(hw, reg, value)	\
101 {\
102 	if ((hw)->mac.type != e1000_82542) \
103 		ddi_put32((OS_DEP(hw))->reg_handle, \
104 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg), \
105 		    value); \
106 	else \
107 		ddi_put32((OS_DEP(hw))->reg_handle, \
108 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + \
109 		    e1000_translate_register_82542(reg)), \
110 		    value); \
111 }
112 
113 #define	E1000_READ_REG(hw, reg) (\
114 	((hw)->mac.type != e1000_82542) ? \
115 	    ddi_get32((OS_DEP(hw))->reg_handle, \
116 		(uint32_t *)((uintptr_t)(hw)->hw_addr + reg)) : \
117 	    ddi_get32((OS_DEP(hw))->reg_handle, \
118 		(uint32_t *)((uintptr_t)(hw)->hw_addr + \
119 		e1000_translate_register_82542(reg))))
120 
121 #define	E1000_WRITE_REG_ARRAY(hw, reg, offset, value) \
122 {\
123 	if ((hw)->mac.type != e1000_82542) \
124 		ddi_put32((OS_DEP(hw))->reg_handle, \
125 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + \
126 		    reg + ((offset) << 2)),\
127 		    value); \
128 	else \
129 		ddi_put32((OS_DEP(hw))->reg_handle, \
130 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + \
131 		    e1000_translate_register_82542(reg) + \
132 		    ((offset) << 2)), value); \
133 }
134 
135 #define	E1000_READ_REG_ARRAY(hw, reg, offset) (\
136 	((hw)->mac.type != e1000_82542) ? \
137 	    ddi_get32((OS_DEP(hw))->reg_handle, \
138 		(uint32_t *)((uintptr_t)(hw)->hw_addr + reg + \
139 		((offset) << 2))) : \
140 	    ddi_get32((OS_DEP(hw))->reg_handle, \
141 		(uint32_t *)((uintptr_t)(hw)->hw_addr + \
142 		e1000_translate_register_82542(reg) + \
143 		((offset) << 2))))
144 
145 
146 #define	E1000_WRITE_REG_ARRAY_DWORD(a, reg, offset, value)	\
147 	E1000_WRITE_REG_ARRAY(a, reg, offset, value)
148 #define	E1000_READ_REG_ARRAY_DWORD(a, reg, offset)		\
149 	E1000_READ_REG_ARRAY(a, reg, offset)
150 
151 
152 #define	E1000_READ_FLASH_REG(hw, reg)	\
153 	ddi_get32((OS_DEP(hw))->ich_flash_handle, \
154 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)))
155 
156 #define	E1000_READ_FLASH_REG16(hw, reg)	\
157 	ddi_get16((OS_DEP(hw))->ich_flash_handle, \
158 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)))
159 
160 #define	E1000_WRITE_FLASH_REG(hw, reg, value)	\
161 	ddi_put32((OS_DEP(hw))->ich_flash_handle, \
162 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
163 
164 #define	E1000_WRITE_FLASH_REG16(hw, reg, value)	\
165 	ddi_put16((OS_DEP(hw))->ich_flash_handle, \
166 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
167 
168 #define	UNREFERENCED_1PARAMETER(_p)		_NOTE(ARGUNUSED(_p))
169 #define	UNREFERENCED_2PARAMETER(_p, _q)		_NOTE(ARGUNUSED(_p, _q))
170 #define	UNREFERENCED_3PARAMETER(_p, _q, _r)	_NOTE(ARGUNUSED(_p, _q, _r))
171 #define	UNREFERENCED_4PARAMETER(_p, _q, _r, _s)	_NOTE(ARGUNUSED(_p, _q, _r, _s))
172 #define	UNREFERENCED_5PARAMETER(_p, _q, _r, _s, _t)	\
173 	_NOTE(ARGUNUSED(_p, _q, _r, _s, _t))
174 
175 typedef	int8_t		s8;
176 typedef	int16_t		s16;
177 typedef	int32_t		s32;
178 typedef	int64_t		s64;
179 typedef	uint8_t		u8;
180 typedef	uint16_t	u16;
181 typedef	uint32_t	u32;
182 typedef	uint64_t	u64;
183 typedef boolean_t	bool;
184 
185 #define	__le16 u16
186 #define	__le32 u32
187 #define	__le64 u64
188 
189 struct e1000g_osdep {
190 	ddi_acc_handle_t reg_handle;
191 	ddi_acc_handle_t cfg_handle;
192 	ddi_acc_handle_t ich_flash_handle;
193 	struct e1000g *adapter;
194 };
195 
196 #ifdef __sparc	/* on SPARC, use only memory-mapped routines */
197 #define	E1000_WRITE_REG_IO	E1000_WRITE_REG
198 #else	/* on x86, use port io routines */
199 #define	E1000_WRITE_REG_IO(a, reg, val)	{ \
200 	outl(((a)->io_base), reg); \
201 	outl(((a)->io_base + 4), val); }
202 #endif	/* __sparc */
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 #endif	/* _E1000_OSDEP_H */
209