Update to odulow per maintenance bronze
[o-du/phy.git] / fhi_lib / lib / ethernet / ethernet.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 ethernet.h
22  * @ingroup group_lte_source_auxlib
23  * @author Intel Corporation
24  **/
25
26 #ifndef AUXLIB_ETHERNET_H
27 #define AUXLIB_ETHERNET_H
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #include <rte_config.h>
34 #include <rte_ether.h>
35 #include <rte_mbuf.h>
36
37 #define BURST_SIZE 4096
38
39 #define ETHER_TYPE_ETHDI RTE_ETHER_TYPE_IPV4    /* hack needed for jumbo frames */
40 #define ETHER_TYPE_ECPRI 0xAEFE
41 #define ETHER_TYPE_SYNC 0xBEFE
42 #define ETHER_TYPE_START_TX 0xCEFE
43
44 #define NUM_MBUFS 65535/*16383*/ /*65535*/ /** optimal is n = (2^q - 1) */
45 #define NUM_MBUFS_RING NUM_MBUFS+1 /** The size of the ring (must be a power of 2) */
46
47 #define MBUF_CACHE 256
48
49 #define MBUF_POOL_ELM_SMALL (1500 + RTE_PKTMBUF_HEADROOM )/* regular ethernet MTU, most compatible */
50 #define MBUF_POOL_ELEMENT (MAX_RX_LEN + RTE_PKTMBUF_HEADROOM)
51
52 #define MAX_RX_LEN 9600
53 #define MAX_TX_LEN (MAX_RX_LEN - 14) /* headroom for rx driver */
54 #define MAX_DATA_SIZE (MAX_TX_LEN - sizeof(struct ether_hdr) - \
55     sizeof(struct ethdi_hdr) - sizeof(struct burst_hdr))
56
57 /* Looks like mbuf size is limited to 16 bits - see the buf_len field. */
58 #define MBUF_POOL_ELM_BIG USHRT_MAX
59 #define NUM_MBUFS_BIG 64
60
61 #define DEFAULT_DUMP_LENGTH 96
62
63 extern struct rte_mempool *_eth_mbuf_pool;
64 extern struct rte_mempool *_eth_mbuf_pool_small;
65 extern struct rte_mempool *_eth_mbuf_pool_big;
66 extern struct rte_mempool *socket_direct_pool;
67 extern struct rte_mempool *socket_indirect_pool;
68
69 /* Do NOT change the order of this enum and below
70  * - need to be in sync with the table of handlers in testue.c */
71 enum pkt_type
72 {
73     PKT_ZERO,
74     PKT_EMPTY,
75     PKT_DISCOVER_REQUEST,
76     PKT_PING,
77     PKT_PONG,
78     PKT_DISCOVER_REPLY,
79     PKT_LTE_DATA,
80     PKT_LTE_CONTROL,
81     PKT_BURST,
82     PKT_DATATEST,
83     PKT_ADD_ETHDEV,
84     PKT_SYNC_START,
85     PKT_LAST,
86 };
87
88 /* Do NOT change the order. */
89 static char * const xran_pkt_descriptions[PKT_LAST + 1] = {
90     "ZERO",
91     "empty packet",
92     "discovery request packet",
93     "ping packet",
94     "pong packet",
95     "discovery reply packet",
96     "LTE data packet",
97     "LTE control packet",
98     "BURST packet",
99     "DATATEST packet",
100     "Add ethernet port command packet",
101     "SYNC-START packet",
102     "LAST packet",
103 };
104
105 struct burst_hdr {
106     int8_t pkt_idx;
107     int8_t total_pkts;
108     int8_t original_type;
109     int8_t data[];
110 };
111
112 struct ethdi_hdr {
113     uint8_t pkt_type;
114     uint8_t source_id;
115     uint8_t dest_id;
116     int8_t data[];    /* original raw data starts here! */
117 };
118
119
120 void xran_init_mbuf_pool(void);
121
122 void xran_init_port(int port);
123
124 void xran_add_eth_hdr_vlan(struct rte_ether_addr *dst, uint16_t ethertype, struct rte_mbuf *mb);
125
126 #if 0
127 void xran_memdump(void *addr, int len);
128 void xran_add_eth_hdr(struct ether_addr *dst, uint16_t ethertype, struct rte_mbuf *);
129 int xran_send_mbuf(struct ether_addr *dst, struct rte_mbuf *mb);
130 int xran_send_message_burst(int dst_id, int pkt_type, void *body, int len);
131 int xran_show_delayed_message(void);
132 #endif
133 /*
134  * Print a message after all critical processing done.
135  * Mt-safe. 4 variants - normal, warning, error and debug log.
136  */
137 int __xran_delayed_msg(const char *fmt, ...);
138 #define nlog(m, ...) __xran_delayed_msg("%s(): " m "\n", __FUNCTION__, ##__VA_ARGS__)
139 #define delayed_message nlog    /* this is the old alias for this function */
140 #define wlog(m, ...) nlog("WARNING: " m, ##__VA_ARGS__)
141 #define elog(m, ...) nlog("ERROR: " m, ##__VA_ARGS__)
142 #ifdef DEBUG
143 # define dlog(m, ...) nlog("DEBUG: " m, ##__VA_ARGS__)
144 #else
145 # define dlog(m, ...)
146 #endif
147
148 #define PANIC_ON(x, m, ...) do { if (unlikely(x)) \
149     rte_panic("%s: " m "\n", #x, ##__VA_ARGS__); } while (0)
150
151 /* Add mbuf to the TX ring. */
152 static inline int xran_enqueue_mbuf(struct rte_mbuf *mb, struct rte_ring *r)
153 {
154     if (rte_ring_enqueue(r, mb) == 0) {
155         return 1;   /* success */
156     }
157
158     rte_pktmbuf_free(mb);
159     wlog("failed to enqueue packet on port %d (ring full)", mb->port);
160
161     return 0;   /* fail */
162 }
163
164 #ifdef __cplusplus
165 }
166 #endif
167
168 #endif /* AUXLIB_ETHERNET_H */