Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #ifndef _ROC_PLATFORM_H_
6 : : #define _ROC_PLATFORM_H_
7 : :
8 : : #include <rte_compat.h>
9 : : #include <rte_alarm.h>
10 : : #include <rte_bitmap.h>
11 : : #include <bus_pci_driver.h>
12 : : #include <rte_byteorder.h>
13 : : #include <rte_common.h>
14 : : #include <rte_cycles.h>
15 : : #include <rte_ether.h>
16 : : #include <rte_interrupts.h>
17 : : #include <rte_io.h>
18 : : #include <rte_lcore.h>
19 : : #include <rte_log.h>
20 : : #include <rte_malloc.h>
21 : : #include <rte_memzone.h>
22 : : #include <rte_pci.h>
23 : : #include <rte_seqcount.h>
24 : : #include <rte_spinlock.h>
25 : : #include <rte_string_fns.h>
26 : : #include <rte_tailq.h>
27 : : #include <rte_telemetry.h>
28 : :
29 : : #include "eal_filesystem.h"
30 : :
31 : : #include "roc_bits.h"
32 : :
33 : : #if defined(__ARM_FEATURE_SVE)
34 : : #define PLT_CPU_FEATURE_PREAMBLE \
35 : : ".arch_extension crc\n" \
36 : : ".arch_extension lse\n" \
37 : : ".arch_extension sve\n"
38 : : #else
39 : : #define PLT_CPU_FEATURE_PREAMBLE \
40 : : ".arch_extension crc\n" \
41 : : ".arch_extension lse\n"
42 : : #endif
43 : :
44 : : #define PLT_ASSERT RTE_ASSERT
45 : : #define PLT_VERIFY RTE_VERIFY
46 : : #define PLT_MEMZONE_NAMESIZE RTE_MEMZONE_NAMESIZE
47 : : #define PLT_PTR_ADD RTE_PTR_ADD
48 : : #define PLT_PTR_SUB RTE_PTR_SUB
49 : : #define PLT_PTR_DIFF RTE_PTR_DIFF
50 : : #define PLT_MAX_RXTX_INTR_VEC_ID RTE_MAX_RXTX_INTR_VEC_ID
51 : : #define PLT_INTR_VEC_RXTX_OFFSET RTE_INTR_VEC_RXTX_OFFSET
52 : : #define PLT_MIN RTE_MIN
53 : : #define PLT_MAX RTE_MAX
54 : : #define PLT_DIM RTE_DIM
55 : : #define PLT_SET_USED RTE_SET_USED
56 : : #define PLT_SWAP RTE_SWAP
57 : : #define PLT_STATIC_ASSERT(s) _Static_assert(s, #s)
58 : : #define PLT_ALIGN RTE_ALIGN
59 : : #define PLT_ALIGN_MUL_CEIL RTE_ALIGN_MUL_CEIL
60 : : #define PLT_MODEL_MZ_NAME "roc_model_mz"
61 : : #define PLT_CACHE_LINE_SIZE RTE_CACHE_LINE_SIZE
62 : : #define BITMASK_ULL GENMASK_ULL
63 : : #define PLT_ALIGN_CEIL RTE_ALIGN_CEIL
64 : : #define PLT_ALIGN_FLOOR RTE_ALIGN_FLOOR
65 : : #define PLT_INIT RTE_INIT
66 : : #define PLT_MAX_ETHPORTS RTE_MAX_ETHPORTS
67 : : #define PLT_TAILQ_FOREACH_SAFE RTE_TAILQ_FOREACH_SAFE
68 : :
69 : : #ifndef PLT_ETHER_ADDR_LEN
70 : : #define PLT_ETHER_ADDR_LEN RTE_ETHER_ADDR_LEN
71 : : #endif
72 : :
73 : : /* Cast to specific datatypes */
74 : : #define PLT_PTR_CAST(val) ((void *)(val))
75 : : #define PLT_U64_CAST(val) ((uint64_t)(val))
76 : : #define PLT_U32_CAST(val) ((uint32_t)(val))
77 : : #define PLT_U16_CAST(val) ((uint16_t)(val))
78 : :
79 : : /* Add / Sub pointer with scalar and cast to uint64_t */
80 : : #define PLT_PTR_ADD_U64_CAST(__ptr, __x) PLT_U64_CAST(PLT_PTR_ADD(__ptr, __x))
81 : : #define PLT_PTR_SUB_U64_CAST(__ptr, __x) PLT_U64_CAST(PLT_PTR_SUB(__ptr, __x))
82 : :
83 : : /** Divide ceil */
84 : : #define PLT_DIV_CEIL(x, y) \
85 : : ({ \
86 : : __typeof(x) __x = x; \
87 : : __typeof(y) __y = y; \
88 : : (__x + __y - 1) / __y; \
89 : : })
90 : :
91 : : #define __plt_cache_aligned __rte_cache_aligned
92 : : #define __plt_always_inline __rte_always_inline
93 : : #define __plt_packed __rte_packed
94 : : #define __plt_unused __rte_unused
95 : : #define __roc_api __rte_internal
96 : : #define plt_iova_t rte_iova_t
97 : :
98 : : #define plt_pci_addr rte_pci_addr
99 : : #define plt_pci_device rte_pci_device
100 : : #define plt_pci_read_config rte_pci_read_config
101 : : #define plt_pci_find_ext_capability rte_pci_find_ext_capability
102 : : #define plt_sysfs_value_parse eal_parse_sysfs_value
103 : :
104 : : #define plt_log2_u32 rte_log2_u32
105 : : #define plt_cpu_to_be_16 rte_cpu_to_be_16
106 : : #define plt_be_to_cpu_16 rte_be_to_cpu_16
107 : : #define plt_cpu_to_be_32 rte_cpu_to_be_32
108 : : #define plt_be_to_cpu_32 rte_be_to_cpu_32
109 : : #define plt_cpu_to_be_64 rte_cpu_to_be_64
110 : : #define plt_be_to_cpu_64 rte_be_to_cpu_64
111 : :
112 : : #define __plt_aligned __rte_aligned
113 : : #define plt_align32pow2 rte_align32pow2
114 : : #define plt_align32prevpow2 rte_align32prevpow2
115 : :
116 : : #define plt_bitmap rte_bitmap
117 : : #define plt_bitmap_init rte_bitmap_init
118 : : #define plt_bitmap_reset rte_bitmap_reset
119 : : #define plt_bitmap_free rte_bitmap_free
120 : : #define plt_bitmap_clear rte_bitmap_clear
121 : : #define plt_bitmap_set rte_bitmap_set
122 : : #define plt_bitmap_get rte_bitmap_get
123 : : #define plt_bitmap_scan_init __rte_bitmap_scan_init
124 : : #define plt_bitmap_scan rte_bitmap_scan
125 : : #define plt_bitmap_get_memory_footprint rte_bitmap_get_memory_footprint
126 : :
127 : : #define plt_spinlock_t rte_spinlock_t
128 : : #define plt_spinlock_init rte_spinlock_init
129 : : #define plt_spinlock_lock rte_spinlock_lock
130 : : #define plt_spinlock_unlock rte_spinlock_unlock
131 : : #define plt_spinlock_trylock rte_spinlock_trylock
132 : :
133 : : #define plt_seqcount_t rte_seqcount_t
134 : : #define plt_seqcount_init rte_seqcount_init
135 : : #define plt_seqcount_read_begin rte_seqcount_read_begin
136 : : #define plt_seqcount_read_retry rte_seqcount_read_retry
137 : : #define plt_seqcount_write_begin rte_seqcount_write_begin
138 : : #define plt_seqcount_write_end rte_seqcount_write_end
139 : :
140 : : #define plt_thread_t rte_thread_t
141 : : #define plt_intr_callback_register rte_intr_callback_register
142 : : #define plt_intr_callback_unregister rte_intr_callback_unregister
143 : : #define plt_intr_disable rte_intr_disable
144 : : #define plt_thread_is_intr rte_thread_is_intr
145 : : #define plt_intr_callback_fn rte_intr_callback_fn
146 : : #define plt_thread_create_control rte_thread_create_internal_control
147 : : #define plt_thread_join rte_thread_join
148 : :
149 : : static inline bool
150 : : plt_thread_is_valid(plt_thread_t thr)
151 : : {
152 : : return thr.opaque_id ? true : false;
153 : : }
154 : :
155 : : #define plt_intr_efd_counter_size_get rte_intr_efd_counter_size_get
156 : : #define plt_intr_efd_counter_size_set rte_intr_efd_counter_size_set
157 : : #define plt_intr_vec_list_index_get rte_intr_vec_list_index_get
158 : : #define plt_intr_vec_list_index_set rte_intr_vec_list_index_set
159 : : #define plt_intr_vec_list_alloc rte_intr_vec_list_alloc
160 : : #define plt_intr_vec_list_free rte_intr_vec_list_free
161 : : #define plt_intr_fd_set rte_intr_fd_set
162 : : #define plt_intr_fd_get rte_intr_fd_get
163 : : #define plt_intr_dev_fd_get rte_intr_dev_fd_get
164 : : #define plt_intr_dev_fd_set rte_intr_dev_fd_set
165 : : #define plt_intr_type_get rte_intr_type_get
166 : : #define plt_intr_type_set rte_intr_type_set
167 : : #define plt_intr_instance_alloc rte_intr_instance_alloc
168 : : #define plt_intr_instance_dup rte_intr_instance_dup
169 : : #define plt_intr_instance_free rte_intr_instance_free
170 : : #define plt_intr_event_list_update rte_intr_event_list_update
171 : : #define plt_intr_max_intr_get rte_intr_max_intr_get
172 : : #define plt_intr_max_intr_set rte_intr_max_intr_set
173 : : #define plt_intr_nb_efd_get rte_intr_nb_efd_get
174 : : #define plt_intr_nb_efd_set rte_intr_nb_efd_set
175 : : #define plt_intr_nb_intr_get rte_intr_nb_intr_get
176 : : #define plt_intr_nb_intr_set rte_intr_nb_intr_set
177 : : #define plt_intr_efds_index_get rte_intr_efds_index_get
178 : : #define plt_intr_efds_index_set rte_intr_efds_index_set
179 : : #define plt_intr_elist_index_get rte_intr_elist_index_get
180 : : #define plt_intr_elist_index_set rte_intr_elist_index_set
181 : :
182 : : #define plt_alarm_set rte_eal_alarm_set
183 : : #define plt_alarm_cancel rte_eal_alarm_cancel
184 : :
185 : : #define plt_intr_handle rte_intr_handle
186 : :
187 : : #define plt_zmalloc(sz, align) rte_zmalloc("cnxk", sz, align)
188 : : #define plt_realloc rte_realloc
189 : : #define plt_free rte_free
190 : :
191 : : #define plt_read64(addr) rte_read64_relaxed((volatile void *)(addr))
192 : : #define plt_write64(val, addr) \
193 : : rte_write64_relaxed((val), (volatile void *)(addr))
194 : :
195 : : #define plt_read32(addr) rte_read32_relaxed((volatile void *)(addr))
196 : : #define plt_write32(val, addr) \
197 : : rte_write32_relaxed((val), (volatile void *)(addr))
198 : :
199 : : #define plt_wmb() rte_wmb()
200 : : #define plt_rmb() rte_rmb()
201 : : #define plt_io_wmb() rte_io_wmb()
202 : : #define plt_io_rmb() rte_io_rmb()
203 : : #define plt_atomic_thread_fence rte_atomic_thread_fence
204 : :
205 : : #define plt_bit_relaxed_get32 rte_bit_relaxed_get32
206 : : #define plt_bit_relaxed_set32 rte_bit_relaxed_set32
207 : : #define plt_bit_relaxed_clear32 rte_bit_relaxed_clear32
208 : :
209 : : #define plt_bit_relaxed_get64 rte_bit_relaxed_get64
210 : : #define plt_bit_relaxed_set64 rte_bit_relaxed_set64
211 : : #define plt_bit_relaxed_clear64 rte_bit_relaxed_clear64
212 : :
213 : : #define plt_popcount32 rte_popcount32
214 : : #define plt_popcount64 rte_popcount64
215 : : #define plt_clz32 rte_clz32
216 : : #define plt_ctz64 rte_ctz64
217 : :
218 : : #define plt_mmap mmap
219 : : #define PLT_PROT_READ PROT_READ
220 : : #define PLT_PROT_WRITE PROT_WRITE
221 : : #define PLT_MAP_SHARED MAP_SHARED
222 : :
223 : : #define plt_memzone rte_memzone
224 : : #define plt_memzone_lookup rte_memzone_lookup
225 : : #define plt_memzone_reserve_cache_align(name, sz) \
226 : : rte_memzone_reserve_aligned(name, sz, 0, 0, RTE_CACHE_LINE_SIZE)
227 : : #define plt_memzone_free rte_memzone_free
228 : : #define plt_memzone_reserve_aligned(name, len, flags, align) \
229 : : rte_memzone_reserve_aligned((name), (len), 0, (flags), (align))
230 : :
231 : : #define plt_tsc_hz rte_get_tsc_hz
232 : : #define plt_tsc_cycles rte_get_tsc_cycles
233 : : #define plt_delay_ms rte_delay_ms
234 : : #define plt_delay_us rte_delay_us
235 : :
236 : : #define plt_lcore_id rte_lcore_id
237 : :
238 : : #define plt_strlcpy rte_strlcpy
239 : :
240 : : #define PLT_TEL_INT_VAL RTE_TEL_INT_VAL
241 : : #define PLT_TEL_STRING_VAL RTE_TEL_STRING_VAL
242 : : #define plt_tel_data rte_tel_data
243 : : #define plt_tel_data_start_array rte_tel_data_start_array
244 : : #define plt_tel_data_add_array_int rte_tel_data_add_array_int
245 : : #define plt_tel_data_add_array_string rte_tel_data_add_array_string
246 : : #define plt_tel_data_start_dict rte_tel_data_start_dict
247 : : #define plt_tel_data_add_dict_int rte_tel_data_add_dict_int
248 : : #define plt_tel_data_add_dict_ptr(d, n, v) \
249 : : rte_tel_data_add_dict_uint(d, n, (uint64_t)v)
250 : : #define plt_tel_data_add_dict_string rte_tel_data_add_dict_string
251 : : #define plt_tel_data_add_dict_u64 rte_tel_data_add_dict_uint
252 : : #define plt_telemetry_register_cmd rte_telemetry_register_cmd
253 : :
254 : : /* Log */
255 : : extern int cnxk_logtype_base;
256 : : extern int cnxk_logtype_mbox;
257 : : extern int cnxk_logtype_cpt;
258 : : extern int cnxk_logtype_ml;
259 : : extern int cnxk_logtype_npa;
260 : : extern int cnxk_logtype_nix;
261 : : extern int cnxk_logtype_npc;
262 : : extern int cnxk_logtype_sso;
263 : : extern int cnxk_logtype_tim;
264 : : extern int cnxk_logtype_tm;
265 : : extern int cnxk_logtype_ree;
266 : : extern int cnxk_logtype_dpi;
267 : :
268 : : #define plt_err(fmt, args...) \
269 : : RTE_LOG(ERR, PMD, "%s():%u " fmt "\n", __func__, __LINE__, ##args)
270 : : #define plt_info(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
271 : : #define plt_warn(fmt, args...) RTE_LOG(WARNING, PMD, fmt "\n", ##args)
272 : : #define plt_print(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
273 : : #define plt_dump(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
274 : : #define plt_dump_no_nl(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
275 : :
276 : : /**
277 : : * Log debug message if given subsystem logging is enabled.
278 : : */
279 : : #define plt_dbg(subsystem, fmt, args...) \
280 : : rte_log(RTE_LOG_DEBUG, cnxk_logtype_##subsystem, \
281 : : "[%s] %s():%u " fmt "\n", #subsystem, __func__, __LINE__, \
282 : : ##args)
283 : :
284 : : #define plt_base_dbg(fmt, ...) plt_dbg(base, fmt, ##__VA_ARGS__)
285 : : #define plt_cpt_dbg(fmt, ...) plt_dbg(cpt, fmt, ##__VA_ARGS__)
286 : : #define plt_mbox_dbg(fmt, ...) plt_dbg(mbox, fmt, ##__VA_ARGS__)
287 : : #define plt_ml_dbg(fmt, ...) plt_dbg(ml, fmt, ##__VA_ARGS__)
288 : : #define plt_npa_dbg(fmt, ...) plt_dbg(npa, fmt, ##__VA_ARGS__)
289 : : #define plt_nix_dbg(fmt, ...) plt_dbg(nix, fmt, ##__VA_ARGS__)
290 : : #define plt_npc_dbg(fmt, ...) plt_dbg(npc, fmt, ##__VA_ARGS__)
291 : : #define plt_sso_dbg(fmt, ...) plt_dbg(sso, fmt, ##__VA_ARGS__)
292 : : #define plt_tim_dbg(fmt, ...) plt_dbg(tim, fmt, ##__VA_ARGS__)
293 : : #define plt_tm_dbg(fmt, ...) plt_dbg(tm, fmt, ##__VA_ARGS__)
294 : : #define plt_ree_dbg(fmt, ...) plt_dbg(ree, fmt, ##__VA_ARGS__)
295 : : #define plt_dpi_dbg(fmt, ...) plt_dbg(dpi, fmt, ##__VA_ARGS__)
296 : :
297 : : /* Datapath logs */
298 : : #define plt_dp_err(fmt, args...) \
299 : : RTE_LOG_DP(ERR, PMD, "%s():%u " fmt "\n", __func__, __LINE__, ##args)
300 : : #define plt_dp_info(fmt, args...) \
301 : : RTE_LOG_DP(INFO, PMD, "%s():%u " fmt "\n", __func__, __LINE__, ##args)
302 : : #define plt_dp_dbg(fmt, args...) \
303 : : RTE_LOG_DP(DEBUG, PMD, "%s():%u " fmt "\n", __func__, __LINE__, ##args)
304 : :
305 : : #ifdef __cplusplus
306 : : #define CNXK_PCI_ID(subsystem_dev, dev) \
307 : : { \
308 : : RTE_CLASS_ANY_ID, PCI_VENDOR_ID_CAVIUM, (dev), RTE_PCI_ANY_ID, \
309 : : (subsystem_dev), \
310 : : }
311 : : #else
312 : : #define CNXK_PCI_ID(subsystem_dev, dev) \
313 : : { \
314 : : .class_id = RTE_CLASS_ANY_ID, \
315 : : .vendor_id = PCI_VENDOR_ID_CAVIUM, .device_id = (dev), \
316 : : .subsystem_vendor_id = RTE_PCI_ANY_ID, \
317 : : .subsystem_device_id = (subsystem_dev), \
318 : : }
319 : : #endif
320 : :
321 : : /* Device memory does not support unaligned access, instruct compiler to
322 : : * not optimize the memory access when working with mailbox memory.
323 : : */
324 : : #ifndef __io
325 : : #define __io volatile
326 : : #endif
327 : :
328 : : __rte_internal
329 : : int roc_plt_init(void);
330 : :
331 : : __rte_internal
332 : : uint16_t roc_plt_control_lmt_id_get(void);
333 : : __rte_internal
334 : : uint16_t roc_plt_lmt_validate(void);
335 : :
336 : : /* Init callbacks */
337 : : typedef int (*roc_plt_init_cb_t)(void);
338 : : int __roc_api roc_plt_init_cb_register(roc_plt_init_cb_t cb);
339 : :
340 : : static inline const void *
341 : : plt_lmt_region_reserve_aligned(const char *name, size_t len, uint32_t align)
342 : : {
343 : : /* To ensure returned memory is physically contiguous, bounding
344 : : * the start and end address in 2M range.
345 : : */
346 : 0 : return rte_memzone_reserve_bounded(name, len, SOCKET_ID_ANY,
347 : : RTE_MEMZONE_IOVA_CONTIG,
348 : : align, RTE_PGSIZE_2M);
349 : : }
350 : :
351 : : #endif /* _ROC_PLATFORM_H_ */
|