FD.io VPP  v16.06
Vector Packet Processing
format.c
Go to the documentation of this file.
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 #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 
27 #if RTE_VERSION >= RTE_VERSION_NUM(2, 2, 0, 0)
28 #define foreach_dpdk_counter \
29  _ (tx_frames_ok, opackets) \
30  _ (tx_bytes_ok, obytes) \
31  _ (tx_errors, oerrors) \
32  _ (tx_loopback_frames_ok, olbpackets) \
33  _ (tx_loopback_bytes_ok, olbbytes) \
34  _ (rx_frames_ok, ipackets) \
35  _ (rx_bytes_ok, ibytes) \
36  _ (rx_errors, ierrors) \
37  _ (rx_missed, imissed) \
38  _ (rx_multicast_frames_ok, imcasts) \
39  _ (rx_no_bufs, rx_nombuf) \
40  _ (rx_loopback_frames_ok, ilbpackets) \
41  _ (rx_loopback_bytes_ok, ilbbytes)
42 #else
43 #define foreach_dpdk_counter \
44  _ (tx_frames_ok, opackets) \
45  _ (tx_bytes_ok, obytes) \
46  _ (tx_errors, oerrors) \
47  _ (tx_loopback_frames_ok, olbpackets) \
48  _ (tx_loopback_bytes_ok, olbbytes) \
49  _ (rx_frames_ok, ipackets) \
50  _ (rx_bytes_ok, ibytes) \
51  _ (rx_errors, ierrors) \
52  _ (rx_missed, imissed) \
53  _ (rx_bad_crc, ibadcrc) \
54  _ (rx_bad_length, ibadlen) \
55  _ (rx_multicast_frames_ok, imcasts) \
56  _ (rx_no_bufs, rx_nombuf) \
57  _ (rx_filter_match, fdirmatch) \
58  _ (rx_filter_miss, fdirmiss) \
59  _ (tx_pause_xon, tx_pause_xon) \
60  _ (rx_pause_xon, rx_pause_xon) \
61  _ (tx_pause_xoff, tx_pause_xoff) \
62  _ (rx_pause_xoff, rx_pause_xoff) \
63  _ (rx_loopback_frames_ok, ilbpackets) \
64  _ (rx_loopback_bytes_ok, ilbbytes)
65 #endif
66 
67 #define foreach_dpdk_q_counter \
68  _ (rx_frames_ok, q_ipackets) \
69  _ (tx_frames_ok, q_opackets) \
70  _ (rx_bytes_ok, q_ibytes) \
71  _ (tx_bytes_ok, q_obytes) \
72  _ (rx_errors, q_errors)
73 
74 #define foreach_dpdk_rss_hf \
75  _(ETH_RSS_IPV4, "ipv4") \
76  _(ETH_RSS_FRAG_IPV4, "ipv4-frag") \
77  _(ETH_RSS_NONFRAG_IPV4_TCP, "ipv4-tcp") \
78  _(ETH_RSS_NONFRAG_IPV4_UDP, "ipv4-udp") \
79  _(ETH_RSS_NONFRAG_IPV4_SCTP, "ipv4-sctp") \
80  _(ETH_RSS_NONFRAG_IPV4_OTHER, "ipv4-other") \
81  _(ETH_RSS_IPV6, "ipv6") \
82  _(ETH_RSS_FRAG_IPV6, "ipv6-frag") \
83  _(ETH_RSS_NONFRAG_IPV6_TCP, "ipv6-tcp") \
84  _(ETH_RSS_NONFRAG_IPV6_UDP, "ipv6-udp") \
85  _(ETH_RSS_NONFRAG_IPV6_SCTP, "ipv6-sctp") \
86  _(ETH_RSS_NONFRAG_IPV6_OTHER, "ipv6-other") \
87  _(ETH_RSS_L2_PAYLOAD, "l2-payload") \
88  _(ETH_RSS_IPV6_EX, "ipv6-ex") \
89  _(ETH_RSS_IPV6_TCP_EX, "ipv6-tcp-ex") \
90  _(ETH_RSS_IPV6_UDP_EX, "ipv6-udp-ex")
91 
92 #define foreach_dpdk_rx_offload_caps \
93  _(DEV_RX_OFFLOAD_VLAN_STRIP, "vlan-strip") \
94  _(DEV_RX_OFFLOAD_IPV4_CKSUM, "ipv4-cksum") \
95  _(DEV_RX_OFFLOAD_UDP_CKSUM , "udp-cksum") \
96  _(DEV_RX_OFFLOAD_TCP_CKSUM , "tcp-cksum") \
97  _(DEV_RX_OFFLOAD_TCP_LRO , "rcp-lro") \
98  _(DEV_RX_OFFLOAD_QINQ_STRIP, "qinq-strip")
99 
100 #define foreach_dpdk_tx_offload_caps \
101  _(DEV_TX_OFFLOAD_VLAN_INSERT, "vlan-insert") \
102  _(DEV_TX_OFFLOAD_IPV4_CKSUM, "ipv4-cksum") \
103  _(DEV_TX_OFFLOAD_UDP_CKSUM , "udp-cksum") \
104  _(DEV_TX_OFFLOAD_TCP_CKSUM , "tcp-cksum") \
105  _(DEV_TX_OFFLOAD_SCTP_CKSUM , "sctp-cksum") \
106  _(DEV_TX_OFFLOAD_TCP_TSO , "tcp-tso") \
107  _(DEV_TX_OFFLOAD_UDP_TSO , "udp-tso") \
108  _(DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM, "outer-ipv4-cksum") \
109  _(DEV_TX_OFFLOAD_QINQ_INSERT, "qinq-insert")
110 
111 #if RTE_VERSION >= RTE_VERSION_NUM(2, 1, 0, 0)
112 
113 #define foreach_dpdk_pkt_rx_offload_flag \
114  _ (PKT_RX_VLAN_PKT, "RX packet is a 802.1q VLAN packet") \
115  _ (PKT_RX_RSS_HASH, "RX packet with RSS hash result") \
116  _ (PKT_RX_FDIR, "RX packet with FDIR infos") \
117  _ (PKT_RX_L4_CKSUM_BAD, "L4 cksum of RX pkt. is not OK") \
118  _ (PKT_RX_IP_CKSUM_BAD, "IP cksum of RX pkt. is not OK") \
119  _ (PKT_RX_IEEE1588_PTP, "RX IEEE1588 L2 Ethernet PT Packet") \
120  _ (PKT_RX_IEEE1588_TMST, "RX IEEE1588 L2/L4 timestamped packet")
121 
122 #define foreach_dpdk_pkt_type \
123  _ (L2, ETHER, "Ethernet packet") \
124  _ (L2, ETHER_TIMESYNC, "Ethernet packet for time sync") \
125  _ (L2, ETHER_ARP, "ARP packet") \
126  _ (L2, ETHER_LLDP, "LLDP (Link Layer Discovery Protocol) packet") \
127  _ (L3, IPV4, "IPv4 packet without extension headers") \
128  _ (L3, IPV4_EXT, "IPv4 packet with extension headers") \
129  _ (L3, IPV4_EXT_UNKNOWN, "IPv4 packet with or without extension headers") \
130  _ (L3, IPV6, "IPv6 packet without extension headers") \
131  _ (L3, IPV6_EXT, "IPv6 packet with extension headers") \
132  _ (L3, IPV6_EXT_UNKNOWN, "IPv6 packet with or without extension headers") \
133  _ (L4, TCP, "TCP packet") \
134  _ (L4, UDP, "UDP packet") \
135  _ (L4, FRAG, "Fragmented IP packet") \
136  _ (L4, SCTP, "SCTP (Stream Control Transmission Protocol) packet") \
137  _ (L4, ICMP, "ICMP packet") \
138  _ (L4, NONFRAG, "Non-fragmented IP packet") \
139  _ (TUNNEL, GRE, "GRE tunneling packet") \
140  _ (TUNNEL, VXLAN, "VXLAN tunneling packet") \
141  _ (TUNNEL, NVGRE, "NVGRE Tunneling packet") \
142  _ (TUNNEL, GENEVE, "GENEVE Tunneling packet") \
143  _ (TUNNEL, GRENAT, "Teredo, VXLAN or GRE Tunneling packet") \
144  _ (INNER_L2, ETHER, "Inner Ethernet packet") \
145  _ (INNER_L2, ETHER_VLAN, "Inner Ethernet packet with VLAN") \
146  _ (INNER_L3, IPV4, "Inner IPv4 packet without extension headers") \
147  _ (INNER_L3, IPV4_EXT, "Inner IPv4 packet with extension headers") \
148  _ (INNER_L3, IPV4_EXT_UNKNOWN, "Inner IPv4 packet with or without extension headers") \
149  _ (INNER_L3, IPV6, "Inner IPv6 packet without extension headers") \
150  _ (INNER_L3, IPV6_EXT, "Inner IPv6 packet with extension headers") \
151  _ (INNER_L3, IPV6_EXT_UNKNOWN, "Inner IPv6 packet with or without extension headers") \
152  _ (INNER_L4, TCP, "Inner TCP packet") \
153  _ (INNER_L4, UDP, "Inner UDP packet") \
154  _ (INNER_L4, FRAG, "Inner fagmented IP packet") \
155  _ (INNER_L4, SCTP, "Inner SCTP (Stream Control Transmission Protocol) packet") \
156  _ (INNER_L4, ICMP, "Inner ICMP packet") \
157  _ (INNER_L4, NONFRAG, "Inner non-fragmented IP packet")
158 
159 #else
160 #define foreach_dpdk_pkt_rx_offload_flag \
161  _ (PKT_RX_VLAN_PKT, "RX packet is a 802.1q VLAN packet") \
162  _ (PKT_RX_RSS_HASH, "RX packet with RSS hash result") \
163  _ (PKT_RX_FDIR, "RX packet with FDIR infos") \
164  _ (PKT_RX_L4_CKSUM_BAD, "L4 cksum of RX pkt. is not OK") \
165  _ (PKT_RX_IP_CKSUM_BAD, "IP cksum of RX pkt. is not OK") \
166  _ (PKT_RX_IPV4_HDR, "RX packet with IPv4 header") \
167  _ (PKT_RX_IPV4_HDR_EXT, "RX packet with extended IPv4 header") \
168  _ (PKT_RX_IPV6_HDR, "RX packet with IPv6 header") \
169  _ (PKT_RX_IPV6_HDR_EXT, "RX packet with extended IPv6 header") \
170  _ (PKT_RX_IEEE1588_PTP, "RX IEEE1588 L2 Ethernet PT Packet") \
171  _ (PKT_RX_IEEE1588_TMST, "RX IEEE1588 L2/L4 timestamped packet")
172 
173 #define foreach_dpdk_pkt_type /* Dummy */
174 #endif /* RTE_VERSION */
175 
176 #define foreach_dpdk_pkt_tx_offload_flag \
177  _ (PKT_TX_VLAN_PKT, "TX packet is a 802.1q VLAN packet") \
178  _ (PKT_TX_IP_CKSUM, "IP cksum of TX pkt. computed by NIC") \
179  _ (PKT_TX_TCP_CKSUM, "TCP cksum of TX pkt. computed by NIC") \
180  _ (PKT_TX_SCTP_CKSUM, "SCTP cksum of TX pkt. computed by NIC") \
181  _ (PKT_TX_IEEE1588_TMST, "TX IEEE1588 packet to timestamp")
182 
183 #define foreach_dpdk_pkt_offload_flag \
184  foreach_dpdk_pkt_rx_offload_flag \
185  foreach_dpdk_pkt_tx_offload_flag
186 
187 #ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
188 #define foreach_dpdk_pkt_ext_rx_offload_flag \
189  _ (PKT_EXT_RX_PKT_ERROR, "RX Packet Error") \
190  _ (PKT_EXT_RX_BAD_FCS, "RX Bad FCS checksum") \
191  _ (PKT_EXT_RX_UDP, "RX packet with UDP L4 header") \
192  _ (PKT_EXT_RX_TCP, "RX packet with TCP L4 header") \
193  _ (PKT_EXT_RX_IPV4_FRAGMENT, "RX packet IPv4 Fragment")
194 
195 #define foreach_dpdk_pkt_ext_offload_flag \
196  foreach_dpdk_pkt_rx_offload_flag \
197  foreach_dpdk_pkt_ext_rx_offload_flag
198 
199 #endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
200 
201 u8 * format_dpdk_device_name (u8 * s, va_list * args)
202 {
203  dpdk_main_t * dm = &dpdk_main;
204  char *devname_format;
205  char *device_name;
206  u32 i = va_arg (*args, u32);
207  struct rte_eth_dev_info dev_info;
208  u8 * ret;
209 
211  devname_format = "%s%d/%d/%d";
212  else
213  devname_format = "%s%x/%x/%x";
214 
215 #ifdef RTE_LIBRTE_KNI
216  if (dm->devices[i].dev_type == VNET_DPDK_DEV_KNI) {
217  return format(s, "kni%d", dm->devices[i].kni_port_id);
218  } else
219 #endif
220  if (dm->devices[i].dev_type == VNET_DPDK_DEV_VHOST_USER) {
221  return format(s, "VirtualEthernet0/0/%d", dm->devices[i].vu_if_id);
222  }
223  switch (dm->devices[i].port_type)
224  {
226  device_name = "GigabitEthernet";
227  break;
228 
230  device_name = "TenGigabitEthernet";
231  break;
232 
234  device_name = "FortyGigabitEthernet";
235  break;
236 
238  return format(s, "BondEthernet%d", dm->devices[i].device_index);
239 
241  device_name = "EthernetSwitch";
242  break;
243 
244  #ifdef NETMAP
245  case VNET_DPDK_PORT_TYPE_NETMAP:
246  rte_eth_dev_info_get(i, &dev_info);
247  return format(s, "netmap:%s", dev_info.driver_name);
248  #endif
249 
251  rte_eth_dev_info_get(i, &dev_info);
252  return format(s, "af_packet%d", dm->devices[i].af_packet_port_id);
253 
254  default:
256  device_name = "UnknownEthernet";
257  break;
258  }
259 
260  rte_eth_dev_info_get(i, &dev_info);
261  ret = format (s, devname_format, device_name, dev_info.pci_dev->addr.bus,
262  dev_info.pci_dev->addr.devid,
263  dev_info.pci_dev->addr.function);
264 
265  /* address Chelsio cards which share PCI address */
266  if (dm->devices[i].pmd == VNET_DPDK_PMD_CXGBE) {
267  struct rte_eth_dev_info di;
268 
269  di.pci_dev = 0;
270  rte_eth_dev_info_get(i+1, &di);
271  if (di.pci_dev && memcmp(&dev_info.pci_dev->addr, &di.pci_dev->addr,
272  sizeof(struct rte_pci_addr)) == 0)
273  return format(ret, "/0");
274 
275  di.pci_dev = 0;
276  rte_eth_dev_info_get(i-1, &di);
277  if (di.pci_dev && memcmp(&dev_info.pci_dev->addr, &di.pci_dev->addr,
278  sizeof(struct rte_pci_addr)) == 0)
279  return format(ret, "/1");
280  }
281  return ret;
282 }
283 
284 static u8 * format_dpdk_device_type (u8 * s, va_list * args)
285 {
286  dpdk_main_t * dm = &dpdk_main;
287  char *dev_type;
288  u32 i = va_arg (*args, u32);
289 
290  if (dm->devices[i].dev_type == VNET_DPDK_DEV_KNI) {
291  return format(s, "Kernel NIC Interface");
292  } else if (dm->devices[i].dev_type == VNET_DPDK_DEV_VHOST_USER) {
293  return format(s, "vhost-user interface");
294  }
295 
296  switch (dm->devices[i].pmd)
297  {
298  case VNET_DPDK_PMD_E1000EM:
299  dev_type = "Intel 82540EM (e1000)";
300  break;
301 
302  case VNET_DPDK_PMD_IGB:
303  dev_type = "Intel e1000";
304  break;
305 
306  case VNET_DPDK_PMD_I40E:
307  dev_type = "Intel X710/XL710 Family";
308  break;
309 
310  case VNET_DPDK_PMD_I40EVF:
311  dev_type = "Intel X710/XL710 Family VF";
312  break;
313 
314  case VNET_DPDK_PMD_FM10K:
315  dev_type = "Intel FM10000 Family Ethernet Switch";
316  break;
317 
318  case VNET_DPDK_PMD_IGBVF:
319  dev_type = "Intel e1000 VF";
320  break;
321 
322  case VNET_DPDK_PMD_VIRTIO:
323  dev_type = "Red Hat Virtio";
324  break;
325 
326  case VNET_DPDK_PMD_IXGBEVF:
327  dev_type = "Intel 82599 VF";
328  break;
329 
330  case VNET_DPDK_PMD_IXGBE:
331  dev_type = "Intel 82599";
332  break;
333 
334  case VNET_DPDK_PMD_VICE:
335  case VNET_DPDK_PMD_ENIC:
336  dev_type = "Cisco VIC";
337  break;
338 
339  case VNET_DPDK_PMD_CXGBE:
340  dev_type = "Chelsio T4/T5";
341  break;
342 
343  case VNET_DPDK_PMD_VMXNET3:
344  dev_type = "VMware VMXNET3";
345  break;
346 
347 #ifdef NETMAP
348  case VNET_DPDK_PMD_NETMAP:
349  dev_type = "Netmap/Vale";
350  break;
351 #endif
352 
353  case VNET_DPDK_PMD_AF_PACKET:
354  dev_type = "af_packet";
355  break;
356 
357  case VNET_DPDK_PMD_BOND:
358  dev_type = "Ethernet Bonding";
359  break;
360 
361  default:
363  dev_type = "### UNKNOWN ###";
364  break;
365  }
366 
367  return format (s, dev_type);
368 }
369 
370 static u8 * format_dpdk_link_status (u8 * s, va_list * args)
371 {
372  dpdk_device_t * xd = va_arg (*args, dpdk_device_t *);
373  struct rte_eth_link * l = &xd->link;
374  vnet_main_t * vnm = vnet_get_main();
376 
377  s = format (s, "%s ", l->link_status ? "up" : "down");
378  if (l->link_status)
379  {
380  u32 promisc = rte_eth_promiscuous_get (xd->device_index);
381 
382  s = format (s, "%s duplex ", (l->link_duplex == ETH_LINK_FULL_DUPLEX) ?
383  "full" : "half");
384  s = format (s, "speed %u mtu %d %s\n", l->link_speed,
385  hi->max_packet_bytes, promisc ? " promisc" : "");
386  }
387  else
388  s = format (s, "\n");
389 
390  return s;
391 }
392 
393 #define _line_len 72
394 #define _(v, str) \
395 if (bitmap & v) { \
396  if (format_get_indent (s) > next_split ) { \
397  next_split += _line_len; \
398  s = format(s,"\n%U", format_white_space, indent); \
399  } \
400  s = format(s, "%s ", str); \
401 }
402 
403 static u8 * format_dpdk_rss_hf_name(u8 * s, va_list * args)
404 {
405  u64 bitmap = va_arg (*args, u64);
406  int next_split = _line_len;
407  int indent = format_get_indent (s);
408 
409  if (!bitmap)
410  return format(s, "none");
411 
413 
414  return s;
415 }
416 
417 static u8 * format_dpdk_rx_offload_caps(u8 * s, va_list * args)
418 {
419  u32 bitmap = va_arg (*args, u32);
420  int next_split = _line_len;
421  int indent = format_get_indent (s);
422 
423  if (!bitmap)
424  return format(s, "none");
425 
427 
428  return s;
429 }
430 
431 static u8 * format_dpdk_tx_offload_caps(u8 * s, va_list * args)
432 {
433  u32 bitmap = va_arg (*args, u32);
434  int next_split = _line_len;
435  int indent = format_get_indent (s);
436  if (!bitmap)
437  return format(s, "none");
438 
440 
441  return s;
442 }
443 
444 #undef _line_len
445 #undef _
446 
447 u8 * format_dpdk_device (u8 * s, va_list * args)
448 {
449  u32 dev_instance = va_arg (*args, u32);
450  int verbose = va_arg (*args, int);
451  dpdk_main_t * dm = &dpdk_main;
452  dpdk_device_t * xd = vec_elt_at_index (dm->devices, dev_instance);
453  uword indent = format_get_indent (s);
454  f64 now = vlib_time_now (dm->vlib_main);
455 
456  dpdk_update_counters (xd, now);
457  dpdk_update_link_state (xd, now);
458 
459  s = format (s, "%U\n%Ucarrier %U",
461  format_white_space, indent + 2,
463 
464  if (verbose > 1 && xd->dev_type == VNET_DPDK_DEV_ETH)
465  {
466  struct rte_eth_dev_info di;
467  struct rte_pci_device * pci;
468  struct rte_eth_rss_conf rss_conf;
469  int vlan_off;
470 
471  rss_conf.rss_key = 0;
472  rte_eth_dev_info_get(xd->device_index, &di);
473  rte_eth_dev_rss_hash_conf_get(xd->device_index, &rss_conf);
474  pci = di.pci_dev;
475 
476  if (pci)
477  s = format(s, "%Upci id: device %04x:%04x subsystem %04x:%04x\n"
478  "%Upci address: %04x:%02x:%02x.%02x\n",
479  format_white_space, indent + 2,
480  pci->id.vendor_id, pci->id.device_id,
481  pci->id.subsystem_vendor_id,
482  pci->id.subsystem_device_id,
483  format_white_space, indent + 2,
484  pci->addr.domain, pci->addr.bus,
485  pci->addr.devid, pci->addr.function);
486  s = format(s, "%Umax rx packet len: %d\n",
487  format_white_space, indent + 2, di.max_rx_pktlen);
488  s = format(s, "%Upromiscuous: unicast %s all-multicast %s\n",
489  format_white_space, indent + 2,
490  rte_eth_promiscuous_get(xd->device_index) ? "on" : "off",
491  rte_eth_promiscuous_get(xd->device_index) ? "on" : "off");
492  vlan_off = rte_eth_dev_get_vlan_offload(xd->device_index);
493  s = format(s, "%Uvlan offload: strip %s filter %s qinq %s\n",
494  format_white_space, indent + 2,
495  vlan_off & ETH_VLAN_STRIP_OFFLOAD ? "on" : "off",
496  vlan_off & ETH_VLAN_FILTER_OFFLOAD ? "on" : "off",
497  vlan_off & ETH_VLAN_EXTEND_OFFLOAD ? "on" : "off");
498  s = format(s, "%Uqueue size (max): rx %d (%d) tx %d (%d)\n",
499  format_white_space, indent + 2,
500  xd->rx_q_used, di.max_rx_queues,
501  xd->tx_q_used, di.max_tx_queues);
502  s = format(s, "%Urx offload caps: %U\n",
503  format_white_space, indent + 2,
504  format_dpdk_rx_offload_caps, di.rx_offload_capa);
505  s = format(s, "%Utx offload caps: %U\n",
506  format_white_space, indent + 2,
507  format_dpdk_tx_offload_caps, di.tx_offload_capa);
508  s = format(s, "%Urss active: %U\n"
509  "%Urss supported: %U\n",
510  format_white_space, indent + 2,
511  format_dpdk_rss_hf_name, rss_conf.rss_hf,
512  format_white_space, indent + 2,
513  format_dpdk_rss_hf_name, di.flow_type_rss_offloads);
514  }
515 
516  if (verbose && xd->dev_type == VNET_DPDK_DEV_VHOST_USER) {
517  s = format(s, "%Uqueue size (max): rx %d (%d) tx %d (%d)\n",
518  format_white_space, indent + 2,
519  xd->rx_q_used, xd->rx_q_used,
520  xd->tx_q_used, xd->tx_q_used);
521  }
522 
523  if (xd->cpu_socket > -1)
524  s = format (s, "%Ucpu socket %d",
525  format_white_space, indent + 2,
526  xd->cpu_socket);
527 
528  /* $$$ MIB counters */
529 
530  {
531 #define _(N, V) \
532  if ((xd->stats.V - xd->last_cleared_stats.V) != 0) { \
533  s = format (s, "\n%U%-40U%16Ld", \
534  format_white_space, indent + 2, \
535  format_c_identifier, #N, \
536  xd->stats.V - xd->last_cleared_stats.V); \
537  } \
538 
540 #undef _
541  }
542 
543  u8 * xs = 0;
544  u32 i = 0;
545 
547 
548  vec_foreach_index(i, xd->xstats)
549  {
550  u64 delta = 0;
551  struct rte_eth_xstats* xstat = vec_elt_at_index(xd->xstats, i);
552  struct rte_eth_xstats* last_xstat =
554 
555  delta = xstat->value - last_xstat->value;
556  if (verbose == 2 || (verbose && delta))
557  {
558  /* format_c_identifier doesn't like c strings inside vector */
559  u8 * name = format(0,"%s", xstat->name);
560  xs = format(xs, "\n%U%-38U%16Ld",
561  format_white_space, indent + 4,
562  format_c_identifier, name, delta);
563  vec_free(name);
564  }
565  }
566 
567  if (verbose && xd->dev_type == VNET_DPDK_DEV_VHOST_USER) {
568  int i;
569  for (i = 0; i < xd->rx_q_used * VIRTIO_QNUM; i++) {
570  u8 * name;
571  if (verbose == 2 || xd->vu_intf->vrings[i].packets) {
572  if (i & 1) {
573  name = format(NULL, "tx q%d packets", i >> 1);
574  } else {
575  name = format(NULL, "rx q%d packets", i >> 1);
576  }
577  xs = format(xs, "\n%U%-38U%16Ld",
578  format_white_space, indent + 4,
579  format_c_identifier, name, xd->vu_intf->vrings[i].packets);
580  vec_free(name);
581 
582  if (i & 1) {
583  name = format(NULL, "tx q%d bytes", i >> 1);
584  } else {
585  name = format(NULL, "rx q%d bytes", i >> 1);
586  }
587  xs = format(xs, "\n%U%-38U%16Ld",
588  format_white_space, indent + 4,
589  format_c_identifier, name, xd->vu_intf->vrings[i].bytes);
590  vec_free(name);
591  }
592  }
593  }
594 
595  if (xs)
596  {
597  s = format(s, "\n%Uextended stats:%v",
598  format_white_space, indent + 2, xs);
599  vec_free(xs);
600  }
601 
602  return s;
603 }
604 
605 u8 * format_dpdk_tx_dma_trace (u8 * s, va_list * va)
606 {
607  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
608  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
610  dpdk_tx_dma_trace_t * t = va_arg (*va, dpdk_tx_dma_trace_t *);
611  dpdk_main_t * dm = &dpdk_main;
613  uword indent = format_get_indent (s);
615 
616  s = format (s, "%U tx queue %d",
618  t->queue_index);
619 
620  s = format (s, "\n%Ubuffer 0x%x: %U",
621  format_white_space, indent,
622  t->buffer_index,
624 
625  s = format (s, "\n%U%U", format_white_space, indent,
627  sizeof (t->buffer.pre_data));
628 
629  return s;
630 }
631 
632 u8 * format_dpdk_rx_dma_trace (u8 * s, va_list * va)
633 {
634  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
635  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
637  dpdk_rx_dma_trace_t * t = va_arg (*va, dpdk_rx_dma_trace_t *);
638  dpdk_main_t * dm = &dpdk_main;
640  format_function_t * f;
641  uword indent = format_get_indent (s);
643 
644  s = format (s, "%U rx queue %d",
646  t->queue_index);
647 
648  s = format (s, "\n%Ubuffer 0x%x: %U",
649  format_white_space, indent,
650  t->buffer_index,
652 
653 #ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
654  s = format (s, "\n%U%U",
655  format_white_space, indent,
657 #else
658  s = format (s, "\n%U%U",
659  format_white_space, indent,
660  format_dpdk_rte_mbuf, &t->mb);
661 #endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
662  f = node->format_buffer;
663  if (!f)
664  f = format_hex_bytes;
665  s = format (s, "\n%U%U", format_white_space, indent,
666  f, t->buffer.pre_data, sizeof (t->buffer.pre_data));
667 
668  return s;
669 }
670 
671 
672 static inline u8 * format_dpdk_pkt_types (u8 * s, va_list * va)
673 {
674  u32 *pkt_types = va_arg (*va, u32 *);
675  uword indent __attribute__((unused)) = format_get_indent (s) + 2;
676 
677  if (!*pkt_types)
678  return s;
679 
680  s = format (s, "Packet Types");
681 
682 #define _(L, F, S) \
683  if ((*pkt_types & RTE_PTYPE_##L##_MASK) == RTE_PTYPE_##L##_##F) \
684  { \
685  s = format (s, "\n%U%s (0x%04x) %s", format_white_space, indent, \
686  "RTE_PTYPE_" #L "_" #F, RTE_PTYPE_##L##_##F, S); \
687  }
688 
690 
691 #undef _
692 
693  return s;
694 }
695 
696 static inline u8 * format_dpdk_pkt_offload_flags (u8 * s, va_list * va)
697 {
698  u16 *ol_flags = va_arg (*va, u16 *);
699  uword indent = format_get_indent (s) + 2;
700 
701  if (!*ol_flags)
702  return s;
703 
704  s = format (s, "Packet Offload Flags");
705 
706 #define _(F, S) \
707  if (*ol_flags & F) \
708  { \
709  s = format (s, "\n%U%s (0x%04x) %s", \
710  format_white_space, indent, #F, F, S); \
711  }
712 
714 
715 #undef _
716 
717  return s;
718 }
719 
720 u8 * format_dpdk_rte_mbuf (u8 * s, va_list * va)
721 {
722  struct rte_mbuf * mb = va_arg (*va, struct rte_mbuf *);
723  uword indent = format_get_indent (s) + 2;
724 
725  s = format (s, "PKT MBUF: port %d, nb_segs %d, pkt_len %d"
726  "\n%Ubuf_len %d, data_len %d, ol_flags 0x%x,"
727  "\n%Upacket_type 0x%x",
728  mb->port, mb->nb_segs, mb->pkt_len,
729  format_white_space, indent,
730  mb->buf_len, mb->data_len, mb->ol_flags,
731  format_white_space, indent,
732  mb->packet_type);
733 
734  if (mb->ol_flags)
735  s = format (s, "\n%U%U", format_white_space, indent,
736  format_dpdk_pkt_offload_flags, &mb->ol_flags);
737 
738  if (mb->packet_type)
739  s = format (s, "\n%U%U", format_white_space, indent,
740  format_dpdk_pkt_types, &mb->packet_type);
741  return s;
742 }
743 
744 #ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
745 
746 static inline u8 * format_dpdk_pkt_rx_offload_flags (u8 * s, va_list * va)
747 {
748  u16 *ol_flags = va_arg (*va, u16 *);
749  uword indent = format_get_indent (s) + 2;
750 
751  if (!*ol_flags)
752  return s;
753 
754  s = format (s, "Packet RX Offload Flags");
755 
756 #define _(F, S) \
757  if (*ol_flags & F) \
758  { \
759  s = format (s, "\n%U%s (0x%04x) %s", \
760  format_white_space, indent, #F, F, S); \
761  }
762 
763  foreach_dpdk_pkt_ext_offload_flag
764 
765 #undef _
766 
767  return s;
768 }
769 
770 u8 * format_dpdk_rx_rte_mbuf (u8 * s, va_list * va)
771 {
772  struct rte_mbuf * mb = va_arg (*va, struct rte_mbuf *);
773  uword indent = format_get_indent (s) + 2;
774 
775  /*
776  * Note: Assumes mb is head of pkt chain -- port, nb_segs, & pkt_len
777  * are only valid for the 1st mbuf segment.
778  */
779  s = format (s, "PKT MBUF: port %d, nb_segs %d, pkt_len %d"
780  "\n%Ubuf_len %d, data_len %d, ol_flags 0x%x"
781  "\n%Upacket_type 0x%x",
782  mb->port, mb->nb_segs, mb->pkt_len,
783  format_white_space, indent,
784  mb->buf_len, mb->data_len, mb->ol_flags,
785  format_white_space, indent,
786  mb->packet_type);
787 
788  if (mb->ol_flags)
789  s = format (s, "\n%U%U", format_white_space, indent,
790  format_dpdk_pkt_rx_offload_flags, &mb->ol_flags);
791 
792  if (mb->packet_type)
793  s = format (s, "\n%U%U", format_white_space, indent,
794  format_dpdk_pkt_types, &mb->packet_type);
795  return s;
796 }
797 #endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
798 
799 uword
800 unformat_socket_mem (unformat_input_t * input, va_list * va)
801 {
802  uword ** r = va_arg (* va, uword **);
803  int i = 0;
804  u32 mem;
805 
807  {
808  if (unformat (input, ","))
809  hash_set (*r, i, 1024);
810  else if (unformat (input, "%u,", &mem))
811  hash_set (*r, i, mem);
812  else if (unformat (input, "%u", &mem))
813  hash_set (*r, i, mem);
814  else
815  {
816  unformat_put_input (input);
817  goto done;
818  }
819  i++;
820  }
821 
822 done:
823  return 1;
824 }
#define foreach_dpdk_pkt_offload_flag
Definition: format.c:183
vmrglw vmrglh hi
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define hash_set(h, key, value)
Definition: hash.h:237
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:267
#define CLIB_UNUSED(x)
Definition: clib.h:79
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:942
vlib_buffer_t buffer
Definition: dpdk.h:432
dpdk_main_t dpdk_main
Definition: dpdk.h:415
format_function_t format_vlib_buffer
Definition: buffer_funcs.h:516
#define UNFORMAT_END_OF_INPUT
Definition: format.h:142
#define NULL
Definition: clib.h:55
u8 * format_c_identifier(u8 *s, va_list *va)
Definition: std-formats.c:239
u8 * format_dpdk_tx_dma_trace(u8 *s, va_list *va)
Definition: format.c:605
u64 packets
Definition: dpdk.h:149
u8 * format_ethernet_header_with_length(u8 *s, va_list *args)
Definition: format.c:70
static u8 * format_dpdk_device_type(u8 *s, va_list *args)
Definition: format.c:284
always_inline uword unformat_check_input(unformat_input_t *i)
Definition: format.h:168
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
static u8 * format_dpdk_rx_offload_caps(u8 *s, va_list *args)
Definition: format.c:417
static u8 * format_dpdk_pkt_offload_flags(u8 *s, va_list *va)
Definition: format.c:696
dpdk_vu_vring vrings[VHOST_MAX_QUEUE_PAIRS *2]
Definition: dpdk.h:166
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:107
#define foreach_dpdk_rx_offload_caps
Definition: format.c:92
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u8 * format_hex_bytes(u8 *s, va_list *va)
Definition: std-formats.c:79
u16 rx_q_used
Definition: dpdk.h:225
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
Definition: buffer.h:142
unsigned long u64
Definition: types.h:89
#define foreach_dpdk_pkt_type
Definition: format.c:122
format_function_t format_dpdk_rx_rte_mbuf
Definition: dpdk.h:601
u32 device_index
Definition: dpdk.h:193
struct rte_eth_xstats * last_cleared_xstats
Definition: dpdk.h:252
#define foreach_dpdk_counter
Definition: format.c:28
struct rte_mbuf mb
Definition: dpdk.h:439
u32 vlib_sw_if_index
Definition: dpdk.h:196
format_function_t format_vnet_sw_interface_name
u32 vlib_hw_if_index
Definition: dpdk.h:195
static u8 * format_dpdk_rss_hf_name(u8 *s, va_list *args)
Definition: format.c:403
#define foreach_dpdk_rss_hf
Definition: format.c:74
u64 bytes
Definition: dpdk.h:150
dpdk_port_type_t port_type
Definition: dpdk.h:254
format_function_t * format_buffer
Definition: node.h:277
u16 tx_q_used
Definition: dpdk.h:224
static u8 * format_dpdk_link_status(u8 *s, va_list *args)
Definition: format.c:370
u8 * format_dpdk_device_name(u8 *s, va_list *args)
Definition: format.c:201
static u8 * format_dpdk_pkt_types(u8 *s, va_list *va)
Definition: format.c:672
dpdk_device_t * devices
Definition: dpdk.h:316
static void dpdk_update_counters(dpdk_device_t *xd, f64 now)
Definition: dpdk_priv.h:167
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:298
dpdk_pmd_t pmd
Definition: dpdk.h:215
always_inline vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u8 * format_dpdk_rte_mbuf(u8 *s, va_list *va)
Definition: format.c:720
u32 vu_if_id
Definition: dpdk.h:237
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:405
u8 af_packet_port_id
Definition: dpdk.h:243
void dpdk_update_link_state(dpdk_device_t *xd, f64 now)
Definition: init.c:1243
struct rte_eth_link link
Definition: dpdk.h:245
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
uword unformat_socket_mem(unformat_input_t *input, va_list *va)
Definition: format.c:800
always_inline uword format_get_indent(u8 *s)
Definition: format.h:72
u64 uword
Definition: types.h:112
u8 kni_port_id
Definition: dpdk.h:234
unsigned short u16
Definition: types.h:57
u8 interface_name_format_decimal
Definition: dpdk.h:335
vlib_buffer_t buffer
Definition: dpdk.h:440
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:140
dpdk_device_type_t dev_type
Definition: dpdk.h:214
unsigned char u8
Definition: types.h:56
always_inline vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
struct rte_eth_xstats * xstats
Definition: dpdk.h:251
static u8 * format_dpdk_tx_offload_caps(u8 *s, va_list *args)
Definition: format.c:431
u8 * format_dpdk_rx_dma_trace(u8 *s, va_list *va)
Definition: format.c:632
always_inline void unformat_put_input(unformat_input_t *input)
Definition: format.h:203
i8 cpu_socket
Definition: dpdk.h:216
always_inline f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:182
dpdk_vu_intf_t * vu_intf
Definition: dpdk.h:240
struct _unformat_input_t unformat_input_t
u8 * format_dpdk_device(u8 *s, va_list *args)
Definition: format.c:447
#define foreach_dpdk_tx_offload_caps
Definition: format.c:100
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
vlib_main_t * vlib_main
Definition: dpdk.h:411