Blame SOURCES/0233-netdrv-net-mlx5e-Move-tc-tunnel-parsing-logic-with-t.patch

d8f823
From af5a918bec18ded5235fe365baf92c6978e36369 Mon Sep 17 00:00:00 2001
d8f823
From: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Date: Tue, 19 May 2020 07:48:55 -0400
d8f823
Subject: [PATCH 233/312] [netdrv] net/mlx5e: Move tc tunnel parsing logic with
d8f823
 the rest at tc_tun module
d8f823
d8f823
Message-id: <20200519074934.6303-25-ahleihel@redhat.com>
d8f823
Patchwork-id: 310526
d8f823
Patchwork-instance: patchwork
d8f823
O-Subject: [RHEL8.3 BZ 1663246 24/63] net/mlx5e: Move tc tunnel parsing logic with the rest at tc_tun module
d8f823
Bugzilla: 1790219 1790218 1663246
d8f823
RH-Acked-by: Marcelo Leitner <mleitner@redhat.com>
d8f823
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
d8f823
RH-Acked-by: John Linville <linville@redhat.com>
d8f823
RH-Acked-by: Ivan Vecera <ivecera@redhat.com>
d8f823
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
d8f823
RH-Acked-by: Kamal Heib <kheib@redhat.com>
d8f823
d8f823
Bugzilla: http://bugzilla.redhat.com/1663246
d8f823
Bugzilla: http://bugzilla.redhat.com/1790219
d8f823
Bugzilla: http://bugzilla.redhat.com/1790218
d8f823
Upstream: v5.7-rc1
d8f823
d8f823
commit ea4cd837b99df6693c3aa067ade528f62544c18d
d8f823
Author: Paul Blakey <paulb@mellanox.com>
d8f823
Date:   Sun Feb 16 12:01:32 2020 +0200
d8f823
d8f823
    net/mlx5e: Move tc tunnel parsing logic with the rest at tc_tun module
d8f823
d8f823
    Currently, tunnel parsing is split between en_tc and tc_tun. The next
d8f823
    patch will replace the tunnel fields matching with a register match,
d8f823
    and will not need this parsing.
d8f823
d8f823
    Move the tunnel parsing logic to tc_tun as a pre-step for skipping
d8f823
    it in the next patch.
d8f823
d8f823
    Signed-off-by: Paul Blakey <paulb@mellanox.com>
d8f823
    Reviewed-by: Roi Dayan <roid@mellanox.com>
d8f823
    Reviewed-by: Oz Shlomo <ozsh@mellanox.com>
d8f823
    Reviewed-by: Mark Bloch <markb@mellanox.com>
d8f823
    Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
d8f823
d8f823
Signed-off-by: Alaa Hleihel <ahleihel@redhat.com>
d8f823
Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
d8f823
---
d8f823
 .../net/ethernet/mellanox/mlx5/core/en/tc_tun.c    | 112 ++++++++++++++++++++-
d8f823
 .../net/ethernet/mellanox/mlx5/core/en/tc_tun.h    |   3 +-
d8f823
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c    | 109 +-------------------
d8f823
 3 files changed, 112 insertions(+), 112 deletions(-)
d8f823
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
d8f823
index b855933f6bec..ae497981ce58 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
d8f823
@@ -469,10 +469,15 @@ int mlx5e_tc_tun_parse(struct net_device *filter_dev,
d8f823
 		       struct mlx5e_priv *priv,
d8f823
 		       struct mlx5_flow_spec *spec,
d8f823
 		       struct flow_cls_offload *f,
d8f823
-		       void *headers_c,
d8f823
-		       void *headers_v, u8 *match_level)
d8f823
+		       u8 *match_level)
d8f823
 {
d8f823
 	struct mlx5e_tc_tunnel *tunnel = mlx5e_get_tc_tun(filter_dev);
d8f823
+	struct flow_rule *rule = flow_cls_offload_flow_rule(f);
d8f823
+	void *headers_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria,
d8f823
+				       outer_headers);
d8f823
+	void *headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value,
d8f823
+				       outer_headers);
d8f823
+	struct netlink_ext_ack *extack = f->common.extack;
d8f823
 	int err = 0;
