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 * 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 */
174 * Shared memory for each of the Session Clients. A session can have
175 * one or more clients.
177 struct tf_session_client {
179 * Linked list of clients
181 struct ll_entry ll_entry; /* For inserting in link list, must be
182 * first field of struct.
186 * String containing name of control channel interface to be
187 * used for this session to communicate with firmware.
189 * ctrl_chan_name will be used as part of a name for any
190 * shared memory allocation.
192 char ctrl_chan_name[TF_SESSION_NAME_MAX];
195 * Firmware FID, learned at time of Session Client create.
200 * Session Client ID, allocated by FW on tf_register_session()
202 union tf_session_client_id session_client_id;
206 * Session open parameter definition
208 struct tf_session_open_session_parms {
210 * [in] Pointer to the TF open session configuration
212 struct tf_open_session_parms *open_cfg;
216 * Session attach parameter definition
218 struct tf_session_attach_session_parms {
220 * [in] Pointer to the TF attach session configuration
222 struct tf_attach_session_parms *attach_cfg;
226 * Session close parameter definition
228 struct tf_session_close_session_parms {
236 union tf_session_id *session_id;
240 * @page session Session Management
242 * @ref tf_session_open_session
244 * @ref tf_session_attach_session
246 * @ref tf_session_close_session
248 * @ref tf_session_is_fid_supported
250 * @ref tf_session_get_session_internal
252 * @ref tf_session_get_session
254 * @ref tf_session_get_session_client
256 * @ref tf_session_find_session_client_by_name
258 * @ref tf_session_find_session_client_by_fid
260 * @ref tf_session_get_device
262 * @ref tf_session_get_fw_session_id
264 * @ref tf_session_get_session_id
266 * @ref tf_session_is_shared_session_creator
268 * @ref tf_session_get_db
270 * @ref tf_session_set_db
272 * @ref tf_session_get_bp
274 * @ref tf_session_is_shared_session
277 * @ref tf_session_get_tcam_shared_db
279 * @ref tf_session_set_tcam_shared_db
284 * Creates a host session with a corresponding firmware session.
287 * Pointer to TF handle
290 * Pointer to the session open parameters
293 * - (0) if successful.
294 * - (-EINVAL) on failure.
296 int tf_session_open_session(struct tf *tfp,
297 struct tf_session_open_session_parms *parms);
300 * Attaches a previous created session.
303 * Pointer to TF handle
306 * Pointer to the session attach parameters
309 * - (0) if successful.
310 * - (-EINVAL) on failure.
312 int tf_session_attach_session(struct tf *tfp,
313 struct tf_session_attach_session_parms *parms);
316 * Closes a previous created session. Only possible if previous
317 * registered Clients had been unregistered first.
320 * Pointer to TF handle
323 * Pointer to the session close parameters.
326 * - (0) if successful.
327 * - (-EUSERS) if clients are still registered with the session.
328 * - (-EINVAL) on failure.
330 int tf_session_close_session(struct tf *tfp,
331 struct tf_session_close_session_parms *parms);
334 * Verifies that the fid is supported by the session. Used to assure
335 * that a function i.e. client/control channel is registered with the
339 * Pointer to TF Session handle
345 * - (true) if successful, else false
346 * - (-EINVAL) on failure.
349 tf_session_is_fid_supported(struct tf_session *tfs,
353 * Looks up the private session information from the TF session
354 * info. Does not perform a fid check against the registered
355 * clients. Should be used if tf_session_get_session() was used
356 * previously i.e. at the TF API boundary.
359 * Pointer to TF handle
362 * Pointer pointer to the session
365 * - (0) if successful.
366 * - (-EINVAL) on failure.
368 int tf_session_get_session_internal(struct tf *tfp,
369 struct tf_session **tfs);
372 * Looks up the private session information from the TF session
373 * info. Performs a fid check against the clients on the session.
376 * Pointer to TF handle
379 * Pointer pointer to the session
382 * - (0) if successful.
383 * - (-EINVAL) on failure.
385 int tf_session_get_session(struct tf *tfp,
386 struct tf_session **tfs);
389 * Looks up client within the session.
392 * Pointer pointer to the session
394 * [in] session_client_id
395 * Client id to look for within the session
398 * client if successful.
399 * - (NULL) on failure, client not found.
401 struct tf_session_client *
402 tf_session_get_session_client(struct tf_session *tfs,
403 union tf_session_client_id session_client_id);
406 * Looks up client using name within the session.
408 * [in] session, pointer to the session
410 * [in] session_client_name, name of the client to lookup in the session
413 * - Pointer to the session, if found.
414 * - (NULL) on failure, client not found.
416 struct tf_session_client *
417 tf_session_find_session_client_by_name(struct tf_session *tfs,
418 const char *ctrl_chan_name);
421 * Looks up client using the fid.
423 * [in] session, pointer to the session
425 * [in] fid, fid of the client to find
428 * - Pointer to the session, if found.
429 * - (NULL) on failure, client not found.
431 struct tf_session_client *
432 tf_session_find_session_client_by_fid(struct tf_session *tfs,
436 * Looks up the device information from the TF Session.
439 * Pointer to TF handle
442 * Pointer pointer to the device
445 * - (0) if successful.
446 * - (-EINVAL) on failure.
448 int tf_session_get_device(struct tf_session *tfs,
449 struct tf_dev_info **tfd);
452 * Looks up the FW Session id the requested TF handle.
455 * Pointer to TF handle
458 * Pointer to the session_id
461 * - (0) if successful.
462 * - (-EINVAL) on failure.
464 int tf_session_get_fw_session_id(struct tf *tfp,
465 uint8_t *fw_session_id);
468 * Looks up the Session id the requested TF handle.
471 * Pointer to TF handle
474 * Pointer to the session_id
477 * - (0) if successful.
478 * - (-EINVAL) on failure.
480 int tf_session_get_session_id(struct tf *tfp,
481 union tf_session_id *session_id);
484 * API to get the em_ext_db from tf_session.
487 * Pointer to TF handle
489 * [out] em_ext_db_handle, pointer to eem handle
492 * - (0) if successful.
493 * - (-EINVAL) on failure.
496 tf_session_get_em_ext_db(struct tf *tfp,
497 void **em_ext_db_handle);
500 * API to set the em_ext_db in tf_session.
503 * Pointer to TF handle
505 * [in] em_ext_db_handle, pointer to eem handle
508 * - (0) if successful.
509 * - (-EINVAL) on failure.
512 tf_session_set_em_ext_db(struct tf *tfp,
513 void *em_ext_db_handle);
516 * API to get the db from tf_session.
519 * Pointer to TF handle
521 * [out] db_handle, pointer to db handle
524 * - (0) if successful.
525 * - (-EINVAL) on failure.
528 tf_session_get_db(struct tf *tfp,
529 enum tf_module_type type,
533 * API to set the db in tf_session.
536 * Pointer to TF handle
538 * [in] db_handle, pointer to db handle
541 * - (0) if successful.
542 * - (-EINVAL) on failure.
545 tf_session_set_db(struct tf *tfp,
546 enum tf_module_type type,
550 * Check if the session is shared session.
552 * [in] session, pointer to the session
555 * - true if it is shared session
556 * - false if it is not shared session
559 tf_session_is_shared_session(struct tf_session *tfs)
561 return tfs->shared_session;
565 * Check if the session is the shared session creator
567 * [in] session, pointer to the session
570 * - true if it is the shared session creator
571 * - false if it is not the shared session creator
574 tf_session_is_shared_session_creator(struct tf_session *tfs)
576 return tfs->shared_session_creator;
580 * Get the pointer to the parent bnxt struct
582 * [in] session, pointer to the session
585 * - the pointer to the parent bnxt struct
587 static inline struct bnxt*
588 tf_session_get_bp(struct tf *tfp)
594 * Set the pointer to the tcam shared database
596 * [in] session, pointer to the session
599 * - the pointer to the parent bnxt struct
602 tf_session_set_tcam_shared_db(struct tf *tfp,
603 void *tcam_shared_db_handle);
606 * Get the pointer to the tcam shared database
608 * [in] session, pointer to the session
611 * - the pointer to the parent bnxt struct
614 tf_session_get_tcam_shared_db(struct tf *tfp,
615 void **tcam_shared_db_handle);
617 #endif /* _TF_SESSION_H_ */