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 EXTERN S16 ssGetDBufOfSize(Region region,Size size,Buffer **dBuf);
71 char* file = __FILE__;
77 /* global variables */
82 PRIVATE Void rgMUXGet20bitRarGrnt ARGS((U8 ulBw,
83 RgInfRarUlGrnt *msg3Grnt,
85 EXTERN U16 rgMUXCalcRiv ARGS((U8 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((U8 *)(&(_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 PRIVATE S16 rgMUXAddCes
167 PRIVATE S16 rgMUXAddCes(inst,pdu, ceShdrBuf, ceBuf, err)
179 if (NULLP != pdu->contResId)
181 if(pdu->schdTbSz >= RG_CRES_ELM_LEN)
183 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_CRES_LCID_IDX, ceBuf, ret);
187 err->errCause = RGERR_MUX_BLD_CEHDR_FAIL;
188 RLOG0(L_ERROR, "Muxing of Contention Resolution CE sub-header is failed");
192 RG_PACK_CE(pdu->contResId->resId[0], RG_CRES_LEN, ceBuf, ret);
196 err->errCause = RGERR_MUX_BLD_CE_FAIL;
197 RLOG0(L_ERROR, "Muxing of Contention Resolution CE is failed")
200 pdu->schdTbSz -= RG_CRES_ELM_LEN;
203 if (TRUE == pdu->ta.pres)
205 if(pdu->schdTbSz >= RG_TA_ELM_LEN)
207 U8 taVal; /* Moving from outer scope to available scope */
208 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_TA_LCID_IDX, ceBuf, ret);
212 err->errCause = RGERR_MUX_BLD_CEHDR_FAIL;
213 RLOG0(L_ERROR, "Muxing of TA CE sub-hdr is failed")
218 RG_PACK_CE(taVal, RG_TA_LEN, ceBuf, ret);
222 err->errCause = RGERR_MUX_BLD_CE_FAIL;
223 RLOG0(L_ERROR, "Muxing of TA CE is failed")
226 pdu->schdTbSz -= RG_TA_ELM_LEN;
227 RLOG1(L_DEBUG,"TA muxed by MAC: %u", pdu->ta.val);
231 if(TRUE == pdu->sCellActCe.pres)
233 if(pdu->schdTbSz >= RG_SCELL_CE_ELM_LEN)
235 /* Adding the subheader for ACT CE */
236 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_SCELL_LCID_IDX, ceBuf, ret);
240 err->errCause = RGERR_MUX_BLD_CEHDR_FAIL;
241 RLOG0(L_ERROR, "Muxing of SCELL Activation CE sub-hdr is failed")
245 /* Adding the ACT CE */
246 RG_PACK_CE(pdu->sCellActCe.val, RG_SCELL_ACT_CE_LEN, ceBuf, ret);
250 err->errCause = RGERR_MUX_BLD_CE_FAIL;
251 RLOG0(L_ERROR, "Muxing of SCELL Activation CE is failed")
254 pdu->schdTbSz -= RG_SCELL_CE_ELM_LEN;
260 /*LcId is not yet decided in 5G-NR spec for MAC CEs Hence, not writing code
267 * @brief Function to insert SDU along with sub headers.
271 * Function : rgMUXInsSdu
273 * @param[in] Inst inst
274 * @param[in] MsgLen *schdTbSz
276 * @param[in] Buffer *sdu
277 * @param[out] Buffer *sduBuf
278 * @param[out] RgErrInfo *err
284 PRIVATE S16 rgMUXInsSdu
294 PRIVATE S16 rgMUXInsSdu(inst,schdTbSz, lcId, sdu, sduBuf, err)
309 SFndLenMsg(sdu, &msgLen);
311 RG_MUX_CALC_LEN(msgLen,lenBytes,elmTotLen);
315 rgDlrate_rgu += msgLen;
317 if (*schdTbSz >= elmTotLen)
320 RG_PACK_VAR_SZ_CE_SDU_SHDR(subHdr, lcId, msgLen,sduBuf, ret);
323 err->errCause = RGERR_MUX_BLD_SDUHDR_FAIL;
324 RLOG1(L_ERROR, "RGERR_MUX_BLD_SDUHDR_FAIL for LCID:%d",lcId);
328 #ifndef L2_OPTMZ /* no need to pack as passing not muxing all LCs PDUs to 1*/
329 RG_PACK_SDU(sduBuf, sdu, ret);
338 err->errCause = RGERR_MUX_BLD_SDU_FAIL;
339 RLOG1(L_ERROR, "RGERR_MUX_BLD_SDU_FAIL for LCID:%d",lcId);
343 *schdTbSz -= elmTotLen;
347 /* This Sub-PDU can not be accodmodated at all */
348 RLOG4(L_ERROR, "Failed lcId %u, elmTotLen %d lenBytes %d LCID:%d",
349 lcId, ((S16)elmTotLen), lenBytes,lcId);
350 RLOG3(L_ERROR, "msglen %d schdTbSz %d LCID:%d",
351 ((S16)msgLen), ((S16)*schdTbSz),lcId);
358 * @brief Function to insert SDU along with sub headers.
362 * Function : rgMUXAddPadd
364 * @param[in] Inst inst
365 * @param[in] RgBldPduInfo *pdu
366 * @param[out] Buffer *mBuf
367 * @param[out] Buffer *sduBuf
385 S16 rgMUXAddPadd(inst,schdTbSz, sduBuf, isRar, err)
394 Buffer *padBuf = NULLP;
406 if((FALSE == isRar) && (NULL != sHdrBuf))
410 RG_PACK_SHDR_FIXD_SZ(subHdr, RG_PAD_LCID_IDX, sduBuf, ret);
414 err->errCause = RGERR_MUX_BLD_PADHDR_FAIL;
415 RLOG0(L_ERROR, "RGERR_MUX_BLD_PADHDR_FAIL");
424 if (*schdTbSz <= RG_MAX_PAD_ARR_SZ)
427 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
431 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
434 padSize += *schdTbSz;
438 err->errCause = RGERR_MUX_BLD_PAD_FAIL;
439 RLOG0(L_ERROR, "RGERR_MUX_BLD_PAD_FAIL");
448 if (*schdTbSz > RG_MAX_PAD_ARR_SZ)
451 RG_PACK_PAD(padBuf,RG_MAX_PAD_ARR_SZ,sduBuf);
455 RG_PACK_PAD(padBuf,RG_MAX_PAD_ARR_SZ,sduBuf);
458 padSize += RG_MAX_PAD_ARR_SZ;
463 err->errCause = RGERR_MUX_BLD_PAD_FAIL;
464 RLOG0(L_ERROR, "RGERR_MUX_BLD_PAD_FAIL");
468 *schdTbSz -= RG_MAX_PAD_ARR_SZ;
473 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
477 RG_PACK_PAD(padBuf,*schdTbSz,sduBuf);
480 padSize += *schdTbSz;
485 err->errCause = RGERR_MUX_BLD_PAD_FAIL;
486 RLOG0(L_ERROR, "RGERR_MUX_BLD_PAD_FAIL");
502 * @brief Function to add SDU along with sub headers.
506 * Function : rgMUXAddSdus
508 * @param[in] Inst inst
509 * @param[in] RgBldPduInfo *pdu
510 * @param[out] Buffer *mBuf
511 * @param[out] Buffer *sduBuf
517 PRIVATE S16 rgMUXAddSdus
525 PRIVATE S16 rgMUXAddSdus(inst,pdu, sduBuf, err)
532 RgRguDDatReqPerUe *dDatReq;
533 RgRguCmnDatReq *cDatReq;
540 cDatReq = (RgRguCmnDatReq *)(pdu->datReq);
541 /* Add sdu(s) to the Message Buffer */
542 if (NULLP != cDatReq)
544 if(rgMUXInsSdu(inst,&pdu->schdTbSz,
545 RG_CCCH_LCID, cDatReq->pdu, sduBuf, err) != ROK)
549 RG_FREE_MSG(cDatReq->pdu);
554 dDatReq = (RgRguDDatReqPerUe *)(pdu->datReq);
555 /* Add sdu(s) to the Message Buffer */
556 if (NULLP != dDatReq)
558 if(pdu->tbIndex == 1)
561 /* Adding this temporary variable for optimization */
562 RguDatReqTb *datReqTb = &dDatReq->datReqTb[0];
564 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
567 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
572 if(rgMUXInsSdu(inst,&pdu->schdTbSz,
573 datReqTb->lchData[idx1].lcId,
574 datReqTb->lchData[idx1].pdu.mBuf[idx2],
577 RLOG1(L_ERROR, "FAILED for LCID:%d",datReqTb->lchData[idx1].lcId);
581 RG_FREE_MSG(datReqTb->lchData[idx1].pdu.mBuf[idx2]);
585 else if(pdu->tbIndex == 2)
588 RguDatReqTb *datReqTb = &dDatReq->datReqTb[1];
589 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
592 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
597 if(rgMUXInsSdu(inst,&pdu->schdTbSz,
598 datReqTb->lchData[idx1].lcId,
599 datReqTb->lchData[idx1].pdu.mBuf[idx2],
602 RLOG2(L_ERROR, "FAILED TB Size %d LCID:%d",
603 ((S16)pdu->schdTbSz),datReqTb->lchData[idx1].lcId);
607 RG_FREE_MSG(datReqTb->lchData[idx1].pdu.mBuf[idx2]);
616 } /* End of switch(reqType) */
617 if(rgMUXAddPadd(inst,&pdu->schdTbSz, sduBuf, FALSE, err) != ROK)
619 RLOG1(L_ERROR, "FAILED for TB Size:%d",(S16)pdu->schdTbSz);
626 * @brief Function to create MAC PDU from RLC SDUs and control elements, if any.
630 * Function : rgMUXBldPdu
632 * -# This function shall be invoked by Downlink Harq Module as soon as a
633 * Data request is received from RLC for a UE along with its stored
634 * control elements to create a MAC PDU.
635 * -# It shall create subheaders for the control elements (timing advance
636 * and contention resolution ID) and pack sub-header before each CE,
637 * if given, and then shall run through all the logical channels and
638 * create subheader for each of the SDUs given on that logical channel
639 * and pack corresponding sub-header before the each SDU
640 * -# It shall invoke rgMUXPadPdu if the total length of the created
641 * buffer is less than the scheduled TB size.
644 * @param[in] Inst *inst
645 * @param[in] RgBldPduInfo *bldPdu
646 * @param[in] Buffer **txPdu
647 * @param[out] RgErrInfo *err
661 S16 rgMUXBldPdu(inst, pdu, txPdu, err)
668 Buffer *mBuf = NULLP;
673 if (rgGetMsg(inst, &mBuf) != ROK)
675 /* Buffer couldnt get allocated. Return a failure */
676 err->errCause = RGERR_MUX_MEM_ALLOC_FAIL;
677 err->errType = RGERR_MUX_BLD_PDU;
678 RLOG1(L_FATAL, "Memory allocation failed during MUXing of MAC TB: MacInst %d", inst);
682 if(rgMUXAddCes(inst, pdu, mBuf, err) != ROK)
685 err->errType = RGERR_MUX_BLD_PDU;
686 RLOG1(L_ERROR, "Failed to Multiplex MAC CEs: MacInst %d", inst);
690 if(rgMUXAddSdus(inst, pdu, mBuf, err) != ROK)
693 err->errType = RGERR_MUX_BLD_PDU;
694 RLOG1(L_ERROR, "FAILED to Multiplex MAC SDU: MacInst %d", inst);
704 #else /* else of ifndef L2_OPTMZ */
707 * @brief Function to add SDU along with sub headers.
711 * Function : rgMUXAddSdus
713 * @param[in] RgBldPduInfo *pdu
714 * @param[out] Buffer *mBuf
715 * @param[out] Buffer *sduBuf
721 PRIVATE S16 rgMUXAddSdus
726 RgTfuDatReqTbInfo *tb,
730 PRIVATE S16 rgMUXAddSdus(pdu, sHdrBuf, tb, err)
734 RgTfuDatReqTbInfo *tb;
738 RgRguDDatReqPerUe *dDatReq;
739 RgRguCmnDatReq *cDatReq;
747 cDatReq = (RgRguCmnDatReq *)(pdu->datReq);
748 /* Add sdu(s) to the Message Buffer */
749 if (NULLP != cDatReq)
751 if(rgMUXInsSdu(inst, &pdu->schdTbSz,
752 RG_CCCH_LCID, cDatReq->pdu,
753 sHdrBuf, NULLP, err) != ROK)
757 /* L2 Optimization for mUe/Tti: RLC pdu mbuf pointer will be passed
758 * to CL it is stored in DlHqProc->TbInfo and it will be used in
759 * case of harq retransmission. Store CCCH data at 0th index of
761 tb->lchInfo[tb->numLch].mBuf[(tb->lchInfo[tb->numLch].numPdu)]\
763 tb->lchInfo[tb->numLch].numPdu++;
765 RLOG3(L_INFO,"MSG4 is muxed numLch=%ld numPdu=%ld tbaddr =%p", tb->numLch,tb->lchInfo[tb->numLch-1].numPdu, (U32)tb);
770 dDatReq = (RgRguDDatReqPerUe *)(pdu->datReq);
771 /* Add sdu(s) to the Message Buffer */
772 if (NULLP != dDatReq)
774 if(pdu->tbIndex == 1)
777 /* Adding this temporary variable for optimization */
778 RguDatReqTb *datReqTb = &dDatReq->datReqTb[0];
780 tb->numLch = lchIdx = 0;
782 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
784 tb->lchInfo[lchIdx].numPdu = pduIdx = 0;
787 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
792 if(rgMUXInsSdu(inst, &pdu->schdTbSz,
793 datReqTb->lchData[idx1].lcId,
794 datReqTb->lchData[idx1].pdu.mBuf[idx2],
795 sHdrBuf, NULLP, err) != ROK)
797 RGDBGERRNEW(inst,(rgPBuf(inst), "FAILED\n"));
801 /* L2 Optimization for mUe/Tti:Increment numPdu by 1
802 * Store pdu buffer in tb to send it to CL/PHY. Increment
804 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++;
813 if(NULL != datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont)
816 tmp = datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont;
817 if(NULL == tmp->b_rptr)
819 RLOG0(L_INFO,"11111Its Null here only ");
824 RLOG0(L_INFO,"222222Its Null here only \n");
827 //tb->lchInfo[tb->numLch].numPdu++;
835 tb->lchInfo[lchIdx].numPdu = pduIdx;
836 /* If Bearer is UM then MBUF to be free by MAC layer */
837 tb->lchInfo[lchIdx].freeBuff = datReqTb->lchData[idx1].freeBuff;
843 else if(pdu->tbIndex == 2)
846 RguDatReqTb *datReqTb = &dDatReq->datReqTb[1];
847 tb->numLch = lchIdx = 0;
848 // prc_trace_format_string(0x40,3,": AddSdus: numOfLch=%d numOfPdu=%d, schdSz=%d", datReqTb->nmbLch, datReqTb->lchData[0].pdu.numPdu, pdu->schdTbSz);
849 for (idx1=0; (idx1 < datReqTb->nmbLch); idx1++)
851 tb->lchInfo[lchIdx].numPdu = pduIdx = 0;
853 (idx2 < datReqTb->lchData[idx1].pdu.numPdu);
858 if(rgMUXInsSdu(inst, &pdu->schdTbSz,
859 datReqTb->lchData[idx1].lcId,
860 datReqTb->lchData[idx1].pdu.mBuf[idx2],
861 sHdrBuf, NULLP, err) != ROK)
863 RGDBGERRNEW(inst,(rgPBuf(inst), "FAILED TB Size %d\n",
864 ((S16)pdu->schdTbSz)));
867 /* L2 Optimization for mUe/Tti:Increment numPdu by 1
868 * Store pdu buffer in tb to send it to CL/PHY. Increment
870 tb->lchInfo[lchIdx].mBuf[pduIdx] = datReqTb->lchData[idx1].pdu.mBuf[idx2];
872 if(datReqTb->lchData[idx1].freeBuff == FALSE)
873 {/* Not incrementing refCnt for UM Mode. */
874 tb->lchInfo[lchIdx].mBuf[pduIdx]->refCnt++;
877 if(NULL != datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont)
880 tmp = datReqTb->lchData[idx1].pdu.mBuf[idx2]->b_cont;
881 if(NULL == tmp->b_rptr)
883 RLOG0(L_INFO,"2212121Its Null here only \n");
888 RLOG0(L_INFO,"343343433ts Null here only \n");
891 // tb->lchInfo[tb->numLch].numPdu++;
899 tb->lchInfo[lchIdx].numPdu = pduIdx;
900 /* If Bearer is UM then MBUF to be free by MAC layer */
901 tb->lchInfo[lchIdx].freeBuff = datReqTb->lchData[idx1].freeBuff;
911 case EVENT_SLOT_IND_TO_MAC:
915 } /* End of switch(reqType) */
918 if(rgMUXAddPadd(inst, &pdu->schdTbSz, sduBuf, NULLP, FALSE, err) != ROK)
920 //RGDBGERRNEW((rgPBuf, "FAILED"));
923 tb->padSize = padSize;
929 * @brief Function to create MAC PDU from RLC SDUs and control elements, if any.
933 * Function : rgMUXBldPdu
934 * -# This function shall be invoked by Downlink Harq Module as soon as a
935 * Data request is received from RLC for a UE along with its stored
936 * control elements to create a MAC PDU.
937 * -# It shall create subheaders for the control elements (timing advance
938 * and contention resolution ID), if given, and then shall run through
939 * all the logical channels and create subheader for each of the SDUs
940 * given on that logical channel.
941 * -# L2 Optimization for mUe/Tti: Avoiding muxing to reduce overhead of
942 * additional Mbuf allocation memory related operation.
943 -# MAC header, MAC CEs, MAC PDUs and MAC padding are stored in pre-
944 allocated mBufs. These pointers will not be freed by CL
945 * -# It shall invoke rgMUXPadPdu if the total length of the created
946 * buffer is less than the scheduled TB size.
947 * -# At successfull operation of this function tb->macHdr, will have
948 * complete MAC Header. tb->macCes will have MAC CEs if any. tb->
949 * lchInfo[idx].mBuf[idx] will have MAC SDU per LCH per TB per UE
952 * @param[in] RgBldPduInfo *bldPdu
953 * @param[out] RgTbInfo *tb
954 * @param[out] RgErrInfo *err
964 RgTfuDatReqTbInfo *tb,
968 S16 rgMUXBldPdu(inst, pdu, tb, err)
971 RgTfuDatReqTbInfo *tb;
975 Buffer *mBuf1; /* MAC hearder */
976 Buffer *mBuf2; /* MAC CEs */
977 //U32 lchIdx, pduIdx;
981 /* Reseting macHdr and macCes pointers */
983 SResetMBuf(tb->macHdr);
985 SResetMBuf(tb->macCes);
987 mBuf1 = tb->macHdr; /* MAC hearder */
988 mBuf2 = tb->macCes; /* MAC CEs */
989 tb->tbSize = pdu->schdTbSz;
991 if(rgMUXAddCes(inst, pdu, mBuf1, mBuf2, err) != ROK)
993 /* Reset rPtr and wPtr to the base of data buffer(db_base)*/
994 RLOG0(L_INFO,"rgMUXBldPdu: rgMUXAddCes is Failed \n");
996 err->errType = RGERR_MUX_BLD_PDU;
997 //RGDBGERRNEW((rgPBuf, "FAILED"));
1000 if(rgMUXAddSdus(inst, pdu, mBuf1, tb, err) != ROK)
1002 /*TODO:MP Reset rPtr and wPtr to the base of data buffer(db_base)
1003 * Reset numLch and numPdu to zero and set MAC SDU buf to NULLP */
1004 RLOG0(L_INFO, "rgMUXBldPdu: rgMUXAddSdus is Failed \n");
1007 err->errType = RGERR_MUX_BLD_PDU;
1008 //RGDBGERRNEW((rgPBuf, "FAILED"));
1012 // SPrntMsg(tb->macHdr, 0, 0);
1013 // prc_trace_format_string(0x40,3,": padSize=%ld", tb->padSize);
1020 #endif /* end of L2_OPTMZ */
1023 * @brief Function to create RAR PDU.
1027 * Function : rgMUXBldRarPdu
1028 * This function is used to build RAR PDUs and is being
1029 * invoked by the scheduler.
1031 * @param[out]RgCellCb *cellCb
1032 * @param[in] RgRaRspAlloc *bldPdu
1033 * @param[in] Buffer **txPdu
1034 * @param[out] RgErrInfo *err
1043 RgInfRaRntiInfo *alloc,
1048 S16 rgMUXBldRarPdu(cell, alloc, txPdu, err)
1050 RgInfRaRntiInfo *alloc;
1055 Buffer *datBuf = NULLP;
1057 U8 data[RG_RAR_ELEM_LEN];
1061 Inst inst = cell->macInst - RG_INST_START;
1063 TRC2(rgMUXBldRarPdu)
1065 schdTbSz = alloc->schdTbSz;
1066 /* RAR PDU Requirements */
1068 1. SubHeader - R/T/RAPID. //5GNR, changed E to R
1069 2. TA ( if applicable)
1071 a. Hopping Flag - 1 Bit.
1072 b. Fixed Size RB Assignment. - 10 Bits.
1073 c. Truncated Modulation and coding scheme - 4 Bits.
1074 d. TPC command for scheduled PUSCH. - 3 Bits.
1075 e. UL Delay - 1 Bit.
1076 f. CQI Request - 1 Bit.
1080 /* Initialize the error type */
1081 err->errType = RGERR_MUX_BLD_RAR_PDU;
1083 if ((ret = rgGetMsg(inst,&datBuf)) != ROK)
1085 /* Buffer couldnt get allocated. Return a failure */
1086 err->errCause = RGERR_MUX_MEM_ALLOC_FAIL;
1087 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId, "FAILED to getMsg");
1091 if (TRUE == alloc->backOffInd.pres)
1093 /*Set T Bit , NO E bit Required */
1096 hdrByte |= (0x0F & (alloc->backOffInd.val));
1098 /* Add the header */
1099 RG_PACK_RAR_SHDR(hdrByte, datBuf, ret);
1102 err->errCause = RGERR_MUX_BLD_BI_FAIL;
1103 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"RGERR_MUX_BLD_BI_FAIL");
1104 RG_FREE_MSG(datBuf);
1110 for (idx=0; idx < (alloc->numCrnti) &&
1111 (schdTbSz >= RG_RAR_ELEM_LEN+RG_RAR_SHDR_LEN); idx++)
1116 hdrByte |= (0x3F & (alloc->crntiInfo[idx].rapId));
1118 /* Add the header */
1119 RG_PACK_RAR_SHDR(hdrByte, datBuf, ret);
1122 err->errCause = RGERR_MUX_BLD_RAPIDHDR_FAIL;
1123 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"RGERR_MUX_BLD_RAPIDHDR_FAIL");
1124 RG_FREE_MSG(datBuf);
1128 /* Prepare the data */
1129 data[0] = 0x7F & ((alloc->crntiInfo[idx].ta.val) >> 4);
1134 rgMUXGet20bitRarGrnt(cell->bwCfg.ulTotalBw, &(alloc->crntiInfo[idx].grnt), &data[1]);
1136 data[1] |= ((U8)((alloc->crntiInfo[idx].ta.val) << 4));
1137 data[4] = (alloc->crntiInfo[idx].tmpCrnti) >> 8;
1138 data[5] = (U8) (alloc->crntiInfo[idx].tmpCrnti);
1140 RLOG_ARG2(L_DEBUG,DBG_CELLID,cell->cellId,
1141 "Rar,Rapid=%d, Temp CRNTI:%d",
1142 alloc->crntiInfo[idx].rapId,
1143 alloc->crntiInfo[idx].tmpCrnti);
1144 MS_BUF_ADD_ALLOC_CALLER();
1145 if(SAddPstMsgMult(&data[0], RG_RAR_ELEM_LEN, datBuf) != ROK)
1147 err->errCause = RGERR_MUX_BLD_RAPID_FAIL;
1148 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"RGERR_MUX_BLD_RAPID_FAIL");
1149 RG_FREE_MSG(datBuf);
1152 schdTbSz -= RG_RAR_ELEM_LEN+RG_RAR_SHDR_LEN;
1155 if(rgMUXAddPadd(inst,&schdTbSz, datBuf, TRUE, err) != ROK)
1157 RG_FREE_MSG(datBuf);
1158 RLOG_ARG0(L_ERROR,DBG_CELLID,cell->cellId,"FAILED to mux add padding");
1165 } /* rgMUXBldRarPdu */
1167 /***********************************************************
1169 * Func : rgMUXGet20bitRarGrnt
1171 * Desc : This function fills up the 20-bit grant
1180 **********************************************************/
1182 PRIVATE Void rgMUXGet20bitRarGrnt
1185 RgInfRarUlGrnt *msg3Grnt,
1189 PRIVATE Void rgMUXGet20bitRarGrnt(ulBw, msg3Grnt, grnt)
1191 RgInfRarUlGrnt *msg3Grnt;
1195 U16 riv = rgMUXCalcRiv(ulBw, msg3Grnt->rbStart, msg3Grnt->numRb);
1197 TRC2(rgMUXGet20bitRarGrnt);
1199 grnt[2] = msg3Grnt->cqiBit; /* cqi bit is 0, output from sched */
1200 grnt[2] |= (msg3Grnt->delayBit << 1);
1201 grnt[2] |= (msg3Grnt->tpc << 2);
1202 grnt[2] |= (msg3Grnt->iMcsCrnt << 5);
1204 grnt[1] = (msg3Grnt->iMcsCrnt >> 3);
1205 /* Forcing right shift to insert 0 as the LSB:
1206 * since this is assumed in the computation */
1207 grnt[1] |= (U8)((riv << 1) & 0xFE);
1209 grnt[0] = (U8)((riv >> 7) & 0x07);
1210 grnt[0] |= ((msg3Grnt->hop & 0x01) << 3);
1213 } /* rgMUXGet20bitRarGrnt */
1215 /***********************************************************
1217 * Func : rgMUXCalcRiv
1219 * Desc : This function calculates RIV.
1227 **********************************************************/
1236 U16 rgMUXCalcRiv(bw, rbStart, numRb)
1242 U8 numRbMinus1 = numRb - 1;
1247 if (numRbMinus1 <= bw/2)
1249 riv = bw * numRbMinus1 + rbStart;
1253 riv = bw * (bw - numRbMinus1) + (bw - rbStart - 1);
1256 } /* rgMUXCalcRiv */
1260 /**********************************************************************
1263 **********************************************************************/