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"
30 /** @ingroup group_source_api_p7_fapi2mac_proc
32 * @param[in] p_phy_ctx Pointer to PHY context.
33 * @param[in] p_phy_crc_ind Pointer to FAPI CRC.indication message structure.
35 * @return Returns ::SUCCESS and ::FAILURE.
38 * This message includes CRC PDU.
41 uint8_t nr5g_fapi_crc_indication(
42 p_nr5g_fapi_phy_ctx_t p_phy_ctx,
43 PCRCIndicationStruct p_phy_crc_ind)
46 fapi_crc_ind_t *p_fapi_crc_ind;
47 p_fapi_api_queue_elem_t p_list_elem;
48 p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
49 nr5g_fapi_stats_t *p_stats;
51 if (NULL == p_phy_ctx) {
52 NR5G_FAPI_LOG(ERROR_LOG, ("[CRC.indication] Invalid " "phy context"));
56 if (NULL == p_phy_crc_ind) {
57 NR5G_FAPI_LOG(ERROR_LOG, ("[NR5G_FAPI [CRC.indication] Invalid Phy "
62 phy_id = p_phy_crc_ind->sSFN_Slot.nCarrierIdx;
63 p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
64 if (p_phy_instance->phy_id != phy_id) {
65 NR5G_FAPI_LOG(ERROR_LOG, ("[CRC.indication] Invalid " "phy instance"));
69 p_stats = &p_phy_instance->stats;
70 p_stats->iapi_stats.iapi_crc_ind++;
73 nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_CRC_INDICATION, 1,
74 sizeof(fapi_crc_ind_t));
76 NR5G_FAPI_LOG(ERROR_LOG, ("[CRC.indication] Unable to create "
77 "list element. Out of memory!!!"));
81 p_fapi_crc_ind = (fapi_crc_ind_t *) (p_list_elem + 1);
82 p_fapi_crc_ind->header.msg_id = FAPI_CRC_INDICATION;
83 p_fapi_crc_ind->header.length = (uint16_t) sizeof(fapi_crc_ind_t);
85 if (nr5g_fapi_crc_indication_to_fapi_translation(p_phy_instance,
86 p_phy_crc_ind, p_fapi_crc_ind)) {
87 NR5G_FAPI_LOG(ERROR_LOG, ("[CRC.indication] L1 to FAPI "
88 "translation failed"));
92 nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
94 p_stats->fapi_stats.fapi_crc_ind++;
96 NR5G_FAPI_LOG(DEBUG_LOG, ("[CRC.indication][%d][%d,%d]",
97 p_phy_instance->phy_id,
98 p_phy_crc_ind->sSFN_Slot.nSFN, p_phy_crc_ind->sSFN_Slot.nSlot));
103 /** @ingroup group_source_api_p7_fapi2mac_proc
105 * @param[in] p_phy_instance Pointer to PHY instance.
106 * @param[in] p_phy_crc_ind Pointer to IAPI CRC.indication structure.
107 * @param[out] p_fapi_crc_ind Pointer to FAPI CRC.indication structure.
109 * @return Returns ::SUCCESS and ::FAILURE.
112 * This function converts IAPI CRC.indication to FAPI CRC.indication
116 uint8_t nr5g_fapi_crc_indication_to_fapi_translation(
117 p_nr5g_fapi_phy_instance_t p_phy_instance,
118 PCRCIndicationStruct p_phy_crc_ind,
119 fapi_crc_ind_t * p_fapi_crc_ind)
125 nr5g_fapi_pusch_info_t *p_pusch_info;
126 fapi_crc_ind_info_t *p_fapi_crc_ind_info;
127 nr5g_fapi_ul_slot_info_t *p_ul_slot_info;
128 nr5g_fapi_stats_t *p_stats;
129 ULCRCStruct *p_ul_crc_struct;
131 p_stats = &p_phy_instance->stats;
133 frame_no = p_fapi_crc_ind->sfn = p_phy_crc_ind->sSFN_Slot.nSFN;
134 slot_no = p_fapi_crc_ind->slot = p_phy_crc_ind->sSFN_Slot.nSlot;
137 nr5g_fapi_get_ul_slot_info(frame_no, slot_no, p_phy_instance);
139 if (p_ul_slot_info == NULL) {
140 NR5G_FAPI_LOG(ERROR_LOG, (" [CRC.indication] No Valid data available "
141 "for frame :%d and slot: %d", frame_no, slot_no));
145 num_crc = p_fapi_crc_ind->numCrcs = p_phy_crc_ind->nCrc;
146 for (i = 0; i < num_crc; i++) {
147 p_stats->iapi_stats.iapi_crc_ind_pdus++;
149 p_fapi_crc_ind_info = &p_fapi_crc_ind->crc[i];
150 p_ul_crc_struct = &p_phy_crc_ind->sULCRCStruct[i];
152 nr5g_fapi_get_pusch_info(p_ul_crc_struct->nUEId, p_ul_slot_info);
154 if (p_pusch_info == NULL) {
155 NR5G_FAPI_LOG(ERROR_LOG,
156 (" [CRC.indication] No Valid data available "
157 "nUEId:%d, frame_no:%d, slot_no:%d", p_ul_crc_struct->nUEId,
162 p_fapi_crc_ind_info->handle = p_pusch_info->handle;
163 p_fapi_crc_ind_info->rnti = p_ul_crc_struct->nRNTI;
164 p_fapi_crc_ind_info->harqId = p_pusch_info->harq_process_id;
165 p_fapi_crc_ind_info->tbCrcStatus = !(p_ul_crc_struct->nCrcFlag);
166 p_fapi_crc_ind_info->ul_cqi = (p_ul_crc_struct->nSNR + 64) * 2;
167 p_pusch_info->ul_cqi = p_fapi_crc_ind_info->ul_cqi;
169 p_fapi_crc_ind_info->numCb = 0;
170 p_pusch_info->timing_advance = p_fapi_crc_ind_info->timingAdvance = 31;
172 p_pusch_info->timing_advance = p_fapi_crc_ind_info->timingAdvance =
173 p_ul_crc_struct->nTA;
175 p_fapi_crc_ind_info->rssi = 880;
177 p_stats->fapi_stats.fapi_crc_ind_pdus++;