FD.io VPP  v19.04.4-rc0-5-ge88582fac
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 u8 *
139 format_dpdk_device_name (u8 * s, va_list * args)
140 {
141  dpdk_main_t *dm = &dpdk_main;
142  char *devname_format;
143  char *device_name;
144  u32 i = va_arg (*args, u32);
145  dpdk_device_t *xd = vec_elt_at_index (dm->devices, i);
146  struct rte_eth_dev_info dev_info;
147  struct rte_pci_device *pci_dev;
148  u8 *ret;
149 
150  if (xd->name)
151  return format (s, "%s", xd->name);
152 
154  devname_format = "%s%d/%d/%d";
155  else
156  devname_format = "%s%x/%x/%x";
157 
158  switch (xd->port_type)
159  {
161  device_name = "GigabitEthernet";
162  break;
163 
165  device_name = "Two_FiveGigabitEthernet";
166  break;
167 
169  device_name = "FiveGigabitEthernet";
170  break;
171 
173  device_name = "TenGigabitEthernet";
174  break;
175 
177  device_name = "TwentyGigabitEthernet";
178  break;
179 
181  device_name = "TwentyFiveGigabitEthernet";
182  break;
183 
185  device_name = "FortyGigabitEthernet";
186  break;
187 
189  device_name = "FiftyGigabitEthernet";
190  break;
191 
193  device_name = "FiftySixGigabitEthernet";
194  break;
195 
197  device_name = "HundredGigabitEthernet";
198  break;
199 
201  return format (s, "BondEthernet%d", xd->bond_instance_num);
202 
204  device_name = "EthernetSwitch";
205  break;
206 
208  device_name = "VirtualFunctionEthernet";
209  break;
210 
212  return format (s, "af_packet%d", xd->af_packet_instance_num);
213 
215  device_name = "VirtioUser";
216  break;
217 
219  device_name = "VhostEthernet";
220  break;
221 
223  device_name = "FailsafeEthernet";
224  break;
225 
226  default:
228  device_name = "UnknownEthernet";
229  break;
230  }
231 
232  rte_eth_dev_info_get (xd->port_id, &dev_info);
233  pci_dev = dpdk_get_pci_device (&dev_info);
234 
235  if (pci_dev && xd->port_type != VNET_DPDK_PORT_TYPE_FAILSAFE)
236  ret = format (s, devname_format, device_name, pci_dev->addr.bus,
237  pci_dev->addr.devid, pci_dev->addr.function);
238  else
239  ret = format (s, "%s%d", device_name, xd->port_id);
240 
241  if (xd->interface_name_suffix)
242  return format (ret, "/%s", xd->interface_name_suffix);
243  return ret;
244 }
245 
246 u8 *
247 format_dpdk_device_flags (u8 * s, va_list * args)
248 {
249  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
250  u8 *t = 0;
251 
252 #define _(a, b, c) if (xd->flags & (1 << a)) \
253 t = format (t, "%s%s", t ? " ":"", c);
255 #undef _
256  s = format (s, "%v", t);
257  vec_free (t);
258  return s;
259 }
260 
261 static u8 *
262 format_dpdk_device_type (u8 * s, va_list * args)
263 {
264  dpdk_main_t *dm = &dpdk_main;
265  char *dev_type;
266  u32 i = va_arg (*args, u32);
267 
268  switch (dm->devices[i].pmd)
269  {
270  case VNET_DPDK_PMD_E1000EM:
271  dev_type = "Intel 82540EM (e1000)";
272  break;
273 
274  case VNET_DPDK_PMD_IGB:
275  dev_type = "Intel e1000";
276  break;
277 
278  case VNET_DPDK_PMD_I40E:
279  dev_type = "Intel X710/XL710 Family";
280  break;
281 
282  case VNET_DPDK_PMD_I40EVF:
283  dev_type = "Intel X710/XL710 Family VF";
284  break;
285 
286  case VNET_DPDK_PMD_ICE:
287  dev_type = "Intel E810 Family";
288  break;
289 
290  case VNET_DPDK_PMD_FM10K:
291  dev_type = "Intel FM10000 Family Ethernet Switch";
292  break;
293 
294  case VNET_DPDK_PMD_IGBVF:
295  dev_type = "Intel e1000 VF";
296  break;
297 
298  case VNET_DPDK_PMD_VIRTIO:
299  dev_type = "Red Hat Virtio";
300  break;
301 
302  case VNET_DPDK_PMD_IXGBEVF:
303  dev_type = "Intel 82599 VF";
304  break;
305 
306  case VNET_DPDK_PMD_IXGBE:
307  dev_type = "Intel 82599";
308  break;
309 
310  case VNET_DPDK_PMD_ENIC:
311  dev_type = "Cisco VIC";
312  break;
313 
314  case VNET_DPDK_PMD_CXGBE:
315  dev_type = "Chelsio T4/T5";
316  break;
317 
318  case VNET_DPDK_PMD_MLX4:
319  dev_type = "Mellanox ConnectX-3 Family";
320  break;
321 
322  case VNET_DPDK_PMD_MLX5:
323  dev_type = "Mellanox ConnectX-4 Family";
324  break;
325 
326  case VNET_DPDK_PMD_VMXNET3:
327  dev_type = "VMware VMXNET3";
328  break;
329 
330  case VNET_DPDK_PMD_AF_PACKET:
331  dev_type = "af_packet";
332  break;
333 
334  case VNET_DPDK_PMD_BOND:
335  dev_type = "Ethernet Bonding";
336  break;
337 
338  case VNET_DPDK_PMD_DPAA2:
339  dev_type = "NXP DPAA2 Mac";
340  break;
341 
342  case VNET_DPDK_PMD_VIRTIO_USER:
343  dev_type = "Virtio User";
344  break;
345 
346  case VNET_DPDK_PMD_THUNDERX:
347  dev_type = "Cavium ThunderX";
348  break;
349 
350  case VNET_DPDK_PMD_VHOST_ETHER:
351  dev_type = "VhostEthernet";
352  break;
353 
354  case VNET_DPDK_PMD_ENA:
355  dev_type = "AWS ENA VF";
356  break;
357 
358  case VNET_DPDK_PMD_FAILSAFE:
359  dev_type = "FailsafeEthernet";
360  break;
361 
362  case VNET_DPDK_PMD_LIOVF_ETHER:
363  dev_type = "Cavium Lio VF";
364  break;
365 
366  case VNET_DPDK_PMD_QEDE:
367  dev_type = "Cavium QLogic FastLinQ QL4xxxx";
368  break;
369 
370  case VNET_DPDK_PMD_NETVSC:
371  dev_type = "Microsoft Hyper-V Netvsc";
372  break;
373 
374  default:
376  dev_type = "### UNKNOWN ###";
377  break;
378  }
379 
380  return format (s, dev_type);
381 }
382 
383 static u8 *
384 format_dpdk_link_status (u8 * s, va_list * args)
385 {
386  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
387  struct rte_eth_link *l = &xd->link;
388  vnet_main_t *vnm = vnet_get_main ();
390 
391  s = format (s, "%s ", l->link_status ? "up" : "down");
392  if (l->link_status)
393  {
394  u32 promisc = rte_eth_promiscuous_get (xd->port_id);
395 
396  s = format (s, "%s duplex ", (l->link_duplex == ETH_LINK_FULL_DUPLEX) ?
397  "full" : "half");
398  s = format (s, "mtu %d %s\n", hi->max_packet_bytes, promisc ?
399  " promisc" : "");
400  }
401  else
402  s = format (s, "\n");
403 
404  return s;
405 }
406 
407 #define _(v, str) \
408 if (bitmap & v) { \
409  if (format_get_indent (s) > 72) \
410  s = format(s,"\n%U", format_white_space, indent); \
411  s = format(s, "%s ", str); \
412 }
413 
414 u8 *
415 format_dpdk_rss_hf_name (u8 * s, va_list * args)
416 {
417  u64 bitmap = va_arg (*args, u64);
418  u32 indent = format_get_indent (s);
419 
420  if (!bitmap)
421  return format (s, "none");
422 
423  foreach_dpdk_rss_hf return s;
424 }
425 
426 #undef _
427 
428 /* Convert to all lower case e.g "VLAN_STRIP" -> "vlan-strip"
429  Works for both vector names and null terminated c strings. */
430 static u8 *
431 format_offload (u8 * s, va_list * va)
432 {
433  u8 *id = va_arg (*va, u8 *);
434  uword i, l;
435 
436  l = ~0;
437  if (clib_mem_is_vec (id))
438  l = vec_len (id);
439 
440  if (id)
441  for (i = 0; id[i] != 0 && i < l; i++)
442  {
443  u8 c = id[i];
444 
445  if (c == '_')
446  c = '-';
447  else
448  c = tolower (c);
449  vec_add1 (s, c);
450  }
451 
452  return s;
453 }
454 
455 #define _(v, func) \
456 if (bitmap & v) { \
457  if (format_get_indent (s) > 72) \
458  s = format(s,"\n%U", format_white_space, indent); \
459  s = format(s, "%U ", format_offload, func (v)); \
460 }
461 
462 u8 *
463 format_dpdk_rx_offload_caps (u8 * s, va_list * args)
464 {
465  u64 bitmap = va_arg (*args, u32);
466  u32 indent = format_get_indent (s);
467  uword i;
468 
469  if (!bitmap)
470  return format (s, "none");
471 
472  for (i = 0; i < 64; i++)
473  {
474  u64 mask = (u64) 1 << i;
475 
476  _(mask, rte_eth_dev_rx_offload_name);
477  }
478  return s;
479 }
480 
481 u8 *
482 format_dpdk_tx_offload_caps (u8 * s, va_list * args)
483 {
484  u64 bitmap = va_arg (*args, u32);
485  u32 indent = format_get_indent (s);
486  uword i;
487 
488  if (!bitmap)
489  return format (s, "none");
490 
491  for (i = 0; i < 64; i++)
492  {
493  u64 mask = (u64) 1 << i;
494 
495  _(mask, rte_eth_dev_tx_offload_name);
496  }
497  return s;
498 }
499 
500 #undef _
501 
502 u8 *
503 format_dpdk_device_errors (u8 * s, va_list * args)
504 {
505  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
506  clib_error_t *e;
507  u32 indent = format_get_indent (s);
508 
509  vec_foreach (e, xd->errors)
510  {
511  s = format (s, "%U%v\n", format_white_space, indent, e->what);
512  }
513  return s;
514 }
515 
516 static u8 *
517 format_dpdk_device_module_info (u8 * s, va_list * args)
518 {
519  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
520  struct rte_eth_dev_module_info mi = { 0 };
521  struct rte_dev_eeprom_info ei = { 0 };
522 
523  if (rte_eth_dev_get_module_info (xd->port_id, &mi) != 0)
524  return format (s, "unknown");
525 
526  ei.length = mi.eeprom_len;
527  ei.data = clib_mem_alloc (mi.eeprom_len);
528 
529  if (rte_eth_dev_get_module_eeprom (xd->port_id, &ei) == 0)
530  {
531  s = format (s, "%U", format_sfp_eeprom, ei.data +
532  (mi.type == RTE_ETH_MODULE_SFF_8436 ? 0x80 : 0));
533  }
534  else
535  s = format (s, "eeprom read error");
536 
537  clib_mem_free (ei.data);
538  return s;
539 }
540 
541 static const char *
542 ptr2sname (void *p)
543 {
544  Dl_info info = { 0 };
545 
546  if (dladdr (p, &info) == 0)
547  return 0;
548 
549  return info.dli_sname;
550 }
551 
552 u8 *
553 format_dpdk_device (u8 * s, va_list * args)
554 {
555  u32 dev_instance = va_arg (*args, u32);
556  int verbose = va_arg (*args, int);
557  dpdk_main_t *dm = &dpdk_main;
558  dpdk_device_t *xd = vec_elt_at_index (dm->devices, dev_instance);
559  u32 indent = format_get_indent (s);
560  f64 now = vlib_time_now (dm->vlib_main);
561  struct rte_eth_dev_info di;
562 
563  dpdk_update_counters (xd, now);
564  dpdk_update_link_state (xd, now);
565  rte_eth_dev_info_get (xd->port_id, &di);
566 
567  s = format (s, "%U\n%Ucarrier %U",
568  format_dpdk_device_type, dev_instance,
570  s = format (s, "%Uflags: %U\n",
572  s = format (s, "%Urx: queues %d (max %d), desc %d "
573  "(min %d max %d align %d)\n",
574  format_white_space, indent + 2, xd->rx_q_used, di.max_rx_queues,
575  xd->nb_rx_desc, di.rx_desc_lim.nb_min, di.rx_desc_lim.nb_max,
576  di.rx_desc_lim.nb_align);
577  s = format (s, "%Utx: queues %d (max %d), desc %d "
578  "(min %d max %d align %d)\n",
579  format_white_space, indent + 2, xd->tx_q_used, di.max_tx_queues,
580  xd->nb_tx_desc, di.tx_desc_lim.nb_min, di.tx_desc_lim.nb_max,
581  di.tx_desc_lim.nb_align);
582 
583  if (xd->flags & DPDK_DEVICE_FLAG_PMD)
584  {
585  struct rte_pci_device *pci;
586  struct rte_eth_rss_conf rss_conf;
587  int vlan_off;
588  int retval;
589 
590  rss_conf.rss_key = 0;
591  rss_conf.rss_hf = 0;
592  retval = rte_eth_dev_rss_hash_conf_get (xd->port_id, &rss_conf);
593  if (retval < 0)
594  clib_warning ("rte_eth_dev_rss_hash_conf_get returned %d", retval);
595 
596  pci = dpdk_get_pci_device (&di);
597 
598  if (pci)
599  {
600  u8 *s2;
601  if (xd->cpu_socket > -1)
602  s2 = format (0, "%d", xd->cpu_socket);
603  else
604  s2 = format (0, "unknown");
605  s = format (s, "%Upci: device %04x:%04x subsystem %04x:%04x "
606  "address %04x:%02x:%02x.%02x numa %v\n",
607  format_white_space, indent + 2, pci->id.vendor_id,
608  pci->id.device_id, pci->id.subsystem_vendor_id,
609  pci->id.subsystem_device_id, pci->addr.domain,
610  pci->addr.bus, pci->addr.devid, pci->addr.function, s2);
611  vec_free (s2);
612  }
613 
614  s = format (s, "%Umodule: %U\n", format_white_space, indent + 2,
616 
617  s = format (s, "%Umax rx packet len: %d\n", format_white_space,
618  indent + 2, di.max_rx_pktlen);
619  s = format (s, "%Upromiscuous: unicast %s all-multicast %s\n",
620  format_white_space, indent + 2,
621  rte_eth_promiscuous_get (xd->port_id) ? "on" : "off",
622  rte_eth_allmulticast_get (xd->port_id) ? "on" : "off");
623  vlan_off = rte_eth_dev_get_vlan_offload (xd->port_id);
624  s = format (s, "%Uvlan offload: strip %s filter %s qinq %s\n",
625  format_white_space, indent + 2,
626  vlan_off & ETH_VLAN_STRIP_OFFLOAD ? "on" : "off",
627  vlan_off & ETH_VLAN_FILTER_OFFLOAD ? "on" : "off",
628  vlan_off & ETH_VLAN_EXTEND_OFFLOAD ? "on" : "off");
629  s = format (s, "%Urx offload avail: %U\n",
630  format_white_space, indent + 2,
631  format_dpdk_rx_offload_caps, di.rx_offload_capa);
632  s = format (s, "%Urx offload active: %U\n",
633  format_white_space, indent + 2,
634  format_dpdk_rx_offload_caps, xd->port_conf.rxmode.offloads);
635  s = format (s, "%Utx offload avail: %U\n",
636  format_white_space, indent + 2,
637  format_dpdk_tx_offload_caps, di.tx_offload_capa);
638  s = format (s, "%Utx offload active: %U\n",
639  format_white_space, indent + 2,
640  format_dpdk_tx_offload_caps, xd->port_conf.txmode.offloads);
641  s = format (s, "%Urss avail: %U\n"
642  "%Urss active: %U\n",
643  format_white_space, indent + 2,
644  format_dpdk_rss_hf_name, di.flow_type_rss_offloads,
645  format_white_space, indent + 2,
646  format_dpdk_rss_hf_name, rss_conf.rss_hf);
647  s = format (s, "%Utx burst function: %s\n",
648  format_white_space, indent + 2,
649  ptr2sname (rte_eth_devices[xd->port_id].tx_pkt_burst));
650  s = format (s, "%Urx burst function: %s\n",
651  format_white_space, indent + 2,
652  ptr2sname (rte_eth_devices[xd->port_id].rx_pkt_burst));
653  }
654 
655  /* $$$ MIB counters */
656  {
657 #define _(N, V) \
658  if ((xd->stats.V - xd->last_cleared_stats.V) != 0) { \
659  s = format (s, "\n%U%-40U%16Lu", \
660  format_white_space, indent + 2, \
661  format_c_identifier, #N, \
662  xd->stats.V - xd->last_cleared_stats.V); \
663  } \
664 
666 #undef _
667  }
668 
669  u8 *xs = 0;
670  u32 i = 0;
671  struct rte_eth_xstat *xstat, *last_xstat;
672  struct rte_eth_xstat_name *xstat_names = 0;
673  int len = rte_eth_xstats_get_names (xd->port_id, NULL, 0);
674  vec_validate (xstat_names, len - 1);
675  rte_eth_xstats_get_names (xd->port_id, xstat_names, len);
676 
678 
679  /* *INDENT-OFF* */
680  vec_foreach_index(i, xd->xstats)
681  {
682  u64 delta = 0;
683  xstat = vec_elt_at_index(xd->xstats, i);
684  last_xstat = vec_elt_at_index(xd->last_cleared_xstats, i);
685 
686  delta = xstat->value - last_xstat->value;
687  if (verbose == 2 || (verbose && delta))
688  {
689  /* format_c_identifier doesn't like c strings inside vector */
690  u8 * name = format(0,"%s", xstat_names[i].name);
691  xs = format(xs, "\n%U%-38U%16Lu",
692  format_white_space, indent + 4,
693  format_c_identifier, name, delta);
694  vec_free(name);
695  }
696  }
697  /* *INDENT-ON* */
698 
699  vec_free (xstat_names);
700 
701  if (xs)
702  {
703  s = format (s, "\n%Uextended stats:%v",
704  format_white_space, indent + 2, xs);
705  vec_free (xs);
706  }
707 
708  if (vec_len (xd->errors))
709  {
710  s = format (s, "%UErrors:\n %U", format_white_space, indent,
712  }
713 
714  return s;
715 }
716 
717 u8 *
718 format_dpdk_tx_trace (u8 * s, va_list * va)
719 {
720  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
721  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
723  dpdk_tx_trace_t *t = va_arg (*va, dpdk_tx_trace_t *);
724  dpdk_main_t *dm = &dpdk_main;
726  u32 indent = format_get_indent (s);
728 
729  s = format (s, "%U tx queue %d",
731 
732  s = format (s, "\n%Ubuffer 0x%x: %U",
733  format_white_space, indent,
735 
736  s = format (s, "\n%U%U",
737  format_white_space, indent,
738  format_dpdk_rte_mbuf, &t->mb, &t->data);
739 
740  s = format (s, "\n%U%U", format_white_space, indent,
742  sizeof (t->buffer.pre_data));
743 
744  return s;
745 }
746 
747 u8 *
748 format_dpdk_rx_trace (u8 * s, va_list * va)
749 {
750  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
751  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
753  dpdk_rx_trace_t *t = va_arg (*va, dpdk_rx_trace_t *);
754  dpdk_main_t *dm = &dpdk_main;
757  u32 indent = format_get_indent (s);
759 
760  s = format (s, "%U rx queue %d",
762 
763  s = format (s, "\n%Ubuffer 0x%x: %U",
764  format_white_space, indent,
766 
767  s = format (s, "\n%U%U",
768  format_white_space, indent,
769  format_dpdk_rte_mbuf, &t->mb, &t->data);
770 
771  if (vm->trace_main.verbose)
772  {
773  s = format (s, "\n%UPacket Dump%s", format_white_space, indent + 2,
774  t->mb.data_len > sizeof (t->data) ? " (truncated)" : "");
775  s = format (s, "\n%U%U", format_white_space, indent + 4,
776  format_hexdump, &t->data,
777  t->mb.data_len >
778  sizeof (t->data) ? sizeof (t->data) : t->mb.data_len);
779  }
780  f = node->format_buffer;
781  if (!f)
782  f = format_hex_bytes;
783  s = format (s, "\n%U%U", format_white_space, indent,
784  f, t->buffer.pre_data, sizeof (t->buffer.pre_data));
785 
786  return s;
787 }
788 
789 
790 static inline u8 *
791 format_dpdk_pkt_types (u8 * s, va_list * va)
792 {
793  u32 *pkt_types = va_arg (*va, u32 *);
794  u32 indent __attribute__ ((unused)) = format_get_indent (s) + 2;
795 
796  if (!*pkt_types)
797  return s;
798 
799  s = format (s, "Packet Types");
800 
801 #define _(L, F, S) \
802  if ((*pkt_types & RTE_PTYPE_##L##_MASK) == RTE_PTYPE_##L##_##F) \
803  { \
804  s = format (s, "\n%U%s (0x%04x) %s", format_white_space, indent, \
805  "RTE_PTYPE_" #L "_" #F, RTE_PTYPE_##L##_##F, S); \
806  }
807 
809 #undef _
810  return s;
811 }
812 
813 static inline u8 *
815 {
816  u64 *ol_flags = va_arg (*va, u64 *);
817  u32 indent = format_get_indent (s) + 2;
818 
819  if (!*ol_flags)
820  return s;
821 
822  s = format (s, "Packet Offload Flags");
823 
824 #define _(F, S) \
825  if (*ol_flags & F) \
826  { \
827  s = format (s, "\n%U%s (0x%04x) %s", \
828  format_white_space, indent, #F, F, S); \
829  }
830 
832 #undef _
833  return s;
834 }
835 
836 u8 *
837 format_dpdk_rte_mbuf_vlan (u8 * s, va_list * va)
838 {
839  ethernet_vlan_header_tv_t *vlan_hdr =
840  va_arg (*va, ethernet_vlan_header_tv_t *);
841 
842  if (clib_net_to_host_u16 (vlan_hdr->type) == ETHERNET_TYPE_DOT1AD)
843  {
844  s = format (s, "%U 802.1q vlan ",
846  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
847  vlan_hdr++;
848  }
849 
850  s = format (s, "%U",
852  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
853 
854  return s;
855 }
856 
857 u8 *
858 format_dpdk_rte_mbuf (u8 * s, va_list * va)
859 {
860  struct rte_mbuf *mb = va_arg (*va, struct rte_mbuf *);
861  ethernet_header_t *eth_hdr = va_arg (*va, ethernet_header_t *);
862  u32 indent = format_get_indent (s) + 2;
863 
864  s = format (s, "PKT MBUF: port %d, nb_segs %d, pkt_len %d"
865  "\n%Ubuf_len %d, data_len %d, ol_flags 0x%lx, data_off %d, phys_addr 0x%x"
866  "\n%Upacket_type 0x%x l2_len %u l3_len %u outer_l2_len %u outer_l3_len %u"
867  "\n%Urss 0x%x fdir.hi 0x%x fdir.lo 0x%x",
868  mb->port, mb->nb_segs, mb->pkt_len,
869  format_white_space, indent,
870  mb->buf_len, mb->data_len, mb->ol_flags, mb->data_off,
871  mb->buf_physaddr, format_white_space, indent, mb->packet_type,
872  mb->l2_len, mb->l3_len, mb->outer_l2_len, mb->outer_l3_len,
873  format_white_space, indent, mb->hash.rss, mb->hash.fdir.hi,
874  mb->hash.fdir.lo);
875 
876  if (mb->ol_flags)
877  s = format (s, "\n%U%U", format_white_space, indent,
878  format_dpdk_pkt_offload_flags, &mb->ol_flags);
879 
880  if ((mb->ol_flags & PKT_RX_VLAN) &&
881  ((mb->ol_flags & (PKT_RX_VLAN_STRIPPED | PKT_RX_QINQ_STRIPPED)) == 0))
882  {
883  ethernet_vlan_header_tv_t *vlan_hdr =
884  ((ethernet_vlan_header_tv_t *) & (eth_hdr->type));
885  s = format (s, " %U", format_dpdk_rte_mbuf_vlan, vlan_hdr);
886  }
887 
888  if (mb->packet_type)
889  s = format (s, "\n%U%U", format_white_space, indent,
890  format_dpdk_pkt_types, &mb->packet_type);
891 
892  return s;
893 }
894 
895 clib_error_t *
897 {
899  {
900  if (0)
901  ;
902 #undef _
903 #define _(f, s) \
904  else if (unformat (input, s)) \
905  *rss_fn |= f;
906 
908 #undef _
909  else
910  {
911  return clib_error_return (0, "unknown input `%U'",
912  format_unformat_error, input);
913  }
914  }
915  return 0;
916 }
917 
918 clib_error_t *
920 {
921  clib_error_t *error = 0;
922 
924  {
925  if (unformat (input, "hqos-thread %u", &hqos->hqos_thread))
926  hqos->hqos_thread_valid = 1;
927  else
928  {
929  error = clib_error_return (0, "unknown input `%U'",
930  format_unformat_error, input);
931  break;
932  }
933  }
934 
935  return error;
936 }
937 
938 /*
939  * fd.io coding-style-patch-verification: ON
940  *
941  * Local Variables:
942  * eval: (c-set-style "gnu")
943  * End:
944  */
#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:553
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:431
u8 * format_dpdk_device_flags(u8 *s, va_list *args)
Definition: format.c:247
#define CLIB_UNUSED(x)
Definition: clib.h:82
u8 * format_dpdk_tx_trace(u8 *s, va_list *va)
Definition: format.c:718
u8 * format_dpdk_rte_mbuf_vlan(u8 *s, va_list *va)
Definition: format.c:837
u8 interface_name_format_decimal
Definition: dpdk.h:373
dpdk_main_t dpdk_main
Definition: init.c:44
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:415
unsigned long u64
Definition: types.h:89
u32 sw_if_index
Definition: dpdk.h:206
#define NULL
Definition: clib.h:58
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:255
clib_error_t * unformat_hqos(unformat_input_t *input, dpdk_device_config_hqos_t *hqos)
Definition: format.c:919
struct rte_pci_device * dpdk_get_pci_device(const struct rte_eth_dev_info *info)
Definition: common.c:348
u16 flags
Definition: dpdk.h:214
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:522
clib_error_t * errors
Definition: dpdk.h:269
int i
static u8 * format_dpdk_pkt_offload_flags(u8 *s, va_list *va)
Definition: format.c:814
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:858
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u16 bond_instance_num
Definition: dpdk.h:248
struct rte_eth_xstat * last_cleared_xstats
Definition: dpdk.h:261
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:139
#define foreach_dpdk_rss_hf
Definition: format.c:48
dpdk_portid_t port_id
Definition: dpdk.h:203
u32 buffer_index
Definition: dpdk.h:441
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:227
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:231
static u8 * format_dpdk_pkt_types(u8 *s, va_list *va)
Definition: format.c:791
static u8 * format_dpdk_device_module_info(u8 *s, va_list *args)
Definition: format.c:517
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:444
u8 * format_dpdk_rx_trace(u8 *s, va_list *va)
Definition: format.c:748
struct _unformat_input_t unformat_input_t
#define foreach_dpdk_counter
Definition: format.c:31
u8 data[256]
Definition: dpdk.h:447
dpdk_port_type_t port_type
Definition: dpdk.h:263
format_function_t format_sfp_eeprom
Definition: sfp.h:133
format_function_t * format_buffer
Definition: node.h:356
u16 tx_q_used
Definition: dpdk.h:226
u16 nb_rx_desc
Definition: dpdk.h:228
u8 name[64]
Definition: memclnt.api:152
u32 hw_if_index
Definition: dpdk.h:205
u8 len
Definition: ip_types.api:49
u16 af_packet_instance_num
Definition: dpdk.h:247
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
svmdb_client_t * c
dpdk_device_t * devices
Definition: dpdk.h:404
vlib_main_t * vm
Definition: buffer.c:312
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:341
#define clib_warning(format, args...)
Definition: error.h:59
dpdk_pmd_t pmd
Definition: dpdk.h:211
u8 * format_hexdump(u8 *s, va_list *va)
Definition: std-formats.c:281
struct rte_eth_xstat * xstats
Definition: dpdk.h:260
struct rte_mbuf mb
Definition: dpdk.h:444
u8 * interface_name_suffix
Definition: dpdk.h:220
static const char * ptr2sname(void *p)
Definition: format.c:542
u16 device_index
Definition: dpdk.h:453
#define ASSERT(truth)
u8 * format_dpdk_device_errors(u8 *s, va_list *args)
Definition: format.c:503
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:205
clib_error_t * unformat_rss_fn(unformat_input_t *input, uword *rss_fn)
Definition: format.c:896
u8 * format_dpdk_tx_offload_caps(u8 *s, va_list *args)
Definition: format.c:482
u8 * format_dpdk_rx_offload_caps(u8 *s, va_list *args)
Definition: format.c:463
vlib_buffer_t buffer
Definition: dpdk.h:456
vlib_trace_main_t trace_main
Definition: main.h:141
void dpdk_update_link_state(dpdk_device_t *xd, f64 now)
Definition: init.c:1398
struct rte_eth_link link
Definition: dpdk.h:254
u32 buffer_index
Definition: dpdk.h:452
static void * clib_mem_alloc(uword size)
Definition: mem.h:132
u8 * name
Definition: dpdk.h:219
vlib_buffer_t buffer
Definition: dpdk.h:446
u8 data[256]
Definition: dpdk.h:457
static u8 * format_dpdk_device_type(u8 *s, va_list *args)
Definition: format.c:262
#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:442
#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:212
static u8 * format_dpdk_link_status(u8 *s, va_list *args)
Definition: format.c:384
struct rte_mbuf mb
Definition: dpdk.h:455
u8 queue_index
Definition: dpdk.h:443
u16 nb_tx_desc
Definition: dpdk.h:216
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:428
u16 queue_index
Definition: dpdk.h:454
vlib_main_t * vlib_main
Definition: dpdk.h:426