net/mlx4: use a single interrupt handle
[dpdk.git] / drivers / net / mlx4 / mlx4.c
index dc8a96f..21762cc 100644 (file)
 #include <rte_mempool.h>
 #include <rte_prefetch.h>
 #include <rte_malloc.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 {
@@ -417,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.
  *
@@ -428,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);
 
@@ -438,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;
 }
@@ -491,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.
  *
@@ -502,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;
@@ -523,21 +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)
-{
-       return dev_configure(dev);
-}
-
 static uint16_t mlx4_tx_burst(void *, struct rte_mbuf **, uint16_t);
 static uint16_t removed_rx_burst(void *, struct rte_mbuf **, uint16_t);
 
@@ -654,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);
@@ -864,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;
@@ -884,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);
@@ -1007,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;
 
@@ -1021,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;
@@ -1041,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)) {
@@ -1397,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);
@@ -1421,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);
        }
@@ -1448,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);
 }
@@ -1667,12 +1647,12 @@ mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
                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. */
@@ -2456,37 +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;
-
-       /* 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:
-       assert(ret >= 0);
-       return -ret;
-}
-
 /**
  * DPDK callback to get flow control status.
  *
@@ -2868,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;
 }
 
@@ -2910,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);
@@ -2918,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;
                }
        }
@@ -3048,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;
@@ -3060,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;
@@ -3113,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);
@@ -3480,14 +3427,24 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                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;