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