xref: /illumos-gate/usr/src/uts/common/io/i40e/i40e_osdep.h (revision 3d75a287b67b9092b2820a0d7c3be218f843066b)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
14  * Copyright 2016 Joyent, Inc.
15  */
16 
17 #ifndef _I40E_OSDEP_H
18 #define	_I40E_OSDEP_H
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <sys/types.h>
25 #include <sys/ddi.h>
26 #include <sys/sunddi.h>
27 #include <sys/pci_cap.h>
28 #include <sys/sysmacros.h>
29 
30 #define	DEBUGOUT(S)				i40e_debug(NULL, 0, S)
31 #define	DEBUGOUT1(S, A)				i40e_debug(NULL, 0, S, A)
32 #define	DEBUGOUT2(S, A, B)			i40e_debug(NULL, 0, S, A, B)
33 #define	DEBUGOUT3(S, A, B, C)			i40e_debug(NULL, 0, S, A, B, C)
34 #define	DEBUGOUT4(S, A, B, C, D)		\
35 	i40e_debug(NULL, 0, S, A, B, C, D)
36 #define	DEBUGOUT5(S, A, B, C, D, E)		\
37 	i40e_debug(NULL, 0, S, A, B, C, D, E)
38 #define	DEBUGOUT6(S, A, B, C, D, E, F)		\
39 	i40e_debug(NULL, 0, S, A, B, C, D, E, F)
40 #define	DEBUGOUT7(S, A, B, C, D, E, F, G)	\
41 	i40e_debug(NULL, 0, S, A, B, C, D, E, F, G)
42 #define	DEBUGFUNC(F)				DEBUGOUT(F);
43 
44 
45 #define	UNREFERENCED_PARAMETER(x)		_NOTE(ARGUNUSED(x))
46 #define	UNREFERENCED_1PARAMETER(_p)		UNREFERENCED_PARAMETER(_p)
47 #define	UNREFERENCED_2PARAMETER(_p, _q)		_NOTE(ARGUNUSED(_p, _q))
48 #define	UNREFERENCED_3PARAMETER(_p, _q, _r)	_NOTE(ARGUNUSED(_p, _q, _r))
49 #define	UNREFERENCED_4PARAMETER(_p, _q, _r, _s)	_NOTE(ARGUNUSED(_p, _q, _r, _s))
50 
51 #define	INLINE  inline
52 
53 /*
54  * The mdb dmod needs to use this code as well, but mdb already defines TRUE and
55  * FALSE in the module API. Thus we don't define these if we're building the
56  * dmod, as indicated by _I40E_MDB_DMOD. However, if we don't define these, then
57  * the shared code will be upset.
58  */
59 #ifndef _I40E_MDB_DMOD
60 #define	FALSE	B_FALSE
61 #define	false	B_FALSE
62 #define	TRUE	B_TRUE
63 #define	true	B_TRUE
64 #endif /* _I40E_MDB_DMOD */
65 
66 
67 #define	CPU_TO_LE16(o)	LE_16(o)
68 #define	CPU_TO_LE32(s)	LE_32(s)
69 #define	CPU_TO_LE64(h)	LE_64(h)
70 #define	LE16_TO_CPU(a)	LE_16(a)
71 #define	LE32_TO_CPU(c)	LE_32(c)
72 #define	LE64_TO_CPU(k)	LE_64(k)
73 
74 #define	I40E_NTOHS(a)	ntohs(a)
75 #define	I40E_NTOHL(a)	ntohl(a)
76 #define	I40E_HTONS(a)	htons(a)
77 #define	I40E_HTONL(a)	htonl(a)
78 
79 #define	i40e_memset(a, b, c, d)  memset((a), (b), (c))
80 #define	i40e_memcpy(a, b, c, d)  bcopy((b), (a), (c))
81 
82 #define	i40e_usec_delay(x) drv_usecwait(x)
83 #define	i40e_msec_delay(x) drv_usecwait(1000 * (x))
84 
85 #define	FIELD_SIZEOF(x, y) (sizeof (((x*)0)->y))
86 
87 #define	BIT(a) 		(1UL << (a))
88 #define	BIT_ULL(a) 	(1ULL << (a))
89 
90 typedef boolean_t	bool;
91 
92 typedef uint8_t		u8;
93 typedef int8_t		s8;
94 typedef uint16_t	u16;
95 typedef int16_t		s16;
96 typedef uint32_t	u32;
97 typedef int32_t		s32;
98 typedef uint64_t	u64;
99 
100 /* long string relief */
101 typedef enum i40e_status_code i40e_status;
102 
103 #define	__le16  u16
104 #define	__le32  u32
105 #define	__le64  u64
106 #define	__be16  u16
107 #define	__be32  u32
108 #define	__be64  u64
109 
110 /*
111  * Most other systems use spin locks for interrupts. However, illumos always
112  * uses a single kmutex_t for both and we decide what to do based on IPL (hint:
113  * it's not going to be a true spin lock, we'll use an adaptive mutex).
114  */
115 struct i40e_spinlock {
116 	kmutex_t ispl_mutex;
117 };
118 
119 /*
120  * Note, while prefetch is strictly not present on all architectures, (it's an
121  * SSE extension on i386), it is expected that the platforms provide it.
122  */
123 #define	prefetch(x) prefetch_read_many(x)
124 
125 struct i40e_osdep {
126 	off_t			ios_reg_size;
127 	ddi_acc_handle_t 	ios_reg_handle;
128 	ddi_acc_handle_t 	ios_cfg_handle;
129 	struct i40e		*ios_i40e;
130 };
131 
132 /*
133  * This structure and its members are defined by the common code. This means we
134  * cannot structure prefix it, even if we want to.
135  */
136 struct i40e_virt_mem {
137 	void 	*va;
138 	u32	size;
139 };
140 
141 /*
142  * The first three members of this structure are defined by the common code.
143  * This means we cannot structure prefix them, even if we wanted to.
144  */
145 struct i40e_dma_mem {
146 	void			*va;	/* Virtual address. */
147 	u64			pa;	/* Physical (DMA/Hardware) address. */
148 	size_t			size;	/* Buffer size. */
149 
150 	/* illumos-private members */
151 	ddi_acc_handle_t	idm_acc_handle;	/* Data access handle */
152 	ddi_dma_handle_t	idm_dma_handle;	/* DMA handle */
153 	uint32_t		idm_alignment;	/* Requested alignment */
154 };
155 
156 struct i40e_hw; /* forward decl */
157 
158 #define	OS_DEP(hw) ((struct i40e_osdep *)((hw)->back))
159 #define	i40e_read_pci_cfg(hw, reg) \
160 	(pci_config_get16(OS_DEP(hw)->ios_cfg_handle, (reg)))
161 #define	i40e_write_pci_cfg(hw, reg, value) \
162 	(pci_config_put16(OS_DEP(hw)->ios_cfg_handle, (reg), (value)))
163 
164 /*
165  * Intel expects that the symbol wr32 and rd32 be defined to something which can
166  * read and write the 32-bit register in PCI space.
167  *
168  * To make it easier for readers and satisfy the general agreement that macros
169  * should be in all capitals, we use our own versions of these macros.
170  */
171 #define	wr32(hw, reg, value) \
172 	ddi_put32(OS_DEP(hw)->ios_reg_handle, \
173 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + (reg)), (value))
174 #define	rd32(hw, reg) \
175 	ddi_get32(OS_DEP(hw)->ios_reg_handle, \
176 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + (reg)))
177 #define	I40E_WRITE_REG	wr32
178 #define	I40E_READ_REG	rd32
179 
180 /*
181  * The use of GLGEN_STAT presumes that we're only using this file for a PF
182  * driver. If we end up doing a VF driver, then we'll want to logically change
183  * this.
184  */
185 #define	i40e_flush(hw) (void) rd32(hw, I40E_GLGEN_STAT)
186 
187 extern void i40e_debug(void *, u32, char *, ...);
188 extern boolean_t i40e_set_hw_bus_info(struct i40e_hw *);
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif /* _I40E_OSDEP_H */
195