19da57d7bSbt /*
29da57d7bSbt  * CDDL HEADER START
39da57d7bSbt  *
473cd555cSBin Tu - Sun Microsystems - Beijing China  * Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
59da57d7bSbt  * The contents of this file are subject to the terms of the
69da57d7bSbt  * Common Development and Distribution License (the "License").
79da57d7bSbt  * You may not use this file except in compliance with the License.
89da57d7bSbt  *
9*0dc2366fSVenugopal Iyer  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0dc2366fSVenugopal Iyer  * or http://www.opensolaris.org/os/licensing.
119da57d7bSbt  * See the License for the specific language governing permissions
129da57d7bSbt  * and limitations under the License.
139da57d7bSbt  *
14*0dc2366fSVenugopal Iyer  * When distributing Covered Code, include this CDDL HEADER in each
15*0dc2366fSVenugopal Iyer  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
169da57d7bSbt  * If applicable, add the following below this CDDL HEADER, with the
179da57d7bSbt  * fields enclosed by brackets "[]" replaced with your own identifying
189da57d7bSbt  * information: Portions Copyright [yyyy] [name of copyright owner]
199da57d7bSbt  *
209da57d7bSbt  * CDDL HEADER END
219da57d7bSbt  */
229da57d7bSbt 
239da57d7bSbt /*
24*0dc2366fSVenugopal Iyer  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
2573cd555cSBin Tu - Sun Microsystems - Beijing China  * Use is subject to license terms.
269da57d7bSbt  */
279da57d7bSbt 
289da57d7bSbt #ifndef	_IXGBE_OSDEP_H
299da57d7bSbt #define	_IXGBE_OSDEP_H
309da57d7bSbt 
319da57d7bSbt #ifdef __cplusplus
329da57d7bSbt extern "C" {
339da57d7bSbt #endif
349da57d7bSbt 
359da57d7bSbt #include <sys/types.h>
3673cd555cSBin Tu - Sun Microsystems - Beijing China #include <sys/byteorder.h>
379da57d7bSbt #include <sys/conf.h>
389da57d7bSbt #include <sys/debug.h>
399da57d7bSbt #include <sys/stropts.h>
409da57d7bSbt #include <sys/stream.h>
419da57d7bSbt #include <sys/strlog.h>
429da57d7bSbt #include <sys/kmem.h>
439da57d7bSbt #include <sys/stat.h>
449da57d7bSbt #include <sys/kstat.h>
459da57d7bSbt #include <sys/modctl.h>
469da57d7bSbt #include <sys/errno.h>
479da57d7bSbt #include <sys/ddi.h>
489da57d7bSbt #include <sys/dditypes.h>
499da57d7bSbt #include <sys/sunddi.h>
509da57d7bSbt #include <sys/pci.h>
519da57d7bSbt #include <sys/atomic.h>
529da57d7bSbt #include <sys/note.h>
539da57d7bSbt #include "ixgbe_debug.h"
549da57d7bSbt 
559da57d7bSbt /* function declarations */
569da57d7bSbt struct ixgbe_hw;
579da57d7bSbt uint16_t ixgbe_read_pci_cfg(struct ixgbe_hw *, uint32_t);
5873cd555cSBin Tu - Sun Microsystems - Beijing China void ixgbe_write_pci_cfg(struct ixgbe_hw *, uint32_t, uint32_t);
599da57d7bSbt 
609da57d7bSbt #define	usec_delay(x)		drv_usecwait(x)
619da57d7bSbt #define	msec_delay(x)		drv_usecwait(x * 1000)
629da57d7bSbt 
639da57d7bSbt #define	OS_DEP(hw)		((struct ixgbe_osdep *)((hw)->back))
649da57d7bSbt 
6513740cb2SPaul Guo #define	false		B_FALSE
6613740cb2SPaul Guo #define	true		B_TRUE
679da57d7bSbt 
689da57d7bSbt #define	IXGBE_READ_PCIE_WORD 	ixgbe_read_pci_cfg
6973cd555cSBin Tu - Sun Microsystems - Beijing China #define	IXGBE_WRITE_PCIE_WORD 	ixgbe_write_pci_cfg
709da57d7bSbt #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
719da57d7bSbt #define	PCI_COMMAND_REGISTER	0x04
729da57d7bSbt #define	PCI_EX_CONF_CAP		0xE0
739da57d7bSbt #define	SPEED_10GB		10000
749da57d7bSbt #define	SPEED_1GB		1000
759da57d7bSbt #define	SPEED_100		100
769da57d7bSbt #define	FULL_DUPLEX		2
779da57d7bSbt 
789da57d7bSbt #define	IXGBE_WRITE_FLUSH(a)	(void) IXGBE_READ_REG(a, IXGBE_STATUS)
799da57d7bSbt 
809da57d7bSbt #define	IXGBE_WRITE_REG(a, reg, value)	\
8113740cb2SPaul Guo 	ddi_put32((OS_DEP(a))->reg_handle, \
8213740cb2SPaul Guo 	    (uint32_t *)((uintptr_t)(a)->hw_addr + reg), (value))
839da57d7bSbt 
849da57d7bSbt #define	IXGBE_READ_REG(a, reg)	\
8513740cb2SPaul Guo 	ddi_get32((OS_DEP(a))->reg_handle, \
8613740cb2SPaul Guo 	    (uint32_t *)((uintptr_t)(a)->hw_addr + reg))
879da57d7bSbt 
8873cd555cSBin Tu - Sun Microsystems - Beijing China #define	IXGBE_WRITE_REG64(hw, reg, value)	\
8973cd555cSBin Tu - Sun Microsystems - Beijing China 	do {								\
9073cd555cSBin Tu - Sun Microsystems - Beijing China 		IXGBE_WRITE_REG(hw, reg, (u32) value);			\
9173cd555cSBin Tu - Sun Microsystems - Beijing China 		IXGBE_WRITE_REG(hw, reg + 4, (u32) (value >> 32));	\
9273cd555cSBin Tu - Sun Microsystems - Beijing China 		_NOTE(CONSTCOND)					\
9373cd555cSBin Tu - Sun Microsystems - Beijing China 	} while (0)
9473cd555cSBin Tu - Sun Microsystems - Beijing China 
959da57d7bSbt #define	msec_delay_irq	msec_delay
9673cd555cSBin Tu - Sun Microsystems - Beijing China #define	IXGBE_HTONL	htonl
979da57d7bSbt 
989da57d7bSbt #define	UNREFERENCED_PARAMETER(x)	_NOTE(ARGUNUSED(x))
999da57d7bSbt 
1009da57d7bSbt typedef	int8_t		s8;
1019da57d7bSbt typedef	int16_t		s16;
1029da57d7bSbt typedef	int32_t		s32;
1039da57d7bSbt typedef	int64_t		s64;
1049da57d7bSbt typedef uint8_t		u8;
1059da57d7bSbt typedef	uint16_t 	u16;
1069da57d7bSbt typedef	uint32_t	u32;
1079da57d7bSbt typedef	uint64_t	u64;
1089da57d7bSbt typedef boolean_t	bool;
1099da57d7bSbt 
1109da57d7bSbt struct ixgbe_osdep {
1119da57d7bSbt 	ddi_acc_handle_t reg_handle;
1129da57d7bSbt 	ddi_acc_handle_t cfg_handle;
1139da57d7bSbt 	struct ixgbe *ixgbe;
1149da57d7bSbt };
1159da57d7bSbt 
1169da57d7bSbt #ifdef __cplusplus
1179da57d7bSbt }
1189da57d7bSbt #endif
1199da57d7bSbt 
1209da57d7bSbt #endif	/* _IXGBE_OSDEP_H */
121