DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/4] net/hns3: support more flow pattern match
@ 2024-10-18  6:19 Jie Hai
  2024-10-18  6:19 ` [PATCH 1/4] net/hns3: restrict FDIR only support one tunnel header Jie Hai
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jie Hai @ 2024-10-18  6:19 UTC (permalink / raw)
  To: dev, thomas, ferruh.yigit, Yisen Zhuang; +Cc: lihuisong, fengchengwen, haijie1

1. support general tunnel flow match
2. support outer VLAN flow match

Chengwen Feng (4):
  net/hns3: restrict FDIR only support one tunnel header
  net/hns3: support general tunnel flow match
  net/hns3: add FDIR VLAN match mode param string
  net/hns3: support outer VLAN flow match

 doc/guides/nics/features/hns3.ini |   3 +-
 doc/guides/nics/hns3.rst          |  10 +++
 drivers/net/hns3/hns3_common.c    |  25 +++++-
 drivers/net/hns3/hns3_common.h    |   1 +
 drivers/net/hns3/hns3_dump.c      |   4 +-
 drivers/net/hns3/hns3_ethdev.c    |   6 +-
 drivers/net/hns3/hns3_fdir.c      | 103 ++++++++++++++++++++++++
 drivers/net/hns3/hns3_fdir.h      |  51 ++++++++++++
 drivers/net/hns3/hns3_flow.c      | 129 +++++++++++++++++++++++++++---
 9 files changed, 318 insertions(+), 14 deletions(-)
 mode change 100644 => 100755 drivers/net/hns3/hns3_common.c

-- 
2.22.0


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

* [PATCH 1/4] net/hns3: restrict FDIR only support one tunnel header
  2024-10-18  6:19 [PATCH 0/4] net/hns3: support more flow pattern match Jie Hai
@ 2024-10-18  6:19 ` Jie Hai
  2024-10-18  6:19 ` [PATCH 2/4] net/hns3: support general tunnel flow match Jie Hai
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jie Hai @ 2024-10-18  6:19 UTC (permalink / raw)
  To: dev, thomas, ferruh.yigit, Yisen Zhuang, Min Hu (Connor),
	Huisong Li, Ferruh Yigit, Chengwen Feng, Wei Hu (Xavier)
  Cc: haijie1

From: Chengwen Feng <fengchengwen@huawei.com>

The device's flow director supports a maximum of one tunnel header, if
passed more than one tunnel header from rte-flow API, the driver should
return error.

Fixes: fcba820d9b9e ("net/hns3: support flow director")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/net/hns3/hns3_flow.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 37eb2b4c3807..e287420fb0f8 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -1221,6 +1221,11 @@ hns3_parse_tunnel(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
 					  "Tunnel packets must configure "
 					  "with mask");
 
+	if (rule->key_conf.spec.tunnel_type != 0)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ITEM,
+					  item, "Too many tunnel headers!");
+
 	switch (item->type) {
 	case RTE_FLOW_ITEM_TYPE_VXLAN:
 	case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
-- 
2.22.0


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

* [PATCH 2/4] net/hns3: support general tunnel flow match
  2024-10-18  6:19 [PATCH 0/4] net/hns3: support more flow pattern match Jie Hai
  2024-10-18  6:19 ` [PATCH 1/4] net/hns3: restrict FDIR only support one tunnel header Jie Hai
