FAPI TM, WLS_LIB and ODULOW documentation
[o-du/phy.git] / fapi_5g / source / api / fapi2phy / nr5g_fapi_fapi2phy_api.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 Intel.
4 *
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
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
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 *******************************************************************************/
18
19 /**
20  * @file This file contains implementation of all the functions used 
21  * to send APIs from FAPI to PHY
22  *
23  **/
24
25 #include <stdio.h>
26 #include "nr5g_fapi_internal.h"
27 #include "gnb_l1_l2_api.h"
28 #include "nr5g_fapi_wls.h"
29 #include "nr5g_fapi_fapi2phy_api.h"
30 #include "nr5g_fapi_fapi2phy_wls.h"
31 #include "nr5g_fapi_log.h"
32
33 nr5g_fapi_fapi2phy_queue_t fapi2phy_q;
34
35 //------------------------------------------------------------------------------
36 /** @ingroup     group_source_api_fapi2phy
37  *
38  *  @param[in]   p_list_elem Pointer to the ListElement
39  *
40  *  @return      void
41  *
42  *  @description This function adds a ListElement API to a Linked list which will
43  *               be sent to L1 once all APIs for a TTI are added
44  *
45 **/
46 //------------------------------------------------------------------------------
47 p_nr5g_fapi_fapi2phy_queue_t nr5g_fapi_fapi2phy_queue(
48     )
49 {
50     return &fapi2phy_q;
51 }
52
53 uint8_t nr5g_fapi_get_stats_location(
54     uint8_t msg_type)
55 {
56     uint8_t loc;
57     switch (msg_type) {
58         case MSG_TYPE_PHY_CONFIG_REQ:
59             loc = MEM_STAT_CONFIG_REQ;
60             break;
61
62         case MSG_TYPE_PHY_START_REQ:
63             loc = MEM_STAT_START_REQ;
64             break;
65
66         case MSG_TYPE_PHY_STOP_REQ:
67             loc = MEM_STAT_STOP_REQ;
68             break;
69
70         case MSG_TYPE_PHY_SHUTDOWN_REQ:
71             loc = MEM_STAT_SHUTDOWN_REQ;
72             break;
73
74         case MSG_TYPE_PHY_DL_CONFIG_REQ:
75             loc = MEM_STAT_DL_CONFIG_REQ;
76             break;
77
78         case MSG_TYPE_PHY_UL_CONFIG_REQ:
79             loc = MEM_STAT_UL_CONFIG_REQ;
80             break;
81
82         case MSG_TYPE_PHY_UL_DCI_REQ:
83             loc = MEM_STAT_UL_DCI_REQ;
84             break;
85
86         case MSG_TYPE_PHY_TX_REQ:
87             loc = MEM_STAT_TX_REQ;
88             break;
89
90         case MSG_TYPE_PHY_DL_IQ_SAMPLES:
91             loc = MEM_STAT_DL_IQ_SAMPLES;
92             break;
93
94         case MSG_TYPE_PHY_UL_IQ_SAMPLES:
95             loc = MEM_STAT_UL_IQ_SAMPLES;
96             break;
97
98         default:
99             loc = MEM_STAT_DEFAULT;
100     }
101
102     return loc;
103 }
104
105 //------------------------------------------------------------------------------
106 /** @ingroup     group_source_api_fapi2phy
107  *
108  *  @param[in]   msg_type Message Type
109  *  @param[in]   num_message_in_blockn Number of Messages in Block
110  *  @param[in]   align_offset Align Offset
111  *
112  *  @return      Pointer to the List Element structure
113  *
114  *  @description This function allocates a buffer from shared memory WLS
115  *               interface and creates a List Element structures. It then fills
116  *               all the fields with data being passed in.
117  *
118 **/
119 //------------------------------------------------------------------------------
120 PMAC2PHY_QUEUE_EL nr5g_fapi_fapi2phy_create_api_list_elem(
121     uint32_t msg_type,
122     uint16_t num_message_in_block,
123     uint32_t align_offset)
124 {
125     PMAC2PHY_QUEUE_EL p_list_elem = NULL;
126     uint8_t loc;
127
128     loc = nr5g_fapi_get_stats_location(msg_type);
129     p_list_elem = (PMAC2PHY_QUEUE_EL) wls_fapi_alloc_buffer(0, loc);
130     //Fill header for link list of API messages
131     if (p_list_elem) {
132         p_list_elem->nMessageType = (uint8_t) msg_type;
133         p_list_elem->nNumMessageInBlock = num_message_in_block;
134         p_list_elem->nAlignOffset = (uint16_t) align_offset;
135         p_list_elem->nMessageLen = num_message_in_block * align_offset;
136         p_list_elem->pNext = NULL;
137     }
138
139     return p_list_elem;
140 }
141
142 //------------------------------------------------------------------------------
143 /** @ingroup     group_source_api_fapi2phy
144  *
145  *  @param[in]   p_list_elem Pointer to the ListElement
146  *
147  *  @return      void
148  *
149  *  @description This function adds a ListElement API to a Linked list which will
150  *               be sent to L1 once all APIs for a TTI are added
151  *
152 **/
153 //------------------------------------------------------------------------------
154 void nr5g_fapi_fapi2phy_add_to_api_list(
155     PMAC2PHY_QUEUE_EL p_list_elem)
156 {
157     p_nr5g_fapi_fapi2phy_queue_t queue = NULL;
158
159     if (!p_list_elem) {
160         return;
161     }
162
163     queue = nr5g_fapi_fapi2phy_queue();
164     if (queue->p_send_list_head && queue->p_send_list_tail) {
165         queue->p_send_list_tail->pNext = p_list_elem;
166         queue->p_send_list_tail = p_list_elem;
167     } else {
168         queue->p_send_list_head = queue->p_send_list_tail = p_list_elem;
169     }
170 }
171
172 //------------------------------------------------------------------------------
173 /** @ingroup      group_source_api_fapi2phy
174  *
175  *  @param        A pointer to phy Instance
176  *
177  *  @return       FAPI status
178  *
179  *  @description  This function send API list to L1
180  *
181 **/
182 //------------------------------------------------------------------------------
183 void nr5g_fapi_fapi2phy_send_api_list(
184     )
185 {
186     uint8_t ret = FAILURE;
187     p_nr5g_fapi_fapi2phy_queue_t queue = NULL;
188
189     queue = nr5g_fapi_fapi2phy_queue();
190     if (queue->p_send_list_head) {
191
192         NR5G_FAPI_LOG(TRACE_LOG,
193             ("[NR5G_FAPI][FAPI2PHY] Sending API's to PHY"));
194         ret = nr5g_fapi_fapi2phy_wls_send(queue->p_send_list_head);
195         if (FAILURE == ret) {
196             NR5G_FAPI_LOG(ERROR_LOG,
197                 ("[NR5G_FAPI][FAPI2PHY] Error sending API's to PHY"));
198         }
199         queue->p_send_list_tail = queue->p_send_list_head = NULL;
200     }
201 }
202
203 //------------------------------------------------------------------------------
204 /** @ingroup        group_source_api_fapi2phy
205  *
206  *  @param[in]      A pointer to phy instance
207  *
208  *  @return         void
209  *
210  *  @description    The function adds all memory elements to WLS free list
211  *
212  **/
213 //-------------------------------------------------------------------------------------------
214
215 void nr5g_fapi_fapi2phy_destroy_api_list_elem(
216     PMAC2PHY_QUEUE_EL p_list_elem)
217 {
218     if (p_list_elem) {
219         uint8_t loc = nr5g_fapi_get_stats_location(p_list_elem->nMessageType);
220         wls_fapi_free_buffer(p_list_elem, loc);
221     }
222 }