19da57d7bSbt /*
29da57d7bSbt  * CDDL HEADER START
39da57d7bSbt  *
49da57d7bSbt  * The contents of this file are subject to the terms of the
59da57d7bSbt  * Common Development and Distribution License (the "License").
69da57d7bSbt  * You may not use this file except in compliance with the License.
79da57d7bSbt  *
80dc2366fSVenugopal Iyer  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90dc2366fSVenugopal Iyer  * or http://www.opensolaris.org/os/licensing.
109da57d7bSbt  * See the License for the specific language governing permissions
119da57d7bSbt  * and limitations under the License.
129da57d7bSbt  *
130dc2366fSVenugopal Iyer  * When distributing Covered Code, include this CDDL HEADER in each
140dc2366fSVenugopal Iyer  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159da57d7bSbt  * If applicable, add the following below this CDDL HEADER, with the
169da57d7bSbt  * fields enclosed by brackets "[]" replaced with your own identifying
179da57d7bSbt  * information: Portions Copyright [yyyy] [name of copyright owner]
189da57d7bSbt  *
199da57d7bSbt  * CDDL HEADER END
209da57d7bSbt  */
219da57d7bSbt 
229da57d7bSbt /*
23*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China  * Copyright(c) 2007-2010 Intel Corporation. All rights reserved.
24*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China  */
25*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China 
26*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China /*
27*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
289da57d7bSbt  */
299da57d7bSbt 
309da57d7bSbt #ifndef	_IXGBE_OSDEP_H
319da57d7bSbt #define	_IXGBE_OSDEP_H
329da57d7bSbt 
339da57d7bSbt #ifdef __cplusplus
349da57d7bSbt extern "C" {
359da57d7bSbt #endif
369da57d7bSbt 
379da57d7bSbt #include <sys/types.h>
3873cd555cSBin Tu - Sun Microsystems - Beijing China #include <sys/byteorder.h>
399da57d7bSbt #include <sys/conf.h>
409da57d7bSbt #include <sys/debug.h>
419da57d7bSbt #include <sys/stropts.h>
429da57d7bSbt #include <sys/stream.h>
439da57d7bSbt #include <sys/strlog.h>
449da57d7bSbt #include <sys/kmem.h>
459da57d7bSbt #include <sys/stat.h>
469da57d7bSbt #include <sys/kstat.h>
479da57d7bSbt #include <sys/modctl.h>
489da57d7bSbt #include <sys/errno.h>
499da57d7bSbt #include <sys/ddi.h>
509da57d7bSbt #include <sys/dditypes.h>
519da57d7bSbt #include <sys/sunddi.h>
529da57d7bSbt #include <sys/pci.h>
539da57d7bSbt #include <sys/atomic.h>
549da57d7bSbt #include <sys/note.h>
559da57d7bSbt #include "ixgbe_debug.h"
569da57d7bSbt 
579da57d7bSbt /* function declarations */
589da57d7bSbt struct ixgbe_hw;
599da57d7bSbt uint16_t ixgbe_read_pci_cfg(struct ixgbe_hw *, uint32_t);
6073cd555cSBin Tu - Sun Microsystems - Beijing China void ixgbe_write_pci_cfg(struct ixgbe_hw *, uint32_t, uint32_t);
619da57d7bSbt 
629da57d7bSbt #define	usec_delay(x)		drv_usecwait(x)
639da57d7bSbt #define	msec_delay(x)		drv_usecwait(x * 1000)
649da57d7bSbt 
659da57d7bSbt #define	OS_DEP(hw)		((struct ixgbe_osdep *)((hw)->back))
669da57d7bSbt 
6713740cb2SPaul Guo #define	false		B_FALSE
6813740cb2SPaul Guo #define	true		B_TRUE
699da57d7bSbt 
709da57d7bSbt #define	IXGBE_READ_PCIE_WORD 	ixgbe_read_pci_cfg
7173cd555cSBin Tu - Sun Microsystems - Beijing China #define	IXGBE_WRITE_PCIE_WORD 	ixgbe_write_pci_cfg
729da57d7bSbt #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
739da57d7bSbt #define	PCI_COMMAND_REGISTER	0x04
749da57d7bSbt #define	PCI_EX_CONF_CAP		0xE0
759da57d7bSbt #define	SPEED_10GB		10000
769da57d7bSbt #define	SPEED_1GB		1000
779da57d7bSbt #define	SPEED_100		100
789da57d7bSbt #define	FULL_DUPLEX		2
799da57d7bSbt 
809da57d7bSbt #define	IXGBE_WRITE_FLUSH(a)	(void) IXGBE_READ_REG(a, IXGBE_STATUS)
819da57d7bSbt 
829da57d7bSbt #define	IXGBE_WRITE_REG(a, reg, value)	\
8313740cb2SPaul Guo 	ddi_put32((OS_DEP(a))->reg_handle, \
8413740cb2SPaul Guo 	    (uint32_t *)((uintptr_t)(a)->hw_addr + reg), (value))
859da57d7bSbt 
86*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China #define	IXGBE_WRITE_REG_ARRAY(a, reg, index, value)	\
87*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China 	IXGBE_WRITE_REG(a, ((reg) + ((index) << 2)), (value))
88*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China 
899da57d7bSbt #define	IXGBE_READ_REG(a, reg)	\
9013740cb2SPaul Guo 	ddi_get32((OS_DEP(a))->reg_handle, \
9113740cb2SPaul Guo 	    (uint32_t *)((uintptr_t)(a)->hw_addr + reg))
929da57d7bSbt 
93*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China #define	IXGBE_READ_REG_ARRAY(a, reg, index)	\
94*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China 	IXGBE_READ_REG(a, ((reg) + ((index) << 2)))
95*5b6dd21fSchenlu chen - Sun Microsystems - Beijing China 
9673cd555cSBin Tu - Sun Microsystems - Beijing China #define	IXGBE_WRITE_REG64(hw, reg, value)	\
9773cd555cSBin Tu - Sun Microsystems - Beijing China 	do {								\
9873cd555cSBin Tu - Sun Microsystems - Beijing China 		IXGBE_WRITE_REG(hw, reg, (u32) value);			\
9973cd555cSBin Tu - Sun Microsystems - Beijing China 		IXGBE_WRITE_REG(hw, reg + 4, (u32) (value >> 32));	\
10073cd555cSBin Tu - Sun Microsystems - Beijing China 		_NOTE(CONSTCOND)					\
10173cd555cSBin Tu - Sun Microsystems - Beijing China 	} while (0)
10273cd555cSBin Tu - Sun Microsystems - Beijing China 
1039da57d7bSbt #define	msec_delay_irq	msec_delay
10473cd555cSBin Tu - Sun Microsystems - Beijing China #define	IXGBE_HTONL	htonl
1059da57d7bSbt 
1069da57d7bSbt #define	UNREFERENCED_PARAMETER(x)	_NOTE(ARGUNUSED(x))
1079da57d7bSbt 
1089da57d7bSbt typedef	int8_t		s8;
1099da57d7bSbt typedef	int16_t		s16;
1109da57d7bSbt typedef	int32_t		s32;
1119da57d7bSbt typedef	int64_t		s64;
1129da57d7bSbt typedef uint8_t		u8;
1139da57d7bSbt typedef	uint16_t 	u16;
1149da57d7bSbt typedef	uint32_t	u32;
1159da57d7bSbt typedef	uint64_t	u64;
1169da57d7bSbt typedef boolean_t	bool;
1179da57d7bSbt 
1189da57d7bSbt struct ixgbe_osdep {
1199da57d7bSbt 	ddi_acc_handle_t reg_handle;
1209da57d7bSbt 	ddi_acc_handle_t cfg_handle;
1219da57d7bSbt 	struct ixgbe *ixgbe;
1229da57d7bSbt };
1239da57d7bSbt 
1249da57d7bSbt #ifdef __cplusplus
1259da57d7bSbt }
1269da57d7bSbt #endif
1279da57d7bSbt 
1289da57d7bSbt #endif	/* _IXGBE_OSDEP_H */
129