public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Saeed Mahameed <saeed@kernel•org>
To: "David S. Miller" <davem@davemloft•net>,
	Jakub Kicinski <kuba@kernel•org>
Cc: netdev@vger•kernel.org, Maor Dickman <maord@nvidia•com>,
	Roi Dayan <roid@nvidia•com>, Saeed Mahameed <saeedm@nvidia•com>
Subject: [net-next 13/13] net/mlx5e: Allow to match on ICMP parameters
Date: Fri, 12 Mar 2021 15:38:51 -0800	[thread overview]
Message-ID: <20210312233851.494832-14-saeed@kernel.org> (raw)
In-Reply-To: <20210312233851.494832-1-saeed@kernel.org>

From: Maor Dickman <maord@nvidia•com>

Support matching on ICMPv4/6 type and code parameters using misc3
section of match parameters.

Signed-off-by: Maor Dickman <maord@nvidia•com>
Reviewed-by: Roi Dayan <roid@nvidia•com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia•com>
---
 .../net/ethernet/mellanox/mlx5/core/en_tc.c   | 47 +++++++++++++++++++
 include/linux/mlx5/device.h                   |  2 +
 2 files changed, 49 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 121f0a744e55..54ea0dae7ded 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -1961,6 +1961,10 @@ static int __parse_cls_flower(struct mlx5e_priv *priv,
 				    misc_parameters);
 	void *misc_v = MLX5_ADDR_OF(fte_match_param, spec->match_value,
 				    misc_parameters);
+	void *misc_c_3 = MLX5_ADDR_OF(fte_match_param, spec->match_criteria,
+				    misc_parameters_3);
+	void *misc_v_3 = MLX5_ADDR_OF(fte_match_param, spec->match_value,
+				    misc_parameters_3);
 	struct flow_rule *rule = flow_cls_offload_flow_rule(f);
 	struct flow_dissector *dissector = rule->match.dissector;
 	u16 addr_type = 0;
@@ -1990,6 +1994,7 @@ static int __parse_cls_flower(struct mlx5e_priv *priv,
 	      BIT(FLOW_DISSECTOR_KEY_CT) |
 	      BIT(FLOW_DISSECTOR_KEY_ENC_IP) |
 	      BIT(FLOW_DISSECTOR_KEY_ENC_OPTS) |
+	      BIT(FLOW_DISSECTOR_KEY_ICMP) |
 	      BIT(FLOW_DISSECTOR_KEY_MPLS))) {
 		NL_SET_ERR_MSG_MOD(extack, "Unsupported key");
 		netdev_dbg(priv->netdev, "Unsupported key used: 0x%x\n",
@@ -2309,7 +2314,49 @@ static int __parse_cls_flower(struct mlx5e_priv *priv,
 		if (match.mask->flags)
 			*match_level = MLX5_MATCH_L4;
 	}
+	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ICMP)) {
+		struct flow_match_icmp match;
 
+		flow_rule_match_icmp(rule, &match);
+		switch (ip_proto) {
+		case IPPROTO_ICMP:
+			if (!(MLX5_CAP_GEN(priv->mdev, flex_parser_protocols) &
+			      MLX5_FLEX_PROTO_ICMP))
+				return -EOPNOTSUPP;
+			MLX5_SET(fte_match_set_misc3, misc_c_3, icmp_type,
+				 match.mask->type);
+			MLX5_SET(fte_match_set_misc3, misc_v_3, icmp_type,
+				 match.key->type);
+			MLX5_SET(fte_match_set_misc3, misc_c_3, icmp_code,
+				 match.mask->code);
+			MLX5_SET(fte_match_set_misc3, misc_v_3, icmp_code,
+				 match.key->code);
+			break;
+		case IPPROTO_ICMPV6:
+			if (!(MLX5_CAP_GEN(priv->mdev, flex_parser_protocols) &
+			      MLX5_FLEX_PROTO_ICMPV6))
+				return -EOPNOTSUPP;
+			MLX5_SET(fte_match_set_misc3, misc_c_3, icmpv6_type,
+				 match.mask->type);
+			MLX5_SET(fte_match_set_misc3, misc_v_3, icmpv6_type,
+				 match.key->type);
+			MLX5_SET(fte_match_set_misc3, misc_c_3, icmpv6_code,
+				 match.mask->code);
+			MLX5_SET(fte_match_set_misc3, misc_v_3, icmpv6_code,
+				 match.key->code);
+			break;
+		default:
+			NL_SET_ERR_MSG_MOD(extack,
+					   "Code and type matching only with ICMP and ICMPv6");
+			netdev_err(priv->netdev,
+				   "Code and type matching only with ICMP and ICMPv6\n");
+			return -EINVAL;
+		}
+		if (match.mask->code || match.mask->type) {
+			*match_level = MLX5_MATCH_L4;
+			spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_3;
+		}
+	}
 	return 0;
 }
 
diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h
index dc3d2508f5c6..92a029a800a0 100644
--- a/include/linux/mlx5/device.h
+++ b/include/linux/mlx5/device.h
@@ -1142,6 +1142,8 @@ enum mlx5_flex_parser_protos {
 	MLX5_FLEX_PROTO_GENEVE	      = 1 << 3,
 	MLX5_FLEX_PROTO_CW_MPLS_GRE   = 1 << 4,
 	MLX5_FLEX_PROTO_CW_MPLS_UDP   = 1 << 5,
+	MLX5_FLEX_PROTO_ICMP	      = 1 << 8,
+	MLX5_FLEX_PROTO_ICMPV6	      = 1 << 9,
 };
 
 /* MLX5 DEV CAPs */
-- 
2.29.2


      parent reply	other threads:[~2021-03-12 23:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 23:38 [pull request][net-next 00/13] mlx5 updates 2021-03-12 Saeed Mahameed
2021-03-12 23:38 ` [net-next 01/13] net/mlx5: DR, Fixed typo in STE v0 Saeed Mahameed
2021-03-12 23:38 ` [net-next 02/13] net/mlx5: DR, Remove unneeded rx_decap_l3 function for STEv1 Saeed Mahameed
2021-03-12 23:38 ` [net-next 03/13] net/mlx5: DR, Add missing vhca_id consume from STEv1 Saeed Mahameed
2021-03-12 23:38 ` [net-next 04/13] net/mlx5: use kvfree() for memory allocated with kvzalloc() Saeed Mahameed
2021-03-12 23:38 ` [net-next 05/13] net/mlx5: remove unneeded semicolon Saeed Mahameed
2021-03-12 23:38 ` [net-next 06/13] net/mlx5: Read congestion counters from all ports when lag is active Saeed Mahameed
2021-03-12 23:38 ` [net-next 07/13] net/mlx5e: Remove redundant newline in NL_SET_ERR_MSG_MOD Saeed Mahameed
2021-03-12 23:38 ` [net-next 08/13] net/mlx5e: Use net_prefetchw instead of prefetchw in MPWQE TX datapath Saeed Mahameed
2021-03-12 23:38 ` [net-next 09/13] net/mlx5e: Dump ICOSQ WQE descriptor on CQE with error events Saeed Mahameed
2021-03-12 23:38 ` [net-next 10/13] net/mlx5e: allocate 'indirection_rqt' buffer dynamically Saeed Mahameed
2021-03-12 23:38 ` [net-next 11/13] net/mlx5: Display the command index in command mailbox dump Saeed Mahameed
2021-03-12 23:38 ` [net-next 12/13] net/mlx5: CT: Add support for mirroring Saeed Mahameed
2021-03-12 23:38 ` Saeed Mahameed [this message]

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=20210312233851.494832-14-saeed@kernel.org \
    --to=saeed@kernel$(echo .)org \
    --cc=davem@davemloft$(echo .)net \
    --cc=kuba@kernel$(echo .)org \
    --cc=maord@nvidia$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=roid@nvidia$(echo .)com \
    --cc=saeedm@nvidia$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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