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 #include "common_def.h"
70 extern SchCb schCb[SCH_MAX_INST];
71 void SchFillCfmPst(Pst *reqPst,Pst *cfmPst,RgMngmt *cfm);
73 SchCellCfgCfmFunc SchCellCfgCfmOpts[] =
75 packSchCellCfgCfm, /* LC */
76 MacProcSchCellCfgCfm, /* TC */
77 packSchCellCfgCfm /* LWLC */
82 * @brief Task Initiation function.
86 * Function : schActvInit
88 * This function is supplied as one of parameters during MAC's
89 * task registration. MAC will invoke this function once, after
90 * it creates and attaches this TAPA Task to a system task.
92 * @param[in] Ent Entity, the entity ID of this task.
93 * @param[in] Inst Inst, the instance ID of this task.
94 * @param[in] Region Region, the region ID registered for memory
96 * @param[in] Reason Reason.
102 Ent entity, /* entity */
103 Inst instId, /* instance */
104 Region region, /* region */
105 Reason reason /* reason */
108 Inst inst = (instId - SCH_INST_START);
110 /* Initialize the MAC TskInit structure to zero */
111 cmMemset ((uint8_t *)&schCb[inst], 0, sizeof(schCb));
113 /* Initialize the MAC TskInit with received values */
114 schCb[inst].schInit.ent = entity;
115 schCb[inst].schInit.inst = inst;
116 schCb[inst].schInit.region = region;
117 schCb[inst].schInit.pool = 0;
118 schCb[inst].schInit.reason = reason;
119 schCb[inst].schInit.cfgDone = FALSE;
120 schCb[inst].schInit.acnt = FALSE;
121 schCb[inst].schInit.usta = FALSE;
122 schCb[inst].schInit.trc = FALSE;
123 schCb[inst].schInit.procId = SFndProcId();
129 * @brief Scheduler instance Configuration Handler.
133 * Function : SchInstCfg
135 * This function in called by HandleSchGenCfgReq(). It handles the
136 * general configurations of the scheduler instance. Returns
137 * reason for success/failure of this function.
139 * @param[in] RgCfg *cfg, the Configuaration information
141 * -# LCM_REASON_NOT_APPL
142 * -# LCM_REASON_INVALID_MSGTYPE
143 * -# LCM_REASON_MEM_NOAVAIL
145 PUBLIC U16 SchInstCfg
147 RgCfg *cfg, /* Configuaration information */
151 uint16_t ret = LCM_REASON_NOT_APPL;
152 Inst inst = (dInst - SCH_INST_START);
154 printf("\nEntered SchInstCfg()");
155 /* Check if Instance Configuration is done already */
156 if (schCb[inst].schInit.cfgDone == TRUE)
158 RETVALUE(LCM_REASON_INVALID_MSGTYPE);
160 /* Update the Pst structure for LM interface */
161 cmMemcpy((U8 *)&schCb[inst].schInit.lmPst,
162 (U8 *)&cfg->s.schInstCfg.genCfg.lmPst,
165 schCb[inst].schInit.inst = inst;
166 schCb[inst].schInit.lmPst.srcProcId = schCb[inst].schInit.procId;
167 schCb[inst].schInit.lmPst.srcEnt = schCb[inst].schInit.ent;
168 schCb[inst].schInit.lmPst.srcInst = schCb[inst].schInit.inst +
170 schCb[inst].schInit.lmPst.event = EVTNONE;
172 schCb[inst].schInit.region = cfg->s.schInstCfg.genCfg.mem.region;
173 schCb[inst].schInit.pool = cfg->s.schInstCfg.genCfg.mem.pool;
174 schCb[inst].genCfg.tmrRes = cfg->s.schInstCfg.genCfg.tmrRes;
176 schCb[inst].genCfg.forceCntrlSrbBoOnPCel = cfg->s.schInstCfg.genCfg.forceCntrlSrbBoOnPCel;
177 schCb[inst].genCfg.isSCellActDeactAlgoEnable = cfg->s.schInstCfg.genCfg.isSCellActDeactAlgoEnable;
179 schCb[inst].genCfg.startCellId = cfg->s.schInstCfg.genCfg.startCellId;
181 /* Initialzie the timer queue */
182 cmMemset((U8 *)&schCb[inst].tmrTq, 0, sizeof(CmTqType)*RGSCH_TQ_SIZE);
183 /* Initialize the timer control point */
184 cmMemset((U8 *)&schCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
185 schCb[inst].tmrTqCp.tmrLen = RGSCH_TQ_SIZE;
187 /* SS_MT_TMR needs to be enabled as schActvTmr needs instance information */
188 /* Timer Registration request to SSI */
189 if (SRegTmrMt(schCb[inst].schInit.ent, dInst,
190 (S16)schCb[inst].genCfg.tmrRes, schActvTmr) != ROK)
192 RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg(): Failed to "
194 RETVALUE(LCM_REASON_MEM_NOAVAIL);
197 /* Set Config done in TskInit */
198 schCb[inst].schInit.cfgDone = TRUE;
199 printf("\nScheduler gen config done");
205 * @brief Layer Manager Configuration request handler.
209 * Function : HandleSchGenCfgReq
211 * This function handles the configuration
212 * request received at scheduler instance from the Layer Manager.
213 * -# Based on the cfg->hdr.elmId.elmnt value it invokes one of the
214 * functions rgHdlGenCfg() or rgHdlSapCfg().
215 * -# Invokes RgMiLrgSchCfgCfm() to send back the confirmation to the LM.
217 * @param[in] Pst *pst, the post structure
218 * @param[in] RgMngmt *cfg, the configuration parameter's structure
222 int HandleSchGenCfgReq
224 Pst *pst, /* post structure */
225 RgMngmt *cfg /* config structure */
228 uint16_t ret = LCM_PRIM_OK;
229 uint16_t reason = LCM_REASON_NOT_APPL;
233 if(pst->dstInst < SCH_INST_START)
235 DU_LOG("\nInvalid inst ID");
236 DU_LOG("\nHandleSchGenCfgReq(): "
237 "pst->dstInst=%d SCH_INST_START=%d", pst->dstInst,SCH_INST_START);
240 printf("\nReceived scheduler gen config");
241 /* Fill the post structure for sending the confirmation */
242 memset(&cfmPst, 0 , sizeof(Pst));
243 SchFillCfmPst(pst, &cfmPst, cfg);
245 cmMemset((U8 *)&cfm, 0, sizeof(RgMngmt));
252 cfm.hdr.elmId.elmnt = cfg->hdr.elmId.elmnt;
253 switch(cfg->hdr.elmId.elmnt)
256 reason = SchInstCfg(&cfg->t.cfg,pst->dstInst );
260 reason = LCM_REASON_INVALID_ELMNT;
261 DU_LOG("\nInvalid Elmnt=%d", cfg->hdr.elmId.elmnt);
265 if (reason != LCM_REASON_NOT_APPL)
270 cfm.cfm.status = ret;
271 cfm.cfm.reason = reason;
273 SchSendCfgCfm(&cfmPst, &cfm);
274 /* SPutSBuf(pst->region, pst->pool, (Data *)cfg, sizeof(RgMngmt)); */
277 }/*-- HandleSchGenCfgReq --*/
280 * @brief slot indication from MAC to SCH.
284 * Function : macSchSlotInd
286 * This API is invoked by PHY to indicate slot indication to Scheduler for
289 * @param[in] Pst *pst
290 * @param[in] SlotIndInfo *slotInd
301 Inst inst = pst->dstInst-SCH_INST_START;
303 /* Now call the TOM (Tfu ownership module) primitive to process further */
304 schProcessSlotInd(slotInd, inst);
307 } /* macSchSlotInd */
309 /*******************************************************************
311 * @brief Processes Rach indication from MAC
315 * Function : macSchRachInd
318 * Processes Rach indication from MAC
321 * @return ROK - success
324 * ****************************************************************/
325 int macSchRachInd(Pst *pst, RachIndInfo *rachInd)
327 Inst inst = pst->dstInst-SCH_INST_START;
328 DU_LOG("\nSCH : Received Rach indication");
329 schProcessRachInd(rachInd, inst);
333 /*******************************************************************
335 * @brief Processes CRC indication from MAC
339 * Function : macSchCrcInd
342 * Processes CRC indication from MAC
344 * @params[in] Post structure
346 * @return ROK - success
349 * ****************************************************************/
350 int macSchCrcInd(Pst *pst, CrcIndInfo *crcInd)
352 switch(crcInd->crcInd[0])
355 DU_LOG("\nSCH : Received CRC indication. CRC Status [FAILURE]");
358 DU_LOG("\nSCH : Received CRC indication. CRC Status [PASS]");
361 DU_LOG("\nSCH : Invalid CRC state %d", crcInd->crcInd[0]);
369 * @brief inti cellCb based on cellCfg
373 * Function : InitSchCellCb
375 * This API is invoked after receiving schCellCfg
377 * @param[in] schCellCb *cell
378 * @param[in] SchCellCfg *schCellCfg
383 int InitSchCellCb(Inst inst, SchCellCfg *schCellCfg)
386 SCH_ALLOC(cell, sizeof(SchCellCb));
389 DU_LOG("\nMemory allocation failed in InitSchCellCb");
393 cell->cellId = schCellCfg->cellId;
394 cell->instIdx = inst;
395 switch(schCellCfg->ssbSchCfg.scsCommon)
399 cell->numSlots = SCH_NUM_SLOTS;
403 DU_LOG("\nSCS %d not supported", schCellCfg->ssbSchCfg.scsCommon);
406 for(uint8_t idx=0; idx<SCH_NUM_SLOTS; idx++)
408 SchDlSlotInfo *schDlSlotInfo;
409 SchUlSlotInfo *schUlSlotInfo;
412 SCH_ALLOC(schDlSlotInfo, sizeof(SchDlSlotInfo));
415 DU_LOG("\nMemory allocation failed in InitSchCellCb");
420 SCH_ALLOC(schUlSlotInfo, sizeof(SchUlSlotInfo));
423 DU_LOG("\nMemory allocation failed in InitSchCellCb");
427 schDlSlotInfo->totalPrb = schUlSlotInfo->totalPrb = MAX_NUM_RB;
429 for(uint8_t itr=0; itr<SCH_SYMBOL_PER_SLOT; itr++)
431 schDlSlotInfo->assignedPrb[itr] = 0;
432 schUlSlotInfo->assignedPrb[itr] = 0;
434 schUlSlotInfo->schPuschInfo = NULLP;
436 for(uint8_t itr=0; itr<MAX_SSB_IDX; itr++)
438 memset(&schDlSlotInfo->ssbInfo[itr], 0, sizeof(SsbInfo));
441 cell->schDlSlotInfo[idx] = schDlSlotInfo;
442 cell->schUlSlotInfo[idx] = schUlSlotInfo;
445 schCb[inst].cells[inst] = cell;
447 DU_LOG("\nCell init completed for cellId:%d", cell->cellId);
454 SchSib1Cfg *sib1SchCfg,
459 uint8_t coreset0Idx = 0;
460 uint8_t searchSpace0Idx = 0;
461 //uint8_t ssbMuxPattern = 0;
463 uint8_t numSymbols = 0;
466 //uint8_t numSearchSpacePerSlot = 0;
468 uint8_t firstSymbol = 0; /* need to calculate using formula mentioned in 38.213 */
469 uint8_t slotIndex = 0;
470 uint8_t FreqDomainResource[6] = {0};
472 uint8_t numPdschSymbols = 12; /* considering pdsch region from 2 to 13 */
474 PdcchCfg *pdcch = &(sib1SchCfg->sib1PdcchCfg);
475 PdschCfg *pdsch = &(sib1SchCfg->sib1PdschCfg);
476 BwpCfg *bwp = &(sib1SchCfg->bwp);
478 coreset0Idx = sib1SchCfg->coresetZeroIndex;
479 searchSpace0Idx = sib1SchCfg->searchSpaceZeroIndex;
481 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
482 //ssbMuxPattern = coresetIdxTable[coreset0Idx][0];
483 numRbs = coresetIdxTable[coreset0Idx][1];
484 numSymbols = coresetIdxTable[coreset0Idx][2];
485 offset = coresetIdxTable[coreset0Idx][3];
487 /* derive the search space params from table 13-11 spec 38.213 */
488 oValue = searchSpaceIdxTable[searchSpace0Idx][0];
489 //numSearchSpacePerSlot = searchSpaceIdxTable[searchSpace0Idx][1];
490 mValue = searchSpaceIdxTable[searchSpace0Idx][2];
491 firstSymbol = searchSpaceIdxTable[searchSpace0Idx][3];
493 /* calculate the n0, need to add the formulae, as of now the value is 0
494 * Need to add the even and odd values of i during configuration
495 * [(O . 2^u + i . M ) ] mod numSlotsPerSubframe
496 * assuming u = 0, i = 0, numSlotsPerSubframe = 10
497 * Also, from this configuration, coreset0 is only on even subframe */
498 slotIndex = ((oValue * 1) + (0 * mValue)) % 10;
499 sib1SchCfg->n0 = slotIndex;
501 /* calculate the PRBs */
502 calculatePRB( ((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
505 bwp->BWPSize = MAX_NUM_RB; /* whole of BW */
507 bwp->subcarrierSpacing = 0; /* 15Khz */
508 bwp->cyclicPrefix = 0; /* normal */
510 /* fill the PDCCH PDU */
511 pdcch->coreset0Cfg.coreSet0Size = numRbs;
512 pdcch->coreset0Cfg.startSymbolIndex = firstSymbol;
513 pdcch->coreset0Cfg.durationSymbols = numSymbols;
514 memcpy(pdcch->coreset0Cfg.freqDomainResource,FreqDomainResource,6);
515 pdcch->coreset0Cfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
516 pdcch->coreset0Cfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
517 pdcch->coreset0Cfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
518 pdcch->coreset0Cfg.coreSetType = 0;
519 pdcch->coreset0Cfg.shiftIndex = pci;
520 pdcch->coreset0Cfg.precoderGranularity = 0; /* sameAsRegBundle */
522 pdcch->dci.rnti = SI_RNTI;
523 pdcch->dci.scramblingId = pci;
524 pdcch->dci.scramblingRnti = 0;
525 pdcch->dci.cceIndex = 0;
526 pdcch->dci.aggregLevel = 4;
527 pdcch->dci.beamPdcchInfo.numPrgs = 1;
528 pdcch->dci.beamPdcchInfo.prgSize = 1;
529 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
530 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
531 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
532 pdcch->dci.txPdcchPower.powerValue = 0;
533 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
534 /* Storing pdschCfg pointer here. Required to access pdsch config while
535 fillig up pdcch pdu */
536 pdcch->dci.pdschCfg = pdsch;
538 /* fill the PDSCH PDU */
540 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
541 pdsch->rnti = 0xFFFF; /* SI-RNTI */
543 pdsch->numCodewords = 1;
544 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
546 pdsch->codeword[cwCount].targetCodeRate = 308;
547 pdsch->codeword[cwCount].qamModOrder = 2;
548 pdsch->codeword[cwCount].mcsIndex = sib1SchCfg->sib1Mcs;
549 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
550 pdsch->codeword[cwCount].rvIndex = 0;
551 tbSize = schCalcTbSize(sib1SchCfg->sib1PduLen);
552 pdsch->codeword[cwCount].tbSize = tbSize;
554 pdsch->dataScramblingId = pci;
555 pdsch->numLayers = 1;
556 pdsch->transmissionScheme = 0;
558 pdsch->dmrs.dlDmrsSymbPos = 2;
559 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
560 pdsch->dmrs.dlDmrsScramblingId = pci;
561 pdsch->dmrs.scid = 0;
562 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
563 pdsch->dmrs.dmrsPorts = 0;
564 pdsch->freqAlloc.resourceAlloc = 1; /* RAT type-1 RIV format */
565 pdsch->freqAlloc.rbStart = offset + SCH_SSB_PRB_DURATION; /* the RB numbering starts from coreset0, and PDSCH is always above SSB */
566 pdsch->freqAlloc.rbSize = schCalcNumPrb(tbSize,sib1SchCfg->sib1Mcs,numPdschSymbols);
567 pdsch->freqAlloc.vrbPrbMapping = 0; /* non-interleaved */
568 pdsch->timeAlloc.rowIndex = 1;
569 pdsch->timeAlloc.startSymbolIndex = 2; /* spec-38.214, Table 5.1.2.1-1 */
570 pdsch->timeAlloc.numSymbols = numPdschSymbols;
571 pdsch->beamPdschInfo.numPrgs = 1;
572 pdsch->beamPdschInfo.prgSize = 1;
573 pdsch->beamPdschInfo.digBfInterfaces = 0;
574 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
575 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
576 pdsch->txPdschPower.powerControlOffset = 0;
577 pdsch->txPdschPower.powerControlOffsetSS = 0;
582 * @brief cell config from MAC to SCH.
586 * Function : macSchCellCfgReq
588 * This API is invoked by MAC to send cell config to SCH
590 * @param[in] Pst *pst
591 * @param[in] SchCellCfg *schCellCfg
599 SchCellCfg *schCellCfg
604 SchCellCfgCfm schCellCfgCfm;
606 Inst inst = pst->dstInst-1;
608 InitSchCellCb(inst, schCellCfg);
609 cellCb = schCb[inst].cells[inst]; //cells is of MAX_CELLS, why inst
610 cellCb->macInst = pst->srcInst;
612 /* derive the SIB1 config parameters */
615 &(schCellCfg->sib1SchCfg),
616 schCellCfg->phyCellId,
617 schCellCfg->ssbSchCfg.ssbOffsetPointA);
618 memcpy(&cellCb->cellCfg, schCellCfg, sizeof(SchCellCfg));
620 memset(&rspPst, 0, sizeof(Pst));
621 SCH_FILL_RSP_PST(rspPst, inst);
622 rspPst.event = EVENT_SCH_CELL_CFG_CFM;
623 schCellCfgCfm.rsp = RSP_OK;
625 ret = (*SchCellCfgCfmOpts[rspPst.selector])(&rspPst, &schCellCfgCfm);
631 /*******************************************************************
633 * @brief Processes DL RLC BO info from MAC
637 * Function : macSchDlRlcBoInfo
640 * Processes DL RLC BO info from MAC
643 * @return ROK - success
646 * ****************************************************************/
647 uint8_t macSchDlRlcBoInfo(Pst *pst, DlRlcBOInfo *dlBoInfo)
650 Inst inst = pst->dstInst-SCH_INST_START;
651 DU_LOG("\nSCH : Received RLC BO Status indication");
653 SchCellCb *cell = schCb[inst].cells[inst];
654 SchDlSlotInfo *schDlSlotInfo = \
655 cell->schDlSlotInfo[(cell->slotInfo.slot + SCHED_DELTA + PHY_DELTA) % SCH_NUM_SLOTS];
657 for(lcIdx = 0; lcIdx < dlBoInfo->numLc; lcIdx++)
659 if(dlBoInfo->boInfo[lcIdx].lcId == CCCH_LCID)
661 SCH_ALLOC(schDlSlotInfo->msg4Info, sizeof(Msg4Info));
662 if(!schDlSlotInfo->msg4Info)
664 DU_LOG("\nSCH : Memory allocation failed for msg4Info");
665 schDlSlotInfo = NULL;
668 schDlSlotInfo->msg4Info->crnti = dlBoInfo->crnti;
669 schDlSlotInfo->msg4Info->ndi = 1;
670 schDlSlotInfo->msg4Info->harqProcNum = 0;
671 schDlSlotInfo->msg4Info->dlAssignIdx = 0;
672 schDlSlotInfo->msg4Info->pucchTpc = 0;
673 schDlSlotInfo->msg4Info->pucchResInd = 0;
674 schDlSlotInfo->msg4Info->harqFeedbackInd = 0;
675 schDlSlotInfo->msg4Info->dciFormatId = 1;
682 /**********************************************************************
684 **********************************************************************/