Added code for MAC-PHY interface, DU_APP, F1AP, SCTP and CU stub
[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 PUBLIC U32 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 PUBLIC S16 cmPkLteRlcId
93 (
94 CmLteRlcId *param,
95 Buffer *mBuf
96 )
97 #else
98 PUBLIC S16 cmPkLteRlcId(param, mBuf)
99 CmLteRlcId *param;
100 Buffer *mBuf;
101 #endif
102 {
103
104    TRC3(cmPkLteRlcId);
105
106    CMCHKPK(cmPkLteCellId, param->cellId, mBuf);
107    CMCHKPK(cmPkLteRnti, param->ueId, mBuf);
108    CMCHKPK(SPkU8, param->rbType, mBuf);
109    CMCHKPK(cmPkLteRbId, param->rbId, mBuf);
110    RETVALUE(ROK);
111 }
112
113
114 \f
115 /***********************************************************
116 *
117 *     Func : cmUnpkLteRlcId
118 *
119 *
120 *     Desc : RLC Identifier
121 *
122 *
123 *     Ret  : S16
124 *
125 *     Notes:
126 *
127 *     File  : 
128 *
129 **********************************************************/
130 #ifdef ANSI
131 PUBLIC S16 cmUnpkLteRlcId
132 (
133 CmLteRlcId *param,
134 Buffer *mBuf
135 )
136 #else
137 PUBLIC S16 cmUnpkLteRlcId(param, mBuf)
138 CmLteRlcId *param;
139 Buffer *mBuf;
140 #endif
141 {
142
143    TRC3(cmUnpkLteRlcId);
144
145    CMCHKUNPK(cmUnpkLteRbId, &param->rbId, mBuf);
146    CMCHKUNPK(SUnpkU8, &param->rbType, mBuf);
147    CMCHKUNPK(cmUnpkLteRnti, &param->ueId, mBuf);
148    CMCHKUNPK(cmUnpkLteCellId, &param->cellId, mBuf);
149    RETVALUE(ROK);
150 }
151
152
153 \f
154 /***********************************************************
155 *
156 *     Func : cmPkLteTimingInfo
157 *
158 *
159 *     Desc : LTE Timing Info
160 *
161 *
162 *     Ret  : S16
163 *
164 *     Notes:
165 *
166 *     File  : 
167 *
168 **********************************************************/
169 #ifdef ANSI
170 PUBLIC S16 cmPkLteTimingInfo
171 (
172 CmLteTimingInfo *param,
173 Buffer *mBuf
174 )
175 #else
176 PUBLIC S16 cmPkLteTimingInfo(param, mBuf)
177 CmLteTimingInfo *param;
178 Buffer *mBuf;
179 #endif
180 {
181
182    TRC3(cmPkLteTimingInfo);
183
184    CMCHKPK(SPkU8, param->subframe, mBuf);
185    CMCHKPK(SPkU16, param->sfn, mBuf);
186    CMCHKPK(SPkU16, param->hSfn, mBuf);
187    RETVALUE(ROK);
188 }
189
190
191 \f
192 /***********************************************************
193 *
194 *     Func : cmUnpkLteTimingInfo
195 *
196 *
197 *     Desc : LTE Timing Info
198 *
199 *
200 *     Ret  : S16
201 *
202 *     Notes:
203 *
204 *     File  : 
205 *
206 **********************************************************/
207 #ifdef ANSI
208 PUBLIC S16 cmUnpkLteTimingInfo
209 (
210 CmLteTimingInfo *param,
211 Buffer *mBuf
212 )
213 #else
214 PUBLIC S16 cmUnpkLteTimingInfo(param, mBuf)
215 CmLteTimingInfo *param;
216 Buffer *mBuf;
217 #endif
218 {
219
220    TRC3(cmUnpkLteTimingInfo);
221
222    CMCHKUNPK(SUnpkU16, &param->hSfn, mBuf);
223    CMCHKUNPK(SUnpkU16, &param->sfn, mBuf);
224    CMCHKUNPK(SUnpkU8, &param->subframe, mBuf);
225    RETVALUE(ROK);
226 }
227
228
229 \f
230 /***********************************************************
231 *
232 *     Func : cmPkLtePdcpId
233 *
234 *
235 *     Desc : PDCP Id
236 *
237 *
238 *     Ret  : S16
239 *
240 *     Notes:
241 *
242 *     File  : 
243 *
244 **********************************************************/
245 #ifdef ANSI
246 PUBLIC S16 cmPkLtePdcpId
247 (
248 CmLtePdcpId *param,
249 Buffer *mBuf
250 )
251 #else
252 PUBLIC S16 cmPkLtePdcpId(param, mBuf)
253 CmLtePdcpId *param;
254 Buffer *mBuf;
255 #endif
256 {
257
258    TRC3(cmPkLtePdcpId);
259
260    CMCHKPK(SPkU8, param->rbType, mBuf);
261    CMCHKPK(cmPkLteRbId, param->rbId, mBuf);
262    CMCHKPK(cmPkLteRnti, param->ueId, mBuf);
263    CMCHKPK(cmPkLteCellId, param->cellId, mBuf);
264    RETVALUE(ROK);
265 }
266
267
268 \f
269 /***********************************************************
270 *
271 *     Func : cmUnpkLtePdcpId
272 *
273 *
274 *     Desc : PDCP Id
275 *
276 *
277 *     Ret  : S16
278 *
279 *     Notes:
280 *
281 *     File  : 
282 *
283 **********************************************************/
284 #ifdef ANSI
285 PUBLIC S16 cmUnpkLtePdcpId
286 (
287 CmLtePdcpId *param,
288 Buffer *mBuf
289 )
290 #else
291 PUBLIC S16 cmUnpkLtePdcpId(param, mBuf)
292 CmLtePdcpId *param;
293 Buffer *mBuf;
294 #endif
295 {
296
297    TRC3(cmUnpkLtePdcpId);
298
299    CMCHKUNPK(cmUnpkLteCellId, &param->cellId, mBuf);
300    CMCHKUNPK(cmUnpkLteRnti, &param->ueId, mBuf);
301    CMCHKUNPK(cmUnpkLteRbId, &param->rbId, mBuf);
302    CMCHKUNPK(SUnpkU8, &param->rbType, mBuf);
303    RETVALUE(ROK);
304 }
305 #ifdef LTE_L2_MEAS 
306 #ifdef ANSI
307 PUBLIC S16 cmUpdateSsiMemInfo
308 (
309 CmLteMemInfo *mInfo
310 )
311 #else
312 PUBLIC S16 cmUpdateSsiMemInfo(mInfo)
313 CmLteMemInfo *mInfo;
314 #endif
315 {
316    U8   numReg = 0;
317    U8   numPool = 0;
318    U8   idxReg;
319    U8   idxPool;
320    SsMemDbgInfo dbgInfo;
321
322    SGetRegPoolInfo(&numReg,&numPool); 
323    mInfo->numRegions = numReg;
324
325    for(idxReg=0; idxReg< numReg; idxReg++)
326    {
327       SGetRegInfo(idxReg, &dbgInfo);
328
329       if(mInfo->regInfo[idxReg].isGenMemInfoUpdated == TRUE)
330       {
331          for(idxPool=0; idxPool<numPool; idxPool++)
332          {
333             mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = dbgInfo.bktDbgTbl[idxPool].numAlloc;
334             if(mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed > mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed)
335                mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed = mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed;
336          }
337       }
338       else
339       {
340       mInfo->regInfo[idxReg].numPools = numPool;
341       mInfo->regInfo[idxReg].regionId = idxReg;
342       mInfo->regInfo[idxReg].regionType = 0;
343
344       for(idxPool=0; idxPool<numPool; idxPool++)
345       {
346          mInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable = dbgInfo.bktDbgTbl[idxPool].numBlks;
347          mInfo->regInfo[idxReg].poolInfo[idxPool].poolSize = dbgInfo.bktDbgTbl[idxPool].size;
348          mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = dbgInfo.bktDbgTbl[idxPool].numAlloc;
349          if(mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed > mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed)
350             mInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed = mInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed;
351       }
352          mInfo->regInfo[idxReg].isGenMemInfoUpdated = TRUE; 
353       }
354    }
355    RETVALUE(ROK);
356 }
357
358 #ifdef ANSI
359 PUBLIC S16 cmFillMemUtilizationMeas
360 (
361  CmLteMemInfo *memoryInfo,
362 CmLteMemInfo *memInfo
363 )
364 #else
365 PUBLIC S16 cmFillMemUtilizationMeas(memoryInfo,memInfo)
366 CmLteMemInfo *memoryInfo;
367 CmLteMemInfo *memInfo;
368 #endif
369 {
370    U8 idxReg = 0;
371    U8 idxPool = 0;
372    U8 numPool = 0;
373
374    memoryInfo->numRegions = memInfo->numRegions;
375    for(idxReg=0; idxReg < memInfo->numRegions; idxReg++)
376    {
377       memoryInfo->regInfo[idxReg].regionId = memInfo->regInfo[idxReg].regionId;
378       memoryInfo->regInfo[idxReg].numPools = memInfo->regInfo[idxReg].numPools;
379       memoryInfo->regInfo[idxReg].regionType = memInfo->regInfo[idxReg].regionType;
380       numPool = memoryInfo->regInfo[idxReg].numPools;
381
382       for(idxPool=0; idxPool < numPool; idxPool++)
383       {
384          memoryInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable = memInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable;
385          memoryInfo->regInfo[idxReg].poolInfo[idxPool].poolSize = memInfo->regInfo[idxReg].poolInfo[idxPool].poolSize;
386          memoryInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = memInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed;
387          memoryInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed  = memInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed;
388       }
389    }
390    RETVALUE(ROK);
391 }
392
393 #ifdef ANSI
394 PUBLIC S16 cmClearMemUtilizationCounter
395 (
396 CmLteMemInfo *memInfo
397 )
398 #else
399 PUBLIC S16 cmClearMemUtilizationCounter(memInfo)
400 CmLteMemInfo *memInfo;
401 #endif
402 {
403    U8 idxReg = 0;
404    U8 idxPool = 0;
405    U8 numPool = 0;
406    for(idxReg=0; idxReg < memInfo->numRegions; idxReg++)
407    {
408       memInfo->regInfo[idxReg].regionId = 0;
409       memInfo->regInfo[idxReg].numPools = 0;
410       memInfo->regInfo[idxReg].regionType = 0;
411       memInfo->regInfo[idxReg].isGenMemInfoUpdated = FALSE;
412       numPool = memInfo->regInfo[idxReg].numPools;
413
414       for(idxPool=0; idxPool<numPool; idxPool++)
415       {
416          memInfo->regInfo[idxReg].poolInfo[idxPool].totAvailable = 0;
417          memInfo->regInfo[idxReg].poolInfo[idxPool].poolSize = 0;
418          memInfo->regInfo[idxReg].poolInfo[idxPool].crntUsed = 0;
419          memInfo->regInfo[idxReg].poolInfo[idxPool].maxUsed  = 0;
420       }
421    }
422    RETVALUE(ROK);
423 }
424
425 #ifdef ANSI
426 PUBLIC S16 cmClearCpuUtilizationCounter
427 (
428 CmCpuStatsInfo *cpuInfo
429 )
430 #else
431 PUBLIC S16 cmClearCpuUtilizationCounter(cpuInfo)
432 CmCpuStatsInfo *cpuInfo
433 #endif
434 {
435    U8 idx= 0;
436    for(idx=0; idx < cpuInfo->numCores; idx++)
437    {
438       cpuInfo->cpuUtil[idx].maxCpuUtil = 0;
439       cpuInfo->cpuUtil[idx].totCpuUtil = 0;
440       cpuInfo->cpuUtil[idx].numSamples = 0;
441    }
442    cpuInfo->numCores = 0;
443    RETVALUE(ROK);
444 }
445
446 #ifdef ANSI
447 PUBLIC S16 cmFillCpuUtilizationMeas
448 (
449 CmLteCpuInfo *cpuMeasInfo,
450 CmCpuStatsInfo *cpuInfo
451 )
452 #else
453 PUBLIC S16 cmFillCpuUtilizationMeas(cpuMeasInfo,cpuInfo)
454 CmLteCpuInfo *cpuMeasInfo;
455 CmCpuStatsInfo *cpuInfo;
456 #endif
457 {
458    U8 idx= 0;
459    cpuMeasInfo->numCores = cpuInfo->numCores;
460    for(idx=0; idx < cpuInfo->numCores; idx++)
461    {
462       cpuMeasInfo->cpuUtil[idx].avgCpuUtil = cpuInfo->cpuUtil[idx].totCpuUtil/cpuInfo->cpuUtil[idx].numSamples;
463       cpuMeasInfo->cpuUtil[idx].maxCpuUtil = cpuInfo->cpuUtil[idx].maxCpuUtil;
464    }
465    RETVALUE(ROK);
466
467 }
468 #endif
469
470 #ifdef TENB_TTI_PERF
471 CmTtiProc ttiProc;
472 #define TTI_1MS 950
473
474 PUBLIC Void cmUpdateTtiCounters(U32 ttiProcessingTime)
475 {
476    ttiProc.numOfTti++;
477    ttiProc.totTtiProcessingTime += ttiProcessingTime;
478    if(ttiProcessingTime > ttiProc.maxTtiProcessingTime)  
479    {
480       ttiProc.maxTtiProcessingTime = ttiProcessingTime;
481    }
482    if(ttiProcessingTime > TTI_THRESHOLD_VALUE)
483    {
484       ttiProc.ttiThresholdExceedCount++;
485    }
486    if(ttiProcessingTime > TTI_1MS)
487    {
488       ttiProc.ttiStretchCount++;
489    }
490    RETVOID;    
491 }
492
493 PUBLIC Void cmResetTtiCounters(Void)
494 {
495         ttiProc.totTtiProcessingTime = 0;
496         ttiProc.numOfTti = 0;
497         ttiProc.maxTtiProcessingTime = 0;
498         ttiProc.ttiStretchCount = 0;
499         ttiProc.ttiThresholdExceedCount = 0;
500         ttiProc.phyReptTtiStretchCount = 0;
501         RETVOID;
502 }
503 #endif
504
505 /**********************************************************************
506          End of file
507 **********************************************************************/