]>
git.proxmox.com Git - ceph.git/blob - 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.
6 #ifndef __NFP_RESID_H__
7 #define __NFP_RESID_H__
9 #if (!defined(_NFP_RESID_NO_C_FUNC) && \
10 (defined(__NFP_TOOL_NFCC) || defined(__NFP_TOOL_NFAS)))
11 #define _NFP_RESID_NO_C_FUNC
14 #ifndef _NFP_RESID_NO_C_FUNC
15 #include "nfp_platform.h"
19 * NFP Chip Architectures
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.
25 #define NFP_CHIP_ARCH_YD 1
26 #define NFP_CHIP_ARCH_TH 2
31 * These are not enums, because they need to be microcode compatible.
32 * They are also not maskable.
34 * Note: The NFP-4xxx family is handled as NFP-6xxx in most software
38 #define NFP_CHIP_FAMILY_NFP6000 0x6000 /* ARCH_TH */
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
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 */
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
63 * Wildcard indicating a CPP read or write action
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.
71 #define NFP_CPP_ACTION_RW 32
73 #define NFP_CPP_TARGET_ID_MASK 0x1f
76 * NFP_CPP_ID - pack target, token, and action into a CPP ID.
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.
82 * @param[in] target NFP CPP target id
83 * @param[in] action NFP CPP action id
84 * @param[in] token NFP CPP token id
87 #define NFP_CPP_ID(target, action, token) \
88 ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \
89 (((action) & 0xff) << 8))
91 #define NFP_CPP_ISLAND_ID(target, action, token, island) \
92 ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \
93 (((action) & 0xff) << 8) | (((island) & 0xff) << 0))
95 #ifndef _NFP_RESID_NO_C_FUNC
98 * Return the NFP CPP target of a NFP CPP ID
99 * @param[in] id NFP CPP ID
100 * @return NFP CPP target
102 static inline uint8_t
103 NFP_CPP_ID_TARGET_of(uint32_t id
)
105 return (id
>> 24) & NFP_CPP_TARGET_ID_MASK
;
109 * Return the NFP CPP token of a NFP CPP ID
110 * @param[in] id NFP CPP ID
111 * @return NFP CPP token
113 static inline uint8_t
114 NFP_CPP_ID_TOKEN_of(uint32_t id
)
116 return (id
>> 16) & 0xff;
120 * Return the NFP CPP action of a NFP CPP ID
121 * @param[in] id NFP CPP ID
122 * @return NFP CPP action
124 static inline uint8_t
125 NFP_CPP_ID_ACTION_of(uint32_t id
)
127 return (id
>> 8) & 0xff;
131 * Return the NFP CPP action of a NFP CPP ID
132 * @param[in] id NFP CPP ID
133 * @return NFP CPP action
135 static inline uint8_t
136 NFP_CPP_ID_ISLAND_of(uint32_t id
)
141 #endif /* _NFP_RESID_NO_C_FUNC */
144 * Check if @p chip_family is an ARCH_TH chip.
145 * @param chip_family One of NFP_CHIP_FAMILY_*
147 #define NFP_FAMILY_IS_ARCH_TH(chip_family) \
148 ((int)(chip_family) == (int)NFP_CHIP_FAMILY_NFP6000)
151 * Get the NFP_CHIP_ARCH_* of @p chip_family.
152 * @param chip_family One of NFP_CHIP_FAMILY_*
154 #define NFP_FAMILY_ARCH(x) \
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) \
162 * Check if @p chip_family is an NFP-6xxx chip.
163 * @param chip_family One of NFP_CHIP_FAMILY_*
165 #define NFP_FAMILY_IS_NFP6000(chip_family) \
166 ((int)(chip_family) == (int)NFP_CHIP_FAMILY_NFP6000)
169 * Make microengine ID for NFP-6xxx.
170 * @param island_id Island ID.
171 * @param menum ME number, 0 based, within island.
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
177 #define NFP6000_MEID(a, b) \
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) \
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
192 #define NFP6000_MEID_IS_VALID(meid) \
194 typeof(meid) _a = (meid); \
195 ((((_a) >> 4) < 64) && (((_a) >> 4) >= 0) && \
196 (((_a) & 0xF) >= 4)) \
200 * Extract island ID from ME ID.
201 * @param meid ME ID as created by NFP6000_MEID
203 #define NFP6000_MEID_ISLAND_of(meid) (((meid) >> 4) & 0x3F)
206 * Extract microengine number (0 based) from ME ID.
207 * @param meid ME ID as created by NFP6000_MEID
209 #define NFP6000_MEID_MENUM_of(meid) (((meid) & 0xF) - 4)
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
217 #define NFP6000_MEID_MEGRP_of(meid) (NFP6000_MEID_MENUM_of(meid) >> 1)
219 #ifndef _NFP_RESID_NO_C_FUNC
222 * Convert a string to an ME ID.
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
229 * @return ME ID on success, -1 on error.
231 int nfp6000_idstr2meid(const char *s
, const char **endptr
);
234 * Extract island ID from string.
238 * int val = nfp6000_idstr2island("i32.me5", &c);
239 * // val == 32, c == "me5"
240 * val = nfp6000_idstr2island("i32", &c);
241 * // val == 32, c == ""
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
248 * @return If successful, the island ID, -1 on error.
250 int nfp6000_idstr2island(const char *s
, const char **endptr
);
253 * Extract microengine number from string.
257 * int menum = nfp6000_idstr2menum("me5.anything", &c);
258 * // menum == 5, c == "anything"
259 * menum = nfp6000_idstr2menum("me5", &c);
260 * // menum == 5, c == ""
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
267 * @return If successful, the ME number, -1 on error.
269 int nfp6000_idstr2menum(const char *s
, const char **endptr
);
272 * Extract context number from string.
276 * int val = nfp6000_idstr2ctxnum("ctx5.anything", &c);
277 * // val == 5, c == "anything"
278 * val = nfp6000_idstr2ctxnum("ctx5", &c);
279 * // val == 5, c == ""
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
286 * @return If successful, the context number, -1 on error.
288 int nfp6000_idstr2ctxnum(const char *s
, const char **endptr
);
291 * Extract microengine group number from string.
295 * int val = nfp6000_idstr2megrp("tg2.anything", &c);
296 * // val == 2, c == "anything"
297 * val = nfp6000_idstr2megrp("tg5", &c);
298 * // val == 2, c == ""
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
305 * @return If successful, the ME group number, -1 on error.
307 int nfp6000_idstr2megrp(const char *s
, const char **endptr
);
310 * Create ME ID string of format "iX[.meY]".
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.
317 const char *nfp6000_meid2str(char *s
, int meid
);
320 * Create ME ID string of format "name[.meY]" or "iX[.meY]".
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.
327 * Similar to nfp6000_meid2str() except use an alias instead of "iX"
328 * if one exists for the island.
330 const char *nfp6000_meid2altstr(char *s
, int meid
);
333 * Create string of format "iX".
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.
340 const char *nfp6000_island2str(char *s
, int island_id
);
343 * Create string of format "name", an island alias.
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.
350 const char *nfp6000_island2altstr(char *s
, int island_id
);
353 * Create string of format "meY".
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.
360 const char *nfp6000_menum2str(char *s
, int menum
);
363 * Create string of format "ctxY".
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.
370 const char *nfp6000_ctxnum2str(char *s
, int ctxnum
);
373 * Create string of format "tgY".
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.
380 const char *nfp6000_megrp2str(char *s
, int megrp
);
383 * Convert a string to an ME ID.
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.
393 int nfp_idstr2meid(int chip_family
, const char *s
, const char **endptr
);
396 * Extract island ID from string.
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 == ""
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.
413 int nfp_idstr2island(int chip_family
, const char *s
, const char **endptr
);
416 * Extract microengine number from string.
420 * int menum = nfp_idstr2menum("me5.anything", &c);
421 * // menum == 5, c == "anything"
422 * menum = nfp_idstr2menum("me5", &c);
423 * // menum == 5, c == ""
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.
433 int nfp_idstr2menum(int chip_family
, const char *s
, const char **endptr
);
436 * Extract context number from string.
440 * int val = nfp_idstr2ctxnum("ctx5.anything", &c);
441 * // val == 5, c == "anything"
442 * val = nfp_idstr2ctxnum("ctx5", &c);
443 * // val == 5, c == ""
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
450 * @return If successful, the context number, -1 on error.
452 int nfp_idstr2ctxnum(int chip_family
, const char *s
, const char **endptr
);
455 * Extract microengine group number from string.
459 * int val = nfp_idstr2megrp("tg2.anything", &c);
460 * // val == 2, c == "anything"
461 * val = nfp_idstr2megrp("tg5", &c);
462 * // val == 5, c == ""
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
469 * @return If successful, the ME group number, -1 on error.
471 int nfp_idstr2megrp(int chip_family
, const char *s
, const char **endptr
);
474 * Create ME ID string of format "iX[.meY]".
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.
482 const char *nfp_meid2str(int chip_family
, char *s
, int meid
);
485 * Create ME ID string of format "name[.meY]" or "iX[.meY]".
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.
493 * Similar to nfp_meid2str() except use an alias instead of "iX"
494 * if one exists for the island.
496 const char *nfp_meid2altstr(int chip_family
, char *s
, int meid
);
499 * Create string of format "iX".
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.
507 const char *nfp_island2str(int chip_family
, char *s
, int island_id
);
510 * Create string of format "name", an island alias.
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.
518 const char *nfp_island2altstr(int chip_family
, char *s
, int island_id
);
521 * Create string of format "meY".
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.
529 const char *nfp_menum2str(int chip_family
, char *s
, int menum
);
532 * Create string of format "ctxY".
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.
539 const char *nfp_ctxnum2str(int chip_family
, char *s
, int ctxnum
);
542 * Create string of format "tgY".
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.
549 const char *nfp_megrp2str(int chip_family
, char *s
, int megrp
);
552 * Convert a two character string to revision number.
554 * Revision integer is 0x00 for A0, 0x11 for B1 etc.
556 * @param s Two character string.
557 * @return Revision number, -1 on error
559 int nfp_idstr2rev(const char *s
);
562 * Create string from revision number.
564 * String will be upper case.
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.
571 const char *nfp_rev2str(char *s
, int rev
);
574 * Get the NFP CPP address from a string
576 * String is in the format [island@]target[:[action:[token:]]address]
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
584 int nfp_str2cpp(int chip_family
,
587 uint64_t *cpp_addrp
);
590 #endif /* _NFP_RESID_NO_C_FUNC */
592 #endif /* __NFP_RESID_H__ */