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_sch_interface.h"
79 #include "mac_upr_inf_api.h"
82 PRIVATE S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
83 PRIVATE Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
86 /* function pointers for packing slot ind from mac to sch */
87 //S16 packMacSchSlotInd(Pst *pst, SlotIndInfo *slotInd);
89 MacSchSlotIndFunc macSchSlotIndOpts[] =
97 PRIVATE Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
100 /* forward references */
103 * @brief This API is invoked to send TFU SAP bind request to PHY.
107 * Function : rgLIMTfuBndReq
109 * This API is invoked to send TFU SAP bind request to PHY. It fills in
110 * the Pst structure, spId and suId values and invokes bind request
113 * @param[in] Inst inst
114 * @param[in] SuId suId
115 * @param[in] SpId spId
121 PUBLIC S16 rgLIMTfuBndReq
128 PUBLIC S16 rgLIMTfuBndReq(inst,suId, spId)
138 TRC2(rgLIMTfuBndReq);
140 /* Get the lower SAP control block from the layer control block. */
141 tfuSap = &(rgCb[inst].tfuSap);
142 (Void)cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
143 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
145 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
148 } /* rgLIMTfuBndReq */
152 * @brief This API is invoked to send TFU SAP unbind request to PHY.
156 * Function : rgLIMTfuBndReq
158 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
159 * the Pst structure and spId value and invokes unbind request
162 * @param[in] Inst inst
163 * @param[in] SpId spId
164 * @param[in] Reason reason
170 PUBLIC S16 rgLIMTfuUbndReq
177 PUBLIC S16 rgLIMTfuUbndReq(inst,spId, reason)
187 TRC2(rgLIMTfuUbndReq);
189 /* Get the lower SAP control block from the layer control block. */
190 tfuSap = &(rgCb[inst].tfuSap);
191 cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
192 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
194 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
198 } /* rgLIMTfuUbndReq */
202 * @brief Bind confirm API for TFU SAP
206 * Function : RgLiTfuBndCfm
208 * This API is invoked by PHY to confirm TFU SAP bind.
211 * @param[in] Pst *pst
212 * @param[in] SuId suId
213 * @param[in] U8 status
219 PUBLIC S16 RgLiTfuBndCfm
226 PUBLIC S16 RgLiTfuBndCfm(pst, suId, status)
239 RG_IS_INST_VALID(pst->dstInst);
240 inst = pst->dstInst - RG_INST_START;
241 /* Lets validate suId first */
243 tfuSap = &(rgCb[inst].tfuSap);
245 if (suId != tfuSap->sapCfg.suId)
247 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
248 tfuSap->sapCfg.suId, suId);
251 ret = rgLMMBndCfm (pst, suId, status);
253 } /* RgLiTfuBndCfm */
255 /** @brief This function Validates the SAP information received along with the
256 * primitive from the lower layer.
258 * Validates SAP information.
259 * @param[in] Inst inst
260 * @param suId The SAP Id
266 PRIVATE S16 rgLIMValidateSap
272 PRIVATE S16 rgLIMValidateSap(inst,suId)
279 TRC2(rgLIMValidateSap)
281 tfuSap = &(rgCb[inst].tfuSap);
283 /* First lets check the suId */
284 if( suId != tfuSap->sapCfg.suId)
286 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
287 tfuSap->sapCfg.suId, suId);
290 if (tfuSap->sapSta.sapState != LRG_BND)
292 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
293 tfuSap->sapCfg.suId);
297 } /* end of rgLIMValidateSap */
299 /** @brief This function frees up the TfuDatIndInfo structure
303 * Function: rgLIMUtlFreeDatIndEvnt
304 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
305 * free up the buffer's present in the datIndLst.
308 * @param [in] TfuDatIndInfo *datInd
309 * @param [in] Bool *error
313 PRIVATE Void rgLIMUtlFreeDatIndEvnt
315 TfuDatIndInfo *datInd,
319 PRIVATE Void rgLIMUtlFreeDatIndEvnt(datInd, error)
320 TfuDatIndInfo *datInd;
328 TRC2(rgLIMUtlFreeDatIndEvnt);
329 /* Steps of freeing up the TfuDatInd.
330 * 1. loop through the datIndLst and free up all the buffers.
331 * 2. free up the whole event
333 if ((error == TRUE) && (datInd->datIndLst.count > 0))
335 node = datInd->datIndLst.first;
338 datInfo = (TfuDatInfo*)node->node;
339 RG_FREE_MSG(datInfo->mBuf);
345 } /* end of rgLIMUtlFreeDatIndEvnt*/
348 * @brief Downlink data indication from PHY.
352 * Function : RgLiTfuDatInd
354 * This API is invoked by PHY to send data indication to MAC on
355 * recieving data from UEs.
357 * @param[in] Pst *pst
358 * @param[in] SuId suId
359 * @param[in] TfuDatIndInfo *datInd
365 PUBLIC S16 RgLiTfuDatInd
369 TfuDatIndInfo *datInd
372 PUBLIC S16 RgLiTfuDatInd(pst, suId, datInd)
375 TfuDatIndInfo *datInd;
380 VOLATILE U32 startTime=0;
384 // printf("5GTF:: DatindRcvd\n");
386 RG_IS_INST_VALID(pst->dstInst);
387 inst = pst->dstInst - RG_INST_START;
389 SStartTask(&startTime, PID_MAC_TFU_DATIND);
392 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
394 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
395 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
399 /* Now call the TOM (Tfu ownership module) primitive to process further */
400 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
401 datInd->datIndLst.count;
402 ret = rgTOMDatInd(inst,datInd);
403 /* Fix: sriky memory corruption precautions */
404 /* Free up the memory for the request structure */
407 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
411 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
415 SStopTask(startTime, PID_MAC_TFU_DATIND);
421 /** @brief This function frees up the TfuDatReqInfo structure.
425 * Function: rgLIMUtlFreeDatReqEvnt
426 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
427 * free up the buffer's present in the PDUs list.
430 * @param [in] TfuDatReqInfo *datReq
431 * @param [in] Bool *error
435 PRIVATE Void rgLIMUtlFreeDatReqEvnt
437 TfuDatReqInfo *datReq,
441 PRIVATE Void rgLIMUtlFreeDatReqEvnt(datReq, error)
442 TfuDatReqInfo *datReq;
447 TfuDatReqPduInfo *datInfo;
451 TRC2(rgLIMUtlFreeDatReqEvnt);
452 /* Steps of freeing up the TfuDatReq.
453 * 1. Free the bch buffer.
454 * 2. loop through the pdus list and free up all the buffers.
455 * 3. free up the whole event
459 if (datReq->bchDat.pres == PRSNT_NODEF)
461 RG_FREE_MSG(datReq->bchDat.val);
463 if (datReq->pdus.count > 0)
465 node = datReq->pdus.first;
468 datInfo = (TfuDatReqPduInfo*)node->node;
469 for (i=0; i<datInfo->nmbOfTBs; i++)
471 if (datInfo->mBuf[i] != NULLP)
473 RG_FREE_MSG(datInfo->mBuf[i]);
482 } /* end of rgLIMUtlFreeDatReqEvnt*/
485 * @brief This API is invoked to send Data to PHY.
489 * Function : rgLIMTfuDatReq
491 * This API is invoked to send Data to PHY. It
492 * fills in the Pst structure, spId value and invokes Data
493 * request primitive at TFU.
495 * @param[in] Inst inst
496 * @param[in] TfuDatReqInfo *datReq
502 PUBLIC S16 rgLIMTfuDatReq
505 TfuDatReqInfo *datReq
508 PUBLIC S16 rgLIMTfuDatReq(inst,datReq)
510 TfuDatReqInfo *datReq;
518 /* Get the lower SAP control block from the layer control block. */
519 tfuSap = &(rgCb[inst].tfuSap);
522 if (tfuSap->sapSta.sapState != LRG_BND)
524 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
525 tfuSap->sapSta.sapState);
527 /* This case will never be hit if sap is not bound then we dont get TTI */
528 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
534 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
536 /* Using existing pst - for optimization */
537 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
540 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
543 } /* rgLIMTfuDatReq*/
547 * @brief This API is invoked to send Data to PHY.
551 * Function : rgLIMTfuDelDatReq
553 * This API is invoked to send Data to PHY. It
554 * fills in the Pst structure, spId value and invokes Data
555 * request primitive at TFU.
557 * @param[in] Inst inst
558 * @param[in] TfuDelDatReqInfo *datReq
564 PUBLIC S16 rgLIMTfuDelDatReq
567 TfuDelDatReqInfo *delDatReq
570 PUBLIC S16 rgLIMTfuDatReq(inst,delDatReq)
572 TfuDelDatReqInfo *delDatReq;
578 TRC2(rgLIMTfuDelDatReq)
580 /* Get the lower SAP control block from the layer control block. */
581 tfuSap = &(rgCb[inst].tfuSap);
584 if (tfuSap->sapSta.sapState != LRG_BND)
586 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
587 tfuSap->sapSta.sapState);
592 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
595 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
598 } /* rgLIMTfuDatReq*/
602 * @brief Transmission time interval indication from PHY.
606 * Function : sendSlotIndMacToSch
608 * This API is invoked by MAC to send slot ind to scheduler.
610 * @param[in] SlotIndInfo *slotInd
615 int sendSlotIndMacToSch(SlotIndInfo *slotInd)
618 /* fill Pst structure to send to lwr_mac to MAC */
626 pst.event = EVENT_SLOT_IND_TO_SCH;
629 pst.selector = MAC_SELECTOR_TC;
631 return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
635 /*******************************************************************
637 * @brief Send slot indication to DU APP
641 * Function : sendSlotIndMacToDuApp
644 * Send slot indication to DU APP
646 * @params[in] Slot indication info
647 * @return ROK - success
650 * ****************************************************************/
651 int sendSlotIndMacToDuApp(SlotIndInfo *slotInd)
656 /* Send Slot Indication to DU APP */
657 MAC_ALLOC(slotInfo, sizeof(SlotInfo));
660 DU_LOG("\nMAC : Slot Indication memory allocation failed");
665 pst.selector = DU_MAC_LWLC;
667 pst.dstEnt = ENTDUAPP;
670 pst.dstProcId = rgCb[pst.srcInst].rgInit.procId;
671 pst.srcProcId = rgCb[pst.srcInst].rgInit.procId;
672 pst.region = MAC_MEM_REGION;
674 pst.event = EVENT_MAC_SLOT_IND;
679 return MacDuAppSlotInd(&pst, slotInfo);
684 * @brief Transmission time interval indication from PHY.
688 * Function : fapiMacSlotInd
690 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
692 * @param[in] Pst *pst
693 * @param[in] SuId suId
694 * @param[in] SlotIndInfo *slotInd
699 PUBLIC S16 fapiMacSlotInd
706 VOLATILE U32 startTime=0;
709 DU_LOG("\nMAC : Slot Indication received");
711 RG_IS_INST_VALID(pst->dstInst);
712 inst = pst->dstInst - RG_INST_START;
714 SStartTask(&startTime, PID_MAC_TTI_IND);
716 /* send slot indication to scheduler */
717 ret = sendSlotIndMacToSch(slotInd);
720 DU_LOG("\nMAC : Sending of slot ind msg from MAC to SCH failed");
724 /* Now call the TOM (Tfu ownership module) primitive to process further */
725 ret = macProcessSlotInd(inst,*slotInd);
728 DU_LOG("\nMAC : macProcessSlotInd failed");
732 /* send slot indication to du app */
733 ret = sendSlotIndMacToDuApp(slotInd);
736 DU_LOG("\nMAC :Sending of slot ind msg from MAC to DU APP failed");
741 SStopTask(startTime, PID_MAC_TTI_IND);
744 } /* fapiMacSlotInd */
746 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
748 * @brief Transmission of non-rt indication from CL.
752 * Function : RgLiTfuNonRtInd
754 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
756 * @param[in] Pst *pst
757 * @param[in] SuId suId
763 PUBLIC S16 RgLiTfuNonRtInd
769 PUBLIC S16 RgLiTfuNonRtInd(pst, suId)
774 TRC3(RgLiTfuNonRtInd);
777 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
779 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
783 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
785 } /* RgLiTfuNonRtInd */
788 /**********************************************************************
791 **********************************************************************/