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