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