d8f823
 
d8f823
 	if (!tunnel) {
d8f823
@@ -499,6 +504,109 @@ int mlx5e_tc_tun_parse(struct net_device *filter_dev,
d8f823
 			goto out;
d8f823
 	}
d8f823
 
d8f823
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_CONTROL)) {
d8f823
+		struct flow_match_control match;
d8f823
+		u16 addr_type;
d8f823
+
d8f823
+		flow_rule_match_enc_control(rule, &match);
d8f823
+		addr_type = match.key->addr_type;
d8f823
+
d8f823
+		/* For tunnel addr_type used same key id`s as for non-tunnel */
d8f823
+		if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
d8f823
+			struct flow_match_ipv4_addrs match;
d8f823
+
d8f823
+			flow_rule_match_enc_ipv4_addrs(rule, &match);
d8f823
+			MLX5_SET(fte_match_set_lyr_2_4, headers_c,
d8f823
+				 src_ipv4_src_ipv6.ipv4_layout.ipv4,
d8f823
+				 ntohl(match.mask->src));
d8f823
+			MLX5_SET(fte_match_set_lyr_2_4, headers_v,
d8f823
+				 src_ipv4_src_ipv6.ipv4_layout.ipv4,
d8f823
+				 ntohl(match.key->src));
d8f823
+
d8f823
+			MLX5_SET(fte_match_set_lyr_2_4, headers_c,
d8f823
+				 dst_ipv4_dst_ipv6.ipv4_layout.ipv4,
d8f823
+				 ntohl(match.mask->dst));
d8f823
+			MLX5_SET(fte_match_set_lyr_2_4, headers_v,
d8f823
+				 dst_ipv4_dst_ipv6.ipv4_layout.ipv4,
d8f823
+				 ntohl(match.key->dst));
d8f823
+
d8f823
+			MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c,
d8f823
+					 ethertype);
d8f823
+			MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
d8f823
+				 ETH_P_IP);
d8f823
+		} else if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
d8f823
+			struct flow_match_ipv6_addrs match;
d8f823
+
d8f823
+			flow_rule_match_enc_ipv6_addrs(rule, &match);
d8f823
+			memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c,
d8f823
+					    src_ipv4_src_ipv6.ipv6_layout.ipv6),
d8f823
+			       &match.mask->src, MLX5_FLD_SZ_BYTES(ipv6_layout,
d8f823
+								   ipv6));
d8f823
+			memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
d8f823
+					    src_ipv4_src_ipv6.ipv6_layout.ipv6),
d8f823
+			       &match.key->src, MLX5_FLD_SZ_BYTES(ipv6_layout,
d8f823
+								  ipv6));
d8f823
+
d8f823
+			memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c,
d8f823
+					    dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
d8f823
+			       &match.mask->dst, MLX5_FLD_SZ_BYTES(ipv6_layout,
d8f823
+								   ipv6));
d8f823
+			memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
d8f823
+					    dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
d8f823
+			       &match.key->dst, MLX5_FLD_SZ_BYTES(ipv6_layout,
d8f823
+								  ipv6));
d8f823
+
d8f823
+			MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c,
d8f823
+					 ethertype);
d8f823
+			MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
d8f823
+				 ETH_P_IPV6);
d8f823
+		}
d8f823
+	}
d8f823
+
d8f823
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IP)) {
d8f823
+		struct flow_match_ip match;
d8f823
+
d8f823
+		flow_rule_match_enc_ip(rule, &match);
d8f823
+		MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_ecn,
d8f823
+			 match.mask->tos & 0x3);
d8f823
+		MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
d8f823
+			 match.key->tos & 0x3);
d8f823
+
d8f823
+		MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_dscp,
d8f823
+			 match.mask->tos >> 2);
d8f823
+		MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp,
d8f823
+			 match.key->tos  >> 2);
d8f823
+
d8f823
+		MLX5_SET(fte_match_set_lyr_2_4, headers_c, ttl_hoplimit,
d8f823
+			 match.mask->ttl);
d8f823
+		MLX5_SET(fte_match_set_lyr_2_4, headers_v, ttl_hoplimit,
d8f823
+			 match.key->ttl);
d8f823
+
d8f823
+		if (match.mask->ttl &&
d8f823
+		    !MLX5_CAP_ESW_FLOWTABLE_FDB
d8f823
+			(priv->mdev,
d8f823
+			 ft_field_support.outer_ipv4_ttl)) {
d8f823
+			NL_SET_ERR_MSG_MOD(extack,
d8f823
+					   "Matching on TTL is not supported");
d8f823
+			err = -EOPNOTSUPP;
d8f823
+			goto out;
d8f823
+		}
d8f823
+	}
d8f823
+
d8f823
+	/* Enforce DMAC when offloading incoming tunneled flows.
d8f823
+	 * Flow counters require a match on the DMAC.
d8f823
+	 */
d8f823
+	MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, dmac_47_16);
d8f823
+	MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, dmac_15_0);
d8f823
+	ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
d8f823
+				     dmac_47_16), priv->netdev->dev_addr);
d8f823
+
d8f823
+	/* let software handle IP fragments */
d8f823
+	MLX5_SET(fte_match_set_lyr_2_4, headers_c, frag, 1);
d8f823
+	MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
d8f823
+
d8f823
+	return 0;
d8f823
+
d8f823
 out:
