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 /*******************************************************************
202 * @return ROK - success
205 * ****************************************************************/
206 uint8_t schFillBoGrantDlSchedInfo(SchCellCb *cell, DlSchedInfo *dlSchedInfo, DlMsgAlloc *dlMsgAlloc)
208 uint8_t ueIdx, lcIdx;
211 uint32_t accumalatedSize = 0;
212 SchUeCb *ueCb = NULLP;
214 while(cell->boIndBitMap)
216 slot = dlSchedInfo->schSlotValue.dlMsgTime.slot;
218 GET_RIGHT_MOST_SET_BIT(cell->boIndBitMap, ueIdx);
219 GET_CRNTI(crnti,ueIdx);
220 ueCb = &cell->ueCb[ueIdx-1];
222 /* allocate PDCCH and PDSCH resources for the ue */
223 SCH_ALLOC(dlMsgAlloc, sizeof(DlMsgAlloc));
226 DU_LOG("\nERROR --> SCH : Memory Allocation failed for ded DL msg alloc");
229 memset(dlMsgAlloc, 0, sizeof(DlMsgAlloc));
230 dlSchedInfo->dlMsgAlloc = dlMsgAlloc;
231 dlMsgAlloc->crnti = crnti;
233 /* Dl ded Msg info is copied, this was earlier filled in macSchDlRlcBoInfo */
234 memcpy(&dlMsgAlloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
237 /* scheduled LC data fill */
238 dlMsgAlloc->numLc = 0;
239 for(lcIdx = 0; lcIdx < MAX_NUM_LC; lcIdx++)
241 if(ueCb->dlInfo.dlLcCtxt[lcIdx].bo)
243 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].lcId = lcIdx;
245 /* calculation for BO includse RLC and MAC header size */
246 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes = \
247 ueCb->dlInfo.dlLcCtxt[lcIdx].bo + MAC_HDR_SIZE;
248 accumalatedSize += dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes;
251 ueCb->dlInfo.dlLcCtxt[lcIdx].bo = 0;
254 if (!dlMsgAlloc->numLc)
256 DU_LOG("\nDEBUG --> SCH : No pending BO for any LC id\n");
257 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
258 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
259 dlSchedInfo->dlMsgAlloc = NULLP;
263 /* pdcch and pdsch data is filled */
264 if((schDlRsrcAllocDlMsg(cell, dlSchedInfo->schSlotValue.dlMsgTime, crnti, &accumalatedSize, dlMsgAlloc)) != ROK)
266 DU_LOG("\nERROR --> SCH : Scheduling of DL dedicated message failed");
267 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
268 SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
269 dlSchedInfo->dlMsgAlloc = NULLP;
274 /* TODO : Update the scheduling byte report for multiple LC based on QCI
276 /* As of now, the total number of bytes scheduled for a slot is divided
277 * equally amongst all LC with pending data. This is avoid starving of any
280 accumalatedSize = accumalatedSize/dlMsgAlloc->numLc;
281 for(lcIdx = 0; lcIdx < dlMsgAlloc->numLc; lcIdx ++)
282 dlMsgAlloc->lcSchInfo[lcIdx].schBytes = accumalatedSize;
285 schAllocPucchResource(cell, dlMsgAlloc->crnti, slot);
287 /* after allocation is done, unset the bo bit for that ue */
288 UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
294 /*******************************************************************
296 * @brief Handles slot indication at SCH
300 * Function : schProcessSlotInd
303 * Handles TTI indication received from PHY
306 * @return ROK - success
309 * ****************************************************************/
310 uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst schInst)
312 uint8_t ueIdx, lcgIdx, ret = ROK;
314 DlSchedInfo dlSchedInfo;
315 DlBrdcstAlloc *dlBrdcstAlloc = NULLP;
316 DlMsgAlloc *msg4Alloc = NULLP;
317 DlMsgAlloc *dlMsgAlloc = NULLP;
318 SchCellCb *cell = NULLP;
320 memset(&dlSchedInfo,0,sizeof(DlSchedInfo));
321 dlSchedInfo.dlMsgAlloc = NULLP;
322 schCalcSlotValues(*slotInd, &dlSchedInfo.schSlotValue);
323 dlBrdcstAlloc = &dlSchedInfo.brdcstAlloc;
324 dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
325 dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
327 cell = schCb[schInst].cells[schInst];
330 DU_LOG("\nERROR --> SCH : Cell Does not exist");
333 memcpy(&cell->slotInfo, slotInd, sizeof(SlotTimingInfo));
334 dlBrdcstAlloc->ssbIdxSupported = SSB_IDX_SUPPORTED;
336 dlSchedInfo.cellId = cell->cellId;
338 slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
340 /* Check for SSB occassion */
341 dlBrdcstAlloc->ssbTrans = schCheckSsbOcc(cell, dlSchedInfo.schSlotValue.broadcastTime);
342 if(dlBrdcstAlloc->ssbTrans)
344 if(schBroadcastSsbAlloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
346 DU_LOG("\nERROR --> SCH : schBroadcastSsbAlloc failed");
347 dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
351 dlSchedInfo.isBroadcastPres = true;
352 if((dlBrdcstAlloc->ssbTrans == NEW_TRANSMISSION) && (!cell->firstSsbTransmitted))
353 cell->firstSsbTransmitted = true;
357 /* Check for SIB1 occassion */
358 dlBrdcstAlloc->sib1Trans = schCheckSib1Occ(cell, dlSchedInfo.schSlotValue.broadcastTime);
359 if(dlBrdcstAlloc->sib1Trans)
361 if(schBroadcastSib1Alloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
363 DU_LOG("\nERROR --> SCH : schBroadcastSib1Alloc failed");
364 dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
368 dlSchedInfo.isBroadcastPres = true;
369 if((dlBrdcstAlloc->sib1Trans == NEW_TRANSMISSION) && (!cell->firstSib1Transmitted))
370 cell->firstSib1Transmitted = true;
374 /* Check for Pending RA Requests */
375 schProcessRaReq(*slotInd, cell);
378 if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarAlloc != NULLP)
380 slot = dlSchedInfo.schSlotValue.rarTime.slot;
381 dlSchedInfo.rarAlloc = cell->schDlSlotInfo[slot]->rarAlloc;
382 cell->schDlSlotInfo[slot]->rarAlloc = NULLP;
386 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
387 (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
389 slot = dlSchedInfo.schSlotValue.dlMsgTime.slot;
391 SCH_ALLOC(msg4Alloc, sizeof(DlMsgAlloc));
394 DU_LOG("\nERROR --> SCH : Memory Allocation failed for msg4 alloc");
398 dlSchedInfo.dlMsgAlloc = msg4Alloc;
400 /* Msg4 info is copied, this was earlier filled in macSchDlRlcBoInfo */
401 memcpy(&msg4Alloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
404 /* pdcch and pdsch data is filled */
405 if((schDlRsrcAllocMsg4(cell, dlSchedInfo.schSlotValue.dlMsgTime, msg4Alloc)) != ROK)
407 DU_LOG("\nERROR --> SCH : MSG4 scheduling failed");
408 SCH_FREE(msg4Alloc, sizeof(DlMsgAlloc));
409 dlSchedInfo.dlMsgAlloc = NULLP;
410 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
415 schAllocPucchResource(cell, msg4Alloc->dlMsgInfo.crnti, dlSchedInfo.schSlotValue.dlMsgTime.slot);
417 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
420 /* Check if UL grant must be sent in this slot for a SR/BSR that had been received */
421 for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
423 uint32_t totDataReq = 0; /* in bytes */
424 DciInfo *dciInfo = NULLP;
425 SchUeCb *ueCb = NULLP;
427 ueCb = &cell->ueCb[ueIdx];
431 totDataReq = UL_GRANT_SIZE; /*fixing so that all control msgs can be handled in SR */
432 ueCb->srRcvd = false;
435 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
437 totDataReq+= ueCb->bsrInfo[lcgIdx].dataVol;
438 ueCb->bsrInfo[lcgIdx].dataVol = 0;
440 if(totDataReq > 0) /* UL grant must be provided for this UE in this slot */
442 SchPuschInfo schPuschInfo;
443 memset(&schPuschInfo, 0, sizeof(SchPuschInfo));
445 SCH_ALLOC(dciInfo, sizeof(DciInfo));
448 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
451 memset(dciInfo,0,sizeof(DciInfo));
453 /* update the SFN and SLOT */
454 memcpy(&dlSchedInfo.schSlotValue.ulDciTime, slotInd, sizeof(SlotTimingInfo));
456 /* Update PUSCH allocation */
457 schFillPuschAlloc(ueCb, dlSchedInfo.schSlotValue.ulDciTime, totDataReq, &schPuschInfo);
459 /* Fill DCI for UL grant */
460 schFillUlDci(ueCb, schPuschInfo, dciInfo);
461 memcpy(&dciInfo->slotIndInfo, &dlSchedInfo.schSlotValue.ulDciTime, sizeof(SlotTimingInfo));
462 dlSchedInfo.ulGrant = dciInfo;
466 /* Check for pending BO grant for LC */
467 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
468 (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
470 if((schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc)) != ROK)
472 DU_LOG("\nERROR --> SCH : DL MSG scheduling failed");
473 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
477 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
478 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
481 /* Send msg to MAC */
482 ret = sendDlAllocToMac(&dlSchedInfo, schInst);
485 DU_LOG("\nERROR --> SCH : Sending DL Broadcast allocation from SCH to MAC failed");
489 schInitDlSlot(cell->schDlSlotInfo[slot]);
490 schUlResAlloc(cell, schInst);
495 /**********************************************************************
497 **********************************************************************/