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