1 From 51e480eb6aba358e6f3f5be906574e3c2b122780 Mon Sep 17 00:00:00 2001
2 From: Alaa Hleihel <alaa@mellanox.com>
3 Date: Sun, 19 May 2019 11:11:49 +0300
4 Subject: net/mlx5: Avoid reloading already removed devices
6 Prior to reloading a device we must first verify that it was not already
7 removed. Otherwise, the attempt to remove the device will do nothing, and
8 in that case we will end up proceeding with adding an new device that no
9 one was expecting to remove, leaving behind used resources such as EQs that
10 causes a failure to destroy comp EQs and syndrome (0x30f433).
12 Fix that by making sure that we try to remove and add a device (based on a
13 protocol) only if the device is already added.
15 Fixes: c5447c70594b ("net/mlx5: E-Switch, Reload IB interface when switching devlink modes")
16 Signed-off-by: Alaa Hleihel <alaa@mellanox.com>
17 Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 drivers/net/ethernet/mellanox/mlx5/core/dev.c | 25 +++++++++++++++++--
21 1 file changed, 23 insertions(+), 2 deletions(-)
23 diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
24 index 37ba7c78859d..1c225be9c7db 100644
25 --- a/drivers/net/ethernet/mellanox/mlx5/core/dev.c
26 +++ b/drivers/net/ethernet/mellanox/mlx5/core/dev.c
27 @@ -342,11 +342,32 @@ void mlx5_unregister_interface(struct mlx5_interface *intf)
29 EXPORT_SYMBOL(mlx5_unregister_interface);
31 +/* Must be called with intf_mutex held */
32 +static bool mlx5_has_added_dev_by_protocol(struct mlx5_core_dev *mdev, int protocol)
34 + struct mlx5_device_context *dev_ctx;
35 + struct mlx5_interface *intf;
38 + list_for_each_entry(intf, &intf_list, list) {
39 + if (intf->protocol == protocol) {
40 + dev_ctx = mlx5_get_device(intf, &mdev->priv);
41 + if (dev_ctx && test_bit(MLX5_INTERFACE_ADDED, &dev_ctx->state))
50 void mlx5_reload_interface(struct mlx5_core_dev *mdev, int protocol)
52 mutex_lock(&mlx5_intf_mutex);
53 - mlx5_remove_dev_by_protocol(mdev, protocol);
54 - mlx5_add_dev_by_protocol(mdev, protocol);
55 + if (mlx5_has_added_dev_by_protocol(mdev, protocol)) {
56 + mlx5_remove_dev_by_protocol(mdev, protocol);
57 + mlx5_add_dev_by_protocol(mdev, protocol);
59 mutex_unlock(&mlx5_intf_mutex);