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  */
229da57d7bSbt /*
235b6dd21fSchenlu chen - Sun Microsystems - Beijing China  * Copyright(c) 2007-2010 Intel Corporation. All rights reserved.
245b6dd21fSchenlu chen - Sun Microsystems - Beijing China  */
255b6dd21fSchenlu chen - Sun Microsystems - Beijing China 
265b6dd21fSchenlu chen - Sun Microsystems - Beijing China /*
275b6dd21fSchenlu chen - Sun Microsystems - Beijing China  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
289da57d7bSbt  */
2969b5a878SDan McDonald /*
3074b989c3SRobert Mustacchi  * Copyright (c) 2017, Joyent, Inc.
31dc0cb1cdSDale Ghent  * Copyright 2016 OmniTI Computer Consulting, Inc. All rights reserved.
3269b5a878SDan McDonald  */
349da57d7bSbt #ifndef	_IXGBE_OSDEP_H
359da57d7bSbt #define	_IXGBE_OSDEP_H
379da57d7bSbt #ifdef __cplusplus
389da57d7bSbt extern "C" {
399da57d7bSbt #endif
419da57d7bSbt #include <sys/types.h>
4273cd555cSBin Tu - Sun Microsystems - Beijing China #include <sys/byteorder.h>
439da57d7bSbt #include <sys/conf.h>
449da57d7bSbt #include <sys/debug.h>
459da57d7bSbt #include <sys/stropts.h>
469da57d7bSbt #include <sys/stream.h>
479da57d7bSbt #include <sys/strlog.h>
489da57d7bSbt #include <sys/kmem.h>
499da57d7bSbt #include <sys/stat.h>
509da57d7bSbt #include <sys/kstat.h>
519da57d7bSbt #include <sys/modctl.h>
529da57d7bSbt #include <sys/errno.h>
539da57d7bSbt #include <sys/ddi.h>
549da57d7bSbt #include <sys/dditypes.h>
559da57d7bSbt #include <sys/sunddi.h>
569da57d7bSbt #include <sys/pci.h>
579da57d7bSbt #include <sys/atomic.h>
589da57d7bSbt #include <sys/note.h>
599da57d7bSbt #include "ixgbe_debug.h"
6169b5a878SDan McDonald /* Cheesy hack for EWARN() */
6248ed61a7SRobert Mustacchi #define	EWARN(H, W) cmn_err(CE_NOTE, W)
6369b5a878SDan McDonald 
649da57d7bSbt /* function declarations */
659da57d7bSbt struct ixgbe_hw;
669da57d7bSbt uint16_t ixgbe_read_pci_cfg(struct ixgbe_hw *, uint32_t);
6773cd555cSBin Tu - Sun Microsystems - Beijing China void ixgbe_write_pci_cfg(struct ixgbe_hw *, uint32_t, uint32_t);
6874b989c3SRobert Mustacchi boolean_t ixgbe_removed(struct ixgbe_hw *);
709da57d7bSbt #define	usec_delay(x)		drv_usecwait(x)
719da57d7bSbt #define	msec_delay(x)		drv_usecwait(x * 1000)
739da57d7bSbt #define	OS_DEP(hw)		((struct ixgbe_osdep *)((hw)->back))
7513740cb2SPaul Guo #define	false		B_FALSE
7613740cb2SPaul Guo #define	true		B_TRUE
7763b3bba8SJerry Jelinek #define	FALSE		B_FALSE
7863b3bba8SJerry Jelinek #define	TRUE		B_TRUE
8048ed61a7SRobert Mustacchi #define	IXGBE_READ_PCIE_WORD	ixgbe_read_pci_cfg
8148ed61a7SRobert Mustacchi #define	IXGBE_WRITE_PCIE_WORD	ixgbe_write_pci_cfg
829da57d7bSbt #define	CMD_MEM_WRT_INVALIDATE	0x0010	/* BIT_4 */
839da57d7bSbt #define	PCI_COMMAND_REGISTER	0x04
849da57d7bSbt #define	PCI_EX_CONF_CAP		0xE0
859da57d7bSbt #define	SPEED_10GB		10000
86dc0cb1cdSDale Ghent #define	SPEED_5GB		5000
87dc0cb1cdSDale Ghent #define	SPEED_2_5GB		2500
889da57d7bSbt #define	SPEED_1GB		1000
899da57d7bSbt #define	SPEED_100		100
909da57d7bSbt #define	FULL_DUPLEX		2
929da57d7bSbt #define	IXGBE_WRITE_FLUSH(a)	(void) IXGBE_READ_REG(a, IXGBE_STATUS)
949da57d7bSbt #define	IXGBE_WRITE_REG(a, reg, value)	\
9513740cb2SPaul Guo 	ddi_put32((OS_DEP(a))->reg_handle, \
9613740cb2SPaul Guo 	    (uint32_t *)((uintptr_t)(a)->hw_addr + reg), (value))
985b6dd21fSchenlu chen - Sun Microsystems - Beijing China #define	IXGBE_WRITE_REG_ARRAY(a, reg, index, value)	\
995b6dd21fSchenlu chen - Sun Microsystems - Beijing China 	IXGBE_WRITE_REG(a, ((reg) + ((index) << 2)), (value))
1005b6dd21fSchenlu chen - Sun Microsystems - Beijing China 
1019da57d7bSbt #define	IXGBE_READ_REG(a, reg)	\
10213740cb2SPaul Guo 	ddi_get32((OS_DEP(a))->reg_handle, \
10313740cb2SPaul Guo 	    (uint32_t *)((uintptr_t)(a)->hw_addr + reg))
1055b6dd21fSchenlu chen - Sun Microsystems - Beijing China #define	IXGBE_READ_REG_ARRAY(a, reg, index)	\
1065b6dd21fSchenlu chen - Sun Microsystems - Beijing China 	IXGBE_READ_REG(a, ((reg) + ((index) << 2)))
1075b6dd21fSchenlu chen - Sun Microsystems - Beijing China 
1089da57d7bSbt #define	msec_delay_irq	msec_delay
10973cd555cSBin Tu - Sun Microsystems - Beijing China #define	IXGBE_HTONL	htonl
11063b3bba8SJerry Jelinek #define	IXGBE_NTOHL	ntohl
11163b3bba8SJerry Jelinek #define	IXGBE_NTOHS	ntohs
11369b5a878SDan McDonald #ifdef _BIG_ENDIAN
11448ed61a7SRobert Mustacchi #define	IXGBE_CPU_TO_LE16	BSWAP_16
115dc0cb1cdSDale Ghent #define	IXGBE_CPU_TO_LE32	BSWAP_32
116*e213fe2dSToomas Soome #define	IXGBE_LE32_TO_CPUS(x)	*(x) = BSWAP_32(*(x))
1179755d32aSIgor Kozhukhov #define	IXGBE_CPU_TO_BE16(x)	(x)
1189755d32aSIgor Kozhukhov #define	IXGBE_CPU_TO_BE32(x)	(x)
11948ed61a7SRobert Mustacchi #define	IXGBE_BE32_TO_CPU(x)	(x)
12069b5a878SDan McDonald #else
12148ed61a7SRobert Mustacchi #define	IXGBE_CPU_TO_LE16(x)	(x)
122dc0cb1cdSDale Ghent #define	IXGBE_CPU_TO_LE32(x)	(x)
123dc0cb1cdSDale Ghent #define	IXGBE_LE32_TO_CPUS(x)	(x)
124dc0cb1cdSDale Ghent #define	IXGBE_CPU_TO_BE16	BSWAP_16
125dc0cb1cdSDale Ghent #define	IXGBE_CPU_TO_BE32	BSWAP_32
12648ed61a7SRobert Mustacchi #define	IXGBE_BE32_TO_CPU	BSWAP_32
127dc0cb1cdSDale Ghent #endif /* _BIG_ENDIAN */
12869b5a878SDan McDonald 
12969b5a878SDan McDonald #define	UNREFERENCED_PARAMETER(x)		_NOTE(ARGUNUSED(x))
131dc0cb1cdSDale Ghent #define	UNREFERENCED_2PARAMETER(_p, _q)		_NOTE(ARGUNUSED(_p, _q))
132dc0cb1cdSDale Ghent #define	UNREFERENCED_3PARAMETER(_p, _q, _r)	_NOTE(ARGUNUSED(_p, _q, _r))
133dc0cb1cdSDale Ghent #define	UNREFERENCED_4PARAMETER(_p, _q, _r, _s)	_NOTE(ARGUNUSED(_p, _q,_r, _s))
13469b5a878SDan McDonald 
13569b5a878SDan McDonald 
13674b989c3SRobert Mustacchi #define	IXGBE_REMOVED(hw) ixgbe_removed(hw)
1389da57d7bSbt typedef	int8_t		s8;
1399da57d7bSbt typedef	int16_t		s16;
1409da57d7bSbt typedef	int32_t		s32;
1419da57d7bSbt typedef	int64_t		s64;
14248ed61a7SRobert Mustacchi typedef	uint8_t		u8;
14348ed61a7SRobert Mustacchi typedef	uint16_t	u16;
1449da57d7bSbt typedef	uint32_t	u32;
1459da57d7bSbt typedef	uint64_t	u64;
14648ed61a7SRobert Mustacchi typedef	boolean_t	bool;
148dc0cb1cdSDale Ghent /* shared code requires this */
149dc0cb1cdSDale Ghent #define	__le16  u16
150dc0cb1cdSDale Ghent #define	__le32  u32
151dc0cb1cdSDale Ghent #define	__le64  u64
152dc0cb1cdSDale Ghent #define	__be16  u16
153dc0cb1cdSDale Ghent #define	__be32  u32
154dc0cb1cdSDale Ghent #define	__be64  u64
155dc0cb1cdSDale Ghent 
1569da57d7bSbt struct ixgbe_osdep {
1579da57d7bSbt 	ddi_acc_handle_t reg_handle;
1589da57d7bSbt 	ddi_acc_handle_t cfg_handle;
1599da57d7bSbt 	struct ixgbe *ixgbe;
1609da57d7bSbt };
1629da57d7bSbt #ifdef __cplusplus
1639da57d7bSbt }
1649da57d7bSbt #endif
1669da57d7bSbt #endif	/* _IXGBE_OSDEP_H */