blob: ff7c7a5a41c94de59bca76101ffe93dda064e259 [file] [log] [blame]
Damjan Marion7f620972016-02-25 16:00:11 +01001/*
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#include <vnet/vnet.h>
16#include <vppinfra/vec.h>
17#include <vppinfra/format.h>
18#include <vlib/unix/cj.h>
19#include <assert.h>
20
21#include <vnet/ethernet/ethernet.h>
22#include <vnet/devices/dpdk/dpdk.h>
23
24#include "dpdk_priv.h"
25#include <vppinfra/error.h>
26
Damjan Marion7f620972016-02-25 16:00:11 +010027#define foreach_dpdk_counter \
28 _ (tx_frames_ok, opackets) \
29 _ (tx_bytes_ok, obytes) \
30 _ (tx_errors, oerrors) \
Damjan Marion7f620972016-02-25 16:00:11 +010031 _ (rx_frames_ok, ipackets) \
32 _ (rx_bytes_ok, ibytes) \
33 _ (rx_errors, ierrors) \
34 _ (rx_missed, imissed) \
Damjan Marion1f0da172016-07-13 22:44:18 +020035 _ (rx_no_bufs, rx_nombuf)
Damjan Marion7f620972016-02-25 16:00:11 +010036
37#define foreach_dpdk_q_counter \
38 _ (rx_frames_ok, q_ipackets) \
39 _ (tx_frames_ok, q_opackets) \
40 _ (rx_bytes_ok, q_ibytes) \
41 _ (tx_bytes_ok, q_obytes) \
42 _ (rx_errors, q_errors)
43
44#define foreach_dpdk_rss_hf \
Damjan Marion7f620972016-02-25 16:00:11 +010045 _(ETH_RSS_FRAG_IPV4, "ipv4-frag") \
46 _(ETH_RSS_NONFRAG_IPV4_TCP, "ipv4-tcp") \
47 _(ETH_RSS_NONFRAG_IPV4_UDP, "ipv4-udp") \
48 _(ETH_RSS_NONFRAG_IPV4_SCTP, "ipv4-sctp") \
49 _(ETH_RSS_NONFRAG_IPV4_OTHER, "ipv4-other") \
Srivatsa Sangli820e3632016-06-14 13:10:55 -070050 _(ETH_RSS_IPV4, "ipv4") \
51 _(ETH_RSS_IPV6_TCP_EX, "ipv6-tcp-ex") \
52 _(ETH_RSS_IPV6_UDP_EX, "ipv6-udp-ex") \
Damjan Marion7f620972016-02-25 16:00:11 +010053 _(ETH_RSS_FRAG_IPV6, "ipv6-frag") \
54 _(ETH_RSS_NONFRAG_IPV6_TCP, "ipv6-tcp") \
55 _(ETH_RSS_NONFRAG_IPV6_UDP, "ipv6-udp") \
56 _(ETH_RSS_NONFRAG_IPV6_SCTP, "ipv6-sctp") \
57 _(ETH_RSS_NONFRAG_IPV6_OTHER, "ipv6-other") \
58 _(ETH_RSS_L2_PAYLOAD, "l2-payload") \
59 _(ETH_RSS_IPV6_EX, "ipv6-ex") \
Srivatsa Sangli820e3632016-06-14 13:10:55 -070060 _(ETH_RSS_IPV6, "ipv6")
61
Damjan Marion7f620972016-02-25 16:00:11 +010062
63#define foreach_dpdk_rx_offload_caps \
64 _(DEV_RX_OFFLOAD_VLAN_STRIP, "vlan-strip") \
65 _(DEV_RX_OFFLOAD_IPV4_CKSUM, "ipv4-cksum") \
66 _(DEV_RX_OFFLOAD_UDP_CKSUM , "udp-cksum") \
67 _(DEV_RX_OFFLOAD_TCP_CKSUM , "tcp-cksum") \
68 _(DEV_RX_OFFLOAD_TCP_LRO , "rcp-lro") \
69 _(DEV_RX_OFFLOAD_QINQ_STRIP, "qinq-strip")
70
71#define foreach_dpdk_tx_offload_caps \
72 _(DEV_TX_OFFLOAD_VLAN_INSERT, "vlan-insert") \
73 _(DEV_TX_OFFLOAD_IPV4_CKSUM, "ipv4-cksum") \
74 _(DEV_TX_OFFLOAD_UDP_CKSUM , "udp-cksum") \
75 _(DEV_TX_OFFLOAD_TCP_CKSUM , "tcp-cksum") \
76 _(DEV_TX_OFFLOAD_SCTP_CKSUM , "sctp-cksum") \
77 _(DEV_TX_OFFLOAD_TCP_TSO , "tcp-tso") \
78 _(DEV_TX_OFFLOAD_UDP_TSO , "udp-tso") \
79 _(DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM, "outer-ipv4-cksum") \
80 _(DEV_TX_OFFLOAD_QINQ_INSERT, "qinq-insert")
81
John Loa60d4cb2016-12-17 03:09:58 -050082#if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0)
83/* New ol_flags bits added in DPDK-16.11 */
84#define PKT_RX_IP_CKSUM_GOOD (1ULL << 7)
85#define PKT_RX_L4_CKSUM_GOOD (1ULL << 8)
86#endif
87
Damjan Marion7f620972016-02-25 16:00:11 +010088#define foreach_dpdk_pkt_rx_offload_flag \
89 _ (PKT_RX_VLAN_PKT, "RX packet is a 802.1q VLAN packet") \
90 _ (PKT_RX_RSS_HASH, "RX packet with RSS hash result") \
91 _ (PKT_RX_FDIR, "RX packet with FDIR infos") \
92 _ (PKT_RX_L4_CKSUM_BAD, "L4 cksum of RX pkt. is not OK") \
93 _ (PKT_RX_IP_CKSUM_BAD, "IP cksum of RX pkt. is not OK") \
John Loa60d4cb2016-12-17 03:09:58 -050094 _ (PKT_RX_VLAN_STRIPPED, "RX packet VLAN tag stripped") \
95 _ (PKT_RX_IP_CKSUM_GOOD, "IP cksum of RX pkt. is valid") \
96 _ (PKT_RX_L4_CKSUM_GOOD, "L4 cksum of RX pkt. is valid") \
Damjan Marion7f620972016-02-25 16:00:11 +010097 _ (PKT_RX_IEEE1588_PTP, "RX IEEE1588 L2 Ethernet PT Packet") \
John Loa60d4cb2016-12-17 03:09:58 -050098 _ (PKT_RX_IEEE1588_TMST, "RX IEEE1588 L2/L4 timestamped packet") \
99 _ (PKT_RX_QINQ_STRIPPED, "RX packet QinQ tags stripped")
100
101#if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0)
102/* PTYPE added in DPDK-16.11 */
103#define RTE_PTYPE_L2_ETHER_VLAN 0x00000006
104#define RTE_PTYPE_L2_ETHER_QINQ 0x00000007
105#endif
Damjan Marion7f620972016-02-25 16:00:11 +0100106
107#define foreach_dpdk_pkt_type \
108 _ (L2, ETHER, "Ethernet packet") \
109 _ (L2, ETHER_TIMESYNC, "Ethernet packet for time sync") \
110 _ (L2, ETHER_ARP, "ARP packet") \
111 _ (L2, ETHER_LLDP, "LLDP (Link Layer Discovery Protocol) packet") \
John Loa60d4cb2016-12-17 03:09:58 -0500112 _ (L2, ETHER_NSH, "NSH (Network Service Header) packet") \
113 _ (L2, ETHER_VLAN, "VLAN packet") \
114 _ (L2, ETHER_QINQ, "QinQ packet") \
Damjan Marion7f620972016-02-25 16:00:11 +0100115 _ (L3, IPV4, "IPv4 packet without extension headers") \
116 _ (L3, IPV4_EXT, "IPv4 packet with extension headers") \
117 _ (L3, IPV4_EXT_UNKNOWN, "IPv4 packet with or without extension headers") \
118 _ (L3, IPV6, "IPv6 packet without extension headers") \
119 _ (L3, IPV6_EXT, "IPv6 packet with extension headers") \
120 _ (L3, IPV6_EXT_UNKNOWN, "IPv6 packet with or without extension headers") \
121 _ (L4, TCP, "TCP packet") \
122 _ (L4, UDP, "UDP packet") \
123 _ (L4, FRAG, "Fragmented IP packet") \
124 _ (L4, SCTP, "SCTP (Stream Control Transmission Protocol) packet") \
125 _ (L4, ICMP, "ICMP packet") \
126 _ (L4, NONFRAG, "Non-fragmented IP packet") \
127 _ (TUNNEL, GRE, "GRE tunneling packet") \
128 _ (TUNNEL, VXLAN, "VXLAN tunneling packet") \
129 _ (TUNNEL, NVGRE, "NVGRE Tunneling packet") \
130 _ (TUNNEL, GENEVE, "GENEVE Tunneling packet") \
131 _ (TUNNEL, GRENAT, "Teredo, VXLAN or GRE Tunneling packet") \
132 _ (INNER_L2, ETHER, "Inner Ethernet packet") \
133 _ (INNER_L2, ETHER_VLAN, "Inner Ethernet packet with VLAN") \
134 _ (INNER_L3, IPV4, "Inner IPv4 packet without extension headers") \
135 _ (INNER_L3, IPV4_EXT, "Inner IPv4 packet with extension headers") \
136 _ (INNER_L3, IPV4_EXT_UNKNOWN, "Inner IPv4 packet with or without extension headers") \
137 _ (INNER_L3, IPV6, "Inner IPv6 packet without extension headers") \
138 _ (INNER_L3, IPV6_EXT, "Inner IPv6 packet with extension headers") \
139 _ (INNER_L3, IPV6_EXT_UNKNOWN, "Inner IPv6 packet with or without extension headers") \
140 _ (INNER_L4, TCP, "Inner TCP packet") \
141 _ (INNER_L4, UDP, "Inner UDP packet") \
142 _ (INNER_L4, FRAG, "Inner fagmented IP packet") \
143 _ (INNER_L4, SCTP, "Inner SCTP (Stream Control Transmission Protocol) packet") \
144 _ (INNER_L4, ICMP, "Inner ICMP packet") \
145 _ (INNER_L4, NONFRAG, "Inner non-fragmented IP packet")
146
Damjan Marion7f620972016-02-25 16:00:11 +0100147#define foreach_dpdk_pkt_tx_offload_flag \
148 _ (PKT_TX_VLAN_PKT, "TX packet is a 802.1q VLAN packet") \
149 _ (PKT_TX_IP_CKSUM, "IP cksum of TX pkt. computed by NIC") \
150 _ (PKT_TX_TCP_CKSUM, "TCP cksum of TX pkt. computed by NIC") \
151 _ (PKT_TX_SCTP_CKSUM, "SCTP cksum of TX pkt. computed by NIC") \
152 _ (PKT_TX_IEEE1588_TMST, "TX IEEE1588 packet to timestamp")
153
154#define foreach_dpdk_pkt_offload_flag \
155 foreach_dpdk_pkt_rx_offload_flag \
156 foreach_dpdk_pkt_tx_offload_flag
157
Damjan Marion25665672016-08-16 18:56:08 +0200158u8 *
159format_dpdk_device_name (u8 * s, va_list * args)
Damjan Marion7f620972016-02-25 16:00:11 +0100160{
Damjan Marion25665672016-08-16 18:56:08 +0200161 dpdk_main_t *dm = &dpdk_main;
Damjan Marion7f620972016-02-25 16:00:11 +0100162 char *devname_format;
163 char *device_name;
164 u32 i = va_arg (*args, u32);
165 struct rte_eth_dev_info dev_info;
Damjan Marion25665672016-08-16 18:56:08 +0200166 u8 *ret;
Damjan Marion7f620972016-02-25 16:00:11 +0100167
Damjan Marion64ae6692016-05-25 18:40:13 +0200168 if (dm->conf->interface_name_format_decimal)
Damjan Marion7f620972016-02-25 16:00:11 +0100169 devname_format = "%s%d/%d/%d";
170 else
171 devname_format = "%s%x/%x/%x";
172
Damjan Marion7f620972016-02-25 16:00:11 +0100173 switch (dm->devices[i].port_type)
174 {
175 case VNET_DPDK_PORT_TYPE_ETH_1G:
176 device_name = "GigabitEthernet";
177 break;
178
179 case VNET_DPDK_PORT_TYPE_ETH_10G:
180 device_name = "TenGigabitEthernet";
181 break;
182
183 case VNET_DPDK_PORT_TYPE_ETH_40G:
184 device_name = "FortyGigabitEthernet";
185 break;
186
Damjan Marion696f1ad2016-12-23 22:42:41 +0100187 case VNET_DPDK_PORT_TYPE_ETH_100G:
188 device_name = "HundredGigabitEthernet";
189 break;
190
Damjan Marion7f620972016-02-25 16:00:11 +0100191 case VNET_DPDK_PORT_TYPE_ETH_BOND:
Damjan Marion25665672016-08-16 18:56:08 +0200192 return format (s, "BondEthernet%d", dm->devices[i].device_index);
Damjan Marion7f620972016-02-25 16:00:11 +0100193
194 case VNET_DPDK_PORT_TYPE_ETH_SWITCH:
195 device_name = "EthernetSwitch";
196 break;
197
Damjan Marion7f620972016-02-25 16:00:11 +0100198 case VNET_DPDK_PORT_TYPE_AF_PACKET:
Damjan Marion25665672016-08-16 18:56:08 +0200199 rte_eth_dev_info_get (i, &dev_info);
200 return format (s, "af_packet%d", dm->devices[i].af_packet_port_id);
Damjan Marion7f620972016-02-25 16:00:11 +0100201
202 default:
203 case VNET_DPDK_PORT_TYPE_UNKNOWN:
204 device_name = "UnknownEthernet";
205 break;
206 }
207
Damjan Marion25665672016-08-16 18:56:08 +0200208 rte_eth_dev_info_get (i, &dev_info);
Alexander Popovsky9dfd3382016-12-04 15:26:58 -0800209
210 if (dev_info.pci_dev)
211 ret = format (s, devname_format, device_name, dev_info.pci_dev->addr.bus,
212 dev_info.pci_dev->addr.devid,
213 dev_info.pci_dev->addr.function);
214 else
215 ret = format (s, "%s%d", device_name, dm->devices[i].device_index);
Damjan Marion7f620972016-02-25 16:00:11 +0100216
Damjan Marion32f7bc12016-07-21 03:42:37 -0700217 if (dm->devices[i].interface_name_suffix)
218 return format (ret, "/%s", dm->devices[i].interface_name_suffix);
Damjan Marion7f620972016-02-25 16:00:11 +0100219 return ret;
220}
221
Damjan Marion25665672016-08-16 18:56:08 +0200222static u8 *
223format_dpdk_device_type (u8 * s, va_list * args)
Damjan Marion7f620972016-02-25 16:00:11 +0100224{
Damjan Marion25665672016-08-16 18:56:08 +0200225 dpdk_main_t *dm = &dpdk_main;
Damjan Marion7f620972016-02-25 16:00:11 +0100226 char *dev_type;
227 u32 i = va_arg (*args, u32);
228
Damjan Marion7f620972016-02-25 16:00:11 +0100229 switch (dm->devices[i].pmd)
230 {
231 case VNET_DPDK_PMD_E1000EM:
Damjan Marion25665672016-08-16 18:56:08 +0200232 dev_type = "Intel 82540EM (e1000)";
233 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100234
235 case VNET_DPDK_PMD_IGB:
Damjan Marion25665672016-08-16 18:56:08 +0200236 dev_type = "Intel e1000";
237 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100238
239 case VNET_DPDK_PMD_I40E:
Damjan Marion25665672016-08-16 18:56:08 +0200240 dev_type = "Intel X710/XL710 Family";
241 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100242
243 case VNET_DPDK_PMD_I40EVF:
Damjan Marion25665672016-08-16 18:56:08 +0200244 dev_type = "Intel X710/XL710 Family VF";
245 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100246
247 case VNET_DPDK_PMD_FM10K:
Damjan Marion25665672016-08-16 18:56:08 +0200248 dev_type = "Intel FM10000 Family Ethernet Switch";
249 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100250
251 case VNET_DPDK_PMD_IGBVF:
Damjan Marion25665672016-08-16 18:56:08 +0200252 dev_type = "Intel e1000 VF";
253 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100254
255 case VNET_DPDK_PMD_VIRTIO:
Damjan Marion25665672016-08-16 18:56:08 +0200256 dev_type = "Red Hat Virtio";
257 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100258
259 case VNET_DPDK_PMD_IXGBEVF:
Damjan Marion25665672016-08-16 18:56:08 +0200260 dev_type = "Intel 82599 VF";
261 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100262
263 case VNET_DPDK_PMD_IXGBE:
Damjan Marion25665672016-08-16 18:56:08 +0200264 dev_type = "Intel 82599";
265 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100266
Damjan Marion7f620972016-02-25 16:00:11 +0100267 case VNET_DPDK_PMD_ENIC:
Damjan Marion25665672016-08-16 18:56:08 +0200268 dev_type = "Cisco VIC";
269 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100270
271 case VNET_DPDK_PMD_CXGBE:
Damjan Marion25665672016-08-16 18:56:08 +0200272 dev_type = "Chelsio T4/T5";
273 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100274
Damjan Marion696f1ad2016-12-23 22:42:41 +0100275 case VNET_DPDK_PMD_MLX5:
276 dev_type = "Mellanox ConnectX-4 Family";
277 break;
278
Damjan Marion7f620972016-02-25 16:00:11 +0100279 case VNET_DPDK_PMD_VMXNET3:
Damjan Marion25665672016-08-16 18:56:08 +0200280 dev_type = "VMware VMXNET3";
281 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100282
Damjan Marion7f620972016-02-25 16:00:11 +0100283 case VNET_DPDK_PMD_AF_PACKET:
Damjan Marion25665672016-08-16 18:56:08 +0200284 dev_type = "af_packet";
285 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100286
287 case VNET_DPDK_PMD_BOND:
Damjan Marion25665672016-08-16 18:56:08 +0200288 dev_type = "Ethernet Bonding";
289 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100290
Sachina29f2002016-06-17 09:24:20 +0530291 case VNET_DPDK_PMD_DPAA2:
Damjan Marion25665672016-08-16 18:56:08 +0200292 dev_type = "NXP DPAA2 Mac";
293 break;
Sachina29f2002016-06-17 09:24:20 +0530294
Damjan Marion7f620972016-02-25 16:00:11 +0100295 default:
296 case VNET_DPDK_PMD_UNKNOWN:
Damjan Marion25665672016-08-16 18:56:08 +0200297 dev_type = "### UNKNOWN ###";
298 break;
Damjan Marion7f620972016-02-25 16:00:11 +0100299 }
300
301 return format (s, dev_type);
302}
303
Damjan Marion25665672016-08-16 18:56:08 +0200304static u8 *
305format_dpdk_link_status (u8 * s, va_list * args)
Damjan Marion7f620972016-02-25 16:00:11 +0100306{
Damjan Marion25665672016-08-16 18:56:08 +0200307 dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
308 struct rte_eth_link *l = &xd->link;
309 vnet_main_t *vnm = vnet_get_main ();
310 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, xd->vlib_hw_if_index);
Damjan Marion7f620972016-02-25 16:00:11 +0100311
312 s = format (s, "%s ", l->link_status ? "up" : "down");
313 if (l->link_status)
314 {
315 u32 promisc = rte_eth_promiscuous_get (xd->device_index);
316
317 s = format (s, "%s duplex ", (l->link_duplex == ETH_LINK_FULL_DUPLEX) ?
Damjan Marion25665672016-08-16 18:56:08 +0200318 "full" : "half");
Damjan Marion7f620972016-02-25 16:00:11 +0100319 s = format (s, "speed %u mtu %d %s\n", l->link_speed,
320 hi->max_packet_bytes, promisc ? " promisc" : "");
321 }
322 else
323 s = format (s, "\n");
324
325 return s;
326}
327
328#define _line_len 72
329#define _(v, str) \
330if (bitmap & v) { \
331 if (format_get_indent (s) > next_split ) { \
332 next_split += _line_len; \
333 s = format(s,"\n%U", format_white_space, indent); \
334 } \
335 s = format(s, "%s ", str); \
336}
337
Damjan Marion25665672016-08-16 18:56:08 +0200338static u8 *
339format_dpdk_rss_hf_name (u8 * s, va_list * args)
Damjan Marion7f620972016-02-25 16:00:11 +0100340{
341 u64 bitmap = va_arg (*args, u64);
342 int next_split = _line_len;
343 int indent = format_get_indent (s);
344
345 if (!bitmap)
Damjan Marion25665672016-08-16 18:56:08 +0200346 return format (s, "none");
Damjan Marion7f620972016-02-25 16:00:11 +0100347
Damjan Marion25665672016-08-16 18:56:08 +0200348 foreach_dpdk_rss_hf return s;
Damjan Marion7f620972016-02-25 16:00:11 +0100349}
350
Damjan Marion25665672016-08-16 18:56:08 +0200351static u8 *
352format_dpdk_rx_offload_caps (u8 * s, va_list * args)
Damjan Marion7f620972016-02-25 16:00:11 +0100353{
354 u32 bitmap = va_arg (*args, u32);
355 int next_split = _line_len;
356 int indent = format_get_indent (s);
357
358 if (!bitmap)
Damjan Marion25665672016-08-16 18:56:08 +0200359 return format (s, "none");
Damjan Marion7f620972016-02-25 16:00:11 +0100360
Damjan Marion25665672016-08-16 18:56:08 +0200361 foreach_dpdk_rx_offload_caps return s;
Damjan Marion7f620972016-02-25 16:00:11 +0100362}
363
Damjan Marion25665672016-08-16 18:56:08 +0200364static u8 *
365format_dpdk_tx_offload_caps (u8 * s, va_list * args)
Damjan Marion7f620972016-02-25 16:00:11 +0100366{
367 u32 bitmap = va_arg (*args, u32);
368 int next_split = _line_len;
369 int indent = format_get_indent (s);
370 if (!bitmap)
Damjan Marion25665672016-08-16 18:56:08 +0200371 return format (s, "none");
Damjan Marion7f620972016-02-25 16:00:11 +0100372
Damjan Marion25665672016-08-16 18:56:08 +0200373 foreach_dpdk_tx_offload_caps return s;
Damjan Marion7f620972016-02-25 16:00:11 +0100374}
375
376#undef _line_len
377#undef _
378
Damjan Marion25665672016-08-16 18:56:08 +0200379u8 *
380format_dpdk_device (u8 * s, va_list * args)
Damjan Marion7f620972016-02-25 16:00:11 +0100381{
382 u32 dev_instance = va_arg (*args, u32);
383 int verbose = va_arg (*args, int);
Damjan Marion25665672016-08-16 18:56:08 +0200384 dpdk_main_t *dm = &dpdk_main;
385 dpdk_device_t *xd = vec_elt_at_index (dm->devices, dev_instance);
Damjan Marion7f620972016-02-25 16:00:11 +0100386 uword indent = format_get_indent (s);
387 f64 now = vlib_time_now (dm->vlib_main);
Damjan Marionc68b4cb2016-05-25 20:11:33 +0200388 struct rte_eth_dev_info di;
Damjan Marion7f620972016-02-25 16:00:11 +0100389
390 dpdk_update_counters (xd, now);
391 dpdk_update_link_state (xd, now);
392
393 s = format (s, "%U\n%Ucarrier %U",
394 format_dpdk_device_type, xd->device_index,
Damjan Marion25665672016-08-16 18:56:08 +0200395 format_white_space, indent + 2, format_dpdk_link_status, xd);
Damjan Marion7f620972016-02-25 16:00:11 +0100396
Damjan Marion25665672016-08-16 18:56:08 +0200397 rte_eth_dev_info_get (xd->device_index, &di);
Damjan Marionc68b4cb2016-05-25 20:11:33 +0200398
Damjan Marion56431702016-09-19 13:18:09 +0200399 if (verbose > 1 && xd->flags & DPDK_DEVICE_FLAG_PMD)
Damjan Marion7f620972016-02-25 16:00:11 +0100400 {
Damjan Marion25665672016-08-16 18:56:08 +0200401 struct rte_pci_device *pci;
Damjan Marion7f620972016-02-25 16:00:11 +0100402 struct rte_eth_rss_conf rss_conf;
403 int vlan_off;
Dave Barachdd522cb2016-08-10 16:56:16 -0400404 int retval;
Damjan Marion7f620972016-02-25 16:00:11 +0100405
406 rss_conf.rss_key = 0;
Damjan Marion25665672016-08-16 18:56:08 +0200407 retval = rte_eth_dev_rss_hash_conf_get (xd->device_index, &rss_conf);
Dave Barachdd522cb2016-08-10 16:56:16 -0400408 if (retval < 0)
Damjan Marion25665672016-08-16 18:56:08 +0200409 clib_warning ("rte_eth_dev_rss_hash_conf_get returned %d", retval);
Damjan Marion7f620972016-02-25 16:00:11 +0100410 pci = di.pci_dev;
411
412 if (pci)
Damjan Marion25665672016-08-16 18:56:08 +0200413 s =
414 format (s,
415 "%Upci id: device %04x:%04x subsystem %04x:%04x\n"
416 "%Upci address: %04x:%02x:%02x.%02x\n",
417 format_white_space, indent + 2, pci->id.vendor_id,
418 pci->id.device_id, pci->id.subsystem_vendor_id,
419 pci->id.subsystem_device_id, format_white_space, indent + 2,
420 pci->addr.domain, pci->addr.bus, pci->addr.devid,
421 pci->addr.function);
422 s =
423 format (s, "%Umax rx packet len: %d\n", format_white_space,
424 indent + 2, di.max_rx_pktlen);
425 s =
426 format (s, "%Umax num of queues: rx %d tx %d\n", format_white_space,
427 indent + 2, di.max_rx_queues, di.max_tx_queues);
428 s =
429 format (s, "%Upromiscuous: unicast %s all-multicast %s\n",
430 format_white_space, indent + 2,
431 rte_eth_promiscuous_get (xd->device_index) ? "on" : "off",
432 rte_eth_promiscuous_get (xd->device_index) ? "on" : "off");
433 vlan_off = rte_eth_dev_get_vlan_offload (xd->device_index);
434 s = format (s, "%Uvlan offload: strip %s filter %s qinq %s\n",
435 format_white_space, indent + 2,
436 vlan_off & ETH_VLAN_STRIP_OFFLOAD ? "on" : "off",
437 vlan_off & ETH_VLAN_FILTER_OFFLOAD ? "on" : "off",
438 vlan_off & ETH_VLAN_EXTEND_OFFLOAD ? "on" : "off");
439 s = format (s, "%Urx offload caps: %U\n",
440 format_white_space, indent + 2,
441 format_dpdk_rx_offload_caps, di.rx_offload_capa);
442 s = format (s, "%Utx offload caps: %U\n",
443 format_white_space, indent + 2,
444 format_dpdk_tx_offload_caps, di.tx_offload_capa);
445 s = format (s, "%Urss active: %U\n"
446 "%Urss supported: %U\n",
447 format_white_space, indent + 2,
448 format_dpdk_rss_hf_name, rss_conf.rss_hf,
449 format_white_space, indent + 2,
450 format_dpdk_rss_hf_name, di.flow_type_rss_offloads);
Damjan Marion7f620972016-02-25 16:00:11 +0100451 }
452
Damjan Marion39da6212016-06-06 13:21:04 +0200453 s = format (s, "%Urx queues %d, rx desc %d, tx queues %d, tx desc %d\n",
Damjan Marion25665672016-08-16 18:56:08 +0200454 format_white_space, indent + 2,
455 xd->rx_q_used, xd->nb_rx_desc, xd->tx_q_used, xd->nb_tx_desc);
Damjan Marion39da6212016-06-06 13:21:04 +0200456
Damjan Marion7f620972016-02-25 16:00:11 +0100457 if (xd->cpu_socket > -1)
Damjan Marion39da6212016-06-06 13:21:04 +0200458 s = format (s, "%Ucpu socket %d\n",
Damjan Marion25665672016-08-16 18:56:08 +0200459 format_white_space, indent + 2, xd->cpu_socket);
Damjan Marion7f620972016-02-25 16:00:11 +0100460
461 /* $$$ MIB counters */
Damjan Marion7f620972016-02-25 16:00:11 +0100462 {
463#define _(N, V) \
Sean Hopea4f16a02016-03-28 13:11:31 -0400464 if ((xd->stats.V - xd->last_cleared_stats.V) != 0) { \
465 s = format (s, "\n%U%-40U%16Ld", \
466 format_white_space, indent + 2, \
467 format_c_identifier, #N, \
468 xd->stats.V - xd->last_cleared_stats.V); \
469 } \
Damjan Marion7f620972016-02-25 16:00:11 +0100470
471 foreach_dpdk_counter
472#undef _
473 }
474
Damjan Marion25665672016-08-16 18:56:08 +0200475 u8 *xs = 0;
Sean Hopea4f16a02016-03-28 13:11:31 -0400476 u32 i = 0;
Damjan Marion25665672016-08-16 18:56:08 +0200477 struct rte_eth_xstat *xstat, *last_xstat;
478 struct rte_eth_xstat_name *xstat_names = 0;
Damjan Marion1f0da172016-07-13 22:44:18 +0200479 int len = rte_eth_xstats_get_names (xd->device_index, NULL, 0);
480 vec_validate (xstat_names, len - 1);
481 rte_eth_xstats_get_names (xd->device_index, xstat_names, len);
Damjan Marion7f620972016-02-25 16:00:11 +0100482
Damjan Marion25665672016-08-16 18:56:08 +0200483 ASSERT (vec_len (xd->xstats) == vec_len (xd->last_cleared_xstats));
Sean Hopea4f16a02016-03-28 13:11:31 -0400484
Damjan Marion25665672016-08-16 18:56:08 +0200485 /* *INDENT-OFF* */
Sean Hopea4f16a02016-03-28 13:11:31 -0400486 vec_foreach_index(i, xd->xstats)
Damjan Marion7f620972016-02-25 16:00:11 +0100487 {
Sean Hopea4f16a02016-03-28 13:11:31 -0400488 u64 delta = 0;
Damjan Marion1f0da172016-07-13 22:44:18 +0200489 xstat = vec_elt_at_index(xd->xstats, i);
490 last_xstat = vec_elt_at_index(xd->last_cleared_xstats, i);
Sean Hopea4f16a02016-03-28 13:11:31 -0400491
492 delta = xstat->value - last_xstat->value;
493 if (verbose == 2 || (verbose && delta))
Damjan Marion7f620972016-02-25 16:00:11 +0100494 {
Sean Hopea4f16a02016-03-28 13:11:31 -0400495 /* format_c_identifier doesn't like c strings inside vector */
Damjan Marion1f0da172016-07-13 22:44:18 +0200496 u8 * name = format(0,"%s", xstat_names[i].name);
Damjan Marion7f620972016-02-25 16:00:11 +0100497 xs = format(xs, "\n%U%-38U%16Ld",
498 format_white_space, indent + 4,
Sean Hopea4f16a02016-03-28 13:11:31 -0400499 format_c_identifier, name, delta);
Damjan Marion7f620972016-02-25 16:00:11 +0100500 vec_free(name);
501 }
502 }
Damjan Marion25665672016-08-16 18:56:08 +0200503 /* *INDENT-ON* */
Damjan Marion7f620972016-02-25 16:00:11 +0100504
Damjan Marion1f0da172016-07-13 22:44:18 +0200505 vec_free (xstat_names);
Shesha Sreenivasamurthy94550842016-03-02 10:33:26 -0800506
Damjan Marion7f620972016-02-25 16:00:11 +0100507 if (xs)
508 {
Damjan Marion25665672016-08-16 18:56:08 +0200509 s = format (s, "\n%Uextended stats:%v",
510 format_white_space, indent + 2, xs);
511 vec_free (xs);
Damjan Marion7f620972016-02-25 16:00:11 +0100512 }
513
514 return s;
515}
516
Damjan Marion25665672016-08-16 18:56:08 +0200517u8 *
518format_dpdk_tx_dma_trace (u8 * s, va_list * va)
Damjan Marion7f620972016-02-25 16:00:11 +0100519{
520 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
521 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
Damjan Marion25665672016-08-16 18:56:08 +0200522 CLIB_UNUSED (vnet_main_t * vnm) = vnet_get_main ();
523 dpdk_tx_dma_trace_t *t = va_arg (*va, dpdk_tx_dma_trace_t *);
524 dpdk_main_t *dm = &dpdk_main;
525 dpdk_device_t *xd = vec_elt_at_index (dm->devices, t->device_index);
Damjan Marion7f620972016-02-25 16:00:11 +0100526 uword indent = format_get_indent (s);
Damjan Marion25665672016-08-16 18:56:08 +0200527 vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, xd->vlib_sw_if_index);
Damjan Marion7f620972016-02-25 16:00:11 +0100528
529 s = format (s, "%U tx queue %d",
Damjan Marion25665672016-08-16 18:56:08 +0200530 format_vnet_sw_interface_name, vnm, sw, t->queue_index);
Damjan Marion7f620972016-02-25 16:00:11 +0100531
532 s = format (s, "\n%Ubuffer 0x%x: %U",
533 format_white_space, indent,
Damjan Marion25665672016-08-16 18:56:08 +0200534 t->buffer_index, format_vlib_buffer, &t->buffer);
Damjan Marion7f620972016-02-25 16:00:11 +0100535
536 s = format (s, "\n%U%U", format_white_space, indent,
537 format_ethernet_header_with_length, t->buffer.pre_data,
538 sizeof (t->buffer.pre_data));
539
540 return s;
541}
542
Damjan Marion25665672016-08-16 18:56:08 +0200543u8 *
544format_dpdk_rx_dma_trace (u8 * s, va_list * va)
Damjan Marion7f620972016-02-25 16:00:11 +0100545{
546 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
547 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
Damjan Marion25665672016-08-16 18:56:08 +0200548 CLIB_UNUSED (vnet_main_t * vnm) = vnet_get_main ();
549 dpdk_rx_dma_trace_t *t = va_arg (*va, dpdk_rx_dma_trace_t *);
550 dpdk_main_t *dm = &dpdk_main;
551 dpdk_device_t *xd = vec_elt_at_index (dm->devices, t->device_index);
552 format_function_t *f;
Damjan Marion7f620972016-02-25 16:00:11 +0100553 uword indent = format_get_indent (s);
Damjan Marion25665672016-08-16 18:56:08 +0200554 vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, xd->vlib_sw_if_index);
Damjan Marion7f620972016-02-25 16:00:11 +0100555
556 s = format (s, "%U rx queue %d",
Damjan Marion25665672016-08-16 18:56:08 +0200557 format_vnet_sw_interface_name, vnm, sw, t->queue_index);
Damjan Marion7f620972016-02-25 16:00:11 +0100558
559 s = format (s, "\n%Ubuffer 0x%x: %U",
560 format_white_space, indent,
Damjan Marion25665672016-08-16 18:56:08 +0200561 t->buffer_index, format_vlib_buffer, &t->buffer);
Damjan Marion7f620972016-02-25 16:00:11 +0100562
Damjan Marion7f620972016-02-25 16:00:11 +0100563 s = format (s, "\n%U%U",
564 format_white_space, indent,
marek zavodskyad2c9c02016-07-07 03:16:10 +0200565 format_dpdk_rte_mbuf, &t->mb, &t->data);
Damjan Marion4fafa622016-11-18 10:35:35 +0100566
Damjan Mariondb7b2692016-06-09 16:16:27 +0200567 if (vm->trace_main.verbose)
568 {
569 s = format (s, "\n%UPacket Dump%s", format_white_space, indent + 2,
Damjan Marion25665672016-08-16 18:56:08 +0200570 t->mb.data_len > sizeof (t->data) ? " (truncated)" : "");
Damjan Mariondb7b2692016-06-09 16:16:27 +0200571 s = format (s, "\n%U%U", format_white_space, indent + 4,
572 format_hexdump, &t->data,
Damjan Marion25665672016-08-16 18:56:08 +0200573 t->mb.data_len >
574 sizeof (t->data) ? sizeof (t->data) : t->mb.data_len);
Damjan Mariondb7b2692016-06-09 16:16:27 +0200575 }
Damjan Marion7f620972016-02-25 16:00:11 +0100576 f = node->format_buffer;
577 if (!f)
578 f = format_hex_bytes;
579 s = format (s, "\n%U%U", format_white_space, indent,
580 f, t->buffer.pre_data, sizeof (t->buffer.pre_data));
581
582 return s;
583}
584
585
Damjan Marion25665672016-08-16 18:56:08 +0200586static inline u8 *
587format_dpdk_pkt_types (u8 * s, va_list * va)
Damjan Marion7f620972016-02-25 16:00:11 +0100588{
589 u32 *pkt_types = va_arg (*va, u32 *);
Damjan Marion25665672016-08-16 18:56:08 +0200590 uword indent __attribute__ ((unused)) = format_get_indent (s) + 2;
Damjan Marion7f620972016-02-25 16:00:11 +0100591
592 if (!*pkt_types)
593 return s;
594
595 s = format (s, "Packet Types");
596
597#define _(L, F, S) \
598 if ((*pkt_types & RTE_PTYPE_##L##_MASK) == RTE_PTYPE_##L##_##F) \
599 { \
600 s = format (s, "\n%U%s (0x%04x) %s", format_white_space, indent, \
601 "RTE_PTYPE_" #L "_" #F, RTE_PTYPE_##L##_##F, S); \
602 }
603
604 foreach_dpdk_pkt_type
Damjan Marion7f620972016-02-25 16:00:11 +0100605#undef _
Damjan Marion25665672016-08-16 18:56:08 +0200606 return s;
Damjan Marion7f620972016-02-25 16:00:11 +0100607}
608
Damjan Marion25665672016-08-16 18:56:08 +0200609static inline u8 *
610format_dpdk_pkt_offload_flags (u8 * s, va_list * va)
Damjan Marion7f620972016-02-25 16:00:11 +0100611{
Damjan Marionb022cd12016-08-16 13:25:59 +0200612 u64 *ol_flags = va_arg (*va, u64 *);
Damjan Marion7f620972016-02-25 16:00:11 +0100613 uword indent = format_get_indent (s) + 2;
614
615 if (!*ol_flags)
616 return s;
617
618 s = format (s, "Packet Offload Flags");
619
620#define _(F, S) \
621 if (*ol_flags & F) \
622 { \
623 s = format (s, "\n%U%s (0x%04x) %s", \
624 format_white_space, indent, #F, F, S); \
625 }
626
627 foreach_dpdk_pkt_offload_flag
Damjan Marion7f620972016-02-25 16:00:11 +0100628#undef _
Damjan Marion25665672016-08-16 18:56:08 +0200629 return s;
630}
631
632u8 *
633format_dpdk_rte_mbuf_vlan (u8 * s, va_list * va)
634{
635 ethernet_vlan_header_tv_t *vlan_hdr =
636 va_arg (*va, ethernet_vlan_header_tv_t *);
637
638 if (clib_net_to_host_u16 (vlan_hdr->type) == ETHERNET_TYPE_DOT1AD)
639 {
640 s = format (s, "%U 802.1q vlan ",
641 format_ethernet_vlan_tci,
642 clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
643 vlan_hdr++;
644 }
645
646 s = format (s, "%U",
647 format_ethernet_vlan_tci,
648 clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
Damjan Marion7f620972016-02-25 16:00:11 +0100649
650 return s;
651}
652
Damjan Marion25665672016-08-16 18:56:08 +0200653u8 *
654format_dpdk_rte_mbuf (u8 * s, va_list * va)
marek zavodskyad2c9c02016-07-07 03:16:10 +0200655{
Damjan Marion25665672016-08-16 18:56:08 +0200656 struct rte_mbuf *mb = va_arg (*va, struct rte_mbuf *);
marek zavodskyad2c9c02016-07-07 03:16:10 +0200657 ethernet_header_t *eth_hdr = va_arg (*va, ethernet_header_t *);
Damjan Marion7f620972016-02-25 16:00:11 +0100658 uword indent = format_get_indent (s) + 2;
659
660 s = format (s, "PKT MBUF: port %d, nb_segs %d, pkt_len %d"
Damjan Marion25665672016-08-16 18:56:08 +0200661 "\n%Ubuf_len %d, data_len %d, ol_flags 0x%x, data_off %d, phys_addr 0x%x"
662 "\n%Upacket_type 0x%x",
663 mb->port, mb->nb_segs, mb->pkt_len,
664 format_white_space, indent,
665 mb->buf_len, mb->data_len, mb->ol_flags, mb->data_off,
666 mb->buf_physaddr, format_white_space, indent, mb->packet_type);
Damjan Marion7f620972016-02-25 16:00:11 +0100667
668 if (mb->ol_flags)
669 s = format (s, "\n%U%U", format_white_space, indent,
Damjan Marion25665672016-08-16 18:56:08 +0200670 format_dpdk_pkt_offload_flags, &mb->ol_flags);
Damjan Marion7f620972016-02-25 16:00:11 +0100671
John Loa60d4cb2016-12-17 03:09:58 -0500672 if ((mb->ol_flags & PKT_RX_VLAN_PKT) &&
673 ((mb->ol_flags & (PKT_RX_VLAN_STRIPPED | PKT_RX_QINQ_STRIPPED)) == 0))
Damjan Marion25665672016-08-16 18:56:08 +0200674 {
675 ethernet_vlan_header_tv_t *vlan_hdr =
676 ((ethernet_vlan_header_tv_t *) & (eth_hdr->type));
677 s = format (s, " %U", format_dpdk_rte_mbuf_vlan, vlan_hdr);
678 }
marek zavodskyad2c9c02016-07-07 03:16:10 +0200679
Damjan Marion7f620972016-02-25 16:00:11 +0100680 if (mb->packet_type)
681 s = format (s, "\n%U%U", format_white_space, indent,
Damjan Marion25665672016-08-16 18:56:08 +0200682 format_dpdk_pkt_types, &mb->packet_type);
marek zavodskyad2c9c02016-07-07 03:16:10 +0200683
Damjan Marion7f620972016-02-25 16:00:11 +0100684 return s;
685}
686
Damjan Marion7f620972016-02-25 16:00:11 +0100687uword
688unformat_socket_mem (unformat_input_t * input, va_list * va)
689{
Damjan Marion25665672016-08-16 18:56:08 +0200690 uword **r = va_arg (*va, uword **);
Damjan Marion7f620972016-02-25 16:00:11 +0100691 int i = 0;
692 u32 mem;
693
694 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
695 {
696 if (unformat (input, ","))
Damjan Marion25665672016-08-16 18:56:08 +0200697 hash_set (*r, i, 1024);
Damjan Marion7f620972016-02-25 16:00:11 +0100698 else if (unformat (input, "%u,", &mem))
Damjan Marion25665672016-08-16 18:56:08 +0200699 hash_set (*r, i, mem);
Damjan Marion7f620972016-02-25 16:00:11 +0100700 else if (unformat (input, "%u", &mem))
Damjan Marion25665672016-08-16 18:56:08 +0200701 hash_set (*r, i, mem);
Damjan Marion7f620972016-02-25 16:00:11 +0100702 else
Damjan Marion25665672016-08-16 18:56:08 +0200703 {
704 unformat_put_input (input);
705 goto done;
706 }
Damjan Marion7f620972016-02-25 16:00:11 +0100707 i++;
708 }
709
710done:
711 return 1;
712}
Srivatsa Sangli820e3632016-06-14 13:10:55 -0700713
714clib_error_t *
715unformat_rss_fn (unformat_input_t * input, uword * rss_fn)
716{
717 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
718 {
719 if (0)
Damjan Marion25665672016-08-16 18:56:08 +0200720 ;
Srivatsa Sangli820e3632016-06-14 13:10:55 -0700721#undef _
722#define _(f, s) \
723 else if (unformat (input, s)) \
724 *rss_fn |= f;
725
726 foreach_dpdk_rss_hf
727#undef _
Damjan Marion25665672016-08-16 18:56:08 +0200728 else
729 {
730 return clib_error_return (0, "unknown input `%U'",
731 format_unformat_error, input);
732 }
Srivatsa Sangli820e3632016-06-14 13:10:55 -0700733 }
734 return 0;
735}
Damjan Marion25665672016-08-16 18:56:08 +0200736
Jasvinder Singh85ecc812016-07-21 17:02:19 +0100737clib_error_t *
738unformat_hqos (unformat_input_t * input, dpdk_device_config_hqos_t * hqos)
739{
740 clib_error_t *error = 0;
741
742 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
743 {
744 if (unformat (input, "hqos-thread %u", &hqos->hqos_thread))
745 hqos->hqos_thread_valid = 1;
746 else
747 {
748 error = clib_error_return (0, "unknown input `%U'",
749 format_unformat_error, input);
750 break;
751 }
752 }
753
754 return error;
755}
756
Damjan Marion25665672016-08-16 18:56:08 +0200757/*
758 * fd.io coding-style-patch-verification: ON
759 *
760 * Local Variables:
761 * eval: (c-set-style "gnu")
762 * End:
763 */