All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/10] net/hns3: some bugfixes for rss
@ 2023-01-29 10:51 Dongdong Liu
  2023-01-29 10:51 ` [PATCH 01/10] net/hns3: fix error log about indirection table size Dongdong Liu
                   ` (11 more replies)
  0 siblings, 12 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

This patchset is to do some bugfixes for hns3 rss.

Huisong Li (10):
  net/hns3: fix error log about indirection table size
  net/hns3: extract common API to query device
  net/hns3: refactor set RSS hash algorithm and key interface
  net/hns3: fix fixed RSS key size to be more compatibility
  net/hns3: fix misclearing RSS configuration
  net/hns3: using RSS filter list to check duplicated rule
  net/hns3: remove useless code when destroy valid RSS rule
  net/hns3: fix useless warning when flush or destroy rule
  net/hns3: fix bad memory structure conversion
  net/hns3: fix incorrect check for duplicate RSS rule

 drivers/net/hns3/hns3_common.c    |  87 +++++++++++-
 drivers/net/hns3/hns3_common.h    |   2 +
 drivers/net/hns3/hns3_ethdev.c    |  63 ---------
 drivers/net/hns3/hns3_ethdev_vf.c |  65 +--------
 drivers/net/hns3/hns3_flow.c      | 217 ++++++++++++++----------------
 drivers/net/hns3/hns3_rss.c       |  63 ++++-----
 drivers/net/hns3/hns3_rss.h       |   7 +-
 7 files changed, 227 insertions(+), 277 deletions(-)

--
2.22.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 01/10] net/hns3: fix error log about indirection table size
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
@ 2023-01-29 10:51 ` Dongdong Liu
  2023-01-29 10:51 ` [PATCH 02/10] net/hns3: extract common API to query device Dongdong Liu
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The error log about indirection table size during initialization phase
of PF and VF is unreasonable when the indirection table size obtained
from firmware or PF function should be zero. In addition, VF driver
should use error level to print this log.

Fixes: 0fce2c46dc16 ("net/hns3: fix RSS indirection table size")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c    | 2 +-
 drivers/net/hns3/hns3_ethdev_vf.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index d326f70129..eb809cd8c9 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2679,7 +2679,7 @@ hns3_check_dev_specifications(struct hns3_hw *hw)
 {
 	if (hw->rss_ind_tbl_size == 0 ||
 	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the size of hash lookup table configured (%u) exceeds the maximum(%u)",
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
 			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
 		return -EINVAL;
 	}
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index d220522c43..e43815607a 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -718,8 +718,8 @@ hns3vf_check_dev_specifications(struct hns3_hw *hw)
 {
 	if (hw->rss_ind_tbl_size == 0 ||
 	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_warn(hw, "the size of hash lookup table configured (%u) exceeds the maximum(%u)",
-			  hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
+			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
 		return -EINVAL;
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 02/10] net/hns3: extract common API to query device
  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 ` Dongdong Liu
  2023-01-29 10:51 ` [PATCH 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

Extract common function to query device specifications.

Fixes: 9c740336f024 ("net/hns3: get device specifications from firmware")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_common.c    | 75 +++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_common.h    |  2 +
 drivers/net/hns3/hns3_ethdev.c    | 63 --------------------------
 drivers/net/hns3/hns3_ethdev_vf.c | 65 +--------------------------
 4 files changed, 79 insertions(+), 126 deletions(-)

diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
index 7adc6a4972..b0c7f8d62c 100644
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -10,6 +10,7 @@
 #include "hns3_logs.h"
 #include "hns3_regs.h"
 #include "hns3_rxtx.h"
+#include "hns3_dcb.h"
 #include "hns3_common.h"
 
 int
@@ -845,3 +846,77 @@ hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id)
 
 	return 0;
 }
+
+void
+hns3_set_default_dev_specifications(struct hns3_hw *hw)
+{
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+
+	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
+	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
+	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
+	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
+
+	if (hns->is_vf)
+		return;
+
+	hw->max_tm_rate = HNS3_ETHER_MAX_RATE;
+}
+
+static void
+hns3_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
+{
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+	struct hns3_dev_specs_0_cmd *req0;
+	struct hns3_dev_specs_1_cmd *req1;
+
+	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
+	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
+
+	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
+	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
+	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
+	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
+	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
+
+	if (hns->is_vf)
+		return;
+
+	hw->max_tm_rate = rte_le_to_cpu_32(req0->max_tm_rate);
+}
+
+static int
+hns3_check_dev_specifications(struct hns3_hw *hw)
+{
+	if (hw->rss_ind_tbl_size == 0 ||
+	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
+			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int
+hns3_query_dev_specifications(struct hns3_hw *hw)
+{
+	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
+	int ret;
+	int i;
+
+	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
+		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
+					  true);
+		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
+	}
+	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
+
+	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
+	if (ret)
+		return ret;
+
+	hns3_parse_dev_specifications(hw, desc);
+
+	return hns3_check_dev_specifications(hw);
+}
diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h
index 5aa001f0cc..8eaeda26e7 100644
--- a/drivers/net/hns3/hns3_common.h
+++ b/drivers/net/hns3/hns3_common.h
@@ -60,5 +60,7 @@ void hns3_unmap_rx_interrupt(struct rte_eth_dev *dev);
 int hns3_restore_rx_interrupt(struct hns3_hw *hw);
 
 int hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id);
+void hns3_set_default_dev_specifications(struct hns3_hw *hw);
+int hns3_query_dev_specifications(struct hns3_hw *hw);
 
 #endif /* HNS3_COMMON_H */
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index eb809cd8c9..ab565ce128 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2647,69 +2647,6 @@ hns3_parse_speed(int speed_cmd, uint32_t *speed)
 	return 0;
 }
 
-static void
-hns3_set_default_dev_specifications(struct hns3_hw *hw)
-{
-	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
-	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
-	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
-	hw->max_tm_rate = HNS3_ETHER_MAX_RATE;
-	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
-}
-
-static void
-hns3_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
-{
-	struct hns3_dev_specs_0_cmd *req0;
-	struct hns3_dev_specs_1_cmd *req1;
-
-	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
-	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
-
-	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
-	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
-	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
-	hw->max_tm_rate = rte_le_to_cpu_32(req0->max_tm_rate);
-	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
-	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
-}
-
-static int
-hns3_check_dev_specifications(struct hns3_hw *hw)
-{
-	if (hw->rss_ind_tbl_size == 0 ||
-	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
-			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int
-hns3_query_dev_specifications(struct hns3_hw *hw)
-{
-	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
-	int ret;
-	int i;
-
-	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
-		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
-					  true);
-		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
-	}
-	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
-
-	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
-	if (ret)
-		return ret;
-
-	hns3_parse_dev_specifications(hw, desc);
-
-	return hns3_check_dev_specifications(hw);
-}
-
 static int
 hns3_get_capability(struct hns3_hw *hw)
 {
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index e43815607a..d3c1bdf2c5 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -688,67 +688,6 @@ hns3vf_interrupt_handler(void *param)
 	hns3vf_enable_irq0(hw);
 }
 
-static void
-hns3vf_set_default_dev_specifications(struct hns3_hw *hw)
-{
-	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
-	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
-	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
-	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
-}
-
-static void
-hns3vf_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
-{
-	struct hns3_dev_specs_0_cmd *req0;
-	struct hns3_dev_specs_1_cmd *req1;
-
-	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
-	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
-
-	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
-	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
-	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
-	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
-	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
-}
-
-static int
-hns3vf_check_dev_specifications(struct hns3_hw *hw)
-{
-	if (hw->rss_ind_tbl_size == 0 ||
-	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
-			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int
-hns3vf_query_dev_specifications(struct hns3_hw *hw)
-{
-	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
-	int ret;
-	int i;
-
-	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
-		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
-					  true);
-		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
-	}
-	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
-
-	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
-	if (ret)
-		return ret;
-
-	hns3vf_parse_dev_specifications(hw, desc);
-
-	return hns3vf_check_dev_specifications(hw);
-}
-
 void
 hns3vf_update_push_lsc_cap(struct hns3_hw *hw, bool supported)
 {
@@ -826,7 +765,7 @@ hns3vf_get_capability(struct hns3_hw *hw)
 		return ret;
 
 	if (hw->revision < PCI_REVISION_ID_HIP09_A) {
-		hns3vf_set_default_dev_specifications(hw);
+		hns3_set_default_dev_specifications(hw);
 		hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
 		hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
 		hw->tso_mode = HNS3_TSO_SW_CAL_PSEUDO_H_CSUM;
@@ -837,7 +776,7 @@ hns3vf_get_capability(struct hns3_hw *hw)
 		return 0;
 	}
 
-	ret = hns3vf_query_dev_specifications(hw);
+	ret = hns3_query_dev_specifications(hw);
 	if (ret) {
 		PMD_INIT_LOG(ERR,
 			     "failed to query dev specifications, ret = %d",
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 03/10] net/hns3: refactor set RSS hash algorithm and key interface
  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 ` Dongdong Liu
  2023-01-29 10:51 ` [PATCH 04/10] net/hns3: fix fixed RSS key size to be more compatibility Dongdong Liu
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

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


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 04/10] net/hns3: fix fixed RSS key size to be more compatibility
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                   ` (2 preceding siblings ...)
  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 ` Dongdong Liu
  2023-01-29 10:51 ` [PATCH 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

For better compatibility, the RSS key size of PF and VF are obtained from
firmware. However, many places still used the old macro HNS3_RSS_KEY_SIZE
as the key size.

Fixes: 9c740336f024 ("net/hns3: get device specifications from firmware")
Cc: stable@dpdk.org

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    | 23 +++++++++++------------
 drivers/net/hns3/hns3_rss.h    |  3 ++-
 4 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
index b0c7f8d62c..2da0f30964 100644
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -129,7 +129,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;
@@ -895,6 +895,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 95609f8483..a18ec7650d 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1406,10 +1406,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,
@@ -1443,16 +1443,6 @@ hns3_disable_rss(struct hns3_hw *hw)
 	return 0;
 }
 
-static void
-hns3_adjust_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)
@@ -1485,9 +1475,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_adjust_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);
@@ -1495,7 +1492,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 3db7bf0445..d6e0754273 100644
--- a/drivers/net/hns3/hns3_rss.c
+++ b/drivers/net/hns3/hns3_rss.c
@@ -316,7 +316,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;
 }
 
@@ -498,9 +498,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;
 	}
 
@@ -511,7 +511,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;
 	}
@@ -547,9 +547,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);
 
@@ -754,8 +754,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++)
@@ -788,9 +788,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 b7f62ca1ee..d6f81996f4 100644
--- a/drivers/net/hns3/hns3_rss.h
+++ b/drivers/net/hns3/hns3_rss.h
@@ -29,6 +29,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
@@ -41,7 +42,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 */
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 05/10] net/hns3: fix misclearing RSS configuration
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                   ` (3 preceding siblings ...)
  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 ` Dongdong Liu
  2023-01-29 10:51 ` [PATCH 06/10] net/hns3: using RSS filter list to check duplicated rule Dongdong Liu
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The RSS configuration will be miscleared when driver receives a RSS rule
which has more one RSS action.

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 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index a18ec7650d..c338eab049 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1421,12 +1421,10 @@ hns3_parse_rss_filter(struct rte_eth_dev *dev,
 
 	/* Check if the next not void action is END */
 	NEXT_ITEM_OF_ACTION(act, actions, act_index);
-	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
-		memset(rss_conf, 0, sizeof(struct hns3_rss_conf));
+	if (act->type != RTE_FLOW_ACTION_TYPE_END)
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_ACTION,
 					  act, "Not supported action.");
-	}
 
 	return 0;
 }
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 06/10] net/hns3: using RSS filter list to check duplicated rule
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                   ` (4 preceding siblings ...)
  2023-01-29 10:51 ` [PATCH 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
@ 2023-01-29 10:51 ` Dongdong Liu
  2023-01-29 10:51 ` [PATCH 07/10] net/hns3: remove useless code when destroy valid RSS rule Dongdong Liu
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

All rules from user are saved in RSS filter list, so use RSS
filter list to check duplicated rule.

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 | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index c338eab049..303275ae93 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1300,7 +1300,7 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 		!memcmp(comp->key, with->key, with->key_len);
 
 	return (func_is_same && rss_key_is_same &&
-		comp->types == (with->types & HNS3_ETH_RSS_SUPPORT) &&
+		comp->types == with->types &&
 		comp->level == with->level &&
 		comp->queue_num == with->queue_num &&
 		!memcmp(comp->queue, with->queue,
@@ -1596,15 +1596,7 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 	}
 
 	/* Set hash algorithm and flow types by the user's config */
-	ret = hns3_hw_rss_hash_set(hw, &rss_flow_conf);
-	if (ret)
-		return ret;
-
-	ret = hns3_rss_conf_copy(rss_info, &rss_flow_conf);
-	if (ret)
-		hns3_err(hw, "RSS config init fail(%d)", ret);
-
-	return ret;
+	return hns3_hw_rss_hash_set(hw, &rss_flow_conf);
 }
 
 static int
@@ -1676,17 +1668,32 @@ hns3_restore_filter(struct hns3_adapter *hns)
 	return hns3_restore_rss_filter(hw);
 }
 
