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