@ 2024-10-18  6:19 ` Jie Hai
  2024-10-18  6:19 ` [PATCH 3/4] net/hns3: add FDIR VLAN match mode param string Jie Hai
  2024-10-18  6:19 ` [PATCH 4/4] net/hns3: support outer VLAN flow match Jie Hai
  3 siblings, 0 replies; 5+ messages in thread
From: Jie Hai @ 2024-10-18  6:19 UTC (permalink / raw)
  To: dev, thomas, ferruh.yigit, Yisen Zhuang; +Cc: lihuisong, fengchengwen, haijie1

From: Chengwen Feng <fengchengwen@huawei.com>

In the current driver implementation, if you want to configure the same
action for all tunnel packets, you need to configure a rule for each
specific tunnel packet. e.g:

  flow create 0 ingress pattern ipv4 / udp / vxlan / end actions ...
  flow create 0 ingress pattern ipv4 / udp / vxlan-gpe / end actions ...
  flow create 0 ingress pattern ipv4 / udp / geneve / end actions ...
  flow create 0 ingress pattern ipv4 / nvgre / end actions ...
  flow create 0 ingress pattern ipv6 / udp / vxlan / end actions ...
  flow create 0 ingress pattern ipv6 / udp / vxlan-gpe / end actions ...
  flow create 0 ingress pattern ipv6 / udp / geneve / end actions ...
  flow create 0 ingress pattern ipv6 / nvgre / end actions ...

It occupies entry rule resources and is inconvenient to use.

The hardware supports 'tunnel packet' meta-data bit, this bit was set
when the hardware detects any type of supported tunnel packets.

This commit supports general tunnel match by identify
RTE_FLOW_ITEM_TYPE_PTYPE, and only support PTYPE_TUNNEL (0xf000). We
will treat it (0xf000) as a general tunnel, all tunnel types that
hardware recognized will match it.

After this commit, we could just create one rule per case:

  case1: match all tunnel packets
  rule1: flow create 0 ingress pattern ptype packet_type is 0xf000 /
         end actions ...

  case2: match all ipv4 tunnel packets
  rule2: flow create 0 ingress pattern ipv4 ptype packet_type is 0xf000
         / end actions ...

  case3: match all ipv6 tunnel packets
  rule3: flow create 0 ingress pattern ipv6 ptype packet_type is 0xf000
         / end actions ...

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 doc/guides/nics/features/hns3.ini |  1 +
 drivers/net/hns3/hns3_flow.c      | 45 ++++++++++++++++++++++++++++---
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/doc/guides/nics/features/hns3.ini b/doc/guides/nics/features/hns3.ini
index 8b623d30778c..d4472f904bc1 100644
--- a/doc/guides/nics/features/hns3.ini
+++ b/doc/guides/nics/features/hns3.ini
@@ -59,6 +59,7 @@ icmp                 = Y
 ipv4                 = Y
 ipv6                 = Y
 nvgre                = Y
+ptype                = P
 sctp                 = Y
 tcp                  = Y
 udp                  = Y
diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index e287420fb0f8..89ee2c6c6614 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -155,13 +155,15 @@ static enum rte_flow_item_type first_items[] = {
 	RTE_FLOW_ITEM_TYPE_NVGRE,
 	RTE_FLOW_ITEM_TYPE_VXLAN,
 	RTE_FLOW_ITEM_TYPE_GENEVE,
-	RTE_FLOW_ITEM_TYPE_VXLAN_GPE
+	RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
+	RTE_FLOW_ITEM_TYPE_PTYPE
 };
 
 static enum rte_flow_item_type L2_next_items[] = {
 	RTE_FLOW_ITEM_TYPE_VLAN,
 	RTE_FLOW_ITEM_TYPE_IPV4,
-	RTE_FLOW_ITEM_TYPE_IPV6
+	RTE_FLOW_ITEM_TYPE_IPV6,
+	RTE_FLOW_ITEM_TYPE_PTYPE
 };
 
 static enum rte_flow_item_type L3_next_items[] = {
@@ -169,7 +171,8 @@ static enum rte_flow_item_type L3_next_items[] = {
 	RTE_FLOW_ITEM_TYPE_UDP,
 	RTE_FLOW_ITEM_TYPE_SCTP,
 	RTE_FLOW_ITEM_TYPE_NVGRE,
-	RTE_FLOW_ITEM_TYPE_ICMP
+	RTE_FLOW_ITEM_TYPE_ICMP,
+	RTE_FLOW_ITEM_TYPE_PTYPE
 };
 
 static enum rte_flow_item_type L4_next_items[] = {
@@ -1204,6 +1207,32 @@ hns3_parse_geneve(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
 	return 0;
 }
 
+static int
+hns3_parse_ptype(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
+		  struct rte_flow_error *error)
+{
+	const struct rte_flow_item_ptype *spec = item->spec;
+	const struct rte_flow_item_ptype *mask = item->mask;
+
+	if (spec == NULL || mask == NULL)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ITEM, item,
+					  "PTYPE must set spec and mask at the same time!");
+
+	if (spec->packet_type != RTE_PTYPE_TUNNEL_MASK ||
+	    (mask->packet_type & RTE_PTYPE_TUNNEL_MASK) != RTE_PTYPE_TUNNEL_MASK)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
+					  "PTYPE only support general tunnel!");
+
+	/*
+	 * Set tunnel_type to non-zero, so that meta-data's tunnel packet bit
+	 * will be set, then hardware will match tunnel packet.
+	 */
+	rule->key_conf.spec.tunnel_type = 1;
+	return 0;
+}
+
 static int
 hns3_parse_tunnel(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
 		  struct rte_flow_error *error)
@@ -1237,6 +1266,9 @@ hns3_parse_tunnel(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
 	case RTE_FLOW_ITEM_TYPE_GENEVE:
 		ret = hns3_parse_geneve(item, rule, error);
 		break;
+	case RTE_FLOW_ITEM_TYPE_PTYPE:
+		ret = hns3_parse_ptype(item, rule, error);
+		break;
 	default:
 		return rte_flow_error_set(error, ENOTSUP,
 					  RTE_FLOW_ERROR_TYPE_ITEM,
@@ -1336,7 +1368,12 @@ is_tunnel_packet(enum rte_flow_item_type type)
 	if (type == RTE_FLOW_ITEM_TYPE_VXLAN_GPE ||
 	    type == RTE_FLOW_ITEM_TYPE_VXLAN ||
 	    type == RTE_FLOW_ITEM_TYPE_NVGRE ||
-	    type == RTE_FLOW_ITEM_TYPE_GENEVE)
+	    type == RTE_FLOW_ITEM_TYPE_GENEVE ||
+	    /*
+	     * Here treat PTYPE as tunnel type because driver only support PTYPE_TUNNEL,
+	     * other PTYPE will return error in hns3_parse_ptype() later.
+	     */
+	    type == RTE_FLOW_ITEM_TYPE_PTYPE)
 		return true;
 	return false;
 }
-- 
2.22.0


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

* [PATCH 3/4] net/hns3: add FDIR VLAN match mode param string
  2024-10-18  6:19 [PATCH 0/4] net/hns3: support more flow pattern match Jie Hai
  2024-10-18  6:19 ` [PATCH 1/4] net/hns3: restrict FDIR only support one tunnel header Jie Hai
  2024-10-18  6:19 ` [PATCH 2/4] net/hns3: support general tunnel flow match Jie Hai
@ 2024-10-18  6:19 ` Jie Hai
  2024-10-18  6:19 ` [PATCH 4/4] net/hns3: support outer VLAN flow match Jie Hai
  3 siblings, 0 replies; 5+ messages in thread
From: Jie Hai @ 2024-10-18  6:19 UTC (permalink / raw)
  To: dev, thomas, ferruh.yigit, Yisen Zhuang; +Cc: lihuisong, fengchengwen, haijie1

From: Chengwen Feng <fengchengwen@huawei.com>

This commit adds fdir_vlan_match_mode in RTE_PMD_REGISTER_PARAM_STRING.

Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 8b43d731acae..63cf79ac7edf 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -6670,7 +6670,8 @@ RTE_PMD_REGISTER_PARAM_STRING(net_hns3,
 		HNS3_DEVARG_RX_FUNC_HINT "=vec|sve|simple|common "
 		HNS3_DEVARG_TX_FUNC_HINT "=vec|sve|simple|common "
 		HNS3_DEVARG_DEV_CAPS_MASK "=<1-65535> "
-		HNS3_DEVARG_MBX_TIME_LIMIT_MS "=<uint16> ");
+		HNS3_DEVARG_MBX_TIME_LIMIT_MS "=<uint16> "
+		HNS3_DEVARG_FDIR_VALN_MATCH_MODE "=strict|nostrict ");
 RTE_LOG_REGISTER_SUFFIX(hns3_logtype_init, init, NOTICE);
 RTE_LOG_REGISTER_SUFFIX(hns3_logtype_driver, driver, NOTICE);
 #ifdef RTE_ETHDEV_DEBUG_RX
-- 
2.22.0


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

* [PATCH 4/4] net/hns3: support outer VLAN flow match
  2024-10-18  6:19 [PATCH 0/4] net/hns3: support more flow pattern match Jie Hai
                   ` (2 preceding siblings ...)
  2024-10-18  6:19 ` [PATCH 3/4] net/hns3: add FDIR VLAN match mode param string Jie Hai
@ 2024-10-18  6:19 ` Jie Hai
  3 siblings, 0 replies; 5+ messages in thread
