1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
10 #include "tf_session.h"
12 #include "tf_em_common.h"
14 #include "hcapi_cfa_defs.h"
19 * 0: Use stack allocator with fixed sized entries
21 * 1: Use dpool allocator with variable size
26 #define TF_EM_MIN_ENTRIES (1 << 15) /* 32K */
27 #define TF_EM_MAX_ENTRIES (1 << 27) /* 128M */
29 #define TF_P4_HW_EM_KEY_MAX_SIZE 52
30 #define TF_P4_EM_KEY_RECORD_SIZE 64
32 #define TF_P58_HW_EM_KEY_MAX_SIZE 80
34 #define TF_EM_MAX_MASK 0x7FFF
35 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
38 * Hardware Page sizes supported for EEM:
39 * 4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
41 * Round-down other page sizes to the lower hardware page
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
54 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
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
81 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
85 * System memory always uses 4K pages
87 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
88 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
98 * E = Entry (bucket inndex)
100 #define TF_EM_INTERNAL_INDEX_SHIFT 2
101 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
102 #define TF_EM_INTERNAL_ENTRY_MASK 0x3
105 * Each EM entry is 512-bit (64-bytes) but ordered differently to
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)];
119 TF_EEM_MEM_TYPE_INVALID,
120 TF_EEM_MEM_TYPE_HOST,
121 TF_EEM_MEM_TYPE_SYSTEM
125 * tf_em_cfg_parms definition
127 struct tf_em_cfg_parms {
129 * [in] Num entries in resource config
131 uint16_t num_elements;
133 * [in] Resource config
135 struct tf_rm_element_cfg *cfg;
137 * Session resource allocations
139 struct tf_session_resources *resources;
143 enum tf_mem_type mem_type;
153 struct rm_db *em_db[TF_DIR_MAX];
159 * @ref tf_alloc_eem_tbl_scope
161 * @ref tf_free_eem_tbl_scope_cb
163 * @ref tf_em_insert_int_entry
165 * @ref tf_em_delete_int_entry
167 * @ref tf_em_insert_ext_entry
169 * @ref tf_em_delete_ext_entry
171 * @ref tf_em_insert_ext_sys_entry
173 * @ref tf_em_delete_ext_sys_entry
175 * @ref tf_em_int_bind
177 * @ref tf_em_int_unbind
179 * @ref tf_em_ext_common_bind
181 * @ref tf_em_ext_common_unbind
183 * @ref tf_em_ext_alloc
185 * @ref tf_em_ext_free
187 * @ref tf_em_ext_common_free
189 * @ref tf_em_ext_common_alloc
193 * Insert record in to internal EM table
196 * Pointer to TruFlow handle
199 * Pointer to input parameters
203 * -EINVAL - Parameter error
205 int tf_em_insert_int_entry(struct tf *tfp,
206 struct tf_insert_em_entry_parms *parms);
209 * Delete record from internal EM table
212 * Pointer to TruFlow handle
215 * Pointer to input parameters
219 * -EINVAL - Parameter error
221 int tf_em_delete_int_entry(struct tf *tfp,
222 struct tf_delete_em_entry_parms *parms);
225 * Insert record in to internal EM table
228 * Pointer to TruFlow handle
231 * Pointer to input parameters
235 * -EINVAL - Parameter error
237 int tf_em_hash_insert_int_entry(struct tf *tfp,
238 struct tf_insert_em_entry_parms *parms);
241 * Delete record from internal EM table
244 * Pointer to TruFlow handle
247 * Pointer to input parameters
251 * -EINVAL - Parameter error
253 int tf_em_hash_delete_int_entry(struct tf *tfp,
254 struct tf_delete_em_entry_parms *parms);
257 * Move record from internal EM table
260 * Pointer to TruFlow handle
263 * Pointer to input parameters
267 * -EINVAL - Parameter error
269 int tf_em_move_int_entry(struct tf *tfp,
270 struct tf_move_em_entry_parms *parms);
273 * Insert record in to external EEM table
276 * Pointer to TruFlow handle
279 * Pointer to input parameters
283 * -EINVAL - Parameter error
285 int tf_em_insert_ext_entry(struct tf *tfp,
286 struct tf_insert_em_entry_parms *parms);
289 * Insert record from external EEM table
292 * Pointer to TruFlow handle
295 * Pointer to input parameters
299 * -EINVAL - Parameter error
301 int tf_em_delete_ext_entry(struct tf *tfp,
302 struct tf_delete_em_entry_parms *parms);
305 * Insert record in to external system EEM table
308 * Pointer to TruFlow handle
311 * Pointer to input parameters
315 * -EINVAL - Parameter error
317 int tf_em_insert_ext_sys_entry(struct tf *tfp,
318 struct tf_insert_em_entry_parms *parms);
321 * Delete record from external system EEM table
324 * Pointer to TruFlow handle
327 * Pointer to input parameters
331 * -EINVAL - Parameter error
333 int tf_em_delete_ext_sys_entry(struct tf *tfp,
334 struct tf_delete_em_entry_parms *parms);
337 * Bind internal EM device interface
340 * Pointer to TruFlow handle
343 * Pointer to input parameters
347 * -EINVAL - Parameter error
349 int tf_em_int_bind(struct tf *tfp,
350 struct tf_em_cfg_parms *parms);
353 * Unbind internal EM device interface
356 * Pointer to TruFlow handle
359 * Pointer to input parameters
363 * -EINVAL - Parameter error
365 int tf_em_int_unbind(struct tf *tfp);
368 * Common bind for EEM device interface. Used for both host and
372 * Pointer to TruFlow handle
375 * Pointer to input parameters
379 * -EINVAL - Parameter error
381 int tf_em_ext_common_bind(struct tf *tfp,
382 struct tf_em_cfg_parms *parms);
385 * Common unbind for EEM device interface. Used for both host and
389 * Pointer to TruFlow handle
392 * Pointer to input parameters
396 * -EINVAL - Parameter error
398 int tf_em_ext_common_unbind(struct tf *tfp);
401 * Alloc for external EEM using host memory
404 * Pointer to TruFlow handle
407 * Pointer to input parameters
411 * -EINVAL - Parameter error
413 int tf_em_ext_alloc(struct tf *tfp,
414 struct tf_alloc_tbl_scope_parms *parms);
417 * Free for external EEM using host memory
420 * Pointer to TruFlow handle
423 * Pointer to input parameters
427 * -EINVAL - Parameter error
429 int tf_em_ext_free(struct tf *tfp,
430 struct tf_free_tbl_scope_parms *parms);
433 * Common free table scope for external EEM using host or system memory
436 * Pointer to TruFlow handle
439 * Pointer to input parameters
443 * -EINVAL - Parameter error
445 int tf_em_ext_common_free(struct tf *tfp,
446 struct tf_free_tbl_scope_parms *parms);
449 * Common alloc table scope for external EEM using host or system memory
452 * Pointer to TruFlow handle
455 * Pointer to input parameters
459 * -EINVAL - Parameter error
461 int tf_em_ext_common_alloc(struct tf *tfp,
462 struct tf_alloc_tbl_scope_parms *parms);
464 * Map a set of parifs to a set of EEM base addresses (table scope)
467 * Pointer to TruFlow handle
470 * Pointer to input parameters
474 * -EINVAL - Parameter error
476 int tf_em_ext_map_tbl_scope(struct tf *tfp,
477 struct tf_map_tbl_scope_parms *parms);
480 * Allocate External Tbl entry from the scope pool.
483 * Pointer to Truflow Handle
485 * Allocation parameters
488 * 0 - Success, entry allocated - no search support
489 * -ENOMEM -EINVAL -EOPNOTSUPP
490 * - Failure, entry not allocated, out of resources
493 tf_tbl_ext_alloc(struct tf *tfp,
494 struct tf_tbl_alloc_parms *parms);
497 * Free External Tbl entry to the scope pool.
500 * Pointer to Truflow Handle
502 * Allocation parameters
505 * 0 - Success, entry freed
507 * - Failure, entry not successfully freed for these reasons
513 tf_tbl_ext_free(struct tf *tfp,
514 struct tf_tbl_free_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_common_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_set(struct tf *tfp,
552 struct tf_tbl_set_parms *parms);
555 tf_em_ext_system_bind(struct tf *tfp,
556 struct tf_em_cfg_parms *parms);
558 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
561 * Retrieves the allocated resource info
564 * Pointer to TF handle, used for HCAPI communication
567 * Pointer to parameters
570 * - (0) if successful.
571 * - (-EINVAL) on failure.
574 tf_em_get_resc_info(struct tf *tfp,
575 struct tf_em_resource_info *em);
576 #endif /* _TF_EM_H_ */