net/mlx5: remove control path locks
[dpdk.git] / drivers / net / mlx5 / mlx5_ethdev.c
index 6f78adc..f0defc6 100644 (file)
@@ -1,40 +1,13 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright 2015 6WIND S.A.
- *   Copyright 2015 Mellanox.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of 6WIND S.A. nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2015 6WIND S.A.
+ * Copyright 2015 Mellanox.
  */
 
 #define _GNU_SOURCE
 
 #include <stddef.h>
 #include <assert.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -55,7 +28,7 @@
 #include <sys/un.h>
 
 #include <rte_atomic.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 #include <rte_bus_pci.h>
 #include <rte_mbuf.h>
 #include <rte_common.h>
@@ -64,6 +37,7 @@
 #include <rte_malloc.h>
 
 #include "mlx5.h"
+#include "mlx5_glue.h"
 #include "mlx5_rxtx.h"
 #include "mlx5_utils.h"
 
@@ -199,181 +173,6 @@ try_dev_id:
        return 0;
 }
 
-/**
- * Check if the counter is located on ib counters file.
- *
- * @param[in] cntr
- *   Counter name.
- *
- * @return
- *   1 if counter is located on ib counters file , 0 otherwise.
- */
-int
-priv_is_ib_cntr(const char *cntr)
-{
-       if (!strcmp(cntr, "out_of_buffer"))
-               return 1;
-       return 0;
-}
-
-/**
- * Read from sysfs entry.
- *
- * @param[in] priv
- *   Pointer to private structure.
- * @param[in] entry
- *   Entry name relative to sysfs path.
- * @param[out] buf
- *   Data output buffer.
- * @param size
- *   Buffer size.
- *
- * @return
- *   0 on success, -1 on failure and errno is set.
- */
-static int
-priv_sysfs_read(const struct priv *priv, const char *entry,
-               char *buf, size_t size)
-{
-       char ifname[IF_NAMESIZE];
-       FILE *file;
-       int ret;
-       int err;
-
-       if (priv_get_ifname(priv, &ifname))
-               return -1;
-
-       if (priv_is_ib_cntr(entry)) {
-               MKSTR(path, "%s/ports/1/hw_counters/%s",
-                     priv->ibdev_path, entry);
-               file = fopen(path, "rb");
-       } else {
-               MKSTR(path, "%s/device/net/%s/%s",
-                     priv->ibdev_path, ifname, entry);
-               file = fopen(path, "rb");
-       }
-       if (file == NULL)
-               return -1;
-       ret = fread(buf, 1, size, file);
-       err = errno;
-       if (((size_t)ret < size) && (ferror(file)))
-               ret = -1;
-       else
-               ret = size;
-       fclose(file);
-       errno = err;
-       return ret;
-}
-
-/**
- * Write to sysfs entry.
- *
- * @param[in] priv
- *   Pointer to private structure.
- * @param[in] entry
- *   Entry name relative to sysfs path.
- * @param[in] buf
- *   Data buffer.
- * @param size
- *   Buffer size.
- *
- * @return
- *   0 on success, -1 on failure and errno is set.
- */
-static int
-priv_sysfs_write(const struct priv *priv, const char *entry,
-                char *buf, size_t size)
-{
-       char ifname[IF_NAMESIZE];
-       FILE *file;
-       int ret;
-       int err;
-
-       if (priv_get_ifname(priv, &ifname))
-               return -1;
-
-       MKSTR(path, "%s/device/net/%s/%s", priv->ibdev_path, ifname, entry);
-
-       file = fopen(path, "wb");
-       if (file == NULL)
-               return -1;
-       ret = fwrite(buf, 1, size, file);
-       err = errno;
-       if (((size_t)ret < size) || (ferror(file)))
-               ret = -1;
-       else
-               ret = size;
-       fclose(file);
-       errno = err;
-       return ret;
-}
-
-/**
- * Get unsigned long sysfs property.
- *
- * @param priv
- *   Pointer to private structure.
- * @param[in] name
- *   Entry name relative to sysfs path.
- * @param[out] value
- *   Value output buffer.
- *
- * @return
- *   0 on success, -1 on failure and errno is set.
- */
-static int
-priv_get_sysfs_ulong(struct priv *priv, const char *name, unsigned long *value)
-{
-       int ret;
-       unsigned long value_ret;
-       char value_str[32];
-
-       ret = priv_sysfs_read(priv, name, value_str, (sizeof(value_str) - 1));
-       if (ret == -1) {
-               DEBUG("cannot read %s value from sysfs: %s",
-                     name, strerror(errno));
-               return -1;
-       }
-       value_str[ret] = '\0';
-       errno = 0;
-       value_ret = strtoul(value_str, NULL, 0);
-       if (errno) {
-               DEBUG("invalid %s value `%s': %s", name, value_str,
-                     strerror(errno));
-               return -1;
-       }
-       *value = value_ret;
-       return 0;
-}
-
-/**
- * Set unsigned long sysfs property.
- *
- * @param priv
- *   Pointer to private structure.
- * @param[in] name
- *   Entry name relative to sysfs path.
- * @param value
- *   Value to set.
- *
- * @return
- *   0 on success, -1 on failure and errno is set.
- */
-static int
-priv_set_sysfs_ulong(struct priv *priv, const char *name, unsigned long value)
-{
-       int ret;
-       MKSTR(value_str, "%lu", value);
-
-       ret = priv_sysfs_write(priv, name, value_str, (sizeof(value_str) - 1));
-       if (ret == -1) {
-               DEBUG("cannot write %s `%s' (%lu) to sysfs: %s",
-                     name, value_str, value, strerror(errno));
-               return -1;
-       }
-       return 0;
-}
-
 /**
  * Perform ifreq ioctl() on associated Ethernet device.
  *
@@ -401,38 +200,6 @@ priv_ifreq(const struct priv *priv, int req, struct ifreq *ifr)
        return ret;
 }
 
-/**
- * Return the number of active VFs for the current device.
- *
- * @param[in] priv
- *   Pointer to private structure.
- * @param[out] num_vfs
- *   Number of active VFs.
- *
- * @return
- *   0 on success, -1 on failure and errno is set.
- */
-int
-priv_get_num_vfs(struct priv *priv, uint16_t *num_vfs)
-{
-       /* The sysfs entry name depends on the operating system. */
-       const char **name = (const char *[]){
-               "device/sriov_numvfs",
-               "device/mlx5_num_vfs",
-               NULL,
-       };
-       int ret;
-
-       do {
-               unsigned long ulong_num_vfs;
-
-               ret = priv_get_sysfs_ulong(priv, *name, &ulong_num_vfs);
-               if (!ret)
-                       *num_vfs = ulong_num_vfs;
-       } while (*(++name) && ret);
-       return ret;
-}
-
 /**
  * Get device MTU.
  *
@@ -447,35 +214,12 @@ priv_get_num_vfs(struct priv *priv, uint16_t *num_vfs)
 int
 priv_get_mtu(struct priv *priv, uint16_t *mtu)
 {
-       unsigned long ulong_mtu;
+       struct ifreq request;
+       int ret = priv_ifreq(priv, SIOCGIFMTU, &request);
 
-       if (priv_get_sysfs_ulong(priv, "mtu", &ulong_mtu) == -1)
-               return -1;
-       *mtu = ulong_mtu;
-       return 0;
-}
-
-/**
- * Read device counter from sysfs.
- *
- * @param priv
- *   Pointer to private structure.
- * @param name
- *   Counter name.
- * @param[out] cntr
- *   Counter output buffer.
- *
- * @return
- *   0 on success, -1 on failure and errno is set.
- */
-int
-priv_get_cntr_sysfs(struct priv *priv, const char *name, uint64_t *cntr)
-{
-       unsigned long ulong_ctr;
-
-       if (priv_get_sysfs_ulong(priv, name, &ulong_ctr) == -1)
-               return -1;
-       *cntr = ulong_ctr;
+       if (ret)
+               return ret;
+       *mtu = request.ifr_mtu;
        return 0;
 }
 
