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