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
29 **********************************************************************/
31 /** @file sch_common.c
32 @brief This module performs common scheduling
34 #include "common_def.h"
41 #include "du_app_mac_inf.h"
42 #include "mac_sch_interface.h"
44 #include "sch_utils.h"
46 SchMacUlSchInfoFunc schMacUlSchInfoOpts[] =
54 * @brief common resource allocation for SSB
58 * Function : schBroadcastSsbAlloc
60 * This function handles common scheduling for SSB
62 * @param[in] SchCellCb *cell, cell cb
63 * @param[in] DlBrdcstAlloc *dlBrdcstAlloc, DL brdcst allocation
66 uint8_t schBroadcastSsbAlloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc)
69 uint8_t ssbStartSymb, idx;
71 SchDlSlotInfo *schDlSlotInfo;
76 DU_LOG("\nERROR --> SCH: schBroadcastSsbAlloc() : Cell is NULL");
80 if(dlBrdcstAlloc == NULL)
82 DU_LOG("\nERROR --> SCH: schBroadcastSsbAlloc() : dlBrdcstAlloc is NULL");
86 schDlSlotInfo = cell->schDlSlotInfo[slotTime.slot];
87 ssbStartPrb = cell->cellCfg.ssbSchCfg.ssbOffsetPointA; //+Kssb
88 ssbStartSymb = cell->ssbStartSymbArr[dlBrdcstAlloc->ssbIdxSupported-1]; /*since we are supporting only 1 ssb beam */
90 /* Assign interface structure */
91 for(idx=0; idx<dlBrdcstAlloc->ssbIdxSupported; idx++)
94 ssbInfo.fdAlloc.startPrb = ssbStartPrb;
95 ssbInfo.fdAlloc.numPrb = SCH_SSB_NUM_PRB;
96 ssbInfo.tdAlloc.startSymb = ssbStartSymb;
97 ssbInfo.tdAlloc.numSymb = SCH_SSB_NUM_SYMB;
98 dlBrdcstAlloc->ssbInfo[idx] = ssbInfo;
99 schDlSlotInfo->ssbInfo[idx] = ssbInfo;
102 if((allocatePrbDl(cell, slotTime, ssbStartSymb, SCH_SSB_NUM_SYMB, &ssbInfo.fdAlloc.startPrb, ssbInfo.fdAlloc.numPrb)) != ROK)
104 DU_LOG("\nERROR --> SCH: PRB allocation failed for SSB in SFN:SLOT [%d : %d]", slotTime.sfn, slotTime.slot);
109 schDlSlotInfo->ssbPres = true;
110 schDlSlotInfo->ssbIdxSupported = dlBrdcstAlloc->ssbIdxSupported;
115 * @brief common resource allocation for SIB1
119 * Function : schBroadcastSib1Alloc
121 * This function handles common scheduling for SIB1
123 * @param[in] SchCellCb *cell, cell cb
124 * @param[in] DlBrdcstAlloc *dlBrdcstAlloc, DL brdcst allocation
127 uint8_t schBroadcastSib1Alloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc)
129 uint8_t dmrsStartSymbol, startSymbol, numSymbol ;
131 FreqDomainAlloc freqAlloc;
132 TimeDomainAlloc timeAlloc;
133 SchDlSlotInfo *schDlSlotInfo = NULLP;
137 DU_LOG("\nERROR --> SCH: schBroadcastSsbAlloc() : Cell is NULL");
141 if(dlBrdcstAlloc == NULL)
143 DU_LOG("\nERROR --> SCH: schBroadcastSsbAlloc() : dlBrdcstAlloc is NULL");
147 dmrs = cell->cellCfg.sib1SchCfg.sib1PdschCfg.dmrs;
148 freqAlloc = cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschFreqAlloc.freqAlloc;
149 timeAlloc = cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschTimeAlloc.timeAlloc;
150 schDlSlotInfo = cell->schDlSlotInfo[slotTime.slot];
152 /* Find total symbols used including DMRS */
153 /* If there are no DRMS symbols, findDmrsStartSymbol() returns MAX_SYMB_PER_SLOT,
154 * in that case only PDSCH symbols are marked as occupied */
155 dmrsStartSymbol = findDmrsStartSymbol(dmrs.dlDmrsSymbPos);
156 if(dmrsStartSymbol == MAX_SYMB_PER_SLOT)
158 startSymbol = timeAlloc.startSymb;
159 numSymbol = timeAlloc.numSymb;
161 /* If DMRS symbol is found, mark DMRS and PDSCH symbols as occupied */
164 startSymbol = dmrsStartSymbol;
165 numSymbol = dmrs.nrOfDmrsSymbols + timeAlloc.numSymb;
169 if((allocatePrbDl(cell, slotTime, startSymbol, numSymbol, &freqAlloc.startPrb, freqAlloc.numPrb)) != ROK)
171 DU_LOG("\nERROR --> SCH: PRB allocation failed for SIB1 in SFN:Slot [%d : %d]", slotTime.sfn, slotTime.slot);
175 memcpy(&dlBrdcstAlloc->sib1Alloc.bwp, &cell->cellCfg.sib1SchCfg.bwp, sizeof(BwpCfg));
176 memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg, &cell->cellCfg.sib1SchCfg.sib1PdcchCfg, sizeof(PdcchCfg));
177 memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdschCfg, &cell->cellCfg.sib1SchCfg.sib1PdschCfg, sizeof(PdschCfg));
178 dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg.dci.pdschCfg = &dlBrdcstAlloc->sib1Alloc.sib1PdschCfg;
179 schDlSlotInfo->sib1Pres = true;
183 /*******************************************************************
185 * @brief Handles sending UL scheduler info to MAC
189 * Function : sendUlSchInfoToMac
192 * Sends UL Sch info to MAC from SCH
195 * @return ROK - success
198 * ****************************************************************/
199 int sendUlSchInfoToMac(UlSchedInfo *ulSchedInfo, Inst inst)
203 memset(&pst, 0, sizeof(Pst));
204 FILL_PST_SCH_TO_MAC(pst, inst);
205 pst.event = EVENT_UL_SCH_INFO;
207 return(*schMacUlSchInfoOpts[pst.selector])(&pst, ulSchedInfo);
211 * @brief Function to fill Pucch Format 0
215 * Function : fillPucchFormat0
217 * Function to fill Pucch format 0
219 * @param[in] SchPucchInfo pointer, SchPucchResrcInfo pointer
223 void fillPucchFormat0(SchPucchInfo *ulSchedPucch, SchPucchResrcInfo *resrcInfo)
225 if(resrcInfo->SchPucchFormat.format0)
227 ulSchedPucch->fdAlloc.numPrb = PUCCH_NUM_PRB_FORMAT_0_1_4;
228 ulSchedPucch->pucchFormat = PUCCH_FORMAT_0;
229 ulSchedPucch->initialCyclicShift = resrcInfo->SchPucchFormat.format0->initialCyclicShift;
230 ulSchedPucch->tdAlloc.numSymb = resrcInfo->SchPucchFormat.format0->numSymbols;
231 ulSchedPucch->tdAlloc.startSymb = resrcInfo->SchPucchFormat.format0->startSymbolIdx;
236 * @brief Function to fill Pucch Format 1
240 * Function : fillPucchFormat1
242 * Function to fill Pucch format 1
244 * @param[in] SchPucchInfo pointer, SchPucchResrcInfo pointer
248 void fillPucchFormat1(SchPucchInfo *ulSchedPucch, SchPucchResrcInfo *resrcInfo)
250 if(resrcInfo->SchPucchFormat.format1)
252 ulSchedPucch->fdAlloc.numPrb = PUCCH_NUM_PRB_FORMAT_0_1_4;
253 ulSchedPucch->pucchFormat = PUCCH_FORMAT_1;
254 ulSchedPucch->initialCyclicShift = resrcInfo->SchPucchFormat.format1->initialCyclicShift;
255 ulSchedPucch->tdAlloc.numSymb = resrcInfo->SchPucchFormat.format1->numSymbols;
256 ulSchedPucch->tdAlloc.startSymb = resrcInfo->SchPucchFormat.format1->startSymbolIdx;
257 ulSchedPucch->timeDomOCC = resrcInfo->SchPucchFormat.format1->timeDomOCC;
262 * @brief Function to fill Pucch format for UL Sched Info
266 * Function : fillUlSchedPucchFormat
268 * Function to fill Pucch format for UL Sched Info
270 * @param[in] pucchFormat , SchPucchInfo pointer,
271 * @param[in] SchPucchFormatCfg pointer, SchPucchResrcInfo pointer
275 uint8_t fillUlSchedPucchFormat(uint8_t pucchFormat, SchPucchInfo *ulSchedPucch,\
276 SchPucchResrcInfo *resrcInfo, SchPucchFormatCfg *formatCfg)
285 fillPucchFormat0(ulSchedPucch, resrcInfo);
292 fillPucchFormat1(ulSchedPucch, resrcInfo);
296 memcpy(&ulSchedPucch->cmnFormatCfg, formatCfg, sizeof(SchPucchFormatCfg));
299 }/* To Add support for more Pucch Format */
302 DU_LOG("\nERROR --> SCH : Invalid PUCCH format[%d] in fillUlSchedPucchFormatCfg()", pucchFormat);
310 * @brief Function to fill Pucch Dedicated Cfg for UL Sched Info
314 * Function : fillUlSchedPucchDedicatedCfg
316 * Function to fill Pucch Dedicated Cfg for UL Sched Info
318 * @param[in] pucchFormat to be filled
319 * @param[in] SchPucchFormatCfg pointer, SchPucchCfg pointer
323 uint8_t fillUlSchedPucchDedicatedCfg(uint16_t numSlots, SchPucchCfg *pucchDedCfg,\
324 SlotTimingInfo *slotInfo, SchPucchInfo *ulSchedPucch)
326 uint8_t ret, resrcSetIdx, resrcIdx, schedReqIdx, srPeriodicity = 0;
327 uint16_t srOffset = 0;
330 if(pucchDedCfg->resrcSet && pucchDedCfg->resrc)
332 //Assuming one entry in the list
333 for(resrcSetIdx = 0; resrcSetIdx < pucchDedCfg->resrcSet->resrcSetToAddModListCount; resrcSetIdx++)
335 for(resrcIdx = 0; resrcIdx < pucchDedCfg->resrc->resrcToAddModListCount; resrcIdx++)
337 if(pucchDedCfg->resrcSet->resrcSetToAddModList[resrcSetIdx].resrcList[resrcSetIdx] ==\
338 pucchDedCfg->resrc->resrcToAddModList[resrcIdx].resrcId)
340 ulSchedPucch->intraFreqHop = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].intraFreqHop;
341 ulSchedPucch->secondPrbHop = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].secondPrbHop;
342 ulSchedPucch->fdAlloc.startPrb = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].startPrb;
343 ulSchedPucch->pucchFormat = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].pucchFormat;
344 ret = fillUlSchedPucchFormat(ulSchedPucch->pucchFormat, ulSchedPucch,\
345 &pucchDedCfg->resrc->resrcToAddModList[resrcIdx], NULLP);
352 if(pucchDedCfg->format1)
354 memset(&ulSchedPucch->cmnFormatCfg, 0, sizeof(SchPucchFormatCfg));
355 ret = fillUlSchedPucchFormat(ulSchedPucch->pucchFormat, ulSchedPucch, NULLP, pucchDedCfg->format1);
360 /* setting SR and UCI flag */
361 if(pucchDedCfg->schedReq)
363 for(schedReqIdx = 0; schedReqIdx < pucchDedCfg->schedReq->schedAddModListCount; schedReqIdx++)
365 srPeriodicity = pucchDedCfg->schedReq->schedAddModList[schedReqIdx].periodicity;
366 srOffset = pucchDedCfg->schedReq->schedAddModList[schedReqIdx].offset;
369 if(((numSlots * slotInfo->sfn + slotInfo->slot - srOffset) % srPeriodicity) == 0)
371 ulSchedPucch->srFlag = true;
372 ulSchedPucch->uciFlag = true;
379 * @brief Function to fill Pucch Resource Info
383 * Function : fillPucchResourceInfo
385 * Function to fill Pucch Resource Info
387 * @param[in] SchPucchInfo *schPucchInfo, Inst inst
388 * @return ROK/RFAILED
391 uint16_t fillPucchResourceInfo(SchPucchInfo *schPucchInfo, Inst inst)
393 uint8_t ret = ROK, ueIdx = 0, pucchIdx = 0;
394 SchCellCb *cell = schCb[inst].cells[inst];
395 SchPucchCfgCmn *pucchCfg = NULLP;
396 SchBwpParams *ulBwp = NULLP;
398 GET_UE_IDX(schPucchInfo->rnti, ueIdx);
399 if(cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres)
401 /* fill pucch dedicated cfg */
402 ret = fillUlSchedPucchDedicatedCfg(cell->numSlots,\
403 &cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg, &cell->slotInfo, schPucchInfo);
406 memset(schPucchInfo, 0, sizeof(SchPucchInfo));
407 DU_LOG("\nERROR --> SCH : Filling PUCCH dedicated cfg failed at fillPucchResourceInfo()");
413 /* fill pucch common cfg */
414 /* derive pucchResourceSet from schCellCfg */
415 pucchCfg = &cell->cellCfg.schInitialUlBwp.pucchCommon;
416 pucchIdx = pucchCfg->pucchResourceCommon;
417 ulBwp = &cell->cellCfg.schInitialUlBwp.bwp;
418 schPucchInfo->fdAlloc.startPrb = ulBwp->freqAlloc.startPrb + pucchResourceSet[pucchIdx][3];
419 schPucchInfo->fdAlloc.numPrb = PUCCH_NUM_PRB_FORMAT_0_1_4;
420 schPucchInfo->tdAlloc.startSymb = pucchResourceSet[pucchIdx][1];
421 schPucchInfo->tdAlloc.numSymb = pucchResourceSet[pucchIdx][2];
422 schPucchInfo->pucchFormat = pucchResourceSet[pucchIdx][0];
424 /* set SR and UCI flag to false */
425 schPucchInfo->srFlag = true;
426 schPucchInfo->uciFlag = true;
428 /* set HARQ flag to true */
429 schPucchInfo->harqFlag = true;
430 schPucchInfo->numHarqBits = 1; /* 1 bit for HARQ */
436 * @brief resource allocation for UL
440 * Function : schUlResAlloc
442 * This function handles UL Resource allocation
444 * @param[in] SchCellCb *cell, cellCb
447 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst)
450 UlSchedInfo ulSchedInfo;
451 SchUlSlotInfo *schUlSlotInfo = NULLP;
452 SlotTimingInfo ulTimingInfo;
453 memset(&ulSchedInfo, 0, sizeof(UlSchedInfo));
456 ADD_DELTA_TO_TIME(cell->slotInfo,ulTimingInfo,PHY_DELTA_UL+SCHED_DELTA);
458 ulSchedInfo.cellId = cell->cellId;
459 ulSchedInfo.slotIndInfo.cellId = ulSchedInfo.cellId;
460 ulSchedInfo.slotIndInfo.sfn = ulTimingInfo.sfn;
461 ulSchedInfo.slotIndInfo.slot = ulTimingInfo.slot;
463 /* Schedule resources for PRACH */
464 if(cell->firstSib1Transmitted)
465 schPrachResAlloc(cell, &ulSchedInfo, ulTimingInfo);
467 schUlSlotInfo = cell->schUlSlotInfo[ulTimingInfo.slot];
468 if(schUlSlotInfo->schPuschInfo)
470 ulSchedInfo.crnti = schUlSlotInfo->schPuschInfo->crnti;
471 ulSchedInfo.dataType |= SCH_DATATYPE_PUSCH;
472 memcpy(&ulSchedInfo.schPuschInfo, schUlSlotInfo->schPuschInfo,
473 sizeof(SchPuschInfo));
474 SCH_FREE(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
475 schUlSlotInfo->schPuschInfo = NULL;
478 if(schUlSlotInfo->pucchPres)
480 ulSchedInfo.dataType |= SCH_DATATYPE_UCI;
481 fillPucchResourceInfo(&schUlSlotInfo->schPucchInfo, schInst);
482 memcpy(&ulSchedInfo.schPucchInfo, &schUlSlotInfo->schPucchInfo,
483 sizeof(SchPucchInfo));
484 memset(&schUlSlotInfo->schPucchInfo, 0, sizeof(SchPucchInfo));
488 ret = sendUlSchInfoToMac(&ulSchedInfo, schInst);
491 DU_LOG("\nERROR --> SCH : Sending UL Sch info from SCH to MAC failed");
494 schInitUlSlot(schUlSlotInfo);
498 /*******************************************************************
500 * @brief Fills pdcch and pdsch info for msg4
504 * Function : schDlRsrcAllocMsg4
507 * Fills pdcch and pdsch info for msg4
510 * @return ROK - success
513 * ****************************************************************/
514 uint8_t schDlRsrcAllocMsg4(SchCellCb *cell, SlotTimingInfo slotTime, DlMsgAlloc *msg4Alloc)
516 uint8_t coreset0Idx = 0;
517 uint8_t firstSymbol = 0;
518 uint8_t numSymbols = 0;
519 uint8_t mcs = DEFAULT_MCS; /* MCS fixed to 4 */
520 uint8_t dmrsStartSymbol = 0, startSymbol = 0, numSymbol = 0;
523 SchBwpDlCfg *initialBwp = NULLP;
524 PdcchCfg *pdcch = NULLP;
525 PdschCfg *pdsch = NULLP;
530 DU_LOG("\nERROR --> SCH: schDlRsrcAllocMsg4() : Cell is NULL");
534 if(msg4Alloc == NULL)
536 DU_LOG("\nERROR --> SCH: schDlRsrcAllocMsg4() : msg4Alloc is NULL");
540 pdcch = &msg4Alloc->dlMsgPdcchCfg;
541 pdsch = &msg4Alloc->dlMsgPdschCfg;
542 bwp = &msg4Alloc->bwp;
543 initialBwp = &cell->cellCfg.schInitialDlBwp;
544 coreset0Idx = initialBwp->pdcchCommon.commonSearchSpace.coresetId;
546 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
547 numRbs = coresetIdxTable[coreset0Idx][1];
548 numSymbols = coresetIdxTable[coreset0Idx][2];
550 /* calculate time domain parameters */
551 uint16_t mask = 0x2000;
552 for(firstSymbol=0; firstSymbol<MAX_SYMB_PER_SLOT; firstSymbol++)
554 if(initialBwp->pdcchCommon.commonSearchSpace.monitoringSymbol & mask)
561 bwp->freqAlloc.numPrb = initialBwp->bwp.freqAlloc.numPrb;
562 bwp->freqAlloc.startPrb = initialBwp->bwp.freqAlloc.startPrb;
563 bwp->subcarrierSpacing = initialBwp->bwp.scs;
564 bwp->cyclicPrefix = initialBwp->bwp.cyclicPrefix;
566 /* fill the PDCCH PDU */
567 pdcch->coresetCfg.startSymbolIndex = firstSymbol;
568 pdcch->coresetCfg.durationSymbols = numSymbols;
569 memcpy(pdcch->coresetCfg.freqDomainResource, \
570 cell->cellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
572 pdcch->coresetCfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
573 pdcch->coresetCfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
574 pdcch->coresetCfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
575 pdcch->coresetCfg.coreSetType = 0;
576 pdcch->coresetCfg.coreSetSize = numRbs;
577 pdcch->coresetCfg.shiftIndex = cell->cellCfg.phyCellId;
578 pdcch->coresetCfg.precoderGranularity = 0; /* sameAsRegBundle */
580 pdcch->dci.rnti = cell->schDlSlotInfo[slotTime.slot]->dlMsgInfo->crnti;
581 pdcch->dci.scramblingId = cell->cellCfg.phyCellId;
582 pdcch->dci.scramblingRnti = 0;
583 pdcch->dci.cceIndex = 4; /* considering SIB1 is sent at cce 0-1-2-3 */
584 pdcch->dci.aggregLevel = 4;
585 pdcch->dci.beamPdcchInfo.numPrgs = 1;
586 pdcch->dci.beamPdcchInfo.prgSize = 1;
587 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
588 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
589 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
590 pdcch->dci.txPdcchPower.powerValue = 0;
591 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
593 /* fill the PDSCH PDU */
595 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
596 pdsch->rnti = cell->schDlSlotInfo[slotTime.slot]->dlMsgInfo->crnti;
598 pdsch->numCodewords = 1;
599 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
601 pdsch->codeword[cwCount].targetCodeRate = 308;
602 pdsch->codeword[cwCount].qamModOrder = 2;
603 pdsch->codeword[cwCount].mcsIndex = mcs; /* mcs configured to 4 */
604 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
605 pdsch->codeword[cwCount].rvIndex = 0;
606 tbSize = schCalcTbSize(msg4Alloc->dlMsgInfo.dlMsgPduLen + TX_PAYLOAD_HDR_LEN); /* MSG4 size + FAPI header size*/
607 pdsch->codeword[cwCount].tbSize = tbSize;
609 pdsch->dataScramblingId = cell->cellCfg.phyCellId;
610 pdsch->numLayers = 1;
611 pdsch->transmissionScheme = 0;
613 pdsch->dmrs.dlDmrsSymbPos = 4; /* Bitmap value 00000000000100 i.e. using 3rd symbol for PDSCH DMRS */
614 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
615 pdsch->dmrs.dlDmrsScramblingId = cell->cellCfg.phyCellId;
616 pdsch->dmrs.scid = 0;
617 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
618 pdsch->dmrs.dmrsPorts = 0;
619 pdsch->dmrs.mappingType = DMRS_MAP_TYPE_A; /* Setting to Type-A */
620 pdsch->dmrs.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
621 pdsch->dmrs.dmrsAddPos = DMRS_ADDITIONAL_POS;
623 pdsch->pdschTimeAlloc.timeAlloc.startSymb = 3; /* spec-38.214, Table 5.1.2.1-1 */
624 pdsch->pdschTimeAlloc.timeAlloc.numSymb = NUM_PDSCH_SYMBOL;
626 pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
627 pdsch->pdschFreqAlloc.freqAlloc.startPrb = MAX_NUM_RB;
628 pdsch->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize, mcs, NUM_PDSCH_SYMBOL);
629 pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
631 /* Find total symbols occupied including DMRS */
632 dmrsStartSymbol = findDmrsStartSymbol(pdsch->dmrs.dlDmrsSymbPos);
633 /* If there are no DRMS symbols, findDmrsStartSymbol() returns MAX_SYMB_PER_SLOT,
634 * in that case only PDSCH symbols are marked as occupied */
635 if(dmrsStartSymbol == MAX_SYMB_PER_SLOT)
637 startSymbol = pdsch->pdschTimeAlloc.timeAlloc.startSymb;
638 numSymbol = pdsch->pdschTimeAlloc.timeAlloc.numSymb;
640 /* If DMRS symbol is found, mark DMRS and PDSCH symbols as occupied */
643 startSymbol = dmrsStartSymbol;
644 numSymbol = pdsch->dmrs.nrOfDmrsSymbols + pdsch->pdschTimeAlloc.timeAlloc.numSymb;
647 /* Allocate the number of PRBs required for RAR PDSCH */
648 if((allocatePrbDl(cell, slotTime, startSymbol, numSymbol,\
649 &pdsch->pdschFreqAlloc.freqAlloc.startPrb, pdsch->pdschFreqAlloc.freqAlloc.numPrb)) != ROK)
651 DU_LOG("\nERROR --> SCH : Resource allocation failed for MSG4");
655 pdsch->beamPdschInfo.numPrgs = 1;
656 pdsch->beamPdschInfo.prgSize = 1;
657 pdsch->beamPdschInfo.digBfInterfaces = 0;
658 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
659 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
660 pdsch->txPdschPower.powerControlOffset = 0;
661 pdsch->txPdschPower.powerControlOffsetSS = 0;
663 pdcch->dci.pdschCfg = pdsch;
668 uint16_t schAllocPucchResource(SchCellCb *cell, uint16_t crnti, uint16_t slot)
670 uint8_t k1 = SCH_DEFAULT_K1, ueIdx = 0, dlToUlAckIdx;
671 uint16_t pucchSlot = 0;
672 SchUlSlotInfo *schUlSlotInfo = NULLP;
673 SchPucchCfg *schPucchCfg = NULLP;
675 GET_UE_IDX(crnti, ueIdx);
676 if(cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres)
678 schPucchCfg = &(cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg);
679 if(schPucchCfg->dlDataToUlAck)
681 for(dlToUlAckIdx = 0; dlToUlAckIdx < schPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; dlToUlAckIdx++)
683 //For now considering only the first value in the list
684 k1 = schPucchCfg->dlDataToUlAck->dlDataToUlAckList[dlToUlAckIdx];
690 pucchSlot = (slot + k1) % cell->numSlots;
691 schUlSlotInfo = cell->schUlSlotInfo[pucchSlot];
692 memset(&schUlSlotInfo->schPucchInfo, 0, sizeof(SchPucchInfo));
694 schUlSlotInfo->pucchPres = true;
695 schUlSlotInfo->schPucchInfo.rnti = crnti;
700 /*******************************************************************
702 * @brief Fills pdcch and pdsch info for dedicated DL msg
706 * Function : schDlRsrcAllocDlMsg
709 * Fills pdcch and pdsch info for dl msg
712 * @return ROK - success
715 * ****************************************************************/
716 uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t crnti,
717 uint32_t tbSize, DlMsgAlloc *dlMsgAlloc, uint16_t startPRB)
720 PdcchCfg *pdcch = NULLP;
721 PdschCfg *pdsch = NULLP;
724 SchControlRsrcSet coreset1;
725 SchPdschConfig pdschCfg;
726 uint8_t dmrsStartSymbol, startSymbol, numSymbol;
728 pdcch = &dlMsgAlloc->dlMsgPdcchCfg;
729 pdsch = &dlMsgAlloc->dlMsgPdschCfg;
730 bwp = &dlMsgAlloc->bwp;
732 GET_UE_IDX(crnti, ueIdx);
733 ueCb = cell->ueCb[ueIdx-1];
734 coreset1 = ueCb.ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
735 pdschCfg = ueCb.ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
738 bwp->freqAlloc.numPrb = MAX_NUM_RB;
739 bwp->freqAlloc.startPrb = 0;
740 bwp->subcarrierSpacing = cell->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
741 bwp->cyclicPrefix = cell->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
743 /* fill the PDCCH PDU */
744 //Considering coreset1 also starts from same symbol as coreset0
745 pdcch->coresetCfg.startSymbolIndex = coresetIdxTable[0][3];
746 pdcch->coresetCfg.durationSymbols = coreset1.duration;
747 memcpy(pdcch->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
748 pdcch->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
749 pdcch->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
750 pdcch->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
751 pdcch->coresetCfg.coreSetType = 1; /* non PBCH coreset */
752 //Considering number of RBs in coreset1 is same as coreset0
753 pdcch->coresetCfg.coreSetSize = coresetIdxTable[0][1];
754 pdcch->coresetCfg.shiftIndex = cell->cellCfg.phyCellId;
755 pdcch->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
757 pdcch->dci.rnti = ueCb.crnti;
758 pdcch->dci.scramblingId = cell->cellCfg.phyCellId;
759 pdcch->dci.scramblingRnti = 0;
760 pdcch->dci.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
761 pdcch->dci.aggregLevel = 4;
762 pdcch->dci.beamPdcchInfo.numPrgs = 1;
763 pdcch->dci.beamPdcchInfo.prgSize = 1;
764 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
765 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
766 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
767 pdcch->dci.txPdcchPower.powerValue = 0;
768 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
770 /* fill the PDSCH PDU */
772 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
773 pdsch->rnti = ueCb.crnti;
775 pdsch->numCodewords = 1;
776 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
778 pdsch->codeword[cwCount].targetCodeRate = 308;
779 pdsch->codeword[cwCount].qamModOrder = ueCb.ueCfg.dlModInfo.modOrder;
780 pdsch->codeword[cwCount].mcsIndex = ueCb.ueCfg.dlModInfo.mcsIndex;
781 pdsch->codeword[cwCount].mcsTable = ueCb.ueCfg.dlModInfo.mcsTable;
782 pdsch->codeword[cwCount].rvIndex = 0;
784 tbSize +=TX_PAYLOAD_HDR_LEN;
785 pdsch->codeword[cwCount].tbSize = tbSize;
787 pdsch->dataScramblingId = cell->cellCfg.phyCellId;
788 pdsch->numLayers = 1;
789 pdsch->transmissionScheme = 0;
791 pdsch->dmrs.dlDmrsSymbPos = 4; /* Bitmap value 00000000000100 i.e. using 3rd symbol for PDSCH DMRS */
792 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
793 pdsch->dmrs.dlDmrsScramblingId = cell->cellCfg.phyCellId;
794 pdsch->dmrs.scid = 0;
795 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
796 pdsch->dmrs.dmrsPorts = 0;
797 pdsch->dmrs.mappingType = DMRS_MAP_TYPE_A; /* Setting to Type-A */
798 pdsch->dmrs.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
799 pdsch->dmrs.dmrsAddPos = pdschCfg.dmrsDlCfgForPdschMapTypeA.addPos;
801 pdsch->pdschTimeAlloc.timeAlloc.startSymb = pdschCfg.timeDomRsrcAllociList[0].startSymbol;
802 pdsch->pdschTimeAlloc.timeAlloc.numSymb = pdschCfg.timeDomRsrcAllociList[0].symbolLength;
804 pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
805 pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
806 pdsch->pdschFreqAlloc.freqAlloc.startPrb = startPRB; /*Start PRB will be already known*/
807 pdsch->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize, ueCb.ueCfg.dlModInfo.mcsIndex, \
808 pdschCfg.timeDomRsrcAllociList[0].symbolLength);
810 /* Find total symbols occupied including DMRS */
811 dmrsStartSymbol = findDmrsStartSymbol(pdsch->dmrs.dlDmrsSymbPos);
812 /* If there are no DRMS symbols, findDmrsStartSymbol() returns MAX_SYMB_PER_SLOT,
813 * in that case only PDSCH symbols are marked as occupied */
814 if(dmrsStartSymbol == MAX_SYMB_PER_SLOT)
816 startSymbol = pdsch->pdschTimeAlloc.timeAlloc.startSymb;
817 numSymbol = pdsch->pdschTimeAlloc.timeAlloc.numSymb;
819 /* If DMRS symbol is found, mark DMRS and PDSCH symbols as occupied */
822 startSymbol = dmrsStartSymbol;
823 numSymbol = pdsch->dmrs.nrOfDmrsSymbols + pdsch->pdschTimeAlloc.timeAlloc.numSymb;
826 /* Allocate the number of PRBs required for DL PDSCH */
827 if((allocatePrbDl(cell, slotTime, startSymbol, numSymbol,\
828 &pdsch->pdschFreqAlloc.freqAlloc.startPrb, pdsch->pdschFreqAlloc.freqAlloc.numPrb)) != ROK)
830 DU_LOG("\nERROR --> SCH : allocatePrbDl() failed for DL MSG");
834 pdsch->beamPdschInfo.numPrgs = 1;
835 pdsch->beamPdschInfo.prgSize = 1;
836 pdsch->beamPdschInfo.digBfInterfaces = 0;
837 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
838 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
839 pdsch->txPdschPower.powerControlOffset = 0;
840 pdsch->txPdschPower.powerControlOffsetSS = 0;
842 pdcch->dci.pdschCfg = pdsch;
846 /*******************************************************************
848 * @brief Fills k0 and k1 information table for FDD
852 * Function : BuildK0K1TableForFdd
855 * Fills k0 and k1 information table for FDD
857 * @params[in] SchCellCb *cell,SchK0K1TimingInfoTbl *k0K1InfoTbl,bool
858 * pdschCfgCmnPres,uint8_t numTimeDomAlloc, SchPdschCfgCmnTimeDomRsrcAlloc
859 * cmnTimeDomRsrcAllocList[], SchPdschTimeDomRsrcAlloc
860 * dedTimeDomRsrcAllocList[], uint8_t ulAckListCount, uint8_t *UlAckTbl
861 * @return ROK - success
864 * ****************************************************************/
865 void BuildK0K1TableForFdd(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres,SchPdschCfgCmn pdschCmnCfg,\
866 SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl)
869 uint8_t k1TmpVal =0, cfgIdx=0;
870 uint8_t slotIdx=0, k0Index=0, k1Index=0, numK0=0, numK1=0, numTimeDomAlloc=0;
872 /* TODO Commented these below lines for resolving warnings. Presently these variable are not
873 * required but this will require for harq processing */
874 // uint8_t k0TmpVal = 0;
875 // SchPdschCfgCmnTimeDomRsrcAlloc cmnTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
876 // SchPdschTimeDomRsrcAlloc dedTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
878 /* Initialization the structure and storing the total slot values. */
879 memset(k0K1InfoTbl, 0, sizeof(SchK0K1TimingInfoTbl));
880 k0K1InfoTbl->tblSize = cell->numSlots;
882 /* Storing time domain resource allocation list based on common or dedicated configuration. */
883 if(pdschCfgCmnPres == true)
885 numTimeDomAlloc = pdschCmnCfg.numTimeDomAlloc;
886 for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
888 /*TODO uncomment this line during harq processing */
889 //cmnTimeDomRsrcAllocList[cfgIdx] = pdschCmnCfg.timeDomRsrcAllocList[cfgIdx];
894 numTimeDomAlloc = pdschDedCfg.numTimeDomRsrcAlloc;
895 for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
897 /*TODO uncomment this line during harq processing */
898 //dedTimeDomRsrcAllocList[cfgIdx] = pdschDedCfg.timeDomRsrcAllociList[cfgIdx];
902 /* Checking all the slots for K0 and K1 values. */
903 for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
906 /* Storing the values of k0 based on time domain resource
907 * allocation list. If the value is unavailable then fill default values,
908 * As per 38.331 PDSCH-TimeDomainResourceAllocation field descriptions. */
909 for(k0Index = 0; ((k0Index < numTimeDomAlloc) && (k0Index < MAX_NUM_K0_IDX)); k0Index++)
911 /* TODO These if 0 we will remove during harq processing */
913 if(pdschCfgCmnPres == true)
915 k0TmpVal = cmnTimeDomRsrcAllocList[k0Index].k0;
919 if(dedTimeDomRsrcAllocList[k0Index].k0 != NULLP)
921 k0TmpVal = *(dedTimeDomRsrcAllocList[k0Index].k0);
925 k0TmpVal = DEFAULT_K0_VALUE;
929 /* Checking all the Ul Alloc values. If value is less than MIN_NUM_K1_IDX
930 * then skip else continue storing the values. */
932 for(k1Index = 0; k1Index < ulAckListCount; k1Index++)
934 k1TmpVal = UlAckTbl[k1Index];
935 if(k1TmpVal <= MIN_NUM_K1_IDX)
940 k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.k1Indexes[numK1++] = k1Index;
941 /* TODO Store K1 index where harq feedback will be received in harq table. */
945 k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.numK1 = numK1;
946 k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k0Index = k0Index;
952 k0K1InfoTbl->k0k1TimingInfo[slotIdx].numK0 = numK0;
957 /*******************************************************************
959 * @brief Fills k0 and k1 information table
963 * Function : BuildK0K1Table
966 * Fills K0 and k1 information table
968 * @params[in] SchCellCb *cell,SchK0K1TimingInfoTbl *k0K1InfoTbl,bool
969 * pdschCfgCmnPres,uint8_t numTimeDomAlloc, SchPdschCfgCmnTimeDomRsrcAlloc
970 * cmnTimeDomRsrcAllocList[], SchPdschTimeDomRsrcAlloc
971 * dedTimeDomRsrcAllocList[], uint8_t ulAckListCount, uint8_t *UlAckTbl
972 * @return ROK - success
975 * ****************************************************************/
976 void BuildK0K1Table(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres, SchPdschCfgCmn pdschCmnCfg,\
977 SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl)
982 bool ulSlotPresent = false;
983 uint8_t k0TmpVal = 0, k1TmpVal =0, tmpSlot=0, startSymbol=0, endSymbol=0, checkSymbol=0;
984 uint8_t slotIdx=0, k0Index=0, k1Index=0, numK0=0, numK1=0, cfgIdx=0, numTimeDomAlloc =0, totalCfgSlot =0;
985 SchPdschCfgCmnTimeDomRsrcAlloc cmnTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
986 SchPdschTimeDomRsrcAlloc dedTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
989 if(cell->cellCfg.dupMode == DUPLEX_MODE_FDD)
991 BuildK0K1TableForFdd(cell, k0K1InfoTbl, pdschCfgCmnPres, pdschCmnCfg, pdschDedCfg, ulAckListCount, UlAckTbl);
997 /* Initialization the K0K1 structure, total num of slot and calculating the slot pattern length. */
998 memset(k0K1InfoTbl, 0, sizeof(SchK0K1TimingInfoTbl));
999 k0K1InfoTbl->tblSize = cell->numSlots;
1000 totalCfgSlot = calculateSlotPatternLength(cell->cellCfg.ssbSchCfg.scsCommon, cell->cellCfg.tddCfg.tddPeriod);
1002 /* Storing time domain resource allocation list based on common or
1003 * dedicated configuration availability. */
1004 if(pdschCfgCmnPres == true)
1006 numTimeDomAlloc = pdschCmnCfg.numTimeDomAlloc;
1007 for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
1009 cmnTimeDomRsrcAllocList[cfgIdx] = pdschCmnCfg.timeDomRsrcAllocList[cfgIdx];
1014 numTimeDomAlloc = pdschDedCfg.numTimeDomRsrcAlloc;
1015 for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
1017 dedTimeDomRsrcAllocList[cfgIdx] = pdschDedCfg.timeDomRsrcAllociList[cfgIdx];
1021 /* Checking all possible indexes for K0 and K1 values. */
1022 for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
1024 /* If current slot is UL or FLEXI then Skip because PDCCH is sent only in DL slots. */
1025 slotCfg = schGetSlotSymbFrmt(slotIdx%totalCfgSlot, cell->slotFrmtBitMap);
1026 if(slotCfg == UL_SLOT || slotCfg == FLEXI_SLOT)
1031 /* Storing K0 , start symbol and length symbol for further processing.
1032 * If K0 value is not available then we can fill the default values
1033 * given in spec 38.331. */
1035 for(k0Index = 0; ((k0Index < numTimeDomAlloc) && (k0Index < MAX_NUM_K0_IDX)); k0Index++)
1037 if(pdschCfgCmnPres == true)
1039 k0TmpVal = cmnTimeDomRsrcAllocList[k0Index].k0;
1040 startSymbol = cmnTimeDomRsrcAllocList[k0Index].startSymbol;
1041 endSymbol = startSymbol + cmnTimeDomRsrcAllocList[k0Index].lengthSymbol;
1045 if(dedTimeDomRsrcAllocList[k0Index].k0 != NULLP)
1047 k0TmpVal = *(dedTimeDomRsrcAllocList[k0Index].k0);
1051 k0TmpVal = DEFAULT_K0_VALUE;
1053 startSymbol = dedTimeDomRsrcAllocList[k0Index].startSymbol;
1054 endSymbol = startSymbol + dedTimeDomRsrcAllocList[k0Index].symbolLength;
1057 /* If current slot + k0 is UL then skip the slot
1058 * else if it is DL slot then continue the next steps
1059 * else if it is a FLEXI slot then check symbols of slot, It should not
1060 * contain any UL slot. */
1061 tmpSlot = (slotIdx+k0TmpVal) % totalCfgSlot;
1062 slotCfg = schGetSlotSymbFrmt(tmpSlot, cell->slotFrmtBitMap);
1063 if(slotCfg == UL_SLOT)
1067 if(slotCfg == FLEXI_SLOT)
1069 for(checkSymbol = startSymbol; checkSymbol<endSymbol; checkSymbol ++)
1071 slotCfg = cell->cellCfg.tddCfg.slotCfg[tmpSlot][checkSymbol];
1072 if(slotCfg == UL_SLOT)
1079 /* If current slot + k0 + k1 is a DL slot then skip the slot
1080 * else if it is UL slot then store the information
1081 * else if it is FLEXI slot then check the symbols, it must have
1082 * at least one UL symbol. */
1084 for(k1Index = 0; k1Index < ulAckListCount; k1Index++)
1086 k1TmpVal = UlAckTbl[k1Index];
1087 if(k1TmpVal > MIN_NUM_K1_IDX)
1089 tmpSlot = (slotIdx+k0TmpVal+k1TmpVal) % totalCfgSlot;
1090 slotCfg = schGetSlotSymbFrmt(tmpSlot, cell->slotFrmtBitMap);
1091 if(slotCfg == DL_SLOT)
1095 if(slotCfg == FLEXI_SLOT)
1097 for(checkSymbol = 0; checkSymbol< MAX_SYMB_PER_SLOT;checkSymbol++)
1099 if(cell->cellCfg.tddCfg.slotCfg[tmpSlot][checkSymbol] == UL_SLOT)
1101 ulSlotPresent = true;
1106 if(ulSlotPresent == true || slotCfg == UL_SLOT)
1108 k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.k1Indexes[numK1++] = k1Index;
1109 /* TODO Store K1 index where harq feedback will be received
1115 /* Store all the values if all condition satisfies. */
1118 k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.numK1 = numK1;
1119 k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k0Index = k0Index;
1125 k0K1InfoTbl->k0k1TimingInfo[slotIdx].numK0 = numK0;
1132 /*******************************************************************
1134 * @brief Fills K2 information table for FDD
1138 * Function : BuildK2InfoTableForFdd
1141 * Fills K2 information table for FDD
1143 * @params[in] SchCellCb *cell,SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[],
1144 * uint16_t puschSymTblSize,SchK2TimingInfoTbl *k2InfoTbl
1145 * @return ROK - success
1148 * ****************************************************************/
1149 void BuildK2InfoTableForFdd(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], uint16_t puschSymTblSize,\
1150 SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl)
1152 uint16_t slotIdx=0, k2Index=0, k2TmpIdx=0, msg3K2TmpIdx=0;
1154 /* Initialization the structure and storing the total slot values. */
1155 memset(k2InfoTbl, 0, sizeof(SchK2TimingInfoTbl));
1156 k2InfoTbl->tblSize = cell->numSlots;
1158 msg3K2InfoTbl->tblSize = cell->numSlots;
1160 /* Checking all possible indexes for K2. */
1161 for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
1163 /* Storing K2 values. */
1164 for(k2Index = 0; ((k2Index < puschSymTblSize) && (k2Index < MAX_NUM_K2_IDX)); k2Index++)
1166 k2TmpIdx= k2InfoTbl->k2TimingInfo[slotIdx].numK2;
1167 k2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[k2TmpIdx] = k2Index;
1168 k2InfoTbl->k2TimingInfo[slotIdx].numK2++;
1170 /* Updating K2 values for MSG3 */
1173 msg3K2TmpIdx = msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2;
1174 msg3K2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[msg3K2TmpIdx] = k2Index;
1175 msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2++;
1181 /*******************************************************************
1183 * @brief Fills K2 information table
1187 * Function : BuildK2InfoTable
1190 * Fills K2 information table
1192 * @params[in] SchCellCb *cell,SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[],
1193 * uint16_t puschSymTblSize, SchK2TimingInfoTbl *k2InfoTbl
1194 * @return ROK - success
1197 * ****************************************************************/
1198 void BuildK2InfoTable(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], uint16_t puschSymTblSize,\
1199 SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl)
1203 bool dlSymbolPresent = false;
1204 uint8_t slotIdx=0, k2Index=0, k2Val=0, k2TmpVal=0, msg3K2TmpVal=0, msg3Delta=0, numK2 =0, currentSymbol =0;
1205 uint8_t startSymbol =0, endSymbol =0, checkSymbol=0, totalCfgSlot=0, slotCfg=0;
1206 SlotConfig currentSlot;
1209 if(cell->cellCfg.dupMode == DUPLEX_MODE_FDD)
1211 BuildK2InfoTableForFdd(cell, timeDomRsrcAllocList, puschSymTblSize, msg3K2InfoTbl, k2InfoTbl);
1217 /* Initialization the structure and storing the total slot values. */
1218 memset(k2InfoTbl, 0, sizeof(SchK2TimingInfoTbl));
1219 k2InfoTbl->tblSize = cell->numSlots;
1221 msg3K2InfoTbl->tblSize = cell->numSlots;
1222 totalCfgSlot = calculateSlotPatternLength(cell->cellCfg.ssbSchCfg.scsCommon, cell->cellCfg.tddCfg.tddPeriod);
1224 /* Checking all possible indexes for K2. */
1225 for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
1227 currentSlot = schGetSlotSymbFrmt(slotIdx % totalCfgSlot, cell->slotFrmtBitMap);
1229 /* If current slot is UL then skip because PDCCH is sent only in DL slots */
1230 if(currentSlot != UL_SLOT)
1232 for(k2Index = 0; ((k2Index < puschSymTblSize) && (k2Index < MAX_NUM_K2_IDX)); k2Index++)
1234 /* Storing k2, startSymbol, endSymbol information for further processing.
1235 * If k2 is absent then fill the default values given in spec 38.331
1236 * PUSCH-TimeDomainResourceAllocationList field descriptions */
1237 k2Val = timeDomRsrcAllocList[k2Index].k2;
1240 switch(cell->cellCfg.ssbSchCfg.scsCommon)
1243 k2Val = DEFAULT_K2_VALUE_FOR_SCS15;
1246 k2Val = DEFAULT_K2_VALUE_FOR_SCS30;
1249 k2Val = DEFAULT_K2_VALUE_FOR_SCS60;
1252 k2Val = DEFAULT_K2_VALUE_FOR_SCS120;
1257 /* Current slot + k2 should be either UL or FLEXI slot.
1258 * If slot is FLEXI then check all the symbols of that slot,
1259 * it should not contain any DL or FLEXI slot */
1260 k2TmpVal = (slotIdx + k2Val) % totalCfgSlot;
1261 slotCfg = schGetSlotSymbFrmt(k2TmpVal, cell->slotFrmtBitMap);
1262 if(slotCfg != DL_SLOT)
1264 if(slotCfg == FLEXI_SLOT)
1266 startSymbol = timeDomRsrcAllocList[k2Index].startSymbol;
1267 endSymbol = startSymbol+ timeDomRsrcAllocList[k2Index].symbolLength;
1268 dlSymbolPresent = false;
1269 for(checkSymbol= startSymbol; checkSymbol<endSymbol; checkSymbol++)
1271 currentSymbol = cell->cellCfg.tddCfg.slotCfg[k2TmpVal][checkSymbol];
1272 if(currentSymbol == DL_SLOT || currentSymbol == FLEXI_SLOT)
1274 dlSymbolPresent = true;
1279 /* Store all the values if all condition satisfies. */
1280 if(dlSymbolPresent != true || slotCfg == UL_SLOT)
1282 numK2 = k2InfoTbl->k2TimingInfo[slotIdx].numK2;
1283 k2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[numK2] = k2Index;
1284 k2InfoTbl->k2TimingInfo[slotIdx].numK2++;
1290 msg3Delta = puschDeltaTable[cell->cellCfg.numerology];
1292 /* Check for K2 for MSG3 */
1293 /* Current slot + k2 should be either UL or FLEXI slot.
1294 * If slot is FLEXI then check all the symbols of that slot,
1295 * it should not contain any DL or FLEXI slot */
1296 msg3K2TmpVal = (slotIdx + k2Val + msg3Delta) % totalCfgSlot;
1297 slotCfg = schGetSlotSymbFrmt(msg3K2TmpVal, cell->slotFrmtBitMap);
1298 if(slotCfg != DL_SLOT)
1300 if(slotCfg == FLEXI_SLOT)
1302 startSymbol = timeDomRsrcAllocList[k2Index].startSymbol;
1303 endSymbol = startSymbol+ timeDomRsrcAllocList[k2Index].symbolLength;
1304 dlSymbolPresent = false;
1305 for(checkSymbol= startSymbol; checkSymbol<endSymbol; checkSymbol++)
1307 currentSymbol = cell->cellCfg.tddCfg.slotCfg[msg3K2TmpVal][checkSymbol];
1308 if(currentSymbol == DL_SLOT || currentSymbol == FLEXI_SLOT)
1310 dlSymbolPresent = true;
1315 /* Store all the values if all condition satisfies. */
1316 if(dlSymbolPresent != true || slotCfg == UL_SLOT)
1318 numK2 = msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2;
1319 msg3K2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[numK2] = k2Index;
1320 msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2++;
1331 /*******************************************************************************************
1333 * @brief Allocate the PRB using RRM policy
1337 * Function : prbAllocUsingRRMPolicy
1340 * [Step1]: Traverse each Node in the LC list
1341 * [Step2]: Check whether the LC has ZERO requirement then clean this LC
1342 * [Step3]: Calcualte the maxPRB for this LC.
1343 * a. For Dedicated LC, maxPRB = sum of remainingReservedPRB and
1345 * b. For Default, just SharedPRB count
1346 * [Step4]: If the LC is the First one to be allocated for this UE then add
1347 * TX_PAYLODN_LEN to reqBO
1348 * [Step5]: Calculate the estimate PRB and estimate BO to be allocated
1349 * based on reqBO and maxPRB left.
1350 * [Step6]: Based on calculated PRB, Update Reserved PRB and Shared PRB counts
1351 * [Step7]: Deduce the reqBO based on allocBO and move the LC node to last.
1352 * [Step8]: Continue the next loop from List->head
1355 * [Exit1]: If all the LCs are allocated in list
1356 * [Exit2]: If PRBs are exhausted
1358 * @params[in] I/P > lcLinkList pointer (LcInfo list)
1359 * I/P > IsDedicatedPRB (Flag to indicate that RESERVED PRB to use
1360 * I/P > mcsIdx and PDSCH symbols count
1361 * I/P & O/P > Shared PRB , reserved PRB Count
1362 * I/P & O/P > Total TBS size accumulated
1363 * I/P & O/P > isTxPayloadLenAdded : Decision flag to add the TX_PAYLOAD_HDR_LEN
1367 * *******************************************************************************************/
1368 void prbAllocUsingRRMPolicy(CmLListCp *lcLL, bool isDedicatedPRB, uint16_t mcsIdx,uint8_t numSymbols,\
1369 uint16_t *sharedPRB, uint16_t *reservedPRB, bool *isTxPayloadLenAdded)
1371 CmLList *node = NULLP;
1372 LcInfo *lcNode = NULLP;
1373 uint16_t remReservedPRB = 0, estPrb = 0, maxPRB = 0;
1377 DU_LOG("\nERROR --> SCH: LcList not present");
1382 /*Only for Dedicated LcList, Valid value will be assigned to remReservedPRB
1383 * For Other LcList, remReservedPRB = 0*/
1384 if(reservedPRB != NULLP && isDedicatedPRB == TRUE)
1386 remReservedPRB = *reservedPRB;
1393 /*For Debugging purpose*/
1396 lcNode = (LcInfo *)node->node;
1398 /* [Step2]: Below condition will hit in rare case as it has been taken care during the cleaning
1399 * process of LCID which was fully allocated. Check is just for safety purpose*/
1400 if(lcNode->reqBO == 0 && lcNode->allocBO == 0)
1402 DU_LOG("\nERROR --> SCH: LCID:%d has no requirement, clearing this node",\
1404 deleteNodeFromLList(lcLL, node);
1405 SCH_FREE(lcNode, sizeof(LcInfo));
1410 /*[Exit1]: All LCs are allocated(allocBO = 0 for fully unallocated LC)*/
1411 if(lcNode->allocBO != 0)
1413 DU_LOG("\nWARNING --> SCH: All LC are allocated [SharedPRB:%d]",*sharedPRB);
1417 /*[Exit2]: If PRBs are exhausted*/
1420 /*Loop Exit: All resources exhausted*/
1421 if(remReservedPRB == 0 && *sharedPRB == 0)
1423 DU_LOG("\nWARNING --> SCH: Dedicated resources exhausted for LC:%d",lcNode->lcId);
1429 /*Loop Exit: All resources exhausted*/
1432 DU_LOG("\nWARNING --> SCH: Default resources exhausted for LC:%d",lcNode->lcId);
1438 maxPRB = remReservedPRB + *sharedPRB;
1441 if(!(*isTxPayloadLenAdded))
1443 DU_LOG("\nINFO --> SCH: LC:%d is the First node to be allocated which includes TX_PAYLOAD_HDR_LEN",\
1445 *isTxPayloadLenAdded = TRUE;
1446 lcNode->allocBO = calculateEstimateTBSize((lcNode->reqBO + TX_PAYLOAD_HDR_LEN),\
1447 mcsIdx, numSymbols, maxPRB, &estPrb);
1448 lcNode->allocBO -=TX_PAYLOAD_HDR_LEN;
1453 lcNode->allocBO = calculateEstimateTBSize(lcNode->reqBO,\
1454 mcsIdx, numSymbols, maxPRB, &estPrb);
1457 /*[Step6]:Re-adjust the reservedPRB pool count and *SharedPRB Count based on
1458 * estimated PRB allocated*/
1459 if((isDedicatedPRB == TRUE) && (estPrb <= remReservedPRB))
1461 remReservedPRB = remReservedPRB - estPrb;
1463 else /*LC requirement need PRB share from SharedPRB*/
1465 if(*sharedPRB <= (estPrb - remReservedPRB))
1467 DU_LOG("\nINFO --> SCH: SharedPRB is less");
1472 *sharedPRB = *sharedPRB - (estPrb - remReservedPRB);
1478 lcNode->reqBO -= lcNode->allocBO; /*Update the reqBO with remaining bytes unallocated*/
1479 lcNode->allocPRB = estPrb;
1480 cmLListAdd2Tail(lcLL, cmLListDelFrm(lcLL, node));
1482 /*[Step8]:Next loop: First LC to be picked from the list
1483 * because Allocated Nodes are moved to the last*/
1490 /*******************************************************************************************
1492 * @brief Check the LC List and fill the LC and GrantSize to be sent to MAC as
1497 * Function : updateGrantSizeForBoRpt
1500 * Check the LC List and fill the LC and GrantSize to be sent to MAC as
1501 * BO Report in dlMsgAlloc Pointer
1503 * @params[in] I/P > lcLinkList pointer (LcInfo list)
1504 * I/P & O/P > dlMsgAlloc(Pending LC to be added in this context)
1505 * I/P & O/P > accumalatedBOSize
1508 * *******************************************************************************************/
1509 void updateGrantSizeForBoRpt(CmLListCp *lcLL, DlMsgAlloc *dlMsgAlloc, uint32_t *accumalatedBOSize)
1511 CmLList *node = NULLP, *next = NULLP;
1512 LcInfo *lcNode = NULLP;
1516 DU_LOG("\nERROR --> SCH: LcList not present");
1534 lcNode = (LcInfo *)node->node;
1537 DU_LOG("\nINFO --> SCH : LcID:%d, [reqBO, allocBO, allocPRB]:[%d,%d,%d]",\
1538 lcNode->lcId, lcNode->reqBO, lcNode->allocBO, lcNode->allocPRB);
1540 /*Add this LC to dlMsgAlloc so that if this LC gets allocated, BO
1541 * report for allocation can be sent to MAC*/
1542 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].lcId = lcNode->lcId;
1543 dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes = lcNode->allocBO;
1545 /*Calculate the Total Payload/BO size allocated*/
1546 *accumalatedBOSize += dlMsgAlloc->lcSchInfo[dlMsgAlloc->numLc].schBytes;
1548 DU_LOG("\nINFO --> SCH: Added in MAC BO report: LCID:%d,reqBO:%d,Idx:%d, TotalBO Size:%d",\
1549 lcNode->lcId,lcNode->reqBO, dlMsgAlloc->numLc, *accumalatedBOSize);
1551 dlMsgAlloc->numLc++;
1552 /*The LC has been fully allocated, clean it*/
1553 if(lcNode->reqBO == 0)
1555 handleLcLList(lcLL, lcNode->lcId, DELETE);
1563 /**********************************************************************
1565 **********************************************************************/