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