From 9106438239e0bc626ff1fa1d97d911caadd0fbb9 Mon Sep 17 00:00:00 2001
From: David Price <davpric2@cisco.com>
Date: Tue, 5 Dec 2017 14:27:45 +0000
Subject: [PATCH] monolithic still works.  Seem to have problem in nFAPI mode
 where it thinks it is decoding O_ACK to be 4 which is not valid

---
 openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c   |  6 ++++--
 openair1/SCHED/phy_procedures_lte_eNb.c       | 19 +++++++++++++------
 openair2/LAYER2/MAC/config.c                  |  3 +--
 openair2/LAYER2/MAC/eNB_scheduler.c           |  4 ++--
 openair2/LAYER2/MAC/eNB_scheduler_RA.c        |  1 -
 .../LAYER2/MAC/eNB_scheduler_primitives.c     |  8 +++++---
 .../CONF/rcc.band7.tm1.50PRB.nfapi.conf       |  2 +-
 targets/RT/USER/lte-enb.c                     |  7 +++----
 targets/RT/USER/lte-ru.c                      |  7 -------
 targets/RT/USER/lte-softmodem.c               | 12 +++++-------
 10 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
index 9ccc610a892..edbca69433e 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
@@ -874,12 +874,13 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   int16_t cseq[6*14*1200] __attribute__((aligned(32)));
   int off;
 
+  int frame = proc->frame_rx;
   int subframe = proc->subframe_rx;
   LTE_UL_eNB_HARQ_t *ulsch_harq;
 
 
 
-  harq_pid = subframe2harq_pid(frame_parms,proc->frame_rx,subframe);
+  harq_pid = subframe2harq_pid(frame_parms,frame,subframe);
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_ULSCH_DECODING0+harq_pid,1);
 
@@ -1264,7 +1265,7 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   }
 
   if (ulsch_harq->O_ACK > 2) {
-    LOG_E(PHY,"ulsch_decoding: FATAL, ACK cannot be more than 2 bits yet\n");
+    LOG_E(PHY,"ulsch_decoding: FATAL, ACK cannot be more than 2 bits yet O_ACK:%d SFN/SF:%04d%d UE_id:%d rnti:%x\n",ulsch_harq->O_ACK,proc->frame_rx,proc->subframe_rx,UE_id,ulsch->rnti);
     return(-1);
   }
 
@@ -1576,6 +1577,7 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
 #endif
   }
 
