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