From: Jie Hai @ 2024-10-18  6:19 UTC (permalink / raw)
  To: dev, thomas, ferruh.yigit, Yisen Zhuang; +Cc: lihuisong, fengchengwen, haijie1

From: Chengwen Feng <fengchengwen@huawei.com>

The hardware FDIR supports many tuples match (including outer vlan),
however, the width of hardware entries is limited, therefore, only
part of tuples are enabled, unfortunately, outer vlan is not enabled.

This commit supports outer vlan match, to avoid affecting the current
use, use runtime config 'fdir_tuple_config' to enable this feature, the
options are as follows:
1. +outvlan-insmac:  means disable inner src mac tuple,
                     and enable outer vlan tuple.
2. +outvlan-indmac:  means disable inner dst mac tuple,
                     and enable outer vlan tuple.
3. +outvlan-insip:   means disable inner src ip tuple,
                     and enable outer vlan tuple.
4. +outvlan-indip:   means disable inner dst ip tuple,
                     and enable outer vlan tuple.
5. +outvlan-sctptag: means disable sctp tag tuple,
                     and enable outer vlan tuple.
6. +outvlan-tunvni:  means disable tunnel vni tuple,
                     and enable outer vlan tuple.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 doc/guides/nics/features/hns3.ini |   2 +-
 doc/guides/nics/hns3.rst          |  10 +++
 drivers/net/hns3/hns3_common.c    |  25 +++++++-
 drivers/net/hns3/hns3_common.h    |   1 +
 drivers/net/hns3/hns3_dump.c      |   4 +-
 drivers/net/hns3/hns3_ethdev.c    |   5 +-
 drivers/net/hns3/hns3_fdir.c      | 103 ++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_fdir.h      |  51 +++++++++++++++
 drivers/net/hns3/hns3_flow.c      |  79 +++++++++++++++++++++--
 9 files changed, 270 insertions(+), 10 deletions(-)
 mode change 100644 => 100755 drivers/net/hns3/hns3_common.c

