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