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

[ upstream commit eb3ef9e0d7eb54b47ab58d3d14f9f5fff3f4120b ]

Add the verification of RSS types from ethdev ops and rte flow without
pattern attribute. The following cases are invalid:
1. types contains unsupported RSS type but hasn't type driver support.
2. types has L3 src/dst but hasn't supported packet type.
3. types has L4 src/dst but hasn't supported packet type and hasn't IP
   packet type.

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

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index ff7a8a6dc0..8b37c17b40 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1605,9 +1605,10 @@ hns3_flow_parse_rss_types(struct hns3_hw *hw,
 
 	/* no pattern specified to set global RSS types. */
 	if (pattern_type == 0) {
-		if (rss_act->types & ~HNS3_ETH_RSS_SUPPORT)
-			hns3_warn(hw, "some types in the requested RSS types (0x%" PRIx64 ") aren't supported, they are ignored.",
-				  rss_act->types);
+		if (!hns3_check_rss_types_valid(hw, rss_act->types))
+			return rte_flow_error_set(error, EINVAL,
+					RTE_FLOW_ERROR_TYPE_ACTION_CONF,
+					NULL, "RSS types is invalid.");
 		rss_conf->hw_pctypes =
 				hns3_flow_get_all_hw_pctypes(rss_act->types);
 		return 0;
@@ -1882,15 +1883,14 @@ hns3_flow_set_rss_ptype_tuple(struct hns3_hw *hw,
 			uint64_t pctype = BIT_ULL(idx);
 
 			tuple_mask = hns3_flow_get_pctype_tuple_mask(pctype);
-			tuples = hns3_rss_calc_tuple_filed(hw,
-							rss_conf->conf.types);
+			tuples = hns3_rss_calc_tuple_filed(rss_conf->conf.types);
 			new_tuple_fields &= ~tuple_mask;
 			new_tuple_fields |= tuples;
 			hw_pctypes &= ~pctype;
 		}
 	} else {
 		new_tuple_fields =
-			hns3_rss_calc_tuple_filed(hw, rss_conf->conf.types);
+			hns3_rss_calc_tuple_filed(rss_conf->conf.types);
 	}
 
 	ret = hns3_set_rss_tuple_field(hw, new_tuple_fields);
diff --git a/drivers/net/hns3/hns3_rss.c b/drivers/net/hns3/hns3_rss.c
index 246b96dd9b..8bcc906e45 100644
--- a/drivers/net/hns3/hns3_rss.c
+++ b/drivers/net/hns3/hns3_rss.c
@@ -492,34 +492,62 @@ hns3_rss_reset_indir_table(struct hns3_hw *hw)
 	return ret;
 }
 
-static void
-hns3_rss_check_l3l4_types(struct hns3_hw *hw, uint64_t rss_hf)
+bool
+hns3_check_rss_types_valid(struct hns3_hw *hw, uint64_t types)
 {
 	uint64_t ip_mask = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
 			   RTE_ETH_RSS_NONFRAG_IPV4_OTHER |
 			   RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
 			   RTE_ETH_RSS_NONFRAG_IPV6_OTHER;
-	uint64_t l4_mask = RTE_ETH_RSS_NONFRAG_IPV4_TCP |
-			   RTE_ETH_RSS_NONFRAG_IPV4_UDP |
-			   RTE_ETH_RSS_NONFRAG_IPV4_SCTP |
-			   RTE_ETH_RSS_NONFRAG_IPV6_TCP |
-			   RTE_ETH_RSS_NONFRAG_IPV6_UDP |
-			   RTE_ETH_RSS_NONFRAG_IPV6_SCTP;
-	uint64_t l3_src_dst_mask = RTE_ETH_RSS_L3_SRC_ONLY |
-				   RTE_ETH_RSS_L3_DST_ONLY;
-	uint64_t l4_src_dst_mask = RTE_ETH_RSS_L4_SRC_ONLY |
-				   RTE_ETH_RSS_L4_DST_ONLY;
-
-	if (rss_hf & l3_src_dst_mask &&
-	    !(rss_hf & ip_mask || rss_hf & l4_mask))
-		hns3_warn(hw, "packet type isn't specified, L3_SRC/DST_ONLY is ignored.");
-
-	if (rss_hf & l4_src_dst_mask && !(rss_hf & l4_mask))
-		hns3_warn(hw, "packet type isn't specified, L4_SRC/DST_ONLY is ignored.");
+	uint64_t ip_l4_mask = RTE_ETH_RSS_NONFRAG_IPV4_TCP |
+			      RTE_ETH_RSS_NONFRAG_IPV4_UDP |
+			      RTE_ETH_RSS_NONFRAG_IPV4_SCTP |
+			      RTE_ETH_RSS_NONFRAG_IPV6_TCP |
+			      RTE_ETH_RSS_NONFRAG_IPV6_UDP |
+			      RTE_ETH_RSS_NONFRAG_IPV6_SCTP;
+	bool has_l4_src_dst = !!(types & HNS3_RSS_SUPPORT_L4_SRC_DST);
+	bool has_ip_pkt = !!(types & ip_mask);
+	uint64_t final_types;
+
+	if (types == 0)
+		return true;
+
+	if ((types & HNS3_ETH_RSS_SUPPORT) == 0) {
+		hns3_err(hw, "specified types(0x%" PRIx64 ") are unsupported.",
+			 types);
+		return false;
+	}
+
+	if ((types & HNS3_RSS_SUPPORT_L3_SRC_DST) != 0 &&
+	    (types & HNS3_RSS_SUPPORT_FLOW_TYPE) == 0) {
+		hns3_err(hw, "IP or IP-TCP/UDP/SCTP packet type isn't specified, L3_SRC/DST_ONLY cannot be set.");
+		return false;
+	}
+
+	if (has_l4_src_dst && (types & ip_l4_mask) == 0) {
+		if (!has_ip_pkt) {
+			hns3_err(hw, "IP-TCP/UDP/SCTP packet type isn't specified, L4_SRC/DST_ONLY cannot be set.");
+			return false;
+		}
+		/*
+		 * For the case that the types has L4_SRC/DST_ONLY but hasn't
+		 * IP-TCP/UDP/SCTP packet type, this types is considered valid
+		 * if it also has IP packet type.
+		 */
+		hns3_warn(hw, "L4_SRC/DST_ONLY is ignored because of no including L4 packet.");
+	}
+
+	if ((types & ~HNS3_ETH_RSS_SUPPORT) != 0) {
+		final_types = types & HNS3_ETH_RSS_SUPPORT;
+		hns3_warn(hw, "set RSS types based on hardware support, requested:0x%" PRIx64 " configured:0x%" PRIx64 "",
+			  types, final_types);
+	}
+
+	return true;
 }
 
 uint64_t
