e170134052dcc4db02420a911a971f427bdb8ddd
[vpp.git] / src / plugins / dpdk / device / dpdk_priv.h
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #define DPDK_NB_RX_DESC_DEFAULT   1024
17 #define DPDK_NB_TX_DESC_DEFAULT   1024
18 #define DPDK_MAX_LRO_SIZE_DEFAULT 65536
19 #define DPDK_NB_RX_DESC_VIRTIO    256
20 #define DPDK_NB_TX_DESC_VIRTIO    256
21
22 /* These args appear by themselves */
23 #define foreach_eal_double_hyphen_predicate_arg \
24 _(no-shconf)                                    \
25 _(no-hpet)                                      \
26 _(no-huge)                                      \
27 _(vmware-tsc-map)
28
29 #define foreach_eal_single_hyphen_arg           \
30 _(mem-alloc-request, m)                         \
31 _(force-ranks, r)
32
33 /* clang-format off */
34 /* These args are preceded by "--" and followed by a single string */
35 #define foreach_eal_double_hyphen_arg           \
36 _(huge-dir)                                     \
37 _(proc-type)                                    \
38 _(file-prefix)                                  \
39 _(vdev)                                         \
40 _(log-level)                                    \
41 _(iova-mode)                                    \
42 _(base-virtaddr)
43 /* clang-format on */
44
45 static_always_inline void
46 dpdk_device_flag_set (dpdk_device_t *xd, __typeof__ (xd->flags) flag, int val)
47 {
48   xd->flags = val ? xd->flags | flag : xd->flags & ~flag;
49 }
50
51 static inline void
52 dpdk_get_xstats (dpdk_device_t * xd)
53 {
54   int len, ret;
55
56   if (!(xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP))
57     return;
58
59   len = rte_eth_xstats_get (xd->port_id, NULL, 0);
60   if (len < 0)
61     return;
62
63   vec_validate (xd->xstats, len - 1);
64
65   ret = rte_eth_xstats_get (xd->port_id, xd->xstats, len);
66   if (ret < 0 || ret > len)
67     {
68       _vec_len (xd->xstats) = 0;
69       return;
70     }
71
72   _vec_len (xd->xstats) = len;
73 }
74
75 #define DPDK_UPDATE_COUNTER(vnm, tidx, xd, stat, cnt)                         \
76   do                                                                          \
77     {                                                                         \
78       u64 _v = (xd)->stats.stat;                                              \
79       u64 _lv = (xd)->last_stats.stat;                                        \
80       if (PREDICT_FALSE (_v != _lv))                                          \
81         {                                                                     \
82           if (PREDICT_FALSE (_v < _lv))                                       \
83             dpdk_log_warn ("%v: %s counter decreased (before %lu after %lu)", \
84                            xd->name, #stat, _lv, _v);                         \
85           else                                                                \
86             vlib_increment_simple_counter (                                   \
87                 vec_elt_at_index ((vnm)->interface_main.sw_if_counters, cnt), \
88                 (tidx), (xd)->sw_if_index, _v - _lv);                         \
89         }                                                                     \
90     }                                                                         \
91   while (0)
92
93 static inline void
94 dpdk_update_counters (dpdk_device_t * xd, f64 now)
95 {
96   vnet_main_t *vnm = vnet_get_main ();
97   u32 thread_index = vlib_get_thread_index ();
98
99   xd->time_last_stats_update = now ? now : xd->time_last_stats_update;
100   clib_memcpy_fast (&xd->last_stats, &xd->stats, sizeof (xd->last_stats));
101   rte_eth_stats_get (xd->port_id, &xd->stats);
102
103   /* maybe bump interface rx no buffer counter */
104   DPDK_UPDATE_COUNTER (vnm, thread_index, xd, rx_nombuf,
105                        VNET_INTERFACE_COUNTER_RX_NO_BUF);
106   DPDK_UPDATE_COUNTER (vnm, thread_index, xd, imissed,
107                        VNET_INTERFACE_COUNTER_RX_MISS);
108   DPDK_UPDATE_COUNTER (vnm, thread_index, xd, ierrors,
109                        VNET_INTERFACE_COUNTER_RX_ERROR);
110
111   dpdk_get_xstats (xd);
112 }
113
114 #if RTE_VERSION < RTE_VERSION_NUM(21, 11, 0, 0)
115 #define RTE_MBUF_F_RX_FDIR                PKT_RX_FDIR
116 #define RTE_MBUF_F_RX_FDIR_FLX            PKT_RX_FDIR_FLX
117 #define RTE_MBUF_F_RX_FDIR_ID             PKT_RX_FDIR_ID
118 #define RTE_MBUF_F_RX_IEEE1588_PTP        PKT_RX_IEEE1588_PTP
119 #define RTE_MBUF_F_RX_IEEE1588_TMST       PKT_RX_IEEE1588_TMST
120 #define RTE_MBUF_F_RX_IP_CKSUM_BAD        PKT_RX_IP_CKSUM_BAD
121 #define RTE_MBUF_F_RX_IP_CKSUM_GOOD       PKT_RX_IP_CKSUM_GOOD
122 #define RTE_MBUF_F_RX_IP_CKSUM_NONE       PKT_RX_IP_CKSUM_GOOD
123 #define RTE_MBUF_F_RX_L4_CKSUM_BAD        PKT_RX_L4_CKSUM_BAD
124 #define RTE_MBUF_F_RX_L4_CKSUM_GOOD       PKT_RX_L4_CKSUM_GOOD
125 #define RTE_MBUF_F_RX_L4_CKSUM_NONE       PKT_RX_L4_CKSUM_GOOD
126 #define RTE_MBUF_F_RX_LRO                 PKT_RX_LRO
127 #define RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD  PKT_RX_OUTER_IP_CKSUM_BAD
128 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD  PKT_RX_OUTER_L4_CKSUM_GOOD
129 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD PKT_RX_OUTER_L4_CKSUM_GOOD
130 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_NONE PKT_RX_OUTER_L4_CKSUM_GOOD
131 #define RTE_MBUF_F_RX_QINQ                PKT_RX_QINQ
132 #define RTE_MBUF_F_RX_QINQ_STRIPPED       PKT_RX_QINQ_STRIPPED
133 #define RTE_MBUF_F_RX_RSS_HASH            PKT_RX_RSS_HASH
134 #define RTE_MBUF_F_RX_SEC_OFFLOAD         PKT_RX_SEC_OFFLOAD
135 #define RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED  PKT_RX_SEC_OFFLOAD_FAILED
136 #define RTE_MBUF_F_RX_VLAN                PKT_RX_VLAN
137 #define RTE_MBUF_F_RX_VLAN_STRIPPED       PKT_RX_VLAN_STRIPPED
138 #define RTE_MBUF_F_TX_IEEE1588_TMST       PKT_TX_IEEE1588_TMST
139 #define RTE_MBUF_F_TX_IPV4                PKT_TX_IPV4
140 #define RTE_MBUF_F_TX_IPV6                PKT_TX_IPV6
141 #define RTE_MBUF_F_TX_IP_CKSUM            PKT_TX_IP_CKSUM
142 #define RTE_MBUF_F_TX_MACSEC              PKT_TX_MACSEC
143 #define RTE_MBUF_F_TX_OUTER_IPV4          PKT_TX_OUTER_IPV4
144 #define RTE_MBUF_F_TX_OUTER_IPV6          PKT_TX_OUTER_IPV6
145 #define RTE_MBUF_F_TX_OUTER_IP_CKSUM      PKT_TX_OUTER_IP_CKSUM
146 #define RTE_MBUF_F_TX_OUTER_UDP_CKSUM     PKT_TX_OUTER_UDP_CKSUM
147 #define RTE_MBUF_F_TX_QINQ                PKT_TX_QINQ
148 #define RTE_MBUF_F_TX_SCTP_CKSUM          PKT_TX_SCTP_CKSUM
149 #define RTE_MBUF_F_TX_SEC_OFFLOAD         PKT_TX_SEC_OFFLOAD
150 #define RTE_MBUF_F_TX_TCP_CKSUM           PKT_TX_TCP_CKSUM
151 #define RTE_MBUF_F_TX_TCP_SEG             PKT_TX_TCP_SEG
152 #define RTE_MBUF_F_TX_TUNNEL_GENEVE       PKT_TX_TUNNEL_GENEVE
153 #define RTE_MBUF_F_TX_TUNNEL_GRE          PKT_TX_TUNNEL_GRE
154 #define RTE_MBUF_F_TX_TUNNEL_GTP          PKT_TX_TUNNEL_GTP
155 #define RTE_MBUF_F_TX_TUNNEL_IP           PKT_TX_TUNNEL_IP
156 #define RTE_MBUF_F_TX_TUNNEL_IPIP         PKT_TX_TUNNEL_IPIP
157 #define RTE_MBUF_F_TX_TUNNEL_MPLSINUDP    PKT_TX_TUNNEL_MPLSINUDP
158 #define RTE_MBUF_F_TX_TUNNEL_UDP          PKT_TX_TUNNEL_UDP
159 #define RTE_MBUF_F_TX_TUNNEL_VXLAN        PKT_TX_TUNNEL_VXLAN
160 #define RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE    PKT_TX_TUNNEL_VXLAN_GPE
161 #define RTE_MBUF_F_TX_UDP_CKSUM           PKT_TX_UDP_CKSUM
162 #define RTE_MBUF_F_TX_UDP_SEG             PKT_TX_UDP_SEG
163 #define RTE_MBUF_F_TX_VLAN                PKT_TX_VLAN
164 #endif
165
166 /*
167  * fd.io coding-style-patch-verification: ON
168  *
169  * Local Variables:
170  * eval: (c-set-style "gnu")
171  * End:
172  */