xref: /dpdk/drivers/net/intel/ice/ice_testpmd.c (revision c1d145834f287aa8cf53de914618a7312f2c360e)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2022 Intel Corporation.
3  */
4 
5 #include <stdlib.h>
6 #include <stdio.h>
7 
8 #include <cmdline_parse_num.h>
9 #include <cmdline_parse_string.h>
10 
11 #include "testpmd.h"
12 #include "ice_ethdev.h"
13 
14 /* Fixed size for ICE ddp runtime configure */
15 #define ICE_BUFF_SIZE	0x000c9000
16 #define ICE_SWITCH_BUFF_SIZE	(4 * 1024 * 1024)
17 
18 /* Dump device ddp package, only for ice PF */
19 struct cmd_ddp_dump_result {
20 	cmdline_fixed_string_t ddp;
21 	cmdline_fixed_string_t dump;
22 	portid_t port_id;
23 	char filepath[];
24 };
25 
26 cmdline_parse_token_string_t cmd_ddp_dump_ddp =
27 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_result, ddp, "ddp");
28 cmdline_parse_token_string_t cmd_ddp_dump_dump =
29 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_result, dump, "dump");
30 cmdline_parse_token_num_t cmd_ddp_dump_port_id =
31 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_dump_result, port_id, RTE_UINT16);
32 cmdline_parse_token_string_t cmd_ddp_dump_filepath =
33 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_result, filepath, NULL);
34 
35 static void
36 cmd_ddp_dump_parsed(void *parsed_result,
37 		    __rte_unused struct cmdline *cl,
38 		    __rte_unused void *data)
39 {
40 	struct cmd_ddp_dump_result *res = parsed_result;
41 	uint8_t *buff;
42 	uint32_t size;
43 	int ret = -ENOTSUP;
44 
45 	size = ICE_BUFF_SIZE;
46 	buff = (uint8_t *)malloc(ICE_BUFF_SIZE);
47 	if (buff) {
48 		ret = rte_pmd_ice_dump_package(res->port_id, &buff, &size);
49 		switch (ret) {
50 		case 0:
51 			save_file(res->filepath, buff, size);
52 			break;
53 		case -EINVAL:
54 			fprintf(stderr, "Invalid buffer size\n");
55 			break;
56 		case -ENOTSUP:
57 			fprintf(stderr,
58 				"Device doesn't support "
59 				"dump DDP runtime configure.\n");
60 			break;
61 		default:
62 			fprintf(stderr,
63 				"Failed to dump DDP runtime configure,"
64 				" error: (%s)\n", strerror(-ret));
65 		}
66 	}
67 	free(buff);
68 }
69 
70 cmdline_parse_inst_t cmd_ddp_dump = {
71 	.f = cmd_ddp_dump_parsed,
72 	.data = NULL,
73 	.help_str = "ddp dump <port_id> <config_path>",
74 	.tokens = {
75 		(void *)&cmd_ddp_dump_ddp,
76 		(void *)&cmd_ddp_dump_dump,
77 		(void *)&cmd_ddp_dump_port_id,
78 		(void *)&cmd_ddp_dump_filepath,
79 		NULL,
80 	},
81 };
82 
83 struct cmd_ddp_dump_switch_result {
84 	cmdline_fixed_string_t ddp;
85 	cmdline_fixed_string_t dump;
86 	cmdline_fixed_string_t swt;
87 	portid_t port_id;
88 	char filepath[];
89 };
90 
91 cmdline_parse_token_string_t cmd_ddp_dump_swt_ddp =
92 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_switch_result, ddp, "ddp");
93 cmdline_parse_token_string_t cmd_ddp_dump_swt_dump =
94 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_switch_result, dump, "dump");
95 cmdline_parse_token_string_t cmd_ddp_dump_swt_switch =
96 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_switch_result, swt, "switch");
97 cmdline_parse_token_num_t cmd_ddp_dump_swt_port_id =
98 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_dump_switch_result, port_id, RTE_UINT16);
99 cmdline_parse_token_string_t cmd_ddp_dump_swt_filepath =
100 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_dump_switch_result, filepath, NULL);
101 
102 static void
103 cmd_ddp_dump_switch_parsed(void *parsed_result,
104 			   __rte_unused struct cmdline *cl,
105 			   __rte_unused void *data)
106 {
107 	struct cmd_ddp_dump_switch_result *res = parsed_result;
108 	uint8_t *buff;
109 	uint32_t size;
110 	int ret = -ENOTSUP;
111 
112 	size = ICE_SWITCH_BUFF_SIZE;
113 	buff = malloc(size);
114 	if (buff) {
115 		ret = rte_pmd_ice_dump_switch(res->port_id, &buff, &size);
116 		switch (ret) {
117 		case 0:
118 			save_file(res->filepath, buff, size);
119 			break;
120 		case -EINVAL:
121 			fprintf(stderr, "Invalid buffer size\n");
122 			break;
123 		case -ENOTSUP:
124 			fprintf(stderr,
125 				"Device doesn't support "
126 				"dump DDP switch runtime configure.\n");
127 			break;
128 		default:
129 			fprintf(stderr,
130 				"Failed to dump DDP switch runtime configure,"
131 				" error: (%s)\n", strerror(-ret));
132 		}
133 	}
134 	free(buff);
135 }
136 
137 
138 cmdline_parse_inst_t cmd_ddp_dump_switch = {
139 	.f = cmd_ddp_dump_switch_parsed,
140 	.data = NULL,
141 	.help_str = "ddp dump switch <port_id> <config_path>",
142 	.tokens = {
143 		(void *)&cmd_ddp_dump_swt_ddp,
144 		(void *)&cmd_ddp_dump_swt_dump,
145 		(void *)&cmd_ddp_dump_swt_switch,
146 		(void *)&cmd_ddp_dump_swt_port_id,
147 		(void *)&cmd_ddp_dump_swt_filepath,
148 		NULL,
149 	},
150 };
151 
152 /* Dump Tx Scheduling Tree configuration, only for ice PF */
153 struct cmd_txsched_dump_result {
154 	cmdline_fixed_string_t txsched;
155 	cmdline_fixed_string_t dump;
156 	portid_t port_id;
157 	cmdline_fixed_string_t mode;
158 	char filepath[];
159 };
160 
161 cmdline_parse_token_string_t cmd_txsched_dump_txsched =
162 	TOKEN_STRING_INITIALIZER(struct cmd_txsched_dump_result, txsched, "txsched");
163 cmdline_parse_token_string_t cmd_txsched_dump_dump =
164 	TOKEN_STRING_INITIALIZER(struct cmd_txsched_dump_result, dump, "dump");
165 cmdline_parse_token_num_t cmd_txsched_dump_port_id =
166 	TOKEN_NUM_INITIALIZER(struct cmd_txsched_dump_result, port_id, RTE_UINT16);
167 cmdline_parse_token_string_t cmd_txsched_dump_mode =
168 	TOKEN_STRING_INITIALIZER(struct cmd_txsched_dump_result, mode, "brief#detail");
169 cmdline_parse_token_string_t cmd_txsched_dump_filepath =
170 	TOKEN_STRING_INITIALIZER(struct cmd_txsched_dump_result, filepath, NULL);
171 
172 static void
173 cmd_txsched_dump_parsed(void *parsed_result,
174 			__rte_unused struct cmdline *cl,
175 			__rte_unused void *data)
176 {
177 	struct cmd_txsched_dump_result *res = parsed_result;
178 	bool detail = false;
179 	FILE *fp;
180 
181 	if (!strcmp(res->mode, "detail"))
182 		detail = true;
183 
184 	fp = fopen(res->filepath, "w");
185 	if (fp == NULL) {
186 		fprintf(stderr, "Failed to open file\n");
187 		return;
188 	}
189 
190 	if (rte_pmd_ice_dump_txsched(res->port_id, detail, fp))
191 		fprintf(stderr, "Failed to dump Tx scheduring runtime configure.\n");
192 	fclose(fp);
193 }
194 
195 cmdline_parse_inst_t cmd_txsched_dump = {
196 	.f = cmd_txsched_dump_parsed,
197 	.data = NULL,
198 	.help_str = "txsched dump <port_id> <brief|detail> <config_path>",
199 	.tokens = {
200 		(void *)&cmd_txsched_dump_txsched,
201 		(void *)&cmd_txsched_dump_dump,
202 		(void *)&cmd_txsched_dump_port_id,
203 		(void *)&cmd_txsched_dump_mode,
204 		(void *)&cmd_txsched_dump_filepath,
205 		NULL,
206 	},
207 };
208 
209 static struct testpmd_driver_commands ice_cmds = {
210 	.commands = {
211 	{
212 		&cmd_ddp_dump,
213 		"ddp dump (port_id) (config_path)\n"
214 		"    Dump a runtime configure on a port\n\n",
215 
216 	},
217 	{
218 		&cmd_ddp_dump_switch,
219 		"ddp dump switch (port_id) (config_path)\n"
220 		"    Dump a runtime switch configure on a port\n\n",
221 
222 	},
223 	{
224 		&cmd_txsched_dump,
225 		"txsched dump (port_id) <brief|detail> (config_path)\n"
226 		"    Dump tx scheduling runtime configure on a port\n\n",
227 
228 	},
229 	{ NULL, NULL },
230 	},
231 };
232 
233 TESTPMD_ADD_DRIVER_COMMANDS(ice_cmds)
234