U8, U16, U32 data type changes
[o-du/l2.git] / src / 5gnrrlc / kw_lim.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 - Lower Interface Functions
22     
23      Type:    C file
24   
25      Desc:     Source code for RLC Lower Interface Module.
26                This file contains following functions
27       
28         --RlcLiRguBndCfm
29         --rlcProcCommLcUlData
30         --rlcProcDedLcUlData
31         --rlcProcCommLcSchedRpt
32         --rlcProcDedLcSchedRpt
33         --RlcLiRguHqStaInd
34
35      File:     kw_lim.c
36
37 **********************************************************************/
38 static const char* RLOG_MODULE_NAME="LIM";
39 static int RLOG_MODULE_ID=2048;
40 static int RLOG_FILE_ID=196;
41
42 /** 
43  * @file kw_lim.c
44  * @brief RLC Lower Interface module
45 */
46
47 #define RLC_MODULE RLC_DBGMASK_INF
48
49 \f
50 /* header (.h) include files */
51 #include "common_def.h"
52 #include "lkw.h"           /* LKW defines */
53 #include "ckw.h"           /* CKW defines */
54 #include "kwu.h"           /* KWU defines */
55 #include "rgu.h"           /* RGU defines */
56 #include "kw_err.h"
57 #include "kw_env.h"        /* RLC environment options */
58
59 #include "kw.h"            /* RLC defines */
60 #include "kw_udx.h"
61 #include "kw_dl.h"
62 #include "kw_ul.h"
63
64 /* extern (.x) include files */
65 #include "lkw.x"           /* LKW */
66 #include "ckw.x"           /* CKW */
67 #include "kwu.x"           /* KWU */
68 #include "rgu.x"           /* RGU */
69
70 #include "kw.x"
71 #include "kw_udx.x"
72 #include "kw_dl.x"
73 #include "kw_ul.x"
74 #include "rlc_utils.h"
75 #include "rlc_mac_inf.h"
76
77 #ifdef __cplusplus
78 EXTERN "C" {
79 #endif /* __cplusplus */
80
81 \f
82 /*****************************************************************************
83  *                          RGU INTERFACE
84  ****************************************************************************/
85 /**
86  * @brief Handler for bind confirmation from MAC.
87  *
88  * @details
89  *    This function handles the bind confirmation received from MAC. If the 
90  *    bind was successful changes the state of the SAP to RLC_SAP_BND 
91  *    else RLC_SAP_CFG. Sends an alarm to LM in any case
92  *
93  * @param[in] pst     Post structure
94  * @param[in] suId    Service User ID
95  * @param[in] status  Status whether the bind was successful or not
96  *
97  * @return  S16
98  *    -# ROK 
99  *    -# RFAILED 
100  *
101 */
102 #ifdef ANSI
103 S16 RlcLiRguBndCfm
104 (
105 Pst     *pst,   
106 SuId    suId, 
107 uint8_t status 
108 )
109 #else
110 S16 RlcLiRguBndCfm (pst, suId, status)
111 Pst     *pst; 
112 SuId    suId;
113 uint8_t status;
114 #endif
115 {
116    uint16_t      event;     /* Event */
117    uint16_t      cause;     /* Cause */
118    RlcRguSapCb   *rguSap;   /* RGU SAP Control Block */
119    RlcCb         *tRlcCb;
120
121 #if (ERRCLASS & ERRCLS_INT_PAR)
122    if (pst->dstInst >= MAX_RLC_INSTANCES)
123    {
124       return  (RFAILED);
125    }
126 #endif
127    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
128
129    RLOG2(L_DEBUG,"RlcLiRguBndCfm(suId(%d), status(%d)", suId, status);
130
131 #if (ERRCLASS & ERRCLS_INT_PAR)
132    if (tRlcCb->init.cfgDone != TRUE)
133    {
134       RLOG0(L_FATAL,"General configuration not done");
135       
136       RLC_SEND_SAPID_ALARM(tRlcCb,suId,LKW_EVENT_LI_BND_CFM, LCM_CAUSE_INV_STATE);
137
138       return RFAILED;
139    }
140
141    if ((suId >= tRlcCb->genCfg.maxRguSaps) || (suId < 0))
142    {
143       RLOG0(L_ERROR, "Invalid suId");
144       
145       RLC_SEND_SAPID_ALARM(tRlcCb,suId, LKW_EVENT_LI_BND_CFM, LCM_CAUSE_INV_SUID);
146
147       return RFAILED;
148    }
149 #endif /* ERRCLASS & ERRCLS_INT_PAR */
150
151    rguSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
152             &(tRlcCb->u.dlCb->rguDlSap[suId]) : &(tRlcCb->u.ulCb->rguUlSap[suId]);
153
154    RLOG1(L_DEBUG, "RlcLiRguBndCfm: For RGU SAP state=%d", rguSap->state)
155
156    switch (rguSap->state)
157    {
158       case RLC_SAP_BINDING:
159       {
160          rlcStopTmr (tRlcCb,(PTR)rguSap, RLC_EVT_WAIT_BNDCFM);
161
162          rguSap->retryCnt = 0;
163           
164          if (status == CM_BND_OK)
165          {
166             rguSap->state = RLC_SAP_BND;
167             event = LCM_EVENT_BND_OK;
168             cause = LKW_CAUSE_SAP_BNDENB;
169          }
170          else
171          {
172             rguSap->state = RLC_SAP_CFG;
173             event = LCM_EVENT_BND_FAIL;
174             cause = LKW_CAUSE_UNKNOWN;
175          }
176
177          break;
178       }
179       default:
180          event = LKW_EVENT_RGU_BND_CFM;
181          cause = LCM_CAUSE_INV_STATE;
182          break;
183    }
184
185    /* Send an alarm with proper event and cause */
186    RLC_SEND_SAPID_ALARM(tRlcCb, suId, event, cause);
187
188    return (ROK);
189 } /* RlcLiRguBndCfm */
190
191 int   rlcDDatIndRcvd;
192 int   rlcCDatIndRcvd;
193 /**
194  * @brief Handler to process PDU received from MAC for common logical channels. 
195  *
196  * @details
197  *    This function receives the PDU from MAC for common logical channels
198  *    does checks before handing over the PDU to the TM module
199  *
200  * @param[in] pst     Post structure
201  * @param[in] suId    Service User ID
202  * @param[in] datInd  Data Indication Information 
203  *
204  * @return  S16
205  *    -# ROK 
206  *    -# RFAILED 
207  *
208 */
209 uint8_t rlcProcCommLcUlData(Pst *pst, SuId suId, RguCDatIndInfo *datInd)
210 {
211    RlcUlRbCb   *rbCb; 
212    RlcCb       *tRlcCb; 
213
214    rlcCDatIndRcvd++;
215
216 #if (ERRCLASS & ERRCLS_INT_PAR)
217    if (pst->dstInst >= MAX_RLC_INSTANCES)
218    {
219       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, datInd, sizeof(RguCDatIndInfo));
220       return RFAILED;
221    }
222 #endif
223
224    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
225
226 #if (ERRCLASS & ERRCLS_DEBUG)
227    if (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL)
228    {
229       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, datInd, sizeof(RguCDatIndInfo));
230       return RFAILED;
231    }
232 #endif
233
234    /* kw006.201 ccpu00120058, Added array boundary condition check */
235 #if (ERRCLASS & ERRCLS_DEBUG)
236    if(RLC_MAX_LCH_PER_CELL <= datInd->lcId)
237    {
238       DU_LOG("\nRLC : rlcProcCommLcUlData : Invalid LcId [%d], Max is [%d]",\
239          datInd->lcId, RLC_MAX_LCH_PER_CELL);
240       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, datInd, sizeof(RguCDatIndInfo));
241       return RFAILED;
242    }
243 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
244
245    /* Fetch RbCb from lcId */
246    rlcDbmFetchUlRbCbFromLchId(tRlcCb, datInd->rnti, datInd->cellId, datInd->lcId, &rbCb);
247    if (!rbCb)
248    {
249       DU_LOG("\nRLC : rlcProcCommLcUlData : LcId [%d] not found",
250          datInd->lcId);
251       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, datInd, sizeof(RguCDatIndInfo));
252       return RFAILED;
253    }
254
255    /* Dispatch to TM Module */
256 #ifdef CCPU_OPT
257    rlcTmmRcvFrmMac(tRlcCb, rbCb, datInd->rnti, datInd->pdu);
258 #else /* CCPU_OPT */
259    rlcTmmRcvFrmMac(tRlcCb, rbCb, datInd->pdu);
260 #endif /* CCPU_OPT */
261
262    RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, datInd, sizeof(RguCDatIndInfo));
263
264    return (ROK);
265 } /* rlcProcCommLcUlData */
266
267 /**
268  * @brief Handler to process PDU received from MAC for 
269  *        dedicated logical channels. 
270  *
271  * @details
272  *    This function receives the PDU from MAC for one or more dedicated 
273  *    logical channels and passes it to the UTL module for further processing
274  *
275  * @param[in] pst     Post structure
276  * @param[in] suId    Service User ID
277  * @param[in] datInd  Data Indication Information 
278  *
279  * @return  S16
280  *    -# ROK 
281  *    -# RFAILED 
282  *
283 */
284  
285 uint8_t rlcProcDedLcUlData(Pst *pst, SuId suId, RguDDatIndInfo *datInd)
286 {
287    rlcDDatIndRcvd++;
288 #if (ERRCLASS & ERRCLS_INT_PAR)
289    if (pst->dstInst >= MAX_RLC_INSTANCES)
290    {
291        RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, datInd, sizeof(RguDDatIndInfo));
292        return RFAILED;
293    }
294 #endif
295
296 #if (ERRCLASS & ERRCLS_DEBUG)
297    if (((RlcCb*)RLC_GET_RLCCB(pst->dstInst))->genCfg.rlcMode == LKW_RLC_MODE_DL)
298    {
299        DU_LOG("\nRLC : rlcProcDedLcUlData : suId(%d))recieved in DL Inst", suId);
300        RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, datInd, sizeof(RguDDatIndInfo));
301        return RFAILED;
302    }
303 #endif
304    rlcUtlRcvFrmMac(RLC_GET_RLCCB(pst->dstInst),datInd);
305 #ifndef SS_RBUF 
306 #ifdef SS_LOCKLESS_MEMORY
307    RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, datInd, sizeof(RguDDatIndInfo));
308 #else
309    RLC_PST_FREE(RLC_MEM_REGION_UL, RLC_POOL, datInd, sizeof(RguDDatIndInfo));
310 #endif
311 #endif
312
313    return ROK;
314 } /* rlcProcDedLcUlData */
315
316 /**
317  * @brief Handler for trigerring the data transfer from RLC to MAC
318  *        for common logical channels.
319  *
320  * @details
321  *    This function receives the size of the PDU to be transmitted
322  *    and acts as a trigger for forming PDU and sending it to MAC. 
323  *
324  * @param[in] pst       Post structure
325  * @param[in] suId      Service User ID
326  * @param[in] staInd    Status Indication Information for Common Logical 
327  *                      Channels
328  *
329  * @return  S16
330  *    -# ROK 
331  *    -# RFAILED 
332  *
333 */ 
334 uint8_t rlcProcCommLcSchedRpt(Pst *pst, SuId suId, RguCStaIndInfo *staInd)
335 {
336    RlcDlRbCb   *rbCb;  
337    RlcCb       *tRlcCb;
338
339 #if (ERRCLASS & ERRCLS_INT_PAR)
340    if (pst->dstInst >= MAX_RLC_INSTANCES)
341    {
342       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguCStaIndInfo));
343       return  (RFAILED);
344    }
345 #endif
346
347    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
348
349 #if (ERRCLASS & ERRCLS_INT_PAR)
350    if ((suId >= tRlcCb->genCfg.maxRguSaps) || (suId < 0))
351    {
352       DU_LOG("\nRLC: rlcProcCommLcSchedRpt: Invalid RGU suId %d\n", suId);
353       return RFAILED; 
354    }
355    if (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_UL)
356    {
357        DU_LOG("\nRLC: rlcProcCommLcSchedRpt: Received in RLC UL CELLID:%d",
358              staInd->cellId);
359        RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguCStaIndInfo));
360        return RFAILED;
361    }
362 #endif
363
364    rbCb = NULLP;
365
366    /* kw006.201 ccpu00120058, added boundary condition check */
367 #if (ERRCLASS & ERRCLS_DEBUG)
368    if(RLC_MAX_LCH_PER_CELL < staInd->lcId)
369    {
370       DU_LOG("\nRLC: rlcProcCommLcSchedRpt: Invalid LcId, Max is [%d] CELLID:%d",
371          RLC_MAX_LCH_PER_CELL, staInd->cellId);
372       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguCStaIndInfo));
373       return RFAILED;
374    }
375 #endif /* (ERRCLASS & ERRCLS_DEBUG) */
376    /* Fertch RbCb from lcId */
377    rlcDbmFetchDlRbCbFromLchId(tRlcCb,0, staInd->cellId, staInd->lcId, &rbCb);
378    if(!rbCb)                                               
379    {
380       DU_LOG("\nRLC: rlcProcCommLcSchedRpt: LcId [%d] not found CELLID:%d",
381          staInd->lcId, staInd->cellId);
382       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguCStaIndInfo));
383       return RFAILED;
384    }
385
386    /* Dispatch to TM Module */
387    rbCb->transId = staInd->transId;
388    rlcTmmSendToMac(tRlcCb, suId, rbCb, staInd);
389 #ifndef SS_RBUF
390 #ifdef SS_LOCKLESS_MEMORY
391    RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguCStaIndInfo));
392 #else
393    RLC_PST_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguCStaIndInfo));
394 #endif
395 #else
396    RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguCStaIndInfo));
397 #endif
398    return ROK;
399 } /* rlcProcCommLcSchedRpt */
400
401 /**
402  * @brief Handler for trigerring the data transfer from RLC to MAC
403  *        for dedicated logical channels.
404  *
405  * @details
406  *    This function receives the size of the PDUs to be transmitted to
407  *    MAC via one or more dedicated logical channels and acts as a trigger
408  *    for forming PDUs and sending them to MAC. 
409  *
410  * @param[in] pst       Post structure
411  * @param[in] suId      Service User ID
412  * @param[in] staInd    Status Indication Information for Dedicated Logical 
413  *                      Channels
414  *
415  * @return  S16
416  *    -# ROK 
417  *    -# RFAILED 
418  *
419 */ 
420 uint8_t rlcProcDedLcSchedRpt(Pst *pst, SuId suId, RguDStaIndInfo *staInd)
421 {
422    RlcCb        *gCb;
423
424 #if (ERRCLASS & ERRCLS_INT_PAR)
425    if (pst->dstInst >= MAX_RLC_INSTANCES)
426    {
427       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguDStaIndInfo));
428       return RFAILED;
429    }
430 #endif
431
432    gCb = RLC_GET_RLCCB(pst->dstInst);
433
434 #if (ERRCLASS & ERRCLS_INT_PAR)
435    if (((RlcCb*)RLC_GET_RLCCB(pst->dstInst))->genCfg.rlcMode == LKW_RLC_MODE_UL)
436    {
437        DU_LOG("\nRLC: rlcProcDedLcSchedRpt: Received in RLC UL ");
438        RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguDStaIndInfo));
439        return RFAILED;
440    }
441    if ((suId >= gCb->genCfg.maxRguSaps) || (suId < 0))
442    {
443       DU_LOG("\nRLC: rlcProcDedLcSchedRpt: Invalid RGU suId %d\n", suId);
444       return (RFAILED); 
445    }
446 #endif
447    rlcUtlSendToMac(gCb, suId, staInd);
448
449    /* kw002.201 :Freeing from proper region */
450    RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, staInd, sizeof(RguDStaIndInfo));
451    return ROK;
452 } /* rlcProcDedLcSchedRpt */
453
454 /**
455  * @brief Handler for handling the flow cntrl Ind from MAC
456  *  to RLC      
457  *
458  * @details
459  *   This function receives the flow control indication from
460  *   MAC and calls rlcUtlTrigPdbFlowCntrl
461  *
462  * @param[in] pst       Post structure
463  * @param[in] suId      Service User ID
464  * @param[in] flowCntrlInd flow control Indication Information 
465  *           from MAC  
466  *
467  * @return  S16
468  *    -# ROK 
469  *    -# RFAILED 
470  *
471 */ 
472 #ifdef ANSI
473 S16 RlcLiRguFlowCntrlInd
474 (
475 Pst              *pst,  
476 SuId             suId,
477 RguFlowCntrlInd *flowCntrlInd
478 )
479 #else
480 S16 RlcLiRguFlowCntrlInd(pst, suId, flowCntrlInd)
481 Pst              *pst; 
482 SuId             suId; 
483 RguFlowCntrlInd  *flowCntrlInd; 
484 #endif
485 {
486    RlcCb       *tRlcCb; 
487    RlcDlRbCb   *rbCb = NULLP;
488    uint32_t    idx;
489    uint32_t    lcIdx;
490
491    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
492    for (idx = 0; idx < flowCntrlInd->numUes; idx++)
493    {
494       for (lcIdx = 0; lcIdx < flowCntrlInd->ueFlowCntrlInfo[idx].numLcs; lcIdx++)  
495       {
496          RguLcFlowCntrlInfo *lcInfo = &(flowCntrlInd->ueFlowCntrlInfo[idx].lcInfo[lcIdx]); 
497          rlcDbmFetchDlRbCbFromLchId(tRlcCb, flowCntrlInd->ueFlowCntrlInfo[idx].ueId, flowCntrlInd->cellId, lcInfo->lcId, &rbCb);
498          if (rbCb)
499          {
500            
501             if (lcInfo->pktAdmitCnt == 0) /* Special case */
502             {
503                rlcUtlTrigPdbFlowCntrl(tRlcCb, rbCb, lcInfo->pktAdmitCnt);
504                continue;
505             }
506             if (rbCb->mode == CM_LTE_MODE_AM)
507             {
508                if ((rbCb->m.amDl.retxLst.count != 0) || 
509                    ((rbCb->m.amDl.bo == 0) || 
510                     (rbCb->m.amDl.bo < lcInfo->maxBo4FlowCtrl)))
511                {
512                   continue;
513                }
514             }
515             else /* UM */
516             {
517                if ((rbCb->m.umDl.bo == 0) ||
518                    (rbCb->m.umDl.bo < lcInfo->maxBo4FlowCtrl))
519                {
520                   continue;
521                }
522             }
523             rlcUtlTrigPdbFlowCntrl(tRlcCb, rbCb, lcInfo->pktAdmitCnt);
524          }
525       }
526    }
527    return ROK;
528 }
529 /* kw005.201 added support for L2 Measurement */
530 #ifdef LTE_L2_MEAS
531 \f
532 /**
533  *
534  * @brief  
535  *
536  *        Handler for indicating the Harq Status of the data sent.
537  *
538  * @b Description:
539  *
540  *        This function receives the harq status of the data sent to MAC.
541  *        This information is used for two things.
542  *        1. Computing the UuLoss of UM
543  *        2. Computing the DL Delay for UM and AM.
544  *
545  *  @param[in] pst     -   Post structure  
546  *  @param[in] suId    -   Service User ID
547  *  @param[in] staInd  -   Harq Status Indication Information. 
548  *
549  *  @return  S16
550  *      -# ROK 
551  *      -# RFAILED
552  *
553  */
554 #ifdef ANSI
555 S16 RlcLiRguHqStaInd
556 (
557 Pst                *pst, 
558 SuId               suId,
559 RguHarqStatusInd   *staInd 
560 )
561 #else
562 S16 RlcLiRguHqStaInd(pst,suId,staInd)
563 Pst                *pst;  
564 SuId               suId; 
565 RguHarqStatusInd   *staInd;
566 #endif
567 {
568
569    RlcUeKey   ueKey;
570    S16        ret; 
571    RlcDlUeCb  *ueCb;
572    uint8_t    tbIdx;
573    RlcCb      *tRlcCb; 
574
575    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
576    ueKey.cellId = staInd->cellId;
577    ueKey.ueId   = staInd->ueId;
578
579    ret = rlcDbmFetchDlUeCb(tRlcCb, ueKey.ueId, ueKey.cellId, &ueCb);
580    if (ret != ROK )
581    {
582       return RFAILED;
583    }
584
585    /*Call rlcUtlProcHarqInd as many times as number of Tbs present*/
586    for ( tbIdx = 0; tbIdx < staInd->numTbs; tbIdx++)
587    {
588       rlcUtlProcHarqInd(tRlcCb, staInd, ueCb, tbIdx);
589    }
590
591    return (ROK);
592 } /* RlcLiRguHqStaInd */
593 #endif /* LTE_L2_MEAS */
594
595 #ifdef __cplusplus
596 }
597 #endif /* __cplusplus */
598
599 /********************************************************************30**
600          End of file
601 **********************************************************************/