+static bool
+hns3_rss_action_is_dup(struct hns3_hw *hw,
+		       const struct rte_flow_action_rss *act)
+{
+	struct hns3_rss_conf_ele *filter;
+
+	TAILQ_FOREACH(filter, &hw->flow_rss_list, entries) {
+		if (!filter->filter_info.valid)
+			continue;
+
+		if (hns3_action_rss_same(&filter->filter_info.conf, act))
+			return true;
+	}
+
+	return false;
+}
+
 static int
 hns3_flow_parse_rss(struct rte_eth_dev *dev,
 		    const struct hns3_rss_conf *conf, bool add)
 {
 	struct hns3_adapter *hns = dev->data->dev_private;
 	struct hns3_hw *hw = &hns->hw;
-	bool ret;
 
-	ret = hns3_action_rss_same(&hw->rss_info.conf, &conf->conf);
-	if (ret) {
-		hns3_err(hw, "Enter duplicate RSS configuration : %d", ret);
+	if (hns3_rss_action_is_dup(hw, &conf->conf)) {
+		hns3_err(hw, "duplicate RSS configuration");
 		return -EINVAL;
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 07/10] net/hns3: remove useless code when destroy valid RSS rule
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                   ` (5 preceding siblings ...)
  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 ` Dongdong Liu
  2023-01-29 10:51 ` [PATCH 08/10] net/hns3: fix useless warning when flush or destroy rule Dongdong Liu
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The hw::rss_info::conf::func was set to the macro RTE_ETH_HASH_FUNCTION_MAX
and hw::rss_info::conf::queue was set to NULL when all rules are flushed,
which indicates no flow rules is issued. See
commit eb158fc756a5 ("net/hns3: fix config when creating RSS rule after
flush").
Actually, the way determining whether there are rules has been changed by
walking the flow RSS list. See
commit 705a50800334 ("net/hns3: fix RSS filter restore").

In addition, the rte_flow_action_rss from user isn't saved to 'conf' in
hw->rss_info now. So this code can be removed.

Fixes: eb158fc756a5 ("net/hns3: fix config when creating RSS rule after flush")
Fixes: 705a50800334 ("net/hns3: fix RSS filter restore")
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 | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 303275ae93..7adde16cbc 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1279,19 +1279,8 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 	bool rss_key_is_same;
 	bool func_is_same;
 
-	/*
-	 * When user flush all RSS rule, RSS func is set invalid with
-	 * RTE_ETH_HASH_FUNCTION_MAX. Then the user create a flow after
-	 * flushed, any validate RSS func is different with it before
-	 * flushed. Others, when user create an action RSS with RSS func
-	 * specified RTE_ETH_HASH_FUNCTION_DEFAULT, the func is the same
-	 * between continuous RSS flow.
-	 */
-	if (comp->func == RTE_ETH_HASH_FUNCTION_MAX)
-		func_is_same = false;
-	else
-		func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
-				(comp->func == with->func) : true;
+	func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
+			(comp->func == with->func) : true;
 
 	if (with->key_len == 0 || with->key == NULL)
 		rss_key_is_same = 1;
@@ -1533,7 +1522,6 @@ static int
 hns3_config_rss_filter(struct hns3_hw *hw,
 		       const struct hns3_rss_conf *conf, bool add)
 {
-	struct hns3_rss_conf *rss_info;
 	uint64_t flow_types;
 	uint16_t num;
 	int ret;
@@ -1560,7 +1548,6 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 	/* Update the useful flow types */
 	rss_flow_conf.types = flow_types;
 
-	rss_info = &hw->rss_info;
 	if (!add) {
 		if (!conf->valid)
 			return 0;
@@ -1571,15 +1558,6 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 			return ret;
 		}
 
-		if (rss_flow_conf.queue_num) {
-			/*
-			 * Due the content of queue pointer have been reset to
-			 * 0, the rss_info->conf.queue should be set to NULL
-			 */
-			rss_info->conf.queue = NULL;
-			rss_info->conf.queue_num = 0;
-		}
-
 		return 0;
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 08/10] net/hns3: fix useless warning when flush or destroy rule
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                   ` (6 preceding siblings ...)
  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 ` Dongdong Liu
  2023-01-29 10:51 ` [PATCH 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The types of the rule will no longer be used when user flush all rules or
destroy a rule. But user would receive some RSS types warnings, like,
"modified RSS types based on hardware support, requested:0x137f83fffc
configured:0x3ffc".

Fixes: ec674cb742e5 ("net/hns3: fix flushing RSS rule")
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 | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 7adde16cbc..fbc38dd3d4 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1537,17 +1537,6 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 		.queue = conf->conf.queue,
 	};
 
-	/* Filter the unsupported flow types */
-	flow_types = conf->conf.types ?
-		     rss_flow_conf.types & HNS3_ETH_RSS_SUPPORT :
-		     hw->rss_info.conf.types;
-	if (flow_types != rss_flow_conf.types)
-		hns3_warn(hw, "modified RSS types based on hardware support, "
-			      "requested:0x%" PRIx64 " configured:0x%" PRIx64,
-			  rss_flow_conf.types, flow_types);
-	/* Update the useful flow types */
-	rss_flow_conf.types = flow_types;
-
 	if (!add) {
 		if (!conf->valid)
 			return 0;
@@ -1573,6 +1562,17 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 			return ret;
 	}
 
+	/* Filter the unsupported flow types */
+	flow_types = conf->conf.types ?
+		     rss_flow_conf.types & HNS3_ETH_RSS_SUPPORT :
+		     hw->rss_info.conf.types;
+	if (flow_types != rss_flow_conf.types)
+		hns3_warn(hw, "modified RSS types based on hardware support,"
+			  " requested:0x%" PRIx64 " configured:0x%" PRIx64,
+			  rss_flow_conf.types, flow_types);
+	/* Update the useful flow types */
+	rss_flow_conf.types = flow_types;
+
 	/* Set hash algorithm and flow types by the user's config */
 	return hns3_hw_rss_hash_set(hw, &rss_flow_conf);
 }
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 09/10] net/hns3: fix bad memory structure conversion
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                   ` (7 preceding siblings ...)
  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 ` Dongdong Liu
  2023-01-29 10:51 ` [PATCH 10/10] net/hns3: fix incorrect check for duplicate RSS rule Dongdong Liu
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

When the type in 'struct rte_flow_action' is RTE_FLOW_ACTION_TYPE_RSS, the
'conf' pointer references the 'struct rte_flow_action_rss' instead of the
'struct hns3_rss_conf' in driver. But driver uses 'struct hns3_rss_conf' to
convert this 'conf' pointer to get RSS action configuration.

In addition, RSS filter configuration is directly cloned to RSS filter node
instead of coping it after successfully setting to hardware.

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 | 57 +++++++++++++-----------------------
 1 file changed, 20 insertions(+), 37 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index fbc38dd3d4..307aba75a7 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -95,8 +95,8 @@ static const struct rte_flow_action *
 hns3_find_rss_general_action(const struct rte_flow_item pattern[],
 			     const struct rte_flow_action actions[])
 {
+	const struct rte_flow_action_rss *rss_act;
 	const struct rte_flow_action *act = NULL;
-	const struct hns3_rss_conf *rss;
 	bool have_eth = false;
 
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
@@ -115,8 +115,8 @@ hns3_find_rss_general_action(const struct rte_flow_item pattern[],
 		}
 	}
 
-	rss = act->conf;
-	if (have_eth && rss->conf.queue_num) {
+	rss_act = act->conf;
+	if (have_eth && rss_act->queue_num) {
 		/*
 		 * Pattern have ETH and action's queue_num > 0, indicate this is
 		 * queue region configuration.
@@ -1296,30 +1296,6 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 			sizeof(*with->queue) * with->queue_num));
 }
 
-static int
-hns3_rss_conf_copy(struct hns3_rss_conf *out,
-		   const struct rte_flow_action_rss *in)
-{
-	if (in->key_len > RTE_DIM(out->key) ||
-	    in->queue_num > RTE_DIM(out->queue))
-		return -EINVAL;
-	if (in->key == NULL && in->key_len)
-		return -EINVAL;
-	out->conf = (struct rte_flow_action_rss) {
-		.func = in->func,
-		.level = in->level,
-		.types = in->types,
-		.key_len = in->key_len,
-		.queue_num = in->queue_num,
-	};
-	out->conf.queue = memcpy(out->queue, in->queue,
-				sizeof(*in->queue) * in->queue_num);
-	if (in->key)
-		out->conf.key = memcpy(out->key, in->key, in->key_len);
-
-	return 0;
-}
-
 static bool
 hns3_rss_input_tuple_supported(struct hns3_hw *hw,
 			       const struct rte_flow_action_rss *rss)
@@ -1733,9 +1709,10 @@ hns3_flow_create_rss_rule(struct rte_eth_dev *dev,
 			  struct rte_flow *flow)
 {
 	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	const struct rte_flow_action_rss *rss_act;
 	struct hns3_rss_conf_ele *rss_filter_ptr;
 	struct hns3_rss_conf_ele *filter_ptr;
-	const struct hns3_rss_conf *rss_conf;
+	struct hns3_rss_conf *new_conf;
 	int ret;
 
 	rss_filter_ptr = rte_zmalloc("hns3 rss filter",
@@ -1745,19 +1722,25 @@ hns3_flow_create_rss_rule(struct rte_eth_dev *dev,
 		return -ENOMEM;
 	}
 
-	/*
-	 * After all the preceding tasks are successfully configured, configure
-	 * rules to the hardware to simplify the rollback of rules in the
-	 * hardware.
-	 */
-	rss_conf = (const struct hns3_rss_conf *)act->conf;
-	ret = hns3_flow_parse_rss(dev, rss_conf, true);
+	rss_act = (const struct rte_flow_action_rss *)act->conf;
+	new_conf = &rss_filter_ptr->filter_info;
+	memcpy(&new_conf->conf, rss_act, sizeof(*rss_act));
+	if (rss_act->queue_num > 0) {
+		memcpy(new_conf->queue, rss_act->queue,
+		       rss_act->queue_num * sizeof(new_conf->queue[0]));
+		new_conf->conf.queue = new_conf->queue;
+	}
+	if (rss_act->key_len > 0) {
+		memcpy(new_conf->key, rss_act->key,
+		       rss_act->key_len * sizeof(new_conf->key[0]));
+		new_conf->conf.key = new_conf->key;
+	}
+
+	ret = hns3_flow_parse_rss(dev, new_conf, true);
 	if (ret != 0) {
 		rte_free(rss_filter_ptr);
 		return ret;
 	}
-
-	hns3_rss_conf_copy(&rss_filter_ptr->filter_info, &rss_conf->conf);
 	rss_filter_ptr->filter_info.valid = true;
 
 	/*
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 10/10] net/hns3: fix incorrect check for duplicate RSS rule
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                   ` (8 preceding siblings ...)
  2023-01-29 10:51 ` [PATCH 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
@ 2023-01-29 10:51 ` Dongdong Liu
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
  11 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-29 10:51 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

