FAPI TM, WLS_LIB and ODULOW documentation
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p7 / nr5g_fapi_proc_rx_data_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 CRC.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_rx_data_ind Pointer to FAPI RX_DATA.indication message structure.
35  *  
36  *  @return     Returns ::SUCCESS and ::FAILURE.
37  *
38  *  @description
39  *  This message includes RX_DATA to be sent to L2.
40  *
41 **/
42 uint8_t nr5g_fapi_rx_data_indication(
43     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
44     PRXULSCHIndicationStruct p_phy_rx_ulsch_ind)
45 {
46     uint8_t phy_id;
47
48     fapi_rx_data_indication_t *p_fapi_rx_data_ind;
49     p_fapi_api_queue_elem_t p_list_elem;
50     p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
51     nr5g_fapi_stats_t *p_stats;
52
53     if (NULL == p_phy_ctx) {
54         NR5G_FAPI_LOG(ERROR_LOG, ("[NR5G_FAPI][RX_DATA.indication] Invalid "
55                 "Phy Context"));
56         return FAILURE;
57     }
58
59     if (NULL == p_phy_rx_ulsch_ind) {
60         NR5G_FAPI_LOG(ERROR_LOG, ("[NR5G_FAPI][RX_DATA.indication] Invalid "
61                 "RX_USLCH indication"));
62         return FAILURE;
63     }
64
65     phy_id = p_phy_rx_ulsch_ind->sSFN_Slot.nCarrierIdx;
66     p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
67     if (p_phy_instance->phy_id != phy_id) {
68         NR5G_FAPI_LOG(ERROR_LOG, ("[NR5G_FAPI][RX_DATA.indication] Invalid "
69                 "handle to phy instance"));
70         return FAILURE;
71     }
72
73     p_stats = &p_phy_instance->stats;
74     p_stats->iapi_stats.iapi_rx_data_ind++;
75     p_list_elem =
76         nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_RX_DATA_INDICATION, 1,
77         sizeof(fapi_rx_data_indication_t));
78     if (!p_list_elem) {
79         NR5G_FAPI_LOG(ERROR_LOG,
80             ("[NR5G_FAPI][RX_DATA.indication] Unable to create "
81                 "list element. Out of memory!!!"));
82         return FAILURE;
83     }
84
85     p_fapi_rx_data_ind = (fapi_rx_data_indication_t *) (p_list_elem + 1);
86     p_fapi_rx_data_ind->header.msg_id = FAPI_RX_DATA_INDICATION;
87     p_fapi_rx_data_ind->header.length =
88         (uint16_t) sizeof(fapi_rx_data_indication_t);
89
90     if (nr5g_fapi_rx_data_indication_to_fapi_translation(p_phy_instance,
91             p_phy_rx_ulsch_ind, p_fapi_rx_data_ind)) {
92         NR5G_FAPI_LOG(ERROR_LOG, ("[NR5G_FAPI][RX_DATA.indication] L1 to FAPI "
93                 "translation failed"));
94         return FAILURE;
95     }
96
97     nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
98
99     p_stats->fapi_stats.fapi_rx_data_ind++;
100     NR5G_FAPI_LOG(DEBUG_LOG, ("[NR5G_FAPI][%d][%d,%d]",
101             p_phy_instance->phy_id,
102             p_phy_rx_ulsch_ind->sSFN_Slot.nSFN,
103             p_phy_rx_ulsch_ind->sSFN_Slot.nSlot));
104
105     return SUCCESS;
106 }
107
108  /** @ingroup group_source_api_p7_fapi2mac_proc
109  *
110  *  @param[in]   ue_id  Variable holding ue_id received in RX_DATA.Indication..
111  *  @param[in]   p_ul_slot_info Pointer to ul slot info structure that stores the 
112  *               UL_TTI.request PDU info.
113  *  
114  *  @return     Returns Pointer to pusch info, if handle of p_ul_slot_info matches ue_id.
115                         NULL, if handle of p_ul_slot_info not matches ue_id
116  *
117  *  @description
118  *  This function retrieves the pusch info stored during corresponding UL_TTI.request processing.  
119  *  based on ue_id.
120  *
121 **/
122 nr5g_fapi_pusch_info_t *nr5g_fapi_get_pusch_info(
123     uint16_t ue_id,
124     nr5g_fapi_ul_slot_info_t * p_ul_slot_info)
125 {
126     uint8_t i, num_ulsch;
127
128     nr5g_fapi_pusch_info_t *p_pusch_info;
129
130     num_ulsch = p_ul_slot_info->num_ulsch;
131     for (i = 0; i < num_ulsch; i++) {
132         p_pusch_info = &p_ul_slot_info->pusch_info[i];
133         if (p_pusch_info->handle == ue_id) {
134             return p_pusch_info;
135         }
136     }
137     return NULL;
138 }
139
140  /** @ingroup group_source_api_p7_fapi2mac_proc
141  *
142  *  @param[in]   p_phy_instance Pointer to PHY instance.
143  *  @param[in]   p_phy_rx_ulsch_ind Pointer to IAPI RX_ULSCH.indication structure.
144  *  @param[out]  p_fapi_rx_data_ind Pointer to FAPI RX_DATA.indication structure.
145  *  
146  *  @return     Returns ::SUCCESS and ::FAILURE.
147  *
148  *  @description
149  *  This function converts IAPI RX_DATA.indication to FAPI CRC.indication
150  *  structure.
151  *
152 **/
153 uint8_t nr5g_fapi_rx_data_indication_to_fapi_translation(
154     p_nr5g_fapi_phy_instance_t p_phy_instance,
155     PRXULSCHIndicationStruct p_phy_rx_ulsch_ind,
156     fapi_rx_data_indication_t * p_fapi_rx_data_ind)
157 {
158     uint8_t num_ulsch, i;
159     uint8_t slot_no;
160     uint16_t frame_no;
161
162     nr5g_fapi_pusch_info_t *p_pusch_info;
163     fapi_pdu_ind_info_t *p_fapi_pdu_ind_info;
164     nr5g_fapi_ul_slot_info_t *p_ul_slot_info;
165     nr5g_fapi_stats_t *p_stats;
166     ULSCHPDUDataStruct *p_rx_ulsch_pdu_data;
167
168     p_stats = &p_phy_instance->stats;
169
170     frame_no = p_fapi_rx_data_ind->sfn = p_phy_rx_ulsch_ind->sSFN_Slot.nSFN;
171     slot_no = p_fapi_rx_data_ind->slot = p_phy_rx_ulsch_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,
178             ("[NR5G_FAPI] [RX_DATA.indication] No Valid data available "
179                 "for frame :%d and slot: %d", frame_no, slot_no));
180         return FAILURE;
181     }
182
183     num_ulsch = p_fapi_rx_data_ind->numPdus = p_phy_rx_ulsch_ind->nUlsch;
184     for (i = 0; i < num_ulsch; i++) {
185         p_stats->iapi_stats.iapi_rx_data_ind_pdus++;
186         p_fapi_pdu_ind_info = &p_fapi_rx_data_ind->pdus[i];
187         p_rx_ulsch_pdu_data = &p_phy_rx_ulsch_ind->sULSCHPDUDataStruct[i];
188         p_pusch_info =
189             nr5g_fapi_get_pusch_info(p_rx_ulsch_pdu_data->nUEId,
190             p_ul_slot_info);
191         if (p_pusch_info == NULL) {
192             NR5G_FAPI_LOG(ERROR_LOG,
193                 ("[NR5G_FAPI] [RX_DATA.indication] No Valid data available "
194                     "nUEId:%d, frame_no:%d, slot_no:%d",
195                     p_rx_ulsch_pdu_data->nUEId, frame_no, slot_no));
196             return FAILURE;
197         }
198
199         p_fapi_pdu_ind_info->handle = p_pusch_info->handle;
200         p_fapi_pdu_ind_info->rnti = p_rx_ulsch_pdu_data->nRNTI;
201         p_fapi_pdu_ind_info->harqId = p_pusch_info->harq_process_id;
202         p_fapi_pdu_ind_info->ul_cqi = p_pusch_info->ul_cqi;
203         p_fapi_pdu_ind_info->timingAdvance = p_pusch_info->timing_advance;
204         p_fapi_pdu_ind_info->rssi = 880;
205         p_fapi_pdu_ind_info->pdu_length = p_rx_ulsch_pdu_data->nPduLen;
206         p_fapi_pdu_ind_info->pduData = (void *)p_rx_ulsch_pdu_data->pPayload;
207
208         p_stats->fapi_stats.fapi_rx_data_ind_pdus++;
209     }
210     return SUCCESS;
211 }