1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2019 Mellanox Technologies. */
3 
4 #ifndef __MLX5_LAG_H__
5 #define __MLX5_LAG_H__
6 
7 #include "mlx5_core.h"
8 #include "lag_mp.h"
9 
10 enum {
11 	MLX5_LAG_FLAG_ROCE   = 1 << 0,
12 	MLX5_LAG_FLAG_SRIOV  = 1 << 1,
13 	MLX5_LAG_FLAG_MULTIPATH = 1 << 2,
14 };
15 
16 #define MLX5_LAG_MODE_FLAGS (MLX5_LAG_FLAG_ROCE | MLX5_LAG_FLAG_SRIOV |\
17 			     MLX5_LAG_FLAG_MULTIPATH)
18 
19 struct lag_func {
20 	struct mlx5_core_dev *dev;
21 	struct net_device    *netdev;
22 };
23 
24 /* Used for collection of netdev event info. */
25 struct lag_tracker {
26 	enum   netdev_lag_tx_type           tx_type;
27 	struct netdev_lag_lower_state_info  netdev_state[MLX5_MAX_PORTS];
28 	unsigned int is_bonded:1;
29 };
30 
31 /* LAG data of a ConnectX card.
32  * It serves both its phys functions.
33  */
34 struct mlx5_lag {
35 	u8                        flags;
36 	u8                        v2p_map[MLX5_MAX_PORTS];
37 	struct lag_func           pf[MLX5_MAX_PORTS];
38 	struct lag_tracker        tracker;
39 	struct workqueue_struct   *wq;
40 	struct delayed_work       bond_work;
41 	struct notifier_block     nb;
42 	struct lag_mp             lag_mp;
43 };
44 
45 static inline struct mlx5_lag *
mlx5_lag_dev_get(struct mlx5_core_dev * dev)46 mlx5_lag_dev_get(struct mlx5_core_dev *dev)
47 {
48 	return dev->priv.lag;
49 }
50 
51 static inline bool
__mlx5_lag_is_active(struct mlx5_lag * ldev)52 __mlx5_lag_is_active(struct mlx5_lag *ldev)
53 {
54 	return !!(ldev->flags & MLX5_LAG_MODE_FLAGS);
55 }
56 
57 void mlx5_modify_lag(struct mlx5_lag *ldev,
58 		     struct lag_tracker *tracker);
59 int mlx5_activate_lag(struct mlx5_lag *ldev,
60 		      struct lag_tracker *tracker,
61 		      u8 flags);
62 int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev,
63 				struct net_device *ndev);
64 
65 #endif /* __MLX5_LAG_H__ */
66