1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
11 #include "tf_device.h"
15 /** RM return codes */
16 #define TF_RM_ALLOCATED_ENTRY_FREE 0
17 #define TF_RM_ALLOCATED_ENTRY_IN_USE 1
18 #define TF_RM_ALLOCATED_NO_ENTRY_FOUND -1
21 * The Resource Manager (RM) module provides basic DB handling for
22 * internal resources. These resources exists within the actual device
23 * and are controlled by the HCAPI Resource Manager running on the
26 * The RM DBs are all intended to be indexed using TF types there for
27 * a lookup requires no additional conversion. The DB configuration
28 * specifies the TF Type to HCAPI Type mapping and it becomes the
29 * responsibility of the DB initialization to handle this static
32 * Accessor functions are providing access to the DB, thus hiding the
35 * The RM DB will work on its initial allocated sizes so the
36 * capability of dynamically growing a particular resource is not
37 * possible. If this capability later becomes a requirement then the
38 * MAX pool size of the chip needs to be added to the tf_rm_elem_info
39 * structure and several new APIs would need to be added to allow for
40 * growth of a single TF resource type.
42 * The access functions do not check for NULL pointers as they are a
43 * support module, not called directly.
47 * Resource reservation single entry result. Used when accessing HCAPI
50 struct tf_rm_new_entry {
51 /** Starting index of the allocated resource */
53 /** Number of allocated elements */
58 * RM Element configuration enumeration. Used by the Device to
59 * indicate how the RM elements the DB consists off, are to be
60 * configured at time of DB creation. The TF may present types to the
61 * ULP layer that is not controlled by HCAPI within the Firmware.
63 enum tf_rm_elem_cfg_type {
68 /** HCAPI 'controlled', no RM storage so the module
69 * using the RM can chose to handle storage locally.
72 /** HCAPI 'controlled', uses a bit allocator pool for internal
75 TF_RM_ELEM_CFG_HCAPI_BA,
77 * HCAPI 'controlled', uses a bit allocator pool for internal
78 * storage in the RM but multiple TF types map to a single
79 * HCAPI type. Parent manages the table.
81 TF_RM_ELEM_CFG_HCAPI_BA_PARENT,
83 * HCAPI 'controlled', uses a bit allocator pool for internal
84 * storage in the RM but multiple TF types map to a single
85 * HCAPI type. Child accesses the parent db.
87 TF_RM_ELEM_CFG_HCAPI_BA_CHILD,
94 * RM Reservation strategy enumeration. Type of strategy comes from
95 * the HCAPI RM QCAPS handshake.
97 enum tf_rm_resc_resv_strategy {
98 TF_RM_RESC_RESV_STATIC_PARTITION,
99 TF_RM_RESC_RESV_STRATEGY_1,
100 TF_RM_RESC_RESV_STRATEGY_2,
101 TF_RM_RESC_RESV_STRATEGY_3,
106 * RM Element configuration structure, used by the Device to configure
107 * how an individual TF type is configured in regard to the HCAPI RM
110 struct tf_rm_element_cfg {
112 * RM Element config controls how the DB for that element is
115 enum tf_rm_elem_cfg_type cfg_type;
117 /* If a HCAPI to TF type conversion is required then TF type
122 * HCAPI RM Type for the element. Used for TF to HCAPI type
128 * if cfg_type == TF_RM_ELEM_CFG_HCAPI_BA_CHILD
130 * Parent Truflow module subtype associated with this resource type.
132 uint16_t parent_subtype;
135 * if cfg_type == TF_RM_ELEM_CFG_HCAPI_BA_CHILD
137 * Resource slices. How many slices will fit in the
138 * resource pool chunk size.
143 * Pool element divider count
144 * If 0 or 1, there is 1:1 correspondence between the RM
145 * BA pool resource element and the HCAPI RM firmware
146 * resource. If > 1, the RM BA pool element has a 1:n
147 * correspondence to the HCAPI RM firmware resource.
153 * Allocation information for a single element.
155 struct tf_rm_alloc_info {
157 * HCAPI RM allocated range information.
160 * In case of dynamic allocation support this would have
161 * to be changed to linked list of tf_rm_entry instead.
163 struct tf_rm_new_entry entry;
167 * Create RM DB parameters
169 struct tf_rm_create_db_parms {
171 * [in] Module type. Used for logging purposes.
173 enum tf_module_type module;
175 * [in] Receive or transmit direction.
179 * [in] Number of elements.
181 uint16_t num_elements;
183 * [in] Parameter structure array. Array size is num_elements.
185 struct tf_rm_element_cfg *cfg;
187 * Resource allocation count array. This array content
188 * originates from the tf_session_resources that is passed in
189 * on session open. Array size is num_elements.
199 * Free RM DB parameters
201 struct tf_rm_free_db_parms {
203 * [in] Receive or transmit direction
213 * Allocate RM parameters for a single element
215 struct tf_rm_allocate_parms {
221 * [in] Module subtype indicates which DB entry to perform the
222 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
223 * TF_MODULE_TYPE_TCAM)
227 * [in] Pointer to the allocated index in normalized
228 * form. Normalized means the index has been adjusted,
229 * i.e. Full Action Record offsets.
233 * [in] Priority, indicates the priority of the entry
234 * priority 0: allocate from top of the tcam (from index 0
235 * or lowest available index)
236 * priority !0: allocate from bottom of the tcam (from highest
241 * [in] Pointer to the allocated index before adjusted.
243 uint32_t *base_index;
247 * Free RM parameters for a single element
249 struct tf_rm_free_parms {
255 * [in] TF subtype indicates which DB entry to perform the
256 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
257 * TF_MODULE_TYPE_TCAM)
267 * Is Allocated parameters for a single element
269 struct tf_rm_is_allocated_parms {
275 * [in] TF subtype indicates which DB entry to perform the
276 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
277 * TF_MODULE_TYPE_TCAM)
285 * [in] Pointer to flag that indicates the state of the query
289 * [in] Pointer to the allocated index before adjusted.
291 uint32_t *base_index;
295 * Get Allocation information for a single element
297 struct tf_rm_get_alloc_info_parms {
303 * [in] TF subtype indicates which DB entry to perform the
304 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
305 * TF_MODULE_TYPE_TCAM)
309 * [out] Pointer to the requested allocation information for
310 * the specified subtype
312 struct tf_rm_alloc_info *info;
316 * Get HCAPI type parameters for a single element
318 struct tf_rm_get_hcapi_parms {
324 * [in] TF subtype indicates which DB entry to perform the
325 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
326 * TF_MODULE_TYPE_TCAM)
330 * [out] Pointer to the hcapi type for the specified subtype
332 uint16_t *hcapi_type;
336 * Get InUse count parameters for single element
338 struct tf_rm_get_inuse_count_parms {
344 * [in] TF subtype indicates which DB entry to perform the
345 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
346 * TF_MODULE_TYPE_TCAM)
350 * [out] Pointer to the inuse count for the specified subtype
356 * Check if the indexes are in the range of reserved resource
358 struct tf_rm_check_indexes_in_range_parms {
364 * [in] TF subtype indicates which DB entry to perform the
365 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
366 * TF_MODULE_TYPE_TCAM)
370 * [in] Starting index
372 uint16_t starting_index;
374 * [in] number of entries
376 uint16_t num_entries;
380 * @page rm Resource Manager
382 * @ref tf_rm_create_db
386 * @ref tf_rm_allocate
390 * @ref tf_rm_is_allocated
392 * @ref tf_rm_get_info
394 * @ref tf_rm_get_hcapi_type
396 * @ref tf_rm_get_inuse_count
400 * Creates and fills a Resource Manager (RM) DB with requested
401 * elements. The DB is indexed per the parms structure.
404 * Pointer to TF handle, used for HCAPI communication
407 * Pointer to create parameters
410 * - (0) if successful.
411 * - (-EINVAL) on failure.
415 * - Fail on parameter check
416 * - Fail on DB creation, i.e. alloc amount is not possible or validation fails
417 * - Fail on DB creation if DB already exist
421 * - Does hcapi reservation
422 * - Populates the pool with allocated elements
423 * - Returns handle to the created DB
425 int tf_rm_create_db(struct tf *tfp,
426 struct tf_rm_create_db_parms *parms);
429 * Creates and fills a Resource Manager (RM) DB with requested
430 * elements. The DB is indexed per the parms structure. It only retrieve
431 * allocated resource information for a exist session.
434 * Pointer to TF handle, used for HCAPI communication
437 * Pointer to create parameters
440 * - (0) if successful.
441 * - (-EINVAL) on failure.
443 int tf_rm_create_db_no_reservation(struct tf *tfp,
444 struct tf_rm_create_db_parms *parms);
447 * Closes the Resource Manager (RM) DB and frees all allocated
448 * resources per the associated database.
451 * Pointer to TF handle, used for HCAPI communication
454 * Pointer to free parameters
457 * - (0) if successful.
458 * - (-EINVAL) on failure.
460 int tf_rm_free_db(struct tf *tfp,
461 struct tf_rm_free_db_parms *parms);
464 * Allocates a single element for the type specified, within the DB.
467 * Pointer to allocate parameters
470 * - (0) if successful.
471 * - (-EINVAL) on failure.
472 * - (-ENOMEM) if pool is empty
474 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
477 * Free's a single element for the type specified, within the DB.
480 * Pointer to free parameters
483 * - (0) if successful.
484 * - (-EINVAL) on failure.
486 int tf_rm_free(struct tf_rm_free_parms *parms);
489 * Performs an allocation verification check on a specified element.
492 * Pointer to is allocated parameters
495 * - (0) if successful.
496 * - (-EINVAL) on failure.
500 * - If pool is set to Chip MAX, then the query index must be checked
501 * against the allocated range and query index must be allocated as well.
502 * - If pool is allocated size only, then check if query index is allocated.
504 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
507 * Retrieves an elements allocation information from the Resource
511 * Pointer to get info parameters
514 * - (0) if successful.
515 * - (-EINVAL) on failure.
517 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
520 * Retrieves all elements allocation information from the Resource
524 * Pointer to get info parameters
527 * number of the elements for the specific module
530 * - (0) if successful.
531 * - (-EINVAL) on failure.
533 int tf_rm_get_all_info(struct tf_rm_get_alloc_info_parms *parms, int size);
536 * Performs a lookup in the Resource Manager DB and retrieves the
537 * requested HCAPI RM type.
540 * Pointer to get hcapi parameters
543 * - (0) if successful.
544 * - (-EINVAL) on failure.
546 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
549 * Performs a lookup in the Resource Manager DB and retrieves the
550 * requested HCAPI RM type inuse count.
553 * Pointer to get inuse parameters
556 * - (0) if successful.
557 * - (-EINVAL) on failure.
559 int tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms);
562 * Check if the requested indexes are in the range of reserved resource.
565 * Pointer to get inuse parameters
568 * - (0) if successful.
569 * - (-EINVAL) on failure.
572 tf_rm_check_indexes_in_range(struct tf_rm_check_indexes_in_range_parms *parms);
575 #endif /* TF_RM_NEW_H_ */