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 scheduler fucntions
29 **********************************************************************/
32 @brief This file implements the schedulers main access to MAC layer code.
34 #include "common_def.h"
35 #include "du_app_mac_inf.h"
40 #include "rg_sch_inf.h"
43 #include "tfu.x" /* TFU types */
44 #include "lrg.x" /* layer management typedefs for MAC */
45 #include "rgr.x" /* layer management typedefs for MAC */
46 #include "rg_sch_inf.x" /* typedefs for Scheduler */
47 #include "mac_sch_interface.h"
49 #include "sch_utils.h"
51 #include "sch_slice_based.h"
54 * @brief Task Initiation function.
58 * Function : schActvInit
60 * This function is supplied as one of parameters during MAC's
61 * task registration. MAC will invoke this function once, after
62 * it creates and attaches this TAPA Task to a system task.
64 * @param[in] Ent Entity, the entity ID of this task.
65 * @param[in] Inst Inst, the instance ID of this task.
66 * @param[in] Region Region, the region ID registered for memory
68 * @param[in] Reason Reason.
72 uint8_t schActvInit(Ent entity, Inst instId, Region region, Reason reason)
74 Inst inst = (instId - SCH_INST_START);
76 /* Initialize the MAC TskInit structure to zero */
77 memset ((uint8_t *)&schCb[inst], 0, sizeof(schCb));
79 /* Initialize the MAC TskInit with received values */
80 schCb[inst].schInit.ent = entity;
81 schCb[inst].schInit.inst = inst;
82 schCb[inst].schInit.region = region;
83 schCb[inst].schInit.pool = 0;
84 schCb[inst].schInit.reason = reason;
85 schCb[inst].schInit.cfgDone = FALSE;
86 schCb[inst].schInit.acnt = FALSE;
87 schCb[inst].schInit.usta = FALSE;
88 schCb[inst].schInit.trc = FALSE;
89 schCb[inst].schInit.procId = ODU_GET_PROCID();
95 * @brief Scheduler All Apis initialized.
99 * Function : schAllApisInit
101 * This function initializes all Scheduler APIs/functionality for each kind
104 * @param[in] Inst inst, the Scheduler instance
107 void schAllApisInit(Inst inst)
109 schFcfsAllApisInit(&schCb[inst].allApis[SCH_FCFS]);
110 schSliceBasedAllApisInit(&schCb[inst].allApis[SCH_SLICE_BASED]);
114 * @brief Scheduler instance Configuration Handler.
118 * Function : SchInstCfg
120 * This function in called by SchProcGenCfgReq(). It handles the
121 * general configurations of the scheduler instance. Returns
122 * reason for success/failure of this function.
124 * @param[in] RgCfg *cfg, the Configuaration information
126 * -# LCM_REASON_NOT_APPL
127 * -# LCM_REASON_INVALID_MSGTYPE
128 * -# LCM_REASON_MEM_NOAVAIL
130 uint8_t SchInstCfg(RgCfg *cfg, Inst dInst)
132 uint16_t ret = LCM_REASON_NOT_APPL;
133 Inst inst = (dInst - SCH_INST_START);
135 DU_LOG("\nDEBUG --> SCH : Entered SchInstCfg()");
136 /* Check if Instance Configuration is done already */
137 if (schCb[inst].schInit.cfgDone == TRUE)
139 return LCM_REASON_INVALID_MSGTYPE;
141 /* Update the Pst structure for LM interface */
142 memcpy(&schCb[inst].schInit.lmPst, &cfg->s.schInstCfg.genCfg.lmPst, sizeof(Pst));
144 schCb[inst].schInit.inst = inst;
145 schCb[inst].schInit.lmPst.srcProcId = schCb[inst].schInit.procId;
146 schCb[inst].schInit.lmPst.srcEnt = schCb[inst].schInit.ent;
147 schCb[inst].schInit.lmPst.srcInst = schCb[inst].schInit.inst +
149 schCb[inst].schInit.lmPst.event = EVTNONE;
151 schCb[inst].schInit.region = cfg->s.schInstCfg.genCfg.mem.region;
152 schCb[inst].schInit.pool = cfg->s.schInstCfg.genCfg.mem.pool;
153 schCb[inst].genCfg.tmrRes = cfg->s.schInstCfg.genCfg.tmrRes;
155 schCb[inst].genCfg.forceCntrlSrbBoOnPCel = cfg->s.schInstCfg.genCfg.forceCntrlSrbBoOnPCel;
156 schCb[inst].genCfg.isSCellActDeactAlgoEnable = cfg->s.schInstCfg.genCfg.isSCellActDeactAlgoEnable;
158 schCb[inst].genCfg.startCellId = cfg->s.schInstCfg.genCfg.startCellId;
160 /* Initialzie the timer queue */
161 memset(&schCb[inst].tmrTq, 0, sizeof(CmTqType) * SCH_TQ_SIZE);
162 /* Initialize the timer control point */
163 memset(&schCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
164 schCb[inst].tmrTqCp.tmrLen = RGSCH_TQ_SIZE;
166 /* SS_MT_TMR needs to be enabled as schActvTmr needs instance information */
167 /* Timer Registration request to system services */
168 if (ODU_REG_TMR_MT(schCb[inst].schInit.ent, dInst, (int)schCb[inst].genCfg.tmrRes, schActvTmr) != ROK)
170 DU_LOG("\nERROR --> SCH : SchInstCfg(): Failed to "
172 return (LCM_REASON_MEM_NOAVAIL);
175 /* Set Config done in TskInit */
176 schCb[inst].schInit.cfgDone = TRUE;
177 DU_LOG("\nINFO --> SCH : Scheduler gen config done");
179 schAllApisInit(inst);
184 * @brief Layer Manager Configuration request handler.
188 * Function : SchProcGenCfgReq
190 * This function handles the configuration
191 * request received at scheduler instance from the Layer Manager.
192 * -# Based on the cfg->hdr.elmId.elmnt value it invokes one of the
193 * functions rgHdlGenCfg() or rgHdlSapCfg().
194 * -# Invokes RgMiLrgSchCfgCfm() to send back the confirmation to the LM.
196 * @param[in] Pst *pst, the post structure
197 * @param[in] RgMngmt *cfg, the configuration parameter's structure
201 uint8_t SchProcGenCfgReq(Pst *pst, RgMngmt *cfg)
203 uint8_t ret = LCM_PRIM_OK;
204 uint16_t reason = LCM_REASON_NOT_APPL;
208 if(pst->dstInst < SCH_INST_START)
210 DU_LOG("\nERROR --> SCH : Invalid inst ID");
211 DU_LOG("\nERROR --> SCH : SchProcGenCfgReq(): "
212 "pst->dstInst=%d SCH_INST_START=%d", pst->dstInst,SCH_INST_START);
215 DU_LOG("\nINFO --> SCH : Received scheduler gen config");
216 /* Fill the post structure for sending the confirmation */
217 memset(&cfmPst, 0 , sizeof(Pst));
218 SchFillCfmPst(pst, &cfmPst, cfg);
220 memset(&cfm, 0, sizeof(RgMngmt));
227 cfm.hdr.elmId.elmnt = cfg->hdr.elmId.elmnt;
228 switch(cfg->hdr.elmId.elmnt)
231 reason = SchInstCfg(&cfg->t.cfg,pst->dstInst );
235 reason = LCM_REASON_INVALID_ELMNT;
236 DU_LOG("\nERROR --> SCH : Invalid Elmnt=%d", cfg->hdr.elmId.elmnt);
240 if (reason != LCM_REASON_NOT_APPL)
245 cfm.cfm.status = ret;
246 cfm.cfm.reason = reason;
248 SchSendCfgCfm(&cfmPst, &cfm);
249 /* SCH_FREE(pst->region, pst->pool, (Data *)cfg, sizeof(RgMngmt)); */
252 }/*-- SchProcGenCfgReq --*/
256 *@brief Returns TDD periodicity in micro seconds
260 * Function : schGetPeriodicityInMsec
262 * This API retunrs TDD periodicity in micro seconds
264 * @param[in] DlUlTxPeriodicity
265 * @return periodicityInMsec
268 uint16_t schGetPeriodicityInMsec(DlUlTxPeriodicity tddPeriod)
270 uint16_t periodicityInMsec = 0;
273 case TX_PRDCTY_MS_0P5:
275 periodicityInMsec = 500;
278 case TX_PRDCTY_MS_0P625:
280 periodicityInMsec = 625;
285 periodicityInMsec = 1000;
288 case TX_PRDCTY_MS_1P25:
290 periodicityInMsec = 1250;
295 periodicityInMsec = 2000;
298 case TX_PRDCTY_MS_2P5:
300 periodicityInMsec = 2500;
305 periodicityInMsec = 5000;
308 case TX_PRDCTY_MS_10:
310 periodicityInMsec = 10000;
315 DU_LOG("\nERROR --> SCH : Invalid DlUlTxPeriodicity:%d", tddPeriod);
319 return periodicityInMsec;
323 *@brief Fills the slotCfg from CellCfg
327 * Function : schFillSlotConfig
329 * This API Fills the slotCfg from CellCfg
331 * @param[in] SchCellCb *cell, TDDCfg tddCfg
334 void schFillSlotConfig(SchCellCb *cell, TDDCfg tddCfg)
336 uint8_t slotIdx = 0, symbolIdx = 0;
338 for(slotIdx =0 ;slotIdx < MAX_TDD_PERIODICITY_SLOTS; slotIdx++)
340 for(symbolIdx = 0; symbolIdx < MAX_SYMB_PER_SLOT; symbolIdx++)
342 /*Fill Full-DL Slots as well as DL symbols ini 1st Flexi Slo*/
343 if(slotIdx < tddCfg.nrOfDlSlots || \
344 (slotIdx == tddCfg.nrOfDlSlots && symbolIdx < tddCfg.nrOfDlSymbols))
346 cell->slotCfg[slotIdx][symbolIdx] = DL_SYMBOL;
349 /*Fill Full-FLEXI SLOT and as well as Flexi Symbols in 1 slot preceding FULL-UL slot*/
350 else if(slotIdx < (MAX_TDD_PERIODICITY_SLOTS - tddCfg.nrOfUlSlots -1) || \
351 (slotIdx == (MAX_TDD_PERIODICITY_SLOTS - tddCfg.nrOfUlSlots -1) && \
352 symbolIdx < (MAX_SYMB_PER_SLOT - tddCfg.nrOfUlSymbols)))
354 cell->slotCfg[slotIdx][symbolIdx] = FLEXI_SYMBOL;
356 /*Fill Partial UL symbols and Full-UL slot*/
359 cell->slotCfg[slotIdx][symbolIdx] = UL_SYMBOL;
366 * @brief init TDD slot config
370 * Function : schInitTddSlotCfg
372 * This API is invoked after receiving schCellCfg
374 * @param[in] schCellCb *cell
375 * @param[in] SchCellCfg *schCellCfg
378 void schInitTddSlotCfg(SchCellCb *cell, SchCellCfg *schCellCfg)
380 uint16_t periodicityInMicroSec = 0;
381 int8_t slotIdx, symbIdx;
383 periodicityInMicroSec = schGetPeriodicityInMsec(schCellCfg->tddCfg.tddPeriod);
384 cell->numSlotsInPeriodicity = (periodicityInMicroSec * pow(2, schCellCfg->numerology))/1000;
385 cell->slotFrmtBitMap = 0;
386 schFillSlotConfig(cell, schCellCfg->tddCfg);
387 for(slotIdx = cell->numSlotsInPeriodicity-1; slotIdx >= 0; slotIdx--)
390 /* If the first and last symbol are the same, the entire slot is the same type */
391 if((cell->slotCfg[slotIdx][symbIdx] == cell->slotCfg[slotIdx][MAX_SYMB_PER_SLOT-1]) &&
392 cell->slotCfg[slotIdx][symbIdx] != FLEXI_SYMBOL)
394 switch(cell->slotCfg[slotIdx][symbIdx])
398 /*BitMap to be set to 00 */
399 cell->slotFrmtBitMap = (cell->slotFrmtBitMap<<2);
404 /*BitMap to be set to 01 */
405 cell->slotFrmtBitMap = ((cell->slotFrmtBitMap<<2) | (UL_SLOT));
409 DU_LOG("\nERROR --> SCH : Invalid slot Config in schInitTddSlotCfg");
413 /* slot config is flexible. First set slotBitMap to 10 */
414 cell->slotFrmtBitMap = ((cell->slotFrmtBitMap<<2) | (FLEXI_SLOT));
420 * @brief Fill SSB start symbol
424 * Function : fillSsbStartSymb
426 * This API stores SSB start index per beam
428 * @param[in] SchCellCb *cellCb
433 void fillSsbStartSymb(SchCellCb *cellCb)
435 uint8_t cnt, scs, symbIdx, ssbStartSymbArr[SCH_MAX_SSB_BEAM];
437 scs = cellCb->cellCfg.scsCommon;
439 memset(ssbStartSymbArr, 0, sizeof(SCH_MAX_SSB_BEAM));
441 /* Determine value of "n" based on Section 4.1 of 3GPP TS 38.213 */
446 if(cellCb->cellCfg.ssbFrequency <= 300000)
447 cnt = 2;/* n = 0, 1 */
449 cnt = 4; /* n = 0, 1, 2, 3 */
450 for(uint8_t idx=0; idx<cnt; idx++)
452 /* start symbol determined using {2, 8} + 14n */
453 ssbStartSymbArr[symbIdx++] = 2 + MAX_SYMB_PER_SLOT*idx;
454 ssbStartSymbArr[symbIdx++] = 8 + MAX_SYMB_PER_SLOT*idx;
460 if(cellCb->cellCfg.ssbFrequency <= 300000)
463 cnt = 2; /* n = 0, 1 */
464 for(uint8_t idx=0; idx<cnt; idx++)
466 /* start symbol determined using {4, 8, 16, 20} + 28n */
467 ssbStartSymbArr[symbIdx++] = 4 + MAX_SYMB_PER_SLOT*idx;
468 ssbStartSymbArr[symbIdx++] = 8 + MAX_SYMB_PER_SLOT*idx;
469 ssbStartSymbArr[symbIdx++] = 16 + MAX_SYMB_PER_SLOT*idx;
470 ssbStartSymbArr[symbIdx++] = 20 + MAX_SYMB_PER_SLOT*idx;
475 DU_LOG("\nERROR --> SCH : SCS %d is currently not supported", scs);
477 memset(cellCb->ssbStartSymbArr, 0, sizeof(SCH_MAX_SSB_BEAM));
478 memcpy(cellCb->ssbStartSymbArr, ssbStartSymbArr, SCH_MAX_SSB_BEAM);
483 * @brief init cellCb based on cellCfg
487 * Function : schInitCellCb
489 * This API is invoked after receiving schCellCfg
491 * @param[in] schCellCb *cell
492 * @param[in] SchCellCfg *schCellCfg
497 uint8_t schInitCellCb(Inst inst, SchCellCfg *schCellCfg)
499 SchCellCb *cell= NULLP;
500 SCH_ALLOC(cell, sizeof(SchCellCb));
503 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb");
507 cell->cellId = schCellCfg->cellId;
508 cell->instIdx = inst;
509 switch(schCellCfg->numerology)
511 case SCH_NUMEROLOGY_0:
513 cell->numSlots = SCH_MU0_NUM_SLOTS;
516 case SCH_NUMEROLOGY_1:
518 cell->numSlots = SCH_MU1_NUM_SLOTS;
521 case SCH_NUMEROLOGY_2:
523 cell->numSlots = SCH_MU2_NUM_SLOTS;
526 case SCH_NUMEROLOGY_3:
528 cell->numSlots = SCH_MU3_NUM_SLOTS;
531 case SCH_NUMEROLOGY_4:
533 cell->numSlots = SCH_MU4_NUM_SLOTS;
537 DU_LOG("\nERROR --> SCH : Numerology %d not supported", schCellCfg->numerology);
540 schInitTddSlotCfg(cell, schCellCfg);
543 SCH_ALLOC(cell->schDlSlotInfo, cell->numSlots * sizeof(SchDlSlotInfo*));
544 if(!cell->schDlSlotInfo)
546 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb for schDlSlotInfo");
550 SCH_ALLOC(cell->schUlSlotInfo, cell->numSlots * sizeof(SchUlSlotInfo*));
551 if(!cell->schUlSlotInfo)
553 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb for schUlSlotInfo");
557 for(uint8_t idx=0; idx<cell->numSlots; idx++)
559 SchDlSlotInfo *schDlSlotInfo;
560 SchUlSlotInfo *schUlSlotInfo;
563 SCH_ALLOC(schDlSlotInfo, sizeof(SchDlSlotInfo));
566 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb");
571 SCH_ALLOC(schUlSlotInfo, sizeof(SchUlSlotInfo));
574 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb");
578 schInitDlSlot(schDlSlotInfo);
579 schInitUlSlot(schUlSlotInfo);
581 cell->schDlSlotInfo[idx] = schDlSlotInfo;
582 cell->schUlSlotInfo[idx] = schUlSlotInfo;
585 cell->firstSsbTransmitted = false;
586 cell->firstSib1Transmitted = false;
587 fillSsbStartSymb(cell);
590 memset(cell->drxCb, 0, MAX_DRX_SIZE*sizeof(SchDrxCb));
592 schCb[inst].cells[inst] = cell;
594 DU_LOG("\nINFO --> SCH : Cell init completed for cellId:%d", cell->cellId);
600 * @brief Fill SIB1 configuration
604 * Function : fillSchSib1Cfg
606 * Fill SIB1 configuration
608 * @param[in] uint8_t bandwidth : total available bandwidth
609 * uint8_t numSlots : total slots per SFN
610 * SchSib1Cfg *sib1SchCfg : cfg to be filled
611 * uint16_t pci : physical cell Id
612 * uint8_t offsetPointA : offset
615 uint8_t fillSchSib1Cfg(uint8_t mu, uint8_t bandwidth, uint8_t numSlots,SchPdcchConfigSib1 *pdcchCfgSib1,\
616 SchSib1Cfg *sib1SchCfg, uint16_t pci, uint8_t offsetPointA, uint16_t sib1PduLen)
618 uint8_t coreset0Idx = 0;
619 uint8_t searchSpace0Idx = 0;
620 //uint8_t ssbMuxPattern = 0;
622 uint8_t numSymbols = 0;
625 //uint8_t numSearchSpacePerSlot = 0;
627 uint8_t firstSymbol = 0; /* need to calculate using formula mentioned in 38.213 */
628 uint8_t slotIndex = 0;
629 uint8_t FreqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
636 pdcch = &(sib1SchCfg->sib1PdcchCfg);
637 bwp = &(sib1SchCfg->bwp);
639 coreset0Idx = pdcchCfgSib1->coresetZeroIndex;
640 searchSpace0Idx = pdcchCfgSib1->searchSpaceZeroIndex;
642 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
643 //ssbMuxPattern = coresetIdxTable[coreset0Idx][0];
644 numRbs = coresetIdxTable[coreset0Idx][1];
645 numSymbols = coresetIdxTable[coreset0Idx][2];
646 offset = coresetIdxTable[coreset0Idx][3];
648 /* derive the search space params from table 13-11 spec 38.213 */
649 oValue = searchSpaceIdxTable[searchSpace0Idx][0];
650 //numSearchSpacePerSlot = searchSpaceIdxTable[searchSpace0Idx][1];
651 mValue = searchSpaceIdxTable[searchSpace0Idx][2];
652 firstSymbol = searchSpaceIdxTable[searchSpace0Idx][3];
654 /* calculate the n0, need to add the formulae, as of now the value is 0
655 * Need to add the even and odd values of i during configuration
656 * [(O . 2^u + i . M ) ] mod numSlotsPerSubframe
657 * assuming u = 0, i = 0, numSlotsPerSubframe = 10
658 * Also, from this configuration, coreset0 is only on even subframe */
659 slotIndex = (int)((oValue*pow(2, mu)) + floor(ssbIdx*mValue))%numSlots;
660 sib1SchCfg->n0 = slotIndex;
665 case BANDWIDTH_20MHZ:
667 bwp->freqAlloc.numPrb = TOTAL_PRB_20MHZ_MU0;
670 case BANDWIDTH_100MHZ:
672 bwp->freqAlloc.numPrb = TOTAL_PRB_100MHZ_MU1;
676 DU_LOG("\nERROR --> SCH : Bandwidth %d not supported", bandwidth);
679 bwp->freqAlloc.startPrb = 0;
680 bwp->subcarrierSpacing = 0; /* 15Khz */
681 bwp->cyclicPrefix = 0; /* normal */
683 /* fill the PDCCH PDU */
684 pdcch->coresetCfg.coreSetSize = numRbs;
685 pdcch->coresetCfg.startSymbolIndex = firstSymbol;
686 pdcch->coresetCfg.durationSymbols = numSymbols;
688 /* Fill Bitmap for PRBs in coreset */
689 fillCoresetFeqDomAllocMap(((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
690 covertFreqDomRsrcMapToIAPIFormat(FreqDomainResource, pdcch->coresetCfg.freqDomainResource);
692 pdcch->coresetCfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
693 pdcch->coresetCfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
694 pdcch->coresetCfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
695 pdcch->coresetCfg.coreSetType = 0;
696 pdcch->coresetCfg.shiftIndex = pci;
697 pdcch->coresetCfg.precoderGranularity = 0; /* sameAsRegBundle */
699 pdcch->dci.rnti = SI_RNTI;
700 pdcch->dci.scramblingId = pci;
701 pdcch->dci.scramblingRnti = 0;
702 pdcch->dci.cceIndex = 0;
703 pdcch->dci.aggregLevel = 4;
704 pdcch->dci.beamPdcchInfo.numPrgs = 1;
705 pdcch->dci.beamPdcchInfo.prgSize = 1;
706 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
707 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
708 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
709 pdcch->dci.txPdcchPower.beta_pdcch_1_0= 0;
710 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
711 /* Storing pdschCfg pointer here. Required to access pdsch config while
712 fillig up pdcch pdu */
713 SCH_ALLOC(pdcch->dci.pdschCfg, sizeof(PdschCfg));
714 if(pdcch->dci.pdschCfg == NULLP)
716 DU_LOG("\nERROR --> SCH : Memory allocation failed in %s ", __func__);
719 pdsch = pdcch->dci.pdschCfg;
721 /* fill the PDSCH PDU */
723 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
724 pdsch->rnti = 0xFFFF; /* SI-RNTI */
726 pdsch->numCodewords = 1;
727 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
729 pdsch->codeword[cwCount].targetCodeRate = 308;
730 pdsch->codeword[cwCount].qamModOrder = 2;
731 pdsch->codeword[cwCount].mcsIndex = DEFAULT_MCS;
732 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
733 pdsch->codeword[cwCount].rvIndex = 0;
734 tbSize = schCalcTbSize(sib1PduLen + TX_PAYLOAD_HDR_LEN);
735 pdsch->codeword[cwCount].tbSize = tbSize;
737 pdsch->dataScramblingId = pci;
738 pdsch->numLayers = 1;
739 pdsch->transmissionScheme = 0;
741 pdsch->dmrs.dlDmrsSymbPos = DL_DMRS_SYMBOL_POS;
742 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
743 pdsch->dmrs.dlDmrsScramblingId = pci;
744 pdsch->dmrs.scid = 0;
745 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
746 pdsch->dmrs.dmrsPorts = 0x0001;
747 pdsch->dmrs.mappingType = DMRS_MAP_TYPE_A; /* Type-A */
748 pdsch->dmrs.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
749 pdsch->dmrs.dmrsAddPos = DMRS_ADDITIONAL_POS;
751 pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
752 /* the RB numbering starts from coreset0, and PDSCH is always above SSB */
753 pdsch->pdschFreqAlloc.startPrb = offsetPointA + SCH_SSB_NUM_PRB;
754 pdsch->pdschFreqAlloc.numPrb = schCalcNumPrb(tbSize, DEFAULT_MCS, NUM_PDSCH_SYMBOL);
755 pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
756 pdsch->pdschTimeAlloc.rowIndex = 1;
757 /* This is Intel's requirement. PDSCH should start after PDSCH DRMS symbol */
758 pdsch->pdschTimeAlloc.startSymb = 3; /* spec-38.214, Table 5.1.2.1-1 */
759 pdsch->pdschTimeAlloc.numSymb = NUM_PDSCH_SYMBOL;
760 pdsch->beamPdschInfo.numPrgs = 1;
761 pdsch->beamPdschInfo.prgSize = 1;
762 pdsch->beamPdschInfo.digBfInterfaces = 0;
763 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
764 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
765 pdsch->txPdschPower.powerControlOffset = 0;
766 pdsch->txPdschPower.powerControlOffsetSS = 0;
772 * @brief cell config from MAC to SCH.
776 * Function : macSchCellCfgReq
778 * This API is invoked by MAC to send cell config to SCH
780 * @param[in] Pst *pst
781 * @param[in] SchCellCfg *schCellCfg
786 uint8_t SchProcCellCfgReq(Pst *pst, SchCellCfg *schCellCfg)
790 SchCellCfgCfm schCellCfgCfm;
792 Inst inst = pst->dstInst - SCH_INST_START;
793 uint8_t coreset0Idx = 0;
796 uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
797 SchPdschConfig pdschCfg;
799 schInitCellCb(inst, schCellCfg);
800 cellCb = schCb[inst].cells[inst]; //cells is of MAX_CELLS, why inst
801 cellCb->macInst = pst->srcInst;
803 /* derive the SIB1 config parameters */
804 ret = fillSchSib1Cfg(schCellCfg->numerology, schCellCfg->dlBandwidth, cellCb->numSlots,
805 &(schCellCfg->pdcchCfgSib1), &(cellCb->sib1SchCfg), schCellCfg->phyCellId,
806 schCellCfg->dlCfgCommon.schFreqInfoDlSib.offsetToPointA, schCellCfg->sib1PduLen);
810 DU_LOG("\nERROR --> SCH : Failed to fill sib1 configuration");
813 memcpy(&cellCb->cellCfg, schCellCfg, sizeof(SchCellCfg));
814 schProcPagingCfg(cellCb);
816 /* Fill coreset frequencyDomainResource bitmap */
817 coreset0Idx = cellCb->cellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
818 numRbs = coresetIdxTable[coreset0Idx][1];
819 offset = coresetIdxTable[coreset0Idx][3];
820 fillCoresetFeqDomAllocMap(((cellCb->cellCfg.dlCfgCommon.schFreqInfoDlSib.offsetToPointA - offset)/6), \
821 (numRbs/6), freqDomainResource);
822 covertFreqDomRsrcMapToIAPIFormat(freqDomainResource, \
823 cellCb->cellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.freqDomainRsrc);
825 /* Fill K0 - K1 table for common cfg*/
826 BuildK0K1Table(cellCb, &cellCb->k0K1InfoTbl, true, cellCb->cellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon,
827 pdschCfg, DEFAULT_UL_ACK_LIST_COUNT, defaultUlAckTbl);
829 BuildK2InfoTable(cellCb, cellCb->cellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList,\
830 cellCb->cellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.numTimeDomRsrcAlloc, &cellCb->msg3K2InfoTbl, \
833 /*As per Spec 38.211, Sec 6.3.3.2; RootSeq Len(Lra) where Lra=839 or Lra=139,
834 *depending on the PRACH preamble format as given by Tables 6.3.3.1-1 and 6.3.3.1-2.*/
835 if(prachCfgIdxTable[cellCb->cellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.prachCfgIdx][0] <= 3)
837 cellCb->cellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.rootSeqLen = ROOT_SEQ_LEN_1;
841 cellCb->cellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.rootSeqLen = ROOT_SEQ_LEN_2;
843 /* Initializing global variables */
844 cellCb->actvUeBitMap = 0;
845 cellCb->boIndBitMap = 0;
847 cellCb->schHqCfg.maxDlDataHqTx = SCH_MAX_NUM_DL_HQ_TX;
848 cellCb->schHqCfg.maxMsg4HqTx = SCH_MAX_NUM_MSG4_TX;
849 cellCb->schHqCfg.maxUlDataHqTx = SCH_MAX_NUM_UL_HQ_TX;
850 cellCb->maxMsg3Tx = SCH_MAX_NUM_MSG3_TX;
852 cellCb->schAlgoType = SCH_FCFS;
853 cellCb->api = &schCb[inst].allApis[cellCb->schAlgoType]; /* For FCFS */
854 cellCb->api->SchCellCfgReq(cellCb);
856 /* Fill and send Cell config confirm */
857 memset(&rspPst, 0, sizeof(Pst));
858 FILL_PST_SCH_TO_MAC(rspPst, pst->dstInst);
859 rspPst.event = EVENT_SCH_CELL_CFG_CFM;
861 schCellCfgCfm.cellId = schCellCfg->cellId;
862 schCellCfgCfm.rsp = RSP_OK;
864 ret = MacMessageRouter(&rspPst, (void *)&schCellCfgCfm);
869 /*******************************************************************
871 * @brief Fill and send Cell delete response to MAC
875 * Function : SchSendCellDeleteRspToMac
877 * Functionality: Fill and send Cell delete response to MAC
879 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
880 * @return ROK - success
883 * ****************************************************************/
884 uint8_t SchSendCellDeleteRspToMac(SchCellDeleteReq *ueDelete, Inst inst, SchMacRsp result)
889 SchCellDeleteRsp delRsp;
891 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
892 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
893 delRsp.cellId = ueDelete->cellId;
896 /* Filling response post */
897 memset(&rspPst, 0, sizeof(Pst));
898 FILL_PST_SCH_TO_MAC(rspPst, inst);
899 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
900 ret = MacMessageRouter(&rspPst, (void *)&delRsp);
903 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
909 /*******************************************************************
911 * @brief Function for cellCb Deletion
915 * Function : deleteSchCellCb
917 * Functionality: Function for cellCb Deletion
919 * @params[in] SchCellDelete *cellDelete
920 * @return ROK - success
923 * ****************************************************************/
924 void deleteSchCellCb(SchCellCb *cellCb)
926 uint8_t sliceIdx=0, slotIdx=0, plmnIdx = 0;
927 CmLListCp *list=NULL;
928 CmLList *node=NULL, *next=NULL;
929 SchPageInfo *tempNode = NULLP;
931 if(cellCb->schDlSlotInfo)
933 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
935 list = &cellCb->schDlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
940 SCH_FREE(node->node, sizeof(FreePrbBlock));
941 deleteNodeFromLList(list, node);
944 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
946 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
949 if(cellCb->schUlSlotInfo)
951 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
953 list = &cellCb->schUlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
958 SCH_FREE(node->node, sizeof(FreePrbBlock));
959 deleteNodeFromLList(list, node);
962 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
964 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
967 for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
969 if(cellCb->cellCfg.plmnInfoList[plmnIdx].snssai)
971 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.plmnInfoList[plmnIdx].numSliceSupport; sliceIdx++)
973 SCH_FREE(cellCb->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
975 SCH_FREE(cellCb->cellCfg.plmnInfoList[plmnIdx].snssai, cellCb->cellCfg.plmnInfoList[plmnIdx].numSliceSupport*sizeof(Snssai*));
978 SCH_FREE(cellCb->sib1SchCfg.sib1PdcchCfg.dci.pdschCfg, sizeof(PdschCfg));
980 for(uint16_t idx =0; idx<MAX_SFN; idx++)
982 list = &cellCb->pageCb.pageIndInfoRecord[idx];
989 tempNode = (SchPageInfo*)(node->node);
990 SCH_FREE(tempNode->pagePdu, tempNode->msgLen);
991 SCH_FREE(node->node, sizeof(SchPageInfo));
993 deleteNodeFromLList(list, node);
998 cellCb->api->SchCellDeleteReq(cellCb);
1000 memset(cellCb, 0, sizeof(SchCellCb));
1003 /*******************************************************************
1005 * @brief Function for cell Delete request from MAC to SCH
1009 * Function : SchProcCellDeleteReq
1011 * Functionality: Function for cell Delete request from MAC to SCH
1013 * @params[in] Pst *pst, SchCellDelete *cellDelete
1014 * @return ROK - success
1017 * ****************************************************************/
1018 uint8_t SchProcCellDeleteReq(Pst *pst, SchCellDeleteReq *cellDelete)
1020 uint8_t cellIdx=0, ret = RFAILED;
1021 Inst inst = pst->dstInst - SCH_INST_START;
1022 SchMacRsp result= RSP_OK;
1026 DU_LOG("\nERROR --> SCH : SchProcCellDeleteReq(): Ue Delete request failed");
1030 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1031 if(schCb[inst].cells[cellIdx] == NULLP)
1033 DU_LOG("\nERROR --> SCH : SchProcCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1038 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1040 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1043 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1044 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1048 DU_LOG("\nERROR --> SCH : SchProcCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1053 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1055 DU_LOG("\nERROR --> SCH : SchProcCellDeleteReq(): failed to send Cell Delete response");
1062 /*******************************************************************
1064 * @brief Processes DL RLC BO info from MAC
1068 * Function : SchProcDlRlcBoInfo
1071 * Processes DL RLC BO info from MAC
1074 * @return ROK - success
1077 * ****************************************************************/
1078 uint8_t SchProcDlRlcBoInfo(Pst *pst, DlRlcBoInfo *dlBoInfo)
1082 bool isLcIdValid = false;
1083 SchUeCb *ueCb = NULLP;
1084 SchCellCb *cell = NULLP;
1085 Inst inst = pst->dstInst-SCH_INST_START;
1087 DU_LOG("\nDEBUG --> SCH : Received RLC BO Status indication LCId [%d] BO [%d]", dlBoInfo->lcId, dlBoInfo->dataVolume);
1088 cell = schCb[inst].cells[inst];
1092 DU_LOG("\nERROR --> SCH : SchProcDlRlcBoInfo(): Cell does not exists");
1096 GET_UE_ID(dlBoInfo->crnti, ueId);
1097 ueCb = &cell->ueCb[ueId-1];
1098 if(ueCb->ueCfg.dataTransmissionAction == STOP_DATA_TRANSMISSION)
1100 DU_LOG("INFO --> SCH : DL Data transmission not allowed for UE %d", ueCb->ueCfg.ueId);
1104 lcId = dlBoInfo->lcId;
1105 CHECK_LCID(lcId, isLcIdValid);
1106 if(isLcIdValid == FALSE)
1108 DU_LOG("ERROR --> SCH: LCID:%d is not valid", lcId);
1112 /*Expected when theres a case of Retransmission Failure or Resetablishment
1113 *By Zero BO, the RLC is informing that previous data can be cleared out
1114 *Thus clearing out the LC from the Lc priority list*/
1115 if(dlBoInfo->dataVolume == 0)
1117 /* TODO : Check the LC is Dedicated or default and accordingly LCList
1122 if(lcId == SRB0_LCID)
1124 cell->raCb[ueId -1].msg4recvd = true;
1125 cell->raCb[ueId -1].dlMsgPduLen = dlBoInfo->dataVolume;
1129 /* TODO : These part of changes will be corrected during DL scheduling as
1130 * per K0 - K1 -K2 */
1131 SET_ONE_BIT(ueId, cell->boIndBitMap);
1132 if(ueCb->dlInfo.dlLcCtxt[lcId].lcId == lcId)
1134 ueCb->dlInfo.dlLcCtxt[lcId].bo = dlBoInfo->dataVolume;
1138 DU_LOG("ERROR --> SCH: LCID:%d is not configured in SCH Cb",lcId);
1142 /* Adding UE Id to list of pending UEs to be scheduled */
1143 cell->api->SchDlRlcBoInfo(cell, ueId);
1147 /*******************************************************************
1149 * @brief Processes BSR indiation from MAC
1153 * Function : SchProcBsr
1156 * Processes DL BSR from MAC
1158 * @params[in] Pst pst
1159 * UlBufferStatusRptInd bsrInd
1160 * @return ROK - success
1163 * ****************************************************************/
1164 uint8_t SchProcBsr(Pst *pst, UlBufferStatusRptInd *bsrInd)
1166 Inst schInst = pst->dstInst-SCH_INST_START;
1167 SchCellCb *cellCb = NULLP;
1168 SchUeCb *ueCb = NULLP;
1171 DU_LOG("\nDEBUG --> SCH : Received BSR");
1174 DU_LOG("\nERROR --> SCH : BSR Ind is empty");
1177 cellCb = schCb[schInst].cells[schInst];
1180 DU_LOG("\nERROR --> SCH : CellCb is empty");
1183 ueCb = schGetUeCb(cellCb, bsrInd->crnti);
1187 DU_LOG("\nERROR --> SCH : UeCB is empty");
1191 if(ueCb->ueCfg.dataTransmissionAction == STOP_DATA_TRANSMISSION)
1193 DU_LOG("\nINFO --> SCH: UL Data transmission not allowed for UE %d", ueCb->ueCfg.ueId);
1197 ueCb->bsrRcvd = true;
1198 /* store dataVolume per lcg in uecb */
1199 for(lcgIdx = 0; lcgIdx < bsrInd->numLcg; lcgIdx++)
1201 ueCb->bsrInfo[bsrInd->dataVolInfo[lcgIdx].lcgId].priority = 1; //TODO: determining LCG priority?
1202 ueCb->bsrInfo[bsrInd->dataVolInfo[lcgIdx].lcgId].dataVol = bsrInd->dataVolInfo[lcgIdx].dataVol;
1205 /* Adding UE Id to list of pending UEs to be scheduled */
1206 cellCb->api->SchBsr(cellCb, ueCb->ueId);
1210 /*******************************************************************
1212 * @brief Processes SR UCI indication from MAC
1216 * Function : SchProcSrUciInd
1219 * Processes SR UCI indication from MAC
1221 * @params[in] Post structure
1223 * @return ROK - success
1226 * ****************************************************************/
1227 uint8_t SchProcSrUciInd(Pst *pst, SrUciIndInfo *uciInd)
1229 Inst inst = pst->dstInst-SCH_INST_START;
1232 SchCellCb *cellCb = schCb[inst].cells[inst];
1234 DU_LOG("\nDEBUG --> SCH : Received SR");
1236 ueCb = schGetUeCb(cellCb, uciInd->crnti);
1238 if(ueCb->state == SCH_UE_STATE_INACTIVE)
1240 DU_LOG("\nERROR --> SCH : Crnti %d is inactive", uciInd->crnti);
1243 if(ueCb->ueCfg.dataTransmissionAction == STOP_DATA_TRANSMISSION)
1245 DU_LOG("\nINFO --> SCH: UL Data transmission not allowed for UE %d", ueCb->ueCfg.ueId);
1248 if(uciInd->numSrBits)
1250 ueCb->srRcvd = true;
1251 /* Adding UE Id to list of pending UEs to be scheduled */
1252 cellCb->api->SchSrUciInd(cellCb, ueCb->ueId);
1257 /*******************************************************************
1259 * @brief Processes DL HARQ indication from MAC
1263 * Function : SchProcDlHarqInd
1266 * Processes DL HARQ indication from MAC
1268 * @params[in] Post structure
1269 * DL HARQ Indication
1270 * @return ROK - success
1273 * ****************************************************************/
1274 uint8_t SchProcDlHarqInd(Pst *pst, DlHarqInd *dlHarqInd)
1276 Inst inst = pst->dstInst-SCH_INST_START;
1278 SchCellCb *cellCb = schCb[inst].cells[inst];
1280 DU_LOG("\nDEBUG --> SCH : Received HARQ");
1282 ueCb = schGetUeCb(cellCb, dlHarqInd->crnti);
1284 if(ueCb->state == SCH_UE_STATE_INACTIVE)
1286 DU_LOG("\nERROR --> SCH : Crnti %d is inactive", dlHarqInd->crnti);
1290 schUpdateHarqFdbk(ueCb, dlHarqInd->numHarq, dlHarqInd->harqPayload, &dlHarqInd->slotInd);
1295 /*******************************************************************
1297 * @brief Allocates requested PRBs for DL
1301 * Function : allocatePrbDl
1304 * Allocates requested PRBs in DL
1305 * Keeps track of allocated PRB (using bitmap) and remaining PRBs
1307 * @params[in] prbAlloc table
1313 * @return ROK - success
1316 * ****************************************************************/
1317 uint8_t allocatePrbDl(SchCellCb *cell, SlotTimingInfo slotTime, \
1318 uint8_t startSymbol, uint8_t symbolLength, uint16_t *startPrb, uint16_t numPrb)
1321 uint16_t broadcastPrbStart=0, broadcastPrbEnd=0;
1322 FreePrbBlock *freePrbBlock = NULLP;
1323 CmLList *freePrbNode = NULLP;
1324 PduTxOccsaion ssbOccasion=0, sib1Occasion=0;
1325 SchDlSlotInfo *schDlSlotInfo = cell->schDlSlotInfo[slotTime.slot];
1326 SchPrbAlloc *prbAlloc = &schDlSlotInfo->prbAlloc;
1328 /* If startPrb is set to MAX_NUM_RB, it means startPrb is not known currently.
1329 * Search for an appropriate location in PRB grid and allocate requested resources */
1330 if(*startPrb == MAX_NUM_RB)
1332 /* Check if SSB/SIB1 is also scheduled in this slot */
1333 ssbOccasion = schCheckSsbOcc(cell, slotTime);
1334 sib1Occasion = schCheckSib1Occ(cell, slotTime);
1336 if(ssbOccasion && sib1Occasion)
1338 broadcastPrbStart = cell->cellCfg.dlCfgCommon.schFreqInfoDlSib.offsetToPointA;
1339 broadcastPrbEnd = broadcastPrbStart + SCH_SSB_NUM_PRB + cell->sib1SchCfg.sib1PdcchCfg.dci.pdschCfg->pdschFreqAlloc.numPrb -1;
1341 else if(ssbOccasion)
1343 broadcastPrbStart = cell->cellCfg.dlCfgCommon.schFreqInfoDlSib.offsetToPointA;
1344 broadcastPrbEnd = broadcastPrbStart + SCH_SSB_NUM_PRB -1;
1346 else if(sib1Occasion)
1348 broadcastPrbStart = cell->sib1SchCfg.sib1PdcchCfg.dci.pdschCfg->pdschFreqAlloc.startPrb;
1349 broadcastPrbEnd = broadcastPrbStart + cell->sib1SchCfg.sib1PdcchCfg.dci.pdschCfg->pdschFreqAlloc.numPrb -1;
1352 /* Iterate through all free PRB blocks */
1353 freePrbNode = prbAlloc->freePrbBlockList.first;
1356 freePrbBlock = (FreePrbBlock *)freePrbNode->node;
1358 /* If broadcast message is scheduled in this slot, then check if its PRBs belong to the current free block.
1359 * Since SSB/SIB1 PRB location is fixed, these PRBs cannot be allocated to other message in same slot */
1360 if((ssbOccasion || sib1Occasion) &&
1361 ((broadcastPrbStart >= freePrbBlock->startPrb) && (broadcastPrbStart <= freePrbBlock->endPrb)) && \
1362 ((broadcastPrbEnd >= freePrbBlock->startPrb) && (broadcastPrbEnd <= freePrbBlock->endPrb)))
1364 /* Implmentation is done such that highest-numbered free-RB is allocated first */
1365 if((freePrbBlock->endPrb > broadcastPrbEnd) && ((freePrbBlock->endPrb - broadcastPrbEnd) >= numPrb))
1367 /* If sufficient free PRBs are available above bradcast message then,
1368 * endPrb = freePrbBlock->endPrb
1369 * startPrb = endPrb - numPrb +1;
1371 *startPrb = freePrbBlock->endPrb - numPrb +1;
1374 else if((broadcastPrbStart > freePrbBlock->startPrb) && ((broadcastPrbStart - freePrbBlock->startPrb) >= numPrb))
1376 /* If free PRBs are available below broadcast message then,
1377 * endPrb = broadcastPrbStart - 1
1378 * startPrb = endPrb - numPrb +1
1380 *startPrb = broadcastPrbStart - numPrb;
1385 freePrbNode = freePrbNode->next;
1391 /* Check if requested number of blocks can be allocated from the current block */
1392 if (freePrbBlock->numFreePrb < numPrb)
1394 freePrbNode = freePrbNode->next;
1397 *startPrb = freePrbBlock->endPrb - numPrb +1;
1402 /* If no free block can be used to allocated request number of RBs */
1403 if(*startPrb == MAX_NUM_RB)
1407 /* If startPrb is known already, check if requested PRBs are available for allocation */
1410 freePrbNode = isPrbAvailable(&prbAlloc->freePrbBlockList, *startPrb, numPrb);
1413 DU_LOG("\nERROR --> SCH: Requested DL PRB unavailable");
1418 /* Update bitmap to allocate PRBs */
1419 for(symbol=startSymbol; symbol < (startSymbol+symbolLength); symbol++)
1421 if(fillPrbBitmap(prbAlloc->prbBitMap[symbol], *startPrb, numPrb) != ROK)
1423 DU_LOG("\nERROR --> SCH: fillPrbBitmap() failed for symbol [%d] in DL", symbol);
1428 /* Update the remaining number for free PRBs */
1429 removeAllocatedPrbFromFreePrbList(&prbAlloc->freePrbBlockList, freePrbNode, *startPrb, numPrb);
1434 /*******************************************************************
1436 * @brief Allocates requested PRBs for UL
1440 * Function : allocatePrbUl
1443 * Allocates requested PRBs in UL
1444 * Keeps track of allocated PRB (using bitmap) and remaining PRBs
1446 * @params[in] prbAlloc table
1452 * @return ROK - success
1455 * ****************************************************************/
1456 uint8_t allocatePrbUl(SchCellCb *cell, SlotTimingInfo slotTime, \
1457 uint8_t startSymbol, uint8_t symbolLength, uint16_t *startPrb, uint16_t numPrb)
1460 uint16_t prachStartPrb, prachNumPrb, prachEndPrb;
1461 bool isPrachOccasion;
1462 FreePrbBlock *freePrbBlock = NULLP;
1463 CmLList *freePrbNode = NULLP;
1464 SchPrbAlloc *prbAlloc = NULLP;
1468 DU_LOG("\nERROR --> SCH : allocatePrbUl(): Received cellCb is null");
1472 prbAlloc = &cell->schUlSlotInfo[slotTime.slot]->prbAlloc;
1473 /* If startPrb is set to MAX_NUM_RB, it means startPrb is not known currently.
1474 * Search for an appropriate location in PRB grid and allocate requested resources */
1475 if(*startPrb == MAX_NUM_RB)
1477 /* Check if PRACH is also scheduled in this slot */
1478 isPrachOccasion = schCheckPrachOcc(cell, slotTime);
1481 prachStartPrb = cell->cellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.msg1FreqStart;
1482 prachNumPrb = schCalcPrachNumRb(cell);
1483 prachEndPrb = prachStartPrb + prachNumPrb -1;
1486 /* Iterate through all free PRB blocks */
1487 freePrbNode = prbAlloc->freePrbBlockList.first;
1490 freePrbBlock = (FreePrbBlock *)freePrbNode->node;
1492 /* If PRACH is scheduled in this slot, then check if its PRBs belong to the current free block.
1493 * PRBs required for PRACH cannot be allocated to any other message */
1494 if((isPrachOccasion) &&
1495 ((prachStartPrb >= freePrbBlock->startPrb) && (prachStartPrb <= freePrbBlock->endPrb)) &&
1496 ((prachEndPrb >= freePrbBlock->startPrb) && (prachEndPrb <= freePrbBlock->endPrb)))
1498 /* Implmentation is done such that highest-numbered free-RB is allocated first */
1499 if((freePrbBlock->endPrb > prachEndPrb) && ((freePrbBlock->endPrb - prachEndPrb) >= numPrb))
1501 /* If sufficient free PRBs are available above PRACH message then,
1502 * endPrb = freePrbBlock->endPrb
1503 * startPrb = endPrb - numPrb +1;
1505 *startPrb = freePrbBlock->endPrb - numPrb +1;
1508 else if((prachStartPrb > freePrbBlock->startPrb) && ((prachStartPrb - freePrbBlock->startPrb) >= numPrb))
1510 /* If free PRBs are available below PRACH message then,
1511 * endPrb = prachStartPrb - 1
1512 * startPrb = endPrb - numPrb +1
1514 *startPrb = prachStartPrb - numPrb;
1519 freePrbNode = freePrbNode->next;
1525 /* Check if requested number of PRBs can be allocated from currect block */
1526 if(freePrbBlock->numFreePrb < numPrb)
1528 freePrbNode = freePrbNode->next;
1531 *startPrb = freePrbBlock->endPrb - numPrb +1;
1536 /* If no free block can be used to allocated requested number of RBs */
1537 if(*startPrb == MAX_NUM_RB)
1542 /* If startPrb is known already, check if requested PRBs are available for allocation */
1543 freePrbNode = isPrbAvailable(&prbAlloc->freePrbBlockList, *startPrb, numPrb);
1546 DU_LOG("\nERROR --> SCH: Requested UL PRB unavailable");
1551 /* Update bitmap to allocate PRBs */
1552 for(symbol=startSymbol; symbol < (startSymbol+symbolLength); symbol++)
1554 if(fillPrbBitmap(prbAlloc->prbBitMap[symbol], *startPrb, numPrb) != ROK)
1556 DU_LOG("\nERROR --> SCH: fillPrbBitmap() failed for symbol [%d] in UL", symbol);
1561 /* Update the remaining number for free PRBs */
1562 removeAllocatedPrbFromFreePrbList(&prbAlloc->freePrbBlockList, freePrbNode, *startPrb, numPrb);
1567 /*******************************************************************************
1569 * @brief Try to find Best Free Block with Max Num PRB
1573 * Function : searchLargestFreeBlock
1576 * Finds the FreeBlock with MaxNum of FREE PRB considering SSB/SIB1 ocassions.
1578 * @params[in] I/P > prbAlloc table (FreeBlock list)
1579 * I/P > Slot timing Info
1581 * I/P > Direction (UL/DL)
1584 * @return Max Number of Free PRB
1585 * If 0, then no Suitable Free Block
1587 * ********************************************************************************/
1589 uint16_t searchLargestFreeBlock(SchCellCb *cell, SlotTimingInfo slotTime,uint16_t *startPrb, Direction dir)
1591 uint16_t reservedPrbStart=0, reservedPrbEnd=0, maxFreePRB = 0;
1592 FreePrbBlock *freePrbBlock = NULLP;
1593 CmLList *freePrbNode = NULLP;
1594 SchPrbAlloc *prbAlloc = NULLP;
1595 bool checkOccasion = FALSE;
1597 *startPrb = 0; /*Initialize the StartPRB to zero*/
1599 /*Based on Direction, Reserved Messsages will differi.e.
1600 * DL >> SSB and SIB1 ocassions wheres for UL, PRACH ocassions to be checked
1601 * and reserved before allocation for dedicated DL/UL msg*/
1604 SchDlSlotInfo *schDlSlotInfo = cell->schDlSlotInfo[slotTime.slot];
1605 PduTxOccsaion ssbOccasion=0, sib1Occasion=0;
1607 prbAlloc = &schDlSlotInfo->prbAlloc;
1609 ssbOccasion = schCheckSsbOcc(cell, slotTime);
1610 sib1Occasion = schCheckSib1Occ(cell, slotTime);
1612 checkOccasion = TRUE;
1613 if(ssbOccasion && sib1Occasion)
1615 reservedPrbStart = cell->cellCfg.dlCfgCommon.schFreqInfoDlSib.offsetToPointA;
1616 reservedPrbEnd = reservedPrbStart + SCH_SSB_NUM_PRB + \
1617 cell->sib1SchCfg.sib1PdcchCfg.dci.pdschCfg->pdschFreqAlloc.numPrb -1;
1619 else if(ssbOccasion)
1621 reservedPrbStart = cell->cellCfg.dlCfgCommon.schFreqInfoDlSib.offsetToPointA;
1622 reservedPrbEnd = reservedPrbStart + SCH_SSB_NUM_PRB -1;
1624 else if(sib1Occasion)
1626 reservedPrbStart = cell->sib1SchCfg.sib1PdcchCfg.dci.pdschCfg->pdschFreqAlloc.startPrb;
1627 reservedPrbEnd = reservedPrbStart + cell->sib1SchCfg.sib1PdcchCfg.dci.pdschCfg->pdschFreqAlloc.numPrb -1;
1631 checkOccasion = FALSE;
1634 else if(dir == DIR_UL)
1636 prbAlloc = &cell->schUlSlotInfo[slotTime.slot]->prbAlloc;
1638 /* Check if PRACH is also scheduled in this slot */
1639 checkOccasion = schCheckPrachOcc(cell, slotTime);
1642 reservedPrbStart = cell->cellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.msg1FreqStart;
1643 reservedPrbEnd = reservedPrbStart + (schCalcPrachNumRb(cell)) -1;
1648 DU_LOG("\nERROR --> SCH: Invalid Direction!");
1649 return (maxFreePRB);
1652 freePrbNode = prbAlloc->freePrbBlockList.first;
1655 freePrbBlock = (FreePrbBlock *)freePrbNode->node;
1657 /*For block with same numFreeBlocks, choose the one with HighestPRB range
1658 *Since FreeBLockList are arranged in Descending order of PRB range thus Skipping this block*/
1659 if(maxFreePRB >= freePrbBlock->numFreePrb)
1662 freePrbNode = freePrbNode->next;
1666 /* If Broadcast/Prach message is scheduled in this slot, then check if its PRBs belong to the current free block.
1667 * Since SSB/SIB1 PRB location is fixed, these PRBs cannot be allocated to other message in same slot */
1669 ((reservedPrbStart >= freePrbBlock->startPrb) && (reservedPrbStart <= freePrbBlock->endPrb)) && \
1670 ((reservedPrbEnd >= freePrbBlock->startPrb) && (reservedPrbEnd <= freePrbBlock->endPrb)))
1673 /* Implmentation is done such that highest-numbered free-RB is Checked first
1674 and freePRB in this block is greater than Max till now */
1675 if((freePrbBlock->endPrb > reservedPrbEnd) && ((freePrbBlock->endPrb - reservedPrbEnd) > maxFreePRB))
1677 /* If sufficient free PRBs are available above reserved message*/
1678 *startPrb = reservedPrbEnd + 1;
1679 maxFreePRB = (freePrbBlock->endPrb - reservedPrbEnd);
1681 /*Also check the other freeBlock (i.e. Above the reserved message) for MAX FREE PRB*/
1682 if((reservedPrbStart > freePrbBlock->startPrb) && ((reservedPrbStart - freePrbBlock->startPrb) > maxFreePRB))
1684 /* If free PRBs are available below reserved message*/
1685 *startPrb = freePrbBlock->startPrb;
1686 maxFreePRB = (reservedPrbStart - freePrbBlock->startPrb);
1691 if(maxFreePRB < freePrbBlock->numFreePrb)
1693 *startPrb = freePrbBlock->startPrb;
1694 maxFreePRB = freePrbBlock->numFreePrb;
1698 freePrbNode = freePrbNode->next;
1703 /*******************************************************************************
1705 * @brief This function is used to send Slice Cfg rsp to MAC
1709 * Function : SchSendSliceCfgRspToMac
1712 * function is used to send Slice Cfg rsp to MAC
1714 * @params[in] Pst *pst, SchSliceCfgRsp sliceCfgRsp
1718 * ********************************************************************************/
1719 void SchSendSliceCfgRspToMac(Inst inst, SchSliceCfgRsp sliceCfgRsp)
1723 memset(&rspPst, 0, sizeof(Pst));
1724 FILL_PST_SCH_TO_MAC(rspPst, inst);
1725 rspPst.event = EVENT_SLICE_CFG_RSP_TO_MAC;
1727 MacMessageRouter(&rspPst, (void *)&sliceCfgRsp);
1730 /*******************************************************************************
1732 * @brief fill slice configuration response
1736 * Function : fillSliceCfgRsp
1739 * fill slice configuration response
1741 * @params[in] SchCellCb, SchSliceCfgReq, SchSliceCfgRsp,uint8_t count
1747 * ********************************************************************************/
1748 uint8_t fillSliceCfgRsp(bool sliceRecfg, SchSliceCfg *storedSliceCfg, SchCellCb *cellCb, SchSliceCfgReq *schSliceCfgReq, SchSliceCfgRsp *schSliceCfgRsp, uint8_t *count)
1750 bool sliceFound = false;
1751 uint8_t cfgIdx = 0, sliceIdx = 0, plmnIdx = 0;
1753 schSliceCfgRsp->numSliceCfgRsp = schSliceCfgReq->numOfConfiguredSlice;
1754 SCH_ALLOC(schSliceCfgRsp->listOfSliceCfgRsp, schSliceCfgRsp->numSliceCfgRsp * sizeof(SliceRsp*));
1755 if(schSliceCfgRsp->listOfSliceCfgRsp == NULLP)
1757 DU_LOG("\nERROR --> SCH : Memory allocation failed at fillSliceCfgRsp");
1761 for(cfgIdx = 0; cfgIdx<schSliceCfgRsp->numSliceCfgRsp ; cfgIdx++)
1764 /* Here comparing the slice cfg request with the slice stored in cellCfg */
1765 if(sliceRecfg != true)
1767 for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
1769 for(sliceIdx = 0; sliceIdx<cellCb->cellCfg.plmnInfoList[plmnIdx].numSliceSupport; sliceIdx++)
1771 if(!memcmp(&schSliceCfgReq->listOfSlices[cfgIdx]->snssai, cellCb->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai)))
1778 if(sliceFound == true)
1786 /* Here comparing the slice cfg request with the slice stored in SchDb */
1787 if(storedSliceCfg->listOfSlices)
1789 for(sliceIdx = 0; sliceIdx<storedSliceCfg->numOfSliceConfigured; sliceIdx++)
1791 if(!memcmp(&schSliceCfgReq->listOfSlices[cfgIdx]->snssai, &storedSliceCfg->listOfSlices[sliceIdx]->snssai,\
1802 SCH_ALLOC(schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx], sizeof(SliceRsp));
1803 if(schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx] == NULLP)
1805 DU_LOG("\nERROR --> SCH : Failed to allocate memory in fillSliceCfgRsp");
1810 schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->snssai = schSliceCfgReq->listOfSlices[cfgIdx]->snssai;
1811 if(sliceFound == true)
1812 schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp = RSP_OK;
1815 schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp = RSP_NOK;
1816 schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->cause = SLICE_NOT_FOUND;
1822 /*******************************************************************************
1824 * @brief This function is used to store the slice configuration Sch DB
1828 * Function : addSliceCfgInSchDb
1831 * function is used to store the slice configuration Sch DB
1833 * @params[in] SchSliceCfg *storeSliceCfg, SchSliceCfgReq *cfgReq,
1834 * SchSliceCfgRsp cfgRsp, uint8_t count
1840 * ********************************************************************************/
1841 uint8_t addSliceCfgInSchDb(SchSliceCfg *storeSliceCfg, SchSliceCfgReq *cfgReq, SchSliceCfgRsp cfgRsp, uint8_t count)
1843 uint8_t cfgIdx = 0, sliceIdx = 0;
1847 storeSliceCfg->numOfSliceConfigured = count;
1848 SCH_ALLOC(storeSliceCfg->listOfSlices, storeSliceCfg->numOfSliceConfigured * sizeof(SchRrmPolicyOfSlice*));
1849 if(storeSliceCfg->listOfSlices == NULLP)
1851 DU_LOG("\nERROR --> SCH : Failed to allocate memory in addSliceCfgInSchDb");
1855 for(cfgIdx = 0; cfgIdx<storeSliceCfg->numOfSliceConfigured; cfgIdx++)
1857 if(cfgRsp.listOfSliceCfgRsp[cfgIdx]->rsp == RSP_OK)
1859 SCH_ALLOC(storeSliceCfg->listOfSlices[sliceIdx], sizeof(SchRrmPolicyOfSlice));
1860 if(storeSliceCfg->listOfSlices[sliceIdx] == NULLP)
1862 DU_LOG("\nERROR --> SCH : Failed to allocate memory in addSliceCfgInSchDb");
1866 memcpy(&storeSliceCfg->listOfSlices[sliceIdx]->snssai, &cfgReq->listOfSlices[sliceIdx]->snssai, sizeof(Snssai));
1867 memcpy(&storeSliceCfg->listOfSlices[sliceIdx]->rrmPolicyRatioInfo, &cfgReq->listOfSlices[sliceIdx]->rrmPolicyRatioInfo,
1868 sizeof(SchRrmPolicyRatio));
1876 /*******************************************************************************
1878 * @brief This function is used to free the slice cfg and re cfg request pointer
1882 * Function : freeSchSliceCfgReq
1885 * function is used to free the slice cfg and re cfg request pointer
1887 * @params[in] Pst *pst, SchSliceCfgReq *schSliceCfgReq
1892 * ********************************************************************************/
1893 void freeSchSliceCfgReq(SchSliceCfgReq *sliceCfgReq)
1899 if(sliceCfgReq->numOfConfiguredSlice)
1901 for(cfgIdx = 0; cfgIdx<sliceCfgReq->numOfConfiguredSlice; cfgIdx++)
1903 if(sliceCfgReq->listOfSlices[cfgIdx])
1905 SCH_FREE(sliceCfgReq->listOfSlices[cfgIdx], sizeof(SchRrmPolicyOfSlice));
1908 SCH_FREE(sliceCfgReq->listOfSlices, sliceCfgReq->numOfConfiguredSlice * sizeof(SchRrmPolicyOfSlice*));
1910 SCH_FREE(sliceCfgReq, sizeof(SchSliceCfgReq));
1913 /*******************************************************************************
1915 * @brief This function is used to store the slice configuration Sch DB
1919 * Function : SchProcSliceCfgReq
1922 * function is used to store the slice configuration Sch DB
1924 * @params[in] Pst *pst, SchSliceCfgReq *schSliceCfgReq
1930 * ********************************************************************************/
1931 uint8_t SchProcSliceCfgReq(Pst *pst, SchSliceCfgReq *schSliceCfgReq)
1934 Inst inst = pst->dstInst - SCH_INST_START;
1935 SchSliceCfgRsp sliceCfgRsp;
1937 DU_LOG("\nINFO --> SCH : Received Slice Cfg request from MAC");
1940 if(schSliceCfgReq->listOfSlices)
1942 /* filling the slice configuration response of each slice */
1943 if(fillSliceCfgRsp(false, NULLP, schCb[inst].cells[0], schSliceCfgReq, &sliceCfgRsp, &count) != ROK)
1945 DU_LOG("\nERROR --> SCH : Failed to fill the slice cfg rsp");
1949 if(addSliceCfgInSchDb(&schCb[inst].sliceCfg, schSliceCfgReq, sliceCfgRsp, count) != ROK)
1951 DU_LOG("\nERROR --> SCH : Failed to add slice cfg in sch database");
1954 freeSchSliceCfgReq(schSliceCfgReq);
1955 SchSendSliceCfgRspToMac(inst, sliceCfgRsp);
1960 DU_LOG("\nERROR --> SCH : Received SchSliceCfgReq is NULL");
1965 /*******************************************************************************
1967 * @brief This function is used to store the slice reconfiguration Sch DB
1971 * Function : modifySliceCfgInSchDb
1974 * function is used to store the slice re configuration Sch DB
1976 * @params[in] Pst *pst, SchSliceCfgReq *schSliceCfgReq
1982 * ********************************************************************************/
1983 uint8_t modifySliceCfgInSchDb(SchSliceCfg *storeSliceCfg, SchSliceRecfgReq *recfgReq, SchSliceRecfgRsp recfgRsp, uint8_t count)
1985 uint8_t cfgIdx = 0, sliceIdx = 0;
1989 if(storeSliceCfg->listOfSlices == NULLP)
1991 DU_LOG("\nINFO --> SCH : Memory allocation failed in modifySliceCfgInSchDb");
1995 for(cfgIdx = 0; cfgIdx<recfgReq->numOfConfiguredSlice; cfgIdx++)
1997 if(recfgRsp.listOfSliceCfgRsp[cfgIdx]->rsp == RSP_OK)
1999 for(sliceIdx = 0; sliceIdx<storeSliceCfg->numOfSliceConfigured; sliceIdx++)
2001 if(!memcmp(&storeSliceCfg->listOfSlices[sliceIdx]->snssai, &recfgReq->listOfSlices[cfgIdx]->snssai, sizeof(Snssai)))
2003 memcpy(&storeSliceCfg->listOfSlices[sliceIdx]->rrmPolicyRatioInfo, &recfgReq->listOfSlices[cfgIdx]->rrmPolicyRatioInfo,
2004 sizeof(SchRrmPolicyRatio));
2011 freeSchSliceCfgReq(recfgReq);
2014 /*******************************************************************************
2016 * @brief This function is used to send Slice re Cfg rsp to MAC
2020 * Function : SchSendSliceRecfgRspToMac
2023 * function is used to send Slice re Cfg rsp to MAC
2025 * @params[in] Pst *pst, SchSliceRecfgRsp schSliceRecfgRsp
2029 * ********************************************************************************/
2030 void SchSendSliceRecfgRspToMac(Inst inst, SchSliceRecfgRsp schSliceRecfgRsp)
2034 memset(&rspPst, 0, sizeof(Pst));
2035 FILL_PST_SCH_TO_MAC(rspPst, inst);
2036 rspPst.event = EVENT_SLICE_RECFG_RSP_TO_MAC;
2038 MacMessageRouter(&rspPst, (void *)&schSliceRecfgRsp);
2040 /*******************************************************************************
2042 * @brief This function is used to store the slice reconfiguration Sch DB
2046 * Function : SchProcSliceRecfgReq
2049 * function is used to store the slice re configuration Sch DB
2051 * @params[in] Pst *pst, SchSliceRecfgReq *schSliceRecfgReq
2057 * ********************************************************************************/
2058 uint8_t SchProcSliceRecfgReq(Pst *pst, SchSliceRecfgReq *schSliceRecfgReq)
2061 Inst inst = pst->dstInst - SCH_INST_START;
2062 SchSliceRecfgRsp schSliceRecfgRsp;
2064 DU_LOG("\nINFO --> SCH : Received Slice ReCfg request from MAC");
2065 if(schSliceRecfgReq)
2067 if(schSliceRecfgReq->listOfSlices)
2069 /* filling the slice configuration response of each slice */
2070 if(fillSliceCfgRsp(true, &schCb[inst].sliceCfg, NULLP, schSliceRecfgReq, &schSliceRecfgRsp, &count) != ROK)
2072 DU_LOG("\nERROR --> SCH : Failed to fill sch slice cfg response");
2076 /* Modify the slice configuration stored in schCb */
2077 if(modifySliceCfgInSchDb(&schCb[inst].sliceCfg, schSliceRecfgReq, schSliceRecfgRsp, count) != ROK)
2079 DU_LOG("\nERROR --> SCH : Failed to modify slice cfg of SchDb");
2082 SchSendSliceRecfgRspToMac(inst, schSliceRecfgRsp);
2087 DU_LOG("\nERROR --> SCH : Received SchSliceRecfgReq is NULL");
2092 /****************************************************************************
2094 * @brief Stores the Paging Configuration from DU APP in CellCb
2098 * Function : schProcPagingParam
2101 * Process the Paging Configuration when FirstPDCCHMonitoring for
2102 * Paging Ocassion is not present.
2104 * As per 38.304 Sec 7.1,
2105 * "When firstPDCCH-MonitoringOccasionOfPO is present, the
2106 * starting PDCCH monitoring occasion number of (i_s + 1)th PO is the
2107 * (i_s + 1)th value of the firstPDCCHMonitoringOccasionOfPO
2108 * parameter; otherwise, it is equal to i_s * S."
2109 * "S = number of actual transmitted SSBs determined according
2110 * to ssb-PositionsInBurst in SIB1"
2112 * @params[in] SchCellCb *cell
2116 *************************************************************************/
2117 void schProcPagingCfg(SchCellCb *cell)
2119 SchPcchCfg *pageCfgRcvd = NULL;
2122 pageCfgRcvd = &(cell->cellCfg.dlCfgCommon.schPcchCfg);
2124 if(pageCfgRcvd->poPresent == TRUE)
2126 /*Fetching first Pdcch Monitoring Occasion for SFN (i_s + 1)th*/
2127 for(i_sIdx = 0; i_sIdx < pageCfgRcvd->numPO; i_sIdx++)
2129 cell->pageCb.pagMonOcc[i_sIdx].pagingOccSlot = pageCfgRcvd->pagingOcc[i_sIdx] / MAX_SYMB_PER_SLOT ;
2130 if ((pageCfgRcvd->pagingOcc[i_sIdx] % MAX_SYMB_PER_SLOT) != 0 )
2132 cell->pageCb.pagMonOcc[i_sIdx].pagingOccSlot++;
2135 cell->pageCb.pagMonOcc[i_sIdx].frameOffset = 0;
2141 schCfgPdcchMonOccOfPO(cell);
2145 /****************************************************************************
2147 * @brief Calculate PO if not present in Configuration
2151 * Function : schCfgPdcchMonOccOfPO
2153 * Functionality: In this function, PO are calculated i_s * S because
2154 * FirstPDCCHMonitoring_ForPO is not present.
2156 * @params[in] SchCellCb *cellCb
2160 *************************************************************************/
2161 void schCfgPdcchMonOccOfPO(SchCellCb *cell)
2163 uint8_t cnt = 0, incr = 1, i_sIdx = 0, frameOffSet = 0;
2164 uint8_t nsValue = cell->cellCfg.dlCfgCommon.schPcchCfg.numPO;
2165 uint8_t totalNumSsb = countSetBits(cell->cellCfg.ssbPosInBurst[0]);
2166 SlotTimingInfo tmpTimingInfo, pdcchTime;
2168 /*Starting with First Sfn and slot*/
2169 tmpTimingInfo.sfn = 0;
2170 tmpTimingInfo.slot = 0;
2172 pdcchTime = tmpTimingInfo;
2174 while(i_sIdx < nsValue)
2176 /*Increment frame Offset if PO falls on next SFN*/
2177 if(pdcchTime.sfn != tmpTimingInfo.sfn)
2181 pdcchTime = tmpTimingInfo;
2182 schIncrSlot(&(tmpTimingInfo), incr, cell->numSlots);
2186 cell->pageCb.pagMonOcc[i_sIdx].pagingOccSlot = pdcchTime.slot;
2187 cell->pageCb.pagMonOcc[i_sIdx].frameOffset = frameOffSet;
2193 if((cnt == totalNumSsb) && (i_sIdx < MAX_PO_PER_PF))
2195 cell->pageCb.pagMonOcc[i_sIdx].pagingOccSlot = pdcchTime.slot;
2196 cell->pageCb.pagMonOcc[i_sIdx].frameOffset = frameOffSet;
2204 /****************************************************************************
2206 * @brief Storing the paging information in SCH database
2210 * Function : schAddPagingIndtoList
2212 * Functionality: Storing the paging information in SCH database
2214 * @params[in] CmLListCp *storedPageList, CmLList *pageIndInfo
2216 * @return ROK - sucess
2219 *************************************************************************/
2220 uint8_t schAddPagingIndtoList(CmLListCp *storedPageList,void * pageIndInfo)
2222 CmLList *firstNodeOfList = NULLP;
2223 CmLList *currentNodeInfo = NULLP;
2224 SchPageInfo *tempNode = NULLP, *recvdNode = NULLP;
2226 recvdNode = (SchPageInfo*) pageIndInfo;
2227 CM_LLIST_FIRST_NODE(storedPageList,firstNodeOfList);
2229 SCH_ALLOC(currentNodeInfo, sizeof(CmLList));
2230 if(!currentNodeInfo)
2232 DU_LOG("\nERROR --> SCH : schAddPagingIndtoList() : Memory allocation failed");
2236 currentNodeInfo->node = (PTR)pageIndInfo;
2237 while(firstNodeOfList)
2239 tempNode = (SchPageInfo*)(firstNodeOfList->node);
2240 if ((recvdNode->pageTxTime.slot < tempNode->pageTxTime.slot))
2242 cmLListInsCrnt(storedPageList, currentNodeInfo);
2245 else if ((recvdNode->pageTxTime.slot == tempNode->pageTxTime.slot))
2247 DU_LOG("\nERROR --> SCH : schAddPagingIndtoList() : Slot[%d] is already present in the list", recvdNode->pageTxTime.slot);
2252 CM_LLIST_NEXT_NODE(storedPageList, firstNodeOfList);
2256 if(!firstNodeOfList)
2258 cmLListAdd2Tail(storedPageList, currentNodeInfo);
2260 DU_LOG("\nDEBUG --> SCH : Paging information is stored successfully for PF:%d, Slot:%d",\
2261 recvdNode->pageTxTime.sfn, recvdNode->pageTxTime.slot);
2265 /****************************************************************************
2267 * @brief Process paging indication at SCH recevied form MAC
2271 * Function : SchProcPagingInd
2273 * Functionality: Process paging indication at SCH recevied form MAC
2275 * @params[in] Pst *pst, SchPageInd *pageInd
2279 *************************************************************************/
2280 uint8_t SchProcPagingInd(Pst *pst, SchPageInd *pageInd)
2282 uint8_t ret = RFAILED;
2283 uint16_t cellIdx = 0;
2284 Inst inst = pst->dstInst - SCH_INST_START;
2285 SchCellCb *cellCb = NULLP;
2286 SchPageInfo *pageInfo = NULLP;
2290 DU_LOG("\nDEBUG --> SCH : Received paging indication from MAC for cellId[%d]",\
2294 for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
2296 if((schCb[inst].cells[cellIdx]) && (schCb[inst].cells[cellIdx]->cellId == pageInd->cellId))
2298 cellCb = schCb[inst].cells[cellIdx];
2304 if(pageInd->i_s > cellCb->cellCfg.dlCfgCommon.schPcchCfg.numPO)
2306 DU_LOG("\nERROR --> SCH : SchProcPagingInd(): i_s should not be greater than number of paging occasion");
2310 SCH_ALLOC(pageInfo, sizeof(SchPageInfo));
2313 pageInfo->pf = pageInd->pf;
2314 pageInfo->i_s = pageInd->i_s;
2315 pageInfo->pageTxTime.cellId = pageInd->cellId;
2316 pageInfo->pageTxTime.sfn = (pageInd->pf + cellCb->pageCb.pagMonOcc[pageInd->i_s].frameOffset) % MAX_SFN;
2317 pageInfo->pageTxTime.slot = cellCb->pageCb.pagMonOcc[pageInd->i_s].pagingOccSlot;
2318 pageInfo->mcs = DEFAULT_MCS;
2319 pageInfo->msgLen = pageInd->pduLen;
2320 SCH_ALLOC(pageInfo->pagePdu, pageInfo->msgLen);
2321 if(!pageInfo->pagePdu)
2323 DU_LOG("\nERROR --> SCH : SchProcPagingInd(): Failed to allocate memory");
2327 memcpy(pageInfo->pagePdu, pageInd->pagePdu, pageInfo->msgLen);
2328 ret = schAddPagingIndtoList(&cellCb->pageCb.pageIndInfoRecord[pageInfo->pageTxTime.sfn], pageInfo);
2331 DU_LOG("\nERROR --> SCH : SchProcPagingInd(): Failed to store paging record");
2337 DU_LOG("\nERROR --> SCH : SchProcPagingInd(): Failed to allocate memory");
2343 DU_LOG("\nERROR --> SCH : Cell ID [%d] not found", pageInd->cellId);
2345 SCH_FREE(pageInd->pagePdu, pageInd->pduLen);
2346 SCH_FREE(pageInd, sizeof(SchPageInd));
2350 DU_LOG("\nERROR --> SCH : SchProcPagingInd(): Received null pointer");
2356 /***********************************************************
2358 * Func : SchFillCfmPst
2361 * Desc : Fills the Confirmation Post Structure cfmPst using the reqPst
2362 * and the cfm->hdr.response.
2369 * File : rg_sch_lmm.c
2371 **********************************************************/
2381 inst = (reqPst->dstInst - SCH_INST_START);
2383 cfmPst->srcEnt = ENTMAC;
2384 cfmPst->srcInst = (Inst) 1;
2385 cfmPst->srcProcId = schCb[inst].schInit.procId;
2386 cfmPst->dstEnt = ENTMAC;
2387 cfmPst->dstInst = (Inst) 0;
2388 cfmPst->dstProcId = reqPst->srcProcId;
2390 cfmPst->selector = cfm->hdr.response.selector;
2391 cfmPst->region = cfm->hdr.response.mem.region;
2392 cfmPst->pool = cfm->hdr.response.mem.pool;
2397 /**********************************************************************
2399 **********************************************************************/