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.
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_FILE_ID=229;
37 static int RLOG_MODULE_ID=4096;
39 /* header include files -- defines (.h) */
40 #include "common_def.h"
41 #include "rg_env.h" /* MAC Environment Defines */
42 #include "tfu.h" /* TFU Interface defines */
43 #include "crg.h" /* CRG Interface defines */
44 #include "rg_sch_inf.h" /* RGR Interface defines */
45 #include "rgu.h" /* RGU Interface defines */
46 #include "lrg.h" /* LRG Interface defines */
48 #include "rg_err.h" /* MAC error defines */
49 #include "rg.h" /* MAC defines */
51 /* header/extern include files (.x) */
53 #include "rgu.x" /* RGU Interface includes */
54 #include "tfu.x" /* CRG Interface includes */
55 #include "crg.x" /* CRG Interface includes */
56 #include "rg_sch_inf.x" /* SCH Interface includes */
57 #include "rg_prg.x" /* PRG Interface includes */
58 #include "rgu.x" /* RGU Interface includes */
59 #include "lrg.x" /* LRG Interface includes */
61 #include "du_app_mac_inf.h"
62 #include "rg.x" /* MAC includes */
66 #include "ss_msg.x" /* MAC includes */
68 #ifndef T2K_MEM_LEAK_DBG
69 S16 ssGetDBufOfSize(Region region,Size size,Buffer **dBuf);
71 char* file = __FILE__;
72 uint32_t line = __LINE__;
77 /* global variables */
78 uint32_t rgDlrate_rgu;
82 static Void rgMUXGet20bitRarGrnt ARGS((uint8_t ulBw,
83 RgInfRarUlGrnt *msg3Grnt,
85 uint16_t rgMUXCalcRiv ARGS((uint8_t bw,
89 #ifndef MS_MBUF_CORRUPTION
90 #define MS_BUF_ADD_ALLOC_CALLER()
92 /* forward references */
94 #define RG_PACK_SHDR_FIXD_SZ(_subHdr, _lcId, _mBuf, _ret) {\
95 _subHdr.shLen = RG_FIXDSZ_CE_SHDR_LEN;\
96 _subHdr.shData[0] = (0x3F & _lcId);\
97 MS_BUF_ADD_ALLOC_CALLER(); \
98 _ret = SAddPstMsgMult(&_subHdr.shData[0], _subHdr.shLen, _mBuf);\
101 #define RG_PACK_CE(_ce, _len, _ceBuf, _ret) {\
102 MS_BUF_ADD_ALLOC_CALLER(); \
103 _ret = SAddPstMsgMult((uint8_t *)(&(_ce)), _len, _ceBuf);\
106 #define RG_MUX_CALC_LEN(_len,_lenBytes,_elmTotLen) {\
108 _lenBytes = (_len <= 255) ? 1 : 2;\
109 _hdrLen = _lenBytes + RG_SDU_SHDR_LEN;\
110 _elmTotLen = _hdrLen + _len;\
113 #define RG_PACK_VAR_SZ_CE_SDU_SHDR(_subHdr, _lcId, _len,_mBuf, _ret) {\
117 _subHdr.shData[0] = (0x3F & _lcId);\
119 _subHdr.shData[1] = (0xFF & _len);\
120 _subHdr.shData[2] = 0;\
124 _subHdr.shData[0] = (0x7F & ((0x40) | _lcId));\
126 _subHdr.shData[1] = (0xFF & (_len >> 8));\
127 _subHdr.shData[2] = (0xFF & _len);\
129 MS_BUF_ADD_ALLOC_CALLER(); \
130 _ret = SAddPstMsgMult(&_subHdr.shData[0], _subHdr.shLen, _mBuf);\
133 #define RG_PACK_PAD_SHDR(_mBuf, _ret) {\
134 _ret = SAddPreMsg(0x3F, _mBuf);\
137 #define RG_PACK_RAR_SHDR(_byte, _mBuf, _ret) {\
138 _ret = SAddPstMsg(_byte, _mBuf);\
143 * @brief Function to add ces along with subhdrs.
144 * This function packs first CE sub-hdr and then CE in ceBuf pointer
148 * Function : rgMUXAddCes
150 * @param[in] Inst inst
151 * @param[in] RgBldPduInfo *pdu
152 * @param[in] Buffer *ceBuf
153 * @param[in] RgErrInfo *err
159 static S16 rgMUXAddCes
167 static S16 rgMUXAddCes(inst,pdu, ceShdrBuf, ceBuf, err)
177 if (NULLP != pdu->contResId)
179 if(pdu->schdTbSz >= RG_CRES_ELM_LEN)
181 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_CRES_LCID_IDX, ceBuf, ret);
185 err->errCause = RGERR_MUX_BLD_CEHDR_FAIL;
186 RLOG0(L_ERROR, "Muxing of Contention Resolution CE sub-header is failed");
190 RG_PACK_CE(pdu->contResId->resId[0], RG_CRES_LEN, ceBuf, ret);
194 err->errCause = RGERR_MUX_BLD_CE_FAIL;
195 RLOG0(L_ERROR, "Muxing of Contention Resolution CE is failed")
198 pdu->schdTbSz -= RG_CRES_ELM_LEN;
201 if (TRUE == pdu->ta.pres)
203 if(pdu->schdTbSz >= RG_TA_ELM_LEN)
205 uint8_t taVal; /* Moving from outer scope to available scope */
206 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_TA_LCID_IDX, ceBuf, ret);
210 err->errCause = RGERR_MUX_BLD_CEHDR_FAIL;
211 RLOG0(L_ERROR, "Muxing of TA CE sub-hdr is failed")
216 RG_PACK_CE(taVal, RG_TA_LEN, ceBuf, ret);
220 err->errCause = RGERR_MUX_BLD_CE_FAIL;
221 RLOG0(L_ERROR, "Muxing of TA CE is failed")
224 pdu->schdTbSz -= RG_TA_ELM_LEN;
225 RLOG1(L_DEBUG,"TA muxed by MAC: %u", pdu->ta.val);
229 if(TRUE == pdu->sCellActCe.pres)
231 if(pdu->schdTbSz >= RG_SCELL_CE_ELM_LEN)
233 /* Adding the subheader for ACT CE */
234 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_SCELL_LCID_IDX, ceBuf, ret);
238 err->errCause = RGERR_MUX_BLD_CEHDR_FAIL;
239 RLOG0(L_ERROR, "Muxing of SCELL Activation CE sub-hdr is failed")
243 /* Adding the ACT CE */
244 RG_PACK_CE(pdu->sCellActCe.val, RG_SCELL_ACT_CE_LEN, ceBuf, ret);
248 err->errCause = RGERR_MUX_BLD_CE_FAIL;
249 RLOG0(L_ERROR, "Muxing of SCELL Activation CE is failed")
252 pdu->schdTbSz -= RG_SCELL_CE_ELM_LEN;
258 /*LcId is not yet decided in 5G-NR spec for MAC CEs Hence, not writing code
265 * @brief Function to insert SDU along with sub headers.
269 * Function : rgMUXInsSdu
271 * @param[in] Inst inst
272 * @param[in] MsgLen *schdTbSz
273 * @param[in] uint8_t lcId
274 * @param[in] Buffer *sdu
275 * @param[out] Buffer *sduBuf
276 * @param[out] RgErrInfo *err
282 static S16 rgMUXInsSdu
292 static S16 rgMUXInsSdu(inst,schdTbSz, lcId, sdu, sduBuf, err)
306 SFndLenMsg(sdu, &msgLen);
308 RG_MUX_CALC_LEN(msgLen,lenBytes,elmTotLen);
312 rgDlrate_rgu += msgLen;
314 if (*schdTbSz >= elmTotLen)
317 RG_PACK_VAR_SZ_CE_SDU_SHDR(subHdr, lcId, msgLen,sduBuf, ret);
320 err->errCause = RGERR_MUX_BLD_SDUHDR_FAIL;
321 RLOG1(L_ERROR, "RGERR_MUX_BLD_SDUHDR_FAIL for LCID:%d",lcId);
325 #ifndef L2_OPTMZ /* no need to pack as passing not muxing all LCs PDUs to 1*/
326 RG_PACK_SDU(sduBuf, sdu, ret);
335 err->errCause = RGERR_MUX_BLD_SDU_FAIL;
336 RLOG1(L_ERROR, "RGERR_MUX_BLD_SDU_FAIL for LCID:%d",lcId);
340 *schdTbSz -= elmTotLen;
344 /* This Sub-PDU can not be accodmodated at all */
345 RLOG4(L_ERROR, "Failed lcId %u, elmTotLen %d lenBytes %d LCID:%d",
346 lcId, ((S16)elmTotLen), lenBytes,lcId);
347 RLOG3(L_ERROR, "msglen %d schdTbSz %d LCID:%d",
348 ((S16)msgLen), ((S16)*schdTbSz),lcId);
355 * @brief Function to insert SDU along with sub headers.
359 * Function : rgMUXAddPadd
361 * @param[in] Inst inst
362 * @param[in] RgBldPduInfo *pdu
363 * @param[out] Buffer *mBuf
364 * @param[out] Buffer *sduBuf
370 uint32_t padSize = 0;
382 S16 rgMUXAddPadd(inst,schdTbSz, sduBuf, isRar, err)
391 Buffer *padBuf = NULLP;
402 if((FALSE == isRar) && (NULL != sHdrBuf))
406 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_PAD_LCID_IDX, sduBuf, ret);
410 err->errCause = RGERR_MUX_BLD_PADHDR_FAIL;
411 RLOG0(L_ERROR, "RGERR_MUX_BLD_PADHDR_FAIL");
420 if (*schdTbSz <= RG_MAX_PAD_ARR_SZ)
423 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
427 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
430 padSize += *schdTbSz;
434 err->errCause = RGERR_MUX_BLD_PAD_FAIL;
435 RLOG0(L_ERROR, "RGERR_MUX_BLD_PAD_FAIL");
444 if (*schdTbSz > RG_MAX_PAD_ARR_SZ)
447 RG_PACK_PAD(padBuf,RG_MAX_PAD_ARR_SZ,sduBuf);
451 RG_PACK_PAD(padBuf,RG_MAX_PAD_ARR_SZ,sduBuf);
454 padSize += RG_MAX_PAD_ARR_SZ;
459 err->errCause = RGERR_MUX_BLD_PAD_FAIL;
460 RLOG0(L_ERROR, "RGERR_MUX_BLD_PAD_FAIL");
464 *schdTbSz -= RG_MAX_PAD_ARR_SZ;
469 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
473 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
476 padSize += *schdTbSz;
481 err->errCause = RGERR_MUX_BLD_PAD_FAIL;
482 RLOG0(L_ERROR, "RGERR_MUX_BLD_PAD_FAIL");
498 * @brief Function to add SDU along with sub headers.
502 * Function : rgMUXAddSdus
504 * @param[in] Inst inst
505 * @param[in] RgBldPduInfo *pdu
506 * @param[out] Buffer *mBuf
507 * @param[out] Buffer *sduBuf
513 static S16 rgMUXAddSdus
521 static S16 rgMUXAddSdus(inst,pdu, sduBuf, err)
528 RgRguDDatReqPerUe *dDatReq;
529 RgRguCmnDatReq *cDatReq;
534 cDatReq = (RgRguCmnDatReq *)(pdu->datReq);
535 /* Add sdu(s) to the Message Buffer */
536 if (NULLP != cDatReq)
538 if(rgMUXInsSdu(inst,&pdu->schdTbSz,
539 RG_CCCH_LCID, cDatReq->pdu, sduBuf, err) != ROK)
543 RG_FREE_MSG(cDatReq->pdu);
548 dDatReq = (RgRguDDatReqPerUe *)(pdu->datReq);
549 /* Add sdu(s) to the Message Buffer */
550 if (NULLP != dDatReq)
552 if(pdu->tbIndex == 1)
555 /* Adding this temporary variable for optimization */
556 RguDatReqTb *datReqTb = &dDatReq->datReqTb[0];
558 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
561 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
566 if(rgMUXInsSdu(inst,&pdu->schdTbSz,
567 datReqTb->lchData[idx1].lcId,
568 datReqTb->lchData[idx1].pdu.mBuf[idx2],
571 RLOG1(L_ERROR, "FAILED for LCID:%d",datReqTb->lchData[idx1].lcId);
575 RG_FREE_MSG(datReqTb->lchData[idx1].pdu.mBuf[idx2]);
579 else if(pdu->tbIndex == 2)
582 RguDatReqTb *datReqTb = &dDatReq->datReqTb[1];
583 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
586 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
591 if(rgMUXInsSdu(inst,&pdu->schdTbSz,
592 datReqTb->lchData[idx1].lcId,
593 datReqTb->lchData[idx1].pdu.mBuf[idx2],
596 RLOG2(L_ERROR, "FAILED TB Size %d LCID:%d",
597 ((S16)pdu->schdTbSz),datReqTb->lchData[idx1].lcId);
601 RG_FREE_MSG(datReqTb->lchData[idx1].pdu.mBuf[idx2]);
610 } /* End of switch(reqType) */
611 if(rgMUXAddPadd(inst,&pdu->schdTbSz, sduBuf, FALSE, err) != ROK)
613 RLOG1(L_ERROR, "FAILED for TB Size:%d",(S16)pdu->schdTbSz);
620 * @brief Function to create MAC PDU from RLC SDUs and control elements, if any.
624 * Function : rgMUXBldPdu
626 * -# This function shall be invoked by Downlink Harq Module as soon as a
627 * Data request is received from RLC for a UE along with its stored
628 * control elements to create a MAC PDU.
629 * -# It shall create subheaders for the control elements (timing advance
630 * and contention resolution ID) and pack sub-header before each CE,
631 * if given, and then shall run through all the logical channels and
632 * create subheader for each of the SDUs given on that logical channel
633 * and pack corresponding sub-header before the each SDU
634 * -# It shall invoke rgMUXPadPdu if the total length of the created
635 * buffer is less than the scheduled TB size.
638 * @param[in] Inst *inst
639 * @param[in] RgBldPduInfo *bldPdu
640 * @param[in] Buffer **txPdu
641 * @param[out] RgErrInfo *err
655 S16 rgMUXBldPdu(inst, pdu, txPdu, err)
662 Buffer *mBuf = NULLP;
664 if (rgGetMsg(inst, &mBuf) != ROK)
666 /* Buffer couldnt get allocated. Return a failure */
667 err->errCause = RGERR_MUX_MEM_ALLOC_FAIL;
668 err->errType = RGERR_MUX_BLD_PDU;
669 RLOG1(L_FATAL, "Memory allocation failed during MUXing of MAC TB: MacInst %d", inst);
673 if(rgMUXAddCes(inst, pdu, mBuf, err) != ROK)
676 err->errType = RGERR_MUX_BLD_PDU;
677 RLOG1(L_ERROR, "Failed to Multiplex MAC CEs: MacInst %d", inst);
681 if(rgMUXAddSdus(inst, pdu, mBuf, err) != ROK)
684 err->errType = RGERR_MUX_BLD_PDU;
685 RLOG1(L_ERROR, "FAILED to Multiplex MAC SDU: MacInst %d", inst);
695 #else /* else of ifndef L2_OPTMZ */
698 * @brief Function to add SDU along with sub headers.
702 * Function : rgMUXAddSdus
704 * @param[in] RgBldPduInfo *pdu
705 * @param[out] Buffer *mBuf
706 * @param[out] Buffer *sduBuf
712 static S16 rgMUXAddSdus
717 RgTfuDatReqTbInfo *tb,
721 static S16 rgMUXAddSdus(pdu, sHdrBuf, tb, err)
725 RgTfuDatReqTbInfo *tb;
729 RgRguDDatReqPerUe *dDatReq;
730 RgRguCmnDatReq *cDatReq;
731 uint32_t lchIdx, pduIdx;
736 cDatReq = (RgRguCmnDatReq *)(pdu->datReq);
737 /* Add sdu(s) to the Message Buffer */
738 if (NULLP != cDatReq)
740 if(rgMUXInsSdu(inst, &pdu->schdTbSz,
741 RG_CCCH_LCID, cDatReq->pdu,
742 sHdrBuf, NULLP, err) != ROK)
746 /* L2 Optimization for mUe/Tti: RLC pdu mbuf pointer will be passed
747 * to CL it is stored in DlHqProc->TbInfo and it will be used in
748 * case of harq retransmission. Store CCCH data at 0th index of
750 tb->lchInfo[tb->numLch].mBuf[(tb->lchInfo[tb->numLch].numPdu)]\
752 tb->lchInfo[tb->numLch].numPdu++;
754 RLOG3(L_INFO,"MSG4 is muxed numLch=%ld numPdu=%ld tbaddr =%p", tb->numLch,tb->lchInfo[tb->numLch-1].numPdu, (uint32_t)tb);
759 dDatReq = (RgRguDDatReqPerUe *)(pdu->datReq);
760 /* Add sdu(s) to the Message Buffer */
761 if (NULLP != dDatReq)
763 if(pdu->tbIndex == 1)
766 /* Adding this temporary variable for optimization */
767 RguDatReqTb *datReqTb = &dDatReq->datReqTb[0];
769 tb->numLch = lchIdx = 0;
771 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
773 tb->lchInfo[lchIdx].numPdu = pduIdx = 0;
776 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
781 if(rgMUXInsSdu(inst, &pdu->schdTbSz,
782 datReqTb->lchData[idx1].lcId,
783 datReqTb->lchData[idx1].pdu.mBuf[idx2],
784 sHdrBuf, NULLP, err) != ROK)
786 RGDBGERRNEW(inst,(rgPBuf(inst), "FAILED\n"));
790 /* L2 Optimization for mUe/Tti:Increment numPdu by 1
791 * Store pdu buffer in tb to send it to CL/PHY. Increment
793 tb->lchInfo[lchIdx].mBuf[pduIdx] = datReqTb->lchData[idx1].pdu.mBuf[idx2];
796 if(datReqTb->lchData[idx1].freeBuff == FALSE)
797 {/* Not incrementing refCnt for UM Mode. */
798 tb->lchInfo[lchIdx].mBuf[pduIdx]->refCnt++;
802 if(NULL != datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont)
805 tmp = datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont;
806 if(NULL == tmp->b_rptr)
808 RLOG0(L_INFO,"11111Its Null here only ");
813 RLOG0(L_INFO,"222222Its Null here only \n");
816 //tb->lchInfo[tb->numLch].numPdu++;
824 tb->lchInfo[lchIdx].numPdu = pduIdx;
825 /* If Bearer is UM then MBUF to be free by MAC layer */
826 tb->lchInfo[lchIdx].freeBuff = datReqTb->lchData[idx1].freeBuff;
832 else if(pdu->tbIndex == 2)
835 RguDatReqTb *datReqTb = &dDatReq->datReqTb[1];
836 tb->numLch = lchIdx = 0;
837 // prc_trace_format_string(0x40,3,": AddSdus: numOfLch=%d numOfPdu=%d, schdSz=%d", datReqTb->nmbLch, datReqTb->lchData[0].pdu.numPdu, pdu->schdTbSz);
838 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
840 tb->lchInfo[lchIdx].numPdu = pduIdx = 0;
842 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
847 if(rgMUXInsSdu(inst, &pdu->schdTbSz,
848 datReqTb->lchData[idx1].lcId,
849 datReqTb->lchData[idx1].pdu.mBuf[idx2],
850 sHdrBuf, NULLP, err) != ROK)
852 RGDBGERRNEW(inst,(rgPBuf(inst), "FAILED TB Size %d\n",
853 ((S16)pdu->schdTbSz)));
856 /* L2 Optimization for mUe/Tti:Increment numPdu by 1
857 * Store pdu buffer in tb to send it to CL/PHY. Increment
859 tb->lchInfo[lchIdx].mBuf[pduIdx] = datReqTb->lchData[idx1].pdu.mBuf[idx2];
861 if(datReqTb->lchData[idx1].freeBuff == FALSE)
862 {/* Not incrementing refCnt for UM Mode. */
863 tb->lchInfo[lchIdx].mBuf[pduIdx]->refCnt++;
866 if(NULL != datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont)
869 tmp = datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont;
870 if(NULL == tmp->b_rptr)
872 RLOG0(L_INFO,"2212121Its Null here only \n");
877 RLOG0(L_INFO,"343343433ts Null here only \n");
880 // tb->lchInfo[tb->numLch].numPdu++;
888 tb->lchInfo[lchIdx].numPdu = pduIdx;
889 /* If Bearer is UM then MBUF to be free by MAC layer */
890 tb->lchInfo[lchIdx].freeBuff = datReqTb->lchData[idx1].freeBuff;
900 case EVENT_SLOT_IND_TO_MAC:
904 } /* End of switch(reqType) */
907 if(rgMUXAddPadd(inst, &pdu->schdTbSz, sduBuf, NULLP, FALSE, err) != ROK)
909 //RGDBGERRNEW((rgPBuf, "FAILED"));
912 tb->padSize = padSize;
918 * @brief Function to create MAC PDU from RLC SDUs and control elements, if any.
922 * Function : rgMUXBldPdu
923 * -# This function shall be invoked by Downlink Harq Module as soon as a
924 * Data request is received from RLC for a UE along with its stored
925 * control elements to create a MAC PDU.
926 * -# It shall create subheaders for the control elements (timing advance
927 * and contention resolution ID), if given, and then shall run through
928 * all the logical channels and create subheader for each of the SDUs
929 * given on that logical channel.
930 * -# L2 Optimization for mUe/Tti: Avoiding muxing to reduce overhead of
931 * additional Mbuf allocation memory related operation.
932 -# MAC header, MAC CEs, MAC PDUs and MAC padding are stored in pre-
933 allocated mBufs. These pointers will not be freed by CL
934 * -# It shall invoke rgMUXPadPdu if the total length of the created
935 * buffer is less than the scheduled TB size.
936 * -# At successfull operation of this function tb->macHdr, will have
937 * complete MAC Header. tb->macCes will have MAC CEs if any. tb->
938 * lchInfo[idx].mBuf[idx] will have MAC SDU per LCH per TB per UE
941 * @param[in] RgBldPduInfo *bldPdu
942 * @param[out] RgTbInfo *tb
943 * @param[out] RgErrInfo *err
953 RgTfuDatReqTbInfo *tb,
957 S16 rgMUXBldPdu(inst, pdu, tb, err)
960 RgTfuDatReqTbInfo *tb;
964 Buffer *mBuf1; /* MAC hearder */
965 Buffer *mBuf2; /* MAC CEs */
966 //uint32_t lchIdx, pduIdx;
968 /* Reseting macHdr and macCes pointers */
970 SResetMBuf(tb->macHdr);
972 SResetMBuf(tb->macCes);
974 mBuf1 = tb->macHdr; /* MAC hearder */
975 mBuf2 = tb->macCes; /* MAC CEs */
976 tb->tbSize = pdu->schdTbSz;
978 if(rgMUXAddCes(inst, pdu, mBuf1, mBuf2, err) != ROK)
980 /* Reset rPtr and wPtr to the base of data buffer(db_base)*/
981 RLOG0(L_INFO,"rgMUXBldPdu: rgMUXAddCes is Failed \n");
983 err->errType = RGERR_MUX_BLD_PDU;
984 //RGDBGERRNEW((rgPBuf, "FAILED"));
987 if(rgMUXAddSdus(inst, pdu, mBuf1, tb, err) != ROK)
989 /*TODO:MP Reset rPtr and wPtr to the base of data buffer(db_base)
990 * Reset numLch and numPdu to zero and set MAC SDU buf to NULLP */
991 RLOG0(L_INFO, "rgMUXBldPdu: rgMUXAddSdus is Failed \n");
994 err->errType = RGERR_MUX_BLD_PDU;
995 //RGDBGERRNEW((rgPBuf, "FAILED"));
999 // SPrntMsg(tb->macHdr, 0, 0);
1000 // prc_trace_format_string(0x40,3,": padSize=%ld", tb->padSize);
1007 #endif /* end of L2_OPTMZ */
1010 * @brief Function to create RAR PDU.
1014 * Function : rgMUXBldRarPdu
1015 * This function is used to build RAR PDUs and is being
1016 * invoked by the scheduler.
1018 * @param[out]RgCellCb *cellCb
1019 * @param[in] RgRaRspAlloc *bldPdu
1020 * @param[in] Buffer **txPdu
1021 * @param[out] RgErrInfo *err
1030 RgInfRaRntiInfo *alloc,
1035 S16 rgMUXBldRarPdu(cell, alloc, txPdu, err)
1037 RgInfRaRntiInfo *alloc;
1042 Buffer *datBuf = NULLP;
1044 uint8_t data[RG_RAR_ELEM_LEN];
1048 Inst inst = cell->macInst - RG_INST_START;
1050 schdTbSz = alloc->schdTbSz;
1051 /* RAR PDU Requirements */
1053 1. SubHeader - R/T/RAPID. //5GNR, changed E to R
1054 2. TA ( if applicable)
1056 a. Hopping Flag - 1 Bit.
1057 b. Fixed Size RB Assignment. - 10 Bits.
1058 c. Truncated Modulation and coding scheme - 4 Bits.
1059 d. TPC command for scheduled PUSCH. - 3 Bits.
1060 e. UL Delay - 1 Bit.
1061 f. CQI Request - 1 Bit.
1065 /* Initialize the error type */
1066 err->errType = RGERR_MUX_BLD_RAR_PDU;
1068 if ((ret = rgGetMsg(inst,&datBuf)) != ROK)
1070 /* Buffer couldnt get allocated. Return a failure */
1071 err->errCause = RGERR_MUX_MEM_ALLOC_FAIL;
1072 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId, "FAILED to getMsg");
1076 if (TRUE == alloc->backOffInd.pres)
1078 /*Set T Bit , NO E bit Required */
1081 hdrByte |= (0x0F & (alloc->backOffInd.val));
1083 /* Add the header */
1084 RG_PACK_RAR_SHDR(hdrByte, datBuf, ret);
1087 err->errCause = RGERR_MUX_BLD_BI_FAIL;
1088 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"RGERR_MUX_BLD_BI_FAIL");
1089 RG_FREE_MSG(datBuf);
1095 for (idx=0; idx < (alloc->numCrnti) &&
1096 (schdTbSz >= RG_RAR_ELEM_LEN+RG_RAR_SHDR_LEN); idx++)
1101 hdrByte |= (0x3F & (alloc->crntiInfo[idx].rapId));
1103 /* Add the header */
1104 RG_PACK_RAR_SHDR(hdrByte, datBuf, ret);
1107 err->errCause = RGERR_MUX_BLD_RAPIDHDR_FAIL;
1108 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"RGERR_MUX_BLD_RAPIDHDR_FAIL");
1109 RG_FREE_MSG(datBuf);
1113 /* Prepare the data */
1114 data[0] = 0x7F & ((alloc->crntiInfo[idx].ta.val) >> 4);
1119 rgMUXGet20bitRarGrnt(cell->bwCfg.ulTotalBw, &(alloc->crntiInfo[idx].grnt), &data[1]);
1121 data[1] |= ((uint8_t)((alloc->crntiInfo[idx].ta.val) << 4));
1122 data[4] = (alloc->crntiInfo[idx].tmpCrnti) >> 8;
1123 data[5] = (uint8_t) (alloc->crntiInfo[idx].tmpCrnti);
1125 RLOG_ARG2(L_DEBUG,DBG_CELLID,cell->cellId,
1126 "Rar,Rapid=%d, Temp CRNTI:%d",
1127 alloc->crntiInfo[idx].rapId,
1128 alloc->crntiInfo[idx].tmpCrnti);
1129 MS_BUF_ADD_ALLOC_CALLER();
1130 if(SAddPstMsgMult(&data[0], RG_RAR_ELEM_LEN, datBuf) != ROK)
1132 err->errCause = RGERR_MUX_BLD_RAPID_FAIL;
1133 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"RGERR_MUX_BLD_RAPID_FAIL");
1134 RG_FREE_MSG(datBuf);
1137 schdTbSz -= RG_RAR_ELEM_LEN+RG_RAR_SHDR_LEN;
1140 if(rgMUXAddPadd(inst,&schdTbSz, datBuf, TRUE, err) != ROK)
1142 RG_FREE_MSG(datBuf);
1143 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"FAILED to mux add padding");
1150 } /* rgMUXBldRarPdu */
1152 /***********************************************************
1154 * Func : rgMUXGet20bitRarGrnt
1156 * Desc : This function fills up the 20-bit grant
1165 **********************************************************/
1167 static Void rgMUXGet20bitRarGrnt
1170 RgInfRarUlGrnt *msg3Grnt,
1174 static Void rgMUXGet20bitRarGrnt(ulBw, msg3Grnt, grnt)
1176 RgInfRarUlGrnt *msg3Grnt;
1180 uint16_t riv = rgMUXCalcRiv(ulBw, msg3Grnt->rbStart, msg3Grnt->numRb);
1182 grnt[2] = msg3Grnt->cqiBit; /* cqi bit is 0, output from sched */
1183 grnt[2] |= (msg3Grnt->delayBit << 1);
1184 grnt[2] |= (msg3Grnt->tpc << 2);
1185 grnt[2] |= (msg3Grnt->iMcsCrnt << 5);
1187 grnt[1] = (msg3Grnt->iMcsCrnt >> 3);
1188 /* Forcing right shift to insert 0 as the LSB:
1189 * since this is assumed in the computation */
1190 grnt[1] |= (uint8_t)((riv << 1) & 0xFE);
1192 grnt[0] = (uint8_t)((riv >> 7) & 0x07);
1193 grnt[0] |= ((msg3Grnt->hop & 0x01) << 3);
1196 } /* rgMUXGet20bitRarGrnt */
1198 /***********************************************************
1200 * Func : rgMUXCalcRiv
1202 * Desc : This function calculates RIV.
1210 **********************************************************/
1212 uint16_t rgMUXCalcRiv
1219 uint16_t rgMUXCalcRiv(bw, rbStart, numRb)
1225 uint8_t numRbMinus1 = numRb - 1;
1228 if (numRbMinus1 <= bw/2)
1230 riv = bw * numRbMinus1 + rbStart;
1234 riv = bw * (bw - numRbMinus1) + (bw - rbStart - 1);
1237 } /* rgMUXCalcRiv */
1241 /**********************************************************************
1244 **********************************************************************/