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