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"
26 #include "mac_upr_inf_api.h"
27 #include "lwr_mac_fsm.h"
28 #include "mac_utils.h"
30 /* Function declarations */
31 extern uint16_t fillUlTtiReq(SlotIndInfo currTimingInfo);
32 extern uint16_t fillDlTtiReq(SlotIndInfo currTimingInfo);
34 /* function pointers for packing slot ind from mac to sch */
35 MacSchSlotIndFunc macSchSlotIndOpts[] =
43 * @brief process DL allocation from scheduler
47 * Function : MacProcDlAlloc
49 * This function copied dl sch info in the mac slot info
52 * @param[in] DL allocation from scheduler
57 uint8_t MacProcDlAlloc(Pst *pst, DlSchedInfo *dlSchedInfo)
60 MacDlSlot *currDlSlot = NULLP;
62 if(dlSchedInfo != NULLP)
64 GET_CELL_IDX(dlSchedInfo->cellId, cellIdx);
65 if(dlSchedInfo->isBroadcastPres)
67 currDlSlot = &macCb.macCell[cellIdx]->\
68 dlSlot[dlSchedInfo->schSlotValue.broadcastTime.slot];
69 currDlSlot->dlInfo.isBroadcastPres = true;
70 memcpy(&currDlSlot->dlInfo.brdcstAlloc, &dlSchedInfo->brdcstAlloc, sizeof(DlBrdcstAlloc));
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->msg4Alloc != NULLP)
85 Msg4Alloc *msg4Alloc = NULLP;
86 currDlSlot = &macCb.macCell[cellIdx]->\
87 dlSlot[dlSchedInfo->schSlotValue.msg4Time.slot];
88 currDlSlot->dlInfo.msg4Alloc = dlSchedInfo->msg4Alloc; /* copy msg4 alloc pointer in MAC slot info */
89 msg4Alloc = dlSchedInfo->msg4Alloc;
90 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize = msg4Alloc->msg4PdschCfg.codeword[0].tbSize;
97 * @brief Forming anf filling the MUX Pdu
100 * Function : fillMsg4Pdu
102 * Forming and filling of Msg4Pdu
104 * @param[in] Msg4Alloc *msg4Alloc
107 void fillMsg4Pdu(uint16_t cellId, Msg4Alloc *msg4Alloc)
110 MacDlData msg4DlData;
113 GET_CELL_IDX(cellId, cellIdx);
115 memset(&msg4DlData, 0, sizeof(MacDlData));
116 memset(&macCeData, 0, sizeof(MacCeInfo));
118 if(macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu != NULLP)
120 MAC_ALLOC(msg4DlData.pduInfo[0].dlPdu, \
121 macCb.macCell[cellIdx]->macRaCb[0].msg4PduLen);
122 if(msg4DlData.pduInfo[0].dlPdu != NULLP)
124 fillMsg4DlData(cellId, &msg4DlData, macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu);
125 fillMacCe(&macCeData, macCb.macCell[cellIdx]->macRaCb[0].msg3Pdu);
126 /* Forming Mux Pdu */
127 macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu = NULLP;
128 MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu, \
129 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize);
130 if(macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu != NULLP)
132 memset(macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu, 0, \
133 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize);
134 macMuxPdu(&msg4DlData, &macCeData, macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu,\
135 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize);
140 DU_LOG("\nMAC: Failed allocating memory for msg4TxPdu");
142 /* Free memory allocated */
143 MAC_FREE(msg4DlData.pduInfo[0].dlPdu, macCb.macCell[cellIdx]->macRaCb[0].msg4PduLen);
147 /* storing msg4 Pdu in macDlSlot */
148 if(macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu)
150 msg4Alloc->msg4Info.msg4PduLen = macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize;
151 MAC_ALLOC(msg4Alloc->msg4Info.msg4Pdu, msg4Alloc->msg4Info.msg4PduLen);
152 if(msg4Alloc->msg4Info.msg4Pdu != NULLP)
154 memcpy(msg4Alloc->msg4Info.msg4Pdu, macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu, \
155 msg4Alloc->msg4Info.msg4PduLen);
160 DU_LOG("\nMAC: Failed at macMuxPdu()");
162 /* TODO: Free all allocated memory, after the usage */
163 /* MAC_FREE(macCb.macCell->macRaCb[0].msg4TxPdu, \
164 macCb.macCell->macRaCb[0].msg4TbSize); // TODO: To be freed after re-transmission is successful.
165 MAC_FREE(macCb.macCell->macRaCb[0].msg4Pdu, macCb.macCell->macRaCb[0].msg4PduLen); */
169 * @brief Builds and Send the Muxed Pdu to Lower MAC
173 * Function : buildAndSendMuxPdu
175 * Build and Sends the Muxed Pdu to Lower MAC.
177 * @param[in] SlotIndInfo *slotInd
181 void buildAndSendMuxPdu(SlotIndInfo currTimingInfo)
184 MacDlSlot *currDlSlot = NULLP;
185 SlotIndInfo muxTimingInfo;
186 memset(&muxTimingInfo, 0, sizeof(SlotIndInfo));
188 GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
190 ADD_DELTA_TO_TIME(currTimingInfo, muxTimingInfo, PHY_DELTA);
191 currDlSlot = &macCb.macCell[cellIdx]->dlSlot[muxTimingInfo.slot];
192 if(currDlSlot->dlInfo.msg4Alloc)
194 fillMsg4Pdu(currTimingInfo.cellId, currDlSlot->dlInfo.msg4Alloc);
200 * @brief Transmission time interval indication from PHY.
204 * Function : sendSlotIndMacToSch
206 * This API is invoked by MAC to send slot ind to scheduler.
208 * @param[in] SlotIndInfo *slotInd
213 int sendSlotIndMacToSch(SlotIndInfo *slotInd)
215 /* fill Pst structure to send to lwr_mac to MAC */
218 FILL_PST_MAC_TO_SCH(pst, EVENT_SLOT_IND_TO_SCH);
219 return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
222 /*******************************************************************
224 * @brief Send slot indication to DU APP
228 * Function : sendSlotIndMacToDuApp
231 * Send slot indication to DU APP
233 * @params[in] Slot indication info
234 * @return ROK - success
237 * ****************************************************************/
238 int sendSlotIndMacToDuApp(SlotIndInfo *slotInd)
242 SlotIndInfo *slotInfo;
244 /* Allocate sharable memory */
245 MAC_ALLOC_SHRABL_BUF(slotInfo, sizeof(SlotIndInfo));
248 DU_LOG("\nMAC : Slot Indication memory allocation failed");
252 slotInfo->cellId = slotInd->cellId;
253 slotInfo->sfn = slotInd->sfn;
254 slotInfo->slot = slotInd->slot;
257 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_SLOT_IND);
259 ret = MacDuAppSlotInd(&pst, slotInfo);
262 DU_LOG("\nMAC: Failed to send slot indication to DU APP");
263 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, slotInfo, sizeof(SlotIndInfo));
267 } /* sendSlotIndMacToDuApp */
269 /*******************************************************************
271 * @brief Process slot indication at MAC
275 * Function : macProcSlotInd
277 * Functionality: Process slot indication at MAC
279 * @params[in] Slot indication info
280 * @return ROK - success
283 * ****************************************************************/
284 uint8_t macProcSlotInd(SlotIndInfo slotInd)
288 GET_CELL_IDX(slotInd.cellId, cellIdx);
290 /* Store current time info */
291 macCb.macCell[cellIdx]->currTime.cellId = slotInd.cellId;
292 macCb.macCell[cellIdx]->currTime.slot = slotInd.slot;
293 macCb.macCell[cellIdx]->currTime.sfn = slotInd.sfn;
295 /* Mux Pdu for Msg4 */
296 buildAndSendMuxPdu(slotInd);
298 /* Trigger for DL TTI REQ */
299 fillDlTtiReq(slotInd);
301 /* Trigger for UL TTI REQ */
302 fillUlTtiReq(slotInd);
305 } /* macProcSlotInd */
308 * @brief Transmission time interval indication from PHY.
312 * Function : fapiMacSlotInd
314 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
316 * @param[in] Pst *pst
317 * @param[in] SuId suId
318 * @param[in] SlotIndInfo *slotInd
323 uint8_t fapiMacSlotInd(Pst *pst, SlotIndInfo *slotInd)
326 VOLATILE uint32_t startTime=0;
328 DU_LOG("\nMAC : Slot Indication received");
331 SStartTask(&startTime, PID_MAC_TTI_IND);
333 /* send slot indication to scheduler */
334 ret = sendSlotIndMacToSch(slotInd);
337 DU_LOG("\nMAC : Sending of slot ind msg from MAC to SCH failed");
341 ret = macProcSlotInd(*slotInd);
344 DU_LOG("\nMAC : macProcSlotInd failed");
348 /* send slot indication to du app */
349 ret = sendSlotIndMacToDuApp(slotInd);
352 DU_LOG("\nMAC :Sending of slot ind msg from MAC to DU APP failed");
357 SStopTask(startTime, PID_MAC_TTI_IND);
360 } /* fapiMacSlotInd */
362 /**********************************************************************
364 **********************************************************************/