1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
3 
4 #ifndef __MLX5_EN_FLOW_METER_H__
5 #define __MLX5_EN_FLOW_METER_H__
6 
7 struct mlx5e_post_meter_priv;
8 struct mlx5e_flow_meter_aso_obj;
9 struct mlx5e_flow_meters;
10 struct mlx5_flow_attr;
11 
12 enum mlx5e_flow_meter_mode {
13 	MLX5_RATE_LIMIT_BPS,
14 	MLX5_RATE_LIMIT_PPS,
15 };
16 
17 struct mlx5e_flow_meter_params {
18 	enum mlx5e_flow_meter_mode mode;
19 	 /* police action index */
20 	u32 index;
21 	u64 rate;
22 	u64 burst;
23 };
24 
25 struct mlx5e_flow_meter_handle {
26 	struct mlx5e_flow_meters *flow_meters;
27 	struct mlx5e_flow_meter_aso_obj *meters_obj;
28 	u32 obj_id;
29 	u8 idx;
30 
31 	int refcnt;
32 	struct hlist_node hlist;
33 	struct mlx5e_flow_meter_params params;
34 
35 	struct mlx5_fc *green_counter;
36 	struct mlx5_fc *red_counter;
37 };
38 
39 struct mlx5e_meter_attr {
40 	struct mlx5e_flow_meter_params params;
41 	struct mlx5e_flow_meter_handle *meter;
42 	struct mlx5e_post_meter_priv *post_meter;
43 };
44 
45 int
46 mlx5e_tc_meter_modify(struct mlx5_core_dev *mdev,
47 		      struct mlx5e_flow_meter_handle *meter,
48 		      struct mlx5e_flow_meter_params *meter_params);
49 
50 struct mlx5e_flow_meter_handle *
51 mlx5e_tc_meter_get(struct mlx5_core_dev *mdev, struct mlx5e_flow_meter_params *params);
52 void
53 mlx5e_tc_meter_put(struct mlx5e_flow_meter_handle *meter);
54 int
55 mlx5e_tc_meter_update(struct mlx5e_flow_meter_handle *meter,
56 		      struct mlx5e_flow_meter_params *params);
57 struct mlx5e_flow_meter_handle *
58 mlx5e_tc_meter_replace(struct mlx5_core_dev *mdev, struct mlx5e_flow_meter_params *params);
59 
60 enum mlx5_flow_namespace_type
61 mlx5e_tc_meter_get_namespace(struct mlx5e_flow_meters *flow_meters);
62 
63 struct mlx5e_flow_meters *
64 mlx5e_flow_meters_init(struct mlx5e_priv *priv,
65 		       enum mlx5_flow_namespace_type ns_type,
66 		       struct mlx5e_post_act *post_action);
67 void
68 mlx5e_flow_meters_cleanup(struct mlx5e_flow_meters *flow_meters);
69 
70 void
71 mlx5e_tc_meter_get_stats(struct mlx5e_flow_meter_handle *meter,
72 			 u64 *bytes, u64 *packets, u64 *drops, u64 *lastuse);
73 
74 #endif /* __MLX5_EN_FLOW_METER_H__ */
75