1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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"
23 #include "du_app_mac_inf.h"
24 #include "mac_sch_interface.h"
25 #include "lwr_mac_upr_inf.h"
27 #include "rlc_mac_inf.h"
28 #include "mac_upr_inf_api.h"
30 #include "lwr_mac_fsm.h"
31 #include "mac_utils.h"
32 #include "lwr_mac_phy.h"
34 uint8_t ssbPeriodicity[6] = {5, 10, 20, 40, 80, 160};
36 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg);
38 packMacCellCfgConfirm packMacCellCfmOpts[] =
40 packMacCellCfgCfm, /* packing for loosely coupled */
41 duHandleMacCellCfgCfm, /* packing for tightly coupled */
42 packMacCellCfgCfm, /* packing for light weight loosly coupled */
45 SchCellCfgFunc SchCellCfgOpts[] =
47 packSchCellCfg, /* packing for loosely coupled */
48 SchHdlCellCfgReq, /* packing for tightly coupled */
49 packSchCellCfg /* packing for light weight loosly coupled */
54 * @brief Layer Manager Configuration request handler for Scheduler
58 * Function : MacSchGenCfgReq
60 * This function receives general configurations for Scheduler
61 * from DU APP and forwards to Scheduler.
63 * @param[in] Pst *pst, the post structure
64 * @param[in] RgMngmt *cfg, the configuration parameter's structure
68 uint8_t MacSchGenCfgReq(Pst *pst, RgMngmt *cfg)
70 printf("\nReceived Scheduler gen config at MAC");
71 pst->dstInst = DEFAULT_CELLS + 1;
72 SchProcGenCfgReq(pst, cfg);
78 * @brief Layer Manager Configuration response from Scheduler
82 * Function : SchSendCfgCfm
84 * This function sends general configurations response from
85 * Scheduler to DU APP.
87 * @param[in] Pst *pst, the post structure
88 * @param[in] RgMngmt *cfm, the configuration confirm structure
92 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt *cfm)
94 DU_LOG("\nDEBUG --> Sending Scheduler config confirm to DU APP");
95 pst->dstEnt = ENTDUAPP;
98 pst->selector = ODU_SELECTOR_LC;
99 RgMiLrgSchCfgCfm(pst, cfm);
105 * @brief Layer Manager Configuration request handler.
109 * Function : MacProcCellCfgReq
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
115 * @param[in] Pst *pst
116 * @param[in] MacCellCfg *macCellCfg
120 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
125 MacCellCb *macCellCb;
127 memset((uint8_t *)&cfmPst, 0, sizeof(Pst));
129 MAC_ALLOC(macCellCb, sizeof(MacCellCb));
130 if(macCellCb == NULLP)
132 DU_LOG("\nERROR --> MAC : macCellCb is NULL at handling of macCellCfg\n");
135 memset(macCellCb, 0, sizeof(MacCellCb));
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));
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)
146 DU_LOG("\nERROR --> MAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
149 memcpy(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, macCellCfg->sib1Cfg.sib1Pdu, \
150 macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
152 /* Send cell cfg to scheduler */
153 ret = MacSchCellCfgReq(pst, macCellCfg);
156 MacCellCfgCfm macCellCfgCfm;
157 macCellCfgCfm.rsp = RSP_NOK;
158 macCellCfgCfm.cellId = macCellCfg->cellId;
160 FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
161 cfmPst.selector = ODU_SELECTOR_LC;
163 ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
167 if(macCellCfg->prachCfg.fdm[0].numUnusedRootSeq != 0)
169 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg->prachCfg.fdm[0].unsuedRootSeq,
170 macCellCfg->prachCfg.fdm[0].numUnusedRootSeq* sizeof(uint8_t));
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));
176 } /* end of MacProcCellCfgReq */
179 * @brief Layer Manager Configuration request handler.
183 * Function : MacSchCellCfgReq
185 * This function sends cell configuration to SCH
187 * @param[in] Pst *pst
188 * @param[in] MacCellCfg *macCellCfg
192 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
194 SchCellCfg schCellCfg;
198 memset(&cfgPst, 0, sizeof(Pst));
199 memset(&schCellCfg, 0, sizeof(SchCellCfg));
200 schCellCfg.cellId = macCellCfg->cellId;
201 schCellCfg.phyCellId = macCellCfg->phyCellId;
202 schCellCfg.numerology = macCellCfg->numerology;
203 schCellCfg.dupMode = macCellCfg->dupType;
204 schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
205 schCellCfg.dlFreq = macCellCfg->dlCarrCfg.freq;
206 schCellCfg.ulFreq = macCellCfg->ulCarrCfg.freq;
208 /* fill ssb scheduler parameters */
209 schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
210 schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
211 schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
212 schCellCfg.ssbSchCfg.ssbPeriod = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
213 schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
214 for(uint8_t idx=0; idx<SSB_MASK_SIZE; idx++)
216 schCellCfg.ssbSchCfg.nSSBMask[idx] = macCellCfg->ssbCfg.ssbMask[idx];
219 /* fill SIB1 scheduler parameters */
220 schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen;
221 schCellCfg.sib1SchCfg.sib1NewTxPeriod = macCellCfg->sib1Cfg.sib1NewTxPeriod;
222 schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod;
223 schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex;
224 schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex;
225 schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs;
227 /* fill RACH config params */
228 schCellCfg.schRachCfg.prachCfgIdx = macCellCfg->prachCfg.prachCfgIdx;
229 schCellCfg.schRachCfg.prachSubcSpacing = \
230 macCellCfg->prachCfg.prachSubcSpacing;
231 schCellCfg.schRachCfg.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
232 schCellCfg.schRachCfg.msg1Fdm = macCellCfg->prachCfg.msg1Fdm;
233 schCellCfg.schRachCfg.rootSeqLen = macCellCfg->prachCfg.rootSeqLen;
234 schCellCfg.schRachCfg.rootSeqIdx = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
235 schCellCfg.schRachCfg.numRootSeq = macCellCfg->prachCfg.fdm[0].numRootSeq;
236 schCellCfg.schRachCfg.k1 = macCellCfg->prachCfg.fdm[0].k1;
237 schCellCfg.schRachCfg.ssbPerRach = macCellCfg->prachCfg.ssbPerRach;
238 schCellCfg.schRachCfg.prachMultCarrBand = \
239 macCellCfg->prachCfg.prachMultCarrBand;
240 schCellCfg.schRachCfg.raContResTmr = macCellCfg->prachCfg.raContResTmr;
241 schCellCfg.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
242 schCellCfg.schRachCfg.raRspWindow = macCellCfg->prachCfg.raRspWindow;
244 /* fill initial DL BWP */
245 schCellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialDlBwp.bwp.firstPrb;
246 schCellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialDlBwp.bwp.numPrb;
247 schCellCfg.schInitialDlBwp.bwp.scs = macCellCfg->initialDlBwp.bwp.scs;
248 schCellCfg.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->initialDlBwp.bwp.cyclicPrefix;
249 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
250 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
251 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
252 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
253 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
254 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
255 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
256 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.duration;
257 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
258 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
259 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
260 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
261 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
262 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
263 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
264 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
265 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
266 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
267 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
268 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
269 schCellCfg.schInitialDlBwp.pdschCommon.k0 = macCellCfg->initialDlBwp.pdschCommon.k0;
270 schCellCfg.schInitialDlBwp.pdschCommon.mappingType =
271 macCellCfg->initialDlBwp.pdschCommon.mappingType;
272 schCellCfg.schInitialDlBwp.pdschCommon.startSymbol =
273 macCellCfg->initialDlBwp.pdschCommon.startSymbol;
274 schCellCfg.schInitialDlBwp.pdschCommon.lengthSymbol =
275 macCellCfg->initialDlBwp.pdschCommon.lengthSymbol;
277 /* fill initial UL BWP */
278 schCellCfg.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialUlBwp.bwp.firstPrb;
279 schCellCfg.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialUlBwp.bwp.numPrb;
280 schCellCfg.schInitialUlBwp.bwp.scs = macCellCfg->initialUlBwp.bwp.scs;
281 schCellCfg.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
282 schCellCfg.schInitialUlBwp.puschCommon.k2 = macCellCfg->initialUlBwp.puschCommon.k2;
283 schCellCfg.schInitialUlBwp.puschCommon.mappingType =
284 macCellCfg->initialUlBwp.puschCommon.mappingType;
285 schCellCfg.schInitialUlBwp.puschCommon.startSymbol =
286 macCellCfg->initialUlBwp.puschCommon.startSymbol;
287 schCellCfg.schInitialUlBwp.puschCommon.lengthSymbol =
288 macCellCfg->initialUlBwp.puschCommon.lengthSymbol;
290 memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
293 FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
295 ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
297 } /* end of MacSchCellCfgReq */
300 /*******************************************************************
302 * @brief Sends Cell config confirm to DU APP
306 * Function : MacSendCellCfgCfm
309 * Sends Cell config confirm to DU APP
311 * @params[in] Response status
314 * ****************************************************************/
315 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
319 MacCellCfgCfm macCellCfgCfm;
321 memset(&pst, 0, sizeof(Pst));
323 GET_CELL_IDX(cellId, cellIdx);
324 macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
325 macCellCfgCfm.rsp = response;
328 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
329 pst.selector = ODU_SELECTOR_LC;
331 (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
336 * @brief Layer Manager Configuration response handler.
340 * Function : MacProcSchCellCfgCfm
342 * This function processes cell configuration to SCH
344 * @param[in] Pst *pst
345 * @param[in] SchCellCfgCfm *schCellCfgCfm
349 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
351 uint16_t *cellId = NULLP;
353 if(schCellCfgCfm->rsp == RSP_OK)
355 cellId = &schCellCfgCfm->cellId;
356 #ifdef INTEL_TIMER_MODE
357 sendToLowerMac(UL_IQ_SAMPLE, 0, (void *)cellId);
359 sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
364 MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
369 /*******************************************************************
371 * @brief MAC handler for config response from PHY
375 * Function : fapiMacConfigRsp
378 * Processes config response from PHY and sends cell config
384 * ****************************************************************/
385 void fapiMacConfigRsp(uint16_t cellId)
387 /* TODO : Processing of config response from PHY */
389 /* Send cell config cfm to DU APP */
390 MacSendCellCfgCfm(cellId, RSP_OK);
393 /**********************************************************************
395 **********************************************************************/