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 */
83 PRIVATE S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
84 PRIVATE Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
87 PRIVATE Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
90 /* forward references */
93 * @brief This API is invoked to send TFU SAP bind request to PHY.
97 * Function : rgLIMTfuBndReq
99 * This API is invoked to send TFU SAP bind request to PHY. It fills in
100 * the Pst structure, spId and suId values and invokes bind request
103 * @param[in] Inst inst
104 * @param[in] SuId suId
105 * @param[in] SpId spId
111 PUBLIC S16 rgLIMTfuBndReq
118 PUBLIC S16 rgLIMTfuBndReq(inst,suId, spId)
128 TRC2(rgLIMTfuBndReq);
130 /* Get the lower SAP control block from the layer control block. */
131 tfuSap = &(rgCb[inst].tfuSap);
132 (Void)cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
133 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
135 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
138 } /* rgLIMTfuBndReq */
142 * @brief This API is invoked to send TFU SAP unbind request to PHY.
146 * Function : rgLIMTfuBndReq
148 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
149 * the Pst structure and spId value and invokes unbind request
152 * @param[in] Inst inst
153 * @param[in] SpId spId
154 * @param[in] Reason reason
160 PUBLIC S16 rgLIMTfuUbndReq
167 PUBLIC S16 rgLIMTfuUbndReq(inst,spId, reason)
177 TRC2(rgLIMTfuUbndReq);
179 /* Get the lower SAP control block from the layer control block. */
180 tfuSap = &(rgCb[inst].tfuSap);
181 cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
182 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
184 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
188 } /* rgLIMTfuUbndReq */
192 * @brief Bind confirm API for TFU SAP
196 * Function : RgLiTfuBndCfm
198 * This API is invoked by PHY to confirm TFU SAP bind.
201 * @param[in] Pst *pst
202 * @param[in] SuId suId
203 * @param[in] U8 status
209 PUBLIC S16 RgLiTfuBndCfm
216 PUBLIC S16 RgLiTfuBndCfm(pst, suId, status)
229 RG_IS_INST_VALID(pst->dstInst);
230 inst = pst->dstInst - RG_INST_START;
231 /* Lets validate suId first */
233 tfuSap = &(rgCb[inst].tfuSap);
235 if (suId != tfuSap->sapCfg.suId)
237 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
238 tfuSap->sapCfg.suId, suId);
241 ret = rgLMMBndCfm (pst, suId, status);
243 } /* RgLiTfuBndCfm */
245 /** @brief This function Validates the SAP information received along with the
246 * primitive from the lower layer.
248 * Validates SAP information.
249 * @param[in] Inst inst
250 * @param suId The SAP Id
256 PRIVATE S16 rgLIMValidateSap
262 PRIVATE S16 rgLIMValidateSap(inst,suId)
269 TRC2(rgLIMValidateSap)
271 tfuSap = &(rgCb[inst].tfuSap);
273 /* First lets check the suId */
274 if( suId != tfuSap->sapCfg.suId)
276 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
277 tfuSap->sapCfg.suId, suId);
280 if (tfuSap->sapSta.sapState != LRG_BND)
282 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
283 tfuSap->sapCfg.suId);
287 } /* end of rgLIMValidateSap */
289 /** @brief This function frees up the TfuDatIndInfo structure
293 * Function: rgLIMUtlFreeDatIndEvnt
294 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
295 * free up the buffer's present in the datIndLst.
298 * @param [in] TfuDatIndInfo *datInd
299 * @param [in] Bool *error
303 PRIVATE Void rgLIMUtlFreeDatIndEvnt
305 TfuDatIndInfo *datInd,
309 PRIVATE Void rgLIMUtlFreeDatIndEvnt(datInd, error)
310 TfuDatIndInfo *datInd;
318 TRC2(rgLIMUtlFreeDatIndEvnt);
319 /* Steps of freeing up the TfuDatInd.
320 * 1. loop through the datIndLst and free up all the buffers.
321 * 2. free up the whole event
323 if ((error == TRUE) && (datInd->datIndLst.count > 0))
325 node = datInd->datIndLst.first;
328 datInfo = (TfuDatInfo*)node->node;
329 RG_FREE_MSG(datInfo->mBuf);
335 } /* end of rgLIMUtlFreeDatIndEvnt*/
338 * @brief Downlink data indication from PHY.
342 * Function : RgLiTfuDatInd
344 * This API is invoked by PHY to send data indication to MAC on
345 * recieving data from UEs.
347 * @param[in] Pst *pst
348 * @param[in] SuId suId
349 * @param[in] TfuDatIndInfo *datInd
355 PUBLIC S16 RgLiTfuDatInd
359 TfuDatIndInfo *datInd
362 PUBLIC S16 RgLiTfuDatInd(pst, suId, datInd)
365 TfuDatIndInfo *datInd;
370 VOLATILE U32 startTime=0;
374 // printf("5GTF:: DatindRcvd\n");
376 RG_IS_INST_VALID(pst->dstInst);
377 inst = pst->dstInst - RG_INST_START;
379 SStartTask(&startTime, PID_MAC_TFU_DATIND);
382 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
384 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
385 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
389 /* Now call the TOM (Tfu ownership module) primitive to process further */
390 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
391 datInd->datIndLst.count;
392 ret = rgTOMDatInd(inst,datInd);
393 /* Fix: sriky memory corruption precautions */
394 /* Free up the memory for the request structure */
397 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
401 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
405 SStopTask(startTime, PID_MAC_TFU_DATIND);
411 /** @brief This function frees up the TfuDatReqInfo structure.
415 * Function: rgLIMUtlFreeDatReqEvnt
416 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
417 * free up the buffer's present in the PDUs list.
420 * @param [in] TfuDatReqInfo *datReq
421 * @param [in] Bool *error
425 PRIVATE Void rgLIMUtlFreeDatReqEvnt
427 TfuDatReqInfo *datReq,
431 PRIVATE Void rgLIMUtlFreeDatReqEvnt(datReq, error)
432 TfuDatReqInfo *datReq;
437 TfuDatReqPduInfo *datInfo;
441 TRC2(rgLIMUtlFreeDatReqEvnt);
442 /* Steps of freeing up the TfuDatReq.
443 * 1. Free the bch buffer.
444 * 2. loop through the pdus list and free up all the buffers.
445 * 3. free up the whole event
449 if (datReq->bchDat.pres == PRSNT_NODEF)
451 RG_FREE_MSG(datReq->bchDat.val);
453 if (datReq->pdus.count > 0)
455 node = datReq->pdus.first;
458 datInfo = (TfuDatReqPduInfo*)node->node;
459 for (i=0; i<datInfo->nmbOfTBs; i++)
461 if (datInfo->mBuf[i] != NULLP)
463 RG_FREE_MSG(datInfo->mBuf[i]);
472 } /* end of rgLIMUtlFreeDatReqEvnt*/
475 * @brief This API is invoked to send Data to PHY.
479 * Function : rgLIMTfuDatReq
481 * This API is invoked to send Data to PHY. It
482 * fills in the Pst structure, spId value and invokes Data
483 * request primitive at TFU.
485 * @param[in] Inst inst
486 * @param[in] TfuDatReqInfo *datReq
492 PUBLIC S16 rgLIMTfuDatReq
495 TfuDatReqInfo *datReq
498 PUBLIC S16 rgLIMTfuDatReq(inst,datReq)
500 TfuDatReqInfo *datReq;
508 /* Get the lower SAP control block from the layer control block. */
509 tfuSap = &(rgCb[inst].tfuSap);
512 if (tfuSap->sapSta.sapState != LRG_BND)
514 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
515 tfuSap->sapSta.sapState);
517 /* This case will never be hit if sap is not bound then we dont get TTI */
518 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
524 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
526 /* Using existing pst - for optimization */
527 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
530 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
533 } /* rgLIMTfuDatReq*/
537 * @brief This API is invoked to send Data to PHY.
541 * Function : rgLIMTfuDelDatReq
543 * This API is invoked to send Data to PHY. It
544 * fills in the Pst structure, spId value and invokes Data
545 * request primitive at TFU.
547 * @param[in] Inst inst
548 * @param[in] TfuDelDatReqInfo *datReq
554 PUBLIC S16 rgLIMTfuDelDatReq
557 TfuDelDatReqInfo *delDatReq
560 PUBLIC S16 rgLIMTfuDatReq(inst,delDatReq)
562 TfuDelDatReqInfo *delDatReq;
568 TRC2(rgLIMTfuDelDatReq)
570 /* Get the lower SAP control block from the layer control block. */
571 tfuSap = &(rgCb[inst].tfuSap);
574 if (tfuSap->sapSta.sapState != LRG_BND)
576 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
577 tfuSap->sapSta.sapState);
582 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
585 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
588 } /* rgLIMTfuDatReq*/
592 * @brief Transmission time interval indication from PHY.
596 * Function : RgLiTfuTtiInd
598 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
600 * @param[in] Pst *pst
601 * @param[in] SuId suId
602 * @param[in] TfuTtiIndInfo *ttiInd
608 PUBLIC S16 RgLiTfuTtiInd
612 TfuTtiIndInfo *ttiInd
615 PUBLIC S16 RgLiTfuTtiInd(pst, suId, ttiInd)
618 TfuTtiIndInfo *ttiInd;
622 VOLATILE U32 startTime=0;
627 RG_IS_INST_VALID(pst->dstInst);
628 inst = pst->dstInst - RG_INST_START;
630 SStartTask(&startTime, PID_MAC_TTI_IND);
633 if ((ret = rgLIMValidateSap (pst->dstInst - RG_INST_START,suId)) != ROK)
635 RLOG_ARG0(L_ERROR,DBG_CELLID,ttiInd->cells[0].cellId,"SAP Validation failed");
640 /* Now call the TOM (Tfu ownership module) primitive to process further */
641 ret = rgTOMTtiInd(inst,ttiInd);
645 SStopTask(startTime, PID_MAC_TTI_IND);
648 } /* RgLiTfuTtiInd */
650 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
652 * @brief Transmission of non-rt indication from CL.
656 * Function : RgLiTfuNonRtInd
658 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
660 * @param[in] Pst *pst
661 * @param[in] SuId suId
667 PUBLIC S16 RgLiTfuNonRtInd
673 PUBLIC S16 RgLiTfuNonRtInd(pst, suId)
678 TRC3(RgLiTfuNonRtInd);
681 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
683 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
687 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
689 } /* RgLiTfuNonRtInd */
692 /**********************************************************************
695 **********************************************************************/