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