net/bnxt: support multi device
[dpdk.git] / drivers / net / bnxt / tf_core / tf_shadow_tcam.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_SHADOW_TCAM_H_
7 #define _TF_SHADOW_TCAM_H_
8
9 #include "tf_core.h"
10
11 struct tf;
12
13 /**
14  * The Shadow tcam module provides shadow DB handling for tcam based
15  * TF types. A shadow DB provides the capability that allows for reuse
16  * of TF resources.
17  *
18  * A Shadow tcam DB is intended to be used by the Tcam module only.
19  */
20
21 /**
22  * Shadow DB configuration information for a single tcam type.
23  *
24  * During Device initialization the HCAPI device specifics are learned
25  * and as well as the RM DB creation. From that those initial steps
26  * this structure can be populated.
27  *
28  * NOTE:
29  * If used in an array of tcam types then such array must be ordered
30  * by the TF type is represents.
31  */
32 struct tf_shadow_tcam_cfg_parms {
33         /**
34          * TF tcam type
35          */
36         enum tf_tcam_tbl_type type;
37
38         /**
39          * Number of entries the Shadow DB needs to hold
40          */
41         int num_entries;
42
43         /**
44          * Element width for this table type
45          */
46         int element_width;
47 };
48
49 /**
50  * Shadow tcam DB creation parameters
51  */
52 struct tf_shadow_tcam_create_db_parms {
53         /**
54          * [in] Configuration information for the shadow db
55          */
56         struct tf_shadow_tcam_cfg_parms *cfg;
57         /**
58          * [in] Number of elements in the parms structure
59          */
60         uint16_t num_elements;
61         /**
62          * [out] Shadow tcam DB handle
63          */
64         void *tf_shadow_tcam_db;
65 };
66
67 /**
68  * Shadow tcam DB free parameters
69  */
70 struct tf_shadow_tcam_free_db_parms {
71         /**
72          * Shadow tcam DB handle
73          */
74         void *tf_shadow_tcam_db;
75 };
76
77 /**
78  * Shadow tcam search parameters
79  */
80 struct tf_shadow_tcam_search_parms {
81         /**
82          * [in] Shadow tcam DB handle
83          */
84         void *tf_shadow_tcam_db;
85         /**
86          * [in] TCAM tbl type
87          */
88         enum tf_tcam_tbl_type type;
89         /**
90          * [in] Pointer to entry blob value in remap table to match
91          */
92         uint8_t *entry;
93         /**
94          * [in] Size of the entry blob passed in bytes
95          */
96         uint16_t entry_sz;
97         /**
98          * [out] Index of the found element returned if hit
99          */
100         uint16_t *index;
101         /**
102          * [out] Reference count incremented if hit
103          */
104         uint16_t *ref_cnt;
105 };
106
107 /**
108  * Shadow tcam insert parameters
109  */
110 struct tf_shadow_tcam_insert_parms {
111         /**
112          * [in] Shadow tcam DB handle
113          */
114         void *tf_shadow_tcam_db;
115         /**
116          * [in] TCAM tbl type
117          */
118         enum tf_tcam_tbl_type type;
119         /**
120          * [in] Pointer to entry blob value in remap table to match
121          */
122         uint8_t *entry;
123         /**
124          * [in] Size of the entry blob passed in bytes
125          */
126         uint16_t entry_sz;
127         /**
128          * [in] Entry to update
129          */
130         uint16_t index;
131         /**
132          * [out] Reference count after insert
133          */
134         uint16_t *ref_cnt;
135 };
136
137 /**
138  * Shadow tcam remove parameters
139  */
140 struct tf_shadow_tcam_remove_parms {
141         /**
142          * [in] Shadow tcam DB handle
143          */
144         void *tf_shadow_tcam_db;
145         /**
146          * [in] TCAM tbl type
147          */
148         enum tf_tcam_tbl_type type;
149         /**
150          * [in] Entry to update
151          */
152         uint16_t index;
153         /**
154          * [out] Reference count after removal
155          */
156         uint16_t *ref_cnt;
157 };
158
159 /**
160  * @page shadow_tcam Shadow tcam DB
161  *
162  * @ref tf_shadow_tcam_create_db
163  *
164  * @ref tf_shadow_tcam_free_db
165  *
166  * @reg tf_shadow_tcam_search
167  *
168  * @reg tf_shadow_tcam_insert
169  *
170  * @reg tf_shadow_tcam_remove
171  */
172
173 /**
174  * Creates and fills a Shadow tcam DB. The DB is indexed per the
175  * parms structure.
176  *
177  * [in] parms
178  *   Pointer to create db parameters
179  *
180  * Returns
181  *   - (0) if successful.
182  *   - (-EINVAL) on failure.
183  */
184 int tf_shadow_tcam_create_db(struct tf_shadow_tcam_create_db_parms *parms);
185
186 /**
187  * Closes the Shadow tcam DB and frees all allocated
188  * resources per the associated database.
189  *
190  * [in] parms
191  *   Pointer to the free DB parameters
192  *
193  * Returns
194  *   - (0) if successful.
195  *   - (-EINVAL) on failure.
196  */
197 int tf_shadow_tcam_free_db(struct tf_shadow_tcam_free_db_parms *parms);
198
199 /**
200  * Search Shadow tcam db for matching result
201  *
202  * [in] parms
203  *   Pointer to the search parameters
204  *
205  * Returns
206  *   - (0) if successful, element was found.
207  *   - (-EINVAL) on failure.
208  */
209 int tf_shadow_tcam_search(struct tf_shadow_tcam_search_parms *parms);
210
211 /**
212  * Inserts an element into the Shadow tcam DB. Will fail if the
213  * elements ref_count is different from 0. Ref_count after insert will
214  * be incremented.
215  *
216  * [in] parms
217  *   Pointer to insert parameters
218  *
219  * Returns
220  *   - (0) if successful.
221  *   - (-EINVAL) on failure.
222  */
223 int tf_shadow_tcam_insert(struct tf_shadow_tcam_insert_parms *parms);
224
225 /**
226  * Removes an element from the Shadow tcam DB. Will fail if the
227  * elements ref_count is 0. Ref_count after removal will be
228  * decremented.
229  *
230  * [in] parms
231  *   Pointer to remove parameter
232  *
233  * Returns
234  *   - (0) if successful.
235  *   - (-EINVAL) on failure.
236  */
237 int tf_shadow_tcam_remove(struct tf_shadow_tcam_remove_parms *parms);
238
239 #endif /* _TF_SHADOW_TCAM_H_ */