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 <linux/debugfs.h>
8
9 #define MLX5_LAG_MAX_HASH_BUCKETS 16
10 #include "mlx5_core.h"
11 #include "mp.h"
12 #include "port_sel.h"
13 #include "mpesw.h"
14
15 enum {
16 MLX5_LAG_P1,
17 MLX5_LAG_P2,
18 };
19
20 enum {
21 MLX5_LAG_FLAG_NDEVS_READY,
22 };
23
24 enum {
25 MLX5_LAG_MODE_FLAG_HASH_BASED,
26 MLX5_LAG_MODE_FLAG_SHARED_FDB,
27 MLX5_LAG_MODE_FLAG_FDB_SEL_MODE_NATIVE,
28 };
29
30 enum mlx5_lag_mode {
31 MLX5_LAG_MODE_NONE,
32 MLX5_LAG_MODE_ROCE,
33 MLX5_LAG_MODE_SRIOV,
34 MLX5_LAG_MODE_MULTIPATH,
35 MLX5_LAG_MODE_MPESW,
36 };
37
38 struct lag_func {
39 struct mlx5_core_dev *dev;
40 struct net_device *netdev;
41 bool has_drop;
42 };
43
44 /* Used for collection of netdev event info. */
45 struct lag_tracker {
46 enum netdev_lag_tx_type tx_type;
47 struct netdev_lag_lower_state_info netdev_state[MLX5_MAX_PORTS];
48 unsigned int is_bonded:1;
49 unsigned int has_inactive:1;
50 enum netdev_lag_hash hash_type;
51 };
52
53 /* LAG data of a ConnectX card.
54 * It serves both its phys functions.
55 */
56 struct mlx5_lag {
57 enum mlx5_lag_mode mode;
58 unsigned long mode_flags;
59 unsigned long state_flags;
60 u8 ports;
61 u8 buckets;
62 int mode_changes_in_progress;
63 u8 v2p_map[MLX5_MAX_PORTS * MLX5_LAG_MAX_HASH_BUCKETS];
64 struct kref ref;
65 struct lag_func pf[MLX5_MAX_PORTS];
66 struct lag_tracker tracker;
67 struct workqueue_struct *wq;
68 struct delayed_work bond_work;
69 struct work_struct mpesw_work;
70 struct notifier_block nb;
71 struct lag_mp lag_mp;
72 struct mlx5_lag_port_sel port_sel;
73 /* Protect lag fields/state changes */
74 struct mutex lock;
75 struct lag_mpesw lag_mpesw;
76 };
77
mlx5_is_lag_supported(struct mlx5_core_dev * dev)78 static inline bool mlx5_is_lag_supported(struct mlx5_core_dev *dev)
79 {
80 if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
81 !MLX5_CAP_GEN(dev, lag_master) ||
82 MLX5_CAP_GEN(dev, num_lag_ports) < 2 ||
83 MLX5_CAP_GEN(dev, num_lag_ports) > MLX5_MAX_PORTS)
84 return false;
85 return true;
86 }
87
88 static inline struct mlx5_lag *
mlx5_lag_dev(struct mlx5_core_dev * dev)89 mlx5_lag_dev(struct mlx5_core_dev *dev)
90 {
91 return dev->priv.lag;
92 }
93
94 static inline bool
__mlx5_lag_is_active(struct mlx5_lag * ldev)95 __mlx5_lag_is_active(struct mlx5_lag *ldev)
96 {
97 return ldev->mode != MLX5_LAG_MODE_NONE;
98 }
99
100 static inline bool
mlx5_lag_is_ready(struct mlx5_lag * ldev)101 mlx5_lag_is_ready(struct mlx5_lag *ldev)
102 {
103 return test_bit(MLX5_LAG_FLAG_NDEVS_READY, &ldev->state_flags);
104 }
105
106 void mlx5_modify_lag(struct mlx5_lag *ldev,
107 struct lag_tracker *tracker);
108 int mlx5_activate_lag(struct mlx5_lag *ldev,
109 struct lag_tracker *tracker,
110 enum mlx5_lag_mode mode,
111 bool shared_fdb);
112 int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev,
113 struct net_device *ndev);
114 bool mlx5_shared_fdb_supported(struct mlx5_lag *ldev);
115 void mlx5_lag_del_mpesw_rule(struct mlx5_core_dev *dev);
116 int mlx5_lag_add_mpesw_rule(struct mlx5_core_dev *dev);
117
118 char *mlx5_get_str_port_sel_mode(enum mlx5_lag_mode mode, unsigned long flags);
119 void mlx5_infer_tx_enabled(struct lag_tracker *tracker, u8 num_ports,
120 u8 *ports, int *num_enabled);
121
122 void mlx5_ldev_add_debugfs(struct mlx5_core_dev *dev);
123 void mlx5_ldev_remove_debugfs(struct dentry *dbg);
124 void mlx5_disable_lag(struct mlx5_lag *ldev);
125
126 #endif /* __MLX5_LAG_H__ */
127