ethdev: fix port accessing after release
[dpdk.git] / lib / librte_ether / rte_ethdev_pci.h
index fe62589..6565ae7 100644 (file)
 
 #include <rte_malloc.h>
 #include <rte_pci.h>
-#include <rte_ethdev.h>
+#include <rte_bus_pci.h>
+#include <rte_config.h>
+#include <rte_ethdev_driver.h>
+
+/**
+ * Copy pci device info to the Ethernet device data.
+ *
+ * @param eth_dev
+ * The *eth_dev* pointer is the address of the *rte_eth_dev* structure.
+ * @param pci_dev
+ * The *pci_dev* pointer is the address of the *rte_pci_device* structure.
+ */
+static inline void
+rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev,
+       struct rte_pci_device *pci_dev)
+{
+       if ((eth_dev == NULL) || (pci_dev == NULL)) {
+               RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
+                               eth_dev, pci_dev);
+               return;
+       }
+
+       eth_dev->intr_handle = &pci_dev->intr_handle;
+
+       eth_dev->data->dev_flags = 0;
+       if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
+               eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
+       if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_RMV)
+               eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_RMV;
+
+       eth_dev->data->kdrv = pci_dev->kdrv;
+       eth_dev->data->numa_node = pci_dev->device.numa_node;
+}
 
 /**
  * @internal
@@ -84,8 +116,6 @@ rte_eth_dev_pci_allocate(struct rte_pci_device *dev, size_t private_data_size)
        }
 
        eth_dev->device = &dev->device;
-       eth_dev->driver = NULL;
-       eth_dev->intr_handle = &dev->intr_handle;
        rte_eth_copy_pci_info(eth_dev, dev);
        return eth_dev;
 }
@@ -93,17 +123,22 @@ rte_eth_dev_pci_allocate(struct rte_pci_device *dev, size_t private_data_size)
 static inline void
 rte_eth_dev_pci_release(struct rte_eth_dev *eth_dev)
 {
-       /* free ether device */
-       rte_eth_dev_release_port(eth_dev);
-
        if (rte_eal_process_type() == RTE_PROC_PRIMARY)
                rte_free(eth_dev->data->dev_private);
 
        eth_dev->data->dev_private = NULL;
 
+       /*
+        * Secondary process will check the name to attach.
+        * Clear this field to avoid attaching a released ports.
+        */
+       eth_dev->data->name[0] = '\0';
+
        eth_dev->device = NULL;
-       eth_dev->driver = NULL;
        eth_dev->intr_handle = NULL;
+
+       /* free ether device */
+       rte_eth_dev_release_port(eth_dev);
 }
 
 typedef int (*eth_dev_pci_callback_t)(struct rte_eth_dev *eth_dev);