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 shared session.
75 * Shared session will allow the application to share resources
76 * on the firmware side without having to allocate them on firmware.
77 * Additional private session core_data will be allocated if this
78 * boolean is set to 'true', default 'false'.
84 * This flag indicates the shared session on firmware side is created
85 * by this session. Some privileges may be assigned to this session.
88 bool shared_session_creator;
91 * Boolean controlling the use and availability of shadow
92 * copy. Shadow copy will allow the TruFlow Core to keep track
93 * of resource content on the firmware side without having to
94 * query firmware. Additional private session core_data will
95 * be allocated if this boolean is set to 'true', default
98 * Size of memory depends on the NVM Resource settings for the
104 * Session Reference Count. To keep track of functions per
105 * session the ref_count is updated. There is also a
106 * parallel TruFlow Firmware ref_count in case the TruFlow
107 * Core goes away without informing the Firmware.
112 * Session Reference Count for attached sessions. To keep
113 * track of application sharing of a session the
114 * ref_count_attach is updated.
116 uint8_t ref_count_attach;
121 struct tf_dev_info dev;
123 * Device init flag. False if Device is not fully initialized,
129 * Linked list of clients registered for this session
134 * em ext db reference for the session
136 void *em_ext_db_handle;
139 * tcam db reference for the session
141 void *tcam_db_handle;
144 * table db reference for the session
149 * identifier db reference for the session
154 * em db reference for the session
159 * the pointer to the parent bp struct
164 * EM allocator for session
166 void *em_pool[TF_DIR_MAX];
172 * Shared memory for each of the Session Clients. A session can have
173 * one or more clients.
175 struct tf_session_client {
177 * Linked list of clients
179 struct ll_entry ll_entry; /* For inserting in link list, must be
180 * first field of struct.
184 * String containing name of control channel interface to be
185 * used for this session to communicate with firmware.
187 * ctrl_chan_name will be used as part of a name for any
188 * shared memory allocation.
190 char ctrl_chan_name[TF_SESSION_NAME_MAX];
193 * Firmware FID, learned at time of Session Client create.
198 * Session Client ID, allocated by FW on tf_register_session()
200 union tf_session_client_id session_client_id;
204 * Session open parameter definition
206 struct tf_session_open_session_parms {
208 * [in] Pointer to the TF open session configuration
210 struct tf_open_session_parms *open_cfg;
214 * Session attach parameter definition
216 struct tf_session_attach_session_parms {
218 * [in] Pointer to the TF attach session configuration
220 struct tf_attach_session_parms *attach_cfg;
224 * Session close parameter definition
226 struct tf_session_close_session_parms {
234 union tf_session_id *session_id;
238 * @page session Session Management
240 * @ref tf_session_open_session
242 * @ref tf_session_attach_session
244 * @ref tf_session_close_session
246 * @ref tf_session_is_fid_supported
248 * @ref tf_session_get_session_internal
250 * @ref tf_session_get_session
252 * @ref tf_session_get_session_client
254 * @ref tf_session_find_session_client_by_name
256 * @ref tf_session_find_session_client_by_fid
258 * @ref tf_session_get_device
260 * @ref tf_session_get_fw_session_id
262 * @ref tf_session_get_session_id
266 * Creates a host session with a corresponding firmware session.
269 * Pointer to TF handle
272 * Pointer to the session open parameters
275 * - (0) if successful.
276 * - (-EINVAL) on failure.
278 int tf_session_open_session(struct tf *tfp,
279 struct tf_session_open_session_parms *parms);
282 * Attaches a previous created session.
285 * Pointer to TF handle
288 * Pointer to the session attach parameters
291 * - (0) if successful.
292 * - (-EINVAL) on failure.
294 int tf_session_attach_session(struct tf *tfp,
295 struct tf_session_attach_session_parms *parms);
298 * Closes a previous created session. Only possible if previous
299 * registered Clients had been unregistered first.
302 * Pointer to TF handle
305 * Pointer to the session close parameters.
308 * - (0) if successful.
309 * - (-EUSERS) if clients are still registered with the session.
310 * - (-EINVAL) on failure.
312 int tf_session_close_session(struct tf *tfp,
313 struct tf_session_close_session_parms *parms);
316 * Verifies that the fid is supported by the session. Used to assure
317 * that a function i.e. client/control channel is registered with the
321 * Pointer to TF Session handle
327 * - (true) if successful, else false
328 * - (-EINVAL) on failure.
331 tf_session_is_fid_supported(struct tf_session *tfs,
335 * Looks up the private session information from the TF session
336 * info. Does not perform a fid check against the registered
337 * clients. Should be used if tf_session_get_session() was used
338 * previously i.e. at the TF API boundary.
341 * Pointer to TF handle
344 * Pointer pointer to the session
347 * - (0) if successful.
348 * - (-EINVAL) on failure.
350 int tf_session_get_session_internal(struct tf *tfp,
351 struct tf_session **tfs);
354 * Looks up the private session information from the TF session
355 * info. Performs a fid check against the clients on the session.
358 * Pointer to TF handle
361 * Pointer pointer to the session
364 * - (0) if successful.
365 * - (-EINVAL) on failure.
367 int tf_session_get_session(struct tf *tfp,
368 struct tf_session **tfs);
371 * Looks up client within the session.
374 * Pointer pointer to the session
376 * [in] session_client_id
377 * Client id to look for within the session
380 * client if successful.
381 * - (NULL) on failure, client not found.
383 struct tf_session_client *
384 tf_session_get_session_client(struct tf_session *tfs,
385 union tf_session_client_id session_client_id);
388 * Looks up client using name within the session.
390 * [in] session, pointer to the session
392 * [in] session_client_name, name of the client to lookup in the session
395 * - Pointer to the session, if found.
396 * - (NULL) on failure, client not found.
398 struct tf_session_client *
399 tf_session_find_session_client_by_name(struct tf_session *tfs,
400 const char *ctrl_chan_name);
403 * Looks up client using the fid.
405 * [in] session, pointer to the session
407 * [in] fid, fid of the client to find
410 * - Pointer to the session, if found.
411 * - (NULL) on failure, client not found.
413 struct tf_session_client *
414 tf_session_find_session_client_by_fid(struct tf_session *tfs,
418 * Looks up the device information from the TF Session.
421 * Pointer to TF handle
424 * Pointer pointer to the device
427 * - (0) if successful.
428 * - (-EINVAL) on failure.
430 int tf_session_get_device(struct tf_session *tfs,
431 struct tf_dev_info **tfd);
434 * Looks up the FW Session id the requested TF handle.
437 * Pointer to TF handle
440 * Pointer to the session_id
443 * - (0) if successful.
444 * - (-EINVAL) on failure.
446 int tf_session_get_fw_session_id(struct tf *tfp,
447 uint8_t *fw_session_id);
450 * Looks up the Session id the requested TF handle.
453 * Pointer to TF handle
456 * Pointer to the session_id
459 * - (0) if successful.
460 * - (-EINVAL) on failure.
462 int tf_session_get_session_id(struct tf *tfp,
463 union tf_session_id *session_id);
466 * API to get the em_ext_db from tf_session.
469 * Pointer to TF handle
471 * [out] em_ext_db_handle, pointer to eem handle
474 * - (0) if successful.
475 * - (-EINVAL) on failure.
478 tf_session_get_em_ext_db(struct tf *tfp,
479 void **em_ext_db_handle);
482 * API to set the em_ext_db in tf_session.
485 * Pointer to TF handle
487 * [in] em_ext_db_handle, pointer to eem handle
490 * - (0) if successful.
491 * - (-EINVAL) on failure.
494 tf_session_set_em_ext_db(struct tf *tfp,
495 void *em_ext_db_handle);
498 * API to get the db from tf_session.
501 * Pointer to TF handle
503 * [out] db_handle, pointer to db handle
506 * - (0) if successful.
507 * - (-EINVAL) on failure.
510 tf_session_get_db(struct tf *tfp,
511 enum tf_module_type type,
515 * API to set the db in tf_session.
518 * Pointer to TF handle
520 * [in] db_handle, pointer to db handle
523 * - (0) if successful.
524 * - (-EINVAL) on failure.
527 tf_session_set_db(struct tf *tfp,
528 enum tf_module_type type,
532 * Check if the session is shared session.
534 * [in] session, pointer to the session
537 * - true if it is shared session
538 * - false if it is not shared session
541 tf_session_is_shared_session(struct tf_session *tfs)
543 return tfs->shared_session;
547 * Check if the session is the shared session creator
549 * [in] session, pointer to the session
552 * - true if it is the shared session creator
553 * - false if it is not the shared session creator
556 tf_session_is_shared_session_creator(struct tf_session *tfs)
558 return tfs->shared_session_creator;
562 * Get the pointer to the parent bnxt struct
564 * [in] session, pointer to the session
567 * - the pointer to the parent bnxt struct
569 static inline struct bnxt*
570 tf_session_get_bp(struct tf_session *tfs)
574 #endif /* _TF_SESSION_H_ */