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