1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
10 #include "tf_session.h"
12 #include "hcapi/hcapi_cfa_defs.h"
14 #define TF_EM_MIN_ENTRIES (1 << 15) /* 32K */
15 #define TF_EM_MAX_ENTRIES (1 << 27) /* 128M */
17 #define TF_HW_EM_KEY_MAX_SIZE 52
18 #define TF_EM_KEY_RECORD_SIZE 64
20 #define TF_EM_MAX_MASK 0x7FFF
21 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
24 * Hardware Page sizes supported for EEM:
25 * 4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
27 * Round-down other page sizes to the lower hardware page
30 #define TF_EM_PAGE_SIZE_4K 12
31 #define TF_EM_PAGE_SIZE_8K 13
32 #define TF_EM_PAGE_SIZE_64K 16
33 #define TF_EM_PAGE_SIZE_256K 18
34 #define TF_EM_PAGE_SIZE_1M 20
35 #define TF_EM_PAGE_SIZE_2M 21
36 #define TF_EM_PAGE_SIZE_4M 22
37 #define TF_EM_PAGE_SIZE_1G 30
40 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
42 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K) /** 4K */
43 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
44 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
45 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
46 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
47 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
48 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K) /** 64K */
49 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
50 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
51 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K) /** 256K */
52 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
53 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
54 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
55 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
56 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
57 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
58 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
59 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
60 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
61 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
62 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
63 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
64 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
65 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
67 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
71 * System memory always uses 4K pages
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_alloc
161 * @ref tf_em_ext_free
163 * @ref tf_em_ext_common_free
165 * @ref tf_em_ext_common_alloc
169 * Insert record in to internal EM table
172 * Pointer to TruFlow handle
175 * Pointer to input parameters
179 * -EINVAL - Parameter error
181 int tf_em_insert_int_entry(struct tf *tfp,
182 struct tf_insert_em_entry_parms *parms);
185 * Delete record from internal EM table
188 * Pointer to TruFlow handle
191 * Pointer to input parameters
195 * -EINVAL - Parameter error
197 int tf_em_delete_int_entry(struct tf *tfp,
198 struct tf_delete_em_entry_parms *parms);
201 * Insert record in to external EEM table
204 * Pointer to TruFlow handle
207 * Pointer to input parameters
211 * -EINVAL - Parameter error
213 int tf_em_insert_ext_entry(struct tf *tfp,
214 struct tf_insert_em_entry_parms *parms);
217 * Insert record from external EEM table
220 * Pointer to TruFlow handle
223 * Pointer to input parameters
227 * -EINVAL - Parameter error
229 int tf_em_delete_ext_entry(struct tf *tfp,
230 struct tf_delete_em_entry_parms *parms);
233 * Insert record in to external system EEM table
236 * Pointer to TruFlow handle
239 * Pointer to input parameters
243 * -EINVAL - Parameter error
245 int tf_em_insert_ext_sys_entry(struct tf *tfp,
246 struct tf_insert_em_entry_parms *parms);
249 * Delete record from external system EEM table
252 * Pointer to TruFlow handle
255 * Pointer to input parameters
259 * -EINVAL - Parameter error
261 int tf_em_delete_ext_sys_entry(struct tf *tfp,
262 struct tf_delete_em_entry_parms *parms);
265 * Bind internal EM device interface
268 * Pointer to TruFlow handle
271 * Pointer to input parameters
275 * -EINVAL - Parameter error
277 int tf_em_int_bind(struct tf *tfp,
278 struct tf_em_cfg_parms *parms);
281 * Unbind internal EM device interface
284 * Pointer to TruFlow handle
287 * Pointer to input parameters
291 * -EINVAL - Parameter error
293 int tf_em_int_unbind(struct tf *tfp);
296 * Common bind for EEM device interface. Used for both host and
300 * Pointer to TruFlow handle
303 * Pointer to input parameters
307 * -EINVAL - Parameter error
309 int tf_em_ext_common_bind(struct tf *tfp,
310 struct tf_em_cfg_parms *parms);
313 * Common unbind for EEM device interface. Used for both host and
317 * Pointer to TruFlow handle
320 * Pointer to input parameters
324 * -EINVAL - Parameter error
326 int tf_em_ext_common_unbind(struct tf *tfp);
329 * Alloc for external EEM using host memory
332 * Pointer to TruFlow handle
335 * Pointer to input parameters
339 * -EINVAL - Parameter error
341 int tf_em_ext_alloc(struct tf *tfp,
342 struct tf_alloc_tbl_scope_parms *parms);
345 * Free for external EEM using host memory
348 * Pointer to TruFlow handle
351 * Pointer to input parameters
355 * -EINVAL - Parameter error
357 int tf_em_ext_free(struct tf *tfp,
358 struct tf_free_tbl_scope_parms *parms);
361 * Common free for external EEM using host or system memory
364 * Pointer to TruFlow handle
367 * Pointer to input parameters
371 * -EINVAL - Parameter error
373 int tf_em_ext_common_free(struct tf *tfp,
374 struct tf_free_tbl_scope_parms *parms);
377 * Common alloc for external EEM using host or system memory
380 * Pointer to TruFlow handle
383 * Pointer to input parameters
387 * -EINVAL - Parameter error
389 int tf_em_ext_common_alloc(struct tf *tfp,
390 struct tf_alloc_tbl_scope_parms *parms);
393 * Allocate External Tbl entry from the scope pool.
396 * Pointer to Truflow Handle
398 * Allocation parameters
401 * 0 - Success, entry allocated - no search support
402 * -ENOMEM -EINVAL -EOPNOTSUPP
403 * - Failure, entry not allocated, out of resources
406 tf_tbl_ext_alloc(struct tf *tfp,
407 struct tf_tbl_alloc_parms *parms);
410 * Free External Tbl entry to the scope pool.
413 * Pointer to Truflow Handle
415 * Allocation parameters
418 * 0 - Success, entry freed
420 * - Failure, entry not successfully freed for these reasons
426 tf_tbl_ext_free(struct tf *tfp,
427 struct tf_tbl_free_parms *parms);
430 * Sets the specified external table type element.
432 * This API sets the specified element data by invoking the
436 * Pointer to TF handle
439 * Pointer to table set parameters
442 * - (0) if successful.
443 * - (-EINVAL) on failure.
445 int tf_tbl_ext_common_set(struct tf *tfp,
446 struct tf_tbl_set_parms *parms);
449 * Sets the specified external table type element.
451 * This API sets the specified element data by invoking the
455 * Pointer to TF handle
458 * Pointer to table set parameters
461 * - (0) if successful.
462 * - (-EINVAL) on failure.
464 int tf_tbl_ext_set(struct tf *tfp,
465 struct tf_tbl_set_parms *parms);
468 tf_em_ext_system_bind(struct tf *tfp,
469 struct tf_em_cfg_parms *parms);
471 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
472 #endif /* _TF_EM_H_ */