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 /** TruFlow 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 * EM allocator for session
161 void *em_pool[TF_DIR_MAX];
163 #ifdef TF_TCAM_SHARED
165 * tcam db reference for the session
167 void *tcam_shared_db_handle;
168 #endif /* TF_TCAM_SHARED */
170 * SRAM db reference for the session
178 * Shared memory for each of the Session Clients. A session can have
179 * one or more clients.
181 struct tf_session_client {
183 * Linked list of clients
185 struct ll_entry ll_entry; /* For inserting in link list, must be
186 * first field of struct.
190 * String containing name of control channel interface to be
191 * used for this session to communicate with firmware.
193 * ctrl_chan_name will be used as part of a name for any
194 * shared memory allocation.
196 char ctrl_chan_name[TF_SESSION_NAME_MAX];
199 * Firmware FID, learned at time of Session Client create.
204 * Session Client ID, allocated by FW on tf_register_session()
206 union tf_session_client_id session_client_id;
210 * Session open parameter definition
212 struct tf_session_open_session_parms {
214 * [in] Pointer to the TF open session configuration
216 struct tf_open_session_parms *open_cfg;
220 * Session attach parameter definition
222 struct tf_session_attach_session_parms {
224 * [in] Pointer to the TF attach session configuration
226 struct tf_attach_session_parms *attach_cfg;
230 * Session close parameter definition
232 struct tf_session_close_session_parms {
240 union tf_session_id *session_id;
244 * @page session Session Management
246 * @ref tf_session_open_session
248 * @ref tf_session_attach_session
250 * @ref tf_session_close_session
252 * @ref tf_session_is_fid_supported
254 * @ref tf_session_get_session_internal
256 * @ref tf_session_get_session
258 * @ref tf_session_get_session_client
260 * @ref tf_session_find_session_client_by_name
262 * @ref tf_session_find_session_client_by_fid
264 * @ref tf_session_get_device
266 * @ref tf_session_get_fw_session_id
268 * @ref tf_session_get_session_id
270 * @ref tf_session_is_shared_session_creator
272 * @ref tf_session_get_db
274 * @ref tf_session_set_db
276 * @ref tf_session_get_bp
278 * @ref tf_session_is_shared_session
281 * @ref tf_session_get_tcam_shared_db
283 * @ref tf_session_set_tcam_shared_db
286 * @ref tf_session_get_sram_db
288 * @ref tf_session_set_sram_db
292 * Creates a host session with a corresponding firmware session.
295 * Pointer to TF handle
298 * Pointer to the session open parameters
301 * - (0) if successful.
302 * - (-EINVAL) on failure.
304 int tf_session_open_session(struct tf *tfp,
305 struct tf_session_open_session_parms *parms);
308 * Attaches a previous created session.
311 * Pointer to TF handle
314 * Pointer to the session attach parameters
317 * - (0) if successful.
318 * - (-EINVAL) on failure.
320 int tf_session_attach_session(struct tf *tfp,
321 struct tf_session_attach_session_parms *parms);
324 * Closes a previous created session. Only possible if previous
325 * registered Clients had been unregistered first.
328 * Pointer to TF handle
331 * Pointer to the session close parameters.
334 * - (0) if successful.
335 * - (-EUSERS) if clients are still registered with the session.
336 * - (-EINVAL) on failure.
338 int tf_session_close_session(struct tf *tfp,
339 struct tf_session_close_session_parms *parms);
342 * Verifies that the fid is supported by the session. Used to assure
343 * that a function i.e. client/control channel is registered with the
347 * Pointer to TF Session handle
353 * - (true) if successful, else false
354 * - (-EINVAL) on failure.
357 tf_session_is_fid_supported(struct tf_session *tfs,
361 * Looks up the private session information from the TF session
362 * info. Does not perform a fid check against the registered
363 * clients. Should be used if tf_session_get_session() was used
364 * previously i.e. at the TF API boundary.
367 * Pointer to TF handle
370 * Pointer pointer to the session
373 * - (0) if successful.
374 * - (-EINVAL) on failure.
376 int tf_session_get_session_internal(struct tf *tfp,
377 struct tf_session **tfs);
380 * Looks up the private session information from the TF session
381 * info. Performs a fid check against the clients on the session.
384 * Pointer to TF handle
387 * Pointer pointer to the session
390 * - (0) if successful.
391 * - (-EINVAL) on failure.
393 int tf_session_get_session(struct tf *tfp,
394 struct tf_session **tfs);
397 * Looks up client within the session.
400 * Pointer pointer to the session
402 * [in] session_client_id
403 * Client id to look for within the session
406 * client if successful.
407 * - (NULL) on failure, client not found.
409 struct tf_session_client *
410 tf_session_get_session_client(struct tf_session *tfs,
411 union tf_session_client_id session_client_id);
414 * Looks up client using name within the session.
416 * [in] session, pointer to the session
418 * [in] session_client_name, name of the client to lookup in the session
421 * - Pointer to the session, if found.
422 * - (NULL) on failure, client not found.
424 struct tf_session_client *
425 tf_session_find_session_client_by_name(struct tf_session *tfs,
426 const char *ctrl_chan_name);
429 * Looks up client using the fid.
431 * [in] session, pointer to the session
433 * [in] fid, fid of the client to find
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_fid(struct tf_session *tfs,
444 * Looks up the device information from the TF Session.
447 * Pointer to session handle
450 * Pointer to the device
453 * - (0) if successful.
454 * - (-EINVAL) on failure.
456 int tf_session_get_device(struct tf_session *tfs,
457 struct tf_dev_info **tfd);
460 * Returns the session and the device from the tfp.
463 * Pointer to TF handle
466 * Pointer to the session
469 * Pointer to the device
472 * - (0) if successful.
473 * - (-EINVAL) on failure.
475 int tf_session_get(struct tf *tfp,
476 struct tf_session **tfs,
477 struct tf_dev_info **tfd);
480 * Looks up the FW Session id the requested TF handle.
483 * Pointer to TF handle
486 * Pointer to the session_id
489 * - (0) if successful.
490 * - (-EINVAL) on failure.
492 int tf_session_get_fw_session_id(struct tf *tfp,
493 uint8_t *fw_session_id);
496 * Looks up the Session id the requested TF handle.
499 * Pointer to TF handle
502 * Pointer to the session_id
505 * - (0) if successful.
506 * - (-EINVAL) on failure.
508 int tf_session_get_session_id(struct tf *tfp,
509 union tf_session_id *session_id);
512 * API to get the em_ext_db from tf_session.
515 * Pointer to TF handle
517 * [out] em_ext_db_handle, pointer to eem handle
520 * - (0) if successful.
521 * - (-EINVAL) on failure.
524 tf_session_get_em_ext_db(struct tf *tfp,
525 void **em_ext_db_handle);
528 * API to set the em_ext_db in tf_session.
531 * Pointer to TF handle
533 * [in] em_ext_db_handle, pointer to eem handle
536 * - (0) if successful.
537 * - (-EINVAL) on failure.
540 tf_session_set_em_ext_db(struct tf *tfp,
541 void *em_ext_db_handle);
544 * API to get the db from tf_session.
547 * Pointer to TF handle
549 * [out] db_handle, pointer to db handle
552 * - (0) if successful.
553 * - (-EINVAL) on failure.
556 tf_session_get_db(struct tf *tfp,
557 enum tf_module_type type,
561 * API to set the db in tf_session.
564 * Pointer to TF handle
566 * [in] db_handle, pointer to db handle
569 * - (0) if successful.
570 * - (-EINVAL) on failure.
573 tf_session_set_db(struct tf *tfp,
574 enum tf_module_type type,
578 * Check if the session is shared session.
580 * [in] session, pointer to the session
583 * - true if it is shared session
584 * - false if it is not shared session
587 tf_session_is_shared_session(struct tf_session *tfs)
589 return tfs->shared_session;
593 * Check if the session is the shared session creator
595 * [in] session, pointer to the session
598 * - true if it is the shared session creator
599 * - false if it is not the shared session creator
602 tf_session_is_shared_session_creator(struct tf_session *tfs)
604 return tfs->shared_session_creator;
608 * Get the pointer to the parent bnxt struct
610 * [in] session, pointer to the session
613 * - the pointer to the parent bnxt struct
615 static inline struct bnxt*
616 tf_session_get_bp(struct tf *tfp)
622 * Set the pointer to the tcam shared database
624 * [in] session, pointer to the session
627 * - the pointer to the parent bnxt struct
630 tf_session_set_tcam_shared_db(struct tf *tfp,
631 void *tcam_shared_db_handle);
634 * Get the pointer to the tcam shared database
636 * [in] session, pointer to the session
639 * - the pointer to the parent bnxt struct
642 tf_session_get_tcam_shared_db(struct tf *tfp,
643 void **tcam_shared_db_handle);
646 * Set the pointer to the SRAM database
648 * [in] session, pointer to the session
651 * - the pointer to the parent bnxt struct
654 tf_session_set_sram_db(struct tf *tfp,
658 * Get the pointer to the SRAM database
660 * [in] session, pointer to the session
663 * - the pointer to the parent bnxt struct
666 tf_session_get_sram_db(struct tf *tfp,
669 #endif /* _TF_SESSION_H_ */