Update to odulow per maintenance bronze
[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  * @brief This file has all definitions for the Ethernet Data Interface Layer
21  * @file ethdi.h
22  * @ingroup group_lte_source_auxlib
23  * @author Intel Corporation
24  **/
25
26
27 #ifndef _ETHDI_H_
28 #define _ETHDI_H_
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <rte_config.h>
35 #include <rte_mbuf.h>
36 #include <rte_timer.h>
37
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
42  */
43 #undef RTE_LIBRTE_PDUMP
44
45 #ifdef RTE_LIBRTE_PDUMP
46 #include <rte_pdump.h>
47 #endif
48
49 #include "ethernet.h"
50 #include "xran_fh_o_du.h"
51
52 #define XRAN_THREAD_DEFAULT_PRIO (98)
53
54 /* If we're not receiving packets for more then this threshold... */
55 //#define SLEEP_THRESHOLD (rte_get_tsc_hz() / 30)    /* = 33.3(3)ms */
56 /* we go to sleep for this long (usleep). Undef SLEEP_TRESHOLD to disable. */
57 #define SLEEP_TIME 200      /* (us) */
58 #define BCAST {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
59
60 #define TX_TIMER_INTERVAL ((rte_get_timer_hz() / 1000000000L)*interval_us*1000) /* nanosec */
61 #define TX_RX_LOOP_TIME rte_get_timer_hz() / 1
62
63 /* CAUTION: Keep in sync with the string table below. */
64 enum xran_entities_id
65 {
66     ID_O_DU,
67     ID_O_RU,
68     ID_BROADCAST,
69     ID_MAX
70 };
71
72 static char *const entity_names[] = {
73     "ORAN O-DU sim app",
74     "ORAN O-RU sim app",
75 };
76
77 typedef int (*PROCESS_CB)(void * arg);
78
79 /**
80  * Structure storing internal configuration of workers
81  */
82 struct xran_worker_config {
83     lcore_function_t *f;
84     void *arg;
85     int32_t state;
86 };
87
88 struct xran_ethdi_ctx
89 {
90     struct xran_io_cfg io_cfg;
91     struct rte_ether_addr entities[XRAN_VF_MAX][ID_BROADCAST + 1];
92
93     struct rte_ring *tx_ring[XRAN_VF_MAX];
94     struct rte_ring *rx_ring[XRAN_VF_MAX];
95     struct rte_ring *pkt_dump_ring[XRAN_VF_MAX];
96     struct rte_timer timer_autodetect;
97     struct rte_timer timer_ping;
98     struct rte_timer timer_sync;
99     struct rte_timer timer_tx;
100
101     struct xran_worker_config pkt_wrk_cfg[RTE_MAX_LCORE];
102
103     unsigned pkt_stats[PKT_LAST + 1];
104 };
105
106 enum {
107     MBUF_KEEP,
108     MBUF_FREE
109 };
110
111 extern enum xran_if_state xran_if_current_state;
112
113 static inline struct xran_ethdi_ctx *xran_ethdi_get_ctx(void)
114 {
115     extern struct xran_ethdi_ctx g_ethdi_ctx;
116
117     return &g_ethdi_ctx;
118 }
119 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
120
121 typedef int (*ethertype_handler)(struct rte_mbuf *, uint64_t rx_time);
122 typedef int (*xran_ethdi_handler)(struct rte_mbuf *, int sender, uint64_t rx_time);
123
124 int xran_register_ethertype_handler(uint16_t ethertype, ethertype_handler callback);
125
126 int32_t xran_ethdi_init_dpdk_io(char *name, const struct xran_io_cfg *io_cfg,
127     int *lcore_id, struct rte_ether_addr *p_o_du_addr,
128     struct rte_ether_addr *p_ru_addr);
129
130 struct rte_mbuf *xran_ethdi_mbuf_alloc(void);
131 int32_t xran_ethdi_mbuf_send(struct rte_mbuf *mb, uint16_t ethertype, uint16_t vf_id);
132 int32_t xran_ethdi_mbuf_send_cp(struct rte_mbuf *mb, uint16_t ethertype, uint16_t vf_id);
133 int32_t xran_ethdi_filter_packet(struct rte_mbuf *pkt, uint64_t rx_time);
134 int32_t process_dpdk_io(void);
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif /* #ifndef _ETHDI_H_ */