Currently, the interface for verifying duplicate RSS rules has
some problems:
1) If the value of 'func' in configuring RSS rule is default
   value, this rule is mistakenly considered as a duplicate rule.
2) If key length is zero or 'key' is NULL in configuring RSS rule
   this rule is also mistakenly considered as a duplicate rule.
3) If 'key' or 'queue' in struct rte_flow_action_rss being NULL
   is used to memcpy, which may cause segment fault.

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 | 58 ++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 16 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 307aba75a7..f76ceb18d1 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1272,28 +1272,54 @@ hns3_filterlist_flush(struct rte_eth_dev *dev)
 	}
 }
 
+static bool
+hns3_flow_rule_key_same(const struct rte_flow_action_rss *comp,
+			const struct rte_flow_action_rss *with)
+{
+	if (comp->key_len != with->key_len)
+		return false;
+
+	if (with->key_len == 0)
+		return true;
+
+	if (comp->key == NULL && with->key == NULL)
+		return true;
+
+	if (!(comp->key != NULL && with->key != NULL))
+		return false;
+
+	return !memcmp(comp->key, with->key, with->key_len);
+}
+
+static bool
+hns3_flow_rule_queues_same(const struct rte_flow_action_rss *comp,
+			   const struct rte_flow_action_rss *with)
+{
+	if (comp->queue_num != with->queue_num)
+		return false;
+
+	if (with->queue_num == 0)
+		return true;
+
+	if (comp->queue == NULL && with->queue == NULL)
+		return true;
+
+	if (!(comp->queue != NULL && with->queue != NULL))
+		return false;
+
+	return !memcmp(comp->queue, with->queue, with->queue_num);
+}
+
 static bool
 hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 		     const struct rte_flow_action_rss *with)
 {
-	bool rss_key_is_same;
-	bool func_is_same;
+	bool same_func;
 
-	func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
-			(comp->func == with->func) : true;
+	same_func = (comp->func == with->func);
 
-	if (with->key_len == 0 || with->key == NULL)
-		rss_key_is_same = 1;
-	else
-		rss_key_is_same = comp->key_len == with->key_len &&
-		!memcmp(comp->key, with->key, with->key_len);
-
-	return (func_is_same && rss_key_is_same &&
-		comp->types == with->types &&
-		comp->level == with->level &&
-		comp->queue_num == with->queue_num &&
-		!memcmp(comp->queue, with->queue,
-			sizeof(*with->queue) * with->queue_num));
+	return same_func && hns3_flow_rule_key_same(comp, with) &&
+		hns3_flow_rule_queues_same(comp, with);
 }
 
 static bool
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 00/10] net/hns3: some bugfixes for rss
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                   ` (9 preceding siblings ...)
  2023-01-29 10:51 ` [PATCH 10/10] net/hns3: fix incorrect check for duplicate RSS rule Dongdong Liu
@ 2023-01-30  9:31 ` Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 01/10] net/hns3: fix error log about indirection table size Dongdong Liu
                     ` (9 more replies)
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
  11 siblings, 10 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

This patchset is to do some bugfixes for hns3 rss.

v1->v2:
- Fix missing comparison of types and level when verifying duplicate
  rules for [PATCH 10/10].

Huisong Li (10):
  net/hns3: fix error log about indirection table size
  net/hns3: extract common API to query device
  net/hns3: refactor set RSS hash algorithm and key interface
  net/hns3: fix fixed RSS key size to be more compatibility
  net/hns3: fix misclearing RSS configuration
  net/hns3: using RSS filter list to check duplicated rule
  net/hns3: remove useless code when destroy valid RSS rule
  net/hns3: fix useless warning when flush or destroy rule
  net/hns3: fix bad memory structure conversion
  net/hns3: fix incorrect check for duplicate RSS rule

 drivers/net/hns3/hns3_common.c    |  87 +++++++++++-
 drivers/net/hns3/hns3_common.h    |   2 +
 drivers/net/hns3/hns3_ethdev.c    |  63 ---------
 drivers/net/hns3/hns3_ethdev_vf.c |  65 +--------
 drivers/net/hns3/hns3_flow.c      | 222 +++++++++++++++---------------
 drivers/net/hns3/hns3_rss.c       |  63 ++++-----
 drivers/net/hns3/hns3_rss.h       |   7 +-
 7 files changed, 232 insertions(+), 277 deletions(-)

