[2/3] app/testpmd: support RSS hash level setting
diff mbox series

Message ID 20191207005919.10962-3-ajit.khaparde@broadcom.com
State New
Delegated to: Ferruh Yigit
Headers show
Series
  • add support for RSS level
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Ajit Khaparde Dec. 7, 2019, 12:59 a.m. UTC
This patch adds support to configure RSS hash level for the device.

Example testpmd commands to set the RSS hash level using testpmd cli:

port config <port id> rss_level <value>
port config all rss_level <value>

Example command to set the RSS hash level using an argument to testpmd:

./build/app/testpmd -l1-4 -n2 -- -i --rxq=<N> --txq=<N> --rss-level=<N>

Example testpmd commands to get the RSS hash level:

show port <port id> rss-hash

Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 app/test-pmd/cmdline.c    | 187 ++++++++++++++++++++++++++++++++++++++
 app/test-pmd/config.c     |   7 ++
 app/test-pmd/parameters.c |   6 +-
 app/test-pmd/testpmd.c    |   8 ++
 app/test-pmd/testpmd.h    |   1 +
 5 files changed, 208 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 2d74df896..225ec3034 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -795,6 +795,9 @@  static void cmd_help_long_parsed(void *parsed_result,
 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
 			"    Set the RSS redirection table.\n\n"
 
+			"port config (port_id|all) rss_level (value)\n"
+			"    Set the RSS hash level for the port.\n\n"
+
 			"port config (port_id) dcb vt (on|off) (traffic_class)"
 			" pfc (on|off)\n"
 			"    Set the DCB mode.\n\n"
@@ -2303,6 +2306,7 @@  cmd_config_rss_parsed(void *parsed_result,
 		return;
 	}
 	rss_conf.rss_key = NULL;
+	rss_conf.rss_level = rss_level;
 	/* Update global configuration for RSS types. */
 	RTE_ETH_FOREACH_DEV(i) {
 		struct rte_eth_rss_conf local_rss_conf;
@@ -2360,6 +2364,187 @@  cmdline_parse_inst_t cmd_config_rss = {
 	},
 };
 
+/* *** configure rss level all ports *** */
+struct cmd_config_rss_level {
+	cmdline_fixed_string_t port;
+	cmdline_fixed_string_t keyword;
+	cmdline_fixed_string_t all;
+	cmdline_fixed_string_t name;
+	uint32_t value;
+};
+
+static void
+cmd_config_rss_level_parsed(void *parsed_result,
+			__attribute__((unused)) struct cmdline *cl,
+			__attribute__((unused)) void *data)
+{
+	struct cmd_config_rss_level *res = parsed_result;
+	int all_updated = 1;
+	int diag;
+	uint16_t i;
+
+	/* Update global configuration for RSS hash level. */
+	RTE_ETH_FOREACH_DEV(i) {
+		struct rte_eth_rss_conf rss_conf;
+		struct rte_eth_dev_info dev_info;
+
+		diag = eth_dev_info_get_print_err(i, &dev_info);
+		if (diag != 0)
+			return;
+
+		if (!(dev_info.rx_offload_capa & DEV_RX_OFFLOAD_RSS_LEVEL)) {
+			printf("Port %d does not support RSS hash level "
+			       "selection\n", i);
+			return;
+		}
+
+		rss_conf.rss_key = NULL;
+		diag = rte_eth_dev_rss_hash_conf_get(i, &rss_conf);
+		if (diag) {
+			printf("Port %d failed to get RSS hash config with "
+			       "error (%d): %s.\n",
+			       i, -diag, strerror(-diag));
+			return;
+		}
+
+		if (rss_conf.rss_level == res->value)
+			return;
+
+		printf("Port %d modifying RSS hash level based on "
+		       "hardware support. Requested:%d Current:%d\n",
+			i, res->value, rss_conf.rss_level);
+
+		rss_conf.rss_level = res->value;
+		diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
+		if (diag < 0) {
+			all_updated = 0;
+			printf("Configuration of RSS hash at ethernet port %d "
+				"failed with error (%d): %s.\n",
+				i, -diag, strerror(-diag));
+		}
+	}
+	if (all_updated)
+		rss_level = res->value;
+}
+
+cmdline_parse_token_string_t cmd_config_rss_level_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_level, port, "port");
+cmdline_parse_token_string_t cmd_config_rss_level_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_level, keyword,
+				 "config");
+cmdline_parse_token_string_t cmd_config_rss_level_all =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_level, all, "all");
+cmdline_parse_token_string_t cmd_config_rss_level_item =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_level, name,
+				 "rss_level");
+cmdline_parse_token_num_t cmd_config_rss_level_value =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_level, value, UINT16);
+
+cmdline_parse_inst_t cmd_config_rss_level = {
+	.f = cmd_config_rss_level_parsed,
+	.data = NULL,
+	.help_str = "port config all rss_level "
+		"<level>",
+	.tokens = {
+		(void *)&cmd_config_rss_level_port,
+		(void *)&cmd_config_rss_level_keyword,
+		(void *)&cmd_config_rss_level_all,
+		(void *)&cmd_config_rss_level_item,
+		(void *)&cmd_config_rss_level_value,
+		NULL,
+	},
+};
+
+/* *** configure rss_level for specific port *** */
+struct cmd_config_rss_level_specific_port {
+	cmdline_fixed_string_t port;
+	cmdline_fixed_string_t keyword;
+	portid_t id;
+	cmdline_fixed_string_t item;
+	uint32_t value;
+};
+
+static void
+cmd_config_rss_level_specific_port_parsed(void *parsed_result,
+				__attribute__((unused)) struct cmdline *cl,
+				__attribute__((unused)) void *data)
+{
+	struct cmd_config_rss_level_specific_port *res = parsed_result;
+	struct rte_eth_dev_info dev_info;
+	struct rte_eth_rss_conf rss_conf;
+	int diag;
+
+	if (port_id_is_invalid(res->id, ENABLED_WARN))
+		return;
+
+	diag = eth_dev_info_get_print_err(res->id, &dev_info);
+	if (diag != 0)
+		return;
+
+	if (!(dev_info.rx_offload_capa & DEV_RX_OFFLOAD_RSS_LEVEL)) {
+		printf("Port %d does not support RSS hash level "
+		       "selection\n", res->id);
+		return;
+	}
+
+	rss_conf.rss_key = NULL;
+	diag = rte_eth_dev_rss_hash_conf_get(res->id, &rss_conf);
+
+	if (rss_conf.rss_level == res->value)
+		return;
+
+	if (diag == 0) {
+		printf("Current RSS hash level %d is being updated to %d\n",
+		       rss_conf.rss_level, res->value);
+		rss_conf.rss_level = res->value;
+		diag = rte_eth_dev_rss_hash_update(res->id, &rss_conf);
+	}
+	if (diag == 0) {
+		rss_level = res->value;
+		return;
+	}
+
+	switch (diag) {
+	case -ENOTSUP:
+		printf("operation not supported by device\n");
+		break;
+	default:
+		printf("operation failed - diag=%d\n", diag);
+		break;
+	}
+}
+
+cmdline_parse_token_string_t cmd_config_rss_level_specific_port_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_level_specific_port,
+				 port, "port");
+cmdline_parse_token_string_t cmd_config_rss_level_specific_port_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_level_specific_port,
+				 keyword, "config");
+cmdline_parse_token_num_t cmd_config_rss_level_specific_port_id =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_level_specific_port, id,
+			      UINT16);
+cmdline_parse_token_string_t cmd_config_rss_level_specific_port_item =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_level_specific_port,
+				 item, "rss_level");
+cmdline_parse_token_num_t cmd_config_rss_level_specific_port_value =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_level_specific_port, value,
+			      UINT16);
+
+cmdline_parse_inst_t cmd_config_rss_level_specific_port = {
+	.f = cmd_config_rss_level_specific_port_parsed,
+	.data = NULL,
+	.help_str = "port config port_id rss_level "
+		"<level>",
+	.tokens = {
+		(void *)&cmd_config_rss_level_specific_port_port,
+		(void *)&cmd_config_rss_level_specific_port_keyword,
+		(void *)&cmd_config_rss_level_specific_port_id,
+		(void *)&cmd_config_rss_level_specific_port_item,
+		(void *)&cmd_config_rss_level_specific_port_value,
+		NULL,
+	},
+};
+
 /* *** configure rss hash key *** */
 struct cmd_config_rss_hash_key {
 	cmdline_fixed_string_t port;
@@ -19336,6 +19521,8 @@  cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
 	(cmdline_parse_inst_t *)&cmd_config_rss,
+	(cmdline_parse_inst_t *)&cmd_config_rss_level,
+	(cmdline_parse_inst_t *)&cmd_config_rss_level_specific_port,
 	(cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
 	(cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 4e1c3cab5..87335d7a5 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1965,6 +1965,13 @@  port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
 			printf("%s ", rss_type_table[i].str);
 	}
 	printf("\n");
+	if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_RSS_LEVEL) {
+		printf("RSS hash level:\n ");
+		if (rss_conf.rss_level == ETH_RSS_LEVEL_DEFAULT)
+			printf("%s ", "Default");
+		printf("%d", rss_conf.rss_level);
+		printf("\n");
+	}
 	if (!show_rss_key)
 		return;
 	printf("RSS key:\n");
diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 2e7a50441..bac3b5a55 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -65,7 +65,7 @@  usage(char* progname)
 	       "--tx-ip=SRC,DST | --tx-udp=PORT | "
 #endif
 	       "--pkt-filter-mode= |"
-	       "--rss-ip | --rss-udp | "
+	       "--rss-ip | --rss-udp | --rss-level= | "
 	       "--rxpt= | --rxht= | --rxwt= | --rxfreet= | "
 	       "--txpt= | --txht= | --txwt= | --txfreet= | "
 	       "--txrst= | --tx-offloads= | | --rx-offloads= | "
@@ -147,6 +147,7 @@  usage(char* progname)
 	       list_pkt_forwarding_modes());
 	printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
 	printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
