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.
35 #include "envopt.h" /* environment options */
36 #include "envdep.h" /* environment dependent */
37 #include "envind.h" /* environment independent */
38 #include "gen.h" /* general layer */
39 #include "ssi.h" /* system service interface */
40 #include "cm_tkns.h" /* Common Token Defines */
41 #include "cm_llist.h" /* Common Link List Defines */
42 #include "cm_hash.h" /* Common Hash List Defines */
43 #include "cm_mblk.h" /* common memory link list library */
44 #include "cm_lte.h" /* Common LTE Defines */
48 #include "rg_sch_inf.h"
50 #include "gen.x" /* general layer typedefs */
51 #include "ssi.x" /* system services typedefs */
52 #include "cm5.x" /* system services */
53 #include "cm_tkns.x" /* Common Token Definitions */
54 #include "cm_llist.x" /* Common Link List Definitions */
55 #include "cm_lib.x" /* Common Library Definitions */
56 #include "cm_hash.x" /* Common Hash List Definitions */
57 #include "cm_mblk.x" /* common memory link list library */
58 #include "cm_lte.x" /* Common LTE Defines */
59 #include "tfu.x" /* TFU types */
60 #include "lrg.x" /* layer management typedefs for MAC */
61 #include "rgr.x" /* layer management typedefs for MAC */
62 #include "rg_sch_inf.x" /* typedefs for Scheduler */
63 #include "du_app_mac_inf.h"
64 #include "mac_sch_interface.h"
66 #include "sch_utils.h"
68 extern SchCb schCb[SCH_MAX_INST];
69 void SchFillCfmPst(Pst *reqPst,Pst *cfmPst,RgMngmt *cfm);
71 SchCellCfgCfmFunc SchCellCfgCfmOpts[] =
73 packSchCellCfgCfm, /* LC */
74 MacProcSchCellCfgCfm, /* TC */
75 packSchCellCfgCfm /* LWLC */
80 * @brief Task Initiation function.
84 * Function : schActvInit
86 * This function is supplied as one of parameters during MAC's
87 * task registration. MAC will invoke this function once, after
88 * it creates and attaches this TAPA Task to a system task.
90 * @param[in] Ent Entity, the entity ID of this task.
91 * @param[in] Inst Inst, the instance ID of this task.
92 * @param[in] Region Region, the region ID registered for memory
94 * @param[in] Reason Reason.
100 Ent entity, /* entity */
101 Inst instId, /* instance */
102 Region region, /* region */
103 Reason reason /* reason */
106 Inst inst = (instId - SCH_INST_START);
108 /* Initialize the MAC TskInit structure to zero */
109 cmMemset ((uint8_t *)&schCb[inst], 0, sizeof(schCb));
111 /* Initialize the MAC TskInit with received values */
112 schCb[inst].schInit.ent = entity;
113 schCb[inst].schInit.inst = inst;
114 schCb[inst].schInit.region = region;
115 schCb[inst].schInit.pool = 0;
116 schCb[inst].schInit.reason = reason;
117 schCb[inst].schInit.cfgDone = FALSE;
118 schCb[inst].schInit.acnt = FALSE;
119 schCb[inst].schInit.usta = FALSE;
120 schCb[inst].schInit.trc = FALSE;
121 schCb[inst].schInit.procId = SFndProcId();
127 * @brief Scheduler instance Configuration Handler.
131 * Function : SchInstCfg
133 * This function in called by HandleSchGenCfgReq(). It handles the
134 * general configurations of the scheduler instance. Returns
135 * reason for success/failure of this function.
137 * @param[in] RgCfg *cfg, the Configuaration information
139 * -# LCM_REASON_NOT_APPL
140 * -# LCM_REASON_INVALID_MSGTYPE
141 * -# LCM_REASON_MEM_NOAVAIL
143 PUBLIC U16 SchInstCfg
145 RgCfg *cfg, /* Configuaration information */
149 uint16_t ret = LCM_REASON_NOT_APPL;
150 Inst inst = (dInst - SCH_INST_START);
152 printf("\nEntered SchInstCfg()");
153 /* Check if Instance Configuration is done already */
154 if (schCb[inst].schInit.cfgDone == TRUE)
156 RETVALUE(LCM_REASON_INVALID_MSGTYPE);
158 /* Update the Pst structure for LM interface */
159 cmMemcpy((U8 *)&schCb[inst].schInit.lmPst,
160 (U8 *)&cfg->s.schInstCfg.genCfg.lmPst,
163 schCb[inst].schInit.inst = inst;
164 schCb[inst].schInit.lmPst.srcProcId = schCb[inst].schInit.procId;
165 schCb[inst].schInit.lmPst.srcEnt = schCb[inst].schInit.ent;
166 schCb[inst].schInit.lmPst.srcInst = schCb[inst].schInit.inst +
168 schCb[inst].schInit.lmPst.event = EVTNONE;
170 schCb[inst].schInit.region = cfg->s.schInstCfg.genCfg.mem.region;
171 schCb[inst].schInit.pool = cfg->s.schInstCfg.genCfg.mem.pool;
172 schCb[inst].genCfg.tmrRes = cfg->s.schInstCfg.genCfg.tmrRes;
174 schCb[inst].genCfg.forceCntrlSrbBoOnPCel = cfg->s.schInstCfg.genCfg.forceCntrlSrbBoOnPCel;
175 schCb[inst].genCfg.isSCellActDeactAlgoEnable = cfg->s.schInstCfg.genCfg.isSCellActDeactAlgoEnable;
177 schCb[inst].genCfg.startCellId = cfg->s.schInstCfg.genCfg.startCellId;
179 /* Initialzie the timer queue */
180 cmMemset((U8 *)&schCb[inst].tmrTq, 0, sizeof(CmTqType)*RGSCH_TQ_SIZE);
181 /* Initialize the timer control point */
182 cmMemset((U8 *)&schCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
183 schCb[inst].tmrTqCp.tmrLen = RGSCH_TQ_SIZE;
185 /* SS_MT_TMR needs to be enabled as schActvTmr needs instance information */
186 /* Timer Registration request to SSI */
187 if (SRegTmrMt(schCb[inst].schInit.ent, dInst,
188 (S16)schCb[inst].genCfg.tmrRes, schActvTmr) != ROK)
190 RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg(): Failed to "
192 RETVALUE(LCM_REASON_MEM_NOAVAIL);
195 /* Set Config done in TskInit */
196 schCb[inst].schInit.cfgDone = TRUE;
197 printf("\nScheduler gen config done");
203 * @brief Layer Manager Configuration request handler.
207 * Function : HandleSchGenCfgReq
209 * This function handles the configuration
210 * request received at scheduler instance from the Layer Manager.
211 * -# Based on the cfg->hdr.elmId.elmnt value it invokes one of the
212 * functions rgHdlGenCfg() or rgHdlSapCfg().
213 * -# Invokes RgMiLrgSchCfgCfm() to send back the confirmation to the LM.
215 * @param[in] Pst *pst, the post structure
216 * @param[in] RgMngmt *cfg, the configuration parameter's structure
220 int HandleSchGenCfgReq
222 Pst *pst, /* post structure */
223 RgMngmt *cfg /* config structure */
226 uint16_t ret = LCM_PRIM_OK;
227 uint16_t reason = LCM_REASON_NOT_APPL;
231 if(pst->dstInst < SCH_INST_START)
233 DU_LOG("\nInvalid inst ID");
234 DU_LOG("\nHandleSchGenCfgReq(): "
235 "pst->dstInst=%d SCH_INST_START=%d", pst->dstInst,SCH_INST_START);
238 printf("\nReceived scheduler gen config");
239 /* Fill the post structure for sending the confirmation */
240 memset(&cfmPst, 0 , sizeof(Pst));
241 SchFillCfmPst(pst, &cfmPst, cfg);
243 cmMemset((U8 *)&cfm, 0, sizeof(RgMngmt));
250 cfm.hdr.elmId.elmnt = cfg->hdr.elmId.elmnt;
251 switch(cfg->hdr.elmId.elmnt)
254 reason = SchInstCfg(&cfg->t.cfg,pst->dstInst );
258 reason = LCM_REASON_INVALID_ELMNT;
259 DU_LOG("\nInvalid Elmnt=%d", cfg->hdr.elmId.elmnt);
263 if (reason != LCM_REASON_NOT_APPL)
268 cfm.cfm.status = ret;
269 cfm.cfm.reason = reason;
271 SchSendCfgCfm(&cfmPst, &cfm);
272 /* SPutSBuf(pst->region, pst->pool, (Data *)cfg, sizeof(RgMngmt)); */
275 }/*-- HandleSchGenCfgReq --*/
278 * @brief slot indication from MAC to SCH.
282 * Function : macSchSlotInd
284 * This API is invoked by PHY to indicate slot indication to Scheduler for
287 * @param[in] Pst *pst
288 * @param[in] SlotIndInfo *slotInd
299 Inst inst = pst->dstInst-SCH_INST_START;
301 /* Now call the TOM (Tfu ownership module) primitive to process further */
302 schProcessSlotInd(slotInd, inst);
305 } /* macSchSlotInd */
307 /*******************************************************************
309 * @brief Processes Rach indication from MAC
313 * Function : macSchRachInd
316 * Processes Rach indication from MAC
319 * @return ROK - success
322 * ****************************************************************/
323 int macSchRachInd(Pst *pst, RachIndInfo *rachInd)
325 Inst inst = pst->dstInst-SCH_INST_START;
326 DU_LOG("\nSCH : Received Rach indication");
327 schProcessRachInd(rachInd, inst);
331 /*******************************************************************
333 * @brief Processes CRC indication from MAC
337 * Function : macSchCrcInd
340 * Processes CRC indication from MAC
342 * @params[in] Post structure
344 * @return ROK - success
347 * ****************************************************************/
348 int macSchCrcInd(Pst *pst, CrcIndInfo *crcInd)
350 switch(crcInd->crcInd[0])
353 DU_LOG("\nSCH : Received CRC indication. CRC Status [FAILURE]");
356 DU_LOG("\nSCH : Received CRC indication. CRC Status [PASS]");
359 DU_LOG("\nSCH : Invalid CRC state %d", crcInd->crcInd[0]);
367 * @brief inti cellCb based on cellCfg
371 * Function : InitSchCellCb
373 * This API is invoked after receiving schCellCfg
375 * @param[in] schCellCb *cell
376 * @param[in] SchCellCfg *schCellCfg
381 int InitSchCellCb(Inst inst, SchCellCfg *schCellCfg)
384 SCH_ALLOC(cell, sizeof(SchCellCb));
387 DU_LOG("\nMemory allocation failed in InitSchCellCb");
391 cell->cellId = schCellCfg->cellId;
392 cell->instIdx = inst;
393 switch(schCellCfg->ssbSchCfg.scsCommon)
397 cell->numSlots = SCH_NUM_SLOTS;
401 DU_LOG("\nSCS %d not supported", schCellCfg->ssbSchCfg.scsCommon);
404 for(uint8_t idx=0; idx<SCH_NUM_SLOTS; idx++)
406 SchDlAlloc *schDlAlloc;
407 SchUlAlloc *schUlAlloc;
410 SCH_ALLOC(schDlAlloc, sizeof(SchDlAlloc));
413 DU_LOG("\nMemory allocation failed in InitSchCellCb");
418 SCH_ALLOC(schUlAlloc, sizeof(SchUlAlloc));
421 DU_LOG("\nMemory allocation failed in InitSchCellCb");
425 schDlAlloc->totalPrb = schUlAlloc->totalPrb = MAX_NUM_RB;
427 for(uint8_t itr=0; itr<SCH_SYMBOL_PER_SLOT; itr++)
429 schDlAlloc->assignedPrb[itr] = 0;
430 schUlAlloc->assignedPrb[itr] = 0;
432 schUlAlloc->schPuschInfo = NULLP;
434 for(uint8_t itr=0; itr<MAX_SSB_IDX; itr++)
436 memset(&schDlAlloc->ssbInfo[itr], 0, sizeof(SsbInfo));
439 cell->dlAlloc[idx] = schDlAlloc;
440 cell->ulAlloc[idx] = schUlAlloc;
443 schCb[inst].cells[inst] = cell;
445 DU_LOG("\nCell init completed for cellId:%d", cell->cellId);
452 SchSib1Cfg *sib1SchCfg,
457 uint8_t coreset0Idx = 0;
458 uint8_t searchSpace0Idx = 0;
459 //uint8_t ssbMuxPattern = 0;
461 uint8_t numSymbols = 0;
464 //uint8_t numSearchSpacePerSlot = 0;
466 uint8_t firstSymbol = 0; /* need to calculate using formula mentioned in 38.213 */
467 uint8_t slotIndex = 0;
468 uint8_t FreqDomainResource[6] = {0};
470 PdcchCfg *pdcch = &(sib1SchCfg->sib1PdcchCfg);
471 PdschCfg *pdsch = &(sib1SchCfg->sib1PdschCfg);
473 coreset0Idx = sib1SchCfg->coresetZeroIndex;
474 searchSpace0Idx = sib1SchCfg->searchSpaceZeroIndex;
476 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
477 //ssbMuxPattern = coresetIdxTable[coreset0Idx][0];
478 numRbs = coresetIdxTable[coreset0Idx][1];
479 numSymbols = coresetIdxTable[coreset0Idx][2];
480 offset = coresetIdxTable[coreset0Idx][3];
482 /* derive the search space params from table 13-11 spec 38.213 */
483 oValue = searchSpaceIdxTable[searchSpace0Idx][0];
484 //numSearchSpacePerSlot = searchSpaceIdxTable[searchSpace0Idx][1];
485 mValue = searchSpaceIdxTable[searchSpace0Idx][2];
486 firstSymbol = searchSpaceIdxTable[searchSpace0Idx][3];
488 /* calculate the n0, need to add the formulae, as of now the value is 0
489 * Need to add the even and odd values of i during configuration
490 * [(O . 2^u + i . M ) ] mod numSlotsPerSubframe
491 * assuming u = 0, i = 0, numSlotsPerSubframe = 10
492 * Also, from this configuration, coreset0 is only on even subframe */
493 slotIndex = ((oValue * 1) + (0 * mValue)) % 10;
494 sib1SchCfg->n0 = slotIndex;
496 /* calculate the PRBs */
497 calculatePRB( ((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
499 /* fill the PDCCH PDU */
500 pdcch->pdcchBwpCfg.BWPSize = MAX_NUM_RB; /* whole of BW */
501 pdcch->pdcchBwpCfg.BWPStart = 0;
502 pdcch->pdcchBwpCfg.subcarrierSpacing = 0; /* 15Khz */
503 pdcch->pdcchBwpCfg.cyclicPrefix = 0; /* normal */
504 pdcch->coreset0Cfg.coreSet0Size = numRbs;
505 pdcch->coreset0Cfg.startSymbolIndex = firstSymbol;
506 pdcch->coreset0Cfg.durationSymbols = numSymbols;
507 memcpy(pdcch->coreset0Cfg.freqDomainResource,FreqDomainResource,6);
508 pdcch->coreset0Cfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
509 pdcch->coreset0Cfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
510 pdcch->coreset0Cfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
511 pdcch->coreset0Cfg.coreSetType = 0;
512 pdcch->coreset0Cfg.shiftIndex = pci;
513 pdcch->coreset0Cfg.precoderGranularity = 0; /* sameAsRegBundle */
515 pdcch->dci.rnti = SI_RNTI;
516 pdcch->dci.scramblingId = pci;
517 pdcch->dci.scramblingRnti = 0;
518 pdcch->dci.cceIndex = 0;
519 pdcch->dci.aggregLevel = 4;
520 pdcch->dci.beamPdcchInfo.numPrgs = 1;
521 pdcch->dci.beamPdcchInfo.prgSize = 1;
522 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
523 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
524 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
525 pdcch->dci.txPdcchPower.powerValue = 0;
526 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
527 /* Storing pdschCfg pointer here. Required to access pdsch config while
528 fillig up pdcch pdu */
529 pdcch->dci.pdschCfg = pdsch;
531 /* fill the PDSCH PDU */
533 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
534 pdsch->rnti = 0xFFFF; /* SI-RNTI */
536 pdsch->pdschBwpCfg.BWPSize = MAX_NUM_RB; /* whole of BW */
537 pdsch->pdschBwpCfg.BWPStart = 0;
538 pdsch->numCodewords = 1;
539 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
541 pdsch->codeword[cwCount].targetCodeRate = 308;
542 pdsch->codeword[cwCount].qamModOrder = 2;
543 pdsch->codeword[cwCount].mcsIndex = sib1SchCfg->sib1Mcs;
544 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
545 pdsch->codeword[cwCount].rvIndex = 0;
546 pdsch->codeword[cwCount].tbSize = 768/8; /* 38.214: Table 5.1.3.2-1,
547 devided by 8 to get the value in bytes */
549 pdsch->dataScramblingId = pci;
550 pdsch->numLayers = 1;
551 pdsch->transmissionScheme = 0;
553 pdsch->dmrs.dlDmrsSymbPos = 2;
554 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
555 pdsch->dmrs.dlDmrsScramblingId = pci;
556 pdsch->dmrs.scid = 0;
557 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
558 pdsch->dmrs.dmrsPorts = 0;
559 pdsch->freqAlloc.resourceAlloc = 1; /* RAT type-1 RIV format */
560 pdsch->freqAlloc.rbStart = offset + SCH_SSB_PRB_DURATION; /* the RB numbering starts from coreset0, and PDSCH is always above SSB */
561 /* formula used for calculation of rbSize, 38.213 section 5.1.3.2 *
562 * Ninfo = Nre . R . Qm . v *
563 * Nre' = Nsc . NsymPdsch - NdmrsSymb - Noh *
564 * Nre = min(156,Nre') . nPrb */
565 pdsch->freqAlloc.rbSize = 10; /* This value is calculated from above formulae */
566 pdsch->freqAlloc.vrbPrbMapping = 0; /* non-interleaved */
567 pdsch->timeAlloc.rowIndex = 1;
568 pdsch->timeAlloc.startSymbolIndex = 2; /* spec-38.214, Table 5.1.2.1-1 */
569 pdsch->timeAlloc.numSymbols = 12;
570 pdsch->beamPdschInfo.numPrgs = 1;
571 pdsch->beamPdschInfo.prgSize = 1;
572 pdsch->beamPdschInfo.digBfInterfaces = 0;
573 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
574 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
575 pdsch->txPdschPower.powerControlOffset = 0;
576 pdsch->txPdschPower.powerControlOffsetSS = 0;
581 * @brief cell config from MAC to SCH.
585 * Function : macSchCellCfgReq
587 * This API is invoked by MAC to send cell config to SCH
589 * @param[in] Pst *pst
590 * @param[in] SchCellCfg *schCellCfg
598 SchCellCfg *schCellCfg
603 SchCellCfgCfm schCellCfgCfm;
605 Inst inst = pst->dstInst-1;
607 InitSchCellCb(inst, schCellCfg);
608 cellCb = schCb[inst].cells[inst]; //cells is of MAX_CELLS, why inst
609 cellCb->macInst = pst->srcInst;
611 /* derive the SIB1 config parameters */
614 &(schCellCfg->sib1SchCfg),
615 schCellCfg->phyCellId,
616 schCellCfg->ssbSchCfg.ssbOffsetPointA);
617 memcpy(&cellCb->cellCfg, schCellCfg, sizeof(SchCellCfg));
619 memset(&rspPst, 0, sizeof(Pst));
620 SCH_FILL_RSP_PST(rspPst, inst);
621 rspPst.event = EVENT_SCH_CELL_CFG_CFM;
622 schCellCfgCfm.rsp = RSP_OK;
624 ret = (*SchCellCfgCfmOpts[rspPst.selector])(&rspPst, &schCellCfgCfm);
630 /*******************************************************************
632 * @brief Processes DL RLC BO info from MAC
636 * Function : macSchDlRlcBoInfo
639 * Processes DL RLC BO info from MAC
642 * @return ROK - success
645 * ****************************************************************/
646 uint8_t macSchDlRlcBoInfo(Pst *pst, DlRlcBOInfo *dlBoInfo)
649 Inst inst = pst->dstInst-SCH_INST_START;
650 DU_LOG("\nSCH : Received RLC BO Status indication");
652 SchCellCb *cell = schCb[inst].cells[inst];
653 SchDlAlloc *dlAlloc = \
654 cell->dlAlloc[(cell->slotInfo.slot + SCHED_DELTA) % SCH_NUM_SLOTS];
656 for(lcIdx = 0; lcIdx < dlBoInfo->numLc; lcIdx++)
658 if(dlBoInfo->boInfo[lcIdx].lcId == CCCH_LCID)
660 SCH_ALLOC(dlAlloc->msg4Info, sizeof(Msg4Info));
661 if(!dlAlloc->msg4Info)
663 DU_LOG("\nSCH : Memory allocation failed for msg4Info");
667 dlAlloc->msg4Info->crnti = dlBoInfo->crnti;
668 dlAlloc->msg4Info->ndi = 1;
669 dlAlloc->msg4Info->harqProcNum = 0;
670 dlAlloc->msg4Info->dlAssignIdx = 0;
671 dlAlloc->msg4Info->pucchTpc = 0;
672 dlAlloc->msg4Info->pucchResInd = 0;
673 dlAlloc->msg4Info->harqFeedbackInd = 0;
674 dlAlloc->msg4Info->dciFormatId = 1;
681 /**********************************************************************
683 **********************************************************************/