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 	u32 mtu;
24 };
25 
26 struct mlx5e_flow_meter_handle {
27 	struct mlx5e_flow_meters *flow_meters;
28 	struct mlx5e_flow_meter_aso_obj *meters_obj;
29 	u32 obj_id;
30 	u8 idx;
31 
32 	int refcnt;
33 	struct hlist_node hlist;
34 	struct mlx5e_flow_meter_params params;
35 
36 	struct mlx5_fc *act_counter;
37 	struct mlx5_fc *drop_counter;
38 };
39 
40 struct mlx5e_meter_attr {
41 	struct mlx5e_flow_meter_params params;
42 	struct mlx5e_flow_meter_handle *meter;
43 	struct mlx5e_post_meter_priv *post_meter;
44 };
45 
46 int
47 mlx5e_tc_meter_modify(struct mlx5_core_dev *mdev,
48 		      struct mlx5e_flow_meter_handle *meter,
49 		      struct mlx5e_flow_meter_params *meter_params);
50 
51 struct mlx5e_flow_meter_handle *
52 mlx5e_tc_meter_get(struct mlx5_core_dev *mdev, struct mlx5e_flow_meter_params *params);
53 void
54 mlx5e_tc_meter_put(struct mlx5e_flow_meter_handle *meter);
55 int
56 mlx5e_tc_meter_update(struct mlx5e_flow_meter_handle *meter,
57 		      struct mlx5e_flow_meter_params *params);
58 struct mlx5e_flow_meter_handle *
59 mlx5e_tc_meter_replace(struct mlx5_core_dev *mdev, struct mlx5e_flow_meter_params *params);
60 
61 enum mlx5_flow_namespace_type
62 mlx5e_tc_meter_get_namespace(struct mlx5e_flow_meters *flow_meters);
63 
64 struct mlx5e_flow_meters *
65 mlx5e_flow_meters_init(struct mlx5e_priv *priv,
66 		       enum mlx5_flow_namespace_type ns_type,
67 		       struct mlx5e_post_act *post_action);
68 void
69 mlx5e_flow_meters_cleanup(struct mlx5e_flow_meters *flow_meters);
70 
71 void
72 mlx5e_tc_meter_get_stats(struct mlx5e_flow_meter_handle *meter,
73 			 u64 *bytes, u64 *packets, u64 *drops, u64 *lastuse);
74 
75 #endif /* __MLX5_EN_FLOW_METER_H__ */
76