Merge "replaced cmMemSet, cmMemcpy with memset and memcpy resp AND Removed TRC()...
[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 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    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
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 = (U8)((datReq->datReq[idx].transId >> 8) & 0XFF);
164       timingInfo.sfn = (U16)((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             EXTERN U32 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 = (U8)(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 = (U8)((datReq->transId >> 8) & 0XFF);
379       timingInfo.sfn = (U16)((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 = (U8)(datReq->transId & 0XFF);
390       timingInfo.sfn = (U16)((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 PRIVATE S16 rgROMHndlCcchDatReq
437 (
438 RgCellCb       *cell,
439 RgRguCmnDatReq *datReq,
440 RgErrInfo      *err
441 )
442 #else
443 PRIVATE 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    U8       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 = (U8)((datReq->transId >> 8) & 0XFF);
476    timingInfo.sfn = (U16)((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 = (U8)(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 PRIVATE S16 rgROMHndlBcchPcchDatReq
535 (
536 RgCellCb       *cell,
537 RgRguCmnDatReq *datReq,
538 RgErrInfo      *err
539 )
540 #else
541 PRIVATE 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    timingInfo.slot = (U8)(datReq->transId & 0XFF);
561    timingInfo.sfn = (U16)((datReq->transId >> 8) & 0xFFFF);
562    sf = &cell->subFrms[(timingInfo.slot % RG_NUM_SUB_FRAMES)];
563
564    if( (sf->txDone == TRUE) ||
565        (!RG_TIMEINFO_SAME(sf->schdTime,timingInfo)))
566    {
567 #if (ERRCLASS & ERRCLS_DEBUG)
568       /* Transmission is already done for this slot. This is a delayed
569        * datReq. So discard */
570       rgFillDgnParams(inst,&dgn, LRG_USTA_DGNVAL_MEM);
571       rgLMMStaInd(inst,LCM_CATEGORY_PROTOCOL, LCM_EVENT_UI_INV_EVT,
572                               LRG_CAUSE_DELAYED_DATREQ, &dgn);
573 #endif
574       err->errCause = RGERR_ROM_DELAYED_DATREQ;
575       return RFAILED;
576    }
577
578 #ifndef RGR_SI_SCH
579    bcch = rgDBMGetBcchOnDlsch(cell,datReq->lcId);
580    if (bcch )
581    {
582       /* Store BCCH-DLSCH data received in Scheduled slot */
583       sf->bcch.tb = datReq->pdu;
584
585       SCpyMsgMsg(datReq->pdu, RG_GET_MEM_REGION(rgCb[inst]),
586                RG_GET_MEM_POOL(rgCb[inst]), &bcch->tb);
587
588       return ROK;
589    }
590
591    bch = rgDBMGetBcchOnBch(cell);
592    if ((bch) && (bch->lcId == datReq->lcId))
593    {
594       /* Store BCH data received in Scheduled slot */
595       sf->bch.tb = datReq->pdu;
596       return ROK;
597    }
598 #endif/*RGR_SI_SCH*/
599
600    pcch = rgDBMGetPcch(cell);
601    if ((pcch) && (pcch->lcId == datReq->lcId))
602    {
603       /* Store PCCH-DLSCH data received in Scheduled slot */
604       sf->pcch.tb = datReq->pdu;
605       return ROK;
606    }
607
608    /* Handle lcCb fetch failure */
609    RGLOGERROR(inst,ERRCLS_INT_PAR,ERG005,(ErrVal)datReq->lcId,
610                   "rgROMHndlBcchPcchDatReq(): Invalid Lc Id");
611    err->errCause = RGERR_ROM_INV_LC_ID;
612
613    return RFAILED;
614 } /* rgROMHndlBcchPcchDatReq */
615
616 /**
617  * @brief Handler for StaRsp received on RGU for a dedicated logical channel.
618  *
619  * @details
620  *
621  *     Function : rgROMDedStaRsp
622  *     
623  *     This fucntion shall store the BO reported for the given logical
624  *     channel.
625  *     
626  *           
627  *  @param[in]  Inst        inst
628  *  @param[in]  RgRguDedStaRsp *staRsp 
629  *  @return  S16
630  *      -# ROK 
631  *      -# RFAILED 
632  **/
633 #ifdef ANSI
634 S16 rgROMDedStaRsp
635 (
636 Inst           inst,
637 RgRguDedStaRsp *staRsp
638 )
639 #else
640 S16 rgROMDedStaRsp(inst,staRsp)
641 Inst           inst;
642 RgRguDedStaRsp *staRsp;
643 #endif
644 {
645    RgCellCb   *cell;
646
647    /* Moving the error variables and assignments to available scope */
648
649    /* Avoiding memset, as the variables of this are getting 
650       initialized */
651
652
653    if(((cell = rgCb[inst].cell) != NULLP)
654       && (cell->cellId == staRsp->cellId))
655    {
656             Pst        schPst;
657 #ifdef UNUSED_VAR
658     RgInfDedBoRpt boRpt
659          boRpt.cellSapId  = cell->schInstMap.cellSapId;
660     boRpt.cellId  = staRsp->cellId;
661          boRpt.rnti    = staRsp->rnti; 
662     boRpt.lcId    = staRsp->lcId; 
663          boRpt.bo      = staRsp->boReport.bo;
664     boRpt.oldestSduArrTime = staRsp->boReport.oldestSduArrTime;
665     boRpt.staPduBo = staRsp->boReport.staPduBo;
666     boRpt.oldestSduArrTime = staRsp->boReport.oldestSduArrTime;
667 #endif
668                                 rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
669             schPst.event = 0;
670             //TODO: commented for compilation without SCH RgMacSchDedBoUpdt(&schPst, &boRpt);
671             return ROK;
672    }
673    RLOG_ARG2(L_ERROR,DBG_CELLID,staRsp->cellId,"Invalid cell for CRNTI:%d LCID:%d ",
674              staRsp->rnti,staRsp->lcId);
675
676    return RFAILED;
677 }  /* rgROMDedStaRsp */
678
679 S16 RgMacSchBrdcmDedBoUpdtReq(
680 Inst inst,
681 CmLteCellId cellId,
682 CmLteRnti rnti, 
683 CmLteLcId lcId, 
684 S32 bo 
685 )
686 {
687
688   RgCellCb   *cell;
689   //if ((cell = rgDBMGetCellCb(cellId)) != NULLP)
690   if (((cell = rgCb[inst].cell) != NULLP) &&
691         (cell->cellId == cellId))
692  {
693      Pst        schPst;
694 #ifdef UNUSED_VAR
695     RgInfDedBoRpt  boRpt;
696     boRpt.cellSapId  = cell->schInstMap.cellSapId;
697     boRpt.cellId     = cellId;
698     boRpt.rnti       = rnti; 
699     boRpt.lcId       = lcId; 
700     boRpt.bo         = bo;
701 #endif
702      rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
703      schPst.event = 0;
704      //TODO: commented for compilation without SCH RgMacSchDedBoUpdtReq (&schPst,&boRpt);
705   }
706   return ROK;
707 }
708 /**
709  * @brief Handler for StaRsp received on RGU for a common logical channel.
710  *
711  * @details
712  *
713  *     Function : rgROMCmnStaRsp
714  *     
715  *     This fucntion shall invoke rgROMHndlCcchStaRsp() for status response on
716  *     CCCH and shall invoke rgROMHndlBcchPcchStaRsp() for status response on
717  *     BCCH or PCCH.
718  *     
719  *           
720  *  @param[in]  Inst        inst
721  *  @param[in]  RgRguCmnStaRsp *staRsp 
722  *  @return  S16
723  *      -# ROK 
724  *      -# RFAILED 
725  **/
726 #ifdef ANSI
727 S16 rgROMCmnStaRsp
728 (
729 Inst            inst, 
730 RgRguCmnStaRsp *staRsp
731 )
732 #else
733 S16 rgROMCmnStaRsp(inst,staRsp)
734 Inst            inst;
735 RgRguCmnStaRsp *staRsp;
736 #endif
737 {
738    RgCellCb   *cell;
739    RgErrInfo  err;
740
741    if(((cell = rgCb[inst].cell) == NULLP)
742       || (cell->cellId != staRsp->cellId))
743    {
744       /* Handle Cell fetch failure */
745       RLOG_ARG2(L_ERROR,DBG_CELLID,staRsp->cellId,
746                 "Invalid cell for CRNTI:%d LCID:%d",staRsp->u.rnti,staRsp->lcId);
747       err.errType = RGERR_ROM_CMNSTARSP;
748       err.errCause = RGERR_ROM_INV_CELL_ID;
749       return RFAILED;
750    }
751
752    /* handle status response on CCCH */
753    if(staRsp->lcId == cell->dlCcchId)
754    {
755       rgROMHndlCcchStaRsp(cell, staRsp, &err); 
756    }
757    else
758    {
759       rgROMHndlBcchPcchStaRsp(cell, staRsp, &err); 
760    }
761    
762    return ROK;
763 }  /* rgROMCmnStaRsp */
764
765 #ifdef LTE_L2_MEAS
766
767 /**
768  * @brief Handler for Request received on RGU for a UL Throughput measurement
769  * enabled logical channel.
770  *
771  * @details
772  *
773  *     Function :rgROML2MUlThrpMeasReq 
774  *     
775  *     This function shall store the L2M UL Throughput Measurement status  information 
776  *     for the given logical channel.
777  *     
778  *           
779  *  @param[in]  Inst        inst
780  *  @param[in]  RgRguL2MUlThrpMeasReq *measReq 
781  *  @return  S16
782  *      -# ROK 
783  *      -# RFAILED 
784  **/
785 #ifdef ANSI
786 S16 rgROML2MUlThrpMeasReq 
787 (
788 Inst                  inst,
789 RgRguL2MUlThrpMeasReq *measReq
790 )
791 #else
792 S16 rgROML2MUlThrpMeasReq(inst,measReq)
793 Inst                  inst;
794 RgRguL2MUlThrpMeasReq *measReq;
795 #endif
796 {
797    RgCellCb   *cell;
798    RgUeCb     *ue;
799    U8         lcgId;
800    U8         loop;
801
802    if(((cell = rgCb[inst].cell) != NULLP)
803       &&(cell->cellId == measReq->cellId))
804    {
805       if ((ue = rgDBMGetUeCb(cell, measReq->rnti)) != NULLP)
806       {
807          for(loop=0; loop<measReq->numLcId;loop++)
808          {
809             if ((rgDBMGetUlDedLcCb(ue, measReq->lcId[loop])) != NULLP)
810             {
811                ue->ul.lcCb[measReq->lcId[loop]].measOn = measReq->enbMeas;
812                if(ue->ul.lcCb[measReq->lcId[loop]].measOn == FALSE)
813                {
814                   lcgId=ue->ul.lcCb[measReq->lcId[loop]].lcgId;
815                   ue->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = 0;
816                   ue->ul.lcgArr[lcgId].lcgBsInfo.firstDatSegRcvd = FALSE;
817                }
818             }
819          }
820          return ROK;
821       }
822    }
823    RLOG_ARG1(L_ERROR,DBG_CELLID,measReq->cellId,"Invalid cell CRNTI:%d",
824              measReq->rnti);
825    return RFAILED;
826 }  /* rgROML2MUlThrpMeasReq */
827
828 #endif
829
830 /**
831  * @brief Handler for StaRsp received on RGU for CCCH.
832  *
833  * @details
834  *
835  *     Function : rgROMHndlCcchStaRsp
836  *     
837  *     This function shall fetch the raCb with the given RNTI and ask RAM to
838  *     update BO. 
839  *     
840  *           
841  *  @param[in]  RgCellCb       *cell
842  *  @param[in]  RgRguCmnStaRsp *staRsp
843  *  @param[out] RgErrInfo      *err
844  *  @return  S16
845  *      -# ROK 
846  *      -# RFAILED 
847  **/
848 #ifdef ANSI
849 PRIVATE S16 rgROMHndlCcchStaRsp
850 (
851 RgCellCb       *cell,
852 RgRguCmnStaRsp *staRsp,
853 RgErrInfo      *err
854 )
855 #else
856 PRIVATE S16 rgROMHndlCcchStaRsp(cell, staRsp, err)
857 RgCellCb       *cell;
858 RgRguCmnStaRsp *staRsp;
859 RgErrInfo      *err;
860 #endif
861 {
862    Pst      schPst;
863    Inst     macInst = cell->macInst - RG_INST_START;
864    //RgInfCmnBoRpt boRpt;
865
866 #ifdef UNUSED_VAR
867    RgInfCmnBoRpt boRpt;
868    boRpt.cellSapId  = cell->schInstMap.cellSapId;
869    boRpt.cellId  = staRsp->cellId;
870    boRpt.u.rnti    = staRsp->u.rnti; 
871    boRpt.lcId    = staRsp->lcId; 
872    boRpt.lcType  = staRsp->lcType; 
873    boRpt.bo      = staRsp->bo;
874 #endif
875    rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
876    //TODO: commented for compilation without SCH RgMacSchCmnBoUpdt(&schPst, &boRpt);
877
878    return ROK;
879 } /* rgROMHndlCcchStaRsp */
880
881
882 /**
883  * @brief Handler for StaRsp received on RGU for BCCH or PCCH.
884  *
885  * @details
886  *
887  *     Function : rgROMHndlBcchPcchStaRsp
888  *     
889  *     This function shall store the buffer and time to transmit in lcCb.
890  *     
891  *           
892  *  @param[in]  RgCellCb       *cell
893  *  @param[in]  RgRguCmnStaRsp *staRsp
894  *  @param[out] RgErrInfo      *err
895  *  @return  S16
896  *      -# ROK 
897  *      -# RFAILED 
898  **/
899 #ifdef ANSI
900 PRIVATE S16 rgROMHndlBcchPcchStaRsp
901 (
902 RgCellCb       *cell,
903 RgRguCmnStaRsp *staRsp,
904 RgErrInfo      *err
905 )
906 #else
907 PRIVATE S16 rgROMHndlBcchPcchStaRsp(cell, staRsp, err)
908 RgCellCb       *cell;
909 RgRguCmnStaRsp *staRsp;
910 RgErrInfo      *err;
911 #endif
912 {
913    Pst      schPst;
914    //RgInfCmnBoRpt boRpt;
915    Inst     macInst = cell->macInst - RG_INST_START;
916
917    memset(&schPst, 0, sizeof(Pst));
918
919    if (rgDBMChkCmnLcCb(cell, staRsp->lcId) != ROK)
920    {
921       /* Handle lcCb fetch failure */
922       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Invalid LCID:%d",staRsp->lcId);
923       err->errCause = RGERR_ROM_INV_LC_ID;
924       return RFAILED;
925    }
926    /* MS_WORKAROUND : This is to ensure that the queue for BCH is not filled with old BO requests :
927          This assumes that BO is not received more than 4 frames in advance from the enodeb application */
928    if (cell->bcchBchInfo.lcId == staRsp->lcId)
929    {
930       U16 nextBchSfn;
931
932       nextBchSfn = (cell->crntTime.sfn + 4 - (cell->crntTime.sfn%4)) % RG_MAX_SFN;
933       if ((staRsp->u.timeToTx.sfn != nextBchSfn) ||
934          ((staRsp->u.timeToTx.sfn == cell->crntTime.sfn) && (cell->crntTime.slot >= 7)))
935       {
936         return ROK;
937       }
938    }
939 /*
940    boRpt.cellSapId     = cell->schInstMap.cellSapId;
941    boRpt.cellId     = staRsp->cellId;
942    boRpt.u.timeToTx = staRsp->u.timeToTx; 
943    boRpt.lcId       = staRsp->lcId; 
944    boRpt.lcType     = staRsp->lcType; 
945    boRpt.bo         = staRsp->bo;*/     
946 #ifdef EMTC_ENABLE
947   if(cell->emtcEnable)
948   {
949      if(boRpt.lcType == CM_LTE_LCH_PCCH)
950      {
951         boRpt.emtcDIReason = staRsp->emtcDiReason;
952         boRpt.pnb = staRsp->pnb;
953      }
954   }
955 #endif
956    rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
957    //TODO: commented for compilation without SCH RgMacSchCmnBoUpdt(&schPst, &boRpt);
958
959    return ROK;
960 } /* rgROMHndlBcchPcchStaRsp */
961
962 /* ADD Changes for Downlink UE Timing Optimization */
963 #ifdef LTEMAC_DLUE_TMGOPTMZ
964 /**
965  * @brief Handler for updating DL SF information on receiving
966  *  DL dedicated data, CCCH, BCCH/PCCH data request.
967  *
968  * @details
969  *
970  *     Function : rgROMUpdDLSfRemDataCnt
971  *     
972  *           
973  *  @param[in]  RgCellCb       *cell
974  *  @param[in]  RgDlSf         *dlSf;
975  *  @return  S16
976  *      -# ROK 
977  *      -# RFAILED 
978  **/
979 #ifdef ANSI
980 PRIVATE S16 rgROMUpdDlSfRemDataCnt
981 (
982 RgCellCb       *cellCb,
983 RgDlSf         *dlSf
984 )
985 #else
986 PRIVATE S16 rgROMUpdDlSfRemDataCnt(cellCb, dlSf)
987 RgCellCb       *cellCb;
988 RgDlSf         *dlSf;
989 #endif
990 {
991    RgErrInfo            err;
992    //Inst                 inst = cellCb->macInst - RG_INST_START;
993
994    if(!dlSf->remDatReqCnt)
995    {
996        /*This is an error scenario of RLC generating more data          
997         * request than the allocation. Do nothing for this. */
998       RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
999             "RX new data while remDatReqCnt is 0 for cell");
1000       return RFAILED;
1001    }
1002
1003    /*Decrement the remaining data request to be received countter
1004      for this SF.
1005      Check if this was the last pending data request for this DL SF.*/
1006     /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
1007      RLC-MAC */
1008    if((0 == --dlSf->remDatReqCnt) && !(dlSf->txDone) &&
1009       (RG_TIMEINFO_SAME(cellCb->crntTime, dlSf->schdTime)) && (dlSf->statIndDone))
1010    {
1011       /*Check if we have already received a TTI for this Data,
1012         if that is the case then we need to send TFU Data request 
1013         to PHY */
1014
1015       if (ROK != rgTOMUtlProcDlSf (dlSf, cellCb, &err))
1016       {
1017          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
1018                "Unable to process downlink slot for cell");
1019          err.errType = RGERR_ROM_DEDDATREQ;
1020       }
1021
1022       /* Mark this frame as sent */
1023       dlSf->txDone = TRUE;
1024    }
1025
1026    return ROK;
1027 } /* rgROMUpdDlSfRemDataCnt*/
1028 #endif
1029
1030 /**********************************************************************
1031  
1032          End of file
1033 **********************************************************************/