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 This API is invoked to send TFU SAP bind request to PHY.
74 * Function : rgLIMTfuBndReq
76 * This API is invoked to send TFU SAP bind request to PHY. It fills in
77 * the Pst structure, spId and suId values and invokes bind request
80 * @param[in] Inst inst
81 * @param[in] SuId suId
82 * @param[in] SpId spId
95 S16 rgLIMTfuBndReq(inst,suId, spId)
106 /* Get the lower SAP control block from the layer control block. */
107 tfuSap = &(rgCb[inst].tfuSap);
108 memcpy (&pst, &(tfuSap->sapCfg.sapPst), sizeof(Pst));
109 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
111 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
114 } /* rgLIMTfuBndReq */
118 * @brief This API is invoked to send TFU SAP unbind request to PHY.
122 * Function : rgLIMTfuBndReq
124 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
125 * the Pst structure and spId value and invokes unbind request
128 * @param[in] Inst inst
129 * @param[in] SpId spId
130 * @param[in] Reason reason
143 S16 rgLIMTfuUbndReq(inst,spId, reason)
154 /* Get the lower SAP control block from the layer control block. */
155 tfuSap = &(rgCb[inst].tfuSap);
156 memcpy (&pst, &(tfuSap->sapCfg.sapPst), sizeof(Pst));
157 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
159 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
163 } /* rgLIMTfuUbndReq */
167 * @brief Bind confirm API for TFU SAP
171 * Function : RgLiTfuBndCfm
173 * This API is invoked by PHY to confirm TFU SAP bind.
176 * @param[in] Pst *pst
177 * @param[in] SuId suId
178 * @param[in] uint8_t status
191 S16 RgLiTfuBndCfm(pst, suId, status)
203 RG_IS_INST_VALID(pst->dstInst);
204 inst = pst->dstInst - RG_INST_START;
205 /* Lets validate suId first */
207 tfuSap = &(rgCb[inst].tfuSap);
209 if (suId != tfuSap->sapCfg.suId)
211 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
212 tfuSap->sapCfg.suId, suId);
215 ret = rgLMMBndCfm (pst, suId, status);
217 } /* RgLiTfuBndCfm */
219 /** @brief This function Validates the SAP information received along with the
220 * primitive from the lower layer.
222 * Validates SAP information.
223 * @param[in] Inst inst
224 * @param suId The SAP Id
231 static S16 rgLIMValidateSap
237 static S16 rgLIMValidateSap(inst,suId)
245 tfuSap = &(rgCb[inst].tfuSap);
247 /* First lets check the suId */
248 if( suId != tfuSap->sapCfg.suId)
250 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
251 tfuSap->sapCfg.suId, suId);
254 if (tfuSap->sapSta.sapState != LRG_BND)
256 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
257 tfuSap->sapCfg.suId);
261 } /* end of rgLIMValidateSap */
263 /** @brief This function frees up the TfuDatIndInfo structure
267 * Function: rgLIMUtlFreeDatIndEvnt
268 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
269 * free up the buffer's present in the datIndLst.
272 * @param [in] TfuDatIndInfo *datInd
273 * @param [in] Bool *error
277 static Void rgLIMUtlFreeDatIndEvnt
279 TfuDatIndInfo *datInd,
283 static Void rgLIMUtlFreeDatIndEvnt(datInd, error)
284 TfuDatIndInfo *datInd;
292 /* Steps of freeing up the TfuDatInd.
293 * 1. loop through the datIndLst and free up all the buffers.
294 * 2. free up the whole event
296 if ((error == TRUE) && (datInd->datIndLst.count > 0))
298 node = datInd->datIndLst.first;
301 datInfo = (TfuDatInfo*)node->node;
302 RG_FREE_MSG(datInfo->mBuf);
308 } /* end of rgLIMUtlFreeDatIndEvnt*/
311 * @brief Downlink data indication from PHY.
315 * Function : RgLiTfuDatInd
317 * This API is invoked by PHY to send data indication to MAC on
318 * recieving data from UEs.
320 * @param[in] Pst *pst
321 * @param[in] SuId suId
322 * @param[in] TfuDatIndInfo *datInd
332 TfuDatIndInfo *datInd
335 S16 RgLiTfuDatInd(pst, suId, datInd)
338 TfuDatIndInfo *datInd;
343 volatile uint32_t startTime=0;
346 // printf("5GTF:: DatindRcvd\n");
348 RG_IS_INST_VALID(pst->dstInst);
349 inst = pst->dstInst - RG_INST_START;
351 SStartTask(&startTime, PID_MAC_TFU_DATIND);
354 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
356 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
357 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
361 /* Now call the TOM (Tfu ownership module) primitive to process further */
362 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
363 datInd->datIndLst.count;
364 ret = rgTOMDatInd(inst,datInd);
365 /* Fix: sriky memory corruption precautions */
366 /* Free up the memory for the request structure */
369 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
373 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
377 SStopTask(startTime, PID_MAC_TFU_DATIND);
383 /** @brief This function frees up the TfuDatReqInfo structure.
387 * Function: rgLIMUtlFreeDatReqEvnt
388 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
389 * free up the buffer's present in the PDUs list.
392 * @param [in] TfuDatReqInfo *datReq
393 * @param [in] Bool *error
397 static Void rgLIMUtlFreeDatReqEvnt
399 TfuDatReqInfo *datReq,
403 static Void rgLIMUtlFreeDatReqEvnt(datReq, error)
404 TfuDatReqInfo *datReq;
409 TfuDatReqPduInfo *datInfo;
413 /* Steps of freeing up the TfuDatReq.
414 * 1. Free the bch buffer.
415 * 2. loop through the pdus list and free up all the buffers.
416 * 3. free up the whole event
420 if (datReq->bchDat.pres == PRSNT_NODEF)
422 RG_FREE_MSG(datReq->bchDat.val);
424 if (datReq->pdus.count > 0)
426 node = datReq->pdus.first;
429 datInfo = (TfuDatReqPduInfo*)node->node;
430 for (i=0; i<datInfo->nmbOfTBs; i++)
432 if (datInfo->mBuf[i] != NULLP)
434 RG_FREE_MSG(datInfo->mBuf[i]);
443 } /* end of rgLIMUtlFreeDatReqEvnt*/
446 * @brief This API is invoked to send Data to PHY.
450 * Function : rgLIMTfuDatReq
452 * This API is invoked to send Data to PHY. It
453 * fills in the Pst structure, spId value and invokes Data
454 * request primitive at TFU.
456 * @param[in] Inst inst
457 * @param[in] TfuDatReqInfo *datReq
466 TfuDatReqInfo *datReq
469 S16 rgLIMTfuDatReq(inst,datReq)
471 TfuDatReqInfo *datReq;
478 /* Get the lower SAP control block from the layer control block. */
479 tfuSap = &(rgCb[inst].tfuSap);
482 if (tfuSap->sapSta.sapState != LRG_BND)
484 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
485 tfuSap->sapSta.sapState);
487 /* This case will never be hit if sap is not bound then we dont get TTI */
488 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
494 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
496 /* Using existing pst - for optimization */
497 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
500 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
503 } /* rgLIMTfuDatReq*/
507 * @brief This API is invoked to send Data to PHY.
511 * Function : rgLIMTfuDelDatReq
513 * This API is invoked to send Data to PHY. It
514 * fills in the Pst structure, spId value and invokes Data
515 * request primitive at TFU.
517 * @param[in] Inst inst
518 * @param[in] TfuDelDatReqInfo *datReq
524 S16 rgLIMTfuDelDatReq
527 TfuDelDatReqInfo *delDatReq
530 S16 rgLIMTfuDatReq(inst,delDatReq)
532 TfuDelDatReqInfo *delDatReq;
539 /* Get the lower SAP control block from the layer control block. */
540 tfuSap = &(rgCb[inst].tfuSap);
543 if (tfuSap->sapSta.sapState != LRG_BND)
545 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
546 tfuSap->sapSta.sapState);
551 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
554 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
557 } /* rgLIMTfuDatReq*/
560 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
562 * @brief Transmission of non-rt indication from CL.
566 * Function : RgLiTfuNonRtInd
568 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
570 * @param[in] Pst *pst
571 * @param[in] SuId suId
583 S16 RgLiTfuNonRtInd(pst, suId)
590 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
592 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
596 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
598 } /* RgLiTfuNonRtInd */
601 /**********************************************************************
604 **********************************************************************/