1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
6 #include <rte_common.h>
8 #include "cfa_resource_types.h"
10 #include "tf_identifier.h"
14 #include "tf_tcam_shared.h"
15 #endif /* TF_TCAM_SHARED */
17 #include "tf_if_tbl.h"
19 #include "tf_msg_common.h"
21 #define TF_DEV_P58_PARIF_MAX 16
22 #define TF_DEV_P58_PF_MASK 0xfUL
24 /* For print alignment, make all entries 8 chars in this table */
25 const char *tf_resource_str_p58[CFA_RESOURCE_TYPE_P58_LAST + 1] = {
26 [CFA_RESOURCE_TYPE_P58_METER] = "meter ",
27 [CFA_RESOURCE_TYPE_P58_SRAM_BANK_0] = "sram_bk0",
28 [CFA_RESOURCE_TYPE_P58_SRAM_BANK_1] = "sram_bk1",
29 [CFA_RESOURCE_TYPE_P58_SRAM_BANK_2] = "sram_bk2",
30 [CFA_RESOURCE_TYPE_P58_SRAM_BANK_3] = "sram_bk3",
31 [CFA_RESOURCE_TYPE_P58_L2_CTXT_TCAM_HIGH] = "l2ctx_hi",
32 [CFA_RESOURCE_TYPE_P58_L2_CTXT_TCAM_LOW] = "l2ctx_lo",
33 [CFA_RESOURCE_TYPE_P58_L2_CTXT_REMAP_HIGH] = "l2ctr_hi",
34 [CFA_RESOURCE_TYPE_P58_L2_CTXT_REMAP_LOW] = "l2ctr_lo",
35 [CFA_RESOURCE_TYPE_P58_PROF_FUNC] = "prf_func",
36 [CFA_RESOURCE_TYPE_P58_PROF_TCAM] = "prf_tcam",
37 [CFA_RESOURCE_TYPE_P58_EM_PROF_ID] = "em_prof ",
38 [CFA_RESOURCE_TYPE_P58_WC_TCAM_PROF_ID] = "wc_prof ",
39 [CFA_RESOURCE_TYPE_P58_EM_REC] = "em_rec ",
40 [CFA_RESOURCE_TYPE_P58_WC_TCAM] = "wc_tcam ",
41 [CFA_RESOURCE_TYPE_P58_METER_PROF] = "mtr_prof",
42 [CFA_RESOURCE_TYPE_P58_MIRROR] = "mirror ",
43 [CFA_RESOURCE_TYPE_P58_EM_FKB] = "em_fkb ",
44 [CFA_RESOURCE_TYPE_P58_WC_FKB] = "wc_fkb ",
45 [CFA_RESOURCE_TYPE_P58_VEB_TCAM] = "veb ",
49 * Device specific function that retrieves the MAX number of HCAPI
50 * types the device supports.
53 * Pointer to TF handle
56 * Pointer to the MAX number of HCAPI types supported
59 * - (0) if successful.
60 * - (-EINVAL) on failure.
63 tf_dev_p58_get_max_types(struct tf *tfp,
66 if (max_types == NULL || tfp == NULL)
69 *max_types = CFA_RESOURCE_TYPE_P58_LAST + 1;
74 * Device specific function that retrieves a human readable
75 * string to identify a CFA resource type.
78 * Pointer to TF handle
81 * HCAPI CFA resource id
87 * - (0) if successful.
88 * - (-EINVAL) on failure.
91 tf_dev_p58_get_resource_str(struct tf *tfp __rte_unused,
93 const char **resource_str)
95 if (resource_str == NULL)
98 if (resource_id > CFA_RESOURCE_TYPE_P58_LAST)
101 *resource_str = tf_resource_str_p58[resource_id];
107 * Device specific function that retrieves the WC TCAM slices the
111 * Pointer to TF handle
114 * Pointer to the WC TCAM slice size
116 * [out] num_slices_per_row
117 * Pointer to the WC TCAM row slice configuration
120 * - (0) if successful.
121 * - (-EINVAL) on failure.
124 tf_dev_p58_get_tcam_slice_info(struct tf *tfp __rte_unused,
125 enum tf_tcam_tbl_type type,
127 uint16_t *num_slices_per_row)
129 #define CFA_P58_WC_TCAM_SLICES_PER_ROW 1
130 #define CFA_P58_WC_TCAM_SLICE_SIZE 24
132 if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
133 /* only support single slice key size now */
134 *num_slices_per_row = CFA_P58_WC_TCAM_SLICES_PER_ROW;
135 if (key_sz > *num_slices_per_row * CFA_P58_WC_TCAM_SLICE_SIZE)
137 } else { /* for other type of tcam */
138 *num_slices_per_row = 1;
144 static int tf_dev_p58_get_mailbox(void)
149 static int tf_dev_p58_word_align(uint16_t size)
151 return ((((size) + 63) >> 6) * 8);
155 * Device specific function that retrieves the increment
156 * required for certain table types in a shared session
162 * pointer to parms structure
165 * - (0) if successful.
166 * - (-EINVAL) on failure.
168 static int tf_dev_p58_get_shared_tbl_increment(struct tf *tfp __rte_unused,
169 struct tf_get_shared_tbl_increment_parms *parms)
171 switch (parms->type) {
172 case TF_TBL_TYPE_FULL_ACT_RECORD:
173 case TF_TBL_TYPE_COMPACT_ACT_RECORD:
174 case TF_TBL_TYPE_ACT_ENCAP_8B:
175 case TF_TBL_TYPE_ACT_ENCAP_16B:
176 case TF_TBL_TYPE_ACT_ENCAP_32B:
177 case TF_TBL_TYPE_ACT_ENCAP_64B:
178 case TF_TBL_TYPE_ACT_SP_SMAC:
179 case TF_TBL_TYPE_ACT_SP_SMAC_IPV4:
180 case TF_TBL_TYPE_ACT_SP_SMAC_IPV6:
181 case TF_TBL_TYPE_ACT_STATS_64:
182 case TF_TBL_TYPE_ACT_MODIFY_IPV4:
183 case TF_TBL_TYPE_ACT_MODIFY_8B:
184 case TF_TBL_TYPE_ACT_MODIFY_16B:
185 case TF_TBL_TYPE_ACT_MODIFY_32B:
186 case TF_TBL_TYPE_ACT_MODIFY_64B:
187 parms->increment_cnt = 8;
190 parms->increment_cnt = 1;
196 #define TF_DEV_P58_BANK_SZ_64B 2048
198 * Get SRAM table information.
200 * Converts an internal RM allocated element offset to
201 * a user address and vice versa.
204 * Pointer to TF handle
207 * Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
210 * Pointer to the Base address of the associated SRAM bank used for
211 * the type of record allocated.
214 * Pointer to the factor to be used as a multiplier to translate
215 * between the RM units to the user address. SRAM manages 64B entries
216 * Addresses must be shifted to an 8B address.
219 * - (0) if successful.
220 * - (-EINVAL) on failure.
222 static int tf_dev_p58_get_sram_tbl_info(struct tf *tfp __rte_unused,
224 enum tf_tbl_type type,
229 struct tf_rm_get_hcapi_parms parms;
233 parms.subtype = type;
234 parms.hcapi_type = &hcapi_type;
236 rc = tf_rm_get_hcapi_type(&parms);
243 switch (hcapi_type) {
244 case CFA_RESOURCE_TYPE_P58_SRAM_BANK_0:
248 case CFA_RESOURCE_TYPE_P58_SRAM_BANK_1:
249 *base = TF_DEV_P58_BANK_SZ_64B;
252 case CFA_RESOURCE_TYPE_P58_SRAM_BANK_2:
253 *base = TF_DEV_P58_BANK_SZ_64B * 2;
256 case CFA_RESOURCE_TYPE_P58_SRAM_BANK_3:
257 *base = TF_DEV_P58_BANK_SZ_64B * 3;
268 * Truflow P58 device specific functions
270 const struct tf_dev_ops tf_dev_ops_p58_init = {
271 .tf_dev_get_max_types = tf_dev_p58_get_max_types,
272 .tf_dev_get_resource_str = tf_dev_p58_get_resource_str,
273 .tf_dev_get_tcam_slice_info = tf_dev_p58_get_tcam_slice_info,
274 .tf_dev_alloc_ident = NULL,
275 .tf_dev_free_ident = NULL,
276 .tf_dev_search_ident = NULL,
277 .tf_dev_get_ident_resc_info = NULL,
278 .tf_dev_get_tbl_info = NULL,
279 .tf_dev_alloc_ext_tbl = NULL,
280 .tf_dev_alloc_tbl = NULL,
281 .tf_dev_free_ext_tbl = NULL,
282 .tf_dev_free_tbl = NULL,
283 .tf_dev_set_tbl = NULL,
284 .tf_dev_set_ext_tbl = NULL,
285 .tf_dev_get_tbl = NULL,
286 .tf_dev_get_bulk_tbl = NULL,
287 .tf_dev_get_shared_tbl_increment = tf_dev_p58_get_shared_tbl_increment,
288 .tf_dev_get_tbl_resc_info = NULL,
289 .tf_dev_alloc_tcam = NULL,
290 .tf_dev_free_tcam = NULL,
291 .tf_dev_alloc_search_tcam = NULL,
292 .tf_dev_set_tcam = NULL,
293 .tf_dev_get_tcam = NULL,
294 .tf_dev_get_tcam_resc_info = NULL,
295 .tf_dev_insert_int_em_entry = NULL,
296 .tf_dev_delete_int_em_entry = NULL,
297 .tf_dev_insert_ext_em_entry = NULL,
298 .tf_dev_delete_ext_em_entry = NULL,
299 .tf_dev_get_em_resc_info = NULL,
300 .tf_dev_alloc_tbl_scope = NULL,
301 .tf_dev_map_tbl_scope = NULL,
302 .tf_dev_map_parif = NULL,
303 .tf_dev_free_tbl_scope = NULL,
304 .tf_dev_set_if_tbl = NULL,
305 .tf_dev_get_if_tbl = NULL,
306 .tf_dev_set_global_cfg = NULL,
307 .tf_dev_get_global_cfg = NULL,
308 .tf_dev_get_mailbox = tf_dev_p58_get_mailbox,
309 .tf_dev_word_align = NULL,
313 * Truflow P58 device specific functions
315 const struct tf_dev_ops tf_dev_ops_p58 = {
316 .tf_dev_get_max_types = tf_dev_p58_get_max_types,
317 .tf_dev_get_resource_str = tf_dev_p58_get_resource_str,
318 .tf_dev_get_tcam_slice_info = tf_dev_p58_get_tcam_slice_info,
319 .tf_dev_alloc_ident = tf_ident_alloc,
320 .tf_dev_free_ident = tf_ident_free,
321 .tf_dev_search_ident = tf_ident_search,
322 .tf_dev_get_ident_resc_info = tf_ident_get_resc_info,
323 .tf_dev_get_tbl_info = tf_dev_p58_get_sram_tbl_info,
324 .tf_dev_alloc_tbl = tf_tbl_alloc,
325 .tf_dev_alloc_ext_tbl = tf_tbl_ext_alloc,
326 .tf_dev_free_tbl = tf_tbl_free,
327 .tf_dev_free_ext_tbl = tf_tbl_ext_free,
328 .tf_dev_set_tbl = tf_tbl_set,
329 .tf_dev_set_ext_tbl = tf_tbl_ext_common_set,
330 .tf_dev_get_tbl = tf_tbl_get,
331 .tf_dev_get_bulk_tbl = tf_tbl_bulk_get,
332 .tf_dev_get_shared_tbl_increment = tf_dev_p58_get_shared_tbl_increment,
333 .tf_dev_get_tbl_resc_info = tf_tbl_get_resc_info,
334 #ifdef TF_TCAM_SHARED
335 .tf_dev_alloc_tcam = tf_tcam_shared_alloc,
336 .tf_dev_free_tcam = tf_tcam_shared_free,
337 .tf_dev_set_tcam = tf_tcam_shared_set,
338 .tf_dev_get_tcam = tf_tcam_shared_get,
339 .tf_dev_move_tcam = tf_tcam_shared_move_p58,
340 .tf_dev_clear_tcam = tf_tcam_shared_clear,
341 #else /* !TF_TCAM_SHARED */
342 .tf_dev_alloc_tcam = tf_tcam_alloc,
343 .tf_dev_free_tcam = tf_tcam_free,
344 .tf_dev_set_tcam = tf_tcam_set,
345 .tf_dev_get_tcam = tf_tcam_get,
347 .tf_dev_alloc_search_tcam = tf_tcam_alloc_search,
348 .tf_dev_get_tcam_resc_info = tf_tcam_get_resc_info,
349 .tf_dev_insert_int_em_entry = tf_em_hash_insert_int_entry,
350 .tf_dev_delete_int_em_entry = tf_em_hash_delete_int_entry,
351 .tf_dev_move_int_em_entry = tf_em_move_int_entry,
352 .tf_dev_insert_ext_em_entry = NULL,
353 .tf_dev_delete_ext_em_entry = NULL,
354 .tf_dev_get_em_resc_info = tf_em_get_resc_info,
355 .tf_dev_alloc_tbl_scope = NULL,
356 .tf_dev_map_tbl_scope = NULL,
357 .tf_dev_map_parif = NULL,
358 .tf_dev_free_tbl_scope = NULL,
359 .tf_dev_set_if_tbl = tf_if_tbl_set,
360 .tf_dev_get_if_tbl = tf_if_tbl_get,
361 .tf_dev_set_global_cfg = tf_global_cfg_set,
362 .tf_dev_get_global_cfg = tf_global_cfg_get,
363 .tf_dev_get_mailbox = tf_dev_p58_get_mailbox,
364 .tf_dev_word_align = tf_dev_p58_word_align,
365 .tf_dev_cfa_key_hash = hcapi_cfa_p58_key_hash