diff mbox

[dpdk-dev,v4,03/11] ethdev: Add rte_eth_dev_free to free specified device

Message ID 1421664027-17971-4-git-send-email-mukawa@igel.co.jp (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Tetsuya Mukawa Jan. 19, 2015, 10:40 a.m. UTC
This patch adds rte_eth_dev_free(). The function is used for changing a
attached status of the device that has specified name.

v4:
- Add paramerter checking.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_ether/rte_ethdev.c | 20 ++++++++++++++++++++
 lib/librte_ether/rte_ethdev.h | 11 +++++++++++
 2 files changed, 31 insertions(+)
diff mbox

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 46cabaf..16f22c0 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -260,6 +260,26 @@  rte_eth_dev_allocate(const char *name)
 	return eth_dev;
 }
 
+struct rte_eth_dev *
+rte_eth_dev_free(const char *name)
+{
+	struct rte_eth_dev *eth_dev;
+
+	if (name == NULL)
+		return NULL;
+
+	eth_dev = rte_eth_dev_allocated(name);
+	if (eth_dev == NULL) {
+		PMD_DEBUG_TRACE("Ethernet Device with name %s doesn't exist!\n",
+				name);
+		return NULL;
+	}
+
+	eth_dev->attached = 0;
+	nb_ports--;
+	return eth_dev;
+}
+
 static int
 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 		 struct rte_pci_device *pci_dev)
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 616a44a..fe64c78 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1653,6 +1653,17 @@  extern uint8_t rte_eth_dev_count(void);
  */
 struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
 
+/**
+ * Function for internal use by dummy drivers primarily, e.g. ring-based
+ * driver.
+ * Free the specified ethdev and returns the pointer to that slot.
+ *
+ * @param	name	Unique identifier name for each Ethernet device
+ * @return
+ *   - Slot in the rte_dev_devices array for the freed device;
+ */
+struct rte_eth_dev *rte_eth_dev_free(const char *name);
+
 struct eth_driver;
 /**
  * @internal