From b9fc5e679f241159000bd37a2c1fdb0955b0f1a3 Mon Sep 17 00:00:00 2001
From: David Price <davpric2@cisco.com>
Date: Fri, 20 Oct 2017 09:18:24 +0100
Subject: [PATCH] Small update mostly tweaking.  Still RACHs

---
 nfapi/nfapi_pnf.c                  | 12 ++----
 openair2/PHY_INTERFACE/IF_Module.c |  9 ++---
 targets/RT/USER/lte-enb.c          | 22 ++++++----
 targets/RT/USER/lte-ru.c           | 64 +++++++++++++++++++++++++++++-
 4 files changed, 85 insertions(+), 22 deletions(-)

diff --git a/nfapi/nfapi_pnf.c b/nfapi/nfapi_pnf.c
index 92ab7a4cb52..ca90bf87113 100644
--- a/nfapi/nfapi_pnf.c
+++ b/nfapi/nfapi_pnf.c
@@ -1807,20 +1807,14 @@ void configure_nfapi_pnf(char *vnf_ip_addr, int vnf_p5_port, char *pnf_ip_addr,
   pthread_create(&pnf_start_pthread, NULL, &pnf_start_thread, config);
 }
 
-void oai_subframe_ind(eNB_rxtx_proc_t *proc)
+void oai_subframe_ind(uint16_t sfn, uint16_t sf)
 {
-  //LOG_D(PHY,"%s(frame:%d, subframe:%d)\n", __FUNCTION__, proc->frame_tx, proc->subframe_tx);
+  //LOG_D(PHY,"%s(sfn:%d, sf:%d)\n", __FUNCTION__, sfn, sf);
 
   //TODO FIXME - HACK - DJP - using a global to bodge it in 
 
   if (p7_config_g != NULL && sync_var==0)
   {
-    //PHY_VARS_eNB *eNB = RC.eNB[0][0];
-    //int even_frame_thread = eNB->proc.proc_rxtx[0] == proc ? 0 : 1;
-
-    int pnf = nfapi_mode==1 ? 1 : 0;
-    uint16_t sfn = pnf ? proc->frame_tx : proc->frame_rx;
-    uint16_t sf = pnf ? proc->subframe_tx : proc->frame_rx;
     uint16_t sfn_sf_tx = sfn<<4 | sf;
 
     if ((sfn % 100 == 0) && sf==0)
@@ -1829,7 +1823,7 @@ void oai_subframe_ind(eNB_rxtx_proc_t *proc)
 
       clock_gettime(CLOCK_MONOTONIC, &ts);
 
-      NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] %s %d.%d (frame:%u subframe:%u) SFN/SF(TX):%u\n", __FUNCTION__, ts.tv_sec, ts.tv_nsec, sfn, sf, NFAPI_SFNSF2DEC(sfn_sf_tx));
+      NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] %s %d.%d (sfn:%u sf:%u) SFN/SF(TX):%u\n", __FUNCTION__, ts.tv_sec, ts.tv_nsec, sfn, sf, NFAPI_SFNSF2DEC(sfn_sf_tx));
     }
 
     int subframe_ret = nfapi_pnf_p7_subframe_ind(p7_config_g, p7_config_g->phy_id, sfn_sf_tx);
diff --git a/openair2/PHY_INTERFACE/IF_Module.c b/openair2/PHY_INTERFACE/IF_Module.c
index 5e817975d65..3c97865fbb3 100644
--- a/openair2/PHY_INTERFACE/IF_Module.c
+++ b/openair2/PHY_INTERFACE/IF_Module.c
@@ -513,9 +513,10 @@ void UL_indication(UL_IND_t *UL_info)
   IF_Module_t  *ifi        = if_inst[module_id];
   eNB_MAC_INST *mac        = RC.mac[module_id];
 