-hns3_rss_calc_tuple_filed(struct hns3_hw *hw, uint64_t rss_hf)
+hns3_rss_calc_tuple_filed(uint64_t rss_hf)
 {
 	uint64_t l3_only_mask = RTE_ETH_RSS_L3_SRC_ONLY |
 				RTE_ETH_RSS_L3_DST_ONLY;
@@ -548,7 +576,6 @@ hns3_rss_calc_tuple_filed(struct hns3_hw *hw, uint64_t rss_hf)
 		    !has_l3_l4_only)
 			tuple |= hns3_set_tuple_table[i].rss_field;
 	}
-	hns3_rss_check_l3l4_types(hw, rss_hf);
 
 	return tuple;
 }
@@ -576,7 +603,7 @@ hns3_set_rss_tuple_by_rss_hf(struct hns3_hw *hw, uint64_t rss_hf)
 	uint64_t tuple_fields;
 	int ret;
 
-	tuple_fields = hns3_rss_calc_tuple_filed(hw, rss_hf);
+	tuple_fields = hns3_rss_calc_tuple_filed(rss_hf);
 	ret = hns3_set_rss_tuple_field(hw, tuple_fields);
 	if (ret != 0)
 		hns3_err(hw, "Update RSS flow types tuples failed, ret = %d",
@@ -611,6 +638,9 @@ hns3_dev_rss_hash_update(struct rte_eth_dev *dev,
 		return -EINVAL;
 	}
 
+	if (!hns3_check_rss_types_valid(hw, rss_hf))
+		return -EINVAL;
+
 	rte_spinlock_lock(&hw->lock);
 	ret = hns3_set_rss_tuple_by_rss_hf(hw, rss_hf);
 	if (ret)
diff --git a/drivers/net/hns3/hns3_rss.h b/drivers/net/hns3/hns3_rss.h
index 76c10afdde..931dacb813 100644
--- a/drivers/net/hns3/hns3_rss.h
+++ b/drivers/net/hns3/hns3_rss.h
@@ -184,6 +184,7 @@ int hns3_set_rss_indir_table(struct hns3_hw *hw, uint16_t *indir,
 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);
+bool hns3_check_rss_types_valid(struct hns3_hw *hw, uint64_t types);
 int hns3_set_rss_tuple_by_rss_hf(struct hns3_hw *hw, uint64_t rss_hf);
 int hns3_set_rss_tuple_field(struct hns3_hw *hw, uint64_t tuple_fields);
 int hns3_get_rss_tuple_field(struct hns3_hw *hw, uint64_t *tuple_fields);
@@ -191,7 +192,7 @@ int hns3_rss_set_algo_key(struct hns3_hw *hw, uint8_t hash_algo,
 			  const uint8_t *key, uint8_t key_len);
 int hns3_rss_get_algo_key(struct hns3_hw *hw,  uint8_t *hash_algo,
 			  uint8_t *key, uint8_t key_len);
-uint64_t hns3_rss_calc_tuple_filed(struct hns3_hw *hw, uint64_t rss_hf)
+uint64_t hns3_rss_calc_tuple_filed(uint64_t rss_hf);
 int hns3_update_rss_algo_key(struct hns3_hw *hw, uint8_t hash_algo,
 			     uint8_t *key, uint8_t key_len);
 
-- 
2.22.0


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

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

Reply instructions:

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

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

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

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

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

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

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