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