U8, U16, U32 data type changes
[o-du/l2.git] / src / cm / cm_lte.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:     Common LTE
22   
23      Type:     C source file
24   
25      Desc:     C code for packing/unpacking of cm_lte data structures. 
26   
27      File:     cm_lte.c 
28   
29 **********************************************************************/
30
31 /* header include files (.h) */
32
33 #include "envopt.h"             /* environment options */  
34 #include "envdep.h"             /* environment dependent */
35 #include "envind.h"             /* environment independent */
36
37 /* header/extern include files (.x) */
38
39 #include "gen.h"           /* general layer */
40 #include "ssi.h"           /* system services */
41 #include "cm_lte.h"             /* common lte header file */
42 #include "cm5.h"           /* common timers */
43 #include "mt_ss.h"         /* MTSS specific */
44 #include "mt_err.h"        /* MTSS error defines */
45 #include "ss_queue.h"      /* queues */
46 #include "ss_task.h"       /* tasking */
47 #include "ss_msg.h"        /* messaging */
48 #include "ss_mem.h"        /* memory management interface */
49 #include "ss_gen.h"        /* general */
50 /* mt003.301 Additions - Task deregistration */
51 #include "ss_err.h"        /* error */
52
53
54 /* header/extern include files (.x) */
55
56 #include "gen.x"           /* general layer */
57 #include "ssi.x"           /* system services */
58 #include "cm_lte.x"             /* common lte header file */
59 #include "cm5.x"           /* common timers */
60 #include "mt_ss.x"         /* MTSS specific */
61 #include "ss_queue.x"      /* queues */
62 #include "ss_task.x"       /* tasking */
63 #include "ss_timer.x"      /* timers */
64 #include "ss_strm.h"
65 #include "ss_strm.x"       /* STREAMS */
66 #include "ss_msg.x"        /* messaging */
67 #include "ss_mem.x"        /* memory management interface */
68 #include "ss_drvr.x"       /* driver tasks */
69 #include "ss_gen.x"        /* general */
70
71
72 /* public variable declarations */
73 uint32_t cmLteTime;
74
75 \f
76 /***********************************************************
77 *
78 *     Func : cmPkLteRlcId
79 *
80 *
81 *     Desc : RLC Identifier
82 *
83 *
84 *     Ret  : S16
85 *
86 *     Notes:
87 *
88 *     File  : 
89 *
90 **********************************************************/
91 #ifdef ANSI
92 S16 cmPkLteRlcId
93 (
94 CmLteRlcId *param,
95 Buffer *mBuf
96 )
97 #else
98 S16 cmPkLteRlcId(param, mBuf)
99 CmLteRlcId *param;
100 Buffer *mBuf;
101 #endif
102 {
103
104
105    CMCHKPK(cmPkLteCellId, param->cellId, mBuf);
106    CMCHKPK(cmPkLteRnti, param->ueId, mBuf);
107    CMCHKPK(oduUnpackUInt8, param->rbType, mBuf);
108    CMCHKPK(cmPkLteRbId, param->rbId, mBuf);
109    return ROK;
110 }
111
112
113 \f
114 /***********************************************************
115 *
116 *     Func : cmUnpkLteRlcId
117 *
118 *
119 *     Desc : RLC Identifier
120 *
121 *
122 *     Ret  : S16
123 *
124 *     Notes:
125 *
126 *     File  : 
127 *
128 **********************************************************/
129 #ifdef ANSI
130 S16 cmUnpkLteRlcId
131 (
132 CmLteRlcId *param,
133 Buffer *mBuf
134 )
135 #else
136 S16 cmUnpkLteRlcId(param, mBuf)
137 CmLteRlcId *param;
138 Buffer *mBuf;
139 #endif
140 {
141
142
143    CMCHKUNPK(cmUnpkLteRbId, &param->rbId, mBuf);
144    CMCHKUNPK(oduPackUInt8, &param->rbType, mBuf);
145    CMCHKUNPK(cmUnpkLteRnti, &param->ueId, mBuf);
146    CMCHKUNPK(cmUnpkLteCellId, &param->cellId, mBuf);
147    return ROK;
148 }
149
150
151 \f
152 /***********************************************************
153 *
154 *     Func : cmPkLteTimingInfo
155 *
156 *
157 *     Desc : LTE Timing Info
158 *
159 *
160 *     Ret  : S16
161 *
162 *     Notes:
163 *
164 *     File  : 
165 *
166 **********************************************************/
167 #ifdef ANSI
168 S16 cmPkLteTimingInfo
169 (
170 CmLteTimingInfo *param,
171 Buffer *mBuf
172 )
173 #else
174 S16 cmPkLteTimingInfo(param, mBuf)
175 CmLteTimingInfo *param;
176 Buffer *mBuf;
177 #endif
178 {
179
180
181    CMCHKPK(oduUnpackUInt16, param->slot, mBuf);
182    CMCHKPK(oduUnpackUInt16, param->sfn, mBuf);
183    //CMCHKPK(oduUnpackUInt16, param->hSfn, mBuf);
184    return ROK;
185 }
186
187
188 \f
189 /***********************************************************
190 *
191 *     Func : cmUnpkLteTimingInfo
192 *
193 *
194 *     Desc : LTE Timing Info
195 *
196 *
197 *     Ret  : S16
198 *
199 *     Notes:
200 *
201 *     File  : 
202 *
203 **********************************************************/
204 #ifdef ANSI
205 S16 cmUnpkLteTimingInfo
206 (
207 CmLteTimingInfo *param,
208 Buffer *mBuf
209 )
210 #else
211 S16 cmUnpkLteTimingInfo(param, mBuf)
212 CmLteTimingInfo *param;
213 Buffer *mBuf;
214 #endif
215 {
216
217
218    //CMCHKUNPK(oduPackUInt16, &param->hSfn, mBuf);
219    CMCHKUNPK(oduPackUInt16, &param->sfn, mBuf);
220    CMCHKUNPK(oduPackUInt16,&param->slot, mBuf);
221    return ROK;
222 }
223
224
225 \f
226 /***********************************************************
227 *
228 *     Func : cmPkLtePdcpId
229 *
230 *
231 *     Desc : PDCP Id
232 *
233 *
234 *     Ret  : S16
235 *
236 *     Notes:
237 *
238 *     File  : 
239 *
240 **********************************************************/
241 #ifdef ANSI
242 S16 cmPkLtePdcpId
243 (
244 CmLtePdcpId *param,
245 Buffer *mBuf
246 )
247 #else
248 S16 cmPkLtePdcpId(param, mBuf)
249 CmLtePdcpId *param;
250 Buffer *mBuf;
251 #endif
252 {
253
254
255    CMCHKPK(oduUnpackUInt8, param->rbType, mBuf);
256    CMCHKPK(cmPkLteRbId, param->rbId, mBuf);
257    CMCHKPK(cmPkLteRnti, param->ueId, mBuf);
258    CMCHKPK(cmPkLteCellId, param->cellId, mBuf);
259    return ROK;
260 }
261
262
263 \f
264 /***********************************************************
265 *
266 *     Func : cmUnpkLtePdcpId
267 *
268 *
269 *     Desc : PDCP Id
270 *
271 *
272 *     Ret  : S16
273 *
274 *     Notes:
275 *
276 *     File  : 
277 *
278 **********************************************************/
279 #ifdef ANSI
280 S16 cmUnpkLtePdcpId
281 (
282 CmLtePdcpId *param,
283 Buffer *mBuf
284 )
285 #else
286 S16 cmUnpkLtePdcpId(param, mBuf)
287 CmLtePdcpId *param;
288 Buffer *mBuf;
289 #endif
290 {
291
292
293    CMCHKUNPK(cmUnpkLteCellId, &param->cellId, mBuf);
294    CMCHKUNPK(cmUnpkLteRnti, &param->ueId, mBuf);
295    CMCHKUNPK(cmUnpkLteRbId, &param->rbId, mBuf);
296    CMCHKUNPK(oduPackUInt8, &param->rbType, mBuf);
297    return ROK;
298 }
299 #ifdef LTE_L2_MEAS 
300 #ifdef ANSI
301 S16 cmUpdateSsiMemInfo
302 (
303 CmLteMemInfo *mInfo
304 )
305 #else
306 S16 cmUpdateSsiMemInfo(mInfo)
307 CmLteMemInfo *mInfo;
308 #endif
309 {
310    uint8_t   numReg = 0;
311    uint8_t   numPool = 0;
312    uint8_t   idxReg;
313    uint8_t   idxPool;
314    SsMemDbgInfo dbgInfo;
315
316    SGetRegPoolInfo(&numReg,&numPool); 
317    mInfo->numRegions = numReg;
318
319    for(idxReg=0; idxReg< numReg; idxReg++)
320    {
321       SGetRegInfo(idxReg, &dbgInfo);
322
323       if(mInfo->regInfo[idxReg].isGenMemInfoUpdated == TRUE)
324       {
325          for(idxPool=0; idxPool<numPool; idxPool++)
326          {
327             mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = dbgInfo.bktDbgTbl[idxPool].numAlloc;
328             if(mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed > mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed)
329                mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed = mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed;
330          }
331       }
332       else
333       {
334       mInfo->regInfo[idxReg].numPools = numPool;
335       mInfo->regInfo[idxReg].regionId = idxReg;
336       mInfo->regInfo[idxReg].regionType = 0;
337
338       for(idxPool=0; idxPool<numPool; idxPool++)
339       {
340          mInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable = dbgInfo.bktDbgTbl[idxPool].numBlks;
341          mInfo->regInfo[idxReg].poolInfo[idxPool].poolSize = dbgInfo.bktDbgTbl[idxPool].size;
342          mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = dbgInfo.bktDbgTbl[idxPool].numAlloc;
343          if(mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed > mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed)
344             mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed = mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed;
345       }
346          mInfo->regInfo[idxReg].isGenMemInfoUpdated = TRUE; 
347       }
348    }
349    return ROK;
350 }
351
352 #ifdef ANSI
353 S16 cmFillMemUtilizationMeas
354 (
355  CmLteMemInfo *memoryInfo,
356 CmLteMemInfo *memInfo
357 )
358 #else
359 S16 cmFillMemUtilizationMeas(memoryInfo,memInfo)
360 CmLteMemInfo *memoryInfo;
361 CmLteMemInfo *memInfo;
362 #endif
363 {
364    uint8_t idxReg = 0;
365    uint8_t idxPool = 0;
366    uint8_t numPool = 0;
367
368    memoryInfo->numRegions = memInfo->numRegions;
369    for(idxReg=0; idxReg < memInfo->numRegions; idxReg++)
370    {
371       memoryInfo->regInfo[idxReg].regionId = memInfo->regInfo[idxReg].regionId;
372       memoryInfo->regInfo[idxReg].numPools = memInfo->regInfo[idxReg].numPools;
373       memoryInfo->regInfo[idxReg].regionType = memInfo->regInfo[idxReg].regionType;
374       numPool = memoryInfo->regInfo[idxReg].numPools;
375
376       for(idxPool=0; idxPool < numPool; idxPool++)
377       {
378          memoryInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable = memInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable;
379          memoryInfo->regInfo[idxReg].poolInfo[idxPool].poolSize = memInfo->regInfo[idxReg].poolInfo[idxPool].poolSize;
380          memoryInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = memInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed;
381          memoryInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed  = memInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed;
382       }
383    }
384    return ROK;
385 }
386
387 #ifdef ANSI
388 S16 cmClearMemUtilizationCounter
389 (
390 CmLteMemInfo *memInfo
391 )
392 #else
393 S16 cmClearMemUtilizationCounter(memInfo)
394 CmLteMemInfo *memInfo;
395 #endif
396 {
397    uint8_t idxReg = 0;
398    uint8_t idxPool = 0;
399    uint8_t numPool = 0;
400    for(idxReg=0; idxReg < memInfo->numRegions; idxReg++)
401    {
402       memInfo->regInfo[idxReg].regionId = 0;
403       memInfo->regInfo[idxReg].numPools = 0;
404       memInfo->regInfo[idxReg].regionType = 0;
405       memInfo->regInfo[idxReg].isGenMemInfoUpdated = FALSE;
406       numPool = memInfo->regInfo[idxReg].numPools;
407
408       for(idxPool=0; idxPool<numPool; idxPool++)
409       {
410          memInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable = 0;
411          memInfo->regInfo[idxReg].poolInfo[idxPool].poolSize = 0;
412          memInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = 0;
413          memInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed  = 0;
414       }
415    }
416    return ROK;
417 }
418
419 #ifdef ANSI
420 S16 cmClearCpuUtilizationCounter
421 (
422 CmCpuStatsInfo *cpuInfo
423 )
424 #else
425 S16 cmClearCpuUtilizationCounter(cpuInfo)
426 CmCpuStatsInfo *cpuInfo
427 #endif
428 {
429    uint8_t idx= 0;
430    for(idx=0; idx < cpuInfo->numCores; idx++)
431    {
432       cpuInfo->cpuUtil[idx].maxCpuUtil = 0;
433       cpuInfo->cpuUtil[idx].totCpuUtil = 0;
434       cpuInfo->cpuUtil[idx].numSamples = 0;
435    }
436    cpuInfo->numCores = 0;
437    return ROK;
438 }
439
440 #ifdef ANSI
441 S16 cmFillCpuUtilizationMeas
442 (
443 CmLteCpuInfo *cpuMeasInfo,
444 CmCpuStatsInfo *cpuInfo
445 )
446 #else
447 S16 cmFillCpuUtilizationMeas(cpuMeasInfo,cpuInfo)
448 CmLteCpuInfo *cpuMeasInfo;
449 CmCpuStatsInfo *cpuInfo;
450 #endif
451 {
452    uint8_t idx= 0;
453    cpuMeasInfo->numCores = cpuInfo->numCores;
454    for(idx=0; idx < cpuInfo->numCores; idx++)
455    {
456       cpuMeasInfo->cpuUtil[idx].avgCpuUtil = cpuInfo->cpuUtil[idx].totCpuUtil/cpuInfo->cpuUtil[idx].numSamples;
457       cpuMeasInfo->cpuUtil[idx].maxCpuUtil = cpuInfo->cpuUtil[idx].maxCpuUtil;
458    }
459    return ROK;
460
461 }
462 #endif
463
464 #ifdef TENB_TTI_PERF
465 CmTtiProc ttiProc;
466 #define TTI_1MS 950
467
468 Void cmUpdateTtiCounters(uint32_t ttiProcessingTime)
469 {
470    ttiProc.numOfTti++;
471    ttiProc.totTtiProcessingTime += ttiProcessingTime;
472    if(ttiProcessingTime > ttiProc.maxTtiProcessingTime)  
473    {
474       ttiProc.maxTtiProcessingTime = ttiProcessingTime;
475    }
476    if(ttiProcessingTime > TTI_THRESHOLD_VALUE)
477    {
478       ttiProc.ttiThresholdExceedCount++;
479    }
480    if(ttiProcessingTime > TTI_1MS)
481    {
482       ttiProc.ttiStretchCount++;
483    }
484    return;    
485 }
486
487 Void cmResetTtiCounters(Void)
488 {
489         ttiProc.totTtiProcessingTime = 0;
490         ttiProc.numOfTti = 0;
491         ttiProc.maxTtiProcessingTime = 0;
492         ttiProc.ttiStretchCount = 0;
493         ttiProc.ttiThresholdExceedCount = 0;
494         ttiProc.phyReptTtiStretchCount = 0;
495         return;
496 }
497 #endif
498
499 /**********************************************************************
500          End of file
501 **********************************************************************/