public inbox for dev@dpdk.org
 help / color / mirror / Atom feed
From: Ciara Loftus <ciara.loftus@intel.com>
To: dev@dpdk.org
Cc: Ciara Loftus <ciara.loftus@intel.com>
Subject: [PATCH v3] net/iavf: support pre and post reset callbacks
Date: Wed, 21 Jan 2026 12:42:50 +0000	[thread overview]
Message-ID: <20260121124250.1999260-1-ciara.loftus@intel.com> (raw)
In-Reply-To: <20260114132159.644359-1-ciara.loftus@intel.com>

The user may want to perform some actions before and/or after a VF
reset, for example storing settings that may be lost during the reset
and restoring them after the reset. To facilitate this, introduce two
new functions which allow the user to register either a pre or post
reset callback, which will be executed before or after the VF has been
reset. To unregister the callback, simply use the register functions
with a NULL callback and argument.

Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
---
v3:
* Fix build issue by removing iavf.h include in rte_pmd_iavf.h
---
 doc/guides/rel_notes/release_26_03.rst |  4 ++
 drivers/net/intel/iavf/iavf.h          |  5 ++
 drivers/net/intel/iavf/iavf_ethdev.c   | 80 ++++++++++++++++++++++++++
 drivers/net/intel/iavf/rte_pmd_iavf.h  | 45 +++++++++++++++
 4 files changed, 134 insertions(+)

diff --git a/doc/guides/rel_notes/release_26_03.rst b/doc/guides/rel_notes/release_26_03.rst
index a50f6ee231..09d9cc3813 100644
--- a/doc/guides/rel_notes/release_26_03.rst
+++ b/doc/guides/rel_notes/release_26_03.rst
@@ -55,6 +55,10 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Updated Intel iavf driver.**
+
+  * Added support for pre and post VF reset callbacks.
+
 
 Removed Items
 -------------
diff --git a/drivers/net/intel/iavf/iavf.h b/drivers/net/intel/iavf/iavf.h
index cbd7f036f3..39949acc11 100644
--- a/drivers/net/intel/iavf/iavf.h
+++ b/drivers/net/intel/iavf/iavf.h
@@ -15,6 +15,7 @@
 #include <iavf_type.h>
 
 #include "iavf_log.h"
+#include "rte_pmd_iavf.h"
 
 #define IAVF_AQ_LEN               32
 #define IAVF_AQ_BUF_SZ            4096
@@ -257,6 +258,10 @@ struct iavf_info {
 
 	struct iavf_vsi vsi;
 	bool vf_reset;	/* true for VF reset pending, false for no VF reset */
+	iavf_pre_reset_cb_t pre_reset_cb; /* Pre reset callback function ptr */
+	iavf_post_reset_cb_t post_reset_cb; /* Post reset callback function ptr */
+	void *pre_reset_cb_arg; /* Pre reset callback argument */
+	void *post_reset_cb_arg; /* Post reset callback argument */
 	uint64_t flags;
 
 	uint8_t *rss_lut;
diff --git a/drivers/net/intel/iavf/iavf_ethdev.c b/drivers/net/intel/iavf/iavf_ethdev.c
index ad48386343..802e095174 100644
--- a/drivers/net/intel/iavf/iavf_ethdev.c
+++ b/drivers/net/intel/iavf/iavf_ethdev.c
@@ -3132,6 +3132,10 @@ iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset)
 	vf->in_reset_recovery = true;
 	iavf_set_no_poll(adapter, false);
 
+	/* Call the pre reset callback */
+	if (vf->pre_reset_cb != NULL)
+		vf->pre_reset_cb(dev->data->port_id, vf->pre_reset_cb_arg);
+
 	ret = iavf_dev_reset(dev);
 	if (ret)
 		goto error;
@@ -3156,6 +3160,10 @@ iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset)
 error:
 	PMD_DRV_LOG(DEBUG, "RESET recover with error code=%dn", ret);
 exit:
+	/* Call the post reset callback */
+	if (vf->post_reset_cb != NULL)
+		vf->post_reset_cb(dev->data->port_id, ret, vf->post_reset_cb_arg);
+
 	vf->in_reset_recovery = false;
 	iavf_set_no_poll(adapter, false);
 
@@ -3195,6 +3203,78 @@ rte_pmd_iavf_reinit(uint16_t port)
 	return 0;
 }
 
