* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fhi_lib / lib / ethernet / ethdi.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 This file has all definitions for the Ethernet Data Interface Layer
21  * @file ethdi.h
22  * @ingroup group_lte_source_auxlib
23  * @author Intel Corporation
24  **/
25
26
27 #ifndef _ETHDI_H_
28 #define _ETHDI_H_
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <unistd.h>
35
36 #include <rte_config.h>
37 #include <rte_mbuf.h>
38 #include <rte_flow.h>
39 #include <rte_timer.h>
40
41 /*  comment this to enable PDUMP
42  *  DPDK has to be compiled with
43  *      CONFIG_RTE_LIBRTE_PMD_PCAP=y
44  *      CONFIG_RTE_LIBRTE_PDUMP=y
45  */
46 #undef RTE_LIBRTE_PDUMP
47
48 #ifdef RTE_LIBRTE_PDUMP
49 #include <rte_pdump.h>
50 #endif
51
52 #include "ethernet.h"
53 #include "xran_transport.h"
54 #include "xran_fh_o_du.h"
55
56 #define XRAN_THREAD_DEFAULT_PRIO (98)
57 #define XRAN_MAX_WORKERS 6 /**< max number of worker cores */
58
59 #define TX_TIMER_INTERVAL ((rte_get_timer_hz() / 1000000000L)*interval_us*1000) /* nanosec */
60 #define TX_RX_LOOP_TIME (rte_get_timer_hz() / 1)
61
62 typedef uint8_t  lcoreid_t;
63 typedef uint16_t portid_t;
64 typedef uint16_t queueid_t;
65 typedef uint16_t streamid_t;
66
67 /* CAUTION: Keep in sync with the string table below. */
68 enum xran_entities_id
69 {
70     ID_O_DU,
71     ID_O_RU,
72     ID_MAX
73 };
74
75 static char *const entity_names[] = {
76     (char *)"ORAN O-DU sim app",
77     (char *)"ORAN O-RU sim app"
78 };
79
80 typedef int (*PROCESS_CB)(void * arg);
81
82 extern queueid_t nb_rxq; /**< Number of RX queues per port. */
83 extern queueid_t nb_txq; /**< Number of TX queues per port. */
84
85 /**
86  * Structure storing internal configuration of workers
87  */
88 struct xran_worker_config {
89     lcore_function_t *f;
90     void *arg;
91     int32_t state;
92 };
93
94 struct xran_ethdi_ctx {
95     struct xran_io_cfg io_cfg;
96     struct rte_ether_addr entities[XRAN_VF_MAX][ID_MAX];
97     uint16_t vf2xran_port[XRAN_VF_MAX];
98     uint16_t vf_and_q2pc_id[XRAN_VF_MAX][XRAN_VF_QUEUE_MAX];
99     struct xran_eaxc_info vf_and_q2cid[XRAN_VF_MAX][XRAN_VF_QUEUE_MAX];
100     uint16_t rxq_per_port[XRAN_VF_MAX];
101
102     struct rte_ring *tx_ring[XRAN_VF_MAX];
103     struct rte_ring *rx_ring[XRAN_VF_MAX][XRAN_VF_QUEUE_MAX];
104
105     struct rte_ring *up_dl_pkt_gen_ring[XRAN_PORTS_NUM];
106
107     struct xran_worker_config time_wrk_cfg; /**< core doing polling of time */
108     struct xran_worker_config pkt_wrk_cfg[RTE_MAX_LCORE]; /**< worker cores */
109
110     phy_encoder_poll_fn bbdev_enc; /**< call back to poll BBDev encoder */
111     phy_decoder_poll_fn bbdev_dec; /**< call back to poll BBDev decoder */
112
113     uint32_t pkt_proc_core_id; /**< core used for processing DPDK timer cb */
114     uint32_t num_workers; /**< number of workers */
115     uint32_t worker_core[XRAN_MAX_WORKERS]; /**< id of core used as worker */
116
117     uint64_t rx_vf_queue_cnt[XRAN_VF_MAX][XRAN_VF_QUEUE_MAX];
118 };
119
120 enum xran_mbuf_mem_op_id {
121     MBUF_KEEP,
122     MBUF_FREE
123 };
124
125 extern enum xran_if_state xran_if_current_state;
126
127 static inline struct xran_ethdi_ctx *xran_ethdi_get_ctx(void)
128 {
129     extern struct xran_ethdi_ctx g_ethdi_ctx;
130     return &g_ethdi_ctx;
131 }
132 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint16_t vf_id);
133
134 typedef int (*ethertype_handler)(struct rte_mbuf* pkt_q[], uint16_t xport_id,  struct xran_eaxc_info *p_cid, uint16_t num);
135
136
137 int32_t xran_register_ethertype_handler(uint16_t ethertype, ethertype_handler callback);
138 int32_t xran_ethdi_init_dpdk_io(char *name, const struct xran_io_cfg *io_cfg,
139                                 int32_t *lcore_id, struct rte_ether_addr *p_o_du_addr,
140                                 struct rte_ether_addr *p_ru_addr, uint32_t mtu);
141
142 struct rte_mbuf *xran_ethdi_mbuf_alloc(void);
143 struct rte_mbuf *xran_ethdi_mbuf_indir_alloc(void);
144 int32_t xran_ethdi_mbuf_send(struct rte_mbuf *mb, uint16_t ethertype, uint16_t vf_id);
145 int32_t xran_ethdi_mbuf_send_cp(struct rte_mbuf *mb, uint16_t ethertype, uint16_t vf_id);
146 int32_t xran_ethdi_filter_packet(struct rte_mbuf *pkt[], uint16_t vf_id, uint16_t q_id, uint16_t num);
147 int32_t process_dpdk_io(void* args);
148 int32_t process_dpdk_io_tx(void* args);
149 int32_t process_dpdk_io_rx(void* args);
150
151 struct rte_flow * generate_ecpri_flow(uint16_t port_id, uint16_t rx_q, uint16_t pc_id_be, struct rte_flow_error *error);
152
153
154 #ifdef __cplusplus
155 }
156 #endif
157
158 #endif /* #ifndef _ETHDI_H_ */