net/mlx4: use a single interrupt handle
[dpdk.git] / drivers / net / mlx4 / mlx4.c
index fbb3d73..21762cc 100644 (file)
 #include <rte_mempool.h>
 #include <rte_prefetch.h>
 #include <rte_malloc.h>
-#include <rte_spinlock.h>
-#include <rte_log.h>
 #include <rte_alarm.h>
 #include <rte_memory.h>
 #include <rte_flow.h>
 #include <rte_kvargs.h>
 #include <rte_interrupts.h>
 #include <rte_branch_prediction.h>
+#include <rte_common.h>
 
 /* Generated configuration header. */
 #include "mlx4_autoconf.h"
 /* PMD headers. */
 #include "mlx4.h"
 #include "mlx4_flow.h"
-
-/* Convenience macros for accessing mbuf fields. */
-#define NEXT(m) ((m)->next)
-#define DATA_LEN(m) ((m)->data_len)
-#define PKT_LEN(m) ((m)->pkt_len)
-#define DATA_OFF(m) ((m)->data_off)
-#define SET_DATA_OFF(m, o) ((m)->data_off = (o))
-#define NB_SEGS(m) ((m)->nb_segs)
-#define PORT(m) ((m)->port)
+#include "mlx4_utils.h"
 
 /** Configuration structure for device arguments. */
 struct mlx4_conf {
@@ -110,29 +101,6 @@ priv_rx_intr_vec_enable(struct priv *priv);
 static void
 priv_rx_intr_vec_disable(struct priv *priv);
 
-/**
- * Lock private structure to protect it from concurrent access in the
- * control path.
- *
- * @param priv
- *   Pointer to private structure.
- */
-void priv_lock(struct priv *priv)
-{
-       rte_spinlock_lock(&priv->lock);
-}
-
-/**
- * Unlock private structure.
- *
- * @param priv
- *   Pointer to private structure.
- */
-void priv_unlock(struct priv *priv)
-{
-       rte_spinlock_unlock(&priv->lock);
-}
-
 /* Allocate a buffer on the stack and fill it with a printf format string. */
 #define MKSTR(name, ...) \
        char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \
@@ -441,10 +409,10 @@ priv_get_mtu(struct priv *priv, uint16_t *mtu)
 }
 
 /**
- * Set device MTU.
+ * DPDK callback to change the MTU.
  *
  * @param priv
- *   Pointer to private structure.
+ *   Pointer to Ethernet device structure.
  * @param mtu
  *   MTU value to set.
  *
@@ -452,8 +420,9 @@ priv_get_mtu(struct priv *priv, uint16_t *mtu)
  *   0 on success, negative errno value otherwise and rte_errno is set.
  */
 static int
-priv_set_mtu(struct priv *priv, uint16_t mtu)
+mlx4_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 {
+       struct priv *priv = dev->data->dev_private;
        uint16_t new_mtu;
        int ret = priv_set_sysfs_ulong(priv, "mtu", mtu);
 
@@ -462,8 +431,10 @@ priv_set_mtu(struct priv *priv, uint16_t mtu)
        ret = priv_get_mtu(priv, &new_mtu);
        if (ret)
                return ret;
-       if (new_mtu == mtu)
+       if (new_mtu == mtu) {
+               priv->mtu = mtu;
                return 0;
+       }
        rte_errno = EINVAL;
        return -rte_errno;
 }
@@ -515,7 +486,7 @@ static void
 priv_mac_addr_del(struct priv *priv);
 
 /**
- * Ethernet device configuration.
+ * DPDK callback for Ethernet device configuration.
  *
  * Prepare the driver for a given number of TX and RX queues.
  *
@@ -526,7 +497,7 @@ priv_mac_addr_del(struct priv *priv);
  *   0 on success, negative errno value otherwise and rte_errno is set.
  */
 static int
-dev_configure(struct rte_eth_dev *dev)
+mlx4_dev_configure(struct rte_eth_dev *dev)
 {
        struct priv *priv = dev->data->dev_private;
        unsigned int rxqs_n = dev->data->nb_rx_queues;
@@ -547,27 +518,6 @@ dev_configure(struct rte_eth_dev *dev)
        return 0;
 }
 
