[ JIRA Id - ODUHIGH-606 ] Fixing null memory size allocation issue
[o-du/l2.git] / src / du_app / du_utils.h
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 /* Utility definitions to be used in du app */
20
21 /* Memory related configs */
22 #define DU_APP_MEM_REGION    0
23 #define RLC_UL_MEM_REGION    1
24 #define RLC_DL_MEM_REGION    4
25 #define MAC_MEM_REGION       4
26
27 #define DU_POOL  1
28 #define RLC_POOL  1
29 #define MAC_POOL 1
30 #define MAX_SLIV_CONFIG_IDX 105
31
32 /* Events */
33 #define EVTCFG 0
34 #define EVTSCTPSTRT  1
35 #define EVENT_CU_DATA  2
36 #define EVENT_SCTP_NTFY  3
37 #define EVTSRVOPENREQ  4
38 #define EVTSRVOPENCFM  5
39 #define EVTTNLMGMTREQ  6
40 #define EVTTNLMGMTCFM  7
41 #define EVTSLOTIND    8
42 #define EVTSTARTPOLL  9
43 #define EVENT_RIC_DATA  10
44
45 /* allocate and zero out a static buffer */
46
47 #ifdef MEM_SIZE_CHECK
48 #define DU_APP_MEMORY_ALLOC_SIZE_LOG(_line, _func, _size) \
49 {\
50    DU_LOG("\n DUAPP line = %d, func = %s, _size= %d ", _line, _func, _size); \
51 }
52 #else
53 #define DU_APP_MEMORY_ALLOC_SIZE_LOG(_line, _func, _size) {}
54 #endif
55
56
57 #ifdef ODU_MEMORY_DEBUG_LOG
58 #define DU_MEM_LOG(_macro, _file, _line, _func, _size, _datPtr)\
59 {\
60    printf("\n%s,=== %s +%d, %s, %lu, %p \n",           \
61          _macro, _file, _line, _func, (uint64_t)_size, _datPtr); \
62 }
63 #else
64 #define DU_MEM_LOG(_macro, _file, _line, _func, _size, _dataPtr) {}
65 #endif
66
67 #define DU_ALLOC(_datPtr, _size)                                \
68 {                                                               \
69    DU_APP_MEMORY_ALLOC_SIZE_LOG(__LINE__, __FUNCTION__, _size); \
70    int _ret;                                                    \
71    _ret = SGetSBuf(DU_APP_MEM_REGION, DU_POOL,                  \
72                     (Data **)&_datPtr, _size);                  \
73    if(_ret == ROK)     \
74    {\
75       DU_MEM_LOG("DU,ALLOC", __FILE__, __LINE__, __FUNCTION__, _size, _datPtr);\
76       memset(_datPtr, 0, _size);                         \
77    }\
78    else                                                         \
79       _datPtr = NULLP;                                          \
80 }
81
82 /* free a static buffer */
83 #define DU_FREE(_datPtr, _size)                                 \
84 {                                                               \
85    if(_datPtr != NULLP)                                                  \
86    {                                                            \
87       DU_MEM_LOG("DU,FREE", __FILE__, __LINE__, __FUNCTION__, _size, _datPtr);\
88       SPutSBuf(DU_APP_MEM_REGION, DU_POOL,                      \
89          (Data *)_datPtr, _size);                               \
90       _datPtr = NULLP;                                          \
91    }                                                            \
92 }
93 /* Allocate shared memory to be used for LWLC
94  * during inter-layer communication */
95 #define DU_ALLOC_SHRABL_BUF(_buf, _size)                     \
96 {                                                            \
97    DU_APP_MEMORY_ALLOC_SIZE_LOG(__LINE__, __FUNCTION__, _size); \
98    if(SGetStaticBuffer(DU_APP_MEM_REGION, DU_POOL,           \
99       (Data **)&_buf, (Size) _size, 0) == ROK)               \
100    {                                                         \
101       DU_MEM_LOG("DU,ALLOC_SHRABL_BUF", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
102       memset((_buf), 0, _size);                      \
103    }                                                         \
104    else                                                      \
105    {                                                         \
106       (_buf) = NULLP;                                        \
107    }                                                         \
108 }
109
110 /* Free shared memory, received through LWLC */
111 #define DU_FREE_SHRABL_BUF(_region, _pool,_buf, _size)          \
112 {                                                               \
113    if (_buf != NULLP)                                           \
114    {                                                            \
115       DU_MEM_LOG("DU,FREE_SHRABL_BUF", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
116       (Void) SPutStaticBuffer(_region, _pool,                   \
117            (Data *) _buf, (Size) _size, 0);                     \
118        _buf = NULLP;                                            \
119    }                                                            \
120 }
121
122 /* Fill Pst structure for sending msg from DU APP to MAC */
123 #define FILL_PST_DUAPP_TO_MAC(_pst, _event)                 \
124 {                                                           \
125    _pst.selector  = ODU_SELECTOR_LWLC;                      \
126    _pst.srcEnt    = ENTDUAPP;                               \
127    _pst.dstEnt    = ENTMAC;                                  \
128    _pst.dstInst   = 0;                                      \
129    _pst.srcInst   = 0;                                      \
130    _pst.dstProcId = DU_PROC;                                \
131    _pst.srcProcId = DU_PROC;                                \
132    _pst.region = DU_APP_MEM_REGION;                         \
133    _pst.pool = DU_POOL;                                     \
134    _pst.event = _event;                                     \
135    _pst.route = 0;                                          \
136    _pst.prior = 0;                                          \
137    _pst.intfVer = 0;                                        \
138 }
139
140 /* Fill Pst structure for sending msg from DU_APP to RLC */
141 #define FILL_PST_DUAPP_TO_RLC(_pst, _dstInst, _event)       \
142 {                                                           \
143    _pst.selector  = ODU_SELECTOR_LWLC;                      \
144    _pst.srcEnt    = ENTDUAPP;                               \
145    _pst.dstEnt    = ENTRLC;                                  \
146    _pst.dstInst   = _dstInst;                               \
147    _pst.srcInst   = DU_INST;                                \
148    _pst.dstProcId = DU_PROC;                                \
149    _pst.srcProcId = DU_PROC;                                \
150    _pst.region = DU_APP_MEM_REGION;                         \
151    _pst.pool = DU_POOL;                                     \
152    _pst.event = _event;                                     \
153    _pst.route = 0;                                          \
154    _pst.prior = 0;                                          \
155    _pst.intfVer = 0;                                        \
156 }
157
158
159 void fillStartSymbolAndLen(uint8_t numRsrcAlloc, PdschConfig *pdschCfg, PuschCfg *puschCfg);
160 uint8_t duAddNodeToLList(CmLListCp *llist, void *blockToAdd, CmLList *currNode);
161 uint8_t duDelNodeFromLList(CmLListCp *llist, CmLList *node);
162
163 DuPagUeRecord* handlePageUeLL(uint16_t pagUeId, uint64_t sTmsi, CmLListCp *pageUeLL, ActionTypeLL action);
164 DuPagUeList* handlePageInfoLL(uint16_t pf, uint8_t i_s, CmLListCp *pagInfoLL, ActionTypeLL action);
165 DuPagInfoList* findPagingInfoFromMap(uint16_t pf, CmHashListCp *pagingInfoMap);
166 #if 0
167 void printPageList(CmHashListCp *pagingInfoMap);
168 #endif
169
170 /**********************************************************************
171          End of file
172 **********************************************************************/