Update to odulow per maintenance bronze
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p5 / nr5g_fapi_proc_shutdown_resp.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 Intel.
4 *
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
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 *******************************************************************************/
18
19 /**
20  * @file
21  * This file consist of implementation of FAPI SHUTDOWN.response message.
22  *
23  **/
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"
33
34  /** @ingroup group_source_api_p5_fapi2phy_proc
35  *
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.
39  *
40  *  @description
41  *  This message allows PHY to indicate whether it has successfully cleaned up 
42  *  the PHY resources alloted or not.
43  *
44 **/
45 uint8_t nr5g_fapi_shutdown_response(
46     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
47     PSHUTDOWNRESPONSEStruct p_iapi_resp)
48 {
49     uint8_t phy_id;
50 #ifdef DEBUG_MODE
51     fapi_vendor_ext_shutdown_res_t *p_fapi_resp;
52 #else
53     fapi_stop_ind_t *p_stop_ind;
54 #endif
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;
59
60     if (NULL == p_phy_ctx) {
61         NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid "
62                 "phy instance"));
63         return FAILURE;
64     }
65
66     if (NULL == p_iapi_resp) {
67         NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid iapi "
68                 "shutdown response message"));
69         return FAILURE;
70     }
71
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 "
76                 "phy instance"));
77         return FAILURE;
78     }
79     p_stats = &p_phy_instance->stats;
80     p_stats->iapi_stats.iapi_shutdown_res++;
81
82     if (p_iapi_resp->nStatus == SUCCESS) {
83 #ifdef DEBUG_MODE
84         p_list_elem =
85             nr5g_fapi_fapi2mac_create_api_list_elem
86             (FAPI_VENDOR_EXT_SHUTDOWN_RESPONSE, 1,
87             sizeof(fapi_vendor_ext_shutdown_res_t));
88         if (!p_list_elem) {
89             NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Unable to create "
90                     "list element. Out of memory!!!"));
91             return FAILURE;
92         }
93
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;
101
102         /* Add element to send list */
103         nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
104
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;
108 #else
109         p_list_elem =
110             nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_STOP_INDICATION, 1,
111             sizeof(fapi_stop_ind_t));
112         if (!p_list_elem) {
113             NR5G_FAPI_LOG(ERROR_LOG,
114                 ("[SHUTDOWN.response][STOP.Indication] Unable to create "
115                     "list element. Out of memory!!!"));
116             return FAILURE;
117         }
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);
121
122         /* Add element to send list */
123         nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
124
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;
128 #endif
129     } else {
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);
137             fapi_req.sfn = 0;
138             fapi_req.slot = 0;
139             fapi_req.test_type = p_phy_instance->shutdown_test_type;
140             nr5g_fapi_shutdown_request(p_phy_instance, &fapi_req);
141             nr5g_fapi_fapi2phy_send_api_list();
142         } else {
143             NR5G_FAPI_LOG(ERROR_LOG, ("[SHUTDOWN.response] Invalid status "
144                     "from PHY, hence triggering Error Indication"));
145             p_list_elem =
146                 nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_ERROR_INDICATION,
147                 1, sizeof(fapi_error_ind_t));
148
149             if (!p_list_elem) {
150                 NR5G_FAPI_LOG(ERROR_LOG,
151                     ("[SHUTDOWN.response][Error.Indication] Unable to create "
152                         "list element. Out of memory!!!"));
153                 return FAILURE;
154             }
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;
163
164             /* Add element to send list */
165             nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
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));
169         }
170     }
171
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));
175     return SUCCESS;
176 }