1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 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 * Number of EM entries. Static for now will be removed
37 * when parameter added at a later date. At this stage we
38 * are using fixed size entries so that each stack entry
39 * represents 4 RT (f/n)blocks. So we take the total block
40 * allocation for truflow and divide that by 4.
42 #define TF_SESSION_TOTAL_FN_BLOCKS (1024 * 8) /* 8K blocks */
43 #define TF_SESSION_EM_ENTRY_SIZE 4 /* 4 blocks per entry */
44 #define TF_SESSION_EM_POOL_SIZE \
45 (TF_SESSION_TOTAL_FN_BLOCKS / TF_SESSION_EM_ENTRY_SIZE)
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 shadow
75 * copy. Shadow copy will allow the TruFlow Core to keep track
76 * of resource content on the firmware side without having to
77 * query firmware. Additional private session core_data will
78 * be allocated if this boolean is set to 'true', default
81 * Size of memory depends on the NVM Resource settings for the
87 * Session Reference Count. To keep track of functions per
88 * session the ref_count is updated. There is also a
89 * parallel TruFlow Firmware ref_count in case the TruFlow
90 * Core goes away without informing the Firmware.
95 * Session Reference Count for attached sessions. To keep
96 * track of application sharing of a session the
97 * ref_count_attach is updated.
99 uint8_t ref_count_attach;
104 struct tf_dev_info dev;
106 * Device init flag. False if Device is not fully initialized,
112 * Linked list of clients registered for this session
120 * Shared memory for each of the Session Clients. A session can have
121 * one or more clients.
123 struct tf_session_client {
125 * Linked list of clients
127 struct ll_entry ll_entry; /* For inserting in link list, must be
128 * first field of struct.
132 * String containing name of control channel interface to be
133 * used for this session to communicate with firmware.
135 * ctrl_chan_name will be used as part of a name for any
136 * shared memory allocation.
138 char ctrl_chan_name[TF_SESSION_NAME_MAX];
141 * Firmware FID, learned at time of Session Client create.
146 * Session Client ID, allocated by FW on tf_register_session()
148 union tf_session_client_id session_client_id;
152 * Session open parameter definition
154 struct tf_session_open_session_parms {
156 * [in] Pointer to the TF open session configuration
158 struct tf_open_session_parms *open_cfg;
162 * Session attach parameter definition
164 struct tf_session_attach_session_parms {
166 * [in] Pointer to the TF attach session configuration
168 struct tf_attach_session_parms *attach_cfg;
172 * Session close parameter definition
174 struct tf_session_close_session_parms {
182 union tf_session_id *session_id;
186 * @page session Session Management
188 * @ref tf_session_open_session
190 * @ref tf_session_attach_session
192 * @ref tf_session_close_session
194 * @ref tf_session_is_fid_supported
196 * @ref tf_session_get_session_internal
198 * @ref tf_session_get_session
200 * @ref tf_session_get_session_client
202 * @ref tf_session_find_session_client_by_name
204 * @ref tf_session_find_session_client_by_fid
206 * @ref tf_session_get_device
208 * @ref tf_session_get_fw_session_id
210 * @ref tf_session_get_session_id
214 * Creates a host session with a corresponding firmware session.
217 * Pointer to TF handle
220 * Pointer to the session open parameters
223 * - (0) if successful.
224 * - (-EINVAL) on failure.
226 int tf_session_open_session(struct tf *tfp,
227 struct tf_session_open_session_parms *parms);
230 * Attaches a previous created session.
233 * Pointer to TF handle
236 * Pointer to the session attach parameters
239 * - (0) if successful.
240 * - (-EINVAL) on failure.
242 int tf_session_attach_session(struct tf *tfp,
243 struct tf_session_attach_session_parms *parms);
246 * Closes a previous created session. Only possible if previous
247 * registered Clients had been unregistered first.
250 * Pointer to TF handle
253 * Pointer to the session close parameters.
256 * - (0) if successful.
257 * - (-EUSERS) if clients are still registered with the session.
258 * - (-EINVAL) on failure.
260 int tf_session_close_session(struct tf *tfp,
261 struct tf_session_close_session_parms *parms);
264 * Verifies that the fid is supported by the session. Used to assure
265 * that a function i.e. client/control channel is registered with the
269 * Pointer to TF Session handle
275 * - (true) if successful, else false
276 * - (-EINVAL) on failure.
279 tf_session_is_fid_supported(struct tf_session *tfs,
283 * Looks up the private session information from the TF session
284 * info. Does not perform a fid check against the registered
285 * clients. Should be used if tf_session_get_session() was used
286 * previously i.e. at the TF API boundary.
289 * Pointer to TF handle
292 * Pointer pointer to the session
295 * - (0) if successful.
296 * - (-EINVAL) on failure.
298 int tf_session_get_session_internal(struct tf *tfp,
299 struct tf_session **tfs);
302 * Looks up the private session information from the TF session
303 * info. Performs a fid check against the clients on the session.
306 * Pointer to TF handle
309 * Pointer pointer to the session
312 * - (0) if successful.
313 * - (-EINVAL) on failure.
315 int tf_session_get_session(struct tf *tfp,
316 struct tf_session **tfs);
319 * Looks up client within the session.
322 * Pointer pointer to the session
324 * [in] session_client_id
325 * Client id to look for within the session
328 * client if successful.
329 * - (NULL) on failure, client not found.
331 struct tf_session_client *
332 tf_session_get_session_client(struct tf_session *tfs,
333 union tf_session_client_id session_client_id);
336 * Looks up client using name within the session.
338 * [in] session, pointer to the session
340 * [in] session_client_name, name of the client to lookup in the session
343 * - Pointer to the session, if found.
344 * - (NULL) on failure, client not found.
346 struct tf_session_client *
347 tf_session_find_session_client_by_name(struct tf_session *tfs,
348 const char *ctrl_chan_name);
351 * Looks up client using the fid.
353 * [in] session, pointer to the session
355 * [in] fid, fid of the client to find
358 * - Pointer to the session, if found.
359 * - (NULL) on failure, client not found.
361 struct tf_session_client *
362 tf_session_find_session_client_by_fid(struct tf_session *tfs,
366 * Looks up the device information from the TF Session.
369 * Pointer to TF handle
372 * Pointer pointer to the device
375 * - (0) if successful.
376 * - (-EINVAL) on failure.
378 int tf_session_get_device(struct tf_session *tfs,
379 struct tf_dev_info **tfd);
382 * Looks up the FW Session id the requested TF handle.
385 * Pointer to TF handle
388 * Pointer to the session_id
391 * - (0) if successful.
392 * - (-EINVAL) on failure.
394 int tf_session_get_fw_session_id(struct tf *tfp,
395 uint8_t *fw_session_id);
398 * Looks up the Session id the requested TF handle.
401 * Pointer to TF handle
404 * Pointer to the session_id
407 * - (0) if successful.
408 * - (-EINVAL) on failure.
410 int tf_session_get_session_id(struct tf *tfp,
411 union tf_session_id *session_id);
413 #endif /* _TF_SESSION_H_ */