xref: /dpdk/app/graph/ethdev.c (revision da7e701151ea8b742d4c38ace3e4fefd1b4507fc)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2023 Marvell.
3  */
4 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 
9 #include <cmdline_parse.h>
10 #include <cmdline_parse_num.h>
11 #include <cmdline_parse_string.h>
12 #include <cmdline_socket.h>
13 #include <rte_bitops.h>
14 #include <rte_ethdev.h>
15 #include <rte_mempool.h>
16 
17 #include "ethdev_priv.h"
18 #include "module_api.h"
19 
20 static const char
21 cmd_ethdev_mtu_help[] = "ethdev <ethdev_name> mtu <mtu_sz>";
22 
23 static const char
24 cmd_ethdev_prom_mode_help[] = "ethdev <ethdev_name> promiscuous <on/off>";
25 
26 static const char
27 cmd_ethdev_help[] = "ethdev <ethdev_name> rxq <n_queues> txq <n_queues> <mempool_name>";
28 
29 static const char
30 cmd_ethdev_stats_help[] = "ethdev <ethdev_name> stats";
31 
32 static const char
33 cmd_ethdev_show_help[] = "ethdev <ethdev_name> show";
34 
35 static const char
36 cmd_ethdev_ip4_addr_help[] = "ethdev <ethdev_name> ip4 addr add <ip> netmask <mask>";
37 
38 static const char
39 cmd_ethdev_ip6_addr_help[] = "ethdev <ethdev_name> ip6 addr add <ip> netmask <mask>";
40 
41 static struct rte_eth_conf port_conf_default = {
42 	.link_speeds = 0,
43 	.rxmode = {
44 		.mq_mode = RTE_ETH_MQ_RX_NONE,
45 		.mtu = 9000 - (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN), /* Jumbo frame MTU */
46 	},
47 	.rx_adv_conf = {
48 		.rss_conf = {
49 			.rss_key = NULL,
50 			.rss_key_len = 40,
51 			.rss_hf = 0,
52 		},
53 	},
54 	.txmode = {
55 		.mq_mode = RTE_ETH_MQ_TX_NONE,
56 	},
57 	.lpbk_mode = 0,
58 };
59 
60 uint32_t enabled_port_mask;
61 static struct ethdev_head eth_node = TAILQ_HEAD_INITIALIZER(eth_node);
62 
63 
64 static struct ethdev*
65 ethdev_port_by_id(uint16_t port_id)
66 {
67 	struct ethdev *port;
68 
69 	TAILQ_FOREACH(port, &eth_node, next) {
70 		if (port->config.port_id == port_id)
71 			return port;
72 	}
73 	return NULL;
74 }
75 
76 void *
77 ethdev_mempool_list_by_portid(uint16_t portid)
78 {
79 	struct ethdev *port;
80 
81 	if (portid >= RTE_MAX_ETHPORTS)
82 		return NULL;
83 
84 	port = ethdev_port_by_id(portid);
85 	if (port)
86 		return &(port->config.rx.mp);
87 	else
88 		return NULL;
89 }
90 
91 int16_t
92 ethdev_portid_by_ip4(uint32_t ip, uint32_t mask)
93 {
94 	int portid = -EINVAL;
95 	struct ethdev *port;
96 
97 	TAILQ_FOREACH(port, &eth_node, next) {
98 		if (mask == 0) {
99 			if ((port->ip4_addr.ip & port->ip4_addr.mask) == (ip & port->ip4_addr.mask))
100 				return port->config.port_id;
101 		} else {
102 			if ((port->ip4_addr.ip & port->ip4_addr.mask) == (ip & mask))
103 				return port->config.port_id;
104 		}
105 	}
106 
107 	return portid;
108 }
109 
110 int16_t
111 ethdev_portid_by_ip6(uint8_t *ip, uint8_t *mask)
112 {
113 	int portid = -EINVAL;
114 	struct ethdev *port;
115 	int j;
116 
117 	TAILQ_FOREACH(port, &eth_node, next) {
118 		for (j = 0; j < ETHDEV_IPV6_ADDR_LEN; j++) {
119 			if (mask == NULL) {
120 				if ((port->ip6_addr.ip[j] & port->ip6_addr.mask[j]) !=
121 				    (ip[j] & port->ip6_addr.mask[j]))
122 					break;
123 
124 			} else {
125 				if ((port->ip6_addr.ip[j] & port->ip6_addr.mask[j]) !=
126 				    (ip[j] & mask[j]))
127 					break;
128 			}
129 		}
130 		if (j == ETHDEV_IPV6_ADDR_LEN)
131 			return port->config.port_id;
132 	}
133 
134 	return portid;
135 }
136 
137 void
138 ethdev_list_clean(void)
139 {
140 	struct ethdev *port;
141 
142 	while (!TAILQ_EMPTY(&eth_node)) {
143 		port = TAILQ_FIRST(&eth_node);
144 		TAILQ_REMOVE(&eth_node, port, next);
145 	}
146 }
147 
148 void
149 ethdev_stop(void)
150 {
151 	uint16_t portid;
152 	int rc;
153 
154 	RTE_ETH_FOREACH_DEV(portid) {
155 		if ((enabled_port_mask & (1 << portid)) == 0)
156 			continue;
157 		printf("Closing port %d...", portid);
158 		rc = rte_eth_dev_stop(portid);
159 		if (rc != 0)
160 			printf("Failed to stop port %u: %s\n",
161 					portid, rte_strerror(-rc));
162 		rte_eth_dev_close(portid);
163 		printf(" Done\n");
164 	}
165 
166 	ethdev_list_clean();
167 	route_ip4_list_clean();
168 	route_ip6_list_clean();
169 	neigh4_list_clean();
170 	neigh6_list_clean();
171 	printf("Bye...\n");
172 }
173 
174 void
175 ethdev_start(void)
176 {
177 	uint16_t portid;
178 	int rc;
179 
180 	RTE_ETH_FOREACH_DEV(portid)
181 	{
182 		if ((enabled_port_mask & (1 << portid)) == 0)
183 			continue;
184 
185 		rc = rte_eth_dev_start(portid);
186 		if (rc < 0)
187 			rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%d\n", rc, portid);
188 	}
189 }
190 
191 
192 static int
193 ethdev_show(const char *name)
194 {
195 	uint16_t mtu = 0, port_id = 0;
196 	struct rte_eth_dev_info info;
197 	struct rte_eth_stats stats;
198 	struct rte_ether_addr addr;
199 	struct rte_eth_link link;
200 	uint32_t length;
201 	int rc;
202 
203 	rc = rte_eth_dev_get_port_by_name(name, &port_id);
204 	if (rc < 0)
205 		return rc;
206 
207 	rte_eth_dev_info_get(port_id, &info);
208 	rte_eth_stats_get(port_id, &stats);
209 	rte_eth_macaddr_get(port_id, &addr);
210 	rte_eth_link_get(port_id, &link);
211 	rte_eth_dev_get_mtu(port_id, &mtu);
212 
213 	length = strlen(conn->msg_out);
214 	conn->msg_out += length;
215 	snprintf(conn->msg_out, conn->msg_out_len_max,
216 		 "%s: flags=<%s> mtu %u\n"
217 		 "\tether " RTE_ETHER_ADDR_PRT_FMT " rxqueues %u txqueues %u\n"
218 		 "\tport# %u  speed %s\n"
219 		 "\tRX packets %" PRIu64"  bytes %" PRIu64"\n"
220 		 "\tRX errors %" PRIu64"  missed %" PRIu64"  no-mbuf %" PRIu64"\n"
221 		 "\tTX packets %" PRIu64"  bytes %" PRIu64"\n"
222 		 "\tTX errors %" PRIu64"\n\n",
223 		 name,
224 		 link.link_status ? "UP" : "DOWN",
225 		 mtu,
226 		 RTE_ETHER_ADDR_BYTES(&addr),
227 		 info.nb_rx_queues,
228 		 info.nb_tx_queues,
229 		 port_id,
230 		 rte_eth_link_speed_to_str(link.link_speed),
231 		 stats.ipackets,
232 		 stats.ibytes,
233 		 stats.ierrors,
234 		 stats.imissed,
235 		 stats.rx_nombuf,
236 		 stats.opackets,
237 		 stats.obytes,
238 		 stats.oerrors);
239 
240 	length = strlen(conn->msg_out);
241 	conn->msg_out_len_max -= length;
242 	return 0;
243 }
244 
245 static int
246 ethdev_ip4_addr_add(const char *name, struct ipv4_addr_config *config)
247 {
248 	struct ethdev *eth_hdl;
249 	uint16_t portid = 0;
250 	int rc;
251 
252 	rc = rte_eth_dev_get_port_by_name(name, &portid);
253 	if (rc < 0)
254 		return rc;
255 
256 	eth_hdl = ethdev_port_by_id(portid);
257 
258 	if (eth_hdl) {
259 		eth_hdl->ip4_addr.ip = config->ip;
260 		eth_hdl->ip4_addr.mask = config->mask;
261 		return 0;
262 	}
263 
264 	rc = -EINVAL;
265 	return rc;
266 }
267 
268 static int
269 ethdev_ip6_addr_add(const char *name, struct ipv6_addr_config *config)
270 {
271 	struct ethdev *eth_hdl;
272 	uint16_t portid = 0;
273 	int rc, i;
274 
275 	rc = rte_eth_dev_get_port_by_name(name, &portid);
276 	if (rc < 0)
277 		return rc;
278 
279 	eth_hdl = ethdev_port_by_id(portid);
280 
281 	if (eth_hdl) {
282 		for (i = 0; i < ETHDEV_IPV6_ADDR_LEN; i++) {
283 			eth_hdl->ip6_addr.ip[i] = config->ip[i];
284 			eth_hdl->ip6_addr.mask[i] = config->mask[i];
285 		}
286 		return 0;
287 	}
288 	rc = -EINVAL;
289 	return rc;
290 }
291 
292 static int
293 ethdev_prom_mode_config(const char *name, bool enable)
294 {
295 	struct ethdev *eth_hdl;
296 	uint16_t portid = 0;
297 	int rc;
298 
299 	rc = rte_eth_dev_get_port_by_name(name, &portid);
300 	if (rc < 0)
301 		return rc;
302 
303 	eth_hdl = ethdev_port_by_id(portid);
304 
305 	if (eth_hdl) {
306 		if (enable)
307 			rc = rte_eth_promiscuous_enable(portid);
308 		else
309 			rc = rte_eth_promiscuous_disable(portid);
310 		if (rc < 0)
311 			return rc;
312 
313 		eth_hdl->config.promiscuous = enable;
314 		return 0;
315 	}
316 
317 	rc = -EINVAL;
318 	return rc;
319 }
320 
321 static int
322 ethdev_mtu_config(const char *name, uint32_t mtu)
323 {
324 	struct ethdev *eth_hdl;
325 	uint16_t portid = 0;
326 	int rc;
327 
328 	rc = rte_eth_dev_get_port_by_name(name, &portid);
329 	if (rc < 0)
330 		return rc;
331 
332 	eth_hdl = ethdev_port_by_id(portid);
333 
334 	if (eth_hdl) {
335 		rc = rte_eth_dev_set_mtu(portid, mtu);
336 		if (rc < 0)
337 			return rc;
338 
339 		eth_hdl->config.mtu = mtu;
340 		return 0;
341 	}
342 
343 	rc = -EINVAL;
344 	return rc;
345 }
346 
347 
348 static int
349 ethdev_process(const char *name, struct ethdev_config *params)
350 {
351 	struct rte_eth_dev_info port_info;
352 	struct rte_eth_conf port_conf;
353 	struct ethdev_rss_config *rss;
354 	struct rte_mempool *mempool;
355 	struct ethdev *ethdev_port;
356 	struct rte_ether_addr smac;
357 	uint16_t port_id = 0;
358 	int numa_node, rc;
359 	uint32_t i;
360 
361 	/* Check input params */
362 	if (!name || !name[0] || !params || !params->rx.n_queues || !params->rx.queue_size ||
363 	    !params->tx.n_queues || !params->tx.queue_size)
364 		return -EINVAL;
365 
366 	rc = rte_eth_dev_get_port_by_name(name, &port_id);
367 	if (rc)
368 		return -EINVAL;
369 
370 	if (!ethdev_port_by_id(port_id)) {
371 		ethdev_port = malloc(sizeof(struct ethdev));
372 		if (!ethdev_port)
373 			return -EINVAL;
374 	} else {
375 		return 0;
376 	}
377 
378 	rc = rte_eth_dev_info_get(port_id, &port_info);
379 	if (rc) {
380 		rc = -EINVAL;
381 		goto exit;
382 	}
383 
384 	mempool = rte_mempool_lookup(params->rx.mempool_name);
385 	if (!mempool) {
386 		rc =  -EINVAL;
387 		goto exit;
388 	}
389 
390 	params->rx.mp = mempool;
391 
392 	rss = params->rx.rss;
393 	if (rss) {
394 		if (!port_info.reta_size || port_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
395 			rc = -EINVAL;
396 			goto exit;
397 		}
398 
399 		if (!rss->n_queues || rss->n_queues >= ETHDEV_RXQ_RSS_MAX) {
400 			rc = -EINVAL;
401 			goto exit;
402 		}
403 
404 		for (i = 0; i < rss->n_queues; i++)
405 			if (rss->queue_id[i] >= port_info.max_rx_queues) {
406 				rc = -EINVAL;
407 				goto exit;
408 			}
409 	}
410 
411 	/* Port */
412 	memcpy(&port_conf, &port_conf_default, sizeof(struct rte_eth_conf));
413 	if (rss) {
414 		uint64_t rss_hf = RTE_ETH_RSS_IP | RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP;
415 
416 		port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_RSS;
417 		port_conf.rx_adv_conf.rss_conf.rss_hf = rss_hf & port_info.flow_type_rss_offloads;
418 	}
419 
420 	numa_node = rte_eth_dev_socket_id(port_id);
421 	if (numa_node == SOCKET_ID_ANY)
422 		numa_node = 0;
423 
424 	if (params->mtu)
425 		port_conf.rxmode.mtu = params->mtu;
426 
427 	rc = rte_eth_dev_configure(port_id, params->rx.n_queues, params->tx.n_queues,
428 				       &port_conf);
429 	if (rc < 0) {
430 		rc = -EINVAL;
431 		goto exit;
432 	}
433 
434 	rc = rte_eth_macaddr_get(port_id, &smac);
435 	if (rc < 0) {
436 		rc = -EINVAL;
437 		goto exit;
438 	}
439 
440 	printf("Port_id = %d srcmac = %x:%x:%x:%x:%x:%x\n", port_id,
441 		smac.addr_bytes[0], smac.addr_bytes[1],
442 		smac.addr_bytes[2], smac.addr_bytes[3],
443 		smac.addr_bytes[4], smac.addr_bytes[5]);
444 
445 	/* Port RX */
446 	for (i = 0; i < params->rx.n_queues; i++) {
447 		rc = rte_eth_rx_queue_setup(port_id, i, params->rx.queue_size, numa_node, NULL,
448 			mempool);
449 		if (rc < 0) {
450 			rc = -EINVAL;
451 			goto exit;
452 		}
453 	}
454 
455 	/* Port TX */
456 	for (i = 0; i < params->tx.n_queues; i++) {
457 		rc = rte_eth_tx_queue_setup(port_id, i, params->tx.queue_size, numa_node, NULL);
458 		if (rc < 0) {
459 			rc = -EINVAL;
460 			goto exit;
461 		}
462 	}
463 
464 	memcpy(&ethdev_port->config, params, sizeof(struct ethdev_config));
465 	memcpy(ethdev_port->config.dev_name, name, strlen(name));
466 	ethdev_port->config.port_id = port_id;
467 	enabled_port_mask |= RTE_BIT32(port_id);
468 
469 	TAILQ_INSERT_TAIL(&eth_node, ethdev_port, next);
470 	return 0;
471 exit:
472 	free(ethdev_port);
473 	return rc;
474 
475 }
476 
477 static int
478 ethdev_stats_show(const char *name)
479 {
480 	uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx;
481 	static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
482 	static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
483 	static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
484 	static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
485 	static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
486 	uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
487 	uint64_t diff_ns, diff_cycles, curr_cycles;
488 	struct rte_eth_stats stats;
489 	static const char *nic_stats_border = "########################";
490 	uint16_t port_id, len;
491 	int rc;
492 
493 	rc = rte_eth_dev_get_port_by_name(name, &port_id);
494 	if (rc < 0)
495 		return rc;
496 
497 	rc = rte_eth_stats_get(port_id, &stats);
498 	if (rc != 0) {
499 		fprintf(stderr,
500 			"%s: Error: failed to get stats (port %u): %d",
501 			__func__, port_id, rc);
502 		return rc;
503 	}
504 
505 	len = strlen(conn->msg_out);
506 	conn->msg_out += len;
507 	snprintf(conn->msg_out, conn->msg_out_len_max,
508 		 "\n  %s NIC statistics for port %-2d %s\n"
509 		 "  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  ""%-"PRIu64"\n"
510 		 "  RX-errors: %-"PRIu64"\n"
511 		 "  RX-nombuf:  %-10"PRIu64"\n"
512 		 "  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  ""%-"PRIu64"\n",
513 		 nic_stats_border, port_id, nic_stats_border, stats.ipackets, stats.imissed,
514 		 stats.ibytes, stats.ierrors, stats.rx_nombuf, stats.opackets, stats.oerrors,
515 		 stats.obytes);
516 
517 	len = strlen(conn->msg_out) - len;
518 	conn->msg_out_len_max -= len;
519 
520 	diff_ns = 0;
521 	diff_cycles = 0;
522 
523 	curr_cycles = rte_rdtsc();
524 	if (prev_cycles[port_id] != 0)
525 		diff_cycles = curr_cycles - prev_cycles[port_id];
526 
527 	prev_cycles[port_id] = curr_cycles;
528 	diff_ns = diff_cycles > 0 ?
529 		diff_cycles * (1 / (double)rte_get_tsc_hz()) * NS_PER_SEC : 0;
530 
531 	diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
532 		(stats.ipackets - prev_pkts_rx[port_id]) : 0;
533 	diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
534 		(stats.opackets - prev_pkts_tx[port_id]) : 0;
535 	prev_pkts_rx[port_id] = stats.ipackets;
536 	prev_pkts_tx[port_id] = stats.opackets;
537 	mpps_rx = diff_ns > 0 ?
538 		(double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
539 	mpps_tx = diff_ns > 0 ?
540 		(double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
541 
542 	diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
543 		(stats.ibytes - prev_bytes_rx[port_id]) : 0;
544 	diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
545 		(stats.obytes - prev_bytes_tx[port_id]) : 0;
546 	prev_bytes_rx[port_id] = stats.ibytes;
547 	prev_bytes_tx[port_id] = stats.obytes;
548 	mbps_rx = diff_ns > 0 ?
549 		(double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
550 	mbps_tx = diff_ns > 0 ?
551 		(double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
552 
553 	len = strlen(conn->msg_out);
554 	snprintf(conn->msg_out + len, conn->msg_out_len_max,
555 		 "\n  Throughput (since last show)\n"
556 		 "  Rx-pps: %12"PRIu64"          Rx-bps: %12"PRIu64"\n  Tx-pps: %12"
557 		 PRIu64"          Tx-bps: %12"PRIu64"\n"
558 		 "  %s############################%s\n",
559 		 mpps_rx, mbps_rx * 8, mpps_tx, mbps_tx * 8, nic_stats_border, nic_stats_border);
560 	return 0;
561 }
562 
563 static void
564 cli_ethdev_mtu(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused)
565 {
566 	struct ethdev_mtu_cmd_tokens *res = parsed_result;
567 	int rc = -EINVAL;
568 
569 	rc = ethdev_mtu_config(res->dev, res->size);
570 	if (rc < 0)
571 		printf(MSG_CMD_FAIL, res->cmd);
572 }
573 
574 static void
575 cli_ethdev_prom_mode(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused)
576 {
577 	struct ethdev_prom_mode_cmd_tokens *res = parsed_result;
578 	bool enable = false;
579 	int rc = -EINVAL;
580 
581 	if (!strcmp(res->enable, "on"))
582 		enable = true;
583 
584 	rc = ethdev_prom_mode_config(res->dev, enable);
585 	if (rc < 0)
586 		printf(MSG_CMD_FAIL, res->cmd);
587 }
588 
589 static void
590 cli_ip4_addr(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused)
591 {
592 	struct ethdev_ip4_cmd_tokens *res = parsed_result;
593 	struct ipv4_addr_config config;
594 	int rc = -EINVAL;
595 
596 	if (parser_ip4_read(&config.ip, res->ip)) {
597 		printf(MSG_ARG_INVALID, "ip");
598 		return;
599 	}
600 
601 	if (parser_ip4_read(&config.mask, res->mask)) {
602 		printf(MSG_ARG_INVALID, "netmask");
603 		return;
604 	}
605 
606 	rc = ethdev_ip4_addr_add(res->dev, &config);
607 	if (rc < 0)
608 		printf(MSG_CMD_FAIL, res->cmd);
609 }
610 
611 static void
612 cli_ip6_addr(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused)
613 {
614 	struct ethdev_ip6_cmd_tokens *res = parsed_result;
615 	struct ipv6_addr_config config;
616 	int rc = -EINVAL;
617 
618 	if (parser_ip6_read(config.ip, res->ip)) {
619 		printf(MSG_ARG_INVALID, "ip");
620 		return;
621 	}
622 
623 	if (parser_ip6_read(config.mask, res->mask)) {
624 		printf(MSG_ARG_INVALID, "netmask");
625 		return;
626 	}
627 
628 	rc = ethdev_ip6_addr_add(res->dev, &config);
629 	if (rc < 0)
630 		printf(MSG_CMD_FAIL, res->cmd);
631 }
632 
633 static void
634 cli_ethdev_show(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused)
635 {
636 	struct ethdev_show_cmd_tokens *res = parsed_result;
637 	int rc = -EINVAL;
638 
639 	rc = ethdev_show(res->dev);
640 	if (rc < 0)
641 		printf(MSG_ARG_INVALID, res->dev);
642 }
643 
644 static void
645 cli_ethdev_stats(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused)
646 {
647 	struct ethdev_stats_cmd_tokens *res = parsed_result;
648 	int rc = -EINVAL;
649 
650 	rc = ethdev_stats_show(res->dev);
651 	if (rc < 0)
652 		printf(MSG_ARG_INVALID, res->dev);
653 }
654 
655 static void
656 cli_ethdev(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused)
657 {
658 	struct ethdev_cmd_tokens *res = parsed_result;
659 	struct ethdev_config config;
660 	int rc;
661 
662 	memset(&config, 0, sizeof(struct ethdev_config));
663 	config.rx.n_queues = res->nb_rxq;
664 	config.rx.queue_size = ETHDEV_RX_DESC_DEFAULT;
665 	memcpy(config.rx.mempool_name, res->mempool, strlen(res->mempool));
666 
667 	config.tx.n_queues = res->nb_txq;
668 	config.tx.queue_size = ETHDEV_TX_DESC_DEFAULT;
669 
670 	config.mtu = port_conf_default.rxmode.mtu;
671 
672 	rc = ethdev_process(res->dev, &config);
673 	if (rc < 0)
674 		printf(MSG_CMD_FAIL, res->cmd);
675 }
676 
677 static void
678 cli_ethdev_help(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl,
679 		__rte_unused void *data)
680 {
681 	size_t len;
682 
683 	len = strlen(conn->msg_out);
684 	conn->msg_out += len;
685 	snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
686 		 "----------------------------- ethdev command help -----------------------------",
687 		 cmd_ethdev_help, cmd_ethdev_ip4_addr_help, cmd_ethdev_ip6_addr_help,
688 		 cmd_ethdev_prom_mode_help, cmd_ethdev_mtu_help, cmd_ethdev_stats_help,
689 		 cmd_ethdev_show_help);
690 
691 	len = strlen(conn->msg_out);
692 	conn->msg_out_len_max -= len;
693 }
694 
695 cmdline_parse_token_string_t ethdev_stats_cmd =
696 	TOKEN_STRING_INITIALIZER(struct ethdev_stats_cmd_tokens, cmd, "ethdev");
697 cmdline_parse_token_string_t ethdev_stats_dev =
698 	TOKEN_STRING_INITIALIZER(struct ethdev_stats_cmd_tokens, dev, NULL);
699 cmdline_parse_token_string_t ethdev_stats_stats =
700 	TOKEN_STRING_INITIALIZER(struct ethdev_stats_cmd_tokens, stats, "stats");
701 
702 cmdline_parse_inst_t ethdev_stats_cmd_ctx = {
703 	.f = cli_ethdev_stats,
704 	.data = NULL,
705 	.help_str = "",
706 	.tokens = {
707 		(void *)&ethdev_stats_cmd,
708 		(void *)&ethdev_stats_dev,
709 		(void *)&ethdev_stats_stats,
710 		NULL,
711 	},
712 };
713 
714 cmdline_parse_token_string_t ethdev_show_cmd =
715 	TOKEN_STRING_INITIALIZER(struct ethdev_show_cmd_tokens, cmd, "ethdev");
716 cmdline_parse_token_string_t ethdev_show_dev =
717 	TOKEN_STRING_INITIALIZER(struct ethdev_show_cmd_tokens, dev, NULL);
718 cmdline_parse_token_string_t ethdev_show_show =
719 	TOKEN_STRING_INITIALIZER(struct ethdev_show_cmd_tokens, show, "show");
720 
721 cmdline_parse_inst_t ethdev_show_cmd_ctx = {
722 	.f = cli_ethdev_show,
723 	.data = NULL,
724 	.help_str = cmd_ethdev_show_help,
725 	.tokens = {
726 		(void *)&ethdev_show_cmd,
727 		(void *)&ethdev_show_dev,
728 		(void *)&ethdev_show_show,
729 		NULL,
730 	},
731 };
732 
733 cmdline_parse_token_string_t ethdev_mtu_cmd =
734 	TOKEN_STRING_INITIALIZER(struct ethdev_mtu_cmd_tokens, cmd, "ethdev");
735 cmdline_parse_token_string_t ethdev_mtu_dev =
736 	TOKEN_STRING_INITIALIZER(struct ethdev_mtu_cmd_tokens, dev, NULL);
737 cmdline_parse_token_string_t ethdev_mtu_mtu =
738 	TOKEN_STRING_INITIALIZER(struct ethdev_mtu_cmd_tokens, mtu, "mtu");
739 cmdline_parse_token_num_t ethdev_mtu_size =
740 	TOKEN_NUM_INITIALIZER(struct ethdev_mtu_cmd_tokens, size, RTE_UINT16);
741 
742 cmdline_parse_inst_t ethdev_mtu_cmd_ctx = {
743 	.f = cli_ethdev_mtu,
744 	.data = NULL,
745 	.help_str = cmd_ethdev_mtu_help,
746 	.tokens = {
747 		(void *)&ethdev_mtu_cmd,
748 		(void *)&ethdev_mtu_dev,
749 		(void *)&ethdev_mtu_mtu,
750 		(void *)&ethdev_mtu_size,
751 		NULL,
752 	},
753 };
754 
755 cmdline_parse_token_string_t ethdev_prom_mode_cmd =
756 	TOKEN_STRING_INITIALIZER(struct ethdev_prom_mode_cmd_tokens, cmd, "ethdev");
757 cmdline_parse_token_string_t ethdev_prom_mode_dev =
758 	TOKEN_STRING_INITIALIZER(struct ethdev_prom_mode_cmd_tokens, dev, NULL);
759 cmdline_parse_token_string_t ethdev_prom_mode_prom =
760 	TOKEN_STRING_INITIALIZER(struct ethdev_prom_mode_cmd_tokens, prom, "promiscuous");
761 cmdline_parse_token_string_t ethdev_prom_mode_enable =
762 	TOKEN_STRING_INITIALIZER(struct ethdev_prom_mode_cmd_tokens, enable, "on#off");
763 
764 cmdline_parse_inst_t ethdev_prom_mode_cmd_ctx = {
765 	.f = cli_ethdev_prom_mode,
766 	.data = NULL,
767 	.help_str = cmd_ethdev_prom_mode_help,
768 	.tokens = {
769 		(void *)&ethdev_prom_mode_cmd,
770 		(void *)&ethdev_prom_mode_dev,
771 		(void *)&ethdev_prom_mode_prom,
772 		(void *)&ethdev_prom_mode_enable,
773 		NULL,
774 	},
775 };
776 
777 cmdline_parse_token_string_t ethdev_ip4_cmd =
778 	TOKEN_STRING_INITIALIZER(struct ethdev_ip4_cmd_tokens, cmd, "ethdev");
779 cmdline_parse_token_string_t ethdev_ip4_dev =
780 	TOKEN_STRING_INITIALIZER(struct ethdev_ip4_cmd_tokens, dev, NULL);
781 cmdline_parse_token_string_t ethdev_ip4_ip4 =
782 	TOKEN_STRING_INITIALIZER(struct ethdev_ip4_cmd_tokens, ip4, "ip4");
783 cmdline_parse_token_string_t ethdev_ip4_addr =
784 	TOKEN_STRING_INITIALIZER(struct ethdev_ip4_cmd_tokens, addr, "addr");
785 cmdline_parse_token_string_t ethdev_ip4_add =
786 	TOKEN_STRING_INITIALIZER(struct ethdev_ip4_cmd_tokens, add, "add");
787 cmdline_parse_token_string_t ethdev_ip4_ip =
788 	TOKEN_STRING_INITIALIZER(struct ethdev_ip4_cmd_tokens, ip, NULL);
789 cmdline_parse_token_string_t ethdev_ip4_netmask =
790 	TOKEN_STRING_INITIALIZER(struct ethdev_ip4_cmd_tokens, netmask, "netmask");
791 cmdline_parse_token_string_t ethdev_ip4_mask =
792 	TOKEN_STRING_INITIALIZER(struct ethdev_ip4_cmd_tokens, mask, NULL);
793 
794 cmdline_parse_inst_t ethdev_ip4_cmd_ctx = {
795 	.f = cli_ip4_addr,
796 	.data = NULL,
797 	.help_str = cmd_ethdev_ip4_addr_help,
798 	.tokens = {
799 		(void *)&ethdev_ip4_cmd,
800 		(void *)&ethdev_ip4_dev,
801 		(void *)&ethdev_ip4_ip4,
802 		(void *)&ethdev_ip4_addr,
803 		(void *)&ethdev_ip4_add,
804 		(void *)&ethdev_ip4_ip,
805 		(void *)&ethdev_ip4_netmask,
806 		(void *)&ethdev_ip4_mask,
807 		NULL,
808 	},
809 };
810 
811 cmdline_parse_token_string_t ethdev_ip6_cmd =
812 	TOKEN_STRING_INITIALIZER(struct ethdev_ip6_cmd_tokens, cmd, "ethdev");
813 cmdline_parse_token_string_t ethdev_ip6_dev =
814 	TOKEN_STRING_INITIALIZER(struct ethdev_ip6_cmd_tokens, dev, NULL);
815 cmdline_parse_token_string_t ethdev_ip6_ip6 =
816 	TOKEN_STRING_INITIALIZER(struct ethdev_ip6_cmd_tokens, ip6, "ip6");
817 cmdline_parse_token_string_t ethdev_ip6_addr =
818 	TOKEN_STRING_INITIALIZER(struct ethdev_ip6_cmd_tokens, addr, "addr");
819 cmdline_parse_token_string_t ethdev_ip6_add =
820 	TOKEN_STRING_INITIALIZER(struct ethdev_ip6_cmd_tokens, add, "add");
821 cmdline_parse_token_string_t ethdev_ip6_ip =
822 	TOKEN_STRING_INITIALIZER(struct ethdev_ip6_cmd_tokens, ip, NULL);
823 cmdline_parse_token_string_t ethdev_ip6_netmask =
824 	TOKEN_STRING_INITIALIZER(struct ethdev_ip6_cmd_tokens, netmask, "netmask");
825 cmdline_parse_token_string_t ethdev_ip6_mask =
826 	TOKEN_STRING_INITIALIZER(struct ethdev_ip6_cmd_tokens, mask, NULL);
827 
828 cmdline_parse_inst_t ethdev_ip6_cmd_ctx = {
829 	.f = cli_ip6_addr,
830 	.data = NULL,
831 	.help_str = cmd_ethdev_ip6_addr_help,
832 	.tokens = {
833 		(void *)&ethdev_ip6_cmd,
834 		(void *)&ethdev_ip6_dev,
835 		(void *)&ethdev_ip6_ip6,
836 		(void *)&ethdev_ip6_addr,
837 		(void *)&ethdev_ip6_add,
838 		(void *)&ethdev_ip6_ip,
839 		(void *)&ethdev_ip6_netmask,
840 		(void *)&ethdev_ip6_mask,
841 		NULL,
842 	},
843 };
844 
845 cmdline_parse_token_string_t ethdev_cmd =
846 	TOKEN_STRING_INITIALIZER(struct ethdev_cmd_tokens, cmd, "ethdev");
847 cmdline_parse_token_string_t ethdev_dev =
848 	TOKEN_STRING_INITIALIZER(struct ethdev_cmd_tokens, dev, NULL);
849 cmdline_parse_token_string_t ethdev_rxq =
850 	TOKEN_STRING_INITIALIZER(struct ethdev_cmd_tokens, rxq, "rxq");
851 cmdline_parse_token_num_t ethdev_nb_rxq =
852 	TOKEN_NUM_INITIALIZER(struct ethdev_cmd_tokens, nb_rxq, RTE_UINT16);
853 cmdline_parse_token_string_t ethdev_txq =
854 	TOKEN_STRING_INITIALIZER(struct ethdev_cmd_tokens, txq, "txq");
855 cmdline_parse_token_num_t ethdev_nb_txq =
856 	TOKEN_NUM_INITIALIZER(struct ethdev_cmd_tokens, nb_txq, RTE_UINT16);
857 cmdline_parse_token_string_t ethdev_mempool =
858 	TOKEN_STRING_INITIALIZER(struct ethdev_cmd_tokens, mempool, NULL);
859 
860 cmdline_parse_inst_t ethdev_cmd_ctx = {
861 	.f = cli_ethdev,
862 	.data = NULL,
863 	.help_str = cmd_ethdev_help,
864 	.tokens = {
865 		(void *)&ethdev_cmd,
866 		(void *)&ethdev_dev,
867 		(void *)&ethdev_rxq,
868 		(void *)&ethdev_nb_rxq,
869 		(void *)&ethdev_txq,
870 		(void *)&ethdev_nb_txq,
871 		(void *)&ethdev_mempool,
872 		NULL,
873 	},
874 };
875 
876 cmdline_parse_token_string_t ethdev_help_cmd =
877 	TOKEN_STRING_INITIALIZER(struct ethdev_help_cmd_tokens, help, "help");
878 cmdline_parse_token_string_t ethdev_help_ethdev =
879 	TOKEN_STRING_INITIALIZER(struct ethdev_help_cmd_tokens, ethdev, "ethdev");
880 
881 cmdline_parse_inst_t ethdev_help_cmd_ctx = {
882 	.f = cli_ethdev_help,
883 	.data = NULL,
884 	.help_str = "",
885 	.tokens = {
886 		(void *)&ethdev_help_cmd,
887 		(void *)&ethdev_help_ethdev,
888 		NULL,
889 	},
890 };
891