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 extern struct roc_model *roc_model; 11 12 struct roc_model { 13 #define ROC_MODEL_CN96xx_A0 BIT_ULL(0) 14 #define ROC_MODEL_CN96xx_B0 BIT_ULL(1) 15 #define ROC_MODEL_CN96xx_C0 BIT_ULL(2) 16 #define ROC_MODEL_CNF95xx_A0 BIT_ULL(4) 17 #define ROC_MODEL_CNF95xx_B0 BIT_ULL(6) 18 #define ROC_MODEL_CNF95XXMM_A0 BIT_ULL(8) 19 #define ROC_MODEL_CNF95XXN_A0 BIT_ULL(12) 20 #define ROC_MODEL_CNF95XXO_A0 BIT_ULL(13) 21 #define ROC_MODEL_CN98xx_A0 BIT_ULL(16) 22 #define ROC_MODEL_CN106XX BIT_ULL(20) 23 #define ROC_MODEL_CNF105XX BIT_ULL(21) 24 #define ROC_MODEL_CNF105XXN BIT_ULL(22) 25 26 uint64_t flag; 27 #define ROC_MODEL_STR_LEN_MAX 128 28 char name[ROC_MODEL_STR_LEN_MAX]; 29 } __plt_cache_aligned; 30 31 #define ROC_MODEL_CN96xx_Ax (ROC_MODEL_CN96xx_A0 | ROC_MODEL_CN96xx_B0) 32 #define ROC_MODEL_CN9K \ 33 (ROC_MODEL_CN96xx_Ax | ROC_MODEL_CN96xx_C0 | ROC_MODEL_CNF95xx_A0 | \ 34 ROC_MODEL_CNF95xx_B0 | ROC_MODEL_CNF95XXMM_A0 | \ 35 ROC_MODEL_CNF95XXO_A0 | ROC_MODEL_CNF95XXN_A0 | ROC_MODEL_CN98xx_A0) 36 37 #define ROC_MODEL_CN10K \ 38 (ROC_MODEL_CN106XX | ROC_MODEL_CNF105XX | ROC_MODEL_CNF105XXN) 39 40 /* Runtime variants */ 41 static inline uint64_t 42 roc_model_runtime_is_cn9k(void) 43 { 44 return (roc_model->flag & (ROC_MODEL_CN9K)); 45 } 46 47 static inline uint64_t 48 roc_model_runtime_is_cn10k(void) 49 { 50 return (roc_model->flag & (ROC_MODEL_CN10K)); 51 } 52 53 /* Compile time variants */ 54 #ifdef ROC_PLATFORM_CN9K 55 #define roc_model_constant_is_cn9k() 1 56 #define roc_model_constant_is_cn10k() 0 57 #else 58 #define roc_model_constant_is_cn9k() 0 59 #define roc_model_constant_is_cn10k() 1 60 #endif 61 62 /* 63 * Compile time variants to enable optimized version check when the library 64 * configured for specific platform version else to fallback to runtime. 65 */ 66 static inline uint64_t 67 roc_model_is_cn9k(void) 68 { 69 #ifdef ROC_PLATFORM_CN9K 70 return 1; 71 #endif 72 #ifdef ROC_PLATFORM_CN10K 73 return 0; 74 #endif 75 return roc_model_runtime_is_cn9k(); 76 } 77 78 static inline uint64_t 79 roc_model_is_cn10k(void) 80 { 81 #ifdef ROC_PLATFORM_CN10K 82 return 1; 83 #endif 84 #ifdef ROC_PLATFORM_CN9K 85 return 0; 86 #endif 87 return roc_model_runtime_is_cn10k(); 88 } 89 90 static inline uint64_t 91 roc_model_is_cn98xx(void) 92 { 93 return (roc_model->flag & ROC_MODEL_CN98xx_A0); 94 } 95 96 static inline uint64_t 97 roc_model_is_cn96_a0(void) 98 { 99 return roc_model->flag & ROC_MODEL_CN96xx_A0; 100 } 101 102 static inline uint64_t 103 roc_model_is_cn96_ax(void) 104 { 105 return (roc_model->flag & ROC_MODEL_CN96xx_Ax); 106 } 107 108 static inline uint64_t 109 roc_model_is_cn95_a0(void) 110 { 111 return roc_model->flag & ROC_MODEL_CNF95xx_A0; 112 } 113 114 static inline uint64_t 115 roc_model_is_cn10ka(void) 116 { 117 return roc_model->flag & ROC_MODEL_CN106XX; 118 } 119 120 static inline uint64_t 121 roc_model_is_cnf10ka(void) 122 { 123 return roc_model->flag & ROC_MODEL_CNF105XX; 124 } 125 126 static inline uint64_t 127 roc_model_is_cnf10kb(void) 128 { 129 return roc_model->flag & ROC_MODEL_CNF105XXN; 130 } 131 132 int roc_model_init(struct roc_model *model); 133 134 #endif 135