From d0ae11783a562ce042f09fff59500b01312b79c8 Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@eurecom.fr>
Date: Fri, 11 Dec 2020 17:29:31 +0100
Subject: [PATCH] Integrate nr_fill_nfapi_dl_pdu() back into
 nr_schedule_ue_spec()

Initially, filling the PDCCH and PDSCH nFAPI messages was split into a
separate function (in an attempt to keep the code structure similar to
LTE). However, this proved as not helpful: the nr_fill_nfapi_dl_pdu()
just filled the messages, with a parameter list almost size as long as
the actual messages (because most parameters are kind of independent).
This made no sense, so we put it back.

Also, from an understanding POV, they just fill a message as specified
in SCF222, so it should not be a problem.
---
 .../LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c   | 203 +++++++++++++++--
 .../NR_MAC_gNB/gNB_scheduler_primitives.c     | 207 ------------------
 openair2/LAYER2/NR_MAC_gNB/mac_proto.h        |  16 --
 3 files changed, 182 insertions(+), 244 deletions(-)

diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
index fec848f921a..adf4dc9f456 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
@@ -547,9 +547,10 @@ void nr_schedule_ue_spec(module_id_t module_id,
   /* PREPROCESSOR */
   gNB_mac->pre_processor_dl(module_id, frame, slot);
 
+  const int CC_id = 0;
+  NR_ServingCellConfigCommon_t *scc = gNB_mac->common_channels[CC_id].ServingCellConfigCommon;
   NR_UE_info_t *UE_info = &gNB_mac->UE_info;
 
-  const int CC_id = 0;
   NR_UE_list_t *UE_list = &UE_info->list;
   for (int UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
     NR_UE_sched_ctrl_t *sched_ctrl = &UE_info->UE_sched_ctrl[UE_id];
@@ -583,10 +584,13 @@ void nr_schedule_ue_spec(module_id_t module_id,
 
     uint8_t N_PRB_DMRS =
         getN_PRB_DMRS(sched_ctrl->active_bwp, sched_ctrl->numDmrsCdmGrpsNoData);
-
     uint8_t N_DMRS_SLOT = get_num_dmrs_symbols(sched_ctrl->active_bwp->bwp_Dedicated->pdsch_Config->choice.setup,
                                                RC.nrmac[module_id]->common_channels->ServingCellConfigCommon->dmrs_TypeA_Position ,
                                                nrOfSymbols);
+    const nfapi_nr_dmrs_type_e dmrsConfigType = getDmrsConfigType(sched_ctrl->active_bwp);
+    const int nrOfLayers = 1;
+    const uint16_t R = nr_get_code_rate_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx);
+    const uint8_t Qm = nr_get_Qm_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx);
     const uint32_t TBS =
         nr_compute_tbs(nr_get_Qm_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
                        nr_get_code_rate_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
@@ -595,7 +599,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
                        N_PRB_DMRS * N_DMRS_SLOT,
                        0 /* N_PRB_oh, 0 for initialBWP */,
                        0 /* tb_scaling */,
-                       1 /* nrOfLayers */)
+                       nrOfLayers)
         >> 3;
 
     const int current_harq_pid = slot % 8;
