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