app/testpmd: support forced ethernet speed
authorAjit Khaparde <ajit.khaparde@broadcom.com>
Fri, 5 Mar 2021 19:42:32 +0000 (11:42 -0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 8 Mar 2021 11:44:01 +0000 (12:44 +0100)
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 <ajit.khaparde@broadcom.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
app/test-pmd/parameters.c
app/test-pmd/testpmd.c
app/test-pmd/testpmd.h
doc/guides/rel_notes/release_21_05.rst
doc/guides/testpmd_app_ug/run_app.rst

index c8acd5d..a326c8c 100644 (file)
@@ -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"))
index 1a57324..98c3248 100644 (file)
@@ -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;
index ce83f31..af40859 100644 (file)
@@ -342,6 +342,7 @@ extern uint8_t no_flush_rx; /**<set by "--no-flush-rx" parameter */
 extern uint8_t flow_isolate_all; /**< set by "--flow-isolate-all */
 extern uint8_t  mp_alloc_type;
 /**< set by "--mp-anon" or "--mp-alloc" parameter */
+extern uint32_t eth_link_speed;
 extern uint8_t no_link_check; /**<set by "--disable-link-check" parameter */
 extern uint8_t no_device_start; /**<set by "--disable-device-start" parameter */
 extern volatile int test_done; /* stop packet forwarding when set to 1. */
index eda9db4..21dc6d2 100644 (file)
@@ -78,6 +78,8 @@ New Features
 
 * **Updated testpmd.**
 
+  * Added a command line option to configure forced speed for Ethernet port.
+    ``dpdk-testpmd -- --eth-link-speed N``
   * Added command to display Rx queue used descriptor count.
     ``show port (port_id) rxq (queue_id) desc used count``
 
index 6745072..ec1dc7d 100644 (file)
@@ -392,6 +392,21 @@ The command line options are:
 
     Generate multiple flows in txonly mode.
 
+*   ``--eth-link-speed``
+
+    Set a forced link speed to the ethernet port::
+
+       10 - 10Mbps (not supported)
+       100 - 100Mbps (not supported)
+       1000 - 1Gbps
+       10000 - 10Gbps
+       25000 - 25Gbps
+       40000 - 40Gbps
+       50000 - 50Gbps
+       100000 - 100Gbps
+       200000 - 200Gbps
+       ...
+
 *   ``--disable-link-check``
 
     Disable check on link status when starting/stopping ports.