Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2001-2020 Intel Corporation
3 : : */
4 : :
5 : : #ifndef _I40E_OSDEP_H_
6 : : #define _I40E_OSDEP_H_
7 : :
8 : : /* File containing OS dependencies for base code */
9 : :
10 : : #include <string.h>
11 : : #include <stdint.h>
12 : : #include <stdbool.h>
13 : : #include <stdio.h>
14 : : #include <stdarg.h>
15 : :
16 : : #include <rte_common.h>
17 : : #include <rte_byteorder.h>
18 : : #include <rte_cycles.h>
19 : : #include <rte_spinlock.h>
20 : : #include <rte_log.h>
21 : : #include <rte_io.h>
22 : :
23 : : #include "i40e_logs.h"
24 : : #include "i40e_status.h"
25 : :
26 : : #define INLINE inline
27 : : #define STATIC static
28 : :
29 : : typedef uint8_t u8;
30 : : typedef int8_t s8;
31 : : typedef uint16_t u16;
32 : : typedef uint32_t u32;
33 : : typedef int32_t s32;
34 : : typedef uint64_t u64;
35 : :
36 : : typedef enum i40e_status_code i40e_status;
37 : : #define __iomem
38 : : #define hw_dbg(hw, S, ...) do {} while (0)
39 : : #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
40 : : #define lower_32_bits(n) ((u32)(n))
41 : : #define low_16_bits(x) ((x) & 0xFFFF)
42 : : #define high_16_bits(x) (((x) & 0xFFFF0000) >> 16)
43 : :
44 : : #ifndef ETH_ADDR_LEN
45 : : #define ETH_ADDR_LEN 6
46 : : #endif
47 : :
48 : : #ifndef __le16
49 : : #define __le16 uint16_t
50 : : #endif
51 : : #ifndef __le32
52 : : #define __le32 uint32_t
53 : : #endif
54 : : #ifndef __le64
55 : : #define __le64 uint64_t
56 : : #endif
57 : : #ifndef __be16
58 : : #define __be16 uint16_t
59 : : #endif
60 : : #ifndef __be32
61 : : #define __be32 uint32_t
62 : : #endif
63 : : #ifndef __be64
64 : : #define __be64 uint64_t
65 : : #endif
66 : :
67 : : #define FALSE 0
68 : : #define TRUE 1
69 : : #define false 0
70 : : #define true 1
71 : :
72 : : /* Avoid macro redefinition warning on Windows */
73 : : #ifdef RTE_EXEC_ENV_WINDOWS
74 : : #ifdef min
75 : : #undef min
76 : : #endif
77 : : #ifdef max
78 : : #undef max
79 : : #endif
80 : : #endif
81 : : #define min(a,b) RTE_MIN(a,b)
82 : : #define max(a,b) RTE_MAX(a,b)
83 : :
84 : : #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
85 : :
86 : : #define DEBUGOUT(S, ...) RTE_LOG(DEBUG, I40E_DRIVER, "%s(): " S, __func__, ## __VA_ARGS__)
87 : : #define DEBUGOUT1 DEBUGOUT
88 : :
89 : : #define DEBUGFUNC(F) DEBUGOUT(F "\n")
90 : : #define DEBUGOUT2 DEBUGOUT1
91 : : #define DEBUGOUT3 DEBUGOUT2
92 : : #define DEBUGOUT6 DEBUGOUT3
93 : : #define DEBUGOUT7 DEBUGOUT6
94 : :
95 : : #define i40e_debug(h, m, s, ...) \
96 : : do { \
97 : : if (((m) & (h)->debug_mask)) \
98 : : DEBUGOUT("i40e %02x.%x " s, \
99 : : (h)->bus.device, (h)->bus.func, \
100 : : ##__VA_ARGS__); \
101 : : } while (0)
102 : :
103 : : /* AQ commands based interfaces of i40e_read_rx_ctl() and i40e_write_rx_ctl()
104 : : * are required for reading/writing below registers, as reading/writing it
105 : : * directly may not function correctly if the device is under heavy small
106 : : * packet traffic. Note that those interfaces are available from FVL5 and not
107 : : * suitable before the AdminQ is ready during initialization.
108 : : *
109 : : * I40E_PFQF_CTL_0
110 : : * I40E_PFQF_HENA
111 : : * I40E_PFQF_FDALLOC
112 : : * I40E_PFQF_HREGION
113 : : * I40E_PFLAN_QALLOC
114 : : * I40E_VPQF_CTL
115 : : * I40E_VFQF_HENA
116 : : * I40E_VFQF_HREGION
117 : : * I40E_VSIQF_CTL
118 : : * I40E_VSILAN_QBASE
119 : : * I40E_VSILAN_QTABLE
120 : : * I40E_VSIQF_TCREGION
121 : : * I40E_PFQF_HKEY
122 : : * I40E_VFQF_HKEY
123 : : * I40E_PRTQF_CTL_0
124 : : * I40E_GLFCOE_RCTL
125 : : * I40E_GLFCOE_RSOF
126 : : * I40E_GLQF_CTL
127 : : * I40E_GLQF_SWAP
128 : : * I40E_GLQF_HASH_MSK
129 : : * I40E_GLQF_HASH_INSET
130 : : * I40E_GLQF_HSYM
131 : : * I40E_GLQF_FC_MSK
132 : : * I40E_GLQF_FC_INSET
133 : : * I40E_GLQF_FD_MSK
134 : : * I40E_PRTQF_FD_INSET
135 : : * I40E_PRTQF_FD_FLXINSET
136 : : * I40E_PRTQF_FD_MSK
137 : : */
138 : :
139 : : #define I40E_PCI_REG(reg) rte_read32(reg)
140 : : #define I40E_PCI_REG_ADDR(a, reg) \
141 : : ((volatile uint32_t *)((char *)(a)->hw_addr + (reg)))
142 : : static inline uint32_t i40e_read_addr(volatile void *addr)
143 : : {
144 : 0 : return rte_le_to_cpu_32(I40E_PCI_REG(addr));
145 : : }
146 : :
147 : : #define I40E_PCI_REG64(reg) rte_read64(reg)
148 : : #define I40E_PCI_REG64_ADDR(a, reg) \
149 : : ((volatile uint64_t *)((char *)(a)->hw_addr + (reg)))
150 : : static inline uint64_t i40e_read64_addr(volatile void *addr)
151 : : {
152 : : return rte_le_to_cpu_64(I40E_PCI_REG64(addr));
153 : : }
154 : :
155 : : #define I40E_PCI_REG_WRITE(reg, value) \
156 : : rte_write32((rte_cpu_to_le_32(value)), reg)
157 : : #define I40E_PCI_REG_WRITE_RELAXED(reg, value) \
158 : : rte_write32_relaxed((rte_cpu_to_le_32(value)), reg)
159 : :
160 : : #define I40E_PCI_REG_WC_WRITE(reg, value) \
161 : : rte_write32_wc((rte_cpu_to_le_32(value)), reg)
162 : : #define I40E_PCI_REG_WC_WRITE_RELAXED(reg, value) \
163 : : rte_write32_wc_relaxed((rte_cpu_to_le_32(value)), reg)
164 : :
165 : : #define I40E_WRITE_FLUSH(a) I40E_READ_REG(a, I40E_GLGEN_STAT)
166 : :
167 : : #define I40E_READ_REG(hw, reg) i40e_read_addr(I40E_PCI_REG_ADDR((hw), (reg)))
168 : : #define I40E_WRITE_REG(hw, reg, value) \
169 : : I40E_PCI_REG_WRITE(I40E_PCI_REG_ADDR((hw), (reg)), (value))
170 : :
171 : : #define I40E_READ_REG64(hw, reg) i40e_read64_addr(I40E_PCI_REG64_ADDR((hw), (reg)))
172 : :
173 : : #define rd32(a, reg) i40e_read_addr(I40E_PCI_REG_ADDR((a), (reg)))
174 : : #define wr32(a, reg, value) \
175 : : I40E_PCI_REG_WRITE(I40E_PCI_REG_ADDR((a), (reg)), (value))
176 : : #define flush(a) i40e_read_addr(I40E_PCI_REG_ADDR((a), (I40E_GLGEN_STAT)))
177 : :
178 : : #define ARRAY_SIZE(arr) RTE_DIM(arr)
179 : :
180 : : /* memory allocation tracking */
181 : : struct __rte_packed_begin i40e_dma_mem {
182 : : void *va;
183 : : u64 pa;
184 : : u32 size;
185 : : const void *zone;
186 : : } __rte_packed_end;
187 : :
188 : : #define i40e_allocate_dma_mem(h, m, mt, s, a) \
189 : : i40e_allocate_dma_mem_d(h, m, mt, s, a)
190 : : #define i40e_free_dma_mem(h, m) i40e_free_dma_mem_d(h, m)
191 : :
192 : : struct __rte_packed_begin i40e_virt_mem {
193 : : void *va;
194 : : u32 size;
195 : : } __rte_packed_end;
196 : :
197 : : #define i40e_allocate_virt_mem(h, m, s) i40e_allocate_virt_mem_d(h, m, s)
198 : : #define i40e_free_virt_mem(h, m) i40e_free_virt_mem_d(h, m)
199 : :
200 : : #define CPU_TO_LE16(o) rte_cpu_to_le_16(o)
201 : : #define CPU_TO_LE32(s) rte_cpu_to_le_32(s)
202 : : #define CPU_TO_LE64(h) rte_cpu_to_le_64(h)
203 : : #define LE16_TO_CPU(a) rte_le_to_cpu_16(a)
204 : : #define LE32_TO_CPU(c) rte_le_to_cpu_32(c)
205 : : #define LE64_TO_CPU(k) rte_le_to_cpu_64(k)
206 : :
207 : : #define cpu_to_le16(o) rte_cpu_to_le_16(o)
208 : : #define cpu_to_le32(s) rte_cpu_to_le_32(s)
209 : : #define cpu_to_le64(h) rte_cpu_to_le_64(h)
210 : : #define le16_to_cpu(a) rte_le_to_cpu_16(a)
211 : : #define le32_to_cpu(c) rte_le_to_cpu_32(c)
212 : : #define le64_to_cpu(k) rte_le_to_cpu_64(k)
213 : :
214 : : /* SW spinlock */
215 : : struct i40e_spinlock {
216 : : rte_spinlock_t spinlock;
217 : : };
218 : :
219 : : #define i40e_init_spinlock(sp) rte_spinlock_init(&(sp)->spinlock)
220 : : #define i40e_acquire_spinlock(sp) rte_spinlock_lock(&(sp)->spinlock)
221 : : #define i40e_release_spinlock(sp) rte_spinlock_unlock(&(sp)->spinlock)
222 : : #define i40e_destroy_spinlock(sp) RTE_SET_USED(sp)
223 : :
224 : : #define I40E_NTOHS(a) rte_be_to_cpu_16(a)
225 : : #define I40E_NTOHL(a) rte_be_to_cpu_32(a)
226 : : #define I40E_HTONS(a) rte_cpu_to_be_16(a)
227 : : #define I40E_HTONL(a) rte_cpu_to_be_32(a)
228 : :
229 : : #define i40e_memset(a, b, c, d) memset((a), (b), (c))
230 : : #define i40e_memcpy(a, b, c, d) memcpy((a), (b), (c))
231 : :
232 : : #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
233 : : #define DELAY(x) rte_delay_us_sleep(x)
234 : : #define i40e_usec_delay(x) DELAY(x)
235 : : #define i40e_msec_delay(x) DELAY(1000 * (x))
236 : : #define udelay(x) DELAY(x)
237 : : #define msleep(x) DELAY(1000*(x))
238 : : #define usleep_range(min, max) msleep(DIV_ROUND_UP(min, 1000))
239 : :
240 : : #endif /* _I40E_OSDEP_H_ */
|