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