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