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 L2 Measurements in MAC
29 **********************************************************************/
32 @brief This file implements the schedulers main access to MAC layer code.
35 /* header include files -- defines (.h) */
36 #include "envopt.h" /* environment options */
37 #include "envdep.h" /* environment dependent */
38 #include "envind.h" /* environment independent */
39 #include "gen.h" /* general layer */
40 #include "ssi.h" /* system service interface */
41 #include "cm_hash.h" /* common hash list */
42 #include "cm_llist.h" /* common linked list library */
43 #include "cm_err.h" /* common error */
44 #include "cm_lte.h" /* common LTE */
52 #include "rg_sch_inf.h"
55 /* header/extern include files (.x) */
56 #include "gen.x" /* general layer typedefs */
57 #include "ssi.x" /* system services typedefs */
58 #include "cm5.x" /* common timers */
59 #include "cm_hash.x" /* common hash list */
60 #include "cm_lib.x" /* common library */
61 #include "cm_llist.x" /* common linked list */
62 #include "cm_mblk.x" /* memory management */
63 #include "cm_tkns.x" /* common tokens */
64 #include "cm_lte.x" /* common tokens */
65 #include "rgu.x" /* RGU types */
66 #include "tfu.x" /* TFU types */
67 #include "lrg.x" /* layer management typedefs for MAC */
68 #include "rgr.x" /* layer management typedefs for MAC */
69 #include "crg.x" /* layer management typedefs for MAC */
70 #include "rg_sch_inf.x" /* typedefs for Scheduler */
71 #include "rg_prg.x" /* typedefs for PRG interface */
72 #include "rg.x" /* MAC types */
75 static const char* RLOG_MODULE_NAME="MAC";
76 static int RLOG_FILE_ID=183;
77 static int RLOG_MODULE_ID=4096;
82 PRIVATE S16 rgL2mInsertMeasCb ARGS((
85 RgInfL2MeasReq *measInfo ));
87 PRIVATE RgL2MeasCb * rgL2mAllocMeasCb ARGS((
89 RgInfL2MeasReq *measInfo,
92 /* Function definitions */
94 /** @brief This function creates the measCb
98 * Function: rgL2mCreateMeasCb
100 * - Check the measType
101 * - Create measCb for every qci
103 * @param [in] RgCellCb *cell
104 * @param [in] RgInfL2MeasReq *measInfo
105 * @param [in] U8 measType
106 * @param [out] RgErrInfo *err
113 PUBLIC S16 rgL2mCreateMeasCb
116 RgInfL2MeasReq *measInfo,
121 PUBLIC S16 rgL2mCreateMeasCb(cell, measInfo, measType, err)
123 RgInfL2MeasReq *measInfo;
128 // Inst inst = cell->macInst - RG_INST_START;
130 RgL2MeasCb *measCb = NULLP;
136 TRC3(rgL2mCreateMeasCb)
138 if ((measCb = rgL2mAllocMeasCb(cell, measInfo, err)) == NULLP)
140 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"Allocation of RgL2MeasCb failed");
143 //Memcpy is already done in rgL2mAllocMeasCb
144 /*cmMemcpy((U8 *)&measCb->measReq, (CONSTANT U8 *)measInfo,\
145 sizeof(RgInfL2MeasReq));*/
146 rgL2mInsertMeasCb(cell, measCb, measInfo);
147 measCb->measReq.timePrd = measInfo->timePrd;
149 if(measInfo->timePrd == 0)
151 cell->sndL2Meas = FALSE;
154 for(idx = 0; idx < measInfo->t.prbReq.numQci; idx++)
156 if(measInfo->timePrd == 0)
158 qciVal = measInfo->t.prbReq.qci[idx];
159 cell->qciArray[qciVal].qci = qciVal;
161 cell->qciArray[measInfo->t.prbReq.qci[idx]].mask = TRUE;
164 } /* rgL2mCreateMeasCb */
168 * @brief Layer Manager Measurement request handler.
172 * Function : rgL2mMeasReq
174 * This function handles measurement request received at MAC
175 * from the Scheduler.
176 * -# Measurement request will be stored in the list in descending order of
179 * @param[in] Pst *pst, the post structure
180 * @param[in] RgInfL2MeasReq *measInfo, the measurement request structure
181 * @param[out] RgErrInfo *err, error information
186 PUBLIC S16 rgL2mMeasReq
189 RgInfL2MeasReq *measInfo,
193 PUBLIC S16 rgL2mMeasReq(cell, measInfo, err)
195 RgInfL2MeasReq *measInfo;
202 /* Creaet MeasCb Insert in cell->l2mList and return*/
203 if ( (ret = rgL2mCreateMeasCb(cell, measInfo,
204 LRG_L2MEAS_AVG_PRB_PER_QCI_UL, err)) != ROK)
206 /* Clear Downlink MeasCb created Above If exists*/
211 /** @brief This function sends the measurement confirm
212 * from mac to scheduler
216 * Function: rgSndL2MeasCfm
218 * @param [in] RgCellCb *cell
219 * @param [in] RgInfL2MeasCfm *measCfm
222 PRIVATE Void rgSndL2MeasCfm
225 RgInfL2MeasCfm *measCfm
228 PRIVATE Void rgSndL2MeasCfm (cell, measCfm)
230 RgInfL2MeasCfm *measCfm;
234 Inst macInst = cell->macInst - RG_INST_START;
237 cmMemset((U8 *)&pst, 0, sizeof(Pst));
238 rgGetPstToInst(&pst,macInst, cell->schInstMap.schInst);
239 RgMacSchL2Meas(&pst, measCfm);
242 }/* rgSndL2MeasCfm */
244 /** @brief This function sends the measurement stop confirm
245 * from mac to scheduler
249 * Function: rgSndL2MeasStopCfm
251 * @param [in] RgCellCb *cell
252 * @param [in] RgInfL2MeasCfm *measCfm
255 PRIVATE Void rgSndL2MeasStopCfm
258 RgInfL2MeasCfm *measCfm
261 PRIVATE Void rgSndL2MeasStopCfm (cell, measCfm)
263 RgInfL2MeasCfm *measCfm;
267 Inst macInst = cell->macInst - RG_INST_START;
269 TRC3(rgSndL2MeasStopCfm)
270 cmMemset((U8 *)&pst, 0, sizeof(Pst));
271 rgGetPstToInst(&pst,macInst, cell->schInstMap.schInst);
272 RgMacSchL2MeasStop(&pst, measCfm);
275 }/* rgSndL2MeasStopCfm */
278 * @brief L2 Measurement request handler.This function shall be called by
279 * scheduler to calculate average PRB usage Per Qci in Uplink
283 * Function : RgSchMacL2MeasReq
285 * @param[in] Pst *pst, the post structure
286 * @param[in] RgInfL2MeasReq *measInfo, L2 Measurement req structure
292 PUBLIC S16 RgSchMacL2MeasReq
294 Pst *pst, /* post structure */
295 RgInfL2MeasReq *measInfo /* Meas Req Info */
298 PUBLIC S16 RgSchMacL2MeasReq(pst, measInfo)
299 Pst *pst; /* post structure */
300 RgInfL2MeasReq *measInfo; /* Meas Req Info */
304 RgCellCb *cellCb = NULLP;
307 RgInfL2MeasCfm measCfm;
309 TRC3(RgSchMacL2MeasReq)
312 RG_IS_INST_VALID(pst->dstInst);
313 inst = pst->dstInst - RG_INST_START;
314 cellCb = rgCb[inst].cell;
315 /* Get the cell using cellId */
316 if ((cellCb == NULLP) ||
317 (cellCb->cellId != measInfo->cellId))
319 RLOG_ARG0(L_ERROR,DBG_CELLID,measInfo->cellId,"unable to get the cellCb");
322 /* Call L2M Function to store Meas req */
323 ret = rgL2mMeasReq(cellCb, measInfo, &err);
326 cmMemset((U8 *)&measCfm, 0, sizeof(RgInfL2MeasCfm));
327 measCfm.transId = measInfo->transId;
328 measCfm.cellId = measInfo->cellId;
329 measCfm.measType = measInfo->measType;
330 measCfm.cfm.reason = LCM_REASON_INVALID_PAR_VAL;
331 measCfm.cfm.status = LCM_PRIM_NOK;
332 rgSndL2MeasCfm(cellCb, &measCfm);
333 RLOG_ARG2(L_ERROR,DBG_CELLID,measInfo->cellId,
334 "Meas req Failed errType(%d) errCause(%d)",
335 err.errType, err.errCause);
339 } /* -- RgSchMacL2MeasReq-- */
342 * @brief L2 Measurement request handler.This function shall be called by
343 * sch to to stop l2 measurement in MAC,
347 * Function : RgSchMacL2MeasStopReq
349 * @param[in] Pst *pst, the post structure
350 * @param[in] RgInfL2MeasReq *measInfo, L2 Measurement req structure
356 PUBLIC S16 RgSchMacL2MeasStopReq
358 Pst *pst, /* post structure */
359 RgInfL2MeasStopReq *measInfo /* Meas Req Info */
362 PUBLIC S16 RgSchMacL2MeasStopReq(pst, measInfo)
363 Pst *pst; /* post structure */
364 RgInfL2MeasStopReq *measInfo; /* Meas Req Info */
368 CmLList *node = NULLP;
369 RgL2MeasCb *measCb = NULLP;
373 RgCellCb *cellCb = NULLP;
375 RgInfL2MeasCfm measCfm;
377 TRC3(RgSchMacL2MeasStopReq)
380 RG_IS_INST_VALID(pst->dstInst);
381 inst = pst->dstInst - RG_INST_START;
382 cellCb = rgCb[inst].cell;
383 /* Get the cell using cellId */
384 if ((cellCb == NULLP) ||
385 (cellCb->cellId != measInfo->cellId))
388 RLOG_ARG0(L_ERROR,DBG_CELLID,measInfo->cellId,
389 "Unable to get the cellCb");
392 node = cellCb->l2mList.first;
395 measCb = (RgL2MeasCb *)(node)->node;
397 /*L2 Meas off for qci in cell */
398 for(idx = 0; idx < measCb->measReq.t.prbReq.numQci; idx++)
400 qciVal = measCb->measReq.t.prbReq.qci[idx];
401 cellCb->qciArray[qciVal].mask = FALSE;
403 cmLListDelFrm(&cellCb->l2mList, &measCb->measLnk);
404 rgFreeSBuf(inst,(Data**)&measCb, sizeof(RgL2MeasCb));
406 cmMemset((U8 *)&measCfm, 0, sizeof(RgInfL2MeasCfm));
407 measCfm.transId = measInfo->transId;
408 measCfm.cellId = measInfo->cellId;
409 measCfm.measType = measInfo->measType;
410 measCfm.cfm.status = LCM_PRIM_OK;
411 rgSndL2MeasStopCfm(cellCb, &measCfm);
413 } /* -- RgSchMacL2MeasStopReq-- */
416 * @brief L2 Measurement request handler.This function shall be called by
417 * scheduler for sending L2 meas
421 * Function : RgSchMacL2MeasSendReq
423 * @param[in] Pst *pst, the post structure
424 * @param[in] RgInfL2MeasReq *measInfo, L2 Measurement req structure
430 PUBLIC S16 RgSchMacL2MeasSendReq
432 Pst *pst, /* post structure */
433 RgInfL2MeasSndReq *measInfo /* Meas Req Info */
436 PUBLIC S16 RgSchMacL2MeasSendReq(pst, measInfo)
437 Pst *pst; /* post structure */
438 RgInfL2MeasSndReq *measInfo; /* Meas Req Info */
442 RgCellCb *cellCb = NULLP;
445 TRC3(RgSchMacL2MeasSendReq)
448 RG_IS_INST_VALID(pst->dstInst);
449 inst = pst->dstInst - RG_INST_START;
450 cellCb = rgCb[inst].cell;
451 /* Get the cell using cellId */
452 if ((cellCb == NULLP) ||
453 (cellCb->cellId != measInfo->cellId))
456 RLOG_ARG0(L_ERROR,DBG_CELLID,measInfo->cellId,
457 "Unable to get the cellCb");
460 /*set sndL2Meas as applicatoin sent l2 meas info request*/
461 cellCb->sndL2Meas = TRUE;
464 }/*RgSchMacL2MeasSendReq*/
466 /** @brief This function inserts the MeasCb in to data base
470 * Function: rgL2mInsertMeasCb
472 * @param [in] RgCellCb *cell
473 * @param [in] RgL2MeasCb *measCb
474 * @param [in] RgInfMeasReq *measInfo
480 PRIVATE S16 rgL2mInsertMeasCb
484 RgInfL2MeasReq *measInfo
487 PRIVATE S16 rgL2mInsertMeasCb(cell, measCb, measInfo)
490 RgInfL2MeasReq *measInfo;
494 RgL2MeasCb *oldMeasCb;
497 TRC3(rgL2mInsertMeasCb)
500 * 1. Check if l2mList has any entries.
502 * 1. Take the first entrie's time period and find the diff with
504 * 2. If the diff is > measInfo->timePeriod then insert before this
506 * 3. Else take the next entry in list
507 * 4. If reached without adding to list . Append at the end of list.
508 * 3. If no entries in l2mList add at the first.
510 lnk = cell->l2mList.first;
512 node = &measCb->measLnk;
513 node->node = (PTR)measCb;
516 oldMeasCb = (RgL2MeasCb *)lnk->node;
517 diffTime = (oldMeasCb->measReq.timePrd -
518 (RG_CALC_SF_DIFF(cell->crntTime, oldMeasCb->startTime)));
519 if (diffTime > measInfo->timePrd)
521 cell->l2mList.crnt = lnk;
522 cmLListInsCrnt(&(cell->l2mList), node);
531 cmLListAdd2Tail(&(cell->l2mList), node);
533 } /* rgL2mInsertMeasCb */
535 /** @brief This function allocates memory from the heap
539 * Function: rgL2mAllocMeasCb
541 * @param [in] RgCellCb *cell
542 * @param [in] RgInfL2MeasReq *measInfo
543 * @param [out] RgErrInfo *err
544 * @return RgSchL2MeasCb *
547 PRIVATE RgL2MeasCb * rgL2mAllocMeasCb
550 RgInfL2MeasReq *measInfo,
554 PRIVATE RgL2MeasCb * rgL2mAllocMeasCb(cell, measInfo, err)
556 RgInfL2MeasReq *measInfo;
560 RgL2MeasCb *measCb = NULLP;
561 Inst inst = cell->macInst - RG_INST_START;
563 TRC3(rgL2mAllocMeasCb)
565 if((rgAllocSBuf(inst,(Data **)&(measCb),
566 sizeof(RgL2MeasCb))) == RFAILED)
568 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,
569 "Allocation of RgL2MeasCb failed");
570 err->errType = RGERR_L2M_MEASREQ;
571 err->errCause = RGERR_RAM_MEM_EXHAUST;
574 cmMemcpy((U8 *)&measCb->measReq, (U8 *)measInfo, sizeof(RgInfL2MeasReq));
575 RGCPYTIMEINFO(cell->crntTime, measCb->startTime);
578 } /* rgL2mAllocMeasCb */
582 * @brief This function calculates the measurement for measType
583 * LRG_L2MEAS_AVG_PRB_PER_QCI_UL and send the end result to the
588 * Function : rgL2Meas
590 * @param[in] RgCellCb *cell
601 PUBLIC S16 rgL2Meas(cell)
605 CmLList *node = NULLP;
606 RgL2MeasCb *measCb = NULLP;
607 RgInfL2MeasCfm measCfm;
610 U32 measPrd; /*LTE_L2_MEAS_PHASE2*/
611 CmLteTimingInfo crntTime;
612 Inst inst = cell->macInst - RG_INST_START;
616 node = cell->l2mList.first;
620 measCb = (RgL2MeasCb *)node->node;
622 crntTime = cell->crntTime;
624 if(cell->crntTime.sfn == 0 && (cell->crntTime.subframe % RG_NUM_SUB_FRAMES) == 0)
629 measPrd = RG_CALC_SFN_SF_DIFF(cell->crntTime,
630 measCb->sfnCycle, measCb->startTime);
632 /*LTE_L2_MEAS_PHASE2*/
633 if (cell->sndL2Meas || measPrd == measCb->measReq.timePrd)
635 cmMemset((U8 *)&measCfm, 0, sizeof(RgInfL2MeasCfm));
636 for(idx = 0; idx < measCb->measReq.t.prbReq.numQci; idx++)
638 qciVal = measCb->measReq.t.prbReq.qci[idx];
639 measCfm.u.prbCfm.prbUsage[idx].qciValue = qciVal;
641 measCfm.transId = measCb->measReq.transId;
642 measCfm.measType = measCb->measReq.measType;
643 measCfm.cellId = measCb->measReq.cellId;
645 measCfm.u.prbCfm.prbUsage[idx].prbUsage =
646 cell->qciArray[qciVal].prbCount;
648 cell->qciArray[qciVal].prbCount = 0;
649 measCfm.u.prbCfm.numQci++;
650 if(measCb->measReq.timePrd > 0)
652 cell->qciArray[qciVal].mask = FALSE;
655 rgSndL2MeasCfm(cell, &measCfm);
657 if(measCb->measReq.timePrd > 0)
659 cmLListDelFrm(&cell->l2mList, &measCb->measLnk);
660 rgFreeSBuf(inst,(Data**)&measCb, sizeof(RgL2MeasCb));
662 else /*if meas period is 0 then do not delette meascb , just reset l2 cntrs value to 0*/
664 measCb->startTime = crntTime;
665 measCb->measReq.timePrd = 0;
666 cell->sndL2Meas = FALSE;
674 #endif /* LTE_L2_MEAS */
675 /**********************************************************************
678 **********************************************************************/