1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5 
6 #ifndef _TF_SHADOW_IDENTIFIER_H_
7 #define _TF_SHADOW_IDENTIFIER_H_
8 
9 #include "tf_core.h"
10 
11 struct tf;
12 
13 /**
14  * The Shadow Identifier module provides shadow DB handling for identifier based
15  * TF types. A shadow DB provides the capability that allows for reuse
16  * of TF resources.
17  *
18  * A Shadow identifier DB is intended to be used by the Identifier Type module
19  * only.
20  */
21 
22 /**
23  * Shadow DB configuration information for a single identifier type.
24  *
25  * It is used in an array of identifier types. The array must be ordered
26  * by the TF type is represents.
27  */
28 struct tf_shadow_ident_cfg_parms {
29 	/**
30 	 * TF Identifier type
31 	 */
32 	enum tf_identifier_type type;
33 
34 	/**
35 	 * Number of entries the Shadow DB needs to hold
36 	 */
37 	int num_entries;
38 
39 	/**
40 	 * Resource allocation count array. This array content
41 	 * originates from the tf_session_resources that is passed in
42 	 * on session open.
43 	 * Array size is num_elements.
44 	 */
45 	uint16_t *alloc_cnt;
46 };
47 
48 /**
49  * Shadow identifier DB creation parameters
50  */
51 struct tf_shadow_ident_create_db_parms {
52 	/**
53 	 * [in] Receive or transmit direction.
54 	 */
55 	enum tf_dir dir;
56 	/**
57 	 * [in] Configuration information for the shadow db
58 	 */
59 	struct tf_shadow_ident_cfg_parms *cfg;
60 	/**
61 	 * [in] Number of elements in the parms structure
62 	 */
63 	uint16_t num_elements;
64 	/**
65 	 * [out] Shadow identifier DB handle
66 	 */
67 	void **tf_shadow_ident_db;
68 };
69 
70 /**
71  * Shadow identifier DB free parameters
72  */
73 struct tf_shadow_ident_free_db_parms {
74 	/**
75 	 * Shadow identifier DB handle
76 	 */
77 	void *tf_shadow_ident_db;
78 };
79 
80 /**
81  * Shadow identifier search parameters
82  */
83 struct tf_shadow_ident_search_parms {
84 	/**
85 	 * [in] Shadow identifier DB handle
86 	 */
87 	void *tf_shadow_ident_db;
88 	/**
89 	 * [in] Identifier type
90 	 */
91 	enum tf_identifier_type type;
92 	/**
93 	 * [in] id to search
94 	 */
95 	uint16_t search_id;
96 	/**
97 	 * [out] Index of the found element returned if hit
98 	 */
99 	bool *hit;
100 	/**
101 	 * [out] Reference count incremented if hit
102 	 */
103 	uint32_t *ref_cnt;
104 };
105 
106 /**
107  * Shadow identifier insert parameters
108  */
109 struct tf_shadow_ident_insert_parms {
110 	/**
111 	 * [in] Shadow identifier DB handle
112 	 */
113 	void *tf_shadow_ident_db;
114 	/**
115 	 * [in] Tbl type
116 	 */
117 	enum tf_identifier_type type;
118 	/**
119 	 * [in] Entry to update
120 	 */
121 	uint16_t id;
122 	/**
123 	 * [out] Reference count after insert
124 	 */
125 	uint32_t ref_cnt;
126 };
127 
128 /**
129  * Shadow identifier remove parameters
130  */
131 struct tf_shadow_ident_remove_parms {
132 	/**
133 	 * [in] Shadow identifier DB handle
134 	 */
135 	void *tf_shadow_ident_db;
136 	/**
137 	 * [in] Tbl type
138 	 */
139 	enum tf_identifier_type type;
140 	/**
141 	 * [in] Entry to update
142 	 */
143 	uint16_t id;
144 	/**
145 	 * [out] Reference count after removal
146 	 */
147 	uint32_t *ref_cnt;
148 };
149 
150 /**
151  * @page shadow_ident Shadow identifier DB
152  *
153  * @ref tf_shadow_ident_create_db
154  *
155  * @ref tf_shadow_ident_free_db
156  *
157  * @reg tf_shadow_ident_search
158  *
159  * @reg tf_shadow_ident_insert
160  *
161  * @reg tf_shadow_ident_remove
162  */
163 
164 /**
165  * Creates and fills a Shadow identifier DB. The DB is indexed per the
166  * parms structure.
167  *
168  * [in] parms
169  *   Pointer to create db parameters
170  *
171  * Returns
172  *   - (0) if successful.
173  *   - (-EINVAL) on failure.
174  */
175 int tf_shadow_ident_create_db(struct tf_shadow_ident_create_db_parms *parms);
176 
177 /**
178  * Closes the Shadow identifier DB and frees all allocated
179  * resources per the associated database.
180  *
181  * [in] parms
182  *   Pointer to the free DB parameters
183  *
184  * Returns
185  *   - (0) if successful.
186  *   - (-EINVAL) on failure.
187  */
188 int tf_shadow_ident_free_db(struct tf_shadow_ident_free_db_parms *parms);
189 
190 /**
191  * Search Shadow identifier db for matching result
192  *
193  * [in] parms
194  *   Pointer to the search parameters
195  *
196  * Returns
197  *   - (0) if successful, element was found.
198  *   - (-EINVAL) on failure.
199  */
200 int tf_shadow_ident_search(struct tf_shadow_ident_search_parms *parms);
201 
202 /**
203  * Inserts an element into the Shadow identifier DB. Ref_count after insert
204  * will be incremented.
205  *
206  * [in] parms
207  *   Pointer to insert parameters
208  *
209  * Returns
210  *   - (0) if successful.
211  *   - (-EINVAL) on failure.
212  */
213 int tf_shadow_ident_insert(struct tf_shadow_ident_insert_parms *parms);
214 
215 /**
216  * Removes an element from the Shadow identifier DB. Will fail if the
217  * elements ref_count is 0. Ref_count after removal will be
218  * decremented.
219  *
220  * [in] parms
221  *   Pointer to remove parameter
222  *
223  * Returns
224  *   - (0) if successful.
225  *   - (-EINVAL) on failure.
226  */
227 int tf_shadow_ident_remove(struct tf_shadow_ident_remove_parms *parms);
228 
229 #endif /* _TF_SHADOW_IDENTIFIER_H_ */
230