Merge "Documentation updates"
[o-du/l2.git] / src / 5gnrmac / rg_lim.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 /************************************************************************
20  
21      Name:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code for Entry point fucntions
26   
27      File:     rg_lim.c 
28   
29 **********************************************************************/
30
31 /** @file rg_lim.c.
32 @brief It has APIs exposed by Lower Interface Modulue of MAC. It acts as an 
33 Interface handler for lower interface APIs.
34 */
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 "common_def.h"
40 #include "rgu.h"           /* RGU defines */
41 #include "tfu.h"           /* RGU defines */
42 #include "lrg.h"           /* layer management defines for LTE-MAC */
43 #include "crg.h"           /* layer management defines for LTE-MAC */
44 #include "rg_sch_inf.h"           /* layer management defines for LTE-MAC */
45 #include "rg_env.h"        /* customisable defines and macros for MAC */
46 #include "rg.h"            /* defines and macros for MAC */
47
48 /* header/extern include files (.x) */
49 #include "rgu.x"           /* RGU types */
50 #include "tfu.x"           /* RGU types */
51 #include "lrg.x"           /* layer management typedefs for MAC */
52 #include "crg.x"           /* layer management typedefs for MAC */
53 #include "rg_sch_inf.x"    /* SCH interface typedefs */
54 #include "rg_prg.x"    /* PRG interface typedefs */
55 #include "rg.x"            /* typedefs for MAC */
56
57 /* local externs */
58 #ifdef UNUSED_FUNC
59 static S16  rgLIMValidateSap ARGS((Inst inst,SuId suId));
60 #endif
61 static Void rgLIMUtlFreeDatIndEvnt ARGS((TfuDatIndInfo *datInd,
62                                           Bool error));
63 #ifdef RG_UNUSED
64 static Void rgLIMUtlFreeDatReqEvnt ARGS((TfuDatReqInfo *datReq,
65                                           Bool error));
66 #endif
67 /* forward references */
68
69 /**
70  * @brief Bind confirm API for TFU SAP 
71  *
72  * @details
73  *
74  *     Function : RgLiTfuBndCfm
75  *      
76  *      This API is invoked by PHY to confirm TFU SAP bind. 
77  *     
78  *           
79  *  @param[in]  Pst   *pst 
80  *  @param[in]  SuId  suId 
81  *  @param[in]  uint8_t    status
82  *  @return  S16
83  *      -# ROK 
84  *      -# RFAILED 
85  **/
86 S16 RgLiTfuBndCfm 
87 (
88 Pst     *pst,
89 SuId    suId, 
90 uint8_t status
91 )
92 {
93    Inst inst;
94    S16 ret;
95    RgLowSapCb  *tfuSap;
96
97
98
99    RG_IS_INST_VALID(pst->dstInst);
100    inst = pst->dstInst - RG_INST_START;
101    /* Lets validate suId first */
102    /* CA_Change */
103    tfuSap = &(rgCb[inst].tfuSap);
104
105    if (suId != tfuSap->sapCfg.suId)
106    {
107       RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
108             tfuSap->sapCfg.suId, suId);
109       return RFAILED;
110    }
111    ret = rgLMMBndCfm (pst, suId, status);
112    return (ret);
113 }  /* RgLiTfuBndCfm */
114
115  /** @brief This function Validates the SAP information received along with the
116   * primitive from the lower layer. 
117   * Function:
118   *   Validates SAP information.
119  *  @param[in]  Inst        inst
120   * @param  suId The SAP Id
121   * @return 
122   *   -# ROK
123   *   -# RFAILED
124   */
125 #ifdef UNUSED_FUNC
126 static S16 rgLIMValidateSap(Inst  inst,SuId suId)
127 {
128    RgLowSapCb  *tfuSap;
129
130
131    tfuSap = &(rgCb[inst].tfuSap);
132
133    /* First lets check the suId */
134    if( suId != tfuSap->sapCfg.suId)
135    {
136       RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
137             tfuSap->sapCfg.suId, suId);
138       return RFAILED;
139    }
140    if (tfuSap->sapSta.sapState != LRG_BND)
141    {
142       RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
143             tfuSap->sapCfg.suId);
144       return RFAILED;
145    }
146    return ROK;
147 } /* end of rgLIMValidateSap */
148 #endif
149 /** @brief This function frees up the TfuDatIndInfo structure
150  *
151  * @details
152  *
153  *     Function: rgLIMUtlFreeDatIndEvnt 
154  *       - Function frees up the TfuDatIndInfo structure, in case of error it shall
155  *       free up the buffer's present in the datIndLst.
156  *
157  *         Processing steps:
158  * @param  [in] TfuDatIndInfo *datInd
159  * @param  [in] Bool          *error
160  * @return 
161  */
162 static Void rgLIMUtlFreeDatIndEvnt(TfuDatIndInfo *datInd,Bool error)
163 {
164
165    TfuDatInfo     *datInfo;
166    CmLList        *node;
167
168    /* Steps of freeing up the TfuDatInd.
169     * 1. loop through the datIndLst and free up all the buffers.
170     * 2. free up the whole event
171     */
172    if ((error == TRUE) && (datInd->datIndLst.count > 0))
173    {
174       node =  datInd->datIndLst.first;
175       while (node)
176       {
177          datInfo = (TfuDatInfo*)node->node;
178          RG_FREE_MSG(datInfo->mBuf);
179          node = node->next;
180       }
181    }
182    RG_FREE_MEM(datInd);
183    return;
184 } /* end of rgLIMUtlFreeDatIndEvnt*/
185
186 /**
187  * @brief Downlink data indication from PHY.
188  *
189  * @details
190  *
191  *     Function : RgLiTfuDatInd
192  *      
193  *      This API is invoked by PHY to send data indication to MAC on 
194  *      recieving data from UEs.
195  *           
196  *  @param[in]  Pst              *pst
197  *  @param[in]  SuId             suId 
198  *  @param[in]  TfuDatIndInfo    *datInd
199  *  @return  S16
200  *      -# ROK 
201  *      -# RFAILED 
202  **/
203 S16 RgLiTfuDatInd
204 (
205 Pst                *pst, 
206 SuId               suId, 
207 TfuDatIndInfo    *datInd
208 )
209 {
210    Inst             inst;
211    S16              ret;
212    volatile uint32_t     startTime=0;
213
214
215   // printf("5GTF:: DatindRcvd\n");
216
217    RG_IS_INST_VALID(pst->dstInst);
218    inst = pst->dstInst - RG_INST_START;
219    /*starting Task*/
220    SStartTask(&startTime, PID_MAC_TFU_DATIND);
221
222 #ifndef NO_ERRCLS 
223    if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
224    {
225       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
226       rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
227       return (ret);
228    }
229 #endif
230    /* Now call the TOM (Tfu ownership module) primitive to process further */
231    rgCb[inst].tfuSap.sapSts.numPduRcvd += 
232                     datInd->datIndLst.count;
233    ret = rgTOMDatInd(inst,datInd);
234    /* Fix: sriky memory corruption precautions */
235    /* Free up the memory for the request structure */
236    if (ret == ROK)
237    {
238       rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
239    }
240    else
241    {
242       rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
243    }
244
245    /*stoping Task*/
246    SStopTask(startTime, PID_MAC_TFU_DATIND);
247
248    return (ret);
249 }  /* RgLiTfuDatInd*/
250
251 #ifdef RG_UNUSED
252 /** @brief This function frees up the TfuDatReqInfo structure.
253  *
254  * @details
255  *
256  *     Function: rgLIMUtlFreeDatReqEvnt
257  *       - Function frees up the TfuDatReqInfo structure, in case of error it shall
258  *       free up the buffer's present in the PDUs list.
259  *
260  *         Processing steps:
261  * @param  [in] TfuDatReqInfo *datReq
262  * @param  [in] Bool          *error
263  * @return 
264  */
265 static Void rgLIMUtlFreeDatReqEvnt(TfuDatReqInfo *datReq,Bool  error)
266 {
267
268    TfuDatReqPduInfo *datInfo;
269    CmLList          *node;
270    uint8_t          i;
271
272    /* Steps of freeing up the TfuDatReq.
273     * 1. Free the bch buffer.
274     * 2. loop through the pdus list and free up all the buffers.
275     * 3. free up the whole event
276     */
277    if (error)
278    {
279       if (datReq->bchDat.pres == PRSNT_NODEF)
280       {
281          RG_FREE_MSG(datReq->bchDat.val);
282       }
283       if (datReq->pdus.count > 0)
284       {
285          node =  datReq->pdus.first;
286          while (node)
287          {
288             datInfo = (TfuDatReqPduInfo*)node->node;
289             for (i=0; i<datInfo->nmbOfTBs; i++)
290             {
291                if (datInfo->mBuf[i] != NULLP)
292                {
293                   RG_FREE_MSG(datInfo->mBuf[i]);
294                }
295             }
296             node = node->next;
297          }
298       }
299    }
300    RG_FREE_MEM(datReq);
301    return;
302 } /* end of rgLIMUtlFreeDatReqEvnt*/
303 #endif
304
305 #ifdef L2_OPTMZ
306 /**
307  * @brief This API is invoked to send Data to PHY.
308  *
309  * @details
310  *
311  *     Function : rgLIMTfuDelDatReq
312  *      
313  *      This API is invoked to send Data to PHY. It 
314  *      fills in the Pst structure, spId value and invokes Data
315  *      request primitive at TFU.
316  *           
317  *  @param[in]  Inst        inst
318  *  @param[in]  TfuDelDatReqInfo *datReq
319  *  @return  S16
320  *      -# ROK 
321  *      -# RFAILED 
322  **/
323 S16 rgLIMTfuDelDatReq(Inst inst,TfuDelDatReqInfo *delDatReq)
324 {
325    S16         ret;
326    RgLowSapCb  *tfuSap;
327
328
329    /* Get the lower SAP control block from the layer control block. */
330    tfuSap = &(rgCb[inst].tfuSap);
331
332 #ifndef NO_ERRCLS
333    if (tfuSap->sapSta.sapState != LRG_BND)
334    {
335       RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
336             tfuSap->sapSta.sapState);
337       return RFAILED;
338    }
339 #endif
340
341    if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId, 
342                             delDatReq)) != ROK)
343    {
344       RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
345    }
346    return (ret);
347 }  /* rgLIMTfuDatReq*/
348 #endif /*L2_OPTMZ */
349
350 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
351  /**
352  * @brief Transmission of non-rt indication from CL.
353  *
354  * @details
355  *
356  *     Function : RgLiTfuNonRtInd 
357  *      
358  *      This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
359  *           
360  *  @param[in]  Pst            *pst
361  *  @param[in]  SuId           suId 
362  *  @return  S16
363  *      -# ROK 
364  *      -# RFAILED 
365  **/
366 S16 RgLiTfuNonRtInd(Pst  *pst,SuId  suId)
367 {
368
369 #ifdef NO_ERRCLS
370    if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
371    {
372       RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
373       return RFAILED;
374    }
375 #endif
376    rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
377    return ROK;
378 }  /* RgLiTfuNonRtInd */
379
380 #endif
381 /**********************************************************************
382  
383          End of file
384 **********************************************************************/