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 "envopt.h" /* environment options */
40 #include "envdep.h" /* environment dependent */
41 #include "envind.h" /* environment independent */
42 #include "gen.h" /* general layer */
43 #include "ssi.h" /* system services */
44 #include "cm5.h" /* common timers defines */
45 #include "cm_hash.h" /* common hash list defines */
46 #include "cm_llist.h" /* common linked list defines */
47 #include "cm_mblk.h" /* memory management */
48 #include "cm_tkns.h" /* common tokens */
49 #include "cm_lte.h" /* common tokens */
50 #include "rgu.h" /* RGU defines */
51 #include "tfu.h" /* RGU defines */
52 #include "lrg.h" /* layer management defines for LTE-MAC */
53 #include "crg.h" /* layer management defines for LTE-MAC */
54 #include "rg_sch_inf.h" /* layer management defines for LTE-MAC */
55 #include "rg_env.h" /* customisable defines and macros for MAC */
56 #include "rg.h" /* defines and macros for MAC */
59 /* header/extern include files (.x) */
60 #include "gen.x" /* general layer typedefs */
61 #include "ssi.x" /* system services typedefs */
62 #include "cm5.x" /* common timers */
63 #include "cm_hash.x" /* common hash list */
64 #include "cm_lib.x" /* common library */
65 #include "cm_llist.x" /* common linked list */
66 #include "cm_mblk.x" /* memory management */
67 #include "cm_tkns.x" /* common tokens */
68 #include "cm_lte.x" /* common tokens */
69 #include "rgu.x" /* RGU types */
70 #include "tfu.x" /* RGU types */
71 #include "lrg.x" /* layer management typedefs for MAC */
72 #include "crg.x" /* layer management typedefs for MAC */
73 #include "rg_sch_inf.x" /* SCH interface typedefs */
74 #include "rg_prg.x" /* PRG interface typedefs */
75 #include "du_app_mac_inf.h"
76 #include "rg.x" /* typedefs for MAC */
78 #include "mac_upr_inf_api.h"
83 PRIVATE S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
85 PRIVATE Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
88 PRIVATE Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
91 /* forward references */
94 * @brief This API is invoked to send TFU SAP bind request to PHY.
98 * Function : rgLIMTfuBndReq
100 * This API is invoked to send TFU SAP bind request to PHY. It fills in
101 * the Pst structure, spId and suId values and invokes bind request
104 * @param[in] Inst inst
105 * @param[in] SuId suId
106 * @param[in] SpId spId
112 PUBLIC S16 rgLIMTfuBndReq
119 PUBLIC S16 rgLIMTfuBndReq(inst,suId, spId)
129 TRC2(rgLIMTfuBndReq);
131 /* Get the lower SAP control block from the layer control block. */
132 tfuSap = &(rgCb[inst].tfuSap);
133 (Void)cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
134 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
136 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
139 } /* rgLIMTfuBndReq */
143 * @brief This API is invoked to send TFU SAP unbind request to PHY.
147 * Function : rgLIMTfuBndReq
149 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
150 * the Pst structure and spId value and invokes unbind request
153 * @param[in] Inst inst
154 * @param[in] SpId spId
155 * @param[in] Reason reason
161 PUBLIC S16 rgLIMTfuUbndReq
168 PUBLIC S16 rgLIMTfuUbndReq(inst,spId, reason)
178 TRC2(rgLIMTfuUbndReq);
180 /* Get the lower SAP control block from the layer control block. */
181 tfuSap = &(rgCb[inst].tfuSap);
182 cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
183 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
185 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
189 } /* rgLIMTfuUbndReq */
193 * @brief Bind confirm API for TFU SAP
197 * Function : RgLiTfuBndCfm
199 * This API is invoked by PHY to confirm TFU SAP bind.
202 * @param[in] Pst *pst
203 * @param[in] SuId suId
204 * @param[in] U8 status
210 PUBLIC S16 RgLiTfuBndCfm
217 PUBLIC S16 RgLiTfuBndCfm(pst, suId, status)
230 RG_IS_INST_VALID(pst->dstInst);
231 inst = pst->dstInst - RG_INST_START;
232 /* Lets validate suId first */
234 tfuSap = &(rgCb[inst].tfuSap);
236 if (suId != tfuSap->sapCfg.suId)
238 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
239 tfuSap->sapCfg.suId, suId);
242 ret = rgLMMBndCfm (pst, suId, status);
244 } /* RgLiTfuBndCfm */
246 /** @brief This function Validates the SAP information received along with the
247 * primitive from the lower layer.
249 * Validates SAP information.
250 * @param[in] Inst inst
251 * @param suId The SAP Id
258 PRIVATE S16 rgLIMValidateSap
264 PRIVATE S16 rgLIMValidateSap(inst,suId)
271 TRC2(rgLIMValidateSap)
273 tfuSap = &(rgCb[inst].tfuSap);
275 /* First lets check the suId */
276 if( suId != tfuSap->sapCfg.suId)
278 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
279 tfuSap->sapCfg.suId, suId);
282 if (tfuSap->sapSta.sapState != LRG_BND)
284 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
285 tfuSap->sapCfg.suId);
289 } /* end of rgLIMValidateSap */
291 /** @brief This function frees up the TfuDatIndInfo structure
295 * Function: rgLIMUtlFreeDatIndEvnt
296 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
297 * free up the buffer's present in the datIndLst.
300 * @param [in] TfuDatIndInfo *datInd
301 * @param [in] Bool *error
305 PRIVATE Void rgLIMUtlFreeDatIndEvnt
307 TfuDatIndInfo *datInd,
311 PRIVATE Void rgLIMUtlFreeDatIndEvnt(datInd, error)
312 TfuDatIndInfo *datInd;
320 TRC2(rgLIMUtlFreeDatIndEvnt);
321 /* Steps of freeing up the TfuDatInd.
322 * 1. loop through the datIndLst and free up all the buffers.
323 * 2. free up the whole event
325 if ((error == TRUE) && (datInd->datIndLst.count > 0))
327 node = datInd->datIndLst.first;
330 datInfo = (TfuDatInfo*)node->node;
331 RG_FREE_MSG(datInfo->mBuf);
337 } /* end of rgLIMUtlFreeDatIndEvnt*/
340 * @brief Downlink data indication from PHY.
344 * Function : RgLiTfuDatInd
346 * This API is invoked by PHY to send data indication to MAC on
347 * recieving data from UEs.
349 * @param[in] Pst *pst
350 * @param[in] SuId suId
351 * @param[in] TfuDatIndInfo *datInd
357 PUBLIC S16 RgLiTfuDatInd
361 TfuDatIndInfo *datInd
364 PUBLIC S16 RgLiTfuDatInd(pst, suId, datInd)
367 TfuDatIndInfo *datInd;
372 VOLATILE U32 startTime=0;
376 // printf("5GTF:: DatindRcvd\n");
378 RG_IS_INST_VALID(pst->dstInst);
379 inst = pst->dstInst - RG_INST_START;
381 SStartTask(&startTime, PID_MAC_TFU_DATIND);
384 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
386 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
387 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
391 /* Now call the TOM (Tfu ownership module) primitive to process further */
392 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
393 datInd->datIndLst.count;
394 ret = rgTOMDatInd(inst,datInd);
395 /* Fix: sriky memory corruption precautions */
396 /* Free up the memory for the request structure */
399 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
403 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
407 SStopTask(startTime, PID_MAC_TFU_DATIND);
413 /** @brief This function frees up the TfuDatReqInfo structure.
417 * Function: rgLIMUtlFreeDatReqEvnt
418 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
419 * free up the buffer's present in the PDUs list.
422 * @param [in] TfuDatReqInfo *datReq
423 * @param [in] Bool *error
427 PRIVATE Void rgLIMUtlFreeDatReqEvnt
429 TfuDatReqInfo *datReq,
433 PRIVATE Void rgLIMUtlFreeDatReqEvnt(datReq, error)
434 TfuDatReqInfo *datReq;
439 TfuDatReqPduInfo *datInfo;
443 TRC2(rgLIMUtlFreeDatReqEvnt);
444 /* Steps of freeing up the TfuDatReq.
445 * 1. Free the bch buffer.
446 * 2. loop through the pdus list and free up all the buffers.
447 * 3. free up the whole event
451 if (datReq->bchDat.pres == PRSNT_NODEF)
453 RG_FREE_MSG(datReq->bchDat.val);
455 if (datReq->pdus.count > 0)
457 node = datReq->pdus.first;
460 datInfo = (TfuDatReqPduInfo*)node->node;
461 for (i=0; i<datInfo->nmbOfTBs; i++)
463 if (datInfo->mBuf[i] != NULLP)
465 RG_FREE_MSG(datInfo->mBuf[i]);
474 } /* end of rgLIMUtlFreeDatReqEvnt*/
477 * @brief This API is invoked to send Data to PHY.
481 * Function : rgLIMTfuDatReq
483 * This API is invoked to send Data to PHY. It
484 * fills in the Pst structure, spId value and invokes Data
485 * request primitive at TFU.
487 * @param[in] Inst inst
488 * @param[in] TfuDatReqInfo *datReq
494 PUBLIC S16 rgLIMTfuDatReq
497 TfuDatReqInfo *datReq
500 PUBLIC S16 rgLIMTfuDatReq(inst,datReq)
502 TfuDatReqInfo *datReq;
510 /* Get the lower SAP control block from the layer control block. */
511 tfuSap = &(rgCb[inst].tfuSap);
514 if (tfuSap->sapSta.sapState != LRG_BND)
516 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
517 tfuSap->sapSta.sapState);
519 /* This case will never be hit if sap is not bound then we dont get TTI */
520 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
526 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
528 /* Using existing pst - for optimization */
529 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
532 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
535 } /* rgLIMTfuDatReq*/
539 * @brief This API is invoked to send Data to PHY.
543 * Function : rgLIMTfuDelDatReq
545 * This API is invoked to send Data to PHY. It
546 * fills in the Pst structure, spId value and invokes Data
547 * request primitive at TFU.
549 * @param[in] Inst inst
550 * @param[in] TfuDelDatReqInfo *datReq
556 PUBLIC S16 rgLIMTfuDelDatReq
559 TfuDelDatReqInfo *delDatReq
562 PUBLIC S16 rgLIMTfuDatReq(inst,delDatReq)
564 TfuDelDatReqInfo *delDatReq;
570 TRC2(rgLIMTfuDelDatReq)
572 /* Get the lower SAP control block from the layer control block. */
573 tfuSap = &(rgCb[inst].tfuSap);
576 if (tfuSap->sapSta.sapState != LRG_BND)
578 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
579 tfuSap->sapSta.sapState);
584 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
587 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
590 } /* rgLIMTfuDatReq*/
593 /*******************************************************************
595 * @brief Fills post structure
599 * Function : fillMacToSchPst
602 * Fills post structure to be used when sending msg from
605 * @params[in] Post structure pointer
606 * @return ROK - success
609 * ****************************************************************/
610 void fillMacToSchPst(Pst *pst)
620 pst->selector = MAC_SELECTOR_TC;
623 /*******************************************************************
625 * @brief MAC handler for config response from PHY
629 * Function : fapiMacConfigRsp
632 * Processes config response from PHY and sends cell config
638 * ****************************************************************/
639 void fapiMacConfigRsp()
641 /* TODO : Processing of config response from PHY */
643 /* Send cell config cfm to DU APP */
644 MacSendCellCfgCfm(RSP_OK);
647 /*******************************************************************
649 * @brief Send stop indication to DU APP
653 * Function : sendStopIndMacToDuApp
656 * Send stop indication to DU APP
658 * @params[in] Pst info
659 * @return ROK - success
662 * ****************************************************************/
663 uint8_t sendStopIndMacToDuApp()
668 MacCellStopInfo *cellStopId;
670 /* Allocate sharable memory */
671 MAC_ALLOC_SHRABL_BUF(cellStopId, sizeof(MacCellStopInfo));
674 DU_LOG("\nMAC : Stop Indication memory allocation failed");
677 cellStopId->cellId = macCb.macCell->cellId;
680 pst.selector = DU_MAC_LWLC;
682 pst.dstEnt = ENTDUAPP;
684 pst.srcInst = macCb.macInst;
685 pst.dstProcId = rgCb[pst.srcInst].rgInit.procId;
686 pst.srcProcId = rgCb[pst.srcInst].rgInit.procId;
687 pst.region = MAC_MEM_REGION;
689 pst.event = EVENT_MAC_STOP_IND;
694 ret = MacDuAppStopInd(&pst, cellStopId);
697 DU_LOG("\nMAC: Failed to send stop indication to DU APP");
698 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, cellStopId, sizeof(MacCellStopInfo));
702 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
704 * @brief Transmission of non-rt indication from CL.
708 * Function : RgLiTfuNonRtInd
710 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
712 * @param[in] Pst *pst
713 * @param[in] SuId suId
719 PUBLIC S16 RgLiTfuNonRtInd
725 PUBLIC S16 RgLiTfuNonRtInd(pst, suId)
730 TRC3(RgLiTfuNonRtInd);
733 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
735 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
739 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
741 } /* RgLiTfuNonRtInd */
744 /**********************************************************************
747 **********************************************************************/