Memory handling fixes
[o-du/l2.git] / src / 5gnrrlc / rlc_dl_msg_router.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**
20   
21         Name:    NR RLC Layer - System Services Interface Functions
22     
23         Type:    C file
24   
25         Desc:    C source code for the interface to System Services
26                   of NR RLC
27  
28         File:    rlc_dl_msg_router.c
29   
30 *********************************************************************21*/
31
32 /** @filerlc_dl_msg_router.c
33 @brief RLC System Services Interface
34 */
35
36 \f
37 /* header (.h) include files */
38 #include "common_def.h"
39 #include "lkw.h"           /* LKW defines */
40 #include "ckw.h"           /* CKW defines */
41 #include "kwu.h"           /* KWU defines */
42 #include "rgu.h"           /* RGU defines */
43 #include "rlc_err.h"        /* Err defines */
44 #include "rlc_env.h"        /* RLC environment options */
45
46
47
48 /* extern (.x) include files */
49 #include "lkw.x"           /* LKW */
50 #include "ckw.x"           /* CKW */
51 #include "kwu.x"           /* KWU */
52 #include "rgu.x"           /* RGU */
53
54 #include "rlc_utils.h"            /* RLC defines */
55 #include "rlc_dl_ul_inf.h"
56 #include "rlc_dl.h"
57 #include "du_app_rlc_inf.h"
58 #include "rlc_mac_inf.h"
59
60 #include "ctf.h"
61 S16 rlcUtlDlBatchProcPkts(Void);
62 S16 rlcDlBatchProc(Void);
63 #if (defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS))
64 uint32_t isDatReqProcessed;
65 void rlcUtlDlBatchProcHqStaInd ARGS ((Void));
66 #endif
67
68 #if (defined(L2_L3_SPLIT) && defined(ICC_RECV_TSK_RBUF))
69 S16 rlcDlBatchProcSplit  ARGS((Void));
70 #endif
71 //UDAY
72 #ifdef L2_OPTMZ
73 uint32_t rlcAmmStaPduList[512] = {0};
74 S16 ssGetDBufOfSize ARGS((Region region, Size size, Buffer **dBuf));
75 #endif
76 S16 rlcDlInitExt ARGS (( Void ));
77 \f
78 /**
79  *
80  * @brief
81  *
82  *  <b> Initialize External </b>
83  *
84  *  @b Description:
85  *  Initializes variables used to interface with Upper/Lower Layer  
86  *
87  *  @return  S16
88  *      -# ROK 
89  *
90 */
91   
92 S16 rlcDlInitExt()
93 {
94    return ROK;
95 } /* kwInitExt */
96
97
98 \f
99 /***********************************************************************
100                       System Service Interface Functions
101  ***********************************************************************/
102 /**
103  *
104  * @brief
105  *
106  *    <b> Activates Initialization </b>
107  *
108  *    @b Description:
109  *    This function is invoked by system services to initialize the NR RLC
110  *    layer. This is an entry point used by LTE_RLC layer to initialize its
111  *    global variables, before becoming operational.
112  *
113  *    Allowable values for parameters are specified in ssi.h.
114  *
115  *    @param[in] ent    - Specify the entity id of the NR RLC task.
116  *    @param[in] inst   - Specify the entity id of the NR RLC task.
117  *    @param[in] region - Specifies the memory region from which
118  *                         NR RLC should allocate structures and buffers.
119  *    @param[in] reason - Specifies the reason for calling this
120  *                         initialization function.
121  *
122  *  @return  S16
123  *      -# ROK 
124  *
125  */
126 S16 rlcDlActvInit
127 (
128 Ent    ent,                 /* entity */
129 Inst   inst,                /* instance */
130 Region region,              /* region */
131 Reason reason               /* reason */
132 )
133 {
134    RlcCb    *tRlcCb;
135
136    if (inst >= MAX_RLC_INSTANCES)
137    {
138        /* intance greater than MAX instances */ 
139        return RFAILED; 
140    }
141
142    if (rlcCb[inst] != NULLP)
143    {
144        return  (RFAILED);
145    }
146   
147    if (SGetSBuf(region, 0, (Data **)&tRlcCb,
148                 (Size)sizeof (RlcCb)) != ROK)    
149    {                     
150       return RFAILED;
151    }
152    /* Initialize rlcCb */
153    RLC_MEM_SET(tRlcCb, 0, sizeof(RlcCb));
154
155    /* Initialize task configuration parameters */
156    tRlcCb->init.ent     = ent;           /* entity */
157    tRlcCb->init.inst    = inst;          /* instance */
158    tRlcCb->init.region  = region;        /* static region */
159    tRlcCb->init.pool    = 0;             /* static pool */
160    tRlcCb->init.reason  = reason;        /* reason */
161    tRlcCb->init.cfgDone = FALSE;         /* configuration done */
162    tRlcCb->init.acnt    = TRUE;          /* enable accounting */
163    tRlcCb->init.usta    = TRUE;          /* enable unsolicited status */
164    tRlcCb->init.trc     = FALSE;         /* enable trace */
165    tRlcCb->init.procId  = ODU_GET_PROCID();
166
167    rlcCb[inst] = tRlcCb;
168
169 //UDAY
170 #ifdef L2_OPTMZ
171    for(int i = 0; i < 512; i++)
172    {
173       Buffer *mBuf = NULL;
174       Buffer *bufPtr = NULL;
175       ODU_GET_MSG_BUF(1, 0 , &mBuf);
176       ssGetDBufOfSize(1 , 1800, &bufPtr);
177       SUpdMsg(mBuf, bufPtr, 0);
178       rlcAmmStaPduList[i] = (uint32_t)mBuf; 
179    }
180 #endif
181    /* call external function for intialization */
182    /*
183    kwInitExt();
184    */
185
186    
187
188    return ROK;
189 } /* kwActvInit */
190
191 \f
192 /**
193  *
194  * @brief
195  *
196  *  <b> Activation Task </b>
197  *
198  *  @b Description:
199  *  Processes events received for NR RLC layer via System Services from
200  *  other layers.
201  *
202  *  @param[in] pst   - Pst Structure
203  *  @param[in] mBuf  - Message Buffer
204  *
205  *  @return  S16
206  *      -# ROK 
207  *
208  */
209 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
210 pthread_t gRlcTId = 0;
211 #endif
212 S16 rlcDlActvTsk
213 (
214 Pst *pst,              /* pst structure */
215 Buffer *mBuf            /* message buffer */
216 )
217 {
218    S16 ret = ROK;
219
220 #ifdef RLC_FREE_RING_BUF
221    gRlcTId = pthread_self();
222 #endif
223
224    switch(pst->srcEnt)
225    {
226       case ENTDUAPP:
227          {
228             switch(pst->event)
229             {
230 #ifdef LCLKW
231                case LKW_EVT_CFG_REQ:
232                   {
233                      ret = unpackRlcConfigReq(RlcMiRlcConfigReq, pst, mBuf);
234                      break;
235                   }
236
237                case LKW_EVT_CNTRL_REQ:
238                   {
239                      ret = cmUnpkLkwCntrlReq(RlcMiLkwCntrlReq, pst, mBuf);
240                      break;
241                   }
242
243                case LKW_EVT_STS_REQ:
244                   {
245                      ret = cmUnpkLkwStsReq(RlcMiLkwStsReq, pst, mBuf);
246                      break;
247                   }
248
249                case LKW_EVT_STA_REQ:
250                   {
251                      ret = cmUnpkLkwStaReq(RlcMiLkwStaReq, pst, mBuf);
252                      break;
253                   }
254                   /* kw005.201 added support for L2 Measurement */
255 #endif  /* LCLKW */
256
257 #ifdef LCKWU
258                case KWU_EVT_DAT_REQ:              /* Data request */
259                   {
260                      //ret = cmUnpkKwuDatReq(rlcProcDlData, pst, mBuf);
261                      break;
262                   }
263 #endif /* LCKWU */
264                
265                case EVENT_DL_RRC_MSG_TRANS_TO_RLC:
266                   {
267                      ret = unpackDlRrcMsgToRlc(RlcProcDlRrcMsgTransfer, pst, mBuf);
268                      break;
269                   }
270                case EVENT_DL_USER_DATA_TRANS_TO_RLC:
271                   {
272                      ret = unpackRlcDlUserDataToRlc(RlcProcDlUserDataTransfer, pst, mBuf);
273                      break;
274                   }
275                default:
276                   ODU_PUT_MSG_BUF(mBuf);
277                   if (pst->dstInst < MAX_RLC_INSTANCES)
278                   {
279                       DU_LOG("\nERROR  --> RLC_DL : Received Invalid Event[%d] from SM",
280                             pst->event);
281                   }
282                   ret = RFAILED;
283                   break;
284
285             }
286             break;
287          }
288
289       case ENTRLC:
290          {
291
292             switch(pst->event)
293             {
294 #ifdef LCUDX
295                case UDX_EVT_BND_REQ:              /* Bind request */
296                   {
297                      ret = cmUnpkUdxBndReq(rlcDlUdxBndReq, pst, mBuf );
298                      break;
299                   }
300
301                case UDX_EVT_UBND_REQ:              /* Bind request */
302                   {
303                      ret = cmUnpkUdxUbndReq(rlcDlUdxUbndReq, pst, mBuf );
304                      break;
305                   }
306                case UDX_EVT_CFG_REQ:             /* Unbind request */
307                   {
308                      ret = cmUnpkUdxCfgReq(rlcDlUdxCfgReq, pst, mBuf );
309                      break;
310                   }
311
312                case UDX_EVT_UEIDCHG_REQ:              /* Configuration request */
313                   {
314                      ret = cmUnpkUdxUeIdChgReq(rlcDlUdxUeIdChgReq, pst, mBuf);
315                      break;
316                   }
317
318                case UDX_EVT_STA_UPD_REQ:              /* Configuration request */
319                   {
320                      ret = cmUnpkUdxStaUpdReq(rlcDlUdxStaUpdReq, pst, mBuf);
321                      break;
322                   }
323
324                case UDX_EVT_STA_PDU_REQ:              /* Configuration request */
325                   {
326                      ret = cmUnpkUdxStaPduReq(rlcDlUdxStaPduReq, pst, mBuf);
327                      break;
328                   }
329
330 #ifdef LTE_L2_MEAS
331                case UDX_EVT_L2MEAS_REQ:
332                   {
333                      ret = cmUnpkUdxL2MeasReq(rlcDlUdxL2MeasReq, pst, mBuf);
334                      break;
335                   }
336                case UDX_EVT_L2MEAS_SEND_REQ:
337                  {
338
339                     ret = cmUnpkUdxL2MeasSendReq(rlcDlUdxL2MeasSendReq, pst, mBuf); 
340   
341                      break;
342                  }
343                case UDX_EVT_L2MEAS_STOP_REQ:
344                  {
345                      ret = cmUnpkUdxL2MeasStopReq(rlcDlUdxL2MeasStopReq, pst, mBuf);
346                      break;
347                  }
348 #endif
349
350 #endif  /* LCCKW */
351                case UDX_EVT_DL_CLEANUP_MEM:
352                   {
353                      rlcUtlFreeDlMemory(RLC_GET_RLCCB(pst->dstInst));
354                      break;
355                   }
356                
357                default:
358                   ODU_PUT_MSG_BUF(mBuf);
359                   if (pst->dstInst < MAX_RLC_INSTANCES)
360                   {
361                       DU_LOG("\nERROR  --> RLC_DL : Received Invalid Event[%d] from RLC UL",
362                             pst->event);
363                   }
364                   ret = RFAILED;
365                   break;
366
367             }
368             break;
369          }
370
371       case ENTNH:
372          {
373             switch(pst->event)
374             {
375 #ifdef LCKWU
376                case KWU_EVT_BND_REQ:              /* Bind request */
377                   {
378                      ret = cmUnpkKwuBndReq(RlcUiKwuBndReq, pst, mBuf );
379                      break;
380                   }
381
382                case KWU_EVT_UBND_REQ:             /* Unbind request */
383                   {
384                      ret = cmUnpkKwuUbndReq(RlcUiKwuUbndReq, pst, mBuf );
385                      break;
386                   }
387 #ifdef L2_L3_SPLIT
388                case KWU_EVT_CPLANE_DAT_REQ:       /* C-Plane Data request */
389                   {
390                      ret = cmUnpkKwuDatReq(rlcProcDlData, pst, mBuf);
391                      break;
392                   }
393 #else
394                case KWU_EVT_DAT_REQ:              /* Data request */
395                   {
396                      //ret = cmUnpkKwuDatReq(rlcProcDlData, pst, mBuf);
397                      break;
398                   }
399 #endif
400                case KWU_EVT_DISC_SDU_REQ:         /* Discard SDU request */
401                   {
402                      ret = cmUnpkKwuDiscSduReq(RlcUiKwuDiscSduReq, pst, mBuf);
403                      break;
404                   }
405
406 #endif  /* LCKWU */
407                default:
408                   ODU_PUT_MSG_BUF(mBuf);
409                   if (pst->dstInst < MAX_RLC_INSTANCES)
410                   {
411                      DU_LOG("\nERROR  --> RLC_DL : Received Invalid Event[%d] from RRC",
412                             pst->event);
413                   }
414                   ret = RFAILED;
415                   break;
416
417             }
418             break;
419          }
420
421       case ENTPJ:
422          {
423             switch(pst->event)
424             {
425 #ifdef LCKWU
426                case KWU_EVT_BND_REQ:              /* Bind request */
427                   {
428                      ret = cmUnpkKwuBndReq(RlcUiKwuBndReq, pst, mBuf );
429                      break;
430                   }
431
432                case KWU_EVT_UBND_REQ:             /* Unbind request */
433                   {
434                      ret = cmUnpkKwuUbndReq(RlcUiKwuUbndReq, pst, mBuf );
435                      break;
436                   }
437 #ifdef L2_L3_SPLIT
438                case KWU_EVT_CPLANE_DAT_REQ:       /* C-Plane Data request */
439                case KWU_EVT_UPLANE_DAT_REQ:       /* U-Plane Data request */
440                   {
441                      ret = cmUnpkKwuDatReq(rlcProcDlData, pst, mBuf);
442                      break;
443                   }
444 #else
445                case KWU_EVT_DAT_REQ:              /* Data request */
446                   {
447                      //ret = cmUnpkKwuDatReq(rlcProcDlData, pst, mBuf);
448                      break;
449                   }
450 #endif
451                case KWU_EVT_DISC_SDU_REQ:         /* Discard SDU request */
452                   {
453                      ret = cmUnpkKwuDiscSduReq(RlcUiKwuDiscSduReq, pst, mBuf);
454                      break;
455                   }
456
457                default:
458                   ODU_PUT_MSG_BUF(mBuf);
459                   if (pst->dstInst < MAX_RLC_INSTANCES)
460                   {
461                      DU_LOG("\nERROR  --> RLC_DL : Received Invalid Event[%d] from PDCP",
462                             pst->event);
463                   }
464                   ret = RFAILED;
465                   break;
466 #endif  /* LCKWU */
467             }
468             break;
469          }
470
471       case ENTMAC:
472          {
473             switch(pst->event)
474             {
475 #ifdef LCRGU
476                case EVTRGUBNDCFM:     /* Bind request */
477                   {
478                      ret = cmUnpkRguBndCfm(RlcLiRguBndCfm, pst, mBuf );
479                      break;
480                   }
481                case EVENT_SCHED_RESULT_TO_RLC: 
482                   {
483                      ret = unpackSchedResultRpt(RlcProcSchedResultRpt, pst, mBuf);
484                      break;
485                   }
486                   /* kw005.201 added support for L2 Measurement */
487 #ifdef LTE_L2_MEAS
488                case EVTRGUHQSTAIND:    /* Harq status indication */
489                   {
490                      ret = cmUnpkRguHqStaInd(RlcLiRguHqStaInd, pst, mBuf);
491                      break;
492                   }
493 #endif
494                case EVTRGUFLOWCNTRLIND:
495                   {
496                      ret = cmUnpkRguFlowCntrlInd(RlcLiRguFlowCntrlInd,pst,mBuf);
497                      break;
498                   }   
499 #endif  /* LCRGU */
500 #ifdef RLC_STA_PROC_IN_MAC/* RLC Status PDU Processing */
501                case UDX_EVT_STA_UPD_REQ:              /* Configuration request */
502                   {
503                      ret = cmUnpkUdxStaUpdReq(rlcDlUdxStaUpdReq, pst, mBuf);
504                      break;
505                   }
506 #endif
507
508                default:
509                   ODU_PUT_MSG_BUF(mBuf);
510                   if (pst->dstInst < MAX_RLC_INSTANCES)
511                   {
512                       DU_LOG("\nERROR  --> RLC_DL : Received Invalid Event[%d] from MAC",
513                             pst->event);
514                   }
515                   ret = RFAILED;
516                   break;
517             }
518             break;
519          }
520 #ifdef SS_RBUF 
521       case ENTLWRMAC:
522       {
523             switch(pst->event)
524             {
525                case EVTCTFBTCHPROCTICK:
526                {
527                   rlcUtlDlBatchProcPkts();
528                   break;
529                }
530              }
531          ODU_PUT_MSG_BUF(mBuf);
532          break;
533       }
534 #endif
535       case ENTYS:
536          {
537             switch(pst->event)
538             {
539                case KWU_EVT_TTI_IND:
540                   {
541 #if (defined(L2_L3_SPLIT) && defined(ICC_RECV_TSK_RBUF))
542                      rlcDlBatchProcSplit();
543 #else 
544 #if defined(PDCP_RLC_DL_RBUF)
545                      rlcDlBatchProc();
546 #endif
547 #endif
548
549 #if (defined(SPLIT_RLC_DL_TASK) && defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS))
550                      //RlcDlHarqStaBatchProc();
551                      rlcUtlDlBatchProcHqStaInd();
552 #endif 
553 #ifndef KWSELFPSTDLCLEAN
554                      /* Revanth_chg */
555                      /* Moving Cleanup from self post event to TTI event */
556                      rlcUtlFreeDlMem();
557 #endif 
558
559                      ODU_PUT_MSG_BUF(mBuf);
560                      break;
561                   }
562             }
563             break;
564          }
565
566
567       default:
568          {
569             if (pst->dstInst < MAX_RLC_INSTANCES)
570             {
571                /*RlcCb *tRlcCb = RLC_GET_RLCCB(pst->dstInst);*/
572                DU_LOG("\nERROR  --> RLC_DL : Received Invalid Source Entity[%d]",
573                      pst->event);
574             }
575             ODU_PUT_MSG_BUF(mBuf);
576             ret = RFAILED;
577             break;
578          }
579     }
580    ODU_EXIT_TASK();
581
582    return (ret);
583 } /* kwActvTsk */
584
585
586 \f  
587 /********************************************************************30**
588          End of file
589 **********************************************************************/