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