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