fixed unused-function and unused variable warnings
[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             //RgInfDedBoRpt boRpt;
690             Pst        schPst;
691             /*boRpt.cellSapId  = cell->schInstMap.cellSapId;
692             boRpt.cellId  = staRsp->cellId;
693             boRpt.rnti    = staRsp->rnti; 
694             boRpt.lcId    = staRsp->lcId; 
695             boRpt.bo      = staRsp->boReport.bo;
696             boRpt.oldestSduArrTime = staRsp->boReport.oldestSduArrTime;
697             boRpt.staPduBo = staRsp->boReport.staPduBo;
698             boRpt.oldestSduArrTime = staRsp->boReport.oldestSduArrTime;*/
699             rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
700             schPst.event = 0;
701             //TODO: commented for compilation without SCH RgMacSchDedBoUpdt(&schPst, &boRpt);
702             RETVALUE(ROK);
703    }
704    RLOG_ARG2(L_ERROR,DBG_CELLID,staRsp->cellId,"Invalid cell for CRNTI:%d LCID:%d ",
705              staRsp->rnti,staRsp->lcId);
706
707    RETVALUE(RFAILED);
708 }  /* rgROMDedStaRsp */
709
710 S16 RgMacSchBrdcmDedBoUpdtReq(
711 Inst inst,
712 CmLteCellId cellId,
713 CmLteRnti rnti, 
714 CmLteLcId lcId, 
715 S32 bo 
716 )
717 {
718   //RgInfDedBoRpt  boRpt;
719   RgCellCb   *cell;
720   //if ((cell = rgDBMGetCellCb(cellId)) != NULLP)
721   if (((cell = rgCb[inst].cell) != NULLP) &&
722         (cell->cellId == cellId))
723   {
724      Pst        schPst;
725     /* boRpt.cellSapId  = cell->schInstMap.cellSapId;
726      boRpt.cellId     = cellId;
727      boRpt.rnti       = rnti; 
728      boRpt.lcId       = lcId; 
729      boRpt.bo         = bo;*/
730      rgGetPstToInst(&schPst,inst, cell->schInstMap.schInst);
731      schPst.event = 0;
732      //TODO: commented for compilation without SCH RgMacSchDedBoUpdtReq (&schPst,&boRpt);
733   }
734   RETVALUE(ROK);
735 }
736 /**
737  * @brief Handler for StaRsp received on RGU for a common logical channel.
738  *
739  * @details
740  *
741  *     Function : rgROMCmnStaRsp
742  *     
743  *     This fucntion shall invoke rgROMHndlCcchStaRsp() for status response on
744  *     CCCH and shall invoke rgROMHndlBcchPcchStaRsp() for status response on
745  *     BCCH or PCCH.
746  *     
747  *           
748  *  @param[in]  Inst        inst
749  *  @param[in]  RgRguCmnStaRsp *staRsp 
750  *  @return  S16
751  *      -# ROK 
752  *      -# RFAILED 
753  **/
754 #ifdef ANSI
755 PUBLIC S16 rgROMCmnStaRsp
756 (
757 Inst            inst, 
758 RgRguCmnStaRsp *staRsp
759 )
760 #else
761 PUBLIC S16 rgROMCmnStaRsp(inst,staRsp)
762 Inst            inst;
763 RgRguCmnStaRsp *staRsp;
764 #endif
765 {
766    RgCellCb   *cell;
767    RgErrInfo  err;
768
769    TRC2(rgROMCmnStaRsp)
770
771
772    if(((cell = rgCb[inst].cell) == NULLP)
773       || (cell->cellId != staRsp->cellId))
774    {
775       /* Handle Cell fetch failure */
776       RLOG_ARG2(L_ERROR,DBG_CELLID,staRsp->cellId,
777                 "Invalid cell for CRNTI:%d LCID:%d",staRsp->u.rnti,staRsp->lcId);
778       err.errType = RGERR_ROM_CMNSTARSP;
779       err.errCause = RGERR_ROM_INV_CELL_ID;
780       RETVALUE(RFAILED);
781    }
782
783    /* handle status response on CCCH */
784    if(staRsp->lcId == cell->dlCcchId)
785    {
786       rgROMHndlCcchStaRsp(cell, staRsp, &err); 
787    }
788    else
789    {
790       rgROMHndlBcchPcchStaRsp(cell, staRsp, &err); 
791    }
792    
793    RETVALUE(ROK);
794 }  /* rgROMCmnStaRsp */
795
796 #ifdef LTE_L2_MEAS
797
798 /**
799  * @brief Handler for Request received on RGU for a UL Throughput measurement
800  * enabled logical channel.
801  *
802  * @details
803  *
804  *     Function :rgROML2MUlThrpMeasReq 
805  *     
806  *     This function shall store the L2M UL Throughput Measurement status  information 
807  *     for the given logical channel.
808  *     
809  *           
810  *  @param[in]  Inst        inst
811  *  @param[in]  RgRguL2MUlThrpMeasReq *measReq 
812  *  @return  S16
813  *      -# ROK 
814  *      -# RFAILED 
815  **/
816 #ifdef ANSI
817 PUBLIC S16 rgROML2MUlThrpMeasReq 
818 (
819 Inst                  inst,
820 RgRguL2MUlThrpMeasReq *measReq
821 )
822 #else
823 PUBLIC S16 rgROML2MUlThrpMeasReq(inst,measReq)
824 Inst                  inst;
825 RgRguL2MUlThrpMeasReq *measReq;
826 #endif
827 {
828    RgCellCb   *cell;
829    RgUeCb     *ue;
830    U8         lcgId;
831    U8         loop;
832    TRC2(rgROML2MUlThrpMeasReq)
833
834
835
836    if(((cell = rgCb[inst].cell) != NULLP)
837       &&(cell->cellId == measReq->cellId))
838    {
839       if ((ue = rgDBMGetUeCb(cell, measReq->rnti)) != NULLP)
840       {
841          for(loop=0; loop<measReq->numLcId;loop++)
842          {
843             if ((rgDBMGetUlDedLcCb(ue, measReq->lcId[loop])) != NULLP)
844             {
845                ue->ul.lcCb[measReq->lcId[loop]].measOn = measReq->enbMeas;
846                if(ue->ul.lcCb[measReq->lcId[loop]].measOn == FALSE)
847                {
848                   lcgId=ue->ul.lcCb[measReq->lcId[loop]].lcgId;
849                   ue->ul.lcgArr[lcgId].lcgBsInfo.outStndngBs = 0;
850                   ue->ul.lcgArr[lcgId].lcgBsInfo.firstDatSegRcvd = FALSE;
851                }
852             }
853          }
854          RETVALUE(ROK);
855       }
856    }
857    RLOG_ARG1(L_ERROR,DBG_CELLID,measReq->cellId,"Invalid cell CRNTI:%d",
858              measReq->rnti);
859    RETVALUE(RFAILED);
860 }  /* rgROML2MUlThrpMeasReq */
861
862 #endif
863
864 /**
865  * @brief Handler for StaRsp received on RGU for CCCH.
866  *
867  * @details
868  *
869  *     Function : rgROMHndlCcchStaRsp
870  *     
871  *     This function shall fetch the raCb with the given RNTI and ask RAM to
872  *     update BO. 
873  *     
874  *           
875  *  @param[in]  RgCellCb       *cell
876  *  @param[in]  RgRguCmnStaRsp *staRsp
877  *  @param[out] RgErrInfo      *err
878  *  @return  S16
879  *      -# ROK 
880  *      -# RFAILED 
881  **/
882 #ifdef ANSI
883 PRIVATE S16 rgROMHndlCcchStaRsp
884 (
885 RgCellCb       *cell,
886 RgRguCmnStaRsp *staRsp,
887 RgErrInfo      *err
888 )
889 #else
890 PRIVATE S16 rgROMHndlCcchStaRsp(cell, staRsp, err)
891 RgCellCb       *cell;
892 RgRguCmnStaRsp *staRsp;
893 RgErrInfo      *err;
894 #endif
895 {
896    Pst      schPst;
897    Inst     macInst = cell->macInst - RG_INST_START;
898    //RgInfCmnBoRpt boRpt;
899
900    TRC2(rgROMHndlCcchStaRsp);
901
902 /*
903    boRpt.cellSapId  = cell->schInstMap.cellSapId;
904    boRpt.cellId  = staRsp->cellId;
905    boRpt.u.rnti    = staRsp->u.rnti; 
906    boRpt.lcId    = staRsp->lcId; 
907    boRpt.lcType  = staRsp->lcType; 
908    boRpt.bo      = staRsp->bo;
909   */
910    rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
911    //TODO: commented for compilation without SCH RgMacSchCmnBoUpdt(&schPst, &boRpt);
912
913    RETVALUE(ROK);
914 } /* rgROMHndlCcchStaRsp */
915
916
917 /**
918  * @brief Handler for StaRsp received on RGU for BCCH or PCCH.
919  *
920  * @details
921  *
922  *     Function : rgROMHndlBcchPcchStaRsp
923  *     
924  *     This function shall store the buffer and time to transmit in lcCb.
925  *     
926  *           
927  *  @param[in]  RgCellCb       *cell
928  *  @param[in]  RgRguCmnStaRsp *staRsp
929  *  @param[out] RgErrInfo      *err
930  *  @return  S16
931  *      -# ROK 
932  *      -# RFAILED 
933  **/
934 #ifdef ANSI
935 PRIVATE S16 rgROMHndlBcchPcchStaRsp
936 (
937 RgCellCb       *cell,
938 RgRguCmnStaRsp *staRsp,
939 RgErrInfo      *err
940 )
941 #else
942 PRIVATE S16 rgROMHndlBcchPcchStaRsp(cell, staRsp, err)
943 RgCellCb       *cell;
944 RgRguCmnStaRsp *staRsp;
945 RgErrInfo      *err;
946 #endif
947 {
948    Pst      schPst;
949    //RgInfCmnBoRpt boRpt;
950    Inst     macInst = cell->macInst - RG_INST_START;
951
952    TRC2(rgROMHndlBcchPcchStaRsp);
953    cmMemset((U8*)&schPst, (U8)0, sizeof(Pst));
954
955    if (rgDBMChkCmnLcCb(cell, staRsp->lcId) != ROK)
956    {
957       /* Handle lcCb fetch failure */
958       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"Invalid LCID:%d",staRsp->lcId);
959       err->errCause = RGERR_ROM_INV_LC_ID;
960       RETVALUE(RFAILED);
961    }
962    /* MS_WORKAROUND : This is to ensure that the queue for BCH is not filled with old BO requests :
963          This assumes that BO is not received more than 4 frames in advance from the enodeb application */
964    if (cell->bcchBchInfo.lcId == staRsp->lcId)
965    {
966       U16 nextBchSfn;
967
968       nextBchSfn = (cell->crntTime.sfn + 4 - (cell->crntTime.sfn%4)) % RG_MAX_SFN;
969       if ((staRsp->u.timeToTx.sfn != nextBchSfn) ||
970          ((staRsp->u.timeToTx.sfn == cell->crntTime.sfn) && (cell->crntTime.slot >= 7)))
971       {
972         RETVALUE(ROK);
973       }
974    }
975 /*
976    boRpt.cellSapId     = cell->schInstMap.cellSapId;
977    boRpt.cellId     = staRsp->cellId;
978    boRpt.u.timeToTx = staRsp->u.timeToTx; 
979    boRpt.lcId       = staRsp->lcId; 
980    boRpt.lcType     = staRsp->lcType; 
981    boRpt.bo         = staRsp->bo;*/     
982 #ifdef EMTC_ENABLE
983   if(cell->emtcEnable)
984   {
985      if(boRpt.lcType == CM_LTE_LCH_PCCH)
986      {
987         boRpt.emtcDIReason = staRsp->emtcDiReason;
988         boRpt.pnb = staRsp->pnb;
989      }
990   }
991 #endif
992    rgGetPstToInst(&schPst,macInst, cell->schInstMap.schInst);
993    //TODO: commented for compilation without SCH RgMacSchCmnBoUpdt(&schPst, &boRpt);
994
995    RETVALUE(ROK);
996 } /* rgROMHndlBcchPcchStaRsp */
997
998 /* ADD Changes for Downlink UE Timing Optimization */
999 #ifdef LTEMAC_DLUE_TMGOPTMZ
1000 /**
1001  * @brief Handler for updating DL SF information on receiving
1002  *  DL dedicated data, CCCH, BCCH/PCCH data request.
1003  *
1004  * @details
1005  *
1006  *     Function : rgROMUpdDLSfRemDataCnt
1007  *     
1008  *           
1009  *  @param[in]  RgCellCb       *cell
1010  *  @param[in]  RgDlSf         *dlSf;
1011  *  @return  S16
1012  *      -# ROK 
1013  *      -# RFAILED 
1014  **/
1015 #ifdef ANSI
1016 PRIVATE S16 rgROMUpdDlSfRemDataCnt
1017 (
1018 RgCellCb       *cellCb,
1019 RgDlSf         *dlSf
1020 )
1021 #else
1022 PRIVATE S16 rgROMUpdDlSfRemDataCnt(cellCb, dlSf)
1023 RgCellCb       *cellCb;
1024 RgDlSf         *dlSf;
1025 #endif
1026 {
1027    RgErrInfo            err;
1028    //Inst                 inst = cellCb->macInst - RG_INST_START;
1029
1030    TRC2(rgROMUpdDlSfRemDataCnt);
1031
1032
1033    if(!dlSf->remDatReqCnt)
1034    {
1035        /*This is an error scenario of RLC generating more data          
1036         * request than the allocation. Do nothing for this. */
1037       RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
1038             "RX new data while remDatReqCnt is 0 for cell");
1039       RETVALUE(RFAILED);
1040    }
1041
1042    /*Decrement the remaining data request to be received countter
1043      for this SF.
1044      Check if this was the last pending data request for this DL SF.*/
1045     /* Fix[ccpu00126310]: Tracks Data Requests from RLC for both loosely and tight coupled 
1046      RLC-MAC */
1047    if((0 == --dlSf->remDatReqCnt) && !(dlSf->txDone) &&
1048       (RG_TIMEINFO_SAME(cellCb->crntTime, dlSf->schdTime)) && (dlSf->statIndDone))
1049    {
1050       /*Check if we have already received a TTI for this Data,
1051         if that is the case then we need to send TFU Data request 
1052         to PHY */
1053
1054       if (ROK != rgTOMUtlProcDlSf (dlSf, cellCb, &err))
1055       {
1056          RLOG_ARG0(L_ERROR,DBG_CELLID,cellCb->cellId,
1057                "Unable to process downlink slot for cell");
1058          err.errType = RGERR_ROM_DEDDATREQ;
1059       }
1060
1061       /* Mark this frame as sent */
1062       dlSf->txDone = TRUE;
1063    }
1064
1065    RETVALUE(ROK);
1066 } /* rgROMUpdDlSfRemDataCnt*/
1067 #endif
1068
1069 /**********************************************************************
1070  
1071          End of file
1072 **********************************************************************/