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"
28 #include "lwr_mac_fsm.h"
29 #include "mac_utils.h"
31 /* function pointers for packing slot ind from mac to sch */
32 MacSchSlotIndFunc macSchSlotIndOpts[] =
40 * @brief process DL allocation from scheduler
44 * Function : MacProcDlAlloc
46 * This function copied dl sch info in the mac slot info
49 * @param[in] DL allocation from scheduler
54 uint8_t MacProcDlAlloc(Pst *pst, DlSchedInfo *dlSchedInfo)
57 MacDlSlot *currDlSlot = NULLP;
59 if(dlSchedInfo != NULLP)
61 GET_CELL_IDX(dlSchedInfo->cellId, cellIdx);
62 if(dlSchedInfo->isBroadcastPres)
64 currDlSlot = &macCb.macCell[cellIdx]->\
65 dlSlot[dlSchedInfo->schSlotValue.broadcastTime.slot];
66 currDlSlot->dlInfo.isBroadcastPres = true;
67 memcpy(&currDlSlot->dlInfo.brdcstAlloc, &dlSchedInfo->brdcstAlloc, sizeof(DlBrdcstAlloc));
68 currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdcchCfg.dci.pdschCfg = \
69 &currDlSlot->dlInfo.brdcstAlloc.sib1Alloc.sib1PdschCfg;
72 if(dlSchedInfo->rarAlloc != NULLP)
74 currDlSlot = &macCb.macCell[cellIdx]->\
75 dlSlot[dlSchedInfo->schSlotValue.rarTime.slot];
76 currDlSlot->dlInfo.rarAlloc = dlSchedInfo->rarAlloc;
79 fillRarPdu(&currDlSlot->dlInfo.rarAlloc->rarInfo);
82 if(dlSchedInfo->dlMsgAlloc != NULLP)
84 currDlSlot = &macCb.macCell[cellIdx]->\
85 dlSlot[dlSchedInfo->schSlotValue.dlMsgTime.slot];
86 currDlSlot->dlInfo.dlMsgAlloc = dlSchedInfo->dlMsgAlloc; /* copy msg4 alloc pointer in MAC slot info */
87 currDlSlot->dlInfo.cellId = dlSchedInfo->cellId;
89 /* Check if the downlink pdu is msg4 */
90 if(dlSchedInfo->dlMsgAlloc->dlMsgInfo.isMsg4Pdu)
92 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize = dlSchedInfo->dlMsgAlloc->dlMsgPdschCfg.codeword[0].tbSize;
96 memcpy(&currDlSlot->dlInfo.schSlotValue, &dlSchedInfo->schSlotValue, sizeof(SchSlotValue));
97 /* Send LC schedule result to RLC */
98 sendSchedRptToRlc(currDlSlot->dlInfo, dlSchedInfo->schSlotValue.dlMsgTime);
102 if(dlSchedInfo->ulGrant != NULLP)
104 currDlSlot = &macCb.macCell[cellIdx]->\
105 dlSlot[dlSchedInfo->schSlotValue.ulDciTime.slot];
106 currDlSlot->dlInfo.ulGrant = dlSchedInfo->ulGrant;
113 * @brief Forming anf filling the MUX Pdu
116 * Function : fillMsg4Pdu
118 * Forming and filling of Msg4Pdu
120 * @param[in] DlMsgAlloc *msg4Alloc
123 void fillMsg4Pdu(uint16_t cellId, DlMsgAlloc *msg4Alloc)
127 MacDlData msg4DlData;
130 GET_CELL_IDX(cellId, cellIdx);
132 memset(&msg4DlData, 0, sizeof(MacDlData));
133 memset(&macCeData, 0, sizeof(MacCeInfo));
135 GET_UE_IDX(msg4Alloc->dlMsgInfo.crnti, ueIdx);
137 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu != NULLP)
139 MAC_ALLOC(msg4DlData.pduInfo[ueIdx].dlPdu, \
140 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
141 if(msg4DlData.pduInfo[ueIdx].dlPdu != NULLP)
143 fillMsg4DlData(&msg4DlData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen,\
144 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu);
145 fillMacCe(&macCeData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg3Pdu);
146 /* Forming Mux Pdu */
147 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu = NULLP;
148 MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
149 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize);
150 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu != NULLP)
152 memset(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, 0, \
153 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize);
154 macMuxPdu(&msg4DlData, &macCeData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu,\
155 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize);
160 DU_LOG("\nMAC: Failed allocating memory for msg4TxPdu");
162 /* Free memory allocated */
163 MAC_FREE(msg4DlData.pduInfo[0].dlPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
167 /* storing msg4 Pdu in macDlSlot */
168 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu)
170 msg4Alloc->dlMsgInfo.dlMsgPduLen = macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize;
171 MAC_ALLOC(msg4Alloc->dlMsgInfo.dlMsgPdu, msg4Alloc->dlMsgInfo.dlMsgPduLen);
172 if(msg4Alloc->dlMsgInfo.dlMsgPdu != NULLP)
174 memcpy(msg4Alloc->dlMsgInfo.dlMsgPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
175 msg4Alloc->dlMsgInfo.dlMsgPduLen);
180 DU_LOG("\nMAC: Failed at macMuxPdu()");
185 * @brief Builds and Send the Muxed Pdu to Lower MAC
189 * Function : buildAndSendMuxPdu
191 * Build and Sends the Muxed Pdu to Lower MAC.
193 * @param[in] SlotIndInfo *slotInd
197 void buildAndSendMuxPdu(SlotIndInfo currTimingInfo)
200 MacDlSlot *currDlSlot = NULLP;
201 SlotIndInfo muxTimingInfo;
202 memset(&muxTimingInfo, 0, sizeof(SlotIndInfo));
204 GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
206 ADD_DELTA_TO_TIME(currTimingInfo, muxTimingInfo, PHY_DELTA);
207 currDlSlot = &macCb.macCell[cellIdx]->dlSlot[muxTimingInfo.slot];
208 if(currDlSlot->dlInfo.dlMsgAlloc)
210 if(currDlSlot->dlInfo.dlMsgAlloc->dlMsgInfo.isMsg4Pdu)
212 fillMsg4Pdu(currTimingInfo.cellId, currDlSlot->dlInfo.dlMsgAlloc);
219 * @brief Transmission time interval indication from PHY.
223 * Function : sendSlotIndMacToSch
225 * This API is invoked by MAC to send slot ind to scheduler.
227 * @param[in] SlotIndInfo *slotInd
232 int sendSlotIndMacToSch(SlotIndInfo *slotInd)
234 /* fill Pst structure to send to lwr_mac to MAC */
237 FILL_PST_MAC_TO_SCH(pst, EVENT_SLOT_IND_TO_SCH);
238 return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
241 /*******************************************************************
243 * @brief Send slot indication to DU APP
247 * Function : sendSlotIndMacToDuApp
250 * Send slot indication to DU APP
252 * @params[in] Slot indication info
253 * @return ROK - success
256 * ****************************************************************/
257 int sendSlotIndMacToDuApp(SlotIndInfo *slotInd)
261 SlotIndInfo *slotInfo;
263 /* Allocate sharable memory */
264 MAC_ALLOC_SHRABL_BUF(slotInfo, sizeof(SlotIndInfo));
267 DU_LOG("\nMAC : Slot Indication memory allocation failed");
271 slotInfo->cellId = slotInd->cellId;
272 slotInfo->sfn = slotInd->sfn;
273 slotInfo->slot = slotInd->slot;
276 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_SLOT_IND);
278 ret = MacDuAppSlotInd(&pst, slotInfo);
281 DU_LOG("\nMAC: Failed to send slot indication to DU APP");
282 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, slotInfo, sizeof(SlotIndInfo));
286 } /* sendSlotIndMacToDuApp */
288 /*******************************************************************
290 * @brief Process slot indication at MAC
294 * Function : macProcSlotInd
296 * Functionality: Process slot indication at MAC
298 * @params[in] Slot indication info
299 * @return ROK - success
302 * ****************************************************************/
303 uint8_t macProcSlotInd(SlotIndInfo slotInd)
307 GET_CELL_IDX(slotInd.cellId, cellIdx);
309 /* Store current time info */
310 macCb.macCell[cellIdx]->currTime.cellId = slotInd.cellId;
311 macCb.macCell[cellIdx]->currTime.slot = slotInd.slot;
312 macCb.macCell[cellIdx]->currTime.sfn = slotInd.sfn;
314 /* Mux Pdu for Msg4 */
315 buildAndSendMuxPdu(slotInd);
317 /* Trigger for DL TTI REQ */
318 fillDlTtiReq(slotInd);
320 /* Trigger for UL TTI REQ */
321 fillUlTtiReq(slotInd);
323 /* Trigger for UL DCI REQ */
324 fillUlDciReq(slotInd);
327 } /* macProcSlotInd */
330 * @brief Transmission time interval indication from PHY.
334 * Function : fapiMacSlotInd
336 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
338 * @param[in] Pst *pst
339 * @param[in] SuId suId
340 * @param[in] SlotIndInfo *slotInd
345 uint8_t fapiMacSlotInd(Pst *pst, SlotIndInfo *slotInd)
348 volatile uint32_t startTime=0;
350 #ifdef ODU_SLOT_IND_DEBUG_LOG
351 DU_LOG("\nMAC : Slot Indication received");
354 ODU_START_TASK(&startTime, PID_MAC_TTI_IND);
356 /* When testing L2 with Intel-L1, any changes specific to
357 * timer mode testing must be guarded under INTEL_TIMER_MODE*/
358 #ifndef INTEL_TIMER_MODE
359 /* send slot indication to scheduler */
360 ret = sendSlotIndMacToSch(slotInd);
363 DU_LOG("\nMAC : Sending of slot ind msg from MAC to SCH failed");
364 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotIndInfo));
368 ret = macProcSlotInd(*slotInd);
371 DU_LOG("\nMAC : macProcSlotInd failed");
372 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotIndInfo));
377 /* send slot indication to du app */
378 ret = sendSlotIndMacToDuApp(slotInd);
381 DU_LOG("\nMAC :Sending of slot ind msg from MAC to DU APP failed");
382 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotIndInfo));
387 ODU_STOP_TASK(startTime, PID_MAC_TTI_IND);
388 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotIndInfo));
390 } /* fapiMacSlotInd */
392 /**********************************************************************
394 **********************************************************************/