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