d8f823
 	return err;
d8f823
 }
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h
d8f823
index 6f9a78c85ffd..1630f0ec3ad7 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h
d8f823
@@ -76,8 +76,7 @@ int mlx5e_tc_tun_parse(struct net_device *filter_dev,
d8f823
 		       struct mlx5e_priv *priv,
d8f823
 		       struct mlx5_flow_spec *spec,
d8f823
 		       struct flow_cls_offload *f,
d8f823
-		       void *headers_c,
d8f823
-		       void *headers_v, u8 *match_level);
d8f823
+		       u8 *match_level);
d8f823
 
d8f823
 int mlx5e_tc_tun_parse_udp_ports(struct mlx5e_priv *priv,
d8f823
 				 struct mlx5_flow_spec *spec,
d8f823
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
d8f823
index 747979c6601a..3d0a5c63d083 100644
d8f823
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
d8f823
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
d8f823
@@ -1675,122 +1675,15 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv,
d8f823
 			     struct net_device *filter_dev, u8 *match_level)
d8f823
 {
d8f823
 	struct netlink_ext_ack *extack = f->common.extack;
d8f823
-	void *headers_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria,
d8f823
-				       outer_headers);
d8f823
-	void *headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value,
d8f823
-				       outer_headers);
d8f823
-	struct flow_rule *rule = flow_cls_offload_flow_rule(f);
d8f823
 	int err;
d8f823
 
d8f823
-	err = mlx5e_tc_tun_parse(filter_dev, priv, spec, f,
d8f823
-				 headers_c, headers_v, match_level);
d8f823
+	err = mlx5e_tc_tun_parse(filter_dev, priv, spec, f, match_level);
d8f823
 	if (err) {
d8f823
 		NL_SET_ERR_MSG_MOD(extack,
d8f823
 				   "failed to parse tunnel attributes");
d8f823
 		return err;
d8f823
 	}
d8f823
 
