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 			u32 tunnel_id);
31 
32 void
33 mlx5e_tc_sample_unoffload(struct mlx5e_tc_psample *sample_priv,
34 			  struct mlx5_flow_handle *rule,
35 			  struct mlx5_flow_attr *attr);
36 
37 struct mlx5e_tc_psample *
38 mlx5e_tc_sample_init(struct mlx5_eswitch *esw, struct mlx5e_post_act *post_act);
39 
40 void
41 mlx5e_tc_sample_cleanup(struct mlx5e_tc_psample *tc_psample);
42 
43 #else /* CONFIG_MLX5_TC_SAMPLE */
44 
45 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,u32 tunnel_id)46 mlx5e_tc_sample_offload(struct mlx5e_tc_psample *tc_psample,
47 			struct mlx5_flow_spec *spec,
48 			struct mlx5_flow_attr *attr,
49 			u32 tunnel_id)
50 { return ERR_PTR(-EOPNOTSUPP); }
51 
52 static inline void
mlx5e_tc_sample_unoffload(struct mlx5e_tc_psample * tc_psample,struct mlx5_flow_handle * rule,struct mlx5_flow_attr * attr)53 mlx5e_tc_sample_unoffload(struct mlx5e_tc_psample *tc_psample,
54 			  struct mlx5_flow_handle *rule,
55 			  struct mlx5_flow_attr *attr) {}
56 
57 static inline struct mlx5e_tc_psample *
mlx5e_tc_sample_init(struct mlx5_eswitch * esw,struct mlx5e_post_act * post_act)58 mlx5e_tc_sample_init(struct mlx5_eswitch *esw, struct mlx5e_post_act *post_act)
59 { return ERR_PTR(-EOPNOTSUPP); }
60 
61 static inline void
mlx5e_tc_sample_cleanup(struct mlx5e_tc_psample * tc_psample)62 mlx5e_tc_sample_cleanup(struct mlx5e_tc_psample *tc_psample) {}
63 
64 static inline void
mlx5e_tc_sample_skb(struct sk_buff * skb,struct mlx5_mapped_obj * mapped_obj)65 mlx5e_tc_sample_skb(struct sk_buff *skb, struct mlx5_mapped_obj *mapped_obj) {}
66 
67 #endif /* CONFIG_MLX5_TC_SAMPLE */
68 #endif /* __MLX5_EN_TC_SAMPLE_H__ */
69