-  LOG_D(PHY,"UL_Indication: frame %d, subframe %d, module_id %d, CC_id %d\n",
-	UL_info->frame,UL_info->subframe,
-	module_id,CC_id);
+  LOG_D(PHY,"frame %d, subframe %d, module_id %d, CC_id %d UL_info[rx_ind:%d number_of_harqs:%d number_of_crcs:%d number_of_cqis:%d number_of_preambles:%d]\n", 
+      UL_info->frame,UL_info->subframe,
+      module_id,CC_id,
+      UL_info->rx_ind.rx_indication_body.number_of_pdus, UL_info->harq_ind.harq_indication_body.number_of_harqs, UL_info->crc_ind.crc_indication_body.number_of_crcs, UL_info->cqi_ind.number_of_cqis, UL_info->rach_ind.number_of_preambles);
 
   if (nfapi_mode != 1)
   {
@@ -535,8 +536,6 @@ void UL_indication(UL_IND_t *UL_info)
   clear_nfapi_information(RC.mac[module_id],CC_id,
 			  UL_info->frame,UL_info->subframe);
 
-  LOG_D(PHY, "UL_info[rx_ind:%d number_of_harqs:%d number_of_crcs:%d number_of_cqis:%d number_of_preambles:%d]\n", UL_info->rx_ind.rx_indication_body.number_of_pdus, UL_info->harq_ind.harq_indication_body.number_of_harqs, UL_info->crc_ind.crc_indication_body.number_of_crcs, UL_info->cqi_ind.number_of_cqis, UL_info->rach_ind.number_of_preambles);
-
   handle_rach(UL_info);
 
   handle_sr(UL_info);
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index 50963015714..cb0c727ab66 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -151,8 +151,9 @@ void wakeup_prach_eNB(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe);
 void wakeup_prach_eNB_br(PHY_VARS_eNB *eNB,RU_t *ru,int frame,int subframe);
 #endif
 
-extern void oai_subframe_ind(eNB_rxtx_proc_t *proc);
 extern uint8_t nfapi_mode;
+extern void oai_subframe_ind(uint16_t sfn, uint16_t sf);
+extern void add_subframe(uint16_t *frameP, uint16_t *subframeP, int offset);
 
 static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_name) {
 
@@ -176,7 +177,7 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
 #endif
   }
 
-  LOG_D(PHY, "SFN/SF proc:%d/%d rx_ind:%d/%d [num_pdus:%d]\n", NFAPI_SFNSF2SFN(eNB->UL_INFO.rx_ind.sfn_sf), NFAPI_SFNSF2SF(eNB->UL_INFO.rx_ind.sfn_sf), proc->frame_rx, proc->subframe_rx, eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus);
+  LOG_D(PHY, "RX_IND:SFN/SF:%d/%d proc:SFN/SF:%d/%d [rx_ind:num_pdus:%d]\n", NFAPI_SFNSF2DEC(eNB->UL_INFO.rx_ind.sfn_sf), proc->frame_rx, proc->subframe_rx, eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus);
 
   if (eNB->UL_INFO.rx_ind.sfn_sf == (proc->frame_rx<<4|proc->subframe_rx) && eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus>0)
   {
@@ -199,10 +200,18 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
     }
   }
 
-  if (nfapi_mode)
+  if (nfapi_mode == 1)
   {
-    oai_subframe_ind(proc); // PNF ---> P7:subframe_ind --> VNF 
-    //LOG_E(PHY, "Returned from oai_subframe_ind()\n");
+    // 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;
+
+    add_subframe(&frame, &subframe, 4);
+
+    //oai_subframe_ind(proc->frame_tx, proc->subframe_tx);
+    //LOG_D(PHY, "oai_subframe_ind(frame:%u, subframe:%d) - NOT CALLED ********\n", frame, subframe);
+    oai_subframe_ind(frame, subframe);
+
     LOG_D(PHY, "UL_info[rx_ind:%d number_of_harqs:%d number_of_crcs:%d number_of_cqis:%d number_of_preambles:%d]\n", eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus, eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs, eNB->UL_INFO.cqi_ind.number_of_cqis, eNB->UL_INFO.rach_ind.number_of_preambles);
   }
 
@@ -339,8 +348,7 @@ void eNB_top(PHY_VARS_eNB *eNB, int frame_rx, int subframe_rx, char *string)
     proc_rxtx->timestamp_tx = proc->timestamp_tx;
 
     if (rxtx(eNB,proc_rxtx,string) < 0) LOG_E(PHY,"eNB %d CC_id %d failed during execution\n",eNB->Mod_id,eNB->CC_id);
-    LOG_D(PHY,"eNB_top out %p (proc %p, CC_id %d), frame %d, subframe %d, instance_cnt_prach %d\n",
-	  (void*)pthread_self(), proc, eNB->CC_id, proc->frame_rx,proc->subframe_rx,proc->instance_cnt_prach);
+    //LOG_D(PHY,"eNB_top out %p (proc %p, CC_id %d), frame %d, subframe %d, instance_cnt_prach %d\n", (void*)pthread_self(), proc, eNB->CC_id, proc->frame_rx,proc->subframe_rx,proc->instance_cnt_prach);
   }
 }
 
diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index 2f88686c936..a091abcb37a 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -129,6 +129,8 @@ int attach_rru(RU_t *ru);
 
 int connect_rau(RU_t *ru);
 
+extern uint8_t nfapi_mode;
+extern void oai_subframe_ind(uint16_t frame, uint16_t subframe);
 
 /*************************************************************/
 /* Functions to attach and configure RRU                     */
@@ -1271,6 +1273,40 @@ static inline int wakeup_prach_ru_br(RU_t *ru) {
 }
 #endif
 
+#if 0
+static inline int wakeup_nfapi_subframe_thread(RU_t *ru) {
+
+  int i;
+  PHY_VARS_eNB **eNB_list = ru->eNB_list;
+
+  LOG_D(PHY,"wakeup_nfapi_subframe_thread (num %d) for RU %d ru->eNB_top:%p\n",ru->num_eNB,ru->idx, ru->eNB_top);
+
+  if (ru->num_eNB==1 && ru->eNB_top!=0) {
+    // call eNB function directly
+
+    char string[20];
+    sprintf(string,"Incoming RU %d",ru->idx);
+    //LOG_D(PHY,"RU %d Call eNB_top\n",ru->idx);
+    ru->eNB_top(eNB_list[0],ru->proc.frame_rx,ru->proc.subframe_rx,string);
+  }
+  else {
+
+    LOG_D(PHY,"ru->num_eNB:%d\n", ru->num_eNB);
+
+    for (i=0;i<ru->num_eNB;i++)
+    {
+      LOG_D(PHY,"ru->wakeup_rxtx:%p\n", ru->wakeup_rxtx);
+
+      if (ru->wakeup_rxtx!=0 && ru->wakeup_rxtx(eNB_list[i],ru) < 0)
+      {
+	LOG_E(PHY,"could not wakeup eNB rxtx process for subframe %d\n", ru->proc.subframe_rx);
+      }
+    }
+  }
+}
+#endif
+
+
 // this is for RU with local RF unit
 void fill_rf_config(RU_t *ru, char *rf_config_file) {
 
@@ -1517,7 +1553,7 @@ static void* ru_thread( void* param ) {
     if (ru->fh_south_in) ru->fh_south_in(ru,&frame,&subframe);
     else AssertFatal(1==0, "No fronthaul interface at south port");
 
-    LOG_D(PHY,"AFTER fh_south_in - SFN/SF:%d/%d RX:%d/%d TX:%d/%d RC.eNB[0][0]:[RX:%d/%d TX(SFN):%d] eNB:%p RU:eNB:%p proc:%p ru->proc:%p\n",
+    LOG_D(PHY,"AFTER fh_south_in - SFN/SF:%d/%d RU->proc[RX:%d/%d TX:%d/%d] RC.eNB[0][0]:[RX:%d/%d TX(SFN):%d] eNB:%p RU:eNB:%p proc:%p ru->proc:%p\n",
         frame,subframe,
         proc->frame_rx,proc->subframe_rx,
         proc->frame_tx,proc->subframe_tx,
@@ -1526,6 +1562,32 @@ static void* ru_thread( void* param ) {
         RC.eNB[0][0], ru->eNB_list[0],
         proc,&ru->proc);
 
+#if 0
+    // This needs to be here, because we need to be as close to the interrupt as possible, any later and you get jitter
+    // However, putting it here causes the PNF to go horribly wrong and get bad harq_pid!
+    //
+    if (nfapi_mode == 1)  // PNF
+    {
+      struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
+
+      //oai_subframe_ind(proc->frame_tx, proc->subframe_tx);
+      //LOG_D(PHY, "oai_subframe_ind(frame:%u, subframe:%d) NOT CALLED **************************************\n", frame, subframe);
+
+      //uint16_t frame = proc->frame_tx;
+      //uint16_t subframe = proc->subframe_tx;
+
+      //add_subframe(&frame, &subframe, 4);
+
+      //oai_subframe_ind(frame, subframe);
+      //LOG_D(PHY, "oai_subframe_ind(frame:%u, subframe:%d) UL_info[rx_ind:%d number_of_harqs:%d number_of_crcs:%d number_of_cqis:%d number_of_preambles:%d]\n", frame, subframe, eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus, eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs, eNB->UL_INFO.cqi_ind.number_of_cqis, eNB->UL_INFO.rach_ind.number_of_preambles);
+    }
+#endif
+    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,
-- 
GitLab