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 /* header include files (.h) */
19 #include "common_def.h"
22 #include "du_app_mac_inf.h"
23 #include "mac_sch_interface.h"
24 #include "lwr_mac_upr_inf.h"
25 #include "rlc_mac_inf.h"
27 #include "mac_upr_inf_api.h"
29 #include "lwr_mac_fsm.h"
30 #include "mac_utils.h"
32 /* function pointers for packing slot ind from mac to sch */
33 MacSchSlotIndFunc macSchSlotIndOpts[] =
41 * @brief process DL allocation from scheduler
45 * Function : MacProcDlAlloc
47 * This function copied dl sch info in the mac slot info
50 * @param[in] DL allocation from scheduler
55 uint8_t MacProcDlAlloc(Pst *pst, DlSchedInfo *dlSchedInfo)
57 uint8_t schInfoIdx = 0;
58 uint8_t ueId = 0, ueIdx = 0;
60 MacDlSlot *currDlSlot = NULLP;
62 #ifdef CALL_FLOW_DEBUG_LOG
63 DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_DL_SCH_INFO\n");
65 if(dlSchedInfo != NULLP)
67 GET_CELL_IDX(dlSchedInfo->cellId, cellIdx);
68 if(dlSchedInfo->isBroadcastPres)
70 currDlSlot = &macCb.macCell[cellIdx]->\
71 dlSlot[dlSchedInfo->schSlotValue.broadcastTime.slot];
72 currDlSlot->dlInfo.isBroadcastPres = true;
73 memcpy(&currDlSlot->dlInfo.brdcstAlloc, &dlSchedInfo->brdcstAlloc, sizeof(DlBrdcstAlloc));
74 currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdcchCfg.dci.pdschCfg = \
75 &currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdschCfg;
78 for(ueIdx=0; ueIdx<MAX_NUM_UE; ueIdx++)
80 if(dlSchedInfo->rarAlloc[ueIdx] != NULLP)
82 currDlSlot = &macCb.macCell[cellIdx]->dlSlot[dlSchedInfo->schSlotValue.rarTime.slot];
83 currDlSlot->dlInfo.rarAlloc[ueIdx] = dlSchedInfo->rarAlloc[ueIdx];
86 fillRarPdu(&currDlSlot->dlInfo.rarAlloc[ueIdx]->rarInfo);
89 if(dlSchedInfo->dlMsgAlloc[ueIdx] != NULLP)
91 currDlSlot = &macCb.macCell[cellIdx]->\
92 dlSlot[dlSchedInfo->schSlotValue.dlMsgTime.slot];
93 currDlSlot->dlInfo.dlMsgAlloc[ueIdx] = dlSchedInfo->dlMsgAlloc[ueIdx]; /* copy msg4 alloc pointer in MAC slot info */
94 currDlSlot->dlInfo.cellId = dlSchedInfo->cellId;
96 /* Check if the downlink pdu is msg4 */
97 for(schInfoIdx=0; schInfoIdx < dlSchedInfo->dlMsgAlloc[ueIdx]->numSchedInfo; schInfoIdx++)
99 if(dlSchedInfo->dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.isMsg4Pdu)
101 GET_UE_ID(dlSchedInfo->dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.crnti, ueId);
103 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize = \
104 dlSchedInfo->dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].dlMsgPdschCfg.codeword[0].tbSize;
108 memcpy(&currDlSlot->dlInfo.schSlotValue, &dlSchedInfo->schSlotValue, sizeof(SchSlotValue));
109 /* Send LC schedule result to RLC */
110 if((dlSchedInfo->dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].pduPres == PDSCH_PDU) ||
111 (dlSchedInfo->dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].pduPres == BOTH))
112 sendSchedRptToRlc(currDlSlot->dlInfo, dlSchedInfo->schSlotValue.dlMsgTime, ueIdx, schInfoIdx);
118 if(dlSchedInfo->ulGrant != NULLP)
120 currDlSlot = &macCb.macCell[cellIdx]->\
121 dlSlot[dlSchedInfo->schSlotValue.ulDciTime.slot];
122 currDlSlot->dlInfo.ulGrant = dlSchedInfo->ulGrant;
129 * @brief process DL Paging allocation from scheduler
133 * Function : MacProcDlPageAlloc
135 * This function copied dl Pag info in the mac slot info
137 * @param[in] Pst *pst
138 * @param[in] DL Paging allocation from scheduler
143 uint8_t MacProcDlPageAlloc(Pst *pst, DlPageAlloc *dlPageAlloc)
145 uint16_t cellIdx = 0;
146 MacDlSlot *currDlSlot = NULLP;
148 #ifdef CALL_FLOW_DEBUG_LOG
149 DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_DL_PAGING_ALLOC\n");
151 if(dlPageAlloc != NULLP)
153 GET_CELL_IDX(dlPageAlloc->cellId, cellIdx);
155 currDlSlot = &macCb.macCell[cellIdx]->dlSlot[dlPageAlloc->dlPageTime.slot];
156 MAC_ALLOC(currDlSlot->pageAllocInfo, sizeof(DlPageAlloc));
157 if(currDlSlot->pageAllocInfo == NULLP)
159 DU_LOG("\nERROR --> MAC : MacProcDlPageAlloc : Memory Allocation is failed!");
162 memcpy(currDlSlot->pageAllocInfo, dlPageAlloc, sizeof(DlPageAlloc));
163 currDlSlot->pageAllocInfo->pagePdcchCfg.dci.pdschCfg = \
164 &currDlSlot->pageAllocInfo->pagePdschCfg;
168 DU_LOG("\nERROR --> MAC : DL Paging Allocation is failed!");
175 * @brief Forming and filling the MUX Pdu
178 * Function : fillMsg4Pdu
180 * Forming and filling of Msg4Pdu
182 * @param[in] DlMsgAlloc *msg4Alloc
185 void fillMsg4Pdu(uint16_t cellId, DlMsgSchInfo *msg4SchInfo)
187 uint8_t ueId = 0, ueIdx = 0;
189 uint16_t msg4TxPduLen;
190 MacDlData msg4DlData;
193 GET_CELL_IDX(cellId, cellIdx);
195 memset(&msg4DlData, 0, sizeof(MacDlData));
196 memset(&macCeData, 0, sizeof(MacCeInfo));
198 GET_UE_ID(msg4SchInfo->dlMsgInfo.crnti, ueId);
201 if(macCb.macCell[cellIdx] == NULLP)
203 DU_LOG("\nERROR --> MAC: Cell Id[%d] not found", cellId);
207 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu != NULLP)
209 MAC_ALLOC(msg4DlData.pduInfo[msg4DlData.numPdu].dlPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
210 if(msg4DlData.pduInfo[msg4DlData.numPdu].dlPdu != NULLP)
212 msg4TxPduLen = macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize - TX_PAYLOAD_HDR_LEN;
214 fillMsg4DlData(&msg4DlData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen, \
215 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu);
216 fillMacCe(&macCeData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg3Pdu);
217 /* Forming Mux Pdu */
218 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu = NULLP;
219 MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, msg4TxPduLen);
220 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu != NULLP)
222 memset(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, 0, msg4TxPduLen);
223 macMuxPdu(&msg4DlData, &macCeData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, msg4TxPduLen);
227 DU_LOG("\nERROR --> MAC: Failed allocating memory for msg4TxPdu");
229 /* Free memory allocated */
230 MAC_FREE(msg4DlData.pduInfo[msg4DlData.numPdu-1].dlPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
235 /* storing msg4 Pdu in macDlSlot */
236 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu)
238 msg4SchInfo->dlMsgInfo.dlMsgPduLen = msg4TxPduLen;
239 MAC_ALLOC(msg4SchInfo->dlMsgInfo.dlMsgPdu, msg4SchInfo->dlMsgInfo.dlMsgPduLen);
240 if(msg4SchInfo->dlMsgInfo.dlMsgPdu != NULLP)
242 memcpy(msg4SchInfo->dlMsgInfo.dlMsgPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
243 msg4SchInfo->dlMsgInfo.dlMsgPduLen);
248 DU_LOG("\nERROR --> MAC: Failed at fillMsg4Pdu()");
253 * @brief Builds and Send the Muxed Pdu to Lower MAC
257 * Function : buildAndSendMuxPdu
259 * Build and Sends the Muxed Pdu to Lower MAC.
261 * @param[in] SlotTimingInfo *slotInd
265 void buildAndSendMuxPdu(SlotTimingInfo currTimingInfo)
270 MacDlSlot *currDlSlot = NULLP;
271 SlotTimingInfo muxTimingInfo;
272 memset(&muxTimingInfo, 0, sizeof(SlotTimingInfo));
274 GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
276 ADD_DELTA_TO_TIME(currTimingInfo, muxTimingInfo, PHY_DELTA_DL);
277 currDlSlot = &macCb.macCell[cellIdx]->dlSlot[muxTimingInfo.slot];
279 for(ueIdx=0; ueIdx<MAX_NUM_UE; ueIdx++)
281 if(currDlSlot->dlInfo.dlMsgAlloc[ueIdx])
283 for(schInfoIdx=0; schInfoIdx<currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->numSchedInfo; schInfoIdx++)
285 if((currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.isMsg4Pdu) &&
286 ((currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].pduPres == PDSCH_PDU) ||
287 (currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].pduPres == BOTH)))
289 fillMsg4Pdu(currTimingInfo.cellId, &currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx]);
297 * @brief Transmission time interval indication from PHY.
301 * Function : sendSlotIndMacToSch
303 * This API is invoked by MAC to send slot ind to scheduler.
305 * @param[in] SlotTimingInfo *slotInd
310 int sendSlotIndMacToSch(SlotTimingInfo *slotInd)
312 /* fill Pst structure to send to lwr_mac to MAC */
315 FILL_PST_MAC_TO_SCH(pst, EVENT_SLOT_IND_TO_SCH);
316 return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
319 /*******************************************************************
321 * @brief Send cell up indication to DU APP
325 * Function : sendCellUpIndMacToDuApp
328 * Send cell up indication to DU APP
330 * @params[in] Cell Up indication info
331 * @return ROK - success
334 * ****************************************************************/
335 int sendCellUpIndMacToDuApp(uint16_t cellId)
339 OduCellId *oduCellId;
341 /* Allocate sharable memory */
342 MAC_ALLOC_SHRABL_BUF(oduCellId, sizeof(OduCellId));
345 DU_LOG("\nERROR --> MAC : Memory allocation failed for cell up indication");
348 oduCellId->cellId = cellId;
351 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_UP_IND);
353 ret = MacDuAppCellUpInd(&pst, oduCellId);
356 DU_LOG("\nERROR --> MAC: Failed to send cell up indication to DU APP");
357 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, oduCellId, sizeof(OduCellId));
361 } /* sendCellUpIndMacToDuApp */
363 /*******************************************************************
365 * @brief Send slot indication to DU APP
369 * Function : sendSlotIndToDuApp
372 * Send cell up indication to DU APP
374 * @params[in] Cell Up indication info
375 * @return ROK - success
378 * ****************************************************************/
379 uint8_t sendSlotIndToDuApp(SlotTimingInfo *slotInd)
383 SlotTimingInfo *slotIndInfo;
385 /* Allocate sharable memory */
386 MAC_ALLOC_SHRABL_BUF(slotIndInfo, sizeof(SlotTimingInfo));
389 DU_LOG("\nERROR --> MAC : Memory allocation failed for slot indication");
392 memcpy(slotIndInfo, slotInd,sizeof(SlotTimingInfo));
395 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_SLOT_IND);
397 ret = MacDuAppSlotInd(&pst, slotIndInfo);
400 DU_LOG("\nERROR --> MAC: Failed to send slot up indication to DU APP");
401 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, slotIndInfo, sizeof(SlotTimingInfo));
406 /*******************************************************************
408 * @brief Process slot indication at MAC
412 * Function : macProcSlotInd
414 * Functionality: Process slot indication at MAC
416 * @params[in] Slot indication info
417 * @return ROK - success
420 * ****************************************************************/
421 uint8_t macProcSlotInd(SlotTimingInfo slotInd)
423 uint16_t cellIdx = 0;
425 GET_CELL_IDX(slotInd.cellId, cellIdx);
427 if(macCb.macCell[cellIdx] == NULLP)
429 DU_LOG("ERROR --> MAC : macProcSlotInd(): CellId[%d] does not exist. Error occurred at SFN [%d] Slot [%d]",\
430 slotInd.cellId, slotInd.sfn, slotInd.slot);
433 /* Store current time info */
434 macCb.macCell[cellIdx]->currTime.cellId = slotInd.cellId;
435 macCb.macCell[cellIdx]->currTime.slot = slotInd.slot;
436 macCb.macCell[cellIdx]->currTime.sfn = slotInd.sfn;
438 /* Mux Pdu for Msg4 */
439 buildAndSendMuxPdu(slotInd);
441 /* Trigger for DL TTI REQ */
442 fillDlTtiReq(slotInd);
445 } /* macProcSlotInd */
448 * @brief Transmission time interval indication from PHY.
452 * Function : fapiMacSlotInd
454 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
456 * @param[in] Pst *pst
457 * @param[in] SuId suId
458 * @param[in] SlotTimingInfo *slotInd
463 uint8_t fapiMacSlotInd(Pst *pst, SlotTimingInfo *slotInd)
467 volatile uint32_t startTime=0;
469 #ifdef ODU_SLOT_IND_DEBUG_LOG
470 DU_LOG("\nDEBUG --> MAC : Slot Indication received. [%d : %d]", slotInd->sfn, slotInd->slot);
473 ODU_START_TASK(&startTime, PID_MAC_TTI_IND);
478 GET_CELL_IDX(slotInd->cellId, cellIdx);
479 macCb.macCell[cellIdx]->state = CELL_STATE_UP;
482 /* When testing L2 with Intel-L1, any changes specific to
483 * timer mode testing must be guarded under INTEL_TIMER_MODE*/
484 #ifndef INTEL_TIMER_MODE
485 /* send slot indication to scheduler */
486 ret = sendSlotIndMacToSch(slotInd);
489 DU_LOG("\nERROR --> MAC : Sending of slot ind msg from MAC to SCH failed");
490 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotTimingInfo));
494 ret = macProcSlotInd(*slotInd);
497 DU_LOG("\nERROR --> MAC : macProcSlotInd failed");
498 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotTimingInfo));
503 /*First Slot Ind is for CellUp. Any other Slot, will be notified to DUAPP as
507 /* send cell up indication to du app */
508 ret = sendCellUpIndMacToDuApp(slotInd->cellId);
513 /* send slot indication to du app */
514 ret = sendSlotIndToDuApp(slotInd);
519 DU_LOG("\nERROR --> MAC :Sending of slot ind msg from MAC to DU APP failed");
520 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotTimingInfo));
525 ODU_STOP_TASK(startTime, PID_MAC_TTI_IND);
526 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotTimingInfo));
529 lwrMacCb.phySlotIndCntr++;
530 if(lwrMacCb.phySlotIndCntr > WLS_MEM_FREE_PRD)
532 lwrMacCb.phySlotIndCntr = 1;
534 freeWlsBlockList(lwrMacCb.phySlotIndCntr - 1);
538 } /* fapiMacSlotInd */
540 /**********************************************************************
542 **********************************************************************/