[v8,08/10] ethdev: add API to get RSS algorithm names

Message ID 20231101074039.3088716-9-haijie1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series support setting and querying RSS algorithms |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai Nov. 1, 2023, 7:40 a.m. UTC
  This patch adds new API rte_eth_dev_rss_algo_name() to get
name of a RSS algorithm and document it.

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
---
 doc/guides/rel_notes/release_23_11.rst |  4 ++++
 lib/ethdev/rte_ethdev.c                | 25 +++++++++++++++++++++++++
 lib/ethdev/rte_ethdev.h                | 16 ++++++++++++++++
 lib/ethdev/version.map                 |  1 +
 4 files changed, 46 insertions(+)
  

Patch

diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst
index e207786044f9..5276d302c40b 100644
--- a/doc/guides/rel_notes/release_23_11.rst
+++ b/doc/guides/rel_notes/release_23_11.rst
@@ -122,6 +122,10 @@  New Features
   a group's miss actions, which are the actions to be performed on packets
   that didn't match any of the flow rules in the group.
 
+* **Added new API for RSS hash algorithm**
+  Added new function ``rte_eth_dev_rss_algo_name`` to get name of RSS hash
+  algorithm.
+
 * **Updated Amazon ena (Elastic Network Adapter) net driver.**
 
   * Upgraded ENA HAL to latest version.
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index f9bd99d07eb1..cd19ea89e1f9 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -160,6 +160,17 @@  enum {
 	STAT_QMAP_RX
 };
 
+static const struct {
+	enum rte_eth_hash_function algo;
+	const char *name;
+} rte_eth_dev_rss_algo_names[] = {
+	{RTE_ETH_HASH_FUNCTION_DEFAULT, "default"},
+	{RTE_ETH_HASH_FUNCTION_SIMPLE_XOR, "simple_xor"},
+	{RTE_ETH_HASH_FUNCTION_TOEPLITZ, "toeplitz"},
+	{RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ, "symmetric_toeplitz"},
+	{RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ_SORT, "symmetric_toeplitz_sort"},
+};
+
 int
 rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
 {
@@ -4792,6 +4803,20 @@  rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
 	return ret;
 }
 
+const char *
+rte_eth_dev_rss_algo_name(enum rte_eth_hash_function rss_algo)
+{
+	const char *name = "Unknown function";
+	unsigned int i;
+
+	for (i = 0; i < RTE_DIM(rte_eth_dev_rss_algo_names); i++) {
+		if (rss_algo == rte_eth_dev_rss_algo_names[i].algo)
+			return rte_eth_dev_rss_algo_names[i].name;
+	}
+
+	return name;
+}
+
 int
 rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
 				struct rte_eth_udp_tunnel *udp_tunnel)
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index 76c45bd759e4..f7339fd5adce 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -4644,6 +4644,22 @@  int
 rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
 			      struct rte_eth_rss_conf *rss_conf);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ *  Get the name of RSS hash algorithm.
+ *
+ * @param rss_algo
+ *   Hash algorithm.
+ *
+ * @return
+ *   Hash algorithm name or 'UNKNOWN' if the rss_algo cannot be recognized.
+ */
+__rte_experimental
+const char *
+rte_eth_dev_rss_algo_name(enum rte_eth_hash_function rss_algo);
+
 /**
  * Add UDP tunneling port for a type of tunnel.
  *
diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map
index 919ba5b8e65b..9336522b713c 100644
--- a/lib/ethdev/version.map
+++ b/lib/ethdev/version.map
@@ -314,6 +314,7 @@  EXPERIMENTAL {
 	rte_flow_restore_info_dynflag;
 
 	# added in 23.11
+	rte_eth_dev_rss_algo_name;
 	rte_eth_recycle_rx_queue_info_get;
 	rte_flow_group_set_miss_actions;
 	rte_flow_calc_table_hash;