patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Huisong Li <lihuisong@huawei.com>
To: <stable@dpdk.org>, <ktraynor@redhat.com>
Cc: <liudongdong3@huawei.com>, <huangdaode@huawei.com>,
	<liuyonglong@huawei.com>, <lihuisong@huawei.com>
Subject: [PATCH 21.11 03/17] net/hns3: fix RSS key size compatibility
Date: Tue, 21 Mar 2023 17:22:52 +0800	[thread overview]
Message-ID: <20230321092306.16918-4-lihuisong@huawei.com> (raw)
In-Reply-To: <20230321092306.16918-1-lihuisong@huawei.com>

[ upstream commit 5172f9c464aa315a9d45b9177af71b4f99d55cdb ]

For better compatibility, the RSS key size of PF and VF are obtained
from firmware. However, the outdated HNS3_RSS_KEY_SIZE macro is still
utilized in many locations as the key size.

Fixes: 9c740336f024 ("net/hns3: get device specifications from firmware")

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_common.c | 12 +++++++++++-
 drivers/net/hns3/hns3_flow.c   | 26 ++++++++++++--------------
 drivers/net/hns3/hns3_rss.c    | 25 ++++++++++++-------------
 drivers/net/hns3/hns3_rss.h    |  5 +++--
 4 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
index 2532c3b770..07e9b3f979 100644
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -130,7 +130,7 @@ hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
 	};
 
 	info->reta_size = hw->rss_ind_tbl_size;
-	info->hash_key_size = HNS3_RSS_KEY_SIZE;
+	info->hash_key_size = hw->rss_key_size;
 	info->flow_type_rss_offloads = HNS3_ETH_RSS_SUPPORT;
 
 	info->default_rxportconf.burst_size = HNS3_DEFAULT_PORT_CONF_BURST_SIZE;
@@ -827,6 +827,16 @@ hns3_check_dev_specifications(struct hns3_hw *hw)
 		return -EINVAL;
 	}
 
+	if (hw->rss_key_size == 0 || hw->rss_key_size > HNS3_RSS_KEY_SIZE_MAX) {
+		hns3_err(hw, "the RSS key size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
+			 hw->rss_key_size, HNS3_RSS_KEY_SIZE_MAX);
+		return -EINVAL;
+	}
+
+	if (hw->rss_key_size > HNS3_RSS_KEY_SIZE)
+		hns3_warn(hw, "the RSS key size obtained (%u) is greater than the default key size (%u)",
+			  hw->rss_key_size, HNS3_RSS_KEY_SIZE);
+
 	return 0;
 }
 
diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 617a6e5a71..97ea4e4de7 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1355,10 +1355,10 @@ hns3_parse_rss_filter(struct rte_eth_dev *dev,
 		return rte_flow_error_set(error, ENOTSUP,
 					  RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
 					  "a nonzero RSS encapsulation level is not supported");
-	if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
+	if (rss->key_len && rss->key_len != hw->rss_key_size)
 		return rte_flow_error_set(error, ENOTSUP,
 					  RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
-					  "RSS hash key must be exactly 40 bytes");
+					  "invalid RSS key length");
 
 	if (!hns3_rss_input_tuple_supported(hw, rss))
 		return rte_flow_error_set(error, EINVAL,
@@ -1390,16 +1390,6 @@ hns3_disable_rss(struct hns3_hw *hw)
 	return 0;
 }
 
-static void
-hns3_parse_rss_key(struct hns3_hw *hw, struct rte_flow_action_rss *rss_conf)
-{
-	if (rss_conf->key == NULL || rss_conf->key_len < HNS3_RSS_KEY_SIZE) {
-		hns3_warn(hw, "Default RSS hash key to be set");
-		rss_conf->key = hns3_hash_key;
-		rss_conf->key_len = HNS3_RSS_KEY_SIZE;
-	}
-}
-
 static int
 hns3_parse_rss_algorithm(struct hns3_hw *hw, enum rte_eth_hash_function *func,
 			 uint8_t *hash_algo)
