1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
10 #include "tf_session.h"
12 #define SUPPORT_CFA_HW_P4 1
13 #define SUPPORT_CFA_HW_P58 0
14 #define SUPPORT_CFA_HW_P59 0
15 #define SUPPORT_CFA_HW_ALL 0
17 #include "hcapi/hcapi_cfa_defs.h"
19 #define TF_HW_EM_KEY_MAX_SIZE 52
20 #define TF_EM_KEY_RECORD_SIZE 64
22 #define TF_EM_MAX_MASK 0x7FFF
23 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
26 * Hardware Page sizes supported for EEM:
27 * 4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
29 * Round-down other page sizes to the lower hardware page
32 #define TF_EM_PAGE_SIZE_4K 12
33 #define TF_EM_PAGE_SIZE_8K 13
34 #define TF_EM_PAGE_SIZE_64K 16
35 #define TF_EM_PAGE_SIZE_256K 18
36 #define TF_EM_PAGE_SIZE_1M 20
37 #define TF_EM_PAGE_SIZE_2M 21
38 #define TF_EM_PAGE_SIZE_4M 22
39 #define TF_EM_PAGE_SIZE_1G 30
42 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
44 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K) /** 4K */
45 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
46 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
47 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
48 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
49 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
50 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K) /** 64K */
51 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
52 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
53 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K) /** 256K */
54 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
55 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
56 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
57 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
58 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
59 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
60 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
61 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
62 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
63 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
64 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
65 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
66 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
67 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
69 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
72 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
73 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
83 * E = Entry (bucket inndex)
85 #define TF_EM_INTERNAL_INDEX_SHIFT 2
86 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
87 #define TF_EM_INTERNAL_ENTRY_MASK 0x3
90 * Each EM entry is 512-bit (64-bytes) but ordered differently to
93 struct tf_em_64b_entry {
94 /** Header is 8 bytes long */
95 struct cfa_p4_eem_entry_hdr hdr;
96 /** Key is 448 bits - 56 bytes */
97 uint8_t key[TF_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
104 TF_EEM_MEM_TYPE_INVALID,
105 TF_EEM_MEM_TYPE_HOST,
106 TF_EEM_MEM_TYPE_SYSTEM
110 * tf_em_cfg_parms definition
112 struct tf_em_cfg_parms {
114 * [in] Num entries in resource config
116 uint16_t num_elements;
118 * [in] Resource config
120 struct tf_rm_element_cfg *cfg;
122 * Session resource allocations
124 struct tf_session_resources *resources;
128 enum tf_mem_type mem_type;
134 * @ref tf_alloc_eem_tbl_scope
136 * @ref tf_free_eem_tbl_scope_cb
138 * @ref tf_em_insert_int_entry
140 * @ref tf_em_delete_int_entry
142 * @ref tf_em_insert_ext_entry
144 * @ref tf_em_delete_ext_entry
146 * @ref tf_em_insert_ext_sys_entry
148 * @ref tf_em_delete_ext_sys_entry
150 * @ref tf_em_int_bind
152 * @ref tf_em_int_unbind
154 * @ref tf_em_ext_common_bind
156 * @ref tf_em_ext_common_unbind
158 * @ref tf_em_ext_host_alloc
160 * @ref tf_em_ext_host_free
162 * @ref tf_em_ext_system_alloc
164 * @ref tf_em_ext_system_free
166 * @ref tf_em_ext_common_free
168 * @ref tf_em_ext_common_alloc
172 * Allocates EEM Table scope
175 * Pointer to TruFlow handle
178 * Pointer to input parameters
182 * -EINVAL - Parameter error
183 * -ENOMEM - Out of memory
185 int tf_alloc_eem_tbl_scope(struct tf *tfp,
186 struct tf_alloc_tbl_scope_parms *parms);
189 * Free's EEM Table scope control block
192 * Pointer to TruFlow handle
195 * Pointer to input parameters
199 * -EINVAL - Parameter error
201 int tf_free_eem_tbl_scope_cb(struct tf *tfp,
202 struct tf_free_tbl_scope_parms *parms);
205 * Insert record in to internal EM table
208 * Pointer to TruFlow handle
211 * Pointer to input parameters
215 * -EINVAL - Parameter error
217 int tf_em_insert_int_entry(struct tf *tfp,
218 struct tf_insert_em_entry_parms *parms);
221 * Delete record from internal EM table
224 * Pointer to TruFlow handle
227 * Pointer to input parameters
231 * -EINVAL - Parameter error
233 int tf_em_delete_int_entry(struct tf *tfp,
234 struct tf_delete_em_entry_parms *parms);
237 * Insert record in to external EEM table
240 * Pointer to TruFlow handle
243 * Pointer to input parameters
247 * -EINVAL - Parameter error
249 int tf_em_insert_ext_entry(struct tf *tfp,
250 struct tf_insert_em_entry_parms *parms);
253 * Insert record from external EEM table
256 * Pointer to TruFlow handle
259 * Pointer to input parameters
263 * -EINVAL - Parameter error
265 int tf_em_delete_ext_entry(struct tf *tfp,
266 struct tf_delete_em_entry_parms *parms);
269 * Insert record in to external system EEM table
272 * Pointer to TruFlow handle
275 * Pointer to input parameters
279 * -EINVAL - Parameter error
281 int tf_em_insert_ext_sys_entry(struct tf *tfp,
282 struct tf_insert_em_entry_parms *parms);
285 * Delete record from external system EEM table
288 * Pointer to TruFlow handle
291 * Pointer to input parameters
295 * -EINVAL - Parameter error
297 int tf_em_delete_ext_sys_entry(struct tf *tfp,
298 struct tf_delete_em_entry_parms *parms);
301 * Bind internal EM device interface
304 * Pointer to TruFlow handle
307 * Pointer to input parameters
311 * -EINVAL - Parameter error
313 int tf_em_int_bind(struct tf *tfp,
314 struct tf_em_cfg_parms *parms);
317 * Unbind internal EM device interface
320 * Pointer to TruFlow handle
323 * Pointer to input parameters
327 * -EINVAL - Parameter error
329 int tf_em_int_unbind(struct tf *tfp);
332 * Common bind for EEM device interface. Used for both host and
336 * Pointer to TruFlow handle
339 * Pointer to input parameters
343 * -EINVAL - Parameter error
345 int tf_em_ext_common_bind(struct tf *tfp,
346 struct tf_em_cfg_parms *parms);
349 * Common unbind for EEM device interface. Used for both host and
353 * Pointer to TruFlow handle
356 * Pointer to input parameters
360 * -EINVAL - Parameter error
362 int tf_em_ext_common_unbind(struct tf *tfp);
365 * Alloc for external EEM using host memory
368 * Pointer to TruFlow handle
371 * Pointer to input parameters
375 * -EINVAL - Parameter error
377 int tf_em_ext_host_alloc(struct tf *tfp,
378 struct tf_alloc_tbl_scope_parms *parms);
381 * Free for external EEM using host memory
384 * Pointer to TruFlow handle
387 * Pointer to input parameters
391 * -EINVAL - Parameter error
393 int tf_em_ext_host_free(struct tf *tfp,
394 struct tf_free_tbl_scope_parms *parms);
397 * Alloc for external EEM using system memory
400 * Pointer to TruFlow handle
403 * Pointer to input parameters
407 * -EINVAL - Parameter error
409 int tf_em_ext_system_alloc(struct tf *tfp,
410 struct tf_alloc_tbl_scope_parms *parms);
413 * Free for external EEM using system memory
416 * Pointer to TruFlow handle
419 * Pointer to input parameters
423 * -EINVAL - Parameter error
425 int tf_em_ext_system_free(struct tf *tfp,
426 struct tf_free_tbl_scope_parms *parms);
429 * Common free for external EEM using host or system memory
432 * Pointer to TruFlow handle
435 * Pointer to input parameters
439 * -EINVAL - Parameter error
441 int tf_em_ext_common_free(struct tf *tfp,
442 struct tf_free_tbl_scope_parms *parms);
445 * Common alloc for external EEM using host or system memory
448 * Pointer to TruFlow handle
451 * Pointer to input parameters
455 * -EINVAL - Parameter error
457 int tf_em_ext_common_alloc(struct tf *tfp,
458 struct tf_alloc_tbl_scope_parms *parms);
461 * Allocate External Tbl entry from the scope pool.
464 * Pointer to Truflow Handle
466 * Allocation parameters
469 * 0 - Success, entry allocated - no search support
470 * -ENOMEM -EINVAL -EOPNOTSUPP
471 * - Failure, entry not allocated, out of resources
474 tf_tbl_ext_alloc(struct tf *tfp,
475 struct tf_tbl_alloc_parms *parms);
478 * Free External Tbl entry to the scope pool.
481 * Pointer to Truflow Handle
483 * Allocation parameters
486 * 0 - Success, entry freed
488 * - Failure, entry not successfully freed for these reasons
494 tf_tbl_ext_free(struct tf *tfp,
495 struct tf_tbl_free_parms *parms);
498 * Sets the specified external table type element.
500 * This API sets the specified element data by invoking the
504 * Pointer to TF handle
507 * Pointer to table set parameters
510 * - (0) if successful.
511 * - (-EINVAL) on failure.
513 int tf_tbl_ext_set(struct tf *tfp,
514 struct tf_tbl_set_parms *parms);
517 * Sets the specified external table type element.
519 * This API sets the specified element data by invoking the
523 * Pointer to TF handle
526 * Pointer to table set parameters
529 * - (0) if successful.
530 * - (-EINVAL) on failure.
532 int tf_tbl_ext_host_set(struct tf *tfp,
533 struct tf_tbl_set_parms *parms);
536 * Sets the specified external table type element.
538 * This API sets the specified element data by invoking the
542 * Pointer to TF handle
545 * Pointer to table set parameters
548 * - (0) if successful.
549 * - (-EINVAL) on failure.
551 int tf_tbl_ext_system_set(struct tf *tfp,
552 struct tf_tbl_set_parms *parms);
554 #endif /* _TF_EM_H_ */