114dce466358e116415437b5a80ae14f7627c4eb
[o-du/phy.git] / fhi_lib / lib / ethernet / ethdi.h
1 /******************************************************************************\r
2 *\r
3 *   Copyright (c) 2019 Intel.\r
4 *\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
8 *\r
9 *       http://www.apache.org/licenses/LICENSE-2.0\r
10 *\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
16 *\r
17 *******************************************************************************/\r
18 \r
19 /**\r
20  * @brief This file has all definitions for the Ethernet Data Interface Layer\r
21  * @file ethdi.h\r
22  * @ingroup group_lte_source_auxlib\r
23  * @author Intel Corporation\r
24  **/\r
25 \r
26 \r
27 #ifndef _ETHDI_H_\r
28 #define _ETHDI_H_\r
29 \r
30 #ifdef __cplusplus\r
31 extern "C" {\r
32 #endif\r
33 \r
34 #include <rte_config.h>\r
35 #include <rte_mbuf.h>\r
36 #include <rte_timer.h>\r
37 \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
42  */\r
43 #undef RTE_LIBRTE_PDUMP\r
44 \r
45 #ifdef RTE_LIBRTE_PDUMP\r
46 #include <rte_pdump.h>\r
47 #endif\r
48 \r
49 #include "ethernet.h"\r
50 #include "xran_fh_o_du.h"\r
51 \r
52 #define XRAN_THREAD_DEFAULT_PRIO (98)\r
53 \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
57 \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
63 \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
66 \r
67 enum xran_ping_states\r
68 {\r
69     PING_IDLE,\r
70     PING_NEEDED,\r
71     AWAITING_PONG\r
72 };\r
73 \r
74 enum xran_ethdi_vf_ports\r
75 {\r
76     ETHDI_UP_VF = 0,\r
77     ETHDI_CP_VF,\r
78     ETHDI_VF_MAX\r
79 };\r
80 \r
81 struct xran_io_loop_cfg\r
82 {\r
83     uint8_t id;\r
84     char *dpdk_dev[ETHDI_VF_MAX];\r
85     char *bbdev_dev[1];\r
86     int bbdev_mode;\r
87     int core;\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
93 };\r
94 \r
95 /* CAUTION: Keep in sync with the string table below. */\r
96 enum xran_entities_id\r
97 {\r
98     ID_LLS_CU,\r
99     ID_RU,\r
100     ID_BROADCAST,\r
101     ID_MAX\r
102 };\r
103 \r
104 static char *const entity_names[] = {\r
105     "xRAN lls-CU sim app",\r
106     "xRAN RU sim app",\r
107 };\r
108 \r
109 typedef int (*PROCESS_CB)(void * arg);\r
110 \r
111 struct xran_ethdi_ctx\r
112 {\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
116     int ping_times;\r
117     int known_peers;\r
118 \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
126 \r
127     uint64_t busy_poll_till;\r
128 \r
129     unsigned pkt_stats[PKT_LAST + 1];\r
130 \r
131     uint16_t cp_vtag;\r
132     uint16_t up_vtag;\r
133 };\r
134 \r
135 enum {\r
136     MBUF_KEEP,\r
137     MBUF_FREE\r
138 };\r
139 \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
143 \r
144 static inline struct xran_ethdi_ctx *xran_ethdi_get_ctx(void)\r
145 {\r
146     extern struct xran_ethdi_ctx g_ethdi_ctx;\r
147 \r
148     return &g_ethdi_ctx;\r
149 }\r
150 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);\r
151 \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
155 \r
156 \r
157 int xran_register_ethertype_handler(uint16_t ethertype, ethertype_handler callback);\r
158 \r
159 \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
166 #if 0\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
170 #endif\r
171 int xran_ethdi_filter_packet(struct rte_mbuf *pkt, uint64_t rx_time);\r
172 int32_t process_dpdk_io(void);\r
173 \r
174 \r
175 #ifdef __cplusplus\r
176 }\r
177 #endif\r
178 \r
179 #endif /* #ifndef _ETHDI_H_ */\r