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