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