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) */
40 #include "envopt.h" /* environment options */
41 #include "envdep.h" /* environment dependent */
42 #include "envind.h" /* environment independent */
43 #include "gen.h" /* general layer */
44 #include "ssi.h" /* system services */
45 #include "cm5.h" /* common timers defines */
46 #include "cm_hash.h" /* common hash list defines */
47 #include "cm_llist.h" /* common linked list defines */
48 #include "cm_mblk.h" /* memory management */
49 #include "cm_tkns.h" /* common tokens */
50 #include "cm_lte.h" /* common tokens */
51 #include "rgu.h" /* RGU defines */
52 #include "tfu.h" /* RGU defines */
53 #include "lrg.h" /* layer management defines for LTE-MAC */
54 #include "crg.h" /* layer management defines for LTE-MAC */
55 #include "rg_sch_inf.h" /* layer management defines for LTE-MAC */
56 #include "rg_env.h" /* customisable defines and macros for MAC */
57 #include "rg.h" /* defines and macros for MAC */
60 /* header/extern include files (.x) */
61 #include "gen.x" /* general layer typedefs */
62 #include "ssi.x" /* system services typedefs */
63 #include "cm5.x" /* common timers */
64 #include "cm_hash.x" /* common hash list */
65 #include "cm_lib.x" /* common library */
66 #include "cm_llist.x" /* common linked list */
67 #include "cm_mblk.x" /* memory management */
68 #include "cm_tkns.x" /* common tokens */
69 #include "cm_lte.x" /* common tokens */
70 #include "rgu.x" /* RGU types */
71 #include "tfu.x" /* RGU types */
72 #include "lrg.x" /* layer management typedefs for MAC */
73 #include "crg.x" /* layer management typedefs for MAC */
74 #include "rg_sch_inf.x" /* SCH interface typedefs */
75 #include "rg_prg.x" /* PRG interface typedefs */
76 #include "du_app_mac_inf.h"
77 #include "rg.x" /* typedefs for MAC */
79 #include "mac_upr_inf_api.h"
84 PRIVATE S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
86 PRIVATE Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
89 PRIVATE Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
92 /* forward references */
95 * @brief This API is invoked to send TFU SAP bind request to PHY.
99 * Function : rgLIMTfuBndReq
101 * This API is invoked to send TFU SAP bind request to PHY. It fills in
102 * the Pst structure, spId and suId values and invokes bind request
105 * @param[in] Inst inst
106 * @param[in] SuId suId
107 * @param[in] SpId spId
113 PUBLIC S16 rgLIMTfuBndReq
120 PUBLIC S16 rgLIMTfuBndReq(inst,suId, spId)
130 TRC2(rgLIMTfuBndReq);
132 /* Get the lower SAP control block from the layer control block. */
133 tfuSap = &(rgCb[inst].tfuSap);
134 (Void)cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
135 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
137 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
140 } /* rgLIMTfuBndReq */
144 * @brief This API is invoked to send TFU SAP unbind request to PHY.
148 * Function : rgLIMTfuBndReq
150 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
151 * the Pst structure and spId value and invokes unbind request
154 * @param[in] Inst inst
155 * @param[in] SpId spId
156 * @param[in] Reason reason
162 PUBLIC S16 rgLIMTfuUbndReq
169 PUBLIC S16 rgLIMTfuUbndReq(inst,spId, reason)
179 TRC2(rgLIMTfuUbndReq);
181 /* Get the lower SAP control block from the layer control block. */
182 tfuSap = &(rgCb[inst].tfuSap);
183 cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
184 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
186 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
190 } /* rgLIMTfuUbndReq */
194 * @brief Bind confirm API for TFU SAP
198 * Function : RgLiTfuBndCfm
200 * This API is invoked by PHY to confirm TFU SAP bind.
203 * @param[in] Pst *pst
204 * @param[in] SuId suId
205 * @param[in] U8 status
211 PUBLIC S16 RgLiTfuBndCfm
218 PUBLIC S16 RgLiTfuBndCfm(pst, suId, status)
231 RG_IS_INST_VALID(pst->dstInst);
232 inst = pst->dstInst - RG_INST_START;
233 /* Lets validate suId first */
235 tfuSap = &(rgCb[inst].tfuSap);
237 if (suId != tfuSap->sapCfg.suId)
239 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
240 tfuSap->sapCfg.suId, suId);
243 ret = rgLMMBndCfm (pst, suId, status);
245 } /* RgLiTfuBndCfm */
247 /** @brief This function Validates the SAP information received along with the
248 * primitive from the lower layer.
250 * Validates SAP information.
251 * @param[in] Inst inst
252 * @param suId The SAP Id
259 PRIVATE S16 rgLIMValidateSap
265 PRIVATE S16 rgLIMValidateSap(inst,suId)
272 TRC2(rgLIMValidateSap)
274 tfuSap = &(rgCb[inst].tfuSap);
276 /* First lets check the suId */
277 if( suId != tfuSap->sapCfg.suId)
279 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
280 tfuSap->sapCfg.suId, suId);
283 if (tfuSap->sapSta.sapState != LRG_BND)
285 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
286 tfuSap->sapCfg.suId);
290 } /* end of rgLIMValidateSap */
292 /** @brief This function frees up the TfuDatIndInfo structure
296 * Function: rgLIMUtlFreeDatIndEvnt
297 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
298 * free up the buffer's present in the datIndLst.
301 * @param [in] TfuDatIndInfo *datInd
302 * @param [in] Bool *error
306 PRIVATE Void rgLIMUtlFreeDatIndEvnt
308 TfuDatIndInfo *datInd,
312 PRIVATE Void rgLIMUtlFreeDatIndEvnt(datInd, error)
313 TfuDatIndInfo *datInd;
321 TRC2(rgLIMUtlFreeDatIndEvnt);
322 /* Steps of freeing up the TfuDatInd.
323 * 1. loop through the datIndLst and free up all the buffers.
324 * 2. free up the whole event
326 if ((error == TRUE) && (datInd->datIndLst.count > 0))
328 node = datInd->datIndLst.first;
331 datInfo = (TfuDatInfo*)node->node;
332 RG_FREE_MSG(datInfo->mBuf);
338 } /* end of rgLIMUtlFreeDatIndEvnt*/
341 * @brief Downlink data indication from PHY.
345 * Function : RgLiTfuDatInd
347 * This API is invoked by PHY to send data indication to MAC on
348 * recieving data from UEs.
350 * @param[in] Pst *pst
351 * @param[in] SuId suId
352 * @param[in] TfuDatIndInfo *datInd
358 PUBLIC S16 RgLiTfuDatInd
362 TfuDatIndInfo *datInd
365 PUBLIC S16 RgLiTfuDatInd(pst, suId, datInd)
368 TfuDatIndInfo *datInd;
373 VOLATILE U32 startTime=0;
377 // printf("5GTF:: DatindRcvd\n");
379 RG_IS_INST_VALID(pst->dstInst);
380 inst = pst->dstInst - RG_INST_START;
382 SStartTask(&startTime, PID_MAC_TFU_DATIND);
385 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
387 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
388 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
392 /* Now call the TOM (Tfu ownership module) primitive to process further */
393 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
394 datInd->datIndLst.count;
395 ret = rgTOMDatInd(inst,datInd);
396 /* Fix: sriky memory corruption precautions */
397 /* Free up the memory for the request structure */
400 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
404 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
408 SStopTask(startTime, PID_MAC_TFU_DATIND);
414 /** @brief This function frees up the TfuDatReqInfo structure.
418 * Function: rgLIMUtlFreeDatReqEvnt
419 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
420 * free up the buffer's present in the PDUs list.
423 * @param [in] TfuDatReqInfo *datReq
424 * @param [in] Bool *error
428 PRIVATE Void rgLIMUtlFreeDatReqEvnt
430 TfuDatReqInfo *datReq,
434 PRIVATE Void rgLIMUtlFreeDatReqEvnt(datReq, error)
435 TfuDatReqInfo *datReq;
440 TfuDatReqPduInfo *datInfo;
444 TRC2(rgLIMUtlFreeDatReqEvnt);
445 /* Steps of freeing up the TfuDatReq.
446 * 1. Free the bch buffer.
447 * 2. loop through the pdus list and free up all the buffers.
448 * 3. free up the whole event
452 if (datReq->bchDat.pres == PRSNT_NODEF)
454 RG_FREE_MSG(datReq->bchDat.val);
456 if (datReq->pdus.count > 0)
458 node = datReq->pdus.first;
461 datInfo = (TfuDatReqPduInfo*)node->node;
462 for (i=0; i<datInfo->nmbOfTBs; i++)
464 if (datInfo->mBuf[i] != NULLP)
466 RG_FREE_MSG(datInfo->mBuf[i]);
475 } /* end of rgLIMUtlFreeDatReqEvnt*/
478 * @brief This API is invoked to send Data to PHY.
482 * Function : rgLIMTfuDatReq
484 * This API is invoked to send Data to PHY. It
485 * fills in the Pst structure, spId value and invokes Data
486 * request primitive at TFU.
488 * @param[in] Inst inst
489 * @param[in] TfuDatReqInfo *datReq
495 PUBLIC S16 rgLIMTfuDatReq
498 TfuDatReqInfo *datReq
501 PUBLIC S16 rgLIMTfuDatReq(inst,datReq)
503 TfuDatReqInfo *datReq;
511 /* Get the lower SAP control block from the layer control block. */
512 tfuSap = &(rgCb[inst].tfuSap);
515 if (tfuSap->sapSta.sapState != LRG_BND)
517 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
518 tfuSap->sapSta.sapState);
520 /* This case will never be hit if sap is not bound then we dont get TTI */
521 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
527 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
529 /* Using existing pst - for optimization */
530 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
533 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
536 } /* rgLIMTfuDatReq*/
540 * @brief This API is invoked to send Data to PHY.
544 * Function : rgLIMTfuDelDatReq
546 * This API is invoked to send Data to PHY. It
547 * fills in the Pst structure, spId value and invokes Data
548 * request primitive at TFU.
550 * @param[in] Inst inst
551 * @param[in] TfuDelDatReqInfo *datReq
557 PUBLIC S16 rgLIMTfuDelDatReq
560 TfuDelDatReqInfo *delDatReq
563 PUBLIC S16 rgLIMTfuDatReq(inst,delDatReq)
565 TfuDelDatReqInfo *delDatReq;
571 TRC2(rgLIMTfuDelDatReq)
573 /* Get the lower SAP control block from the layer control block. */
574 tfuSap = &(rgCb[inst].tfuSap);
577 if (tfuSap->sapSta.sapState != LRG_BND)
579 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
580 tfuSap->sapSta.sapState);
585 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
588 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
591 } /* rgLIMTfuDatReq*/
594 /*******************************************************************
596 * @brief Fills post structure
600 * Function : fillMacToSchPst
603 * Fills post structure to be used when sending msg from
606 * @params[in] Post structure pointer
607 * @return ROK - success
610 * ****************************************************************/
611 void fillMacToSchPst(Pst *pst)
621 pst->selector = MAC_SELECTOR_TC;
624 /*******************************************************************
626 * @brief MAC handler for config response from PHY
630 * Function : fapiMacConfigRsp
633 * Processes config response from PHY and sends cell config
639 * ****************************************************************/
640 void fapiMacConfigRsp()
642 /* TODO : Processing of config response from PHY */
644 /* Send cell config cfm to DU APP */
645 MacSendCellCfgCfm(RSP_OK);
648 /*******************************************************************
650 * @brief Send stop indication to DU APP
654 * Function : sendStopIndMacToDuApp
657 * Send stop indication to DU APP
659 * @params[in] Pst info
660 * @return ROK - success
663 * ****************************************************************/
664 uint8_t sendStopIndMacToDuApp()
669 MacCellStopInfo *cellStopId;
671 /* Allocate sharable memory */
672 MAC_ALLOC_SHRABL_BUF(cellStopId, sizeof(MacCellStopInfo));
675 DU_LOG("\nMAC : Stop Indication memory allocation failed");
678 cellStopId->cellId = macCb.macCell->cellId;
681 pst.selector = DU_MAC_LWLC;
683 pst.dstEnt = ENTDUAPP;
685 pst.srcInst = macCb.macInst;
686 pst.dstProcId = rgCb[pst.srcInst].rgInit.procId;
687 pst.srcProcId = rgCb[pst.srcInst].rgInit.procId;
688 pst.region = MAC_MEM_REGION;
690 pst.event = EVENT_MAC_STOP_IND;
695 ret = MacDuAppStopInd(&pst, cellStopId);
698 DU_LOG("\nMAC: Failed to send stop indication to DU APP");
699 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, cellStopId, sizeof(MacCellStopInfo));
703 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
705 * @brief Transmission of non-rt indication from CL.
709 * Function : RgLiTfuNonRtInd
711 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
713 * @param[in] Pst *pst
714 * @param[in] SuId suId
720 PUBLIC S16 RgLiTfuNonRtInd
726 PUBLIC S16 RgLiTfuNonRtInd(pst, suId)
731 TRC3(RgLiTfuNonRtInd);
734 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
736 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
740 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
742 } /* RgLiTfuNonRtInd */
745 /**********************************************************************
748 **********************************************************************/