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 bool has_drop; 32 }; 33 34 /* Used for collection of netdev event info. */ 35 struct lag_tracker { 36 enum netdev_lag_tx_type tx_type; 37 struct netdev_lag_lower_state_info netdev_state[MLX5_MAX_PORTS]; 38 unsigned int is_bonded:1; 39 unsigned int has_inactive:1; 40 enum netdev_lag_hash hash_type; 41 }; 42 43 /* LAG data of a ConnectX card. 44 * It serves both its phys functions. 45 */ 46 struct mlx5_lag { 47 u8 flags; 48 int mode_changes_in_progress; 49 bool shared_fdb; 50 u8 v2p_map[MLX5_MAX_PORTS]; 51 struct kref ref; 52 struct lag_func pf[MLX5_MAX_PORTS]; 53 struct lag_tracker tracker; 54 struct workqueue_struct *wq; 55 struct delayed_work bond_work; 56 struct notifier_block nb; 57 struct lag_mp lag_mp; 58 struct mlx5_lag_port_sel port_sel; 59 }; 60 61 static inline struct mlx5_lag * 62 mlx5_lag_dev(struct mlx5_core_dev *dev) 63 { 64 return dev->priv.lag; 65 } 66 67 static inline bool 68 __mlx5_lag_is_active(struct mlx5_lag *ldev) 69 { 70 return !!(ldev->flags & MLX5_LAG_MODE_FLAGS); 71 } 72 73 static inline bool 74 mlx5_lag_is_ready(struct mlx5_lag *ldev) 75 { 76 return ldev->flags & MLX5_LAG_FLAG_READY; 77 } 78 79 void mlx5_modify_lag(struct mlx5_lag *ldev, 80 struct lag_tracker *tracker); 81 int mlx5_activate_lag(struct mlx5_lag *ldev, 82 struct lag_tracker *tracker, 83 u8 flags, 84 bool shared_fdb); 85 int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev, 86 struct net_device *ndev); 87 88 #endif /* __MLX5_LAG_H__ */ 89