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