JIRA ID:[ODUHIGH-259, ODUHIGH-260]
[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 MAC_MEM_REGION   4
23 #define MAC_POOL         1
24
25 /* allocate and zero out a MAC static buffer */
26 #define MAC_ALLOC(_datPtr, _size)                            \
27 {                                                            \
28    uint8_t _ret;                                             \
29    _ret = SGetSBuf(MAC_MEM_REGION, MAC_POOL,                 \
30          (Data **)&_datPtr, _size);                          \
31    if(_ret == ROK)                                           \
32    {                                                         \
33       memset(_datPtr, 0, _size);                \
34    }                                                         \
35    else                                                      \
36    {                                                         \
37       _datPtr = NULLP;                                       \
38    }                                                         \
39 }
40
41 /* free a static buffer */
42 #define MAC_FREE(_datPtr, _size)                             \
43 {                                                            \
44    if(_datPtr)                                               \
45    {                                                         \
46       SPutSBuf(MAC_MEM_REGION, MAC_POOL,                     \
47             (Data *)_datPtr, _size);                         \
48       _datPtr = NULLP;                                      \
49    }                                                         \
50 }
51
52 /* Allocate shared memory to be used for LWLC
53  * during inter-layer communication */
54 #define MAC_ALLOC_SHRABL_BUF(_buf, _size)                    \
55 {                                                            \
56    if(SGetStaticBuffer(MAC_MEM_REGION, MAC_POOL,             \
57             (Data **)&_buf, (Size) _size, 0) == ROK)         \
58    {                                                         \
59       memset((_buf), 0, _size);                 \
60    }                                                         \
61    else                                                      \
62    {                                                         \
63       (_buf) = NULLP;                                        \
64    }                                                         \
65 }
66
67 /* Free shared memory, received through LWLC */
68 #define MAC_FREE_SHRABL_BUF(_region, _pool,_buf, _size)      \
69 {                                                            \
70    if (_buf != NULLP)                                        \
71    {                                                         \
72       (Void) SPutStaticBuffer(_region, _pool,                \
73             (Data *) _buf, (Size) _size, 0);                 \
74       _buf = NULLP;                                          \
75    }                                                         \
76 }
77
78 /* Fill Pst structure for sending msg from MAC to DU APP */
79 #define FILL_PST_MAC_TO_DUAPP(_pst, _event)                     \
80 {                                                           \
81    _pst.selector  = ODU_SELECTOR_LWLC;                      \
82    _pst.srcEnt    = ENTMAC;                                  \
83    _pst.dstEnt    = ENTDUAPP;                               \
84    _pst.dstInst   = 0;                                      \
85    _pst.srcInst   = macCb.macInst;                          \
86    _pst.dstProcId = macCb.procId;                           \
87    _pst.srcProcId = macCb.procId;                           \
88    _pst.region = MAC_MEM_REGION;                            \
89    _pst.pool = MAC_POOL;                                    \
90    _pst.event = _event;                                     \
91    _pst.route = 0;                                          \
92    _pst.prior = 0;                                          \
93    _pst.intfVer = 0;                                        \
94 }
95
96 /* Fill Pst structure for sending msg from MAC to SCH */
97 #define FILL_PST_MAC_TO_SCH(_pst, _event)                       \
98 {                                                           \
99    _pst.selector  = ODU_SELECTOR_TC;                        \
100    _pst.srcEnt    = ENTMAC;                                  \
101    _pst.dstEnt    = ENTMAC;                                  \
102    _pst.dstInst   = 1;                                      \
103    _pst.srcInst   = macCb.macInst;                          \
104    _pst.dstProcId = macCb.procId;                           \
105    _pst.srcProcId = macCb.procId;                           \
106    _pst.region = MAC_MEM_REGION;                            \
107    _pst.pool = MAC_POOL;                                    \
108    _pst.event = _event;                                     \
109    _pst.route = 0;                                          \
110    _pst.prior = 0;                                          \
111    _pst.intfVer = 0;                                        \
112 }
113
114 /* Fills Pst to send msg to RLC */
115 #define FILL_PST_MAC_TO_RLC(_pst, _dstInst, _event)        \
116 {                                                      \
117    pst.selector  = ODU_SELECTOR_LWLC;                  \
118    pst.srcEnt    = ENTMAC;                              \
119    pst.dstEnt    = ENTRLC;                              \
120    pst.dstInst   = _dstInst;                           \
121    pst.srcInst   = macCb.macInst;                      \
122    pst.dstProcId = macCb.procId;                       \
123    pst.srcProcId = macCb.procId;                       \
124    pst.region    = MAC_MEM_REGION;                     \
125    pst.pool      = MAC_POOL;                           \
126    pst.event     = _event;                             \
127    pst.route     = 0;                                  \
128    pst.prior     = 0;                                  \
129    pst.intfVer   = 0;                                  \
130 }
131
132 /* Function declaration */
133 uint16_t getNewCrnti(uint8_t *crntiMap);
134 uint32_t shortBsrBytesTable[MAX_SHORT_BSR_TABLE_ENTRIES];
135 /**********************************************************************
136          End of file
137 **********************************************************************/