a54f435b4660981d82b635766c889477a671c74a
[dpdk.git] / drivers / common / cnxk / roc_model.h
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
27         uint64_t flag;
28 #define ROC_MODEL_STR_LEN_MAX 128
29         char name[ROC_MODEL_STR_LEN_MAX];
30 } __plt_cache_aligned;
31
32 #define ROC_MODEL_CN96xx_Ax (ROC_MODEL_CN96xx_A0 | ROC_MODEL_CN96xx_B0)
33 #define ROC_MODEL_CN9K                                                         \
34         (ROC_MODEL_CN96xx_Ax | ROC_MODEL_CN96xx_C0 | ROC_MODEL_CNF95xx_A0 |    \
35          ROC_MODEL_CNF95xx_B0 | ROC_MODEL_CNF95xxMM_A0 |                       \
36          ROC_MODEL_CNF95xxO_A0 | ROC_MODEL_CNF95xxN_A0 | ROC_MODEL_CN98xx_A0 | \
37          ROC_MODEL_CNF95xxN_A1)
38
39 #define ROC_MODEL_CN106xx   (ROC_MODEL_CN106xx_A0)
40 #define ROC_MODEL_CNF105xx  (ROC_MODEL_CNF105xx_A0)
41 #define ROC_MODEL_CNF105xxN (ROC_MODEL_CNF105xxN_A0)
42 #define ROC_MODEL_CN10K                                                        \
43         (ROC_MODEL_CN106xx | ROC_MODEL_CNF105xx | ROC_MODEL_CNF105xxN)
44
45 /* Runtime variants */
46 static inline uint64_t
47 roc_model_runtime_is_cn9k(void)
48 {
49         return (roc_model->flag & (ROC_MODEL_CN9K));
50 }
51
52 static inline uint64_t
53 roc_model_runtime_is_cn10k(void)
54 {
55         return (roc_model->flag & (ROC_MODEL_CN10K));
56 }
57
58 /* Compile time variants */
59 #ifdef ROC_PLATFORM_CN9K
60 #define roc_model_constant_is_cn9k()  1
61 #define roc_model_constant_is_cn10k() 0
62 #else
63 #define roc_model_constant_is_cn9k()  0
64 #define roc_model_constant_is_cn10k() 1
65 #endif
66
67 /*
68  * Compile time variants to enable optimized version check when the library
69  * configured for specific platform version else to fallback to runtime.
70  */
71 static inline uint64_t
72 roc_model_is_cn9k(void)
73 {
74 #ifdef ROC_PLATFORM_CN9K
75         return 1;
76 #endif
77 #ifdef ROC_PLATFORM_CN10K
78         return 0;
79 #endif
80         return roc_model_runtime_is_cn9k();
81 }
82
83 static inline uint64_t
84 roc_model_is_cn10k(void)
85 {
86 #ifdef ROC_PLATFORM_CN10K
87         return 1;
88 #endif
89 #ifdef ROC_PLATFORM_CN9K
90         return 0;
91 #endif
92         return roc_model_runtime_is_cn10k();
93 }
94
95 static inline uint64_t
96 roc_model_is_cn98xx(void)
97 {
98         return (roc_model->flag & ROC_MODEL_CN98xx_A0);
99 }
100
101 static inline uint64_t
102 roc_model_is_cn96_a0(void)
103 {
104         return roc_model->flag & ROC_MODEL_CN96xx_A0;
105 }
106
107 static inline uint64_t
108 roc_model_is_cn96_ax(void)
109 {
110         return (roc_model->flag & ROC_MODEL_CN96xx_Ax);
111 }
112
113 static inline uint64_t
114 roc_model_is_cn96_cx(void)
115 {
116         return (roc_model->flag & ROC_MODEL_CN96xx_C0);
117 }
118
119 static inline uint64_t
120 roc_model_is_cn95_a0(void)
121 {
122         return roc_model->flag & ROC_MODEL_CNF95xx_A0;
123 }
124
125 static inline uint64_t
126 roc_model_is_cn10ka(void)
127 {
128         return roc_model->flag & ROC_MODEL_CN106xx;
129 }
130
131 static inline uint64_t
132 roc_model_is_cnf10ka(void)
133 {
134         return roc_model->flag & ROC_MODEL_CNF105xx;
135 }
136
137 static inline uint64_t
138 roc_model_is_cnf10kb(void)
139 {
140         return roc_model->flag & ROC_MODEL_CNF105xxN;
141 }
142
143 static inline uint64_t
144 roc_model_is_cn10ka_a0(void)
145 {
146         return roc_model->flag & ROC_MODEL_CN106xx_A0;
147 }
148
149 static inline uint64_t
150 roc_model_is_cnf10ka_a0(void)
151 {
152         return roc_model->flag & ROC_MODEL_CNF105xx_A0;
153 }
154
155 static inline uint64_t
156 roc_model_is_cnf10kb_a0(void)
157 {
158         return roc_model->flag & ROC_MODEL_CNF105xxN_A0;
159 }
160
161 int roc_model_init(struct roc_model *model);
162
163 #endif