1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
14 #include "tf_device.h"
16 #include "tf_resources.h"
21 * The Session module provides session control support. A session is
22 * to the ULP layer known as a session_info instance. The session
23 * private data is the actual session.
26 * - The device and all the resources related to the device.
27 * - Any session sharing between ULP applications
32 #define TF_SESSION_ID_INVALID 0xFFFFFFFF /** Invalid Session ID define */
35 * At this stage we are using fixed size entries so that each
36 * stack entry represents either 2 or 4 RT (f/n)blocks. So we
37 * take the total block allocation for truflow and divide that
40 #ifdef TF_EM_ENTRY_IPV4_ONLY
41 #define TF_SESSION_EM_ENTRY_SIZE 2 /* 2 blocks per entry */
43 #define TF_SESSION_EM_ENTRY_SIZE 4 /* 4 blocks per entry */
49 * Shared memory containing private TruFlow session information.
50 * Through this structure the session can keep track of resource
51 * allocations and (if so configured) any shadow copy of flow
52 * information. It also holds info about Session Clients.
54 * Memory is assigned to the Truflow instance by way of
55 * tf_open_session. Memory is allocated and owned by i.e. ULP.
57 * Access control to this shared memory is handled by the spin_lock in
61 /** TruFlow Version. Used to control the structure layout
62 * when sharing sessions. No guarantee that a secondary
63 * process would come from the same version of an executable.
65 struct tf_session_version ver;
68 * Session ID, allocated by FW on tf_open_session()
70 union tf_session_id session_id;
73 * Boolean controlling the use and availability of shared session.
74 * Shared session will allow the application to share resources
75 * on the firmware side without having to allocate them on firmware.
76 * Additional private session core_data will be allocated if this
77 * boolean is set to 'true', default 'false'.
83 * This flag indicates the shared session on firmware side is created
84 * by this session. Some privileges may be assigned to this session.
87 bool shared_session_creator;
90 * Boolean controlling the use and availability of shadow
91 * copy. Shadow copy will allow the TruFlow Core to keep track
92 * of resource content on the firmware side without having to
93 * query firmware. Additional private session core_data will
94 * be allocated if this boolean is set to 'true', default
97 * Size of memory depends on the NVM Resource settings for the
103 * Session Reference Count. To keep track of functions per
104 * session the ref_count is updated. There is also a
105 * parallel TruFlow Firmware ref_count in case the TruFlow
106 * Core goes away without informing the Firmware.
111 * Session Reference Count for attached sessions. To keep
112 * track of application sharing of a session the
113 * ref_count_attach is updated.
115 uint8_t ref_count_attach;
120 struct tf_dev_info dev;
122 * Device init flag. False if Device is not fully initialized,
128 * Linked list of clients registered for this session
133 * em ext db reference for the session
135 void *em_ext_db_handle;
138 * tcam db reference for the session
140 void *tcam_db_handle;
143 * table db reference for the session
148 * identifier db reference for the session
153 * em db reference for the session
158 * EM allocator for session
160 void *em_pool[TF_DIR_MAX];
162 #ifdef TF_TCAM_SHARED
164 * tcam db reference for the session
166 void *tcam_shared_db_handle;
167 #endif /* TF_TCAM_SHARED */
170 * SRAM db reference for the session
175 * if table db reference for the session
177 void *if_tbl_db_handle;
180 * global db reference for the session
182 void *global_db_handle;
185 * Number of slices per row for WC TCAM
187 uint16_t wc_num_slices_per_row;
193 * Shared memory for each of the Session Clients. A session can have
194 * one or more clients.
196 struct tf_session_client {
198 * Linked list of clients
200 struct ll_entry ll_entry; /* For inserting in link list, must be
201 * first field of struct.
205 * String containing name of control channel interface to be
206 * used for this session to communicate with firmware.
208 * ctrl_chan_name will be used as part of a name for any
209 * shared memory allocation.
211 char ctrl_chan_name[TF_SESSION_NAME_MAX];
214 * Firmware FID, learned at time of Session Client create.
219 * Session Client ID, allocated by FW on tf_register_session()
221 union tf_session_client_id session_client_id;
225 * Session open parameter definition
227 struct tf_session_open_session_parms {
229 * [in] Pointer to the TF open session configuration
231 struct tf_open_session_parms *open_cfg;
235 * Session attach parameter definition
237 struct tf_session_attach_session_parms {
239 * [in] Pointer to the TF attach session configuration
241 struct tf_attach_session_parms *attach_cfg;
245 * Session close parameter definition
247 struct tf_session_close_session_parms {
255 union tf_session_id *session_id;
259 * @page session Session Management
261 * @ref tf_session_open_session
263 * @ref tf_session_attach_session
265 * @ref tf_session_close_session
267 * @ref tf_session_is_fid_supported
269 * @ref tf_session_get_session_internal
271 * @ref tf_session_get_session
273 * @ref tf_session_get_session_client
275 * @ref tf_session_find_session_client_by_name
277 * @ref tf_session_find_session_client_by_fid
279 * @ref tf_session_get_device
281 * @ref tf_session_get_fw_session_id
283 * @ref tf_session_get_session_id
285 * @ref tf_session_is_shared_session_creator
287 * @ref tf_session_get_db
289 * @ref tf_session_set_db
291 * @ref tf_session_get_bp
293 * @ref tf_session_is_shared_session
296 * @ref tf_session_get_tcam_shared_db
298 * @ref tf_session_set_tcam_shared_db
301 * @ref tf_session_get_sram_db
303 * @ref tf_session_set_sram_db
307 * Creates a host session with a corresponding firmware session.
310 * Pointer to TF handle
313 * Pointer to the session open parameters
316 * - (0) if successful.
317 * - (-EINVAL) on failure.
319 int tf_session_open_session(struct tf *tfp,
320 struct tf_session_open_session_parms *parms);
323 * Attaches a previous created session.
326 * Pointer to TF handle
329 * Pointer to the session attach parameters
332 * - (0) if successful.
333 * - (-EINVAL) on failure.
335 int tf_session_attach_session(struct tf *tfp,
336 struct tf_session_attach_session_parms *parms);
339 * Closes a previous created session. Only possible if previous
340 * registered Clients had been unregistered first.
343 * Pointer to TF handle
346 * Pointer to the session close parameters.
349 * - (0) if successful.
350 * - (-EUSERS) if clients are still registered with the session.
351 * - (-EINVAL) on failure.
353 int tf_session_close_session(struct tf *tfp,
354 struct tf_session_close_session_parms *parms);
357 * Verifies that the fid is supported by the session. Used to assure
358 * that a function i.e. client/control channel is registered with the
362 * Pointer to TF Session handle
368 * - (true) if successful, else false
369 * - (-EINVAL) on failure.
372 tf_session_is_fid_supported(struct tf_session *tfs,
376 * Looks up the private session information from the TF session
377 * info. Does not perform a fid check against the registered
378 * clients. Should be used if tf_session_get_session() was used
379 * previously i.e. at the TF API boundary.
382 * Pointer to TF handle
385 * Pointer pointer to the session
388 * - (0) if successful.
389 * - (-EINVAL) on failure.
391 int tf_session_get_session_internal(struct tf *tfp,
392 struct tf_session **tfs);
395 * Looks up the private session information from the TF session
396 * info. Performs a fid check against the clients on the session.
399 * Pointer to TF handle
402 * Pointer pointer to the session
405 * - (0) if successful.
406 * - (-EINVAL) on failure.
408 int tf_session_get_session(struct tf *tfp,
409 struct tf_session **tfs);
412 * Looks up client within the session.
415 * Pointer pointer to the session
417 * [in] session_client_id
418 * Client id to look for within the session
421 * client if successful.
422 * - (NULL) on failure, client not found.
424 struct tf_session_client *
425 tf_session_get_session_client(struct tf_session *tfs,
426 union tf_session_client_id session_client_id);
429 * Looks up client using name within the session.
431 * [in] session, pointer to the session
433 * [in] session_client_name, name of the client to lookup in the session
436 * - Pointer to the session, if found.
437 * - (NULL) on failure, client not found.
439 struct tf_session_client *
440 tf_session_find_session_client_by_name(struct tf_session *tfs,
441 const char *ctrl_chan_name);
444 * Looks up client using the fid.
446 * [in] session, pointer to the session
448 * [in] fid, fid of the client to find
451 * - Pointer to the session, if found.
452 * - (NULL) on failure, client not found.
454 struct tf_session_client *
455 tf_session_find_session_client_by_fid(struct tf_session *tfs,
459 * Looks up the device information from the TF Session.
462 * Pointer to session handle
465 * Pointer to the device
468 * - (0) if successful.
469 * - (-EINVAL) on failure.
471 int tf_session_get_device(struct tf_session *tfs,
472 struct tf_dev_info **tfd);
475 * Returns the session and the device from the tfp.
478 * Pointer to TF handle
481 * Pointer to the session
484 * Pointer to the device
487 * - (0) if successful.
488 * - (-EINVAL) on failure.
490 int tf_session_get(struct tf *tfp,
491 struct tf_session **tfs,
492 struct tf_dev_info **tfd);
495 * Looks up the FW Session id the requested TF handle.
498 * Pointer to TF handle
501 * Pointer to the session_id
504 * - (0) if successful.
505 * - (-EINVAL) on failure.
507 int tf_session_get_fw_session_id(struct tf *tfp,
508 uint8_t *fw_session_id);
511 * Looks up the Session id the requested TF handle.
514 * Pointer to TF handle
517 * Pointer to the session_id
520 * - (0) if successful.
521 * - (-EINVAL) on failure.
523 int tf_session_get_session_id(struct tf *tfp,
524 union tf_session_id *session_id);
527 * API to get the em_ext_db from tf_session.
530 * Pointer to TF handle
532 * [out] em_ext_db_handle, pointer to eem handle
535 * - (0) if successful.
536 * - (-EINVAL) on failure.
539 tf_session_get_em_ext_db(struct tf *tfp,
540 void **em_ext_db_handle);
543 * API to set the em_ext_db in tf_session.
546 * Pointer to TF handle
548 * [in] em_ext_db_handle, pointer to eem handle
551 * - (0) if successful.
552 * - (-EINVAL) on failure.
555 tf_session_set_em_ext_db(struct tf *tfp,
556 void *em_ext_db_handle);
559 * API to get the db from tf_session.
562 * Pointer to TF handle
564 * [out] db_handle, pointer to db handle
567 * - (0) if successful.
568 * - (-EINVAL) on failure.
571 tf_session_get_db(struct tf *tfp,
572 enum tf_module_type type,
576 * API to set the db in tf_session.
579 * Pointer to TF handle
581 * [in] db_handle, pointer to db handle
584 * - (0) if successful.
585 * - (-EINVAL) on failure.
588 tf_session_set_db(struct tf *tfp,
589 enum tf_module_type type,
593 * Check if the session is shared session.
595 * [in] session, pointer to the session
598 * - true if it is shared session
599 * - false if it is not shared session
602 tf_session_is_shared_session(struct tf_session *tfs)
604 return tfs->shared_session;
608 * Check if the session is the shared session creator
610 * [in] session, pointer to the session
613 * - true if it is the shared session creator
614 * - false if it is not the shared session creator
617 tf_session_is_shared_session_creator(struct tf_session *tfs)
619 return tfs->shared_session_creator;
623 * Get the pointer to the parent bnxt struct
625 * [in] session, pointer to the session
628 * - the pointer to the parent bnxt struct
630 static inline struct bnxt*
631 tf_session_get_bp(struct tf *tfp)
637 * Set the pointer to the tcam shared database
639 * [in] session, pointer to the session
642 * - the pointer to the parent bnxt struct
645 tf_session_set_tcam_shared_db(struct tf *tfp,
646 void *tcam_shared_db_handle);
649 * Get the pointer to the tcam shared database
651 * [in] session, pointer to the session
654 * - the pointer to the parent bnxt struct
657 tf_session_get_tcam_shared_db(struct tf *tfp,
658 void **tcam_shared_db_handle);
661 * Set the pointer to the SRAM database
663 * [in] session, pointer to the session
666 * - the pointer to the parent bnxt struct
669 tf_session_set_sram_db(struct tf *tfp,
673 * Get the pointer to the SRAM database
675 * [in] session, pointer to the session
678 * - the pointer to the parent bnxt struct
681 tf_session_get_sram_db(struct tf *tfp,
685 * Set the pointer to the global cfg database
687 * [in] session, pointer to the session
690 * - (0) if successful.
691 * - (-EINVAL) on failure.
694 tf_session_set_global_db(struct tf *tfp,
695 void *global_handle);
698 * Get the pointer to the global cfg database
700 * [in] session, pointer to the session
703 * - (0) if successful.
704 * - (-EINVAL) on failure.
707 tf_session_get_global_db(struct tf *tfp,
708 void **global_handle);
711 * Set the pointer to the if table cfg database
713 * [in] session, pointer to the session
716 * - (0) if successful.
717 * - (-EINVAL) on failure.
720 tf_session_set_if_tbl_db(struct tf *tfp,
721 void *if_tbl_handle);
724 * Get the pointer to the if table cfg database
726 * [in] session, pointer to the session
729 * - (0) if successful.
730 * - (-EINVAL) on failure.
733 tf_session_get_if_tbl_db(struct tf *tfp,
734 void **if_tbl_handle);
736 #endif /* _TF_SESSION_H_ */