[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-422]F1AP Paging Message Handling at DUAPP
[o-du/l2.git] / src / 5gnrrlc / rlc_utils.h
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   
21         Name:     NR RLC file
22
23         Type:     C include file
24   
25         Desc:     This file contain the hash definations for RLC 
26  
27         File:     kw.h
28   
29 **********************************************************************/
30 /** @file rlc_utils.h
31 @brief RLC Hash definitions
32 */
33
34 #ifndef __RLC_UTILS_H__
35 #define __RLC_UTILS_H__
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
40
41 #include "du_log.h"
42 #include "du_app_rlc_inf.h"
43 \f 
44
45 #define EKWxxx 1
46 #define EMG099 1
47 #define EMG102 2
48 #define EMG103 3
49 #define EMG104 4
50
51 /* RLC-SPLIT Activity */
52 #define RLC_ONE       1
53 #define RLC_BIT0      0x01
54 #define RLC_BIT1      0x02
55 #define RLC_BIT2      0x04
56 #define RLC_BIT3      0x08
57
58 #define RLC_2K_BYTE   2048
59
60 /* RLC RB flag bits */
61 #define RLC_RB_REESTABLISH_DL  RLC_BIT0
62 #define RLC_RB_REESTABLISH_UL  RLC_BIT1
63 #define RLC_RB_DELETE_DL       RLC_BIT2
64 #define RLC_RB_DELETE_UL       RLC_BIT3
65
66
67 #define RLC_MOD_1024           0x3FF  /* used for MOD 1024 */
68
69
70 \f 
71 /************************************************************************
72  *                            SAP States
73  ************************************************************************/
74
75 #define RLC_SAP_NOT_CFG        0     /*!< SAP Not Configured */
76 #define RLC_SAP_CFG            1     /*!< SAP Configured but not not bound */
77 #define RLC_SAP_BND            2     /*!< SAP Bound */
78 #define RLC_SAP_BINDING        3     /*!< SAP Bind initiated */
79 #define RLC_SAP_UBND           4     /*!< SAP Unbind */
80
81 #define RLC_MAX_SAP_BND_RETRY  3     /*!< Maximum SAP Bin Retries */
82
83 #define RLC_MAX_UE             0xffffffff  /*!< Maximum number of UEs. */
84
85 /* Maximum number of Saps */
86 #define RLC_MAX_UDXSAPS        1     /*!< Maximum number of UDX Saps */
87 #define RLC_MAX_KWUSAPS        2     /*!< Maximum number of KWU Saps. */
88 #define RLC_MAX_CKWSAPS        1     /*!< Maximum number of CKW Saps. */
89 /*MCELL changes*/
90 #define RLC_MAX_RGUSAPS        4//5     /*!< Maximum number of RGU Saps. */
91
92 #define RLC_MAX_RGUSAP_TMR     1     /*!< Maximum number of RGU SAP Timers. */
93
94 #define RLC_UI_RRC             0     /*!< Upper interface RRC sap Id. */
95 #define RLC_UI_PDCP            1     /*!< Upper interface PDCP sap Id. */
96
97 #ifdef LTE_L2_MEAS
98 /* TODO. This works for FDD only. For TDD the array dimension
99  * should be changed according to the number of Harq Procs */
100 #define RLC_MAX_TB_PER_UE      64    /*!< Maximum number of tbCb for UE */
101 #define RLC_INVALID_TBID       RLC_MAX_TB_PER_UE
102 #endif
103 /*******************************************************************************
104  *                              Memory related Defines 
105  ******************************************************************************/
106 /* Allocate function */
107 #ifdef ODU_MEMORY_DEBUG_LOG
108 #define RLC_MEM_LOG(_macro, _file, _line, _func, _size, _datPtr)\
109 {\
110    printf("\n%s=== %s +%d, %s, %d, %p\n",           \
111          _macro, _file, _line, _func, _size, _datPtr); \
112 }
113 #else
114 #define RLC_MEM_LOG(_macro, _file, _line, _func, _size, _dataPtr) {}
115 #endif
116
117 #define RLC_ALLOC(_cb,_buf, _size)                                    \
118 {                                                                    \
119  if (SGetSBuf(_cb->init.region, _cb->init.pool, (Data **)&_buf,      \
120                 (Size) _size) == ROK)                                \
121    {                                                                 \
122       RLC_MEM_LOG("RLC_ALLOC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
123       memset((_buf), 0, _size);                              \
124    }                                                                 \
125    else                                                              \
126    {                                                                 \
127       (_buf) = NULLP;                                                \
128    }                                                                 \
129 }
130
131 #define RLC_FREE(_cb,_buf, _size)                          \
132 {                                                         \
133    if (_buf != NULLP)                                     \
134    {                                                      \
135       RLC_MEM_LOG("RLC_FREE", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
136       (Void) SPutSBuf(_cb->init.region, _cb->init.pool,   \
137             (Data *) _buf, (Size) _size);                 \
138       _buf = NULLP;                                       \
139    }                                                      \
140 }
141
142 #define RLC_FREE_SHRABL_BUF(_region, _pool,_buf, _size)    \
143 {                                                         \
144    if (_buf != NULLP)                                     \
145    { \
146       RLC_MEM_LOG("RLC_FREE_SHRABL_BUF", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
147       (Void) SPutStaticBuffer(_region, _pool,             \
148             (Data *) _buf, (Size) _size, 0);                 \
149       _buf = NULLP;                                       \
150    }                                                      \
151 }
152
153 #define RLC_FREE_SHRABL_BUF_WC(_region, _pool,_buf, _size) \
154 {                                                         \
155  if (_buf != NULLP){\
156       RLC_MEM_LOG("RLC_FREE_SHRABL_BUF_WC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
157   (Void) SPutStaticBuffer(_region, _pool,                 \
158         (Data *) _buf, (Size) _size, 0);                 \
159   _buf = NULLP;      \
160   }\
161 }
162
163 #define RLC_ALLOC_SHRABL_BUF_WC(_region, _pool,_buf, _size)           \
164 {                                                                    \
165    if(SGetStaticBuffer(_region, _pool, (Data **)&_buf,                    \
166             (Size) _size, 0)==ROK)                                    \
167    {\
168       RLC_MEM_LOG("RLC_ALLOC_SHRABL_BUF_WC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
169    }\
170    else\
171    {\
172       (_buf) = NULLP;\
173    }\
174 }
175
176 #define RLC_ALLOC_SHRABL_BUF(_region, _pool,_buf, _size)              \
177 {                                                                    \
178  if (SGetStaticBuffer(_region, _pool, (Data **)&_buf,                \
179                 (Size) _size, 0) == ROK)                                \
180    {                                                                 \
181       RLC_MEM_LOG("RLC_ALLOC_SHRABL_BUF", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
182       memset((_buf), 0, _size);                              \
183    }                                                                 \
184    else                                                              \
185    {                                                                 \
186       (_buf) = NULLP;                                                \
187    }                                                                 \
188 }
189
190 #define RLC_ALLOC_WC(_cb,_buf, _size)  \
191 {\
192    if(SGetSBuf(_cb->init.region, _cb->init.pool, (Data **)&_buf, (Size) _size) == ROK)\
193    {\
194       RLC_MEM_LOG("RLC_ALLOC_WC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
195    }\
196 }
197
198 #define RLC_REMOVE_SDU(_cb,_sduQ,_sdu)              \
199 {                                               \
200    if(_sdu->mBuf)                               \
201    {                                            \
202       RLC_MEM_LOG("RLC_REMOVE_SDU", __FILE__, __LINE__, __FUNCTION__, _sdu->sduSz, _sdu->mBuf);\
203       ODU_PUT_MSG_BUF(_sdu->mBuf);    \
204    }                                            \
205    cmLListDelFrm(_sduQ,&_sdu->lstEnt);          \
206    RLC_FREE(_cb,_sdu, sizeof(RlcSdu));            \
207 }
208
209 /* kw002.201 Freeing from region of pst */
210 #define RLC_PST_FREE(_region, _pool, _buf, _size)          \
211 {                                                         \
212    if (_buf != NULLP)                                     \
213    {                                                      \
214       RLC_MEM_LOG("RLC_PST_FREE", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
215       (Void) SPutSBuf(_region, _pool,                     \
216                       (Data *) _buf, (Size) _size);       \
217       _buf = NULLP;                                       \
218    }                                                      \
219 }
220
221 #ifdef XEON_SPECIFIC_CHANGES
222 #ifdef SS_LOCKLESS_MEMORY
223 #define RLC_SHRABL_STATIC_BUF_FREE(_region, _pool, _buf, _size)     \
224 {                                                                  \
225    if (_buf != NULLP)                                              \
226    {                                                               \
227       (Void) SPutStaticBuffer(_region, _pool,                      \
228                       (Data *) _buf, (Size) _size, 0);             \
229       _buf = NULLP;                                                \
230    }                                                               \
231 }
232
233 #define RLC_SHRABL_STATIC_BUF_ALLOC(_region, _pool, _buf, _size)     \
234 {                                                                        \
235  SGetStaticBuffer(_region, _pool, (Data **)&_buf,      \
236                 (Size) _size, 0);                                        \
237 }
238
239 #else
240
241 #define RLC_SHRABL_STATIC_BUF_FREE(_region, _pool, _buf, _size)     \
242 {                                                                  \
243    if (_buf != NULLP)                                              \
244    {                                                               \
245       (Void) SPutSBuf(_region, _pool,                      \
246                       (Data *) _buf, (Size) _size);             \
247       _buf = NULLP;                                                \
248    }                                                               \
249 }
250
251 #define RLC_SHRABL_STATIC_BUF_ALLOC(_region, _pool, _buf, _size)     \
252 {                                                                        \
253  SGetSBuf(_region, _pool, (Data **)&_buf,      \
254                 (Size) _size);                                        \
255 }
256 #endif /* SS_LOCKLESS_MEMORY */
257
258 #else 
259
260 #define RLC_SHRABL_STATIC_BUF_FREE(_region, _pool, _buf, _size)     \
261 {                                                                  \
262    if (_buf != NULLP)                                              \
263    {                                                               \
264       RLC_MEM_LOG("RLC_SHRABL_STATIC_BUF_FREE", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
265       (Void) SPutStaticBuffer(_region, _pool,                      \
266             (Data *) _buf, (Size) _size, 0);             \
267       _buf = NULLP;                                                \
268    }                                                               \
269 }
270
271 #define RLC_SHRABL_STATIC_BUF_ALLOC(_region, _pool, _buf, _size)     \
272 {                                                                        \
273    SGetStaticBuffer(_region, _pool, (Data **)&_buf,      \
274          (Size) _size, 0);                                        \
275    RLC_MEM_LOG("RLC_SHRABL_STATIC_BUF_ALLOC", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
276 }
277 #endif
278
279 #define RLC_MEM_CPY(_dst, _src, _size)  memcpy(_dst, _src, _size); 
280
281 #define RLC_MEM_ZERO(_buf, _size) memset((_buf), 0, _size);
282
283 #define RLC_GET_MEM_REGION(_cb) (_cb->init.region)
284
285 #define RLC_GET_MEM_POOL(_cb) (_cb->init.pool)
286
287 #define RLC_GET_MEM_POOL_ADDRESS(_cb) (&_cb->init.pool)
288
289 /* Memset to value */
290 #define RLC_MEM_SET(_arg, _val, _size) memset(_arg, _val, _size); 
291
292 /* Alarms */
293 /* Send an alarm for sapId events */
294 /* kw005.201 added support for L2 Measurement */
295 #ifdef LTE_L2_MEAS
296 #define RLC_GETSDUIDX(_sduIdx) \
297 {\
298    _sduIdx = (((_sduIdx)+1) % RLC_L2MEAS_MAX_OUTSTNGSDU);\
299 }
300 #define RLC_SEND_SAPID_ALARM(_cb,_sapId, _evnt, _cause) \
301 { \
302    rlcLmmSendAlarm(_cb,LCM_CATEGORY_INTERFACE, _evnt, _cause, _sapId, 0, 0); \
303 }
304 #define RLC_SEND_UEID_ALARM(_cb,_ueId, _qci, _evnt, _cause) \
305 { \
306    rlcLmmSendAlarm(_cb,LCM_CATEGORY_INTERFACE, _evnt, _cause, 0, _ueId, _qci); \
307 }
308 #else /* LTE_L2_MEAS */
309 #define RLC_SEND_SAPID_ALARM(_cb,_sapId, _evnt, _cause) \
310 { \
311    rlcLmmSendAlarm(_cb,LCM_CATEGORY_INTERFACE, _evnt, _cause, _sapId, 0); \
312 }
313 #define RLC_SEND_UEID_ALARM(_cb,_ueId, _evnt, _cause) \
314 { \
315    rlcLmmSendAlarm(_cb,LCM_CATEGORY_INTERFACE, _evnt, _cause, 0, _ueId); \
316 }
317 #endif /* LTE_L2_MEAS */
318
319 /*******************************************************************************
320  *                              Common Defines 
321  ******************************************************************************/
322
323 /* RLC Configuration parameters */
324 #define RLC_MAX_UL_LI                (2 * RLC_MAX_LI)
325 /*macro RLC_MAX_DL_LI is moved to rlc_env.h file */
326 #define RLC_MAX_DAT                  RLC_MAXIMUM_DAT
327 /*macro RLC_MAX_PDU is moved to rlc_env.h file */
328 #define RLC_MAX_RB_PER_CELL          10
329 #define RLC_MAX_SRB_PER_UE           3
330 #define RLC_MAX_DRB_PER_UE           32
331 #define RLC_MAX_LCH_PER_UE           12
332 #define RLC_MAX_LCH_PER_CELL         6
333 #define RLC_MAX_NUM_RB               24
334 #define RLC_MAX_UE                   0xffffffff 
335 #define RLC_UE_LIST_BUCKET_SIZE      128 
336 #define RLC_CELL_LIST_BUCKET_SIZE    10 
337 #define RLC_TRANS_ID_LST_BKT_SIZE    10 
338 #define RLC_MAX_RB                   32
339
340 /* RLC Mode defines */
341 #define RLC_MODE_TM 1
342 #define RLC_MODE_UM 2
343 #define RLC_MODE_AM 3
344
345 /* Direction defines */
346 #define RLC_DIR_UL        1     /*!< Unlink direction */
347 #define RLC_DIR_DL        2     /*!< Downlink direction */
348 #define RLC_DIR_BOTH      3     /*!< Both Downlink and Unlink */
349
350 #define RLC_DEF_SEQ_NUM 0 /**< Sequence number to pick in case of duplicate
351                               entries in hash list searches*/
352
353 /**
354  * @def RLC_MIN
355  *
356  *    Macro to find the miniumum of two numbers
357  *
358  * @param[in] x    First number
359  * @param[in] y    Second number
360  *
361 */
362 #define RLC_MIN(x,y) (x) < (y) ? (x) : (y)
363
364 /**
365  * @def RLC_GET_RLCCB
366  *
367  *    Macro to the RLC instance
368  *
369  * @param[in] _inst    Instance Id
370  *
371 */
372 #define RLC_GET_RLCCB(_inst) rlcCb[_inst]                              
373
374 #define RLC_ADD_SDU            1     /*!< Add SDU. */
375 #define RLC_DEL_SDU            2     /*!< Delete SDU. */
376
377 #define RLC_CFM_NOK            0     /*!< Do not send DatCfm */
378 #define RLC_CFM_OK             1     /*!< Send DatCfm */
379
380 /* Set the unsolictated Status flag */
381 #define RLC_SET_USTA_FLAG(_rlcCb, _value) \
382 { \
383    _rlcCb->init.usta = _value; \
384 }
385
386 /* Macros to get the init parameters */
387 #define RLC_GET_DBG_MASK(_rlcCb) (_rlcCb->init.dbgMask)
388 #define RLC_GET_LMPST_MEM_POOL(_rlcCb) (_rlcCb->init.lmPst.pool)
389 #define RLC_GET_LMPST_MEM_REGION(_rlcCb) (_rlcCb->init.lmPst.region)
390
391 /* Macros for configuration module */
392 #define RLC_CFG_FILL_CFG_CFM(_entCfm, _rbId, _rbType, _status, _reason)  \
393 {                                                              \
394    _entCfm->rbId  = _rbId;                                     \
395    _entCfm->rbType = _rbType;                                  \
396    _entCfm->status.status = _status;                           \
397    _entCfm->status.reason = _reason;                           \
398
399
400 /**
401  * @def RLC_VALIDATE_UE_RBID
402  *
403  *    This macro validates whether the _rbId passed is valid or not. It checks
404  *    if the _rbId is within the maximum value depending on the _rbType.
405  *    Returns TRUE if valid else FALSE
406  *
407  * @param[in] _rbType    Type of the Radio Bearer; SRB or DRB
408  * @param[in] _rbId      RB Id of the RB to be validated
409  *
410 */ 
411 #define RLC_VALIDATE_UE_RBID(_rbType, _rbId)                     \
412        ((_rbType == CM_LTE_SRB && _rbId < RLC_MAX_SRB_PER_UE) || \
413        (_rbType == CM_LTE_DRB && _rbId < RLC_MAX_DRB_PER_UE))
414
415 /*******************************************************************************
416  *                              UIM Defines 
417  ******************************************************************************/
418 #if (ERRCLASS & ERRCLS_INT_PAR)
419 #define RLC_VALDATE_SAP(_cb,_chkSpId, _sap, _ret)                             \
420 {                                                                            \
421    if (_chkSpId != _sap->spId)                                               \
422    {                                                                         \
423       RLCLOGERROR(_cb,ERRCLS_DEBUG, EKWxxx, (ErrVal) RFAILED,                 \
424             "Sap Id Validation Failed.");                                    \
425       _ret = RFAILED;                                                        \
426    }                                                                         \
427    /* SAP state validation */                                                \
428    if(_sap->state != RLC_SAP_BND)                                             \
429    {                                                                         \
430       RLCLOGERROR(_cb,ERRCLS_INT_PAR, EKWXXX, (ErrVal) RFAILED,               \
431             "Sap State Invalid.");                                           \
432       RLC_SEND_SAPID_ALARM(_cb,0, LCM_EVENT_UI_INV_EVT, LCM_CAUSE_INV_STATE); \
433       _ret = RFAILED;                                                        \
434    }                                                                         \
435 }
436 #else /* ERRCLASS & ERRCLS_INT_PAR */
437 #define RLC_VALDATE_SAP(_cb,_chkSpId, _sap, _ret)                             \
438 {                                                                            \
439    /* SAP state validation */                                                \
440    if(_sap->state != RLC_SAP_BND)                                             \
441    {                                                                         \
442       RLCLOGERROR(_cb,ERRCLS_INT_PAR, EKWXXX, (ErrVal) RFAILED,               \
443             "Sap State Invalid.");                                           \
444       RLC_SEND_SAPID_ALARM(_cb,0, LCM_EVENT_UI_INV_EVT, LCM_CAUSE_INV_STATE); \
445       _ret = RFAILED;                                                        \
446    }                                                                         \
447 }
448 #endif /* ERRCLASS & ERRCLS_INT_PAR */
449
450 /*******************************************************************************
451  *                              Timer Defines 
452  ******************************************************************************/
453 #define RLC_TMR_LEN                     10
454 #define RLC_MAX_UM_TMR                  1
455 #define RLC_MAX_AM_TMR                  3
456 #define RLC_MAX_THPT_TMR                1
457 #define RLC_MAX_UE_TMR                  1
458
459 /* Timer events */
460 #define EVENT_RLC_UMUL_REASSEMBLE_TMR     1
461 #define EVENT_RLC_AMUL_REASSEMBLE_TMR     2
462 #define EVENT_RLC_AMUL_STA_PROH_TMR       3
463 #define EVENT_RLC_AMDL_POLL_RETX_TMR      4
464 #define EVENT_RLC_WAIT_BNDCFM             5
465 /* kw005.201 added support for L2 Measurement */
466 #ifdef LTE_L2_MEAS
467 #define EVENT_RLC_L2_TMR                  6
468 #endif /* LTE_L2_MEAS */
469 #define EVENT_RLC_UE_THROUGHPUT_TMR       7
470 #define EVENT_RLC_UE_DELETE_TMR           8
471 #define EVENT_RLC_SNSSAI_THROUGHPUT_TMR   9
472
473 /* Wait time for RLC Timers */
474 #define RLC_UE_DELETE_WAIT_TIME           5 /*in milliseconds */
475
476 /*******************************************************************************
477  *                              DBM Defines 
478  ******************************************************************************/
479 /**
480  * @def RLC_DBM_GET_RBCB_FROM_UECB
481  *
482  *    This macro makes _rbCb point to the RB in _ueCb based on the passed 
483  *    _rbId and _rbType. _rbCb can point to NULLP
484  *
485  * @param[in] _rbId      RB Id of the RB to be fetched
486  * @param[in] _rbType    Type of the RB, SRB or DRB
487  * @param[in] _ueCb      Pointer to the UECb for which to get the RB
488  * @param[out] _rbCb     Pointer to the found RbCb
489  *
490 */
491 #define RLC_DBM_GET_RBCB_FROM_UECB(_rbId, _rbType, _ueCb, _rbCb)            \
492            (_rbCb) = ((_rbType) == CM_LTE_SRB) ? (_ueCb)->srbCb[(_rbId)] : \
493                                                  (_ueCb)->drbCb[(_rbId)];     
494 /**
495  * @def RLC_DBM_GET_CELL_RBCB
496  *
497  *    This macro makes _rbCb point to the RB in the _rbCbLst. 
498  *    _rbCb can point to NULLP
499  *
500  * @param[in] _rbId         RB Id of the RB to be fetched
501  * @param[in] _rbCbLst      Pointer to array of RBCbs
502  * @param[out] _rbCb        Pointer to the found RbCb
503  *
504 */
505 #define RLC_DBM_GET_CELL_RBCB(_rbId, _rbCbLst, _rbCb) \
506            (_rbCb) = (_rbCbLst)[(_rbId)]; 
507
508 /*******************************************************************************
509  *                              UMM Defines 
510  ******************************************************************************/
511 #define RLC_UMDL     rbCb->m.umDl 
512 #define RLC_UMUL     rbCb->m.umUl 
513
514 /* Sequence Number length defines */
515 #define RLC_UM_CFG_6BIT_SN_LEN      1 /**< UM 6-bit Sequence number length 
516                                           in bytes*/   
517 #define RLC_UM_CFG_12BIT_SN_LEN     2 /**< UM 12-bit Sequence number length 
518                                           in bytes*/
519 /* 5GNR */
520 /* Sequence Number length defines */
521 #define RLC_AM_CFG_12BIT_SN_LEN      1 /**< AM 12-bit Sequence number length 
522                                           in bytes*/   
523 #define RLC_AM_CFG_18BIT_SN_LEN      2 /**< AM 18-bit Sequence number length 
524                                           in bytes*/
525
526 /**
527  * @def RLC_REMOVE_MAC_HDR_SZ
528  *
529  *    If PDU size is greater than 127, MAC header would be 3 bytes else 2 bytes
530  *
531  * @param[in,out] _pduSz        Size of the pdu 
532  *
533 */
534 #define RLC_REMOVE_MAC_HDR_SZ(_pduSz) (_pduSz) -= ((_pduSz) > 127) ? 3 : 2;
535
536 /**
537  * @def RLC_UM_GET_VALUE
538  *
539  *    This macro is used to calculate the value of UM state variables used 
540  *    in comparisons.  VR(UH) - UM Window Size is taken as the base modulus.
541  *    Returns the modifed value
542  *
543  * @param[in] _val               Value of the state variable 
544  * @param[in] _kwUmUl        Um Uplink control block
545  *
546 */ 
547 #define RLC_UM_GET_VALUE(_val,_kwUmUl)  \
548      (((_val) - ((_kwUmUl).vrUh - (_kwUmUl).umWinSz)) & ((_kwUmUl).modBitMask))
549      
550 /*******************************************************************************
551  *                              AMM Defines 
552  ******************************************************************************/ 
553 #define RLC_AMDL                           rbCb->m.amDl 
554 #define RLC_AMUL                           rbCb->m.amUl
555
556 /* PDU Types */
557 #define RLC_DATA_PDU  1
558 #define RLC_CNTRL_PDU 0
559
560 #define RLC_FI_FIRST_SEG                0x02
561 #define RLC_FI_LAST_SEG                 0x01
562 #define RLC_SI_FIRST_SEG                0x01
563 #define RLC_SI_LAST_SEG                 0x02
564 #define RLC_SI_MID_SEG                  0x03
565
566 #define RLC_POLL_SET                    0x40 /* 01000000 */
567 #define RLC_POLL_UNSET                  0xbf /* 10111111 */
568 #define RLC_MAX_NACK_CNT                100
569 /*RLC_MAX_CNTRL_FIELDS (Maximum size of Status Pdu) 
570  *  = MAX_NACK_CNT * sizeof(NACK_SN,E1,E2,E3,soStart,soEnd, nackRange)
571  * for 18 bit SN + Fixed Header*/
572 #define RLC_MAX_CNTRL_FIELDS            ((RLC_MAX_NACK_CNT * 8) + 3)  
573
574 /* Each LI(Length Indicator) holds approx 1+1/2 byte and some other fields thus keeping Header Size equal to twice of MAX LI */
575 /* 5GNR_RLC: Need to change value of HDRSZ as per number of PDUs going in one datReq */
576 #define RLC_MIN_HDRSZ                         1
577 #define RLC_MAX_HDRSZ                         5 
578 #define RLC_AM_PDU_FIXED_HDRSZ                2
579 #define RLC_AM_PDU_12BIT_SN_HDRSZ             2
580 #define RLC_AM_PDU_18BIT_SN_HDRSZ             3
581 #define RLC_AM_SEG_12BIT_SN_WITH_SO_HDRSZ     4
582 #define RLC_AM_SEG_18BIT_SN_WITH_SO_HDRSZ     5
583 #define RLC_AM_SEG_12BIT_SN_WITHOUT_SO_HDRSZ  2
584 #define RLC_AM_SEG_18BIT_SN_WITHOUT_SO_HDRSZ  3
585 #define RLC_EXTN_HDRSZ                  2
586 #define RLC_CNTRL_PDU_FIXED_HDRSZ       3
587 #define RLC_MAC_HDR_SZ2                 2
588 #define RLC_MAC_HDR_SZ3                 3
589 #define RLC_BYTE_LEN                    8
590 #define RLC_2BYTE_LEN                   16
591 #define RLC_E1_LEN                      1
592 #define RLC_NACK_E1E2_LEN               12
593 #define RLC_SO_LEN                      15
594 #define RLC_DC_LEN                      1
595 #define RLC_CPT_LEN                     3
596 #define RLC_RF_LEN                      1
597 #define RLC_P_LEN                       1
598 #define RLC_FI_LEN                      2
599 #define RLC_SI_LEN                      2
600 #define RLC_E_LEN                       1
601 #define RLC_SN_LEN                      10
602 #define RLC_SN_LEN_12BITS               12
603 #define RLC_SN_LEN_18BITS               18
604 #define RLC_LSF_LEN                     1
605 #define RLC_LI_LEN                      11
606 #define RLC_STA_PDU_R_BITS_ACKSN_12BITS 7  /* 5GNR : Num Reserved bits in STATUS PDU */
607 #define RLC_STA_PDU_R_BITS_ACKSN_18BITS 1
608 #define RLC_STA_PDU_R_BITS_NACKSN_12BITS 1
609 #define RLC_STA_PDU_R_BITS_NACKSN_18BITS 3
610 #define RLC_NACK_RANGE_LEN               8
611 #define RLC_SO_LEN_5GNR                  16
612
613 #define RLC_DC_POS                      0x80
614 #define RLC_DC_SHT                      7      
615 #define RLC_POLL_POS                    0x40 /* 5GNR */
616 #define RLC_POLL_SHT                    6    /* 5GNR */
617 #define RLC_SI_POS                      0x30 /* 5GNR */
618 #define RLC_SI_SHT                      4    /* 5GNR */
619 #define RLC_SN_POS_12BIT                0x0F
620 #define RLC_SN_POS_18BIT                0x03
621 #define RLC_AM_GET_WIN_SZ(_snLen)       ((RLC_AM_CFG_12BIT_SN_LEN == (_snLen)) ? (2048) : (131072)) /* 5GNR */
622 #define RLC_RCV_BUF_BIN_SIZE 512   /* receive buffer size */
623 #define RLC_TX_BUF_BIN_SIZE 512   /* receive buffer size */
624
625 #define RLC_SDU_LST                     1
626 #define RLC_SEG_LST                     2
627 #define RLC_RETX_LST                    3
628 #define RLC_ALL_BYTES_MISSING           0xffff
629
630 #define RLC_MAX_PDU_MAP                 30       /*!< Maximum PDU Map. */
631
632 #define RLC_LLIST_FIRST_SDU(lstCp, nod)          \
633 {                                               \
634    CmLList *tmpNode;                            \
635    /*CM_LLIST_FIRST_NODE(&(lstCp), tmpNode);*/      \
636    /*if (tmpNode != NULLP)*/                        \
637    if((tmpNode=cmLListFirst(&lstCp)))            \
638       nod = (RlcSdu *)tmpNode->node;             \
639    else                                         \
640       nod = NULLP;                              \
641 }                                                          
642
643                                                            
644 #define RLC_LLIST_FIRST_SEG(lstCp, nod)         \
645 {                                              \
646    CmLList *tmpNode;                           \
647    /*CM_LLIST_FIRST_NODE(&(lstCp), tmpNode);*/     \
648    /*if (tmpNode != NULLP)*/                       \
649    if((tmpNode=cmLListFirst(&lstCp)))            \
650       nod = (RlcSeg *)tmpNode->node;            \
651    else                                        \
652       nod = NULLP;                             \
653 }                                                          
654
655 #define RLC_LLIST_FIRST_RETX(lstCp, nod)        \
656 {                                              \
657    CmLList *tmpNode;                           \
658    /*CM_LLIST_FIRST_NODE(&(lstCp), tmpNode);*/     \
659    /*if (tmpNode != NULLP)*/                       \
660    if((tmpNode=cmLListFirst(&lstCp)))            \
661       nod = (RlcRetx *)tmpNode->node;           \
662    else                                        \
663       nod = NULLP;                             \
664 }
665
666 #define RLC_LLIST_NEXT_SDU(lstCp, nod)          \
667 {                                              \
668    CmLList *tmpNode;                           \
669    /*CM_LLIST_NEXT_NODE(&(lstCp), tmpNode);*/      \
670    /*if (tmpNode != NULLP)  */                     \
671    if((tmpNode = cmLListNext(&lstCp)))          \
672       nod = (RlcSdu *)tmpNode->node;            \
673    else                                        \
674       nod = NULLP;                             \
675 }                                              
676
677
678 #define RLC_LLIST_NEXT_SEG(lstCp, nod)          \
679 {                                              \
680    CmLList *tmpNode;                           \
681    (lstCp).crnt = &((nod)->lstEnt);            \
682    /*CM_LLIST_NEXT_NODE(&(lstCp), tmpNode);*/      \
683    /*if (tmpNode != NULLP)*/                       \
684    if((tmpNode = cmLListNext(&lstCp)))           \
685       nod = (RlcSeg *)tmpNode->node;            \
686    else                                        \
687       nod = NULLP;                             \
688 }      
689
690                                         
691 #define RLC_LLIST_NEXT_RETX(lstCp, nod)         \
692 {                                              \
693    CmLList *tmpNode;                           \
694    /*CM_LLIST_NEXT_NODE(&(lstCp), tmpNode);*/      \
695    /*if (tmpNode != NULLP) */                      \
696    if ((tmpNode = cmLListNext(&lstCp)))          \
697       nod = (RlcRetx *)tmpNode->node;           \
698    else                                        \
699       nod = NULLP;                             \
700 }
701
702
703 #define RLC_LLIST_LAST_RETX(lstCp, nod)         \
704 {                                              \
705    CmLList *tempNode = NULLP;                  \
706    cmLListLast(&lstCp);                        \
707    tempNode = cmLListCrnt(&lstCp);             \
708    if (tempNode != NULLP)                      \
709       nod = (RlcRetx *)tempNode->node;          \
710    else                                        \
711       nod = NULLP;                             \
712 }
713
714 #define RLC_LLIST_LAST_SEG(lstCp, nod)          \
715 {                                              \
716    CmLList *tempNode = NULLP;                  \
717    cmLListLast(&lstCp);                        \
718    tempNode = cmLListCrnt(&lstCp);             \
719    if (tempNode != NULLP)                      \
720       nod = (RlcSeg *)tempNode->node;           \
721    else                                        \
722       nod = NULLP;                             \
723 }
724
725 #define RLC_LLIST_LAST_SDU(lstCp, nod)          \
726 {                                              \
727    CmLList *tempNode = NULLP;                  \
728    cmLListLast(&lstCp);                        \
729    tempNode = cmLListCrnt(&lstCp);             \
730    if (tempNode != NULLP)                      \
731       nod = (RlcSdu *)tempNode->node;           \
732    else                                        \
733       nod = NULLP;                             \
734 }
735
736 #define CM_LLIST_INS_AFT_CRNT(lstCp, nod)      \
737 {                                              \
738    CmLList *nodeToIns = &nod->lstEnt;\
739    nodeToIns->node = (PTR) nod;\
740    cmLListInsAfterCrnt(&lstCp, nodeToIns);     \
741 }
742
743 #define CM_LLIST_INS_BEF_CRNT(lstCp, nod)      \
744 {                                              \
745    CmLList *nodeToIns = &nod->lstEnt;          \
746    nodeToIns->node = (PTR) nod;                \
747    cmLListInsCrnt(&lstCp, nodeToIns);          \
748 }
749
750 #define RLC_LLIST_DEL_RECBUF(_recBuf)                      \
751 {                                                          \
752    RlcSeg  *_seg = NULLP;                                  \
753    RLC_LLIST_FIRST_SEG(_recBuf->segLst, _seg);             \
754    while (_seg)                                            \
755    {                                                       \
756       cmLListDelFrm(&_recBuf->segLst, &_seg->lstEnt);      \
757       RLC_FREE(_seg, sizeof(RlcSeg));                      \
758       RLC_LLIST_NEXT_SEG(_recBuf->segLst, _seg);           \
759    }                                                       \
760 }
761
762 #define RLC_UMM_LLIST_FIRST_SEG(lstCp, nod)         \
763 {                                              \
764    CmLList *tmpNode;                           \
765    if((tmpNode=cmLListFirst(&lstCp)))            \
766       nod = (RlcUmSeg *)tmpNode->node;            \
767    else                                        \
768       nod = NULLP;                             \
769 } /*!< um mode first segment of linked list*/
770
771 #define RLC_UMM_LLIST_NEXT_SEG(lstCp, nod)          \
772 {                                              \
773    CmLList *tmpNode;                           \
774    (lstCp).crnt = &((nod)->lstEnt);            \
775    if((tmpNode = cmLListNext(&lstCp)))           \
776       nod = (RlcUmSeg *)tmpNode->node;            \
777    else                                        \
778       nod = NULLP;                             \
779 }/*!< next segment in um mode linked list*/
780
781 #define MODAMT(x, y, z,_snModMask)   \
782 {                         \
783    y = (x - z) & _snModMask;   \
784 }                                                         
785
786 #define MODAMR(x, y, z , _snModMask)   \
787 {                         \
788    y = (x - z) & (_snModMask);   \
789 }
790
791 /**
792  * @def RLC_AM_IS_TRANS_WIN_STALLED
793  *
794  *    This macro is used to check if the AM transmit window is stalled or not.
795  *    The tramist window is stalled when the distance between txNext and txNextAck
796  *    is greater than equal to Window Size. Actually it should never be greater 
797  *    than Window Size.
798  *    Returns TRUE if the window is stalled else FALSE
799  *
800  * @param[in] _amDl     AM Downlink control block
801  *
802 */ 
803 #define RLC_AM_IS_TRANS_WIN_STALLED(_amDl)  \
804      ((((_amDl)->txNext - (_amDl)->txNextAck) & _amDl->snModMask) >= (RLC_AM_GET_WIN_SZ(_amDl->snLen)))
805
806 #ifdef TENB_STATS
807 #define RLC_AM_TRANS_WIN_SIZE(_amDl)  \
808      (((_amDl)->txNext - (_amDl)->txNextAck) & _amDl->snModMask)
809 #endif
810
811 #define RLC_AM_IS_POLL_BIT_SET(_amDl) \
812   (RLC_AMDL.pollSn == ((RLC_AMDL.txNext - 1) & RLC_AMDL.snModMask))
813
814 #define RLC_FILL_CNTRL_INFO(cntrlInfo, _val, _len, _idx, _eb)\
815 {                                                           \
816    cntrlInfo.val = _val;                                    \
817    cntrlInfo.len = _len;                                    \
818    cntrlInfo.idx = _idx;                                    \
819    cntrlInfo.emtBits = _eb;                                 \
820 }
821 #define RLC_FILL_PREV_IDX(cntrlInfo, _e1Idx, _e1eb, _idx, _eb) \
822 {                                                                     \
823   _e1Idx = cntrlInfo.e1Idx;                                           \
824   _e1eb  = cntrlInfo.e1eb;                                            \
825   _idx   = cntrlInfo.idx;                                             \
826   _eb    = cntrlInfo.emtBits;                                         \
827 }
828
829 #define RLC_FILL_HDR_ARGS(hdrInfo, _val, _len)  \
830 {                                              \
831    hdrInfo.val = _val;                         \
832    hdrInfo.len = _len;                         \
833 }
834
835 /* kw003.201 - This macro provides the header size other than the */
836 /*             fixed header of 2 bytes for each AMD PDU or 4 bytes*/
837 /*             for an AM PDU segment                              */
838 #define RLC_AM_EXTN_HDRSZ(_numLi, _eHdrSz)       \
839 {                                               \
840    if ((_numLi - 1) % 2)                        \
841    {                                            \
842       _eHdrSz = ((3 * (_numLi - 2)) >> 1) + 2;  \
843    }                                            \
844    else                                         \
845    {                                            \
846       _eHdrSz = (3 * (_numLi - 1)) >> 1;        \
847    }                                            \
848 }
849
850 /* Update poll bit in the buffer */
851 #define RLC_UPD_POLL_BIT(_gCb, _retx, _poll)                \
852 {                                                          \
853    uint8_t fHdr;                                                \
854                                                            \
855    if (_poll != _retx->amHdr.p)                            \
856    {                                                       \
857       /* Get the first byte of the buffer */               \
858       SRemPreMsg((Data *)&fHdr, _retx->seg);               \
859       if (_poll == TRUE)                                   \
860       {                                                    \
861          fHdr = fHdr | RLC_POLL_SET;                        \
862       }                                                    \
863       else                                                 \
864       {                                                    \
865          fHdr = fHdr & RLC_POLL_UNSET;                      \
866       }                                                    \
867       /* Concatenated updated hdr to the mBuf */           \
868       SAddPreMsg ((Data)fHdr, _retx->seg);                 \
869    }                                                       \
870    /* Update poll bit in the hdrInfo */                    \
871    _retx->amHdr.p = _poll;                                 \
872 }
873
874 #define RLC_AM_ELIMINATE_EXTN_HDR(_pduSz, _sduSz, _numLi)   \
875 {                                                          \
876    if ( (_pduSz > _sduSz) && (_sduSz < 2048) )             \
877    {                                                       \
878       _pduSz -= (_numLi % 2) ? 1 : 2;                      \
879    }                                                       \
880 }
881 /**
882  * @def RLC_AM_CHK_SN_WITHIN_RECV_WINDOW
883  *
884  *    This macro is used to check if a Sequence Number falls within the AM
885  *    reception window or not.
886  *    The condition is VR(R) <= SN < VR(MR), which are subtracting the base
887  *    modulus becomes 0 <= (SN - VR(R)) % SNLen < (VR(MR) - VR(R)) % SnLen
888  *    NOTE: Careful with the parantheses
889  *
890  *    Returns TRUE if within the window; FALSE otherwise
891  *
892  * @param[in] _sn       The sequence number to be checked
893  * @param[in] _amUl     AM Uplink control block
894  *
895 */
896 #define RLC_AM_CHK_SN_WITHIN_RECV_WINDOW(_sn, _amUl)          \
897   ((((_sn) - (_amUl->rxNext)) & (_amUl->snModMask)) < (((_amUl->vrMr) - (_amUl->rxNext)) & (_amUl->snModMask))) 
898
899 #define RLC_POWER(x, y)  x << (y-1); 
900
901 #ifndef L2_OPTMZ
902 #define rlcCpyMsg(_cb,x, y) \
903       (SAddMsgRef((x), RLC_GET_MEM_REGION(_cb), RLC_GET_MEM_POOL(_cb), (y)))
904 #else
905 /* L2 optimization for mUe/Tti: Removing dup buf*/
906 #define rlcCpyMsg(_cb,x, y) \
907       (SIncMsgRef((x), RLC_GET_MEM_REGION(_cb), RLC_GET_MEM_POOL(_cb), (y)))
908 #endif
909
910 //      printf("Copy Msg %x \n",x);
911
912 /*******************************************************************************
913  *                              Debugging Defines 
914  ******************************************************************************/
915 #define RLC_DBG_SUB_MASK   DBGMASK_MI             /**< Use for sub-mask */
916 #define RLC_DBGMASK_DETAIL (RLC_DBG_SUB_MASK << 0) /**< Parameters, It will give
917                                                       in depth info */
918 #define RLC_DBGMASK_BRIEF  (RLC_DBG_SUB_MASK << 1) /**< Info, It will give info at
919                                                     entry and exit places along
920                                                    with certain state changes */
921 #define RLC_DBGMASK_ERROR  (RLC_DBG_SUB_MASK << 2) /**< Error information */
922 #define RLC_DBGMASK_FATAL  (RLC_DBG_SUB_MASK << 3) /**< FATAL errors like memory
923                                                     resource failure etc., */
924
925 #define RLC_DBG_MDL_MASK (RLC_DBG_SUB_MASK << 4)
926
927 #define RLC_DBGMASK_TM         (RLC_DBG_MDL_MASK << 0)    /**< TM */
928 #define RLC_DBGMASK_UM         (RLC_DBG_MDL_MASK << 1)    /**< UM */
929 #define RLC_DBGMASK_AM         (RLC_DBG_MDL_MASK << 2)    /**< AM */
930 #define RLC_DBGMASK_DL         (RLC_DBG_MDL_MASK << 3)    /**< DL */
931 #define RLC_DBGMASK_UL         (RLC_DBG_MDL_MASK << 4)    /**< UL */
932 #define RLC_DBGMASK_CFG        (RLC_DBG_MDL_MASK << 5)    /**< CFG */
933 #define RLC_DBGMASK_LMM        (RLC_DBG_MDL_MASK << 6)    /**< LMM */
934 #define RLC_DBGMASK_INF        (RLC_DBG_MDL_MASK << 7)    /**< UI, LI */
935 #define RLC_DBGMASK_DUT        (RLC_DBG_MDL_MASK << 8)    /**< DBM, UTL, TMR */
936 #define RLC_DBGMASK_MBUF_PRNT  (RLC_DBG_MDL_MASK << 9)    /**< MBUF, useful in
937                                                              integrated 
938                                                              testing */
939 #define RLC_DBGMASK_MEM_INFO   (RLC_DBG_MDL_MASK << 10)   /**< Print SSI memory
940                                                              information*/
941 #define RLC_DBGMASK_UDX        (RLC_DBG_MDL_MASK << 11)   /**< UDX interface */
942
943 #ifdef DEBUGP
944 #define RLC_PRNT_BORDER                                   \
945 do                                                       \
946 {                                                        \
947    RLC_PRNT((_kwPBuf, "\n==========================\n")); \
948 }while(0)
949
950 #define RLC_PRNT_HLINE(_cb,_pMsg)                                              \
951 {                                                                             \
952    sprintf((_cb)->init.prntBuf, "[RLC_LAYER: %s:%d]::", __FILE__, __LINE__);  \
953    SPrint((_cb)->init.prntBuf);                                               \
954    RLC_PRNT_TSTAMP(_cb);                                                       \
955    sprintf((_cb)->init.prntBuf, _pMsg);                                       \
956    SPrint((_cb)->init.prntBuf);                                               \
957 }
958
959 #define RLC_PRNT(_cb,_prntbuf)  \
960 {                              \
961    sprintf _prntbuf;           \
962    SPrint(_cb->init.prntBuf);  \
963 }
964
965 #define RLC_PRINT_TO_BUFFER(_cb,...)                             \
966 {                                                               \
967    snprintf((_cb)->init.prntBuf, PRNTSZE, "[%s]::", __func__);  \
968    SPrint((_cb)->init.prntBuf);                                 \
969    snprintf(_cb->init.prntBuf, PRNTSZE,__VA_ARGS__);            \
970    SPrint(_cb->init.prntBuf);                                   \
971 }
972
973 #define RLC_PRNT_TSTAMP(_cb)                                   \
974 {                                                             \
975    S8 _buf[60];                                               \
976    DateTime dt;                                               \
977    memset((&dt), 0, sizeof(DateTime));                \
978    SGetDateTime(&dt);                                         \
979    sprintf(_buf, "date: %02d/%02d/%04d time: %02d:%02d:%02d", \
980      (int)dt.month,(int)dt.day,(int)dt.year + 1900,           \
981      (int)dt.hour,(int)dt.min,(int)dt.sec);                   \
982    RLC_PRNT(_cb,(_cb->init.prntBuf,("[%s]", _buf)));           \
983 }
984
985 #define RLC_PRNT_MBUF(_cb,_mBufPtr)                          \
986 do                                                          \
987 {                                                           \
988    if(_cb->init.dbgMask & (RLC_DBGMASK_MBUF_PRNT))           \
989    {                                                        \
990      RLC_PRNT_HLINE(_cb,("\nMessage Buffer Contents:\n"));   \
991      SPrntMsg ((Buffer *)_mBufPtr, 0, 0);                   \
992    }                                                        \
993 }while(0)
994
995 #define RLC_PRNT_MEMINFO(_cb)                                  \
996 do                                                            \
997 {                                                             \
998    uint32_t  _memInfo;                                             \
999    if(_cb->init.dbgMask & (RLC_DBGMASK_MEM_INFO))              \
1000    {                                                          \
1001      RLC_PRNT_HLINE(_cb,("\nMemory Information:\n"));          \
1002      SRegInfoShow(0, &_memInfo);                              \
1003    }                                                          \
1004 }while(0)
1005
1006 #define RLCDBGP_INTERNAL(_cb,_mask,...)           \
1007 do                                               \
1008 {                                                \
1009    if (!((_cb->init.dbgMask & _mask) ^ _mask))   \
1010    {                                             \
1011       RLC_PRINT_TO_BUFFER(_cb, __VA_ARGS__);      \
1012    }                                             \
1013 }while(0)
1014
1015 #define RLCDBGP_ERROR(_cb, ...) \
1016    RLCDBGP_INTERNAL(_cb,(RLC_DBGMASK_ERROR | RLC_MODULE),__VA_ARGS__)
1017
1018 #define RLCDBGP_DETAIL(_cb, ...) \
1019    RLCDBGP_INTERNAL(_cb,(RLC_DBGMASK_DETAIL | RLC_MODULE),__VA_ARGS__)
1020
1021 #define RLCDBGP_BRIEF(_cb, ...) \
1022    RLCDBGP_INTERNAL(_cb,(RLC_DBGMASK_BRIEF | RLC_MODULE),__VA_ARGS__)   
1023    
1024 #else  /* DEBUGP */ 
1025 #define RLC_PRNT_HLINE(_cb,_pMsg)
1026 #define RLC_PRNT(_cb,_prntbuf)
1027 #define RLC_PRNT_TSTAMP(_cb)
1028 #define RLC_PRNT_MBUF(_cb,_mBufPtr)
1029 #define RLC_PRNT_MEMINFO(_cb)
1030 #define RLCDBGP(_cb,_mask, _arg)
1031 #define RLCDBGP_ERROR(_cb, ...) 
1032 #define RLCDBGP_DETAIL(_cb, ...)
1033 #define RLCDBGP_BRIEF(_cb, ...)
1034 #endif /* DEBUGP */
1035
1036 /*******************************************************************************
1037  *                              LMM Defines 
1038  ******************************************************************************/
1039 #define RLC_LMM_RB_STS_INC(_cb)    (_cb)->genSts.numOfRb++;
1040
1041 #define RLC_LMM_RB_STS_DEC(_cb)    (_cb)->genSts.numOfRb--;
1042
1043 #if defined(SS_MULTICORE_SUPPORT) && defined(SS_M_PROTO_REGION)
1044 #define RLC_FILL_SAP_HELPER(_Sap, _cfg, _gCb)\
1045 {\
1046    _Sap->pst.selector = _cfg->selector; \
1047    _Sap->pst.route = _cfg->route; \
1048    _Sap->pst.prior =  _cfg->priority; \
1049    _Sap->pst.region = _gCb->init.region;\
1050    _Sap->pst.pool = _gCb->init.pool;\
1051    _Sap->pst.dstProcId = _cfg->procId; \
1052    _Sap->pst.dstEnt = _cfg->ent; \
1053    _Sap->pst.dstInst = _cfg->inst; \
1054    _Sap->pst.srcProcId = _gCb->init.procId; \
1055    _Sap->pst.srcEnt = _gCb->init.ent; \
1056    _Sap->pst.srcInst = _gCb->init.inst; \
1057    _Sap->pst.event = EVTNONE; \
1058    _Sap->spId = _cfg->sapId; \
1059    _Sap->state = RLC_SAP_CFG; \
1060 }
1061 #else /* defined(SS_MULTICORE_SUPPORT) && defined(SS_M_PROTO_REGION) */
1062 #define RLC_FILL_SAP_HELPER(_Sap, _cfg, _gCb)\
1063 {\
1064    _Sap->pst.selector = _cfg->selector; \
1065    _Sap->pst.route = _cfg->route; \
1066    _Sap->pst.prior =  _cfg->priority; \
1067    _Sap->pst.region = _cfg->mem.region;\
1068    _Sap->pst.pool = _cfg->mem.pool;\
1069    _Sap->pst.dstProcId = _cfg->procId;\
1070    _Sap->pst.dstEnt = _cfg->ent;\
1071    _Sap->pst.dstInst = _cfg->inst;\
1072    _Sap->pst.srcProcId = _gCb->init.procId;\
1073    _Sap->pst.srcEnt = _gCb->init.ent;\
1074    _Sap->pst.srcInst = _gCb->init.inst;\
1075    _Sap->pst.event = EVTNONE;\
1076    _Sap->spId = _cfg->sapId;\
1077    _Sap->state = RLC_SAP_CFG;\
1078 }
1079 #endif
1080
1081 /*******************************************************************************
1082  *                              UDX Defines 
1083  ******************************************************************************/
1084 #define RLC_GET_DL_SAPCB(_cb, _rbCb) (_cb->u.dlCb->udxDlSap + _rbCb->udxSapId)
1085 #define RLC_GET_UDX_SAP(_cb) (_cb->u.ulCb->udxUlSap)
1086
1087 /* kw005.201 added support for L2 Measurement */
1088 #ifdef LTE_L2_MEAS
1089 #define RLC_L2_MAX_TIMERS        1
1090 #define RLC_QCI_LIST_BUCKET_SIZE 10
1091 #define RLC_TB_LIST_BUCKET_SIZE  10
1092 #define RLC_MAX_L2MEAS_EVT       10
1093 /* L2 Measurement index to be used in rbCb to store measData */                                       
1094 #define RLC_L2MEAS_ACT_UE       0                                       
1095 #define RLC_L2MEAS_DL_DELAY     1                                       
1096 #define RLC_L2MEAS_DL_DISC      2
1097 #define RLC_L2MEAS_UU_LOSS      3
1098 #define RLC_L2MEAS_DL_IP        4
1099 #define RLC_L2MEAS_UL_IP        5
1100 #endif /* LTE_L2_MEAS */
1101
1102 #define RLC_RDWR_LOCK(_lockPtr)
1103 #define RLC_RDWR_UNLOCK(_lockPtr)
1104 #define RLC_TIME_DIFF(t1,t2)                  \
1105    (t1<t2 ? ((0xffffffff - t2) + t1 ): (t1 - t2)) 
1106
1107 /*******************************************************************/
1108
1109 /* Memory */
1110 #define RLC_MEM_REGION_UL    1
1111 #define RLC_MEM_REGION_DL    4
1112 #define RLC_POOL 1
1113
1114 /* Inst */
1115 #define RLC_UL_INST   0
1116 #define RLC_DL_INST   1
1117
1118 #define PDCP_SN 1
1119
1120 /* Fill Pst structure for sending msg from RLC to DUAPP */
1121 #define FILL_PST_RLC_TO_DUAPP(_pst, _srcInst, _event) \
1122 {                                                              \
1123    _pst.selector    = ODU_SELECTOR_LWLC;                       \
1124    _pst.srcEnt      = ENTRLC;                                  \
1125    _pst.dstEnt      = ENTDUAPP;                                \
1126    _pst.dstInst     = 0;                                       \
1127    _pst.srcInst     = _srcInst;                                \
1128    _pst.dstProcId   = ODU_GET_PROCID();                        \
1129    _pst.srcProcId   = ODU_GET_PROCID();                        \
1130    if(_srcInst == RLC_UL_INST)                                 \
1131    {                                                           \
1132       _pst.region   = RLC_MEM_REGION_UL;                       \
1133    }                                                           \
1134    else if(_srcInst == RLC_DL_INST)                            \
1135    {                                                           \
1136       _pst.region   = RLC_MEM_REGION_DL;                       \
1137    }                                                           \
1138    _pst.pool        = RLC_POOL;                                \
1139    _pst.event       = _event;                                  \
1140    _pst.route       = 0;                                       \
1141    _pst.prior       = 0;                                       \
1142    _pst.intfVer     = 0;                                       \
1143 }
1144
1145 #define FILL_PST_RLC_TO_MAC(_pst, _srcInst, _event)    \
1146 {                                                      \
1147    pst.selector  = ODU_SELECTOR_LWLC;                  \
1148    pst.srcEnt    = ENTRLC;                             \
1149    pst.dstEnt    = ENTMAC;                             \
1150    pst.dstInst   = 0;                                  \
1151    pst.srcInst   = _srcInst;                           \
1152    pst.dstProcId = ODU_GET_PROCID();                   \
1153    pst.srcProcId = ODU_GET_PROCID();                   \
1154    if(_srcInst == RLC_UL_INST)                         \
1155    {                                                   \
1156       pst.region    = RLC_MEM_REGION_UL;               \
1157    }                                                   \
1158    else if(_srcInst == RLC_DL_INST)                    \
1159    {                                                   \
1160       pst.region    = RLC_MEM_REGION_DL;               \
1161    }                                                   \
1162    pst.pool      = RLC_POOL;                           \
1163    pst.event     = _event;                             \
1164    pst.route     = 0;                                  \
1165    pst.prior     = 0;                                  \
1166    pst.intfVer   = 0;                                  \
1167 }
1168
1169 /** @brief global variables */
1170 uint16_t getTransId();
1171
1172 /** @brief Local typedefs */
1173 typedef uint32_t    RlcSn;   /*!< Sequence Number length */
1174
1175 typedef RguDDatIndInfo KwDatIndInfo;
1176
1177 typedef RguDStaIndInfo KwDStaIndInfo;
1178
1179 typedef RguPduInfo KwPduInfo; /* kw002.201 : Aligning the structure with RGU */
1180
1181 typedef struct _amRlcStats
1182 {
1183    uint32_t   numDLStaPduSent;
1184    uint32_t   numDLNacksInStaPdu;
1185    uint32_t   numDLBytesUnused;
1186    uint32_t   numDLPollTimerExpiresSrb;
1187    uint32_t   numDLPollTimerExpiresDrb;
1188    uint32_t   numDLMaxRetx;
1189    uint32_t   numDLRetransPdus;
1190    uint32_t   numULPdusDiscarded;
1191    uint32_t   numULReAsmblTimerExpires;
1192    uint32_t   numULStaPduRcvd;
1193    uint32_t   numULNackInStaPduRcvd;
1194    uint32_t   numRlcAmCellSduTx; /* Count of SDUs transmitted in DL for all UEs */
1195    uint32_t   numRlcAmCellSduBytesTx; /*Total number of bytes transmitted in DL for all Ues */
1196    uint32_t   numRlcAmCellRetxPdu; /*Count of PDUs retransmitted for all Ues */
1197    uint32_t   numRlcAmMaxRetx; /*Total number of Max-RLC retransmissions hit for all the Ues */
1198    uint32_t   numRlcAmCellDupPduRx; /*Count of Duplicate PDUs detected for a UE in UL for all Ues */
1199    uint32_t   numRlcAmCellDropOutWinRx; /*Count of PDUs dropped due to Out of Window reception for all Ues */
1200    uint32_t   numRlcAmCellSduRx; /* Count of SDUs received in UL for all UEs*/
1201    uint32_t   numRlcAmCellSduBytesRx;/*Total number of bytes received in UL for all Ues*/
1202    uint32_t   numRlcAmCellNackRx; /*Total number of UL PDUs nacked for all the Ues*/
1203    uint32_t   numRlcAmCellWinStall; /*Number of window stalls detected for all the Ues */
1204 }AMRLCStats;
1205
1206 typedef struct _umRlcStats
1207 {
1208    uint32_t   numDLBytesUnused;
1209    uint32_t   numDLMaxRetx;
1210    uint32_t   numULPdusDiscarded;
1211    uint32_t   numULReAsmblTimerExpires;
1212    uint32_t   numULPdusOutsideWindow;
1213 }UMRLCStats;
1214
1215 typedef struct _rlcStats
1216 {
1217    AMRLCStats   amRlcStats;
1218    UMRLCStats   umRlcStats;
1219 }RLCStats;
1220
1221 RLCStats gRlcStats;
1222
1223 /* kw005.201 added support for L2 Measurement */
1224 #ifdef LTE_L2_MEAS
1225 typedef struct rlcSduSnMap RlcSduSnMap;
1226 typedef RguLchMapInfo KwLchMapInfo;
1227 #endif /*  LTE_L2_MEAS */
1228
1229 /** @defgroup ummode UM Module Info 
1230 */
1231 /** 
1232  * @brief  Structure to hold an Unacknowledged Mode header
1233  *
1234  * @details
1235  *    - si    : Segmentation Info
1236  *    - sn    : Sequence number
1237  *    - so    : Segmentation offset
1238 */
1239 typedef struct rlcUmHdr
1240 {
1241    uint8_t     si;              /*!< Segmentation Info */
1242    RlcSn       sn;              /*!< Sequence number */
1243    uint16_t    so;              /*!< Segmentation offset */
1244 }RlcUmHdr;
1245
1246 /** 
1247  * @brief  Structure to hold an Acknowledged Mode header
1248  *
1249  * @details
1250  *    - dc    : Data/Control PDU
1251  *    - rf    : Resegmentation flag
1252  *    - p     : Poll bit
1253  *    - fi    : Framing Info
1254  *    - e     : Extension bit
1255  *    - lsf   : Last segment flat
1256  *    - sn    : Sequence number
1257  *    - so    : Segment offset
1258  *    - numLi : Number of length indicators in the following array (li)
1259  *    - li    : Length indicators
1260 */
1261 typedef struct rlcAmHdr
1262 {
1263    uint8_t     dc;              /*!< Data/Control PDU */
1264    uint8_t     p;               /*!< Poll bit */
1265    uint8_t     si;              /*!< Segmentation Info: 5GNR */ 
1266    RlcSn       sn;              /*!< Sequence number */
1267    uint32_t    so;              /*!< Segment offset */
1268 }RlcAmHdr;
1269
1270 /* structures used for encoding/decoding the headers */
1271 typedef struct rlcCntrlInfo
1272 {
1273    uint16_t  val;
1274    uint8_t   len;
1275    uint16_t  idx;
1276    uint8_t   emtBits;
1277    uint16_t  e1Idx;
1278    uint16_t  e2Idx;   
1279    uint8_t   e1eb;
1280 }RlcCntrlInfo;
1281
1282 typedef struct rlcHdrInfo
1283 {
1284    uint32_t  val;
1285    uint8_t   len;
1286    uint8_t   eb;
1287    uint8_t   *hdr;
1288    uint16_t  idx;
1289    uint8_t   pEb;
1290    uint8_t   pLen;
1291 }RlcHdrInfo;
1292
1293 typedef struct rlcExtHdr
1294 {
1295    uint32_t val;
1296    uint16_t len;
1297    uint8_t  hdr;
1298    uint8_t  pLen;
1299 }RlcExtHdr;
1300
1301 /** 
1302  * @brief  Structure to hold information about a Logical channel
1303  *
1304  * @details
1305  *    - lChId    : Logical channel Id
1306  *    - lChType  : Logical channel type 
1307 */ 
1308 typedef struct rlcLchInfo
1309 {
1310    CmLteLcId     lChId;     /*!< Logical channel Id */
1311    CmLteLcType   lChType;   /*!< Logical channel type */
1312 }RlcLchInfo;
1313
1314 /* kw005.201 added support for L2 Measurement */
1315 #ifdef LTE_L2_MEAS
1316
1317 /** @struct RlcL2Cntr
1318  * RLC L2 Counter  */
1319 typedef struct rlcL2Cntr
1320 {
1321    struct
1322    {
1323       uint32_t  numActvUe;        /*!< number of active Ue */
1324       uint32_t  sampOc;           /*!< Total number of sampling occasion */
1325    }actUe;
1326    struct
1327    {
1328       uint32_t  dLoss;            /*!< Total number of lost packets */  
1329       uint32_t  posPkts;          /*!< Total number of positively acknowlegded 
1330                                   packets */
1331    }uuLoss;
1332    struct                    /*!< For DL IP throughput */
1333    {
1334       uint32_t volSummation;      /*!< Sum of data in bytes */
1335       uint32_t timeSummation;     /*!< Sum of time difference in milli sec*/
1336    }dlIpThruput;
1337    struct                    /*!< For UL IP throughput */
1338    {
1339       uint32_t volSummation;      /*!< Sum of data in bytes */
1340       uint32_t timeSummation;     /*!< Sum of time difference in milli sec*/
1341    }ulIpThruput;
1342    /* Discard new changes starts */
1343    struct                    /*!< For UL IP throughput */
1344    {
1345       uint32_t discSdus;          /*!< Total RLC SDUs discarded */
1346       uint32_t totSdus;           /*!< Total RLC SDUs received */
1347    }dlDisc;
1348    struct                    /*!< For UL IP throughput */
1349    {
1350       uint64_t sduDelay;          /*!< Total SDUs delay */
1351       uint32_t numSdus;
1352    }dlPjSduDelay;
1353    uint32_t    totDrbsPerQci;     /*!< Total Count of DRB's for this QCI */
1354 }RlcL2Cntr;
1355
1356 struct rlcSduSnMap
1357 {
1358    CmLList     lstEnt;
1359    Bool        failMarked;
1360    Bool        fullySent;
1361    uint32_t    sduId;
1362    uint16_t    numSn;
1363    uint16_t    snList[RLC_MAX_PDU_MAP];
1364    uint16_t    harqAck;
1365    uint16_t    reqSent;
1366    uint16_t    rspRcvd;
1367 };
1368
1369 typedef struct rlcSnSduMap
1370 {
1371    uint16_t         sn;
1372    CmLteLcId        lChId;              /*!< Logical channel Id */
1373    uint16_t         numSdu;
1374 #ifdef LTE_RLC_R9
1375    Bool        isBurstSplitted;    /*!< true: burst for this LCH is splitted */
1376 #endif /* LTE_RLC_R9 */
1377    RlcSduSnMap  *sduList[RLC_MAX_DL_LI];
1378 }RlcSnSduMap;
1379
1380 typedef struct rlcTbSnMap
1381 {
1382    CmHashListEnt  hlTbEnt;
1383    uint32_t       tbId;
1384    uint16_t       prevNumSn;
1385    uint16_t       numSn;
1386    RlcSnSduMap    snSduMap[RGU_MAX_PDU * RGU_MAX_LC];
1387 }RlcTbSnMap;
1388
1389 typedef struct rlcL2MeasCbUeMeasInfo
1390 {
1391    CmLteRnti   ueId;                    /*!< UE ID (Used only for IP Throughput
1392                                              in UL/DL */
1393    CmLteCellId cellId;                  /*!< UE ID (Used only for IP Throughput
1394                                              in UL/DL */
1395    Bool        isValid;                 /*! < is this UE entry valid */
1396    uint8_t     numLcId;                 /*!< Holds the number of LCh for which Ul Ip
1397                                              measurement is ON */
1398    uint8_t     lcId[RLC_MAX_LCH_PER_UE]; /*!< Holds the list of LCh for which Ul ip
1399                                              measurement is ON */
1400    RlcL2Cntr    measData[LKW_MAX_QCI];
1401    uint16_t     numQci;                  /*!< number of valid qcI */
1402    uint8_t      qci[LKW_MAX_QCI];        /*!< list of valid qcI */
1403 }RlcL2MeasCbUeMeasInfo;
1404
1405 typedef struct rlcL2MeasCbIpThMeas
1406 {
1407    uint8_t                   numUes;
1408    uint8_t                   totNumQci;
1409    uint8_t                   totQci[LKW_MAX_QCI];
1410    RlcL2MeasCbUeMeasInfo ueInfoLst[LKW_MAX_UE]; /*Added for handling meas for multiple ues*/ 
1411 }RlcL2MeasCbIpThMeas;
1412
1413 typedef struct rlcL2MeasCbNonIpThMeas
1414 {
1415    uint16_t    numSamples;              /*!< Number of samples to take on numActUe */
1416    uint16_t    numQci;                  /*!< number of valid qcI */
1417    uint8_t     qci[LKW_MAX_QCI];        /*!< list of valid qcI */
1418    RlcL2Cntr   measData[LKW_MAX_QCI];   /*!< Measurement CB */
1419 }RlcL2MeasCbNonIpThMeas;
1420
1421 typedef union rlcL2MeasCbIpNonIpThMeasVal
1422 {
1423    RlcL2MeasCbIpThMeas    ipThMeas;
1424    RlcL2MeasCbNonIpThMeas nonIpThMeas;
1425 }RlcL2MeasCbIpNonIpThMeasVal;
1426
1427 /** @struct RlcL2MeasCb
1428  * RLC L2 Measurement CB */
1429 typedef struct rlcL2MeasCb
1430 {
1431    uint8_t        measType;        /*!< Bit-wise set measurement types */
1432    RlcL2MeasCbIpNonIpThMeasVal val;   /* Union of IP tpt or non-ip tpt */
1433 }RlcL2MeasCb;
1434
1435 /** @struct RlcL2MeasEvtCb
1436  * RLC L2 Measurement Evt CB */
1437 typedef struct rlcL2MeasEvtCb
1438 {
1439    uint32_t      transId;                /*!< TransId of Measurement Req */
1440    uint32_t      cbIdx;                  /*!< TransId of Measurement Req */
1441    CmTimer       l2Tmr; /* NOT USED */                 /*!< L2 Timer per request */
1442    TmrCfg        l2TmrCfg; /* NOT USED */               /*!< Time period of measurement */
1443    RlcL2MeasCb   measCb;                 /*!< Measurement CB */ 
1444    EpcTime       startTime; /* NOT USED */            /*!<  start time when meas starts*/ 
1445 }RlcL2MeasEvtCb;
1446
1447 /** @struct RlcL2MeasRbCb
1448  * RLC L2 Measurement Rb CB */
1449 typedef struct rlcL2MeasRbCb
1450 {
1451    uint8_t        measOn;                      /*!< Measurements that are running */ 
1452    RlcL2Cntr      *l2Sts[RLC_MAX_L2MEAS_EVT];  /*!< L2 Mesurement statistics */     
1453 }RlcL2MeasRbCb;
1454
1455 /** @struct RlcL2Cb
1456  * RLC L2  CB */
1457 typedef struct rlcL2Cb
1458 {
1459    uint16_t        rlcNumMeas;                   /*!< Number of measurements going on */
1460    RlcL2MeasEvtCb  rlcL2EvtCb[LKW_MAX_L2MEAS];  /*!< Pointers to Measurement Cb */
1461    uint8_t         measOn[LKW_MAX_QCI];          /*!< Measurement on */
1462    uint32_t        numActUe[LKW_MAX_QCI];       /*!< Measurement on */
1463 }RlcL2Cb;
1464
1465
1466 typedef enum _dlIpThrputState
1467 {
1468    KW_DL_IPTHRU_RESET = 0,
1469    KW_DL_IPTHRU_BURST_STARTED,
1470    KW_DL_IPTHRU_BURST_CONTINUE,
1471    KW_DL_IPTHRU_BURST_COMPLETED
1472 }DlIpThrputState;
1473
1474 /** 
1475 * @struct rlcL2MeasSduLst
1476 * Structure to hold parameters of 
1477 * burst sdus in DL for a RB */
1478 typedef struct rlcOutStngSduInfo
1479 {
1480    uint32_t  sduId;            /*!< SDU Id of sdu */
1481    MsgLen    sduLen;           /*!< Size of sdu */
1482    uint32_t  numTb;            /*!< Hold the number of TBs for this sdu in DL */
1483 }RlcOutStngSduInfo;
1484
1485 /** 
1486 * @struct rlcL2MeasDlIpTh
1487 * Structure to hold parameters for DL ip 
1488 * throughput for a RB */
1489 typedef struct rlcL2MeasDlIpTh
1490 {
1491    Bool               isBurstAct;            /*!< Set to TRUE when burst is active in DL */
1492    uint64_t           burstStartTime;        /*!< Holds the starting time of the burst */
1493    uint32_t           burstEndSduId;         /*!< Sdu ID when burst ends */
1494    uint8_t            lastSduIdx;            /*!< Holds the index of last outStanding sdu */
1495    RlcOutStngSduInfo  outStngSduArr[RLC_L2MEAS_MAX_OUTSTNGSDU];/*!< Hold the burst sdu information */
1496 }RlcL2MeasDlIpTh;
1497
1498 /** 
1499 * @struct rlcL2MeasIpThruput
1500 * Structure to hold parameters for UL/DL ip 
1501 * throughput for a RB */
1502 typedef struct rlcL2MeasIpThruput
1503 {
1504    uint32_t         dataVol;                 /*!< Holds volume of new data in bytes
1505                                               for UL IP throughput */
1506    uint32_t         ttiCnt;                  /*!< Holds ttiCnt received from MAC in UL */
1507    uint32_t         prevTtiCnt;        /*!< Holds previous ttiCnt received from MAC in UL */
1508    RlcL2MeasDlIpTh  dlIpTh;
1509 }RlcL2MeasIpThruput;
1510
1511 #endif /* LTE_L2_MEAS */
1512
1513 /** 
1514  * @brief  Structure to hold an UE key for the UE hast lists
1515  *
1516  * @details
1517  *    - ueId    : UE Id
1518  *    - cellId  : Cell Id 
1519 */
1520 typedef struct rlcUeKey
1521 {
1522    CmLteRnti     ueId;     /*!< UE Id */
1523    CmLteCellId   cellId;   /*!< Cell Id */
1524 }RlcUeKey;
1525
1526 /** 
1527  * @brief  Structure to hold an information about the CKW SAP
1528  *
1529  * @details
1530  *    - pst   : Service user post structure
1531  *    - spId  : Service provider Id
1532  *    - suId  : Service user Id
1533  *    - state : State of the SAP
1534  *    - sts   : SAP specific statistics 
1535 */
1536 typedef struct rlcCkwSapCb
1537 {
1538    Pst           pst;     /*!< Service user post structure */
1539    SpId          spId;    /*!< Service provider Id */
1540    SuId          suId;    /*!< Service user Id */
1541    uint8_t       state;   /*!< Sap Status */
1542    RlcCkwCntSts   sts;     /*!< Statistics */
1543 }RlcCkwSapCb;
1544
1545 /** 
1546  * @brief  Structure to hold an information about the KWU SAP
1547  *
1548  * @details
1549  *    - pst   : Service user post structure
1550  *    - spId  : Service provider Id
1551  *    - suId  : Service user Id
1552  *    - state : State of the SAP
1553  *    - sts   : SAP specific statistics 
1554 */
1555 typedef struct rlcKwuSapCb
1556 {
1557    Pst           pst;     /*!< Service user post structure */
1558    SpId          spId;    /*!< Service provider Id */
1559    SuId          suId;    /*!< Service user Id */
1560    uint8_t       state;   /*!< Sap Status */
1561    RlcKwuSapSts  sts;     /*!< Statistics */
1562 }RlcKwuSapCb;
1563
1564 /** 
1565  * @brief  Structure to hold an information about the RGU SAP
1566  *
1567  * @details
1568  *    - pst       : Service user post structure
1569  *    - spId      : Service provider Id
1570  *    - suId      : Service user Id
1571  *    - state     : State of the SAP
1572  *    - bndTmr    : Bind Timer
1573  *    - bndTmrInt : Timer Interval
1574  *    - retryCnt  : Bind Retry Count
1575 */
1576 typedef struct rlcRguSapCb
1577 {
1578    Pst       pst;         /*!< Service user post structure */
1579    SpId      spId;        /*!< Service provider Id */
1580    SuId      suId;        /*!< Service user Id */
1581    uint8_t   state;       /*!< Sap Status */
1582    CmTimer   bndTmr;      /*!< Bind Timer */
1583    uint16_t  bndTmrInt;   /*!< Timer Interval */
1584    uint8_t   retryCnt;    /*!< Bind Retry Count */
1585 }RlcRguSapCb;
1586
1587 /** 
1588  * @brief  Structure to hold an information about the UDX UL SAP
1589  *
1590  * @details
1591  *    - pst       : Service user post structure
1592  *    - spId      : Service provider Id
1593  *    - suId      : Service user Id
1594  *    - state     : State of the SAP
1595  *    - bndTmr    : Bind Timer
1596  *    - bndTmrInt : Timer Interval
1597  *    - retryCnt  : Bind Retry Count
1598 */
1599 typedef struct rlcUdxUlSapCb
1600 {
1601    Pst       pst;         /*!< Service user post structure */
1602    SpId      spId;        /*!< Service provider Id */
1603    SuId      suId;        /*!< Service user Id */
1604    uint8_t   state;       /*!< Sap Status */
1605    CmTimer   bndTmr;      /*!< Bind Timer */
1606    uint16_t  bndTmrInt;   /*!< Timer Interval */
1607    uint8_t   retryCnt;    /*!< Bind Retry Count */
1608 }RlcUdxUlSapCb;
1609
1610 /** 
1611  * @brief  Structure to hold an information about the UDX DL SAP
1612  *
1613  * @details
1614  *    - pst       : Service user post structure
1615  *    - spId      : Service provider Id
1616  *    - suId      : Service user Id
1617  *    - state     : State of the SAP
1618 */
1619 typedef struct rlcUdxDlSapCb
1620 {
1621    Pst     pst;     /*!< Service user post structure */
1622    SpId    spId;    /*!< Service provider Id */
1623    SuId    suId;    /*!< Service user Id */
1624    uint8_t state;   /*!< Sap Status */
1625 }RlcUdxDlSapCb;
1626
1627 /** 
1628  * @brief  Structure to hold info about memory to be freed
1629  *
1630  * @details
1631  *    - sduLst  : The SDU queues are appended to this queue, used 
1632  *                for the UM SDU queues
1633  *    - txLst   : Stores to be released AM Mode TX PDUs
1634  *    - reTxLst : Stores to be released AM Re TX PDU's
1635  *    - rbLst   : List of AM DL RBs to be freed 
1636 */
1637 typedef struct rlcDlDataToBeFreed
1638 {
1639    CmLListCp   sduLst;     /*!< Queue of SDU's to be freed  */
1640    CmLListCp   txLst;     /*!< Stores to be released TX PDUs */
1641    CmLListCp   reTxLst;   /*!< Stores to be released ReTX PDUs */
1642    CmLListCp   rbLst;     /*!< List of AM DL RBs to be freed */
1643 }RlcDlDataToBeFreed;
1644
1645 /** 
1646  * @brief  Structure to hold an information about DL RLC instance
1647  *
1648  * @details
1649  *    - numKwuSaps        : Number of RLC KWU Saps
1650  *    - numUdxSaps        : Number of RLC UDX Saps
1651  *    - rlcKwuDlSap          : Pointer to the array of KWU SAPS
1652  *    - udxDlSap          : Pointer to the array of UDX SAPS
1653  *    - rguDlSap          : RGU Sap Control Block
1654  *    - cellLstCp         : Hashlist of CellCb
1655  *    - ueLstCp           : Hashlist of UeCb 
1656  *    - toBeFreed         : Pointer to data to be freed
1657  *    - shutdownReveived  : Request for shutdown recevied or not
1658  *    - eventInQueue      : Event for cleanup exists in queue or not
1659  */
1660 typedef struct rlcDlCb
1661 {
1662    uint8_t             numKwuSaps;         /*!< Number of RLC Data Saps */
1663    uint8_t             numUdxSaps;         /*!< Number of RLC Data Saps */
1664    RlcKwuSapCb         *rlcKwuDlSap;          /*!< KWU Sap Control Block */
1665    RlcUdxDlSapCb       *udxDlSap;          /*!< UDX DL Sap Control Block */
1666    RlcRguSapCb         *rguDlSap;          /*!< RGU Sap Control Block */
1667    CmHashListCp        cellLstCp;          /*!< Hashlist of CellCb */
1668    CmHashListCp        ueLstCp;            /*!< Hashlist of UeCb */
1669    RlcDlDataToBeFreed  toBeFreed;          /*!< Pointer to data to be freed */        
1670    Pst                 selfPst;            /*!< Pst to post events to self */
1671    Buffer              *selfPstMBuf;       /*!< Buffer used for self post */
1672    Bool                shutdownReceived;   /*!< Request for shutdown recevied */
1673    Bool                eventInQueue;       /*!< Event exists in queue or not */
1674 #ifdef LTE_L2_MEAS
1675    RlcL2Cb              rlcL2Cb; /*!< Control Block for L2 Measurements in RLC */
1676 #endif /* LTE_L2_MEAS */
1677 }RlcDlCb;
1678
1679 /** 
1680  * @brief  Structure to hold an information about UL RLC instance
1681  *
1682  * @details
1683  *    - ckwSap       : CKW Sap Conrol Block
1684  *    - numKwuSaps   : Number of RLC KWU Saps
1685  *    - numUdxSaps   : Number of RLC UDX Saps
1686  *    - udxUlSap     : Pointer to the array of UDX SAPS 
1687  *    - rlcKwuUlSap     : Pointer to the array of KWU SAPS
1688  *    - rguUlSap     : RGU Sap Control Block
1689  *    - cellLstCp    : Hashlist of CellCb
1690  *    - ueLstCp      : Hashlist of UeCb 
1691  *    - transIdLstCp : Hashlist of cfg trans
1692  */
1693 typedef struct rlcUlCb
1694 {
1695    RlcCkwSapCb     ckwSap;         /*!< CKW Sap Conrol Block */ 
1696    uint8_t         numKwuSaps;     /*!< Number of RLC Data Saps */
1697    uint8_t         numUdxSaps;     /*!< Number of RLC Data Saps */
1698    RlcUdxUlSapCb   *udxUlSap;      /*!< UDX DL Sap Control Block */
1699    RlcKwuSapCb     *rlcKwuUlSap;      /*!< KWU Sap Control Block */
1700    RlcRguSapCb     *rguUlSap;      /*!< RGU Sap Control Block */
1701    CmHashListCp   cellLstCp;      /*!< Hashlist of CellCb */
1702    CmHashListCp   ueLstCp;        /*!< Hashlist of UeCb */
1703    CmHashListCp   transIdLstCp;   /*!< Hashlist of cfg trans */
1704    uint8_t        rlcUlUdxEventType;  /*!<Ue Create/ReConfig> */
1705 /* kw005.201 added support for L2 Measurement */
1706 #ifdef LTE_L2_MEAS
1707    RlcL2Cb        rlcL2Cb; /*!< Control Block for L2 Measurements in RLC */
1708 #endif /* LTE_L2_MEAS */
1709 }RlcUlCb;
1710
1711 typedef struct rlcThptPerUe
1712 {
1713    uint16_t ueId;
1714    uint64_t dataVol;
1715 }RlcThptPerUe;
1716
1717 typedef struct rlcTptPerSnssai
1718 {
1719    Snssai   *snssai;
1720    uint64_t dataVol;
1721    double   tpt;
1722 }RlcTptPerSnssai;
1723
1724
1725 typedef struct rlcSnssaiTputInfo
1726 {
1727    CmTimer       snssaiThptTmr;                   /* Throughput Timer */
1728    CmLListCp     *dlTputPerSnssaiList; 
1729    CmLListCp     *ulTputPerSnssaiList;
1730 }RlcSnssaiTputInfo;
1731
1732 typedef struct rlcUeTputInfo
1733 {
1734    CmTimer       ueThptTmr;                   /* Throughput Timer */
1735    uint8_t       numActvUe;                 /* Number of Active UEs */
1736    RlcThptPerUe  thptPerUe[MAX_NUM_UE];     /* Throughput calculated per UE */
1737 }RlcUeTputInfo;
1738 /**
1739  * @brief  Structure to hold information about throughput at  RLC
1740  * 
1741  */
1742 typedef struct rlcThpt
1743 {
1744    Inst               inst;                /* RLC instance */
1745    RlcUeTputInfo      ueTputInfo;
1746    RlcSnssaiTputInfo  snssaiTputInfo;
1747 }RlcThpt;
1748
1749 /** 
1750  * @brief  Structure to hold an information about a RLC instance
1751  *
1752  * @details
1753  *    - init    : Task Initialization Info
1754  *    - genCfg  : General Configuration
1755  *    - genSts  : General Statistics
1756  *    - trcLen  : Trace Length
1757  *    - trcMask : Trace Mask
1758  *    - rlcTq    : Timer queue
1759  *    - rlcTqCp  : Timer queue control point
1760  *    - u       : Union depending on whether the instance is UL or DL
1761  *      - ulCb  : UL instance Control Block
1762  *      - dlCb  : DL instance Control Block
1763  */
1764 typedef struct rlcCb
1765 {
1766    TskInit    init;               /*!< Task Initialization Info */
1767    RlcGenCfg   genCfg;             /*!< General Configuration Structure */
1768    RlcGenSts   genSts;             /*!< General Statistics */
1769    S16        trcLen;             /*!< Trace Length */
1770    uint8_t         trcMask;            /*!< Trace Mask */
1771    CmTqType   rlcTq[RLC_TMR_LEN];   /*!< Timer queue */
1772    CmTqCp     rlcTqCp;             /*!< Timer queue control point */
1773    union 
1774    {
1775       RlcUlCb   *ulCb;   /*!< Ul Control Block */
1776       RlcDlCb   *dlCb;   /*!< Dl Control Block */
1777    } u;
1778    uint8_t    dlSduId;   /*!< Downlink SDU ID */
1779    RlcThpt    rlcThpt;   /*!< Throughput at RLC*/
1780 }RlcCb;
1781
1782 RlcCb *rlcCb[MAX_RLC_INSTANCES];   /*!< RLC global control block */
1783
1784 CmLListCp *arrTputPerSnssai[DIR_BOTH]; /*Stores the address of Througput LL*/
1785 /****************************************************************************
1786  *                      Declarations
1787  ***************************************************************************/
1788 S16 rlcGetSId ARGS((SystemId *s));
1789
1790 Void rlcTmrExpiry ARGS((PTR cb, S16 tmrEvnt));
1791
1792 S16 rlcLmmSendTrc ARGS ((RlcCb *gCb, Event event, Buffer *mBuf));
1793
1794 void rlcStartTmr ARGS((RlcCb *gCb, PTR cb, S16 tmrEvnt));
1795
1796 void rlcStopTmr  ARGS((RlcCb *gCb, PTR cb, uint8_t tmrType));
1797
1798 bool rlcChkTmr ARGS((RlcCb *gCb,PTR cb, S16 tmrEvnt));
1799
1800 void rlcUeThptTmrExpiry(PTR cb);
1801
1802 uint8_t  rlcUeDeleteTmrExpiry(PTR cb);
1803
1804 void rlcSnssaiThptTmrExpiry(PTR cb);
1805 RlcTptPerSnssai* rlcHandleSnssaiTputlist(RlcCb *gCb, Snssai *snssai,\
1806                                 ActionTypeLL  action, Direction dir);
1807 uint8_t rlcCalculateTputPerSnssai(CmLListCp *snssaiList, Direction dir);
1808 uint8_t rlcDelTputSnssaiList(RlcCb *gCb, Direction dir);
1809 uint8_t BuildSliceReportToDu(uint8_t snssaiCnt);
1810 bool rlcFindSliceEntry(SliceIdentifier snssaiVal, uint8_t *snssaiIdx,\
1811                       SlicePmList *sliceStats);
1812
1813 #ifdef LTE_L2_MEAS
1814 Void rlcLmmSendAlarm ARGS (( RlcCb *gCb,
1815                                    uint16_t category, 
1816                                    uint16_t event, 
1817                                    uint16_t cause, 
1818                                    SuId suId, 
1819                                    uint32_t ueId, 
1820                                    uint8_t qci));
1821
1822 S16 RlcMiRlcDlL2MeasReq ARGS (( Pst *pst, RlcL2MeasReqEvt *measReqEvt ));
1823 S16 RlcMiRlcDlL2MeasSendReq ARGS((Pst *pst,uint8_t measType));
1824 S16 RlcMiRlcDlL2MeasStopReq ARGS((Pst *pst,uint8_t measType));
1825 S16 RlcMiRlcUlL2MeasReq ARGS (( Pst *pst, RlcL2MeasReqEvt *measReqEvt ));
1826 S16 RlcMiRlcUlL2MeasSendReq ARGS((Pst *pst,uint8_t measType));
1827 S16 RlcMiRlcUlL2MeasStopReq ARGS((Pst *pst,uint8_t measType));
1828 Void rlcUtlPlcMeasDatInL2Sts ARGS((RlcL2Cntr *measData, 
1829                                          RlcL2MeasRbCb *rbL2Cb,
1830                                          uint8_t measType));
1831 #else /* LTE_L2_MEAS */
1832 Void rlcLmmSendAlarm ARGS ((RlcCb *gCb,
1833                                   uint16_t category, 
1834                                   uint16_t event, 
1835                                   uint16_t cause, 
1836                                   SuId suId, 
1837                                   uint32_t ueId));
1838 #endif /* LTE_L2_MEAS */
1839
1840 #ifdef __cplusplus
1841 }
1842 #endif /* __cplusplus */
1843
1844 #endif /* __RLC_UTILS_H__ */
1845 /**********************************************************************
1846   
1847          End of file
1848 **********************************************************************/