net/bnxt: update multi device design
[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_NEW_H_
7 #define TF_RM_NEW_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  * The access functions does not check for NULL pointers as it's a
37  * support module, not called directly.
38  */
39
40 /**
41  * Resource reservation single entry result. Used when accessing HCAPI
42  * RM on the firmware.
43  */
44 struct tf_rm_new_entry {
45         /** Starting index of the allocated resource */
46         uint16_t start;
47         /** Number of allocated elements */
48         uint16_t stride;
49 };
50
51 /**
52  * RM Element configuration enumeration. Used by the Device to
53  * indicate how the RM elements the DB consists off, are to be
54  * configured at time of DB creation. The TF may present types to the
55  * ULP layer that is not controlled by HCAPI within the Firmware.
56  */
57 enum tf_rm_elem_cfg_type {
58         /** No configuration */
59         TF_RM_ELEM_CFG_NULL,
60         /** HCAPI 'controlled' */
61         TF_RM_ELEM_CFG_HCAPI,
62         /** Private thus not HCAPI 'controlled' */
63         TF_RM_ELEM_CFG_PRIVATE,
64         /**
65          * Shared element thus it belongs to a shared FW Session and
66          * is not controlled by the Host.
67          */
68         TF_RM_ELEM_CFG_SHARED,
69         TF_RM_TYPE_MAX
70 };
71
72 /**
73  * RM Reservation strategy enumeration. Type of strategy comes from
74  * the HCAPI RM QCAPS handshake.
75  */
76 enum tf_rm_resc_resv_strategy {
77         TF_RM_RESC_RESV_STATIC_PARTITION,
78         TF_RM_RESC_RESV_STRATEGY_1,
79         TF_RM_RESC_RESV_STRATEGY_2,
80         TF_RM_RESC_RESV_STRATEGY_3,
81         TF_RM_RESC_RESV_MAX
82 };
83
84 /**
85  * RM Element configuration structure, used by the Device to configure
86  * how an individual TF type is configured in regard to the HCAPI RM
87  * of same type.
88  */
89 struct tf_rm_element_cfg {
90         /**
91          * RM Element config controls how the DB for that element is
92          * processed.
93          */
94         enum tf_rm_elem_cfg_type cfg_type;
95
96         /* If a HCAPI to TF type conversion is required then TF type
97          * can be added here.
98          */
99
100         /**
101          * HCAPI RM Type for the element. Used for TF to HCAPI type
102          * conversion.
103          */
104         uint16_t hcapi_type;
105 };
106
107 /**
108  * Allocation information for a single element.
109  */
110 struct tf_rm_alloc_info {
111         /**
112          * HCAPI RM allocated range information.
113          *
114          * NOTE:
115          * In case of dynamic allocation support this would have
116          * to be changed to linked list of tf_rm_entry instead.
117          */
118         struct tf_rm_new_entry entry;
119 };
120
121 /**
122  * Create RM DB parameters
123  */
124 struct tf_rm_create_db_parms {
125         /**
126          * [in] Receive or transmit direction
127          */
128         enum tf_dir dir;
129         /**
130          * [in] Number of elements.
131          */
132         uint16_t num_elements;
133         /**
134          * [in] Parameter structure array. Array size is num_elements.
135          */
136         struct tf_rm_element_cfg *cfg;
137         /**
138          * Allocation number array. Array size is num_elements.
139          */
140         uint16_t *alloc_num;
141         /**
142          * [out] RM DB Handle
143          */
144         void *rm_db;
145 };
146
147 /**
148  * Free RM DB parameters
149  */
150 struct tf_rm_free_db_parms {
151         /**
152          * [in] Receive or transmit direction
153          */
154         enum tf_dir dir;
155         /**
156          * [in] RM DB Handle
157          */
158         void *rm_db;
159 };
160
161 /**
162  * Allocate RM parameters for a single element
163  */
164 struct tf_rm_allocate_parms {
165         /**
166          * [in] RM DB Handle
167          */
168         void *rm_db;
169         /**
170          * [in] DB Index, indicates which DB entry to perform the
171          * action on.
172          */
173         uint16_t db_index;
174         /**
175          * [in] Pointer to the allocated index in normalized
176          * form. Normalized means the index has been adjusted,
177          * i.e. Full Action Record offsets.
178          */
179         uint32_t *index;
180 };
181
182 /**
183  * Free RM parameters for a single element
184  */
185 struct tf_rm_free_parms {
186         /**
187          * [in] RM DB Handle
188          */
189         void *rm_db;
190         /**
191          * [in] DB Index, indicates which DB entry to perform the
192          * action on.
193          */
194         uint16_t db_index;
195         /**
196          * [in] Index to free
197          */
198         uint16_t index;
199 };
200
201 /**
202  * Is Allocated parameters for a single element
203  */
204 struct tf_rm_is_allocated_parms {
205         /**
206          * [in] RM DB Handle
207          */
208         void *rm_db;
209         /**
210          * [in] DB Index, indicates which DB entry to perform the
211          * action on.
212          */
213         uint16_t db_index;
214         /**
215          * [in] Index to free
216          */
217         uint32_t index;
218         /**
219          * [in] Pointer to flag that indicates the state of the query
220          */
221         int *allocated;
222 };
223
224 /**
225  * Get Allocation information for a single element
226  */
227 struct tf_rm_get_alloc_info_parms {
228         /**
229          * [in] RM DB Handle
230          */
231         void *rm_db;
232         /**
233          * [in] DB Index, indicates which DB entry to perform the
234          * action on.
235          */
236         uint16_t db_index;
237         /**
238          * [out] Pointer to the requested allocation information for
239          * the specified db_index
240          */
241         struct tf_rm_alloc_info *info;
242 };
243
244 /**
245  * Get HCAPI type parameters for a single element
246  */
247 struct tf_rm_get_hcapi_parms {
248         /**
249          * [in] RM DB Handle
250          */
251         void *rm_db;
252         /**
253          * [in] DB Index, indicates which DB entry to perform the
254          * action on.
255          */
256         uint16_t db_index;
257         /**
258          * [out] Pointer to the hcapi type for the specified db_index
259          */
260         uint16_t *hcapi_type;
261 };
262
263 /**
264  * @page rm Resource Manager
265  *
266  * @ref tf_rm_create_db
267  *
268  * @ref tf_rm_free_db
269  *
270  * @ref tf_rm_allocate
271  *
272  * @ref tf_rm_free
273  *
274  * @ref tf_rm_is_allocated
275  *
276  * @ref tf_rm_get_info
277  *
278  * @ref tf_rm_get_hcapi_type
279  */
280
281 /**
282  * Creates and fills a Resource Manager (RM) DB with requested
283  * elements. The DB is indexed per the parms structure.
284  *
285  * [in] tfp
286  *   Pointer to TF handle, used for HCAPI communication
287  *
288  * [in] parms
289  *   Pointer to create parameters
290  *
291  * Returns
292  *   - (0) if successful.
293  *   - (-EINVAL) on failure.
294  */
295 /*
296  * NOTE:
297  * - Fail on parameter check
298  * - Fail on DB creation, i.e. alloc amount is not possible or validation fails
299  * - Fail on DB creation if DB already exist
300  *
301  * - Allocs local DB
302  * - Does hcapi qcaps
303  * - Does hcapi reservation
304  * - Populates the pool with allocated elements
305  * - Returns handle to the created DB
306  */
307 int tf_rm_create_db(struct tf *tfp,
308                     struct tf_rm_create_db_parms *parms);
309
310 /**
311  * Closes the Resource Manager (RM) DB and frees all allocated
312  * resources per the associated database.
313  *
314  * [in] tfp
315  *   Pointer to TF handle, used for HCAPI communication
316  *
317  * [in] parms
318  *   Pointer to free parameters
319  *
320  * Returns
321  *   - (0) if successful.
322  *   - (-EINVAL) on failure.
323  */
324 int tf_rm_free_db(struct tf *tfp,
325                   struct tf_rm_free_db_parms *parms);
326
327 /**
328  * Allocates a single element for the type specified, within the DB.
329  *
330  * [in] parms
331  *   Pointer to allocate parameters
332  *
333  * Returns
334  *   - (0) if successful.
335  *   - (-EINVAL) on failure.
336  *   - (-ENOMEM) if pool is empty
337  */
338 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
339
340 /**
341  * Free's a single element for the type specified, within the DB.
342  *
343  * [in] parms
344  *   Pointer to free parameters
345  *
346  * Returns
347  *   - (0) if successful.
348  *   - (-EINVAL) on failure.
349  */
350 int tf_rm_free(struct tf_rm_free_parms *parms);
351
352 /**
353  * Performs an allocation verification check on a specified element.
354  *
355  * [in] parms
356  *   Pointer to is allocated parameters
357  *
358  * Returns
359  *   - (0) if successful.
360  *   - (-EINVAL) on failure.
361  */
362 /*
363  * NOTE:
364  *  - If pool is set to Chip MAX, then the query index must be checked
365  *    against the allocated range and query index must be allocated as well.
366  *  - If pool is allocated size only, then check if query index is allocated.
367  */
368 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
369
370 /**
371  * Retrieves an elements allocation information from the Resource
372  * Manager (RM) DB.
373  *
374  * [in] parms
375  *   Pointer to get info parameters
376  *
377  * Returns
378  *   - (0) if successful.
379  *   - (-EINVAL) on failure.
380  */
381 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
382
383 /**
384  * Performs a lookup in the Resource Manager DB and retrieves the
385  * requested HCAPI type.
386  *
387  * [in] parms
388  *   Pointer to get hcapi parameters
389  *
390  * Returns
391  *   - (0) if successful.
392  *   - (-EINVAL) on failure.
393  */
394 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
395
396 #endif /* TF_RM_NEW_H_ */