net/bnxt: remove VLAN pop action for egress flows
[dpdk.git] / drivers / net / bnxt / tf_core / tf_em.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_EM_H_
7 #define _TF_EM_H_
8
9 #include "tf_core.h"
10 #include "tf_session.h"
11
12
13 #define SUPPORT_CFA_HW_P4 1
14 #define SUPPORT_CFA_HW_P58 0
15 #define SUPPORT_CFA_HW_P59 0
16 #define SUPPORT_CFA_HW_ALL 0
17
18 #include "hcapi/hcapi_cfa_defs.h"
19
20 #define TF_EM_MIN_ENTRIES     (1 << 15) /* 32K */
21 #define TF_EM_MAX_ENTRIES     (1 << 27) /* 128M */
22
23 #define TF_HW_EM_KEY_MAX_SIZE 52
24 #define TF_EM_KEY_RECORD_SIZE 64
25
26 #define TF_EM_MAX_MASK 0x7FFF
27 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
28
29 /**
30  * Hardware Page sizes supported for EEM:
31  *   4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
32  *
33  * Round-down other page sizes to the lower hardware page
34  * size supported.
35  */
36 #define TF_EM_PAGE_SIZE_4K 12
37 #define TF_EM_PAGE_SIZE_8K 13
38 #define TF_EM_PAGE_SIZE_64K 16
39 #define TF_EM_PAGE_SIZE_256K 18
40 #define TF_EM_PAGE_SIZE_1M 20
41 #define TF_EM_PAGE_SIZE_2M 21
42 #define TF_EM_PAGE_SIZE_4M 22
43 #define TF_EM_PAGE_SIZE_1G 30
44
45 /* Set page size */
46 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
47
48 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K)   /** 4K */
49 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
50 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
51 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
52 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
53 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
54 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K)        /** 64K */
55 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
56 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
57 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K)       /** 256K */
58 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
59 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
60 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
61 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
62 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
63 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
64 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
65 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
66 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
67 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
68 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
69 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
70 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
71 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
72 #else
73 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
74 #endif
75
76 /*
77  * System memory always uses 4K pages
78  */
79 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
80 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
81
82 /*
83  * Used to build GFID:
84  *
85  *   15           2  0
86  *  +--------------+--+
87  *  |   Index      |E |
88  *  +--------------+--+
89  *
90  * E = Entry (bucket inndex)
91  */
92 #define TF_EM_INTERNAL_INDEX_SHIFT 2
93 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
94 #define TF_EM_INTERNAL_ENTRY_MASK  0x3
95
96 /** EM Entry
97  *  Each EM entry is 512-bit (64-bytes) but ordered differently to
98  *  EEM.
99  */
100 struct tf_em_64b_entry {
101         /** Header is 8 bytes long */
102         struct cfa_p4_eem_entry_hdr hdr;
103         /** Key is 448 bits - 56 bytes */
104         uint8_t key[TF_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
105 };
106
107 /** EEM Memory Type
108  *
109  */
110 enum tf_mem_type {
111         TF_EEM_MEM_TYPE_INVALID,
112         TF_EEM_MEM_TYPE_HOST,
113         TF_EEM_MEM_TYPE_SYSTEM
114 };
115
116 /**
117  * tf_em_cfg_parms definition
118  */
119 struct tf_em_cfg_parms {
120         /**
121          * [in] Num entries in resource config
122          */
123         uint16_t num_elements;
124         /**
125          * [in] Resource config
126          */
127         struct tf_rm_element_cfg *cfg;
128         /**
129          * Session resource allocations
130          */
131         struct tf_session_resources *resources;
132         /**
133          * [in] Memory type.
134          */
135         enum tf_mem_type mem_type;
136 };
137
138 /**
139  * @page em EM
140  *
141  * @ref tf_alloc_eem_tbl_scope
142  *
143  * @ref tf_free_eem_tbl_scope_cb
144  *
145  * @ref tf_em_insert_int_entry
146  *
147  * @ref tf_em_delete_int_entry
148  *
149  * @ref tf_em_insert_ext_entry
150  *
151  * @ref tf_em_delete_ext_entry
152  *
153  * @ref tf_em_insert_ext_sys_entry
154  *
155  * @ref tf_em_delete_ext_sys_entry
156  *
157  * @ref tf_em_int_bind
158  *
159  * @ref tf_em_int_unbind
160  *
161  * @ref tf_em_ext_common_bind
162  *
163  * @ref tf_em_ext_common_unbind
164  *
165  * @ref tf_em_ext_alloc
166  *
167  * @ref tf_em_ext_free
168  *
169  * @ref tf_em_ext_common_free
170  *
171  * @ref tf_em_ext_common_alloc
172  */
173
174 /**
175  * Insert record in to internal EM table
176  *
177  * [in] tfp
178  *   Pointer to TruFlow handle
179  *
180  * [in] parms
181  *   Pointer to input parameters
182  *
183  * Returns:
184  *   0       - Success
185  *   -EINVAL - Parameter error
186  */
187 int tf_em_insert_int_entry(struct tf *tfp,
188                            struct tf_insert_em_entry_parms *parms);
189
190 /**
191  * Delete record from internal EM table
192  *
193  * [in] tfp
194  *   Pointer to TruFlow handle
195  *
196  * [in] parms
197  *   Pointer to input parameters
198  *
199  * Returns:
200  *   0       - Success
201  *   -EINVAL - Parameter error
202  */
203 int tf_em_delete_int_entry(struct tf *tfp,
204                            struct tf_delete_em_entry_parms *parms);
205
206 /**
207  * Insert record in to external EEM table
208  *
209  * [in] tfp
210  *   Pointer to TruFlow handle
211  *
212  * [in] parms
213  *   Pointer to input parameters
214  *
215  * Returns:
216  *   0       - Success
217  *   -EINVAL - Parameter error
218  */
219 int tf_em_insert_ext_entry(struct tf *tfp,
220                            struct tf_insert_em_entry_parms *parms);
221
222 /**
223  * Insert record from external EEM table
224  *
225  * [in] tfp
226  *   Pointer to TruFlow handle
227  *
228  * [in] parms
229  *   Pointer to input parameters
230  *
231  * Returns:
232  *   0       - Success
233  *   -EINVAL - Parameter error
234  */
235 int tf_em_delete_ext_entry(struct tf *tfp,
236                            struct tf_delete_em_entry_parms *parms);
237
238 /**
239  * Insert record in to external system EEM table
240  *
241  * [in] tfp
242  *   Pointer to TruFlow handle
243  *
244  * [in] parms
245  *   Pointer to input parameters
246  *
247  * Returns:
248  *   0       - Success
249  *   -EINVAL - Parameter error
250  */
251 int tf_em_insert_ext_sys_entry(struct tf *tfp,
252                                struct tf_insert_em_entry_parms *parms);
253
254 /**
255  * Delete record from external system EEM table
256  *
257  * [in] tfp
258  *   Pointer to TruFlow handle
259  *
260  * [in] parms
261  *   Pointer to input parameters
262  *
263  * Returns:
264  *   0       - Success
265  *   -EINVAL - Parameter error
266  */
267 int tf_em_delete_ext_sys_entry(struct tf *tfp,
268                                struct tf_delete_em_entry_parms *parms);
269
270 /**
271  * Bind internal EM device interface
272  *
273  * [in] tfp
274  *   Pointer to TruFlow handle
275  *
276  * [in] parms
277  *   Pointer to input parameters
278  *
279  * Returns:
280  *   0       - Success
281  *   -EINVAL - Parameter error
282  */
283 int tf_em_int_bind(struct tf *tfp,
284                    struct tf_em_cfg_parms *parms);
285
286 /**
287  * Unbind internal EM device interface
288  *
289  * [in] tfp
290  *   Pointer to TruFlow handle
291  *
292  * [in] parms
293  *   Pointer to input parameters
294  *
295  * Returns:
296  *   0       - Success
297  *   -EINVAL - Parameter error
298  */
299 int tf_em_int_unbind(struct tf *tfp);
300
301 /**
302  * Common bind for EEM device interface. Used for both host and
303  * system memory
304  *
305  * [in] tfp
306  *   Pointer to TruFlow handle
307  *
308  * [in] parms
309  *   Pointer to input parameters
310  *
311  * Returns:
312  *   0       - Success
313  *   -EINVAL - Parameter error
314  */
315 int tf_em_ext_common_bind(struct tf *tfp,
316                           struct tf_em_cfg_parms *parms);
317
318 /**
319  * Common unbind for EEM device interface. Used for both host and
320  * system memory
321  *
322  * [in] tfp
323  *   Pointer to TruFlow handle
324  *
325  * [in] parms
326  *   Pointer to input parameters
327  *
328  * Returns:
329  *   0       - Success
330  *   -EINVAL - Parameter error
331  */
332 int tf_em_ext_common_unbind(struct tf *tfp);
333
334 /**
335  * Alloc for external EEM using host memory
336  *
337  * [in] tfp
338  *   Pointer to TruFlow handle
339  *
340  * [in] parms
341  *   Pointer to input parameters
342  *
343  * Returns:
344  *   0       - Success
345  *   -EINVAL - Parameter error
346  */
347 int tf_em_ext_alloc(struct tf *tfp,
348                     struct tf_alloc_tbl_scope_parms *parms);
349
350 /**
351  * Free for external EEM using host memory
352  *
353  * [in] tfp
354  *   Pointer to TruFlow handle
355  *
356  * [in] parms
357  *   Pointer to input parameters
358  *
359  * Returns:
360  *   0       - Success
361  *   -EINVAL - Parameter error
362  */
363 int tf_em_ext_free(struct tf *tfp,
364                    struct tf_free_tbl_scope_parms *parms);
365
366 /**
367  * Common free for external EEM using host or system memory
368  *
369  * [in] tfp
370  *   Pointer to TruFlow handle
371  *
372  * [in] parms
373  *   Pointer to input parameters
374  *
375  * Returns:
376  *   0       - Success
377  *   -EINVAL - Parameter error
378  */
379 int tf_em_ext_common_free(struct tf *tfp,
380                           struct tf_free_tbl_scope_parms *parms);
381
382 /**
383  * Common alloc for external EEM using host or system memory
384  *
385  * [in] tfp
386  *   Pointer to TruFlow handle
387  *
388  * [in] parms
389  *   Pointer to input parameters
390  *
391  * Returns:
392  *   0       - Success
393  *   -EINVAL - Parameter error
394  */
395 int tf_em_ext_common_alloc(struct tf *tfp,
396                            struct tf_alloc_tbl_scope_parms *parms);
397
398 /**
399  * Allocate External Tbl entry from the scope pool.
400  *
401  * [in] tfp
402  *   Pointer to Truflow Handle
403  * [in] parms
404  *   Allocation parameters
405  *
406  * Return:
407  *  0       - Success, entry allocated - no search support
408  *  -ENOMEM -EINVAL -EOPNOTSUPP
409  *          - Failure, entry not allocated, out of resources
410  */
411 int
412 tf_tbl_ext_alloc(struct tf *tfp,
413                  struct tf_tbl_alloc_parms *parms);
414
415 /**
416  * Free External Tbl entry to the scope pool.
417  *
418  * [in] tfp
419  *   Pointer to Truflow Handle
420  * [in] parms
421  *   Allocation parameters
422  *
423  * Return:
424  *  0       - Success, entry freed
425  *
426  * - Failure, entry not successfully freed for these reasons
427  *  -ENOMEM
428  *  -EOPNOTSUPP
429  *  -EINVAL
430  */
431 int
432 tf_tbl_ext_free(struct tf *tfp,
433                 struct tf_tbl_free_parms *parms);
434
435 /**
436  * Sets the specified external table type element.
437  *
438  * This API sets the specified element data by invoking the
439  * firmware.
440  *
441  * [in] tfp
442  *   Pointer to TF handle
443  *
444  * [in] parms
445  *   Pointer to table set parameters
446  *
447  * Returns
448  *   - (0) if successful.
449  *   - (-EINVAL) on failure.
450  */
451 int tf_tbl_ext_common_set(struct tf *tfp,
452                           struct tf_tbl_set_parms *parms);
453
454 /**
455  * Sets the specified external table type element.
456  *
457  * This API sets the specified element data by invoking the
458  * firmware.
459  *
460  * [in] tfp
461  *   Pointer to TF handle
462  *
463  * [in] parms
464  *   Pointer to table set parameters
465  *
466  * Returns
467  *   - (0) if successful.
468  *   - (-EINVAL) on failure.
469  */
470 int tf_tbl_ext_set(struct tf *tfp,
471                    struct tf_tbl_set_parms *parms);
472
473 int
474 tf_em_ext_system_bind(struct tf *tfp,
475                       struct tf_em_cfg_parms *parms);
476
477 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
478 #endif /* _TF_EM_H_ */