ethdev: add function to release port in secondary process
authorQi Zhang <qi.z.zhang@intel.com>
Tue, 16 Oct 2018 00:16:27 +0000 (08:16 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 17 Oct 2018 08:16:18 +0000 (10:16 +0200)
Add driver API rte_eth_release_port_secondary to support the
case when an ethdev need to be detached on a secondary process.
Local state is set to unused and shared data will not be reset
so the primary process can still use it.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
lib/librte_ethdev/rte_ethdev.c
lib/librte_ethdev/rte_ethdev_driver.h
lib/librte_ethdev/rte_ethdev_pci.h
lib/librte_ethdev/rte_ethdev_version.map

index 21f1dfb..741a864 100644 (file)
@@ -362,6 +362,18 @@ rte_eth_dev_attach_secondary(const char *name)
        return eth_dev;
 }
 
+int
+rte_eth_dev_release_port_secondary(struct rte_eth_dev *eth_dev)
+{
+       if (eth_dev == NULL)
+               return -EINVAL;
+
+       _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_DESTROY, NULL);
+       eth_dev->state = RTE_ETH_DEV_UNUSED;
+
+       return 0;
+}
+
 int
 rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 {
@@ -3578,9 +3590,10 @@ rte_eth_dev_destroy(struct rte_eth_dev *ethdev,
                        return ret;
        }
 
-       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-               rte_free(ethdev->data->dev_private);
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return rte_eth_dev_release_port_secondary(ethdev);
 
+       rte_free(ethdev->data->dev_private);
        ethdev->data->dev_private = NULL;
 
        return rte_eth_dev_release_port(ethdev);
index f158462..ca31b57 100644 (file)
@@ -61,12 +61,26 @@ struct rte_eth_dev *rte_eth_dev_attach_secondary(const char *name);
  * Release the specified ethdev port.
  *
  * @param eth_dev
- * The *eth_dev* pointer is the address of the *rte_eth_dev* structure.
+ * Device to be detached.
  * @return
  *   - 0 on success, negative on error
  */
 int rte_eth_dev_release_port(struct rte_eth_dev *eth_dev);
 
+/**
+ * @internal
+ * Release the specified ethdev port in the local process.
+ * Only set ethdev state to unused, but not reset shared data since
+ * it assume other processes is still using it. typically it is
+ * called by a secondary process.
+ *
+ * @param eth_dev
+ * Device to be detached.
+ * @return
+ *   - 0 on success, negative on error
+ */
+int rte_eth_dev_release_port_secondary(struct rte_eth_dev *eth_dev);
+
 /**
  * @internal
  * Release device queues and clear its configuration to force the user
index f652596..70d2d25 100644 (file)
@@ -135,9 +135,15 @@ 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)
 {
-       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-               rte_free(eth_dev->data->dev_private);
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
+               eth_dev->device = NULL;
+               eth_dev->intr_handle = NULL;
+               rte_eth_dev_release_port_secondary(eth_dev);
+               return;
+       }
 
+       /* primary process */
+       rte_free(eth_dev->data->dev_private);
        eth_dev->data->dev_private = NULL;
 
        /*
index dfa122c..3a4dd47 100644 (file)
@@ -220,6 +220,13 @@ DPDK_18.08 {
 
 } DPDK_18.05;
 
+DPDK_18.11 {
+       global:
+
+       rte_eth_dev_release_port_secondary;
+
+} DPDK_18.08;
+
 EXPERIMENTAL {
        global: