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];
167 * Shared memory for each of the Session Clients. A session can have
168 * one or more clients.
170 struct tf_session_client {
172 * Linked list of clients
174 struct ll_entry ll_entry; /* For inserting in link list, must be
175 * first field of struct.
179 * String containing name of control channel interface to be
180 * used for this session to communicate with firmware.
182 * ctrl_chan_name will be used as part of a name for any
183 * shared memory allocation.
185 char ctrl_chan_name[TF_SESSION_NAME_MAX];
188 * Firmware FID, learned at time of Session Client create.
193 * Session Client ID, allocated by FW on tf_register_session()
195 union tf_session_client_id session_client_id;
199 * Session open parameter definition
201 struct tf_session_open_session_parms {
203 * [in] Pointer to the TF open session configuration
205 struct tf_open_session_parms *open_cfg;
209 * Session attach parameter definition
211 struct tf_session_attach_session_parms {
213 * [in] Pointer to the TF attach session configuration
215 struct tf_attach_session_parms *attach_cfg;
219 * Session close parameter definition
221 struct tf_session_close_session_parms {
229 union tf_session_id *session_id;
233 * @page session Session Management
235 * @ref tf_session_open_session
237 * @ref tf_session_attach_session
239 * @ref tf_session_close_session
241 * @ref tf_session_is_fid_supported
243 * @ref tf_session_get_session_internal
245 * @ref tf_session_get_session
247 * @ref tf_session_get_session_client
249 * @ref tf_session_find_session_client_by_name
251 * @ref tf_session_find_session_client_by_fid
253 * @ref tf_session_get_device
255 * @ref tf_session_get_fw_session_id
257 * @ref tf_session_get_session_id
261 * Creates a host session with a corresponding firmware session.
264 * Pointer to TF handle
267 * Pointer to the session open parameters
270 * - (0) if successful.
271 * - (-EINVAL) on failure.
273 int tf_session_open_session(struct tf *tfp,
274 struct tf_session_open_session_parms *parms);
277 * Attaches a previous created session.
280 * Pointer to TF handle
283 * Pointer to the session attach parameters
286 * - (0) if successful.
287 * - (-EINVAL) on failure.
289 int tf_session_attach_session(struct tf *tfp,
290 struct tf_session_attach_session_parms *parms);
293 * Closes a previous created session. Only possible if previous
294 * registered Clients had been unregistered first.
297 * Pointer to TF handle
300 * Pointer to the session close parameters.
303 * - (0) if successful.
304 * - (-EUSERS) if clients are still registered with the session.
305 * - (-EINVAL) on failure.
307 int tf_session_close_session(struct tf *tfp,
308 struct tf_session_close_session_parms *parms);
311 * Verifies that the fid is supported by the session. Used to assure
312 * that a function i.e. client/control channel is registered with the
316 * Pointer to TF Session handle
322 * - (true) if successful, else false
323 * - (-EINVAL) on failure.
326 tf_session_is_fid_supported(struct tf_session *tfs,
330 * Looks up the private session information from the TF session
331 * info. Does not perform a fid check against the registered
332 * clients. Should be used if tf_session_get_session() was used
333 * previously i.e. at the TF API boundary.
336 * Pointer to TF handle
339 * Pointer pointer to the session
342 * - (0) if successful.
343 * - (-EINVAL) on failure.
345 int tf_session_get_session_internal(struct tf *tfp,
346 struct tf_session **tfs);
349 * Looks up the private session information from the TF session
350 * info. Performs a fid check against the clients on the session.
353 * Pointer to TF handle
356 * Pointer pointer to the session
359 * - (0) if successful.
360 * - (-EINVAL) on failure.
362 int tf_session_get_session(struct tf *tfp,
363 struct tf_session **tfs);
366 * Looks up client within the session.
369 * Pointer pointer to the session
371 * [in] session_client_id
372 * Client id to look for within the session
375 * client if successful.
376 * - (NULL) on failure, client not found.
378 struct tf_session_client *
379 tf_session_get_session_client(struct tf_session *tfs,
380 union tf_session_client_id session_client_id);
383 * Looks up client using name within the session.
385 * [in] session, pointer to the session
387 * [in] session_client_name, name of the client to lookup in the session
390 * - Pointer to the session, if found.
391 * - (NULL) on failure, client not found.
393 struct tf_session_client *
394 tf_session_find_session_client_by_name(struct tf_session *tfs,
395 const char *ctrl_chan_name);
398 * Looks up client using the fid.
400 * [in] session, pointer to the session
402 * [in] fid, fid of the client to find
405 * - Pointer to the session, if found.
406 * - (NULL) on failure, client not found.
408 struct tf_session_client *
409 tf_session_find_session_client_by_fid(struct tf_session *tfs,
413 * Looks up the device information from the TF Session.
416 * Pointer to TF handle
419 * Pointer pointer to the device
422 * - (0) if successful.
423 * - (-EINVAL) on failure.
425 int tf_session_get_device(struct tf_session *tfs,
426 struct tf_dev_info **tfd);
429 * Looks up the FW Session id the requested TF handle.
432 * Pointer to TF handle
435 * Pointer to the session_id
438 * - (0) if successful.
439 * - (-EINVAL) on failure.
441 int tf_session_get_fw_session_id(struct tf *tfp,
442 uint8_t *fw_session_id);
445 * Looks up the Session id the requested TF handle.
448 * Pointer to TF handle
451 * Pointer to the session_id
454 * - (0) if successful.
455 * - (-EINVAL) on failure.
457 int tf_session_get_session_id(struct tf *tfp,
458 union tf_session_id *session_id);
461 * API to get the em_ext_db from tf_session.
464 * Pointer to TF handle
466 * [out] em_ext_db_handle, pointer to eem handle
469 * - (0) if successful.
470 * - (-EINVAL) on failure.
473 tf_session_get_em_ext_db(struct tf *tfp,
474 void **em_ext_db_handle);
477 * API to set the em_ext_db in tf_session.
480 * Pointer to TF handle
482 * [in] em_ext_db_handle, pointer to eem handle
485 * - (0) if successful.
486 * - (-EINVAL) on failure.
489 tf_session_set_em_ext_db(struct tf *tfp,
490 void *em_ext_db_handle);
493 * API to get the db from tf_session.
496 * Pointer to TF handle
498 * [out] db_handle, pointer to db handle
501 * - (0) if successful.
502 * - (-EINVAL) on failure.
505 tf_session_get_db(struct tf *tfp,
506 enum tf_module_type type,
510 * API to set the db in tf_session.
513 * Pointer to TF handle
515 * [in] db_handle, pointer to db handle
518 * - (0) if successful.
519 * - (-EINVAL) on failure.
522 tf_session_set_db(struct tf *tfp,
523 enum tf_module_type type,
527 * Check if the session is shared session.
529 * [in] session, pointer to the session
532 * - true if it is shared session
533 * - false if it is not shared session
536 tf_session_is_shared_session(struct tf_session *tfs)
538 return tfs->shared_session;
542 * Check if the session is the shared session creator
544 * [in] session, pointer to the session
547 * - true if it is the shared session creator
548 * - false if it is not the shared session creator
551 tf_session_is_shared_session_creator(struct tf_session *tfs)
553 return tfs->shared_session_creator;
557 * Get the pointer to the parent bnxt struct
559 * [in] session, pointer to the session
562 * - the pointer to the parent bnxt struct
564 static inline struct bnxt*
565 tf_session_get_bp(struct tf *tfp)
569 #endif /* _TF_SESSION_H_ */