net/bnxt: add initial TruFlow core session close
[dpdk.git] / drivers / net / bnxt / tf_core / tf_rm.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_resources.h"
10 #include "tf_core.h"
11 #include "bitalloc.h"
12
13 struct tf;
14 struct tf_session;
15
16 /* Internal macro to determine appropriate allocation pools based on
17  * DIRECTION parm, also performs error checking for DIRECTION parm. The
18  * SESSION_POOL and SESSION pointers are set appropriately upon
19  * successful return (the GLOBAL_POOL is used to globally manage
20  * resource allocation and the SESSION_POOL is used to track the
21  * resources that have been allocated to the session)
22  *
23  * parameters:
24  *   struct tfp        *tfp
25  *   enum tf_dir        direction
26  *   struct bitalloc  **session_pool
27  *   string             base_pool_name - used to form pointers to the
28  *                                       appropriate bit allocation
29  *                                       pools, both directions of the
30  *                                       session pools must have same
31  *                                       base name, for example if
32  *                                       POOL_NAME is feat_pool: - the
33  *                                       ptr's to the session pools
34  *                                       are feat_pool_rx feat_pool_tx
35  *
36  *  int                  rc - return code
37  *                            0 - Success
38  *                           -1 - invalid DIRECTION parm
39  */
40 #define TF_RM_GET_POOLS(tfs, direction, session_pool, pool_name, rc) do { \
41                 (rc) = 0;                                               \
42                 if ((direction) == TF_DIR_RX) {                         \
43                         *(session_pool) = (tfs)->pool_name ## _RX;      \
44                 } else if ((direction) == TF_DIR_TX) {                  \
45                         *(session_pool) = (tfs)->pool_name ## _TX;      \
46                 } else {                                                \
47                         rc = -1;                                        \
48                 }                                                       \
49         } while (0)
50
51 #define TF_RM_GET_POOLS_RX(tfs, session_pool, pool_name)        \
52         (*(session_pool) = (tfs)->pool_name ## _RX)
53
54 #define TF_RM_GET_POOLS_TX(tfs, session_pool, pool_name)        \
55         (*(session_pool) = (tfs)->pool_name ## _TX)
56
57 /**
58  * Resource query single entry
59  */
60 struct tf_rm_query_entry {
61         /** Minimum guaranteed number of elements */
62         uint16_t min;
63         /** Maximum non-guaranteed number of elements */
64         uint16_t max;
65 };
66
67 /**
68  * Resource single entry
69  */
70 struct tf_rm_entry {
71         /** Starting index of the allocated resource */
72         uint16_t start;
73         /** Number of allocated elements */
74         uint16_t stride;
75 };
76
77 /**
78  * Resource query array of HW entities
79  */
80 struct tf_rm_hw_query {
81         /** array of HW resource entries */
82         struct tf_rm_query_entry hw_query[TF_RESC_TYPE_HW_MAX];
83 };
84
85 /**
86  * Resource allocation array of HW entities
87  */
88 struct tf_rm_hw_alloc {
89         /** array of HW resource entries */
90         uint16_t hw_num[TF_RESC_TYPE_HW_MAX];
91 };
92
93 /**
94  * Resource query array of SRAM entities
95  */
96 struct tf_rm_sram_query {
97         /** array of SRAM resource entries */
98         struct tf_rm_query_entry sram_query[TF_RESC_TYPE_SRAM_MAX];
99 };
100
101 /**
102  * Resource allocation array of SRAM entities
103  */
104 struct tf_rm_sram_alloc {
105         /** array of SRAM resource entries */
106         uint16_t sram_num[TF_RESC_TYPE_SRAM_MAX];
107 };
108
109 /**
110  * Initializes the Resource Manager and the associated database
111  * entries for HW and SRAM resources. Must be called before any other
112  * Resource Manager functions.
113  *
114  * [in] tfp
115  *   Pointer to TF handle
116  */
117 void tf_rm_init(struct tf *tfp);
118
119 /**
120  * Allocates and validates both HW and SRAM resources per the NVM
121  * configuration. If any allocation fails all resources for the
122  * session is deallocated.
123  *
124  * [in] tfp
125  *   Pointer to TF handle
126  *
127  * Returns
128  *   - (0) if successful.
129  *   - (-EINVAL) on failure.
130  */
131 int tf_rm_allocate_validate(struct tf *tfp);
132
133 /**
134  * Closes the Resource Manager and frees all allocated resources per
135  * the associated database.
136  *
137  * [in] tfp
138  *   Pointer to TF handle
139  *
140  * Returns
141  *   - (0) if successful.
142  *   - (-EINVAL) on failure.
143  *   - (-ENOTEMPTY) if resources are not cleaned up before close
144  */
145 int tf_rm_close(struct tf *tfp);
146 #endif /* TF_RM_H_ */