b62d44d89dec1d1ec9851871f964f4023b51cd4f
[o-du/l2.git] / src / 5gnrrlc / rlc_utl_dl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /**********************************************************************
20
21      Name:     NR RLC Layer 
22   
23      Type:     C file
24   
25      Desc:     Source code for RLC Utility Module
26                This file contains following functions
27
28                   --rlcUtlSendToMac
29                   --rlcUtlRcvFrmMac
30                   --rlcUtlEmptySduQ
31                   --rlcUtlSendDedLcBoStatus
32                   --rlcUtlSendUlDataToDu 
33                   --kwUtlShutDown
34
35      File:     rlc_utl_dl.c
36
37 **********************************************************************/
38
39 /** @file rlc_utl_dl.c
40 @brief RLC Utility Module 
41 */
42
43 /* header (.h) include files */
44
45 #include "common_def.h"
46 /* kw005.201 added support for L2 Measurement */
47 #ifdef LTE_L2_MEAS
48 #include <sys/time.h>
49 #endif
50 #include "ckw.h"           /* CKW defines */
51 #include "kwu.h"           /* CKW defines */
52 #include "lkw.h"           /* LKW defines */
53 #include "rgu.h"           /* RGU defiens */
54
55 #include "rlc_env.h"        /* RLC environment options */
56 #include "rlc_err.h"        /* Error defines */
57
58
59 /* extern (.x) include files */
60 #include "ckw.x"           /* CKW includes */
61 #include "kwu.x"           /* KWU includes */
62 #include "lkw.x"           /* LKW inlcudes */
63 #include "rgu.x"           /* RGU includes */
64
65 #include "rlc_utils.h"            /* RLC defines */
66 #include "rlc_dl_ul_inf.h"
67 #include "rlc_dl.h"         /* RLC downlink includes */
68 #include "rlc_mac_inf.h"
69 #include "du_app_rlc_inf.h"
70 #include "rlc_lwr_inf_api.h"
71 #include "rlc_upr_inf_api.h"
72
73 #include "ss_rbuf.h"
74 #include "ss_rbuf.x" 
75
76 SsRngBufCnt rngCb;
77
78 #if (defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS))
79 uint32_t isDatReqProcessed;
80 #endif
81 #define RLC_MODULE (RLC_DBGMASK_DUT | RLC_DBGMASK_DL) /* for debugging purpose */
82 #if (defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS)) || defined (SS_RBUF)
83 void rlcUtlDlBatchProcHqStaInd ARGS ((Void));
84 #endif
85 Void ResetRLCStats(Void)
86 {
87    RlcCb* dlInst = rlcCb[1]; 
88    RlcCb* ulInst = rlcCb[0]; 
89    memset(&gRlcStats, 0, sizeof(RLCStats));
90    memset(&dlInst->genSts,0,sizeof(RlcGenSts));
91    memset(&ulInst->genSts,0,sizeof(RlcGenSts));
92 }
93
94 #ifndef ALIGN_64BIT
95 Void PrintRLCStats(Void)
96 {
97    RlcCb* dlInst = rlcCb[1]; 
98    RlcCb* ulInst = rlcCb[0]; 
99
100    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: PDUs Sent = (%ld), PdusRext = (%ld), TimeOut = (%ld), SduDiscarded = (%ld)",
101                      dlInst->genSts.pdusSent,
102                      dlInst->genSts.pdusRetx,
103                      dlInst->genSts.protTimeOut,
104                      dlInst->genSts.numSduDisc);
105    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: PDUs Rcvd = (%ld), unexpPdus = (%ld), errorPdus = (%ld)",
106                      ulInst->genSts.pdusRecv,
107                      ulInst->genSts.unexpPdusRecv,
108                      ulInst->genSts.errorPdusRecv);
109    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: AMDL: "
110                      "StaPduSent:%lu NacksInStaPdu:%lu BytesUnused:%lu PollTimerExpires SRB:%lu ",
111                      gRlcStats.amRlcStats.numDLStaPduSent, gRlcStats.amRlcStats.numDLNacksInStaPdu, 
112                      gRlcStats.amRlcStats.numDLBytesUnused, gRlcStats.amRlcStats.numDLPollTimerExpiresSrb);
113    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: AMDL: "
114                      "DRB:%lu MaxRetx:%lu RetransPdus:%lu", 
115                      gRlcStats.amRlcStats.numDLPollTimerExpiresDrb, gRlcStats.amRlcStats.numDLMaxRetx, 
116                      gRlcStats.amRlcStats.numDLRetransPdus);
117    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: AMUL: "
118                      " PdusDiscarded:%lu ReAsmblTimerExpires:%lu StaPduRcvd:%lu NackInStaPduRcvd:%lu ", 
119                      gRlcStats.amRlcStats.numULPdusDiscarded, gRlcStats.amRlcStats.numULReAsmblTimerExpires, 
120                      gRlcStats.amRlcStats.numULStaPduRcvd, gRlcStats.amRlcStats.numULNackInStaPduRcvd);
121
122    RTLIN_DUMP_DEBUG("RLC Stats: PDUs Sent = (%ld), PdusRext = (%ld), TimeOut = (%ld), SduDiscarded = (%ld)\n",
123                      dlInst->genSts.pdusSent,
124                      dlInst->genSts.pdusRetx,
125                      dlInst->genSts.protTimeOut,
126                      dlInst->genSts.numSduDisc);
127    RTLIN_DUMP_DEBUG("RLC Stats: PDUs Rcvd = (%ld), unexpPdus = (%ld), errorPdus = (%ld)\n",
128                      ulInst->genSts.pdusRecv,
129                      ulInst->genSts.unexpPdusRecv,
130                      ulInst->genSts.errorPdusRecv);
131    RTLIN_DUMP_DEBUG("RLC Stats:"
132                     "RLC_AMDL: StaPduSent:%lu NacksInStaPdu:%lu BytesUnused:%lu PollTimerExpires SRB:%lu DRB:%lu MaxRetx:%lu RetransPdus:%lu \n"
133                     "RLC_AMUL: PdusDiscarded:%lu ReAsmblTimerExpires:%lu StaPduRcvd:%lu NackInStaPduRcvd:%lu \n", 
134                      gRlcStats.amRlcStats.numDLStaPduSent, gRlcStats.amRlcStats.numDLNacksInStaPdu, gRlcStats.amRlcStats.numDLBytesUnused, 
135                      gRlcStats.amRlcStats.numDLPollTimerExpiresSrb, gRlcStats.amRlcStats.numDLPollTimerExpiresDrb, gRlcStats.amRlcStats.numDLMaxRetx, 
136                      gRlcStats.amRlcStats.numDLRetransPdus, gRlcStats.amRlcStats.numULPdusDiscarded, gRlcStats.amRlcStats.numULReAsmblTimerExpires, 
137                      gRlcStats.amRlcStats.numULStaPduRcvd, gRlcStats.amRlcStats.numULNackInStaPduRcvd);
138 }
139 #else
140 Void PrintRLCStats(Void)
141 {
142    RlcCb* dlInst = rlcCb[1]; 
143    RlcCb* ulInst = rlcCb[0]; 
144
145    DU_LOG ("\n ================================ RLC STATS ===========================\n");
146    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: PDUs Sent = (%d), PdusRext = (%d), TimeOut = (%d), SduDiscarded = (%d)",
147                      dlInst->genSts.pdusSent,
148                      dlInst->genSts.pdusRetx,
149                      dlInst->genSts.protTimeOut,
150                      dlInst->genSts.numSduDisc);
151    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: PDUs Rcvd = (%d), unexpPdus = (%d), errorPdus = (%d)",
152                      ulInst->genSts.pdusRecv,
153                      ulInst->genSts.unexpPdusRecv,
154                      ulInst->genSts.errorPdusRecv);
155    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: AMDL: "
156                      "StaPduSent:%u NacksInStaPdu:%u BytesUnused:%u PollTimerExpires SRB:%u ",
157                      gRlcStats.amRlcStats.numDLStaPduSent, gRlcStats.amRlcStats.numDLNacksInStaPdu, 
158                      gRlcStats.amRlcStats.numDLBytesUnused, gRlcStats.amRlcStats.numDLPollTimerExpiresSrb);
159    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: AMDL: "
160                      "DRB:%u MaxRetx:%u RetransPdus:%u", 
161                      gRlcStats.amRlcStats.numDLPollTimerExpiresDrb, gRlcStats.amRlcStats.numDLMaxRetx, 
162                      gRlcStats.amRlcStats.numDLRetransPdus);
163    DU_LOG("\nINFO  -->  RLC_DL : RLC Stats: AMUL: "
164                      " PdusDiscarded:%u ReAsmblTimerExpires:%u StaPduRcvd:%u NackInStaPduRcvd:%u ", 
165                      gRlcStats.amRlcStats.numULPdusDiscarded, gRlcStats.amRlcStats.numULReAsmblTimerExpires, 
166                      gRlcStats.amRlcStats.numULStaPduRcvd, gRlcStats.amRlcStats.numULNackInStaPduRcvd);
167  /*  RTLIN_DUMP_DEBUG("AM RLC Stats:"
168                     "RLC_AMDL: SDUs Tx :(%u) SDU Bytes Tx :(%u) SDUs Retx :(%u) MaxRetx:(%u) WindowStalls: (%u) \n"
169                     "RLC_AMUL: DropOutWinRx :(%u) SDUs Rx :(%u) SDU Bytes Rx :(%u) SDUNack Rx :(%u) Duplicate Pdu Rx :(%u) \n",
170                      gRlcStats.amRlcStats.numRlcAmCellSduTx, gRlcStats.amRlcStats.numRlcAmCellSduBytesTx,
171                      gRlcStats.amRlcStats.numRlcAmCellRetxPdu, gRlcStats.amRlcStats.numRlcAmMaxRetx, gRlcStats.amRlcStats.numRlcAmCellWinStall,
172                      gRlcStats.amRlcStats.numRlcAmCellDropOutWinRx, gRlcStats.amRlcStats.numRlcAmCellSduRx,
173                      gRlcStats.amRlcStats.numRlcAmCellSduBytesRx, gRlcStats.amRlcStats.numRlcAmCellNackRx, gRlcStats.amRlcStats.numRlcAmCellDupPduRx);
174 */
175    RTLIN_DUMP_DEBUG("RLC Stats: PDUs Sent = (%d), PdusRext = (%d), TimeOut = (%d), SduDiscarded = (%d)\n",
176                      dlInst->genSts.pdusSent,
177                      dlInst->genSts.pdusRetx,
178                      dlInst->genSts.protTimeOut,
179                      dlInst->genSts.numSduDisc);
180    RTLIN_DUMP_DEBUG("RLC Stats: PDUs Rcvd = (%d), unexpPdus = (%d), errorPdus = (%d)\n",
181                      ulInst->genSts.pdusRecv,
182                      ulInst->genSts.unexpPdusRecv,
183                      ulInst->genSts.errorPdusRecv);
184    RTLIN_DUMP_DEBUG("RLC_AMDL: StaPduSent:%u NacksInStaPdu:%u BytesUnused:%u PollTimerExpires SRB:%u DRB:%u MaxRetx:%u RetransPdus:%u \n"
185                     "      SDUs Tx :(%u) SDU Bytes Tx :(%u) SDUs Retx :(%u) WindowStalls: (%u) \n"
186
187                     "RLC_AMUL: PdusDiscarded:%u ReAsmblTimerExpires:%u StaPduRcvd:%u NackInStaPduRcvd:%u \n"
188                     "      DropOutWinRx :(%u) SDUs Rx :(%u) SDU Bytes Rx :(%u) SDUNack Rx :(%u) Duplicate Pdu Rx:(%u) \n", 
189                      gRlcStats.amRlcStats.numDLStaPduSent, gRlcStats.amRlcStats.numDLNacksInStaPdu, gRlcStats.amRlcStats.numDLBytesUnused, 
190                      gRlcStats.amRlcStats.numDLPollTimerExpiresSrb, gRlcStats.amRlcStats.numDLPollTimerExpiresDrb,
191                      gRlcStats.amRlcStats.numDLMaxRetx, gRlcStats.amRlcStats.numDLRetransPdus,
192                      gRlcStats.amRlcStats.numRlcAmCellSduTx, gRlcStats.amRlcStats.numRlcAmCellSduBytesTx,
193                      gRlcStats.amRlcStats.numRlcAmCellRetxPdu, gRlcStats.amRlcStats.numRlcAmCellWinStall,
194                      gRlcStats.amRlcStats.numULPdusDiscarded, gRlcStats.amRlcStats.numULReAsmblTimerExpires, 
195                      gRlcStats.amRlcStats.numULStaPduRcvd, gRlcStats.amRlcStats.numULNackInStaPduRcvd,
196                      gRlcStats.amRlcStats.numRlcAmCellDropOutWinRx, gRlcStats.amRlcStats.numRlcAmCellSduRx,
197                      gRlcStats.amRlcStats.numRlcAmCellSduBytesRx, gRlcStats.amRlcStats.numRlcAmCellNackRx, gRlcStats.amRlcStats.numRlcAmCellDupPduRx);
198 }
199 #endif
200
201 /*******************************************************************
202  *
203  * @brief 
204  *    Handler for storing all DL PDU Info into RLC-MAC interface
205  *    struct and sending to lower interface
206  *
207  * @details
208  *    This function stores DL PDU info for all logical channels
209  *    of per UE grant per TTI and sends to MAC
210  *
211  *    Function : rlcSendDedLcDlData 
212  *
213  * @params[in] 
214  * @return ROK     - success
215  *         RFAILED - failure
216  *
217  * ****************************************************************/
218 uint8_t rlcSendDedLcDlData(Pst *post, SpId spId, RguDDatReqInfo *datReqInfo)
219 {
220    uint8_t          ueIdx;                /* UE info list iterator */ 
221    uint8_t          tbIdx;                /* TB info list iterator */
222    uint8_t          lchIdx;               /* Lch info list iterator */
223    uint8_t          pduIdx;               /* RLC PDU list iterator */
224    RguDDatReqPerUe  datPerUe;             /* DL data info per UE */
225    RguDatReqTb      datPerTb;             /* DL data info per TB */
226    RguLchDatReq     datPerLch;            /* DL data info per Lch */
227    RlcData          *dlData = NULLP;      /* DL data to be sent to MAC */
228    RlcDlRrcMsgRsp   *dlRrcMsgRsp = NULLP; /*DL RRC Rsp to be sent to DU*/
229    Pst              pst;                  /* Post structure */
230    uint16_t         pduLen;               /* PDU length */
231    uint16_t         copyLen;              /* Number of bytes copied */
232    uint8_t          lcId = 0;
233
234    RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL,
235                        dlData, sizeof(RlcData));
236    if(dlData == NULLP)
237    {
238       DU_LOG("\nERROR  -->  RLC_DL : rlcSendDedLcDlData: Memory allocation failed for dl data");
239       RLC_FREE_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL,
240           datReqInfo, sizeof(RguDDatReqInfo));
241       return RFAILED;
242    }
243    memset(dlData, 0, sizeof(RlcData));
244
245    for(ueIdx = 0; ueIdx < datReqInfo->nmbOfUeGrantPerTti; ueIdx++)
246    {
247       datPerUe = datReqInfo->datReq[ueIdx];
248
249       dlData->cellId = datReqInfo->cellId;
250       dlData->rnti = datPerUe.rnti;
251       /* Retrieving sfn/slot from transId. It was filled in RlcProcSchedResultRpt */
252       dlData->slotInfo.sfn = datPerUe.transId >> 16;
253       dlData->slotInfo.slot = datPerUe.transId & 0xffff;
254       dlData->numPdu = 0;
255       dlData->numLc = 0;
256
257       for(tbIdx = 0; tbIdx < datPerUe.nmbOfTbs; tbIdx++)
258       {
259          datPerTb = datPerUe.datReqTb[tbIdx];
260          for(lchIdx = 0; lchIdx < datPerTb.nmbLch; lchIdx++)
261          {
262             datPerLch = datPerTb.lchData[lchIdx];
263             lcId = datPerLch.lcId;
264             for(pduIdx = 0; pduIdx < datPerLch.pdu.numPdu; pduIdx++)
265             {
266                dlData->pduInfo[dlData->numPdu].commCh = FALSE;
267                dlData->pduInfo[dlData->numPdu].lcId = datPerLch.lcId;
268
269                /* Copy Message to fixed buffer to send */
270                ODU_GET_MSG_LEN(datPerLch.pdu.mBuf[pduIdx], (MsgLen *)&pduLen);
271                RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL,
272                   dlData->pduInfo[dlData->numPdu].pduBuf, pduLen);
273
274                if (dlData->pduInfo[dlData->numPdu].pduBuf == NULLP )
275                {
276                   DU_LOG("\nERROR  -->  RLC_DL : rlcSendDedLcDlData: Memory allocation failed");
277                   for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
278                   {
279                      RLC_FREE_SHRABL_BUF(pst.region, pst.pool, dlData->pduInfo[pduIdx].pduBuf,\
280                        dlData->pduInfo[pduIdx].pduLen);
281                   }
282                   RLC_FREE_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL,
283                      dlData, sizeof(RlcData));
284                   RLC_FREE_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL,
285                      datReqInfo, sizeof(RguDDatReqInfo));
286                   return RFAILED;
287                }
288
289                ODU_COPY_MSG_TO_FIX_BUF(datPerLch.pdu.mBuf[pduIdx], 0, pduLen, \
290                   dlData->pduInfo[dlData->numPdu].pduBuf, (MsgLen *)&copyLen);
291                dlData->pduInfo[dlData->numPdu].pduLen = pduLen;
292
293                /* Free message */
294                ODU_PUT_MSG_BUF(datPerLch.pdu.mBuf[pduIdx]);
295
296                dlData->numPdu++;
297             }/* For per PDU */
298             dlData->boStatus[dlData->numLc].cellId = datReqInfo->cellId;
299             GET_UE_IDX(datPerUe.rnti, dlData->boStatus[dlData->numLc].ueIdx);
300             dlData->boStatus[dlData->numLc].commCh = false;
301             dlData->boStatus[dlData->numLc].lcId = datPerLch.lcId;
302             dlData->boStatus[dlData->numLc].bo = datPerLch.boReport.bo + datPerLch.boReport.estRlcHdrSz;
303             dlData->numLc++;
304          }/* For Data per Lch */
305       }/* For Data per Tb */
306
307       RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL, dlRrcMsgRsp, sizeof(RlcDlRrcMsgRsp));
308       if(dlRrcMsgRsp == NULLP)
309       {
310          DU_LOG("\nERROR  -->  RLC_DL : rlcSendDedLcDlData: Memory allocation failed for dlRrcMsgRsp");
311          for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
312          {
313             RLC_FREE_SHRABL_BUF(pst.region, pst.pool, dlData->pduInfo[pduIdx].pduBuf,\
314                dlData->pduInfo[pduIdx].pduLen);
315          }
316          RLC_FREE_SHRABL_BUF(pst.region, pst.pool, dlData, sizeof(RlcData));
317          RLC_FREE_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL,
318              datReqInfo, sizeof(RguDDatReqInfo));
319          return RFAILED;
320       }
321       dlRrcMsgRsp->cellId = dlData->cellId;
322       dlRrcMsgRsp->crnti = dlData->rnti;
323
324       /* Sending DL Data per UE to MAC */
325       FILL_PST_RLC_TO_MAC(pst, RLC_DL_INST, EVENT_DL_DATA_TO_MAC);
326       if(RlcSendDlDataToMac(&pst, dlData) != ROK)
327       {
328          DU_LOG("\nERROR  -->  RLC_DL : rlcSendDedLcDlData: Failed to send Dl RRC Msg To Mac");
329          dlRrcMsgRsp->state = TRANSMISSION_FAILED;
330          for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
331          {
332             RLC_FREE_SHRABL_BUF(pst.region, pst.pool, dlData->pduInfo[pduIdx].pduBuf,\
333                dlData->pduInfo[pduIdx].pduLen);
334          }
335          RLC_FREE_SHRABL_BUF(pst.region, pst.pool, dlData, sizeof(RlcData));
336          RLC_FREE_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(RguDDatReqInfo));
337          RLC_FREE_SHRABL_BUF(pst.region, pst.pool, dlRrcMsgRsp, sizeof(RlcDlRrcMsgRsp));
338          return RFAILED;
339       }
340       else
341          dlRrcMsgRsp->state = TRANSMISSION_COMPLETE;
342
343       FILL_PST_RLC_TO_DUAPP(pst, RLC_DL_INST, EVENT_DL_RRC_MSG_RSP_TO_DU);
344       if(lcId >= SRB1_LCID && lcId <= SRB3_LCID) /* Valid for all RRC messages i.e. SRB1, SRB2, SRB3 */
345       {
346          if(rlcSendDlRrcMsgRspToDu(&pst, dlRrcMsgRsp) != ROK)
347          {
348             DU_LOG("\nERROR  -->  RLC_DL : rlcSendDedLcDlData: Failed to send Dl RRC Msg Rsp To Du");
349             RLC_FREE_SHRABL_BUF(pst.region, pst.pool, dlRrcMsgRsp, sizeof(RlcDlRrcMsgRsp));
350             RLC_FREE_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(RguDDatReqInfo));
351             return RFAILED;
352          }
353       }
354    } /* For Data per UE */
355    RLC_FREE_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(RguDDatReqInfo));
356    
357    return ROK;
358 }/* End of rlcSendDedLcDlData */
359
360 /**
361  *
362  * @brief 
363  *        Handler for sending the data to multiple logical channels of a UE
364  *
365  * @details:
366  *        This function sends the data for one or more logical channels
367  *        after processing the SDUs and forming the PDUs.It calls
368  *        UMM or AMM functions to form the PDUs for the requested sizes
369  *        by MAC. 
370  *
371  * @param[in] gCb          RLC instance Control block 
372  * @param[in] staIndInfo   Status Indication Information containing the 
373  *                         size of PDU(s) for one or more logical channels  
374  *
375  * @return  S16
376  *      -# ROK 
377  *      -# RFAILED
378  *
379  */
380 uint8_t rlcUtlSendToMac(RlcCb *gCb, SuId suId, KwDStaIndInfo *staIndInfo)
381 {
382    uint8_t           numPdu = 0;
383    uint16_t          ueId;
384    RlcDlUeCb         *ueCb;         /* UE control block */
385    uint32_t          count;         /* Loop Counter */
386    uint32_t          numTb;         /* Number of Tbs */
387    RlcDlRbCb         *rbCb;         /* RB Control Block */
388    RlcDatReq         datReq;        /* PDUs Information */
389    RguDDatReqInfo   *datReqInfo;   /* Data Request Information */
390    RlcRguSapCb      *rguSap;       /* MAC SAP CB */
391    uint32_t         totNumPdu;     /* Total number of PDUS */
392    RguStaIndTb      *staIndTb = NULLP;
393    RguDatReqTb      *datReqTb = NULLP;
394    RguDStaIndPerUe  *staInd = NULLP;
395 #ifdef LTE_L2_MEAS   
396    uint32_t   grantPerLch[RGU_MAX_LC] = {0};
397 #endif
398 /* kw005.201 added support for L2 Measurement */
399 #ifdef LTE_L2_MEAS_LOSS_DELAY
400    uint8_t        snIdx1;
401    uint8_t        snIdx2;
402 #endif /* LTE_L2_MEAS */
403    uint32_t  idx, ueDataIdx = 0;
404
405 //Debug
406    uint32_t staIndSz=0,datIndSz = 0;
407
408    datReqInfo = NULLP;
409    RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL,
410                        datReqInfo,sizeof(RguDDatReqInfo));
411 #if (ERRCLASS & ERRCLS_ADD_RES)
412       if ( datReqInfo == NULLP )
413       {
414          DU_LOG("\nERROR  -->  RLC_DL : rlcUtlSendToMac: Memory allocation failed");
415          return RFAILED;
416       }
417 #endif /* ERRCLASS & ERRCLS_ADD_RES */
418    for(idx = 0; idx < staIndInfo->nmbOfUeGrantPerTti; idx++)
419    {
420       staInd = &staIndInfo->staInd[idx];
421       /* Fetch Ue control block */
422       GET_UE_IDX(staInd->rnti, ueId);
423       if(ROK != rlcDbmFetchDlUeCb(gCb, ueId, staIndInfo->cellId,&ueCb))
424       {
425          /* Fetch UeCb failed */
426          DU_LOG("\nERROR  -->  RLC_DL : rlcUtlSendToMac: UeId[%u]:ueCb not found",
427             staInd->rnti);
428          /* If ueCb is not found for current rnti then continue to look for next rnti*/
429          continue; 
430       }
431       
432       /* kw002.201 Removed the allocation of RlcDatReq */
433       /* kw004.201 Used SSI function to initialize the variable */
434       memset(&datReq, 0, sizeof(RlcDatReq) ); 
435       totNumPdu = 0;
436       for (numTb = 0; numTb < staInd->nmbOfTbs; numTb++)
437       {
438          staIndTb = &(staInd->staIndTb[numTb]);
439          datReqTb = &(datReqInfo->datReq[ueDataIdx].datReqTb[numTb]);
440 #ifdef LTE_L2_MEAS
441          ueCb->tbIdx = (ueCb->tbIdx+1) % RLC_MAX_TB_PER_UE;
442 #endif   
443          for (count = 0;count < staIndTb->nmbLch; count++)
444          {
445 #ifdef LTE_L2_MEAS
446             /*Calculate the total grant size from MAC */
447             if((staIndTb->lchStaInd[count].lcId >= RGU_MAX_LC) 
448                 || (staIndTb->lchStaInd[count].lcId == 0))
449             {
450                /* TODO : Need to figure out why this is happening */
451                break;
452             }
453             else
454             {
455                grantPerLch[staIndTb->lchStaInd[count].lcId] += staIndTb->lchStaInd[count].totBufSize;
456             }
457 #endif   
458             rbCb = ueCb->lCh[staIndTb->lchStaInd[count].lcId - 1].dlRbCb;
459
460             if (rbCb && (!rlcDlUtlIsReestInProgress(rbCb)))
461             { 
462                /* Cosider buffer size for throughput calculation */
463                if(gCb->rlcThpt.thptPerUe[ueId-1].ueId == ueId)
464                   gCb->rlcThpt.thptPerUe[ueId-1].dataVol += staIndTb->lchStaInd[count].totBufSize;
465
466                staIndSz += staIndTb->lchStaInd[count].totBufSize;
467                datReq.pduSz = staIndTb->lchStaInd[count].totBufSize;
468 #ifdef LTE_L2_MEAS            
469                datReq.totMacGrant = grantPerLch[staIndTb->lchStaInd[count].lcId];
470 #endif
471                rlcUtlGetCurrTime(&datReq.boRep.oldestSduArrTime);
472                if ( RLC_MODE_UM == rbCb->mode )
473                {
474                   rlcUmmProcessSdus(gCb,rbCb,&datReq);
475                }
476                else if ( RLC_MODE_AM == rbCb->mode )
477                {
478                   rlcAmmProcessSdus(gCb,rbCb,&datReq,staInd->fillCtrlPdu);
479                }
480 #ifdef LTE_L2_MEAS            
481                grantPerLch[staIndTb->lchStaInd[count].lcId] = datReq.totMacGrant;
482 #endif
483                if ( 0 == datReq.pduInfo.numPdu )
484                {
485                   continue;
486                }
487                totNumPdu += datReq.pduInfo.numPdu;
488                memcpy(&(datReqTb->lchData[count].pdu),
489                   &(datReq.pduInfo),sizeof(KwPduInfo));
490
491                for (;numPdu < datReqTb->lchData[count].pdu.numPdu ; numPdu ++)
492                {
493                   MsgLen len = 0;
494                   ODU_GET_MSG_LEN(datReqTb->lchData[count].pdu.mBuf[numPdu],&len);
495                   datIndSz += len; 
496                }
497                datReqTb->lchData[count].setMaxUlPrio = FALSE;
498                if (RLC_AM_IS_POLL_BIT_SET(RLC_AMDL) && 
499                    (RLC_AMDL.sduQ.count > 1))
500                { 
501                   /* Poll bit is set indicate to MAC*/
502                   datReqTb->lchData[count].setMaxUlPrio = TRUE;
503                }
504                datReqTb->lchData[count].boReport.bo = datReq.boRep.bo;
505
506 #ifdef CCPU_OPT
507                datReqTb->lchData[count].boReport.estRlcHdrSz = 
508                   datReq.boRep.estHdrSz;
509                datReqTb->lchData[count].boReport.staPduPrsnt = 
510                   datReq.boRep.staPduPrsnt;
511 #endif /* CCPU_OPT */
512                datReqTb->lchData[count].boReport.staPduBo = 
513                   datReq.boRep.staPduBo;
514                datReqTb->lchData[count].lcId = staIndTb->lchStaInd[count].lcId;
515
516 #ifdef L2_OPTMZ
517                /* Set if Bearer is UM */
518                if ( RLC_MODE_UM == rbCb->mode )
519                {
520                   datReqTb->lchData[count].freeBuff = TRUE;
521                }
522                else
523                {
524                   datReqTb->lchData[count].freeBuff = FALSE;
525                }
526 #endif
527
528                /* kw005.201 added support for L2 Measurement */
529 #ifdef LTE_L2_MEAS_LOSS_DELAY
530                datReqTb->rguSnInfo->lchMap[count].lChId =
531                   staIndTb->lchStaInd[count].lcId;
532                /* In some cases L2 Measurement for few of the lcId may be off, 
533                 * in this case we are assigning snList to 0xffff 
534                 */
535                for(snIdx1 = 0; snIdx1 < RGU_MAX_PDU; snIdx1++)
536                {
537                   datReqTb->rguSnInfo->lchMap[count].snList[snIdx1] = 0xffff;
538                }
539                if(tbSnMap->numSn != 0)
540                {
541                   snIdx2 = 0;
542                   for(snIdx1=tbSnMap->prevNumSn;snIdx1 < tbSnMap->numSn;snIdx1++)
543                   {
544                      datReqTb->rguSnInfo->lchMap[count].snList[snIdx2++] = 
545                         tbSnMap->snSduMap[snIdx1].sn;
546                   }
547                   tbSnMap->prevNumSn = tbSnMap->numSn;
548                }
549 #endif
550                datReqTb->lchData[count].boReport.oldestSduArrTime = 
551                                              datReq.boRep.oldestSduArrTime;
552                /* kw004.201 Used SSI function to initialize the variable */
553                memset(&datReq, 0, sizeof(RlcDatReq) ); 
554             }
555          }
556 #ifdef LTE_L2_MEAS
557          if(ueCb->l2MeasTbCb[ueCb->tbIdx]!= NULLP)
558          {
559             datReqTb->tbId = ueCb->tbIdx;
560          }
561          else
562          {
563             datReqTb->tbId = RLC_INVALID_TBID; 
564          }
565 #endif
566          datReqTb->nmbLch = staIndTb->nmbLch;
567          /*adding the check to make sure that lcId is not sent as 0
568           * when no data is there in datReq */
569          if ( 0 == totNumPdu )
570          {
571             datReqTb->lchData[0].lcId = staIndTb->lchStaInd[0].lcId;
572          }
573          /* kw005.201 added support for L2 Measurement */
574 #ifdef LTE_L2_MEAS_LOSS_DELAY
575          if(tbSnMap->numSn == 0)
576          {
577             RLC_FREE(tbSnMap,sizeof(RlcTbSnMap));
578             RLC_FREE(datReqTb->rguSnInfo,sizeof(RguSnMapInfo));
579             datReqTb->rguSnInfo = NULLP;
580             rlcCb.rlcL2Cb.curTbSnMap = NULLP;
581             datReqTb->snMapPres = FALSE;
582          }
583          else
584          {
585             cmHashListInsert(&(rlcCb.rlcL2Cb.tbHlCp),(PTR)tbSnMap,
586                   (uint8_t *) &(tbSnMap->tbId), (uint16_t)sizeof(tbSnMap->tbId));
587             rlcCb.rlcL2Cb.curTbSnMap = NULLP;
588          }
589 #endif /* LTE_L2_MEAS */
590       }
591       datReqInfo->datReq[ueDataIdx].nmbOfTbs = staInd->nmbOfTbs;
592       datReqInfo->datReq[ueDataIdx].transId = staInd->transId;
593       datReqInfo->datReq[ueDataIdx].rnti    = staInd->rnti;
594       ueDataIdx++;
595    }
596
597    if(ueDataIdx > 0)
598    {
599       datReqInfo->cellId  = staIndInfo->cellId;
600       datReqInfo->nmbOfUeGrantPerTti = staIndInfo->nmbOfUeGrantPerTti;
601
602       rguSap = &(gCb->u.dlCb->rguDlSap[suId]);
603       rlcSendDedLcDlData(&rguSap->pst,rguSap->spId,datReqInfo); 
604    }
605    else
606    {
607       RLC_FREE_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo,sizeof(RguDDatReqInfo));
608    }
609    return ROK;
610 }
611
612 /**
613  *
614  * @brief 
615  *        Handler for sending Status Response to MAC. 
616  *
617  * @detail:
618  *        This function is used by  RLC entity for sending
619  *        status response to MAC after receiving a SDU from
620  *        PDCP.
621  *
622  * @param[in]  gCb           RLC instance Control block
623  * @param[in]  rbCb          Radio Bearer Control Block 
624  * @param[in]  bo            Buffer Occupancy
625  * @param[in]  estHdrSz      Estimated Header Size
626  * @param[in]  staPduPrsnt   Status PDU present or not
627  *
628  * @return  S16
629  *      -# ROK 
630  *      -# RFAILED
631  */
632 uint8_t rlcUtlSendDedLcBoStatus(RlcCb *gCb, RlcDlRbCb *rbCb, int32_t bo, \
633    int32_t estHdrSz, bool staPduPrsnt, uint32_t staPduBo)
634 {
635    Pst           pst;           /* Post info */
636    RlcBoStatus   *boStatus;      /* Buffer occupancy status information */
637
638 #ifndef TENB_ACC
639    if ((rbCb->lastRprtdBoToMac > (uint32_t)8000) && (rbCb->boUnRprtdCnt < (uint32_t)5) 
640        && (!staPduPrsnt) && ((RLC_MODE_AM == rbCb->mode ) && (RLC_AMDL.nxtRetx == NULLP)))
641    {
642       rbCb->boUnRprtdCnt++;
643       return ROK;
644    }
645 #endif
646    rbCb->boUnRprtdCnt = (uint32_t)0;
647    rbCb->lastRprtdBoToMac = (uint32_t)bo;
648
649    RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_DL, RLC_POOL, \
650       boStatus, sizeof(RlcBoStatus));
651
652    boStatus->cellId = rbCb->rlcId.cellId;
653    boStatus->ueIdx = rbCb->rlcId.ueId;
654    boStatus->commCh = FALSE; 
655    boStatus->lcId = rbCb->lch.lChId;
656    boStatus->bo = bo + estHdrSz;
657
658    FILL_PST_RLC_TO_MAC(pst, RLC_DL_INST, EVENT_BO_STATUS_TO_MAC);
659    /* Send Status Response to MAC layer */
660    if(RlcSendBoStatusToMac(&pst, boStatus) != ROK)
661    {
662       RLC_FREE_SHRABL_BUF(pst.region, pst.pool, boStatus, sizeof(RlcBoStatus));
663    }
664
665    return ROK;
666 }
667
668 /**
669  *
670  * @brief 
671  *        Handler for emptying the SDU queue. 
672  * 
673  * @detail:
674  *        This function is used to empty the SDU queue when
675  *        a re-establishment request is received from the 
676  *        upper layer.
677  *
678  * @param[in]  gCb    RLC instance control block
679  * @param[in]  rbCb   Radio bearer control block
680  * @param[in]  sduQ   SDU queue to be emptied
681  *
682  * @return Void 
683  */
684 /* kw005.201 added support for L2 Measurement */
685 #ifdef LTE_L2_MEAS_RLC
686 Void rlcUtlEmptySduQ
687 (
688 RlcCb        *gCb, 
689 RlcDlRbCb    *rbCb,
690 CmLListCp   *sduQ 
691 )
692 #else
693 Void rlcUtlEmptySduQ
694 (
695 RlcCb        *gCb,
696 CmLListCp   *sduQ 
697 )
698 #endif
699 {
700 #ifdef LTE_L2_MEAS_RLC
701    CmLListCp   *sduSnMapQ;             /* SDU Sequence number map queue */
702    CmLList     *firstSduSnMap;         /* First Node in SDU SnMap Queue */
703    RlcSduSnMap  *sduSnMap;              /* SDU Sn Map */
704
705    sduSnMapQ = NULLP;
706    firstSduSnMap = NULLP;
707    sduSnMap = NULLP;
708
709
710    sduSnMapQ = &rbCb->sduSnMapQ;
711    CM_LLIST_FIRST_NODE(sduSnMapQ, firstSduSnMap);
712
713    while(firstSduSnMap)
714    {
715       sduSnMap = (RlcSduSnMap *)firstSduSnMap->node;
716       if(sduSnMap != NULLP)
717       {
718          cmLListDelFrm(&(rbCb->sduSnMapQ), &(sduSnMap->lstEnt));
719          RLC_FREE(sduSnMap, sizeof(RlcSduSnMap));
720          CM_LLIST_FIRST_NODE(sduSnMapQ, firstSduSnMap);
721       }
722       else
723       {
724          CM_LLIST_NEXT_NODE(sduSnMapQ, firstSduSnMap);
725       }
726    }
727 #endif
728    return;
729 }
730
731 /**
732  *
733  * @brief 
734  *    Function to set that re-establishment has started for an RB
735  * 
736  * @detail:
737  *    This function is used to set the reestInProgress flag to TRUE.
738  *    This also sets the estimated header size to 0 and sends bo as
739  *    0 to MAC so that RLC does not need to transmit any data.
740  *    If the poll re-transmit timer is running for the RB;
741  *    it is stopped
742  *
743  * @param[in]      gCb      RLC instance control block 
744  * @param[in]      rbCb     RB for which re-establishment has started 
745  *
746  * @return  void 
747  */
748 Void rlcDlUtlSetReestInProgressForRB(RlcCb *gCb,RlcDlRbCb *rbCb)
749 {
750       
751    rbCb->reestInProgress = TRUE;
752    
753    if(rbCb->mode == RLC_MODE_AM )
754    {
755       rbCb->m.amDl.estHdrSz = 0;
756
757       if(rlcChkTmr(gCb, (PTR)rbCb, EVENT_RLC_AMDL_POLL_RETX_TMR))
758       {
759          rlcStopTmr(gCb, (PTR)rbCb, EVENT_RLC_AMDL_POLL_RETX_TMR);
760       }
761    }
762    rlcUtlSendDedLcBoStatus(gCb, rbCb, 0, 0, FALSE,0);
763
764    return;
765 }
766
767 /**
768  *
769  * @brief 
770  *    Function to check if re-establishment is ongoing for an RB
771  * 
772  * @param[in]      rbCb     RB for which re-establishment is to be checked 
773  *
774  * @return  Bool
775  *          TRUE  : Re-establishment is in progress
776  *          FALSE : Re-establishment is not in progress
777  */
778 bool rlcDlUtlIsReestInProgress(RlcDlRbCb *rbCb)
779 {
780    return (rbCb->reestInProgress);
781 }
782
783 /**
784  *
785  * @brief 
786  *    Function to set re-establishment to FALSE
787  * 
788  * @param[in]      rbCb     RB for which re-establishment is to be reset 
789  *
790  * @return  Void
791  */
792 Void rlcDlUtlResetReestInProgress(RlcDlRbCb *rbCb)
793 {
794
795    rbCb->reestInProgress = FALSE;
796 }
797
798 /**
799  *
800  * @brief 
801  *    Function to set that re-establishment has started for all the RBs
802  *    of an UE; except for SRB1
803  *
804  * @detail: For SRB1 only the poll-retransmit timer is stopped
805  * 
806  * @param[in]      gCb      RLC instance control block 
807  * @param[in]      ueCb     UE for which re-establishment has started 
808  *
809  * @return  void 
810  */
811 Void rlcDlUtlSetReestInProgressForAllRBs(RlcCb *gCb,RlcDlUeCb *ueCb)
812 {
813    uint32_t        rbIdx;
814    
815    for(rbIdx = 0;rbIdx < RLC_MAX_SRB_PER_UE;rbIdx++)
816    {
817       if(ueCb->srbCb[rbIdx] != NULLP)
818       {
819          if(ueCb->srbCb[rbIdx]->rlcId.rbId != 1)
820          {
821             rlcDlUtlSetReestInProgressForRB(gCb,ueCb->srbCb[rbIdx]); 
822          }
823          else
824          {
825             /* For SRB we just need to stop the poll re-transmit timer */
826             if(rlcChkTmr(gCb, (PTR)ueCb->srbCb[rbIdx], EVENT_RLC_AMDL_POLL_RETX_TMR))
827             {
828                rlcStopTmr(gCb, (PTR)ueCb->srbCb[rbIdx], EVENT_RLC_AMDL_POLL_RETX_TMR);
829             }
830          }
831       }
832    }
833    
834    for(rbIdx = 0;rbIdx < RLC_MAX_DRB_PER_UE;rbIdx++)
835    {
836       if(ueCb->drbCb[rbIdx] != NULLP)
837       {
838          rlcDlUtlSetReestInProgressForRB(gCb,ueCb->drbCb[rbIdx]);
839       }
840    }
841       
842    return;
843 }
844
845 /**
846  * @brief  Function to increment number of SDUs transmitted 
847  *         in KWU SAP statistics
848  *
849  *
850  * @param[in]  rlckwuSap     KWU SAP in which to increment the counter
851  *
852  * @return  Void
853  */
854 void rlcUtlIncrementKwuStsSduTx(RlcKwuSapCb *rlckwuSap)
855 {
856    rlckwuSap->sts.sduTx++;
857    return;
858 }
859
860 /**
861  * @brief  Function to increment number of bytes and PDUs transmitted 
862  *         in General statistics
863  *
864  *
865  * @param[in]  genSts   KWU SAP in which to increment the counter
866  * @param[in]  pdu      The PDU which is sent
867  *
868  * @return  Void
869  */
870 void rlcUtlIncrementGenStsBytesAndPdusSent(RlcGenSts *genSts, Buffer *pdu)
871 {
872    MsgLen bytesSent;
873    ODU_GET_MSG_LEN(pdu, &bytesSent);
874    genSts->bytesSent += bytesSent;
875    genSts->pdusSent++;
876    return;
877 }
878
879 /**
880  * @brief  Function to initialize the data structures used to free memory
881  *
882  *
883  * @param[in]  gCb        RLC instance control block
884  * @param[out] toBeFreed  Pointer to the freeing structure. This is 
885  *                        initialized here
886  *
887  * @return  Void
888  */
889 Void rlcUtlInitToBeFreed(RlcCb *gCb,RlcDlDataToBeFreed *toBeFreed)
890 {
891    cmLListInit(&(toBeFreed->sduLst));
892    cmLListInit(&(toBeFreed->rbLst));
893    cmLListInit(&(toBeFreed->reTxLst));
894    cmLListInit(&(toBeFreed->txLst));
895    
896    return;
897 }
898
899 /**
900  * @brief  Function to initialize the DL self Pst structure
901  *
902  *
903  * @param[in]  gCb   RLC instance control block
904  *
905  * @return  Void
906  */
907 Void rlcUtlInitializeSelfPst(RlcCb *gCb)
908 {
909    Pst *selfPst = &gCb->u.dlCb->selfPst;
910    
911    RLC_MEM_SET(selfPst, 0, sizeof(Pst));
912    selfPst->srcProcId = SFndProcId();
913    selfPst->dstProcId = SFndProcId();
914    selfPst->dstEnt = gCb->init.ent;
915    selfPst->dstInst = gCb->init.inst; /* this is for the DL instance */
916    selfPst->srcEnt = gCb->init.ent;
917    selfPst->srcInst = gCb->init.inst;  /* DL instance will send to itself */
918    selfPst->prior  = PRIOR3;
919    selfPst->event  = UDX_EVT_DL_CLEANUP_MEM;
920 }
921
922 /**
923  * @brief  Function to send a DL cleanup event
924  *
925  *
926  * @param[in]  gCb   RLC instance control block
927  *
928  * @return  Void
929  */
930 void rlcUtlRaiseDlCleanupEvent(RlcCb *gCb)
931 {
932 #ifdef KWSELFPSTDLCLEAN
933    if(!gCb->u.dlCb->eventInQueue)
934    {
935       ODU_POST_TASK(&gCb->u.dlCb->selfPst, gCb->u.dlCb->selfPstMBuf);
936       gCb->u.dlCb->eventInQueue = TRUE;
937    }
938 #endif
939    return;
940 }
941
942 /**
943  * @brief  Function to add a SDU to the to be freed sdu list
944  *
945  *
946  * @param[in]  gCb   RLC instance control block
947  * @param[in]  sdu   SDU to be added to the list
948  *
949  * @return  Void
950  */
951 void rlcUtlAddSduToBeFreedQueue(RlcCb *gCb, RlcSdu *sdu)
952 {
953    cmLListAdd2Tail(&(gCb->u.dlCb->toBeFreed.sduLst), &(sdu->lstEnt));
954    return;
955 }
956
957 /**
958  * @brief  Function to add a re-transmitted pdu to the to be freed list
959  *
960  *
961  * @param[in]  gCb   RLC instance control block
962  * @param[in]  retx  Re-transmitted pdu to be added to the list
963  *
964  * @return  Void
965  */
966 Void rlcUtlAddReTxPduToBeFreedQueue(RlcCb *gCb,RlcRetx *retx)
967 {
968    cmLListAdd2Tail(&(gCb->u.dlCb->toBeFreed.reTxLst), &(retx->lstEnt));
969    return;
970 }
971
972 /**
973  * @brief  Function to add a transmitted pdu to the to be freed list
974  *
975  *
976  * @param[in]  gCb   RLC instance control block
977  * @param[in]  pdu   PDU to be added to the list
978  *
979  * @return  Void
980  */
981 Void rlcUtlAddTxPduToBeFreedQueue(RlcCb   *gCb,RlcTx   *pdu)
982 {
983    pdu->rlsLnk.node = (PTR)pdu;
984    cmLListAdd2Tail(&(gCb->u.dlCb->toBeFreed.txLst), &(pdu->rlsLnk));
985    return;
986 }
987
988 /*
989  * @brief
990  *    function to free/release the Acknowledged mode RBCB buffers
991  *
992  * @details
993  *    This primitive Frees the Acknowledged Mode RbCb transmission Buffer,
994  *    retransmission Buffer and reciption Buffers
995  *
996  * @param [in]      gCb       - RLC instance control block
997  * @param [in]      rbCb      - Downlink RB Control Block
998  * @param [in,out]  toBeFreed - Number of buffers to be freed
999  *
1000  * @return Bool
1001  *     - TRUE if more data to be freed
1002  *     - FALSE if all the data has been freed
1003  */
1004 static Bool rlcUtlFreeDlAmRbMemory(RlcCb *gCb,RlcDlRbCb *rbCb,uint32_t *toBeFreed)
1005 {
1006    RlcRetx   *retx;   /* retransmission buffer */
1007    RlcSn     mTxNext;    /* send state variable */
1008    RlcTx      *txBuf;
1009
1010    MODAMT(RLC_AMDL.txNext, mTxNext, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
1011
1012    /* TODO : to be checked changed from <= to < */
1013    while ((0 < mTxNext) && *toBeFreed)
1014    {
1015       txBuf =  rlcUtlGetTxBuf(RLC_AMDL.txBufLst, RLC_AMDL.txNextAck);
1016       if (txBuf && txBuf->pduLst.first)
1017       {
1018          while(txBuf->pduLst.first)
1019          {
1020             RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(txBuf->pduLst.first->node);
1021             ODU_PUT_MSG_BUF(pduInfo->pdu);
1022             /* Delete node from the txBuf Pdu lst */
1023             cmLListDelFrm(&txBuf->pduLst, txBuf->pduLst.first);
1024             RLC_FREE(gCb, pduInfo, sizeof(RlcDlPduInfo));
1025          }
1026          rlcUtlDelTxBuf(RLC_AMDL.txBufLst, txBuf, gCb);
1027          if(gCb->u.dlCb->shutdownReceived == 0)
1028          {   
1029             (*toBeFreed)--;
1030          }
1031       }
1032       RLC_AMDL.txNextAck = (RLC_AMDL.txNextAck + 1) & RLC_AMDL.snModMask;
1033       MODAMT(RLC_AMDL.txNext, mTxNext, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
1034    }
1035    if(*toBeFreed == 0)
1036    {
1037       return (TRUE);
1038    }
1039    
1040 #ifndef LTE_TDD 
1041       RLC_FREE(gCb,RLC_AMDL.txBufLst, (RLC_TX_BUF_BIN_SIZE * sizeof(CmLListCp)));
1042 #endif
1043
1044    RLC_LLIST_FIRST_RETX(RLC_AMDL.retxLst, retx);
1045    while (retx && (*toBeFreed)) /* Till to be freed becomes 0 */
1046    {
1047
1048       ODU_PUT_MSG_BUF(retx->seg);
1049
1050       cmLListDelFrm(&RLC_AMDL.retxLst, &retx->lstEnt);
1051       RLC_FREE(gCb, retx, sizeof(RlcRetx));
1052
1053       RLC_LLIST_FIRST_RETX(RLC_AMDL.retxLst, retx);
1054       if(gCb->u.dlCb->shutdownReceived == 0)
1055       {
1056       (*toBeFreed)--;
1057    }
1058
1059    }
1060
1061    RLC_AMDL.nxtRetx = NULLP;
1062
1063    /* clean up if there is info about STATUS PDU to be sent */
1064    if(RLC_AMDL.pStaPdu)
1065    {
1066       Pst *udxPst;
1067       udxPst = &gCb->u.dlCb->udxDlSap->pst;
1068       RLC_FREE_SHRABL_BUF_WC(udxPst->region,
1069                             udxPst->pool,
1070                             RLC_AMDL.pStaPdu, 
1071                             sizeof(RlcUdxDlStaPdu));
1072       RLC_AMDL.pStaPdu = NULLP;
1073    }
1074
1075    if(*toBeFreed == 0)
1076    {
1077       return (TRUE);
1078    }  
1079    if(gCb->u.dlCb->shutdownReceived)
1080    {   
1081       (*toBeFreed)--;
1082    }
1083    
1084    return (FALSE);
1085
1086
1087 /**
1088  * @brief  Function to free memory from the DL instance
1089  *
1090  *
1091  * @param[in]  gCb   RLC instance control block
1092  *
1093  * @return  Void
1094  */
1095 Void rlcUtlFreeDlMemory(RlcCb *gCb)
1096 {
1097    uint32_t toBeFreed; 
1098
1099    /* safety check, in case some event was still lying in the queue after
1100       the dlCb was deleted*/
1101    if(!gCb->u.dlCb)
1102    {
1103       return;
1104    }
1105
1106    RlcDlDataToBeFreed* pToBeFreed = &gCb->u.dlCb->toBeFreed;
1107    /* ccpu00136940 */
1108    if(gCb->u.dlCb->shutdownReceived)
1109    {
1110       toBeFreed = pToBeFreed->txLst.count + pToBeFreed->reTxLst.count + pToBeFreed->sduLst.count + pToBeFreed->rbLst.count; 
1111    }
1112    else
1113    {
1114       if ((pToBeFreed->txLst.count + pToBeFreed->reTxLst.count + pToBeFreed->sduLst.count) > (3 * RLC_MAX_TO_BE_FREED))
1115       {
1116 #if !defined(KWSELFPSTDLCLEAN) && defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS)
1117          if (isDatReqProcessed)
1118          {
1119             toBeFreed = (2 *RLC_MAX_TO_BE_FREED);
1120          }
1121          else
1122 #endif
1123          {
1124             toBeFreed = (3 *RLC_MAX_TO_BE_FREED)/2;
1125          }
1126       }
1127       else
1128       {
1129          toBeFreed = RLC_MAX_TO_BE_FREED;
1130       }
1131    }   
1132    CmLListCp        *lst;
1133
1134    gCb->u.dlCb->eventInQueue = FALSE; /* reset as we have received the event
1135                                          and are processing it */
1136
1137    /* Free from the ReTx list */
1138    lst  = &pToBeFreed->reTxLst;
1139    while((lst->first) && toBeFreed)
1140    {
1141       RlcRetx* seg = (RlcRetx *)(lst->first->node);
1142       cmLListDelFrm(lst, lst->first);
1143       ODU_PUT_MSG_BUF(seg->seg);
1144       RLC_FREE(gCb,seg, sizeof(RlcRetx));
1145       toBeFreed--;
1146    }   
1147
1148    /* Free from the Tx list */
1149    lst  = &pToBeFreed->txLst;
1150    while((lst->first) && toBeFreed)
1151    {
1152       RlcTx* pdu = (RlcTx *)(lst->first->node);
1153       cmLListDelFrm(lst, lst->first);
1154       while(pdu->pduLst.first)
1155       {
1156          RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(pdu->pduLst.first->node);
1157          
1158          cmLListDelFrm(&pdu->pduLst, pdu->pduLst.first);
1159          ODU_PUT_MSG_BUF(pduInfo->pdu);
1160          RLC_FREE(gCb, pduInfo, sizeof(RlcDlPduInfo));
1161       }
1162       RLC_FREE(gCb,pdu, sizeof(RlcTx));
1163       toBeFreed--;
1164    }
1165
1166    /* Free from the SDU queue */
1167    lst  = &pToBeFreed->sduLst;
1168    while((lst->first) && toBeFreed)
1169    {
1170       RlcSdu* sdu = (RlcSdu *)(lst->first->node);
1171       RLC_REMOVE_SDU(gCb, lst, sdu);
1172       toBeFreed--;
1173    }      
1174
1175    /* Free from the RBs */
1176    lst  = &pToBeFreed->rbLst;
1177    while((lst->first) && toBeFreed)
1178    {
1179       RlcDlRbCb* rbCb = (RlcDlRbCb *)(lst->first->node);
1180       Bool moreToBeFreed = rlcUtlFreeDlAmRbMemory(gCb, rbCb,&toBeFreed);
1181       if(!moreToBeFreed)
1182       {
1183          cmLListDelFrm(lst, lst->first);
1184          RLC_FREE(gCb, rbCb, sizeof(RlcDlRbCb));
1185       }
1186    } 
1187
1188    if ((toBeFreed == 0) && !(gCb->u.dlCb->shutdownReceived))
1189    {
1190       rlcUtlRaiseDlCleanupEvent(gCb);
1191    }
1192
1193    return;
1194 }
1195
1196
1197 #ifdef LTE_L2_MEAS
1198 /**
1199  *
1200  * @brief Function to initialise measurement
1201  *
1202  * @b Description
1203  *
1204  * @param[in]  gCb     RLC Instance Control Block
1205  *
1206  *  @return  Void
1207  *
1208  */
1209 S16 rlcUtlL2MeasDlInit(RlcCb *gCb)
1210 {
1211    uint16_t   cntr;
1212
1213    gCb->u.dlCb->rlcL2Cb.rlcNumMeas=0;
1214    for(cntr = 0; cntr < LKW_MAX_L2MEAS; cntr++)
1215    {
1216       memset(&(gCb->u.dlCb->rlcL2Cb.rlcL2EvtCb[cntr]), 0, sizeof(RlcL2MeasEvtCb));
1217    }
1218    gCb->u.dlCb->rlcL2Cb.rlcL2EvtCb[RLC_L2MEAS_DL_DISC].measCb.measType = LKW_L2MEAS_DL_DISC;
1219    gCb->u.dlCb->rlcL2Cb.rlcL2EvtCb[RLC_L2MEAS_DL_IP].measCb.measType = LKW_L2MEAS_DL_IP;
1220    gCb->u.dlCb->rlcL2Cb.rlcL2EvtCb[RLC_L2MEAS_DL_DELAY].measCb.measType= LKW_L2MEAS_DL_DELAY;
1221    gCb->u.dlCb->rlcL2Cb.rlcL2EvtCb[RLC_L2MEAS_UU_LOSS].measCb.measType= LKW_L2MEAS_UU_LOSS;
1222    gCb->u.dlCb->rlcL2Cb.rlcL2EvtCb[RLC_L2MEAS_ACT_UE].measCb.measType= LKW_L2MEAS_ACT_UE;
1223
1224    return ROK;
1225 }
1226 /**
1227  *
1228  * @brief Function to detect the data Burst start Condition in a DTCH
1229  *
1230  * @b Description
1231  *
1232  * @param[in]  rbCb     RB control block
1233  * @param[in]  contSduLst  Array of Contained SDUs in the DTCH   
1234  * @param[in]  dataVol  Available data in the DTCH
1235  * @param[in]  schPduSz    Total grant Size given by MAC
1236  *
1237  *  @return  Void
1238  *
1239  */
1240 Void rlcUtlUpdateBurstSdus
1241 (
1242 RlcCb            *gCb,
1243 RlcDlRbCb        *rbCb,
1244 RlcContSduLst    *contSduLst,
1245 S32              dataVol,
1246 uint32_t         schPduSz
1247 )
1248 {
1249
1250    RlcL2MeasDlIpTh   *l2MeasDlIpThruput = NULLP;
1251    RlcL2MeasTb       *l2MeasTb = NULLP;
1252    uint8_t           idx;
1253    uint8_t           currTbIdx;
1254    volatile uint32_t startTime = 0;
1255    RlcContSduLst   *dstContSduLst;
1256
1257
1258    /*starting Task*/
1259    SStartTask(&startTime, PID_RLC_DLIP_TPT_BURSTCALC);
1260
1261    l2MeasDlIpThruput = &rbCb->l2MeasIpThruput.dlIpTh;
1262
1263    if(RLC_MEAS_IS_DL_IP_MEAS_ON_FOR_RB(gCb, rbCb))
1264    {
1265       if(dataVol > schPduSz)
1266       {
1267          if(l2MeasDlIpThruput->isBurstAct == FALSE)
1268          {
1269             l2MeasDlIpThruput->burstStartTime = glblTtiCnt;
1270             l2MeasDlIpThruput->isBurstAct = TRUE;
1271             l2MeasDlIpThruput->burstEndSduId = 0;
1272          }
1273          else
1274          {  /* This is the case when another burst started before RLC gets the 
1275                l2MeasDlIpThruput->burstEndSduId = 0; */
1276          }
1277       }
1278       else
1279       {  /* Store the burstEndSduId here */
1280          if((l2MeasDlIpThruput->isBurstAct == TRUE) &&
1281                (!l2MeasDlIpThruput->burstEndSduId))
1282          {
1283             l2MeasDlIpThruput->burstEndSduId = 
1284                l2MeasDlIpThruput->outStngSduArr[l2MeasDlIpThruput->lastSduIdx].sduId;
1285          }
1286       }
1287       if(l2MeasDlIpThruput->isBurstAct == TRUE)
1288       {
1289          l2MeasTb = rlcUtlGetCurMeasTb(gCb,rbCb);
1290          /* Get the lChId from index 0, because index 0 is always for DL */
1291          if(l2MeasTb->numLcId >= RLC_MAX_ACTV_DRB) 
1292          {
1293             /* ccpu00143043 */
1294             return;
1295          }
1296          l2MeasTb->sduInfo[l2MeasTb->numLcId].lcId = rbCb->lch.lChId;
1297          /* Copy all the sduIdx from sduInfo to tb sduInfo */
1298          currTbIdx = l2MeasTb->sduInfo[l2MeasTb->numLcId].numSdus;
1299          dstContSduLst = &l2MeasTb->sduInfo[l2MeasTb->numLcId];
1300          /* ccpu00143043 */
1301          for(idx = 0; ((idx < contSduLst->numSdus)
1302                   && (currTbIdx < RLC_L2MEAS_MAX_OUTSTNGSDU)) ; idx++)
1303          {
1304             dstContSduLst->sduIdx[currTbIdx++] = contSduLst->sduIdx[idx];
1305          }
1306          l2MeasTb->sduInfo[l2MeasTb->numLcId].numSdus += idx;
1307          l2MeasTb->numLcId++;
1308       }/* End of isBurstAct */
1309    }/* End of if measOn */
1310
1311    /*stopping Task*/
1312    SStopTask(startTime, PID_RLC_DLIP_TPT_BURSTCALC);
1313    return;
1314 }
1315 /**
1316  * @brief
1317  *        This function is used to store locally the sduIdx of the sdu in the 
1318  *        outstanding SDU array
1319  * 
1320  * @b Description:
1321  *        Stores the Sdu Idx in the contained  SDU Array and increments 
1322  *        the num contained  Sdus 
1323  *
1324  *  @param[in]  sduIdx  the Index of the SDU in the outstanding SDU array
1325  *  @param[out] contSduLst This stores the indices of the SDUs 
1326  *
1327  *  @return  Void
1328  */
1329 Void rlcUtlUpdateContainedSduLst(uint8_t sduIdx,RlcContSduLst *contSduLst)
1330 {
1331    if (contSduLst->numSdus < RLC_L2MEAS_MAX_OUTSTNGSDU)
1332    {
1333     contSduLst->sduIdx[contSduLst->numSdus] = sduIdx;
1334     contSduLst->numSdus++;
1335    }
1336     return;
1337 }
1338
1339 /**
1340  * @brief
1341  *        This function is used to store the sduId of the sdu in the 
1342  *        outstanding SDU array
1343  * 
1344  * @b Description:
1345  *        Stores the Sdu Id in the outstanding SDU Array and increments 
1346  *        the num contained  Sdus 
1347  *
1348  *  @param[out] dlIpThPut  The structure in which the outstanding sdus are 
1349  *                         updated
1350  *  @param[in] sduIdx   The Idx at which the sdu ID is stored  
1351  *  @param[in] sduLen   The size if sdu in bytes  
1352  *  @param[in] newIdx   Indicates if the sdu is already present in the 
1353  *                      outstanding array  
1354  *
1355  *  @return  Void
1356  */
1357 Void rlcUtlUpdateOutStandingSduLst
1358 (
1359 RlcL2MeasDlIpTh   *dlIpThPut, 
1360 uint8_t           sduIdx, 
1361 MsgLen            sduLen, 
1362 uint32_t          sduId,
1363 Bool              newIdx
1364 )
1365 {
1366    if (sduIdx < RLC_L2MEAS_MAX_OUTSTNGSDU)
1367    {
1368    if(newIdx == TRUE)
1369    {      
1370      dlIpThPut->outStngSduArr[sduIdx].numTb = 0;
1371    }
1372    dlIpThPut->outStngSduArr[sduIdx].numTb++;
1373    dlIpThPut->outStngSduArr[sduIdx].sduId = sduId;
1374    dlIpThPut->outStngSduArr[sduIdx].sduLen = sduLen;
1375    }
1376    return;
1377 }
1378 RlcL2MeasTb * rlcUtlGetCurMeasTb(RlcCb *gCb,RlcDlRbCb *rbCb)
1379 {
1380    RlcL2MeasTb  *curL2MeasTb;
1381    uint16_t         idx;
1382
1383    if((curL2MeasTb = rbCb->ueCb->l2MeasTbCb[rbCb->ueCb->tbIdx]) == NULLP)
1384       {
1385          /* Intentionally avoiding the RLC_ALLOC macro to avoid  memset */
1386          RLC_ALLOC(gCb, curL2MeasTb, (Size)sizeof(RlcL2MeasTb));
1387          if(curL2MeasTb == NULLP)
1388          {
1389             DU_LOG("ERROR  --> RLC_DL :  rlcUtlGetCurMeasTb(): Memory allocation failed");
1390             return (NULLP);
1391          }
1392          rbCb->ueCb->l2MeasTbCb[rbCb->ueCb->tbIdx] = curL2MeasTb;
1393          /* Initialize the Meas Tb details */
1394          curL2MeasTb->numLcId = 0;
1395          curL2MeasTb->numLchInfo = 0;
1396          curL2MeasTb->txSegSduCnt = 0;
1397          for (idx = 0; idx < RLC_MAX_ACTV_DRB; idx++)
1398          {
1399             curL2MeasTb->sduInfo[idx].numSdus = 0;
1400          }
1401          for (idx = 0; idx < RLC_MAX_ACTV_DRB; idx++)
1402          {
1403             curL2MeasTb->lchInfo[idx].numSdus = 0;
1404          }
1405       }
1406    return (curL2MeasTb);
1407 }
1408
1409
1410 /**
1411  *
1412  * @brief Handler for Processing harq status indication
1413  *
1414  *
1415  * @b Description
1416  *        This function is called when the MAC sends a harq ind Mesage.
1417  *        This is used only for UuLoss and Dl Delay and DL Ipthoughput
1418  *        L2 Measurements.
1419  *
1420  *  @param[in] staInd Harq status indication received from MAC.
1421  *  @param[in] ueCb   UeCb corresponding to the Tb Id.
1422  *  @param[in] tbIdx  TB index, 0 for SISO and 0,1 for MIMO.
1423  *
1424  *
1425  *  @return  S16
1426  *      -# ROK
1427  */
1428
1429 S16 rlcUtlProcHarqInd
1430 (
1431 RlcCb            *gCb,
1432 RguHarqStatusInd *hqStaInd,
1433 RlcDlUeCb        *ueCb,
1434 uint8_t          tbIdx
1435 )
1436 {
1437 #ifdef LTE_L2_MEAS
1438    RlcDlRbCb        *rlcRbCb;           /* KW Control Block */
1439    RlcL2MeasTb       *l2MeasTb = NULLP;         /* Measurement TbCb */
1440    uint8_t           lcIdx;             /* Logical channel id index */
1441    uint8_t           sduIndx;            /* sdu index to out standing sdu list in rbCb */
1442    uint32_t          numSdus;           /* number of sdus in the outstanding sdu list */
1443    RlcOutStngSduInfo *outStngSduArr;  /* Outstanding sdu list */
1444    Ticks             ackTime;
1445    Ticks             delay;
1446    uint32_t          totlSduCnt = 0;
1447 #endif
1448    uint8_t           timeAddedFlag;
1449    S16               ret;
1450    volatile uint32_t     startTime = 0;
1451    /*kw005.201 Code added for DL IP thruput measurement*/
1452
1453    /*starting Task*/
1454    SStartTask(&startTime, PID_RLC_DLIP_TPT_PRCHARQIND);
1455
1456    ret = ROK;
1457    if(hqStaInd->tbId[tbIdx] >= RLC_INVALID_TBID)
1458    {
1459       return ROK;
1460    }
1461
1462    /* Find the L2 measurement tbCb to process DL Ip thruput*/
1463    l2MeasTb = ueCb->l2MeasTbCb[hqStaInd->tbId[tbIdx]];
1464    if(l2MeasTb == NULLP)
1465    {
1466       return ROK;
1467    }
1468    /* For each logical channel in the tbCb, process 
1469     * and get the DL IP thruput */
1470    ackTime = SGetTtiCount();
1471    for(lcIdx = 0; ((lcIdx < l2MeasTb->numLcId) && (lcIdx < RLC_MAX_ACTV_DRB)); lcIdx++)
1472    {
1473       timeAddedFlag = FALSE;
1474       if((rlcRbCb = ueCb->lCh[l2MeasTb->sduInfo[lcIdx].lcId - 1].dlRbCb)
1475             == NULLP)
1476       {
1477          continue;
1478       }
1479       /* fix for DL IP stop*/
1480       if (!gCb->u.dlCb->rlcL2Cb.measOn[rlcRbCb->qci]
1481             || (rlcRbCb->rlcId.rbType == CM_LTE_SRB))
1482       {
1483          continue;
1484       }
1485       
1486       /* Get the outstanding SDUs using sdu index stored in Container sduList
1487        * and check for HARQ ACK/NACK */
1488       numSdus = l2MeasTb->sduInfo[lcIdx].numSdus;
1489       /* ccpu00143043 */
1490       if ((numSdus >= RLC_L2MEAS_MAX_OUTSTNGSDU) || (numSdus == 0))
1491       {
1492          break;
1493       }
1494       totlSduCnt += numSdus;
1495
1496       if (RLC_MEAS_IS_DL_IP_MEAS_ON_FOR_RB(gCb,rlcRbCb))
1497       {
1498          for(sduIndx = 0; sduIndx < numSdus; sduIndx++)
1499          {
1500             outStngSduArr =&(rlcRbCb->l2MeasIpThruput.dlIpTh.outStngSduArr[\
1501                   l2MeasTb->sduInfo[lcIdx].sduIdx[sduIndx]]);
1502             if(hqStaInd->status[tbIdx] == TRUE)
1503             {
1504                /* If ACK is for burst End Sdu Id set burstActive 
1505                 * to FALSE  and accumulate time */
1506                if((rlcRbCb->l2MeasIpThruput.dlIpTh.burstEndSduId == 
1507                         outStngSduArr->sduId) && (outStngSduArr->numTb == 1))
1508                {
1509                   rlcRbCb->l2MeasIpThruput.dlIpTh.isBurstAct = FALSE;
1510                   /*Update the l2Sts structure for calculating throughput*/
1511                   rlcRbCb->rbL2Cb.l2Sts[RLC_L2MEAS_DL_IP]->dlIpThruput.volSummation
1512                      += outStngSduArr->sduLen;
1513
1514                   rlcRbCb->rbL2Cb.l2Sts[RLC_L2MEAS_DL_IP]->dlIpThruput.timeSummation
1515                      += glblTtiCnt - rlcRbCb->l2MeasIpThruput.dlIpTh.burstStartTime;
1516                   outStngSduArr->sduId = 0;
1517                   outStngSduArr->sduLen = 0;
1518                   outStngSduArr->numTb = 0;
1519                   rlcRbCb->l2MeasIpThruput.dlIpTh.burstEndSduId = 0;
1520                }
1521
1522                /* If burst is active and this sdu is only transmitted in single TB then
1523                 * accumulate volume  and clear the outstanding sduList */
1524                if((rlcRbCb->l2MeasIpThruput.dlIpTh.isBurstAct == TRUE) &&
1525                      (--(outStngSduArr->numTb) == 0))
1526                {
1527                   rlcRbCb->rbL2Cb.l2Sts[RLC_L2MEAS_DL_IP]->dlIpThruput.volSummation
1528                      += outStngSduArr->sduLen;
1529
1530                   if(timeAddedFlag == FALSE)
1531                   {
1532                      rlcRbCb->rbL2Cb.l2Sts[RLC_L2MEAS_DL_IP]->dlIpThruput.timeSummation
1533                         += glblTtiCnt - rlcRbCb->l2MeasIpThruput.dlIpTh.burstStartTime;
1534                      rlcRbCb->l2MeasIpThruput.dlIpTh.burstStartTime = glblTtiCnt;
1535                      timeAddedFlag = TRUE;
1536                   }
1537                   outStngSduArr->sduId = 0;
1538                   outStngSduArr->sduLen = 0;
1539                }
1540             }/* End of status == TRUE */
1541             else
1542             {
1543                if(rlcRbCb->l2MeasIpThruput.dlIpTh.isBurstAct == TRUE)
1544                {
1545                   if((rlcRbCb->l2MeasIpThruput.dlIpTh.burstEndSduId == 
1546                            outStngSduArr->sduId))
1547                   {
1548                      rlcRbCb->l2MeasIpThruput.dlIpTh.isBurstAct = FALSE;
1549                      rlcRbCb->l2MeasIpThruput.dlIpTh.burstEndSduId = 0;
1550                   }
1551                   /* Clear the outstanding sdu list */
1552                   outStngSduArr->sduId = 0;
1553                   outStngSduArr->sduLen = 0;
1554                   outStngSduArr->numTb = 0;
1555                }
1556             }
1557          }
1558       } 
1559    }
1560
1561    for(lcIdx = 0; ((lcIdx < l2MeasTb->numLchInfo) && (lcIdx < RLC_MAX_ACTV_DRB)); lcIdx++)
1562    {
1563       if((rlcRbCb = ueCb->lCh[l2MeasTb->lchInfo[lcIdx].lcId - 1].dlRbCb)
1564             == NULLP)
1565       {
1566          continue;
1567       }
1568       numSdus = l2MeasTb->lchInfo[lcIdx].numSdus;
1569       if ( numSdus == 0 )
1570       {
1571          continue;
1572       }
1573       /* ccpu00143043 */
1574       if ((numSdus > RLC_L2MEAS_MAX_OUTSTNGSDU) || (numSdus == 0))
1575       {
1576          break;
1577       }
1578       /* Update stats */
1579       if(hqStaInd->status[tbIdx] == TRUE)
1580       {
1581          for(sduIndx = 0; sduIndx < numSdus; sduIndx++)
1582          {
1583             delay = RLC_TIME_DIFF(ackTime,l2MeasTb->lchInfo[lcIdx].sduInfo[sduIndx].arvlTime);
1584             RLC_UPD_PDCP_L2_DLDELAY_STS(gCb,rlcRbCb, delay); 
1585          }
1586          /* Case of sduInfo not updated */
1587          if (totlSduCnt == 0)
1588          {
1589             totlSduCnt = numSdus;
1590          }
1591          RLC_UPD_L2_UU_LOSS_POS_PKTS(gCb,rlcRbCb, (totlSduCnt + l2MeasTb->txSegSduCnt));
1592       }
1593       else
1594       {
1595          /* Case of sduInfo not updated */
1596          if (totlSduCnt == 0)
1597          {
1598             totlSduCnt = numSdus;
1599          }
1600          RLC_UPD_L2_UU_LOSS_PKTS(gCb,rlcRbCb, (totlSduCnt + l2MeasTb->txSegSduCnt));
1601       }
1602    }
1603    /* Free this tb, deallocate the memory */
1604    RLC_FREE(gCb, l2MeasTb, sizeof(RlcL2MeasTb));
1605    ueCb->l2MeasTbCb[hqStaInd->tbId[tbIdx]] = NULLP;
1606    
1607    /*stopping Task*/
1608    SStopTask(startTime, PID_RLC_DLIP_TPT_PRCHARQIND);
1609
1610    return (ret);
1611 }/* end of  rlcUtlProcHarqInd */ 
1612
1613 /**
1614  *
1615  * @brief Handler for Sending L2 Measurement confirm.
1616  *
1617  *
1618  * @b Description
1619  *        This function sends a consolidates the mesaurements taken during
1620  *        this time and sends the confirm .
1621  *
1622  *  @param[in] measEvtCb    Measurement Event Control Block.
1623  *
1624  *
1625  *  @return  S16
1626  *      -# ROK
1627  */
1628
1629 S16 rlcUtlSndDlL2MeasCfm(RlcCb *gCb,RlcL2MeasEvtCb *measEvtCb)
1630 {
1631    uint32_t         qciIdx;
1632    RlcL2MeasCb      *measCb = NULLP;
1633    RlcL2MeasCfmEvt   measCfmEvt;
1634    uint32_t          posPkts;
1635    uint32_t          dLoss;
1636    uint64_t          dlDataVol;
1637    uint64_t          dlTime;
1638    uint16_t          cntr;
1639    /* Discard new changes starts */
1640    uint8_t           qci = 0;
1641    uint32_t          cfmIdx =0;
1642    /* Discard new changes ends */
1643
1644    /* kw006.201 ccpu00120058 emoved 64 bit compilation warning */
1645 #ifndef ALIGN_64BIT
1646    DU_LOG("\nDEBUG  -->  RLC_DL : rlcUtlSndL2MeasCfm(transId(%ld))", measEvtCb->transId);
1647 #else
1648    DU_LOG("\nDEBUG  -->  RLC_DL : rlcUtlSndL2MeasCfm(transId(%d))", measEvtCb->transId);
1649 #endif
1650
1651    /* Clean up the RB data structures */
1652    measCb = &measEvtCb->measCb;
1653    
1654    memset(&measCfmEvt, 0, sizeof(RlcL2MeasCfmEvt));
1655    measCfmEvt.transId = measEvtCb->transId;
1656
1657    measCfmEvt.measType = measCb->measType;
1658    measCfmEvt.status.status = LCM_PRIM_OK;
1659    measCfmEvt.status.reason = LCM_REASON_NOT_APPL;
1660    
1661    if(measCb->measType & LKW_L2MEAS_DL_IP)
1662    {
1663       RlcL2MeasCbUeMeasInfo *pUeInfoLstCb  = measCb->val.ipThMeas.ueInfoLst;
1664       RlcL2MeasCfmUeInfoLst *pUeInfoLstCfm = measCfmEvt.val.ipThMeas.ueInfoLst;
1665
1666       for(cntr = 0;(cntr < measCb->val.ipThMeas.numUes) && (cntr < gCb->genCfg.maxUe);cntr++)        
1667       {
1668          pUeInfoLstCfm[cfmIdx].numCfm = 0;
1669          if (pUeInfoLstCb[cntr].isValid == TRUE)
1670          {
1671             pUeInfoLstCfm[cfmIdx].ueId = pUeInfoLstCb[cntr].ueId;
1672             pUeInfoLstCfm[cfmIdx].cellId = pUeInfoLstCb[cntr].cellId;
1673             for(qciIdx = 0; qciIdx < pUeInfoLstCb[cntr].numQci; qciIdx++)           
1674             {
1675                qci = pUeInfoLstCb[cntr].qci[qciIdx];
1676                pUeInfoLstCfm[cfmIdx].measCfm[pUeInfoLstCfm[cfmIdx].numCfm].qci = qci;
1677
1678                dlDataVol = pUeInfoLstCb[cntr].measData[qci].dlIpThruput.volSummation;
1679                dlTime = pUeInfoLstCb[cntr].measData[qci].dlIpThruput.timeSummation;
1680
1681                if((0 == dlTime) || !(gCb->u.dlCb->rlcL2Cb.measOn[qci] & LKW_L2MEAS_DL_IP) )
1682                {
1683                   pUeInfoLstCfm[cfmIdx].measCfm[pUeInfoLstCfm[cfmIdx].numCfm].val.ipThrput.dlIpThPut = 0;
1684                }
1685                else
1686                {
1687                   pUeInfoLstCfm[cfmIdx].measCfm[pUeInfoLstCfm[cfmIdx].numCfm].val.ipThrput.dlIpThPut = 
1688                      (dlDataVol / dlTime);
1689                }
1690                pUeInfoLstCfm[cfmIdx].measCfm[pUeInfoLstCfm[cfmIdx].numCfm].val.ipThrput.dlIpThPut *= 8;
1691
1692                /* Reset the values after reporting to Application */
1693                pUeInfoLstCb[cntr].measData[qci].dlIpThruput.volSummation = 0;
1694                pUeInfoLstCb[cntr].measData[qci].dlIpThruput.timeSummation = 0;
1695
1696                measCfmEvt.val.ipThMeas.ueInfoLst[cfmIdx].numCfm++;
1697             }
1698             cfmIdx++;
1699          }
1700       }
1701       measCfmEvt.val.ipThMeas.numUes = cfmIdx; 
1702    }
1703    else
1704    {
1705       RlcL2Cntr *pMeasData = measCb->val.nonIpThMeas.measData;
1706       RlcL2MeasCfmNonIpThMeas *pMeasCfmNonIp = &measCfmEvt.val.nonIpThMeas;
1707
1708       pMeasCfmNonIp->numCfm = 0;
1709
1710       for(qciIdx = 0; qciIdx < LKW_MAX_QCI; qciIdx++)
1711       {
1712          qci = measCb->val.nonIpThMeas.qci[qciIdx];
1713          if (qci > 0)
1714          {
1715             pMeasCfmNonIp->measCfm[pMeasCfmNonIp->numCfm].qci = qci;
1716
1717             if(measCb->measType & LKW_L2MEAS_UU_LOSS)
1718             {
1719                dLoss = pMeasData[qci].uuLoss.dLoss;
1720                posPkts = pMeasData[qci].uuLoss.posPkts;
1721                if(((posPkts + dLoss) != 0))
1722                {
1723                   pMeasCfmNonIp->measCfm[pMeasCfmNonIp->numCfm].val.nonIpThrput.uuLoss  =
1724                      ((dLoss  * 1000000) / (posPkts + dLoss));
1725                }
1726                pMeasData[qci].uuLoss.dLoss = 0;
1727                pMeasData[qci].uuLoss.posPkts = 0;
1728             }
1729             if(measCb->measType & LKW_L2MEAS_DL_DISC)
1730             {
1731
1732                pMeasCfmNonIp->measCfm[pMeasCfmNonIp->numCfm].val.nonIpThrput.dlDiscRate = 0;
1733                if(pMeasData[qci].dlDisc.totSdus != 0)
1734                {
1735                   pMeasCfmNonIp->measCfm[pMeasCfmNonIp->numCfm].val.nonIpThrput.dlDiscRate = 
1736                      (((pMeasData[qci].dlDisc.discSdus)  * 1000000) / (pMeasData[qci].dlDisc.totSdus));
1737                }
1738
1739                pMeasData[qci].dlDisc.totSdus = 0;
1740                pMeasData[qci].dlDisc.discSdus = 0;
1741             }
1742             if(measCb->measType & LKW_L2MEAS_DL_DELAY)
1743             {
1744                if (pMeasData[qci].dlPjSduDelay.numSdus > 0)
1745                {
1746                   pMeasCfmNonIp->measCfm[pMeasCfmNonIp->numCfm].val.nonIpThrput.dlSduDelay = 
1747                     (pMeasData[qci].dlPjSduDelay.sduDelay / pMeasData[qci].dlPjSduDelay.numSdus);
1748                   pMeasData[qci].dlPjSduDelay.sduDelay = 0;
1749                   pMeasData[qci].dlPjSduDelay.numSdus = 0;
1750                }
1751             }
1752             pMeasCfmNonIp->numCfm++;
1753          }
1754       }
1755    }
1756    /* Fix Klock warning */
1757    RlcMiLkwL2MeasCfm(&gCb->genCfg.lmPst, &measCfmEvt);
1758    return ROK;
1759 } /* rlcUtlSndL2MeasCfm */
1760 /**
1761  *
1762  * @brief Handler for Sending Negative confirm .
1763  *
1764  *
1765   @b Description
1766  *        This function is called when the l2 measurement cannot be started
1767  *        This function sends  negative confirm for all the requests
1768  *
1769  *  @param[in] measReqEvt    Measurement Req Structure
1770  *
1771  *
1772  *  @return  S16
1773  *      -# ROK
1774  */
1775
1776 S16 rlcUtlSndDlL2MeasNCfm(RlcCb *gCb,RlcL2MeasReqEvt *measReqEvt,RlcL2MeasCfmEvt *measCfmEvt)
1777 {
1778
1779    RlcMiLkwL2MeasCfm(&gCb->genCfg.lmPst, measCfmEvt);
1780    return ROK;
1781 } /* kwUtlSndL2MeasNCfm */
1782 /**
1783  *
1784  * @brief Handler for resetting the RB data structures
1785  *
1786  *
1787  * @b Description
1788  *        This function resets the RB data structure after the expiry of 
1789  *        measurement timer.
1790  *
1791  *  @param[in] measCb    Measurement Control Block.
1792  *
1793  *
1794  *  @return  Void
1795  */
1796
1797 Void rlcUtlResetDlL2MeasInRlcRb(RlcCb *gCb,RlcL2MeasCb *measCb,uint8_t measType)
1798 {
1799    uint32_t           ueIdx;
1800    uint32_t           qciIdx;
1801    RlcDlUeCb      *ueCb = NULL;
1802
1803
1804
1805    if (measCb->measType & LKW_L2MEAS_DL_IP)
1806    {
1807       for(ueIdx = 0; ueIdx < measCb->val.ipThMeas.numUes; ueIdx++)
1808       {           
1809          if (measCb->val.ipThMeas.ueInfoLst[ueIdx].isValid == TRUE)
1810          {
1811             for (qciIdx =0; qciIdx < measCb->val.ipThMeas.ueInfoLst[ueIdx].numQci; qciIdx++)
1812             {
1813                if (measType & LKW_L2MEAS_DL_IP)
1814                {
1815                   measCb->val.ipThMeas.ueInfoLst[ueIdx].measData[qciIdx].dlIpThruput.volSummation = 0;
1816                   measCb->val.ipThMeas.ueInfoLst[ueIdx].measData[qciIdx].dlIpThruput.timeSummation = 0;
1817                   gCb->u.dlCb->rlcL2Cb.measOn[qciIdx] &= ~measType; 
1818                }
1819             }
1820
1821             if(ROK  != rlcDbmFetchDlUeCb(gCb,measCb->val.ipThMeas.ueInfoLst[ueIdx].ueId,
1822                      measCb->val.ipThMeas.ueInfoLst[ueIdx].cellId, &ueCb))
1823             {
1824                continue;
1825             }
1826
1827          }
1828       }
1829    }
1830    else
1831    {
1832       /* for now the only meas should be DL discard in this case */
1833       if (measCb->measType & LKW_L2MEAS_DL_DISC)
1834       {
1835          uint32_t i;
1836          for(i = 0; i < measCb->val.nonIpThMeas.numQci; i++)
1837          {
1838             uint8_t qciVal = measCb->val.nonIpThMeas.qci[i];
1839
1840             measCb->val.nonIpThMeas.measData[qciVal].dlDisc.discSdus = 0;
1841             measCb->val.nonIpThMeas.measData[qciVal].dlDisc.totSdus  = 0;
1842          }
1843          
1844       }
1845       if (measCb->measType & LKW_L2MEAS_DL_DELAY)
1846       {
1847          uint32_t i;
1848          for(i = 0; i < measCb->val.nonIpThMeas.numQci; i++)
1849          {
1850             uint8_t qciVal = measCb->val.nonIpThMeas.qci[i];
1851
1852             measCb->val.nonIpThMeas.measData[qciVal].dlPjSduDelay.sduDelay = 0;
1853          }
1854       }
1855       measCb->val.nonIpThMeas.numQci = 0;
1856    }
1857 } /* rlcUtlResetDlL2MeasInRlcRb */
1858 #endif
1859
1860 static Void dumpRLCDlRbInformation(RlcDlRbCb* dlRbCb)
1861 {
1862    if(dlRbCb->mode == RLC_MODE_UM)
1863    {
1864       DU_LOG("\nDEBUG  -->  RLC_DL : UM Downlink UEID:%d CELLID:%d Q size = %d",
1865                        dlRbCb->rlcId.ueId,
1866                        dlRbCb->rlcId.cellId,
1867                        (int)dlRbCb->m.umDl.sduQ.count);
1868    }
1869    else if(dlRbCb->mode == RLC_MODE_AM)
1870    {
1871       uint32_t j, numTxPdus=0;
1872       for(j = 0; j <= (RLC_AM_GET_WIN_SZ(dlRbCb->m.amDl.snLen)); j++)
1873       {
1874          RlcTx *txBuf = rlcUtlGetTxBuf(dlRbCb->m.amDl.txBufLst, j);
1875          if(txBuf != NULLP)
1876          {
1877             numTxPdus++;
1878          }
1879       }
1880       DU_LOG("\nDEBUG  -->  RLC_DL : AM Downlink UEID:%d CELLID:%d Sizes SDU Q = %d TX Q = %d ",
1881                        dlRbCb->rlcId.ueId,
1882                        dlRbCb->rlcId.cellId,
1883                        (int)dlRbCb->m.amDl.sduQ.count,
1884                        (int)numTxPdus);
1885       DU_LOG("\nDEBUG  -->  RLC_DL : AM Downlink UEID:%d CELLID:%d RETX Q= %d",
1886                        dlRbCb->rlcId.ueId,
1887                        dlRbCb->rlcId.cellId,
1888                        (int)dlRbCb->m.amDl.retxLst.count);
1889    }
1890 }
1891
1892 Void DumpRLCDlDebugInformation(Void)
1893 {
1894    RlcCb* dlInst = rlcCb[1]; /* TODO : Check whether DL is 0 or 1 */
1895
1896    RlcDlCb *dlCb = dlInst->u.dlCb;
1897
1898    RlcDlUeCb *ueCb = NULLP; 
1899    RTLIN_DUMP_DEBUG("RLC Information\n");
1900    RTLIN_DUMP_DEBUG("===============\n");
1901    /* Until no more ueCb is ueLstCp hash list get and delete ueCb */
1902    while (ROK == cmHashListGetNext(&dlCb->ueLstCp, 
1903                                    (PTR) ueCb, 
1904                                    (PTR *)&ueCb))
1905    {
1906       uint32_t i;
1907       for(i = 0; i< RLC_MAX_SRB_PER_UE; i++)
1908       {
1909          RlcDlRbCb* dlRbCb = ueCb->srbCb[i]; 
1910          if( dlRbCb != NULLP)
1911          {
1912             dumpRLCDlRbInformation(dlRbCb);
1913          }
1914       }
1915       for(i = 0; i< RLC_MAX_DRB_PER_UE; i++)
1916       {
1917          RlcDlRbCb* dlRbCb = ueCb->drbCb[i]; 
1918          if( dlRbCb != NULLP)
1919          {
1920             dumpRLCDlRbInformation(dlRbCb);
1921          }
1922       }
1923    }
1924
1925    RlcDlDataToBeFreed* pToBeFreed = &dlCb->toBeFreed;
1926
1927    RTLIN_DUMP_DEBUG("toBeFreed RETX list size = %d\n",(int)pToBeFreed->reTxLst.count);
1928    RTLIN_DUMP_DEBUG("toBeFreed TX list size   = %d\n",(int)pToBeFreed->txLst.count);
1929    RTLIN_DUMP_DEBUG("toBeFreed SDU list size  = %d\n",(int)pToBeFreed->sduLst.count);
1930    RTLIN_DUMP_DEBUG("toBeFreed RB list size   = %d\n",(int)pToBeFreed->rbLst.count);
1931 }
1932
1933 /**
1934  *
1935  * @b Description
1936  *        This function frees downlink memory 
1937  *
1938  *  @param[in] Void
1939  *
1940  *
1941  *  @return  Void
1942  */
1943
1944 void rlcUtlFreeDlMem( Void)
1945 {
1946   rlcUtlFreeDlMemory(RLC_GET_RLCCB(RLC_DL_INST));
1947 }
1948
1949 /**
1950  *
1951  * @b Description
1952  *        This function returns current time
1953  *
1954  *  @param[in] uint32_t 
1955  *
1956  *
1957  *  @return  Void
1958  */
1959
1960 void rlcUtlGetCurrTime(uint32_t  *currTime)
1961 {
1962    /* Need t define else part for PAL */
1963    *currTime = SGetTtiCount();
1964 }
1965
1966 #if defined(MAC_RLC_HARQ_STA_RBUF) || defined (SS_RBUF)
1967 #ifdef LTE_L2_MEAS
1968 void rlcUtlDlBatchProcHqStaInd( Void)
1969 {
1970    /* Read from Ring Buffer and process PDCP packets */
1971    //Pst pst = {0};
1972
1973    Void *elmIndx = NULLP;
1974    RguHarqStaInd *staInd = NULLP;
1975
1976 #if defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS)
1977    isDatReqProcessed = TRUE;
1978 #endif
1979    elmIndx = (Void *)SRngGetRIndx(SS_RNG_BUF_MAC_HARQ);
1980    while(NULLP != elmIndx)
1981    {
1982       staInd = (RguHarqStaInd *)elmIndx;
1983       RlcLiRguHqStaInd(&(staInd->pst), 0, &(staInd->hqStatusInd));
1984
1985       elmIndx = NULLP;
1986       staInd  = NULLP;
1987       SRngIncrRIndx(SS_RNG_BUF_MAC_HARQ);
1988
1989       if((elmIndx = (Void *)SRngGetRIndx(SS_RNG_BUF_MAC_HARQ)) == NULLP)
1990       {
1991 #if defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS)
1992          isDatReqProcessed = FALSE;
1993 #endif
1994          break;
1995       }
1996    }
1997 }
1998 #endif
1999 #endif
2000
2001 /**
2002  * @brief evaluate and trigger PDB based flow control to PDCP 
2003  *
2004  * @details 
2005  *
2006  * @param[in]   rbCb  RB control block 
2007  *
2008  *
2009  *  @return  Void
2010  *
2011  */
2012 Void rlcUtlTrigPdbFlowCntrl(RlcCb  *gCb,RlcDlRbCb *rbCb,uint32_t pktAdmitCnt)
2013 {
2014    KwuFlowCntrlIndInfo    *flowCntrlInfo;
2015    RlcKwuSapCb*            rlckwuSap;
2016
2017    rlckwuSap = gCb->u.dlCb->rlcKwuDlSap + RLC_UI_PDCP;
2018
2019    RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region, 
2020                               rlckwuSap->pst.pool, 
2021                               flowCntrlInfo, 
2022                               sizeof(KwuFlowCntrlIndInfo));
2023    flowCntrlInfo->rlcId       = rbCb->rlcId;
2024    flowCntrlInfo->pktAdmitCnt = pktAdmitCnt;
2025    RlcUiKwuFlowCntrlInd(&rlckwuSap->pst, rlckwuSap->suId, flowCntrlInfo);
2026 }
2027
2028 /**
2029  *
2030  * @brief Store the DL buffer in hashList  
2031  *
2032  *
2033  * @b Description
2034  *
2035  *   Use the SN % binSize as key and store the received UL buffer
2036  *  @param[in] txBufLst       List CP array
2037  *  @param[in] txBuf          transmitted buffer
2038  *  @param[in] sn              sn of the received buffer 
2039  *
2040  *
2041  *  @return  Void
2042  */
2043 void rlcUtlStoreTxBuf(CmLListCp *txBufLst, RlcTx *txBuf, RlcSn sn)
2044 {
2045    uint32_t   hashKey; 
2046
2047    hashKey = (sn % RLC_TX_BUF_BIN_SIZE );
2048    txBuf->sn = sn; 
2049    txBuf->lnk.node = (PTR)txBuf;
2050    cmLListAdd2Tail(&(txBufLst[hashKey]), &txBuf->lnk);
2051
2052    return;
2053 } /* rlcUtlStoreRecBuf */
2054
2055 /**
2056  *
2057  * @brief Retrieve the DL buffer from the list
2058  *
2059  *
2060  * @Description
2061  *
2062  *   Use the SN % binSize as key and retrieve the DL buffer
2063  *  @param[in] txBufLst       List CP array
2064  *  @param[in] sn              sn of the transmitted buffer 
2065  *
2066  *
2067  *  @return  Void
2068  */
2069 RlcTx* rlcUtlGetTxBuf(CmLListCp *txBufLst, RlcSn sn)
2070 {
2071    uint32_t            hashKey; 
2072    CmLListCp           *txBufLstCp;
2073    RlcTx               *txBuf;
2074    CmLList             *node = NULLP;
2075
2076    hashKey = (sn % RLC_TX_BUF_BIN_SIZE ); 
2077  
2078    txBufLstCp = &txBufLst[hashKey];
2079    CM_LLIST_FIRST_NODE(txBufLstCp, node);
2080    while(node)
2081    {
2082       txBuf = (RlcTx *) node->node;
2083       if(txBuf->sn == sn)
2084       {
2085          return (txBuf);
2086       }
2087       CM_LLIST_NEXT_NODE(txBufLstCp, node);
2088    }
2089    return NULLP;
2090 } /* rlcUtlStoreTxBuf */
2091 /**
2092  *
2093  * @brief Delete the DL buffer from the list
2094  *
2095  *
2096  * @Description
2097  *
2098  *   Use the SN % binSize as key and retrieve the DL buffer
2099  *  @param[in] txBufLst       List CP array
2100  *  @param[in] sn              sn of the transmitted bffer 
2101  *
2102  *
2103  *  @return  Void
2104  */
2105 Void rlcUtlDelTxBuf (CmLListCp *txBufLst,RlcTx  *txBuf,RlcCb *gCb)
2106 {
2107    uint32_t            hashKey; 
2108    CmLListCp           *txBufLstCp;
2109
2110    hashKey = (txBuf->sn % RLC_TX_BUF_BIN_SIZE ); 
2111  
2112    txBufLstCp = &txBufLst[hashKey];
2113    //DU_LOG("\nINFO  -->  RLC_DL : D-sn(%d)\n", txBuf->hdr.sn);
2114    cmLListDelFrm(txBufLstCp, &txBuf->lnk);
2115    RLC_FREE(gCb, txBuf, sizeof(RlcTx));
2116    return;
2117 } /* rlcUtlDelTxBuf */
2118
2119 /**
2120  *
2121  * @brief Remove the DL buffer from the list
2122  *
2123  *
2124  * @Description
2125  *
2126  *   Use the SN % binSize as key and retrieve the DL buffer
2127  *  @param[in] txBufLst       List CP array
2128  *  @param[in] sn              sn of the transmitted bffer 
2129  *
2130  *
2131  *  @return  Void
2132  */
2133 Void rlcUtlRemovTxBuf(CmLListCp *txBufLst,RlcTx  *txBuf,RlcCb *gCb)
2134 {
2135    uint32_t            hashKey; 
2136    CmLListCp           *txBufLstCp;
2137
2138    hashKey = (txBuf->sn % RLC_TX_BUF_BIN_SIZE ); 
2139  
2140    txBufLstCp = &txBufLst[hashKey];
2141    //DU_LOG("\nINFO  -->  RLC_DL : D-sn(%d)\n", txBuf->hdr.sn);
2142    cmLListDelFrm(txBufLstCp, &txBuf->lnk);
2143    return;
2144 } /* rlcUtlRemovTxBuf */
2145
2146
2147
2148 /********************************************************************30**
2149          End of file
2150 **********************************************************************/