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_CNF95xxN_A1 BIT_ULL(14) 22 #define ROC_MODEL_CNF95xxN_B0 BIT_ULL(15) 23 #define ROC_MODEL_CN98xx_A0 BIT_ULL(16) 24 #define ROC_MODEL_CN106xx_A0 BIT_ULL(20) 25 #define ROC_MODEL_CNF105xx_A0 BIT_ULL(21) 26 #define ROC_MODEL_CNF105xxN_A0 BIT_ULL(22) 27 /* Following flags describe platform code is running on */ 28 #define ROC_ENV_HW BIT_ULL(61) 29 #define ROC_ENV_EMUL BIT_ULL(62) 30 #define ROC_ENV_ASIM BIT_ULL(63) 31 32 uint64_t flag; 33 #define ROC_MODEL_STR_LEN_MAX 128 34 char name[ROC_MODEL_STR_LEN_MAX]; 35 char env[ROC_MODEL_STR_LEN_MAX]; 36 } __plt_cache_aligned; 37 38 #define ROC_MODEL_CN96xx_Ax (ROC_MODEL_CN96xx_A0 | ROC_MODEL_CN96xx_B0) 39 #define ROC_MODEL_CN9K \ 40 (ROC_MODEL_CN96xx_Ax | ROC_MODEL_CN96xx_C0 | ROC_MODEL_CNF95xx_A0 | \ 41 ROC_MODEL_CNF95xx_B0 | ROC_MODEL_CNF95xxMM_A0 | \ 42 ROC_MODEL_CNF95xxO_A0 | ROC_MODEL_CNF95xxN_A0 | ROC_MODEL_CN98xx_A0 | \ 43 ROC_MODEL_CNF95xxN_A1 | ROC_MODEL_CNF95xxN_B0) 44 #define ROC_MODEL_CNF9K \ 45 (ROC_MODEL_CNF95xx_A0 | ROC_MODEL_CNF95xx_B0 | \ 46 ROC_MODEL_CNF95xxMM_A0 | ROC_MODEL_CNF95xxO_A0 | \ 47 ROC_MODEL_CNF95xxN_A0 | ROC_MODEL_CNF95xxN_A1 | \ 48 ROC_MODEL_CNF95xxN_B0) 49 50 #define ROC_MODEL_CN106xx (ROC_MODEL_CN106xx_A0) 51 #define ROC_MODEL_CNF105xx (ROC_MODEL_CNF105xx_A0) 52 #define ROC_MODEL_CNF105xxN (ROC_MODEL_CNF105xxN_A0) 53 #define ROC_MODEL_CN10K \ 54 (ROC_MODEL_CN106xx | ROC_MODEL_CNF105xx | ROC_MODEL_CNF105xxN) 55 #define ROC_MODEL_CNF10K (ROC_MODEL_CNF105xx | ROC_MODEL_CNF105xxN) 56 57 /* Runtime variants */ 58 static inline uint64_t roc_model_runtime_is_cn9k(void)59roc_model_runtime_is_cn9k(void) 60 { 61 return (roc_model->flag & (ROC_MODEL_CN9K)); 62 } 63 64 static inline uint64_t roc_model_runtime_is_cn10k(void)65roc_model_runtime_is_cn10k(void) 66 { 67 return (roc_model->flag & (ROC_MODEL_CN10K)); 68 } 69 70 /* Compile time variants */ 71 #ifdef ROC_PLATFORM_CN9K 72 #define roc_model_constant_is_cn9k() 1 73 #define roc_model_constant_is_cn10k() 0 74 #else 75 #define roc_model_constant_is_cn9k() 0 76 #define roc_model_constant_is_cn10k() 1 77 #endif 78 79 /* 80 * Compile time variants to enable optimized version check when the library 81 * configured for specific platform version else to fallback to runtime. 82 */ 83 static inline uint64_t roc_model_is_cn9k(void)84roc_model_is_cn9k(void) 85 { 86 #ifdef ROC_PLATFORM_CN9K 87 return 1; 88 #endif 89 #ifdef ROC_PLATFORM_CN10K 90 return 0; 91 #endif 92 return roc_model_runtime_is_cn9k(); 93 } 94 95 static inline uint64_t roc_model_is_cn10k(void)96roc_model_is_cn10k(void) 97 { 98 #ifdef ROC_PLATFORM_CN10K 99 return 1; 100 #endif 101 #ifdef ROC_PLATFORM_CN9K 102 return 0; 103 #endif 104 return roc_model_runtime_is_cn10k(); 105 } 106 107 static inline uint64_t roc_model_is_cn98xx(void)108roc_model_is_cn98xx(void) 109 { 110 return (roc_model->flag & ROC_MODEL_CN98xx_A0); 111 } 112 113 static inline uint64_t roc_model_is_cn96_a0(void)114roc_model_is_cn96_a0(void) 115 { 116 return roc_model->flag & ROC_MODEL_CN96xx_A0; 117 } 118 119 static inline uint64_t roc_model_is_cn96_ax(void)120roc_model_is_cn96_ax(void) 121 { 122 return (roc_model->flag & ROC_MODEL_CN96xx_Ax); 123 } 124 125 static inline uint64_t roc_model_is_cn96_cx(void)126roc_model_is_cn96_cx(void) 127 { 128 return (roc_model->flag & ROC_MODEL_CN96xx_C0); 129 } 130 131 static inline uint64_t roc_model_is_cn95_a0(void)132roc_model_is_cn95_a0(void) 133 { 134 return roc_model->flag & ROC_MODEL_CNF95xx_A0; 135 } 136 137 static inline uint64_t roc_model_is_cn10ka(void)138roc_model_is_cn10ka(void) 139 { 140 return roc_model->flag & ROC_MODEL_CN106xx; 141 } 142 143 static inline uint64_t roc_model_is_cnf10ka(void)144roc_model_is_cnf10ka(void) 145 { 146 return roc_model->flag & ROC_MODEL_CNF105xx; 147 } 148 149 static inline uint64_t roc_model_is_cnf10kb(void)150roc_model_is_cnf10kb(void) 151 { 152 return roc_model->flag & ROC_MODEL_CNF105xxN; 153 } 154 155 static inline uint64_t roc_model_is_cn10ka_a0(void)156roc_model_is_cn10ka_a0(void) 157 { 158 return roc_model->flag & ROC_MODEL_CN106xx_A0; 159 } 160 161 static inline uint64_t roc_model_is_cnf10ka_a0(void)162roc_model_is_cnf10ka_a0(void) 163 { 164 return roc_model->flag & ROC_MODEL_CNF105xx_A0; 165 } 166 167 static inline uint64_t roc_model_is_cnf10kb_a0(void)168roc_model_is_cnf10kb_a0(void) 169 { 170 return roc_model->flag & ROC_MODEL_CNF105xxN_A0; 171 } 172 173 static inline bool roc_env_is_hw(void)174roc_env_is_hw(void) 175 { 176 return roc_model->flag & ROC_ENV_HW; 177 } 178 179 static inline bool roc_env_is_emulator(void)180roc_env_is_emulator(void) 181 { 182 return roc_model->flag & ROC_ENV_EMUL; 183 } 184 185 static inline bool roc_env_is_asim(void)186roc_env_is_asim(void) 187 { 188 return roc_model->flag & ROC_ENV_ASIM; 189 } 190 191 static inline const char * roc_env_get(void)192roc_env_get(void) 193 { 194 return roc_model->env; 195 } 196 197 int roc_model_init(struct roc_model *model); 198 199 #endif 200