1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2021 Mellanox Technologies. */
3 
4 #ifndef __MLX5_EN_TC_SAMPLE_H__
5 #define __MLX5_EN_TC_SAMPLE_H__
6 
7 #include "eswitch.h"
8 
9 struct mlx5_flow_attr;
10 struct mlx5e_tc_psample;
11 struct mlx5e_post_act;
12 
13 struct mlx5e_sample_attr {
14 	u32 group_num;
15 	u32 rate;
16 	u32 trunc_size;
17 	u32 restore_obj_id;
18 	u32 sampler_id;
19 	struct mlx5e_sample_flow *sample_flow;
20 };
21 
22 #if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE)
23 
24 void mlx5e_tc_sample_skb(struct sk_buff *skb, struct mlx5_mapped_obj *mapped_obj);
25 
26 struct mlx5_flow_handle *
27 mlx5e_tc_sample_offload(struct mlx5e_tc_psample *sample_priv,
28 			struct mlx5_flow_spec *spec,
29 			struct mlx5_flow_attr *attr);
30 
31 void
32 mlx5e_tc_sample_unoffload(struct mlx5e_tc_psample *sample_priv,
33 			  struct mlx5_flow_handle *rule,
34 			  struct mlx5_flow_attr *attr);
35 
36 struct mlx5e_tc_psample *
37 mlx5e_tc_sample_init(struct mlx5_eswitch *esw, struct mlx5e_post_act *post_act);
38 
39 void
40 mlx5e_tc_sample_cleanup(struct mlx5e_tc_psample *tc_psample);
41 
42 #else /* CONFIG_MLX5_TC_SAMPLE */
43 
44 static inline struct mlx5_flow_handle *
mlx5e_tc_sample_offload(struct mlx5e_tc_psample * tc_psample,struct mlx5_flow_spec * spec,struct mlx5_flow_attr * attr)45 mlx5e_tc_sample_offload(struct mlx5e_tc_psample *tc_psample,
46 			struct mlx5_flow_spec *spec,
47 			struct mlx5_flow_attr *attr)
48 { return ERR_PTR(-EOPNOTSUPP); }
49 
50 static inline void
mlx5e_tc_sample_unoffload(struct mlx5e_tc_psample * tc_psample,struct mlx5_flow_handle * rule,struct mlx5_flow_attr * attr)51 mlx5e_tc_sample_unoffload(struct mlx5e_tc_psample *tc_psample,
52 			  struct mlx5_flow_handle *rule,
53 			  struct mlx5_flow_attr *attr) {}
54 
55 static inline struct mlx5e_tc_psample *
mlx5e_tc_sample_init(struct mlx5_eswitch * esw,struct mlx5e_post_act * post_act)56 mlx5e_tc_sample_init(struct mlx5_eswitch *esw, struct mlx5e_post_act *post_act)
57 { return ERR_PTR(-EOPNOTSUPP); }
58 
59 static inline void
mlx5e_tc_sample_cleanup(struct mlx5e_tc_psample * tc_psample)60 mlx5e_tc_sample_cleanup(struct mlx5e_tc_psample *tc_psample) {}
61 
62 static inline void
mlx5e_tc_sample_skb(struct sk_buff * skb,struct mlx5_mapped_obj * mapped_obj)63 mlx5e_tc_sample_skb(struct sk_buff *skb, struct mlx5_mapped_obj *mapped_obj) {}
64 
65 #endif /* CONFIG_MLX5_TC_SAMPLE */
66 #endif /* __MLX5_EN_TC_SAMPLE_H__ */
67