1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
10 #include "tf_session.h"
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_EM_MIN_ENTRIES (1 << 15) /* 32K */
21 #define TF_EM_MAX_ENTRIES (1 << 27) /* 128M */
23 #define TF_HW_EM_KEY_MAX_SIZE 52
24 #define TF_EM_KEY_RECORD_SIZE 64
26 #define TF_EM_MAX_MASK 0x7FFF
27 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
30 * Hardware Page sizes supported for EEM:
31 * 4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
33 * Round-down other page sizes to the lower hardware page
36 #define TF_EM_PAGE_SIZE_4K 12
37 #define TF_EM_PAGE_SIZE_8K 13
38 #define TF_EM_PAGE_SIZE_64K 16
39 #define TF_EM_PAGE_SIZE_256K 18
40 #define TF_EM_PAGE_SIZE_1M 20
41 #define TF_EM_PAGE_SIZE_2M 21
42 #define TF_EM_PAGE_SIZE_4M 22
43 #define TF_EM_PAGE_SIZE_1G 30
46 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
48 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K) /** 4K */
49 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
50 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
51 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
52 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
53 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
54 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K) /** 64K */
55 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
56 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
57 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K) /** 256K */
58 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
59 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
60 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
61 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
62 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
63 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
64 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
65 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
66 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
67 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
68 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
69 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
70 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
71 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
73 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
77 * System memory always uses 4K pages
79 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
80 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
90 * E = Entry (bucket inndex)
92 #define TF_EM_INTERNAL_INDEX_SHIFT 2
93 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
94 #define TF_EM_INTERNAL_ENTRY_MASK 0x3
97 * Each EM entry is 512-bit (64-bytes) but ordered differently to
100 struct tf_em_64b_entry {
101 /** Header is 8 bytes long */
102 struct cfa_p4_eem_entry_hdr hdr;
103 /** Key is 448 bits - 56 bytes */
104 uint8_t key[TF_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
111 TF_EEM_MEM_TYPE_INVALID,
112 TF_EEM_MEM_TYPE_HOST,
113 TF_EEM_MEM_TYPE_SYSTEM
117 * tf_em_cfg_parms definition
119 struct tf_em_cfg_parms {
121 * [in] Num entries in resource config
123 uint16_t num_elements;
125 * [in] Resource config
127 struct tf_rm_element_cfg *cfg;
129 * Session resource allocations
131 struct tf_session_resources *resources;
135 enum tf_mem_type mem_type;
141 * @ref tf_alloc_eem_tbl_scope
143 * @ref tf_free_eem_tbl_scope_cb
145 * @ref tf_em_insert_int_entry
147 * @ref tf_em_delete_int_entry
149 * @ref tf_em_insert_ext_entry
151 * @ref tf_em_delete_ext_entry
153 * @ref tf_em_insert_ext_sys_entry
155 * @ref tf_em_delete_ext_sys_entry
157 * @ref tf_em_int_bind
159 * @ref tf_em_int_unbind
161 * @ref tf_em_ext_common_bind
163 * @ref tf_em_ext_common_unbind
165 * @ref tf_em_ext_alloc
167 * @ref tf_em_ext_free
169 * @ref tf_em_ext_common_free
171 * @ref tf_em_ext_common_alloc
175 * Insert record in to internal EM table
178 * Pointer to TruFlow handle
181 * Pointer to input parameters
185 * -EINVAL - Parameter error
187 int tf_em_insert_int_entry(struct tf *tfp,
188 struct tf_insert_em_entry_parms *parms);
191 * Delete record from internal EM table
194 * Pointer to TruFlow handle
197 * Pointer to input parameters
201 * -EINVAL - Parameter error
203 int tf_em_delete_int_entry(struct tf *tfp,
204 struct tf_delete_em_entry_parms *parms);
207 * Insert record in to external EEM table
210 * Pointer to TruFlow handle
213 * Pointer to input parameters
217 * -EINVAL - Parameter error
219 int tf_em_insert_ext_entry(struct tf *tfp,
220 struct tf_insert_em_entry_parms *parms);
223 * Insert record from external EEM table
226 * Pointer to TruFlow handle
229 * Pointer to input parameters
233 * -EINVAL - Parameter error
235 int tf_em_delete_ext_entry(struct tf *tfp,
236 struct tf_delete_em_entry_parms *parms);
239 * Insert record in to external system EEM table
242 * Pointer to TruFlow handle
245 * Pointer to input parameters
249 * -EINVAL - Parameter error
251 int tf_em_insert_ext_sys_entry(struct tf *tfp,
252 struct tf_insert_em_entry_parms *parms);
255 * Delete record from external system EEM table
258 * Pointer to TruFlow handle
261 * Pointer to input parameters
265 * -EINVAL - Parameter error
267 int tf_em_delete_ext_sys_entry(struct tf *tfp,
268 struct tf_delete_em_entry_parms *parms);
271 * Bind internal EM device interface
274 * Pointer to TruFlow handle
277 * Pointer to input parameters
281 * -EINVAL - Parameter error
283 int tf_em_int_bind(struct tf *tfp,
284 struct tf_em_cfg_parms *parms);
287 * Unbind internal EM device interface
290 * Pointer to TruFlow handle
293 * Pointer to input parameters
297 * -EINVAL - Parameter error
299 int tf_em_int_unbind(struct tf *tfp);
302 * Common bind for EEM device interface. Used for both host and
306 * Pointer to TruFlow handle
309 * Pointer to input parameters
313 * -EINVAL - Parameter error
315 int tf_em_ext_common_bind(struct tf *tfp,
316 struct tf_em_cfg_parms *parms);
319 * Common unbind for EEM device interface. Used for both host and
323 * Pointer to TruFlow handle
326 * Pointer to input parameters
330 * -EINVAL - Parameter error
332 int tf_em_ext_common_unbind(struct tf *tfp);
335 * Alloc for external EEM using host memory
338 * Pointer to TruFlow handle
341 * Pointer to input parameters
345 * -EINVAL - Parameter error
347 int tf_em_ext_alloc(struct tf *tfp,
348 struct tf_alloc_tbl_scope_parms *parms);
351 * Free for external EEM using host memory
354 * Pointer to TruFlow handle
357 * Pointer to input parameters
361 * -EINVAL - Parameter error
363 int tf_em_ext_free(struct tf *tfp,
364 struct tf_free_tbl_scope_parms *parms);
367 * Common free for external EEM using host or system memory
370 * Pointer to TruFlow handle
373 * Pointer to input parameters
377 * -EINVAL - Parameter error
379 int tf_em_ext_common_free(struct tf *tfp,
380 struct tf_free_tbl_scope_parms *parms);
383 * Common alloc for external EEM using host or system memory
386 * Pointer to TruFlow handle
389 * Pointer to input parameters
393 * -EINVAL - Parameter error
395 int tf_em_ext_common_alloc(struct tf *tfp,
396 struct tf_alloc_tbl_scope_parms *parms);
399 * Allocate External Tbl entry from the scope pool.
402 * Pointer to Truflow Handle
404 * Allocation parameters
407 * 0 - Success, entry allocated - no search support
408 * -ENOMEM -EINVAL -EOPNOTSUPP
409 * - Failure, entry not allocated, out of resources
412 tf_tbl_ext_alloc(struct tf *tfp,
413 struct tf_tbl_alloc_parms *parms);
416 * Free External Tbl entry to the scope pool.
419 * Pointer to Truflow Handle
421 * Allocation parameters
424 * 0 - Success, entry freed
426 * - Failure, entry not successfully freed for these reasons
432 tf_tbl_ext_free(struct tf *tfp,
433 struct tf_tbl_free_parms *parms);
436 * Sets the specified external table type element.
438 * This API sets the specified element data by invoking the
442 * Pointer to TF handle
445 * Pointer to table set parameters
448 * - (0) if successful.
449 * - (-EINVAL) on failure.
451 int tf_tbl_ext_common_set(struct tf *tfp,
452 struct tf_tbl_set_parms *parms);
455 * Sets the specified external table type element.
457 * This API sets the specified element data by invoking the
461 * Pointer to TF handle
464 * Pointer to table set parameters
467 * - (0) if successful.
468 * - (-EINVAL) on failure.
470 int tf_tbl_ext_set(struct tf *tfp,
471 struct tf_tbl_set_parms *parms);
474 tf_em_ext_system_bind(struct tf *tfp,
475 struct tf_em_cfg_parms *parms);
477 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
478 #endif /* _TF_EM_H_ */