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