eal: support link bonding device initialization
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal.c
index d7a59de..573fd06 100644 (file)
@@ -1,14 +1,14 @@
 /*-
  *   BSD LICENSE
- * 
+ *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   Copyright(c) 2012-2014 6WIND S.A.
  *   All rights reserved.
- * 
+ *
  *   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
@@ -18,7 +18,7 @@
  *     * Neither the name of Intel Corporation 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
@@ -75,6 +75,7 @@
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 #include <rte_eth_ring.h>
+#include <rte_dev.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
 #define OPT_BASE_VIRTADDR   "base-virtaddr"
 #define OPT_XEN_DOM0    "xen-dom0"
 #define OPT_CREATE_UIO_DEV "create-uio-dev"
+#define OPT_VFIO_INTR    "vfio-intr"
 
 #define RTE_EAL_BLACKLIST_SIZE 0x100
 
@@ -256,7 +258,7 @@ rte_eal_config_attach(void)
                        rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
        }
 
-       rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config), 
+       rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
                                PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
        close(mem_cfg_fd);
        if (rte_mem_cfg_addr == MAP_FAILED)
@@ -358,9 +360,10 @@ eal_usage(const char *prgname)
               "  --"OPT_VDEV": add a virtual device.\n"
               "               The argument format is <driver><id>[,key=val,...]\n"
               "               (ex: --vdev=eth_pcap0,iface=eth2).\n"
-              "  --"OPT_VMWARE_TSC_MAP": use VMware TSC map instead of "
-                          "native RDTSC\n"
+              "  --"OPT_VMWARE_TSC_MAP": use VMware TSC map instead of native RDTSC\n"
               "  --"OPT_BASE_VIRTADDR": specify base virtual address\n"
+              "  --"OPT_VFIO_INTR": specify desired interrupt mode for VFIO "
+                          "(legacy|msi|msix)\n"
               "  --"OPT_CREATE_UIO_DEV": create /dev/uioX (usually done by hotplug)\n"
               "\nEAL options for DEBUG use only:\n"
               "  --"OPT_NO_HUGE"  : use malloc instead of hugetlbfs\n"
@@ -397,11 +400,11 @@ rte_set_application_usage_hook( rte_usage_hook_t usage_func )
 static int xdigit2val(unsigned char c)
 {
        int val;
-       if(isdigit(c)) 
+       if(isdigit(c))
                val = c - '0';
        else if(isupper(c))
                val = c - 'A' + 10;
-       else 
+       else
                val = c - 'a' + 10;
        return val;
 }
@@ -560,6 +563,7 @@ eal_parse_base_virtaddr(const char *arg)
        char *end;
        uint64_t addr;
 
+       errno = 0;
        addr = strtoull(arg, &end, 16);
 
        /* check for errors */
@@ -579,6 +583,28 @@ eal_parse_base_virtaddr(const char *arg)
        return 0;
 }
 
+static int
+eal_parse_vfio_intr(const char *mode)
+{
+       unsigned i;
+       static struct {
+               const char *name;
+               enum rte_intr_mode value;
+       } map[] = {
+               { "legacy", RTE_INTR_MODE_LEGACY },
+               { "msi", RTE_INTR_MODE_MSI },
+               { "msix", RTE_INTR_MODE_MSIX },
+       };
+
+       for (i = 0; i < RTE_DIM(map); i++) {
+               if (!strcmp(mode, map[i].name)) {
+                       internal_config.vfio_intr_mode = map[i].value;
+                       return 0;
+               }
+       }
+       return -1;
+}
+
 static inline size_t
 eal_get_hugepage_mem_size(void)
 {
@@ -633,6 +659,7 @@ eal_parse_args(int argc, char **argv)
                {OPT_PCI_BLACKLIST, 1, 0, 0},
                {OPT_VDEV, 1, 0, 0},
                {OPT_SYSLOG, 1, NULL, 0},
+               {OPT_VFIO_INTR, 1, NULL, 0},
                {OPT_BASE_VIRTADDR, 1, 0, 0},
                {OPT_XEN_DOM0, 0, 0, 0},
                {OPT_CREATE_UIO_DEV, 1, NULL, 0},
@@ -650,6 +677,8 @@ eal_parse_args(int argc, char **argv)
        internal_config.force_sockets = 0;
        internal_config.syslog_facility = LOG_DAEMON;
        internal_config.xen_dom0_support = 0;
+       /* if set to NONE, interrupt mode is determined automatically */
+       internal_config.vfio_intr_mode = RTE_INTR_MODE_NONE;
 #ifdef RTE_LIBEAL_USE_HPET
        internal_config.no_hpet = 0;
 #else
@@ -753,7 +782,7 @@ eal_parse_args(int argc, char **argv)
                                        "running on Dom0, please configure"
                                        " RTE_LIBRTE_XEN_DOM0=y\n");
                                return -1;
