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_if_tbl.h"
16 #include "tf_msg_common.h"
18 #define TF_DEV_P4_PARIF_MAX 16
19 #define TF_DEV_P4_PF_MASK 0xfUL
21 const char *tf_resource_str_p4[CFA_RESOURCE_TYPE_P4_LAST + 1] = {
22 /* CFA_RESOURCE_TYPE_P4_MCG */
24 /* CFA_RESOURCE_TYPE_P4_ENCAP_8B */
26 /* CFA_RESOURCE_TYPE_P4_ENCAP_16B */
28 /* CFA_RESOURCE_TYPE_P4_ENCAP_64B */
30 /* CFA_RESOURCE_TYPE_P4_SP_MAC */
32 /* CFA_RESOURCE_TYPE_P4_SP_MAC_IPV4 */
34 /* CFA_RESOURCE_TYPE_P4_SP_MAC_IPV6 */
36 /* CFA_RESOURCE_TYPE_P4_COUNTER_64B */
38 /* CFA_RESOURCE_TYPE_P4_NAT_PORT */
40 /* CFA_RESOURCE_TYPE_P4_NAT_IPV4 */
42 /* CFA_RESOURCE_TYPE_P4_METER */
44 /* CFA_RESOURCE_TYPE_P4_FLOW_STATE */
46 /* CFA_RESOURCE_TYPE_P4_FULL_ACTION */
48 /* CFA_RESOURCE_TYPE_P4_FORMAT_0_ACTION */
50 /* CFA_RESOURCE_TYPE_P4_EXT_FORMAT_0_ACTION */
52 /* CFA_RESOURCE_TYPE_P4_FORMAT_1_ACTION */
54 /* CFA_RESOURCE_TYPE_P4_FORMAT_2_ACTION */
56 /* CFA_RESOURCE_TYPE_P4_FORMAT_3_ACTION */
58 /* CFA_RESOURCE_TYPE_P4_FORMAT_4_ACTION */
60 /* CFA_RESOURCE_TYPE_P4_FORMAT_5_ACTION */
62 /* CFA_RESOURCE_TYPE_P4_FORMAT_6_ACTION */
64 /* CFA_RESOURCE_TYPE_P4_L2_CTXT_TCAM_HIGH */
66 /* CFA_RESOURCE_TYPE_P4_L2_CTXT_TCAM_LOW */
68 /* CFA_RESOURCE_TYPE_P4_L2_CTXT_REMAP_HIGH */
70 /* CFA_RESOURCE_TYPE_P4_L2_CTXT_REMAP_LOW */
72 /* CFA_RESOURCE_TYPE_P4_PROF_FUNC */
74 /* CFA_RESOURCE_TYPE_P4_PROF_TCAM */
76 /* CFA_RESOURCE_TYPE_P4_EM_PROF_ID */
78 /* CFA_RESOURCE_TYPE_P4_EM_REC */
80 /* CFA_RESOURCE_TYPE_P4_WC_TCAM_PROF_ID */
82 /* CFA_RESOURCE_TYPE_P4_WC_TCAM */
84 /* CFA_RESOURCE_TYPE_P4_METER_PROF */
86 /* CFA_RESOURCE_TYPE_P4_MIRROR */
88 /* CFA_RESOURCE_TYPE_P4_SP_TCAM */
90 /* CFA_RESOURCE_TYPE_P4_TBL_SCOPE */
95 * Device specific function that retrieves the MAX number of HCAPI
96 * types the device supports.
99 * Pointer to TF handle
102 * Pointer to the MAX number of CFA resource types supported
105 * - (0) if successful.
106 * - (-EINVAL) on failure.
109 tf_dev_p4_get_max_types(struct tf *tfp,
112 struct tf_session *tfs;
113 struct tf_dev_info *dev;
116 if (max_types == NULL || tfp == NULL)
119 /* Retrieve the session information */
120 rc = tf_session_get_session(tfp, &tfs);
124 /* Retrieve the device information */
125 rc = tf_session_get_device(tfs, &dev);
129 if (dev->type == TF_DEVICE_TYPE_WH)
130 *max_types = CFA_RESOURCE_TYPE_P4_LAST + 1;
131 else if (dev->type == TF_DEVICE_TYPE_SR)
132 *max_types = CFA_RESOURCE_TYPE_P45_LAST + 1;
139 * Device specific function that retrieves a human readable
140 * string to identify a CFA resource type.
143 * Pointer to TF handle
146 * HCAPI CFA resource id
152 * - (0) if successful.
153 * - (-EINVAL) on failure.
156 tf_dev_p4_get_resource_str(struct tf *tfp __rte_unused,
157 uint16_t resource_id,
158 const char **resource_str)
160 if (resource_str == NULL)
163 if (resource_id > CFA_RESOURCE_TYPE_P4_LAST)
166 *resource_str = tf_resource_str_p4[resource_id];
172 * Device specific function that retrieves the WC TCAM slices the
176 * Pointer to TF handle
179 * Pointer to the WC TCAM slice size
181 * [out] num_slices_per_row
182 * Pointer to the WC TCAM row slice configuration
185 * - (0) if successful.
186 * - (-EINVAL) on failure.
189 tf_dev_p4_get_tcam_slice_info(struct tf *tfp __rte_unused,
190 enum tf_tcam_tbl_type type,
192 uint16_t *num_slices_per_row)
194 #define CFA_P4_WC_TCAM_SLICES_PER_ROW 2
195 #define CFA_P4_WC_TCAM_SLICE_SIZE 12
197 if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
198 *num_slices_per_row = CFA_P4_WC_TCAM_SLICES_PER_ROW;
199 if (key_sz > *num_slices_per_row * CFA_P4_WC_TCAM_SLICE_SIZE)
202 *num_slices_per_row = 1;
203 } else { /* for other type of tcam */
204 *num_slices_per_row = 1;
211 tf_dev_p4_map_parif(struct tf *tfp __rte_unused,
212 uint16_t parif_bitmask,
216 uint16_t sz_in_bytes)
218 uint32_t parif_pf[2] = { 0 };
219 uint32_t parif_pf_mask[2] = { 0 };
223 if (sz_in_bytes != sizeof(uint64_t))
226 for (parif = 0; parif < TF_DEV_P4_PARIF_MAX; parif++) {
227 if (parif_bitmask & (1UL << parif)) {
230 parif_pf_mask[0] |= TF_DEV_P4_PF_MASK << shift;
231 parif_pf[0] |= pf << shift;
233 shift = 4 * (parif - 8);
234 parif_pf_mask[1] |= TF_DEV_P4_PF_MASK << shift;
235 parif_pf[1] |= pf << shift;
239 tfp_memcpy(data, parif_pf, sz_in_bytes);
240 tfp_memcpy(mask, parif_pf_mask, sz_in_bytes);
245 static int tf_dev_p4_get_mailbox(void)
252 * Truflow P4 device specific functions
254 const struct tf_dev_ops tf_dev_ops_p4_init = {
255 .tf_dev_get_max_types = tf_dev_p4_get_max_types,
256 .tf_dev_get_resource_str = tf_dev_p4_get_resource_str,
257 .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
258 .tf_dev_alloc_ident = NULL,
259 .tf_dev_free_ident = NULL,
260 .tf_dev_search_ident = NULL,
261 .tf_dev_alloc_ext_tbl = NULL,
262 .tf_dev_alloc_tbl = NULL,
263 .tf_dev_free_ext_tbl = NULL,
264 .tf_dev_free_tbl = NULL,
265 .tf_dev_alloc_search_tbl = NULL,
266 .tf_dev_set_tbl = NULL,
267 .tf_dev_set_ext_tbl = NULL,
268 .tf_dev_get_tbl = NULL,
269 .tf_dev_get_bulk_tbl = NULL,
270 .tf_dev_alloc_tcam = NULL,
271 .tf_dev_free_tcam = NULL,
272 .tf_dev_alloc_search_tcam = NULL,
273 .tf_dev_set_tcam = NULL,
274 .tf_dev_get_tcam = NULL,
275 .tf_dev_insert_int_em_entry = NULL,
276 .tf_dev_delete_int_em_entry = NULL,
277 .tf_dev_insert_ext_em_entry = NULL,
278 .tf_dev_delete_ext_em_entry = NULL,
279 .tf_dev_alloc_tbl_scope = NULL,
280 .tf_dev_map_tbl_scope = NULL,
281 .tf_dev_map_parif = NULL,
282 .tf_dev_free_tbl_scope = NULL,
283 .tf_dev_set_if_tbl = NULL,
284 .tf_dev_get_if_tbl = NULL,
285 .tf_dev_set_global_cfg = NULL,
286 .tf_dev_get_global_cfg = NULL,
287 .tf_dev_get_mailbox = tf_dev_p4_get_mailbox,
291 * Truflow P4 device specific functions
293 const struct tf_dev_ops tf_dev_ops_p4 = {
294 .tf_dev_get_max_types = tf_dev_p4_get_max_types,
295 .tf_dev_get_resource_str = tf_dev_p4_get_resource_str,
296 .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
297 .tf_dev_alloc_ident = tf_ident_alloc,
298 .tf_dev_free_ident = tf_ident_free,
299 .tf_dev_search_ident = tf_ident_search,
300 .tf_dev_alloc_tbl = tf_tbl_alloc,
301 .tf_dev_alloc_ext_tbl = tf_tbl_ext_alloc,
302 .tf_dev_free_tbl = tf_tbl_free,
303 .tf_dev_free_ext_tbl = tf_tbl_ext_free,
304 .tf_dev_alloc_search_tbl = tf_tbl_alloc_search,
305 .tf_dev_set_tbl = tf_tbl_set,
306 .tf_dev_set_ext_tbl = tf_tbl_ext_common_set,
307 .tf_dev_get_tbl = tf_tbl_get,
308 .tf_dev_get_bulk_tbl = tf_tbl_bulk_get,
309 .tf_dev_alloc_tcam = tf_tcam_alloc,
310 .tf_dev_free_tcam = tf_tcam_free,
311 .tf_dev_alloc_search_tcam = tf_tcam_alloc_search,
312 .tf_dev_set_tcam = tf_tcam_set,
313 .tf_dev_get_tcam = NULL,
314 .tf_dev_insert_int_em_entry = tf_em_insert_int_entry,
315 .tf_dev_delete_int_em_entry = tf_em_delete_int_entry,
316 .tf_dev_insert_ext_em_entry = tf_em_insert_ext_entry,
317 .tf_dev_delete_ext_em_entry = tf_em_delete_ext_entry,
318 .tf_dev_alloc_tbl_scope = tf_em_ext_common_alloc,
319 .tf_dev_map_tbl_scope = tf_em_ext_map_tbl_scope,
320 .tf_dev_map_parif = tf_dev_p4_map_parif,
321 .tf_dev_free_tbl_scope = tf_em_ext_common_free,
322 .tf_dev_set_if_tbl = tf_if_tbl_set,
323 .tf_dev_get_if_tbl = tf_if_tbl_get,
324 .tf_dev_set_global_cfg = tf_global_cfg_set,
325 .tf_dev_get_global_cfg = tf_global_cfg_get,
326 .tf_dev_get_mailbox = tf_dev_p4_get_mailbox,