ixgbe: move to drivers/net/
[dpdk.git] / lib / librte_pmd_mlx4 / mlx4.c
index 492cbbf..f915bc1 100644 (file)
 #include <linux/ethtool.h>
 #include <linux/sockios.h>
 
+/* Verbs header. */
+/* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
+#ifdef PEDANTIC
+#pragma GCC diagnostic ignored "-pedantic"
+#endif
+#include <infiniband/verbs.h>
+#ifdef PEDANTIC
+#pragma GCC diagnostic error "-pedantic"
+#endif
+
 /* DPDK headers don't like -pedantic. */
 #ifdef PEDANTIC
 #pragma GCC diagnostic ignored "-pedantic"
 #pragma GCC diagnostic error "-pedantic"
 #endif
 
-/* Verbs header. */
-/* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
-#ifdef PEDANTIC
-#pragma GCC diagnostic ignored "-pedantic"
-#endif
-
-#include <infiniband/verbs.h>
-
-#ifdef PEDANTIC
-#pragma GCC diagnostic error "-pedantic"
-#endif
-
 /* Generated configuration header. */
 #include "mlx4_autoconf.h"
 
@@ -280,9 +278,6 @@ struct priv {
        unsigned int hw_tss:1; /* TSS is supported. */
        unsigned int hw_rss:1; /* RSS is supported. */
        unsigned int rss:1; /* RSS is enabled. */
-#ifdef MLX4_COMPAT_VMWARE
-       unsigned int vmware:1; /* Use VMware compatibility. */
-#endif
        unsigned int vf:1; /* This is a VF device. */
 #ifdef INLINE_RECV
        unsigned int inl_recv_size; /* Inline recv size */
@@ -797,10 +792,10 @@ txq_alloc_elts(struct txq *txq, unsigned int elts_n)
 error:
        if (mr_linear != NULL)
                claim_zero(ibv_dereg_mr(mr_linear));
-       if (elts_linear != NULL)
-               rte_free(elts_linear);
-       if (elts != NULL)
-               rte_free(elts);
+
+       rte_free(elts_linear);
+       rte_free(elts);
+
        DEBUG("%p: failed, freed everything", (void *)txq);
        assert(ret > 0);
        return ret;
@@ -828,8 +823,8 @@ txq_free_elts(struct txq *txq)
        txq->mr_linear = NULL;
        if (mr_linear != NULL)
                claim_zero(ibv_dereg_mr(mr_linear));
-       if (elts_linear != NULL)
-               rte_free(elts_linear);
+
+       rte_free(elts_linear);
        if (elts == NULL)
                return;
        for (i = 0; (i != elemof(*elts)); ++i) {
@@ -1827,7 +1822,7 @@ rxq_free_elts(struct rxq *rxq)
 static void
 rxq_mac_addr_del(struct rxq *rxq, unsigned int mac_index)
 {
-#if defined(NDEBUG) || defined(MLX4_COMPAT_VMWARE)
+#ifndef NDEBUG
        struct priv *priv = rxq->priv;
        const uint8_t (*mac)[ETHER_ADDR_LEN] =
                (const uint8_t (*)[ETHER_ADDR_LEN])
@@ -1844,16 +1839,6 @@ rxq_mac_addr_del(struct rxq *rxq, unsigned int mac_index)
              (void *)rxq,
              (*mac)[0], (*mac)[1], (*mac)[2], (*mac)[3], (*mac)[4], (*mac)[5],
              mac_index);
-#ifdef MLX4_COMPAT_VMWARE
-       if (priv->vmware) {
-               union ibv_gid gid = { .raw = { 0 } };
-
-               memcpy(&gid.raw[10], *mac, sizeof(*mac));
-               claim_zero(ibv_detach_mcast(rxq->qp, &gid, 0));
-               BITFIELD_RESET(rxq->mac_configured, mac_index);
-               return;
-       }
-#endif
        assert(rxq->mac_flow[mac_index] != NULL);
        claim_zero(ibv_exp_destroy_flow(rxq->mac_flow[mac_index]));
        rxq->mac_flow[mac_index] = NULL;
@@ -1962,22 +1947,6 @@ rxq_mac_addr_add(struct rxq *rxq, unsigned int mac_index)
              (*mac)[0], (*mac)[1], (*mac)[2], (*mac)[3], (*mac)[4], (*mac)[5],
              mac_index,
              vlans);
-#ifdef MLX4_COMPAT_VMWARE
-       if (priv->vmware) {
-               union ibv_gid gid = { .raw = { 0 } };
-
-               /* Call multicast attach with unicast mac to get traffic. */
-               memcpy(&gid.raw[10], *mac, sizeof(*mac));
-               errno = 0;
-               if (ibv_attach_mcast(rxq->qp, &gid, 0)) {
-                       if (errno)
-                               return errno;
-                       return EINVAL;
-               }
-               BITFIELD_SET(rxq->mac_configured, mac_index);
-               return 0;
-       }
-#endif
        /* Create related flow. */
        errno = 0;
        flow = ibv_exp_create_flow(rxq->qp, attr);
@@ -2175,13 +2144,6 @@ rxq_allmulticast_enable(struct rxq *rxq)
                .flags = 0
        };
 
