1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
9 #include "tf_session.h"
18 tf_open_session(struct tf *tfp,
19 struct tf_open_session_parms *parms)
22 struct tf_session *session;
23 struct tfp_calloc_parms alloc_parms;
24 unsigned int domain, bus, slot, device;
25 uint8_t fw_session_id;
27 if (tfp == NULL || parms == NULL)
30 /* Filter out any non-supported device types on the Core
31 * side. It is assumed that the Firmware will be supported if
32 * firmware open session succeeds.
34 if (parms->device_type != TF_DEVICE_TYPE_WH)
37 /* Build the beginning of session_id */
38 rc = sscanf(parms->ctrl_chan_name,
46 "Failed to scan device ctrl_chan_name\n");
50 /* open FW session and get a new session_id */
51 rc = tf_msg_session_open(tfp,
52 parms->ctrl_chan_name,
58 "Session is already open, rc:%d\n",
62 "Open message send failed, rc:%d\n",
65 parms->session_id.id = TF_FW_SESSION_ID_INVALID;
69 /* Allocate session */
70 alloc_parms.nitems = 1;
71 alloc_parms.size = sizeof(struct tf_session_info);
72 alloc_parms.alignment = 0;
73 rc = tfp_calloc(&alloc_parms);
77 "Failed to allocate session info, rc:%d\n",
82 tfp->session = (struct tf_session_info *)alloc_parms.mem_va;
84 /* Allocate core data for the session */
85 alloc_parms.nitems = 1;
86 alloc_parms.size = sizeof(struct tf_session);
87 alloc_parms.alignment = 0;
88 rc = tfp_calloc(&alloc_parms);
92 "Failed to allocate session data, rc:%d\n",
97 tfp->session->core_data = alloc_parms.mem_va;
99 session = (struct tf_session *)tfp->session->core_data;
100 tfp_memcpy(session->ctrl_chan_name,
101 parms->ctrl_chan_name,
102 TF_SESSION_NAME_MAX);
104 /* Initialize Session */
105 session->device_type = parms->device_type;
107 /* Construct the Session ID */
108 session->session_id.internal.domain = domain;
109 session->session_id.internal.bus = bus;
110 session->session_id.internal.device = device;
111 session->session_id.internal.fw_session_id = fw_session_id;
113 rc = tf_msg_session_qcfg(tfp);
117 "Query config message send failed, rc:%d\n",
122 session->ref_count++;
124 /* Return session ID */
125 parms->session_id = session->session_id;
128 "Session created, session_id:%d\n",
129 parms->session_id.id);
132 "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
133 parms->session_id.internal.domain,
134 parms->session_id.internal.bus,
135 parms->session_id.internal.device,
136 parms->session_id.internal.fw_session_id);
141 tfp_free(tfp->session->core_data);
142 tfp_free(tfp->session);
147 tf_close_session(tfp);
152 tf_attach_session(struct tf *tfp __rte_unused,
153 struct tf_attach_session_parms *parms __rte_unused)
161 /* - Open the shared memory for the attach_chan_name
162 * - Point to the shared session for this Device instance
163 * - Check that session is valid
164 * - Attach to the firmware so it can record there is more
165 * than one client of the session.
169 if (tfp->session->session_id.id != TF_SESSION_ID_INVALID) {
170 rc = tf_msg_session_attach(tfp,
171 parms->ctrl_chan_name,
175 #endif /* TF_SHARED */
180 tf_close_session(struct tf *tfp)
184 struct tf_session *tfs;
185 union tf_session_id session_id;
187 if (tfp == NULL || tfp->session == NULL)
190 tfs = (struct tf_session *)(tfp->session->core_data);
192 if (tfs->session_id.id != TF_SESSION_ID_INVALID) {
193 rc = tf_msg_session_close(tfp);
197 "Message send failed, rc:%d\n",
201 /* Update the ref_count */
205 session_id = tfs->session_id;
207 /* Final cleanup as we're last user of the session */
208 if (tfs->ref_count == 0) {
209 tfp_free(tfp->session->core_data);
210 tfp_free(tfp->session);
215 "Session closed, session_id:%d\n",
219 "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
220 session_id.internal.domain,
221 session_id.internal.bus,
222 session_id.internal.device,
223 session_id.internal.fw_session_id);