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 *******************************************************************************/
20 * This file consist of implementation of FAPI CRC.indication 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_fapi2mac_p7_proc.h"
28 #include "nr5g_fapi_fapi2mac_p7_pvt_proc.h"
29 #include "nr5g_fapi_snr_conversion.h"
31 /** @ingroup group_source_api_p7_fapi2mac_proc
33 * @param[in] p_phy_ctx Pointer to PHY context.
34 * @param[in] p_phy_crc_ind Pointer to FAPI CRC.indication message structure.
36 * @return Returns ::SUCCESS and ::FAILURE.
39 * This message includes CRC PDU.
42 uint8_t nr5g_fapi_crc_indication(
44 p_nr5g_fapi_phy_ctx_t p_phy_ctx,
45 p_fapi_api_stored_vendor_queue_elems vendor_extension_elems,
46 PCRCIndicationStruct p_phy_crc_ind)
49 fapi_crc_ind_t *p_fapi_crc_ind;
50 p_fapi_api_queue_elem_t p_list_elem;
51 p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
52 nr5g_fapi_stats_t *p_stats;
54 if (NULL == p_phy_ctx) {
55 NR5G_FAPI_LOG(ERROR_LOG, ("[CRC.indication] Invalid " "phy context"));
59 if (NULL == p_phy_crc_ind) {
60 NR5G_FAPI_LOG(ERROR_LOG, ("[NR5G_FAPI [CRC.indication] Invalid Phy "
65 phy_id = p_phy_crc_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, ("[CRC.indication] Invalid " "phy instance"));
72 p_stats = &p_phy_instance->stats;
73 p_stats->iapi_stats.iapi_crc_ind++;
76 nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_CRC_INDICATION, 1,
77 sizeof(fapi_crc_ind_t));
80 NR5G_FAPI_LOG(ERROR_LOG, ("[CRC.indication] Unable to create "
81 "list element. Out of memory!!!"));
85 p_fapi_crc_ind = (fapi_crc_ind_t *) (p_list_elem + 1);
86 p_fapi_crc_ind->header.msg_id = FAPI_CRC_INDICATION;
87 p_fapi_crc_ind->header.length = (uint16_t) sizeof(fapi_crc_ind_t);
89 fapi_vendor_p7_ind_msg_t* p_fapi_vend_p7 =
90 nr5g_fapi_proc_vendor_p7_msg_get(vendor_extension_elems, phy_id);
91 fapi_vendor_ext_snr_t* p_fapi_snr = p_fapi_vend_p7 ? &p_fapi_vend_p7->crc_snr : NULL;
92 fapi_vendor_ext_crc_ind_t* p_fapi_vend_crc_ind = p_fapi_vend_p7 ? &p_fapi_vend_p7->crc_ind : NULL;
94 if (p_fapi_vend_crc_ind) {
95 p_fapi_vend_crc_ind->carrier_idx = phy_id;
96 p_fapi_vend_crc_ind->sym = p_phy_crc_ind->sSFN_Slot.nSym;
99 if (nr5g_fapi_crc_indication_to_fapi_translation(is_urllc, p_phy_instance,
100 p_phy_crc_ind, p_fapi_crc_ind, p_fapi_snr)) {
101 NR5G_FAPI_LOG(ERROR_LOG, ("[CRC.indication] L1 to FAPI "
102 "translation failed"));
106 nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem, is_urllc);
108 p_stats->fapi_stats.fapi_crc_ind++;
110 NR5G_FAPI_LOG(DEBUG_LOG, ("[CRC.indication][%u][%u,%u,%u] is_urllc %u",
111 p_phy_instance->phy_id,
112 p_phy_crc_ind->sSFN_Slot.nSFN, p_phy_crc_ind->sSFN_Slot.nSlot,
113 p_phy_crc_ind->sSFN_Slot.nSym, is_urllc));
118 /** @ingroup group_source_api_p7_fapi2mac_proc
120 * @param[in] p_phy_instance Pointer to PHY instance.
121 * @param[in] p_phy_crc_ind Pointer to IAPI CRC.indication structure.
122 * @param[out] p_fapi_crc_ind Pointer to FAPI CRC.indication structure.
124 * @return Returns ::SUCCESS and ::FAILURE.
127 * This function converts IAPI CRC.indication to FAPI CRC.indication
131 uint8_t nr5g_fapi_crc_indication_to_fapi_translation(
133 p_nr5g_fapi_phy_instance_t p_phy_instance,
134 PCRCIndicationStruct p_phy_crc_ind,
135 fapi_crc_ind_t * p_fapi_crc_ind,
136 fapi_vendor_ext_snr_t * p_fapi_snr)
140 uint16_t slot_no, frame_no;
142 nr5g_fapi_pusch_info_t *p_pusch_info;
143 fapi_crc_ind_info_t *p_fapi_crc_ind_info;
144 nr5g_fapi_ul_slot_info_t *p_ul_slot_info;
145 nr5g_fapi_stats_t *p_stats;
146 ULCRCStruct *p_ul_crc_struct;
148 p_stats = &p_phy_instance->stats;
150 frame_no = p_fapi_crc_ind->sfn = p_phy_crc_ind->sSFN_Slot.nSFN;
151 slot_no = p_fapi_crc_ind->slot = p_phy_crc_ind->sSFN_Slot.nSlot;
152 symbol_no = p_phy_crc_ind->sSFN_Slot.nSym;
155 nr5g_fapi_get_ul_slot_info(is_urllc, frame_no, slot_no, symbol_no, p_phy_instance);
157 if (p_ul_slot_info == NULL) {
158 NR5G_FAPI_LOG(ERROR_LOG, (" [CRC.indication] No Valid data available "
159 "for frame :%d, slot: %d, symbol: %d, urllc %u", frame_no, slot_no, symbol_no, is_urllc));
163 num_crc = p_fapi_crc_ind->numCrcs = p_phy_crc_ind->nCrc;
164 for (i = 0; i < num_crc; i++) {
165 p_stats->iapi_stats.iapi_crc_ind_pdus++;
167 p_fapi_crc_ind_info = &p_fapi_crc_ind->crc[i];
168 p_ul_crc_struct = &p_phy_crc_ind->sULCRCStruct[i];
170 nr5g_fapi_get_pusch_info(p_ul_crc_struct->nUEId, p_ul_slot_info);
172 if (p_pusch_info == NULL) {
173 NR5G_FAPI_LOG(ERROR_LOG,
174 (" [CRC.indication] No Valid data available "
175 "nUEId:%d, frame_no:%d, slot_no:%d, urllc %u", p_ul_crc_struct->nUEId,
176 frame_no, slot_no, is_urllc));
180 p_fapi_crc_ind_info->handle = p_pusch_info->handle;
181 p_fapi_crc_ind_info->rnti = p_ul_crc_struct->nRNTI;
182 p_fapi_crc_ind_info->harqId = p_pusch_info->harq_process_id;
183 p_fapi_crc_ind_info->tbCrcStatus = !(p_ul_crc_struct->nCrcFlag);
184 p_fapi_crc_ind_info->ul_cqi = nr5g_fapi_convert_snr_iapi_to_fapi(p_ul_crc_struct->nSNR);
187 p_fapi_snr->nSNR[i] = p_ul_crc_struct->nSNR;
189 p_pusch_info->ul_cqi = p_fapi_crc_ind_info->ul_cqi;
191 p_fapi_crc_ind_info->numCb = 0;
192 p_pusch_info->timing_advance = p_fapi_crc_ind_info->timingAdvance = 31;
194 p_pusch_info->timing_advance = p_fapi_crc_ind_info->timingAdvance =
195 p_ul_crc_struct->nTA;
197 p_fapi_crc_ind_info->rssi = 880;
199 p_stats->fapi_stats.fapi_crc_ind_pdus++;