1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 /********************************************************************20**
21 Name: RLC - AM DL module file
25 Desc: Source code for Acknowledged Mode Module functions such as,
27 Transmission of data/control PDUs
28 Retransmission (Feedback in terms of status)
31 Reception - reordering
32 Duplicate detection for byte segments
37 *********************************************************************21*/
38 /* header include files (.h) */
39 #include "common_def.h"
40 #include "lkw.h" /* LKW defines */
41 #include "ckw.h" /* CKW defines */
42 #include "kwu.h" /* KWU defines */
43 #include "rgu.h" /* RGU defines */
44 #include "rlc_err.h" /* Err defines */
45 #include "rlc_env.h" /* RLC environment options */
47 /* extern (.x) include files */
48 #include "lkw.x" /* LKW */
49 #include "ckw.x" /* CKW */
50 #include "kwu.x" /* KWU */
51 #include "rgu.x" /* RGU */
53 #include "rlc_utils.h" /* RLC defines */
54 #include "rlc_dl_ul_inf.h"
60 uint32_t rlcAmmStaPduList[512];
61 uint32_t rlcAmmStaPduListCnt = 0;
66 @brief RLC Acknowledged Mode Downlink Module
68 #define RLC_MODULE (RLC_DBGMASK_AM | RLC_DBGMASK_DL)
70 uint32_t rlcStatusPduCnt, rlcStatusAckCnt, rlcStatusNcnt, rlcSduSndCnt;
76 /* forward references */
77 Void rlcAmmDlHndlStatusPdu ARGS ((RlcCb *gCb,
79 RlcUdxStaPdu *pStaPdu));
81 /* public variable declarations */
83 /* This structure holds all the global structs we need. */
85 /* private variable declarations */
87 #define RLC_AM_REMOVE_HDR(_gCb, _rbCb, _retx) do { \
88 if ((_retx)->yetToConst == FALSE) \
91 SSegMsg((_retx)->seg, (_retx)->hdrSz, &_pduInfo); \
92 ODU_PUT_MSG_BUF((_retx)->seg); \
93 (_retx)->seg = _pduInfo; \
95 (_rbCb)->m.amDl.estHdrSz -= retx->hdrSz;\
98 /* private function declarations */
100 static Void rlcResegRetxPdus ARGS ((RlcCb *gCb,
102 RlcDatReq *rlcDatReq));
104 static Void rlcRemRetxPdu ARGS ((RlcCb *gCb,
108 static Void rlcAmmCreateStatusPdu ARGS ((RlcCb *gCb,
110 RlcDatReq *rlcDatReq));
112 static Void rlcAmmDlMarkPduForReTx ARGS ((RlcCb *gCb,
116 static Void rlcAmmDlProcessSuccessfulTxPdu ARGS((RlcCb *gCb,
119 KwuDatCfmInfo **datCfm));
121 static Void rlcAmmDlSetTxNextAck ARGS((RlcAmDl *amDl, RlcSn sn));
123 static Void rlcAmmDlCheckAndStopPollTmr ARGS((RlcCb *gCb,
127 static Void rlcAssembleSdus ARGS ((RlcCb *gCb,
129 RlcDatReq *rlcDatReq));
131 static bool rlcAmmDlCheckAndSetPoll ARGS ((RlcCb *gCb,
136 static Void rlcAmmCreatePdu ARGS ((RlcCb *gCb,
139 RlcDlPduInfo *pduInfo,
142 static Void rlcAmmSndStaInd ARGS ((RlcCb *gCb,RlcDlRbCb *rbCb, RlcRetx *retx));
144 static Void rlcGetNxtRetx ARGS ((RlcCb *gCb, RlcRetx **retx));
146 static Void rlcConstructAmHdr ARGS ((RlcAmHdr *amHdr,
151 static Void rlcAmmDlUpdateTxAndReTxBufForAckSn ARGS ((RlcCb *gCb,
155 KwuDatCfmInfo **datCfm));
157 static Void rlcAmmDlMoveFrmTxtoRetxBuffer ARGS ((RlcCb *gCb,
162 static Void rlcAmmDlCheckIsSDUDelivered ARGS((RlcCb *gCb,
165 KwuDatCfmInfo **datCfm));
167 static Void rlcAmmAddPduToRetxLst ARGS((RlcAmDl *amDl,
170 static Void rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer ARGS(
175 RlcDlPduInfo *pduInfo
178 static Void rlcAmmDlHndlStatus4SduByteSegInTxBuf ARGS(
182 RlcNackInfo *nackSnInfo,
184 KwuDatCfmInfo **datCfm
187 static Void rlcAmmDlUpdateTxAndReTxBufForNackSn ARGS(
191 RlcNackInfo *nackSnInfo,
193 KwuDatCfmInfo **datCfm
196 static Void RlcDlAmmGetNackSnInfoFrmNackRangeIdx ARGS(
199 RlcNackInfo *nackInfo,
201 RlcNackInfo *nackSnInfo,
205 static Void rlcAmmDlUpdTxAndReTxBufForLessThanNackSn ARGS(
212 KwuDatCfmInfo **datCfm
214 /*****************************************************************************
216 AM Module contains the following funcitons:
220 - rlcAmmDlAssembleCntrlInfo
223 - rlcAmmDlCheckAndSetPoll
229 *******************************************************************************/
230 /** @addtogroup ammode */
234 * @brief Function to send a Status Response to MAC for a dedicated logical
238 * Function calculates the current bo and send a Status response for the
239 * dedicated logical channel if the bo is non zero
241 * @param[in] gCb RLC instance control block
242 * @param[in] rbCb Radio Bearer control block
243 * @param[in] amDl AM downlink control block
247 void rlcAmmSendDedLcBoStatus(RlcCb *gCb, RlcDlRbCb *rbCb, RlcAmDl *amDl)
249 int32_t bo = rlcAmmCalculateBo(amDl);
253 rlcUtlSendDedLcBoStatus(gCb, rbCb, bo, amDl->estHdrSz, \
254 amDl->cntrlBo ?TRUE:FALSE,amDl->cntrlBo);
261 * @brief Function to check if the pollSn is acked and stop the poll timer
263 * @param[in] gCb RLC instance control block
264 * @param[in] rbCb Radio Bearer control block
265 * @param[in] mAckSn The last received ACKSN. The base modulus value should
270 static Void rlcAmmDlCheckAndStopPollTmr(RlcCb *gCb,RlcDlRbCb *rbCb,RlcSn mAckSn)
274 MODAMT(rbCb->m.amDl.pollSn, mPollSn, rbCb->m.amDl.txNextAck,rbCb->m.amDl.snModMask);
276 if (mPollSn <= mAckSn)
278 if (rlcChkTmr(gCb, (PTR)rbCb, EVENT_RLC_AMDL_POLL_RETX_TMR))
280 rlcStopTmr(gCb, (PTR)rbCb, EVENT_RLC_AMDL_POLL_RETX_TMR);
288 * @brief Function to set VT(A) and VT(MS). Calculates the VT(MS) from VT(A)
290 * @param[in,out] amDl AM downlink control block
291 * @param[in]sn Sequence number to be set as VT(A)
295 static Void rlcAmmDlSetTxNextAck(RlcAmDl *amDl,RlcSn sn)
297 amDl->txNextAck = sn;
303 * @brief Function to process a successfully re-transmitted PDU/segment
306 * Checks if the SDU has been completely delivered or not. Removes the PDU
307 * from the re-transmission buffer
309 * @param[in] gCb RLC instance control block
310 * @param[in] rbCb Downlink Radio Bearer control block
311 * @param[in] retx The PDU/segment which was successfully re-transmitted
315 static Void rlcAmmDlProcessSuccessfulReTx
320 KwuDatCfmInfo **datCfm
323 rlcAmmDlCheckIsSDUDelivered(gCb, rbCb, &(retx->sduMap), datCfm);
325 rlcRemRetxPdu(gCb, rbCb, retx);
331 * @brief Handler to Move the PDU from txBuf to re-transmission buffer
334 * This function is used to move the PDU from the txBuf to re-transmit buffer
336 * @param[in]RlcCb *gCb RLC instance control block
337 * @param[in]RlcAmDl *amDl AM Downlink Control Block
338 * @param[in]RlcRetx **retx node in the reTx buffer to be moved to, allocated by
340 * @param[in]RlcDlPduInfo *pduInfo TX PDU which needs to be moved
346 static Void rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer
351 RlcDlPduInfo *pduInfo
355 RLC_ALLOC_WC(gCb,*retx, sizeof(RlcRetx));
357 #if (ERRCLASS & ERRCLS_ADD_RES)
360 DU_LOG("\nERROR --> RLC_DL : Memory allocation failed");
363 #endif /* ERRCLASS & ERRCLS_RES */
365 (*retx)->seg = pduInfo->pdu;
366 (*retx)->segSz = pduInfo->pduSz;
367 /* MS_FIX for DL stall */
368 (*retx)->soEnd = (pduInfo->amHdr.so + pduInfo->pduSz - 1);
370 (*retx)->hdrSz = pduInfo->hdrSz;
371 (*retx)->retxCnt = 1;
372 (*retx)->yetToConst = 0;
373 (*retx)->pendingReTrans = TRUE;
375 /* initialize the list pointer to 0 instead of memset */
376 (*retx)->lstEnt.next = 0;
377 (*retx)->lstEnt.prev = 0;
378 /* copy the sdu maps */
379 RLC_MEM_CPY(&((*retx)->sduMap),
383 RLC_MEM_CPY(&((*retx)->amHdr), &pduInfo->amHdr, sizeof(RlcAmHdr));
384 rlcAmmAddPduToRetxLst(amDl, (*retx));
386 /* Update the BO appropriately */
387 amDl->retxBo += (*retx)->segSz;
388 amDl->estHdrSz += (*retx)->hdrSz;
390 gRlcStats.amRlcStats.numDLRetransPdus++;
393 } /*rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer */
396 * @brief Function to handle Status of Sdu byte segment for a nackSn
399 * This function is used to move the PDU from the txBuf to re-transmit buffer
401 * @param[in]RlcCb *gCb RLC instance control block
402 * @param[in]RlcDlRbCb *rbCb AM Downlink Control Block
403 * @param[in]RlcNackInfo *nackSnInfo Nack Information of a NACK_SN
404 * @param[in]RlcRetx **retx node in the reTx buffer to be moved to, allocated by
406 * @param[in]KwuDatCfmInfo **datCfm Ptr to datCfm
412 static Void rlcAmmDlHndlStatus4SduByteSegInTxBuf
416 RlcNackInfo *nackSnInfo,
418 KwuDatCfmInfo ** datCfm
425 txBuf = rlcUtlGetTxBuf(RLC_AMDL.txBufLst, nackSnInfo->sn);
430 lnk = txBuf->pduLst.first;
433 RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(lnk->node);
434 RlcSn pduSoEnd = (pduInfo->amHdr.so + pduInfo->sduMap.sduSz - 1);
436 /* If So of Sdu byte segment(pduInfo/seg) is < status pdu
437 soStart that means it's ACKED*/
438 if(pduSoEnd < nackSnInfo->soStart)
440 rlcAmmDlCheckIsSDUDelivered(gCb,
446 else if (pduSoEnd <= nackSnInfo->soEnd)
448 /* Move Sdu byte segment from TX buf to retx buf*/
449 rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer(gCb,
460 /* Delete node from the txBuf Pdu lst */
461 cmLListDelFrm(&txBuf->pduLst, lnk);
462 RLC_FREE(gCb, pduInfo, sizeof(RlcDlPduInfo));
465 if(!txBuf->pduLst.count)
467 /*No more Sdu byte segment are left. Hence delete txBuf*/
468 rlcUtlDelTxBuf(RLC_AMDL.txBufLst, txBuf,gCb);
475 * @brief Function to handle Status of Sdu byte segment for a nackSn
478 * This function is used to move the PDU from the txBuf to re-transmit buffer
480 * @param[in]RlcCb *gCb RLC instance control block
481 * @param[in]RlcDlRbCb *rbCb AM Downlink Control Block
482 * @param[in]RlcNackInfo *nackSnInfo Nack Information of a NACK_SN
483 * @param[in]RlcRetx **retx node in the reTx buffer to be moved to, allocated by
485 * @param[in]KwuDatCfmInfo **datCfm Ptr to datCfm
490 static Void rlcAmmDlUpdateTxAndReTxBufForNackSn
494 RlcNackInfo *nackSnInfo,
496 KwuDatCfmInfo **datCfm
502 /* Now process the NACK_SN received. Now the NACK_SN is */
503 /* either the first element of RETX or is in TX array */
504 /* To remove the remaining acks from the pdu byte segments */
506 /* if the NACK_SN is in the transmit buffer, move it to the re-
508 txBuf = rlcUtlGetTxBuf(RLC_AMDL.txBufLst, nackSnInfo->sn);
511 if(nackSnInfo->isSegment)
513 /* Go through all the AMD PDUs of a particular SN
514 and check if segment is ACKED if yes then mark succesfully sent,
515 if segment is NACKed then move it to to retx lst */
516 rlcAmmDlHndlStatus4SduByteSegInTxBuf(gCb, rbCb, nackSnInfo, &retx, datCfm);
520 /*e2= 0 and e3= 0: Move complete PDU from TX buf to retx buf*/
521 rlcAmmDlMoveFrmTxtoRetxBuffer(gCb,
527 #if (ERRCLASS & ERRCLS_ADD_RES)
531 (*retxNode) = retx->lstEnt.next;
537 /* process the pdus/segments in the re-transmit buffer with
541 retx = (RlcRetx *)((*retxNode)->node);
542 if (retx->amHdr.sn != nackSnInfo->sn)
546 if ((nackSnInfo->isSegment) &&
547 ((retx->soEnd < nackSnInfo->soStart) /*|| (retx->amHdr.so > soEnd)*/))
549 DU_LOG( "\nDEBUG --> RLC_DL : rlcHndlStaRsp: Handle ACK for byte segment, Its "
550 "sn = %d UEID:%d CELLID:%d",
554 DU_LOG("\nDEBUG --> RLC_DL : soStart and soEnd = %d, %d, UEID:%d CELLID:%d",
555 retx->amHdr.so, retx->soEnd,
559 (*retxNode) = (*retxNode)->next;
560 rlcAmmDlProcessSuccessfulReTx(gCb,rbCb, retx, datCfm);
562 else if((!nackSnInfo->isSegment) || (retx->soEnd <= nackSnInfo->soEnd))
564 /* This case covers the NACKED segments and also the case */
565 /* when there are segments and the entire SN is nacked. */
566 /* This case also covers the case of nonsegmented retx PDU*/
568 (*retxNode) = (*retxNode)->next;
569 /* Mark the retx PDU we found for further retransmission */
570 rlcAmmDlMarkPduForReTx(gCb, rbCb, retx);
574 /* If we are here that means this segment and segments after this are ACKed*/
577 } /* end of retxNode while loop*/
582 * @brief Function to get nack Sn information from nackRange index
585 * This function is used to get nack Sn information from nackRange index
587 * @param[in]RlcAmDl *amDl,
588 * @param[in]RlcUdxStaPdu *StaPdu,
589 * @param[in]RlcNackInfo *nackSnInfo,
590 * @param[in]RlcRetx *retx;
591 * @param[in]RlcSn sn,
592 * @param[in]uint8_t idx
597 static Void RlcDlAmmGetNackSnInfoFrmNackRangeIdx
600 RlcNackInfo *nackInfo,
602 RlcNackInfo *nackSnInfo,
610 nackSnInfo->isSegment = FALSE;
612 if((!nackInfo->isSegment) || (!idx && nackSnInfo->nackRange && (!nackInfo->soStart)))
614 nackSnInfo->soStart = 0;
615 nackSnInfo->soEnd = 0;
618 txBuf = rlcUtlGetTxBuf(amDl->txBufLst, nackSnInfo->sn);
621 node = txBuf->pduLst.first;
624 RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(node->node);
625 uint16_t pduSoEnd = pduInfo->amHdr.so + pduInfo->sduMap.sduSz - 1;
626 if((!idx) && (pduInfo->amHdr.so == nackInfo->soStart))
628 nackSnInfo->isSegment = TRUE;
629 nackSnInfo->soStart = pduInfo->amHdr.so;
630 nackSnInfo->soEnd = pduSoEnd;
633 else if((idx == nackSnInfo->nackRange - 1) && \
634 (pduSoEnd == nackInfo->soEnd))
636 nackSnInfo->isSegment = TRUE;
637 nackSnInfo->soStart = pduInfo->amHdr.so;
638 nackSnInfo->soEnd = pduSoEnd;
644 if(!nackSnInfo->isSegment)
648 retx = (RlcRetx *)(retxNode->node);
649 if(retx->amHdr.sn != nackSnInfo->sn)
653 if((!idx) && (retx->amHdr.so == nackInfo->soStart))
655 nackSnInfo->isSegment = TRUE;
656 nackSnInfo->soStart = retx->amHdr.so;
657 nackSnInfo->soEnd = retx->soEnd;
660 else if((idx == nackSnInfo->nackRange - 1) && \
661 (retx->soEnd == nackInfo->soEnd))
663 nackSnInfo->isSegment = TRUE;
664 nackSnInfo->soStart = retx->amHdr.so;
665 nackSnInfo->soEnd = retx->soEnd;
668 retxNode = retxNode->next;
674 * @brief Function to update transmission buffers and send confimations to
675 * PDCP on the reception of Status PDU
678 * First processes the NACKs received
679 * -# Removes the pdus which are acked by each of the NACK SN from the
680 * transmission and re-transmission buffer
681 * -# If NACKed SN in in the transmisson buffer, moves it to re-transmission
683 * -# Removes PDU segments of the NACKed SN which have been successfully
684 * received by the other end. For the un-successful ones, marks them for
686 * -# When PDUs/segments are removed from the buffer, indicates to upper
687 * layer if the SDU is completely delivered
688 * -# Removes the PDUs/segments which are acked by the ACK_SN but not by the
691 * @param[in] gCb RLC Instance control block
692 * @param[in] rbCb Downlink Radio Bearer control block
693 * @param[in] pStaPdu The decoded Status Pdu
697 Void rlcAmmDlHndlStatusPdu(RlcCb *gCb,RlcDlRbCb *rbCb,RlcUdxStaPdu *pStaPdu)
702 KwuDatCfmInfo* datCfm;
703 RlcKwuSapCb *rlckwuSap;
708 rlckwuSap = gCb->u.dlCb->rlcKwuDlSap + RLC_UI_PDCP;
709 /* store the re-transmission bo, to check if it changes due to the
710 processing of the status pdu */
711 oldRetxBo = RLC_AMDL.retxBo;
713 /* Allocate memory for datCfm Info */
714 RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
716 #if (ERRCLASS & ERRCLS_ADD_RES)
719 DU_LOG("\nERROR --> RLC_DL : Memory allocation failed UEID:%d CELLID:%d",
722 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
725 #endif /* ERRCLASS & ERRCLS_RES */
727 datCfm->numSduIds = 0;
728 datCfm->rlcId = rbCb->rlcId;
730 MODAMT(pStaPdu->ackSn, mAckSn, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
731 MODAMT(RLC_AMDL.txNext,mTxNext, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
735 DU_LOG("\nERROR --> RLC_DL : Invalid ACK SN = %d received. Current Vta =%d"
741 /* RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo)); */
742 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
746 /* Venki - stopping the poll retx timer */
747 /*Stop PollRetx Tmr */
748 rlcAmmDlCheckAndStopPollTmr(gCb, rbCb, mAckSn);
750 /* Set the first node in retx list to retxNode */
751 retxNode = RLC_AMDL.retxLst.first;
753 /* If NACK exists in control PDU */
754 if (pStaPdu->nackCnt)
757 RlcNackInfo nackSnInfo;
760 RlcSn transWinStartSn = RLC_AMDL.txNextAck; /*used to track the SN from which
761 to start processing the transmission
765 /* if any NACKs then txNextAck should be equal to the first NACK_SN*/
766 txNextAck = pStaPdu->nackInfo[0].sn;
768 rlcStatusNcnt += pStaPdu->nackCnt;
771 while (idx < pStaPdu->nackCnt)
773 nackSnInfo.isSegment = pStaPdu->nackInfo[idx].isSegment;
774 nackSnInfo.nackRange = pStaPdu->nackInfo[idx].nackRange;
775 nackSnInfo.sn = pStaPdu->nackInfo[idx].sn;
777 DU_LOG("\nDEBUG --> RLC_DL : rlcHndlStaRsp: NACK SN = %d UEID:%d CELLID:%d",
782 nackSnInfo.soStart = pStaPdu->nackInfo[idx].soStart;
783 nackSnInfo.soEnd = pStaPdu->nackInfo[idx].soEnd;
785 /* e2 is used as a boolean indicating presence of SOStart or SOEnd */
787 sn = transWinStartSn;
789 /* move transWinStartSn to nackSnInfo.sn + 1, as the pdu's before that
790 will be removed from the buffer */
791 transWinStartSn = (nackSnInfo.sn + (nackSnInfo.nackRange ?\
792 (nackSnInfo.nackRange - 1) : 0) + 1) & RLC_AMDL.snModMask;
794 /* Clear the acked SNs from the retx list */
795 MODAMT(nackSnInfo.sn, mNackSn, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
797 if ((mNackSn > mAckSn) || (mNackSn >= mTxNext))
799 /* Erroneous NACK_SN, we should raise an error towards L3 */
800 DU_LOG("\nERROR --> RLC_DL : Status Pdu is not correct UEID:%d CELLID:%d",
803 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
807 /* clear all the SNs < NACK_SN from re-transmission list */
808 rlcAmmDlUpdTxAndReTxBufForLessThanNackSn(gCb, rbCb, sn, mNackSn,
811 if(!nackSnInfo.nackRange)
813 rlcAmmDlUpdateTxAndReTxBufForNackSn(gCb, rbCb, &nackSnInfo, &retxNode, &datCfm);
814 gRlcStats.amRlcStats.numRlcAmCellNackRx++;
819 /* Update issegment, soStart, soEnd ,sn in nackSnInfo and handle
823 RlcDlAmmGetNackSnInfoFrmNackRangeIdx(&RLC_AMDL, &pStaPdu->nackInfo[idx],
824 retxNode, &nackSnInfo, idx1);
826 rlcAmmDlUpdateTxAndReTxBufForNackSn(gCb, rbCb, &nackSnInfo,
828 nackSnInfo.sn = ((nackSnInfo.sn + 1) & (RLC_AMDL.snModMask));
829 gRlcStats.amRlcStats.numRlcAmCellNackRx++;
831 }while((++idx1) < (nackSnInfo.nackRange));
835 } /* End of nackCnt while loop */
837 /* Remove the PDUs with are further acked by the ACK_SN after taking
838 care of all the NACK_SN related acknowledgments*/
839 rlcAmmDlUpdateTxAndReTxBufForAckSn(gCb,rbCb, mAckSn, retxNode, &datCfm);
841 /* Update txNextAck */
842 rlcAmmDlSetTxNextAck(&RLC_AMDL,txNextAck);
848 DU_LOG("\nDEBUG --> RLC_DL : rlcHndlStaRsp: Received All ACKS UEID:%d CELLID:%d",
852 /* For the remaining ACKs after last nackSn */
853 rlcAmmDlUpdateTxAndReTxBufForAckSn(gCb,rbCb, mAckSn, retxNode, &datCfm);
855 /* update txNextAck */
856 rlcAmmDlSetTxNextAck(&RLC_AMDL, pStaPdu->ackSn);
859 if(datCfm->numSduIds != 0)
861 if(datCfm->numSduIds > 1024)
863 DU_LOG("\nDEBUG --> RLC_DL : Sending [%u] SDU Cfms to PDCP & [%u] lost for"
866 datCfm->numSduIds-1024,
869 datCfm->numSduIds = 1024;
871 rlcSduSndCnt += datCfm->numSduIds;
872 /* Sap control block */
873 RlcUiKwuDatCfm(&rlckwuSap->pst, rlckwuSap->suId, datCfm);
877 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
880 /* Fix for memory corruption */
881 RLC_LLIST_FIRST_RETX(RLC_AMDL.retxLst, RLC_AMDL.nxtRetx);
882 /* BO update, if retransmission BO has changed. RLC_AMDL.retxBo would have
883 canged inside the above called functions */
884 if (oldRetxBo != RLC_AMDL.retxBo)
886 rlcAmmSendDedLcBoStatus(gCb, rbCb, &RLC_AMDL);
893 * @brief Function to calculate the current buffer occupancy
896 * Function to calculate the current bo depending on the control,
897 * re-transmit, transmit bo's and the state of the transmit window.
898 * If the transmit window is stalled, then the transmit bo is not
901 * @param[in] amDl AM mode donwlink control block
906 S32 rlcAmmCalculateBo(RlcAmDl *amDl)
910 /* Make sure non of the bo's are negative */
916 if (amDl->cntrlBo < 0)
921 if (amDl->retxBo < 0)
926 bo = amDl->cntrlBo + amDl->retxBo;
928 /* if window is not stalled then add the transmit bo also */
929 if (! RLC_AM_IS_TRANS_WIN_STALLED(amDl))
939 * @brief Handler to queue the SDUs received from PDCP
942 * This function is invoked by UIM to queue the SDU received from PDCP in the
943 * SDU queue of the corresponding RbCb. It also updates the BO and report the
945 * - Allocate memory for and assign received buffer to the SDU
946 * - Add SDU in the sduQ of RlcAmDl
947 * - Calculate bo with the buffer received
948 * - Accumulate bo with retransmission bo and control pdu's bo if available
949 * - Estimate the header size for the bo; Fill in StaRspInfo and send it
952 * @param[in] gCb RLC Instance control block
953 * @param[in] rbCb RB control block
954 * @param[in] mBuf Sdu to be queued
955 * @param[in] datReq Ptr to the datReq sent from PDCP
960 void rlcAmmQSdu(RlcCb *gCb, RlcDlRbCb *rbCb, Buffer *mBuf, RlcDatReqInfo *datReq)
972 RLC_ALLOC_WC(gCb,sdu, sizeof(RlcSdu));
974 #if (ERRCLASS & ERRCLS_ADD_RES)
977 DU_LOG("\nERROR --> RLC_DL : rlcAmmQSdu : Memory allocation failed UEID:%d CELLID:%d",\
978 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
981 #endif /* ERRCLASS & ERRCLS_RES */
983 RLC_UPD_L2_DL_TOT_SDU_STS(gCb,rbCb);
984 /* Discard new changes starts */
985 rlcUtlGetCurrTime(&sdu->arrTime);
986 /* Discard new changes ends */
987 /* Assign values to sdu */
988 ODU_GET_MSG_LEN(mBuf, &sdu->sduSz);
991 sdu->actSz = sdu->sduSz;
992 sdu->mode.am.sduId = datReq->sduId;
993 /* initialize values for AM mode to 0 */
994 sdu->mode.am.rcvdSz = 0;
995 sdu->mode.am.isSegmented = 0;
996 #ifndef RGL_SPECIFIC_CHANGES
1000 dlrate_kwu += sdu->sduSz;
1004 /* Update nxtTx to point to the added sdu if this is the first SDU in the
1006 if (RLC_AMDL.nxtTx == NULLP)
1008 DU_LOG("\nDEBUG --> RLC_DL : rlcAmmQSdu: Received SDU will be transmitted next \
1009 UEID:%d CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1010 RLC_AMDL.nxtTx = sdu;
1013 /* Add sdu to the sdu list */
1014 cmLListAdd2Tail(&RLC_AMDL.sduQ, &sdu->lstEnt);
1015 sdu->lstEnt.node = (PTR)sdu;
1019 if (rbCb->ueCb->tenbStats)
1021 if (RLC_AMDL.sduQ.count > rbCb->ueCb->tenbStats->stats.nonPersistent.rlc.dlMaxPktsInSduQ)
1023 rbCb->ueCb->tenbStats->stats.nonPersistent.rlc.dlMaxPktsInSduQ = RLC_AMDL.sduQ.count;
1025 rlcWinSz = RLC_AM_TRANS_WIN_SIZE(&RLC_AMDL);
1026 if (rlcWinSz > rbCb->ueCb->tenbStats->stats.nonPersistent.rlc.dlMaxWindowSz)
1028 rbCb->ueCb->tenbStats->stats.nonPersistent.rlc.dlMaxWindowSz = rlcWinSz;
1034 /* Update BO and estimate header size for the current BO */
1035 RLC_AMDL.bo = RLC_AMDL.bo + sdu->sduSz;
1036 if(RLC_AMDL.snLen == RLC_AM_CFG_12BIT_SN_LEN)
1038 RLC_AMDL.estHdrSz += 2;
1042 RLC_AMDL.estHdrSz += 3;
1044 #ifdef LTE_L2_MEAS_RLC
1045 /* Update numActUe if it is not active */
1046 if((rbCb->rbL2Cb.measOn & LKW_L2MEAS_ACT_UE) &&
1047 (rbCb->ueCb->numActRb[rbCb->qci] == 0))
1049 rbCb->ueCb->numActRb[rbCb->qci]++;
1050 gCb.rlcL2Cb.numActUe[rbCb->qci]++;
1054 if(!rlcDlUtlIsReestInProgress(rbCb))
1056 rlcAmmSendDedLcBoStatus(gCb, rbCb, &RLC_AMDL);
1064 * @brief Private handler to construct control PDU
1067 * This function sets the pduSz correctly after eliminating the fixed
1068 * header sizes and the MAC header size. It copies the already prepared
1069 * STATUS PDU to the data to be sent to MAC.
1071 * @param[in] gCb RLC instance control block
1072 * @param[in] rbCb Downlink RB control block
1073 * @param[in] kwdatReq DatReq to be sent to MAC
1078 static void rlcAmmDlAssembleCntrlInfo(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq)
1080 RlcUdxDlSapCb *sapCb;
1083 macHdrEstmt = (rbCb->m.amDl.cntrlBo < 256) ?
1084 RLC_MAC_HDR_SZ2 : RLC_MAC_HDR_SZ3;
1085 /* Eliminate fixed hdr size (14bits including ACK_SN) */
1086 if (rlcDatReq->pduSz >= (RLC_CNTRL_PDU_FIXED_HDRSZ + macHdrEstmt))
1088 /* Check the TB size whether it is sufficcient enough to fit the
1089 status Pdu into it otherwise make arrangement such that it can fit
1090 into in a way of possible NACks*/
1091 /* ccpu00135743 : fix for MAC Hdr size calc */
1092 rlcDatReq->pduSz -= macHdrEstmt;
1094 /* Create the status Pdu with the required NACKs */
1095 rlcAmmCreateStatusPdu(gCb,rbCb,rlcDatReq);
1097 sapCb = RLC_GET_DL_SAPCB(gCb, rbCb);
1098 rlcDlUdxStaProhTmrStart(&(gCb->u.dlCb->udxDlSap->pst),
1099 sapCb->suId, &(rbCb->rlcId));
1101 /* Update number of pdus in pduInfo */
1102 rlcDatReq->pduInfo.mBuf[rlcDatReq->pduInfo.numPdu] = RLC_AMDL.mBuf;
1103 rlcDatReq->pduInfo.numPdu++;
1104 gRlcStats.amRlcStats.numDLStaPduSent++;
1106 RLC_FREE_SHRABL_BUF(gCb->u.dlCb->udxDlSap->pst.region,
1107 gCb->u.dlCb->udxDlSap->pst.pool,
1109 sizeof(RlcUdxDlStaPdu));
1111 RLC_AMDL.pStaPdu = NULLP;
1112 RLC_AMDL.mBuf = NULLP;
1113 gRlcStats.amRlcStats.numDLStaPduSent++;
1120 * @brief Handler to form the PDUs with the size indicated by MAC
1123 * This function is invoked by UTL with the PDU size indicated by
1124 * MAC (after eliminating MAC header size). It assembles control
1125 * Info / data (New SDUs / Retx PDUs), check if polling needs to be
1126 * set for the data PDU and returns PDU(s) and updated BO with
1127 * estimated header size to be sent to MAC.
1129 * - Check if the control BO is available and call rlcAssembleCntrlInfo
1130 * to assemble control Information
1131 * - Check if the pdu size is available to form PDUs from retransmission
1132 * buffer and call rlcResegRetxPdus
1133 * - Check if the pdu size is available and assemble SDUs from sduQ
1134 * if exist, using rlcAssembleSdus
1135 * - PDU Info and bo are filled in and then sent to MAC from the
1138 * @param[in] gCb RLC instance control block
1139 * @param[in] rbCb RB control block
1140 * @param[in] kwdatReq DatReq to be sent to MAC
1141 * @param[in] fillCtrlPdu Indicates whether cntrl PDU to be filled or not
1146 void rlcAmmProcessSdus(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq, bool fillCtrlPdu)
1148 /* Assemble control information. fillCtrlPdu parameter check is added for CA
1149 * It is used to force cntrl Pdu scheduling on PCell. for Non CA case this
1150 * flag will always be TRUE. In CA case, for PCELL it is TRUE and for SCEll
1153 if ((RLC_AMDL.cntrlBo != 0)
1159 rlcDatReq->boRep.staPduPrsnt = TRUE;
1160 rlcDatReq->boRep.staPduBo = RLC_AMDL.cntrlBo;
1162 if (RLC_AMDL.pStaPdu != NULLP)
1164 rlcAmmDlAssembleCntrlInfo (gCb, rbCb, rlcDatReq);
1168 DU_LOG("\nERROR --> RLC_DL : rlcAmmProcessSdus: Miscomputation of control Bo. \
1169 UEID:%d CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1171 RLC_AMDL.cntrlBo = 0;
1174 /* Retransmit PDUs /portions of PDUs available in retxLst */
1175 if ((rlcDatReq->pduSz > 0) && (RLC_AMDL.nxtRetx != NULLP))
1177 rlcResegRetxPdus (gCb,rbCb, rlcDatReq);
1180 /* Assemble SDUs to form new PDUs */
1181 if ((rlcDatReq->pduSz > 0) && (RLC_AMDL.nxtTx != 0))
1183 rlcAssembleSdus(gCb,rbCb, rlcDatReq);
1186 if (RLC_AMDL.nxtRetx != NULLP)
1188 rlcDatReq->boRep.oldestSduArrTime = RLC_AMDL.nxtRetx->sduMap.sdu->arrTime;
1190 else if (RLC_AMDL.nxtTx != NULLP)
1192 rlcDatReq->boRep.oldestSduArrTime = RLC_AMDL.nxtTx->arrTime;
1195 rlcDatReq->boRep.bo = rlcAmmCalculateBo(&RLC_AMDL);
1196 rlcDatReq->boRep.staPduBo = RLC_AMDL.cntrlBo;
1198 /* Hdr estimation is moved to kwAmmCreatePDu */
1199 rlcDatReq->boRep.estHdrSz = RLC_AMDL.estHdrSz;
1201 if(rlcDatReq->pduSz > 0)
1203 gRlcStats.amRlcStats.numDLBytesUnused += rlcDatReq->pduSz;
1209 * @brief Private handler split a PDU/segment into two
1212 * Its a private function called by kwResegRetxPdu to split a segment
1213 * or a retransmit PDU into two segments splitting at the passed size.
1214 * This function is called only for those PDUs that dont have any LIs.
1216 * @param[in] gCb RLC instance control block
1217 * @param[in] rbCb RB control block
1218 * @param[in,out] crnt The PDU to be split, first part of split pdu remians
1220 * @param[out] next The second part of the split pdu
1221 * @param[in] size The size witin crnt, at which to split
1226 static void rlcSplitPdu(RlcCb *gCb, RlcDlRbCb *rbCb, RlcRetx *crnt, RlcRetx *next, uint16_t size)
1229 RlcAmDl *amDl = &RLC_AMDL;
1231 /* Set the SN for the new segment */
1232 next->amHdr.sn = crnt->amHdr.sn;
1234 /* Set the protocol specific fields appropriately */
1235 si = crnt->amHdr.si;
1236 crnt->amHdr.si = si | RLC_SI_FIRST_SEG;
1237 next->amHdr.si = si | RLC_SI_LAST_SEG;
1241 /* Update seg size */
1242 next->segSz = crnt->segSz - size;
1245 /* Set the SO fields appropriately */
1246 /* MS_FIX for DL stall */
1247 next->soEnd = crnt->soEnd;
1249 /* Set the SO fields appropriately */
1250 /* SO of next will be after the end of current */
1251 next->amHdr.so = crnt->amHdr.so + crnt->segSz;
1252 /* SO End of current will be one less than the start of next */
1253 crnt->soEnd = next->amHdr.so - 1;
1255 /* intialize the other fields in the amHdr of next to 0 */
1259 /* This macro is called for No LI case - one SDU */
1260 /* Update the size of SDU in each node's sduMap */
1261 next->sduMap.sdu = crnt->sduMap.sdu;
1262 crnt->sduMap.sduSz = crnt->segSz;
1263 next->sduMap.sduSz = next->segSz;
1265 /* Segment the payload into two parts based on the size passed */
1266 ODU_SEGMENT_MSG(crnt->seg, size, &next->seg);
1267 next->retxCnt = crnt->retxCnt;
1268 next->yetToConst = TRUE;
1269 next->pendingReTrans = crnt->pendingReTrans;
1271 /* Compute the header size and update the BO appropriately */
1272 if(amDl->snLen == RLC_AM_CFG_12BIT_SN_LEN)
1274 next->hdrSz = RLC_AM_SEG_12BIT_SN_WITH_SO_HDRSZ;
1275 if(crnt->amHdr.si == RLC_SI_FIRST_SEG)
1277 crnt->hdrSz = RLC_AM_SEG_12BIT_SN_WITHOUT_SO_HDRSZ;
1281 crnt->hdrSz = RLC_AM_SEG_12BIT_SN_WITH_SO_HDRSZ;
1286 next->hdrSz = RLC_AM_SEG_18BIT_SN_WITH_SO_HDRSZ;
1287 if(crnt->amHdr.si == RLC_SI_FIRST_SEG)
1289 crnt->hdrSz = RLC_AM_SEG_18BIT_SN_WITHOUT_SO_HDRSZ;
1293 crnt->hdrSz = RLC_AM_SEG_18BIT_SN_WITH_SO_HDRSZ;
1297 /* Add the next to the retx list */
1298 RLC_AMDL.retxLst.crnt = &crnt->lstEnt;
1299 CM_LLIST_INS_AFT_CRNT(RLC_AMDL.retxLst, next);
1300 RLC_AMDL.nxtRetx = next;
1301 amDl->estHdrSz += next->hdrSz;
1307 * @brief Private handler to retransmit PDUs or PDU segments
1310 * Its a private function called by kwProcessSdus, to create the
1311 * PDUs / its segments from the retransmission buffer available in RbCb.
1313 * - Eliminate the fixed header size and MAC header size while
1314 * forming PDUs/segments
1315 * - While pdusize is available and retxBuf has data (pdu or portion
1316 * of pdu) to be sent, form the pdu as it is if it matches with the
1317 * pdusize else segment the PDUs/portion of PDUs
1318 * - Call rlcAmmDlCheckAndSetPoll function to check and set the poll bit as
1320 * - Concatenate data and header info and fill pduInfo
1321 * - Update retxCnt and send indication to PDCP if it reaches maxRetx
1324 * @param[in] gCb RLC instance control block
1325 * @param[in] rbCb RB control block
1326 * @param[in] kwdatReq DatReq to be sent to MAC
1331 static void rlcResegRetxPdus(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq)
1335 uint8_t hdr[RLC_MAX_HDRSZ];
1341 RlcL2MeasTb *l2MeasTb;
1342 RlclchInfo *lchInfo;
1348 /* TODO : This shoould be taken care in new Trasmissions */
1349 /* This lchInfo should be retrieved there */
1350 l2MeasTb = rlcUtlGetCurMeasTb(gCb, rbCb);
1351 if (l2MeasTb == NULLP)
1355 /* TODO : This lcid needs to be searched in case of normal Tx */
1356 /* In retx here, its fine as this will be higher priority */
1357 lchInfo = &l2MeasTb->lchInfo[l2MeasTb->numLchInfo];
1358 if (l2MeasTb->numLchInfo >= RLC_MAX_ACTV_DRB)
1362 l2MeasTb->numLchInfo++;
1363 lchInfo->lcId = rbCb->lch.lChId;
1364 lchInfo->numSdus = 0;
1367 while ((rlcDatReq->pduSz > 0) && (amDl->nxtRetx != NULLP)&&
1368 (rlcDatReq->pduInfo.numPdu < RLC_MAX_PDU))
1372 retx = amDl->nxtRetx;
1373 /* kw003.201 : Add header size to seg size to determine if the */
1374 /* the segment can be completed within the allocation */
1375 /* kw003.201 - Eliminate MAC Header Size based on bites needed */
1376 tmpSz = RLC_MIN((retx->segSz + retx->hdrSz), rlcDatReq->pduSz);
1377 pduSz = (retx->segSz + retx->hdrSz);
1378 /* 5GNR_RLC_DL : length field in 5GNR MAC Hdr is 8/16 btis*/
1379 rlcDatReq->pduSz -= (tmpSz < 255) ? RLC_MAC_HDR_SZ2 : RLC_MAC_HDR_SZ3;
1381 /* kw003.201 - We should have at least one more than basic header */
1382 if (rlcDatReq->pduSz <= retx->hdrSz)
1386 rlcGetNxtRetx(gCb, &(amDl->nxtRetx));
1388 /* Send retx buf without segmentation */
1389 if (rlcDatReq->pduSz >= pduSz)
1393 DU_LOG("\nINFO --> RLC_DL : rlcResegRetxPdus: Send retx buf without segmentation "
1394 "UEID:%d CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1396 if (retx->yetToConst)
1398 /* Construct hdr with the available hdr values */
1399 rlcConstructAmHdr(&retx->amHdr, hdr, amDl->snLen, &idx);
1400 /* Add header to the pdu/segment */
1401 ODU_ADD_PRE_MSG_MULT_IN_ORDER(hdr, idx + 1, retx->seg);
1402 retx->yetToConst = FALSE;
1405 /* kw003.201 - Check if poll bit needs to be set. Retx size does */
1406 /* not affect the poll bit so it is being passed as zero */
1407 pollBit = rlcAmmDlCheckAndSetPoll(gCb,rbCb, FALSE, 0);
1408 RLC_UPD_POLL_BIT(gCb, retx, pollBit);
1410 rlcDatReq->pduSz -= pduSz;
1411 RLC_AMDL.estHdrSz -= retx->hdrSz;
1414 if (rbCb->rlcId.rbType == CM_LTE_DRB)
1417 for (sduIdx = lchInfo->numSdus ;
1418 ((numSdus < retx->numSdu) && (sduIdx < RLC_L2MEAS_SDUIDX)) ;
1419 sduIdx++, numSdus++)
1421 lchInfo->sduInfo[sduIdx].arvlTime = retx->sduMap[numSdus].sdu->arrTime;
1422 lchInfo->sduInfo[sduIdx].isRetxPdu = TRUE; /* TODO : for later use */
1424 lchInfo->numSdus += numSdus;
1432 /* Segment this pdu / portion of pdu. Insert this segment into */
1433 /* retxLst and update offset */
1434 DU_LOG("\nINFO --> RLC_DL : rlcResegRetxPdus: Segment retx buf UEID:%d CELLID:%d",
1435 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1437 /* Eliminate fixed header size if the pdu is segmented for the */
1439 if(amDl->snLen == RLC_AM_CFG_12BIT_SN_LEN)
1441 if(retx->amHdr.si < RLC_SI_LAST_SEG)
1443 rlcDatReq->pduSz -= RLC_AM_SEG_12BIT_SN_WITHOUT_SO_HDRSZ;
1447 rlcDatReq->pduSz -= RLC_AM_SEG_12BIT_SN_WITH_SO_HDRSZ;
1452 if(retx->amHdr.si < RLC_SI_LAST_SEG)
1454 rlcDatReq->pduSz -= RLC_AM_SEG_18BIT_SN_WITHOUT_SO_HDRSZ;
1458 rlcDatReq->pduSz -= RLC_AM_SEG_18BIT_SN_WITH_SO_HDRSZ;
1461 if (rlcDatReq->pduSz <= 0)
1466 /* Allocate memory for tracking a new segment */
1467 RLC_ALLOC_WC(gCb,tNode, sizeof(RlcRetx));
1468 #if (ERRCLASS & ERRCLS_ADD_RES)
1471 DU_LOG("\nERROR --> RLC_DL : rlcResegRetxPdus: Memory allocation failed UEID:%d CELLID:%d",
1472 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1475 #endif /* ERRCLASS & ERRCLS_RES */
1477 /* initialize the list pointer to 0 instead of memset */
1478 tNode->lstEnt.next = 0;
1479 tNode->lstEnt.prev = 0;
1481 /* Segment header and data */
1482 RLC_AM_REMOVE_HDR(gCb, rbCb, retx);
1484 /* kw003.201 - Split the payload and update other fields */
1485 rlcSplitPdu(gCb,rbCb, retx, tNode, rlcDatReq->pduSz);
1490 sduIdx = lchInfo->numSdus;
1491 for (numSdus = 0, sduIdx = lchInfo->numSdus;
1492 ((numSdus < retx->numSdu) && (sduIdx < RLC_L2MEAS_SDUIDX));
1493 numSdus++, sduIdx++)
1495 lchInfo->sduInfo[sduIdx].arvlTime =
1496 retx->sduMap[numSdus].sdu->arrTime;
1497 lchInfo->sduInfo[sduIdx].isRetxPdu = TRUE;
1499 lchInfo->numSdus = sduIdx;
1500 if ((retx->amHdr.lsf == 0) && (lchInfo->numSdus > 0))
1505 /* Construct hdr with the available hdr values */
1506 rlcConstructAmHdr(&retx->amHdr, hdr, amDl->snLen, &idx);
1507 ODU_ADD_PRE_MSG_MULT_IN_ORDER(hdr, idx + 1, retx->seg);
1509 retx->hdrSz = idx + 1;
1511 /* Poll bit need not be set for this seg, since its second */
1512 /* half remains in retxLst */
1513 RLC_UPD_POLL_BIT(gCb, retx, FALSE);
1514 retx->yetToConst = FALSE;
1515 rlcDatReq->pduSz = 0;
1518 rlcCpyMsg(gCb,retx->seg, &pdu);
1520 /* Update pduInfo */
1521 rlcDatReq->pduInfo.mBuf[rlcDatReq->pduInfo.numPdu] = pdu;
1522 rlcDatReq->pduInfo.numPdu++;
1523 /* kw005.201 ccpu00117318, updating the statistics */
1524 gCb->genSts.pdusRetx += 1;
1525 gRlcStats.amRlcStats.numRlcAmCellRetxPdu++;
1526 retx->soEnd = retx->amHdr.so + retx->segSz - 1;
1527 retx->pendingReTrans = FALSE;
1528 amDl->retxBo -= retx->segSz;
1531 DU_LOG("\nINFO --> RLC_DL : rlcResegRetxPdus: retxBo after resegmentation = %ld"
1532 "UEID:%d CELLID:%d", amDl->retxBo, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1534 DU_LOG("\nINFO --> RLC_DL : rlcResegRetxPdus: retxBo after resegmentation = %d "
1535 "UEID:%d CELLID:%d", amDl->retxBo, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1543 * @brief Private handler to assemble SDUs to form new data PDU(s)
1546 * Its a private function called by kwProcessSdus, to create the new data
1547 * PDUs from the SDU queue of RbCb.
1549 * - While pdusize is available, segment/concatenate SDUs or else if it
1550 * matches the pdu size form PDUs accordingly.
1551 * - RLC header and MAC header size are eliminated while forming the PDUs
1552 * - Call rlcAmmDlCheckAndSetPoll function to check and set the poll bit
1554 * - Concatenate data and header info and fill pduInfo
1556 * @param[in] rbCb RB control block
1557 * @param[in] kwdatReq DatReq to be sent to MAC
1562 static void rlcAssembleSdus(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq)
1564 Buffer *pdu = NULLP;
1565 MsgLen macGrntSz = rlcDatReq->pduSz;
1566 RlcAmDl *amDl = &RLC_AMDL;
1567 RlcSdu *sdu = amDl->nxtTx;
1569 bool nxtTxUpd = FALSE;
1570 KwuDiscSduInfo *discSduInfo = NULLP;
1571 RlcKwuSapCb* rlckwuSap = gCb->u.dlCb->rlcKwuDlSap + RLC_UI_PDCP;
1573 RlcContSduLst contSduLst; /*Contained sduLst */
1574 int32_t dataVol = amDl->bo;
1575 uint32_t *totMacGrant = &rlcDatReq->totMacGrant;
1576 RlcL2MeasDlIpTh *dlIpThPut = &rbCb->l2MeasIpThruput.dlIpTh;
1577 uint8_t *sduIdx = &dlIpThPut->lastSduIdx;
1579 bool isSduSegmented;
1582 RlclchInfo *dstLchInfo;
1583 uint32_t segSduCnt = 0;
1585 uint32_t numSdus = 0;
1586 uint32_t currSduIdx = 0;
1587 RlcL2MeasTb *l2MeasTb;
1589 /* Discard new changes starts */
1592 uint8_t numNewPdu = 0;
1593 RlcTx *txBuf = NULLP;
1594 /* Discard new changes ends */
1595 volatile uint32_t startTime = 0;
1597 uint32_t fixedHdrSz;
1599 RlcAmHdr *amHdr = NULLP;
1600 RlcDlPduInfo *pduInfo = NULLP;
1603 contSduLst.numSdus = 0;
1604 contSduLst.lcId = rbCb->lch.lChId;
1606 lchInfo.lcId = rbCb->lch.lChId;
1607 lchInfo.numSdus = 0;
1609 /* Discard new changes starts */
1610 /* Allocate memory for discSdu Info */
1611 RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region,
1612 rlckwuSap->pst.pool,
1614 sizeof(KwuDiscSduInfo));
1616 #if (ERRCLASS & ERRCLS_ADD_RES)
1617 if (discSduInfo == NULLP)
1619 DU_LOG("\nERROR --> RLC_DL : rlcAssembleSdus: Memory allocation failed UEID:%d CELLID:%d",
1620 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1623 #endif /* ERRCLASS & ERRCLS_RES */
1625 discSduInfo->numSduIds = 0;
1626 discSduInfo->rlcId = rbCb->rlcId;
1628 rlcUtlGetCurrTime(&curTime);
1629 amDl->sduQ.crnt = &sdu->lstEnt;
1630 /* Eliminate fixed header size */
1631 if(amDl->snLen == RLC_AM_CFG_12BIT_SN_LEN)
1633 fixedHdrSz = RLC_AM_PDU_12BIT_SN_HDRSZ;
1637 fixedHdrSz = RLC_AM_PDU_18BIT_SN_HDRSZ;
1640 while ((macGrntSz > fixedHdrSz) && (sdu != NULLP) &&
1641 (rlcDatReq->pduInfo.numPdu < RLC_MAX_PDU) &&
1642 (numNewPdu < RLC_MAX_NEW_DL_PDU))
1645 isSduSegmented = sdu->mode.am.isSegmented;
1647 /* Discard new changes starts */
1648 if ((sdu->mode.am.isSegmented == FALSE) && (rbCb->discTmrInt > 0) && \
1649 (rbCb->rlcId.rbType == CM_LTE_DRB))
1651 timeDiff = RLC_TIME_DIFF(curTime,sdu->arrTime);
1652 if (timeDiff > rbCb->discTmrInt)
1656 SStartTask(&startTime, PID_RLC_AMM_DISC_SDUS);
1658 RLC_UPD_L2_DL_DISC_SDU_STS(gCb,rbCb);
1659 /* TODO need to send disc cfm to pdcp */
1661 /* Update bo for boReport */
1662 amDl->bo -= sdu->sduSz;
1664 /* Get next sdu for assembly */
1665 nxtNode = sdu->lstEnt.next;
1667 /* store the info for sending it to PDCP */
1668 if(discSduInfo->numSduIds > 500)
1670 DU_LOG("\nERROR --> RLC_DL : rlcAssembleSdus: This is a big error, we shouldn't be here"
1671 "UEID:%d CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1675 discSduInfo->sduIds[discSduInfo->numSduIds] = sdu->mode.am.sduId;
1676 discSduInfo->numSduIds++;
1678 cmLListDelFrm(&amDl->sduQ, &sdu->lstEnt);
1680 rlcUtlAddSduToBeFreedQueue(gCb, sdu);
1681 rlcUtlRaiseDlCleanupEvent(gCb);
1683 /* We need to restore the crnt in the linked list which
1684 * would have become NULL in the DelFrm above */
1685 amDl->sduQ.crnt = nxtNode;
1688 sdu = (RlcSdu*)nxtNode->node;
1693 ODU_STOP_TASK(startTime, PID_RLC_AMM_DISC_SDUS);
1702 /** Check for window stall when you are creating a new PDU */
1703 if (RLC_AM_IS_TRANS_WIN_STALLED(amDl))
1705 DU_LOG("\nINFO --> RLC_DL : Window stalled \n");
1706 gRlcStats.amRlcStats.numRlcAmCellWinStall++;
1710 hdrEstmt = fixedHdrSz;
1712 if (sdu->mode.am.isSegmented)
1714 /* Adding two byte for SO */
1717 /* Eliminate MAC header */
1718 pduSz = RLC_MIN(macGrntSz, (sdu->sduSz + hdrEstmt));
1719 hdrEstmt += (pduSz < 255) ? RLC_MAC_HDR_SZ2 : RLC_MAC_HDR_SZ3;
1721 macGrntSz -= hdrEstmt;
1722 /* Check for PDU Size is large enough */
1728 /* Dont create new txBuf for segmented SDU */
1729 if (!sdu->mode.am.isSegmented)
1732 RLC_ALLOC_WC(gCb,txBuf, sizeof(RlcTx));
1734 cmLListInit(&txBuf->pduLst);
1736 #if (ERRCLASS & ERRCLS_ADD_RES)
1739 uint32_t avblMem = 0;
1740 SRegInfoShow(gCb->init.region, &avblMem);
1741 DU_LOG("\nERROR --> RLC_DL : rlcAssembleSdus: Memory allocation failed UEID:%d CELLID:%d",
1742 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1745 #endif /* ERRCLASS & ERRCLS_RES */
1747 rlcUtlStoreTxBuf(amDl->txBufLst, txBuf, amDl->txNext);
1751 txBuf = rlcUtlGetTxBuf(amDl->txBufLst, amDl->txNext);
1754 RLC_ALLOC_WC(gCb,pduInfo, sizeof(RlcDlPduInfo));
1755 #if (ERRCLASS & ERRCLS_ADD_RES)
1756 if (pduInfo == NULLP)
1758 uint32_t avblMem = 0;
1759 SRegInfoShow(gCb->init.region, &avblMem);
1760 DU_LOG("\nERROR --> RLC_DL : rlcAssembleSdus: Memory allocation failed UEID:%d CELLID:%d",
1761 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1764 #endif /* ERRCLASS & ERRCLS_RES */
1766 /*Initialize DL segment structure */
1767 pduInfo->lstEnt.next = NULLP;
1768 pduInfo->lstEnt.prev = NULLP;
1769 pduInfo->lstEnt.node = NULLP;
1771 pduInfo->pdu = NULLP;
1772 pduInfo->amHdr.dc = 0;
1773 pduInfo->amHdr.p = 0;
1774 pduInfo->amHdr.si = 0;
1775 pduInfo->amHdr.so = 0;
1777 pduInfo->amHdr.sn = amDl->txNext;
1779 /* No Segmentation scenario :
1780 * If SDU size is less than or equal to the requested PDU size
1781 * - Allocate memory and copy SDU into it.
1783 * -# Remove SDU from the Queue.
1785 if (macGrntSz >= sdu->sduSz)
1789 /* Update Framing Info */
1790 if (sdu->mode.am.isSegmented)
1792 /*5GNR RLC_DL : SN should be same for all segment of a SDU*/
1793 pduInfo->amHdr.sn = sdu->mode.am.sn;
1794 pduInfo->amHdr.si = RLC_SI_LAST_SEG; /* binary 10 */
1795 pduInfo->amHdr.so = sdu->actSz - sdu->sduSz;
1796 sdu->mode.am.isSegmented = FALSE;
1798 gRlcStats.amRlcStats.numRlcAmCellSduTx++;
1802 gRlcStats.amRlcStats.numRlcAmCellSduTx++;
1804 amHdr = &pduInfo->amHdr;
1805 /* Create PDU with hdr and data */
1806 rlcAmmCreatePdu(gCb,rbCb, amHdr, pduInfo, pdu);
1808 #ifdef LTE_L2_MEAS_RLC
1809 rlcUtlUpdSduSnMap(rbCb, sdu, rlcDatReq, TRUE);
1810 #endif /* LTE_L2_MEAS */
1812 /* kw005.201 ccpu00117318, updating the statistics */
1813 rlcUtlIncrementKwuStsSduTx(gCb->u.dlCb->rlcKwuDlSap + rbCb->k1wuSapId);
1815 if(RLC_MEAS_IS_DL_ANY_MEAS_ON_FOR_RB(gCb,rbCb))
1819 *sduIdx = dlIpThPut->lastSduIdx;
1823 RLC_GETSDUIDX(*sduIdx);
1826 rlcUtlUpdateContainedSduLst(*sduIdx, &contSduLst);
1827 rlcUtlUpdateOutStandingSduLst(dlIpThPut, *sduIdx, sdu->actSz,
1828 sdu->mode.am.sduId, newIdx);
1829 /* Update the arrival time for each SDU */
1830 if ( lchInfo.numSdus < RLC_L2MEAS_SDUIDX)
1832 lchInfo.sduInfo[lchInfo.numSdus].arvlTime = sdu->arrTime;
1837 sduMap.sduSz = sdu->sduSz;
1842 * Allocate buffer for next PDU
1843 * Remove the segmented portion from SDUQ
1844 * Calculate the hdr with LI for SDU */
1846 Buffer *remSeg = NULLP;
1849 if(RLC_MEAS_IS_DL_IP_MEAS_ON_FOR_RB(gCb,rbCb) ||
1850 RLC_MEAS_IS_DL_DELAY_MEAS_ON_FOR_RB(gCb,rbCb) ||
1851 RLC_MEAS_IS_DL_UU_LOSS_MEAS_ON_FOR_RB(gCb,rbCb) )
1853 /* If actual size of the sdu is equal to msgLen
1854 * then it is first segment of the SDU */
1855 if(sdu->actSz == sdu->sduSz)
1857 RLC_GETSDUIDX(*sduIdx);
1862 *sduIdx = dlIpThPut->lastSduIdx;
1864 rlcUtlUpdateContainedSduLst(*sduIdx, &contSduLst);
1865 rlcUtlUpdateOutStandingSduLst(dlIpThPut, *sduIdx, sdu->actSz,
1866 sdu->mode.am.sduId, newIdx);
1867 if(RLC_MEAS_IS_DL_UU_LOSS_MEAS_ON_FOR_RB(gCb,rbCb))
1869 /* If actual size of the sdu is equal to msgLen
1870 * then it is first segment of the SDU */
1871 if(sdu->actSz == sdu->sduSz)
1879 /* Segment the SDU to the size of the PDU and update header Info */
1880 ODU_SEGMENT_MSG(sdu->mBuf, macGrntSz, &remSeg);
1884 /* Update SI and SN */
1885 if (sdu->mode.am.isSegmented)
1887 /*5GNR RLC_DL : SN should be same for all segment of a SDU.
1888 * Sdu was already segmented and segmenting again*/
1889 pduInfo->amHdr.sn = sdu->mode.am.sn;
1890 pduInfo->amHdr.si = RLC_SI_MID_SEG; /* binary 11 */
1891 pduInfo->amHdr.so = sdu->actSz - sdu->sduSz;
1895 /*5GNR RLC_DL : This means it is the first*/
1896 pduInfo->amHdr.si = RLC_SI_FIRST_SEG; /* binary 01 */
1897 /*5GNR_RLC_DL : Store SN so that in sub-seqent SDU segments will use this SN*/
1898 sdu->mode.am.sn = pduInfo->amHdr.sn;
1899 pduInfo->amHdr.so = 0;
1903 amHdr = &pduInfo->amHdr;
1904 /* Create PDU with hdr and data */
1905 rlcAmmCreatePdu(gCb,rbCb, amHdr, pduInfo, pdu);
1907 sdu->mode.am.isSegmented = TRUE;
1908 sdu->sduSz -= macGrntSz;
1909 sduMap.sduSz = macGrntSz;
1911 #ifdef LTE_L2_MEAS_RLC
1912 rlcUtlUpdSduSnMap(rbCb, sdu, rlcDatReq, FALSE);
1913 #endif /* LTE_L2_MEAS */
1919 /* Update bo for boReport */
1920 amDl->bo -= sduMap.sduSz;
1924 /* Update pduInfo */
1925 rlcDatReq->pduInfo.mBuf[rlcDatReq->pduInfo.numPdu] = pdu;
1926 rlcDatReq->pduInfo.numPdu++;
1928 /* kw005.201 ccpu00117318, updating the statistics */
1929 gCb->genSts.pdusSent++;
1930 gRlcStats.amRlcStats.numRlcAmCellSduBytesTx = gRlcStats.amRlcStats.numRlcAmCellSduBytesTx + sduMap.sduSz;
1931 /* Update the RLC Tx buffer with the new PDU info */
1932 RLC_MEM_CPY(&pduInfo->sduMap, &sduMap, sizeof(RlcSduMap));
1935 macGrntSz -= sduMap.sduSz;
1936 /* Get next sdu for assembly */
1937 RLC_LLIST_NEXT_SDU(amDl->sduQ, sdu);
1939 } /*End of pduSz loop */
1941 rlcDatReq->pduSz = macGrntSz;
1942 /* Updating nxtTx to sdu in the Q */
1947 if(RLC_MEAS_IS_DL_ANY_MEAS_ON_FOR_RB(gCb,rbCb) &&
1948 (rbCb->rlcId.rbType == CM_LTE_DRB))
1952 l2MeasTb = rlcUtlGetCurMeasTb(gCb, rbCb);
1953 rlcUtlUpdateBurstSdus(gCb, rbCb, &contSduLst, dataVol, *totMacGrant);
1954 if ((lchInfo.numSdus != 0) && (l2MeasTb != NULLP))
1956 for (lchIdx = 0; ((lchIdx < l2MeasTb->numLchInfo)
1957 && (lchIdx < RLC_MAX_ACTV_DRB )); lchIdx++)
1959 if (l2MeasTb->lchInfo[lchIdx].lcId == rbCb->lch.lChId)
1961 /* Lch Info already added in Retx procedure */
1965 if (lchIdx < RLC_MAX_ACTV_DRB)
1967 if (lchIdx == l2MeasTb->numLchInfo)
1969 l2MeasTb->lchInfo[lchIdx].lcId = rbCb->lch.lChId;
1970 l2MeasTb->lchInfo[lchIdx].numSdus = 0;
1971 l2MeasTb->numLchInfo++;
1973 dstLchInfo = &l2MeasTb->lchInfo[lchIdx];
1974 currSduIdx = l2MeasTb->lchInfo[lchIdx].numSdus;
1975 while ((numSdus < lchInfo.numSdus) && (currSduIdx < RLC_L2MEAS_SDUIDX))
1977 dstLchInfo->sduInfo[currSduIdx].arvlTime = lchInfo.sduInfo[numSdus].arvlTime;
1978 dstLchInfo->sduInfo[currSduIdx].isRetxPdu = FALSE;
1982 l2MeasTb->lchInfo[lchIdx].numSdus += numSdus;
1985 /* Fix Klock warning */
1986 if(l2MeasTb != NULLP)
1988 l2MeasTb->txSegSduCnt += segSduCnt;
1991 *totMacGrant -= (oldBo - amDl->bo);
1994 if(discSduInfo->numSduIds != 0)
1996 /* Sap control block */
1997 RlcUiKwuDiscSduCfm(&rlckwuSap->pst, rlckwuSap->suId, discSduInfo);
2001 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, discSduInfo, sizeof(KwuDiscSduInfo));
2004 DU_LOG("\nDEBUG --> RLC_DL : rlcAssembleSdus: BO after assembly = %d UEID:%d CELLID:%d",
2005 amDl->bo, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
2010 * @brief Private handler to check if the poll bit needs to be set for data PDU
2013 * Its a private function called by kwProcessSdus, to checks if the
2014 * polling bit needs to be set for any RLC data PDU and updates the
2016 * - For the new PDUs, if the counters exceed the configured
2017 * pduWoPoll/byteWoPoll values, return poll bit.
2018 * - For the PDUs/portion of PDUs, if the SDU list / retxBuf is
2019 * empty, return poll bit.
2020 * - Update the pollPdu, pollByte counters and Poll_SN; start staProhTmr
2022 * @param[in] rCb RLC instance control block
2023 * @param[in] rbCb RB control block
2024 * @param[in] newPdu Flag to indicate if its a new AMD PDU.
2025 * @param[in] bufSz Length of the PDU
2028 * -# 1 - To set the poll bit
2029 * -# 0 - Poll bit is not set
2032 static bool rlcAmmDlCheckAndSetPoll(RlcCb *gCb, RlcDlRbCb *rbCb, bool newPdu, MsgLen bufSz)
2034 bool pollBit = FALSE;
2035 RlcAmDl *amDl = &(rbCb->m.amDl);
2037 /* If it's a new PDU increment PDU without poll and bytes without poll
2038 and check if they cross the configured number of poll pdu and poll bytes*/
2042 /* Patch kw004.201 */
2043 amDl->byteWoPoll += bufSz;
2045 if (((amDl->pollPdu != -1) && (amDl->pduWoPoll >= amDl->pollPdu)) ||
2046 ((amDl->pollByte != -1) && (amDl->byteWoPoll >= amDl->pollByte)))
2052 /* Check if both tx/retx buffer are empty or if tx window is stalled */
2053 if (((amDl->nxtTx == NULLP) && (amDl->nxtRetx == NULLP)) ||
2054 RLC_AM_IS_TRANS_WIN_STALLED(amDl))
2061 amDl->pduWoPoll = 0;
2062 amDl->byteWoPoll = 0;
2064 amDl->pollSn = (amDl->txNext - 1) & amDl->snModMask;
2066 DU_LOG("\nINFO --> RLC_DL : rlcAmmDlCheckAndSetPoll: Poll SN = %d UEID:%d CELLID:%d",
2067 amDl->pollSn, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
2069 /* kw005.201: Fix for poll retransmission timer.
2070 * Timer is stopped if it is already running and
2071 * then starting the timer. Fixes crs
2072 * ccpu00117216 and ccpu00118284 .
2074 if( TRUE == rlcChkTmr(gCb,(PTR)rbCb,EVENT_RLC_AMDL_POLL_RETX_TMR) )
2076 rlcStopTmr(gCb,(PTR)rbCb, EVENT_RLC_AMDL_POLL_RETX_TMR);
2079 rlcStartTmr(gCb,(PTR)rbCb, EVENT_RLC_AMDL_POLL_RETX_TMR);
2086 * @brief Private handler to create AMD PDU
2089 * This function constructs header and concatenate it with the data for
2090 * the PDU. It also updates the txBuf with the created PDU.
2092 * @param[in] gCB RLC instance control block
2093 * @param[in] rbCb Downlink RB control block
2094 * @param[in] amHdr AM header
2095 * @param[in] RlcDlPduInfo Pointer to PduInfo
2096 * @param[in] pdu PDU buffer
2101 static void rlcAmmCreatePdu(RlcCb *gCb, RlcDlRbCb *rbCb, RlcAmHdr *amHdr,
2102 RlcDlPduInfo *pduInfo, Buffer *pdu)
2104 uint8_t hdr[RLC_MAX_HDRSZ];
2108 RlcAmDl *amDl = &(rbCb->m.amDl);
2111 amHdr->sn = amDl->txNext;
2112 /*5GNR RLC_DL : Increment txNext only if no segmentation of it is a last segment */
2113 if((!amHdr->si) || (amHdr->si == RLC_SI_LAST_SEG))
2115 amDl->txNext = (amDl->txNext + 1) & amDl->snModMask;
2118 /* Update hdr Info */
2119 ODU_GET_MSG_LEN(pdu, &pduSz);
2121 /* passing newPDU = TRUE*/
2122 amHdr->p = rlcAmmDlCheckAndSetPoll(gCb,rbCb, TRUE, pduSz);
2124 /* Construct header with the available hdr Info, set isSegment to FALSE */
2125 rlcConstructAmHdr(amHdr, hdr, amDl->snLen, &idx);
2127 /* Concatenate hdr and data */
2128 ODU_ADD_PRE_MSG_MULT_IN_ORDER(hdr, idx+1, pdu);
2130 txBuf = rlcUtlGetTxBuf(amDl->txBufLst, amHdr->sn);
2131 rlcCpyMsg(gCb,pdu,&(pduInfo->pdu));
2132 pduInfo->pduSz = pduSz;
2133 pduInfo->hdrSz = idx+1;
2135 /*Update estHdrSz. deduct current hdrSz */
2136 amDl->estHdrSz -= pduInfo->hdrSz;
2137 /* Reestimate estHdrSz for mid and last seg */
2140 amDl->estHdrSz += ((amHdr->si == RLC_SI_MID_SEG)? pduInfo->hdrSz : (pduInfo->hdrSz + 2));
2143 cmLListAdd2Tail(&txBuf->pduLst, &pduInfo->lstEnt);
2144 pduInfo->lstEnt.node = (PTR)pduInfo;
2146 gCb->genSts.bytesSent += pduSz;
2152 * @brief Private handler to remove the retx PDU from the rbCb
2155 * This function releases a retx PDU stored on DL portion of rbCb.
2156 * It also updates the BO if wtForAck flag is not set which implies
2157 * that it is not sent out yet.
2159 * @param[in] gCb RLC instance control block
2160 * @param[in] retx retransmit PDU to be removed
2161 * @param[in] rbCb Radio Bearer Control Block
2166 static Void rlcRemRetxPdu(RlcCb *gCb,RlcDlRbCb *rbCb,RlcRetx *retx)
2168 cmLListDelFrm(&RLC_AMDL.retxLst, &retx->lstEnt);
2170 if( RLC_AMDL.retxLst.count == 0)
2172 RLC_AMDL.nxtRetx = NULLP;
2175 if(retx->pendingReTrans == TRUE)
2177 RLC_AMDL.retxBo -= retx->segSz;
2178 RLC_AMDL.estHdrSz -= retx->hdrSz;
2181 rlcUtlAddReTxPduToBeFreedQueue(gCb, retx);
2182 rlcUtlRaiseDlCleanupEvent(gCb);
2188 * @brief Private handler to mark a retx PDU for further retransmission
2191 * This function sets a retx PDU that has not been ACKed in the
2192 * received Status PDU for futher retransmission. If the retransmission
2193 * limit is reached, it releases the retx PDU and informs the higher
2194 * layers about the same.
2196 * @param[in] gCb RLC instance control block
2197 * @param[in] retx retransmit PDU to be removed
2198 * @param[in] rbCb Radio Bearer Control Block
2203 static Void rlcAmmDlMarkPduForReTx(RlcCb *gCb,RlcDlRbCb *rbCb,RlcRetx *retx)
2205 if (RLC_AMDL.maxReTxReached == TRUE)
2210 if(retx->pendingReTrans == FALSE)
2212 retx->pendingReTrans = TRUE;
2215 RLC_AMDL.retxBo += retx->segSz;
2216 RLC_AMDL.estHdrSz += retx->hdrSz;
2218 if (retx->retxCnt > RLC_AMDL.maxRetx)
2220 /* RLC_DL_MAX_RETX fix */
2221 /* Marking the RB stalled for DL scheduling. This is to avoid unnecessary */
2222 /* preparation of RLC PDUs and adding the same to Tx Buffer */
2223 /* This condition is to avoid sending StaIndication more than once */
2224 if (TRUE != rbCb->m.amDl.maxReTxReached)
2226 rbCb->m.amDl.maxReTxReached = TRUE;
2227 rbCb->m.amDl.bo = 0;
2228 rbCb->m.amDl.cntrlBo = 0;
2229 rbCb->m.amDl.retxBo = 0;
2230 /* Sending BO update to SCH */
2231 rlcUtlSendDedLcBoStatus(gCb, rbCb, 0,0,0,0);
2232 rlcAmmSndStaInd(gCb, rbCb, retx);
2233 gRlcStats.amRlcStats.numDLMaxRetx++;
2235 /* As per 38.322, RLC on reaching maxRetxThreshold in AM mode following needs to be done: */
2236 /* if RETX_COUNT = maxRetxThreshold: */
2237 /* - indicate to upper layers that max retransmission has been reached. "*/
2238 BuildAndSendRlcMaxRetransIndToDu(rbCb->rlcId.cellId, rbCb->rlcId.ueId, rbCb->lch.lChId, rbCb->lch.lChType);
2241 rlcRemRetxPdu(gCb,rbCb, retx);
2247 if (RLC_AMDL.nxtRetx == NULLP)
2249 RLC_AMDL.nxtRetx = retx;
2252 gRlcStats.amRlcStats.numDLRetransPdus++;
2260 * @brief Private handler to check if SDU is completely deliverd and
2261 * send higher layers data confirmation
2264 * This function sends higher layers data confirmation for SDUs which
2265 * have been successfully delivered to the peer RLC entity.
2267 * @param[in] gCb RLC instance control block
2268 * @param[in] rbCb Radio Bearer Control Block
2269 * @param[in] sduLst List of SDUs that were part of the PDU
2270 * @param[in] numSdu Number of SDUs in the list
2275 static Void rlcAmmDlCheckIsSDUDelivered
2280 KwuDatCfmInfo **datCfm
2287 sdu->mode.am.rcvdSz += sduMap->sduSz;
2289 /* send a dat cfm if all the bytes of the sdu have been received */
2290 if (sdu->mode.am.rcvdSz == sdu->actSz)
2292 /* Send DatCfm for this sdu */
2293 if((*datCfm)->numSduIds < KWU_MAX_DAT_CFM)
2295 (*datCfm)->sduIds[(*datCfm)->numSduIds++] = sdu->mode.am.sduId;
2299 /* This is an error that should never happen, we should resize
2300 * the #define to a larger value or check why we need to
2301 * send so many confirms in one go
2302 * Confrims to PDCP are being dropped in this case
2304 RlcKwuSapCb *rlckwuSap;
2305 rlckwuSap = gCb->u.dlCb->rlcKwuDlSap + RLC_UI_PDCP;
2306 RlcUiKwuDatCfm(&rlckwuSap->pst, rlckwuSap->suId, *datCfm);
2308 RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region, rlckwuSap->pst.pool, *datCfm, sizeof(KwuDatCfmInfo));
2310 #if (ERRCLASS & ERRCLS_ADD_RES)
2311 if (*datCfm == NULLP)
2313 DU_LOG("\nERROR --> RLC_DL : Memory allocation failed UEID:%d CELLID:%d",
2315 rbCb->rlcId.cellId);
2318 #endif /* ERRCLASS & ERRCLS_RES */
2320 (*datCfm)->numSduIds = 0;
2321 (*datCfm)->rlcId = rbCb->rlcId;
2322 /* ccpu00135618: say total 1026 sduIds to copy the 1025 sduId after
2323 * new allocation of datCfm */
2324 (*datCfm)->sduIds[(*datCfm)->numSduIds++] = sdu->mode.am.sduId;
2327 /* Remove SDU from the sduQ */
2328 cmLListDelFrm(&RLC_AMDL.sduQ, &sdu->lstEnt);
2329 rlcUtlAddSduToBeFreedQueue(gCb, sdu);
2330 rlcUtlRaiseDlCleanupEvent(gCb);
2337 * @brief Private handler to mark a PDU successful.
2340 * This function is called when we receive a STATUS pdu that marks
2341 * a PDU as successful. It releases the PDU from RLC entity and
2342 * informs PDCP of successful SDUs delivered as a result of this PDU.
2344 * @param[in] gCb RLC instance control block
2345 * @param[in] rbCb Radio Bearer Control Block
2346 * @param[in] sn SN that is successfully delivered to the peer
2351 static Void rlcAmmDlProcessSuccessfulTxPdu
2356 KwuDatCfmInfo **datCfm
2361 RlcTx *txBuf = rlcUtlGetTxBuf(RLC_AMDL.txBufLst, sn);
2367 pduNode = txBuf->pduLst.first;
2370 RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(pduNode->node);
2371 rlcAmmDlCheckIsSDUDelivered(gCb,
2375 pduNode = pduNode->next;
2378 rlcUtlAddTxPduToBeFreedQueue(gCb, txBuf);
2379 rlcUtlRaiseDlCleanupEvent(gCb);
2380 /* so that it is not processed again */
2381 rlcUtlRemovTxBuf(RLC_AMDL.txBufLst, txBuf, gCb);
2387 * @brief Handler to send Status Indication to PDCP
2390 * This function is used to send status indication to PDCP when the
2391 * maximum retransmission threshold value is reached for a PDU.
2393 * @param[in] gCb RLC instance control block
2394 * @param[in] rbCb RB control block
2395 * @param[in] retx The PDU/segment that failed max re-transmissions
2400 static Void rlcAmmSndStaInd
2407 KwuStaIndInfo *staInd;
2408 RlcKwuSapCb *rlckwuSap;
2410 /* Sap control block */
2411 rlckwuSap = gCb->u.dlCb->rlcKwuDlSap + RLC_UI_PDCP;
2413 /* Allocate memory for staInd Info */
2414 RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region, rlckwuSap->pst.pool, staInd, sizeof(KwuStaIndInfo));
2416 #if (ERRCLASS & ERRCLS_ADD_RES)
2417 if (staInd == NULLP)
2419 DU_LOG("\nERROR --> RLC_DL : Memory allocation failed UEID:%d CELLID:%d",
2421 rbCb->rlcId.cellId);
2424 #endif /* ERRCLASS & ERRCLS_RES */
2426 /* Fill staInd Info */
2427 RLC_MEM_CPY(&staInd->rlcId, &rbCb->rlcId, sizeof(CmLteRlcId));
2430 staInd->sduId[0] = retx->sduMap.sdu->mode.am.sduId;
2434 RlcUiKwuStaInd(&rlckwuSap->pst, rlckwuSap->suId, staInd);
2435 #endif /* KW_PDCP */
2441 * @brief Handler to get the next node to be retransmitted from retxLst
2444 * This function is used to get the next node to be retransmitted
2447 * @param[in] gCb RLC instance control block
2448 * @param[in] retx The PDU/segment after which to find a node to be
2454 static void rlcGetNxtRetx(RlcCb *gCb, RlcRetx **retx)
2460 tNode = &((*retx)->lstEnt);
2461 tNode = tNode->next;
2465 *retx = (RlcRetx *)tNode->node;
2472 }while((*retx)->pendingReTrans == FALSE);
2478 * @brief Handler to process the re-establishment request received from UIM
2480 * @param[in] gCb RLC instance control block
2481 * @param[in] rlcId Identity of the RB in the UE/Cell for which
2482 * re-establishment is to be done
2483 * @param[in] rbCb Downlink RB control block (rbCb is freed in this
2489 Void rlcAmmDlReEstablish
2496 /* create a new AM DL RB, reset it and replace in the UeCb*/
2501 RLC_ALLOC(gCb, resetRb, sizeof(RlcDlRbCb));
2503 /* ccpu00135170 Removing KLOCK warning */
2504 if(resetRb == NULLP)
2509 RLC_MEM_CPY(resetRb, rbCb, sizeof(RlcDlRbCb));
2510 RLC_MEM_SET(&resetRb->m.amDl, 0 , sizeof(RlcAmDl));
2512 /* AGHOSH changes start */
2513 /* restore the old AM values */
2514 newAmDl = &resetRb->m.amDl;
2515 oldAmDl = &rbCb->m.amDl;
2517 newAmDl->pollPdu = oldAmDl->pollPdu;
2518 newAmDl->pollByte = oldAmDl->pollByte;
2519 newAmDl->maxRetx = oldAmDl->maxRetx;
2520 newAmDl->snLen = oldAmDl->snLen;
2521 newAmDl->snModMask = oldAmDl->snModMask;
2522 newAmDl->pollRetxTmrInt = oldAmDl->pollRetxTmrInt;
2523 rbCb->boUnRprtdCnt = (uint32_t)0;
2524 rbCb->lastRprtdBoToMac = (uint32_t)0;
2525 cmInitTimers(&(resetRb->m.amDl.pollRetxTmr), 1);
2526 /* AGHOSH changes end */
2528 if (ROK != rlcDbmFetchDlUeCb(gCb,rlcId.ueId, rlcId.cellId, &ueCb))
2530 DU_LOG("\nERROR --> RLC_DL : UeId [%d]: UeCb not found RBID;%d",
2536 if(rlcId.rbType == CM_LTE_SRB)
2538 ueCb->srbCb[rlcId.rbId] = resetRb;
2542 ueCb->drbCb[rlcId.rbId] = resetRb;
2544 /* update into the logical channel array also */
2545 ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = resetRb;
2547 if((resetRb->rlcId.rbType == CM_LTE_SRB)
2548 &&(resetRb->rlcId.rbId == 1))
2550 /* To stop the traffic on SRB2 and other DRBs*/
2551 rlcDlUtlSetReestInProgressForAllRBs(gCb, ueCb);
2555 rlcDlUtlSetReestInProgressForRB(gCb, resetRb);
2558 /* allocate the TX array again */
2562 resetRb->m.amDl.txBufLst,
2563 (RLC_TX_BUF_BIN_SIZE * sizeof(CmLListCp)));
2564 for(hashIndex = 0; hashIndex < RLC_TX_BUF_BIN_SIZE; hashIndex++)
2566 cmLListInit(&(resetRb->m.amDl.txBufLst[hashIndex]));
2569 /* send the old rb of deletion */
2570 rlcAmmFreeDlRbCb(gCb,rbCb);
2573 /* TODO: for now we are re-settting the re-establishment flag here
2574 this needs to be fixed
2575 There should be a proper intreface to resume the RBs */
2576 if(rlcId.rbType == CM_LTE_SRB)
2578 rlcDlUtlResetReestInProgress(ueCb->srbCb[rlcId.rbId]);
2582 rlcDlUtlResetReestInProgress(ueCb->drbCb[rlcId.rbId]);
2589 * @brief Handler to discard a SDU.
2592 * This function is used to discard a SDU after receiving
2593 * the Discard Request from UIM. The SDU is discarded if its
2594 * available and is not mapped to any PDU yet.
2596 * @param[in] gCb RLC instance control block
2597 * @param[in] rbCb RB control block
2598 * @param[in] sduId Sdu ID of the SDU to be discarded
2601 * -# ROK In case of successful discard
2602 * -# RFAILED In case the SDU is not found or already mapped
2604 S16 rlcAmmDiscSdu(RlcCb *gCb,RlcDlRbCb *rbCb,uint32_t sduId )
2610 * @brief Handler for Poll retransmit timer expiry
2613 * This function is used to handle events upon expiry of Poll
2616 * @param[in] gCb RLC instance control block
2617 * @param[in] rbCb Downlink RB control block
2621 Void rlcAmmPollRetxTmrExp(RlcCb *gCb,RlcDlRbCb *rbCb)
2624 RlcAmDl *amDl = &(rbCb->m.amDl);
2628 /* kw003.201 - Correcting the logic for determmining whether to do */
2629 /* any transmission of PDU. As per the spec section */
2630 /* 5.2.2.3, if there is any to transmit or retransmit, */
2631 /* do nothing. Else, pick up the VT(S) -1 for retx */
2632 /* We have nothing to transmit if window is stalled or */
2633 /* there are no SDUs to be transmitted or if there are */
2634 /* PDUs to be retransmitted. */
2635 if(CM_LTE_SRB == rbCb->rlcId.rbType)
2637 gRlcStats.amRlcStats.numDLPollTimerExpiresSrb++;
2641 gRlcStats.amRlcStats.numDLPollTimerExpiresDrb++;
2644 if (((amDl->nxtTx == NULLP) && (amDl->nxtRetx == NULLP)) ||
2645 RLC_AM_IS_TRANS_WIN_STALLED(amDl))
2647 sn = (amDl->txNext - 1) & amDl->snModMask;
2648 txBuf = rlcUtlGetTxBuf(amDl->txBufLst, sn);
2652 rlcAmmDlMoveFrmTxtoRetxBuffer(gCb,amDl, &retx, sn);
2654 if (RLC_AMDL.nxtRetx == NULLP)
2656 RLC_AMDL.nxtRetx = retx;
2659 rlcAmmSendDedLcBoStatus(gCb, rbCb, &RLC_AMDL);
2662 /* Get the last node in retxLst */
2663 RLC_LLIST_LAST_RETX(amDl->retxLst, retx);
2665 /* Unset wtForAck flag for the NACK PDUs */
2668 rlcAmmDlMarkPduForReTx(gCb, rbCb, retx);
2669 rlcAmmSendDedLcBoStatus(gCb, rbCb, &RLC_AMDL);
2677 * @brief Handler to update Acks for the remaining PDUs after the last accessed
2681 * This function is used to handle ACKs for the PDUs remaining after the
2682 * last accessed NACK PDU, It updates the txBuf/retxBuf for the ACKs and
2683 * sends DatCfm to PDCP for the same.
2685 * @param[in] gCb RLC instance control block
2686 * @param[in] rbCb Downlink Radio Bearer control block
2687 * @param[in] mAckSn The ACK SN after doing the base modulus
2688 * @param[in] rextNode Next node in the re-transmission buffer
2694 static Void rlcAmmDlUpdateTxAndReTxBufForAckSn
2700 KwuDatCfmInfo **datCfm
2708 /* Remove pdus/segs from retxLst */
2711 retx = (RlcRetx *)(retxNode->node);
2712 retxNode = retxNode->next;
2713 MODAMT(retx->amHdr.sn, mSn, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
2716 rlcAmmDlProcessSuccessfulReTx(gCb,rbCb, retx, datCfm);
2720 /* For the remaining; pdus not acknowldeged by the NACK_SN but being
2721 acknowledged by the ACK_SN*/
2722 /* start from the starting of the transmission window and remove till just
2724 mSn = 0; /* same as MODAMT(RLC_AMDL.txNextAck, mSn, RLC_AMDL.txNextAck);*/
2725 sn = RLC_AMDL.txNextAck;
2728 txBuf = rlcUtlGetTxBuf(RLC_AMDL.txBufLst, sn);
2732 DU_LOG("\nDEBUG --> RLC_DL : rlcAmmDlUpdateTxAndReTxBufForAckSn: ACK for PDU "
2733 "with sn = %d UEID:%d CELLID:%d",
2736 rbCb->rlcId.cellId);
2738 rlcAmmDlProcessSuccessfulTxPdu(gCb,rbCb, sn, datCfm);
2741 sn = (sn + 1) & RLC_AMDL.snModMask;
2742 MODAMT(sn, mSn, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
2749 * @brief Handler to update Acks for the remaining PDUs after the last accessed
2753 * This function is used to handle ACKs for the PDUs remaining after the
2754 * last accessed NACK PDU, It updates the txBuf/retxBuf for the ACKs and
2755 * sends DatCfm to PDCP for the same.
2757 * @param[in] gCb RLC instance control block
2758 * @param[in] rbCb Downlink Radio Bearer control block
2759 * @param[in] mAckSn The ACK SN after doing the base modulus
2760 * @param[in] rextNode Next node in the re-transmission buffer
2765 static Void rlcAmmDlUpdTxAndReTxBufForLessThanNackSn
2772 KwuDatCfmInfo **datCfm
2781 retx = (RlcRetx *)((*retxNode)->node);
2782 MODAMT(retx->amHdr.sn, mSn, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
2785 (*retxNode) = (*retxNode)->next;
2786 rlcAmmDlProcessSuccessfulReTx(gCb,rbCb, retx, datCfm);
2794 /* Remove all pdus with SN < NACK_SN from the transmission buffer */
2795 MODAMT(sn, mSn, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
2796 while (mSn < mNackSn)
2798 /* this if check seems redundant,why should mSn ever be mTxSn
2799 (which actually is VT(A) */
2800 txBuf = rlcUtlGetTxBuf(RLC_AMDL.txBufLst, sn);
2801 if ((txBuf != NULLP))
2803 DU_LOG("\nDEBUG --> RLC_DL : rlcHndlStaRsp: Handle ACK (sn = %d) UEID:%d CELLID:%d",
2806 rbCb->rlcId.cellId);
2808 /* Remove pdus from txBuf */
2809 rlcAmmDlProcessSuccessfulTxPdu(gCb,rbCb, sn, datCfm);
2812 sn = (sn + 1) & RLC_AMDL.snModMask;
2813 MODAMT(sn, mSn, RLC_AMDL.txNextAck,RLC_AMDL.snModMask);
2821 * @brief Handler to form construct AM header
2824 * This function is used to construct am header with the available header
2827 * @param[in] gCb RLC instance control block
2828 * @param[in] amHdr AM Header
2829 * @param[in] isSeg Check for Segmentation of PDU
2830 * @param[in] hdr Header field
2831 * @param[in] idx Index
2836 static void rlcConstructAmHdr(RlcAmHdr *amHdr, uint8_t *hdr, uint8_t snLen, uint16_t *idx)
2839 hdr[0] = RLC_DATA_BITMASK;
2841 hdr[0] = hdr[0] | (amHdr->p << 6);
2842 hdr[0] = hdr[0] | ((amHdr->si & 0x3) << 4);
2843 if(snLen == RLC_AM_CFG_12BIT_SN_LEN)
2845 hdr[0] = hdr[0] | (uint8_t)((amHdr->sn & 0xF00) >> 8);
2846 hdr[1] = (uint8_t)(amHdr->sn & 0x0FF);
2851 hdr[0] = hdr[0] | (uint8_t)((amHdr->sn & 0x30000) >> 16);
2852 hdr[1] = (uint8_t)((amHdr->sn & 0xFF00) >> 8);
2854 hdr[2] = (uint8_t)(amHdr->sn & 0xFF);
2858 if ((amHdr->si == RLC_SI_MID_SEG) || (amHdr->si == RLC_SI_LAST_SEG))
2861 hdr[(*idx)] = (uint8_t)((amHdr->so & 0xFF00)>> 8);
2863 hdr[(*idx)] = (uint8_t)(amHdr->so & 0xFF);
2870 * @brief This function adds a retx PDU to list of retx PDUs
2873 * kw003.201 - Poll expiry may cause an SN to be added to retx
2874 * out of sequence and hence all additions to retx
2875 * must validate that they are added in sequence
2877 * @param[in] amDl AM Downlink Control Block
2878 * @param[in] retx Retransmit PDU
2883 static Void rlcAmmAddPduToRetxLst(RlcAmDl *amDl,RlcRetx *retx)
2890 node = amDl->retxLst.last;
2891 MODAMT(retx->amHdr.sn, retxMSn, amDl->txNextAck,amDl->snModMask);
2892 while(node != NULLP)
2894 tRetx = (RlcRetx *)(node->node);
2895 MODAMT(tRetx->amHdr.sn, tMSn, amDl->txNextAck,amDl->snModMask);
2907 amDl->retxLst.crnt = node;
2908 cmLListInsAfterCrnt(&amDl->retxLst, &retx->lstEnt);
2909 retx->lstEnt.node = (PTR)retx;
2913 amDl->retxLst.crnt = amDl->retxLst.first;
2914 cmLListInsCrnt(&amDl->retxLst, &retx->lstEnt);
2915 retx->lstEnt.node = (PTR)retx;
2918 if (amDl->nxtRetx == NULLP)
2920 amDl->nxtRetx = retx;
2927 * @brief Handler to Move the PDU from txBuf to re-transmission buffer
2930 * This function is used to move the PDU from the txBuf to re-transmit buffer
2932 * @param[in] gCb RLC instance control block
2933 * @param[in] amDl AM Downlink Control Block
2934 * @param[in] retx node in the reTx buffer to be moved to, allocated by
2936 * @param[in] sn SN in the tx buffer which needs to be moved
2942 static Void rlcAmmDlMoveFrmTxtoRetxBuffer
2950 RlcTx* txBuf = rlcUtlGetTxBuf(amDl->txBufLst, sn);
2956 while(txBuf->pduLst.first)
2958 RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(txBuf->pduLst.first->node);
2960 /* Move Sdu byte segment from TX buf to retx buf*/
2961 rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer(gCb,
2966 /* Delete node from the txBuf Pdu lst */
2967 cmLListDelFrm(&txBuf->pduLst, txBuf->pduLst.first);
2968 RLC_FREE(gCb, pduInfo, sizeof(RlcDlPduInfo));
2970 /* Remove PDU from txBuf */
2971 rlcUtlDelTxBuf(amDl->txBufLst, txBuf,gCb);
2980 * function to free/release the Acknowledged mode RBCB buffers
2983 * This primitive Frees the Acknowledged Mode RbCb transmission Buffer,
2984 * retransmission Buffer and reciption Buffers
2986 * @param [in] gCb - RLC instance control block
2987 * @param [in] rbCb - Downlink RB Control Block
2991 Void rlcAmmFreeDlRbCb(RlcCb *gCb,RlcDlRbCb *rbCb)
2993 /* stop the re-transmission timer */
2994 if(TRUE == rlcChkTmr(gCb,(PTR)rbCb,EVENT_RLC_AMDL_POLL_RETX_TMR))
2996 rlcStopTmr(gCb,(PTR)rbCb, EVENT_RLC_AMDL_POLL_RETX_TMR);
2999 /* store the entire Rb pointer */
3000 rbCb->rlsLnk.node = (PTR)rbCb;
3001 cmLListAdd2Tail(&gCb->u.dlCb->toBeFreed.rbLst, &rbCb->rlsLnk);
3004 cmLListCatLList(&(gCb->u.dlCb->toBeFreed.sduLst),&(rbCb->m.amDl.sduQ));
3006 rlcUtlRaiseDlCleanupEvent(gCb);
3012 * @brief Handler to create STATUS Pdu
3015 * This function is used to create status pdu
3017 * @param[in] gCb RLC instance control block
3018 * @param[in] rbCb Downlink RB control block
3019 * @param[in] rlcDatReq The data to be passed to MAC
3024 static void rlcAmmCreateStatusPdu(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq)
3026 RlcSn sn; /* sequence number */
3027 RlcSn ack_sn; /* Ack sequence number */
3028 Buffer *mBuf; /* control pdu buffer */
3029 MsgLen cntrlPduSz; /* control pdu size */
3030 uint8_t cntrlPdu[RLC_MAX_CNTRL_FIELDS]; /* control pdu to be added to mBuf */
3031 RlcUdxDlStaPdu *pStaPdu;
3032 uint16_t bytesToEncode = 0; /* bytes required to encode the STATUS PDU */
3033 uint16_t encIdx = 0;
3034 uint16_t prevEncIdx = 0;
3035 RlcNackInfo *rlcNackInfo;
3038 pStaPdu = RLC_AMDL.pStaPdu;
3047 /* ACK SN Field will be set in the end based on available Grant */
3049 encIdx = bytesToEncode = 3; /* Num Octets before NACK SN info encoding*/
3051 ack_sn = pStaPdu->ackSn;
3053 if (rbCb->m.amDl.snLen == RLC_AM_CFG_12BIT_SN_LEN)
3056 /* If alteast one NACK SN Info then set the E1 field */
3057 if (pStaPdu->nackCount)
3067 for(nkCnt = 0;nkCnt < pStaPdu->nackCount; nkCnt++)
3069 sn = pStaPdu->nackInfo[nkCnt].sn;
3071 rlcNackInfo = &(pStaPdu->nackInfo[nkCnt]);
3073 bytesToEncode += 2; /* 2 Octets for NACK SN */
3075 /* Check if E2 : isSegment is set */
3076 if (rlcNackInfo->isSegment)
3078 bytesToEncode += 4; /* 4 Octets: SOstart, SOend */
3081 /* Check if E3 : nackRange is set */
3082 if (rlcNackInfo->nackRange)
3084 bytesToEncode += 1; /* 1 Octet: NACK range */
3087 /* Check if this NACK info can be accomodated in the Grant */
3088 if( rlcDatReq->pduSz >= bytesToEncode)
3090 /* If there is a NACK SN before this then set its
3094 /* NACKSN E1 E2 E3 R */
3095 cntrlPdu[prevEncIdx + 1] |= 0x8;
3098 /* 12 BIT Nack SN encode */
3099 cntrlPdu[encIdx] = (sn & 0xFF0) >> 4;
3102 cntrlPdu[encIdx + 1] = (sn & 0xF) << 4;
3104 if (rlcNackInfo->isSegment)
3107 cntrlPdu[encIdx + 1] |= 0x4;
3110 /* Add soStart and soEnd */
3112 cntrlPdu[encIdx + 2] = (rlcNackInfo->soStart) >> 8;
3113 cntrlPdu[encIdx + 3] = rlcNackInfo->soStart & 0xFF;
3116 cntrlPdu[encIdx + 4] = (rlcNackInfo->soEnd) >> 8;
3117 cntrlPdu[encIdx + 5] = rlcNackInfo->soEnd & 0xFF;
3120 if (rlcNackInfo->nackRange)
3123 cntrlPdu[encIdx + 1] |= 0x2;
3124 if(rlcNackInfo->isSegment)
3126 cntrlPdu[encIdx + 6] = rlcNackInfo->nackRange;
3130 cntrlPdu[encIdx + 2] = rlcNackInfo->nackRange;
3134 gRlcStats.amRlcStats.numDLNacksInStaPdu++;
3136 /* Set ACK SN now */
3139 ack_sn = rlcNackInfo->sn;
3141 /* Not even one nack can be accomodated */
3150 prevEncIdx = encIdx;
3151 encIdx = bytesToEncode;
3153 }/* Loop is done for the NackCount */
3158 DU_LOG("\nINFO --> RLC_DL : rlcAssembleCntrlInfo: ACK PDU's SN = %d"\
3159 "UEID:%d CELLID:%d", ack_sn, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
3161 cntrlPdu[0] |= (ack_sn & 0xF00)>> 8;
3162 cntrlPdu[1] = (uint8_t)ack_sn;
3166 else if (rbCb->m.amDl.snLen == RLC_AM_CFG_18BIT_SN_LEN)
3168 /* If alteast one NACK SN Info then set the E1 field */
3169 if (pStaPdu->nackCount)
3179 for(nkCnt = 0;nkCnt < pStaPdu->nackCount; nkCnt++)
3181 sn = pStaPdu->nackInfo[nkCnt].sn;
3183 rlcNackInfo = &(pStaPdu->nackInfo[nkCnt]);
3185 bytesToEncode += 3; /* 3 Octets for NACK SN */
3187 /* Check if E2 : isSegment is set */
3188 if (rlcNackInfo->isSegment)
3190 bytesToEncode += 4; /* 4 Octets: SOstart, SOend */
3193 /* Check if E3 : nackRange is set */
3194 if (rlcNackInfo->nackRange)
3196 bytesToEncode += 1; /* 1 Octet: NACK range */
3199 /* Check if this NACK info can be accomodated in the Grant */
3200 if( rlcDatReq->pduSz >= bytesToEncode)
3202 /* If there is a NACK SN before this then set its
3206 /* NACKSN E1 E2 E3 R R R */
3207 cntrlPdu[prevEncIdx + 2] |= 0x20;
3210 /* 18 BIT Nack SN encode */
3211 cntrlPdu[encIdx] = (uint8_t)((sn & 0x3FC00) >> 10);
3214 cntrlPdu[encIdx + 1] = (uint8_t)((sn & 0x3FC) >> 2);
3217 cntrlPdu[encIdx + 2] = (uint8_t)((sn & 0x3)<< 6);
3219 if (rlcNackInfo->isSegment)
3221 /* NACKSN E1 E2 E3 R R R */
3223 cntrlPdu[encIdx + 2] |= 0x10;
3226 /* Add soStart and soEnd */
3228 cntrlPdu[encIdx + 3] = (rlcNackInfo->soStart) >> 8;
3229 cntrlPdu[encIdx + 4] = (uint8_t)rlcNackInfo->soStart;
3232 cntrlPdu[encIdx + 5] = (rlcNackInfo->soEnd) >> 8;
3233 cntrlPdu[encIdx + 6] = (uint8_t)(rlcNackInfo->soEnd);
3236 if (rlcNackInfo->nackRange)
3238 /* NACKSN E1 E2 E3 R R R */
3240 cntrlPdu[encIdx + 2] |= 0x08;
3242 if (rlcNackInfo->isSegment)
3244 cntrlPdu[encIdx + 7] = rlcNackInfo->nackRange;
3248 cntrlPdu[encIdx + 3] = rlcNackInfo->nackRange;
3252 gRlcStats.amRlcStats.numDLNacksInStaPdu++;
3254 /* Set ACK SN now */
3257 ack_sn = rlcNackInfo->sn;
3259 /* Not even one nack can be accomodated */
3262 cntrlPdu[2] &= 0xFD;
3268 prevEncIdx = encIdx;
3269 encIdx = bytesToEncode;
3271 }/* Loop is done for the NackCount */
3276 DU_LOG("\nINFO --> RLC_DL : rlcAssembleCntrlInfo: ACK PDU's SN = %d"
3277 "UEID:%d CELLID:%d", ack_sn, rbCb->rlcId.ueId,rbCb->rlcId.cellId);
3279 cntrlPdu[0] |= (ack_sn & 0x3C000) >> 14;
3280 cntrlPdu[1] = (ack_sn & 0x3FC0) >> 6;
3281 cntrlPdu[2] |= (ack_sn & 0x3F)<< 2;
3288 DU_LOG("\nERROR --> RLC_DL : rlcAssembleCntrlInfo:Conf SN LEN %d is INVALID !!!! \
3289 UEID:%d CELLID:%d", rbCb->m.amDl.snLen, rbCb->rlcId.ueId,
3290 rbCb->rlcId.cellId);
3295 ODU_GET_MSG_BUF(RLC_MEM_REGION_DL, RLC_POOL, &mBuf);
3297 mBuf = (Buffer *)rlcAmmStaPduList[rlcAmmStaPduListCnt++];
3299 if(rlcAmmStaPduListCnt > 511)
3300 rlcAmmStaPduListCnt = 0;
3303 cntrlPduSz = encIdx;
3304 ODU_ADD_POST_MSG_MULT(cntrlPdu, cntrlPduSz, mBuf);
3306 rlcDatReq->pduSz -= cntrlPduSz;
3307 /* Add mBuf to RLC_AMDL.mBuf */
3308 RLC_AMDL.mBuf = mBuf;
3313 #ifdef RLC_STA_PROC_IN_MAC/* RLC Status PDU Processing */
3315 S16 rlcProcDlStatusPdu(Pst *udxPst,SuId suId,
3316 CmLteCellId cellId,CmLteRnti rnti,CmLteLcId lcId,Buffer *rlcSdu);
3318 static Void rgAmmExtractElmnt(RlcCb *gCb,Buffer *pdu,RlcExtHdr *hdrInfo)
3321 uint8_t pLen = hdrInfo->pLen;
3322 uint8_t len = (uint8_t)hdrInfo->len;
3327 /* uint8_t rLen1 = 0; */
3334 SRemPreMsg(&hdr, pdu);
3340 val = tHdr >> (RLC_BYTE_LEN - (len));
3344 else /*if (len > 8) */
3348 val = val >> (RLC_BYTE_LEN - fLen);
3349 val = val << (len - fLen);
3351 SRemPreMsg(&hdr, pdu);
3355 hdr = hdr >> (RLC_BYTE_LEN - rLen);
3358 pLen = (RLC_BYTE_LEN - rLen);
3362 rLen = rLen - RLC_BYTE_LEN;
3364 tVal = tVal << rLen;
3367 SRemPreMsg(&hdr, pdu);
3369 hdr = hdr >> (RLC_BYTE_LEN - rLen);
3372 pLen = (RLC_BYTE_LEN - rLen);
3376 hdrInfo->pLen = pLen;
3386 static Void rgAmmUlHndlStatusPdu
3398 RlcUdxStaPdu *pStaPdu;
3399 uint8_t e3; /* NACK RANGE : 5GNR */
3402 uint32_t resrvdBitsAckSn;
3403 uint32_t resrvdBitsNackSn;
3405 RLCDBGP_BRIEF(gCb, "rgAmmUlHndlStatusPdu(rbCb, cntrlPdu, fByte) \n");
3407 RLC_MEM_ZERO(&hdrInfo, sizeof(RlcExtHdr));
3409 /* Extract the Control PDU */
3410 hdrInfo.hdr = (*fByte << 1);
3413 /* D/C has been shifted in the calling function */
3414 if (hdrInfo.hdr & 0xE0)
3416 RLCDBGP_ERROR(gCb, "rgAmmUlHndlStatusPdu: Reserved value for CPT received \n");
3420 RLC_ALLOC_SHRABL_BUF(udxPst->region,
3423 sizeof(RlcUdxStaPdu));
3425 #if (ERRCLASS & ERRCLS_ADD_RES)
3426 /* Memory allocation failure can not be expected */
3433 if (rbCb->m.amDl.snLen == RLC_AM_CFG_12BIT_SN_LEN)
3436 resrvdBitsAckSn = RLC_STA_PDU_R_BITS_ACKSN_12BITS;
3437 resrvdBitsNackSn = RLC_STA_PDU_R_BITS_NACKSN_12BITS;
3439 else if (rbCb->m.amDl.snLen == RLC_AM_CFG_18BIT_SN_LEN)
3442 resrvdBitsAckSn = RLC_STA_PDU_R_BITS_ACKSN_18BITS;
3443 resrvdBitsNackSn = RLC_STA_PDU_R_BITS_NACKSN_18BITS;
3448 resrvdBitsAckSn = 0;
3449 resrvdBitsAckSn = 0;
3452 pStaPdu->nackCnt = 0;
3454 hdrInfo.hdr = hdrInfo.hdr << RLC_CPT_LEN;
3457 hdrInfo.len = RLC_SN_LEN;
3458 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3459 pStaPdu->ackSn = hdrInfo.val;
3461 /* Check if NACK Exists */
3462 hdrInfo.len = RLC_E1_LEN;
3463 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3464 e1 = (uint8_t)hdrInfo.val;
3465 RLCDBGP_DETAIL(gCb, "rgAmmUlHndlStatusPdu: ACK SN = %d \n", pStaPdu->ackSn);
3467 /* Extract the Reserved Bits after ACK SN field */
3468 hdrInfo.len = resrvdBitsAckSn;
3469 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3472 /* If NACK exists in control PDU */
3473 /* For ACKs and NACKs */
3474 while (e1 && (pStaPdu->nackCnt < RLC_MAX_NACK_CNT))
3476 hdrInfo.len = snLen;
3477 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3478 pStaPdu->nackInfo[pStaPdu->nackCnt].sn = hdrInfo.val;
3480 hdrInfo.len = RLC_E1_LEN;
3481 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3482 e1 = (uint8_t)hdrInfo.val;
3485 /* hdrInfo.len = RLC_E1_LEN; --> previusly stored value (for e1) is
3487 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3488 /* e2 = (uint8_t) hdrInfo.val;*/
3490 /* Store e2 value */
3491 pStaPdu->nackInfo[pStaPdu->nackCnt].isSegment = (uint8_t) hdrInfo.val;
3493 /* Extract e3 : 5GNR */
3494 /* hdrInfo.len = RLC_E1_LEN; --> previusly stored value (for e1) is
3496 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3497 e3 = (uint8_t) hdrInfo.val;
3499 /* Extract Reserved Bits after NACK SN */
3500 hdrInfo.len = resrvdBitsNackSn;
3501 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3503 /* Test for resegmentation */
3504 if (pStaPdu->nackInfo[pStaPdu->nackCnt].isSegment)
3506 hdrInfo.len = RLC_SO_LEN_5GNR; /* 5GNR : SO Len 16 Bits */
3507 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3508 pStaPdu->nackInfo[pStaPdu->nackCnt].soStart = hdrInfo.val;
3510 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3511 pStaPdu->nackInfo[pStaPdu->nackCnt].soEnd = hdrInfo.val;
3514 "rgAmmUlHndlStatusPdu: soStart and soEnd = %d %d \n",
3515 pStaPdu->nackInfo[pStaPdu->nackCnt].soStart,
3516 pStaPdu->nackInfo[pStaPdu->nackCnt].soEnd);
3521 pStaPdu->nackInfo[pStaPdu->nackCnt].soStart = 0;
3522 pStaPdu->nackInfo[pStaPdu->nackCnt].soEnd = 0;
3525 /* NACK RANGE Field is SET */
3528 /* Extract NACK range field */
3529 hdrInfo.len = RLC_NACK_RANGE_LEN;
3530 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3531 snRange = (uint8_t)hdrInfo.val;
3533 pStaPdu->nackInfo[pStaPdu->nackCnt].nackRange = snRange;
3539 gRlcStats.amRlcStats.numULStaPduRcvd++;
3540 gRlcStats.amRlcStats.numULNackInStaPduRcvd += pStaPdu->nackCnt;
3542 /* In case we have reached the MAX NACK CNT, then we should modify the ACK_SN
3543 to the last NACK SN + 1 and discard the original ACK_SN*/
3544 if(pStaPdu->nackCnt == RLC_MAX_NACK_CNT)
3546 pStaPdu->ackSn = (pStaPdu->nackInfo[RLC_MAX_NACK_CNT-1].sn + 1) & amDl->snModMask;
3550 /* Parse & send Status PDU to RLC-DL */
3551 //rlcUlUdxStaUpdReq(&(sapCb->pst), sapCb->spId, &rbCb->rlcId, pStaPdu);
3552 rlcUlUdxStaUpdReq(udxPst, suId, &rbCb->rlcId, pStaPdu);
3557 S16 rlcProcDlStatusPdu(Pst *udxPst,SuId suId,
3558 CmLteCellId cellId,CmLteRnti rnti,CmLteLcId lcId,Buffer *rlcSdu)
3560 RlcDlRbCb *rbCb = NULLP;
3561 RlcDlUeCb *ueCb = NULLP;
3564 S16 retVal = RFAILED;
3566 Pst dlRlcPst = *udxPst;
3568 gCb = RLC_GET_RLCCB(1); /* DL RLC instance */
3570 if( ROK != rlcDbmFetchDlUeCb(gCb,rnti,cellId,&(ueCb)))
3572 DU_LOG("\nERROR --> RLC_DL : RLC UECb Not found...\n");
3577 rbCb = ueCb->lCh[lcId - 1].dlRbCb;
3579 /* Skip if mode is not AM */
3580 if((rbCb == NULLP) || (rbCb->mode != RLC_MODE_AM))
3585 if(ROK != SExamMsg((Data *)(&fByte),
3588 DU_LOG("\nERROR --> RLC_DL : Failure in Rlc Hdr SExamMsg\n");
3592 if(RLC_CNTRL_PDU == ((fByte & RLC_DC_POS) >> RLC_DC_SHT))
3594 SRemPreMsg(&temp, rlcSdu);
3595 dlRlcPst.selector = 1;/* LWLC*/
3596 rgAmmUlHndlStatusPdu(&dlRlcPst,suId,gCb, rbCb, rlcSdu, &fByte);
3610 /********************************************************************30**
3613 **********************************************************************/