-#ifdef MLX4_COMPAT_VMWARE
-       if (rxq->priv->vmware) {
-               ERROR("%p: allmulticast mode is not supported in VMware",
-                     (void *)rxq);
-               return EINVAL;
-       }
-#endif
        DEBUG("%p: enabling allmulticast mode", (void *)rxq);
        if (rxq->allmulti_flow != NULL)
                return EBUSY;
@@ -2210,13 +2172,6 @@ rxq_allmulticast_enable(struct rxq *rxq)
 static void
 rxq_allmulticast_disable(struct rxq *rxq)
 {
-#ifdef MLX4_COMPAT_VMWARE
-       if (rxq->priv->vmware) {
-               ERROR("%p: allmulticast mode is not supported in VMware",
-                     (void *)rxq);
-               return;
-       }
-#endif
        DEBUG("%p: disabling allmulticast mode", (void *)rxq);
        if (rxq->allmulti_flow == NULL)
                return;
@@ -2245,13 +2200,6 @@ rxq_promiscuous_enable(struct rxq *rxq)
                .flags = 0
        };
 
-#ifdef MLX4_COMPAT_VMWARE
-       if (rxq->priv->vmware) {
-               ERROR("%p: promiscuous mode is not supported in VMware",
-                     (void *)rxq);
-               return EINVAL;
-       }
-#endif
        if (rxq->priv->vf)
                return 0;
        DEBUG("%p: enabling promiscuous mode", (void *)rxq);
@@ -2282,13 +2230,6 @@ rxq_promiscuous_enable(struct rxq *rxq)
 static void
 rxq_promiscuous_disable(struct rxq *rxq)
 {
-#ifdef MLX4_COMPAT_VMWARE
-       if (rxq->priv->vmware) {
-               ERROR("%p: promiscuous mode is not supported in VMware",
-                     (void *)rxq);
-               return;
-       }
-#endif
        if (rxq->priv->vf)
                return;
        DEBUG("%p: disabling promiscuous mode", (void *)rxq);
@@ -3556,7 +3497,7 @@ static void
 mlx4_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 {
        struct priv *priv = dev->data->dev_private;
-       struct rte_eth_stats tmp = { .ipackets = 0 };
+       struct rte_eth_stats tmp = {0};
        unsigned int i;
        unsigned int idx;
 
@@ -4221,7 +4162,7 @@ mlx4_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
        return -ret;
 }
 
-static struct eth_dev_ops mlx4_dev_ops = {
+static const struct eth_dev_ops mlx4_dev_ops = {
        .dev_configure = mlx4_dev_configure,
        .dev_start = mlx4_dev_start,
        .dev_stop = mlx4_dev_stop,
@@ -4425,6 +4366,10 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
        list = ibv_get_device_list(&i);
        if (list == NULL) {
                assert(errno);
+               if (errno == ENOSYS) {
+                       WARN("cannot list devices, is ib_uverbs loaded?");
+                       return 0;
+               }
                return -errno;
        }
        assert(i >= 0);
@@ -4453,9 +4398,15 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                break;
        }
        if (attr_ctx == NULL) {
-               if (err == 0)
-                       err = ENODEV;
                ibv_free_device_list(list);
+               switch (err) {
+               case 0:
+                       WARN("cannot access device, is mlx4_ib loaded?");
+                       return 0;
+               case EINVAL:
+                       WARN("cannot use device, are drivers up to date?");
+                       return 0;
+               }
                assert(err > 0);
                return -err;
        }
@@ -4586,12 +4537,7 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                }
 #endif /* INLINE_RECV */
 
-#ifdef MLX4_COMPAT_VMWARE
-               if (mlx4_getenv_int("MLX4_COMPAT_VMWARE"))
-                       priv->vmware = 1;
-#else /* MLX4_COMPAT_VMWARE */
                (void)mlx4_getenv_int;
-#endif /* MLX4_COMPAT_VMWARE */
                priv->vf = vf;
                if (ibv_query_gid(ctx, port, 0, &temp_gid)) {
                        ERROR("ibv_query_gid() failure");
@@ -4656,8 +4602,7 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                continue;
 
 port_error:
-               if (priv)
-                       rte_free(priv);
+               rte_free(priv);
                if (pd)
                        claim_zero(ibv_dealloc_pd(pd));
                if (ctx)
@@ -4687,7 +4632,7 @@ error:
        return -err;
 }
 
-static struct rte_pci_id mlx4_pci_id_map[] = {
+static const struct rte_pci_id mlx4_pci_id_map[] = {
        {
                .vendor_id = PCI_VENDOR_ID_MELLANOX,
                .device_id = PCI_DEVICE_ID_MELLANOX_CONNECTX3,