FD.io VPP  v21.01.1
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 
61 #define foreach_dpdk_pkt_type \
62  _ (L2, ETHER, "Ethernet packet") \
63  _ (L2, ETHER_TIMESYNC, "Ethernet packet for time sync") \
64  _ (L2, ETHER_ARP, "ARP packet") \
65  _ (L2, ETHER_LLDP, "LLDP (Link Layer Discovery Protocol) packet") \
66  _ (L2, ETHER_NSH, "NSH (Network Service Header) packet") \
67  _ (L2, ETHER_VLAN, "VLAN packet") \
68  _ (L2, ETHER_QINQ, "QinQ packet") \
69  _ (L3, IPV4, "IPv4 packet without extension headers") \
70  _ (L3, IPV4_EXT, "IPv4 packet with extension headers") \
71  _ (L3, IPV4_EXT_UNKNOWN, "IPv4 packet with or without extension headers") \
72  _ (L3, IPV6, "IPv6 packet without extension headers") \
73  _ (L3, IPV6_EXT, "IPv6 packet with extension headers") \
74  _ (L3, IPV6_EXT_UNKNOWN, "IPv6 packet with or without extension headers") \
75  _ (L4, TCP, "TCP packet") \
76  _ (L4, UDP, "UDP packet") \
77  _ (L4, FRAG, "Fragmented IP packet") \
78  _ (L4, SCTP, "SCTP (Stream Control Transmission Protocol) packet") \
79  _ (L4, ICMP, "ICMP packet") \
80  _ (L4, NONFRAG, "Non-fragmented IP packet") \
81  _ (TUNNEL, GRE, "GRE tunneling packet") \
82  _ (TUNNEL, VXLAN, "VXLAN tunneling packet") \
83  _ (TUNNEL, NVGRE, "NVGRE Tunneling packet") \
84  _ (TUNNEL, GENEVE, "GENEVE Tunneling packet") \
85  _ (TUNNEL, GRENAT, "Teredo, VXLAN or GRE Tunneling packet") \
86  _ (INNER_L2, ETHER, "Inner Ethernet packet") \
87  _ (INNER_L2, ETHER_VLAN, "Inner Ethernet packet with VLAN") \
88  _ (INNER_L3, IPV4, "Inner IPv4 packet without extension headers") \
89  _ (INNER_L3, IPV4_EXT, "Inner IPv4 packet with extension headers") \
90  _ (INNER_L3, IPV4_EXT_UNKNOWN, "Inner IPv4 packet with or without extension headers") \
91  _ (INNER_L3, IPV6, "Inner IPv6 packet without extension headers") \
92  _ (INNER_L3, IPV6_EXT, "Inner IPv6 packet with extension headers") \
93  _ (INNER_L3, IPV6_EXT_UNKNOWN, "Inner IPv6 packet with or without extension headers") \
94  _ (INNER_L4, TCP, "Inner TCP packet") \
95  _ (INNER_L4, UDP, "Inner UDP packet") \
96  _ (INNER_L4, FRAG, "Inner fragmented IP packet") \
97  _ (INNER_L4, SCTP, "Inner SCTP (Stream Control Transmission Protocol) packet") \
98  _ (INNER_L4, ICMP, "Inner ICMP packet") \
99  _ (INNER_L4, NONFRAG, "Inner non-fragmented IP packet")
100 
101 #define foreach_dpdk_pkt_tx_offload_flag \
102  _ (PKT_TX_VLAN_PKT, "TX packet is a 802.1q VLAN packet") \
103  _ (PKT_TX_IP_CKSUM, "IP cksum of TX pkt. computed by NIC") \
104  _ (PKT_TX_TCP_CKSUM, "TCP cksum of TX pkt. computed by NIC") \
105  _ (PKT_TX_SCTP_CKSUM, "SCTP cksum of TX pkt. computed by NIC") \
106  _ (PKT_TX_IEEE1588_TMST, "TX IEEE1588 packet to timestamp")
107 
108 #define foreach_dpdk_pkt_offload_flag \
109  foreach_dpdk_pkt_rx_offload_flag \
110  foreach_dpdk_pkt_tx_offload_flag
111 
112 #define foreach_dpdk_pkt_dyn_rx_offload_flag \
113  _ (RX_TIMESTAMP, 0, "Timestamp field is valid")
114 
115 u8 *
116 format_dpdk_device_name (u8 * s, va_list * args)
117 {
118  dpdk_main_t *dm = &dpdk_main;
119  char *devname_format;
120  char *device_name;
121  u32 i = va_arg (*args, u32);
122  dpdk_device_t *xd = vec_elt_at_index (dm->devices, i);
123  struct rte_eth_dev_info dev_info;
124  struct rte_pci_device *pci_dev;
125  u8 *ret;
126 
127  if (xd->name)
128  return format (s, "%s", xd->name);
129 
131  devname_format = "%s%d/%d/%d";
132  else
133  devname_format = "%s%x/%x/%x";
134 
135  switch (xd->port_type)
136  {
138  device_name = "GigabitEthernet";
139  break;
140 
142  device_name = "Two_FiveGigabitEthernet";
143  break;
144 
146  device_name = "FiveGigabitEthernet";
147  break;
148 
150  device_name = "TenGigabitEthernet";
151  break;
152 
154  device_name = "TwentyGigabitEthernet";
155  break;
156 
158  device_name = "TwentyFiveGigabitEthernet";
159  break;
160 
162  device_name = "FortyGigabitEthernet";
163  break;
164 
166  device_name = "FiftyGigabitEthernet";
167  break;
168 
170  device_name = "FiftySixGigabitEthernet";
171  break;
172 
174  device_name = "HundredGigabitEthernet";
175  break;
176 
178  device_name = "EthernetSwitch";
179  break;
180 
182  device_name = "VirtualFunctionEthernet";
183  break;
184 
186  return format (s, "af_packet%d", xd->af_packet_instance_num);
187 
189  device_name = "VirtioUser";
190  break;
191 
193  device_name = "VhostEthernet";
194  break;
195 
197  device_name = "FailsafeEthernet";
198  break;
199 
200  default:
202  device_name = "UnknownEthernet";
203  break;
204  }
205 
206  rte_eth_dev_info_get (xd->port_id, &dev_info);
207  pci_dev = dpdk_get_pci_device (&dev_info);
208 
209  if (pci_dev && xd->port_type != VNET_DPDK_PORT_TYPE_FAILSAFE)
210  ret = format (s, devname_format, device_name, pci_dev->addr.bus,
211  pci_dev->addr.devid, pci_dev->addr.function);
212  else
213  ret = format (s, "%s%d", device_name, xd->port_id);
214 
215  if (xd->interface_name_suffix)
216  return format (ret, "/%s", xd->interface_name_suffix);
217  return ret;
218 }
219 
220 u8 *
221 format_dpdk_device_flags (u8 * s, va_list * args)
222 {
223  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
224  u8 *t = 0;
225 
226 #define _(a, b, c) if (xd->flags & (1 << a)) \
227 t = format (t, "%s%s", t ? " ":"", c);
229 #undef _
230  s = format (s, "%v", t);
231  vec_free (t);
232  return s;
233 }
234 
235 static u8 *
236 format_dpdk_device_type (u8 * s, va_list * args)
237 {
238  dpdk_main_t *dm = &dpdk_main;
239  char *dev_type;
240  u32 i = va_arg (*args, u32);
241 
242  switch (dm->devices[i].pmd)
243  {
244  case VNET_DPDK_PMD_E1000EM:
245  dev_type = "Intel 82540EM (e1000)";
246  break;
247 
248  case VNET_DPDK_PMD_IGB:
249  dev_type = "Intel e1000";
250  break;
251 
252  case VNET_DPDK_PMD_I40E:
253  dev_type = "Intel X710/XL710 Family";
254  break;
255 
256  case VNET_DPDK_PMD_I40EVF:
257  dev_type = "Intel X710/XL710 Family VF";
258  break;
259 
260  case VNET_DPDK_PMD_ICE:
261  dev_type = "Intel E810 Family";
262  break;
263 
264  case VNET_DPDK_PMD_IAVF:
265  dev_type = "Intel iAVF";
266  break;
267 
268  case VNET_DPDK_PMD_FM10K:
269  dev_type = "Intel FM10000 Family Ethernet Switch";
270  break;
271 
272  case VNET_DPDK_PMD_IGBVF:
273  dev_type = "Intel e1000 VF";
274  break;
275 
276  case VNET_DPDK_PMD_VIRTIO:
277  dev_type = "Red Hat Virtio";
278  break;
279 
280  case VNET_DPDK_PMD_IXGBEVF:
281  dev_type = "Intel 82599 VF";
282  break;
283 
284  case VNET_DPDK_PMD_IXGBE:
285  dev_type = "Intel 82599";
286  break;
287 
288  case VNET_DPDK_PMD_ENIC:
289  dev_type = "Cisco VIC";
290  break;
291 
292  case VNET_DPDK_PMD_CXGBE:
293  dev_type = "Chelsio T4/T5";
294  break;
295 
296  case VNET_DPDK_PMD_MLX4:
297  dev_type = "Mellanox ConnectX-3 Family";
298  break;
299 
300  case VNET_DPDK_PMD_MLX5:
301  dev_type = "Mellanox ConnectX-4 Family";
302  break;
303 
304  case VNET_DPDK_PMD_VMXNET3:
305  dev_type = "VMware VMXNET3";
306  break;
307 
308  case VNET_DPDK_PMD_AF_PACKET:
309  dev_type = "af_packet";
310  break;
311 
312  case VNET_DPDK_PMD_DPAA2:
313  dev_type = "NXP DPAA2 Mac";
314  break;
315 
316  case VNET_DPDK_PMD_VIRTIO_USER:
317  dev_type = "Virtio User";
318  break;
319 
320  case VNET_DPDK_PMD_THUNDERX:
321  dev_type = "Cavium ThunderX";
322  break;
323 
324  case VNET_DPDK_PMD_VHOST_ETHER:
325  dev_type = "VhostEthernet";
326  break;
327 
328  case VNET_DPDK_PMD_ENA:
329  dev_type = "AWS ENA VF";
330  break;
331 
332  case VNET_DPDK_PMD_FAILSAFE:
333  dev_type = "FailsafeEthernet";
334  break;
335 
336  case VNET_DPDK_PMD_LIOVF_ETHER:
337  dev_type = "Cavium Lio VF";
338  break;
339 
340  case VNET_DPDK_PMD_QEDE:
341  dev_type = "Cavium QLogic FastLinQ QL4xxxx";
342  break;
343 
344  case VNET_DPDK_PMD_NETVSC:
345  dev_type = "Microsoft Hyper-V Netvsc";
346  break;
347 
348  case VNET_DPDK_PMD_BNXT:
349  dev_type = "Broadcom NetXtreme E/S-Series";
350  break;
351 
352  default:
354  dev_type = "### UNKNOWN ###";
355  break;
356  }
357 
358  return format (s, dev_type);
359 }
360 
361 static u8 *
362 format_dpdk_link_status (u8 * s, va_list * args)
363 {
364  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
365  struct rte_eth_link *l = &xd->link;
366  vnet_main_t *vnm = vnet_get_main ();
368 
369  s = format (s, "%s ", l->link_status ? "up" : "down");
370  if (l->link_status)
371  {
372  u32 promisc = rte_eth_promiscuous_get (xd->port_id);
373 
374  s = format (s, "%s duplex ", (l->link_duplex == ETH_LINK_FULL_DUPLEX) ?
375  "full" : "half");
376  s = format (s, "mtu %d %s\n", hi->max_packet_bytes, promisc ?
377  " promisc" : "");
378  }
379  else
380  s = format (s, "\n");
381 
382  return s;
383 }
384 
385 #define _(n, v, str) \
386 if (bitmap & v) { \
387  if (format_get_indent (s) > 72) \
388  s = format(s,"\n%U", format_white_space, indent); \
389  s = format(s, "%s ", str); \
390 }
391 
392 u8 *
393 format_dpdk_rss_hf_name (u8 * s, va_list * args)
394 {
395  u64 bitmap = va_arg (*args, u64);
396  u32 indent = format_get_indent (s);
397 
398  if (!bitmap)
399  return format (s, "none");
400 
401  foreach_dpdk_rss_hf return s;
402 }
403 
404 #undef _
405 
406 /* Convert to all lower case e.g "VLAN_STRIP" -> "vlan-strip"
407  Works for both vector names and null terminated c strings. */
408 static u8 *
409 format_offload (u8 * s, va_list * va)
410 {
411  u8 *id = va_arg (*va, u8 *);
412  uword i, l;
413 
414  l = ~0;
415  if (clib_mem_is_vec (id))
416  l = vec_len (id);
417 
418  if (id)
419  for (i = 0; id[i] != 0 && i < l; i++)
420  {
421  u8 c = id[i];
422 
423  if (c == '_')
424  c = '-';
425  else
426  c = tolower (c);
427  vec_add1 (s, c);
428  }
429 
430  return s;
431 }
432 
433 #define _(v, func) \
434 if (bitmap & v) { \
435  if (format_get_indent (s) > 72) \
436  s = format(s,"\n%U", format_white_space, indent); \
437  s = format(s, "%U ", format_offload, func (v)); \
438 }
439 
440 u8 *
441 format_dpdk_rx_offload_caps (u8 * s, va_list * args)
442 {
443  u64 bitmap = va_arg (*args, u32);
444  u32 indent = format_get_indent (s);
445  uword i;
446 
447  if (!bitmap)
448  return format (s, "none");
449 
450  for (i = 0; i < 64; i++)
451  {
452  u64 mask = (u64) 1 << i;
453 
454  _(mask, rte_eth_dev_rx_offload_name);
455  }
456  return s;
457 }
458 
459 u8 *
460 format_dpdk_tx_offload_caps (u8 * s, va_list * args)
461 {
462  u64 bitmap = va_arg (*args, u32);
463  u32 indent = format_get_indent (s);
464  uword i;
465 
466  if (!bitmap)
467  return format (s, "none");
468 
469  for (i = 0; i < 64; i++)
470  {
471  u64 mask = (u64) 1 << i;
472 
473  _(mask, rte_eth_dev_tx_offload_name);
474  }
475  return s;
476 }
477 
478 #undef _
479 
480 u8 *
481 format_dpdk_device_errors (u8 * s, va_list * args)
482 {
483  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
484  clib_error_t *e;
485  u32 indent = format_get_indent (s);
486 
487  vec_foreach (e, xd->errors)
488  {
489  s = format (s, "%U%v\n", format_white_space, indent, e->what);
490  }
491  return s;
492 }
493 
494 static u8 *
495 format_dpdk_device_module_info (u8 * s, va_list * args)
496 {
497  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
498  struct rte_eth_dev_module_info mi = { 0 };
499  struct rte_dev_eeprom_info ei = { 0 };
500 
501  if (rte_eth_dev_get_module_info (xd->port_id, &mi) != 0)
502  return format (s, "unknown");
503 
504  ei.length = mi.eeprom_len;
505  ei.data = clib_mem_alloc (mi.eeprom_len);
506 
507  if (rte_eth_dev_get_module_eeprom (xd->port_id, &ei) == 0)
508  {
509  s = format (s, "%U", format_sfp_eeprom, ei.data +
510  (mi.type == RTE_ETH_MODULE_SFF_8436 ? 0x80 : 0));
511  }
512  else
513  s = format (s, "eeprom read error");
514 
515  clib_mem_free (ei.data);
516  return s;
517 }
518 
519 static const char *
520 ptr2sname (void *p)
521 {
522  Dl_info info = { 0 };
523 
524  if (dladdr (p, &info) == 0)
525  return 0;
526 
527  return info.dli_sname;
528 }
529 
530 static u8 *
531 format_switch_info (u8 * s, va_list * args)
532 {
533  struct rte_eth_switch_info *si =
534  va_arg (*args, struct rte_eth_switch_info *);
535 
536  if (si->name)
537  s = format (s, "name %s ", si->name);
538 
539  s = format (s, "domain id %d port id %d", si->domain_id, si->port_id);
540 
541  return s;
542 }
543 
544 u8 *
545 format_dpdk_device (u8 * s, va_list * args)
546 {
547  u32 dev_instance = va_arg (*args, u32);
548  int verbose = va_arg (*args, int);
549  dpdk_main_t *dm = &dpdk_main;
550  dpdk_device_t *xd = vec_elt_at_index (dm->devices, dev_instance);
551  u32 indent = format_get_indent (s);
552  f64 now = vlib_time_now (dm->vlib_main);
553  struct rte_eth_dev_info di;
554  struct rte_eth_burst_mode mode;
555 
556  dpdk_update_counters (xd, now);
557  dpdk_update_link_state (xd, now);
558  rte_eth_dev_info_get (xd->port_id, &di);
559 
560  s = format (s, "%U\n%Ucarrier %U",
561  format_dpdk_device_type, dev_instance,
563  s = format (s, "%Uflags: %U\n",
565  if (di.device->devargs && di.device->devargs->args)
566  s = format (s, "%UDevargs: %s\n",
567  format_white_space, indent + 2, di.device->devargs->args);
568  s = format (s, "%Urx: queues %d (max %d), desc %d "
569  "(min %d max %d align %d)\n",
570  format_white_space, indent + 2, xd->rx_q_used, di.max_rx_queues,
571  xd->nb_rx_desc, di.rx_desc_lim.nb_min, di.rx_desc_lim.nb_max,
572  di.rx_desc_lim.nb_align);
573  s = format (s, "%Utx: queues %d (max %d), desc %d "
574  "(min %d max %d align %d)\n",
575  format_white_space, indent + 2, xd->tx_q_used, di.max_tx_queues,
576  xd->nb_tx_desc, di.tx_desc_lim.nb_min, di.tx_desc_lim.nb_max,
577  di.tx_desc_lim.nb_align);
578 
579  if (xd->flags & DPDK_DEVICE_FLAG_PMD)
580  {
581  struct rte_pci_device *pci;
582  struct rte_eth_rss_conf rss_conf;
583  int vlan_off;
584  int retval;
585 
586  rss_conf.rss_key = 0;
587  rss_conf.rss_hf = 0;
588  retval = rte_eth_dev_rss_hash_conf_get (xd->port_id, &rss_conf);
589  if (retval < 0)
590  clib_warning ("rte_eth_dev_rss_hash_conf_get returned %d", retval);
591 
592  pci = dpdk_get_pci_device (&di);
593 
594  if (pci)
595  {
596  u8 *s2;
597  if (xd->cpu_socket > -1)
598  s2 = format (0, "%d", xd->cpu_socket);
599  else
600  s2 = format (0, "unknown");
601  s = format (s, "%Upci: device %04x:%04x subsystem %04x:%04x "
602  "address %04x:%02x:%02x.%02x numa %v\n",
603  format_white_space, indent + 2, pci->id.vendor_id,
604  pci->id.device_id, pci->id.subsystem_vendor_id,
605  pci->id.subsystem_device_id, pci->addr.domain,
606  pci->addr.bus, pci->addr.devid, pci->addr.function, s2);
607  vec_free (s2);
608  }
609 
610  if (di.switch_info.domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
611  {
612  s =
613  format (s, "%Uswitch info: %U\n", format_white_space, indent + 2,
614  format_switch_info, &di.switch_info);
615  }
616 
617  if (1 < verbose)
618  {
619  s = format (s, "%Umodule: %U\n", format_white_space, indent + 2,
621  }
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 
654  if (rte_eth_tx_burst_mode_get (xd->port_id, 0, &mode) == 0)
655  {
656  s = format (s, "%Utx burst mode: %s%s\n",
657  format_white_space, indent + 2,
658  mode.info,
659  mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
660  " (per queue)" : "");
661  }
662  else
663  {
664  s = format (s, "%Utx burst function: %s\n",
665  format_white_space, indent + 2,
666  ptr2sname (rte_eth_devices[xd->port_id].tx_pkt_burst));
667  }
668 
669  if (rte_eth_rx_burst_mode_get (xd->port_id, 0, &mode) == 0)
670  {
671  s = format (s, "%Urx burst mode: %s%s\n",
672  format_white_space, indent + 2,
673  mode.info,
674  mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
675  " (per queue)" : "");
676  }
677  else
678  {
679  s = format (s, "%Urx burst function: %s\n",
680  format_white_space, indent + 2,
681  ptr2sname (rte_eth_devices[xd->port_id].rx_pkt_burst));
682  }
683  }
684 
685  /* $$$ MIB counters */
686  {
687 #define _(N, V) \
688  if (xd->stats.V != 0) { \
689  s = format (s, "\n%U%-40U%16Lu", \
690  format_white_space, indent + 2, \
691  format_c_identifier, #N, \
692  xd->stats.V); \
693  } \
694 
696 #undef _
697  }
698 
699  u8 *xs = 0;
700  u32 i = 0;
701  struct rte_eth_xstat *xstat;
702  struct rte_eth_xstat_name *xstat_names = 0;
703  int len = vec_len (xd->xstats);
704  vec_validate (xstat_names, len - 1);
705  int ret = rte_eth_xstats_get_names (xd->port_id, xstat_names, len);
706 
707  if (ret >= 0 && ret <= len)
708  {
709  /* *INDENT-OFF* */
710  vec_foreach_index(i, xd->xstats)
711  {
712  xstat = vec_elt_at_index(xd->xstats, i);
713  if (verbose == 2 || (verbose && xstat->value))
714  {
715  xs = format(xs, "\n%U%-38s%16Lu",
716  format_white_space, indent + 4,
717  xstat_names[i].name,
718  xstat->value);
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  u64 rx_dynflag;
844  int rx_dynflag_offset;
845 
846  if (!*ol_flags)
847  return s;
848 
849  s = format (s, "Packet Offload Flags");
850 
851 #define _(F, S) \
852  if (*ol_flags & F) \
853  { \
854  s = format (s, "\n%U%s (0x%04x) %s", \
855  format_white_space, indent, #F, F, S); \
856  }
857 
859 #undef _
860 #define _(F, P, S) \
861  { \
862  rx_dynflag_offset = rte_mbuf_dynflag_lookup(RTE_MBUF_DYNFLAG_##F##_NAME, \
863  P); \
864  if (rx_dynflag_offset >= 0) \
865  { \
866  rx_dynflag = (u64) 1 << rx_dynflag_offset; \
867  if (*ol_flags & rx_dynflag) \
868  { \
869  s = format (s, "\n%U%s %s", format_white_space, indent, \
870  #F, S); \
871  } \
872  } \
873  }
875 #undef _
876  return s;
877 }
878 
879 u8 *
880 format_dpdk_rte_mbuf_vlan (u8 * s, va_list * va)
881 {
882  ethernet_vlan_header_tv_t *vlan_hdr =
883  va_arg (*va, ethernet_vlan_header_tv_t *);
884 
885  if (clib_net_to_host_u16 (vlan_hdr->type) == ETHERNET_TYPE_DOT1AD)
886  {
887  s = format (s, "%U 802.1q vlan ",
889  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
890  vlan_hdr++;
891  }
892 
893  s = format (s, "%U",
895  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
896 
897  return s;
898 }
899 
900 u8 *
901 format_dpdk_rte_mbuf (u8 * s, va_list * va)
902 {
903  struct rte_mbuf *mb = va_arg (*va, struct rte_mbuf *);
904  ethernet_header_t *eth_hdr = va_arg (*va, ethernet_header_t *);
905  u32 indent = format_get_indent (s) + 2;
906 
907  s = format (s, "PKT MBUF: port %d, nb_segs %d, pkt_len %d"
908  "\n%Ubuf_len %d, data_len %d, ol_flags 0x%lx, data_off %d, phys_addr 0x%x"
909  "\n%Upacket_type 0x%x l2_len %u l3_len %u outer_l2_len %u outer_l3_len %u"
910  "\n%Urss 0x%x fdir.hi 0x%x fdir.lo 0x%x",
911  mb->port, mb->nb_segs, mb->pkt_len,
912  format_white_space, indent,
913  mb->buf_len, mb->data_len, mb->ol_flags, mb->data_off,
914  mb->buf_iova, format_white_space, indent, mb->packet_type,
915  mb->l2_len, mb->l3_len, mb->outer_l2_len, mb->outer_l3_len,
916  format_white_space, indent, mb->hash.rss, mb->hash.fdir.hi,
917  mb->hash.fdir.lo);
918 
919  if (mb->ol_flags)
920  s = format (s, "\n%U%U", format_white_space, indent,
921  format_dpdk_pkt_offload_flags, &mb->ol_flags);
922 
923  if ((mb->ol_flags & PKT_RX_VLAN) &&
924  ((mb->ol_flags & (PKT_RX_VLAN_STRIPPED | PKT_RX_QINQ_STRIPPED)) == 0))
925  {
926  ethernet_vlan_header_tv_t *vlan_hdr =
927  ((ethernet_vlan_header_tv_t *) & (eth_hdr->type));
928  s = format (s, " %U", format_dpdk_rte_mbuf_vlan, vlan_hdr);
929  }
930 
931  if (mb->packet_type)
932  s = format (s, "\n%U%U", format_white_space, indent,
933  format_dpdk_pkt_types, &mb->packet_type);
934 
935  return s;
936 }
937 
938 clib_error_t *
940 {
942  {
943  if (0)
944  ;
945 #undef _
946 #define _(n, f, s) \
947  else if (unformat (input, s)) \
948  *rss_fn |= f;
949 
951 #undef _
952  else
953  {
954  return clib_error_return (0, "unknown input `%U'",
955  format_unformat_error, input);
956  }
957  }
958  return 0;
959 }
960 
961 
962 /*
963  * fd.io coding-style-patch-verification: ON
964  *
965  * Local Variables:
966  * eval: (c-set-style "gnu")
967  * End:
968  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:509
u8 * format_dpdk_device(u8 *s, va_list *args)
Definition: format.c:545
#define vec_foreach_index(var, v)
Iterate over vector indices.
static u8 * format_offload(u8 *s, va_list *va)
Definition: format.c:409
u8 * format_dpdk_device_flags(u8 *s, va_list *args)
Definition: format.c:221
#define CLIB_UNUSED(x)
Definition: clib.h:87
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:880
u8 interface_name_format_decimal
Definition: dpdk.h:299
dpdk_main_t dpdk_main
Definition: init.c:47
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:393
unsigned long u64
Definition: types.h:89
u32 sw_if_index
Definition: dpdk.h:185
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:334
struct rte_pci_device * dpdk_get_pci_device(const struct rte_eth_dev_info *info)
Definition: common.c:252
u16 flags
Definition: dpdk.h:192
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:592
clib_error_t * errors
Definition: dpdk.h:237
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)
vlib_main_t * vm
Definition: in2out_ed.c:1580
u8 * format_dpdk_rte_mbuf(u8 *s, va_list *va)
Definition: format.c:901
u16 mask
Definition: flow_types.api:52
unsigned char u8
Definition: types.h:56
static u8 * format_switch_info(u8 *s, va_list *args)
Definition: format.c:531
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:116
dpdk_portid_t port_id
Definition: dpdk.h:195
u32 buffer_index
Definition: dpdk.h:364
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
#define foreach_dpdk_pkt_type
Definition: format.c:61
#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:190
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:210
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:495
format_function_t format_vnet_sw_interface_name
format_function_t format_vnet_buffer
Definition: buffer.h:497
__clib_export u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
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:368
dpdk_port_type_t port_type
Definition: dpdk.h:231
format_function_t format_sfp_eeprom
Definition: sfp.h:133
format_function_t * format_buffer
Definition: node.h:358
u16 tx_q_used
Definition: dpdk.h:191
u16 nb_rx_desc
Definition: dpdk.h:201
u32 hw_if_index
Definition: dpdk.h:184
u8 len
Definition: ip_types.api:103
u16 af_packet_instance_num
Definition: dpdk.h:222
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
svmdb_client_t * c
dpdk_device_t * devices
Definition: dpdk.h:330
static void dpdk_update_counters(dpdk_device_t *xd, f64 now)
Definition: dpdk_priv.h:95
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:196
u8 * format_hexdump(u8 *s, va_list *va)
Definition: std-formats.c:352
string name[64]
Definition: ip.api:44
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1580
struct rte_eth_xstat * xstats
Definition: dpdk.h:229
struct rte_mbuf mb
Definition: dpdk.h:367
u8 * interface_name_suffix
Definition: dpdk.h:204
static const char * ptr2sname(void *p)
Definition: format.c:520
u16 device_index
Definition: dpdk.h:376
u8 * format_dpdk_device_errors(u8 *s, va_list *args)
Definition: format.c:481
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:311
clib_error_t * unformat_rss_fn(unformat_input_t *input, uword *rss_fn)
Definition: format.c:939
u8 * format_dpdk_tx_offload_caps(u8 *s, va_list *args)
Definition: format.c:460
u8 * format_dpdk_rx_offload_caps(u8 *s, va_list *args)
Definition: format.c:441
vlib_buffer_t buffer
Definition: dpdk.h:380
#define foreach_dpdk_pkt_dyn_rx_offload_flag
Definition: format.c:112
vlib_trace_main_t trace_main
Definition: main.h:194
void dpdk_update_link_state(dpdk_device_t *xd, f64 now)
Definition: init.c:1554
struct rte_eth_link link
Definition: dpdk.h:224
u32 buffer_index
Definition: dpdk.h:375
static void * clib_mem_alloc(uword size)
Definition: mem.h:253
u8 * name
Definition: dpdk.h:203
vl_api_ip4_address_t hi
Definition: arp.api:37
vlib_buffer_t buffer
Definition: dpdk.h:370
u8 data[256]
Definition: dpdk.h:379
#define foreach_dpdk_rss_hf
Definition: dpdk.h:418
static u8 * format_dpdk_device_type(u8 *s, va_list *args)
Definition: format.c:236
#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:365
#define foreach_dpdk_pkt_offload_flag
Definition: format.c:108
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:197
static u8 * format_dpdk_link_status(u8 *s, va_list *args)
Definition: format.c:362
u8 si
Definition: lisp_types.api:47
struct rte_mbuf mb
Definition: dpdk.h:378
u8 queue_index
Definition: dpdk.h:366
u16 nb_tx_desc
Definition: dpdk.h:200
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:349
u16 queue_index
Definition: dpdk.h:377
vlib_main_t * vlib_main
Definition: dpdk.h:347