net/bnxt: cleanup ULP parser and mapper
[dpdk.git] / drivers / net / bnxt / tf_core / tf_em.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 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 #include "tf_em_common.h"
13
14 #include "hcapi_cfa_defs.h"
15
16 /**
17  * TF_EM_ALLOC
18  *
19  * 0: Use stack allocator with fixed sized entries
20  *    (default).
21  * 1: Use dpool allocator with variable size
22  *    entries.
23  */
24 #define TF_EM_ALLOC 0
25
26 #define TF_EM_MIN_ENTRIES     (1 << 15) /* 32K */
27 #define TF_EM_MAX_ENTRIES     (1 << 27) /* 128M */
28
29 #define TF_P4_HW_EM_KEY_MAX_SIZE 52
30 #define TF_P4_EM_KEY_RECORD_SIZE 64
31
32 #define TF_P58_HW_EM_KEY_MAX_SIZE 80
33
34 #define TF_EM_MAX_MASK 0x7FFF
35 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
36
37 /**
38  * Hardware Page sizes supported for EEM:
39  *   4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
40  *
41  * Round-down other page sizes to the lower hardware page
42  * size supported.
43  */
44 #define TF_EM_PAGE_SIZE_4K 12
45 #define TF_EM_PAGE_SIZE_8K 13
46 #define TF_EM_PAGE_SIZE_64K 16
47 #define TF_EM_PAGE_SIZE_256K 18
48 #define TF_EM_PAGE_SIZE_1M 20
49 #define TF_EM_PAGE_SIZE_2M 21
50 #define TF_EM_PAGE_SIZE_4M 22
51 #define TF_EM_PAGE_SIZE_1G 30
52
53 /* Set page size */
54 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
55
56 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K)   /** 4K */
57 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
58 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
59 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
60 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
61 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
62 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K)        /** 64K */
63 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
64 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
65 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K)       /** 256K */
66 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
67 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
68 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
69 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
70 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
71 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
72 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
73 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
74 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
75 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
76 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
77 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
78 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
79 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
80 #else
81 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
82 #endif
83
84 /*
85  * System memory always uses 4K pages
86  */
87 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
88 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
89
90 /*
91  * Used to build GFID:
92  *
93  *   15           2  0
94  *  +--------------+--+
95  *  |   Index      |E |
96  *  +--------------+--+
97  *
98  * E = Entry (bucket index)
99  */
100 #define TF_EM_INTERNAL_INDEX_SHIFT 2
101 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
102 #define TF_EM_INTERNAL_ENTRY_MASK  0x3
103
104 /** EM Entry
105  *  Each EM entry is 512-bit (64-bytes) but ordered differently to
106  *  EEM.
107  */
108 struct tf_em_64b_entry {
109         /** Header is 8 bytes long */
110         struct cfa_p4_eem_entry_hdr hdr;
111         /** Key is 448 bits - 56 bytes */
112         uint8_t key[TF_P4_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
113 };
114
115 /** EEM Memory Type
116  *
117  */
118 enum tf_mem_type {
119         TF_EEM_MEM_TYPE_INVALID,
120         TF_EEM_MEM_TYPE_HOST,
121         TF_EEM_MEM_TYPE_SYSTEM
122 };
123
124 /**
125  * tf_em_cfg_parms definition
126  */
127 struct tf_em_cfg_parms {
128         /**
129          * [in] Num entries in resource config
130          */
131         uint16_t num_elements;
132         /**
133          * [in] Resource config
134          */
135         struct tf_rm_element_cfg *cfg;
136         /**
137          * Session resource allocations
138          */
139         struct tf_session_resources *resources;
140         /**
141          * [in] Memory type.
142          */
143         enum tf_mem_type mem_type;
144 };
145
146 /**
147  * EM database
148  *
149  * EM rm database
150  *
151  */
152 struct em_rm_db {
153         struct rm_db *em_db[TF_DIR_MAX];
154 };
155
156 /**
157  * @page em EM
158  *
159  * @ref tf_alloc_eem_tbl_scope
160  *
161  * @ref tf_free_eem_tbl_scope_cb
162  *
163  * @ref tf_em_insert_int_entry
164  *
165  * @ref tf_em_delete_int_entry
166  *
167  * @ref tf_em_insert_ext_entry
168  *
169  * @ref tf_em_delete_ext_entry
170  *
171  * @ref tf_em_insert_ext_sys_entry
172  *
173  * @ref tf_em_delete_ext_sys_entry
174  *
175  * @ref tf_em_int_bind
176  *
177  * @ref tf_em_int_unbind
178  *
179  * @ref tf_em_ext_common_bind
180  *
181  * @ref tf_em_ext_common_unbind
182  *
183  * @ref tf_em_ext_alloc
184  *
185  * @ref tf_em_ext_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 internal EM 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_hash_insert_int_entry(struct tf *tfp,
238                                 struct tf_insert_em_entry_parms *parms);
239
240 /**
241  * Delete record from internal EM 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_hash_delete_int_entry(struct tf *tfp,
254                                 struct tf_delete_em_entry_parms *parms);
255
256 /**
257  * Move record from internal EM 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_move_int_entry(struct tf *tfp,
270                          struct tf_move_em_entry_parms *parms);
271
272 /**
273  * Insert record in to external 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_insert_ext_entry(struct tf *tfp,
286                            struct tf_insert_em_entry_parms *parms);
287
288 /**
289  * Insert record from external EEM table
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_delete_ext_entry(struct tf *tfp,
302                            struct tf_delete_em_entry_parms *parms);
303
304 /**
305  * Insert record in to external system EEM table
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_insert_ext_sys_entry(struct tf *tfp,
318                                struct tf_insert_em_entry_parms *parms);
319
320 /**
321  * Delete record from external system EEM table
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_delete_ext_sys_entry(struct tf *tfp,
334                                struct tf_delete_em_entry_parms *parms);
335
336 /**
337  * Bind internal EM device interface
338  *
339  * [in] tfp
340  *   Pointer to TruFlow handle
341  *
342  * [in] parms
343  *   Pointer to input parameters
344  *
345  * Returns:
346  *   0       - Success
347  *   -EINVAL - Parameter error
348  */
349 int tf_em_int_bind(struct tf *tfp,
350                    struct tf_em_cfg_parms *parms);
351
352 /**
353  * Unbind internal EM device interface
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_int_unbind(struct tf *tfp);
366
367 /**
368  * Common bind for EEM device interface. Used for both host and
369  * system 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_common_bind(struct tf *tfp,
382                           struct tf_em_cfg_parms *parms);
383
384 /**
385  * Common unbind for EEM device interface. Used for both host and
386  * system memory
387  *
388  * [in] tfp
389  *   Pointer to TruFlow handle
390  *
391  * [in] parms
392  *   Pointer to input parameters
393  *
394  * Returns:
395  *   0       - Success
396  *   -EINVAL - Parameter error
397  */
398 int tf_em_ext_common_unbind(struct tf *tfp);
399
400 /**
401  * Alloc for external EEM using host 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_alloc(struct tf *tfp,
414                     struct tf_alloc_tbl_scope_parms *parms);
415
416 /**
417  * Free for external EEM using host memory
418  *
419  * [in] tfp
420  *   Pointer to TruFlow handle
421  *
422  * [in] parms
423  *   Pointer to input parameters
424  *
425  * Returns:
426  *   0       - Success
427  *   -EINVAL - Parameter error
428  */
429 int tf_em_ext_free(struct tf *tfp,
430                    struct tf_free_tbl_scope_parms *parms);
431
432 /**
433  * Common free table scope for external EEM using host or system memory
434  *
435  * [in] tfp
436  *   Pointer to TruFlow handle
437  *
438  * [in] parms
439  *   Pointer to input parameters
440  *
441  * Returns:
442  *   0       - Success
443  *   -EINVAL - Parameter error
444  */
445 int tf_em_ext_common_free(struct tf *tfp,
446                           struct tf_free_tbl_scope_parms *parms);
447
448 /**
449  * Common alloc table scope for external EEM using host or system memory
450  *
451  * [in] tfp
452  *   Pointer to TruFlow handle
453  *
454  * [in] parms
455  *   Pointer to input parameters
456  *
457  * Returns:
458  *   0       - Success
459  *   -EINVAL - Parameter error
460  */
461 int tf_em_ext_common_alloc(struct tf *tfp,
462                            struct tf_alloc_tbl_scope_parms *parms);
463 /**
464  * Map a set of parifs to a set of EEM base addresses (table scope)
465  *
466  * [in] tfp
467  *   Pointer to TruFlow handle
468  *
469  * [in] parms
470  *   Pointer to input parameters
471  *
472  * Returns:
473  *   0       - Success
474  *   -EINVAL - Parameter error
475  */
476 int tf_em_ext_map_tbl_scope(struct tf *tfp,
477                             struct tf_map_tbl_scope_parms *parms);
478
479 /**
480  * Allocate External Tbl entry from the scope pool.
481  *
482  * [in] tfp
483  *   Pointer to Truflow Handle
484  * [in] parms
485  *   Allocation parameters
486  *
487  * Return:
488  *  0       - Success, entry allocated - no search support
489  *  -ENOMEM -EINVAL -EOPNOTSUPP
490  *          - Failure, entry not allocated, out of resources
491  */
492 int
493 tf_tbl_ext_alloc(struct tf *tfp,
494                  struct tf_tbl_alloc_parms *parms);
495
496 /**
497  * Free External Tbl entry to the scope pool.
498  *
499  * [in] tfp
500  *   Pointer to Truflow Handle
501  * [in] parms
502  *   Allocation parameters
503  *
504  * Return:
505  *  0       - Success, entry freed
506  *
507  * - Failure, entry not successfully freed for these reasons
508  *  -ENOMEM
509  *  -EOPNOTSUPP
510  *  -EINVAL
511  */
512 int
513 tf_tbl_ext_free(struct tf *tfp,
514                 struct tf_tbl_free_parms *parms);
515
516 /**
517  * Sets the specified external table type element.
518  *
519  * This API sets the specified element data by invoking the
520  * firmware.
521  *
522  * [in] tfp
523  *   Pointer to TF handle
524  *
525  * [in] parms
526  *   Pointer to table set parameters
527  *
528  * Returns
529  *   - (0) if successful.
530  *   - (-EINVAL) on failure.
531  */
532 int tf_tbl_ext_common_set(struct tf *tfp,
533                           struct tf_tbl_set_parms *parms);
534
535 /**
536  * Sets the specified external table type element.
537  *
538  * This API sets the specified element data by invoking the
539  * firmware.
540  *
541  * [in] tfp
542  *   Pointer to TF handle
543  *
544  * [in] parms
545  *   Pointer to table set parameters
546  *
547  * Returns
548  *   - (0) if successful.
549  *   - (-EINVAL) on failure.
550  */
551 int tf_tbl_ext_set(struct tf *tfp,
552                    struct tf_tbl_set_parms *parms);
553
554 int
555 tf_em_ext_system_bind(struct tf *tfp,
556                       struct tf_em_cfg_parms *parms);
557
558 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
559
560 /**
561  * Retrieves the allocated resource info
562  *
563  * [in] tfp
564  *   Pointer to TF handle, used for HCAPI communication
565  *
566  * [in] parms
567  *   Pointer to parameters
568  *
569  * Returns
570  *   - (0) if successful.
571  *   - (-EINVAL) on failure.
572  */
573 int
574 tf_em_get_resc_info(struct tf *tfp,
575                     struct tf_em_resource_info *em);
576 #endif /* _TF_EM_H_ */