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);
117 ADD_DELTA_TO_TIME(slotInd, schSlotValue->broadcastTime, PHY_DELTA + SCHED_DELTA);
118 ADD_DELTA_TO_TIME(slotInd, schSlotValue->rarTime, PHY_DELTA + SCHED_DELTA);
119 ADD_DELTA_TO_TIME(slotInd, schSlotValue->dlMsgTime, PHY_DELTA + SCHED_DELTA);
122 /*******************************************************************
134 * @return ROK - success
137 * ****************************************************************/
138 uint8_t schFillBoGrantDlSchedInfo(SchCellCb *cell, DlSchedInfo *dlSchedInfo, DlMsgAlloc *dlMsgAlloc)
140 uint8_t ueIdx, lcIdx;
143 uint16_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);
190 schAllocPucchResource(cell, dlMsgAlloc->crnti, slot);
192 /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
193 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo, \
195 cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
197 /* after allocation is done, unset the bo bit for that ue */
198 UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
204 /*******************************************************************
206 * @brief Handles slot indication at SCH
210 * Function : schProcessSlotInd
213 * Handles TTI indication received from PHY
216 * @return ROK - success
219 * ****************************************************************/
220 uint8_t schProcessSlotInd(SlotIndInfo *slotInd, Inst schInst)
223 uint8_t ssb_rep, ueIdx, lcgIdx;
224 uint16_t slot, sfnSlot = 0;
225 DlSchedInfo dlSchedInfo;
226 DlBrdcstAlloc *dlBrdcstAlloc = NULLP;
227 RarAlloc *rarAlloc = NULLP;
228 DlMsgAlloc *msg4Alloc = NULLP;
229 DlMsgAlloc *dlMsgAlloc = NULLP;
230 SchCellCb *cell = NULLP;
232 memset(&dlSchedInfo,0,sizeof(DlSchedInfo));
233 schCalcSlotValues(*slotInd, &dlSchedInfo.schSlotValue);
234 dlBrdcstAlloc = &dlSchedInfo.brdcstAlloc;
235 dlBrdcstAlloc->ssbTrans = NO_SSB;
236 dlBrdcstAlloc->sib1Trans = NO_SIB1;
238 cell = schCb[schInst].cells[schInst];
239 ssb_rep = cell->cellCfg.ssbSchCfg.ssbPeriod;
240 memcpy(&cell->slotInfo, slotInd, sizeof(SlotIndInfo));
241 dlBrdcstAlloc->ssbIdxSupported = 1;
243 sfnSlot = dlSchedInfo.schSlotValue.broadcastTime.sfn * cell->numSlots +
244 dlSchedInfo.schSlotValue.broadcastTime.slot;
246 slot = dlSchedInfo.schSlotValue.currentTime.slot;
248 dlSchedInfo.cellId = cell->cellId;
250 /* Identify SSB ocassion*/
251 if (sfnSlot % SCH_MIB_TRANS == 0)
253 dlBrdcstAlloc->ssbTrans = SSB_TRANSMISSION;
255 else if (sfnSlot % ssb_rep == 0)
257 dlBrdcstAlloc->ssbTrans = SSB_REPEAT;
261 /* not SSB occassion */
264 /* Identify SIB1 occasions */
265 if(sfnSlot % cell->cellCfg.sib1SchCfg.sib1NewTxPeriod == 0)
267 dlBrdcstAlloc->sib1Trans = SIB1_TRANSMISSION;
269 else if (sfnSlot % cell->cellCfg.sib1SchCfg.sib1RepetitionPeriod == 0)
271 dlBrdcstAlloc->sib1Trans = SIB1_REPITITION;
275 /* not SIB1 occassion */
278 if(dlBrdcstAlloc->ssbTrans || dlBrdcstAlloc->sib1Trans)
280 dlSchedInfo.isBroadcastPres = true;
281 slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
282 ret = schBroadcastAlloc(cell,dlBrdcstAlloc,slot);
285 DU_LOG("\nERROR --> SCH : schBroadcastAlloc failed");
291 if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarInfo != NULLP)
293 slot = dlSchedInfo.schSlotValue.rarTime.slot;
294 SCH_ALLOC(rarAlloc, sizeof(RarAlloc));
297 DU_LOG("\nERROR --> SCH : Memory Allocation failed for RAR alloc");
301 dlSchedInfo.rarAlloc = rarAlloc;
303 /* RAR info is copied, this was earlier filled in schProcessRachInd */
304 memcpy(&rarAlloc->rarInfo,cell->schDlSlotInfo[slot]->rarInfo, sizeof(RarInfo));
306 /* pdcch and pdsch data is filled */
308 cell->schDlSlotInfo[slot]->rarInfo->raRnti,
309 cell->cellCfg.phyCellId,
310 cell->cellCfg.ssbSchCfg.ssbOffsetPointA);
312 SCH_FREE(cell->schDlSlotInfo[slot]->rarInfo,sizeof(RarAlloc));
313 cell->schDlSlotInfo[slot]->rarInfo = NULLP;
317 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
318 (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
320 slot = dlSchedInfo.schSlotValue.dlMsgTime.slot;
322 SCH_ALLOC(msg4Alloc, sizeof(DlMsgAlloc));
325 DU_LOG("\nERROR --> SCH : Memory Allocation failed for msg4 alloc");
329 dlSchedInfo.dlMsgAlloc = msg4Alloc;
331 /* Msg4 info is copied, this was earlier filled in macSchDlRlcBoInfo */
332 memcpy(&msg4Alloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
335 /* pdcch and pdsch data is filled */
336 schDlRsrcAllocMsg4(msg4Alloc, cell, dlSchedInfo.schSlotValue.dlMsgTime.slot);
339 schAllocPucchResource(cell, msg4Alloc->dlMsgInfo.crnti, dlSchedInfo.schSlotValue.dlMsgTime.slot);
341 SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
342 cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
344 /* check if UL grant must be sent in this slot for a SR/BSR that had been received */
345 for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
347 uint32_t totDataReq = 0; /* in bytes */
348 DciInfo *dciInfo = NULLP;
349 SchUeCb *ueCb = NULLP;
351 ueCb = &cell->ueCb[ueIdx];
355 totDataReq = UL_GRANT_SIZE; /*fixing so that all control msgs can be handled in SR */
356 ueCb->srRcvd = false;
359 for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
361 totDataReq+= ueCb->bsrInfo[lcgIdx].dataVol;
362 ueCb->bsrInfo[lcgIdx].dataVol = 0;
364 if(totDataReq > 0) /* UL grant must be provided for this UE in this slot */
366 SchPuschInfo schPuschInfo;
367 memset(&schPuschInfo, 0, sizeof(SchPuschInfo));
369 SCH_ALLOC(dciInfo, sizeof(DciInfo));
372 DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciInfo alloc");
375 memset(dciInfo,0,sizeof(DciInfo));
376 /* update the SFN and SLOT */
377 memcpy(&dlSchedInfo.schSlotValue.ulDciTime, slotInd, sizeof(SlotIndInfo));
378 slot = dlSchedInfo.schSlotValue.ulDciTime.slot;
379 /* Update PUSCH allocation */
380 schFillPuschAlloc(ueCb, slot, totDataReq, &schPuschInfo);
381 /* Fill DCI for UL grant */
382 schFillUlDci(ueCb, schPuschInfo, dciInfo);
383 memcpy(&dciInfo->slotIndInfo, &dlSchedInfo.schSlotValue.ulDciTime, sizeof(SlotIndInfo));
384 dlSchedInfo.ulGrant = dciInfo;
388 /* Check for pending BO grant for LC */
389 if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
390 (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
392 schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc);
395 /* send msg to MAC */
396 ret = sendDlAllocToMac(&dlSchedInfo, schInst);
399 DU_LOG("\nERROR --> SCH : Sending DL Broadcast allocation from SCH to MAC failed");
403 schInitDlSlot(cell->schDlSlotInfo[slot]);
404 schUlResAlloc(cell, schInst);
410 /**********************************************************************
412 **********************************************************************/