net/ice/base: fix build with GCC 12
[dpdk.git] / drivers / net / ice / ice_testpmd.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2022 Intel Corporation.
3  */
4
5 #include <rte_pmd_ice.h>
6
7 #include <cmdline_parse_num.h>
8 #include <cmdline_parse_string.h>
9
10 #include "testpmd.h"
11
12 /* Fixed size for ICE ddp runtime configure */
13 #define ICE_BUFF_SIZE   0x000c9000
14
15 /* Dump device ddp package, only for ice PF */
16 struct cmd_ddp_dump_result {
17         cmdline_fixed_string_t ddp;
18         cmdline_fixed_string_t add;
19         portid_t port_id;
20         char filepath[];
21 };
22
23 cmdline_parse_token_string_t cmd_ddp_dump_ddp =
24         TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_result, ddp, "ddp");
25 cmdline_parse_token_string_t cmd_ddp_dump_dump =
26         TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_result, add, "dump");
27 cmdline_parse_token_num_t cmd_ddp_dump_port_id =
28         TOKEN_NUM_INITIALIZER(struct cmd_ddp_dump_result, port_id, RTE_UINT16);
29 cmdline_parse_token_string_t cmd_ddp_dump_filepath =
30         TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_result, filepath, NULL);
31
32 static void
33 cmd_ddp_dump_parsed(void *parsed_result,
34                     __rte_unused struct cmdline *cl,
35                     __rte_unused void *data)
36 {
37         struct cmd_ddp_dump_result *res = parsed_result;
38         uint8_t *buff;
39         uint32_t size;
40         int ret = -ENOTSUP;
41
42         size = ICE_BUFF_SIZE;
43         buff = (uint8_t *)malloc(ICE_BUFF_SIZE);
44         if (buff) {
45                 ret = rte_pmd_ice_dump_package(res->port_id, &buff, &size);
46                 switch (ret) {
47                 case 0:
48                         save_file(res->filepath, buff, size);
49                         break;
50                 case -EINVAL:
51                         fprintf(stderr, "Invalid buffer size\n");
52                         break;
53                 case -ENOTSUP:
54                         fprintf(stderr,
55                                 "Device doesn't support "
56                                 "dump DDP runtime configure.\n");
57                         break;
58                 default:
59                         fprintf(stderr,
60                                 "Failed to dump DDP runtime configure,"
61                                 " error: (%s)\n", strerror(-ret));
62                 }
63         }
64         free(buff);
65 }
66
67 cmdline_parse_inst_t cmd_ddp_dump = {
68         .f = cmd_ddp_dump_parsed,
69         .data = NULL,
70         .help_str = "ddp dump <port_id> <config_path>",
71         .tokens = {
72                 (void *)&cmd_ddp_dump_ddp,
73                 (void *)&cmd_ddp_dump_dump,
74                 (void *)&cmd_ddp_dump_port_id,
75                 (void *)&cmd_ddp_dump_filepath,
76                 NULL,
77         },
78 };
79
80 static struct testpmd_driver_commands ice_cmds = {
81         .commands = {
82         {
83                 &cmd_ddp_dump,
84                 "ddp dump (port_id) (config_path)\n"
85                 "    Dump a runtime configure on a port\n\n",
86
87         },
88         { NULL, NULL },
89         },
90 };
91 TESTPMD_ADD_DRIVER_COMMANDS(ice_cmds)