-/**
- * DPDK callback for Ethernet device configuration.
- *
- * @param dev
- *   Pointer to Ethernet device structure.
- *
- * @return
- *   0 on success, negative errno value otherwise and rte_errno is set.
- */
-static int
-mlx4_dev_configure(struct rte_eth_dev *dev)
-{
-       struct priv *priv = dev->data->dev_private;
-       int ret;
-
-       priv_lock(priv);
-       ret = dev_configure(dev);
-       priv_unlock(priv);
-       return ret;
-}
-
 static uint16_t mlx4_tx_burst(void *, struct rte_mbuf **, uint16_t);
 static uint16_t removed_rx_burst(void *, struct rte_mbuf **, uint16_t);
 
@@ -608,8 +558,10 @@ txq_alloc_elts(struct txq *txq, unsigned int elts_n)
        txq->elts_head = 0;
        txq->elts_tail = 0;
        txq->elts_comp = 0;
-       /* Request send completion every MLX4_PMD_TX_PER_COMP_REQ packets or
-        * at least 4 times per ring. */
+       /*
+        * Request send completion every MLX4_PMD_TX_PER_COMP_REQ packets or
+        * at least 4 times per ring.
+        */
        txq->elts_comp_cd_init =
                ((MLX4_PMD_TX_PER_COMP_REQ < (elts_n / 4)) ?
                 MLX4_PMD_TX_PER_COMP_REQ : (elts_n / 4));
@@ -618,7 +570,6 @@ txq_alloc_elts(struct txq *txq, unsigned int elts_n)
        return 0;
 error:
        rte_free(elts);
-
        DEBUG("%p: failed, freed everything", (void *)txq);
        assert(ret > 0);
        rte_errno = ret;
@@ -664,7 +615,6 @@ txq_free_elts(struct txq *txq)
        rte_free(elts);
 }
 
-
 /**
  * Clean up a TX queue.
  *
@@ -684,7 +634,7 @@ txq_cleanup(struct txq *txq)
                claim_zero(ibv_destroy_qp(txq->qp));
        if (txq->cq != NULL)
                claim_zero(ibv_destroy_cq(txq->cq));
-       for (i = 0; (i != elemof(txq->mp2mr)); ++i) {
+       for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
                if (txq->mp2mr[i].mp == NULL)
                        break;
                assert(txq->mp2mr[i].mr != NULL);
@@ -755,7 +705,6 @@ static void mlx4_check_mempool_cb(struct rte_mempool *mp,
 
        (void)mp;
        (void)mem_idx;
-
        /* It already failed, skip the next chunks. */
        if (data->ret != 0)
                return;
@@ -799,7 +748,6 @@ static int mlx4_check_mempool(struct rte_mempool *mp, uintptr_t *start,
        rte_mempool_mem_iter(mp, mlx4_check_mempool_cb, &data);
        *start = (uintptr_t)data.start;
        *end = (uintptr_t)data.end;
-
        return data.ret;
 }
 
@@ -833,7 +781,6 @@ mlx4_mp2mr(struct ibv_pd *pd, struct rte_mempool *mp)
                        (void *)mp);
                return NULL;
        }
-
        DEBUG("mempool %p area start=%p end=%p size=%zu",
              (void *)mp, (void *)start, (void *)end,
              (size_t)(end - start));
@@ -897,7 +844,7 @@ txq_mp2mr(struct txq *txq, struct rte_mempool *mp)
        unsigned int i;
        struct ibv_mr *mr;
 
-       for (i = 0; (i != elemof(txq->mp2mr)); ++i) {
+       for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
                if (unlikely(txq->mp2mr[i].mp == NULL)) {
                        /* Unknown MP, add a new MR for it. */
                        break;
@@ -917,7 +864,7 @@ txq_mp2mr(struct txq *txq, struct rte_mempool *mp)
                      (void *)txq);
                return (uint32_t)-1;
        }
