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 "rg.x" /* typedefs for MAC */
82 PRIVATE S16 rgLIMValidateSap ARGS((Inst inst,SuId suId));
83 PRIVATE Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
86 PRIVATE Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
89 /* forward references */
92 * @brief This API is invoked to send TFU SAP bind request to PHY.
96 * Function : rgLIMTfuBndReq
98 * This API is invoked to send TFU SAP bind request to PHY. It fills in
99 * the Pst structure, spId and suId values and invokes bind request
102 * @param[in] Inst inst
103 * @param[in] SuId suId
104 * @param[in] SpId spId
110 PUBLIC S16 rgLIMTfuBndReq
117 PUBLIC S16 rgLIMTfuBndReq(inst,suId, spId)
127 TRC2(rgLIMTfuBndReq);
129 /* Get the lower SAP control block from the layer control block. */
130 tfuSap = &(rgCb[inst].tfuSap);
131 (Void)cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
132 if((ret = RgLiTfuBndReq (&pst, suId, spId)) != ROK)
134 RLOG0(L_ERROR,"Call to RgLiTfuBndReq() failed");
137 } /* rgLIMTfuBndReq */
141 * @brief This API is invoked to send TFU SAP unbind request to PHY.
145 * Function : rgLIMTfuBndReq
147 * This API is invoked to send TFU SAP unbind request to PHY. It fills in
148 * the Pst structure and spId value and invokes unbind request
151 * @param[in] Inst inst
152 * @param[in] SpId spId
153 * @param[in] Reason reason
159 PUBLIC S16 rgLIMTfuUbndReq
166 PUBLIC S16 rgLIMTfuUbndReq(inst,spId, reason)
176 TRC2(rgLIMTfuUbndReq);
178 /* Get the lower SAP control block from the layer control block. */
179 tfuSap = &(rgCb[inst].tfuSap);
180 cmMemcpy ((U8*)&pst, (U8*)&(tfuSap->sapCfg.sapPst), sizeof(Pst));
181 if((ret = RgLiTfuUbndReq (&pst, tfuSap->sapCfg.spId, reason)) != ROK)
183 RLOG0(L_ERROR,"Call to RgLiTfuUbndReq() failed");
187 } /* rgLIMTfuUbndReq */
191 * @brief Bind confirm API for TFU SAP
195 * Function : RgLiTfuBndCfm
197 * This API is invoked by PHY to confirm TFU SAP bind.
200 * @param[in] Pst *pst
201 * @param[in] SuId suId
202 * @param[in] U8 status
208 PUBLIC S16 RgLiTfuBndCfm
215 PUBLIC S16 RgLiTfuBndCfm(pst, suId, status)
228 RG_IS_INST_VALID(pst->dstInst);
229 inst = pst->dstInst - RG_INST_START;
230 /* Lets validate suId first */
232 tfuSap = &(rgCb[inst].tfuSap);
234 if (suId != tfuSap->sapCfg.suId)
236 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
237 tfuSap->sapCfg.suId, suId);
240 ret = rgLMMBndCfm (pst, suId, status);
242 } /* RgLiTfuBndCfm */
244 /** @brief This function Validates the SAP information received along with the
245 * primitive from the lower layer.
247 * Validates SAP information.
248 * @param[in] Inst inst
249 * @param suId The SAP Id
255 PRIVATE S16 rgLIMValidateSap
261 PRIVATE S16 rgLIMValidateSap(inst,suId)
268 TRC2(rgLIMValidateSap)
270 tfuSap = &(rgCb[inst].tfuSap);
272 /* First lets check the suId */
273 if( suId != tfuSap->sapCfg.suId)
275 RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
276 tfuSap->sapCfg.suId, suId);
279 if (tfuSap->sapSta.sapState != LRG_BND)
281 RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
282 tfuSap->sapCfg.suId);
286 } /* end of rgLIMValidateSap */
288 /** @brief This function frees up the TfuDatIndInfo structure
292 * Function: rgLIMUtlFreeDatIndEvnt
293 * - Function frees up the TfuDatIndInfo structure, in case of error it shall
294 * free up the buffer's present in the datIndLst.
297 * @param [in] TfuDatIndInfo *datInd
298 * @param [in] Bool *error
302 PRIVATE Void rgLIMUtlFreeDatIndEvnt
304 TfuDatIndInfo *datInd,
308 PRIVATE Void rgLIMUtlFreeDatIndEvnt(datInd, error)
309 TfuDatIndInfo *datInd;
317 TRC2(rgLIMUtlFreeDatIndEvnt);
318 /* Steps of freeing up the TfuDatInd.
319 * 1. loop through the datIndLst and free up all the buffers.
320 * 2. free up the whole event
322 if ((error == TRUE) && (datInd->datIndLst.count > 0))
324 node = datInd->datIndLst.first;
327 datInfo = (TfuDatInfo*)node->node;
328 RG_FREE_MSG(datInfo->mBuf);
334 } /* end of rgLIMUtlFreeDatIndEvnt*/
337 * @brief Downlink data indication from PHY.
341 * Function : RgLiTfuDatInd
343 * This API is invoked by PHY to send data indication to MAC on
344 * recieving data from UEs.
346 * @param[in] Pst *pst
347 * @param[in] SuId suId
348 * @param[in] TfuDatIndInfo *datInd
354 PUBLIC S16 RgLiTfuDatInd
358 TfuDatIndInfo *datInd
361 PUBLIC S16 RgLiTfuDatInd(pst, suId, datInd)
364 TfuDatIndInfo *datInd;
369 VOLATILE U32 startTime=0;
373 // printf("5GTF:: DatindRcvd\n");
375 RG_IS_INST_VALID(pst->dstInst);
376 inst = pst->dstInst - RG_INST_START;
378 SStartTask(&startTime, PID_MAC_TFU_DATIND);
381 if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
383 RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
384 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
388 /* Now call the TOM (Tfu ownership module) primitive to process further */
389 rgCb[inst].tfuSap.sapSts.numPduRcvd +=
390 datInd->datIndLst.count;
391 ret = rgTOMDatInd(inst,datInd);
392 /* Fix: sriky memory corruption precautions */
393 /* Free up the memory for the request structure */
396 rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
400 rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
404 SStopTask(startTime, PID_MAC_TFU_DATIND);
410 /** @brief This function frees up the TfuDatReqInfo structure.
414 * Function: rgLIMUtlFreeDatReqEvnt
415 * - Function frees up the TfuDatReqInfo structure, in case of error it shall
416 * free up the buffer's present in the PDUs list.
419 * @param [in] TfuDatReqInfo *datReq
420 * @param [in] Bool *error
424 PRIVATE Void rgLIMUtlFreeDatReqEvnt
426 TfuDatReqInfo *datReq,
430 PRIVATE Void rgLIMUtlFreeDatReqEvnt(datReq, error)
431 TfuDatReqInfo *datReq;
436 TfuDatReqPduInfo *datInfo;
440 TRC2(rgLIMUtlFreeDatReqEvnt);
441 /* Steps of freeing up the TfuDatReq.
442 * 1. Free the bch buffer.
443 * 2. loop through the pdus list and free up all the buffers.
444 * 3. free up the whole event
448 if (datReq->bchDat.pres == PRSNT_NODEF)
450 RG_FREE_MSG(datReq->bchDat.val);
452 if (datReq->pdus.count > 0)
454 node = datReq->pdus.first;
457 datInfo = (TfuDatReqPduInfo*)node->node;
458 for (i=0; i<datInfo->nmbOfTBs; i++)
460 if (datInfo->mBuf[i] != NULLP)
462 RG_FREE_MSG(datInfo->mBuf[i]);
471 } /* end of rgLIMUtlFreeDatReqEvnt*/
474 * @brief This API is invoked to send Data to PHY.
478 * Function : rgLIMTfuDatReq
480 * This API is invoked to send Data to PHY. It
481 * fills in the Pst structure, spId value and invokes Data
482 * request primitive at TFU.
484 * @param[in] Inst inst
485 * @param[in] TfuDatReqInfo *datReq
491 PUBLIC S16 rgLIMTfuDatReq
494 TfuDatReqInfo *datReq
497 PUBLIC S16 rgLIMTfuDatReq(inst,datReq)
499 TfuDatReqInfo *datReq;
507 /* Get the lower SAP control block from the layer control block. */
508 tfuSap = &(rgCb[inst].tfuSap);
511 if (tfuSap->sapSta.sapState != LRG_BND)
513 RLOG_ARG1(L_ERROR,DBG_CELLID,datReq->cellId,"Lower SAP not bound (%d)",
514 tfuSap->sapSta.sapState);
516 /* This case will never be hit if sap is not bound then we dont get TTI */
517 rgLIMUtlFreeDatReqEvnt(datReq, TRUE);
523 tfuSap->sapSts.numPduTxmit += datReq->pdus.count;
525 /* Using existing pst - for optimization */
526 if((ret = RgLiTfuDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
529 RLOG_ARG0(L_ERROR,DBG_CELLID,datReq->cellId,"Call to RgLiTfuDatReq() failed");
532 } /* rgLIMTfuDatReq*/
536 * @brief This API is invoked to send Data to PHY.
540 * Function : rgLIMTfuDelDatReq
542 * This API is invoked to send Data to PHY. It
543 * fills in the Pst structure, spId value and invokes Data
544 * request primitive at TFU.
546 * @param[in] Inst inst
547 * @param[in] TfuDelDatReqInfo *datReq
553 PUBLIC S16 rgLIMTfuDelDatReq
556 TfuDelDatReqInfo *delDatReq
559 PUBLIC S16 rgLIMTfuDatReq(inst,delDatReq)
561 TfuDelDatReqInfo *delDatReq;
567 TRC2(rgLIMTfuDelDatReq)
569 /* Get the lower SAP control block from the layer control block. */
570 tfuSap = &(rgCb[inst].tfuSap);
573 if (tfuSap->sapSta.sapState != LRG_BND)
575 RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
576 tfuSap->sapSta.sapState);
581 if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId,
584 RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
587 } /* rgLIMTfuDatReq*/
591 * @brief Transmission time interval indication from PHY.
595 * Function : RgLiTfuTtiInd
597 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
599 * @param[in] Pst *pst
600 * @param[in] SuId suId
601 * @param[in] TfuTtiIndInfo *ttiInd
607 PUBLIC S16 RgLiTfuTtiInd
611 TfuTtiIndInfo *ttiInd
614 PUBLIC S16 RgLiTfuTtiInd(pst, suId, ttiInd)
617 TfuTtiIndInfo *ttiInd;
621 VOLATILE U32 startTime=0;
626 RG_IS_INST_VALID(pst->dstInst);
627 inst = pst->dstInst - RG_INST_START;
629 SStartTask(&startTime, PID_MAC_TTI_IND);
632 if ((ret = rgLIMValidateSap (pst->dstInst - RG_INST_START,suId)) != ROK)
634 RLOG_ARG0(L_ERROR,DBG_CELLID,ttiInd->cells[0].cellId,"SAP Validation failed");
639 /* Now call the TOM (Tfu ownership module) primitive to process further */
640 ret = rgTOMTtiInd(inst,ttiInd);
644 SStopTask(startTime, PID_MAC_TTI_IND);
647 } /* RgLiTfuTtiInd */
649 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
651 * @brief Transmission of non-rt indication from CL.
655 * Function : RgLiTfuNonRtInd
657 * This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
659 * @param[in] Pst *pst
660 * @param[in] SuId suId
666 PUBLIC S16 RgLiTfuNonRtInd
672 PUBLIC S16 RgLiTfuNonRtInd(pst, suId)
677 TRC3(RgLiTfuNonRtInd);
680 if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
682 RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
686 rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
688 } /* RgLiTfuNonRtInd */
691 /**********************************************************************
694 **********************************************************************/