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"
85 PRIVATE S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
87 PRIVATE Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
90 /* function pointers for packing slot ind from mac to sch */
91 //S16 packMacSchSlotInd(Pst *pst, SlotIndInfo *slotInd);
93 MacSchSlotIndFunc macSchSlotIndOpts[] =
101 PRIVATE Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
104 /* forward references */
107 * @brief This API is invoked to send TFU SAP bind request to PHY.
111 * Function : rgLIMTfuBndReq
113 * This API is invoked to send TFU SAP bind request to PHY. It fills in
114 * the Pst structure, spId and suId values and invokes bind request
117 * @param[in] Inst inst
118 * @param[in] SuId suId
119 * @param[in] SpId spId
125 PUBLIC S16 rgLIMTfuBndReq
132 PUBLIC S16 rgLIMTfuBndReq(inst,suId, spId)
142 TRC2(rgLIMTfuBndReq);
144 /* Get the lower SAP control block from the layer control block. */
145 tfuSap = &(rgCb[inst].tfuSap);
146 (Void)cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
147 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
149 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
152 } /* rgLIMTfuBndReq */
156 * @brief This API is invoked to send TFU SAP unbind request to PHY.
160 * Function : rgLIMTfuBndReq
162 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
163 * the Pst structure and spId value and invokes unbind request
166 * @param[in] Inst inst
167 * @param[in] SpId spId
168 * @param[in] Reason reason
174 PUBLIC S16 rgLIMTfuUbndReq
181 PUBLIC S16 rgLIMTfuUbndReq(inst,spId, reason)
191 TRC2(rgLIMTfuUbndReq);
193 /* Get the lower SAP control block from the layer control block. */
194 tfuSap = &(rgCb[inst].tfuSap);
195 cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
196 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
198 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
202 } /* rgLIMTfuUbndReq */
206 * @brief Bind confirm API for TFU SAP
210 * Function : RgLiTfuBndCfm
212 * This API is invoked by PHY to confirm TFU SAP bind.
215 * @param[in] Pst *pst
216 * @param[in] SuId suId
217 * @param[in] U8 status
223 PUBLIC S16 RgLiTfuBndCfm
230 PUBLIC S16 RgLiTfuBndCfm(pst, suId, status)
243 RG_IS_INST_VALID(pst->dstInst);
244 inst = pst->dstInst - RG_INST_START;
245 /* Lets validate suId first */
247 tfuSap = &(rgCb[inst].tfuSap);
249 if (suId != tfuSap->sapCfg.suId)
251 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
252 tfuSap->sapCfg.suId, suId);
255 ret = rgLMMBndCfm (pst, suId, status);
257 } /* RgLiTfuBndCfm */
259 /** @brief This function Validates the SAP information received along with the
260 * primitive from the lower layer.
262 * Validates SAP information.
263 * @param[in] Inst inst
264 * @param suId The SAP Id
271 PRIVATE S16 rgLIMValidateSap
277 PRIVATE S16 rgLIMValidateSap(inst,suId)
284 TRC2(rgLIMValidateSap)
286 tfuSap = &(rgCb[inst].tfuSap);
288 /* First lets check the suId */
289 if( suId != tfuSap->sapCfg.suId)
291 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
292 tfuSap->sapCfg.suId, suId);
295 if (tfuSap->sapSta.sapState != LRG_BND)
297 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
298 tfuSap->sapCfg.suId);
302 } /* end of rgLIMValidateSap */
304 /** @brief This function frees up the TfuDatIndInfo structure
308 * Function: rgLIMUtlFreeDatIndEvnt
309 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
310 * free up the buffer's present in the datIndLst.
313 * @param [in] TfuDatIndInfo *datInd
314 * @param [in] Bool *error
318 PRIVATE Void rgLIMUtlFreeDatIndEvnt
320 TfuDatIndInfo *datInd,
324 PRIVATE Void rgLIMUtlFreeDatIndEvnt(datInd, error)
325 TfuDatIndInfo *datInd;
333 TRC2(rgLIMUtlFreeDatIndEvnt);
334 /* Steps of freeing up the TfuDatInd.
335 * 1. loop through the datIndLst and free up all the buffers.
336 * 2. free up the whole event
338 if ((error == TRUE) && (datInd->datIndLst.count > 0))
340 node = datInd->datIndLst.first;
343 datInfo = (TfuDatInfo*)node->node;
344 RG_FREE_MSG(datInfo->mBuf);
350 } /* end of rgLIMUtlFreeDatIndEvnt*/
353 * @brief Downlink data indication from PHY.
357 * Function : RgLiTfuDatInd
359 * This API is invoked by PHY to send data indication to MAC on
360 * recieving data from UEs.
362 * @param[in] Pst *pst
363 * @param[in] SuId suId
364 * @param[in] TfuDatIndInfo *datInd
370 PUBLIC S16 RgLiTfuDatInd
374 TfuDatIndInfo *datInd
377 PUBLIC S16 RgLiTfuDatInd(pst, suId, datInd)
380 TfuDatIndInfo *datInd;
385 VOLATILE U32 startTime=0;
389 // printf("5GTF:: DatindRcvd\n");
391 RG_IS_INST_VALID(pst->dstInst);
392 inst = pst->dstInst - RG_INST_START;
394 SStartTask(&startTime, PID_MAC_TFU_DATIND);
397 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
399 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
400 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
404 /* Now call the TOM (Tfu ownership module) primitive to process further */
405 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
406 datInd->datIndLst.count;
407 ret = rgTOMDatInd(inst,datInd);
408 /* Fix: sriky memory corruption precautions */
409 /* Free up the memory for the request structure */
412 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
416 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
420 SStopTask(startTime, PID_MAC_TFU_DATIND);
426 /** @brief This function frees up the TfuDatReqInfo structure.
430 * Function: rgLIMUtlFreeDatReqEvnt
431 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
432 * free up the buffer's present in the PDUs list.
435 * @param [in] TfuDatReqInfo *datReq
436 * @param [in] Bool *error
440 PRIVATE Void rgLIMUtlFreeDatReqEvnt
442 TfuDatReqInfo *datReq,
446 PRIVATE Void rgLIMUtlFreeDatReqEvnt(datReq, error)
447 TfuDatReqInfo *datReq;
452 TfuDatReqPduInfo *datInfo;
456 TRC2(rgLIMUtlFreeDatReqEvnt);
457 /* Steps of freeing up the TfuDatReq.
458 * 1. Free the bch buffer.
459 * 2. loop through the pdus list and free up all the buffers.
460 * 3. free up the whole event
464 if (datReq->bchDat.pres == PRSNT_NODEF)
466 RG_FREE_MSG(datReq->bchDat.val);
468 if (datReq->pdus.count > 0)
470 node = datReq->pdus.first;
473 datInfo = (TfuDatReqPduInfo*)node->node;
474 for (i=0; i<datInfo->nmbOfTBs; i++)
476 if (datInfo->mBuf[i] != NULLP)
478 RG_FREE_MSG(datInfo->mBuf[i]);
487 } /* end of rgLIMUtlFreeDatReqEvnt*/
490 * @brief This API is invoked to send Data to PHY.
494 * Function : rgLIMTfuDatReq
496 * This API is invoked to send Data to PHY. It
497 * fills in the Pst structure, spId value and invokes Data
498 * request primitive at TFU.
500 * @param[in] Inst inst
501 * @param[in] TfuDatReqInfo *datReq
507 PUBLIC S16 rgLIMTfuDatReq
510 TfuDatReqInfo *datReq
513 PUBLIC S16 rgLIMTfuDatReq(inst,datReq)
515 TfuDatReqInfo *datReq;
523 /* Get the lower SAP control block from the layer control block. */
524 tfuSap = &(rgCb[inst].tfuSap);
527 if (tfuSap->sapSta.sapState != LRG_BND)
529 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
530 tfuSap->sapSta.sapState);
532 /* This case will never be hit if sap is not bound then we dont get TTI */
533 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
539 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
541 /* Using existing pst - for optimization */
542 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
545 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
548 } /* rgLIMTfuDatReq*/
552 * @brief This API is invoked to send Data to PHY.
556 * Function : rgLIMTfuDelDatReq
558 * This API is invoked to send Data to PHY. It
559 * fills in the Pst structure, spId value and invokes Data
560 * request primitive at TFU.
562 * @param[in] Inst inst
563 * @param[in] TfuDelDatReqInfo *datReq
569 PUBLIC S16 rgLIMTfuDelDatReq
572 TfuDelDatReqInfo *delDatReq
575 PUBLIC S16 rgLIMTfuDatReq(inst,delDatReq)
577 TfuDelDatReqInfo *delDatReq;
583 TRC2(rgLIMTfuDelDatReq)
585 /* Get the lower SAP control block from the layer control block. */
586 tfuSap = &(rgCb[inst].tfuSap);
589 if (tfuSap->sapSta.sapState != LRG_BND)
591 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
592 tfuSap->sapSta.sapState);
597 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
600 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
603 } /* rgLIMTfuDatReq*/
607 * @brief Transmission time interval indication from PHY.
611 * Function : sendSlotIndMacToSch
613 * This API is invoked by MAC to send slot ind to scheduler.
615 * @param[in] SlotIndInfo *slotInd
620 int sendSlotIndMacToSch(SlotIndInfo *slotInd)
623 /* fill Pst structure to send to lwr_mac to MAC */
631 pst.event = EVENT_SLOT_IND_TO_SCH;
634 pst.selector = MAC_SELECTOR_TC;
636 return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
640 * @brief Transmission time interval indication from PHY.
644 * Function : fapiMacSlotInd
646 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
648 * @param[in] Pst *pst
649 * @param[in] SuId suId
650 * @param[in] SlotIndInfo *slotInd
655 PUBLIC S16 fapiMacSlotInd
662 VOLATILE U32 startTime=0;
665 RG_IS_INST_VALID(pst->dstInst);
666 inst = pst->dstInst - RG_INST_START;
668 SStartTask(&startTime, PID_MAC_TTI_IND);
670 /* send slot indication to scheduler */
671 ret = sendSlotIndMacToSch(slotInd);
674 DU_LOG("\nsending of slot ind msg from MAC to SCH failed");
678 /* Now call the TOM (Tfu ownership module) primitive to process further */
679 ret = macProcessSlotInd(inst,*slotInd);
682 DU_LOG("\nmacProcessSlotInd failed");
688 SStopTask(startTime, PID_MAC_TTI_IND);
691 } /* fapiMacSlotInd */
693 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
695 * @brief Transmission of non-rt indication from CL.
699 * Function : RgLiTfuNonRtInd
701 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
703 * @param[in] Pst *pst
704 * @param[in] SuId suId
710 PUBLIC S16 RgLiTfuNonRtInd
716 PUBLIC S16 RgLiTfuNonRtInd(pst, suId)
721 TRC3(RgLiTfuNonRtInd);
724 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
726 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
730 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
732 } /* RgLiTfuNonRtInd */
735 /**********************************************************************
738 **********************************************************************/