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>
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
43 #undef RTE_LIBRTE_PDUMP
45 #ifdef RTE_LIBRTE_PDUMP
46 #include <rte_pdump.h>
50 #include "xran_fh_o_du.h"
52 #define XRAN_THREAD_DEFAULT_PRIO (98)
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 */
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}
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
74 enum xran_ethdi_vf_ports
81 struct xran_io_loop_cfg
84 char *dpdk_dev[ETHDI_VF_MAX];
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. */
95 /* CAUTION: Keep in sync with the string table below. */
104 static char *const entity_names[] = {
105 "xRAN lls-CU sim app",
109 typedef int (*PROCESS_CB)(void * arg);
111 struct xran_ethdi_ctx
113 struct xran_io_loop_cfg io_cfg;
114 struct ether_addr entities[ID_BROADCAST + 1];
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;
127 uint64_t busy_poll_till;
129 unsigned pkt_stats[PKT_LAST + 1];
140 extern enum xran_if_state xran_if_current_state;
141 extern uint8_t ping_dst_id;
142 extern struct ether_addr entities_addrs[];
144 static inline struct xran_ethdi_ctx *xran_ethdi_get_ctx(void)
146 extern struct xran_ethdi_ctx g_ethdi_ctx;
150 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
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);
157 int xran_register_ethertype_handler(uint16_t ethertype, ethertype_handler callback);
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);
167 void xran_ethdi_stop_tx(void);
168 void xran_ethdi_ports_stats(void);
169 int xran_ethdi_dpdk_io_loop(void *);
171 int xran_ethdi_filter_packet(struct rte_mbuf *pkt, uint64_t rx_time);
172 int32_t process_dpdk_io(void);
179 #endif /* #ifndef _ETHDI_H_ */