diff --git a/doc/guides/nics/features/hns3.ini b/doc/guides/nics/features/hns3.ini
index d4472f904bc1..5326d20e72df 100644
--- a/doc/guides/nics/features/hns3.ini
+++ b/doc/guides/nics/features/hns3.ini
@@ -63,7 +63,7 @@ ptype                = P
 sctp                 = Y
 tcp                  = Y
 udp                  = Y
-vlan                 = P
+vlan                 = Y
 vxlan                = Y
 vxlan_gpe            = Y
 
diff --git a/doc/guides/nics/hns3.rst b/doc/guides/nics/hns3.rst
index ba193ee76610..bdc10da1c74f 100644
--- a/doc/guides/nics/hns3.rst
+++ b/doc/guides/nics/hns3.rst
@@ -183,6 +183,16 @@ Runtime Configuration
 
     -a 0000:7d:00.0,fdir_vlan_match_mode=nostrict
 
+- ``fdir_tuple_config`` (default ``none``)
+
+  Used to customize the flow director tuples. Current supported options are follows:
+  ``+outvlan-insmac``: means disable inner src mac tuple, and enable outer vlan tuple.
+  ``+outvlan-indmac``: means disable inner dst mac tuple, and enable outer vlan tuple.
+  ``+outvlan-insip``: means disable inner src ip tuple, and enable outer vlan tuple.
+  ``+outvlan-indip``: means disable inner dst ip tuple, and enable outer vlan tuple.
+  ``+outvlan-sctptag``: means disable sctp tag tuple, and enable outer vlan tuple.
+  ``+outvlan-tunvni``: means disable tunnel vni tuple, and enable outer vlan tuple.
+
 Driver compilation and testing
 ------------------------------
 
diff --git a/drivers/net/hns3/hns3_common.c b/drivers/net/hns3/hns3_common.c
old mode 100644
new mode 100755
index 5e6cdfdaa019..09c282969ed3
--- a/drivers/net/hns3/hns3_common.c
+++ b/drivers/net/hns3/hns3_common.c
@@ -272,6 +272,24 @@ hns3_parse_vlan_match_mode(const char *key, const char *value, void *args)
 	return 0;
 }
 
+static int
+hns3_parse_fdir_tuple_config(const char *key, const char *value, void *args)
+{
+	enum hns3_fdir_tuple_config tuple_cfg;
+
+	tuple_cfg = hns3_parse_tuple_config(value);
+	if (tuple_cfg == HNS3_FDIR_TUPLE_CONFIG_DEFAULT ||
+	    tuple_cfg == HNS3_FDIR_TUPLE_CONFIG_BUTT) {
+		PMD_INIT_LOG(WARNING, "invalid value:\"%s\" for key:\"%s\"",
+			     value, key);
+		return -1;
+	}
+
+	*(enum hns3_fdir_tuple_config *)args = tuple_cfg;
+
+	return 0;
+}
+
 void
 hns3_parse_devargs(struct rte_eth_dev *dev)
 {
@@ -306,11 +324,16 @@ hns3_parse_devargs(struct rte_eth_dev *dev)
 			   &hns3_parse_dev_caps_mask, &dev_caps_mask);
 	(void)rte_kvargs_process(kvlist, HNS3_DEVARG_MBX_TIME_LIMIT_MS,
 			   &hns3_parse_mbx_time_limit, &mbx_time_limit_ms);
-	if (!hns->is_vf)
+	if (!hns->is_vf) {
 		(void)rte_kvargs_process(kvlist,
 					 HNS3_DEVARG_FDIR_VALN_MATCH_MODE,
 					 &hns3_parse_vlan_match_mode,
 					 &hns->pf.fdir.vlan_match_mode);
+		(void)rte_kvargs_process(kvlist,
+					 HNS3_DEVARG_FDIR_TUPLE_CONFIG,
+					 &hns3_parse_fdir_tuple_config,
+					 &hns->pf.fdir.tuple_cfg);
+	}
 
 	rte_kvargs_free(kvlist);
 
