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 It has APIs exposed by Lower Interface Modulue of MAC. It acts as an
33 Interface handler for lower interface APIs.
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_FILE_ID=182;
37 static int RLOG_MODULE_ID=4096;
38 /* header include files -- defines (.h) */
39 #include "envopt.h" /* environment options */
40 #include "envdep.h" /* environment dependent */
41 #include "envind.h" /* environment independent */
42 #include "gen.h" /* general layer */
43 #include "ssi.h" /* system services */
44 #include "cm5.h" /* common timers defines */
45 #include "cm_hash.h" /* common hash list defines */
46 #include "cm_llist.h" /* common linked list defines */
47 #include "cm_mblk.h" /* memory management */
48 #include "cm_tkns.h" /* common tokens */
49 #include "cm_lte.h" /* common tokens */
50 #include "rgu.h" /* RGU defines */
51 #include "tfu.h" /* RGU defines */
52 #include "lrg.h" /* layer management defines for LTE-MAC */
53 #include "crg.h" /* layer management defines for LTE-MAC */
54 #include "rg_sch_inf.h" /* layer management defines for LTE-MAC */
55 #include "rg_env.h" /* customisable defines and macros for MAC */
56 #include "rg.h" /* defines and macros for MAC */
59 /* header/extern include files (.x) */
60 #include "gen.x" /* general layer typedefs */
61 #include "ssi.x" /* system services typedefs */
62 #include "cm5.x" /* common timers */
63 #include "cm_hash.x" /* common hash list */
64 #include "cm_lib.x" /* common library */
65 #include "cm_llist.x" /* common linked list */
66 #include "cm_mblk.x" /* memory management */
67 #include "cm_tkns.x" /* common tokens */
68 #include "cm_lte.x" /* common tokens */
69 #include "rgu.x" /* RGU types */
70 #include "tfu.x" /* RGU types */
71 #include "lrg.x" /* layer management typedefs for MAC */
72 #include "crg.x" /* layer management typedefs for MAC */
73 #include "rg_sch_inf.x" /* SCH interface typedefs */
74 #include "rg_prg.x" /* PRG interface typedefs */
75 #include "du_app_mac_inf.h"
76 #include "rg.x" /* typedefs for MAC */
78 #include "mac_upr_inf_api.h"
83 PRIVATE S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
85 PRIVATE Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
88 /* function pointers for packing slot ind from mac to sch */
89 //S16 packMacSchSlotInd(Pst *pst, SlotIndInfo *slotInd);
91 MacSchSlotIndFunc macSchSlotIndOpts[] =
99 PRIVATE Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
102 /* forward references */
105 * @brief This API is invoked to send TFU SAP bind request to PHY.
109 * Function : rgLIMTfuBndReq
111 * This API is invoked to send TFU SAP bind request to PHY. It fills in
112 * the Pst structure, spId and suId values and invokes bind request
115 * @param[in] Inst inst
116 * @param[in] SuId suId
117 * @param[in] SpId spId
123 PUBLIC S16 rgLIMTfuBndReq
130 PUBLIC S16 rgLIMTfuBndReq(inst,suId, spId)
140 TRC2(rgLIMTfuBndReq);
142 /* Get the lower SAP control block from the layer control block. */
143 tfuSap = &(rgCb[inst].tfuSap);
144 (Void)cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
145 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
147 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
150 } /* rgLIMTfuBndReq */
154 * @brief This API is invoked to send TFU SAP unbind request to PHY.
158 * Function : rgLIMTfuBndReq
160 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
161 * the Pst structure and spId value and invokes unbind request
164 * @param[in] Inst inst
165 * @param[in] SpId spId
166 * @param[in] Reason reason
172 PUBLIC S16 rgLIMTfuUbndReq
179 PUBLIC S16 rgLIMTfuUbndReq(inst,spId, reason)
189 TRC2(rgLIMTfuUbndReq);
191 /* Get the lower SAP control block from the layer control block. */
192 tfuSap = &(rgCb[inst].tfuSap);
193 cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
194 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
196 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
200 } /* rgLIMTfuUbndReq */
204 * @brief Bind confirm API for TFU SAP
208 * Function : RgLiTfuBndCfm
210 * This API is invoked by PHY to confirm TFU SAP bind.
213 * @param[in] Pst *pst
214 * @param[in] SuId suId
215 * @param[in] U8 status
221 PUBLIC S16 RgLiTfuBndCfm
228 PUBLIC S16 RgLiTfuBndCfm(pst, suId, status)
241 RG_IS_INST_VALID(pst->dstInst);
242 inst = pst->dstInst - RG_INST_START;
243 /* Lets validate suId first */
245 tfuSap = &(rgCb[inst].tfuSap);
247 if (suId != tfuSap->sapCfg.suId)
249 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
250 tfuSap->sapCfg.suId, suId);
253 ret = rgLMMBndCfm (pst, suId, status);
255 } /* RgLiTfuBndCfm */
257 /** @brief This function Validates the SAP information received along with the
258 * primitive from the lower layer.
260 * Validates SAP information.
261 * @param[in] Inst inst
262 * @param suId The SAP Id
269 PRIVATE S16 rgLIMValidateSap
275 PRIVATE S16 rgLIMValidateSap(inst,suId)
282 TRC2(rgLIMValidateSap)
284 tfuSap = &(rgCb[inst].tfuSap);
286 /* First lets check the suId */
287 if( suId != tfuSap->sapCfg.suId)
289 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
290 tfuSap->sapCfg.suId, suId);
293 if (tfuSap->sapSta.sapState != LRG_BND)
295 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
296 tfuSap->sapCfg.suId);
300 } /* end of rgLIMValidateSap */
302 /** @brief This function frees up the TfuDatIndInfo structure
306 * Function: rgLIMUtlFreeDatIndEvnt
307 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
308 * free up the buffer's present in the datIndLst.
311 * @param [in] TfuDatIndInfo *datInd
312 * @param [in] Bool *error
316 PRIVATE Void rgLIMUtlFreeDatIndEvnt
318 TfuDatIndInfo *datInd,
322 PRIVATE Void rgLIMUtlFreeDatIndEvnt(datInd, error)
323 TfuDatIndInfo *datInd;
331 TRC2(rgLIMUtlFreeDatIndEvnt);
332 /* Steps of freeing up the TfuDatInd.
333 * 1. loop through the datIndLst and free up all the buffers.
334 * 2. free up the whole event
336 if ((error == TRUE) && (datInd->datIndLst.count > 0))
338 node = datInd->datIndLst.first;
341 datInfo = (TfuDatInfo*)node->node;
342 RG_FREE_MSG(datInfo->mBuf);
348 } /* end of rgLIMUtlFreeDatIndEvnt*/
351 * @brief Downlink data indication from PHY.
355 * Function : RgLiTfuDatInd
357 * This API is invoked by PHY to send data indication to MAC on
358 * recieving data from UEs.
360 * @param[in] Pst *pst
361 * @param[in] SuId suId
362 * @param[in] TfuDatIndInfo *datInd
368 PUBLIC S16 RgLiTfuDatInd
372 TfuDatIndInfo *datInd
375 PUBLIC S16 RgLiTfuDatInd(pst, suId, datInd)
378 TfuDatIndInfo *datInd;
383 VOLATILE U32 startTime=0;
387 // printf("5GTF:: DatindRcvd\n");
389 RG_IS_INST_VALID(pst->dstInst);
390 inst = pst->dstInst - RG_INST_START;
392 SStartTask(&startTime, PID_MAC_TFU_DATIND);
395 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
397 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
398 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
402 /* Now call the TOM (Tfu ownership module) primitive to process further */
403 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
404 datInd->datIndLst.count;
405 ret = rgTOMDatInd(inst,datInd);
406 /* Fix: sriky memory corruption precautions */
407 /* Free up the memory for the request structure */
410 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
414 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
418 SStopTask(startTime, PID_MAC_TFU_DATIND);
424 /** @brief This function frees up the TfuDatReqInfo structure.
428 * Function: rgLIMUtlFreeDatReqEvnt
429 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
430 * free up the buffer's present in the PDUs list.
433 * @param [in] TfuDatReqInfo *datReq
434 * @param [in] Bool *error
438 PRIVATE Void rgLIMUtlFreeDatReqEvnt
440 TfuDatReqInfo *datReq,
444 PRIVATE Void rgLIMUtlFreeDatReqEvnt(datReq, error)
445 TfuDatReqInfo *datReq;
450 TfuDatReqPduInfo *datInfo;
454 TRC2(rgLIMUtlFreeDatReqEvnt);
455 /* Steps of freeing up the TfuDatReq.
456 * 1. Free the bch buffer.
457 * 2. loop through the pdus list and free up all the buffers.
458 * 3. free up the whole event
462 if (datReq->bchDat.pres == PRSNT_NODEF)
464 RG_FREE_MSG(datReq->bchDat.val);
466 if (datReq->pdus.count > 0)
468 node = datReq->pdus.first;
471 datInfo = (TfuDatReqPduInfo*)node->node;
472 for (i=0; i<datInfo->nmbOfTBs; i++)
474 if (datInfo->mBuf[i] != NULLP)
476 RG_FREE_MSG(datInfo->mBuf[i]);
485 } /* end of rgLIMUtlFreeDatReqEvnt*/
488 * @brief This API is invoked to send Data to PHY.
492 * Function : rgLIMTfuDatReq
494 * This API is invoked to send Data to PHY. It
495 * fills in the Pst structure, spId value and invokes Data
496 * request primitive at TFU.
498 * @param[in] Inst inst
499 * @param[in] TfuDatReqInfo *datReq
505 PUBLIC S16 rgLIMTfuDatReq
508 TfuDatReqInfo *datReq
511 PUBLIC S16 rgLIMTfuDatReq(inst,datReq)
513 TfuDatReqInfo *datReq;
521 /* Get the lower SAP control block from the layer control block. */
522 tfuSap = &(rgCb[inst].tfuSap);
525 if (tfuSap->sapSta.sapState != LRG_BND)
527 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
528 tfuSap->sapSta.sapState);
530 /* This case will never be hit if sap is not bound then we dont get TTI */
531 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
537 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
539 /* Using existing pst - for optimization */
540 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
543 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
546 } /* rgLIMTfuDatReq*/
550 * @brief This API is invoked to send Data to PHY.
554 * Function : rgLIMTfuDelDatReq
556 * This API is invoked to send Data to PHY. It
557 * fills in the Pst structure, spId value and invokes Data
558 * request primitive at TFU.
560 * @param[in] Inst inst
561 * @param[in] TfuDelDatReqInfo *datReq
567 PUBLIC S16 rgLIMTfuDelDatReq
570 TfuDelDatReqInfo *delDatReq
573 PUBLIC S16 rgLIMTfuDatReq(inst,delDatReq)
575 TfuDelDatReqInfo *delDatReq;
581 TRC2(rgLIMTfuDelDatReq)
583 /* Get the lower SAP control block from the layer control block. */
584 tfuSap = &(rgCb[inst].tfuSap);
587 if (tfuSap->sapSta.sapState != LRG_BND)
589 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
590 tfuSap->sapSta.sapState);
595 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
598 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
601 } /* rgLIMTfuDatReq*/
604 /*******************************************************************
606 * @brief Fills post structure
610 * Function : fillMacToSchPst
613 * Fills post structure to be used when sending msg from
616 * @params[in] Post structure pointer
617 * @return ROK - success
620 * ****************************************************************/
621 void fillMacToSchPst(Pst *pst)
631 pst->selector = MAC_SELECTOR_TC;
634 /*******************************************************************
636 * @brief MAC handler for config response from PHY
640 * Function : fapiMacConfigRsp
643 * Processes config response from PHY and sends cell config
649 * ****************************************************************/
650 void fapiMacConfigRsp()
652 /* TODO : Processing of config response from PHY */
654 /* Send cell config cfm to DU APP */
655 MacSendCellCfgCfm(RSP_OK);
659 * @brief Transmission time interval indication from PHY.
663 * Function : sendSlotIndMacToSch
665 * This API is invoked by MAC to send slot ind to scheduler.
667 * @param[in] SlotIndInfo *slotInd
672 int sendSlotIndMacToSch(SlotIndInfo *slotInd)
674 /* fill Pst structure to send to lwr_mac to MAC */
677 fillMacToSchPst(&pst);
678 pst.event = EVENT_SLOT_IND_TO_SCH;
680 return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
684 /*******************************************************************
686 * @brief Send slot indication to DU APP
690 * Function : sendSlotIndMacToDuApp
693 * Send slot indication to DU APP
695 * @params[in] Slot indication info
696 * @return ROK - success
699 * ****************************************************************/
700 int sendSlotIndMacToDuApp(SlotIndInfo *slotInd)
705 /* Send Slot Indication to DU APP */
706 MAC_ALLOC(slotInfo, sizeof(SlotInfo));
709 DU_LOG("\nMAC : Slot Indication memory allocation failed");
713 slotInfo->cellId = macCb.macCell->cellId;
714 slotInfo->sfn = slotInd->sfn;
715 slotInfo->slot = slotInd->slot;
718 pst.selector = DU_MAC_LWLC;
720 pst.dstEnt = ENTDUAPP;
722 pst.srcInst = macCb.macInst;
723 pst.dstProcId = rgCb[pst.srcInst].rgInit.procId;
724 pst.srcProcId = rgCb[pst.srcInst].rgInit.procId;
725 pst.region = MAC_MEM_REGION;
727 pst.event = EVENT_MAC_SLOT_IND;
732 return MacDuAppSlotInd(&pst, slotInfo);
737 * @brief Transmission time interval indication from PHY.
741 * Function : fapiMacSlotInd
743 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
745 * @param[in] Pst *pst
746 * @param[in] SuId suId
747 * @param[in] SlotIndInfo *slotInd
752 PUBLIC S16 fapiMacSlotInd
759 VOLATILE U32 startTime=0;
762 DU_LOG("\nMAC : Slot Indication received");
764 RG_IS_INST_VALID(pst->dstInst);
765 inst = pst->dstInst - RG_INST_START;
767 SStartTask(&startTime, PID_MAC_TTI_IND);
769 /* send slot indication to scheduler */
770 ret = sendSlotIndMacToSch(slotInd);
773 DU_LOG("\nMAC : Sending of slot ind msg from MAC to SCH failed");
777 /* Now call the TOM (Tfu ownership module) primitive to process further */
778 ret = macProcessSlotInd(inst,*slotInd);
781 DU_LOG("\nMAC : macProcessSlotInd failed");
785 /* send slot indication to du app */
786 ret = sendSlotIndMacToDuApp(slotInd);
789 DU_LOG("\nMAC :Sending of slot ind msg from MAC to DU APP failed");
794 SStopTask(startTime, PID_MAC_TTI_IND);
797 } /* fapiMacSlotInd */
799 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
801 * @brief Transmission of non-rt indication from CL.
805 * Function : RgLiTfuNonRtInd
807 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
809 * @param[in] Pst *pst
810 * @param[in] SuId suId
816 PUBLIC S16 RgLiTfuNonRtInd
822 PUBLIC S16 RgLiTfuNonRtInd(pst, suId)
827 TRC3(RgLiTfuNonRtInd);
830 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
832 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
836 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
838 } /* RgLiTfuNonRtInd */
841 /**********************************************************************
844 **********************************************************************/