@@ -1432,9 +1422,16 @@ hns3_parse_rss_algorithm(struct hns3_hw *hw, enum rte_eth_hash_function *func,
 static int
 hns3_hw_rss_hash_set(struct hns3_hw *hw, struct rte_flow_action_rss *rss_config)
 {
+	uint8_t rss_key[HNS3_RSS_KEY_SIZE_MAX] = {0};
+	bool use_default_key = false;
 	int ret;
 
-	hns3_parse_rss_key(hw, rss_config);
+	if (rss_config->key == NULL || rss_config->key_len != hw->rss_key_size) {
+		hns3_warn(hw, "Default RSS hash key to be set");
+		memcpy(rss_key, hns3_hash_key,
+			RTE_MIN(sizeof(hns3_hash_key), hw->rss_key_size));
+		use_default_key = true;
+	}
 
 	ret = hns3_parse_rss_algorithm(hw, &rss_config->func,
 				       &hw->rss_info.hash_algo);
@@ -1442,7 +1439,8 @@ hns3_hw_rss_hash_set(struct hns3_hw *hw, struct rte_flow_action_rss *rss_config)
 		return ret;
 
 	ret = hns3_rss_set_algo_key(hw, hw->rss_info.hash_algo,
-				    rss_config->key, HNS3_RSS_KEY_SIZE);
+				    use_default_key ? rss_key : rss_config->key,
+				    hw->rss_key_size);
 	if (ret)
 		return ret;
 
diff --git a/drivers/net/hns3/hns3_rss.c b/drivers/net/hns3/hns3_rss.c
index 67e33a2765..bf031e6ad7 100644
--- a/drivers/net/hns3/hns3_rss.c
+++ b/drivers/net/hns3/hns3_rss.c
@@ -10,7 +10,7 @@
 #include "hns3_logs.h"
 
 /* Default hash keys */
-const uint8_t hns3_hash_key[] = {
+const uint8_t hns3_hash_key[HNS3_RSS_KEY_SIZE] = {
 	0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
 	0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
 	0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
@@ -317,7 +317,7 @@ hns3_rss_set_algo_key(struct hns3_hw *hw, uint8_t hash_algo,
 		}
 	}
 	/* Update the shadow RSS key with user specified */
-	memcpy(hw->rss_info.key, key, HNS3_RSS_KEY_SIZE);
+	memcpy(hw->rss_info.key, key, hw->rss_key_size);
 	return 0;
 }
 
@@ -553,9 +553,9 @@ hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
 	uint8_t *key = rss_conf->rss_key;
 	int ret;
 
-	if (key && key_len != HNS3_RSS_KEY_SIZE) {
+	if (key && key_len != hw->rss_key_size) {
 		hns3_err(hw, "the hash key len(%u) is invalid, must be %u",
-			 key_len, HNS3_RSS_KEY_SIZE);
+			 key_len, hw->rss_key_size);
 		return -EINVAL;
 	}
 
@@ -566,7 +566,7 @@ hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
 
 	if (key) {
 		ret = hns3_rss_set_algo_key(hw, hw->rss_info.hash_algo,
-					    key, HNS3_RSS_KEY_SIZE);
+					    key, hw->rss_key_size);
 		if (ret)
 			goto set_algo_key_fail;
 	}
@@ -602,9 +602,9 @@ hns3_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
 	rss_conf->rss_hf = rss_cfg->conf.types;
 
 	/* Get the RSS Key required by the user */
-	if (rss_conf->rss_key && rss_conf->rss_key_len >= HNS3_RSS_KEY_SIZE) {
-		memcpy(rss_conf->rss_key, rss_cfg->key, HNS3_RSS_KEY_SIZE);
-		rss_conf->rss_key_len = HNS3_RSS_KEY_SIZE;
+	if (rss_conf->rss_key && rss_conf->rss_key_len >= hw->rss_key_size) {
+		memcpy(rss_conf->rss_key, rss_cfg->key, hw->rss_key_size);
+		rss_conf->rss_key_len = hw->rss_key_size;
 	}
 	rte_spinlock_unlock(&hw->lock);
 
@@ -824,8 +824,8 @@ hns3_rss_set_default_args(struct hns3_hw *hw)
 	/* Default hash algorithm */
 	rss_cfg->conf.func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
 
-	/* Default RSS key */
-	memcpy(rss_cfg->key, hns3_hash_key, HNS3_RSS_KEY_SIZE);
+	memcpy(rss_cfg->key, hns3_hash_key,
+		RTE_MIN(sizeof(hns3_hash_key), hw->rss_key_size));
 
 	/* Initialize RSS indirection table */
 	for (i = 0; i < hw->rss_ind_tbl_size; i++)
@@ -858,9 +858,8 @@ hns3_config_rss(struct hns3_adapter *hns)
 		break;
 	}
 
-	/* Configure RSS hash algorithm and hash key */
-	ret = hns3_rss_set_algo_key(hw, hw->rss_info.hash_algo, hash_key,
-				    HNS3_RSS_KEY_SIZE);
+	ret = hns3_rss_set_algo_key(hw, rss_cfg->hash_algo,
+				    hash_key, hw->rss_key_size);
 	if (ret)
 		return ret;
 