--
2.22.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH V2 01/10] net/hns3: fix error log about indirection table size
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
@ 2023-01-30  9:31   ` Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 02/10] net/hns3: extract common API to query device Dongdong Liu
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The error log about indirection table size during initialization phase
of PF and VF is unreasonable when the indirection table size obtained
from firmware or PF function should be zero. In addition, VF driver
should use error level to print this log.

Fixes: 0fce2c46dc16 ("net/hns3: fix RSS indirection table size")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c    | 2 +-
 drivers/net/hns3/hns3_ethdev_vf.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index d326f70129..eb809cd8c9 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2679,7 +2679,7 @@ hns3_check_dev_specifications(struct hns3_hw *hw)
 {
 	if (hw->rss_ind_tbl_size == 0 ||
 	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the size of hash lookup table configured (%u) exceeds the maximum(%u)",
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
 			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
 		return -EINVAL;
 	}
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index d220522c43..e43815607a 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -718,8 +718,8 @@ hns3vf_check_dev_specifications(struct hns3_hw *hw)
 {
 	if (hw->rss_ind_tbl_size == 0 ||
 	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_warn(hw, "the size of hash lookup table configured (%u) exceeds the maximum(%u)",
-			  hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
+			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
 		return -EINVAL;
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 02/10] net/hns3: extract common API to query device
  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   ` Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
                     ` (7 subsequent siblings)
  9 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

Extract common function to query device specifications.

Fixes: 9c740336f024 ("net/hns3: get device specifications from firmware")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_common.c    | 75 +++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_common.h    |  2 +
 drivers/net/hns3/hns3_ethdev.c    | 63 --------------------------
 drivers/net/hns3/hns3_ethdev_vf.c | 65 +--------------------------
 4 files changed, 79 insertions(+), 126 deletions(-)

diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
index 7adc6a4972..b0c7f8d62c 100644
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -10,6 +10,7 @@
 #include "hns3_logs.h"
 #include "hns3_regs.h"
 #include "hns3_rxtx.h"
+#include "hns3_dcb.h"
 #include "hns3_common.h"
 
 int
@@ -845,3 +846,77 @@ hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id)
 
 	return 0;
 }
+
+void
+hns3_set_default_dev_specifications(struct hns3_hw *hw)
+{
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+
+	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
+	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
+	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
+	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
+
+	if (hns->is_vf)
+		return;
+
+	hw->max_tm_rate = HNS3_ETHER_MAX_RATE;
+}
+
+static void
+hns3_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
+{
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+	struct hns3_dev_specs_0_cmd *req0;
+	struct hns3_dev_specs_1_cmd *req1;
+
+	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
+	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
+
+	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
+	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
+	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
+	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
+	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
+
+	if (hns->is_vf)
+		return;
+
+	hw->max_tm_rate = rte_le_to_cpu_32(req0->max_tm_rate);
+}
+
+static int
+hns3_check_dev_specifications(struct hns3_hw *hw)
+{
+	if (hw->rss_ind_tbl_size == 0 ||
+	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
+			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int
+hns3_query_dev_specifications(struct hns3_hw *hw)
+{
+	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
+	int ret;
+	int i;
+
+	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
+		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
+					  true);
+		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
+	}
+	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
+
+	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
+	if (ret)
+		return ret;
+
+	hns3_parse_dev_specifications(hw, desc);
+
+	return hns3_check_dev_specifications(hw);
+}
diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h
index 5aa001f0cc..8eaeda26e7 100644
--- a/drivers/net/hns3/hns3_common.h
+++ b/drivers/net/hns3/hns3_common.h
@@ -60,5 +60,7 @@ void hns3_unmap_rx_interrupt(struct rte_eth_dev *dev);
 int hns3_restore_rx_interrupt(struct hns3_hw *hw);
 
 int hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id);
+void hns3_set_default_dev_specifications(struct hns3_hw *hw);
+int hns3_query_dev_specifications(struct hns3_hw *hw);
 
 #endif /* HNS3_COMMON_H */
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index eb809cd8c9..ab565ce128 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2647,69 +2647,6 @@ hns3_parse_speed(int speed_cmd, uint32_t *speed)
 	return 0;
 }
 
-static void
-hns3_set_default_dev_specifications(struct hns3_hw *hw)
-{
-	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
-	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
-	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
-	hw->max_tm_rate = HNS3_ETHER_MAX_RATE;
-	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
-}
-
-static void
-hns3_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
-{
-	struct hns3_dev_specs_0_cmd *req0;
-	struct hns3_dev_specs_1_cmd *req1;
-
-	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
-	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
-
-	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
-	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
-	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
-	hw->max_tm_rate = rte_le_to_cpu_32(req0->max_tm_rate);
-	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
-	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
-}
-
-static int
-hns3_check_dev_specifications(struct hns3_hw *hw)
-{
-	if (hw->rss_ind_tbl_size == 0 ||
-	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
-			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int
-hns3_query_dev_specifications(struct hns3_hw *hw)
-{
-	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
-	int ret;
-	int i;
-
-	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
-		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
-					  true);
-		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
-	}
-	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
-
-	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
-	if (ret)
-		return ret;
-
-	hns3_parse_dev_specifications(hw, desc);
-
-	return hns3_check_dev_specifications(hw);
-}
-
 static int
 hns3_get_capability(struct hns3_hw *hw)
 {
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index e43815607a..d3c1bdf2c5 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -688,67 +688,6 @@ hns3vf_interrupt_handler(void *param)
 	hns3vf_enable_irq0(hw);
 }
 
-static void
-hns3vf_set_default_dev_specifications(struct hns3_hw *hw)
-{
-	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
-	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
-	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
-	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
-}
-
-static void
-hns3vf_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
-{
-	struct hns3_dev_specs_0_cmd *req0;
-	struct hns3_dev_specs_1_cmd *req1;
-
-	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
-	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
-
-	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
-	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
-	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
-	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
-	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
-}
-
-static int
-hns3vf_check_dev_specifications(struct hns3_hw *hw)
-{
-	if (hw->rss_ind_tbl_size == 0 ||
-	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
-			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int
-hns3vf_query_dev_specifications(struct hns3_hw *hw)
-{
-	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
-	int ret;
-	int i;
-
-	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
-		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
-					  true);
-		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
-	}
-	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
-
-	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
-	if (ret)
-		return ret;
-
-	hns3vf_parse_dev_specifications(hw, desc);
-
-	return hns3vf_check_dev_specifications(hw);
-}
-
 void
 hns3vf_update_push_lsc_cap(struct hns3_hw *hw, bool supported)
 {
@@ -826,7 +765,7 @@ hns3vf_get_capability(struct hns3_hw *hw)
 		return ret;
 
 	if (hw->revision < PCI_REVISION_ID_HIP09_A) {
-		hns3vf_set_default_dev_specifications(hw);
+		hns3_set_default_dev_specifications(hw);
 		hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
 		hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
 		hw->tso_mode = HNS3_TSO_SW_CAL_PSEUDO_H_CSUM;
@@ -837,7 +776,7 @@ hns3vf_get_capability(struct hns3_hw *hw)
 		return 0;
 	}
 
-	ret = hns3vf_query_dev_specifications(hw);
+	ret = hns3_query_dev_specifications(hw);
 	if (ret) {
 		PMD_INIT_LOG(ERR,
 			     "failed to query dev specifications, ret = %d",
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 03/10] net/hns3: refactor set RSS hash algorithm and key interface
  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   ` Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 04/10] net/hns3: fix fixed RSS key size to be more compatibility Dongdong Liu
                     ` (6 subsequent siblings)
  9 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

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


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 04/10] net/hns3: fix fixed RSS key size to be more compatibility
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (2 preceding siblings ...)
  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   ` Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
                     ` (5 subsequent siblings)
  9 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

For better compatibility, the RSS key size of PF and VF are obtained from
firmware. However, many places still used the old macro HNS3_RSS_KEY_SIZE
as the key size.

Fixes: 9c740336f024 ("net/hns3: get device specifications from firmware")
Cc: stable@dpdk.org

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    | 23 +++++++++++------------
 drivers/net/hns3/hns3_rss.h    |  3 ++-
 4 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
index b0c7f8d62c..2da0f30964 100644
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -129,7 +129,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;
@@ -895,6 +895,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 95609f8483..a18ec7650d 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1406,10 +1406,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,
@@ -1443,16 +1443,6 @@ hns3_disable_rss(struct hns3_hw *hw)
 	return 0;
 }
 
-static void
-hns3_adjust_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)
@@ -1485,9 +1475,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_adjust_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);
@@ -1495,7 +1492,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 3db7bf0445..d6e0754273 100644
--- a/drivers/net/hns3/hns3_rss.c
+++ b/drivers/net/hns3/hns3_rss.c
@@ -316,7 +316,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;
 }
 
@@ -498,9 +498,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;
 	}
 
@@ -511,7 +511,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;
 	}
@@ -547,9 +547,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);
 
@@ -754,8 +754,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++)
@@ -788,9 +788,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 b7f62ca1ee..d6f81996f4 100644
--- a/drivers/net/hns3/hns3_rss.h
+++ b/drivers/net/hns3/hns3_rss.h
@@ -29,6 +29,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
@@ -41,7 +42,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 */
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 05/10] net/hns3: fix misclearing RSS configuration
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (3 preceding siblings ...)
  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   ` Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 06/10] net/hns3: using RSS filter list to check duplicated rule Dongdong Liu
                     ` (4 subsequent siblings)
  9 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The RSS configuration will be miscleared when driver receives a RSS rule
which has more one RSS action.

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 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index a18ec7650d..c338eab049 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1421,12 +1421,10 @@ hns3_parse_rss_filter(struct rte_eth_dev *dev,
 
 	/* Check if the next not void action is END */
 	NEXT_ITEM_OF_ACTION(act, actions, act_index);
-	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
-		memset(rss_conf, 0, sizeof(struct hns3_rss_conf));
+	if (act->type != RTE_FLOW_ACTION_TYPE_END)
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_ACTION,
 					  act, "Not supported action.");
-	}
 
 	return 0;
 }
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 06/10] net/hns3: using RSS filter list to check duplicated rule
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (4 preceding siblings ...)
  2023-01-30  9:31   ` [PATCH V2 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
@ 2023-01-30  9:31   ` Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 07/10] net/hns3: remove useless code when destroy valid RSS rule Dongdong Liu
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

All rules from user are saved in RSS filter list, so use RSS
filter list to check duplicated rule.

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 | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index c338eab049..303275ae93 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1300,7 +1300,7 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 		!memcmp(comp->key, with->key, with->key_len);
 
 	return (func_is_same && rss_key_is_same &&
-		comp->types == (with->types & HNS3_ETH_RSS_SUPPORT) &&
+		comp->types == with->types &&
 		comp->level == with->level &&
 		comp->queue_num == with->queue_num &&
 		!memcmp(comp->queue, with->queue,
@@ -1596,15 +1596,7 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 	}
 
 	/* Set hash algorithm and flow types by the user's config */
-	ret = hns3_hw_rss_hash_set(hw, &rss_flow_conf);
-	if (ret)
-		return ret;
-
-	ret = hns3_rss_conf_copy(rss_info, &rss_flow_conf);
-	if (ret)
-		hns3_err(hw, "RSS config init fail(%d)", ret);
-
-	return ret;
+	return hns3_hw_rss_hash_set(hw, &rss_flow_conf);
 }
 
 static int
@@ -1676,17 +1668,32 @@ hns3_restore_filter(struct hns3_adapter *hns)
 	return hns3_restore_rss_filter(hw);
 }
 
+static bool
+hns3_rss_action_is_dup(struct hns3_hw *hw,
+		       const struct rte_flow_action_rss *act)
+{
+	struct hns3_rss_conf_ele *filter;
+
+	TAILQ_FOREACH(filter, &hw->flow_rss_list, entries) {
+		if (!filter->filter_info.valid)
+			continue;
+
+		if (hns3_action_rss_same(&filter->filter_info.conf, act))
+			return true;
+	}
+
+	return false;
+}
+
 static int
 hns3_flow_parse_rss(struct rte_eth_dev *dev,
 		    const struct hns3_rss_conf *conf, bool add)
 {
 	struct hns3_adapter *hns = dev->data->dev_private;
 	struct hns3_hw *hw = &hns->hw;
-	bool ret;
 
-	ret = hns3_action_rss_same(&hw->rss_info.conf, &conf->conf);
-	if (ret) {
-		hns3_err(hw, "Enter duplicate RSS configuration : %d", ret);
+	if (hns3_rss_action_is_dup(hw, &conf->conf)) {
+		hns3_err(hw, "duplicate RSS configuration");
 		return -EINVAL;
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 07/10] net/hns3: remove useless code when destroy valid RSS rule
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (5 preceding siblings ...)
  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   ` Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 08/10] net/hns3: fix useless warning when flush or destroy rule Dongdong Liu
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The hw::rss_info::conf::func was set to the macro RTE_ETH_HASH_FUNCTION_MAX
and hw::rss_info::conf::queue was set to NULL when all rules are flushed,
which indicates no flow rules is issued. See
commit eb158fc756a5 ("net/hns3: fix config when creating RSS rule after
flush").
Actually, the way determining whether there are rules has been changed by
walking the flow RSS list. See
commit 705a50800334 ("net/hns3: fix RSS filter restore").

In addition, the rte_flow_action_rss from user isn't saved to 'conf' in
hw->rss_info now. So this code can be removed.

Fixes: eb158fc756a5 ("net/hns3: fix config when creating RSS rule after flush")
Fixes: 705a50800334 ("net/hns3: fix RSS filter restore")
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 | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 303275ae93..7adde16cbc 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1279,19 +1279,8 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 	bool rss_key_is_same;
 	bool func_is_same;
 
-	/*
-	 * When user flush all RSS rule, RSS func is set invalid with
-	 * RTE_ETH_HASH_FUNCTION_MAX. Then the user create a flow after
-	 * flushed, any validate RSS func is different with it before
-	 * flushed. Others, when user create an action RSS with RSS func
-	 * specified RTE_ETH_HASH_FUNCTION_DEFAULT, the func is the same
-	 * between continuous RSS flow.
-	 */
-	if (comp->func == RTE_ETH_HASH_FUNCTION_MAX)
-		func_is_same = false;
-	else
-		func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
-				(comp->func == with->func) : true;
+	func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
+			(comp->func == with->func) : true;
 
 	if (with->key_len == 0 || with->key == NULL)
 		rss_key_is_same = 1;
@@ -1533,7 +1522,6 @@ static int
 hns3_config_rss_filter(struct hns3_hw *hw,
 		       const struct hns3_rss_conf *conf, bool add)
 {
-	struct hns3_rss_conf *rss_info;
 	uint64_t flow_types;
 	uint16_t num;
 	int ret;
@@ -1560,7 +1548,6 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 	/* Update the useful flow types */
 	rss_flow_conf.types = flow_types;
 
-	rss_info = &hw->rss_info;
 	if (!add) {
 		if (!conf->valid)
 			return 0;
@@ -1571,15 +1558,6 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 			return ret;
 		}
 
-		if (rss_flow_conf.queue_num) {
-			/*
-			 * Due the content of queue pointer have been reset to
-			 * 0, the rss_info->conf.queue should be set to NULL
-			 */
-			rss_info->conf.queue = NULL;
-			rss_info->conf.queue_num = 0;
-		}
-
 		return 0;
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 08/10] net/hns3: fix useless warning when flush or destroy rule
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (6 preceding siblings ...)
  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   ` Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
  2023-01-30  9:31   ` [PATCH V2 10/10] net/hns3: fix incorrect check for duplicate RSS rule Dongdong Liu
  9 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The types of the rule will no longer be used when user flush all rules or
destroy a rule. But user would receive some RSS types warnings, like,
"modified RSS types based on hardware support, requested:0x137f83fffc
configured:0x3ffc".

Fixes: ec674cb742e5 ("net/hns3: fix flushing RSS rule")
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 | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 7adde16cbc..fbc38dd3d4 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1537,17 +1537,6 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 		.queue = conf->conf.queue,
 	};
 
