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_EM_MIN_ENTRIES (1 << 15) /* 32K */
20 #define TF_EM_MAX_ENTRIES (1 << 27) /* 128M */
22 #define TF_HW_EM_KEY_MAX_SIZE 52
23 #define TF_EM_KEY_RECORD_SIZE 64
25 #define TF_EM_MAX_MASK 0x7FFF
26 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
29 * Hardware Page sizes supported for EEM:
30 * 4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
32 * Round-down other page sizes to the lower hardware page
35 #define TF_EM_PAGE_SIZE_4K 12
36 #define TF_EM_PAGE_SIZE_8K 13
37 #define TF_EM_PAGE_SIZE_64K 16
38 #define TF_EM_PAGE_SIZE_256K 18
39 #define TF_EM_PAGE_SIZE_1M 20
40 #define TF_EM_PAGE_SIZE_2M 21
41 #define TF_EM_PAGE_SIZE_4M 22
42 #define TF_EM_PAGE_SIZE_1G 30
45 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
47 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K) /** 4K */
48 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
49 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
50 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
51 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
52 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
53 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K) /** 64K */
54 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
55 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
56 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K) /** 256K */
57 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
58 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
59 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
60 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
61 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
62 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
63 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
64 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
65 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
66 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
67 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
68 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
69 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
70 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
72 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
76 * System memory always uses 4K pages
78 #ifdef TF_USE_SYSTEM_MEM
79 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SIZE_4K)
80 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SIZE_4K)
82 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
83 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
94 * E = Entry (bucket inndex)
96 #define TF_EM_INTERNAL_INDEX_SHIFT 2
97 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
98 #define TF_EM_INTERNAL_ENTRY_MASK 0x3
101 * Each EM entry is 512-bit (64-bytes) but ordered differently to
104 struct tf_em_64b_entry {
105 /** Header is 8 bytes long */
106 struct cfa_p4_eem_entry_hdr hdr;
107 /** Key is 448 bits - 56 bytes */
108 uint8_t key[TF_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
115 TF_EEM_MEM_TYPE_INVALID,
116 TF_EEM_MEM_TYPE_HOST,
117 TF_EEM_MEM_TYPE_SYSTEM
121 * tf_em_cfg_parms definition
123 struct tf_em_cfg_parms {
125 * [in] Num entries in resource config
127 uint16_t num_elements;
129 * [in] Resource config
131 struct tf_rm_element_cfg *cfg;
133 * Session resource allocations
135 struct tf_session_resources *resources;
139 enum tf_mem_type mem_type;
145 * @ref tf_alloc_eem_tbl_scope
147 * @ref tf_free_eem_tbl_scope_cb
149 * @ref tf_em_insert_int_entry
151 * @ref tf_em_delete_int_entry
153 * @ref tf_em_insert_ext_entry
155 * @ref tf_em_delete_ext_entry
157 * @ref tf_em_insert_ext_sys_entry
159 * @ref tf_em_delete_ext_sys_entry
161 * @ref tf_em_int_bind
163 * @ref tf_em_int_unbind
165 * @ref tf_em_ext_common_bind
167 * @ref tf_em_ext_common_unbind
169 * @ref tf_em_ext_host_alloc
171 * @ref tf_em_ext_host_free
173 * @ref tf_em_ext_system_alloc
175 * @ref tf_em_ext_system_free
177 * @ref tf_em_ext_common_free
179 * @ref tf_em_ext_common_alloc
183 * Insert record in to internal EM table
186 * Pointer to TruFlow handle
189 * Pointer to input parameters
193 * -EINVAL - Parameter error
195 int tf_em_insert_int_entry(struct tf *tfp,
196 struct tf_insert_em_entry_parms *parms);
199 * Delete record from internal EM table
202 * Pointer to TruFlow handle
205 * Pointer to input parameters
209 * -EINVAL - Parameter error
211 int tf_em_delete_int_entry(struct tf *tfp,
212 struct tf_delete_em_entry_parms *parms);
215 * Insert record in to external EEM table
218 * Pointer to TruFlow handle
221 * Pointer to input parameters
225 * -EINVAL - Parameter error
227 int tf_em_insert_ext_entry(struct tf *tfp,
228 struct tf_insert_em_entry_parms *parms);
231 * Insert record from external EEM table
234 * Pointer to TruFlow handle
237 * Pointer to input parameters
241 * -EINVAL - Parameter error
243 int tf_em_delete_ext_entry(struct tf *tfp,
244 struct tf_delete_em_entry_parms *parms);
247 * Insert record in to external system EEM table
250 * Pointer to TruFlow handle
253 * Pointer to input parameters
257 * -EINVAL - Parameter error
259 int tf_em_insert_ext_sys_entry(struct tf *tfp,
260 struct tf_insert_em_entry_parms *parms);
263 * Delete record from external system EEM table
266 * Pointer to TruFlow handle
269 * Pointer to input parameters
273 * -EINVAL - Parameter error
275 int tf_em_delete_ext_sys_entry(struct tf *tfp,
276 struct tf_delete_em_entry_parms *parms);
279 * Bind internal EM device interface
282 * Pointer to TruFlow handle
285 * Pointer to input parameters
289 * -EINVAL - Parameter error
291 int tf_em_int_bind(struct tf *tfp,
292 struct tf_em_cfg_parms *parms);
295 * Unbind internal EM device interface
298 * Pointer to TruFlow handle
301 * Pointer to input parameters
305 * -EINVAL - Parameter error
307 int tf_em_int_unbind(struct tf *tfp);
310 * Common bind for EEM device interface. Used for both host and
314 * Pointer to TruFlow handle
317 * Pointer to input parameters
321 * -EINVAL - Parameter error
323 int tf_em_ext_common_bind(struct tf *tfp,
324 struct tf_em_cfg_parms *parms);
327 * Common unbind for EEM device interface. Used for both host and
331 * Pointer to TruFlow handle
334 * Pointer to input parameters
338 * -EINVAL - Parameter error
340 int tf_em_ext_common_unbind(struct tf *tfp);
343 * Alloc for external EEM using host memory
346 * Pointer to TruFlow handle
349 * Pointer to input parameters
353 * -EINVAL - Parameter error
355 int tf_em_ext_alloc(struct tf *tfp,
356 struct tf_alloc_tbl_scope_parms *parms);
359 * Free for external EEM using host memory
362 * Pointer to TruFlow handle
365 * Pointer to input parameters
369 * -EINVAL - Parameter error
371 int tf_em_ext_free(struct tf *tfp,
372 struct tf_free_tbl_scope_parms *parms);
375 * Common free for external EEM using host or system memory
378 * Pointer to TruFlow handle
381 * Pointer to input parameters
385 * -EINVAL - Parameter error
387 int tf_em_ext_common_free(struct tf *tfp,
388 struct tf_free_tbl_scope_parms *parms);
391 * Common alloc for external EEM using host or system memory
394 * Pointer to TruFlow handle
397 * Pointer to input parameters
401 * -EINVAL - Parameter error
403 int tf_em_ext_common_alloc(struct tf *tfp,
404 struct tf_alloc_tbl_scope_parms *parms);
407 * Allocate External Tbl entry from the scope pool.
410 * Pointer to Truflow Handle
412 * Allocation parameters
415 * 0 - Success, entry allocated - no search support
416 * -ENOMEM -EINVAL -EOPNOTSUPP
417 * - Failure, entry not allocated, out of resources
420 tf_tbl_ext_alloc(struct tf *tfp,
421 struct tf_tbl_alloc_parms *parms);
424 * Free External Tbl entry to the scope pool.
427 * Pointer to Truflow Handle
429 * Allocation parameters
432 * 0 - Success, entry freed
434 * - Failure, entry not successfully freed for these reasons
440 tf_tbl_ext_free(struct tf *tfp,
441 struct tf_tbl_free_parms *parms);
444 * Sets the specified external table type element.
446 * This API sets the specified element data by invoking the
450 * Pointer to TF handle
453 * Pointer to table set parameters
456 * - (0) if successful.
457 * - (-EINVAL) on failure.
459 int tf_tbl_ext_common_set(struct tf *tfp,
460 struct tf_tbl_set_parms *parms);
463 * Sets the specified external table type element.
465 * This API sets the specified element data by invoking the
469 * Pointer to TF handle
472 * Pointer to table set parameters
475 * - (0) if successful.
476 * - (-EINVAL) on failure.
478 int tf_tbl_ext_set(struct tf *tfp,
479 struct tf_tbl_set_parms *parms);
482 tf_em_ext_system_bind(struct tf *tfp,
483 struct tf_em_cfg_parms *parms);
485 #endif /* _TF_EM_H_ */