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 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
294 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
295 dlSchedInfo->dlMsgAlloc = NULLP;
299 /*[Step3]: Calculate Best FREE BLOCK with MAX PRB count*/
300 maxFreePRB = searchLargestFreeBlockDL(cell, dlSchedInfo->schSlotValue.dlMsgTime, &startPrb);
302 /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
303 * the list based on RRM policy*/
305 /*Either this UE contains no reservedPRB pool fir dedicated S-NSSAI or
306 * Num of Free PRB available is not enough to reserve Dedicated PRBs*/
309 if((ueCb->dlLcPrbEst.dedLcInfo == NULLP)
310 || ((maxFreePRB < ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB)))
312 ueCb->dlLcPrbEst.sharedNumPrb = maxFreePRB;
313 DU_LOG("\nWARNING --> SCH : Only Default Slice is scheduled, sharedPRB Count:%d",\
314 ueCb->dlLcPrbEst.sharedNumPrb);
316 /*PRB Alloc for Default LCs*/
317 prbAllocUsingRRMPolicy(&(ueCb->dlLcPrbEst.defLcList), FALSE, mcsIdx, pdschSymbols,\
318 &(ueCb->dlLcPrbEst.sharedNumPrb), NULLP, &isTxPayloadLenAdded);
322 ueCb->dlLcPrbEst.sharedNumPrb = maxFreePRB - ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB;
324 /*PRB Alloc for Dedicated LCs*/
325 prbAllocUsingRRMPolicy(&(ueCb->dlLcPrbEst.dedLcInfo->dedLcList), TRUE, mcsIdx, pdschSymbols,\
326 &(ueCb->dlLcPrbEst.sharedNumPrb), &(ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB), &isTxPayloadLenAdded);
328 /*PRB Alloc for Default LCs*/
329 prbAllocUsingRRMPolicy(&(ueCb->dlLcPrbEst.defLcList), FALSE, mcsIdx, pdschSymbols, \
330 &(ueCb->dlLcPrbEst.sharedNumPrb), &(ueCb->dlLcPrbEst.dedLcInfo->rsvdDedicatedPRB), &isTxPayloadLenAdded);
334 /*[Step5]:Traverse each LCID in LcList to calculate the exact Scheduled Bytes
335 * using allocated BO per LC and Update dlMsgAlloc(BO report for MAC*/
336 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
337 updateGrantSizeForBoRpt(&(ueCb->dlLcPrbEst.dedLcInfo->dedLcList), dlMsgAlloc, &(accumalatedSize));
339 updateGrantSizeForBoRpt(&(ueCb->dlLcPrbEst.defLcList), dlMsgAlloc, &(accumalatedSize));
341 /*Below case will hit if NO LC(s) are allocated due to resource crunch*/
342 if (!accumalatedSize)
346 DU_LOG("\nERROR --> SCH : NO FREE PRB!!");
350 /*Schedule the LC for next slot*/
351 DU_LOG("\nDEBUG --> SCH : No LC has been scheduled");
353 /*Not Freeing dlMsgAlloc as ZERO BO REPORT to be sent to RLC so that
354 * Allocation can be done in next slot*/
358 /*[Step6]: pdcch and pdsch data is filled */
359 if((schDlRsrcAllocDlMsg(cell, dlSchedInfo->schSlotValue.dlMsgTime, \
360 crnti, accumalatedSize, dlMsgAlloc, startPrb)) != ROK)
362 DU_LOG("\nERROR --> SCH : Scheduling of DL dedicated message failed");
363 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
364 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
365 dlSchedInfo->dlMsgAlloc = NULLP;
369 dlMsgAlloc->pduPres = BOTH;
371 /* TODO : Update the scheduling byte report for multiple LC based on QCI
373 /* As of now, the total number of bytes scheduled for a slot is divided
374 * equally amongst all LC with pending data. This is avoid starving of any
378 accumalatedSize = accumalatedSize/dlMsgAlloc->numLc;
379 for(lcIdx = 0; lcIdx < dlMsgAlloc->numLc; lcIdx ++)
380 dlMsgAlloc->lcSchInfo[lcIdx].schBytes = accumalatedSize;
383 /* TODO : Correct values of K1 will be used from K0K1 table */
384 if(cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres)
386 schPucchCfg = &(cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg);
387 if(schPucchCfg->dlDataToUlAck)
389 for(dlToUlAckIdx = 0; dlToUlAckIdx < schPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; dlToUlAckIdx++)
391 //For now considering only the first value in the list
392 k1 = schPucchCfg->dlDataToUlAck->dlDataToUlAckList[dlToUlAckIdx];
397 ADD_DELTA_TO_TIME(dlSchedInfo->schSlotValue.dlMsgTime, pucchTime, k1);
398 schAllocPucchResource(cell, pucchTime, crnti);
400 /* after allocation is done, unset the bo bit for that ue */
401 UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
407 /*******************************************************************
409 * @brief Handles slot indication at SCH
413 * Function : schProcessSlotInd
416 * Handles TTI indication received from PHY
419 * @return ROK - success
422 * ****************************************************************/
423 uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst schInst)
425 uint8_t ueIdx, lcgIdx, ret = ROK;
427 DlSchedInfo dlSchedInfo;
428 DlBrdcstAlloc *dlBrdcstAlloc = NULLP;
429 DlMsgAlloc *dlMsgAlloc = NULLP;
430 SchCellCb *cell = NULLP;
432 memset(&dlSchedInfo,0,sizeof(DlSchedInfo));
433 dlSchedInfo.dlMsgAlloc = NULLP;
434 schCalcSlotValues(*slotInd, &dlSchedInfo.schSlotValue);
435 dlBrdcstAlloc = &dlSchedInfo.brdcstAlloc;
436 dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
437 dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
439 cell = schCb[schInst].cells[schInst];
442 DU_LOG("\nERROR --> SCH : Cell Does not exist");
445 memcpy(&cell->slotInfo, slotInd, sizeof(SlotTimingInfo));
446 dlBrdcstAlloc->ssbIdxSupported = SSB_IDX_SUPPORTED;
448 dlSchedInfo.cellId = cell->cellId;
449 slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
451 /* Check for SSB occassion */
452 dlBrdcstAlloc->ssbTrans = schCheckSsbOcc(cell, dlSchedInfo.schSlotValue.broadcastTime);
453 if(dlBrdcstAlloc->ssbTrans)
455 if(schBroadcastSsbAlloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
457 DU_LOG("\nERROR --> SCH : schBroadcastSsbAlloc failed");
458 dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
462 dlSchedInfo.isBroadcastPres = true;
463 if((dlBrdcstAlloc->ssbTrans == NEW_TRANSMISSION) && (!cell->firstSsbTransmitted))
464 cell->firstSsbTransmitted = true;
468 /* Check for SIB1 occassion */
469 dlBrdcstAlloc->sib1Trans = schCheckSib1Occ(cell, dlSchedInfo.schSlotValue.broadcastTime);
470 if(dlBrdcstAlloc->sib1Trans)
472 if(schBroadcastSib1Alloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
474 DU_LOG("\nERROR --> SCH : schBroadcastSib1Alloc failed");
475 dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
479 dlSchedInfo.isBroadcastPres = true;
480 if((dlBrdcstAlloc->sib1Trans == NEW_TRANSMISSION) && (!cell->firstSib1Transmitted))
481 cell->firstSib1Transmitted = true;
485 /* Check for Pending RA Requests */
486 schProcessRaReq(*slotInd, cell);
489 if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarAlloc != NULLP)
491 slot = dlSchedInfo.schSlotValue.rarTime.slot;
492 dlSchedInfo.rarAlloc = cell->schDlSlotInfo[slot]->rarAlloc;
493 cell->schDlSlotInfo[slot]->rarAlloc = NULLP;
496 schProcessMsg4Req(cell, *slotInd);
499 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc != NULLP) &&
500 (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc->dlMsgInfo.isMsg4Pdu))
502 slot = dlSchedInfo.schSlotValue.dlMsgTime.slot;
503 dlSchedInfo.dlMsgAlloc = cell->schDlSlotInfo[slot]->dlMsgAlloc;
504 cell->schDlSlotInfo[slot]->dlMsgAlloc = NULLP;
507 /* Check if UL grant must be sent in this slot for a SR/BSR that had been received */
508 for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
510 uint32_t totDataReq = 0; /* in bytes */
511 DciInfo *dciInfo = NULLP;
512 SchUeCb *ueCb = NULLP;
514 ueCb = &cell->ueCb[ueIdx];
518 totDataReq = UL_GRANT_SIZE; /*fixing so that all control msgs can be handled in SR */
519 ueCb->srRcvd = false;
522 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
524 totDataReq+= ueCb->bsrInfo[lcgIdx].dataVol;
525 ueCb->bsrInfo[lcgIdx].dataVol = 0;
527 if(totDataReq > 0) /* UL grant must be provided for this UE in this slot */
529 SchPuschInfo schPuschInfo;
530 memset(&schPuschInfo, 0, sizeof(SchPuschInfo));
532 SCH_ALLOC(dciInfo, sizeof(DciInfo));
535 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
538 memset(dciInfo,0,sizeof(DciInfo));
540 /* update the SFN and SLOT */
541 memcpy(&dlSchedInfo.schSlotValue.ulDciTime, slotInd, sizeof(SlotTimingInfo));
543 /* Update PUSCH allocation */
544 schFillPuschAlloc(ueCb, dlSchedInfo.schSlotValue.ulDciTime, totDataReq, &schPuschInfo);
546 /* Fill DCI for UL grant */
547 schFillUlDci(ueCb, schPuschInfo, dciInfo);
548 memcpy(&dciInfo->slotIndInfo, &dlSchedInfo.schSlotValue.ulDciTime, sizeof(SlotTimingInfo));
549 dlSchedInfo.ulGrant = dciInfo;
553 /* Check for pending BO grant for LC */
554 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc != NULLP) &&
555 (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc->dlMsgInfo.isMsg4Pdu))
557 if((schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc)) != ROK)
559 DU_LOG("\nERROR --> SCH : DL MSG scheduling failed");
560 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc, sizeof(DlMsgAlloc));
564 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
565 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgAlloc, sizeof(DlMsgAlloc));
568 /* Send msg to MAC */
569 ret = sendDlAllocToMac(&dlSchedInfo, schInst);
572 DU_LOG("\nERROR --> SCH : Sending DL Broadcast allocation from SCH to MAC failed");
576 schInitDlSlot(cell->schDlSlotInfo[slot]);
577 schUlResAlloc(cell, schInst);
582 /**********************************************************************
584 **********************************************************************/