Branch data Line data Source code
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 : : 12 : : extern struct roc_model *roc_model; 13 : : 14 : : struct roc_model { 15 : : #define ROC_MODEL_CN96xx_A0 BIT_ULL(0) 16 : : #define ROC_MODEL_CN96xx_B0 BIT_ULL(1) 17 : : #define ROC_MODEL_CN96xx_C0 BIT_ULL(2) 18 : : #define ROC_MODEL_CNF95xx_A0 BIT_ULL(4) 19 : : #define ROC_MODEL_CNF95xx_B0 BIT_ULL(6) 20 : : #define ROC_MODEL_CNF95xxMM_A0 BIT_ULL(8) 21 : : #define ROC_MODEL_CNF95xxN_A0 BIT_ULL(12) 22 : : #define ROC_MODEL_CNF95xxO_A0 BIT_ULL(13) 23 : : #define ROC_MODEL_CNF95xxN_A1 BIT_ULL(14) 24 : : #define ROC_MODEL_CNF95xxN_B0 BIT_ULL(15) 25 : : #define ROC_MODEL_CN98xx_A0 BIT_ULL(16) 26 : : #define ROC_MODEL_CN98xx_A1 BIT_ULL(17) 27 : : #define ROC_MODEL_CN106xx_A0 BIT_ULL(20) 28 : : #define ROC_MODEL_CNF105xx_A0 BIT_ULL(21) 29 : : #define ROC_MODEL_CNF105xxN_A0 BIT_ULL(22) 30 : : #define ROC_MODEL_CN103xx_A0 BIT_ULL(23) 31 : : #define ROC_MODEL_CN106xx_A1 BIT_ULL(24) 32 : : #define ROC_MODEL_CNF105xx_A1 BIT_ULL(25) 33 : : #define ROC_MODEL_CN106xx_B0 BIT_ULL(26) 34 : : #define ROC_MODEL_CNF105xxN_B0 BIT_ULL(27) 35 : : /* Following flags describe platform code is running on */ 36 : : #define ROC_ENV_HW BIT_ULL(61) 37 : : #define ROC_ENV_EMUL BIT_ULL(62) 38 : : #define ROC_ENV_ASIM BIT_ULL(63) 39 : : 40 : : uint64_t flag; 41 : : #define ROC_MODEL_STR_LEN_MAX 128 42 : : char name[ROC_MODEL_STR_LEN_MAX]; 43 : : char env[ROC_MODEL_STR_LEN_MAX]; 44 : : } __plt_cache_aligned; 45 : : 46 : : #define ROC_MODEL_CN96xx_Ax (ROC_MODEL_CN96xx_A0 | ROC_MODEL_CN96xx_B0) 47 : : #define ROC_MODEL_CN98xx_Ax (ROC_MODEL_CN98xx_A0 | ROC_MODEL_CN98xx_A1) 48 : : #define ROC_MODEL_CN9K \ 49 : : (ROC_MODEL_CN96xx_Ax | ROC_MODEL_CN96xx_C0 | ROC_MODEL_CNF95xx_A0 | \ 50 : : ROC_MODEL_CNF95xx_B0 | ROC_MODEL_CNF95xxMM_A0 | \ 51 : : ROC_MODEL_CNF95xxO_A0 | ROC_MODEL_CNF95xxN_A0 | ROC_MODEL_CN98xx_Ax | \ 52 : : ROC_MODEL_CNF95xxN_A1 | ROC_MODEL_CNF95xxN_B0) 53 : : #define ROC_MODEL_CNF9K \ 54 : : (ROC_MODEL_CNF95xx_A0 | ROC_MODEL_CNF95xx_B0 | \ 55 : : ROC_MODEL_CNF95xxMM_A0 | ROC_MODEL_CNF95xxO_A0 | \ 56 : : ROC_MODEL_CNF95xxN_A0 | ROC_MODEL_CNF95xxN_A1 | \ 57 : : ROC_MODEL_CNF95xxN_B0) 58 : : 59 : : #define ROC_MODEL_CN106xx (ROC_MODEL_CN106xx_A0 | ROC_MODEL_CN106xx_A1 | ROC_MODEL_CN106xx_B0) 60 : : #define ROC_MODEL_CNF105xx (ROC_MODEL_CNF105xx_A0 | ROC_MODEL_CNF105xx_A1) 61 : : #define ROC_MODEL_CNF105xxN (ROC_MODEL_CNF105xxN_A0 | ROC_MODEL_CNF105xxN_B0) 62 : : #define ROC_MODEL_CN103xx (ROC_MODEL_CN103xx_A0) 63 : : #define ROC_MODEL_CN10K \ 64 : : (ROC_MODEL_CN106xx | ROC_MODEL_CNF105xx | ROC_MODEL_CNF105xxN | \ 65 : : ROC_MODEL_CN103xx) 66 : : #define ROC_MODEL_CNF10K (ROC_MODEL_CNF105xx | ROC_MODEL_CNF105xxN) 67 : : 68 : : /* Runtime variants */ 69 : : static inline uint64_t 70 : : roc_model_runtime_is_cn9k(void) 71 : : { 72 [ # # # # : 0 : return (roc_model->flag & (ROC_MODEL_CN9K)); # # # # # # # # # # # # # # # # # # # # ] 73 : : } 74 : : 75 : : static inline uint64_t 76 : : roc_model_runtime_is_cn10k(void) 77 : : { 78 [ # # # # : 0 : return (roc_model->flag & (ROC_MODEL_CN10K)); # # # # # # # # # # # # # # ] 79 : : } 80 : : 81 : : /* Compile time variants */ 82 : : #ifdef ROC_PLATFORM_CN9K 83 : : #define roc_model_constant_is_cn9k() 1 84 : : #define roc_model_constant_is_cn10k() 0 85 : : #else 86 : : #define roc_model_constant_is_cn9k() 0 87 : : #define roc_model_constant_is_cn10k() 1 88 : : #endif 89 : : 90 : : /* 91 : : * Compile time variants to enable optimized version check when the library 92 : : * configured for specific platform version else to fallback to runtime. 93 : : */ 94 : : static inline uint64_t 95 : : roc_model_is_cn9k(void) 96 : : { 97 : : #ifdef ROC_PLATFORM_CN9K 98 : : return 1; 99 : : #endif 100 : : #ifdef ROC_PLATFORM_CN10K 101 : : return 0; 102 : : #endif 103 : : return roc_model_runtime_is_cn9k(); 104 : : } 105 : : 106 : : static inline uint64_t 107 : : roc_model_is_cn10k(void) 108 : : { 109 : : #ifdef ROC_PLATFORM_CN10K 110 : : return 1; 111 : : #endif 112 : : #ifdef ROC_PLATFORM_CN9K 113 : : return 0; 114 : : #endif 115 : : return roc_model_runtime_is_cn10k(); 116 : : } 117 : : 118 : : static inline uint64_t 119 : : roc_model_is_cn98xx(void) 120 : : { 121 [ # # # # ]: 0 : return (roc_model->flag & ROC_MODEL_CN98xx_Ax); 122 : : } 123 : : 124 : : static inline uint64_t 125 : : roc_model_is_cn98xx_a0(void) 126 : : { 127 : : return (roc_model->flag & ROC_MODEL_CN98xx_A0); 128 : : } 129 : : 130 : : static inline uint64_t 131 : : roc_model_is_cn98xx_a1(void) 132 : : { 133 : : return (roc_model->flag & ROC_MODEL_CN98xx_A1); 134 : : } 135 : : 136 : : static inline uint64_t 137 : : roc_model_is_cn96_a0(void) 138 : : { 139 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CN96xx_A0; # # ] 140 : : } 141 : : 142 : : static inline uint64_t 143 : : roc_model_is_cn96_ax(void) 144 : : { 145 [ # # # # ]: 0 : return (roc_model->flag & ROC_MODEL_CN96xx_Ax); 146 : : } 147 : : 148 : : static inline uint64_t 149 : : roc_model_is_cn96_b0(void) 150 : : { 151 [ # # ]: 0 : return (roc_model->flag & ROC_MODEL_CN96xx_B0); 152 : : } 153 : : 154 : : static inline uint64_t 155 : : roc_model_is_cn96_cx(void) 156 : : { 157 [ # # ]: 0 : return (roc_model->flag & ROC_MODEL_CN96xx_C0); 158 : : } 159 : : 160 : : static inline uint64_t 161 : : roc_model_is_cn95_a0(void) 162 : : { 163 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CNF95xx_A0; # # # # ] 164 : : } 165 : : 166 : : static inline uint64_t 167 : : roc_model_is_cnf95xxn_a0(void) 168 : : { 169 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CNF95xxN_A0; # # ] 170 : : } 171 : : 172 : : static inline uint64_t 173 : : roc_model_is_cnf95xxn_a1(void) 174 : : { 175 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CNF95xxN_A1; # # ] 176 : : } 177 : : 178 : : static inline uint64_t 179 : : roc_model_is_cnf95xxn_b0(void) 180 : : { 181 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CNF95xxN_B0; # # ] 182 : : } 183 : : 184 : : static inline uint64_t 185 : : roc_model_is_cnf95xxo_a0(void) 186 : : { 187 [ # # ]: 0 : return roc_model->flag & ROC_MODEL_CNF95xxO_A0; 188 : : } 189 : : 190 : : static inline uint16_t 191 : : roc_model_is_cn95xxn_a0(void) 192 : : { 193 : : return roc_model->flag & ROC_MODEL_CNF95xxN_A0; 194 : : } 195 : : 196 : : static inline uint64_t 197 : : roc_model_is_cn10ka(void) 198 : : { 199 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CN106xx; # # ] 200 : : } 201 : : 202 : : static inline uint64_t 203 : : roc_model_is_cnf10ka(void) 204 : : { 205 : : return roc_model->flag & ROC_MODEL_CNF105xx; 206 : : } 207 : : 208 : : static inline uint64_t 209 : : roc_model_is_cnf10kb(void) 210 : : { 211 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CNF105xxN; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ] 212 : : } 213 : : 214 : : static inline uint64_t 215 : : roc_model_is_cn10kb_a0(void) 216 : : { 217 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CN103xx_A0; # # # # ] 218 : : } 219 : : 220 : : static inline uint64_t 221 : : roc_model_is_cn10ka_a0(void) 222 : : { 223 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CN106xx_A0; # # # # # # ] 224 : : } 225 : : 226 : : static inline uint64_t 227 : : roc_model_is_cn10ka_a1(void) 228 : : { 229 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CN106xx_A1; # # # # # # ] 230 : : } 231 : : 232 : : static inline uint64_t 233 : : roc_model_is_cn10ka_b0(void) 234 : : { 235 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CN106xx_B0; # # ] 236 : : } 237 : : 238 : : static inline uint64_t 239 : : roc_model_is_cnf10ka_a0(void) 240 : : { 241 [ # # # # ]: 0 : return roc_model->flag & ROC_MODEL_CNF105xx_A0; 242 : : } 243 : : 244 : : static inline uint64_t 245 : : roc_model_is_cnf10ka_a1(void) 246 : : { 247 : : return roc_model->flag & ROC_MODEL_CNF105xx_A1; 248 : : } 249 : : 250 : : static inline uint64_t 251 : : roc_model_is_cnf10kb_a0(void) 252 : : { 253 [ # # # # ]: 0 : return roc_model->flag & ROC_MODEL_CNF105xxN_A0; 254 : : } 255 : : 256 : : static inline uint64_t 257 : : roc_model_is_cnf10kb_b0(void) 258 : : { 259 : : return roc_model->flag & ROC_MODEL_CNF105xxN_B0; 260 : : } 261 : : 262 : : static inline uint64_t 263 : : roc_model_is_cn10kb(void) 264 : : { 265 [ # # # # : 0 : return roc_model->flag & ROC_MODEL_CN103xx; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ] 266 : : } 267 : : 268 : : static inline bool 269 : : roc_env_is_hw(void) 270 : : { 271 [ # # # # ]: 0 : return roc_model->flag & ROC_ENV_HW; 272 : : } 273 : : 274 : : static inline bool 275 : : roc_env_is_emulator(void) 276 : : { 277 [ # # # # ]: 0 : return roc_model->flag & ROC_ENV_EMUL; 278 : : } 279 : : 280 : : static inline bool 281 : : roc_env_is_asim(void) 282 : : { 283 [ # # ]: 0 : return roc_model->flag & ROC_ENV_ASIM; 284 : : } 285 : : 286 : : static inline const char * 287 : : roc_env_get(void) 288 : : { 289 : : return roc_model->env; 290 : : } 291 : : 292 : : int roc_model_init(struct roc_model *model); 293 : : 294 : : #endif