1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2023 Marvell.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmdline_parse.h>
#include <cmdline_parse_num.h>
#include <cmdline_parse_string.h>
#include <cmdline_socket.h>
#include <rte_bitops.h>
#include <rte_ethdev.h>
#include <rte_mempool.h>
#include "ethdev_priv.h"
#include "module_api.h"
static const char
cmd_ethdev_mtu_help[] = "ethdev <ethdev_name> mtu <mtu_sz>";
static const char
cmd_ethdev_prom_mode_help[] = "ethdev <ethdev_name> promiscuous <on/off>";
static const char
cmd_ethdev_help[] = "ethdev <ethdev_name> rxq <n_queues> txq <n_queues> <mempool_name>";
static const char
cmd_ethdev_stats_help[] = "ethdev <ethdev_name> stats";
static const char
cmd_ethdev_show_help[] = "ethdev <ethdev_name> show";
static const char
cmd_ethdev_ip4_addr_help[] = "ethdev <ethdev_name> ip4 addr add <ip> netmask <mask>";
static const char
cmd_ethdev_ip6_addr_help[] = "ethdev <ethdev_name> ip6 addr add <ip> netmask <mask>";
static const char
cmd_ethdev_forward_help[] = "ethdev forward <tx_dev_name> <rx_dev_name>";
static struct rte_eth_conf port_conf_default = {
.link_speeds = 0,
.rxmode = {
.mq_mode = RTE_ETH_MQ_RX_NONE,
.mtu = 9000 - (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN), /* Jumbo frame MTU */
},
.rx_adv_conf = {
.rss_conf = {
.rss_key = NULL,
.rss_key_len = 40,
.rss_hf = 0,
},
},
.txmode = {
.mq_mode = RTE_ETH_MQ_TX_NONE,
},
.lpbk_mode = 0,
};
uint32_t enabled_port_mask;
static struct ethdev_head eth_node = TAILQ_HEAD_INITIALIZER(eth_node);
static struct ethdev*
ethdev_port_by_id(uint16_t port_id)
{
struct ethdev *port;
TAILQ_FOREACH(port, ð_node, next) {
if (port->config.port_id == port_id)
return port;
}
return NULL;
}
int16_t
ethdev_txport_by_rxport_get(uint16_t portid_rx)
{
int portid = -EINVAL;
struct ethdev *port;
port = ethdev_port_by_id(portid_rx);
if (port)
portid = port->tx_port_id;
return portid;
}
void *
ethdev_mempool_list_by_portid(uint16_t portid)
{
struct ethdev *port;
if (portid >= RTE_MAX_ETHPORTS)
return NULL;
port = ethdev_port_by_id(portid);
if (port)
return &(port->config.rx.mp);
else
return NULL;
}
int16_t
ethdev_portid_by_ip4(uint32_t ip, uint32_t mask)
{
int portid = -EINVAL;
struct ethdev *port;
TAILQ_FOREACH(port, ð_node, next) {
if (mask == 0) {
if ((port->ip4_addr.ip & port->ip4_addr.mask) == (ip & port->ip4_addr.mask))
return port->config.port_id;
} else {
if ((port->ip4_addr.ip & port->ip4_addr.mask) == (ip & mask))
return port->config.port_id;
}
}
return portid;
}
int16_t
ethdev_portid_by_ip6(struct rte_ipv6_addr *ip, struct rte_ipv6_addr *mask)
{
struct ethdev *port;
TAILQ_FOREACH(port, ð_node, next) {
uint8_t depth = rte_ipv6_mask_depth(&port->ip6_addr.mask);
if (mask != NULL)
depth = RTE_MAX(depth, rte_ipv6_mask_depth(mask));
if (rte_ipv6_addr_eq_prefix(&port->ip6_addr.ip, ip, depth))
return port->config.port_id;
}
return -EINVAL;
}
void
ethdev_list_clean(void)
{
struct ethdev *port;
while (!TAILQ_EMPTY(ð_node)) {
port = TAILQ_FIRST(ð_node);
TAILQ_REMOVE(ð_node, port, next);
}
}
void
ethdev_stop(void)
{
uint16_t portid;
int rc;
RTE_ETH_FOREACH_DEV(portid) {
if ((enabled_port_mask & (1 << portid)) == 0)
continue;
printf("Closing port %d...", portid);
rc = rte_eth_dev_stop(portid);
if (rc != 0)
printf("Failed to stop port %u: %s\n",
portid, rte_strerror(-rc));
rte_eth_dev_close(portid);
printf(" Done\n");
}
ethdev_list_clean();
route_ip4_list_clean();
route_ip6_list_clean();
neigh4_list_clean();
neigh6_list_clean();
printf("Bye...\n");
}
void
ethdev_start(void)
{
uint16_t portid;
int rc;
RTE_ETH_FOREACH_DEV(portid)
{
if ((enabled_port_mask & (1 << portid)) == 0)
continue;
rc = rte_eth_dev_start(portid);
if (rc < 0)
rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%d\n", rc, portid);
}
}
static int
ethdev_show(const char *name)
{
uint16_t mtu = 0, port_id = 0;
struct rte_eth_dev_info info;
struct rte_eth_stats stats;
struct rte_ether_addr addr;
struct rte_eth_link link;
uint32_t length;
int rc;
rc = rte_eth_dev_get_port_by_name(name, &port_id);
if (rc < 0)
return rc;
rc = rte_eth_dev_info_get(port_id, &info);
if (rc < 0)
return rc;
rc = rte_eth_link_get(port_id, &link);
if (rc < 0)
return rc;
rc = rte_eth_stats_get(port_id, &stats);
if (rc < 0)
return rc;
rc = rte_eth_macaddr_get(port_id, &addr);
if (rc < 0)
return rc;
rte_eth_dev_get_mtu(port_id, &mtu);
length = strlen(conn->msg_out);
conn->msg_out += length;
snprintf(conn->msg_out, conn->msg_out_len_max,
"%s: flags=<%s> mtu %u\n"
"\tether " RTE_ETHER_ADDR_PRT_FMT " rxqueues %u txqueues %u\n"
"\tport# %u speed %s\n"
"\tRX packets %" PRIu64" bytes %" PRIu64"\n"
"\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n"
"\tTX packets %" PRIu64" bytes %" PRIu64"\n"
"\tTX errors %" PRIu64"\n\n",
name,
link.link_status ? "UP" : "DOWN",
mtu,
RTE_ETHER_ADDR_BYTES(&addr),
info.nb_rx_queues,
info.nb_tx_queues,
port_id,
rte_eth_link_speed_to_str(link.link_speed),
stats.ipackets,
stats.ibytes,
stats.ierrors,
stats.imissed,
stats.rx_nombuf,
stats.opackets,
stats.obytes,
stats.oerrors);
length = strlen(conn->msg_out);
conn->msg_out_len_max -= length;
return 0;
}
static int
ethdev_ip4_addr_add(const char *name, struct ipv4_addr_config *config)
{
struct ethdev *eth_hdl;
uint16_t portid = 0;
int rc;
rc = rte_eth_dev_get_port_by_name(name, &portid);
if (rc < 0)
return rc;
eth_hdl = ethdev_port_by_id(portid);
if (eth_hdl) {
eth_hdl->ip4_addr.ip = config->ip;
eth_hdl->ip4_addr.mask = config->mask;
return 0;
}
rc = -EINVAL;
return rc;
}
static int
ethdev_ip6_addr_add(const char *name, struct ipv6_addr_config *config)
{
struct ethdev *eth_hdl;
uint16_t portid = 0;
int rc;
rc = rte_eth_dev_get_port_by_name(name, &portid);
if (rc < 0)
return rc;
eth_hdl = ethdev_port_by_id(portid);
if (eth_hdl) {
eth_hdl->ip6_addr.ip = config->ip;
eth_hdl->ip6_addr.mask = config->mask;
return 0;
}
rc = -EINVAL;
return rc;
}
static int
ethdev_prom_mode_config(const char *name, bool enable)
{
struct ethdev *eth_hdl;
uint16_t portid = 0;
int rc;
rc = rte_eth_dev_get_port_by_name(name, &portid);
if (rc < 0)
return rc;
eth_hdl = ethdev_port_by_id(portid);
if (eth_hdl) {
if (enable)
rc = rte_eth_promiscuous_enable(portid);
else
rc = rte_eth_promiscuous_disable(portid);
if (rc < 0)
return rc;
eth_hdl->config.promiscuous = enable;
return 0;
}
rc = -EINVAL;
return rc;
}
static int
ethdev_mtu_config(const char *name, uint32_t mtu)
{
struct ethdev *eth_hdl;
uint16_t portid = 0;
int rc;
rc = rte_eth_dev_get_port_by_name(name, &portid);
if (rc < 0)
return rc;
eth_hdl = ethdev_port_by_id(portid);
if (eth_hdl) {
rc = rte_eth_dev_set_mtu(portid, mtu);
if (rc < 0)
return rc;
eth_hdl->config.mtu = mtu;
return 0;
}
rc = -EINVAL;
return rc;
}
static int
ethdev_process(const char *name, struct ethdev_config *params)
{
struct rte_eth_dev_info port_info;
struct rte_eth_conf port_conf;
struct ethdev_rss_config *rss;
struct rte_mempool *mempool;
struct ethdev *ethdev_port;
struct rte_ether_addr smac;
uint16_t port_id = 0;
int numa_node, rc;
uint32_t i;
/* Check input params */
if (!name || !name[0] || !params || !params->rx.n_queues || !params->rx.queue_size ||
!params->tx.n_queues || !params->tx.queue_size)
return -EINVAL;
rc = rte_eth_dev_get_port_by_name(name, &port_id);
if (rc)
return -EINVAL;
if (!ethdev_port_by_id(port_id)) {
ethdev_port = malloc(sizeof(struct ethdev));
if (!ethdev_port)
return -EINVAL;
} else {
return 0;
}
rc = rte_eth_dev_info_get(port_id, &port_info);
if (rc) {
rc = -EINVAL;
goto exit;
}
mempool = rte_mempool_lookup(params->rx.mempool_name);
if (!mempool) {
rc = -EINVAL;
goto exit;
}
params->rx.mp = mempool;
rss = params->rx.rss;
if (rss) {
if (!port_info.reta_size || port_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
rc = -EINVAL;
goto exit;
}
if (!rss->n_queues || rss->n_queues >= ETHDEV_RXQ_RSS_MAX) {
rc = -EINVAL;
goto exit;
}
for (i = 0; i < rss->n_queues; i++)
if (rss->queue_id[i] >= port_info.max_rx_queues) {
rc = -EINVAL;
goto exit;
}
}
/* Port */
port_conf = port_conf_default;
if (rss) {
uint64_t rss_hf = RTE_ETH_RSS_IP | RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP;
port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_RSS;
port_conf.rx_adv_conf.rss_conf.rss_hf = rss_hf & port_info.flow_type_rss_offloads;
}
numa_node = rte_eth_dev_socket_id(port_id);
if (numa_node == SOCKET_ID_ANY)
numa_node = 0;
if (params->mtu)
port_conf.rxmode.mtu = params->mtu;
rc = rte_eth_dev_configure(port_id, params->rx.n_queues, params->tx.n_queues,
&port_conf);
if (rc < 0) {
rc = -EINVAL;
goto exit;
}
rc = rte_eth_macaddr_get(port_id, &smac);
if (rc < 0) {
rc = -EINVAL;
goto exit;
}
printf("Port_id = %d srcmac = %x:%x:%x:%x:%x:%x\n", port_id,
smac.addr_bytes[0], smac.addr_bytes[1],
smac.addr_bytes[2], smac.addr_bytes[3],
smac.addr_bytes[4], smac.addr_bytes[5]);
/* Port RX */
for (i = 0; i < params->rx.n_queues; i++) {
rc = rte_eth_rx_queue_setup(port_id, i, params->rx.queue_size, numa_node, NULL,
mempool);
if (rc < 0) {
rc = -EINVAL;
goto exit;
}
}
/* Port TX */
for (i = 0; i < params->tx.n_queues; i++) {
rc = rte_eth_tx_queue_setup(port_id, i, params->tx.queue_size, numa_node, NULL);
if (rc < 0) {
rc = -EINVAL;
goto exit;
}
}
memcpy(ðdev_port->config, params, sizeof(struct ethdev_config));
memcpy(ethdev_port->config.dev_name, name, strlen(name));
ethdev_port->config.port_id = port_id;
enabled_port_mask |= RTE_BIT32(port_id);
TAILQ_INSERT_TAIL(ð_node, ethdev_port, next);
return 0;
exit:
free(ethdev_port);
return rc;
}
static int
ethdev_stats_show(const char *name)
{
uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx;
static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
static uint64_t prev_cycles[RTE_MAX_ETHPORTS];
uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
uint64_t diff_ns, diff_cycles, curr_cycles;
struct rte_eth_stats stats;
static const char *nic_stats_border = "########################";
uint16_t port_id, len;
int rc;
rc = rte_eth_dev_get_port_by_name(name, &port_id);
if (rc < 0)
return rc;
rc = rte_eth_stats_get(port_id, &stats);
if (rc != 0) {
fprintf(stderr,
"%s: Error: failed to get stats (port %u): %d",
__func__, port_id, rc);
return rc;
}
len = strlen(conn->msg_out);
conn->msg_out += len;
snprintf(conn->msg_out, conn->msg_out_len_max,
"\n %s NIC statistics for port %-2d %s\n"
" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: ""%-"PRIu64"\n"
" RX-errors: %-"PRIu64"\n"
" RX-nombuf: %-10"PRIu64"\n"
" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: ""%-"PRIu64"\n",
nic_stats_border, port_id, nic_stats_border, stats.ipackets, stats.imissed,
stats.ibytes, stats.ierrors, stats.rx_nombuf, stats.opackets, stats.oerrors,
stats.obytes);
len = strlen(conn->msg_out) - len;
conn->msg_out_len_max -= len;
diff_ns = 0;
diff_cycles = 0;
curr_cycles = rte_rdtsc();
if (prev_cycles[port_id] != 0)
diff_cycles = curr_cycles - prev_cycles[port_id];
prev_cycles[port_id] = curr_cycles;
diff_ns = diff_cycles > 0 ?
diff_cycles * (1 / (double)rte_get_tsc_hz()) * NS_PER_SEC : 0;
diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
(stats.ipackets - prev_pkts_rx[port_id]) : 0;
diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
(stats.opackets - prev_pkts_tx[port_id]) : 0;
prev_pkts_rx[port_id] = stats.ipackets;
prev_pkts_tx[port_id] = stats.opackets;
mpps_rx = diff_ns > 0 ?
(double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
mpps_tx = diff_ns > 0 ?
(double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
(stats.ibytes - prev_bytes_rx[port_id]) : 0;
diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
(stats.obytes - prev_bytes_tx[port_id]) : 0;
prev_bytes_rx[port_id] = stats.ibytes;
prev_bytes_tx[port_id] = stats.obytes;
mbps_rx = diff_ns > 0 ?
(double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
mbps_tx = diff_ns > 0 ?
(double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
len = strlen(conn->msg_out);
snprintf(conn->msg_out + len, conn->msg_out_len_max,
"\n Throughput (since last show)\n"
" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
PRIu64" Tx-bps: %12"PRIu64"\n"
" %s############################%s\n",
mpps_rx, mbps_rx * 8, mpps_tx, mbps_tx * 8, nic_stats_border, nic_stats_border);
return 0;
}
void
cmd_ethdev_dev_mtu_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
void *data __rte_unused)
{
struct cmd_ethdev_dev_mtu_result *res = parsed_result;
int rc = -EINVAL;
rc = ethdev_mtu_config(res->dev, res->size);
if (rc < 0)
printf(MSG_CMD_FAIL, res->ethdev);
}
void
cmd_ethdev_dev_promiscuous_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
void *data __rte_unused)
{
struct cmd_ethdev_dev_promiscuous_result *res = parsed_result;
bool enable = false;
int rc = -EINVAL;
if (!strcmp(res->enable, "on"))
enable = true;
rc = ethdev_prom_mode_config(res->dev, enable);
if (rc < 0)
printf(MSG_CMD_FAIL, res->ethdev);
}
void
cmd_ethdev_dev_ip4_addr_add_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
void *data __rte_unused)
{
struct cmd_ethdev_dev_ip4_addr_add_result *res = parsed_result;
struct ipv4_addr_config config;
int rc = -EINVAL;
config.ip = rte_be_to_cpu_32(res->ip.addr.ipv4.s_addr);
config.mask = rte_be_to_cpu_32(res->mask.addr.ipv4.s_addr);
rc = ethdev_ip4_addr_add(res->dev, &config);
if (rc < 0)
printf(MSG_CMD_FAIL, res->ethdev);
}
void
cmd_ethdev_dev_ip6_addr_add_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
void *data __rte_unused)
{
struct cmd_ethdev_dev_ip6_addr_add_result *res = parsed_result;
struct ipv6_addr_config config = {
.ip = res->ip.addr.ipv6,
.mask = res->mask.addr.ipv6,
};
int rc;
rc = ethdev_ip6_addr_add(res->dev, &config);
if (rc < 0)
printf(MSG_CMD_FAIL, res->ethdev);
}
void
cmd_ethdev_dev_show_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
void *data __rte_unused)
{
struct cmd_ethdev_dev_show_result *res = parsed_result;
int rc = -EINVAL;
rc = ethdev_show(res->dev);
if (rc < 0)
printf(MSG_ARG_INVALID, res->dev);
}
void
cmd_ethdev_dev_stats_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
void *data __rte_unused)
{
struct cmd_ethdev_dev_stats_result *res = parsed_result;
int rc = -EINVAL;
rc = ethdev_stats_show(res->dev);
if (rc < 0)
printf(MSG_ARG_INVALID, res->dev);
}
void
cmd_ethdev_parsed(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused)
{
struct cmd_ethdev_result *res = parsed_result;
struct ethdev_config config;
int rc;
memset(&config, 0, sizeof(struct ethdev_config));
config.rx.n_queues = res->nb_rxq;
config.rx.queue_size = ETHDEV_RX_DESC_DEFAULT;
memcpy(config.rx.mempool_name, res->mempool, strlen(res->mempool));
config.tx.n_queues = res->nb_txq;
config.tx.queue_size = ETHDEV_TX_DESC_DEFAULT;
config.mtu = port_conf_default.rxmode.mtu;
rc = ethdev_process(res->dev, &config);
if (rc < 0)
printf(MSG_CMD_FAIL, res->ethdev);
}
void
cmd_help_ethdev_parsed(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl,
__rte_unused void *data)
{
size_t len;
len = strlen(conn->msg_out);
conn->msg_out += len;
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%s\n",
"----------------------------- ethdev command help -----------------------------",
cmd_ethdev_help, cmd_ethdev_ip4_addr_help, cmd_ethdev_ip6_addr_help,
cmd_ethdev_forward_help, cmd_ethdev_prom_mode_help, cmd_ethdev_mtu_help,
cmd_ethdev_stats_help, cmd_ethdev_show_help);
len = strlen(conn->msg_out);
conn->msg_out_len_max -= len;
}
static int
ethdev_forward_config(char *tx_dev, char *rx_dev)
{
uint16_t portid_rx = 0;
uint16_t portid_tx = 0;
struct ethdev *port;
int rc = -EINVAL;
rc = rte_eth_dev_get_port_by_name(tx_dev, &portid_tx);
if (rc < 0)
return rc;
rc = rte_eth_dev_get_port_by_name(rx_dev, &portid_rx);
if (rc < 0)
return rc;
port = ethdev_port_by_id(portid_rx);
if (port) {
port->tx_port_id = portid_tx;
rc = 0;
} else {
rc = -EINVAL;
}
return rc;
}
void
cmd_ethdev_forward_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
void *data __rte_unused)
{
struct cmd_ethdev_forward_result *res = parsed_result;
int rc = -EINVAL;
rc = ethdev_forward_config(res->tx_dev, res->rx_dev);
if (rc < 0)
printf(MSG_CMD_FAIL, res->ethdev);
}
|