o-du/phy
Intel O-RAN/X-RAN Generated Doxygen Documentation
ethernet.h
Go to the documentation of this file.
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 
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 VLAN_SUPPORT
40 #define FLEXRAN_UP_VLAN_TAG 2
41 #define ETHER_TYPE_ETHDI ETHER_TYPE_IPv4 /* hack needed for jumbo frames */
42 #define ETHER_TYPE_ECPRI 0xAEFE
43 #define ETHER_TYPE_SYNC 0xBEFE
44 #define ETHER_TYPE_START_TX 0xCEFE
45 
46 #define NUM_MBUFS 65536
47 #define MBUF_CACHE 256
48 
49 #define MBUF_POOL_ELM_SMALL 1500 /* regular ethernet MTU, most compatible */
50 #define MBUF_POOL_ELEMENT MAX_RX_LEN
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 */
72 {
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;
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, struct ether_addr *p_lls_cu_addr);
123 
124 void xran_add_eth_hdr_vlan(struct ether_addr *dst, uint16_t ethertype, struct rte_mbuf *mb, uint16_t vlan_tci);
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 */
void xran_add_eth_hdr_vlan(struct ether_addr *dst, uint16_t ethertype, struct rte_mbuf *mb, uint16_t vlan_tci)
Definition: ethernet.c:434
struct rte_mempool * _eth_mbuf_pool_big
Definition: ethernet.c:74
void xran_init_port(int port, struct ether_addr *p_lls_cu_addr)
Definition: ethernet.c:229
int8_t original_type
Definition: ethernet.h:108
pkt_type
Definition: ethernet.h:71
int __xran_delayed_msg(const char *fmt,...)
Definition: ethernet.c:97
int8_t total_pkts
Definition: ethernet.h:107
int8_t data[]
Definition: ethernet.h:109
struct rte_mempool * _eth_mbuf_pool_small
Definition: ethernet.c:73
int8_t pkt_idx
Definition: ethernet.h:106
struct rte_mempool * socket_indirect_pool
Definition: ethernet.c:77
uint16_t ethertype
Definition: ethdi.c:114
#define wlog(m,...)
Definition: ethernet.h:140
uint8_t dest_id
Definition: ethernet.h:115
uint8_t pkt_type
Definition: ethernet.h:113
uint8_t source_id
Definition: ethernet.h:114
void xran_init_mbuf_pool(void)
Definition: ethernet.c:185
struct rte_mempool * _eth_mbuf_pool
Definition: ethernet.c:70
struct rte_mempool * socket_direct_pool
Definition: ethernet.c:76