net/bnxt: add hashing changes for Thor
[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 #include "tf_msg_common.h"
17
18 #define TF_DEV_P58_PARIF_MAX 16
19 #define TF_DEV_P58_PF_MASK 0xfUL
20
21 /* For print alignment, make all entries 8 chars in this table */
22 const char *tf_resource_str_p58[CFA_RESOURCE_TYPE_P58_LAST + 1] = {
23         [CFA_RESOURCE_TYPE_P58_METER]              = "meter   ",
24         [CFA_RESOURCE_TYPE_P58_SRAM_BANK_0]        = "sram_bk0",
25         [CFA_RESOURCE_TYPE_P58_SRAM_BANK_1]        = "sram_bk1",
26         [CFA_RESOURCE_TYPE_P58_SRAM_BANK_2]        = "sram_bk2",
27         [CFA_RESOURCE_TYPE_P58_SRAM_BANK_3]        = "sram_bk3",
28         [CFA_RESOURCE_TYPE_P58_L2_CTXT_TCAM_HIGH]  = "l2ctx_hi",
29         [CFA_RESOURCE_TYPE_P58_L2_CTXT_TCAM_LOW]   = "l2ctx_lo",
30         [CFA_RESOURCE_TYPE_P58_L2_CTXT_REMAP_HIGH] = "l2ctr_hi",
31         [CFA_RESOURCE_TYPE_P58_L2_CTXT_REMAP_LOW]  = "l2ctr_lo",
32         [CFA_RESOURCE_TYPE_P58_PROF_FUNC]          = "prf_func",
33         [CFA_RESOURCE_TYPE_P58_PROF_TCAM]          = "prf_tcam",
34         [CFA_RESOURCE_TYPE_P58_EM_PROF_ID]         = "em_prof ",
35         [CFA_RESOURCE_TYPE_P58_WC_TCAM_PROF_ID]    = "wc_prof ",
36         [CFA_RESOURCE_TYPE_P58_EM_REC]             = "em_rec  ",
37         [CFA_RESOURCE_TYPE_P58_WC_TCAM]            = "wc_tcam ",
38         [CFA_RESOURCE_TYPE_P58_METER_PROF]         = "mtr_prof",
39         [CFA_RESOURCE_TYPE_P58_MIRROR]             = "mirror  ",
40         [CFA_RESOURCE_TYPE_P58_EM_FKB]             = "em_fkb  ",
41         [CFA_RESOURCE_TYPE_P58_WC_FKB]             = "wc_fkb  ",
42         [CFA_RESOURCE_TYPE_P58_VEB_TCAM]           = "veb     ",
43 };
44
45 /**
46  * Device specific function that retrieves the MAX number of HCAPI
47  * types the device supports.
48  *
49  * [in] tfp
50  *   Pointer to TF handle
51  *
52  * [out] max_types
53  *   Pointer to the MAX number of HCAPI types supported
54  *
55  * Returns
56  *   - (0) if successful.
57  *   - (-EINVAL) on failure.
58  */
59 static int
60 tf_dev_p58_get_max_types(struct tf *tfp,
61                          uint16_t *max_types)
62 {
63         if (max_types == NULL || tfp == NULL)
64                 return -EINVAL;
65
66         *max_types = CFA_RESOURCE_TYPE_P58_LAST + 1;
67
68         return 0;
69 }
70 /**
71  * Device specific function that retrieves a human readable
72  * string to identify a CFA resource type.
73  *
74  * [in] tfp
75  *   Pointer to TF handle
76  *
77  * [in] resource_id
78  *   HCAPI CFA resource id
79  *
80  * [out] resource_str
81  *   Resource string
82  *
83  * Returns
84  *   - (0) if successful.
85  *   - (-EINVAL) on failure.
86  */
87 static int
88 tf_dev_p58_get_resource_str(struct tf *tfp __rte_unused,
89                             uint16_t resource_id,
90                             const char **resource_str)
91 {
92         if (resource_str == NULL)
93                 return -EINVAL;
94
95         if (resource_id > CFA_RESOURCE_TYPE_P58_LAST)
96                 return -EINVAL;
97
98         *resource_str = tf_resource_str_p58[resource_id];
99
100         return 0;
101 }
102
103 /**
104  * Device specific function that retrieves the WC TCAM slices the
105  * device supports.
106  *
107  * [in] tfp
108  *   Pointer to TF handle
109  *
110  * [out] slice_size
111  *   Pointer to the WC TCAM slice size
112  *
113  * [out] num_slices_per_row
114  *   Pointer to the WC TCAM row slice configuration
115  *
116  * Returns
117  *   - (0) if successful.
118  *   - (-EINVAL) on failure.
119  */
120 static int
121 tf_dev_p58_get_tcam_slice_info(struct tf *tfp __rte_unused,
122                               enum tf_tcam_tbl_type type,
123                               uint16_t key_sz,
124                               uint16_t *num_slices_per_row)
125 {
126 #define CFA_P58_WC_TCAM_SLICES_PER_ROW 1
127 #define CFA_P58_WC_TCAM_SLICE_SIZE     24
128
129         if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
130                 /* only support single slice key size now */
131                 *num_slices_per_row = CFA_P58_WC_TCAM_SLICES_PER_ROW;
132                 if (key_sz > *num_slices_per_row * CFA_P58_WC_TCAM_SLICE_SIZE)
133                         return -ENOTSUP;
134         } else { /* for other type of tcam */
135                 *num_slices_per_row = 1;
136         }
137
138         return 0;
139 }
140
141 static int tf_dev_p58_get_mailbox(void)
142 {
143         return TF_CHIMP_MB;
144 }
145
146 static int tf_dev_p58_word_align(uint16_t size)
147 {
148         return ((((size) + 63) >> 6) * 8);
149 }
150
151
152 #define TF_DEV_P58_BANK_SZ_64B 2048
153 /**
154  * Get SRAM table information.
155  *
156  * Converts an internal RM allocated element offset to
157  * a user address and vice versa.
158  *
159  * [in] tfp
160  *   Pointer to TF handle
161  *
162  * [in] type
163  *   Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
164  *
165  * [in/out] base
166  *   Pointer to the Base address of the associated SRAM bank used for
167  *   the type of record allocated.
168  *
169  * [in/out] shift
170  *   Pointer to the factor to be used as a multiplier to translate
171  *   between the RM units to the user address.  SRAM manages 64B entries
172  *   Addresses must be shifted to an 8B address.
173  *
174  * Returns
175  *   - (0) if successful.
176  *   - (-EINVAL) on failure.
177  */
178 static int tf_dev_p58_get_sram_tbl_info(struct tf *tfp __rte_unused,
179                                         void *db,
180                                         enum tf_tbl_type type,
181                                         uint16_t *base,
182                                         uint16_t *shift)
183 {
184         uint16_t hcapi_type;
185         struct tf_rm_get_hcapi_parms parms;
186         int rc;
187
188         parms.rm_db = db;
189         parms.subtype = type;
190         parms.hcapi_type = &hcapi_type;
191
192         rc = tf_rm_get_hcapi_type(&parms);
193         if (rc)
194                 return rc;
195
196         switch (hcapi_type) {
197         case CFA_RESOURCE_TYPE_P58_SRAM_BANK_0:
198                 *base = 0;
199                 *shift = 3;
200                 break;
201         case CFA_RESOURCE_TYPE_P58_SRAM_BANK_1:
202                 *base = TF_DEV_P58_BANK_SZ_64B;
203                 *shift = 3;
204                 break;
205         case CFA_RESOURCE_TYPE_P58_SRAM_BANK_2:
206                 *base = TF_DEV_P58_BANK_SZ_64B * 2;
207                 *shift = 3;
208                 break;
209         case CFA_RESOURCE_TYPE_P58_SRAM_BANK_3:
210                 *base = TF_DEV_P58_BANK_SZ_64B * 3;
211                 *shift = 3;
212                 break;
213         default:
214                 *base = 0;
215                 *shift = 0;
216                 break;
217         }
218         return 0;
219 }
220 /**
221  * Truflow P58 device specific functions
222  */
223 const struct tf_dev_ops tf_dev_ops_p58_init = {
224         .tf_dev_get_max_types = tf_dev_p58_get_max_types,
225         .tf_dev_get_resource_str = tf_dev_p58_get_resource_str,
226         .tf_dev_get_tcam_slice_info = tf_dev_p58_get_tcam_slice_info,
227         .tf_dev_alloc_ident = NULL,
228         .tf_dev_free_ident = NULL,
229         .tf_dev_search_ident = NULL,
230         .tf_dev_get_tbl_info = NULL,
231         .tf_dev_alloc_ext_tbl = NULL,
232         .tf_dev_alloc_tbl = NULL,
233         .tf_dev_free_ext_tbl = NULL,
234         .tf_dev_free_tbl = NULL,
235         .tf_dev_alloc_search_tbl = NULL,
236         .tf_dev_set_tbl = NULL,
237         .tf_dev_set_ext_tbl = NULL,
238         .tf_dev_get_tbl = NULL,
239         .tf_dev_get_bulk_tbl = NULL,
240         .tf_dev_alloc_tcam = NULL,
241         .tf_dev_free_tcam = NULL,
242         .tf_dev_alloc_search_tcam = NULL,
243         .tf_dev_set_tcam = NULL,
244         .tf_dev_get_tcam = NULL,
245         .tf_dev_insert_int_em_entry = NULL,
246         .tf_dev_delete_int_em_entry = NULL,
247         .tf_dev_insert_ext_em_entry = NULL,
248         .tf_dev_delete_ext_em_entry = NULL,
249         .tf_dev_alloc_tbl_scope = NULL,
250         .tf_dev_map_tbl_scope = NULL,
251         .tf_dev_map_parif = NULL,
252         .tf_dev_free_tbl_scope = NULL,
253         .tf_dev_set_if_tbl = NULL,
254         .tf_dev_get_if_tbl = NULL,
255         .tf_dev_set_global_cfg = NULL,
256         .tf_dev_get_global_cfg = NULL,
257         .tf_dev_get_mailbox = tf_dev_p58_get_mailbox,
258         .tf_dev_word_align = NULL,
259 };
260
261 /**
262  * Truflow P58 device specific functions
263  */
264 const struct tf_dev_ops tf_dev_ops_p58 = {
265         .tf_dev_get_max_types = tf_dev_p58_get_max_types,
266         .tf_dev_get_resource_str = tf_dev_p58_get_resource_str,
267         .tf_dev_get_tcam_slice_info = tf_dev_p58_get_tcam_slice_info,
268         .tf_dev_alloc_ident = tf_ident_alloc,
269         .tf_dev_free_ident = tf_ident_free,
270         .tf_dev_search_ident = tf_ident_search,
271         .tf_dev_get_tbl_info = tf_dev_p58_get_sram_tbl_info,
272         .tf_dev_alloc_tbl = tf_tbl_alloc,
273         .tf_dev_alloc_ext_tbl = tf_tbl_ext_alloc,
274         .tf_dev_free_tbl = tf_tbl_free,
275         .tf_dev_free_ext_tbl = tf_tbl_ext_free,
276         .tf_dev_alloc_search_tbl = tf_tbl_alloc_search,
277         .tf_dev_set_tbl = tf_tbl_set,
278         .tf_dev_set_ext_tbl = tf_tbl_ext_common_set,
279         .tf_dev_get_tbl = tf_tbl_get,
280         .tf_dev_get_bulk_tbl = tf_tbl_bulk_get,
281         .tf_dev_alloc_tcam = tf_tcam_alloc,
282         .tf_dev_free_tcam = tf_tcam_free,
283         .tf_dev_alloc_search_tcam = tf_tcam_alloc_search,
284         .tf_dev_set_tcam = tf_tcam_set,
285         .tf_dev_get_tcam = tf_tcam_get,
286         .tf_dev_insert_int_em_entry = tf_em_hash_insert_int_entry,
287         .tf_dev_delete_int_em_entry = tf_em_hash_delete_int_entry,
288         .tf_dev_insert_ext_em_entry = NULL,
289         .tf_dev_delete_ext_em_entry = NULL,
290         .tf_dev_alloc_tbl_scope = NULL,
291         .tf_dev_map_tbl_scope = NULL,
292         .tf_dev_map_parif = NULL,
293         .tf_dev_free_tbl_scope = NULL,
294         .tf_dev_set_if_tbl = tf_if_tbl_set,
295         .tf_dev_get_if_tbl = tf_if_tbl_get,
296         .tf_dev_set_global_cfg = tf_global_cfg_set,
297         .tf_dev_get_global_cfg = tf_global_cfg_get,
298         .tf_dev_get_mailbox = tf_dev_p58_get_mailbox,
299         .tf_dev_word_align = tf_dev_p58_word_align,
300         .tf_dev_cfa_key_hash = hcapi_cfa_p58_key_hash
301 };