U8, U16, U32 data type changes
[o-du/l2.git] / src / 5gnrrlc / kw_tenb_stats.c
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 /**********************************************************************
20  
21     Name:  
22  
23     Type:   C include file
24  
25     Desc:   
26  
27     File:  l2_tenb_stats.c
28  
29 **********************************************************************/
30
31 /* header (.h) include files */
32 #include "common_def.h"
33 #include "lkw.h"           /* LKW defines */
34 #include "ckw.h"           /* CKW defines */
35 #include "kwu.h"           /* KWU defines */
36 #include "rgu.h"           /* RGU defines */
37 #include "kw_err.h"        /* RLC error options */
38 #include "kw_env.h"        /* RLC environment options */
39 #include "kw.h"            /* RLC defines */
40 #include "kw_ul.h"
41
42 /* extern (.x) include files */
43 #include "lkw.x"           /* LKW */
44 #include "ckw.x"           /* CKW */
45 #include "kwu.x"           /* KWU */
46 #include "rgu.x"           /* RGU */
47
48 #include "kw.x"
49 #include "kw_ul.x"
50 #ifdef TENB_STATS
51 #include "l2_tenb_stats.x"    /* Total EnodeB Stats declarations */
52 #endif
53
54 #ifdef TENB_STATS
55 TSL2CellStatsCb* l2CellStats[L2_STATS_MAX_CELLS];
56 TSL2UeStatsCb*   l2UeStats[L2_STATS_MAX_UES];
57 CmLListCp        freeL2UeStatsLst; /*!< Free Pool of UE stats Blocks */
58 CmLListCp        inUseL2UeStatsLst;/*!< In Use Pool of UE stats Blocks */
59
60 /*
61 *
62 *       Fun:   TSL2AllocStatsMem
63 *
64 *       Desc:  Pre-Allocate Memory for L2 stats BLOCKs 
65 *
66 *       Ret:   
67 *
68 *       Notes: None
69 *
70 *
71 */
72 #ifdef ANSI
73 Void TSL2AllocStatsMem 
74 (
75  Region region,
76  Pool   pool 
77 )
78 #else
79 Void TSL2AllocStatsMem(region, pool)
80  Region region;
81  Pool   pool;
82 #endif
83 {
84    uint32_t cnt=0;
85
86    cmLListInit(&inUseL2UeStatsLst);     
87    cmLListInit(&freeL2UeStatsLst);      
88    for (cnt=0; cnt < L2_STATS_MAX_CELLS; cnt++)
89    {
90                   if(NULL == l2CellStats[cnt])
91                   {
92                  if (SGetSBuf(region, pool, (Data **)&l2CellStats[cnt],
93                                          (Size)sizeof (TSL2CellStatsCb)) != ROK)
94                  {
95                                 printf("\n STATS Unexpected MEM Alloc Failure\n");
96                  }
97           }
98         memset(l2CellStats[cnt], 0x00, sizeof(TSL2CellStatsCb));
99    }
100
101    for (cnt=0; cnt < L2_STATS_MAX_UES; cnt++)
102    {
103         TSL2UeStatsCb *statsCb = l2UeStats[cnt];
104                   if(NULL == statsCb)
105                   {
106                  if (SGetSBuf(region, pool, (Data **)&statsCb,
107                                          (Size)sizeof (TSL2UeStatsCb)) != ROK)
108                  {
109                                 printf("\n STATS Unexpected MEM Alloc Failure at %d\n", (int)cnt);
110                  }
111                   }
112         memset(statsCb, 0x00, sizeof(TSL2UeStatsCb));
113         statsCb->lnk.node = (PTR)statsCb;
114         cmLListAdd2Tail(&freeL2UeStatsLst, &statsCb->lnk);
115         l2UeStats[cnt] = statsCb;
116    }
117
118    return;
119 }
120
121 /*
122 *
123 *       Fun:   TSL2AllocUeStatsBlk
124 *
125 *       Desc:  Assign Stats Block for this UE[RNTI] 
126 *
127 *       Ret:   
128 *
129 *       Notes: None
130 *
131 *
132 */
133 #ifdef ANSI
134 TSL2UeStatsCb* TSL2AllocUeStatsBlk 
135 (
136  uint16_t   rnti
137 )
138 #else
139 TSL2UeStatsCb* TSL2AllocUeStatsBlk(rnti)
140  uint16_t   rnti;
141 #endif
142 {
143    CmLList          *tmp = NULLP;
144    TSL2UeStatsCb  *statsCb = NULLP;
145
146    tmp = freeL2UeStatsLst.first;
147    if (tmp == NULLP)
148    {
149       printf("\n STATS Unexpected Mem BLK unavailable for UE %d\n", rnti);
150    }
151    cmLListDelFrm(&freeL2UeStatsLst, tmp);
152    statsCb = (TSL2UeStatsCb *)(tmp->node);
153    cmLListAdd2Tail(&inUseL2UeStatsLst, tmp);
154
155    statsCb->stats.rnti = (uint32_t)rnti;
156    statsCb->inUse = TRUE;
157
158    return (statsCb);
159 }
160
161 /*
162 *
163 *       Fun:   TSL2DeallocUeStatsBlk
164 *
165 *       Desc:  Deassign Stats Block for this UE[RNTI] 
166 *
167 *       Ret:   
168 *
169 *       Notes: None
170 *
171 *
172 */
173 #ifdef ANSI
174 Void TSL2DeallocUeStatsBlk 
175 (
176  uint16_t       rnti,
177  TSL2UeStatsCb  *statsCb
178 )
179 #else
180 Void TSL2DeallocUeStatsBlk(rnti, statsCb)
181  uint16_t       rnti;
182  TSL2UeStatsCb  *statsCb;
183 #endif
184 {
185    statsCb->inUse = FALSE;
186    cmLListDelFrm(&inUseL2UeStatsLst, &statsCb->lnk);
187    freeL2UeStatsLst.crnt = freeL2UeStatsLst.first;
188    cmLListInsAfterCrnt(&freeL2UeStatsLst, &statsCb->lnk);
189
190    return;
191 }
192
193 /*
194 *
195 *       Fun:   TSL2AllocCellStatsBlk
196 *
197 *       Desc:  Assign Stats Block for this CELL[CELLID] 
198 *
199 *       Ret:   
200 *
201 *       Notes: None
202 *
203 *
204 */
205 #ifdef ANSI
206 TSL2CellStatsCb* TSL2AllocCellStatsBlk 
207 (
208  uint32_t cellId
209 )
210 #else
211 TSL2CellStatsCb* TSL2AllocCellStatsBlk(cellId)
212  uint32_t cellId;
213 #endif
214 {
215    if (cellId != 1)
216    {
217       printf("\n STATS Unexpected CellID = %d\n", (int)cellId);
218    }
219
220    return (l2CellStats[cellId-1]);
221 }
222
223 /*
224 *
225 *       Fun:   TSL2DeallocCellStatsBlk
226 *
227 *       Desc:  Deassign Stats Block for this CELL[CELLID] 
228 *
229 *       Ret:   
230 *
231 *       Notes: None
232 *
233 *
234 */
235 #ifdef ANSI
236 Void TSL2DeallocCellStatsBlk 
237 (
238  uint32_t cellId
239 )
240 #else
241 Void TSL2DeallocCellStatsBlk(cellId)
242  uint32_t cellId;
243 #endif
244 {
245
246    return;
247 }
248
249 /*
250 *
251 *       Fun:   TSL2SendStatsToApp
252 *
253 *       Desc:  Collates and Sends STATS to Application 
254 *              Send UE STATS first. 10 UEs are grouped in one message.
255 *              Followed by CELL Stats. All CELLS are grouped in one msg.
256 *              At Reception of CELL stats APP assumes STATS reception cycle is complete.
257 *
258 *       Ret:   
259 *
260 *       Notes: None
261 *
262 *
263 */
264 #ifdef ANSI
265 Void TSL2SendStatsToApp
266 (
267  Pst    *pst,
268  SuId   suId
269  )
270 #else
271 Void TSL2SendStatsToApp(pst, suId)
272  Pst    *pst;
273  SuId   suId;
274 #endif
275 {
276    uint32_t idx;
277
278    for (idx = 0; idx < L2_STATS_MAX_UES; idx++)
279    {
280       TSL2UeStatsCb *statsCb = l2UeStats[idx];
281       uint32_t rnti;
282       if (statsCb->inUse != TRUE)
283       {
284          continue;
285       }
286       if (pst->selector == 0)
287       {
288          /* Loose Coupling */
289          TSInfPkSndL2UeStats(pst, suId, &statsCb->stats);
290       }
291       else
292       {
293 #ifdef PX
294          /* Tight Coupling */
295          TSInfHdlL2UeStatsInd(pst, suId, &statsCb->stats);
296 #endif
297       }
298       rnti = statsCb->stats.rnti;
299       memset(&statsCb->stats.nonPersistent, 0x00, sizeof(statsCb->stats.nonPersistent));
300       /* memset(&statsCb->stats, 0x00, sizeof(TSInfL2UeStats)); */
301       statsCb->stats.rnti = rnti;
302    }
303
304    /* Allocate mBuf for CELLSTATS */
305    for (idx = 0; idx < L2_STATS_MAX_CELLS; idx++)
306    {
307       TSL2CellStatsCb *statsCellCb = l2CellStats[idx];
308       uint32_t cellId;
309       if (pst->selector == 0)
310       {
311          /* Loose Coupling */
312          TSInfPkSndL2CellStats(pst, suId, l2CellStats[idx]);
313       }
314       else
315       {
316 #ifdef PX
317          /* Tight Coupling */
318          TSInfHdlL2CellStatsInd(pst, suId, l2CellStats[idx]);
319 #endif
320       }
321       cellId = statsCellCb->cellId;
322       memset(l2CellStats[idx], 0x00, sizeof(TSInfL2CellStats));
323       statsCellCb->cellId = cellId;
324    }
325    return;
326 }
327 #endif /* TENB_STATS */
328 /**********************************************************************
329          End of file
330 **********************************************************************/