+static int
+iavf_validate_reset_cb(uint16_t port, void *cb, void *cb_arg)
+{
+	struct rte_eth_dev *dev;
+	struct iavf_info *vf;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	if (cb == NULL && cb_arg != NULL) {
+		PMD_DRV_LOG(ERR, "Cannot unregister reset cb on port %u, arg must be NULL.", port);
+		return -EINVAL;
+	}
+
+	dev = &rte_eth_devices[port];
+	if (!is_iavf_supported(dev)) {
+		PMD_DRV_LOG(ERR, "Cannot modify reset cb, port %u not an IAVF device.", port);
+		return -ENOTSUP;
+	}
+
+	vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+	if (vf->in_reset_recovery) {
+		PMD_DRV_LOG(ERR, "Cannot modify reset cb on port %u, VF is resetting.", port);
+		return -EBUSY;
+	}
+
+	return 0;
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_iavf_register_pre_reset_cb, 26.03)
+int
+rte_pmd_iavf_register_pre_reset_cb(uint16_t port,
+				   iavf_pre_reset_cb_t pre_reset_cb,
+				   void *pre_reset_cb_arg)
+{
+	struct rte_eth_dev *dev;
+	struct iavf_info *vf;
+	int ret;
+
+	ret = iavf_validate_reset_cb(port, pre_reset_cb, pre_reset_cb_arg);
+	if (ret)
+		return ret;
+
+	dev = &rte_eth_devices[port];
+	vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+	vf->pre_reset_cb = pre_reset_cb;
+	vf->pre_reset_cb_arg = pre_reset_cb_arg;
+
+	return 0;
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_iavf_register_post_reset_cb, 26.03)
+int
+rte_pmd_iavf_register_post_reset_cb(uint16_t port,
+				    iavf_post_reset_cb_t post_reset_cb,
+				    void *post_reset_cb_arg)
+{
+	struct rte_eth_dev *dev;
+	struct iavf_info *vf;
+	int ret;
+
+	ret = iavf_validate_reset_cb(port, post_reset_cb, post_reset_cb_arg);
+	if (ret)
+		return ret;
+
+	dev = &rte_eth_devices[port];
+	vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+	vf->post_reset_cb = post_reset_cb;
+	vf->post_reset_cb_arg = post_reset_cb_arg;
+
+	return 0;
+}
+
 void
 iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change)
 {
diff --git a/drivers/net/intel/iavf/rte_pmd_iavf.h b/drivers/net/intel/iavf/rte_pmd_iavf.h
index dea1bd2789..df4e947e85 100644
--- a/drivers/net/intel/iavf/rte_pmd_iavf.h
+++ b/drivers/net/intel/iavf/rte_pmd_iavf.h
@@ -24,6 +24,11 @@
 extern "C" {
 #endif
 
+/** Callback function pointer for pre VF reset event */
+typedef void (*iavf_pre_reset_cb_t)(uint16_t port_id, void *arg);
+/** Callback function pointer for post VF reset event */
+typedef void (*iavf_post_reset_cb_t)(uint16_t port_id, int reset_state, void *arg);
+
 /**
  * The supported network flexible descriptor's extraction metadata format.
  */
@@ -109,6 +114,46 @@ extern uint64_t rte_pmd_ifd_dynflag_proto_xtr_ipsec_crypto_said_mask;
 __rte_experimental
 int rte_pmd_iavf_reinit(uint16_t port);
 
+/**
+ * Register or unregister a pre reset event callback
+ *
+ * @param port
+ *   The port identifier of the Ethernet device.
+ * @param pre_reset_cb
+ *   The callback function that will be invoked by the driver prior to a reset.
+ *   Pass NULL to unregister an existing callback.
+ * @param pre_reset_cb_arg
+ *   The argument passed to the callback function.
+ *   May be NULL when registering the callback if no argument is needed to the callback.
+ *   Must be NULL when unregistering the callback.
+ * @return
+ *   0 if successful, otherwise if a failure occurs.
+ */
+__rte_experimental
+int rte_pmd_iavf_register_pre_reset_cb(uint16_t port,
+					iavf_pre_reset_cb_t pre_reset_cb,
+					void *pre_reset_cb_arg);
+
+/**
+ * Register or unregister a post reset event callback
+ *
+ * @param port
+ *   The port identifier of the Ethernet device.
+ * @param post_reset_cb
+ *   The callback function that will be invoked by the driver after a reset.
+ *   Pass NULL to unregister an existing callback.
+ * @param post_reset_cb_arg
+ *   The argument passed to the callback function.
+ *   May be NULL when registering the callback if no argument is needed to the callback.
+ *   Must be NULL when unregistering the callback.
+ * @return
+ *   0 if successful, otherwise if a failure occurs.
+ */
+__rte_experimental
+int rte_pmd_iavf_register_post_reset_cb(uint16_t port,
+					iavf_post_reset_cb_t post_reset_cb,
+					void *post_reset_cb_arg);
+
 /**
  * The mbuf dynamic field pointer for flexible descriptor's extraction metadata.
  */
-- 
2.43.0


  parent reply	other threads:[~2026-01-21 12:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-13 15:17 [PATCH] net/iavf: support pre and post reset callbacks Ciara Loftus
2026-01-13 15:51 ` Bruce Richardson
2026-01-14 13:21 ` [PATCH v2] " Ciara Loftus
2026-01-20 18:01   ` Bruce Richardson
2026-01-21  9:29     ` David Marchand
2026-01-21 19:39       ` Aaron Conole
2026-01-21 12:42   ` Ciara Loftus [this message]
2026-01-23 11:53     ` [PATCH v3] " Bruce Richardson

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=20260121124250.1999260-1-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