diff --git a/drivers/net/hns3/hns3_common.h b/drivers/net/hns3/hns3_common.h
index cf9593bd0caa..18e369c2a6c0 100644
--- a/drivers/net/hns3/hns3_common.h
+++ b/drivers/net/hns3/hns3_common.h
@@ -28,6 +28,7 @@ enum {
 #define HNS3_DEVARG_MBX_TIME_LIMIT_MS	"mbx_time_limit_ms"
 
 #define HNS3_DEVARG_FDIR_VALN_MATCH_MODE	"fdir_vlan_match_mode"
+#define HNS3_DEVARG_FDIR_TUPLE_CONFIG	"fdir_tuple_config"
 
 #define MSEC_PER_SEC              1000L
 #define USEC_PER_MSEC             1000L
diff --git a/drivers/net/hns3/hns3_dump.c b/drivers/net/hns3/hns3_dump.c
index fff44b9514c3..1a50391851b4 100644
--- a/drivers/net/hns3/hns3_dump.c
+++ b/drivers/net/hns3/hns3_dump.c
@@ -169,6 +169,7 @@ hns3_get_fdir_basic_info(FILE *file, struct hns3_pf *pf)
 		"\t  -- mode=%u max_key_len=%u rule_num:%u cnt_num:%u\n"
 		"\t  -- key_sel=%u tuple_active=0x%x meta_data_active=0x%x\n"
 		"\t  -- ipv6_word_en: in_s=%u in_d=%u out_s=%u out_d=%u\n"
+		"\t  -- tuple_config: %s\n"
 		"\t  -- active_tuples:\n",
 		fdcfg->fd_mode, fdcfg->max_key_length,
 		fdcfg->rule_num[HNS3_FD_STAGE_1],
@@ -179,7 +180,8 @@ hns3_get_fdir_basic_info(FILE *file, struct hns3_pf *pf)
 		fdcfg->key_cfg[HNS3_FD_STAGE_1].inner_sipv6_word_en,
 		fdcfg->key_cfg[HNS3_FD_STAGE_1].inner_dipv6_word_en,
 		fdcfg->key_cfg[HNS3_FD_STAGE_1].outer_sipv6_word_en,
-		fdcfg->key_cfg[HNS3_FD_STAGE_1].outer_dipv6_word_en);
+		fdcfg->key_cfg[HNS3_FD_STAGE_1].outer_dipv6_word_en,
+		hns3_tuple_config_name(pf->fdir.tuple_cfg));
 
 	for (i = 0; i < MAX_TUPLE; i++) {
 		if (!(fdcfg->key_cfg[HNS3_FD_STAGE_1].tuple_active & BIT(i)))
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 63cf79ac7edf..6fdb3101d8d2 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -6671,7 +6671,10 @@ RTE_PMD_REGISTER_PARAM_STRING(net_hns3,
 		HNS3_DEVARG_TX_FUNC_HINT "=vec|sve|simple|common "
 		HNS3_DEVARG_DEV_CAPS_MASK "=<1-65535> "
 		HNS3_DEVARG_MBX_TIME_LIMIT_MS "=<uint16> "
-		HNS3_DEVARG_FDIR_VALN_MATCH_MODE "=strict|nostrict ");
+		HNS3_DEVARG_FDIR_VALN_MATCH_MODE "=strict|nostrict "
+		HNS3_DEVARG_FDIR_TUPLE_CONFIG "=+outvlan-insmac|+outvlan-indmac|"
+					      "+outvlan-insip|+outvlan-indip"
+					      "+outvlan-sctptag|+outvlan-tunvni ");
 RTE_LOG_REGISTER_SUFFIX(hns3_logtype_init, init, NOTICE);
 RTE_LOG_REGISTER_SUFFIX(hns3_logtype_driver, driver, NOTICE);
 #ifdef RTE_ETHDEV_DEBUG_RX
diff --git a/drivers/net/hns3/hns3_fdir.c b/drivers/net/hns3/hns3_fdir.c
index 4843066723b3..a354d1d32f16 100644
--- a/drivers/net/hns3/hns3_fdir.c
+++ b/drivers/net/hns3/hns3_fdir.c
@@ -300,6 +300,58 @@ static int hns3_set_fd_key_config(struct hns3_adapter *hns)
 	return ret;
 }
 
