1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /************************************************************************
25 Desc: C source code for scheduling based on First Come First Serve
30 **********************************************************************/
32 /** @file sch_slot_ind.c
33 @brief This module processes slot indications
35 #include "common_def.h"
41 #include "du_app_mac_inf.h"
42 #include "mac_sch_interface.h"
45 #include "sch_utils.h"
51 /*******************************************************************
53 * @brief Function to handle Cell configuration request
57 * Function : schFcfsCellCfgReq
59 * Functionality: This function configures cell paremeters
60 * required for FCFS scheduling
62 * @params[in] SchCellCb *cellCb, Cell control block
66 * ****************************************************************/
67 uint8_t schFcfsCellCfgReq(SchCellCb *cellCb)
69 SchFcfsCellCb *fcfsCellCb = NULLP;
71 SCH_ALLOC(fcfsCellCb, sizeof(SchFcfsCellCb));
74 DU_LOG("\nERROR --> SCH: Memory allocation failed in schFcfsCellCfgReq");
77 cmLListInit(&fcfsCellCb->ueToBeScheduled);
78 cellCb->schSpcCell = (void *)fcfsCellCb;
82 /*******************************************************************
84 * @brief Function to handle Cell configuration request
88 * Function : schFcfsCellDelReq
90 * Functionality: This function deletes/frees cell params
91 * specific to FCFS scheduling
93 * @params[in] Pointer to Cell control block
96 * ****************************************************************/
97 void schFcfsCellDelReq(SchCellCb *cellCb)
99 SchFcfsCellCb *fcfsCellCb = NULLP;
100 CmLList *node=NULL, *next=NULL;
102 fcfsCellCb = (SchFcfsCellCb *)cellCb->schSpcCell;
103 /* Remove all UE from ueToBeScheduled list and deallocate */
104 node = fcfsCellCb->ueToBeScheduled.first;
108 SCH_FREE(node->node, sizeof(uint8_t));
109 cmLListDelFrm(&fcfsCellCb->ueToBeScheduled, node);
110 SCH_FREE(node, sizeof(CmLList));
113 SCH_FREE(fcfsCellCb, sizeof(SchFcfsCellCb));
114 cellCb->schSpcCell = NULLP;
117 /*******************************************************************
119 * @brief Function to handle UE configuration request
123 * Function : SchFcfsAddUeConfigReq
125 * Functionality: Adds/Configures UE parameters required for
128 * @params[in] Pointer to UE control block
132 * ****************************************************************/
133 uint8_t SchFcfsAddUeConfigReq(SchUeCb *ueCb)
135 SchFcfsUeCb *ueFcfsCb;
137 SCH_ALLOC(ueFcfsCb, sizeof(SchFcfsHqCb));
140 DU_LOG("\nERROR --> SCH: Memory allocation failed in SchFcfsAddUeConfigReq");
144 cmLListInit(&ueFcfsCb->hqRetxCb.ulRetxHqList);
145 cmLListInit(&ueFcfsCb->hqRetxCb.dlRetxHqList);
146 ueCb->schSpcUeCb = (void *)ueFcfsCb;
151 /*******************************************************************
153 * @brief Handles UE reconfiguration request
157 * Function : SchFcfsModUeConfigReq
161 * @params[in] Pointer to UE control block
164 * ****************************************************************/
165 void SchFcfsModUeConfigReq(SchUeCb *ueCb)
167 /*TBD: No action required for FCFS*/
171 /*******************************************************************
173 * @brief Handles UE Delete Request
177 * Function : SchFcfsUeDeleteReq
179 * Functionality: Deletes/Frees UE parameters specific to
182 * @params[in] Pointer to UE control block
185 * ****************************************************************/
186 void SchFcfsUeDeleteReq(SchUeCb *ueCb)
188 SchFcfsCellCb *fcfsCellCb = NULLP;
189 SchFcfsUeCb *ueFcfsCb = NULLP;
190 CmLList *node=NULL, *next=NULL;
193 fcfsCellCb = (SchFcfsCellCb *)ueCb->cellCb->schSpcCell;
194 /* Remove all UE from ueToBeScheduled list and deallocate */
195 node = fcfsCellCb->ueToBeScheduled.first;
199 ueId = *(uint8_t *)node->node;
200 if(ueId == ueCb->ueId)
202 SCH_FREE(node->node, sizeof(uint8_t));
203 cmLListDelFrm(&fcfsCellCb->ueToBeScheduled, node);
204 SCH_FREE(node, sizeof(CmLList));
210 ueFcfsCb = (SchFcfsUeCb *)ueCb->schSpcUeCb;
211 cmLListDeleteLList(&ueFcfsCb->hqRetxCb.ulRetxHqList);
212 cmLListDeleteLList(&ueFcfsCb->hqRetxCb.dlRetxHqList);
214 SCH_FREE(ueFcfsCb, sizeof(SchFcfsUeCb));
215 ueCb->schSpcUeCb = NULLP;
219 /*******************************************************************
221 * @brief Intializes HARQ Process control block
225 * Function : schFcfsInitDlHqProcCb
227 * Functionality: Intitialized parameters of HARQ process control
228 * block specific to FCFS scheduling in Downlink
230 * @params[in] Pointer to Downlink HARQ Process control block
234 * ****************************************************************/
235 uint8_t schFcfsInitDlHqProcCb(SchDlHqProcCb *hqP)
237 SchFcfsHqProcCb *fcfsHqP;
239 SCH_ALLOC(fcfsHqP, sizeof(SchFcfsHqProcCb));
242 DU_LOG("\nERROR --> SCH: Memory allocation failed in schFcfsInitDlHqProcCb");
246 cmLListInit(&fcfsHqP->lcCb.dedLcList);
247 cmLListInit(&fcfsHqP->lcCb.defLcList);
248 hqP->schSpcDlHqProcCb = (void *)fcfsHqP;
253 /*******************************************************************
255 * @brief Handles HARQ Process delete request
259 * Function : schFcfsDeleteDlHqProcCb
261 * Functionality: Deletes HARQ Process parameters specific to
262 * FCFS scheduling in Downlink
264 * @params[in] Pointer to Downlink HARQ Process control block
267 * ****************************************************************/
268 void schFcfsDeleteDlHqProcCb(SchDlHqProcCb *hqP)
270 SchFcfsHqProcCb *fcfsHqP = (SchFcfsHqProcCb *)hqP->schSpcDlHqProcCb;
271 cmLListDeleteLList(&fcfsHqP->lcCb.dedLcList);
272 cmLListDeleteLList(&fcfsHqP->lcCb.defLcList);
273 SCH_FREE(fcfsHqP, sizeof(SchFcfsHqProcCb));
274 hqP->schSpcDlHqProcCb = NULLP;
277 /*******************************************************************
279 * @brief Intializes HARQ Process control block
283 * Function : schFcfsInitUlHqProcCb
285 * Functionality: Intitialized parameters of HARQ process control
286 * block specific to FCFS scheduling in Uplink
288 * @params[in] Pointer to Uplink HARQ Process control block
292 * ****************************************************************/
293 uint8_t schFcfsInitUlHqProcCb(SchUlHqProcCb *hqP)
295 SchFcfsHqProcCb *fcfsHqP;
297 SCH_ALLOC(fcfsHqP, sizeof(SchFcfsHqProcCb));
300 DU_LOG("\nERROR --> SCH: Memory allocation failed in schFcfsInitUlHqProcCb");
303 cmLListInit(&fcfsHqP->lcCb.dedLcList);
304 cmLListInit(&fcfsHqP->lcCb.defLcList);
305 hqP->schSpcUlHqProcCb = (void *)fcfsHqP;
310 /*******************************************************************
312 * @brief Handled Deletion of HARQ Process control block
316 * Function : schFcfsDeleteUlHqProcCb
318 * Functionality: Deletes HARQ Process parameters specific to
319 * FCFS scheduling in Uplink
321 * @params[in] Pointer to Uplink HARQ Process Control block
324 * ****************************************************************/
325 void schFcfsDeleteUlHqProcCb(SchUlHqProcCb *hqP)
327 SchFcfsHqProcCb *fcfsHqP = (SchFcfsHqProcCb *)hqP->schSpcUlHqProcCb;
328 cmLListDeleteLList(&fcfsHqP->lcCb.dedLcList);
329 cmLListDeleteLList(&fcfsHqP->lcCb.defLcList);
330 SCH_FREE(fcfsHqP, sizeof(SchFcfsHqProcCb));
331 hqP->schSpcUlHqProcCb = NULLP;
334 /*******************************************************************
336 * @brief Handles freeing of HARQ Process
340 * Function : schFcfsFreeDlHqProcCb
342 * Functionality: Frees HARQ Process parameters specific to
343 * FCFS scheduling in Downlink when HARQ process becomes free
345 * @params[in] Pointer to HARQ process control block
348 * ****************************************************************/
349 void schFcfsFreeDlHqProcCb(SchDlHqProcCb *hqP)
351 SchFcfsHqProcCb *fcfsHqP = (SchFcfsHqProcCb *)hqP->schSpcDlHqProcCb;
353 cmLListDeleteLList(&fcfsHqP->lcCb.dedLcList);
354 cmLListDeleteLList(&fcfsHqP->lcCb.defLcList);
357 /*******************************************************************
359 * @brief Handles freeing of HARQ Process
363 * Function : schFcfsFreeUlHqProcCb
365 * Functionality: Frees HARQ Process parameters specific to
366 * FCFS scheduling in Uplink when HARQ process becomes free
368 * @params[in] Pointer to HARQ process control block
371 * ****************************************************************/
372 void schFcfsFreeUlHqProcCb(SchUlHqProcCb *hqP)
374 SchFcfsHqProcCb *fcfsHqP = (SchFcfsHqProcCb *)hqP->schSpcUlHqProcCb;
376 cmLListDeleteLList(&fcfsHqP->lcCb.dedLcList);
377 cmLListDeleteLList(&fcfsHqP->lcCb.defLcList);
380 /*******************************************************************
382 * @brief Adds HARQ process to retransmission list
386 * Function : schFcfsAddToDlHqRetxList
388 * Functionality: Adds HARQ process to retransmission list
390 * @params[in] Pointer to Downlink HARQ Process
393 * ****************************************************************/
394 void schFcfsAddToDlHqRetxList(SchDlHqProcCb *hqP)
396 SchFcfsUeCb *fcfsUeCb;
398 fcfsUeCb = (SchFcfsUeCb *)hqP->hqEnt->ue->schSpcUeCb;
399 cmLListAdd2Tail(&(fcfsUeCb->hqRetxCb.dlRetxHqList),&hqP->dlHqProcLink);
401 if(hqP->hqEnt->ue->ueDrxInfoPres == true)
403 schDrxStrtDlHqRttTmr(hqP);
408 schFcfsAddUeToSchedule(hqP->hqEnt->cell, hqP->hqEnt->ue->ueId);
412 /*******************************************************************
414 * @brief Adds HARQ process to retransmission list
418 * Function : schFcfsAddToUlHqRetxList
420 * Functionality: Adds HARQ process to retransmission list
422 * @params[in] Pointer to Uplink HARQ Process
425 * ****************************************************************/
426 void schFcfsAddToUlHqRetxList(SchUlHqProcCb *hqP)
428 SchFcfsUeCb *fcfsUeCb;
430 fcfsUeCb = (SchFcfsUeCb *)hqP->hqEnt->ue->schSpcUeCb;
431 cmLListAdd2Tail(&(fcfsUeCb->hqRetxCb.ulRetxHqList),&hqP->ulHqProcLink);
433 if(hqP->hqEnt->ue->ueDrxInfoPres == true)
435 schDrxStrtUlHqRttTmr(hqP);
440 schFcfsAddUeToSchedule(hqP->hqEnt->cell, hqP->hqEnt->ue->ueId);
444 /*******************************************************************
446 * @brief Add UE to ueToBeScheduled List
450 * Function : schFcfsAddUeToSchedule
453 * Search if UE entry present in the list
455 * If no, add UE to the list
457 * @params[in] Cell control block
460 * @return ROK - success
463 * ****************************************************************/
464 uint8_t schFcfsAddUeToSchedule(SchCellCb *cellCb, uint16_t ueIdToAdd)
466 SchFcfsCellCb *fcfsCellCb = NULLP;
470 fcfsCellCb = (SchFcfsCellCb *)cellCb->schSpcCell;
471 /* Search if UE entry is already present in ueToBeScheduled list.
472 * If yes, another entry for same UE not needed. Hence, return */
473 node = fcfsCellCb->ueToBeScheduled.first;
476 ueId = (uint8_t *)node->node;
477 if(*ueId == ueIdToAdd)
482 /* If UE entry not present already, add UE to the end of ueToBeScheduled list */
483 SCH_ALLOC(ueId, sizeof(uint8_t));
486 DU_LOG("\nERROR --> SCH : Memory allocation failure in schFcfsAddUeToSchedule");
490 if(addNodeToLList(&fcfsCellCb->ueToBeScheduled, ueId, NULLP) != ROK)
492 DU_LOG("\nERROR --> SCH : Failed to add ueId [%d] to cell->ueToBeScheduled list", *ueId);
498 /*******************************************************************
500 * @brief Handled CRC Indication
504 * Function : schFcfsProcessCrcInd
506 * Functionality: Processes CRC Indication as required for FCFS
509 * @params[in] Pointer to Cell control block
513 * ****************************************************************/
514 void schFcfsProcessCrcInd(SchCellCb *cellCb, uint16_t ueId)
516 schFcfsAddUeToSchedule(cellCb, ueId);
519 /*******************************************************************
521 * @brief Processes Buffer Occupancy report from RLC
525 * Function : schFcfsDlRlcBoInfo
527 * Functionality: Process buffer occupany report
532 * ****************************************************************/
533 void schFcfsDlRlcBoInfo(SchCellCb *cellCb, uint16_t ueId)
535 schFcfsAddUeToSchedule(cellCb, ueId);
538 /*******************************************************************
540 * @brief Processes BSR request
544 * Function : schFcfsBsr
546 * Functionality: Processes BSR as per FCFS scheduling
548 * @params[in] Pointer to Cell
552 * ****************************************************************/
553 void schFcfsBsr(SchCellCb *cellCb, uint16_t ueId)
555 schFcfsAddUeToSchedule(cellCb, ueId);
558 /*******************************************************************
560 * @brief Processed UCI Indication
564 * Function : schFcfsSrUciInd
566 * Functionality: Processing of UCI indication specific to
569 * @params[in] Pointer to Cell
573 * ****************************************************************/
574 void schFcfsSrUciInd(SchCellCb *cellCb, uint16_t ueId)
576 schFcfsAddUeToSchedule(cellCb, ueId);
579 /*******************************************************************
581 * @brief Processing of RACH Indication
585 * Function : schFcfsProcessRachInd
587 * Functionality: Processing of RACH Indication specific to
590 * @params[in] Pointer to Cell Cb
594 * ****************************************************************/
595 void schFcfsProcessRachInd(SchCellCb *cellCb, uint16_t ueId)
597 schFcfsAddUeToSchedule(cellCb, ueId);
600 /*******************************************************************
602 * @brief Processing of DL HARQ Indication
606 * Function : SchFcfsDlHarqInd
613 * ****************************************************************/
614 void SchFcfsDlHarqInd()
619 /*******************************************************************
621 * @brief Processing of Paging indication
625 * Function : schFcfsPagingInd
632 * ****************************************************************/
633 void schFcfsPagingInd()
638 /*******************************************************************
640 * @brief Processing of RACH Resource Request
644 * Function : schFcfsRachRsrcReq
651 * ****************************************************************/
652 void schFcfsRachRsrcReq()
657 /*******************************************************************
659 * @brief Processing of RACH Resource Release
663 * Function : schFcfsRachRsrcRel
670 * ****************************************************************/
671 void schFcfsRachRsrcRel()
676 /*******************************************************************
678 * @brief Remove entry from HARQ retransmission list
682 * Function : schFcfsRemoveFrmDlHqRetxList
684 * Functionality: Remove entry from HARQ retransmission list
686 * @params[in] Pointer to UE
690 * ****************************************************************/
691 void schFcfsRemoveFrmDlHqRetxList(SchUeCb *ueCb, CmLList *node)
693 SchFcfsUeCb *fcfsUeCb;
695 fcfsUeCb = (SchFcfsUeCb *)ueCb->schSpcUeCb;
696 cmLListDelFrm(&fcfsUeCb->hqRetxCb.dlRetxHqList, node);
699 /*******************************************************************
701 * @brief Remove entry from HARQ retransmission list
705 * Function : schFcfsRemoveFrmUlHqRetxList
707 * Functionality: Remove entry from HARQ retransmission list
709 * @params[in] Pointer to UE
713 * ****************************************************************/
714 void schFcfsRemoveFrmUlHqRetxList(SchUeCb *ueCb, CmLList *node)
716 SchFcfsUeCb *fcfsUeCb;
718 fcfsUeCb = (SchFcfsUeCb *)ueCb->schSpcUeCb;
719 cmLListDelFrm(&fcfsUeCb->hqRetxCb.ulRetxHqList, node);
722 /*******************************************************************
724 * @brief Remove UE from Scheduling List
728 * Function : schFcfsRemoveUeFrmScheduleLst
730 * Functionality: Remove UE from Scheduling List
732 * @params[in] Pointer to Cell
736 * ****************************************************************/
737 void schFcfsRemoveUeFrmScheduleLst(SchCellCb *cell, CmLList *node)
739 SchFcfsCellCb *fcfsCell;
741 fcfsCell = (SchFcfsCellCb *)cell->schSpcCell;
742 SCH_FREE(node->node, sizeof(uint8_t));
743 deleteNodeFromLList(&fcfsCell->ueToBeScheduled, node);
746 /*******************************************************************
748 * @brief Handler to calculate TBS size for BSR requested
752 * Function : schFcfsCalculateUlTbs
754 * Functionality: Function will note the required TBS for each LCGIDX and use
755 * the Priority LCG List and RRM policy to allocate the TBS size
757 * @params [in] ueCb (Pointer to UE CB)
758 * [in] puschTime (Time slot where PUSCH will be sent)
759 * [in] symbLen (No of Symbols used for PUSCH transmission)
760 * [out] startPrb(Pointer to startPRB which will be calculated while
761 * finding the best Free Block)
762 * [out] totTBS(Pointer to total TBS size)
763 * [in] isRetx (to indicate retransmission)
764 * [in] hqP (UL Harq process pointer)
766 * @return uint8_t : ROK > Scheduling of UL grant is successful
767 * RFAILED > vice versa
769 * ****************************************************************/
770 uint8_t schFcfsCalculateUlTbs(SchUeCb *ueCb, SlotTimingInfo puschTime, uint8_t symbLen,\
771 uint16_t *startPrb, uint32_t *totTBS, bool isRetx, SchUlHqProcCb *hqP, SchFcfsHqProcCb *fcfsHqP)
774 CmLListCp *lcLL = NULLP;
775 uint16_t lcgIdx = 0, lcId =0, maxFreePRB = 0;
776 uint16_t rsvdDedicatedPRB;
781 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
783 if(ueCb->bsrInfo[lcgIdx].dataVol == 0)
788 /*TODO: lcgIdx and LCID has been implemented as one to one mapping.
789 * Need to check the mapping to figure out the LCID and lcgIdx once L2
790 * spec specifies any logic*/
792 if(ueCb->ulInfo.ulLcCtxt[lcId].isDedicated)
794 lcLL = &(fcfsHqP->lcCb.dedLcList);
795 rsvdDedicatedPRB = ueCb->ulInfo.ulLcCtxt[lcId].rsvdDedicatedPRB;
799 lcLL = &(fcfsHqP->lcCb.defLcList);
802 /*[Step2]: Update the reqPRB and Payloadsize for this LC in the appropriate List*/
803 if(updateLcListReqPRB(lcLL, lcId, ueCb->bsrInfo[lcgIdx].dataVol) != ROK)
805 DU_LOG("\nERROR --> SCH: LcgId:%d updation failed",lcId);
810 if ((fcfsHqP->lcCb.defLcList.count == 0) && (fcfsHqP->lcCb.dedLcList.count == 0))
812 if( (ueCb->srRcvd) || (isRetx) )
814 *startPrb = MAX_NUM_RB;
815 *totTBS = schCalcTbSize(UL_GRANT_SIZE);
817 /*Returning true when NO Grant is there for UE as this is not scheduling
822 maxFreePRB = searchLargestFreeBlock(ueCb->cellCb, puschTime, startPrb, DIR_UL);
824 /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
825 * the list based on RRM policy*/
827 /*Either this UE contains no reservedPRB pool fir dedicated S-NSSAI or
828 * Num of Free PRB available is not enough to reserve Dedicated PRBs*/
831 mcsIdx = ueCb->ueCfg.ulModInfo.mcsIndex;
832 if((fcfsHqP->lcCb.dedLcList.count == 0) || ((maxFreePRB < rsvdDedicatedPRB)))
834 fcfsHqP->lcCb.sharedNumPrb = maxFreePRB;
835 DU_LOG("\nDEBUG --> SCH : UL Only Default Slice is scheduled, sharedPRB Count:%d",\
836 fcfsHqP->lcCb.sharedNumPrb);
838 /*PRB Alloc for Default LCs*/
839 prbAllocUsingRRMPolicy(&(fcfsHqP->lcCb.defLcList), FALSE, mcsIdx, symbLen,\
840 &(fcfsHqP->lcCb.sharedNumPrb), NULLP, NULLP,&(ueCb->srRcvd));
844 fcfsHqP->lcCb.sharedNumPrb = maxFreePRB - rsvdDedicatedPRB;
846 /*PRB Alloc for Dedicated LCs*/
847 prbAllocUsingRRMPolicy(&(fcfsHqP->lcCb.dedLcList), TRUE, mcsIdx, symbLen,\
848 &(fcfsHqP->lcCb.sharedNumPrb), &(rsvdDedicatedPRB),\
849 NULLP, &(ueCb->srRcvd));
851 /*PRB Alloc for Default LCs*/
852 prbAllocUsingRRMPolicy(&(fcfsHqP->lcCb.defLcList), FALSE, mcsIdx, symbLen, \
853 &(fcfsHqP->lcCb.sharedNumPrb), &(rsvdDedicatedPRB),\
854 NULLP,&(ueCb->srRcvd));
857 /*[Step5]:Traverse each LCID in LcList to calculate the exact Scheduled Bytes
858 * using allocated BO per LC and Update dlMsgAlloc(BO report for MAC*/
859 if(fcfsHqP->lcCb.dedLcList.count != 0)
860 updateGrantSizeForBoRpt(&(fcfsHqP->lcCb.dedLcList), NULLP, ueCb->bsrInfo, totTBS);
862 updateGrantSizeForBoRpt(&(fcfsHqP->lcCb.defLcList), NULLP, ueCb->bsrInfo, totTBS);
864 /*Below case will hit if NO LC(s) are allocated due to resource crunch*/
869 DU_LOG("\nERROR --> SCH : NO FREE PRB!!");
873 /*Schedule the LC for next slot*/
874 DU_LOG("\nDEBUG --> SCH : No LC has been scheduled");
881 /*******************************************************************
883 * @brief Grants resources to LC in uplink
887 * Function : schProcessSrOrBsrReq
890 * Grants resources to LC in uplink
892 * @params[in] PDCCH Time
901 *******************************************************************/
902 uint8_t schFcfsScheduleUlLc(SlotTimingInfo dciTime, SlotTimingInfo puschTime, uint8_t startSymb , uint8_t symbLen, bool isRetx, SchUlHqProcCb **hqP)
905 SchFcfsHqProcCb *fcfsHqProcCb;
906 uint8_t ret = RFAILED;
907 uint16_t startPrb = 0;
908 uint32_t totDataReq = 0; /* in bytes */
910 SchPuschInfo *puschInfo;
911 DciInfo *dciInfo = NULLP;
913 cell = (*hqP)->hqEnt->cell;
914 ueCb = (*hqP)->hqEnt->ue;
915 fcfsHqProcCb = (SchFcfsHqProcCb *)(*hqP)->schSpcUlHqProcCb;
916 ret = schFcfsCalculateUlTbs(ueCb, puschTime, symbLen, &startPrb, &totDataReq, isRetx, *hqP, fcfsHqProcCb);
918 if(totDataReq > 0 && ret == ROK)
920 SCH_ALLOC(dciInfo, sizeof(DciInfo));
923 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
926 if(fcfsHqProcCb->lcCb.dedLcList.count != 0)
927 updateBsrAndLcList(&(fcfsHqProcCb->lcCb.dedLcList), ueCb->bsrInfo, RFAILED);
929 updateBsrAndLcList(&(fcfsHqProcCb->lcCb.defLcList), ueCb->bsrInfo, RFAILED);
933 cell->schDlSlotInfo[dciTime.slot]->ulGrant = dciInfo;
934 memset(dciInfo,0,sizeof(DciInfo));
936 /* Update PUSCH allocation */
937 if(schFillPuschAlloc(ueCb, puschTime, totDataReq, startSymb, symbLen, startPrb, isRetx, *hqP) == ROK)
939 if(cell->schUlSlotInfo[puschTime.slot]->schPuschInfo)
941 puschInfo = cell->schUlSlotInfo[puschTime.slot]->schPuschInfo;
942 if(puschInfo != NULLP)
944 /* Fill DCI for UL grant */
945 schFillUlDci(ueCb, puschInfo, dciInfo, isRetx, *hqP);
946 ueCb->srRcvd = false;
947 ueCb->bsrRcvd = false;
948 cell->schUlSlotInfo[puschTime.slot]->puschUe = ueCb->ueId;
949 if(fcfsHqProcCb->lcCb.dedLcList.count != 0)
950 updateBsrAndLcList(&(fcfsHqProcCb->lcCb.dedLcList), ueCb->bsrInfo, ROK);
951 updateBsrAndLcList(&(fcfsHqProcCb->lcCb.defLcList), ueCb->bsrInfo, ROK);
952 cmLListAdd2Tail(&(ueCb->hqUlmap[puschTime.slot]->hqList), &(*hqP)->ulSlotLnk);
957 if(fcfsHqProcCb->lcCb.dedLcList.count != 0)
958 updateBsrAndLcList(&(fcfsHqProcCb->lcCb.dedLcList), ueCb->bsrInfo, RFAILED);
959 updateBsrAndLcList(&(fcfsHqProcCb->lcCb.defLcList), ueCb->bsrInfo, RFAILED);
964 /*******************************************************************
966 * @brief Grants resources to LC in downlink
970 * Function : schFcfsScheduleDlLc
972 * Functionality: Grants resources to LC in uplink
974 * @params[in] PDCCH Time
979 * ****************************************************************/
980 uint32_t schFcfsScheduleDlLc(SlotTimingInfo pdcchTime, SlotTimingInfo pdschTime, uint8_t pdschNumSymbols, \
981 uint16_t *startPrb, bool isRetx, SchDlHqProcCb **hqP)
983 SchFcfsHqProcCb *fcfsHqProcCb;
986 uint16_t maxFreePRB = 0;
988 uint32_t accumalatedSize = 0;
989 CmLListCp *lcLL = NULLP;
990 uint16_t rsvdDedicatedPRB = 0;
991 DlMsgSchInfo *dciSlotAlloc;
993 /* TX_PAYLOAD_HDR_LEN: Overhead which is to be Added once for any UE while estimating Accumulated TB Size
994 * Following flag added to keep the record whether TX_PAYLOAD_HDR_LEN is added to the first Node getting allocated.
995 * If both Dedicated and Default LC lists are present then First LC in Dedicated List will include this overhead
996 * else if only Default list is present then first node in this List will add this overhead len*/
997 bool isTxPayloadLenAdded = FALSE;
999 ueCb = (*hqP)->hqEnt->ue;
1000 dciSlotAlloc = (*hqP)->hqEnt->cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueCb->ueId -1];
1001 fcfsHqProcCb = (SchFcfsHqProcCb *)((*hqP)->schSpcDlHqProcCb);
1003 if (isRetx == FALSE)
1005 /*Re-Initalization per UE*/
1006 /* scheduled LC data fill */
1007 dciSlotAlloc->transportBlock[0].numLc = 0;
1008 isTxPayloadLenAdded = FALSE; /*Re-initlaize the flag for every UE*/
1009 accumalatedSize = 0;
1011 for(lcIdx = 0; lcIdx < MAX_NUM_LC; lcIdx++)
1013 if(ueCb->dlInfo.dlLcCtxt[lcIdx].bo)
1015 /*Check the LC is Dedicated or default and accordingly LCList will
1017 if(ueCb->dlInfo.dlLcCtxt[lcIdx].isDedicated)
1019 lcLL = &(fcfsHqProcCb->lcCb.dedLcList);
1020 rsvdDedicatedPRB = ueCb->dlInfo.dlLcCtxt[lcIdx].rsvdDedicatedPRB;
1024 lcLL = &(fcfsHqProcCb->lcCb.defLcList);
1027 /*[Step2]: Update the reqPRB and Payloadsize for this LC in the appropriate List*/
1028 if(updateLcListReqPRB(lcLL, ueCb->dlInfo.dlLcCtxt[lcIdx].lcId,\
1029 (ueCb->dlInfo.dlLcCtxt[lcIdx].bo + MAC_HDR_SIZE)) != ROK)
1031 DU_LOG("\nERROR --> SCH : Updation in LC List Failed");
1032 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
1033 if(!dciSlotAlloc->dlMsgPdschCfg)
1035 SCH_FREE(dciSlotAlloc, sizeof(DlMsgSchInfo));
1036 (*hqP)->hqEnt->cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueCb->ueId -1] = NULL;
1038 return accumalatedSize;
1043 if ((fcfsHqProcCb->lcCb.defLcList.count == 0) && (fcfsHqProcCb->lcCb.dedLcList.count == 0))
1045 DU_LOG("\nDEBUG --> SCH : No pending BO for any LC id\n");
1046 UNSET_ONE_BIT((*hqP)->hqEnt->ue->ueId, (*hqP)->hqEnt->cell->boIndBitMap);
1048 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
1049 if(!dciSlotAlloc->dlMsgPdschCfg)
1051 SCH_FREE(dciSlotAlloc, sizeof(DlMsgSchInfo));
1052 (*hqP)->hqEnt->cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueCb->ueId -1] = NULL;
1054 /*TRUE because this UE has nothing to be scheduled*/
1055 return accumalatedSize;
1059 /*[Step3]: Calculate Best FREE BLOCK with MAX PRB count*/
1060 maxFreePRB = searchLargestFreeBlock((*hqP)->hqEnt->cell, pdschTime, startPrb, DIR_DL);
1062 /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
1063 * the list based on RRM policy*/
1065 /*Either this UE contains no reservedPRB pool fir dedicated S-NSSAI or
1066 * Num of Free PRB available is not enough to reserve Dedicated PRBs*/
1071 mcsIdx = ueCb->ueCfg.dlModInfo.mcsIndex;
1073 if((fcfsHqProcCb->lcCb.dedLcList.count == NULLP) || ((maxFreePRB < rsvdDedicatedPRB)))
1075 fcfsHqProcCb->lcCb.sharedNumPrb = maxFreePRB;
1076 DU_LOG("\nDEBUG --> SCH : DL Only Default Slice is scheduled, sharedPRB Count:%d",\
1077 fcfsHqProcCb->lcCb.sharedNumPrb);
1079 /*PRB Alloc for Default LCs*/
1080 prbAllocUsingRRMPolicy(&(fcfsHqProcCb->lcCb.defLcList), FALSE, mcsIdx, pdschNumSymbols,\
1081 &(fcfsHqProcCb->lcCb.sharedNumPrb), NULLP, &isTxPayloadLenAdded, NULLP);
1085 fcfsHqProcCb->lcCb.sharedNumPrb = maxFreePRB - rsvdDedicatedPRB;
1086 /*PRB Alloc for Dedicated LCs*/
1087 prbAllocUsingRRMPolicy(&(fcfsHqProcCb->lcCb.dedLcList), TRUE, mcsIdx, pdschNumSymbols,\
1088 &(fcfsHqProcCb->lcCb.sharedNumPrb), &(rsvdDedicatedPRB), &isTxPayloadLenAdded, NULLP);
1090 /*PRB Alloc for Default LCs*/
1091 prbAllocUsingRRMPolicy(&(fcfsHqProcCb->lcCb.defLcList), FALSE, mcsIdx, pdschNumSymbols, \
1092 &(fcfsHqProcCb->lcCb.sharedNumPrb), &(rsvdDedicatedPRB), &isTxPayloadLenAdded, NULLP);
1097 /*[Step5]:Traverse each LCID in LcList to calculate the exact Scheduled Bytes
1098 * using allocated BO per LC and Update dlMsgAlloc BO report for MAC */
1099 if (isRetx == FALSE)
1101 if(fcfsHqProcCb->lcCb.dedLcList.count != 0)
1102 updateGrantSizeForBoRpt(&(fcfsHqProcCb->lcCb.dedLcList), dciSlotAlloc, NULLP, &(accumalatedSize));
1104 updateGrantSizeForBoRpt(&(fcfsHqProcCb->lcCb.defLcList), dciSlotAlloc, NULLP, &(accumalatedSize));
1108 accumalatedSize = (*hqP)->tbInfo[0].tbSzReq;
1111 /*Below case will hit if NO LC(s) are allocated due to resource crunch*/
1112 if (!accumalatedSize)
1116 DU_LOG("\nERROR --> SCH : NO FREE PRB!!");
1120 /*Schedule the LC for next slot*/
1121 DU_LOG("\nDEBUG --> SCH : No LC has been scheduled");
1123 /* Not Freeing dlMsgAlloc as ZERO BO REPORT to be sent to RLC so that
1124 * Allocation can be done in next slot*/
1125 accumalatedSize = 0;
1128 return accumalatedSize;
1131 /*******************************************************************
1133 * @brief Scheduling of Slots in UL And DL
1137 * Function : schFcfsScheduleSlot
1139 * Functionality: Scheduling of slots in UL and DL specific to
1142 * @params[in] Pointer to Cell
1144 * Scheduler instance
1147 * ****************************************************************/
1148 void schFcfsScheduleSlot(SchCellCb *cell, SlotTimingInfo *slotInd, Inst schInst)
1150 SchFcfsCellCb *fcfsCell;
1151 SchFcfsUeCb *fcfsUeCb;
1152 SchDlHqProcCb *hqP = NULLP;
1153 SchUlHqProcCb *ulHqP = NULLP;
1154 CmLList *pendingUeNode;
1157 bool isRarPending = false, isRarScheduled = false;
1158 bool isMsg4Pending = false, isMsg4Scheduled = false;
1159 bool isDlMsgPending = false, isDlMsgScheduled = false;
1160 bool isUlGrantPending = false, isUlGrantScheduled = false;
1161 bool isNodeFreed = false;
1163 fcfsCell = (SchFcfsCellCb *)cell->schSpcCell;
1165 /* Select first UE in the linked list to be scheduled next */
1166 pendingUeNode = fcfsCell->ueToBeScheduled.first;
1167 while(pendingUeNode)
1169 if(pendingUeNode->node)
1171 ueId = *(uint8_t *)(pendingUeNode->node);
1172 fcfsUeCb = (SchFcfsUeCb *)cell->ueCb[ueId-1].schSpcUeCb;
1174 /* If RAR is pending for this UE, schedule PDCCH,PDSCH to send RAR and
1175 * PUSCH to receive MSG3 as per k0-k2 configuration*/
1176 if(cell->raReq[ueId-1] != NULLP)
1178 isRarPending = true;
1179 isRarScheduled = schProcessRaReq(schInst, cell, *slotInd, ueId);
1182 /*MSG3 retransmisson*/
1183 if(cell->raCb[ueId-1].retxMsg3HqProc)
1185 schMsg3RetxSchedulingForUe(&(cell->raCb[ueId-1]));
1188 /* If MSG4 is pending for this UE, schedule PDCCH,PDSCH to send MSG4 and
1189 * PUCCH to receive UL msg as per k0-k1 configuration */
1190 if (cell->ueCb[ueId-1].retxMsg4HqProc) //should work from dlmap later tbd
1192 /* Retransmission of MSG4 */
1193 isMsg4Pending = true;
1194 if(schProcessMsg4Req(cell, *slotInd, ueId, TRUE, &cell->ueCb[ueId-1].retxMsg4HqProc) == ROK)
1195 isMsg4Scheduled = true;
1199 /* First transmission of MSG4 */
1200 if(cell->raCb[ueId-1].msg4recvd)
1202 isMsg4Pending = true;
1203 if(schProcessMsg4Req(cell, *slotInd, ueId, FALSE, &cell->ueCb[ueId-1].msg4HqProc) == ROK)
1204 isMsg4Scheduled = true;
1206 /* If MSG4 scheduling failed, free the newly assigned HARQ process */
1207 if(!isMsg4Scheduled)
1208 schDlReleaseHqProcess(cell->ueCb[ueId-1].msg4HqProc);
1212 if(isRarPending || isMsg4Pending)
1214 /* If RAR or MSG is successfully scheduled then
1215 * remove UE from linked list since no pending msgs for this UE */
1216 if(isRarScheduled || isMsg4Scheduled)
1218 schFcfsRemoveUeFrmScheduleLst(cell, pendingUeNode);
1221 /* If RAR/MSG4 is pending but couldnt be scheduled then,
1222 * put this UE at the end of linked list to be scheduled later */
1225 cmLListAdd2Tail(&fcfsCell->ueToBeScheduled, cmLListDelFrm(&fcfsCell->ueToBeScheduled, pendingUeNode));
1230 if((cell->ueCb[ueId-1].ueDrxInfoPres == true) && (cell->ueCb[ueId-1].drxUeCb.drxDlUeActiveStatus != true))
1232 if(pendingUeNode->node)
1234 cmLListAdd2Tail(&fcfsCell->ueToBeScheduled, cmLListDelFrm(&fcfsCell->ueToBeScheduled, pendingUeNode));
1244 node = fcfsUeCb->hqRetxCb.dlRetxHqList.first;
1247 /* DL Data ReTransmisson */
1248 isDlMsgPending = true;
1249 isDlMsgScheduled = schFillBoGrantDlSchedInfo(cell, *slotInd, ueId, TRUE, ((SchDlHqProcCb**) &(node->node)));
1250 if(isDlMsgScheduled)
1253 schDrxStopDlHqRetxTmr(cell, &cell->ueCb[ueId-1], ((SchDlHqProcCb**) &(node->node)));
1255 schFcfsRemoveFrmDlHqRetxList(&cell->ueCb[ueId-1], node);
1260 /* DL Data new transmission */
1261 if((cell->boIndBitMap) & (1<<ueId))
1263 isDlMsgPending = true;
1264 isDlMsgScheduled = schFillBoGrantDlSchedInfo(cell, *slotInd, ueId, FALSE, &hqP);
1266 /* If DL scheduling failed, free the newly assigned HARQ process */
1267 if(!isDlMsgScheduled)
1268 schDlReleaseHqProcess(hqP);
1272 schHdlDrxInActvStrtTmr(cell, &cell->ueCb[ueId-1], PHY_DELTA_DL + SCHED_DELTA);
1278 /* Scheduling of UL grant */
1281 node = fcfsUeCb->hqRetxCb.ulRetxHqList.first;
1284 /* UL Data ReTransmisson */
1285 isUlGrantPending = true;
1286 isUlGrantScheduled = schProcessSrOrBsrReq(cell, *slotInd, ueId, TRUE, (SchUlHqProcCb**) &(node->node));
1287 if(isUlGrantScheduled)
1290 schDrxStopUlHqRetxTmr(cell, &cell->ueCb[ueId-1], ((SchUlHqProcCb**) &(node->node)));
1292 schFcfsRemoveFrmUlHqRetxList(&cell->ueCb[ueId-1], node);
1297 /* UL Data new transmission */
1298 if(cell->ueCb[ueId-1].srRcvd || cell->ueCb[ueId-1].bsrRcvd)
1300 isUlGrantPending = true;
1301 isUlGrantScheduled = schProcessSrOrBsrReq(cell, *slotInd, ueId, FALSE, &ulHqP);
1302 if(!isUlGrantScheduled)
1303 schUlReleaseHqProcess(ulHqP, FALSE);
1307 schHdlDrxInActvStrtTmr(cell, &cell->ueCb[ueId-1], PHY_DELTA_UL + SCHED_DELTA);
1313 if(!isUlGrantPending && !isDlMsgPending)
1315 /* No action required */
1317 else if((isUlGrantPending && !isUlGrantScheduled) || (isDlMsgPending && !isDlMsgScheduled))
1319 cmLListAdd2Tail(&fcfsCell->ueToBeScheduled, cmLListDelFrm(&fcfsCell->ueToBeScheduled, pendingUeNode));
1323 schFcfsRemoveUeFrmScheduleLst(cell, pendingUeNode);
1328 if(cell->schDlSlotInfo[slotInd->slot]->prbAlloc.numPrbAlloc >= MAX_NUM_RB)
1330 DU_LOG("\nINFO --> SCH: No PRB available to proceed with next UE");
1333 if(isNodeFreed == false)
1335 pendingUeNode= pendingUeNode->next;
1339 pendingUeNode = fcfsCell->ueToBeScheduled.first;
1344 /*******************************************************************
1346 * @brief Initializes all function pointers to FCFS function handler
1350 * Function : schFcfsAllApisInit
1352 * Functionality: Initializes all function pointers to FCFS
1355 * @params[in] Function pointer array
1358 * ****************************************************************/
1359 void schFcfsAllApisInit(SchAllApis *allFcfsApi)
1361 /* Interface API function pointers */
1362 allFcfsApi->SchCellCfgReq = schFcfsCellCfgReq;
1363 allFcfsApi->SchCellDeleteReq = schFcfsCellDelReq;
1364 allFcfsApi->SchAddUeConfigReq = SchFcfsAddUeConfigReq;
1365 allFcfsApi->SchModUeConfigReq = SchFcfsModUeConfigReq;
1366 allFcfsApi->SchUeDeleteReq = SchFcfsUeDeleteReq;
1367 allFcfsApi->SchDlHarqInd = SchFcfsDlHarqInd;
1368 allFcfsApi->SchCrcInd = schFcfsProcessCrcInd;
1369 allFcfsApi->SchRachInd = schFcfsProcessRachInd;
1370 allFcfsApi->SchPagingInd = schFcfsPagingInd;
1371 allFcfsApi->SchRachRsrcReq = schFcfsRachRsrcReq;
1372 allFcfsApi->SchRachRsrcRel = schFcfsRachRsrcRel;
1373 allFcfsApi->SchDlRlcBoInfo = schFcfsDlRlcBoInfo;
1374 allFcfsApi->SchSrUciInd = schFcfsSrUciInd;
1375 allFcfsApi->SchBsr = schFcfsBsr;
1377 /* Internal API function pointers */
1378 allFcfsApi->SchAddToDlHqRetxList = schFcfsAddToDlHqRetxList;
1379 allFcfsApi->SchAddToUlHqRetxList = schFcfsAddToUlHqRetxList;
1380 allFcfsApi->SchRemoveFrmDlHqRetxList = schFcfsRemoveFrmDlHqRetxList;
1381 allFcfsApi->SchRemoveFrmUlHqRetxList = schFcfsRemoveFrmUlHqRetxList;
1382 allFcfsApi->SchAddUeToSchedule = schFcfsAddUeToSchedule;
1383 allFcfsApi->SchRemoveUeFrmScheduleLst = schFcfsRemoveUeFrmScheduleLst;
1384 allFcfsApi->SchInitDlHqProcCb = schFcfsInitDlHqProcCb;
1385 allFcfsApi->SchInitUlHqProcCb = schFcfsInitUlHqProcCb;
1386 allFcfsApi->SchFreeDlHqProcCb = schFcfsFreeDlHqProcCb;
1387 allFcfsApi->SchFreeUlHqProcCb = schFcfsFreeUlHqProcCb;
1388 allFcfsApi->SchDeleteDlHqProcCb = schFcfsDeleteDlHqProcCb;
1389 allFcfsApi->SchDeleteUlHqProcCb = schFcfsDeleteUlHqProcCb;
1390 allFcfsApi->SchScheduleSlot = schFcfsScheduleSlot;
1391 allFcfsApi->SchScheduleDlLc = schFcfsScheduleDlLc;
1392 allFcfsApi->SchScheduleUlLc = schFcfsScheduleUlLc;
1394 /**********************************************************************
1396 **********************************************************************/