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 /* This file contains APIs to send/receive messages from PHY */
21 #include "common_def.h"
24 #include "du_app_mac_inf.h"
25 #include "mac_sch_interface.h"
26 #include "lwr_mac_upr_inf.h"
28 #include "lwr_mac_fsm.h"
29 #include "lwr_mac_phy.h"
30 #include "mac_utils.h"
31 #include "lwr_mac_utils.h"
34 #include "nr5g_fapi_internal.h"
35 #include "fapi_vendor_extension.h"
42 CmLListCp wlsBlockToFreeList[WLS_MEM_FREE_PRD];
45 uint8_t rgClHndlCfgReq ARGS((void *msg));
46 void l1ProcessFapiRequest ARGS((uint8_t msgType, uint32_t msgLen, void *msg));
50 /*******************************************************************
52 * @brief Sends request to start wls receiver thread
56 * Function : LwrMacStartWlsRcvr
59 * Sends request to start wls receiver thread
64 * ****************************************************************/
65 void LwrMacStartWlsRcvr()
70 DU_LOG("\nINFO --> LWR MAC : Requesting to start WLS receiver thread");
73 memset(&pst, 0, sizeof(Pst));
74 FILL_PST_LWR_MAC_TO_LWR_MAC(pst, EVT_START_WLS_RCVR);
76 if (ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf) != ROK)
78 DU_LOG("\nERROR --> LWR MAC : Memory allocation failed for LwrMacStartWlsRcvr");
82 ODU_POST_TASK(&pst, mBuf);
85 /*******************************************************************
87 * @brief Enqueues memory blocks for use by L1
91 * Function : LwrMacEnqueueWlsBlock
94 * Enqueues memory blocks for use by L1
99 * ****************************************************************/
100 void LwrMacEnqueueWlsBlock()
103 void *wlsHdlr = NULLP;
105 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
109 mtGetWlsHdl(&wlsHdlr);
110 /* allocate blocks for UL transmittion */
111 while(WLS_EnqueueBlock(wlsHdlr, WLS_VA2PA(wlsHdlr, memPtr)))
113 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
118 // free not enqueued block
121 WLS_MEM_FREE(memPtr, LWR_MAC_WLS_BUF_SIZE);
124 }/* LwrMacEnqueueWlsBlock */
126 /*******************************************************************
128 * @brief Add memory block (to be freed later) to list
132 * Function : addWlsBlockToFree
135 * Add memory block (to be freed later) to list
138 * @return ROK - success
141 * ****************************************************************/
142 void addWlsBlockToFree(void *msg, uint32_t msgLen, uint8_t idx)
144 CmLList *node = NULLP;
145 WlsBlockToFree *block = NULLP;
146 MAC_ALLOC(block, sizeof(WlsBlockToFree));
149 MAC_ALLOC(node, sizeof(CmLList));
153 block->size = msgLen;
155 node->node = (PTR)block;
156 cmLListAdd2Tail(&wlsBlockToFreeList[idx], node);
159 }/* addWlsBlockToFree */
162 /*******************************************************************
164 * @brief Free DL Memory blocks stored in list
168 * Function : freeWlsBlockList
170 * Functionality: Free DL Memory blocks stored in list
172 * @params[in] Array index to be freed
173 * @return ROK - success
176 * ****************************************************************/
177 void freeWlsBlockList(uint8_t idx)
180 WlsBlockToFree *block;
181 if(wlsBlockToFreeList[idx].count)
183 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
186 block = (WlsBlockToFree *)node->node;
187 cmLListDelFrm(&wlsBlockToFreeList[idx], node);
188 WLS_MEM_FREE(block->ptr, block->size);
189 MAC_FREE(block, sizeof(WlsBlockToFree));
190 MAC_FREE(node, sizeof(CmLList));
192 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
197 /*******************************************************************
199 * @brief Receives msg from L1
203 * Function :LwrMacRecvPhyMsg
206 * Receives L1 Msg and enqueues memort for UL msg
210 * ****************************************************************/
211 void LwrMacRecvPhyMsg()
214 uint32_t numMsgToGet; /* Number of Memory blocks to get */
215 void *wlsHdlr; /* WLS handler */
216 uint64_t l1Msg; /* Message received */
221 p_fapi_api_queue_elem_t currElem = NULLP;
223 mtGetWlsHdl(&wlsHdlr);
224 if(WLS_Ready(wlsHdlr) == 0)
228 numMsgToGet = WLS_Wait(wlsHdlr);
237 l1Msg = (uint64_t)NULLP;
239 l1Msg = WLS_Get(wlsHdlr, &msgSize, &msgType, &flag);
242 l1MsgPtr = WLS_PA2VA(wlsHdlr, l1Msg);
243 currElem = (p_fapi_api_queue_elem_t) l1MsgPtr;
244 if(currElem->msg_type != FAPI_VENDOR_MSG_HEADER_IND)
246 procPhyMessages(currElem->msg_type, 0, (void *)(currElem + 1));
248 WLS_MEM_FREE(currElem, LWR_MAC_WLS_BUF_SIZE);
251 LwrMacEnqueueWlsBlock();
255 } /* LwrMacRecvPhyMsg */
257 #endif /* INTEL_WLS_MEM */
259 /*******************************************************************
261 * @brief Send FAPI messages to Intel PHY/Phy stub
265 * Function : LwrMacSendToL1
267 * Functionality: Send FAPI messages to Intel PHY/Phy stub
269 * @params[in] Message pointer
270 * @return ROK - success
273 * ****************************************************************/
274 uint8_t LwrMacSendToL1(void *msg)
279 p_fapi_api_queue_elem_t currMsg = NULLP;
281 #ifdef CALL_FLOW_DEBUG_LOG
284 currMsg = (p_fapi_api_queue_elem_t)msg;
287 switch(currMsg->msg_type)
289 case FAPI_PARAM_REQUEST:
290 strcpy(message, "FAPI_PARAM_REQUEST");
292 case FAPI_CONFIG_REQUEST:
293 strcpy(message, "FAPI_CONFIG_REQUEST");
295 case FAPI_START_REQUEST:
296 strcpy(message, "FAPI_START_REQUEST");
298 case FAPI_DL_TTI_REQUEST:
299 strcpy(message, "FAPI_DL_TTI_REQUEST");
301 case FAPI_TX_DATA_REQUEST:
302 strcpy(message, "FAPI_TX_DATA_REQUEST");
304 case FAPI_UL_TTI_REQUEST:
305 strcpy(message, "FAPI_UL_TTI_REQUEST");
307 case FAPI_STOP_REQUEST:
308 strcpy(message, "FAPI_STOP_REQUEST");
310 case FAPI_UL_DCI_REQUEST:
311 strcpy(message, "FAPI_UL_DCI_REQUEST");
314 strcpy(message, "INVALID_MSG");
317 DU_LOG("\nCall Flow: ENTLWRMAC -> PHY : %s\n",message);
318 currMsg = currMsg->p_next;
324 void * wlsHdlr = NULLP;
326 mtGetWlsHdl(&wlsHdlr);
329 currMsg = (p_fapi_api_queue_elem_t)msg;
330 msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t);
331 addWlsBlockToFree(currMsg, msgLen, (lwrMacCb.phySlotIndCntr-1));
332 if(currMsg->p_next == NULLP)
334 DU_LOG("\nERROR --> LWR MAC : There cannot be only one block to send");
338 /* Sending first block */
339 ret = WLS_Put(wlsHdlr, WLS_VA2PA(wlsHdlr, currMsg), msgLen, currMsg->msg_type, WLS_SG_FIRST);
342 DU_LOG("\nERROR --> LWR MAC : Failure in sending message to PHY");
345 currMsg = currMsg->p_next;
349 /* Sending the next msg */
350 msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t);
351 addWlsBlockToFree(currMsg, msgLen, (lwrMacCb.phySlotIndCntr-1));
352 if(currMsg->p_next != NULLP)
354 ret = WLS_Put(wlsHdlr, WLS_VA2PA(wlsHdlr, currMsg), msgLen, currMsg->msg_type, WLS_SG_NEXT);
357 DU_LOG("\nERROR --> LWR MAC : Failure in sending message to PHY");
360 currMsg = currMsg->p_next;
364 /* Sending last msg */
365 ret = WLS_Put(wlsHdlr, WLS_VA2PA(wlsHdlr, currMsg), msgLen, currMsg->msg_type, WLS_SG_LAST);
368 DU_LOG("\nERROR --> LWR MAC : Failure in sending message to PHY");
376 p_fapi_api_queue_elem_t nextMsg = NULLP;
378 /* FAPI header and vendor specific msgs are freed here. Only
379 * the main FAPI messages are sent to phy stub */
380 currMsg = (p_fapi_api_queue_elem_t)msg;
383 nextMsg = currMsg->p_next;
384 msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t);
385 if((currMsg->msg_type != FAPI_VENDOR_MSG_HEADER_IND) && \
386 (currMsg->msg_type != FAPI_VENDOR_MESSAGE))
388 l1ProcessFapiRequest(currMsg->msg_type, msgLen, currMsg);
392 LWR_MAC_FREE(currMsg, msgLen);
401 /**********************************************************************
403 **********************************************************************/