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"
24 #include "du_app_mac_inf.h"
25 #include "mac_sch_interface.h"
26 #include "lwr_mac_upr_inf.h"
28 #include "mac_upr_inf_api.h"
29 #include "lwr_mac_fsm.h"
30 #include "mac_utils.h"
32 /* Function declarations */
33 extern uint16_t fillUlTtiReq(SlotIndInfo currTimingInfo);
34 extern uint16_t fillDlTtiReq(SlotIndInfo currTimingInfo);
35 extern uint16_t fillUlDciReq(SlotIndInfo currTimingInfo);
37 /* function pointers for packing slot ind from mac to sch */
38 MacSchSlotIndFunc macSchSlotIndOpts[] =
46 * @brief process DL allocation from scheduler
50 * Function : MacProcDlAlloc
52 * This function copied dl sch info in the mac slot info
55 * @param[in] DL allocation from scheduler
60 uint8_t MacProcDlAlloc(Pst *pst, DlSchedInfo *dlSchedInfo)
63 MacDlSlot *currDlSlot = NULLP;
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));
76 if(dlSchedInfo->rarAlloc != NULLP)
78 currDlSlot = &macCb.macCell[cellIdx]->\
79 dlSlot[dlSchedInfo->schSlotValue.rarTime.slot];
80 currDlSlot->dlInfo.rarAlloc = dlSchedInfo->rarAlloc;
83 fillRarPdu(&currDlSlot->dlInfo.rarAlloc->rarInfo);
86 if(dlSchedInfo->msg4Alloc != NULLP)
88 Msg4Alloc *msg4Alloc = NULLP;
89 currDlSlot = &macCb.macCell[cellIdx]->\
90 dlSlot[dlSchedInfo->schSlotValue.msg4Time.slot];
91 currDlSlot->dlInfo.msg4Alloc = dlSchedInfo->msg4Alloc; /* copy msg4 alloc pointer in MAC slot info */
92 msg4Alloc = dlSchedInfo->msg4Alloc;
93 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize = msg4Alloc->msg4PdschCfg.codeword[0].tbSize;
95 if(dlSchedInfo->ulGrant != NULLP)
97 currDlSlot = &macCb.macCell[cellIdx]->\
98 dlSlot[dlSchedInfo->schSlotValue.ulDciTime.slot];
99 currDlSlot->dlInfo.ulGrant = dlSchedInfo->ulGrant;
106 * @brief Forming anf filling the MUX Pdu
109 * Function : fillMsg4Pdu
111 * Forming and filling of Msg4Pdu
113 * @param[in] Msg4Alloc *msg4Alloc
116 void fillMsg4Pdu(uint16_t cellId, Msg4Alloc *msg4Alloc)
119 MacDlData msg4DlData;
122 GET_CELL_IDX(cellId, cellIdx);
124 memset(&msg4DlData, 0, sizeof(MacDlData));
125 memset(&macCeData, 0, sizeof(MacCeInfo));
127 if(macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu != NULLP)
129 MAC_ALLOC(msg4DlData.pduInfo[0].dlPdu, \
130 macCb.macCell[cellIdx]->macRaCb[0].msg4PduLen);
131 if(msg4DlData.pduInfo[0].dlPdu != NULLP)
133 fillMsg4DlData(cellId, &msg4DlData, macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu);
134 fillMacCe(&macCeData, macCb.macCell[cellIdx]->macRaCb[0].msg3Pdu);
135 /* Forming Mux Pdu */
136 macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu = NULLP;
137 MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu, \
138 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize);
139 if(macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu != NULLP)
141 memset(macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu, 0, \
142 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize);
143 macMuxPdu(&msg4DlData, &macCeData, macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu,\
144 macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize);
149 DU_LOG("\nMAC: Failed allocating memory for msg4TxPdu");
151 /* Free memory allocated */
152 MAC_FREE(msg4DlData.pduInfo[0].dlPdu, macCb.macCell[cellIdx]->macRaCb[0].msg4PduLen);
156 /* storing msg4 Pdu in macDlSlot */
157 if(macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu)
159 msg4Alloc->msg4Info.msg4PduLen = macCb.macCell[cellIdx]->macRaCb[0].msg4TbSize;
160 MAC_ALLOC(msg4Alloc->msg4Info.msg4Pdu, msg4Alloc->msg4Info.msg4PduLen);
161 if(msg4Alloc->msg4Info.msg4Pdu != NULLP)
163 memcpy(msg4Alloc->msg4Info.msg4Pdu, macCb.macCell[cellIdx]->macRaCb[0].msg4TxPdu, \
164 msg4Alloc->msg4Info.msg4PduLen);
169 DU_LOG("\nMAC: Failed at macMuxPdu()");
171 /* TODO: Free all allocated memory, after the usage */
172 /* MAC_FREE(macCb.macCell->macRaCb[0].msg4TxPdu, \
173 macCb.macCell->macRaCb[0].msg4TbSize); // TODO: To be freed after re-transmission is successful.
174 MAC_FREE(macCb.macCell->macRaCb[0].msg4Pdu, macCb.macCell->macRaCb[0].msg4PduLen); */
178 * @brief Builds and Send the Muxed Pdu to Lower MAC
182 * Function : buildAndSendMuxPdu
184 * Build and Sends the Muxed Pdu to Lower MAC.
186 * @param[in] SlotIndInfo *slotInd
190 void buildAndSendMuxPdu(SlotIndInfo currTimingInfo)
193 MacDlSlot *currDlSlot = NULLP;
194 SlotIndInfo muxTimingInfo;
195 memset(&muxTimingInfo, 0, sizeof(SlotIndInfo));
197 GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
199 ADD_DELTA_TO_TIME(currTimingInfo, muxTimingInfo, PHY_DELTA);
200 currDlSlot = &macCb.macCell[cellIdx]->dlSlot[muxTimingInfo.slot];
201 if(currDlSlot->dlInfo.msg4Alloc)
203 fillMsg4Pdu(currTimingInfo.cellId, currDlSlot->dlInfo.msg4Alloc);
209 * @brief Transmission time interval indication from PHY.
213 * Function : sendSlotIndMacToSch
215 * This API is invoked by MAC to send slot ind to scheduler.
217 * @param[in] SlotIndInfo *slotInd
222 int sendSlotIndMacToSch(SlotIndInfo *slotInd)
224 /* fill Pst structure to send to lwr_mac to MAC */
227 FILL_PST_MAC_TO_SCH(pst, EVENT_SLOT_IND_TO_SCH);
228 return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
231 /*******************************************************************
233 * @brief Send slot indication to DU APP
237 * Function : sendSlotIndMacToDuApp
240 * Send slot indication to DU APP
242 * @params[in] Slot indication info
243 * @return ROK - success
246 * ****************************************************************/
247 int sendSlotIndMacToDuApp(SlotIndInfo *slotInd)
251 SlotIndInfo *slotInfo;
253 /* Allocate sharable memory */
254 MAC_ALLOC_SHRABL_BUF(slotInfo, sizeof(SlotIndInfo));
257 DU_LOG("\nMAC : Slot Indication memory allocation failed");
261 slotInfo->cellId = slotInd->cellId;
262 slotInfo->sfn = slotInd->sfn;
263 slotInfo->slot = slotInd->slot;
266 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_SLOT_IND);
268 ret = MacDuAppSlotInd(&pst, slotInfo);
271 DU_LOG("\nMAC: Failed to send slot indication to DU APP");
272 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, slotInfo, sizeof(SlotIndInfo));
276 } /* sendSlotIndMacToDuApp */
278 /*******************************************************************
280 * @brief Process slot indication at MAC
284 * Function : macProcSlotInd
286 * Functionality: Process slot indication at MAC
288 * @params[in] Slot indication info
289 * @return ROK - success
292 * ****************************************************************/
293 uint8_t macProcSlotInd(SlotIndInfo slotInd)
297 GET_CELL_IDX(slotInd.cellId, cellIdx);
299 /* Store current time info */
300 macCb.macCell[cellIdx]->currTime.cellId = slotInd.cellId;
301 macCb.macCell[cellIdx]->currTime.slot = slotInd.slot;
302 macCb.macCell[cellIdx]->currTime.sfn = slotInd.sfn;
304 /* Mux Pdu for Msg4 */
305 buildAndSendMuxPdu(slotInd);
307 /* Trigger for DL TTI REQ */
308 fillDlTtiReq(slotInd);
310 /* Trigger for UL TTI REQ */
311 fillUlTtiReq(slotInd);
313 /* Trigger for UL DCI REQ */
314 fillUlDciReq(slotInd);
317 } /* macProcSlotInd */
320 * @brief Transmission time interval indication from PHY.
324 * Function : fapiMacSlotInd
326 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
328 * @param[in] Pst *pst
329 * @param[in] SuId suId
330 * @param[in] SlotIndInfo *slotInd
335 uint8_t fapiMacSlotInd(Pst *pst, SlotIndInfo *slotInd)
338 VOLATILE uint32_t startTime=0;
340 DU_LOG("\nMAC : Slot Indication received");
343 ODU_START_TASK(&startTime, PID_MAC_TTI_IND);
345 /* send slot indication to scheduler */
346 ret = sendSlotIndMacToSch(slotInd);
349 DU_LOG("\nMAC : Sending of slot ind msg from MAC to SCH failed");
353 ret = macProcSlotInd(*slotInd);
356 DU_LOG("\nMAC : macProcSlotInd failed");
360 /* send slot indication to du app */
361 ret = sendSlotIndMacToDuApp(slotInd);
364 DU_LOG("\nMAC :Sending of slot ind msg from MAC to DU APP failed");
369 ODU_STOP_TASK(startTime, PID_MAC_TTI_IND);
372 } /* fapiMacSlotInd */
374 /**********************************************************************
376 **********************************************************************/