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