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 /************************************************************************
25 Desc: C source code for Entry point fucntions
29 **********************************************************************/
32 @brief MAC Multiplexing API.
36 /* header include files -- defines (.h) */
37 #include "common_def.h"
38 #include "rg_env.h" /* MAC Environment Defines */
39 #include "tfu.h" /* TFU Interface defines */
40 #include "crg.h" /* CRG Interface defines */
41 #include "rg_sch_inf.h" /* RGR Interface defines */
42 #include "rgu.h" /* RGU Interface defines */
43 #include "lrg.h" /* LRG Interface defines */
45 #include "rg_err.h" /* MAC error defines */
46 #include "rg.h" /* MAC defines */
48 /* header/extern include files (.x) */
50 #include "rgu.x" /* RGU Interface includes */
51 #include "tfu.x" /* CRG Interface includes */
52 #include "crg.x" /* CRG Interface includes */
53 #include "rg_sch_inf.x" /* SCH Interface includes */
54 #include "rg_prg.x" /* PRG Interface includes */
55 #include "rgu.x" /* RGU Interface includes */
56 #include "lrg.x" /* LRG Interface includes */
58 #include "du_app_mac_inf.h"
59 #include "rg.x" /* MAC includes */
63 #include "ss_msg.x" /* MAC includes */
65 #ifndef T2K_MEM_LEAK_DBG
66 S16 ssGetDBufOfSize(Region region,Size size,Buffer **dBuf);
68 char* file = __FILE__;
69 uint32_t line = __LINE__;
74 /* global variables */
75 uint32_t rgDlrate_rgu;
79 static Void rgMUXGet20bitRarGrnt ARGS((uint8_t ulBw,
80 RgInfRarUlGrnt *msg3Grnt,
82 uint16_t rgMUXCalcRiv ARGS((uint8_t bw,
86 #ifndef MS_MBUF_CORRUPTION
87 #define MS_BUF_ADD_ALLOC_CALLER()
89 /* forward references */
91 #define RG_PACK_SHDR_FIXD_SZ(_subHdr, _lcId, _mBuf, _ret) {\
92 _subHdr.shLen = RG_FIXDSZ_CE_SHDR_LEN;\
93 _subHdr.shData[0] = (0x3F & _lcId);\
94 MS_BUF_ADD_ALLOC_CALLER(); \
95 _ret = SAddPstMsgMult(&_subHdr.shData[0], _subHdr.shLen, _mBuf);\
98 #define RG_PACK_CE(_ce, _len, _ceBuf, _ret) {\
99 MS_BUF_ADD_ALLOC_CALLER(); \
100 _ret = SAddPstMsgMult((uint8_t *)(&(_ce)), _len, _ceBuf);\
103 #define RG_MUX_CALC_LEN(_len,_lenBytes,_elmTotLen) {\
105 _lenBytes = (_len <= 255) ? 1 : 2;\
106 _hdrLen = _lenBytes + RG_SDU_SHDR_LEN;\
107 _elmTotLen = _hdrLen + _len;\
110 #define RG_PACK_VAR_SZ_CE_SDU_SHDR(_subHdr, _lcId, _len,_mBuf, _ret) {\
114 _subHdr.shData[0] = (0x3F & _lcId);\
116 _subHdr.shData[1] = (0xFF & _len);\
117 _subHdr.shData[2] = 0;\
121 _subHdr.shData[0] = (0x7F & ((0x40) | _lcId));\
123 _subHdr.shData[1] = (0xFF & (_len >> 8));\
124 _subHdr.shData[2] = (0xFF & _len);\
126 MS_BUF_ADD_ALLOC_CALLER(); \
127 _ret = SAddPstMsgMult(&_subHdr.shData[0], _subHdr.shLen, _mBuf);\
130 #define RG_PACK_PAD_SHDR(_mBuf, _ret) {\
131 _ret = SAddPreMsg(0x3F, _mBuf);\
134 #define RG_PACK_RAR_SHDR(_byte, _mBuf, _ret) {\
135 _ret = SAddPstMsg(_byte, _mBuf);\
140 * @brief Function to add ces along with subhdrs.
141 * This function packs first CE sub-hdr and then CE in ceBuf pointer
145 * Function : rgMUXAddCes
147 * @param[in] Inst inst
148 * @param[in] RgBldPduInfo *pdu
149 * @param[in] Buffer *ceBuf
150 * @param[in] RgErrInfo *err
155 static S16 rgMUXAddCes
166 if (NULLP != pdu->contResId)
168 if(pdu->schdTbSz >= RG_CRES_ELM_LEN)
170 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_CRES_LCID_IDX, ceBuf, ret);
174 err->errCause = RGERR_MUX_BLD_CEHDR_FAIL;
175 DU_LOG("\nERROR --> MAC : Muxing of Contention Resolution CE sub-header is failed");
179 RG_PACK_CE(pdu->contResId->resId[0], RG_CRES_LEN, ceBuf, ret);
183 err->errCause = RGERR_MUX_BLD_CE_FAIL;
184 DU_LOG("\nERROR --> MAC : Muxing of Contention Resolution CE is failed");
187 pdu->schdTbSz -= RG_CRES_ELM_LEN;
190 if (TRUE == pdu->ta.pres)
192 if(pdu->schdTbSz >= RG_TA_ELM_LEN)
194 uint8_t taVal; /* Moving from outer scope to available scope */
195 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_TA_LCID_IDX, ceBuf, ret);
199 err->errCause = RGERR_MUX_BLD_CEHDR_FAIL;
200 DU_LOG("\nERROR --> MAC : Muxing of TA CE sub-hdr is failed");
205 RG_PACK_CE(taVal, RG_TA_LEN, ceBuf, ret);
209 err->errCause = RGERR_MUX_BLD_CE_FAIL;
210 DU_LOG("\nERROR --> MAC : Muxing of TA CE is failed");
213 pdu->schdTbSz -= RG_TA_ELM_LEN;
214 DU_LOG("\nDEBUG --> MAC : TA muxed by MAC: %u", pdu->ta.val);
218 if(TRUE == pdu->sCellActCe.pres)
220 if(pdu->schdTbSz >= RG_SCELL_CE_ELM_LEN)
222 /* Adding the subheader for ACT CE */
223 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_SCELL_LCID_IDX, ceBuf, ret);
227 err->errCause = RGERR_MUX_BLD_CEHDR_FAIL;
228 DU_LOG("\nERROR --> MAC : Muxing of SCELL Activation CE sub-hdr is failed")
232 /* Adding the ACT CE */
233 RG_PACK_CE(pdu->sCellActCe.val, RG_SCELL_ACT_CE_LEN, ceBuf, ret);
237 err->errCause = RGERR_MUX_BLD_CE_FAIL;
238 DU_LOG("\nERROR --> MAC : Muxing of SCELL Activation CE is failed")
241 pdu->schdTbSz -= RG_SCELL_CE_ELM_LEN;
247 /*LcId is not yet decided in 5G-NR spec for MAC CEs Hence, not writing code
254 * @brief Function to insert SDU along with sub headers.
258 * Function : rgMUXInsSdu
260 * @param[in] Inst inst
261 * @param[in] MsgLen *schdTbSz
262 * @param[in] uint8_t lcId
263 * @param[in] Buffer *sdu
264 * @param[out] Buffer *sduBuf
265 * @param[out] RgErrInfo *err
270 static S16 rgMUXInsSdu
285 SFndLenMsg(sdu, &msgLen);
287 RG_MUX_CALC_LEN(msgLen,lenBytes,elmTotLen);
291 rgDlrate_rgu += msgLen;
293 if (*schdTbSz >= elmTotLen)
296 RG_PACK_VAR_SZ_CE_SDU_SHDR(subHdr, lcId, msgLen,sduBuf, ret);
299 err->errCause = RGERR_MUX_BLD_SDUHDR_FAIL;
300 DU_LOG("\nERROR --> MAC : RGERR_MUX_BLD_SDUHDR_FAIL for LCID:%d",lcId);
304 #ifndef L2_OPTMZ /* no need to pack as passing not muxing all LCs PDUs to 1*/
305 RG_PACK_SDU(sduBuf, sdu, ret);
314 err->errCause = RGERR_MUX_BLD_SDU_FAIL;
315 DU_LOG("\nERROR --> MAC : RGERR_MUX_BLD_SDU_FAIL for LCID:%d",lcId);
319 *schdTbSz -= elmTotLen;
323 /* This Sub-PDU can not be accodmodated at all */
324 DU_LOG("\nERROR --> MAC : Failed lcId %u, elmTotLen %d lenBytes %d LCID:%d",
325 lcId, ((S16)elmTotLen), lenBytes,lcId);
326 DU_LOG("\nERROR --> MAC : msglen %d schdTbSz %d LCID:%d",
327 ((S16)msgLen), ((S16)*schdTbSz),lcId);
334 * @brief Function to insert SDU along with sub headers.
338 * Function : rgMUXAddPadd
340 * @param[in] Inst inst
341 * @param[in] RgBldPduInfo *pdu
342 * @param[out] Buffer *mBuf
343 * @param[out] Buffer *sduBuf
349 uint32_t padSize = 0;
361 Buffer *padBuf = NULLP;
372 if((FALSE == isRar) && (NULL != sHdrBuf))
376 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_PAD_LCID_IDX, sduBuf, ret);
380 err->errCause = RGERR_MUX_BLD_PADHDR_FAIL;
381 DU_LOG("\nERROR --> MAC : RGERR_MUX_BLD_PADHDR_FAIL");
390 if (*schdTbSz <= RG_MAX_PAD_ARR_SZ)
393 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
397 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
400 padSize += *schdTbSz;
404 err->errCause = RGERR_MUX_BLD_PAD_FAIL;
405 DU_LOG("\nERROR --> MAC : RGERR_MUX_BLD_PAD_FAIL");
414 if (*schdTbSz > RG_MAX_PAD_ARR_SZ)
417 RG_PACK_PAD(padBuf,RG_MAX_PAD_ARR_SZ,sduBuf);
421 RG_PACK_PAD(padBuf,RG_MAX_PAD_ARR_SZ,sduBuf);
424 padSize += RG_MAX_PAD_ARR_SZ;
429 err->errCause = RGERR_MUX_BLD_PAD_FAIL;
430 DU_LOG("\nERROR --> MAC : RGERR_MUX_BLD_PAD_FAIL");
434 *schdTbSz -= RG_MAX_PAD_ARR_SZ;
439 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
443 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
446 padSize += *schdTbSz;
451 err->errCause = RGERR_MUX_BLD_PAD_FAIL;
452 DU_LOG("\nERROR --> MAC : RGERR_MUX_BLD_PAD_FAIL");
468 * @brief Function to add SDU along with sub headers.
472 * Function : rgMUXAddSdus
474 * @param[in] Inst inst
475 * @param[in] RgBldPduInfo *pdu
476 * @param[out] Buffer *mBuf
477 * @param[out] Buffer *sduBuf
482 static S16 rgMUXAddSdus
490 RgRguDDatReqPerUe *dDatReq;
491 RgRguCmnDatReq *cDatReq;
496 cDatReq = (RgRguCmnDatReq *)(pdu->datReq);
497 /* Add sdu(s) to the Message Buffer */
498 if (NULLP != cDatReq)
500 if(rgMUXInsSdu(inst,&pdu->schdTbSz,
501 RG_CCCH_LCID, cDatReq->pdu, sduBuf, err) != ROK)
505 RG_FREE_MSG(cDatReq->pdu);
510 dDatReq = (RgRguDDatReqPerUe *)(pdu->datReq);
511 /* Add sdu(s) to the Message Buffer */
512 if (NULLP != dDatReq)
514 if(pdu->tbIndex == 1)
517 /* Adding this temporary variable for optimization */
518 RguDatReqTb *datReqTb = &dDatReq->datReqTb[0];
520 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
523 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
528 if(rgMUXInsSdu(inst,&pdu->schdTbSz,
529 datReqTb->lchData[idx1].lcId,
530 datReqTb->lchData[idx1].pdu.mBuf[idx2],
533 DU_LOG("\nERROR --> MAC : FAILED for LCID:%d",datReqTb->lchData[idx1].lcId);
537 RG_FREE_MSG(datReqTb->lchData[idx1].pdu.mBuf[idx2]);
541 else if(pdu->tbIndex == 2)
544 RguDatReqTb *datReqTb = &dDatReq->datReqTb[1];
545 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
548 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
553 if(rgMUXInsSdu(inst,&pdu->schdTbSz,
554 datReqTb->lchData[idx1].lcId,
555 datReqTb->lchData[idx1].pdu.mBuf[idx2],
558 DU_LOG("\nERROR --> MAC : FAILED TB Size %d LCID:%d",
559 ((S16)pdu->schdTbSz),datReqTb->lchData[idx1].lcId);
563 RG_FREE_MSG(datReqTb->lchData[idx1].pdu.mBuf[idx2]);
572 } /* End of switch(reqType) */
573 if(rgMUXAddPadd(inst,&pdu->schdTbSz, sduBuf, FALSE, err) != ROK)
575 DU_LOG("\nERROR --> MAC : FAILED for TB Size:%d",(S16)pdu->schdTbSz);
582 * @brief Function to create MAC PDU from RLC SDUs and control elements, if any.
586 * Function : rgMUXBldPdu
588 * -# This function shall be invoked by Downlink Harq Module as soon as a
589 * Data request is received from RLC for a UE along with its stored
590 * control elements to create a MAC PDU.
591 * -# It shall create subheaders for the control elements (timing advance
592 * and contention resolution ID) and pack sub-header before each CE,
593 * if given, and then shall run through all the logical channels and
594 * create subheader for each of the SDUs given on that logical channel
595 * and pack corresponding sub-header before the each SDU
596 * -# It shall invoke rgMUXPadPdu if the total length of the created
597 * buffer is less than the scheduled TB size.
600 * @param[in] Inst *inst
601 * @param[in] RgBldPduInfo *bldPdu
602 * @param[in] Buffer **txPdu
603 * @param[out] RgErrInfo *err
616 Buffer *mBuf = NULLP;
618 if (rgGetMsg(inst, &mBuf) != ROK)
620 /* Buffer couldnt get allocated. Return a failure */
621 err->errCause = RGERR_MUX_MEM_ALLOC_FAIL;
622 err->errType = RGERR_MUX_BLD_PDU;
623 DU_LOG("\nERROR --> MAC : Memory allocation failed during MUXing of MAC TB: MacInst %d", inst);
627 if(rgMUXAddCes(inst, pdu, mBuf, err) != ROK)
630 err->errType = RGERR_MUX_BLD_PDU;
631 DU_LOG("\nERROR --> MAC : Failed to Multiplex MAC CEs: MacInst %d", inst);
635 if(rgMUXAddSdus(inst, pdu, mBuf, err) != ROK)
638 err->errType = RGERR_MUX_BLD_PDU;
639 DU_LOG("\nERROR --> MAC : FAILED to Multiplex MAC SDU: MacInst %d", inst);
649 #else /* else of ifndef L2_OPTMZ */
652 * @brief Function to add SDU along with sub headers.
656 * Function : rgMUXAddSdus
658 * @param[in] RgBldPduInfo *pdu
659 * @param[out] Buffer *mBuf
660 * @param[out] Buffer *sduBuf
665 static S16 rgMUXAddSdus
670 RgTfuDatReqTbInfo *tb,
674 RgRguDDatReqPerUe *dDatReq;
675 RgRguCmnDatReq *cDatReq;
676 uint32_t lchIdx, pduIdx;
681 cDatReq = (RgRguCmnDatReq *)(pdu->datReq);
682 /* Add sdu(s) to the Message Buffer */
683 if (NULLP != cDatReq)
685 if(rgMUXInsSdu(inst, &pdu->schdTbSz,
686 RG_CCCH_LCID, cDatReq->pdu,
687 sHdrBuf, NULLP, err) != ROK)
691 /* L2 Optimization for mUe/Tti: RLC pdu mbuf pointer will be passed
692 * to CL it is stored in DlHqProc->TbInfo and it will be used in
693 * case of harq retransmission. Store CCCH data at 0th index of
695 tb->lchInfo[tb->numLch].mBuf[(tb->lchInfo[tb->numLch].numPdu)]\
697 tb->lchInfo[tb->numLch].numPdu++;
699 DU_LOG("\nINFO --> MAC : MSG4 is muxed numLch=%ld numPdu=%ld tbaddr =%p",\
700 tb->numLch,tb->lchInfo[tb->numLch-1].numPdu, (uint32_t)tb);
705 dDatReq = (RgRguDDatReqPerUe *)(pdu->datReq);
706 /* Add sdu(s) to the Message Buffer */
707 if (NULLP != dDatReq)
709 if(pdu->tbIndex == 1)
712 /* Adding this temporary variable for optimization */
713 RguDatReqTb *datReqTb = &dDatReq->datReqTb[0];
715 tb->numLch = lchIdx = 0;
717 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
719 tb->lchInfo[lchIdx].numPdu = pduIdx = 0;
722 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
727 if(rgMUXInsSdu(inst, &pdu->schdTbSz,
728 datReqTb->lchData[idx1].lcId,
729 datReqTb->lchData[idx1].pdu.mBuf[idx2],
730 sHdrBuf, NULLP, err) != ROK)
732 DU_LOG("\nERROR --> MAC : Failed to insert SDU in rgMUXAddSdus\n");
736 /* L2 Optimization for mUe/Tti:Increment numPdu by 1
737 * Store pdu buffer in tb to send it to CL/PHY. Increment
739 tb->lchInfo[lchIdx].mBuf[pduIdx] = datReqTb->lchData[idx1].pdu.mBuf[idx2];
742 if(datReqTb->lchData[idx1].freeBuff == FALSE)
743 {/* Not incrementing refCnt for UM Mode. */
744 tb->lchInfo[lchIdx].mBuf[pduIdx]->refCnt++;
748 if(NULL != datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont)
751 tmp = datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont;
752 if(NULL == tmp->b_rptr)
754 DU_LOG("\nERROR --> MAC : rgMUXAddSdus failed in EVTRGUDDATREQ");
759 DU_LOG("\nERROR --> MAC : rgMUXAddSdus failed in EVTRGUDDATREQ");
762 //tb->lchInfo[tb->numLch].numPdu++;
770 tb->lchInfo[lchIdx].numPdu = pduIdx;
771 /* If Bearer is UM then MBUF to be free by MAC layer */
772 tb->lchInfo[lchIdx].freeBuff = datReqTb->lchData[idx1].freeBuff;
778 else if(pdu->tbIndex == 2)
781 RguDatReqTb *datReqTb = &dDatReq->datReqTb[1];
782 tb->numLch = lchIdx = 0;
783 // prc_trace_format_string(0x40,3,": AddSdus: numOfLch=%d numOfPdu=%d, schdSz=%d", datReqTb->nmbLch, datReqTb->lchData[0].pdu.numPdu, pdu->schdTbSz);
784 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
786 tb->lchInfo[lchIdx].numPdu = pduIdx = 0;
788 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
793 if(rgMUXInsSdu(inst, &pdu->schdTbSz,
794 datReqTb->lchData[idx1].lcId,
795 datReqTb->lchData[idx1].pdu.mBuf[idx2],
796 sHdrBuf, NULLP, err) != ROK)
798 DU_LOG("\nERROR --> MAC : FAILED TB Size %d\n",
799 ((S16)pdu->schdTbSz));
802 /* L2 Optimization for mUe/Tti:Increment numPdu by 1
803 * Store pdu buffer in tb to send it to CL/PHY. Increment
805 tb->lchInfo[lchIdx].mBuf[pduIdx] = datReqTb->lchData[idx1].pdu.mBuf[idx2];
807 if(datReqTb->lchData[idx1].freeBuff == FALSE)
808 {/* Not incrementing refCnt for UM Mode. */
809 tb->lchInfo[lchIdx].mBuf[pduIdx]->refCnt++;
812 if(NULL != datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont)
815 tmp = datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont;
816 if(NULL == tmp->b_rptr)
818 DU_LOG("\nERROR --> MAC : rgMUXAddSdus failed in EVTRGUDDATREQ");
823 DU_LOG("\nERROR --> MAC : rgMUXAddSdus failed in EVTRGUDDATREQ");
826 // tb->lchInfo[tb->numLch].numPdu++;
834 tb->lchInfo[lchIdx].numPdu = pduIdx;
835 /* If Bearer is UM then MBUF to be free by MAC layer */
836 tb->lchInfo[lchIdx].freeBuff = datReqTb->lchData[idx1].freeBuff;
846 case EVENT_SLOT_IND_TO_MAC:
850 } /* End of switch(reqType) */
853 if(rgMUXAddPadd(inst, &pdu->schdTbSz, sduBuf, NULLP, FALSE, err) != ROK)
855 //RGDBGERRNEW((rgPBuf, "FAILED"));
858 tb->padSize = padSize;
864 * @brief Function to create MAC PDU from RLC SDUs and control elements, if any.
868 * Function : rgMUXBldPdu
869 * -# This function shall be invoked by Downlink Harq Module as soon as a
870 * Data request is received from RLC for a UE along with its stored
871 * control elements to create a MAC PDU.
872 * -# It shall create subheaders for the control elements (timing advance
873 * and contention resolution ID), if given, and then shall run through
874 * all the logical channels and create subheader for each of the SDUs
875 * given on that logical channel.
876 * -# L2 Optimization for mUe/Tti: Avoiding muxing to reduce overhead of
877 * additional Mbuf allocation memory related operation.
878 -# MAC header, MAC CEs, MAC PDUs and MAC padding are stored in pre-
879 allocated mBufs. These pointers will not be freed by CL
880 * -# It shall invoke rgMUXPadPdu if the total length of the created
881 * buffer is less than the scheduled TB size.
882 * -# At successfull operation of this function tb->macHdr, will have
883 * complete MAC Header. tb->macCes will have MAC CEs if any. tb->
884 * lchInfo[idx].mBuf[idx] will have MAC SDU per LCH per TB per UE
887 * @param[in] RgBldPduInfo *bldPdu
888 * @param[out] RgTbInfo *tb
889 * @param[out] RgErrInfo *err
898 RgTfuDatReqTbInfo *tb,
902 Buffer *mBuf1; /* MAC hearder */
903 Buffer *mBuf2; /* MAC CEs */
904 //uint32_t lchIdx, pduIdx;
906 /* Reseting macHdr and macCes pointers */
908 SResetMBuf(tb->macHdr);
910 SResetMBuf(tb->macCes);
912 mBuf1 = tb->macHdr; /* MAC hearder */
913 mBuf2 = tb->macCes; /* MAC CEs */
914 tb->tbSize = pdu->schdTbSz;
916 if(rgMUXAddCes(inst, pdu, mBuf1, mBuf2, err) != ROK)
918 /* Reset rPtr and wPtr to the base of data buffer(db_base)*/
919 DU_LOG("\nERROR --> MAC : rgMUXBldPdu: rgMUXAddCes is Failed \n");
921 err->errType = RGERR_MUX_BLD_PDU;
922 //RGDBGERRNEW((rgPBuf, "FAILED"));
925 if(rgMUXAddSdus(inst, pdu, mBuf1, tb, err) != ROK)
927 /*TODO:MP Reset rPtr and wPtr to the base of data buffer(db_base)
928 * Reset numLch and numPdu to zero and set MAC SDU buf to NULLP */
929 DU_LOG("\nERROR --> MAC : rgMUXBldPdu: rgMUXAddSdus is Failed \n");
932 err->errType = RGERR_MUX_BLD_PDU;
933 //RGDBGERRNEW((rgPBuf, "FAILED"));
937 // SPrntMsg(tb->macHdr, 0, 0);
938 // prc_trace_format_string(0x40,3,": padSize=%ld", tb->padSize);
945 #endif /* end of L2_OPTMZ */
948 * @brief Function to create RAR PDU.
952 * Function : rgMUXBldRarPdu
953 * This function is used to build RAR PDUs and is being
954 * invoked by the scheduler.
956 * @param[out]RgCellCb *cellCb
957 * @param[in] RgRaRspAlloc *bldPdu
958 * @param[in] Buffer **txPdu
959 * @param[out] RgErrInfo *err
967 RgInfRaRntiInfo *alloc,
972 Buffer *datBuf = NULLP;
974 uint8_t data[RG_RAR_ELEM_LEN];
978 Inst inst = cell->macInst - RG_INST_START;
980 schdTbSz = alloc->schdTbSz;
981 /* RAR PDU Requirements */
983 1. SubHeader - R/T/RAPID. //5GNR, changed E to R
984 2. TA ( if applicable)
986 a. Hopping Flag - 1 Bit.
987 b. Fixed Size RB Assignment. - 10 Bits.
988 c. Truncated Modulation and coding scheme - 4 Bits.
989 d. TPC command for scheduled PUSCH. - 3 Bits.
991 f. CQI Request - 1 Bit.
995 /* Initialize the error type */
996 err->errType = RGERR_MUX_BLD_RAR_PDU;
998 if ((ret = rgGetMsg(inst,&datBuf)) != ROK)
1000 /* Buffer couldnt get allocated. Return a failure */
1001 err->errCause = RGERR_MUX_MEM_ALLOC_FAIL;
1002 DU_LOG("\nERROR --> MAC : FAILED to getMsg");
1006 if (TRUE == alloc->backOffInd.pres)
1008 /*Set T Bit , NO E bit Required */
1011 hdrByte |= (0x0F & (alloc->backOffInd.val));
1013 /* Add the header */
1014 RG_PACK_RAR_SHDR(hdrByte, datBuf, ret);
1017 err->errCause = RGERR_MUX_BLD_BI_FAIL;
1018 DU_LOG("\nERROR --> MAC : RGERR_MUX_BLD_BI_FAIL");
1019 RG_FREE_MSG(datBuf);
1025 for (idx=0; idx < (alloc->numCrnti) &&
1026 (schdTbSz >= RG_RAR_ELEM_LEN+RG_RAR_SHDR_LEN); idx++)
1031 hdrByte |= (0x3F & (alloc->crntiInfo[idx].rapId));
1033 /* Add the header */
1034 RG_PACK_RAR_SHDR(hdrByte, datBuf, ret);
1037 err->errCause = RGERR_MUX_BLD_RAPIDHDR_FAIL;
1038 DU_LOG("\nERROR --> MAC : RGERR_MUX_BLD_RAPIDHDR_FAIL");
1039 RG_FREE_MSG(datBuf);
1043 /* Prepare the data */
1044 data[0] = 0x7F & ((alloc->crntiInfo[idx].ta.val) >> 4);
1049 rgMUXGet20bitRarGrnt(cell->bwCfg.ulTotalBw, &(alloc->crntiInfo[idx].grnt), &data[1]);
1051 data[1] |= ((uint8_t)((alloc->crntiInfo[idx].ta.val) << 4));
1052 data[4] = (alloc->crntiInfo[idx].tmpCrnti) >> 8;
1053 data[5] = (uint8_t) (alloc->crntiInfo[idx].tmpCrnti);
1055 DU_LOG("\nDEBUG --> MAC : Rar,Rapid=%d, Temp CRNTI:%d",
1056 alloc->crntiInfo[idx].rapId,
1057 alloc->crntiInfo[idx].tmpCrnti);
1058 MS_BUF_ADD_ALLOC_CALLER();
1059 if(SAddPstMsgMult(&data[0], RG_RAR_ELEM_LEN, datBuf) != ROK)
1061 err->errCause = RGERR_MUX_BLD_RAPID_FAIL;
1062 DU_LOG("\nERROR --> MAC : RGERR_MUX_BLD_RAPID_FAIL");
1063 RG_FREE_MSG(datBuf);
1066 schdTbSz -= RG_RAR_ELEM_LEN+RG_RAR_SHDR_LEN;
1069 if(rgMUXAddPadd(inst,&schdTbSz, datBuf, TRUE, err) != ROK)
1071 RG_FREE_MSG(datBuf);
1072 DU_LOG("\nERROR --> MAC : FAILED to mux add padding");
1079 } /* rgMUXBldRarPdu */
1081 /***********************************************************
1083 * Func : rgMUXGet20bitRarGrnt
1085 * Desc : This function fills up the 20-bit grant
1094 **********************************************************/
1095 static Void rgMUXGet20bitRarGrnt
1098 RgInfRarUlGrnt *msg3Grnt,
1102 uint16_t riv = rgMUXCalcRiv(ulBw, msg3Grnt->rbStart, msg3Grnt->numRb);
1104 grnt[2] = msg3Grnt->cqiBit; /* cqi bit is 0, output from sched */
1105 grnt[2] |= (msg3Grnt->delayBit << 1);
1106 grnt[2] |= (msg3Grnt->tpc << 2);
1107 grnt[2] |= (msg3Grnt->iMcsCrnt << 5);
1109 grnt[1] = (msg3Grnt->iMcsCrnt >> 3);
1110 /* Forcing right shift to insert 0 as the LSB:
1111 * since this is assumed in the computation */
1112 grnt[1] |= (uint8_t)((riv << 1) & 0xFE);
1114 grnt[0] = (uint8_t)((riv >> 7) & 0x07);
1115 grnt[0] |= ((msg3Grnt->hop & 0x01) << 3);
1118 } /* rgMUXGet20bitRarGrnt */
1120 /***********************************************************
1122 * Func : rgMUXCalcRiv
1124 * Desc : This function calculates RIV.
1132 **********************************************************/
1133 uint16_t rgMUXCalcRiv
1140 uint8_t numRbMinus1 = numRb - 1;
1143 if (numRbMinus1 <= bw/2)
1145 riv = bw * numRbMinus1 + rbStart;
1149 riv = bw * (bw - numRbMinus1) + (bw - rbStart - 1);
1152 } /* rgMUXCalcRiv */
1156 /**********************************************************************
1159 **********************************************************************/