1 /******************************************************************************
3 * Copyright (c) 2019 Intel.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 *******************************************************************************/
20 * @brief This file has all definitions for the Ethernet Data Interface Layer
22 * @ingroup group_lte_source_auxlib
23 * @author Intel Corporation
26 #ifndef AUXLIB_ETHERNET_H
27 #define AUXLIB_ETHERNET_H
33 #include <rte_config.h>
34 #include <rte_ether.h>
37 #define BURST_SIZE 4096
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
46 #define NUM_MBUFS 65536
47 #define MBUF_CACHE 256
49 #define MBUF_POOL_ELM_SMALL 1500 /* regular ethernet MTU, most compatible */
50 #define MBUF_POOL_ELEMENT MAX_RX_LEN
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))
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
61 #define DEFAULT_DUMP_LENGTH 96
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;
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 */
88 /* Do NOT change the order. */
89 static char * const xran_pkt_descriptions[PKT_LAST + 1] = {
92 "discovery request packet",
95 "discovery reply packet",
100 "Add ethernet port command packet",
108 int8_t original_type;
116 int8_t data[]; /* original raw data starts here! */
120 void xran_init_mbuf_pool(void);
122 void xran_init_port(int port, struct ether_addr *p_lls_cu_addr);
124 void xran_add_eth_hdr_vlan(struct ether_addr *dst, uint16_t ethertype, struct rte_mbuf *mb, uint16_t vlan_tci);
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);
134 * Print a message after all critical processing done.
135 * Mt-safe. 4 variants - normal, warning, error and debug log.
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__)
143 # define dlog(m, ...) nlog("DEBUG: " m, ##__VA_ARGS__)
145 # define dlog(m, ...)
148 #define PANIC_ON(x, m, ...) do { if (unlikely(x)) \
149 rte_panic("%s: " m "\n", #x, ##__VA_ARGS__); } while (0)
151 /* Add mbuf to the TX ring. */
152 static inline int xran_enqueue_mbuf(struct rte_mbuf *mb, struct rte_ring *r)
154 if (rte_ring_enqueue(r, mb) == 0) {
155 return 1; /* success */
158 rte_pktmbuf_free(mb);
159 wlog("failed to enqueue packet on port %d (ring full)", mb->port);
168 #endif /* AUXLIB_ETHERNET_H */