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 BYTES_IN_MBIT 125000
10 
11 struct mlx5e_priv;
12 struct mlx5e_htb;
13 struct mlx5e_channels;
14 struct mlx5e_channel;
15 struct tc_htb_qopt_offload;
16 
17 int mlx5e_qos_bytes_rate_check(struct mlx5_core_dev *mdev, u64 nbytes);
18 int mlx5e_qos_max_leaf_nodes(struct mlx5_core_dev *mdev);
19 
20 /* SQ lifecycle */
21 int mlx5e_open_qos_sq(struct mlx5e_priv *priv, struct mlx5e_channels *chs,
22 		      u16 node_qid, u32 hw_id);
23 int mlx5e_activate_qos_sq(void *data, u16 node_qid, u32 hw_id);
24 void mlx5e_deactivate_qos_sq(struct mlx5e_priv *priv, u16 qid);
25 void mlx5e_close_qos_sq(struct mlx5e_priv *priv, u16 qid);
26 void mlx5e_reactivate_qos_sq(struct mlx5e_priv *priv, u16 qid, struct netdev_queue *txq);
27 void mlx5e_reset_qdisc(struct net_device *dev, u16 qid);
28 
29 int mlx5e_qos_open_queues(struct mlx5e_priv *priv, struct mlx5e_channels *chs);
30 void mlx5e_qos_activate_queues(struct mlx5e_priv *priv);
31 void mlx5e_qos_deactivate_queues(struct mlx5e_channel *c);
32 void mlx5e_qos_deactivate_all_queues(struct mlx5e_channels *chs);
33 void mlx5e_qos_close_queues(struct mlx5e_channel *c);
34 void mlx5e_qos_close_all_queues(struct mlx5e_channels *chs);
35 int mlx5e_qos_alloc_queues(struct mlx5e_priv *priv, struct mlx5e_channels *chs);
36 
37 /* TX datapath API */
38 u16 mlx5e_qid_from_qos(struct mlx5e_channels *chs, u16 qid);
39 
40 /* HTB API */
41 int mlx5e_htb_setup_tc(struct mlx5e_priv *priv, struct tc_htb_qopt_offload *htb);
42 
43 /* MQPRIO TX rate limit */
44 struct mlx5e_mqprio_rl;
45 struct mlx5e_mqprio_rl *mlx5e_mqprio_rl_alloc(void);
46 void mlx5e_mqprio_rl_free(struct mlx5e_mqprio_rl *rl);
47 int mlx5e_mqprio_rl_init(struct mlx5e_mqprio_rl *rl, struct mlx5_core_dev *mdev, u8 num_tc,
48 			 u64 max_rate[]);
49 void mlx5e_mqprio_rl_cleanup(struct mlx5e_mqprio_rl *rl);
50 int mlx5e_mqprio_rl_get_node_hw_id(struct mlx5e_mqprio_rl *rl, int tc, u32 *hw_id);
51 #endif
52