mlx4: avoid init errors when kernel modules are not loaded
[dpdk.git] / lib / librte_pmd_mlx4 / mlx4.c
index c4a65a5..3a45746 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"
 
@@ -4425,6 +4423,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 +4455,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;
        }
@@ -4627,17 +4635,13 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                DEBUG("port %u MTU is %u", priv->port, priv->mtu);
 
                /* from rte_ethdev.c */
-#if RTE_VERSION >= RTE_VERSION_NUM(1, 7, 0, 0)
                {
                        char name[RTE_ETH_NAME_MAX_LEN];
 
                        snprintf(name, sizeof(name), "%s port %u",
                                 ibv_get_device_name(ibv_dev), port);
-                       eth_dev = rte_eth_dev_allocate(name);
+                       eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
                }
-#else
-               eth_dev = rte_eth_dev_allocate();
-#endif
                if (eth_dev == NULL) {
                        ERROR("can not allocate rte ethdev");
                        err = ENOMEM;
@@ -4648,11 +4652,7 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                eth_dev->pci_dev = pci_dev;
                eth_dev->driver = &mlx4_driver;
                eth_dev->data->rx_mbuf_alloc_failed = 0;
-#if RTE_VERSION >= RTE_VERSION_NUM(1, 7, 0, 0)
                eth_dev->data->mtu = ETHER_MTU;
-#else
-               eth_dev->data->max_frame_size = ETHER_MAX_LEN;
-#endif
 
                priv->dev = eth_dev;
                eth_dev->dev_ops = &mlx4_dev_ops;