[v13,6/7] net/iavf: add watchdog for VFLR

Message ID 20211028160500.2775783-7-radu.nicolau@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Qi Zhang
Headers
Series [v13,1/7] common/iavf: add iAVF IPsec inline crypto support |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Radu Nicolau Oct. 28, 2021, 4:04 p.m. UTC
  Add watchdog to iAVF PMD which support monitoring the VFLR register. If
the device is not already in reset then if a VF reset in progress is
detected then notfiy user through callback and set into reset state.
If the device is already in reset then poll for completion of reset.

The watchdog is disabled by default, to enable it set
IAVF_DEV_WATCHDOG_PERIOD to a non zero value (microseconds)

Signed-off-by: Declan Doherty <declan.doherty@intel.com>
Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
Acked-by: Jingjing Wu <jingjing.wu@intel.com>
---
 drivers/net/iavf/iavf.h        |  5 ++
 drivers/net/iavf/iavf_ethdev.c | 94 ++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+)
  

Comments

Ferruh Yigit Nov. 5, 2021, 11:54 a.m. UTC | #1
On 10/28/2021 5:04 PM, Radu Nicolau wrote:
> diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
> index 783a10060c..ae0f8f17f4 100644
> --- a/drivers/net/iavf/iavf_ethdev.c
> +++ b/drivers/net/iavf/iavf_ethdev.c
> @@ -25,6 +25,7 @@
>   #include <rte_malloc.h>
>   #include <rte_memzone.h>
>   #include <rte_dev.h>
> +#include <rte_alarm.h>

Duplicated include, 'rte_alarm.h' is already included above.

Reported by Thomas, and will be fixed in main, thanks.
  

Patch

diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h
index 53c99d0f0e..614cf7d070 100644
--- a/drivers/net/iavf/iavf.h
+++ b/drivers/net/iavf/iavf.h
@@ -31,6 +31,8 @@ 
 
 #define IAVF_NUM_MACADDR_MAX      64
 
+#define IAVF_DEV_WATCHDOG_PERIOD     0
+
 #define IAVF_DEFAULT_RX_PTHRESH      8
 #define IAVF_DEFAULT_RX_HTHRESH      8
 #define IAVF_DEFAULT_RX_WTHRESH      0
@@ -216,6 +218,9 @@  struct iavf_info {
 	int cmd_retval; /* return value of the cmd response from PF */
 	uint8_t *aq_resp; /* buffer to store the adminq response from PF */
 
+	/** iAVF watchdog enable */
+	bool watchdog_enabled;
+
 	/* Event from pf */
 	bool dev_closed;
 	bool link_up;
diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
index 783a10060c..ae0f8f17f4 100644
--- a/drivers/net/iavf/iavf_ethdev.c
+++ b/drivers/net/iavf/iavf_ethdev.c
@@ -25,6 +25,7 @@ 
 #include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <rte_dev.h>
+#include <rte_alarm.h>
 
 #include "iavf.h"
 #include "iavf_rxtx.h"
@@ -240,6 +241,91 @@  iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused,
 	return 0;
 }
 
+__rte_unused
+static int
+iavf_vfr_inprogress(struct iavf_hw *hw)
+{
+	int inprogress = 0;
+
+	if ((IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
+		IAVF_VFGEN_RSTAT_VFR_STATE_MASK) ==
+		VIRTCHNL_VFR_INPROGRESS)
+		inprogress = 1;
+
+	if (inprogress)
+		PMD_DRV_LOG(INFO, "Watchdog detected VFR in progress");
+
+	return inprogress;
+}
+
+__rte_unused
+static void
+iavf_dev_watchdog(void *cb_arg)
+{
+	struct iavf_adapter *adapter = cb_arg;
+	struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
+	int vfr_inprogress = 0, rc = 0;
+
+	/* check if watchdog has been disabled since last call */
+	if (!adapter->vf.watchdog_enabled)
+		return;
+
+	/* If in reset then poll vfr_inprogress register for completion */
+	if (adapter->vf.vf_reset) {
+		vfr_inprogress = iavf_vfr_inprogress(hw);
+
+		if (!vfr_inprogress) {
+			PMD_DRV_LOG(INFO, "VF \"%s\" reset has completed",
+				adapter->vf.eth_dev->data->name);
+			adapter->vf.vf_reset = false;
+		}
+	/* If not in reset then poll vfr_inprogress register for VFLR event */
+	} else {
+		vfr_inprogress = iavf_vfr_inprogress(hw);
+
+		if (vfr_inprogress) {
+			PMD_DRV_LOG(INFO,
+				"VF \"%s\" reset event detected by watchdog",
+				adapter->vf.eth_dev->data->name);
+
+			/* enter reset state with VFLR event */
+			adapter->vf.vf_reset = true;
+
+			rte_eth_dev_callback_process(adapter->vf.eth_dev,
+				RTE_ETH_EVENT_INTR_RESET, NULL);
+		}
+	}
+
+	/* re-alarm watchdog */
+	rc = rte_eal_alarm_set(IAVF_DEV_WATCHDOG_PERIOD,
+			&iavf_dev_watchdog, cb_arg);
+
+	if (rc)
+		PMD_DRV_LOG(ERR, "Failed \"%s\" to reset device watchdog alarm",
+			adapter->vf.eth_dev->data->name);
+}
+
+static void
+iavf_dev_watchdog_enable(struct iavf_adapter *adapter __rte_unused)
+{
+#if (IAVF_DEV_WATCHDOG_PERIOD > 0)
+	PMD_DRV_LOG(INFO, "Enabling device watchdog");
+	adapter->vf.watchdog_enabled = true;
+	if (rte_eal_alarm_set(IAVF_DEV_WATCHDOG_PERIOD,
+			&iavf_dev_watchdog, (void *)adapter))
+		PMD_DRV_LOG(ERR, "Failed to enabled device watchdog");
+#endif
+}
+
+static void
+iavf_dev_watchdog_disable(struct iavf_adapter *adapter __rte_unused)
+{
+#if (IAVF_DEV_WATCHDOG_PERIOD > 0)
+	PMD_DRV_LOG(INFO, "Disabling device watchdog");
+	adapter->vf.watchdog_enabled = false;
+#endif
+}
+
 static int
 iavf_set_mc_addr_list(struct rte_eth_dev *dev,
 			struct rte_ether_addr *mc_addrs,
@@ -2466,6 +2552,11 @@  iavf_dev_init(struct rte_eth_dev *eth_dev)
 
 	iavf_default_rss_disable(adapter);
 
+
+	/* Start device watchdog */
+	iavf_dev_watchdog_enable(adapter);
+
+
 	return 0;
 
 flow_init_err:
@@ -2549,6 +2640,9 @@  iavf_dev_close(struct rte_eth_dev *dev)
 	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true))
 		vf->vf_reset = false;
 
+	/* disable watchdog */
+	iavf_dev_watchdog_disable(adapter);
+
 	return ret;
 }