Merge "[Epic-ID: ODUHIGH-556][Task-ID: ODUHIGH-570] UL Candidate Sel and Res Alloc...
[o-du/l2.git] / src / 5gnrsch / sch_fcfs.c
index 26cc887..93ec5c1 100644 (file)
@@ -41,6 +41,7 @@ File:     sch_fcfs.c
 #include "du_app_mac_inf.h"
 #include "mac_sch_interface.h"
 #include "sch.h"
+#include "sch_tmr.h"
 #include "sch_utils.h"
 #include "sch_fcfs.h"
 #ifdef NR_DRX 
@@ -748,7 +749,7 @@ void schFcfsRemoveUeFrmScheduleLst(SchCellCb *cell, CmLList *node)
  *
  * @details
  *
- *    Function :  schCalculateUlTbs
+ *    Function :  schFcfsCalculateUlTbs
  *
  *    Functionality: Function will note the required TBS for each LCGIDX and use
  *    the Priority LCG List and RRM policy to allocate the TBS size
@@ -766,7 +767,7 @@ void schFcfsRemoveUeFrmScheduleLst(SchCellCb *cell, CmLList *node)
  *                   RFAILED > vice versa
  *
  * ****************************************************************/
-uint8_t schCalculateUlTbs(SchUeCb *ueCb, SlotTimingInfo puschTime, uint8_t symbLen,\
+uint8_t schFcfsCalculateUlTbs(SchUeCb *ueCb, SlotTimingInfo puschTime, uint8_t symbLen,\
                           uint16_t *startPrb, uint32_t *totTBS, bool isRetx, SchUlHqProcCb *hqP, SchFcfsHqProcCb *fcfsHqP)
 {
    uint16_t mcsIdx = 0;
@@ -905,14 +906,14 @@ uint8_t schFcfsScheduleUlLc(SlotTimingInfo dciTime, SlotTimingInfo puschTime, ui
    uint8_t ret = RFAILED;
    uint16_t startPrb = 0;
    uint32_t totDataReq = 0; /* in bytes */
-   SchUeCb *ueCb;
-   SchPuschInfo *puschInfo;
+   SchUeCb *ueCb = NULLP;
+   SchPuschInfo *puschInfo = NULLP;
    DciInfo  *dciInfo = NULLP;
 
    cell = (*hqP)->hqEnt->cell;
    ueCb = (*hqP)->hqEnt->ue;
    fcfsHqProcCb = (SchFcfsHqProcCb *)(*hqP)->schSpcUlHqProcCb;
-   ret = schCalculateUlTbs(ueCb, puschTime, symbLen, &startPrb, &totDataReq, isRetx, *hqP, fcfsHqProcCb);
+   ret = schFcfsCalculateUlTbs(ueCb, puschTime, symbLen, &startPrb, &totDataReq, isRetx, *hqP, fcfsHqProcCb);
 
    if(totDataReq > 0 && ret == ROK)
    {
@@ -935,17 +936,15 @@ uint8_t schFcfsScheduleUlLc(SlotTimingInfo dciTime, SlotTimingInfo puschTime, ui
       /* Update PUSCH allocation */
       if(schFillPuschAlloc(ueCb, puschTime, totDataReq, startSymb, symbLen, startPrb, isRetx, *hqP) == ROK)
       {
-         if(cell->schUlSlotInfo[puschTime.slot]->schPuschInfo)
+         if(cell->schUlSlotInfo[puschTime.slot]->schPuschInfo[ueCb->ueId])
          {
-            puschInfo = cell->schUlSlotInfo[puschTime.slot]->schPuschInfo;
+            puschInfo = cell->schUlSlotInfo[puschTime.slot]->schPuschInfo[ueCb->ueId];
             if(puschInfo != NULLP)
             {
                /* Fill DCI for UL grant */
                schFillUlDci(ueCb, puschInfo, dciInfo, isRetx, *hqP);
-               memcpy(&dciInfo->slotIndInfo, &dciTime, sizeof(SlotTimingInfo));
                ueCb->srRcvd = false;
                ueCb->bsrRcvd = false;
-               cell->schUlSlotInfo[puschTime.slot]->puschUe = ueCb->ueId;
                if(fcfsHqProcCb->lcCb.dedLcList.count != 0)
                   updateBsrAndLcList(&(fcfsHqProcCb->lcCb.dedLcList), ueCb->bsrInfo, ROK);
                updateBsrAndLcList(&(fcfsHqProcCb->lcCb.defLcList), ueCb->bsrInfo, ROK);
@@ -977,17 +976,18 @@ uint8_t schFcfsScheduleUlLc(SlotTimingInfo dciTime, SlotTimingInfo puschTime, ui
  *         RFAILED
  *
  * ****************************************************************/
-uint32_t schFcfsScheduleDlLc(SlotTimingInfo pdcchTime, SlotTimingInfo pdschTime, uint8_t pdschNumSymbols, bool isRetx, SchDlHqProcCb **hqP)
+uint32_t schFcfsScheduleDlLc(SlotTimingInfo pdcchTime, SlotTimingInfo pdschTime, uint8_t pdschNumSymbols, \
+                               uint16_t *startPrb, bool isRetx, SchDlHqProcCb **hqP)
 {
    SchFcfsHqProcCb *fcfsHqProcCb;
    SchUeCb *ueCb;
    uint8_t lcIdx = 0;
-   uint16_t startPrb = 0, maxFreePRB = 0;
+   uint16_t maxFreePRB = 0;
    uint16_t mcsIdx = 0;
    uint32_t accumalatedSize = 0;
    CmLListCp *lcLL = NULLP;
    uint16_t rsvdDedicatedPRB = 0;
-   DlMsgAlloc *dciSlotAlloc;
+   DlMsgSchInfo *dciSlotAlloc;
 
    /* TX_PAYLOAD_HDR_LEN: Overhead which is to be Added once for any UE while estimating Accumulated TB Size
     * Following flag added to keep the record whether TX_PAYLOAD_HDR_LEN is added to the first Node getting allocated.
@@ -1003,7 +1003,7 @@ uint32_t schFcfsScheduleDlLc(SlotTimingInfo pdcchTime, SlotTimingInfo pdschTime,
    {
       /*Re-Initalization per UE*/
       /* scheduled LC data fill */
-      dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo].numLc = 0;
+      dciSlotAlloc->transportBlock[0].numLc = 0;
       isTxPayloadLenAdded = FALSE; /*Re-initlaize the flag for every UE*/
       accumalatedSize = 0;
 
@@ -1029,17 +1029,14 @@ uint32_t schFcfsScheduleDlLc(SlotTimingInfo pdcchTime, SlotTimingInfo pdschTime,
             {
                DU_LOG("\nERROR  --> SCH : Updation in LC List Failed");
                /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
-               if(dciSlotAlloc->numSchedInfo == 0)
+               if(!dciSlotAlloc->dlMsgPdschCfg)
                {
-                  SCH_FREE(dciSlotAlloc, sizeof(DlMsgAlloc));
+                  SCH_FREE(dciSlotAlloc, sizeof(DlMsgSchInfo));
                   (*hqP)->hqEnt->cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueCb->ueId -1] = NULL;
                }
-               else
-                  memset(&dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo], 0, sizeof(DlMsgSchInfo));
-               return false;
+               return accumalatedSize;
             }
          }
-         ueCb->dlInfo.dlLcCtxt[lcIdx].bo = 0;
       }//End of for loop
 
       if ((fcfsHqProcCb->lcCb.defLcList.count == 0) && (fcfsHqProcCb->lcCb.dedLcList.count == 0))
@@ -1048,21 +1045,18 @@ uint32_t schFcfsScheduleDlLc(SlotTimingInfo pdcchTime, SlotTimingInfo pdschTime,
          UNSET_ONE_BIT((*hqP)->hqEnt->ue->ueId, (*hqP)->hqEnt->cell->boIndBitMap);
 
          /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
-         if(dciSlotAlloc->numSchedInfo == 0)
+         if(!dciSlotAlloc->dlMsgPdschCfg)
          {
-            SCH_FREE(dciSlotAlloc, sizeof(DlMsgAlloc));
+            SCH_FREE(dciSlotAlloc, sizeof(DlMsgSchInfo));
             (*hqP)->hqEnt->cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueCb->ueId -1] = NULL;
          }
-         else
-            memset(&dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo], 0, sizeof(DlMsgSchInfo));
-
          /*TRUE because this UE has nothing to be scheduled*/
-         return true;
+         return accumalatedSize;
       }
    }
 
    /*[Step3]: Calculate Best FREE BLOCK with MAX PRB count*/
-   maxFreePRB = searchLargestFreeBlock((*hqP)->hqEnt->cell, pdschTime, &startPrb, DIR_DL);
+   maxFreePRB = searchLargestFreeBlock((*hqP)->hqEnt->cell, pdschTime, startPrb, DIR_DL);
 
    /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
     * the list based on RRM policy*/
@@ -1078,7 +1072,7 @@ uint32_t schFcfsScheduleDlLc(SlotTimingInfo pdcchTime, SlotTimingInfo pdschTime,
          if((fcfsHqProcCb->lcCb.dedLcList.count == NULLP) || ((maxFreePRB < rsvdDedicatedPRB)))
          { 
             fcfsHqProcCb->lcCb.sharedNumPrb = maxFreePRB;
-            DU_LOG("\nDEBUG  --> SCH : DL Only Default Slice is scheduled, sharedPRB Count:%d",\
+            DU_LOG("\nDEBUG  -->  SCH : DL Only Default Slice is scheduled, sharedPRB Count:%d",\
                   fcfsHqProcCb->lcCb.sharedNumPrb);
 
             /*PRB Alloc for Default LCs*/
@@ -1158,18 +1152,25 @@ void schFcfsScheduleSlot(SchCellCb *cell, SlotTimingInfo *slotInd, Inst schInst)
    SchUlHqProcCb  *ulHqP = NULLP;
    CmLList        *pendingUeNode;
    CmLList        *node;
-   uint8_t        ueId;
+   uint8_t        ueId, ueCount = 0;
    bool           isRarPending = false, isRarScheduled = false;
    bool           isMsg4Pending = false, isMsg4Scheduled = false;
    bool           isDlMsgPending = false, isDlMsgScheduled = false;
    bool           isUlGrantPending = false, isUlGrantScheduled = false;
 
    fcfsCell = (SchFcfsCellCb *)cell->schSpcCell;
-   
+
    /* Select first UE in the linked list to be scheduled next */
    pendingUeNode = fcfsCell->ueToBeScheduled.first;
-   if(pendingUeNode)
+   ueCount = fcfsCell->ueToBeScheduled.count;
+
+   while(pendingUeNode && ueCount > 0)
    {
+      /*Since Multi-UE perTTI is not supported, re-init following parameters.*/
+      isRarPending = false; isRarScheduled = false;
+      isMsg4Pending = false; isMsg4Scheduled = false;
+      isDlMsgPending = false; isDlMsgScheduled = false;
+      isUlGrantPending = false; isUlGrantScheduled = false;
       if(pendingUeNode->node)
       {
          ueId = *(uint8_t *)(pendingUeNode->node);
@@ -1272,12 +1273,23 @@ void schFcfsScheduleSlot(SchCellCb *cell, SlotTimingInfo *slotInd, Inst schInst)
                   else
                   {
 #ifdef NR_DRX
-                     schHdlDrxInActvStrtTmr(cell, &cell->ueCb[ueId-1], PHY_DELTA_DL + SCHED_DELTA);
+                     schHdlDrxInActvStrtTmr(cell, &cell->ueCb[ueId-1], gConfigInfo.gPhyDeltaDl + SCHED_DELTA);
 #endif
                   }
                }
             }
-
+         }
+#ifdef NR_DRX 
+         if((cell->ueCb[ueId-1].ueDrxInfoPres == true) && (cell->ueCb[ueId-1].drxUeCb.drxUlUeActiveStatus != true))
+         {
+            if(pendingUeNode->node)
+            {
+               cmLListAdd2Tail(&fcfsCell->ueToBeScheduled, cmLListDelFrm(&fcfsCell->ueToBeScheduled, pendingUeNode));
+            }
+         }
+         else 
+#endif
+         {
             /* Scheduling of UL grant */
             node = NULLP;
             if(fcfsUeCb)
@@ -1307,26 +1319,38 @@ void schFcfsScheduleSlot(SchCellCb *cell, SlotTimingInfo *slotInd, Inst schInst)
                   else
                   {
 #ifdef NR_DRX
-                     schHdlDrxInActvStrtTmr(cell, &cell->ueCb[ueId-1], PHY_DELTA_UL + SCHED_DELTA);
+                     schHdlDrxInActvStrtTmr(cell, &cell->ueCb[ueId-1], gConfigInfo.gPhyDeltaUl + SCHED_DELTA);
 #endif
                   }
                }
             }
 
-            if(!isUlGrantPending && !isDlMsgPending)
-            {
-               /* No action required */  
-            }
-            else if((isUlGrantPending && !isUlGrantScheduled) || (isDlMsgPending && !isDlMsgScheduled))
+            if(isUlGrantPending || isDlMsgPending)
             {
-               cmLListAdd2Tail(&fcfsCell->ueToBeScheduled, cmLListDelFrm(&fcfsCell->ueToBeScheduled, pendingUeNode));
-            }
-            else
-            {
-               schFcfsRemoveUeFrmScheduleLst(cell, pendingUeNode);
+               if((isUlGrantPending && !isUlGrantScheduled) || (isDlMsgPending && !isDlMsgScheduled))
+               {
+                  cmLListAdd2Tail(&fcfsCell->ueToBeScheduled, cmLListDelFrm(&fcfsCell->ueToBeScheduled, pendingUeNode));
+               }
+               else
+               {
+                  schFcfsRemoveUeFrmScheduleLst(cell, pendingUeNode);
+               }
             }
          }
       }
+      if(!isUlGrantPending && !isDlMsgPending && !isRarPending && !isMsg4Pending)
+      {
+         DU_LOG("\nERROR  -->  SCH: In SchFcfsScheduleSlot, UE:%d is wrongly queued\
+               in Pending UE List without any actions, Removing the UE from the list",ueId);
+         schFcfsRemoveUeFrmScheduleLst(cell, pendingUeNode);
+      }
+      if(cell->schDlSlotInfo[slotInd->slot]->prbAlloc.numPrbAlloc >= MAX_NUM_RB)
+      {
+         DU_LOG("\nINFO   -->  SCH: No PRB available to proceed with next UE");
+         return;     
+      }
+      pendingUeNode = fcfsCell->ueToBeScheduled.first;
+      ueCount--;
    }
 }