@@ -493,15 +237,9 @@ priv_get_cntr_sysfs(struct priv *priv, const char *name, uint64_t *cntr)
 static int
 priv_set_mtu(struct priv *priv, uint16_t mtu)
 {
-       uint16_t new_mtu;
+       struct ifreq request = { .ifr_mtu = mtu, };
 
-       if (priv_set_sysfs_ulong(priv, "mtu", mtu) ||
-           priv_get_mtu(priv, &new_mtu))
-               return -1;
-       if (new_mtu == mtu)
-               return 0;
-       errno = EINVAL;
-       return -1;
+       return priv_ifreq(priv, SIOCSIFMTU, &request);
 }
 
 /**
@@ -520,28 +258,27 @@ priv_set_mtu(struct priv *priv, uint16_t mtu)
 int
 priv_set_flags(struct priv *priv, unsigned int keep, unsigned int flags)
 {
-       unsigned long tmp;
+       struct ifreq request;
+       int ret = priv_ifreq(priv, SIOCGIFFLAGS, &request);
 
-       if (priv_get_sysfs_ulong(priv, "flags", &tmp) == -1)
-               return -1;
-       tmp &= keep;
-       tmp |= (flags & (~keep));
-       return priv_set_sysfs_ulong(priv, "flags", tmp);
+       if (ret)
+               return ret;
+       request.ifr_flags &= keep;
+       request.ifr_flags |= flags & ~keep;
+       return priv_ifreq(priv, SIOCSIFFLAGS, &request);
 }
 
 /**
- * Ethernet device configuration.
- *
- * Prepare the driver for a given number of TX and RX queues.
+ * DPDK callback for Ethernet device configuration.
  *
  * @param dev
  *   Pointer to Ethernet device structure.
  *
  * @return
- *   0 on success, errno value on failure.
+ *   0 on success, negative errno value on failure.
  */
