1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
14 #include "tf_device.h"
17 #include "tf_resources.h"
22 * The Session module provides session control support. A session is
23 * to the ULP layer known as a session_info instance. The session
24 * private data is the actual session.
27 * - The device and all the resources related to the device.
28 * - Any session sharing between ULP applications
33 #define TF_SESSION_ID_INVALID 0xFFFFFFFF /** Invalid Session ID define */
36 * At this stage we are using fixed size entries so that each
37 * stack entry represents either 2 or 4 RT (f/n)blocks. So we
38 * take the total block allocation for truflow and divide that
41 #ifdef TF_EM_ENTRY_IPV4_ONLY
42 #define TF_SESSION_EM_ENTRY_SIZE 2 /* 2 blocks per entry */
44 #define TF_SESSION_EM_ENTRY_SIZE 4 /* 4 blocks per entry */
50 * Shared memory containing private TruFlow session information.
51 * Through this structure the session can keep track of resource
52 * allocations and (if so configured) any shadow copy of flow
53 * information. It also holds info about Session Clients.
55 * Memory is assigned to the Truflow instance by way of
56 * tf_open_session. Memory is allocated and owned by i.e. ULP.
58 * Access control to this shared memory is handled by the spin_lock in
62 /** TrueFlow Version. Used to control the structure layout
63 * when sharing sessions. No guarantee that a secondary
64 * process would come from the same version of an executable.
66 struct tf_session_version ver;
69 * Session ID, allocated by FW on tf_open_session()
71 union tf_session_id session_id;
74 * Boolean controlling the use and availability of shadow
75 * copy. Shadow copy will allow the TruFlow Core to keep track
76 * of resource content on the firmware side without having to
77 * query firmware. Additional private session core_data will
78 * be allocated if this boolean is set to 'true', default
81 * Size of memory depends on the NVM Resource settings for the
87 * Session Reference Count. To keep track of functions per
88 * session the ref_count is updated. There is also a
89 * parallel TruFlow Firmware ref_count in case the TruFlow
90 * Core goes away without informing the Firmware.
95 * Session Reference Count for attached sessions. To keep
96 * track of application sharing of a session the
97 * ref_count_attach is updated.
99 uint8_t ref_count_attach;
104 struct tf_dev_info dev;
106 * Device init flag. False if Device is not fully initialized,
112 * Linked list of clients registered for this session
117 * em ext db reference for the session
119 void *em_ext_db_handle;
122 * tcam db reference for the session
124 void *tcam_db_handle;
127 * table db reference for the session
132 * identifier db reference for the session
137 * em db reference for the session
145 * Shared memory for each of the Session Clients. A session can have
146 * one or more clients.
148 struct tf_session_client {
150 * Linked list of clients
152 struct ll_entry ll_entry; /* For inserting in link list, must be
153 * first field of struct.
157 * String containing name of control channel interface to be
158 * used for this session to communicate with firmware.
160 * ctrl_chan_name will be used as part of a name for any
161 * shared memory allocation.
163 char ctrl_chan_name[TF_SESSION_NAME_MAX];
166 * Firmware FID, learned at time of Session Client create.
171 * Session Client ID, allocated by FW on tf_register_session()
173 union tf_session_client_id session_client_id;
177 * Session open parameter definition
179 struct tf_session_open_session_parms {
181 * [in] Pointer to the TF open session configuration
183 struct tf_open_session_parms *open_cfg;
187 * Session attach parameter definition
189 struct tf_session_attach_session_parms {
191 * [in] Pointer to the TF attach session configuration
193 struct tf_attach_session_parms *attach_cfg;
197 * Session close parameter definition
199 struct tf_session_close_session_parms {
207 union tf_session_id *session_id;
211 * @page session Session Management
213 * @ref tf_session_open_session
215 * @ref tf_session_attach_session
217 * @ref tf_session_close_session
219 * @ref tf_session_is_fid_supported
221 * @ref tf_session_get_session_internal
223 * @ref tf_session_get_session
225 * @ref tf_session_get_session_client
227 * @ref tf_session_find_session_client_by_name
229 * @ref tf_session_find_session_client_by_fid
231 * @ref tf_session_get_device
233 * @ref tf_session_get_fw_session_id
235 * @ref tf_session_get_session_id
239 * Creates a host session with a corresponding firmware session.
242 * Pointer to TF handle
245 * Pointer to the session open parameters
248 * - (0) if successful.
249 * - (-EINVAL) on failure.
251 int tf_session_open_session(struct tf *tfp,
252 struct tf_session_open_session_parms *parms);
255 * Attaches a previous created session.
258 * Pointer to TF handle
261 * Pointer to the session attach parameters
264 * - (0) if successful.
265 * - (-EINVAL) on failure.
267 int tf_session_attach_session(struct tf *tfp,
268 struct tf_session_attach_session_parms *parms);
271 * Closes a previous created session. Only possible if previous
272 * registered Clients had been unregistered first.
275 * Pointer to TF handle
278 * Pointer to the session close parameters.
281 * - (0) if successful.
282 * - (-EUSERS) if clients are still registered with the session.
283 * - (-EINVAL) on failure.
285 int tf_session_close_session(struct tf *tfp,
286 struct tf_session_close_session_parms *parms);
289 * Verifies that the fid is supported by the session. Used to assure
290 * that a function i.e. client/control channel is registered with the
294 * Pointer to TF Session handle
300 * - (true) if successful, else false
301 * - (-EINVAL) on failure.
304 tf_session_is_fid_supported(struct tf_session *tfs,
308 * Looks up the private session information from the TF session
309 * info. Does not perform a fid check against the registered
310 * clients. Should be used if tf_session_get_session() was used
311 * previously i.e. at the TF API boundary.
314 * Pointer to TF handle
317 * Pointer pointer to the session
320 * - (0) if successful.
321 * - (-EINVAL) on failure.
323 int tf_session_get_session_internal(struct tf *tfp,
324 struct tf_session **tfs);
327 * Looks up the private session information from the TF session
328 * info. Performs a fid check against the clients on the session.
331 * Pointer to TF handle
334 * Pointer pointer to the session
337 * - (0) if successful.
338 * - (-EINVAL) on failure.
340 int tf_session_get_session(struct tf *tfp,
341 struct tf_session **tfs);
344 * Looks up client within the session.
347 * Pointer pointer to the session
349 * [in] session_client_id
350 * Client id to look for within the session
353 * client if successful.
354 * - (NULL) on failure, client not found.
356 struct tf_session_client *
357 tf_session_get_session_client(struct tf_session *tfs,
358 union tf_session_client_id session_client_id);
361 * Looks up client using name within the session.
363 * [in] session, pointer to the session
365 * [in] session_client_name, name of the client to lookup in the session
368 * - Pointer to the session, if found.
369 * - (NULL) on failure, client not found.
371 struct tf_session_client *
372 tf_session_find_session_client_by_name(struct tf_session *tfs,
373 const char *ctrl_chan_name);
376 * Looks up client using the fid.
378 * [in] session, pointer to the session
380 * [in] fid, fid of the client to find
383 * - Pointer to the session, if found.
384 * - (NULL) on failure, client not found.
386 struct tf_session_client *
387 tf_session_find_session_client_by_fid(struct tf_session *tfs,
391 * Looks up the device information from the TF Session.
394 * Pointer to TF handle
397 * Pointer pointer to the device
400 * - (0) if successful.
401 * - (-EINVAL) on failure.
403 int tf_session_get_device(struct tf_session *tfs,
404 struct tf_dev_info **tfd);
407 * Looks up the FW Session id the requested TF handle.
410 * Pointer to TF handle
413 * Pointer to the session_id
416 * - (0) if successful.
417 * - (-EINVAL) on failure.
419 int tf_session_get_fw_session_id(struct tf *tfp,
420 uint8_t *fw_session_id);
423 * Looks up the Session id the requested TF handle.
426 * Pointer to TF handle
429 * Pointer to the session_id
432 * - (0) if successful.
433 * - (-EINVAL) on failure.
435 int tf_session_get_session_id(struct tf *tfp,
436 union tf_session_id *session_id);
439 * API to get the em_ext_db from tf_session.
442 * Pointer to TF handle
444 * [out] em_ext_db_handle, pointer to eem handle
447 * - (0) if successful.
448 * - (-EINVAL) on failure.
451 tf_session_get_em_ext_db(struct tf *tfp,
452 void **em_ext_db_handle);
455 * API to set the em_ext_db in tf_session.
458 * Pointer to TF handle
460 * [in] em_ext_db_handle, pointer to eem handle
463 * - (0) if successful.
464 * - (-EINVAL) on failure.
467 tf_session_set_em_ext_db(struct tf *tfp,
468 void *em_ext_db_handle);
471 * API to get the db from tf_session.
474 * Pointer to TF handle
476 * [out] db_handle, pointer to db handle
479 * - (0) if successful.
480 * - (-EINVAL) on failure.
483 tf_session_get_db(struct tf *tfp,
484 enum tf_module_type type,
488 * API to set the db in tf_session.
491 * Pointer to TF handle
493 * [in] db_handle, pointer to db handle
496 * - (0) if successful.
497 * - (-EINVAL) on failure.
500 tf_session_set_db(struct tf *tfp,
501 enum tf_module_type type,
503 #endif /* _TF_SESSION_H_ */