-       if (unlikely(i == elemof(txq->mp2mr))) {
+       if (unlikely(i == RTE_DIM(txq->mp2mr))) {
                /* Table is full, remove oldest entry. */
                DEBUG("%p: MR <-> MP table full, dropping oldest entry.",
                      (void *)txq);
@@ -960,8 +907,10 @@ txq_mp2mr_mbuf_check(struct rte_mempool *mp, void *arg, void *obj,
        struct txq_mp2mr_mbuf_check_data *data = arg;
        struct rte_mbuf *buf = obj;
 
-       /* Check whether mbuf structure fits element size and whether mempool
-        * pointer is valid. */
+       /*
+        * Check whether mbuf structure fits element size and whether mempool
+        * pointer is valid.
+        */
        if (sizeof(*buf) > mp->elt_size || buf->pool != mp)
                data->ret = -1;
 }
@@ -1038,7 +987,7 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
                struct txq_elt *elt_next = &(*txq->elts)[elts_head_next];
                struct txq_elt *elt = &(*txq->elts)[elts_head];
                struct ibv_send_wr *wr = &elt->wr;
-               unsigned int segs = NB_SEGS(buf);
+               unsigned int segs = buf->nb_segs;
                unsigned int sent_size = 0;
                uint32_t send_flags = 0;
 
@@ -1052,7 +1001,7 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
 #endif
                        /* Faster than rte_pktmbuf_free(). */
                        do {
-                               struct rte_mbuf *next = NEXT(tmp);
+                               struct rte_mbuf *next = tmp->next;
 
                                rte_pktmbuf_free_seg(tmp);
                                tmp = next;
@@ -1072,7 +1021,7 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
 
                        /* Retrieve buffer information. */
                        addr = rte_pktmbuf_mtod(buf, uintptr_t);
-                       length = DATA_LEN(buf);
+                       length = buf->data_len;
                        /* Retrieve Memory Region key for this memory pool. */
                        lkey = txq_mp2mr(txq, txq_mb2mp(buf));
                        if (unlikely(lkey == (uint32_t)-1)) {
@@ -1224,8 +1173,10 @@ txq_setup(struct rte_eth_dev *dev, struct txq *txq, uint16_t desc,
                        .max_inline_data = MLX4_PMD_MAX_INLINE,
                },
                .qp_type = IBV_QPT_RAW_PACKET,
-               /* Do *NOT* enable this, completions events are managed per
-                * TX burst. */
+               /*
+                * Do *NOT* enable this, completions events are managed per
+                * Tx burst.
+                */
                .sq_sig_all = 0,
        };
        tmpl.qp = ibv_create_qp(priv->pd, &attr.init);
@@ -1316,14 +1267,12 @@ mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
        struct txq *txq = (*priv->txqs)[idx];
        int ret;
 
-       priv_lock(priv);
        DEBUG("%p: configuring queue %u for %u descriptors",
              (void *)dev, idx, desc);
        if (idx >= priv->txqs_n) {
                rte_errno = EOVERFLOW;
                ERROR("%p: queue index out of range (%u >= %u)",
                      (void *)dev, idx, priv->txqs_n);
-               priv_unlock(priv);
                return -rte_errno;
        }
        if (txq != NULL) {
@@ -1331,7 +1280,6 @@ mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                      (void *)dev, idx, (void *)txq);
                if (priv->started) {
                        rte_errno = EEXIST;
-                       priv_unlock(priv);
                        return -rte_errno;
                }
                (*priv->txqs)[idx] = NULL;
@@ -1342,7 +1290,6 @@ mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                        rte_errno = ENOMEM;
                        ERROR("%p: unable to allocate queue index %u",
                              (void *)dev, idx);
-                       priv_unlock(priv);
                        return -rte_errno;
                }
        }
@@ -1357,7 +1304,6 @@ mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                /* Update send callback. */
                dev->tx_pkt_burst = mlx4_tx_burst;
        }
-       priv_unlock(priv);
        return ret;
 }
 
@@ -1377,7 +1323,6 @@ mlx4_tx_queue_release(void *dpdk_txq)
        if (txq == NULL)
                return;
        priv = txq->priv;
-       priv_lock(priv);
        for (i = 0; (i != priv->txqs_n); ++i)
                if ((*priv->txqs)[i] == txq) {
                        DEBUG("%p: removing TX queue %p from list",
@@ -1387,7 +1332,6 @@ mlx4_tx_queue_release(void *dpdk_txq)
                }
        txq_cleanup(txq);
        rte_free(txq);
-       priv_unlock(priv);
 }
 
 /* RX queues handling. */
@@ -1433,7 +1377,7 @@ rxq_alloc_elts(struct rxq *rxq, unsigned int elts_n)
                wr->sg_list = sge;
                wr->num_sge = 1;
                /* Headroom is reserved by rte_pktmbuf_alloc(). */
-               assert(DATA_OFF(buf) == RTE_PKTMBUF_HEADROOM);
+               assert(buf->data_off == RTE_PKTMBUF_HEADROOM);
                /* Buffer is supposed to be empty. */
                assert(rte_pktmbuf_data_len(buf) == 0);
                assert(rte_pktmbuf_pkt_len(buf) == 0);
