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.
48 * RM Element configuration enumeration. Used by the Device to
49 * indicate how the RM elements the DB consists off, are to be
50 * configured at time of DB creation. The TF may present types to the
51 * ULP layer that is not controlled by HCAPI within the Firmware.
53 enum tf_rm_elem_cfg_type {
58 /** HCAPI 'controlled', no RM storage so the module
59 * using the RM can chose to handle storage locally.
62 /** HCAPI 'controlled', uses a bit allocator pool for internal
65 TF_RM_ELEM_CFG_HCAPI_BA,
67 * HCAPI 'controlled', uses a bit allocator pool for internal
68 * storage in the RM but multiple TF types map to a single
69 * HCAPI type. Parent manages the table.
71 TF_RM_ELEM_CFG_HCAPI_BA_PARENT,
73 * HCAPI 'controlled', uses a bit allocator pool for internal
74 * storage in the RM but multiple TF types map to a single
75 * HCAPI type. Child accesses the parent db.
77 TF_RM_ELEM_CFG_HCAPI_BA_CHILD,
84 * RM Reservation strategy enumeration. Type of strategy comes from
85 * the HCAPI RM QCAPS handshake.
87 enum tf_rm_resc_resv_strategy {
88 TF_RM_RESC_RESV_STATIC_PARTITION,
89 TF_RM_RESC_RESV_STRATEGY_1,
90 TF_RM_RESC_RESV_STRATEGY_2,
91 TF_RM_RESC_RESV_STRATEGY_3,
96 * RM Element configuration structure, used by the Device to configure
97 * how an individual TF type is configured in regard to the HCAPI RM
100 struct tf_rm_element_cfg {
102 * RM Element config controls how the DB for that element is
105 enum tf_rm_elem_cfg_type cfg_type;
108 * HCAPI RM Type for the element. Used for TF to HCAPI type
114 * if cfg_type == TF_RM_ELEM_CFG_HCAPI_BA_CHILD/PARENT
116 * Parent Truflow module subtype associated with this resource type.
118 uint16_t parent_subtype;
121 * if cfg_type == TF_RM_ELEM_CFG_HCAPI_BA_CHILD/PARENT
123 * Resource slices. How many slices will fit in the
124 * resource pool chunk size.
130 * Allocation information for a single element.
132 struct tf_rm_alloc_info {
134 * HCAPI RM allocated range information.
137 * In case of dynamic allocation support this would have
138 * to be changed to linked list of tf_rm_entry instead.
140 struct tf_resource_info entry;
144 * Create RM DB parameters
146 struct tf_rm_create_db_parms {
148 * [in] Module type. Used for logging purposes.
150 enum tf_module_type module;
152 * [in] Receive or transmit direction.
156 * [in] Number of elements.
158 uint16_t num_elements;
160 * [in] Parameter structure array. Array size is num_elements.
162 struct tf_rm_element_cfg *cfg;
164 * Resource allocation count array. This array content
165 * originates from the tf_session_resources that is passed in
166 * on session open. Array size is num_elements.
176 * Free RM DB parameters
178 struct tf_rm_free_db_parms {
180 * [in] Receive or transmit direction
190 * Allocate RM parameters for a single element
192 struct tf_rm_allocate_parms {
198 * [in] Module subtype indicates which DB entry to perform the
199 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
200 * TF_MODULE_TYPE_TCAM)
204 * [in] Pointer to the allocated index in normalized
205 * form. Normalized means the index has been adjusted,
206 * i.e. Full Action Record offsets.
210 * [in] Priority, indicates the priority of the entry
211 * priority 0: allocate from top of the tcam (from index 0
212 * or lowest available index)
213 * priority !0: allocate from bottom of the tcam (from highest
218 * [in] Pointer to the allocated index before adjusted.
220 uint32_t *base_index;
224 * Free RM parameters for a single element
226 struct tf_rm_free_parms {
232 * [in] TF subtype indicates which DB entry to perform the
233 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
234 * TF_MODULE_TYPE_TCAM)
244 * Is Allocated parameters for a single element
246 struct tf_rm_is_allocated_parms {
252 * [in] TF subtype indicates which DB entry to perform the
253 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
254 * TF_MODULE_TYPE_TCAM)
262 * [in] Pointer to flag that indicates the state of the query
266 * [in] Pointer to the allocated index before adjusted.
268 uint32_t *base_index;
272 * Get Allocation information for a single element
274 struct tf_rm_get_alloc_info_parms {
280 * [in] TF subtype indicates which DB entry to perform the
281 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
282 * TF_MODULE_TYPE_TCAM)
286 * [out] Pointer to the requested allocation information for
287 * the specified subtype
289 struct tf_rm_alloc_info *info;
293 * Get HCAPI type parameters for a single element
295 struct tf_rm_get_hcapi_parms {
301 * [in] TF subtype indicates which DB entry to perform the
302 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
303 * TF_MODULE_TYPE_TCAM)
307 * [out] Pointer to the hcapi type for the specified subtype
309 uint16_t *hcapi_type;
312 * Get Slices parameters for a single element
314 struct tf_rm_get_slices_parms {
320 * [in] TF subtype indicates which DB entry to perform the
321 * action on. (e.g. TF_TBL_TYPE_FULL_ACTION subtype of module
322 * TF_MODULE_TYPE_TABLE)
326 * [in/out] Pointer to number of slices for the given type
332 * Get InUse count parameters for single element
334 struct tf_rm_get_inuse_count_parms {
340 * [in] TF subtype indicates which DB entry to perform the
341 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
342 * TF_MODULE_TYPE_TCAM)
346 * [out] Pointer to the inuse count for the specified subtype
352 * Check if the indexes are in the range of reserved resource
354 struct tf_rm_check_indexes_in_range_parms {
360 * [in] TF subtype indicates which DB entry to perform the
361 * action on. (e.g. TF_TCAM_TBL_TYPE_L2_CTXT subtype of module
362 * TF_MODULE_TYPE_TCAM)
366 * [in] Starting index
368 uint16_t starting_index;
370 * [in] number of entries
372 uint16_t num_entries;
376 * @page rm Resource Manager
378 * @ref tf_rm_create_db
382 * @ref tf_rm_allocate
386 * @ref tf_rm_is_allocated
388 * @ref tf_rm_get_info
390 * @ref tf_rm_get_hcapi_type
392 * @ref tf_rm_get_inuse_count
394 * @ref tf_rm_get_slice_size
398 * Creates and fills a Resource Manager (RM) DB with requested
399 * elements. The DB is indexed per the parms structure.
402 * Pointer to TF handle, used for HCAPI communication
405 * Pointer to create parameters
408 * - (0) if successful.
409 * - (-EINVAL) on failure.
413 * - Fail on parameter check
414 * - Fail on DB creation, i.e. alloc amount is not possible or validation fails
415 * - Fail on DB creation if DB already exist
419 * - Does hcapi reservation
420 * - Populates the pool with allocated elements
421 * - Returns handle to the created DB
423 int tf_rm_create_db(struct tf *tfp,
424 struct tf_rm_create_db_parms *parms);
427 * Creates and fills a Resource Manager (RM) DB with requested
428 * elements. The DB is indexed per the parms structure. It only retrieve
429 * allocated resource information for a exist session.
432 * Pointer to TF handle, used for HCAPI communication
435 * Pointer to create parameters
438 * - (0) if successful.
439 * - (-EINVAL) on failure.
441 int tf_rm_create_db_no_reservation(struct tf *tfp,
442 struct tf_rm_create_db_parms *parms);
445 * Closes the Resource Manager (RM) DB and frees all allocated
446 * resources per the associated database.
449 * Pointer to TF handle, used for HCAPI communication
452 * Pointer to free parameters
455 * - (0) if successful.
456 * - (-EINVAL) on failure.
458 int tf_rm_free_db(struct tf *tfp,
459 struct tf_rm_free_db_parms *parms);
462 * Allocates a single element for the type specified, within the DB.
465 * Pointer to allocate parameters
468 * - (0) if successful.
469 * - (-EINVAL) on failure.
470 * - (-ENOMEM) if pool is empty
472 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
475 * Free's a single element for the type specified, within the DB.
478 * Pointer to free parameters
481 * - (0) if successful.
482 * - (-EINVAL) on failure.
484 int tf_rm_free(struct tf_rm_free_parms *parms);
487 * Performs an allocation verification check on a specified element.
490 * Pointer to is allocated parameters
493 * - (0) if successful.
494 * - (-EINVAL) on failure.
498 * - If pool is set to Chip MAX, then the query index must be checked
499 * against the allocated range and query index must be allocated as well.
500 * - If pool is allocated size only, then check if query index is allocated.
502 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
505 * Retrieves an elements allocation information from the Resource
509 * Pointer to get info parameters
512 * - (0) if successful.
513 * - (-EINVAL) on failure.
515 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
518 * Retrieves all elements allocation information from the Resource
522 * Pointer to get info parameters
525 * number of the elements for the specific module
528 * - (0) if successful.
529 * - (-EINVAL) on failure.
531 int tf_rm_get_all_info(struct tf_rm_get_alloc_info_parms *parms, int size);
534 * Performs a lookup in the Resource Manager DB and retrieves the
535 * requested HCAPI RM type.
538 * Pointer to get hcapi parameters
541 * - (0) if successful.
542 * - (-EINVAL) on failure.
544 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
547 * Performs a lookup in the Resource Manager DB and retrieves the
548 * requested HCAPI RM type inuse count.
551 * Pointer to get inuse parameters
554 * - (0) if successful.
555 * - (-EINVAL) on failure.
557 int tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms);
560 * Check if the requested indexes are in the range of reserved resource.
563 * Pointer to get inuse parameters
566 * - (0) if successful.
567 * - (-EINVAL) on failure.
570 tf_rm_check_indexes_in_range(struct tf_rm_check_indexes_in_range_parms *parms);
573 * Get the number of slices per resource bit allocator for the resource type
576 * Pointer to get inuse parameters
579 * - (0) if successful.
580 * - (-EINVAL) on failure.
583 tf_rm_get_slices(struct tf_rm_get_slices_parms *parms);
585 #endif /* TF_RM_NEW_H_ */