xref: /dpdk/drivers/common/cnxk/roc_model.h (revision 62afdd8d493d8f563c053a4afccb3c5acd1acf54)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4 
5 #ifndef _ROC_MODEL_H_
6 #define _ROC_MODEL_H_
7 
8 #include <stdbool.h>
9 
10 #include "roc_bits.h"
11 #include "roc_constants.h"
12 
13 extern struct roc_model *roc_model;
14 
15 struct roc_model {
16 /* CN9k Models*/
17 #define ROC_MODEL_CN96xx_A0    BIT_ULL(0)
18 #define ROC_MODEL_CN96xx_B0    BIT_ULL(1)
19 #define ROC_MODEL_CN96xx_C0    BIT_ULL(2)
20 #define ROC_MODEL_CNF95xx_A0   BIT_ULL(4)
21 #define ROC_MODEL_CNF95xx_B0   BIT_ULL(6)
22 #define ROC_MODEL_CNF95xxMM_A0 BIT_ULL(8)
23 #define ROC_MODEL_CNF95xxN_A0  BIT_ULL(12)
24 #define ROC_MODEL_CNF95xxO_A0  BIT_ULL(13)
25 #define ROC_MODEL_CNF95xxN_A1  BIT_ULL(14)
26 #define ROC_MODEL_CNF95xxN_B0  BIT_ULL(15)
27 #define ROC_MODEL_CN98xx_A0    BIT_ULL(16)
28 #define ROC_MODEL_CN98xx_A1    BIT_ULL(17)
29 /* CN10k Models*/
30 #define ROC_MODEL_CN106xx_A0   BIT_ULL(20)
31 #define ROC_MODEL_CNF105xx_A0  BIT_ULL(21)
32 #define ROC_MODEL_CNF105xxN_A0 BIT_ULL(22)
33 #define ROC_MODEL_CN103xx_A0   BIT_ULL(23)
34 #define ROC_MODEL_CN106xx_A1   BIT_ULL(24)
35 #define ROC_MODEL_CNF105xx_A1  BIT_ULL(25)
36 #define ROC_MODEL_CN106xx_B0   BIT_ULL(26)
37 #define ROC_MODEL_CNF105xxN_B0 BIT_ULL(27)
38 /* CN20k Models*/
39 #define ROC_MODEL_CN206xx_A0   BIT_ULL(40)
40 
41 /* Following flags describe platform code is running on */
42 #define ROC_ENV_HW   BIT_ULL(61)
43 #define ROC_ENV_EMUL BIT_ULL(62)
44 #define ROC_ENV_ASIM BIT_ULL(63)
45 
46 	uint64_t flag;
47 #define ROC_MODEL_STR_LEN_MAX 128
48 	char name[ROC_MODEL_STR_LEN_MAX];
49 	char env[ROC_MODEL_STR_LEN_MAX];
50 } __plt_cache_aligned;
51 
52 /* CN9K models */
53 #define ROC_MODEL_CN96xx_Ax (ROC_MODEL_CN96xx_A0 | ROC_MODEL_CN96xx_B0)
54 #define ROC_MODEL_CN98xx_Ax (ROC_MODEL_CN98xx_A0 | ROC_MODEL_CN98xx_A1)
55 #define ROC_MODEL_CN9K                                                         \
56 	(ROC_MODEL_CN96xx_Ax | ROC_MODEL_CN96xx_C0 | ROC_MODEL_CNF95xx_A0 |    \
57 	 ROC_MODEL_CNF95xx_B0 | ROC_MODEL_CNF95xxMM_A0 |                       \
58 	 ROC_MODEL_CNF95xxO_A0 | ROC_MODEL_CNF95xxN_A0 | ROC_MODEL_CN98xx_Ax | \
59 	 ROC_MODEL_CNF95xxN_A1 | ROC_MODEL_CNF95xxN_B0)
60 #define ROC_MODEL_CNF9K                                                        \
61 	(ROC_MODEL_CNF95xx_A0 | ROC_MODEL_CNF95xx_B0 |                         \
62 	 ROC_MODEL_CNF95xxMM_A0 | ROC_MODEL_CNF95xxO_A0 |                      \
63 	 ROC_MODEL_CNF95xxN_A0 | ROC_MODEL_CNF95xxN_A1 |                       \
64 	 ROC_MODEL_CNF95xxN_B0)
65 
66 /* CN10K models */
67 #define ROC_MODEL_CN106xx   (ROC_MODEL_CN106xx_A0 | ROC_MODEL_CN106xx_A1 | ROC_MODEL_CN106xx_B0)
68 #define ROC_MODEL_CNF105xx  (ROC_MODEL_CNF105xx_A0 | ROC_MODEL_CNF105xx_A1)
69 #define ROC_MODEL_CNF105xxN (ROC_MODEL_CNF105xxN_A0 | ROC_MODEL_CNF105xxN_B0)
70 #define ROC_MODEL_CN103xx   (ROC_MODEL_CN103xx_A0)
71 #define ROC_MODEL_CN10K                                                        \
72 	(ROC_MODEL_CN106xx | ROC_MODEL_CNF105xx | ROC_MODEL_CNF105xxN |        \
73 	 ROC_MODEL_CN103xx)
74 #define ROC_MODEL_CNF10K (ROC_MODEL_CNF105xx | ROC_MODEL_CNF105xxN)
75 
76 /* CN20K models */
77 #define ROC_MODEL_CN206xx   (ROC_MODEL_CN206xx_A0)
78 #define ROC_MODEL_CN20K     (ROC_MODEL_CN206xx)
79 
80 /* Runtime variants */
81 static inline uint64_t
82 roc_model_runtime_is_cn9k(void)
83 {
84 	return (roc_model->flag & (ROC_MODEL_CN9K));
85 }
86 
87 static inline uint64_t
88 roc_model_runtime_is_cn10k(void)
89 {
90 	return (roc_model->flag & (ROC_MODEL_CN10K));
91 }
92 
93 static inline uint64_t
94 roc_model_runtime_is_cn20k(void)
95 {
96 	return (roc_model->flag & (ROC_MODEL_CN20K));
97 }
98 
99 /* Compile time variants */
100 #ifdef ROC_PLATFORM_CN9K
101 #define roc_model_constant_is_cn9k()  1
102 #define roc_model_constant_is_cn10k() 0
103 #define roc_model_constant_is_cn20k() 0
104 #endif
105 #ifdef ROC_PLATFORM_CN10K
106 #define roc_model_constant_is_cn9k()  0
107 #define roc_model_constant_is_cn10k() 1
108 #define roc_model_constant_is_cn20k() 0
109 #endif
110 #ifdef ROC_PLATFORM_CN20K
111 #define roc_model_constant_is_cn9k()  0
112 #define roc_model_constant_is_cn10k() 0
113 #define roc_model_constant_is_cn20k() 1
114 #endif
115 #if !defined(ROC_PLATFORM_CN9K) && !defined(ROC_PLATFORM_CN10K) && !defined(ROC_PLATFORM_CN20K)
116 #define roc_model_constant_is_cn9k()  0
117 #define roc_model_constant_is_cn10k() 0
118 #define roc_model_constant_is_cn20k() 0
119 #endif
120 
121 /*
122  * Compile time variants to enable optimized version check when the library
123  * configured for specific platform version else to fallback to runtime.
124  */
125 static inline uint64_t
126 roc_model_is_cn9k(void)
127 {
128 #ifdef ROC_PLATFORM_CN9K
129 	return 1;
130 #endif
131 #if defined(ROC_PLATFORM_CN10K) || defined(ROC_PLATFORM_CN20K)
132 	return 0;
133 #endif
134 	return roc_model_runtime_is_cn9k();
135 }
136 
137 static inline uint64_t
138 roc_model_is_cn10k(void)
139 {
140 #ifdef ROC_PLATFORM_CN10K
141 	return 1;
142 #endif
143 #if defined(ROC_PLATFORM_CN9K) || defined(ROC_PLATFORM_CN20K)
144 	return 0;
145 #endif
146 	return roc_model_runtime_is_cn10k();
147 }
148 
149 static inline uint64_t
150 roc_model_is_cn20k(void)
151 {
152 #ifdef ROC_PLATFORM_CN20K
153 	return 1;
154 #endif
155 #if defined(ROC_PLATFORM_CN9K) || defined(ROC_PLATFORM_CN10K)
156 	return 0;
157 #endif
158 	return roc_model_runtime_is_cn20k();
159 }
160 
161 static inline uint16_t
162 roc_model_optimal_align_sz(void)
163 {
164 	if (roc_model_is_cn9k())
165 		return ROC_ALIGN;
166 	if (roc_model_is_cn10k())
167 		return ROC_ALIGN;
168 	if (roc_model_is_cn20k())
169 		return ROC_ALIGN << 1;
170 	return 128;
171 }
172 
173 static inline uint64_t
174 roc_model_is_cn98xx(void)
175 {
176 	return (roc_model->flag & ROC_MODEL_CN98xx_Ax);
177 }
178 
179 static inline uint64_t
180 roc_model_is_cn98xx_a0(void)
181 {
182 	return (roc_model->flag & ROC_MODEL_CN98xx_A0);
183 }
184 
185 static inline uint64_t
186 roc_model_is_cn98xx_a1(void)
187 {
188 	return (roc_model->flag & ROC_MODEL_CN98xx_A1);
189 }
190 
191 static inline uint64_t
192 roc_model_is_cn96_a0(void)
193 {
194 	return roc_model->flag & ROC_MODEL_CN96xx_A0;
195 }
196 
197 static inline uint64_t
198 roc_model_is_cn96_ax(void)
199 {
200 	return (roc_model->flag & ROC_MODEL_CN96xx_Ax);
201 }
202 
203 static inline uint64_t
204 roc_model_is_cn96_b0(void)
205 {
206 	return (roc_model->flag & ROC_MODEL_CN96xx_B0);
207 }
208 
209 static inline uint64_t
210 roc_model_is_cn96_cx(void)
211 {
212 	return (roc_model->flag & ROC_MODEL_CN96xx_C0);
213 }
214 
215 static inline uint64_t
216 roc_model_is_cn95_a0(void)
217 {
218 	return roc_model->flag & ROC_MODEL_CNF95xx_A0;
219 }
220 
221 static inline uint64_t
222 roc_model_is_cnf95xxn_a0(void)
223 {
224 	return roc_model->flag & ROC_MODEL_CNF95xxN_A0;
225 }
226 
227 static inline uint64_t
228 roc_model_is_cnf95xxn_a1(void)
229 {
230 	return roc_model->flag & ROC_MODEL_CNF95xxN_A1;
231 }
232 
233 static inline uint64_t
234 roc_model_is_cnf95xxn_b0(void)
235 {
236 	return roc_model->flag & ROC_MODEL_CNF95xxN_B0;
237 }
238 
239 static inline uint64_t
240 roc_model_is_cnf95xxo_a0(void)
241 {
242 	return roc_model->flag & ROC_MODEL_CNF95xxO_A0;
243 }
244 
245 static inline uint16_t
246 roc_model_is_cn95xxn_a0(void)
247 {
248 	return roc_model->flag & ROC_MODEL_CNF95xxN_A0;
249 }
250 
251 static inline uint64_t
252 roc_model_is_cn10ka(void)
253 {
254 	return roc_model->flag & ROC_MODEL_CN106xx;
255 }
256 
257 static inline uint64_t
258 roc_model_is_cnf10ka(void)
259 {
260 	return roc_model->flag & ROC_MODEL_CNF105xx;
261 }
262 
263 static inline uint64_t
264 roc_model_is_cnf10kb(void)
265 {
266 	return roc_model->flag & ROC_MODEL_CNF105xxN;
267 }
268 
269 static inline uint64_t
270 roc_model_is_cn10kb_a0(void)
271 {
272 	return roc_model->flag & ROC_MODEL_CN103xx_A0;
273 }
274 
275 static inline uint64_t
276 roc_model_is_cn10ka_a0(void)
277 {
278 	return roc_model->flag & ROC_MODEL_CN106xx_A0;
279 }
280 
281 static inline uint64_t
282 roc_model_is_cn10ka_a1(void)
283 {
284 	return roc_model->flag & ROC_MODEL_CN106xx_A1;
285 }
286 
287 static inline uint64_t
288 roc_model_is_cn10ka_b0(void)
289 {
290 	return roc_model->flag & ROC_MODEL_CN106xx_B0;
291 }
292 
293 static inline uint64_t
294 roc_model_is_cnf10ka_a0(void)
295 {
296 	return roc_model->flag & ROC_MODEL_CNF105xx_A0;
297 }
298 
299 static inline uint64_t
300 roc_model_is_cnf10ka_a1(void)
301 {
302 	return roc_model->flag & ROC_MODEL_CNF105xx_A1;
303 }
304 
305 static inline uint64_t
306 roc_model_is_cnf10kb_a0(void)
307 {
308 	return roc_model->flag & ROC_MODEL_CNF105xxN_A0;
309 }
310 
311 static inline uint64_t
312 roc_model_is_cnf10kb_b0(void)
313 {
314 	return roc_model->flag & ROC_MODEL_CNF105xxN_B0;
315 }
316 
317 static inline uint64_t
318 roc_model_is_cn10kb(void)
319 {
320 	return roc_model->flag & ROC_MODEL_CN103xx;
321 }
322 
323 static inline bool
324 roc_env_is_hw(void)
325 {
326 	return roc_model->flag & ROC_ENV_HW;
327 }
328 
329 static inline bool
330 roc_env_is_emulator(void)
331 {
332 	return roc_model->flag & ROC_ENV_EMUL;
333 }
334 
335 static inline bool
336 roc_env_is_asim(void)
337 {
338 	return roc_model->flag & ROC_ENV_ASIM;
339 }
340 
341 static inline const char *
342 roc_env_get(void)
343 {
344 	return roc_model->env;
345 }
346 
347 int roc_model_init(struct roc_model *model);
348 
349 #endif
350