899324e890da14f4ae16cba96bd8188eb62f6993
[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 MAC_MEM_REGION   4
22 #define MAC_POOL         1
23
24 /* allocate and zero out a MAC static buffer */
25 #define MAC_ALLOC(_datPtr, _size)                            \
26 {                                                            \
27    uint8_t _ret;                                             \
28    _ret = SGetSBuf(MAC_MEM_REGION, MAC_POOL,                 \
29          (Data **)&_datPtr, _size);                          \
30    if(_ret == ROK)                                           \
31    {                                                         \
32       cmMemset((uint8_t *)_datPtr, 0, _size);                \
33    }                                                         \
34    else                                                      \
35    {                                                         \
36       _datPtr = NULLP;                                       \
37    }                                                         \
38 }
39
40 /* free a static buffer */
41 #define MAC_FREE(_datPtr, _size)                             \
42 {                                                            \
43    if(_datPtr)                                               \
44    {                                                         \
45       SPutSBuf(MAC_MEM_REGION, MAC_POOL,                     \
46             (Data *)_datPtr, _size);                         \
47    }                                                         \
48 }
49
50 /* Allocate shared memory to be used for LWLC
51  * during inter-layer communication */
52 #define MAC_ALLOC_SHRABL_BUF(_buf, _size)                    \
53 {                                                            \
54    if(SGetStaticBuffer(MAC_MEM_REGION, MAC_POOL,             \
55             (Data **)&_buf, (Size) _size, 0) == ROK)         \
56    {                                                         \
57       cmMemset((uint8_t *)(_buf), 0, _size);                 \
58    }                                                         \
59    else                                                      \
60    {                                                         \
61       (_buf) = NULLP;                                        \
62    }                                                         \
63 }
64
65 /* Free shared memory, received through LWLC */
66 #define MAC_FREE_SHRABL_BUF(_region, _pool,_buf, _size)      \
67 {                                                            \
68    if (_buf != NULLP)                                        \
69    {                                                         \
70       (Void) SPutStaticBuffer(_region, _pool,                \
71             (Data *) _buf, (Size) _size, 0);                 \
72       _buf = NULLP;                                          \
73    }                                                         \
74 }
75
76 /* Fill Pst structure for sending msg from MAC to DU APP */
77 #define FILL_PST_MAC_TO_DUAPP(_pst, _event)                     \
78 {                                                           \
79    _pst.selector  = ODU_SELECTOR_LWLC;                      \
80    _pst.srcEnt    = ENTRG;                                  \
81    _pst.dstEnt    = ENTDUAPP;                               \
82    _pst.dstInst   = 0;                                      \
83    _pst.srcInst   = macCb.macInst;                          \
84    _pst.dstProcId = macCb.procId;                           \
85    _pst.srcProcId = macCb.procId;                           \
86    _pst.region = MAC_MEM_REGION;                            \
87    _pst.pool = MAC_POOL;                                    \
88    _pst.event = _event;                                     \
89    _pst.route = 0;                                          \
90    _pst.prior = 0;                                          \
91    _pst.intfVer = 0;                                        \
92 }
93
94 /* Fill Pst structure for sending msg from MAC to SCH */
95 #define FILL_PST_MAC_TO_SCH(_pst, _event)                       \
96 {                                                           \
97    _pst.selector  = ODU_SELECTOR_TC;                        \
98    _pst.srcEnt    = ENTRG;                                  \
99    _pst.dstEnt    = ENTRG;                                  \
100    _pst.dstInst   = 1;                                      \
101    _pst.srcInst   = macCb.macInst;                          \
102    _pst.dstProcId = macCb.procId;                           \
103    _pst.srcProcId = macCb.procId;                           \
104    _pst.region = MAC_MEM_REGION;                            \
105    _pst.pool = MAC_POOL;                                    \
106    _pst.event = _event;                                     \
107    _pst.route = 0;                                          \
108    _pst.prior = 0;                                          \
109    _pst.intfVer = 0;                                        \
110 }
111
112 /**********************************************************************
113          End of file
114 **********************************************************************/