[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-523] Statistics Indication between DU APP...
[o-du/l2.git] / src / 5gnrmac / mac_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 /* Contains common utility definitions to be used at MAC */
20
21 #define MAX_SHORT_BSR_TABLE_ENTRIES 32
22 #define MAX_LONG_BSR_TABLE_ENTRIES  256
23 #define MAC_MEM_REGION   4
24 #define MAC_POOL         1
25
26 #ifdef ODU_MEMORY_DEBUG_LOG
27 #define MAC_MEM_LOG(_macro, _file, _line, _func, _size, _datPtr)\
28 {\
29    printf("\n%s,=== %s +%d, %s, %lu, %p \n",           \
30          _macro, _file, _line, _func, (uint64_t)_size, _datPtr); \
31 }
32 #else
33 #define MAC_MEM_LOG(_macro, _file, _line, _func, _size, _dataPtr) {}
34 #endif
35
36 /* allocate and zero out a MAC static buffer */
37 #define MAC_ALLOC(_datPtr, _size)                            \
38 {                                                            \
39    uint8_t _ret;                                             \
40    _ret = SGetSBuf(MAC_MEM_REGION, MAC_POOL,                 \
41          (Data **)&_datPtr, _size);                               \
42    if(_ret == ROK)                                           \
43    {                                                         \
44       memset(_datPtr, 0, _size);                             \
45       MAC_MEM_LOG("MAC,ALLOC", __FILE__, __LINE__, __FUNCTION__, _size, _datPtr);\
46    }                                                         \
47    else                                                      \
48    {                                                         \
49       _datPtr = NULLP;                                       \
50    }                                                         \
51 }
52
53 /* free a static buffer */
54 #define MAC_FREE(_datPtr, _size)                             \
55 {                                                            \
56    if(_datPtr)                                               \
57    {                                                         \
58       MAC_MEM_LOG("MAC,FREE", __FILE__, __LINE__, __FUNCTION__, _size, _datPtr);\
59       SPutSBuf(MAC_MEM_REGION, MAC_POOL,                     \
60             (Data *)_datPtr, _size);                              \
61       _datPtr = NULLP;                                       \
62    }                                                         \
63 }
64
65 /* Allocate shared memory to be used for LWLC
66  * during inter-layer communication */
67 #define MAC_ALLOC_SHRABL_BUF(_buf, _size)                    \
68 {                                                            \
69    if(SGetStaticBuffer(MAC_MEM_REGION, MAC_POOL,             \
70             (Data **)&_buf, (Size) _size, 0) == ROK)              \
71    {                                                         \
72       MAC_MEM_LOG("MAC,ALLOC_SHRABL_BUF", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
73       memset((_buf), 0, _size);                              \
74    }                                                         \
75    else                                                      \
76    {                                                         \
77       (_buf) = NULLP;                                        \
78    }                                                         \
79 }
80
81 /* Free shared memory, received through LWLC */
82 #define MAC_FREE_SHRABL_BUF(_region, _pool,_buf, _size)      \
83 {                                                            \
84    if (_buf != NULLP)                                        \
85    {                                                         \
86       MAC_MEM_LOG("MAC,FREE_SHRABL_BUF", __FILE__, __LINE__, __FUNCTION__, _size, _buf);\
87       (Void) SPutStaticBuffer(_region, _pool,                \
88             (Data *) _buf, (Size) _size, 0);                 \
89       _buf = NULLP;                                          \
90    }                                                         \
91 }
92
93 /* Fill Pst structure for sending msg from MAC to DU APP */
94 #define FILL_PST_MAC_TO_DUAPP(_pst, _event)                     \
95 {                                                           \
96    _pst.selector  = ODU_SELECTOR_LWLC;                      \
97    _pst.srcEnt    = ENTMAC;                                  \
98    _pst.dstEnt    = ENTDUAPP;                               \
99    _pst.dstInst   = 0;                                      \
100    _pst.srcInst   = macCb.macInst;                          \
101    _pst.dstProcId = macCb.procId;                           \
102    _pst.srcProcId = macCb.procId;                           \
103    _pst.region = MAC_MEM_REGION;                            \
104    _pst.pool = MAC_POOL;                                    \
105    _pst.event = _event;                                     \
106    _pst.route = 0;                                          \
107    _pst.prior = 0;                                          \
108    _pst.intfVer = 0;                                        \
109 }
110
111 /* Fill Pst structure for sending msg from MAC to SCH */
112 #define FILL_PST_MAC_TO_SCH(_pst, _event)                       \
113 {                                                           \
114    _pst.selector  = ODU_SELECTOR_TC;                        \
115    _pst.srcEnt    = ENTMAC;                                  \
116    _pst.dstEnt    = ENTMAC;                                  \
117    _pst.dstInst   = 1;                                      \
118    _pst.srcInst   = macCb.macInst;                          \
119    _pst.dstProcId = macCb.procId;                           \
120    _pst.srcProcId = macCb.procId;                           \
121    _pst.region = MAC_MEM_REGION;                            \
122    _pst.pool = MAC_POOL;                                    \
123    _pst.event = _event;                                     \
124    _pst.route = 0;                                          \
125    _pst.prior = 0;                                          \
126    _pst.intfVer = 0;                                        \
127 }
128
129 /* Fills Pst to send msg to RLC */
130 #define FILL_PST_MAC_TO_RLC(_pst, _dstInst, _event)        \
131 {                                                      \
132    pst.selector  = ODU_SELECTOR_LWLC;                  \
133    pst.srcEnt    = ENTMAC;                              \
134    pst.dstEnt    = ENTRLC;                              \
135    pst.dstInst   = _dstInst;                           \
136    pst.srcInst   = macCb.macInst;                      \
137    pst.dstProcId = macCb.procId;                       \
138    pst.srcProcId = macCb.procId;                       \
139    pst.region    = MAC_MEM_REGION;                     \
140    pst.pool      = MAC_POOL;                           \
141    pst.event     = _event;                             \
142    pst.route     = 0;                                  \
143    pst.prior     = 0;                                  \
144    pst.intfVer   = 0;                                  \
145 }
146
147 /* Function declaration */
148 uint32_t shortBsrBytesTable[MAX_SHORT_BSR_TABLE_ENTRIES];
149 uint32_t longBsrBytesTable[MAX_LONG_BSR_TABLE_ENTRIES];
150
151 /**********************************************************************
152          End of file
153 **********************************************************************/