-	/* Filter the unsupported flow types */
-	flow_types = conf->conf.types ?
-		     rss_flow_conf.types & HNS3_ETH_RSS_SUPPORT :
-		     hw->rss_info.conf.types;
-	if (flow_types != rss_flow_conf.types)
-		hns3_warn(hw, "modified RSS types based on hardware support, "
-			      "requested:0x%" PRIx64 " configured:0x%" PRIx64,
-			  rss_flow_conf.types, flow_types);
-	/* Update the useful flow types */
-	rss_flow_conf.types = flow_types;
-
 	if (!add) {
 		if (!conf->valid)
 			return 0;
@@ -1573,6 +1562,17 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 			return ret;
 	}
 
+	/* Filter the unsupported flow types */
+	flow_types = conf->conf.types ?
+		     rss_flow_conf.types & HNS3_ETH_RSS_SUPPORT :
+		     hw->rss_info.conf.types;
+	if (flow_types != rss_flow_conf.types)
+		hns3_warn(hw, "modified RSS types based on hardware support,"
+			  " requested:0x%" PRIx64 " configured:0x%" PRIx64,
+			  rss_flow_conf.types, flow_types);
+	/* Update the useful flow types */
+	rss_flow_conf.types = flow_types;
+
 	/* Set hash algorithm and flow types by the user's config */
 	return hns3_hw_rss_hash_set(hw, &rss_flow_conf);
 }
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 09/10] net/hns3: fix bad memory structure conversion
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (7 preceding siblings ...)
  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   ` 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
  9 siblings, 1 reply; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

When the type in 'struct rte_flow_action' is RTE_FLOW_ACTION_TYPE_RSS, the
'conf' pointer references the 'struct rte_flow_action_rss' instead of the
'struct hns3_rss_conf' in driver. But driver uses 'struct hns3_rss_conf' to
convert this 'conf' pointer to get RSS action configuration.

In addition, RSS filter configuration is directly cloned to RSS filter node
instead of coping it after successfully setting to hardware.

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 | 57 +++++++++++++-----------------------
 1 file changed, 20 insertions(+), 37 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index fbc38dd3d4..307aba75a7 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -95,8 +95,8 @@ static const struct rte_flow_action *
 hns3_find_rss_general_action(const struct rte_flow_item pattern[],
 			     const struct rte_flow_action actions[])
 {
+	const struct rte_flow_action_rss *rss_act;
 	const struct rte_flow_action *act = NULL;
-	const struct hns3_rss_conf *rss;
 	bool have_eth = false;
 
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
@@ -115,8 +115,8 @@ hns3_find_rss_general_action(const struct rte_flow_item pattern[],
 		}
 	}
 
-	rss = act->conf;
-	if (have_eth && rss->conf.queue_num) {
+	rss_act = act->conf;
+	if (have_eth && rss_act->queue_num) {
 		/*
 		 * Pattern have ETH and action's queue_num > 0, indicate this is
 		 * queue region configuration.
@@ -1296,30 +1296,6 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 			sizeof(*with->queue) * with->queue_num));
 }
 
-static int
-hns3_rss_conf_copy(struct hns3_rss_conf *out,
-		   const struct rte_flow_action_rss *in)
-{
-	if (in->key_len > RTE_DIM(out->key) ||
-	    in->queue_num > RTE_DIM(out->queue))
-		return -EINVAL;
-	if (in->key == NULL && in->key_len)
-		return -EINVAL;
-	out->conf = (struct rte_flow_action_rss) {
-		.func = in->func,
-		.level = in->level,
-		.types = in->types,
-		.key_len = in->key_len,
-		.queue_num = in->queue_num,
-	};
-	out->conf.queue = memcpy(out->queue, in->queue,
-				sizeof(*in->queue) * in->queue_num);
-	if (in->key)
-		out->conf.key = memcpy(out->key, in->key, in->key_len);
-
-	return 0;
-}
-
 static bool
 hns3_rss_input_tuple_supported(struct hns3_hw *hw,
 			       const struct rte_flow_action_rss *rss)
@@ -1733,9 +1709,10 @@ hns3_flow_create_rss_rule(struct rte_eth_dev *dev,
 			  struct rte_flow *flow)
 {
 	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	const struct rte_flow_action_rss *rss_act;
 	struct hns3_rss_conf_ele *rss_filter_ptr;
 	struct hns3_rss_conf_ele *filter_ptr;
-	const struct hns3_rss_conf *rss_conf;
+	struct hns3_rss_conf *new_conf;
 	int ret;
 
 	rss_filter_ptr = rte_zmalloc("hns3 rss filter",
@@ -1745,19 +1722,25 @@ hns3_flow_create_rss_rule(struct rte_eth_dev *dev,
 		return -ENOMEM;
 	}
 
-	/*
-	 * After all the preceding tasks are successfully configured, configure
-	 * rules to the hardware to simplify the rollback of rules in the
-	 * hardware.
-	 */
-	rss_conf = (const struct hns3_rss_conf *)act->conf;
-	ret = hns3_flow_parse_rss(dev, rss_conf, true);
+	rss_act = (const struct rte_flow_action_rss *)act->conf;
+	new_conf = &rss_filter_ptr->filter_info;
+	memcpy(&new_conf->conf, rss_act, sizeof(*rss_act));
+	if (rss_act->queue_num > 0) {
+		memcpy(new_conf->queue, rss_act->queue,
+		       rss_act->queue_num * sizeof(new_conf->queue[0]));
+		new_conf->conf.queue = new_conf->queue;
+	}
+	if (rss_act->key_len > 0) {
+		memcpy(new_conf->key, rss_act->key,
+		       rss_act->key_len * sizeof(new_conf->key[0]));
+		new_conf->conf.key = new_conf->key;
+	}
+
+	ret = hns3_flow_parse_rss(dev, new_conf, true);
 	if (ret != 0) {
 		rte_free(rss_filter_ptr);
 		return ret;
 	}
-
-	hns3_rss_conf_copy(&rss_filter_ptr->filter_info, &rss_conf->conf);
 	rss_filter_ptr->filter_info.valid = true;
 
 	/*
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V2 10/10] net/hns3: fix incorrect check for duplicate RSS rule
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (8 preceding siblings ...)
  2023-01-30  9:31   ` [PATCH V2 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
@ 2023-01-30  9:31   ` Dongdong Liu
  9 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-30  9:31 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

Currently, the interface for verifying duplicate RSS rules has
some problems:
1) If the value of 'func' in configuring RSS rule is default
   value, this rule is mistakenly considered as a duplicate rule.
2) If key length is zero or 'key' is NULL in configuring RSS rule
   this rule is also mistakenly considered as a duplicate rule.
3) If 'key' or 'queue' in struct rte_flow_action_rss being NULL
   is used to memcpy, which may cause segment fault.

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 | 63 +++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 16 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 307aba75a7..8ff9d4ae66 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1272,28 +1272,59 @@ hns3_filterlist_flush(struct rte_eth_dev *dev)
 	}
 }
 
+static bool
+hns3_flow_rule_key_same(const struct rte_flow_action_rss *comp,
+			const struct rte_flow_action_rss *with)
+{
+	if (comp->key_len != with->key_len)
+		return false;
+
+	if (with->key_len == 0)
+		return true;
+
+	if (comp->key == NULL && with->key == NULL)
+		return true;
+
+	if (!(comp->key != NULL && with->key != NULL))
+		return false;
+
+	return !memcmp(comp->key, with->key, with->key_len);
+}
+
+static bool
+hns3_flow_rule_queues_same(const struct rte_flow_action_rss *comp,
+			   const struct rte_flow_action_rss *with)
+{
+	if (comp->queue_num != with->queue_num)
+		return false;
+
+	if (with->queue_num == 0)
+		return true;
+
+	if (comp->queue == NULL && with->queue == NULL)
+		return true;
+
+	if (!(comp->queue != NULL && with->queue != NULL))
+		return false;
+
+	return !memcmp(comp->queue, with->queue, with->queue_num);
+}
+
 static bool
 hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 		     const struct rte_flow_action_rss *with)
 {
-	bool rss_key_is_same;
-	bool func_is_same;
+	bool same_level;
+	bool same_types;
+	bool same_func;
 
-	func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
-			(comp->func == with->func) : true;
+	same_level = (comp->level == with->level);
+	same_types = (comp->types == with->types);
+	same_func = (comp->func == with->func);
 
-	if (with->key_len == 0 || with->key == NULL)
-		rss_key_is_same = 1;
-	else
-		rss_key_is_same = comp->key_len == with->key_len &&
-		!memcmp(comp->key, with->key, with->key_len);
-
-	return (func_is_same && rss_key_is_same &&
-		comp->types == with->types &&
-		comp->level == with->level &&
-		comp->queue_num == with->queue_num &&
-		!memcmp(comp->queue, with->queue,
-			sizeof(*with->queue) * with->queue_num));
+	return same_level && same_types && same_func &&
+		hns3_flow_rule_key_same(comp, with) &&
+		hns3_flow_rule_queues_same(comp, with);
 }
 
 static bool
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH V2 09/10] net/hns3: fix bad memory structure conversion
  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
  0 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31  9:34 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko, lihuisong
  Cc: stable, yisen.zhuang



On 2023/1/30 17:31, Dongdong Liu wrote:
> From: Huisong Li <lihuisong@huawei.com>
>
> When the type in 'struct rte_flow_action' is RTE_FLOW_ACTION_TYPE_RSS, the
> 'conf' pointer references the 'struct rte_flow_action_rss' instead of the
> 'struct hns3_rss_conf' in driver. But driver uses 'struct hns3_rss_conf' to
> convert this 'conf' pointer to get RSS action configuration.
>
> In addition, RSS filter configuration is directly cloned to RSS filter node
> instead of coping it after successfully setting to hardware.
>
> 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 | 57 +++++++++++++-----------------------
>  1 file changed, 20 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
> index fbc38dd3d4..307aba75a7 100644
> --- a/drivers/net/hns3/hns3_flow.c
> +++ b/drivers/net/hns3/hns3_flow.c
> @@ -95,8 +95,8 @@ static const struct rte_flow_action *
>  hns3_find_rss_general_action(const struct rte_flow_item pattern[],
>  			     const struct rte_flow_action actions[])
>  {
> +	const struct rte_flow_action_rss *rss_act;
>  	const struct rte_flow_action *act = NULL;
> -	const struct hns3_rss_conf *rss;
>  	bool have_eth = false;
>
>  	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
> @@ -115,8 +115,8 @@ hns3_find_rss_general_action(const struct rte_flow_item pattern[],
>  		}
>  	}
>
> -	rss = act->conf;
> -	if (have_eth && rss->conf.queue_num) {
> +	rss_act = act->conf;
> +	if (have_eth && rss_act->queue_num) {
>  		/*
>  		 * Pattern have ETH and action's queue_num > 0, indicate this is
>  		 * queue region configuration.
> @@ -1296,30 +1296,6 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
>  			sizeof(*with->queue) * with->queue_num));
>  }
>
> -static int
> -hns3_rss_conf_copy(struct hns3_rss_conf *out,
> -		   const struct rte_flow_action_rss *in)
> -{
> -	if (in->key_len > RTE_DIM(out->key) ||
> -	    in->queue_num > RTE_DIM(out->queue))
> -		return -EINVAL;
> -	if (in->key == NULL && in->key_len)
> -		return -EINVAL;
> -	out->conf = (struct rte_flow_action_rss) {
> -		.func = in->func,
> -		.level = in->level,
> -		.types = in->types,
> -		.key_len = in->key_len,
> -		.queue_num = in->queue_num,
> -	};
> -	out->conf.queue = memcpy(out->queue, in->queue,
> -				sizeof(*in->queue) * in->queue_num);
> -	if (in->key)
> -		out->conf.key = memcpy(out->key, in->key, in->key_len);
> -
> -	return 0;
> -}
> -
>  static bool
>  hns3_rss_input_tuple_supported(struct hns3_hw *hw,
>  			       const struct rte_flow_action_rss *rss)
> @@ -1733,9 +1709,10 @@ hns3_flow_create_rss_rule(struct rte_eth_dev *dev,
>  			  struct rte_flow *flow)
>  {
>  	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> +	const struct rte_flow_action_rss *rss_act;
>  	struct hns3_rss_conf_ele *rss_filter_ptr;
>  	struct hns3_rss_conf_ele *filter_ptr;
> -	const struct hns3_rss_conf *rss_conf;
> +	struct hns3_rss_conf *new_conf;
>  	int ret;
>
>  	rss_filter_ptr = rte_zmalloc("hns3 rss filter",
> @@ -1745,19 +1722,25 @@ hns3_flow_create_rss_rule(struct rte_eth_dev *dev,
>  		return -ENOMEM;
>  	}
>
> -	/*
> -	 * After all the preceding tasks are successfully configured, configure
> -	 * rules to the hardware to simplify the rollback of rules in the
> -	 * hardware.
> -	 */
> -	rss_conf = (const struct hns3_rss_conf *)act->conf;
> -	ret = hns3_flow_parse_rss(dev, rss_conf, true);
> +	rss_act = (const struct rte_flow_action_rss *)act->conf;
> +	new_conf = &rss_filter_ptr->filter_info;
> +	memcpy(&new_conf->conf, rss_act, sizeof(*rss_act));
> +	if (rss_act->queue_num > 0) {
> +		memcpy(new_conf->queue, rss_act->queue,
> +		       rss_act->queue_num * sizeof(new_conf->queue[0]));
> +		new_conf->conf.queue = new_conf->queue;
> +	}
> +	if (rss_act->key_len > 0) {

When do the below test, Segmentation fault occurred.
testpmd> flow create 0 ingress pattern end actions rss key_len 40 / end
Segmentation fault (core dumped)

It should make sure new_conf->key is not NULL before doing memcpy.
Will fix this in V3.

Thanks,
Dongdong
> +		memcpy(new_conf->key, rss_act->key,
> +		       rss_act->key_len * sizeof(new_conf->key[0]));
> +		new_conf->conf.key = new_conf->key;
> +	}
> +
> +	ret = hns3_flow_parse_rss(dev, new_conf, true);
>  	if (ret != 0) {
>  		rte_free(rss_filter_ptr);
>  		return ret;
>  	}
> -
> -	hns3_rss_conf_copy(&rss_filter_ptr->filter_info, &rss_conf->conf);
>  	rss_filter_ptr->filter_info.valid = true;
>
>  	/*
>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH V3 00/10] net/hns3: some bugfixes for rss
  2023-01-29 10:51 [PATCH 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                   ` (10 preceding siblings ...)
  2023-01-30  9:31 ` [PATCH V2 00/10] net/hns3: some bugfixes for rss Dongdong Liu
@ 2023-01-31 13:02 ` Dongdong Liu
  2023-01-31 13:02   ` [PATCH V3 01/10] net/hns3: fix error log about indirection table size Dongdong Liu
                     ` (10 more replies)
  11 siblings, 11 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

This patchset is to do some bugfixes for hns3 rss.

v2->v3:
- Fix segmentation fault when key_len is 40 and key is NULL for
  [PATCH V2 09/10].

v1->v2:
- Fix missing comparison of types and level when verifying duplicate
  rules for [PATCH 10/10].

Huisong Li (10):
  net/hns3: fix error log about indirection table size
  net/hns3: extract common API to query device
  net/hns3: refactor set RSS hash algorithm and key interface
  net/hns3: fix fixed RSS key size to be more compatibility
  net/hns3: fix misclearing RSS configuration
  net/hns3: using RSS filter list to check duplicated rule
  net/hns3: remove useless code when destroy valid RSS rule
  net/hns3: fix useless warning when flush or destroy rule
  net/hns3: fix bad memory structure conversion
  net/hns3: fix incorrect check for duplicate RSS rule

 drivers/net/hns3/hns3_common.c    |  87 +++++++++++-
 drivers/net/hns3/hns3_common.h    |   2 +
 drivers/net/hns3/hns3_ethdev.c    |  63 ---------
 drivers/net/hns3/hns3_ethdev_vf.c |  65 +--------
 drivers/net/hns3/hns3_flow.c      | 224 +++++++++++++++---------------
 drivers/net/hns3/hns3_rss.c       |  63 ++++-----
 drivers/net/hns3/hns3_rss.h       |   7 +-
 7 files changed, 234 insertions(+), 277 deletions(-)

--
2.22.0


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH V3 01/10] net/hns3: fix error log about indirection table size
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
@ 2023-01-31 13:02   ` Dongdong Liu
  2023-01-31 13:02   ` [PATCH V3 02/10] net/hns3: extract common API to query device Dongdong Liu
                     ` (9 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The error log about indirection table size during initialization phase
of PF and VF is unreasonable when the indirection table size obtained
from firmware or PF function should be zero. In addition, VF driver
should use error level to print this log.

Fixes: 0fce2c46dc16 ("net/hns3: fix RSS indirection table size")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c    | 2 +-
 drivers/net/hns3/hns3_ethdev_vf.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index d326f70129..eb809cd8c9 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2679,7 +2679,7 @@ hns3_check_dev_specifications(struct hns3_hw *hw)
 {
 	if (hw->rss_ind_tbl_size == 0 ||
 	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the size of hash lookup table configured (%u) exceeds the maximum(%u)",
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
 			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
 		return -EINVAL;
 	}
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index d220522c43..e43815607a 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -718,8 +718,8 @@ hns3vf_check_dev_specifications(struct hns3_hw *hw)
 {
 	if (hw->rss_ind_tbl_size == 0 ||
 	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_warn(hw, "the size of hash lookup table configured (%u) exceeds the maximum(%u)",
-			  hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
+			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
 		return -EINVAL;
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V3 02/10] net/hns3: extract common API to query device
  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   ` Dongdong Liu
  2023-01-31 13:02   ` [PATCH V3 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
                     ` (8 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

Extract common function to query device specifications.

Fixes: 9c740336f024 ("net/hns3: get device specifications from firmware")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 drivers/net/hns3/hns3_common.c    | 75 +++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_common.h    |  2 +
 drivers/net/hns3/hns3_ethdev.c    | 63 --------------------------
 drivers/net/hns3/hns3_ethdev_vf.c | 65 +--------------------------
 4 files changed, 79 insertions(+), 126 deletions(-)

diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
index 7adc6a4972..b0c7f8d62c 100644
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -10,6 +10,7 @@
 #include "hns3_logs.h"
 #include "hns3_regs.h"
 #include "hns3_rxtx.h"
+#include "hns3_dcb.h"
 #include "hns3_common.h"
 
 int
@@ -845,3 +846,77 @@ hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id)
 
 	return 0;
 }
