1 /******************************************************************************
3 * Copyright (c) 2019 Intel.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 *******************************************************************************/
21 * This file consist of implementation of FAPI SHUTDOWN.response message.
24 #include "nr5g_fapi_framework.h"
25 #include "gnb_l1_l2_api.h"
26 #include "nr5g_fapi_fapi2mac_api.h"
27 #include "nr5g_fapi_fapi2mac_p5_proc.h"
28 #include "nr5g_fapi_stats.h"
29 #include "nr5g_fapi_fapi2phy_p5_proc.h"
30 #include "nr5g_fapi_fapi2phy_p5_pvt_proc.h"
31 #include "nr5g_fapi_memory.h"
33 /** @ingroup group_source_api_p5_fapi2phy_proc
35 * @param[in] p_phy_ctx Pointer to PHY context.
36 * @param[in] p_fapi_resp Pointer to IAPI SHUTDOWN.response message structure.
37 * @return Returns ::SUCCESS and ::FAILURE.
40 * This message allows PHY to indicate whether it has successfully cleaned up
41 * the PHY resources alloted or not.
44 uint8_t nr5g_fapi_shutdown_response(
45 p_nr5g_fapi_phy_ctx_t p_phy_ctx,
46 PSHUTDOWNRESPONSEStruct p_iapi_resp)
50 fapi_vendor_ext_shutdown_res_t *p_fapi_resp;
52 fapi_stop_ind_t *p_stop_ind;
54 fapi_error_ind_t *p_fapi_error_ind;
55 p_fapi_api_queue_elem_t p_list_elem;
56 p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
57 nr5g_fapi_stats_t *p_stats;
59 if (NULL == p_phy_ctx) {
60 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid "
65 if (NULL == p_iapi_resp) {
66 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid iapi "
67 "shutdown response message"));
71 phy_id = p_iapi_resp->sSFN_Slot.nCarrierIdx;
72 p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
73 if (p_phy_instance->phy_id != phy_id) {
74 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid "
78 p_stats = &p_phy_instance->stats;
79 p_stats->iapi_stats.iapi_shutdown_res++;
81 if (p_iapi_resp->nStatus == SUCCESS) {
84 nr5g_fapi_fapi2mac_create_api_list_elem(
85 FAPI_VENDOR_EXT_SHUTDOWN_RESPONSE, 1,
86 sizeof(fapi_vendor_ext_shutdown_res_t));
88 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Unable to create "
89 "list element. Out of memory!!!"));
93 p_fapi_resp = (fapi_vendor_ext_shutdown_res_t *) (p_list_elem + 1);
94 p_fapi_resp->header.msg_id = FAPI_VENDOR_EXT_SHUTDOWN_RESPONSE;
95 p_fapi_resp->header.length =
96 (uint16_t) sizeof(fapi_vendor_ext_shutdown_res_t);
97 p_fapi_resp->sfn = p_iapi_resp->sSFN_Slot.nSFN;
98 p_fapi_resp->slot = p_iapi_resp->sSFN_Slot.nSlot;
99 p_fapi_resp->nStatus = p_iapi_resp->nStatus;
101 /* Add element to send list */
102 nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
104 p_stats->fapi_stats.fapi_vext_shutdown_res++;
105 NR5G_FAPI_LOG(INFO_LOG, ("[SHUTDOWN.response][%d]", phy_id));
106 p_phy_instance->shutdown_retries = 0;
109 nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_STOP_INDICATION, 1,
110 sizeof(fapi_stop_ind_t));
112 NR5G_FAPI_LOG(ERROR_LOG,
113 ("[SHUTDOWN.response][STOP.Indication] Unable to create "
114 "list element. Out of memory!!!"));
117 p_stop_ind = (fapi_stop_ind_t *) (p_list_elem + 1);
118 p_stop_ind->header.msg_id = FAPI_STOP_INDICATION;
119 p_stop_ind->header.length = sizeof(fapi_stop_ind_t);
121 /* Add element to send list */
122 nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
124 p_stats->fapi_stats.fapi_stop_ind++;
125 NR5G_FAPI_LOG(INFO_LOG, ("[STOP.Indication][%d]", phy_id));
126 p_phy_instance->shutdown_retries = 0;
129 /* PHY SHUTDOWN Failed. Retrigger Shutdown request for 3 tries before
130 * triggering error indication towards L2 */
131 p_phy_instance->shutdown_retries++;
132 if (p_phy_instance->shutdown_retries <= 3) {
133 fapi_vendor_ext_shutdown_req_t fapi_req;
134 fapi_req.header.msg_id = FAPI_VENDOR_EXT_SHUTDOWN_REQUEST;
135 fapi_req.header.length = sizeof(fapi_vendor_ext_shutdown_req_t);
138 fapi_req.test_type = p_phy_instance->shutdown_test_type;
139 nr5g_fapi_shutdown_request(p_phy_instance, &fapi_req);
141 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid status "
142 "from PHY, hence triggering Error Indication"));
144 nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_ERROR_INDICATION,
145 1, sizeof(fapi_error_ind_t));
148 NR5G_FAPI_LOG(ERROR_LOG,
149 ("[SHUTDOWN.response][Error.Indication] Unable to create "
150 "list element. Out of memory!!!"));
153 p_fapi_error_ind = (fapi_error_ind_t *) (p_list_elem + 1);
154 p_fapi_error_ind->header.msg_id = FAPI_ERROR_INDICATION;
155 p_fapi_error_ind->header.length =
156 (uint16_t) sizeof(fapi_error_ind_t);
157 p_fapi_error_ind->sfn = p_iapi_resp->sSFN_Slot.nSFN;
158 p_fapi_error_ind->slot = p_iapi_resp->sSFN_Slot.nSlot;
159 p_fapi_error_ind->message_id = FAPI_VENDOR_EXT_SHUTDOWN_REQUEST;
160 p_fapi_error_ind->error_code = p_iapi_resp->nStatus;
162 /* Add element to send list */
163 nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
164 p_stats->fapi_stats.fapi_error_ind++;
165 p_phy_instance->shutdown_retries = 0;
166 NR5G_FAPI_LOG(INFO_LOG, ("[Error.Indication][%d]", phy_id));
170 nr5g_fapi_print_phy_instance_stats(p_phy_instance);
171 NR5G_FAPI_MEMSET(&p_phy_instance->stats, sizeof(nr5g_fapi_stats_t), 0,
172 sizeof(nr5g_fapi_stats_t));