-static int
-dev_configure(struct rte_eth_dev *dev)
+int
+mlx5_dev_configure(struct rte_eth_dev *dev)
 {
        struct priv *priv = dev->data->dev_private;
        unsigned int rxqs_n = dev->data->nb_rx_queues;
@@ -623,28 +360,7 @@ dev_configure(struct rte_eth_dev *dev)
                        j = 0;
        }
        return 0;
-}
 
-/**
- * DPDK callback for Ethernet device configuration.
- *
- * @param dev
- *   Pointer to Ethernet device structure.
- *
- * @return
- *   0 on success, negative errno value on failure.
- */
-int
-mlx5_dev_configure(struct rte_eth_dev *dev)
-{
-       struct priv *priv = dev->data->dev_private;
-       int ret;
-
-       priv_lock(priv);
-       ret = dev_configure(dev);
-       assert(ret >= 0);
-       priv_unlock(priv);
-       return -ret;
 }
 
 /**
@@ -664,8 +380,6 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
        char ifname[IF_NAMESIZE];
 
        info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
-
-       priv_lock(priv);
        /* FIXME: we should ask the device for these values. */
        info->min_rx_bufsize = 32;
        info->max_rx_pktlen = 65536;
@@ -692,9 +406,18 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
                priv->reta_idx_n : config->ind_table_max_size;
        info->hash_key_size = priv->rss_conf.rss_key_len;
        info->speed_capa = priv->link_speed_capa;
-       priv_unlock(priv);
+       info->flow_type_rss_offloads = ~MLX5_RSS_HF_MASK;
 }
 
+/**
+ * Get supported packet types.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ *
+ * @return
+ *   A pointer to the supported Packet types array.
+ */
 const uint32_t *
 mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev)
 {
@@ -727,11 +450,12 @@ mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev)
  *
  * @param dev
  *   Pointer to Ethernet device structure.
- * @param wait_to_complete
- *   Wait for request completion (ignored).
+ *
+ * @return
+ *   0 on success, -1 on error.
  */
 static int
-mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev, int wait_to_complete)
+mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev)
 {
        struct priv *priv = dev->data->dev_private;
        struct ethtool_cmd edata = {
@@ -741,9 +465,6 @@ mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev, int wait_to_complete)
        struct rte_eth_link dev_link;
        int link_speed = 0;
 
-       /* priv_lock() is not taken to allow concurrent calls. */
-
-       (void)wait_to_complete;
        if (priv_ifreq(priv, SIOCGIFFLAGS, &ifr)) {
                WARN("ioctl(SIOCGIFFLAGS) failed: %s", strerror(errno));
                return -1;
@@ -793,11 +514,12 @@ mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev, int wait_to_complete)
  *
  * @param dev
  *   Pointer to Ethernet device structure.
- * @param wait_to_complete
- *   Wait for request completion (ignored).
+ *
+ * @return
+ *   0 on success, -1 on error.
  */
 static int
-mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev, int wait_to_complete)
+mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev)
 {
        struct priv *priv = dev->data->dev_private;
        struct ethtool_link_settings gcmd = { .cmd = ETHTOOL_GLINKSETTINGS };
@@ -805,7 +527,6 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev, int wait_to_complete)
        struct rte_eth_link dev_link;
        uint64_t sc;
 
