a492c62bff4c461424aad5e3359ec3d20038047a
[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 #ifdef TF_TCAM_SHARED
14 #include "tf_tcam_shared.h"
15 #endif /* TF_TCAM_SHARED */
16 #include "tf_em.h"
17 #include "tf_if_tbl.h"
18 #include "tfp.h"
19 #include "tf_msg_common.h"
20
21 #define TF_DEV_P58_PARIF_MAX 16
22 #define TF_DEV_P58_PF_MASK 0xfUL
23
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     ",
46         [CFA_RESOURCE_TYPE_P58_METADATA]           = "metadata",
47 };
48
49 /**
50  * Device specific function that retrieves the MAX number of HCAPI
51  * types the device supports.
52  *
53  * [in] tfp
54  *   Pointer to TF handle
55  *
56  * [out] max_types
57  *   Pointer to the MAX number of HCAPI types supported
58  *
59  * Returns
60  *   - (0) if successful.
61  *   - (-EINVAL) on failure.
62  */
63 static int
64 tf_dev_p58_get_max_types(struct tf *tfp,
65                          uint16_t *max_types)
66 {
67         if (max_types == NULL || tfp == NULL)
68                 return -EINVAL;
69
70         *max_types = CFA_RESOURCE_TYPE_P58_LAST + 1;
71
72         return 0;
73 }
74 /**
75  * Device specific function that retrieves a human readable
76  * string to identify a CFA resource type.
77  *
78  * [in] tfp
79  *   Pointer to TF handle
80  *
81  * [in] resource_id
82  *   HCAPI CFA resource id
83  *
84  * [out] resource_str
85  *   Resource string
86  *
87  * Returns
88  *   - (0) if successful.
89  *   - (-EINVAL) on failure.
90  */
91 static int
92 tf_dev_p58_get_resource_str(struct tf *tfp __rte_unused,
93                             uint16_t resource_id,
94                             const char **resource_str)
95 {
96         if (resource_str == NULL)
97                 return -EINVAL;
98
99         if (resource_id > CFA_RESOURCE_TYPE_P58_LAST)
100                 return -EINVAL;
101
102         *resource_str = tf_resource_str_p58[resource_id];
103
104         return 0;
105 }
106
107 /**
108  * Device specific function that retrieves the WC TCAM slices the
109  * device supports.
110  *
111  * [in] tfp
112  *   Pointer to TF handle
113  *
114  * [out] slice_size
115  *   Pointer to the WC TCAM slice size
116  *
117  * [out] num_slices_per_row
118  *   Pointer to the WC TCAM row slice configuration
119  *
120  * Returns
121  *   - (0) if successful.
122  *   - (-EINVAL) on failure.
123  */
124 static int
125 tf_dev_p58_get_tcam_slice_info(struct tf *tfp __rte_unused,
126                               enum tf_tcam_tbl_type type,
127                               uint16_t key_sz,
128                               uint16_t *num_slices_per_row)
129 {
130 #define CFA_P58_WC_TCAM_SLICES_PER_ROW 1
131 #define CFA_P58_WC_TCAM_SLICE_SIZE     24
132
133         if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
134                 /* only support single slice key size now */
135                 *num_slices_per_row = CFA_P58_WC_TCAM_SLICES_PER_ROW;
136                 if (key_sz > *num_slices_per_row * CFA_P58_WC_TCAM_SLICE_SIZE)
137                         return -ENOTSUP;
138         } else { /* for other type of tcam */
139                 *num_slices_per_row = 1;
140         }
141
142         return 0;
143 }
144
145 static int tf_dev_p58_get_mailbox(void)
146 {
147         return TF_CHIMP_MB;
148 }
149
150 static int tf_dev_p58_word_align(uint16_t size)
151 {
152         return ((((size) + 63) >> 6) * 8);
153 }
154
155 /**
156  * Device specific function that retrieves the increment
157  * required for certain table types in a shared session
158  *
159  * [in] tfp
160  * tf handle
161  *
162  * [in/out] parms
163  *   pointer to parms structure
164  *
165  * Returns
166  *   - (0) if successful.
167  *   - (-EINVAL) on failure.
168  */
169 static int tf_dev_p58_get_shared_tbl_increment(struct tf *tfp __rte_unused,
170                                 struct tf_get_shared_tbl_increment_parms *parms)
171 {
172         switch (parms->type) {
173         case TF_TBL_TYPE_FULL_ACT_RECORD:
174         case TF_TBL_TYPE_COMPACT_ACT_RECORD:
175         case TF_TBL_TYPE_ACT_ENCAP_8B:
176         case TF_TBL_TYPE_ACT_ENCAP_16B:
177         case TF_TBL_TYPE_ACT_ENCAP_32B:
178         case TF_TBL_TYPE_ACT_ENCAP_64B:
179         case TF_TBL_TYPE_ACT_SP_SMAC:
180         case TF_TBL_TYPE_ACT_SP_SMAC_IPV4:
181         case TF_TBL_TYPE_ACT_SP_SMAC_IPV6:
182         case TF_TBL_TYPE_ACT_STATS_64:
183         case TF_TBL_TYPE_ACT_MODIFY_IPV4:
184         case TF_TBL_TYPE_ACT_MODIFY_8B:
185         case TF_TBL_TYPE_ACT_MODIFY_16B:
186         case TF_TBL_TYPE_ACT_MODIFY_32B:
187         case TF_TBL_TYPE_ACT_MODIFY_64B:
188                 parms->increment_cnt = 8;
189                 break;
190         default:
191                 parms->increment_cnt = 1;
192                 break;
193         }
194         return 0;
195 }
196
197 #define TF_DEV_P58_BANK_SZ_64B 2048
198 /**
199  * Get SRAM table information.
200  *
201  * Converts an internal RM allocated element offset to
202  * a user address and vice versa.
203  *
204  * [in] tfp
205  *   Pointer to TF handle
206  *
207  * [in] type
208  *   Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
209  *
210  * [in/out] base
211  *   Pointer to the Base address of the associated SRAM bank used for
212  *   the type of record allocated.
213  *
214  * [in/out] shift
215  *   Pointer to the factor to be used as a multiplier to translate
216  *   between the RM units to the user address.  SRAM manages 64B entries
217  *   Addresses must be shifted to an 8B address.
218  *
219  * Returns
220  *   - (0) if successful.
221  *   - (-EINVAL) on failure.
222  */
223 static int tf_dev_p58_get_sram_tbl_info(struct tf *tfp __rte_unused,
224                                         void *db,
225                                         enum tf_tbl_type type,
226                                         uint16_t *base,
227                                         uint16_t *shift)
228 {
229         uint16_t hcapi_type;
230         struct tf_rm_get_hcapi_parms parms;
231         int rc;
232
233         parms.rm_db = db;
234         parms.subtype = type;
235         parms.hcapi_type = &hcapi_type;
236
237         rc = tf_rm_get_hcapi_type(&parms);
238         if (rc) {
239                 *base = 0;
240                 *shift = 0;
241                 return 0;
242         }
243
244         switch (hcapi_type) {
245         case CFA_RESOURCE_TYPE_P58_SRAM_BANK_0:
246                 *base = 0;
247                 *shift = 3;
248                 break;
249         case CFA_RESOURCE_TYPE_P58_SRAM_BANK_1:
250                 *base = TF_DEV_P58_BANK_SZ_64B;
251                 *shift = 3;
252                 break;
253         case CFA_RESOURCE_TYPE_P58_SRAM_BANK_2:
254                 *base = TF_DEV_P58_BANK_SZ_64B * 2;
255                 *shift = 3;
256                 break;
257         case CFA_RESOURCE_TYPE_P58_SRAM_BANK_3:
258                 *base = TF_DEV_P58_BANK_SZ_64B * 3;
259                 *shift = 3;
260                 break;
261         default:
262                 *base = 0;
263                 *shift = 0;
264                 break;
265         }
266         return 0;
267 }
268 /**
269  * Truflow P58 device specific functions
270  */
271 const struct tf_dev_ops tf_dev_ops_p58_init = {
272         .tf_dev_get_max_types = tf_dev_p58_get_max_types,
273         .tf_dev_get_resource_str = tf_dev_p58_get_resource_str,
274         .tf_dev_get_tcam_slice_info = tf_dev_p58_get_tcam_slice_info,
275         .tf_dev_alloc_ident = NULL,
276         .tf_dev_free_ident = NULL,
277         .tf_dev_search_ident = NULL,
278         .tf_dev_get_ident_resc_info = NULL,
279         .tf_dev_get_tbl_info = NULL,
280         .tf_dev_alloc_ext_tbl = NULL,
281         .tf_dev_alloc_tbl = NULL,
282         .tf_dev_free_ext_tbl = NULL,
283         .tf_dev_free_tbl = NULL,
284         .tf_dev_set_tbl = NULL,
285         .tf_dev_set_ext_tbl = NULL,
286         .tf_dev_get_tbl = NULL,
287         .tf_dev_get_bulk_tbl = NULL,
288         .tf_dev_get_shared_tbl_increment = tf_dev_p58_get_shared_tbl_increment,
289         .tf_dev_get_tbl_resc_info = NULL,
290         .tf_dev_alloc_tcam = NULL,
291         .tf_dev_free_tcam = NULL,
292         .tf_dev_alloc_search_tcam = NULL,
293         .tf_dev_set_tcam = NULL,
294         .tf_dev_get_tcam = NULL,
295         .tf_dev_get_tcam_resc_info = NULL,
296         .tf_dev_insert_int_em_entry = NULL,
297         .tf_dev_delete_int_em_entry = NULL,
298         .tf_dev_insert_ext_em_entry = NULL,
299         .tf_dev_delete_ext_em_entry = NULL,
300         .tf_dev_get_em_resc_info = NULL,
301         .tf_dev_alloc_tbl_scope = NULL,
302         .tf_dev_map_tbl_scope = NULL,
303         .tf_dev_map_parif = NULL,
304         .tf_dev_free_tbl_scope = NULL,
305         .tf_dev_set_if_tbl = NULL,
306         .tf_dev_get_if_tbl = NULL,
307         .tf_dev_set_global_cfg = NULL,
308         .tf_dev_get_global_cfg = NULL,
309         .tf_dev_get_mailbox = tf_dev_p58_get_mailbox,
310         .tf_dev_word_align = NULL,
311 };
312
313 /**
314  * Truflow P58 device specific functions
315  */
316 const struct tf_dev_ops tf_dev_ops_p58 = {
317         .tf_dev_get_max_types = tf_dev_p58_get_max_types,
318         .tf_dev_get_resource_str = tf_dev_p58_get_resource_str,
319         .tf_dev_get_tcam_slice_info = tf_dev_p58_get_tcam_slice_info,
320         .tf_dev_alloc_ident = tf_ident_alloc,
321         .tf_dev_free_ident = tf_ident_free,
322         .tf_dev_search_ident = tf_ident_search,
323         .tf_dev_get_ident_resc_info = tf_ident_get_resc_info,
324         .tf_dev_get_tbl_info = tf_dev_p58_get_sram_tbl_info,
325         .tf_dev_alloc_tbl = tf_tbl_alloc,
326         .tf_dev_alloc_ext_tbl = tf_tbl_ext_alloc,
327         .tf_dev_free_tbl = tf_tbl_free,
328         .tf_dev_free_ext_tbl = tf_tbl_ext_free,
329         .tf_dev_set_tbl = tf_tbl_set,
330         .tf_dev_set_ext_tbl = tf_tbl_ext_common_set,
331         .tf_dev_get_tbl = tf_tbl_get,
332         .tf_dev_get_bulk_tbl = tf_tbl_bulk_get,
333         .tf_dev_get_shared_tbl_increment = tf_dev_p58_get_shared_tbl_increment,
334         .tf_dev_get_tbl_resc_info = tf_tbl_get_resc_info,
335 #ifdef TF_TCAM_SHARED
336         .tf_dev_alloc_tcam = tf_tcam_shared_alloc,
337         .tf_dev_free_tcam = tf_tcam_shared_free,
338         .tf_dev_set_tcam = tf_tcam_shared_set,
339         .tf_dev_get_tcam = tf_tcam_shared_get,
340         .tf_dev_move_tcam = tf_tcam_shared_move_p58,
341         .tf_dev_clear_tcam = tf_tcam_shared_clear,
342 #else /* !TF_TCAM_SHARED */
343         .tf_dev_alloc_tcam = tf_tcam_alloc,
344         .tf_dev_free_tcam = tf_tcam_free,
345         .tf_dev_set_tcam = tf_tcam_set,
346         .tf_dev_get_tcam = tf_tcam_get,
347 #endif
348         .tf_dev_alloc_search_tcam = tf_tcam_alloc_search,
349         .tf_dev_get_tcam_resc_info = tf_tcam_get_resc_info,
350         .tf_dev_insert_int_em_entry = tf_em_hash_insert_int_entry,
351         .tf_dev_delete_int_em_entry = tf_em_hash_delete_int_entry,
352         .tf_dev_move_int_em_entry = tf_em_move_int_entry,
353         .tf_dev_insert_ext_em_entry = NULL,
354         .tf_dev_delete_ext_em_entry = NULL,
355         .tf_dev_get_em_resc_info = tf_em_get_resc_info,
356         .tf_dev_alloc_tbl_scope = NULL,
357         .tf_dev_map_tbl_scope = NULL,
358         .tf_dev_map_parif = NULL,
359         .tf_dev_free_tbl_scope = NULL,
360         .tf_dev_set_if_tbl = tf_if_tbl_set,
361         .tf_dev_get_if_tbl = tf_if_tbl_get,
362         .tf_dev_set_global_cfg = tf_global_cfg_set,
363         .tf_dev_get_global_cfg = tf_global_cfg_get,
364         .tf_dev_get_mailbox = tf_dev_p58_get_mailbox,
365         .tf_dev_word_align = tf_dev_p58_word_align,
366         .tf_dev_cfa_key_hash = hcapi_cfa_p58_key_hash
367 };