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