app/procinfo: add --show-crypto
[dpdk.git] / app / proc-info / main.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdint.h>
8 #include <errno.h>
9 #include <stdarg.h>
10 #include <inttypes.h>
11 #include <sys/queue.h>
12 #include <stdlib.h>
13 #include <getopt.h>
14 #include <unistd.h>
15
16 #include <rte_eal.h>
17 #include <rte_common.h>
18 #include <rte_debug.h>
19 #include <rte_ethdev.h>
20 #include <rte_malloc.h>
21 #include <rte_memory.h>
22 #include <rte_memzone.h>
23 #include <rte_launch.h>
24 #include <rte_tailq.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_log.h>
28 #include <rte_atomic.h>
29 #include <rte_branch_prediction.h>
30 #include <rte_string_fns.h>
31 #include <rte_metrics.h>
32 #include <rte_cycles.h>
33 #include <rte_security.h>
34 #include <rte_cryptodev.h>
35 #include <rte_tm.h>
36
37 /* Maximum long option length for option parsing. */
38 #define MAX_LONG_OPT_SZ 64
39 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
40
41 #define MAX_STRING_LEN 256
42
43 #define STATS_BDR_FMT "========================================"
44 #define STATS_BDR_STR(w, s) printf("%.*s%s%.*s\n", w, \
45         STATS_BDR_FMT, s, w, STATS_BDR_FMT)
46
47 /**< mask of enabled ports */
48 static uint32_t enabled_port_mask;
49 /**< Enable stats. */
50 static uint32_t enable_stats;
51 /**< Enable xstats. */
52 static uint32_t enable_xstats;
53 /**< Enable collectd format*/
54 static uint32_t enable_collectd_format;
55 /**< FD to send collectd format messages to STDOUT*/
56 static int stdout_fd;
57 /**< Host id process is running on */
58 static char host_id[MAX_LONG_OPT_SZ];
59 /**< Enable metrics. */
60 static uint32_t enable_metrics;
61 /**< Enable stats reset. */
62 static uint32_t reset_stats;
63 /**< Enable xstats reset. */
64 static uint32_t reset_xstats;
65 /**< Enable memory info. */
66 static uint32_t mem_info;
67 /**< Enable displaying xstat name. */
68 static uint32_t enable_xstats_name;
69 static char *xstats_name;
70
71 /**< Enable xstats by ids. */
72 #define MAX_NB_XSTATS_IDS 1024
73 static uint32_t nb_xstats_ids;
74 static uint64_t xstats_ids[MAX_NB_XSTATS_IDS];
75
76 /* show border */
77 static char bdr_str[MAX_STRING_LEN];
78
79 /**< Enable show port. */
80 static uint32_t enable_shw_port;
81 /**< Enable show tm. */
82 static uint32_t enable_shw_tm;
83 /**< Enable show crypto. */
84 static uint32_t enable_shw_crypto;
85
86 /**< display usage */
87 static void
88 proc_info_usage(const char *prgname)
89 {
90         printf("%s [EAL options] -- -p PORTMASK\n"
91                 "  -m to display DPDK memory zones, segments and TAILQ information\n"
92                 "  -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
93                 "  --stats: to display port statistics, enabled by default\n"
94                 "  --xstats: to display extended port statistics, disabled by "
95                         "default\n"
96                 "  --metrics: to display derived metrics of the ports, disabled by "
97                         "default\n"
98                 "  --xstats-name NAME: to display single xstat id by NAME\n"
99                 "  --xstats-ids IDLIST: to display xstat values by id. "
100                         "The argument is comma-separated list of xstat ids to print out.\n"
101                 "  --stats-reset: to reset port statistics\n"
102                 "  --xstats-reset: to reset port extended statistics\n"
103                 "  --collectd-format: to print statistics to STDOUT in expected by collectd format\n"
104                 "  --host-id STRING: host id used to identify the system process is running on\n"
105                 "  --show-port: to display ports information\n"
106                 "  --show-tm: to display traffic manager information for ports\n"
107                 "  --show-crypto: to display crypto information\n",
108                 prgname);
109 }
110
111 /*
112  * Parse the portmask provided at run time.
113  */
114 static int
115 parse_portmask(const char *portmask)
116 {
117         char *end = NULL;
118         unsigned long pm;
119
120         errno = 0;
121
122         /* parse hexadecimal string */
123         pm = strtoul(portmask, &end, 16);
124         if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0') ||
125                 (errno != 0)) {
126                 printf("%s ERROR parsing the port mask\n", __func__);
127                 return -1;
128         }
129
130         if (pm == 0)
131                 return -1;
132
133         return pm;
134
135 }
136
137 /*
138  * Parse ids value list into array
139  */
140 static int
141 parse_xstats_ids(char *list, uint64_t *ids, int limit) {
142         int length;
143         char *token;
144         char *ctx = NULL;
145         char *endptr;
146
147         length = 0;
148         token = strtok_r(list, ",", &ctx);
149         while (token != NULL) {
150                 ids[length] = strtoull(token, &endptr, 10);
151                 if (*endptr != '\0')
152                         return -EINVAL;
153
154                 length++;
155                 if (length >= limit)
156                         return -E2BIG;
157
158                 token = strtok_r(NULL, ",", &ctx);
159         }
160
161         return length;
162 }
163
164 static int
165 proc_info_preparse_args(int argc, char **argv)
166 {
167         char *prgname = argv[0];
168         int i;
169
170         for (i = 0; i < argc; i++) {
171                 /* Print stats or xstats to STDOUT in collectd format */
172                 if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) {
173                         enable_collectd_format = 1;
174                         stdout_fd = dup(STDOUT_FILENO);
175                         close(STDOUT_FILENO);
176                 }
177                 if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) {
178                         if ((i + 1) == argc) {
179                                 printf("Invalid host id or not specified\n");
180                                 proc_info_usage(prgname);
181                                 return -1;
182                         }
183                         snprintf(host_id, sizeof(host_id), "%s", argv[i+1]);
184                 }
185         }
186
187         if (!strlen(host_id)) {
188                 int err = gethostname(host_id, MAX_LONG_OPT_SZ-1);
189
190                 if (err)
191                         strcpy(host_id, "unknown");
192         }
193
194         return 0;
195 }
196
197 /* Parse the argument given in the command line of the application */
198 static int
199 proc_info_parse_args(int argc, char **argv)
200 {
201         int opt;
202         int option_index;
203         char *prgname = argv[0];
204         static struct option long_option[] = {
205                 {"stats", 0, NULL, 0},
206                 {"stats-reset", 0, NULL, 0},
207                 {"xstats", 0, NULL, 0},
208                 {"metrics", 0, NULL, 0},
209                 {"xstats-reset", 0, NULL, 0},
210                 {"xstats-name", required_argument, NULL, 1},
211                 {"collectd-format", 0, NULL, 0},
212                 {"xstats-ids", 1, NULL, 1},
213                 {"host-id", 0, NULL, 0},
214                 {"show-port", 0, NULL, 0},
215                 {"show-tm", 0, NULL, 0},
216                 {"show-crypto", 0, NULL, 0},
217                 {NULL, 0, 0, 0}
218         };
219
220         if (argc == 1)
221                 proc_info_usage(prgname);
222
223         /* Parse command line */
224         while ((opt = getopt_long(argc, argv, "p:m",
225                         long_option, &option_index)) != EOF) {
226                 switch (opt) {
227                 /* portmask */
228                 case 'p':
229                         enabled_port_mask = parse_portmask(optarg);
230                         if (enabled_port_mask == 0) {
231                                 printf("invalid portmask\n");
232                                 proc_info_usage(prgname);
233                                 return -1;
234                         }
235                         break;
236                 case 'm':
237                         mem_info = 1;
238                         break;
239                 case 0:
240                         /* Print stats */
241                         if (!strncmp(long_option[option_index].name, "stats",
242                                         MAX_LONG_OPT_SZ))
243                                 enable_stats = 1;
244                         /* Print xstats */
245                         else if (!strncmp(long_option[option_index].name, "xstats",
246                                         MAX_LONG_OPT_SZ))
247                                 enable_xstats = 1;
248                         else if (!strncmp(long_option[option_index].name,
249                                         "metrics",
250                                         MAX_LONG_OPT_SZ))
251                                 enable_metrics = 1;
252                         /* Reset stats */
253                         if (!strncmp(long_option[option_index].name, "stats-reset",
254                                         MAX_LONG_OPT_SZ))
255                                 reset_stats = 1;
256                         /* Reset xstats */
257                         else if (!strncmp(long_option[option_index].name, "xstats-reset",
258                                         MAX_LONG_OPT_SZ))
259                                 reset_xstats = 1;
260                         else if (!strncmp(long_option[option_index].name,
261                                         "show-port", MAX_LONG_OPT_SZ))
262                                 enable_shw_port = 1;
263                         else if (!strncmp(long_option[option_index].name,
264                                         "show-tm", MAX_LONG_OPT_SZ))
265                                 enable_shw_tm = 1;
266                         else if (!strncmp(long_option[option_index].name,
267                                         "show-crypto", MAX_LONG_OPT_SZ))
268                                 enable_shw_crypto = 1;
269                         break;
270                 case 1:
271                         /* Print xstat single value given by name*/
272                         if (!strncmp(long_option[option_index].name,
273                                         "xstats-name", MAX_LONG_OPT_SZ)) {
274                                 enable_xstats_name = 1;
275                                 xstats_name = optarg;
276                                 printf("name:%s:%s\n",
277                                                 long_option[option_index].name,
278                                                 optarg);
279                         } else if (!strncmp(long_option[option_index].name,
280                                         "xstats-ids",
281                                         MAX_LONG_OPT_SZ))       {
282                                 nb_xstats_ids = parse_xstats_ids(optarg,
283                                                 xstats_ids, MAX_NB_XSTATS_IDS);
284
285                                 if (nb_xstats_ids <= 0) {
286                                         printf("xstats-id list parse error.\n");
287                                         return -1;
288                                 }
289
290                         }
291                         break;
292                 default:
293                         proc_info_usage(prgname);
294                         return -1;
295                 }
296         }
297         return 0;
298 }
299
300 static void
301 meminfo_display(void)
302 {
303         printf("----------- MEMORY_SEGMENTS -----------\n");
304         rte_dump_physmem_layout(stdout);
305         printf("--------- END_MEMORY_SEGMENTS ---------\n");
306
307         printf("------------ MEMORY_ZONES -------------\n");
308         rte_memzone_dump(stdout);
309         printf("---------- END_MEMORY_ZONES -----------\n");
310
311         printf("------------- TAIL_QUEUES -------------\n");
312         rte_dump_tailq(stdout);
313         printf("---------- END_TAIL_QUEUES ------------\n");
314 }
315
316 static void
317 nic_stats_display(uint16_t port_id)
318 {
319         struct rte_eth_stats stats;
320         uint8_t i;
321
322         static const char *nic_stats_border = "########################";
323
324         rte_eth_stats_get(port_id, &stats);
325         printf("\n  %s NIC statistics for port %-2d %s\n",
326                    nic_stats_border, port_id, nic_stats_border);
327
328         printf("  RX-packets: %-10"PRIu64"  RX-errors:  %-10"PRIu64
329                "  RX-bytes:  %-10"PRIu64"\n", stats.ipackets, stats.ierrors,
330                stats.ibytes);
331         printf("  RX-nombuf:  %-10"PRIu64"\n", stats.rx_nombuf);
332         printf("  TX-packets: %-10"PRIu64"  TX-errors:  %-10"PRIu64
333                "  TX-bytes:  %-10"PRIu64"\n", stats.opackets, stats.oerrors,
334                stats.obytes);
335
336         printf("\n");
337         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
338                 printf("  Stats reg %2d RX-packets: %-10"PRIu64
339                        "  RX-errors: %-10"PRIu64
340                        "  RX-bytes: %-10"PRIu64"\n",
341                        i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
342         }
343
344         printf("\n");
345         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
346                 printf("  Stats reg %2d TX-packets: %-10"PRIu64
347                        "  TX-bytes: %-10"PRIu64"\n",
348                        i, stats.q_opackets[i], stats.q_obytes[i]);
349         }
350
351         printf("  %s############################%s\n",
352                    nic_stats_border, nic_stats_border);
353 }
354
355 static void
356 nic_stats_clear(uint16_t port_id)
357 {
358         printf("\n Clearing NIC stats for port %d\n", port_id);
359         rte_eth_stats_reset(port_id);
360         printf("\n  NIC statistics for port %d cleared\n", port_id);
361 }
362
363 static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
364                                       const char *cnt_name) {
365         char *type_end = strrchr(cnt_name, '_');
366
367         if ((type_end != NULL) &&
368             (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) {
369                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
370                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
371                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
372                         strncpy(cnt_type, "if_rx_dropped", cnt_type_len);
373                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
374                         strncpy(cnt_type, "if_rx_octets", cnt_type_len);
375                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
376                         strncpy(cnt_type, "if_rx_packets", cnt_type_len);
377                 else if (strncmp(type_end, "_placement",
378                                  strlen("_placement")) == 0)
379                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
380                 else if (strncmp(type_end, "_buff", strlen("_buff")) == 0)
381                         strncpy(cnt_type, "if_rx_errors", cnt_type_len);
382                 else
383                         /* Does not fit obvious type: use a more generic one */
384                         strncpy(cnt_type, "derive", cnt_type_len);
385         } else if ((type_end != NULL) &&
386                 (strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) {
387                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
388                         strncpy(cnt_type, "if_tx_errors", cnt_type_len);
389                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
390                         strncpy(cnt_type, "if_tx_dropped", cnt_type_len);
391                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
392                         strncpy(cnt_type, "if_tx_octets", cnt_type_len);
393                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
394                         strncpy(cnt_type, "if_tx_packets", cnt_type_len);
395                 else
396                         /* Does not fit obvious type: use a more generic one */
397                         strncpy(cnt_type, "derive", cnt_type_len);
398         } else if ((type_end != NULL) &&
399                    (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
400                 if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
401                         strncpy(cnt_type, "operations", cnt_type_len);
402                 else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
403                         strncpy(cnt_type, "errors", cnt_type_len);
404                 else if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
405                         strncpy(cnt_type, "filter_result", cnt_type_len);
406         } else if ((type_end != NULL) &&
407                    (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
408                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
409                         strncpy(cnt_type, "errors", cnt_type_len);
410         } else {
411                 /* Does not fit obvious type, or strrchr error: */
412                 /* use a more generic type */
413                 strncpy(cnt_type, "derive", cnt_type_len);
414         }
415 }
416
417 static void
418 nic_xstats_by_name_display(uint16_t port_id, char *name)
419 {
420         uint64_t id;
421
422         printf("###### NIC statistics for port %-2d, statistic name '%s':\n",
423                            port_id, name);
424
425         if (rte_eth_xstats_get_id_by_name(port_id, name, &id) == 0)
426                 printf("%s: %"PRIu64"\n", name, id);
427         else
428                 printf("Statistic not found...\n");
429
430 }
431
432 static void
433 nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len)
434 {
435         struct rte_eth_xstat_name *xstats_names;
436         uint64_t *values;
437         int ret, i;
438         static const char *nic_stats_border = "########################";
439
440         values = malloc(sizeof(*values) * len);
441         if (values == NULL) {
442                 printf("Cannot allocate memory for xstats\n");
443                 return;
444         }
445
446         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
447         if (xstats_names == NULL) {
448                 printf("Cannot allocate memory for xstat names\n");
449                 free(values);
450                 return;
451         }
452
453         if (len != rte_eth_xstats_get_names_by_id(
454                         port_id, xstats_names, len, ids)) {
455                 printf("Cannot get xstat names\n");
456                 goto err;
457         }
458
459         printf("###### NIC extended statistics for port %-2d #########\n",
460                            port_id);
461         printf("%s############################\n", nic_stats_border);
462         ret = rte_eth_xstats_get_by_id(port_id, ids, values, len);
463         if (ret < 0 || ret > len) {
464                 printf("Cannot get xstats\n");
465                 goto err;
466         }
467
468         for (i = 0; i < len; i++)
469                 printf("%s: %"PRIu64"\n",
470                         xstats_names[i].name,
471                         values[i]);
472
473         printf("%s############################\n", nic_stats_border);
474 err:
475         free(values);
476         free(xstats_names);
477 }
478
479 static void
480 nic_xstats_display(uint16_t port_id)
481 {
482         struct rte_eth_xstat_name *xstats_names;
483         uint64_t *values;
484         int len, ret, i;
485         static const char *nic_stats_border = "########################";
486
487         len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
488         if (len < 0) {
489                 printf("Cannot get xstats count\n");
490                 return;
491         }
492         values = malloc(sizeof(*values) * len);
493         if (values == NULL) {
494                 printf("Cannot allocate memory for xstats\n");
495                 return;
496         }
497
498         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
499         if (xstats_names == NULL) {
500                 printf("Cannot allocate memory for xstat names\n");
501                 free(values);
502                 return;
503         }
504         if (len != rte_eth_xstats_get_names_by_id(
505                         port_id, xstats_names, len, NULL)) {
506                 printf("Cannot get xstat names\n");
507                 goto err;
508         }
509
510         printf("###### NIC extended statistics for port %-2d #########\n",
511                            port_id);
512         printf("%s############################\n",
513                            nic_stats_border);
514         ret = rte_eth_xstats_get_by_id(port_id, NULL, values, len);
515         if (ret < 0 || ret > len) {
516                 printf("Cannot get xstats\n");
517                 goto err;
518         }
519
520         for (i = 0; i < len; i++) {
521                 if (enable_collectd_format) {
522                         char counter_type[MAX_STRING_LEN];
523                         char buf[MAX_STRING_LEN];
524                         size_t n;
525
526                         collectd_resolve_cnt_type(counter_type,
527                                                   sizeof(counter_type),
528                                                   xstats_names[i].name);
529                         n = snprintf(buf, MAX_STRING_LEN,
530                                 "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%"
531                                 PRIu64"\n", host_id, port_id, counter_type,
532                                 xstats_names[i].name, values[i]);
533                         if (n > sizeof(buf) - 1)
534                                 n = sizeof(buf) - 1;
535                         ret = write(stdout_fd, buf, n);
536                         if (ret < 0)
537                                 goto err;
538                 } else {
539                         printf("%s: %"PRIu64"\n", xstats_names[i].name,
540                                         values[i]);
541                 }
542         }
543
544         printf("%s############################\n",
545                            nic_stats_border);
546 err:
547         free(values);
548         free(xstats_names);
549 }
550
551 static void
552 nic_xstats_clear(uint16_t port_id)
553 {
554         printf("\n Clearing NIC xstats for port %d\n", port_id);
555         rte_eth_xstats_reset(port_id);
556         printf("\n  NIC extended statistics for port %d cleared\n", port_id);
557 }
558
559 static void
560 metrics_display(int port_id)
561 {
562         struct rte_metric_value *metrics;
563         struct rte_metric_name *names;
564         int len, ret;
565         static const char *nic_stats_border = "########################";
566
567         len = rte_metrics_get_names(NULL, 0);
568         if (len < 0) {
569                 printf("Cannot get metrics count\n");
570                 return;
571         }
572         if (len == 0) {
573                 printf("No metrics to display (none have been registered)\n");
574                 return;
575         }
576
577         metrics = rte_malloc("proc_info_metrics",
578                 sizeof(struct rte_metric_value) * len, 0);
579         if (metrics == NULL) {
580                 printf("Cannot allocate memory for metrics\n");
581                 return;
582         }
583
584         names =  rte_malloc(NULL, sizeof(struct rte_metric_name) * len, 0);
585         if (names == NULL) {
586                 printf("Cannot allocate memory for metrcis names\n");
587                 rte_free(metrics);
588                 return;
589         }
590
591         if (len != rte_metrics_get_names(names, len)) {
592                 printf("Cannot get metrics names\n");
593                 rte_free(metrics);
594                 rte_free(names);
595                 return;
596         }
597
598         if (port_id == RTE_METRICS_GLOBAL)
599                 printf("###### Non port specific metrics  #########\n");
600         else
601                 printf("###### metrics for port %-2d #########\n", port_id);
602         printf("%s############################\n", nic_stats_border);
603         ret = rte_metrics_get_values(port_id, metrics, len);
604         if (ret < 0 || ret > len) {
605                 printf("Cannot get metrics values\n");
606                 rte_free(metrics);
607                 rte_free(names);
608                 return;
609         }
610
611         int i;
612         for (i = 0; i < len; i++)
613                 printf("%s: %"PRIu64"\n", names[i].name, metrics[i].value);
614
615         printf("%s############################\n", nic_stats_border);
616         rte_free(metrics);
617         rte_free(names);
618 }
619
620 static void
621 show_port(void)
622 {
623         uint16_t i = 0;
624         int ret = 0, j, k;
625
626         snprintf(bdr_str, MAX_STRING_LEN, " show - Port PMD %"PRIu64,
627                         rte_get_tsc_hz());
628         STATS_BDR_STR(10, bdr_str);
629
630         RTE_ETH_FOREACH_DEV(i) {
631                 uint16_t mtu = 0;
632                 struct rte_eth_link link;
633                 struct rte_eth_dev_info dev_info;
634                 struct rte_eth_rxq_info queue_info;
635                 struct rte_eth_rss_conf rss_conf;
636
637                 memset(&rss_conf, 0, sizeof(rss_conf));
638
639                 snprintf(bdr_str, MAX_STRING_LEN, " Port (%u)", i);
640                 STATS_BDR_STR(5, bdr_str);
641                 printf("  - generic config\n");
642
643                 printf("\t  -- Socket %d\n", rte_eth_dev_socket_id(i));
644                 rte_eth_link_get(i, &link);
645                 printf("\t  -- link speed %d duplex %d,"
646                                 " auto neg %d status %d\n",
647                                 link.link_speed,
648                                 link.link_duplex,
649                                 link.link_autoneg,
650                                 link.link_status);
651                 printf("\t  -- promiscuous (%d)\n",
652                                 rte_eth_promiscuous_get(i));
653                 ret = rte_eth_dev_get_mtu(i, &mtu);
654                 if (ret == 0)
655                         printf("\t  -- mtu (%d)\n", mtu);
656
657                 rte_eth_dev_info_get(i, &dev_info);
658
659                 printf("  - queue\n");
660                 for (j = 0; j < dev_info.nb_rx_queues; j++) {
661                         ret = rte_eth_rx_queue_info_get(i, j, &queue_info);
662                         if (ret == 0) {
663                                 printf("\t  -- queue %d rx scatter %d"
664                                                 " descriptors %d"
665                                                 " offloads 0x%"PRIx64
666                                                 " mempool socket %d\n",
667                                                 j,
668                                                 queue_info.scattered_rx,
669                                                 queue_info.nb_desc,
670                                                 queue_info.conf.offloads,
671                                                 queue_info.mp->socket_id);
672                         }
673                 }
674
675                 ret = rte_eth_dev_rss_hash_conf_get(i, &rss_conf);
676                 if (ret == 0) {
677                         if (rss_conf.rss_key) {
678                                 printf("  - RSS\n");
679                                 printf("\t  -- RSS len %u key (hex):",
680                                                 rss_conf.rss_key_len);
681                                 for (k = 0; k < rss_conf.rss_key_len; k++)
682                                         printf(" %x", rss_conf.rss_key[k]);
683                                 printf("\t  -- hf 0x%"PRIx64"\n",
684                                                 rss_conf.rss_hf);
685                         }
686                 }
687
688                 printf("  - cyrpto context\n");
689                 void *p_ctx = rte_eth_dev_get_sec_ctx(i);
690                 printf("\t  -- security context - %p\n", p_ctx);
691
692                 if (p_ctx) {
693                         printf("\t  -- size %u\n",
694                                         rte_security_session_get_size(p_ctx));
695                         const struct rte_security_capability *s_cap =
696                                 rte_security_capabilities_get(p_ctx);
697                         if (s_cap) {
698                                 printf("\t  -- action (0x%x), protocol (0x%x),"
699                                                 " offload flags (0x%x)\n",
700                                                 s_cap->action,
701                                                 s_cap->protocol,
702                                                 s_cap->ol_flags);
703                                 printf("\t  -- capabilities - oper type %x\n",
704                                                 s_cap->crypto_capabilities->op);
705                         }
706                 }
707         }
708
709         STATS_BDR_STR(50, "");
710 }
711
712 static void
713 display_nodecap_info(int is_leaf, struct rte_tm_node_capabilities *cap)
714 {
715         if (cap == NULL)
716                 return;
717
718         if (!is_leaf) {
719                 printf("\t  -- nonleaf sched max:\n"
720                         "\t\t  + children (%u)\n"
721                         "\t\t  + sp priorities (%u)\n"
722                         "\t\t  + wfq children per group (%u)\n"
723                         "\t\t  + wfq groups (%u)\n"
724                         "\t\t  + wfq weight (%u)\n",
725                         cap->nonleaf.sched_n_children_max,
726                         cap->nonleaf.sched_sp_n_priorities_max,
727                         cap->nonleaf.sched_wfq_n_children_per_group_max,
728                         cap->nonleaf.sched_wfq_n_groups_max,
729                         cap->nonleaf.sched_wfq_weight_max);
730         } else {
731                 printf("\t  -- leaf cman support:\n"
732                         "\t\t  + wred pkt mode (%d)\n"
733                         "\t\t  + wred byte mode (%d)\n"
734                         "\t\t  + head drop (%d)\n"
735                         "\t\t  + wred context private (%d)\n"
736                         "\t\t  + wred context shared (%u)\n",
737                         cap->leaf.cman_wred_packet_mode_supported,
738                         cap->leaf.cman_wred_byte_mode_supported,
739                         cap->leaf.cman_head_drop_supported,
740                         cap->leaf.cman_wred_context_private_supported,
741                         cap->leaf.cman_wred_context_shared_n_max);
742         }
743 }
744
745 static void
746 display_levelcap_info(int is_leaf, struct rte_tm_level_capabilities *cap)
747 {
748         if (cap == NULL)
749                 return;
750
751         if (!is_leaf) {
752                 printf("\t  -- shaper private: (%d) dual rate (%d)\n",
753                         cap->nonleaf.shaper_private_supported,
754                         cap->nonleaf.shaper_private_dual_rate_supported);
755                 printf("\t  -- shaper share: (%u)\n",
756                         cap->nonleaf.shaper_shared_n_max);
757                 printf("\t  -- non leaf sched MAX:\n"
758                         "\t\t  + children (%u)\n"
759                         "\t\t  + sp (%u)\n"
760                         "\t\t  + wfq children per group (%u)\n"
761                         "\t\t  + wfq groups (%u)\n"
762                         "\t\t  + wfq weight (%u)\n",
763                         cap->nonleaf.sched_n_children_max,
764                         cap->nonleaf.sched_sp_n_priorities_max,
765                         cap->nonleaf.sched_wfq_n_children_per_group_max,
766                         cap->nonleaf.sched_wfq_n_groups_max,
767                         cap->nonleaf.sched_wfq_weight_max);
768         } else {
769                 printf("\t  -- shaper private: (%d) dual rate (%d)\n",
770                         cap->leaf.shaper_private_supported,
771                         cap->leaf.shaper_private_dual_rate_supported);
772                 printf("\t  -- shaper share: (%u)\n",
773                         cap->leaf.shaper_shared_n_max);
774                 printf("  -- leaf cman support:\n"
775                         "\t\t  + wred pkt mode (%d)\n"
776                         "\t\t  + wred byte mode (%d)\n"
777                         "\t\t  + head drop (%d)\n"
778                         "\t\t  + wred context private (%d)\n"
779                         "\t\t  + wred context shared (%u)\n",
780                         cap->leaf.cman_wred_packet_mode_supported,
781                         cap->leaf.cman_wred_byte_mode_supported,
782                         cap->leaf.cman_head_drop_supported,
783                         cap->leaf.cman_wred_context_private_supported,
784                         cap->leaf.cman_wred_context_shared_n_max);
785         }
786 }
787
788 static void
789 show_tm(void)
790 {
791         int ret = 0, check_for_leaf = 0, is_leaf = 0;
792         unsigned int j, k;
793         uint16_t i = 0;
794
795         snprintf(bdr_str, MAX_STRING_LEN, " show - TM PMD %"PRIu64,
796                         rte_get_tsc_hz());
797         STATS_BDR_STR(10, bdr_str);
798
799         RTE_ETH_FOREACH_DEV(i) {
800                 struct rte_eth_dev_info dev_info;
801                 struct rte_tm_capabilities cap;
802                 struct rte_tm_error error;
803                 struct rte_tm_node_capabilities capnode;
804                 struct rte_tm_level_capabilities caplevel;
805                 uint32_t n_leaf_nodes = 0;
806
807                 memset(&cap, 0, sizeof(cap));
808                 memset(&error, 0, sizeof(error));
809
810                 rte_eth_dev_info_get(i, &dev_info);
811                 printf("  - Generic for port (%u)\n"
812                         "\t  -- driver name %s\n"
813                         "\t  -- max vf (%u)\n"
814                         "\t  -- max tx queues (%u)\n"
815                         "\t  -- number of tx queues (%u)\n",
816                         i,
817                         dev_info.driver_name,
818                         dev_info.max_vfs,
819                         dev_info.max_tx_queues,
820                         dev_info.nb_tx_queues);
821
822                 ret = rte_tm_capabilities_get(i, &cap, &error);
823                 if (ret)
824                         continue;
825
826                 printf("  - MAX: nodes (%u) levels (%u) children (%u)\n",
827                         cap.n_nodes_max,
828                         cap.n_levels_max,
829                         cap.sched_n_children_max);
830
831                 printf("  - identical nodes: non leaf (%d) leaf (%d)\n",
832                         cap.non_leaf_nodes_identical,
833                         cap.leaf_nodes_identical);
834
835                 printf("  - Shaper MAX:\n"
836                         "\t  -- total (%u)\n"
837                         "\t  -- private (%u) private dual (%d)\n"
838                         "\t  -- shared (%u) shared dual (%u)\n",
839                         cap.shaper_n_max,
840                         cap.shaper_private_n_max,
841                         cap.shaper_private_dual_rate_n_max,
842                         cap.shaper_shared_n_max,
843                         cap.shaper_shared_dual_rate_n_max);
844
845                 printf("  - mark support:\n");
846                 printf("\t  -- vlan dei: GREEN (%d) YELLOW (%d) RED (%d)\n",
847                         cap.mark_vlan_dei_supported[RTE_TM_GREEN],
848                         cap.mark_vlan_dei_supported[RTE_TM_YELLOW],
849                         cap.mark_vlan_dei_supported[RTE_TM_RED]);
850                 printf("\t  -- ip ecn tcp: GREEN (%d) YELLOW (%d) RED (%d)\n",
851                         cap.mark_ip_ecn_tcp_supported[RTE_TM_GREEN],
852                         cap.mark_ip_ecn_tcp_supported[RTE_TM_YELLOW],
853                         cap.mark_ip_ecn_tcp_supported[RTE_TM_RED]);
854                 printf("\t  -- ip ecn sctp: GREEN (%d) YELLOW (%d) RED (%d)\n",
855                         cap.mark_ip_ecn_sctp_supported[RTE_TM_GREEN],
856                         cap.mark_ip_ecn_sctp_supported[RTE_TM_YELLOW],
857                         cap.mark_ip_ecn_sctp_supported[RTE_TM_RED]);
858                 printf("\t  -- ip dscp: GREEN (%d) YELLOW (%d) RED (%d)\n",
859                         cap.mark_ip_dscp_supported[RTE_TM_GREEN],
860                         cap.mark_ip_dscp_supported[RTE_TM_YELLOW],
861                         cap.mark_ip_dscp_supported[RTE_TM_RED]);
862
863                 printf("  - mask stats (0x%"PRIx64")"
864                         " dynamic update (0x%"PRIx64")\n",
865                         cap.stats_mask,
866                         cap.dynamic_update_mask);
867
868                 printf("  - sched MAX:\n"
869                         "\t  -- total (%u)\n"
870                         "\t  -- sp levels (%u)\n"
871                         "\t  -- wfq children per group (%u)\n"
872                         "\t  -- wfq groups (%u)\n"
873                         "\t  -- wfq weight (%u)\n",
874                         cap.sched_sp_n_priorities_max,
875                         cap.sched_sp_n_priorities_max,
876                         cap.sched_wfq_n_children_per_group_max,
877                         cap.sched_wfq_n_groups_max,
878                         cap.sched_wfq_weight_max);
879
880                 printf("  - CMAN support:\n"
881                         "\t  -- WRED mode: pkt (%d) byte (%d)\n"
882                         "\t  -- head drop (%d)\n",
883                         cap.cman_wred_packet_mode_supported,
884                         cap.cman_wred_byte_mode_supported,
885                         cap.cman_head_drop_supported);
886                 printf("\t  -- MAX WRED CONTEXT:"
887                         " total (%u) private (%u) shared (%u)\n",
888                         cap.cman_wred_context_n_max,
889                         cap.cman_wred_context_private_n_max,
890                         cap.cman_wred_context_shared_n_max);
891
892                 for (j = 0; j < cap.n_nodes_max; j++) {
893                         memset(&capnode, 0, sizeof(capnode));
894                         ret = rte_tm_node_capabilities_get(i, j,
895                                         &capnode, &error);
896                         if (ret)
897                                 continue;
898
899                         check_for_leaf = 1;
900
901                         printf("  NODE %u\n", j);
902                         printf("\t  - shaper private: (%d) dual rate (%d)\n",
903                                 capnode.shaper_private_supported,
904                                 capnode.shaper_private_dual_rate_supported);
905                         printf("\t  - shaper shared max: (%u)\n",
906                                 capnode.shaper_shared_n_max);
907                         printf("\t  - stats mask %"PRIx64"\n",
908                                 capnode.stats_mask);
909
910                         ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
911                         if (ret)
912                                 continue;
913
914                         display_nodecap_info(is_leaf, &capnode);
915                 }
916
917                 for (j = 0; j < cap.n_levels_max; j++) {
918                         memset(&caplevel, 0, sizeof(caplevel));
919                         ret = rte_tm_level_capabilities_get(i, j,
920                                         &caplevel, &error);
921                         if (ret)
922                                 continue;
923
924                         printf("  - Level %u\n", j);
925                         printf("\t  -- node MAX: %u non leaf %u leaf %u\n",
926                                 caplevel.n_nodes_max,
927                                 caplevel.n_nodes_nonleaf_max,
928                                 caplevel.n_nodes_leaf_max);
929                         printf("\t  -- indetical: non leaf %u leaf %u\n",
930                                 caplevel.non_leaf_nodes_identical,
931                                 caplevel.leaf_nodes_identical);
932
933                         for (k = 0; k < caplevel.n_nodes_max; k++) {
934                                 ret = rte_tm_node_type_get(i, k,
935                                         &is_leaf, &error);
936                                 if (ret)
937                                         continue;
938
939                                 display_levelcap_info(is_leaf, &caplevel);
940                         }
941                 }
942
943                 if (check_for_leaf) {
944                         ret = rte_tm_get_number_of_leaf_nodes(i,
945                                         &n_leaf_nodes, &error);
946                         if (ret == 0)
947                                 printf("  - leaf nodes (%u)\n", n_leaf_nodes);
948                 }
949
950                 for (j = 0; j < n_leaf_nodes; j++) {
951                         struct rte_tm_node_stats stats;
952                         memset(&stats, 0, sizeof(stats));
953
954                         ret = rte_tm_node_stats_read(i, j,
955                                         &stats, &cap.stats_mask, 0, &error);
956                         if (ret)
957                                 continue;
958
959                         printf("  - STATS for node (%u)\n", j);
960                         printf("  -- pkts (%"PRIu64") bytes (%"PRIu64")\n",
961                                 stats.n_pkts, stats.n_bytes);
962
963                         ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
964                         if (ret || (!is_leaf))
965                                 continue;
966
967                         printf("  -- leaf queued:"
968                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n",
969                                 stats.leaf.n_pkts_queued,
970                                 stats.leaf.n_bytes_queued);
971                         printf("  - dropped:\n"
972                                 "\t  -- GREEN:"
973                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n"
974                                 "\t  -- YELLOW:"
975                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n"
976                                 "\t  -- RED:"
977                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n",
978                                 stats.leaf.n_pkts_dropped[RTE_TM_GREEN],
979                                 stats.leaf.n_bytes_dropped[RTE_TM_GREEN],
980                                 stats.leaf.n_pkts_dropped[RTE_TM_YELLOW],
981                                 stats.leaf.n_bytes_dropped[RTE_TM_YELLOW],
982                                 stats.leaf.n_pkts_dropped[RTE_TM_RED],
983                                 stats.leaf.n_bytes_dropped[RTE_TM_RED]);
984                 }
985         }
986
987         STATS_BDR_STR(50, "");
988 }
989
990 static void
991 display_crypto_feature_info(uint64_t x)
992 {
993         if (x == 0)
994                 return;
995
996         printf("\t  -- feature flags\n");
997         printf("\t\t  + symmetric (%c), asymmetric (%c)\n"
998                 "\t\t  + symmetric operation chaining (%c)\n",
999                 (x & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ? 'y' : 'n',
1000                 (x & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) ? 'y' : 'n',
1001                 (x & RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING) ? 'y' : 'n');
1002         printf("\t\t  + CPU: SSE (%c), AVX (%c), AVX2 (%c), AVX512 (%c)\n",
1003                 (x & RTE_CRYPTODEV_FF_CPU_SSE) ? 'y' : 'n',
1004                 (x & RTE_CRYPTODEV_FF_CPU_AVX) ? 'y' : 'n',
1005                 (x & RTE_CRYPTODEV_FF_CPU_AVX2) ? 'y' : 'n',
1006                 (x & RTE_CRYPTODEV_FF_CPU_AVX512) ? 'y' : 'n');
1007         printf("\t\t  + AESNI: CPU (%c), HW (%c)\n",
1008                 (x & RTE_CRYPTODEV_FF_CPU_AESNI) ? 'y' : 'n',
1009                 (x & RTE_CRYPTODEV_FF_HW_ACCELERATED) ? 'y' : 'n');
1010         printf("\t\t  + INLINE (%c)\n",
1011                 (x & RTE_CRYPTODEV_FF_SECURITY) ? 'y' : 'n');
1012         printf("\t\t  + ARM: NEON (%c), CE (%c)\n",
1013                 (x & RTE_CRYPTODEV_FF_CPU_NEON) ? 'y' : 'n',
1014                 (x & RTE_CRYPTODEV_FF_CPU_ARM_CE) ? 'y' : 'n');
1015         printf("\t  -- buffer offload\n");
1016         printf("\t\t  + IN_PLACE_SGL (%c)\n",
1017                 (x & RTE_CRYPTODEV_FF_IN_PLACE_SGL) ? 'y' : 'n');
1018         printf("\t\t  + OOP_SGL_IN_SGL_OUT (%c)\n",
1019                 (x & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT) ? 'y' : 'n');
1020         printf("\t\t  + OOP_SGL_IN_LB_OUT (%c)\n",
1021                 (x & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT) ? 'y' : 'n');
1022         printf("\t\t  + OOP_LB_IN_SGL_OUT (%c)\n",
1023                 (x & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT) ? 'y' : 'n');
1024         printf("\t\t  + OOP_LB_IN_LB_OUT (%c)\n",
1025                 (x & RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT) ? 'y' : 'n');
1026 }
1027
1028 static void
1029 show_crypto(void)
1030 {
1031         uint8_t crypto_dev_count = rte_cryptodev_count(), i;
1032
1033         snprintf(bdr_str, MAX_STRING_LEN, " show - CRYPTO PMD %"PRIu64,
1034                         rte_get_tsc_hz());
1035         STATS_BDR_STR(10, bdr_str);
1036
1037         for (i = 0; i < crypto_dev_count; i++) {
1038                 struct rte_cryptodev_info dev_info;
1039                 struct rte_cryptodev_stats stats;
1040
1041                 rte_cryptodev_info_get(i, &dev_info);
1042
1043                 printf("  - device (%u)\n", i);
1044                 printf("\t  -- name (%s)\n"
1045                         "\t  -- driver (%s)\n"
1046                         "\t  -- id (%u) on socket (%d)\n"
1047                         "\t  -- queue pairs (%d)\n",
1048                         rte_cryptodev_name_get(i),
1049                         dev_info.driver_name,
1050                         dev_info.driver_id,
1051                         dev_info.device->numa_node,
1052                         rte_cryptodev_queue_pair_count(i));
1053
1054                 display_crypto_feature_info(dev_info.feature_flags);
1055
1056                 memset(&stats, 0, sizeof(0));
1057                 if (rte_cryptodev_stats_get(i, &stats) == 0) {
1058                         printf("\t  -- stats\n");
1059                         printf("\t\t  + enqueue count (%"PRIu64")"
1060                                 " error (%"PRIu64")\n",
1061                                 stats.enqueued_count,
1062                                 stats.enqueue_err_count);
1063                         printf("\t\t  + dequeue count (%"PRIu64")"
1064                                 " error (%"PRIu64")\n",
1065                                 stats.dequeued_count,
1066                                 stats.dequeue_err_count);
1067                 }
1068         }
1069
1070         STATS_BDR_STR(50, "");
1071 }
1072
1073 int
1074 main(int argc, char **argv)
1075 {
1076         int ret;
1077         int i;
1078         char c_flag[] = "-c1";
1079         char n_flag[] = "-n4";
1080         char mp_flag[] = "--proc-type=secondary";
1081         char *argp[argc + 3];
1082         uint16_t nb_ports;
1083
1084         /* preparse app arguments */
1085         ret = proc_info_preparse_args(argc, argv);
1086         if (ret < 0) {
1087                 printf("Failed to parse arguments\n");
1088                 return -1;
1089         }
1090
1091         argp[0] = argv[0];
1092         argp[1] = c_flag;
1093         argp[2] = n_flag;
1094         argp[3] = mp_flag;
1095
1096         for (i = 1; i < argc; i++)
1097                 argp[i + 3] = argv[i];
1098
1099         argc += 3;
1100
1101         ret = rte_eal_init(argc, argp);
1102         if (ret < 0)
1103                 rte_panic("Cannot init EAL\n");
1104
1105         argc -= ret;
1106         argv += (ret - 3);
1107
1108         if (!rte_eal_primary_proc_alive(NULL))
1109                 rte_exit(EXIT_FAILURE, "No primary DPDK process is running.\n");
1110
1111         /* parse app arguments */
1112         ret = proc_info_parse_args(argc, argv);
1113         if (ret < 0)
1114                 rte_exit(EXIT_FAILURE, "Invalid argument\n");
1115
1116         if (mem_info) {
1117                 meminfo_display();
1118                 return 0;
1119         }
1120
1121         nb_ports = rte_eth_dev_count_avail();
1122         if (nb_ports == 0)
1123                 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
1124
1125         /* If no port mask was specified*/
1126         if (enabled_port_mask == 0)
1127                 enabled_port_mask = 0xffff;
1128
1129         RTE_ETH_FOREACH_DEV(i) {
1130                 if (enabled_port_mask & (1 << i)) {
1131                         if (enable_stats)
1132                                 nic_stats_display(i);
1133                         else if (enable_xstats)
1134                                 nic_xstats_display(i);
1135                         else if (reset_stats)
1136                                 nic_stats_clear(i);
1137                         else if (reset_xstats)
1138                                 nic_xstats_clear(i);
1139                         else if (enable_xstats_name)
1140                                 nic_xstats_by_name_display(i, xstats_name);
1141                         else if (nb_xstats_ids > 0)
1142                                 nic_xstats_by_ids_display(i, xstats_ids,
1143                                                 nb_xstats_ids);
1144                         else if (enable_metrics)
1145                                 metrics_display(i);
1146                 }
1147         }
1148
1149         /* print port independent stats */
1150         if (enable_metrics)
1151                 metrics_display(RTE_METRICS_GLOBAL);
1152
1153         /* show information for PMD */
1154         if (enable_shw_port)
1155                 show_port();
1156         if (enable_shw_tm)
1157                 show_tm();
1158         if (enable_shw_crypto)
1159                 show_crypto();
1160
1161         ret = rte_eal_cleanup();
1162         if (ret)
1163                 printf("Error from rte_eal_cleanup(), %d\n", ret);
1164
1165         snprintf(bdr_str, MAX_STRING_LEN, " ");
1166         STATS_BDR_STR(50, bdr_str);
1167
1168         return 0;
1169 }