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];
53 int schFillRar(RarAlloc *rarAlloc, uint16_t raRnti, uint16_t pci, uint8_t
56 /*******************************************************************
58 * @brief Handles sending DL broadcast alloc to MAC
62 * Function : sendDlAllocToMac
65 * Sends DL Broadcast Resource Allocation to MAC from SCH
68 * @return ROK - success
71 * ****************************************************************/
72 uint8_t sendDlAllocToMac(DlSchedInfo *dlSchedInfo, Inst inst)
76 memset(&pst, 0, sizeof(Pst));
77 FILL_PST_SCH_TO_MAC(pst, inst);
78 pst.event = EVENT_DL_ALLOC;
80 return(*schMacDlAllocOpts[pst.selector])(&pst, dlSchedInfo);
85 /*******************************************************************
87 * @brief Handles slot indication at SCH
91 * Function : schCalcSlotValues
94 * Handles TTI indication received from PHY
97 * @return ROK - success
100 * ****************************************************************/
101 void schCalcSlotValues(SlotIndInfo slotInd, SchSlotValue *schSlotValue)
103 /****************************************************************
104 * PHY_DELTA - the physical layer delta *
105 * SCHED_DELTA - scheduler schedules one slot ahead *
106 * BO_DELTA - this delay is considered for BO response and *
107 * RLC buffer packet to received at MAC *
108 * lower-mac (FAPI filling) will be working on PHY_DELTA *
109 * brdcast scheduler will working on PHY_DELTA + SCHED_DELTA *
110 * RAR scheduler will working on PHY_DELTA + SCHED_DELTA *
111 * msg4 scheduler will working on PHY_DELTA + SCHED_DELTA *
112 * dedicated DL msg scheduler will working *
113 * on PHY_DELTA + SCHED_DELTA + BO_DELTA *
114 ****************************************************************/
116 ADD_DELTA_TO_TIME(slotInd, schSlotValue->currentTime, PHY_DELTA_DL);
117 ADD_DELTA_TO_TIME(slotInd, schSlotValue->broadcastTime, PHY_DELTA_DL + SCHED_DELTA);
118 ADD_DELTA_TO_TIME(slotInd, schSlotValue->rarTime, PHY_DELTA_DL + SCHED_DELTA);
119 ADD_DELTA_TO_TIME(slotInd, schSlotValue->dlMsgTime, PHY_DELTA_DL + SCHED_DELTA);
122 /*******************************************************************
134 * @return ROK - success
137 * ****************************************************************/
138 uint8_t schFillBoGrantDlSchedInfo(SchCellCb *cell, DlSchedInfo *dlSchedInfo, DlMsgAlloc *dlMsgAlloc)
140 uint8_t ueIdx, lcIdx;
143 uint32_t accumalatedSize = 0;
144 SchUeCb *ueCb = NULLP;
146 while(cell->boIndBitMap)
148 slot = dlSchedInfo->schSlotValue.dlMsgTime.slot;
150 GET_RIGHT_MOST_SET_BIT(cell->boIndBitMap, ueIdx);
151 GET_CRNTI(crnti,ueIdx);
152 ueCb = &cell->ueCb[ueIdx-1];
154 /* allocate PDCCH and PDSCH resources for the ue */
155 SCH_ALLOC(dlMsgAlloc, sizeof(DlMsgAlloc));
158 DU_LOG("\nERROR --> SCH : Memory Allocation failed for ded DL msg alloc");
161 memset(dlMsgAlloc, 0, sizeof(DlMsgAlloc));
162 dlSchedInfo->dlMsgAlloc = dlMsgAlloc;
163 dlMsgAlloc->crnti = crnti;
165 /* Dl ded Msg info is copied, this was earlier filled in macSchDlRlcBoInfo */
166 memcpy(&dlMsgAlloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
169 /* scheduled LC data fill */
170 dlMsgAlloc->numLc = 0;
171 for(lcIdx = 0; lcIdx < MAX_NUM_LC; lcIdx++)
173 if(ueCb->dlInfo.dlLcCtxt[lcIdx].bo)
175 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].lcId = lcIdx;
177 /* calculation for BO includse RLC and MAC header size */
178 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes = \
179 ueCb->dlInfo.dlLcCtxt[lcIdx].bo + MAC_HDR_SIZE;
180 accumalatedSize += dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes;
183 ueCb->dlInfo.dlLcCtxt[lcIdx].bo = 0;
186 /* pdcch and pdsch data is filled */
187 schDlRsrcAllocDlMsg(dlMsgAlloc, cell, crnti, &accumalatedSize, slot);
188 /* Calculated TB size could be less than the total size requested.
189 * Hence, updated the scheduled bytes report. Following is valid only for
191 * TODO : Update the scheduling byte report for multiple LC based on QCI
193 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc -1].schBytes = accumalatedSize;
196 schAllocPucchResource(cell, dlMsgAlloc->crnti, slot);
198 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
199 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo, \
201 cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
203 /* after allocation is done, unset the bo bit for that ue */
204 UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
210 /*******************************************************************
212 * @brief Handles slot indication at SCH
216 * Function : schProcessSlotInd
219 * Handles TTI indication received from PHY
222 * @return ROK - success
225 * ****************************************************************/
226 uint8_t schProcessSlotInd(SlotIndInfo *slotInd, Inst schInst)
228 uint8_t ssb_rep, ueIdx, lcgIdx, ret = ROK;
230 DlSchedInfo dlSchedInfo;
231 DlBrdcstAlloc *dlBrdcstAlloc = NULLP;
232 RarAlloc *rarAlloc = NULLP;
233 DlMsgAlloc *msg4Alloc = NULLP;
234 DlMsgAlloc *dlMsgAlloc = NULLP;
235 SchCellCb *cell = NULLP;
238 memset(&dlSchedInfo,0,sizeof(DlSchedInfo));
239 dlSchedInfo.dlMsgAlloc = NULLP;
240 schCalcSlotValues(*slotInd, &dlSchedInfo.schSlotValue);
241 dlBrdcstAlloc = &dlSchedInfo.brdcstAlloc;
242 dlBrdcstAlloc->ssbTrans = NO_SSB;
243 dlBrdcstAlloc->sib1Trans = NO_SIB1;
245 cell = schCb[schInst].cells[schInst];
246 ssb_rep = cell->cellCfg.ssbSchCfg.ssbPeriod;
247 memcpy(&cell->slotInfo, slotInd, sizeof(SlotIndInfo));
248 dlBrdcstAlloc->ssbIdxSupported = 1;
250 slot = dlSchedInfo.schSlotValue.currentTime.slot;
252 dlSchedInfo.cellId = cell->cellId;
254 /* Identify SSB ocassion*/
255 if ((dlSchedInfo.schSlotValue.broadcastTime.sfn % SCH_MIB_TRANS == 0) && (dlSchedInfo.schSlotValue.broadcastTime.slot ==0))
257 dlBrdcstAlloc->ssbTrans = SSB_TRANSMISSION;
258 if(!cell->firstSsbTransmitted)
259 cell->firstSsbTransmitted = true;
261 else if (cell->firstSsbTransmitted)
263 if((ssb_rep == 5) && ((dlSchedInfo.schSlotValue.broadcastTime.slot == 0 || dlSchedInfo.schSlotValue.broadcastTime.slot == 10)))
264 dlBrdcstAlloc->ssbTrans = SSB_REPEAT;
265 else if((dlSchedInfo.schSlotValue.broadcastTime.sfn % (ssb_rep/10) == 0) && dlSchedInfo.schSlotValue.broadcastTime.slot == 0)
266 dlBrdcstAlloc->ssbTrans = SSB_REPEAT;
270 /* not SSB occassion */
273 /* Identify SIB1 occasions */
274 if((dlSchedInfo.schSlotValue.broadcastTime.sfn % SCH_SIB1_TRANS == 0) && (dlSchedInfo.schSlotValue.broadcastTime.slot ==0))
276 dlBrdcstAlloc->sib1Trans = SIB1_TRANSMISSION;
277 if(!cell->firstSib1Transmitted)
278 cell->firstSib1Transmitted = true;
280 else if (cell->firstSib1Transmitted)
282 if((dlSchedInfo.schSlotValue.broadcastTime.sfn % (cell->cellCfg.sib1SchCfg.sib1RepetitionPeriod/10) == 0) &&
283 (dlSchedInfo.schSlotValue.broadcastTime.slot == 0))
285 dlBrdcstAlloc->sib1Trans = SIB1_REPITITION;
290 /* not SIB1 occassion */
294 if(dlBrdcstAlloc->ssbTrans || dlBrdcstAlloc->sib1Trans)
296 dlSchedInfo.isBroadcastPres = true;
297 slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
298 ret = schBroadcastAlloc(cell,dlBrdcstAlloc,slot);
301 DU_LOG("\nERROR --> SCH : schBroadcastAlloc failed");
307 if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarInfo != NULLP)
309 slot = dlSchedInfo.schSlotValue.rarTime.slot;
310 SCH_ALLOC(rarAlloc, sizeof(RarAlloc));
313 DU_LOG("\nERROR --> SCH : Memory Allocation failed for RAR alloc");
317 dlSchedInfo.rarAlloc = rarAlloc;
319 /* RAR info is copied, this was earlier filled in schProcessRachInd */
320 memcpy(&rarAlloc->rarInfo,cell->schDlSlotInfo[slot]->rarInfo, sizeof(RarInfo));
322 /* pdcch and pdsch data is filled */
324 cell->schDlSlotInfo[slot]->rarInfo->raRnti,
325 cell->cellCfg.phyCellId,
326 cell->cellCfg.ssbSchCfg.ssbOffsetPointA);
328 SCH_FREE(cell->schDlSlotInfo[slot]->rarInfo,sizeof(RarAlloc));
329 cell->schDlSlotInfo[slot]->rarInfo = NULLP;
333 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
334 (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
336 slot = dlSchedInfo.schSlotValue.dlMsgTime.slot;
338 SCH_ALLOC(msg4Alloc, sizeof(DlMsgAlloc));
341 DU_LOG("\nERROR --> SCH : Memory Allocation failed for msg4 alloc");
345 dlSchedInfo.dlMsgAlloc = msg4Alloc;
347 /* Msg4 info is copied, this was earlier filled in macSchDlRlcBoInfo */
348 memcpy(&msg4Alloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
351 /* pdcch and pdsch data is filled */
352 schDlRsrcAllocMsg4(msg4Alloc, cell, dlSchedInfo.schSlotValue.dlMsgTime.slot);
355 schAllocPucchResource(cell, msg4Alloc->dlMsgInfo.crnti, dlSchedInfo.schSlotValue.dlMsgTime.slot);
357 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
358 cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
360 /* check if UL grant must be sent in this slot for a SR/BSR that had been received */
361 for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
363 uint32_t totDataReq = 0; /* in bytes */
364 DciInfo *dciInfo = NULLP;
365 SchUeCb *ueCb = NULLP;
367 ueCb = &cell->ueCb[ueIdx];
371 totDataReq = UL_GRANT_SIZE; /*fixing so that all control msgs can be handled in SR */
372 ueCb->srRcvd = false;
375 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
377 totDataReq+= ueCb->bsrInfo[lcgIdx].dataVol;
378 ueCb->bsrInfo[lcgIdx].dataVol = 0;
380 if(totDataReq > 0) /* UL grant must be provided for this UE in this slot */
382 SchPuschInfo schPuschInfo;
383 memset(&schPuschInfo, 0, sizeof(SchPuschInfo));
385 SCH_ALLOC(dciInfo, sizeof(DciInfo));
388 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
391 memset(dciInfo,0,sizeof(DciInfo));
392 /* update the SFN and SLOT */
393 memcpy(&dlSchedInfo.schSlotValue.ulDciTime, slotInd, sizeof(SlotIndInfo));
394 slot = dlSchedInfo.schSlotValue.ulDciTime.slot;
395 /* Update PUSCH allocation */
396 schFillPuschAlloc(ueCb, slot, totDataReq, &schPuschInfo);
397 /* Fill DCI for UL grant */
398 schFillUlDci(ueCb, schPuschInfo, dciInfo);
399 memcpy(&dciInfo->slotIndInfo, &dlSchedInfo.schSlotValue.ulDciTime, sizeof(SlotIndInfo));
400 dlSchedInfo.ulGrant = dciInfo;
404 /* Check for pending BO grant for LC */
405 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
406 (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
408 schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc);
411 /* send msg to MAC */
412 ret = sendDlAllocToMac(&dlSchedInfo, schInst);
415 DU_LOG("\nERROR --> SCH : Sending DL Broadcast allocation from SCH to MAC failed");
419 schInitDlSlot(cell->schDlSlotInfo[slot]);
420 schUlResAlloc(cell, schInst);
426 /**********************************************************************
428 **********************************************************************/