remove/replaced PRIVATE and EXTERN keywords
[o-du/l2.git] / src / 5gnrmac / lwr_mac_handle_phy.c
index cfb8190..4efba24 100644 (file)
 
 /* header include files (.h) */
 #include "common_def.h"
-#include "tfu.h"           /* RGU Interface defines */
+#include "lrg.h"
 #ifdef INTEL_FAPI
 #include "fapi.h"
 #endif
 
 /* header/extern include files (.x) */
-#include "tfu.x"           /* RGU Interface includes */
-#include "du_log.h"
+#include "lrg.x"
+#include "du_app_mac_inf.h"
+#include "mac_sch_interface.h"
+#include "lwr_mac.h"
 #include "lwr_mac_fsm.h"
 #include "lwr_mac_phy.h"
 #include "lwr_mac_upr_inf.h"
-#include "rg.h"
+#include "mac.h"
+#include "mac_utils.h"
+#include "lwr_mac_utils.h"
 
 #ifdef INTEL_FAPI
 /* Function pointer for slot indication from lower mac to mac */
@@ -63,7 +67,7 @@ packRxDataIndMsg sendRxDataIndOpts[] =
    fapiMacRxDataInd,
    packRxDataInd
 };
+
 /* Function pointer for stop indication from lower mac to mac */ 
 packStopIndMsg sendStopIndOpts[] =
 {
@@ -71,35 +75,14 @@ packStopIndMsg sendStopIndOpts[] =
    fapiMacStopInd,
    packStopInd
 };
-/*******************************************************************
- *
- * @brief Fills post structure
- *
- * @details
- *
- *    Function : fillLwrMacToMacPst
- *
- *    Functionality:
- *     Fills post structure used to send message from lower MAC
- *     to MAC
- *
- * @params[in] Pst pointer 
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-void fillLwrMacToMacPst(Pst *pst)
+
+/* Function pointer for Uci indication from lower mac to mac */
+packMacUciIndMsg sendUciIndOpts[] =
 {
-   pst->srcProcId = 0;
-   pst->dstProcId = 0;
-   pst->srcEnt = ENTTF;
-   pst->dstEnt = ENTRG;
-   pst->srcInst = 0;
-   pst->dstInst = 0;
-   pst->region = 0;
-   pst->pool =  0; 
-   pst->selector = ODU_SELECTOR_TC;
-}
+   packMacUciInd,
+   FapiMacUciInd,
+   packMacUciInd
+};
 
 /*******************************************************************
  *
@@ -107,7 +90,7 @@ void fillLwrMacToMacPst(Pst *pst)
  *
  * @details
  *
- *    Function : handleSlotInd
+ *    Function : procSlotInd
  *
  *    Functionality:
  *     Processes Slot Indication from PHY and sends to MAC
@@ -117,16 +100,16 @@ void fillLwrMacToMacPst(Pst *pst)
  *         RFAILED - failure
  *
  * ****************************************************************/
-U16 handleSlotInd(fapi_slot_ind_t *fapiSlotInd)
+uint8_t procSlotInd(fapi_slot_ind_t *fapiSlotInd)
 {
    /* fill Pst structure to send to lwr_mac to MAC */
    Pst pst;
    uint16_t ret;
    SlotIndInfo slotInd;
 
-   fillLwrMacToMacPst(&pst);
-   pst.event = EVENT_SLOT_IND_TO_MAC;
+   FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_SLOT_IND_TO_MAC);
 
+   slotInd.cellId = lwrMacCb.cellCb[0].cellId; 
    slotInd.sfn = fapiSlotInd->sfn;
    slotInd.slot = fapiSlotInd->slot;
 
@@ -150,7 +133,7 @@ U16 handleSlotInd(fapi_slot_ind_t *fapiSlotInd)
  *
  * @details
  *
- *    Function : handleStopInd
+ *    Function : procStopInd
  *
  *    Functionality:
  *         Handles Stop Indication received from PHY
@@ -159,18 +142,19 @@ U16 handleSlotInd(fapi_slot_ind_t *fapiSlotInd)
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t handleStopInd()
+uint8_t procStopInd()
 {
    uint8_t ret;
    Pst pst;
 
-   clGlobalCp.phyState = PHY_STATE_CONFIGURED;
+   lwrMacCb.phyState = PHY_STATE_CONFIGURED;
+   lwrMacCb.cellCb[0].state = PHY_STATE_CONFIGURED;
    DU_LOG("\nLWR_MAC: PHY has moved to configured state");
 
-   fillLwrMacToMacPst(&pst);
-   pst.event = EVENT_STOP_IND_TO_MAC;
+   FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_STOP_IND_TO_MAC);
 
