O-RAN E Maintenance Release contribution for ODULOW
[o-du/phy.git] / fhi_lib / lib / ethernet / ethernet.h
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 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 _XRANLIB_ETHERNET_H_
27 #define _XRANLIB_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
38 #define BURST_SIZE 4096 /** IAVF_MAX_RING_DESC        4096  */
39
40 #define ETHER_TYPE_ETHDI RTE_ETHER_TYPE_IPV4    /* hack needed for jumbo frames */
41 #define ETHER_TYPE_ECPRI 0xAEFE
42
43 #define NUM_MBUFS 65535/*16383*/ /*65535*/ /** optimal is n = (2^q - 1) */
44 #define NUM_MBUFS_RING NUM_MBUFS+1 /** The size of the ring (must be a power of 2) */
45
46 #define NUM_MBUFS_VF 1048575
47
48 #define NUM_MBUFS_RING_TRX 2097152
49
50 #define MBUF_CACHE 256
51
52 #define MBUF_POOL_ELM_SMALL_INDIRECT (128 + RTE_PKTMBUF_HEADROOM ) /* indirect */
53
54 #define MBUF_POOL_ELM_SMALL (1500 + RTE_PKTMBUF_HEADROOM )/* regular ethernet MTU, most compatible */
55 #define MBUF_POOL_ELEMENT (MAX_RX_LEN + RTE_PKTMBUF_HEADROOM)
56
57 #define MBUF_POOL_PKT_GEN_ELM (256 + RTE_PKTMBUF_HEADROOM )
58
59 #define MAX_RX_LEN 9600
60 #define MAX_TX_LEN (MAX_RX_LEN - 14) /* headroom for rx driver */
61 #define MAX_DATA_SIZE (MAX_TX_LEN - sizeof(struct ether_hdr) - \
62     sizeof(struct ethdi_hdr) - sizeof(struct burst_hdr))
63
64 extern struct rte_mempool *_eth_mbuf_pool;
65
66 extern struct rte_mempool *_eth_mbuf_pkt_gen;
67 extern struct rte_mempool *_eth_mbuf_pool_big;
68 extern struct rte_mempool *socket_direct_pool;
69 extern struct rte_mempool *socket_indirect_pool;
70
71 extern struct rte_mempool *_eth_mbuf_pool_vf_rx[16][RTE_MAX_QUEUES_PER_PORT];
72 extern struct rte_mempool *_eth_mbuf_pool_vf_small[16];
73
74
75
76 struct ethdi_hdr {
77     uint8_t pkt_type;
78     uint8_t source_id;
79     uint8_t dest_id;
80     int8_t data[];    /* original raw data starts here! */
81 };
82
83
84 void xran_init_mbuf_pool(uint32_t mtu);
85 void xran_init_port(int port, uint16_t num_rxq, uint32_t mtu);
86 void xran_init_port_mempool(int p_id, uint32_t mtu);
87 void xran_add_eth_hdr_vlan(struct rte_ether_addr *dst, uint16_t ethertype, struct rte_mbuf *mb);
88
89 #define PANIC_ON(x, m, ...) do { if (unlikely(x)) \
90     rte_panic("%s: " m "\n", #x, ##__VA_ARGS__); } while (0)
91
92 /* Add mbuf to the TX ring. */
93 static inline int xran_enqueue_mbuf(struct rte_mbuf *mb, struct rte_ring *r)
94 {
95     if (rte_ring_enqueue(r, mb) == 0) {
96         return 1;   /* success */
97     }
98
99     rte_pktmbuf_free(mb);
100     //print_err("failed to enqueue packet on port %d (ring full)", mb->port);
101
102     return 0;   /* fail */
103 }
104
105 #ifdef __cplusplus
106 }
107 #endif
108
109 #endif /* _XRANLIB_ETHERNET_H_ */