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 *******************************************************************************/
19 /* header include files (.h) */
20 #include "common_def.h"
26 /* header/extern include files (.x) */
28 #include "du_app_mac_inf.h"
29 #include "mac_sch_interface.h"
31 #include "lwr_mac_fsm.h"
32 #include "lwr_mac_phy.h"
33 #include "lwr_mac_upr_inf.h"
35 #include "mac_utils.h"
36 #include "lwr_mac_utils.h"
39 /* Function pointer for slot indication from lower mac to mac */
40 packSlotIndMsg packSlotIndOpts[] =
42 packLcSlotInd, /* packing for loosely coupled */
43 fapiMacSlotInd, /* packing for tightly coupled */
44 packLwlcSlotInd /* packing for light weight loosly coupled */
47 /* Function pointer for rach indication from lower mac to mac */
48 packRachIndMsg sendRachIndOpts[] =
55 /* Function pointer for crc indication from lower mac to mac */
56 packCrcIndMsg sendCrcIndOpts[] =
63 /* Function pointer for Rx Data indication from lower mac to mac */
64 packRxDataIndMsg sendRxDataIndOpts[] =
71 /* Function pointer for stop indication from lower mac to mac */
72 packStopIndMsg sendStopIndOpts[] =
79 /* Function pointer for Uci indication from lower mac to mac */
80 packMacUciIndMsg sendUciIndOpts[] =
87 /*******************************************************************
89 * @brief Processes Slot Indication from PHY and sends to MAC
93 * Function : procSlotInd
96 * Processes Slot Indication from PHY and sends to MAC
98 * @params[in] fapi_slot_ind_t pointer
99 * @return ROK - success
102 * ****************************************************************/
103 uint8_t procSlotInd(fapi_slot_ind_t *fapiSlotInd)
105 /* fill Pst structure to send to lwr_mac to MAC */
110 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_SLOT_IND_TO_MAC);
112 slotInd.cellId = lwrMacCb.cellCb[0].cellId;
113 slotInd.sfn = fapiSlotInd->sfn;
114 slotInd.slot = fapiSlotInd->slot;
116 ret = (*packSlotIndOpts[pst.selector])(&pst, &slotInd);
120 if(slotIndIdx > WLS_MEM_FREE_PRD)
124 freeWlsBlockList(slotIndIdx - 1);
130 /*******************************************************************
132 * @brief Handles stop indication recived from PHY
136 * Function : procStopInd
139 * Handles Stop Indication received from PHY
141 * @return ROK - success
144 * ****************************************************************/
145 uint8_t procStopInd()
150 lwrMacCb.phyState = PHY_STATE_CONFIGURED;
151 lwrMacCb.cellCb[0].state = PHY_STATE_CONFIGURED;
152 DU_LOG("\nLWR_MAC: PHY has moved to configured state");
154 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_STOP_IND_TO_MAC);
156 ret = (*sendStopIndOpts[pst.selector])(&pst, \
157 lwrMacCb.cellCb[0].cellId);
160 /*******************************************************************
162 * @brief Processes Rach Indication from PHY and sends to MAC
166 * Function : procRachInd
169 * Processes Rach Indication from PHY and sends to MAC
171 * @params[in] fapi_rach_indication_t pointer
172 * @return ROK - success
175 * ****************************************************************/
176 uint8_t procRachInd(fapi_rach_indication_t *fapiRachInd)
181 RachPduInfo *rachPdu;
184 rachInd.cellId = lwrMacCb.cellCb[0].cellId;
185 rachInd.timingInfo.sfn = fapiRachInd->sfn;
186 rachInd.timingInfo.slot = fapiRachInd->slot;
187 rachInd.numPdu = fapiRachInd->numPdus;
188 for(pduIdx=0; pduIdx < rachInd.numPdu; pduIdx++)
190 rachPdu = &rachInd.rachPdu[pduIdx];
191 rachPdu->pci = fapiRachInd->rachPdu[pduIdx].phyCellId;
192 rachPdu->symbolIdx = fapiRachInd->rachPdu[pduIdx].symbolIndex;
193 rachPdu->slotIdx = fapiRachInd->rachPdu[pduIdx].slotIndex;
194 rachPdu->freqIdx = fapiRachInd->rachPdu[pduIdx].freqIndex;
195 rachPdu->numPream = fapiRachInd->rachPdu[pduIdx].numPreamble;
196 for(prmbleIdx=0; prmbleIdx<rachPdu->numPream; prmbleIdx++)
198 rachPdu->preamInfo[prmbleIdx].preamIdx = \
199 fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].preambleIndex;
200 rachPdu->preamInfo[prmbleIdx].timingAdv = \
201 fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].timingAdvance;
204 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_RACH_IND_TO_MAC);
206 (*sendRachIndOpts[pst.selector])(&pst, &rachInd);
211 /*******************************************************************
213 * @brief Handles CRC indication from PHY and sends to MAC
217 * Function : procCrcInd
220 * Handles CRC indication from PHY and sends to MAC
222 * @params[in] fapi_crc_ind_t message pointer
223 * @return ROK - success
226 * ****************************************************************/
228 uint8_t procCrcInd(fapi_crc_ind_t *fapiCrcInd)
232 uint8_t crcStatusIdx;
236 crcInd.cellId = lwrMacCb.cellCb[0].cellId;
237 crcInd.timingInfo.sfn = fapiCrcInd->sfn;
238 crcInd.timingInfo.slot = fapiCrcInd->slot;
239 crcInd.numCrc = fapiCrcInd->numCrcs;
241 for(crcInfoIdx = 0; crcInfoIdx < crcInd.numCrc; crcInfoIdx++)
243 crcIndInfo = &crcInd.crcInfo[crcInfoIdx];
244 crcIndInfo->handle = fapiCrcInd->crc[crcInfoIdx].handle;
245 crcIndInfo->rnti = fapiCrcInd->crc[crcInfoIdx].rnti;
246 crcIndInfo->harqId = fapiCrcInd->crc[crcInfoIdx].harqId;
247 crcIndInfo->tbCrcStatus = fapiCrcInd->crc[crcInfoIdx].tbCrcStatus;
248 crcIndInfo->numCb = fapiCrcInd->crc[crcInfoIdx].numCb;
249 for(crcStatusIdx = 0; crcStatusIdx < crcIndInfo->numCb; crcStatusIdx++)
251 crcIndInfo->cbCrcStatus[crcStatusIdx] = \
252 fapiCrcInd->crc[crcInfoIdx].cbCrcStatus[crcStatusIdx];
254 crcIndInfo->ul_cqi = fapiCrcInd->crc[crcInfoIdx].ul_cqi;
255 crcIndInfo->timingAdvance = fapiCrcInd->crc[crcInfoIdx].timingAdvance;
256 crcIndInfo->rssi = fapiCrcInd->crc[crcInfoIdx].rssi;
259 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_CRC_IND_TO_MAC);
261 (*sendCrcIndOpts[pst.selector])(&pst, &crcInd);
266 /*******************************************************************
268 * @brief Handles Rx Data indication from PHY and sends to MAC
272 * Function : procRxDataInd
275 * Handles Rx Data indication from PHY and sends to MAC
277 * @params[in] fapi_rx_data_indication_t message pointer
278 * @return ROK - success
281 * ****************************************************************/
283 uint8_t procRxDataInd(fapi_rx_data_indication_t *fapiRxDataInd)
290 rxDataInd.cellId = lwrMacCb.cellCb[0].cellId;
291 rxDataInd.timingInfo.sfn = fapiRxDataInd->sfn;
292 rxDataInd.timingInfo.slot = fapiRxDataInd->slot;
293 rxDataInd.numPdus = fapiRxDataInd->numPdus;
295 for(pduIdx = 0; pduIdx < rxDataInd.numPdus; pduIdx++)
297 pdu = &rxDataInd.pdus[pduIdx];
298 pdu->handle = fapiRxDataInd->pdus[pduIdx].handle;
299 pdu->rnti = fapiRxDataInd->pdus[pduIdx].rnti;
300 pdu->harqId = fapiRxDataInd->pdus[pduIdx].harqId;
301 pdu->pduLength = fapiRxDataInd->pdus[pduIdx].pdu_length;
302 pdu->ul_cqi = fapiRxDataInd->pdus[pduIdx].ul_cqi;
303 pdu->timingAdvance = fapiRxDataInd->pdus[pduIdx].timingAdvance;
304 pdu->rssi = fapiRxDataInd->pdus[pduIdx].rssi;
306 MAC_ALLOC(pdu->pduData, pdu->pduLength);
307 memcpy(pdu->pduData, fapiRxDataInd->pdus[pduIdx].pduData, pdu->pduLength);
310 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_RX_DATA_IND_TO_MAC);
312 (*sendRxDataIndOpts[pst.selector])(&pst, &rxDataInd);
316 /*******************************************************************
318 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
322 * Function : fillUciIndPucchF0F1
325 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
327 *@params[in] UciPucchF0F1 *
328 * fapi_uci_o_pucch_f0f1_t *
329 * @return ROK - success
332 * ****************************************************************/
333 uint8_t fillUciIndPucchF0F1(UciPucchF0F1 *pduInfo, fapi_uci_o_pucch_f0f1_t *fapiPduInfo)
339 pduInfo->handle = fapiPduInfo->handle;
340 pduInfo->pduBitmap = fapiPduInfo->pduBitmap;
341 pduInfo->pucchFormat = fapiPduInfo->pucchFormat;
342 pduInfo->ul_cqi = fapiPduInfo->ul_cqi;
343 pduInfo->crnti = fapiPduInfo->rnti;
344 pduInfo->timingAdvance = fapiPduInfo->timingAdvance;
345 pduInfo->rssi = fapiPduInfo->rssi;
346 memcpy(pduInfo->uciBits, fapiPduInfo->uciBits, MAX_UCI_BIT_PER_TTI_IN_BYTES);
347 if(fapiPduInfo->srInfo.srIndication)
349 pduInfo->srInfo.srIndPres = fapiPduInfo->srInfo.srIndication;
350 pduInfo->srInfo.srConfdcLevel = fapiPduInfo->srInfo.srConfidenceLevel;
353 if(fapiPduInfo->harqInfo.numHarq)
355 pduInfo->harqInfo.numHarq = fapiPduInfo->harqInfo.numHarq;
356 pduInfo->harqInfo.harqConfdcLevel = fapiPduInfo->harqInfo.harqConfidenceLevel;
357 for(harqIdx = 0; harqIdx < pduInfo->harqInfo.numHarq; harqIdx++)
359 pduInfo->harqInfo.harqValue[harqIdx] = fapiPduInfo->harqInfo.harqValue[harqIdx];
365 /*******************************************************************
367 * @brief Handles Uci indication from PHY and sends to MAC
371 * Function : procUciInd
374 * Handles Uci indication from PHY and sends to MAC
376 * @params[in] fapi_uci_indication_t message pointer
377 * @return ROK - success
380 * ****************************************************************/
382 uint8_t procUciInd(fapi_uci_indication_t *fapiUciInd)
387 memset(&pst, 0, sizeof(Pst));
389 memset(&macUciInd, 0, sizeof(UciInd));
391 macUciInd.cellId = lwrMacCb.cellCb[0].cellId;
392 macUciInd.slotInd.sfn = fapiUciInd->sfn;
393 macUciInd.slotInd.slot = fapiUciInd->slot;
394 macUciInd.numUcis = fapiUciInd->numUcis;
396 for(pduIdx = 0; pduIdx < macUciInd.numUcis; pduIdx++)
398 macUciInd.pdus[pduIdx].pduType = fapiUciInd->uciPdu[pduIdx].pduType;
399 switch(macUciInd.pdus[pduIdx].pduType)
403 case UCI_IND_PUCCH_F0F1:
405 UciPucchF0F1 *pduInfo = NULLP;
406 macUciInd.pdus[pduIdx].pduSize = fapiUciInd->uciPdu[pduIdx].pduSize;
407 pduInfo = &macUciInd.pdus[pduIdx].uci.uciPucchF0F1;
408 ret = fillUciIndPucchF0F1(pduInfo, &fapiUciInd->uciPdu[pduIdx].uci.uciPucchF0F1);
411 case UCI_IND_PUCCH_F2F3F4:
414 DU_LOG("\nLWR_MAC: Invalid Pdu Type %d at procmacUciInd()", macUciInd.pdus[pduIdx].pduType);
421 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_UCI_IND_TO_MAC);
422 ret = (*sendUciIndOpts[pst.selector])(&pst, &macUciInd);
426 DU_LOG("\nLWR_MAC: Failed sending UCI Ind to MAC");
432 void procPhyMessages(uint16_t msgType, uint32_t msgSize, void *msg)
435 /* extract the header */
437 header = (fapi_msg_t *)msg;
439 switch(header->msg_id)
441 case FAPI_PARAM_RESPONSE:
442 case FAPI_CONFIG_RESPONSE:
444 sendToLowerMac(msgType, msgSize, msg);
447 case FAPI_SLOT_INDICATION:
449 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
451 DU_LOG("\nLWR_MAC: PHY has moved to running state");
452 lwrMacCb.phyState = PHY_STATE_RUNNING;
453 lwrMacCb.cellCb[0].state = PHY_STATE_RUNNING;
456 fapi_slot_ind_t *slotInd;
457 slotInd = (fapi_slot_ind_t *)msg;
458 procSlotInd(slotInd);
461 case FAPI_ERROR_INDICATION:
465 case FAPI_RX_DATA_INDICATION:
467 fapi_rx_data_indication_t *rxDataInd;
468 rxDataInd = (fapi_rx_data_indication_t *)msg;
469 procRxDataInd(rxDataInd);
472 case FAPI_CRC_INDICATION:
474 fapi_crc_ind_t *crcInd;
475 crcInd = (fapi_crc_ind_t *)msg;
479 case FAPI_UCI_INDICATION:
481 fapi_uci_indication_t *phyUciInd = NULLP;
482 phyUciInd = (fapi_uci_indication_t*)msg;
483 procUciInd(phyUciInd);
486 case FAPI_SRS_INDICATION:
490 case FAPI_RACH_INDICATION:
492 fapi_rach_indication_t *rachInd;
493 rachInd = (fapi_rach_indication_t *)msg;
494 procRachInd(rachInd);
497 case FAPI_STOP_INDICATION:
499 DU_LOG("\nLWR_MAC: Handling Stop Indication");
505 WLS_MEM_FREE(msg, LWR_MAC_WLS_BUF_SIZE);
510 /**********************************************************************
512 **********************************************************************/