ethdev: remove assumption that port will not be detached
[dpdk.git] / lib / librte_eal / common / include / rte_pci.h
index 9836446..ac30925 100644 (file)
@@ -117,7 +117,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 +142,13 @@ struct rte_pci_addr {
 
 struct rte_devargs;
 
+enum rte_pt_driver {
+       RTE_PT_UNKNOWN          = 0,
+       RTE_PT_IGB_UIO          = 1,
+       RTE_PT_VFIO             = 2,
+       RTE_PT_UIO_GENERIC      = 3,
+};
+
 /**
  * A structure describing a PCI device.
  */
@@ -155,6 +162,7 @@ struct rte_pci_device {
        uint16_t max_vfs;                       /**< sriov enable if not zero */
        int numa_node;                          /**< NUMA node connection */
        struct rte_devargs *devargs;            /**< Device user arguments */
+       enum rte_pt_driver pt_driver;           /**< Driver of passthrough */
 };
 
 /** Any PCI device identifier (vendor, device, ...) */
@@ -183,6 +191,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,6 +203,7 @@ 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. */
+       pci_devuninit_t *devuninit;             /**< Device uninit function. */
        struct rte_pci_id *id_table;            /**< ID table, NULL terminated. */
        uint32_t drv_flags;                     /**< Flags contolling handling of device. */
 };
@@ -202,6 +216,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)                   \
@@ -262,6 +278,40 @@ eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
 }
 #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(struct rte_pci_addr *addr, 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;
+}
+
 /**
  * Probe the PCI bus for registered drivers.
  *
@@ -275,6 +325,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(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(struct rte_pci_addr *addr);
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+
 /**
  * Dump the content of the PCI bus.
  *