Front Haul Interface Library first 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 /**
21  * @brief This file has all definitions for the Ethernet Data Interface Layer
22  * @file ethdi.h
23  * @ingroup group_lte_source_auxlib
24  * @author Intel Corporation
25  **/
26
27
28 #ifndef _ETHDI_H_
29 #define _ETHDI_H_
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #include <rte_config.h>
36 #include <rte_mbuf.h>
37 #include <rte_timer.h>
38
39 #include "ethernet.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 extern enum xran_if_state xran_if_current_state;
57
58 enum xran_if_state
59 {
60     XRAN_RUNNING,
61     XRAN_STOPPED
62 };
63
64 enum xran_ping_states
65 {
66     PING_IDLE,
67     PING_NEEDED,
68     AWAITING_PONG
69 };
70
71 enum xran_ethdi_vf_ports
72 {
73     ETHDI_UP_VF = 0,
74     ETHDI_CP_VF,
75     ETHDI_VF_MAX
76 };
77
78 struct xran_io_loop_cfg
79 {
80     uint8_t id;
81     char *dpdk_dev[ETHDI_VF_MAX];
82     int core;
83     int system_core;    /* Needed as DPDK will change your starting core. */
84     int pkt_proc_core;  /* Needed for packet processing thread. */
85     int pkt_aux_core;   /* Needed for packet dumping for debug purposes. */
86     int timing_core;    /* Needed for getting precise time */
87     int port[ETHDI_VF_MAX];           /* This is auto-detected, no need to set. */
88 };
89
90 /* CAUTION: Keep in sync with the string table below. */
91 enum xran_entities_id
92 {
93     ID_LLS_CU,
94     ID_RU,
95     ID_BROADCAST,
96     ID_MAX
97 };
98
99 static char *const entity_names[] = {
100     "xRAN lls-CU sim app",
101     "xRAN RU sim app",
102 };
103
104 typedef int (*PROCESS_CB)(void * arg);
105
106 struct xran_ethdi_ctx
107 {
108     struct xran_io_loop_cfg io_cfg;
109     struct ether_addr entities[ID_BROADCAST + 1];
110     uint8_t ping_state;
111     int ping_times;
112     int known_peers;
113
114     struct rte_ring *tx_ring[ETHDI_VF_MAX];
115     struct rte_ring *rx_ring[ETHDI_VF_MAX];
116     struct rte_ring *pkt_dump_ring[ETHDI_VF_MAX];
117     struct rte_timer timer_autodetect;
118     struct rte_timer timer_ping;
119     struct rte_timer timer_sync;
120     struct rte_timer timer_tx;
121
122     uint64_t busy_poll_till;
123
124     unsigned pkt_stats[PKT_LAST + 1];
125
126     uint16_t cp_vtag;
127     uint16_t up_vtag;
128 };
129
130 enum {
131     MBUF_KEEP,
132     MBUF_FREE
133 };
134
135 extern uint8_t ping_dst_id;
136 extern struct ether_addr entities_addrs[];
137
138 static inline struct xran_ethdi_ctx *xran_ethdi_get_ctx(void)
139 {
140     extern struct xran_ethdi_ctx g_ethdi_ctx;
141
142     return &g_ethdi_ctx;
143 }
144 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
145
146 typedef int (*ethertype_handler)(struct rte_mbuf *, uint64_t rx_time);
147 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
148 typedef void (xran_ethdi_tx_callback)(struct rte_timer *tim, void *arg);
149
150
151 int xran_register_ethertype_handler(uint16_t ethertype, ethertype_handler callback);
152
153
154 int xran_ethdi_init_dpdk_io(char *name, const struct xran_io_loop_cfg *io_cfg,
155     int *lcore_id, struct ether_addr *p_lls_cu_addr, struct ether_addr *p_ru_addr,
156     uint16_t cp_vlan, uint16_t up_vlan);
157 int xran_ethdi_dpdk_io_loop(void *);
158 struct rte_mbuf *xran_ethdi_mbuf_alloc(void);
159 int xran_ethdi_mbuf_send(struct rte_mbuf *mb, uint16_t ethertype);
160 int xran_ethdi_mbuf_send_cp(struct rte_mbuf *mb, uint16_t ethertype);
161 void xran_ethdi_stop_tx(void);
162 int xran_ethdi_filter_packet(struct rte_mbuf *pkt, uint64_t rx_time);
163
164
165 #ifdef __cplusplus
166 }
167 #endif
168
169 #endif /* #ifndef _ETHDI_H_ */