@@ -1457,7 +1401,7 @@ rxq_alloc_elts(struct rxq *rxq, unsigned int elts_n)
        return 0;
 error:
        if (elts != NULL) {
-               for (i = 0; (i != elemof(*elts)); ++i)
+               for (i = 0; (i != RTE_DIM(*elts)); ++i)
                        rte_pktmbuf_free_seg((*elts)[i].buf);
                rte_free(elts);
        }
@@ -1484,7 +1428,7 @@ rxq_free_elts(struct rxq *rxq)
        rxq->elts = NULL;
        if (elts == NULL)
                return;
-       for (i = 0; (i != elemof(*elts)); ++i)
+       for (i = 0; (i != RTE_DIM(*elts)); ++i)
                rte_pktmbuf_free_seg((*elts)[i].buf);
        rte_free(elts);
 }
@@ -1698,22 +1642,19 @@ mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
                        ++rxq->priv->dev->data->rx_mbuf_alloc_failed;
                        goto repost;
                }
-
                /* Reconfigure sge to use rep instead of seg. */
                elt->sge.addr = (uintptr_t)rep->buf_addr + RTE_PKTMBUF_HEADROOM;
                assert(elt->sge.lkey == rxq->mr->lkey);
                elt->buf = rep;
-
                /* Update seg information. */
-               SET_DATA_OFF(seg, RTE_PKTMBUF_HEADROOM);
-               NB_SEGS(seg) = 1;
-               PORT(seg) = rxq->port_id;
-               NEXT(seg) = NULL;
-               PKT_LEN(seg) = len;
-               DATA_LEN(seg) = len;
+               seg->data_off = RTE_PKTMBUF_HEADROOM;
+               seg->nb_segs = 1;
+               seg->port = rxq->port_id;
+               seg->next = NULL;
+               seg->pkt_len = len;
+               seg->data_len = len;
                seg->packet_type = 0;
                seg->ol_flags = 0;
-
                /* Return packet. */
                *(pkts++) = seg;
                ++pkts_ret;
@@ -1960,14 +1901,12 @@ mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
        struct rxq *rxq = (*priv->rxqs)[idx];
        int ret;
 
-       priv_lock(priv);
        DEBUG("%p: configuring queue %u for %u descriptors",
              (void *)dev, idx, desc);
        if (idx >= priv->rxqs_n) {
                rte_errno = EOVERFLOW;
                ERROR("%p: queue index out of range (%u >= %u)",
                      (void *)dev, idx, priv->rxqs_n);
-               priv_unlock(priv);
                return -rte_errno;
        }
        if (rxq != NULL) {
@@ -1975,7 +1914,6 @@ mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                      (void *)dev, idx, (void *)rxq);
                if (priv->started) {
                        rte_errno = EEXIST;
-                       priv_unlock(priv);
                        return -rte_errno;
                }
                (*priv->rxqs)[idx] = NULL;
@@ -1988,7 +1926,6 @@ mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                        rte_errno = ENOMEM;
                        ERROR("%p: unable to allocate queue index %u",
                              (void *)dev, idx);
-                       priv_unlock(priv);
                        return -rte_errno;
                }
        }
@@ -2003,7 +1940,6 @@ mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                /* Update receive callback. */
                dev->rx_pkt_burst = mlx4_rx_burst;
        }
-       priv_unlock(priv);
        return ret;
 }
 
@@ -2023,7 +1959,6 @@ mlx4_rx_queue_release(void *dpdk_rxq)
        if (rxq == NULL)
                return;
        priv = rxq->priv;
-       priv_lock(priv);
        for (i = 0; (i != priv->rxqs_n); ++i)
                if ((*priv->rxqs)[i] == rxq) {
                        DEBUG("%p: removing RX queue %p from list",
@@ -2035,7 +1970,6 @@ mlx4_rx_queue_release(void *dpdk_rxq)
                }
        rxq_cleanup(rxq);
        rte_free(rxq);
-       priv_unlock(priv);
 }
 
 static int
@@ -2064,11 +1998,8 @@ mlx4_dev_start(struct rte_eth_dev *dev)
        struct priv *priv = dev->data->dev_private;
        int ret;
 
-       priv_lock(priv);
-       if (priv->started) {
-               priv_unlock(priv);
+       if (priv->started)
                return 0;
-       }
        DEBUG("%p: attaching configured flows to all RX queues", (void *)dev);
        priv->started = 1;
        ret = priv_mac_addr_add(priv);
@@ -2098,13 +2029,11 @@ mlx4_dev_start(struct rte_eth_dev *dev)
                      (void *)dev, strerror(ret));
                goto err;
        }
