DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dongdong Liu <liudongdong3@huawei.com>
To: <dev@dpdk.org>, <ferruh.yigit@amd.com>, <thomas@monjalon.net>,
	<andrew.rybchenko@oktetlabs.ru>
Cc: <stable@dpdk.org>, <yisen.zhuang@huawei.com>,
	<liudongdong3@huawei.com>, <lihuisong@huawei.com>
Subject: [PATCH V3 03/10] net/hns3: refactor set RSS hash algorithm and key interface
Date: Tue, 31 Jan 2023 21:02:53 +0800	[thread overview]
Message-ID: <20230131130300.24713-4-liudongdong3@huawei.com> (raw)
In-Reply-To: <20230131130300.24713-1-liudongdong3@huawei.com>

From: Huisong Li <lihuisong@huawei.com>

The hns3_rss_set_algo_key() is used to set RSS hash algorithm and key to
hardware. The maximum times of command sent to firmware depend on the
length of key. However, now this times is fixed, which isn't good for
key expansion. In addition, hash algorithm comes from rss_info::hash_algo
maintained in driver, which also isn't good for the usage of this function.
This patch has to use hash algorithm and key length as the input parameters
of this interface.

Fixes: c37ca66f2b27 ("net/hns3: support RSS")
Cc: stable@dpdk.org

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

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index a2c1589c39..95609f8483 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1494,7 +1494,8 @@ hns3_hw_rss_hash_set(struct hns3_hw *hw, struct rte_flow_action_rss *rss_config)
 	if (ret)
 		return ret;
 
-	ret = hns3_rss_set_algo_key(hw, rss_config->key);
+	ret = hns3_rss_set_algo_key(hw, hw->rss_info.hash_algo,
+				    rss_config->key, HNS3_RSS_KEY_SIZE);
 	if (ret)
 		return ret;
 
