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);
83 /*******************************************************************
85 * @brief Handles slot indication at SCH
89 * Function : schCalcSlotValues
92 * Handles TTI indication received from PHY
95 * @return ROK - success
98 * ****************************************************************/
99 void schCalcSlotValues(SlotIndInfo slotInd, SchSlotValue *schSlotValue)
101 /****************************************************************
102 * PHY_DELTA - the physical layer delta *
103 * SCHED_DELTA - scheduler schedules one slot ahead *
104 * BO_DELTA - this delay is considered for BO response and *
105 * RLC buffer packet to received at MAC *
106 * lower-mac (FAPI filling) will be working on PHY_DELTA *
107 * brdcast scheduler will working on PHY_DELTA + SCHED_DELTA *
108 * RAR scheduler will working on PHY_DELTA + SCHED_DELTA *
109 * msg4 scheduler will working on PHY_DELTA + SCHED_DELTA *
110 * dedicated DL msg scheduler will working *
111 * on PHY_DELTA + SCHED_DELTA + BO_DELTA *
112 ****************************************************************/
114 ADD_DELTA_TO_TIME(slotInd, schSlotValue->currentTime, PHY_DELTA_DL);
115 ADD_DELTA_TO_TIME(slotInd, schSlotValue->broadcastTime, PHY_DELTA_DL + SCHED_DELTA);
116 ADD_DELTA_TO_TIME(slotInd, schSlotValue->rarTime, PHY_DELTA_DL + SCHED_DELTA);
117 ADD_DELTA_TO_TIME(slotInd, schSlotValue->dlMsgTime, PHY_DELTA_DL + SCHED_DELTA);
120 /*******************************************************************
132 * @return ROK - success
135 * ****************************************************************/
136 uint8_t schFillBoGrantDlSchedInfo(SchCellCb *cell, DlSchedInfo *dlSchedInfo, DlMsgAlloc *dlMsgAlloc)
138 uint8_t ueIdx, lcIdx;
141 uint32_t accumalatedSize = 0;
142 SchUeCb *ueCb = NULLP;
144 while(cell->boIndBitMap)
146 slot = dlSchedInfo->schSlotValue.dlMsgTime.slot;
148 GET_RIGHT_MOST_SET_BIT(cell->boIndBitMap, ueIdx);
149 GET_CRNTI(crnti,ueIdx);
150 ueCb = &cell->ueCb[ueIdx-1];
152 /* allocate PDCCH and PDSCH resources for the ue */
153 SCH_ALLOC(dlMsgAlloc, sizeof(DlMsgAlloc));
156 DU_LOG("\nERROR --> SCH : Memory Allocation failed for ded DL msg alloc");
159 memset(dlMsgAlloc, 0, sizeof(DlMsgAlloc));
160 dlSchedInfo->dlMsgAlloc = dlMsgAlloc;
161 dlMsgAlloc->crnti = crnti;
163 /* Dl ded Msg info is copied, this was earlier filled in macSchDlRlcBoInfo */
164 memcpy(&dlMsgAlloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
167 /* scheduled LC data fill */
168 dlMsgAlloc->numLc = 0;
169 for(lcIdx = 0; lcIdx < MAX_NUM_LC; lcIdx++)
171 if(ueCb->dlInfo.dlLcCtxt[lcIdx].bo)
173 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].lcId = lcIdx;
175 /* calculation for BO includse RLC and MAC header size */
176 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes = \
177 ueCb->dlInfo.dlLcCtxt[lcIdx].bo + MAC_HDR_SIZE;
178 accumalatedSize += dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes;
181 ueCb->dlInfo.dlLcCtxt[lcIdx].bo = 0;
184 /* pdcch and pdsch data is filled */
185 schDlRsrcAllocDlMsg(dlMsgAlloc, cell, crnti, &accumalatedSize, slot);
186 /* Calculated TB size could be less than the total size requested.
187 * Hence, updated the scheduled bytes report. Following is valid only for
189 * TODO : Update the scheduling byte report for multiple LC based on QCI
191 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc -1].schBytes = accumalatedSize;
194 schAllocPucchResource(cell, dlMsgAlloc->crnti, slot);
196 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
197 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo, \
199 cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
201 /* after allocation is done, unset the bo bit for that ue */
202 UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
208 /*******************************************************************
210 * @brief Handles slot indication at SCH
214 * Function : schProcessSlotInd
217 * Handles TTI indication received from PHY
220 * @return ROK - success
223 * ****************************************************************/
224 uint8_t schProcessSlotInd(SlotIndInfo *slotInd, Inst schInst)
226 uint8_t ssb_rep, ueIdx, lcgIdx, ret = ROK;
228 DlSchedInfo dlSchedInfo;
229 DlBrdcstAlloc *dlBrdcstAlloc = NULLP;
230 RarAlloc *rarAlloc = NULLP;
231 DlMsgAlloc *msg4Alloc = NULLP;
232 DlMsgAlloc *dlMsgAlloc = NULLP;
233 SchCellCb *cell = NULLP;
236 memset(&dlSchedInfo,0,sizeof(DlSchedInfo));
237 dlSchedInfo.dlMsgAlloc = NULLP;
238 schCalcSlotValues(*slotInd, &dlSchedInfo.schSlotValue);
239 dlBrdcstAlloc = &dlSchedInfo.brdcstAlloc;
240 dlBrdcstAlloc->ssbTrans = NO_SSB;
241 dlBrdcstAlloc->sib1Trans = NO_SIB1;
243 cell = schCb[schInst].cells[schInst];
246 DU_LOG("\nERROR --> SCH : Cell Does not exist");
249 ssb_rep = cell->cellCfg.ssbSchCfg.ssbPeriod;
250 memcpy(&cell->slotInfo, slotInd, sizeof(SlotIndInfo));
251 dlBrdcstAlloc->ssbIdxSupported = 1;
253 slot = dlSchedInfo.schSlotValue.currentTime.slot;
255 dlSchedInfo.cellId = cell->cellId;
257 /* Identify SSB ocassion*/
258 if ((dlSchedInfo.schSlotValue.broadcastTime.sfn % SCH_MIB_TRANS == 0) && (dlSchedInfo.schSlotValue.broadcastTime.slot ==0))
260 dlBrdcstAlloc->ssbTrans = SSB_TRANSMISSION;
261 if(!cell->firstSsbTransmitted)
262 cell->firstSsbTransmitted = true;
264 else if (cell->firstSsbTransmitted)
266 if((ssb_rep == 5) && ((dlSchedInfo.schSlotValue.broadcastTime.slot == 0 || dlSchedInfo.schSlotValue.broadcastTime.slot == 10)))
267 dlBrdcstAlloc->ssbTrans = SSB_REPEAT;
268 else if((dlSchedInfo.schSlotValue.broadcastTime.sfn % (ssb_rep/10) == 0) && dlSchedInfo.schSlotValue.broadcastTime.slot == 0)
269 dlBrdcstAlloc->ssbTrans = SSB_REPEAT;
273 /* not SSB occassion */
276 /* Identify SIB1 occasions */
277 if((dlSchedInfo.schSlotValue.broadcastTime.sfn % SCH_SIB1_TRANS == 0) && (dlSchedInfo.schSlotValue.broadcastTime.slot ==0))
279 dlBrdcstAlloc->sib1Trans = SIB1_TRANSMISSION;
280 if(!cell->firstSib1Transmitted)
281 cell->firstSib1Transmitted = true;
283 else if (cell->firstSib1Transmitted)
285 if((dlSchedInfo.schSlotValue.broadcastTime.sfn % (cell->cellCfg.sib1SchCfg.sib1RepetitionPeriod/10) == 0) &&
286 (dlSchedInfo.schSlotValue.broadcastTime.slot == 0))
288 dlBrdcstAlloc->sib1Trans = SIB1_REPITITION;
293 /* not SIB1 occassion */
297 if(dlBrdcstAlloc->ssbTrans || dlBrdcstAlloc->sib1Trans)
299 dlSchedInfo.isBroadcastPres = true;
300 slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
301 ret = schBroadcastAlloc(cell,dlBrdcstAlloc,slot);
304 DU_LOG("\nERROR --> SCH : schBroadcastAlloc failed");
310 if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarInfo != NULLP)
312 slot = dlSchedInfo.schSlotValue.rarTime.slot;
313 SCH_ALLOC(rarAlloc, sizeof(RarAlloc));
316 DU_LOG("\nERROR --> SCH : Memory Allocation failed for RAR alloc");
320 dlSchedInfo.rarAlloc = rarAlloc;
322 /* RAR info is copied, this was earlier filled in schProcessRachInd */
323 memcpy(&rarAlloc->rarInfo,cell->schDlSlotInfo[slot]->rarInfo, sizeof(RarInfo));
325 /* pdcch and pdsch data is filled */
327 cell->schDlSlotInfo[slot]->rarInfo->raRnti,
328 cell->cellCfg.phyCellId,
329 cell->cellCfg.ssbSchCfg.ssbOffsetPointA,
330 dlBrdcstAlloc->ssbTrans,
331 dlBrdcstAlloc->sib1Trans);
333 SCH_FREE(cell->schDlSlotInfo[slot]->rarInfo,sizeof(RarInfo));
334 cell->schDlSlotInfo[slot]->rarInfo = NULLP;
338 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
339 (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
341 slot = dlSchedInfo.schSlotValue.dlMsgTime.slot;
343 SCH_ALLOC(msg4Alloc, sizeof(DlMsgAlloc));
346 DU_LOG("\nERROR --> SCH : Memory Allocation failed for msg4 alloc");
350 dlSchedInfo.dlMsgAlloc = msg4Alloc;
352 /* Msg4 info is copied, this was earlier filled in macSchDlRlcBoInfo */
353 memcpy(&msg4Alloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
356 /* pdcch and pdsch data is filled */
357 schDlRsrcAllocMsg4(msg4Alloc, cell, dlSchedInfo.schSlotValue.dlMsgTime.slot, dlBrdcstAlloc->ssbTrans, dlBrdcstAlloc->sib1Trans);
360 schAllocPucchResource(cell, msg4Alloc->dlMsgInfo.crnti, dlSchedInfo.schSlotValue.dlMsgTime.slot);
362 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
363 cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
365 /* check if UL grant must be sent in this slot for a SR/BSR that had been received */
366 for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
368 uint32_t totDataReq = 0; /* in bytes */
369 DciInfo *dciInfo = NULLP;
370 SchUeCb *ueCb = NULLP;
372 ueCb = &cell->ueCb[ueIdx];
376 totDataReq = UL_GRANT_SIZE; /*fixing so that all control msgs can be handled in SR */
377 ueCb->srRcvd = false;
380 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
382 totDataReq+= ueCb->bsrInfo[lcgIdx].dataVol;
383 ueCb->bsrInfo[lcgIdx].dataVol = 0;
385 if(totDataReq > 0) /* UL grant must be provided for this UE in this slot */
387 SchPuschInfo schPuschInfo;
388 memset(&schPuschInfo, 0, sizeof(SchPuschInfo));
390 SCH_ALLOC(dciInfo, sizeof(DciInfo));
393 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
396 memset(dciInfo,0,sizeof(DciInfo));
397 /* update the SFN and SLOT */
398 memcpy(&dlSchedInfo.schSlotValue.ulDciTime, slotInd, sizeof(SlotIndInfo));
399 slot = dlSchedInfo.schSlotValue.ulDciTime.slot;
400 /* Update PUSCH allocation */
401 schFillPuschAlloc(ueCb, slot, totDataReq, &schPuschInfo);
402 /* Fill DCI for UL grant */
403 schFillUlDci(ueCb, schPuschInfo, dciInfo);
404 memcpy(&dciInfo->slotIndInfo, &dlSchedInfo.schSlotValue.ulDciTime, sizeof(SlotIndInfo));
405 dlSchedInfo.ulGrant = dciInfo;
409 /* Check for pending BO grant for LC */
410 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
411 (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
413 schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc);
416 /* send msg to MAC */
417 ret = sendDlAllocToMac(&dlSchedInfo, schInst);
420 DU_LOG("\nERROR --> SCH : Sending DL Broadcast allocation from SCH to MAC failed");
424 schInitDlSlot(cell->schDlSlotInfo[slot]);
425 schUlResAlloc(cell, schInst);
431 /**********************************************************************
433 **********************************************************************/