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