replaced cmMemSet, cmMemcpy with memset and memcpy resp AND Removed TRC() traces...
[o-du/l2.git] / src / 5gnrmac / mac_cfg_hdl.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 /* This file stores handler for MAC and SCH configuration requests */
19 /* header include files (.h) */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "lrg.x"
23 #include "du_app_mac_inf.h"
24 #include "mac_sch_interface.h"
25 #include "lwr_mac_upr_inf.h"
26 #include "mac.h"
27 #include "rlc_mac_inf.h"
28 #include "mac_upr_inf_api.h"
29 #include "lwr_mac.h"
30 #include "lwr_mac_fsm.h"
31 #include "mac_utils.h"
32
33 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg  *macCellCfg);
34
35 packMacCellCfgConfirm packMacCellCfmOpts[] =
36 {
37    packMacCellCfgCfm,      /* packing for loosely coupled */
38    duHandleMacCellCfgCfm,      /* packing for tightly coupled */
39    packMacCellCfgCfm,    /* packing for light weight loosly coupled */
40 };
41
42 SchCellCfgFunc SchCellCfgOpts[] =
43 {
44    packSchCellCfg,   /* packing for loosely coupled */
45    SchHdlCellCfgReq, /* packing for tightly coupled */
46    packSchCellCfg    /* packing for light weight loosly coupled */
47 };
48
49
50 /**
51  * @brief Layer Manager  Configuration request handler for Scheduler
52  *
53  * @details
54  *
55  *     Function : MacSchGenCfgReq
56  *
57  *     This function receives general configurations for Scheduler
58  *     from DU APP and forwards to Scheduler.
59  *
60  *  @param[in]  Pst *pst, the post structure
61  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
62  *  @return 
63  *      -# ROK
64  **/
65 uint8_t MacSchGenCfgReq(Pst *pst, RgMngmt *cfg)
66 {
67    printf("\nReceived Scheduler gen config at MAC");
68    pst->dstInst = DEFAULT_CELLS + 1;
69    SchProcGenCfgReq(pst, cfg);
70
71    return ROK;
72 }
73
74 /**
75  * @brief Layer Manager Configuration response from Scheduler
76  *
77  * @details
78  *
79  *     Function : SchSendCfgCfm
80  *
81  *     This function sends general configurations response from
82  *     Scheduler to DU APP.
83  *
84  *  @param[in]  Pst *pst, the post structure
85  *  @param[in]  RgMngmt *cfm, the configuration confirm structure
86  *  @return 
87  *      -# ROK
88  **/
89 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt  *cfm)
90 {
91    printf("\nSending Scheduler config confirm to DU APP");
92    pst->dstEnt = ENTDUAPP;
93    pst->dstInst = 0;
94    pst->srcInst = 0;
95    pst->selector = ODU_SELECTOR_LC;
96    RgMiLrgSchCfgCfm(pst, cfm);
97
98    return ROK;
99 }
100
101 /**
102  * @brief Layer Manager Configuration request handler.
103  *
104  * @details
105  *
106  *     Function : MacProcCellCfgReq
107  *
108  *     This function handles the gNB and cell configuration
109  *     request received from DU APP.
110  *     This API unapcks and forwards the config towards SCH
111  *
112  *  @param[in]  Pst           *pst
113  *  @param[in]  MacCellCfg    *macCellCfg
114  *  @return  
115  *      -# ROK
116  **/
117 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
118 {
119    Pst cfmPst;
120    uint16_t cellIdx;
121    uint8_t ret = ROK;
122    MacCellCb     *macCellCb;
123
124    memset(&cfmPst, 0, sizeof(Pst));
125
126    MAC_ALLOC(macCellCb, sizeof(MacCellCb));
127    if(macCellCb == NULLP)
128    {
129       DU_LOG("\nMAC : macCellCb is NULL at handling of macCellCfg\n");
130       return RFAILED;
131    }
132    memset(macCellCb, 0, sizeof(MacCellCb));
133
134    GET_CELL_IDX(macCellCfg->cellId, cellIdx);
135    macCb.macCell[cellIdx] = macCellCb;
136    macCb.macCell[cellIdx]->cellId = macCellCfg->cellId;
137    memcpy(&macCb.macCell[cellIdx]->macCellCfg, macCellCfg, sizeof(MacCellCfg));
138
139    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
140          macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
141    if(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu == NULLP)
142    {
143       DU_LOG("\nMAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
144       return RFAILED;
145    }
146    memcpy(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, macCellCfg->sib1Cfg.sib1Pdu, \
147          macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
148
149    /* Send cell cfg to scheduler */
150    ret = MacSchCellCfgReq(pst, macCellCfg);
151    if(ret != ROK)
152    {
153       MacCellCfgCfm macCellCfgCfm;
154       macCellCfgCfm.rsp = RSP_NOK;
155       macCellCfgCfm.cellId = macCellCfg->cellId;
156       /* Fill Pst */
157       FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
158       cfmPst.selector  = ODU_SELECTOR_LC;
159
160       ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
161    }
162    else
163    {
164       if(macCellCfg->prachCfg.fdm[0].numUnusedRootSeq != 0)
165       {
166          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg->prachCfg.fdm[0].unsuedRootSeq,
167                macCellCfg->prachCfg.fdm[0].numUnusedRootSeq* sizeof(uint8_t));
168       }
169       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg->sib1Cfg.sib1Pdu, macCellCfg->sib1Cfg.sib1PduLen);
170       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
171    }
172 #ifdef INTEL_WLS
173    LwrMacEnqueueWlsBlock();
174 #endif
175    return ret;
176 } /* end of MacProcCellCfgReq */
177
178 /**
179  * @brief Layer Manager Configuration request handler.
180  *
181  * @details
182  *
183  *     Function : MacSchCellCfgReq
184  *
185  *     This function sends cell configuration to SCH
186  *
187  *  @param[in]  Pst           *pst
188  *  @param[in]  MacCellCfg    *macCellCfg
189  *  @return  
190  *      -# ROK
191  **/
192 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
193 {
194    SchCellCfg schCellCfg;
195    Pst        cfgPst;
196    uint8_t    ret;
197
198    memset(&cfgPst, 0, sizeof(Pst));
199    schCellCfg.cellId = macCellCfg->cellId;
200    schCellCfg.phyCellId = macCellCfg->phyCellId;
201    schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
202    schCellCfg.dupMode = macCellCfg->dupType;
203
204    /* fill ssb scheduler parameters */
205    schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
206    schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
207    schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
208    schCellCfg.ssbSchCfg.ssbPeriod = macCellCfg->ssbCfg.ssbPeriod;
209    schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
210    for(uint8_t idx=0; idx<SSB_MASK_SIZE; idx++)
211    {
212       schCellCfg.ssbSchCfg.nSSBMask[idx] = macCellCfg->ssbCfg.ssbMask[idx];
213    }
214
215    /* fill SIB1 scheduler parameters */
216    schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen;
217    schCellCfg.sib1SchCfg.sib1NewTxPeriod = macCellCfg->sib1Cfg.sib1NewTxPeriod;
218    schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod;
219    schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex;
220    schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex;
221    schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs;
222
223    /* fill RACH config params */
224    schCellCfg.schRachCfg.prachCfgIdx = macCellCfg->prachCfg.prachCfgIdx;
225    schCellCfg.schRachCfg.prachSubcSpacing = \
226                                             macCellCfg->prachCfg.prachSubcSpacing;
227    schCellCfg.schRachCfg.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
228    schCellCfg.schRachCfg.msg1Fdm       = macCellCfg->prachCfg.msg1Fdm;
229    schCellCfg.schRachCfg.rootSeqLen    = macCellCfg->prachCfg.rootSeqLen;
230    schCellCfg.schRachCfg.rootSeqIdx    = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
231    schCellCfg.schRachCfg.numRootSeq    = macCellCfg->prachCfg.fdm[0].numRootSeq;
232    schCellCfg.schRachCfg.k1            = macCellCfg->prachCfg.fdm[0].k1;
233    schCellCfg.schRachCfg.ssbPerRach    = macCellCfg->prachCfg.ssbPerRach;
234    schCellCfg.schRachCfg.prachMultCarrBand = \
235                                              macCellCfg->prachCfg.prachMultCarrBand;
236    schCellCfg.schRachCfg.raContResTmr  = macCellCfg->prachCfg.raContResTmr;
237    schCellCfg.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
238    schCellCfg.schRachCfg.raRspWindow   = macCellCfg->prachCfg.raRspWindow;
239
240    /* fill initial DL BWP */
241    schCellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialDlBwp.bwp.firstPrb;
242    schCellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialDlBwp.bwp.numPrb;
243    schCellCfg.schInitialDlBwp.bwp.scs = macCellCfg->initialDlBwp.bwp.scs;
244    schCellCfg.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->initialDlBwp.bwp.cyclicPrefix;
245    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
246       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
247    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
248       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
249    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
250       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
251    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
252       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.duration;
253    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
254       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
255    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
256       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
257    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
258       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
259    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
260       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
261    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
262       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
263    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
264       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
265    schCellCfg.schInitialDlBwp.pdschCommon.k0 = macCellCfg->initialDlBwp.pdschCommon.k0;
266    schCellCfg.schInitialDlBwp.pdschCommon.mappingType =
267       macCellCfg->initialDlBwp.pdschCommon.mappingType;
268    schCellCfg.schInitialDlBwp.pdschCommon.startSymbol =
269       macCellCfg->initialDlBwp.pdschCommon.startSymbol;
270    schCellCfg.schInitialDlBwp.pdschCommon.lengthSymbol =
271       macCellCfg->initialDlBwp.pdschCommon.lengthSymbol;
272
273    /* fill initial UL BWP */
274    schCellCfg.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialUlBwp.bwp.firstPrb;
275    schCellCfg.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialUlBwp.bwp.numPrb;
276    schCellCfg.schInitialUlBwp.bwp.scs = macCellCfg->initialUlBwp.bwp.scs;
277    schCellCfg.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
278    schCellCfg.schInitialUlBwp.puschCommon.k2 = macCellCfg->initialUlBwp.puschCommon.k2;
279    schCellCfg.schInitialUlBwp.puschCommon.mappingType =
280       macCellCfg->initialUlBwp.puschCommon.mappingType;
281    schCellCfg.schInitialUlBwp.puschCommon.startSymbol =
282       macCellCfg->initialUlBwp.puschCommon.startSymbol;
283    schCellCfg.schInitialUlBwp.puschCommon.lengthSymbol =
284       macCellCfg->initialUlBwp.puschCommon.lengthSymbol;
285
286    FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
287
288    ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
289    return ret;
290 } /* end of MacSchCellCfgReq */
291
292
293 /*******************************************************************
294  *
295  * @brief Sends Cell config confirm to DU APP
296  *
297  * @details
298  *
299  *    Function : MacSendCellCfgCfm
300  *
301  *    Functionality:
302  *      Sends Cell config confirm to DU APP
303  *
304  * @params[in] Response status
305  * @return void
306  *
307  * ****************************************************************/
308 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
309 {
310    Pst pst;
311    uint16_t   cellIdx;
312    MacCellCfgCfm macCellCfgCfm;
313
314    memset(&pst, 0, sizeof(Pst));
315
316    GET_CELL_IDX(cellId, cellIdx);
317    macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
318    macCellCfgCfm.rsp = response;
319
320    /* Fill Pst */
321    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
322    pst.selector  = ODU_SELECTOR_LC;
323
324    (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
325 }
326
327
328 /**
329  * @brief Layer Manager Configuration response handler.
330  *
331  * @details
332  *
333  *     Function : MacProcSchCellCfgCfm
334  *
335  *     This function processes cell configuration to SCH
336  *
337  *  @param[in]  Pst           *pst
338  *  @param[in]  SchCellCfgCfm *schCellCfgCfm
339  *  @return  int
340  *      -# ROK
341  **/
342 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
343 {
344    uint16_t *cellId = NULLP;
345
346    if(schCellCfgCfm->rsp == RSP_OK)
347    {
348       cellId = &schCellCfgCfm->cellId;
349       sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
350    }
351    else
352    {
353       MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
354    }
355    return ROK;
356 }
357
358 /*******************************************************************
359  *
360  * @brief MAC handler for config response from PHY
361  *
362  * @details
363  *
364  *    Function : fapiMacConfigRsp
365  *
366  *    Functionality:
367  *     Processes config response from PHY and sends cell config
368  *     confirm to DU APP
369  *
370  * @params[in]
371  * @return void
372  *
373  * ****************************************************************/
374 void fapiMacConfigRsp(uint16_t cellId)
375 {
376    /* TODO : Processing of config response from PHY */
377
378    /* Send cell config cfm to DU APP */
379    MacSendCellCfgCfm(cellId, RSP_OK);
380 }
381
382 /**********************************************************************
383   End of file
384  **********************************************************************/