1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
10 #include "tf_session.h"
12 #include "tf_em_common.h"
14 #include "hcapi_cfa_defs.h"
16 #define TF_EM_MIN_ENTRIES (1 << 15) /* 32K */
17 #define TF_EM_MAX_ENTRIES (1 << 27) /* 128M */
19 #define TF_P4_HW_EM_KEY_MAX_SIZE 52
20 #define TF_P4_EM_KEY_RECORD_SIZE 64
22 #define TF_P58_HW_EM_KEY_MAX_SIZE 80
24 #define TF_EM_MAX_MASK 0x7FFF
25 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
28 * Hardware Page sizes supported for EEM:
29 * 4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
31 * Round-down other page sizes to the lower hardware page
34 #define TF_EM_PAGE_SIZE_4K 12
35 #define TF_EM_PAGE_SIZE_8K 13
36 #define TF_EM_PAGE_SIZE_64K 16
37 #define TF_EM_PAGE_SIZE_256K 18
38 #define TF_EM_PAGE_SIZE_1M 20
39 #define TF_EM_PAGE_SIZE_2M 21
40 #define TF_EM_PAGE_SIZE_4M 22
41 #define TF_EM_PAGE_SIZE_1G 30
44 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
46 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K) /** 4K */
47 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
48 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
49 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
50 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
51 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
52 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K) /** 64K */
53 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
54 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
55 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K) /** 256K */
56 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
57 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
58 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
59 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
60 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
61 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
62 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
63 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
64 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
65 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
66 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
67 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
68 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
69 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
71 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
75 * System memory always uses 4K pages
77 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
78 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
88 * E = Entry (bucket inndex)
90 #define TF_EM_INTERNAL_INDEX_SHIFT 2
91 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
92 #define TF_EM_INTERNAL_ENTRY_MASK 0x3
95 * Each EM entry is 512-bit (64-bytes) but ordered differently to
98 struct tf_em_64b_entry {
99 /** Header is 8 bytes long */
100 struct cfa_p4_eem_entry_hdr hdr;
101 /** Key is 448 bits - 56 bytes */
102 uint8_t key[TF_P4_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
109 TF_EEM_MEM_TYPE_INVALID,
110 TF_EEM_MEM_TYPE_HOST,
111 TF_EEM_MEM_TYPE_SYSTEM
115 * tf_em_cfg_parms definition
117 struct tf_em_cfg_parms {
119 * [in] Num entries in resource config
121 uint16_t num_elements;
123 * [in] Resource config
125 struct tf_rm_element_cfg *cfg;
127 * Session resource allocations
129 struct tf_session_resources *resources;
133 enum tf_mem_type mem_type;
139 * @ref tf_alloc_eem_tbl_scope
141 * @ref tf_free_eem_tbl_scope_cb
143 * @ref tf_em_insert_int_entry
145 * @ref tf_em_delete_int_entry
147 * @ref tf_em_insert_ext_entry
149 * @ref tf_em_delete_ext_entry
151 * @ref tf_em_insert_ext_sys_entry
153 * @ref tf_em_delete_ext_sys_entry
155 * @ref tf_em_int_bind
157 * @ref tf_em_int_unbind
159 * @ref tf_em_ext_common_bind
161 * @ref tf_em_ext_common_unbind
163 * @ref tf_em_ext_alloc
165 * @ref tf_em_ext_free
167 * @ref tf_em_ext_common_free
169 * @ref tf_em_ext_common_alloc
173 * Insert record in to internal EM table
176 * Pointer to TruFlow handle
179 * Pointer to input parameters
183 * -EINVAL - Parameter error
185 int tf_em_insert_int_entry(struct tf *tfp,
186 struct tf_insert_em_entry_parms *parms);
189 * Delete record from internal EM table
192 * Pointer to TruFlow handle
195 * Pointer to input parameters
199 * -EINVAL - Parameter error
201 int tf_em_delete_int_entry(struct tf *tfp,
202 struct tf_delete_em_entry_parms *parms);
205 * Insert record in to internal EM table
208 * Pointer to TruFlow handle
211 * Pointer to input parameters
215 * -EINVAL - Parameter error
217 int tf_em_hash_insert_int_entry(struct tf *tfp,
218 struct tf_insert_em_entry_parms *parms);
221 * Delete record from internal EM table
224 * Pointer to TruFlow handle
227 * Pointer to input parameters
231 * -EINVAL - Parameter error
233 int tf_em_hash_delete_int_entry(struct tf *tfp,
234 struct tf_delete_em_entry_parms *parms);
237 * Insert record in to external EEM table
240 * Pointer to TruFlow handle
243 * Pointer to input parameters
247 * -EINVAL - Parameter error
249 int tf_em_insert_ext_entry(struct tf *tfp,
250 struct tf_insert_em_entry_parms *parms);
253 * Insert record from external EEM table
256 * Pointer to TruFlow handle
259 * Pointer to input parameters
263 * -EINVAL - Parameter error
265 int tf_em_delete_ext_entry(struct tf *tfp,
266 struct tf_delete_em_entry_parms *parms);
269 * Insert record in to external system EEM table
272 * Pointer to TruFlow handle
275 * Pointer to input parameters
279 * -EINVAL - Parameter error
281 int tf_em_insert_ext_sys_entry(struct tf *tfp,
282 struct tf_insert_em_entry_parms *parms);
285 * Delete record from external system EEM table
288 * Pointer to TruFlow handle
291 * Pointer to input parameters
295 * -EINVAL - Parameter error
297 int tf_em_delete_ext_sys_entry(struct tf *tfp,
298 struct tf_delete_em_entry_parms *parms);
301 * Bind internal EM device interface
304 * Pointer to TruFlow handle
307 * Pointer to input parameters
311 * -EINVAL - Parameter error
313 int tf_em_int_bind(struct tf *tfp,
314 struct tf_em_cfg_parms *parms);
317 * Unbind internal EM device interface
320 * Pointer to TruFlow handle
323 * Pointer to input parameters
327 * -EINVAL - Parameter error
329 int tf_em_int_unbind(struct tf *tfp);
332 * Common bind for EEM device interface. Used for both host and
336 * Pointer to TruFlow handle
339 * Pointer to input parameters
343 * -EINVAL - Parameter error
345 int tf_em_ext_common_bind(struct tf *tfp,
346 struct tf_em_cfg_parms *parms);
349 * Common unbind for EEM device interface. Used for both host and
353 * Pointer to TruFlow handle
356 * Pointer to input parameters
360 * -EINVAL - Parameter error
362 int tf_em_ext_common_unbind(struct tf *tfp);
365 * Alloc for external EEM using host memory
368 * Pointer to TruFlow handle
371 * Pointer to input parameters
375 * -EINVAL - Parameter error
377 int tf_em_ext_alloc(struct tf *tfp,
378 struct tf_alloc_tbl_scope_parms *parms);
381 * Free for external EEM using host memory
384 * Pointer to TruFlow handle
387 * Pointer to input parameters
391 * -EINVAL - Parameter error
393 int tf_em_ext_free(struct tf *tfp,
394 struct tf_free_tbl_scope_parms *parms);
397 * Common free table scope for external EEM using host or system memory
400 * Pointer to TruFlow handle
403 * Pointer to input parameters
407 * -EINVAL - Parameter error
409 int tf_em_ext_common_free(struct tf *tfp,
410 struct tf_free_tbl_scope_parms *parms);
413 * Common alloc table scope for external EEM using host or system memory
416 * Pointer to TruFlow handle
419 * Pointer to input parameters
423 * -EINVAL - Parameter error
425 int tf_em_ext_common_alloc(struct tf *tfp,
426 struct tf_alloc_tbl_scope_parms *parms);
428 * Map a set of parifs to a set of EEM base addresses (table scope)
431 * Pointer to TruFlow handle
434 * Pointer to input parameters
438 * -EINVAL - Parameter error
440 int tf_em_ext_map_tbl_scope(struct tf *tfp,
441 struct tf_map_tbl_scope_parms *parms);
444 * Allocate External Tbl entry from the scope pool.
447 * Pointer to Truflow Handle
449 * Allocation parameters
452 * 0 - Success, entry allocated - no search support
453 * -ENOMEM -EINVAL -EOPNOTSUPP
454 * - Failure, entry not allocated, out of resources
457 tf_tbl_ext_alloc(struct tf *tfp,
458 struct tf_tbl_alloc_parms *parms);
461 * Free External Tbl entry to the scope pool.
464 * Pointer to Truflow Handle
466 * Allocation parameters
469 * 0 - Success, entry freed
471 * - Failure, entry not successfully freed for these reasons
477 tf_tbl_ext_free(struct tf *tfp,
478 struct tf_tbl_free_parms *parms);
481 * Sets the specified external table type element.
483 * This API sets the specified element data by invoking the
487 * Pointer to TF handle
490 * Pointer to table set parameters
493 * - (0) if successful.
494 * - (-EINVAL) on failure.
496 int tf_tbl_ext_common_set(struct tf *tfp,
497 struct tf_tbl_set_parms *parms);
500 * Sets the specified external table type element.
502 * This API sets the specified element data by invoking the
506 * Pointer to TF handle
509 * Pointer to table set parameters
512 * - (0) if successful.
513 * - (-EINVAL) on failure.
515 int tf_tbl_ext_set(struct tf *tfp,
516 struct tf_tbl_set_parms *parms);
519 tf_em_ext_system_bind(struct tf *tfp,
520 struct tf_em_cfg_parms *parms);
522 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
523 #endif /* _TF_EM_H_ */