xref: /onnv-gate/usr/src/uts/common/io/e1000g/e1000_osdep.h (revision 11532:df2488d7edc4)
13526Sxy150489 /*
23526Sxy150489  * This file is provided under a CDDLv1 license.  When using or
33526Sxy150489  * redistributing this file, you may do so under this license.
43526Sxy150489  * In redistributing this file this license must be included
53526Sxy150489  * and no other modification of this header file is permitted.
63526Sxy150489  *
73526Sxy150489  * CDDL LICENSE SUMMARY
83526Sxy150489  *
98479SChenlu.Chen@Sun.COM  * Copyright(c) 1999 - 2009 Intel Corporation. All rights reserved.
103526Sxy150489  *
113526Sxy150489  * The contents of this file are subject to the terms of Version
123526Sxy150489  * 1.0 of the Common Development and Distribution License (the "License").
133526Sxy150489  *
143526Sxy150489  * You should have received a copy of the License with this software.
153526Sxy150489  * You can obtain a copy of the License at
163526Sxy150489  *	http://www.opensolaris.org/os/licensing.
173526Sxy150489  * See the License for the specific language governing permissions
183526Sxy150489  * and limitations under the License.
193526Sxy150489  */
203526Sxy150489 
213526Sxy150489 /*
22*11532SGuoqing.Zhu@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
233526Sxy150489  * Use is subject to license terms of the CDDLv1.
243526Sxy150489  */
253526Sxy150489 
263526Sxy150489 #ifndef _E1000_OSDEP_H
273526Sxy150489 #define	_E1000_OSDEP_H
283526Sxy150489 
293526Sxy150489 #ifdef __cplusplus
303526Sxy150489 extern "C" {
313526Sxy150489 #endif
323526Sxy150489 
333526Sxy150489 #include <sys/types.h>
343526Sxy150489 #include <sys/conf.h>
353526Sxy150489 #include <sys/debug.h>
363526Sxy150489 #include <sys/stropts.h>
373526Sxy150489 #include <sys/stream.h>
383526Sxy150489 #include <sys/strlog.h>
393526Sxy150489 #include <sys/kmem.h>
403526Sxy150489 #include <sys/stat.h>
413526Sxy150489 #include <sys/kstat.h>
423526Sxy150489 #include <sys/modctl.h>
433526Sxy150489 #include <sys/errno.h>
443526Sxy150489 #include <sys/ddi.h>
453526Sxy150489 #include <sys/sunddi.h>
463526Sxy150489 #include <sys/pci.h>
474919Sxy150489 #include <sys/atomic.h>
487426SChenliang.Xu@Sun.COM #include <sys/note.h>
4910680SMin.Xu@Sun.COM #include <sys/mutex.h>
504919Sxy150489 #include "e1000g_debug.h"
513526Sxy150489 
523526Sxy150489 #define	usec_delay(x)		drv_usecwait(x)
533526Sxy150489 #define	msec_delay(x)		drv_usecwait(x * 1000)
547607STed.You@Sun.COM #define	msec_delay_irq		msec_delay
553526Sxy150489 
564919Sxy150489 #ifdef E1000G_DEBUG
574919Sxy150489 #define	DEBUGOUT(S)		\
584919Sxy150489 	E1000G_DEBUGLOG_0(NULL, E1000G_INFO_LEVEL, S)
594919Sxy150489 #define	DEBUGOUT1(S, A)		\
604919Sxy150489 	E1000G_DEBUGLOG_1(NULL, E1000G_INFO_LEVEL, S, A)
614919Sxy150489 #define	DEBUGOUT2(S, A, B)	\
624919Sxy150489 	E1000G_DEBUGLOG_2(NULL, E1000G_INFO_LEVEL, S, A, B)
634919Sxy150489 #define	DEBUGOUT3(S, A, B, C)	\
644919Sxy150489 	E1000G_DEBUGLOG_3(NULL, E1000G_INFO_LEVEL, S, A, B, C)
654919Sxy150489 #define	DEBUGFUNC(F)		\
664919Sxy150489 	E1000G_DEBUGLOG_0(NULL, E1000G_TRACE_LEVEL, F)
673526Sxy150489 #else
683526Sxy150489 #define	DEBUGOUT(S)
693526Sxy150489 #define	DEBUGOUT1(S, A)
703526Sxy150489 #define	DEBUGOUT2(S, A, B)
713526Sxy150489 #define	DEBUGOUT3(S, A, B, C)
724919Sxy150489 #define	DEBUGFUNC(F)
733526Sxy150489 #endif
743526Sxy150489 
754919Sxy150489 #define	OS_DEP(hw)		((struct e1000g_osdep *)((hw)->back))
763526Sxy150489 
777607STed.You@Sun.COM #define	false		0
787607STed.You@Sun.COM #define	true		1
7910680SMin.Xu@Sun.COM 
803526Sxy150489 #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
813526Sxy150489 #define	PCI_COMMAND_REGISTER	0x04
824919Sxy150489 #define	PCI_EX_CONF_CAP		0xE0
837607STed.You@Sun.COM #define	ADAPTER_REG_SET		1 /* solaris mapping of adapter registers */
844919Sxy150489 #define	ICH_FLASH_REG_SET	2	/* solaris mapping of flash memory */
853526Sxy150489 
864919Sxy150489 #define	RECEIVE_BUFFER_ALIGN_SIZE	256
874919Sxy150489 #define	E1000_MDALIGN			4096
888178SChenlu.Chen@Sun.COM #define	E1000_MDALIGN_82546		65536
894919Sxy150489 #define	E1000_ERT_2048			0x100
904919Sxy150489 
914919Sxy150489 /* PHY Extended Status Register */
924919Sxy150489 #define	IEEE_ESR_1000T_HD_CAPS	0x1000	/* 1000T HD capable */
934919Sxy150489 #define	IEEE_ESR_1000T_FD_CAPS	0x2000	/* 1000T FD capable */
944919Sxy150489 #define	IEEE_ESR_1000X_HD_CAPS	0x4000	/* 1000X HD capable */
954919Sxy150489 #define	IEEE_ESR_1000X_FD_CAPS	0x8000	/* 1000X FD capable */
964919Sxy150489 
976735Scc210113 /*
986735Scc210113  * required by shared code
996735Scc210113  */
1007426SChenliang.Xu@Sun.COM #define	E1000_WRITE_FLUSH(a)	(void)E1000_READ_REG(a, E1000_STATUS)
1014919Sxy150489 
1024919Sxy150489 #define	E1000_WRITE_REG(hw, reg, value)	\
1033526Sxy150489 {\
1044919Sxy150489 	if ((hw)->mac.type != e1000_82542) \
1054919Sxy150489 		ddi_put32((OS_DEP(hw))->reg_handle, \
1067426SChenliang.Xu@Sun.COM 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + reg), \
1073526Sxy150489 		    value); \
1083526Sxy150489 	else \
1094919Sxy150489 		ddi_put32((OS_DEP(hw))->reg_handle, \
1107426SChenliang.Xu@Sun.COM 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + \
1114919Sxy150489 		    e1000_translate_register_82542(reg)), \
1123526Sxy150489 		    value); \
1133526Sxy150489 }
1143526Sxy150489 
1154919Sxy150489 #define	E1000_READ_REG(hw, reg) (\
1164919Sxy150489 	((hw)->mac.type != e1000_82542) ? \
1174919Sxy150489 	    ddi_get32((OS_DEP(hw))->reg_handle, \
1187426SChenliang.Xu@Sun.COM 		(uint32_t *)((uintptr_t)(hw)->hw_addr + reg)) : \
1194919Sxy150489 	    ddi_get32((OS_DEP(hw))->reg_handle, \
1207426SChenliang.Xu@Sun.COM 		(uint32_t *)((uintptr_t)(hw)->hw_addr + \
1214919Sxy150489 		e1000_translate_register_82542(reg))))
1223526Sxy150489 
1234919Sxy150489 #define	E1000_WRITE_REG_ARRAY(hw, reg, offset, value) \
1243526Sxy150489 {\
1254919Sxy150489 	if ((hw)->mac.type != e1000_82542) \
1264919Sxy150489 		ddi_put32((OS_DEP(hw))->reg_handle, \
1277426SChenliang.Xu@Sun.COM 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + \
1287426SChenliang.Xu@Sun.COM 		    reg + ((offset) << 2)),\
1293526Sxy150489 		    value); \
1303526Sxy150489 	else \
1314919Sxy150489 		ddi_put32((OS_DEP(hw))->reg_handle, \
1327426SChenliang.Xu@Sun.COM 		    (uint32_t *)((uintptr_t)(hw)->hw_addr + \
1334919Sxy150489 		    e1000_translate_register_82542(reg) + \
1343526Sxy150489 		    ((offset) << 2)), value); \
1353526Sxy150489 }
1363526Sxy150489 
1374919Sxy150489 #define	E1000_READ_REG_ARRAY(hw, reg, offset) (\
1384919Sxy150489 	((hw)->mac.type != e1000_82542) ? \
1394919Sxy150489 	    ddi_get32((OS_DEP(hw))->reg_handle, \
1407426SChenliang.Xu@Sun.COM 		(uint32_t *)((uintptr_t)(hw)->hw_addr + reg + \
1417426SChenliang.Xu@Sun.COM 		((offset) << 2))) : \
1424919Sxy150489 	    ddi_get32((OS_DEP(hw))->reg_handle, \
1437426SChenliang.Xu@Sun.COM 		(uint32_t *)((uintptr_t)(hw)->hw_addr + \
1444919Sxy150489 		e1000_translate_register_82542(reg) + \
1453526Sxy150489 		((offset) << 2))))
1463526Sxy150489 
1473526Sxy150489 
1487426SChenliang.Xu@Sun.COM #define	E1000_WRITE_REG_ARRAY_DWORD(a, reg, offset, value)	\
1497426SChenliang.Xu@Sun.COM 	E1000_WRITE_REG_ARRAY(a, reg, offset, value)
1507426SChenliang.Xu@Sun.COM #define	E1000_READ_REG_ARRAY_DWORD(a, reg, offset)		\
1517426SChenliang.Xu@Sun.COM 	E1000_READ_REG_ARRAY(a, reg, offset)
1523526Sxy150489 
1533526Sxy150489 
1544919Sxy150489 #define	E1000_READ_FLASH_REG(hw, reg)	\
1553526Sxy150489 	ddi_get32((OS_DEP(hw))->ich_flash_handle, \
1567426SChenliang.Xu@Sun.COM 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)))
1573526Sxy150489 
1584919Sxy150489 #define	E1000_READ_FLASH_REG16(hw, reg)	\
1593526Sxy150489 	ddi_get16((OS_DEP(hw))->ich_flash_handle, \
1607426SChenliang.Xu@Sun.COM 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)))
1613526Sxy150489 
1624919Sxy150489 #define	E1000_WRITE_FLASH_REG(hw, reg, value)	\
1634919Sxy150489 	ddi_put32((OS_DEP(hw))->ich_flash_handle, \
1647426SChenliang.Xu@Sun.COM 		(uint32_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
1653526Sxy150489 
1664919Sxy150489 #define	E1000_WRITE_FLASH_REG16(hw, reg, value)	\
1674919Sxy150489 	ddi_put16((OS_DEP(hw))->ich_flash_handle, \
1687426SChenliang.Xu@Sun.COM 		(uint16_t *)((uintptr_t)(hw)->flash_address + (reg)), (value))
1693526Sxy150489 
1707426SChenliang.Xu@Sun.COM #define	UNREFERENCED_1PARAMETER(_p)		_NOTE(ARGUNUSED(_p))
1717426SChenliang.Xu@Sun.COM #define	UNREFERENCED_2PARAMETER(_p, _q)		_NOTE(ARGUNUSED(_p, _q))
1727426SChenliang.Xu@Sun.COM #define	UNREFERENCED_3PARAMETER(_p, _q, _r)	_NOTE(ARGUNUSED(_p, _q, _r))
1737426SChenliang.Xu@Sun.COM #define	UNREFERENCED_4PARAMETER(_p, _q, _r, _s)	_NOTE(ARGUNUSED(_p, _q, _r, _s))
1747426SChenliang.Xu@Sun.COM #define	UNREFERENCED_5PARAMETER(_p, _q, _r, _s, _t)	\
1757426SChenliang.Xu@Sun.COM 	_NOTE(ARGUNUSED(_p, _q, _r, _s, _t))
1767426SChenliang.Xu@Sun.COM 
1774919Sxy150489 typedef	int8_t		s8;
1784919Sxy150489 typedef	int16_t		s16;
1794919Sxy150489 typedef	int32_t		s32;
1804919Sxy150489 typedef	int64_t		s64;
1814919Sxy150489 typedef	uint8_t		u8;
1824919Sxy150489 typedef	uint16_t	u16;
1834919Sxy150489 typedef	uint32_t	u32;
1844919Sxy150489 typedef	uint64_t	u64;
1857607STed.You@Sun.COM typedef boolean_t	bool;
1863526Sxy150489 
1878479SChenlu.Chen@Sun.COM #define	__le16 u16
1888479SChenlu.Chen@Sun.COM #define	__le32 u32
1898479SChenlu.Chen@Sun.COM #define	__le64 u64
1908479SChenlu.Chen@Sun.COM 
1913526Sxy150489 struct e1000g_osdep {
1924919Sxy150489 	ddi_acc_handle_t reg_handle;
1934919Sxy150489 	ddi_acc_handle_t cfg_handle;
1943526Sxy150489 	ddi_acc_handle_t ich_flash_handle;
195*11532SGuoqing.Zhu@Sun.COM 	ddi_acc_handle_t io_reg_handle;
1964919Sxy150489 	struct e1000g *adapter;
1973526Sxy150489 };
1983526Sxy150489 
19910680SMin.Xu@Sun.COM /* Shared Code Mutex Defines */
20010680SMin.Xu@Sun.COM #define	E1000_MUTEX			kmutex_t
20110680SMin.Xu@Sun.COM #define	E1000_MUTEX_INIT(mutex)		mutex_init(mutex, NULL, \
20210680SMin.Xu@Sun.COM 	MUTEX_DRIVER, NULL)
20310680SMin.Xu@Sun.COM #define	E1000_MUTEX_DESTROY(mutex)	mutex_destroy(mutex)
20410680SMin.Xu@Sun.COM 
20510680SMin.Xu@Sun.COM #define	E1000_MUTEX_LOCK(mutex)		mutex_enter(mutex)
20610680SMin.Xu@Sun.COM #define	E1000_MUTEX_TRYLOCK(mutex)	mutex_tryenter(mutex)
20710680SMin.Xu@Sun.COM #define	E1000_MUTEX_UNLOCK(mutex)	mutex_exit(mutex)
20810680SMin.Xu@Sun.COM 
2093526Sxy150489 #ifdef __sparc	/* on SPARC, use only memory-mapped routines */
2103526Sxy150489 #define	E1000_WRITE_REG_IO	E1000_WRITE_REG
2113526Sxy150489 #else	/* on x86, use port io routines */
2124919Sxy150489 #define	E1000_WRITE_REG_IO(a, reg, val)	{ \
213*11532SGuoqing.Zhu@Sun.COM 	ddi_put32((OS_DEP(a))->io_reg_handle, \
214*11532SGuoqing.Zhu@Sun.COM 	    (uint32_t *)(a)->io_base, \
215*11532SGuoqing.Zhu@Sun.COM 	    reg); \
216*11532SGuoqing.Zhu@Sun.COM 	ddi_put32((OS_DEP(a))->io_reg_handle, \
217*11532SGuoqing.Zhu@Sun.COM 	    (uint32_t *)((a)->io_base + 4), \
218*11532SGuoqing.Zhu@Sun.COM 	    val); \
219*11532SGuoqing.Zhu@Sun.COM }
2203526Sxy150489 #endif	/* __sparc */
2213526Sxy150489 
2223526Sxy150489 #ifdef __cplusplus
2233526Sxy150489 }
2243526Sxy150489 #endif
2253526Sxy150489 
2263526Sxy150489 #endif	/* _E1000_OSDEP_H */
227