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