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
94 S16 RgLiTfuBndCfm(pst, suId, status)
106 RG_IS_INST_VALID(pst->dstInst);
107 inst = pst->dstInst - RG_INST_START;
108 /* Lets validate suId first */
110 tfuSap = &(rgCb[inst].tfuSap);
112 if (suId != tfuSap->sapCfg.suId)
114 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
115 tfuSap->sapCfg.suId, suId);
118 ret = rgLMMBndCfm (pst, suId, status);
120 } /* RgLiTfuBndCfm */
122 /** @brief This function Validates the SAP information received along with the
123 * primitive from the lower layer.
125 * Validates SAP information.
126 * @param[in] Inst inst
127 * @param suId The SAP Id
134 static S16 rgLIMValidateSap
140 static S16 rgLIMValidateSap(inst,suId)
148 tfuSap = &(rgCb[inst].tfuSap);
150 /* First lets check the suId */
151 if( suId != tfuSap->sapCfg.suId)
153 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
154 tfuSap->sapCfg.suId, suId);
157 if (tfuSap->sapSta.sapState != LRG_BND)
159 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
160 tfuSap->sapCfg.suId);
164 } /* end of rgLIMValidateSap */
166 /** @brief This function frees up the TfuDatIndInfo structure
170 * Function: rgLIMUtlFreeDatIndEvnt
171 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
172 * free up the buffer's present in the datIndLst.
175 * @param [in] TfuDatIndInfo *datInd
176 * @param [in] Bool *error
180 static Void rgLIMUtlFreeDatIndEvnt
182 TfuDatIndInfo *datInd,
186 static Void rgLIMUtlFreeDatIndEvnt(datInd, error)
187 TfuDatIndInfo *datInd;
195 /* Steps of freeing up the TfuDatInd.
196 * 1. loop through the datIndLst and free up all the buffers.
197 * 2. free up the whole event
199 if ((error == TRUE) && (datInd->datIndLst.count > 0))
201 node = datInd->datIndLst.first;
204 datInfo = (TfuDatInfo*)node->node;
205 RG_FREE_MSG(datInfo->mBuf);
211 } /* end of rgLIMUtlFreeDatIndEvnt*/
214 * @brief Downlink data indication from PHY.
218 * Function : RgLiTfuDatInd
220 * This API is invoked by PHY to send data indication to MAC on
221 * recieving data from UEs.
223 * @param[in] Pst *pst
224 * @param[in] SuId suId
225 * @param[in] TfuDatIndInfo *datInd
235 TfuDatIndInfo *datInd
238 S16 RgLiTfuDatInd(pst, suId, datInd)
241 TfuDatIndInfo *datInd;
246 volatile uint32_t startTime=0;
249 // printf("5GTF:: DatindRcvd\n");
251 RG_IS_INST_VALID(pst->dstInst);
252 inst = pst->dstInst - RG_INST_START;
254 SStartTask(&startTime, PID_MAC_TFU_DATIND);
257 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
259 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
260 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
264 /* Now call the TOM (Tfu ownership module) primitive to process further */
265 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
266 datInd->datIndLst.count;
267 ret = rgTOMDatInd(inst,datInd);
268 /* Fix: sriky memory corruption precautions */
269 /* Free up the memory for the request structure */
272 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
276 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
280 SStopTask(startTime, PID_MAC_TFU_DATIND);
286 /** @brief This function frees up the TfuDatReqInfo structure.
290 * Function: rgLIMUtlFreeDatReqEvnt
291 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
292 * free up the buffer's present in the PDUs list.
295 * @param [in] TfuDatReqInfo *datReq
296 * @param [in] Bool *error
300 static Void rgLIMUtlFreeDatReqEvnt
302 TfuDatReqInfo *datReq,
306 static Void rgLIMUtlFreeDatReqEvnt(datReq, error)
307 TfuDatReqInfo *datReq;
312 TfuDatReqPduInfo *datInfo;
316 /* Steps of freeing up the TfuDatReq.
317 * 1. Free the bch buffer.
318 * 2. loop through the pdus list and free up all the buffers.
319 * 3. free up the whole event
323 if (datReq->bchDat.pres == PRSNT_NODEF)
325 RG_FREE_MSG(datReq->bchDat.val);
327 if (datReq->pdus.count > 0)
329 node = datReq->pdus.first;
332 datInfo = (TfuDatReqPduInfo*)node->node;
333 for (i=0; i<datInfo->nmbOfTBs; i++)
335 if (datInfo->mBuf[i] != NULLP)
337 RG_FREE_MSG(datInfo->mBuf[i]);
346 } /* end of rgLIMUtlFreeDatReqEvnt*/
351 * @brief This API is invoked to send Data to PHY.
355 * Function : rgLIMTfuDelDatReq
357 * This API is invoked to send Data to PHY. It
358 * fills in the Pst structure, spId value and invokes Data
359 * request primitive at TFU.
361 * @param[in] Inst inst
362 * @param[in] TfuDelDatReqInfo *datReq
368 S16 rgLIMTfuDelDatReq
371 TfuDelDatReqInfo *delDatReq
374 S16 rgLIMTfuDatReq(inst,delDatReq)
376 TfuDelDatReqInfo *delDatReq;
383 /* Get the lower SAP control block from the layer control block. */
384 tfuSap = &(rgCb[inst].tfuSap);
387 if (tfuSap->sapSta.sapState != LRG_BND)
389 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
390 tfuSap->sapSta.sapState);
395 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
398 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
401 } /* rgLIMTfuDatReq*/
404 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
406 * @brief Transmission of non-rt indication from CL.
410 * Function : RgLiTfuNonRtInd
412 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
414 * @param[in] Pst *pst
415 * @param[in] SuId suId
427 S16 RgLiTfuNonRtInd(pst, suId)
434 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
436 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
440 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
442 } /* RgLiTfuNonRtInd */
445 /**********************************************************************
448 **********************************************************************/