-       (void)wait_to_complete;
        if (priv_ifreq(priv, SIOCGIFFLAGS, &ifr)) {
                WARN("ioctl(SIOCGIFFLAGS) failed: %s", strerror(errno));
                return -1;
@@ -885,25 +606,132 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev, int wait_to_complete)
 }
 
 /**
- * DPDK callback to retrieve physical link information.
+ * Enable receiving and transmitting traffic.
  *
- * @param dev
- *   Pointer to Ethernet device structure.
+ * @param priv
+ *   Pointer to private structure.
+ */
+static void
+priv_link_start(struct priv *priv)
+{
+       struct rte_eth_dev *dev = priv->dev;
+       int err;
+
+       dev->tx_pkt_burst = priv_select_tx_function(priv, dev);
+       dev->rx_pkt_burst = priv_select_rx_function(priv, dev);
+       err = priv_dev_traffic_enable(priv, dev);
+       if (err)
+               ERROR("%p: error occurred while configuring control flows: %s",
+                     (void *)priv, strerror(err));
+       err = priv_flow_start(priv, &priv->flows);
+       if (err)
+               ERROR("%p: error occurred while configuring flows: %s",
+                     (void *)priv, strerror(err));
+}
+
+/**
+ * Disable receiving and transmitting traffic.
+ *
+ * @param priv
+ *   Pointer to private structure.
+ */
+static void
+priv_link_stop(struct priv *priv)
+{
+       struct rte_eth_dev *dev = priv->dev;
+
+       priv_flow_stop(priv, &priv->flows);
+       priv_dev_traffic_disable(priv, dev);
+       dev->rx_pkt_burst = removed_rx_burst;
+       dev->tx_pkt_burst = removed_tx_burst;
+}
+
+/**
+ * Retrieve physical link information and update rx/tx_pkt_burst callbacks
+ * accordingly.
+ *
+ * @param priv
+ *   Pointer to private structure.
  * @param wait_to_complete
  *   Wait for request completion (ignored).
  */
 int
-mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
+priv_link_update(struct priv *priv, int wait_to_complete __rte_unused)
 {
+       struct rte_eth_dev *dev = priv->dev;
        struct utsname utsname;
        int ver[3];
+       int ret;
+       struct rte_eth_link dev_link = dev->data->dev_link;
 
        if (uname(&utsname) == -1 ||
            sscanf(utsname.release, "%d.%d.%d",
                   &ver[0], &ver[1], &ver[2]) != 3 ||
            KERNEL_VERSION(ver[0], ver[1], ver[2]) < KERNEL_VERSION(4, 9, 0))
-               return mlx5_link_update_unlocked_gset(dev, wait_to_complete);
-       return mlx5_link_update_unlocked_gs(dev, wait_to_complete);
+               ret = mlx5_link_update_unlocked_gset(dev);
+       else
+               ret = mlx5_link_update_unlocked_gs(dev);
+       /* If lsc interrupt is disabled, should always be ready for traffic. */
+       if (!dev->data->dev_conf.intr_conf.lsc) {
+               priv_link_start(priv);
+               return ret;
+       }
+       /* Re-select burst callbacks only if link status has been changed. */
+       if (!ret && dev_link.link_status != dev->data->dev_link.link_status) {
+               if (dev->data->dev_link.link_status == ETH_LINK_UP)
+                       priv_link_start(priv);
+               else
+                       priv_link_stop(priv);
+       }
+       return ret;
+}
+
+/**
+ * Querying the link status till it changes to the desired state.
+ * Number of query attempts is bounded by MLX5_MAX_LINK_QUERY_ATTEMPTS.
+ *
+ * @param priv
+ *   Pointer to private structure.
+ * @param status
+ *   Link desired status.
+ *
+ * @return
+ *   0 on success, negative errno value on failure.
+ */
+int
+priv_force_link_status_change(struct priv *priv, int status)
+{
+       int try = 0;
+
+       while (try < MLX5_MAX_LINK_QUERY_ATTEMPTS) {
+               priv_link_update(priv, 0);
+               if (priv->dev->data->dev_link.link_status == status)
+                       return 0;
+               try++;
+               sleep(1);
+       }
+       return -EAGAIN;
+}
+
+/**
+ * DPDK callback to retrieve physical link information.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param wait_to_complete
+ *   Wait for request completion (ignored).
+ *
+ * @return
+ *   0 on success, -1 on error.
+ */
+int
+mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)
+{
+       struct priv *priv = dev->data->dev_private;
+       int ret;
+
+       ret = priv_link_update(priv, wait_to_complete);
+       return ret;
 }
 
 /**
@@ -924,7 +752,6 @@ mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
        uint16_t kern_mtu;
        int ret = 0;
 
-       priv_lock(priv);
        ret = priv_get_mtu(priv, &kern_mtu);
        if (ret)
                goto out;
@@ -939,13 +766,11 @@ mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
                priv->mtu = mtu;
                DEBUG("adapter port %u MTU set to %u", priv->port, mtu);
        }
-       priv_unlock(priv);
        return 0;
 out:
        ret = errno;
        WARN("cannot set port %u MTU to %u: %s", priv->port, mtu,
             strerror(ret));
-       priv_unlock(priv);
        assert(ret >= 0);
        return -ret;
 }
@@ -972,7 +797,6 @@ mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
        int ret;
 
        ifr.ifr_data = (void *)&ethpause;
-       priv_lock(priv);
        if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
                ret = errno;
                WARN("ioctl(SIOCETHTOOL, ETHTOOL_GPAUSEPARAM)"
@@ -980,7 +804,6 @@ mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
                     strerror(ret));
                goto out;
        }
-
        fc_conf->autoneg = ethpause.autoneg;
        if (ethpause.rx_pause && ethpause.tx_pause)
                fc_conf->mode = RTE_FC_FULL;
@@ -991,9 +814,7 @@ mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
        else
                fc_conf->mode = RTE_FC_NONE;
        ret = 0;
-
 out:
-       priv_unlock(priv);
        assert(ret >= 0);
        return -ret;
 }
@@ -1032,8 +853,6 @@ mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
                ethpause.tx_pause = 1;
        else
                ethpause.tx_pause = 0;
-
-       priv_lock(priv);
        if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
                ret = errno;
                WARN("ioctl(SIOCETHTOOL, ETHTOOL_SPAUSEPARAM)"
@@ -1042,9 +861,7 @@ mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
                goto out;
        }
        ret = 0;
-
 out:
-       priv_unlock(priv);
        assert(ret >= 0);
        return -ret;
 }
@@ -1113,7 +930,7 @@ priv_link_status_update(struct priv *priv)
 {
        struct rte_eth_link *link = &priv->dev->data->dev_link;
 
-       mlx5_link_update(priv->dev, 0);
+       priv_link_update(priv, 0);
        if (((link->link_speed == 0) && link->link_status) ||
                ((link->link_speed != 0) && !link->link_status)) {
                /*
@@ -1154,7 +971,7 @@ priv_dev_status_handler(struct priv *priv)
 
        /* Read all message and acknowledge them. */
        for (;;) {
-               if (ibv_get_async_event(priv->ctx, &event))
+               if (mlx5_glue->get_async_event(priv->ctx, &event))
                        break;
                if ((event.event_type == IBV_EVENT_PORT_ACTIVE ||
                        event.event_type == IBV_EVENT_PORT_ERR) &&
@@ -1166,7 +983,7 @@ priv_dev_status_handler(struct priv *priv)
                else
                        DEBUG("event type %d on port %d not handled",
                              event.event_type, event.element.port_num);
-               ibv_ack_async_event(&event);
+               mlx5_glue->ack_async_event(&event);
        }
        if (ret & (1 << RTE_ETH_EVENT_INTR_LSC))
                if (priv_link_status_update(priv))
@@ -1187,15 +1004,8 @@ mlx5_dev_link_status_handler(void *arg)
        struct priv *priv = dev->data->dev_private;
        int ret;
 
-       while (!priv_trylock(priv)) {
-               /* Alarm is being canceled. */
-               if (priv->pending_alarm == 0)
-                       return;
-               rte_pause();
-       }
        priv->pending_alarm = 0;
        ret = priv_link_status_update(priv);
-       priv_unlock(priv);
        if (!ret)
                _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
 }
