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"
23 #include "lwr_mac_phy.h"
24 #include "lwr_mac_fsm.h"
30 EXTERN S16 rgClHndlCfgReq ARGS((void *msg));
31 EXTERN void l1ProcessFapiRequest ARGS((uint8_t msgType, uint32_t msgLen, void *msg));
35 /*******************************************************************
37 * @brief Enqueues memory blocks for use by L1
41 * Function : LwrMacEnqueueWlsBlock
44 * Enqueues memory blocks for use by L1
49 * ****************************************************************/
50 void LwrMacEnqueueWlsBlock()
55 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
59 wlsHdlr = mtGetWlsHdl();
61 /* allocate blocks for UL transmittion */
62 while(WLS_EnqueueBlock(wlsHdlr, WLS_VA2PA(wlsHdlr, memPtr)))
64 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
69 // free not enqueued block
72 WLS_MEM_FREE(memPtr, LWR_MAC_WLS_BUF_SIZE);
75 }/* LwrMacEnqueueWlsBlock */
77 /*******************************************************************
79 * @brief Enqueue N number of blocks
83 * Function : enqueueNBlocks
86 * Enqueue N number of memory blocks
88 * @params[in] Number of blocks
89 * @return ROK - success
92 * ****************************************************************/
93 uint16_t enqueueNBlocks(uint32_t numBlocks)
96 void *wlsHdlr; /* WLS handler */
98 wlsHdlr = mtGetWlsHdl();
103 memPtr = (void *)NULL;
104 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
107 WLS_EnqueueBlock(wlsHdlr, WLS_VA2PA(wlsHdlr, memPtr));
111 }/* enqueueNBlocks */
113 /*******************************************************************
115 * @brief Add memory block (to be freed later) to list
119 * Function : addWlsBlockToFree
122 * Add memory block (to be freed later) to list
125 * @return ROK - success
128 * ****************************************************************/
129 void addWlsBlockToFree(void *msg, uint32_t msgLen, uint8_t idx)
132 WlsBlockToFree *block;
133 MAC_ALLOC(block, sizeof(WlsBlockToFree));
136 MAC_ALLOC(node, sizeof(CmLList));
140 block->size = msgLen;
142 node->node = (PTR)block;
143 cmLListAdd2Tail(&wlsBlockToFreeList[idx], node);
146 }/* addWlsBlockToFree */
148 void freeWlsBlockList(uint8_t idx)
151 WlsBlockToFree *block;
152 if(wlsBlockToFreeList[idx].count)
154 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
157 block = (WlsBlockToFree *)node->node;
158 cmLListDelFrm(&wlsBlockToFreeList[idx], node);
159 WLS_MEM_FREE(block->ptr, block->size);
160 MAC_FREE(block, sizeof(WlsBlockToFree));
161 MAC_FREE(node, sizeof(CmLList));
163 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
168 /*******************************************************************
170 * @brief Receives msg from L1
174 * Function :LwrMacRecvPhyMsg
177 * Receives L1 Msg and enqueues memort for UL msg
181 * ****************************************************************/
182 void LwrMacRecvPhyMsg()
184 uint32_t numL1Msg; /* Number of L1 messaes received */
185 uint32_t numToGet; /* Number of Memory blocks to get */
186 void *wlsHdlr; /* WLS handler */
187 uint64_t l1Msg; /* Message received */
193 wlsHdlr = mtGetWlsHdl();
194 if(WLS_Ready(wlsHdlr))
196 numToGet = WLS_Wait(wlsHdlr);
202 l1Msg = (uint64_t) NULL;
203 l1Msg = WLS_Get(wlsHdlr, &msgSize, &msgType, &flag);
206 l1MsgPtr = WLS_PA2VA(wlsHdlr, l1Msg);
207 handlePhyMessages(msgType, msgSize, l1MsgPtr);
214 enqueueNBlocks(numL1Msg);
218 } /* LwrMacRecvPhyMsg */
220 #endif /* INTEL_WLS */
222 /*******************************************************************
224 * @brief Sends message to PHY
228 * Function : LwrMacSendToPhy
230 * -Sends message to PHY
232 * @params[in] Message Type
238 * *****************************************************************/
240 PUBLIC uint16_t LwrMacSendToPhy(uint8_t msgType, uint32_t msgLen, void *msg)
244 unsigned long long pMsg;
246 pMsg = WLS_VA2PA(mtGetWlsHdl(), msg);
247 ret = WLS_Put(mtGetWlsHdl(), pMsg, msgLen, msgType, 0);
251 printf("\nFailure in sending message to PHY");
252 WLS_MEM_FREE(msg, msgLen);
257 addWlsBlockToFree(msg, msgLen, (slotIndIdx-1));
260 l1ProcessFapiRequest(msgType, msgLen, msg);
263 } /* LwrMacSendToPhy */
265 /**********************************************************************
267 **********************************************************************/