1 /******************************************************************************
2
3 Copyright (c) 2013-2015, Intel Corporation
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32 ******************************************************************************/
33 /*$FreeBSD: head/sys/dev/ixl/i40e_osdep.h 284049 2015-06-05 22:52:42Z jfv $*/
34
35 #ifndef _I40E_OSDEP_H_
36 #define _I40E_OSDEP_H_
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 #include <sys/types.h>
43 #include <sys/conf.h>
44 #include <sys/debug.h>
45 #include <sys/stropts.h>
46 #include <sys/stream.h>
47 #include <sys/strsun.h>
48 #include <sys/strlog.h>
49 #include <sys/kmem.h>
50 #include <sys/stat.h>
51 #include <sys/kstat.h>
52 #include <sys/modctl.h>
53 #include <sys/errno.h>
54 #include <sys/dlpi.h>
55 #include <sys/mac_provider.h>
56 #include <sys/mac_ether.h>
57 #include <sys/vlan.h>
58 #include <sys/ddi.h>
59 #include <sys/sunddi.h>
60 #include <sys/pci.h>
61 #include <sys/pci_cap.h>
62 #include <sys/pcie.h>
63 #include <sys/sdt.h>
64 #include <sys/ethernet.h>
65 #include <sys/pattr.h>
66 #include <sys/strsubr.h>
67 #include <sys/netlb.h>
68 #include <sys/random.h>
69 #include <inet/common.h>
70 #include <inet/tcp.h>
71 #include <inet/ip.h>
72 #include <inet/mi.h>
73 #include <inet/nd.h>
74 #include <sys/bitmap.h>
75 #include <sys/ddifm.h>
76 #include <sys/fm/protocol.h>
77 #include <sys/fm/util.h>
78 #include <sys/disp.h>
79 #include <sys/fm/io/ddi.h>
80
81
82 /*
83 * On the off chance we need to hack Intel-written code, define I40E_ILLUMOS
84 * here so we can have #ifdef I40E_ILLUMOS in (hopefully) very rare case.
85 */
86 #define I40E_ILLUMOS 1
87
88 #define i40e_usec_delay(x) drv_usecwait(x)
89 #define i40e_msec_delay(x) drv_usecwait(1000 * (x))
90
91 /* XXX KEBE ASKS Better alternatives to printf()? */
92 #define DBG 0
93 #define MSGOUT(S, A, B) printf(S "\n", A, B)
94 #define DEBUGFUNC(F) DEBUGOUT(F);
95 #if DBG
96 #define DEBUGOUT(S) printf(S "\n")
97 #define DEBUGOUT1(S,A) printf(S "\n",A)
98 #define DEBUGOUT2(S,A,B) printf(S "\n",A,B)
99 #define DEBUGOUT3(S,A,B,C) printf(S "\n",A,B,C)
100 #define DEBUGOUT7(S,A,B,C,D,E,F,G) printf(S "\n",A,B,C,D,E,F,G)
101 #else
102 #define DEBUGOUT(S)
103 #define DEBUGOUT1(S,A)
104 #define DEBUGOUT2(S,A,B)
105 #define DEBUGOUT3(S,A,B,C)
106 #define DEBUGOUT6(S,A,B,C,D,E,F)
107 #define DEBUGOUT7(S,A,B,C,D,E,F,G)
108 #endif
109
110 #define UNREFERENCED_XPARAMETER
111 #define UNREFERENCED_PARAMETER(_p)
112 #define UNREFERENCED_1PARAMETER(_p)
113 #define UNREFERENCED_2PARAMETER(_p, _q)
114 #define UNREFERENCED_3PARAMETER(_p, _q, _r)
115 #define UNREFERENCED_4PARAMETER(_p, _q, _r, _s)
116
117 #define STATIC static
118 #define INLINE inline
119
120 #define FALSE B_FALSE
121 #define false B_FALSE /* shared code requires this */
122 #define TRUE B_TRUE
123 #define true B_TRUE
124 #define CMD_MEM_WRT_INVALIDATE 0x0010 /* BIT_4 */
125 #define PCI_COMMAND_REGISTER 0x04 /* stolen from ixgbe_osdep.h */
126
127 /* XXX KEBE ASKS --> best implementations of bcopy? memcpy? memset? */
128 #define i40e_memset(a, b, c, d) memset((a), (b), (c))
129 #define i40e_memcpy(a, b, c, d) bcopy((b), (a), (c))
130
131 /* illumos LE_XX() macros do these little-to-native/native-to-little ops. */
132 #define CPU_TO_LE16(o) LE_16(o)
133 #define CPU_TO_LE32(s) LE_32(s)
134 #define CPU_TO_LE64(h) LE_64(h)
135 #define LE16_TO_CPU(a) LE_16(a)
136 #define LE32_TO_CPU(c) LE_32(c)
137 #define LE64_TO_CPU(k) LE_64(k)
138
139 #define I40E_NTOHS(a) ntohs(a)
140 #define I40E_NTOHL(a) ntohl(a)
141 #define I40E_HTONS(a) htons(a)
142 #define I40E_HTONL(a) htonl(a)
143
144 #define FIELD_SIZEOF(x, y) (sizeof(((x*)0)->y))
145
146 #define BIT(a) (1UL << (a))
147 #define BIT_ULL(a) (1ULL << (a))
148
149 typedef boolean_t bool;
150
151 typedef uint8_t u8;
152 typedef int8_t s8;
153 typedef uint16_t u16;
154 typedef int16_t s16;
155 typedef uint32_t u32;
156 typedef int32_t s32;
157 typedef uint64_t u64;
158
159 /* long string relief */
160 typedef enum i40e_status_code i40e_status;
161
162 #define __le16 u16
163 #define __le32 u32
164 #define __le64 u64
165 #define __be16 u16
166 #define __be32 u32
167 #define __be64 u64
168
169 /* SW spinlock */
170 struct i40e_spinlock {
171 /* struct mtx mutex; */
172 kmutex_t mutex;
173 };
174
175 #if defined(__amd64__) || defined(i386)
176 /* NOTE: According to asm/cpu.h -> This is an SSE extension. Be careful. */
177 #define prefetch(x) prefetch_read_many(x)
178 #else
179 #define prefetch(x)
180 #endif
181
182 struct i40e_osdep {
183 ddi_acc_handle_t reg_handle;
184 ddi_acc_handle_t cfg_handle;
185 struct i40e_s *i40e;
186 };
187
188 struct i40e_hw; /* forward decl */
189 #define OS_DEP(hw) ((struct i40e_osdep *)((hw)->back))
190 /*
191 u16 i40e_read_pci_cfg(struct i40e_hw *, u32);
192 void i40e_write_pci_cfg(struct i40e_hw *, u32, u16);
193 */
194 #define i40e_read_pci_cfg(hw, reg) \
195 (pci_config_get16(OS_DEP(hw)->cfg_handle, (reg)))
196 #define i40e_write_pci_cfg(hw, reg, value) \
197 (pci_config_put16(OS_DEP(hw)->cfg_handle, (reg), (value)))
198
199 /* wr32/rd32 are peppered throughout the Intel-written code. */
200 #define wr32(hw, reg, value) \
201 ddi_put32(OS_DEP(hw)->reg_handle, \
202 (uint32_t *)((uintptr_t)(hw)->hw_addr + (reg)), (value))
203 #define rd32(hw, reg) \
204 ddi_get32(OS_DEP(hw)->reg_handle, \
205 (uint32_t *)((uintptr_t)(hw)->hw_addr + (reg)))
206
207 /*
208 * I40E_GLGEN_STAT is only for physical function, but that's all we do for
209 * now.
210 */
211 #define i40e_flush(hw) (void) rd32(hw, I40E_GLGEN_STAT)
212
213
214 /* #define i40e_debug(h, m, s, ...) i40e_debug_d(h, m, s, ##__VA_ARGS__) */
215 /* extern void i40e_debug_d(void *hw, u32 mask, char *fmt_str, ...); */
216 extern void i40e_debug(void *, u32, char *, ...);
217 extern boolean_t i40e_set_hw_bus_info(struct i40e_hw *);
218
219 struct i40e_virt_mem {
220 void *va;
221 u32 size;
222 };
223
224 struct i40e_dma_mem {
225 void *va; /* Virtual address. */
226 u64 pa; /* Physical (DMA/Hardware) address. */
227 size_t size; /* Buffer size. */
228
229 /* Illumos DDI data. */
230 ddi_acc_handle_t acc_handle; /* Data access handle */
231 ddi_dma_handle_t dma_handle; /* DMA handle */
232
233 int nseg;
234 int flags;
235 };
236
237 /*
238 ** This hardware supports either 16 or 32 byte rx descriptors
239 ** we default here to the larger size.
240 */
241 #define i40e_rx_desc i40e_32byte_rx_desc
242
243 /*
244 * XXX KEBE SAYS WE MAY NEED DEFS FOR:
245 *
246 * void rd32_osdep(struct i40e_osdep *osdep, uint32_t reg)
247 * void wr32_osdep(struct i40e_osdep *osdep, uint32_t reg, uint32_t value)
248 * void i40e_flush_osdep(struct i40e_osdep *)
249 * rd64(a, reg)
250 * wr64(a, reg, value)
251 * i40e_flush()
252 */
253
254 #ifdef __cplusplus
255 }
256 #endif
257
258 #endif /* _I40E_OSDEP_H_ */