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