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