1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
10 #include "tf_session.h"
12 #ifdef TF_USE_SYSTEM_MEM
14 * Select EEM sysmem mmap export to be done at init
15 * or on the first write to EEM.
17 #define TF_EM_SYSMEM_DELAY_EXPORT 1
19 #define TF_EM_SYSMEM_DELAY_EXPORT 0
22 #define SUPPORT_CFA_HW_P4 1
23 #define SUPPORT_CFA_HW_P58 0
24 #define SUPPORT_CFA_HW_P59 0
25 #define SUPPORT_CFA_HW_ALL 0
27 #include "hcapi/hcapi_cfa_defs.h"
29 #define TF_EM_MIN_ENTRIES (1 << 15) /* 32K */
30 #define TF_EM_MAX_ENTRIES (1 << 27) /* 128M */
32 #define TF_HW_EM_KEY_MAX_SIZE 52
33 #define TF_EM_KEY_RECORD_SIZE 64
35 #define TF_EM_MAX_MASK 0x7FFF
36 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
39 * Hardware Page sizes supported for EEM:
40 * 4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
42 * Round-down other page sizes to the lower hardware page
45 #define TF_EM_PAGE_SIZE_4K 12
46 #define TF_EM_PAGE_SIZE_8K 13
47 #define TF_EM_PAGE_SIZE_64K 16
48 #define TF_EM_PAGE_SIZE_256K 18
49 #define TF_EM_PAGE_SIZE_1M 20
50 #define TF_EM_PAGE_SIZE_2M 21
51 #define TF_EM_PAGE_SIZE_4M 22
52 #define TF_EM_PAGE_SIZE_1G 30
55 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
57 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K) /** 4K */
58 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
59 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
60 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
61 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
62 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
63 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K) /** 64K */
64 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
65 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
66 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K) /** 256K */
67 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
68 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
69 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
70 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
71 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
72 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
73 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
74 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
75 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
76 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
77 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
78 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
79 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
80 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
82 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
86 * System memory always uses 4K pages
88 #ifdef TF_USE_SYSTEM_MEM
89 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SIZE_4K)
90 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SIZE_4K)
92 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
93 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
100 * +--------------+--+
102 * +--------------+--+
104 * E = Entry (bucket inndex)
106 #define TF_EM_INTERNAL_INDEX_SHIFT 2
107 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
108 #define TF_EM_INTERNAL_ENTRY_MASK 0x3
111 * Each EM entry is 512-bit (64-bytes) but ordered differently to
114 struct tf_em_64b_entry {
115 /** Header is 8 bytes long */
116 struct cfa_p4_eem_entry_hdr hdr;
117 /** Key is 448 bits - 56 bytes */
118 uint8_t key[TF_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
125 TF_EEM_MEM_TYPE_INVALID,
126 TF_EEM_MEM_TYPE_HOST,
127 TF_EEM_MEM_TYPE_SYSTEM
131 * tf_em_cfg_parms definition
133 struct tf_em_cfg_parms {
135 * [in] Num entries in resource config
137 uint16_t num_elements;
139 * [in] Resource config
141 struct tf_rm_element_cfg *cfg;
143 * Session resource allocations
145 struct tf_session_resources *resources;
149 enum tf_mem_type mem_type;
155 * @ref tf_alloc_eem_tbl_scope
157 * @ref tf_free_eem_tbl_scope_cb
159 * @ref tf_em_insert_int_entry
161 * @ref tf_em_delete_int_entry
163 * @ref tf_em_insert_ext_entry
165 * @ref tf_em_delete_ext_entry
167 * @ref tf_em_insert_ext_sys_entry
169 * @ref tf_em_delete_ext_sys_entry
171 * @ref tf_em_int_bind
173 * @ref tf_em_int_unbind
175 * @ref tf_em_ext_common_bind
177 * @ref tf_em_ext_common_unbind
179 * @ref tf_em_ext_host_alloc
181 * @ref tf_em_ext_host_free
183 * @ref tf_em_ext_system_alloc
185 * @ref tf_em_ext_system_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 external EEM table
228 * Pointer to TruFlow handle
231 * Pointer to input parameters
235 * -EINVAL - Parameter error
237 int tf_em_insert_ext_entry(struct tf *tfp,
238 struct tf_insert_em_entry_parms *parms);
241 * Insert record from external EEM table
244 * Pointer to TruFlow handle
247 * Pointer to input parameters
251 * -EINVAL - Parameter error
253 int tf_em_delete_ext_entry(struct tf *tfp,
254 struct tf_delete_em_entry_parms *parms);
257 * Insert record in to external system EEM table
260 * Pointer to TruFlow handle
263 * Pointer to input parameters
267 * -EINVAL - Parameter error
269 int tf_em_insert_ext_sys_entry(struct tf *tfp,
270 struct tf_insert_em_entry_parms *parms);
273 * Delete record from external system EEM table
276 * Pointer to TruFlow handle
279 * Pointer to input parameters
283 * -EINVAL - Parameter error
285 int tf_em_delete_ext_sys_entry(struct tf *tfp,
286 struct tf_delete_em_entry_parms *parms);
289 * Bind internal EM device interface
292 * Pointer to TruFlow handle
295 * Pointer to input parameters
299 * -EINVAL - Parameter error
301 int tf_em_int_bind(struct tf *tfp,
302 struct tf_em_cfg_parms *parms);
305 * Unbind internal EM device interface
308 * Pointer to TruFlow handle
311 * Pointer to input parameters
315 * -EINVAL - Parameter error
317 int tf_em_int_unbind(struct tf *tfp);
320 * Common bind for EEM device interface. Used for both host and
324 * Pointer to TruFlow handle
327 * Pointer to input parameters
331 * -EINVAL - Parameter error
333 int tf_em_ext_common_bind(struct tf *tfp,
334 struct tf_em_cfg_parms *parms);
337 * Common unbind for EEM device interface. Used for both host and
341 * Pointer to TruFlow handle
344 * Pointer to input parameters
348 * -EINVAL - Parameter error
350 int tf_em_ext_common_unbind(struct tf *tfp);
353 * Alloc for external EEM using host memory
356 * Pointer to TruFlow handle
359 * Pointer to input parameters
363 * -EINVAL - Parameter error
365 int tf_em_ext_alloc(struct tf *tfp,
366 struct tf_alloc_tbl_scope_parms *parms);
369 * Free for external EEM using host memory
372 * Pointer to TruFlow handle
375 * Pointer to input parameters
379 * -EINVAL - Parameter error
381 int tf_em_ext_free(struct tf *tfp,
382 struct tf_free_tbl_scope_parms *parms);
385 * Common free for external EEM using host or system memory
388 * Pointer to TruFlow handle
391 * Pointer to input parameters
395 * -EINVAL - Parameter error
397 int tf_em_ext_common_free(struct tf *tfp,
398 struct tf_free_tbl_scope_parms *parms);
401 * Common alloc for external EEM using host or system memory
404 * Pointer to TruFlow handle
407 * Pointer to input parameters
411 * -EINVAL - Parameter error
413 int tf_em_ext_common_alloc(struct tf *tfp,
414 struct tf_alloc_tbl_scope_parms *parms);
417 * Allocate External Tbl entry from the scope pool.
420 * Pointer to Truflow Handle
422 * Allocation parameters
425 * 0 - Success, entry allocated - no search support
426 * -ENOMEM -EINVAL -EOPNOTSUPP
427 * - Failure, entry not allocated, out of resources
430 tf_tbl_ext_alloc(struct tf *tfp,
431 struct tf_tbl_alloc_parms *parms);
434 * Free External Tbl entry to the scope pool.
437 * Pointer to Truflow Handle
439 * Allocation parameters
442 * 0 - Success, entry freed
444 * - Failure, entry not successfully freed for these reasons
450 tf_tbl_ext_free(struct tf *tfp,
451 struct tf_tbl_free_parms *parms);
454 * Sets the specified external table type element.
456 * This API sets the specified element data by invoking the
460 * Pointer to TF handle
463 * Pointer to table set parameters
466 * - (0) if successful.
467 * - (-EINVAL) on failure.
469 int tf_tbl_ext_common_set(struct tf *tfp,
470 struct tf_tbl_set_parms *parms);
473 * Sets the specified external table type element.
475 * This API sets the specified element data by invoking the
479 * Pointer to TF handle
482 * Pointer to table set parameters
485 * - (0) if successful.
486 * - (-EINVAL) on failure.
488 int tf_tbl_ext_set(struct tf *tfp,
489 struct tf_tbl_set_parms *parms);
492 tf_em_ext_system_bind(struct tf *tfp,
493 struct tf_em_cfg_parms *parms);
495 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
496 #endif /* _TF_EM_H_ */