The watchdog clears the `vf_reset` flag once a PF reset finishes. If the
PMD does not recover the VF itself (`auto_reset` devarg is 0, or the
port is stopped) and the application then stops and resets the port,
`vf_reset` is already false. This causes two problems:

- `iavf_stop_queues()` sends the queue disable to the disabled AdminQ
  and waits for it to time out.
- `iavf_dev_close()` does the same for its virtchnl commands, and does
  not re-enable PCI bus mastering, so `iavf_dev_init()` fails.

Add a `reinit_needed` flag, set when the reset is entered, which the
watchdog never clears. Use it in `iavf_stop_queues()` to skip the queue
disable, and in `iavf_dev_close()`, with `pf_reset_in_progress`, to skip
the AdminQ commands and re-enable bus mastering. Clear it once bus
mastering has been re-enabled.

Fixes: a0e296420a70 ("net/iavf: keep watchdog armed for the whole reset window")
Cc: [email protected]

Signed-off-by: Ciara Loftus <[email protected]>
---
 drivers/net/intel/iavf/iavf.h        |  1 +
 drivers/net/intel/iavf/iavf_ethdev.c | 32 ++++++++++++++++------------
 drivers/net/intel/iavf/iavf_rxtx.c   |  3 ++-
 drivers/net/intel/iavf/iavf_vchnl.c  |  1 +
 4 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/drivers/net/intel/iavf/iavf.h b/drivers/net/intel/iavf/iavf.h
index 0c98ae28e1..a41fd1110a 100644
--- a/drivers/net/intel/iavf/iavf.h
+++ b/drivers/net/intel/iavf/iavf.h
@@ -292,6 +292,7 @@ struct iavf_info {
 
        RTE_ATOMIC(bool)in_reset_recovery;
        RTE_ATOMIC(uint32_t)reset_events_pending;
+       RTE_ATOMIC(bool)reinit_needed; /* VF was reset and needs re-init */
        bool reset_pending;
        bool pf_reset_in_progress;
        bool start_pending;
diff --git a/drivers/net/intel/iavf/iavf_ethdev.c 
b/drivers/net/intel/iavf/iavf_ethdev.c
index 10069feae2..6f7e69b73f 100644
--- a/drivers/net/intel/iavf/iavf_ethdev.c
+++ b/drivers/net/intel/iavf/iavf_ethdev.c
@@ -3203,6 +3203,13 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
        return ret;
 }
 
+static bool
+iavf_adminq_down(struct iavf_info *vf)
+{
+       return vf->pf_reset_in_progress ||
+               rte_atomic_load_explicit(&vf->reinit_needed, 
rte_memory_order_acquire);
+}
+
 static int
 iavf_dev_close(struct rte_eth_dev *dev)
 {
@@ -3212,6 +3219,7 @@ iavf_dev_close(struct rte_eth_dev *dev)
        struct iavf_adapter *adapter =
                IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
        struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+       bool adminq_down;
        int ret;
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
@@ -3224,11 +3232,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
 
        ret = iavf_dev_stop(dev);
 
-       /*
-        * Prevent sending close-time virtchnl messages to the AdminQ
-        * during PF-initiated reset recovery.
-        */
-       if (!vf->pf_reset_in_progress) {
+       /* Prevent sending close-time virtchnl messages when the AdminQ is 
down. */
+       adminq_down = iavf_adminq_down(vf);
+       if (!adminq_down) {
 
                /*
                 * Release redundant queue resource when close the dev
@@ -3257,19 +3263,16 @@ iavf_dev_close(struct rte_eth_dev *dev)
        /* free iAVF security device context all related resources */
        iavf_security_ctx_destroy(adapter);
 
-       /* Skip the virtchnl-emitting teardown on a PF-initiated reset */
-       if (!vf->pf_reset_in_progress) {
+       /* Skip the virtchnl-emitting teardown after a reset */
+       if (!adminq_down) {
                /* remove RSS configuration */
                iavf_hash_uninit(adapter);
                iavf_flow_flush(dev, NULL);
        }
        iavf_flow_uninit(adapter);
 
-       /*
-        * Prevent sending VIRTCHNL_OP_RESET_VF during PF-initiated
-        * reset recovery.
-        */
-       if (!vf->pf_reset_in_progress)
+       /* Prevent sending VIRTCHNL_OP_RESET_VF when the AdminQ is down. */
+       if (!adminq_down)
                iavf_vf_reset(hw);
        /*
         * If a reset is pending, wait for the PF to disable the VF's admin
@@ -3322,9 +3325,10 @@ iavf_dev_close(struct rte_eth_dev *dev)
         * effect.
         */
 out:
-       if (rte_atomic_load_explicit(&vf->vf_reset, rte_memory_order_acquire) &&
-           !rte_pci_set_bus_master(pci_dev, true)) {
+       /* Check again if the AdminQ is down before enabling bus mastering. */
+       if (iavf_adminq_down(vf) && !rte_pci_set_bus_master(pci_dev, true)) {
                rte_atomic_store_explicit(&vf->vf_reset, false, 
rte_memory_order_release);
+               rte_atomic_store_explicit(&vf->reinit_needed, false, 
rte_memory_order_release);
                iavf_set_no_poll(adapter, false);
        }
 
diff --git a/drivers/net/intel/iavf/iavf_rxtx.c 
b/drivers/net/intel/iavf/iavf_rxtx.c
index 8c84991b86..a0dcf772b0 100644
--- a/drivers/net/intel/iavf/iavf_rxtx.c
+++ b/drivers/net/intel/iavf/iavf_rxtx.c
@@ -1106,7 +1106,8 @@ iavf_stop_queues(struct rte_eth_dev *dev)
        int ret;
 
        /* adminq will be disabled when vf is resetting. */
-       if (rte_atomic_load_explicit(&vf->in_reset_recovery, 
rte_memory_order_relaxed)) {
+       if (rte_atomic_load_explicit(&vf->in_reset_recovery, 
rte_memory_order_relaxed) ||
+           rte_atomic_load_explicit(&vf->reinit_needed, 
rte_memory_order_acquire)) {
                iavf_reset_queues(dev);
                return;
        }
diff --git a/drivers/net/intel/iavf/iavf_vchnl.c 
b/drivers/net/intel/iavf/iavf_vchnl.c
index 64ca93c20b..24a120bed3 100644
--- a/drivers/net/intel/iavf/iavf_vchnl.c
+++ b/drivers/net/intel/iavf/iavf_vchnl.c
@@ -162,6 +162,7 @@ iavf_dev_enter_reset(struct rte_eth_dev *dev, bool drain_tx)
         * posted on this path.
         */
        rte_atomic_fetch_add_explicit(&vf->reset_events_pending, 1, 
rte_memory_order_relaxed);
+       rte_atomic_store_explicit(&vf->reinit_needed, true, 
rte_memory_order_release);
        if (!rte_atomic_compare_exchange_strong_explicit(&vf->vf_reset, 
&expected, true,
                        rte_memory_order_release, rte_memory_order_acquire)) {
                rte_atomic_fetch_sub_explicit(&vf->reset_events_pending, 1,
-- 
2.43.0

Reply via email to