net/mlx5e: TC, Parse sample action
authorChris Mi <cmi@nvidia.com>
Mon, 31 Aug 2020 05:28:35 +0000 (13:28 +0800)
committerSaeed Mahameed <saeedm@nvidia.com>
Wed, 7 Apr 2021 04:36:03 +0000 (21:36 -0700)
Parse TC sample action and save sample parameters in flow attribute
data structure.

Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Oz Shlomo <ozsh@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h [new file with mode: 0644]
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

index c223591..d1599b7 100644 (file)
@@ -27,6 +27,7 @@ enum {
        MLX5E_TC_FLOW_FLAG_L3_TO_L2_DECAP        = MLX5E_TC_FLOW_BASE + 8,
        MLX5E_TC_FLOW_FLAG_TUN_RX                = MLX5E_TC_FLOW_BASE + 9,
        MLX5E_TC_FLOW_FLAG_FAILED                = MLX5E_TC_FLOW_BASE + 10,
+       MLX5E_TC_FLOW_FLAG_SAMPLE                = MLX5E_TC_FLOW_BASE + 11,
 };
 
 struct mlx5e_tc_flow_parse_attr {
index c938215..85782d1 100644 (file)
@@ -47,6 +47,7 @@
 #include <net/tc_act/tc_pedit.h>
 #include <net/tc_act/tc_csum.h>
 #include <net/tc_act/tc_mpls.h>
+#include <net/psample.h>
 #include <net/arp.h>
 #include <net/ipv6_stubs.h>
 #include <net/bareudp.h>
@@ -1481,6 +1482,7 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
        if (flow_flag_test(flow, L3_TO_L2_DECAP))
                mlx5e_detach_decap(priv, flow);
 
+       kfree(flow->attr->esw_attr->sample);
        kfree(flow->attr);
 }
 
@@ -3627,6 +3629,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
        bool ft_flow = mlx5e_is_ft_flow(flow);
        const struct flow_action_entry *act;
        struct mlx5_esw_flow_attr *esw_attr;
+       struct mlx5_sample_attr sample = {};
        bool encap = false, decap = false;
        u32 action = attr->action;
        int err, i, if_count = 0;
@@ -3881,6 +3884,10 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                        attr->dest_chain = act->chain_index;
                        break;
                case FLOW_ACTION_CT:
+                       if (flow_flag_test(flow, SAMPLE)) {
+                               NL_SET_ERR_MSG_MOD(extack, "Sample action with connection tracking is not supported");
+                               return -EOPNOTSUPP;
+                       }
                        err = mlx5_tc_ct_parse_action(get_ct_priv(priv), attr, act, extack);
                        if (err)
                                return err;
@@ -3888,6 +3895,17 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                        flow_flag_set(flow, CT);
                        esw_attr->split_count = esw_attr->out_count;
                        break;
+               case FLOW_ACTION_SAMPLE:
+                       if (flow_flag_test(flow, CT)) {
+                               NL_SET_ERR_MSG_MOD(extack, "Sample action with connection tracking is not supported");
+                               return -EOPNOTSUPP;
+                       }
+                       sample.rate = act->sample.rate;
+                       sample.group_num = act->sample.psample_group->group_num;
+                       if (act->sample.truncate)
+                               sample.trunc_size = act->sample.trunc_size;
+                       flow_flag_set(flow, SAMPLE);
+                       break;
                default:
                        NL_SET_ERR_MSG_MOD(extack, "The offload action is not supported");
                        return -EOPNOTSUPP;
@@ -3966,6 +3984,16 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,
                return -EOPNOTSUPP;
        }
 
+       /* Allocate sample attribute only when there is a sample action and
+        * no errors after parsing.
+        */
+       if (flow_flag_test(flow, SAMPLE)) {
+               esw_attr->sample = kzalloc(sizeof(*esw_attr->sample), GFP_KERNEL);
+               if (!esw_attr->sample)
+                       return -ENOMEM;
+               *esw_attr->sample = sample;
+       }
+
        return 0;
 }
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h b/drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h
new file mode 100644 (file)
index 0000000..35a5e6d
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+/* Copyright (c) 2021 Mellanox Technologies. */
+
+#ifndef __MLX5_EN_TC_SAMPLE_H__
+#define __MLX5_EN_TC_SAMPLE_H__
+
+struct mlx5_sample_attr {
+       u32 group_num;
+       u32 rate;
+       u32 trunc_size;
+};
+
+#endif /* __MLX5_EN_TC_SAMPLE_H__ */
index a973963..9b26bd6 100644 (file)
@@ -46,6 +46,7 @@
 #include "lib/fs_chains.h"
 #include "sf/sf.h"
 #include "en/tc_ct.h"
+#include "esw/sample.h"
 
 enum mlx5_mapped_obj_type {
        MLX5_MAPPED_OBJ_CHAIN,
@@ -440,6 +441,7 @@ struct mlx5_esw_flow_attr {
        } dests[MLX5_MAX_FLOW_FWD_VPORTS];
        struct mlx5_rx_tun_attr *rx_tun_attr;
        struct mlx5_pkt_reformat *decap_pkt_reformat;
+       struct mlx5_sample_attr *sample;
 };
 
 int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,