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 "mac_upr_inf_api.h"
29 #include "lwr_mac_fsm.h"
30 #include "mac_utils.h"
32 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg);
34 packMacCellCfgConfirm packMacCellCfmOpts[] =
36 packMacCellCfgCfm, /* packing for loosely coupled */
37 duHandleMacCellCfgCfm, /* packing for tightly coupled */
38 packMacCellCfgCfm, /* packing for light weight loosly coupled */
41 SchCellCfgFunc SchCellCfgOpts[] =
43 packSchCellCfg, /* packing for loosely coupled */
44 SchHdlCellCfgReq, /* packing for tightly coupled */
45 packSchCellCfg /* packing for light weight loosly coupled */
50 * @brief Layer Manager Configuration request handler for Scheduler
54 * Function : MacSchGenCfgReq
56 * This function receives general configurations for Scheduler
57 * from DU APP and forwards to Scheduler.
59 * @param[in] Pst *pst, the post structure
60 * @param[in] RgMngmt *cfg, the configuration parameter's structure
64 PUBLIC int MacSchGenCfgReq(Pst *pst, RgMngmt *cfg)
66 printf("\nReceived Scheduler gen config at MAC");
67 pst->dstInst = DEFAULT_CELLS + 1;
68 SchProcGenCfgReq(pst, cfg);
74 * @brief Layer Manager Configuration response from Scheduler
78 * Function : SchSendCfgCfm
80 * This function sends general configurations response from
81 * Scheduler to DU APP.
83 * @param[in] Pst *pst, the post structure
84 * @param[in] RgMngmt *cfm, the configuration confirm structure
88 PUBLIC uint8_t SchSendCfgCfm(Pst *pst, RgMngmt *cfm)
90 printf("\nSending Scheduler config confirm to DU APP");
91 pst->dstEnt = ENTDUAPP;
94 pst->selector = ODU_SELECTOR_LC;
95 RgMiLrgSchCfgCfm(pst, cfm);
101 * @brief Layer Manager Configuration request handler.
105 * Function : MacProcCellCfgReq
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
111 * @param[in] Pst *pst
112 * @param[in] MacCellCfg *macCellCfg
116 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
121 MacCellCb *macCellCb;
123 cmMemset((uint8_t *)&cfmPst, 0, sizeof(Pst));
125 MAC_ALLOC(macCellCb, sizeof(MacCellCb));
126 if(macCellCb == NULLP)
128 DU_LOG("\nMAC : macCellCb is NULL at handling of macCellCfg\n");
131 memset(macCellCb, 0, sizeof(MacCellCb));
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));
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)
142 DU_LOG("\nMAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
145 memcpy(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, macCellCfg->sib1Cfg.sib1Pdu, \
146 macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
148 /* Send cell cfg to scheduler */
149 ret = MacSchCellCfgReq(pst, macCellCfg);
152 MacCellCfgCfm macCellCfgCfm;
153 macCellCfgCfm.rsp = RSP_NOK;
154 macCellCfgCfm.cellId = macCellCfg->cellId;
156 FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
157 cfmPst.selector = ODU_SELECTOR_LC;
159 ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
163 if(macCellCfg->prachCfg.fdm[0].numUnusedRootSeq != 0)
165 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg->prachCfg.fdm[0].unsuedRootSeq,
166 macCellCfg->prachCfg.fdm[0].numUnusedRootSeq* sizeof(uint8_t));
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));
172 LwrMacEnqueueWlsBlock();
175 } /* end of MacProcCellCfgReq */
178 * @brief Layer Manager Configuration request handler.
182 * Function : MacSchCellCfgReq
184 * This function sends cell configuration to SCH
186 * @param[in] Pst *pst
187 * @param[in] MacCellCfg *macCellCfg
191 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
193 SchCellCfg schCellCfg;
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;
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++)
211 schCellCfg.ssbSchCfg.nSSBMask[idx] = macCellCfg->ssbCfg.ssbMask[idx];
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;
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;
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;
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;
285 FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
287 ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
289 } /* end of MacSchCellCfgReq */
292 /*******************************************************************
294 * @brief Sends Cell config confirm to DU APP
298 * Function : MacSendCellCfgCfm
301 * Sends Cell config confirm to DU APP
303 * @params[in] Response status
306 * ****************************************************************/
307 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
311 MacCellCfgCfm macCellCfgCfm;
313 cmMemset((uint8_t *)&pst, 0, sizeof(Pst));
315 GET_CELL_IDX(cellId, cellIdx);
316 macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
317 macCellCfgCfm.rsp = response;
320 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
321 pst.selector = ODU_SELECTOR_LC;
323 (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
328 * @brief Layer Manager Configuration response handler.
332 * Function : MacProcSchCellCfgCfm
334 * This function processes cell configuration to SCH
336 * @param[in] Pst *pst
337 * @param[in] SchCellCfgCfm *schCellCfgCfm
341 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
343 uint16_t *cellId = NULLP;
345 if(schCellCfgCfm->rsp == RSP_OK)
347 cellId = &schCellCfgCfm->cellId;
348 sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
352 MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
357 /*******************************************************************
359 * @brief MAC handler for config response from PHY
363 * Function : fapiMacConfigRsp
366 * Processes config response from PHY and sends cell config
372 * ****************************************************************/
373 void fapiMacConfigRsp(uint16_t cellId)
375 /* TODO : Processing of config response from PHY */
377 /* Send cell config cfm to DU APP */
378 MacSendCellCfgCfm(cellId, RSP_OK);
381 /**********************************************************************
383 **********************************************************************/