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