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_SELQ_H__
5 #define __MLX5_EN_SELQ_H__
6 
7 #include <linux/kernel.h>
8 
9 struct mlx5e_selq_params;
10 
11 struct mlx5e_selq {
12 	struct mlx5e_selq_params __rcu *active;
13 	struct mlx5e_selq_params *standby;
14 	struct mutex *state_lock; /* points to priv->state_lock */
15 	bool is_prepared;
16 };
17 
18 struct mlx5e_params;
19 struct net_device;
20 struct sk_buff;
21 
22 int mlx5e_selq_init(struct mlx5e_selq *selq, struct mutex *state_lock);
23 void mlx5e_selq_cleanup(struct mlx5e_selq *selq);
24 void mlx5e_selq_prepare_params(struct mlx5e_selq *selq, struct mlx5e_params *params);
25 void mlx5e_selq_prepare_htb(struct mlx5e_selq *selq, u16 htb_maj_id, u16 htb_defcls);
26 bool mlx5e_selq_is_htb_enabled(struct mlx5e_selq *selq);
27 void mlx5e_selq_apply(struct mlx5e_selq *selq);
28 void mlx5e_selq_cancel(struct mlx5e_selq *selq);
29 
mlx5e_txq_to_ch_ix(u16 txq,u16 num_channels)30 static inline u16 mlx5e_txq_to_ch_ix(u16 txq, u16 num_channels)
31 {
32 	while (unlikely(txq >= num_channels))
33 		txq -= num_channels;
34 	return txq;
35 }
36 
mlx5e_txq_to_ch_ix_htb(u16 txq,u16 num_channels)37 static inline u16 mlx5e_txq_to_ch_ix_htb(u16 txq, u16 num_channels)
38 {
39 	if (unlikely(txq >= num_channels)) {
40 		if (unlikely(txq >= num_channels << 3))
41 			txq %= num_channels;
42 		else
43 			do
44 				txq -= num_channels;
45 			while (txq >= num_channels);
46 	}
47 	return txq;
48 }
49 
50 u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
51 		       struct net_device *sb_dev);
52 
53 #endif /* __MLX5_EN_SELQ_H__ */
54