1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
11 #include "tf_device.h"
16 * The Resource Manager (RM) module provides basic DB handling for
17 * internal resources. These resources exists within the actual device
18 * and are controlled by the HCAPI Resource Manager running on the
21 * The RM DBs are all intended to be indexed using TF types there for
22 * a lookup requires no additional conversion. The DB configuration
23 * specifies the TF Type to HCAPI Type mapping and it becomes the
24 * responsibility of the DB initialization to handle this static
27 * Accessor functions are providing access to the DB, thus hiding the
30 * The RM DB will work on its initial allocated sizes so the
31 * capability of dynamically growing a particular resource is not
32 * possible. If this capability later becomes a requirement then the
33 * MAX pool size of the Chip Å“needs to be added to the tf_rm_elem_info
34 * structure and several new APIs would need to be added to allow for
35 * growth of a single TF resource type.
37 * The access functions does not check for NULL pointers as it's a
38 * support module, not called directly.
42 * Resource reservation single entry result. Used when accessing HCAPI
45 struct tf_rm_new_entry {
46 /** Starting index of the allocated resource */
48 /** Number of allocated elements */
53 * RM Element configuration enumeration. Used by the Device to
54 * indicate how the RM elements the DB consists off, are to be
55 * configured at time of DB creation. The TF may present types to the
56 * ULP layer that is not controlled by HCAPI within the Firmware.
58 enum tf_rm_elem_cfg_type {
63 /** HCAPI 'controlled', no RM storage thus the Device Module
64 * using the RM can chose to handle storage locally.
67 /** HCAPI 'controlled', uses a Bit Allocator Pool for internal
70 TF_RM_ELEM_CFG_HCAPI_BA,
72 * Shared element thus it belongs to a shared FW Session and
73 * is not controlled by the Host.
75 TF_RM_ELEM_CFG_SHARED,
80 * RM Reservation strategy enumeration. Type of strategy comes from
81 * the HCAPI RM QCAPS handshake.
83 enum tf_rm_resc_resv_strategy {
84 TF_RM_RESC_RESV_STATIC_PARTITION,
85 TF_RM_RESC_RESV_STRATEGY_1,
86 TF_RM_RESC_RESV_STRATEGY_2,
87 TF_RM_RESC_RESV_STRATEGY_3,
92 * RM Element configuration structure, used by the Device to configure
93 * how an individual TF type is configured in regard to the HCAPI RM
96 struct tf_rm_element_cfg {
98 * RM Element config controls how the DB for that element is
101 enum tf_rm_elem_cfg_type cfg_type;
103 /* If a HCAPI to TF type conversion is required then TF type
108 * HCAPI RM Type for the element. Used for TF to HCAPI type
115 * Allocation information for a single element.
117 struct tf_rm_alloc_info {
119 * HCAPI RM allocated range information.
122 * In case of dynamic allocation support this would have
123 * to be changed to linked list of tf_rm_entry instead.
125 struct tf_rm_new_entry entry;
129 * Create RM DB parameters
131 struct tf_rm_create_db_parms {
133 * [in] Device module type. Used for logging purposes.
135 enum tf_device_module_type type;
137 * [in] Receive or transmit direction.
141 * [in] Number of elements.
143 uint16_t num_elements;
145 * [in] Parameter structure array. Array size is num_elements.
147 struct tf_rm_element_cfg *cfg;
149 * Resource allocation count array. This array content
150 * originates from the tf_session_resources that is passed in
152 * Array size is num_elements.
162 * Free RM DB parameters
164 struct tf_rm_free_db_parms {
166 * [in] Receive or transmit direction
176 * Allocate RM parameters for a single element
178 struct tf_rm_allocate_parms {
184 * [in] DB Index, indicates which DB entry to perform the
189 * [in] Pointer to the allocated index in normalized
190 * form. Normalized means the index has been adjusted,
191 * i.e. Full Action Record offsets.
195 * [in] Priority, indicates the priority of the entry
196 * priority 0: allocate from top of the tcam (from index 0
197 * or lowest available index)
198 * priority !0: allocate from bottom of the tcam (from highest
205 * Free RM parameters for a single element
207 struct tf_rm_free_parms {
213 * [in] DB Index, indicates which DB entry to perform the
224 * Is Allocated parameters for a single element
226 struct tf_rm_is_allocated_parms {
232 * [in] DB Index, indicates which DB entry to perform the
241 * [in] Pointer to flag that indicates the state of the query
247 * Get Allocation information for a single element
249 struct tf_rm_get_alloc_info_parms {
255 * [in] DB Index, indicates which DB entry to perform the
260 * [out] Pointer to the requested allocation information for
261 * the specified db_index
263 struct tf_rm_alloc_info *info;
267 * Get HCAPI type parameters for a single element
269 struct tf_rm_get_hcapi_parms {
275 * [in] DB Index, indicates which DB entry to perform the
280 * [out] Pointer to the hcapi type for the specified db_index
282 uint16_t *hcapi_type;
286 * Get InUse count parameters for single element
288 struct tf_rm_get_inuse_count_parms {
294 * [in] DB Index, indicates which DB entry to perform the
299 * [out] Pointer to the inuse count for the specified db_index
305 * @page rm Resource Manager
307 * @ref tf_rm_create_db
311 * @ref tf_rm_allocate
315 * @ref tf_rm_is_allocated
317 * @ref tf_rm_get_info
319 * @ref tf_rm_get_hcapi_type
321 * @ref tf_rm_get_inuse_count
325 * Creates and fills a Resource Manager (RM) DB with requested
326 * elements. The DB is indexed per the parms structure.
329 * Pointer to TF handle, used for HCAPI communication
332 * Pointer to create parameters
335 * - (0) if successful.
336 * - (-EINVAL) on failure.
340 * - Fail on parameter check
341 * - Fail on DB creation, i.e. alloc amount is not possible or validation fails
342 * - Fail on DB creation if DB already exist
346 * - Does hcapi reservation
347 * - Populates the pool with allocated elements
348 * - Returns handle to the created DB
350 int tf_rm_create_db(struct tf *tfp,
351 struct tf_rm_create_db_parms *parms);
354 * Closes the Resource Manager (RM) DB and frees all allocated
355 * resources per the associated database.
358 * Pointer to TF handle, used for HCAPI communication
361 * Pointer to free parameters
364 * - (0) if successful.
365 * - (-EINVAL) on failure.
367 int tf_rm_free_db(struct tf *tfp,
368 struct tf_rm_free_db_parms *parms);
371 * Allocates a single element for the type specified, within the DB.
374 * Pointer to allocate parameters
377 * - (0) if successful.
378 * - (-EINVAL) on failure.
379 * - (-ENOMEM) if pool is empty
381 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
384 * Free's a single element for the type specified, within the DB.
387 * Pointer to free parameters
390 * - (0) if successful.
391 * - (-EINVAL) on failure.
393 int tf_rm_free(struct tf_rm_free_parms *parms);
396 * Performs an allocation verification check on a specified element.
399 * Pointer to is allocated parameters
402 * - (0) if successful.
403 * - (-EINVAL) on failure.
407 * - If pool is set to Chip MAX, then the query index must be checked
408 * against the allocated range and query index must be allocated as well.
409 * - If pool is allocated size only, then check if query index is allocated.
411 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
414 * Retrieves an elements allocation information from the Resource
418 * Pointer to get info parameters
421 * - (0) if successful.
422 * - (-EINVAL) on failure.
424 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
427 * Performs a lookup in the Resource Manager DB and retrieves the
428 * requested HCAPI RM type.
431 * Pointer to get hcapi parameters
434 * - (0) if successful.
435 * - (-EINVAL) on failure.
437 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
440 * Performs a lookup in the Resource Manager DB and retrieves the
441 * requested HCAPI RM type inuse count.
444 * Pointer to get inuse parameters
447 * - (0) if successful.
448 * - (-EINVAL) on failure.
450 int tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms);
452 #endif /* TF_RM_NEW_H_ */