+
+void
+hns3_set_default_dev_specifications(struct hns3_hw *hw)
+{
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+
+	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
+	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
+	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
+	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
+
+	if (hns->is_vf)
+		return;
+
+	hw->max_tm_rate = HNS3_ETHER_MAX_RATE;
+}
+
+static void
+hns3_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
+{
+	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+	struct hns3_dev_specs_0_cmd *req0;
+	struct hns3_dev_specs_1_cmd *req1;
+
+	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
+	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
+
+	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
+	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
+	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
+	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
+	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
+
+	if (hns->is_vf)
+		return;
+
+	hw->max_tm_rate = rte_le_to_cpu_32(req0->max_tm_rate);
+}
+
+static int
+hns3_check_dev_specifications(struct hns3_hw *hw)
+{
+	if (hw->rss_ind_tbl_size == 0 ||
+	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
+		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
+			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int
+hns3_query_dev_specifications(struct hns3_hw *hw)
+{
+	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
+	int ret;
+	int i;
+
+	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
+		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
+					  true);
+		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
+	}
+	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
+
+	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
+	if (ret)
+		return ret;
+
+	hns3_parse_dev_specifications(hw, desc);
+
+	return hns3_check_dev_specifications(hw);
+}
diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h
index 5aa001f0cc..8eaeda26e7 100644
--- a/drivers/net/hns3/hns3_common.h
+++ b/drivers/net/hns3/hns3_common.h
@@ -60,5 +60,7 @@ void hns3_unmap_rx_interrupt(struct rte_eth_dev *dev);
 int hns3_restore_rx_interrupt(struct hns3_hw *hw);
 
 int hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id);
+void hns3_set_default_dev_specifications(struct hns3_hw *hw);
+int hns3_query_dev_specifications(struct hns3_hw *hw);
 
 #endif /* HNS3_COMMON_H */
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index eb809cd8c9..ab565ce128 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2647,69 +2647,6 @@ hns3_parse_speed(int speed_cmd, uint32_t *speed)
 	return 0;
 }
 
-static void
-hns3_set_default_dev_specifications(struct hns3_hw *hw)
-{
-	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
-	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
-	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
-	hw->max_tm_rate = HNS3_ETHER_MAX_RATE;
-	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
-}
-
-static void
-hns3_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
-{
-	struct hns3_dev_specs_0_cmd *req0;
-	struct hns3_dev_specs_1_cmd *req1;
-
-	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
-	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
-
-	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
-	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
-	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
-	hw->max_tm_rate = rte_le_to_cpu_32(req0->max_tm_rate);
-	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
-	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
-}
-
-static int
-hns3_check_dev_specifications(struct hns3_hw *hw)
-{
-	if (hw->rss_ind_tbl_size == 0 ||
-	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
-			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int
-hns3_query_dev_specifications(struct hns3_hw *hw)
-{
-	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
-	int ret;
-	int i;
-
-	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
-		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
-					  true);
-		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
-	}
-	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
-
-	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
-	if (ret)
-		return ret;
-
-	hns3_parse_dev_specifications(hw, desc);
-
-	return hns3_check_dev_specifications(hw);
-}
-
 static int
 hns3_get_capability(struct hns3_hw *hw)
 {
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index e43815607a..d3c1bdf2c5 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -688,67 +688,6 @@ hns3vf_interrupt_handler(void *param)
 	hns3vf_enable_irq0(hw);
 }
 
