1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
9 #include "tf_resources.h"
16 /* Internal macro to determine appropriate allocation pools based on
17 * DIRECTION parm, also performs error checking for DIRECTION parm. The
18 * SESSION_POOL and SESSION pointers are set appropriately upon
19 * successful return (the GLOBAL_POOL is used to globally manage
20 * resource allocation and the SESSION_POOL is used to track the
21 * resources that have been allocated to the session)
25 * enum tf_dir direction
26 * struct bitalloc **session_pool
27 * string base_pool_name - used to form pointers to the
28 * appropriate bit allocation
29 * pools, both directions of the
30 * session pools must have same
31 * base name, for example if
32 * POOL_NAME is feat_pool: - the
33 * ptr's to the session pools
34 * are feat_pool_rx feat_pool_tx
36 * int rc - return code
38 * -1 - invalid DIRECTION parm
40 #define TF_RM_GET_POOLS(tfs, direction, session_pool, pool_name, rc) do { \
42 if ((direction) == TF_DIR_RX) { \
43 *(session_pool) = (tfs)->pool_name ## _RX; \
44 } else if ((direction) == TF_DIR_TX) { \
45 *(session_pool) = (tfs)->pool_name ## _TX; \
51 #define TF_RM_GET_POOLS_RX(tfs, session_pool, pool_name) \
52 (*(session_pool) = (tfs)->pool_name ## _RX)
54 #define TF_RM_GET_POOLS_TX(tfs, session_pool, pool_name) \
55 (*(session_pool) = (tfs)->pool_name ## _TX)
58 * Resource query single entry
60 struct tf_rm_query_entry {
61 /** Minimum guaranteed number of elements */
63 /** Maximum non-guaranteed number of elements */
68 * Resource single entry
71 /** Starting index of the allocated resource */
73 /** Number of allocated elements */
78 * Resource query array of HW entities
80 struct tf_rm_hw_query {
81 /** array of HW resource entries */
82 struct tf_rm_query_entry hw_query[TF_RESC_TYPE_HW_MAX];
86 * Resource allocation array of HW entities
88 struct tf_rm_hw_alloc {
89 /** array of HW resource entries */
90 uint16_t hw_num[TF_RESC_TYPE_HW_MAX];
94 * Resource query array of SRAM entities
96 struct tf_rm_sram_query {
97 /** array of SRAM resource entries */
98 struct tf_rm_query_entry sram_query[TF_RESC_TYPE_SRAM_MAX];
102 * Resource allocation array of SRAM entities
104 struct tf_rm_sram_alloc {
105 /** array of SRAM resource entries */
106 uint16_t sram_num[TF_RESC_TYPE_SRAM_MAX];
110 * Resource Manager arrays for a single direction
113 /** array of HW resource entries */
114 struct tf_rm_entry hw_entry[TF_RESC_TYPE_HW_MAX];
115 /** array of SRAM resource entries */
116 struct tf_rm_entry sram_entry[TF_RESC_TYPE_SRAM_MAX];
120 * Resource Manager Database
123 struct tf_rm_resc rx;
124 struct tf_rm_resc tx;
128 * Helper function converting direction to text string
131 *tf_dir_2_str(enum tf_dir dir);
134 * Helper function converting identifier to text string
137 *tf_ident_2_str(enum tf_identifier_type id_type);
140 * Helper function converting tcam type to text string
143 *tf_tcam_tbl_2_str(enum tf_tcam_tbl_type tcam_type);
146 * Helper function used to convert HW HCAPI resource type to a string.
149 *tf_hcapi_hw_2_str(enum tf_resource_type_hw hw_type);
152 * Helper function used to convert SRAM HCAPI resource type to a string.
155 *tf_hcapi_sram_2_str(enum tf_resource_type_sram sram_type);
158 * Initializes the Resource Manager and the associated database
159 * entries for HW and SRAM resources. Must be called before any other
160 * Resource Manager functions.
163 * Pointer to TF handle
165 void tf_rm_init(struct tf *tfp);
168 * Allocates and validates both HW and SRAM resources per the NVM
169 * configuration. If any allocation fails all resources for the
170 * session is deallocated.
173 * Pointer to TF handle
176 * - (0) if successful.
177 * - (-EINVAL) on failure.
179 int tf_rm_allocate_validate(struct tf *tfp);
182 * Closes the Resource Manager and frees all allocated resources per
183 * the associated database.
186 * Pointer to TF handle
189 * - (0) if successful.
190 * - (-EINVAL) on failure.
191 * - (-ENOTEMPTY) if resources are not cleaned up before close
193 int tf_rm_close(struct tf *tfp);
197 * Initializes Shadow DB of configuration elements
200 * Pointer to TF Session
205 int tf_rm_shadow_db_init(struct tf_session *tfs);
206 #endif /* TF_SHADOW */
209 * Perform a Session Pool lookup using the Tcam table type.
211 * Function will print error msg if tcam type is unsupported or lookup
215 * Pointer to TF Session
221 * Receive or transmit direction
223 * [in/out] session_pool
227 * 0 - Success will set the **pool
228 * -EOPNOTSUPP - Type is not supported
231 tf_rm_lookup_tcam_type_pool(struct tf_session *tfs,
233 enum tf_tcam_tbl_type type,
234 struct bitalloc **pool);
237 * Perform a Session Pool lookup using the Table type.
239 * Function will print error msg if table type is unsupported or
243 * Pointer to TF Session
249 * Receive or transmit direction
251 * [in/out] session_pool
255 * 0 - Success will set the **pool
256 * -EOPNOTSUPP - Type is not supported
259 tf_rm_lookup_tbl_type_pool(struct tf_session *tfs,
261 enum tf_tbl_type type,
262 struct bitalloc **pool);
265 * Converts the TF Table Type to internal HCAPI_TYPE
268 * Type to be converted
270 * [in/out] hcapi_type
274 * 0 - Success will set the *hcapi_type
275 * -EOPNOTSUPP - Type is not supported
278 tf_rm_convert_tbl_type(enum tf_tbl_type type,
279 uint32_t *hcapi_type);
282 * TF RM Convert of index methods.
284 enum tf_rm_convert_type {
285 /** Adds the base of the Session Pool to the index */
286 TF_RM_CONVERT_ADD_BASE,
287 /** Removes the Session Pool base from the index */
288 TF_RM_CONVERT_RM_BASE
292 * Provides conversion of the Table Type index in relation to the
296 * Pointer to TF Session
299 * Receive or transmit direction
305 * Type of conversion to perform
308 * Index to be converted
310 * [in/out] convert_index
311 * Pointer to the converted index
314 tf_rm_convert_index(struct tf_session *tfs,
316 enum tf_tbl_type type,
317 enum tf_rm_convert_type c_type,
319 uint32_t *convert_index);
321 #endif /* TF_RM_H_ */