diff --git a/drivers/net/hns3/hns3_rss.c b/drivers/net/hns3/hns3_rss.c
index ca5a129234..3db7bf0445 100644
--- a/drivers/net/hns3/hns3_rss.c
+++ b/drivers/net/hns3/hns3_rss.c
@@ -277,45 +277,37 @@ static const struct {
 
 /*
  * rss_generic_config command function, opcode:0x0D01.
- * Used to set algorithm, key_offset and hash key of rss.
+ * Used to set algorithm and hash key of RSS.
  */
 int
-hns3_rss_set_algo_key(struct hns3_hw *hw, const uint8_t *key)
+hns3_rss_set_algo_key(struct hns3_hw *hw, uint8_t hash_algo,
+		      const uint8_t *key, uint8_t key_len)
 {
-#define HNS3_KEY_OFFSET_MAX	3
-#define HNS3_SET_HASH_KEY_BYTE_FOUR	2
-
 	struct hns3_rss_generic_config_cmd *req;
 	struct hns3_cmd_desc desc;
-	uint32_t key_offset, key_size;
-	const uint8_t *key_cur;
-	uint8_t cur_offset;
+	const uint8_t *cur_key;
+	uint16_t cur_key_size;
+	uint16_t max_bd_num;
+	uint16_t idx;
 	int ret;
 
 	req = (struct hns3_rss_generic_config_cmd *)desc.data;
 
-	/*
-	 * key_offset=0, hash key byte0~15 is set to hardware.
-	 * key_offset=1, hash key byte16~31 is set to hardware.
-	 * key_offset=2, hash key byte32~39 is set to hardware.
-	 */
-	for (key_offset = 0; key_offset < HNS3_KEY_OFFSET_MAX; key_offset++) {
+	max_bd_num = DIV_ROUND_UP(key_len, HNS3_RSS_HASH_KEY_NUM);
+	for (idx = 0; idx < max_bd_num; idx++) {
 		hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RSS_GENERIC_CONFIG,
 					  false);
 
-		req->hash_config |=
-			(hw->rss_info.hash_algo & HNS3_RSS_HASH_ALGO_MASK);
-		req->hash_config |= (key_offset << HNS3_RSS_HASH_KEY_OFFSET_B);
+		req->hash_config |= (hash_algo & HNS3_RSS_HASH_ALGO_MASK);
+		req->hash_config |= (idx << HNS3_RSS_HASH_KEY_OFFSET_B);
 
-		if (key_offset == HNS3_SET_HASH_KEY_BYTE_FOUR)
-			key_size = HNS3_RSS_KEY_SIZE - HNS3_RSS_HASH_KEY_NUM *
-			HNS3_SET_HASH_KEY_BYTE_FOUR;
+		if (idx == max_bd_num - 1)
+			cur_key_size = key_len % HNS3_RSS_HASH_KEY_NUM;
 		else
-			key_size = HNS3_RSS_HASH_KEY_NUM;
+			cur_key_size = HNS3_RSS_HASH_KEY_NUM;
 
-		cur_offset = key_offset * HNS3_RSS_HASH_KEY_NUM;
-		key_cur = key + cur_offset;
-		memcpy(req->hash_key, key_cur, key_size);
+		cur_key = key + idx * HNS3_RSS_HASH_KEY_NUM;
+		memcpy(req->hash_key, cur_key, cur_key_size);
 
 		ret = hns3_cmd_send(hw, &desc, 1);
 		if (ret) {
@@ -518,7 +510,8 @@ hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
 		goto set_tuple_fail;
 
 	if (key) {
-		ret = hns3_rss_set_algo_key(hw, key);
+		ret = hns3_rss_set_algo_key(hw, hw->rss_info.hash_algo,
+					    key, HNS3_RSS_KEY_SIZE);
 		if (ret)
 			goto set_algo_key_fail;
 	}
@@ -795,8 +788,9 @@ hns3_config_rss(struct hns3_adapter *hns)
 		break;
 	}
 
-	/* Configure RSS hash algorithm and hash key offset */
-	ret = hns3_rss_set_algo_key(hw, hash_key);
+	/* 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);
 	if (ret)
 		return ret;
 
diff --git a/drivers/net/hns3/hns3_rss.h b/drivers/net/hns3/hns3_rss.h
index 8e8b056f4e..b7f62ca1ee 100644
--- a/drivers/net/hns3/hns3_rss.h
+++ b/drivers/net/hns3/hns3_rss.h
@@ -109,6 +109,8 @@ int hns3_rss_reset_indir_table(struct hns3_hw *hw);
 int hns3_config_rss(struct hns3_adapter *hns);
 void hns3_rss_uninit(struct hns3_adapter *hns);
 int hns3_set_rss_tuple_by_rss_hf(struct hns3_hw *hw, uint64_t rss_hf);
-int hns3_rss_set_algo_key(struct hns3_hw *hw, const uint8_t *key);
+int hns3_rss_set_algo_key(struct hns3_hw *hw, uint8_t hash_algo,
+			  const uint8_t *key, uint8_t key_len);
+
 
 #endif /* HNS3_RSS_H */
-- 
2.22.0


  parent reply	other threads:[~2023-01-31 13:04 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
2023-01-29 10:51 ` [PATCH 01/10] net/hns3: fix error log about indirection table size Dongdong Liu
2023-01-29 10:51 ` [PATCH 02/10] net/hns3: extract common API to query device Dongdong Liu
2023-01-29 10:51 ` [PATCH 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
2023-01-29 10:51 ` [PATCH 04/10] net/hns3: fix fixed RSS key size to be more compatibility Dongdong Liu
2023-01-29 10:51 ` [PATCH 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
2023-01-29 10:51 ` [PATCH 06/10] net/hns3: using RSS filter list to check duplicated rule Dongdong Liu
2023-01-29 10:51 ` [PATCH 07/10] net/hns3: remove useless code when destroy valid RSS rule Dongdong Liu
2023-01-29 10:51 ` [PATCH 08/10] net/hns3: fix useless warning when flush or destroy rule Dongdong Liu
2023-01-29 10:51 ` [PATCH 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
2023-01-29 10:51 ` [PATCH 10/10] net/hns3: fix incorrect check for duplicate RSS rule Dongdong Liu
2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 01/10] net/hns3: fix error log about indirection table size Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 02/10] net/hns3: extract common API to query device Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 04/10] net/hns3: fix fixed RSS key size to be more compatibility Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 06/10] net/hns3: using RSS filter list to check duplicated rule Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 07/10] net/hns3: remove useless code when destroy valid RSS rule Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 08/10] net/hns3: fix useless warning when flush or destroy rule Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
2023-01-31  9:34     ` Dongdong Liu
2023-01-30  9:31   ` [PATCH V2 10/10] net/hns3: fix incorrect check for duplicate RSS rule Dongdong Liu
2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 01/10] net/hns3: fix error log about indirection table size Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 02/10] net/hns3: extract common API to query device Dongdong Liu
2023-01-31 13:02   ` Dongdong Liu [this message]
2023-01-31 13:02   ` [PATCH V3 04/10] net/hns3: fix fixed RSS key size to be more compatibility Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 06/10] net/hns3: using RSS filter list to check duplicated rule Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 07/10] net/hns3: remove useless code when destroy valid RSS rule Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 08/10] net/hns3: fix useless warning when flush or destroy rule Dongdong Liu
2023-01-31 13:02   ` [PATCH V3 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
2023-01-31 13:03   ` [PATCH V3 10/10] net/hns3: fix incorrect check for duplicate RSS rule Dongdong Liu
2023-02-08 17:46   ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Ferruh Yigit

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=20230131130300.24713-4-liudongdong3@huawei.com \
    --to=liudongdong3@huawei.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=lihuisong@huawei.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    --cc=yisen.zhuang@huawei.com \
    /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).