1 /******************************************************************************
\r
3 * Copyright (c) 2019 Intel.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
17 *******************************************************************************/
\r
20 * @brief This file has all definitions for the Ethernet Data Interface Layer
\r
22 * @ingroup group_lte_source_auxlib
\r
23 * @author Intel Corporation
\r
34 #include <rte_config.h>
\r
35 #include <rte_mbuf.h>
\r
36 #include <rte_timer.h>
\r
38 /* comment this to enable PDUMP
\r
39 * DPDK has to be compiled with
\r
40 * CONFIG_RTE_LIBRTE_PMD_PCAP=y
\r
41 * CONFIG_RTE_LIBRTE_PDUMP=y
\r
43 #undef RTE_LIBRTE_PDUMP
\r
45 #ifdef RTE_LIBRTE_PDUMP
\r
46 #include <rte_pdump.h>
\r
49 #include "ethernet.h"
\r
50 #include "xran_fh_o_du.h"
\r
52 #define XRAN_THREAD_DEFAULT_PRIO (98)
\r
54 /* How often to ping? */
\r
55 #define PING_INTERVAL 300 /* (us) */
\r
56 #define PING_BUSY_POLL 50 /* (us) how long to actively wait for response */
\r
58 /* If we're not receiving packets for more then this threshold... */
\r
59 //#define SLEEP_THRESHOLD (rte_get_tsc_hz() / 30) /* = 33.3(3)ms */
\r
60 /* we go to sleep for this long (usleep). Undef SLEEP_TRESHOLD to disable. */
\r
61 #define SLEEP_TIME 200 /* (us) */
\r
62 #define BCAST {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
\r
64 #define TX_TIMER_INTERVAL ((rte_get_timer_hz() / 1000000000L)*interval_us*1000) /* nanosec */
\r
65 #define TX_RX_LOOP_TIME rte_get_timer_hz() / 1
\r
67 enum xran_ping_states
\r
74 enum xran_ethdi_vf_ports
\r
81 struct xran_io_loop_cfg
\r
84 char *dpdk_dev[ETHDI_VF_MAX];
\r
88 int system_core; /* Needed as DPDK will change your starting core. */
\r
89 int pkt_proc_core; /* Needed for packet processing thread. */
\r
90 int pkt_aux_core; /* Needed for packet dumping for debug purposes. */
\r
91 int timing_core; /* Needed for getting precise time */
\r
92 int port[ETHDI_VF_MAX]; /* This is auto-detected, no need to set. */
\r
95 /* CAUTION: Keep in sync with the string table below. */
\r
96 enum xran_entities_id
\r
104 static char *const entity_names[] = {
\r
105 "xRAN lls-CU sim app",
\r
109 typedef int (*PROCESS_CB)(void * arg);
\r
111 struct xran_ethdi_ctx
\r
113 struct xran_io_loop_cfg io_cfg;
\r
114 struct ether_addr entities[ID_BROADCAST + 1];
\r
115 uint8_t ping_state;
\r
119 struct rte_ring *tx_ring[ETHDI_VF_MAX];
\r
120 struct rte_ring *rx_ring[ETHDI_VF_MAX];
\r
121 struct rte_ring *pkt_dump_ring[ETHDI_VF_MAX];
\r
122 struct rte_timer timer_autodetect;
\r
123 struct rte_timer timer_ping;
\r
124 struct rte_timer timer_sync;
\r
125 struct rte_timer timer_tx;
\r
127 uint64_t busy_poll_till;
\r
129 unsigned pkt_stats[PKT_LAST + 1];
\r
140 extern enum xran_if_state xran_if_current_state;
\r
141 extern uint8_t ping_dst_id;
\r
142 extern struct ether_addr entities_addrs[];
\r
144 static inline struct xran_ethdi_ctx *xran_ethdi_get_ctx(void)
\r
146 extern struct xran_ethdi_ctx g_ethdi_ctx;
\r
148 return &g_ethdi_ctx;
\r
150 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
\r
152 typedef int (*ethertype_handler)(struct rte_mbuf *, uint64_t rx_time);
\r
153 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
\r
154 typedef void (xran_ethdi_tx_callback)(struct rte_timer *tim, void *arg);
\r
157 int xran_register_ethertype_handler(uint16_t ethertype, ethertype_handler callback);
\r
160 int xran_ethdi_init_dpdk_io(char *name, const struct xran_io_loop_cfg *io_cfg,
\r
161 int *lcore_id, struct ether_addr *p_lls_cu_addr, struct ether_addr *p_ru_addr,
\r
162 uint16_t cp_vlan, uint16_t up_vlan);
\r
163 struct rte_mbuf *xran_ethdi_mbuf_alloc(void);
\r
164 int xran_ethdi_mbuf_send(struct rte_mbuf *mb, uint16_t ethertype);
\r
165 int xran_ethdi_mbuf_send_cp(struct rte_mbuf *mb, uint16_t ethertype);
\r
167 void xran_ethdi_stop_tx(void);
\r
168 void xran_ethdi_ports_stats(void);
\r
169 int xran_ethdi_dpdk_io_loop(void *);
\r
171 int xran_ethdi_filter_packet(struct rte_mbuf *pkt, uint64_t rx_time);
\r
172 int32_t process_dpdk_io(void);
\r
179 #endif /* #ifndef _ETHDI_H_ */
\r