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"
68 extern SchCb schCb[SCH_MAX_INST];
70 SchCellCfgCfmFunc SchCellCfgCfmOpts[] =
72 packSchCellCfgCfm, /* LC */
73 MacProcSchCellCfgCfm, /* TC */
74 packSchCellCfgCfm /* LWLC */
78 * @brief Task Initiation function.
82 * Function : schActvInit
84 * This function is supplied as one of parameters during MAC's
85 * task registration. MAC will invoke this function once, after
86 * it creates and attaches this TAPA Task to a system task.
88 * @param[in] Ent Entity, the entity ID of this task.
89 * @param[in] Inst Inst, the instance ID of this task.
90 * @param[in] Region Region, the region ID registered for memory
92 * @param[in] Reason Reason.
98 Ent entity, /* entity */
99 Inst instId, /* instance */
100 Region region, /* region */
101 Reason reason /* reason */
104 Inst inst = (instId - SCH_INST_START);
106 /* Initialize the MAC TskInit structure to zero */
107 cmMemset ((uint8_t *)&schCb[inst], 0, sizeof(schCb));
109 /* Initialize the MAC TskInit with received values */
110 schCb[inst].schInit.ent = entity;
111 schCb[inst].schInit.inst = inst;
112 schCb[inst].schInit.region = region;
113 schCb[inst].schInit.pool = 0;
114 schCb[inst].schInit.reason = reason;
115 schCb[inst].schInit.cfgDone = FALSE;
116 schCb[inst].schInit.acnt = FALSE;
117 schCb[inst].schInit.usta = FALSE;
118 schCb[inst].schInit.trc = FALSE;
119 schCb[inst].schInit.procId = SFndProcId();
125 * @brief Scheduler instance Configuration Handler.
129 * Function : SchInstCfg
131 * This function in called by HandleSchGenCfgReq(). It handles the
132 * general configurations of the scheduler instance. Returns
133 * reason for success/failure of this function.
135 * @param[in] RgCfg *cfg, the Configuaration information
137 * -# LCM_REASON_NOT_APPL
138 * -# LCM_REASON_INVALID_MSGTYPE
139 * -# LCM_REASON_MEM_NOAVAIL
141 PUBLIC U16 SchInstCfg
143 RgCfg *cfg, /* Configuaration information */
147 uint16_t ret = LCM_REASON_NOT_APPL;
148 Inst inst = (dInst - SCH_INST_START);
150 printf("\nEntered SchInstCfg()");
151 /* Check if Instance Configuration is done already */
152 if (schCb[inst].schInit.cfgDone == TRUE)
154 RETVALUE(LCM_REASON_INVALID_MSGTYPE);
156 /* Update the Pst structure for LM interface */
157 cmMemcpy((U8 *)&schCb[inst].schInit.lmPst,
158 (U8 *)&cfg->s.schInstCfg.genCfg.lmPst,
161 schCb[inst].schInit.inst = inst;
162 schCb[inst].schInit.lmPst.srcProcId = schCb[inst].schInit.procId;
163 schCb[inst].schInit.lmPst.srcEnt = schCb[inst].schInit.ent;
164 schCb[inst].schInit.lmPst.srcInst = schCb[inst].schInit.inst +
166 schCb[inst].schInit.lmPst.event = EVTNONE;
168 schCb[inst].schInit.region = cfg->s.schInstCfg.genCfg.mem.region;
169 schCb[inst].schInit.pool = cfg->s.schInstCfg.genCfg.mem.pool;
170 schCb[inst].genCfg.tmrRes = cfg->s.schInstCfg.genCfg.tmrRes;
172 schCb[inst].genCfg.forceCntrlSrbBoOnPCel = cfg->s.schInstCfg.genCfg.forceCntrlSrbBoOnPCel;
173 schCb[inst].genCfg.isSCellActDeactAlgoEnable = cfg->s.schInstCfg.genCfg.isSCellActDeactAlgoEnable;
175 schCb[inst].genCfg.startCellId = cfg->s.schInstCfg.genCfg.startCellId;
177 /* Initialzie the timer queue */
178 cmMemset((U8 *)&schCb[inst].tmrTq, 0, sizeof(CmTqType)*RGSCH_TQ_SIZE);
179 /* Initialize the timer control point */
180 cmMemset((U8 *)&schCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
181 schCb[inst].tmrTqCp.tmrLen = RGSCH_TQ_SIZE;
183 /* SS_MT_TMR needs to be enabled as schActvTmr needs instance information */
184 /* Timer Registration request to SSI */
185 if (SRegTmrMt(schCb[inst].schInit.ent, dInst,
186 (S16)schCb[inst].genCfg.tmrRes, schActvTmr) != ROK)
188 RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg(): Failed to "
190 RETVALUE(LCM_REASON_MEM_NOAVAIL);
193 /* Set Config done in TskInit */
194 schCb[inst].schInit.cfgDone = TRUE;
195 printf("\nScheduler gen config done");
201 * @brief Layer Manager Configuration request handler.
205 * Function : HandleSchGenCfgReq
207 * This function handles the configuration
208 * request received at scheduler instance from the Layer Manager.
209 * -# Based on the cfg->hdr.elmId.elmnt value it invokes one of the
210 * functions rgHdlGenCfg() or rgHdlSapCfg().
211 * -# Invokes RgMiLrgSchCfgCfm() to send back the confirmation to the LM.
213 * @param[in] Pst *pst, the post structure
214 * @param[in] RgMngmt *cfg, the configuration parameter's structure
218 int HandleSchGenCfgReq
220 Pst *pst, /* post structure */
221 RgMngmt *cfg /* config structure */
224 uint16_t ret = LCM_PRIM_OK;
225 uint16_t reason = LCM_REASON_NOT_APPL;
229 if(pst->dstInst < SCH_INST_START)
231 DU_LOG("\nInvalid inst ID");
232 DU_LOG("\nHandleSchGenCfgReq(): "
233 "pst->dstInst=%d SCH_INST_START=%d", pst->dstInst,SCH_INST_START);
236 printf("\nReceived scheduler gen config");
237 /* Fill the post structure for sending the confirmation */
238 memset(&cfmPst, 0 , sizeof(Pst));
239 SchFillCfmPst(pst, &cfmPst, cfg);
241 cmMemset((U8 *)&cfm, 0, sizeof(RgMngmt));
248 cfm.hdr.elmId.elmnt = cfg->hdr.elmId.elmnt;
249 switch(cfg->hdr.elmId.elmnt)
252 reason = SchInstCfg(&cfg->t.cfg,pst->dstInst );
256 reason = LCM_REASON_INVALID_ELMNT;
257 DU_LOG("\nInvalid Elmnt=%d", cfg->hdr.elmId.elmnt);
261 if (reason != LCM_REASON_NOT_APPL)
266 cfm.cfm.status = ret;
267 cfm.cfm.reason = reason;
269 SchSendCfgCfm(&cfmPst, &cfm);
270 /* SPutSBuf(pst->region, pst->pool, (Data *)cfg, sizeof(RgMngmt)); */
273 }/*-- HandleSchGenCfgReq --*/
276 * @brief slot indication from MAC to SCH.
280 * Function : macSchSlotInd
282 * This API is invoked by PHY to indicate slot indication to Scheduler for
285 * @param[in] Pst *pst
286 * @param[in] SlotIndInfo *slotInd
297 Inst inst = pst->dstInst-SCH_INST_START;
299 /* Now call the TOM (Tfu ownership module) primitive to process further */
300 schProcessSlotInd(slotInd, inst);
303 } /* macSchSlotInd */
306 * @brief inti cellCb based on cellCfg
310 * Function : InitSchCellCb
312 * This API is invoked after receiving schCellCfg
314 * @param[in] schCellCb *cell
315 * @param[in] SchCellCfg *schCellCfg
320 int InitSchCellCb(Inst inst, SchCellCfg *schCellCfg)
323 SCH_ALLOC(cell, sizeof(SchCellCb));
326 DU_LOG("\nMemory allocation failed in InitSchCellCb");
330 cell->cellId = schCellCfg->cellId;
331 cell->instIdx = inst;
332 switch(schCellCfg->scsCommon)
336 cell->numSlots = SCH_NUM_SLOTS;
340 DU_LOG("\nSCS %d not supported", schCellCfg->scsCommon);
343 for(uint8_t idx=0; idx<SCH_NUM_SLOTS; idx++)
345 SchDlAlloc *schDlAlloc;
346 SCH_ALLOC(schDlAlloc, sizeof(SchDlAlloc));
349 DU_LOG("\nMemory allocation failed in InitSchCellCb");
353 schDlAlloc->totalPrb = ((schCellCfg->bandwidth *
354 1000)/(schCellCfg->scsCommon))/SCH_NUM_SC_PRB;
355 for(uint8_t itr=0; itr<MAX_SSB_IDX; itr++)
357 schDlAlloc->assignedPrb[itr] = 0;
359 for(uint8_t itr=0; itr<MAX_SSB_IDX; itr++)
361 memset(&schDlAlloc->ssbInfo[itr], 0, sizeof(SsbInfo));
364 cell->dlAlloc[idx] = schDlAlloc;
366 schCb[inst].cells[inst] = cell; //Sphoorthi TODO: check if this works
368 DU_LOG("\nCell init completed for cellId:%d", cell->cellId);
374 * @brief cell config from MAC to SCH.
378 * Function : macSchCellCfgReq
380 * This API is invoked by MAC to send cell config to SCH
382 * @param[in] Pst *pst
383 * @param[in] SchCellCfg *schCellCfg
391 SchCellCfg *schCellCfg
396 SchCellCfgCfm schCellCfgCfm;
398 Inst inst = pst->dstInst-1;
400 InitSchCellCb(inst, schCellCfg);
401 cellCb = schCb[inst].cells[inst];
402 cellCb->macInst = pst->srcInst;
403 memcpy(&cellCb->cellCfg, schCellCfg, sizeof(SchCellCfg));
405 memset(&rspPst, 0, sizeof(Pst));
406 SCH_FILL_RSP_PST(rspPst, inst);
407 rspPst.event = EVENT_SCH_CELL_CFG_CFM;
408 schCellCfgCfm.rsp = RSP_OK;
410 ret = (*SchCellCfgCfmOpts[rspPst.selector])(&rspPst, &schCellCfgCfm);
416 /**********************************************************************
418 **********************************************************************/