* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fapi_5g / source / framework / workers / nr5g_fapi_phy2mac_thread.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 #include "nr5g_fapi_framework.h"
19 #include "nr5g_fapi_fapi2phy_wls.h"
20 #include "nr5g_fapi_phy2mac_thread.h"
21 #include "nr5g_fapi_fapi2mac_api.h"
22 #include "nr5g_fapi_fapi2mac_p5_proc.h"
23 #include "nr5g_fapi_fapi2mac_p7_proc.h"
24 #include "nr5g_fapi_log.h"
25 //------------------------------------------------------------------------------
26 /** @ingroup nr5g_fapi_source_framework_workers_phy2mac_group
27  *
28  *  @param[in,out]   void
29  *
30  *  @return none
31  *
32  *  @description
33  *  DOXYGEN_TO_DO
34  *
35 **/
36 //------------------------------------------------------------------------------
37 void *nr5g_fapi_phy2mac_thread_func(
38     void *config)
39 {
40     PMAC2PHY_QUEUE_EL p_msg_list = NULL;
41     p_nr5g_fapi_phy_ctx_t p_phy_ctx = (p_nr5g_fapi_phy_ctx_t) config;
42
43     NR5G_FAPI_LOG(INFO_LOG, ("[PHY2MAC] Thread %s launched LWP:%ld on "
44             "Core: %d\n", __func__, pthread_self(),
45             p_phy_ctx->phy2mac_worker_core_id));
46
47     nr5g_fapi_init_thread(p_phy_ctx->phy2mac_worker_core_id);
48
49     nr5g_fapi_fapi2mac_init_api_list();
50
51     while (!p_phy_ctx->process_exit) {
52         p_msg_list = nr5g_fapi_fapi2phy_wls_recv();
53         if (p_msg_list)
54             nr5g_fapi_phy2mac_api_recv_handler(false, config, p_msg_list);
55
56         nr5g_fapi_fapi2mac_send_api_list(false);
57     }
58     pthread_exit(NULL);
59 }
60
61 //------------------------------------------------------------------------------
62 /** @ingroup nr5g_fapi_source_framework_workers_mac2phy_group
63  *
64  *  @param[in,out]   void
65  *
66  *  @return none
67  *
68  *  @description
69  *  DOXYGEN_TO_DO
70  *
71 **/
72 //------------------------------------------------------------------------------
73 void nr5g_fapi_phy2mac_api_recv_handler(
74     bool is_urllc,
75     void *config,
76     PMAC2PHY_QUEUE_EL p_msg_list)
77 {
78     PMAC2PHY_QUEUE_EL p_curr_msg;
79     PL1L2MessageHdr p_msg_header = NULL;
80     uint64_t start_tick = __rdtsc();
81     fapi_api_stored_vendor_queue_elems vendor_extension_elems;
82     NR5G_FAPI_LOG(TRACE_LOG, ("[PHY2MAC] %s:", __func__));
83
84     memset(&vendor_extension_elems, 0, sizeof(vendor_extension_elems));
85     nr5g_fapi_message_header((p_nr5g_fapi_phy_ctx_t) config, is_urllc);
86
87     p_curr_msg = (PMAC2PHY_QUEUE_EL) p_msg_list;
88     while (p_curr_msg) {
89         p_msg_header = (PL1L2MessageHdr) (p_curr_msg + 1);
90         switch (p_msg_header->nMessageType) {
91                 /*  P5 Vendor Message Processing */
92 #ifdef DEBUG_MODE
93             case MSG_TYPE_PHY_DL_IQ_SAMPLES:
94                 {
95                     nr5g_fapi_dl_iq_samples_response((p_nr5g_fapi_phy_ctx_t)
96                         config, (PADD_REMOVE_BBU_CORES_NR5G) p_msg_header);
97                 }
98                 break;
99
100             case MSG_TYPE_PHY_UL_IQ_SAMPLES:
101                 {
102                     nr5g_fapi_ul_iq_samples_response((p_nr5g_fapi_phy_ctx_t)
103                         config, (PADD_REMOVE_BBU_CORES_NR5G) p_msg_header);
104                 }
105                 break;
106 #endif
107             case MSG_TYPE_PHY_SHUTDOWN_RESP:
108                 {
109                     nr5g_fapi_shutdown_response((p_nr5g_fapi_phy_ctx_t) config,
110                         (PSHUTDOWNRESPONSEStruct) p_msg_header);
111                 }
112                 break;
113
114                 /*  P5 Message Processing */
115             case MSG_TYPE_PHY_CONFIG_RESP:
116                 {
117                     nr5g_fapi_config_response((p_nr5g_fapi_phy_ctx_t) config,
118                         (PCONFIGRESPONSEStruct) p_msg_header);
119                 }
120                 break;
121
122             case MSG_TYPE_PHY_START_RESP:
123                 {
124                     nr5g_fapi_start_resp((p_nr5g_fapi_phy_ctx_t) config,
125                         (PSTARTRESPONSEStruct) p_msg_header);
126                 }
127                 break;
128
129             case MSG_TYPE_PHY_STOP_RESP:
130                 {
131                     nr5g_fapi_stop_indication((p_nr5g_fapi_phy_ctx_t) config,
132                         (PSTOPRESPONSEStruct) p_msg_header);
133                 }
134                 break;
135
136                 /*  P7 Message Processing */
137             case MSG_TYPE_PHY_RX_ULSCH_IND:
138                 {
139                     nr5g_fapi_rx_data_indication(is_urllc,
140                         (p_nr5g_fapi_phy_ctx_t) config,
141                         &vendor_extension_elems,
142                         (PRXULSCHIndicationStruct) p_msg_header);
143                 }
144                 break;
145
146             case MSG_TYPE_PHY_RX_ULSCH_UCI_IND:
147                 {
148                     nr5g_fapi_rx_data_uci_indication(is_urllc,
149                         (p_nr5g_fapi_phy_ctx_t) config,
150                         (PRXULSCHUCIIndicationStruct) p_msg_header);
151                 }
152                 break;
153
154             case MSG_TYPE_PHY_CRC_IND:
155                 {
156                     nr5g_fapi_crc_indication(is_urllc,
157                         (p_nr5g_fapi_phy_ctx_t) config,
158                         &vendor_extension_elems,
159                         (PCRCIndicationStruct) p_msg_header);
160                 }
161                 break;
162
163             case MSG_TYPE_PHY_UCI_IND:
164                 {
165                     nr5g_fapi_uci_indication(is_urllc,
166                         (p_nr5g_fapi_phy_ctx_t) config,
167                         &vendor_extension_elems,
168                         (PRXUCIIndicationStruct) p_msg_header);
169                 }
170                 break;
171
172             case MSG_TYPE_PHY_RX_RACH_IND:
173                 {
174                     nr5g_fapi_rach_indication(is_urllc,
175                         (p_nr5g_fapi_phy_ctx_t) config,
176                         (PRXRACHIndicationStruct) p_msg_header);
177                 }
178                 break;
179
180             case MSG_TYPE_PHY_RX_SRS_IND:
181                 {
182                     nr5g_fapi_srs_indication(is_urllc,
183                         (p_nr5g_fapi_phy_ctx_t) config,
184                         &vendor_extension_elems,
185                         (PRXSRSIndicationStruct) p_msg_header);
186                 }
187                 break;
188
189             case MSG_TYPE_PHY_SLOT_IND:
190                 {
191                     nr5g_fapi_slot_indication(is_urllc,
192                         (p_nr5g_fapi_phy_ctx_t) config,
193                         &vendor_extension_elems,
194                         (PSlotIndicationStruct) p_msg_header);
195                     nr5g_fapi_statistic_info_set_all();
196                 }
197                 break;
198
199             case MSG_TYPE_PHY_ERR_IND:
200                 {
201                 }
202                 break;
203
204             default:
205                 NR5G_FAPI_LOG(ERROR_LOG, ("[PHY2MAC THREAD] Received Unknown Message: [nMessageType = 0x%x]",
206                     p_msg_header->nMessageType));
207                 break;
208         }
209         p_curr_msg = p_curr_msg->pNext;
210     }
211     nr5g_fapi_proc_vendor_p7_msgs_move_to_api_list(is_urllc, &vendor_extension_elems);
212
213     tick_total_parse_per_tti_ul += __rdtsc() - start_tick;
214
215 }