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 {
59 /** No configuration */
61 /** HCAPI 'controlled', uses a Pool for internal storage */
63 /** Private thus not HCAPI 'controlled', creates a Pool for storage */
64 TF_RM_ELEM_CFG_PRIVATE,
66 * Shared element thus it belongs to a shared FW Session and
67 * is not controlled by the Host.
69 TF_RM_ELEM_CFG_SHARED,
74 * RM Reservation strategy enumeration. Type of strategy comes from
75 * the HCAPI RM QCAPS handshake.
77 enum tf_rm_resc_resv_strategy {
78 TF_RM_RESC_RESV_STATIC_PARTITION,
79 TF_RM_RESC_RESV_STRATEGY_1,
80 TF_RM_RESC_RESV_STRATEGY_2,
81 TF_RM_RESC_RESV_STRATEGY_3,
86 * RM Element configuration structure, used by the Device to configure
87 * how an individual TF type is configured in regard to the HCAPI RM
90 struct tf_rm_element_cfg {
92 * RM Element config controls how the DB for that element is
95 enum tf_rm_elem_cfg_type cfg_type;
97 /* If a HCAPI to TF type conversion is required then TF type
102 * HCAPI RM Type for the element. Used for TF to HCAPI type
109 * Allocation information for a single element.
111 struct tf_rm_alloc_info {
113 * HCAPI RM allocated range information.
116 * In case of dynamic allocation support this would have
117 * to be changed to linked list of tf_rm_entry instead.
119 struct tf_rm_new_entry entry;
123 * Create RM DB parameters
125 struct tf_rm_create_db_parms {
127 * [in] Device module type. Used for logging purposes.
129 enum tf_device_module_type type;
131 * [in] Receive or transmit direction.
135 * [in] Number of elements.
137 uint16_t num_elements;
139 * [in] Parameter structure array. Array size is num_elements.
141 struct tf_rm_element_cfg *cfg;
143 * Resource allocation count array. This array content
144 * originates from the tf_session_resources that is passed in
146 * Array size is num_elements.
156 * Free RM DB parameters
158 struct tf_rm_free_db_parms {
160 * [in] Receive or transmit direction
170 * Allocate RM parameters for a single element
172 struct tf_rm_allocate_parms {
178 * [in] DB Index, indicates which DB entry to perform the
183 * [in] Pointer to the allocated index in normalized
184 * form. Normalized means the index has been adjusted,
185 * i.e. Full Action Record offsets.
189 * [in] Priority, indicates the priority of the entry
190 * priority 0: allocate from top of the tcam (from index 0
191 * or lowest available index)
192 * priority !0: allocate from bottom of the tcam (from highest
199 * Free RM parameters for a single element
201 struct tf_rm_free_parms {
207 * [in] DB Index, indicates which DB entry to perform the
218 * Is Allocated parameters for a single element
220 struct tf_rm_is_allocated_parms {
226 * [in] DB Index, indicates which DB entry to perform the
235 * [in] Pointer to flag that indicates the state of the query
241 * Get Allocation information for a single element
243 struct tf_rm_get_alloc_info_parms {
249 * [in] DB Index, indicates which DB entry to perform the
254 * [out] Pointer to the requested allocation information for
255 * the specified db_index
257 struct tf_rm_alloc_info *info;
261 * Get HCAPI type parameters for a single element
263 struct tf_rm_get_hcapi_parms {
269 * [in] DB Index, indicates which DB entry to perform the
274 * [out] Pointer to the hcapi type for the specified db_index
276 uint16_t *hcapi_type;
280 * Get InUse count parameters for single element
282 struct tf_rm_get_inuse_count_parms {
288 * [in] DB Index, indicates which DB entry to perform the
293 * [out] Pointer to the inuse count for the specified db_index
299 * @page rm Resource Manager
301 * @ref tf_rm_create_db
305 * @ref tf_rm_allocate
309 * @ref tf_rm_is_allocated
311 * @ref tf_rm_get_info
313 * @ref tf_rm_get_hcapi_type
315 * @ref tf_rm_get_inuse_count
319 * Creates and fills a Resource Manager (RM) DB with requested
320 * elements. The DB is indexed per the parms structure.
323 * Pointer to TF handle, used for HCAPI communication
326 * Pointer to create parameters
329 * - (0) if successful.
330 * - (-EINVAL) on failure.
334 * - Fail on parameter check
335 * - Fail on DB creation, i.e. alloc amount is not possible or validation fails
336 * - Fail on DB creation if DB already exist
340 * - Does hcapi reservation
341 * - Populates the pool with allocated elements
342 * - Returns handle to the created DB
344 int tf_rm_create_db(struct tf *tfp,
345 struct tf_rm_create_db_parms *parms);
348 * Closes the Resource Manager (RM) DB and frees all allocated
349 * resources per the associated database.
352 * Pointer to TF handle, used for HCAPI communication
355 * Pointer to free parameters
358 * - (0) if successful.
359 * - (-EINVAL) on failure.
361 int tf_rm_free_db(struct tf *tfp,
362 struct tf_rm_free_db_parms *parms);
365 * Allocates a single element for the type specified, within the DB.
368 * Pointer to allocate parameters
371 * - (0) if successful.
372 * - (-EINVAL) on failure.
373 * - (-ENOMEM) if pool is empty
375 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
378 * Free's a single element for the type specified, within the DB.
381 * Pointer to free parameters
384 * - (0) if successful.
385 * - (-EINVAL) on failure.
387 int tf_rm_free(struct tf_rm_free_parms *parms);
390 * Performs an allocation verification check on a specified element.
393 * Pointer to is allocated parameters
396 * - (0) if successful.
397 * - (-EINVAL) on failure.
401 * - If pool is set to Chip MAX, then the query index must be checked
402 * against the allocated range and query index must be allocated as well.
403 * - If pool is allocated size only, then check if query index is allocated.
405 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
408 * Retrieves an elements allocation information from the Resource
412 * Pointer to get info parameters
415 * - (0) if successful.
416 * - (-EINVAL) on failure.
418 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
421 * Performs a lookup in the Resource Manager DB and retrieves the
422 * requested HCAPI RM type.
425 * Pointer to get hcapi parameters
428 * - (0) if successful.
429 * - (-EINVAL) on failure.
431 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
434 * Performs a lookup in the Resource Manager DB and retrieves the
435 * requested HCAPI RM type inuse count.
438 * Pointer to get inuse parameters
441 * - (0) if successful.
442 * - (-EINVAL) on failure.
444 int tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms);
446 #endif /* TF_RM_NEW_H_ */