Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2001-2024 Intel Corporation
3 : : */
4 : :
5 : : #ifndef _IXGBE_OS_H_
6 : : #define _IXGBE_OS_H_
7 : :
8 : : #include <pthread.h>
9 : : #include <string.h>
10 : : #include <stdint.h>
11 : : #include <stdio.h>
12 : : #include <stdarg.h>
13 : : #include <stdbool.h>
14 : : #include <rte_common.h>
15 : : #include <rte_debug.h>
16 : : #include <rte_cycles.h>
17 : : #include <rte_log.h>
18 : : #include <rte_byteorder.h>
19 : : #include <rte_io.h>
20 : : #include <rte_ip.h>
21 : :
22 : : #include "../ixgbe_logs.h"
23 : : #include "../ixgbe_bypass_defines.h"
24 : :
25 : : #ifndef IPPROTO_SCTP
26 : : #define IPPROTO_SCTP 132
27 : : #endif
28 : :
29 : : #define ASSERT(x) if(!(x)) rte_panic("IXGBE: x")
30 : :
31 : : #define DELAY(x) rte_delay_us_sleep(x)
32 : : #define usec_delay(x) DELAY(x)
33 : : #define msec_delay(x) DELAY(1000*(x))
34 : :
35 : : #define DEBUGFUNC(F) DEBUGOUT(F "\n");
36 : : #define DEBUGOUT(S, ...) RTE_LOG(DEBUG, IXGBE_DRIVER, "%s(): " S, __func__, ## __VA_ARGS__)
37 : : #define DEBUGOUT1(S, ...) DEBUGOUT(S, ##__VA_ARGS__)
38 : : #define DEBUGOUT2(S, ...) DEBUGOUT(S, ##__VA_ARGS__)
39 : : #define DEBUGOUT3(S, ...) DEBUGOUT(S, ##__VA_ARGS__)
40 : : #define DEBUGOUT6(S, ...) DEBUGOUT(S, ##__VA_ARGS__)
41 : : #define DEBUGOUT7(S, ...) DEBUGOUT(S, ##__VA_ARGS__)
42 : :
43 : : #define ERROR_REPORT1(e, S, ...) DEBUGOUT(S, ##__VA_ARGS__)
44 : : #define ERROR_REPORT2(e, S, ...) DEBUGOUT(S, ##__VA_ARGS__)
45 : : #define ERROR_REPORT3(e, S, ...) DEBUGOUT(S, ##__VA_ARGS__)
46 : :
47 : : #define FALSE 0
48 : : #define TRUE 1
49 : :
50 : : #define false 0
51 : : #define true 1
52 : : #ifndef RTE_EXEC_ENV_WINDOWS
53 : : #define min(a,b) RTE_MIN(a,b)
54 : : #endif
55 : :
56 : : #define EWARN(hw, S, ...) DEBUGOUT1(S, ##__VA_ARGS__)
57 : :
58 : : /* Bunch of defines for shared code bogosity */
59 : : #ifndef UNREFERENCED_PARAMETER
60 : : #define UNREFERENCED_PARAMETER(_p)
61 : : #endif
62 : : #define UNREFERENCED_1PARAMETER(_p)
63 : : #define UNREFERENCED_2PARAMETER(_p, _q)
64 : : #define UNREFERENCED_3PARAMETER(_p, _q, _r)
65 : : #define UNREFERENCED_4PARAMETER(_p, _q, _r, _s)
66 : : #define UNREFERENCED_5PARAMETER(_p, _q, _r, _s, _t)
67 : :
68 : : /* Shared code error reporting */
69 : : enum {
70 : : IXGBE_ERROR_SOFTWARE,
71 : : IXGBE_ERROR_POLLING,
72 : : IXGBE_ERROR_INVALID_STATE,
73 : : IXGBE_ERROR_UNSUPPORTED,
74 : : IXGBE_ERROR_ARGUMENT,
75 : : IXGBE_ERROR_CAUTION,
76 : : };
77 : :
78 : : #define STATIC static
79 : : #define IXGBE_NTOHL(_i) rte_be_to_cpu_32(_i)
80 : : #define IXGBE_NTOHS(_i) rte_be_to_cpu_16(_i)
81 : : #define IXGBE_CPU_TO_LE16(_i) rte_cpu_to_le_16(_i)
82 : : #define IXGBE_CPU_TO_LE32(_i) rte_cpu_to_le_32(_i)
83 : : #define IXGBE_LE16_TO_CPU(_i) rte_le_to_cpu_16(_i)
84 : : #define IXGBE_LE32_TO_CPU(_i) rte_le_to_cpu_32(_i)
85 : : #define IXGBE_LE64_TO_CPU(_i) rte_le_to_cpu_64(_i)
86 : : #define IXGBE_LE32_TO_CPUS(_i) rte_le_to_cpu_32(_i)
87 : : #define IXGBE_CPU_TO_BE16(_i) rte_cpu_to_be_16(_i)
88 : : #define IXGBE_CPU_TO_BE32(_i) rte_cpu_to_be_32(_i)
89 : : #define IXGBE_BE32_TO_CPU(_i) rte_be_to_cpu_32(_i)
90 : :
91 : : typedef uint8_t u8;
92 : : typedef int8_t s8;
93 : : typedef uint16_t u16;
94 : : typedef int16_t s16;
95 : : typedef uint32_t u32;
96 : : typedef int32_t s32;
97 : : typedef uint64_t u64;
98 : :
99 : : #define mb() rte_mb()
100 : : #define wmb() rte_wmb()
101 : : #define rmb() rte_rmb()
102 : :
103 : : #define IOMEM
104 : :
105 : : #define prefetch(x) rte_prefetch0(x)
106 : :
107 : : #define IXGBE_PCI_REG(reg) rte_read32(reg)
108 : :
109 : : static inline uint32_t ixgbe_read_addr(volatile void* addr)
110 : : {
111 : 0 : return rte_le_to_cpu_32(IXGBE_PCI_REG(addr));
112 : : }
113 : :
114 : : #define IXGBE_PCI_REG_WRITE(reg, value) \
115 : : rte_write32((rte_cpu_to_le_32(value)), reg)
116 : :
117 : : #define IXGBE_PCI_REG_WRITE_RELAXED(reg, value) \
118 : : rte_write32_relaxed((rte_cpu_to_le_32(value)), reg)
119 : :
120 : : #define IXGBE_PCI_REG_WC_WRITE(reg, value) \
121 : : rte_write32_wc((rte_cpu_to_le_32(value)), reg)
122 : :
123 : : #define IXGBE_PCI_REG_WC_WRITE_RELAXED(reg, value) \
124 : : rte_write32_wc_relaxed((rte_cpu_to_le_32(value)), reg)
125 : :
126 : : #define IXGBE_PCI_REG_ADDR(hw, reg) \
127 : : ((volatile uint32_t *)((char *)(hw)->hw_addr + (reg)))
128 : :
129 : : #define IXGBE_PCI_REG_ARRAY_ADDR(hw, reg, index) \
130 : : IXGBE_PCI_REG_ADDR((hw), (reg) + ((index) << 2))
131 : :
132 : : /* Not implemented !! */
133 : : #define IXGBE_READ_PCIE_WORD(hw, reg) 0
134 : : #define IXGBE_WRITE_PCIE_WORD(hw, reg, value) do { } while(0)
135 : :
136 : : #define IXGBE_WRITE_FLUSH(a) IXGBE_READ_REG(a, IXGBE_STATUS)
137 : :
138 : : #define IXGBE_READ_REG(hw, reg) \
139 : : ixgbe_read_addr(IXGBE_PCI_REG_ADDR((hw), (reg)))
140 : :
141 : : #define IXGBE_WRITE_REG(hw, reg, value) \
142 : : IXGBE_PCI_REG_WRITE(IXGBE_PCI_REG_ADDR((hw), (reg)), (value))
143 : :
144 : : #define IXGBE_READ_REG_ARRAY(hw, reg, index) \
145 : : IXGBE_PCI_REG(IXGBE_PCI_REG_ARRAY_ADDR((hw), (reg), (index)))
146 : :
147 : : #define IXGBE_WRITE_REG_ARRAY(hw, reg, index, value) \
148 : : IXGBE_PCI_REG_WRITE(IXGBE_PCI_REG_ARRAY_ADDR((hw), (reg), (index)), (value))
149 : :
150 : : #define IXGBE_WRITE_REG_THEN_POLL_MASK(hw, reg, val, mask, poll_ms) \
151 : : do { \
152 : : uint32_t cnt = poll_ms; \
153 : : IXGBE_WRITE_REG(hw, (reg), (val)); \
154 : : while (((IXGBE_READ_REG(hw, (reg))) & (mask)) && (cnt--)) \
155 : : rte_delay_ms(1); \
156 : : } while (0)
157 : :
158 : : struct ixgbe_hw;
159 : : struct ixgbe_lock {
160 : : pthread_mutex_t mutex;
161 : : };
162 : :
163 : : void *ixgbe_calloc(struct ixgbe_hw *hw, size_t count, size_t size);
164 : : void *ixgbe_malloc(struct ixgbe_hw *hw, size_t size);
165 : : void ixgbe_free(struct ixgbe_hw *hw, void *addr);
166 : :
167 : : void ixgbe_init_lock(struct ixgbe_lock *lock);
168 : : void ixgbe_destroy_lock(struct ixgbe_lock *lock);
169 : : void ixgbe_acquire_lock(struct ixgbe_lock *lock);
170 : : void ixgbe_release_lock(struct ixgbe_lock *lock);
171 : :
172 : : #endif /* _IXGBE_OS_H_ */
|