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 /** Session ID, allocated by FW on tf_open_session() */
67 union tf_session_id session_id;
70 * String containing name of control channel interface to be
71 * used for this session to communicate with firmware.
73 * ctrl_chan_name will be used as part of a name for any
74 * shared memory allocation.
76 char ctrl_chan_name[TF_SESSION_NAME_MAX];
79 * Boolean controlling the use and availability of shadow
80 * copy. Shadow copy will allow the TruFlow Core to keep track
81 * of resource content on the firmware side without having to
82 * query firmware. Additional private session core_data will
83 * be allocated if this boolean is set to 'true', default
86 * Size of memory depends on the NVM Resource settings for the
92 * Session Reference Count. To keep track of functions per
93 * session the ref_count is incremented. There is also a
94 * parallel TruFlow Firmware ref_count in case the TruFlow
95 * Core goes away without informing the Firmware.
100 struct tf_dev_info *dev;
102 /** Session HW and SRAM resources */
103 struct tf_rm_db resc;
105 /* Session HW resource pools */
107 /** RX L2 CTXT TCAM Pool */
108 BITALLOC_INST(TF_L2_CTXT_TCAM_POOL_NAME_RX, TF_NUM_L2_CTXT_TCAM);
109 /** TX L2 CTXT TCAM Pool */
110 BITALLOC_INST(TF_L2_CTXT_TCAM_POOL_NAME_TX, TF_NUM_L2_CTXT_TCAM);
112 /** RX Profile Func Pool */
113 BITALLOC_INST(TF_PROF_FUNC_POOL_NAME_RX, TF_NUM_PROF_FUNC);
114 /** TX Profile Func Pool */
115 BITALLOC_INST(TF_PROF_FUNC_POOL_NAME_TX, TF_NUM_PROF_FUNC);
117 /** RX Profile TCAM Pool */
118 BITALLOC_INST(TF_PROF_TCAM_POOL_NAME_RX, TF_NUM_PROF_TCAM);
119 /** TX Profile TCAM Pool */
120 BITALLOC_INST(TF_PROF_TCAM_POOL_NAME_TX, TF_NUM_PROF_TCAM);
122 /** RX EM Profile ID Pool */
123 BITALLOC_INST(TF_EM_PROF_ID_POOL_NAME_RX, TF_NUM_EM_PROF_ID);
124 /** TX EM Key Pool */
125 BITALLOC_INST(TF_EM_PROF_ID_POOL_NAME_TX, TF_NUM_EM_PROF_ID);
127 /** RX WC Profile Pool */
128 BITALLOC_INST(TF_WC_TCAM_PROF_ID_POOL_NAME_RX, TF_NUM_WC_PROF_ID);
129 /** TX WC Profile Pool */
130 BITALLOC_INST(TF_WC_TCAM_PROF_ID_POOL_NAME_TX, TF_NUM_WC_PROF_ID);
132 /* TBD, how do we want to handle EM records ?*/
133 /* EM Records are not controlled by way of a pool */
135 /** RX WC TCAM Pool */
136 BITALLOC_INST(TF_WC_TCAM_POOL_NAME_RX, TF_NUM_WC_TCAM_ROW);
137 /** TX WC TCAM Pool */
138 BITALLOC_INST(TF_WC_TCAM_POOL_NAME_TX, TF_NUM_WC_TCAM_ROW);
140 /** RX Meter Profile Pool */
141 BITALLOC_INST(TF_METER_PROF_POOL_NAME_RX, TF_NUM_METER_PROF);
142 /** TX Meter Profile Pool */
143 BITALLOC_INST(TF_METER_PROF_POOL_NAME_TX, TF_NUM_METER_PROF);
145 /** RX Meter Instance Pool */
146 BITALLOC_INST(TF_METER_INST_POOL_NAME_RX, TF_NUM_METER);
148 BITALLOC_INST(TF_METER_INST_POOL_NAME_TX, TF_NUM_METER);
150 /** RX Mirror Configuration Pool*/
151 BITALLOC_INST(TF_MIRROR_POOL_NAME_RX, TF_NUM_MIRROR);
152 /** RX Mirror Configuration Pool */
153 BITALLOC_INST(TF_MIRROR_POOL_NAME_TX, TF_NUM_MIRROR);
156 BITALLOC_INST(TF_UPAR_POOL_NAME_RX, TF_NUM_UPAR);
158 BITALLOC_INST(TF_UPAR_POOL_NAME_TX, TF_NUM_UPAR);
160 /** RX SP TCAM Pool */
161 BITALLOC_INST(TF_SP_TCAM_POOL_NAME_RX, TF_NUM_SP_TCAM);
162 /** TX SP TCAM Pool */
163 BITALLOC_INST(TF_SP_TCAM_POOL_NAME_TX, TF_NUM_SP_TCAM);
166 BITALLOC_INST(TF_FKB_POOL_NAME_RX, TF_NUM_FKB);
168 BITALLOC_INST(TF_FKB_POOL_NAME_TX, TF_NUM_FKB);
170 /** RX Table Scope Pool */
171 BITALLOC_INST(TF_TBL_SCOPE_POOL_NAME_RX, TF_NUM_TBL_SCOPE);
172 /** TX Table Scope Pool */
173 BITALLOC_INST(TF_TBL_SCOPE_POOL_NAME_TX, TF_NUM_TBL_SCOPE);
175 /** RX L2 Func Pool */
176 BITALLOC_INST(TF_L2_FUNC_POOL_NAME_RX, TF_NUM_L2_FUNC);
177 /** TX L2 Func Pool */
178 BITALLOC_INST(TF_L2_FUNC_POOL_NAME_TX, TF_NUM_L2_FUNC);
180 /** RX Epoch0 Pool */
181 BITALLOC_INST(TF_EPOCH0_POOL_NAME_RX, TF_NUM_EPOCH0);
182 /** TX Epoch0 Pool */
183 BITALLOC_INST(TF_EPOCH0_POOL_NAME_TX, TF_NUM_EPOCH0);
185 /** TX Epoch1 Pool */
186 BITALLOC_INST(TF_EPOCH1_POOL_NAME_RX, TF_NUM_EPOCH1);
187 /** TX Epoch1 Pool */
188 BITALLOC_INST(TF_EPOCH1_POOL_NAME_TX, TF_NUM_EPOCH1);
190 /** RX MetaData Profile Pool */
191 BITALLOC_INST(TF_METADATA_POOL_NAME_RX, TF_NUM_METADATA);
192 /** TX MetaData Profile Pool */
193 BITALLOC_INST(TF_METADATA_POOL_NAME_TX, TF_NUM_METADATA);
195 /** RX Connection Tracking State Pool */
196 BITALLOC_INST(TF_CT_STATE_POOL_NAME_RX, TF_NUM_CT_STATE);
197 /** TX Connection Tracking State Pool */
198 BITALLOC_INST(TF_CT_STATE_POOL_NAME_TX, TF_NUM_CT_STATE);
200 /** RX Range Profile Pool */
201 BITALLOC_INST(TF_RANGE_PROF_POOL_NAME_RX, TF_NUM_RANGE_PROF);
202 /** TX Range Profile Pool */
203 BITALLOC_INST(TF_RANGE_PROF_POOL_NAME_TX, TF_NUM_RANGE_PROF);
206 BITALLOC_INST(TF_RANGE_ENTRY_POOL_NAME_RX, TF_NUM_RANGE_ENTRY);
208 BITALLOC_INST(TF_RANGE_ENTRY_POOL_NAME_TX, TF_NUM_RANGE_ENTRY);
211 BITALLOC_INST(TF_LAG_ENTRY_POOL_NAME_RX, TF_NUM_LAG_ENTRY);
213 BITALLOC_INST(TF_LAG_ENTRY_POOL_NAME_TX, TF_NUM_LAG_ENTRY);
215 /* Session SRAM pools */
217 /** RX Full Action Record Pool */
218 BITALLOC_INST(TF_SRAM_FULL_ACTION_POOL_NAME_RX,
219 TF_RSVD_SRAM_FULL_ACTION_RX);
220 /** TX Full Action Record Pool */
221 BITALLOC_INST(TF_SRAM_FULL_ACTION_POOL_NAME_TX,
222 TF_RSVD_SRAM_FULL_ACTION_TX);
224 /** RX Multicast Group Pool, only RX is supported */
225 BITALLOC_INST(TF_SRAM_MCG_POOL_NAME_RX,
226 TF_RSVD_SRAM_MCG_RX);
228 /** RX Encap 8B Pool*/
229 BITALLOC_INST(TF_SRAM_ENCAP_8B_POOL_NAME_RX,
230 TF_RSVD_SRAM_ENCAP_8B_RX);
231 /** TX Encap 8B Pool*/
232 BITALLOC_INST(TF_SRAM_ENCAP_8B_POOL_NAME_TX,
233 TF_RSVD_SRAM_ENCAP_8B_TX);
235 /** RX Encap 16B Pool */
236 BITALLOC_INST(TF_SRAM_ENCAP_16B_POOL_NAME_RX,
237 TF_RSVD_SRAM_ENCAP_16B_RX);
238 /** TX Encap 16B Pool */
239 BITALLOC_INST(TF_SRAM_ENCAP_16B_POOL_NAME_TX,
240 TF_RSVD_SRAM_ENCAP_16B_TX);
242 /** TX Encap 64B Pool, only TX is supported */
243 BITALLOC_INST(TF_SRAM_ENCAP_64B_POOL_NAME_TX,
244 TF_RSVD_SRAM_ENCAP_64B_TX);
246 /** RX Source Properties SMAC Pool */
247 BITALLOC_INST(TF_SRAM_SP_SMAC_POOL_NAME_RX,
248 TF_RSVD_SRAM_SP_SMAC_RX);
249 /** TX Source Properties SMAC Pool */
250 BITALLOC_INST(TF_SRAM_SP_SMAC_POOL_NAME_TX,
251 TF_RSVD_SRAM_SP_SMAC_TX);
253 /** TX Source Properties SMAC IPv4 Pool, only TX is supported */
254 BITALLOC_INST(TF_SRAM_SP_SMAC_IPV4_POOL_NAME_TX,
255 TF_RSVD_SRAM_SP_SMAC_IPV4_TX);
257 /** TX Source Properties SMAC IPv6 Pool, only TX is supported */
258 BITALLOC_INST(TF_SRAM_SP_SMAC_IPV6_POOL_NAME_TX,
259 TF_RSVD_SRAM_SP_SMAC_IPV6_TX);
261 /** RX Counter 64B Pool */
262 BITALLOC_INST(TF_SRAM_STATS_64B_POOL_NAME_RX,
263 TF_RSVD_SRAM_COUNTER_64B_RX);
264 /** TX Counter 64B Pool */
265 BITALLOC_INST(TF_SRAM_STATS_64B_POOL_NAME_TX,
266 TF_RSVD_SRAM_COUNTER_64B_TX);
268 /** RX NAT Source Port Pool */
269 BITALLOC_INST(TF_SRAM_NAT_SPORT_POOL_NAME_RX,
270 TF_RSVD_SRAM_NAT_SPORT_RX);
271 /** TX NAT Source Port Pool */
272 BITALLOC_INST(TF_SRAM_NAT_SPORT_POOL_NAME_TX,
273 TF_RSVD_SRAM_NAT_SPORT_TX);
275 /** RX NAT Destination Port Pool */
276 BITALLOC_INST(TF_SRAM_NAT_DPORT_POOL_NAME_RX,
277 TF_RSVD_SRAM_NAT_DPORT_RX);
278 /** TX NAT Destination Port Pool */
279 BITALLOC_INST(TF_SRAM_NAT_DPORT_POOL_NAME_TX,
280 TF_RSVD_SRAM_NAT_DPORT_TX);
282 /** RX NAT Source IPv4 Pool */
283 BITALLOC_INST(TF_SRAM_NAT_S_IPV4_POOL_NAME_RX,
284 TF_RSVD_SRAM_NAT_S_IPV4_RX);
285 /** TX NAT Source IPv4 Pool */
286 BITALLOC_INST(TF_SRAM_NAT_S_IPV4_POOL_NAME_TX,
287 TF_RSVD_SRAM_NAT_S_IPV4_TX);
289 /** RX NAT Destination IPv4 Pool */
290 BITALLOC_INST(TF_SRAM_NAT_D_IPV4_POOL_NAME_RX,
291 TF_RSVD_SRAM_NAT_D_IPV4_RX);
292 /** TX NAT IPv4 Destination Pool */
293 BITALLOC_INST(TF_SRAM_NAT_D_IPV4_POOL_NAME_TX,
294 TF_RSVD_SRAM_NAT_D_IPV4_TX);
297 * Pools not allocated from HCAPI RM
300 /** RX L2 Ctx Remap ID Pool */
301 BITALLOC_INST(TF_L2_CTXT_REMAP_POOL_NAME_RX, TF_NUM_L2_CTXT_TCAM);
302 /** TX L2 Ctx Remap ID Pool */
303 BITALLOC_INST(TF_L2_CTXT_REMAP_POOL_NAME_TX, TF_NUM_L2_CTXT_TCAM);
305 /** CRC32 seed table */
306 #define TF_LKUP_SEED_MEM_SIZE 512
307 uint32_t lkup_em_seed_mem[TF_DIR_MAX][TF_LKUP_SEED_MEM_SIZE];
309 /** Lookup3 init values */
310 uint32_t lkup_lkup3_init_cfg[TF_DIR_MAX];
312 /** Table scope array */
313 struct tf_tbl_scope_cb tbl_scopes[TF_NUM_TBL_SCOPE];
318 struct stack em_pool[TF_DIR_MAX];
322 * Session open parameter definition
324 struct tf_session_open_session_parms {
326 * [in] Pointer to the TF open session configuration
328 struct tf_open_session_parms *open_cfg;
332 * Session attach parameter definition
334 struct tf_session_attach_session_parms {
336 * [in] Pointer to the TF attach session configuration
338 struct tf_attach_session_parms *attach_cfg;
342 * Session close parameter definition
344 struct tf_session_close_session_parms {
346 union tf_session_id *session_id;
350 * @page session Session Management
352 * @ref tf_session_open_session
354 * @ref tf_session_attach_session
356 * @ref tf_session_close_session
358 * @ref tf_session_get_session
360 * @ref tf_session_get_device
362 * @ref tf_session_get_fw_session_id
366 * Creates a host session with a corresponding firmware session.
369 * Pointer to TF handle
372 * Pointer to the session open parameters
375 * - (0) if successful.
376 * - (-EINVAL) on failure.
378 int tf_session_open_session(struct tf *tfp,
379 struct tf_session_open_session_parms *parms);
382 * Attaches a previous created session.
385 * Pointer to TF handle
388 * Pointer to the session attach parameters
391 * - (0) if successful.
392 * - (-EINVAL) on failure.
394 int tf_session_attach_session(struct tf *tfp,
395 struct tf_session_attach_session_parms *parms);
398 * Closes a previous created session.
401 * Pointer to TF handle
404 * Pointer to the session close parameters.
407 * - (0) if successful.
408 * - (-EINVAL) on failure.
410 int tf_session_close_session(struct tf *tfp,
411 struct tf_session_close_session_parms *parms);
414 * Looks up the private session information from the TF session info.
417 * Pointer to TF handle
420 * Pointer pointer to the session
423 * - (0) if successful.
424 * - (-EINVAL) on failure.
426 int tf_session_get_session(struct tf *tfp,
427 struct tf_session **tfs);
430 * Looks up the device information from the TF Session.
433 * Pointer to TF handle
436 * Pointer pointer to the device
439 * - (0) if successful.
440 * - (-EINVAL) on failure.
442 int tf_session_get_device(struct tf_session *tfs,
443 struct tf_dev_info **tfd);
446 * Looks up the FW session id of the firmware connection for the
447 * requested TF handle.
450 * Pointer to TF handle
453 * Pointer to the session_id
456 * - (0) if successful.
457 * - (-EINVAL) on failure.
459 int tf_session_get_fw_session_id(struct tf *tfp,
460 uint8_t *fw_session_id);
462 #endif /* _TF_SESSION_H_ */