+static void hns3_set_tuple_config(struct hns3_adapter *hns,
+				  struct hns3_fd_key_cfg *key_cfg)
+{
+	enum hns3_fdir_tuple_config tuple_cfg = hns->pf.fdir.tuple_cfg;
+
+	if (tuple_cfg == HNS3_FDIR_TUPLE_CONFIG_DEFAULT)
+		return;
+
+	if (hns->pf.fdir.fd_cfg.max_key_length != MAX_KEY_LENGTH) {
+		hns3_warn(&hns->hw, "fdir tuple config only valid with 400bit key!");
+		return;
+	}
+
+	switch (tuple_cfg) {
+	case HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INSMAC:
+		key_cfg->tuple_active &= ~BIT(INNER_SRC_MAC);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_FST);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_SEC);
+		break;
+	case HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INDMAC:
+		key_cfg->tuple_active &= ~BIT(INNER_DST_MAC);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_FST);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_SEC);
+		break;
+	case HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INSIP:
+		key_cfg->tuple_active &= ~BIT(INNER_SRC_IP);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_FST);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_SEC);
+		break;
+	case HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INDIP:
+		key_cfg->tuple_active &= ~BIT(INNER_DST_IP);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_FST);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_SEC);
+		break;
+	case HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_SCTPTAG:
+		key_cfg->tuple_active &= ~BIT(INNER_SCTP_TAG);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_FST);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_SEC);
+		break;
+	case HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_TUNVNI:
+		key_cfg->tuple_active &= ~BIT(OUTER_TUN_VNI);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_FST);
+		key_cfg->tuple_active |= BIT(OUTER_VLAN_TAG_SEC);
+		break;
+	default:
+		hns3_err(&hns->hw, "invalid fdir tuple config %u!", tuple_cfg);
+		return;
+	}
+
+	hns3_info(&hns->hw, "fdir tuple config %s!", hns3_tuple_config_name(tuple_cfg));
+}
+
 int hns3_init_fd_config(struct hns3_adapter *hns)
 {
 	struct hns3_pf *pf = &hns->pf;
@@ -352,6 +404,8 @@ int hns3_init_fd_config(struct hns3_adapter *hns)
 			 "l4_src_port l4_dst_port tun_vni tun_flow_id>");
 	}
 
+	hns3_set_tuple_config(hns, key_cfg);
+
 	/* roce_type is used to filter roce frames
 	 * dst_vport is used to specify the rule
 	 */
