1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
10 #include "tf_session.h"
12 #define TF_HACK_TBL_SCOPE_BASE 68
13 #define SUPPORT_CFA_HW_P4 1
14 #define SUPPORT_CFA_HW_P58 0
15 #define SUPPORT_CFA_HW_P59 0
16 #define SUPPORT_CFA_HW_ALL 0
18 #include "hcapi/hcapi_cfa_defs.h"
20 #define TF_HW_EM_KEY_MAX_SIZE 52
21 #define TF_EM_KEY_RECORD_SIZE 64
23 #define TF_EM_MAX_MASK 0x7FFF
24 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
27 * Hardware Page sizes supported for EEM:
28 * 4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
30 * Round-down other page sizes to the lower hardware page
33 #define TF_EM_PAGE_SIZE_4K 12
34 #define TF_EM_PAGE_SIZE_8K 13
35 #define TF_EM_PAGE_SIZE_64K 16
36 #define TF_EM_PAGE_SIZE_256K 18
37 #define TF_EM_PAGE_SIZE_1M 20
38 #define TF_EM_PAGE_SIZE_2M 21
39 #define TF_EM_PAGE_SIZE_4M 22
40 #define TF_EM_PAGE_SIZE_1G 30
43 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
45 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K) /** 4K */
46 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
47 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
48 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
49 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
50 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
51 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K) /** 64K */
52 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
53 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
54 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K) /** 256K */
55 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
56 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
57 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
58 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
59 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
60 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
61 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
62 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
63 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
64 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
65 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
66 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
67 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
68 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
70 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
73 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
74 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
84 * E = Entry (bucket inndex)
86 #define TF_EM_INTERNAL_INDEX_SHIFT 2
87 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
88 #define TF_EM_INTERNAL_ENTRY_MASK 0x3
91 * Each EM entry is 512-bit (64-bytes) but ordered differently to
94 struct tf_em_64b_entry {
95 /** Header is 8 bytes long */
96 struct cfa_p4_eem_entry_hdr hdr;
97 /** Key is 448 bits - 56 bytes */
98 uint8_t key[TF_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
105 TF_EEM_MEM_TYPE_INVALID,
106 TF_EEM_MEM_TYPE_HOST,
107 TF_EEM_MEM_TYPE_SYSTEM
111 * tf_em_cfg_parms definition
113 struct tf_em_cfg_parms {
115 * [in] Num entries in resource config
117 uint16_t num_elements;
119 * [in] Resource config
121 struct tf_rm_element_cfg *cfg;
123 * Session resource allocations
125 struct tf_session_resources *resources;
129 enum tf_mem_type mem_type;
135 * @ref tf_alloc_eem_tbl_scope
137 * @ref tf_free_eem_tbl_scope_cb
139 * @ref tf_em_insert_int_entry
141 * @ref tf_em_delete_int_entry
143 * @ref tf_em_insert_ext_entry
145 * @ref tf_em_delete_ext_entry
147 * @ref tf_em_insert_ext_sys_entry
149 * @ref tf_em_delete_ext_sys_entry
151 * @ref tf_em_int_bind
153 * @ref tf_em_int_unbind
155 * @ref tf_em_ext_common_bind
157 * @ref tf_em_ext_common_unbind
159 * @ref tf_em_ext_host_alloc
161 * @ref tf_em_ext_host_free
163 * @ref tf_em_ext_system_alloc
165 * @ref tf_em_ext_system_free
167 * @ref tf_em_ext_common_free
169 * @ref tf_em_ext_common_alloc
173 * Allocates EEM Table scope
176 * Pointer to TruFlow handle
179 * Pointer to input parameters
183 * -EINVAL - Parameter error
184 * -ENOMEM - Out of memory
186 int tf_alloc_eem_tbl_scope(struct tf *tfp,
187 struct tf_alloc_tbl_scope_parms *parms);
190 * Free's EEM Table scope control block
193 * Pointer to TruFlow handle
196 * Pointer to input parameters
200 * -EINVAL - Parameter error
202 int tf_free_eem_tbl_scope_cb(struct tf *tfp,
203 struct tf_free_tbl_scope_parms *parms);
206 * Insert record in to internal EM table
209 * Pointer to TruFlow handle
212 * Pointer to input parameters
216 * -EINVAL - Parameter error
218 int tf_em_insert_int_entry(struct tf *tfp,
219 struct tf_insert_em_entry_parms *parms);
222 * Delete record from internal EM table
225 * Pointer to TruFlow handle
228 * Pointer to input parameters
232 * -EINVAL - Parameter error
234 int tf_em_delete_int_entry(struct tf *tfp,
235 struct tf_delete_em_entry_parms *parms);
238 * Insert record in to external EEM table
241 * Pointer to TruFlow handle
244 * Pointer to input parameters
248 * -EINVAL - Parameter error
250 int tf_em_insert_ext_entry(struct tf *tfp,
251 struct tf_insert_em_entry_parms *parms);
254 * Insert record from external EEM table
257 * Pointer to TruFlow handle
260 * Pointer to input parameters
264 * -EINVAL - Parameter error
266 int tf_em_delete_ext_entry(struct tf *tfp,
267 struct tf_delete_em_entry_parms *parms);
270 * Insert record in to external system EEM table
273 * Pointer to TruFlow handle
276 * Pointer to input parameters
280 * -EINVAL - Parameter error
282 int tf_em_insert_ext_sys_entry(struct tf *tfp,
283 struct tf_insert_em_entry_parms *parms);
286 * Delete record from external system EEM table
289 * Pointer to TruFlow handle
292 * Pointer to input parameters
296 * -EINVAL - Parameter error
298 int tf_em_delete_ext_sys_entry(struct tf *tfp,
299 struct tf_delete_em_entry_parms *parms);
302 * Bind internal EM device interface
305 * Pointer to TruFlow handle
308 * Pointer to input parameters
312 * -EINVAL - Parameter error
314 int tf_em_int_bind(struct tf *tfp,
315 struct tf_em_cfg_parms *parms);
318 * Unbind internal EM device interface
321 * Pointer to TruFlow handle
324 * Pointer to input parameters
328 * -EINVAL - Parameter error
330 int tf_em_int_unbind(struct tf *tfp);
333 * Common bind for EEM device interface. Used for both host and
337 * Pointer to TruFlow handle
340 * Pointer to input parameters
344 * -EINVAL - Parameter error
346 int tf_em_ext_common_bind(struct tf *tfp,
347 struct tf_em_cfg_parms *parms);
350 * Common unbind for EEM device interface. Used for both host and
354 * Pointer to TruFlow handle
357 * Pointer to input parameters
361 * -EINVAL - Parameter error
363 int tf_em_ext_common_unbind(struct tf *tfp);
366 * Alloc for external EEM using host memory
369 * Pointer to TruFlow handle
372 * Pointer to input parameters
376 * -EINVAL - Parameter error
378 int tf_em_ext_host_alloc(struct tf *tfp,
379 struct tf_alloc_tbl_scope_parms *parms);
382 * Free for external EEM using host memory
385 * Pointer to TruFlow handle
388 * Pointer to input parameters
392 * -EINVAL - Parameter error
394 int tf_em_ext_host_free(struct tf *tfp,
395 struct tf_free_tbl_scope_parms *parms);
398 * Alloc for external EEM using system memory
401 * Pointer to TruFlow handle
404 * Pointer to input parameters
408 * -EINVAL - Parameter error
410 int tf_em_ext_system_alloc(struct tf *tfp,
411 struct tf_alloc_tbl_scope_parms *parms);
414 * Free for external EEM using system memory
417 * Pointer to TruFlow handle
420 * Pointer to input parameters
424 * -EINVAL - Parameter error
426 int tf_em_ext_system_free(struct tf *tfp,
427 struct tf_free_tbl_scope_parms *parms);
430 * Common free for external EEM using host or system memory
433 * Pointer to TruFlow handle
436 * Pointer to input parameters
440 * -EINVAL - Parameter error
442 int tf_em_ext_common_free(struct tf *tfp,
443 struct tf_free_tbl_scope_parms *parms);
446 * Common alloc for external EEM using host or system memory
449 * Pointer to TruFlow handle
452 * Pointer to input parameters
456 * -EINVAL - Parameter error
458 int tf_em_ext_common_alloc(struct tf *tfp,
459 struct tf_alloc_tbl_scope_parms *parms);
460 #endif /* _TF_EM_H_ */