Merge "Added a new Flag ODU_LWR_MAC_DEBUG in the code"
[o-du/l2.git] / src / 5gnrsch / sch.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 /************************************************************************
20  
21      Name:     sch.c
22   
23      Type:     C source file
24   
25      Desc:     C source code for scheduler fucntions
26   
27      File:     sch.c
28   
29 **********************************************************************/
30
31 /** @file sch.c
32 @brief This file implements the schedulers main access to MAC layer code.
33 */
34 #include "common_def.h" 
35 #include "du_app_mac_inf.h"
36 #include "lrg.h"
37 #include "tfu.h"
38 #include "du_log.h"
39 #include "rgr.h"
40 #include "rg_sch_inf.h"
41 #include "rg_sch.h"
42
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"
48 #include "sch.h"
49 #include "sch_utils.h"
50
51 extern SchCb schCb[SCH_MAX_INST];
52 void SchFillCfmPst(Pst *reqPst,Pst *cfmPst,RgMngmt *cfm);
53
54 /* local defines */
55 SchCellCfgCfmFunc SchCellCfgCfmOpts[] = 
56 {
57    packSchCellCfgCfm,     /* LC */
58    MacProcSchCellCfgCfm,  /* TC */
59    packSchCellCfgCfm      /* LWLC */
60 };
61
62
63 /**
64  * @brief Task Initiation function. 
65  *
66  * @details
67  *
68  *     Function : schActvInit
69  *     
70  *     This function is supplied as one of parameters during MAC's 
71  *     task registration. MAC will invoke this function once, after
72  *     it creates and attaches this TAPA Task to a system task.
73  *     
74  *  @param[in]  Ent Entity, the entity ID of this task.     
75  *  @param[in]  Inst Inst, the instance ID of this task.
76  *  @param[in]  Region Region, the region ID registered for memory 
77  *              usage of this task.
78  *  @param[in]  Reason Reason.
79  *  @return  int
80  *      -# ROK
81  **/
82 uint8_t schActvInit(Ent entity, Inst instId, Region region, Reason reason)
83 {
84    Inst inst = (instId  - SCH_INST_START);
85
86    /* Initialize the MAC TskInit structure to zero */
87    memset ((uint8_t *)&schCb[inst], 0, sizeof(schCb));
88
89    /* Initialize the MAC TskInit with received values */
90    schCb[inst].schInit.ent = entity;
91    schCb[inst].schInit.inst = inst;
92    schCb[inst].schInit.region = region;
93    schCb[inst].schInit.pool = 0;
94    schCb[inst].schInit.reason = reason;
95    schCb[inst].schInit.cfgDone = FALSE;
96    schCb[inst].schInit.acnt = FALSE;
97    schCb[inst].schInit.usta = FALSE;
98    schCb[inst].schInit.trc = FALSE;
99    schCb[inst].schInit.procId = ODU_GET_PROCID();
100
101    return ROK;
102 } /* schActvInit */
103
104 /**
105  * @brief Scheduler instance Configuration Handler. 
106  *
107  * @details
108  *
109  *     Function : SchInstCfg
110  *     
111  *     This function in called by SchProcGenCfgReq(). It handles the
112  *     general configurations of the scheduler instance. Returns
113  *     reason for success/failure of this function.
114  *     
115  *  @param[in]  RgCfg *cfg, the Configuaration information 
116  *  @return  U16
117  *      -# LCM_REASON_NOT_APPL 
118  *      -# LCM_REASON_INVALID_MSGTYPE
119  *      -# LCM_REASON_MEM_NOAVAIL
120  **/
121 uint8_t SchInstCfg(RgCfg *cfg, Inst  dInst)
122 {
123    uint16_t ret = LCM_REASON_NOT_APPL;
124    Inst     inst = (dInst - SCH_INST_START);
125
126    printf("\nEntered SchInstCfg()");
127    /* Check if Instance Configuration is done already */
128    if (schCb[inst].schInit.cfgDone == TRUE)
129    {
130       return LCM_REASON_INVALID_MSGTYPE;
131    }
132    /* Update the Pst structure for LM interface */
133    memcpy(&schCb[inst].schInit.lmPst,
134          &cfg->s.schInstCfg.genCfg.lmPst,
135          sizeof(Pst));
136
137    schCb[inst].schInit.inst = inst;
138    schCb[inst].schInit.lmPst.srcProcId = schCb[inst].schInit.procId;
139    schCb[inst].schInit.lmPst.srcEnt = schCb[inst].schInit.ent;
140    schCb[inst].schInit.lmPst.srcInst = schCb[inst].schInit.inst +
141       SCH_INST_START;
142    schCb[inst].schInit.lmPst.event = EVTNONE;
143
144    schCb[inst].schInit.region = cfg->s.schInstCfg.genCfg.mem.region;
145    schCb[inst].schInit.pool = cfg->s.schInstCfg.genCfg.mem.pool;
146    schCb[inst].genCfg.tmrRes = cfg->s.schInstCfg.genCfg.tmrRes;
147 #ifdef LTE_ADV
148    schCb[inst].genCfg.forceCntrlSrbBoOnPCel =  cfg->s.schInstCfg.genCfg.forceCntrlSrbBoOnPCel;
149    schCb[inst].genCfg.isSCellActDeactAlgoEnable =  cfg->s.schInstCfg.genCfg.isSCellActDeactAlgoEnable;
150 #endif
151    schCb[inst].genCfg.startCellId    = cfg->s.schInstCfg.genCfg.startCellId;
152 #if 0
153    /* Initialzie the timer queue */   
154    memset(&schCb[inst].tmrTq, 0, sizeof(CmTqType)*RGSCH_TQ_SIZE);
155    /* Initialize the timer control point */
156    memset(&schCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
157    schCb[inst].tmrTqCp.tmrLen = RGSCH_TQ_SIZE;
158
159    /* SS_MT_TMR needs to be enabled as schActvTmr needs instance information */
160    /* Timer Registration request to SSI */
161    if (ODU_REG_TMR_MT(schCb[inst].schInit.ent, dInst,
162             (int)schCb[inst].genCfg.tmrRes, schActvTmr) != ROK)
163    {
164       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg(): Failed to "
165             "register timer.");
166       return (LCM_REASON_MEM_NOAVAIL);
167    }   
168 #endif               
169    /* Set Config done in TskInit */
170    schCb[inst].schInit.cfgDone = TRUE;
171    printf("\nScheduler gen config done");
172
173    return ret;
174 }
175
176 /**
177  * @brief Layer Manager Configuration request handler. 
178  *
179  * @details
180  *
181  *     Function : SchProcGenCfgReq
182  *     
183  *     This function handles the configuration
184  *     request received at scheduler instance from the Layer Manager.
185  *     -# Based on the cfg->hdr.elmId.elmnt value it invokes one of the
186  *        functions rgHdlGenCfg() or rgHdlSapCfg().
187  *     -# Invokes RgMiLrgSchCfgCfm() to send back the confirmation to the LM.
188  *     
189  *  @param[in]  Pst *pst, the post structure     
190  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
191  *  @return  S16
192  *      -# ROK
193  **/
194 uint8_t SchProcGenCfgReq(Pst *pst, RgMngmt *cfg)
195 {
196    uint8_t       ret = LCM_PRIM_OK;
197    uint16_t       reason = LCM_REASON_NOT_APPL;
198    RgMngmt   cfm;
199    Pst       cfmPst;
200
201    if(pst->dstInst < SCH_INST_START)
202    {
203       DU_LOG("\nInvalid inst ID");
204       DU_LOG("\nSchProcGenCfgReq(): "
205             "pst->dstInst=%d SCH_INST_START=%d", pst->dstInst,SCH_INST_START); 
206       return ROK;
207    }
208    printf("\nReceived scheduler gen config");
209    /* Fill the post structure for sending the confirmation */
210    memset(&cfmPst, 0 , sizeof(Pst));
211    SchFillCfmPst(pst, &cfmPst, cfg);
212
213    memset(&cfm, 0, sizeof(RgMngmt));
214
215 #ifdef LMINT3
216    cfm.hdr.transId =
217       cfg->hdr.transId;
218 #endif
219
220    cfm.hdr.elmId.elmnt = cfg->hdr.elmId.elmnt;
221    switch(cfg->hdr.elmId.elmnt)
222    {
223       case STSCHINST:
224          reason = SchInstCfg(&cfg->t.cfg,pst->dstInst );
225          break;
226       default:
227          ret = LCM_PRIM_NOK;
228          reason = LCM_REASON_INVALID_ELMNT;
229          DU_LOG("\nInvalid Elmnt=%d", cfg->hdr.elmId.elmnt);
230          break;
231    }
232
233    if (reason != LCM_REASON_NOT_APPL)
234    {
235       ret = LCM_PRIM_NOK;
236    }
237
238    cfm.cfm.status = ret;
239    cfm.cfm.reason = reason;
240
241    SchSendCfgCfm(&cfmPst, &cfm);
242    /*   SPutSBuf(pst->region, pst->pool, (Data *)cfg, sizeof(RgMngmt)); */
243
244    return ROK;
245 }/*-- SchProcGenCfgReq --*/
246
247 /**
248  * @brief slot indication from MAC to SCH.
249  *
250  * @details
251  *
252  *     Function : MacSchSlotInd 
253  *      
254  *      This API is invoked by PHY to indicate slot indication to Scheduler for
255  *      a cell.
256  *           
257  *  @param[in]  Pst            *pst
258  *  @param[in]  SlotIndInfo    *slotInd
259  *  @return  S16
260  *      -# ROK 
261  *      -# RFAILED 
262  **/
263 uint8_t MacSchSlotInd(Pst *pst, SlotIndInfo *slotInd)
264 {
265    Inst  inst = pst->dstInst-SCH_INST_START;
266
267    /* Now call the TOM (Tfu ownership module) primitive to process further */
268    schProcessSlotInd(slotInd, inst);
269
270    return ROK;
271 }  /* MacSchSlotInd */
272
273 /*******************************************************************
274  *
275  * @brief Processes Rach indication from MAC 
276  *
277  * @details
278  *
279  *    Function : MacSchRachInd
280  *
281  *    Functionality:
282  *      Processes Rach indication from MAC
283  *
284  * @params[in] 
285  * @return ROK     - success
286  *         RFAILED - failure
287  *
288  * ****************************************************************/
289 uint8_t MacSchRachInd(Pst *pst, RachIndInfo *rachInd)
290 {
291    Inst  inst = pst->dstInst-SCH_INST_START;
292    DU_LOG("\nSCH : Received Rach indication");
293    schProcessRachInd(rachInd, inst);
294    return ROK;
295 }
296
297 /*******************************************************************
298  *
299  * @brief Processes CRC indication from MAC 
300  *
301  * @details
302  *
303  *    Function : MacSchCrcInd
304  *
305  *    Functionality:
306  *      Processes CRC indication from MAC
307  *
308  * @params[in] Post structure
309  *             Crc Indication
310  * @return ROK     - success
311  *         RFAILED - failure
312  *
313  * ****************************************************************/
314 uint8_t MacSchCrcInd(Pst *pst, CrcIndInfo *crcInd)
315 {
316    switch(crcInd->crcInd[0])
317    {
318       case CRC_FAILED:
319          DU_LOG("\nSCH : Received CRC indication. CRC Status [FAILURE]");
320          break;
321       case CRC_PASSED:
322          DU_LOG("\nSCH : Received CRC indication. CRC Status [PASS]");
323          break;
324       default:
325          DU_LOG("\nSCH : Invalid CRC state %d", crcInd->crcInd[0]);
326          return RFAILED;
327    }
328    return ROK;
329 }
330
331
332 /**
333  * @brief inti cellCb based on cellCfg
334  *
335  * @details
336  *
337  *     Function : schInitCellCb 
338  *      
339  *      This API is invoked after receiving schCellCfg
340  *           
341  *  @param[in]  schCellCb *cell
342  *  @param[in]  SchCellCfg *schCellCfg
343  *  @return  int
344  *      -# ROK 
345  *      -# RFAILED 
346  **/
347 uint8_t schInitCellCb(Inst inst, SchCellCfg *schCellCfg)
348 {
349    SchCellCb *cell;
350    SCH_ALLOC(cell, sizeof(SchCellCb));
351    if(!cell)
352    {
353       DU_LOG("\nMemory allocation failed in schInitCellCb");
354       return RFAILED;
355    }
356
357    cell->cellId = schCellCfg->cellId; 
358    cell->instIdx = inst;
359    switch(schCellCfg->ssbSchCfg.scsCommon)
360    {
361       case SCH_SCS_15KHZ:
362          {
363             cell->numSlots = SCH_NUM_SLOTS;
364          }
365          break;
366       default:
367          DU_LOG("\nSCS %d not supported", schCellCfg->ssbSchCfg.scsCommon);
368    }
369
370    for(uint8_t idx=0; idx<SCH_NUM_SLOTS; idx++)
371    {
372       SchDlSlotInfo *schDlSlotInfo;
373       SchUlSlotInfo *schUlSlotInfo;
374
375       /* DL Alloc */
376       SCH_ALLOC(schDlSlotInfo, sizeof(SchDlSlotInfo));
377       if(!schDlSlotInfo)
378       {
379          DU_LOG("\nMemory allocation failed in schInitCellCb");
380          return RFAILED;
381       }
382
383       /* UL Alloc */
384       SCH_ALLOC(schUlSlotInfo, sizeof(SchUlSlotInfo));
385       if(!schUlSlotInfo)
386       {
387          DU_LOG("\nMemory allocation failed in schInitCellCb");
388          return RFAILED;
389       }
390
391       schInitDlSlot(schDlSlotInfo);
392       schInitUlSlot(schUlSlotInfo);
393
394       cell->schDlSlotInfo[idx] = schDlSlotInfo;
395       cell->schUlSlotInfo[idx] = schUlSlotInfo;
396
397    }
398    schCb[inst].cells[inst] = cell;
399
400    DU_LOG("\nCell init completed for cellId:%d", cell->cellId);
401
402    return ROK;   
403 }
404
405 /**
406  * @brief Fill SIB1 configuration
407  *
408  * @details
409  *
410  *     Function : fillSchSib1Cfg
411  *
412  *     Fill SIB1 configuration
413  *
414  *  @param[in]  Inst schInst : scheduler instance
415  *              SchSib1Cfg *sib1SchCfg : cfg to be filled
416  *              uint16_t pci : physical cell Id
417  *              uint8_t offsetPointA : offset
418  *  @return  void
419  **/
420 void fillSchSib1Cfg(Inst schInst, SchSib1Cfg *sib1SchCfg, uint16_t pci, \
421    uint8_t offsetPointA)
422 {
423    uint8_t coreset0Idx = 0;
424    uint8_t searchSpace0Idx = 0;
425    //uint8_t ssbMuxPattern = 0;
426    uint8_t numRbs = 0;
427    uint8_t numSymbols = 0;
428    uint8_t offset = 0;
429    uint8_t oValue = 0;
430    //uint8_t numSearchSpacePerSlot = 0;
431    uint8_t mValue = 0;
432    uint8_t firstSymbol = 0; /* need to calculate using formula mentioned in 38.213 */
433    uint8_t slotIndex = 0;
434    uint8_t FreqDomainResource[6] = {0};
435    uint16_t tbSize = 0;
436    uint8_t numPdschSymbols = 12; /* considering pdsch region from 2 to 13 */
437
438    PdcchCfg *pdcch = &(sib1SchCfg->sib1PdcchCfg);
439    PdschCfg *pdsch = &(sib1SchCfg->sib1PdschCfg);
440    BwpCfg *bwp = &(sib1SchCfg->bwp);
441
442    coreset0Idx     = sib1SchCfg->coresetZeroIndex;
443    searchSpace0Idx = sib1SchCfg->searchSpaceZeroIndex;
444
445    /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
446    //ssbMuxPattern = coresetIdxTable[coreset0Idx][0];
447    numRbs        = coresetIdxTable[coreset0Idx][1];
448    numSymbols    = coresetIdxTable[coreset0Idx][2];
449    offset        = coresetIdxTable[coreset0Idx][3];
450
451    /* derive the search space params from table 13-11 spec 38.213 */
452    oValue                = searchSpaceIdxTable[searchSpace0Idx][0];
453    //numSearchSpacePerSlot = searchSpaceIdxTable[searchSpace0Idx][1];
454    mValue                = searchSpaceIdxTable[searchSpace0Idx][2];
455    firstSymbol           = searchSpaceIdxTable[searchSpace0Idx][3];
456
457    /* calculate the n0, need to add the formulae, as of now the value is 0 
458     * Need to add the even and odd values of i during configuration 
459     * [(O . 2^u + i . M )  ] mod numSlotsPerSubframe 
460     * assuming u = 0, i = 0, numSlotsPerSubframe = 10
461     * Also, from this configuration, coreset0 is only on even subframe */
462    slotIndex = ((oValue * 1) + (0 * mValue)) % 10; 
463    sib1SchCfg->n0 = slotIndex;
464
465    /* calculate the PRBs */
466    schAllocFreqDomRscType0(((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
467
468    /* fill BWP */
469    bwp->freqAlloc.numPrb   = MAX_NUM_RB; /* whole of BW */
470    bwp->freqAlloc.startPrb = 0;
471    bwp->subcarrierSpacing  = 0;         /* 15Khz */
472    bwp->cyclicPrefix       = 0;              /* normal */
473
474    /* fill the PDCCH PDU */
475    pdcch->coresetCfg.coreSetSize = numRbs;
476    pdcch->coresetCfg.startSymbolIndex = firstSymbol;
477    pdcch->coresetCfg.durationSymbols = numSymbols;
478    memcpy(pdcch->coresetCfg.freqDomainResource,FreqDomainResource,6);
479    pdcch->coresetCfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
480    pdcch->coresetCfg.regBundleSize = 6;    /* spec-38.211 sec 7.3.2.2 */
481    pdcch->coresetCfg.interleaverSize = 2;  /* spec-38.211 sec 7.3.2.2 */
482    pdcch->coresetCfg.coreSetType = 0;
483    pdcch->coresetCfg.shiftIndex = pci;
484    pdcch->coresetCfg.precoderGranularity = 0; /* sameAsRegBundle */
485    pdcch->numDlDci = 1;
486    pdcch->dci.rnti = SI_RNTI;
487    pdcch->dci.scramblingId = pci;
488    pdcch->dci.scramblingRnti = 0;
489    pdcch->dci.cceIndex = 0;
490    pdcch->dci.aggregLevel = 4;
491    pdcch->dci.beamPdcchInfo.numPrgs = 1;
492    pdcch->dci.beamPdcchInfo.prgSize = 1;
493    pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
494    pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
495    pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
496    pdcch->dci.txPdcchPower.powerValue = 0;
497    pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
498    /* Storing pdschCfg pointer here. Required to access pdsch config while
499       fillig up pdcch pdu */
500    pdcch->dci.pdschCfg = pdsch; 
501
502    /* fill the PDSCH PDU */
503    uint8_t cwCount = 0;
504    pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
505    pdsch->rnti = 0xFFFF; /* SI-RNTI */
506    pdsch->pduIndex = 0;
507    pdsch->numCodewords = 1;
508    for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
509    {
510       pdsch->codeword[cwCount].targetCodeRate = 308;
511       pdsch->codeword[cwCount].qamModOrder = 2;
512       pdsch->codeword[cwCount].mcsIndex = sib1SchCfg->sib1Mcs;
513       pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
514       pdsch->codeword[cwCount].rvIndex = 0;
515       tbSize = schCalcTbSize(sib1SchCfg->sib1PduLen);
516       pdsch->codeword[cwCount].tbSize = tbSize;
517    }
518    pdsch->dataScramblingId                   = pci;
519    pdsch->numLayers                          = 1;
520    pdsch->transmissionScheme                 = 0;
521    pdsch->refPoint                           = 0;
522    pdsch->dmrs.dlDmrsSymbPos                 = 2;
523    pdsch->dmrs.dmrsConfigType                = 0; /* type-1 */
524    pdsch->dmrs.dlDmrsScramblingId            = pci;
525    pdsch->dmrs.scid                          = 0;
526    pdsch->dmrs.numDmrsCdmGrpsNoData          = 1;
527    pdsch->dmrs.dmrsPorts                     = 0;
528    pdsch->dmrs.mappingType                   = DMRS_MAP_TYPE_A; /* Type-A */
529    pdsch->dmrs.nrOfDmrsSymbols               = NUM_DMRS_SYMBOLS;
530    pdsch->dmrs.dmrsAddPos                    = DMRS_ADDITIONAL_POS;
531
532    pdsch->pdschFreqAlloc.resourceAllocType   = 1; /* RAT type-1 RIV format */
533    pdsch->pdschFreqAlloc.freqAlloc.startPrb  = offset + SCH_SSB_NUM_PRB; /* the RB numbering starts from coreset0,
534                                                                             and PDSCH is always above SSB */
535    pdsch->pdschFreqAlloc.freqAlloc.numPrb    = schCalcNumPrb(tbSize,sib1SchCfg->sib1Mcs,numPdschSymbols);
536    pdsch->pdschFreqAlloc.vrbPrbMapping       = 0; /* non-interleaved */
537    pdsch->pdschTimeAlloc.rowIndex            = 1;
538    pdsch->pdschTimeAlloc.timeAlloc.startSymb = 2; /* spec-38.214, Table 5.1.2.1-1 */
539    pdsch->pdschTimeAlloc.timeAlloc.numSymb   = numPdschSymbols;
540    pdsch->beamPdschInfo.numPrgs              = 1;
541    pdsch->beamPdschInfo.prgSize              = 1;
542    pdsch->beamPdschInfo.digBfInterfaces      = 0;
543    pdsch->beamPdschInfo.prg[0].pmIdx         = 0;
544    pdsch->beamPdschInfo.prg[0].beamIdx[0]    = 0;
545    pdsch->txPdschPower.powerControlOffset    = 0;
546    pdsch->txPdschPower.powerControlOffsetSS  = 0;
547
548 }
549
550 /**
551  * @brief Fill SSB start symbol
552  *
553  * @details
554  *
555  *     Function : fillSsbStartSymb 
556  *      
557  *      This API stores SSB start index per beam
558  *           
559  *  @param[in]  SchCellCb     *cellCb
560  *  @return  int
561  *      -# ROK 
562  *      -# RFAILED 
563  **/
564 void fillSsbStartSymb(SchCellCb *cellCb)
565 {
566    uint8_t cnt, scs;
567
568    scs = cellCb->cellCfg.ssbSchCfg.scsCommon;
569    uint8_t ssbStartSymbArr[SCH_MAX_SSB_BEAM];
570
571    memset(ssbStartSymbArr, 0, sizeof(SCH_MAX_SSB_BEAM));
572    /* Determine value of "n" based on Section 4.1 of 3GPP TS 38.213 */
573    switch(scs)
574    {
575       case SCH_SCS_15KHZ:
576          {
577             uint8_t symbIdx=0;
578             cnt = 2;/* n = 0, 1 for SCS = 15KHz */
579             for(uint8_t idx=0; idx<cnt; idx++)
580             {
581                /* start symbol determined using {2, 8} + 14n */
582                ssbStartSymbArr[symbIdx++] = 2 + SCH_SYMBOL_PER_SLOT*idx;
583                ssbStartSymbArr[symbIdx++]       = 8 +   SCH_SYMBOL_PER_SLOT*idx;
584             }
585          }
586          break;
587       default:
588          DU_LOG("\nSCS %d is currently not supported", scs);
589    }
590    memset(cellCb->ssbStartSymbArr, 0, sizeof(SCH_MAX_SSB_BEAM));
591    memcpy(cellCb->ssbStartSymbArr, ssbStartSymbArr, SCH_MAX_SSB_BEAM);
592
593 }
594
595 /**
596  * @brief cell config from MAC to SCH.
597  *
598  * @details
599  *
600  *     Function : macSchCellCfgReq
601  *      
602  *      This API is invoked by MAC to send cell config to SCH
603  *           
604  *  @param[in]  Pst            *pst
605  *  @param[in]  SchCellCfg     *schCellCfg
606  *  @return  int
607  *      -# ROK 
608  *      -# RFAILED 
609  **/
610 uint8_t SchHdlCellCfgReq(Pst *pst, SchCellCfg *schCellCfg)
611 {
612    uint8_t ret = ROK;
613    SchCellCb *cellCb;
614    SchCellCfgCfm schCellCfgCfm;
615    Pst rspPst;
616    Inst inst = pst->dstInst-1; 
617
618    schInitCellCb(inst, schCellCfg);
619    cellCb = schCb[inst].cells[inst]; //cells is of MAX_CELLS, why inst
620    cellCb->macInst = pst->srcInst;
621
622    /* derive the SIB1 config parameters */
623    fillSchSib1Cfg(
624          inst,
625          &(schCellCfg->sib1SchCfg),
626          schCellCfg->phyCellId,
627          schCellCfg->ssbSchCfg.ssbOffsetPointA);
628    memcpy(&cellCb->cellCfg, schCellCfg, sizeof(SchCellCfg));
629
630    /* Initializing global variables */
631    cellCb->actvUeBitMap = 0;
632    cellCb->boIndBitMap = 0;
633
634    /* Fill and send Cell config confirm */
635    memset(&rspPst, 0, sizeof(Pst));
636    FILL_PST_SCH_TO_MAC(rspPst, pst->dstInst);
637    rspPst.event = EVENT_SCH_CELL_CFG_CFM;
638
639    schCellCfgCfm.cellId = schCellCfg->cellId; 
640    schCellCfgCfm.rsp = RSP_OK;
641
642    ret = (*SchCellCfgCfmOpts[rspPst.selector])(&rspPst, &schCellCfgCfm);
643
644    return ret;
645
646 }
647
648 /*******************************************************************
649  *
650  * @brief Processes DL RLC BO info from MAC
651  *
652  * @details
653  *
654  *    Function : MacSchDlRlcBoInfo
655  *
656  *    Functionality:
657  *       Processes DL RLC BO info from MAC
658  *
659  * @params[in] 
660  * @return ROK     - success
661  *         RFAILED - failure
662  *
663  * ****************************************************************/
664 uint8_t MacSchDlRlcBoInfo(Pst *pst, DlRlcBoInfo *dlBoInfo)
665 {
666    uint8_t  lcId = 0;
667    uint16_t ueIdx = 0;
668    uint16_t slot;
669    SchUeCb *ueCb = NULLP;
670    SchCellCb *cell = NULLP;
671    SchDlSlotInfo *schDlSlotInfo = NULLP;
672
673    Inst  inst = pst->dstInst-SCH_INST_START;
674    DU_LOG("\nSCH : Received RLC BO Status indication");
675    cell = schCb[inst].cells[inst];
676
677    GET_UE_IDX(dlBoInfo->crnti, ueIdx);
678    ueCb = &cell->ueCb[ueIdx-1];
679    lcId  = dlBoInfo->lcId;
680
681    if(lcId == SRB1_LCID || lcId == SRB2_LCID || lcId == SRB3_LCID || \
682       (lcId >= MIN_DRB_LCID && lcId <= MAX_DRB_LCID))
683    {
684       SET_ONE_BIT(ueIdx, cell->boIndBitMap);
685       ueCb->dlLcCtxt[lcId].bo = dlBoInfo->dataVolume;
686    }
687    else if(lcId != SRB0_LCID)
688    {
689       DU_LOG("\nSCH : Invalid LC Id %d in MacSchDlRlcBoInfo", lcId);
690       return RFAILED;
691    }
692
693    slot = (cell->slotInfo.slot + SCHED_DELTA + PHY_DELTA + BO_DELTA) % SCH_NUM_SLOTS;
694    schDlSlotInfo = cell->schDlSlotInfo[slot];
695
696    SCH_ALLOC(schDlSlotInfo->dlMsgInfo, sizeof(DlMsgInfo));
697    if(!schDlSlotInfo->dlMsgInfo)
698    {
699       DU_LOG("\nSCH : Memory allocation failed for dlMsgInfo");
700       schDlSlotInfo = NULL;
701       return RFAILED;
702    }
703    schDlSlotInfo->dlMsgInfo->crnti = dlBoInfo->crnti;
704    schDlSlotInfo->dlMsgInfo->ndi = 1;
705    schDlSlotInfo->dlMsgInfo->harqProcNum = 0;
706    schDlSlotInfo->dlMsgInfo->dlAssignIdx = 0;
707    schDlSlotInfo->dlMsgInfo->pucchTpc = 0;
708    schDlSlotInfo->dlMsgInfo->pucchResInd = 0;
709    schDlSlotInfo->dlMsgInfo->harqFeedbackInd = 0;
710    schDlSlotInfo->dlMsgInfo->dciFormatId = 1;
711    if(lcId == SRB0_LCID)
712       schDlSlotInfo->dlMsgInfo->isMsg4Pdu = true;
713
714    return ROK;
715 }
716
717 /*******************************************************************
718  *
719  * @brief Processes BSR indiation from MAC
720  *
721  * @details
722  *
723  *    Function : MacSchBsr
724  *
725  *    Functionality:
726  *       Processes DL BSR from MAC
727  *
728  * @params[in]    Pst pst
729  *                UlBufferStatusRptInd bsrInd
730  * @return ROK     - success
731  *         RFAILED - failure
732  *
733  * ****************************************************************/
734 uint8_t MacSchBsr(Pst *pst, UlBufferStatusRptInd *bsrInd)
735 {
736    Inst           schInst       = pst->dstInst-SCH_INST_START;
737    SchCellCb      *cellCb       = NULLP;
738    SchUeCb        *ueCb         = NULLP;
739    uint8_t        lcgIdx;
740
741    DU_LOG("\nSCH : Received BSR");
742    cellCb = schCb[schInst].cells[schInst];
743    ueCb = schGetUeCb(cellCb, bsrInd->crnti);
744
745    /* store dataVolume per lcg in uecb */
746    for(lcgIdx = 0; lcgIdx < bsrInd->numLcg; lcgIdx++)
747    {
748       ueCb->bsrInfo[lcgIdx].priority = 1; //TODO: determining LCG priority?
749       ueCb->bsrInfo[lcgIdx].dataVol = bsrInd->dataVolInfo[lcgIdx].dataVol;
750    }
751    return ROK;
752 }
753
754 /*******************************************************************
755  *
756  * @brief Processes SR UCI indication from MAC 
757  *
758  * @details
759  *
760  *    Function : MacSchSrUciInd
761  *
762  *    Functionality:
763  *      Processes SR UCI indication from MAC
764  *
765  * @params[in] Post structure
766  *             UCI Indication
767  * @return ROK     - success
768  *         RFAILED - failure
769  *
770  * ****************************************************************/
771 uint8_t MacSchSrUciInd(Pst *pst, SrUciIndInfo *uciInd)
772 {
773    Inst  inst = pst->dstInst-SCH_INST_START;
774
775    SchUeCb   *ueCb; 
776    SchCellCb *cellCb = schCb[inst].cells[inst];
777
778    DU_LOG("\nSCH : Received SR");
779
780    ueCb = schGetUeCb(cellCb, uciInd->crnti);
781
782    if(uciInd->numSrBits)
783    {
784       ueCb->srRcvd = true;
785    }
786    return ROK;
787 }
788 /**********************************************************************
789   End of file
790  **********************************************************************/