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 Slice based scheduling algorithm
27 File: sch_slice_based.c
29 **********************************************************************/
31 /** @file sch_slot_ind.c
32 @brief This module processes slot indications
34 #include "common_def.h"
40 #include "du_app_mac_inf.h"
41 #include "mac_sch_interface.h"
43 #include "sch_utils.h"
44 #include "sch_slice_based.h"
49 /*******************************************************************
51 * @brief Function to handle Cell configuration request
55 * Function : schSliceBasedCellCfgReq
57 * Functionality: This function configures cell paremeters
58 * required for Slice Based scheduling
60 * @params[in] SchCellCb *cellCb, Cell control block
64 * ****************************************************************/
65 uint8_t schSliceBasedCellCfgReq(SchCellCb *cellCb)
67 SchSliceBasedCellCb *schSpcCellCb = NULLP;
69 SCH_ALLOC(schSpcCellCb, sizeof(SchSliceBasedCellCb));
72 DU_LOG("\nERROR --> SCH: Memory allocation failed in schSliceBasedCellCfgReq");
75 cmLListInit(&schSpcCellCb->ueToBeScheduled);
76 cellCb->schSpcCell = (void *)schSpcCellCb;
80 /*******************************************************************
82 * @brief Function to handle Cell configuration request
86 * Function : schSliceBasedCellDelReq
88 * Functionality: This function deletes/frees cell params
89 * specific to Slice Based scheduling
91 * @params[in] Pointer to Cell control block
94 * ****************************************************************/
95 void schSliceBasedCellDelReq(SchCellCb *cellCb)
97 SchSliceBasedCellCb *schSpcCellCb = NULLP;
98 CmLList *node=NULL, *next=NULL;
100 schSpcCellCb = (SchSliceBasedCellCb *)cellCb->schSpcCell;
101 /* Remove all UE from ueToBeScheduled list and deallocate */
102 node = schSpcCellCb->ueToBeScheduled.first;
106 SCH_FREE(node->node, sizeof(uint8_t));
107 cmLListDelFrm(&schSpcCellCb->ueToBeScheduled, node);
108 SCH_FREE(node, sizeof(CmLList));
111 SCH_FREE(schSpcCellCb, sizeof(SchSliceBasedCellCb));
112 cellCb->schSpcCell = NULLP;
115 /*******************************************************************
117 * @brief Function to handle UE configuration request
121 * Function : SchSliceBasedAddUeConfigReq
123 * Functionality: Adds/Configures UE parameters required for
124 * Slice Based scheduling
126 * @params[in] Pointer to UE control block
130 * ****************************************************************/
131 uint8_t SchSliceBasedAddUeConfigReq(SchUeCb *ueCb)
133 SchSliceBasedUeCb *ueSliceBasedCb;
135 SCH_ALLOC(ueSliceBasedCb, sizeof(SchSliceBasedHqCb));
138 DU_LOG("\nERROR --> SCH: Memory allocation failed in SchSliceBasedAddUeConfigReq");
142 cmLListInit(&ueSliceBasedCb->hqRetxCb.ulRetxHqList);
143 cmLListInit(&ueSliceBasedCb->hqRetxCb.dlRetxHqList);
144 ueCb->schSpcUeCb = (void *)ueSliceBasedCb;
149 /*******************************************************************
151 * @brief Handles UE reconfiguration request
155 * Function : SchSliceBasedModUeConfigReq
159 * @params[in] Pointer to UE control block
162 * ****************************************************************/
163 void SchSliceBasedModUeConfigReq(SchUeCb *ueCb)
165 /*TBD: No action required for Slice Based*/
169 /*******************************************************************
171 * @brief Handles UE Delete Request
175 * Function : SchSliceBasedUeDeleteReq
177 * Functionality: Deletes/Frees UE parameters specific to
178 * Slice Based scheduling
180 * @params[in] Pointer to UE control block
183 * ****************************************************************/
184 void SchSliceBasedUeDeleteReq(SchUeCb *ueCb)
186 SchSliceBasedCellCb *schSpcCellCb = NULLP;
187 SchSliceBasedUeCb *ueSliceBasedCb = NULLP;
188 CmLList *node=NULL, *next=NULL;
191 schSpcCellCb = (SchSliceBasedCellCb *)ueCb->cellCb->schSpcCell;
192 /* Remove all UE from ueToBeScheduled list and deallocate */
193 node = schSpcCellCb->ueToBeScheduled.first;
197 ueId = *(uint8_t *)node->node;
198 if(ueId == ueCb->ueId)
200 SCH_FREE(node->node, sizeof(uint8_t));
201 cmLListDelFrm(&schSpcCellCb->ueToBeScheduled, node);
202 SCH_FREE(node, sizeof(CmLList));
208 ueSliceBasedCb = (SchSliceBasedUeCb *)ueCb->schSpcUeCb;
209 cmLListDeleteLList(&ueSliceBasedCb->hqRetxCb.ulRetxHqList);
210 cmLListDeleteLList(&ueSliceBasedCb->hqRetxCb.dlRetxHqList);
212 SCH_FREE(ueSliceBasedCb, sizeof(SchSliceBasedUeCb));
213 ueCb->schSpcUeCb = NULLP;
217 /*******************************************************************
219 * @brief Intializes HARQ Process control block
223 * Function : schSliceBasedInitDlHqProcCb
225 * Functionality: Intitialized parameters of HARQ process control
226 * block specific to Slice Based scheduling in Downlink
228 * @params[in] Pointer to Downlink HARQ Process control block
232 * ****************************************************************/
233 uint8_t schSliceBasedInitDlHqProcCb(SchDlHqProcCb *hqP)
235 SchSliceBasedHqProcCb *schSpcHqP;
237 SCH_ALLOC(schSpcHqP, sizeof(SchSliceBasedHqProcCb));
240 DU_LOG("\nERROR --> SCH: Memory allocation failed in schSliceBasedInitDlHqProcCb");
244 cmLListInit(&schSpcHqP->lcCb.dedLcList);
245 cmLListInit(&schSpcHqP->lcCb.defLcList);
246 hqP->schSpcDlHqProcCb = (void *)schSpcHqP;
251 /*******************************************************************
253 * @brief Handles HARQ Process delete request
257 * Function : schSliceBasedDeleteDlHqProcCb
259 * Functionality: Deletes HARQ Process parameters specific to
260 * Slice Based scheduling in Downlink
262 * @params[in] Pointer to Downlink HARQ Process control block
265 * ****************************************************************/
266 void schSliceBasedDeleteDlHqProcCb(SchDlHqProcCb *hqP)
268 SchSliceBasedHqProcCb *schSpcHqP = (SchSliceBasedHqProcCb *)hqP->schSpcDlHqProcCb;
269 cmLListDeleteLList(&schSpcHqP->lcCb.dedLcList);
270 cmLListDeleteLList(&schSpcHqP->lcCb.defLcList);
271 SCH_FREE(schSpcHqP, sizeof(SchSliceBasedHqProcCb));
272 hqP->schSpcDlHqProcCb = NULLP;
275 /*******************************************************************
277 * @brief Intializes HARQ Process control block
281 * Function : schSliceBasedInitUlHqProcCb
283 * Functionality: Intitialized parameters of HARQ process control
284 * block specific to Slice Based scheduling in Uplink
286 * @params[in] Pointer to Uplink HARQ Process control block
290 * ****************************************************************/
291 uint8_t schSliceBasedInitUlHqProcCb(SchUlHqProcCb *hqP)
293 SchSliceBasedHqProcCb *schSpcHqP;
295 SCH_ALLOC(schSpcHqP, sizeof(SchSliceBasedHqProcCb));
298 DU_LOG("\nERROR --> SCH: Memory allocation failed in schSliceBasedInitUlHqProcCb");
301 cmLListInit(&schSpcHqP->lcCb.dedLcList);
302 cmLListInit(&schSpcHqP->lcCb.defLcList);
303 hqP->schSpcUlHqProcCb = (void *)schSpcHqP;
308 /*******************************************************************
310 * @brief Handled Deletion of HARQ Process control block
314 * Function : schSliceBasedDeleteUlHqProcCb
316 * Functionality: Deletes HARQ Process parameters specific to
317 * Slice Based scheduling in Uplink
319 * @params[in] Pointer to Uplink HARQ Process Control block
322 * ****************************************************************/
323 void schSliceBasedDeleteUlHqProcCb(SchUlHqProcCb *hqP)
325 SchSliceBasedHqProcCb *schSpcHqP = (SchSliceBasedHqProcCb *)hqP->schSpcUlHqProcCb;
326 cmLListDeleteLList(&schSpcHqP->lcCb.dedLcList);
327 cmLListDeleteLList(&schSpcHqP->lcCb.defLcList);
328 SCH_FREE(schSpcHqP, sizeof(SchSliceBasedHqProcCb));
329 hqP->schSpcUlHqProcCb = NULLP;
332 /*******************************************************************
334 * @brief Handles freeing of HARQ Process
338 * Function : schSliceBasedFreeDlHqProcCb
340 * Functionality: Frees HARQ Process parameters specific to
341 * Slice Based scheduling in Downlink when HARQ process becomes free
343 * @params[in] Pointer to HARQ process control block
346 * ****************************************************************/
347 void schSliceBasedFreeDlHqProcCb(SchDlHqProcCb *hqP)
349 SchSliceBasedHqProcCb *schSpcHqP = (SchSliceBasedHqProcCb *)hqP->schSpcDlHqProcCb;
351 cmLListDeleteLList(&schSpcHqP->lcCb.dedLcList);
352 cmLListDeleteLList(&schSpcHqP->lcCb.defLcList);
355 /*******************************************************************
357 * @brief Handles freeing of HARQ Process
361 * Function : schSliceBasedFreeUlHqProcCb
363 * Functionality: Frees HARQ Process parameters specific to
364 * Slice Based scheduling in Uplink when HARQ process becomes free
366 * @params[in] Pointer to HARQ process control block
369 * ****************************************************************/
370 void schSliceBasedFreeUlHqProcCb(SchUlHqProcCb *hqP)
372 SchSliceBasedHqProcCb *schSpcHqP = (SchSliceBasedHqProcCb *)hqP->schSpcUlHqProcCb;
374 cmLListDeleteLList(&schSpcHqP->lcCb.dedLcList);
375 cmLListDeleteLList(&schSpcHqP->lcCb.defLcList);
378 /*******************************************************************
380 * @brief Adds HARQ process to retransmission list
384 * Function : schSliceBasedAddToDlHqRetxList
386 * Functionality: Adds HARQ process to retransmission list
388 * @params[in] Pointer to Downlink HARQ Process
391 * ****************************************************************/
392 void schSliceBasedAddToDlHqRetxList(SchDlHqProcCb *hqP)
394 SchSliceBasedUeCb *schSpcUeCb;
396 schSpcUeCb = (SchSliceBasedUeCb *)hqP->hqEnt->ue->schSpcUeCb;
397 cmLListAdd2Tail(&(schSpcUeCb->hqRetxCb.dlRetxHqList),&hqP->dlHqProcLink);
399 if(hqP->hqEnt->ue->ueDrxInfoPres == true)
401 schDrxStrtDlHqRttTmr(hqP);
406 schSliceBasedAddUeToSchedule(hqP->hqEnt->cell, hqP->hqEnt->ue->ueId);
410 /*******************************************************************
412 * @brief Adds HARQ process to retransmission list
416 * Function : schSliceBasedAddToUlHqRetxList
418 * Functionality: Adds HARQ process to retransmission list
420 * @params[in] Pointer to Uplink HARQ Process
423 * ****************************************************************/
424 void schSliceBasedAddToUlHqRetxList(SchUlHqProcCb *hqP)
426 SchSliceBasedUeCb *schSpcUeCb;
428 schSpcUeCb = (SchSliceBasedUeCb *)hqP->hqEnt->ue->schSpcUeCb;
429 cmLListAdd2Tail(&(schSpcUeCb->hqRetxCb.ulRetxHqList),&hqP->ulHqProcLink);
431 if(hqP->hqEnt->ue->ueDrxInfoPres == true)
433 schDrxStrtUlHqRttTmr(hqP);
438 schSliceBasedAddUeToSchedule(hqP->hqEnt->cell, hqP->hqEnt->ue->ueId);
442 /*******************************************************************
444 * @brief Add UE to ueToBeScheduled List
448 * Function : schSliceBasedAddUeToSchedule
451 * Search if UE entry present in the list
453 * If no, add UE to the list
455 * @params[in] Cell control block
458 * @return ROK - success
461 * ****************************************************************/
462 uint8_t schSliceBasedAddUeToSchedule(SchCellCb *cellCb, uint16_t ueIdToAdd)
464 SchSliceBasedCellCb *schSpcCellCb = NULLP;
468 schSpcCellCb = (SchSliceBasedCellCb *)cellCb->schSpcCell;
469 /* Search if UE entry is already present in ueToBeScheduled list.
470 * If yes, another entry for same UE not needed. Hence, return */
471 node = schSpcCellCb->ueToBeScheduled.first;
474 ueId = (uint8_t *)node->node;
475 if(*ueId == ueIdToAdd)
480 /* If UE entry not present already, add UE to the end of ueToBeScheduled list */
481 SCH_ALLOC(ueId, sizeof(uint8_t));
484 DU_LOG("\nERROR --> SCH : Memory allocation failure in schSliceBasedAddUeToSchedule");
488 if(addNodeToLList(&schSpcCellCb->ueToBeScheduled, ueId, NULLP) != ROK)
490 DU_LOG("\nERROR --> SCH : Failed to add ueId [%d] to cell->ueToBeScheduled list", *ueId);
496 /*******************************************************************
498 * @brief Handled CRC Indication
502 * Function : schSliceBasedProcessCrcInd
504 * Functionality: Processes CRC Indication as required for Slice Based
507 * @params[in] Pointer to Cell control block
511 * ****************************************************************/
512 void schSliceBasedProcessCrcInd(SchCellCb *cellCb, uint16_t ueId)
514 schSliceBasedAddUeToSchedule(cellCb, ueId);
517 /*******************************************************************
519 * @brief Processes Buffer Occupancy report from RLC
523 * Function : schSliceBasedDlRlcBoInfo
525 * Functionality: Process buffer occupany report
530 * ****************************************************************/
531 void schSliceBasedDlRlcBoInfo(SchCellCb *cellCb, uint16_t ueId)
533 schSliceBasedAddUeToSchedule(cellCb, ueId);
536 /*******************************************************************
538 * @brief Processes BSR request
542 * Function : schSliceBasedBsr
544 * Functionality: Processes BSR as per Slice Based scheduling
546 * @params[in] Pointer to Cell
550 * ****************************************************************/
551 void schSliceBasedBsr(SchCellCb *cellCb, uint16_t ueId)
553 schSliceBasedAddUeToSchedule(cellCb, ueId);
556 /*******************************************************************
558 * @brief Processed UCI Indication
562 * Function : schSliceBasedSrUciInd
564 * Functionality: Processing of UCI indication specific to
565 * Slice Based scheduling
567 * @params[in] Pointer to Cell
571 * ****************************************************************/
572 void schSliceBasedSrUciInd(SchCellCb *cellCb, uint16_t ueId)
574 schSliceBasedAddUeToSchedule(cellCb, ueId);
577 /*******************************************************************
579 * @brief Processing of RACH Indication
583 * Function : schSliceBasedProcessRachInd
585 * Functionality: Processing of RACH Indication specific to
586 * Slice Based scheduling
588 * @params[in] Pointer to Cell Cb
592 * ****************************************************************/
593 void schSliceBasedProcessRachInd(SchCellCb *cellCb, uint16_t ueId)
595 schSliceBasedAddUeToSchedule(cellCb, ueId);
598 /*******************************************************************
600 * @brief Processing of DL HARQ Indication
604 * Function : SchSliceBasedDlHarqInd
611 * ****************************************************************/
612 void SchSliceBasedDlHarqInd()
617 /*******************************************************************
619 * @brief Processing of Paging indication
623 * Function : schSliceBasedPagingInd
630 * ****************************************************************/
631 void schSliceBasedPagingInd()
636 /*******************************************************************
638 * @brief Processing of RACH Resource Request
642 * Function : schSliceBasedRachRsrcReq
649 * ****************************************************************/
650 void schSliceBasedRachRsrcReq()
655 /*******************************************************************
657 * @brief Processing of RACH Resource Release
661 * Function : schSliceBasedRachRsrcRel
668 * ****************************************************************/
669 void schSliceBasedRachRsrcRel()
674 /*******************************************************************
676 * @brief Remove entry from HARQ retransmission list
680 * Function : schSliceBasedRemoveFrmDlHqRetxList
682 * Functionality: Remove entry from HARQ retransmission list
684 * @params[in] Pointer to UE
688 * ****************************************************************/
689 void schSliceBasedRemoveFrmDlHqRetxList(SchUeCb *ueCb, CmLList *node)
691 SchSliceBasedUeCb *schSpcUeCb;
693 schSpcUeCb = (SchSliceBasedUeCb *)ueCb->schSpcUeCb;
694 cmLListDelFrm(&schSpcUeCb->hqRetxCb.dlRetxHqList, node);
697 /*******************************************************************
699 * @brief Remove entry from HARQ retransmission list
703 * Function : schSliceBasedRemoveFrmUlHqRetxList
705 * Functionality: Remove entry from HARQ retransmission list
707 * @params[in] Pointer to UE
711 * ****************************************************************/
712 void schSliceBasedRemoveFrmUlHqRetxList(SchUeCb *ueCb, CmLList *node)
714 SchSliceBasedUeCb *schSpcUeCb;
716 schSpcUeCb = (SchSliceBasedUeCb *)ueCb->schSpcUeCb;
717 cmLListDelFrm(&schSpcUeCb->hqRetxCb.ulRetxHqList, node);
720 /*******************************************************************
722 * @brief Remove UE from Scheduling List
726 * Function : schSliceBasedRemoveUeFrmScheduleLst
728 * Functionality: Remove UE from Scheduling List
730 * @params[in] Pointer to Cell
734 * ****************************************************************/
735 void schSliceBasedRemoveUeFrmScheduleLst(SchCellCb *cell, CmLList *node)
737 SchSliceBasedCellCb *schSpcCell;
739 schSpcCell = (SchSliceBasedCellCb *)cell->schSpcCell;
740 SCH_FREE(node->node, sizeof(uint8_t));
741 deleteNodeFromLList(&schSpcCell->ueToBeScheduled, node);
744 /*******************************************************************
746 * @brief Handler to calculate TBS size for BSR requested
750 * Function : schSliceBasedCalculateUlTbs
752 * Functionality: Function will note the required TBS for each LCGIDX and use
753 * the Priority LCG List and RRM policy to allocate the TBS size
755 * @params [in] ueCb (Pointer to UE CB)
756 * [in] puschTime (Time slot where PUSCH will be sent)
757 * [in] symbLen (No of Symbols used for PUSCH transmission)
758 * [out] startPrb(Pointer to startPRB which will be calculated while
759 * finding the best Free Block)
760 * [out] totTBS(Pointer to total TBS size)
761 * [in] isRetx (to indicate retransmission)
762 * [in] hqP (UL Harq process pointer)
764 * @return uint8_t : ROK > Scheduling of UL grant is successful
765 * RFAILED > vice versa
767 * ****************************************************************/
768 uint8_t schSliceBasedCalculateUlTbs(SchUeCb *ueCb, SlotTimingInfo puschTime, uint8_t symbLen,\
769 uint16_t *startPrb, uint32_t *totTBS, bool isRetx, SchUlHqProcCb *hqP, SchSliceBasedHqProcCb *schSpcHqP)
772 CmLListCp *lcLL = NULLP;
773 uint16_t lcgIdx = 0, lcId =0, maxFreePRB = 0;
774 uint16_t rsvdDedicatedPRB;
779 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
781 if(ueCb->bsrInfo[lcgIdx].dataVol == 0)
786 /*TODO: lcgIdx and LCID has been implemented as one to one mapping.
787 * Need to check the mapping to figure out the LCID and lcgIdx once L2
788 * spec specifies any logic*/
790 if(ueCb->ulInfo.ulLcCtxt[lcId].isDedicated)
792 lcLL = &(schSpcHqP->lcCb.dedLcList);
793 rsvdDedicatedPRB = ueCb->ulInfo.ulLcCtxt[lcId].rsvdDedicatedPRB;
797 lcLL = &(schSpcHqP->lcCb.defLcList);
800 /*[Step2]: Update the reqPRB and Payloadsize for this LC in the appropriate List*/
801 if(updateLcListReqPRB(lcLL, lcId, ueCb->bsrInfo[lcgIdx].dataVol) != ROK)
803 DU_LOG("\nERROR --> SCH: LcgId:%d updation failed",lcId);
808 if ((schSpcHqP->lcCb.defLcList.count == 0) && (schSpcHqP->lcCb.dedLcList.count == 0))
810 if( (ueCb->srRcvd) || (isRetx) )
812 *startPrb = MAX_NUM_RB;
813 *totTBS = schCalcTbSize(UL_GRANT_SIZE);
815 /*Returning true when NO Grant is there for UE as this is not scheduling
820 maxFreePRB = searchLargestFreeBlock(ueCb->cellCb, puschTime, startPrb, DIR_UL);
822 /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
823 * the list based on RRM policy*/
825 /*Either this UE contains no reservedPRB pool fir dedicated S-NSSAI or
826 * Num of Free PRB available is not enough to reserve Dedicated PRBs*/
829 mcsIdx = ueCb->ueCfg.ulModInfo.mcsIndex;
830 if((schSpcHqP->lcCb.dedLcList.count == 0) || ((maxFreePRB < rsvdDedicatedPRB)))
832 schSpcHqP->lcCb.sharedNumPrb = maxFreePRB;
833 DU_LOG("\nDEBUG --> SCH : UL Only Default Slice is scheduled, sharedPRB Count:%d",\
834 schSpcHqP->lcCb.sharedNumPrb);
836 /*PRB Alloc for Default LCs*/
837 prbAllocUsingRRMPolicy(&(schSpcHqP->lcCb.defLcList), FALSE, mcsIdx, symbLen,\
838 &(schSpcHqP->lcCb.sharedNumPrb), NULLP, NULLP,&(ueCb->srRcvd));
842 schSpcHqP->lcCb.sharedNumPrb = maxFreePRB - rsvdDedicatedPRB;
844 /*PRB Alloc for Dedicated LCs*/
845 prbAllocUsingRRMPolicy(&(schSpcHqP->lcCb.dedLcList), TRUE, mcsIdx, symbLen,\
846 &(schSpcHqP->lcCb.sharedNumPrb), &(rsvdDedicatedPRB),\
847 NULLP, &(ueCb->srRcvd));
849 /*PRB Alloc for Default LCs*/
850 prbAllocUsingRRMPolicy(&(schSpcHqP->lcCb.defLcList), FALSE, mcsIdx, symbLen, \
851 &(schSpcHqP->lcCb.sharedNumPrb), &(rsvdDedicatedPRB),\
852 NULLP,&(ueCb->srRcvd));
855 /*[Step5]:Traverse each LCID in LcList to calculate the exact Scheduled Bytes
856 * using allocated BO per LC and Update dlMsgAlloc(BO report for MAC*/
857 if(schSpcHqP->lcCb.dedLcList.count != 0)
858 updateGrantSizeForBoRpt(&(schSpcHqP->lcCb.dedLcList), NULLP, ueCb->bsrInfo, totTBS);
860 updateGrantSizeForBoRpt(&(schSpcHqP->lcCb.defLcList), NULLP, ueCb->bsrInfo, totTBS);
862 /*Below case will hit if NO LC(s) are allocated due to resource crunch*/
867 DU_LOG("\nERROR --> SCH : NO FREE PRB!!");
871 /*Schedule the LC for next slot*/
872 DU_LOG("\nDEBUG --> SCH : No LC has been scheduled");
879 /*******************************************************************
881 * @brief Grants resources to LC in uplink
885 * Function : schProcessSrOrBsrReq
888 * Grants resources to LC in uplink
890 * @params[in] PDCCH Time
899 *******************************************************************/
900 uint8_t schSliceBasedScheduleUlLc(SlotTimingInfo dciTime, SlotTimingInfo puschTime, uint8_t startSymb , uint8_t symbLen, bool isRetx, SchUlHqProcCb **hqP)
903 SchSliceBasedHqProcCb *schSpcHqProcCb;
904 uint8_t ret = RFAILED;
905 uint16_t startPrb = 0;
906 uint32_t totDataReq = 0; /* in bytes */
908 SchPuschInfo *puschInfo;
909 DciInfo *dciInfo = NULLP;
911 cell = (*hqP)->hqEnt->cell;
912 ueCb = (*hqP)->hqEnt->ue;
913 schSpcHqProcCb = (SchSliceBasedHqProcCb *)(*hqP)->schSpcUlHqProcCb;
914 ret = schSliceBasedCalculateUlTbs(ueCb, puschTime, symbLen, &startPrb, &totDataReq, isRetx, *hqP, schSpcHqProcCb);
916 if(totDataReq > 0 && ret == ROK)
918 SCH_ALLOC(dciInfo, sizeof(DciInfo));
921 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
924 if(schSpcHqProcCb->lcCb.dedLcList.count != 0)
925 updateBsrAndLcList(&(schSpcHqProcCb->lcCb.dedLcList), ueCb->bsrInfo, RFAILED);
927 updateBsrAndLcList(&(schSpcHqProcCb->lcCb.defLcList), ueCb->bsrInfo, RFAILED);
931 cell->schDlSlotInfo[dciTime.slot]->ulGrant = dciInfo;
932 memset(dciInfo,0,sizeof(DciInfo));
934 /* Update PUSCH allocation */
935 if(schFillPuschAlloc(ueCb, puschTime, totDataReq, startSymb, symbLen, startPrb, isRetx, *hqP) == ROK)
937 if(cell->schUlSlotInfo[puschTime.slot]->schPuschInfo)
939 puschInfo = cell->schUlSlotInfo[puschTime.slot]->schPuschInfo;
940 if(puschInfo != NULLP)
942 /* Fill DCI for UL grant */
943 schFillUlDci(ueCb, puschInfo, dciInfo, isRetx, *hqP);
944 ueCb->srRcvd = false;
945 ueCb->bsrRcvd = false;
946 cell->schUlSlotInfo[puschTime.slot]->puschUe = ueCb->ueId;
947 if(schSpcHqProcCb->lcCb.dedLcList.count != 0)
948 updateBsrAndLcList(&(schSpcHqProcCb->lcCb.dedLcList), ueCb->bsrInfo, ROK);
949 updateBsrAndLcList(&(schSpcHqProcCb->lcCb.defLcList), ueCb->bsrInfo, ROK);
950 cmLListAdd2Tail(&(ueCb->hqUlmap[puschTime.slot]->hqList), &(*hqP)->ulSlotLnk);
955 if(schSpcHqProcCb->lcCb.dedLcList.count != 0)
956 updateBsrAndLcList(&(schSpcHqProcCb->lcCb.dedLcList), ueCb->bsrInfo, RFAILED);
957 updateBsrAndLcList(&(schSpcHqProcCb->lcCb.defLcList), ueCb->bsrInfo, RFAILED);
962 /*******************************************************************
964 * @brief Grants resources to LC in downlink
968 * Function : schSliceBasedScheduleDlLc
970 * Functionality: Grants resources to LC in uplink
972 * @params[in] PDCCH Time
977 * ****************************************************************/
978 uint32_t schSliceBasedScheduleDlLc(SlotTimingInfo pdcchTime, SlotTimingInfo pdschTime, uint8_t pdschNumSymbols, bool isRetx, SchDlHqProcCb **hqP)
980 SchSliceBasedHqProcCb *schSpcHqProcCb;
983 uint16_t startPrb = 0, maxFreePRB = 0;
985 uint32_t accumalatedSize = 0;
986 CmLListCp *lcLL = NULLP;
987 uint16_t rsvdDedicatedPRB = 0;
988 DlMsgSchInfo *dciSlotAlloc;
990 /* TX_PAYLOAD_HDR_LEN: Overhead which is to be Added once for any UE while estimating Accumulated TB Size
991 * Following flag added to keep the record whether TX_PAYLOAD_HDR_LEN is added to the first Node getting allocated.
992 * If both Dedicated and Default LC lists are present then First LC in Dedicated List will include this overhead
993 * else if only Default list is present then first node in this List will add this overhead len*/
994 bool isTxPayloadLenAdded = FALSE;
996 ueCb = (*hqP)->hqEnt->ue;
997 dciSlotAlloc = (*hqP)->hqEnt->cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueCb->ueId -1];
998 schSpcHqProcCb = (SchSliceBasedHqProcCb *)((*hqP)->schSpcDlHqProcCb);
1000 if (isRetx == FALSE)
1002 /*Re-Initalization per UE*/
1003 /* scheduled LC data fill */
1004 dciSlotAlloc->transportBlock[0].numLc = 0;
1005 isTxPayloadLenAdded = FALSE; /*Re-initlaize the flag for every UE*/
1006 accumalatedSize = 0;
1008 for(lcIdx = 0; lcIdx < MAX_NUM_LC; lcIdx++)
1010 if(ueCb->dlInfo.dlLcCtxt[lcIdx].bo)
1012 /*Check the LC is Dedicated or default and accordingly LCList will
1014 if(ueCb->dlInfo.dlLcCtxt[lcIdx].isDedicated)
1016 lcLL = &(schSpcHqProcCb->lcCb.dedLcList);
1017 rsvdDedicatedPRB = ueCb->dlInfo.dlLcCtxt[lcIdx].rsvdDedicatedPRB;
1021 lcLL = &(schSpcHqProcCb->lcCb.defLcList);
1024 /*[Step2]: Update the reqPRB and Payloadsize for this LC in the appropriate List*/
1025 if(updateLcListReqPRB(lcLL, ueCb->dlInfo.dlLcCtxt[lcIdx].lcId,\
1026 (ueCb->dlInfo.dlLcCtxt[lcIdx].bo + MAC_HDR_SIZE)) != ROK)
1028 DU_LOG("\nERROR --> SCH : Updation in LC List Failed");
1029 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
1030 if(!dciSlotAlloc->dlMsgPdschCfg)
1032 SCH_FREE(dciSlotAlloc, sizeof(DlMsgSchInfo));
1033 (*hqP)->hqEnt->cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueCb->ueId -1] = NULL;
1035 return accumalatedSize;
1040 if ((schSpcHqProcCb->lcCb.defLcList.count == 0) && (schSpcHqProcCb->lcCb.dedLcList.count == 0))
1042 DU_LOG("\nDEBUG --> SCH : No pending BO for any LC id\n");
1043 UNSET_ONE_BIT((*hqP)->hqEnt->ue->ueId, (*hqP)->hqEnt->cell->boIndBitMap);
1045 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
1046 if(!dciSlotAlloc->dlMsgPdschCfg)
1048 SCH_FREE(dciSlotAlloc, sizeof(DlMsgSchInfo));
1049 (*hqP)->hqEnt->cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueCb->ueId -1] = NULL;
1051 /*TRUE because this UE has nothing to be scheduled*/
1052 return accumalatedSize;
1056 /*[Step3]: Calculate Best FREE BLOCK with MAX PRB count*/
1057 maxFreePRB = searchLargestFreeBlock((*hqP)->hqEnt->cell, pdschTime, &startPrb, DIR_DL);
1059 /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
1060 * the list based on RRM policy*/
1062 /*Either this UE contains no reservedPRB pool fir dedicated S-NSSAI or
1063 * Num of Free PRB available is not enough to reserve Dedicated PRBs*/
1068 mcsIdx = ueCb->ueCfg.dlModInfo.mcsIndex;
1070 if((schSpcHqProcCb->lcCb.dedLcList.count == NULLP) || ((maxFreePRB < rsvdDedicatedPRB)))
1072 schSpcHqProcCb->lcCb.sharedNumPrb = maxFreePRB;
1073 DU_LOG("\nDEBUG --> SCH : DL Only Default Slice is scheduled, sharedPRB Count:%d",\
1074 schSpcHqProcCb->lcCb.sharedNumPrb);
1076 /*PRB Alloc for Default LCs*/
1077 prbAllocUsingRRMPolicy(&(schSpcHqProcCb->lcCb.defLcList), FALSE, mcsIdx, pdschNumSymbols,\
1078 &(schSpcHqProcCb->lcCb.sharedNumPrb), NULLP, &isTxPayloadLenAdded, NULLP);
1082 schSpcHqProcCb->lcCb.sharedNumPrb = maxFreePRB - rsvdDedicatedPRB;
1083 /*PRB Alloc for Dedicated LCs*/
1084 prbAllocUsingRRMPolicy(&(schSpcHqProcCb->lcCb.dedLcList), TRUE, mcsIdx, pdschNumSymbols,\
1085 &(schSpcHqProcCb->lcCb.sharedNumPrb), &(rsvdDedicatedPRB), &isTxPayloadLenAdded, NULLP);
1087 /*PRB Alloc for Default LCs*/
1088 prbAllocUsingRRMPolicy(&(schSpcHqProcCb->lcCb.defLcList), FALSE, mcsIdx, pdschNumSymbols, \
1089 &(schSpcHqProcCb->lcCb.sharedNumPrb), &(rsvdDedicatedPRB), &isTxPayloadLenAdded, NULLP);
1094 /*[Step5]:Traverse each LCID in LcList to calculate the exact Scheduled Bytes
1095 * using allocated BO per LC and Update dlMsgAlloc BO report for MAC */
1096 if (isRetx == FALSE)
1098 if(schSpcHqProcCb->lcCb.dedLcList.count != 0)
1099 updateGrantSizeForBoRpt(&(schSpcHqProcCb->lcCb.dedLcList), dciSlotAlloc, NULLP, &(accumalatedSize));
1101 updateGrantSizeForBoRpt(&(schSpcHqProcCb->lcCb.defLcList), dciSlotAlloc, NULLP, &(accumalatedSize));
1105 accumalatedSize = (*hqP)->tbInfo[0].tbSzReq;
1108 /*Below case will hit if NO LC(s) are allocated due to resource crunch*/
1109 if (!accumalatedSize)
1113 DU_LOG("\nERROR --> SCH : NO FREE PRB!!");
1117 /*Schedule the LC for next slot*/
1118 DU_LOG("\nDEBUG --> SCH : No LC has been scheduled");
1120 /* Not Freeing dlMsgAlloc as ZERO BO REPORT to be sent to RLC so that
1121 * Allocation can be done in next slot*/
1122 accumalatedSize = 0;
1125 return accumalatedSize;
1128 /*******************************************************************
1130 * @brief Scheduling of Slots in UL And DL
1134 * Function : schSliceBasedScheduleSlot
1136 * Functionality: Scheduling of slots in UL and DL specific to
1137 * Slice Based scheduling
1139 * @params[in] Pointer to Cell
1141 * Scheduler instance
1144 * ****************************************************************/
1145 void schSliceBasedScheduleSlot(SchCellCb *cell, SlotTimingInfo *slotInd, Inst schInst)
1147 SchSliceBasedCellCb *schSpcCell;
1148 SchSliceBasedUeCb *schSpcUeCb;
1149 SchDlHqProcCb *hqP = NULLP;
1150 SchUlHqProcCb *ulHqP = NULLP;
1151 CmLList *pendingUeNode;
1154 bool isRarPending = false, isRarScheduled = false;
1155 bool isMsg4Pending = false, isMsg4Scheduled = false;
1156 bool isDlMsgPending = false, isDlMsgScheduled = false;
1157 bool isUlGrantPending = false, isUlGrantScheduled = false;
1159 schSpcCell = (SchSliceBasedCellCb *)cell->schSpcCell;
1161 /* Select first UE in the linked list to be scheduled next */
1162 pendingUeNode = schSpcCell->ueToBeScheduled.first;
1165 if(pendingUeNode->node)
1167 ueId = *(uint8_t *)(pendingUeNode->node);
1168 schSpcUeCb = (SchSliceBasedUeCb *)cell->ueCb[ueId-1].schSpcUeCb;
1170 /* If RAR is pending for this UE, schedule PDCCH,PDSCH to send RAR and
1171 * PUSCH to receive MSG3 as per k0-k2 configuration*/
1172 if(cell->raReq[ueId-1] != NULLP)
1174 isRarPending = true;
1175 isRarScheduled = schProcessRaReq(schInst, cell, *slotInd, ueId);
1178 /*MSG3 retransmisson*/
1179 if(cell->raCb[ueId-1].retxMsg3HqProc)
1181 schMsg3RetxSchedulingForUe(&(cell->raCb[ueId-1]));
1184 /* If MSG4 is pending for this UE, schedule PDCCH,PDSCH to send MSG4 and
1185 * PUCCH to receive UL msg as per k0-k1 configuration */
1186 if (cell->ueCb[ueId-1].retxMsg4HqProc) //should work from dlmap later tbd
1188 /* Retransmission of MSG4 */
1189 isMsg4Pending = true;
1190 if(schProcessMsg4Req(cell, *slotInd, ueId, TRUE, &cell->ueCb[ueId-1].retxMsg4HqProc) == ROK)
1191 isMsg4Scheduled = true;
1195 /* First transmission of MSG4 */
1196 if(cell->raCb[ueId-1].msg4recvd)
1198 isMsg4Pending = true;
1199 if(schProcessMsg4Req(cell, *slotInd, ueId, FALSE, &cell->ueCb[ueId-1].msg4HqProc) == ROK)
1200 isMsg4Scheduled = true;
1202 /* If MSG4 scheduling failed, free the newly assigned HARQ process */
1203 if(!isMsg4Scheduled)
1204 schDlReleaseHqProcess(cell->ueCb[ueId-1].msg4HqProc);
1208 if(isRarPending || isMsg4Pending)
1210 /* If RAR or MSG is successfully scheduled then
1211 * remove UE from linked list since no pending msgs for this UE */
1212 if(isRarScheduled || isMsg4Scheduled)
1214 schSliceBasedRemoveUeFrmScheduleLst(cell, pendingUeNode);
1216 /* If RAR/MSG4 is pending but couldnt be scheduled then,
1217 * put this UE at the end of linked list to be scheduled later */
1220 cmLListAdd2Tail(&schSpcCell->ueToBeScheduled, cmLListDelFrm(&schSpcCell->ueToBeScheduled, pendingUeNode));
1225 if((cell->ueCb[ueId-1].ueDrxInfoPres == true) && (cell->ueCb[ueId-1].drxUeCb.drxDlUeActiveStatus != true))
1227 if(pendingUeNode->node)
1229 cmLListAdd2Tail(&schSpcCell->ueToBeScheduled, cmLListDelFrm(&schSpcCell->ueToBeScheduled, pendingUeNode));
1239 node = schSpcUeCb->hqRetxCb.dlRetxHqList.first;
1242 /* DL Data ReTransmisson */
1243 isDlMsgPending = true;
1244 isDlMsgScheduled = schFillBoGrantDlSchedInfo(cell, *slotInd, ueId, TRUE, ((SchDlHqProcCb**) &(node->node)));
1245 if(isDlMsgScheduled)
1248 schDrxStopDlHqRetxTmr(cell, &cell->ueCb[ueId-1], ((SchDlHqProcCb**) &(node->node)));
1250 schSliceBasedRemoveFrmDlHqRetxList(&cell->ueCb[ueId-1], node);
1255 /* DL Data new transmission */
1256 if((cell->boIndBitMap) & (1<<ueId))
1258 isDlMsgPending = true;
1259 isDlMsgScheduled = schFillBoGrantDlSchedInfo(cell, *slotInd, ueId, FALSE, &hqP);
1261 /* If DL scheduling failed, free the newly assigned HARQ process */
1262 if(!isDlMsgScheduled)
1263 schDlReleaseHqProcess(hqP);
1267 schHdlDrxInActvStrtTmr(cell, &cell->ueCb[ueId-1], PHY_DELTA_DL + SCHED_DELTA);
1273 /* Scheduling of UL grant */
1276 node = schSpcUeCb->hqRetxCb.ulRetxHqList.first;
1279 /* UL Data ReTransmisson */
1280 isUlGrantPending = true;
1281 isUlGrantScheduled = schProcessSrOrBsrReq(cell, *slotInd, ueId, TRUE, (SchUlHqProcCb**) &(node->node));
1282 if(isUlGrantScheduled)
1285 schDrxStopUlHqRetxTmr(cell, &cell->ueCb[ueId-1], ((SchUlHqProcCb**) &(node->node)));
1287 schSliceBasedRemoveFrmUlHqRetxList(&cell->ueCb[ueId-1], node);
1292 /* UL Data new transmission */
1293 if(cell->ueCb[ueId-1].srRcvd || cell->ueCb[ueId-1].bsrRcvd)
1295 isUlGrantPending = true;
1296 isUlGrantScheduled = schProcessSrOrBsrReq(cell, *slotInd, ueId, FALSE, &ulHqP);
1297 if(!isUlGrantScheduled)
1298 schUlReleaseHqProcess(ulHqP, FALSE);
1302 schHdlDrxInActvStrtTmr(cell, &cell->ueCb[ueId-1], PHY_DELTA_UL + SCHED_DELTA);
1308 if(!isUlGrantPending && !isDlMsgPending)
1310 /* No action required */
1312 else if((isUlGrantPending && !isUlGrantScheduled) || (isDlMsgPending && !isDlMsgScheduled))
1314 cmLListAdd2Tail(&schSpcCell->ueToBeScheduled, cmLListDelFrm(&schSpcCell->ueToBeScheduled, pendingUeNode));
1318 schSliceBasedRemoveUeFrmScheduleLst(cell, pendingUeNode);
1325 /*******************************************************************
1327 * @brief Initializes all function pointers to Slice Based function handler
1331 * Function : schSliceBasedAllApisInit
1333 * Functionality: Initializes all function pointers to Slice Based
1336 * @params[in] Function pointer array
1339 * ****************************************************************/
1340 void schSliceBasedAllApisInit(SchAllApis *allSliceBasedApi)
1342 /* Interface API function pointers */
1343 allSliceBasedApi->SchCellCfgReq = schSliceBasedCellCfgReq;
1344 allSliceBasedApi->SchCellDeleteReq = schSliceBasedCellDelReq;
1345 allSliceBasedApi->SchAddUeConfigReq = SchSliceBasedAddUeConfigReq;
1346 allSliceBasedApi->SchModUeConfigReq = SchSliceBasedModUeConfigReq;
1347 allSliceBasedApi->SchUeDeleteReq = SchSliceBasedUeDeleteReq;
1348 allSliceBasedApi->SchDlHarqInd = SchSliceBasedDlHarqInd;
1349 allSliceBasedApi->SchCrcInd = schSliceBasedProcessCrcInd;
1350 allSliceBasedApi->SchRachInd = schSliceBasedProcessRachInd;
1351 allSliceBasedApi->SchPagingInd = schSliceBasedPagingInd;
1352 allSliceBasedApi->SchRachRsrcReq = schSliceBasedRachRsrcReq;
1353 allSliceBasedApi->SchRachRsrcRel = schSliceBasedRachRsrcRel;
1354 allSliceBasedApi->SchDlRlcBoInfo = schSliceBasedDlRlcBoInfo;
1355 allSliceBasedApi->SchSrUciInd = schSliceBasedSrUciInd;
1356 allSliceBasedApi->SchBsr = schSliceBasedBsr;
1358 /* Internal API function pointers */
1359 allSliceBasedApi->SchAddToDlHqRetxList = schSliceBasedAddToDlHqRetxList;
1360 allSliceBasedApi->SchAddToUlHqRetxList = schSliceBasedAddToUlHqRetxList;
1361 allSliceBasedApi->SchRemoveFrmDlHqRetxList = schSliceBasedRemoveFrmDlHqRetxList;
1362 allSliceBasedApi->SchRemoveFrmUlHqRetxList = schSliceBasedRemoveFrmUlHqRetxList;
1363 allSliceBasedApi->SchAddUeToSchedule = schSliceBasedAddUeToSchedule;
1364 allSliceBasedApi->SchRemoveUeFrmScheduleLst = schSliceBasedRemoveUeFrmScheduleLst;
1365 allSliceBasedApi->SchInitDlHqProcCb = schSliceBasedInitDlHqProcCb;
1366 allSliceBasedApi->SchInitUlHqProcCb = schSliceBasedInitUlHqProcCb;
1367 allSliceBasedApi->SchFreeDlHqProcCb = schSliceBasedFreeDlHqProcCb;
1368 allSliceBasedApi->SchFreeUlHqProcCb = schSliceBasedFreeUlHqProcCb;
1369 allSliceBasedApi->SchDeleteDlHqProcCb = schSliceBasedDeleteDlHqProcCb;
1370 allSliceBasedApi->SchDeleteUlHqProcCb = schSliceBasedDeleteUlHqProcCb;
1371 allSliceBasedApi->SchScheduleSlot = schSliceBasedScheduleSlot;
1372 allSliceBasedApi->SchScheduleDlLc = schSliceBasedScheduleDlLc;
1373 allSliceBasedApi->SchScheduleUlLc = schSliceBasedScheduleUlLc;
1375 /**********************************************************************
1377 **********************************************************************/