-static void
-hns3vf_set_default_dev_specifications(struct hns3_hw *hw)
-{
-	hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
-	hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
-	hw->rss_key_size = HNS3_RSS_KEY_SIZE;
-	hw->intr.int_ql_max = HNS3_INTR_QL_NONE;
-}
-
-static void
-hns3vf_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
-{
-	struct hns3_dev_specs_0_cmd *req0;
-	struct hns3_dev_specs_1_cmd *req1;
-
-	req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
-	req1 = (struct hns3_dev_specs_1_cmd *)desc[1].data;
-
-	hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
-	hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
-	hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
-	hw->intr.int_ql_max = rte_le_to_cpu_16(req0->intr_ql_max);
-	hw->min_tx_pkt_len = req1->min_tx_pkt_len;
-}
-
-static int
-hns3vf_check_dev_specifications(struct hns3_hw *hw)
-{
-	if (hw->rss_ind_tbl_size == 0 ||
-	    hw->rss_ind_tbl_size > HNS3_RSS_IND_TBL_SIZE_MAX) {
-		hns3_err(hw, "the indirection table size obtained (%u) is invalid, and should not be zero or exceed the maximum(%u)",
-			 hw->rss_ind_tbl_size, HNS3_RSS_IND_TBL_SIZE_MAX);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int
-hns3vf_query_dev_specifications(struct hns3_hw *hw)
-{
-	struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
-	int ret;
-	int i;
-
-	for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
-		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
-					  true);
-		desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
-	}
-	hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
-
-	ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
-	if (ret)
-		return ret;
-
-	hns3vf_parse_dev_specifications(hw, desc);
-
-	return hns3vf_check_dev_specifications(hw);
-}
-
 void
 hns3vf_update_push_lsc_cap(struct hns3_hw *hw, bool supported)
 {
@@ -826,7 +765,7 @@ hns3vf_get_capability(struct hns3_hw *hw)
 		return ret;
 
 	if (hw->revision < PCI_REVISION_ID_HIP09_A) {
-		hns3vf_set_default_dev_specifications(hw);
+		hns3_set_default_dev_specifications(hw);
 		hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
 		hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
 		hw->tso_mode = HNS3_TSO_SW_CAL_PSEUDO_H_CSUM;
@@ -837,7 +776,7 @@ hns3vf_get_capability(struct hns3_hw *hw)
 		return 0;
 	}
 
-	ret = hns3vf_query_dev_specifications(hw);
+	ret = hns3_query_dev_specifications(hw);
 	if (ret) {
 		PMD_INIT_LOG(ERR,
 			     "failed to query dev specifications, ret = %d",
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V3 03/10] net/hns3: refactor set RSS hash algorithm and key interface
  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
  2023-01-31 13:02   ` [PATCH V3 04/10] net/hns3: fix fixed RSS key size to be more compatibility Dongdong Liu
                     ` (7 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

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


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V3 04/10] net/hns3: fix fixed RSS key size to be more compatibility
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (2 preceding siblings ...)
  2023-01-31 13:02   ` [PATCH V3 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
@ 2023-01-31 13:02   ` Dongdong Liu
  2023-01-31 13:02   ` [PATCH V3 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
                     ` (6 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

For better compatibility, the RSS key size of PF and VF are obtained from
firmware. However, many places still used the old macro HNS3_RSS_KEY_SIZE
as the key size.

Fixes: 9c740336f024 ("net/hns3: get device specifications from firmware")
Cc: stable@dpdk.org

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    | 23 +++++++++++------------
 drivers/net/hns3/hns3_rss.h    |  3 ++-
 4 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
index b0c7f8d62c..2da0f30964 100644
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -129,7 +129,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;
@@ -895,6 +895,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 95609f8483..a18ec7650d 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1406,10 +1406,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,
@@ -1443,16 +1443,6 @@ hns3_disable_rss(struct hns3_hw *hw)
 	return 0;
 }
 
-static void
-hns3_adjust_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)
@@ -1485,9 +1475,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_adjust_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);
@@ -1495,7 +1492,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 3db7bf0445..d6e0754273 100644
--- a/drivers/net/hns3/hns3_rss.c
+++ b/drivers/net/hns3/hns3_rss.c
@@ -316,7 +316,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;
 }
 
@@ -498,9 +498,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;
 	}
 
@@ -511,7 +511,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;
 	}
@@ -547,9 +547,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);
 
@@ -754,8 +754,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++)
@@ -788,9 +788,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 b7f62ca1ee..d6f81996f4 100644
--- a/drivers/net/hns3/hns3_rss.h
+++ b/drivers/net/hns3/hns3_rss.h
@@ -29,6 +29,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
@@ -41,7 +42,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 */
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V3 05/10] net/hns3: fix misclearing RSS configuration
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (3 preceding siblings ...)
  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   ` Dongdong Liu
  2023-01-31 13:02   ` [PATCH V3 06/10] net/hns3: using RSS filter list to check duplicated rule Dongdong Liu
                     ` (5 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The RSS configuration will be miscleared when driver receives a RSS rule
which has more one RSS action.

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 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index a18ec7650d..c338eab049 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1421,12 +1421,10 @@ hns3_parse_rss_filter(struct rte_eth_dev *dev,
 
 	/* Check if the next not void action is END */
 	NEXT_ITEM_OF_ACTION(act, actions, act_index);
-	if (act->type != RTE_FLOW_ACTION_TYPE_END) {
-		memset(rss_conf, 0, sizeof(struct hns3_rss_conf));
+	if (act->type != RTE_FLOW_ACTION_TYPE_END)
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_ACTION,
 					  act, "Not supported action.");
-	}
 
 	return 0;
 }
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V3 06/10] net/hns3: using RSS filter list to check duplicated rule
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (4 preceding siblings ...)
  2023-01-31 13:02   ` [PATCH V3 05/10] net/hns3: fix misclearing RSS configuration Dongdong Liu
