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 */
52 MacSchCellDeleteReqFunc macSchCellDeleteReqOpts[]=
54 packMacSchCellDeleteReq, /* packing for loosely coupled */
55 MacSchCellDeleteReq, /* packing for tightly coupled */
56 packMacSchCellDeleteReq /* packing for light weight loosely coupled */
59 MacDuCellDeleteRspFunc macDuCellDeleteRspOpts[] =
61 packDuMacCellDeleteRsp, /* packing for loosely coupled */
62 DuProcMacCellDeleteRsp, /* packing for tightly coupled */
63 packDuMacCellDeleteRsp /* packing for light weight loosly coupled */
67 * @brief Layer Manager Configuration request handler for Scheduler
71 * Function : MacSchGenCfgReq
73 * This function receives general configurations for Scheduler
74 * from DU APP and forwards to Scheduler.
76 * @param[in] Pst *pst, the post structure
77 * @param[in] RgMngmt *cfg, the configuration parameter's structure
81 uint8_t MacSchGenCfgReq(Pst *pst, RgMngmt *cfg)
83 printf("\nReceived Scheduler gen config at MAC");
84 pst->dstInst = DEFAULT_CELLS + 1;
85 SchProcGenCfgReq(pst, cfg);
91 * @brief Layer Manager Configuration response from Scheduler
95 * Function : SchSendCfgCfm
97 * This function sends general configurations response from
98 * Scheduler to DU APP.
100 * @param[in] Pst *pst, the post structure
101 * @param[in] RgMngmt *cfm, the configuration confirm structure
105 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt *cfm)
107 DU_LOG("\nDEBUG --> Sending Scheduler config confirm to DU APP");
108 pst->dstEnt = ENTDUAPP;
111 pst->selector = ODU_SELECTOR_LC;
112 RgMiLrgSchCfgCfm(pst, cfm);
118 * @brief Layer Manager Configuration request handler.
122 * Function : MacProcCellCfgReq
124 * This function handles the gNB and cell configuration
125 * request received from DU APP.
126 * This API unapcks and forwards the config towards SCH
128 * @param[in] Pst *pst
129 * @param[in] MacCellCfg *macCellCfg
133 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
138 MacCellCb *macCellCb;
140 memset((uint8_t *)&cfmPst, 0, sizeof(Pst));
142 MAC_ALLOC(macCellCb, sizeof(MacCellCb));
143 if(macCellCb == NULLP)
145 DU_LOG("\nERROR --> MAC : macCellCb is NULL at handling of macCellCfg\n");
148 memset(macCellCb, 0, sizeof(MacCellCb));
150 GET_CELL_IDX(macCellCfg->cellId, cellIdx);
151 macCb.macCell[cellIdx] = macCellCb;
152 macCb.macCell[cellIdx]->cellId = macCellCfg->cellId;
153 memcpy(&macCb.macCell[cellIdx]->macCellCfg, macCellCfg, sizeof(MacCellCfg));
155 MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
156 macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
157 if(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu == NULLP)
159 DU_LOG("\nERROR --> MAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
162 memcpy(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, macCellCfg->sib1Cfg.sib1Pdu, \
163 macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
165 /* Send cell cfg to scheduler */
166 ret = MacSchCellCfgReq(pst, macCellCfg);
169 MacCellCfgCfm macCellCfgCfm;
170 macCellCfgCfm.rsp = RSP_NOK;
171 macCellCfgCfm.cellId = macCellCfg->cellId;
173 FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
174 cfmPst.selector = ODU_SELECTOR_LC;
176 ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
180 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
183 } /* end of MacProcCellCfgReq */
186 * @brief Layer Manager Configuration request handler.
190 * Function : MacSchCellCfgReq
192 * This function sends cell configuration to SCH
194 * @param[in] Pst *pst
195 * @param[in] MacCellCfg *macCellCfg
199 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
201 SchCellCfg schCellCfg;
205 memset(&cfgPst, 0, sizeof(Pst));
206 memset(&schCellCfg, 0, sizeof(SchCellCfg));
207 schCellCfg.cellId = macCellCfg->cellId;
208 schCellCfg.phyCellId = macCellCfg->phyCellId;
209 schCellCfg.numerology = macCellCfg->numerology;
210 schCellCfg.dupMode = macCellCfg->dupType;
211 schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
212 schCellCfg.dlFreq = macCellCfg->dlCarrCfg.freq;
213 schCellCfg.ulFreq = macCellCfg->ulCarrCfg.freq;
215 /* fill ssb scheduler parameters */
216 schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
217 schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
218 schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
219 schCellCfg.ssbSchCfg.ssbPeriod = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
220 schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
221 for(uint8_t idx=0; idx<SSB_MASK_SIZE; idx++)
223 schCellCfg.ssbSchCfg.nSSBMask[idx] = macCellCfg->ssbCfg.ssbMask[idx];
226 /* fill SIB1 scheduler parameters */
227 schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen;
228 schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod;
229 schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex;
230 schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex;
231 schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs;
233 /* fill RACH config params */
234 schCellCfg.schRachCfg.prachCfgIdx = macCellCfg->prachCfg.prachCfgIdx;
235 schCellCfg.schRachCfg.prachSubcSpacing = \
236 macCellCfg->prachCfg.prachSubcSpacing;
237 schCellCfg.schRachCfg.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
238 schCellCfg.schRachCfg.msg1Fdm = macCellCfg->prachCfg.msg1Fdm;
239 schCellCfg.schRachCfg.rootSeqLen = macCellCfg->prachCfg.rootSeqLen;
240 schCellCfg.schRachCfg.rootSeqIdx = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
241 schCellCfg.schRachCfg.numRootSeq = macCellCfg->prachCfg.fdm[0].numRootSeq;
242 schCellCfg.schRachCfg.k1 = macCellCfg->prachCfg.fdm[0].k1;
243 schCellCfg.schRachCfg.ssbPerRach = macCellCfg->prachCfg.ssbPerRach;
244 schCellCfg.schRachCfg.prachMultCarrBand = \
245 macCellCfg->prachCfg.prachMultCarrBand;
246 schCellCfg.schRachCfg.raContResTmr = macCellCfg->prachCfg.raContResTmr;
247 schCellCfg.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
248 schCellCfg.schRachCfg.raRspWindow = macCellCfg->prachCfg.raRspWindow;
250 /* fill initial DL BWP */
251 schCellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialDlBwp.bwp.firstPrb;
252 schCellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialDlBwp.bwp.numPrb;
253 schCellCfg.schInitialDlBwp.bwp.scs = macCellCfg->initialDlBwp.bwp.scs;
254 schCellCfg.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->initialDlBwp.bwp.cyclicPrefix;
255 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
256 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
257 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
258 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
259 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
260 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
261 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
262 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.duration;
263 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
264 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
265 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
266 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
267 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
268 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
269 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
270 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
271 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
272 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
273 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
274 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
275 schCellCfg.schInitialDlBwp.pdschCommon.k0 = macCellCfg->initialDlBwp.pdschCommon.k0;
276 schCellCfg.schInitialDlBwp.pdschCommon.mappingType =
277 macCellCfg->initialDlBwp.pdschCommon.mappingType;
278 schCellCfg.schInitialDlBwp.pdschCommon.startSymbol =
279 macCellCfg->initialDlBwp.pdschCommon.startSymbol;
280 schCellCfg.schInitialDlBwp.pdschCommon.lengthSymbol =
281 macCellCfg->initialDlBwp.pdschCommon.lengthSymbol;
283 /* fill initial UL BWP */
284 schCellCfg.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialUlBwp.bwp.firstPrb;
285 schCellCfg.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialUlBwp.bwp.numPrb;
286 schCellCfg.schInitialUlBwp.bwp.scs = macCellCfg->initialUlBwp.bwp.scs;
287 schCellCfg.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
288 schCellCfg.schInitialUlBwp.puschCommon.k2 = macCellCfg->initialUlBwp.puschCommon.k2;
289 schCellCfg.schInitialUlBwp.puschCommon.mappingType =
290 macCellCfg->initialUlBwp.puschCommon.mappingType;
291 schCellCfg.schInitialUlBwp.puschCommon.startSymbol =
292 macCellCfg->initialUlBwp.puschCommon.startSymbol;
293 schCellCfg.schInitialUlBwp.puschCommon.lengthSymbol =
294 macCellCfg->initialUlBwp.puschCommon.lengthSymbol;
296 memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
299 FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
301 ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
303 } /* end of MacSchCellCfgReq */
306 /*******************************************************************
308 * @brief Sends Cell config confirm to DU APP
312 * Function : MacSendCellCfgCfm
315 * Sends Cell config confirm to DU APP
317 * @params[in] Response status
320 * ****************************************************************/
321 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
325 MacCellCfgCfm macCellCfgCfm;
327 memset(&pst, 0, sizeof(Pst));
329 GET_CELL_IDX(cellId, cellIdx);
330 macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
331 macCellCfgCfm.rsp = response;
334 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
335 pst.selector = ODU_SELECTOR_LC;
337 (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
342 * @brief Layer Manager Configuration response handler.
346 * Function : MacProcSchCellCfgCfm
348 * This function processes cell configuration to SCH
350 * @param[in] Pst *pst
351 * @param[in] SchCellCfgCfm *schCellCfgCfm
355 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
357 uint16_t *cellId = NULLP;
359 if(schCellCfgCfm->rsp == RSP_OK)
361 cellId = &schCellCfgCfm->cellId;
362 #ifdef INTEL_TIMER_MODE
363 sendToLowerMac(UL_IQ_SAMPLE, 0, (void *)cellId);
365 sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
370 MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
375 /*******************************************************************
377 * @brief MAC handler for config response from PHY
381 * Function : fapiMacConfigRsp
384 * Processes config response from PHY and sends cell config
390 * ****************************************************************/
391 void fapiMacConfigRsp(uint16_t cellId)
393 /* TODO : Processing of config response from PHY */
395 /* Send cell config cfm to DU APP */
396 MacSendCellCfgCfm(cellId, RSP_OK);
399 /*******************************************************************
401 * @brief Fill and Send Cell Delete response from MAC to DU APP
405 * Function : MacSendCellDeleteRsp
407 * Functionality: Fill and Send Cell Delete response from MAC to DUAPP
409 * @params[in] MAC Cell delete result
410 * SCH Cell delete response
411 * @return ROK - success
414 * ****************************************************************/
415 uint8_t MacSendCellDeleteRsp(CellDeleteStatus result, uint8_t cellId)
417 MacCellDeleteRsp *deleteRsp=NULLP;
420 MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacCellDeleteRsp));
423 DU_LOG("\nERROR --> MAC : MacSendCellDeleteRsp(): Memory allocation for Cell delete response failed");
427 /* Filling CELL delete response */
429 memset(deleteRsp, 0, sizeof(MacCellDeleteRsp));
430 deleteRsp->cellId = cellId;
431 deleteRsp->result = result;
433 /* Fill Post structure and send CELL delete response*/
434 memset(&rspPst, 0, sizeof(Pst));
435 FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_CELL_DELETE_RSP);
436 return (*macDuCellDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
439 /*******************************************************************
441 * @brief Processes CELL delete response from scheduler
445 * Function : MacProcSchCellDeleteRsp
448 * Processes CELL delete from scheduler
450 * @params[in] Pst : Post structure
451 * schCellDelRsp : Scheduler CELL delete respons
452 * @return ROK - success
455 * * ****************************************************************/
456 uint8_t MacProcSchCellDeleteRsp(Pst *pst, SchCellDeleteRsp *schCellDelRsp)
460 CellDeleteStatus status;
464 if(schCellDelRsp->rsp == RSP_OK)
466 DU_LOG("\nINFO --> MAC : SCH CELL Delete response for cellId[%d] is successful ", \
467 schCellDelRsp->cellId);
468 GET_CELL_IDX(schCellDelRsp->cellId, cellIdx);
469 if(macCb.macCell[cellIdx])
471 if(macCb.macCell[cellIdx]->cellId == schCellDelRsp->cellId)
473 memset(macCb.macCell[cellIdx], 0, sizeof(MacCellCb));
474 status = SUCCESSFUL_RSP;
475 MAC_FREE(macCb.macCell[cellIdx], sizeof(MacCellCb));
479 DU_LOG("ERROR --> MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
480 status = CELL_ID_INVALID;
486 DU_LOG("ERROR --> MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
487 status = CELL_ID_INVALID;
493 DU_LOG("ERROR --> MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
494 status = CELL_ID_INVALID;
497 if(MacSendCellDeleteRsp(status, schCellDelRsp->cellId) != ROK)
499 DU_LOG("\nERROR --> MAC: MacProcSchCellDeleteRsp(): Failed to send CELL delete response");
506 DU_LOG("\nERROR --> MAC: MacProcSchCellDeleteRsp(): schCellDelRsp is NULL");
512 /*******************************************************************
514 * @brief Sends Cell delete req to Scheduler
518 * Function : sendCellDelReqToSch
520 * Functionality: sends Cell delete req to Scheduler
522 * @params[in] SchCellDelete *schCellDel
523 * @return ROK - success
526 * ****************************************************************/
528 uint8_t sendCellDelReqToSch(SchCellDelete *schCellDel)
531 FILL_PST_MAC_TO_SCH(schPst, EVENT_CELL_DELETE_REQ_TO_SCH);
532 return(*macSchCellDeleteReqOpts[schPst.selector])(&schPst, schCellDel);
535 /*******************************************************************
537 * @brief Handles CELL Delete requst from DU APP
541 * Function : MacProcCellDeleteReq
543 * Functionality: Handles CELL Delete requst from DU APP
545 * @params[in] Pst *pst, MacCellDelete *cellDelete
546 * @return ROK - success
550 * ****************************************************************/
551 uint8_t MacProcCellDeleteReq(Pst *pst, MacCellDelete *cellDelete)
553 uint8_t ret = ROK, cellIdx=0;
554 SchCellDelete schCellDelete;
556 DU_LOG("\nINFO --> MAC : Cell Delete Request received for cellId[%d]", cellDelete->cellId);
560 GET_CELL_IDX(cellDelete->cellId, cellIdx);
561 if(macCb.macCell[cellIdx])
563 if(macCb.macCell[cellIdx]->cellId == cellDelete->cellId)
565 memset(&schCellDelete, 0, sizeof(SchCellDelete));
566 schCellDelete.cellId = cellDelete->cellId;
567 ret = sendCellDelReqToSch(&schCellDelete);
570 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Failed to send UE Delete Request to SCH");
576 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
583 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
590 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Sending failure response to DU");
591 if(MacSendCellDeleteRsp(CELL_ID_INVALID, cellDelete->cellId) != ROK)
593 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): failed to send cell delete rsp for cellID[%d]",\
598 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellDelete, sizeof(MacCellDelete));
602 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Received MacCellDelete is NULL");
608 /**********************************************************************
610 **********************************************************************/