net/bnxt: update multi device design
[dpdk.git] / drivers / net / bnxt / tf_core / tf_tbl_type.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef TF_TBL_TYPE_H_
7 #define TF_TBL_TYPE_H_
8
9 #include "tf_core.h"
10
11 struct tf;
12
13 /**
14  * The Table module provides processing of Internal TF table types.
15  */
16
17 /**
18  * Table configuration parameters
19  */
20 struct tf_tbl_cfg_parms {
21         /**
22          * Number of table types in each of the configuration arrays
23          */
24         uint16_t num_elements;
25         /**
26          * Table Type element configuration array
27          */
28         struct tf_rm_element_cfg *cfg;
29         /**
30          * Shadow table type configuration array
31          */
32         struct tf_shadow_tbl_cfg *shadow_cfg;
33         /**
34          * Boolean controlling the request shadow copy.
35          */
36         bool shadow_copy;
37         /**
38          * Session resource allocations
39          */
40         struct tf_session_resources *resources;
41 };
42
43 /**
44  * Table allocation parameters
45  */
46 struct tf_tbl_alloc_parms {
47         /**
48          * [in] Receive or transmit direction
49          */
50         enum tf_dir dir;
51         /**
52          * [in] Type of the allocation
53          */
54         enum tf_tbl_type type;
55         /**
56          * [out] Idx of allocated entry or found entry (if search_enable)
57          */
58         uint32_t idx;
59 };
60
61 /**
62  * Table free parameters
63  */
64 struct tf_tbl_free_parms {
65         /**
66          * [in] Receive or transmit direction
67          */
68         enum tf_dir dir;
69         /**
70          * [in] Type of the allocation type
71          */
72         enum tf_tbl_type type;
73         /**
74          * [in] Index to free
75          */
76         uint32_t idx;
77         /**
78          * [out] Reference count after free, only valid if session has been
79          * created with shadow_copy.
80          */
81         uint16_t ref_cnt;
82 };
83
84 /**
85  * Table allocate search parameters
86  */
87 struct tf_tbl_alloc_search_parms {
88         /**
89          * [in] Receive or transmit direction
90          */
91         enum tf_dir dir;
92         /**
93          * [in] Type of the allocation
94          */
95         enum tf_tbl_type type;
96         /**
97          * [in] Table scope identifier (ignored unless TF_TBL_TYPE_EXT)
98          */
99         uint32_t tbl_scope_id;
100         /**
101          * [in] Enable search for matching entry. If the table type is
102          * internal the shadow copy will be searched before
103          * alloc. Session must be configured with shadow copy enabled.
104          */
105         uint8_t search_enable;
106         /**
107          * [in] Result data to search for (if search_enable)
108          */
109         uint8_t *result;
110         /**
111          * [in] Result data size in bytes (if search_enable)
112          */
113         uint16_t result_sz_in_bytes;
114         /**
115          * [out] If search_enable, set if matching entry found
116          */
117         uint8_t hit;
118         /**
119          * [out] Current ref count after allocation (if search_enable)
120          */
121         uint16_t ref_cnt;
122         /**
123          * [out] Idx of allocated entry or found entry (if search_enable)
124          */
125         uint32_t idx;
126 };
127
128 /**
129  * Table set parameters
130  */
131 struct tf_tbl_set_parms {
132         /**
133          * [in] Receive or transmit direction
134          */
135         enum tf_dir dir;
136         /**
137          * [in] Type of object to set
138          */
139         enum tf_tbl_type type;
140         /**
141          * [in] Entry data
142          */
143         uint8_t *data;
144         /**
145          * [in] Entry size
146          */
147         uint16_t data_sz_in_bytes;
148         /**
149          * [in] Entry index to write to
150          */
151         uint32_t idx;
152 };
153
154 /**
155  * Table get parameters
156  */
157 struct tf_tbl_get_parms {
158         /**
159          * [in] Receive or transmit direction
160          */
161         enum tf_dir dir;
162         /**
163          * [in] Type of object to get
164          */
165         enum tf_tbl_type type;
166         /**
167          * [out] Entry data
168          */
169         uint8_t *data;
170         /**
171          * [out] Entry size
172          */
173         uint16_t data_sz_in_bytes;
174         /**
175          * [in] Entry index to read
176          */
177         uint32_t idx;
178 };
179
180 /**
181  * @page tbl Table
182  *
183  * @ref tf_tbl_bind
184  *
185  * @ref tf_tbl_unbind
186  *
187  * @ref tf_tbl_alloc
188  *
189  * @ref tf_tbl_free
190  *
191  * @ref tf_tbl_alloc_search
192  *
193  * @ref tf_tbl_set
194  *
195  * @ref tf_tbl_get
196  */
197
198 /**
199  * Initializes the Table module with the requested DBs. Must be
200  * invoked as the first thing before any of the access functions.
201  *
202  * [in] tfp
203  *   Pointer to TF handle, used for HCAPI communication
204  *
205  * [in] parms
206  *   Pointer to Table configuration parameters
207  *
208  * Returns
209  *   - (0) if successful.
210  *   - (-EINVAL) on failure.
211  */
212 int tf_tbl_bind(struct tf *tfp,
213                 struct tf_tbl_cfg_parms *parms);
214
215 /**
216  * Cleans up the private DBs and releases all the data.
217  *
218  * [in] tfp
219  *   Pointer to TF handle, used for HCAPI communication
220  *
221  * [in] parms
222  *   Pointer to parameters
223  *
224  * Returns
225  *   - (0) if successful.
226  *   - (-EINVAL) on failure.
227  */
228 int tf_tbl_unbind(struct tf *tfp);
229
230 /**
231  * Allocates the requested table type from the internal RM DB.
232  *
233  * [in] tfp
234  *   Pointer to TF handle, used for HCAPI communication
235  *
236  * [in] parms
237  *   Pointer to Table allocation parameters
238  *
239  * Returns
240  *   - (0) if successful.
241  *   - (-EINVAL) on failure.
242  */
243 int tf_tbl_alloc(struct tf *tfp,
244                  struct tf_tbl_alloc_parms *parms);
245
246 /**
247  * Free's the requested table type and returns it to the DB. If shadow
248  * DB is enabled its searched first and if found the element refcount
249  * is decremented. If refcount goes to 0 then its returned to the
250  * table type DB.
251  *
252  * [in] tfp
253  *   Pointer to TF handle, used for HCAPI communication
254  *
255  * [in] parms
256  *   Pointer to Table free parameters
257  *
258  * Returns
259  *   - (0) if successful.
260  *   - (-EINVAL) on failure.
261  */
262 int tf_tbl_free(struct tf *tfp,
263                 struct tf_tbl_free_parms *parms);
264
265 /**
266  * Supported if Shadow DB is configured. Searches the Shadow DB for
267  * any matching element. If found the refcount in the shadow DB is
268  * updated accordingly. If not found a new element is allocated and
269  * installed into the shadow DB.
270  *
271  * [in] tfp
272  *   Pointer to TF handle, used for HCAPI communication
273  *
274  * [in] parms
275  *   Pointer to parameters
276  *
277  * Returns
278  *   - (0) if successful.
279  *   - (-EINVAL) on failure.
280  */
281 int tf_tbl_alloc_search(struct tf *tfp,
282                         struct tf_tbl_alloc_search_parms *parms);
283
284 /**
285  * Configures the requested element by sending a firmware request which
286  * then installs it into the device internal structures.
287  *
288  * [in] tfp
289  *   Pointer to TF handle, used for HCAPI communication
290  *
291  * [in] parms
292  *   Pointer to Table set parameters
293  *
294  * Returns
295  *   - (0) if successful.
296  *   - (-EINVAL) on failure.
297  */
298 int tf_tbl_set(struct tf *tfp,
299                struct tf_tbl_set_parms *parms);
300
301 /**
302  * Retrieves the requested element by sending a firmware request to get
303  * the element.
304  *
305  * [in] tfp
306  *   Pointer to TF handle, used for HCAPI communication
307  *
308  * [in] parms
309  *   Pointer to Table get parameters
310  *
311  * Returns
312  *   - (0) if successful.
313  *   - (-EINVAL) on failure.
314  */
315 int tf_tbl_get(struct tf *tfp,
316                struct tf_tbl_get_parms *parms);
317
318 #endif /* TF_TBL_TYPE_H */