eal: remove sys/queue.h from public headers
[dpdk.git] / drivers / net / bnxt / tf_core / tf_rm.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 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 #include "tf_device.h"
12
13 struct tf;
14
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
19
20 /**
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
24  * firmware.
25  *
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
30  * mapping.
31  *
32  * Accessor functions are providing access to the DB, thus hiding the
33  * implementation.
34  *
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.
41  *
42  * The access functions do not check for NULL pointers as they are a
43  * support module, not called directly.
44  */
45
46
47 /**
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.
52  */
53 enum tf_rm_elem_cfg_type {
54         /**
55          * No configuration
56          */
57         TF_RM_ELEM_CFG_NULL,
58         /** HCAPI 'controlled', no RM storage so the module
59          *  using the RM can chose to handle storage locally.
60          */
61         TF_RM_ELEM_CFG_HCAPI,
62         /** HCAPI 'controlled', uses a bit allocator pool for internal
63          *  storage in the RM.
64          */
65         TF_RM_ELEM_CFG_HCAPI_BA,
66         /**
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.
70          */
71         TF_RM_ELEM_CFG_HCAPI_BA_PARENT,
72         /**
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.
76          */
77         TF_RM_ELEM_CFG_HCAPI_BA_CHILD,
78
79
80         TF_RM_TYPE_MAX
81 };
82
83 /**
84  * RM Reservation strategy enumeration. Type of strategy comes from
85  * the HCAPI RM QCAPS handshake.
86  */
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,
92         TF_RM_RESC_RESV_MAX
93 };
94
95 /**
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
98  * of same type.
99  */
100 struct tf_rm_element_cfg {
101         /**
102          * RM Element config controls how the DB for that element is
103          * processed.
104          */
105         enum tf_rm_elem_cfg_type cfg_type;
106
107         /**
108          * HCAPI RM Type for the element. Used for TF to HCAPI type
109          * conversion.
110          */
111         uint16_t hcapi_type;
112
113         /**
114          * if cfg_type == TF_RM_ELEM_CFG_HCAPI_BA_CHILD/PARENT
115          *
116          * Parent Truflow module subtype associated with this resource type.
117          */
118         uint16_t parent_subtype;
119
120         /**
121          * if cfg_type == TF_RM_ELEM_CFG_HCAPI_BA_CHILD/PARENT
122          *
123          * Resource slices.  How many slices will fit in the
124          * resource pool chunk size.
125          */
126         uint8_t slices;
127 };
128
129 /**
130  * Allocation information for a single element.
131  */
132 struct tf_rm_alloc_info {
133         /**
134          * HCAPI RM allocated range information.
135          *
136          * NOTE:
137          * In case of dynamic allocation support this would have
138          * to be changed to linked list of tf_rm_entry instead.
139          */
140         struct tf_resource_info entry;
141 };
142
143 /**
144  * Create RM DB parameters
145  */
146 struct tf_rm_create_db_parms {
147         /**
148          * [in] Module type. Used for logging purposes.
149          */
150         enum tf_module_type module;
151         /**
152          * [in] Receive or transmit direction.
153          */
154         enum tf_dir dir;
155         /**
156          * [in] Number of elements.
157          */
158         uint16_t num_elements;
159         /**
160          * [in] Parameter structure array. Array size is num_elements.
161          */
162         struct tf_rm_element_cfg *cfg;
163         /**
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.
167          */
168         uint16_t *alloc_cnt;
169         /**
170          * [out] RM DB Handle
171          */
172         void **rm_db;
173 };
174
175 /**
176  * Free RM DB parameters
177  */
178 struct tf_rm_free_db_parms {
179         /**
180          * [in] Receive or transmit direction
181          */
182         enum tf_dir dir;
183         /**
184          * [in] RM DB Handle
185          */
186         void *rm_db;
187 };
188
189 /**
190  * Allocate RM parameters for a single element
191  */
192 struct tf_rm_allocate_parms {
193         /**
194          * [in] RM DB Handle
195          */
196         void *rm_db;
197         /**
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)
201          */
202         uint16_t subtype;
203         /**
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.
207          */
208         uint32_t *index;
209         /**
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
214          *              available index)
215          */
216         uint32_t priority;
217         /**
218          * [in] Pointer to the allocated index before adjusted.
219          */
220         uint32_t *base_index;
221 };
222
223 /**
224  * Free RM parameters for a single element
225  */
226 struct tf_rm_free_parms {
227         /**
228          * [in] RM DB Handle
229          */
230         void *rm_db;
231         /**
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)
235          */
236         uint16_t subtype;
237         /**
238          * [in] Index to free
239          */
240         uint16_t index;
241 };
242
243 /**
244  * Is Allocated parameters for a single element
245  */
246 struct tf_rm_is_allocated_parms {
247         /**
248          * [in] RM DB Handle
249          */
250         void *rm_db;
251         /**
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)
255          */
256         uint16_t subtype;
257         /**
258          * [in] Index to free
259          */
260         uint32_t index;
261         /**
262          * [in] Pointer to flag that indicates the state of the query
263          */
264         int *allocated;
265         /**
266          * [in] Pointer to the allocated index before adjusted.
267          */
268         uint32_t *base_index;
269 };
270
271 /**
272  * Get Allocation information for a single element
273  */
274 struct tf_rm_get_alloc_info_parms {
275         /**
276          * [in] RM DB Handle
277          */
278         void *rm_db;
279         /**
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)
283          */
284         uint16_t subtype;
285         /**
286          * [out] Pointer to the requested allocation information for
287          * the specified subtype
288          */
289         struct tf_rm_alloc_info *info;
290 };
291
292 /**
293  * Get HCAPI type parameters for a single element
294  */
295 struct tf_rm_get_hcapi_parms {
296         /**
297          * [in] RM DB Handle
298          */
299         void *rm_db;
300         /**
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)
304          */
305         uint16_t subtype;
306         /**
307          * [out] Pointer to the hcapi type for the specified subtype
308          */
309         uint16_t *hcapi_type;
310 };
311 /**
312  * Get Slices parameters for a single element
313  */
314 struct tf_rm_get_slices_parms {
315         /**
316          * [in] RM DB Handle
317          */
318         void *rm_db;
319         /**
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)
323          */
324         uint16_t subtype;
325         /**
326          * [in/out] Pointer to number of slices for the given type
327          */
328         uint16_t *slices;
329 };
330
331 /**
332  * Get InUse count parameters for single element
333  */
334 struct tf_rm_get_inuse_count_parms {
335         /**
336          * [in] RM DB Handle
337          */
338         void *rm_db;
339         /**
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)
343          */
344         uint16_t subtype;
345         /**
346          * [out] Pointer to the inuse count for the specified subtype
347          */
348         uint16_t *count;
349 };
350
351 /**
352  * Check if the indexes are in the range of reserved resource
353  */
354 struct tf_rm_check_indexes_in_range_parms {
355         /**
356          * [in] RM DB Handle
357          */
358         void *rm_db;
359         /**
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)
363          */
364         uint16_t subtype;
365         /**
366          * [in] Starting index
367          */
368         uint16_t starting_index;
369         /**
370          * [in] number of entries
371          */
372         uint16_t num_entries;
373 };
374
375 /**
376  * @page rm Resource Manager
377  *
378  * @ref tf_rm_create_db
379  *
380  * @ref tf_rm_free_db
381  *
382  * @ref tf_rm_allocate
383  *
384  * @ref tf_rm_free
385  *
386  * @ref tf_rm_is_allocated
387  *
388  * @ref tf_rm_get_info
389  *
390  * @ref tf_rm_get_hcapi_type
391  *
392  * @ref tf_rm_get_inuse_count
393  *
394  * @ref tf_rm_get_slice_size
395  */
396
397 /**
398  * Creates and fills a Resource Manager (RM) DB with requested
399  * elements. The DB is indexed per the parms structure.
400  *
401  * [in] tfp
402  *   Pointer to TF handle, used for HCAPI communication
403  *
404  * [in] parms
405  *   Pointer to create parameters
406  *
407  * Returns
408  *   - (0) if successful.
409  *   - (-EINVAL) on failure.
410  */
411 /*
412  * NOTE:
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
416  *
417  * - Allocs local DB
418  * - Does hcapi qcaps
419  * - Does hcapi reservation
420  * - Populates the pool with allocated elements
421  * - Returns handle to the created DB
422  */
423 int tf_rm_create_db(struct tf *tfp,
424                     struct tf_rm_create_db_parms *parms);
425
426 /**
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.
430  *
431  * [in] tfp
432  *   Pointer to TF handle, used for HCAPI communication
433  *
434  * [in] parms
435  *   Pointer to create parameters
436  *
437  * Returns
438  *   - (0) if successful.
439  *   - (-EINVAL) on failure.
440  */
441 int tf_rm_create_db_no_reservation(struct tf *tfp,
442                     struct tf_rm_create_db_parms *parms);
443
444 /**
445  * Closes the Resource Manager (RM) DB and frees all allocated
446  * resources per the associated database.
447  *
448  * [in] tfp
449  *   Pointer to TF handle, used for HCAPI communication
450  *
451  * [in] parms
452  *   Pointer to free parameters
453  *
454  * Returns
455  *   - (0) if successful.
456  *   - (-EINVAL) on failure.
457  */
458 int tf_rm_free_db(struct tf *tfp,
459                   struct tf_rm_free_db_parms *parms);
460
461 /**
462  * Allocates a single element for the type specified, within the DB.
463  *
464  * [in] parms
465  *   Pointer to allocate parameters
466  *
467  * Returns
468  *   - (0) if successful.
469  *   - (-EINVAL) on failure.
470  *   - (-ENOMEM) if pool is empty
471  */
472 int tf_rm_allocate(struct tf_rm_allocate_parms *parms);
473
474 /**
475  * Free's a single element for the type specified, within the DB.
476  *
477  * [in] parms
478  *   Pointer to free parameters
479  *
480  * Returns
481  *   - (0) if successful.
482  *   - (-EINVAL) on failure.
483  */
484 int tf_rm_free(struct tf_rm_free_parms *parms);
485
486 /**
487  * Performs an allocation verification check on a specified element.
488  *
489  * [in] parms
490  *   Pointer to is allocated parameters
491  *
492  * Returns
493  *   - (0) if successful.
494  *   - (-EINVAL) on failure.
495  */
496 /*
497  * NOTE:
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.
501  */
502 int tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms);
503
504 /**
505  * Retrieves an elements allocation information from the Resource
506  * Manager (RM) DB.
507  *
508  * [in] parms
509  *   Pointer to get info parameters
510  *
511  * Returns
512  *   - (0) if successful.
513  *   - (-EINVAL) on failure.
514  */
515 int tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms);
516
517 /**
518  * Retrieves all elements allocation information from the Resource
519  * Manager (RM) DB.
520  *
521  * [in] parms
522  *   Pointer to get info parameters
523  *
524  * [in] size
525  *   number of the elements for the specific module
526  *
527  * Returns
528  *   - (0) if successful.
529  *   - (-EINVAL) on failure.
530  */
531 int tf_rm_get_all_info(struct tf_rm_get_alloc_info_parms *parms, int size);
532
533 /**
534  * Performs a lookup in the Resource Manager DB and retrieves the
535  * requested HCAPI RM type.
536  *
537  * [in] parms
538  *   Pointer to get hcapi parameters
539  *
540  * Returns
541  *   - (0) if successful.
542  *   - (-EINVAL) on failure.
543  */
544 int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
545
546 /**
547  * Performs a lookup in the Resource Manager DB and retrieves the
548  * requested HCAPI RM type inuse count.
549  *
550  * [in] parms
551  *   Pointer to get inuse parameters
552  *
553  * Returns
554  *   - (0) if successful.
555  *   - (-EINVAL) on failure.
556  */
557 int tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms);
558
559 /**
560  * Check if the requested indexes are in the range of reserved resource.
561  *
562  * [in] parms
563  *   Pointer to get inuse parameters
564  *
565  * Returns
566  *   - (0) if successful.
567  *   - (-EINVAL) on failure.
568  */
569 int
570 tf_rm_check_indexes_in_range(struct tf_rm_check_indexes_in_range_parms *parms);
571
572 /**
573  * Get the number of slices per resource bit allocator for the resource type
574  *
575  * [in] parms
576  *   Pointer to get inuse parameters
577  *
578  * Returns
579  *   - (0) if successful.
580  *   - (-EINVAL) on failure.
581  */
582 int
583 tf_rm_get_slices(struct tf_rm_get_slices_parms *parms);
584
585 #endif /* TF_RM_NEW_H_ */