1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 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 table scope 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 table scope 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);
392 * Map a set of parifs to a set of EEM base addresses (table scope)
395 * Pointer to TruFlow handle
398 * Pointer to input parameters
402 * -EINVAL - Parameter error
404 int tf_em_ext_map_tbl_scope(struct tf *tfp,
405 struct tf_map_tbl_scope_parms *parms);
408 * Allocate External Tbl entry from the scope pool.
411 * Pointer to Truflow Handle
413 * Allocation parameters
416 * 0 - Success, entry allocated - no search support
417 * -ENOMEM -EINVAL -EOPNOTSUPP
418 * - Failure, entry not allocated, out of resources
421 tf_tbl_ext_alloc(struct tf *tfp,
422 struct tf_tbl_alloc_parms *parms);
425 * Free External Tbl entry to the scope pool.
428 * Pointer to Truflow Handle
430 * Allocation parameters
433 * 0 - Success, entry freed
435 * - Failure, entry not successfully freed for these reasons
441 tf_tbl_ext_free(struct tf *tfp,
442 struct tf_tbl_free_parms *parms);
445 * Sets the specified external table type element.
447 * This API sets the specified element data by invoking the
451 * Pointer to TF handle
454 * Pointer to table set parameters
457 * - (0) if successful.
458 * - (-EINVAL) on failure.
460 int tf_tbl_ext_common_set(struct tf *tfp,
461 struct tf_tbl_set_parms *parms);
464 * Sets the specified external table type element.
466 * This API sets the specified element data by invoking the
470 * Pointer to TF handle
473 * Pointer to table set parameters
476 * - (0) if successful.
477 * - (-EINVAL) on failure.
479 int tf_tbl_ext_set(struct tf *tfp,
480 struct tf_tbl_set_parms *parms);
483 tf_em_ext_system_bind(struct tf *tfp,
484 struct tf_em_cfg_parms *parms);
486 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
487 #endif /* _TF_EM_H_ */