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