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)
58 MacDlSlot *currDlSlot = NULLP;
60 if(dlSchedInfo != NULLP)
62 GET_CELL_IDX(dlSchedInfo->cellId, cellIdx);
63 if(dlSchedInfo->isBroadcastPres)
65 currDlSlot = &macCb.macCell[cellIdx]->\
66 dlSlot[dlSchedInfo->schSlotValue.broadcastTime.slot];
67 currDlSlot->dlInfo.isBroadcastPres = true;
68 memcpy(&currDlSlot->dlInfo.brdcstAlloc, &dlSchedInfo->brdcstAlloc, sizeof(DlBrdcstAlloc));
69 currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdcchCfg.dci.pdschCfg = \
70 &currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdschCfg;
73 if(dlSchedInfo->rarAlloc != NULLP)
75 currDlSlot = &macCb.macCell[cellIdx]->\
76 dlSlot[dlSchedInfo->schSlotValue.rarTime.slot];
77 currDlSlot->dlInfo.rarAlloc = dlSchedInfo->rarAlloc;
80 fillRarPdu(&currDlSlot->dlInfo.rarAlloc->rarInfo);
83 if(dlSchedInfo->dlMsgAlloc != NULLP)
85 currDlSlot = &macCb.macCell[cellIdx]->\
86 dlSlot[dlSchedInfo->schSlotValue.dlMsgTime.slot];
87 currDlSlot->dlInfo.dlMsgAlloc = dlSchedInfo->dlMsgAlloc; /* copy msg4 alloc pointer in MAC slot info */
88 currDlSlot->dlInfo.cellId = dlSchedInfo->cellId;
90 /* Check if the downlink pdu is msg4 */
91 if(dlSchedInfo->dlMsgAlloc->dlMsgInfo.isMsg4Pdu)
93 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize = dlSchedInfo->dlMsgAlloc->dlMsgPdschCfg.codeword[0].tbSize;
97 memcpy(&currDlSlot->dlInfo.schSlotValue, &dlSchedInfo->schSlotValue, sizeof(SchSlotValue));
98 /* Send LC schedule result to RLC */
99 sendSchedRptToRlc(currDlSlot->dlInfo, dlSchedInfo->schSlotValue.dlMsgTime);
103 if(dlSchedInfo->ulGrant != NULLP)
105 currDlSlot = &macCb.macCell[cellIdx]->\
106 dlSlot[dlSchedInfo->schSlotValue.ulDciTime.slot];
107 currDlSlot->dlInfo.ulGrant = dlSchedInfo->ulGrant;
114 * @brief Forming anf filling the MUX Pdu
117 * Function : fillMsg4Pdu
119 * Forming and filling of Msg4Pdu
121 * @param[in] DlMsgAlloc *msg4Alloc
124 void fillMsg4Pdu(uint16_t cellId, DlMsgAlloc *msg4Alloc)
128 uint16_t msg4TxPduLen;
129 MacDlData msg4DlData;
132 GET_CELL_IDX(cellId, cellIdx);
134 memset(&msg4DlData, 0, sizeof(MacDlData));
135 memset(&macCeData, 0, sizeof(MacCeInfo));
137 GET_UE_IDX(msg4Alloc->dlMsgInfo.crnti, ueIdx);
140 if(macCb.macCell[cellIdx] == NULLP)
142 DU_LOG("\nERROR --> MAC: Cell Id[%d] not found", cellId);
146 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu != NULLP)
148 MAC_ALLOC(msg4DlData.pduInfo[ueIdx].dlPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
149 if(msg4DlData.pduInfo[ueIdx].dlPdu != NULLP)
151 msg4TxPduLen = macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize - TX_PAYLOAD_HDR_LEN;
153 fillMsg4DlData(&msg4DlData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen, \
154 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu);
155 fillMacCe(&macCeData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg3Pdu);
156 /* Forming Mux Pdu */
157 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu = NULLP;
158 MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, msg4TxPduLen);
159 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu != NULLP)
161 memset(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, 0, msg4TxPduLen);
162 macMuxPdu(&msg4DlData, &macCeData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, msg4TxPduLen);
166 DU_LOG("\nERROR --> MAC: Failed allocating memory for msg4TxPdu");
168 /* Free memory allocated */
169 MAC_FREE(msg4DlData.pduInfo[0].dlPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
173 /* storing msg4 Pdu in macDlSlot */
174 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu)
176 msg4Alloc->dlMsgInfo.dlMsgPduLen = msg4TxPduLen;
177 MAC_ALLOC(msg4Alloc->dlMsgInfo.dlMsgPdu, msg4Alloc->dlMsgInfo.dlMsgPduLen);
178 if(msg4Alloc->dlMsgInfo.dlMsgPdu != NULLP)
180 memcpy(msg4Alloc->dlMsgInfo.dlMsgPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
181 msg4Alloc->dlMsgInfo.dlMsgPduLen);
186 DU_LOG("\nERROR --> MAC: Failed at macMuxPdu()");
191 * @brief Builds and Send the Muxed Pdu to Lower MAC
195 * Function : buildAndSendMuxPdu
197 * Build and Sends the Muxed Pdu to Lower MAC.
199 * @param[in] SlotIndInfo *slotInd
203 void buildAndSendMuxPdu(SlotIndInfo currTimingInfo)
206 MacDlSlot *currDlSlot = NULLP;
207 SlotIndInfo muxTimingInfo;
208 memset(&muxTimingInfo, 0, sizeof(SlotIndInfo));
210 GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
212 ADD_DELTA_TO_TIME(currTimingInfo, muxTimingInfo, PHY_DELTA_DL);
213 currDlSlot = &macCb.macCell[cellIdx]->dlSlot[muxTimingInfo.slot];
214 if(currDlSlot->dlInfo.dlMsgAlloc)
216 if(currDlSlot->dlInfo.dlMsgAlloc->dlMsgInfo.isMsg4Pdu)
218 fillMsg4Pdu(currTimingInfo.cellId, currDlSlot->dlInfo.dlMsgAlloc);
225 * @brief Transmission time interval indication from PHY.
229 * Function : sendSlotIndMacToSch
231 * This API is invoked by MAC to send slot ind to scheduler.
233 * @param[in] SlotIndInfo *slotInd
238 int sendSlotIndMacToSch(SlotIndInfo *slotInd)
240 /* fill Pst structure to send to lwr_mac to MAC */
243 FILL_PST_MAC_TO_SCH(pst, EVENT_SLOT_IND_TO_SCH);
244 return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
247 /*******************************************************************
249 * @brief Send cell up indication to DU APP
253 * Function : sendCellUpIndMacToDuApp
256 * Send cell up indication to DU APP
258 * @params[in] Cell Up indication info
259 * @return ROK - success
262 * ****************************************************************/
263 int sendCellUpIndMacToDuApp(uint16_t cellId)
267 OduCellId *oduCellId;
269 /* Allocate sharable memory */
270 MAC_ALLOC_SHRABL_BUF(oduCellId, sizeof(OduCellId));
273 DU_LOG("\nERROR --> MAC : Memory allocation failed for cell up indication");
276 oduCellId->cellId = cellId;
279 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_UP_IND);
281 ret = MacDuAppCellUpInd(&pst, oduCellId);
284 DU_LOG("\nERROR --> MAC: Failed to send cell up indication to DU APP");
285 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, oduCellId, sizeof(OduCellId));
289 } /* sendCellUpIndMacToDuApp */
291 /*******************************************************************
293 * @brief Process slot indication at MAC
297 * Function : macProcSlotInd
299 * Functionality: Process slot indication at MAC
301 * @params[in] Slot indication info
302 * @return ROK - success
305 * ****************************************************************/
306 uint8_t macProcSlotInd(SlotIndInfo slotInd)
308 uint16_t cellIdx = 0;
310 GET_CELL_IDX(slotInd.cellId, cellIdx);
312 if(macCb.macCell[cellIdx] == NULLP)
314 DU_LOG("ERROR --> MAC : macProcSlotInd(): CellId[%d] does not exist. Error occurred at SFN [%d] Slot [%d]",\
315 slotInd.cellId, slotInd.sfn, slotInd.slot);
318 /* Store current time info */
319 macCb.macCell[cellIdx]->currTime.cellId = slotInd.cellId;
320 macCb.macCell[cellIdx]->currTime.slot = slotInd.slot;
321 macCb.macCell[cellIdx]->currTime.sfn = slotInd.sfn;
323 /* Mux Pdu for Msg4 */
324 buildAndSendMuxPdu(slotInd);
326 /* Trigger for DL TTI REQ */
327 fillDlTtiReq(slotInd);
330 } /* macProcSlotInd */
333 * @brief Transmission time interval indication from PHY.
337 * Function : fapiMacSlotInd
339 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
341 * @param[in] Pst *pst
342 * @param[in] SuId suId
343 * @param[in] SlotIndInfo *slotInd
348 uint8_t fapiMacSlotInd(Pst *pst, SlotIndInfo *slotInd)
352 volatile uint32_t startTime=0;
354 #ifdef ODU_SLOT_IND_DEBUG_LOG
355 DU_LOG("\nDEBUG --> MAC : Slot Indication received. [%d : %d]", slotInd->sfn, slotInd->slot);
358 ODU_START_TASK(&startTime, PID_MAC_TTI_IND);
363 GET_CELL_IDX(slotInd->cellId, cellIdx);
364 macCb.macCell[cellIdx]->state = CELL_STATE_UP;
367 /* When testing L2 with Intel-L1, any changes specific to
368 * timer mode testing must be guarded under INTEL_TIMER_MODE*/
369 #ifndef INTEL_TIMER_MODE
370 /* send slot indication to scheduler */
371 ret = sendSlotIndMacToSch(slotInd);
374 DU_LOG("\nERROR --> MAC : Sending of slot ind msg from MAC to SCH failed");
375 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotIndInfo));
379 ret = macProcSlotInd(*slotInd);
382 DU_LOG("\nERROR --> MAC : macProcSlotInd failed");
383 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotIndInfo));
388 /* send slot indication to du app */
391 ret = sendCellUpIndMacToDuApp(slotInd->cellId);
394 DU_LOG("\nERROR --> MAC :Sending of slot ind msg from MAC to DU APP failed");
395 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotIndInfo));
401 ODU_STOP_TASK(startTime, PID_MAC_TTI_IND);
402 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotIndInfo));
405 lwrMacCb.phySlotIndCntr++;
406 if(lwrMacCb.phySlotIndCntr > WLS_MEM_FREE_PRD)
408 lwrMacCb.phySlotIndCntr = 1;
410 freeWlsBlockList(lwrMacCb.phySlotIndCntr - 1);
414 } /* fapiMacSlotInd */
416 /**********************************************************************
418 **********************************************************************/