FD.io VPP  v19.08-27-gf4dcae4
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  /* format_c_identifier doesn't like c strings inside vector */
680  u8 * name = format(0,"%s", xstat_names[i].name);
681  xs = format(xs, "\n%U%-38U%16Lu",
682  format_white_space, indent + 4,
683  format_c_identifier, name, xstat->value);
684  vec_free(name);
685  }
686  }
687  /* *INDENT-ON* */
688 
689  vec_free (xstat_names);
690  }
691 
692  if (xs)
693  {
694  s = format (s, "\n%Uextended stats:%v",
695  format_white_space, indent + 2, xs);
696  vec_free (xs);
697  }
698 
699  if (vec_len (xd->errors))
700  {
701  s = format (s, "%UErrors:\n %U", format_white_space, indent,
703  }
704 
705  return s;
706 }
707 
708 u8 *
709 format_dpdk_tx_trace (u8 * s, va_list * va)
710 {
711  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
712  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
714  dpdk_tx_trace_t *t = va_arg (*va, dpdk_tx_trace_t *);
715  dpdk_main_t *dm = &dpdk_main;
717  u32 indent = format_get_indent (s);
719 
720  s = format (s, "%U tx queue %d",
722 
723  s = format (s, "\n%Ubuffer 0x%x: %U",
724  format_white_space, indent,
726 
727  s = format (s, "\n%U%U",
728  format_white_space, indent,
729  format_dpdk_rte_mbuf, &t->mb, &t->data);
730 
731  s = format (s, "\n%U%U", format_white_space, indent,
733  sizeof (t->buffer.pre_data));
734 
735  return s;
736 }
737 
738 u8 *
739 format_dpdk_rx_trace (u8 * s, va_list * va)
740 {
741  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
742  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
744  dpdk_rx_trace_t *t = va_arg (*va, dpdk_rx_trace_t *);
745  dpdk_main_t *dm = &dpdk_main;
748  u32 indent = format_get_indent (s);
750 
751  s = format (s, "%U rx queue %d",
753 
754  s = format (s, "\n%Ubuffer 0x%x: %U",
755  format_white_space, indent,
757 
758  s = format (s, "\n%U%U",
759  format_white_space, indent,
760  format_dpdk_rte_mbuf, &t->mb, &t->data);
761 
762  if (vm->trace_main.verbose)
763  {
764  s = format (s, "\n%UPacket Dump%s", format_white_space, indent + 2,
765  t->mb.data_len > sizeof (t->data) ? " (truncated)" : "");
766  s = format (s, "\n%U%U", format_white_space, indent + 4,
767  format_hexdump, &t->data,
768  t->mb.data_len >
769  sizeof (t->data) ? sizeof (t->data) : t->mb.data_len);
770  }
771  f = node->format_buffer;
772  if (!f)
773  f = format_hex_bytes;
774  s = format (s, "\n%U%U", format_white_space, indent,
775  f, t->buffer.pre_data, sizeof (t->buffer.pre_data));
776 
777  return s;
778 }
779 
780 
781 static inline u8 *
782 format_dpdk_pkt_types (u8 * s, va_list * va)
783 {
784  u32 *pkt_types = va_arg (*va, u32 *);
785  u32 indent __attribute__ ((unused)) = format_get_indent (s) + 2;
786 
787  if (!*pkt_types)
788  return s;
789 
790  s = format (s, "Packet Types");
791 
792 #define _(L, F, S) \
793  if ((*pkt_types & RTE_PTYPE_##L##_MASK) == RTE_PTYPE_##L##_##F) \
794  { \
795  s = format (s, "\n%U%s (0x%04x) %s", format_white_space, indent, \
796  "RTE_PTYPE_" #L "_" #F, RTE_PTYPE_##L##_##F, S); \
797  }
798 
800 #undef _
801  return s;
802 }
803 
804 static inline u8 *
806 {
807  u64 *ol_flags = va_arg (*va, u64 *);
808  u32 indent = format_get_indent (s) + 2;
809 
810  if (!*ol_flags)
811  return s;
812 
813  s = format (s, "Packet Offload Flags");
814 
815 #define _(F, S) \
816  if (*ol_flags & F) \
817  { \
818  s = format (s, "\n%U%s (0x%04x) %s", \
819  format_white_space, indent, #F, F, S); \
820  }
821 
823 #undef _
824  return s;
825 }
826 
827 u8 *
828 format_dpdk_rte_mbuf_vlan (u8 * s, va_list * va)
829 {
830  ethernet_vlan_header_tv_t *vlan_hdr =
831  va_arg (*va, ethernet_vlan_header_tv_t *);
832 
833  if (clib_net_to_host_u16 (vlan_hdr->type) == ETHERNET_TYPE_DOT1AD)
834  {
835  s = format (s, "%U 802.1q vlan ",
837  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
838  vlan_hdr++;
839  }
840 
841  s = format (s, "%U",
843  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
844 
845  return s;
846 }
847 
848 u8 *
849 format_dpdk_rte_mbuf (u8 * s, va_list * va)
850 {
851  struct rte_mbuf *mb = va_arg (*va, struct rte_mbuf *);
852  ethernet_header_t *eth_hdr = va_arg (*va, ethernet_header_t *);
853  u32 indent = format_get_indent (s) + 2;
854 
855  s = format (s, "PKT MBUF: port %d, nb_segs %d, pkt_len %d"
856  "\n%Ubuf_len %d, data_len %d, ol_flags 0x%lx, data_off %d, phys_addr 0x%x"
857  "\n%Upacket_type 0x%x l2_len %u l3_len %u outer_l2_len %u outer_l3_len %u"
858  "\n%Urss 0x%x fdir.hi 0x%x fdir.lo 0x%x",
859  mb->port, mb->nb_segs, mb->pkt_len,
860  format_white_space, indent,
861  mb->buf_len, mb->data_len, mb->ol_flags, mb->data_off,
862  mb->buf_physaddr, format_white_space, indent, mb->packet_type,
863  mb->l2_len, mb->l3_len, mb->outer_l2_len, mb->outer_l3_len,
864  format_white_space, indent, mb->hash.rss, mb->hash.fdir.hi,
865  mb->hash.fdir.lo);
866 
867  if (mb->ol_flags)
868  s = format (s, "\n%U%U", format_white_space, indent,
869  format_dpdk_pkt_offload_flags, &mb->ol_flags);
870 
871  if ((mb->ol_flags & PKT_RX_VLAN) &&
872  ((mb->ol_flags & (PKT_RX_VLAN_STRIPPED | PKT_RX_QINQ_STRIPPED)) == 0))
873  {
874  ethernet_vlan_header_tv_t *vlan_hdr =
875  ((ethernet_vlan_header_tv_t *) & (eth_hdr->type));
876  s = format (s, " %U", format_dpdk_rte_mbuf_vlan, vlan_hdr);
877  }
878 
879  if (mb->packet_type)
880  s = format (s, "\n%U%U", format_white_space, indent,
881  format_dpdk_pkt_types, &mb->packet_type);
882 
883  return s;
884 }
885 
886 clib_error_t *
888 {
890  {
891  if (0)
892  ;
893 #undef _
894 #define _(f, s) \
895  else if (unformat (input, s)) \
896  *rss_fn |= f;
897 
899 #undef _
900  else
901  {
902  return clib_error_return (0, "unknown input `%U'",
903  format_unformat_error, input);
904  }
905  }
906  return 0;
907 }
908 
909 clib_error_t *
911 {
912  clib_error_t *error = 0;
913 
915  {
916  if (unformat (input, "hqos-thread %u", &hqos->hqos_thread))
917  hqos->hqos_thread_valid = 1;
918  else
919  {
920  error = clib_error_return (0, "unknown input `%U'",
921  format_unformat_error, input);
922  break;
923  }
924  }
925 
926  return error;
927 }
928 
929 /*
930  * fd.io coding-style-patch-verification: ON
931  *
932  * Local Variables:
933  * eval: (c-set-style "gnu")
934  * End:
935  */
#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:82
u8 * format_dpdk_tx_trace(u8 *s, va_list *va)
Definition: format.c:709
u8 * format_dpdk_rte_mbuf_vlan(u8 *s, va_list *va)
Definition: format.c:828
u8 interface_name_format_decimal
Definition: dpdk.h:361
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:258
clib_error_t * unformat_hqos(unformat_input_t *input, dpdk_device_config_hqos_t *hqos)
Definition: format.c:910
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:805
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:849
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
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:429
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:782
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:436
u8 * format_dpdk_rx_trace(u8 *s, va_list *va)
Definition: format.c:739
struct _unformat_input_t unformat_input_t
#define foreach_dpdk_counter
Definition: format.c:31
u8 data[256]
Definition: dpdk.h:435
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:356
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:392
vlib_main_t * vm
Definition: buffer.c:312
static void dpdk_update_counters(dpdk_device_t *xd, f64 now)
Definition: dpdk_priv.h:77
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
#define clib_warning(format, args...)
Definition: error.h:59
dpdk_pmd_t pmd
Definition: dpdk.h: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:432
u8 * interface_name_suffix
Definition: dpdk.h:215
static const char * ptr2sname(void *p)
Definition: format.c:533
u16 device_index
Definition: dpdk.h:441
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:887
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:444
vlib_trace_main_t trace_main
Definition: main.h:146
void dpdk_update_link_state(dpdk_device_t *xd, f64 now)
Definition: init.c:1476
struct rte_eth_link link
Definition: dpdk.h:244
u32 buffer_index
Definition: dpdk.h:440
static void * clib_mem_alloc(uword size)
Definition: mem.h:153
u8 * name
Definition: dpdk.h:214
vlib_buffer_t buffer
Definition: dpdk.h:434
u8 data[256]
Definition: dpdk.h:445
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:430
#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:443
u8 queue_index
Definition: dpdk.h:431
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:416
u16 queue_index
Definition: dpdk.h:442
vlib_main_t * vlib_main
Definition: dpdk.h:414