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"
36 EXTERN uint8_t rgClHndlCfgReq ARGS((void *msg));
37 EXTERN void l1ProcessFapiRequest ARGS((uint8_t msgType, uint32_t msgLen, void *msg));
41 /*******************************************************************
43 * @brief Enqueues memory blocks for use by L1
47 * Function : LwrMacEnqueueWlsBlock
50 * Enqueues memory blocks for use by L1
55 * ****************************************************************/
56 void LwrMacEnqueueWlsBlock()
61 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
65 wlsHdlr = mtGetWlsHdl();
67 /* allocate blocks for UL transmittion */
68 while(WLS_EnqueueBlock(wlsHdlr, WLS_VA2PA(wlsHdlr, memPtr)))
70 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
75 // free not enqueued block
78 WLS_MEM_FREE(memPtr, LWR_MAC_WLS_BUF_SIZE);
81 }/* LwrMacEnqueueWlsBlock */
83 /*******************************************************************
85 * @brief Enqueue N number of blocks
89 * Function : enqueueNBlocks
92 * Enqueue N number of memory blocks
94 * @params[in] Number of blocks
95 * @return ROK - success
98 * ****************************************************************/
99 uint16_t enqueueNBlocks(uint32_t numBlocks)
102 void *wlsHdlr; /* WLS handler */
104 wlsHdlr = mtGetWlsHdl();
109 memPtr = (void *)NULL;
110 WLS_MEM_ALLOC(memPtr, LWR_MAC_WLS_BUF_SIZE);
113 WLS_EnqueueBlock(wlsHdlr, WLS_VA2PA(wlsHdlr, memPtr));
117 }/* enqueueNBlocks */
119 /*******************************************************************
121 * @brief Add memory block (to be freed later) to list
125 * Function : addWlsBlockToFree
128 * Add memory block (to be freed later) to list
131 * @return ROK - success
134 * ****************************************************************/
135 void addWlsBlockToFree(void *msg, uint32_t msgLen, uint8_t idx)
138 WlsBlockToFree *block;
139 MAC_ALLOC(block, sizeof(WlsBlockToFree));
142 MAC_ALLOC(node, sizeof(CmLList));
146 block->size = msgLen;
148 node->node = (PTR)block;
149 cmLListAdd2Tail(&wlsBlockToFreeList[idx], node);
152 }/* addWlsBlockToFree */
154 void freeWlsBlockList(uint8_t idx)
157 WlsBlockToFree *block;
158 if(wlsBlockToFreeList[idx].count)
160 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
163 block = (WlsBlockToFree *)node->node;
164 cmLListDelFrm(&wlsBlockToFreeList[idx], node);
165 WLS_MEM_FREE(block->ptr, block->size);
166 MAC_FREE(block, sizeof(WlsBlockToFree));
167 MAC_FREE(node, sizeof(CmLList));
169 CM_LLIST_FIRST_NODE(&wlsBlockToFreeList[idx], node);
174 /*******************************************************************
176 * @brief Receives msg from L1
180 * Function :LwrMacRecvPhyMsg
183 * Receives L1 Msg and enqueues memort for UL msg
187 * ****************************************************************/
188 void LwrMacRecvPhyMsg()
190 uint32_t numL1Msg; /* Number of L1 messaes received */
191 uint32_t numToGet; /* Number of Memory blocks to get */
192 void *wlsHdlr; /* WLS handler */
193 uint64_t l1Msg; /* Message received */
199 wlsHdlr = mtGetWlsHdl();
200 if(WLS_Ready(wlsHdlr))
202 numToGet = WLS_Wait(wlsHdlr);
208 l1Msg = (uint64_t) NULL;
209 l1Msg = WLS_Get(wlsHdlr, &msgSize, &msgType, &flag);
212 l1MsgPtr = WLS_PA2VA(wlsHdlr, l1Msg);
213 procPhyMessages(msgType, msgSize, l1MsgPtr);
220 enqueueNBlocks(numL1Msg);
224 } /* LwrMacRecvPhyMsg */
226 #endif /* INTEL_WLS */
228 /*******************************************************************
230 * @brief Sends message to PHY
234 * Function : LwrMacSendToPhy
236 * -Sends message to PHY
238 * @params[in] Message Type
244 * *****************************************************************/
246 uint8_t LwrMacSendToPhy(uint8_t msgType, uint32_t msgLen, void *msg)
250 unsigned long long pMsg;
252 pMsg = WLS_VA2PA(mtGetWlsHdl(), msg);
253 ret = WLS_Put(mtGetWlsHdl(), pMsg, msgLen, msgType, 0);
257 printf("\nFailure in sending message to PHY");
258 WLS_MEM_FREE(msg, msgLen);
263 addWlsBlockToFree(msg, msgLen, (slotIndIdx-1));
266 l1ProcessFapiRequest(msgType, msgLen, msg);
269 } /* LwrMacSendToPhy */
271 /**********************************************************************
273 **********************************************************************/