Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2017-2021 Intel Corporation
3 : : */
4 : :
5 : : #ifndef _IAVF_OSDEP_H_
6 : : #define _IAVF_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_memzone.h>
18 : : #include <rte_malloc.h>
19 : : #include <rte_byteorder.h>
20 : : #include <rte_cycles.h>
21 : : #include <rte_spinlock.h>
22 : : #include <rte_log.h>
23 : : #include <rte_io.h>
24 : :
25 : : #ifndef __INTEL_NET_BASE_OSDEP__
26 : : #define __INTEL_NET_BASE_OSDEP__
27 : :
28 : : #define INLINE inline
29 : : #define STATIC static
30 : :
31 : : typedef uint8_t u8;
32 : : typedef int8_t s8;
33 : : typedef uint16_t u16;
34 : : typedef int16_t s16;
35 : : typedef uint32_t u32;
36 : : typedef int32_t s32;
37 : : typedef uint64_t u64;
38 : : typedef uint64_t s64;
39 : :
40 : : #ifndef __le16
41 : : #define __le16 uint16_t
42 : : #endif
43 : : #ifndef __le32
44 : : #define __le32 uint32_t
45 : : #endif
46 : : #ifndef __le64
47 : : #define __le64 uint64_t
48 : : #endif
49 : : #ifndef __be16
50 : : #define __be16 uint16_t
51 : : #endif
52 : : #ifndef __be32
53 : : #define __be32 uint32_t
54 : : #endif
55 : : #ifndef __be64
56 : : #define __be64 uint64_t
57 : : #endif
58 : :
59 : : /* Avoid macro redefinition warning on Windows */
60 : : #ifdef RTE_EXEC_ENV_WINDOWS
61 : : #ifdef min
62 : : #undef min
63 : : #endif
64 : : #ifdef max
65 : : #undef max
66 : : #endif
67 : : #endif
68 : : #define min(a, b) RTE_MIN(a, b)
69 : : #define max(a, b) RTE_MAX(a, b)
70 : :
71 : : #define FIELD_SIZEOF(t, f) RTE_SIZEOF_FIELD(t, f)
72 : : #define ARRAY_SIZE(arr) RTE_DIM(arr)
73 : :
74 : : #define CPU_TO_LE16(o) rte_cpu_to_le_16(o)
75 : : #define CPU_TO_LE32(s) rte_cpu_to_le_32(s)
76 : : #define CPU_TO_LE64(h) rte_cpu_to_le_64(h)
77 : : #define LE16_TO_CPU(a) rte_le_to_cpu_16(a)
78 : : #define LE32_TO_CPU(c) rte_le_to_cpu_32(c)
79 : : #define LE64_TO_CPU(k) rte_le_to_cpu_64(k)
80 : :
81 : : #define CPU_TO_BE16(o) rte_cpu_to_be_16(o)
82 : : #define CPU_TO_BE32(o) rte_cpu_to_be_32(o)
83 : : #define CPU_TO_BE64(o) rte_cpu_to_be_64(o)
84 : :
85 : : #define NTOHS(a) rte_be_to_cpu_16(a)
86 : : #define NTOHL(a) rte_be_to_cpu_32(a)
87 : : #define HTONS(a) rte_cpu_to_be_16(a)
88 : : #define HTONL(a) rte_cpu_to_be_32(a)
89 : :
90 : : static __rte_always_inline uint32_t
91 : : readl(volatile void *addr)
92 : : {
93 : : return rte_le_to_cpu_32(rte_read32(addr));
94 : : }
95 : :
96 : : static __rte_always_inline void
97 : : writel(uint32_t value, volatile void *addr)
98 : : {
99 : : rte_write32(rte_cpu_to_le_32(value), addr);
100 : 0 : }
101 : :
102 : : static __rte_always_inline void
103 : : writel_relaxed(uint32_t value, volatile void *addr)
104 : : {
105 : : rte_write32_relaxed(rte_cpu_to_le_32(value), addr);
106 : : }
107 : :
108 : : static __rte_always_inline uint64_t
109 : : readq(volatile void *addr)
110 : : {
111 : : return rte_le_to_cpu_64(rte_read64(addr));
112 : : }
113 : :
114 : : static __rte_always_inline void
115 : : writeq(uint64_t value, volatile void *addr)
116 : : {
117 : : rte_write64(rte_cpu_to_le_64(value), addr);
118 : : }
119 : :
120 : : #define wr32(a, reg, value) writel((value), (a)->hw_addr + (reg))
121 : : #define rd32(a, reg) readl((a)->hw_addr + (reg))
122 : : #define wr64(a, reg, value) writeq((value), (a)->hw_addr + (reg))
123 : : #define rd64(a, reg) readq((a)->hw_addr + (reg))
124 : :
125 : : #endif /* __INTEL_NET_BASE_OSDEP__ */
126 : :
127 : : #define iavf_memset(a, b, c, d) memset((a), (b), (c))
128 : : #define iavf_memcpy(a, b, c, d) memcpy((a), (b), (c))
129 : :
130 : : #define iavf_usec_delay(x) rte_delay_us_sleep(x)
131 : : #define iavf_msec_delay(x) iavf_usec_delay(1000 * (x))
132 : :
133 : : #define IAVF_PCI_REG_WRITE(reg, value) writel(value, reg)
134 : : #define IAVF_PCI_REG_WRITE_RELAXED(reg, value) writel_relaxed(value, reg)
135 : :
136 : : #define IAVF_PCI_REG_WC_WRITE(reg, value) \
137 : : rte_write32_wc((rte_cpu_to_le_32(value)), reg)
138 : : #define IAVF_PCI_REG_WC_WRITE_RELAXED(reg, value) \
139 : : rte_write32_wc_relaxed((rte_cpu_to_le_32(value)), reg)
140 : :
141 : : #define IAVF_READ_REG(hw, reg) rd32(hw, reg)
142 : : #define IAVF_WRITE_REG(hw, reg, value) wr32(hw, reg, value)
143 : :
144 : : #define IAVF_WRITE_FLUSH(a) IAVF_READ_REG(a, IAVF_VFGEN_RSTAT)
145 : :
146 : : extern int iavf_common_logger;
147 : : #define RTE_LOGTYPE_IAVF_COMMON iavf_common_logger
148 : :
149 : : #define DEBUGOUT(S, ...) RTE_LOG(DEBUG, IAVF_COMMON, S, ## __VA_ARGS__)
150 : : #define DEBUGOUT2(S, ...) DEBUGOUT(S, ## __VA_ARGS__)
151 : : #define DEBUGFUNC(F) DEBUGOUT(F "\n")
152 : :
153 : : #define iavf_debug(h, m, s, ...) \
154 : : do { \
155 : : if (((m) & (h)->debug_mask)) \
156 : : DEBUGOUT("iavf %02x.%x " s, \
157 : : (h)->bus.device, (h)->bus.func, \
158 : : ##__VA_ARGS__); \
159 : : } while (0)
160 : :
161 : : /* memory allocation tracking */
162 : : struct __rte_packed_begin iavf_dma_mem {
163 : : void *va;
164 : : u64 pa;
165 : : u32 size;
166 : : const void *zone;
167 : : } __rte_packed_end;
168 : :
169 : : struct __rte_packed_begin iavf_virt_mem {
170 : : void *va;
171 : : u32 size;
172 : : } __rte_packed_end;
173 : :
174 : : #define iavf_allocate_dma_mem(h, m, unused, s, a) \
175 : : iavf_allocate_dma_mem_d(h, m, s, a)
176 : : #define iavf_free_dma_mem(h, m) iavf_free_dma_mem_d(h, m)
177 : :
178 : : #define iavf_allocate_virt_mem(h, m, s) iavf_allocate_virt_mem_d(h, m, s)
179 : : #define iavf_free_virt_mem(h, m) iavf_free_virt_mem_d(h, m)
180 : :
181 : : /* SW spinlock */
182 : : struct iavf_spinlock {
183 : : rte_spinlock_t spinlock;
184 : : };
185 : :
186 : : #define iavf_init_spinlock(sp) rte_spinlock_init(&(sp)->spinlock)
187 : : #define iavf_acquire_spinlock(sp) rte_spinlock_lock(&(sp)->spinlock)
188 : : #define iavf_release_spinlock(sp) rte_spinlock_unlock(&(sp)->spinlock)
189 : : #define iavf_destroy_spinlock(sp) RTE_SET_USED(sp)
190 : :
191 : : #endif /* _IAVF_OSDEP_H_ */
|