-               #endif 
+               #endif
                        }
                        else if (!strcmp(lgopts[option_index].name, OPT_NO_PCI)) {
                                internal_config.no_pci = 1;
@@ -827,6 +856,14 @@ eal_parse_args(int argc, char **argv)
                                        return -1;
                                }
                        }
+                       else if (!strcmp(lgopts[option_index].name, OPT_VFIO_INTR)) {
+                               if (eal_parse_vfio_intr(optarg) < 0) {
+                                       RTE_LOG(ERR, EAL, "invalid parameters for --"
+                                                       OPT_VFIO_INTR "\n");
+                                       eal_usage(prgname);
+                                       return -1;
+                               }
+                       }
                        else if (!strcmp(lgopts[option_index].name, OPT_CREATE_UIO_DEV)) {
                                internal_config.create_uio_dev = 1;
                        }
@@ -932,7 +969,7 @@ sync_func(__attribute__((unused)) void *arg)
        return 0;
 }
 
-inline static void 
+inline static void
 rte_eal_mcfg_complete(void)
 {
        /* ALL shared mem_config related INIT DONE */
@@ -941,7 +978,7 @@ rte_eal_mcfg_complete(void)
 }
 
 /*
- * Request iopl priviledge for all RPL, returns 0 on success
+ * Request iopl privilege for all RPL, returns 0 on success
  */
 static int
 rte_eal_iopl_init(void)
@@ -1007,7 +1044,7 @@ rte_eal_init(int argc, char **argv)
 
        if (rte_eal_iopl_init() == 0)
                rte_config.flags |= EAL_FLG_HIGH_IOPL;
-       
+
        if (rte_eal_pci_init() < 0)
                rte_panic("Cannot init PCI\n");
 
@@ -1021,7 +1058,7 @@ rte_eal_init(int argc, char **argv)
 
        /* the directories are locked during eal_hugepage_info_init */
        eal_hugedirs_unlock();
-       
+
        if (rte_eal_memzone_init() < 0)
                rte_panic("Cannot init memzone\n");
 
@@ -1061,8 +1098,8 @@ rte_eal_init(int argc, char **argv)
        RTE_LOG(DEBUG, EAL, "Master core %u is ready (tid=%x)\n",
                rte_config.master_lcore, (int)thread_id);
 
-       if (rte_eal_vdev_init() < 0)
-               rte_panic("Cannot init virtual devices\n");
+       if (rte_eal_dev_init(PMD_INIT_PRE_PCI_PROBE) < 0)
+               rte_panic("Cannot init pmd devices\n");
 
        RTE_LCORE_FOREACH_SLAVE(i) {
 
@@ -1091,6 +1128,14 @@ rte_eal_init(int argc, char **argv)
        rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
        rte_eal_mp_wait_lcore();
 
+       /* Probe & Initialize PCI devices */
+       if (rte_eal_pci_probe())
+                       rte_panic("Cannot probe PCI\n");
+
+       /* Initialize any outstanding devices */
+       if (rte_eal_dev_init(PMD_INIT_POST_PCI_PROBE) < 0)
+               rte_panic("Cannot init pmd devices\n");
+
        return fctret;
 }