@@ -1215,9 +1025,7 @@ mlx5_dev_interrupt_handler(void *cb_arg)
        struct priv *priv = dev->data->dev_private;
        uint32_t events;
 
-       priv_lock(priv);
        events = priv_dev_status_handler(priv);
-       priv_unlock(priv);
        if (events & (1 << RTE_ETH_EVENT_INTR_LSC))
                _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
        if (events & (1 << RTE_ETH_EVENT_INTR_RMV))
@@ -1236,9 +1044,7 @@ mlx5_dev_handler_socket(void *cb_arg)
        struct rte_eth_dev *dev = cb_arg;
        struct priv *priv = dev->data->dev_private;
 
-       priv_lock(priv);
        priv_socket_handle(priv);
-       priv_unlock(priv);
 }
 
 /**
@@ -1297,7 +1103,6 @@ priv_dev_interrupt_handler_install(struct priv *priv, struct rte_eth_dev *dev)
                rte_intr_callback_register(&priv->intr_handle,
                                           mlx5_dev_interrupt_handler, dev);
        }
-
        rc = priv_socket_init(priv);
        if (!rc && priv->primary_socket) {
                priv->intr_handle_socket.fd = priv->primary_socket;
@@ -1312,8 +1117,6 @@ priv_dev_interrupt_handler_install(struct priv *priv, struct rte_eth_dev *dev)
  *
  * @param priv
  *   Pointer to private data structure.
- * @param dev
- *   Pointer to rte_eth_dev structure.
  * @param up
  *   Nonzero for link up, otherwise link down.
  *
@@ -1321,24 +1124,9 @@ priv_dev_interrupt_handler_install(struct priv *priv, struct rte_eth_dev *dev)
  *   0 on success, errno value on failure.
  */
 static int
-priv_dev_set_link(struct priv *priv, struct rte_eth_dev *dev, int up)
+priv_dev_set_link(struct priv *priv, int up)
 {
-       int err;
-
-       if (up) {
-               err = priv_set_flags(priv, ~IFF_UP, IFF_UP);
-               if (err)
-                       return err;
-               dev->tx_pkt_burst = priv_select_tx_function(priv, dev);
-               dev->rx_pkt_burst = priv_select_rx_function(priv, dev);
-       } else {
-               err = priv_set_flags(priv, ~IFF_UP, ~IFF_UP);
-               if (err)
-                       return err;
-               dev->rx_pkt_burst = removed_rx_burst;
-               dev->tx_pkt_burst = removed_tx_burst;
-       }
-       return 0;
+       return priv_set_flags(priv, ~IFF_UP, up ? IFF_UP : ~IFF_UP);
 }
 
 /**
@@ -1356,9 +1144,7 @@ mlx5_set_link_down(struct rte_eth_dev *dev)
        struct priv *priv = dev->data->dev_private;
        int err;
 
-       priv_lock(priv);
-       err = priv_dev_set_link(priv, dev, 0);
-       priv_unlock(priv);
+       err = priv_dev_set_link(priv, 0);
        return err;
 }
 
@@ -1377,9 +1163,7 @@ mlx5_set_link_up(struct rte_eth_dev *dev)
        struct priv *priv = dev->data->dev_private;
        int err;
 
-       priv_lock(priv);
-       err = priv_dev_set_link(priv, dev, 1);
-       priv_unlock(priv);
+       err = priv_dev_set_link(priv, 1);
        return err;
 }
 
@@ -1453,3 +1237,23 @@ priv_select_rx_function(struct priv *priv, __rte_unused struct rte_eth_dev *dev)
        }
        return rx_pkt_burst;
 }
+
+/**
+ * Check if mlx5 device was removed.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ *
+ * @return
+ *   1 when device is removed, otherwise 0.
+ */
+int
+mlx5_is_removed(struct rte_eth_dev *dev)
+{
+       struct ibv_device_attr device_attr;
+       struct priv *priv = dev->data->dev_private;
+
+       if (mlx5_glue->query_device(priv->ctx, &device_attr) == EIO)
+               return 1;
+       return 0;
+}