Moving all common header file into common_def.h file
[o-du/l2.git] / src / 5gnrmac / rg_rom.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:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code for Entry point fucntions.
26   
27      File:     rg_rom.c
28   
29 **********************************************************************/
30
31 /** @file rg_rom.c
32 @brief APIs to handle all the primitives invoked on RGU interface.
33 */
34
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_FILE_ID=184;
37 static int RLOG_MODULE_ID=4096;
38
39 /* header include files (.h) */
40 #include "common_def.h"
41 #include "rg_env.h"        /* MAC Environment Defines */
42 #include "crg.h"           /* CRG Interface defines */
43 #include "rgu.h"           /* RGU Interface defines */
44 #include "tfu.h"           /* TFU Interface defines */
45 #include "rg_sch_inf.h"           /* RGR Interface defines */
46 #include "lrg.h"           /* LRG Interface defines */
47
48 #include "rg.h"            /* MAC defines */
49 #include "rg_err.h"        /* MAC error defines */
50
51 /* header/extern include files (.x) */
52
53 #include "crg.x"           /* CRG Interface includes */
54 #include "rgu.x"           /* RGU Interface includes */
55 #include "tfu.x"           /* TFU Interface includes */
56 #include "rg_sch_inf.x"    /* SCH Interface includes */
57 #include "rg_prg.x"        /* PRG Interface includes */
58 #include "lrg.x"           /* LRG Interface includes */
59
60 #include "du_app_mac_inf.h"
61 #include "rg.x"            /* MAC includes */
62
63 /* local defines */
64 #define RG_NON_MIMO_IDX 0
65
66 /* local typedefs */
67  
68 S16 RgMacSchBrdcmDedBoUpdtReq ARGS((Inst inst, CmLteCellId cellId, CmLteRnti rnti, CmLteLcId lcId, S32 bo ));
69 PRIVATE S16 rgROMHndlCcchDatReq     ARGS((RgCellCb *cell,
70                                     RgRguCmnDatReq *datReq, RgErrInfo *err));
71 PRIVATE S16 rgROMHndlBcchPcchDatReq ARGS((RgCellCb *cell,
72                                     RgRguCmnDatReq *datReq, RgErrInfo *err));
73 PRIVATE S16 rgROMHndlCcchStaRsp     ARGS((RgCellCb *cell, 
74                                     RgRguCmnStaRsp *staRsp, RgErrInfo *err));
75 PRIVATE S16 rgROMHndlBcchPcchStaRsp ARGS((RgCellCb *cell, 
76                                     RgRguCmnStaRsp *staRsp, RgErrInfo *err));
77
78 /* ADD Changes for Downlink UE Timing Optimization */
79 #ifdef LTEMAC_DLUE_TMGOPTMZ
80 PRIVATE S16 rgROMUpdDlSfRemDataCnt ARGS((RgCellCb  *cellCb,
81                                     RgDlSf    *dlSf));
82 PUBLIC S16 rgTOMUtlProcDlSf ARGS(( RgDlSf     *dlSf,
83                                    RgCellCb   *cellCb,
84                                    RgErrInfo  *err));
85 #endif
86
87 /* forward references */
88
89 /**
90  * @brief Handler for dedicated DatReq received on RGU for an UE.
91  *
92  * @details
93  *
94  *     Function : rgROMDedDatReq
95  *     
96  *     This function shall
97  *      -# store the BO reported for the given logical channels.
98  *      -# invoke DL HARQ for further processing.
99  *     
100  *           
101  *  @param[in]  Inst        inst
102  *  @param[in]  RgRguDedDatReq *datReq 
103  *  @return  S16
104  *      -# ROK 
105  *      -# RFAILED 
106  **/
107 #ifdef ANSI
108 PUBLIC S16 rgROMDedDatReq
109 (
110 Inst      inst,
111 RgRguDedDatReq *datReq
112 )
113 #else
114 PUBLIC S16 rgROMDedDatReq(inst,datReq)
115 Inst      inst;
116 RgRguDedDatReq *datReq;
117 #endif
118 {
119 #if 0
120    RgCellCb     *cell;
121    RgUeCb       *ue;
122    U8           idx1,idx2;
123    RgDlHqProcCb *hqProc;
124    U8           hqPId;
125    RgErrInfo    err;
126    Pst          schPst;
127    RgInfDedBoRpt boRpt;
128    CmLteTimingInfo timingInfo;
129    RgDlSf       *sf;
130 #if (ERRCLASS & ERRCLS_DEBUG)
131    RgUstaDgn   dgn;      /* Alarm diagnostics structure */
132 #endif
133 /* ADD Changes for Downlink UE Timing Optimization */
134 #ifdef LTEMAC_DLUE_TMGOPTMZ
135    S16 ret;
136 #endif
137    U32 idx;
138    //U8  datReqFailCnt = 0;
139
140    TRC2(rgROMDedDatReq)
141
142
143    if (((cell = rgCb[inst].cell) == NULLP) 
144        || (cell->cellId != datReq->cellId))
145    {
146 #if (ERRCLASS & ERRCLS_INT_PAR)
147       /* Handle Cell fetch failure */
148       RGLOGERROR(inst,ERRCLS_INT_PAR,ERG001,(ErrVal)datReq->cellId,
149             "rgROMDedDatReq(): Invalid cell Id");
150 #endif
151       err.errType = RGERR_ROM_DEDDATREQ;
152       err.errCause = RGERR_ROM_INV_CELL_ID;
153       if(cell != NULLP)
154       {
155          /* Update stats */
156          rgUpdtRguDedSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP, datReq);
157       }
158       RETVALUE(RFAILED);
159    }
160
161 /* Add loop here to scan for all UEs in the consolidated DDatReq*/
162    for(idx = 0; idx < datReq->nmbOfUeGrantPerTti; idx++)
163    {
164
165       timingInfo.slot = (U8)((datReq->datReq[idx].transId >> 8) & 0XFF);
166       timingInfo.sfn = (U16)((datReq->datReq[idx].transId >> 16) & 0xFFFF);
167       sf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
168
169       if( (sf->txDone == TRUE) ||
170             (!RG_TIMEINFO_SAME(sf->schdTime,timingInfo)))
171       {
172 #if (ERRCLASS & ERRCLS_DEBUG)
173          /* Transmission is already done for this slot. This is a delayed
174           * datReq. So discard */
175          rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
176          rgLMMStaInd(inst,LCM_CATEGORY_PROTOCOL, LCM_EVENT_UI_INV_EVT,
177                LRG_CAUSE_DELAYED_DATREQ, &dgn);
178 #endif
179          err.errType = RGERR_ROM_DEDDATREQ;
180          err.errCause = RGERR_ROM_DELAYED_DATREQ;
181          /* Update stats */
182          rgUpdtRguDedSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP, datReq);
183 #ifdef CA_DBG
184          {
185             EXTERN U32 dbgDelayedDatReqInMac;
186             dbgDelayedDatReqInMac++;
187          }
188 #endif /* CA_DBG */         
189 #ifndef L2_OPTMZ
190          RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[idx]);
191 #endif
192          continue;
193         // RETVALUE(RFAILED);
194       }
195
196       if ((ue = rgDBMGetUeCb(cell, datReq->datReq[idx].rnti)) == NULLP)
197       {
198 #if (ERRCLASS & ERRCLS_INT_PAR)
199             /* Handle Ue fetch failure */
200             RGLOGERROR(inst,ERRCLS_INT_PAR,ERG002,(ErrVal)datReq->datReq[idx].rnti,
201                   "rgROMDedDatReq(): Invalid ue Id");
202 #endif
203             err.errType = RGERR_ROM_DEDDATREQ;
204             err.errCause = RGERR_ROM_INV_UE_ID;
205             /* Update stats */
206             rgUpdtRguDedSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP, datReq);
207             /* ADD Changes for Downlink UE Timing Optimization */
208 #ifdef LTEMAC_DLUE_TMGOPTMZ
209             /* Trying to send the prev successful PDU's 
210              * if present */
211             ret = rgROMUpdDlSfRemDataCnt(cell, sf);
212             if(ret == RFAILED)
213             {
214                RLOG0(L_INFO, "Dropping due to no ue \n");
215 #ifndef L2_OPTMZ
216                RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[idx]);
217 #endif
218                /* Return from here as above functions found more datReq than expected*/
219               /* RETVALUE(ret); */
220             }
221 #endif
222             /* Conitnue for next UE */
223             continue;
224       }
225
226       hqPId = (U8)(datReq->datReq[idx].transId);
227       hqPId = hqPId >> 2;
228       /* get harq process and invoke DHM */
229       rgDHMGetHqProcFrmId(ue, hqPId, &hqProc);
230
231       if (rgDHMHndlDedDatReq(inst,hqProc, &datReq->datReq[idx], sf, &err) == RFAILED)
232       {
233          RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,
234                    "Handling of Data request in DHM failedi RNTI:%d",
235                     datReq->datReq[idx].rnti);
236          err.errType = RGERR_ROM_DEDDATREQ;
237          /* errcause shall be filled in appropriately by DHM */
238          /* Update stats */
239          rgUpdtRguDedSts(inst,ue->rguDlSap,RG_RGU_SDU_DROP, datReq);
240          /* ADD Changes for Downlink UE Timing Optimization */
241 #ifdef LTEMAC_DLUE_TMGOPTMZ
242          /* Trying to send the prev successful PDU's 
243           * if present */
244          ret = rgROMUpdDlSfRemDataCnt(cell, sf);
245          if(ret == RFAILED)
246          {
247          RLOG0(L_INFO, "Dropping due to no failure of remCnt update");
248 #ifndef L2_OPTMZ
249             RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[idx]);
250 #endif
251             /* Return from here as above functions found more datReq than expected*/
252             //RETVALUE(ret);
253          }
254 #endif
255          continue;
256       }
257
258       /* Merging the updation of statistics of SDUs with for loop below */ 
259
260       rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
261       schPst.event = 0;
262       boRpt.cellSapId  = cell->schInstMap.cellSapId;
263       boRpt.cellId  = datReq->cellId;
264
265       boRpt.rnti    = datReq->datReq[idx].rnti; 
266
267
268       /* Fill the DStaRsp struct and send it to scheduler */
269       for (idx1 = 0; idx1 < datReq->datReq[idx].nmbOfTbs; idx1++)
270       {
271          for(idx2 = 0; idx2 < datReq->datReq[idx].datReqTb[idx1].nmbLch; idx2++)
272          {
273             /* Updating dedicated SDUs received statistics without 
274                additional function above for optimization */
275             ue->rguDlSap->sapSts.numPduRcvd +=
276                datReq->datReq[idx].datReqTb[idx1].lchData[idx2].pdu.numPdu;
277
278             boRpt.lcId    = datReq->datReq[idx].datReqTb[idx1].lchData[idx2].lcId; 
279             boRpt.bo      = datReq->datReq[idx].datReqTb[idx1].lchData[idx2].boReport.bo;
280             boRpt.oldestSduArrTime 
281                = datReq->datReq[idx].datReqTb[idx1].lchData[idx2].boReport.oldestSduArrTime;
282             boRpt.staPduBo = datReq->datReq[idx].datReqTb[idx1].lchData[idx2].boReport.staPduBo;
283             
284             boRpt.setMaxUlPrio= datReq->datReq[idx].datReqTb[idx1].lchData[idx2].setMaxUlPrio;
285 #ifdef CCPU_OPT
286             boRpt.setMaxDlPrio= datReq->datReq[idx].datReqTb[idx1].lchData[idx2].boReport.staPduPrsnt;
287 #endif
288             RgMacSchDedBoUpdt(&schPst, &boRpt);
289          }
290       }
291
292       /* ADD Changes for Downlink UE Timing Optimization */
293 #ifdef LTEMAC_DLUE_TMGOPTMZ
294 //       sf->remDatReqCnt -= datReqFailCnt;
295       /*Presently this function is not returning RFAILED, thus not checking
296         for failure condition.*/
297       ret = rgROMUpdDlSfRemDataCnt(cell, sf);
298       if(ret == RFAILED)
299       {
300          RLOG0(L_INFO, "\n Dropping due to no failure of remCnt update(1) \n");
301 #ifndef L2_OPTMZ
302          RG_DROP_RGUDDATREQ_MBUF(datReq->datReq[idx]);
303 #endif
304          /* Return from here as above functions found more datReq than expected*/
305         // RETVALUE(ret);
306       }
307 #endif
308    } /* for loop for num of Ue per TTI*/
309
310 #endif
311    /* Data send successfully to PHY. lets retuns ROK*/
312    RETVALUE(ROK);
313 }  /* rgROMDedDatReq */
314
315
316 /**
317  * @brief Handler for DatReq received on RGU for a common logical channel.
318  *
319  * @details
320  *
321  *     Function : rgROMCmnDatReq
322  *     
323  *     This function shall invoke rgROMHndlCcchDatReq() if datReq is on CCCH
324  *     If not, it shall invoke rgROMHndlBcchPcchDatReq().
325  *     
326  *           
327  *  @param[in]  Inst        inst
328  *  @param[in]  RgRguCmnDatReq *datReq 
329  *  @return  S16
330  *      -# ROK 
331  *      -# RFAILED 
332  **/
333 #ifdef ANSI
334 PUBLIC S16 rgROMCmnDatReq
335 (
336 Inst            inst,
337 RgRguCmnDatReq *datReq
338 )
339 #else
340 PUBLIC S16 rgROMCmnDatReq(inst,datReq)
341 Inst            inst;
342 RgRguCmnDatReq *datReq;
343 #endif
344 {
345    RgCellCb    *cell;
346    RgErrInfo   err;
347    S16         ret;
348 /* ADD Changes for Downlink UE Timing Optimization */
349 #ifdef LTEMAC_DLUE_TMGOPTMZ
350    CmLteTimingInfo timingInfo;
351    RgDlSf   *sf;
352 #endif
353
354    TRC2(rgROMCmnDatReq)
355
356    ret = ROK;
357    err.errType = RGERR_ROM_CMNDATREQ;
358    if(((cell = rgCb[inst].cell) == NULLP)
359       ||(cell->cellId != datReq->cellId))
360    {
361 #if (ERRCLASS & ERRCLS_INT_PAR)
362       /* Handle Cell fetch failure */
363       RGLOGERROR(inst,ERRCLS_INT_PAR,ERG003,(ErrVal)datReq->cellId,
364                             "rgROMCmnDatReq(): Invalid cell Id");
365 #endif
366       err.errCause = RGERR_ROM_INV_CELL_ID;
367       /* Update stats */
368       if(cell != NULLP)
369       {
370          rgUpdtRguCmnSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP);
371       }
372       RETVALUE(RFAILED);
373    }
374
375    if (datReq->lcId == cell->dlCcchId)
376    {
377       ret = rgROMHndlCcchDatReq(cell, datReq, &err);
378
379       /*Get the timing Info*/
380       /* ADD Changes for Downlink UE Timing Optimization */
381 #ifdef LTEMAC_DLUE_TMGOPTMZ
382       timingInfo.slot = (U8)((datReq->transId >> 8) & 0XFF);
383       timingInfo.sfn = (U16)((datReq->transId >> 16) & 0xFFFF);
384 #endif
385    } 
386    else
387    {
388       ret = rgROMHndlBcchPcchDatReq(cell, datReq, &err);
389
390       /*Get the timing Info*/
391       /* ADD Changes for Downlink UE Timing Optimization */
392 #ifdef LTEMAC_DLUE_TMGOPTMZ
393       timingInfo.slot = (U8)(datReq->transId & 0XFF);
394       timingInfo.sfn = (U16)((datReq->transId >> 8) & 0xFFFF);
395 #endif
396    }
397
398    /* Update stats */
399    if (ret == RFAILED)
400    {
401       rgUpdtRguCmnSts(inst,cell->rguDlSap,RG_RGU_SDU_DROP);
402    }
403    else
404    {
405       /* Update stats with number of SDUs received */
406       rgUpdtRguCmnSts(inst,cell->rguDlSap,RG_RGU_SDU_RCVD);
407    }
408
409    /* ADD Changes for Downlink UE Timing Optimization */
410 #ifdef LTEMAC_DLUE_TMGOPTMZ
411    RG_ARRAY_BOUND_CHECK(0, cell->subFrms, (timingInfo.slot % RG_NUM_SUB_FRAMES));
412    sf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
413
414    ret = rgROMUpdDlSfRemDataCnt(cell, sf);
415    /*Added check for RFAILED as above function can return RFAILED*/
416 #endif
417
418    RETVALUE(ret);
419 }  /* rgROMCmnDatReq */
420
421 /**
422  * @brief Handler for DatReq received on RGU for CCCH.
423  *
424  * @details
425  *
426  *     Function : rgROMHndlCcchDatReq
427  *     
428  *     This function shall fetch the raCb with the given rnti and indicate msg4
429  *     arrival to RAM.
430  *     
431  *           
432  *  @param[in]  RgCellCb       *cell
433  *  @param[in]  RgRguCmnDatReq *datReq 
434  *  @param[out] RgErrInfo      *err
435  *  @return  S16
436  *      -# ROK 
437  *      -# RFAILED 
438  **/
439 #ifdef ANSI
440 PRIVATE S16 rgROMHndlCcchDatReq
441 (
442 RgCellCb       *cell,
443 RgRguCmnDatReq *datReq,
444 RgErrInfo      *err
445 )
446 #else
447 PRIVATE S16 rgROMHndlCcchDatReq(cell, datReq, err)
448 RgCellCb       *cell;
449 RgRguCmnDatReq *datReq;
450 RgErrInfo      *err;
451 #endif
452 {
453    Inst     inst = cell->macInst - RG_INST_START;
454    RgUeCb   *ue;
455    U8       hqPId;
456    RgDlHqProcCb *hqProc;
457    CmLteTimingInfo timingInfo;
458    RgDlSf   *sf;
459 #if (ERRCLASS & ERRCLS_DEBUG)
460    RgUstaDgn   dgn;      /* Alarm diagnostics structure */
461 #endif
462
463    TRC2(rgROMHndlCcchDatReq);
464
465
466    err->errType = RGERR_ROM_CMNDATREQ;
467
468    if ((ue = rgDBMGetUeCb(cell, datReq->u.rnti)) == NULLP)
469    {
470       if ((ue = rgDBMGetUeCbFromRachLst(cell, datReq->u.rnti)) == NULLP)
471       {
472    #if (ERRCLASS & ERRCLS_INT_PAR)
473          /* Handle Ue fetch failure */
474          RGLOGERROR(inst,ERRCLS_INT_PAR,ERG004,(ErrVal)datReq->u.rnti,
475                               "rgROMHndlCcchDatReq(): Invalid ue Id");
476    #endif
477          err->errCause = RGERR_ROM_INV_UE_ID;
478          RETVALUE(RFAILED);
479       }
480    }
481
482    timingInfo.slot = (U8)((datReq->transId >> 8) & 0XFF);
483    timingInfo.sfn = (U16)((datReq->transId >> 16) & 0xFFFF);
484    sf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
485
486    if( (sf->txDone == TRUE) ||
487        (!RG_TIMEINFO_SAME(sf->schdTime,timingInfo)))
488    {
489 #if (ERRCLASS & ERRCLS_DEBUG)
490       /* Transmission is already done for this slot. This is a delayed
491        * datReq. So discard */
492       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
493       rgLMMStaInd(inst,LCM_CATEGORY_PROTOCOL, LCM_EVENT_UI_INV_EVT,
494                               LRG_CAUSE_DELAYED_DATREQ, &dgn);
495 #endif
496       err->errCause = RGERR_ROM_DELAYED_DATREQ;
497       RETVALUE(RFAILED);
498    }
499
500    hqPId = (U8)(datReq->transId);
501    hqPId = hqPId >> 2;
502
503    /* get harq process and invoke DHM */
504    rgDHMGetHqProcFrmId(ue, hqPId, &hqProc);
505  
506    /* Changed for CR timer implementation*/
507    /* invoke DHM to process CCCH data */
508    if (rgDHMHndlCmnDatReq(inst,hqProc, datReq, err) == RFAILED)
509    {
510       RLOG_ARG2(L_ERROR,DBG_CELLID,cell->cellId,
511             "Handling of Data request in DHM failed RNTI:%d LCID:%d",
512             datReq->u.rnti,datReq->lcId);
513       /* Release First TB */
514       rgDHMRlsHqProcTB(cell, hqProc, 1);
515       /* err shall be filled in appropriately by DHM */
516       RETVALUE(RFAILED);
517    }
518  
519    RETVALUE(ROK); 
520 } /* rgROMHndlCcchDatReq */
521
522
523 /**
524  * @brief Handler for DatReq received on RGU for BCCH or PCCH.
525  *
526  * @details
527  *
528  *     Function : rgROMHndlBcchPcchDatReq
529  *     
530  *     This function shall store the buffer and time to transmit in lcCb.
531  *     
532  *           
533  *  @param[in]  RgCellCb       *cell
534  *  @param[in]  RgRguCmnDatReq *datReq 
535  *  @param[out] RgErrInfo      *err
536  *  @return  S16
537  *      -# ROK 
538  *      -# RFAILED 
539  **/
540 #ifdef ANSI
541 PRIVATE S16 rgROMHndlBcchPcchDatReq
542 (
543 RgCellCb       *cell,
544 RgRguCmnDatReq *datReq,
545 RgErrInfo      *err
546 )
547 #else
548 PRIVATE S16 rgROMHndlBcchPcchDatReq(cell, datReq, err)
549 RgCellCb       *cell;
550 RgRguCmnDatReq *datReq;
551 RgErrInfo      *err;
552 #endif
553 {
554    Inst            inst = cell->macInst - RG_INST_START;
555    RgPcchLcCb      *pcch;
556    /* Modified for SI Enhancement*/
557 #ifndef RGR_SI_SCH
558    RgBcchBchLcCb   *bch;
559    RgBcchDlschLcCb *bcch;
560 #endif/*RGR_SI_SCH*/
561    RgDlSf          *sf;
562    CmLteTimingInfo timingInfo;
563 #if (ERRCLASS & ERRCLS_DEBUG)
564    RgUstaDgn   dgn;      /* Alarm diagnostics structure */
565 #endif
566
567    TRC2(rgROMHndlBcchPcchDatReq);
568
569
570    timingInfo.slot = (U8)(datReq->transId & 0XFF);
571    timingInfo.sfn = (U16)((datReq->transId >> 8) & 0xFFFF);
572    sf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
573
574    if( (sf->txDone == TRUE) ||
575        (!RG_TIMEINFO_SAME(sf->schdTime,timingInfo)))
576    {
577 #if (ERRCLASS & ERRCLS_DEBUG)
578       /* Transmission is already done for this slot. This is a delayed
579        * datReq. So discard */
580       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
581       rgLMMStaInd(inst,LCM_CATEGORY_PROTOCOL, LCM_EVENT_UI_INV_EVT,
582                               LRG_CAUSE_DELAYED_DATREQ, &dgn);
583 #endif
584       err->errCause = RGERR_ROM_DELAYED_DATREQ;
585       RETVALUE(RFAILED);
586    }
587
588 #ifndef RGR_SI_SCH
589    bcch = rgDBMGetBcchOnDlsch(cell,datReq->lcId);
590    if (bcch )
591    {
592       /* Store BCCH-DLSCH data received in Scheduled slot */
593       sf->bcch.tb = datReq->pdu;
594
595       SCpyMsgMsg(datReq->pdu, RG_GET_MEM_REGION(rgCb[inst]),
596                RG_GET_MEM_POOL(rgCb[inst]), &bcch->tb);
597
598       RETVALUE(ROK);
599    }
600
601    bch = rgDBMGetBcchOnBch(cell);
602    if ((bch) && (bch->lcId == datReq->lcId))
603    {
604       /* Store BCH data received in Scheduled slot */
605       sf->bch.tb = datReq->pdu;
606       RETVALUE(ROK);
607    }
608 #endif/*RGR_SI_SCH*/
609
610    pcch = rgDBMGetPcch(cell);
611    if ((pcch) && (pcch->lcId == datReq->lcId))
612    {
613       /* Store PCCH-DLSCH data received in Scheduled slot */
614       sf->pcch.tb = datReq->pdu;
615       RETVALUE(ROK);
616    }
617
618    /* Handle lcCb fetch failure */
619    RGLOGERROR(inst,ERRCLS_INT_PAR,ERG005,(ErrVal)datReq->lcId,
620                   "rgROMHndlBcchPcchDatReq(): Invalid Lc Id");
621    err->errCause = RGERR_ROM_INV_LC_ID;
622
623    RETVALUE(RFAILED);
624 } /* rgROMHndlBcchPcchDatReq */
625
626 /**
627  * @brief Handler for StaRsp received on RGU for a dedicated logical channel.
628  *
629  * @details
630  *
631  *     Function : rgROMDedStaRsp
632  *     
633  *     This fucntion shall store the BO reported for the given logical
634  *     channel.
635  *     
636  *           
637  *  @param[in]  Inst        inst
638  *  @param[in]  RgRguDedStaRsp *staRsp 
639  *  @return  S16
640  *      -# ROK 
641  *      -# RFAILED 
642  **/
643 #ifdef ANSI
644 PUBLIC S16 rgROMDedStaRsp
645 (
646 Inst           inst,
647 RgRguDedStaRsp *staRsp
648 )
649 #else
650 PUBLIC S16 rgROMDedStaRsp(inst,staRsp)
651 Inst           inst;
652 RgRguDedStaRsp *staRsp;
653 #endif
654 {
655    RgCellCb   *cell;
656
657    /* Moving the error variables and assignments to available scope */
658
659    TRC2(rgROMDedStaRsp)
660
661    /* Avoiding memset, as the variables of this are getting 
662       initialized */
663
664
665    if(((cell = rgCb[inst].cell) != NULLP)
666       && (cell->cellId == staRsp->cellId))
667    {
668             Pst        schPst;
669 #ifdef UNUSED_VAR
670     RgInfDedBoRpt boRpt
671          boRpt.cellSapId  = cell->schInstMap.cellSapId;
672     boRpt.cellId  = staRsp->cellId;
673          boRpt.rnti    = staRsp->rnti; 
674     boRpt.lcId    = staRsp->lcId; 
675          boRpt.bo      = staRsp->boReport.bo;
676     boRpt.oldestSduArrTime = staRsp->boReport.oldestSduArrTime;
677     boRpt.staPduBo = staRsp->boReport.staPduBo;
678     boRpt.oldestSduArrTime = staRsp->boReport.oldestSduArrTime;
679 #endif
680                                 rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
681             schPst.event = 0;
682             //TODO: commented for compilation without SCH RgMacSchDedBoUpdt(&schPst, &boRpt);
683             RETVALUE(ROK);
684    }
685    RLOG_ARG2(L_ERROR,DBG_CELLID,staRsp->cellId,"Invalid cell for CRNTI:%d LCID:%d ",
686              staRsp->rnti,staRsp->lcId);
687
688    RETVALUE(RFAILED);
689 }  /* rgROMDedStaRsp */
690
691 S16 RgMacSchBrdcmDedBoUpdtReq(
692 Inst inst,
693 CmLteCellId cellId,
694 CmLteRnti rnti, 
695 CmLteLcId lcId, 
696 S32 bo 
697 )
698 {
699
700   RgCellCb   *cell;
701   //if ((cell = rgDBMGetCellCb(cellId)) != NULLP)
702   if (((cell = rgCb[inst].cell) != NULLP) &&
703         (cell->cellId == cellId))
704  {
705      Pst        schPst;
706 #ifdef UNUSED_VAR
707     RgInfDedBoRpt  boRpt;
708     boRpt.cellSapId  = cell->schInstMap.cellSapId;
709     boRpt.cellId     = cellId;
710     boRpt.rnti       = rnti; 
711     boRpt.lcId       = lcId; 
712     boRpt.bo         = bo;
713 #endif
714      rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
715      schPst.event = 0;
716      //TODO: commented for compilation without SCH RgMacSchDedBoUpdtReq (&schPst,&boRpt);
717   }
718   RETVALUE(ROK);
719 }
720 /**
721  * @brief Handler for StaRsp received on RGU for a common logical channel.
722  *
723  * @details
724  *
725  *     Function : rgROMCmnStaRsp
726  *     
727  *     This fucntion shall invoke rgROMHndlCcchStaRsp() for status response on
728  *     CCCH and shall invoke rgROMHndlBcchPcchStaRsp() for status response on
729  *     BCCH or PCCH.
730  *     
731  *           
732  *  @param[in]  Inst        inst
733  *  @param[in]  RgRguCmnStaRsp *staRsp 
734  *  @return  S16
735  *      -# ROK 
736  *      -# RFAILED 
737  **/
738 #ifdef ANSI
739 PUBLIC S16 rgROMCmnStaRsp
740 (
741 Inst            inst, 
742 RgRguCmnStaRsp *staRsp
743 )
744 #else
745 PUBLIC S16 rgROMCmnStaRsp(inst,staRsp)
746 Inst            inst;
747 RgRguCmnStaRsp *staRsp;
748 #endif
749 {
750    RgCellCb   *cell;
751    RgErrInfo  err;
752
753    TRC2(rgROMCmnStaRsp)
754
755
756    if(((cell = rgCb[inst].cell) == NULLP)
757       || (cell->cellId != staRsp->cellId))
758    {
759       /* Handle Cell fetch failure */
760       RLOG_ARG2(L_ERROR,DBG_CELLID,staRsp->cellId,
761                 "Invalid cell for CRNTI:%d LCID:%d",staRsp->u.rnti,staRsp->lcId);
762       err.errType = RGERR_ROM_CMNSTARSP;
763       err.errCause = RGERR_ROM_INV_CELL_ID;
764       RETVALUE(RFAILED);
765    }
766
767    /* handle status response on CCCH */
768    if(staRsp->lcId == cell->dlCcchId)
769    {
770       rgROMHndlCcchStaRsp(cell, staRsp, &err); 
771    }
772    else
773    {
774       rgROMHndlBcchPcchStaRsp(cell, staRsp, &err); 
775    }
776    
777    RETVALUE(ROK);
778 }  /* rgROMCmnStaRsp */
779
780 #ifdef LTE_L2_MEAS
781
782 /**
783  * @brief Handler for Request received on RGU for a UL Throughput measurement
784  * enabled logical channel.
785  *
786  * @details
787  *
788  *     Function :rgROML2MUlThrpMeasReq 
789  *     
790  *     This function shall store the L2M UL Throughput Measurement status  information 
791  *     for the given logical channel.
792  *     
793  *           
794  *  @param[in]  Inst        inst
795  *  @param[in]  RgRguL2MUlThrpMeasReq *measReq 
796  *  @return  S16
797  *      -# ROK 
798  *      -# RFAILED 
799  **/
800 #ifdef ANSI
801 PUBLIC S16 rgROML2MUlThrpMeasReq 
802 (
803 Inst                  inst,
804 RgRguL2MUlThrpMeasReq *measReq
805 )
806 #else
807 PUBLIC S16 rgROML2MUlThrpMeasReq(inst,measReq)
808 Inst                  inst;
809 RgRguL2MUlThrpMeasReq *measReq;
810 #endif
811 {
812    RgCellCb   *cell;
813    RgUeCb     *ue;
814    U8         lcgId;
815    U8         loop;
816    TRC2(rgROML2MUlThrpMeasReq)
817
818
819
820    if(((cell = rgCb[inst].cell) != NULLP)
821       &&(cell->cellId == measReq->cellId))
822    {
823       if ((ue = rgDBMGetUeCb(cell, measReq->rnti)) != NULLP)
824       {
825          for(loop=0; loop<measReq->numLcId;loop++)
826          {
827             if ((rgDBMGetUlDedLcCb(ue, measReq->lcId[loop])) != NULLP)
828             {
829                ue->ul.lcCb[measReq->lcId[loop]].measOn = measReq->enbMeas;
830                if(ue->ul.lcCb[measReq->lcId[loop]].measOn == FALSE)
831                {
832                   lcgId=ue->ul.lcCb[measReq->lcId[loop]].lcgId;
833                   ue->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = 0;
834                   ue->ul.lcgArr[lcgId].lcgBsInfo.firstDatSegRcvd = FALSE;
835                }
836             }
837          }
838          RETVALUE(ROK);
839       }
840    }
841    RLOG_ARG1(L_ERROR,DBG_CELLID,measReq->cellId,"Invalid cell CRNTI:%d",
842              measReq->rnti);
843    RETVALUE(RFAILED);
844 }  /* rgROML2MUlThrpMeasReq */
845
846 #endif
847
848 /**
849  * @brief Handler for StaRsp received on RGU for CCCH.
850  *
851  * @details
852  *
853  *     Function : rgROMHndlCcchStaRsp
854  *     
855  *     This function shall fetch the raCb with the given RNTI and ask RAM to
856  *     update BO. 
857  *     
858  *           
859  *  @param[in]  RgCellCb       *cell
860  *  @param[in]  RgRguCmnStaRsp *staRsp
861  *  @param[out] RgErrInfo      *err
862  *  @return  S16
863  *      -# ROK 
864  *      -# RFAILED 
865  **/
866 #ifdef ANSI
867 PRIVATE S16 rgROMHndlCcchStaRsp
868 (
869 RgCellCb       *cell,
870 RgRguCmnStaRsp *staRsp,
871 RgErrInfo      *err
872 )
873 #else
874 PRIVATE S16 rgROMHndlCcchStaRsp(cell, staRsp, err)
875 RgCellCb       *cell;
876 RgRguCmnStaRsp *staRsp;
877 RgErrInfo      *err;
878 #endif
879 {
880    Pst      schPst;
881    Inst     macInst = cell->macInst - RG_INST_START;
882    //RgInfCmnBoRpt boRpt;
883
884    TRC2(rgROMHndlCcchStaRsp);
885 #ifdef UNUSED_VAR
886    RgInfCmnBoRpt boRpt;
887    boRpt.cellSapId  = cell->schInstMap.cellSapId;
888    boRpt.cellId  = staRsp->cellId;
889    boRpt.u.rnti    = staRsp->u.rnti; 
890    boRpt.lcId    = staRsp->lcId; 
891    boRpt.lcType  = staRsp->lcType; 
892    boRpt.bo      = staRsp->bo;
893 #endif
894    rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
895    //TODO: commented for compilation without SCH RgMacSchCmnBoUpdt(&schPst, &boRpt);
896
897    RETVALUE(ROK);
898 } /* rgROMHndlCcchStaRsp */
899
900
901 /**
902  * @brief Handler for StaRsp received on RGU for BCCH or PCCH.
903  *
904  * @details
905  *
906  *     Function : rgROMHndlBcchPcchStaRsp
907  *     
908  *     This function shall store the buffer and time to transmit in lcCb.
909  *     
910  *           
911  *  @param[in]  RgCellCb       *cell
912  *  @param[in]  RgRguCmnStaRsp *staRsp
913  *  @param[out] RgErrInfo      *err
914  *  @return  S16
915  *      -# ROK 
916  *      -# RFAILED 
917  **/
918 #ifdef ANSI
919 PRIVATE S16 rgROMHndlBcchPcchStaRsp
920 (
921 RgCellCb       *cell,
922 RgRguCmnStaRsp *staRsp,
923 RgErrInfo      *err
924 )
925 #else
926 PRIVATE S16 rgROMHndlBcchPcchStaRsp(cell, staRsp, err)
927 RgCellCb       *cell;
928 RgRguCmnStaRsp *staRsp;
929 RgErrInfo      *err;
930 #endif
931 {
932    Pst      schPst;
933    //RgInfCmnBoRpt boRpt;
934    Inst     macInst = cell->macInst - RG_INST_START;
935
936    TRC2(rgROMHndlBcchPcchStaRsp);
937    cmMemset((U8*)&schPst, (U8)0, sizeof(Pst));
938
939    if (rgDBMChkCmnLcCb(cell, staRsp->lcId) != ROK)
940    {
941       /* Handle lcCb fetch failure */
942       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Invalid LCID:%d",staRsp->lcId);
943       err->errCause = RGERR_ROM_INV_LC_ID;
944       RETVALUE(RFAILED);
945    }
946    /* MS_WORKAROUND : This is to ensure that the queue for BCH is not filled with old BO requests :
947          This assumes that BO is not received more than 4 frames in advance from the enodeb application */
948    if (cell->bcchBchInfo.lcId == staRsp->lcId)
949    {
950       U16 nextBchSfn;
951
952       nextBchSfn = (cell->crntTime.sfn + 4 - (cell->crntTime.sfn%4)) % RG_MAX_SFN;
953       if ((staRsp->u.timeToTx.sfn != nextBchSfn) ||
954          ((staRsp->u.timeToTx.sfn == cell->crntTime.sfn) && (cell->crntTime.slot >= 7)))
955       {
956         RETVALUE(ROK);
957       }
958    }
959 /*
960    boRpt.cellSapId     = cell->schInstMap.cellSapId;
961    boRpt.cellId     = staRsp->cellId;
962    boRpt.u.timeToTx = staRsp->u.timeToTx; 
963    boRpt.lcId       = staRsp->lcId; 
964    boRpt.lcType     = staRsp->lcType; 
965    boRpt.bo         = staRsp->bo;*/     
966 #ifdef EMTC_ENABLE
967   if(cell->emtcEnable)
968   {
969      if(boRpt.lcType == CM_LTE_LCH_PCCH)
970      {
971         boRpt.emtcDIReason = staRsp->emtcDiReason;
972         boRpt.pnb = staRsp->pnb;
973      }
974   }
975 #endif
976    rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
977    //TODO: commented for compilation without SCH RgMacSchCmnBoUpdt(&schPst, &boRpt);
978
979    RETVALUE(ROK);
980 } /* rgROMHndlBcchPcchStaRsp */
981
982 /* ADD Changes for Downlink UE Timing Optimization */
983 #ifdef LTEMAC_DLUE_TMGOPTMZ
984 /**
985  * @brief Handler for updating DL SF information on receiving
986  *  DL dedicated data, CCCH, BCCH/PCCH data request.
987  *
988  * @details
989  *
990  *     Function : rgROMUpdDLSfRemDataCnt
991  *     
992  *           
993  *  @param[in]  RgCellCb       *cell
994  *  @param[in]  RgDlSf         *dlSf;
995  *  @return  S16
996  *      -# ROK 
997  *      -# RFAILED 
998  **/
999 #ifdef ANSI
1000 PRIVATE S16 rgROMUpdDlSfRemDataCnt
1001 (
1002 RgCellCb       *cellCb,
1003 RgDlSf         *dlSf
1004 )
1005 #else
1006 PRIVATE S16 rgROMUpdDlSfRemDataCnt(cellCb, dlSf)
1007 RgCellCb       *cellCb;
1008 RgDlSf         *dlSf;
1009 #endif
1010 {
1011    RgErrInfo            err;
1012    //Inst                 inst = cellCb->macInst - RG_INST_START;
1013
1014    TRC2(rgROMUpdDlSfRemDataCnt);
1015
1016
1017    if(!dlSf->remDatReqCnt)
1018    {
1019        /*This is an error scenario of RLC generating more data          
1020         * request than the allocation. Do nothing for this. */
1021       RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
1022             "RX new data while remDatReqCnt is 0 for cell");
1023       RETVALUE(RFAILED);
1024    }
1025
1026    /*Decrement the remaining data request to be received countter
1027      for this SF.
1028      Check if this was the last pending data request for this DL SF.*/
1029     /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
1030      RLC-MAC */
1031    if((0 == --dlSf->remDatReqCnt) && !(dlSf->txDone) &&
1032       (RG_TIMEINFO_SAME(cellCb->crntTime, dlSf->schdTime)) && (dlSf->statIndDone))
1033    {
1034       /*Check if we have already received a TTI for this Data,
1035         if that is the case then we need to send TFU Data request 
1036         to PHY */
1037
1038       if (ROK != rgTOMUtlProcDlSf (dlSf, cellCb, &err))
1039       {
1040          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
1041                "Unable to process downlink slot for cell");
1042          err.errType = RGERR_ROM_DEDDATREQ;
1043       }
1044
1045       /* Mark this frame as sent */
1046       dlSf->txDone = TRUE;
1047    }
1048
1049    RETVALUE(ROK);
1050 } /* rgROMUpdDlSfRemDataCnt*/
1051 #endif
1052
1053 /**********************************************************************
1054  
1055          End of file
1056 **********************************************************************/