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 static const char* RLOG_MODULE_NAME="AMM";
39 static int RLOG_MODULE_ID=2048;
40 static int RLOG_FILE_ID=189;
41 /* header include files (.h) */
42 #include "common_def.h"
43 #include "lkw.h" /* LKW defines */
44 #include "ckw.h" /* CKW defines */
45 #include "kwu.h" /* KWU defines */
46 #include "rgu.h" /* RGU defines */
47 #include "kw_err.h" /* Err defines */
48 #include "kw_env.h" /* RLC environment options */
50 #include "kw.h" /* RLC defines */
55 /* extern (.x) include files */
56 #include "lkw.x" /* LKW */
57 #include "ckw.x" /* CKW */
58 #include "kwu.x" /* KWU */
59 #include "rgu.x" /* RGU */
67 extern U32 rlcAmmStaPduList[512];
68 U32 rlcAmmStaPduListCnt = 0;
73 @brief RLC Acknowledged Mode Downlink Module
75 #define RLC_MODULE (RLC_DBGMASK_AM | RLC_DBGMASK_DL)
77 U32 rlcStatusPduCnt, rlcStatusAckCnt, rlcStatusNcnt, rlcSduSndCnt;
83 /* forward references */
84 EXTERN Void rlcAmmDlHndlStatusPdu ARGS ((RlcCb *gCb,
86 RlcUdxStaPdu *pStaPdu));
88 /* public variable declarations */
90 /* This structure holds all the global structs we need. */
92 /* private variable declarations */
94 #define RLC_AM_RMV_HDR(_gCb, _rbCb, _retx) do { \
95 if ((_retx)->yetToConst == FALSE) \
98 SSegMsg((_retx)->seg, (_retx)->hdrSz, &_pduInfo); \
99 RLC_FREE_BUF((_retx)->seg); \
100 (_retx)->seg = _pduInfo; \
102 (_rbCb)->m.amDl.estHdrSz -= retx->hdrSz;\
105 /* private function declarations */
107 PRIVATE Void rlcResegRetxPdus ARGS ((RlcCb *gCb,
109 RlcDatReq *rlcDatReq));
111 PRIVATE Void rlcRemRetxPdu ARGS ((RlcCb *gCb,
115 PRIVATE Void rlcAmmCreateStatusPdu ARGS ((RlcCb *gCb,
117 RlcDatReq *rlcDatReq));
119 PRIVATE Void rlcAmmDlMarkPduForReTx ARGS ((RlcCb *gCb,
123 PRIVATE Void rlcAmmDlProcessSuccessfulTxPdu ARGS((RlcCb *gCb,
126 KwuDatCfmInfo **datCfm));
128 PRIVATE Void rlcAmmDlSetTxNextAck ARGS((RlcAmDl *amDl, RlcSn sn));
130 PRIVATE Void rlcAmmDlCheckAndStopPollTmr ARGS((RlcCb *gCb,
134 PRIVATE Void rlcAssembleSdus ARGS ((RlcCb *gCb,
136 RlcDatReq *rlcDatReq));
138 bool rlcAmmDlCheckAndSetPoll ARGS ((RlcCb *gCb,
143 PRIVATE Void rlcAmmCreatePdu ARGS ((RlcCb *gCb,
146 RlcDlPduInfo *pduInfo,
149 PRIVATE Void rlcAmmSndStaInd ARGS ((RlcCb *gCb,RlcDlRbCb *rbCb, RlcRetx *retx));
151 PRIVATE Void rlcGetNxtRetx ARGS ((RlcCb *gCb, RlcRetx **retx));
153 PRIVATE Void rlcConstructAmHdr ARGS ((RlcAmHdr *amHdr,
158 PRIVATE Void rlcAmmDlUpdateTxAndReTxBufForAckSn ARGS ((RlcCb *gCb,
162 KwuDatCfmInfo **datCfm));
164 PRIVATE Void rlcAmmDlMoveFrmTxtoRetxBuffer ARGS ((RlcCb *gCb,
169 PRIVATE Void rlcAmmDlCheckIsSDUDelivered ARGS((RlcCb *gCb,
172 KwuDatCfmInfo **datCfm));
174 PRIVATE Void rlcAmmAddPduToRetxLst ARGS((RlcAmDl *amDl,
177 PRIVATE Void rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer ARGS(
182 RlcDlPduInfo *pduInfo
185 PRIVATE Void rlcAmmDlHndlStatus4SduByteSegInTxBuf ARGS(
189 RlcNackInfo *nackSnInfo,
191 KwuDatCfmInfo **datCfm
194 PRIVATE Void rlcAmmDlUpdateTxAndReTxBufForNackSn ARGS(
198 RlcNackInfo *nackSnInfo,
200 KwuDatCfmInfo **datCfm
203 PRIVATE Void RlcDlAmmGetNackSnInfoFrmNackRangeIdx ARGS(
206 RlcNackInfo *nackInfo,
208 RlcNackInfo *nackSnInfo,
212 PRIVATE Void rlcAmmDlUpdTxAndReTxBufForLessThanNackSn ARGS(
219 KwuDatCfmInfo **datCfm
221 /*****************************************************************************
223 AM Module contains the following funcitons:
227 - rlcAmmDlAssembleCntrlInfo
230 - rlcAmmDlCheckAndSetPoll
236 *******************************************************************************/
237 /** @addtogroup ammode */
241 * @brief Function to send a Status Response to MAC for a dedicated logical
245 * Function calculates the current bo and send a Status response for the
246 * dedicated logical channel if the bo is non zero
248 * @param[in] gCb RLC instance control block
249 * @param[in] rbCb Radio Bearer control block
250 * @param[in] amDl AM downlink control block
254 void rlcAmmSendDedLcBoStatus(RlcCb *gCb, RlcDlRbCb *rbCb, RlcAmDl *amDl)
256 int32_t bo = rlcAmmCalculateBo(amDl);
260 rlcUtlSendDedLcBoStatus(gCb, rbCb, bo, amDl->estHdrSz, \
261 amDl->cntrlBo ?TRUE:FALSE,amDl->cntrlBo);
268 * @brief Function to check if the pollSn is acked and stop the poll timer
270 * @param[in] gCb RLC instance control block
271 * @param[in] rbCb Radio Bearer control block
272 * @param[in] mAckSn The last received ACKSN. The base modulus value should
278 PRIVATE Void rlcAmmDlCheckAndStopPollTmr
285 PRIVATE Void rlcAmmDlCheckAndStopPollTmr(gCb, rbCb, mAckSn)
293 MODAMT(rbCb->m.amDl.pollSn, mPollSn, rbCb->m.amDl.txNextAck,rbCb->m.amDl.snModMask);
295 if (mPollSn <= mAckSn)
297 if (rlcChkTmr(gCb, (PTR)rbCb, RLC_EVT_AMDL_POLL_RETX_TMR))
299 rlcStopTmr(gCb, (PTR)rbCb, RLC_EVT_AMDL_POLL_RETX_TMR);
307 * @brief Function to set VT(A) and VT(MS). Calculates the VT(MS) from VT(A)
309 * @param[in,out] amDl AM downlink control block
310 * @param[in]sn Sequence number to be set as VT(A)
315 PRIVATE Void rlcAmmDlSetTxNextAck
321 PRIVATE Void rlcAmmDlSetTxNextAck(amDl, sn)
326 amDl->txNextAck = sn;
332 * @brief Function to process a successfully re-transmitted PDU/segment
335 * Checks if the SDU has been completely delivered or not. Removes the PDU
336 * from the re-transmission buffer
338 * @param[in] gCb RLC instance control block
339 * @param[in] rbCb Downlink Radio Bearer control block
340 * @param[in] retx The PDU/segment which was successfully re-transmitted
345 PRIVATE Void rlcAmmDlProcessSuccessfulReTx
350 KwuDatCfmInfo **datCfm
353 PRIVATE Void rlcAmmDlProcessSuccessfulReTx(gCb, rbCb, retx, datCfm)
357 KwuDatCfmInfo **datCfm;
360 rlcAmmDlCheckIsSDUDelivered(gCb, rbCb, &(retx->sduMap), datCfm);
362 rlcRemRetxPdu(gCb, rbCb, retx);
368 * @brief Handler to Move the PDU from txBuf to re-transmission buffer
371 * This function is used to move the PDU from the txBuf to re-transmit buffer
373 * @param[in]RlcCb *gCb RLC instance control block
374 * @param[in]RlcAmDl *amDl AM Downlink Control Block
375 * @param[in]RlcRetx **retx node in the reTx buffer to be moved to, allocated by
377 * @param[in]RlcDlPduInfo *pduInfo TX PDU which needs to be moved
384 PRIVATE Void rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer
389 RlcDlPduInfo *pduInfo
392 PRIVATE Void rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer(gCb, amDl, retx, pduInfo)
396 RlcDlPduInfo *pduInfo;
400 RLC_ALLOC_WC(gCb,*retx, sizeof(RlcRetx));
402 #if (ERRCLASS & ERRCLS_ADD_RES)
405 RLOG0(L_FATAL, "Memory allocation failed");
408 #endif /* ERRCLASS & ERRCLS_RES */
410 (*retx)->seg = pduInfo->pdu;
411 (*retx)->segSz = pduInfo->pduSz;
412 /* MS_FIX for DL stall */
413 (*retx)->soEnd = (pduInfo->amHdr.so + pduInfo->pduSz - 1);
415 (*retx)->hdrSz = pduInfo->hdrSz;
416 (*retx)->retxCnt = 1;
417 (*retx)->yetToConst = 0;
418 (*retx)->pendingReTrans = TRUE;
420 /* initialize the list pointer to 0 instead of memset */
421 (*retx)->lstEnt.next = 0;
422 (*retx)->lstEnt.prev = 0;
423 /* copy the sdu maps */
424 RLC_MEM_CPY(&((*retx)->sduMap),
428 RLC_MEM_CPY(&((*retx)->amHdr), &pduInfo->amHdr, sizeof(RlcAmHdr));
429 rlcAmmAddPduToRetxLst(amDl, (*retx));
431 /* Update the BO appropriately */
432 amDl->retxBo += (*retx)->segSz;
433 amDl->estHdrSz += (*retx)->hdrSz;
435 gRlcStats.amRlcStats.numDLRetransPdus++;
438 } /*rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer */
441 * @brief Function to handle Status of Sdu byte segment for a nackSn
444 * This function is used to move the PDU from the txBuf to re-transmit buffer
446 * @param[in]RlcCb *gCb RLC instance control block
447 * @param[in]RlcDlRbCb *rbCb AM Downlink Control Block
448 * @param[in]RlcNackInfo *nackSnInfo Nack Information of a NACK_SN
449 * @param[in]RlcRetx **retx node in the reTx buffer to be moved to, allocated by
451 * @param[in]KwuDatCfmInfo **datCfm Ptr to datCfm
458 PRIVATE Void rlcAmmDlHndlStatus4SduByteSegInTxBuf
462 RlcNackInfo *nackSnInfo,
464 KwuDatCfmInfo ** datCfm
467 PRIVATE Void rlcAmmDlHndlStatus4SduByteSegInTxBuf(gCb, rbCb, nackSnInfo, retx, datCfm)
471 RlcNackInfo *nackSnInfo;
473 KwuDatCfmInfo **datCfm;
481 txBuf = rlcUtlGetTxBuf(AMDL.txBufLst, nackSnInfo->sn);
486 lnk = txBuf->pduLst.first;
489 RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(lnk->node);
490 RlcSn pduSoEnd = (pduInfo->amHdr.so + pduInfo->sduMap.sduSz - 1);
492 /* If So of Sdu byte segment(pduInfo/seg) is < status pdu
493 soStart that means it's ACKED*/
494 if(pduSoEnd < nackSnInfo->soStart)
496 rlcAmmDlCheckIsSDUDelivered(gCb,
502 else if (pduSoEnd <= nackSnInfo->soEnd)
504 /* Move Sdu byte segment from TX buf to retx buf*/
505 rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer(gCb,
516 /* Delete node from the txBuf Pdu lst */
517 cmLListDelFrm(&txBuf->pduLst, lnk);
518 RLC_FREE_WC(gCb, pduInfo, sizeof(RlcDlPduInfo));
521 if(!txBuf->pduLst.count)
523 /*No more Sdu byte segment are left. Hence delete txBuf*/
524 rlcUtlDelTxBuf(AMDL.txBufLst, txBuf,gCb);
531 * @brief Function to handle Status of Sdu byte segment for a nackSn
534 * This function is used to move the PDU from the txBuf to re-transmit buffer
536 * @param[in]RlcCb *gCb RLC instance control block
537 * @param[in]RlcDlRbCb *rbCb AM Downlink Control Block
538 * @param[in]RlcNackInfo *nackSnInfo Nack Information of a NACK_SN
539 * @param[in]RlcRetx **retx node in the reTx buffer to be moved to, allocated by
541 * @param[in]KwuDatCfmInfo **datCfm Ptr to datCfm
547 PRIVATE Void rlcAmmDlUpdateTxAndReTxBufForNackSn
551 RlcNackInfo *nackSnInfo,
553 KwuDatCfmInfo **datCfm
556 PRIVATE Void rlcAmmDlUpdateTxAndReTxBufForNackSn(gCb, rbCb, nackSnInfo, retxNode, datCfm)
560 RlcNackInfo *nackSnInfo;
562 KwuDatCfmInfo **datCfm;
569 /* Now process the NACK_SN received. Now the NACK_SN is */
570 /* either the first element of RETX or is in TX array */
571 /* To remove the remaining acks from the pdu byte segments */
573 /* if the NACK_SN is in the transmit buffer, move it to the re-
575 txBuf = rlcUtlGetTxBuf(AMDL.txBufLst, nackSnInfo->sn);
578 if(nackSnInfo->isSegment)
580 /* Go through all the AMD PDUs of a particular SN
581 and check if segment is ACKED if yes then mark succesfully sent,
582 if segment is NACKed then move it to to retx lst */
583 rlcAmmDlHndlStatus4SduByteSegInTxBuf(gCb, rbCb, nackSnInfo, &retx, datCfm);
587 /*e2= 0 and e3= 0: Move complete PDU from TX buf to retx buf*/
588 rlcAmmDlMoveFrmTxtoRetxBuffer(gCb,
594 #if (ERRCLASS & ERRCLS_ADD_RES)
598 (*retxNode) = retx->lstEnt.next;
604 /* process the pdus/segments in the re-transmit buffer with
608 retx = (RlcRetx *)((*retxNode)->node);
609 if (retx->amHdr.sn != nackSnInfo->sn)
613 if ((nackSnInfo->isSegment) &&
614 ((retx->soEnd < nackSnInfo->soStart) /*|| (retx->amHdr.so > soEnd)*/))
616 RLOG_ARG3(L_DEBUG, DBG_RBID, rbCb->rlcId.rbId,
617 "rlcHndlStaRsp: Handle ACK for byte segment, Its "
618 "sn = %d UEID:%d CELLID:%d",
622 RLOG_ARG4(L_DEBUG, DBG_RBID, rbCb->rlcId.rbId,
623 "soStart and soEnd = %d, %d, UEID:%d CELLID:%d",
624 retx->amHdr.so, retx->soEnd,
628 (*retxNode) = (*retxNode)->next;
629 rlcAmmDlProcessSuccessfulReTx(gCb,rbCb, retx, datCfm);
631 else if((!nackSnInfo->isSegment) || (retx->soEnd <= nackSnInfo->soEnd))
633 /* This case covers the NACKED segments and also the case */
634 /* when there are segments and the entire SN is nacked. */
635 /* This case also covers the case of nonsegmented retx PDU*/
637 (*retxNode) = (*retxNode)->next;
638 /* Mark the retx PDU we found for further retransmission */
639 rlcAmmDlMarkPduForReTx(gCb, rbCb, retx);
643 /* If we are here that means this segment and segments after this are ACKed*/
646 } /* end of retxNode while loop*/
651 * @brief Function to get nack Sn information from nackRange index
654 * This function is used to get nack Sn information from nackRange index
656 * @param[in]RlcAmDl *amDl,
657 * @param[in]RlcUdxStaPdu *StaPdu,
658 * @param[in]RlcNackInfo *nackSnInfo,
659 * @param[in]RlcRetx *retx;
660 * @param[in]RlcSn sn,
667 PRIVATE Void RlcDlAmmGetNackSnInfoFrmNackRangeIdx
670 RlcNackInfo *nackInfo,
672 RlcNackInfo *nackSnInfo,
676 PRIVATE Void RlcDlAmmGetNackSnInfoFrmNackRangeIdx(amDl, nackInfo, retxNode, nackSnInfo, idx)
679 RlcNackInfo *nackInfo;
681 RlcNackInfo *nackSnInfo;
690 nackSnInfo->isSegment = FALSE;
692 if((!nackInfo->isSegment) || (!idx && nackSnInfo->nackRange && (!nackInfo->soStart)))
694 nackSnInfo->soStart = 0;
695 nackSnInfo->soEnd = 0;
698 txBuf = rlcUtlGetTxBuf(amDl->txBufLst, nackSnInfo->sn);
701 node = txBuf->pduLst.first;
704 RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(node->node);
705 U16 pduSoEnd = pduInfo->amHdr.so + pduInfo->sduMap.sduSz - 1;
706 if((!idx) && (pduInfo->amHdr.so == nackInfo->soStart))
708 nackSnInfo->isSegment = TRUE;
709 nackSnInfo->soStart = pduInfo->amHdr.so;
710 nackSnInfo->soEnd = pduSoEnd;
713 else if((idx == nackSnInfo->nackRange - 1) && \
714 (pduSoEnd == nackInfo->soEnd))
716 nackSnInfo->isSegment = TRUE;
717 nackSnInfo->soStart = pduInfo->amHdr.so;
718 nackSnInfo->soEnd = pduSoEnd;
724 if(!nackSnInfo->isSegment)
728 retx = (RlcRetx *)(retxNode->node);
729 if(retx->amHdr.sn != nackSnInfo->sn)
733 if((!idx) && (retx->amHdr.so == nackInfo->soStart))
735 nackSnInfo->isSegment = TRUE;
736 nackSnInfo->soStart = retx->amHdr.so;
737 nackSnInfo->soEnd = retx->soEnd;
740 else if((idx == nackSnInfo->nackRange - 1) && \
741 (retx->soEnd == nackInfo->soEnd))
743 nackSnInfo->isSegment = TRUE;
744 nackSnInfo->soStart = retx->amHdr.so;
745 nackSnInfo->soEnd = retx->soEnd;
748 retxNode = retxNode->next;
754 * @brief Function to update transmission buffers and send confimations to
755 * PDCP on the reception of Status PDU
758 * First processes the NACKs received
759 * -# Removes the pdus which are acked by each of the NACK SN from the
760 * transmission and re-transmission buffer
761 * -# If NACKed SN in in the transmisson buffer, moves it to re-transmission
763 * -# Removes PDU segments of the NACKed SN which have been successfully
764 * received by the other end. For the un-successful ones, marks them for
766 * -# When PDUs/segments are removed from the buffer, indicates to upper
767 * layer if the SDU is completely delivered
768 * -# Removes the PDUs/segments which are acked by the ACK_SN but not by the
771 * @param[in] gCb RLC Instance control block
772 * @param[in] rbCb Downlink Radio Bearer control block
773 * @param[in] pStaPdu The decoded Status Pdu
778 Void rlcAmmDlHndlStatusPdu
782 RlcUdxStaPdu *pStaPdu
785 Void rlcAmmDlHndlStatusPdu(gCb, rbCb, pStaPdu)
788 RlcUdxStaPdu *pStaPdu;
794 KwuDatCfmInfo* datCfm;
795 RlcKwuSapCb *rlckwuSap;
800 rlckwuSap = gCb->u.dlCb->rlcKwuDlSap + RLC_UI_PDCP;
801 /* store the re-transmission bo, to check if it changes due to the
802 processing of the status pdu */
803 oldRetxBo = AMDL.retxBo;
805 /* Allocate memory for datCfm Info */
806 RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
808 #if (ERRCLASS & ERRCLS_ADD_RES)
811 RLOG_ARG2(L_FATAL,DBG_RBID,rbCb->rlcId.rbId,
812 "Memory allocation failed UEID:%d CELLID:%d",
815 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
818 #endif /* ERRCLASS & ERRCLS_RES */
820 datCfm->numSduIds = 0;
821 datCfm->rlcId = rbCb->rlcId;
823 MODAMT(pStaPdu->ackSn, mAckSn, AMDL.txNextAck,AMDL.snModMask);
824 MODAMT(AMDL.txNext,mTxNext, AMDL.txNextAck,AMDL.snModMask);
828 RLOG_ARG4(L_WARNING,DBG_RBID, rbCb->rlcId.rbId,
829 "Invalid ACK SN = %d received. Current Vta =%d"
835 /* RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo)); */
836 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
840 /* Venki - stopping the poll retx timer */
841 /*Stop PollRetx Tmr */
842 rlcAmmDlCheckAndStopPollTmr(gCb, rbCb, mAckSn);
844 /* Set the first node in retx list to retxNode */
845 retxNode = AMDL.retxLst.first;
847 /* If NACK exists in control PDU */
848 if (pStaPdu->nackCnt)
851 RlcNackInfo nackSnInfo;
854 RlcSn transWinStartSn = AMDL.txNextAck; /*used to track the SN from which
855 to start processing the transmission
859 /* if any NACKs then txNextAck should be equal to the first NACK_SN*/
860 txNextAck = pStaPdu->nackInfo[0].sn;
862 rlcStatusNcnt += pStaPdu->nackCnt;
865 while (idx < pStaPdu->nackCnt)
867 nackSnInfo.isSegment = pStaPdu->nackInfo[idx].isSegment;
868 nackSnInfo.nackRange = pStaPdu->nackInfo[idx].nackRange;
869 nackSnInfo.sn = pStaPdu->nackInfo[idx].sn;
871 RLOG_ARG3(L_DEBUG,DBG_RBID, rbCb->rlcId.rbId,
872 "rlcHndlStaRsp: NACK SN = %d UEID:%d CELLID:%d",
877 nackSnInfo.soStart = pStaPdu->nackInfo[idx].soStart;
878 nackSnInfo.soEnd = pStaPdu->nackInfo[idx].soEnd;
880 /* e2 is used as a boolean indicating presence of SOStart or SOEnd */
882 sn = transWinStartSn;
884 /* move transWinStartSn to nackSnInfo.sn + 1, as the pdu's before that
885 will be removed from the buffer */
886 transWinStartSn = (nackSnInfo.sn + (nackSnInfo.nackRange ?\
887 (nackSnInfo.nackRange - 1) : 0) + 1) & AMDL.snModMask;
889 /* Clear the acked SNs from the retx list */
890 MODAMT(nackSnInfo.sn, mNackSn, AMDL.txNextAck,AMDL.snModMask);
892 if ((mNackSn > mAckSn) || (mNackSn >= mTxNext))
894 /* Erroneous NACK_SN, we should raise an error towards L3 */
895 RLOG_ARG2(L_ERROR,DBG_RBID, rbCb->rlcId.rbId,
896 "Status Pdu is not correct UEID:%d CELLID:%d",
899 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
903 /* clear all the SNs < NACK_SN from re-transmission list */
904 rlcAmmDlUpdTxAndReTxBufForLessThanNackSn(gCb, rbCb, sn, mNackSn,
907 if(!nackSnInfo.nackRange)
909 rlcAmmDlUpdateTxAndReTxBufForNackSn(gCb, rbCb, &nackSnInfo, &retxNode, &datCfm);
910 gRlcStats.amRlcStats.numRlcAmCellNackRx++;
915 /* Update issegment, soStart, soEnd ,sn in nackSnInfo and handle
919 RlcDlAmmGetNackSnInfoFrmNackRangeIdx(&AMDL, &pStaPdu->nackInfo[idx],
920 retxNode, &nackSnInfo, idx1);
922 rlcAmmDlUpdateTxAndReTxBufForNackSn(gCb, rbCb, &nackSnInfo,
924 nackSnInfo.sn = ((nackSnInfo.sn + 1) & (AMDL.snModMask));
925 gRlcStats.amRlcStats.numRlcAmCellNackRx++;
927 }while((++idx1) < (nackSnInfo.nackRange));
931 } /* End of nackCnt while loop */
933 /* Remove the PDUs with are further acked by the ACK_SN after taking
934 care of all the NACK_SN related acknowledgments*/
935 rlcAmmDlUpdateTxAndReTxBufForAckSn(gCb,rbCb, mAckSn, retxNode, &datCfm);
937 /* Update txNextAck */
938 rlcAmmDlSetTxNextAck(&AMDL,txNextAck);
944 RLOG_ARG2(L_UNUSED,DBG_RBID, rbCb->rlcId.rbId,
945 "rlcHndlStaRsp: Received All ACKS UEID:%d CELLID:%d",
949 /* For the remaining ACKs after last nackSn */
950 rlcAmmDlUpdateTxAndReTxBufForAckSn(gCb,rbCb, mAckSn, retxNode, &datCfm);
952 /* update txNextAck */
953 rlcAmmDlSetTxNextAck(&AMDL, pStaPdu->ackSn);
956 if(datCfm->numSduIds != 0)
958 if(datCfm->numSduIds > 1024)
960 RLOG_ARG4(L_DEBUG,DBG_RBID,datCfm->rlcId.rbId,
961 "Sending [%lu] SDU Cfms to PDCP & [%lu] lost for"
964 datCfm->numSduIds-1024,
967 datCfm->numSduIds = 1024;
969 rlcSduSndCnt += datCfm->numSduIds;
970 /* Sap control block */
971 RlcUiKwuDatCfm(&rlckwuSap->pst, rlckwuSap->suId, datCfm);
975 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, datCfm, sizeof(KwuDatCfmInfo));
978 /* Fix for memory corruption */
979 RLC_LLIST_FIRST_RETX(AMDL.retxLst, AMDL.nxtRetx);
980 /* BO update, if retransmission BO has changed. AMDL.retxBo would have
981 canged inside the above called functions */
982 if (oldRetxBo != AMDL.retxBo)
984 rlcAmmSendDedLcBoStatus(gCb, rbCb, &AMDL);
991 * @brief Function to calculate the current buffer occupancy
994 * Function to calculate the current bo depending on the control,
995 * re-transmit, transmit bo's and the state of the transmit window.
996 * If the transmit window is stalled, then the transmit bo is not
999 * @param[in] amDl AM mode donwlink control block
1005 S32 rlcAmmCalculateBo
1010 S32 rlcAmmCalculateBo(amDl)
1016 /* Make sure non of the bo's are negative */
1022 if (amDl->cntrlBo < 0)
1027 if (amDl->retxBo < 0)
1032 bo = amDl->cntrlBo + amDl->retxBo;
1034 /* if window is not stalled then add the transmit bo also */
1035 if (! RLC_AM_IS_TRANS_WIN_STALLED(amDl))
1045 * @brief Handler to queue the SDUs received from PDCP
1048 * This function is invoked by UIM to queue the SDU received from PDCP in the
1049 * SDU queue of the corresponding RbCb. It also updates the BO and report the
1051 * - Allocate memory for and assign received buffer to the SDU
1052 * - Add SDU in the sduQ of RlcAmDl
1053 * - Calculate bo with the buffer received
1054 * - Accumulate bo with retransmission bo and control pdu's bo if available
1055 * - Estimate the header size for the bo; Fill in StaRspInfo and send it
1058 * @param[in] gCb RLC Instance control block
1059 * @param[in] rbCb RB control block
1060 * @param[in] mBuf Sdu to be queued
1061 * @param[in] datReq Ptr to the datReq sent from PDCP
1066 void rlcAmmQSdu(RlcCb *gCb, RlcDlRbCb *rbCb, Buffer *mBuf, KwuDatReqInfo *datReq)
1078 RLC_ALLOC_WC(gCb,sdu, sizeof(RlcSdu));
1080 #if (ERRCLASS & ERRCLS_ADD_RES)
1083 DU_LOG("\n RLC : rlcAmmQSdu : Memory allocation failed UEID:%d CELLID:%d",\
1084 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1087 #endif /* ERRCLASS & ERRCLS_RES */
1089 RLC_UPD_L2_DL_TOT_SDU_STS(gCb,rbCb);
1090 /* Discard new changes starts */
1091 rlcUtlGetCurrTime(&sdu->arrTime);
1092 /* Discard new changes ends */
1093 /* Assign values to sdu */
1094 ODU_GET_MSG_LEN(mBuf, &sdu->sduSz);
1097 sdu->actSz = sdu->sduSz;
1098 sdu->mode.am.sduId = datReq->sduId;
1099 /* initialize values for AM mode to 0 */
1100 sdu->mode.am.rcvdSz = 0;
1101 sdu->mode.am.isSegmented = 0;
1102 #ifndef RGL_SPECIFIC_CHANGES
1105 extern uint32_t dlrate_kwu;
1106 dlrate_kwu += sdu->sduSz;
1110 /* Update nxtTx to point to the added sdu if this is the first SDU in the
1112 if (AMDL.nxtTx == NULLP)
1114 DU_LOG("\nRLC : rlcAmmQSdu: Received SDU will be transmitted next \
1115 UEID:%d CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1119 /* Add sdu to the sdu list */
1120 cmLListAdd2Tail(&AMDL.sduQ, &sdu->lstEnt);
1121 sdu->lstEnt.node = (PTR)sdu;
1125 if (rbCb->ueCb->tenbStats)
1127 if (AMDL.sduQ.count > rbCb->ueCb->tenbStats->stats.nonPersistent.rlc.dlMaxPktsInSduQ)
1129 rbCb->ueCb->tenbStats->stats.nonPersistent.rlc.dlMaxPktsInSduQ = AMDL.sduQ.count;
1131 rlcWinSz = RLC_AM_TRANS_WIN_SIZE(&AMDL);
1132 if (rlcWinSz > rbCb->ueCb->tenbStats->stats.nonPersistent.rlc.dlMaxWindowSz)
1134 rbCb->ueCb->tenbStats->stats.nonPersistent.rlc.dlMaxWindowSz = rlcWinSz;
1140 /* Update BO and estimate header size for the current BO */
1141 AMDL.bo = AMDL.bo + sdu->sduSz;
1142 if(AMDL.snLen == RLC_AM_CFG_12BIT_SN_LEN)
1150 #ifdef LTE_L2_MEAS_RLC
1151 /* Update numActUe if it is not active */
1152 if((rbCb->rbL2Cb.measOn & LKW_L2MEAS_ACT_UE) &&
1153 (rbCb->ueCb->numActRb[rbCb->qci] == 0))
1155 rbCb->ueCb->numActRb[rbCb->qci]++;
1156 gCb.rlcL2Cb.numActUe[rbCb->qci]++;
1160 if(!rlcDlUtlIsReestInProgress(rbCb))
1162 rlcAmmSendDedLcBoStatus(gCb, rbCb, &AMDL);
1170 * @brief Private handler to construct control PDU
1173 * This function sets the pduSz correctly after eliminating the fixed
1174 * header sizes and the MAC header size. It copies the already prepared
1175 * STATUS PDU to the data to be sent to MAC.
1177 * @param[in] gCb RLC instance control block
1178 * @param[in] rbCb Downlink RB control block
1179 * @param[in] kwdatReq DatReq to be sent to MAC
1184 void rlcAmmDlAssembleCntrlInfo(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq)
1186 RlcUdxDlSapCb *sapCb;
1189 macHdrEstmt = (rbCb->m.amDl.cntrlBo < 256) ?
1190 RLC_MAC_HDR_SZ2 : RLC_MAC_HDR_SZ3;
1191 /* Eliminate fixed hdr size (14bits including ACK_SN) */
1192 if (rlcDatReq->pduSz >= (RLC_CNTRL_PDU_FIXED_HDRSZ + macHdrEstmt))
1194 /* Check the TB size whether it is sufficcient enough to fit the
1195 status Pdu into it otherwise make arrangement such that it can fit
1196 into in a way of possible NACks*/
1197 /* ccpu00135743 : fix for MAC Hdr size calc */
1198 rlcDatReq->pduSz -= macHdrEstmt;
1200 /* Create the status Pdu with the required NACKs */
1201 rlcAmmCreateStatusPdu(gCb,rbCb,rlcDatReq);
1203 sapCb = RLC_GET_DL_SAPCB(gCb, rbCb);
1204 rlcDlUdxStaProhTmrStart(&(gCb->u.dlCb->udxDlSap->pst),
1205 sapCb->suId, &(rbCb->rlcId));
1207 /* Update number of pdus in pduInfo */
1208 rlcDatReq->pduInfo.mBuf[rlcDatReq->pduInfo.numPdu] = AMDL.mBuf;
1209 rlcDatReq->pduInfo.numPdu++;
1210 gRlcStats.amRlcStats.numDLStaPduSent++;
1212 RLC_FREE_SHRABL_BUF(gCb->u.dlCb->udxDlSap->pst.region,
1213 gCb->u.dlCb->udxDlSap->pst.pool,
1215 sizeof(RlcUdxDlStaPdu));
1217 AMDL.pStaPdu = NULLP;
1219 gRlcStats.amRlcStats.numDLStaPduSent++;
1226 * @brief Handler to form the PDUs with the size indicated by MAC
1229 * This function is invoked by UTL with the PDU size indicated by
1230 * MAC (after eliminating MAC header size). It assembles control
1231 * Info / data (New SDUs / Retx PDUs), check if polling needs to be
1232 * set for the data PDU and returns PDU(s) and updated BO with
1233 * estimated header size to be sent to MAC.
1235 * - Check if the control BO is available and call rlcAssembleCntrlInfo
1236 * to assemble control Information
1237 * - Check if the pdu size is available to form PDUs from retransmission
1238 * buffer and call rlcResegRetxPdus
1239 * - Check if the pdu size is available and assemble SDUs from sduQ
1240 * if exist, using rlcAssembleSdus
1241 * - PDU Info and bo are filled in and then sent to MAC from the
1244 * @param[in] gCb RLC instance control block
1245 * @param[in] rbCb RB control block
1246 * @param[in] kwdatReq DatReq to be sent to MAC
1247 * @param[in] fillCtrlPdu Indicates whether cntrl PDU to be filled or not
1252 void rlcAmmProcessSdus(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq, bool fillCtrlPdu)
1254 /* Assemble control information. fillCtrlPdu parameter check is added for CA
1255 * It is used to force cntrl Pdu scheduling on PCell. for Non CA case this
1256 * flag will always be TRUE. In CA case, for PCELL it is TRUE and for SCEll
1259 if ((AMDL.cntrlBo != 0)
1265 rlcDatReq->boRep.staPduPrsnt = TRUE;
1266 rlcDatReq->boRep.staPduBo = AMDL.cntrlBo;
1268 if (AMDL.pStaPdu != NULLP)
1270 rlcAmmDlAssembleCntrlInfo (gCb, rbCb, rlcDatReq);
1274 DU_LOG("\nRLC: rlcAmmProcessSdus: Miscomputation of control Bo. \
1275 UEID:%d CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1280 /* Retransmit PDUs /portions of PDUs available in retxLst */
1281 if ((rlcDatReq->pduSz > 0) && (AMDL.nxtRetx != NULLP))
1283 rlcResegRetxPdus (gCb,rbCb, rlcDatReq);
1286 /* Assemble SDUs to form new PDUs */
1287 if ((rlcDatReq->pduSz > 0) && (AMDL.nxtTx != 0))
1289 rlcAssembleSdus(gCb,rbCb, rlcDatReq);
1292 if (AMDL.nxtRetx != NULLP)
1294 rlcDatReq->boRep.oldestSduArrTime = AMDL.nxtRetx->sduMap.sdu->arrTime;
1296 else if (AMDL.nxtTx != NULLP)
1298 rlcDatReq->boRep.oldestSduArrTime = AMDL.nxtTx->arrTime;
1301 rlcDatReq->boRep.bo = rlcAmmCalculateBo(&AMDL);
1302 rlcDatReq->boRep.staPduBo = AMDL.cntrlBo;
1304 /* Hdr estimation is moved to kwAmmCreatePDu */
1305 rlcDatReq->boRep.estHdrSz = AMDL.estHdrSz;
1307 if(rlcDatReq->pduSz > 0)
1309 gRlcStats.amRlcStats.numDLBytesUnused += rlcDatReq->pduSz;
1315 * @brief Private handler split a PDU/segment into two
1318 * Its a private function called by kwResegRetxPdu to split a segment
1319 * or a retransmit PDU into two segments splitting at the passed size.
1320 * This function is called only for those PDUs that dont have any LIs.
1322 * @param[in] gCb RLC instance control block
1323 * @param[in] rbCb RB control block
1324 * @param[in,out] crnt The PDU to be split, first part of split pdu remians
1326 * @param[out] next The second part of the split pdu
1327 * @param[in] size The size witin crnt, at which to split
1332 void rlcSplitPdu(RlcCb *gCb, RlcDlRbCb *rbCb, RlcRetx *crnt, RlcRetx *next, uint16_t size)
1335 RlcAmDl *amDl = &AMDL;
1337 /* Set the SN for the new segment */
1338 next->amHdr.sn = crnt->amHdr.sn;
1340 /* Set the protocol specific fields appropriately */
1341 si = crnt->amHdr.si;
1342 crnt->amHdr.si = si | RLC_SI_FIRST_SEG;
1343 next->amHdr.si = si | RLC_SI_LAST_SEG;
1347 /* Update seg size */
1348 next->segSz = crnt->segSz - size;
1351 /* Set the SO fields appropriately */
1352 /* MS_FIX for DL stall */
1353 next->soEnd = crnt->soEnd;
1355 /* Set the SO fields appropriately */
1356 /* SO of next will be after the end of current */
1357 next->amHdr.so = crnt->amHdr.so + crnt->segSz;
1358 /* SO End of current will be one less than the start of next */
1359 crnt->soEnd = next->amHdr.so - 1;
1361 /* intialize the other fields in the amHdr of next to 0 */
1365 /* This macro is called for No LI case - one SDU */
1366 /* Update the size of SDU in each node's sduMap */
1367 next->sduMap.sdu = crnt->sduMap.sdu;
1368 crnt->sduMap.sduSz = crnt->segSz;
1369 next->sduMap.sduSz = next->segSz;
1371 /* Segment the payload into two parts based on the size passed */
1372 ODU_SEGMENT_MSG(crnt->seg, size, &next->seg);
1373 next->retxCnt = crnt->retxCnt;
1374 next->yetToConst = TRUE;
1375 next->pendingReTrans = crnt->pendingReTrans;
1377 /* Compute the header size and update the BO appropriately */
1378 if(amDl->snLen == RLC_AM_CFG_12BIT_SN_LEN)
1380 next->hdrSz = RLC_AM_SEG_12BIT_SN_WITH_SO_HDRSZ;
1381 if(crnt->amHdr.si == RLC_SI_FIRST_SEG)
1383 crnt->hdrSz = RLC_AM_SEG_12BIT_SN_WITHOUT_SO_HDRSZ;
1387 crnt->hdrSz = RLC_AM_SEG_12BIT_SN_WITH_SO_HDRSZ;
1392 next->hdrSz = RLC_AM_SEG_18BIT_SN_WITH_SO_HDRSZ;
1393 if(crnt->amHdr.si == RLC_SI_FIRST_SEG)
1395 crnt->hdrSz = RLC_AM_SEG_18BIT_SN_WITHOUT_SO_HDRSZ;
1399 crnt->hdrSz = RLC_AM_SEG_18BIT_SN_WITH_SO_HDRSZ;
1403 /* Add the next to the retx list */
1404 AMDL.retxLst.crnt = &crnt->lstEnt;
1405 CM_LLIST_INS_AFT_CRNT(AMDL.retxLst, next);
1406 AMDL.nxtRetx = next;
1407 amDl->estHdrSz += next->hdrSz;
1413 * @brief Private handler to retransmit PDUs or PDU segments
1416 * Its a private function called by kwProcessSdus, to create the
1417 * PDUs / its segments from the retransmission buffer available in RbCb.
1419 * - Eliminate the fixed header size and MAC header size while
1420 * forming PDUs/segments
1421 * - While pdusize is available and retxBuf has data (pdu or portion
1422 * of pdu) to be sent, form the pdu as it is if it matches with the
1423 * pdusize else segment the PDUs/portion of PDUs
1424 * - Call rlcAmmDlCheckAndSetPoll function to check and set the poll bit as
1426 * - Concatenate data and header info and fill pduInfo
1427 * - Update retxCnt and send indication to PDCP if it reaches maxRetx
1430 * @param[in] gCb RLC instance control block
1431 * @param[in] rbCb RB control block
1432 * @param[in] kwdatReq DatReq to be sent to MAC
1437 void rlcResegRetxPdus(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq)
1441 uint8_t hdr[RLC_MAX_HDRSZ];
1447 RlcL2MeasTb *l2MeasTb;
1448 RlclchInfo *lchInfo;
1454 /* TODO : This shoould be taken care in new Trasmissions */
1455 /* This lchInfo should be retrieved there */
1456 l2MeasTb = rlcUtlGetCurMeasTb(gCb, rbCb);
1457 if (l2MeasTb == NULLP)
1461 /* TODO : This lcid needs to be searched in case of normal Tx */
1462 /* In retx here, its fine as this will be higher priority */
1463 lchInfo = &l2MeasTb->lchInfo[l2MeasTb->numLchInfo];
1464 if (l2MeasTb->numLchInfo >= RLC_MAX_ACTV_DRB)
1468 l2MeasTb->numLchInfo++;
1469 lchInfo->lcId = rbCb->lch.lChId;
1470 lchInfo->numSdus = 0;
1473 while ((rlcDatReq->pduSz > 0) && (amDl->nxtRetx != NULLP)&&
1474 (rlcDatReq->pduInfo.numPdu < RLC_MAX_PDU))
1478 retx = amDl->nxtRetx;
1479 /* kw003.201 : Add header size to seg size to determine if the */
1480 /* the segment can be completed within the allocation */
1481 /* kw003.201 - Eliminate MAC Header Size based on bites needed */
1482 tmpSz = RLC_MIN((retx->segSz + retx->hdrSz), rlcDatReq->pduSz);
1483 pduSz = (retx->segSz + retx->hdrSz);
1484 /* 5GNR_RLC: length field in 5GNR MAC Hdr is 8/16 btis*/
1485 rlcDatReq->pduSz -= (tmpSz < 255) ? RLC_MAC_HDR_SZ2 : RLC_MAC_HDR_SZ3;
1487 /* kw003.201 - We should have at least one more than basic header */
1488 if (rlcDatReq->pduSz <= retx->hdrSz)
1492 rlcGetNxtRetx(gCb, &(amDl->nxtRetx));
1494 /* Send retx buf without segmentation */
1495 if (rlcDatReq->pduSz >= pduSz)
1499 DU_LOG("\nRLC: rlcResegRetxPdus: Send retx buf without segmentation "
1500 "UEID:%d CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1502 if (retx->yetToConst)
1504 /* Construct hdr with the available hdr values */
1505 rlcConstructAmHdr(&retx->amHdr, hdr, amDl->snLen, &idx);
1506 /* Add header to the pdu/segment */
1507 ODU_ADD_PRE_MSG_MULT_IN_ORDER(hdr, idx + 1, retx->seg);
1508 retx->yetToConst = FALSE;
1511 /* kw003.201 - Check if poll bit needs to be set. Retx size does */
1512 /* not affect the poll bit so it is being passed as zero */
1513 pollBit = rlcAmmDlCheckAndSetPoll(gCb,rbCb, FALSE, 0);
1514 RLC_UPD_POLL_BIT(gCb, retx, pollBit);
1516 rlcDatReq->pduSz -= pduSz;
1517 AMDL.estHdrSz -= retx->hdrSz;
1520 if (rbCb->rlcId.rbType == CM_LTE_DRB)
1523 for (sduIdx = lchInfo->numSdus ;
1524 ((numSdus < retx->numSdu) && (sduIdx < RLC_L2MEAS_SDUIDX)) ;
1525 sduIdx++, numSdus++)
1527 lchInfo->sduInfo[sduIdx].arvlTime = retx->sduMap[numSdus].sdu->arrTime;
1528 lchInfo->sduInfo[sduIdx].isRetxPdu = TRUE; /* TODO : for later use */
1530 lchInfo->numSdus += numSdus;
1538 /* Segment this pdu / portion of pdu. Insert this segment into */
1539 /* retxLst and update offset */
1540 DU_LOG("\nRLC: rlcResegRetxPdus: Segment retx buf UEID:%d CELLID:%d",
1541 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1543 /* Eliminate fixed header size if the pdu is segmented for the */
1545 if(amDl->snLen == RLC_AM_CFG_12BIT_SN_LEN)
1547 if(retx->amHdr.si < RLC_SI_LAST_SEG)
1549 rlcDatReq->pduSz -= RLC_AM_SEG_12BIT_SN_WITHOUT_SO_HDRSZ;
1553 rlcDatReq->pduSz -= RLC_AM_SEG_12BIT_SN_WITH_SO_HDRSZ;
1558 if(retx->amHdr.si < RLC_SI_LAST_SEG)
1560 rlcDatReq->pduSz -= RLC_AM_SEG_18BIT_SN_WITHOUT_SO_HDRSZ;
1564 rlcDatReq->pduSz -= RLC_AM_SEG_18BIT_SN_WITH_SO_HDRSZ;
1567 if (rlcDatReq->pduSz <= 0)
1572 /* Allocate memory for tracking a new segment */
1573 RLC_ALLOC_WC(gCb,tNode, sizeof(RlcRetx));
1574 #if (ERRCLASS & ERRCLS_ADD_RES)
1577 DU_LOG("\nRLC: rlcResegRetxPdus: Memory allocation failed UEID:%d CELLID:%d",
1578 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1581 #endif /* ERRCLASS & ERRCLS_RES */
1583 /* initialize the list pointer to 0 instead of memset */
1584 tNode->lstEnt.next = 0;
1585 tNode->lstEnt.prev = 0;
1587 /* Segment header and data */
1588 RLC_AM_RMV_HDR(gCb, rbCb, retx);
1590 /* kw003.201 - Split the payload and update other fields */
1591 rlcSplitPdu(gCb,rbCb, retx, tNode, rlcDatReq->pduSz);
1596 sduIdx = lchInfo->numSdus;
1597 for (numSdus = 0, sduIdx = lchInfo->numSdus;
1598 ((numSdus < retx->numSdu) && (sduIdx < RLC_L2MEAS_SDUIDX));
1599 numSdus++, sduIdx++)
1601 lchInfo->sduInfo[sduIdx].arvlTime =
1602 retx->sduMap[numSdus].sdu->arrTime;
1603 lchInfo->sduInfo[sduIdx].isRetxPdu = TRUE;
1605 lchInfo->numSdus = sduIdx;
1606 if ((retx->amHdr.lsf == 0) && (lchInfo->numSdus > 0))
1611 /* Construct hdr with the available hdr values */
1612 rlcConstructAmHdr(&retx->amHdr, hdr, amDl->snLen, &idx);
1613 ODU_ADD_PRE_MSG_MULT_IN_ORDER(hdr, idx + 1, retx->seg);
1615 retx->hdrSz = idx + 1;
1617 /* Poll bit need not be set for this seg, since its second */
1618 /* half remains in retxLst */
1619 RLC_UPD_POLL_BIT(gCb, retx, FALSE);
1620 retx->yetToConst = FALSE;
1621 rlcDatReq->pduSz = 0;
1624 rlcCpyMsg(gCb,retx->seg, &pdu);
1626 /* Update pduInfo */
1627 rlcDatReq->pduInfo.mBuf[rlcDatReq->pduInfo.numPdu] = pdu;
1628 rlcDatReq->pduInfo.numPdu++;
1629 /* kw005.201 ccpu00117318, updating the statistics */
1630 gCb->genSts.pdusRetx += 1;
1631 gRlcStats.amRlcStats.numRlcAmCellRetxPdu++;
1632 retx->soEnd = retx->amHdr.so + retx->segSz - 1;
1633 retx->pendingReTrans = FALSE;
1634 amDl->retxBo -= retx->segSz;
1637 DU_LOG("\nRLC: rlcResegRetxPdus: retxBo after resegmentation = %ld"
1638 "UEID:%d CELLID:%d", amDl->retxBo, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1640 DU_LOG("\nRLC: rlcResegRetxPdus: retxBo after resegmentation = %d "
1641 "UEID:%d CELLID:%d", amDl->retxBo, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1649 * @brief Private handler to assemble SDUs to form new data PDU(s)
1652 * Its a private function called by kwProcessSdus, to create the new data
1653 * PDUs from the SDU queue of RbCb.
1655 * - While pdusize is available, segment/concatenate SDUs or else if it
1656 * matches the pdu size form PDUs accordingly.
1657 * - RLC header and MAC header size are eliminated while forming the PDUs
1658 * - Call rlcAmmDlCheckAndSetPoll function to check and set the poll bit
1660 * - Concatenate data and header info and fill pduInfo
1662 * @param[in] rbCb RB control block
1663 * @param[in] kwdatReq DatReq to be sent to MAC
1668 void rlcAssembleSdus(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq)
1670 Buffer *pdu = NULLP;
1671 MsgLen macGrntSz = rlcDatReq->pduSz;
1672 RlcAmDl *amDl = &AMDL;
1673 RlcSdu *sdu = amDl->nxtTx;
1675 bool nxtTxUpd = FALSE;
1676 KwuDiscSduInfo *discSduInfo = NULLP;
1677 RlcKwuSapCb* rlckwuSap = gCb->u.dlCb->rlcKwuDlSap + RLC_UI_PDCP;
1679 RlcContSduLst contSduLst; /*Contained sduLst */
1680 int32_t dataVol = amDl->bo;
1681 uint32_t *totMacGrant = &rlcDatReq->totMacGrant;
1682 RlcL2MeasDlIpTh *dlIpThPut = &rbCb->l2MeasIpThruput.dlIpTh;
1683 uint8_t *sduIdx = &dlIpThPut->lastSduIdx;
1685 bool isSduSegmented;
1688 RlclchInfo *dstLchInfo;
1689 uint32_t segSduCnt = 0;
1691 uint32_t numSdus = 0;
1692 uint32_t currSduIdx = 0;
1693 RlcL2MeasTb *l2MeasTb;
1695 /* Discard new changes starts */
1698 uint8_t numNewPdu = 0;
1699 RlcTx *txBuf = NULLP;
1700 /* Discard new changes ends */
1701 VOLATILE uint32_t startTime = 0;
1703 uint32_t fixedHdrSz;
1705 RlcAmHdr *amHdr = NULLP;
1706 RlcDlPduInfo *pduInfo = NULLP;
1709 contSduLst.numSdus = 0;
1710 contSduLst.lcId = rbCb->lch.lChId;
1712 lchInfo.lcId = rbCb->lch.lChId;
1713 lchInfo.numSdus = 0;
1715 /* Discard new changes starts */
1716 /* Allocate memory for discSdu Info */
1717 RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region,
1718 rlckwuSap->pst.pool,
1720 sizeof(KwuDiscSduInfo));
1722 #if (ERRCLASS & ERRCLS_ADD_RES)
1723 if (discSduInfo == NULLP)
1725 DU_LOG("\nRLC: rlcAssembleSdus: Memory allocation failed UEID:%d CELLID:%d",
1726 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1729 #endif /* ERRCLASS & ERRCLS_RES */
1731 discSduInfo->numSduIds = 0;
1732 discSduInfo->rlcId = rbCb->rlcId;
1734 rlcUtlGetCurrTime(&curTime);
1735 amDl->sduQ.crnt = &sdu->lstEnt;
1736 /* Eliminate fixed header size */
1737 /*5GNR: value of RLC_AM_PDU_FIXED_HDRSZ will be 2 or 3 depending on SN Size*/
1738 if(amDl->snLen == RLC_AM_CFG_12BIT_SN_LEN)
1740 fixedHdrSz = RLC_AM_PDU_12BIT_SN_HDRSZ;
1744 fixedHdrSz = RLC_AM_PDU_18BIT_SN_HDRSZ;
1747 while ((macGrntSz > fixedHdrSz) && (sdu != NULLP) &&
1748 (rlcDatReq->pduInfo.numPdu < RLC_MAX_PDU) &&
1749 (numNewPdu < RLC_MAX_NEW_DL_PDU))
1752 isSduSegmented = sdu->mode.am.isSegmented;
1754 /* Discard new changes starts */
1755 if ((sdu->mode.am.isSegmented == FALSE) && (rbCb->discTmrInt > 0) && \
1756 (rbCb->rlcId.rbType == CM_LTE_DRB))
1758 //leftAmSdus[rbCb->qci]--;
1759 timeDiff = RLC_TIME_DIFF(curTime,sdu->arrTime);
1760 if (timeDiff > rbCb->discTmrInt)
1764 SStartTask(&startTime, PID_RLC_AMM_DISC_SDUS);
1766 RLC_UPD_L2_DL_DISC_SDU_STS(gCb,rbCb);
1767 /* TODO need to send disc cfm to pdcp */
1769 /* Update bo for boReport */
1770 amDl->bo -= sdu->sduSz;
1772 /* Get next sdu for assembly */
1773 nxtNode = sdu->lstEnt.next;
1775 /* store the info for sending it to PDCP */
1776 if(discSduInfo->numSduIds > 500)
1778 DU_LOG("\nRLC: rlcAssembleSdus: This is a big error, we shouldn't be here"
1779 "UEID:%d CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1783 discSduInfo->sduIds[discSduInfo->numSduIds] = sdu->mode.am.sduId;
1784 discSduInfo->numSduIds++;
1786 cmLListDelFrm(&amDl->sduQ, &sdu->lstEnt);
1788 rlcUtlAddSduToBeFreedQueue(gCb, sdu);
1789 rlcUtlRaiseDlCleanupEvent(gCb);
1791 /* We need to restore the crnt in the linked list which
1792 * would have become NULL in the DelFrm above */
1793 amDl->sduQ.crnt = nxtNode;
1796 sdu = (RlcSdu*)nxtNode->node;
1801 ODU_STOP_TASK(startTime, PID_RLC_AMM_DISC_SDUS);
1810 /** kw003.201 - Check for window stall when you are
1811 * creating a new PDU
1813 if (RLC_AM_IS_TRANS_WIN_STALLED(amDl))
1816 printf("\n Window stalled \n");
1817 gRlcStats.amRlcStats.numRlcAmCellWinStall++;
1822 hdrEstmt = fixedHdrSz;
1824 if (sdu->mode.am.isSegmented)
1826 /* Adding two byte for SO */
1829 /* Eliminate MAC header */
1830 /* ccpu00135743 : Fix for MAC Hdr size calculation */
1831 /*5GNR: value of mac hdr length field changed to 8/16bits */
1832 pduSz = RLC_MIN(macGrntSz, (sdu->sduSz + hdrEstmt));
1833 hdrEstmt += (pduSz < 255) ? RLC_MAC_HDR_SZ2 : RLC_MAC_HDR_SZ3;
1835 macGrntSz -= hdrEstmt;
1836 /* kw005.201 Check for PDU Size is large enough.
1837 * Fix for ccpu00118973
1844 /* Dont create new txBuf for segmented SDU */
1845 if (!sdu->mode.am.isSegmented)
1848 RLC_ALLOC_WC(gCb,txBuf, sizeof(RlcTx));
1850 cmLListInit(&txBuf->pduLst);
1852 #if (ERRCLASS & ERRCLS_ADD_RES)
1855 uint32_t avblMem = 0;
1856 SRegInfoShow(gCb->init.region, &avblMem);
1857 DU_LOG("\nRLC: rlcAssembleSdus: Memory allocation failed UEID:%d CELLID:%d",
1858 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1861 #endif /* ERRCLASS & ERRCLS_RES */
1863 rlcUtlStoreTxBuf(amDl->txBufLst, txBuf, amDl->txNext);
1867 txBuf = rlcUtlGetTxBuf(amDl->txBufLst, amDl->txNext);
1870 RLC_ALLOC_WC(gCb,pduInfo, sizeof(RlcDlPduInfo));
1871 #if (ERRCLASS & ERRCLS_ADD_RES)
1872 if (pduInfo == NULLP)
1874 uint32_t avblMem = 0;
1875 SRegInfoShow(gCb->init.region, &avblMem);
1876 DU_LOG("\nRLC: rlcAssembleSdus: Memory allocation failed UEID:%d CELLID:%d",
1877 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1880 #endif /* ERRCLASS & ERRCLS_RES */
1882 /*Initialize DL segment structure */
1883 pduInfo->lstEnt.next = NULLP;
1884 pduInfo->lstEnt.prev = NULLP;
1885 pduInfo->lstEnt.node = NULLP;
1887 pduInfo->pdu = NULLP;
1888 pduInfo->amHdr.dc = 0;
1889 pduInfo->amHdr.p = 0;
1890 pduInfo->amHdr.si = 0;
1891 pduInfo->amHdr.so = 0;
1893 pduInfo->amHdr.sn = amDl->txNext;
1895 if (macGrntSz >= sdu->sduSz)
1899 /* Update Framing Info */
1900 if (sdu->mode.am.isSegmented)
1902 /*5GNR RLC: SN should be same for all segment of a SDU*/
1903 pduInfo->amHdr.sn = sdu->mode.am.sn;
1904 pduInfo->amHdr.si = RLC_SI_LAST_SEG; /* binary 10 */
1905 pduInfo->amHdr.so = sdu->actSz - sdu->sduSz;
1906 sdu->mode.am.isSegmented = FALSE;
1909 gRlcStats.amRlcStats.numRlcAmCellSduTx++;
1910 //printf("\n 5GNRLOG: last segment of lcId %d SduId %u So %u macGrntSz %u sduActSz %u sdu->sduSz %u\n",
1911 // rbCb->lch.lChId, sdu->mode.am.sduId, pduInfo->amHdr.so, macGrntSz, sdu->actSz, sdu->sduSz);
1915 gRlcStats.amRlcStats.numRlcAmCellSduTx++;
1917 amHdr = &pduInfo->amHdr;
1918 /* Create PDU with hdr and data */
1919 rlcAmmCreatePdu(gCb,rbCb, amHdr, pduInfo, pdu);
1921 //printf("\n Segmentation not required case: numPdu %d pdu %p \n",rlcDatReq->pduInfo.numPdu, pdu);
1923 #ifdef LTE_L2_MEAS_RLC
1924 rlcUtlUpdSduSnMap(rbCb, sdu, rlcDatReq, TRUE);
1925 #endif /* LTE_L2_MEAS */
1927 /* kw005.201 ccpu00117318, updating the statistics */
1928 rlcUtlIncrementKwuStsSduTx(gCb->u.dlCb->rlcKwuDlSap + rbCb->k1wuSapId);
1930 if(RLC_MEAS_IS_DL_ANY_MEAS_ON_FOR_RB(gCb,rbCb))
1934 *sduIdx = dlIpThPut->lastSduIdx;
1938 RLC_GETSDUIDX(*sduIdx);
1941 rlcUtlUpdateContainedSduLst(*sduIdx, &contSduLst);
1942 rlcUtlUpdateOutStandingSduLst(dlIpThPut, *sduIdx, sdu->actSz,
1943 sdu->mode.am.sduId, newIdx);
1944 /* Update the arrival time for each SDU */
1946 if ( lchInfo.numSdus < RLC_L2MEAS_SDUIDX)
1948 lchInfo.sduInfo[lchInfo.numSdus].arvlTime = sdu->arrTime;
1953 sduMap.sduSz = sdu->sduSz;
1958 * Allocate buffer for next PDU
1959 * Remove the segmented portion from SDUQ
1960 * Calculate the hdr with LI for SDU */
1962 Buffer *remSeg = NULLP;
1964 //printf("\n SDU segmentation case: numPdu %d pdu %p \n", rlcDatReq->pduInfo.numPdu, pdu);
1966 if(RLC_MEAS_IS_DL_IP_MEAS_ON_FOR_RB(gCb,rbCb) ||
1967 RLC_MEAS_IS_DL_DELAY_MEAS_ON_FOR_RB(gCb,rbCb) ||
1968 RLC_MEAS_IS_DL_UU_LOSS_MEAS_ON_FOR_RB(gCb,rbCb) )
1970 /* If actual size of the sdu is equal to msgLen
1971 * then it is first segment of the SDU */
1972 if(sdu->actSz == sdu->sduSz)
1974 RLC_GETSDUIDX(*sduIdx);
1979 *sduIdx = dlIpThPut->lastSduIdx;
1981 rlcUtlUpdateContainedSduLst(*sduIdx, &contSduLst);
1982 rlcUtlUpdateOutStandingSduLst(dlIpThPut, *sduIdx, sdu->actSz,
1983 sdu->mode.am.sduId, newIdx);
1984 if(RLC_MEAS_IS_DL_UU_LOSS_MEAS_ON_FOR_RB(gCb,rbCb))
1986 /* If actual size of the sdu is equal to msgLen
1987 * then it is first segment of the SDU */
1988 if(sdu->actSz == sdu->sduSz)
1996 /* Segment the SDU to the size of the PDU and update header Info */
1997 ODU_SEGMENT_MSG(sdu->mBuf, macGrntSz, &remSeg);
2001 /* Update SI and SN */
2002 if (sdu->mode.am.isSegmented)
2004 /*5GNR RLC: SN should be same for all segment of a SDU.
2005 * Sdu was already segmented and segmenting again*/
2006 pduInfo->amHdr.sn = sdu->mode.am.sn;
2007 pduInfo->amHdr.si = RLC_SI_MID_SEG; /* binary 11 */
2008 pduInfo->amHdr.so = sdu->actSz - sdu->sduSz;
2010 //printf("\n 5GNRLOG: mid segment of lcId %d SduId %u So %u macGrntSz %u sduActSz %u sdu->sduSz %u\n",
2011 // rbCb->lch.lChId, sdu->mode.am.sduId, txBuf->amHdr.so, macGrntSz, sdu->actSz, sdu->sduSz);
2015 /*5GNR RLC: This means it is the first*/
2016 pduInfo->amHdr.si = RLC_SI_FIRST_SEG; /* binary 01 */
2017 /*5GNR_RLC: Store SN so that in sub-seqent SDU segments will use this SN*/
2018 sdu->mode.am.sn = pduInfo->amHdr.sn;
2019 pduInfo->amHdr.so = 0;
2021 //printf("\n 5GNRLOG: First segment of lcId %d SduId %u So %u macGrntSz %u sduActSz %u sdu->sduSz %u\n",
2022 // rbCb->lch.lChId, sdu->mode.am.sduId, txBuf->amHdr.so, macGrntSz, sdu->actSz, sdu->sduSz);
2025 amHdr = &pduInfo->amHdr;
2026 /* Create PDU with hdr and data */
2027 rlcAmmCreatePdu(gCb,rbCb, amHdr, pduInfo, pdu);
2029 sdu->mode.am.isSegmented = TRUE;
2030 sdu->sduSz -= macGrntSz;
2031 sduMap.sduSz = macGrntSz;
2033 #ifdef LTE_L2_MEAS_RLC
2034 rlcUtlUpdSduSnMap(rbCb, sdu, rlcDatReq, FALSE);
2035 #endif /* LTE_L2_MEAS */
2041 /* Update bo for boReport */
2042 amDl->bo -= sduMap.sduSz;
2046 /* Update pduInfo */
2047 rlcDatReq->pduInfo.mBuf[rlcDatReq->pduInfo.numPdu] = pdu;
2048 rlcDatReq->pduInfo.numPdu++;
2050 /* kw005.201 ccpu00117318, updating the statistics */
2051 gCb->genSts.pdusSent++;
2052 gRlcStats.amRlcStats.numRlcAmCellSduBytesTx = gRlcStats.amRlcStats.numRlcAmCellSduBytesTx + sduMap.sduSz;
2053 /* Update the RLC Tx buffer with the new PDU info */
2054 RLC_MEM_CPY(&pduInfo->sduMap, &sduMap, sizeof(RlcSduMap));
2057 macGrntSz -= sduMap.sduSz;
2058 /* Get next sdu for assembly */
2059 RLC_LLIST_NEXT_SDU(amDl->sduQ, sdu);
2061 } /*End of pduSz loop */
2063 rlcDatReq->pduSz = macGrntSz;
2064 /* Updating nxtTx to sdu in the Q */
2069 if(RLC_MEAS_IS_DL_ANY_MEAS_ON_FOR_RB(gCb,rbCb) &&
2070 (rbCb->rlcId.rbType == CM_LTE_DRB))
2074 l2MeasTb = rlcUtlGetCurMeasTb(gCb, rbCb);
2075 rlcUtlUpdateBurstSdus(gCb, rbCb, &contSduLst, dataVol, *totMacGrant);
2076 if ((lchInfo.numSdus != 0) && (l2MeasTb != NULLP))
2078 for (lchIdx = 0; ((lchIdx < l2MeasTb->numLchInfo)
2079 && (lchIdx < RLC_MAX_ACTV_DRB )); lchIdx++)
2081 if (l2MeasTb->lchInfo[lchIdx].lcId == rbCb->lch.lChId)
2083 /* Lch Info already added in Retx procedure */
2087 if (lchIdx < RLC_MAX_ACTV_DRB)
2089 if (lchIdx == l2MeasTb->numLchInfo)
2091 l2MeasTb->lchInfo[lchIdx].lcId = rbCb->lch.lChId;
2092 l2MeasTb->lchInfo[lchIdx].numSdus = 0;
2093 l2MeasTb->numLchInfo++;
2095 dstLchInfo = &l2MeasTb->lchInfo[lchIdx];
2096 currSduIdx = l2MeasTb->lchInfo[lchIdx].numSdus;
2097 while ((numSdus < lchInfo.numSdus) && (currSduIdx < RLC_L2MEAS_SDUIDX))
2099 dstLchInfo->sduInfo[currSduIdx].arvlTime = lchInfo.sduInfo[numSdus].arvlTime;
2100 dstLchInfo->sduInfo[currSduIdx].isRetxPdu = FALSE;
2104 l2MeasTb->lchInfo[lchIdx].numSdus += numSdus;
2107 /* Fix Klock warning */
2108 if(l2MeasTb != NULLP)
2110 l2MeasTb->txSegSduCnt += segSduCnt;
2113 *totMacGrant -= (oldBo - amDl->bo);
2116 if(discSduInfo->numSduIds != 0)
2118 /* Sap control block */
2119 RlcUiKwuDiscSduCfm(&rlckwuSap->pst, rlckwuSap->suId, discSduInfo);
2123 RLC_SHRABL_STATIC_BUF_FREE(rlckwuSap->pst.region, rlckwuSap->pst.pool, discSduInfo, sizeof(KwuDiscSduInfo));
2127 DU_LOG("\nRLC: rlcAssembleSdus: BO after assembly = %d UEID:%d CELLID:%d",
2128 amDl->bo, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
2134 * @brief Private handler to check if the poll bit needs to be set for data PDU
2137 * Its a private function called by kwProcessSdus, to checks if the
2138 * polling bit needs to be set for any RLC data PDU and updates the
2140 * - For the new PDUs, if the counters exceed the configured
2141 * pduWoPoll/byteWoPoll values, return poll bit.
2142 * - For the PDUs/portion of PDUs, if the SDU list / retxBuf is
2143 * empty, return poll bit.
2144 * - Update the pollPdu, pollByte counters and Poll_SN; start staProhTmr
2146 * @param[in] rCb RLC instance control block
2147 * @param[in] rbCb RB control block
2148 * @param[in] newPdu Flag to indicate if its a new AMD PDU.
2149 * @param[in] bufSz Length of the PDU
2152 * -# 1 - To set the poll bit
2153 * -# 0 - Poll bit is not set
2156 bool rlcAmmDlCheckAndSetPoll(RlcCb *gCb, RlcDlRbCb *rbCb, bool newPdu, MsgLen bufSz)
2158 bool pollBit = FALSE;
2159 RlcAmDl *amDl = &(rbCb->m.amDl);
2161 /* If it's a new PDU increment PDU without poll and bytes without poll
2162 and check if they cross the configured number of poll pdu and poll bytes*/
2166 /* Patch kw004.201 */
2167 amDl->byteWoPoll += bufSz;
2169 if (((amDl->pollPdu != -1) && (amDl->pduWoPoll >= amDl->pollPdu)) ||
2170 ((amDl->pollByte != -1) && (amDl->byteWoPoll >= amDl->pollByte)))
2176 /* Check if both tx/retx buffer are empty or if tx window is stalled */
2177 if (((amDl->nxtTx == NULLP) && (amDl->nxtRetx == NULLP)) ||
2178 RLC_AM_IS_TRANS_WIN_STALLED(amDl))
2185 amDl->pduWoPoll = 0;
2186 amDl->byteWoPoll = 0;
2188 amDl->pollSn = (amDl->txNext - 1) & amDl->snModMask;
2190 DU_LOG("\nRLC: rlcAmmDlCheckAndSetPoll: Poll SN = %d UEID:%d CELLID:%d",
2191 amDl->pollSn, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
2193 /* kw005.201: Fix for poll retransmission timer.
2194 * Timer is stopped if it is already running and
2195 * then starting the timer. Fixes crs
2196 * ccpu00117216 and ccpu00118284 .
2198 if( TRUE == rlcChkTmr(gCb,(PTR)rbCb,RLC_EVT_AMDL_POLL_RETX_TMR) )
2200 rlcStopTmr(gCb,(PTR)rbCb, RLC_EVT_AMDL_POLL_RETX_TMR);
2203 rlcStartTmr(gCb,(PTR)rbCb, RLC_EVT_AMDL_POLL_RETX_TMR);
2210 * @brief Private handler to create AMD PDU
2213 * This function constructs header and concatenate it with the data for
2214 * the PDU. It also updates the txBuf with the created PDU.
2216 * @param[in] gCB RLC instance control block
2217 * @param[in] rbCb Downlink RB control block
2218 * @param[in] amHdr AM header
2219 * @param[in] RlcDlPduInfo Pointer to PduInfo
2220 * @param[in] pdu PDU buffer
2225 void rlcAmmCreatePdu(RlcCb *gCb, RlcDlRbCb *rbCb, RlcAmHdr *amHdr,
2226 RlcDlPduInfo *pduInfo, Buffer *pdu)
2228 uint8_t hdr[RLC_MAX_HDRSZ];
2232 RlcAmDl *amDl = &(rbCb->m.amDl);
2235 amHdr->sn = amDl->txNext;
2237 /*5GNR RLC: Increment txNext only if no segmentation of it is a last segment */
2238 if((!amHdr->si) || (amHdr->si == RLC_SI_LAST_SEG))
2240 //printf("\n 5GNRLOG: no segment/last seg SDU with lcId %d Sn %u txNext %u So %u\n",
2241 // rbCb->lch.lChId, amHdr->sn, amDl->txNext, amHdr->so);
2242 amDl->txNext = (amDl->txNext + 1) & amDl->snModMask;
2245 /* Update hdr Info */
2246 ODU_GET_MSG_LEN(pdu, &pduSz);
2248 /* passing newPDU = TRUE*/
2249 amHdr->p = rlcAmmDlCheckAndSetPoll(gCb,rbCb, TRUE, pduSz);
2251 /* Construct header with the available hdr Info, set isSegment to FALSE */
2252 rlcConstructAmHdr(amHdr, hdr, amDl->snLen, &idx);
2254 /* Concatenate hdr and data */
2255 ODU_ADD_PRE_MSG_MULT_IN_ORDER(hdr, idx+1, pdu);
2257 txBuf = rlcUtlGetTxBuf(amDl->txBufLst, amHdr->sn);
2258 rlcCpyMsg(gCb,pdu,&(pduInfo->pdu));
2259 pduInfo->pduSz = pduSz;
2260 pduInfo->hdrSz = idx+1;
2262 /*Update estHdrSz. deduct current hdrSz */
2263 amDl->estHdrSz -= pduInfo->hdrSz;
2264 /* Reestimate estHdrSz for mid and last seg */
2267 amDl->estHdrSz += ((amHdr->si == RLC_SI_MID_SEG)? pduInfo->hdrSz : (pduInfo->hdrSz + 2));
2270 cmLListAdd2Tail(&txBuf->pduLst, &pduInfo->lstEnt);
2271 pduInfo->lstEnt.node = (PTR)pduInfo;
2273 gCb->genSts.bytesSent += pduSz;
2279 * @brief Private handler to remove the retx PDU from the rbCb
2282 * This function releases a retx PDU stored on DL portion of rbCb.
2283 * It also updates the BO if wtForAck flag is not set which implies
2284 * that it is not sent out yet.
2286 * @param[in] gCb RLC instance control block
2287 * @param[in] retx retransmit PDU to be removed
2288 * @param[in] rbCb Radio Bearer Control Block
2294 PRIVATE Void rlcRemRetxPdu
2301 PRIVATE Void rlcRemRetxPdu(gCb, rbCb, retx)
2307 cmLListDelFrm(&AMDL.retxLst, &retx->lstEnt);
2309 if( AMDL.retxLst.count == 0)
2311 AMDL.nxtRetx = NULLP;
2314 if(retx->pendingReTrans == TRUE)
2316 AMDL.retxBo -= retx->segSz;
2317 AMDL.estHdrSz -= retx->hdrSz;
2320 rlcUtlAddReTxPduToBeFreedQueue(gCb, retx);
2321 rlcUtlRaiseDlCleanupEvent(gCb);
2327 * @brief Private handler to mark a retx PDU for further retransmission
2330 * This function sets a retx PDU that has not been ACKed in the
2331 * received Status PDU for futher retransmission. If the retransmission
2332 * limit is reached, it releases the retx PDU and informs the higher
2333 * layers about the same.
2335 * @param[in] gCb RLC instance control block
2336 * @param[in] retx retransmit PDU to be removed
2337 * @param[in] rbCb Radio Bearer Control Block
2343 PRIVATE Void rlcAmmDlMarkPduForReTx
2350 PRIVATE Void rlcAmmDlMarkPduForReTx(*gCb, rbCb, retx)
2356 if (AMDL.maxReTxReached == TRUE)
2361 if(retx->pendingReTrans == FALSE)
2363 retx->pendingReTrans = TRUE;
2366 AMDL.retxBo += retx->segSz;
2367 AMDL.estHdrSz += retx->hdrSz;
2369 if (retx->retxCnt > AMDL.maxRetx)
2371 /* RLC_DL_MAX_RETX fix */
2372 /* Marking the RB stalled for DL scheduling. This is to avoid unnecessary */
2373 /* preparation of RLC PDUs and adding the same to Tx Buffer */
2374 /* This condition is to avoid sending StaIndication more than once */
2375 if (TRUE != rbCb->m.amDl.maxReTxReached)
2377 rbCb->m.amDl.maxReTxReached = TRUE;
2378 rbCb->m.amDl.bo = 0;
2379 rbCb->m.amDl.cntrlBo = 0;
2380 rbCb->m.amDl.retxBo = 0;
2381 /* Sending BO update to SCH */
2382 rlcUtlSendDedLcBoStatus(gCb, rbCb, 0,0,0,0);
2383 rlcAmmSndStaInd(gCb, rbCb, retx);
2384 gRlcStats.amRlcStats.numDLMaxRetx++;
2387 rlcRemRetxPdu(gCb,rbCb, retx);
2393 if (AMDL.nxtRetx == NULLP)
2395 AMDL.nxtRetx = retx;
2398 gRlcStats.amRlcStats.numDLRetransPdus++;
2406 * @brief Private handler to check if SDU is completely deliverd and
2407 * send higher layers data confirmation
2410 * This function sends higher layers data confirmation for SDUs which
2411 * have been successfully delivered to the peer RLC entity.
2413 * @param[in] gCb RLC instance control block
2414 * @param[in] rbCb Radio Bearer Control Block
2415 * @param[in] sduLst List of SDUs that were part of the PDU
2416 * @param[in] numSdu Number of SDUs in the list
2422 PRIVATE Void rlcAmmDlCheckIsSDUDelivered
2427 KwuDatCfmInfo **datCfm
2430 PRIVATE Void rlcAmmDlCheckIsSDUDelivered(gCb, rbCb, sduMap, datCfm)
2434 KwuDatCfmInfo **datCfm;
2441 sdu->mode.am.rcvdSz += sduMap->sduSz;
2443 /* send a dat cfm if all the bytes of the sdu have been received */
2444 if (sdu->mode.am.rcvdSz == sdu->actSz)
2446 /* Send DatCfm for this sdu */
2447 if((*datCfm)->numSduIds < KWU_MAX_DAT_CFM)
2449 (*datCfm)->sduIds[(*datCfm)->numSduIds++] = sdu->mode.am.sduId;
2453 /* This is an error that should never happen, we should resize
2454 * the #define to a larger value or check why we need to
2455 * send so many confirms in one go
2456 * Confrims to PDCP are being dropped in this case
2458 RlcKwuSapCb *rlckwuSap;
2459 rlckwuSap = gCb->u.dlCb->rlcKwuDlSap + RLC_UI_PDCP;
2460 RlcUiKwuDatCfm(&rlckwuSap->pst, rlckwuSap->suId, *datCfm);
2462 RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region, rlckwuSap->pst.pool, *datCfm, sizeof(KwuDatCfmInfo));
2464 #if (ERRCLASS & ERRCLS_ADD_RES)
2465 if (*datCfm == NULLP)
2467 RLOG_ARG2(L_FATAL,DBG_RBID,rbCb->rlcId.rbId,
2468 "Memory allocation failed UEID:%d CELLID:%d",
2470 rbCb->rlcId.cellId);
2473 #endif /* ERRCLASS & ERRCLS_RES */
2475 (*datCfm)->numSduIds = 0;
2476 (*datCfm)->rlcId = rbCb->rlcId;
2477 /* ccpu00135618: say total 1026 sduIds to copy the 1025 sduId after
2478 * new allocation of datCfm */
2479 (*datCfm)->sduIds[(*datCfm)->numSduIds++] = sdu->mode.am.sduId;
2482 /* Remove SDU from the sduQ */
2483 cmLListDelFrm(&AMDL.sduQ, &sdu->lstEnt);
2484 rlcUtlAddSduToBeFreedQueue(gCb, sdu);
2485 rlcUtlRaiseDlCleanupEvent(gCb);
2492 * @brief Private handler to mark a PDU successful.
2495 * This function is called when we receive a STATUS pdu that marks
2496 * a PDU as successful. It releases the PDU from RLC entity and
2497 * informs PDCP of successful SDUs delivered as a result of this PDU.
2499 * @param[in] gCb RLC instance control block
2500 * @param[in] rbCb Radio Bearer Control Block
2501 * @param[in] sn SN that is successfully delivered to the peer
2507 PRIVATE Void rlcAmmDlProcessSuccessfulTxPdu
2512 KwuDatCfmInfo **datCfm
2515 PRIVATE Void rlcAmmDlProcessSuccessfulTxPdu(gCb, rbCb, sn, datCfm)
2519 KwuDatCfmInfo **datCfm;
2524 RlcTx *txBuf = rlcUtlGetTxBuf(AMDL.txBufLst, sn);
2530 pduNode = txBuf->pduLst.first;
2533 RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(pduNode->node);
2534 rlcAmmDlCheckIsSDUDelivered(gCb,
2538 pduNode = pduNode->next;
2541 rlcUtlAddTxPduToBeFreedQueue(gCb, txBuf);
2542 rlcUtlRaiseDlCleanupEvent(gCb);
2543 /* so that it is not processed again */
2544 rlcUtlRemovTxBuf(AMDL.txBufLst, txBuf, gCb);
2550 * @brief Handler to send Status Indication to PDCP
2553 * This function is used to send status indication to PDCP when the
2554 * maximum retransmission threshold value is reached for a PDU.
2556 * @param[in] gCb RLC instance control block
2557 * @param[in] rbCb RB control block
2558 * @param[in] retx The PDU/segment that failed max re-transmissions
2564 PRIVATE Void rlcAmmSndStaInd
2571 PRIVATE Void rlcAmmSndStaInd(gCb, rbCb, retx)
2577 KwuStaIndInfo *staInd;
2578 RlcKwuSapCb *rlckwuSap;
2580 /* Sap control block */
2581 rlckwuSap = gCb->u.dlCb->rlcKwuDlSap + RLC_UI_PDCP;
2583 /* Allocate memory for staInd Info */
2584 RLC_SHRABL_STATIC_BUF_ALLOC(rlckwuSap->pst.region, rlckwuSap->pst.pool, staInd, sizeof(KwuStaIndInfo));
2586 #if (ERRCLASS & ERRCLS_ADD_RES)
2587 if (staInd == NULLP)
2589 RLOG_ARG2(L_FATAL,DBG_RBID,rbCb->rlcId.rbId,
2590 "Memory allocation failed UEID:%d CELLID:%d",
2592 rbCb->rlcId.cellId);
2595 #endif /* ERRCLASS & ERRCLS_RES */
2597 /* Fill staInd Info */
2598 RLC_MEM_CPY(&staInd->rlcId, &rbCb->rlcId, sizeof(CmLteRlcId));
2601 staInd->sduId[0] = retx->sduMap.sdu->mode.am.sduId;
2605 RlcUiKwuStaInd(&rlckwuSap->pst, rlckwuSap->suId, staInd);
2606 #endif /* KW_PDCP */
2612 * @brief Handler to get the next node to be retransmitted from retxLst
2615 * This function is used to get the next node to be retransmitted
2618 * @param[in] gCb RLC instance control block
2619 * @param[in] retx The PDU/segment after which to find a node to be
2625 void rlcGetNxtRetx(RlcCb *gCb, RlcRetx **retx)
2631 tNode = &((*retx)->lstEnt);
2632 tNode = tNode->next;
2636 *retx = (RlcRetx *)tNode->node;
2643 }while((*retx)->pendingReTrans == FALSE);
2649 * @brief Handler to process the re-establishment request received from UIM
2651 * @param[in] gCb RLC instance control block
2652 * @param[in] rlcId Identity of the RB in the UE/Cell for which
2653 * re-establishment is to be done
2654 * @param[in] rbCb Downlink RB control block (rbCb is freed in this
2661 Void rlcAmmDlReEstablish
2668 Void rlcAmmDlReEstablish(gCb, rlcId, rbCb)
2674 /* create a new AM DL RB, reset it and replace in the UeCb*/
2679 RLC_ALLOC(gCb, resetRb, sizeof(RlcDlRbCb));
2681 /* ccpu00135170 Removing KLOCK warning */
2682 if(resetRb == NULLP)
2687 RLC_MEM_CPY(resetRb, rbCb, sizeof(RlcDlRbCb));
2688 RLC_MEM_SET(&resetRb->m.amDl, 0 , sizeof(RlcAmDl));
2690 /* AGHOSH changes start */
2691 /* restore the old AM values */
2692 newAmDl = &resetRb->m.amDl;
2693 oldAmDl = &rbCb->m.amDl;
2695 newAmDl->pollPdu = oldAmDl->pollPdu;
2696 newAmDl->pollByte = oldAmDl->pollByte;
2697 newAmDl->maxRetx = oldAmDl->maxRetx;
2698 newAmDl->snLen = oldAmDl->snLen;
2699 newAmDl->snModMask = oldAmDl->snModMask;
2700 newAmDl->pollRetxTmrInt = oldAmDl->pollRetxTmrInt;
2701 rbCb->boUnRprtdCnt = (U32)0;
2702 rbCb->lastRprtdBoToMac = (U32)0;
2703 cmInitTimers(&(resetRb->m.amDl.pollRetxTmr), 1);
2704 /* AGHOSH changes end */
2706 if (ROK != rlcDbmFetchDlUeCb(gCb,rlcId.ueId, rlcId.cellId, &ueCb))
2708 RLOG_ARG2(L_ERROR,DBG_CELLID, rlcId.cellId,
2709 "UeId [%d]: UeCb not found RBID;%d",
2715 if(rlcId.rbType == CM_LTE_SRB)
2717 ueCb->srbCb[rlcId.rbId] = resetRb;
2721 ueCb->drbCb[rlcId.rbId] = resetRb;
2723 /* update into the logical channel array also */
2724 ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = resetRb;
2726 if((resetRb->rlcId.rbType == CM_LTE_SRB)
2727 &&(resetRb->rlcId.rbId == 1))
2729 /* To stop the traffic on SRB2 and other DRBs*/
2730 rlcDlUtlSetReestInProgressForAllRBs(gCb, ueCb);
2734 rlcDlUtlSetReestInProgressForRB(gCb, resetRb);
2737 /* allocate the TX array again */
2741 resetRb->m.amDl.txBufLst,
2742 (RLC_TX_BUF_BIN_SIZE * sizeof(CmLListCp)));
2743 for(hashIndex = 0; hashIndex < RLC_TX_BUF_BIN_SIZE; hashIndex++)
2745 cmLListInit(&(resetRb->m.amDl.txBufLst[hashIndex]));
2748 /* send the old rb of deletion */
2749 rlcAmmFreeDlRbCb(gCb,rbCb);
2752 /* TODO: for now we are re-settting the re-establishment flag here
2753 this needs to be fixed
2754 There should be a proper intreface to resume the RBs */
2755 if(rlcId.rbType == CM_LTE_SRB)
2757 rlcDlUtlResetReestInProgress(ueCb->srbCb[rlcId.rbId]);
2761 rlcDlUtlResetReestInProgress(ueCb->drbCb[rlcId.rbId]);
2768 * @brief Handler to discard a SDU.
2771 * This function is used to discard a SDU after receiving
2772 * the Discard Request from UIM. The SDU is discarded if its
2773 * available and is not mapped to any PDU yet.
2775 * @param[in] gCb RLC instance control block
2776 * @param[in] rbCb RB control block
2777 * @param[in] sduId Sdu ID of the SDU to be discarded
2780 * -# ROK In case of successful discard
2781 * -# RFAILED In case the SDU is not found or already mapped
2791 S16 rlcAmmDiscSdu(gCb, rbCb, sduId)
2801 * @brief Handler for Poll retransmit timer expiry
2804 * This function is used to handle events upon expiry of Poll
2807 * @param[in] gCb RLC instance control block
2808 * @param[in] rbCb Downlink RB control block
2813 Void rlcAmmPollRetxTmrExp
2819 Void rlcAmmPollRetxTmrExp(gCb, rbCb)
2825 RlcAmDl *amDl = &(rbCb->m.amDl);
2829 /* kw003.201 - Correcting the logic for determmining whether to do */
2830 /* any transmission of PDU. As per the spec section */
2831 /* 5.2.2.3, if there is any to transmit or retransmit, */
2832 /* do nothing. Else, pick up the VT(S) -1 for retx */
2833 /* We have nothing to transmit if window is stalled or */
2834 /* there are no SDUs to be transmitted or if there are */
2835 /* PDUs to be retransmitted. */
2836 if(CM_LTE_SRB == rbCb->rlcId.rbType)
2838 gRlcStats.amRlcStats.numDLPollTimerExpiresSrb++;
2842 gRlcStats.amRlcStats.numDLPollTimerExpiresDrb++;
2845 if (((amDl->nxtTx == NULLP) && (amDl->nxtRetx == NULLP)) ||
2846 RLC_AM_IS_TRANS_WIN_STALLED(amDl))
2848 sn = (amDl->txNext - 1) & amDl->snModMask;
2849 txBuf = rlcUtlGetTxBuf(amDl->txBufLst, sn);
2853 rlcAmmDlMoveFrmTxtoRetxBuffer(gCb,amDl, &retx, sn);
2855 if (AMDL.nxtRetx == NULLP)
2857 AMDL.nxtRetx = retx;
2860 rlcAmmSendDedLcBoStatus(gCb, rbCb, &AMDL);
2863 /* Get the last node in retxLst */
2864 RLC_LLIST_LAST_RETX(amDl->retxLst, retx);
2866 /* Unset wtForAck flag for the NACK PDUs */
2869 rlcAmmDlMarkPduForReTx(gCb, rbCb, retx);
2870 rlcAmmSendDedLcBoStatus(gCb, rbCb, &AMDL);
2878 * @brief Handler to update Acks for the remaining PDUs after the last accessed
2882 * This function is used to handle ACKs for the PDUs remaining after the
2883 * last accessed NACK PDU, It updates the txBuf/retxBuf for the ACKs and
2884 * sends DatCfm to PDCP for the same.
2886 * @param[in] gCb RLC instance control block
2887 * @param[in] rbCb Downlink Radio Bearer control block
2888 * @param[in] mAckSn The ACK SN after doing the base modulus
2889 * @param[in] rextNode Next node in the re-transmission buffer
2896 PRIVATE Void rlcAmmDlUpdateTxAndReTxBufForAckSn
2902 KwuDatCfmInfo **datCfm
2905 PRIVATE Void rlcAmmDlUpdateTxAndReTxBufForAckSn(gCb, rbCb, mAckSn, retxNode, datCfm)
2910 KwuDatCfmInfo **datCfm;
2918 /* Remove pdus/segs from retxLst */
2921 retx = (RlcRetx *)(retxNode->node);
2922 retxNode = retxNode->next;
2923 MODAMT(retx->amHdr.sn, mSn, AMDL.txNextAck,AMDL.snModMask);
2926 rlcAmmDlProcessSuccessfulReTx(gCb,rbCb, retx, datCfm);
2930 /* For the remaining; pdus not acknowldeged by the NACK_SN but being
2931 acknowledged by the ACK_SN*/
2932 /* start from the starting of the transmission window and remove till just
2934 mSn = 0; /* same as MODAMT(AMDL.txNextAck, mSn, AMDL.txNextAck);*/
2935 sn = AMDL.txNextAck;
2938 txBuf = rlcUtlGetTxBuf(AMDL.txBufLst, sn);
2941 RLOG_ARG3(L_UNUSED,DBG_RBID,rbCb->rlcId.rbId,
2942 "rlcAmmDlUpdateTxAndReTxBufForAckSn: ACK for PDU "
2943 "with sn = %ld UEID:%ld CELLID:%ld",
2946 rbCb->rlcId.cellId);
2948 rlcAmmDlProcessSuccessfulTxPdu(gCb,rbCb, sn, datCfm);
2951 sn = (sn + 1) & AMDL.snModMask;
2952 MODAMT(sn, mSn, AMDL.txNextAck,AMDL.snModMask);
2959 * @brief Handler to update Acks for the remaining PDUs after the last accessed
2963 * This function is used to handle ACKs for the PDUs remaining after the
2964 * last accessed NACK PDU, It updates the txBuf/retxBuf for the ACKs and
2965 * sends DatCfm to PDCP for the same.
2967 * @param[in] gCb RLC instance control block
2968 * @param[in] rbCb Downlink Radio Bearer control block
2969 * @param[in] mAckSn The ACK SN after doing the base modulus
2970 * @param[in] rextNode Next node in the re-transmission buffer
2976 PRIVATE Void rlcAmmDlUpdTxAndReTxBufForLessThanNackSn
2983 KwuDatCfmInfo **datCfm
2986 PRIVATE Void rlcAmmDlUpdTxAndReTxBufForLessThanNackSn(gCb, rbCb, sn, mNackSn, retxNode, datCfm)
2992 KwuDatCfmInfo **datCfm;
3001 retx = (RlcRetx *)((*retxNode)->node);
3002 MODAMT(retx->amHdr.sn, mSn, AMDL.txNextAck,AMDL.snModMask);
3005 (*retxNode) = (*retxNode)->next;
3006 rlcAmmDlProcessSuccessfulReTx(gCb,rbCb, retx, datCfm);
3014 /* Remove all pdus with SN < NACK_SN from the transmission buffer */
3015 MODAMT(sn, mSn, AMDL.txNextAck,AMDL.snModMask);
3016 while (mSn < mNackSn)
3018 /* this if check seems redundant,why should mSn ever be mTxSn
3019 (which actually is VT(A) */
3020 txBuf = rlcUtlGetTxBuf(AMDL.txBufLst, sn);
3021 if ((txBuf != NULLP))
3023 RLOG_ARG3(L_DEBUG,DBG_RBID, rbCb->rlcId.rbId,
3024 "rlcHndlStaRsp: Handle ACK (sn = %d) UEID:%d CELLID:%d",
3027 rbCb->rlcId.cellId);
3029 /* Remove pdus from txBuf */
3030 rlcAmmDlProcessSuccessfulTxPdu(gCb,rbCb, sn, datCfm);
3033 sn = (sn + 1) & AMDL.snModMask;
3034 MODAMT(sn, mSn, AMDL.txNextAck,AMDL.snModMask);
3042 * @brief Handler to form construct AM header
3045 * This function is used to construct am header with the available header
3048 * @param[in] gCb RLC instance control block
3049 * @param[in] amHdr AM Header
3050 * @param[in] isSeg Check for Segmentation of PDU
3051 * @param[in] hdr Header field
3052 * @param[in] idx Index
3057 void rlcConstructAmHdr(RlcAmHdr *amHdr, uint8_t *hdr, uint8_t snLen, uint16_t *idx)
3060 hdr[0] = RLC_DATA_BITMASK;
3062 hdr[0] = hdr[0] | (amHdr->p << 6);
3063 hdr[0] = hdr[0] | ((amHdr->si & 0x3) << 4);
3064 if(snLen == RLC_AM_CFG_12BIT_SN_LEN)
3066 hdr[0] = hdr[0] | (U8)((amHdr->sn & 0xF00) >> 8);
3067 hdr[1] = (U8)(amHdr->sn & 0x0FF);
3072 hdr[0] = hdr[0] | (U8)((amHdr->sn & 0x30000) >> 16);
3073 hdr[1] = (U8)((amHdr->sn & 0xFF00) >> 8);
3075 hdr[2] = (U8)(amHdr->sn & 0xFF);
3079 if ((amHdr->si == RLC_SI_MID_SEG) || (amHdr->si == RLC_SI_LAST_SEG))
3082 hdr[(*idx)] = (U8)((amHdr->so & 0xFF00)>> 8);
3084 hdr[(*idx)] = (U8)(amHdr->so & 0xFF);
3091 * @brief This function adds a retx PDU to list of retx PDUs
3094 * kw003.201 - Poll expiry may cause an SN to be added to retx
3095 * out of sequence and hence all additions to retx
3096 * must validate that they are added in sequence
3098 * @param[in] amDl AM Downlink Control Block
3099 * @param[in] retx Retransmit PDU
3105 PRIVATE Void rlcAmmAddPduToRetxLst
3111 PRIVATE Void rlcAmmAddPduToRetxLst(amDl, retx)
3121 node = amDl->retxLst.last;
3122 MODAMT(retx->amHdr.sn, retxMSn, amDl->txNextAck,amDl->snModMask);
3123 while(node != NULLP)
3125 tRetx = (RlcRetx *)(node->node);
3126 MODAMT(tRetx->amHdr.sn, tMSn, amDl->txNextAck,amDl->snModMask);
3138 amDl->retxLst.crnt = node;
3139 cmLListInsAfterCrnt(&amDl->retxLst, &retx->lstEnt);
3140 retx->lstEnt.node = (PTR)retx;
3144 amDl->retxLst.crnt = amDl->retxLst.first;
3145 cmLListInsCrnt(&amDl->retxLst, &retx->lstEnt);
3146 retx->lstEnt.node = (PTR)retx;
3149 if (amDl->nxtRetx == NULLP)
3151 amDl->nxtRetx = retx;
3158 * @brief Handler to Move the PDU from txBuf to re-transmission buffer
3161 * This function is used to move the PDU from the txBuf to re-transmit buffer
3163 * @param[in] gCb RLC instance control block
3164 * @param[in] amDl AM Downlink Control Block
3165 * @param[in] retx node in the reTx buffer to be moved to, allocated by
3167 * @param[in] sn SN in the tx buffer which needs to be moved
3174 PRIVATE Void rlcAmmDlMoveFrmTxtoRetxBuffer
3182 PRIVATE Void rlcAmmDlMoveFrmTxtoRetxBuffer(gCb, amDl, retx, sn)
3189 RlcTx* txBuf = rlcUtlGetTxBuf(amDl->txBufLst, sn);
3195 while(txBuf->pduLst.first)
3197 RlcDlPduInfo *pduInfo = (RlcDlPduInfo *)(txBuf->pduLst.first->node);
3198 RLC_ALLOC_WC(gCb,*retx, sizeof(RlcRetx));
3200 #if (ERRCLASS & ERRCLS_ADD_RES)
3203 RLOG0(L_FATAL, "Memory allocation failed");
3206 #endif /* ERRCLASS & ERRCLS_RES */
3208 /* Move Sdu byte segment from TX buf to retx buf*/
3209 rlcAmmDlMoveSduByteSegFrmTxtoRetxBuffer(gCb,
3214 /* Delete node from the txBuf Pdu lst */
3215 cmLListDelFrm(&txBuf->pduLst, txBuf->pduLst.first);
3216 RLC_FREE_WC(gCb, pduInfo, sizeof(RlcDlPduInfo));
3218 /* Remove PDU from txBuf */
3219 rlcUtlDelTxBuf(amDl->txBufLst, txBuf,gCb);
3228 * function to free/release the Acknowledged mode RBCB buffers
3231 * This primitive Frees the Acknowledged Mode RbCb transmission Buffer,
3232 * retransmission Buffer and reciption Buffers
3234 * @param [in] gCb - RLC instance control block
3235 * @param [in] rbCb - Downlink RB Control Block
3240 Void rlcAmmFreeDlRbCb
3246 Void rlcAmmFreeDlRbCb(gCb,rbCb)
3251 /* stop the re-transmission timer */
3252 if(TRUE == rlcChkTmr(gCb,(PTR)rbCb,RLC_EVT_AMDL_POLL_RETX_TMR))
3254 rlcStopTmr(gCb,(PTR)rbCb, RLC_EVT_AMDL_POLL_RETX_TMR);
3257 /* store the entire Rb pointer */
3258 rbCb->rlsLnk.node = (PTR)rbCb;
3259 cmLListAdd2Tail(&gCb->u.dlCb->toBeFreed.rbLst, &rbCb->rlsLnk);
3262 cmLListCatLList(&(gCb->u.dlCb->toBeFreed.sduLst),&(rbCb->m.amDl.sduQ));
3264 rlcUtlRaiseDlCleanupEvent(gCb);
3270 * @brief Handler to create STATUS Pdu
3273 * This function is used to create status pdu
3275 * @param[in] gCb RLC instance control block
3276 * @param[in] rbCb Downlink RB control block
3277 * @param[in] rlcDatReq The data to be passed to MAC
3282 void rlcAmmCreateStatusPdu(RlcCb *gCb, RlcDlRbCb *rbCb, RlcDatReq *rlcDatReq)
3284 RlcSn sn; /* sequence number */
3285 RlcSn ack_sn; /* Ack sequence number */
3286 Buffer *mBuf; /* control pdu buffer */
3287 MsgLen cntrlPduSz; /* control pdu size */
3288 uint8_t cntrlPdu[RLC_MAX_CNTRL_FIELDS]; /* control pdu to be added to mBuf */
3289 RlcUdxDlStaPdu *pStaPdu;
3290 uint16_t bytesToEncode = 0; /* bytes required to encode the STATUS PDU */
3291 uint16_t encIdx = 0;
3292 uint16_t prevEncIdx = 0;
3293 RlcNackInfo *rlcNackInfo;
3296 pStaPdu = AMDL.pStaPdu;
3305 /* ACK SN Field will be set in the end based on available Grant */
3307 encIdx = bytesToEncode = 3; /* Num Octets before NACK SN info encoding*/
3309 ack_sn = pStaPdu->ackSn;
3311 if (rbCb->m.amDl.snLen == RLC_AM_CFG_12BIT_SN_LEN)
3314 /* If alteast one NACK SN Info then set the E1 field */
3315 if (pStaPdu->nackCount)
3325 for(nkCnt = 0;nkCnt < pStaPdu->nackCount; nkCnt++)
3327 sn = pStaPdu->nackInfo[nkCnt].sn;
3329 rlcNackInfo = &(pStaPdu->nackInfo[nkCnt]);
3331 bytesToEncode += 2; /* 2 Octets for NACK SN */
3333 /* Check if E2 : isSegment is set */
3334 if (rlcNackInfo->isSegment)
3336 bytesToEncode += 4; /* 4 Octets: SOstart, SOend */
3339 /* Check if E3 : nackRange is set */
3340 if (rlcNackInfo->nackRange)
3342 bytesToEncode += 1; /* 1 Octet: NACK range */
3345 /* Check if this NACK info can be accomodated in the Grant */
3346 if( rlcDatReq->pduSz >= bytesToEncode)
3348 /* If there is a NACK SN before this then set its
3352 /* NACKSN E1 E2 E3 R */
3353 cntrlPdu[prevEncIdx + 1] |= 0x8;
3356 /* 12 BIT Nack SN encode */
3357 cntrlPdu[encIdx] = (sn & 0xFF0) >> 4;
3360 cntrlPdu[encIdx + 1] = (sn & 0xF) << 4;
3362 if (rlcNackInfo->isSegment)
3365 cntrlPdu[encIdx + 1] |= 0x4;
3368 /* Add soStart and soEnd */
3370 cntrlPdu[encIdx + 2] = (rlcNackInfo->soStart) >> 8;
3371 cntrlPdu[encIdx + 3] = rlcNackInfo->soStart & 0xFF;
3374 cntrlPdu[encIdx + 4] = (rlcNackInfo->soEnd) >> 8;
3375 cntrlPdu[encIdx + 5] = rlcNackInfo->soEnd & 0xFF;
3378 if (rlcNackInfo->nackRange)
3381 cntrlPdu[encIdx + 1] |= 0x2;
3382 if(rlcNackInfo->isSegment)
3384 cntrlPdu[encIdx + 6] = rlcNackInfo->nackRange;
3388 cntrlPdu[encIdx + 2] = rlcNackInfo->nackRange;
3392 gRlcStats.amRlcStats.numDLNacksInStaPdu++;
3394 /* Set ACK SN now */
3397 ack_sn = rlcNackInfo->sn;
3399 /* Not even one nack can be accomodated */
3408 prevEncIdx = encIdx;
3409 encIdx = bytesToEncode;
3411 }/* Loop is done for the NackCount */
3416 DU_LOG("\nRLC: rlcAssembleCntrlInfo: ACK PDU's SN = %d"\
3417 "UEID:%d CELLID:%d", ack_sn, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
3419 cntrlPdu[0] |= (ack_sn & 0xF00)>> 8;
3420 cntrlPdu[1] = (U8)ack_sn;
3424 else if (rbCb->m.amDl.snLen == RLC_AM_CFG_18BIT_SN_LEN)
3426 /* If alteast one NACK SN Info then set the E1 field */
3427 if (pStaPdu->nackCount)
3437 for(nkCnt = 0;nkCnt < pStaPdu->nackCount; nkCnt++)
3439 sn = pStaPdu->nackInfo[nkCnt].sn;
3441 rlcNackInfo = &(pStaPdu->nackInfo[nkCnt]);
3443 bytesToEncode += 3; /* 3 Octets for NACK SN */
3445 /* Check if E2 : isSegment is set */
3446 if (rlcNackInfo->isSegment)
3448 bytesToEncode += 4; /* 4 Octets: SOstart, SOend */
3451 /* Check if E3 : nackRange is set */
3452 if (rlcNackInfo->nackRange)
3454 bytesToEncode += 1; /* 1 Octet: NACK range */
3457 /* Check if this NACK info can be accomodated in the Grant */
3458 if( rlcDatReq->pduSz >= bytesToEncode)
3460 /* If there is a NACK SN before this then set its
3464 /* NACKSN E1 E2 E3 R R R */
3465 cntrlPdu[prevEncIdx + 2] |= 0x20;
3468 /* 18 BIT Nack SN encode */
3469 cntrlPdu[encIdx] = (U8)((sn & 0x3FC00) >> 10);
3472 cntrlPdu[encIdx + 1] = (U8)((sn & 0x3FC) >> 2);
3475 cntrlPdu[encIdx + 2] = (U8)((sn & 0x3)<< 6);
3477 if (rlcNackInfo->isSegment)
3479 /* NACKSN E1 E2 E3 R R R */
3481 cntrlPdu[encIdx + 2] |= 0x10;
3484 /* Add soStart and soEnd */
3486 cntrlPdu[encIdx + 3] = (rlcNackInfo->soStart) >> 8;
3487 cntrlPdu[encIdx + 4] = (U8)rlcNackInfo->soStart;
3490 cntrlPdu[encIdx + 5] = (rlcNackInfo->soEnd) >> 8;
3491 cntrlPdu[encIdx + 6] = (U8)(rlcNackInfo->soEnd);
3494 if (rlcNackInfo->nackRange)
3496 /* NACKSN E1 E2 E3 R R R */
3498 cntrlPdu[encIdx + 2] |= 0x08;
3500 if (rlcNackInfo->isSegment)
3502 cntrlPdu[encIdx + 7] = rlcNackInfo->nackRange;
3506 cntrlPdu[encIdx + 3] = rlcNackInfo->nackRange;
3510 gRlcStats.amRlcStats.numDLNacksInStaPdu++;
3512 /* Set ACK SN now */
3515 ack_sn = rlcNackInfo->sn;
3517 /* Not even one nack can be accomodated */
3520 cntrlPdu[2] &= 0xFD;
3526 prevEncIdx = encIdx;
3527 encIdx = bytesToEncode;
3529 }/* Loop is done for the NackCount */
3534 DU_LOG("\nRLC: rlcAssembleCntrlInfo: ACK PDU's SN = %d"
3535 "UEID:%d CELLID:%d", ack_sn, rbCb->rlcId.ueId,rbCb->rlcId.cellId);
3537 cntrlPdu[0] |= (ack_sn & 0x3C000) >> 14;
3538 cntrlPdu[1] = (ack_sn & 0x3FC0) >> 6;
3539 cntrlPdu[2] |= (ack_sn & 0x3F)<< 2;
3546 DU_LOG("\nRLC: rlcAssembleCntrlInfo:Conf SN LEN %d is INVALID !!!! \
3547 UEID:%d CELLID:%d", rbCb->m.amDl.snLen, rbCb->rlcId.ueId,
3548 rbCb->rlcId.cellId);
3553 SGetMsg(RLC_GET_MEM_REGION(gCb), RLC_GET_MEM_POOL(gCb),&mBuf);
3555 mBuf = (Buffer *)rlcAmmStaPduList[rlcAmmStaPduListCnt++];
3557 if(rlcAmmStaPduListCnt > 511)
3558 rlcAmmStaPduListCnt = 0;
3561 cntrlPduSz = encIdx;
3562 ODU_ADD_POST_MSG_MULT(cntrlPdu, cntrlPduSz, mBuf);
3564 rlcDatReq->pduSz -= cntrlPduSz;
3565 /* Add mBuf to AMDL.mBuf */
3571 #ifdef RLC_STA_PROC_IN_MAC/* RLC Status PDU Processing */
3573 S16 rlcProcDlStatusPdu(Pst *udxPst,SuId suId,
3574 CmLteCellId cellId,CmLteRnti rnti,CmLteLcId lcId,Buffer *rlcSdu);
3577 PRIVATE Void rgAmmExtractElmnt
3584 PRIVATE Void rgAmmExtractElmnt(gCb, pdu, hdrInfo)
3591 U8 pLen = hdrInfo->pLen;
3592 U8 len = (U8)hdrInfo->len;
3604 SRemPreMsg(&hdr, pdu);
3610 val = tHdr >> (RLC_BYTE_LEN - (len));
3614 else /*if (len > 8) */
3618 val = val >> (RLC_BYTE_LEN - fLen);
3619 val = val << (len - fLen);
3621 SRemPreMsg(&hdr, pdu);
3625 hdr = hdr >> (RLC_BYTE_LEN - rLen);
3628 pLen = (RLC_BYTE_LEN - rLen);
3632 rLen = rLen - RLC_BYTE_LEN;
3634 tVal = tVal << rLen;
3637 SRemPreMsg(&hdr, pdu);
3639 hdr = hdr >> (RLC_BYTE_LEN - rLen);
3642 pLen = (RLC_BYTE_LEN - rLen);
3646 hdrInfo->pLen = pLen;
3657 PRIVATE Void rgAmmUlHndlStatusPdu
3667 PRIVATE Void rgAmmUlHndlStatusPdu(udxPst,suId,gCb, rbCb, cntrlPdu, fByte)
3678 RlcUdxStaPdu *pStaPdu;
3679 U8 e3; /* NACK RANGE : 5GNR */
3682 U32 resrvdBitsAckSn;
3683 U32 resrvdBitsNackSn;
3685 RLCDBGP_BRIEF(gCb, "rgAmmUlHndlStatusPdu(rbCb, cntrlPdu, fByte) \n");
3687 RLC_MEM_ZERO(&hdrInfo, sizeof(RlcExtHdr));
3689 /* Extract the Control PDU */
3690 hdrInfo.hdr = (*fByte << 1);
3693 /* D/C has been shifted in the calling function */
3694 if (hdrInfo.hdr & 0xE0)
3696 RLCDBGP_ERROR(gCb, "rgAmmUlHndlStatusPdu: Reserved value for CPT received \n");
3700 RLC_ALLOC_SHRABL_BUF(udxPst->region,
3703 sizeof(RlcUdxStaPdu));
3705 #if (ERRCLASS & ERRCLS_ADD_RES)
3706 /* Memory allocation failure can not be expected */
3713 if (rbCb->m.amDl.snLen == RLC_AM_CFG_12BIT_SN_LEN)
3716 resrvdBitsAckSn = RLC_STA_PDU_R_BITS_ACKSN_12BITS;
3717 resrvdBitsNackSn = RLC_STA_PDU_R_BITS_NACKSN_12BITS;
3719 else if (rbCb->m.amDl.snLen == RLC_AM_CFG_18BIT_SN_LEN)
3722 resrvdBitsAckSn = RLC_STA_PDU_R_BITS_ACKSN_18BITS;
3723 resrvdBitsNackSn = RLC_STA_PDU_R_BITS_NACKSN_18BITS;
3728 resrvdBitsAckSn = 0;
3729 resrvdBitsAckSn = 0;
3732 pStaPdu->nackCnt = 0;
3734 hdrInfo.hdr = hdrInfo.hdr << RLC_CPT_LEN;
3737 hdrInfo.len = RLC_SN_LEN;
3738 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3739 pStaPdu->ackSn = hdrInfo.val;
3741 /* Check if NACK Exists */
3742 hdrInfo.len = RLC_E1_LEN;
3743 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3744 e1 = (U8)hdrInfo.val;
3745 RLCDBGP_DETAIL(gCb, "rgAmmUlHndlStatusPdu: ACK SN = %d \n", pStaPdu->ackSn);
3747 /* Extract the Reserved Bits after ACK SN field */
3748 hdrInfo.len = resrvdBitsAckSn;
3749 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3752 /* If NACK exists in control PDU */
3753 /* For ACKs and NACKs */
3754 while (e1 && (pStaPdu->nackCnt < RLC_MAX_NACK_CNT))
3756 hdrInfo.len = snLen;
3757 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3758 pStaPdu->nackInfo[pStaPdu->nackCnt].sn = hdrInfo.val;
3760 hdrInfo.len = RLC_E1_LEN;
3761 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3762 e1 = (U8)hdrInfo.val;
3765 /* hdrInfo.len = RLC_E1_LEN; --> previusly stored value (for e1) is
3767 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3768 /* e2 = (U8) hdrInfo.val;*/
3770 /* Store e2 value */
3771 pStaPdu->nackInfo[pStaPdu->nackCnt].isSegment = (U8) hdrInfo.val;
3773 /* Extract e3 : 5GNR */
3774 /* hdrInfo.len = RLC_E1_LEN; --> previusly stored value (for e1) is
3776 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3777 e3 = (U8) hdrInfo.val;
3779 /* Extract Reserved Bits after NACK SN */
3780 hdrInfo.len = resrvdBitsNackSn;
3781 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3783 /* Test for resegmentation */
3784 if (pStaPdu->nackInfo[pStaPdu->nackCnt].isSegment)
3786 hdrInfo.len = RLC_SO_LEN_5GNR; /* 5GNR : SO Len 16 Bits */
3787 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3788 pStaPdu->nackInfo[pStaPdu->nackCnt].soStart = hdrInfo.val;
3790 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3791 pStaPdu->nackInfo[pStaPdu->nackCnt].soEnd = hdrInfo.val;
3794 "rgAmmUlHndlStatusPdu: soStart and soEnd = %d %d \n",
3795 pStaPdu->nackInfo[pStaPdu->nackCnt].soStart,
3796 pStaPdu->nackInfo[pStaPdu->nackCnt].soEnd);
3801 pStaPdu->nackInfo[pStaPdu->nackCnt].soStart = 0;
3802 pStaPdu->nackInfo[pStaPdu->nackCnt].soEnd = 0;
3805 /* NACK RANGE Field is SET */
3808 /* Extract NACK range field */
3809 hdrInfo.len = RLC_NACK_RANGE_LEN;
3810 rgAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
3811 snRange = (U8)hdrInfo.val;
3813 pStaPdu->nackInfo[pStaPdu->nackCnt].nackRange = snRange;
3819 gRlcStats.amRlcStats.numULStaPduRcvd++;
3820 gRlcStats.amRlcStats.numULNackInStaPduRcvd += pStaPdu->nackCnt;
3822 /* In case we have reached the MAX NACK CNT, then we should modify the ACK_SN
3823 to the last NACK SN + 1 and discard the original ACK_SN*/
3824 if(pStaPdu->nackCnt == RLC_MAX_NACK_CNT)
3826 pStaPdu->ackSn = (pStaPdu->nackInfo[RLC_MAX_NACK_CNT-1].sn + 1) & amDl->snModMask;
3830 /* Parse & send Status PDU to RLC-DL */
3831 //rlcUlUdxStaUpdReq(&(sapCb->pst), sapCb->spId, &rbCb->rlcId, pStaPdu);
3832 rlcUlUdxStaUpdReq(udxPst, suId, &rbCb->rlcId, pStaPdu);
3837 S16 rlcProcDlStatusPdu(Pst *udxPst,SuId suId,
3838 CmLteCellId cellId,CmLteRnti rnti,CmLteLcId lcId,Buffer *rlcSdu)
3840 RlcDlRbCb *rbCb = NULLP;
3841 RlcDlUeCb *ueCb = NULLP;
3844 S16 retVal = RFAILED;
3846 Pst dlRlcPst = *udxPst;
3848 gCb = RLC_GET_RLCCB(1); /* DL RLC instance */
3850 if( ROK != rlcDbmFetchDlUeCb(gCb,rnti,cellId,&(ueCb)))
3852 printf("\n RLC UECb Not found...\n");
3857 rbCb = ueCb->lCh[lcId - 1].dlRbCb;
3859 /* Skip if mode is not AM */
3860 if((rbCb == NULLP) || (rbCb->mode != CM_LTE_MODE_AM))
3865 if(ROK != SExamMsg((Data *)(&fByte),
3868 printf("\n Failure in Rlc Hdr SExamMsg\n");
3872 if(RLC_CNTRL_PDU == ((fByte & RLC_DC_POS) >> RLC_DC_SHT))
3874 SRemPreMsg(&temp, rlcSdu);
3875 dlRlcPst.selector = 1;/* LWLC*/
3876 rgAmmUlHndlStatusPdu(&dlRlcPst,suId,gCb, rbCb, rlcSdu, &fByte);
3890 /********************************************************************30**
3893 **********************************************************************/