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 PRIVATE S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
61 PRIVATE Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
64 PRIVATE 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)
105 TRC2(rgLIMTfuBndReq);
107 /* Get the lower SAP control block from the layer control block. */
108 tfuSap = &(rgCb[inst].tfuSap);
109 (Void)cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
110 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
112 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
115 } /* rgLIMTfuBndReq */
119 * @brief This API is invoked to send TFU SAP unbind request to PHY.
123 * Function : rgLIMTfuBndReq
125 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
126 * the Pst structure and spId value and invokes unbind request
129 * @param[in] Inst inst
130 * @param[in] SpId spId
131 * @param[in] Reason reason
144 S16 rgLIMTfuUbndReq(inst,spId, reason)
154 TRC2(rgLIMTfuUbndReq);
156 /* Get the lower SAP control block from the layer control block. */
157 tfuSap = &(rgCb[inst].tfuSap);
158 cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
159 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
161 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
165 } /* rgLIMTfuUbndReq */
169 * @brief Bind confirm API for TFU SAP
173 * Function : RgLiTfuBndCfm
175 * This API is invoked by PHY to confirm TFU SAP bind.
178 * @param[in] Pst *pst
179 * @param[in] SuId suId
180 * @param[in] U8 status
193 S16 RgLiTfuBndCfm(pst, suId, status)
206 RG_IS_INST_VALID(pst->dstInst);
207 inst = pst->dstInst - RG_INST_START;
208 /* Lets validate suId first */
210 tfuSap = &(rgCb[inst].tfuSap);
212 if (suId != tfuSap->sapCfg.suId)
214 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
215 tfuSap->sapCfg.suId, suId);
218 ret = rgLMMBndCfm (pst, suId, status);
220 } /* RgLiTfuBndCfm */
222 /** @brief This function Validates the SAP information received along with the
223 * primitive from the lower layer.
225 * Validates SAP information.
226 * @param[in] Inst inst
227 * @param suId The SAP Id
234 PRIVATE S16 rgLIMValidateSap
240 PRIVATE S16 rgLIMValidateSap(inst,suId)
247 TRC2(rgLIMValidateSap)
249 tfuSap = &(rgCb[inst].tfuSap);
251 /* First lets check the suId */
252 if( suId != tfuSap->sapCfg.suId)
254 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
255 tfuSap->sapCfg.suId, suId);
258 if (tfuSap->sapSta.sapState != LRG_BND)
260 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
261 tfuSap->sapCfg.suId);
265 } /* end of rgLIMValidateSap */
267 /** @brief This function frees up the TfuDatIndInfo structure
271 * Function: rgLIMUtlFreeDatIndEvnt
272 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
273 * free up the buffer's present in the datIndLst.
276 * @param [in] TfuDatIndInfo *datInd
277 * @param [in] Bool *error
281 PRIVATE Void rgLIMUtlFreeDatIndEvnt
283 TfuDatIndInfo *datInd,
287 PRIVATE Void rgLIMUtlFreeDatIndEvnt(datInd, error)
288 TfuDatIndInfo *datInd;
296 TRC2(rgLIMUtlFreeDatIndEvnt);
297 /* Steps of freeing up the TfuDatInd.
298 * 1. loop through the datIndLst and free up all the buffers.
299 * 2. free up the whole event
301 if ((error == TRUE) && (datInd->datIndLst.count > 0))
303 node = datInd->datIndLst.first;
306 datInfo = (TfuDatInfo*)node->node;
307 RG_FREE_MSG(datInfo->mBuf);
313 } /* end of rgLIMUtlFreeDatIndEvnt*/
316 * @brief Downlink data indication from PHY.
320 * Function : RgLiTfuDatInd
322 * This API is invoked by PHY to send data indication to MAC on
323 * recieving data from UEs.
325 * @param[in] Pst *pst
326 * @param[in] SuId suId
327 * @param[in] TfuDatIndInfo *datInd
337 TfuDatIndInfo *datInd
340 S16 RgLiTfuDatInd(pst, suId, datInd)
343 TfuDatIndInfo *datInd;
348 VOLATILE U32 startTime=0;
352 // printf("5GTF:: DatindRcvd\n");
354 RG_IS_INST_VALID(pst->dstInst);
355 inst = pst->dstInst - RG_INST_START;
357 SStartTask(&startTime, PID_MAC_TFU_DATIND);
360 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
362 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
363 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
367 /* Now call the TOM (Tfu ownership module) primitive to process further */
368 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
369 datInd->datIndLst.count;
370 ret = rgTOMDatInd(inst,datInd);
371 /* Fix: sriky memory corruption precautions */
372 /* Free up the memory for the request structure */
375 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
379 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
383 SStopTask(startTime, PID_MAC_TFU_DATIND);
389 /** @brief This function frees up the TfuDatReqInfo structure.
393 * Function: rgLIMUtlFreeDatReqEvnt
394 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
395 * free up the buffer's present in the PDUs list.
398 * @param [in] TfuDatReqInfo *datReq
399 * @param [in] Bool *error
403 PRIVATE Void rgLIMUtlFreeDatReqEvnt
405 TfuDatReqInfo *datReq,
409 PRIVATE Void rgLIMUtlFreeDatReqEvnt(datReq, error)
410 TfuDatReqInfo *datReq;
415 TfuDatReqPduInfo *datInfo;
419 TRC2(rgLIMUtlFreeDatReqEvnt);
420 /* Steps of freeing up the TfuDatReq.
421 * 1. Free the bch buffer.
422 * 2. loop through the pdus list and free up all the buffers.
423 * 3. free up the whole event
427 if (datReq->bchDat.pres == PRSNT_NODEF)
429 RG_FREE_MSG(datReq->bchDat.val);
431 if (datReq->pdus.count > 0)
433 node = datReq->pdus.first;
436 datInfo = (TfuDatReqPduInfo*)node->node;
437 for (i=0; i<datInfo->nmbOfTBs; i++)
439 if (datInfo->mBuf[i] != NULLP)
441 RG_FREE_MSG(datInfo->mBuf[i]);
450 } /* end of rgLIMUtlFreeDatReqEvnt*/
453 * @brief This API is invoked to send Data to PHY.
457 * Function : rgLIMTfuDatReq
459 * This API is invoked to send Data to PHY. It
460 * fills in the Pst structure, spId value and invokes Data
461 * request primitive at TFU.
463 * @param[in] Inst inst
464 * @param[in] TfuDatReqInfo *datReq
473 TfuDatReqInfo *datReq
476 S16 rgLIMTfuDatReq(inst,datReq)
478 TfuDatReqInfo *datReq;
486 /* Get the lower SAP control block from the layer control block. */
487 tfuSap = &(rgCb[inst].tfuSap);
490 if (tfuSap->sapSta.sapState != LRG_BND)
492 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
493 tfuSap->sapSta.sapState);
495 /* This case will never be hit if sap is not bound then we dont get TTI */
496 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
502 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
504 /* Using existing pst - for optimization */
505 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
508 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
511 } /* rgLIMTfuDatReq*/
515 * @brief This API is invoked to send Data to PHY.
519 * Function : rgLIMTfuDelDatReq
521 * This API is invoked to send Data to PHY. It
522 * fills in the Pst structure, spId value and invokes Data
523 * request primitive at TFU.
525 * @param[in] Inst inst
526 * @param[in] TfuDelDatReqInfo *datReq
532 S16 rgLIMTfuDelDatReq
535 TfuDelDatReqInfo *delDatReq
538 S16 rgLIMTfuDatReq(inst,delDatReq)
540 TfuDelDatReqInfo *delDatReq;
546 TRC2(rgLIMTfuDelDatReq)
548 /* Get the lower SAP control block from the layer control block. */
549 tfuSap = &(rgCb[inst].tfuSap);
552 if (tfuSap->sapSta.sapState != LRG_BND)
554 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
555 tfuSap->sapSta.sapState);
560 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
563 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
566 } /* rgLIMTfuDatReq*/
569 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
571 * @brief Transmission of non-rt indication from CL.
575 * Function : RgLiTfuNonRtInd
577 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
579 * @param[in] Pst *pst
580 * @param[in] SuId suId
592 S16 RgLiTfuNonRtInd(pst, suId)
597 TRC3(RgLiTfuNonRtInd);
600 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
602 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
606 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
608 } /* RgLiTfuNonRtInd */
611 /**********************************************************************
614 **********************************************************************/