[ JIRA Id - ODUHIGH-606 ] Fixing null memory size allocation issue
[o-du/l2.git] / src / 5gnrmac / lwr_mac_phy.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 #ifndef _LWR_MAC_PHY_H_
19 #define _LWR_MAC_PHY_H_
20
21
22 typedef enum
23 {
24    MSG_OK,
25    MSG_INVALID_STATE,
26    MSG_INVALID_CONFIG,
27    SFN_OUT_OF_SYNC,
28    MSG_SLOT_ERR,
29    MSG_BCH_MISSING,
30    MSG_INVALID_SFN,
31    MSG_UL_DCI_ERR,
32    MSG_TX_ERR
33 }ErrorCode;
34
35 #ifdef MEM_SIZE_CHECK
36 #define WLS_MEMORY_ALLOC_SIZE_LOG(_line, _func, _size) \
37 {\
38    DU_LOG("\nRLC line = %d, func = %s, _size= %d ", _line, _func, _size); \
39 }
40 #else
41 #define WLS_MEMORY_ALLOC_SIZE_LOG(_line, _func, _size) {}
42 #endif
43
44 #ifdef ODU_MEMORY_DEBUG_LOG
45 #define WLS_MEM_LOG(_macro, _file, _line, _func, _size, _datPtr)\
46 {\
47    printf("\n%s=== %s +%d, %s, %lu, %p \n",           \
48       _macro, _file, _line, _func, (uint64_t)_size, _datPtr); \
49 }
50 #else
51 #define WLS_MEM_LOG(_macro, _file, _line, _func, _size, _datPtr) \
52 {\
53 }
54 #endif
55
56 #ifdef INTEL_WLS_MEM
57 #define LWR_MAC_WLS_BUF_SIZE   32000      /* Size of WLS memory block */
58 #define EVT_START_WLS_RCVR     1
59
60 /* allocate static buffer from WLS memory */
61 #define WLS_MEM_ALLOC(_datPtr, _size)                        \
62 {                                                            \
63    WLS_MEMORY_ALLOC_SIZE_LOG(__LINE__, __FUNCTION__, _size);  \
64    uint8_t _ret;                                             \
65    _ret = SGetSBufWls(0, 0, (Data **)&_datPtr, _size);       \
66    if(_ret == ROK)                                           \
67    {\
68       WLS_MEM_LOG("WLSMEM_ALLOC", __FILE__, __LINE__, __FUNCTION__, _size, _datPtr);\
69       memset(_datPtr, 0, _size);                             \
70    }\
71    else                                                      \
72       _datPtr = NULLP;                                       \
73 }                                                              
74
75 /* free a static buffer from WLS memory*/
76 #define WLS_MEM_FREE(_datPtr, _size)                         \
77    if(_datPtr)                                               \
78    {                                                         \
79       WLS_MEM_LOG("WLSMEM_FREE", __FILE__, __LINE__, __FUNCTION__, _size, _datPtr);\
80       SPutSBufWls(0, 0, (Data *)_datPtr, _size);             \
81       _datPtr = NULLP;                                       \
82    }
83
84 typedef struct wlsBlockToFree
85 {
86    void     *ptr;
87    uint32_t size;
88 }WlsBlockToFree;
89
90 extern CmLListCp wlsBlockToFreeList[WLS_MEM_FREE_PRD];
91
92 void addWlsBlockToFree(void *msg, uint32_t msgLen, uint8_t idx);
93 void freeWlsBlockList(uint8_t idx);
94 void LwrMacEnqueueWlsBlock();
95 void LwrMacRecvPhyMsg();
96 void LwrMacStartWlsRcvr();
97 #endif /* INTEL_WLS_MEM */
98
99 uint8_t LwrMacSendToL1(void *msg);
100 #endif
101
102 /**********************************************************************
103   End of file
104  **********************************************************************/
105