app/procinfo: remove useless memset
[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 #include <strings.h>
16
17 #include <rte_eal.h>
18 #include <rte_common.h>
19 #include <rte_debug.h>
20 #include <rte_ethdev.h>
21 #include <rte_malloc.h>
22 #include <rte_memory.h>
23 #include <rte_memzone.h>
24 #include <rte_launch.h>
25 #include <rte_tailq.h>
26 #include <rte_per_lcore.h>
27 #include <rte_lcore.h>
28 #include <rte_log.h>
29 #include <rte_atomic.h>
30 #include <rte_branch_prediction.h>
31 #include <rte_string_fns.h>
32 #include <rte_metrics.h>
33 #include <rte_cycles.h>
34 #ifdef RTE_LIB_SECURITY
35 #include <rte_security.h>
36 #endif
37 #include <rte_cryptodev.h>
38 #include <rte_tm.h>
39 #include <rte_hexdump.h>
40
41 /* Maximum long option length for option parsing. */
42 #define MAX_LONG_OPT_SZ 64
43 #define MAX_STRING_LEN 256
44
45 #define STATS_BDR_FMT "========================================"
46 #define STATS_BDR_STR(w, s) printf("%.*s%s%.*s\n", w, \
47         STATS_BDR_FMT, s, w, STATS_BDR_FMT)
48
49 /**< mask of enabled ports */
50 static unsigned long enabled_port_mask;
51 /**< Enable stats. */
52 static uint32_t enable_stats;
53 /**< Enable xstats. */
54 static uint32_t enable_xstats;
55 /**< Enable collectd format*/
56 static uint32_t enable_collectd_format;
57 /**< FD to send collectd format messages to STDOUT*/
58 static int stdout_fd;
59 /**< Host id process is running on */
60 static char host_id[MAX_LONG_OPT_SZ];
61 /**< Enable metrics. */
62 static uint32_t enable_metrics;
63 /**< Enable stats reset. */
64 static uint32_t reset_stats;
65 /**< Enable xstats reset. */
66 static uint32_t reset_xstats;
67 /**< Enable memory info. */
68 static uint32_t mem_info;
69 /**< Enable displaying xstat name. */
70 static uint32_t enable_xstats_name;
71 static char *xstats_name;
72
73 /**< Enable xstats by ids. */
74 #define MAX_NB_XSTATS_IDS 1024
75 static uint32_t nb_xstats_ids;
76 static uint64_t xstats_ids[MAX_NB_XSTATS_IDS];
77
78 /* show border */
79 static char bdr_str[MAX_STRING_LEN];
80
81 /**< Enable show port. */
82 static uint32_t enable_shw_port;
83 /**< Enable show tm. */
84 static uint32_t enable_shw_tm;
85 /**< Enable show crypto. */
86 static uint32_t enable_shw_crypto;
87 /**< Enable show ring. */
88 static uint32_t enable_shw_ring;
89 static char *ring_name;
90 /**< Enable show mempool. */
91 static uint32_t enable_shw_mempool;
92 static char *mempool_name;
93 /**< Enable iter mempool. */
94 static uint32_t enable_iter_mempool;
95 static char *mempool_iter_name;
96
97 /**< display usage */
98 static void
99 proc_info_usage(const char *prgname)
100 {
101         printf("%s [EAL options] -- -p PORTMASK\n"
102                 "  -m to display DPDK memory zones, segments and TAILQ information\n"
103                 "  -p PORTMASK: hexadecimal bitmask of ports to retrieve stats for\n"
104                 "  --stats: to display port statistics, enabled by default\n"
105                 "  --xstats: to display extended port statistics, disabled by "
106                         "default\n"
107                 "  --metrics: to display derived metrics of the ports, disabled by "
108                         "default\n"
109                 "  --xstats-name NAME: to display single xstat id by NAME\n"
110                 "  --xstats-ids IDLIST: to display xstat values by id. "
111                         "The argument is comma-separated list of xstat ids to print out.\n"
112                 "  --stats-reset: to reset port statistics\n"
113                 "  --xstats-reset: to reset port extended statistics\n"
114                 "  --collectd-format: to print statistics to STDOUT in expected by collectd format\n"
115                 "  --host-id STRING: host id used to identify the system process is running on\n"
116                 "  --show-port: to display ports information\n"
117                 "  --show-tm: to display traffic manager information for ports\n"
118                 "  --show-crypto: to display crypto information\n"
119                 "  --show-ring[=name]: to display ring information\n"
120                 "  --show-mempool[=name]: to display mempool information\n"
121                 "  --iter-mempool=name: iterate mempool elements to display content\n",
122                 prgname);
123 }
124
125 /*
126  * Parse the portmask provided at run time.
127  */
128 static int
129 parse_portmask(const char *portmask)
130 {
131         char *end = NULL;
132
133         errno = 0;
134
135         /* parse hexadecimal string */
136         enabled_port_mask = strtoul(portmask, &end, 16);
137         if (portmask[0] == '\0' || end == NULL || *end != '\0' || errno != 0) {
138                 fprintf(stderr, "Invalid portmask '%s'\n", portmask);
139                 return -1;
140         }
141
142         return 0;
143 }
144
145 /*
146  * Parse ids value list into array
147  */
148 static int
149 parse_xstats_ids(char *list, uint64_t *ids, int limit) {
150         int length;
151         char *token;
152         char *ctx = NULL;
153         char *endptr;
154
155         length = 0;
156         token = strtok_r(list, ",", &ctx);
157         while (token != NULL) {
158                 ids[length] = strtoull(token, &endptr, 10);
159                 if (*endptr != '\0')
160                         return -EINVAL;
161
162                 length++;
163                 if (length >= limit)
164                         return -E2BIG;
165
166                 token = strtok_r(NULL, ",", &ctx);
167         }
168
169         return length;
170 }
171
172 static int
173 proc_info_preparse_args(int argc, char **argv)
174 {
175         char *prgname = argv[0];
176         int i;
177
178         for (i = 0; i < argc; i++) {
179                 /* Print stats or xstats to STDOUT in collectd format */
180                 if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) {
181                         enable_collectd_format = 1;
182                         stdout_fd = dup(STDOUT_FILENO);
183                         close(STDOUT_FILENO);
184                 }
185                 if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) {
186                         if ((i + 1) == argc) {
187                                 printf("Invalid host id or not specified\n");
188                                 proc_info_usage(prgname);
189                                 return -1;
190                         }
191                         strlcpy(host_id, argv[i + 1], sizeof(host_id));
192                 }
193         }
194
195         if (!strlen(host_id)) {
196                 int err = gethostname(host_id, MAX_LONG_OPT_SZ-1);
197
198                 if (err)
199                         strlcpy(host_id, "unknown", sizeof(host_id));
200         }
201
202         return 0;
203 }
204
205 /* Parse the argument given in the command line of the application */
206 static int
207 proc_info_parse_args(int argc, char **argv)
208 {
209         int opt;
210         int option_index;
211         char *prgname = argv[0];
212         static struct option long_option[] = {
213                 {"stats", 0, NULL, 0},
214                 {"stats-reset", 0, NULL, 0},
215                 {"xstats", 0, NULL, 0},
216                 {"metrics", 0, NULL, 0},
217                 {"xstats-reset", 0, NULL, 0},
218                 {"xstats-name", required_argument, NULL, 1},
219                 {"collectd-format", 0, NULL, 0},
220                 {"xstats-ids", 1, NULL, 1},
221                 {"host-id", 0, NULL, 0},
222                 {"show-port", 0, NULL, 0},
223                 {"show-tm", 0, NULL, 0},
224                 {"show-crypto", 0, NULL, 0},
225                 {"show-ring", optional_argument, NULL, 0},
226                 {"show-mempool", optional_argument, NULL, 0},
227                 {"iter-mempool", required_argument, NULL, 0},
228                 {NULL, 0, 0, 0}
229         };
230
231         if (argc == 1)
232                 proc_info_usage(prgname);
233
234         /* Parse command line */
235         while ((opt = getopt_long(argc, argv, "p:m",
236                         long_option, &option_index)) != EOF) {
237                 switch (opt) {
238                 /* portmask */
239                 case 'p':
240                         if (parse_portmask(optarg) < 0) {
241                                 proc_info_usage(prgname);
242                                 return -1;
243                         }
244                         break;
245                 case 'm':
246                         mem_info = 1;
247                         break;
248                 case 0:
249                         /* Print stats */
250                         if (!strncmp(long_option[option_index].name, "stats",
251                                         MAX_LONG_OPT_SZ))
252                                 enable_stats = 1;
253                         /* Print xstats */
254                         else if (!strncmp(long_option[option_index].name, "xstats",
255                                         MAX_LONG_OPT_SZ))
256                                 enable_xstats = 1;
257                         else if (!strncmp(long_option[option_index].name,
258                                         "metrics",
259                                         MAX_LONG_OPT_SZ))
260                                 enable_metrics = 1;
261                         /* Reset stats */
262                         if (!strncmp(long_option[option_index].name, "stats-reset",
263                                         MAX_LONG_OPT_SZ))
264                                 reset_stats = 1;
265                         /* Reset xstats */
266                         else if (!strncmp(long_option[option_index].name, "xstats-reset",
267                                         MAX_LONG_OPT_SZ))
268                                 reset_xstats = 1;
269                         else if (!strncmp(long_option[option_index].name,
270                                         "show-port", MAX_LONG_OPT_SZ))
271                                 enable_shw_port = 1;
272                         else if (!strncmp(long_option[option_index].name,
273                                         "show-tm", MAX_LONG_OPT_SZ))
274                                 enable_shw_tm = 1;
275                         else if (!strncmp(long_option[option_index].name,
276                                         "show-crypto", MAX_LONG_OPT_SZ))
277                                 enable_shw_crypto = 1;
278                         else if (!strncmp(long_option[option_index].name,
279                                         "show-ring", MAX_LONG_OPT_SZ)) {
280                                 enable_shw_ring = 1;
281                                 ring_name = optarg;
282                         } else if (!strncmp(long_option[option_index].name,
283                                         "show-mempool", MAX_LONG_OPT_SZ)) {
284                                 enable_shw_mempool = 1;
285                                 mempool_name = optarg;
286                         } else if (!strncmp(long_option[option_index].name,
287                                         "iter-mempool", MAX_LONG_OPT_SZ)) {
288                                 enable_iter_mempool = 1;
289                                 mempool_iter_name = optarg;
290                         }
291                         break;
292                 case 1:
293                         /* Print xstat single value given by name*/
294                         if (!strncmp(long_option[option_index].name,
295                                         "xstats-name", MAX_LONG_OPT_SZ)) {
296                                 enable_xstats_name = 1;
297                                 xstats_name = optarg;
298                                 printf("name:%s:%s\n",
299                                                 long_option[option_index].name,
300                                                 optarg);
301                         } else if (!strncmp(long_option[option_index].name,
302                                         "xstats-ids",
303                                         MAX_LONG_OPT_SZ))       {
304                                 int ret = parse_xstats_ids(optarg,
305                                                 xstats_ids, MAX_NB_XSTATS_IDS);
306                                 if (ret <= 0) {
307                                         printf("xstats-id list parse error.\n");
308                                         return -1;
309                                 }
310                                 nb_xstats_ids = ret;
311                         }
312                         break;
313                 default:
314                         proc_info_usage(prgname);
315                         return -1;
316                 }
317         }
318         return 0;
319 }
320
321 static void
322 meminfo_display(void)
323 {
324         printf("----------- MEMORY_SEGMENTS -----------\n");
325         rte_dump_physmem_layout(stdout);
326         printf("--------- END_MEMORY_SEGMENTS ---------\n");
327
328         printf("------------ MEMORY_ZONES -------------\n");
329         rte_memzone_dump(stdout);
330         printf("---------- END_MEMORY_ZONES -----------\n");
331
332         printf("------------- TAIL_QUEUES -------------\n");
333         rte_dump_tailq(stdout);
334         printf("---------- END_TAIL_QUEUES ------------\n");
335 }
336
337 static void
338 nic_stats_display(uint16_t port_id)
339 {
340         struct rte_eth_stats stats;
341         uint8_t i;
342
343         static const char *nic_stats_border = "########################";
344
345         rte_eth_stats_get(port_id, &stats);
346         printf("\n  %s NIC statistics for port %-2d %s\n",
347                    nic_stats_border, port_id, nic_stats_border);
348
349         printf("  RX-packets: %-10"PRIu64"  RX-errors:  %-10"PRIu64
350                "  RX-bytes:  %-10"PRIu64"\n", stats.ipackets, stats.ierrors,
351                stats.ibytes);
352         printf("  RX-nombuf:  %-10"PRIu64"\n", stats.rx_nombuf);
353         printf("  TX-packets: %-10"PRIu64"  TX-errors:  %-10"PRIu64
354                "  TX-bytes:  %-10"PRIu64"\n", stats.opackets, stats.oerrors,
355                stats.obytes);
356
357         printf("\n");
358         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
359                 printf("  Stats reg %2d RX-packets: %-10"PRIu64
360                        "  RX-errors: %-10"PRIu64
361                        "  RX-bytes: %-10"PRIu64"\n",
362                        i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
363         }
364
365         printf("\n");
366         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
367                 printf("  Stats reg %2d TX-packets: %-10"PRIu64
368                        "  TX-bytes: %-10"PRIu64"\n",
369                        i, stats.q_opackets[i], stats.q_obytes[i]);
370         }
371
372         printf("  %s############################%s\n",
373                    nic_stats_border, nic_stats_border);
374 }
375
376 static void
377 nic_stats_clear(uint16_t port_id)
378 {
379         printf("\n Clearing NIC stats for port %d\n", port_id);
380         rte_eth_stats_reset(port_id);
381         printf("\n  NIC statistics for port %d cleared\n", port_id);
382 }
383
384 static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
385                                       const char *cnt_name) {
386         char *type_end = strrchr(cnt_name, '_');
387
388         if ((type_end != NULL) &&
389             (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) {
390                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
391                         strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
392                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
393                         strlcpy(cnt_type, "if_rx_dropped", cnt_type_len);
394                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
395                         strlcpy(cnt_type, "if_rx_octets", cnt_type_len);
396                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
397                         strlcpy(cnt_type, "if_rx_packets", cnt_type_len);
398                 else if (strncmp(type_end, "_placement",
399                                  strlen("_placement")) == 0)
400                         strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
401                 else if (strncmp(type_end, "_buff", strlen("_buff")) == 0)
402                         strlcpy(cnt_type, "if_rx_errors", cnt_type_len);
403                 else
404                         /* Does not fit obvious type: use a more generic one */
405                         strlcpy(cnt_type, "derive", cnt_type_len);
406         } else if ((type_end != NULL) &&
407                 (strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) {
408                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
409                         strlcpy(cnt_type, "if_tx_errors", cnt_type_len);
410                 else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
411                         strlcpy(cnt_type, "if_tx_dropped", cnt_type_len);
412                 else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
413                         strlcpy(cnt_type, "if_tx_octets", cnt_type_len);
414                 else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
415                         strlcpy(cnt_type, "if_tx_packets", cnt_type_len);
416                 else
417                         /* Does not fit obvious type: use a more generic one */
418                         strlcpy(cnt_type, "derive", cnt_type_len);
419         } else if ((type_end != NULL) &&
420                    (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
421                 if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
422                         strlcpy(cnt_type, "filter_result", cnt_type_len);
423                 else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
424                         strlcpy(cnt_type, "errors", cnt_type_len);
425         } else if ((type_end != NULL) &&
426                    (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
427                 if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
428                         strlcpy(cnt_type, "errors", cnt_type_len);
429         } else {
430                 /* Does not fit obvious type, or strrchr error: */
431                 /* use a more generic type */
432                 strlcpy(cnt_type, "derive", cnt_type_len);
433         }
434 }
435
436 static void
437 nic_xstats_by_name_display(uint16_t port_id, char *name)
438 {
439         uint64_t id;
440
441         printf("###### NIC statistics for port %-2d, statistic name '%s':\n",
442                            port_id, name);
443
444         if (rte_eth_xstats_get_id_by_name(port_id, name, &id) == 0)
445                 printf("%s: %"PRIu64"\n", name, id);
446         else
447                 printf("Statistic not found...\n");
448
449 }
450
451 static void
452 nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len)
453 {
454         struct rte_eth_xstat_name *xstats_names;
455         uint64_t *values;
456         int ret, i;
457         static const char *nic_stats_border = "########################";
458
459         values = malloc(sizeof(*values) * len);
460         if (values == NULL) {
461                 printf("Cannot allocate memory for xstats\n");
462                 return;
463         }
464
465         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
466         if (xstats_names == NULL) {
467                 printf("Cannot allocate memory for xstat names\n");
468                 free(values);
469                 return;
470         }
471
472         if (len != rte_eth_xstats_get_names_by_id(
473                         port_id, xstats_names, len, ids)) {
474                 printf("Cannot get xstat names\n");
475                 goto err;
476         }
477
478         printf("###### NIC extended statistics for port %-2d #########\n",
479                            port_id);
480         printf("%s############################\n", nic_stats_border);
481         ret = rte_eth_xstats_get_by_id(port_id, ids, values, len);
482         if (ret < 0 || ret > len) {
483                 printf("Cannot get xstats\n");
484                 goto err;
485         }
486
487         for (i = 0; i < len; i++)
488                 printf("%s: %"PRIu64"\n",
489                         xstats_names[i].name,
490                         values[i]);
491
492         printf("%s############################\n", nic_stats_border);
493 err:
494         free(values);
495         free(xstats_names);
496 }
497
498 static void
499 nic_xstats_display(uint16_t port_id)
500 {
501         struct rte_eth_xstat_name *xstats_names;
502         uint64_t *values;
503         int len, ret, i;
504         static const char *nic_stats_border = "########################";
505
506         len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
507         if (len < 0) {
508                 printf("Cannot get xstats count\n");
509                 return;
510         }
511         values = malloc(sizeof(*values) * len);
512         if (values == NULL) {
513                 printf("Cannot allocate memory for xstats\n");
514                 return;
515         }
516
517         xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
518         if (xstats_names == NULL) {
519                 printf("Cannot allocate memory for xstat names\n");
520                 free(values);
521                 return;
522         }
523         if (len != rte_eth_xstats_get_names_by_id(
524                         port_id, xstats_names, len, NULL)) {
525                 printf("Cannot get xstat names\n");
526                 goto err;
527         }
528
529         printf("###### NIC extended statistics for port %-2d #########\n",
530                            port_id);
531         printf("%s############################\n",
532                            nic_stats_border);
533         ret = rte_eth_xstats_get_by_id(port_id, NULL, values, len);
534         if (ret < 0 || ret > len) {
535                 printf("Cannot get xstats\n");
536                 goto err;
537         }
538
539         for (i = 0; i < len; i++) {
540                 if (enable_collectd_format) {
541                         char counter_type[MAX_STRING_LEN];
542                         char buf[MAX_STRING_LEN];
543                         size_t n;
544
545                         collectd_resolve_cnt_type(counter_type,
546                                                   sizeof(counter_type),
547                                                   xstats_names[i].name);
548                         n = snprintf(buf, MAX_STRING_LEN,
549                                 "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%"
550                                 PRIu64"\n", host_id, port_id, counter_type,
551                                 xstats_names[i].name, values[i]);
552                         if (n > sizeof(buf) - 1)
553                                 n = sizeof(buf) - 1;
554                         ret = write(stdout_fd, buf, n);
555                         if (ret < 0)
556                                 goto err;
557                 } else {
558                         printf("%s: %"PRIu64"\n", xstats_names[i].name,
559                                         values[i]);
560                 }
561         }
562
563         printf("%s############################\n",
564                            nic_stats_border);
565 err:
566         free(values);
567         free(xstats_names);
568 }
569
570 static void
571 nic_xstats_clear(uint16_t port_id)
572 {
573         int ret;
574
575         printf("\n Clearing NIC xstats for port %d\n", port_id);
576         ret = rte_eth_xstats_reset(port_id);
577         if (ret != 0) {
578                 printf("\n Error clearing xstats for port %d: %s\n", port_id,
579                        strerror(-ret));
580                 return;
581         }
582
583         printf("\n  NIC extended statistics for port %d cleared\n", port_id);
584 }
585
586 static void
587 metrics_display(int port_id)
588 {
589         struct rte_metric_value *metrics;
590         struct rte_metric_name *names;
591         int len, ret;
592         static const char *nic_stats_border = "########################";
593
594         len = rte_metrics_get_names(NULL, 0);
595         if (len < 0) {
596                 printf("Cannot get metrics count\n");
597                 return;
598         }
599         if (len == 0) {
600                 printf("No metrics to display (none have been registered)\n");
601                 return;
602         }
603
604         metrics = rte_malloc("proc_info_metrics",
605                 sizeof(struct rte_metric_value) * len, 0);
606         if (metrics == NULL) {
607                 printf("Cannot allocate memory for metrics\n");
608                 return;
609         }
610
611         names =  rte_malloc(NULL, sizeof(struct rte_metric_name) * len, 0);
612         if (names == NULL) {
613                 printf("Cannot allocate memory for metrcis names\n");
614                 rte_free(metrics);
615                 return;
616         }
617
618         if (len != rte_metrics_get_names(names, len)) {
619                 printf("Cannot get metrics names\n");
620                 rte_free(metrics);
621                 rte_free(names);
622                 return;
623         }
624
625         if (port_id == RTE_METRICS_GLOBAL)
626                 printf("###### Non port specific metrics  #########\n");
627         else
628                 printf("###### metrics for port %-2d #########\n", port_id);
629         printf("%s############################\n", nic_stats_border);
630         ret = rte_metrics_get_values(port_id, metrics, len);
631         if (ret < 0 || ret > len) {
632                 printf("Cannot get metrics values\n");
633                 rte_free(metrics);
634                 rte_free(names);
635                 return;
636         }
637
638         int i;
639         for (i = 0; i < len; i++)
640                 printf("%s: %"PRIu64"\n", names[i].name, metrics[i].value);
641
642         printf("%s############################\n", nic_stats_border);
643         rte_free(metrics);
644         rte_free(names);
645 }
646
647 static void
648 show_security_context(uint16_t portid)
649 {
650         void *p_ctx = rte_eth_dev_get_sec_ctx(portid);
651         const struct rte_security_capability *s_cap;
652
653         if (p_ctx == NULL)
654                 return;
655
656         printf("  - crypto context\n");
657         printf("\t  -- security context - %p\n", p_ctx);
658         printf("\t  -- size %u\n",
659                rte_security_session_get_size(p_ctx));
660
661         s_cap = rte_security_capabilities_get(p_ctx);
662         if (s_cap) {
663                 printf("\t  -- action (0x%x), protocol (0x%x),"
664                        " offload flags (0x%x)\n",
665                        s_cap->action,
666                        s_cap->protocol,
667                        s_cap->ol_flags);
668                 printf("\t  -- capabilities - oper type %x\n",
669                        s_cap->crypto_capabilities->op);
670         }
671 }
672
673 static void
674 show_offloads(uint64_t offloads,
675               const char *(show_offload)(uint64_t))
676 {
677         printf(" offloads :");
678         while (offloads != 0) {
679                 uint64_t offload_flag = 1ULL << __builtin_ctzll(offloads);
680                 printf(" %s", show_offload(offload_flag));
681                 offloads &= ~offload_flag;
682         }
683 }
684
685 static void
686 show_port(void)
687 {
688         int i, ret, j, k;
689
690         snprintf(bdr_str, MAX_STRING_LEN, " show - Port PMD ");
691         STATS_BDR_STR(10, bdr_str);
692
693         for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
694                 uint16_t mtu = 0;
695                 struct rte_eth_link link;
696                 struct rte_eth_dev_info dev_info;
697                 struct rte_eth_rss_conf rss_conf;
698                 char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
699                 struct rte_eth_fc_conf fc_conf;
700                 struct rte_ether_addr mac;
701                 struct rte_eth_dev_owner owner;
702
703                 /* Skip if port is not in mask */
704                 if ((enabled_port_mask & (1ul << i)) == 0)
705                         continue;
706
707                 /* Skip if port is unused */
708                 if (!rte_eth_dev_is_valid_port(i))
709                         continue;
710
711                 memset(&rss_conf, 0, sizeof(rss_conf));
712
713                 snprintf(bdr_str, MAX_STRING_LEN, " Port %u ", i);
714                 STATS_BDR_STR(5, bdr_str);
715                 printf("  - generic config\n");
716
717                 ret = rte_eth_dev_info_get(i, &dev_info);
718                 if (ret != 0) {
719                         printf("Error during getting device info: %s\n",
720                                 strerror(-ret));
721                         return;
722                 }
723
724                 printf("\t  -- driver %s device %s socket %d\n",
725                        dev_info.driver_name, dev_info.device->name,
726                        rte_eth_dev_socket_id(i));
727
728                 ret = rte_eth_dev_owner_get(i, &owner);
729                 if (ret == 0 && owner.id != RTE_ETH_DEV_NO_OWNER)
730                         printf("\t --  owner %#"PRIx64":%s\n",
731                                owner.id, owner.name);
732
733                 ret = rte_eth_link_get(i, &link);
734                 if (ret < 0) {
735                         printf("Link get failed (port %u): %s\n",
736                                i, rte_strerror(-ret));
737                 } else {
738                         rte_eth_link_to_str(link_status_text,
739                                         sizeof(link_status_text),
740                                         &link);
741                         printf("\t%s\n", link_status_text);
742                 }
743
744                 ret = rte_eth_dev_flow_ctrl_get(i, &fc_conf);
745                 if (ret == 0 && fc_conf.mode != RTE_FC_NONE)  {
746                         printf("\t  -- flow control mode %s%s high %u low %u pause %u%s%s\n",
747                                fc_conf.mode == RTE_FC_RX_PAUSE ? "rx " :
748                                fc_conf.mode == RTE_FC_TX_PAUSE ? "tx " :
749                                fc_conf.mode == RTE_FC_FULL ? "full" : "???",
750                                fc_conf.autoneg ? " auto" : "",
751                                fc_conf.high_water,
752                                fc_conf.low_water,
753                                fc_conf.pause_time,
754                                fc_conf.send_xon ? " xon" : "",
755                                fc_conf.mac_ctrl_frame_fwd ? " mac_ctrl" : "");
756                 }
757
758                 ret = rte_eth_macaddr_get(i, &mac);
759                 if (ret == 0) {
760                         char ebuf[RTE_ETHER_ADDR_FMT_SIZE];
761
762                         rte_ether_format_addr(ebuf, sizeof(ebuf), &mac);
763                         printf("\t  -- mac %s\n", ebuf);
764                 }
765
766                 ret = rte_eth_promiscuous_get(i);
767                 if (ret >= 0)
768                         printf("\t  -- promiscuous mode %s\n",
769                                ret > 0 ? "enabled" : "disabled");
770
771                 ret = rte_eth_allmulticast_get(i);
772                 if (ret >= 0)
773                         printf("\t  -- all multicast mode %s\n",
774                                ret > 0 ? "enabled" : "disabled");
775
776                 ret = rte_eth_dev_get_mtu(i, &mtu);
777                 if (ret == 0)
778                         printf("\t  -- mtu (%d)\n", mtu);
779
780                 for (j = 0; j < dev_info.nb_rx_queues; j++) {
781                         struct rte_eth_rxq_info queue_info;
782                         int count;
783
784                         ret = rte_eth_rx_queue_info_get(i, j, &queue_info);
785                         if (ret != 0)
786                                 break;
787
788                         if (j == 0)
789                                 printf("  - rx queue\n");
790
791                         printf("\t  -- %d descriptors ", j);
792                         count = rte_eth_rx_queue_count(i, j);
793                         if (count >= 0)
794                                 printf("%d/", count);
795                         printf("%u", queue_info.nb_desc);
796
797                         if (queue_info.scattered_rx)
798                                 printf(" scattered");
799
800                         if (queue_info.conf.rx_drop_en)
801                                 printf(" drop_en");
802
803                         if (queue_info.conf.rx_deferred_start)
804                                 printf(" deferred_start");
805
806                         if (queue_info.rx_buf_size != 0)
807                                 printf(" rx buffer size %u",
808                                        queue_info.rx_buf_size);
809
810                         printf(" mempool %s socket %d",
811                                queue_info.mp->name,
812                                queue_info.mp->socket_id);
813
814                         if (queue_info.conf.offloads != 0)
815                                 show_offloads(queue_info.conf.offloads, rte_eth_dev_rx_offload_name);
816
817                         printf("\n");
818                 }
819
820                 for (j = 0; j < dev_info.nb_tx_queues; j++) {
821                         struct rte_eth_txq_info queue_info;
822
823                         ret = rte_eth_tx_queue_info_get(i, j, &queue_info);
824                         if (ret != 0)
825                                 break;
826
827                         if (j == 0)
828                                 printf("  - tx queue\n");
829
830                         printf("\t  -- %d descriptors %d",
831                                j, queue_info.nb_desc);
832
833                         printf(" thresh %u/%u",
834                                queue_info.conf.tx_rs_thresh,
835                                queue_info.conf.tx_free_thresh);
836
837                         if (queue_info.conf.tx_deferred_start)
838                                 printf(" deferred_start");
839
840                         if (queue_info.conf.offloads != 0)
841                                 show_offloads(queue_info.conf.offloads, rte_eth_dev_tx_offload_name);
842                         printf("\n");
843                 }
844
845                 ret = rte_eth_dev_rss_hash_conf_get(i, &rss_conf);
846                 if (ret == 0) {
847                         if (rss_conf.rss_key) {
848                                 printf("  - RSS\n");
849                                 printf("\t  -- RSS len %u key (hex):",
850                                                 rss_conf.rss_key_len);
851                                 for (k = 0; k < rss_conf.rss_key_len; k++)
852                                         printf(" %x", rss_conf.rss_key[k]);
853                                 printf("\t  -- hf 0x%"PRIx64"\n",
854                                                 rss_conf.rss_hf);
855                         }
856                 }
857
858 #ifdef RTE_LIB_SECURITY
859                 show_security_context(i);
860 #endif
861         }
862 }
863
864 static void
865 display_nodecap_info(int is_leaf, struct rte_tm_node_capabilities *cap)
866 {
867         if (cap == NULL)
868                 return;
869
870         if (!is_leaf) {
871                 printf("\t  -- nonleaf sched max:\n"
872                         "\t\t  + children (%u)\n"
873                         "\t\t  + sp priorities (%u)\n"
874                         "\t\t  + wfq children per group (%u)\n"
875                         "\t\t  + wfq groups (%u)\n"
876                         "\t\t  + wfq weight (%u)\n",
877                         cap->nonleaf.sched_n_children_max,
878                         cap->nonleaf.sched_sp_n_priorities_max,
879                         cap->nonleaf.sched_wfq_n_children_per_group_max,
880                         cap->nonleaf.sched_wfq_n_groups_max,
881                         cap->nonleaf.sched_wfq_weight_max);
882         } else {
883                 printf("\t  -- leaf cman support:\n"
884                         "\t\t  + wred pkt mode (%d)\n"
885                         "\t\t  + wred byte mode (%d)\n"
886                         "\t\t  + head drop (%d)\n"
887                         "\t\t  + wred context private (%d)\n"
888                         "\t\t  + wred context shared (%u)\n",
889                         cap->leaf.cman_wred_packet_mode_supported,
890                         cap->leaf.cman_wred_byte_mode_supported,
891                         cap->leaf.cman_head_drop_supported,
892                         cap->leaf.cman_wred_context_private_supported,
893                         cap->leaf.cman_wred_context_shared_n_max);
894         }
895 }
896
897 static void
898 display_levelcap_info(int is_leaf, struct rte_tm_level_capabilities *cap)
899 {
900         if (cap == NULL)
901                 return;
902
903         if (!is_leaf) {
904                 printf("\t  -- shaper private: (%d) dual rate (%d)\n",
905                         cap->nonleaf.shaper_private_supported,
906                         cap->nonleaf.shaper_private_dual_rate_supported);
907                 printf("\t  -- shaper share: (%u)\n",
908                         cap->nonleaf.shaper_shared_n_max);
909                 printf("\t  -- non leaf sched MAX:\n"
910                         "\t\t  + children (%u)\n"
911                         "\t\t  + sp (%u)\n"
912                         "\t\t  + wfq children per group (%u)\n"
913                         "\t\t  + wfq groups (%u)\n"
914                         "\t\t  + wfq weight (%u)\n",
915                         cap->nonleaf.sched_n_children_max,
916                         cap->nonleaf.sched_sp_n_priorities_max,
917                         cap->nonleaf.sched_wfq_n_children_per_group_max,
918                         cap->nonleaf.sched_wfq_n_groups_max,
919                         cap->nonleaf.sched_wfq_weight_max);
920         } else {
921                 printf("\t  -- shaper private: (%d) dual rate (%d)\n",
922                         cap->leaf.shaper_private_supported,
923                         cap->leaf.shaper_private_dual_rate_supported);
924                 printf("\t  -- shaper share: (%u)\n",
925                         cap->leaf.shaper_shared_n_max);
926                 printf("  -- leaf cman support:\n"
927                         "\t\t  + wred pkt mode (%d)\n"
928                         "\t\t  + wred byte mode (%d)\n"
929                         "\t\t  + head drop (%d)\n"
930                         "\t\t  + wred context private (%d)\n"
931                         "\t\t  + wred context shared (%u)\n",
932                         cap->leaf.cman_wred_packet_mode_supported,
933                         cap->leaf.cman_wred_byte_mode_supported,
934                         cap->leaf.cman_head_drop_supported,
935                         cap->leaf.cman_wred_context_private_supported,
936                         cap->leaf.cman_wred_context_shared_n_max);
937         }
938 }
939
940 static void
941 show_tm(void)
942 {
943         int ret = 0, check_for_leaf = 0, is_leaf = 0;
944         unsigned int j, k;
945         uint16_t i = 0;
946
947         snprintf(bdr_str, MAX_STRING_LEN, " show - TM PMD ");
948         STATS_BDR_STR(10, bdr_str);
949
950         RTE_ETH_FOREACH_DEV(i) {
951                 struct rte_eth_dev_info dev_info;
952                 struct rte_tm_capabilities cap;
953                 struct rte_tm_error error;
954                 struct rte_tm_node_capabilities capnode;
955                 struct rte_tm_level_capabilities caplevel;
956                 uint32_t n_leaf_nodes = 0;
957
958                 memset(&cap, 0, sizeof(cap));
959                 memset(&error, 0, sizeof(error));
960
961                 ret = rte_eth_dev_info_get(i, &dev_info);
962                 if (ret != 0) {
963                         printf("Error during getting device (port %u) info: %s\n",
964                                 i, strerror(-ret));
965                         return;
966                 }
967
968                 printf("  - Generic for port (%u)\n"
969                         "\t  -- driver name %s\n"
970                         "\t  -- max vf (%u)\n"
971                         "\t  -- max tx queues (%u)\n"
972                         "\t  -- number of tx queues (%u)\n",
973                         i,
974                         dev_info.driver_name,
975                         dev_info.max_vfs,
976                         dev_info.max_tx_queues,
977                         dev_info.nb_tx_queues);
978
979                 ret = rte_tm_capabilities_get(i, &cap, &error);
980                 if (ret)
981                         continue;
982
983                 printf("  - MAX: nodes (%u) levels (%u) children (%u)\n",
984                         cap.n_nodes_max,
985                         cap.n_levels_max,
986                         cap.sched_n_children_max);
987
988                 printf("  - identical nodes: non leaf (%d) leaf (%d)\n",
989                         cap.non_leaf_nodes_identical,
990                         cap.leaf_nodes_identical);
991
992                 printf("  - Shaper MAX:\n"
993                         "\t  -- total (%u)\n"
994                         "\t  -- private (%u) private dual (%d)\n"
995                         "\t  -- shared (%u) shared dual (%u)\n",
996                         cap.shaper_n_max,
997                         cap.shaper_private_n_max,
998                         cap.shaper_private_dual_rate_n_max,
999                         cap.shaper_shared_n_max,
1000                         cap.shaper_shared_dual_rate_n_max);
1001
1002                 printf("  - mark support:\n");
1003                 printf("\t  -- vlan dei: GREEN (%d) YELLOW (%d) RED (%d)\n",
1004                         cap.mark_vlan_dei_supported[RTE_COLOR_GREEN],
1005                         cap.mark_vlan_dei_supported[RTE_COLOR_YELLOW],
1006                         cap.mark_vlan_dei_supported[RTE_COLOR_RED]);
1007                 printf("\t  -- ip ecn tcp: GREEN (%d) YELLOW (%d) RED (%d)\n",
1008                         cap.mark_ip_ecn_tcp_supported[RTE_COLOR_GREEN],
1009                         cap.mark_ip_ecn_tcp_supported[RTE_COLOR_YELLOW],
1010                         cap.mark_ip_ecn_tcp_supported[RTE_COLOR_RED]);
1011                 printf("\t  -- ip ecn sctp: GREEN (%d) YELLOW (%d) RED (%d)\n",
1012                         cap.mark_ip_ecn_sctp_supported[RTE_COLOR_GREEN],
1013                         cap.mark_ip_ecn_sctp_supported[RTE_COLOR_YELLOW],
1014                         cap.mark_ip_ecn_sctp_supported[RTE_COLOR_RED]);
1015                 printf("\t  -- ip dscp: GREEN (%d) YELLOW (%d) RED (%d)\n",
1016                         cap.mark_ip_dscp_supported[RTE_COLOR_GREEN],
1017                         cap.mark_ip_dscp_supported[RTE_COLOR_YELLOW],
1018                         cap.mark_ip_dscp_supported[RTE_COLOR_RED]);
1019
1020                 printf("  - mask stats (0x%"PRIx64")"
1021                         " dynamic update (0x%"PRIx64")\n",
1022                         cap.stats_mask,
1023                         cap.dynamic_update_mask);
1024
1025                 printf("  - sched MAX:\n"
1026                         "\t  -- total (%u)\n"
1027                         "\t  -- sp levels (%u)\n"
1028                         "\t  -- wfq children per group (%u)\n"
1029                         "\t  -- wfq groups (%u)\n"
1030                         "\t  -- wfq weight (%u)\n",
1031                         cap.sched_sp_n_priorities_max,
1032                         cap.sched_sp_n_priorities_max,
1033                         cap.sched_wfq_n_children_per_group_max,
1034                         cap.sched_wfq_n_groups_max,
1035                         cap.sched_wfq_weight_max);
1036
1037                 printf("  - CMAN support:\n"
1038                         "\t  -- WRED mode: pkt (%d) byte (%d)\n"
1039                         "\t  -- head drop (%d)\n",
1040                         cap.cman_wred_packet_mode_supported,
1041                         cap.cman_wred_byte_mode_supported,
1042                         cap.cman_head_drop_supported);
1043                 printf("\t  -- MAX WRED CONTEXT:"
1044                         " total (%u) private (%u) shared (%u)\n",
1045                         cap.cman_wred_context_n_max,
1046                         cap.cman_wred_context_private_n_max,
1047                         cap.cman_wred_context_shared_n_max);
1048
1049                 for (j = 0; j < cap.n_nodes_max; j++) {
1050                         memset(&capnode, 0, sizeof(capnode));
1051                         ret = rte_tm_node_capabilities_get(i, j,
1052                                         &capnode, &error);
1053                         if (ret)
1054                                 continue;
1055
1056                         check_for_leaf = 1;
1057
1058                         printf("  NODE %u\n", j);
1059                         printf("\t  - shaper private: (%d) dual rate (%d)\n",
1060                                 capnode.shaper_private_supported,
1061                                 capnode.shaper_private_dual_rate_supported);
1062                         printf("\t  - shaper shared max: (%u)\n",
1063                                 capnode.shaper_shared_n_max);
1064                         printf("\t  - stats mask %"PRIx64"\n",
1065                                 capnode.stats_mask);
1066
1067                         ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
1068                         if (ret)
1069                                 continue;
1070
1071                         display_nodecap_info(is_leaf, &capnode);
1072                 }
1073
1074                 for (j = 0; j < cap.n_levels_max; j++) {
1075                         memset(&caplevel, 0, sizeof(caplevel));
1076                         ret = rte_tm_level_capabilities_get(i, j,
1077                                         &caplevel, &error);
1078                         if (ret)
1079                                 continue;
1080
1081                         printf("  - Level %u\n", j);
1082                         printf("\t  -- node MAX: %u non leaf %u leaf %u\n",
1083                                 caplevel.n_nodes_max,
1084                                 caplevel.n_nodes_nonleaf_max,
1085                                 caplevel.n_nodes_leaf_max);
1086                         printf("\t  -- indetical: non leaf %u leaf %u\n",
1087                                 caplevel.non_leaf_nodes_identical,
1088                                 caplevel.leaf_nodes_identical);
1089
1090                         for (k = 0; k < caplevel.n_nodes_max; k++) {
1091                                 ret = rte_tm_node_type_get(i, k,
1092                                         &is_leaf, &error);
1093                                 if (ret)
1094                                         continue;
1095
1096                                 display_levelcap_info(is_leaf, &caplevel);
1097                         }
1098                 }
1099
1100                 if (check_for_leaf) {
1101                         ret = rte_tm_get_number_of_leaf_nodes(i,
1102                                         &n_leaf_nodes, &error);
1103                         if (ret == 0)
1104                                 printf("  - leaf nodes (%u)\n", n_leaf_nodes);
1105                 }
1106
1107                 for (j = 0; j < n_leaf_nodes; j++) {
1108                         struct rte_tm_node_stats stats;
1109                         memset(&stats, 0, sizeof(stats));
1110
1111                         ret = rte_tm_node_stats_read(i, j,
1112                                         &stats, &cap.stats_mask, 0, &error);
1113                         if (ret)
1114                                 continue;
1115
1116                         printf("  - STATS for node (%u)\n", j);
1117                         printf("  -- pkts (%"PRIu64") bytes (%"PRIu64")\n",
1118                                 stats.n_pkts, stats.n_bytes);
1119
1120                         ret = rte_tm_node_type_get(i, j, &is_leaf, &error);
1121                         if (ret || (!is_leaf))
1122                                 continue;
1123
1124                         printf("  -- leaf queued:"
1125                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n",
1126                                 stats.leaf.n_pkts_queued,
1127                                 stats.leaf.n_bytes_queued);
1128                         printf("  - dropped:\n"
1129                                 "\t  -- GREEN:"
1130                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n"
1131                                 "\t  -- YELLOW:"
1132                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n"
1133                                 "\t  -- RED:"
1134                                 " pkts (%"PRIu64") bytes (%"PRIu64")\n",
1135                                 stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN],
1136                                 stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN],
1137                                 stats.leaf.n_pkts_dropped[RTE_COLOR_YELLOW],
1138                                 stats.leaf.n_bytes_dropped[RTE_COLOR_YELLOW],
1139                                 stats.leaf.n_pkts_dropped[RTE_COLOR_RED],
1140                                 stats.leaf.n_bytes_dropped[RTE_COLOR_RED]);
1141                 }
1142         }
1143 }
1144
1145 static void
1146 display_crypto_feature_info(uint64_t x)
1147 {
1148         if (x == 0)
1149                 return;
1150
1151         printf("\t  -- feature flags\n");
1152         printf("\t\t  + symmetric (%c), asymmetric (%c)\n"
1153                 "\t\t  + symmetric operation chaining (%c)\n",
1154                 (x & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ? 'y' : 'n',
1155                 (x & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) ? 'y' : 'n',
1156                 (x & RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING) ? 'y' : 'n');
1157         printf("\t\t  + CPU: SSE (%c), AVX (%c), AVX2 (%c), AVX512 (%c)\n",
1158                 (x & RTE_CRYPTODEV_FF_CPU_SSE) ? 'y' : 'n',
1159                 (x & RTE_CRYPTODEV_FF_CPU_AVX) ? 'y' : 'n',
1160                 (x & RTE_CRYPTODEV_FF_CPU_AVX2) ? 'y' : 'n',
1161                 (x & RTE_CRYPTODEV_FF_CPU_AVX512) ? 'y' : 'n');
1162         printf("\t\t  + AESNI: CPU (%c), HW (%c)\n",
1163                 (x & RTE_CRYPTODEV_FF_CPU_AESNI) ? 'y' : 'n',
1164                 (x & RTE_CRYPTODEV_FF_HW_ACCELERATED) ? 'y' : 'n');
1165         printf("\t\t  + SECURITY OFFLOAD (%c)\n",
1166                 (x & RTE_CRYPTODEV_FF_SECURITY) ? 'y' : 'n');
1167         printf("\t\t  + ARM: NEON (%c), CE (%c)\n",
1168                 (x & RTE_CRYPTODEV_FF_CPU_NEON) ? 'y' : 'n',
1169                 (x & RTE_CRYPTODEV_FF_CPU_ARM_CE) ? 'y' : 'n');
1170         printf("\t  -- buffer offload\n");
1171         printf("\t\t  + IN_PLACE_SGL (%c)\n",
1172                 (x & RTE_CRYPTODEV_FF_IN_PLACE_SGL) ? 'y' : 'n');
1173         printf("\t\t  + OOP_SGL_IN_SGL_OUT (%c)\n",
1174                 (x & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT) ? 'y' : 'n');
1175         printf("\t\t  + OOP_SGL_IN_LB_OUT (%c)\n",
1176                 (x & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT) ? 'y' : 'n');
1177         printf("\t\t  + OOP_LB_IN_SGL_OUT (%c)\n",
1178                 (x & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT) ? 'y' : 'n');
1179         printf("\t\t  + OOP_LB_IN_LB_OUT (%c)\n",
1180                 (x & RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT) ? 'y' : 'n');
1181 }
1182
1183 static void
1184 show_crypto(void)
1185 {
1186         uint8_t crypto_dev_count = rte_cryptodev_count(), i;
1187
1188         snprintf(bdr_str, MAX_STRING_LEN, " show - CRYPTO PMD ");
1189         STATS_BDR_STR(10, bdr_str);
1190
1191         for (i = 0; i < crypto_dev_count; i++) {
1192                 struct rte_cryptodev_info dev_info;
1193                 struct rte_cryptodev_stats stats;
1194
1195                 rte_cryptodev_info_get(i, &dev_info);
1196
1197                 printf("  - device (%u)\n", i);
1198                 printf("\t  -- name (%s)\n"
1199                        "\t  -- driver (%s)\n"
1200                        "\t  -- id (%u) on socket (%d)\n"
1201                        "\t  -- queue pairs (%d)\n",
1202                        rte_cryptodev_name_get(i),
1203                        dev_info.driver_name,
1204                        dev_info.driver_id,
1205                        dev_info.device->numa_node,
1206                        rte_cryptodev_queue_pair_count(i));
1207
1208                 display_crypto_feature_info(dev_info.feature_flags);
1209
1210                 if (rte_cryptodev_stats_get(i, &stats) == 0) {
1211                         printf("\t  -- stats\n");
1212                         printf("\t\t  + enqueue count (%"PRIu64")"
1213                                " error (%"PRIu64")\n",
1214                                stats.enqueued_count,
1215                                stats.enqueue_err_count);
1216                         printf("\t\t  + dequeue count (%"PRIu64")"
1217                                " error (%"PRIu64")\n",
1218                                stats.dequeued_count,
1219                                stats.dequeue_err_count);
1220                 }
1221
1222 #ifdef RTE_LIB_SECURITY
1223                 show_security_context(i);
1224 #endif
1225         }
1226 }
1227
1228 static void
1229 show_ring(char *name)
1230 {
1231         snprintf(bdr_str, MAX_STRING_LEN, " show - RING ");
1232         STATS_BDR_STR(10, bdr_str);
1233
1234         if (name != NULL) {
1235                 struct rte_ring *ptr = rte_ring_lookup(name);
1236                 if (ptr != NULL) {
1237                         printf("  - Name (%s) on socket (%d)\n"
1238                                 "  - flags:\n"
1239                                 "\t  -- Single Producer Enqueue (%u)\n"
1240                                 "\t  -- Single Consmer Dequeue (%u)\n",
1241                                 ptr->name,
1242                                 ptr->memzone->socket_id,
1243                                 ptr->flags & RING_F_SP_ENQ,
1244                                 ptr->flags & RING_F_SC_DEQ);
1245                         printf("  - size (%u) mask (0x%x) capacity (%u)\n",
1246                                 ptr->size,
1247                                 ptr->mask,
1248                                 ptr->capacity);
1249                         printf("  - count (%u) free count (%u)\n",
1250                                 rte_ring_count(ptr),
1251                                 rte_ring_free_count(ptr));
1252                         printf("  - full (%d) empty (%d)\n",
1253                                 rte_ring_full(ptr),
1254                                 rte_ring_empty(ptr));
1255
1256                         STATS_BDR_STR(50, "");
1257                         return;
1258                 }
1259         }
1260
1261         rte_ring_list_dump(stdout);
1262 }
1263
1264 static void
1265 show_mempool(char *name)
1266 {
1267         uint64_t flags = 0;
1268
1269         snprintf(bdr_str, MAX_STRING_LEN, " show - MEMPOOL ");
1270         STATS_BDR_STR(10, bdr_str);
1271
1272         if (name != NULL) {
1273                 struct rte_mempool *ptr = rte_mempool_lookup(name);
1274                 if (ptr != NULL) {
1275                         struct rte_mempool_ops *ops;
1276
1277                         flags = ptr->flags;
1278                         ops = rte_mempool_get_ops(ptr->ops_index);
1279                         printf("  - Name: %s on socket %d\n"
1280                                 "  - flags:\n"
1281                                 "\t  -- No spread (%c)\n"
1282                                 "\t  -- No cache align (%c)\n"
1283                                 "\t  -- SP put (%c), SC get (%c)\n"
1284                                 "\t  -- Pool created (%c)\n"
1285                                 "\t  -- No IOVA config (%c)\n",
1286                                 ptr->name,
1287                                 ptr->socket_id,
1288                                 (flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n',
1289                                 (flags & MEMPOOL_F_NO_CACHE_ALIGN) ? 'y' : 'n',
1290                                 (flags & MEMPOOL_F_SP_PUT) ? 'y' : 'n',
1291                                 (flags & MEMPOOL_F_SC_GET) ? 'y' : 'n',
1292                                 (flags & MEMPOOL_F_POOL_CREATED) ? 'y' : 'n',
1293                                 (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n');
1294                         printf("  - Size %u Cache %u element %u\n"
1295                                 "  - header %u trailer %u\n"
1296                                 "  - private data size %u\n",
1297                                 ptr->size,
1298                                 ptr->cache_size,
1299                                 ptr->elt_size,
1300                                 ptr->header_size,
1301                                 ptr->trailer_size,
1302                                 ptr->private_data_size);
1303                         printf("  - memezone - socket %d\n",
1304                                 ptr->mz->socket_id);
1305                         printf("  - Count: avail (%u), in use (%u)\n",
1306                                 rte_mempool_avail_count(ptr),
1307                                 rte_mempool_in_use_count(ptr));
1308                         printf("  - ops_index %d ops_name %s\n",
1309                                 ptr->ops_index, ops ? ops->name : "NA");
1310
1311                         return;
1312                 }
1313         }
1314
1315         rte_mempool_list_dump(stdout);
1316 }
1317
1318 static void
1319 mempool_itr_obj(struct rte_mempool *mp, void *opaque,
1320                 void *obj, unsigned int obj_idx)
1321 {
1322         printf("  - obj_idx %u opaque %p obj %p\n",
1323                         obj_idx, opaque, obj);
1324
1325         if (obj)
1326                 rte_hexdump(stdout, " Obj Content",
1327                                 obj, (mp->elt_size > 256)?256:mp->elt_size);
1328 }
1329
1330 static void
1331 iter_mempool(char *name)
1332 {
1333         snprintf(bdr_str, MAX_STRING_LEN, " iter - MEMPOOL ");
1334         STATS_BDR_STR(10, bdr_str);
1335
1336         if (name != NULL) {
1337                 struct rte_mempool *ptr = rte_mempool_lookup(name);
1338                 if (ptr != NULL) {
1339                         /* iterate each object */
1340                         uint32_t ret = rte_mempool_obj_iter(ptr,
1341                                         mempool_itr_obj, NULL);
1342                         printf("\n  - iterated %u objects\n", ret);
1343                         return;
1344                 }
1345         }
1346 }
1347
1348 int
1349 main(int argc, char **argv)
1350 {
1351         int ret;
1352         int i;
1353         char c_flag[] = "-c1";
1354         char n_flag[] = "-n4";
1355         char mp_flag[] = "--proc-type=secondary";
1356         char log_flag[] = "--log-level=6";
1357         char *argp[argc + 4];
1358         uint16_t nb_ports;
1359
1360         /* preparse app arguments */
1361         ret = proc_info_preparse_args(argc, argv);
1362         if (ret < 0) {
1363                 printf("Failed to parse arguments\n");
1364                 return -1;
1365         }
1366
1367         argp[0] = argv[0];
1368         argp[1] = c_flag;
1369         argp[2] = n_flag;
1370         argp[3] = mp_flag;
1371         argp[4] = log_flag;
1372
1373         for (i = 1; i < argc; i++)
1374                 argp[i + 4] = argv[i];
1375
1376         argc += 4;
1377
1378         ret = rte_eal_init(argc, argp);
1379         if (ret < 0)
1380                 rte_panic("Cannot init EAL\n");
1381
1382         argc -= ret;
1383         argv += ret - 4;
1384
1385         if (!rte_eal_primary_proc_alive(NULL))
1386                 rte_exit(EXIT_FAILURE, "No primary DPDK process is running.\n");
1387
1388         /* parse app arguments */
1389         ret = proc_info_parse_args(argc, argv);
1390         if (ret < 0)
1391                 rte_exit(EXIT_FAILURE, "Invalid argument\n");
1392
1393         if (mem_info) {
1394                 meminfo_display();
1395                 return 0;
1396         }
1397
1398         nb_ports = rte_eth_dev_count_avail();
1399         if (nb_ports == 0)
1400                 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
1401
1402         /* If no port mask was specified, then show non-owned ports */
1403         if (enabled_port_mask == 0) {
1404                 RTE_ETH_FOREACH_DEV(i)
1405                         enabled_port_mask = 1ul << i;
1406         }
1407
1408         for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
1409
1410                 /* Skip if port is not in mask */
1411                 if ((enabled_port_mask & (1ul << i)) == 0)
1412                         continue;
1413
1414                 /* Skip if port is unused */
1415                 if (!rte_eth_dev_is_valid_port(i))
1416                         continue;
1417
1418                 if (enable_stats)
1419                         nic_stats_display(i);
1420                 else if (enable_xstats)
1421                         nic_xstats_display(i);
1422                 else if (reset_stats)
1423                         nic_stats_clear(i);
1424                 else if (reset_xstats)
1425                         nic_xstats_clear(i);
1426                 else if (enable_xstats_name)
1427                         nic_xstats_by_name_display(i, xstats_name);
1428                 else if (nb_xstats_ids > 0)
1429                         nic_xstats_by_ids_display(i, xstats_ids,
1430                                                   nb_xstats_ids);
1431                 else if (enable_metrics)
1432                         metrics_display(i);
1433
1434         }
1435
1436         /* print port independent stats */
1437         if (enable_metrics)
1438                 metrics_display(RTE_METRICS_GLOBAL);
1439
1440         /* show information for PMD */
1441         if (enable_shw_port)
1442                 show_port();
1443         if (enable_shw_tm)
1444                 show_tm();
1445         if (enable_shw_crypto)
1446                 show_crypto();
1447         if (enable_shw_ring)
1448                 show_ring(ring_name);
1449         if (enable_shw_mempool)
1450                 show_mempool(mempool_name);
1451         if (enable_iter_mempool)
1452                 iter_mempool(mempool_iter_name);
1453
1454         RTE_ETH_FOREACH_DEV(i)
1455                 rte_eth_dev_close(i);
1456
1457         ret = rte_eal_cleanup();
1458         if (ret)
1459                 printf("Error from rte_eal_cleanup(), %d\n", ret);
1460
1461         return 0;
1462 }