1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2020, Mellanox Technologies inc. All rights reserved. */
3 
4 #ifndef __MLX5E_EN_QOS_H
5 #define __MLX5E_EN_QOS_H
6 
7 #include <linux/mlx5/driver.h>
8 
9 #define MLX5E_QOS_MAX_LEAF_NODES 256
10 
11 struct mlx5e_priv;
12 struct mlx5e_channels;
13 struct mlx5e_channel;
14 
15 int mlx5e_qos_bytes_rate_check(struct mlx5_core_dev *mdev, u64 nbytes);
16 int mlx5e_qos_max_leaf_nodes(struct mlx5_core_dev *mdev);
17 int mlx5e_qos_cur_leaf_nodes(struct mlx5e_priv *priv);
18 
19 /* TX datapath API */
20 int mlx5e_get_txq_by_classid(struct mlx5e_priv *priv, u16 classid);
21 struct mlx5e_txqsq *mlx5e_get_sq(struct mlx5e_priv *priv, int qid);
22 
23 /* SQ lifecycle */
24 int mlx5e_qos_open_queues(struct mlx5e_priv *priv, struct mlx5e_channels *chs);
25 void mlx5e_qos_activate_queues(struct mlx5e_priv *priv);
26 void mlx5e_qos_deactivate_queues(struct mlx5e_channel *c);
27 void mlx5e_qos_close_queues(struct mlx5e_channel *c);
28 
29 /* HTB API */
30 int mlx5e_htb_root_add(struct mlx5e_priv *priv, u16 htb_maj_id, u16 htb_defcls,
31 		       struct netlink_ext_ack *extack);
32 int mlx5e_htb_root_del(struct mlx5e_priv *priv);
33 int mlx5e_htb_leaf_alloc_queue(struct mlx5e_priv *priv, u16 classid,
34 			       u32 parent_classid, u64 rate, u64 ceil,
35 			       struct netlink_ext_ack *extack);
36 int mlx5e_htb_leaf_to_inner(struct mlx5e_priv *priv, u16 classid, u16 child_classid,
37 			    u64 rate, u64 ceil, struct netlink_ext_ack *extack);
38 int mlx5e_htb_leaf_del(struct mlx5e_priv *priv, u16 *classid,
39 		       struct netlink_ext_ack *extack);
40 int mlx5e_htb_leaf_del_last(struct mlx5e_priv *priv, u16 classid, bool force,
41 			    struct netlink_ext_ack *extack);
42 int mlx5e_htb_node_modify(struct mlx5e_priv *priv, u16 classid, u64 rate, u64 ceil,
43 			  struct netlink_ext_ack *extack);
44 
45 /* MQPRIO TX rate limit */
46 struct mlx5e_mqprio_rl;
47 struct mlx5e_mqprio_rl *mlx5e_mqprio_rl_alloc(void);
48 void mlx5e_mqprio_rl_free(struct mlx5e_mqprio_rl *rl);
49 int mlx5e_mqprio_rl_init(struct mlx5e_mqprio_rl *rl, struct mlx5_core_dev *mdev, u8 num_tc,
50 			 u64 max_rate[]);
51 void mlx5e_mqprio_rl_cleanup(struct mlx5e_mqprio_rl *rl);
52 int mlx5e_mqprio_rl_get_node_hw_id(struct mlx5e_mqprio_rl *rl, int tc, u32 *hw_id);
53 #endif
54