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