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 Entry point fucntions for slot indications
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"
45 SchMacDlAllocFunc schMacDlAllocOpts[] =
52 /*******************************************************************
54 * @brief Handles sending DL broadcast alloc to MAC
58 * Function : sendDlAllocToMac
61 * Sends DL Broadcast Resource Allocation to MAC from SCH
64 * @return ROK - success
67 * ****************************************************************/
68 uint8_t sendDlAllocToMac(DlSchedInfo *dlSchedInfo, Inst inst)
72 memset(&pst, 0, sizeof(Pst));
73 FILL_PST_SCH_TO_MAC(pst, inst);
74 pst.event = EVENT_DL_SCH_INFO;
76 return(*schMacDlAllocOpts[pst.selector])(&pst, dlSchedInfo);
80 /*******************************************************************
82 * @brief Handles slot indication at SCH
86 * Function : schCalcSlotValues
89 * Handles TTI indication received from PHY
92 * @return ROK - success
95 * ****************************************************************/
96 void schCalcSlotValues(SlotTimingInfo slotInd, SchSlotValue *schSlotValue)
98 /****************************************************************
99 * PHY_DELTA - the physical layer delta *
100 * SCHED_DELTA - scheduler schedules one slot ahead *
101 * BO_DELTA - this delay is considered for BO response and *
102 * RLC buffer packet to received at MAC *
103 * lower-mac (FAPI filling) will be working on PHY_DELTA *
104 * brdcast scheduler will working on PHY_DELTA + SCHED_DELTA *
105 * RAR scheduler will working on PHY_DELTA + SCHED_DELTA *
106 * msg4 scheduler will working on PHY_DELTA + SCHED_DELTA *
107 * dedicated DL msg scheduler will working *
108 * on PHY_DELTA + SCHED_DELTA + BO_DELTA *
109 ****************************************************************/
111 ADD_DELTA_TO_TIME(slotInd, schSlotValue->currentTime, PHY_DELTA_DL);
112 ADD_DELTA_TO_TIME(slotInd, schSlotValue->broadcastTime, PHY_DELTA_DL + SCHED_DELTA);
113 ADD_DELTA_TO_TIME(slotInd, schSlotValue->rarTime, PHY_DELTA_DL + SCHED_DELTA);
114 ADD_DELTA_TO_TIME(slotInd, schSlotValue->dlMsgTime, PHY_DELTA_DL + SCHED_DELTA);
117 /*******************************************************************
119 * @brief Checks if a slot is to be scheduled for SSB transmission
123 * Function : schCheckSsbOcc
126 * Checks if a slot is to be scheduled for SSB transmission
128 * @params[in] SlotTimingInfo slotTime
130 * @return Pdu transmission
132 * ****************************************************************/
133 PduTxOccsaion schCheckSsbOcc(SchCellCb *cell, SlotTimingInfo slotTime)
137 ssb_rep = cell->cellCfg.ssbSchCfg.ssbPeriod;
139 /* Identify SSB ocassion*/
140 if ((slotTime.sfn % SCH_MIB_TRANS == 0) && (slotTime.slot ==0))
142 return NEW_TRANSMISSION;
144 else if(cell->firstSsbTransmitted)
146 if((ssb_rep == 5) && ((slotTime.slot == 0 || slotTime.slot == 10)))
148 else if((slotTime.sfn % (ssb_rep/10) == 0) && slotTime.slot == 0)
151 /* not SSB occassion */
152 return NO_TRANSMISSION;
155 /*******************************************************************
157 * @brief Checks if a slot is to be scheduled for SIB1 transmission
161 * Function : schCheckSib1Occ
164 * Checks if a slot is to be scheduled for SIB1 transmission
166 * @params[in] SlotTimingInfo slotTime
168 * @return Pdu transmission
170 * ****************************************************************/
171 PduTxOccsaion schCheckSib1Occ(SchCellCb *cell, SlotTimingInfo slotTime)
173 /* Identify SIB1 occasions */
174 if((slotTime.sfn % SCH_SIB1_TRANS == 0) && (slotTime.slot ==0))
176 return NEW_TRANSMISSION;
178 else if(cell->firstSib1Transmitted)
180 if((slotTime.sfn % (cell->cellCfg.sib1SchCfg.sib1RepetitionPeriod/10) == 0) &&
181 (slotTime.slot == 0))
186 /* not SIB1 occassion */
187 return NO_TRANSMISSION;
190 /*******************************************************************
196 * Function : schFillBoGrantDlSchedInfo
202 * @return ROK - success
205 * ****************************************************************/
206 uint8_t schFillBoGrantDlSchedInfo(SchCellCb *cell, DlSchedInfo *dlSchedInfo, DlMsgAlloc *dlMsgAlloc)
208 uint8_t ueIdx = 0, lcIdx = 0, pdschSymbols = 0, k1 = 0;
209 uint16_t slot = 0, startPrb = 0, maxFreePRB = 0,dlToUlAckIdx =0;
210 uint16_t crnti = 0, mcsIdx = 0;
211 uint32_t accumalatedSize = 0;
212 SchUeCb *ueCb = NULLP;
213 CmLListCp *lcLL = NULLP;
214 SchPdschConfig pdschCfg;
215 SlotTimingInfo pucchTime;
216 SchPucchCfg *schPucchCfg;
218 /* TX_PAYLOAD_HDR_LEN: Overhead which is to be Added once for any UE while estimating Accumulated TB Size
219 * Following flag added to keep the record whether TX_PAYLOAD_HDR_LEN is added to the first Node getting allocated.
220 * If both Dedicated and Default LC lists are present then First LC in Dedicated List will include this overhead
221 * else if only Default list is present then first node in this List will add this overhead len*/
222 bool isTxPayloadLenAdded = FALSE;
224 while(cell->boIndBitMap)
226 slot = dlSchedInfo->schSlotValue.dlMsgTime.slot;
228 GET_RIGHT_MOST_SET_BIT(cell->boIndBitMap, ueIdx);
229 GET_CRNTI(crnti,ueIdx);
230 ueCb = &cell->ueCb[ueIdx-1];
232 /* allocate PDCCH and PDSCH resources for the ue */
233 SCH_ALLOC(dlMsgAlloc, sizeof(DlMsgAlloc));
236 DU_LOG("\nERROR --> SCH : Memory Allocation failed for ded DL msg alloc");
239 memset(dlMsgAlloc, 0, sizeof(DlMsgAlloc));
240 dlSchedInfo->dlMsgAlloc = dlMsgAlloc;
241 dlMsgAlloc->crnti = crnti;
243 pdschCfg = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
244 mcsIdx = ueCb->ueCfg.dlModInfo.mcsIndex;
246 /*TODO: K0Index must be used instead of 0th Index in
247 * pdschCfg.timeDomRsrcAllociList*/
248 pdschSymbols = pdschCfg.timeDomRsrcAllociList[0].symbolLength;
249 /* Dl ded Msg info is copied, this was earlier filled in macSchDlRlcBoInfo */
250 memcpy(&dlMsgAlloc->dlMsgInfo, &cell->schDlSlotInfo[slot]->dlMsgAlloc->dlMsgInfo, \
253 /*Re-Initalization per UE*/
254 /* scheduled LC data fill */
255 dlMsgAlloc->numLc = 0;
256 isTxPayloadLenAdded = FALSE; /*Re-initlaize the flag for every UE*/
259 for(lcIdx = 0; lcIdx < MAX_NUM_LC; lcIdx++)
261 if(ueCb->dlInfo.dlLcCtxt[lcIdx].bo)
263 /*Check the LC is Dedicated or default and accordingly LCList will
265 if(ueCb->dlInfo.dlLcCtxt[lcIdx].isDedicated)
267 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
271 lcLL = &(ueCb->dlLcPrbEst.defLcList);
274 /*[Step2]: Update the reqPRB and Payloadsize for this LC in the appropriate List*/
275 if(updateLcListReqPRB(lcLL, ueCb->dlInfo.dlLcCtxt[lcIdx].lcId,\
276 (ueCb->dlInfo.dlLcCtxt[lcIdx].bo + MAC_HDR_SIZE)) != ROK)
278 DU_LOG("\nERROR --> SCH : Updation in LC List Failed");
279 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
280 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
281 dlSchedInfo->dlMsgAlloc = NULLP;
285 ueCb->dlInfo.dlLcCtxt[lcIdx].bo = 0;
289 if ((ueCb->dlLcPrbEst.defLcList.count == 0) && \
290 ((ueCb->dlLcPrbEst.dedLcInfo != NULL) && (ueCb->dlLcPrbEst.dedLcInfo->dedLcList.count == 0)))
292 DU_LOG("\nDEBUG --> SCH : No pending BO for any LC id\n");
293 UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
294 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
295 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
296 dlSchedInfo->dlMsgAlloc = NULLP;
300 /*[Step3]: Calculate Best FREE BLOCK with MAX PRB count*/
301 maxFreePRB = searchLargestFreeBlockDL(cell, dlSchedInfo->schSlotValue.dlMsgTime, &startPrb);
303 /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
304 * the list based on RRM policy*/
306 /*Either this UE contains no reservedPRB pool fir dedicated S-NSSAI or
307 * Num of Free PRB available is not enough to reserve Dedicated PRBs*/
310 if((ueCb->dlLcPrbEst.dedLcInfo == NULLP)
311 || ((maxFreePRB < ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB)))
313 ueCb->dlLcPrbEst.sharedNumPrb = maxFreePRB;
314 DU_LOG("\nWARNING --> SCH : Only Default Slice is scheduled, sharedPRB Count:%d",\
315 ueCb->dlLcPrbEst.sharedNumPrb);
317 /*PRB Alloc for Default LCs*/
318 prbAllocUsingRRMPolicy(&(ueCb->dlLcPrbEst.defLcList), FALSE, mcsIdx, pdschSymbols,\
319 &(ueCb->dlLcPrbEst.sharedNumPrb), NULLP, &isTxPayloadLenAdded);
323 ueCb->dlLcPrbEst.sharedNumPrb = maxFreePRB - ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB;
325 /*PRB Alloc for Dedicated LCs*/
326 prbAllocUsingRRMPolicy(&(ueCb->dlLcPrbEst.dedLcInfo->dedLcList), TRUE, mcsIdx, pdschSymbols,\
327 &(ueCb->dlLcPrbEst.sharedNumPrb), &(ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB), &isTxPayloadLenAdded);
329 /*PRB Alloc for Default LCs*/
330 prbAllocUsingRRMPolicy(&(ueCb->dlLcPrbEst.defLcList), FALSE, mcsIdx, pdschSymbols, \
331 &(ueCb->dlLcPrbEst.sharedNumPrb), &(ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB), &isTxPayloadLenAdded);
335 /*[Step5]:Traverse each LCID in LcList to calculate the exact Scheduled Bytes
336 * using allocated BO per LC and Update dlMsgAlloc(BO report for MAC*/
337 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
338 updateGrantSizeForBoRpt(&(ueCb->dlLcPrbEst.dedLcInfo->dedLcList), dlMsgAlloc, &(accumalatedSize));
340 updateGrantSizeForBoRpt(&(ueCb->dlLcPrbEst.defLcList), dlMsgAlloc, &(accumalatedSize));
342 /*Below case will hit if NO LC(s) are allocated due to resource crunch*/
343 if (!accumalatedSize)
347 DU_LOG("\nERROR --> SCH : NO FREE PRB!!");
351 /*Schedule the LC for next slot*/
352 DU_LOG("\nDEBUG --> SCH : No LC has been scheduled");
354 /*Not Freeing dlMsgAlloc as ZERO BO REPORT to be sent to RLC so that
355 * Allocation can be done in next slot*/
359 /*[Step6]: pdcch and pdsch data is filled */
360 if((schDlRsrcAllocDlMsg(cell, dlSchedInfo->schSlotValue.dlMsgTime, \
361 crnti, accumalatedSize, dlMsgAlloc, startPrb)) != ROK)
363 DU_LOG("\nERROR --> SCH : Scheduling of DL dedicated message failed");
364 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
365 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
366 dlSchedInfo->dlMsgAlloc = NULLP;
370 dlMsgAlloc->pduPres = BOTH;
372 /* TODO : Update the scheduling byte report for multiple LC based on QCI
374 /* As of now, the total number of bytes scheduled for a slot is divided
375 * equally amongst all LC with pending data. This is avoid starving of any
379 accumalatedSize = accumalatedSize/dlMsgAlloc->numLc;
380 for(lcIdx = 0; lcIdx < dlMsgAlloc->numLc; lcIdx ++)
381 dlMsgAlloc->lcSchInfo[lcIdx].schBytes = accumalatedSize;
384 /* TODO : Correct values of K1 will be used from K0K1 table */
385 if(cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres)
387 schPucchCfg = &(cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg);
388 if(schPucchCfg->dlDataToUlAck)
390 for(dlToUlAckIdx = 0; dlToUlAckIdx < schPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; dlToUlAckIdx++)
392 //For now considering only the first value in the list
393 k1 = schPucchCfg->dlDataToUlAck->dlDataToUlAckList[dlToUlAckIdx];
398 ADD_DELTA_TO_TIME(dlSchedInfo->schSlotValue.dlMsgTime, pucchTime, k1);
399 schAllocPucchResource(cell, pucchTime, crnti);
401 /* after allocation is done, unset the bo bit for that ue */
402 UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
408 /*******************************************************************
410 * @brief Handles slot indication at SCH
414 * Function : schProcessSlotInd
417 * Handles TTI indication received from PHY
420 * @return ROK - success
423 * ****************************************************************/
424 uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst schInst)
426 uint8_t ueId, ueIdx, lcgIdx, ret = ROK;
428 bool isRarScheduled = false;
429 CmLList *pendingUeNode;
430 DlSchedInfo dlSchedInfo;
431 DlBrdcstAlloc *dlBrdcstAlloc = NULLP;
432 DlMsgAlloc *dlMsgAlloc = NULLP;
433 SchCellCb *cell = NULLP;
435 memset(&dlSchedInfo,0,sizeof(DlSchedInfo));
436 dlSchedInfo.dlMsgAlloc = NULLP;
437 schCalcSlotValues(*slotInd, &dlSchedInfo.schSlotValue);
438 dlBrdcstAlloc = &dlSchedInfo.brdcstAlloc;
439 dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
440 dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
442 cell = schCb[schInst].cells[schInst];
445 DU_LOG("\nERROR --> SCH : Cell Does not exist");
448 memcpy(&cell->slotInfo, slotInd, sizeof(SlotTimingInfo));
449 dlBrdcstAlloc->ssbIdxSupported = SSB_IDX_SUPPORTED;
451 dlSchedInfo.cellId = cell->cellId;
452 slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
454 /* Check for SSB occassion */
455 dlBrdcstAlloc->ssbTrans = schCheckSsbOcc(cell, dlSchedInfo.schSlotValue.broadcastTime);
456 if(dlBrdcstAlloc->ssbTrans)
458 if(schBroadcastSsbAlloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
460 DU_LOG("\nERROR --> SCH : schBroadcastSsbAlloc failed");
461 dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
465 dlSchedInfo.isBroadcastPres = true;
466 if((dlBrdcstAlloc->ssbTrans == NEW_TRANSMISSION) && (!cell->firstSsbTransmitted))
467 cell->firstSsbTransmitted = true;
471 /* Check for SIB1 occassion */
472 dlBrdcstAlloc->sib1Trans = schCheckSib1Occ(cell, dlSchedInfo.schSlotValue.broadcastTime);
473 if(dlBrdcstAlloc->sib1Trans)
475 if(schBroadcastSib1Alloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
477 DU_LOG("\nERROR --> SCH : schBroadcastSib1Alloc failed");
478 dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
482 dlSchedInfo.isBroadcastPres = true;
483 if((dlBrdcstAlloc->sib1Trans == NEW_TRANSMISSION) && (!cell->firstSib1Transmitted))
484 cell->firstSib1Transmitted = true;
488 /* Select first UE in the linked list to be scheduled next */
489 pendingUeNode = cell->ueToBeScheduled.first;
492 ueId = *(uint8_t *)(pendingUeNode->node);
494 /* Check for Pending RA Requests */
495 if(cell->raReq[ueId-1] != NULLP)
497 isRarScheduled = schProcessRaReq(cell, *slotInd, ueId);
498 /* If RAR scheduled for this UE, remove from linked list since no
499 * pending msgs for this UE */
502 SCH_FREE(pendingUeNode->node, sizeof(uint8_t));
503 deleteNodeFromLList(&cell->ueToBeScheduled, pendingUeNode);
505 /* If RAR couldnt be scheduled, put this UE at the end of linked
506 * list to be scheduled later */
509 cmLListAdd2Tail(&cell->ueToBeScheduled, cmLListDelFrm(&cell->ueToBeScheduled, pendingUeNode));
515 for(ueIdx=0; ueIdx<MAX_NUM_UE; ueIdx++)
517 if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarAlloc[ueIdx] != NULLP)
519 slot = dlSchedInfo.schSlotValue.rarTime.slot;
520 dlSchedInfo.rarAlloc[ueIdx] = cell->schDlSlotInfo[slot]->rarAlloc[ueIdx];
521 cell->schDlSlotInfo[slot]->rarAlloc[ueIdx] = NULLP;
525 schProcessMsg4Req(cell, *slotInd);
528 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc != NULLP) &&
529 (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc->dlMsgInfo.isMsg4Pdu))
531 slot = dlSchedInfo.schSlotValue.dlMsgTime.slot;
532 dlSchedInfo.dlMsgAlloc = cell->schDlSlotInfo[slot]->dlMsgAlloc;
533 cell->schDlSlotInfo[slot]->dlMsgAlloc = NULLP;
536 /* Check if UL grant must be sent in this slot for a SR/BSR that had been received */
537 for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
539 uint32_t totDataReq = 0; /* in bytes */
540 DciInfo *dciInfo = NULLP;
541 SchUeCb *ueCb = NULLP;
543 ueCb = &cell->ueCb[ueIdx];
547 totDataReq = UL_GRANT_SIZE; /*fixing so that all control msgs can be handled in SR */
548 ueCb->srRcvd = false;
551 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
553 totDataReq+= ueCb->bsrInfo[lcgIdx].dataVol;
554 ueCb->bsrInfo[lcgIdx].dataVol = 0;
556 if(totDataReq > 0) /* UL grant must be provided for this UE in this slot */
558 SchPuschInfo schPuschInfo;
559 memset(&schPuschInfo, 0, sizeof(SchPuschInfo));
561 SCH_ALLOC(dciInfo, sizeof(DciInfo));
564 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
567 memset(dciInfo,0,sizeof(DciInfo));
569 /* update the SFN and SLOT */
570 memcpy(&dlSchedInfo.schSlotValue.ulDciTime, slotInd, sizeof(SlotTimingInfo));
572 /* Update PUSCH allocation */
573 schFillPuschAlloc(ueCb, dlSchedInfo.schSlotValue.ulDciTime, totDataReq, &schPuschInfo);
575 /* Fill DCI for UL grant */
576 schFillUlDci(ueCb, schPuschInfo, dciInfo);
577 memcpy(&dciInfo->slotIndInfo, &dlSchedInfo.schSlotValue.ulDciTime, sizeof(SlotTimingInfo));
578 dlSchedInfo.ulGrant = dciInfo;
582 /* Check for pending BO grant for LC */
583 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc != NULLP) &&
584 (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc->dlMsgInfo.isMsg4Pdu))
586 if((schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc)) != ROK)
588 DU_LOG("\nERROR --> SCH : DL MSG scheduling failed");
589 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc, sizeof(DlMsgAlloc));
593 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
594 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc, sizeof(DlMsgAlloc));
597 /* Send msg to MAC */
598 ret = sendDlAllocToMac(&dlSchedInfo, schInst);
601 DU_LOG("\nERROR --> SCH : Sending DL Broadcast allocation from SCH to MAC failed");
605 schInitDlSlot(cell->schDlSlotInfo[slot]);
606 schUlResAlloc(cell, schInst);
611 /**********************************************************************
613 **********************************************************************/