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