From b7b78a089c454d42eb654360eeecb1e2f15e6cd8 Mon Sep 17 00:00:00 2001 From: Ajit Khaparde Date: Fri, 5 Mar 2021 11:42:32 -0800 Subject: [PATCH] app/testpmd: support forced ethernet speed Add support for forced ethernet speed setting. Currently testpmd tries to configure the Ethernet port in autoneg mode. It is not possible to set the Ethernet port to a specific speed while starting testpmd. In some cases capability to configure a forced speed for the Ethernet port during initialization may be necessary. This patch tries to add this support. The patch assumes full duplex setting and does not attempt to change that. So speeds like 10M, 100M are not configurable using this method. The command line to configure a forced speed of 10G: dpdk-testpmd -c 0xff -- -i --eth-link-speed 10000 The command line to configure a forced speed of 50G: dpdk-testpmd -c 0xff -- -i --eth-link-speed 50000 Signed-off-by: Ajit Khaparde Reviewed-by: Ferruh Yigit --- app/test-pmd/parameters.c | 44 ++++++++++++++++++++++++++ app/test-pmd/testpmd.c | 8 +++++ app/test-pmd/testpmd.h | 1 + doc/guides/rel_notes/release_21_05.rst | 2 ++ doc/guides/testpmd_app_ug/run_app.rst | 15 +++++++++ 5 files changed, 70 insertions(+) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index c8acd5d1b7..a326c8ce4f 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -184,6 +184,7 @@ usage(char* progname) printf(" --txpkts=X[,Y]*: set TX segment sizes" " or total packet length.\n"); printf(" --txonly-multi-flow: generate multiple flows in txonly mode\n"); + printf(" --eth-link-speed: force link speed.\n"); printf(" --disable-link-check: disable check on link status when " "starting/stopping ports.\n"); printf(" --disable-device-start: do not automatically start port\n"); @@ -485,6 +486,43 @@ parse_event_printing_config(const char *optarg, int enable) return 0; } +static int +parse_link_speed(int n) +{ + uint32_t speed = ETH_LINK_SPEED_FIXED; + + switch (n) { + case 1000: + speed |= ETH_LINK_SPEED_1G; + break; + case 10000: + speed |= ETH_LINK_SPEED_10G; + break; + case 25000: + speed |= ETH_LINK_SPEED_25G; + break; + case 40000: + speed |= ETH_LINK_SPEED_40G; + break; + case 50000: + speed |= ETH_LINK_SPEED_50G; + break; + case 100000: + speed |= ETH_LINK_SPEED_100G; + break; + case 200000: + speed |= ETH_LINK_SPEED_200G; + break; + case 100: + case 10: + default: + printf("Unsupported fixed speed\n"); + return 0; + } + + return speed; +} + void launch_args_parse(int argc, char** argv) { @@ -579,6 +617,7 @@ launch_args_parse(int argc, char** argv) { "rxpkts", 1, 0, 0 }, { "txpkts", 1, 0, 0 }, { "txonly-multi-flow", 0, 0, 0 }, + { "eth-link-speed", 1, 0, 0 }, { "disable-link-check", 0, 0, 0 }, { "disable-device-start", 0, 0, 0 }, { "no-lsc-interrupt", 0, 0, 0 }, @@ -1232,6 +1271,11 @@ launch_args_parse(int argc, char** argv) txonly_multi_flow = 1; if (!strcmp(lgopts[opt_idx].name, "no-flush-rx")) no_flush_rx = 1; + if (!strcmp(lgopts[opt_idx].name, "eth-link-speed")) { + n = atoi(optarg); + if (n >= 0 && parse_link_speed(n) > 0) + eth_link_speed = parse_link_speed(n); + } if (!strcmp(lgopts[opt_idx].name, "disable-link-check")) no_link_check = 1; if (!strcmp(lgopts[opt_idx].name, "disable-device-start")) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 1a57324b1b..98c3248c01 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -513,6 +513,11 @@ uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES; */ enum rte_eth_rx_mq_mode rx_mq_mode = ETH_MQ_RX_VMDQ_DCB_RSS; +/* + * Used to set forced link speed + */ +uint32_t eth_link_speed; + /* Forward function declarations */ static void setup_attached_port(portid_t pi); static void check_all_ports_link_status(uint32_t port_mask); @@ -1484,6 +1489,9 @@ init_config(void) port->tx_conf[k].offloads = port->dev_conf.txmode.offloads; + if (eth_link_speed) + port->dev_conf.link_speeds = eth_link_speed; + /* set flag to initialize port/queue */ port->need_reconfig = 1; port->need_reconfig_queues = 1; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index ce83f31f0d..af40859170 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -342,6 +342,7 @@ extern uint8_t no_flush_rx; /**