ebda4ede5c0631e1399eddfcd9e309f8a6b8eae1
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p7 / nr5g_fapi_proc_srs_ind.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 SRS.indication message.
22  *
23  **/
24
25 #include "nr5g_fapi_framework.h"
26 #include "gnb_l1_l2_api.h"
27 #include "nr5g_fapi_fapi2mac_api.h"
28 #include "nr5g_fapi_fapi2mac_p7_proc.h"
29 #include "nr5g_fapi_fapi2mac_p7_pvt_proc.h"
30
31  /** @ingroup group_source_api_p7_fapi2mac_proc
32  *
33  *  @param[in]  p_phy_ctx Pointer to PHY context.
34  *  @param[in]  p_phy_srs_ind Pointer to FAPI SRS.indication message structure.
35  *  
36  *  @return     Returns ::SUCCESS and ::FAILURE.
37  *
38  *  @description
39  *  This message includes SRS PDU. 
40  *
41 **/
42 uint8_t nr5g_fapi_srs_indication(
43     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
44     PRXSRSIndicationStruct p_phy_srs_ind)
45 {
46     uint8_t phy_id;
47     fapi_srs_indication_t *p_fapi_srs_ind;
48     p_fapi_api_queue_elem_t p_list_elem;
49     p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
50     nr5g_fapi_stats_t *p_stats;
51
52     if (NULL == p_phy_ctx) {
53         NR5G_FAPI_LOG(ERROR_LOG, ("[SRS.indication] Invalid " "Phy Context"));
54         return FAILURE;
55     }
56
57     if (NULL == p_phy_srs_ind) {
58         NR5G_FAPI_LOG(ERROR_LOG, ("[SRS.indication] Invalid "
59                 "SRS Indication"));
60         return FAILURE;
61     }
62
63     phy_id = p_phy_srs_ind->sSFN_Slot.nCarrierIdx;
64     p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
65     if (p_phy_instance->phy_id != phy_id) {
66         NR5G_FAPI_LOG(ERROR_LOG, ("[SRS.indication] Invalid " "Phy Instance"));
67         return FAILURE;
68     }
69
70     p_stats = &p_phy_instance->stats;
71     p_stats->iapi_stats.iapi_srs_ind++;
72
73     p_list_elem =
74         nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_SRS_INDICATION, 1,
75         sizeof(fapi_srs_indication_t));
76     if (!p_list_elem) {
77         NR5G_FAPI_LOG(ERROR_LOG, ("[SRS.indication] Unable "
78                 "to create list element. Out of memory!!!"));
79         return FAILURE;
80     }
81
82     p_fapi_srs_ind = (fapi_srs_indication_t *) (p_list_elem + 1);
83     p_fapi_srs_ind->header.msg_id = FAPI_SRS_INDICATION;
84     p_fapi_srs_ind->header.length = (uint16_t) sizeof(fapi_srs_indication_t);
85
86     if (nr5g_fapi_srs_indication_to_fapi_translation(p_phy_instance,
87             p_phy_srs_ind, p_fapi_srs_ind)) {
88         NR5G_FAPI_LOG(ERROR_LOG,
89             ("[SRS.indication] L1 to FAPI " "translation failed"));
90         return FAILURE;
91     }
92
93     /* Add element to send list */
94     nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
95
96     p_stats->fapi_stats.fapi_srs_ind++;
97     NR5G_FAPI_LOG(DEBUG_LOG, ("[SRS.indication][%d][%d,%d]",
98             p_phy_instance->phy_id,
99             p_phy_srs_ind->sSFN_Slot.nSFN,
100             p_phy_srs_ind->sSFN_Slot.nSlot));
101
102     return SUCCESS;
103 }
104
105  /** @ingroup group_source_api_p7_fapi2mac_proc
106  *
107  *  @param[in]   ue_id  Variable holding ue_id received SRS.Indication..
108  *  @param[in]   p_ul_slot_info Pointer to ul slot info structure that stores the 
109  *               UL_TTI.request PDU info.
110  *  
111  *  @return     Returns Pointer to srs info, if handle of p_ul_slot_info matches ue_id.
112                         NULL, if handle of p_ul_slot_info not matches ue_id
113  *
114  *  @description
115  *  This function retrieves the srs info stored during corresponding UL_TTI.request processing.  
116  *  based on ue_id.
117  *
118 **/
119 nr5g_fapi_srs_info_t *nr5g_fapi_get_srs_info(
120     uint16_t nUEId,
121     nr5g_fapi_ul_slot_info_t * p_ul_slot_info)
122 {
123     uint8_t i, num_srs;
124
125     nr5g_fapi_srs_info_t *p_srs_info;
126
127     num_srs = p_ul_slot_info->num_srs;
128     for (i = 0; i < num_srs; i++) {
129         p_srs_info = &p_ul_slot_info->srs_info[i];
130         if (p_srs_info->handle == nUEId) {
131             return p_srs_info;
132         }
133     }
134     return NULL;
135 }
136
137  /** @ingroup group_source_api_p7_fapi2mac_proc
138  *
139  *  @param[in]  p_phy_instance Pointer to PHY instance.
140  *  @param[in]   p_phy_srs_ind Pointer to IAPI SRS.indication structure.
141  *  @param[out]  p_fapi_srs_ind Pointer to FAPI SRS.indication structure.
142  *  
143  *  @return     Returns ::SUCCESS and ::FAILURE.
144  *
145  *  @description
146  *  This function converts IAPI SRS.indication to FAPI SRS.indication
147  *  structure.
148  *
149 **/
150 uint8_t nr5g_fapi_srs_indication_to_fapi_translation(
151     p_nr5g_fapi_phy_instance_t p_phy_instance,
152     PRXSRSIndicationStruct p_phy_srs_ind,
153     fapi_srs_indication_t * p_fapi_srs_ind)
154 {
155     uint8_t num_srs_pdus, i;
156     uint8_t slot_no, num_rept_symbols, nr_of_symbols;
157     uint16_t frame_no, num_rbs, j, k;
158     int8_t wideband_snr = 0, rb_snr;
159     int16_t temp = 0;
160
161     nr5g_fapi_srs_info_t *p_srs_info;
162     fapi_srs_pdu_t *p_fapi_srs_pdu;
163     fapi_symb_snr_t *p_fapi_symb_snr;
164     nr5g_fapi_ul_slot_info_t *p_ul_slot_info;
165     nr5g_fapi_stats_t *p_stats;
166     ULSRSEstStruct *p_ul_srs_est_struct;
167
168     p_stats = &p_phy_instance->stats;
169
170     frame_no = p_fapi_srs_ind->sfn = p_phy_srs_ind->sSFN_Slot.nSFN;
171     slot_no = p_fapi_srs_ind->slot = p_phy_srs_ind->sSFN_Slot.nSlot;
172
173     p_ul_slot_info =
174         nr5g_fapi_get_ul_slot_info(frame_no, slot_no, p_phy_instance);
175
176     if (p_ul_slot_info == NULL) {
177         NR5G_FAPI_LOG(ERROR_LOG, ("[SRS.indication] No Valid data available "
178                 "for frame :%d and slot: %d", frame_no, slot_no));
179         return FAILURE;
180     }
181
182     num_srs_pdus = p_fapi_srs_ind->numPdus = p_phy_srs_ind->nNrOfSrs;
183     for (i = 0; i < num_srs_pdus; i++) {
184         p_stats->iapi_stats.iapi_srs_ind_pdus++;
185         p_fapi_srs_pdu = &p_fapi_srs_ind->srsPdus[i];
186         p_ul_srs_est_struct = &p_phy_srs_ind->sULSRSEstStruct[i];
187         p_srs_info =
188             nr5g_fapi_get_srs_info(p_ul_srs_est_struct->nUEId, p_ul_slot_info);
189         if (p_srs_info == NULL) {
190             NR5G_FAPI_LOG(ERROR_LOG,
191                 ("[SRS.indication] No Valid data available "
192                     "for nUEId:%d with frameno:%d, slot_no:%d",
193                     p_ul_srs_est_struct->nUEId, frame_no, slot_no));
194             return FAILURE;
195         }
196
197         p_fapi_srs_pdu->handle = p_srs_info->handle;
198         p_fapi_srs_pdu->rnti = p_ul_srs_est_struct->nRNTI;
199         p_fapi_srs_pdu->timingAdvance = 0xFFFF;
200
201         nr_of_symbols = p_fapi_srs_pdu->numSymbols =
202             p_ul_srs_est_struct->nNrOfSymbols;
203         for (j = 0; j < nr_of_symbols; j++) {
204             temp += p_ul_srs_est_struct->nWideBandSNR[j];
205         }
206         wideband_snr = temp / nr_of_symbols;
207
208         p_fapi_srs_pdu->wideBandSnr = (wideband_snr + 64) * 2;
209         num_rept_symbols = p_fapi_srs_pdu->numReportedSymbols = 1;
210
211         for (j = 0; j < num_rept_symbols; j++) {
212             p_fapi_symb_snr = &p_fapi_srs_pdu->symbSnr[j];
213             num_rbs = p_fapi_symb_snr->numRbs =
214                 p_ul_srs_est_struct->nNrOfBlocks * 4;
215
216             for (k = 0; k < num_rbs; k++) {
217                 rb_snr = p_ul_srs_est_struct->nBlockSNR[k / 68][k % 68];
218                 p_fapi_symb_snr->rbSNR[k] = (rb_snr + 64) * 2;
219             }
220         }
221         p_stats->fapi_stats.fapi_srs_ind_pdus++;
222     }
223
224     return SUCCESS;
225 }