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