+  LOG_I(PHY,"frame %d subframe %d O_ACK:%d o_ACK[]=%d:%d:%d:%d\n",frame,subframe,ulsch_harq->O_ACK,ulsch_harq->o_ACK[0],ulsch_harq->o_ACK[1],ulsch_harq->o_ACK[2],ulsch_harq->o_ACK[3]);
 
   // Do ULSCH Decoding for data portion
 
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index f727f2172a2..5c0b8cd7fdf 100644
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -338,8 +338,14 @@ void pdsch_procedures(PHY_VARS_eNB *eNB,
       dlsch_harq->pdu,dlsch_harq->pdsch_start,frame,subframe,dlsch_harq->nb_rb,dlsch_harq->rb_alloc[0],dlsch_harq->Qm,dlsch_harq->Nl,dlsch_harq->round);
   // 36-212 
   if (nfapi_mode == 0 || nfapi_mode == 1) { // monolthic OR PNF - do not need turbo encoding on VNF
+
+    if (dlsch_harq->pdu==NULL){
+        LOG_E(PHY,"dlsch_harq->pdu == NULL SFN/SF:%04d%d dlsch[rnti:%x] dlsch_harq[pdu:%p pdsch_start:%d Qm:%d Nl:%d round:%d nb_rb:%d rb_alloc[0]:%d]\n", frame,subframe,dlsch->rnti, dlsch_harq->pdu,dlsch_harq->pdsch_start,dlsch_harq->Qm,dlsch_harq->Nl,dlsch_harq->round,dlsch_harq->nb_rb,dlsch_harq->rb_alloc[0]);
+      return;
+    }
+
     start_meas(&eNB->dlsch_encoding_stats);
-    AssertFatal(dlsch_harq->pdu!=NULL,"dlsch_harq->pdu == NULL (rnti %x)\n",dlsch->rnti);
+
     eNB->te(eNB,
         dlsch_harq->pdu,
         dlsch_harq->pdsch_start,
@@ -721,8 +727,8 @@ void prach_procedures(PHY_VARS_eNB *eNB,
 	    eNB->preamble_list[0].preamble_rel13.rach_resource_type   = 0;
 	    eNB->preamble_list[0].instance_length                     = 0; //don't know exactly what this is
 	    
-            if (nfapi_mode == 1)    // If NFAPI PNF then we need to send the message to the VNF
-            {
+            if (nfapi_mode == 1) {  // If NFAPI PNF then we need to send the message to the VNF
+
               LOG_E(PHY,"Filling NFAPI indication for RACH : SFN_SF:%d TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
                   NFAPI_SFNSF2DEC(eNB->UL_INFO.rach_ind.sfn_sf),
                   eNB->preamble_list[0].preamble_rel8.timing_advance,
@@ -1763,7 +1769,7 @@ void fill_ulsch_harq_indication(PHY_VARS_eNB *eNB,LTE_UL_eNB_HARQ_t *ulsch_harq,
     return;
   }
 
-  LOG_D(PHY,"%s(eNB, ulsch_harq, rnti:%04x, frame:%d, subframe:%d, bundling:%d) harq_pdus:%d\n", __FUNCTION__, rnti, frame, subframe, bundling,eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs);
+  LOG_I(PHY,"%s(eNB, ulsch_harq, rnti:%04x, frame:%d, subframe:%d, bundling:%d) harq_pdus:%d O_ACK:%d\n", __FUNCTION__, rnti, frame, subframe, bundling,eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs,ulsch_harq->O_ACK);
 
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
   nfapi_harq_indication_pdu_t *pdu =   &eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs];
@@ -1773,6 +1779,8 @@ void fill_ulsch_harq_indication(PHY_VARS_eNB *eNB,LTE_UL_eNB_HARQ_t *ulsch_harq,
   eNB->UL_INFO.harq_ind.header.message_id = NFAPI_HARQ_INDICATION;
   eNB->UL_INFO.harq_ind.sfn_sf = frame<<4|subframe;
 
+  eNB->UL_INFO.harq_ind.harq_indication_body.tl.tag = NFAPI_HARQ_INDICATION_BODY_TAG;
+
   pdu->instance_length                                = 0; // don't know what to do with this
   //  pdu->rx_ue_information.handle                       = handle;
   pdu->rx_ue_information.tl.tag                       = NFAPI_RX_UE_INFORMATION_TAG;
@@ -2073,8 +2081,7 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
 
   uci_procedures(eNB,proc);
 
-  if (nfapi_mode == 0 || nfapi_mode == 1) // If PNF or monolithic
-  {
+  if (nfapi_mode == 0 || nfapi_mode == 1) { // If PNF or monolithic
     pusch_procedures(eNB,proc);
   }
 
diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c
index 251db013612..1aa3a856368 100644
--- a/openair2/LAYER2/MAC/config.c
+++ b/openair2/LAYER2/MAC/config.c
@@ -1003,8 +1003,7 @@ rrc_mac_config_req_eNB(module_id_t Mod_idP,
     if (
         (nfapi_mode == 1 || nfapi_mode == 2) &&
         (RC.mac[Mod_idP]->if_inst->PHY_config_req == NULL)
-       )
-    {
+       ) {
       while(RC.mac[Mod_idP]->if_inst->PHY_config_req == NULL) {
         // DJP AssertFatal(RC.mac[Mod_idP]->if_inst->PHY_config_req != NULL,"if_inst->phy_config_request is null\n");
         usleep(100 * 1000);
diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index 8ae23ed4c39..4d95cf6c627 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -571,8 +571,8 @@ clear_nfapi_information(eNB_MAC_INST * eNB, int CC_idP,
 
     eNB->pdu_index[CC_idP] = 0;
 
-    if (nfapi_mode==0 || nfapi_mode == 1)   // monolithic or PNF
-    {
+    if (nfapi_mode==0 || nfapi_mode == 1) { // monolithic or PNF
+
       DL_req[CC_idP].dl_config_request_body.number_pdcch_ofdm_symbols           = 1;
       DL_req[CC_idP].dl_config_request_body.number_dci                          = 0;
       DL_req[CC_idP].dl_config_request_body.number_pdu                          = 0;
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index 28f5662b60e..14cdb4b5f34 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -66,7 +66,6 @@
 #include "T.h"
 
 extern uint8_t nfapi_mode;
-extern uint8_t sf_ahead;
 extern int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req);
 
 void add_subframe(uint16_t *frameP, uint16_t *subframeP, int offset)
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
index 7e9db10c305..7bba9145fc9 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
@@ -3674,6 +3674,8 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id,
 
 	uint8_t harq_pid = ((10 * frameP) + subframeP + 10236) & 7;
 
+        LOG_I(MAC,"frame %d subframe %d harq_pid %d mode %d tmode[0] %d num_ack_nak %d round %d\n",frameP,subframeP,harq_pid,harq_indication_fdd->mode,tmode[0],num_ack_nak,sched_ctl->round[CC_idP][harq_pid]);
+
 	switch (harq_indication_fdd->mode) {
 	case 0:		// Format 1a/b (10.1.2.1)
 	    AssertFatal(numCC == 1,
@@ -3682,8 +3684,8 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id,
 	    if (tmode[0] == 1 || tmode[0] == 2 || tmode[0] == 5 || tmode[0] == 6 || tmode[0] == 7) {	// NOTE: have to handle the case of TM9-10 with 1 antenna port
 		// single ACK/NAK bit
 		AssertFatal(num_ack_nak == 1,
-			    "num_ack_nak %d > 1 for 1 CC and single-layer transmission\n",
-			    num_ack_nak);
+			    "num_ack_nak %d > 1 for 1 CC and single-layer transmission frame:%d subframe:%d\n",
+			    num_ack_nak,frameP,subframeP);
 		AssertFatal(sched_ctl->round[CC_idP][harq_pid] < 8,
 			    "Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n",
 			    harq_pid, UE_id, rnti);
@@ -4474,7 +4476,7 @@ harq_indication(module_id_t mod_idP, int CC_idP, frame_t frameP,
     UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
     COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP];
     // extract HARQ Information
-    LOG_D(MAC,
+    LOG_I(MAC,
 	  "Frame %d, subframe %d: Received harq indication (%d) from UE %d/%x, ul_cqi %d\n",
 	  frameP, subframeP, channel, UE_id, rnti, ul_cqi);
     if (cc->tdd_Config)
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi.conf
index 8b2410f3d95..88aacde36bd 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi.conf
@@ -75,7 +75,7 @@ eNBs =
 
       pusch_p0_Nominal                                   = -86;
       pusch_alpha                                        = "AL1";
-      pucch_p0_Nominal                                   = -104;
+      pucch_p0_Nominal                                   = -96;
       msg3_delta_Preamble                                = 6;
       pucch_deltaF_Format1                               = "deltaF2";
       pucch_deltaF_Format1b                              = "deltaF3";
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index fa26ee0a6ba..d50cbbb8545 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -174,8 +174,8 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
 
   // *******************************************************************
 
-  if (nfapi_mode == 1)
-  {
+  if (nfapi_mode == 1) {
+
     // I am a PNF and I need to let nFAPI know that we have a (sub)frame tick
     uint16_t frame = proc->frame_rx;
     uint16_t subframe = proc->subframe_rx;
@@ -205,8 +205,7 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
     }
   }
 
-  if (nfapi_mode == 1 && eNB->pdcch_vars[proc->subframe_tx&1].num_pdcch_symbols == 0)
-  {
+  if (nfapi_mode == 1 && eNB->pdcch_vars[proc->subframe_tx&1].num_pdcch_symbols == 0) {
     LOG_E(PHY, "eNB->pdcch_vars[proc->subframe_tx&1].num_pdcch_symbols == 0");
     return 0;
   }
diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index df05630de44..66cd5daffad 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -129,7 +129,6 @@ int attach_rru(RU_t *ru);
 
 int connect_rau(RU_t *ru);
 
-extern uint8_t nfapi_mode;
 extern uint16_t sf_ahead;
 
 /*************************************************************/
@@ -1491,12 +1490,6 @@ static void* ru_thread( void* param ) {
         RC.eNB[0][0]->proc.frame_rx,RC.eNB[0][0]->proc.subframe_rx,
         RC.eNB[0][0]->proc.frame_tx);
 
-    if (nfapi_mode == 1) // PNF
-    {
-      // This is the earliest I think we can do this
-      //wakeup_nfapi_subframe_thread();
-    }
-
     if (0 && is_prach_subframe(fp, proc->frame_rx, proc->subframe_rx))
       LOG_D(PHY,"RU thread (do_prach %d, is_prach_subframe %d), received frame %d, subframe %d\n",
           ru->do_prach,
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 3f4f43cc8b5..c786a62e2e6 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -116,7 +116,7 @@ pthread_cond_t nfapi_sync_cond;
 pthread_mutex_t nfapi_sync_mutex;
 int nfapi_sync_var=-1; //!< protected by mutex \ref nfapi_sync_mutex
 
-uint8_t nfapi_mode = 0;
+uint8_t nfapi_mode = 0; // Default to monolithic mode
 
 pthread_cond_t sync_cond;
 pthread_mutex_t sync_mutex;
@@ -1256,8 +1256,8 @@ int main( int argc, char **argv )
   
   rt_sleep_ns(10*100000000ULL);
   
-  if (nfapi_mode)
-  {
+  if (nfapi_mode) {
+
     printf("NFAPI*** - mutex and cond created - will block shortly for completion of PNF connection\n");
     pthread_cond_init(&sync_cond,NULL);
     pthread_mutex_init(&sync_mutex, NULL);
@@ -1265,8 +1265,7 @@ int main( int argc, char **argv )
   
   const char *nfapi_mode_str = "<UNKNOWN>";
 
-  switch(nfapi_mode)
-  {
+  switch(nfapi_mode) {
     case 0:
       nfapi_mode_str = "MONOLITHIC";
       break;
@@ -1329,8 +1328,7 @@ int main( int argc, char **argv )
 
     config_sync_var=0;
 
-    if (nfapi_mode==1) // PNF
-    {
+    if (nfapi_mode==1) { // PNF
       wait_nfapi_init("main?");
     }
 
-- 
GitLab