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