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 "common_def.h"
40 #include "rgu.h" /* RGU defines */
41 #include "tfu.h" /* RGU defines */
42 #include "lrg.h" /* layer management defines for LTE-MAC */
43 #include "crg.h" /* layer management defines for LTE-MAC */
44 #include "rg_sch_inf.h" /* layer management defines for LTE-MAC */
45 #include "rg_env.h" /* customisable defines and macros for MAC */
46 #include "rg.h" /* defines and macros for MAC */
48 /* header/extern include files (.x) */
49 #include "rgu.x" /* RGU types */
50 #include "tfu.x" /* RGU types */
51 #include "lrg.x" /* layer management typedefs for MAC */
52 #include "crg.x" /* layer management typedefs for MAC */
53 #include "rg_sch_inf.x" /* SCH interface typedefs */
54 #include "rg_prg.x" /* PRG interface typedefs */
55 #include "rg.x" /* typedefs for MAC */
59 static S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
61 static Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
64 static Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
67 /* forward references */
70 * @brief Bind confirm API for TFU SAP
74 * Function : RgLiTfuBndCfm
76 * This API is invoked by PHY to confirm TFU SAP bind.
80 * @param[in] SuId suId
81 * @param[in] uint8_t status
99 RG_IS_INST_VALID(pst->dstInst);
100 inst = pst->dstInst - RG_INST_START;
101 /* Lets validate suId first */
103 tfuSap = &(rgCb[inst].tfuSap);
105 if (suId != tfuSap->sapCfg.suId)
107 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
108 tfuSap->sapCfg.suId, suId);
111 ret = rgLMMBndCfm (pst, suId, status);
113 } /* RgLiTfuBndCfm */
115 /** @brief This function Validates the SAP information received along with the
116 * primitive from the lower layer.
118 * Validates SAP information.
119 * @param[in] Inst inst
120 * @param suId The SAP Id
126 static S16 rgLIMValidateSap(Inst inst,SuId suId)
131 tfuSap = &(rgCb[inst].tfuSap);
133 /* First lets check the suId */
134 if( suId != tfuSap->sapCfg.suId)
136 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
137 tfuSap->sapCfg.suId, suId);
140 if (tfuSap->sapSta.sapState != LRG_BND)
142 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
143 tfuSap->sapCfg.suId);
147 } /* end of rgLIMValidateSap */
149 /** @brief This function frees up the TfuDatIndInfo structure
153 * Function: rgLIMUtlFreeDatIndEvnt
154 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
155 * free up the buffer's present in the datIndLst.
158 * @param [in] TfuDatIndInfo *datInd
159 * @param [in] Bool *error
162 static Void rgLIMUtlFreeDatIndEvnt(TfuDatIndInfo *datInd,Bool error)
168 /* Steps of freeing up the TfuDatInd.
169 * 1. loop through the datIndLst and free up all the buffers.
170 * 2. free up the whole event
172 if ((error == TRUE) && (datInd->datIndLst.count > 0))
174 node = datInd->datIndLst.first;
177 datInfo = (TfuDatInfo*)node->node;
178 RG_FREE_MSG(datInfo->mBuf);
184 } /* end of rgLIMUtlFreeDatIndEvnt*/
187 * @brief Downlink data indication from PHY.
191 * Function : RgLiTfuDatInd
193 * This API is invoked by PHY to send data indication to MAC on
194 * recieving data from UEs.
196 * @param[in] Pst *pst
197 * @param[in] SuId suId
198 * @param[in] TfuDatIndInfo *datInd
207 TfuDatIndInfo *datInd
212 volatile uint32_t startTime=0;
215 // printf("5GTF:: DatindRcvd\n");
217 RG_IS_INST_VALID(pst->dstInst);
218 inst = pst->dstInst - RG_INST_START;
220 SStartTask(&startTime, PID_MAC_TFU_DATIND);
223 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
225 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
226 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
230 /* Now call the TOM (Tfu ownership module) primitive to process further */
231 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
232 datInd->datIndLst.count;
233 ret = rgTOMDatInd(inst,datInd);
234 /* Fix: sriky memory corruption precautions */
235 /* Free up the memory for the request structure */
238 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
242 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
246 SStopTask(startTime, PID_MAC_TFU_DATIND);
252 /** @brief This function frees up the TfuDatReqInfo structure.
256 * Function: rgLIMUtlFreeDatReqEvnt
257 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
258 * free up the buffer's present in the PDUs list.
261 * @param [in] TfuDatReqInfo *datReq
262 * @param [in] Bool *error
265 static Void rgLIMUtlFreeDatReqEvnt(TfuDatReqInfo *datReq,Bool error)
268 TfuDatReqPduInfo *datInfo;
272 /* Steps of freeing up the TfuDatReq.
273 * 1. Free the bch buffer.
274 * 2. loop through the pdus list and free up all the buffers.
275 * 3. free up the whole event
279 if (datReq->bchDat.pres == PRSNT_NODEF)
281 RG_FREE_MSG(datReq->bchDat.val);
283 if (datReq->pdus.count > 0)
285 node = datReq->pdus.first;
288 datInfo = (TfuDatReqPduInfo*)node->node;
289 for (i=0; i<datInfo->nmbOfTBs; i++)
291 if (datInfo->mBuf[i] != NULLP)
293 RG_FREE_MSG(datInfo->mBuf[i]);
302 } /* end of rgLIMUtlFreeDatReqEvnt*/
307 * @brief This API is invoked to send Data to PHY.
311 * Function : rgLIMTfuDelDatReq
313 * This API is invoked to send Data to PHY. It
314 * fills in the Pst structure, spId value and invokes Data
315 * request primitive at TFU.
317 * @param[in] Inst inst
318 * @param[in] TfuDelDatReqInfo *datReq
323 S16 rgLIMTfuDelDatReq(Inst inst,TfuDelDatReqInfo *delDatReq)
329 /* Get the lower SAP control block from the layer control block. */
330 tfuSap = &(rgCb[inst].tfuSap);
333 if (tfuSap->sapSta.sapState != LRG_BND)
335 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
336 tfuSap->sapSta.sapState);
341 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
344 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
347 } /* rgLIMTfuDatReq*/
350 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
352 * @brief Transmission of non-rt indication from CL.
356 * Function : RgLiTfuNonRtInd
358 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
360 * @param[in] Pst *pst
361 * @param[in] SuId suId
366 S16 RgLiTfuNonRtInd(Pst *pst,SuId suId)
370 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
372 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
376 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
378 } /* RgLiTfuNonRtInd */
381 /**********************************************************************
384 **********************************************************************/