Adding new commiter to ODU-High repo
[o-du/l2.git] / src / 5gnrmac / rg_lmm.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:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code for Layer Manager Interface Module 
26   
27      File:     rg_lmm.c 
28   
29 **********************************************************************/
30
31 /** @file rg_lmm.c
32 @brief This file contains the Layer Management interface module implementation.
33        The functions for the configuration, control, status and statistics 
34        request primitives are defined here.
35 */
36
37 /* header include files (.h) */
38 #include "common_def.h"
39 #include "rg_env.h"        /* MAC Environment Defines */
40 #include "crg.h"           /* CRG Interface defines */
41 #include "rgu.h"           /* RGU Interface defines */
42 #include "tfu.h"           /* RGU Interface defines */
43 #include "rg_sch_inf.h"    /* RGR Interface defines */
44 #include "lrg.h"           /* LRG Interface defines */
45 #include "rgr.h"           /* LRG Interface defines */
46 #include "rg.h"            /* MAC defines */
47 #include "rg_err.h"        /* MAC error defines */
48 #include "mac_utils.h"
49
50 /* header/extern include files (.x) */
51 #include "crg.x"           /* CRG Interface includes */
52 #include "rgu.x"           /* RGU Interface includes */
53 #include "tfu.x"           /* RGU Interface includes */
54 #include "rg_sch_inf.x"    /* SCH Interface includes */
55 #include "rg_prg.x"    /* PRG Interface includes */
56 #include "lrg.x"           /* LRG Interface includes */
57 #include "rgr.x"           /* LRG Interface includes */
58 #include "du_app_mac_inf.h"
59 #include "rg.x"            /* MAC includes */
60 #ifdef SS_DIAG
61 #include "ss_diag.h"        /* Common log file */
62 #endif
63 #include "ss_rbuf.h"
64 #include "ss_rbuf.x"
65 #include "mac_sch_interface.h"
66 #include "lwr_mac_upr_inf.h"
67 #include "mac.h"
68 #include "lwr_mac_fsm.h"
69 #include "lwr_mac_phy.h"
70
71 #ifdef __cplusplus
72 extern "C" {
73 #endif /* __cplusplus */
74 Void rgGetSId ARGS((SystemId *s));
75 #ifdef __cplusplus
76 }
77 #endif /* __cplusplus */
78
79 /* Public variable declaration */
80 MacCb  macCb;
81
82 /* forward references */
83 static uint16_t rgLMMGenCfg ARGS((
84    Inst           inst,
85    RgCfg          *cfg           
86 ));
87
88 static uint16_t rgLMMSapCfg ARGS((
89    Inst           inst,
90    RgCfg          *cfg,
91    Elmnt          sapType
92 ));
93
94 static Void rgLMMFillCfmPst ARGS((
95    Pst           *reqPst,
96    Pst           *cfmPst,
97    RgMngmt       *cfm
98 ));
99
100 \f
101 /**
102  * @brief Task Initiation callback function. 
103  *
104  * @details
105  *
106  *     Function : macActvInit
107  *     
108  *     This function is supplied as one of parameters during MAC's 
109  *     task registration. SSI will invoke this function once, after
110  *     it creates and attaches this TAPA Task to a system task.
111  *     
112  *  @param[in]  Ent entity, the entity ID of this task.     
113  *  @param[in]  Inst inst, the instance ID of this task.
114  *  @param[in]  Region region, the region ID registered for memory 
115  *              usage of this task.
116  *  @param[in]  Reason reason.
117  *  @return  S16
118  *      -# ROK
119  **/
120 uint8_t macActvInit
121 (
122 Ent entity,            /* entity */
123 Inst inst,             /* instance */
124 Region region,         /* region */
125 Reason reason          /* reason */
126 )
127 {
128    Inst macInst ;
129
130    RG_IS_INST_VALID(inst);
131
132    macInst = inst - RG_INST_START;
133    /* Initialize the MAC TskInit structure to zero */
134    memset (&rgCb[macInst], 0, sizeof(RgCb));
135
136    /* Initialize the MAC TskInit with received values */
137    rgCb[macInst].rgInit.ent = entity;
138    rgCb[macInst].rgInit.inst = inst;
139    rgCb[macInst].rgInit.region = region;
140    rgCb[macInst].rgInit.pool = 0;
141    rgCb[macInst].rgInit.reason = reason;
142    rgCb[macInst].rgInit.cfgDone = FALSE;
143    rgCb[macInst].rgInit.acnt = FALSE;
144    rgCb[macInst].rgInit.usta = FALSE;
145    rgCb[macInst].rgInit.trc = FALSE;
146    rgCb[macInst].trcLen = 0; 
147 #ifdef DEBUGP
148 #ifdef RG_DEBUG
149    /* disabling debugs by default */
150    rgCb[macInst].rgInit.dbgMask = 0xffffffff; 
151 #endif
152 #endif /* DEBUGP */
153 #ifdef SS_DIAG
154    rgCb[macInst].rgInit.logMask = 0x0;
155 #endif
156    rgCb[macInst].rgInit.procId = SFndProcId();
157    rgCb[macInst].tfuSap.numBndRetries = 0;
158
159    /* Initialize Sap state */
160    rgCb[macInst].tfuSap.sapSta.sapState = LRG_NOT_CFG;
161    rgCb[macInst].crgSap.sapSta.sapState = LRG_NOT_CFG;
162    rgCb[macInst].rguSap = NULLP;
163    rgCb[macInst].crgSap.sapSta.sapState = LRG_NOT_CFG;
164
165    rgCb[macInst].inactiveCell = NULLP;
166    rgCb[macInst].cell         = NULLP;
167 #ifdef SS_RBUF
168    SAttachSRngBuf(SS_RNG_BUF_ULMAC_TO_ULRLC, SS_RBUF_ENT_ULMAC,SS_RNG_TX);
169    SAttachSRngBuf(SS_RNG_BUF_ULMAC_TO_ULRLC, SS_RBUF_ENT_ULRLC,SS_RNG_RX);
170 #endif
171
172    /* Initialize lower mac */
173    lwrMacLayerInit(region, 0);
174
175    return ROK;
176
177 } /* macActvInit */
178 \f
179 /**
180  * @brief Layer Manager Configuration request handler. 
181  *
182  * @details
183  *
184  *     Function : RgMiLrgCfgReq
185  *     
186  *     This function handles the configuration
187  *     request received from the Layer Manager.
188  *     -# Based on the cfg->hdr.elmId.elmnt value it invokes one of the
189  *        functions rgHdlGenCfg() or rgHdlSapCfg().
190  *     -# Invokes RgMiLrgCfgCfm() to send back the confirmation to the LM.
191  *     
192  *  @param[in]  Pst *pst, the post structure     
193  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
194  *  @return  S16
195  *      -# ROK
196  **/
197 S16 RgMiLrgCfgReq
198 (
199 Pst      *pst,    /* post structure  */
200 RgMngmt  *cfg     /* config structure  */
201 )
202 {
203    uint16_t  ret = LCM_PRIM_OK;
204    uint16_t  reason = LCM_REASON_NOT_APPL;
205    RgMngmt   cfm;
206    Pst       cfmPst;
207    Inst      inst;
208
209
210
211    DU_LOG("\nINFO    -->  MAC : Received CfgReq for MAC layer, Entity = %d, Instance = %d", pst->srcEnt, pst->srcInst);
212
213    RG_IS_INST_VALID(pst->dstInst);
214    inst = pst->dstInst - RG_INST_START;
215
216    /* Fill the post structure for sending the confirmation */
217    rgLMMFillCfmPst(pst, &cfmPst, cfg);
218
219    memset(&cfm, 0, sizeof(RgMngmt));
220
221 #ifdef LMINT3
222    cfm.hdr.transId = cfg->hdr.transId;
223 #endif
224
225
226    cfm.hdr.elmId.elmnt = cfg->hdr.elmId.elmnt;
227    switch(cfg->hdr.elmId.elmnt)
228    {
229       case STGEN:
230 #ifdef INTEL_WLS_MEM
231          /* Start WLS message receiver thread */
232          LwrMacStartWlsRcvr();
233 #endif
234          reason = rgLMMGenCfg(inst,&cfg->t.cfg); 
235          break;
236       case STRGUSAP:
237       case STCRGSAP:
238       case STTFUSAP:
239          reason = rgLMMSapCfg(inst,&cfg->t.cfg, cfg->hdr.elmId.elmnt);
240          break;
241       default:
242          ret = LCM_PRIM_NOK;
243          reason = LCM_REASON_INVALID_ELMNT;
244          DU_LOG("\nERROR  -->  MAC : Invalid Elmnt=%d",
245                cfg->hdr.elmId.elmnt);
246          break;
247    }
248
249    if (reason != LCM_REASON_NOT_APPL)
250    {
251       ret = LCM_PRIM_NOK;
252    }
253
254    cfm.cfm.status = ret;
255    cfm.cfm.reason = reason;
256
257    RgMiLrgCfgCfm(&cfmPst, &cfm);
258
259    return ROK;
260 }/*-- RgMiLrgCfgReq --*/
261
262 \f
263 /**
264  * @brief Layer Manager Statistics request handler. 
265  *
266  * @details
267  *
268  *     Function : RgMiLrgStsReq
269  *     
270  *     This function handles the statistics
271  *     request received from the Layer Manager.
272  *      -# Based on sts->hdr.elmId.elmnt, it retrieves either general or SAP
273  *      statistics from the rgCb global control block.
274  *      -# If action=ARST, it will reset the statistics parameters in rgCb to 0.
275  *      -# Invokes the RgMiLrgStsCfm to send back the confirmation to LM.
276  *     
277  *  @param[in]  Pst *pst, the post structure     
278  *  @param[in]  RgMngmt *sts, the statistics parameter's structure
279  *  @return  S16
280  *      -# ROK
281  **/
282 S16 RgMiLrgStsReq
283 (
284 Pst      *pst,    /* post structure  */
285 RgMngmt  *sts     /* statistics structure  */
286 )
287 {
288    Pst       cfmPst;
289    RgMngmt   cfm;
290    Inst      inst;
291
292    RG_IS_INST_VALID(pst->dstInst);
293    inst = pst->dstInst - RG_INST_START;
294    /* Fill the post structure for sending the confirmation */
295    rgLMMFillCfmPst(pst, &cfmPst, sts);
296
297    memset(&cfm, 0, sizeof(RgMngmt));
298
299 #ifdef LMINT3
300    cfm.hdr.transId = sts->hdr.transId;
301 #endif
302    SGetDateTime(&cfm.t.sts.dt);
303    cfm.cfm.status = LCM_PRIM_OK;
304    cfm.cfm.reason = LCM_REASON_NOT_APPL;
305    cfm.hdr.elmId.elmnt = sts->hdr.elmId.elmnt;
306    cfm.t.sts.action = sts->t.sts.action;
307
308    /* Check if General Config Done */
309    if(rgCb[inst].rgInit.cfgDone != TRUE) 
310    {
311       cfm.cfm.status = LCM_PRIM_NOK;
312       cfm.cfm.reason = LCM_REASON_GENCFG_NOT_DONE;
313       RgMiLrgStsCfm(&cfmPst,&cfm);
314       DU_LOG("\nERROR  -->  MAC : Gen Cfg not done");
315       return ROK;
316    }
317
318    switch(sts->hdr.elmId.elmnt)
319    {
320       case STGEN:
321          {
322             memcpy(&(cfm.t.sts.s.genSts), &rgCb[inst].genSts,
323                   sizeof(RgGenSts));
324             /* check if action is read and reset */
325             if(sts->t.sts.action == ARST)
326             {
327                rgCb[inst].genSts.numHarqFail = 0;
328             }
329             /* L2 statistics */
330 #ifdef MAC_SCH_STATS
331             {
332                RgGenSts *genSts = &(cfm.t.sts.s.genSts);
333                uint8_t       cqi = 0;
334                for(cqi=0; cqi <= 14; cqi++)
335                {
336                   /* Filling DL ACK/NACK stats */
337                   genSts->nackAckStats.dlCqiStat[cqi].mcs = \
338                      hqFailStats.dlCqiStat[cqi].mcs;
339                   genSts->nackAckStats.dlCqiStat[cqi].numOfNacks = \
340                      hqFailStats.dlCqiStat[cqi].numOfNacks;
341                   genSts->nackAckStats.dlCqiStat[cqi].numOfAcks = 
342                      hqFailStats.dlCqiStat[cqi].numOfAcks;
343
344                   /* Filling UL ACK/NACK stats */
345                   genSts->nackAckStats.ulCqiStat[cqi].mcs = \
346                      hqFailStats.ulCqiStat[cqi].mcs;
347                   genSts->nackAckStats.ulCqiStat[cqi].numOfNacks = \
348                      hqFailStats.ulCqiStat[cqi].numOfNacks;
349                   genSts->nackAckStats.ulCqiStat[cqi].numOfAcks = \
350                      hqFailStats.ulCqiStat[cqi].numOfAcks;
351
352                   /* Filling DL HQ Retx stats */
353                   genSts->hqRetxStats.dlCqiStat[cqi].mcs = \
354                      hqRetxStats.dlCqiStat[cqi].mcs;
355                   genSts->hqRetxStats.dlCqiStat[cqi].numOfHQ_1 = \
356                      hqRetxStats.dlCqiStat[cqi].numOfHQ_1;
357                   genSts->hqRetxStats.dlCqiStat[cqi].numOfHQ_2 = \
358                      hqRetxStats.dlCqiStat[cqi].numOfHQ_2;
359                   genSts->hqRetxStats.dlCqiStat[cqi].numOfHQ_3 = \
360                      hqRetxStats.dlCqiStat[cqi].numOfHQ_3;
361                   genSts->hqRetxStats.dlCqiStat[cqi].numOfHQ_4 = \
362                      hqRetxStats.dlCqiStat[cqi].numOfHQ_4;
363                   genSts->hqRetxStats.dlCqiStat[cqi].totalTx = \
364                      hqRetxStats.dlCqiStat[cqi].totalTx;
365
366                   /* Filling UL HQ Retx stats */
367                   genSts->hqRetxStats.ulCqiStat[cqi].mcs = \
368                      hqRetxStats.ulCqiStat[cqi].mcs;
369                   genSts->hqRetxStats.ulCqiStat[cqi].numOfHQ_1 = \
370                      hqRetxStats.ulCqiStat[cqi].numOfHQ_1;
371                   genSts->hqRetxStats.ulCqiStat[cqi].numOfHQ_2 = \
372                      hqRetxStats.ulCqiStat[cqi].numOfHQ_2;
373                   genSts->hqRetxStats.ulCqiStat[cqi].numOfHQ_3 = \
374                      hqRetxStats.ulCqiStat[cqi].numOfHQ_3;
375                   genSts->hqRetxStats.ulCqiStat[cqi].numOfHQ_4 = \
376                      hqRetxStats.ulCqiStat[cqi].numOfHQ_4;
377                   genSts->hqRetxStats.ulCqiStat[cqi].totalTx = \
378                      hqRetxStats.ulCqiStat[cqi].totalTx;
379                }
380                /* Reset statistics */
381                if(sts->t.sts.action == ZEROSTS)
382                {
383                   memset(&hqRetxStats, 0, \
384                         sizeof(RgSchHqRetxStats));
385                   memset(&hqFailStats, 0, \
386                         sizeof(RgSchNackAckStats));
387                }
388             }
389 #endif /* MAC_SCH_STATS*/
390          }
391          break;
392       case STRGUSAP:
393          memcpy(&(cfm.t.sts.s.rguSts), &rgCb[inst].rguSap[sts->t.sts.sapInst].sapSts,
394                   sizeof(RgSapSts));
395
396          /* check if action is read and reset */
397          if(sts->t.sts.action == ARST)
398             memset(&rgCb[inst].rguSap[sts->t.sts.sapInst].sapSts, 0, sizeof(RgSapSts));
399
400          break;
401       case STCRGSAP:
402          memcpy(&(cfm.t.sts.s.crgSts), &rgCb[inst].crgSap.sapSts,
403                   sizeof(RgSapSts));
404
405          /* check if action is read and reset */
406          if(sts->t.sts.action == ARST)
407             memset(&rgCb[inst].crgSap.sapSts, 0, sizeof(RgSapSts));
408
409          break;
410       case STTFUSAP:
411          memcpy(&(cfm.t.sts.s.tfuSts), &rgCb[inst].tfuSap.sapSts,
412                   sizeof(RgSapSts));
413
414          /* check if action is read and reset */
415          if(sts->t.sts.action == ARST)
416             memset(&rgCb[inst].tfuSap.sapSts, 0, sizeof(RgSapSts));
417
418          break;
419       default:
420          cfm.cfm.status = LCM_PRIM_NOK;
421          cfm.cfm.reason = LCM_REASON_INVALID_ELMNT;
422          DU_LOG("\nERROR  -->  MAC : Invalid Elmnt = %d",sts->hdr.elmId.elmnt);
423          break;     
424    }
425    RgMiLrgStsCfm(&cfmPst,&cfm);
426    return ROK;
427 }/*-- RgMiLrgStsReq --*/
428
429 \f
430 /**
431  * @brief SAP Configuration Handler. 
432  *
433  * @details
434  *
435  *     Function : rgLMMSapCfg
436  *     
437  *     This function in called by RgMiLrgCfgReq(). It handles the
438  *     interface SAP configuration of the LTE MAC layer. It 
439  *     initializes the sapState to LRG_UNBND. Returns
440  *     reason for success/failure of this function.
441  *     
442  *  @param[in]  Inst        inst
443  *  @param[in]  RgCfg *cfg, the Configuaration information 
444  *  @return  uint16_t
445  *      -# LCM_REASON_GENCFG_NOT_DONE
446  *      -# LCM_REASON_INVALID_SAP
447  *      -# LCM_REASON_NOT_APPL
448  **/
449 static uint16_t rgLMMSapCfg
450 (
451 Inst  inst,
452 RgCfg *cfg,            /* Configuaration information */
453 Elmnt sapType             /* Sap Type */
454 )
455 {
456    uint16_t          ret = LCM_REASON_NOT_APPL;
457    RgLowSapCfgInfo   *lowSapCfg = NULLP;
458    RgUpSapCfgInfo    *upSapCfg = NULLP;
459    RgUpSapCb         *upSapCb  = NULLP;
460
461
462       /* Check if Gen Config has been done */
463    if(rgCb[inst].rgInit.cfgDone != TRUE)
464          return (LCM_REASON_GENCFG_NOT_DONE);
465
466    switch(sapType)
467    {   
468       case STRGUSAP:
469          if ((cfg->s.rguSap.spId > LRG_MAX_RGU_SAPS) &&
470                (cfg->s.rguSap.selector != ODU_SELECTOR_TC) &&
471                (cfg->s.rguSap.selector != ODU_SELECTOR_LC))
472          {
473             ret = LCM_REASON_INVALID_PAR_VAL;
474             DU_LOG("\nERROR  -->  MAC : unsupported Selector value for RGU");
475             break;
476          }
477          upSapCb = &(rgCb[inst].rguSap[cfg->s.rguSap.spId]);
478          if(upSapCb->sapSta.sapState == LRG_NOT_CFG)
479          { 
480             upSapCb->sapSta.sapState = LRG_UNBND;
481          }
482          upSapCfg = &(upSapCb->sapCfg);
483          upSapCfg->sapPst.dstEnt = cfg->s.rguSap.ent;
484          upSapCfg->sapPst.dstInst = cfg->s.rguSap.inst;
485          upSapCfg->sapPst.dstProcId = cfg->s.rguSap.procId;
486          upSapCfg->sapPst.srcEnt = rgCb[inst].rgInit.ent;
487          upSapCfg->sapPst.srcInst = rgCb[inst].rgInit.inst;
488          upSapCfg->sapPst.srcProcId = rgCb[inst].rgInit.procId;
489          upSapCfg->sapPst.region = cfg->s.rguSap.mem.region;
490          upSapCfg->sapPst.pool = cfg->s.rguSap.mem.pool;
491          upSapCfg->sapPst.selector = cfg->s.rguSap.selector;
492          upSapCfg->sapPst.route = cfg->s.rguSap.route;
493          upSapCfg->sapPst.intfVer = 0; 
494          upSapCfg->sapPst.prior = cfg->s.rguSap.prior;
495          upSapCfg->suId = cfg->s.rguSap.suId;
496          upSapCfg->spId = cfg->s.rguSap.spId;
497          /*T2K uses 2 saps, T3K uses 1 sap. change the rgRguDlSap to 1 only if
498           * there is cfg request with sap is 1*/
499          break;
500       case STCRGSAP:
501          if ((cfg->s.crgSap.selector != ODU_SELECTOR_TC) &&
502                (cfg->s.crgSap.selector != ODU_SELECTOR_LC))
503          {
504             ret = LCM_REASON_INVALID_PAR_VAL;
505             DU_LOG("\nERROR  -->  MAC : unsupported Selector value for CRG");
506             break;
507          }
508          if(rgCb[inst].crgSap.sapSta.sapState == LRG_NOT_CFG)
509          { 
510             rgCb[inst].crgSap.sapSta.sapState = LRG_UNBND;
511          }
512          upSapCfg = &rgCb[inst].crgSap.sapCfg;
513
514          upSapCfg->sapPst.dstEnt = cfg->s.crgSap.ent;
515          upSapCfg->sapPst.dstInst = cfg->s.crgSap.inst;
516          upSapCfg->sapPst.dstProcId = cfg->s.crgSap.procId;
517          upSapCfg->sapPst.srcEnt = rgCb[inst].rgInit.ent;
518          upSapCfg->sapPst.srcInst = rgCb[inst].rgInit.inst;
519          upSapCfg->sapPst.srcProcId = rgCb[inst].rgInit.procId;
520          upSapCfg->sapPst.region = cfg->s.crgSap.mem.region;
521          upSapCfg->sapPst.pool = cfg->s.crgSap.mem.pool;
522          upSapCfg->sapPst.selector = cfg->s.crgSap.selector;
523          upSapCfg->sapPst.route = cfg->s.crgSap.route;
524          upSapCfg->sapPst.intfVer = 0; 
525          upSapCfg->sapPst.prior = cfg->s.crgSap.prior;
526          upSapCfg->suId = cfg->s.crgSap.suId;
527          upSapCfg->spId = cfg->s.crgSap.spId;
528          break;
529       case STTFUSAP:
530 #ifndef CL_MAC_LWLC 
531          if ((cfg->s.tfuSap.selector != ODU_SELECTOR_TC) &&
532                (cfg->s.tfuSap.selector != ODU_SELECTOR_LC))
533          {
534             ret = LCM_REASON_INVALID_PAR_VAL;
535             DU_LOG("\nERROR  -->  MAC : unsupported Selector value for TFU");
536             break;
537          }
538 #endif
539          if (rgCb[inst].tfuSap.sapSta.sapState == LRG_NOT_CFG) 
540          { 
541             rgCb[inst].tfuSap.sapSta.sapState = LRG_UNBND;
542          }
543          lowSapCfg = &rgCb[inst].tfuSap.sapCfg;
544
545          lowSapCfg->sapPst.dstEnt = cfg->s.tfuSap.ent;
546          lowSapCfg->sapPst.dstInst = cfg->s.tfuSap.inst;
547          lowSapCfg->sapPst.dstProcId = rgCb[inst].rgInit.procId;
548          lowSapCfg->sapPst.srcEnt = rgCb[inst].rgInit.ent;
549          lowSapCfg->sapPst.srcInst = rgCb[inst].rgInit.inst;
550          lowSapCfg->sapPst.srcProcId = rgCb[inst].rgInit.procId;
551          lowSapCfg->sapPst.region = cfg->s.tfuSap.mem.region;
552          lowSapCfg->sapPst.pool = cfg->s.tfuSap.mem.pool;
553          lowSapCfg->sapPst.selector = cfg->s.tfuSap.selector;
554          lowSapCfg->sapPst.route = cfg->s.tfuSap.route;
555          lowSapCfg->sapPst.intfVer = 0; 
556          lowSapCfg->sapPst.prior = cfg->s.tfuSap.prior;
557          lowSapCfg->suId = cfg->s.tfuSap.suId;
558          lowSapCfg->spId = cfg->s.tfuSap.spId;
559          memcpy(&lowSapCfg->bndTmr, &cfg->s.tfuSap.bndTmr,
560                    sizeof(TmrCfg));
561          break;
562       default:
563          /* would never reach here */
564          break;
565    }
566    return (ret);
567 }
568
569 \f
570 /**
571  * @brief General Configuration Handler. 
572  *
573  * @details
574  *
575  *     Function : rgLMMGenCfg
576  *     
577  *     This function in called by RgMiLrgCfgReq(). It handles the
578  *     general configuration of the LTE MAC layer. It initializes 
579  *     the hash lists of RgCb. Returns
580  *     reason for success/failure of this function.
581  *     
582  *  @param[in]  Inst        inst
583  *  @param[in]  RgCfg *cfg, the Configuaration information 
584  *  @return  uint16_t
585  *      -# LCM_REASON_NOT_APPL 
586  *      -# LCM_REASON_INVALID_MSGTYPE
587  *      -# LCM_REASON_MEM_NOAVAIL
588  **/
589 static uint16_t rgLMMGenCfg
590 (
591 Inst inst,
592 RgCfg *cfg            /* Configuaration information */
593 )
594 {
595    uint16_t    ret = LCM_REASON_NOT_APPL;
596
597
598    /* Check if General Configuration is done already */
599    if (rgCb[inst].rgInit.cfgDone == TRUE)
600    {
601       return (LCM_REASON_INVALID_MSGTYPE);
602    }
603    if ((cfg->s.genCfg.lmPst.selector != ODU_SELECTOR_TC) &&
604          (cfg->s.genCfg.lmPst.selector != ODU_SELECTOR_LC))
605    {
606       DU_LOG("\nERROR  -->  MAC : unsupported Selector value for RGU");
607       return (LCM_REASON_INVALID_PAR_VAL);
608    }
609    /* Update the Pst structure for LM interface */
610    memcpy(&rgCb[inst].rgInit.lmPst, &cfg->s.genCfg.lmPst,
611              sizeof(Pst));
612
613    rgCb[inst].rgInit.lmPst.srcProcId = rgCb[inst].rgInit.procId;
614    rgCb[inst].rgInit.lmPst.srcEnt = rgCb[inst].rgInit.ent;
615    rgCb[inst].rgInit.lmPst.srcInst = rgCb[inst].rgInit.inst;
616    rgCb[inst].rgInit.lmPst.event = EVTNONE;
617
618    rgCb[inst].rgInit.region = cfg->s.genCfg.mem.region;
619    rgCb[inst].rgInit.pool = cfg->s.genCfg.mem.pool;
620    rgCb[inst].genCfg.tmrRes = cfg->s.genCfg.tmrRes;
621
622    macCb.tmrRes = cfg->s.genCfg.tmrRes;
623    macCb.macInst = rgCb[inst].rgInit.inst;
624    macCb.procId = rgCb[inst].rgInit.procId;
625
626    /* Initialize SAP States */
627    rgCb[inst].crgSap.sapSta.sapState = LRG_NOT_CFG;
628
629    if(cfg->s.genCfg.numRguSaps == 0)
630    {
631       DU_LOG("\nERROR  -->  MAC : rgGenCfg(): Invalid numRguSap.\n");
632       return RFAILED;
633    }
634
635    /* allocate RGR saps */
636    MAC_ALLOC(rgCb[inst].rguSap, sizeof(RgUpSapCb) * cfg->s.genCfg.numRguSaps);
637    if(rgCb[inst].rguSap == NULLP)
638    {
639       DU_LOG("\nERROR  -->  MAC : rgGenCfg(): Failed to allocate mem for RGU SAP's.\n");
640       return RFAILED;
641    }
642    rgCb[inst].numRguSaps = cfg->s.genCfg.numRguSaps;
643
644    for (int idx = 0; idx < rgCb[inst].numRguSaps; idx++)
645    {
646       rgCb[inst].rguSap[idx].sapSta.sapState = LRG_NOT_CFG;
647       memset(&rgCb[inst].rguSap[idx], 0, sizeof(RgUpSapCb));
648    }
649    rgCb[inst].tfuSap.sapSta.sapState = LRG_NOT_CFG;
650    /* Initialize the timer blocks */
651    cmInitTimers(macCb.tmrBlk, MAX_NUM_TIMER);
652    /* Initialzie the timer queue */   
653    memset(&macCb.tmrTq, 0, sizeof(CmTqType) * MAC_TQ_SIZE);
654    /* Initialize the timer control point */
655    memset(&macCb.tmrTqCp, 0, sizeof(CmTqCp));
656    macCb.tmrTqCp.tmrLen = MAC_TQ_SIZE;
657
658    /* Timer Registration request to SSI */
659    if(ODU_REG_TMR_MT(ENTMAC, macCb.macInst, macCb.tmrRes, macActvTmr) != ROK)
660    {
661
662       DU_LOG("\nERROR  -->  MAC : Failed to register timer");
663
664       MAC_FREE(rgCb[inst].rguSap,
665             (sizeof(RgUpSapCb) * cfg->s.genCfg.numRguSaps));
666
667       return (LCM_REASON_MEM_NOAVAIL);
668    }
669
670    /* Set Config done in TskInit */
671    rgCb[inst].rgInit.cfgDone = TRUE;
672
673    return (ret);
674 }
675
676 \f
677 /***********************************************************
678  *
679  *     Func : rgLMMFillCfmPst 
680  *        
681  *
682  *     Desc : Fills the Confirmation Post Structure cfmPst using the reqPst 
683  *            and the cfm->hdr.response.
684  *            
685  *
686  *     Ret  : Void
687  *
688  *     Notes: 
689  *
690  *     File : rg_lmm.c 
691  *
692  **********************************************************/
693 static Void rgLMMFillCfmPst
694 (
695 Pst           *reqPst,
696 Pst           *cfmPst,
697 RgMngmt       *cfm
698 )
699 {
700    Inst inst;
701    inst = (reqPst->dstInst - RG_INST_START);
702
703    cfmPst->srcEnt    = rgCb[inst].rgInit.ent;
704    cfmPst->srcInst   = rgCb[inst].rgInit.inst;
705    cfmPst->srcProcId = rgCb[inst].rgInit.procId;
706    cfmPst->dstEnt    = reqPst->srcEnt;
707    cfmPst->dstInst   = reqPst->srcInst;
708    cfmPst->dstProcId = reqPst->srcProcId;
709
710    cfmPst->selector  = cfm->hdr.response.selector;
711    cfmPst->prior     = cfm->hdr.response.prior;
712    cfmPst->route     = cfm->hdr.response.route;
713    cfmPst->region    = cfm->hdr.response.mem.region;
714    cfmPst->pool      = cfm->hdr.response.mem.pool;
715
716    return;
717 }
718
719 \f
720 /**
721  * @brief Timer start handler. 
722  *
723  * @details
724  *
725  *     Function : rgLMMStartTmr
726  *     
727  *     This function based on the input parameters starts the timer for 
728  *     "tmrVal" duration. As of now MAC uses the timer functionality for 
729  *     BndReq only. Hence there is no conditional code based on "tmrEvnt".
730  *     
731  *  @param[in]  Inst        inst
732  *  @param[in]  S16   tmrEvnt, the Timer Event    
733  *  @param[in]  uint32_t   tmrVal,  the Wait Time
734  *  @param[in]  PTR   cb,  Entry for which Timer expired
735  *  @return  S16
736  *      -# ROK
737  **/
738 S16 rgLMMStartTmr
739 (
740 Inst               inst,
741 S16                tmrEvnt,            /* Timer Event */
742 uint32_t           tmrVal,             /* Wait Time */
743 PTR                cb                  /* Entry for which Timer Expired */
744 )
745 {
746    CmTmrArg    arg;
747
748
749       UNUSED(tmrEvnt);
750
751    /* Initialize the arg structure */
752    memset(&arg, 0, sizeof(CmTmrArg));
753
754    arg.tqCp = &rgCb[inst].tmrTqCp;
755    arg.tq = rgCb[inst].tmrTq;
756    arg.timers = rgCb[inst].tmrBlk;
757    arg.cb = cb;
758    arg.tNum = 0;
759    arg.max = RG_MAX_TIMER;
760    arg.evnt = RG_BNDREQ_TMR;
761    arg.wait = tmrVal;      
762    cmPlcCbTq(&arg);
763
764    return ROK;
765 }
766
767 \f
768 /**
769  * @brief Timer stop handler. 
770  *
771  * @details
772  *
773  *     Function : rgLMMStopTmr
774  *     
775  *     This function based on the input parameters stops the timer for 
776  *     "tmrEvnt". As of now MAC uses the timer functionality for 
777  *     BndReq only. Hence there is no conditional code based on "tmrEvnt".
778  *     Once the bind happens and this timer is stopped, the timer functionality
779  *     is deregistered with SSI. As there is no further use of timer processing.
780  *     
781  *  @param[in]  Inst        inst
782  *  @param[in]  S16   tmrEvnt, the Timer Event    
783  *  @param[in]  PTR   cb,  Entry for which Timer expired
784  *  @return  S16
785  *      -# ROK
786  *      -# RFAILED
787  **/
788 S16 rgLMMStopTmr
789 (
790 Inst               inst,             /* Scheduler instance */
791 S16                tmrEvnt,            /* Timer Event */
792 PTR                cb                  /* Entry for which Timer Expired */
793 )
794 {
795    CmTmrArg   arg;
796    uint8_t      i;
797    S16        ret; 
798
799
800    ret = RFAILED;
801
802    for(i=0;i<RG_MAX_TIMER;i++)
803    {
804       /* Search for the Timer Blocks */
805       if(rgCb[inst].tmrBlk[i].tmrEvnt == tmrEvnt)
806       {
807          /* Initialize the arg structure */
808          memset(&arg, 0, sizeof(CmTmrArg));
809
810          arg.tqCp = &rgCb[inst].tmrTqCp;
811          arg.tq = rgCb[inst].tmrTq;
812          arg.timers = rgCb[inst].tmrBlk;
813          arg.cb = cb;
814          arg.max = RG_MAX_TIMER;
815          arg.evnt = NOTUSED;
816          arg.wait = NOTUSED;
817
818          arg.tNum = i;   
819          cmRmvCbTq(&arg);
820          ret = ROK;
821          break;
822       }
823
824    }
825
826
827    return (ret);
828 }
829
830 \f
831 /**
832  * @brief Timer Expiry handler. 
833  *
834  * @details
835  *
836  *     Function : rgLMMTmrExpiry
837  *     
838  *     This is a callback function used as an input parameter to cmPrcTmr()
839  *     to check expiry of any timer. In this function, the only concern is
840  *     about tmrEvnt=Bind timer.
841  *     
842  *  @param[in]  PTR   cb,  Entry for which Timer expired
843  *  @param[in]  S16   tmrEvnt, the Timer Event    
844  *  @return  S16
845  *      -# ROK
846  **/
847 S16 rgLMMTmrExpiry
848 (
849 PTR cb,               /* Pointer to timer control block */
850 S16 tmrEvnt           /* Timer Event */
851 )
852 {
853    S16        ret = ROK;
854    RgLowSapCb *tfuSap = (RgLowSapCb *)cb;
855    Inst          inst = tfuSap->sapCfg.sapPst.srcInst - RG_INST_START;
856
857    switch(tmrEvnt)
858    {
859       case RG_BNDREQ_TMR:
860          tfuSap->numBndRetries++;
861          if(tfuSap->numBndRetries > RG_MAX_BNDRETRY)
862          {
863             rgLMMStaInd(inst,LCM_CATEGORY_INTERFACE, LCM_EVENT_BND_FAIL,
864                         LCM_CAUSE_TMR_EXPIRED, NULLP);
865          }
866          else
867          {
868             /* Restart the bind timer */
869             if (tfuSap->sapCfg.bndTmr.enb == TRUE)
870             {
871                ret = rgLMMStartTmr(inst,RG_BNDREQ_TMR, tfuSap->sapCfg.bndTmr.val,
872                cb);
873             }
874
875             /* Send bind request */
876             //rgLIMTfuBndReq(inst,rgCb[inst].tfuSap.sapCfg.suId,
877                                 //rgCb[inst].tfuSap.sapCfg.spId);
878          }
879          break;
880       default:
881          DU_LOG("\nERROR  -->  MAC : Invalid tmrEvnt=%d",tmrEvnt);
882          ret = RFAILED;
883          break;
884    }
885    return (ret);
886 }
887
888
889 \f
890 /**
891  * @brief Layer Manager Unsolicited Status Indication generation. 
892  *
893  * @details
894  *
895  *     Function : rgLMMStaInd 
896  *     
897  *     This API is used by the other modules of MAC to send a unsolicited
898  *     status indication to the Layer Manager.
899  *     
900  *  @param[in]  Inst        inst
901  *  @param[in]  uint16_t category, the Alarm category
902  *  @param[in]  uint16_t event, the Alarm event
903  *  @param[in]  uint16_t cause, the cause of the Alarm
904  *  @param[in]  RgUstaDgn *dgn, Alarm Diagonostics
905  *  @return  S16
906  *      -# ROK
907  **/
908 S16 rgLMMStaInd
909 (
910 Inst inst,
911 uint16_t category,
912 uint16_t event,
913 uint16_t cause,
914 RgUstaDgn *dgn
915 )
916 {
917    RgMngmt    usta;
918    if(rgCb[inst].rgInit.usta == FALSE)
919    {
920       return ROK;
921    }
922
923    memset(&usta, 0, sizeof(RgMngmt));
924
925    SGetDateTime(&usta.t.usta.cmAlarm.dt);
926    usta.t.usta.cmAlarm.category = category;
927    usta.t.usta.cmAlarm.event = event;
928    usta.t.usta.cmAlarm.cause = cause;
929    if (dgn != NULLP)
930    {
931       memcpy(&usta.t.usta.dgn, dgn, sizeof(RgUstaDgn));
932    }
933
934    rgCb[inst].rgInit.lmPst.selector = rgCb[inst].genCfg.ustaResp.response.selector;
935    rgCb[inst].rgInit.lmPst.prior = rgCb[inst].genCfg.ustaResp.response.prior;
936    rgCb[inst].rgInit.lmPst.route = rgCb[inst].genCfg.ustaResp.response.route;
937    rgCb[inst].rgInit.lmPst.region = rgCb[inst].genCfg.ustaResp.response.mem.region;
938    rgCb[inst].rgInit.lmPst.pool = rgCb[inst].genCfg.ustaResp.response.mem.pool;
939    usta.hdr.transId = rgCb[inst].genCfg.ustaResp.transId;
940
941    return (RgMiLrgStaInd(&rgCb[inst].rgInit.lmPst, &usta));
942 }
943
944 /**********************************************************************
945
946   End of file
947  **********************************************************************/