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_phy.h"
29 #include "lwr_mac_fsm.h"
30 #include "mac_utils.h"
31 #include "lwr_mac_utils.h"
34 #include "fapi_vendor_extension.h"
40 uint8_t rgClHndlCfgReq ARGS((void *msg));
41 void l1ProcessFapiRequest ARGS((uint8_t msgType, uint32_t msgLen, void *msg));
45 /*******************************************************************
47 * @brief Sends request to start wls receiver thread
51 * Function : LwrMacStartWlsRcvr
54 * Sends request to start wls receiver thread
59 * ****************************************************************/
60 void LwrMacStartWlsRcvr()
65 DU_LOG("\nLWR MAC: Requesting to start WLS receiver thread");
68 memset(&pst, 0, sizeof(Pst));
69 FILL_PST_LWR_MAC_TO_LWR_MAC(pst, EVT_START_WLS_RCVR);
71 if (ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf) != ROK)
73 DU_LOG("\nLWR MAC : Memory allocation failed for LwrMacStartWlsRcvr");
77 ODU_POST_TASK(&pst, mBuf);
80 /*******************************************************************
82 * @brief Enqueues memory blocks for use by L1
86 * Function : LwrMacEnqueueWlsBlock
89 * Enqueues memory blocks for use by L1
94 * ****************************************************************/
95 void LwrMacEnqueueWlsBlock()
98 void *wlsHdlr = NULLP;
100 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
104 mtGetWlsHdl(&wlsHdlr);
105 /* allocate blocks for UL transmittion */
106 while(WLS_EnqueueBlock(wlsHdlr, WLS_VA2PA(wlsHdlr, memPtr)))
108 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
113 // free not enqueued block
116 WLS_MEM_FREE(memPtr, LWR_MAC_WLS_BUF_SIZE);
119 }/* LwrMacEnqueueWlsBlock */
121 /*******************************************************************
123 * @brief Add memory block (to be freed later) to list
127 * Function : addWlsBlockToFree
130 * Add memory block (to be freed later) to list
133 * @return ROK - success
136 * ****************************************************************/
137 void addWlsBlockToFree(void *msg, uint32_t msgLen, uint8_t idx)
140 WlsBlockToFree *block;
141 MAC_ALLOC(block, sizeof(WlsBlockToFree));
144 MAC_ALLOC(node, sizeof(CmLList));
148 block->size = msgLen;
150 node->node = (PTR)block;
151 cmLListAdd2Tail(&wlsBlockToFreeList[idx], node);
154 }/* addWlsBlockToFree */
157 /*******************************************************************
159 * @brief Free DL Memory blocks stored in list
163 * Function : freeWlsBlockList
165 * Functionality: Free DL Memory blocks stored in list
167 * @params[in] Array index to be freed
168 * @return ROK - success
171 * ****************************************************************/
172 void freeWlsBlockList(uint8_t idx)
175 WlsBlockToFree *block;
176 if(wlsBlockToFreeList[idx].count)
178 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
181 block = (WlsBlockToFree *)node->node;
182 cmLListDelFrm(&wlsBlockToFreeList[idx], node);
183 WLS_MEM_FREE(block->ptr, block->size);
184 MAC_FREE(block, sizeof(WlsBlockToFree));
185 MAC_FREE(node, sizeof(CmLList));
187 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
192 /*******************************************************************
194 * @brief Receives msg from L1
198 * Function :LwrMacRecvPhyMsg
201 * Receives L1 Msg and enqueues memort for UL msg
205 * ****************************************************************/
206 void LwrMacRecvPhyMsg()
209 uint32_t numMsgToGet; /* Number of Memory blocks to get */
210 void *wlsHdlr; /* WLS handler */
211 uint64_t l1Msg; /* Message received */
216 p_fapi_api_queue_elem_t currElem = NULLP;
219 mtGetWlsHdl(&wlsHdlr);
220 if(WLS_Ready(wlsHdlr) == 0)
224 numMsgToGet = WLS_Wait(wlsHdlr);
230 printf("\nLWR_MAC: numMsgToGet %d", numMsgToGet);
234 l1Msg = (uint64_t)NULLP;
236 l1Msg = WLS_Get(wlsHdlr, &msgSize, &msgType, &flag);
239 l1MsgPtr = WLS_PA2VA(wlsHdlr, l1Msg);
240 currElem = (p_fapi_api_queue_elem_t) l1MsgPtr;
241 if(currElem->msg_type != FAPI_VENDOR_MSG_HEADER_IND)
243 procPhyMessages(currElem->msg_type, 0, (void *)(currElem + 1));
245 WLS_MEM_FREE(currElem, LWR_MAC_WLS_BUF_SIZE);
248 LwrMacEnqueueWlsBlock();
252 } /* LwrMacRecvPhyMsg */
254 #endif /* INTEL_WLS_MEM */
256 /*******************************************************************
258 * @brief Sends message to PHY Stub
262 * Function : LwrMacSendToPhy
264 * -Sends message to PHY Stub
265 * -Once super header and vendor specific message is
266 * implemented for all FAPI messages, this function
267 * can be deleted. LwrMacSendToFapi() should be used.
269 * @params[in] Message Type
275 * *****************************************************************/
277 uint8_t LwrMacSendToPhy(uint8_t msgType, uint32_t msgLen, void *msg)
279 l1ProcessFapiRequest(msgType, msgLen, msg);
281 } /* LwrMacSendToPhy */
284 /*******************************************************************
286 * @brief Send FAPI messages to Intel PHY/Phy stub
290 * Function : LwrMacSendToFapi
292 * Functionality: Send FAPI messages to Intel PHY/Phy stub
294 * @params[in] Message pointer
295 * @return ROK - success
298 * ****************************************************************/
299 uint8_t LwrMacSendToFapi(void *msg)
304 p_fapi_api_queue_elem_t currMsg = NULLP;
307 void * wlsHdlr = NULLP;
309 mtGetWlsHdl(&wlsHdlr);
312 currMsg = (p_fapi_api_queue_elem_t)msg;
313 msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t);
314 addWlsBlockToFree(currMsg, msgLen, (slotIndIdx-1));
315 if(currMsg->p_next == NULLP)
317 DU_LOG("\nThere cannot be only one block to send");
321 /* Sending first block */
322 ret = WLS_Put(wlsHdlr, WLS_VA2PA(wlsHdlr, currMsg), msgLen, currMsg->msg_type, WLS_SG_FIRST);
325 DU_LOG("\nFailure in sending message to PHY");
328 currMsg = currMsg->p_next;
332 /* Sending the next msg */
333 msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t);
334 addWlsBlockToFree(currMsg, msgLen, (slotIndIdx-1));
335 if(currMsg->p_next != NULLP)
337 ret = WLS_Put(wlsHdlr, WLS_VA2PA(wlsHdlr, currMsg), msgLen, currMsg->msg_type, WLS_SG_NEXT);
340 DU_LOG("\nFailure in sending message to PHY");
343 currMsg = currMsg->p_next;
347 /* Sending last msg */
348 ret = WLS_Put(wlsHdlr, WLS_VA2PA(wlsHdlr, currMsg), msgLen, currMsg->msg_type, WLS_SG_LAST);
351 DU_LOG("\nFailure in sending message to PHY");
359 p_fapi_api_queue_elem_t nextMsg = NULLP;
361 /* FAPI header and vendor specific msgs are freed here. Only
362 * the main FAPI messages are sent to phy stub */
363 currMsg = (p_fapi_api_queue_elem_t)msg;
366 nextMsg = currMsg->p_next;
367 msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t);
368 if((currMsg->msg_type != FAPI_VENDOR_MSG_HEADER_IND) && \
369 (currMsg->msg_type != FAPI_VENDOR_MESSAGE))
371 l1ProcessFapiRequest(currMsg->msg_type, msgLen, currMsg);
375 MAC_FREE(currMsg, msgLen);
384 /**********************************************************************
386 **********************************************************************/