1 /******************************************************************************
3 * Copyright (c) 2019 Intel.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 *******************************************************************************/
20 * @brief This file has all definitions for the Ethernet Data Interface Layer
22 * @ingroup group_lte_source_auxlib
23 * @author Intel Corporation
34 #include <rte_config.h>
36 #include <rte_timer.h>
39 #include "xran_fh_o_du.h"
41 #define XRAN_THREAD_DEFAULT_PRIO (98)
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 */
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}
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
63 enum xran_ethdi_vf_ports
70 struct xran_io_loop_cfg
73 char *dpdk_dev[ETHDI_VF_MAX];
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. */
84 /* CAUTION: Keep in sync with the string table below. */
93 static char *const entity_names[] = {
94 "xRAN lls-CU sim app",
98 typedef int (*PROCESS_CB)(void * arg);
100 struct xran_ethdi_ctx
102 struct xran_io_loop_cfg io_cfg;
103 struct ether_addr entities[ID_BROADCAST + 1];
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;
116 uint64_t busy_poll_till;
118 unsigned pkt_stats[PKT_LAST + 1];
129 extern enum xran_if_state xran_if_current_state;
130 extern uint8_t ping_dst_id;
131 extern struct ether_addr entities_addrs[];
133 static inline struct xran_ethdi_ctx *xran_ethdi_get_ctx(void)
135 extern struct xran_ethdi_ctx g_ethdi_ctx;
139 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
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);
146 int xran_register_ethertype_handler(uint16_t ethertype, ethertype_handler callback);
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);
156 void xran_ethdi_stop_tx(void);
157 void xran_ethdi_ports_stats(void);
158 int xran_ethdi_dpdk_io_loop(void *);
160 int xran_ethdi_filter_packet(struct rte_mbuf *pkt, uint64_t rx_time);
161 int32_t process_dpdk_io(void);
168 #endif /* #ifndef _ETHDI_H_ */