-   ret = (*sendStopIndOpts[pst.selector])(&pst);
+   ret = (*sendStopIndOpts[pst.selector])(&pst, \
+      lwrMacCb.cellCb[0].cellId);
    return ret;
 }
 /*******************************************************************
@@ -179,7 +163,7 @@ uint8_t handleStopInd()
  *
  * @details
  *
- *    Function : handleRachInd
+ *    Function : procRachInd
  *
  *    Functionality:
  *         Processes Rach Indication from PHY and sends to MAC
@@ -189,7 +173,7 @@ uint8_t handleStopInd()
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t handleRachInd(fapi_rach_indication_t  *fapiRachInd)
+uint8_t procRachInd(fapi_rach_indication_t  *fapiRachInd)
 {
    Pst          pst;
    uint8_t      pduIdx;
@@ -197,30 +181,30 @@ uint8_t handleRachInd(fapi_rach_indication_t  *fapiRachInd)
    RachPduInfo  *rachPdu;
    RachInd      rachInd;
 
+   rachInd.cellId = lwrMacCb.cellCb[0].cellId;
    rachInd.timingInfo.sfn = fapiRachInd->sfn;
    rachInd.timingInfo.slot = fapiRachInd->slot;
    rachInd.numPdu = fapiRachInd->numPdus;
    for(pduIdx=0; pduIdx < rachInd.numPdu; pduIdx++)
    {
       rachPdu = &rachInd.rachPdu[pduIdx];
-      rachPdu->pci = fapiRachInd->rachPdu[pduIdx].physCellId;
+      rachPdu->pci = fapiRachInd->rachPdu[pduIdx].phyCellId;
       rachPdu->symbolIdx = fapiRachInd->rachPdu[pduIdx].symbolIndex;
       rachPdu->slotIdx = fapiRachInd->rachPdu[pduIdx].slotIndex;
       rachPdu->freqIdx = fapiRachInd->rachPdu[pduIdx].freqIndex;
       rachPdu->numPream = fapiRachInd->rachPdu[pduIdx].numPreamble; 
       for(prmbleIdx=0; prmbleIdx<rachPdu->numPream; prmbleIdx++)
       {
-         rachPdu->preamInfo[prmbleIdx].preamIdx = \
-            fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].preambleIndex;
-         rachPdu->preamInfo[prmbleIdx].timingAdv = \
-            fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].timingAdvance;
+        rachPdu->preamInfo[prmbleIdx].preamIdx = \
+           fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].preambleIndex;
+        rachPdu->preamInfo[prmbleIdx].timingAdv = \
+           fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].timingAdvance;
       }
    }
-   fillLwrMacToMacPst(&pst);
-   pst.event = EVENT_RACH_IND_TO_MAC;
+   FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_RACH_IND_TO_MAC);
 
    (*sendRachIndOpts[pst.selector])(&pst, &rachInd);
-       return ROK;
+   return ROK;
 
 }/* handleRachInd */
 
@@ -230,7 +214,7 @@ uint8_t handleRachInd(fapi_rach_indication_t  *fapiRachInd)
  *
  * @details
  *
- *    Function : handleCrcInd
+ *    Function : procCrcInd
  *
  *    Functionality:
  *      Handles CRC indication from PHY and sends to MAC
@@ -241,7 +225,7 @@ uint8_t handleRachInd(fapi_rach_indication_t  *fapiRachInd)
  *
  * ****************************************************************/
 
