fb5ad29a5cd30b38e63ff3c21b204bbfeed44b03
[dpdk.git] / drivers / net / bnxt / tf_core / tf_device_p58.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #include <rte_common.h>
7
8 #include "cfa_resource_types.h"
9 #include "tf_device.h"
10 #include "tf_identifier.h"
11 #include "tf_tbl.h"
12 #include "tf_tcam.h"
13 #include "tf_em.h"
14 #include "tf_if_tbl.h"
15 #include "tfp.h"
16
17 #define TF_DEV_P58_PARIF_MAX 16
18 #define TF_DEV_P58_PF_MASK 0xfUL
19
20 const char *tf_resource_str_p58[CFA_RESOURCE_TYPE_P58_LAST + 1] = {
21         /* CFA_RESOURCE_TYPE_P58_METER */
22         "meter   ",
23         /* CFA_RESOURCE_TYPE_P58_SRAM_BANK_0 */
24         "sram_bk0",
25         /* CFA_RESOURCE_TYPE_P58_SRAM_BANK_1 */
26         "sram_bk1",
27         /* CFA_RESOURCE_TYPE_P58_SRAM_BANK_2 */
28         "sram_bk2",
29         /* CFA_RESOURCE_TYPE_P58_SRAM_BANK_3 */
30         "sram_bk3",
31         /* CFA_RESOURCE_TYPE_P58_L2_CTXT_TCAM_HIGH */
32         "l2ctx_hi",
33         /* CFA_RESOURCE_TYPE_P58_L2_CTXT_TCAM_LOW */
34         "l2ctx_lo",
35         /* CFA_RESOURCE_TYPE_P58_L2_CTXT_REMAP_HIGH */
36         "l2ctr_hi",
37         /* CFA_RESOURCE_TYPE_P58_L2_CTXT_REMAP_LOW */
38         "l2ctr_lo",
39         /* CFA_RESOURCE_TYPE_P58_PROF_FUNC */
40         "prf_func",
41         /* CFA_RESOURCE_TYPE_P58_PROF_TCAM */
42         "prf_tcam",
43         /* CFA_RESOURCE_TYPE_P58_EM_PROF_ID */
44         "em_prof ",
45         /* CFA_RESOURCE_TYPE_P58_WC_TCAM_PROF_ID */
46         "wc_prof ",
47         /* CFA_RESOURCE_TYPE_P58_EM_REC */
48         "em_rec  ",
49         /* CFA_RESOURCE_TYPE_P58_WC_TCAM */
50         "wc_tcam ",
51         /* CFA_RESOURCE_TYPE_P58_METER_PROF */
52         "mtr_prof",
53         /* CFA_RESOURCE_TYPE_P58_MIRROR */
54         "mirror  ",
55         /* CFA_RESOURCE_TYPE_P58_EM_FKB */
56         "em_fkb  ",
57         /* CFA_RESOURCE_TYPE_P58_WC_FKB */
58         "wc_fkb  ",
59         /* CFA_RESOURCE_TYPE_P58_VEB_TCAM */
60         "veb     ",
61 };
62
63 /**
64  * Device specific function that retrieves the MAX number of HCAPI
65  * types the device supports.
66  *
67  * [in] tfp
68  *   Pointer to TF handle
69  *
70  * [out] max_types
71  *   Pointer to the MAX number of HCAPI types supported
72  *
73  * Returns
74  *   - (0) if successful.
75  *   - (-EINVAL) on failure.
76  */
77 static int
78 tf_dev_p58_get_max_types(struct tf *tfp,
79                         uint16_t *max_types)
80 {
81         struct tf_session *tfs;
82         struct tf_dev_info *dev;
83         int rc;
84
85         if (max_types == NULL || tfp == NULL)
86                 return -EINVAL;
87
88         /* Retrieve the session information */
89         rc = tf_session_get_session(tfp, &tfs);
90         if (rc)
91                 return rc;
92
93         /* Retrieve the device information */
94         rc = tf_session_get_device(tfs, &dev);
95         if (rc)
96                 return rc;
97
98         *max_types = CFA_RESOURCE_TYPE_P58_LAST + 1;
99
100         return 0;
101 }
102 /**
103  * Device specific function that retrieves a human readable
104  * string to identify a CFA resource type.
105  *
106  * [in] tfp
107  *   Pointer to TF handle
108  *
109  * [in] resource_id
110  *   HCAPI CFA resource id
111  *
112  * [out] resource_str
113  *   Resource string
114  *
115  * Returns
116  *   - (0) if successful.
117  *   - (-EINVAL) on failure.
118  */
119 static int
120 tf_dev_p58_get_resource_str(struct tf *tfp __rte_unused,
121                             uint16_t resource_id,
122                             const char **resource_str)
123 {
124         if (resource_str == NULL)
125                 return -EINVAL;
126
127         if (resource_id > CFA_RESOURCE_TYPE_P58_LAST)
128                 return -EINVAL;
129
130         *resource_str = tf_resource_str_p58[resource_id];
131
132         return 0;
133 }
134
135 /**
136  * Device specific function that retrieves the WC TCAM slices the
137  * device supports.
138  *
139  * [in] tfp
140  *   Pointer to TF handle
141  *
142  * [out] slice_size
143  *   Pointer to the WC TCAM slice size
144  *
145  * [out] num_slices_per_row
146  *   Pointer to the WC TCAM row slice configuration
147  *
148  * Returns
149  *   - (0) if successful.
150  *   - (-EINVAL) on failure.
151  */
152 static int
153 tf_dev_p58_get_tcam_slice_info(struct tf *tfp __rte_unused,
154                               enum tf_tcam_tbl_type type,
155                               uint16_t key_sz,
156                               uint16_t *num_slices_per_row)
157 {
158 #define CFA_P58_WC_TCAM_SLICES_PER_ROW 2
159 #define CFA_P58_WC_TCAM_SLICE_SIZE     12
160
161         if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
162                 *num_slices_per_row = CFA_P58_WC_TCAM_SLICES_PER_ROW;
163                 if (key_sz > *num_slices_per_row * CFA_P58_WC_TCAM_SLICE_SIZE)
164                         return -ENOTSUP;
165
166                 *num_slices_per_row = 1;
167         } else { /* for other type of tcam */
168                 *num_slices_per_row = 1;
169         }
170
171         return 0;
172 }
173
174 static int
175 tf_dev_p58_map_parif(struct tf *tfp __rte_unused,
176                     uint16_t parif_bitmask,
177                     uint16_t pf,
178                     uint8_t *data,
179                     uint8_t *mask,
180                     uint16_t sz_in_bytes)
181 {
182         uint32_t parif_pf[2] = { 0 };
183         uint32_t parif_pf_mask[2] = { 0 };
184         uint32_t parif;
185         uint32_t shift;
186
187         if (sz_in_bytes != sizeof(uint64_t))
188                 return -ENOTSUP;
189
190         for (parif = 0; parif < TF_DEV_P58_PARIF_MAX; parif++) {
191                 if (parif_bitmask & (1UL << parif)) {
192                         if (parif < 8) {
193                                 shift = 4 * parif;
194                                 parif_pf_mask[0] |= TF_DEV_P58_PF_MASK << shift;
195                                 parif_pf[0] |= pf << shift;
196                         } else {
197                                 shift = 4 * (parif - 8);
198                                 parif_pf_mask[1] |= TF_DEV_P58_PF_MASK << shift;
199                                 parif_pf[1] |= pf << shift;
200                         }
201                 }
202         }
203         tfp_memcpy(data, parif_pf, sz_in_bytes);
204         tfp_memcpy(mask, parif_pf_mask, sz_in_bytes);
205
206         return 0;
207 }
208
209
210 /**
211  * Truflow P58 device specific functions
212  */
213 const struct tf_dev_ops tf_dev_ops_p58_init = {
214         .tf_dev_get_max_types = tf_dev_p58_get_max_types,
215         .tf_dev_get_resource_str = tf_dev_p58_get_resource_str,
216         .tf_dev_get_tcam_slice_info = tf_dev_p58_get_tcam_slice_info,
217         .tf_dev_alloc_ident = NULL,
218         .tf_dev_free_ident = NULL,
219         .tf_dev_search_ident = NULL,
220         .tf_dev_alloc_ext_tbl = NULL,
221         .tf_dev_alloc_tbl = NULL,
222         .tf_dev_free_ext_tbl = NULL,
223         .tf_dev_free_tbl = NULL,
224         .tf_dev_alloc_search_tbl = NULL,
225         .tf_dev_set_tbl = NULL,
226         .tf_dev_set_ext_tbl = NULL,
227         .tf_dev_get_tbl = NULL,
228         .tf_dev_get_bulk_tbl = NULL,
229         .tf_dev_alloc_tcam = NULL,
230         .tf_dev_free_tcam = NULL,
231         .tf_dev_alloc_search_tcam = NULL,
232         .tf_dev_set_tcam = NULL,
233         .tf_dev_get_tcam = NULL,
234         .tf_dev_insert_int_em_entry = NULL,
235         .tf_dev_delete_int_em_entry = NULL,
236         .tf_dev_insert_ext_em_entry = NULL,
237         .tf_dev_delete_ext_em_entry = NULL,
238         .tf_dev_alloc_tbl_scope = NULL,
239         .tf_dev_map_tbl_scope = NULL,
240         .tf_dev_map_parif = NULL,
241         .tf_dev_free_tbl_scope = NULL,
242         .tf_dev_set_if_tbl = NULL,
243         .tf_dev_get_if_tbl = NULL,
244         .tf_dev_set_global_cfg = NULL,
245         .tf_dev_get_global_cfg = NULL,
246 };
247
248 /**
249  * Truflow P58 device specific functions
250  */
251 const struct tf_dev_ops tf_dev_ops_p58 = {
252         .tf_dev_get_max_types = tf_dev_p58_get_max_types,
253         .tf_dev_get_resource_str = tf_dev_p58_get_resource_str,
254         .tf_dev_get_tcam_slice_info = tf_dev_p58_get_tcam_slice_info,
255         .tf_dev_alloc_ident = tf_ident_alloc,
256         .tf_dev_free_ident = tf_ident_free,
257         .tf_dev_search_ident = tf_ident_search,
258         .tf_dev_alloc_tbl = tf_tbl_alloc,
259         .tf_dev_alloc_ext_tbl = tf_tbl_ext_alloc,
260         .tf_dev_free_tbl = tf_tbl_free,
261         .tf_dev_free_ext_tbl = tf_tbl_ext_free,
262         .tf_dev_alloc_search_tbl = tf_tbl_alloc_search,
263         .tf_dev_set_tbl = tf_tbl_set,
264         .tf_dev_set_ext_tbl = tf_tbl_ext_common_set,
265         .tf_dev_get_tbl = tf_tbl_get,
266         .tf_dev_get_bulk_tbl = tf_tbl_bulk_get,
267         .tf_dev_alloc_tcam = tf_tcam_alloc,
268         .tf_dev_free_tcam = tf_tcam_free,
269         .tf_dev_alloc_search_tcam = tf_tcam_alloc_search,
270         .tf_dev_set_tcam = tf_tcam_set,
271         .tf_dev_get_tcam = NULL,
272         .tf_dev_insert_int_em_entry = tf_em_insert_int_entry,
273         .tf_dev_delete_int_em_entry = tf_em_delete_int_entry,
274         .tf_dev_insert_ext_em_entry = tf_em_insert_ext_entry,
275         .tf_dev_delete_ext_em_entry = tf_em_delete_ext_entry,
276         .tf_dev_alloc_tbl_scope = tf_em_ext_common_alloc,
277         .tf_dev_map_tbl_scope = tf_em_ext_map_tbl_scope,
278         .tf_dev_map_parif = tf_dev_p58_map_parif,
279         .tf_dev_free_tbl_scope = tf_em_ext_common_free,
280         .tf_dev_set_if_tbl = tf_if_tbl_set,
281         .tf_dev_get_if_tbl = tf_if_tbl_get,
282         .tf_dev_set_global_cfg = tf_global_cfg_set,
283         .tf_dev_get_global_cfg = tf_global_cfg_get,
284 };