a652afdcbfc90d5237cb4059b99ddd8cb942748c
[dpdk.git] / drivers / net / bnxt / tf_core / tf_rm_new.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef TF_RM_H_
7 #define TF_RM_H_
8
9 #include "tf_core.h"
10 #include "bitalloc.h"
11
12 struct tf;
13
14 /**
15  * The Resource Manager (RM) module provides basic DB handling for
16  * internal resources. These resources exists within the actual device
17  * and are controlled by the HCAPI Resource Manager running on the
18  * firmware.
19  *
20  * The RM DBs are all intended to be indexed using TF types there for
21  * a lookup requires no additional conversion. The DB configuration
22  * specifies the TF Type to HCAPI Type mapping and it becomes the
23  * responsibility of the DB initialization to handle this static
24  * mapping.
25  *
26  * Accessor functions are providing access to the DB, thus hiding the
27  * implementation.
28  *
29  * The RM DB will work on its initial allocated sizes so the
30  * capability of dynamically growing a particular resource is not
31  * possible. If this capability later becomes a requirement then the
32  * MAX pool size of the Chip Å“needs to be added to the tf_rm_elem_info
33  * structure and several new APIs would need to be added to allow for
34  * growth of a single TF resource type.
35  */
36
37 /**
38  * Resource reservation single entry result. Used when accessing HCAPI
39  * RM on the firmware.
40  */
41 struct tf_rm_entry {
42         /** Starting index of the allocated resource */
43         uint16_t start;
44         /** Number of allocated elements */
45         uint16_t stride;
46 };
47
48 /**
49  * RM Element configuration enumeration. Used by the Device to
50  * indicate how the RM elements the DB consists off, are to be
51  * configured at time of DB creation. The TF may present types to the
52  * ULP layer that is not controlled by HCAPI within the Firmware.
53  */
54 enum tf_rm_elem_cfg_type {
55         TF_RM_ELEM_CFG_NULL,    /**< No configuration */
56         TF_RM_ELEM_CFG_HCAPI,   /**< HCAPI 'controlled' */
57         TF_RM_ELEM_CFG_PRIVATE, /**< Private thus not HCAPI 'controlled' */
58         TF_RM_TYPE_MAX
59 };
60
61 /**
62  * RM Element configuration structure, used by the Device to configure
63  * how an individual TF type is configured in regard to the HCAPI RM
64  * of same type.
65  */
66 struct tf_rm_element_cfg {
67         /**
68          * RM Element config controls how the DB for that element is
69          * processed.
70          */
71         enum tf_rm_elem_cfg_type cfg;
72
73         /* If a HCAPI to TF type conversion is required then TF type
74          * can be added here.
75          */
76
77         /**
78          * HCAPI RM Type for the element. Used for TF to HCAPI type
79          * conversion.
80          */
81         uint16_t hcapi_type;
82 };
83
84 /**
85  * Allocation information for a single element.
86  */
87 struct tf_rm_alloc_info {
88         /**
89          * HCAPI RM allocated range information.
90          *
91          * NOTE:
92          * In case of dynamic allocation support this would have
93          * to be changed to linked list of tf_rm_entry instead.
94          */
95         struct tf_rm_entry entry;
96 };
97
98 /**
99  * Create RM DB parameters
100  */
101 struct tf_rm_create_db_parms {
102         /**
103          * [in] Receive or transmit direction
104          */
105         enum tf_dir dir;
106         /**
107          * [in] Number of elements in the parameter structure
108          */
109         uint16_t num_elements;
110         /**
111          * [in] Parameter structure
112          */
113         struct tf_rm_element_cfg *parms;
114         /**
115          * [out] RM DB Handle
116          */
117         void *tf_rm_db;
118 };
119
120 /**
121  * Free RM DB parameters
122  */
123 struct tf_rm_free_db_parms {
124         /**
125          * [in] Receive or transmit direction
126          */
127         enum tf_dir dir;
128         /**
129          * [in] RM DB Handle
130          */
131         void *tf_rm_db;
132 };
133
134 /**
135  * Allocate RM parameters for a single element
136  */
137 struct tf_rm_allocate_parms {
138         /**
139          * [in] RM DB Handle
140          */
141         void *tf_rm_db;
142         /**
143          * [in] DB Index, indicates which DB entry to perform the
144          * action on.
145          */
146         uint16_t db_index;
147         /**
148          * [in] Pointer to the allocated index in normalized
149          * form. Normalized means the index has been adjusted,
150          * i.e. Full Action Record offsets.
151          */
152         uint32_t *index;
153 };
154
155 /**
156  * Free RM parameters for a single element
157  */
158 struct tf_rm_free_parms {
159         /**
160          * [in] RM DB Handle
161          */
162         void *tf_rm_db;
163         /**
164          * [in] DB Index, indicates which DB entry to perform the
165          * action on.
166          */
167         uint16_t db_index;
168         /**
169          * [in] Index to free
170          */
171         uint32_t index;
172 };
173
174 /**
175  * Is Allocated parameters for a single element
176  */
177 struct tf_rm_is_allocated_parms {
178         /**
179          * [in] RM DB Handle
180          */
181         void *tf_rm_db;
182         /**
183          * [in] DB Index, indicates which DB entry to perform the
184          * action on.
185          */
186         uint16_t db_index;
187         /**
188          * [in] Index to free
189          */
190         uint32_t index;
191         /**
192          * [in] Pointer to flag that indicates the state of the query
193          */
194         uint8_t *allocated;
195 };
196
197 /**
198  * Get Allocation information for a single element
199  */
200 struct tf_rm_get_alloc_info_parms {
201         /**
202          * [in] RM DB Handle
203          */
204         void *tf_rm_db;
205         /**
206          * [in] DB Index, indicates which DB entry to perform the
207          * action on.
208          */
209         uint16_t db_index;
210         /**
211          * [out] Pointer to the requested allocation information for
212          * the specified db_index
213          */
214         struct tf_rm_alloc_info *info;
215 };
216
217 /**
218  * Get HCAPI type parameters for a single element
219  */
220 struct tf_rm_get_hcapi_parms {
221         /**
222          * [in] RM DB Handle
223          */
224         void *tf_rm_db;
225         /**
226          * [in] DB Index, indicates which DB entry to perform the
227          * action on.
228          */
229         uint16_t db_index;
230         /**
231          * [out] Pointer to the hcapi type for the specified db_index
232          */
233         uint16_t *hcapi_type;
234 };
235
236 /**
237  * @page rm Resource Manager
238  *
239  * @ref tf_rm_create_db
240  *
241  * @ref tf_rm_free_db
242  *
243  * @ref tf_rm_allocate
244  *
245  * @ref tf_rm_free
246  *
247  * @ref tf_rm_is_allocated
248  *
249  * @ref tf_rm_get_info
250  *
251  * @ref tf_rm_get_hcapi_type
252  */
253
254 /**
255  * Creates and fills a Resource Manager (RM) DB with requested
256  * elements. The DB is indexed per the parms structure.
257  *
258  * [in] tfp
259  *   Pointer to TF handle, used for HCAPI communication
260  *
261  * [in] parms
262  *   Pointer to create parameters
263  *
264  * Returns
265  *   - (0) if successful.
266  *   - (-EINVAL) on failure.
267  */
268 /*
269  * NOTE:
270  * - Fail on parameter check
271  * - Fail on DB creation, i.e. alloc amount is not possible or validation fails
272  * - Fail on DB creation if DB already exist
273  *
274  * - Allocs local DB
275  * - Does hcapi qcaps
276  * - Does hcapi reservation
277  * - Populates the pool with allocated elements
278  * - Returns handle to the created DB
279  */
280 int tf_rm_create_db(struct tf *tfp,
281                     struct tf_rm_create_db_parms *parms);
282
283 /**
284  * Closes the Resource Manager (RM) DB and frees all allocated
285  * resources per the associated database.
286  *
287  * [in] tfp
288  *   Pointer to TF handle, used for HCAPI communication
289  *
290  * [in] parms
291  *   Pointer to free parameters
292  *
293  * Returns
294  *   - (0) if successful.
295  *   - (-EINVAL) on failure.
296  */
297 int tf_rm_free_db(struct tf *tfp,
298                   struct tf_rm_free_db_parms *parms);
299
300 /**
301  * Allocates a single element for the type specified, within the DB.
302  *
303  * [in] parms
304  *   Pointer to allocate parameters
305  *
306  * Returns
307  *   - (0) if successful.
308  *   - (-EINVAL) on failure.
309  */
310 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
311
312 /**
313  * Free's a single element for the type specified, within the DB.
314  *
315  * [in] parms
316  *   Pointer to free parameters
317  *
318  * Returns
319  *   - (0) if successful.
320  *   - (-EpINVAL) on failure.
321  */
322 int tf_rm_free(struct tf_rm_free_parms *parms);
323
324 /**
325  * Performs an allocation verification check on a specified element.
326  *
327  * [in] parms
328  *   Pointer to is allocated parameters
329  *
330  * Returns
331  *   - (0) if successful.
332  *   - (-EINVAL) on failure.
333  */
334 /*
335  * NOTE:
336  *  - If pool is set to Chip MAX, then the query index must be checked
337  *    against the allocated range and query index must be allocated as well.
338  *  - If pool is allocated size only, then check if query index is allocated.
339  */
340 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
341
342 /**
343  * Retrieves an elements allocation information from the Resource
344  * Manager (RM) DB.
345  *
346  * [in] parms
347  *   Pointer to get info parameters
348  *
349  * Returns
350  *   - (0) if successful.
351  *   - (-EINVAL) on failure.
352  */
353 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
354
355 /**
356  * Performs a lookup in the Resource Manager DB and retrieves the
357  * requested HCAPI type.
358  *
359  * [in] parms
360  *   Pointer to get hcapi parameters
361  *
362  * Returns
363  *   - (0) if successful.
364  *   - (-EINVAL) on failure.
365  */
366 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
367
368 #endif /* TF_RM_H_ */