-uint8_t handleCrcInd(fapi_crc_ind_t  *fapiCrcInd)
+uint8_t procCrcInd(fapi_crc_ind_t  *fapiCrcInd)
 {
    Pst          pst;
    uint8_t      crcInfoIdx;
@@ -249,6 +233,7 @@ uint8_t handleCrcInd(fapi_crc_ind_t  *fapiCrcInd)
    CrcInfo      *crcIndInfo;
    CrcInd       crcInd;
 
+   crcInd.cellId = lwrMacCb.cellCb[0].cellId;
    crcInd.timingInfo.sfn = fapiCrcInd->sfn;
    crcInd.timingInfo.slot = fapiCrcInd->slot;
    crcInd.numCrc = fapiCrcInd->numCrcs;
@@ -263,17 +248,16 @@ uint8_t handleCrcInd(fapi_crc_ind_t  *fapiCrcInd)
       crcIndInfo->numCb       = fapiCrcInd->crc[crcInfoIdx].numCb;
       for(crcStatusIdx = 0; crcStatusIdx < crcIndInfo->numCb; crcStatusIdx++)
       {
-         crcIndInfo->cbCrcStatus[crcStatusIdx] = \
-            fapiCrcInd->crc[crcInfoIdx].cbCrcStatus[crcStatusIdx];
+        crcIndInfo->cbCrcStatus[crcStatusIdx] = \
+           fapiCrcInd->crc[crcInfoIdx].cbCrcStatus[crcStatusIdx];
       }
       crcIndInfo->ul_cqi  = fapiCrcInd->crc[crcInfoIdx].ul_cqi;
       crcIndInfo->timingAdvance = fapiCrcInd->crc[crcInfoIdx].timingAdvance;
       crcIndInfo->rssi = fapiCrcInd->crc[crcInfoIdx].rssi;
    }
 
-   fillLwrMacToMacPst(&pst);
-   pst.event = EVENT_CRC_IND_TO_MAC;
-   
+   FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_CRC_IND_TO_MAC);
+
    (*sendCrcIndOpts[pst.selector])(&pst, &crcInd);
    return ROK;
 
@@ -285,7 +269,7 @@ uint8_t handleCrcInd(fapi_crc_ind_t  *fapiCrcInd)
  *
  * @details
  *
- *    Function : handleRxDataInd
+ *    Function : procRxDataInd
  *
  *    Functionality:
  *      Handles Rx Data indication from PHY and sends to MAC
@@ -295,14 +279,15 @@ uint8_t handleCrcInd(fapi_crc_ind_t  *fapiCrcInd)
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t handleRxDataInd(fapi_rx_data_indication_t  *fapiRxDataInd)
+
+uint8_t procRxDataInd(fapi_rx_data_indication_t  *fapiRxDataInd)
 {
    Pst           pst;
    uint8_t       pduIdx;
    RxDataInd     rxDataInd;
    RxDataIndPdu  *pdu;   
 
+   rxDataInd.cellId = lwrMacCb.cellCb[0].cellId;
    rxDataInd.timingInfo.sfn = fapiRxDataInd->sfn; 
    rxDataInd.timingInfo.slot = fapiRxDataInd->slot;
    rxDataInd.numPdus = fapiRxDataInd->numPdus;
@@ -313,7 +298,7 @@ uint8_t handleRxDataInd(fapi_rx_data_indication_t  *fapiRxDataInd)
       pdu->handle = fapiRxDataInd->pdus[pduIdx].handle;
       pdu->rnti = fapiRxDataInd->pdus[pduIdx].rnti;
       pdu->harqId = fapiRxDataInd->pdus[pduIdx].harqId;
-      pdu->pduLength = fapiRxDataInd->pdus[pduIdx].pduLength;
+      pdu->pduLength = fapiRxDataInd->pdus[pduIdx].pdu_length;
       pdu->ul_cqi = fapiRxDataInd->pdus[pduIdx].ul_cqi;
       pdu->timingAdvance = fapiRxDataInd->pdus[pduIdx].timingAdvance;
       pdu->rssi = fapiRxDataInd->pdus[pduIdx].rssi;
@@ -322,82 +307,199 @@ uint8_t handleRxDataInd(fapi_rx_data_indication_t  *fapiRxDataInd)
       memcpy(pdu->pduData, fapiRxDataInd->pdus[pduIdx].pduData, pdu->pduLength);
    }
 
-   fillLwrMacToMacPst(&pst);
-   pst.event = EVENT_RX_DATA_IND_TO_MAC;
+   FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_RX_DATA_IND_TO_MAC);
+
    (*sendRxDataIndOpts[pst.selector])(&pst, &rxDataInd);
    return ROK;
 }
 