-       priv_unlock(priv);
        return 0;
 err:
        /* Rollback. */
        priv_mac_addr_del(priv);
        priv->started = 0;
-       priv_unlock(priv);
        return ret;
 }
 
@@ -2121,16 +2050,12 @@ mlx4_dev_stop(struct rte_eth_dev *dev)
 {
        struct priv *priv = dev->data->dev_private;
 
-       priv_lock(priv);
-       if (!priv->started) {
-               priv_unlock(priv);
+       if (!priv->started)
                return;
-       }
        DEBUG("%p: detaching flows from all RX queues", (void *)dev);
        priv->started = 0;
        mlx4_priv_flow_stop(priv);
        priv_mac_addr_del(priv);
-       priv_unlock(priv);
 }
 
 /**
@@ -2210,14 +2135,15 @@ mlx4_dev_close(struct rte_eth_dev *dev)
 
        if (priv == NULL)
                return;
-       priv_lock(priv);
        DEBUG("%p: closing device \"%s\"",
              (void *)dev,
              ((priv->ctx != NULL) ? priv->ctx->device->name : ""));
        priv_mac_addr_del(priv);
-       /* Prevent crashes when queues are still in use. This is unfortunately
+       /*
+        * Prevent crashes when queues are still in use. This is unfortunately
         * still required for DPDK 1.3 because some programs (such as testpmd)
-        * never release them before closing the device. */
+        * never release them before closing the device.
+        */
        dev->rx_pkt_burst = removed_rx_burst;
        dev->tx_pkt_burst = removed_tx_burst;
        if (priv->rxqs != NULL) {
@@ -2257,7 +2183,6 @@ mlx4_dev_close(struct rte_eth_dev *dev)
        priv_dev_removal_interrupt_handler_uninstall(priv, dev);
        priv_dev_link_interrupt_handler_uninstall(priv, dev);
        priv_rx_intr_vec_disable(priv);
-       priv_unlock(priv);
        memset(priv, 0, sizeof(*priv));
 }
 
@@ -2306,12 +2231,8 @@ static int
 mlx4_set_link_down(struct rte_eth_dev *dev)
 {
        struct priv *priv = dev->data->dev_private;
-       int err;
 
-       priv_lock(priv);
-       err = priv_set_link(priv, 0);
-       priv_unlock(priv);
-       return err;
+       return priv_set_link(priv, 0);
 }
 
 /**
@@ -2327,13 +2248,10 @@ static int
 mlx4_set_link_up(struct rte_eth_dev *dev)
 {
        struct priv *priv = dev->data->dev_private;
-       int err;
 
-       priv_lock(priv);
-       err = priv_set_link(priv, 1);
-       priv_unlock(priv);
-       return err;
+       return priv_set_link(priv, 1);
 }
+
 /**
  * DPDK callback to get information about the device.
  *
@@ -2350,10 +2268,8 @@ mlx4_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);
-
        if (priv == NULL)
                return;
-       priv_lock(priv);
        /* FIXME: we should ask the device for these values. */
        info->min_rx_bufsize = 32;
        info->max_rx_pktlen = 65536;
@@ -2380,7 +2296,6 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
                        ETH_LINK_SPEED_20G |
                        ETH_LINK_SPEED_40G |
                        ETH_LINK_SPEED_56G;
-       priv_unlock(priv);
 }
 
 /**
@@ -2401,7 +2316,6 @@ mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 
        if (priv == NULL)
                return;
-       priv_lock(priv);
        /* Add software counters. */
        for (i = 0; (i != priv->rxqs_n); ++i) {
                struct rxq *rxq = (*priv->rxqs)[i];
@@ -2436,7 +2350,6 @@ mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
                tmp.oerrors += txq->stats.odropped;
        }
        *stats = tmp;
-       priv_unlock(priv);
 }
 
 /**
@@ -2454,7 +2367,6 @@ mlx4_stats_reset(struct rte_eth_dev *dev)
 
        if (priv == NULL)
                return;
-       priv_lock(priv);
        for (i = 0; (i != priv->rxqs_n); ++i) {
                if ((*priv->rxqs)[i] == NULL)
                        continue;
@@ -2469,7 +2381,6 @@ mlx4_stats_reset(struct rte_eth_dev *dev)
                (*priv->txqs)[i]->stats =
                        (struct mlx4_txq_stats){ .idx = idx };
        }
-       priv_unlock(priv);
 }
 
 /**
@@ -2494,8 +2405,6 @@ mlx4_link_update(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. */
-
        if (priv == NULL) {
                rte_errno = EINVAL;
                return -rte_errno;
@@ -2527,39 +2436,6 @@ mlx4_link_update(struct rte_eth_dev *dev, int wait_to_complete)
        return 0;
 }
 
