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"
24 #include "fapi_vendor_extension.h"
27 /* header/extern include files (.x) */
29 #include "du_app_mac_inf.h"
30 #include "mac_sch_interface.h"
32 #include "lwr_mac_fsm.h"
33 #include "lwr_mac_phy.h"
34 #include "lwr_mac_upr_inf.h"
36 #include "mac_utils.h"
37 #include "lwr_mac_utils.h"
40 /* Function pointer for slot indication from lower mac to mac */
41 SlotIndFunc sendSlotIndOpts[] =
43 packSlotInd, /* packing for loosely coupled */
44 fapiMacSlotInd, /* packing for tightly coupled */
45 packSlotInd /* packing for light weight loosly coupled */
48 /* Function pointer for rach indication from lower mac to mac */
49 RachIndFunc sendRachIndOpts[] =
56 /* Function pointer for crc indication from lower mac to mac */
57 CrcIndFunc sendCrcIndOpts[] =
64 /* Function pointer for Rx Data indication from lower mac to mac */
65 RxDataIndFunc sendRxDataIndOpts[] =
72 /* Function pointer for stop indication from lower mac to mac */
73 StopIndFunc sendStopIndOpts[] =
80 /* Function pointer for Uci indication from lower mac to mac */
81 UciIndFunc sendUciIndOpts[] =
88 /*******************************************************************
90 * @brief Processes Slot Indication from PHY and sends to MAC
94 * Function : procSlotInd
97 * Processes Slot Indication from PHY and sends to MAC
99 * @params[in] fapi_slot_ind_t pointer
100 * @return ROK - success
103 * ****************************************************************/
104 uint8_t procSlotInd(fapi_slot_ind_t *fapiSlotInd)
106 /* fill Pst structure to send to lwr_mac to MAC */
109 SlotIndInfo *slotInd = {0};
111 MAC_ALLOC_SHRABL_BUF(slotInd, sizeof(SlotIndInfo));
114 slotInd->cellId = lwrMacCb.cellCb[0].cellId;
115 slotInd->sfn = fapiSlotInd->sfn;
116 slotInd->slot = fapiSlotInd->slot;
118 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_SLOT_IND_TO_MAC);
119 ret = (*sendSlotIndOpts[pst.selector])(&pst, slotInd);
123 DU_LOG("\nERROR --> LWR_MAC: Memory allocation failed in procSlotInd");
129 /*******************************************************************
131 * @brief Handles stop indication recived from PHY
135 * Function : procStopInd
138 * Handles Stop Indication received from PHY
140 * @return ROK - success
143 * ****************************************************************/
144 uint8_t procStopInd()
147 uint16_t *cellId = NULLP;
149 MAC_ALLOC_SHRABL_BUF(cellId, sizeof(uint16_t));
152 DU_LOG("\nERROR --> LWR_MAC: Memory Allocation failed in procStopInd");
156 *cellId = lwrMacCb.cellCb[0].cellId;
157 lwrMacCb.phyState = PHY_STATE_CONFIGURED;
158 lwrMacCb.cellCb[0].state = PHY_STATE_CONFIGURED;
159 DU_LOG("\nINFO --> LWR_MAC: PHY has moved to configured state");
161 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_STOP_IND_TO_MAC);
162 return (*sendStopIndOpts[pst.selector])(&pst, cellId);
165 /*******************************************************************
167 * @brief Processes Rach Indication from PHY and sends to MAC
171 * Function : procRachInd
174 * Processes Rach Indication from PHY and sends to MAC
176 * @params[in] fapi_rach_indication_t pointer
177 * @return ROK - success
180 * ****************************************************************/
181 uint8_t procRachInd(fapi_rach_indication_t *fapiRachInd)
186 RachPduInfo *rachPdu = NULLP;
187 RachInd *rachInd = NULLP;
189 MAC_ALLOC_SHRABL_BUF(rachInd, sizeof(RachInd));
192 DU_LOG("\nERROR --> LWR_MAC : Memory Allocation failed in procRachInd");
195 if(!fapiRachInd->numPdus)
197 DU_LOG("\nDEBUG --> LWR_MAC : No PDU in RACH.indication at [%d, %d]", fapiRachInd->sfn, fapiRachInd->slot);
201 rachInd->cellId = lwrMacCb.cellCb[0].cellId;
202 rachInd->timingInfo.sfn = fapiRachInd->sfn;
203 rachInd->timingInfo.slot = fapiRachInd->slot;
204 rachInd->numPdu = fapiRachInd->numPdus;
205 for(pduIdx=0; pduIdx < rachInd->numPdu; pduIdx++)
207 rachPdu = &rachInd->rachPdu[pduIdx];
208 rachPdu->pci = fapiRachInd->rachPdu[pduIdx].phyCellId;
209 rachPdu->symbolIdx = fapiRachInd->rachPdu[pduIdx].symbolIndex;
210 rachPdu->slotIdx = fapiRachInd->rachPdu[pduIdx].slotIndex;
211 rachPdu->freqIdx = fapiRachInd->rachPdu[pduIdx].freqIndex;
212 rachPdu->numPream = fapiRachInd->rachPdu[pduIdx].numPreamble;
213 for(prmbleIdx=0; prmbleIdx<rachPdu->numPream; prmbleIdx++)
215 rachPdu->preamInfo[prmbleIdx].preamIdx = \
216 fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].preambleIndex;
217 rachPdu->preamInfo[prmbleIdx].timingAdv = \
218 fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].timingAdvance;
222 /* Fill post and sent to MAC */
223 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_RACH_IND_TO_MAC);
224 return (*sendRachIndOpts[pst.selector])(&pst, rachInd);
227 /*******************************************************************
229 * @brief Handles CRC indication from PHY and sends to MAC
233 * Function : procCrcInd
236 * Handles CRC indication from PHY and sends to MAC
238 * @params[in] fapi_crc_ind_t message pointer
239 * @return ROK - success
242 * ****************************************************************/
244 uint8_t procCrcInd(fapi_crc_ind_t *fapiCrcInd)
248 uint8_t crcStatusIdx;
249 CrcInfo *crcIndInfo = NULLP;
250 CrcInd *crcInd = NULLP;
252 MAC_ALLOC_SHRABL_BUF(crcInd, sizeof(CrcInd));
255 DU_LOG("\nERROR --> LWR_MAC : Memory Allocation failed in procCrcInd");
258 if(!fapiCrcInd->numCrcs)
260 DU_LOG("\nDEBUG --> LWR_MAC : No CRC PDUs in CRC.indication at [%d, %d]", fapiCrcInd->sfn, fapiCrcInd->slot);
264 crcInd->cellId = lwrMacCb.cellCb[0].cellId;
265 crcInd->timingInfo.sfn = fapiCrcInd->sfn;
266 crcInd->timingInfo.slot = fapiCrcInd->slot;
267 crcInd->numCrc = fapiCrcInd->numCrcs;
269 for(crcInfoIdx = 0; crcInfoIdx < crcInd->numCrc; crcInfoIdx++)
271 crcIndInfo = &crcInd->crcInfo[crcInfoIdx];
272 crcIndInfo->handle = fapiCrcInd->crc[crcInfoIdx].handle;
273 crcIndInfo->rnti = fapiCrcInd->crc[crcInfoIdx].rnti;
274 crcIndInfo->harqId = fapiCrcInd->crc[crcInfoIdx].harqId;
275 crcIndInfo->tbCrcStatus = fapiCrcInd->crc[crcInfoIdx].tbCrcStatus;
276 crcIndInfo->numCb = fapiCrcInd->crc[crcInfoIdx].numCb;
277 for(crcStatusIdx = 0; crcStatusIdx < crcIndInfo->numCb; crcStatusIdx++)
279 crcIndInfo->cbCrcStatus[crcStatusIdx] = \
280 fapiCrcInd->crc[crcInfoIdx].cbCrcStatus[crcStatusIdx];
282 crcIndInfo->ul_cqi = fapiCrcInd->crc[crcInfoIdx].ul_cqi;
283 crcIndInfo->timingAdvance = fapiCrcInd->crc[crcInfoIdx].timingAdvance;
284 crcIndInfo->rssi = fapiCrcInd->crc[crcInfoIdx].rssi;
287 /* Fill post and sent to MAC */
288 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_CRC_IND_TO_MAC);
289 return (*sendCrcIndOpts[pst.selector])(&pst, crcInd);
292 /*******************************************************************
294 * @brief Handles Rx Data indication from PHY and sends to MAC
298 * Function : procRxDataInd
301 * Handles Rx Data indication from PHY and sends to MAC
303 * @params[in] fapi_rx_data_indication_t message pointer
304 * @return ROK - success
307 * ****************************************************************/
309 uint8_t procRxDataInd(fapi_rx_data_indication_t *fapiRxDataInd)
313 RxDataInd *rxDataInd = NULLP;
314 RxDataIndPdu *pdu = NULLP;
316 MAC_ALLOC_SHRABL_BUF(rxDataInd, sizeof(RxDataInd));
319 DU_LOG("\nERROR --> LWR_MAC : Memory Allocation failed in procRxDataInd");
322 if(!fapiRxDataInd->numPdus)
324 DU_LOG("\nDEBUG --> LWR_MAC : No PDU in RX_Data.indication at [%d, %d]", fapiRxDataInd->sfn, fapiRxDataInd->slot);
328 rxDataInd->cellId = lwrMacCb.cellCb[0].cellId;
329 rxDataInd->timingInfo.sfn = fapiRxDataInd->sfn;
330 rxDataInd->timingInfo.slot = fapiRxDataInd->slot;
331 rxDataInd->numPdus = fapiRxDataInd->numPdus;
333 for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
335 pdu = &rxDataInd->pdus[pduIdx];
336 pdu->handle = fapiRxDataInd->pdus[pduIdx].handle;
337 pdu->rnti = fapiRxDataInd->pdus[pduIdx].rnti;
338 pdu->harqId = fapiRxDataInd->pdus[pduIdx].harqId;
339 pdu->pduLength = fapiRxDataInd->pdus[pduIdx].pdu_length;
340 pdu->ul_cqi = fapiRxDataInd->pdus[pduIdx].ul_cqi;
341 pdu->timingAdvance = fapiRxDataInd->pdus[pduIdx].timingAdvance;
342 pdu->rssi = fapiRxDataInd->pdus[pduIdx].rssi;
344 MAC_ALLOC_SHRABL_BUF(pdu->pduData, pdu->pduLength);
345 memcpy(pdu->pduData, fapiRxDataInd->pdus[pduIdx].pduData, pdu->pduLength);
347 /* Free WLS memory allocated for Rx PDU */
348 WLS_MEM_FREE(fapiRxDataInd->pdus[pduIdx].pduData, LWR_MAC_WLS_BUF_SIZE);
352 /* Fill post and sent to MAC */
353 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_RX_DATA_IND_TO_MAC);
354 return (*sendRxDataIndOpts[pst.selector])(&pst, rxDataInd);
357 /*******************************************************************
359 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
363 * Function : fillUciIndPucchF0F1
366 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
368 *@params[in] UciPucchF0F1 *
369 * fapi_uci_o_pucch_f0f1_t *
370 * @return ROK - success
373 * ****************************************************************/
374 uint8_t fillUciIndPucchF0F1(UciPucchF0F1 *pduInfo, fapi_uci_o_pucch_f0f1_t *fapiPduInfo)
380 pduInfo->handle = fapiPduInfo->handle;
381 pduInfo->pduBitmap = fapiPduInfo->pduBitmap;
382 pduInfo->pucchFormat = fapiPduInfo->pucchFormat;
383 pduInfo->ul_cqi = fapiPduInfo->ul_cqi;
384 pduInfo->crnti = fapiPduInfo->rnti;
385 pduInfo->timingAdvance = fapiPduInfo->timingAdvance;
386 pduInfo->rssi = fapiPduInfo->rssi;
387 if(fapiPduInfo->srInfo.srIndication)
389 pduInfo->srInfo.srIndPres = fapiPduInfo->srInfo.srIndication;
390 pduInfo->srInfo.srConfdcLevel = fapiPduInfo->srInfo.srConfidenceLevel;
392 if(fapiPduInfo->harqInfo.numHarq)
394 pduInfo->harqInfo.numHarq = fapiPduInfo->harqInfo.numHarq;
395 pduInfo->harqInfo.harqConfdcLevel = fapiPduInfo->harqInfo.harqConfidenceLevel;
396 for(harqIdx = 0; harqIdx < pduInfo->harqInfo.numHarq; harqIdx++)
398 pduInfo->harqInfo.harqValue[harqIdx] = fapiPduInfo->harqInfo.harqValue[harqIdx];
404 /*******************************************************************
406 * @brief Handles Uci indication from PHY and sends to MAC
410 * Function : procUciInd
413 * Handles Uci indication from PHY and sends to MAC
415 * @params[in] fapi_uci_indication_t message pointer
416 * @return ROK - success
419 * ****************************************************************/
421 uint8_t procUciInd(fapi_uci_indication_t *fapiUciInd)
426 UciInd *macUciInd = NULLP;
428 MAC_ALLOC_SHRABL_BUF(macUciInd, sizeof(UciInd));
431 DU_LOG("\nERROR --> LWR_MAC: Memory Allocation failed in procUciInd");
435 DU_LOG("\nDEBUG --> LWR_MAC: Processing UCI Indication");
436 memset(macUciInd, 0, sizeof(UciInd));
437 macUciInd->cellId = lwrMacCb.cellCb[0].cellId;
438 macUciInd->slotInd.sfn = fapiUciInd->sfn;
439 macUciInd->slotInd.slot = fapiUciInd->slot;
440 macUciInd->numUcis = fapiUciInd->numUcis;
442 for(pduIdx = 0; pduIdx < macUciInd->numUcis; pduIdx++)
444 macUciInd->pdus[pduIdx].pduType = fapiUciInd->uciPdu[pduIdx].pduType;
445 switch(macUciInd->pdus[pduIdx].pduType)
449 case UCI_IND_PUCCH_F0F1:
451 UciPucchF0F1 *pduInfo = NULLP;
452 macUciInd->pdus[pduIdx].pduSize = fapiUciInd->uciPdu[pduIdx].pduSize;
453 pduInfo = &macUciInd->pdus[pduIdx].uci.uciPucchF0F1;
454 ret = fillUciIndPucchF0F1(pduInfo, &fapiUciInd->uciPdu[pduIdx].uci.uciPucchF0F1);
457 case UCI_IND_PUCCH_F2F3F4:
460 DU_LOG("\nERROR --> LWR_MAC: Invalid Pdu Type %d at procmacUciInd()", macUciInd->pdus[pduIdx].pduType);
467 FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_UCI_IND_TO_MAC);
468 ret = (*sendUciIndOpts[pst.selector])(&pst, macUciInd);
472 DU_LOG("\nERROR --> LWR_MAC: Failed sending UCI Ind to MAC");
478 /*******************************************************************
480 * @brief Processes message from PHY
484 * Function : procPhyMessages
486 * Functionality: Processes message from PHY
489 * @return ROK - success
492 * ****************************************************************/
493 void procPhyMessages(uint16_t msgType, uint32_t msgSize, void *msg)
496 /* extract the header */
497 fapi_msg_t *header = NULLP;
498 header = (fapi_msg_t *)msg;
500 switch(header->msg_id)
502 #ifdef INTEL_TIMER_MODE
503 case FAPI_VENDOR_EXT_UL_IQ_SAMPLES:
505 DU_LOG("\nDEBUG --> LWR_MAC: Received FAPI_VENDOR_EXT_UL_IQ_SAMPLES");
508 sendToLowerMac(CONFIG_REQUEST, 0, (void *)&cellId);
512 case FAPI_PARAM_RESPONSE:
514 sendToLowerMac(PARAM_RESPONSE, msgSize, msg);
517 case FAPI_CONFIG_RESPONSE:
519 sendToLowerMac(CONFIG_RESPONSE, msgSize, msg);
522 case FAPI_SLOT_INDICATION:
524 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
526 DU_LOG("\nINFO --> LWR_MAC: PHY has moved to running state");
527 lwrMacCb.phyState = PHY_STATE_RUNNING;
528 lwrMacCb.cellCb[0].state = PHY_STATE_RUNNING;
531 fapi_slot_ind_t *slotInd = NULLP;
532 slotInd = (fapi_slot_ind_t *)msg;
533 procSlotInd(slotInd);
536 case FAPI_ERROR_INDICATION:
540 case FAPI_RX_DATA_INDICATION:
542 fapi_rx_data_indication_t *rxDataInd;
543 rxDataInd = (fapi_rx_data_indication_t *)msg;
544 procRxDataInd(rxDataInd);
547 case FAPI_CRC_INDICATION:
549 fapi_crc_ind_t *crcInd;
550 crcInd = (fapi_crc_ind_t *)msg;
554 case FAPI_UCI_INDICATION:
556 fapi_uci_indication_t *phyUciInd = NULLP;
557 phyUciInd = (fapi_uci_indication_t*)msg;
558 procUciInd(phyUciInd);
561 case FAPI_SRS_INDICATION:
565 case FAPI_RACH_INDICATION:
567 fapi_rach_indication_t *rachInd;
568 rachInd = (fapi_rach_indication_t *)msg;
569 procRachInd(rachInd);
572 case FAPI_STOP_INDICATION:
574 DU_LOG("\nINFO --> LWR_MAC: Handling Stop Indication");
582 /**********************************************************************
584 **********************************************************************/