* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p7 / nr5g_fapi_proc_rx_data_uci_ind.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2021 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 UCI.indication on PUSCH message.
22  *
23  **/
24
25 #include "nr5g_mac_phy_api.h"
26 #include "nr5g_fapi_framework.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 #include "nr5g_fapi_memory.h"
31
32  /** @ingroup group_source_api_p7_fapi2mac_proc
33  *
34  *  @param[in]  p_phy_ctx Pointer to PHY Context.
35  *  @param[in]  p_phy_rx_ulsch_uci_ind Pointer to IAPI RX_ULSCH_UCI.indication message structure.
36  *  
37  *  @return     Returns ::SUCCESS and ::FAILURE.
38  *
39  *  @description
40  *  This message includes UCI payload on PUSCH.
41  *
42 **/
43 uint8_t nr5g_fapi_rx_data_uci_indication(
44     bool is_urllc,
45     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
46     PRXULSCHUCIIndicationStruct p_phy_rx_ulsch_uci_ind)
47 {
48     uint8_t phy_id;
49
50     fapi_uci_indication_t *p_fapi_uci_ind;
51     p_fapi_api_queue_elem_t p_list_elem;
52     p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
53     nr5g_fapi_stats_t *p_stats;
54
55     if (NULL == p_phy_ctx) {
56         NR5G_FAPI_LOG(ERROR_LOG, ("[UCI.indication on PUSCH] Invalid Phy "
57                 "Context"));
58         return FAILURE;        
59     }
60
61     if (NULL == p_phy_rx_ulsch_uci_ind) {
62         NR5G_FAPI_LOG(ERROR_LOG, ("[UCI.indication on PUSCH] Invalid Phy "
63                 "RX_ULSCH_UCI indication"));
64         return FAILURE;        
65     }
66
67     phy_id = p_phy_rx_ulsch_uci_ind->sSFN_Slot.nCarrierIdx;
68     p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
69     if (p_phy_instance->phy_id != phy_id) {
70         NR5G_FAPI_LOG(ERROR_LOG, ("[UCI.indication on PUSCH] Invalid Phy "
71                 "instance"));
72         return FAILURE;
73     }
74     
75     p_stats = &p_phy_instance->stats;
76     p_stats->iapi_stats.iapi_uci_ind++;
77
78     p_list_elem = 
79         nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_UCI_INDICATION, 1,
80             sizeof(fapi_uci_indication_t));
81     if (!p_list_elem) {
82         NR5G_FAPI_LOG(ERROR_LOG, ("[UCI.indication on PUSCH] Unable to create "
83                 "list element. Out of memory!!!"));
84         return FAILURE;        
85     }
86
87     p_fapi_uci_ind = (fapi_uci_indication_t *) (p_list_elem + 1);
88     p_fapi_uci_ind->header.msg_id = FAPI_UCI_INDICATION;
89     p_fapi_uci_ind->header.length = sizeof(fapi_uci_indication_t);
90
91     if (nr5g_fapi_rx_data_uci_indication_to_fapi_translation(p_phy_instance,
92             p_phy_rx_ulsch_uci_ind, p_fapi_uci_ind)) {
93         NR5G_FAPI_LOG(ERROR_LOG,
94             ("[UCI.indication on PUSCH] FAPI to L1 " "translation failed"));
95         return FAILURE;
96     }
97
98     nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem, is_urllc);
99
100     p_stats->fapi_stats.fapi_uci_ind++;
101
102     NR5G_FAPI_LOG(DEBUG_LOG, ("[UCI.indication on PUSCH][%u][%u,%u,%u] is_urllc %u",
103         p_phy_instance->phy_id,p_phy_rx_ulsch_uci_ind->sSFN_Slot.nSFN,
104         p_phy_rx_ulsch_uci_ind->sSFN_Slot.nSlot,
105         p_phy_rx_ulsch_uci_ind->sSFN_Slot.nSym, is_urllc));
106
107     return SUCCESS;
108 }
109
110 /** @ingroup group_source_api_p7_fapi2mac_proc
111  *
112  *  @param[in]  p_phy_instance Pointer to PHY instance.
113  *  @param[in]   p_phy_uci_ind Pointer to IAPI RX_ULSCH_UCI.indication structure.
114  *  @param[out]  p_fapi_uci_ind Pointer to FAPI UCI.indication structure.
115  *  
116  *  @return     Returns ::SUCCESS and ::FAILURE.
117  *
118  *  @description
119  *  This function converts IAPI RX_ULSCH_UCI.indication to FAPI UCI.indication
120  *  structure.
121  *
122 **/
123 uint8_t nr5g_fapi_rx_data_uci_indication_to_fapi_translation(
124     p_nr5g_fapi_phy_instance_t p_phy_instance,
125     PRXULSCHUCIIndicationStruct p_phy_rx_ulsch_uci_ind,
126     fapi_uci_indication_t * p_fapi_uci_ind)
127 {
128     uint8_t num_uci, i;
129     uint8_t nUciDetected, nUciCsiP1Detected, nUciCsiP2Detected;
130
131     PULSCHUCIPDUDataStruct p_phy_uci_pdu_data_struct;
132     fapi_uci_pdu_info_t *p_fapi_uci_pdu_info;
133     fapi_uci_o_pusch_t *p_uci_push;
134     nr5g_fapi_stats_t *p_stats;
135
136     p_stats = &p_phy_instance->stats;
137
138     p_fapi_uci_ind->sfn = p_phy_rx_ulsch_uci_ind->sSFN_Slot.nSFN;
139     p_fapi_uci_ind->slot = p_phy_rx_ulsch_uci_ind->sSFN_Slot.nSlot;
140     
141     num_uci = p_fapi_uci_ind->numUcis = p_phy_rx_ulsch_uci_ind->nUlschUci;
142
143     for (i = 0; i < num_uci; i++) {
144         p_stats->iapi_stats.iapi_uci_ind_pdus++;
145
146         p_fapi_uci_pdu_info = &p_fapi_uci_ind->uciPdu[i];
147         p_phy_uci_pdu_data_struct =
148             &p_phy_rx_ulsch_uci_ind->sULSCHUCIPDUDataStruct[i];
149
150         p_fapi_uci_pdu_info->pduType = 0;
151         p_fapi_uci_pdu_info->pduSize = sizeof(fapi_uci_o_pusch_t);
152         
153         p_uci_push = &p_fapi_uci_pdu_info->uci.uciPusch;
154         memset(p_uci_push, 0, sizeof(fapi_uci_o_pusch_t));
155
156         p_uci_push->handle = p_phy_uci_pdu_data_struct->nUEId;
157         p_uci_push->pduBitmap = 0;
158         p_uci_push->ul_cqi = 0xff;
159         p_uci_push->rnti = p_phy_uci_pdu_data_struct->nRNTI;
160         p_uci_push->timingAdvance = 0xffff;
161         p_uci_push->rssi = 0xffff;
162         
163         nUciDetected = p_phy_uci_pdu_data_struct->nUciDetected;
164         if (nUciDetected) {
165             p_uci_push->pduBitmap |= 0x02;
166             p_uci_push->harqInfo.harqCrc = p_phy_uci_pdu_data_struct->nUciCrc;
167             p_uci_push->harqInfo.harqBitLen =
168                 p_phy_uci_pdu_data_struct->nPduUciAckLen;
169             NR5G_FAPI_MEMCPY(p_uci_push->harqInfo.harqPayload,
170                 sizeof(uint8_t) * FAPI_MAX_HARQ_INFO_LEN_BYTES,
171                 p_phy_uci_pdu_data_struct->nUciAckBits,
172                 sizeof(uint8_t) * FAPI_MAX_HARQ_INFO_LEN_BYTES);
173         }
174
175         nUciCsiP1Detected = p_phy_uci_pdu_data_struct->nUciCsiP1Detected;
176         if (nUciCsiP1Detected) {
177             p_uci_push->pduBitmap |= 0x04;
178             p_uci_push->csiPart1info.csiPart1Crc =
179                 p_phy_uci_pdu_data_struct->nUciCsiP1Crc;
180             p_uci_push->csiPart1info.csiPart1BitLen =
181                 p_phy_uci_pdu_data_struct->nPduUciCsiP1Len;
182             NR5G_FAPI_MEMCPY(p_uci_push->csiPart1info.csiPart1Payload,
183                 sizeof(uint8_t) * FAPI_MAX_CSI_PART1_DATA_BYTES,
184                 p_phy_uci_pdu_data_struct->nUciCsiP1Bits,
185                 sizeof(uint8_t) * FAPI_MAX_CSI_PART1_DATA_BYTES);
186         }
187
188         nUciCsiP2Detected = p_phy_uci_pdu_data_struct->nUciCsiP2Detected;
189         if (nUciCsiP2Detected) {
190             p_uci_push->pduBitmap |= 0x08;
191             p_uci_push->csiPart2info.csiPart2Crc =
192                 p_phy_uci_pdu_data_struct->nUciCsiP2Crc;
193             p_uci_push->csiPart2info.csiPart2BitLen =
194                 p_phy_uci_pdu_data_struct->nPduUciCsiP2Len;
195             NR5G_FAPI_MEMCPY(p_uci_push->csiPart2info.csiPart2Payload,
196                 sizeof(uint8_t) * FAPI_MAX_CSI_PART2_DATA_BYTES,
197                 p_phy_uci_pdu_data_struct->nUciCsiP2Bits,
198                 sizeof(uint8_t) * FAPI_MAX_CSI_PART2_DATA_BYTES);
199         }
200         p_stats->fapi_stats.fapi_uci_ind_pdus++;
201     }
202
203     return SUCCESS;
204 }