xref: /titanic_41/usr/src/uts/common/io/e1000g/e1000_osdep.h (revision c6a664189ff58eecb65704097a089f0bb4d35523)
108057504Sxy150489 /*
208057504Sxy150489  * This file is provided under a CDDLv1 license.  When using or
308057504Sxy150489  * redistributing this file, you may do so under this license.
408057504Sxy150489  * In redistributing this file this license must be included
508057504Sxy150489  * and no other modification of this header file is permitted.
608057504Sxy150489  *
708057504Sxy150489  * CDDL LICENSE SUMMARY
808057504Sxy150489  *
9d5c3073dSchenlu chen - Sun Microsystems - Beijing China  * Copyright(c) 1999 - 2009 Intel Corporation. All rights reserved.
1008057504Sxy150489  *
1108057504Sxy150489  * The contents of this file are subject to the terms of Version
1208057504Sxy150489  * 1.0 of the Common Development and Distribution License (the "License").
1308057504Sxy150489  *
1408057504Sxy150489  * You should have received a copy of the License with this software.
1508057504Sxy150489  * You can obtain a copy of the License at
1608057504Sxy150489  *	http://www.opensolaris.org/os/licensing.
1708057504Sxy150489  * See the License for the specific language governing permissions
1808057504Sxy150489  * and limitations under the License.
1908057504Sxy150489  */
2008057504Sxy150489 
2108057504Sxy150489 /*
223f64cd55Sguoqing zhu - Sun Microsystems - Beijing China  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
2308057504Sxy150489  * Use is subject to license terms of the CDDLv1.
2408057504Sxy150489  */
2508057504Sxy150489 
2608057504Sxy150489 #ifndef _E1000_OSDEP_H
2708057504Sxy150489 #define	_E1000_OSDEP_H
2808057504Sxy150489 
2908057504Sxy150489 #ifdef __cplusplus
3008057504Sxy150489 extern "C" {
3108057504Sxy150489 #endif
3208057504Sxy150489 
3308057504Sxy150489 #include <sys/types.h>
3408057504Sxy150489 #include <sys/conf.h>
3508057504Sxy150489 #include <sys/debug.h>
3608057504Sxy150489 #include <sys/stropts.h>
3708057504Sxy150489 #include <sys/stream.h>
3808057504Sxy150489 #include <sys/strlog.h>
3908057504Sxy150489 #include <sys/kmem.h>
4008057504Sxy150489 #include <sys/stat.h>
4108057504Sxy150489 #include <sys/kstat.h>
4208057504Sxy150489 #include <sys/modctl.h>
4308057504Sxy150489 #include <sys/errno.h>
4408057504Sxy150489 #include <sys/ddi.h>
4508057504Sxy150489 #include <sys/sunddi.h>
4608057504Sxy150489 #include <sys/pci.h>
4725f2d433Sxy150489 #include <sys/atomic.h>
48fe62dec3SChen-Liang Xu #include <sys/note.h>
49caf05df5SMiles Xu, Sun Microsystems #include <sys/mutex.h>
5075eba5b6SRobert Mustacchi #include <sys/pci_cap.h>
5125f2d433Sxy150489 #include "e1000g_debug.h"
5208057504Sxy150489 
5308057504Sxy150489 #define	usec_delay(x)		drv_usecwait(x)
54*c6a66418SRobert Mustacchi #define	usec_delay_irq		usec_delay
5508057504Sxy150489 #define	msec_delay(x)		drv_usecwait(x * 1000)
564d737963Sxiangtao you - Sun Microsystems - Beijing China #define	msec_delay_irq		msec_delay
5708057504Sxy150489 
5825f2d433Sxy150489 #ifdef E1000G_DEBUG
5925f2d433Sxy150489 #define	DEBUGOUT(S)		\
6025f2d433Sxy150489 	E1000G_DEBUGLOG_0(NULL, E1000G_INFO_LEVEL, S)
6125f2d433Sxy150489 #define	DEBUGOUT1(S, A)		\
6225f2d433Sxy150489 	E1000G_DEBUGLOG_1(NULL, E1000G_INFO_LEVEL, S, A)
6325f2d433Sxy150489 #define	DEBUGOUT2(S, A, B)	\
6425f2d433Sxy150489 	E1000G_DEBUGLOG_2(NULL, E1000G_INFO_LEVEL, S, A, B)
6525f2d433Sxy150489 #define	DEBUGOUT3(S, A, B, C)	\
6625f2d433Sxy150489 	E1000G_DEBUGLOG_3(NULL, E1000G_INFO_LEVEL, S, A, B, C)
6725f2d433Sxy150489 #define	DEBUGFUNC(F)		\
6825f2d433Sxy150489 	E1000G_DEBUGLOG_0(NULL, E1000G_TRACE_LEVEL, F)
6908057504Sxy150489 #else
7008057504Sxy150489 #define	DEBUGOUT(S)
7108057504Sxy150489 #define	DEBUGOUT1(S, A)
7208057504Sxy150489 #define	DEBUGOUT2(S, A, B)
7308057504Sxy150489 #define	DEBUGOUT3(S, A, B, C)
7425f2d433Sxy150489 #define	DEBUGFUNC(F)
7508057504Sxy150489 #endif
7608057504Sxy150489 
7725f2d433Sxy150489 #define	OS_DEP(hw)		((struct e1000g_osdep *)((hw)->back))
7808057504Sxy150489 
794d737963Sxiangtao you - Sun Microsystems - Beijing China #define	false		0
804d737963Sxiangtao you - Sun Microsystems - Beijing China #define	true		1
8175eba5b6SRobert Mustacchi #define	FALSE		false
8275eba5b6SRobert Mustacchi #define	TRUE		true
83caf05df5SMiles Xu, Sun Microsystems 
8408057504Sxy150489 #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
8508057504Sxy150489 #define	PCI_COMMAND_REGISTER	0x04
8625f2d433Sxy150489 #define	PCI_EX_CONF_CAP		0xE0
874d737963Sxiangtao you - Sun Microsystems - Beijing China #define	ADAPTER_REG_SET		1 /* solaris mapping of adapter registers */
8825f2d433Sxy150489 #define	ICH_FLASH_REG_SET	2	/* solaris mapping of flash memory */
8908057504Sxy150489 
9025f2d433Sxy150489 #define	RECEIVE_BUFFER_ALIGN_SIZE	256
9125f2d433Sxy150489 #define	E1000_MDALIGN			4096
92ede5269eSchenlu chen - Sun Microsystems - Beijing China #define	E1000_MDALIGN_82546		65536
9325f2d433Sxy150489 #define	E1000_ERT_2048			0x100
9408057504Sxy150489 
9525f2d433Sxy150489 /* PHY Extended Status Register */
9625f2d433Sxy150489 #define	IEEE_ESR_1000T_HD_CAPS	0x1000	/* 1000T HD capable */
9725f2d433Sxy150489 #define	IEEE_ESR_1000T_FD_CAPS	0x2000	/* 1000T FD capable */
9825f2d433Sxy150489 #define	IEEE_ESR_1000X_HD_CAPS	0x4000	/* 1000X HD capable */
9925f2d433Sxy150489 #define	IEEE_ESR_1000X_FD_CAPS	0x8000	/* 1000X FD capable */
10025f2d433Sxy150489 
101592a4d85Scc210113 /*
102592a4d85Scc210113  * required by shared code
103592a4d85Scc210113  */
104fe62dec3SChen-Liang Xu #define	E1000_WRITE_FLUSH(a)	(void)E1000_READ_REG(a, E1000_STATUS)
10525f2d433Sxy150489 
10625f2d433Sxy150489 #define	E1000_WRITE_REG(hw, reg, value)	\
10708057504Sxy150489 {\
10825f2d433Sxy150489 	if ((hw)->mac.type != e1000_82542) \
10925f2d433Sxy150489 		ddi_put32((OS_DEP(hw))->reg_handle, \
110fe62dec3SChen-Liang Xu 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg), \
11108057504Sxy150489 		    value); \
11208057504Sxy150489 	else \
11325f2d433Sxy150489 		ddi_put32((OS_DEP(hw))->reg_handle, \
114fe62dec3SChen-Liang Xu 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + \
11525f2d433Sxy150489 		    e1000_translate_register_82542(reg)), \
11608057504Sxy150489 		    value); \
11708057504Sxy150489 }
11808057504Sxy150489 
11925f2d433Sxy150489 #define	E1000_READ_REG(hw, reg) (\
12025f2d433Sxy150489 	((hw)->mac.type != e1000_82542) ? \
12125f2d433Sxy150489 	    ddi_get32((OS_DEP(hw))->reg_handle, \
122fe62dec3SChen-Liang Xu 		(uint32_t *)((uintptr_t)(hw)->hw_addr + reg)) : \
12325f2d433Sxy150489 	    ddi_get32((OS_DEP(hw))->reg_handle, \
124fe62dec3SChen-Liang Xu 		(uint32_t *)((uintptr_t)(hw)->hw_addr + \
12525f2d433Sxy150489 		e1000_translate_register_82542(reg))))
12608057504Sxy150489 
12725f2d433Sxy150489 #define	E1000_WRITE_REG_ARRAY(hw, reg, offset, value) \
12808057504Sxy150489 {\
12925f2d433Sxy150489 	if ((hw)->mac.type != e1000_82542) \
13025f2d433Sxy150489 		ddi_put32((OS_DEP(hw))->reg_handle, \
131fe62dec3SChen-Liang Xu 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + \
132fe62dec3SChen-Liang Xu 		    reg + ((offset) << 2)),\
13308057504Sxy150489 		    value); \
13408057504Sxy150489 	else \
13525f2d433Sxy150489 		ddi_put32((OS_DEP(hw))->reg_handle, \
136fe62dec3SChen-Liang Xu 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + \
13725f2d433Sxy150489 		    e1000_translate_register_82542(reg) + \
13808057504Sxy150489 		    ((offset) << 2)), value); \
13908057504Sxy150489 }
14008057504Sxy150489 
14125f2d433Sxy150489 #define	E1000_READ_REG_ARRAY(hw, reg, offset) (\
14225f2d433Sxy150489 	((hw)->mac.type != e1000_82542) ? \
14325f2d433Sxy150489 	    ddi_get32((OS_DEP(hw))->reg_handle, \
144fe62dec3SChen-Liang Xu 		(uint32_t *)((uintptr_t)(hw)->hw_addr + reg + \
145fe62dec3SChen-Liang Xu 		((offset) << 2))) : \
14625f2d433Sxy150489 	    ddi_get32((OS_DEP(hw))->reg_handle, \
147fe62dec3SChen-Liang Xu 		(uint32_t *)((uintptr_t)(hw)->hw_addr + \
14825f2d433Sxy150489 		e1000_translate_register_82542(reg) + \
14908057504Sxy150489 		((offset) << 2))))
15008057504Sxy150489 
15108057504Sxy150489 
152fe62dec3SChen-Liang Xu #define	E1000_WRITE_REG_ARRAY_DWORD(a, reg, offset, value)	\
153fe62dec3SChen-Liang Xu 	E1000_WRITE_REG_ARRAY(a, reg, offset, value)
154fe62dec3SChen-Liang Xu #define	E1000_READ_REG_ARRAY_DWORD(a, reg, offset)		\
155fe62dec3SChen-Liang Xu 	E1000_READ_REG_ARRAY(a, reg, offset)
15608057504Sxy150489 
15708057504Sxy150489 
15825f2d433Sxy150489 #define	E1000_READ_FLASH_REG(hw, reg)	\
15908057504Sxy150489 	ddi_get32((OS_DEP(hw))->ich_flash_handle, \
160fe62dec3SChen-Liang Xu 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)))
16108057504Sxy150489 
16225f2d433Sxy150489 #define	E1000_READ_FLASH_REG16(hw, reg)	\
16308057504Sxy150489 	ddi_get16((OS_DEP(hw))->ich_flash_handle, \
164fe62dec3SChen-Liang Xu 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)))
16508057504Sxy150489 
16625f2d433Sxy150489 #define	E1000_WRITE_FLASH_REG(hw, reg, value)	\
16708057504Sxy150489 	ddi_put32((OS_DEP(hw))->ich_flash_handle, \
168fe62dec3SChen-Liang Xu 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
16908057504Sxy150489 
17025f2d433Sxy150489 #define	E1000_WRITE_FLASH_REG16(hw, reg, value)	\
17108057504Sxy150489 	ddi_put16((OS_DEP(hw))->ich_flash_handle, \
172fe62dec3SChen-Liang Xu 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
17308057504Sxy150489 
174fe62dec3SChen-Liang Xu #define	UNREFERENCED_1PARAMETER(_p)		_NOTE(ARGUNUSED(_p))
175fe62dec3SChen-Liang Xu #define	UNREFERENCED_2PARAMETER(_p, _q)		_NOTE(ARGUNUSED(_p, _q))
176fe62dec3SChen-Liang Xu #define	UNREFERENCED_3PARAMETER(_p, _q, _r)	_NOTE(ARGUNUSED(_p, _q, _r))
177fe62dec3SChen-Liang Xu #define	UNREFERENCED_4PARAMETER(_p, _q, _r, _s)	_NOTE(ARGUNUSED(_p, _q, _r, _s))
178fe62dec3SChen-Liang Xu #define	UNREFERENCED_5PARAMETER(_p, _q, _r, _s, _t)	\
179fe62dec3SChen-Liang Xu 	_NOTE(ARGUNUSED(_p, _q, _r, _s, _t))
180fe62dec3SChen-Liang Xu 
18125f2d433Sxy150489 typedef	int8_t		s8;
18225f2d433Sxy150489 typedef	int16_t		s16;
18325f2d433Sxy150489 typedef	int32_t		s32;
18425f2d433Sxy150489 typedef	int64_t		s64;
18525f2d433Sxy150489 typedef	uint8_t		u8;
18625f2d433Sxy150489 typedef	uint16_t	u16;
18725f2d433Sxy150489 typedef	uint32_t	u32;
18825f2d433Sxy150489 typedef	uint64_t	u64;
1894d737963Sxiangtao you - Sun Microsystems - Beijing China typedef boolean_t	bool;
19008057504Sxy150489 
191d5c3073dSchenlu chen - Sun Microsystems - Beijing China #define	__le16 u16
192d5c3073dSchenlu chen - Sun Microsystems - Beijing China #define	__le32 u32
193d5c3073dSchenlu chen - Sun Microsystems - Beijing China #define	__le64 u64
194d5c3073dSchenlu chen - Sun Microsystems - Beijing China 
19508057504Sxy150489 struct e1000g_osdep {
19625f2d433Sxy150489 	ddi_acc_handle_t reg_handle;
19725f2d433Sxy150489 	ddi_acc_handle_t cfg_handle;
19808057504Sxy150489 	ddi_acc_handle_t ich_flash_handle;
1993f64cd55Sguoqing zhu - Sun Microsystems - Beijing China 	ddi_acc_handle_t io_reg_handle;
20025f2d433Sxy150489 	struct e1000g *adapter;
20108057504Sxy150489 };
20208057504Sxy150489 
203caf05df5SMiles Xu, Sun Microsystems /* Shared Code Mutex Defines */
204caf05df5SMiles Xu, Sun Microsystems #define	E1000_MUTEX			kmutex_t
205caf05df5SMiles Xu, Sun Microsystems #define	E1000_MUTEX_INIT(mutex)		mutex_init(mutex, NULL, \
206caf05df5SMiles Xu, Sun Microsystems 	MUTEX_DRIVER, NULL)
207caf05df5SMiles Xu, Sun Microsystems #define	E1000_MUTEX_DESTROY(mutex)	mutex_destroy(mutex)
208caf05df5SMiles Xu, Sun Microsystems 
209caf05df5SMiles Xu, Sun Microsystems #define	E1000_MUTEX_LOCK(mutex)		mutex_enter(mutex)
210caf05df5SMiles Xu, Sun Microsystems #define	E1000_MUTEX_TRYLOCK(mutex)	mutex_tryenter(mutex)
211caf05df5SMiles Xu, Sun Microsystems #define	E1000_MUTEX_UNLOCK(mutex)	mutex_exit(mutex)
212caf05df5SMiles Xu, Sun Microsystems 
21308057504Sxy150489 #ifdef __sparc	/* on SPARC, use only memory-mapped routines */
21408057504Sxy150489 #define	E1000_WRITE_REG_IO	E1000_WRITE_REG
21508057504Sxy150489 #else	/* on x86, use port io routines */
21625f2d433Sxy150489 #define	E1000_WRITE_REG_IO(a, reg, val)	{ \
2173f64cd55Sguoqing zhu - Sun Microsystems - Beijing China 	ddi_put32((OS_DEP(a))->io_reg_handle, \
2183f64cd55Sguoqing zhu - Sun Microsystems - Beijing China 	    (uint32_t *)(a)->io_base, \
2193f64cd55Sguoqing zhu - Sun Microsystems - Beijing China 	    reg); \
2203f64cd55Sguoqing zhu - Sun Microsystems - Beijing China 	ddi_put32((OS_DEP(a))->io_reg_handle, \
2213f64cd55Sguoqing zhu - Sun Microsystems - Beijing China 	    (uint32_t *)((a)->io_base + 4), \
2223f64cd55Sguoqing zhu - Sun Microsystems - Beijing China 	    val); \
2233f64cd55Sguoqing zhu - Sun Microsystems - Beijing China }
22408057504Sxy150489 #endif	/* __sparc */
22508057504Sxy150489 
22608057504Sxy150489 #ifdef __cplusplus
22708057504Sxy150489 }
22808057504Sxy150489 #endif
22908057504Sxy150489 
23008057504Sxy150489 #endif	/* _E1000_OSDEP_H */
231