[dpdk-dev] [RFC PATCH v2 06/28] ethdev: Add rte_eth_dev_shutdown for closing PCI devices.

Tetsuya Mukawa mukawa at igel.co.jp
Tue Nov 4 04:45:26 CET 2014


rte_eth_dev_shutdown() is called when PCI device is closed.

Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp>
---
 lib/librte_ether/rte_ethdev.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index efd631b..b623e31 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -319,6 +319,42 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 	return diag;
 }
 
+static int
+rte_eth_dev_shutdown(struct rte_pci_driver *pci_drv,
+		 struct rte_pci_device *pci_dev)
+{
+	struct eth_driver *eth_drv;
+	struct rte_eth_dev *eth_dev;
+	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
+
+	/* Create unique Ethernet device name using PCI address */
+	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "%d:%d.%d",
+			pci_dev->addr.bus, pci_dev->addr.devid,
+			pci_dev->addr.function);
+
+	eth_dev = rte_eth_dev_free(ethdev_name);
+	if (eth_dev == NULL)
+		return -ENODEV;
+
+	eth_drv = (struct eth_driver *)pci_drv;
+
+	/* Invoke PMD device shutdown function */
+	if (*eth_drv->eth_dev_shutdown)
+		(*eth_drv->eth_dev_shutdown)(eth_drv, eth_dev);
+
+	/* init user callbacks */
+	TAILQ_INIT(&(eth_dev->callbacks));
+
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+		rte_free(eth_dev->data->dev_private);
+
+	eth_dev->pci_dev = NULL;
+	eth_dev->driver = NULL;
+	eth_dev->data = NULL;
+
+	return 0;
+}
+
 /**
  * Register an Ethernet [Poll Mode] driver.
  *
@@ -337,6 +373,7 @@ void
 rte_eth_driver_register(struct eth_driver *eth_drv)
 {
 	eth_drv->pci_drv.devinit = rte_eth_dev_init;
+	eth_drv->pci_drv.devshutdown = rte_eth_dev_shutdown;
 	rte_eal_pci_register(&eth_drv->pci_drv);
 }
 
-- 
1.9.1



More information about the dev mailing list