@ 2023-01-31 13:02   ` Dongdong Liu
  2023-01-31 13:02   ` [PATCH V3 07/10] net/hns3: remove useless code when destroy valid RSS rule Dongdong Liu
                     ` (4 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

All rules from user are saved in RSS filter list, so use RSS
filter list to check duplicated rule.

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 | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index c338eab049..303275ae93 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1300,7 +1300,7 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 		!memcmp(comp->key, with->key, with->key_len);
 
 	return (func_is_same && rss_key_is_same &&
-		comp->types == (with->types & HNS3_ETH_RSS_SUPPORT) &&
+		comp->types == with->types &&
 		comp->level == with->level &&
 		comp->queue_num == with->queue_num &&
 		!memcmp(comp->queue, with->queue,
@@ -1596,15 +1596,7 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 	}
 
 	/* Set hash algorithm and flow types by the user's config */
-	ret = hns3_hw_rss_hash_set(hw, &rss_flow_conf);
-	if (ret)
-		return ret;
-
-	ret = hns3_rss_conf_copy(rss_info, &rss_flow_conf);
-	if (ret)
-		hns3_err(hw, "RSS config init fail(%d)", ret);
-
-	return ret;
+	return hns3_hw_rss_hash_set(hw, &rss_flow_conf);
 }
 
 static int
@@ -1676,17 +1668,32 @@ hns3_restore_filter(struct hns3_adapter *hns)
 	return hns3_restore_rss_filter(hw);
 }
 
+static bool
+hns3_rss_action_is_dup(struct hns3_hw *hw,
+		       const struct rte_flow_action_rss *act)
+{
+	struct hns3_rss_conf_ele *filter;
+
+	TAILQ_FOREACH(filter, &hw->flow_rss_list, entries) {
+		if (!filter->filter_info.valid)
+			continue;
+
+		if (hns3_action_rss_same(&filter->filter_info.conf, act))
+			return true;
+	}
+
+	return false;
+}
+
 static int
 hns3_flow_parse_rss(struct rte_eth_dev *dev,
 		    const struct hns3_rss_conf *conf, bool add)
 {
 	struct hns3_adapter *hns = dev->data->dev_private;
 	struct hns3_hw *hw = &hns->hw;
-	bool ret;
 
-	ret = hns3_action_rss_same(&hw->rss_info.conf, &conf->conf);
-	if (ret) {
-		hns3_err(hw, "Enter duplicate RSS configuration : %d", ret);
+	if (hns3_rss_action_is_dup(hw, &conf->conf)) {
+		hns3_err(hw, "duplicate RSS configuration");
 		return -EINVAL;
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V3 07/10] net/hns3: remove useless code when destroy valid RSS rule
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (5 preceding siblings ...)
  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   ` Dongdong Liu
  2023-01-31 13:02   ` [PATCH V3 08/10] net/hns3: fix useless warning when flush or destroy rule Dongdong Liu
                     ` (3 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The hw::rss_info::conf::func was set to the macro RTE_ETH_HASH_FUNCTION_MAX
and hw::rss_info::conf::queue was set to NULL when all rules are flushed,
which indicates no flow rules is issued. See
commit eb158fc756a5 ("net/hns3: fix config when creating RSS rule after
flush").
Actually, the way determining whether there are rules has been changed by
walking the flow RSS list. See
commit 705a50800334 ("net/hns3: fix RSS filter restore").

In addition, the rte_flow_action_rss from user isn't saved to 'conf' in
hw->rss_info now. So this code can be removed.

Fixes: eb158fc756a5 ("net/hns3: fix config when creating RSS rule after flush")
Fixes: 705a50800334 ("net/hns3: fix RSS filter restore")
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 | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 303275ae93..7adde16cbc 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1279,19 +1279,8 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 	bool rss_key_is_same;
 	bool func_is_same;
 
-	/*
-	 * When user flush all RSS rule, RSS func is set invalid with
-	 * RTE_ETH_HASH_FUNCTION_MAX. Then the user create a flow after
-	 * flushed, any validate RSS func is different with it before
-	 * flushed. Others, when user create an action RSS with RSS func
-	 * specified RTE_ETH_HASH_FUNCTION_DEFAULT, the func is the same
-	 * between continuous RSS flow.
-	 */
-	if (comp->func == RTE_ETH_HASH_FUNCTION_MAX)
-		func_is_same = false;
-	else
-		func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
-				(comp->func == with->func) : true;
+	func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
+			(comp->func == with->func) : true;
 
 	if (with->key_len == 0 || with->key == NULL)
 		rss_key_is_same = 1;
@@ -1533,7 +1522,6 @@ static int
 hns3_config_rss_filter(struct hns3_hw *hw,
 		       const struct hns3_rss_conf *conf, bool add)
 {
-	struct hns3_rss_conf *rss_info;
 	uint64_t flow_types;
 	uint16_t num;
 	int ret;
@@ -1560,7 +1548,6 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 	/* Update the useful flow types */
 	rss_flow_conf.types = flow_types;
 
-	rss_info = &hw->rss_info;
 	if (!add) {
 		if (!conf->valid)
 			return 0;
@@ -1571,15 +1558,6 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 			return ret;
 		}
 
-		if (rss_flow_conf.queue_num) {
-			/*
-			 * Due the content of queue pointer have been reset to
-			 * 0, the rss_info->conf.queue should be set to NULL
-			 */
-			rss_info->conf.queue = NULL;
-			rss_info->conf.queue_num = 0;
-		}
-
 		return 0;
 	}
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V3 08/10] net/hns3: fix useless warning when flush or destroy rule
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (6 preceding siblings ...)
  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   ` Dongdong Liu
  2023-01-31 13:02   ` [PATCH V3 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
                     ` (2 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

The types of the rule will no longer be used when user flush all rules or
destroy a rule. But user would receive some RSS types warnings, like,
"modified RSS types based on hardware support, requested:0x137f83fffc
configured:0x3ffc".

Fixes: ec674cb742e5 ("net/hns3: fix flushing RSS rule")
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 | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 7adde16cbc..fbc38dd3d4 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1537,17 +1537,6 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 		.queue = conf->conf.queue,
 	};
 
-	/* Filter the unsupported flow types */
-	flow_types = conf->conf.types ?
-		     rss_flow_conf.types & HNS3_ETH_RSS_SUPPORT :
-		     hw->rss_info.conf.types;
-	if (flow_types != rss_flow_conf.types)
-		hns3_warn(hw, "modified RSS types based on hardware support, "
-			      "requested:0x%" PRIx64 " configured:0x%" PRIx64,
-			  rss_flow_conf.types, flow_types);
-	/* Update the useful flow types */
-	rss_flow_conf.types = flow_types;
-
 	if (!add) {
 		if (!conf->valid)
 			return 0;
@@ -1573,6 +1562,17 @@ hns3_config_rss_filter(struct hns3_hw *hw,
 			return ret;
 	}
 
+	/* Filter the unsupported flow types */
+	flow_types = conf->conf.types ?
+		     rss_flow_conf.types & HNS3_ETH_RSS_SUPPORT :
+		     hw->rss_info.conf.types;
+	if (flow_types != rss_flow_conf.types)
+		hns3_warn(hw, "modified RSS types based on hardware support,"
+			  " requested:0x%" PRIx64 " configured:0x%" PRIx64,
+			  rss_flow_conf.types, flow_types);
+	/* Update the useful flow types */
+	rss_flow_conf.types = flow_types;
+
 	/* Set hash algorithm and flow types by the user's config */
 	return hns3_hw_rss_hash_set(hw, &rss_flow_conf);
 }
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V3 09/10] net/hns3: fix bad memory structure conversion
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (7 preceding siblings ...)
  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   ` 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
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:02 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

When the type in 'struct rte_flow_action' is RTE_FLOW_ACTION_TYPE_RSS, the
'conf' pointer references the 'struct rte_flow_action_rss' instead of the
'struct hns3_rss_conf' in driver. But driver uses 'struct hns3_rss_conf' to
convert this 'conf' pointer to get RSS action configuration.

In addition, RSS filter configuration is directly cloned to RSS filter node
instead of coping it after successfully setting to hardware.

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 | 59 ++++++++++++++----------------------
 1 file changed, 22 insertions(+), 37 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index fbc38dd3d4..a30b19cfdb 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -95,8 +95,8 @@ static const struct rte_flow_action *
 hns3_find_rss_general_action(const struct rte_flow_item pattern[],
 			     const struct rte_flow_action actions[])
 {
+	const struct rte_flow_action_rss *rss_act;
 	const struct rte_flow_action *act = NULL;
-	const struct hns3_rss_conf *rss;
 	bool have_eth = false;
 
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
@@ -115,8 +115,8 @@ hns3_find_rss_general_action(const struct rte_flow_item pattern[],
 		}
 	}
 
-	rss = act->conf;
-	if (have_eth && rss->conf.queue_num) {
+	rss_act = act->conf;
+	if (have_eth && rss_act->queue_num) {
 		/*
 		 * Pattern have ETH and action's queue_num > 0, indicate this is
 		 * queue region configuration.
@@ -1296,30 +1296,6 @@ hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 			sizeof(*with->queue) * with->queue_num));
 }
 
-static int
-hns3_rss_conf_copy(struct hns3_rss_conf *out,
-		   const struct rte_flow_action_rss *in)
-{
-	if (in->key_len > RTE_DIM(out->key) ||
-	    in->queue_num > RTE_DIM(out->queue))
-		return -EINVAL;
-	if (in->key == NULL && in->key_len)
-		return -EINVAL;
-	out->conf = (struct rte_flow_action_rss) {
-		.func = in->func,
-		.level = in->level,
-		.types = in->types,
-		.key_len = in->key_len,
-		.queue_num = in->queue_num,
-	};
-	out->conf.queue = memcpy(out->queue, in->queue,
-				sizeof(*in->queue) * in->queue_num);
-	if (in->key)
-		out->conf.key = memcpy(out->key, in->key, in->key_len);
-
-	return 0;
-}
-
 static bool
 hns3_rss_input_tuple_supported(struct hns3_hw *hw,
 			       const struct rte_flow_action_rss *rss)
@@ -1733,9 +1709,10 @@ hns3_flow_create_rss_rule(struct rte_eth_dev *dev,
 			  struct rte_flow *flow)
 {
 	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	const struct rte_flow_action_rss *rss_act;
 	struct hns3_rss_conf_ele *rss_filter_ptr;
 	struct hns3_rss_conf_ele *filter_ptr;
-	const struct hns3_rss_conf *rss_conf;
+	struct hns3_rss_conf *new_conf;
 	int ret;
 
 	rss_filter_ptr = rte_zmalloc("hns3 rss filter",
@@ -1745,19 +1722,27 @@ hns3_flow_create_rss_rule(struct rte_eth_dev *dev,
 		return -ENOMEM;
 	}
 
-	/*
-	 * After all the preceding tasks are successfully configured, configure
-	 * rules to the hardware to simplify the rollback of rules in the
-	 * hardware.
-	 */
-	rss_conf = (const struct hns3_rss_conf *)act->conf;
-	ret = hns3_flow_parse_rss(dev, rss_conf, true);
+	rss_act = (const struct rte_flow_action_rss *)act->conf;
+	new_conf = &rss_filter_ptr->filter_info;
+	memcpy(&new_conf->conf, rss_act, sizeof(*rss_act));
+	if (rss_act->queue_num > 0) {
+		memcpy(new_conf->queue, rss_act->queue,
+		       rss_act->queue_num * sizeof(new_conf->queue[0]));
+		new_conf->conf.queue = new_conf->queue;
+	}
+	if (rss_act->key_len > 0) {
+		if (rss_act->key != NULL) {
+			memcpy(new_conf->key, rss_act->key,
+			       rss_act->key_len * sizeof(new_conf->key[0]));
+			new_conf->conf.key = new_conf->key;
+		}
+	}
+
+	ret = hns3_flow_parse_rss(dev, new_conf, true);
 	if (ret != 0) {
 		rte_free(rss_filter_ptr);
 		return ret;
 	}
-
-	hns3_rss_conf_copy(&rss_filter_ptr->filter_info, &rss_conf->conf);
 	rss_filter_ptr->filter_info.valid = true;
 
 	/*
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH V3 10/10] net/hns3: fix incorrect check for duplicate RSS rule
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (8 preceding siblings ...)
  2023-01-31 13:02   ` [PATCH V3 09/10] net/hns3: fix bad memory structure conversion Dongdong Liu
@ 2023-01-31 13:03   ` Dongdong Liu
  2023-02-08 17:46   ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Ferruh Yigit
  10 siblings, 0 replies; 35+ messages in thread
From: Dongdong Liu @ 2023-01-31 13:03 UTC (permalink / raw)
  To: dev, ferruh.yigit, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, liudongdong3, lihuisong

From: Huisong Li <lihuisong@huawei.com>

Currently, the interface for verifying duplicate RSS rules has
some problems:
1) If the value of 'func' in configuring RSS rule is default
   value, this rule is mistakenly considered as a duplicate rule.
2) If key length is zero or 'key' is NULL in configuring RSS rule
   this rule is also mistakenly considered as a duplicate rule.
3) If 'key' or 'queue' in struct rte_flow_action_rss being NULL
   is used to memcpy, which may cause segment fault.

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 | 63 +++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 16 deletions(-)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index a30b19cfdb..e80ec0f053 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1272,28 +1272,59 @@ hns3_filterlist_flush(struct rte_eth_dev *dev)
 	}
 }
 
+static bool
+hns3_flow_rule_key_same(const struct rte_flow_action_rss *comp,
+			const struct rte_flow_action_rss *with)
+{
+	if (comp->key_len != with->key_len)
+		return false;
+
+	if (with->key_len == 0)
+		return true;
+
+	if (comp->key == NULL && with->key == NULL)
+		return true;
+
+	if (!(comp->key != NULL && with->key != NULL))
+		return false;
+
+	return !memcmp(comp->key, with->key, with->key_len);
+}
+
+static bool
+hns3_flow_rule_queues_same(const struct rte_flow_action_rss *comp,
+			   const struct rte_flow_action_rss *with)
+{
+	if (comp->queue_num != with->queue_num)
+		return false;
+
+	if (with->queue_num == 0)
+		return true;
+
+	if (comp->queue == NULL && with->queue == NULL)
+		return true;
+
+	if (!(comp->queue != NULL && with->queue != NULL))
+		return false;
+
+	return !memcmp(comp->queue, with->queue, with->queue_num);
+}
+
 static bool
 hns3_action_rss_same(const struct rte_flow_action_rss *comp,
 		     const struct rte_flow_action_rss *with)
 {
-	bool rss_key_is_same;
-	bool func_is_same;
+	bool same_level;
+	bool same_types;
+	bool same_func;
 
-	func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
-			(comp->func == with->func) : true;
+	same_level = (comp->level == with->level);
+	same_types = (comp->types == with->types);
+	same_func = (comp->func == with->func);
 
-	if (with->key_len == 0 || with->key == NULL)
-		rss_key_is_same = 1;
-	else
-		rss_key_is_same = comp->key_len == with->key_len &&
-		!memcmp(comp->key, with->key, with->key_len);
-
-	return (func_is_same && rss_key_is_same &&
-		comp->types == with->types &&
-		comp->level == with->level &&
-		comp->queue_num == with->queue_num &&
-		!memcmp(comp->queue, with->queue,
-			sizeof(*with->queue) * with->queue_num));
+	return same_level && same_types && same_func &&
+		hns3_flow_rule_key_same(comp, with) &&
+		hns3_flow_rule_queues_same(comp, with);
 }
 
 static bool
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH V3 00/10] net/hns3: some bugfixes for rss
  2023-01-31 13:02 ` [PATCH V3 00/10] net/hns3: some bugfixes for rss Dongdong Liu
                     ` (9 preceding siblings ...)
  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   ` Ferruh Yigit
  10 siblings, 0 replies; 35+ messages in thread
From: Ferruh Yigit @ 2023-02-08 17:46 UTC (permalink / raw)
  To: Dongdong Liu, dev, thomas, andrew.rybchenko
  Cc: stable, yisen.zhuang, lihuisong

On 1/31/2023 1:02 PM, Dongdong Liu wrote:
> This patchset is to do some bugfixes for hns3 rss.
> 
> v2->v3:
> - Fix segmentation fault when key_len is 40 and key is NULL for
>   [PATCH V2 09/10].
> 
> v1->v2:
> - Fix missing comparison of types and level when verifying duplicate
>   rules for [PATCH 10/10].
> 
> Huisong Li (10):
>   net/hns3: fix error log about indirection table size
>   net/hns3: extract common API to query device
>   net/hns3: refactor set RSS hash algorithm and key interface
>   net/hns3: fix fixed RSS key size to be more compatibility
>   net/hns3: fix misclearing RSS configuration
>   net/hns3: using RSS filter list to check duplicated rule
>   net/hns3: remove useless code when destroy valid RSS rule
>   net/hns3: fix useless warning when flush or destroy rule
>   net/hns3: fix bad memory structure conversion
>   net/hns3: fix incorrect check for duplicate RSS rule


Some commit logs and patch titles updated while merging.

Series applied to dpdk-next-net/main, thanks.

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2023-02-08 17:46 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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   ` [PATCH V3 03/10] net/hns3: refactor set RSS hash algorithm and key interface Dongdong Liu
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.