f050a9589ff8e1de2a43ea231b82b5a2ceffa018
[o-du/l2.git] / src / 5gnrrlc / kw_tmr.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:    RLC - TMR module file
22     
23         Type:    C source file
24   
25         Desc:    Source code for timer functions such as, 
26
27                  - kwStartTmr
28                  - kwStopTmr
29                  - kwTmrExpiry
30                  - kwBndTmrExpiry  
31                   
32         File:    kw_tmr.c
33   
34 *********************************************************************21*/
35 static const char* RLOG_MODULE_NAME="TMR";
36 static int RLOG_MODULE_ID=2048;
37 static int RLOG_FILE_ID=202;
38
39
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_env.h"        /* RLC environment options */
58
59 #include "kw.h"            /* RLC defines */
60 #include "kw_err.h"        /* Error defines */
61 #include "kw_ul.h"
62 #include "kw_udx.h"
63 #include "kw_dl.h"
64
65 /* extern (.x) include files */
66 #include "gen.x"           /* general */
67 #include "ssi.x"           /* system services */
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
80 #include "kw.x"
81 #include "kw_udx.x"
82 #include "kw_dl.x"
83 #include "kw_ul.x"
84
85 /** 
86  * @file gp_tmr.c
87  * @brief RLC Timer Module
88 */
89
90 /**
91  * @def KW_TMR_CALCUATE_WAIT
92  *
93  *    This macro calculates and assigns wait time based on the value of the 
94  *    timer and the timer resolution. Timer value of 0 signifies that the
95  *    timer is not configured
96  *
97  * @param[out] _wait   Time for which to arm the timer changed to proper 
98  *                     value according to the resolution
99  * @param[in] _tmrVal   Value of the timer
100  * @param[in] _timerRes   Resolution of the timer
101  *
102 */
103 #define KW_TMR_CALCUATE_WAIT(_wait, _tmrVal, _timerRes)       \
104 {                                                             \
105    (_wait) = ((_tmrVal) * SS_TICKS_SEC)/((_timerRes) * 1000); \
106    if((0 != (_tmrVal)) && (0 == (_wait)))                     \
107    {                                                          \
108       (_wait) = 1;                                            \
109    }                                                          \
110 }
111
112 /* private function declarations */
113 PRIVATE Void kwBndTmrExpiry(PTR cb);
114
115 /**
116  * @brief Handler to start timer
117  *       
118  * @param[in] gCb       Pointer to the RLC instance control block
119  * @param[in] cb        Control block depending on the type of the timer event. 
120  *                      It can be uplink/downlink rbCb or rgu sap control block
121  * @param[in] tmrEvnt   Timer event to be started
122  *
123  * @return  Void
124 */
125 #ifdef ANSI
126 PUBLIC Void kwStartTmr
127 (
128 KwCb  *gCb,
129 PTR   cb,          
130 S16   tmrEvnt     
131 )
132 #else
133 PUBLIC Void kwStartTmr (gCb,cb, tmrEvnt)
134 KwCb  *gCb;
135 PTR   cb;        
136 S16   tmrEvnt;  
137 #endif
138 {
139 /* kw005.201 added support for L2 Measurement */
140 #ifdef LTE_L2_MEAS
141    KwL2MeasEvtCb *measEvtCb = NULLP;
142 #endif
143
144    CmTmrArg arg;
145    arg.wait = 0;
146
147    TRC2(kwStartTmr)
148
149    /* kw002.201 Adjusting the wait time as per timeRes configured by layer manager */
150    switch (tmrEvnt)
151    {
152       case KW_EVT_UMUL_REORD_TMR:
153       {
154          KwUmUl* umUl = &(((KwUlRbCb *)cb)->m.umUl);
155          /* kw005.201 Changed wait calculation ccpu00117634*/ 
156          KW_TMR_CALCUATE_WAIT(arg.wait, umUl->reOrdTmrInt, gCb->genCfg.timeRes);
157
158          arg.timers = &umUl->reOrdTmr;
159          arg.max = KW_MAX_UM_TMR;
160          break;
161       }
162       case KW_EVT_AMUL_REORD_TMR:
163       {
164          KwAmUl* amUl = &(((KwUlRbCb *)cb)->m.amUl);
165          /* kw005.201 Changed wait calculation ccpu00117634*/ 
166          KW_TMR_CALCUATE_WAIT(arg.wait, amUl->reOrdTmrInt, gCb->genCfg.timeRes);         
167
168          arg.timers = &amUl->reOrdTmr;
169          arg.max = KW_MAX_AM_TMR;
170          break;
171       }
172       case KW_EVT_AMUL_STA_PROH_TMR:
173       {
174          KwAmUl* amUl = &(((KwUlRbCb *)cb)->m.amUl);
175          /* kw005.201 Changed wait calculation ccpu00117634*/ 
176          KW_TMR_CALCUATE_WAIT(arg.wait,
177                               amUl->staProhTmrInt,
178                               gCb->genCfg.timeRes);                  
179
180          arg.timers = &amUl->staProhTmr;
181          arg.max = KW_MAX_AM_TMR;
182          break;
183       } 
184       case KW_EVT_AMDL_POLL_RETX_TMR:
185       {
186          KwAmDl* amDl = &(((KwDlRbCb *)cb)->m.amDl);
187          /* kw005.201 Changed wait calculation ccpu00117634*/ 
188          KW_TMR_CALCUATE_WAIT(arg.wait, 
189                               amDl->pollRetxTmrInt, 
190                               gCb->genCfg.timeRes);                  
191
192          arg.timers = &amDl->pollRetxTmr;
193          arg.max = KW_MAX_AM_TMR;
194          break;
195       } 
196       case KW_EVT_WAIT_BNDCFM:
197       {
198          KwRguSapCb* rguSap = (KwRguSapCb *)cb;
199          /* kw005.201 Changed wait calculation ccpu00117634*/ 
200          KW_TMR_CALCUATE_WAIT(arg.wait, rguSap->bndTmrInt, gCb->genCfg.timeRes);                  
201
202          arg.timers = &rguSap->bndTmr;
203          arg.max = KW_MAX_RGUSAP_TMR;
204          break;
205       }
206 /* kw005.201 added support for L2 Measurement */
207 #ifdef LTE_L2_MEAS
208       case KW_EVT_L2_TMR:
209       {
210          measEvtCb = (KwL2MeasEvtCb *)cb;
211          /* kw005.201 Changed wait calculation ccpu00117634*/ 
212          KW_TMR_CALCUATE_WAIT(arg.wait, 
213                               measEvtCb->l2TmrCfg.val, 
214                               gCb->genCfg.timeRes);                  
215
216          arg.timers = &measEvtCb->l2Tmr;
217          arg.max = KW_L2_MAX_TIMERS;
218          break;
219       }
220 #endif
221       default:
222       {
223          RLOG0(L_ERROR, "Invalid tmr Evnt");
224       }
225    } 
226
227    if(arg.wait != 0)
228    {
229       arg.tqCp   = &gCb->kwTqCp;
230       arg.tq     = gCb->kwTq;
231       arg.cb     = cb;
232       arg.evnt   = tmrEvnt;
233       arg.tNum   = 0;
234
235       cmPlcCbTq(&arg);
236    }
237
238    RETVOID;
239 }
240
241 /**
242  * @brief Handler to stop a timer
243  *       
244  * @param[in] gCb       Pointer to the RLC instance control block
245  * @param[in] cb        Control block depending on the type of the timer event. 
246  *                      It can be uplink/downlink rbCb or rgu sap control block
247  * @param[in] tmrType   Timer event to be started
248  *
249  * @return  Void
250 */
251 #ifdef ANSI
252 PUBLIC Void kwStopTmr
253 (
254 KwCb   *gCb,
255 PTR    cb,
256 U8     tmrType
257 )
258 #else
259 PUBLIC Void kwStopTmr (gCb, cb, tmrType)
260 KwCb   *gCb;
261 PTR    cb; 
262 U8     tmrType;
263 #endif
264 {
265    CmTmrArg   arg;
266 /* kw005.201 added support for L2 Measurement */
267 #ifdef LTE_L2_MEAS
268    KwL2MeasEvtCb *measEvtCb = NULLP;
269 #endif
270    TRC2(kwStopTmr)
271
272    arg.timers = NULLP;
273
274    switch (tmrType)
275    {
276       case KW_EVT_UMUL_REORD_TMR:
277       {
278          arg.timers  = &((KwUlRbCb *)cb)->m.umUl.reOrdTmr;
279          arg.max = KW_MAX_UM_TMR;
280          break;
281       }
282       case KW_EVT_AMUL_REORD_TMR:
283       {
284          arg.timers = &((KwUlRbCb *)cb)->m.amUl.reOrdTmr;
285          arg.max = KW_MAX_AM_TMR;
286          break;
287       }
288       case KW_EVT_AMUL_STA_PROH_TMR:
289       {
290          arg.timers = &((KwUlRbCb *)cb)->m.amUl.staProhTmr;
291          arg.max = KW_MAX_AM_TMR;
292          break;
293       } 
294       case KW_EVT_AMDL_POLL_RETX_TMR:
295       {
296          arg.timers = &((KwDlRbCb *)cb)->m.amDl.pollRetxTmr;
297          arg.max = KW_MAX_AM_TMR;
298          break;
299       } 
300       case KW_EVT_WAIT_BNDCFM:
301       {
302          arg.timers = &((KwRguSapCb *)cb)->bndTmr;
303          arg.max = KW_MAX_RGUSAP_TMR;
304          break;
305       }
306 /* kw005.201 added support for L2 Measurement */
307 #ifdef LTE_L2_MEAS
308       case KW_EVT_L2_TMR:
309       {
310          measEvtCb = (KwL2MeasEvtCb *)cb;
311          arg.timers   = &measEvtCb->l2Tmr;
312          arg.max  = KW_L2_MAX_TIMERS;
313          break;
314       }
315 #endif
316       default:
317       {
318          RLOG0(L_ERROR, "Invalid tmr Evnt");
319       }
320    } 
321    if (tmrType != TMR0)
322    {
323       arg.tqCp   = &gCb->kwTqCp;
324       arg.tq     = gCb->kwTq;
325       arg.cb     = cb;
326       arg.evnt   = tmrType;
327       arg.wait   = 0;
328       arg.tNum   = 0;
329       cmRmvCbTq(&arg);
330    }
331    
332    RETVOID;
333 }
334
335 /**
336  * @brief Handler to invoke events on expiry of timer.
337  *
338  * @details
339  *    This function is used to handle expiry of timer,it invokes relevant 
340  *    functions.
341  *       
342  * @param[in] cb        Control block depending on the type of the timer event. 
343  *                      It can be uplink/downlink rbCb or rgu sap control block
344  * @param[in] tmrEvnt   Timer event to be started
345  *
346  * @return  Void
347 */
348 #ifdef ANSI
349 PUBLIC Void kwTmrExpiry
350 (
351 PTR   cb,
352 S16   tmrEvnt 
353 )
354 #else
355 PUBLIC Void kwTmrExpiry (cb, tmrEvnt)
356 PTR   cb;
357 S16   tmrEvnt;
358 #endif
359 {
360 /* kw005.201 added support for L2 Measurement */
361    TRC2(kwTmrExpiry)
362
363    switch (tmrEvnt)
364    {
365       case KW_EVT_UMUL_REORD_TMR:
366       {
367          KwUlRbCb *ulRbCb = (KwUlRbCb *)cb;
368          kwUmmReOrdTmrExp(KW_GET_KWCB(ulRbCb->inst), ulRbCb);
369
370          break;
371       }
372       case KW_EVT_AMUL_REORD_TMR:
373       {
374          KwUlRbCb *ulRbCb = (KwUlRbCb *)cb;
375          kwAmmReOrdTmrExp(KW_GET_KWCB(ulRbCb->inst), ulRbCb);
376          break;
377       }
378       case KW_EVT_AMUL_STA_PROH_TMR:
379       {
380          KwUlRbCb *ulRbCb = (KwUlRbCb *)cb;
381          kwAmmStaProTmrExp(KW_GET_KWCB(ulRbCb->inst), ulRbCb);
382
383          break;
384       }
385       case KW_EVT_AMDL_POLL_RETX_TMR:
386       {
387          KwDlRbCb *dlRbCb = (KwDlRbCb *)cb;
388          KwCb *gCb = KW_GET_KWCB(dlRbCb->inst);
389          
390          kwAmmPollRetxTmrExp(gCb, dlRbCb);
391
392          gCb->genSts.protTimeOut++;
393          break;
394       }
395       case KW_EVT_WAIT_BNDCFM:
396       {
397          kwBndTmrExpiry(cb);
398          break;
399       }
400       /* kw005.201 L2 Measurement support */
401       default:
402       {
403          break;
404       }
405    }
406
407    RETVOID;
408 }
409
410 /**
411  * @brief Handler to check if the timer is running
412  *       
413  * @param[in] gCb       Pointer to the RLC instance control block
414  * @param[in] cb        Control block depending on the type of the timer event. 
415  *                      It can be uplink/downlink rbCb or rgu sap control block
416  * @param[in] tmrEvnt   Timer event to be started
417  *
418  * @return  Bool indicating whether the timer is running or not
419  *      -# ROK 
420  *      -# RFAILED 
421 */
422 #ifdef ANSI
423 PUBLIC Bool kwChkTmr
424 (
425 KwCb   *gCb,
426 PTR    cb,
427 S16    tmrEvnt
428 )
429 #else
430 PUBLIC Bool kwChkTmr(gCb,cb, tmrEvnt)
431 KwCb   *gCb;
432 PTR    cb;
433 S16    tmrEvnt;
434 #endif
435 {
436    TRC2(kwChkTmr)
437
438    switch (tmrEvnt)
439    {
440       case KW_EVT_UMUL_REORD_TMR:
441       {
442          return (((KwUlRbCb *)cb)->m.umUl.reOrdTmr.tmrEvnt == 
443                   KW_EVT_UMUL_REORD_TMR);
444       }
445       case KW_EVT_AMUL_REORD_TMR:
446       {
447          return (((KwUlRbCb *)cb)->m.amUl.reOrdTmr.tmrEvnt == 
448                   KW_EVT_AMUL_REORD_TMR);
449       }
450       case KW_EVT_AMUL_STA_PROH_TMR:
451       {
452          return (((KwUlRbCb *)cb)->m.amUl.staProhTmr.tmrEvnt == 
453                   KW_EVT_AMUL_STA_PROH_TMR);
454       } 
455       case KW_EVT_AMDL_POLL_RETX_TMR:
456       {
457          return (((KwDlRbCb *)cb)->m.amDl.pollRetxTmr.tmrEvnt == 
458                   KW_EVT_AMDL_POLL_RETX_TMR);
459       } 
460       case KW_EVT_WAIT_BNDCFM:
461       {
462          return (((KwRguSapCb *)cb)->bndTmr.tmrEvnt == KW_EVT_WAIT_BNDCFM);
463       }
464       default:
465       {
466          RLOG0(L_ERROR, "Invalid tmr Evnt");
467       }
468    } 
469
470    RETVALUE(FALSE);
471 }
472
473 /**
474  * @brief Handler to do processing on expiry of the bind timer
475  *
476  * @details
477  *    This function processes the RLC bind timer expiry. If the number of 
478  *    retries is less than the maximum retry counter, bind request is sent 
479  *    again, else an alarm is raised to the layer manager.
480  *       
481  * @param[in] cb  Pointer to the Rgu sap
482  *
483  * @return  Void
484 */
485 #ifdef ANSI
486 PRIVATE Void kwBndTmrExpiry
487 (
488 PTR cb
489 )
490 #else
491 PRIVATE Void kwBndTmrExpiry(cb)
492 PTR cb;
493 #endif
494 {
495    KwRguSapCb *rguSapCb; 
496
497    TRC2(kwBndTmrExpiry)
498
499    rguSapCb = (KwRguSapCb *) cb;
500
501    if (rguSapCb->state == KW_SAP_BINDING)
502    {
503       if (rguSapCb->retryCnt < KW_MAX_SAP_BND_RETRY)
504       {
505          /* start timer to wait for bind confirm */
506          kwStartTmr(KW_GET_KWCB(rguSapCb->pst.srcInst),
507                     (PTR)rguSapCb, 
508                     KW_EVT_WAIT_BNDCFM);
509          
510          /* Send bind request */
511          rguSapCb->retryCnt++;
512          KwLiRguBndReq (&rguSapCb->pst, rguSapCb->suId, rguSapCb->spId);
513       }
514       else
515       {
516          rguSapCb->retryCnt = 0;
517          rguSapCb->state = KW_SAP_CFG;
518
519          /* Send alarm to the layer manager */
520 #ifdef LTE_L2_MEAS
521          kwLmmSendAlarm(KW_GET_KWCB(rguSapCb->pst.srcInst),
522                         LCM_CATEGORY_INTERFACE, 
523                         LCM_EVENT_BND_FAIL,
524                         LCM_CAUSE_TMR_EXPIRED, 
525                         0, 
526                         0, 
527                         0);
528 #else
529          kwLmmSendAlarm(KW_GET_KWCB(rguSapCb->pst.srcInst),
530                         LCM_CATEGORY_INTERFACE, 
531                         LCM_EVENT_BND_FAIL,
532                         LCM_CAUSE_TMR_EXPIRED, 
533                         0, /* suId */
534                         0 /* ueId */);
535 #endif
536       }
537    }
538
539    RETVOID;
540 }
541
542
543 \f  
544 /********************************************************************30**
545   
546          End of file
547 **********************************************************************/