1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
6 #include <rte_common.h>
7 #include <cfa_resource_types.h>
10 #include "tf_identifier.h"
14 #include "tf_if_tbl.h"
17 #define TF_DEV_P4_PARIF_MAX 16
18 #define TF_DEV_P4_PF_MASK 0xfUL
21 * Device specific function that retrieves the MAX number of HCAPI
22 * types the device supports.
25 * Pointer to TF handle
28 * Pointer to the MAX number of HCAPI types supported
31 * - (0) if successful.
32 * - (-EINVAL) on failure.
35 tf_dev_p4_get_max_types(struct tf *tfp,
38 struct tf_session *tfs;
39 struct tf_dev_info *dev;
42 if (max_types == NULL || tfp == NULL)
45 /* Retrieve the session information */
46 rc = tf_session_get_session(tfp, &tfs);
50 /* Retrieve the device information */
51 rc = tf_session_get_device(tfs, &dev);
55 if (dev->type == TF_DEVICE_TYPE_WH)
56 *max_types = CFA_RESOURCE_TYPE_P4_LAST + 1;
57 else if (dev->type == TF_DEVICE_TYPE_SR)
58 *max_types = CFA_RESOURCE_TYPE_P45_LAST + 1;
66 * Device specific function that retrieves the WC TCAM slices the
70 * Pointer to TF handle
73 * Pointer to the WC TCAM slice size
75 * [out] num_slices_per_row
76 * Pointer to the WC TCAM row slice configuration
79 * - (0) if successful.
80 * - (-EINVAL) on failure.
83 tf_dev_p4_get_tcam_slice_info(struct tf *tfp __rte_unused,
84 enum tf_tcam_tbl_type type,
86 uint16_t *num_slices_per_row)
88 #define CFA_P4_WC_TCAM_SLICES_PER_ROW 2
89 #define CFA_P4_WC_TCAM_SLICE_SIZE 12
91 if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
92 *num_slices_per_row = CFA_P4_WC_TCAM_SLICES_PER_ROW;
93 if (key_sz > *num_slices_per_row * CFA_P4_WC_TCAM_SLICE_SIZE)
96 *num_slices_per_row = 1;
97 } else { /* for other type of tcam */
98 *num_slices_per_row = 1;
105 tf_dev_p4_map_parif(struct tf *tfp __rte_unused,
106 struct tf_map_tbl_scope_parms *parms,
109 uint16_t sz_in_bytes)
111 uint32_t parif_pf[2] = { 0 };
112 uint32_t parif_pf_mask[2] = { 0 };
115 uint32_t scope_id = (uint32_t)(parms->tbl_scope_id);
117 if (sz_in_bytes != sizeof(uint64_t))
120 for (parif = 0; parif < TF_DEV_P4_PARIF_MAX; parif++) {
121 if (parms->parif_bitmask & (1UL << parif)) {
124 parif_pf_mask[0] |= TF_DEV_P4_PF_MASK << shift;
125 parif_pf[0] |= scope_id << shift;
127 shift = 4 * (parif - 8);
128 parif_pf_mask[1] |= TF_DEV_P4_PF_MASK << shift;
129 parif_pf[1] |= scope_id << shift;
133 tfp_memcpy(data, parif_pf, sz_in_bytes);
134 tfp_memcpy(mask, parif_pf_mask, sz_in_bytes);
141 * Truflow P4 device specific functions
143 const struct tf_dev_ops tf_dev_ops_p4_init = {
144 .tf_dev_get_max_types = tf_dev_p4_get_max_types,
145 .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
146 .tf_dev_alloc_ident = NULL,
147 .tf_dev_free_ident = NULL,
148 .tf_dev_search_ident = NULL,
149 .tf_dev_alloc_ext_tbl = NULL,
150 .tf_dev_alloc_tbl = NULL,
151 .tf_dev_free_ext_tbl = NULL,
152 .tf_dev_free_tbl = NULL,
153 .tf_dev_alloc_search_tbl = NULL,
154 .tf_dev_set_tbl = NULL,
155 .tf_dev_set_ext_tbl = NULL,
156 .tf_dev_get_tbl = NULL,
157 .tf_dev_get_bulk_tbl = NULL,
158 .tf_dev_alloc_tcam = NULL,
159 .tf_dev_free_tcam = NULL,
160 .tf_dev_alloc_search_tcam = NULL,
161 .tf_dev_set_tcam = NULL,
162 .tf_dev_get_tcam = NULL,
163 .tf_dev_insert_int_em_entry = NULL,
164 .tf_dev_delete_int_em_entry = NULL,
165 .tf_dev_insert_ext_em_entry = NULL,
166 .tf_dev_delete_ext_em_entry = NULL,
167 .tf_dev_alloc_tbl_scope = NULL,
168 .tf_dev_map_tbl_scope = NULL,
169 .tf_dev_map_parif = NULL,
170 .tf_dev_free_tbl_scope = NULL,
171 .tf_dev_set_if_tbl = NULL,
172 .tf_dev_get_if_tbl = NULL,
173 .tf_dev_set_global_cfg = NULL,
174 .tf_dev_get_global_cfg = NULL,
178 * Truflow P4 device specific functions
180 const struct tf_dev_ops tf_dev_ops_p4 = {
181 .tf_dev_get_max_types = tf_dev_p4_get_max_types,
182 .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
183 .tf_dev_alloc_ident = tf_ident_alloc,
184 .tf_dev_free_ident = tf_ident_free,
185 .tf_dev_search_ident = tf_ident_search,
186 .tf_dev_alloc_tbl = tf_tbl_alloc,
187 .tf_dev_alloc_ext_tbl = tf_tbl_ext_alloc,
188 .tf_dev_free_tbl = tf_tbl_free,
189 .tf_dev_free_ext_tbl = tf_tbl_ext_free,
190 .tf_dev_alloc_search_tbl = tf_tbl_alloc_search,
191 .tf_dev_set_tbl = tf_tbl_set,
192 .tf_dev_set_ext_tbl = tf_tbl_ext_common_set,
193 .tf_dev_get_tbl = tf_tbl_get,
194 .tf_dev_get_bulk_tbl = tf_tbl_bulk_get,
195 .tf_dev_alloc_tcam = tf_tcam_alloc,
196 .tf_dev_free_tcam = tf_tcam_free,
197 .tf_dev_alloc_search_tcam = tf_tcam_alloc_search,
198 .tf_dev_set_tcam = tf_tcam_set,
199 .tf_dev_get_tcam = NULL,
200 .tf_dev_insert_int_em_entry = tf_em_insert_int_entry,
201 .tf_dev_delete_int_em_entry = tf_em_delete_int_entry,
202 .tf_dev_insert_ext_em_entry = tf_em_insert_ext_entry,
203 .tf_dev_delete_ext_em_entry = tf_em_delete_ext_entry,
204 .tf_dev_alloc_tbl_scope = tf_em_ext_common_alloc,
205 .tf_dev_map_tbl_scope = tf_em_ext_map_tbl_scope,
206 .tf_dev_map_parif = tf_dev_p4_map_parif,
207 .tf_dev_free_tbl_scope = tf_em_ext_common_free,
208 .tf_dev_set_if_tbl = tf_if_tbl_set,
209 .tf_dev_get_if_tbl = tf_if_tbl_get,
210 .tf_dev_set_global_cfg = tf_global_cfg_set,
211 .tf_dev_get_global_cfg = tf_global_cfg_get,