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