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