FD.io VPP  v20.01-48-g3e0dafb74
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 #define __USE_GNU
22 #include <dlfcn.h>
23 
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/ethernet/sfp.h>
26 #include <dpdk/device/dpdk.h>
27 
28 #include <dpdk/device/dpdk_priv.h>
29 #include <vppinfra/error.h>
30 
31 #define foreach_dpdk_counter \
32  _ (tx_frames_ok, opackets) \
33  _ (tx_bytes_ok, obytes) \
34  _ (tx_errors, oerrors) \
35  _ (rx_frames_ok, ipackets) \
36  _ (rx_bytes_ok, ibytes) \
37  _ (rx_errors, ierrors) \
38  _ (rx_missed, imissed) \
39  _ (rx_no_bufs, rx_nombuf)
40 
41 #define foreach_dpdk_q_counter \
42  _ (rx_frames_ok, q_ipackets) \
43  _ (tx_frames_ok, q_opackets) \
44  _ (rx_bytes_ok, q_ibytes) \
45  _ (tx_bytes_ok, q_obytes) \
46  _ (rx_errors, q_errors)
47 
48 #define foreach_dpdk_rss_hf \
49  _(ETH_RSS_FRAG_IPV4, "ipv4-frag") \
50  _(ETH_RSS_NONFRAG_IPV4_TCP, "ipv4-tcp") \
51  _(ETH_RSS_NONFRAG_IPV4_UDP, "ipv4-udp") \
52  _(ETH_RSS_NONFRAG_IPV4_SCTP, "ipv4-sctp") \
53  _(ETH_RSS_NONFRAG_IPV4_OTHER, "ipv4-other") \
54  _(ETH_RSS_IPV4, "ipv4") \
55  _(ETH_RSS_IPV6_TCP_EX, "ipv6-tcp-ex") \
56  _(ETH_RSS_IPV6_UDP_EX, "ipv6-udp-ex") \
57  _(ETH_RSS_FRAG_IPV6, "ipv6-frag") \
58  _(ETH_RSS_NONFRAG_IPV6_TCP, "ipv6-tcp") \
59  _(ETH_RSS_NONFRAG_IPV6_UDP, "ipv6-udp") \
60  _(ETH_RSS_NONFRAG_IPV6_SCTP, "ipv6-sctp") \
61  _(ETH_RSS_NONFRAG_IPV6_OTHER, "ipv6-other") \
62  _(ETH_RSS_IPV6_EX, "ipv6-ex") \
63  _(ETH_RSS_IPV6, "ipv6") \
64  _(ETH_RSS_L2_PAYLOAD, "l2-payload") \
65  _(ETH_RSS_PORT, "port") \
66  _(ETH_RSS_VXLAN, "vxlan") \
67  _(ETH_RSS_GENEVE, "geneve") \
68  _(ETH_RSS_NVGRE, "nvgre")
69 
70 #define foreach_dpdk_pkt_rx_offload_flag \
71  _ (PKT_RX_VLAN, "RX packet is a 802.1q VLAN packet") \
72  _ (PKT_RX_RSS_HASH, "RX packet with RSS hash result") \
73  _ (PKT_RX_FDIR, "RX packet with FDIR infos") \
74  _ (PKT_RX_L4_CKSUM_BAD, "L4 cksum of RX pkt. is not OK") \
75  _ (PKT_RX_IP_CKSUM_BAD, "IP cksum of RX pkt. is not OK") \
76  _ (PKT_RX_EIP_CKSUM_BAD, "External IP header checksum error") \
77  _ (PKT_RX_VLAN_STRIPPED, "RX packet VLAN tag stripped") \
78  _ (PKT_RX_IP_CKSUM_GOOD, "IP cksum of RX pkt. is valid") \
79  _ (PKT_RX_L4_CKSUM_GOOD, "L4 cksum of RX pkt. is valid") \
80  _ (PKT_RX_IEEE1588_PTP, "RX IEEE1588 L2 Ethernet PT Packet") \
81  _ (PKT_RX_IEEE1588_TMST, "RX IEEE1588 L2/L4 timestamped packet") \
82  _ (PKT_RX_QINQ_STRIPPED, "RX packet QinQ tags stripped") \
83  _ (PKT_RX_TIMESTAMP, "Timestamp field is valid")
84 
85 #define foreach_dpdk_pkt_type \
86  _ (L2, ETHER, "Ethernet packet") \
87  _ (L2, ETHER_TIMESYNC, "Ethernet packet for time sync") \
88  _ (L2, ETHER_ARP, "ARP packet") \
89  _ (L2, ETHER_LLDP, "LLDP (Link Layer Discovery Protocol) packet") \
90  _ (L2, ETHER_NSH, "NSH (Network Service Header) packet") \
91  _ (L2, ETHER_VLAN, "VLAN packet") \
92  _ (L2, ETHER_QINQ, "QinQ packet") \
93  _ (L3, IPV4, "IPv4 packet without extension headers") \
94  _ (L3, IPV4_EXT, "IPv4 packet with extension headers") \
95  _ (L3, IPV4_EXT_UNKNOWN, "IPv4 packet with or without extension headers") \
96  _ (L3, IPV6, "IPv6 packet without extension headers") \
97  _ (L3, IPV6_EXT, "IPv6 packet with extension headers") \
98  _ (L3, IPV6_EXT_UNKNOWN, "IPv6 packet with or without extension headers") \
99  _ (L4, TCP, "TCP packet") \
100  _ (L4, UDP, "UDP packet") \
101  _ (L4, FRAG, "Fragmented IP packet") \
102  _ (L4, SCTP, "SCTP (Stream Control Transmission Protocol) packet") \
103  _ (L4, ICMP, "ICMP packet") \
104  _ (L4, NONFRAG, "Non-fragmented IP packet") \
105  _ (TUNNEL, GRE, "GRE tunneling packet") \
106  _ (TUNNEL, VXLAN, "VXLAN tunneling packet") \
107  _ (TUNNEL, NVGRE, "NVGRE Tunneling packet") \
108  _ (TUNNEL, GENEVE, "GENEVE Tunneling packet") \
109  _ (TUNNEL, GRENAT, "Teredo, VXLAN or GRE Tunneling packet") \
110  _ (INNER_L2, ETHER, "Inner Ethernet packet") \
111  _ (INNER_L2, ETHER_VLAN, "Inner Ethernet packet with VLAN") \
112  _ (INNER_L3, IPV4, "Inner IPv4 packet without extension headers") \
113  _ (INNER_L3, IPV4_EXT, "Inner IPv4 packet with extension headers") \
114  _ (INNER_L3, IPV4_EXT_UNKNOWN, "Inner IPv4 packet with or without extension headers") \
115  _ (INNER_L3, IPV6, "Inner IPv6 packet without extension headers") \
116  _ (INNER_L3, IPV6_EXT, "Inner IPv6 packet with extension headers") \
117  _ (INNER_L3, IPV6_EXT_UNKNOWN, "Inner IPv6 packet with or without extension headers") \
118  _ (INNER_L4, TCP, "Inner TCP packet") \
119  _ (INNER_L4, UDP, "Inner UDP packet") \
120  _ (INNER_L4, FRAG, "Inner fragmented IP packet") \
121  _ (INNER_L4, SCTP, "Inner SCTP (Stream Control Transmission Protocol) packet") \
122  _ (INNER_L4, ICMP, "Inner ICMP packet") \
123  _ (INNER_L4, NONFRAG, "Inner non-fragmented IP packet")
124 
125 #define foreach_dpdk_pkt_tx_offload_flag \
126  _ (PKT_TX_VLAN_PKT, "TX packet is a 802.1q VLAN packet") \
127  _ (PKT_TX_IP_CKSUM, "IP cksum of TX pkt. computed by NIC") \
128  _ (PKT_TX_TCP_CKSUM, "TCP cksum of TX pkt. computed by NIC") \
129  _ (PKT_TX_SCTP_CKSUM, "SCTP cksum of TX pkt. computed by NIC") \
130  _ (PKT_TX_IEEE1588_TMST, "TX IEEE1588 packet to timestamp")
131 
132 #define foreach_dpdk_pkt_offload_flag \
133  foreach_dpdk_pkt_rx_offload_flag \
134  foreach_dpdk_pkt_tx_offload_flag
135 
136 u8 *
137 format_dpdk_device_name (u8 * s, va_list * args)
138 {
139  dpdk_main_t *dm = &dpdk_main;
140  char *devname_format;
141  char *device_name;
142  u32 i = va_arg (*args, u32);
143  dpdk_device_t *xd = vec_elt_at_index (dm->devices, i);
144  struct rte_eth_dev_info dev_info;
145  struct rte_pci_device *pci_dev;
146  u8 *ret;
147 
148  if (xd->name)
149  return format (s, "%s", xd->name);
150 
152  devname_format = "%s%d/%d/%d";
153  else
154  devname_format = "%s%x/%x/%x";
155 
156  switch (xd->port_type)
157  {
159  device_name = "GigabitEthernet";
160  break;
161 
163  device_name = "Two_FiveGigabitEthernet";
164  break;
165 
167  device_name = "FiveGigabitEthernet";
168  break;
169 
171  device_name = "TenGigabitEthernet";
172  break;
173 
175  device_name = "TwentyGigabitEthernet";
176  break;
177 
179  device_name = "TwentyFiveGigabitEthernet";
180  break;
181 
183  device_name = "FortyGigabitEthernet";
184  break;
185 
187  device_name = "FiftyGigabitEthernet";
188  break;
189 
191  device_name = "FiftySixGigabitEthernet";
192  break;
193 
195  device_name = "HundredGigabitEthernet";
196  break;
197 
199  device_name = "EthernetSwitch";
200  break;
201 
203  device_name = "VirtualFunctionEthernet";
204  break;
205 
207  return format (s, "af_packet%d", xd->af_packet_instance_num);
208 
210  device_name = "VirtioUser";
211  break;
212 
214  device_name = "VhostEthernet";
215  break;
216 
218  device_name = "FailsafeEthernet";
219  break;
220 
221  default:
223  device_name = "UnknownEthernet";
224  break;
225  }
226 
227  rte_eth_dev_info_get (xd->port_id, &dev_info);
228  pci_dev = dpdk_get_pci_device (&dev_info);
229 
230  if (pci_dev && xd->port_type != VNET_DPDK_PORT_TYPE_FAILSAFE)
231  ret = format (s, devname_format, device_name, pci_dev->addr.bus,
232  pci_dev->addr.devid, pci_dev->addr.function);
233  else
234  ret = format (s, "%s%d", device_name, xd->port_id);
235 
236  if (xd->interface_name_suffix)
237  return format (ret, "/%s", xd->interface_name_suffix);
238  return ret;
239 }
240 
241 u8 *
242 format_dpdk_device_flags (u8 * s, va_list * args)
243 {
244  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
245  u8 *t = 0;
246 
247 #define _(a, b, c) if (xd->flags & (1 << a)) \
248 t = format (t, "%s%s", t ? " ":"", c);
250 #undef _
251  s = format (s, "%v", t);
252  vec_free (t);
253  return s;
254 }
255 
256 static u8 *
257 format_dpdk_device_type (u8 * s, va_list * args)
258 {
259  dpdk_main_t *dm = &dpdk_main;
260  char *dev_type;
261  u32 i = va_arg (*args, u32);
262 
263  switch (dm->devices[i].pmd)
264  {
265  case VNET_DPDK_PMD_E1000EM:
266  dev_type = "Intel 82540EM (e1000)";
267  break;
268 
269  case VNET_DPDK_PMD_IGB:
270  dev_type = "Intel e1000";
271  break;
272 
273  case VNET_DPDK_PMD_I40E:
274  dev_type = "Intel X710/XL710 Family";
275  break;
276 
277  case VNET_DPDK_PMD_I40EVF:
278  dev_type = "Intel X710/XL710 Family VF";
279  break;
280 
281  case VNET_DPDK_PMD_ICE:
282  dev_type = "Intel E810 Family";
283  break;
284 
285  case VNET_DPDK_PMD_FM10K:
286  dev_type = "Intel FM10000 Family Ethernet Switch";
287  break;
288 
289  case VNET_DPDK_PMD_IGBVF:
290  dev_type = "Intel e1000 VF";
291  break;
292 
293  case VNET_DPDK_PMD_VIRTIO:
294  dev_type = "Red Hat Virtio";
295  break;
296 
297  case VNET_DPDK_PMD_IXGBEVF:
298  dev_type = "Intel 82599 VF";
299  break;
300 
301  case VNET_DPDK_PMD_IXGBE:
302  dev_type = "Intel 82599";
303  break;
304 
305  case VNET_DPDK_PMD_ENIC:
306  dev_type = "Cisco VIC";
307  break;
308 
309  case VNET_DPDK_PMD_CXGBE:
310  dev_type = "Chelsio T4/T5";
311  break;
312 
313  case VNET_DPDK_PMD_MLX4:
314  dev_type = "Mellanox ConnectX-3 Family";
315  break;
316 
317  case VNET_DPDK_PMD_MLX5:
318  dev_type = "Mellanox ConnectX-4 Family";
319  break;
320 
321  case VNET_DPDK_PMD_VMXNET3:
322  dev_type = "VMware VMXNET3";
323  break;
324 
325  case VNET_DPDK_PMD_AF_PACKET:
326  dev_type = "af_packet";
327  break;
328 
329  case VNET_DPDK_PMD_DPAA2:
330  dev_type = "NXP DPAA2 Mac";
331  break;
332 
333  case VNET_DPDK_PMD_VIRTIO_USER:
334  dev_type = "Virtio User";
335  break;
336 
337  case VNET_DPDK_PMD_THUNDERX:
338  dev_type = "Cavium ThunderX";
339  break;
340 
341  case VNET_DPDK_PMD_VHOST_ETHER:
342  dev_type = "VhostEthernet";
343  break;
344 
345  case VNET_DPDK_PMD_ENA:
346  dev_type = "AWS ENA VF";
347  break;
348 
349  case VNET_DPDK_PMD_FAILSAFE:
350  dev_type = "FailsafeEthernet";
351  break;
352 
353  case VNET_DPDK_PMD_LIOVF_ETHER:
354  dev_type = "Cavium Lio VF";
355  break;
356 
357  case VNET_DPDK_PMD_QEDE:
358  dev_type = "Cavium QLogic FastLinQ QL4xxxx";
359  break;
360 
361  case VNET_DPDK_PMD_NETVSC:
362  dev_type = "Microsoft Hyper-V Netvsc";
363  break;
364 
365  case VNET_DPDK_PMD_BNXT:
366  dev_type = "Broadcom NetXtreme E/S-Series";
367  break;
368 
369  default:
371  dev_type = "### UNKNOWN ###";
372  break;
373  }
374 
375  return format (s, dev_type);
376 }
377 
378 static u8 *
379 format_dpdk_link_status (u8 * s, va_list * args)
380 {
381  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
382  struct rte_eth_link *l = &xd->link;
383  vnet_main_t *vnm = vnet_get_main ();
385 
386  s = format (s, "%s ", l->link_status ? "up" : "down");
387  if (l->link_status)
388  {
389  u32 promisc = rte_eth_promiscuous_get (xd->port_id);
390 
391  s = format (s, "%s duplex ", (l->link_duplex == ETH_LINK_FULL_DUPLEX) ?
392  "full" : "half");
393  s = format (s, "mtu %d %s\n", hi->max_packet_bytes, promisc ?
394  " promisc" : "");
395  }
396  else
397  s = format (s, "\n");
398 
399  return s;
400 }
401 
402 #define _(v, str) \
403 if (bitmap & v) { \
404  if (format_get_indent (s) > 72) \
405  s = format(s,"\n%U", format_white_space, indent); \
406  s = format(s, "%s ", str); \
407 }
408 
409 u8 *
410 format_dpdk_rss_hf_name (u8 * s, va_list * args)
411 {
412  u64 bitmap = va_arg (*args, u64);
413  u32 indent = format_get_indent (s);
414 
415  if (!bitmap)
416  return format (s, "none");
417 
418  foreach_dpdk_rss_hf return s;
419 }
420 
421 #undef _
422 
423 /* Convert to all lower case e.g "VLAN_STRIP" -> "vlan-strip"
424  Works for both vector names and null terminated c strings. */
425 static u8 *
426 format_offload (u8 * s, va_list * va)
427 {
428  u8 *id = va_arg (*va, u8 *);
429  uword i, l;
430 
431  l = ~0;
432  if (clib_mem_is_vec (id))
433  l = vec_len (id);
434 
435  if (id)
436  for (i = 0; id[i] != 0 && i < l; i++)
437  {
438  u8 c = id[i];
439 
440  if (c == '_')
441  c = '-';
442  else
443  c = tolower (c);
444  vec_add1 (s, c);
445  }
446 
447  return s;
448 }
449 
450 #define _(v, func) \
451 if (bitmap & v) { \
452  if (format_get_indent (s) > 72) \
453  s = format(s,"\n%U", format_white_space, indent); \
454  s = format(s, "%U ", format_offload, func (v)); \
455 }
456 
457 u8 *
458 format_dpdk_rx_offload_caps (u8 * s, va_list * args)
459 {
460  u64 bitmap = va_arg (*args, u32);
461  u32 indent = format_get_indent (s);
462  uword i;
463 
464  if (!bitmap)
465  return format (s, "none");
466 
467  for (i = 0; i < 64; i++)
468  {
469  u64 mask = (u64) 1 << i;
470 
471  _(mask, rte_eth_dev_rx_offload_name);
472  }
473  return s;
474 }
475 
476 u8 *
477 format_dpdk_tx_offload_caps (u8 * s, va_list * args)
478 {
479  u64 bitmap = va_arg (*args, u32);
480  u32 indent = format_get_indent (s);
481  uword i;
482 
483  if (!bitmap)
484  return format (s, "none");
485 
486  for (i = 0; i < 64; i++)
487  {
488  u64 mask = (u64) 1 << i;
489 
490  _(mask, rte_eth_dev_tx_offload_name);
491  }
492  return s;
493 }
494 
495 #undef _
496 
497 u8 *
498 format_dpdk_device_errors (u8 * s, va_list * args)
499 {
500  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
501  clib_error_t *e;
502  u32 indent = format_get_indent (s);
503 
504  vec_foreach (e, xd->errors)
505  {
506  s = format (s, "%U%v\n", format_white_space, indent, e->what);
507  }
508  return s;
509 }
510 
511 static u8 *
512 format_dpdk_device_module_info (u8 * s, va_list * args)
513 {
514  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
515  struct rte_eth_dev_module_info mi = { 0 };
516  struct rte_dev_eeprom_info ei = { 0 };
517 
518  if (rte_eth_dev_get_module_info (xd->port_id, &mi) != 0)
519  return format (s, "unknown");
520 
521  ei.length = mi.eeprom_len;
522  ei.data = clib_mem_alloc (mi.eeprom_len);
523 
524  if (rte_eth_dev_get_module_eeprom (xd->port_id, &ei) == 0)
525  {
526  s = format (s, "%U", format_sfp_eeprom, ei.data +
527  (mi.type == RTE_ETH_MODULE_SFF_8436 ? 0x80 : 0));
528  }
529  else
530  s = format (s, "eeprom read error");
531 
532  clib_mem_free (ei.data);
533  return s;
534 }
535 
536 static const char *
537 ptr2sname (void *p)
538 {
539  Dl_info info = { 0 };
540 
541  if (dladdr (p, &info) == 0)
542  return 0;
543 
544  return info.dli_sname;
545 }
546 
547 u8 *
548 format_dpdk_device (u8 * s, va_list * args)
549 {
550  u32 dev_instance = va_arg (*args, u32);
551  int verbose = va_arg (*args, int);
552  dpdk_main_t *dm = &dpdk_main;
553  dpdk_device_t *xd = vec_elt_at_index (dm->devices, dev_instance);
554  u32 indent = format_get_indent (s);
555  f64 now = vlib_time_now (dm->vlib_main);
556  struct rte_eth_dev_info di;
557 
558  dpdk_update_counters (xd, now);
559  dpdk_update_link_state (xd, now);
560  rte_eth_dev_info_get (xd->port_id, &di);
561 
562  s = format (s, "%U\n%Ucarrier %U",
563  format_dpdk_device_type, dev_instance,
565  s = format (s, "%Uflags: %U\n",
567  if (di.device->devargs && di.device->devargs->args)
568  s = format (s, "%UDevargs: %s\n",
569  format_white_space, indent + 2, di.device->devargs->args);
570  s = format (s, "%Urx: queues %d (max %d), desc %d "
571  "(min %d max %d align %d)\n",
572  format_white_space, indent + 2, xd->rx_q_used, di.max_rx_queues,
573  xd->nb_rx_desc, di.rx_desc_lim.nb_min, di.rx_desc_lim.nb_max,
574  di.rx_desc_lim.nb_align);
575  s = format (s, "%Utx: queues %d (max %d), desc %d "
576  "(min %d max %d align %d)\n",
577  format_white_space, indent + 2, xd->tx_q_used, di.max_tx_queues,
578  xd->nb_tx_desc, di.tx_desc_lim.nb_min, di.tx_desc_lim.nb_max,
579  di.tx_desc_lim.nb_align);
580 
581  if (xd->flags & DPDK_DEVICE_FLAG_PMD)
582  {
583  struct rte_pci_device *pci;
584  struct rte_eth_rss_conf rss_conf;
585  int vlan_off;
586  int retval;
587 
588  rss_conf.rss_key = 0;
589  rss_conf.rss_hf = 0;
590  retval = rte_eth_dev_rss_hash_conf_get (xd->port_id, &rss_conf);
591  if (retval < 0)
592  clib_warning ("rte_eth_dev_rss_hash_conf_get returned %d", retval);
593 
594  pci = dpdk_get_pci_device (&di);
595 
596  if (pci)
597  {
598  u8 *s2;
599  if (xd->cpu_socket > -1)
600  s2 = format (0, "%d", xd->cpu_socket);
601  else
602  s2 = format (0, "unknown");
603  s = format (s, "%Upci: device %04x:%04x subsystem %04x:%04x "
604  "address %04x:%02x:%02x.%02x numa %v\n",
605  format_white_space, indent + 2, pci->id.vendor_id,
606  pci->id.device_id, pci->id.subsystem_vendor_id,
607  pci->id.subsystem_device_id, pci->addr.domain,
608  pci->addr.bus, pci->addr.devid, pci->addr.function, s2);
609  vec_free (s2);
610  }
611 
612  if (1 < verbose)
613  {
614  s = format (s, "%Umodule: %U\n", format_white_space, indent + 2,
616  }
617 
618  s = format (s, "%Umax rx packet len: %d\n", format_white_space,
619  indent + 2, di.max_rx_pktlen);
620  s = format (s, "%Upromiscuous: unicast %s all-multicast %s\n",
621  format_white_space, indent + 2,
622  rte_eth_promiscuous_get (xd->port_id) ? "on" : "off",
623  rte_eth_allmulticast_get (xd->port_id) ? "on" : "off");
624  vlan_off = rte_eth_dev_get_vlan_offload (xd->port_id);
625  s = format (s, "%Uvlan offload: strip %s filter %s qinq %s\n",
626  format_white_space, indent + 2,
627  vlan_off & ETH_VLAN_STRIP_OFFLOAD ? "on" : "off",
628  vlan_off & ETH_VLAN_FILTER_OFFLOAD ? "on" : "off",
629  vlan_off & ETH_VLAN_EXTEND_OFFLOAD ? "on" : "off");
630  s = format (s, "%Urx offload avail: %U\n",
631  format_white_space, indent + 2,
632  format_dpdk_rx_offload_caps, di.rx_offload_capa);
633  s = format (s, "%Urx offload active: %U\n",
634  format_white_space, indent + 2,
635  format_dpdk_rx_offload_caps, xd->port_conf.rxmode.offloads);
636  s = format (s, "%Utx offload avail: %U\n",
637  format_white_space, indent + 2,
638  format_dpdk_tx_offload_caps, di.tx_offload_capa);
639  s = format (s, "%Utx offload active: %U\n",
640  format_white_space, indent + 2,
641  format_dpdk_tx_offload_caps, xd->port_conf.txmode.offloads);
642  s = format (s, "%Urss avail: %U\n"
643  "%Urss active: %U\n",
644  format_white_space, indent + 2,
645  format_dpdk_rss_hf_name, di.flow_type_rss_offloads,
646  format_white_space, indent + 2,
647  format_dpdk_rss_hf_name, rss_conf.rss_hf);
648  s = format (s, "%Utx burst function: %s\n",
649  format_white_space, indent + 2,
650  ptr2sname (rte_eth_devices[xd->port_id].tx_pkt_burst));
651  s = format (s, "%Urx burst function: %s\n",
652  format_white_space, indent + 2,
653  ptr2sname (rte_eth_devices[xd->port_id].rx_pkt_burst));
654  }
655 
656  /* $$$ MIB counters */
657  {
658 #define _(N, V) \
659  if (xd->stats.V != 0) { \
660  s = format (s, "\n%U%-40U%16Lu", \
661  format_white_space, indent + 2, \
662  format_c_identifier, #N, \
663  xd->stats.V); \
664  } \
665 
667 #undef _
668  }
669 
670  u8 *xs = 0;
671  u32 i = 0;
672  struct rte_eth_xstat *xstat;
673  struct rte_eth_xstat_name *xstat_names = 0;
674  int len = vec_len (xd->xstats);
675  vec_validate (xstat_names, len - 1);
676  int ret = rte_eth_xstats_get_names (xd->port_id, xstat_names, len);
677 
678  if (ret >= 0 && ret <= len)
679  {
680  /* *INDENT-OFF* */
681  vec_foreach_index(i, xd->xstats)
682  {
683  xstat = vec_elt_at_index(xd->xstats, i);
684  if (verbose == 2 || (verbose && xstat->value))
685  {
686  /* format_c_identifier doesn't like c strings inside vector */
687  u8 * name = format(0,"%s", xstat_names[i].name);
688  xs = format(xs, "\n%U%-38U%16Lu",
689  format_white_space, indent + 4,
690  format_c_identifier, name, xstat->value);
691  vec_free(name);
692  }
693  }
694  /* *INDENT-ON* */
695 
696  vec_free (xstat_names);
697  }
698 
699  if (xs)
700  {
701  s = format (s, "\n%Uextended stats:%v",
702  format_white_space, indent + 2, xs);
703  vec_free (xs);
704  }
705 
706  if (vec_len (xd->errors))
707  {
708  s = format (s, "%UErrors:\n %U", format_white_space, indent,
710  }
711 
712  return s;
713 }
714 
715 u8 *
716 format_dpdk_tx_trace (u8 * s, va_list * va)
717 {
718  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
719  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
721  dpdk_tx_trace_t *t = va_arg (*va, dpdk_tx_trace_t *);
722  dpdk_main_t *dm = &dpdk_main;
724  u32 indent = format_get_indent (s);
726 
727  s = format (s, "%U tx queue %d",
729 
730  s = format (s, "\n%Ubuffer 0x%x: %U",
731  format_white_space, indent,
733 
734  s = format (s, "\n%U%U",
735  format_white_space, indent,
736  format_dpdk_rte_mbuf, &t->mb, &t->data);
737 
738  s = format (s, "\n%U%U", format_white_space, indent,
740  sizeof (t->buffer.pre_data));
741 
742  return s;
743 }
744 
745 u8 *
746 format_dpdk_rx_trace (u8 * s, va_list * va)
747 {
748  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
749  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
751  dpdk_rx_trace_t *t = va_arg (*va, dpdk_rx_trace_t *);
752  dpdk_main_t *dm = &dpdk_main;
755  u32 indent = format_get_indent (s);
757 
758  s = format (s, "%U rx queue %d",
760 
761  s = format (s, "\n%Ubuffer 0x%x: %U",
762  format_white_space, indent,
764 
765  s = format (s, "\n%U%U",
766  format_white_space, indent,
767  format_dpdk_rte_mbuf, &t->mb, &t->data);
768 
769  if (vm->trace_main.verbose)
770  {
771  s = format (s, "\n%UPacket Dump%s", format_white_space, indent + 2,
772  t->mb.data_len > sizeof (t->data) ? " (truncated)" : "");
773  s = format (s, "\n%U%U", format_white_space, indent + 4,
774  format_hexdump, &t->data,
775  t->mb.data_len >
776  sizeof (t->data) ? sizeof (t->data) : t->mb.data_len);
777  }
778  f = node->format_buffer;
779  if (!f)
780  f = format_hex_bytes;
781  s = format (s, "\n%U%U", format_white_space, indent,
782  f, t->buffer.pre_data, sizeof (t->buffer.pre_data));
783 
784  return s;
785 }
786 
787 
788 static inline u8 *
789 format_dpdk_pkt_types (u8 * s, va_list * va)
790 {
791  u32 *pkt_types = va_arg (*va, u32 *);
792  u32 indent __attribute__ ((unused)) = format_get_indent (s) + 2;
793 
794  if (!*pkt_types)
795  return s;
796 
797  s = format (s, "Packet Types");
798 
799 #define _(L, F, S) \
800  if ((*pkt_types & RTE_PTYPE_##L##_MASK) == RTE_PTYPE_##L##_##F) \
801  { \
802  s = format (s, "\n%U%s (0x%04x) %s", format_white_space, indent, \
803  "RTE_PTYPE_" #L "_" #F, RTE_PTYPE_##L##_##F, S); \
804  }
805 
807 #undef _
808  return s;
809 }
810 
811 static inline u8 *
813 {
814  u64 *ol_flags = va_arg (*va, u64 *);
815  u32 indent = format_get_indent (s) + 2;
816 
817  if (!*ol_flags)
818  return s;
819 
820  s = format (s, "Packet Offload Flags");
821 
822 #define _(F, S) \
823  if (*ol_flags & F) \
824  { \
825  s = format (s, "\n%U%s (0x%04x) %s", \
826  format_white_space, indent, #F, F, S); \
827  }
828 
830 #undef _
831  return s;
832 }
833 
834 u8 *
835 format_dpdk_rte_mbuf_vlan (u8 * s, va_list * va)
836 {
837  ethernet_vlan_header_tv_t *vlan_hdr =
838  va_arg (*va, ethernet_vlan_header_tv_t *);
839 
840  if (clib_net_to_host_u16 (vlan_hdr->type) == ETHERNET_TYPE_DOT1AD)
841  {
842  s = format (s, "%U 802.1q vlan ",
844  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
845  vlan_hdr++;
846  }
847 
848  s = format (s, "%U",
850  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
851 
852  return s;
853 }
854 
855 u8 *
856 format_dpdk_rte_mbuf (u8 * s, va_list * va)
857 {
858  struct rte_mbuf *mb = va_arg (*va, struct rte_mbuf *);
859  ethernet_header_t *eth_hdr = va_arg (*va, ethernet_header_t *);
860  u32 indent = format_get_indent (s) + 2;
861 
862  s = format (s, "PKT MBUF: port %d, nb_segs %d, pkt_len %d"
863  "\n%Ubuf_len %d, data_len %d, ol_flags 0x%lx, data_off %d, phys_addr 0x%x"
864  "\n%Upacket_type 0x%x l2_len %u l3_len %u outer_l2_len %u outer_l3_len %u"
865  "\n%Urss 0x%x fdir.hi 0x%x fdir.lo 0x%x",
866  mb->port, mb->nb_segs, mb->pkt_len,
867  format_white_space, indent,
868  mb->buf_len, mb->data_len, mb->ol_flags, mb->data_off,
869  mb->buf_physaddr, format_white_space, indent, mb->packet_type,
870  mb->l2_len, mb->l3_len, mb->outer_l2_len, mb->outer_l3_len,
871  format_white_space, indent, mb->hash.rss, mb->hash.fdir.hi,
872  mb->hash.fdir.lo);
873 
874  if (mb->ol_flags)
875  s = format (s, "\n%U%U", format_white_space, indent,
876  format_dpdk_pkt_offload_flags, &mb->ol_flags);
877 
878  if ((mb->ol_flags & PKT_RX_VLAN) &&
879  ((mb->ol_flags & (PKT_RX_VLAN_STRIPPED | PKT_RX_QINQ_STRIPPED)) == 0))
880  {
881  ethernet_vlan_header_tv_t *vlan_hdr =
882  ((ethernet_vlan_header_tv_t *) & (eth_hdr->type));
883  s = format (s, " %U", format_dpdk_rte_mbuf_vlan, vlan_hdr);
884  }
885 
886  if (mb->packet_type)
887  s = format (s, "\n%U%U", format_white_space, indent,
888  format_dpdk_pkt_types, &mb->packet_type);
889 
890  return s;
891 }
892 
893 clib_error_t *
895 {
897  {
898  if (0)
899  ;
900 #undef _
901 #define _(f, s) \
902  else if (unformat (input, s)) \
903  *rss_fn |= f;
904 
906 #undef _
907  else
908  {
909  return clib_error_return (0, "unknown input `%U'",
910  format_unformat_error, input);
911  }
912  }
913  return 0;
914 }
915 
916 clib_error_t *
918 {
919  clib_error_t *error = 0;
920 
922  {
923  if (unformat (input, "hqos-thread %u", &hqos->hqos_thread))
924  hqos->hqos_thread_valid = 1;
925  else
926  {
927  error = clib_error_return (0, "unknown input `%U'",
928  format_unformat_error, input);
929  break;
930  }
931  }
932 
933  return error;
934 }
935 
936 /*
937  * fd.io coding-style-patch-verification: ON
938  *
939  * Local Variables:
940  * eval: (c-set-style "gnu")
941  * End:
942  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:440
u8 * format_dpdk_device(u8 *s, va_list *args)
Definition: format.c:548
#define vec_foreach_index(var, v)
Iterate over vector indices.
static u8 * format_offload(u8 *s, va_list *va)
Definition: format.c:426
u8 * format_dpdk_device_flags(u8 *s, va_list *args)
Definition: format.c:242
#define CLIB_UNUSED(x)
Definition: clib.h:82
u8 * format_dpdk_tx_trace(u8 *s, va_list *va)
Definition: format.c:716
u8 * format_dpdk_rte_mbuf_vlan(u8 *s, va_list *va)
Definition: format.c:835
u8 interface_name_format_decimal
Definition: dpdk.h:368
dpdk_main_t dpdk_main
Definition: init.c:45
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
u8 * format_dpdk_rss_hf_name(u8 *s, va_list *args)
Definition: format.c:410
unsigned long u64
Definition: types.h:89
u32 sw_if_index
Definition: dpdk.h:202
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:279
clib_error_t * unformat_hqos(unformat_input_t *input, dpdk_device_config_hqos_t *hqos)
Definition: format.c:917
struct rte_pci_device * dpdk_get_pci_device(const struct rte_eth_dev_info *info)
Definition: common.c:247
u16 flags
Definition: dpdk.h:210
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
clib_error_t * errors
Definition: dpdk.h:258
int i
static u8 * format_dpdk_pkt_offload_flags(u8 *s, va_list *va)
Definition: format.c:812
static u32 format_get_indent(u8 *s)
Definition: format.h:72
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u8 * format_dpdk_rte_mbuf(u8 *s, va_list *va)
Definition: format.c:856
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
u8 * format_dpdk_device_name(u8 *s, va_list *args)
Definition: format.c:137
#define foreach_dpdk_rss_hf
Definition: format.c:48
dpdk_portid_t port_id
Definition: dpdk.h:199
u32 buffer_index
Definition: dpdk.h:436
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
#define foreach_dpdk_pkt_type
Definition: format.c:85
#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
#define clib_error_return(e, args...)
Definition: error.h:99
u16 rx_q_used
Definition: dpdk.h:223
u8 * format_ethernet_header_with_length(u8 *s, va_list *args)
Definition: format.c:97
unsigned int u32
Definition: types.h:88
struct rte_eth_conf port_conf
Definition: dpdk.h:227
static u8 * format_dpdk_pkt_types(u8 *s, va_list *va)
Definition: format.c:789
static u8 * format_dpdk_device_module_info(u8 *s, va_list *args)
Definition: format.c:512
u8 * format_c_identifier(u8 *s, va_list *va)
Definition: std-formats.c:274
format_function_t format_vnet_sw_interface_name
format_function_t format_vnet_buffer
Definition: buffer.h:483
u8 * format_dpdk_rx_trace(u8 *s, va_list *va)
Definition: format.c:746
struct _unformat_input_t unformat_input_t
#define foreach_dpdk_counter
Definition: format.c:31
u8 data[256]
Definition: dpdk.h:442
dpdk_port_type_t port_type
Definition: dpdk.h:252
format_function_t format_sfp_eeprom
Definition: sfp.h:133
format_function_t * format_buffer
Definition: node.h:358
u16 tx_q_used
Definition: dpdk.h:222
u16 nb_rx_desc
Definition: dpdk.h:224
vlib_main_t * vm
Definition: in2out_ed.c:1810
u32 hw_if_index
Definition: dpdk.h:201
u8 len
Definition: ip_types.api:91
u16 af_packet_instance_num
Definition: dpdk.h:243
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
svmdb_client_t * c
dpdk_device_t * devices
Definition: dpdk.h:399
static void dpdk_update_counters(dpdk_device_t *xd, f64 now)
Definition: dpdk_priv.h:77
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:342
#define clib_warning(format, args...)
Definition: error.h:59
dpdk_pmd_t pmd
Definition: dpdk.h:207
u8 * format_hexdump(u8 *s, va_list *va)
Definition: std-formats.c:297
string name[64]
Definition: ip.api:44
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1810
struct rte_eth_xstat * xstats
Definition: dpdk.h:250
struct rte_mbuf mb
Definition: dpdk.h:439
u8 * interface_name_suffix
Definition: dpdk.h:216
static const char * ptr2sname(void *p)
Definition: format.c:537
u16 device_index
Definition: dpdk.h:448
u8 * format_dpdk_device_errors(u8 *s, va_list *args)
Definition: format.c:498
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
Definition: buffer.h:178
static void clib_mem_free(void *p)
Definition: mem.h:226
clib_error_t * unformat_rss_fn(unformat_input_t *input, uword *rss_fn)
Definition: format.c:894
u8 * format_dpdk_tx_offload_caps(u8 *s, va_list *args)
Definition: format.c:477
u8 * format_dpdk_rx_offload_caps(u8 *s, va_list *args)
Definition: format.c:458
vlib_buffer_t buffer
Definition: dpdk.h:451
vlib_trace_main_t trace_main
Definition: main.h:164
void dpdk_update_link_state(dpdk_device_t *xd, f64 now)
Definition: init.c:1544
struct rte_eth_link link
Definition: dpdk.h:245
u32 buffer_index
Definition: dpdk.h:447
static void * clib_mem_alloc(uword size)
Definition: mem.h:153
u8 * name
Definition: dpdk.h:215
vl_api_ip4_address_t hi
Definition: arp.api:37
vlib_buffer_t buffer
Definition: dpdk.h:441
u8 data[256]
Definition: dpdk.h:452
static u8 * format_dpdk_device_type(u8 *s, va_list *args)
Definition: format.c:257
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u64 uword
Definition: types.h:112
u16 device_index
Definition: dpdk.h:437
#define foreach_dpdk_pkt_offload_flag
Definition: format.c:132
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
static uword clib_mem_is_vec(void *v)
Predicate function, says whether the supplied vector is a clib heap object.
Definition: vec.h:207
#define vec_foreach(var, vec)
Vector iterator.
i8 cpu_socket
Definition: dpdk.h:208
static u8 * format_dpdk_link_status(u8 *s, va_list *args)
Definition: format.c:379
struct rte_mbuf mb
Definition: dpdk.h:450
u8 queue_index
Definition: dpdk.h:438
u16 nb_tx_desc
Definition: dpdk.h:212
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
u8 * format_ethernet_vlan_tci(u8 *s, va_list *va)
Definition: format.c:79
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
dpdk_config_main_t * conf
Definition: dpdk.h:423
u16 queue_index
Definition: dpdk.h:449
vlib_main_t * vlib_main
Definition: dpdk.h:421