xref: /dpdk/drivers/net/ntnic/include/hw_mod_backend.h (revision 7fadd2ba32137dae8cfe1e4634c1b67a6d29e35a)
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright(c) 2023 Napatech A/S
4  */
5 
6 #ifndef _HW_MOD_BACKEND_H_
7 #define _HW_MOD_BACKEND_H_
8 
9 #include <stdbool.h>
10 #include <string.h>
11 
12 #include "ntlog.h"
13 
14 #include "hw_mod_cat_v18.h"
15 #include "hw_mod_cat_v21.h"
16 #include "hw_mod_flm_v25.h"
17 #include "hw_mod_km_v7.h"
18 #include "hw_mod_qsl_v7.h"
19 #include "hw_mod_pdb_v9.h"
20 #include "hw_mod_slc_lr_v2.h"
21 #include "hw_mod_hsh_v5.h"
22 #include "hw_mod_tpe_v3.h"
23 
24 #define MAX_PHYS_ADAPTERS 8
25 
26 #define VER_MAJOR(ver) (((ver) >> 16) & 0xffff)
27 #define VER_MINOR(ver) ((ver) & 0xffff)
28 
29 struct flow_api_backend_s;
30 struct common_func_s;
31 
32 void *callocate_mod(struct common_func_s *mod, int sets, ...);
33 void zero_module_cache(struct common_func_s *mod);
34 
35 #define ALL_ENTRIES -1000
36 #define ALL_BANK_ENTRIES -1001
37 
38 #define INDEX_TOO_LARGE (-2)
39 #define INDEX_TOO_LARGE_LOG NT_LOG(INF, FILTER, "ERROR:%s: Index too large", __func__)
40 
41 #define WORD_OFF_TOO_LARGE (-3)
42 #define WORD_OFF_TOO_LARGE_LOG NT_LOG(INF, FILTER, "ERROR:%s: Word offset too large", __func__)
43 
44 #define UNSUP_FIELD (-5)
45 #define UNSUP_FIELD_LOG                                                         \
46 	NT_LOG(INF, FILTER, "ERROR:%s: Unsupported field in NIC module", __func__)
47 
48 #define UNSUP_VER (-4)
49 #define UNSUP_VER_LOG                                                                       \
50 	NT_LOG(INF, FILTER, "ERROR:%s: Unsupported NIC module: %s ver %i.%i", __func__, _MOD_, \
51 		VER_MAJOR(_VER_), VER_MINOR(_VER_))
52 
53 #define COUNT_ERROR (-4)
54 #define COUNT_ERROR_LOG(_RESOURCE_)                                                         \
55 	NT_LOG(INF, FILTER,                                                                      \
56 		"ERROR:%s: Insufficient resource [ %s ] : NIC module: %s ver %i.%i", __func__,  \
57 		#_RESOURCE_, _MOD_, VER_MAJOR(_VER_), VER_MINOR(_VER_))                          \
58 
59 #define NOT_FOUND 0xffffffff
60 
61 enum {
62 	EXTRA_INDEXES
63 };
64 
65 #define GET(cached_val, val) ({ *(val) = *(cached_val); })
66 
67 #define SET(cached_val, val) ({ *(cached_val) = *(val); })
68 
69 #define GET_SET(cached_val, val)                                                                  \
70 	do {                                                                                      \
71 		uint32_t *temp_val = (val);                                                       \
72 		typeof(cached_val) *temp_cached_val = &(cached_val);                          \
73 		if (get)                                                                          \
74 			GET(temp_cached_val, temp_val);                                           \
75 		else                                                                              \
76 			SET(temp_cached_val, temp_val);                                           \
77 	} while (0)
78 
79 #define GET_SIGNED(cached_val, val) ({ *(val) = (uint32_t)(*(cached_val)); })
80 
81 #define SET_SIGNED(cached_val, val) ({ *(cached_val) = (int32_t)(*(val)); })
82 
83 #define GET_SET_SIGNED(cached_val, val)                                                           \
84 	do {                                                                                      \
85 		uint32_t *temp_val = (val);                                                       \
86 		typeof(cached_val) *temp_cached_val = &(cached_val);                          \
87 		if (get)                                                                          \
88 			GET_SIGNED(temp_cached_val, temp_val);                                    \
89 		else                                                                              \
90 			SET_SIGNED(temp_cached_val, temp_val);                                    \
91 	} while (0)
92 
93 #define FIND_EQUAL_INDEX(be_module_reg, type, idx, start, nb_elements)                            \
94 	do {                                                                                      \
95 		typeof(be_module_reg) *temp_be_module =                                       \
96 			(typeof(be_module_reg) *)be_module_reg;                               \
97 		typeof(idx) tmp_idx = (idx);                                                  \
98 		typeof(nb_elements) tmp_nb_elements = (nb_elements);                          \
99 		unsigned int start_idx = (unsigned int)(start);                                   \
100 		*value = NOT_FOUND;                                                               \
101 		for (unsigned int i = start_idx; i < tmp_nb_elements; i++) {                      \
102 			if ((unsigned int)(tmp_idx) == i)                                         \
103 				continue;                                                         \
104 			if (memcmp(&temp_be_module[tmp_idx], &temp_be_module[i], sizeof(type)) == \
105 			    0) {                                                                  \
106 				*value = i;                                                       \
107 				break;                                                            \
108 			}                                                                         \
109 		}                                                                                 \
110 	} while (0)
111 
112 #define DO_COMPARE_INDEXS(be_module_reg, type, idx, cmp_idx)                                      \
113 	do {                                                                                      \
114 		typeof(be_module_reg) *temp_be_module = &(be_module_reg);                     \
115 		typeof(idx) tmp_idx = (idx);                                                  \
116 		typeof(cmp_idx) tmp_cmp_idx = (cmp_idx);                                      \
117 		if ((unsigned int)(tmp_idx) != (unsigned int)(tmp_cmp_idx)) {                     \
118 			(void)memcmp(temp_be_module + tmp_idx, &temp_be_module[tmp_cmp_idx],      \
119 				     sizeof(type));                                               \
120 		}                                                                                 \
121 	} while (0)
122 
123 enum km_flm_if_select_e {
124 	KM_FLM_IF_FIRST = 0,
125 	KM_FLM_IF_SECOND = 1
126 };
127 
128 #define FIELD_START_INDEX 100
129 
130 #define COMMON_FUNC_INFO_S                                                                        \
131 	int ver;                                                                                  \
132 	void *base;                                                                               \
133 	unsigned int alloced_size;                                                                \
134 	int debug
135 
136 struct common_func_s {
137 	COMMON_FUNC_INFO_S;
138 };
139 
140 struct cat_func_s {
141 	COMMON_FUNC_INFO_S;
142 	uint32_t nb_cat_funcs;
143 	uint32_t nb_flow_types;
144 	uint32_t nb_pm_ext;
145 	uint32_t nb_len;
146 	uint32_t kcc_size;
147 	uint32_t cts_num;
148 	uint32_t kcc_banks;
149 	uint32_t kcc_id_bit_size;
150 	uint32_t kcc_records;
151 	uint32_t km_if_count;
152 	int32_t km_if_m0;
153 	int32_t km_if_m1;
154 
155 	union {
156 		struct hw_mod_cat_v18_s v18;
157 		struct hw_mod_cat_v21_s v21;
158 	};
159 };
160 enum hw_cat_e {
161 	/*
162 	 * functions initial CAT v18
163 	 */
164 	/* 00 */ HW_CAT_CFN_SET_ALL_DEFAULTS = 0,
165 	/* 01 */ HW_CAT_CFN_PRESET_ALL,
166 	/* 02 */ HW_CAT_CFN_COMPARE,
167 	/* 03 */ HW_CAT_CFN_FIND,
168 	/* 04 */ HW_CAT_CFN_COPY_FROM,
169 	/* 05 */ HW_CAT_COT_PRESET_ALL,
170 	/* 06 */ HW_CAT_COT_COMPARE,
171 	/* 07 */ HW_CAT_COT_FIND,
172 	/* 08 */ HW_CAT_COT_COPY_FROM,
173 	/* fields */
174 	/* 00 */ HW_CAT_CFN_ENABLE = FIELD_START_INDEX,
175 	/* 01 */ HW_CAT_CFN_INV,
176 	/* 02 */ HW_CAT_CFN_PTC_INV,
177 	/* 03 */ HW_CAT_CFN_PTC_ISL,
178 	/* 04 */ HW_CAT_CFN_PTC_CFP,
179 	/* 05 */ HW_CAT_CFN_PTC_MAC,
180 	/* 06 */ HW_CAT_CFN_PTC_L2,
181 	/* 07 */ HW_CAT_CFN_PTC_VNTAG,
182 	/* 08 */ HW_CAT_CFN_PTC_VLAN,
183 	/* 09 */ HW_CAT_CFN_PTC_MPLS,
184 	/* 10 */ HW_CAT_CFN_PTC_L3,
185 	/* 11 */ HW_CAT_CFN_PTC_FRAG,
186 	/* 12 */ HW_CAT_CFN_PTC_IP_PROT,
187 	/* 13 */ HW_CAT_CFN_PTC_L4,
188 	/* 14 */ HW_CAT_CFN_PTC_TUNNEL,
189 	/* 15 */ HW_CAT_CFN_PTC_TNL_L2,
190 	/* 16 */ HW_CAT_CFN_PTC_TNL_VLAN,
191 	/* 17 */ HW_CAT_CFN_PTC_TNL_MPLS,
192 	/* 18 */ HW_CAT_CFN_PTC_TNL_L3,
193 	/* 19 */ HW_CAT_CFN_PTC_TNL_FRAG,
194 	/* 20 */ HW_CAT_CFN_PTC_TNL_IP_PROT,
195 	/* 21 */ HW_CAT_CFN_PTC_TNL_L4,
196 	/* 22 */ HW_CAT_CFN_ERR_INV,
197 	/* 23 */ HW_CAT_CFN_ERR_CV,
198 	/* 24 */ HW_CAT_CFN_ERR_FCS,
199 	/* 25 */ HW_CAT_CFN_ERR_TRUNC,
200 	/* 26 */ HW_CAT_CFN_ERR_L3_CS,
201 	/* 27 */ HW_CAT_CFN_ERR_L4_CS,
202 	/* 28 */ HW_CAT_CFN_MAC_PORT,
203 	/* 29 */ HW_CAT_CFN_PM_CMP,
204 	/* 30 */ HW_CAT_CFN_PM_DCT,
205 	/* 31 */ HW_CAT_CFN_PM_EXT_INV,
206 	/* 32 */ HW_CAT_CFN_PM_CMB,
207 	/* 33 */ HW_CAT_CFN_PM_AND_INV,
208 	/* 34 */ HW_CAT_CFN_PM_OR_INV,
209 	/* 35 */ HW_CAT_CFN_PM_INV,
210 	/* 36 */ HW_CAT_CFN_LC,
211 	/* 37 */ HW_CAT_CFN_LC_INV,
212 	/* 38 */ HW_CAT_CFN_KM0_OR,
213 	/* 39 */ HW_CAT_CFN_KM1_OR,
214 	/* 40 */ HW_CAT_KCE_ENABLE_BM,
215 	/* 41 */ HW_CAT_KCS_CATEGORY,
216 	/* 42 */ HW_CAT_FTE_ENABLE_BM,
217 	/* 43 */ HW_CAT_CTE_ENABLE_BM,
218 	/* 44 */ HW_CAT_CTS_CAT_A,
219 	/* 45 */ HW_CAT_CTS_CAT_B,
220 	/* 46 */ HW_CAT_COT_COLOR,
221 	/* 47 */ HW_CAT_COT_KM,
222 	/* 48 */ HW_CAT_CCT_COLOR,
223 	/* 49 */ HW_CAT_CCT_KM,
224 	/* 50 */ HW_CAT_KCC_KEY,
225 	/* 51 */ HW_CAT_KCC_CATEGORY,
226 	/* 52 */ HW_CAT_KCC_ID,
227 	/* 53 */ HW_CAT_EXO_DYN,
228 	/* 54 */ HW_CAT_EXO_OFS,
229 	/* 55 */ HW_CAT_RCK_DATA,
230 	/* 56 */ HW_CAT_LEN_LOWER,
231 	/* 57 */ HW_CAT_LEN_UPPER,
232 	/* 58 */ HW_CAT_LEN_DYN1,
233 	/* 59 */ HW_CAT_LEN_DYN2,
234 	/* 60 */ HW_CAT_LEN_INV,
235 	/* 61 */ HW_CAT_CFN_ERR_TNL_L3_CS,
236 	/* 62 */ HW_CAT_CFN_ERR_TNL_L4_CS,
237 	/* 63 */ HW_CAT_CFN_ERR_TTL_EXP,
238 	/* 64 */ HW_CAT_CFN_ERR_TNL_TTL_EXP,
239 };
240 
241 bool hw_mod_cat_present(struct flow_api_backend_s *be);
242 int hw_mod_cat_alloc(struct flow_api_backend_s *be);
243 void hw_mod_cat_free(struct flow_api_backend_s *be);
244 int hw_mod_cat_reset(struct flow_api_backend_s *be);
245 int hw_mod_cat_cfn_flush(struct flow_api_backend_s *be, int start_idx, int count);
246 int hw_mod_cat_cfn_set(struct flow_api_backend_s *be, enum hw_cat_e field, int index, int word_off,
247 	uint32_t value);
248 
249 int hw_mod_cat_cte_flush(struct flow_api_backend_s *be, int start_idx, int count);
250 int hw_mod_cat_cts_flush(struct flow_api_backend_s *be, int start_idx, int count);
251 int hw_mod_cat_cot_flush(struct flow_api_backend_s *be, int start_idx, int count);
252 int hw_mod_cat_cct_flush(struct flow_api_backend_s *be, int start_idx, int count);
253 int hw_mod_cat_kcc_flush(struct flow_api_backend_s *be, int start_idx, int count);
254 
255 int hw_mod_cat_exo_flush(struct flow_api_backend_s *be, int start_idx, int count);
256 int hw_mod_cat_rck_flush(struct flow_api_backend_s *be, int start_idx, int count);
257 int hw_mod_cat_len_flush(struct flow_api_backend_s *be, int start_idx, int count);
258 
259 struct km_func_s {
260 	COMMON_FUNC_INFO_S;
261 	uint32_t nb_categories;
262 	uint32_t nb_cam_banks;
263 	uint32_t nb_cam_record_words;
264 	uint32_t nb_cam_records;
265 	uint32_t nb_tcam_banks;
266 	uint32_t nb_tcam_bank_width;
267 	/* not read from backend, but rather set using version */
268 	uint32_t nb_km_rcp_mask_a_word_size;
269 	/* --- || --- */
270 	uint32_t nb_km_rcp_mask_b_word_size;
271 	union {
272 		struct hw_mod_km_v7_s v7;
273 	};
274 };
275 enum hw_km_e {
276 	/* functions */
277 	HW_KM_RCP_PRESET_ALL = 0,
278 	HW_KM_CAM_PRESET_ALL,
279 	/* to sync and reset hw with cache - force write all entries in a bank */
280 	HW_KM_TCAM_BANK_RESET,
281 	/* fields */
282 	HW_KM_RCP_QW0_DYN = FIELD_START_INDEX,
283 	HW_KM_RCP_QW0_OFS,
284 	HW_KM_RCP_QW0_SEL_A,
285 	HW_KM_RCP_QW0_SEL_B,
286 	HW_KM_RCP_QW4_DYN,
287 	HW_KM_RCP_QW4_OFS,
288 	HW_KM_RCP_QW4_SEL_A,
289 	HW_KM_RCP_QW4_SEL_B,
290 	HW_KM_RCP_DW8_DYN,
291 	HW_KM_RCP_DW8_OFS,
292 	HW_KM_RCP_DW8_SEL_A,
293 	HW_KM_RCP_DW8_SEL_B,
294 	HW_KM_RCP_DW10_DYN,
295 	HW_KM_RCP_DW10_OFS,
296 	HW_KM_RCP_DW10_SEL_A,
297 	HW_KM_RCP_DW10_SEL_B,
298 	HW_KM_RCP_SWX_CCH,
299 	HW_KM_RCP_SWX_SEL_A,
300 	HW_KM_RCP_SWX_SEL_B,
301 	HW_KM_RCP_MASK_A,
302 	HW_KM_RCP_MASK_B,
303 	HW_KM_RCP_DUAL,
304 	HW_KM_RCP_PAIRED,
305 	HW_KM_RCP_EL_A,
306 	HW_KM_RCP_EL_B,
307 	HW_KM_RCP_INFO_A,
308 	HW_KM_RCP_INFO_B,
309 	HW_KM_RCP_FTM_A,
310 	HW_KM_RCP_FTM_B,
311 	HW_KM_RCP_BANK_A,
312 	HW_KM_RCP_BANK_B,
313 	HW_KM_RCP_KL_A,
314 	HW_KM_RCP_KL_B,
315 	HW_KM_RCP_KEYWAY_A,
316 	HW_KM_RCP_KEYWAY_B,
317 	HW_KM_RCP_SYNERGY_MODE,
318 	HW_KM_RCP_DW0_B_DYN,
319 	HW_KM_RCP_DW0_B_OFS,
320 	HW_KM_RCP_DW2_B_DYN,
321 	HW_KM_RCP_DW2_B_OFS,
322 	HW_KM_RCP_SW4_B_DYN,
323 	HW_KM_RCP_SW4_B_OFS,
324 	HW_KM_RCP_SW5_B_DYN,
325 	HW_KM_RCP_SW5_B_OFS,
326 	HW_KM_CAM_W0,
327 	HW_KM_CAM_W1,
328 	HW_KM_CAM_W2,
329 	HW_KM_CAM_W3,
330 	HW_KM_CAM_W4,
331 	HW_KM_CAM_W5,
332 	HW_KM_CAM_FT0,
333 	HW_KM_CAM_FT1,
334 	HW_KM_CAM_FT2,
335 	HW_KM_CAM_FT3,
336 	HW_KM_CAM_FT4,
337 	HW_KM_CAM_FT5,
338 	HW_KM_TCAM_T,
339 	HW_KM_TCI_COLOR,
340 	HW_KM_TCI_FT,
341 	HW_KM_TCQ_BANK_MASK,
342 	HW_KM_TCQ_QUAL
343 };
344 bool hw_mod_km_present(struct flow_api_backend_s *be);
345 int hw_mod_km_alloc(struct flow_api_backend_s *be);
346 void hw_mod_km_free(struct flow_api_backend_s *be);
347 int hw_mod_km_reset(struct flow_api_backend_s *be);
348 int hw_mod_km_rcp_flush(struct flow_api_backend_s *be, int start_idx, int count);
349 int hw_mod_km_cam_flush(struct flow_api_backend_s *be, int start_bank, int start_record,
350 	int count);
351 int hw_mod_km_tcam_flush(struct flow_api_backend_s *be, int start_bank, int count);
352 int hw_mod_km_tcam_set(struct flow_api_backend_s *be, enum hw_km_e field, int bank, int byte,
353 	int byte_val, uint32_t *value_set);
354 int hw_mod_km_tci_flush(struct flow_api_backend_s *be, int start_bank, int start_record,
355 	int count);
356 int hw_mod_km_tcq_flush(struct flow_api_backend_s *be, int start_bank, int start_record,
357 	int count);
358 
359 struct flm_func_s {
360 	COMMON_FUNC_INFO_S;
361 	uint32_t nb_categories;
362 	uint32_t nb_size_mb;
363 	uint32_t nb_entry_size;
364 	uint32_t nb_variant;
365 	uint32_t nb_prios;
366 	uint32_t nb_pst_profiles;
367 	uint32_t nb_scrub_profiles;
368 	uint32_t nb_rpp_clock_in_ps;
369 	uint32_t nb_load_aps_max;
370 	union {
371 		struct hw_mod_flm_v25_s v25;
372 	};
373 };
374 enum hw_flm_e {
375 	/* functions */
376 	HW_FLM_CONTROL_PRESET_ALL = 0,
377 	HW_FLM_RCP_PRESET_ALL,
378 	HW_FLM_FLOW_LRN_DATA,
379 	HW_FLM_FLOW_INF_STA_DATA,
380 	/* Control fields */
381 	HW_FLM_CONTROL_ENABLE = FIELD_START_INDEX,
382 	HW_FLM_CONTROL_INIT,
383 	HW_FLM_CONTROL_LDS,
384 	HW_FLM_CONTROL_LFS,
385 	HW_FLM_CONTROL_LIS,
386 	HW_FLM_CONTROL_UDS,
387 	HW_FLM_CONTROL_UIS,
388 	HW_FLM_CONTROL_RDS,
389 	HW_FLM_CONTROL_RIS,
390 	HW_FLM_CONTROL_PDS,
391 	HW_FLM_CONTROL_PIS,
392 	HW_FLM_CONTROL_CRCWR,
393 	HW_FLM_CONTROL_CRCRD,
394 	HW_FLM_CONTROL_RBL,
395 	HW_FLM_CONTROL_EAB,
396 	HW_FLM_CONTROL_SPLIT_SDRAM_USAGE,
397 	HW_FLM_STATUS_CALIB_SUCCESS,
398 	HW_FLM_STATUS_CALIB_FAIL,
399 	HW_FLM_STATUS_INITDONE,
400 	HW_FLM_STATUS_IDLE,
401 	HW_FLM_STATUS_CRITICAL,
402 	HW_FLM_STATUS_PANIC,
403 	HW_FLM_STATUS_CRCERR,
404 	HW_FLM_STATUS_EFT_BP,
405 	HW_FLM_STATUS_CACHE_BUFFER_CRITICAL,
406 	HW_FLM_LOAD_BIN,
407 	HW_FLM_LOAD_LPS,
408 	HW_FLM_LOAD_APS,
409 	HW_FLM_PRIO_LIMIT0,
410 	HW_FLM_PRIO_FT0,
411 	HW_FLM_PRIO_LIMIT1,
412 	HW_FLM_PRIO_FT1,
413 	HW_FLM_PRIO_LIMIT2,
414 	HW_FLM_PRIO_FT2,
415 	HW_FLM_PRIO_LIMIT3,
416 	HW_FLM_PRIO_FT3,
417 	HW_FLM_PST_PRESET_ALL,
418 	HW_FLM_PST_BP,
419 	HW_FLM_PST_PP,
420 	HW_FLM_PST_TP,
421 	HW_FLM_RCP_LOOKUP,
422 	HW_FLM_RCP_QW0_DYN,
423 	HW_FLM_RCP_QW0_OFS,
424 	HW_FLM_RCP_QW0_SEL,
425 	HW_FLM_RCP_QW4_DYN,
426 	HW_FLM_RCP_QW4_OFS,
427 	HW_FLM_RCP_SW8_DYN,
428 	HW_FLM_RCP_SW8_OFS,
429 	HW_FLM_RCP_SW8_SEL,
430 	HW_FLM_RCP_SW9_DYN,
431 	HW_FLM_RCP_SW9_OFS,
432 	HW_FLM_RCP_MASK,
433 	HW_FLM_RCP_KID,
434 	HW_FLM_RCP_OPN,
435 	HW_FLM_RCP_IPN,
436 	HW_FLM_RCP_BYT_DYN,
437 	HW_FLM_RCP_BYT_OFS,
438 	HW_FLM_RCP_TXPLM,
439 	HW_FLM_RCP_AUTO_IPV4_MASK,
440 	HW_FLM_BUF_CTRL_LRN_FREE,
441 	HW_FLM_BUF_CTRL_INF_AVAIL,
442 	HW_FLM_BUF_CTRL_STA_AVAIL,
443 	HW_FLM_STAT_LRN_DONE,
444 	HW_FLM_STAT_LRN_IGNORE,
445 	HW_FLM_STAT_LRN_FAIL,
446 	HW_FLM_STAT_UNL_DONE,
447 	HW_FLM_STAT_UNL_IGNORE,
448 	HW_FLM_STAT_REL_DONE,
449 	HW_FLM_STAT_REL_IGNORE,
450 	HW_FLM_STAT_PRB_DONE,
451 	HW_FLM_STAT_PRB_IGNORE,
452 	HW_FLM_STAT_AUL_DONE,
453 	HW_FLM_STAT_AUL_IGNORE,
454 	HW_FLM_STAT_AUL_FAIL,
455 	HW_FLM_STAT_TUL_DONE,
456 	HW_FLM_STAT_FLOWS,
457 	HW_FLM_STAT_STA_DONE,	/* module ver 0.20 */
458 	HW_FLM_STAT_INF_DONE,	/* module ver 0.20 */
459 	HW_FLM_STAT_INF_SKIP,	/* module ver 0.20 */
460 	HW_FLM_STAT_PCK_HIT,	/* module ver 0.20 */
461 	HW_FLM_STAT_PCK_MISS,	/* module ver 0.20 */
462 	HW_FLM_STAT_PCK_UNH,	/* module ver 0.20 */
463 	HW_FLM_STAT_PCK_DIS,	/* module ver 0.20 */
464 	HW_FLM_STAT_CSH_HIT,	/* module ver 0.20 */
465 	HW_FLM_STAT_CSH_MISS,	/* module ver 0.20 */
466 	HW_FLM_STAT_CSH_UNH,	/* module ver 0.20 */
467 	HW_FLM_STAT_CUC_START,	/* module ver 0.20 */
468 	HW_FLM_STAT_CUC_MOVE,	/* module ver 0.20 */
469 	HW_FLM_SCAN_I,	/* module ver 0.22 */
470 	HW_FLM_SCRUB_PRESET_ALL,
471 	HW_FLM_SCRUB_T,	/* module ver 0.22 */
472 	HW_FLM_SCRUB_R,	/* module ver 0.24 */
473 	HW_FLM_SCRUB_DEL,	/* module ver 0.24 */
474 	HW_FLM_SCRUB_INF,	/* module ver 0.24 */
475 };
476 
477 bool hw_mod_flm_present(struct flow_api_backend_s *be);
478 int hw_mod_flm_alloc(struct flow_api_backend_s *be);
479 void hw_mod_flm_free(struct flow_api_backend_s *be);
480 int hw_mod_flm_reset(struct flow_api_backend_s *be);
481 
482 int hw_mod_flm_control_flush(struct flow_api_backend_s *be);
483 int hw_mod_flm_control_set(struct flow_api_backend_s *be, enum hw_flm_e field, uint32_t value);
484 
485 int hw_mod_flm_scan_flush(struct flow_api_backend_s *be);
486 
487 int hw_mod_flm_rcp_flush(struct flow_api_backend_s *be, int start_idx, int count);
488 
489 int hw_mod_flm_scrub_flush(struct flow_api_backend_s *be, int start_idx, int count);
490 
491 struct hsh_func_s {
492 	COMMON_FUNC_INFO_S;
493 	uint32_t nb_rcp;/* number of HSH recipes supported by FPGA */
494 	/* indication if Toeplitz is supported by FPGA, i.e. 0 - unsupported, 1 - supported */
495 	uint32_t toeplitz;
496 	union {
497 		struct hw_mod_hsh_v5_s v5;
498 	};
499 };
500 enum hw_hsh_e {
501 	/* functions */
502 	HW_HSH_RCP_PRESET_ALL = 0,
503 	HW_HSH_RCP_COMPARE,
504 	HW_HSH_RCP_FIND,
505 	/* fields */
506 	HW_HSH_RCP_LOAD_DIST_TYPE = FIELD_START_INDEX,
507 	HW_HSH_RCP_MAC_PORT_MASK,
508 	HW_HSH_RCP_SORT,
509 	HW_HSH_RCP_QW0_PE,
510 	HW_HSH_RCP_QW0_OFS,
511 	HW_HSH_RCP_QW4_PE,
512 	HW_HSH_RCP_QW4_OFS,
513 	HW_HSH_RCP_W8_PE,
514 	HW_HSH_RCP_W8_OFS,
515 	HW_HSH_RCP_W8_SORT,
516 	HW_HSH_RCP_W9_PE,
517 	HW_HSH_RCP_W9_OFS,
518 	HW_HSH_RCP_W9_SORT,
519 	HW_HSH_RCP_W9_P,
520 	HW_HSH_RCP_P_MASK,
521 	HW_HSH_RCP_WORD_MASK,
522 	HW_HSH_RCP_SEED,
523 	HW_HSH_RCP_TNL_P,
524 	HW_HSH_RCP_HSH_VALID,
525 	HW_HSH_RCP_HSH_TYPE,
526 	HW_HSH_RCP_TOEPLITZ,
527 	HW_HSH_RCP_K,
528 	HW_HSH_RCP_AUTO_IPV4_MASK
529 };
530 bool hw_mod_hsh_present(struct flow_api_backend_s *be);
531 int hw_mod_hsh_alloc(struct flow_api_backend_s *be);
532 void hw_mod_hsh_free(struct flow_api_backend_s *be);
533 int hw_mod_hsh_reset(struct flow_api_backend_s *be);
534 int hw_mod_hsh_rcp_flush(struct flow_api_backend_s *be, int start_idx, int count);
535 
536 struct qsl_func_s {
537 	COMMON_FUNC_INFO_S;
538 	uint32_t nb_rcp_categories;
539 	uint32_t nb_qst_entries;
540 	union {
541 		struct hw_mod_qsl_v7_s v7;
542 	};
543 };
544 enum hw_qsl_e {
545 	/* functions */
546 	HW_QSL_RCP_PRESET_ALL = 0,
547 	HW_QSL_RCP_COMPARE,
548 	HW_QSL_RCP_FIND,
549 	HW_QSL_QST_PRESET_ALL,
550 	/* fields */
551 	HW_QSL_RCP_DISCARD = FIELD_START_INDEX,
552 	HW_QSL_RCP_DROP,
553 	HW_QSL_RCP_TBL_LO,
554 	HW_QSL_RCP_TBL_HI,
555 	HW_QSL_RCP_TBL_IDX,
556 	HW_QSL_RCP_TBL_MSK,
557 	HW_QSL_RCP_LR,
558 	HW_QSL_RCP_TSA,
559 	HW_QSL_RCP_VLI,
560 	HW_QSL_QST_QUEUE,
561 	HW_QSL_QST_EN,	/* Alias: HW_QSL_QST_QEN */
562 	HW_QSL_QST_TX_PORT,
563 	HW_QSL_QST_LRE,
564 	HW_QSL_QST_TCI,
565 	HW_QSL_QST_VEN,
566 	HW_QSL_QEN_EN,
567 	HW_QSL_UNMQ_DEST_QUEUE,
568 	HW_QSL_UNMQ_EN,
569 };
570 bool hw_mod_qsl_present(struct flow_api_backend_s *be);
571 int hw_mod_qsl_alloc(struct flow_api_backend_s *be);
572 void hw_mod_qsl_free(struct flow_api_backend_s *be);
573 int hw_mod_qsl_reset(struct flow_api_backend_s *be);
574 int hw_mod_qsl_rcp_flush(struct flow_api_backend_s *be, int start_idx, int count);
575 int hw_mod_qsl_qst_flush(struct flow_api_backend_s *be, int start_idx, int count);
576 int hw_mod_qsl_qen_flush(struct flow_api_backend_s *be, int start_idx, int count);
577 int hw_mod_qsl_unmq_flush(struct flow_api_backend_s *be, int start_idx, int count);
578 int hw_mod_qsl_unmq_set(struct flow_api_backend_s *be, enum hw_qsl_e field, uint32_t index,
579 	uint32_t value);
580 
581 struct slc_lr_func_s {
582 	COMMON_FUNC_INFO_S;
583 	union {
584 		struct hw_mod_slc_lr_v2_s v2;
585 	};
586 };
587 enum hw_slc_lr_e {
588 	/* functions */
589 	HW_SLC_LR_RCP_PRESET_ALL = 0,
590 	HW_SLC_LR_RCP_COMPARE,
591 	HW_SLC_LR_RCP_FIND,
592 	/* fields */
593 	HW_SLC_LR_RCP_HEAD_SLC_EN = FIELD_START_INDEX,
594 	HW_SLC_LR_RCP_HEAD_DYN,
595 	HW_SLC_LR_RCP_HEAD_OFS,
596 	HW_SLC_LR_RCP_TAIL_SLC_EN,
597 	HW_SLC_LR_RCP_TAIL_DYN,
598 	HW_SLC_LR_RCP_TAIL_OFS,
599 	HW_SLC_LR_RCP_PCAP
600 };
601 bool hw_mod_slc_lr_present(struct flow_api_backend_s *be);
602 int hw_mod_slc_lr_alloc(struct flow_api_backend_s *be);
603 void hw_mod_slc_lr_free(struct flow_api_backend_s *be);
604 int hw_mod_slc_lr_reset(struct flow_api_backend_s *be);
605 int hw_mod_slc_lr_rcp_flush(struct flow_api_backend_s *be, int start_idx, int count);
606 
607 struct pdb_func_s {
608 	COMMON_FUNC_INFO_S;
609 	uint32_t nb_pdb_rcp_categories;
610 
611 	union {
612 		struct hw_mod_pdb_v9_s v9;
613 	};
614 };
615 
616 struct tpe_func_s {
617 	COMMON_FUNC_INFO_S;
618 	uint32_t nb_rcp_categories;
619 	uint32_t nb_ifr_categories;
620 	uint32_t nb_cpy_writers;
621 	uint32_t nb_rpl_depth;
622 	uint32_t nb_rpl_ext_categories;
623 	union {
624 		struct hw_mod_tpe_v3_s v3;
625 	};
626 };
627 
628 enum debug_mode_e {
629 	FLOW_BACKEND_DEBUG_MODE_NONE = 0x0000,
630 	FLOW_BACKEND_DEBUG_MODE_WRITE = 0x0001
631 };
632 
633 struct flow_api_backend_ops {
634 	int version;
635 	int (*set_debug_mode)(void *dev, enum debug_mode_e mode);
636 	int (*get_nb_phy_port)(void *dev);
637 	int (*get_nb_rx_port)(void *dev);
638 	int (*get_ltx_avail)(void *dev);
639 	int (*get_nb_cat_funcs)(void *dev);
640 	int (*get_nb_categories)(void *dev);
641 	int (*get_nb_cat_km_if_cnt)(void *dev);
642 	int (*get_nb_cat_km_if_m0)(void *dev);
643 	int (*get_nb_cat_km_if_m1)(void *dev);
644 
645 	int (*get_nb_queues)(void *dev);
646 	int (*get_nb_km_flow_types)(void *dev);
647 	int (*get_nb_pm_ext)(void *dev);
648 	int (*get_nb_len)(void *dev);
649 	int (*get_kcc_size)(void *dev);
650 	int (*get_kcc_banks)(void *dev);
651 	int (*get_nb_km_categories)(void *dev);
652 	int (*get_nb_km_cam_banks)(void *dev);
653 	int (*get_nb_km_cam_record_words)(void *dev);
654 	int (*get_nb_km_cam_records)(void *dev);
655 	int (*get_nb_km_tcam_banks)(void *dev);
656 	int (*get_nb_km_tcam_bank_width)(void *dev);
657 	int (*get_nb_flm_categories)(void *dev);
658 	int (*get_nb_flm_size_mb)(void *dev);
659 	int (*get_nb_flm_entry_size)(void *dev);
660 	int (*get_nb_flm_variant)(void *dev);
661 	int (*get_nb_flm_prios)(void *dev);
662 	int (*get_nb_flm_pst_profiles)(void *dev);
663 	int (*get_nb_flm_scrub_profiles)(void *dev);
664 	int (*get_nb_flm_load_aps_max)(void *dev);
665 	int (*get_nb_qsl_categories)(void *dev);
666 	int (*get_nb_qsl_qst_entries)(void *dev);
667 	int (*get_nb_pdb_categories)(void *dev);
668 	int (*get_nb_roa_categories)(void *dev);
669 	int (*get_nb_tpe_categories)(void *dev);
670 	int (*get_nb_tx_cpy_writers)(void *dev);
671 	int (*get_nb_tx_cpy_mask_mem)(void *dev);
672 	int (*get_nb_tx_rpl_depth)(void *dev);
673 	int (*get_nb_tx_rpl_ext_categories)(void *dev);
674 	int (*get_nb_tpe_ifr_categories)(void *dev);
675 	int (*get_nb_rpp_per_ps)(void *dev);
676 	int (*get_nb_hsh_categories)(void *dev);
677 	int (*get_nb_hsh_toeplitz)(void *dev);
678 
679 	int (*alloc_rx_queue)(void *dev, int queue_id);
680 	int (*free_rx_queue)(void *dev, int hw_queue);
681 
682 	/* CAT */
683 	bool (*get_cat_present)(void *dev);
684 	uint32_t (*get_cat_version)(void *dev);
685 	int (*cat_cfn_flush)(void *dev, const struct cat_func_s *cat, int cat_func, int cnt);
686 	int (*cat_kce_flush)(void *dev, const struct cat_func_s *cat, int km_if_idx, int index,
687 		int cnt);
688 	int (*cat_kcs_flush)(void *dev, const struct cat_func_s *cat, int km_if_idx, int cat_func,
689 		int cnt);
690 	int (*cat_fte_flush)(void *dev, const struct cat_func_s *cat, int km_if_idx, int index,
691 		int cnt);
692 	int (*cat_cte_flush)(void *dev, const struct cat_func_s *cat, int cat_func, int cnt);
693 	int (*cat_cts_flush)(void *dev, const struct cat_func_s *cat, int index, int cnt);
694 	int (*cat_cot_flush)(void *dev, const struct cat_func_s *cat, int cat_func, int cnt);
695 	int (*cat_cct_flush)(void *dev, const struct cat_func_s *cat, int index, int cnt);
696 	int (*cat_exo_flush)(void *dev, const struct cat_func_s *cat, int index, int cnt);
697 	int (*cat_rck_flush)(void *dev, const struct cat_func_s *cat, int index, int cnt);
698 	int (*cat_len_flush)(void *dev, const struct cat_func_s *cat, int index, int cnt);
699 	int (*cat_kcc_flush)(void *dev, const struct cat_func_s *cat, int index, int cnt);
700 
701 	/* KM */
702 	bool (*get_km_present)(void *dev);
703 	uint32_t (*get_km_version)(void *dev);
704 	int (*km_rcp_flush)(void *dev, const struct km_func_s *km, int category, int cnt);
705 	int (*km_cam_flush)(void *dev, const struct km_func_s *km, int bank, int record, int cnt);
706 	int (*km_tcam_flush)(void *dev, const struct km_func_s *km, int bank, int byte, int value,
707 		int cnt);
708 	int (*km_tci_flush)(void *dev, const struct km_func_s *km, int bank, int record, int cnt);
709 	int (*km_tcq_flush)(void *dev, const struct km_func_s *km, int bank, int record, int cnt);
710 
711 	/* FLM */
712 	bool (*get_flm_present)(void *dev);
713 	uint32_t (*get_flm_version)(void *dev);
714 	int (*flm_control_flush)(void *dev, const struct flm_func_s *flm);
715 	int (*flm_status_flush)(void *dev, const struct flm_func_s *flm);
716 	int (*flm_status_update)(void *dev, const struct flm_func_s *flm);
717 	int (*flm_scan_flush)(void *dev, const struct flm_func_s *flm);
718 	int (*flm_load_bin_flush)(void *dev, const struct flm_func_s *flm);
719 	int (*flm_prio_flush)(void *dev, const struct flm_func_s *flm);
720 	int (*flm_pst_flush)(void *dev, const struct flm_func_s *flm, int index, int cnt);
721 	int (*flm_rcp_flush)(void *dev, const struct flm_func_s *flm, int index, int cnt);
722 	int (*flm_scrub_flush)(void *dev, const struct flm_func_s *flm, int index, int cnt);
723 	int (*flm_buf_ctrl_update)(void *dev, const struct flm_func_s *flm);
724 	int (*flm_stat_update)(void *dev, const struct flm_func_s *flm);
725 	int (*flm_lrn_data_flush)(void *be_dev, const struct flm_func_s *flm,
726 		const uint32_t *lrn_data, uint32_t records,
727 		uint32_t *handled_records, uint32_t words_per_record,
728 		uint32_t *inf_word_cnt, uint32_t *sta_word_cnt);
729 	int (*flm_inf_sta_data_update)(void *be_dev, const struct flm_func_s *flm,
730 		uint32_t *inf_data, uint32_t inf_size,
731 		uint32_t *inf_word_cnt, uint32_t *sta_data,
732 		uint32_t sta_size, uint32_t *sta_word_cnt);
733 
734 	/* HSH */
735 	bool (*get_hsh_present)(void *dev);
736 	uint32_t (*get_hsh_version)(void *dev);
737 	int (*hsh_rcp_flush)(void *dev, const struct hsh_func_s *hsh, int category, int cnt);
738 
739 	/* QSL */
740 	bool (*get_qsl_present)(void *dev);
741 	uint32_t (*get_qsl_version)(void *dev);
742 	int (*qsl_rcp_flush)(void *dev, const struct qsl_func_s *qsl, int category, int cnt);
743 	int (*qsl_qst_flush)(void *dev, const struct qsl_func_s *qsl, int entry, int cnt);
744 	int (*qsl_qen_flush)(void *dev, const struct qsl_func_s *qsl, int entry, int cnt);
745 	int (*qsl_unmq_flush)(void *dev, const struct qsl_func_s *qsl, int entry, int cnt);
746 
747 	/* SLC LR */
748 	bool (*get_slc_lr_present)(void *dev);
749 	uint32_t (*get_slc_lr_version)(void *dev);
750 	int (*slc_lr_rcp_flush)(void *dev, const struct slc_lr_func_s *slc_lr, int category,
751 		int cnt);
752 
753 	/* PDB */
754 	bool (*get_pdb_present)(void *dev);
755 	uint32_t (*get_pdb_version)(void *dev);
756 	int (*pdb_rcp_flush)(void *dev, const struct pdb_func_s *pdb, int category, int cnt);
757 	int (*pdb_config_flush)(void *dev, const struct pdb_func_s *pdb);
758 
759 	/* TPE */
760 	bool (*get_tpe_present)(void *dev);
761 	uint32_t (*get_tpe_version)(void *dev);
762 	int (*tpe_rpp_rcp_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
763 	int (*tpe_rpp_ifr_rcp_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
764 	int (*tpe_ifr_rcp_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
765 	int (*tpe_ins_rcp_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
766 	int (*tpe_rpl_rcp_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
767 	int (*tpe_rpl_ext_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
768 	int (*tpe_rpl_rpl_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
769 	int (*tpe_cpy_rcp_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
770 	int (*tpe_hfu_rcp_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
771 	int (*tpe_csu_rcp_flush)(void *dev, const struct tpe_func_s *tpe, int index, int cnt);
772 };
773 
774 struct flow_api_backend_s {
775 	void *be_dev;
776 	const struct flow_api_backend_ops *iface;
777 
778 	/* flow filter FPGA modules */
779 	struct cat_func_s cat;
780 	struct km_func_s km;
781 	struct flm_func_s flm;
782 	struct hsh_func_s hsh;
783 	struct qsl_func_s qsl;
784 	struct slc_lr_func_s slc_lr;
785 
786 	/* NIC attributes */
787 	unsigned int num_phy_ports;
788 	unsigned int num_rx_ports;
789 
790 	/* flow filter resource capacities */
791 	unsigned int max_categories;
792 	unsigned int max_queues;
793 };
794 
795 int flow_api_backend_init(struct flow_api_backend_s *dev, const struct flow_api_backend_ops *iface,
796 	void *be_dev);
797 int flow_api_backend_done(struct flow_api_backend_s *dev);
798 
799 #endif  /* _HW_MOD_BACKEND_H_ */
800