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