0001
0002
0003
0004 #include <linux/netdevice.h>
0005 #include <net/nexthop.h>
0006 #include "lag/lag.h"
0007 #include "eswitch.h"
0008 #include "lib/mlx5.h"
0009
0010 void mlx5_mpesw_work(struct work_struct *work)
0011 {
0012 struct mlx5_lag *ldev = container_of(work, struct mlx5_lag, mpesw_work);
0013
0014 mutex_lock(&ldev->lock);
0015 mlx5_disable_lag(ldev);
0016 mutex_unlock(&ldev->lock);
0017 }
0018
0019 static void mlx5_lag_disable_mpesw(struct mlx5_core_dev *dev)
0020 {
0021 struct mlx5_lag *ldev = dev->priv.lag;
0022
0023 if (!queue_work(ldev->wq, &ldev->mpesw_work))
0024 mlx5_core_warn(dev, "failed to queue work\n");
0025 }
0026
0027 void mlx5_lag_del_mpesw_rule(struct mlx5_core_dev *dev)
0028 {
0029 struct mlx5_lag *ldev = dev->priv.lag;
0030
0031 if (!ldev)
0032 return;
0033
0034 mutex_lock(&ldev->lock);
0035 if (!atomic_dec_return(&ldev->lag_mpesw.mpesw_rule_count) &&
0036 ldev->mode == MLX5_LAG_MODE_MPESW)
0037 mlx5_lag_disable_mpesw(dev);
0038 mutex_unlock(&ldev->lock);
0039 }
0040
0041 int mlx5_lag_add_mpesw_rule(struct mlx5_core_dev *dev)
0042 {
0043 struct mlx5_lag *ldev = dev->priv.lag;
0044 int err = 0;
0045
0046 if (!ldev)
0047 return 0;
0048
0049 mutex_lock(&ldev->lock);
0050 if (atomic_add_return(1, &ldev->lag_mpesw.mpesw_rule_count) != 1)
0051 goto out;
0052
0053 if (ldev->mode != MLX5_LAG_MODE_NONE) {
0054 err = -EINVAL;
0055 goto out;
0056 }
0057
0058 err = mlx5_activate_lag(ldev, NULL, MLX5_LAG_MODE_MPESW, false);
0059 if (err)
0060 mlx5_core_warn(dev, "Failed to create LAG in MPESW mode (%d)\n", err);
0061
0062 out:
0063 mutex_unlock(&ldev->lock);
0064 return err;
0065 }
0066
0067 int mlx5_lag_do_mirred(struct mlx5_core_dev *mdev, struct net_device *out_dev)
0068 {
0069 struct mlx5_lag *ldev = mdev->priv.lag;
0070
0071 if (!netif_is_bond_master(out_dev) || !ldev)
0072 return 0;
0073
0074 mutex_lock(&ldev->lock);
0075 if (ldev->mode == MLX5_LAG_MODE_MPESW) {
0076 mutex_unlock(&ldev->lock);
0077 return -EOPNOTSUPP;
0078 }
0079 mutex_unlock(&ldev->lock);
0080 return 0;
0081 }
0082
0083 bool mlx5_lag_mpesw_is_activated(struct mlx5_core_dev *dev)
0084 {
0085 bool ret;
0086
0087 ret = dev->priv.lag && dev->priv.lag->mode == MLX5_LAG_MODE_MPESW;
0088 return ret;
0089 }
0090
0091 void mlx5_lag_mpesw_init(struct mlx5_lag *ldev)
0092 {
0093 INIT_WORK(&ldev->mpesw_work, mlx5_mpesw_work);
0094 atomic_set(&ldev->lag_mpesw.mpesw_rule_count, 0);
0095 }
0096
0097 void mlx5_lag_mpesw_cleanup(struct mlx5_lag *ldev)
0098 {
0099 cancel_delayed_work_sync(&ldev->bond_work);
0100 }