1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017-2021 Intel Corporation
14 #include <rte_common.h>
15 #include <rte_memcpy.h>
16 #include <rte_memzone.h>
17 #include <rte_malloc.h>
18 #include <rte_byteorder.h>
19 #include <rte_cycles.h>
20 #include <rte_spinlock.h>
24 #ifndef __INTEL_NET_BASE_OSDEP__
25 #define __INTEL_NET_BASE_OSDEP__
40 #define __le16 uint16_t
43 #define __le32 uint32_t
46 #define __le64 uint64_t
49 #define __be16 uint16_t
52 #define __be32 uint32_t
55 #define __be64 uint64_t
58 /* Avoid macro redefinition warning on Windows */
59 #ifdef RTE_EXEC_ENV_WINDOWS
67 #define min(a, b) RTE_MIN(a, b)
68 #define max(a, b) RTE_MAX(a, b)
70 #define FIELD_SIZEOF(t, f) RTE_SIZEOF_FIELD(t, f)
71 #define ARRAY_SIZE(arr) RTE_DIM(arr)
73 #define CPU_TO_LE16(o) rte_cpu_to_le_16(o)
74 #define CPU_TO_LE32(s) rte_cpu_to_le_32(s)
75 #define CPU_TO_LE64(h) rte_cpu_to_le_64(h)
76 #define LE16_TO_CPU(a) rte_le_to_cpu_16(a)
77 #define LE32_TO_CPU(c) rte_le_to_cpu_32(c)
78 #define LE64_TO_CPU(k) rte_le_to_cpu_64(k)
80 #define CPU_TO_BE16(o) rte_cpu_to_be_16(o)
81 #define CPU_TO_BE32(o) rte_cpu_to_be_32(o)
82 #define CPU_TO_BE64(o) rte_cpu_to_be_64(o)
84 #define NTOHS(a) rte_be_to_cpu_16(a)
85 #define NTOHL(a) rte_be_to_cpu_32(a)
86 #define HTONS(a) rte_cpu_to_be_16(a)
87 #define HTONL(a) rte_cpu_to_be_32(a)
89 static __rte_always_inline uint32_t
90 readl(volatile void *addr)
92 return rte_le_to_cpu_32(rte_read32(addr));
95 static __rte_always_inline void
96 writel(uint32_t value, volatile void *addr)
98 rte_write32(rte_cpu_to_le_32(value), addr);
101 static __rte_always_inline void
102 writel_relaxed(uint32_t value, volatile void *addr)
104 rte_write32_relaxed(rte_cpu_to_le_32(value), addr);
107 static __rte_always_inline uint64_t
108 readq(volatile void *addr)
110 return rte_le_to_cpu_64(rte_read64(addr));
113 static __rte_always_inline void
114 writeq(uint64_t value, volatile void *addr)
116 rte_write64(rte_cpu_to_le_64(value), addr);
119 #define wr32(a, reg, value) writel((value), (a)->hw_addr + (reg))
120 #define rd32(a, reg) readl((a)->hw_addr + (reg))
121 #define wr64(a, reg, value) writeq((value), (a)->hw_addr + (reg))
122 #define rd64(a, reg) readq((a)->hw_addr + (reg))
124 #endif /* __INTEL_NET_BASE_OSDEP__ */
126 #define iavf_memset(a, b, c, d) memset((a), (b), (c))
127 #define iavf_memcpy(a, b, c, d) rte_memcpy((a), (b), (c))
129 #define iavf_usec_delay(x) rte_delay_us_sleep(x)
130 #define iavf_msec_delay(x) iavf_usec_delay(1000 * (x))
132 #define IAVF_PCI_REG_WRITE(reg, value) writel(value, reg)
133 #define IAVF_PCI_REG_WRITE_RELAXED(reg, value) writel_relaxed(value, reg)
135 #define IAVF_PCI_REG_WC_WRITE(reg, value) \
136 rte_write32_wc((rte_cpu_to_le_32(value)), reg)
137 #define IAVF_PCI_REG_WC_WRITE_RELAXED(reg, value) \
138 rte_write32_wc_relaxed((rte_cpu_to_le_32(value)), reg)
140 #define IAVF_READ_REG(hw, reg) rd32(hw, reg)
141 #define IAVF_WRITE_REG(hw, reg, value) wr32(hw, reg, value)
143 #define IAVF_WRITE_FLUSH(a) IAVF_READ_REG(a, IAVF_VFGEN_RSTAT)
145 extern int iavf_common_logger;
147 #define DEBUGOUT(S) rte_log(RTE_LOG_DEBUG, iavf_common_logger, S)
148 #define DEBUGOUT2(S, A...) rte_log(RTE_LOG_DEBUG, iavf_common_logger, S, ##A)
149 #define DEBUGFUNC(F) DEBUGOUT(F "\n")
151 #define iavf_debug(h, m, s, ...) \
153 if (((m) & (h)->debug_mask)) \
154 rte_log(RTE_LOG_DEBUG, iavf_common_logger, \
156 (h)->bus.device, (h)->bus.func, \
160 /* memory allocation tracking */
161 struct iavf_dma_mem {
168 struct iavf_virt_mem {
174 struct iavf_spinlock {
175 rte_spinlock_t spinlock;
178 #define iavf_allocate_dma_mem(h, m, unused, s, a) \
179 iavf_allocate_dma_mem_d(h, m, s, a)
180 #define iavf_free_dma_mem(h, m) iavf_free_dma_mem_d(h, m)
182 #define iavf_allocate_virt_mem(h, m, s) iavf_allocate_virt_mem_d(h, m, s)
183 #define iavf_free_virt_mem(h, m) iavf_free_virt_mem_d(h, m)
186 iavf_init_spinlock_d(struct iavf_spinlock *sp)
188 rte_spinlock_init(&sp->spinlock);
192 iavf_acquire_spinlock_d(struct iavf_spinlock *sp)
194 rte_spinlock_lock(&sp->spinlock);
198 iavf_release_spinlock_d(struct iavf_spinlock *sp)
200 rte_spinlock_unlock(&sp->spinlock);
204 iavf_destroy_spinlock_d(__rte_unused struct iavf_spinlock *sp)
208 #define iavf_init_spinlock(_sp) iavf_init_spinlock_d(_sp)
209 #define iavf_acquire_spinlock(_sp) iavf_acquire_spinlock_d(_sp)
210 #define iavf_release_spinlock(_sp) iavf_release_spinlock_d(_sp)
211 #define iavf_destroy_spinlock(_sp) iavf_destroy_spinlock_d(_sp)
213 #endif /* _IAVF_OSDEP_H_ */