1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #ifndef _ROC_PLATFORM_H_
6 #define _ROC_PLATFORM_H_
9 #include <rte_bitmap.h>
10 #include <rte_bus_pci.h>
11 #include <rte_byteorder.h>
12 #include <rte_common.h>
13 #include <rte_cycles.h>
14 #include <rte_ether.h>
15 #include <rte_interrupts.h>
17 #include <rte_lcore.h>
19 #include <rte_malloc.h>
20 #include <rte_memzone.h>
22 #include <rte_spinlock.h>
23 #include <rte_string_fns.h>
24 #include <rte_tailq.h>
25 #include <rte_telemetry.h>
29 #if defined(__ARM_FEATURE_SVE)
30 #define PLT_CPU_FEATURE_PREAMBLE \
31 ".arch_extension crc\n" \
32 ".arch_extension lse\n" \
33 ".arch_extension sve\n"
35 #define PLT_CPU_FEATURE_PREAMBLE \
36 ".arch_extension crc\n" \
37 ".arch_extension lse\n"
40 #define PLT_ASSERT RTE_ASSERT
41 #define PLT_MEMZONE_NAMESIZE RTE_MEMZONE_NAMESIZE
42 #define PLT_STD_C11 RTE_STD_C11
43 #define PLT_PTR_ADD RTE_PTR_ADD
44 #define PLT_PTR_DIFF RTE_PTR_DIFF
45 #define PLT_MAX_RXTX_INTR_VEC_ID RTE_MAX_RXTX_INTR_VEC_ID
46 #define PLT_INTR_VEC_RXTX_OFFSET RTE_INTR_VEC_RXTX_OFFSET
47 #define PLT_MIN RTE_MIN
48 #define PLT_MAX RTE_MAX
49 #define PLT_DIM RTE_DIM
50 #define PLT_SET_USED RTE_SET_USED
51 #define PLT_SWAP RTE_SWAP
52 #define PLT_STATIC_ASSERT(s) _Static_assert(s, #s)
53 #define PLT_ALIGN RTE_ALIGN
54 #define PLT_ALIGN_MUL_CEIL RTE_ALIGN_MUL_CEIL
55 #define PLT_MODEL_MZ_NAME "roc_model_mz"
56 #define PLT_CACHE_LINE_SIZE RTE_CACHE_LINE_SIZE
57 #define BITMASK_ULL GENMASK_ULL
58 #define PLT_ALIGN_CEIL RTE_ALIGN_CEIL
59 #define PLT_INIT RTE_INIT
60 #define PLT_MAX_ETHPORTS RTE_MAX_ETHPORTS
61 #define PLT_TAILQ_FOREACH_SAFE RTE_TAILQ_FOREACH_SAFE
63 #ifndef PLT_ETHER_ADDR_LEN
64 #define PLT_ETHER_ADDR_LEN RTE_ETHER_ADDR_LEN
67 /* Cast to specific datatypes */
68 #define PLT_PTR_CAST(val) ((void *)(val))
69 #define PLT_U64_CAST(val) ((uint64_t)(val))
70 #define PLT_U32_CAST(val) ((uint32_t)(val))
71 #define PLT_U16_CAST(val) ((uint16_t)(val))
74 #define PLT_DIV_CEIL(x, y) \
76 __typeof(x) __x = x; \
77 __typeof(y) __y = y; \
78 (__x + __y - 1) / __y; \
81 #define __plt_cache_aligned __rte_cache_aligned
82 #define __plt_always_inline __rte_always_inline
83 #define __plt_packed __rte_packed
84 #define __plt_unused __rte_unused
85 #define __roc_api __rte_internal
86 #define plt_iova_t rte_iova_t
88 #define plt_pci_addr rte_pci_addr
89 #define plt_pci_device rte_pci_device
90 #define plt_pci_read_config rte_pci_read_config
91 #define plt_pci_find_ext_capability rte_pci_find_ext_capability
93 #define plt_log2_u32 rte_log2_u32
94 #define plt_cpu_to_be_16 rte_cpu_to_be_16
95 #define plt_be_to_cpu_16 rte_be_to_cpu_16
96 #define plt_cpu_to_be_32 rte_cpu_to_be_32
97 #define plt_be_to_cpu_32 rte_be_to_cpu_32
98 #define plt_cpu_to_be_64 rte_cpu_to_be_64
99 #define plt_be_to_cpu_64 rte_be_to_cpu_64
101 #define plt_aligned __rte_aligned
102 #define plt_align32pow2 rte_align32pow2
103 #define plt_align32prevpow2 rte_align32prevpow2
105 #define plt_bitmap rte_bitmap
106 #define plt_bitmap_init rte_bitmap_init
107 #define plt_bitmap_reset rte_bitmap_reset
108 #define plt_bitmap_free rte_bitmap_free
109 #define plt_bitmap_clear rte_bitmap_clear
110 #define plt_bitmap_set rte_bitmap_set
111 #define plt_bitmap_get rte_bitmap_get
112 #define plt_bitmap_scan_init __rte_bitmap_scan_init
113 #define plt_bitmap_scan rte_bitmap_scan
114 #define plt_bitmap_get_memory_footprint rte_bitmap_get_memory_footprint
116 #define plt_spinlock_t rte_spinlock_t
117 #define plt_spinlock_init rte_spinlock_init
118 #define plt_spinlock_lock rte_spinlock_lock
119 #define plt_spinlock_unlock rte_spinlock_unlock
121 #define plt_intr_callback_register rte_intr_callback_register
122 #define plt_intr_callback_unregister rte_intr_callback_unregister
123 #define plt_intr_disable rte_intr_disable
124 #define plt_thread_is_intr rte_thread_is_intr
125 #define plt_intr_callback_fn rte_intr_callback_fn
126 #define plt_ctrl_thread_create rte_ctrl_thread_create
128 #define plt_intr_efd_counter_size_get rte_intr_efd_counter_size_get
129 #define plt_intr_efd_counter_size_set rte_intr_efd_counter_size_set
130 #define plt_intr_vec_list_index_get rte_intr_vec_list_index_get
131 #define plt_intr_vec_list_index_set rte_intr_vec_list_index_set
132 #define plt_intr_vec_list_alloc rte_intr_vec_list_alloc
133 #define plt_intr_vec_list_free rte_intr_vec_list_free
134 #define plt_intr_fd_set rte_intr_fd_set
135 #define plt_intr_fd_get rte_intr_fd_get
136 #define plt_intr_dev_fd_get rte_intr_dev_fd_get
137 #define plt_intr_dev_fd_set rte_intr_dev_fd_set
138 #define plt_intr_type_get rte_intr_type_get
139 #define plt_intr_type_set rte_intr_type_set
140 #define plt_intr_instance_alloc rte_intr_instance_alloc
141 #define plt_intr_instance_dup rte_intr_instance_dup
142 #define plt_intr_instance_free rte_intr_instance_free
143 #define plt_intr_event_list_update rte_intr_event_list_update
144 #define plt_intr_max_intr_get rte_intr_max_intr_get
145 #define plt_intr_max_intr_set rte_intr_max_intr_set
146 #define plt_intr_nb_efd_get rte_intr_nb_efd_get
147 #define plt_intr_nb_efd_set rte_intr_nb_efd_set
148 #define plt_intr_nb_intr_get rte_intr_nb_intr_get
149 #define plt_intr_nb_intr_set rte_intr_nb_intr_set
150 #define plt_intr_efds_index_get rte_intr_efds_index_get
151 #define plt_intr_efds_index_set rte_intr_efds_index_set
152 #define plt_intr_elist_index_get rte_intr_elist_index_get
153 #define plt_intr_elist_index_set rte_intr_elist_index_set
155 #define plt_alarm_set rte_eal_alarm_set
156 #define plt_alarm_cancel rte_eal_alarm_cancel
158 #define plt_intr_handle rte_intr_handle
160 #define plt_zmalloc(sz, align) rte_zmalloc("cnxk", sz, align)
161 #define plt_realloc rte_realloc
162 #define plt_free rte_free
164 #define plt_read64(addr) rte_read64_relaxed((volatile void *)(addr))
165 #define plt_write64(val, addr) \
166 rte_write64_relaxed((val), (volatile void *)(addr))
168 #define plt_wmb() rte_wmb()
169 #define plt_rmb() rte_rmb()
170 #define plt_io_wmb() rte_io_wmb()
171 #define plt_io_rmb() rte_io_rmb()
172 #define plt_atomic_thread_fence rte_atomic_thread_fence
174 #define plt_mmap mmap
175 #define PLT_PROT_READ PROT_READ
176 #define PLT_PROT_WRITE PROT_WRITE
177 #define PLT_MAP_SHARED MAP_SHARED
179 #define plt_memzone rte_memzone
180 #define plt_memzone_lookup rte_memzone_lookup
181 #define plt_memzone_reserve_cache_align(name, sz) \
182 rte_memzone_reserve_aligned(name, sz, 0, 0, RTE_CACHE_LINE_SIZE)
183 #define plt_memzone_free rte_memzone_free
184 #define plt_memzone_reserve_aligned(name, len, flags, align) \
185 rte_memzone_reserve_aligned((name), (len), 0, (flags), (align))
187 #define plt_tsc_hz rte_get_tsc_hz
188 #define plt_delay_ms rte_delay_ms
189 #define plt_delay_us rte_delay_us
191 #define plt_lcore_id rte_lcore_id
193 #define plt_strlcpy rte_strlcpy
195 #define PLT_TEL_INT_VAL RTE_TEL_INT_VAL
196 #define PLT_TEL_STRING_VAL RTE_TEL_STRING_VAL
197 #define plt_tel_data rte_tel_data
198 #define plt_tel_data_start_array rte_tel_data_start_array
199 #define plt_tel_data_add_array_int rte_tel_data_add_array_int
200 #define plt_tel_data_add_array_string rte_tel_data_add_array_string
201 #define plt_tel_data_start_dict rte_tel_data_start_dict
202 #define plt_tel_data_add_dict_int rte_tel_data_add_dict_int
203 #define plt_tel_data_add_dict_ptr(d, n, v) \
204 rte_tel_data_add_dict_u64(d, n, (uint64_t)v)
205 #define plt_tel_data_add_dict_string rte_tel_data_add_dict_string
206 #define plt_tel_data_add_dict_u64 rte_tel_data_add_dict_u64
207 #define plt_telemetry_register_cmd rte_telemetry_register_cmd
210 extern int cnxk_logtype_base;
211 extern int cnxk_logtype_mbox;
212 extern int cnxk_logtype_cpt;
213 extern int cnxk_logtype_npa;
214 extern int cnxk_logtype_nix;
215 extern int cnxk_logtype_npc;
216 extern int cnxk_logtype_sso;
217 extern int cnxk_logtype_tim;
218 extern int cnxk_logtype_tm;
219 extern int cnxk_logtype_ree;
221 #define plt_err(fmt, args...) \
222 RTE_LOG(ERR, PMD, "%s():%u " fmt "\n", __func__, __LINE__, ##args)
223 #define plt_info(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
224 #define plt_warn(fmt, args...) RTE_LOG(WARNING, PMD, fmt "\n", ##args)
225 #define plt_print(fmt, args...) RTE_LOG(INFO, PMD, fmt "\n", ##args)
226 #define plt_dump(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
227 #define plt_dump_no_nl(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
230 * Log debug message if given subsystem logging is enabled.
232 #define plt_dbg(subsystem, fmt, args...) \
233 rte_log(RTE_LOG_DEBUG, cnxk_logtype_##subsystem, \
234 "[%s] %s():%u " fmt "\n", #subsystem, __func__, __LINE__, \
237 #define plt_base_dbg(fmt, ...) plt_dbg(base, fmt, ##__VA_ARGS__)
238 #define plt_cpt_dbg(fmt, ...) plt_dbg(cpt, fmt, ##__VA_ARGS__)
239 #define plt_mbox_dbg(fmt, ...) plt_dbg(mbox, fmt, ##__VA_ARGS__)
240 #define plt_npa_dbg(fmt, ...) plt_dbg(npa, fmt, ##__VA_ARGS__)
241 #define plt_nix_dbg(fmt, ...) plt_dbg(nix, fmt, ##__VA_ARGS__)
242 #define plt_npc_dbg(fmt, ...) plt_dbg(npc, fmt, ##__VA_ARGS__)
243 #define plt_sso_dbg(fmt, ...) plt_dbg(sso, fmt, ##__VA_ARGS__)
244 #define plt_tim_dbg(fmt, ...) plt_dbg(tim, fmt, ##__VA_ARGS__)
245 #define plt_tm_dbg(fmt, ...) plt_dbg(tm, fmt, ##__VA_ARGS__)
246 #define plt_ree_dbg(fmt, ...) plt_dbg(ree, fmt, ##__VA_ARGS__)
249 #define plt_dp_err(fmt, args...) \
250 RTE_LOG_DP(ERR, PMD, "%s():%u " fmt "\n", __func__, __LINE__, ##args)
251 #define plt_dp_info(fmt, args...) \
252 RTE_LOG_DP(INFO, PMD, "%s():%u " fmt "\n", __func__, __LINE__, ##args)
255 #define CNXK_PCI_ID(subsystem_dev, dev) \
257 RTE_CLASS_ANY_ID, PCI_VENDOR_ID_CAVIUM, (dev), RTE_PCI_ANY_ID, \
261 #define CNXK_PCI_ID(subsystem_dev, dev) \
263 .class_id = RTE_CLASS_ANY_ID, \
264 .vendor_id = PCI_VENDOR_ID_CAVIUM, .device_id = (dev), \
265 .subsystem_vendor_id = RTE_PCI_ANY_ID, \
266 .subsystem_device_id = (subsystem_dev), \
271 int roc_plt_init(void);
274 typedef int (*roc_plt_init_cb_t)(void);
275 int __roc_api roc_plt_init_cb_register(roc_plt_init_cb_t cb);
277 static inline const void *
278 plt_lmt_region_reserve_aligned(const char *name, size_t len, uint32_t align)
280 /* To ensure returned memory is physically contiguous, bounding
281 * the start and end address in 2M range.
283 return rte_memzone_reserve_bounded(name, len, SOCKET_ID_ANY,
284 RTE_MEMZONE_IOVA_CONTIG,
285 align, RTE_PGSIZE_2M);
288 #endif /* _ROC_PLATFORM_H_ */