d8f823
-	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_CONTROL)) {
d8f823
-		struct flow_match_control match;
d8f823
-		u16 addr_type;
d8f823
-
d8f823
-		flow_rule_match_enc_control(rule, &match);
d8f823
-		addr_type = match.key->addr_type;
d8f823
-
d8f823
-		/* For tunnel addr_type used same key id`s as for non-tunnel */
d8f823
-		if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
d8f823
-			struct flow_match_ipv4_addrs match;
d8f823
-
d8f823
-			flow_rule_match_enc_ipv4_addrs(rule, &match);
d8f823
-			MLX5_SET(fte_match_set_lyr_2_4, headers_c,
d8f823
-				 src_ipv4_src_ipv6.ipv4_layout.ipv4,
d8f823
-				 ntohl(match.mask->src));
d8f823
-			MLX5_SET(fte_match_set_lyr_2_4, headers_v,
d8f823
-				 src_ipv4_src_ipv6.ipv4_layout.ipv4,
d8f823
-				 ntohl(match.key->src));
d8f823
-
d8f823
-			MLX5_SET(fte_match_set_lyr_2_4, headers_c,
d8f823
-				 dst_ipv4_dst_ipv6.ipv4_layout.ipv4,
d8f823
-				 ntohl(match.mask->dst));
d8f823
-			MLX5_SET(fte_match_set_lyr_2_4, headers_v,
d8f823
-				 dst_ipv4_dst_ipv6.ipv4_layout.ipv4,
d8f823
-				 ntohl(match.key->dst));
d8f823
-
d8f823
-			MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c,
d8f823
-					 ethertype);
d8f823
-			MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
d8f823
-				 ETH_P_IP);
d8f823
-		} else if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
d8f823
-			struct flow_match_ipv6_addrs match;
d8f823
-
d8f823
-			flow_rule_match_enc_ipv6_addrs(rule, &match);
d8f823
-			memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c,
d8f823
-					    src_ipv4_src_ipv6.ipv6_layout.ipv6),
d8f823
-			       &match.mask->src, MLX5_FLD_SZ_BYTES(ipv6_layout,
d8f823
-								   ipv6));
d8f823
-			memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
d8f823
-					    src_ipv4_src_ipv6.ipv6_layout.ipv6),
d8f823
-			       &match.key->src, MLX5_FLD_SZ_BYTES(ipv6_layout,
d8f823
-								  ipv6));
d8f823
-
d8f823
-			memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c,
d8f823
-					    dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
d8f823
-			       &match.mask->dst, MLX5_FLD_SZ_BYTES(ipv6_layout,
d8f823
-								   ipv6));
d8f823
-			memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
d8f823
-					    dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
d8f823
-			       &match.key->dst, MLX5_FLD_SZ_BYTES(ipv6_layout,
d8f823
-								  ipv6));
d8f823
-
d8f823
-			MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c,
d8f823
-					 ethertype);
d8f823
-			MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
d8f823
-				 ETH_P_IPV6);
d8f823
-		}
d8f823
-	}
d8f823
-
d8f823
-	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IP)) {
d8f823
-		struct flow_match_ip match;
d8f823
-
d8f823
-		flow_rule_match_enc_ip(rule, &match);
d8f823
-		MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_ecn,
d8f823
-			 match.mask->tos & 0x3);
d8f823
-		MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
d8f823
-			 match.key->tos & 0x3);
d8f823
-
d8f823
-		MLX5_SET(fte_match_set_lyr_2_4, headers_c, ip_dscp,
d8f823
-			 match.mask->tos >> 2);
d8f823
-		MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp,
d8f823
-			 match.key->tos  >> 2);
d8f823
-
d8f823
-		MLX5_SET(fte_match_set_lyr_2_4, headers_c, ttl_hoplimit,
d8f823
-			 match.mask->ttl);
d8f823
-		MLX5_SET(fte_match_set_lyr_2_4, headers_v, ttl_hoplimit,
d8f823
-			 match.key->ttl);
d8f823
-
d8f823
-		if (match.mask->ttl &&
d8f823
-		    !MLX5_CAP_ESW_FLOWTABLE_FDB
d8f823
-			(priv->mdev,
d8f823
-			 ft_field_support.outer_ipv4_ttl)) {
d8f823
-			NL_SET_ERR_MSG_MOD(extack,
d8f823
-					   "Matching on TTL is not supported");
d8f823
-			return -EOPNOTSUPP;
d8f823
-		}
d8f823
-
d8f823
-	}
d8f823
-
d8f823
-	/* Enforce DMAC when offloading incoming tunneled flows.
d8f823
-	 * Flow counters require a match on the DMAC.
d8f823
-	 */
d8f823
-	MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, dmac_47_16);
d8f823
-	MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, dmac_15_0);
d8f823
-	ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
d8f823
-				     dmac_47_16), priv->netdev->dev_addr);
d8f823
-
d8f823
-	/* let software handle IP fragments */
d8f823
-	MLX5_SET(fte_match_set_lyr_2_4, headers_c, frag, 1);
d8f823
-	MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 0);
d8f823
-
d8f823
 	return 0;
d8f823
 }
d8f823
 
d8f823
-- 
d8f823
2.13.6
d8f823