1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
9 #include "tf_session.h"
17 tf_open_session(struct tf *tfp,
18 struct tf_open_session_parms *parms)
21 struct tf_session *session;
22 struct tfp_calloc_parms alloc_parms;
23 unsigned int domain, bus, slot, device;
24 uint8_t fw_session_id;
26 if (tfp == NULL || parms == NULL)
29 /* Filter out any non-supported device types on the Core
30 * side. It is assumed that the Firmware will be supported if
31 * firmware open session succeeds.
33 if (parms->device_type != TF_DEVICE_TYPE_WH)
36 /* Build the beginning of session_id */
37 rc = sscanf(parms->ctrl_chan_name,
45 "Failed to scan device ctrl_chan_name\n");
49 /* open FW session and get a new session_id */
50 rc = tf_msg_session_open(tfp,
51 parms->ctrl_chan_name,
57 "Session is already open, rc:%d\n",
61 "Open message send failed, rc:%d\n",
64 parms->session_id.id = TF_FW_SESSION_ID_INVALID;
68 /* Allocate session */
69 alloc_parms.nitems = 1;
70 alloc_parms.size = sizeof(struct tf_session_info);
71 alloc_parms.alignment = 0;
72 rc = tfp_calloc(&alloc_parms);
76 "Failed to allocate session info, rc:%d\n",
81 tfp->session = (struct tf_session_info *)alloc_parms.mem_va;
83 /* Allocate core data for the session */
84 alloc_parms.nitems = 1;
85 alloc_parms.size = sizeof(struct tf_session);
86 alloc_parms.alignment = 0;
87 rc = tfp_calloc(&alloc_parms);
91 "Failed to allocate session data, rc:%d\n",
96 tfp->session->core_data = alloc_parms.mem_va;
98 session = (struct tf_session *)tfp->session->core_data;
99 tfp_memcpy(session->ctrl_chan_name,
100 parms->ctrl_chan_name,
101 TF_SESSION_NAME_MAX);
103 /* Initialize Session */
104 session->device_type = parms->device_type;
106 /* Construct the Session ID */
107 session->session_id.internal.domain = domain;
108 session->session_id.internal.bus = bus;
109 session->session_id.internal.device = device;
110 session->session_id.internal.fw_session_id = fw_session_id;
112 rc = tf_msg_session_qcfg(tfp);
116 "Query config message send failed, rc:%d\n",
121 session->ref_count++;
123 /* Return session ID */
124 parms->session_id = session->session_id;
127 "Session created, session_id:%d\n",
128 parms->session_id.id);
131 "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
132 parms->session_id.internal.domain,
133 parms->session_id.internal.bus,
134 parms->session_id.internal.device,
135 parms->session_id.internal.fw_session_id);
140 tfp_free(tfp->session->core_data);
141 tfp_free(tfp->session);
146 tf_close_session(tfp);
151 tf_attach_session(struct tf *tfp __rte_unused,
152 struct tf_attach_session_parms *parms __rte_unused)
160 /* - Open the shared memory for the attach_chan_name
161 * - Point to the shared session for this Device instance
162 * - Check that session is valid
163 * - Attach to the firmware so it can record there is more
164 * than one client of the session.
168 if (tfp->session->session_id.id != TF_SESSION_ID_INVALID) {
169 rc = tf_msg_session_attach(tfp,
170 parms->ctrl_chan_name,
174 #endif /* TF_SHARED */
179 tf_close_session(struct tf *tfp)
183 struct tf_session *tfs;
184 union tf_session_id session_id;
186 if (tfp == NULL || tfp->session == NULL)
189 tfs = (struct tf_session *)(tfp->session->core_data);
191 if (tfs->session_id.id != TF_SESSION_ID_INVALID) {
192 rc = tf_msg_session_close(tfp);
196 "Message send failed, rc:%d\n",
200 /* Update the ref_count */
204 session_id = tfs->session_id;
206 /* Final cleanup as we're last user of the session */
207 if (tfs->ref_count == 0) {
208 tfp_free(tfp->session->core_data);
209 tfp_free(tfp->session);
214 "Session closed, session_id:%d\n",
218 "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
219 session_id.internal.domain,
220 session_id.internal.bus,
221 session_id.internal.device,
222 session_id.internal.fw_session_id);