Front Haul Interface Library update to third seed code contribution
[o-du/phy.git] / fhi_lib / lib / ethernet / ethdi.h
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
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 <rte_config.h>
35 #include <rte_mbuf.h>
36 #include <rte_timer.h>
37
38 /*  comment this to enable PDUMP
39  *  DPDK has to be compiled with
40  *      CONFIG_RTE_LIBRTE_PMD_PCAP=y
41  *      CONFIG_RTE_LIBRTE_PDUMP=y
42  */
43 #undef RTE_LIBRTE_PDUMP
44
45 #ifdef RTE_LIBRTE_PDUMP
46 #include <rte_pdump.h>
47 #endif
48
49 #include "ethernet.h"
50 #include "xran_fh_o_du.h"
51
52 #define XRAN_THREAD_DEFAULT_PRIO (98)
53
54 /* How often to ping? */
55 #define PING_INTERVAL 300   /* (us) */
56 #define PING_BUSY_POLL 50   /* (us) how long to actively wait for response */
57
58 /* If we're not receiving packets for more then this threshold... */
59 //#define SLEEP_THRESHOLD (rte_get_tsc_hz() / 30)    /* = 33.3(3)ms */
60 /* we go to sleep for this long (usleep). Undef SLEEP_TRESHOLD to disable. */
61 #define SLEEP_TIME 200      /* (us) */
62 #define BCAST {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
63
64 #define TX_TIMER_INTERVAL ((rte_get_timer_hz() / 1000000000L)*interval_us*1000) /* nanosec */
65 #define TX_RX_LOOP_TIME rte_get_timer_hz() / 1
66
67 enum xran_ping_states
68 {
69     PING_IDLE,
70     PING_NEEDED,
71     AWAITING_PONG
72 };
73
74 enum xran_ethdi_vf_ports
75 {
76     ETHDI_UP_VF = 0,
77     ETHDI_CP_VF,
78     ETHDI_VF_MAX
79 };
80
81 struct xran_io_loop_cfg
82 {
83     uint8_t id;
84     char *dpdk_dev[ETHDI_VF_MAX];
85     char *bbdev_dev[1];
86     int bbdev_mode;
87     int core;
88     int system_core;    /* Needed as DPDK will change your starting core. */
89     int pkt_proc_core;  /* Needed for packet processing thread. */
90     int pkt_aux_core;   /* Needed for packet dumping for debug purposes. */
91     int timing_core;    /* Needed for getting precise time */
92     int port[ETHDI_VF_MAX];           /* This is auto-detected, no need to set. */
93 };
94
95 /* CAUTION: Keep in sync with the string table below. */
96 enum xran_entities_id
97 {
98     ID_LLS_CU,
99     ID_RU,
100     ID_BROADCAST,
101     ID_MAX
102 };
103
104 static char *const entity_names[] = {
105     "xRAN lls-CU sim app",
106     "xRAN RU sim app",
107 };
108
109 typedef int (*PROCESS_CB)(void * arg);
110
111 struct xran_ethdi_ctx
112 {
113     struct xran_io_loop_cfg io_cfg;
114     struct ether_addr entities[ID_BROADCAST + 1];
115     uint8_t ping_state;
116     int ping_times;
117     int known_peers;
118
119     struct rte_ring *tx_ring[ETHDI_VF_MAX];
120     struct rte_ring *rx_ring[ETHDI_VF_MAX];
121     struct rte_ring *pkt_dump_ring[ETHDI_VF_MAX];
122     struct rte_timer timer_autodetect;
123     struct rte_timer timer_ping;
124     struct rte_timer timer_sync;
125     struct rte_timer timer_tx;
126
127     uint64_t busy_poll_till;
128
129     unsigned pkt_stats[PKT_LAST + 1];
130
131     uint16_t cp_vtag;
132     uint16_t up_vtag;
133 };
134
135 enum {
136     MBUF_KEEP,
137     MBUF_FREE
138 };
139
140 extern enum xran_if_state xran_if_current_state;
141 extern uint8_t ping_dst_id;
142 extern struct ether_addr entities_addrs[];
143
144 static inline struct xran_ethdi_ctx *xran_ethdi_get_ctx(void)
145 {
146     extern struct xran_ethdi_ctx g_ethdi_ctx;
147
148     return &g_ethdi_ctx;
149 }
150 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
151
152 typedef int (*ethertype_handler)(struct rte_mbuf *, uint64_t rx_time);
153 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
154 typedef void (xran_ethdi_tx_callback)(struct rte_timer *tim, void *arg);
155
156
157 int xran_register_ethertype_handler(uint16_t ethertype, ethertype_handler callback);
158
159
160 int xran_ethdi_init_dpdk_io(char *name, const struct xran_io_loop_cfg *io_cfg,
161     int *lcore_id, struct ether_addr *p_lls_cu_addr, struct ether_addr *p_ru_addr,
162     uint16_t cp_vlan, uint16_t up_vlan);
163 struct rte_mbuf *xran_ethdi_mbuf_alloc(void);
164 int xran_ethdi_mbuf_send(struct rte_mbuf *mb, uint16_t ethertype);
165 int xran_ethdi_mbuf_send_cp(struct rte_mbuf *mb, uint16_t ethertype);
166 #if 0
167 void xran_ethdi_stop_tx(void);
168 void xran_ethdi_ports_stats(void);
169 int xran_ethdi_dpdk_io_loop(void *);
170 #endif
171 int xran_ethdi_filter_packet(struct rte_mbuf *pkt, uint64_t rx_time);
172 int32_t process_dpdk_io(void);
173
174
175 #ifdef __cplusplus
176 }
177 #endif
178
179 #endif /* #ifndef _ETHDI_H_ */