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"
21 #include "tfu.h" /* RGU Interface defines */
26 /* header/extern include files (.x) */
27 #include "tfu.x" /* RGU Interface includes */
29 #include "lwr_mac_fsm.h"
30 #include "lwr_mac_phy.h"
31 #include "lwr_mac_upr_inf.h"
35 /* Function pointer for slot indication from lower mac to mac */
36 packSlotIndMsg packSlotIndOpts[] =
38 packLcSlotInd, /* packing for loosely coupled */
39 fapiMacSlotInd, /* packing for tightly coupled */
40 packLwlcSlotInd /* packing for light weight loosly coupled */
43 /* Function pointer for rach indication from lower mac to mac */
44 packRachIndMsg sendRachIndOpts[] =
51 /* Function pointer for crc indication from lower mac to mac */
52 packCrcIndMsg sendCrcIndOpts[] =
59 /* Function pointer for Rx Data indication from lower mac to mac */
60 packRxDataIndMsg sendRxDataIndOpts[] =
67 /* Function pointer for stop indication from lower mac to mac */
68 packStopIndMsg sendStopIndOpts[] =
74 /*******************************************************************
76 * @brief Fills post structure
80 * Function : fillLwrMacToMacPst
83 * Fills post structure used to send message from lower MAC
86 * @params[in] Pst pointer
87 * @return ROK - success
90 * ****************************************************************/
91 void fillLwrMacToMacPst(Pst *pst)
101 pst->selector = ODU_SELECTOR_TC;
104 /*******************************************************************
106 * @brief Processes Slot Indication from PHY and sends to MAC
110 * Function : handleSlotInd
113 * Processes Slot Indication from PHY and sends to MAC
115 * @params[in] fapi_slot_ind_t pointer
116 * @return ROK - success
119 * ****************************************************************/
120 U16 handleSlotInd(fapi_slot_ind_t *fapiSlotInd)
122 /* fill Pst structure to send to lwr_mac to MAC */
127 fillLwrMacToMacPst(&pst);
128 pst.event = EVENT_SLOT_IND_TO_MAC;
130 slotInd.sfn = fapiSlotInd->sfn;
131 slotInd.slot = fapiSlotInd->slot;
133 ret = (*packSlotIndOpts[pst.selector])(&pst, &slotInd);
137 if(slotIndIdx > WLS_MEM_FREE_PRD)
141 freeWlsBlockList(slotIndIdx - 1);
147 /*******************************************************************
149 * @brief Handles stop indication recived from PHY
153 * Function : handleStopInd
156 * Handles Stop Indication received from PHY
158 * @return ROK - success
161 * ****************************************************************/
162 uint8_t handleStopInd()
167 clGlobalCp.phyState = PHY_STATE_CONFIGURED;
168 DU_LOG("\nLWR_MAC: PHY has moved to configured state");
170 fillLwrMacToMacPst(&pst);
171 pst.event = EVENT_STOP_IND_TO_MAC;
173 ret = (*sendStopIndOpts[pst.selector])(&pst);
176 /*******************************************************************
178 * @brief Processes Rach Indication from PHY and sends to MAC
182 * Function : handleRachInd
185 * Processes Rach Indication from PHY and sends to MAC
187 * @params[in] fapi_rach_indication_t pointer
188 * @return ROK - success
191 * ****************************************************************/
192 uint8_t handleRachInd(fapi_rach_indication_t *fapiRachInd)
197 RachPduInfo *rachPdu;
200 rachInd.timingInfo.sfn = fapiRachInd->sfn;
201 rachInd.timingInfo.slot = fapiRachInd->slot;
202 rachInd.numPdu = fapiRachInd->numPdus;
203 for(pduIdx=0; pduIdx < rachInd.numPdu; pduIdx++)
205 rachPdu = &rachInd.rachPdu[pduIdx];
206 rachPdu->pci = fapiRachInd->rachPdu[pduIdx].physCellId;
207 rachPdu->symbolIdx = fapiRachInd->rachPdu[pduIdx].symbolIndex;
208 rachPdu->slotIdx = fapiRachInd->rachPdu[pduIdx].slotIndex;
209 rachPdu->freqIdx = fapiRachInd->rachPdu[pduIdx].freqIndex;
210 rachPdu->numPream = fapiRachInd->rachPdu[pduIdx].numPreamble;
211 for(prmbleIdx=0; prmbleIdx<rachPdu->numPream; prmbleIdx++)
213 rachPdu->preamInfo[prmbleIdx].preamIdx = \
214 fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].preambleIndex;
215 rachPdu->preamInfo[prmbleIdx].timingAdv = \
216 fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].timingAdvance;
219 fillLwrMacToMacPst(&pst);
220 pst.event = EVENT_RACH_IND_TO_MAC;
222 (*sendRachIndOpts[pst.selector])(&pst, &rachInd);
227 /*******************************************************************
229 * @brief Handles CRC indication from PHY and sends to MAC
233 * Function : handleCrcInd
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 handleCrcInd(fapi_crc_ind_t *fapiCrcInd)
248 uint8_t crcStatusIdx;
252 crcInd.timingInfo.sfn = fapiCrcInd->sfn;
253 crcInd.timingInfo.slot = fapiCrcInd->slot;
254 crcInd.numCrc = fapiCrcInd->numCrcs;
256 for(crcInfoIdx = 0; crcInfoIdx < crcInd.numCrc; crcInfoIdx++)
258 crcIndInfo = &crcInd.crcInfo[crcInfoIdx];
259 crcIndInfo->handle = fapiCrcInd->crc[crcInfoIdx].handle;
260 crcIndInfo->rnti = fapiCrcInd->crc[crcInfoIdx].rnti;
261 crcIndInfo->harqId = fapiCrcInd->crc[crcInfoIdx].harqId;
262 crcIndInfo->tbCrcStatus = fapiCrcInd->crc[crcInfoIdx].tbCrcStatus;
263 crcIndInfo->numCb = fapiCrcInd->crc[crcInfoIdx].numCb;
264 for(crcStatusIdx = 0; crcStatusIdx < crcIndInfo->numCb; crcStatusIdx++)
266 crcIndInfo->cbCrcStatus[crcStatusIdx] = \
267 fapiCrcInd->crc[crcInfoIdx].cbCrcStatus[crcStatusIdx];
269 crcIndInfo->ul_cqi = fapiCrcInd->crc[crcInfoIdx].ul_cqi;
270 crcIndInfo->timingAdvance = fapiCrcInd->crc[crcInfoIdx].timingAdvance;
271 crcIndInfo->rssi = fapiCrcInd->crc[crcInfoIdx].rssi;
274 fillLwrMacToMacPst(&pst);
275 pst.event = EVENT_CRC_IND_TO_MAC;
277 (*sendCrcIndOpts[pst.selector])(&pst, &crcInd);
282 /*******************************************************************
284 * @brief Handles Rx Data indication from PHY and sends to MAC
288 * Function : handleRxDataInd
291 * Handles Rx Data indication from PHY and sends to MAC
293 * @params[in] fapi_rx_data_indication_t message pointer
294 * @return ROK - success
297 * ****************************************************************/
299 uint8_t handleRxDataInd(fapi_rx_data_indication_t *fapiRxDataInd)
306 rxDataInd.timingInfo.sfn = fapiRxDataInd->sfn;
307 rxDataInd.timingInfo.slot = fapiRxDataInd->slot;
308 rxDataInd.numPdus = fapiRxDataInd->numPdus;
310 for(pduIdx = 0; pduIdx < rxDataInd.numPdus; pduIdx++)
312 pdu = &rxDataInd.pdus[pduIdx];
313 pdu->handle = fapiRxDataInd->pdus[pduIdx].handle;
314 pdu->rnti = fapiRxDataInd->pdus[pduIdx].rnti;
315 pdu->harqId = fapiRxDataInd->pdus[pduIdx].harqId;
316 pdu->pduLength = fapiRxDataInd->pdus[pduIdx].pduLength;
317 pdu->ul_cqi = fapiRxDataInd->pdus[pduIdx].ul_cqi;
318 pdu->timingAdvance = fapiRxDataInd->pdus[pduIdx].timingAdvance;
319 pdu->rssi = fapiRxDataInd->pdus[pduIdx].rssi;
321 MAC_ALLOC(pdu->pduData, pdu->pduLength);
322 memcpy(pdu->pduData, fapiRxDataInd->pdus[pduIdx].pduData, pdu->pduLength);
325 fillLwrMacToMacPst(&pst);
326 pst.event = EVENT_RX_DATA_IND_TO_MAC;
328 (*sendRxDataIndOpts[pst.selector])(&pst, &rxDataInd);
334 void handlePhyMessages(uint16_t msgType, uint32_t msgSize, void *msg)
337 /* extract the header */
339 header = (fapi_msg_t *)msg;
341 switch(header->message_type_id)
343 case FAPI_PARAM_RESPONSE:
344 case FAPI_CONFIG_RESPONSE:
346 sendToLowerMac(msgType, msgSize, msg);
349 case FAPI_SLOT_INDICATION:
351 if(clGlobalCp.phyState == PHY_STATE_CONFIGURED)
353 DU_LOG("\nLWR_MAC: PHY has moved to running state");
354 clGlobalCp.phyState = PHY_STATE_RUNNING;
357 fapi_slot_ind_t *slotInd;
358 slotInd = (fapi_slot_ind_t *)msg;
359 handleSlotInd(slotInd);
362 case FAPI_ERROR_INDICATION:
366 case FAPI_RX_DATA_INDICATION:
368 fapi_rx_data_indication_t *rxDataInd;
369 rxDataInd = (fapi_rx_data_indication_t *)msg;
370 handleRxDataInd(rxDataInd);
373 case FAPI_CRC_INDICATION:
375 fapi_crc_ind_t *crcInd;
376 crcInd = (fapi_crc_ind_t *)msg;
377 handleCrcInd(crcInd);
380 case FAPI_UCI_INDICATION:
384 case FAPI_SRS_INDICATION:
388 case FAPI_RACH_INDICATION:
390 fapi_rach_indication_t *rachInd;
391 rachInd = (fapi_rach_indication_t *)msg;
392 handleRachInd(rachInd);
395 case FAPI_STOP_INDICATION:
397 DU_LOG("\nLWR_MAC: Handling Stop Indication");
403 WLS_MEM_FREE(msg, LWR_MAC_WLS_BUF_SIZE);
408 /**********************************************************************
410 **********************************************************************/