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