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 Forming anf filling the MUX Pdu
132 * Function : fillMsg4Pdu
134 * Forming and filling of Msg4Pdu
136 * @param[in] DlMsgAlloc *msg4Alloc
139 void fillMsg4Pdu(uint16_t cellId, DlMsgSchInfo *msg4SchInfo)
141 uint8_t ueId = 0, ueIdx = 0;
143 uint16_t msg4TxPduLen;
144 MacDlData msg4DlData;
147 GET_CELL_IDX(cellId, cellIdx);
149 memset(&msg4DlData, 0, sizeof(MacDlData));
150 memset(&macCeData, 0, sizeof(MacCeInfo));
152 GET_UE_ID(msg4SchInfo->dlMsgInfo.crnti, ueId);
155 if(macCb.macCell[cellIdx] == NULLP)
157 DU_LOG("\nERROR --> MAC: Cell Id[%d] not found", cellId);
161 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu != NULLP)
163 MAC_ALLOC(msg4DlData.pduInfo[msg4DlData.numPdu].dlPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
164 if(msg4DlData.pduInfo[msg4DlData.numPdu].dlPdu != NULLP)
166 msg4TxPduLen = macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize - TX_PAYLOAD_HDR_LEN;
168 fillMsg4DlData(&msg4DlData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen, \
169 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu);
170 fillMacCe(&macCeData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg3Pdu);
171 /* Forming Mux Pdu */
172 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu = NULLP;
173 MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, msg4TxPduLen);
174 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu != NULLP)
176 memset(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, 0, msg4TxPduLen);
177 macMuxPdu(&msg4DlData, &macCeData, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, msg4TxPduLen);
181 DU_LOG("\nERROR --> MAC: Failed allocating memory for msg4TxPdu");
183 /* Free memory allocated */
184 MAC_FREE(msg4DlData.pduInfo[msg4DlData.numPdu-1].dlPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
189 /* storing msg4 Pdu in macDlSlot */
190 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu)
192 msg4SchInfo->dlMsgInfo.dlMsgPduLen = msg4TxPduLen;
193 MAC_ALLOC(msg4SchInfo->dlMsgInfo.dlMsgPdu, msg4SchInfo->dlMsgInfo.dlMsgPduLen);
194 if(msg4SchInfo->dlMsgInfo.dlMsgPdu != NULLP)
196 memcpy(msg4SchInfo->dlMsgInfo.dlMsgPdu, macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
197 msg4SchInfo->dlMsgInfo.dlMsgPduLen);
202 DU_LOG("\nERROR --> MAC: Failed at fillMsg4Pdu()");
207 * @brief Builds and Send the Muxed Pdu to Lower MAC
211 * Function : buildAndSendMuxPdu
213 * Build and Sends the Muxed Pdu to Lower MAC.
215 * @param[in] SlotTimingInfo *slotInd
219 void buildAndSendMuxPdu(SlotTimingInfo currTimingInfo)
224 MacDlSlot *currDlSlot = NULLP;
225 SlotTimingInfo muxTimingInfo;
226 memset(&muxTimingInfo, 0, sizeof(SlotTimingInfo));
228 GET_CELL_IDX(currTimingInfo.cellId, cellIdx);
230 ADD_DELTA_TO_TIME(currTimingInfo, muxTimingInfo, PHY_DELTA_DL);
231 currDlSlot = &macCb.macCell[cellIdx]->dlSlot[muxTimingInfo.slot];
233 for(ueIdx=0; ueIdx<MAX_NUM_UE; ueIdx++)
235 if(currDlSlot->dlInfo.dlMsgAlloc[ueIdx])
237 for(schInfoIdx=0; schInfoIdx<currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->numSchedInfo; schInfoIdx++)
239 if((currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].dlMsgInfo.isMsg4Pdu) &&
240 ((currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].pduPres == PDSCH_PDU) ||
241 (currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx].pduPres == BOTH)))
243 fillMsg4Pdu(currTimingInfo.cellId, &currDlSlot->dlInfo.dlMsgAlloc[ueIdx]->dlMsgSchedInfo[schInfoIdx]);
251 * @brief Transmission time interval indication from PHY.
255 * Function : sendSlotIndMacToSch
257 * This API is invoked by MAC to send slot ind to scheduler.
259 * @param[in] SlotTimingInfo *slotInd
264 int sendSlotIndMacToSch(SlotTimingInfo *slotInd)
266 /* fill Pst structure to send to lwr_mac to MAC */
269 FILL_PST_MAC_TO_SCH(pst, EVENT_SLOT_IND_TO_SCH);
270 return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
273 /*******************************************************************
275 * @brief Send cell up indication to DU APP
279 * Function : sendCellUpIndMacToDuApp
282 * Send cell up indication to DU APP
284 * @params[in] Cell Up indication info
285 * @return ROK - success
288 * ****************************************************************/
289 int sendCellUpIndMacToDuApp(uint16_t cellId)
293 OduCellId *oduCellId;
295 /* Allocate sharable memory */
296 MAC_ALLOC_SHRABL_BUF(oduCellId, sizeof(OduCellId));
299 DU_LOG("\nERROR --> MAC : Memory allocation failed for cell up indication");
302 oduCellId->cellId = cellId;
305 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_UP_IND);
307 ret = MacDuAppCellUpInd(&pst, oduCellId);
310 DU_LOG("\nERROR --> MAC: Failed to send cell up indication to DU APP");
311 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, oduCellId, sizeof(OduCellId));
315 } /* sendCellUpIndMacToDuApp */
317 /*******************************************************************
319 * @brief Send slot indication to DU APP
323 * Function : sendSlotIndToDuApp
326 * Send cell up indication to DU APP
328 * @params[in] Cell Up indication info
329 * @return ROK - success
332 * ****************************************************************/
333 uint8_t sendSlotIndToDuApp(SlotTimingInfo *slotInd)
337 SlotTimingInfo *slotIndInfo;
339 /* Allocate sharable memory */
340 MAC_ALLOC_SHRABL_BUF(slotIndInfo, sizeof(SlotTimingInfo));
343 DU_LOG("\nERROR --> MAC : Memory allocation failed for slot indication");
346 memcpy(slotIndInfo, slotInd,sizeof(SlotTimingInfo));
349 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_SLOT_IND);
351 ret = MacDuAppSlotInd(&pst, slotIndInfo);
354 DU_LOG("\nERROR --> MAC: Failed to send slot up indication to DU APP");
355 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, slotIndInfo, sizeof(SlotTimingInfo));
360 /*******************************************************************
362 * @brief Process slot indication at MAC
366 * Function : macProcSlotInd
368 * Functionality: Process slot indication at MAC
370 * @params[in] Slot indication info
371 * @return ROK - success
374 * ****************************************************************/
375 uint8_t macProcSlotInd(SlotTimingInfo slotInd)
377 uint16_t cellIdx = 0;
379 GET_CELL_IDX(slotInd.cellId, cellIdx);
381 if(macCb.macCell[cellIdx] == NULLP)
383 DU_LOG("ERROR --> MAC : macProcSlotInd(): CellId[%d] does not exist. Error occurred at SFN [%d] Slot [%d]",\
384 slotInd.cellId, slotInd.sfn, slotInd.slot);
387 /* Store current time info */
388 macCb.macCell[cellIdx]->currTime.cellId = slotInd.cellId;
389 macCb.macCell[cellIdx]->currTime.slot = slotInd.slot;
390 macCb.macCell[cellIdx]->currTime.sfn = slotInd.sfn;
392 /* Mux Pdu for Msg4 */
393 buildAndSendMuxPdu(slotInd);
395 /* Trigger for DL TTI REQ */
396 fillDlTtiReq(slotInd);
399 } /* macProcSlotInd */
402 * @brief Transmission time interval indication from PHY.
406 * Function : fapiMacSlotInd
408 * This API is invoked by PHY to indicate TTI indication to MAC for a cell.
410 * @param[in] Pst *pst
411 * @param[in] SuId suId
412 * @param[in] SlotTimingInfo *slotInd
417 uint8_t fapiMacSlotInd(Pst *pst, SlotTimingInfo *slotInd)
421 volatile uint32_t startTime=0;
423 #ifdef ODU_SLOT_IND_DEBUG_LOG
424 DU_LOG("\nDEBUG --> MAC : Slot Indication received. [%d : %d]", slotInd->sfn, slotInd->slot);
427 ODU_START_TASK(&startTime, PID_MAC_TTI_IND);
432 GET_CELL_IDX(slotInd->cellId, cellIdx);
433 macCb.macCell[cellIdx]->state = CELL_STATE_UP;
436 /* When testing L2 with Intel-L1, any changes specific to
437 * timer mode testing must be guarded under INTEL_TIMER_MODE*/
438 #ifndef INTEL_TIMER_MODE
439 /* send slot indication to scheduler */
440 ret = sendSlotIndMacToSch(slotInd);
443 DU_LOG("\nERROR --> MAC : Sending of slot ind msg from MAC to SCH failed");
444 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotTimingInfo));
448 ret = macProcSlotInd(*slotInd);
451 DU_LOG("\nERROR --> MAC : macProcSlotInd failed");
452 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotTimingInfo));
457 /*First Slot Ind is for CellUp. Any other Slot, will be notified to DUAPP as
461 /* send cell up indication to du app */
462 ret = sendCellUpIndMacToDuApp(slotInd->cellId);
467 /* send slot indication to du app */
468 ret = sendSlotIndToDuApp(slotInd);
473 DU_LOG("\nERROR --> MAC :Sending of slot ind msg from MAC to DU APP failed");
474 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotTimingInfo));
479 ODU_STOP_TASK(startTime, PID_MAC_TTI_IND);
480 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, slotInd, sizeof(SlotTimingInfo));
483 lwrMacCb.phySlotIndCntr++;
484 if(lwrMacCb.phySlotIndCntr > WLS_MEM_FREE_PRD)
486 lwrMacCb.phySlotIndCntr = 1;
488 freeWlsBlockList(lwrMacCb.phySlotIndCntr - 1);
492 } /* fapiMacSlotInd */
494 /**********************************************************************
496 **********************************************************************/