+/*******************************************************************
+ *
+ * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
+ *
+ * @details
+ *
+ *    Function : fillUciIndPucchF0F1
+ *
+ *    Functionality:
+ *       Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
+ *
+ *@params[in] UciPucchF0F1 *
+ *            fapi_uci_o_pucch_f0f1_t *
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t fillUciIndPucchF0F1(UciPucchF0F1 *pduInfo, fapi_uci_o_pucch_f0f1_t *fapiPduInfo)
+{
+
+   uint8_t harqIdx;
+   uint8_t ret = ROK;
+   
+   pduInfo->handle        = fapiPduInfo->handle;
+   pduInfo->pduBitmap     = fapiPduInfo->pduBitmap;
+   pduInfo->pucchFormat   = fapiPduInfo->pucchFormat;
+   pduInfo->ul_cqi        = fapiPduInfo->ul_cqi;
+   pduInfo->crnti         = fapiPduInfo->rnti;
+   pduInfo->timingAdvance = fapiPduInfo->timingAdvance;
+   pduInfo->rssi          = fapiPduInfo->rssi;   
+   memcpy(pduInfo->uciBits, fapiPduInfo->uciBits, MAX_UCI_BIT_PER_TTI_IN_BYTES);
+   if(fapiPduInfo->srInfo.srIndication)
+   {
+      pduInfo->srInfo.srIndPres = fapiPduInfo->srInfo.srIndication;
+      pduInfo->srInfo.srConfdcLevel = fapiPduInfo->srInfo.srConfidenceLevel;
+
+   }
+   if(fapiPduInfo->harqInfo.numHarq)
+   {
+      pduInfo->harqInfo.numHarq = fapiPduInfo->harqInfo.numHarq;
+      pduInfo->harqInfo.harqConfdcLevel = fapiPduInfo->harqInfo.harqConfidenceLevel;
+      for(harqIdx = 0; harqIdx < pduInfo->harqInfo.numHarq; harqIdx++)
+      {
+         pduInfo->harqInfo.harqValue[harqIdx] = fapiPduInfo->harqInfo.harqValue[harqIdx];
+      }
+   }
+   return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Handles Uci indication from PHY and sends to MAC
+ *
+ * @details
+ *
+ *    Function : procUciInd
+ *
+ *    Functionality:
+ *      Handles Uci indication from PHY and sends to MAC
+ *
+ * @params[in] fapi_uci_indication_t message pointer
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t procUciInd(fapi_uci_indication_t  *fapiUciInd)
+{
+   uint8_t pduIdx;
+   uint8_t ret = ROK;
+   Pst     pst;
+   memset(&pst, 0, sizeof(Pst));
+   UciInd  macUciInd;
+   memset(&macUciInd, 0, sizeof(UciInd));
+
+   macUciInd.cellId = lwrMacCb.cellCb[0].cellId;
+   macUciInd.slotInd.sfn = fapiUciInd->sfn; 
+   macUciInd.slotInd.slot = fapiUciInd->slot;
+   macUciInd.numUcis = fapiUciInd->numUcis;
+
+   for(pduIdx = 0; pduIdx < macUciInd.numUcis; pduIdx++)
+   {
+      macUciInd.pdus[pduIdx].pduType = fapiUciInd->uciPdu[pduIdx].pduType;
+      switch(macUciInd.pdus[pduIdx].pduType)
+      {
+         case UCI_IND_PUSCH:
+         break;
+         case UCI_IND_PUCCH_F0F1:
+         {
+            UciPucchF0F1 *pduInfo = NULLP;
+            macUciInd.pdus[pduIdx].pduSize = fapiUciInd->uciPdu[pduIdx].pduSize;
+            pduInfo = &macUciInd.pdus[pduIdx].uci.uciPucchF0F1;
+            ret = fillUciIndPucchF0F1(pduInfo, &fapiUciInd->uciPdu[pduIdx].uci.uciPucchF0F1);
+         }
+         break;
+         case UCI_IND_PUCCH_F2F3F4:
+            break;
+         default:
+            DU_LOG("\nLWR_MAC: Invalid Pdu Type %d at procmacUciInd()", macUciInd.pdus[pduIdx].pduType);
+           ret = RFAILED;
+            break;
+      }
+   }
+   if(!ret)
+   {
+      FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_UCI_IND_TO_MAC);
+      ret = (*sendUciIndOpts[pst.selector])(&pst, &macUciInd);
+   }
+   else
+   {
+      DU_LOG("\nLWR_MAC: Failed sending UCI Ind to MAC");
+   }
+   return ret;
+}
 #endif /* FAPI */
 
