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_P1,
12 MLX5_LAG_P2,
13 };
14
15 enum {
16 MLX5_LAG_FLAG_ROCE = 1 << 0,
17 MLX5_LAG_FLAG_SRIOV = 1 << 1,
18 MLX5_LAG_FLAG_MULTIPATH = 1 << 2,
19 MLX5_LAG_FLAG_READY = 1 << 3,
20 };
21
22 #define MLX5_LAG_MODE_FLAGS (MLX5_LAG_FLAG_ROCE | MLX5_LAG_FLAG_SRIOV |\
23 MLX5_LAG_FLAG_MULTIPATH)
24
25 struct lag_func {
26 struct mlx5_core_dev *dev;
27 struct net_device *netdev;
28 };
29
30 /* Used for collection of netdev event info. */
31 struct lag_tracker {
32 enum netdev_lag_tx_type tx_type;
33 struct netdev_lag_lower_state_info netdev_state[MLX5_MAX_PORTS];
34 unsigned int is_bonded:1;
35 };
36
37 /* LAG data of a ConnectX card.
38 * It serves both its phys functions.
39 */
40 struct mlx5_lag {
41 u8 flags;
42 int mode_changes_in_progress;
43 bool shared_fdb;
44 u8 v2p_map[MLX5_MAX_PORTS];
45 struct kref ref;
46 struct lag_func pf[MLX5_MAX_PORTS];
47 struct lag_tracker tracker;
48 struct workqueue_struct *wq;
49 struct delayed_work bond_work;
50 struct notifier_block nb;
51 struct lag_mp lag_mp;
52 };
53
54 static inline struct mlx5_lag *
mlx5_lag_dev(struct mlx5_core_dev * dev)55 mlx5_lag_dev(struct mlx5_core_dev *dev)
56 {
57 return dev->priv.lag;
58 }
59
60 static inline bool
__mlx5_lag_is_active(struct mlx5_lag * ldev)61 __mlx5_lag_is_active(struct mlx5_lag *ldev)
62 {
63 return !!(ldev->flags & MLX5_LAG_MODE_FLAGS);
64 }
65
66 static inline bool
mlx5_lag_is_ready(struct mlx5_lag * ldev)67 mlx5_lag_is_ready(struct mlx5_lag *ldev)
68 {
69 return ldev->flags & MLX5_LAG_FLAG_READY;
70 }
71
72 void mlx5_modify_lag(struct mlx5_lag *ldev,
73 struct lag_tracker *tracker);
74 int mlx5_activate_lag(struct mlx5_lag *ldev,
75 struct lag_tracker *tracker,
76 u8 flags,
77 bool shared_fdb);
78 int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev,
79 struct net_device *ndev);
80
81 #endif /* __MLX5_LAG_H__ */
82