@@ -605,26 +609,183 @@ void nr_schedule_ue_spec(module_id_t module_id,
     harq->is_waiting = 1;
     UE_info->mac_stats[UE_id].dlsch_rounds[harq->round]++;
 
-    LOG_D(MAC, "%4d.%2d RNTI %04x start %d RBS %d MCS %d TBS %d HARQ PID %d round %d NDI %d\n",
-          frame, slot, rnti, sched_ctrl->rbStart, sched_ctrl->rbSize, sched_ctrl->mcs,
-          TBS, current_harq_pid, harq->round, harq->ndi);
+    LOG_D(MAC,
+          "%4d.%2d RNTI %04x start %d RBs %d startSymbol %d nb_symbsol %d MCS %d TBS %d HARQ PID %d round %d NDI %d\n",
+          frame,
+          slot,
+          rnti,
+          sched_ctrl->rbStart,
+          sched_ctrl->rbSize,
+          startSymbolIndex,
+          nrOfSymbols,
+          sched_ctrl->mcs,
+          TBS,
+          current_harq_pid,
+          harq->round,
+          harq->ndi);
+
+    NR_BWP_Downlink_t *bwp = sched_ctrl->active_bwp;
+    AssertFatal(bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList,
+                "searchSpacesToAddModList is null\n");
+    AssertFatal(bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList->list.count > 0,
+                "searchSPacesToAddModList is empty\n");
+
 
     nfapi_nr_dl_tti_request_body_t *dl_req = &gNB_mac->DL_req[CC_id].dl_tti_request_body;
-    nr_fill_nfapi_dl_pdu(module_id,
-                         dl_req,
-                         rnti,
-                         UE_info->secondaryCellGroup[UE_id],
-                         sched_ctrl,
-                         pucch,
-                         getDmrsConfigType(sched_ctrl->active_bwp),
-                         nr_get_code_rate_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
-                         nr_get_Qm_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
-                         TBS,
-                         startSymbolIndex,
-                         nrOfSymbols,
-                         current_harq_pid,
-                         harq->ndi,
-                         harq->round);
+
+    /* TODO: can be moved down? */
+    nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdcch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs];
+    memset(dl_tti_pdcch_pdu, 0, sizeof(nfapi_nr_dl_tti_request_pdu_t));
+    dl_tti_pdcch_pdu->PDUType = NFAPI_NR_DL_TTI_PDCCH_PDU_TYPE;
+    dl_tti_pdcch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdcch_pdu));
+    dl_req->nPDUs += 1;
+    nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu = &dl_tti_pdcch_pdu->pdcch_pdu.pdcch_pdu_rel15;
+
+    nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdsch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs];
+    memset(dl_tti_pdsch_pdu, 0, sizeof(nfapi_nr_dl_tti_request_pdu_t));
+    dl_tti_pdsch_pdu->PDUType = NFAPI_NR_DL_TTI_PDSCH_PDU_TYPE;
+    dl_tti_pdsch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdsch_pdu));
+    dl_req->nPDUs += 1;
+    nfapi_nr_dl_tti_pdsch_pdu_rel15_t *pdsch_pdu = &dl_tti_pdsch_pdu->pdsch_pdu.pdsch_pdu_rel15;
+
+    pdsch_pdu->pduBitmap = 0;
+    pdsch_pdu->rnti = rnti;
+    pdsch_pdu->pduIndex = gNB_mac->pdu_index[CC_id]++;
+
+    // BWP
+    pdsch_pdu->BWPSize  = NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth, MAX_BWP_SIZE);
+    pdsch_pdu->BWPStart = NRRIV2PRBOFFSET(bwp->bwp_Common->genericParameters.locationAndBandwidth,MAX_BWP_SIZE);
+    pdsch_pdu->SubcarrierSpacing = bwp->bwp_Common->genericParameters.subcarrierSpacing;
+    if (bwp->bwp_Common->genericParameters.cyclicPrefix)
+      pdsch_pdu->CyclicPrefix = *bwp->bwp_Common->genericParameters.cyclicPrefix;
+    else
+      pdsch_pdu->CyclicPrefix = 0;
+
+    // Codeword information
+    pdsch_pdu->NrOfCodewords = 1;
+    pdsch_pdu->targetCodeRate[0] = R;
+    pdsch_pdu->qamModOrder[0] = Qm;
+    pdsch_pdu->mcsIndex[0] = sched_ctrl->mcs;
+    pdsch_pdu->mcsTable[0] = sched_ctrl->mcsTableIdx;
+    pdsch_pdu->rvIndex[0] = nr_rv_round_map[harq->round];
+    pdsch_pdu->TBSize[0] = TBS;
+
+    pdsch_pdu->dataScramblingId = *scc->physCellId;
+    pdsch_pdu->nrOfLayers = nrOfLayers;
+    pdsch_pdu->transmissionScheme = 0;
+    pdsch_pdu->refPoint = 0; // Point A
+
+    // DMRS
+    pdsch_pdu->dlDmrsSymbPos =
+        fill_dmrs_mask(bwp->bwp_Dedicated->pdsch_Config->choice.setup,
+                       scc->dmrs_TypeA_Position,
+                       nrOfSymbols);
+    pdsch_pdu->dmrsConfigType = dmrsConfigType;
+    pdsch_pdu->dlDmrsScramblingId = *scc->physCellId;
+    pdsch_pdu->SCID = 0;
+    pdsch_pdu->numDmrsCdmGrpsNoData = sched_ctrl->numDmrsCdmGrpsNoData;
+    pdsch_pdu->dmrsPorts = 1;
+
+    // Pdsch Allocation in frequency domain
+    pdsch_pdu->resourceAlloc = 1;
+    pdsch_pdu->rbStart = sched_ctrl->rbStart;
+    pdsch_pdu->rbSize = sched_ctrl->rbSize;
+    pdsch_pdu->VRBtoPRBMapping = 1; // non-interleaved, check if this is ok for initialBWP
+
+    // Resource Allocation in time domain
+    pdsch_pdu->StartSymbolIndex = startSymbolIndex;
+    pdsch_pdu->NrOfSymbols = nrOfSymbols;
+
+    /* Check and validate PTRS values */
+    struct NR_SetupRelease_PTRS_DownlinkConfig *phaseTrackingRS =
+        bwp->bwp_Dedicated->pdsch_Config->choice.setup->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->phaseTrackingRS;
+    if (phaseTrackingRS) {
+      bool valid_ptrs_setup = set_dl_ptrs_values(phaseTrackingRS->choice.setup,
+                                                 pdsch_pdu->rbSize,
+                                                 pdsch_pdu->mcsIndex[0],
+                                                 pdsch_pdu->mcsTable[0],
+                                                 &pdsch_pdu->PTRSFreqDensity,
+                                                 &pdsch_pdu->PTRSTimeDensity,
+                                                 &pdsch_pdu->PTRSPortIndex,
+                                                 &pdsch_pdu->nEpreRatioOfPDSCHToPTRS,
+                                                 &pdsch_pdu->PTRSReOffset,
+                                                 pdsch_pdu->NrOfSymbols);
+      if (valid_ptrs_setup)
+        pdsch_pdu->pduBitmap |= 0x1; // Bit 0: pdschPtrs - Indicates PTRS included (FR2)
+    }
+
+    dci_pdu_rel15_t dci_pdu[MAX_DCI_CORESET];
+    memset(dci_pdu, 0, sizeof(dci_pdu_rel15_t) * MAX_DCI_CORESET);
+
+    // bwp indicator
+    const int n_dl_bwp = UE_info->secondaryCellGroup[UE_id]->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count;
+      AssertFatal(n_dl_bwp == 1,
+          "downlinkBWP_ToAddModList has %d BWP!\n",
+          n_dl_bwp);
+    // as per table 7.3.1.1.2-1 in 38.212
+    dci_pdu[0].bwp_indicator.val = n_dl_bwp < 4 ? bwp->bwp_Id : bwp->bwp_Id - 1;
+    AssertFatal(bwp->bwp_Dedicated->pdsch_Config->choice.setup->resourceAllocation == NR_PDSCH_Config__resourceAllocation_resourceAllocationType1,
+                "Only frequency resource allocation type 1 is currently supported\n");
+    dci_pdu[0].frequency_domain_assignment.val =
+        PRBalloc_to_locationandbandwidth0(
+            pdsch_pdu->rbSize,
+            pdsch_pdu->rbStart,
+            pdsch_pdu->BWPSize);
+    dci_pdu[0].time_domain_assignment.val = sched_ctrl->time_domain_allocation;
+    dci_pdu[0].mcs = sched_ctrl->mcs;
+    dci_pdu[0].rv = pdsch_pdu->rvIndex[0];
+    dci_pdu[0].harq_pid = current_harq_pid;
+    dci_pdu[0].ndi = harq->ndi;
+    dci_pdu[0].dai[0].val = (pucch->dai_c-1)&3;
+    dci_pdu[0].tpc = sched_ctrl->tpc1; // TPC for PUCCH: table 7.2.1-1 in 38.213
+    dci_pdu[0].pucch_resource_indicator = pucch->resource_indicator;
+    dci_pdu[0].pdsch_to_harq_feedback_timing_indicator.val = pucch->timing_indicator; // PDSCH to HARQ TI
+    dci_pdu[0].antenna_ports.val = 0;  // nb of cdm groups w/o data 1 and dmrs port 0
+    dci_pdu[0].dmrs_sequence_initialization.val = pdsch_pdu->SCID;
+    LOG_D(MAC,
+          "%4d.%2d DCI type 1 payload: freq_alloc %d (%d,%d,%d), "
+          "time_alloc %d, vrb to prb %d, mcs %d tb_scaling %d ndi %d rv %d\n",
+          frame,
+          slot,
+          dci_pdu[0].frequency_domain_assignment.val,
+          pdsch_pdu->rbStart,
+          pdsch_pdu->rbSize,
+          pdsch_pdu->BWPSize,
+          dci_pdu[0].time_domain_assignment.val,
+          dci_pdu[0].vrb_to_prb_mapping.val,
+          dci_pdu[0].mcs,
+          dci_pdu[0].tb_scaling,
+          dci_pdu[0].ndi,
+          dci_pdu[0].rv);
+
+    nr_configure_pdcch(gNB_mac,
+                       pdcch_pdu,
+                       rnti,
+                       sched_ctrl->search_space,
+                       sched_ctrl->coreset,
+                       scc,
+                       bwp,
+                       sched_ctrl->aggregation_level,
+                       sched_ctrl->cce_index);
+
+    const long f = sched_ctrl->search_space->searchSpaceType->choice.ue_Specific->dci_Formats;
+    /*const*/ int dci_format = f ? NR_DL_DCI_FORMAT_1_1 : NR_DL_DCI_FORMAT_1_0;
+    int rnti_types[2] = { NR_RNTI_C, 0 };
+
+    fill_dci_pdu_rel15(scc,
+                       UE_info->secondaryCellGroup[UE_id],
+                       pdcch_pdu,
+                       dci_pdu,
+                       &dci_format,
+                       rnti_types,
+                       pdsch_pdu->BWPSize,
+                       bwp->bwp_Id);
+
+    LOG_D(MAC,
+          "coreset params: FreqDomainResource %llx, start_symbol %d  n_symb %d\n",
+          (unsigned long long)pdcch_pdu->FreqDomainResource,
+          pdcch_pdu->StartSymbolIndex,
+          pdcch_pdu->DurationSymbols);
 
     NR_UE_ret_info_t *retInfo = &sched_ctrl->retInfo[current_harq_pid];
     if (harq->round != 0) { /* retransmission */
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
index 9fcb402a476..492a2092adf 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
@@ -502,213 +502,6 @@ void nr_configure_css_dci_initial(nfapi_nr_dl_tti_pdcch_pdu_rel15_t* pdcch_pdu,
 
 }
 
-void nr_fill_nfapi_dl_pdu(int Mod_idP,
-                          nfapi_nr_dl_tti_request_body_t *dl_req,
-                          rnti_t rnti,
-                          NR_CellGroupConfig_t *secondaryCellGroup,
-                          NR_UE_sched_ctrl_t *sched_ctrl,
-                          NR_sched_pucch_t *pucch_sched,
-                          nfapi_nr_dmrs_type_e dmrsConfigType,
-                          uint16_t R,
-                          uint8_t Qm,
-                          uint32_t TBS,
-                          int StartSymbolIndex,
-                          int NrOfSymbols,
-                          int harq_pid,
-                          int ndi,
-                          int round) {
-  gNB_MAC_INST                        *nr_mac  = RC.nrmac[Mod_idP];
-  NR_COMMON_channels_t                *cc      = nr_mac->common_channels;
-  NR_ServingCellConfigCommon_t        *scc     = cc->ServingCellConfigCommon;
-
-  const int bwp_id = sched_ctrl->active_bwp->bwp_Id;
-  const int nrOfLayers = 1;
-  const int mcs = sched_ctrl->mcs;
-  const int mcs_table_index = sched_ctrl->mcsTableIdx;
-  bool valid_ptrs_setup = false;
-
-  AssertFatal(secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
-	      "downlinkBWP_ToAddModList has %d BWP!\n",
-	      secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
-  NR_BWP_Downlink_t *bwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[bwp_id-1];
-
-  AssertFatal(bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList!=NULL,"searchPsacesToAddModList is null\n");
-  AssertFatal(bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList->list.count>0,
-              "searchPsacesToAddModList is empty\n");
-
-  nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdcch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs];
-  memset((void*)dl_tti_pdcch_pdu,0,sizeof(nfapi_nr_dl_tti_request_pdu_t));
-  dl_tti_pdcch_pdu->PDUType = NFAPI_NR_DL_TTI_PDCCH_PDU_TYPE;
-  dl_tti_pdcch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdcch_pdu));
-
-  nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdsch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs+1];
-  memset((void*)dl_tti_pdsch_pdu,0,sizeof(nfapi_nr_dl_tti_request_pdu_t));
-  dl_tti_pdsch_pdu->PDUType = NFAPI_NR_DL_TTI_PDSCH_PDU_TYPE;
-  dl_tti_pdsch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdsch_pdu));
-
-  nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_rel15 = &dl_tti_pdcch_pdu->pdcch_pdu.pdcch_pdu_rel15;
-  nfapi_nr_dl_tti_pdsch_pdu_rel15_t *pdsch_pdu_rel15 = &dl_tti_pdsch_pdu->pdsch_pdu.pdsch_pdu_rel15;
-
-
-  pdsch_pdu_rel15->pduBitmap = 0;
-  pdsch_pdu_rel15->rnti = rnti;
-  pdsch_pdu_rel15->pduIndex = nr_mac->pdu_index[0]++;
-
-  // BWP
-  pdsch_pdu_rel15->BWPSize  = NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth, MAX_BWP_SIZE);
-  pdsch_pdu_rel15->BWPStart = NRRIV2PRBOFFSET(bwp->bwp_Common->genericParameters.locationAndBandwidth, MAX_BWP_SIZE);
-  pdsch_pdu_rel15->SubcarrierSpacing = bwp->bwp_Common->genericParameters.subcarrierSpacing;
-  if (bwp->bwp_Common->genericParameters.cyclicPrefix)
-    pdsch_pdu_rel15->CyclicPrefix = *bwp->bwp_Common->genericParameters.cyclicPrefix;
-  else
-    pdsch_pdu_rel15->CyclicPrefix = 0;
-
-  pdsch_pdu_rel15->NrOfCodewords = 1;
-  pdsch_pdu_rel15->targetCodeRate[0] = nr_get_code_rate_dl(mcs, mcs_table_index);
-  pdsch_pdu_rel15->qamModOrder[0] = 2;
-  pdsch_pdu_rel15->mcsIndex[0] = mcs;
-  pdsch_pdu_rel15->mcsTable[0] = mcs_table_index;
-  pdsch_pdu_rel15->rvIndex[0] = nr_rv_round_map[round];
-  pdsch_pdu_rel15->dataScramblingId = *scc->physCellId;
-  pdsch_pdu_rel15->nrOfLayers = nrOfLayers;
-  pdsch_pdu_rel15->transmissionScheme = 0;
-  pdsch_pdu_rel15->refPoint = 0; // Point A
-  pdsch_pdu_rel15->dmrsConfigType = dmrsConfigType;
-  pdsch_pdu_rel15->dlDmrsScramblingId = *scc->physCellId;
-  pdsch_pdu_rel15->SCID = 0;
-  pdsch_pdu_rel15->numDmrsCdmGrpsNoData = sched_ctrl->numDmrsCdmGrpsNoData;
-  pdsch_pdu_rel15->dmrsPorts = 1;
-  pdsch_pdu_rel15->resourceAlloc = 1;
-  pdsch_pdu_rel15->rbStart = sched_ctrl->rbStart;
-  pdsch_pdu_rel15->rbSize = sched_ctrl->rbSize;
-  pdsch_pdu_rel15->VRBtoPRBMapping = 1; // non-interleaved, check if this is ok for initialBWP
-  pdsch_pdu_rel15->targetCodeRate[0] = R;
-  pdsch_pdu_rel15->qamModOrder[0] = Qm;
-  pdsch_pdu_rel15->TBSize[0] = TBS;
-  pdsch_pdu_rel15->mcsTable[0] = sched_ctrl->mcsTableIdx;
-  pdsch_pdu_rel15->StartSymbolIndex = StartSymbolIndex;
-  pdsch_pdu_rel15->NrOfSymbols      = NrOfSymbols;
-
-  pdsch_pdu_rel15->dlDmrsSymbPos =
-      fill_dmrs_mask(bwp->bwp_Dedicated->pdsch_Config->choice.setup,
-                     scc->dmrs_TypeA_Position,
-                     pdsch_pdu_rel15->NrOfSymbols);
-
-  /* Check and validate PTRS values */
-  if(bwp->bwp_Dedicated->pdsch_Config->choice.setup->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->phaseTrackingRS != NULL) {
-    valid_ptrs_setup = set_dl_ptrs_values(bwp->bwp_Dedicated->pdsch_Config->choice.setup->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->phaseTrackingRS->choice.setup,
-                                          pdsch_pdu_rel15->rbSize, pdsch_pdu_rel15->mcsIndex[0],
-                                          pdsch_pdu_rel15->mcsTable[0],
-                                          &pdsch_pdu_rel15->PTRSFreqDensity,&pdsch_pdu_rel15->PTRSTimeDensity,
-                                          &pdsch_pdu_rel15->PTRSPortIndex,&pdsch_pdu_rel15->nEpreRatioOfPDSCHToPTRS,
-                                          &pdsch_pdu_rel15->PTRSReOffset, pdsch_pdu_rel15->NrOfSymbols);
-    if(valid_ptrs_setup==true) {
-      pdsch_pdu_rel15->pduBitmap |=0x1;
-    }
-  }
-
-  dci_pdu_rel15_t dci_pdu_rel15[MAX_DCI_CORESET];
-  memset(dci_pdu_rel15, 0, sizeof(dci_pdu_rel15_t) * MAX_DCI_CORESET);
-
-  // bwp indicator
-  int n_dl_bwp = secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count;
-  if (n_dl_bwp < 4)
-    dci_pdu_rel15[0].bwp_indicator.val = bwp_id;
-  else
-    dci_pdu_rel15[0].bwp_indicator.val = bwp_id - 1; // as per table 7.3.1.1.2-1 in 38.212
-  // frequency domain assignment
-  if (bwp->bwp_Dedicated->pdsch_Config->choice.setup->resourceAllocation==NR_PDSCH_Config__resourceAllocation_resourceAllocationType1)
-    dci_pdu_rel15[0].frequency_domain_assignment.val =
-        PRBalloc_to_locationandbandwidth0(
-            pdsch_pdu_rel15->rbSize,
-            pdsch_pdu_rel15->rbStart,
-            NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth,
-                     MAX_BWP_SIZE));
-  else
-    AssertFatal(1==0,"Only frequency resource allocation type 1 is currently supported\n");
-  // time domain assignment: row index used instead of SLIV
-  dci_pdu_rel15[0].time_domain_assignment.val = sched_ctrl->time_domain_allocation;
-  // mcs and rv
-  dci_pdu_rel15[0].mcs = mcs;
-  dci_pdu_rel15[0].rv = pdsch_pdu_rel15->rvIndex[0];
-  // harq pid and ndi
-  dci_pdu_rel15[0].harq_pid = harq_pid;
-  dci_pdu_rel15[0].ndi = ndi;
-  // DAI
-  dci_pdu_rel15[0].dai[0].val = (pucch_sched->dai_c-1)&3;
-
-  // TPC for PUCCH
-  dci_pdu_rel15[0].tpc = sched_ctrl->tpc1; // table 7.2.1-1 in 38.213
-  // PUCCH resource indicator
-  dci_pdu_rel15[0].pucch_resource_indicator = pucch_sched->resource_indicator;
-  // PDSCH to HARQ TI
-  dci_pdu_rel15[0].pdsch_to_harq_feedback_timing_indicator.val = pucch_sched->timing_indicator;
-  // antenna ports
-  dci_pdu_rel15[0].antenna_ports.val = 0;  // nb of cdm groups w/o data 1 and dmrs port 0
-  // dmrs sequence initialization
-  dci_pdu_rel15[0].dmrs_sequence_initialization.val = pdsch_pdu_rel15->SCID;
-  LOG_D(MAC,
-        "[gNB scheduler phytest] DCI type 1 payload: freq_alloc %d (%d,%d,%d), "
-        "time_alloc %d, vrb to prb %d, mcs %d tb_scaling %d ndi %d rv %d\n",
-        dci_pdu_rel15[0].frequency_domain_assignment.val,
-        pdsch_pdu_rel15->rbStart,
-        pdsch_pdu_rel15->rbSize,
-        NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth, MAX_BWP_SIZE),
-        dci_pdu_rel15[0].time_domain_assignment.val,
-        dci_pdu_rel15[0].vrb_to_prb_mapping.val,
-        dci_pdu_rel15[0].mcs,
-        dci_pdu_rel15[0].tb_scaling,
-        dci_pdu_rel15[0].ndi,
-        dci_pdu_rel15[0].rv);
-
-  nr_configure_pdcch(nr_mac,
-                     pdcch_pdu_rel15,
-                     rnti,
-                     sched_ctrl->search_space,
-                     sched_ctrl->coreset,
-                     scc,
-                     bwp,
-                     sched_ctrl->aggregation_level,
-                     sched_ctrl->cce_index);
-
-  int dci_formats[2];
-  int rnti_types[2];
-
-  if (sched_ctrl->search_space->searchSpaceType->choice.ue_Specific->dci_Formats)
-    dci_formats[0]  = NR_DL_DCI_FORMAT_1_1;
-  else
-    dci_formats[0]  = NR_DL_DCI_FORMAT_1_0;
-
-  rnti_types[0]   = NR_RNTI_C;
-
-  fill_dci_pdu_rel15(scc,secondaryCellGroup,pdcch_pdu_rel15,dci_pdu_rel15,dci_formats,rnti_types,pdsch_pdu_rel15->BWPSize,bwp_id);
-
-  LOG_D(MAC,
-        "DCI params: rnti %x, rnti_type %d, dci_format %d\n",
-        pdcch_pdu_rel15->dci_pdu.RNTI[0],
-        rnti_types[0],
-        dci_formats[0]);
-  LOG_D(MAC,
-        "coreset params: FreqDomainResource %llx, start_symbol %d  n_symb %d\n",
-        (unsigned long long)pdcch_pdu_rel15->FreqDomainResource,
-        pdcch_pdu_rel15->StartSymbolIndex,
-        pdcch_pdu_rel15->DurationSymbols);
-
-  LOG_D(MAC,
-        "DLSCH PDU: start PRB %d n_PRB %d start symbol %d nb_symbols %d "
-        "nb_layers %d nb_codewords %d mcs %d TBS: %d\n",
-        pdsch_pdu_rel15->rbStart,
-        pdsch_pdu_rel15->rbSize,
-        pdsch_pdu_rel15->StartSymbolIndex,
-        pdsch_pdu_rel15->NrOfSymbols,
-        pdsch_pdu_rel15->nrOfLayers,
-        pdsch_pdu_rel15->NrOfCodewords,
-        pdsch_pdu_rel15->mcsIndex[0],
-        TBS);
-
-  dl_req->nPDUs += 2;
-}
-
 void config_uldci(NR_BWP_Uplink_t *ubwp,
                   nfapi_nr_pusch_pdu_t *pusch_pdu,
                   nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_rel15,
diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
index 9079f42f901..921c035af91 100644
--- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
+++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
@@ -170,22 +170,6 @@ void nr_schedule_css_dlsch_phytest(module_id_t   module_idP,
                                    frame_t       frameP,
                                    sub_frame_t   subframeP);
 
-void nr_fill_nfapi_dl_pdu(int Mod_id,
-                          nfapi_nr_dl_tti_request_body_t *dl_req,
-                          rnti_t rnti,
-                          NR_CellGroupConfig_t *secondaryCellGroup,
-                          NR_UE_sched_ctrl_t *sched_ctrl,
-                          NR_sched_pucch_t *pucch_sched,
-                          nfapi_nr_dmrs_type_e dmrsConfigType,
-                          uint16_t R,
-                          uint8_t Qm,
-                          uint32_t tbs,
-                          int StartSymbolIndex,
-                          int NrOfSymbols,
-                          int harq_pid,
-                          int ndi,
-                          int round);
-
 void handle_nr_uci_pucch_0_1(module_id_t mod_id,
                              frame_t frame,
                              sub_frame_t slot,
-- 
GitLab