1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
8 #include <rte_common.h>
10 #include "tf_session.h"
11 #include "tf_common.h"
16 tf_session_open_session(struct tf *tfp,
17 struct tf_session_open_session_parms *parms)
20 struct tf_session *session = NULL;
21 struct tfp_calloc_parms cparms;
22 uint8_t fw_session_id;
23 union tf_session_id *session_id;
25 TF_CHECK_PARMS2(tfp, parms);
27 /* Open FW session and get a new session_id */
28 rc = tf_msg_session_open(tfp,
29 parms->open_cfg->ctrl_chan_name,
35 "Session is already open, rc:%s\n",
39 "Open message send failed, rc:%s\n",
42 parms->open_cfg->session_id.id = TF_FW_SESSION_ID_INVALID;
46 /* Allocate session */
48 cparms.size = sizeof(struct tf_session_info);
50 rc = tfp_calloc(&cparms);
54 "Failed to allocate session info, rc:%s\n",
58 tfp->session = (struct tf_session_info *)cparms.mem_va;
60 /* Allocate core data for the session */
62 cparms.size = sizeof(struct tf_session);
64 rc = tfp_calloc(&cparms);
68 "Failed to allocate session data, rc:%s\n",
72 tfp->session->core_data = cparms.mem_va;
74 /* Initialize Session and Device */
75 session = (struct tf_session *)tfp->session->core_data;
76 session->ver.major = 0;
77 session->ver.minor = 0;
78 session->ver.update = 0;
80 session_id = &parms->open_cfg->session_id;
81 session->session_id.internal.domain = session_id->internal.domain;
82 session->session_id.internal.bus = session_id->internal.bus;
83 session->session_id.internal.device = session_id->internal.device;
84 session->session_id.internal.fw_session_id = fw_session_id;
85 /* Return the allocated fw session id */
86 session_id->internal.fw_session_id = fw_session_id;
88 session->shadow_copy = parms->open_cfg->shadow_copy;
90 tfp_memcpy(session->ctrl_chan_name,
91 parms->open_cfg->ctrl_chan_name,
95 parms->open_cfg->device_type,
97 &parms->open_cfg->resources,
99 /* Logging handled by dev_bind */
103 /* Query for Session Config
105 rc = tf_msg_session_qcfg(tfp);
108 "Query config message send failed, rc:%s\n",
113 session->ref_count++;
118 tfp_free(tfp->session->core_data);
119 tfp_free(tfp->session);
124 tf_close_session(tfp);
129 tf_session_attach_session(struct tf *tfp __rte_unused,
130 struct tf_session_attach_session_parms *parms __rte_unused)
132 int rc = -EOPNOTSUPP;
134 TF_CHECK_PARMS2(tfp, parms);
137 "Attach not yet supported, rc:%s\n",
143 tf_session_close_session(struct tf *tfp,
144 struct tf_session_close_session_parms *parms)
147 struct tf_session *tfs = NULL;
148 struct tf_dev_info *tfd = NULL;
150 TF_CHECK_PARMS2(tfp, parms);
152 rc = tf_session_get_session(tfp, &tfs);
155 "Session lookup failed, rc:%s\n",
160 if (tfs->session_id.id == TF_SESSION_ID_INVALID) {
163 "Invalid session id, unable to close, rc:%s\n",
168 /* Record the session we're closing so the caller knows the
171 *parms->session_id = tfs->session_id;
173 rc = tf_session_get_device(tfs, &tfd);
176 "Device lookup failed, rc:%s\n",
181 /* In case we're attached only the session client gets closed */
182 rc = tf_msg_session_close(tfp);
186 "FW Session close failed, rc:%s\n",
192 /* Final cleanup as we're last user of the session */
193 if (tfs->ref_count == 0) {
194 /* Unbind the device */
195 rc = dev_unbind(tfp, tfd);
199 "Device unbind failed, rc:%s\n",
203 tfp_free(tfp->session->core_data);
204 tfp_free(tfp->session);
212 tf_session_get_session(struct tf *tfp,
213 struct tf_session **tfs)
217 if (tfp->session == NULL || tfp->session->core_data == NULL) {
220 "Session not created, rc:%s\n",
225 *tfs = (struct tf_session *)(tfp->session->core_data);
231 tf_session_get_device(struct tf_session *tfs,
232 struct tf_dev_info **tfd)
236 if (tfs->dev == NULL) {
239 "Device not created, rc:%s\n",
250 tf_session_get_fw_session_id(struct tf *tfp,
251 uint8_t *fw_session_id)
254 struct tf_session *tfs = NULL;
256 if (tfp->session == NULL) {
259 "Session not created, rc:%s\n",
264 rc = tf_session_get_session(tfp, &tfs);
268 *fw_session_id = tfs->session_id.internal.fw_session_id;