-void handlePhyMessages(uint16_t msgType, uint32_t msgSize, void *msg)
+void procPhyMessages(uint16_t msgType, uint32_t msgSize, void *msg)
 {
 #ifdef INTEL_FAPI
    /* extract the header */
    fapi_msg_t *header;
    header = (fapi_msg_t *)msg;
 
-   switch(header->message_type_id)
+   switch(header->msg_id)
    {
       case FAPI_PARAM_RESPONSE:
       case FAPI_CONFIG_RESPONSE:
-      {
-         sendToLowerMac(msgType, msgSize, msg);
-         break;
-      }
+        {
+           sendToLowerMac(msgType, msgSize, msg);
+           break;
+        }
       case FAPI_SLOT_INDICATION:
-      {
-         if(clGlobalCp.phyState == PHY_STATE_CONFIGURED)
-         {
-            DU_LOG("\nLWR_MAC: PHY has moved to running state");
-            clGlobalCp.phyState = PHY_STATE_RUNNING;
-         }
-
-         fapi_slot_ind_t *slotInd;
-         slotInd  = (fapi_slot_ind_t *)msg;
-         handleSlotInd(slotInd);
-         break;
-      }
+        {
+           if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
+           {
+              DU_LOG("\nLWR_MAC: PHY has moved to running state");
+              lwrMacCb.phyState = PHY_STATE_RUNNING;
+              lwrMacCb.cellCb[0].state = PHY_STATE_RUNNING;
+           }
+
+           fapi_slot_ind_t *slotInd;
+           slotInd  = (fapi_slot_ind_t *)msg;
+           procSlotInd(slotInd);
+           break;
+        }
       case FAPI_ERROR_INDICATION:
-      {
-         break;
-      }
+        {
+           break;
+        }
       case FAPI_RX_DATA_INDICATION:
-      {
-         fapi_rx_data_indication_t *rxDataInd;
-         rxDataInd = (fapi_rx_data_indication_t *)msg;
-         handleRxDataInd(rxDataInd);
-         break;
-      }  
+        {
+           fapi_rx_data_indication_t *rxDataInd;
+           rxDataInd = (fapi_rx_data_indication_t *)msg;
+           procRxDataInd(rxDataInd);
+           break;
+        }  
       case FAPI_CRC_INDICATION:
-      {
-         fapi_crc_ind_t  *crcInd;
-         crcInd = (fapi_crc_ind_t *)msg;
-         handleCrcInd(crcInd);
-         break;
-      }  
+        {
+           fapi_crc_ind_t  *crcInd;
+           crcInd = (fapi_crc_ind_t *)msg;
+           procCrcInd(crcInd);
+           break;
+        }  
       case FAPI_UCI_INDICATION:
-      {
-         break;
-      }
+        {
+           fapi_uci_indication_t *phyUciInd = NULLP;
+           phyUciInd = (fapi_uci_indication_t*)msg;
+           procUciInd(phyUciInd);
+           break;
+        }
       case FAPI_SRS_INDICATION:
-      {
-         break;
-      }  
+        {
+           break;
+        }  
       case FAPI_RACH_INDICATION:
-      {
-         fapi_rach_indication_t  *rachInd;
-         rachInd = (fapi_rach_indication_t *)msg;
-         handleRachInd(rachInd);
-         break;
-      }
+        {
+           fapi_rach_indication_t  *rachInd;
+           rachInd = (fapi_rach_indication_t *)msg;
+           procRachInd(rachInd);
+           break;
+        }
       case FAPI_STOP_INDICATION:
-      {
-         DU_LOG("\nLWR_MAC: Handling Stop Indication");
-         handleStopInd();
-         break;
-      }  
+        {
+           DU_LOG("\nLWR_MAC: Handling Stop Indication");
+           procStopInd();
+           break;
+        }  
    }
 #ifdef INTEL_WLS
    WLS_MEM_FREE(msg, LWR_MAC_WLS_BUF_SIZE); 
@@ -406,5 +508,5 @@ void handlePhyMessages(uint16_t msgType, uint32_t msgSize, void *msg)
 }
 
 /**********************************************************************
-         End of file
-**********************************************************************/
+  End of file
+ **********************************************************************/