net/mlx5: E-Switch, Refactor eswitch ingress acl codes
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / lag.h
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 };
20
21 #define MLX5_LAG_MODE_FLAGS (MLX5_LAG_FLAG_ROCE | MLX5_LAG_FLAG_SRIOV |\
22                              MLX5_LAG_FLAG_MULTIPATH)
23
24 struct lag_func {
25         struct mlx5_core_dev *dev;
26         struct net_device    *netdev;
27 };
28
29 /* Used for collection of netdev event info. */
30 struct lag_tracker {
31         enum   netdev_lag_tx_type           tx_type;
32         struct netdev_lag_lower_state_info  netdev_state[MLX5_MAX_PORTS];
33         unsigned int is_bonded:1;
34 };
35
36 /* LAG data of a ConnectX card.
37  * It serves both its phys functions.
38  */
39 struct mlx5_lag {
40         u8                        flags;
41         u8                        v2p_map[MLX5_MAX_PORTS];
42         struct lag_func           pf[MLX5_MAX_PORTS];
43         struct lag_tracker        tracker;
44         struct workqueue_struct   *wq;
45         struct delayed_work       bond_work;
46         struct notifier_block     nb;
47         struct lag_mp             lag_mp;
48 };
49
50 static inline struct mlx5_lag *
51 mlx5_lag_dev_get(struct mlx5_core_dev *dev)
52 {
53         return dev->priv.lag;
54 }
55
56 static inline bool
57 __mlx5_lag_is_active(struct mlx5_lag *ldev)
58 {
59         return !!(ldev->flags & MLX5_LAG_MODE_FLAGS);
60 }
61
62 void mlx5_modify_lag(struct mlx5_lag *ldev,
63                      struct lag_tracker *tracker);
64 int mlx5_activate_lag(struct mlx5_lag *ldev,
65                       struct lag_tracker *tracker,
66                       u8 flags);
67 int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev,
68                                 struct net_device *ndev);
69
70 #endif /* __MLX5_LAG_H__ */