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"
38 /* Function pointer for slot indication from lower mac to mac */
39 packSlotIndMsg packSlotIndOpts[] =
41 packLcSlotInd, /* packing for loosely coupled */
42 fapiMacSlotInd, /* packing for tightly coupled */
43 packLwlcSlotInd /* packing for light weight loosly coupled */
46 /* Function pointer for rach indication from lower mac to mac */
47 packRachIndMsg sendRachIndOpts[] =
54 /* Function pointer for crc indication from lower mac to mac */
55 packCrcIndMsg sendCrcIndOpts[] =
62 /* Function pointer for Rx Data indication from lower mac to mac */
63 packRxDataIndMsg sendRxDataIndOpts[] =
70 /* Function pointer for stop indication from lower mac to mac */
71 packStopIndMsg sendStopIndOpts[] =
77 /*******************************************************************
79 * @brief Fills post structure
83 * Function : fillLwrMacToMacPst
86 * Fills post structure used to send message from lower MAC
89 * @params[in] Pst pointer
90 * @return ROK - success
93 * ****************************************************************/
94 void fillLwrMacToMacPst(Pst *pst)
104 pst->selector = ODU_SELECTOR_TC;
107 /*******************************************************************
109 * @brief Processes Slot Indication from PHY and sends to MAC
113 * Function : procSlotInd
116 * Processes Slot Indication from PHY and sends to MAC
118 * @params[in] fapi_slot_ind_t pointer
119 * @return ROK - success
122 * ****************************************************************/
123 uint8_t procSlotInd(fapi_slot_ind_t *fapiSlotInd)
125 /* fill Pst structure to send to lwr_mac to MAC */
130 fillLwrMacToMacPst(&pst);
131 pst.event = EVENT_SLOT_IND_TO_MAC;
133 slotInd.cellId = lwrMacCb.cellCb[0].cellId;
134 slotInd.sfn = fapiSlotInd->sfn;
135 slotInd.slot = fapiSlotInd->slot;
137 ret = (*packSlotIndOpts[pst.selector])(&pst, &slotInd);
141 if(slotIndIdx > WLS_MEM_FREE_PRD)
145 freeWlsBlockList(slotIndIdx - 1);
151 /*******************************************************************
153 * @brief Handles stop indication recived from PHY
157 * Function : procStopInd
160 * Handles Stop Indication received from PHY
162 * @return ROK - success
165 * ****************************************************************/
166 uint8_t procStopInd()
171 lwrMacCb.phyState = PHY_STATE_CONFIGURED;
172 lwrMacCb.cellCb[0].state = PHY_STATE_CONFIGURED;
173 DU_LOG("\nLWR_MAC: PHY has moved to configured state");
175 fillLwrMacToMacPst(&pst);
176 pst.event = EVENT_STOP_IND_TO_MAC;
178 ret = (*sendStopIndOpts[pst.selector])(&pst, \
179 lwrMacCb.cellCb[0].cellId);
182 /*******************************************************************
184 * @brief Processes Rach Indication from PHY and sends to MAC
188 * Function : procRachInd
191 * Processes Rach Indication from PHY and sends to MAC
193 * @params[in] fapi_rach_indication_t pointer
194 * @return ROK - success
197 * ****************************************************************/
198 uint8_t procRachInd(fapi_rach_indication_t *fapiRachInd)
203 RachPduInfo *rachPdu;
206 rachInd.cellId = lwrMacCb.cellCb[0].cellId;
207 rachInd.timingInfo.sfn = fapiRachInd->sfn;
208 rachInd.timingInfo.slot = fapiRachInd->slot;
209 rachInd.numPdu = fapiRachInd->numPdus;
210 for(pduIdx=0; pduIdx < rachInd.numPdu; pduIdx++)
212 rachPdu = &rachInd.rachPdu[pduIdx];
213 rachPdu->pci = fapiRachInd->rachPdu[pduIdx].phyCellId;
214 rachPdu->symbolIdx = fapiRachInd->rachPdu[pduIdx].symbolIndex;
215 rachPdu->slotIdx = fapiRachInd->rachPdu[pduIdx].slotIndex;
216 rachPdu->freqIdx = fapiRachInd->rachPdu[pduIdx].freqIndex;
217 rachPdu->numPream = fapiRachInd->rachPdu[pduIdx].numPreamble;
218 for(prmbleIdx=0; prmbleIdx<rachPdu->numPream; prmbleIdx++)
220 rachPdu->preamInfo[prmbleIdx].preamIdx = \
221 fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].preambleIndex;
222 rachPdu->preamInfo[prmbleIdx].timingAdv = \
223 fapiRachInd->rachPdu[pduIdx].preambleInfo[prmbleIdx].timingAdvance;
226 fillLwrMacToMacPst(&pst);
227 pst.event = EVENT_RACH_IND_TO_MAC;
229 (*sendRachIndOpts[pst.selector])(&pst, &rachInd);
234 /*******************************************************************
236 * @brief Handles CRC indication from PHY and sends to MAC
240 * Function : procCrcInd
243 * Handles CRC indication from PHY and sends to MAC
245 * @params[in] fapi_crc_ind_t message pointer
246 * @return ROK - success
249 * ****************************************************************/
251 uint8_t procCrcInd(fapi_crc_ind_t *fapiCrcInd)
255 uint8_t crcStatusIdx;
259 crcInd.cellId = lwrMacCb.cellCb[0].cellId;
260 crcInd.timingInfo.sfn = fapiCrcInd->sfn;
261 crcInd.timingInfo.slot = fapiCrcInd->slot;
262 crcInd.numCrc = fapiCrcInd->numCrcs;
264 for(crcInfoIdx = 0; crcInfoIdx < crcInd.numCrc; crcInfoIdx++)
266 crcIndInfo = &crcInd.crcInfo[crcInfoIdx];
267 crcIndInfo->handle = fapiCrcInd->crc[crcInfoIdx].handle;
268 crcIndInfo->rnti = fapiCrcInd->crc[crcInfoIdx].rnti;
269 crcIndInfo->harqId = fapiCrcInd->crc[crcInfoIdx].harqId;
270 crcIndInfo->tbCrcStatus = fapiCrcInd->crc[crcInfoIdx].tbCrcStatus;
271 crcIndInfo->numCb = fapiCrcInd->crc[crcInfoIdx].numCb;
272 for(crcStatusIdx = 0; crcStatusIdx < crcIndInfo->numCb; crcStatusIdx++)
274 crcIndInfo->cbCrcStatus[crcStatusIdx] = \
275 fapiCrcInd->crc[crcInfoIdx].cbCrcStatus[crcStatusIdx];
277 crcIndInfo->ul_cqi = fapiCrcInd->crc[crcInfoIdx].ul_cqi;
278 crcIndInfo->timingAdvance = fapiCrcInd->crc[crcInfoIdx].timingAdvance;
279 crcIndInfo->rssi = fapiCrcInd->crc[crcInfoIdx].rssi;
282 fillLwrMacToMacPst(&pst);
283 pst.event = EVENT_CRC_IND_TO_MAC;
285 (*sendCrcIndOpts[pst.selector])(&pst, &crcInd);
290 /*******************************************************************
292 * @brief Handles Rx Data indication from PHY and sends to MAC
296 * Function : procRxDataInd
299 * Handles Rx Data indication from PHY and sends to MAC
301 * @params[in] fapi_rx_data_indication_t message pointer
302 * @return ROK - success
305 * ****************************************************************/
307 uint8_t procRxDataInd(fapi_rx_data_indication_t *fapiRxDataInd)
314 rxDataInd.cellId = lwrMacCb.cellCb[0].cellId;
315 rxDataInd.timingInfo.sfn = fapiRxDataInd->sfn;
316 rxDataInd.timingInfo.slot = fapiRxDataInd->slot;
317 rxDataInd.numPdus = fapiRxDataInd->numPdus;
319 for(pduIdx = 0; pduIdx < rxDataInd.numPdus; pduIdx++)
321 pdu = &rxDataInd.pdus[pduIdx];
322 pdu->handle = fapiRxDataInd->pdus[pduIdx].handle;
323 pdu->rnti = fapiRxDataInd->pdus[pduIdx].rnti;
324 pdu->harqId = fapiRxDataInd->pdus[pduIdx].harqId;
325 pdu->pduLength = fapiRxDataInd->pdus[pduIdx].pdu_length;
326 pdu->ul_cqi = fapiRxDataInd->pdus[pduIdx].ul_cqi;
327 pdu->timingAdvance = fapiRxDataInd->pdus[pduIdx].timingAdvance;
328 pdu->rssi = fapiRxDataInd->pdus[pduIdx].rssi;
330 MAC_ALLOC(pdu->pduData, pdu->pduLength);
331 memcpy(pdu->pduData, fapiRxDataInd->pdus[pduIdx].pduData, pdu->pduLength);
334 fillLwrMacToMacPst(&pst);
335 pst.event = EVENT_RX_DATA_IND_TO_MAC;
337 (*sendRxDataIndOpts[pst.selector])(&pst, &rxDataInd);
343 void procPhyMessages(uint16_t msgType, uint32_t msgSize, void *msg)
346 /* extract the header */
348 header = (fapi_msg_t *)msg;
350 switch(header->msg_id)
352 case FAPI_PARAM_RESPONSE:
353 case FAPI_CONFIG_RESPONSE:
355 sendToLowerMac(msgType, msgSize, msg);
358 case FAPI_SLOT_INDICATION:
360 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
362 DU_LOG("\nLWR_MAC: PHY has moved to running state");
363 lwrMacCb.phyState = PHY_STATE_RUNNING;
364 lwrMacCb.cellCb[0].state = PHY_STATE_RUNNING;
367 fapi_slot_ind_t *slotInd;
368 slotInd = (fapi_slot_ind_t *)msg;
369 procSlotInd(slotInd);
372 case FAPI_ERROR_INDICATION:
376 case FAPI_RX_DATA_INDICATION:
378 fapi_rx_data_indication_t *rxDataInd;
379 rxDataInd = (fapi_rx_data_indication_t *)msg;
380 procRxDataInd(rxDataInd);
383 case FAPI_CRC_INDICATION:
385 fapi_crc_ind_t *crcInd;
386 crcInd = (fapi_crc_ind_t *)msg;
390 case FAPI_UCI_INDICATION:
394 case FAPI_SRS_INDICATION:
398 case FAPI_RACH_INDICATION:
400 fapi_rach_indication_t *rachInd;
401 rachInd = (fapi_rach_indication_t *)msg;
402 procRachInd(rachInd);
405 case FAPI_STOP_INDICATION:
407 DU_LOG("\nLWR_MAC: Handling Stop Indication");
413 WLS_MEM_FREE(msg, LWR_MAC_WLS_BUF_SIZE);
418 /**********************************************************************
420 **********************************************************************/