1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
14 #include "tf_device.h"
20 * The Session module provides session control support. A session is
21 * to the ULP layer known as a session_info instance. The session
22 * private data is the actual session.
25 * - The device and all the resources related to the device.
26 * - Any session sharing between ULP applications
31 #define TF_SESSIONS_MAX 1 /** max # sessions */
32 #define TF_SESSION_ID_INVALID 0xFFFFFFFF /** Invalid Session ID define */
35 * Number of EM entries. Static for now will be removed
36 * when parameter added at a later date. At this stage we
37 * are using fixed size entries so that each stack entry
38 * represents 4 RT (f/n)blocks. So we take the total block
39 * allocation for truflow and divide that by 4.
41 #define TF_SESSION_TOTAL_FN_BLOCKS (1024 * 8) /* 8K blocks */
42 #define TF_SESSION_EM_ENTRY_SIZE 4 /* 4 blocks per entry */
43 #define TF_SESSION_EM_POOL_SIZE \
44 (TF_SESSION_TOTAL_FN_BLOCKS / TF_SESSION_EM_ENTRY_SIZE)
48 * Shared memory containing private TruFlow session information.
49 * Through this structure the session can keep track of resource
50 * allocations and (if so configured) any shadow copy of flow
53 * Memory is assigned to the Truflow instance by way of
54 * tf_open_session. Memory is allocated and owned by i.e. ULP.
56 * Access control to this shared memory is handled by the spin_lock in
60 /** TrueFlow Version. Used to control the structure layout
61 * when sharing sessions. No guarantee that a secondary
62 * process would come from the same version of an executable.
64 struct tf_session_version ver;
66 /** Device type, provided by tf_open_session().
68 enum tf_device_type device_type;
70 /** Session ID, allocated by FW on tf_open_session().
72 union tf_session_id session_id;
75 * String containing name of control channel interface to be
76 * used for this session to communicate with firmware.
78 * ctrl_chan_name will be used as part of a name for any
79 * shared memory allocation.
81 char ctrl_chan_name[TF_SESSION_NAME_MAX];
84 * Boolean controlling the use and availability of shadow
85 * copy. Shadow copy will allow the TruFlow Core to keep track
86 * of resource content on the firmware side without having to
87 * query firmware. Additional private session core_data will
88 * be allocated if this boolean is set to 'true', default
91 * Size of memory depends on the NVM Resource settings for the
97 * Session Reference Count. To keep track of functions per
98 * session the ref_count is incremented. There is also a
99 * parallel TruFlow Firmware ref_count in case the TruFlow
100 * Core goes away without informing the Firmware.
105 struct tf_dev_info *dev;
107 /** Session HW and SRAM resources */
108 struct tf_rm_db resc;
110 /* Session HW resource pools */
112 /** RX L2 CTXT TCAM Pool */
113 BITALLOC_INST(TF_L2_CTXT_TCAM_POOL_NAME_RX, TF_NUM_L2_CTXT_TCAM);
114 /** TX L2 CTXT TCAM Pool */
115 BITALLOC_INST(TF_L2_CTXT_TCAM_POOL_NAME_TX, TF_NUM_L2_CTXT_TCAM);
117 /** RX Profile Func Pool */
118 BITALLOC_INST(TF_PROF_FUNC_POOL_NAME_RX, TF_NUM_PROF_FUNC);
119 /** TX Profile Func Pool */
120 BITALLOC_INST(TF_PROF_FUNC_POOL_NAME_TX, TF_NUM_PROF_FUNC);
122 /** RX Profile TCAM Pool */
123 BITALLOC_INST(TF_PROF_TCAM_POOL_NAME_RX, TF_NUM_PROF_TCAM);
124 /** TX Profile TCAM Pool */
125 BITALLOC_INST(TF_PROF_TCAM_POOL_NAME_TX, TF_NUM_PROF_TCAM);
127 /** RX EM Profile ID Pool */
128 BITALLOC_INST(TF_EM_PROF_ID_POOL_NAME_RX, TF_NUM_EM_PROF_ID);
129 /** TX EM Key Pool */
130 BITALLOC_INST(TF_EM_PROF_ID_POOL_NAME_TX, TF_NUM_EM_PROF_ID);
132 /** RX WC Profile Pool */
133 BITALLOC_INST(TF_WC_TCAM_PROF_ID_POOL_NAME_RX, TF_NUM_WC_PROF_ID);
134 /** TX WC Profile Pool */
135 BITALLOC_INST(TF_WC_TCAM_PROF_ID_POOL_NAME_TX, TF_NUM_WC_PROF_ID);
137 /* TBD, how do we want to handle EM records ?*/
138 /* EM Records are not controlled by way of a pool */
140 /** RX WC TCAM Pool */
141 BITALLOC_INST(TF_WC_TCAM_POOL_NAME_RX, TF_NUM_WC_TCAM_ROW);
142 /** TX WC TCAM Pool */
143 BITALLOC_INST(TF_WC_TCAM_POOL_NAME_TX, TF_NUM_WC_TCAM_ROW);
145 /** RX Meter Profile Pool */
146 BITALLOC_INST(TF_METER_PROF_POOL_NAME_RX, TF_NUM_METER_PROF);
147 /** TX Meter Profile Pool */
148 BITALLOC_INST(TF_METER_PROF_POOL_NAME_TX, TF_NUM_METER_PROF);
150 /** RX Meter Instance Pool */
151 BITALLOC_INST(TF_METER_INST_POOL_NAME_RX, TF_NUM_METER);
153 BITALLOC_INST(TF_METER_INST_POOL_NAME_TX, TF_NUM_METER);
155 /** RX Mirror Configuration Pool*/
156 BITALLOC_INST(TF_MIRROR_POOL_NAME_RX, TF_NUM_MIRROR);
157 /** RX Mirror Configuration Pool */
158 BITALLOC_INST(TF_MIRROR_POOL_NAME_TX, TF_NUM_MIRROR);
161 BITALLOC_INST(TF_UPAR_POOL_NAME_RX, TF_NUM_UPAR);
163 BITALLOC_INST(TF_UPAR_POOL_NAME_TX, TF_NUM_UPAR);
165 /** RX SP TCAM Pool */
166 BITALLOC_INST(TF_SP_TCAM_POOL_NAME_RX, TF_NUM_SP_TCAM);
167 /** TX SP TCAM Pool */
168 BITALLOC_INST(TF_SP_TCAM_POOL_NAME_TX, TF_NUM_SP_TCAM);
171 BITALLOC_INST(TF_FKB_POOL_NAME_RX, TF_NUM_FKB);
173 BITALLOC_INST(TF_FKB_POOL_NAME_TX, TF_NUM_FKB);
175 /** RX Table Scope Pool */
176 BITALLOC_INST(TF_TBL_SCOPE_POOL_NAME_RX, TF_NUM_TBL_SCOPE);
177 /** TX Table Scope Pool */
178 BITALLOC_INST(TF_TBL_SCOPE_POOL_NAME_TX, TF_NUM_TBL_SCOPE);
180 /** RX L2 Func Pool */
181 BITALLOC_INST(TF_L2_FUNC_POOL_NAME_RX, TF_NUM_L2_FUNC);
182 /** TX L2 Func Pool */
183 BITALLOC_INST(TF_L2_FUNC_POOL_NAME_TX, TF_NUM_L2_FUNC);
185 /** RX Epoch0 Pool */
186 BITALLOC_INST(TF_EPOCH0_POOL_NAME_RX, TF_NUM_EPOCH0);
187 /** TX Epoch0 Pool */
188 BITALLOC_INST(TF_EPOCH0_POOL_NAME_TX, TF_NUM_EPOCH0);
190 /** TX Epoch1 Pool */
191 BITALLOC_INST(TF_EPOCH1_POOL_NAME_RX, TF_NUM_EPOCH1);
192 /** TX Epoch1 Pool */
193 BITALLOC_INST(TF_EPOCH1_POOL_NAME_TX, TF_NUM_EPOCH1);
195 /** RX MetaData Profile Pool */
196 BITALLOC_INST(TF_METADATA_POOL_NAME_RX, TF_NUM_METADATA);
197 /** TX MetaData Profile Pool */
198 BITALLOC_INST(TF_METADATA_POOL_NAME_TX, TF_NUM_METADATA);
200 /** RX Connection Tracking State Pool */
201 BITALLOC_INST(TF_CT_STATE_POOL_NAME_RX, TF_NUM_CT_STATE);
202 /** TX Connection Tracking State Pool */
203 BITALLOC_INST(TF_CT_STATE_POOL_NAME_TX, TF_NUM_CT_STATE);
205 /** RX Range Profile Pool */
206 BITALLOC_INST(TF_RANGE_PROF_POOL_NAME_RX, TF_NUM_RANGE_PROF);
207 /** TX Range Profile Pool */
208 BITALLOC_INST(TF_RANGE_PROF_POOL_NAME_TX, TF_NUM_RANGE_PROF);
211 BITALLOC_INST(TF_RANGE_ENTRY_POOL_NAME_RX, TF_NUM_RANGE_ENTRY);
213 BITALLOC_INST(TF_RANGE_ENTRY_POOL_NAME_TX, TF_NUM_RANGE_ENTRY);
216 BITALLOC_INST(TF_LAG_ENTRY_POOL_NAME_RX, TF_NUM_LAG_ENTRY);
218 BITALLOC_INST(TF_LAG_ENTRY_POOL_NAME_TX, TF_NUM_LAG_ENTRY);
220 /* Session SRAM pools */
222 /** RX Full Action Record Pool */
223 BITALLOC_INST(TF_SRAM_FULL_ACTION_POOL_NAME_RX,
224 TF_RSVD_SRAM_FULL_ACTION_RX);
225 /** TX Full Action Record Pool */
226 BITALLOC_INST(TF_SRAM_FULL_ACTION_POOL_NAME_TX,
227 TF_RSVD_SRAM_FULL_ACTION_TX);
229 /** RX Multicast Group Pool, only RX is supported */
230 BITALLOC_INST(TF_SRAM_MCG_POOL_NAME_RX,
231 TF_RSVD_SRAM_MCG_RX);
233 /** RX Encap 8B Pool*/
234 BITALLOC_INST(TF_SRAM_ENCAP_8B_POOL_NAME_RX,
235 TF_RSVD_SRAM_ENCAP_8B_RX);
236 /** TX Encap 8B Pool*/
237 BITALLOC_INST(TF_SRAM_ENCAP_8B_POOL_NAME_TX,
238 TF_RSVD_SRAM_ENCAP_8B_TX);
240 /** RX Encap 16B Pool */
241 BITALLOC_INST(TF_SRAM_ENCAP_16B_POOL_NAME_RX,
242 TF_RSVD_SRAM_ENCAP_16B_RX);
243 /** TX Encap 16B Pool */
244 BITALLOC_INST(TF_SRAM_ENCAP_16B_POOL_NAME_TX,
245 TF_RSVD_SRAM_ENCAP_16B_TX);
247 /** TX Encap 64B Pool, only TX is supported */
248 BITALLOC_INST(TF_SRAM_ENCAP_64B_POOL_NAME_TX,
249 TF_RSVD_SRAM_ENCAP_64B_TX);
251 /** RX Source Properties SMAC Pool */
252 BITALLOC_INST(TF_SRAM_SP_SMAC_POOL_NAME_RX,
253 TF_RSVD_SRAM_SP_SMAC_RX);
254 /** TX Source Properties SMAC Pool */
255 BITALLOC_INST(TF_SRAM_SP_SMAC_POOL_NAME_TX,
256 TF_RSVD_SRAM_SP_SMAC_TX);
258 /** TX Source Properties SMAC IPv4 Pool, only TX is supported */
259 BITALLOC_INST(TF_SRAM_SP_SMAC_IPV4_POOL_NAME_TX,
260 TF_RSVD_SRAM_SP_SMAC_IPV4_TX);
262 /** TX Source Properties SMAC IPv6 Pool, only TX is supported */
263 BITALLOC_INST(TF_SRAM_SP_SMAC_IPV6_POOL_NAME_TX,
264 TF_RSVD_SRAM_SP_SMAC_IPV6_TX);
266 /** RX Counter 64B Pool */
267 BITALLOC_INST(TF_SRAM_STATS_64B_POOL_NAME_RX,
268 TF_RSVD_SRAM_COUNTER_64B_RX);
269 /** TX Counter 64B Pool */
270 BITALLOC_INST(TF_SRAM_STATS_64B_POOL_NAME_TX,
271 TF_RSVD_SRAM_COUNTER_64B_TX);
273 /** RX NAT Source Port Pool */
274 BITALLOC_INST(TF_SRAM_NAT_SPORT_POOL_NAME_RX,
275 TF_RSVD_SRAM_NAT_SPORT_RX);
276 /** TX NAT Source Port Pool */
277 BITALLOC_INST(TF_SRAM_NAT_SPORT_POOL_NAME_TX,
278 TF_RSVD_SRAM_NAT_SPORT_TX);
280 /** RX NAT Destination Port Pool */
281 BITALLOC_INST(TF_SRAM_NAT_DPORT_POOL_NAME_RX,
282 TF_RSVD_SRAM_NAT_DPORT_RX);
283 /** TX NAT Destination Port Pool */
284 BITALLOC_INST(TF_SRAM_NAT_DPORT_POOL_NAME_TX,
285 TF_RSVD_SRAM_NAT_DPORT_TX);
287 /** RX NAT Source IPv4 Pool */
288 BITALLOC_INST(TF_SRAM_NAT_S_IPV4_POOL_NAME_RX,
289 TF_RSVD_SRAM_NAT_S_IPV4_RX);
290 /** TX NAT Source IPv4 Pool */
291 BITALLOC_INST(TF_SRAM_NAT_S_IPV4_POOL_NAME_TX,
292 TF_RSVD_SRAM_NAT_S_IPV4_TX);
294 /** RX NAT Destination IPv4 Pool */
295 BITALLOC_INST(TF_SRAM_NAT_D_IPV4_POOL_NAME_RX,
296 TF_RSVD_SRAM_NAT_D_IPV4_RX);
297 /** TX NAT IPv4 Destination Pool */
298 BITALLOC_INST(TF_SRAM_NAT_D_IPV4_POOL_NAME_TX,
299 TF_RSVD_SRAM_NAT_D_IPV4_TX);
302 * Pools not allocated from HCAPI RM
305 /** RX L2 Ctx Remap ID Pool */
306 BITALLOC_INST(TF_L2_CTXT_REMAP_POOL_NAME_RX, TF_NUM_L2_CTXT_TCAM);
307 /** TX L2 Ctx Remap ID Pool */
308 BITALLOC_INST(TF_L2_CTXT_REMAP_POOL_NAME_TX, TF_NUM_L2_CTXT_TCAM);
310 /** CRC32 seed table */
311 #define TF_LKUP_SEED_MEM_SIZE 512
312 uint32_t lkup_em_seed_mem[TF_DIR_MAX][TF_LKUP_SEED_MEM_SIZE];
314 /** Lookup3 init values */
315 uint32_t lkup_lkup3_init_cfg[TF_DIR_MAX];
317 /** Table scope array */
318 struct tf_tbl_scope_cb tbl_scopes[TF_NUM_TBL_SCOPE];
323 struct stack em_pool[TF_DIR_MAX];
327 * @page session Session Management
329 * @ref tf_session_get_session
331 * @ref tf_session_get_device
335 * Looks up the private session information from the TF session info.
338 * Pointer to TF handle
341 * Pointer to the session
344 * - (0) if successful.
345 * - (-EINVAL) on failure.
347 int tf_session_get_session(struct tf *tfp,
348 struct tf_session *tfs);
351 * Looks up the device information from the TF Session.
354 * Pointer to TF handle
357 * Pointer to the device
360 * - (0) if successful.
361 * - (-EINVAL) on failure.
363 int tf_session_get_device(struct tf_session *tfs,
364 struct tf_dev_info *tfd);
366 #endif /* _TF_SESSION_H_ */