-/**
- * DPDK callback to change the MTU.
- *
- * @param dev
- *   Pointer to Ethernet device structure.
- * @param in_mtu
- *   New MTU.
- *
- * @return
- *   0 on success, negative errno value otherwise and rte_errno is set.
- */
-static int
-mlx4_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
-{
-       struct priv *priv = dev->data->dev_private;
-       int ret = 0;
-
-       priv_lock(priv);
-       /* Set kernel interface MTU first. */
-       if (priv_set_mtu(priv, mtu)) {
-               ret = rte_errno;
-               WARN("cannot set port %u MTU to %u: %s", priv->port, mtu,
-                    strerror(rte_errno));
-               goto out;
-       } else
-               DEBUG("adapter port %u MTU set to %u", priv->port, mtu);
-       priv->mtu = mtu;
-out:
-       priv_unlock(priv);
-       assert(ret >= 0);
-       return -ret;
-}
-
 /**
  * DPDK callback to get flow control status.
  *
@@ -2582,7 +2458,6 @@ mlx4_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 = rte_errno;
                WARN("ioctl(SIOCETHTOOL, ETHTOOL_GPAUSEPARAM)"
@@ -2590,7 +2465,6 @@ mlx4_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
                     strerror(rte_errno));
                goto out;
        }
-
        fc_conf->autoneg = ethpause.autoneg;
        if (ethpause.rx_pause && ethpause.tx_pause)
                fc_conf->mode = RTE_FC_FULL;
@@ -2601,9 +2475,7 @@ mlx4_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;
 }
@@ -2636,14 +2508,11 @@ mlx4_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
                ethpause.rx_pause = 1;
        else
                ethpause.rx_pause = 0;
-
        if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) ||
            (fc_conf->mode & RTE_FC_TX_PAUSE))
                ethpause.tx_pause = 1;
        else
                ethpause.tx_pause = 0;
-
-       priv_lock(priv);
        if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
                ret = rte_errno;
                WARN("ioctl(SIOCETHTOOL, ETHTOOL_SPAUSEPARAM)"
@@ -2652,9 +2521,7 @@ mlx4_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;
 }
@@ -2880,14 +2747,12 @@ mlx4_dev_link_status_handler(void *arg)
        uint32_t events;
        int ret;
 
-       priv_lock(priv);
        assert(priv->pending_alarm == 1);
        priv->pending_alarm = 0;
        ret = priv_dev_status_handler(priv, dev, &events);
-       priv_unlock(priv);
        if (ret > 0 && events & (1 << RTE_ETH_EVENT_INTR_LSC))
-               _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL,
-                                             NULL);
+               _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
+                                             NULL, NULL);
 }
 
 /**
@@ -2907,9 +2772,7 @@ mlx4_dev_interrupt_handler(void *cb_arg)
        uint32_t ev;
        int i;
 
-       priv_lock(priv);
        ret = priv_dev_status_handler(priv, dev, &ev);
-       priv_unlock(priv);
        if (ret > 0) {
                for (i = RTE_ETH_EVENT_UNKNOWN;
                     i < RTE_ETH_EVENT_MAX;
@@ -2934,6 +2797,7 @@ mlx4_dev_interrupt_handler(void *cb_arg)
  *   Pointer to private structure.
  * @param dev
  *   Pointer to the rte_eth_dev structure.
+ *
  * @return
  *   0 on success, negative errno value otherwise and rte_errno is set.
  */
@@ -2953,8 +2817,7 @@ priv_dev_interrupt_handler_uninstall(struct priv *priv, struct rte_eth_dev *dev)
                ERROR("rte_intr_callback_unregister failed with %d %s",
                      ret, strerror(rte_errno));
        }
-       priv->intr_handle.fd = 0;
-       priv->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+       priv->intr_handle.fd = -1;
        return ret;
 }
 
@@ -2965,6 +2828,7 @@ priv_dev_interrupt_handler_uninstall(struct priv *priv, struct rte_eth_dev *dev)
  *   Pointer to private structure.
  * @param dev
  *   Pointer to the rte_eth_dev structure.
+ *
  * @return
  *   0 on success, negative errno value otherwise and rte_errno is set.
  */
