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