netdev.vger.kernel.org archive mirror
 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, Roi Dayan <roid@nvidia.com>,
	Oz Shlomo <ozsh@nvidia.com>, Saeed Mahameed <saeedm@nvidia.com>
Subject: [net-next v0 12/16] net/mlx5e: TC action parsing loop
Date: Tue, 14 Dec 2021 21:32:56 -0800	[thread overview]
Message-ID: <20211215053300.130679-13-saeed@kernel.org> (raw)
In-Reply-To: <20211215053300.130679-1-saeed@kernel.org>

From: Roi Dayan <roid@nvidia.com>

Introduce a common function to implement the generic parsing loop.
The same function can be used for parsing NIC and FDB (Switchdev mode) flows.

Signed-off-by: Roi Dayan <roid@nvidia.com>
Reviewed-by: Oz Shlomo <ozsh@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_tc.c   | 88 ++++++++++---------
 1 file changed, 46 insertions(+), 42 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 7fc89d41d971..a3f414171ca5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -3138,6 +3138,39 @@ add_vlan_prio_tag_rewrite_action(struct mlx5e_priv *priv,
 						    extack);
 }
 
+static int
+parse_tc_actions(struct mlx5e_tc_act_parse_state *parse_state,
+		 struct flow_action *flow_action)
+{
+	struct netlink_ext_ack *extack = parse_state->extack;
+	struct mlx5e_tc_flow *flow = parse_state->flow;
+	struct mlx5_flow_attr *attr = flow->attr;
+	enum mlx5_flow_namespace_type ns_type;
+	struct mlx5e_priv *priv = flow->priv;
+	const struct flow_action_entry *act;
+	struct mlx5e_tc_act *tc_act;
+	int err, i;
+
+	ns_type = mlx5e_get_flow_namespace(flow);
+
+	flow_action_for_each(i, act, flow_action) {
+		tc_act = mlx5e_tc_act_get(act->id, ns_type);
+		if (!tc_act) {
+			NL_SET_ERR_MSG_MOD(extack, "Not implemented offload action");
+			return -EOPNOTSUPP;
+		}
+
+		if (!tc_act->can_offload(parse_state, act, i))
+			return -EOPNOTSUPP;
+
+		err = tc_act->parse_action(parse_state, act, priv, attr);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 static int
 actions_prepare_mod_hdr_actions(struct mlx5e_priv *priv,
 				struct mlx5e_tc_flow *flow,
@@ -3204,11 +3237,8 @@ parse_tc_nic_actions(struct mlx5e_priv *priv,
 	struct mlx5e_tc_act_parse_state *parse_state;
 	struct mlx5e_tc_flow_parse_attr *parse_attr;
 	struct mlx5_flow_attr *attr = flow->attr;
-	enum mlx5_flow_namespace_type ns_type;
-	const struct flow_action_entry *act;
 	struct pedit_headers_action *hdrs;
-	struct mlx5e_tc_act *tc_act;
-	int err, i;
+	int err;
 
 	err = flow_action_supported(flow_action, extack);
 	if (err)
@@ -3219,23 +3249,11 @@ parse_tc_nic_actions(struct mlx5e_priv *priv,
 	parse_state = &parse_attr->parse_state;
 	mlx5e_tc_act_init_parse_state(parse_state, flow, flow_action, extack);
 	parse_state->ct_priv = get_ct_priv(priv);
-	ns_type = mlx5e_get_flow_namespace(flow);
 	hdrs = parse_state->hdrs;
 
-	flow_action_for_each(i, act, flow_action) {
-		tc_act = mlx5e_tc_act_get(act->id, ns_type);
-		if (!tc_act) {
-			NL_SET_ERR_MSG_MOD(extack, "Not implemented offload action");
-			return -EOPNOTSUPP;
-		}
-
-		if (!tc_act->can_offload(parse_state, act, i))
-			return -EOPNOTSUPP;
-
-		err = tc_act->parse_action(parse_state, act, priv, attr);
-		if (err)
-			return err;
-	}
+	err = parse_tc_actions(parse_state, flow_action);
+	if (err)
+		return err;
 
 	if (attr->dest_chain && parse_attr->mirred_ifindex[0]) {
 		NL_SET_ERR_MSG(extack, "Mirroring goto chain rules isn't supported");
@@ -3337,21 +3355,19 @@ int mlx5e_set_fwd_to_int_port_actions(struct mlx5e_priv *priv,
 	return 0;
 }
 
-static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
-				struct flow_action *flow_action,
-				struct mlx5e_tc_flow *flow,
-				struct netlink_ext_ack *extack)
+static int
+parse_tc_fdb_actions(struct mlx5e_priv *priv,
+		     struct flow_action *flow_action,
+		     struct mlx5e_tc_flow *flow,
+		     struct netlink_ext_ack *extack)
 {
 	struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
 	struct mlx5e_tc_act_parse_state *parse_state;
 	struct mlx5e_tc_flow_parse_attr *parse_attr;
 	struct mlx5_flow_attr *attr = flow->attr;
-	enum mlx5_flow_namespace_type ns_type;
-	const struct flow_action_entry *act;
 	struct mlx5_esw_flow_attr *esw_attr;
 	struct pedit_headers_action *hdrs;
-	struct mlx5e_tc_act *tc_act;
-	int err, i;
+	int err;
 
 	err = flow_action_supported(flow_action, extack);
 	if (err)
@@ -3362,23 +3378,11 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
 	parse_state = &parse_attr->parse_state;
 	mlx5e_tc_act_init_parse_state(parse_state, flow, flow_action, extack);
 	parse_state->ct_priv = get_ct_priv(priv);
-	ns_type = mlx5e_get_flow_namespace(flow);
 	hdrs = parse_state->hdrs;
 
-	flow_action_for_each(i, act, flow_action) {
-		tc_act = mlx5e_tc_act_get(act->id, ns_type);
-		if (!tc_act) {
-			NL_SET_ERR_MSG_MOD(extack, "Not implemented offload action");
-			return -EOPNOTSUPP;
-		}
-
-		if (!tc_act->can_offload(parse_state, act, i))
-			return -EOPNOTSUPP;
-
-		err = tc_act->parse_action(parse_state, act, priv, attr);
-		if (err)
-			return err;
-	}
+	err = parse_tc_actions(parse_state, flow_action);
+	if (err)
+		return err;
 
 	/* Forward to/from internal port can only have 1 dest */
 	if ((netif_is_ovs_master(parse_attr->filter_dev) || esw_attr->dest_int_port) &&
-- 
2.31.1


  parent reply	other threads:[~2021-12-15  5:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15  5:32 [pull request][net-next v0 00/16] mlx5 updates 2021-12-14 Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 01/16] net/mlx5e: Add tc action infrastructure Saeed Mahameed
2021-12-15 14:50   ` patchwork-bot+netdevbpf
2021-12-15  5:32 ` [net-next v0 02/16] net/mlx5e: Add goto to tc action infra Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 03/16] net/mlx5e: Add tunnel encap/decap " Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 04/16] net/mlx5e: Add csum " Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 05/16] net/mlx5e: Add pedit " Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 06/16] net/mlx5e: Add vlan push/pop/mangle " Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 07/16] net/mlx5e: Add mpls push/pop " Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 08/16] net/mlx5e: Add mirred/redirect " Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 09/16] net/mlx5e: Add ct " Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 10/16] net/mlx5e: Add sample and ptype to tc_action infra Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 11/16] net/mlx5e: Add redirect ingress to tc action infra Saeed Mahameed
2021-12-15  5:32 ` Saeed Mahameed [this message]
2021-12-15  5:32 ` [net-next v0 13/16] net/mlx5e: Move sample attr allocation to tc_action sample parse op Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 14/16] net/mlx5e: Add post_parse() op to tc action infrastructure Saeed Mahameed
2021-12-15  5:32 ` [net-next v0 15/16] net/mlx5e: Move vlan action chunk into tc action vlan post parse op Saeed Mahameed
2021-12-15  5:33 ` [net-next v0 16/16] net/mlx5e: Move goto action checks into tc_action goto " Saeed Mahameed

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=20211215053300.130679-13-saeed@kernel.org \
    --to=saeed@kernel.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ozsh@nvidia.com \
    --cc=roid@nvidia.com \
    --cc=saeedm@nvidia.com \
    /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).