]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/dpdk/drivers/net/nfp/nfpcore/nfp-common/nfp_resid.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / drivers / net / nfp / nfpcore / nfp-common / nfp_resid.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Netronome Systems, Inc.
3 * All rights reserved.
4 */
5
6 #ifndef __NFP_RESID_H__
7 #define __NFP_RESID_H__
8
9 #if (!defined(_NFP_RESID_NO_C_FUNC) && \
10 (defined(__NFP_TOOL_NFCC) || defined(__NFP_TOOL_NFAS)))
11 #define _NFP_RESID_NO_C_FUNC
12 #endif
13
14 #ifndef _NFP_RESID_NO_C_FUNC
15 #include "nfp_platform.h"
16 #endif
17
18 /*
19 * NFP Chip Architectures
20 *
21 * These are semi-arbitrary values to indicate an NFP architecture.
22 * They serve as a software view of a group of chip families, not necessarily a
23 * direct mapping to actual hardware design.
24 */
25 #define NFP_CHIP_ARCH_YD 1
26 #define NFP_CHIP_ARCH_TH 2
27
28 /*
29 * NFP Chip Families.
30 *
31 * These are not enums, because they need to be microcode compatible.
32 * They are also not maskable.
33 *
34 * Note: The NFP-4xxx family is handled as NFP-6xxx in most software
35 * components.
36 *
37 */
38 #define NFP_CHIP_FAMILY_NFP6000 0x6000 /* ARCH_TH */
39
40 /* NFP Microengine/Flow Processing Core Versions */
41 #define NFP_CHIP_ME_VERSION_2_7 0x0207
42 #define NFP_CHIP_ME_VERSION_2_8 0x0208
43 #define NFP_CHIP_ME_VERSION_2_9 0x0209
44
45 /* NFP Chip Base Revisions. Minor stepping can just be added to these */
46 #define NFP_CHIP_REVISION_A0 0x00
47 #define NFP_CHIP_REVISION_B0 0x10
48 #define NFP_CHIP_REVISION_C0 0x20
49 #define NFP_CHIP_REVISION_PF 0xff /* Maximum possible revision */
50
51 /* CPP Targets for each chip architecture */
52 #define NFP6000_CPPTGT_NBI 1
53 #define NFP6000_CPPTGT_VQDR 2
54 #define NFP6000_CPPTGT_ILA 6
55 #define NFP6000_CPPTGT_MU 7
56 #define NFP6000_CPPTGT_PCIE 9
57 #define NFP6000_CPPTGT_ARM 10
58 #define NFP6000_CPPTGT_CRYPTO 12
59 #define NFP6000_CPPTGT_CTXPB 14
60 #define NFP6000_CPPTGT_CLS 15
61
62 /*
63 * Wildcard indicating a CPP read or write action
64 *
65 * The action used will be either read or write depending on whether a read or
66 * write instruction/call is performed on the NFP_CPP_ID. It is recomended that
67 * the RW action is used even if all actions to be performed on a NFP_CPP_ID are
68 * known to be only reads or writes. Doing so will in many cases save NFP CPP
69 * internal software resources.
70 */
71 #define NFP_CPP_ACTION_RW 32
72
73 #define NFP_CPP_TARGET_ID_MASK 0x1f
74
75 /*
76 * NFP_CPP_ID - pack target, token, and action into a CPP ID.
77 *
78 * Create a 32-bit CPP identifier representing the access to be made.
79 * These identifiers are used as parameters to other NFP CPP functions. Some
80 * CPP devices may allow wildcard identifiers to be specified.
81 *
82 * @param[in] target NFP CPP target id
83 * @param[in] action NFP CPP action id
84 * @param[in] token NFP CPP token id
85 * @return NFP CPP ID
86 */
87 #define NFP_CPP_ID(target, action, token) \
88 ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \
89 (((action) & 0xff) << 8))
90
91 #define NFP_CPP_ISLAND_ID(target, action, token, island) \
92 ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \
93 (((action) & 0xff) << 8) | (((island) & 0xff) << 0))
94
95 #ifndef _NFP_RESID_NO_C_FUNC
96
97 /**
98 * Return the NFP CPP target of a NFP CPP ID
99 * @param[in] id NFP CPP ID
100 * @return NFP CPP target
101 */
102 static inline uint8_t
103 NFP_CPP_ID_TARGET_of(uint32_t id)
104 {
105 return (id >> 24) & NFP_CPP_TARGET_ID_MASK;
106 }
107
108 /*
109 * Return the NFP CPP token of a NFP CPP ID
110 * @param[in] id NFP CPP ID
111 * @return NFP CPP token
112 */
113 static inline uint8_t
114 NFP_CPP_ID_TOKEN_of(uint32_t id)
115 {
116 return (id >> 16) & 0xff;
117 }
118
119 /*
120 * Return the NFP CPP action of a NFP CPP ID
121 * @param[in] id NFP CPP ID
122 * @return NFP CPP action
123 */
124 static inline uint8_t
125 NFP_CPP_ID_ACTION_of(uint32_t id)
126 {
127 return (id >> 8) & 0xff;
128 }
129
130 /*
131 * Return the NFP CPP action of a NFP CPP ID
132 * @param[in] id NFP CPP ID
133 * @return NFP CPP action
134 */
135 static inline uint8_t
136 NFP_CPP_ID_ISLAND_of(uint32_t id)
137 {
138 return (id) & 0xff;
139 }
140
141 #endif /* _NFP_RESID_NO_C_FUNC */
142
143 /*
144 * Check if @p chip_family is an ARCH_TH chip.
145 * @param chip_family One of NFP_CHIP_FAMILY_*
146 */
147 #define NFP_FAMILY_IS_ARCH_TH(chip_family) \
148 ((int)(chip_family) == (int)NFP_CHIP_FAMILY_NFP6000)
149
150 /*
151 * Get the NFP_CHIP_ARCH_* of @p chip_family.
152 * @param chip_family One of NFP_CHIP_FAMILY_*
153 */
154 #define NFP_FAMILY_ARCH(x) \
155 (__extension__ ({ \
156 typeof(x) _x = (x); \
157 (NFP_FAMILY_IS_ARCH_TH(_x) ? NFP_CHIP_ARCH_TH : \
158 NFP_FAMILY_IS_ARCH_YD(_x) ? NFP_CHIP_ARCH_YD : -1) \
159 }))
160
161 /*
162 * Check if @p chip_family is an NFP-6xxx chip.
163 * @param chip_family One of NFP_CHIP_FAMILY_*
164 */
165 #define NFP_FAMILY_IS_NFP6000(chip_family) \
166 ((int)(chip_family) == (int)NFP_CHIP_FAMILY_NFP6000)
167
168 /*
169 * Make microengine ID for NFP-6xxx.
170 * @param island_id Island ID.
171 * @param menum ME number, 0 based, within island.
172 *
173 * NOTE: menum should really be unsigned - MSC compiler throws error (not
174 * warning) if a clause is always true i.e. menum >= 0 if cluster_num is type
175 * unsigned int hence the cast of the menum to an int in that particular clause
176 */
177 #define NFP6000_MEID(a, b) \
178 (__extension__ ({ \
179 typeof(a) _a = (a); \
180 typeof(b) _b = (b); \
181 (((((int)(_a) & 0x3F) == (int)(_a)) && \
182 (((int)(_b) >= 0) && ((int)(_b) < 12))) ? \
183 (int)(((_a) << 4) | ((_b) + 4)) : -1) \
184 }))
185
186 /*
187 * Do a general sanity check on the ME ID.
188 * The check is on the highest possible island ID for the chip family and the
189 * microengine number must be a master ID.
190 * @param meid ME ID as created by NFP6000_MEID
191 */
192 #define NFP6000_MEID_IS_VALID(meid) \
193 (__extension__ ({ \
194 typeof(meid) _a = (meid); \
195 ((((_a) >> 4) < 64) && (((_a) >> 4) >= 0) && \
196 (((_a) & 0xF) >= 4)) \
197 }))
198
199 /*
200 * Extract island ID from ME ID.
201 * @param meid ME ID as created by NFP6000_MEID
202 */
203 #define NFP6000_MEID_ISLAND_of(meid) (((meid) >> 4) & 0x3F)
204
205 /*
206 * Extract microengine number (0 based) from ME ID.
207 * @param meid ME ID as created by NFP6000_MEID
208 */
209 #define NFP6000_MEID_MENUM_of(meid) (((meid) & 0xF) - 4)
210
211 /*
212 * Extract microengine group number (0 based) from ME ID.
213 * The group is two code-sharing microengines, so group 0 refers to MEs 0,1,
214 * group 1 refers to MEs 2,3 etc.
215 * @param meid ME ID as created by NFP6000_MEID
216 */
217 #define NFP6000_MEID_MEGRP_of(meid) (NFP6000_MEID_MENUM_of(meid) >> 1)
218
219 #ifndef _NFP_RESID_NO_C_FUNC
220
221 /*
222 * Convert a string to an ME ID.
223 *
224 * @param s A string of format iX.meY
225 * @param endptr If non-NULL, *endptr will point to the trailing string
226 * after the ME ID part of the string, which is either
227 * an empty string or the first character after the separating
228 * period.
229 * @return ME ID on success, -1 on error.
230 */
231 int nfp6000_idstr2meid(const char *s, const char **endptr);
232
233 /*
234 * Extract island ID from string.
235 *
236 * Example:
237 * char *c;
238 * int val = nfp6000_idstr2island("i32.me5", &c);
239 * // val == 32, c == "me5"
240 * val = nfp6000_idstr2island("i32", &c);
241 * // val == 32, c == ""
242 *
243 * @param s A string of format "iX.anything" or "iX"
244 * @param endptr If non-NULL, *endptr will point to the trailing string
245 * after the island part of the string, which is either
246 * an empty string or the first character after the separating
247 * period.
248 * @return If successful, the island ID, -1 on error.
249 */
250 int nfp6000_idstr2island(const char *s, const char **endptr);
251
252 /*
253 * Extract microengine number from string.
254 *
255 * Example:
256 * char *c;
257 * int menum = nfp6000_idstr2menum("me5.anything", &c);
258 * // menum == 5, c == "anything"
259 * menum = nfp6000_idstr2menum("me5", &c);
260 * // menum == 5, c == ""
261 *
262 * @param s A string of format "meX.anything" or "meX"
263 * @param endptr If non-NULL, *endptr will point to the trailing string
264 * after the ME number part of the string, which is either
265 * an empty string or the first character after the separating
266 * period.
267 * @return If successful, the ME number, -1 on error.
268 */
269 int nfp6000_idstr2menum(const char *s, const char **endptr);
270
271 /*
272 * Extract context number from string.
273 *
274 * Example:
275 * char *c;
276 * int val = nfp6000_idstr2ctxnum("ctx5.anything", &c);
277 * // val == 5, c == "anything"
278 * val = nfp6000_idstr2ctxnum("ctx5", &c);
279 * // val == 5, c == ""
280 *
281 * @param s A string of format "ctxN.anything" or "ctxN"
282 * @param endptr If non-NULL, *endptr will point to the trailing string
283 * after the context number part of the string, which is either
284 * an empty string or the first character after the separating
285 * period.
286 * @return If successful, the context number, -1 on error.
287 */
288 int nfp6000_idstr2ctxnum(const char *s, const char **endptr);
289
290 /*
291 * Extract microengine group number from string.
292 *
293 * Example:
294 * char *c;
295 * int val = nfp6000_idstr2megrp("tg2.anything", &c);
296 * // val == 2, c == "anything"
297 * val = nfp6000_idstr2megrp("tg5", &c);
298 * // val == 2, c == ""
299 *
300 * @param s A string of format "tgX.anything" or "tgX"
301 * @param endptr If non-NULL, *endptr will point to the trailing string
302 * after the ME group part of the string, which is either
303 * an empty string or the first character after the separating
304 * period.
305 * @return If successful, the ME group number, -1 on error.
306 */
307 int nfp6000_idstr2megrp(const char *s, const char **endptr);
308
309 /*
310 * Create ME ID string of format "iX[.meY]".
311 *
312 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
313 * The resulting string is output here.
314 * @param meid Microengine ID.
315 * @return Pointer to "s" on success, NULL on error.
316 */
317 const char *nfp6000_meid2str(char *s, int meid);
318
319 /*
320 * Create ME ID string of format "name[.meY]" or "iX[.meY]".
321 *
322 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
323 * The resulting string is output here.
324 * @param meid Microengine ID.
325 * @return Pointer to "s" on success, NULL on error.
326 *
327 * Similar to nfp6000_meid2str() except use an alias instead of "iX"
328 * if one exists for the island.
329 */
330 const char *nfp6000_meid2altstr(char *s, int meid);
331
332 /*
333 * Create string of format "iX".
334 *
335 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
336 * The resulting string is output here.
337 * @param island_id Island ID.
338 * @return Pointer to "s" on success, NULL on error.
339 */
340 const char *nfp6000_island2str(char *s, int island_id);
341
342 /*
343 * Create string of format "name", an island alias.
344 *
345 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
346 * The resulting string is output here.
347 * @param island_id Island ID.
348 * @return Pointer to "s" on success, NULL on error.
349 */
350 const char *nfp6000_island2altstr(char *s, int island_id);
351
352 /*
353 * Create string of format "meY".
354 *
355 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
356 * The resulting string is output here.
357 * @param menum Microengine number within island.
358 * @return Pointer to "s" on success, NULL on error.
359 */
360 const char *nfp6000_menum2str(char *s, int menum);
361
362 /*
363 * Create string of format "ctxY".
364 *
365 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
366 * The resulting string is output here.
367 * @param ctxnum Context number within microengine.
368 * @return Pointer to "s" on success, NULL on error.
369 */
370 const char *nfp6000_ctxnum2str(char *s, int ctxnum);
371
372 /*
373 * Create string of format "tgY".
374 *
375 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
376 * The resulting string is output here.
377 * @param megrp Microengine group number within cluster.
378 * @return Pointer to "s" on success, NULL on error.
379 */
380 const char *nfp6000_megrp2str(char *s, int megrp);
381
382 /*
383 * Convert a string to an ME ID.
384 *
385 * @param chip_family Chip family ID
386 * @param s A string of format iX.meY (or clX.meY)
387 * @param endptr If non-NULL, *endptr will point to the trailing
388 * string after the ME ID part of the string, which
389 * is either an empty string or the first character
390 * after the separating period.
391 * @return ME ID on success, -1 on error.
392 */
393 int nfp_idstr2meid(int chip_family, const char *s, const char **endptr);
394
395 /*
396 * Extract island ID from string.
397 *
398 * Example:
399 * char *c;
400 * int val = nfp_idstr2island(chip, "i32.me5", &c);
401 * // val == 32, c == "me5"
402 * val = nfp_idstr2island(chip, "i32", &c);
403 * // val == 32, c == ""
404 *
405 * @param chip_family Chip family ID
406 * @param s A string of format "iX.anything" or "iX"
407 * @param endptr If non-NULL, *endptr will point to the trailing
408 * striong after the ME ID part of the string, which
409 * is either an empty string or the first character
410 * after the separating period.
411 * @return The island ID on succes, -1 on error.
412 */
413 int nfp_idstr2island(int chip_family, const char *s, const char **endptr);
414
415 /*
416 * Extract microengine number from string.
417 *
418 * Example:
419 * char *c;
420 * int menum = nfp_idstr2menum("me5.anything", &c);
421 * // menum == 5, c == "anything"
422 * menum = nfp_idstr2menum("me5", &c);
423 * // menum == 5, c == ""
424 *
425 * @param chip_family Chip family ID
426 * @param s A string of format "meX.anything" or "meX"
427 * @param endptr If non-NULL, *endptr will point to the trailing
428 * striong after the ME ID part of the string, which
429 * is either an empty string or the first character
430 * after the separating period.
431 * @return The ME number on succes, -1 on error.
432 */
433 int nfp_idstr2menum(int chip_family, const char *s, const char **endptr);
434
435 /*
436 * Extract context number from string.
437 *
438 * Example:
439 * char *c;
440 * int val = nfp_idstr2ctxnum("ctx5.anything", &c);
441 * // val == 5, c == "anything"
442 * val = nfp_idstr2ctxnum("ctx5", &c);
443 * // val == 5, c == ""
444 *
445 * @param s A string of format "ctxN.anything" or "ctxN"
446 * @param endptr If non-NULL, *endptr will point to the trailing string
447 * after the context number part of the string, which is either
448 * an empty string or the first character after the separating
449 * period.
450 * @return If successful, the context number, -1 on error.
451 */
452 int nfp_idstr2ctxnum(int chip_family, const char *s, const char **endptr);
453
454 /*
455 * Extract microengine group number from string.
456 *
457 * Example:
458 * char *c;
459 * int val = nfp_idstr2megrp("tg2.anything", &c);
460 * // val == 2, c == "anything"
461 * val = nfp_idstr2megrp("tg5", &c);
462 * // val == 5, c == ""
463 *
464 * @param s A string of format "tgX.anything" or "tgX"
465 * @param endptr If non-NULL, *endptr will point to the trailing string
466 * after the ME group part of the string, which is either
467 * an empty string or the first character after the separating
468 * period.
469 * @return If successful, the ME group number, -1 on error.
470 */
471 int nfp_idstr2megrp(int chip_family, const char *s, const char **endptr);
472
473 /*
474 * Create ME ID string of format "iX[.meY]".
475 *
476 * @param chip_family Chip family ID
477 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
478 * The resulting string is output here.
479 * @param meid Microengine ID.
480 * @return Pointer to "s" on success, NULL on error.
481 */
482 const char *nfp_meid2str(int chip_family, char *s, int meid);
483
484 /*
485 * Create ME ID string of format "name[.meY]" or "iX[.meY]".
486 *
487 * @param chip_family Chip family ID
488 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
489 * The resulting string is output here.
490 * @param meid Microengine ID.
491 * @return Pointer to "s" on success, NULL on error.
492 *
493 * Similar to nfp_meid2str() except use an alias instead of "iX"
494 * if one exists for the island.
495 */
496 const char *nfp_meid2altstr(int chip_family, char *s, int meid);
497
498 /*
499 * Create string of format "iX".
500 *
501 * @param chip_family Chip family ID
502 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
503 * The resulting string is output here.
504 * @param island_id Island ID.
505 * @return Pointer to "s" on success, NULL on error.
506 */
507 const char *nfp_island2str(int chip_family, char *s, int island_id);
508
509 /*
510 * Create string of format "name", an island alias.
511 *
512 * @param chip_family Chip family ID
513 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
514 * The resulting string is output here.
515 * @param island_id Island ID.
516 * @return Pointer to "s" on success, NULL on error.
517 */
518 const char *nfp_island2altstr(int chip_family, char *s, int island_id);
519
520 /*
521 * Create string of format "meY".
522 *
523 * @param chip_family Chip family ID
524 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
525 * The resulting string is output here.
526 * @param menum Microengine number within island.
527 * @return Pointer to "s" on success, NULL on error.
528 */
529 const char *nfp_menum2str(int chip_family, char *s, int menum);
530
531 /*
532 * Create string of format "ctxY".
533 *
534 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
535 * The resulting string is output here.
536 * @param ctxnum Context number within microengine.
537 * @return Pointer to "s" on success, NULL on error.
538 */
539 const char *nfp_ctxnum2str(int chip_family, char *s, int ctxnum);
540
541 /*
542 * Create string of format "tgY".
543 *
544 * @param s Pointer to char buffer of size NFP_MEID_STR_SZ.
545 * The resulting string is output here.
546 * @param megrp Microengine group number within cluster.
547 * @return Pointer to "s" on success, NULL on error.
548 */
549 const char *nfp_megrp2str(int chip_family, char *s, int megrp);
550
551 /*
552 * Convert a two character string to revision number.
553 *
554 * Revision integer is 0x00 for A0, 0x11 for B1 etc.
555 *
556 * @param s Two character string.
557 * @return Revision number, -1 on error
558 */
559 int nfp_idstr2rev(const char *s);
560
561 /*
562 * Create string from revision number.
563 *
564 * String will be upper case.
565 *
566 * @param s Pointer to char buffer with size of at least 3
567 * for 2 characters and string terminator.
568 * @param rev Revision number.
569 * @return Pointer to "s" on success, NULL on error.
570 */
571 const char *nfp_rev2str(char *s, int rev);
572
573 /*
574 * Get the NFP CPP address from a string
575 *
576 * String is in the format [island@]target[:[action:[token:]]address]
577 *
578 * @param chip_family Chip family ID
579 * @param tid Pointer to string to parse
580 * @param cpp_idp Pointer to CPP ID
581 * @param cpp_addrp Pointer to CPP address
582 * @return 0 on success, or -1 and errno
583 */
584 int nfp_str2cpp(int chip_family,
585 const char *tid,
586 uint32_t *cpp_idp,
587 uint64_t *cpp_addrp);
588
589
590 #endif /* _NFP_RESID_NO_C_FUNC */
591
592 #endif /* __NFP_RESID_H__ */