Adding new commiter to ODU-High repo
[o-du/l2.git] / src / 5gnrmac / rg_utl.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_utl.c
28   
29 **********************************************************************/
30
31 /** @file rg_utl.c
32 @brief This file implements utility functions for LTE MAC
33 */
34
35
36 /* header include files (.h) */
37 #include "common_def.h"
38 #include "rg_env.h"        /* MAC Environment Defines */
39 #include "crg.h"           /* CRG Interface defines */
40 #include "rgu.h"           /* RGU Interface defines */
41 #include "tfu.h"           /* TFU Interface defines */
42 #include "rg_sch_inf.h"    /* RGR Interface defines */
43 #include "lrg.h"           /* LRG Interface defines */
44 #include  "mac_utils.h"
45
46 #include "rg_prg.h"        /* PRG(MAC-MAC) Interface includes */
47 #include "rg.h"            /* MAC defines */
48 #include "rg_err.h"        /* MAC error defines */
49
50 /* header/extern include files (.x) */
51 #include "cm5.x"           /* Timer */
52
53 #include "crg.x"           /* CRG Interface includes */
54 #include "rgu.x"           /* RGU Interface includes */
55 #include "tfu.x"           /* TFU Interface includes */
56 #include "rg_sch_inf.x"    /* RGR Interface includes */
57 #include "lrg.x"           /* LRG Interface includes */
58 #include "rg_prg.x"        /* PRG(MAC-MAC) Interface includes */
59
60 #include "du_app_mac_inf.h"
61 #include "rg.x"            /* MAC includes */
62
63 /* local defines */
64 #define RG_NON_MIMO_IDX 0
65
66 RgCb rgCb[RG_MAX_INST];
67 /***********************************************************
68  *
69  *     Func : rgAllocSBuf
70  *
71  *     Desc : Utility Function to Allocate static buffer. 
72  *            Memory allocated is assumed contiguous.
73  *            
74  *
75  *     Ret  : ROK
76  *            RFAILED
77  *
78  *     Notes: Caller doesnt need to raise the alarm in case of memory
79  *            allocation gets failed. 
80  *
81  *     File : rg_utl.c
82  *
83  **********************************************************/
84 S16 rgAllocSBuf
85 (
86 Inst    inst,
87 Data    **pData,            /* Pointer of the data to be returned */
88 Size    size                /* size */
89 )
90 {
91    RgUstaDgn dgn;      /* Alarm diagnostics structure */
92
93    /* Initialize the param to NULLP */
94    *pData = NULLP;
95
96    if (size == 0)
97    {
98       return RFAILED;
99    }
100
101    /* allocate buffer */
102 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
103    MS_BUF_ADD_ALLOC_CALLER();
104 #endif /* */
105    MAC_ALLOC(pData, size);
106    if(pData == NULLP)
107    {
108      dgn.type = LRG_USTA_DGNVAL_MEM;
109      dgn.u.mem.region = rgCb[inst].rgInit.region;
110      dgn.u.mem.pool = rgCb[inst].rgInit.pool;
111      /*  Send an alarm to Layer Manager */
112      rgLMMStaInd(inst,LCM_CATEGORY_RESOURCE, LCM_EVENT_SMEM_ALLOC_FAIL,
113                                        LCM_CAUSE_MEM_ALLOC_FAIL, &dgn);
114       DU_LOG("\nERROR  -->  MAC : Unable to Allocate Buffer");
115       return RFAILED;
116    }
117
118    /* zero out the allocated memory */
119    memset(*pData, 0x00, size);
120
121    return ROK;
122
123 } /* end of rgAllocSBuf */
124
125 /*
126 *
127 *       Fun:   rgFreeSharableSBuf
128 *
129 *       Desc:  The argument to rgFreeSBuf() is a pointer to a block
130 *              previously allocated by rgAllocSBuf() and size. It 
131 *              deallocates the memory. 
132 *
133 *       Ret:   void
134 *
135 *       Notes: ccpu00117052 - MOD- changed the Data parameter from 
136 *                             pointer to address of pointer so that
137 *                             the freed memory could be set to NULLP
138 *
139 *       File:  rg_utl.c
140 */
141 Void rgFreeSharableSBuf
142 (
143 Inst inst,
144 Data **data,         /* address of pointer to data */
145 Size size            /* size */
146 )
147 {
148
149    if ((data == NULLP) || (*data == NULLP) || (size == 0))
150    {
151       return;
152    }
153
154    /* Deallocate buffer */
155    MAC_FREE_SHRABL_BUF(rgCb[inst].rgInit.region, rgCb[inst].rgInit.pool, *data, size);
156    
157    if (data != NULLP)
158    {
159       return;
160    }
161
162    *data = NULLP;
163
164    return;
165
166 } /* end of rgFreeSharableBuf */
167
168
169
170 /*
171 *
172 *       Fun:   rgFreeSBuf
173 *
174 *       Desc:  The argument to rgFreeSBuf() is a pointer to a block
175 *              previously allocated by rgAllocSBuf() and size. It 
176 *              deallocates the memory. 
177 *
178 *       Ret:   void
179 *
180 *       Notes: ccpu00117052 - MOD- changed the Data parameter from 
181 *                             pointer to address of pointer so that
182 *                             the freed memory could be set to NULLP
183 *
184 *       File:  rg_utl.c
185 */
186 Void rgFreeSBuf
187 (
188 Inst inst,
189 Data **data,         /* address of pointer to data */
190 Size size            /* size */
191 )
192 {
193
194    if ((data == NULLP) || (*data == NULLP) || (size == 0))
195    {
196       return;
197    }
198
199
200 #ifdef MS_MBUF_CORRUPTION /* Should be enabled when debugging mbuf corruption */
201    MS_BUF_ADD_CALLER();
202 #endif /* */
203    /* Deallocate buffer */
204    MAC_FREE(data, size);
205
206    if (data != NULLP)
207    {
208       DU_LOG("\nERROR  -->  MAC : rgFreeSBuf failed.\n");
209       return;
210    }
211
212    *data = NULLP;
213
214    return;
215
216 } /* end of rgFreeSBuf */
217
218
219 /***********************************************************
220  *
221  *     Func : rgFillDgnParams
222  *
223  *     Desc : Utility Function to Fill Diagonostic params. 
224  *
225  *     Ret  : None.
226  *
227  *     Notes: None.
228  *
229  *     File : rg_utl.c
230  *
231  **********************************************************/
232 Void rgFillDgnParams
233 (
234 Inst        inst,
235 RgUstaDgn   *dgn,
236 uint8_t     dgnType
237 )
238 {
239
240    switch(dgnType)
241    {
242       case LRG_USTA_DGNVAL_MEM:
243          dgn->type = (uint8_t) LRG_USTA_DGNVAL_MEM;
244          dgn->u.mem.region  = rgCb[inst].rgInit.region;
245          dgn->u.mem.pool    = rgCb[inst].rgInit.pool;
246       break;
247
248       default:
249       break;
250    }
251
252    return;
253 } /* end of rgFillDgnParams */
254
255
256 /**********************************************************************
257  
258          End of file
259 **********************************************************************/