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