diff --git a/drivers/net/hns3/hns3_rss.h b/drivers/net/hns3/hns3_rss.h
index bc5b14e17b..68069d6120 100644
--- a/drivers/net/hns3/hns3_rss.h
+++ b/drivers/net/hns3/hns3_rss.h
@@ -28,6 +28,7 @@
 #define HNS3_RSS_IND_TBL_SIZE	512 /* The size of hash lookup table */
 #define HNS3_RSS_IND_TBL_SIZE_MAX 2048
 #define HNS3_RSS_KEY_SIZE	40
+#define HNS3_RSS_KEY_SIZE_MAX	128
 #define HNS3_RSS_SET_BITMAP_MSK	0xffff
 
 #define HNS3_RSS_HASH_ALGO_TOEPLITZ	0
@@ -44,7 +45,7 @@ struct hns3_rss_conf {
 	/* RSS parameters :algorithm, flow_types,  key, queue */
 	struct rte_flow_action_rss conf;
 	uint8_t hash_algo; /* hash function type defined by hardware */
-	uint8_t key[HNS3_RSS_KEY_SIZE];  /* Hash key */
+	uint8_t key[HNS3_RSS_KEY_SIZE_MAX];  /* Hash key */
 	uint16_t rss_indirection_tbl[HNS3_RSS_IND_TBL_SIZE_MAX];
 	uint16_t queue[HNS3_RSS_QUEUES_BUFFER_NUM]; /* Queues indices to use */
 	bool valid; /* check if RSS rule is valid */
@@ -90,7 +91,7 @@ static inline uint32_t roundup_pow_of_two(uint32_t x)
 	return 1UL << fls(x - 1);
 }
 
-extern const uint8_t hns3_hash_key[];
+extern const uint8_t hns3_hash_key[HNS3_RSS_KEY_SIZE];
 
 struct hns3_adapter;
 
-- 
2.22.0


  parent reply	other threads:[~2023-03-21  9:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21  9:22 [PATCH 21.11 00/17] backport some patches for hns3 Huisong Li
2023-03-21  9:22 ` [PATCH 21.11 01/17] net/hns3: separate Tx prepare from getting Tx function Huisong Li
2023-03-21  9:22 ` [PATCH 21.11 02/17] net/hns3: make getting Tx function static Huisong Li
2023-03-21  9:22 ` Huisong Li [this message]
2023-03-21  9:22 ` [PATCH 21.11 04/17] net/hns3: fix burst mode query with dummy function Huisong Li
2023-03-21  9:22 ` [PATCH 21.11 05/17] net/hns3: extract common functions to set Rx/Tx Huisong Li
2023-03-21  9:22 ` [PATCH 21.11 06/17] net/hns3: use hardware config to report hash key Huisong Li
2023-03-21  9:22 ` [PATCH 21.11 07/17] net/hns3: use hardware config to report hash types Huisong Li
2023-03-21  9:22 ` [PATCH 21.11 08/17] net/hns3: separate setting hash algorithm Huisong Li
2023-03-21  9:22 ` [PATCH 21.11 09/17] net/hns3: separate setting hash key Huisong Li
2023-03-21  9:22 ` [PATCH 21.11 10/17] net/hns3: separate setting RSS types Huisong Li
2023-03-21  9:23 ` [PATCH 21.11 11/17] net/hns3: use new RSS rule to configure hardware Huisong Li
2023-03-21  9:23 ` [PATCH 21.11 12/17] net/hns3: save hash algo to RSS filter list node Huisong Li
2023-03-21  9:23 ` [PATCH 21.11 13/17] net/hns3: remove unused structures Huisong Li
2023-03-21  9:23 ` [PATCH 21.11 14/17] net/hns3: allow adding queue buffer size hash rule Huisong Li
2023-03-21  9:23 ` [PATCH 21.11 15/17] net/hns3: separate flow RSS config from RSS conf Huisong Li
2023-03-21  9:23 ` [PATCH 21.11 16/17] net/hns3: reimplement hash flow function Huisong Li
2023-03-21  9:23 ` [PATCH 21.11 17/17] net/hns3: add verification of RSS types Huisong Li
2023-03-21 16:21 ` [PATCH 21.11 00/17] backport some patches for hns3 Kevin Traynor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230321092306.16918-4-lihuisong@huawei.com \
    --to=lihuisong@huawei.com \
    --cc=huangdaode@huawei.com \
    --cc=ktraynor@redhat.com \
    --cc=liudongdong3@huawei.com \
    --cc=liuyonglong@huawei.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).