@@ -2975,8 +2839,9 @@ priv_dev_interrupt_handler_install(struct priv *priv,
        int flags;
        int rc;
 
-       /* Check whether the interrupt handler has already been installed
-        * for either type of interrupt
+       /*
+        * Check whether the interrupt handler has already been installed
+        * for either type of interrupt.
         */
        if (priv->intr_conf.lsc &&
            priv->intr_conf.rmv &&
@@ -2993,7 +2858,6 @@ priv_dev_interrupt_handler_install(struct priv *priv,
                return -rte_errno;
        } else {
                priv->intr_handle.fd = priv->ctx->async_fd;
-               priv->intr_handle.type = RTE_INTR_HANDLE_EXT;
                rc = rte_intr_callback_register(&priv->intr_handle,
                                                 mlx4_dev_interrupt_handler,
                                                 dev);
@@ -3001,6 +2865,7 @@ priv_dev_interrupt_handler_install(struct priv *priv,
                        rte_errno = -rc;
                        ERROR("rte_intr_callback_register failed "
                              " (rte_errno: %s)", strerror(rte_errno));
+                       priv->intr_handle.fd = -1;
                        return -rte_errno;
                }
        }
@@ -3014,6 +2879,7 @@ priv_dev_interrupt_handler_install(struct priv *priv,
  *   Pointer to private structure.
  * @param dev
  *   Pointer to the rte_eth_dev structure.
+ *
  * @return
  *   0 on success, negative errno value otherwise and rte_errno is set.
  */
@@ -3035,6 +2901,7 @@ priv_dev_removal_interrupt_handler_uninstall(struct priv *priv,
  *   Pointer to private structure.
  * @param dev
  *   Pointer to the rte_eth_dev structure.
+ *
  * @return
  *   0 on success, negative errno value otherwise and rte_errno is set.
  */
@@ -3068,6 +2935,7 @@ priv_dev_link_interrupt_handler_uninstall(struct priv *priv,
  *   Pointer to private structure.
  * @param dev
  *   Pointer to the rte_eth_dev structure.
+ *
  * @return
  *   0 on success, negative errno value otherwise and rte_errno is set.
  */
@@ -3093,6 +2961,7 @@ priv_dev_link_interrupt_handler_install(struct priv *priv,
  *   Pointer to private structure.
  * @param dev
  *   Pointer to the rte_eth_dev structure.
+ *
  * @return
  *   0 on success, negative errno value otherwise and rte_errno is set.
  */
@@ -3127,7 +2996,7 @@ priv_rx_intr_vec_enable(struct priv *priv)
        unsigned int rxqs_n = priv->rxqs_n;
        unsigned int n = RTE_MIN(rxqs_n, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
        unsigned int count = 0;
-       struct rte_intr_handle *intr_handle = priv->dev->intr_handle;
+       struct rte_intr_handle *intr_handle = &priv->intr_handle;
 
        if (!priv->dev->data->dev_conf.intr_conf.rxq)
                return 0;
@@ -3139,7 +3008,6 @@ priv_rx_intr_vec_enable(struct priv *priv)
                      " Rx interrupts will not be supported");
                return -rte_errno;
        }
-       intr_handle->type = RTE_INTR_HANDLE_EXT;
        for (i = 0; i != n; ++i) {
                struct rxq *rxq = (*priv->rxqs)[i];
                int fd;
@@ -3192,7 +3060,7 @@ priv_rx_intr_vec_enable(struct priv *priv)
 static void
 priv_rx_intr_vec_disable(struct priv *priv)
 {
-       struct rte_intr_handle *intr_handle = priv->dev->intr_handle;
+       struct rte_intr_handle *intr_handle = &priv->intr_handle;
 
        rte_intr_free_epoll_fd(intr_handle);
        free(intr_handle->intr_vec);
@@ -3390,7 +3258,6 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 
        (void)pci_drv;
        assert(pci_drv == &mlx4_driver);
-
        list = ibv_get_device_list(&i);
        if (list == NULL) {
                rte_errno = errno;
@@ -3441,14 +3308,12 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                return -rte_errno;
        }
        ibv_dev = list[i];
-
        DEBUG("device opened");
        if (ibv_query_device(attr_ctx, &device_attr)) {
                rte_errno = ENODEV;
                goto error;
        }
        INFO("%u port(s) detected", device_attr.phys_port_cnt);
-
        conf.ports.present |= (UINT64_C(1) << device_attr.phys_port_cnt) - 1;
        if (mlx4_args(pci_dev->device.devargs, &conf)) {
                ERROR("failed to process device arguments");
@@ -3470,15 +3335,12 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                /* If port is not enabled, skip. */
                if (!(conf.ports.enabled & (1 << i)))
                        continue;
-
                DEBUG("using port %u", port);
-
                ctx = ibv_open_device(ibv_dev);
                if (ctx == NULL) {
                        rte_errno = ENODEV;
                        goto port_error;
                }
-
                /* Check port status. */
                err = ibv_query_port(ctx, port, &port_attr);
                if (err) {
@@ -3486,19 +3348,16 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                        ERROR("port query failed: %s", strerror(rte_errno));
                        goto port_error;
                }
-
                if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
                        rte_errno = ENOTSUP;
                        ERROR("port %d is not configured in Ethernet mode",
                              port);
                        goto port_error;
                }
-
                if (port_attr.state != IBV_PORT_ACTIVE)
                        DEBUG("port %d is not active: \"%s\" (%d)",
                              port, ibv_port_state_str(port_attr.state),
                              port_attr.state);
-
                /* Allocate protection domain. */
                pd = ibv_alloc_pd(ctx);
                if (pd == NULL) {
@@ -3506,7 +3365,6 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                        ERROR("PD allocation failure");
                        goto port_error;
                }
-
                /* from rte_ethdev.c */
                priv = rte_zmalloc("ethdev private structure",
                                   sizeof(*priv),
@@ -3516,13 +3374,11 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                        ERROR("priv allocation failure");
                        goto port_error;
                }
-
                priv->ctx = ctx;
                priv->device_attr = device_attr;
                priv->port = port;
                priv->pd = pd;
                priv->mtu = ETHER_MTU;
-
                priv->vf = vf;
                /* Configure the first MAC address by default. */
                if (priv_get_mac(priv, &mac.addr_bytes)) {
@@ -3553,7 +3409,6 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                /* Get actual MTU if possible. */
                priv_get_mtu(priv, &priv->mtu);
                DEBUG("port %u MTU is %u", priv->port, priv->mtu);
-
                /* from rte_ethdev.c */
                {
                        char name[RTE_ETH_NAME_MAX_LEN];
@@ -3567,28 +3422,32 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                        rte_errno = ENOMEM;
                        goto port_error;
                }
-
                eth_dev->data->dev_private = priv;
                eth_dev->data->mac_addrs = &priv->mac;
                eth_dev->device = &pci_dev->device;
-
                rte_eth_copy_pci_info(eth_dev, pci_dev);
-
                eth_dev->device->driver = &mlx4_driver.driver;
-
+               /* Initialize local interrupt handle for current port. */
+               priv->intr_handle = (struct rte_intr_handle){
+                       .fd = -1,
+                       .type = RTE_INTR_HANDLE_EXT,
+               };
                /*
-                * Copy and override interrupt handle to prevent it from
-                * being shared between all ethdev instances of a given PCI
-                * device. This is required to properly handle Rx interrupts
-                * on all ports.
+                * Override ethdev interrupt handle pointer with private
+                * handle instead of that of the parent PCI device used by
+                * default. This prevents it from being shared between all
+                * ports of the same PCI device since each of them is
+                * associated its own Verbs context.
+                *
+                * Rx interrupts in particular require this as the PMD has
+                * no control over the registration of queue interrupts
+                * besides setting up eth_dev->intr_handle, the rest is
+                * handled by rte_intr_rx_ctl().
                 */
-               priv->intr_handle_dev = *eth_dev->intr_handle;
-               eth_dev->intr_handle = &priv->intr_handle_dev;
-
+               eth_dev->intr_handle = &priv->intr_handle;
                priv->dev = eth_dev;
                eth_dev->dev_ops = &mlx4_dev_ops;
                eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
-
                /* Bring Ethernet device up. */
                DEBUG("forcing Ethernet interface up");
                priv_set_flags(priv, ~IFF_UP, IFF_UP);
@@ -3596,7 +3455,6 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
                        mlx4_link_update(eth_dev, 0);
                continue;
-
 port_error:
                rte_free(priv);
                if (pd)
@@ -3609,14 +3467,12 @@ port_error:
        }
        if (i == device_attr.phys_port_cnt)
                return 0;
-
        /*
         * XXX if something went wrong in the loop above, there is a resource
         * leak (ctx, pd, priv, dpdk ethdev) but we can do nothing about it as
         * long as the dpdk does not provide a way to deallocate a ethdev and a
         * way to enumerate the registered ethdevs to free the previous ones.
         */
-
 error:
        if (attr_ctx)
                claim_zero(ibv_close_device(attr_ctx));