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 /**
12  * Shadow DB configuration information
13  *
14  * The shadow configuration is for all tcam table types for a direction
15  */
16 struct tf_shadow_tcam_cfg_parms {
17 	/**
18 	 * [in] The number of elements in the alloc_cnt and base_addr
19 	 * For now, it should always be equal to TF_TCAM_TBL_TYPE_MAX
20 	 */
21 	int num_entries;
22 	/**
23 	 * [in] Resource allocation count array
24 	 * This array content originates from the tf_session_resources
25 	 * that is passed in on session open
26 	 * Array size is TF_TCAM_TBL_TYPE_MAX
27 	 */
28 	uint16_t *alloc_cnt;
29 	/**
30 	 * [in] The base index for each tcam table
31 	 */
32 	uint16_t base_addr[TF_TCAM_TBL_TYPE_MAX];
33 };
34 
35 /**
36  * Shadow TCAM  DB creation parameters.  The shadow db for this direction
37  * is returned
38  */
39 struct tf_shadow_tcam_create_db_parms {
40 	/**
41 	 * [in] Receive or transmit direction
42 	 */
43 	enum tf_dir dir;
44 	/**
45 	 * [in] Configuration information for the shadow db
46 	 */
47 	struct tf_shadow_tcam_cfg_parms *cfg;
48 	/**
49 	 * [out] Shadow tcam DB handle
50 	 */
51 	void **shadow_db;
52 };
53 
54 /**
55  * Create the shadow db for a single direction
56  *
57  * The returned shadow db must be free using the free db API when no longer
58  * needed
59  */
60 int
61 tf_shadow_tcam_create_db(struct tf_shadow_tcam_create_db_parms *parms);
62 
63 /**
64  * Shadow TCAM free parameters
65  */
66 struct tf_shadow_tcam_free_db_parms {
67 	/**
68 	 * [in] Shadow tcam DB handle
69 	 */
70 	void *shadow_db;
71 };
72 
73 /**
74  * Free all resources associated with the shadow db
75  */
76 int
77 tf_shadow_tcam_free_db(struct tf_shadow_tcam_free_db_parms *parms);
78 
79 /**
80  * Shadow TCAM bind index parameters
81  */
82 struct tf_shadow_tcam_bind_index_parms {
83 	/**
84 	 * [in] Shadow tcam DB handle
85 	 */
86 	void *shadow_db;
87 	/**
88 	 * [in] receive or transmit direction
89 	 */
90 	enum tf_dir dir;
91 	/**
92 	 * [in] TCAM table type
93 	 */
94 	enum tf_tcam_tbl_type type;
95 	/**
96 	 * [in] index of the entry to program
97 	 */
98 	uint16_t idx;
99 	/**
100 	 * [in] struct containing key
101 	 */
102 	uint8_t *key;
103 	/**
104 	 * [in] struct containing mask fields
105 	 */
106 	uint8_t *mask;
107 	/**
108 	 * [in] key size in bits (if search)
109 	 */
110 	uint16_t key_size;
111 	/**
112 	 * [in] The hash bucket handled returned from the search
113 	 */
114 	uint32_t hb_handle;
115 };
116 
117 /**
118  * Binds the allocated tcam index with the hash and shadow tables
119  */
120 int
121 tf_shadow_tcam_bind_index(struct tf_shadow_tcam_bind_index_parms *parms);
122 
123 /**
124  * Shadow TCAM insert parameters
125  */
126 struct	tf_shadow_tcam_insert_parms {
127 	/**
128 	 * [in] Shadow tcam DB handle
129 	 */
130 	void *shadow_db;
131 	/**
132 	 * [in] The set parms from tf core
133 	 */
134 	struct tf_tcam_set_parms *sparms;
135 };
136 
137 /**
138  * Set the entry into the tcam manager hash and shadow tables
139  *
140  * The search must have been used prior to setting the entry so that the
141  * hash has been calculated and duplicate entries will not be added
142  */
143 int
144 tf_shadow_tcam_insert(struct tf_shadow_tcam_insert_parms *parms);
145 
146 /**
147  * Shadow TCAM remove parameters
148  */
149 struct tf_shadow_tcam_remove_parms {
150 	/**
151 	 * [in] Shadow tcam DB handle
152 	 */
153 	void *shadow_db;
154 	/**
155 	 * [in,out] The set parms from tf core
156 	 */
157 	struct tf_tcam_free_parms *fparms;
158 };
159 
160 /**
161  * Remove the entry from the tcam hash and shadow tables
162  *
163  * The search must have been used prior to setting the entry so that the
164  * hash has been calculated and duplicate entries will not be added
165  */
166 int
167 tf_shadow_tcam_remove(struct tf_shadow_tcam_remove_parms *parms);
168 
169 /**
170  * Shadow TCAM search parameters
171  */
172 struct tf_shadow_tcam_search_parms {
173 	/**
174 	 * [in] Shadow tcam DB handle
175 	 */
176 	void *shadow_db;
177 	/**
178 	 * [in,out] The search parameters from tf core
179 	 */
180 	struct tf_tcam_alloc_search_parms *sparms;
181 	/**
182 	 * [out] The hash handle to use for the set
183 	 */
184 	uint32_t hb_handle;
185 };
186 
187 /**
188  * Search for an entry in the tcam hash/shadow tables
189  *
190  * If there is a miss, but there is room for insertion, the hb_handle returned
191  * is used for insertion during the bind index API
192  */
193 int
194 tf_shadow_tcam_search(struct tf_shadow_tcam_search_parms *parms);
195 #endif
196