+	printf("  --rss-level=N: set RSS hash level.\n");
 	printf("  --rxq=N: set the number of RX queues per port to N.\n");
 	printf("  --rxd=N: set the number of descriptors in RX rings to N.\n");
 	printf("  --txq=N: set the number of TX queues per port to N.\n");
@@ -623,6 +624,7 @@  launch_args_parse(int argc, char** argv)
 		{ "forward-mode",               1, 0, 0 },
 		{ "rss-ip",			0, 0, 0 },
 		{ "rss-udp",			0, 0, 0 },
+		{ "rss-level",			1, 0, 0 },
 		{ "rxq",			1, 0, 0 },
 		{ "txq",			1, 0, 0 },
 		{ "rxd",			1, 0, 0 },
@@ -1037,6 +1039,8 @@  launch_args_parse(int argc, char** argv)
 				rss_hf = ETH_RSS_IP;
 			if (!strcmp(lgopts[opt_idx].name, "rss-udp"))
 				rss_hf = ETH_RSS_UDP;
+			if (!strcmp(lgopts[opt_idx].name, "rss-level"))
+				rss_level = atoi(optarg);
 			if (!strcmp(lgopts[opt_idx].name, "rxq")) {
 				n = atoi(optarg);
 				if (n >= 0 && check_nb_rxq((queueid_t)n) == 0)
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index b37468223..37d6472c7 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -319,6 +319,11 @@  uint64_t noisy_lkup_num_reads_writes;
  */
 uint64_t rss_hf = ETH_RSS_IP; /* RSS IP by default. */
 
+/*
+ * Receive Side Scaling (RSS) configuration.
+ */
+uint32_t rss_level = ETH_RSS_LEVEL_DEFAULT;/* Use default hardware RSS level. */
+
 /*
  * Port topology configuration
  */
@@ -3068,9 +3073,12 @@  init_port_config(void)
 			port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
 			port->dev_conf.rx_adv_conf.rss_conf.rss_hf =
 				rss_hf & port->dev_info.flow_type_rss_offloads;
+			port->dev_conf.rx_adv_conf.rss_conf.rss_level =
+				rss_level;
 		} else {
 			port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
 			port->dev_conf.rx_adv_conf.rss_conf.rss_hf = 0;
+			port->dev_conf.rx_adv_conf.rss_conf.rss_level = 0;
 		}
 
 		if (port->dcb_flag == 0) {
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 857a11f8d..2578f6c1c 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -383,6 +383,7 @@  extern struct rte_eth_rxmode rx_mode;
 extern struct rte_eth_txmode tx_mode;
 
 extern uint64_t rss_hf;
+extern uint32_t rss_level;
 
 extern queueid_t nb_hairpinq;
 extern queueid_t nb_rxq;