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 */
49 /* header/extern include files (.x) */
50 #include "rgu.x" /* RGU types */
51 #include "tfu.x" /* RGU types */
52 #include "lrg.x" /* layer management typedefs for MAC */
53 #include "crg.x" /* layer management typedefs for MAC */
54 #include "rg_sch_inf.x" /* SCH interface typedefs */
55 #include "rg_prg.x" /* PRG interface typedefs */
56 #include "du_app_mac_inf.h"
57 #include "rg.x" /* typedefs for MAC */
59 #include "mac_upr_inf_api.h"
64 PRIVATE S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
66 PRIVATE Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
69 PRIVATE Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
72 /* forward references */
75 * @brief This API is invoked to send TFU SAP bind request to PHY.
79 * Function : rgLIMTfuBndReq
81 * This API is invoked to send TFU SAP bind request to PHY. It fills in
82 * the Pst structure, spId and suId values and invokes bind request
85 * @param[in] Inst inst
86 * @param[in] SuId suId
87 * @param[in] SpId spId
93 PUBLIC S16 rgLIMTfuBndReq
100 PUBLIC S16 rgLIMTfuBndReq(inst,suId, spId)
110 TRC2(rgLIMTfuBndReq);
112 /* Get the lower SAP control block from the layer control block. */
113 tfuSap = &(rgCb[inst].tfuSap);
114 (Void)cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
115 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
117 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
120 } /* rgLIMTfuBndReq */
124 * @brief This API is invoked to send TFU SAP unbind request to PHY.
128 * Function : rgLIMTfuBndReq
130 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
131 * the Pst structure and spId value and invokes unbind request
134 * @param[in] Inst inst
135 * @param[in] SpId spId
136 * @param[in] Reason reason
142 PUBLIC S16 rgLIMTfuUbndReq
149 PUBLIC S16 rgLIMTfuUbndReq(inst,spId, reason)
159 TRC2(rgLIMTfuUbndReq);
161 /* Get the lower SAP control block from the layer control block. */
162 tfuSap = &(rgCb[inst].tfuSap);
163 cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
164 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
166 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
170 } /* rgLIMTfuUbndReq */
174 * @brief Bind confirm API for TFU SAP
178 * Function : RgLiTfuBndCfm
180 * This API is invoked by PHY to confirm TFU SAP bind.
183 * @param[in] Pst *pst
184 * @param[in] SuId suId
185 * @param[in] U8 status
191 PUBLIC S16 RgLiTfuBndCfm
198 PUBLIC S16 RgLiTfuBndCfm(pst, suId, status)
211 RG_IS_INST_VALID(pst->dstInst);
212 inst = pst->dstInst - RG_INST_START;
213 /* Lets validate suId first */
215 tfuSap = &(rgCb[inst].tfuSap);
217 if (suId != tfuSap->sapCfg.suId)
219 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
220 tfuSap->sapCfg.suId, suId);
223 ret = rgLMMBndCfm (pst, suId, status);
225 } /* RgLiTfuBndCfm */
227 /** @brief This function Validates the SAP information received along with the
228 * primitive from the lower layer.
230 * Validates SAP information.
231 * @param[in] Inst inst
232 * @param suId The SAP Id
239 PRIVATE S16 rgLIMValidateSap
245 PRIVATE S16 rgLIMValidateSap(inst,suId)
252 TRC2(rgLIMValidateSap)
254 tfuSap = &(rgCb[inst].tfuSap);
256 /* First lets check the suId */
257 if( suId != tfuSap->sapCfg.suId)
259 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
260 tfuSap->sapCfg.suId, suId);
263 if (tfuSap->sapSta.sapState != LRG_BND)
265 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
266 tfuSap->sapCfg.suId);
270 } /* end of rgLIMValidateSap */
272 /** @brief This function frees up the TfuDatIndInfo structure
276 * Function: rgLIMUtlFreeDatIndEvnt
277 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
278 * free up the buffer's present in the datIndLst.
281 * @param [in] TfuDatIndInfo *datInd
282 * @param [in] Bool *error
286 PRIVATE Void rgLIMUtlFreeDatIndEvnt
288 TfuDatIndInfo *datInd,
292 PRIVATE Void rgLIMUtlFreeDatIndEvnt(datInd, error)
293 TfuDatIndInfo *datInd;
301 TRC2(rgLIMUtlFreeDatIndEvnt);
302 /* Steps of freeing up the TfuDatInd.
303 * 1. loop through the datIndLst and free up all the buffers.
304 * 2. free up the whole event
306 if ((error == TRUE) && (datInd->datIndLst.count > 0))
308 node = datInd->datIndLst.first;
311 datInfo = (TfuDatInfo*)node->node;
312 RG_FREE_MSG(datInfo->mBuf);
318 } /* end of rgLIMUtlFreeDatIndEvnt*/
321 * @brief Downlink data indication from PHY.
325 * Function : RgLiTfuDatInd
327 * This API is invoked by PHY to send data indication to MAC on
328 * recieving data from UEs.
330 * @param[in] Pst *pst
331 * @param[in] SuId suId
332 * @param[in] TfuDatIndInfo *datInd
338 PUBLIC S16 RgLiTfuDatInd
342 TfuDatIndInfo *datInd
345 PUBLIC S16 RgLiTfuDatInd(pst, suId, datInd)
348 TfuDatIndInfo *datInd;
353 VOLATILE U32 startTime=0;
357 // printf("5GTF:: DatindRcvd\n");
359 RG_IS_INST_VALID(pst->dstInst);
360 inst = pst->dstInst - RG_INST_START;
362 SStartTask(&startTime, PID_MAC_TFU_DATIND);
365 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
367 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
368 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
372 /* Now call the TOM (Tfu ownership module) primitive to process further */
373 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
374 datInd->datIndLst.count;
375 ret = rgTOMDatInd(inst,datInd);
376 /* Fix: sriky memory corruption precautions */
377 /* Free up the memory for the request structure */
380 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
384 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
388 SStopTask(startTime, PID_MAC_TFU_DATIND);
394 /** @brief This function frees up the TfuDatReqInfo structure.
398 * Function: rgLIMUtlFreeDatReqEvnt
399 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
400 * free up the buffer's present in the PDUs list.
403 * @param [in] TfuDatReqInfo *datReq
404 * @param [in] Bool *error
408 PRIVATE Void rgLIMUtlFreeDatReqEvnt
410 TfuDatReqInfo *datReq,
414 PRIVATE Void rgLIMUtlFreeDatReqEvnt(datReq, error)
415 TfuDatReqInfo *datReq;
420 TfuDatReqPduInfo *datInfo;
424 TRC2(rgLIMUtlFreeDatReqEvnt);
425 /* Steps of freeing up the TfuDatReq.
426 * 1. Free the bch buffer.
427 * 2. loop through the pdus list and free up all the buffers.
428 * 3. free up the whole event
432 if (datReq->bchDat.pres == PRSNT_NODEF)
434 RG_FREE_MSG(datReq->bchDat.val);
436 if (datReq->pdus.count > 0)
438 node = datReq->pdus.first;
441 datInfo = (TfuDatReqPduInfo*)node->node;
442 for (i=0; i<datInfo->nmbOfTBs; i++)
444 if (datInfo->mBuf[i] != NULLP)
446 RG_FREE_MSG(datInfo->mBuf[i]);
455 } /* end of rgLIMUtlFreeDatReqEvnt*/
458 * @brief This API is invoked to send Data to PHY.
462 * Function : rgLIMTfuDatReq
464 * This API is invoked to send Data to PHY. It
465 * fills in the Pst structure, spId value and invokes Data
466 * request primitive at TFU.
468 * @param[in] Inst inst
469 * @param[in] TfuDatReqInfo *datReq
475 PUBLIC S16 rgLIMTfuDatReq
478 TfuDatReqInfo *datReq
481 PUBLIC S16 rgLIMTfuDatReq(inst,datReq)
483 TfuDatReqInfo *datReq;
491 /* Get the lower SAP control block from the layer control block. */
492 tfuSap = &(rgCb[inst].tfuSap);
495 if (tfuSap->sapSta.sapState != LRG_BND)
497 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
498 tfuSap->sapSta.sapState);
500 /* This case will never be hit if sap is not bound then we dont get TTI */
501 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
507 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
509 /* Using existing pst - for optimization */
510 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
513 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
516 } /* rgLIMTfuDatReq*/
520 * @brief This API is invoked to send Data to PHY.
524 * Function : rgLIMTfuDelDatReq
526 * This API is invoked to send Data to PHY. It
527 * fills in the Pst structure, spId value and invokes Data
528 * request primitive at TFU.
530 * @param[in] Inst inst
531 * @param[in] TfuDelDatReqInfo *datReq
537 PUBLIC S16 rgLIMTfuDelDatReq
540 TfuDelDatReqInfo *delDatReq
543 PUBLIC S16 rgLIMTfuDatReq(inst,delDatReq)
545 TfuDelDatReqInfo *delDatReq;
551 TRC2(rgLIMTfuDelDatReq)
553 /* Get the lower SAP control block from the layer control block. */
554 tfuSap = &(rgCb[inst].tfuSap);
557 if (tfuSap->sapSta.sapState != LRG_BND)
559 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
560 tfuSap->sapSta.sapState);
565 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
568 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
571 } /* rgLIMTfuDatReq*/
574 /*******************************************************************
576 * @brief Fills post structure
580 * Function : fillMacToSchPst
583 * Fills post structure to be used when sending msg from
586 * @params[in] Post structure pointer
587 * @return ROK - success
590 * ****************************************************************/
591 void fillMacToSchPst(Pst *pst)
601 pst->selector = ODU_SELECTOR_TC;
604 /*******************************************************************
606 * @brief MAC handler for config response from PHY
610 * Function : fapiMacConfigRsp
613 * Processes config response from PHY and sends cell config
619 * ****************************************************************/
620 void fapiMacConfigRsp()
622 /* TODO : Processing of config response from PHY */
624 /* Send cell config cfm to DU APP */
625 MacSendCellCfgCfm(RSP_OK);
628 /*******************************************************************
630 * @brief Send stop indication to DU APP
634 * Function : sendStopIndMacToDuApp
637 * Send stop indication to DU APP
639 * @params[in] Pst info
640 * @return ROK - success
643 * ****************************************************************/
644 uint8_t sendStopIndMacToDuApp()
649 MacCellStopInfo *cellStopId;
651 /* Allocate sharable memory */
652 MAC_ALLOC_SHRABL_BUF(cellStopId, sizeof(MacCellStopInfo));
655 DU_LOG("\nMAC : Stop Indication memory allocation failed");
658 cellStopId->cellId = macCb.macCell->cellId;
661 pst.selector = ODU_SELECTOR_LWLC;
663 pst.dstEnt = ENTDUAPP;
665 pst.srcInst = macCb.macInst;
666 pst.dstProcId = rgCb[pst.srcInst].rgInit.procId;
667 pst.srcProcId = rgCb[pst.srcInst].rgInit.procId;
668 pst.region = MAC_MEM_REGION;
670 pst.event = EVENT_MAC_STOP_IND;
675 ret = MacDuAppStopInd(&pst, cellStopId);
678 DU_LOG("\nMAC: Failed to send stop indication to DU APP");
679 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, cellStopId, sizeof(MacCellStopInfo));
683 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
685 * @brief Transmission of non-rt indication from CL.
689 * Function : RgLiTfuNonRtInd
691 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
693 * @param[in] Pst *pst
694 * @param[in] SuId suId
700 PUBLIC S16 RgLiTfuNonRtInd
706 PUBLIC S16 RgLiTfuNonRtInd(pst, suId)
711 TRC3(RgLiTfuNonRtInd);
714 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
716 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
720 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
722 } /* RgLiTfuNonRtInd */
725 /**********************************************************************
728 **********************************************************************/