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"
35 #include "fapi_vendor_extension.h"
41 uint8_t rgClHndlCfgReq ARGS((void *msg));
42 void l1ProcessFapiRequest ARGS((uint8_t msgType, uint32_t msgLen, void *msg));
46 /*******************************************************************
48 * @brief Sends request to start wls receiver thread
52 * Function : LwrMacStartWlsRcvr
55 * Sends request to start wls receiver thread
60 * ****************************************************************/
61 void LwrMacStartWlsRcvr()
66 DU_LOG("\nINFO --> LWR MAC : Requesting to start WLS receiver thread");
69 memset(&pst, 0, sizeof(Pst));
70 FILL_PST_LWR_MAC_TO_LWR_MAC(pst, EVT_START_WLS_RCVR);
72 if (ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf) != ROK)
74 DU_LOG("\nERROR --> LWR MAC : Memory allocation failed for LwrMacStartWlsRcvr");
78 ODU_POST_TASK(&pst, mBuf);
81 /*******************************************************************
83 * @brief Enqueues memory blocks for use by L1
87 * Function : LwrMacEnqueueWlsBlock
90 * Enqueues memory blocks for use by L1
95 * ****************************************************************/
96 void LwrMacEnqueueWlsBlock()
99 void *wlsHdlr = NULLP;
101 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
105 mtGetWlsHdl(&wlsHdlr);
106 /* allocate blocks for UL transmittion */
107 while(WLS_EnqueueBlock(wlsHdlr, WLS_VA2PA(wlsHdlr, memPtr)))
109 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
114 // free not enqueued block
117 WLS_MEM_FREE(memPtr, LWR_MAC_WLS_BUF_SIZE);
120 }/* LwrMacEnqueueWlsBlock */
122 /*******************************************************************
124 * @brief Add memory block (to be freed later) to list
128 * Function : addWlsBlockToFree
131 * Add memory block (to be freed later) to list
134 * @return ROK - success
137 * ****************************************************************/
138 void addWlsBlockToFree(void *msg, uint32_t msgLen, uint8_t idx)
140 CmLList *node = NULLP;
141 WlsBlockToFree *block = NULLP;
142 MAC_ALLOC(block, sizeof(WlsBlockToFree));
145 MAC_ALLOC(node, sizeof(CmLList));
149 block->size = msgLen;
151 node->node = (PTR)block;
152 cmLListAdd2Tail(&wlsBlockToFreeList[idx], node);
155 }/* addWlsBlockToFree */
158 /*******************************************************************
160 * @brief Free DL Memory blocks stored in list
164 * Function : freeWlsBlockList
166 * Functionality: Free DL Memory blocks stored in list
168 * @params[in] Array index to be freed
169 * @return ROK - success
172 * ****************************************************************/
173 void freeWlsBlockList(uint8_t idx)
176 WlsBlockToFree *block;
177 if(wlsBlockToFreeList[idx].count)
179 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
182 block = (WlsBlockToFree *)node->node;
183 cmLListDelFrm(&wlsBlockToFreeList[idx], node);
184 WLS_MEM_FREE(block->ptr, block->size);
185 MAC_FREE(block, sizeof(WlsBlockToFree));
186 MAC_FREE(node, sizeof(CmLList));
188 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
193 /*******************************************************************
195 * @brief Receives msg from L1
199 * Function :LwrMacRecvPhyMsg
202 * Receives L1 Msg and enqueues memort for UL msg
206 * ****************************************************************/
207 void LwrMacRecvPhyMsg()
210 uint32_t numMsgToGet; /* Number of Memory blocks to get */
211 void *wlsHdlr; /* WLS handler */
212 uint64_t l1Msg; /* Message received */
217 p_fapi_api_queue_elem_t currElem = NULLP;
219 mtGetWlsHdl(&wlsHdlr);
220 if(WLS_Ready(wlsHdlr) == 0)
224 numMsgToGet = WLS_Wait(wlsHdlr);
233 l1Msg = (uint64_t)NULLP;
235 l1Msg = WLS_Get(wlsHdlr, &msgSize, &msgType, &flag);
238 l1MsgPtr = WLS_PA2VA(wlsHdlr, l1Msg);
239 currElem = (p_fapi_api_queue_elem_t) l1MsgPtr;
240 if(currElem->msg_type != FAPI_VENDOR_MSG_HEADER_IND)
242 procPhyMessages(currElem->msg_type, 0, (void *)(currElem + 1));
244 WLS_MEM_FREE(currElem, LWR_MAC_WLS_BUF_SIZE);
247 LwrMacEnqueueWlsBlock();
251 } /* LwrMacRecvPhyMsg */
253 #endif /* INTEL_WLS_MEM */
255 /*******************************************************************
257 * @brief Send FAPI messages to Intel PHY/Phy stub
261 * Function : LwrMacSendToL1
263 * Functionality: Send FAPI messages to Intel PHY/Phy stub
265 * @params[in] Message pointer
266 * @return ROK - success
269 * ****************************************************************/
270 uint8_t LwrMacSendToL1(void *msg)
275 p_fapi_api_queue_elem_t currMsg = NULLP;
278 void * wlsHdlr = NULLP;
280 mtGetWlsHdl(&wlsHdlr);
283 currMsg = (p_fapi_api_queue_elem_t)msg;
284 msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t);
285 addWlsBlockToFree(currMsg, msgLen, (lwrMacCb.phySlotIndCntr-1));
286 if(currMsg->p_next == NULLP)
288 DU_LOG("\nERROR --> LWR MAC : There cannot be only one block to send");
292 /* Sending first block */
293 ret = WLS_Put(wlsHdlr, WLS_VA2PA(wlsHdlr, currMsg), msgLen, currMsg->msg_type, WLS_SG_FIRST);
296 DU_LOG("\nERROR --> LWR MAC : Failure in sending message to PHY");
299 currMsg = currMsg->p_next;
303 /* Sending the next msg */
304 msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t);
305 addWlsBlockToFree(currMsg, msgLen, (lwrMacCb.phySlotIndCntr-1));
306 if(currMsg->p_next != NULLP)
308 ret = WLS_Put(wlsHdlr, WLS_VA2PA(wlsHdlr, currMsg), msgLen, currMsg->msg_type, WLS_SG_NEXT);
311 DU_LOG("\nERROR --> LWR MAC : Failure in sending message to PHY");
314 currMsg = currMsg->p_next;
318 /* Sending last msg */
319 ret = WLS_Put(wlsHdlr, WLS_VA2PA(wlsHdlr, currMsg), msgLen, currMsg->msg_type, WLS_SG_LAST);
322 DU_LOG("\nERROR --> LWR MAC : Failure in sending message to PHY");
330 p_fapi_api_queue_elem_t nextMsg = NULLP;
332 /* FAPI header and vendor specific msgs are freed here. Only
333 * the main FAPI messages are sent to phy stub */
334 currMsg = (p_fapi_api_queue_elem_t)msg;
337 nextMsg = currMsg->p_next;
338 msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t);
339 if((currMsg->msg_type != FAPI_VENDOR_MSG_HEADER_IND) && \
340 (currMsg->msg_type != FAPI_VENDOR_MESSAGE))
342 l1ProcessFapiRequest(currMsg->msg_type, msgLen, currMsg);
346 LWR_MAC_FREE(currMsg, msgLen);
355 /**********************************************************************
357 **********************************************************************/