Added FAPI header to P7 messages[Issue-ID: ODUHIGH-254]
[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 #ifdef ANSI
87 S16 RgLiTfuBndCfm 
88 (
89 Pst     *pst,
90 SuId    suId, 
91 uint8_t status
92 )
93 #else
94 S16 RgLiTfuBndCfm(pst, suId, status)
95 Pst     *pst; 
96 SuId    suId; 
97 uint8_t status;
98 #endif
99 {
100    Inst inst;
101    S16 ret;
102    RgLowSapCb  *tfuSap;
103
104
105
106    RG_IS_INST_VALID(pst->dstInst);
107    inst = pst->dstInst - RG_INST_START;
108    /* Lets validate suId first */
109    /* CA_Change */
110    tfuSap = &(rgCb[inst].tfuSap);
111
112    if (suId != tfuSap->sapCfg.suId)
113    {
114       RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
115             tfuSap->sapCfg.suId, suId);
116       return RFAILED;
117    }
118    ret = rgLMMBndCfm (pst, suId, status);
119    return (ret);
120 }  /* RgLiTfuBndCfm */
121
122  /** @brief This function Validates the SAP information received along with the
123   * primitive from the lower layer. 
124   * Function:
125   *   Validates SAP information.
126  *  @param[in]  Inst        inst
127   * @param  suId The SAP Id
128   * @return 
129   *   -# ROK
130   *   -# RFAILED
131   */
132 #ifdef UNUSED_FUNC
133 #ifdef ANSI
134 static S16 rgLIMValidateSap
135 (
136  Inst    inst,
137  SuId    suId
138 )
139 #else
140 static S16 rgLIMValidateSap(inst,suId)
141  Inst    inst;
142  SuId    suId;
143 #endif
144 {
145    RgLowSapCb  *tfuSap;
146
147
148    tfuSap = &(rgCb[inst].tfuSap);
149
150    /* First lets check the suId */
151    if( suId != tfuSap->sapCfg.suId)
152    {
153       RLOG2(L_ERROR,"Incorrect SuId. Configured (%d) Recieved (%d)",
154             tfuSap->sapCfg.suId, suId);
155       return RFAILED;
156    }
157    if (tfuSap->sapSta.sapState != LRG_BND)
158    {
159       RLOG1(L_ERROR,"Lower SAP not enabled SuId (%d)",
160             tfuSap->sapCfg.suId);
161       return RFAILED;
162    }
163    return ROK;
164 } /* end of rgLIMValidateSap */
165 #endif
166 /** @brief This function frees up the TfuDatIndInfo structure
167  *
168  * @details
169  *
170  *     Function: rgLIMUtlFreeDatIndEvnt 
171  *       - Function frees up the TfuDatIndInfo structure, in case of error it shall
172  *       free up the buffer's present in the datIndLst.
173  *
174  *         Processing steps:
175  * @param  [in] TfuDatIndInfo *datInd
176  * @param  [in] Bool          *error
177  * @return 
178  */
179 #ifdef ANSI
180 static Void rgLIMUtlFreeDatIndEvnt 
181 (
182  TfuDatIndInfo *datInd,
183  Bool          error
184  )
185 #else
186 static Void rgLIMUtlFreeDatIndEvnt(datInd, error)
187  TfuDatIndInfo *datInd;
188  Bool          error;
189 #endif
190 {
191
192    TfuDatInfo     *datInfo;
193    CmLList        *node;
194
195    /* Steps of freeing up the TfuDatInd.
196     * 1. loop through the datIndLst and free up all the buffers.
197     * 2. free up the whole event
198     */
199    if ((error == TRUE) && (datInd->datIndLst.count > 0))
200    {
201       node =  datInd->datIndLst.first;
202       while (node)
203       {
204          datInfo = (TfuDatInfo*)node->node;
205          RG_FREE_MSG(datInfo->mBuf);
206          node = node->next;
207       }
208    }
209    RG_FREE_MEM(datInd);
210    return;
211 } /* end of rgLIMUtlFreeDatIndEvnt*/
212
213 /**
214  * @brief Downlink data indication from PHY.
215  *
216  * @details
217  *
218  *     Function : RgLiTfuDatInd
219  *      
220  *      This API is invoked by PHY to send data indication to MAC on 
221  *      recieving data from UEs.
222  *           
223  *  @param[in]  Pst              *pst
224  *  @param[in]  SuId             suId 
225  *  @param[in]  TfuDatIndInfo    *datInd
226  *  @return  S16
227  *      -# ROK 
228  *      -# RFAILED 
229  **/
230 #ifdef ANSI
231 S16 RgLiTfuDatInd
232 (
233 Pst                *pst, 
234 SuId               suId, 
235 TfuDatIndInfo    *datInd
236 )
237 #else
238 S16 RgLiTfuDatInd(pst, suId, datInd)
239 Pst                *pst; 
240 SuId               suId; 
241 TfuDatIndInfo    *datInd;
242 #endif
243 {
244    Inst             inst;
245    S16              ret;
246    volatile uint32_t     startTime=0;
247
248
249   // printf("5GTF:: DatindRcvd\n");
250
251    RG_IS_INST_VALID(pst->dstInst);
252    inst = pst->dstInst - RG_INST_START;
253    /*starting Task*/
254    SStartTask(&startTime, PID_MAC_TFU_DATIND);
255
256 #ifndef NO_ERRCLS 
257    if ((ret = rgLIMValidateSap (inst,suId)) != ROK)
258    {
259       RLOG_ARG0(L_ERROR,DBG_CELLID,datInd->cellId,"SAP Validation failed");
260       rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
261       return (ret);
262    }
263 #endif
264    /* Now call the TOM (Tfu ownership module) primitive to process further */
265    rgCb[inst].tfuSap.sapSts.numPduRcvd += 
266                     datInd->datIndLst.count;
267    ret = rgTOMDatInd(inst,datInd);
268    /* Fix: sriky memory corruption precautions */
269    /* Free up the memory for the request structure */
270    if (ret == ROK)
271    {
272       rgLIMUtlFreeDatIndEvnt(datInd, FALSE);
273    }
274    else
275    {
276       rgLIMUtlFreeDatIndEvnt(datInd, TRUE);
277    }
278
279    /*stoping Task*/
280    SStopTask(startTime, PID_MAC_TFU_DATIND);
281
282    return (ret);
283 }  /* RgLiTfuDatInd*/
284
285 #ifdef RG_UNUSED
286 /** @brief This function frees up the TfuDatReqInfo structure.
287  *
288  * @details
289  *
290  *     Function: rgLIMUtlFreeDatReqEvnt
291  *       - Function frees up the TfuDatReqInfo structure, in case of error it shall
292  *       free up the buffer's present in the PDUs list.
293  *
294  *         Processing steps:
295  * @param  [in] TfuDatReqInfo *datReq
296  * @param  [in] Bool          *error
297  * @return 
298  */
299 #ifdef ANSI
300 static Void rgLIMUtlFreeDatReqEvnt
301 (
302  TfuDatReqInfo *datReq,
303  Bool          error
304  )
305 #else
306 static Void rgLIMUtlFreeDatReqEvnt(datReq, error)
307  TfuDatReqInfo *datReq;
308  Bool          error;
309 #endif
310 {
311
312    TfuDatReqPduInfo *datInfo;
313    CmLList          *node;
314    uint8_t          i;
315
316    /* Steps of freeing up the TfuDatReq.
317     * 1. Free the bch buffer.
318     * 2. loop through the pdus list and free up all the buffers.
319     * 3. free up the whole event
320     */
321    if (error)
322    {
323       if (datReq->bchDat.pres == PRSNT_NODEF)
324       {
325          RG_FREE_MSG(datReq->bchDat.val);
326       }
327       if (datReq->pdus.count > 0)
328       {
329          node =  datReq->pdus.first;
330          while (node)
331          {
332             datInfo = (TfuDatReqPduInfo*)node->node;
333             for (i=0; i<datInfo->nmbOfTBs; i++)
334             {
335                if (datInfo->mBuf[i] != NULLP)
336                {
337                   RG_FREE_MSG(datInfo->mBuf[i]);
338                }
339             }
340             node = node->next;
341          }
342       }
343    }
344    RG_FREE_MEM(datReq);
345    return;
346 } /* end of rgLIMUtlFreeDatReqEvnt*/
347 #endif
348
349 #ifdef L2_OPTMZ
350 /**
351  * @brief This API is invoked to send Data to PHY.
352  *
353  * @details
354  *
355  *     Function : rgLIMTfuDelDatReq
356  *      
357  *      This API is invoked to send Data to PHY. It 
358  *      fills in the Pst structure, spId value and invokes Data
359  *      request primitive at TFU.
360  *           
361  *  @param[in]  Inst        inst
362  *  @param[in]  TfuDelDatReqInfo *datReq
363  *  @return  S16
364  *      -# ROK 
365  *      -# RFAILED 
366  **/
367 #ifdef ANSI
368 S16 rgLIMTfuDelDatReq 
369 (
370 Inst          inst,
371 TfuDelDatReqInfo *delDatReq
372 )
373 #else
374 S16 rgLIMTfuDatReq(inst,delDatReq)
375 Inst          inst;
376 TfuDelDatReqInfo *delDatReq;
377 #endif
378 {
379    S16         ret;
380    RgLowSapCb  *tfuSap;
381
382
383    /* Get the lower SAP control block from the layer control block. */
384    tfuSap = &(rgCb[inst].tfuSap);
385
386 #ifndef NO_ERRCLS
387    if (tfuSap->sapSta.sapState != LRG_BND)
388    {
389       RLOG_ARG1(L_ERROR,DBG_CELLID,delDatReq->cellId,"Lower SAP not bound (%d)",
390             tfuSap->sapSta.sapState);
391       return RFAILED;
392    }
393 #endif
394
395    if((ret = RgLiTfuDelDatReq (&tfuSap->sapCfg.sapPst, tfuSap->sapCfg.spId, 
396                             delDatReq)) != ROK)
397    {
398       RLOG_ARG0(L_ERROR,DBG_CELLID,delDatReq->cellId,"Call to RgLiTfuDelDatReq() failed");
399    }
400    return (ret);
401 }  /* rgLIMTfuDatReq*/
402 #endif /*L2_OPTMZ */
403
404 #if defined(TENB_T2K3K_SPECIFIC_CHANGES) && defined(LTE_TDD)
405  /**
406  * @brief Transmission of non-rt indication from CL.
407  *
408  * @details
409  *
410  *     Function : RgLiTfuNonRtInd 
411  *      
412  *      This API is invoked by CL to indicate non-rt processing indication to MAC for a cell.
413  *           
414  *  @param[in]  Pst            *pst
415  *  @param[in]  SuId           suId 
416  *  @return  S16
417  *      -# ROK 
418  *      -# RFAILED 
419  **/
420 #ifdef ANSI
421 S16 RgLiTfuNonRtInd
422 (
423 Pst                 *pst,
424 SuId                suId
425 )
426 #else
427 S16 RgLiTfuNonRtInd(pst, suId)
428 Pst                 *pst;
429 SuId                suId;
430 #endif
431 {
432
433 #ifdef NO_ERRCLS
434    if (rgLIMValidateSap (pst->dstInst - RG_INST_START, suId) != ROK)
435    {
436       RGDBGERRNEW(pst->dstInst - RG_INST_START, (rgPBuf(pst->dstInst - RG_INST_START),"RgLiTfuNonRtInd() SAP Validation failed.\n"));
437       return RFAILED;
438    }
439 #endif
440    rgDHMFreeTbBufs(pst->dstInst - RG_INST_START);
441    return ROK;
442 }  /* RgLiTfuNonRtInd */
443
444 #endif
445 /**********************************************************************
446  
447          End of file
448 **********************************************************************/