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_fapi2phy_api.h"
28 #include "nr5g_fapi_fapi2mac_p5_proc.h"
29 #include "nr5g_fapi_stats.h"
30 #include "nr5g_fapi_fapi2phy_p5_proc.h"
31 #include "nr5g_fapi_fapi2phy_p5_pvt_proc.h"
32 #include "nr5g_fapi_memory.h"
34 /** @ingroup group_source_api_p5_fapi2phy_proc
36 * @param[in] p_phy_ctx Pointer to PHY context.
37 * @param[in] p_fapi_resp Pointer to IAPI SHUTDOWN.response message structure.
38 * @return Returns ::SUCCESS and ::FAILURE.
41 * This message allows PHY to indicate whether it has successfully cleaned up
42 * the PHY resources alloted or not.
45 uint8_t nr5g_fapi_shutdown_response(
46 p_nr5g_fapi_phy_ctx_t p_phy_ctx,
47 PSHUTDOWNRESPONSEStruct p_iapi_resp)
51 fapi_vendor_ext_shutdown_res_t *p_fapi_resp;
53 fapi_stop_ind_t *p_stop_ind;
55 fapi_error_ind_t *p_fapi_error_ind;
56 p_fapi_api_queue_elem_t p_list_elem;
57 p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
58 nr5g_fapi_stats_t *p_stats;
60 if (NULL == p_phy_ctx) {
61 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid "
66 if (NULL == p_iapi_resp) {
67 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid iapi "
68 "shutdown response message"));
72 phy_id = p_iapi_resp->sSFN_Slot.nCarrierIdx;
73 p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
74 if (p_phy_instance->phy_id != phy_id) {
75 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid "
79 p_stats = &p_phy_instance->stats;
80 p_stats->iapi_stats.iapi_shutdown_res++;
82 if (p_iapi_resp->nStatus == SUCCESS) {
85 nr5g_fapi_fapi2mac_create_api_list_elem
86 (FAPI_VENDOR_EXT_SHUTDOWN_RESPONSE, 1,
87 sizeof(fapi_vendor_ext_shutdown_res_t));
89 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Unable to create "
90 "list element. Out of memory!!!"));
94 p_fapi_resp = (fapi_vendor_ext_shutdown_res_t *) (p_list_elem + 1);
95 p_fapi_resp->header.msg_id = FAPI_VENDOR_EXT_SHUTDOWN_RESPONSE;
96 p_fapi_resp->header.length =
97 (uint16_t) sizeof(fapi_vendor_ext_shutdown_res_t);
98 p_fapi_resp->sfn = p_iapi_resp->sSFN_Slot.nSFN;
99 p_fapi_resp->slot = p_iapi_resp->sSFN_Slot.nSlot;
100 p_fapi_resp->nStatus = p_iapi_resp->nStatus;
102 /* Add element to send list */
103 nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem, false);
105 p_stats->fapi_stats.fapi_vext_shutdown_res++;
106 NR5G_FAPI_LOG(INFO_LOG, ("[SHUTDOWN.response][%d]", phy_id));
107 p_phy_instance->shutdown_retries = 0;
110 nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_STOP_INDICATION, 1,
111 sizeof(fapi_stop_ind_t));
113 NR5G_FAPI_LOG(ERROR_LOG,
114 ("[SHUTDOWN.response][STOP.Indication] Unable to create "
115 "list element. Out of memory!!!"));
118 p_stop_ind = (fapi_stop_ind_t *) (p_list_elem + 1);
119 p_stop_ind->header.msg_id = FAPI_STOP_INDICATION;
120 p_stop_ind->header.length = sizeof(fapi_stop_ind_t);
122 /* Add element to send list */
123 nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem, false);
125 p_stats->fapi_stats.fapi_stop_ind++;
126 NR5G_FAPI_LOG(INFO_LOG, ("[STOP.Indication][%d]", phy_id));
127 p_phy_instance->shutdown_retries = 0;
130 /* PHY SHUTDOWN Failed. Retrigger Shutdown request for 3 tries before
131 * triggering error indication towards L2 */
132 p_phy_instance->shutdown_retries++;
133 if (p_phy_instance->shutdown_retries <= 3) {
134 fapi_vendor_ext_shutdown_req_t fapi_req;
135 fapi_req.header.msg_id = FAPI_VENDOR_EXT_SHUTDOWN_REQUEST;
136 fapi_req.header.length = sizeof(fapi_vendor_ext_shutdown_req_t);
139 fapi_req.test_type = p_phy_instance->shutdown_test_type;
140 nr5g_fapi_shutdown_request(0, p_phy_instance, &fapi_req);
141 nr5g_fapi_fapi2phy_send_api_list(0);
143 NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid status "
144 "from PHY, hence triggering Error Indication"));
146 nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_ERROR_INDICATION,
147 1, sizeof(fapi_error_ind_t));
150 NR5G_FAPI_LOG(ERROR_LOG,
151 ("[SHUTDOWN.response][Error.Indication] Unable to create "
152 "list element. Out of memory!!!"));
155 p_fapi_error_ind = (fapi_error_ind_t *) (p_list_elem + 1);
156 p_fapi_error_ind->header.msg_id = FAPI_ERROR_INDICATION;
157 p_fapi_error_ind->header.length =
158 (uint16_t) sizeof(fapi_error_ind_t);
159 p_fapi_error_ind->sfn = p_iapi_resp->sSFN_Slot.nSFN;
160 p_fapi_error_ind->slot = p_iapi_resp->sSFN_Slot.nSlot;
161 p_fapi_error_ind->message_id = FAPI_VENDOR_EXT_SHUTDOWN_REQUEST;
162 p_fapi_error_ind->error_code = p_iapi_resp->nStatus;
164 /* Add element to send list */
165 nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem, false);
166 p_stats->fapi_stats.fapi_error_ind++;
167 p_phy_instance->shutdown_retries = 0;
168 NR5G_FAPI_LOG(INFO_LOG, ("[Error.Indication][%d]", phy_id));
172 nr5g_fapi_print_phy_instance_stats(p_phy_instance);
173 NR5G_FAPI_MEMSET(&p_phy_instance->stats, sizeof(nr5g_fapi_stats_t), 0,
174 sizeof(nr5g_fapi_stats_t));