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 SchCb schCb[SCH_MAX_INST];
54 /*******************************************************************
56 * @brief Handles sending DL broadcast alloc to MAC
60 * Function : sendDlAllocToMac
63 * Sends DL Broadcast Resource Allocation to MAC from SCH
66 * @return ROK - success
69 * ****************************************************************/
70 uint8_t sendDlAllocToMac(DlSchedInfo *dlSchedInfo, Inst inst)
74 memset(&pst, 0, sizeof(Pst));
75 FILL_PST_SCH_TO_MAC(pst, inst);
76 pst.event = EVENT_DL_SCH_INFO;
78 return(*schMacDlAllocOpts[pst.selector])(&pst, dlSchedInfo);
82 /*******************************************************************
84 * @brief Handles slot indication at SCH
88 * Function : schCalcSlotValues
91 * Handles TTI indication received from PHY
94 * @return ROK - success
97 * ****************************************************************/
98 void schCalcSlotValues(SlotTimingInfo slotInd, SchSlotValue *schSlotValue)
100 /****************************************************************
101 * PHY_DELTA - the physical layer delta *
102 * SCHED_DELTA - scheduler schedules one slot ahead *
103 * BO_DELTA - this delay is considered for BO response and *
104 * RLC buffer packet to received at MAC *
105 * lower-mac (FAPI filling) will be working on PHY_DELTA *
106 * brdcast scheduler will working on PHY_DELTA + SCHED_DELTA *
107 * RAR scheduler will working on PHY_DELTA + SCHED_DELTA *
108 * msg4 scheduler will working on PHY_DELTA + SCHED_DELTA *
109 * dedicated DL msg scheduler will working *
110 * on PHY_DELTA + SCHED_DELTA + BO_DELTA *
111 ****************************************************************/
113 ADD_DELTA_TO_TIME(slotInd, schSlotValue->currentTime, PHY_DELTA_DL);
114 ADD_DELTA_TO_TIME(slotInd, schSlotValue->broadcastTime, PHY_DELTA_DL + SCHED_DELTA);
115 ADD_DELTA_TO_TIME(slotInd, schSlotValue->rarTime, PHY_DELTA_DL + SCHED_DELTA);
116 ADD_DELTA_TO_TIME(slotInd, schSlotValue->dlMsgTime, PHY_DELTA_DL + SCHED_DELTA);
119 /*******************************************************************
121 * @brief Checks if a slot is to be scheduled for SSB transmission
125 * Function : schCheckSsbOcc
128 * Checks if a slot is to be scheduled for SSB transmission
130 * @params[in] SlotTimingInfo slotTime
132 * @return Pdu transmission
134 * ****************************************************************/
135 PduTxOccsaion schCheckSsbOcc(SlotTimingInfo slotTime, SchCellCb *cell)
139 ssb_rep = cell->cellCfg.ssbSchCfg.ssbPeriod;
141 /* Identify SSB ocassion*/
142 if ((slotTime.sfn % SCH_MIB_TRANS == 0) && (slotTime.slot ==0))
144 return NEW_TRANSMISSION;
146 else if(cell->firstSsbTransmitted)
148 if((ssb_rep == 5) && ((slotTime.slot == 0 || slotTime.slot == 10)))
150 else if((slotTime.sfn % (ssb_rep/10) == 0) && slotTime.slot == 0)
153 /* not SSB occassion */
154 return NO_TRANSMISSION;
157 /*******************************************************************
159 * @brief Checks if a slot is to be scheduled for SIB1 transmission
163 * Function : schCheckSib1Occ
166 * Checks if a slot is to be scheduled for SIB1 transmission
168 * @params[in] SlotTimingInfo slotTime
170 * @return Pdu transmission
172 * ****************************************************************/
173 PduTxOccsaion schCheckSib1Occ(SlotTimingInfo slotTime, SchCellCb *cell)
175 /* Identify SIB1 occasions */
176 if((slotTime.sfn % SCH_SIB1_TRANS == 0) && (slotTime.slot ==0))
178 return NEW_TRANSMISSION;
180 else if(cell->firstSib1Transmitted)
182 if((slotTime.sfn % (cell->cellCfg.sib1SchCfg.sib1RepetitionPeriod/10) == 0) &&
183 (slotTime.slot == 0))
188 /* not SIB1 occassion */
189 return NO_TRANSMISSION;
192 /*******************************************************************
204 * @return ROK - success
207 * ****************************************************************/
208 uint8_t schFillBoGrantDlSchedInfo(SchCellCb *cell, DlSchedInfo *dlSchedInfo, DlMsgAlloc *dlMsgAlloc)
210 uint8_t ueIdx, lcIdx;
213 uint32_t accumalatedSize = 0;
214 SchUeCb *ueCb = NULLP;
216 while(cell->boIndBitMap)
218 slot = dlSchedInfo->schSlotValue.dlMsgTime.slot;
220 GET_RIGHT_MOST_SET_BIT(cell->boIndBitMap, ueIdx);
221 GET_CRNTI(crnti,ueIdx);
222 ueCb = &cell->ueCb[ueIdx-1];
224 /* allocate PDCCH and PDSCH resources for the ue */
225 SCH_ALLOC(dlMsgAlloc, sizeof(DlMsgAlloc));
228 DU_LOG("\nERROR --> SCH : Memory Allocation failed for ded DL msg alloc");
231 memset(dlMsgAlloc, 0, sizeof(DlMsgAlloc));
232 dlSchedInfo->dlMsgAlloc = dlMsgAlloc;
233 dlMsgAlloc->crnti = crnti;
235 /* Dl ded Msg info is copied, this was earlier filled in macSchDlRlcBoInfo */
236 memcpy(&dlMsgAlloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
239 /* scheduled LC data fill */
240 dlMsgAlloc->numLc = 0;
241 for(lcIdx = 0; lcIdx < MAX_NUM_LC; lcIdx++)
243 if(ueCb->dlInfo.dlLcCtxt[lcIdx].bo)
245 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].lcId = lcIdx;
247 /* calculation for BO includse RLC and MAC header size */
248 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes = \
249 ueCb->dlInfo.dlLcCtxt[lcIdx].bo + MAC_HDR_SIZE;
250 accumalatedSize += dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes;
253 ueCb->dlInfo.dlLcCtxt[lcIdx].bo = 0;
256 if (!dlMsgAlloc->numLc)
258 DU_LOG("\nDEBUG --> SCH : No pending BO for any LC id\n");
259 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
260 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo, \
265 /* pdcch and pdsch data is filled */
266 schDlRsrcAllocDlMsg(dlMsgAlloc, cell, crnti, &accumalatedSize, slot);
268 /* TODO : Update the scheduling byte report for multiple LC based on QCI
270 /* As of now, the total number of bytes scheduled for a slot is divided
271 * equally amongst all LC with pending data. This is avoid starving of any
274 accumalatedSize = accumalatedSize/dlMsgAlloc->numLc;
275 for(lcIdx = 0; lcIdx < dlMsgAlloc->numLc; lcIdx ++)
276 dlMsgAlloc->lcSchInfo[lcIdx].schBytes = accumalatedSize;
279 schAllocPucchResource(cell, dlMsgAlloc->crnti, slot);
281 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
282 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo, \
284 cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
286 /* after allocation is done, unset the bo bit for that ue */
287 UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
293 /*******************************************************************
295 * @brief Handles slot indication at SCH
299 * Function : schProcessSlotInd
302 * Handles TTI indication received from PHY
305 * @return ROK - success
308 * ****************************************************************/
309 uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst schInst)
311 uint8_t ueIdx, lcgIdx, ret = ROK;
313 DlSchedInfo dlSchedInfo;
314 DlBrdcstAlloc *dlBrdcstAlloc = NULLP;
315 DlMsgAlloc *msg4Alloc = NULLP;
316 DlMsgAlloc *dlMsgAlloc = NULLP;
317 SchCellCb *cell = NULLP;
319 memset(&dlSchedInfo,0,sizeof(DlSchedInfo));
320 dlSchedInfo.dlMsgAlloc = NULLP;
321 schCalcSlotValues(*slotInd, &dlSchedInfo.schSlotValue);
322 dlBrdcstAlloc = &dlSchedInfo.brdcstAlloc;
323 dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
324 dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
326 cell = schCb[schInst].cells[schInst];
329 DU_LOG("\nERROR --> SCH : Cell Does not exist");
332 memcpy(&cell->slotInfo, slotInd, sizeof(SlotTimingInfo));
333 dlBrdcstAlloc->ssbIdxSupported = SSB_IDX_SUPPORTED;
335 slot = dlSchedInfo.schSlotValue.currentTime.slot;
337 dlSchedInfo.cellId = cell->cellId;
339 /* Check if this slot is SSB occassion */
340 dlBrdcstAlloc->ssbTrans = schCheckSsbOcc(dlSchedInfo.schSlotValue.broadcastTime, cell);
341 if((dlBrdcstAlloc->ssbTrans == NEW_TRANSMISSION) && (!cell->firstSsbTransmitted))
342 cell->firstSsbTransmitted = true;
344 /* Check if this slot is SIB1 occassion */
345 dlBrdcstAlloc->sib1Trans = schCheckSib1Occ(dlSchedInfo.schSlotValue.broadcastTime, cell);
346 if((dlBrdcstAlloc->sib1Trans == NEW_TRANSMISSION) && (!cell->firstSib1Transmitted))
347 cell->firstSib1Transmitted = true;
349 if(dlBrdcstAlloc->ssbTrans || dlBrdcstAlloc->sib1Trans)
351 dlSchedInfo.isBroadcastPres = true;
352 slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
353 ret = schBroadcastAlloc(cell,dlBrdcstAlloc,slot);
356 DU_LOG("\nERROR --> SCH : schBroadcastAlloc failed");
361 /* Check for Pending RA Requests */
362 schProcessRaReq(*slotInd, cell);
365 if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarAlloc != NULLP)
367 slot = dlSchedInfo.schSlotValue.rarTime.slot;
368 dlSchedInfo.rarAlloc = cell->schDlSlotInfo[slot]->rarAlloc;
369 cell->schDlSlotInfo[slot]->rarAlloc = NULLP;
373 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
374 (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
376 slot = dlSchedInfo.schSlotValue.dlMsgTime.slot;
378 SCH_ALLOC(msg4Alloc, sizeof(DlMsgAlloc));
381 DU_LOG("\nERROR --> SCH : Memory Allocation failed for msg4 alloc");
385 dlSchedInfo.dlMsgAlloc = msg4Alloc;
387 /* Msg4 info is copied, this was earlier filled in macSchDlRlcBoInfo */
388 memcpy(&msg4Alloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
391 /* pdcch and pdsch data is filled */
392 schDlRsrcAllocMsg4(msg4Alloc, cell, dlSchedInfo.schSlotValue.dlMsgTime.slot, dlBrdcstAlloc->ssbTrans, dlBrdcstAlloc->sib1Trans);
395 schAllocPucchResource(cell, msg4Alloc->dlMsgInfo.crnti, dlSchedInfo.schSlotValue.dlMsgTime.slot);
397 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
398 cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
401 /* check if UL grant must be sent in this slot for a SR/BSR that had been received */
402 for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
404 uint32_t totDataReq = 0; /* in bytes */
405 DciInfo *dciInfo = NULLP;
406 SchUeCb *ueCb = NULLP;
408 ueCb = &cell->ueCb[ueIdx];
412 totDataReq = UL_GRANT_SIZE; /*fixing so that all control msgs can be handled in SR */
413 ueCb->srRcvd = false;
416 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
418 totDataReq+= ueCb->bsrInfo[lcgIdx].dataVol;
419 ueCb->bsrInfo[lcgIdx].dataVol = 0;
421 if(totDataReq > 0) /* UL grant must be provided for this UE in this slot */
423 SchPuschInfo schPuschInfo;
424 memset(&schPuschInfo, 0, sizeof(SchPuschInfo));
426 SCH_ALLOC(dciInfo, sizeof(DciInfo));
429 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
432 memset(dciInfo,0,sizeof(DciInfo));
433 /* update the SFN and SLOT */
434 memcpy(&dlSchedInfo.schSlotValue.ulDciTime, slotInd, sizeof(SlotTimingInfo));
435 slot = dlSchedInfo.schSlotValue.ulDciTime.slot;
436 /* Update PUSCH allocation */
437 schFillPuschAlloc(ueCb, slot, totDataReq, &schPuschInfo);
438 /* Fill DCI for UL grant */
439 schFillUlDci(ueCb, schPuschInfo, dciInfo);
440 memcpy(&dciInfo->slotIndInfo, &dlSchedInfo.schSlotValue.ulDciTime, sizeof(SlotTimingInfo));
441 dlSchedInfo.ulGrant = dciInfo;
445 /* Check for pending BO grant for LC */
446 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
447 (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
449 schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc);
452 /* send msg to MAC */
453 ret = sendDlAllocToMac(&dlSchedInfo, schInst);
456 DU_LOG("\nERROR --> SCH : Sending DL Broadcast allocation from SCH to MAC failed");
460 schInitDlSlot(cell->schDlSlotInfo[slot]);
461 schUlResAlloc(cell, schInst);
467 /**********************************************************************
469 **********************************************************************/