Round Robin Scheduling of Multi-UE [Issue-ID: ODUHIGH-387]
[o-du/l2.git] / src / 5gnrsch / sch.c
index 8fd6a87..c1c1a43 100644 (file)
@@ -664,6 +664,7 @@ uint8_t schInitCellCb(Inst inst, SchCellCfg *schCellCfg)
    cell->firstSsbTransmitted = false;
    cell->firstSib1Transmitted = false;
    fillSsbStartSymb(cell);
+   cmLListInit(&cell->ueToBeScheduled);
    schCb[inst].cells[inst] = cell;
 
    DU_LOG("\nINFO  -->  SCH : Cell init completed for cellId:%d", cell->cellId);
@@ -931,6 +932,7 @@ uint8_t MacSchDlRlcBoInfo(Pst *pst, DlRlcBoInfo *dlBoInfo)
 #ifdef NR_TDD
    uint16_t slotIdx = 0;
 #endif
+   bool isLcIdValid = false;
    DlMsgInfo dlMsgInfo;
    SchUeCb *ueCb = NULLP;
    SchCellCb *cell = NULLP;
@@ -941,7 +943,7 @@ uint8_t MacSchDlRlcBoInfo(Pst *pst, DlRlcBoInfo *dlBoInfo)
    DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_DL_RLC_BO_INFO_TO_SCH\n");
 #endif
 
-   DU_LOG("\nDEBUG  -->  SCH : Received RLC BO Status indication");
+   DU_LOG("\nDEBUG  -->  SCH : Received RLC BO Status indication LCId [%d] BO [%d]", dlBoInfo->lcId, dlBoInfo->dataVolume);
    cell = schCb[inst].cells[inst];
 
    if(cell == NULLP)
@@ -953,6 +955,12 @@ uint8_t MacSchDlRlcBoInfo(Pst *pst, DlRlcBoInfo *dlBoInfo)
    GET_UE_IDX(dlBoInfo->crnti, ueIdx);
    ueCb = &cell->ueCb[ueIdx-1];
    lcId  = dlBoInfo->lcId;
+   CHECK_LCID(lcId, isLcIdValid);
+   if(isLcIdValid == FALSE)
+   {
+      DU_LOG("ERROR --> SCH: LCID:%d is not valid", lcId);
+      return RFAILED;
+   }
 
    memset(&dlMsgInfo, 0, sizeof(DlMsgInfo));
    dlMsgInfo.crnti = dlBoInfo->crnti;
@@ -974,23 +982,14 @@ uint8_t MacSchDlRlcBoInfo(Pst *pst, DlRlcBoInfo *dlBoInfo)
    {
       /* TODO : These part of changes will be corrected during DL scheduling as
        * per K0 - K1 -K2 */
-      if(lcId == SRB1_LCID || lcId == SRB2_LCID || lcId == SRB3_LCID || \
-            (lcId >= MIN_DRB_LCID && lcId <= MAX_DRB_LCID))
+      SET_ONE_BIT(ueIdx, cell->boIndBitMap);
+      if(ueCb->dlInfo.dlLcCtxt[lcId].lcId == lcId)
       {
-         SET_ONE_BIT(ueIdx, cell->boIndBitMap);
-         if(ueCb->dlInfo.dlLcCtxt[lcId].lcId == lcId)
-         {
-            ueCb->dlInfo.dlLcCtxt[lcId].bo = dlBoInfo->dataVolume;
-         }
-         else
-         {
-            DU_LOG("ERROR --> SCH: LCID:%d is not configured in SCH Cb",lcId);
-            return RFAILED;
-         }
+         ueCb->dlInfo.dlLcCtxt[lcId].bo = dlBoInfo->dataVolume;
       }
-      else if(lcId != SRB0_LCID)
+      else
       {
-         DU_LOG("\nERROR  -->  SCH : Invalid LC Id %d in MacSchDlRlcBoInfo", lcId);
+         DU_LOG("ERROR --> SCH: LCID:%d is not configured in SCH Cb",lcId);
          return RFAILED;
       }
 
@@ -1372,6 +1371,58 @@ uint8_t allocatePrbUl(SchCellCb *cell, SlotTimingInfo slotTime, \
 
    return ROK;
 }
+
+/*******************************************************************
+ *
+ * @brief Add UE to ueToBeScheduled List
+ *
+ * @details
+ *
+ *    Function : addUeToBeScheduled
+ *
+ *    Functionality:
+ *      Search if UE entry present in the list
+ *      If yes, return.
+ *      If no, add UE to the list
+ *
+ * @params[in] Cell control block
+ *             Ue Idx to be added
+ *
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t addUeToBeScheduled(SchCellCb *cell, uint8_t ueIdToAdd)
+{
+   uint8_t *ueId;
+   CmLList *node;
+
+   /* Search if UE entry is already present in ueToBeScheduled list.
+    * If yes, another entry for same UE not needed. Hence, return */
+   node = cell->ueToBeScheduled.first;
+   while(node)
+   {
+      ueId = (uint8_t *)node->node;
+      if(*ueId == ueIdToAdd)
+         return ROK;
+      node = node->next;
+   }
+
+   /* If UE entry not present already, add UE to the end of ueToBeScheduled list */
+   SCH_ALLOC(ueId, sizeof(uint8_t));
+   if(!ueId)
+   {
+      DU_LOG("\nERROR  -->  SCH : Memory allocation failure in addUeToBeScheduled");
+      return RFAILED;
+   }
+   *ueId = ueIdToAdd;
+   if(addNodeToLList(&cell->ueToBeScheduled, ueId, NULLP) != ROK)
+   {
+      DU_LOG("\nERROR  --> SCH : Failed to add UeIdx to cell->ueToBeScheduled list");
+      return RFAILED;
+   }
+   return ROK;
+}
  
 /*******************************************************************************
  *