O-RAN E Maintenance Release contribution for ODULOW
[o-du/phy.git] / fhi_lib / lib / src / xran_cp_proc.h
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 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  * @brief XRAN C-plane processing module header file
21  * @file xran_cp_proc.h
22  * @ingroup group_source_xran
23  * @author Intel Corporation
24  **/
25
26 #ifndef _XRAN_CP_PROC_H_
27 #define _XRAN_CP_PROC_H_
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #include <stdio.h>
34 #include <unistd.h>
35
36 #include <rte_common.h>
37
38 #include "xran_fh_o_du.h"
39 #include "xran_printf.h"
40
41 extern uint8_t xran_cp_seq_id_num[XRAN_PORTS_NUM][XRAN_MAX_CELLS_PER_PORT][XRAN_DIR_MAX][XRAN_MAX_ANTENNA_NR * 2 + XRAN_MAX_ANT_ARRAY_ELM_NR];
42 extern uint8_t xran_updl_seq_id_num[XRAN_PORTS_NUM][XRAN_MAX_CELLS_PER_PORT][XRAN_MAX_ANTENNA_NR];
43 extern uint8_t xran_upul_seq_id_num[XRAN_PORTS_NUM][XRAN_MAX_CELLS_PER_PORT][XRAN_MAX_ANTENNA_NR * 2 + XRAN_MAX_ANT_ARRAY_ELM_NR];
44 extern uint8_t xran_section_id_curslot[XRAN_PORTS_NUM][XRAN_DIR_MAX][XRAN_MAX_CELLS_PER_PORT][XRAN_MAX_ANTENNA_NR * 2+ XRAN_MAX_ANT_ARRAY_ELM_NR];
45 extern uint16_t xran_section_id[XRAN_PORTS_NUM][XRAN_DIR_MAX][XRAN_MAX_CELLS_PER_PORT][XRAN_MAX_ANTENNA_NR * 2+ XRAN_MAX_ANT_ARRAY_ELM_NR];
46
47 int32_t xran_init_sectionid(void *pHandle);
48 int32_t xran_init_seqid(void *pHandle);
49
50 int32_t process_cplane(struct rte_mbuf *pkt, void* handle);
51 int32_t xran_cp_create_and_send_section(void *pHandle, uint8_t ru_port_id, int dir, int tti, int cc_id, struct xran_prb_map *prbMap,
52                                         enum xran_category category,  uint8_t ctx_id);
53 int32_t xran_ruemul_init(void *pHandle);
54 int32_t xran_ruemul_release(void *pHandle);
55
56 static __rte_always_inline uint16_t
57 xran_alloc_sectionid(void *pHandle, uint8_t dir, uint8_t cc_id, uint8_t ant_id, uint8_t slot_id)
58 {
59     int8_t xran_port = 0;
60     if((xran_port =  xran_dev_ctx_get_port_id(pHandle)) < 0 ){
61         print_err("Invalid pHandle - %p", pHandle);
62         return (0);
63     }
64
65     if(cc_id >= XRAN_MAX_CELLS_PER_PORT) {
66         print_err("Invalid CC ID - %d", cc_id);
67         return (0);
68     }
69     if(ant_id >= XRAN_MAX_ANTENNA_NR * 2 + XRAN_MAX_ANT_ARRAY_ELM_NR) {  //for PRACH, ant_id starts from num_ant
70         print_err("Invalid antenna ID - %d", ant_id);
71         return (0);
72     }
73
74     /* if new slot has been started,
75      * then initializes section id again for new start */
76     if(xran_section_id_curslot[xran_port][dir][cc_id][ant_id] != slot_id) {
77         xran_section_id[xran_port][dir][cc_id][ant_id] = 0;
78         xran_section_id_curslot[xran_port][dir][cc_id][ant_id] = slot_id;
79     }
80
81     return(xran_section_id[xran_port][dir][cc_id][ant_id]++);
82 }
83
84 static __rte_always_inline uint8_t
85 xran_get_upul_seqid(void *pHandle, uint8_t cc_id, uint8_t ant_id)
86 {
87     int8_t xran_port = 0;
88     if((xran_port =  xran_dev_ctx_get_port_id(pHandle)) < 0 ){
89         print_err("Invalid pHandle - %p", pHandle);
90         return (0);
91     }
92
93     if(xran_port >= XRAN_PORTS_NUM) {
94         print_err("Invalid port - %d", xran_port);
95         return (0);
96     }
97
98     if(cc_id >= XRAN_MAX_CELLS_PER_PORT) {
99         print_err("Invalid CC ID - %d", cc_id);
100         return (0);
101     }
102     if(ant_id >= XRAN_MAX_ANTENNA_NR * 2 + XRAN_MAX_ANT_ARRAY_ELM_NR) {
103         print_err("Invalid antenna ID - %d", ant_id);
104         return (0);
105     }
106
107     return(xran_upul_seq_id_num[xran_port][cc_id][ant_id]++);
108 }
109
110 static __rte_always_inline uint8_t*
111 xran_get_upul_seqid_addr(void *pHandle, uint8_t cc_id, uint8_t ant_id)
112 {
113     int8_t xran_port = 0;
114     if((xran_port =  xran_dev_ctx_get_port_id(pHandle)) < 0 ){
115         print_err("Invalid pHandle - %p", pHandle);
116         return (0);
117     }
118
119     if(xran_port >= XRAN_PORTS_NUM) {
120         print_err("Invalid port - %d", xran_port);
121         return (0);
122     }
123
124     if(cc_id >= XRAN_MAX_CELLS_PER_PORT) {
125         print_err("Invalid CC ID - %d", cc_id);
126         return (0);
127     }
128     if(ant_id >= XRAN_MAX_ANTENNA_NR * 2) {
129         print_err("Invalid antenna ID - %d", ant_id);
130         return (0);
131     }
132
133     return(&xran_upul_seq_id_num[xran_port][cc_id][ant_id]);
134 }
135
136 static __rte_always_inline int8_t
137 xran_check_cp_seqid(void *pHandle, uint8_t dir, uint8_t cc_id, uint8_t ant_id, uint8_t seq_id)
138 {
139     int8_t xran_port = 0;
140     if((xran_port =  xran_dev_ctx_get_port_id(pHandle)) < 0 ){
141         print_err("Invalid pHandle - %p", pHandle);
142         return (0);
143     }
144
145     if(xran_port >= XRAN_PORTS_NUM) {
146         print_err("Invalid port - %d", xran_port);
147         return (0);
148     }
149
150     if(dir >= XRAN_DIR_MAX) {
151         print_err("Invalid direction - %d", dir);
152         return (-1);
153         }
154     if(cc_id >= XRAN_MAX_CELLS_PER_PORT) {
155         print_err("Invalid CC ID - %d", cc_id);
156         return (-1);
157     }
158     if(ant_id >= XRAN_MAX_ANTENNA_NR * 2) {
159         print_err("Invalid antenna ID - %d", ant_id);
160         return (-1);
161     }
162
163     xran_cp_seq_id_num[xran_port][cc_id][dir][ant_id]++;
164     if(xran_cp_seq_id_num[xran_port][cc_id][dir][ant_id] == seq_id) { /* expected sequence */
165         return (0);
166     }
167     else {
168         xran_cp_seq_id_num[xran_port][cc_id][dir][ant_id] = seq_id;
169         return (-1);
170     }
171 }
172
173 static __rte_always_inline int8_t
174 xran_check_updl_seqid(void *pHandle, uint8_t cc_id, uint8_t ant_id, uint8_t slot_id, uint8_t seq_id)
175 {
176     int8_t xran_port = 0;
177     if((xran_port =  xran_dev_ctx_get_port_id(pHandle)) < 0 ){
178         print_err("Invalid pHandle - %p", pHandle);
179         return (0);
180     }
181
182     if(xran_port >= XRAN_PORTS_NUM) {
183         print_err("Invalid port - %d", xran_port);
184         return (0);
185     }
186
187     if(cc_id >= XRAN_MAX_CELLS_PER_PORT) {
188         print_err("Invalid CC ID - %d", cc_id);
189         return (-1);
190     }
191
192     if(ant_id >= XRAN_MAX_ANTENNA_NR) {
193         print_err("Invalid antenna ID - %d", ant_id);
194         return (-1);
195     }
196
197     /* O-RU needs to check the sequence ID of U-Plane DL from O-DU */
198     xran_updl_seq_id_num[xran_port][cc_id][ant_id]++;
199     if(xran_updl_seq_id_num[xran_port][cc_id][ant_id] == seq_id) {
200         /* expected sequence */
201         /*print_dbg("ant %u  cc_id %u : slot_id %u : seq_id %u : expected seq_id %u\n",
202             ant_id, cc_id, slot_id, seq_id, xran_updl_seq_id_num[cc_id][ant_id]);*/
203         return (0);
204     } else {
205        /*print_err("[%d] ant %u  cc_id %u : slot_id %u : seq_id %u : expected seq_id %u\n",
206             xran_port, ant_id, cc_id, slot_id, seq_id, xran_updl_seq_id_num[xran_port][cc_id][ant_id]);*/
207
208         xran_updl_seq_id_num[xran_port][cc_id][ant_id] = seq_id;
209
210         return (-1);
211     }
212 }
213
214 static __rte_always_inline int8_t
215 xran_check_upul_seqid(void *pHandle, uint8_t cc_id, uint8_t ant_id, uint8_t slot_id, uint8_t seq_id)
216 {
217     int8_t xran_port = 0;
218     if((xran_port =  xran_dev_ctx_get_port_id(pHandle)) < 0 ){
219         print_err("Invalid pHandle - %p", pHandle);
220         return (0);
221     }
222
223     if(xran_port >= XRAN_PORTS_NUM) {
224         print_err("Invalid port - %d", xran_port);
225         return (0);
226     }
227
228     if(cc_id >= XRAN_MAX_CELLS_PER_PORT) {
229         print_err("Invalid CC ID - %d", cc_id);
230         return (-1);
231     }
232
233     if(ant_id >= XRAN_MAX_ANTENNA_NR * 2 + XRAN_MAX_ANT_ARRAY_ELM_NR) {
234         print_err("Invalid antenna ID - %d", ant_id);
235         return (-1);
236     }
237
238     /* O-DU needs to check the sequence ID of U-Plane UL from O-RU */
239     xran_upul_seq_id_num[xran_port][cc_id][ant_id]++;
240     if(xran_upul_seq_id_num[xran_port][cc_id][ant_id] == seq_id) { /* expected sequence */
241         return (XRAN_STATUS_SUCCESS);
242     } else {
243         print_dbg("[%d]expected seqid %u received %u, slot %u, ant %u cc %u", xran_port,  xran_upul_seq_id_num[xran_port][cc_id][ant_id], seq_id, slot_id, ant_id, cc_id);
244         xran_upul_seq_id_num[xran_port][cc_id][ant_id] = seq_id; // for next
245         return (-1);
246     }
247 }
248
249 static __rte_always_inline uint8_t*
250 xran_get_updl_seqid_addr(void *pHandle, uint8_t cc_id, uint8_t ant_id)
251 {
252     int8_t xran_port = 0;
253     if((xran_port =  xran_dev_ctx_get_port_id(pHandle)) < 0 ){
254         print_err("Invalid pHandle - %p", pHandle);
255         return (0);
256     }
257
258     if(xran_port >= XRAN_PORTS_NUM) {
259         print_err("Invalid port - %d", xran_port);
260         return (0);
261     }
262
263     if(cc_id >= XRAN_MAX_CELLS_PER_PORT) {
264         print_err("Invalid CC ID - %d", cc_id);
265         return (NULL);
266     }
267     if(ant_id >= XRAN_MAX_ANTENNA_NR) {
268         print_err("Invalid antenna ID - %d", ant_id);
269         return (NULL);
270     }
271
272     /* Only U-Plane DL needs to get sequence ID in O-DU */
273     return(&xran_updl_seq_id_num[xran_port][cc_id][ant_id]);
274 }
275
276 static __rte_always_inline uint8_t
277 xran_get_cp_seqid(void *pHandle, uint8_t dir, uint8_t cc_id, uint8_t ant_id)
278 {
279     int8_t xran_port = 0;
280     if((xran_port =  xran_dev_ctx_get_port_id(pHandle)) < 0 ){
281         print_err("Invalid pHandle - %p", pHandle);
282         return (0);
283     }
284
285     if(xran_port >= XRAN_PORTS_NUM) {
286         print_err("Invalid port - %d", xran_port);
287         return (0);
288     }
289
290     if(dir >= XRAN_DIR_MAX) {
291         print_err("Invalid direction - %d", dir);
292         return (0);
293         }
294     if(cc_id >= XRAN_MAX_CELLS_PER_PORT) {
295         print_err("Invalid CC ID - %d", cc_id);
296         return (0);
297         }
298     if(ant_id >= XRAN_MAX_ANTENNA_NR * 2 + XRAN_MAX_ANT_ARRAY_ELM_NR) {
299         print_err("Invalid antenna ID - %d", ant_id);
300         return (0);
301         }
302
303     return(xran_cp_seq_id_num[xran_port][cc_id][dir][ant_id]++);
304 }
305
306 static __rte_always_inline uint8_t
307 xran_get_updl_seqid(void *pHandle, uint8_t cc_id, uint8_t ant_id)
308 {
309     int8_t xran_port = 0;
310     if((xran_port =  xran_dev_ctx_get_port_id(pHandle)) < 0 ){
311         print_err("Invalid pHandle - %p", pHandle);
312         return (0);
313     }
314
315     if(xran_port >= XRAN_PORTS_NUM) {
316         print_err("Invalid port - %d", xran_port);
317         return (0);
318     }
319     if(cc_id >= XRAN_MAX_CELLS_PER_PORT) {
320         print_err("Invalid CC ID - %d", cc_id);
321         return (0);
322         }
323     if(ant_id >= XRAN_MAX_ANTENNA_NR) {
324         print_err("Invalid antenna ID - %d", ant_id);
325         return (0);
326         }
327
328     /* Only U-Plane DL needs to get sequence ID in O-DU */
329     return(xran_updl_seq_id_num[xran_port][cc_id][ant_id]++);
330 }
331
332 #ifdef __cplusplus
333 }
334 #endif
335
336 #endif /*  _XRAN_CP_PROC_H_ */