lib: remove extra parenthesis after return
[dpdk.git] / lib / librte_eal / common / include / rte_pci.h
index 9836446..7801fa0 100644 (file)
@@ -74,6 +74,7 @@
 extern "C" {
 #endif
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
 #include <errno.h>
@@ -117,7 +118,7 @@ struct rte_pci_resource {
 };
 
 /** Maximum number of PCI resources. */
-#define PCI_MAX_RESOURCE 7
+#define PCI_MAX_RESOURCE 6
 
 /**
  * A structure describing an ID for a PCI driver. Each driver provides a
@@ -142,6 +143,13 @@ struct rte_pci_addr {
 
 struct rte_devargs;
 
+enum rte_kernel_driver {
+       RTE_KDRV_UNKNOWN = 0,
+       RTE_KDRV_IGB_UIO,
+       RTE_KDRV_VFIO,
+       RTE_KDRV_UIO_GENERIC,
+};
+
 /**
  * A structure describing a PCI device.
  */
@@ -151,10 +159,11 @@ struct rte_pci_device {
        struct rte_pci_id id;                   /**< PCI ID. */
        struct rte_pci_resource mem_resource[PCI_MAX_RESOURCE];   /**< PCI Memory Resource */
        struct rte_intr_handle intr_handle;     /**< Interrupt handle */
-       const struct rte_pci_driver *driver;    /**< Associated driver */
+       struct rte_pci_driver *driver;          /**< Associated driver */
        uint16_t max_vfs;                       /**< sriov enable if not zero */
        int numa_node;                          /**< NUMA node connection */
        struct rte_devargs *devargs;            /**< Device user arguments */
+       enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
 };
 
 /** Any PCI device identifier (vendor, device, ...) */
@@ -183,6 +192,11 @@ struct rte_pci_driver;
  */
 typedef int (pci_devinit_t)(struct rte_pci_driver *, struct rte_pci_device *);
 
+/**
+ * Uninitialisation function for the driver called during hotplugging.
+ */
+typedef int (pci_devuninit_t)(struct rte_pci_device *);
+
 /**
  * A structure describing a PCI driver.
  */
@@ -190,7 +204,8 @@ struct rte_pci_driver {
        TAILQ_ENTRY(rte_pci_driver) next;       /**< Next in list. */
        const char *name;                       /**< Driver name. */
        pci_devinit_t *devinit;                 /**< Device init. function. */
-       struct rte_pci_id *id_table;            /**< ID table, NULL terminated. */
+       pci_devuninit_t *devuninit;             /**< Device uninit function. */
+       const struct rte_pci_id *id_table;      /**< ID table, NULL terminated. */
        uint32_t drv_flags;                     /**< Flags contolling handling of device. */
 };
 
@@ -202,6 +217,8 @@ struct rte_pci_driver {
 #define RTE_PCI_DRV_FORCE_UNBIND 0x0004
 /** Device driver supports link state interrupt */
 #define RTE_PCI_DRV_INTR_LSC   0x0008
+/** Device driver supports detaching capability */
+#define RTE_PCI_DRV_DETACHABLE 0x0010
 
 /**< Internal use only - Macro used by pci addr parsing functions **/
 #define GET_PCIADDR_FIELD(in, fd, lim, dlm)                   \
@@ -211,7 +228,7 @@ do {                                                               \
        errno = 0;                                              \
        val = strtoul((in), &end, 16);                          \
        if (errno != 0 || end[0] != (dlm) || val > (lim))       \
-               return (-EINVAL);                               \
+               return -EINVAL;                                 \
        (fd) = (typeof (fd))val;                                \
        (in) = end + 1;                                         \
 } while(0)
@@ -222,10 +239,10 @@ do {                                                               \
  * a domain prefix (i.e. domain returned is always 0)
  *
  * @param input
- *     The input string to be parsed. Should have the format XX:XX.X
+ *     The input string to be parsed. Should have the format XX:XX.X
  * @param dev_addr
- *     The PCI Bus-Device-Function address to be returned. Domain will always be
- *     returned as 0
+ *     The PCI Bus-Device-Function address to be returned. Domain will always be
+ *     returned as 0
  * @return
  *  0 on success, negative on error.
  */
@@ -236,7 +253,7 @@ eal_parse_pci_BDF(const char *input, struct rte_pci_addr *dev_addr)
        GET_PCIADDR_FIELD(input, dev_addr->bus, UINT8_MAX, ':');
        GET_PCIADDR_FIELD(input, dev_addr->devid, UINT8_MAX, '.');
        GET_PCIADDR_FIELD(input, dev_addr->function, UINT8_MAX, 0);
-       return (0);
+       return 0;
 }
 
 /**
@@ -245,9 +262,9 @@ eal_parse_pci_BDF(const char *input, struct rte_pci_addr *dev_addr)
  * a domain prefix.
  *
  * @param input
- *     The input string to be parsed. Should have the format XXXX:XX:XX.X
+ *     The input string to be parsed. Should have the format XXXX:XX:XX.X
  * @param dev_addr
- *     The PCI Bus-Device-Function address to be returned
+ *     The PCI Bus-Device-Function address to be returned
  * @return
  *  0 on success, negative on error.
  */
@@ -258,10 +275,54 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
        GET_PCIADDR_FIELD(input, dev_addr->bus, UINT8_MAX, ':');
        GET_PCIADDR_FIELD(input, dev_addr->devid, UINT8_MAX, '.');
        GET_PCIADDR_FIELD(input, dev_addr->function, UINT8_MAX, 0);
-       return (0);
+       return 0;
 }
 #undef GET_PCIADDR_FIELD
 
+/* Compare two PCI device addresses. */
+/**
+ * Utility function to compare two PCI device addresses.
+ *
+ * @param addr
+ *     The PCI Bus-Device-Function address to compare
+ * @param addr2
+ *     The PCI Bus-Device-Function address to compare
+ * @return
+ *     0 on equal PCI address.
+ *     Positive on addr is greater than addr2.
+ *     Negative on addr is less than addr2, or error.
+ */
+static inline int
+rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
+                        const struct rte_pci_addr *addr2)
+{
+       uint64_t dev_addr, dev_addr2;
+
+       if ((addr == NULL) || (addr2 == NULL))
+               return -1;
+
+       dev_addr = (addr->domain << 24) | (addr->bus << 16) |
+                               (addr->devid << 8) | addr->function;
+       dev_addr2 = (addr2->domain << 24) | (addr2->bus << 16) |
+                               (addr2->devid << 8) | addr2->function;
+
+       if (dev_addr > dev_addr2)
+               return 1;
+       else if (dev_addr < dev_addr2)
+               return -1;
+       else
+               return 0;
+}
+
+/**
+ * Scan the content of the PCI bus, and the devices in the devices
+ * list
+ *
+ * @return
+ *  0 on success, negative on error
+ */
+int rte_eal_pci_scan(void);
+
 /**
  * Probe the PCI bus for registered drivers.
  *
@@ -275,6 +336,38 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
  */
 int rte_eal_pci_probe(void);
 
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+/**
+ * Probe the single PCI device.
+ *
+ * Scan the content of the PCI bus, and find the pci device specified by pci
+ * address, then call the probe() function for registered driver that has a
+ * matching entry in its id_table for discovered device.
+ *
+ * @param addr
+ *     The PCI Bus-Device-Function address to probe.
+ * @return
+ *   - 0 on success.
+ *   - Negative on error.
+ */
+int rte_eal_pci_probe_one(const struct rte_pci_addr *addr);
+
+/**
+ * Close the single PCI device.
+ *
+ * Scan the content of the PCI bus, and find the pci device specified by pci
+ * address, then call the close() function for registered driver that has a
+ * matching entry in its id_table for discovered device.
+ *
+ * @param addr
+ *     The PCI Bus-Device-Function address to close.
+ * @return
+ *   - 0 on success.
+ *   - Negative on error.
+ */
+int rte_eal_pci_close_one(const struct rte_pci_addr *addr);
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
 /**
  * Dump the content of the PCI bus.
  *