@@ -500,6 +554,14 @@ static void hns3_fd_convert_int16(uint32_t tuple, struct hns3_fdir_rule *rule,
 	uint16_t key;
 
 	switch (tuple) {
+	case OUTER_VLAN_TAG_FST:
+		key = rule->key_conf.spec.outer_vlan_tag1;
+		mask = rule->key_conf.mask.outer_vlan_tag1;
+		break;
+	case OUTER_VLAN_TAG_SEC:
+		key = rule->key_conf.spec.outer_vlan_tag2;
+		mask = rule->key_conf.mask.outer_vlan_tag2;
+		break;
 	case OUTER_SRC_PORT:
 		key = rule->key_conf.spec.outer_src_port;
 		mask = rule->key_conf.mask.outer_src_port;
@@ -575,6 +637,8 @@ static bool hns3_fd_convert_tuple(struct hns3_hw *hw,
 		hns3_fd_convert_mac(key_conf->spec.src_mac,
 				    key_conf->mask.src_mac, key_x, key_y);
 		break;
+	case OUTER_VLAN_TAG_FST:
+	case OUTER_VLAN_TAG_SEC:
 	case OUTER_SRC_PORT:
 	case OUTER_DST_PORT:
 	case OUTER_ETH_TYPE:
@@ -1128,3 +1192,42 @@ int hns3_fd_get_count(struct hns3_hw *hw, uint32_t id, uint64_t *value)
 
 	return ret;
 }
+
+static struct {
+	enum hns3_fdir_tuple_config tuple_cfg;
+	const char *name;
+} tuple_config_map[] = {
+	{ HNS3_FDIR_TUPLE_CONFIG_DEFAULT,          "default"          },
+	{ HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INSMAC,  "+outvlan-insmac"  },
+	{ HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INDMAC,  "+outvlan-indmac"  },
+	{ HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INSIP,   "+outvlan-insip"   },
+	{ HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INDIP,   "+outvlan-indip"   },
+	{ HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_SCTPTAG, "+outvlan-sctptag" },
+	{ HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_TUNVNI,  "+outvlan-tunvni"  }
+};
+
+enum hns3_fdir_tuple_config
+hns3_parse_tuple_config(const char *name)
+{
+	uint32_t i;
+
+	for (i = 0; i < RTE_DIM(tuple_config_map); i++) {
+		if (!strcmp(name, tuple_config_map[i].name))
+			return tuple_config_map[i].tuple_cfg;
+	}
+
+	return HNS3_FDIR_TUPLE_CONFIG_BUTT;
+}
+
+const char *
+hns3_tuple_config_name(enum hns3_fdir_tuple_config tuple_cfg)
+{
+	uint32_t i;
+
+	for (i = 0; i < RTE_DIM(tuple_config_map); i++) {
+		if (tuple_cfg == tuple_config_map[i].tuple_cfg)
+			return tuple_config_map[i].name;
+	}
+
+	return "unknown";
+}
diff --git a/drivers/net/hns3/hns3_fdir.h b/drivers/net/hns3/hns3_fdir.h
index 6ccd90a253f8..2d0c9bf3c8b6 100644
--- a/drivers/net/hns3/hns3_fdir.h
+++ b/drivers/net/hns3/hns3_fdir.h
@@ -97,6 +97,8 @@ struct hns3_fd_rule_tuples {
 	uint32_t sctp_tag;
 	uint16_t outer_src_port;
 	uint16_t tunnel_type;
+	uint16_t outer_vlan_tag1;
+	uint16_t outer_vlan_tag2;
 	uint16_t outer_ether_type;
 	uint8_t outer_proto;
 	uint8_t outer_tun_vni[VNI_OR_TNI_LEN];
@@ -181,6 +183,51 @@ TAILQ_HEAD(hns3_fdir_rule_list, hns3_fdir_rule_ele);
 #define HNS3_FDIR_VLAN_STRICT_MATCH	1
 #define HNS3_FDIR_VLAN_NOSTRICT_MATCH	0
 
+/*
+ * The hardware supports many tuples match (see @enum HNS3_FD_TUPLE),
+ * however, the width of hardware entries is limited, therefore, only part
+ * of tuples are enabled (see as @hns3_init_fd_config).
+ *
+ * We should replace the existing tuples if we want to enable other tuples
+ * because the width capacity is insufficient.
+ */
+enum hns3_fdir_tuple_config {
+	/* Default tuple config (see as @hns3_init_fd_config). */
+	HNS3_FDIR_TUPLE_CONFIG_DEFAULT,
+	/*
+	 * Based on the default tuple config, disable the inner src-mac tuple,
+	 * and enable the outer VLAN tuple.
+	 */
+	HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INSMAC,
+	/*
+	 * Based on the default tuple config, disable the inner dst-mac tuple,
+	 * and enable the outer VLAN tuple.
+	 */
+	HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INDMAC,
+	/*
+	 * Based on the default tuple config, disable the inner src-ip tuple,
+	 * and enable the outer VLAN tuple.
+	 */
+	HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INSIP,
+	/*
+	 * Based on the default tuple config, disable the inner dst-ip tuple,
+	 * and enable the outer VLAN tuple.
+	 */
+	HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INDIP,
+	/*
+	 * Based on the default tuple config, disable the sctp-tag tuple,
+	 * and enable the outer VLAN tuple.
+	 */
+	HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_SCTPTAG,
+	/*
+	 * Based on the default tuple config, disable the tunnel vni tuple,
+	 * and enable the outer VLAN tuple.
+	 */
+	HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_TUNVNI,
+
+	HNS3_FDIR_TUPLE_CONFIG_BUTT
+};
+
 /*
  *  A structure used to define fields of a FDIR related info.
  */
@@ -190,6 +237,7 @@ struct hns3_fdir_info {
 	struct rte_hash *hash_handle;
 	struct hns3_fd_cfg fd_cfg;
 	uint8_t vlan_match_mode;
+	enum hns3_fdir_tuple_config tuple_cfg;
 };
 
 struct hns3_adapter;
@@ -204,4 +252,7 @@ int hns3_clear_all_fdir_filter(struct hns3_adapter *hns);
 int hns3_fd_get_count(struct hns3_hw *hw, uint32_t id, uint64_t *value);
 int hns3_restore_all_fdir_filter(struct hns3_adapter *hns);
 
+enum hns3_fdir_tuple_config hns3_parse_tuple_config(const char *name);
+const char *hns3_tuple_config_name(enum hns3_fdir_tuple_config tuple_cfg);
+
 #endif /* HNS3_FDIR_H */
diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c
index 89ee2c6c6614..4674f74f43e2 100644
--- a/drivers/net/hns3/hns3_flow.c
+++ b/drivers/net/hns3/hns3_flow.c
@@ -608,6 +608,59 @@ hns3_check_attr(const struct rte_flow_attr *attr, struct rte_flow_error *error)
 	return 0;
 }
 
+static int
+hns3_check_tuple(const struct rte_eth_dev *dev, const struct hns3_fdir_rule *rule,
+		 struct rte_flow_error *error)
+{
+	const char * const err_msg[] = {
+		"Not support outer dst mac",
+		"Not support outer src mac",
+		"Not support outer vlan1 tag",
+		"Not support outer vlan2 tag",
+		"Not support outer eth type",
+		"Not support outer l2 rsv",
+		"Not support outer ip tos",
+		"Not support outer ip proto",
+		"Not support outer src ip",
+		"Not support outer dst ip",
+		"Not support outer l3 rsv",
+		"Not support outer src port",
+		"Not support outer dst port",
+		"Not support outer l4 rsv",
+		"Not support outer tun vni",
+		"Not support outer tun flow id",
+		"Not support inner dst mac",
+		"Not support inner src mac",
+		"Not support inner vlan tag1",
+		"Not support inner vlan tag2",
+		"Not support inner eth type",
+		"Not support inner l2 rsv",
+		"Not support inner ip tos",
+		"Not support inner ip proto",
+		"Not support inner src ip",
+		"Not support inner dst ip",
+		"Not support inner l3 rsv",
+		"Not support inner src port",
+		"Not support inner dst port",
+		"Not support inner sctp tag",
+	};
+	struct hns3_adapter *hns = dev->data->dev_private;
+	uint32_t tuple_active = hns->pf.fdir.fd_cfg.key_cfg[HNS3_FD_STAGE_1].tuple_active;
+	uint32_t i;
+
+	for (i = 0; i < MAX_TUPLE; i++) {
+		if ((rule->input_set & BIT(i)) == 0)
+			continue;
+		if (tuple_active & BIT(i))
+			continue;
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_ITEM,
+					  NULL, err_msg[i]);
+	}
+
+	return 0;
+}
+
 static int
 hns3_parse_eth(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
 	       struct rte_flow_error *error __rte_unused)
@@ -1029,12 +1082,22 @@ hns3_handle_tunnel(const struct rte_flow_item *item,
 		rule->key_conf.mask.ether_type = 0;
 	}
 
-	/* check vlan config */
-	if (rule->input_set & (BIT(INNER_VLAN_TAG1) | BIT(INNER_VLAN_TAG2)))
-		return rte_flow_error_set(error, EINVAL,
-					  RTE_FLOW_ERROR_TYPE_ITEM,
-					  item,
-					  "Outer vlan tags is unsupported");
+	if (rule->input_set & BIT(INNER_VLAN_TAG1)) {
+		hns3_set_bit(rule->input_set, OUTER_VLAN_TAG_FST, 1);
+		hns3_set_bit(rule->input_set, INNER_VLAN_TAG1, 0);
+		rule->key_conf.spec.outer_vlan_tag1 = rule->key_conf.spec.vlan_tag1;
+		rule->key_conf.mask.outer_vlan_tag1 = rule->key_conf.mask.vlan_tag1;
+		rule->key_conf.spec.vlan_tag1 = 0;
+		rule->key_conf.mask.vlan_tag1 = 0;
+	}
+	if (rule->input_set & BIT(INNER_VLAN_TAG2)) {
+		hns3_set_bit(rule->input_set, OUTER_VLAN_TAG_SEC, 1);
+		hns3_set_bit(rule->input_set, INNER_VLAN_TAG2, 0);
+		rule->key_conf.spec.outer_vlan_tag2 = rule->key_conf.spec.vlan_tag2;
+		rule->key_conf.mask.outer_vlan_tag2 = rule->key_conf.mask.vlan_tag2;
+		rule->key_conf.spec.vlan_tag2 = 0;
+		rule->key_conf.mask.vlan_tag2 = 0;
+	}
 
 	/* clear vlan_num for inner vlan select */
 	rule->key_conf.outer_vlan_num = rule->key_conf.vlan_num;
@@ -1444,6 +1507,10 @@ hns3_parse_fdir_filter(struct rte_eth_dev *dev,
 		}
 	}
 
+	ret = hns3_check_tuple(dev, rule, error);
+	if (ret)
+		return ret;
+
 	return hns3_handle_actions(dev, actions, rule, error);
 }
 
-- 
2.22.0


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

end of thread, other threads:[~2024-10-18  6:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-18  6:19 [PATCH 0/4] net/hns3: support more flow pattern match Jie Hai
2024-10-18  6:19 ` [PATCH 1/4] net/hns3: restrict FDIR only support one tunnel header Jie Hai
2024-10-18  6:19 ` [PATCH 2/4] net/hns3: support general tunnel flow match Jie Hai
2024-10-18  6:19 ` [PATCH 3/4] net/hns3: add FDIR VLAN match mode param string Jie Hai
2024-10-18  6:19 ` [PATCH 4/4] net/hns3: support outer VLAN flow match Jie Hai

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).