net/mlx5e: Add csum to tc action infra
authorRoi Dayan <roid@nvidia.com>
Wed, 21 Jul 2021 07:30:40 +0000 (10:30 +0300)
committerSaeed Mahameed <saeedm@nvidia.com>
Wed, 15 Dec 2021 05:29:42 +0000 (21:29 -0800)
Add parsing support by implementing struct mlx5e_tc_act
for this action.

Signed-off-by: Roi Dayan <roid@nvidia.com>
Reviewed-by: Oz Shlomo <ozsh@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/Makefile
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/act.c
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/act.h
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/csum.c [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

index 407e42c6f06299633e66aaf5c79204c19d13993b..c148d0fea6f1a3abd78533e2e76dbdbc5f1a6fde 100644 (file)
@@ -49,7 +49,7 @@ mlx5_core-$(CONFIG_MLX5_CLS_ACT)     += en_tc.o en/rep/tc.o en/rep/neigh.o \
 
 mlx5_core-$(CONFIG_MLX5_CLS_ACT)     += en/tc/act/act.o en/tc/act/drop.o en/tc/act/trap.o \
                                        en/tc/act/accept.o en/tc/act/mark.o en/tc/act/goto.o \
-                                       en/tc/act/tun.o
+                                       en/tc/act/tun.o en/tc/act/csum.o
 
 mlx5_core-$(CONFIG_MLX5_TC_CT)      += en/tc_ct.o
 mlx5_core-$(CONFIG_MLX5_TC_SAMPLE)   += en/tc/sample.o
index 4b406153db72e0d77ecb406e0411774ce3ff649e..449a9425f1070578621312d9421e2442bd38df87 100644 (file)
@@ -20,6 +20,9 @@ static struct mlx5e_tc_act *tc_acts_fdb[NUM_FLOW_ACTIONS] = {
        NULL, /* FLOW_ACTION_VLAN_MANGLE, */
        &mlx5e_tc_act_tun_encap,
        &mlx5e_tc_act_tun_decap,
+       NULL, /* FLOW_ACTION_MANGLE, */
+       NULL, /* FLOW_ACTION_ADD, */
+       &mlx5e_tc_act_csum,
 };
 
 /* Must be aligned with enum flow_action_id. */
@@ -39,7 +42,7 @@ static struct mlx5e_tc_act *tc_acts_nic[NUM_FLOW_ACTIONS] = {
        NULL, /* FLOW_ACTION_TUNNEL_DECAP, */
        NULL, /* FLOW_ACTION_MANGLE, */
        NULL, /* FLOW_ACTION_ADD, */
-       NULL, /* FLOW_ACTION_CSUM, */
+       &mlx5e_tc_act_csum,
        &mlx5e_tc_act_mark,
 };
 
index b0d6333b24a3ea551d62444cb001b311e388a522..da19484add62142f9e3eef8ea0c16d1c4ed76b7a 100644 (file)
@@ -37,6 +37,7 @@ extern struct mlx5e_tc_act mlx5e_tc_act_mark;
 extern struct mlx5e_tc_act mlx5e_tc_act_goto;
 extern struct mlx5e_tc_act mlx5e_tc_act_tun_encap;
 extern struct mlx5e_tc_act mlx5e_tc_act_tun_decap;
+extern struct mlx5e_tc_act mlx5e_tc_act_csum;
 
 struct mlx5e_tc_act *
 mlx5e_tc_act_get(enum flow_action_id act_id,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/csum.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/csum.c
new file mode 100644 (file)
index 0000000..29920ef
--- /dev/null
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+// Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#include <linux/tc_act/tc_csum.h>
+#include "act.h"
+#include "en/tc_priv.h"
+
+static bool
+csum_offload_supported(struct mlx5e_priv *priv,
+                      u32 action,
+                      u32 update_flags,
+                      struct netlink_ext_ack *extack)
+{
+       u32 prot_flags = TCA_CSUM_UPDATE_FLAG_IPV4HDR | TCA_CSUM_UPDATE_FLAG_TCP |
+                        TCA_CSUM_UPDATE_FLAG_UDP;
+
+       /*  The HW recalcs checksums only if re-writing headers */
+       if (!(action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)) {
+               NL_SET_ERR_MSG_MOD(extack,
+                                  "TC csum action is only offloaded with pedit");
+               netdev_warn(priv->netdev,
+                           "TC csum action is only offloaded with pedit\n");
+               return false;
+       }
+
+       if (update_flags & ~prot_flags) {
+               NL_SET_ERR_MSG_MOD(extack,
+                                  "can't offload TC csum action for some header/s");
+               netdev_warn(priv->netdev,
+                           "can't offload TC csum action for some header/s - flags %#x\n",
+                           update_flags);
+               return false;
+       }
+
+       return true;
+}
+
+static bool
+tc_act_can_offload_csum(struct mlx5e_tc_act_parse_state *parse_state,
+                       const struct flow_action_entry *act,
+                       int act_index)
+{
+       struct mlx5e_tc_flow *flow = parse_state->flow;
+
+       return csum_offload_supported(flow->priv, flow->attr->action,
+                                     act->csum_flags, parse_state->extack);
+}
+
+static int
+tc_act_parse_csum(struct mlx5e_tc_act_parse_state *parse_state,
+                 const struct flow_action_entry *act,
+                 struct mlx5e_priv *priv,
+                 struct mlx5_flow_attr *attr)
+{
+       return 0;
+}
+
+struct mlx5e_tc_act mlx5e_tc_act_csum = {
+       .can_offload = tc_act_can_offload_csum,
+       .parse_action = tc_act_parse_csum,
+};
index 8b96d88d16918c4f407c117fe5e5ba538e3978e8..73132517c6a0a1b5d9ad94d0ff5edeec621d14e9 100644 (file)
@@ -41,7 +41,6 @@
 #include <linux/completion.h>
 #include <linux/if_macvlan.h>
 #include <net/tc_act/tc_pedit.h>
-#include <net/tc_act/tc_csum.h>
 #include <net/psample.h>
 #include <net/arp.h>
 #include <net/ipv6_stubs.h>
@@ -3008,35 +3007,6 @@ out_dealloc_parsed_actions:
        return err;
 }
 
-static bool csum_offload_supported(struct mlx5e_priv *priv,
-                                  u32 action,
-                                  u32 update_flags,
-                                  struct netlink_ext_ack *extack)
-{
-       u32 prot_flags = TCA_CSUM_UPDATE_FLAG_IPV4HDR | TCA_CSUM_UPDATE_FLAG_TCP |
-                        TCA_CSUM_UPDATE_FLAG_UDP;
-
-       /*  The HW recalcs checksums only if re-writing headers */
-       if (!(action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)) {
-               NL_SET_ERR_MSG_MOD(extack,
-                                  "TC csum action is only offloaded with pedit");
-               netdev_warn(priv->netdev,
-                           "TC csum action is only offloaded with pedit\n");
-               return false;
-       }
-
-       if (update_flags & ~prot_flags) {
-               NL_SET_ERR_MSG_MOD(extack,
-                                  "can't offload TC csum action for some header/s");
-               netdev_warn(priv->netdev,
-                           "can't offload TC csum action for some header/s - flags %#x\n",
-                           update_flags);
-               return false;
-       }
-
-       return true;
-}
-
 struct ip_ttl_word {
        __u8    ttl;
        __u8    protocol;
@@ -3457,13 +3427,6 @@ parse_tc_nic_actions(struct mlx5e_priv *priv,
                                return err;
 
                        break;
-               case FLOW_ACTION_CSUM:
-                       if (csum_offload_supported(priv, attr->action,
-                                                  act->csum_flags,
-                                                  extack))
-                               break;
-
-                       return -EOPNOTSUPP;
                case FLOW_ACTION_REDIRECT: {
                        struct net_device *peer_dev = act->dev;
 
@@ -3894,12 +3857,6 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                                esw_attr->split_count = esw_attr->out_count;
                        }
                        break;
-               case FLOW_ACTION_CSUM:
-                       if (csum_offload_supported(priv, attr->action,
-                                                  act->csum_flags, extack))
-                               break;
-
-                       return -EOPNOTSUPP;
                case FLOW_ACTION_REDIRECT_INGRESS: {
                        struct net_device *out_dev;