RDMA/mlx5: Refactor transport domain bookkeeping logic
In preparation to enable loopback on a single user context move the logic that enables/disables loopback to separate functions and group variables under a single struct. Signed-off-by: Mark Bloch <markb@mellanox.com> Reviewed-by: Yishai Hadas <yishaih@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
@@ -1571,6 +1571,32 @@ static void deallocate_uars(struct mlx5_ib_dev *dev,
|
|||||||
mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]);
|
mlx5_cmd_free_uar(dev->mdev, bfregi->sys_pages[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mlx5_ib_enable_lb(struct mlx5_ib_dev *dev)
|
||||||
|
{
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
mutex_lock(&dev->lb.mutex);
|
||||||
|
dev->lb.user_td++;
|
||||||
|
|
||||||
|
if (dev->lb.user_td == 2)
|
||||||
|
err = mlx5_nic_vport_update_local_lb(dev->mdev, true);
|
||||||
|
|
||||||
|
mutex_unlock(&dev->lb.mutex);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mlx5_ib_disable_lb(struct mlx5_ib_dev *dev)
|
||||||
|
{
|
||||||
|
mutex_lock(&dev->lb.mutex);
|
||||||
|
dev->lb.user_td--;
|
||||||
|
|
||||||
|
if (dev->lb.user_td < 2)
|
||||||
|
mlx5_nic_vport_update_local_lb(dev->mdev, false);
|
||||||
|
|
||||||
|
mutex_unlock(&dev->lb.mutex);
|
||||||
|
}
|
||||||
|
|
||||||
static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn)
|
static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@@ -1587,14 +1613,7 @@ static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn)
|
|||||||
!MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc)))
|
!MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc)))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
mutex_lock(&dev->lb_mutex);
|
return mlx5_ib_enable_lb(dev);
|
||||||
dev->user_td++;
|
|
||||||
|
|
||||||
if (dev->user_td == 2)
|
|
||||||
err = mlx5_nic_vport_update_local_lb(dev->mdev, true);
|
|
||||||
|
|
||||||
mutex_unlock(&dev->lb_mutex);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn)
|
static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn)
|
||||||
@@ -1609,13 +1628,7 @@ static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn)
|
|||||||
!MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc)))
|
!MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mutex_lock(&dev->lb_mutex);
|
mlx5_ib_disable_lb(dev);
|
||||||
dev->user_td--;
|
|
||||||
|
|
||||||
if (dev->user_td < 2)
|
|
||||||
mlx5_nic_vport_update_local_lb(dev->mdev, false);
|
|
||||||
|
|
||||||
mutex_unlock(&dev->lb_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
|
static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
|
||||||
@@ -5880,7 +5893,7 @@ int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev)
|
|||||||
if ((MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) &&
|
if ((MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) &&
|
||||||
(MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) ||
|
(MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) ||
|
||||||
MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc)))
|
MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc)))
|
||||||
mutex_init(&dev->lb_mutex);
|
mutex_init(&dev->lb.mutex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -858,6 +858,12 @@ to_mcounters(struct ib_counters *ibcntrs)
|
|||||||
return container_of(ibcntrs, struct mlx5_ib_mcounters, ibcntrs);
|
return container_of(ibcntrs, struct mlx5_ib_mcounters, ibcntrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct mlx5_ib_lb_state {
|
||||||
|
/* protect the user_td */
|
||||||
|
struct mutex mutex;
|
||||||
|
u32 user_td;
|
||||||
|
};
|
||||||
|
|
||||||
struct mlx5_ib_dev {
|
struct mlx5_ib_dev {
|
||||||
struct ib_device ib_dev;
|
struct ib_device ib_dev;
|
||||||
const struct uverbs_object_tree_def *driver_trees[6];
|
const struct uverbs_object_tree_def *driver_trees[6];
|
||||||
@@ -899,9 +905,7 @@ struct mlx5_ib_dev {
|
|||||||
const struct mlx5_ib_profile *profile;
|
const struct mlx5_ib_profile *profile;
|
||||||
struct mlx5_eswitch_rep *rep;
|
struct mlx5_eswitch_rep *rep;
|
||||||
|
|
||||||
/* protect the user_td */
|
struct mlx5_ib_lb_state lb;
|
||||||
struct mutex lb_mutex;
|
|
||||||
u32 user_td;
|
|
||||||
u8 umr_fence;
|
u8 umr_fence;
|
||||||
struct list_head ib_dev_list;
|
struct list_head ib_dev_list;
|
||||||
u64 sys_image_guid;
|
u64 sys_image_guid;
|
||||||
|
Reference in New Issue
Block a user