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;
209 uint16_t slot = 0, startPrb = 0, maxFreePRB = 0;
210 uint16_t crnti = 0, mcsIdx = 0;
211 uint32_t accumalatedSize = 0;
212 SchUeCb *ueCb = NULLP;
213 CmLListCp *lcLL = NULLP;
214 SchPdschConfig pdschCfg;
216 /* TX_PAYLOAD_HDR_LEN: Overhead which is to be Added once for any UE while estimating Accumulated TB Size
217 * Following flag added to keep the record whether TX_PAYLOAD_HDR_LEN is added to the first Node getting allocated.
218 * If both Dedicated and Default LC lists are present then First LC in Dedicated List will include this overhead
219 * else if only Default list is present then first node in this List will add this overhead len*/
220 bool isTxPayloadLenAdded = FALSE;
222 while(cell->boIndBitMap)
224 slot = dlSchedInfo->schSlotValue.dlMsgTime.slot;
226 GET_RIGHT_MOST_SET_BIT(cell->boIndBitMap, ueIdx);
227 GET_CRNTI(crnti,ueIdx);
228 ueCb = &cell->ueCb[ueIdx-1];
230 /* allocate PDCCH and PDSCH resources for the ue */
231 SCH_ALLOC(dlMsgAlloc, sizeof(DlMsgAlloc));
234 DU_LOG("\nERROR --> SCH : Memory Allocation failed for ded DL msg alloc");
237 memset(dlMsgAlloc, 0, sizeof(DlMsgAlloc));
238 dlSchedInfo->dlMsgAlloc = dlMsgAlloc;
239 dlMsgAlloc->crnti = crnti;
241 pdschCfg = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
242 mcsIdx = ueCb->ueCfg.dlModInfo.mcsIndex;
244 /*TODO: K0Index must be used instead of 0th Index in
245 * pdschCfg.timeDomRsrcAllociList*/
246 pdschSymbols = pdschCfg.timeDomRsrcAllociList[0].symbolLength;
247 /* Dl ded Msg info is copied, this was earlier filled in macSchDlRlcBoInfo */
248 memcpy(&dlMsgAlloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
251 /*Re-Initalization per UE*/
252 /* scheduled LC data fill */
253 dlMsgAlloc->numLc = 0;
254 isTxPayloadLenAdded = FALSE; /*Re-initlaize the flag for every UE*/
257 for(lcIdx = 0; lcIdx < MAX_NUM_LC; lcIdx++)
259 if(ueCb->dlInfo.dlLcCtxt[lcIdx].bo)
261 /*Check the LC is Dedicated or default and accordingly LCList will
263 if(ueCb->dlInfo.dlLcCtxt[lcIdx].isDedicated)
265 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
269 lcLL = &(ueCb->dlLcPrbEst.defLcList);
272 /*[Step2]: Update the reqPRB and Payloadsize for this LC in the appropriate List*/
273 if(updateLcListReqPRB(lcLL, ueCb->dlInfo.dlLcCtxt[lcIdx].lcId,\
274 (ueCb->dlInfo.dlLcCtxt[lcIdx].bo + MAC_HDR_SIZE)) != ROK)
276 DU_LOG("\nERROR --> SCH : Updation in LC List Failed");
277 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
278 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
279 dlSchedInfo->dlMsgAlloc = NULLP;
283 ueCb->dlInfo.dlLcCtxt[lcIdx].bo = 0;
287 if ((ueCb->dlLcPrbEst.defLcList.count == 0) && \
288 ((ueCb->dlLcPrbEst.dedLcInfo != NULL) && (ueCb->dlLcPrbEst.dedLcInfo->dedLcList.count == 0)))
290 DU_LOG("\nDEBUG --> SCH : No pending BO for any LC id\n");
291 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
292 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
293 dlSchedInfo->dlMsgAlloc = NULLP;
297 /*[Step3]: Calculate Best FREE BLOCK with MAX PRB count*/
298 maxFreePRB = searchLargestFreeBlockDL(cell, dlSchedInfo->schSlotValue.dlMsgTime, &startPrb);
300 /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
301 * the list based on RRM policy*/
303 /*Either this UE contains no reservedPRB pool fir dedicated S-NSSAI or
304 * Num of Free PRB available is not enough to reserve Dedicated PRBs*/
307 if((ueCb->dlLcPrbEst.dedLcInfo == NULLP)
308 || ((maxFreePRB < ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB)))
310 ueCb->dlLcPrbEst.sharedNumPrb = maxFreePRB;
311 DU_LOG("\nWARNING --> SCH : Only Default Slice is scheduled, sharedPRB Count:%d",\
312 ueCb->dlLcPrbEst.sharedNumPrb);
314 /*PRB Alloc for Default LCs*/
315 prbAllocUsingRRMPolicy(&(ueCb->dlLcPrbEst.defLcList), FALSE, mcsIdx, pdschSymbols,\
316 &(ueCb->dlLcPrbEst.sharedNumPrb), NULLP, &isTxPayloadLenAdded);
320 ueCb->dlLcPrbEst.sharedNumPrb = maxFreePRB - ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB;
322 /*PRB Alloc for Dedicated LCs*/
323 prbAllocUsingRRMPolicy(&(ueCb->dlLcPrbEst.dedLcInfo->dedLcList), TRUE, mcsIdx, pdschSymbols,\
324 &(ueCb->dlLcPrbEst.sharedNumPrb), &(ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB), &isTxPayloadLenAdded);
326 /*PRB Alloc for Default LCs*/
327 prbAllocUsingRRMPolicy(&(ueCb->dlLcPrbEst.defLcList), FALSE, mcsIdx, pdschSymbols, \
328 &(ueCb->dlLcPrbEst.sharedNumPrb), &(ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB), &isTxPayloadLenAdded);
332 /*[Step5]:Traverse each LCID in LcList to calculate the exact Scheduled Bytes
333 * using allocated BO per LC and Update dlMsgAlloc(BO report for MAC*/
334 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
335 updateGrantSizeForBoRpt(&(ueCb->dlLcPrbEst.dedLcInfo->dedLcList), dlMsgAlloc, &(accumalatedSize));
337 updateGrantSizeForBoRpt(&(ueCb->dlLcPrbEst.defLcList), dlMsgAlloc, &(accumalatedSize));
339 /*Below case will hit if NO LC(s) are allocated due to resource crunch*/
340 if (!accumalatedSize)
344 DU_LOG("\nERROR --> SCH : NO FREE PRB!!");
348 /*Schedule the LC for next slot*/
349 DU_LOG("\nDEBUG --> SCH : No LC has been scheduled");
351 /*Not Freeing dlMsgAlloc as ZERO BO REPORT to be sent to RLC so that
352 * Allocation can be done in next slot*/
355 /*[Step6]: pdcch and pdsch data is filled */
356 if((schDlRsrcAllocDlMsg(cell, dlSchedInfo->schSlotValue.dlMsgTime, \
357 crnti, accumalatedSize, dlMsgAlloc, startPrb)) != ROK)
359 DU_LOG("\nERROR --> SCH : Scheduling of DL dedicated message failed");
360 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
361 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
362 dlSchedInfo->dlMsgAlloc = NULLP;
366 /* TODO : Update the scheduling byte report for multiple LC based on QCI
368 /* As of now, the total number of bytes scheduled for a slot is divided
369 * equally amongst all LC with pending data. This is avoid starving of any
373 accumalatedSize = accumalatedSize/dlMsgAlloc->numLc;
374 for(lcIdx = 0; lcIdx < dlMsgAlloc->numLc; lcIdx ++)
375 dlMsgAlloc->lcSchInfo[lcIdx].schBytes = accumalatedSize;
378 schAllocPucchResource(cell, dlMsgAlloc->crnti, slot);
380 /* after allocation is done, unset the bo bit for that ue */
381 UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
387 /*******************************************************************
389 * @brief Handles slot indication at SCH
393 * Function : schProcessSlotInd
396 * Handles TTI indication received from PHY
399 * @return ROK - success
402 * ****************************************************************/
403 uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst schInst)
405 uint8_t ueIdx, lcgIdx, ret = ROK;
407 DlSchedInfo dlSchedInfo;
408 DlBrdcstAlloc *dlBrdcstAlloc = NULLP;
409 DlMsgAlloc *msg4Alloc = NULLP;
410 DlMsgAlloc *dlMsgAlloc = NULLP;
411 SchCellCb *cell = NULLP;
413 memset(&dlSchedInfo,0,sizeof(DlSchedInfo));
414 dlSchedInfo.dlMsgAlloc = NULLP;
415 schCalcSlotValues(*slotInd, &dlSchedInfo.schSlotValue);
416 dlBrdcstAlloc = &dlSchedInfo.brdcstAlloc;
417 dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
418 dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
420 cell = schCb[schInst].cells[schInst];
423 DU_LOG("\nERROR --> SCH : Cell Does not exist");
426 memcpy(&cell->slotInfo, slotInd, sizeof(SlotTimingInfo));
427 dlBrdcstAlloc->ssbIdxSupported = SSB_IDX_SUPPORTED;
429 dlSchedInfo.cellId = cell->cellId;
431 slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
433 /* Check for SSB occassion */
434 dlBrdcstAlloc->ssbTrans = schCheckSsbOcc(cell, dlSchedInfo.schSlotValue.broadcastTime);
435 if(dlBrdcstAlloc->ssbTrans)
437 if(schBroadcastSsbAlloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
439 DU_LOG("\nERROR --> SCH : schBroadcastSsbAlloc failed");
440 dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
444 dlSchedInfo.isBroadcastPres = true;
445 if((dlBrdcstAlloc->ssbTrans == NEW_TRANSMISSION) && (!cell->firstSsbTransmitted))
446 cell->firstSsbTransmitted = true;
450 /* Check for SIB1 occassion */
451 dlBrdcstAlloc->sib1Trans = schCheckSib1Occ(cell, dlSchedInfo.schSlotValue.broadcastTime);
452 if(dlBrdcstAlloc->sib1Trans)
454 if(schBroadcastSib1Alloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
456 DU_LOG("\nERROR --> SCH : schBroadcastSib1Alloc failed");
457 dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
461 dlSchedInfo.isBroadcastPres = true;
462 if((dlBrdcstAlloc->sib1Trans == NEW_TRANSMISSION) && (!cell->firstSib1Transmitted))
463 cell->firstSib1Transmitted = true;
467 /* Check for Pending RA Requests */
468 schProcessRaReq(*slotInd, cell);
471 if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarAlloc != NULLP)
473 slot = dlSchedInfo.schSlotValue.rarTime.slot;
474 dlSchedInfo.rarAlloc = cell->schDlSlotInfo[slot]->rarAlloc;
475 cell->schDlSlotInfo[slot]->rarAlloc = NULLP;
479 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
480 (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
482 slot = dlSchedInfo.schSlotValue.dlMsgTime.slot;
484 SCH_ALLOC(msg4Alloc, sizeof(DlMsgAlloc));
487 DU_LOG("\nERROR --> SCH : Memory Allocation failed for msg4 alloc");
491 dlSchedInfo.dlMsgAlloc = msg4Alloc;
493 /* Msg4 info is copied, this was earlier filled in macSchDlRlcBoInfo */
494 memcpy(&msg4Alloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
497 /* pdcch and pdsch data is filled */
498 if((schDlRsrcAllocMsg4(cell, dlSchedInfo.schSlotValue.dlMsgTime, msg4Alloc)) != ROK)
500 DU_LOG("\nERROR --> SCH : MSG4 scheduling failed");
501 SCH_FREE(msg4Alloc, sizeof(DlMsgAlloc));
502 dlSchedInfo.dlMsgAlloc = NULLP;
503 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
508 schAllocPucchResource(cell, msg4Alloc->dlMsgInfo.crnti, dlSchedInfo.schSlotValue.dlMsgTime.slot);
510 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
513 /* Check if UL grant must be sent in this slot for a SR/BSR that had been received */
514 for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
516 uint32_t totDataReq = 0; /* in bytes */
517 DciInfo *dciInfo = NULLP;
518 SchUeCb *ueCb = NULLP;
520 ueCb = &cell->ueCb[ueIdx];
524 totDataReq = UL_GRANT_SIZE; /*fixing so that all control msgs can be handled in SR */
525 ueCb->srRcvd = false;
528 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
530 totDataReq+= ueCb->bsrInfo[lcgIdx].dataVol;
531 ueCb->bsrInfo[lcgIdx].dataVol = 0;
533 if(totDataReq > 0) /* UL grant must be provided for this UE in this slot */
535 SchPuschInfo schPuschInfo;
536 memset(&schPuschInfo, 0, sizeof(SchPuschInfo));
538 SCH_ALLOC(dciInfo, sizeof(DciInfo));
541 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
544 memset(dciInfo,0,sizeof(DciInfo));
546 /* update the SFN and SLOT */
547 memcpy(&dlSchedInfo.schSlotValue.ulDciTime, slotInd, sizeof(SlotTimingInfo));
549 /* Update PUSCH allocation */
550 schFillPuschAlloc(ueCb, dlSchedInfo.schSlotValue.ulDciTime, totDataReq, &schPuschInfo);
552 /* Fill DCI for UL grant */
553 schFillUlDci(ueCb, schPuschInfo, dciInfo);
554 memcpy(&dciInfo->slotIndInfo, &dlSchedInfo.schSlotValue.ulDciTime, sizeof(SlotTimingInfo));
555 dlSchedInfo.ulGrant = dciInfo;
559 /* Check for pending BO grant for LC */
560 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
561 (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
563 if((schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc)) != ROK)
565 DU_LOG("\nERROR --> SCH : DL MSG scheduling failed");
566 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
570 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
571 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
574 /* Send msg to MAC */
575 ret = sendDlAllocToMac(&dlSchedInfo, schInst);
578 DU_LOG("\nERROR --> SCH : Sending DL Broadcast allocation from SCH to MAC failed");
582 schInitDlSlot(cell->schDlSlotInfo[slot]);
583 schUlResAlloc(cell, schInst);
588 /**********************************************************************
590 **********************************************************************/