DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ciara Loftus <ciara.loftus@intel.com>
To: dev@dpdk.org
Cc: Ciara Loftus <ciara.loftus@intel.com>
Subject: [RFC 1/3] ethdev: introduce device reinitialisation API
Date: Fri, 17 Oct 2025 11:11:07 +0000	[thread overview]
Message-ID: <20251017111109.1734792-2-ciara.loftus@intel.com> (raw)
In-Reply-To: <20251017111109.1734792-1-ciara.loftus@intel.com>

Add a new ethdev API for resetting a device followed by a restoration of
the configuration present at the time of the invocation of the API.
In some cases if the driver can support it, the device will be restarted
if it was started when the API was invoked.

This operation could be useful for example when the user has detected an
issue with the device and wants to reset and reinitialise it in an
attempt to get it working again. While this is possible by calling a
sequence of existing APIs (reset, configure, rx_queue_setup and
tx_queue_setup), in the case where we are restoring the exact same
configuration, much of the reconfiguration performed in those calls
would be unnecessary and can be achieved by calling a subset of that
functionality, which is what this API will perform.

Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
---
 lib/ethdev/ethdev_driver.h       |  4 ++++
 lib/ethdev/ethdev_trace.h        |  7 +++++++
 lib/ethdev/ethdev_trace_points.c |  3 +++
 lib/ethdev/rte_ethdev.c          | 32 ++++++++++++++++++++++++++++++++
 lib/ethdev/rte_ethdev.h          | 25 +++++++++++++++++++++++++
 5 files changed, 71 insertions(+)

diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h
index 71085bddff..18fff9f1a1 100644
--- a/lib/ethdev/ethdev_driver.h
+++ b/lib/ethdev/ethdev_driver.h
@@ -229,6 +229,9 @@ typedef int (*eth_dev_close_t)(struct rte_eth_dev *dev);
 /** @internal Function used to reset a configured Ethernet device. */
 typedef int (*eth_dev_reset_t)(struct rte_eth_dev *dev);
 
+/** @internal Function used to reinitialise a configured Ethernet device. */
+typedef int (*eth_dev_reinit_t)(struct rte_eth_dev *dev);
+
 /** @internal Function used to detect an Ethernet device removal. */
 typedef int (*eth_is_removed_t)(struct rte_eth_dev *dev);
 
@@ -1387,6 +1390,7 @@ struct eth_dev_ops {
 	eth_dev_set_link_down_t    dev_set_link_down; /**< Device link down */
 	eth_dev_close_t            dev_close;     /**< Close device */
 	eth_dev_reset_t		   dev_reset;	  /**< Reset device */
+	eth_dev_reinit_t	   dev_reinit;	  /**< Reinitialize device */
 	eth_link_update_t          link_update;   /**< Get device link state */
 	eth_speed_lanes_get_t	   speed_lanes_get;	  /**< Get link speed active lanes */
 	eth_speed_lanes_set_t      speed_lanes_set;	  /**< Set link speeds supported lanes */
diff --git a/lib/ethdev/ethdev_trace.h b/lib/ethdev/ethdev_trace.h
index 482befc209..a1eb5a4438 100644
--- a/lib/ethdev/ethdev_trace.h
+++ b/lib/ethdev/ethdev_trace.h
@@ -231,6 +231,13 @@ RTE_TRACE_POINT(
 	rte_trace_point_emit_int(ret);
 )
 
+RTE_TRACE_POINT(
+	rte_ethdev_trace_reinit,
+	RTE_TRACE_POINT_ARGS(uint16_t port_id, int ret),
+	rte_trace_point_emit_u16(port_id);
+	rte_trace_point_emit_int(ret);
+)
+
 RTE_TRACE_POINT(
 	rte_eth_trace_rx_hairpin_queue_setup,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id, uint16_t rx_queue_id,
diff --git a/lib/ethdev/ethdev_trace_points.c b/lib/ethdev/ethdev_trace_points.c
index 071c508327..57713d6e70 100644
--- a/lib/ethdev/ethdev_trace_points.c
+++ b/lib/ethdev/ethdev_trace_points.c
@@ -143,6 +143,9 @@ RTE_TRACE_POINT_REGISTER(rte_ethdev_trace_set_link_down,
 RTE_TRACE_POINT_REGISTER(rte_ethdev_trace_reset,
 	lib.ethdev.reset)
 
+RTE_TRACE_POINT_REGISTER(rte_ethdev_trace_reinit,
+	lib.ethdev.reinit)
+
 RTE_TRACE_POINT_REGISTER(rte_ethdev_trace_is_removed,
 	lib.ethdev.is_removed)
 
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index f22139cb38..67d69fef34 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -2057,6 +2057,38 @@ rte_eth_dev_reset(uint16_t port_id)
 	return ret;
 }
 
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_reinit, 25.11)
+int
+rte_eth_dev_reinit(uint16_t port_id)
+{
+	struct rte_eth_dev *dev;
+	int ret;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if (dev->dev_ops->dev_reinit == NULL)
+		return -ENOTSUP;
+
+	if (dev->data->dev_configured == 0) {
+		RTE_ETHDEV_LOG_LINE(INFO,
+			"Cannot reinit device (port %u), device not configured",
+			port_id);
+		return -EINVAL;
+	}
+
+	ret = eth_err(port_id, dev->dev_ops->dev_reinit(dev));
+
+	if (ret == -EBUSY)
+		RTE_ETHDEV_LOG_LINE(INFO,
+			"Cannot reinit started device (port %u), please stop it first",
+			port_id);
+
+	rte_ethdev_trace_reinit(port_id, ret);
+
+	return ret;
+}
+
 RTE_EXPORT_SYMBOL(rte_eth_dev_is_removed)
 int
 rte_eth_dev_is_removed(uint16_t port_id)
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index d23c143eed..accc559af3 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -2989,6 +2989,31 @@ int rte_eth_dev_close(uint16_t port_id);
  */
 int rte_eth_dev_reset(uint16_t port_id);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Reinitialise an Ethernet device and restore its configuration.
+ *
+ * When a device needs to be reset passively and the current configuration
+ * needs to be restored following the reset, the DPDK application can
+ * invoke this function. Some devices may also restart the device after
+ * the reinit if it was started before, if the device can do this safely.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ *
+ * @return
+ *   - (0) if successful.
+ *   - (-ENODEV) if *port_id* is invalid.
+ *   - (-ENOTSUP) if hardware doesn't support this function.
+ *   - (-EBUSY) if the device is started and the driver needs it to be
+ *   stopped before performing the reinit.
+ *   - (<0): Error code of the driver reinitialisation function.
+ */
+__rte_experimental
+int rte_eth_dev_reinit(uint16_t port_id);
+
 /**
  * Enable receipt in promiscuous mode for an Ethernet device.
  *
-- 
2.34.1


  reply	other threads:[~2025-10-17 11:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-17 11:11 [RFC 0/3] " Ciara Loftus
2025-10-17 11:11 ` Ciara Loftus [this message]
2025-10-17 11:11 ` [RFC 2/3] net/iavf: implement device reinitialisation callback Ciara Loftus
2025-10-17 11:11 ` [RFC 3/3] app/testpmd: support port reinitialisation Ciara Loftus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251017111109.1734792-2-ciara.loftus@intel.com \
    --to=ciara.loftus@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).