fcdbd436809d10283c8827a0dab69734a642a2f9
[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
304 #ifdef LCKWU
305                case KWU_EVT_DAT_REQ:              /* Data request */
306                   {
307                      ret = cmUnpkKwuDatReq(KwUiKwuDatReq, pst, mBuf);
308                      break;
309                   }
310 #endif /* LCKWU */
311                default:
312                   SPutMsg(mBuf);
313                   if (pst->dstInst < KW_MAX_RLC_INSTANCES)
314                   {
315                       RLOG1(L_ERROR,"Received Invalid Event[%d] from SM",
316                             pst->event);
317                   }
318                   ret = RFAILED;
319                   break;
320
321             }
322             break;
323          }
324
325       case ENTKW:
326          {
327
328             switch(pst->event)
329             {
330 #ifdef LCUDX
331                case UDX_EVT_BND_REQ:              /* Bind request */
332                   {
333                      ret = cmUnpkUdxBndReq(KwDlUdxBndReq, pst, mBuf );
334                      break;
335                   }
336
337                case UDX_EVT_UBND_REQ:              /* Bind request */
338                   {
339                      ret = cmUnpkUdxUbndReq(KwDlUdxUbndReq, pst, mBuf );
340                      break;
341                   }
342                case UDX_EVT_CFG_REQ:             /* Unbind request */
343                   {
344                      ret = cmUnpkUdxCfgReq(KwDlUdxCfgReq, pst, mBuf );
345                      break;
346                   }
347
348                case UDX_EVT_UEIDCHG_REQ:              /* Configuration request */
349                   {
350                      ret = cmUnpkUdxUeIdChgReq(KwDlUdxUeIdChgReq, pst, mBuf);
351                      break;
352                   }
353
354                case UDX_EVT_STA_UPD_REQ:              /* Configuration request */
355                   {
356                      ret = cmUnpkUdxStaUpdReq(KwDlUdxStaUpdReq, pst, mBuf);
357                      break;
358                   }
359
360                case UDX_EVT_STA_PDU_REQ:              /* Configuration request */
361                   {
362                      ret = cmUnpkUdxStaPduReq(KwDlUdxStaPduReq, pst, mBuf);
363                      break;
364                   }
365
366 #ifdef LTE_L2_MEAS
367                case UDX_EVT_L2MEAS_REQ:
368                   {
369                      ret = cmUnpkUdxL2MeasReq(KwDlUdxL2MeasReq, pst, mBuf);
370                      break;
371                   }
372                case UDX_EVT_L2MEAS_SEND_REQ:
373                  {
374
375                     ret = cmUnpkUdxL2MeasSendReq(KwDlUdxL2MeasSendReq, pst, mBuf); 
376   
377                      break;
378                  }
379                case UDX_EVT_L2MEAS_STOP_REQ:
380                  {
381                      ret = cmUnpkUdxL2MeasStopReq(KwDlUdxL2MeasStopReq, pst, mBuf);
382                      break;
383                  }
384 #endif
385
386 #endif  /* LCCKW */
387                case UDX_EVT_DL_CLEANUP_MEM:
388                   {
389                      kwUtlFreeDlMemory(KW_GET_KWCB(pst->dstInst));
390                      break;
391                   }
392                
393                default:
394                   SPutMsg(mBuf);
395                   if (pst->dstInst < KW_MAX_RLC_INSTANCES)
396                   {
397                       RLOG1(L_ERROR,"Received Invalid Event[%d] from RLC UL",
398                             pst->event);
399                   }
400                   ret = RFAILED;
401                   break;
402
403             }
404             break;
405          }
406
407       case ENTNH:
408          {
409             switch(pst->event)
410             {
411 #ifdef LCKWU
412                case KWU_EVT_BND_REQ:              /* Bind request */
413                   {
414                      ret = cmUnpkKwuBndReq(KwUiKwuBndReq, pst, mBuf );
415                      break;
416                   }
417
418                case KWU_EVT_UBND_REQ:             /* Unbind request */
419                   {
420                      ret = cmUnpkKwuUbndReq(KwUiKwuUbndReq, pst, mBuf );
421                      break;
422                   }
423 #ifdef L2_L3_SPLIT
424                case KWU_EVT_CPLANE_DAT_REQ:       /* C-Plane Data request */
425                   {
426                      ret = cmUnpkKwuDatReq(KwUiKwuDatReq, pst, mBuf);
427                      break;
428                   }
429 #else
430                case KWU_EVT_DAT_REQ:              /* Data request */
431                   {
432                      ret = cmUnpkKwuDatReq(KwUiKwuDatReq, pst, mBuf);
433                      break;
434                   }
435 #endif
436                case KWU_EVT_DISC_SDU_REQ:         /* Discard SDU request */
437                   {
438                      ret = cmUnpkKwuDiscSduReq(KwUiKwuDiscSduReq, pst, mBuf);
439                      break;
440                   }
441
442 #endif  /* LCKWU */
443                default:
444                   SPutMsg(mBuf);
445                   if (pst->dstInst < KW_MAX_RLC_INSTANCES)
446                   {
447                       RLOG1(L_ERROR,"Received Invalid Event[%d] from RRC",
448                             pst->event);
449                   }
450                   ret = RFAILED;
451                   break;
452
453             }
454             break;
455          }
456
457       case ENTPJ:
458          {
459             switch(pst->event)
460             {
461 #ifdef LCKWU
462                case KWU_EVT_BND_REQ:              /* Bind request */
463                   {
464                      ret = cmUnpkKwuBndReq(KwUiKwuBndReq, pst, mBuf );
465                      break;
466                   }
467
468                case KWU_EVT_UBND_REQ:             /* Unbind request */
469                   {
470                      ret = cmUnpkKwuUbndReq(KwUiKwuUbndReq, pst, mBuf );
471                      break;
472                   }
473 #ifdef L2_L3_SPLIT
474                case KWU_EVT_CPLANE_DAT_REQ:       /* C-Plane Data request */
475                case KWU_EVT_UPLANE_DAT_REQ:       /* U-Plane Data request */
476                   {
477                      ret = cmUnpkKwuDatReq(KwUiKwuDatReq, pst, mBuf);
478                      break;
479                   }
480 #else
481                case KWU_EVT_DAT_REQ:              /* Data request */
482                   {
483                      ret = cmUnpkKwuDatReq(KwUiKwuDatReq, pst, mBuf);
484                      break;
485                   }
486 #endif
487                case KWU_EVT_DISC_SDU_REQ:         /* Discard SDU request */
488                   {
489                      ret = cmUnpkKwuDiscSduReq(KwUiKwuDiscSduReq, pst, mBuf);
490                      break;
491                   }
492
493                default:
494                   SPutMsg(mBuf);
495                   if (pst->dstInst < KW_MAX_RLC_INSTANCES)
496                   {
497                       RLOG1(L_ERROR,"Received Invalid Event[%d] from PDCP",
498                             pst->event);
499                   }
500                   ret = RFAILED;
501                   break;
502 #endif  /* LCKWU */
503             }
504             break;
505          }
506
507       case ENTRG:
508          {
509             switch(pst->event)
510             {
511 #ifdef LCRGU
512                case EVTRGUBNDCFM:     /* Bind request */
513                   {
514                      ret = cmUnpkRguBndCfm(KwLiRguBndCfm, pst, mBuf );
515                      break;
516                   }
517                case EVTSCHREP:    /* Dedicated Channel Status Response */
518                   {
519                      ret = unpackSchedRep(RlcMacProcSchedRep, pst, mBuf);
520                      break;
521                   }
522                   /* kw005.201 added support for L2 Measurement */
523 #ifdef LTE_L2_MEAS
524                case EVTRGUHQSTAIND:    /* Harq status indication */
525                   {
526                      ret = cmUnpkRguHqStaInd(KwLiRguHqStaInd, pst, mBuf);
527                      break;
528                   }
529 #endif
530                case EVTRGUFLOWCNTRLIND:
531                   {
532                      ret = cmUnpkRguFlowCntrlInd(KwLiRguFlowCntrlInd,pst,mBuf);
533                      break;
534                   }   
535 #endif  /* LCRGU */
536 #ifdef RLC_STA_PROC_IN_MAC/* RLC Status PDU Processing */
537                case UDX_EVT_STA_UPD_REQ:              /* Configuration request */
538                   {
539                      ret = cmUnpkUdxStaUpdReq(KwDlUdxStaUpdReq, pst, mBuf);
540                      break;
541                   }
542 #endif
543
544                default:
545                   SPutMsg(mBuf);
546                   if (pst->dstInst < KW_MAX_RLC_INSTANCES)
547                   {
548                       RLOG1(L_ERROR,"Received Invalid Event[%d] from MAC",
549                             pst->event);
550                   }
551                   ret = RFAILED;
552                   break;
553             }
554             break;
555          }
556 #ifdef SS_RBUF 
557       case ENTTF:
558       {
559             switch(pst->event)
560             {
561                case EVTCTFBTCHPROCTICK:
562                {
563                   kwUtlDlBatchProcPkts();
564                   break;
565                }
566              }
567          SPutMsg(mBuf);
568          break;
569       }
570 #endif
571       case ENTYS:
572          {
573             switch(pst->event)
574             {
575                case KWU_EVT_TTI_IND:
576                   {
577 #if (defined(L2_L3_SPLIT) && defined(ICC_RECV_TSK_RBUF))
578                      kwDlBatchProcSplit();
579 #else 
580 #if defined(PDCP_RLC_DL_RBUF)
581                      kwDlBatchProc();
582 #endif
583 #endif
584
585 #if (defined(SPLIT_RLC_DL_TASK) && defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS))
586                      //KwDlHarqStaBatchProc();
587                      kwUtlDlBatchProcHqStaInd();
588 #endif 
589 #ifndef KWSELFPSTDLCLEAN
590                      /* Revanth_chg */
591                      /* Moving Cleanup from self post event to TTI event */
592                      kwUtlFreeDlMem();
593 #endif 
594
595                      SPutMsg(mBuf);
596                      break;
597                   }
598             }
599             break;
600          }
601
602
603       default:
604          {
605             if (pst->dstInst < KW_MAX_RLC_INSTANCES)
606             {
607                /*KwCb *tKwCb = KW_GET_KWCB(pst->dstInst);*/
608                RLOG1(L_ERROR, "Received Invalid Source Entity[%d]",
609                      pst->event);
610             }
611             SPutMsg(mBuf);
612             ret = RFAILED;
613             break;
614          }
615     }
616    SExitTsk();
617
618    RETVALUE(ret);
619 } /* kwActvTsk */
620
621
622 \f  
623 /********************************************************************30**
624          End of file
625 **********************************************************************/