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