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